From adc8df9d05d274b5f210556e935c83b652a14141 Mon Sep 17 00:00:00 2001 From: Jakob Maljaars <jakob.maljaars@stcorp.nl> Date: Thu, 2 Jul 2020 15:30:28 +0200 Subject: [PATCH] Include dependencies via git-submodules --- .gitmodules | 9 + CMakeLists.txt | 23 +- cpp/test/CMakeLists.txt | 9 +- cpp/test/taocommon.cc | 10 + cpp/test/teigen.cc | 13 + cpp/test/tpybind11.cc | 7 + external/CMakeLists.txt | 2 - external/README.md | 29 +- external/aocommon | 1 + external/eigen | 1 + external/eigen/include/eigen3/Eigen/Cholesky | 46 - .../eigen/include/eigen3/Eigen/CholmodSupport | 48 - external/eigen/include/eigen3/Eigen/Core | 361 - external/eigen/include/eigen3/Eigen/Dense | 7 - external/eigen/include/eigen3/Eigen/Eigen | 2 - .../eigen/include/eigen3/Eigen/Eigenvalues | 61 - external/eigen/include/eigen3/Eigen/Geometry | 60 - .../eigen/include/eigen3/Eigen/Householder | 30 - .../eigen3/Eigen/IterativeLinearSolvers | 48 - external/eigen/include/eigen3/Eigen/Jacobi | 33 - .../eigen/include/eigen3/Eigen/KLUSupport | 41 - external/eigen/include/eigen3/Eigen/LU | 50 - .../eigen/include/eigen3/Eigen/MetisSupport | 35 - .../include/eigen3/Eigen/OrderingMethods | 70 - .../eigen/include/eigen3/Eigen/PaStiXSupport | 49 - .../eigen/include/eigen3/Eigen/PardisoSupport | 35 - external/eigen/include/eigen3/Eigen/QR | 51 - .../include/eigen3/Eigen/QtAlignedMalloc | 40 - .../eigen/include/eigen3/Eigen/SPQRSupport | 34 - external/eigen/include/eigen3/Eigen/SVD | 51 - external/eigen/include/eigen3/Eigen/Sparse | 34 - .../eigen/include/eigen3/Eigen/SparseCholesky | 37 - .../eigen/include/eigen3/Eigen/SparseCore | 69 - external/eigen/include/eigen3/Eigen/SparseLU | 50 - external/eigen/include/eigen3/Eigen/SparseQR | 36 - external/eigen/include/eigen3/Eigen/StdDeque | 27 - external/eigen/include/eigen3/Eigen/StdList | 26 - external/eigen/include/eigen3/Eigen/StdVector | 27 - .../eigen/include/eigen3/Eigen/SuperLUSupport | 64 - .../eigen/include/eigen3/Eigen/UmfPackSupport | 40 - .../include/eigen3/Eigen/src/Cholesky/LDLT.h | 688 - .../include/eigen3/Eigen/src/Cholesky/LLT.h | 558 - .../eigen3/Eigen/src/Cholesky/LLT_LAPACKE.h | 99 - .../Eigen/src/CholmodSupport/CholmodSupport.h | 682 - .../Eigen/src/Core/ArithmeticSequence.h | 413 - .../include/eigen3/Eigen/src/Core/Array.h | 415 - .../include/eigen3/Eigen/src/Core/ArrayBase.h | 226 - .../eigen3/Eigen/src/Core/ArrayWrapper.h | 209 - .../include/eigen3/Eigen/src/Core/Assign.h | 90 - .../eigen3/Eigen/src/Core/AssignEvaluator.h | 982 - .../eigen3/Eigen/src/Core/Assign_MKL.h | 178 - .../eigen3/Eigen/src/Core/BandMatrix.h | 353 - .../include/eigen3/Eigen/src/Core/Block.h | 452 - .../eigen3/Eigen/src/Core/BooleanRedux.h | 162 - .../eigen3/Eigen/src/Core/CommaInitializer.h | 160 - .../Eigen/src/Core/ConditionEstimator.h | 175 - .../eigen3/Eigen/src/Core/CoreEvaluators.h | 1732 -- .../eigen3/Eigen/src/Core/CoreIterators.h | 132 - .../eigen3/Eigen/src/Core/CwiseBinaryOp.h | 189 - .../eigen3/Eigen/src/Core/CwiseNullaryOp.h | 922 - .../eigen3/Eigen/src/Core/CwiseTernaryOp.h | 197 - .../eigen3/Eigen/src/Core/CwiseUnaryOp.h | 103 - .../eigen3/Eigen/src/Core/CwiseUnaryView.h | 130 - .../include/eigen3/Eigen/src/Core/DenseBase.h | 661 - .../eigen3/Eigen/src/Core/DenseCoeffsBase.h | 685 - .../eigen3/Eigen/src/Core/DenseStorage.h | 590 - .../include/eigen3/Eigen/src/Core/Diagonal.h | 262 - .../eigen3/Eigen/src/Core/DiagonalMatrix.h | 391 - .../eigen3/Eigen/src/Core/DiagonalProduct.h | 28 - .../eigen/include/eigen3/Eigen/src/Core/Dot.h | 318 - .../include/eigen3/Eigen/src/Core/EigenBase.h | 160 - .../Eigen/src/Core/ForceAlignedAccess.h | 146 - .../include/eigen3/Eigen/src/Core/Fuzzy.h | 155 - .../eigen3/Eigen/src/Core/GeneralProduct.h | 467 - .../eigen3/Eigen/src/Core/GenericPacketMath.h | 759 - .../eigen3/Eigen/src/Core/GlobalFunctions.h | 193 - .../eigen/include/eigen3/Eigen/src/Core/IO.h | 258 - .../eigen3/Eigen/src/Core/IndexedView.h | 207 - .../include/eigen3/Eigen/src/Core/Inverse.h | 117 - .../eigen/include/eigen3/Eigen/src/Core/Map.h | 171 - .../include/eigen3/Eigen/src/Core/MapBase.h | 308 - .../eigen3/Eigen/src/Core/MathFunctions.h | 1852 -- .../eigen3/Eigen/src/Core/MathFunctionsImpl.h | 106 - .../include/eigen3/Eigen/src/Core/Matrix.h | 563 - .../eigen3/Eigen/src/Core/MatrixBase.h | 547 - .../eigen3/Eigen/src/Core/NestByValue.h | 85 - .../include/eigen3/Eigen/src/Core/NoAlias.h | 109 - .../include/eigen3/Eigen/src/Core/NumTraits.h | 289 - .../Eigen/src/Core/PartialReduxEvaluator.h | 232 - .../eigen3/Eigen/src/Core/PermutationMatrix.h | 605 - .../eigen3/Eigen/src/Core/PlainObjectBase.h | 1117 -- .../include/eigen3/Eigen/src/Core/Product.h | 191 - .../eigen3/Eigen/src/Core/ProductEvaluators.h | 1174 -- .../include/eigen3/Eigen/src/Core/Random.h | 182 - .../include/eigen3/Eigen/src/Core/Redux.h | 507 - .../eigen/include/eigen3/Eigen/src/Core/Ref.h | 286 - .../include/eigen3/Eigen/src/Core/Replicate.h | 142 - .../include/eigen3/Eigen/src/Core/Reshaped.h | 453 - .../eigen3/Eigen/src/Core/ReturnByValue.h | 117 - .../include/eigen3/Eigen/src/Core/Reverse.h | 215 - .../include/eigen3/Eigen/src/Core/Select.h | 162 - .../eigen3/Eigen/src/Core/SelfAdjointView.h | 365 - .../eigen3/Eigen/src/Core/SelfCwiseBinaryOp.h | 47 - .../include/eigen3/Eigen/src/Core/Solve.h | 188 - .../eigen3/Eigen/src/Core/SolveTriangular.h | 235 - .../eigen3/Eigen/src/Core/SolverBase.h | 168 - .../eigen3/Eigen/src/Core/StableNorm.h | 264 - .../eigen3/Eigen/src/Core/StlIterators.h | 331 - .../include/eigen3/Eigen/src/Core/Stride.h | 111 - .../include/eigen3/Eigen/src/Core/Swap.h | 68 - .../include/eigen3/Eigen/src/Core/Transpose.h | 415 - .../eigen3/Eigen/src/Core/Transpositions.h | 368 - .../eigen3/Eigen/src/Core/TriangularMatrix.h | 1001 - .../eigen3/Eigen/src/Core/VectorBlock.h | 96 - .../eigen3/Eigen/src/Core/VectorwiseOp.h | 760 - .../include/eigen3/Eigen/src/Core/Visitor.h | 309 - .../eigen3/Eigen/src/Core/arch/AVX/Complex.h | 471 - .../Eigen/src/Core/arch/AVX/MathFunctions.h | 160 - .../Eigen/src/Core/arch/AVX/PacketMath.h | 1238 -- .../Eigen/src/Core/arch/AVX/TypeCasting.h | 89 - .../Eigen/src/Core/arch/AVX512/Complex.h | 492 - .../src/Core/arch/AVX512/MathFunctions.h | 446 - .../Eigen/src/Core/arch/AVX512/PacketMath.h | 1929 -- .../Eigen/src/Core/arch/AVX512/TypeCasting.h | 47 - .../Eigen/src/Core/arch/AltiVec/Complex.h | 447 - .../src/Core/arch/AltiVec/MathFunctions.h | 90 - .../Eigen/src/Core/arch/AltiVec/PacketMath.h | 1190 -- .../eigen3/Eigen/src/Core/arch/CUDA/Complex.h | 103 - .../Eigen/src/Core/arch/Default/ConjHelper.h | 29 - .../arch/Default/GenericPacketMathFunctions.h | 655 - .../Default/GenericPacketMathFunctionsFwd.h | 69 - .../eigen3/Eigen/src/Core/arch/Default/Half.h | 756 - .../Eigen/src/Core/arch/Default/Settings.h | 49 - .../Eigen/src/Core/arch/Default/TypeCasting.h | 77 - .../Eigen/src/Core/arch/GPU/MathFunctions.h | 103 - .../Eigen/src/Core/arch/GPU/PacketMath.h | 1040 - .../Eigen/src/Core/arch/GPU/TypeCasting.h | 55 - .../src/Core/arch/HIP/hcc/math_constants.h | 23 - .../eigen3/Eigen/src/Core/arch/MSA/Complex.h | 759 - .../Eigen/src/Core/arch/MSA/MathFunctions.h | 387 - .../Eigen/src/Core/arch/MSA/PacketMath.h | 1318 -- .../eigen3/Eigen/src/Core/arch/NEON/Complex.h | 522 - .../Eigen/src/Core/arch/NEON/MathFunctions.h | 35 - .../Eigen/src/Core/arch/NEON/PacketMath.h | 800 - .../Eigen/src/Core/arch/NEON/TypeCasting.h | 34 - .../eigen3/Eigen/src/Core/arch/SSE/Complex.h | 488 - .../Eigen/src/Core/arch/SSE/MathFunctions.h | 182 - .../Eigen/src/Core/arch/SSE/PacketMath.h | 1307 -- .../Eigen/src/Core/arch/SSE/TypeCasting.h | 135 - .../Eigen/src/Core/arch/SYCL/InteropHeaders.h | 229 - .../Eigen/src/Core/arch/SYCL/MathFunctions.h | 289 - .../Eigen/src/Core/arch/SYCL/PacketMath.h | 670 - .../src/Core/arch/SYCL/SyclMemoryModel.h | 694 - .../Eigen/src/Core/arch/SYCL/TypeCasting.h | 85 - .../Eigen/src/Core/arch/ZVector/Complex.h | 563 - .../src/Core/arch/ZVector/MathFunctions.h | 239 - .../Eigen/src/Core/arch/ZVector/PacketMath.h | 1193 -- .../src/Core/functors/AssignmentFunctors.h | 177 - .../Eigen/src/Core/functors/BinaryFunctors.h | 475 - .../Eigen/src/Core/functors/NullaryFunctors.h | 189 - .../Eigen/src/Core/functors/StlFunctors.h | 136 - .../Eigen/src/Core/functors/TernaryFunctors.h | 25 - .../Eigen/src/Core/functors/UnaryFunctors.h | 1036 - .../Core/products/GeneralBlockPanelKernel.h | 2787 --- .../src/Core/products/GeneralMatrixMatrix.h | 517 - .../products/GeneralMatrixMatrixTriangular.h | 317 - .../GeneralMatrixMatrixTriangular_BLAS.h | 145 - .../Core/products/GeneralMatrixMatrix_BLAS.h | 124 - .../src/Core/products/GeneralMatrixVector.h | 518 - .../Core/products/GeneralMatrixVector_BLAS.h | 136 - .../Eigen/src/Core/products/Parallelizer.h | 180 - .../Core/products/SelfadjointMatrixMatrix.h | 544 - .../products/SelfadjointMatrixMatrix_BLAS.h | 295 - .../Core/products/SelfadjointMatrixVector.h | 262 - .../products/SelfadjointMatrixVector_BLAS.h | 118 - .../src/Core/products/SelfadjointProduct.h | 133 - .../Core/products/SelfadjointRank2Update.h | 94 - .../Core/products/TriangularMatrixMatrix.h | 472 - .../products/TriangularMatrixMatrix_BLAS.h | 317 - .../Core/products/TriangularMatrixVector.h | 350 - .../products/TriangularMatrixVector_BLAS.h | 255 - .../Core/products/TriangularSolverMatrix.h | 335 - .../products/TriangularSolverMatrix_BLAS.h | 167 - .../Core/products/TriangularSolverVector.h | 148 - .../eigen3/Eigen/src/Core/util/BlasUtil.h | 500 - .../src/Core/util/ConfigureVectorization.h | 486 - .../eigen3/Eigen/src/Core/util/Constants.h | 550 - .../src/Core/util/DisableStupidWarnings.h | 103 - .../Eigen/src/Core/util/ForwardDeclarations.h | 320 - .../Eigen/src/Core/util/IndexedViewHelper.h | 186 - .../Eigen/src/Core/util/IntegralConstant.h | 272 - .../eigen3/Eigen/src/Core/util/MKL_support.h | 137 - .../eigen3/Eigen/src/Core/util/Macros.h | 1299 -- .../eigen3/Eigen/src/Core/util/Memory.h | 1126 -- .../include/eigen3/Eigen/src/Core/util/Meta.h | 719 - .../eigen3/Eigen/src/Core/util/NonMPL2.h | 3 - .../src/Core/util/ReenableStupidWarnings.h | 31 - .../Eigen/src/Core/util/ReshapedHelper.h | 51 - .../eigen3/Eigen/src/Core/util/StaticAssert.h | 220 - .../Eigen/src/Core/util/SymbolicIndex.h | 293 - .../eigen3/Eigen/src/Core/util/XprHelper.h | 864 - .../src/Eigenvalues/ComplexEigenSolver.h | 346 - .../Eigen/src/Eigenvalues/ComplexSchur.h | 462 - .../src/Eigenvalues/ComplexSchur_LAPACKE.h | 91 - .../Eigen/src/Eigenvalues/EigenSolver.h | 622 - .../src/Eigenvalues/GeneralizedEigenSolver.h | 418 - .../GeneralizedSelfAdjointEigenSolver.h | 226 - .../src/Eigenvalues/HessenbergDecomposition.h | 374 - .../src/Eigenvalues/MatrixBaseEigenvalues.h | 158 - .../eigen3/Eigen/src/Eigenvalues/RealQZ.h | 657 - .../eigen3/Eigen/src/Eigenvalues/RealSchur.h | 558 - .../Eigen/src/Eigenvalues/RealSchur_LAPACKE.h | 77 - .../src/Eigenvalues/SelfAdjointEigenSolver.h | 879 - .../SelfAdjointEigenSolver_LAPACKE.h | 87 - .../src/Eigenvalues/Tridiagonalization.h | 561 - .../eigen3/Eigen/src/Geometry/AlignedBox.h | 392 - .../eigen3/Eigen/src/Geometry/AngleAxis.h | 247 - .../eigen3/Eigen/src/Geometry/EulerAngles.h | 114 - .../eigen3/Eigen/src/Geometry/Homogeneous.h | 497 - .../eigen3/Eigen/src/Geometry/Hyperplane.h | 282 - .../eigen3/Eigen/src/Geometry/OrthoMethods.h | 235 - .../Eigen/src/Geometry/ParametrizedLine.h | 232 - .../eigen3/Eigen/src/Geometry/Quaternion.h | 847 - .../eigen3/Eigen/src/Geometry/Rotation2D.h | 199 - .../eigen3/Eigen/src/Geometry/RotationBase.h | 206 - .../eigen3/Eigen/src/Geometry/Scaling.h | 188 - .../eigen3/Eigen/src/Geometry/Transform.h | 1570 -- .../eigen3/Eigen/src/Geometry/Translation.h | 202 - .../eigen3/Eigen/src/Geometry/Umeyama.h | 166 - .../Eigen/src/Geometry/arch/Geometry_SSE.h | 170 - .../Eigen/src/Householder/BlockHouseholder.h | 110 - .../Eigen/src/Householder/Householder.h | 176 - .../src/Householder/HouseholderSequence.h | 545 - .../BasicPreconditioners.h | 226 - .../src/IterativeLinearSolvers/BiCGSTAB.h | 212 - .../ConjugateGradient.h | 229 - .../IncompleteCholesky.h | 394 - .../IterativeLinearSolvers/IncompleteLUT.h | 453 - .../IterativeSolverBase.h | 444 - .../LeastSquareConjugateGradient.h | 198 - .../IterativeLinearSolvers/SolveWithGuess.h | 115 - .../include/eigen3/Eigen/src/Jacobi/Jacobi.h | 483 - .../eigen3/Eigen/src/KLUSupport/KLUSupport.h | 358 - .../include/eigen3/Eigen/src/LU/Determinant.h | 117 - .../include/eigen3/Eigen/src/LU/FullPivLU.h | 875 - .../include/eigen3/Eigen/src/LU/InverseImpl.h | 417 - .../eigen3/Eigen/src/LU/PartialPivLU.h | 619 - .../Eigen/src/LU/PartialPivLU_LAPACKE.h | 83 - .../eigen3/Eigen/src/LU/arch/Inverse_SSE.h | 338 - .../Eigen/src/MetisSupport/MetisSupport.h | 137 - .../eigen3/Eigen/src/OrderingMethods/Amd.h | 435 - .../Eigen/src/OrderingMethods/Eigen_Colamd.h | 1863 -- .../Eigen/src/OrderingMethods/Ordering.h | 153 - .../Eigen/src/PaStiXSupport/PaStiXSupport.h | 678 - .../Eigen/src/PardisoSupport/PardisoSupport.h | 545 - .../eigen3/Eigen/src/QR/ColPivHouseholderQR.h | 674 - .../src/QR/ColPivHouseholderQR_LAPACKE.h | 97 - .../src/QR/CompleteOrthogonalDecomposition.h | 635 - .../Eigen/src/QR/FullPivHouseholderQR.h | 713 - .../eigen3/Eigen/src/QR/HouseholderQR.h | 434 - .../Eigen/src/QR/HouseholderQR_LAPACKE.h | 68 - .../src/SPQRSupport/SuiteSparseQRSupport.h | 335 - .../include/eigen3/Eigen/src/SVD/BDCSVD.h | 1350 -- .../include/eigen3/Eigen/src/SVD/JacobiSVD.h | 805 - .../eigen3/Eigen/src/SVD/JacobiSVD_LAPACKE.h | 91 - .../include/eigen3/Eigen/src/SVD/SVDBase.h | 354 - .../Eigen/src/SVD/UpperBidiagonalization.h | 414 - .../src/SparseCholesky/SimplicialCholesky.h | 697 - .../SparseCholesky/SimplicialCholesky_impl.h | 174 - .../eigen3/Eigen/src/SparseCore/AmbiVector.h | 378 - .../Eigen/src/SparseCore/CompressedStorage.h | 274 - .../ConservativeSparseSparseProduct.h | 352 - .../Eigen/src/SparseCore/MappedSparseMatrix.h | 67 - .../Eigen/src/SparseCore/SparseAssign.h | 270 - .../eigen3/Eigen/src/SparseCore/SparseBlock.h | 567 - .../Eigen/src/SparseCore/SparseColEtree.h | 206 - .../src/SparseCore/SparseCompressedBase.h | 370 - .../src/SparseCore/SparseCwiseBinaryOp.h | 722 - .../Eigen/src/SparseCore/SparseCwiseUnaryOp.h | 150 - .../Eigen/src/SparseCore/SparseDenseProduct.h | 342 - .../src/SparseCore/SparseDiagonalProduct.h | 138 - .../eigen3/Eigen/src/SparseCore/SparseDot.h | 98 - .../eigen3/Eigen/src/SparseCore/SparseFuzzy.h | 29 - .../eigen3/Eigen/src/SparseCore/SparseMap.h | 305 - .../Eigen/src/SparseCore/SparseMatrix.h | 1512 -- .../Eigen/src/SparseCore/SparseMatrixBase.h | 398 - .../Eigen/src/SparseCore/SparsePermutation.h | 178 - .../Eigen/src/SparseCore/SparseProduct.h | 169 - .../eigen3/Eigen/src/SparseCore/SparseRedux.h | 49 - .../eigen3/Eigen/src/SparseCore/SparseRef.h | 397 - .../src/SparseCore/SparseSelfAdjointView.h | 656 - .../Eigen/src/SparseCore/SparseSolverBase.h | 124 - .../SparseSparseProductWithPruning.h | 198 - .../Eigen/src/SparseCore/SparseTranspose.h | 92 - .../src/SparseCore/SparseTriangularView.h | 189 - .../eigen3/Eigen/src/SparseCore/SparseUtil.h | 186 - .../Eigen/src/SparseCore/SparseVector.h | 478 - .../eigen3/Eigen/src/SparseCore/SparseView.h | 254 - .../Eigen/src/SparseCore/TriangularSolver.h | 315 - .../eigen3/Eigen/src/SparseLU/SparseLU.h | 773 - .../eigen3/Eigen/src/SparseLU/SparseLUImpl.h | 66 - .../Eigen/src/SparseLU/SparseLU_Memory.h | 226 - .../Eigen/src/SparseLU/SparseLU_Structs.h | 110 - .../src/SparseLU/SparseLU_SupernodalMatrix.h | 301 - .../Eigen/src/SparseLU/SparseLU_Utils.h | 80 - .../Eigen/src/SparseLU/SparseLU_column_bmod.h | 181 - .../Eigen/src/SparseLU/SparseLU_column_dfs.h | 179 - .../src/SparseLU/SparseLU_copy_to_ucol.h | 107 - .../Eigen/src/SparseLU/SparseLU_gemm_kernel.h | 280 - .../src/SparseLU/SparseLU_heap_relax_snode.h | 126 - .../Eigen/src/SparseLU/SparseLU_kernel_bmod.h | 130 - .../Eigen/src/SparseLU/SparseLU_panel_bmod.h | 223 - .../Eigen/src/SparseLU/SparseLU_panel_dfs.h | 258 - .../Eigen/src/SparseLU/SparseLU_pivotL.h | 137 - .../Eigen/src/SparseLU/SparseLU_pruneL.h | 136 - .../Eigen/src/SparseLU/SparseLU_relax_snode.h | 83 - .../eigen3/Eigen/src/SparseQR/SparseQR.h | 758 - .../eigen3/Eigen/src/StlSupport/StdDeque.h | 126 - .../eigen3/Eigen/src/StlSupport/StdList.h | 106 - .../eigen3/Eigen/src/StlSupport/StdVector.h | 131 - .../eigen3/Eigen/src/StlSupport/details.h | 84 - .../Eigen/src/SuperLUSupport/SuperLUSupport.h | 1027 - .../Eigen/src/UmfPackSupport/UmfPackSupport.h | 642 - .../include/eigen3/Eigen/src/misc/Image.h | 82 - .../include/eigen3/Eigen/src/misc/Kernel.h | 79 - .../eigen3/Eigen/src/misc/RealSvd2x2.h | 55 - .../include/eigen3/Eigen/src/misc/blas.h | 440 - .../include/eigen3/Eigen/src/misc/lapack.h | 152 - .../include/eigen3/Eigen/src/misc/lapacke.h | 16292 ---------------- .../eigen3/Eigen/src/misc/lapacke_mangling.h | 17 - .../Eigen/src/plugins/ArrayCwiseBinaryOps.h | 332 - .../Eigen/src/plugins/ArrayCwiseUnaryOps.h | 644 - .../eigen3/Eigen/src/plugins/BlockMethods.h | 1443 -- .../Eigen/src/plugins/CommonCwiseBinaryOps.h | 115 - .../Eigen/src/plugins/CommonCwiseUnaryOps.h | 177 - .../Eigen/src/plugins/IndexedViewMethods.h | 262 - .../Eigen/src/plugins/MatrixCwiseBinaryOps.h | 152 - .../Eigen/src/plugins/MatrixCwiseUnaryOps.h | 85 - .../Eigen/src/plugins/ReshapedMethods.h | 149 - .../eigen3/signature_of_eigen3_matrix_library | 1 - .../eigen3/unsupported/Eigen/AdolcForward | 156 - .../eigen3/unsupported/Eigen/AlignedVector3 | 234 - .../eigen3/unsupported/Eigen/ArpackSupport | 31 - .../include/eigen3/unsupported/Eigen/AutoDiff | 46 - .../include/eigen3/unsupported/Eigen/BVH | 95 - .../eigen3/unsupported/Eigen/CXX11/Tensor | 157 - .../unsupported/Eigen/CXX11/TensorSymmetry | 42 - .../eigen3/unsupported/Eigen/CXX11/ThreadPool | 75 - .../Eigen/CXX11/src/Tensor/Tensor.h | 554 - .../Eigen/CXX11/src/Tensor/TensorArgMax.h | 329 - .../Eigen/CXX11/src/Tensor/TensorAssign.h | 247 - .../Eigen/CXX11/src/Tensor/TensorBase.h | 1153 -- .../Eigen/CXX11/src/Tensor/TensorBlock.h | 1559 -- .../CXX11/src/Tensor/TensorBroadcasting.h | 1094 -- .../Eigen/CXX11/src/Tensor/TensorChipping.h | 534 - .../CXX11/src/Tensor/TensorConcatenation.h | 394 - .../CXX11/src/Tensor/TensorContraction.h | 1021 - .../src/Tensor/TensorContractionBlocking.h | 73 - .../CXX11/src/Tensor/TensorContractionCuda.h | 6 - .../CXX11/src/Tensor/TensorContractionGpu.h | 1413 -- .../src/Tensor/TensorContractionMapper.h | 575 - .../CXX11/src/Tensor/TensorContractionSycl.h | 1650 -- .../src/Tensor/TensorContractionThreadPool.h | 1679 -- .../Eigen/CXX11/src/Tensor/TensorConversion.h | 429 - .../CXX11/src/Tensor/TensorConvolution.h | 1132 -- .../CXX11/src/Tensor/TensorConvolutionSycl.h | 544 - .../Eigen/CXX11/src/Tensor/TensorCostModel.h | 214 - .../Eigen/CXX11/src/Tensor/TensorCustomOp.h | 347 - .../Eigen/CXX11/src/Tensor/TensorDevice.h | 135 - .../Eigen/CXX11/src/Tensor/TensorDeviceCuda.h | 6 - .../CXX11/src/Tensor/TensorDeviceDefault.h | 104 - .../Eigen/CXX11/src/Tensor/TensorDeviceGpu.h | 360 - .../Eigen/CXX11/src/Tensor/TensorDeviceSycl.h | 1048 - .../CXX11/src/Tensor/TensorDeviceThreadPool.h | 407 - .../CXX11/src/Tensor/TensorDimensionList.h | 236 - .../Eigen/CXX11/src/Tensor/TensorDimensions.h | 490 - .../Eigen/CXX11/src/Tensor/TensorEvalTo.h | 236 - .../Eigen/CXX11/src/Tensor/TensorEvaluator.h | 984 - .../Eigen/CXX11/src/Tensor/TensorExecutor.h | 700 - .../Eigen/CXX11/src/Tensor/TensorExpr.h | 388 - .../Eigen/CXX11/src/Tensor/TensorFFT.h | 669 - .../Eigen/CXX11/src/Tensor/TensorFixedSize.h | 396 - .../Eigen/CXX11/src/Tensor/TensorForcedEval.h | 240 - .../src/Tensor/TensorForwardDeclarations.h | 191 - .../Eigen/CXX11/src/Tensor/TensorFunctors.h | 477 - .../Eigen/CXX11/src/Tensor/TensorGenerator.h | 302 - .../CXX11/src/Tensor/TensorGlobalFunctions.h | 33 - .../src/Tensor/TensorGpuHipCudaDefines.h | 93 - .../src/Tensor/TensorGpuHipCudaUndefines.h | 40 - .../Eigen/CXX11/src/Tensor/TensorIO.h | 79 - .../Eigen/CXX11/src/Tensor/TensorImagePatch.h | 603 - .../Eigen/CXX11/src/Tensor/TensorIndexList.h | 738 - .../Eigen/CXX11/src/Tensor/TensorInflation.h | 247 - .../CXX11/src/Tensor/TensorInitializer.h | 82 - .../Eigen/CXX11/src/Tensor/TensorIntDiv.h | 263 - .../Eigen/CXX11/src/Tensor/TensorLayoutSwap.h | 233 - .../Eigen/CXX11/src/Tensor/TensorMacros.h | 93 - .../Eigen/CXX11/src/Tensor/TensorMap.h | 343 - .../Eigen/CXX11/src/Tensor/TensorMeta.h | 319 - .../Eigen/CXX11/src/Tensor/TensorMorphing.h | 1152 -- .../Eigen/CXX11/src/Tensor/TensorPadding.h | 708 - .../Eigen/CXX11/src/Tensor/TensorPatch.h | 291 - .../Eigen/CXX11/src/Tensor/TensorRandom.h | 350 - .../Eigen/CXX11/src/Tensor/TensorReduction.h | 1134 -- .../CXX11/src/Tensor/TensorReductionCuda.h | 6 - .../CXX11/src/Tensor/TensorReductionGpu.h | 821 - .../CXX11/src/Tensor/TensorReductionSycl.h | 586 - .../Eigen/CXX11/src/Tensor/TensorRef.h | 454 - .../Eigen/CXX11/src/Tensor/TensorReverse.h | 482 - .../Eigen/CXX11/src/Tensor/TensorScan.h | 313 - .../Eigen/CXX11/src/Tensor/TensorScanSycl.h | 512 - .../Eigen/CXX11/src/Tensor/TensorShuffling.h | 485 - .../Eigen/CXX11/src/Tensor/TensorStorage.h | 146 - .../Eigen/CXX11/src/Tensor/TensorStriding.h | 362 - .../Eigen/CXX11/src/Tensor/TensorTrace.h | 303 - .../Eigen/CXX11/src/Tensor/TensorTraits.h | 264 - .../Eigen/CXX11/src/Tensor/TensorUInt128.h | 249 - .../CXX11/src/Tensor/TensorVolumePatch.h | 629 - .../src/TensorSymmetry/DynamicSymmetry.h | 293 - .../CXX11/src/TensorSymmetry/StaticSymmetry.h | 236 - .../Eigen/CXX11/src/TensorSymmetry/Symmetry.h | 338 - .../TensorSymmetry/util/TemplateGroupTheory.h | 669 - .../Eigen/CXX11/src/ThreadPool/Barrier.h | 67 - .../Eigen/CXX11/src/ThreadPool/EventCount.h | 249 - .../src/ThreadPool/NonBlockingThreadPool.h | 480 - .../Eigen/CXX11/src/ThreadPool/RunQueue.h | 236 - .../Eigen/CXX11/src/ThreadPool/ThreadCancel.h | 23 - .../CXX11/src/ThreadPool/ThreadEnvironment.h | 40 - .../Eigen/CXX11/src/ThreadPool/ThreadLocal.h | 301 - .../src/ThreadPool/ThreadPoolInterface.h | 48 - .../Eigen/CXX11/src/ThreadPool/ThreadYield.h | 20 - .../Eigen/CXX11/src/util/CXX11Meta.h | 537 - .../Eigen/CXX11/src/util/CXX11Workarounds.h | 88 - .../Eigen/CXX11/src/util/EmulateArray.h | 261 - .../Eigen/CXX11/src/util/MaxSizeVector.h | 158 - .../eigen3/unsupported/Eigen/EulerAngles | 43 - .../include/eigen3/unsupported/Eigen/FFT | 424 - .../eigen3/unsupported/Eigen/IterativeSolvers | 46 - .../eigen3/unsupported/Eigen/KroneckerProduct | 36 - .../unsupported/Eigen/LevenbergMarquardt | 49 - .../eigen3/unsupported/Eigen/MPRealSupport | 213 - .../eigen3/unsupported/Eigen/MatrixFunctions | 504 - .../unsupported/Eigen/MoreVectorization | 24 - .../unsupported/Eigen/NonLinearOptimization | 140 - .../eigen3/unsupported/Eigen/NumericalDiff | 56 - .../eigen3/unsupported/Eigen/OpenGLSupport | 322 - .../eigen3/unsupported/Eigen/Polynomials | 138 - .../include/eigen3/unsupported/Eigen/Skyline | 39 - .../eigen3/unsupported/Eigen/SparseExtra | 53 - .../eigen3/unsupported/Eigen/SpecialFunctions | 88 - .../include/eigen3/unsupported/Eigen/Splines | 35 - .../Eigen/src/AutoDiff/AutoDiffJacobian.h | 108 - .../Eigen/src/AutoDiff/AutoDiffScalar.h | 730 - .../Eigen/src/AutoDiff/AutoDiffVector.h | 220 - .../unsupported/Eigen/src/BVH/BVAlgorithms.h | 293 - .../eigen3/unsupported/Eigen/src/BVH/KdBVH.h | 223 - .../ArpackSelfAdjointEigenSolver.h | 790 - .../Eigen/src/EulerAngles/EulerAngles.h | 355 - .../Eigen/src/EulerAngles/EulerSystem.h | 305 - .../unsupported/Eigen/src/FFT/ei_fftw_impl.h | 263 - .../Eigen/src/FFT/ei_kissfft_impl.h | 420 - .../IterativeSolvers/ConstrainedConjGrad.h | 189 - .../Eigen/src/IterativeSolvers/DGMRES.h | 511 - .../Eigen/src/IterativeSolvers/GMRES.h | 335 - .../Eigen/src/IterativeSolvers/IncompleteLU.h | 90 - .../IterativeSolvers/IterationController.h | 154 - .../Eigen/src/IterativeSolvers/MINRES.h | 267 - .../Eigen/src/IterativeSolvers/Scaling.h | 193 - .../KroneckerProduct/KroneckerTensorProduct.h | 305 - .../Eigen/src/LevenbergMarquardt/LMcovar.h | 84 - .../Eigen/src/LevenbergMarquardt/LMonestep.h | 202 - .../Eigen/src/LevenbergMarquardt/LMpar.h | 160 - .../Eigen/src/LevenbergMarquardt/LMqrsolv.h | 188 - .../LevenbergMarquardt/LevenbergMarquardt.h | 396 - .../src/MatrixFunctions/MatrixExponential.h | 441 - .../src/MatrixFunctions/MatrixFunction.h | 569 - .../src/MatrixFunctions/MatrixLogarithm.h | 373 - .../Eigen/src/MatrixFunctions/MatrixPower.h | 705 - .../src/MatrixFunctions/MatrixSquareRoot.h | 368 - .../Eigen/src/MatrixFunctions/StemFunction.h | 117 - .../src/MoreVectorization/MathFunctions.h | 95 - .../HybridNonLinearSolver.h | 601 - .../LevenbergMarquardt.h | 657 - .../Eigen/src/NonLinearOptimization/chkder.h | 66 - .../Eigen/src/NonLinearOptimization/covar.h | 70 - .../Eigen/src/NonLinearOptimization/dogleg.h | 107 - .../Eigen/src/NonLinearOptimization/fdjac1.h | 79 - .../Eigen/src/NonLinearOptimization/lmpar.h | 298 - .../Eigen/src/NonLinearOptimization/qrsolv.h | 91 - .../Eigen/src/NonLinearOptimization/r1mpyq.h | 30 - .../Eigen/src/NonLinearOptimization/r1updt.h | 99 - .../Eigen/src/NonLinearOptimization/rwupdt.h | 49 - .../Eigen/src/NumericalDiff/NumericalDiff.h | 130 - .../Eigen/src/Polynomials/Companion.h | 275 - .../Eigen/src/Polynomials/PolynomialSolver.h | 428 - .../Eigen/src/Polynomials/PolynomialUtils.h | 143 - .../Eigen/src/Skyline/SkylineInplaceLU.h | 352 - .../Eigen/src/Skyline/SkylineMatrix.h | 862 - .../Eigen/src/Skyline/SkylineMatrixBase.h | 212 - .../Eigen/src/Skyline/SkylineProduct.h | 295 - .../Eigen/src/Skyline/SkylineStorage.h | 259 - .../Eigen/src/Skyline/SkylineUtil.h | 89 - .../SparseExtra/BlockOfDynamicSparseMatrix.h | 122 - .../Eigen/src/SparseExtra/BlockSparseMatrix.h | 1079 - .../src/SparseExtra/DynamicSparseMatrix.h | 404 - .../Eigen/src/SparseExtra/MarketIO.h | 282 - .../src/SparseExtra/MatrixMarketIterator.h | 247 - .../Eigen/src/SparseExtra/RandomSetter.h | 327 - .../BesselFunctionsArrayAPI.h | 286 - .../BesselFunctionsFunctors.h | 357 - .../SpecialFunctions/BesselFunctionsHalf.h | 66 - .../SpecialFunctions/BesselFunctionsImpl.h | 1959 -- .../BesselFunctionsPacketMath.h | 130 - .../SpecialFunctions/HipVectorCompatibility.h | 59 - .../SpecialFunctionsArrayAPI.h | 167 - .../SpecialFunctionsFunctors.h | 330 - .../SpecialFunctions/SpecialFunctionsHalf.h | 58 - .../SpecialFunctions/SpecialFunctionsImpl.h | 2025 -- .../SpecialFunctionsPacketMath.h | 79 - .../arch/GPU/GpuSpecialFunctions.h | 369 - .../unsupported/Eigen/src/Splines/Spline.h | 507 - .../Eigen/src/Splines/SplineFitting.h | 431 - .../unsupported/Eigen/src/Splines/SplineFwd.h | 93 - .../share/eigen3/cmake/Eigen3Config.cmake | 37 - .../eigen3/cmake/Eigen3ConfigVersion.cmake | 51 - .../share/eigen3/cmake/Eigen3Targets.cmake | 98 - .../eigen/share/eigen3/cmake/UseEigen3.cmake | 6 - external/pybind11 | 1 + external/pybind11/include/pybind11/attr.h | 493 - .../pybind11/include/pybind11/buffer_info.h | 108 - external/pybind11/include/pybind11/cast.h | 2157 -- external/pybind11/include/pybind11/chrono.h | 184 - external/pybind11/include/pybind11/common.h | 2 - external/pybind11/include/pybind11/complex.h | 65 - .../pybind11/include/pybind11/detail/class.h | 632 - .../pybind11/include/pybind11/detail/common.h | 808 - .../pybind11/include/pybind11/detail/descr.h | 100 - .../pybind11/include/pybind11/detail/init.h | 335 - .../include/pybind11/detail/internals.h | 336 - .../pybind11/include/pybind11/detail/typeid.h | 55 - external/pybind11/include/pybind11/eigen.h | 607 - external/pybind11/include/pybind11/embed.h | 202 - external/pybind11/include/pybind11/eval.h | 117 - .../pybind11/include/pybind11/functional.h | 101 - external/pybind11/include/pybind11/iostream.h | 209 - external/pybind11/include/pybind11/numpy.h | 1642 -- .../pybind11/include/pybind11/operators.h | 168 - external/pybind11/include/pybind11/options.h | 65 - external/pybind11/include/pybind11/pybind11.h | 2183 --- external/pybind11/include/pybind11/pytypes.h | 1484 -- external/pybind11/include/pybind11/stl.h | 386 - external/pybind11/include/pybind11/stl_bind.h | 649 - .../cmake/pybind11/FindPythonLibsNew.cmake | 202 - .../share/cmake/pybind11/pybind11Config.cmake | 128 - .../pybind11/pybind11ConfigVersion.cmake | 37 - .../cmake/pybind11/pybind11Targets.cmake | 113 - .../share/cmake/pybind11/pybind11Tools.cmake | 227 - 557 files changed, 78 insertions(+), 211412 deletions(-) create mode 100644 .gitmodules create mode 100644 cpp/test/taocommon.cc create mode 100644 cpp/test/teigen.cc create mode 100644 cpp/test/tpybind11.cc delete mode 100644 external/CMakeLists.txt create mode 160000 external/aocommon create mode 160000 external/eigen delete mode 100644 external/eigen/include/eigen3/Eigen/Cholesky delete mode 100644 external/eigen/include/eigen3/Eigen/CholmodSupport delete mode 100644 external/eigen/include/eigen3/Eigen/Core delete mode 100644 external/eigen/include/eigen3/Eigen/Dense delete mode 100644 external/eigen/include/eigen3/Eigen/Eigen delete mode 100644 external/eigen/include/eigen3/Eigen/Eigenvalues delete mode 100644 external/eigen/include/eigen3/Eigen/Geometry delete mode 100644 external/eigen/include/eigen3/Eigen/Householder delete mode 100644 external/eigen/include/eigen3/Eigen/IterativeLinearSolvers delete mode 100644 external/eigen/include/eigen3/Eigen/Jacobi delete mode 100644 external/eigen/include/eigen3/Eigen/KLUSupport delete mode 100644 external/eigen/include/eigen3/Eigen/LU delete mode 100644 external/eigen/include/eigen3/Eigen/MetisSupport delete mode 100644 external/eigen/include/eigen3/Eigen/OrderingMethods delete mode 100644 external/eigen/include/eigen3/Eigen/PaStiXSupport delete mode 100644 external/eigen/include/eigen3/Eigen/PardisoSupport delete mode 100644 external/eigen/include/eigen3/Eigen/QR delete mode 100644 external/eigen/include/eigen3/Eigen/QtAlignedMalloc delete mode 100644 external/eigen/include/eigen3/Eigen/SPQRSupport delete mode 100644 external/eigen/include/eigen3/Eigen/SVD delete mode 100644 external/eigen/include/eigen3/Eigen/Sparse delete mode 100644 external/eigen/include/eigen3/Eigen/SparseCholesky delete mode 100644 external/eigen/include/eigen3/Eigen/SparseCore delete mode 100644 external/eigen/include/eigen3/Eigen/SparseLU delete mode 100644 external/eigen/include/eigen3/Eigen/SparseQR delete mode 100644 external/eigen/include/eigen3/Eigen/StdDeque delete mode 100644 external/eigen/include/eigen3/Eigen/StdList delete mode 100644 external/eigen/include/eigen3/Eigen/StdVector delete mode 100644 external/eigen/include/eigen3/Eigen/SuperLUSupport delete mode 100644 external/eigen/include/eigen3/Eigen/UmfPackSupport delete mode 100644 external/eigen/include/eigen3/Eigen/src/Cholesky/LDLT.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Cholesky/LLT.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Cholesky/LLT_LAPACKE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/CholmodSupport/CholmodSupport.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/ArithmeticSequence.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Array.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/ArrayBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/ArrayWrapper.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Assign.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/AssignEvaluator.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Assign_MKL.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/BandMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Block.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/BooleanRedux.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/CommaInitializer.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/ConditionEstimator.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/CoreEvaluators.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/CoreIterators.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/CwiseNullaryOp.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/CwiseTernaryOp.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/CwiseUnaryOp.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/CwiseUnaryView.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/DenseBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/DenseStorage.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Diagonal.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/DiagonalMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/DiagonalProduct.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Dot.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/EigenBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/ForceAlignedAccess.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Fuzzy.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/GeneralProduct.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/GenericPacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/GlobalFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/IO.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/IndexedView.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Inverse.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Map.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/MapBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/MathFunctionsImpl.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Matrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/MatrixBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/NestByValue.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/NoAlias.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/NumTraits.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/PartialReduxEvaluator.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/PermutationMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/PlainObjectBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Product.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/ProductEvaluators.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Random.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Redux.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Ref.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Replicate.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Reshaped.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/ReturnByValue.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Reverse.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Select.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/SelfAdjointView.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/SelfCwiseBinaryOp.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Solve.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/SolveTriangular.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/SolverBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/StableNorm.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/StlIterators.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Stride.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Swap.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Transpose.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Transpositions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/TriangularMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/VectorBlock.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/VectorwiseOp.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/Visitor.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/Complex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/TypeCasting.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/Complex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/TypeCasting.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/Complex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/CUDA/Complex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/Default/ConjHelper.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/Default/Half.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/Default/Settings.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/Default/TypeCasting.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/TypeCasting.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/HIP/hcc/math_constants.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/Complex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/Complex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/TypeCasting.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/Complex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/TypeCasting.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/InteropHeaders.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/TypeCasting.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/Complex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/PacketMath.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/functors/AssignmentFunctors.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/functors/BinaryFunctors.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/functors/NullaryFunctors.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/functors/StlFunctors.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/functors/TernaryFunctors.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/functors/UnaryFunctors.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixVector.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/Parallelizer.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointProduct.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointRank2Update.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixVector.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverVector.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/BlasUtil.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/Constants.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/DisableStupidWarnings.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/IndexedViewHelper.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/IntegralConstant.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/MKL_support.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/Macros.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/Memory.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/Meta.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/NonMPL2.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/ReenableStupidWarnings.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/ReshapedHelper.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/StaticAssert.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/SymbolicIndex.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Core/util/XprHelper.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexEigenSolver.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexSchur.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/EigenSolver.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/HessenbergDecomposition.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealQZ.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealSchur.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Eigenvalues/Tridiagonalization.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/AlignedBox.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/AngleAxis.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/EulerAngles.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/Homogeneous.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/Hyperplane.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/OrthoMethods.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/ParametrizedLine.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/Quaternion.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/Rotation2D.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/RotationBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/Scaling.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/Transform.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/Translation.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/Umeyama.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Geometry/arch/Geometry_SSE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Householder/BlockHouseholder.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Householder/Householder.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Householder/HouseholderSequence.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/Jacobi/Jacobi.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/KLUSupport/KLUSupport.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/LU/Determinant.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/LU/FullPivLU.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/LU/InverseImpl.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/LU/PartialPivLU.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/LU/PartialPivLU_LAPACKE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/LU/arch/Inverse_SSE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/MetisSupport/MetisSupport.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/OrderingMethods/Amd.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/OrderingMethods/Eigen_Colamd.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/OrderingMethods/Ordering.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/PaStiXSupport/PaStiXSupport.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/PardisoSupport/PardisoSupport.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/QR/ColPivHouseholderQR.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/QR/CompleteOrthogonalDecomposition.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/QR/FullPivHouseholderQR.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/QR/HouseholderQR.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/QR/HouseholderQR_LAPACKE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SVD/BDCSVD.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SVD/JacobiSVD.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SVD/JacobiSVD_LAPACKE.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SVD/SVDBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SVD/UpperBidiagonalization.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCholesky/SimplicialCholesky.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/AmbiVector.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/CompressedStorage.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/MappedSparseMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseAssign.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseBlock.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseColEtree.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCompressedBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCwiseBinaryOp.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCwiseUnaryOp.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDenseProduct.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDiagonalProduct.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDot.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseFuzzy.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMap.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMatrixBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparsePermutation.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseProduct.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseRedux.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseRef.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSelfAdjointView.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSolverBase.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSparseProductWithPruning.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseTranspose.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseTriangularView.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseUtil.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseVector.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/SparseView.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseCore/TriangularSolver.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLUImpl.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Memory.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Structs.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Utils.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_column_bmod.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_column_dfs.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_gemm_kernel.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_kernel_bmod.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_panel_bmod.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_panel_dfs.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_pivotL.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_pruneL.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_relax_snode.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SparseQR/SparseQR.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/StlSupport/StdDeque.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/StlSupport/StdList.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/StlSupport/StdVector.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/StlSupport/details.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/SuperLUSupport/SuperLUSupport.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/UmfPackSupport/UmfPackSupport.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/misc/Image.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/misc/Kernel.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/misc/RealSvd2x2.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/misc/blas.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/misc/lapack.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/misc/lapacke.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/misc/lapacke_mangling.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/ArrayCwiseBinaryOps.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/ArrayCwiseUnaryOps.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/BlockMethods.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/CommonCwiseUnaryOps.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/IndexedViewMethods.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/MatrixCwiseBinaryOps.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/MatrixCwiseUnaryOps.h delete mode 100644 external/eigen/include/eigen3/Eigen/src/plugins/ReshapedMethods.h delete mode 100644 external/eigen/include/eigen3/signature_of_eigen3_matrix_library delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/AdolcForward delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/AlignedVector3 delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/ArpackSupport delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/AutoDiff delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/BVH delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/Tensor delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/TensorSymmetry delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/ThreadPool delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/Tensor.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorArgMax.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBroadcasting.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorChipping.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConcatenation.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionBlocking.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionCuda.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionGpu.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionSycl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionThreadPool.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConversion.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConvolution.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConvolutionSycl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorCostModel.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceDefault.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceGpu.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvalTo.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFFT.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFixedSize.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGenerator.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGlobalFunctions.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaUndefines.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIO.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorImagePatch.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorInflation.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorInitializer.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorLayoutSwap.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMap.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorPatch.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionGpu.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorRef.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReverse.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorScan.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorScanSycl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorShuffling.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStriding.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorVolumePatch.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/DynamicSymmetry.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/StaticSymmetry.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/Symmetry.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/util/TemplateGroupTheory.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/Barrier.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/EventCount.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/RunQueue.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadCancel.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadEnvironment.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadPoolInterface.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadYield.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/CXX11Meta.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/CXX11Workarounds.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/EmulateArray.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/EulerAngles delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/FFT delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/IterativeSolvers delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/KroneckerProduct delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/LevenbergMarquardt delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/MPRealSupport delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/MatrixFunctions delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/MoreVectorization delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/NonLinearOptimization delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/NumericalDiff delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/OpenGLSupport delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/Polynomials delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/Skyline delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/SparseExtra delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/SpecialFunctions delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/Splines delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffJacobian.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffVector.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/BVH/BVAlgorithms.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/BVH/KdBVH.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Eigenvalues/ArpackSelfAdjointEigenSolver.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/EulerAngles/EulerAngles.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/EulerAngles/EulerSystem.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/FFT/ei_fftw_impl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/FFT/ei_kissfft_impl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/ConstrainedConjGrad.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/DGMRES.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/GMRES.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/IncompleteLU.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/IterationController.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/MINRES.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/Scaling.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMcovar.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMonestep.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMpar.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMqrsolv.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/StemFunction.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/MoreVectorization/MathFunctions.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/chkder.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/covar.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/dogleg.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/fdjac1.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/lmpar.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/qrsolv.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/r1mpyq.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/r1updt.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/rwupdt.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/NumericalDiff/NumericalDiff.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/Companion.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/PolynomialSolver.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/PolynomialUtils.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineInplaceLU.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineMatrix.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineProduct.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineStorage.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineUtil.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/BlockOfDynamicSparseMatrix.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/RandomSetter.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsArrayAPI.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsFunctors.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsHalf.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsImpl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsPacketMath.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/HipVectorCompatibility.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsArrayAPI.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsFunctors.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsHalf.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsImpl.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsPacketMath.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/arch/GPU/GpuSpecialFunctions.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Splines/Spline.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Splines/SplineFitting.h delete mode 100644 external/eigen/include/eigen3/unsupported/Eigen/src/Splines/SplineFwd.h delete mode 100644 external/eigen/share/eigen3/cmake/Eigen3Config.cmake delete mode 100644 external/eigen/share/eigen3/cmake/Eigen3ConfigVersion.cmake delete mode 100644 external/eigen/share/eigen3/cmake/Eigen3Targets.cmake delete mode 100644 external/eigen/share/eigen3/cmake/UseEigen3.cmake create mode 160000 external/pybind11 delete mode 100644 external/pybind11/include/pybind11/attr.h delete mode 100644 external/pybind11/include/pybind11/buffer_info.h delete mode 100644 external/pybind11/include/pybind11/cast.h delete mode 100644 external/pybind11/include/pybind11/chrono.h delete mode 100644 external/pybind11/include/pybind11/common.h delete mode 100644 external/pybind11/include/pybind11/complex.h delete mode 100644 external/pybind11/include/pybind11/detail/class.h delete mode 100644 external/pybind11/include/pybind11/detail/common.h delete mode 100644 external/pybind11/include/pybind11/detail/descr.h delete mode 100644 external/pybind11/include/pybind11/detail/init.h delete mode 100644 external/pybind11/include/pybind11/detail/internals.h delete mode 100644 external/pybind11/include/pybind11/detail/typeid.h delete mode 100644 external/pybind11/include/pybind11/eigen.h delete mode 100644 external/pybind11/include/pybind11/embed.h delete mode 100644 external/pybind11/include/pybind11/eval.h delete mode 100644 external/pybind11/include/pybind11/functional.h delete mode 100644 external/pybind11/include/pybind11/iostream.h delete mode 100644 external/pybind11/include/pybind11/numpy.h delete mode 100644 external/pybind11/include/pybind11/operators.h delete mode 100644 external/pybind11/include/pybind11/options.h delete mode 100644 external/pybind11/include/pybind11/pybind11.h delete mode 100644 external/pybind11/include/pybind11/pytypes.h delete mode 100644 external/pybind11/include/pybind11/stl.h delete mode 100644 external/pybind11/include/pybind11/stl_bind.h delete mode 100644 external/pybind11/share/cmake/pybind11/FindPythonLibsNew.cmake delete mode 100644 external/pybind11/share/cmake/pybind11/pybind11Config.cmake delete mode 100644 external/pybind11/share/cmake/pybind11/pybind11ConfigVersion.cmake delete mode 100644 external/pybind11/share/cmake/pybind11/pybind11Targets.cmake delete mode 100644 external/pybind11/share/cmake/pybind11/pybind11Tools.cmake diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..9906b7f0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "external/aocommon"] + path = external/aocommon + url = https://gitlab.com/aroffringa/aocommon.git +[submodule "external/eigen"] + path = external/eigen + url = https://gitlab.com/libeigen/eigen.git +[submodule "external/pybind11"] + path = external/pybind11 + url = https://github.com/pybind/pybind11.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 257feac9..a710cef4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,27 @@ set(CMAKE_INSTALL_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/${projectname}") message("Storing data in: " ${CMAKE_INSTALL_DATA_DIR}) configure_file(${CMAKE_SOURCE_DIR}/CMake/config.h.in ${CMAKE_BINARY_DIR}/config.h) +# Find and include git submodules +find_package(Git QUIET) +if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") +# Update submodules as needed + option(GIT_SUBMODULE "Check submodules during build" ON) + if(GIT_SUBMODULE) + message(STATUS "Submodule update") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --checkout + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() + endif() +endif() + +# Include aocommon/eigen3/pybind11 headers +include_directories("${CMAKE_SOURCE_DIR}/external/aocommon/include/") +include_directories("${CMAKE_SOURCE_DIR}/external/eigen/") +add_subdirectory("${CMAKE_SOURCE_DIR}/external/pybind11") + # Find and include HDF5 find_package(HDF5 COMPONENTS C CXX REQUIRED) add_definitions(${HDF5_DEFINITIONS}) @@ -44,7 +65,7 @@ add_compile_options(-std=c++11 "${OpenMP_CXX_FLAGS}" -Wall -DNDEBUG -Wl,--no-und #------------------------------------------------------------------------------ # Find/load top level dependencies -add_subdirectory(external) +# add_subdirectory(external) #------------------------------------------------------------------------------ # Add source diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt index 6eb6fe91..25798968 100644 --- a/cpp/test/CMakeLists.txt +++ b/cpp/test/CMakeLists.txt @@ -4,6 +4,13 @@ add_executable(tstation tstation.cc) target_link_libraries(tstation PUBLIC everybeam) target_link_libraries(tstation PUBLIC OpenMP::OpenMP_CXX) +add_executable(taocommon taocommon.cc) +add_executable(teigen teigen.cc) +add_executable(tpybind11 tpybind11.cc) +target_link_libraries(tpybind11 PRIVATE pybind11::embed) #------------------------------------------------------------------------------ # Add test -add_test(station-tests tstation) \ No newline at end of file +add_test(station-tests tstation) +add_test(submodule-tests taocommon) +add_test(submodule-tests teigen) +add_test(submodule-tests tpybind11) \ No newline at end of file diff --git a/cpp/test/taocommon.cc b/cpp/test/taocommon.cc new file mode 100644 index 00000000..7007eb4b --- /dev/null +++ b/cpp/test/taocommon.cc @@ -0,0 +1,10 @@ +#include <aocommon/matrix2x2.h> +#include <iostream> + +int main() { + double unit[4] = {1.0, 0.0, 0.0, 1.0}; + double e1, e2; + Matrix2x2::EigenValues(unit, e1, e2); + std::cout << "EigenValue 1 " << e1 << "\nEigenvalue 2 " << e2 << std::endl; + return 0; +} diff --git a/cpp/test/teigen.cc b/cpp/test/teigen.cc new file mode 100644 index 00000000..103ddd5a --- /dev/null +++ b/cpp/test/teigen.cc @@ -0,0 +1,13 @@ +#include <iostream> +#include <Eigen/Dense> + +using Eigen::MatrixXd; + +int main() { + MatrixXd m(2, 2); + m(0, 0) = 3; + m(1, 0) = 2.5; + m(0, 1) = -1; + m(1, 1) = m(1, 0) + m(0, 1); + std::cout << m << std::endl; +} diff --git a/cpp/test/tpybind11.cc b/cpp/test/tpybind11.cc new file mode 100644 index 00000000..20e9e68b --- /dev/null +++ b/cpp/test/tpybind11.cc @@ -0,0 +1,7 @@ +#include <pybind11/pybind11.h> +#include <pybind11/eigen.h> + +int main() { + // Empty, just check if headers are correctly found + return 0; +} \ No newline at end of file diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt deleted file mode 100644 index ccd9aa1f..00000000 --- a/external/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -find_package (pybind11 PATHS pybind11 NO_DEFAULT_PATH REQUIRED) -find_package (Eigen3 PATHS eigen NO_DEFAULT_PATH REQUIRED) diff --git a/external/README.md b/external/README.md index fb942129..0932f0e6 100644 --- a/external/README.md +++ b/external/README.md @@ -1,26 +1,9 @@ -External dependencies included in source tree +External dependencies are included via git submodules, see .gitmodules in the root of the source. -Subdirectories were created as described below. +Please note that the dependencies are fixed to a specific commit, to make sure tests do not break due to +a silent updateing of the submodules. Dependencies are checked out on the following commits: +- `aocommon`: be6072490469977f513722b87f3032812438e968 +- `eigen`: `3.3.7` (https://gitlab.com/libeigen/eigen/-/tags/3.3.7) +- `pybind11`: `v2.5.0` (https://github.com/pybind/pybind11/releases/tag/v2.5.0) -Install pybind11 into LOFARBeam source tree - - - git clone https://github.com/pybind/pybind11.git - cd pybind11 - git checkout v2.4.3 - mkdir build - cd build - cmake .. -DCMAKE_INSTALL_PREFIX=<srcdir>/LOFARBeam/external/pybind11 - make install - - -Install Eigen3 into LOFARBeam source tree - - git clone https://gitlab.com/libeigen/eigen.git - cd eigen - git checkout 'master@{2020-01-01 00:00:00}' - mkdir build - cd build - cmake .. -DCMAKE_INSTALL_PREFIX=<srcdir>/LOFARBeam/external/eigen -DEIGEN_BUILD_PKGCONFIG=Off - make install diff --git a/external/aocommon b/external/aocommon new file mode 160000 index 00000000..be607249 --- /dev/null +++ b/external/aocommon @@ -0,0 +1 @@ +Subproject commit be6072490469977f513722b87f3032812438e968 diff --git a/external/eigen b/external/eigen new file mode 160000 index 00000000..21ae2afd --- /dev/null +++ b/external/eigen @@ -0,0 +1 @@ +Subproject commit 21ae2afd4edaa1b69782c67a54182d34efe43f9c diff --git a/external/eigen/include/eigen3/Eigen/Cholesky b/external/eigen/include/eigen3/Eigen/Cholesky deleted file mode 100644 index 1332b540..00000000 --- a/external/eigen/include/eigen3/Eigen/Cholesky +++ /dev/null @@ -1,46 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CHOLESKY_MODULE_H -#define EIGEN_CHOLESKY_MODULE_H - -#include "Core" -#include "Jacobi" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup Cholesky_Module Cholesky module - * - * - * - * This module provides two variants of the Cholesky decomposition for selfadjoint (hermitian) matrices. - * Those decompositions are also accessible via the following methods: - * - MatrixBase::llt() - * - MatrixBase::ldlt() - * - SelfAdjointView::llt() - * - SelfAdjointView::ldlt() - * - * \code - * #include <Eigen/Cholesky> - * \endcode - */ - -#include "src/Cholesky/LLT.h" -#include "src/Cholesky/LDLT.h" -#ifdef EIGEN_USE_LAPACKE -#ifdef EIGEN_USE_MKL -#include "mkl_lapacke.h" -#else -#include "src/misc/lapacke.h" -#endif -#include "src/Cholesky/LLT_LAPACKE.h" -#endif - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_CHOLESKY_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/Eigen/CholmodSupport b/external/eigen/include/eigen3/Eigen/CholmodSupport deleted file mode 100644 index bed8924d..00000000 --- a/external/eigen/include/eigen3/Eigen/CholmodSupport +++ /dev/null @@ -1,48 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CHOLMODSUPPORT_MODULE_H -#define EIGEN_CHOLMODSUPPORT_MODULE_H - -#include "SparseCore" - -#include "src/Core/util/DisableStupidWarnings.h" - -extern "C" { - #include <cholmod.h> -} - -/** \ingroup Support_modules - * \defgroup CholmodSupport_Module CholmodSupport module - * - * This module provides an interface to the Cholmod library which is part of the <a href="http://www.suitesparse.com">suitesparse</a> package. - * It provides the two following main factorization classes: - * - class CholmodSupernodalLLT: a supernodal LLT Cholesky factorization. - * - class CholmodDecomposiiton: a general L(D)LT Cholesky factorization with automatic or explicit runtime selection of the underlying factorization method (supernodal or simplicial). - * - * For the sake of completeness, this module also propose the two following classes: - * - class CholmodSimplicialLLT - * - class CholmodSimplicialLDLT - * Note that these classes does not bring any particular advantage compared to the built-in - * SimplicialLLT and SimplicialLDLT factorization classes. - * - * \code - * #include <Eigen/CholmodSupport> - * \endcode - * - * In order to use this module, the cholmod headers must be accessible from the include paths, and your binary must be linked to the cholmod library and its dependencies. - * The dependencies depend on how cholmod has been compiled. - * For a cmake based project, you can use our FindCholmod.cmake module to help you in this task. - * - */ - -#include "src/CholmodSupport/CholmodSupport.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_CHOLMODSUPPORT_MODULE_H - diff --git a/external/eigen/include/eigen3/Eigen/Core b/external/eigen/include/eigen3/Eigen/Core deleted file mode 100644 index bb8ad464..00000000 --- a/external/eigen/include/eigen3/Eigen/Core +++ /dev/null @@ -1,361 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2007-2011 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CORE_H -#define EIGEN_CORE_H - -// first thing Eigen does: stop the compiler from committing suicide -#include "src/Core/util/DisableStupidWarnings.h" - -// then include this file where all our macros are defined. It's really important to do it first because -// it's where we do all the compiler/OS/arch detections and define most defaults. -#include "src/Core/util/Macros.h" - -// This detects SSE/AVX/NEON/etc. and configure alignment settings -#include "src/Core/util/ConfigureVectorization.h" - -// We need cuda_runtime.h/hip_runtime.h to ensure that -// the EIGEN_USING_STD_MATH macro works properly on the device side -#if defined(EIGEN_CUDACC) - #include <cuda_runtime.h> -#elif defined(EIGEN_HIPCC) - #include <hip/hip_runtime.h> -#endif - - -#ifdef EIGEN_EXCEPTIONS - #include <new> -#endif - -// Disable the ipa-cp-clone optimization flag with MinGW 6.x or newer (enabled by default with -O3) -// See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=556 for details. -#if EIGEN_COMP_MINGW && EIGEN_GNUC_AT_LEAST(4,6) - #pragma GCC optimize ("-fno-ipa-cp-clone") -#endif - -#include <complex> - -// this include file manages BLAS and MKL related macros -// and inclusion of their respective header files -#include "src/Core/util/MKL_support.h" - - -#if defined(EIGEN_HAS_CUDA_FP16) || defined(EIGEN_HAS_HIP_FP16) - #define EIGEN_HAS_GPU_FP16 -#endif - -#if (defined _OPENMP) && (!defined EIGEN_DONT_PARALLELIZE) - #define EIGEN_HAS_OPENMP -#endif - -#ifdef EIGEN_HAS_OPENMP -#include <omp.h> -#endif - -// MSVC for windows mobile does not have the errno.h file -#if !(EIGEN_COMP_MSVC && EIGEN_OS_WINCE) && !EIGEN_COMP_ARM -#define EIGEN_HAS_ERRNO -#endif - -#ifdef EIGEN_HAS_ERRNO -#include <cerrno> -#endif -#include <cstddef> -#include <cstdlib> -#include <cmath> -#include <cassert> -#include <functional> -#ifndef EIGEN_NO_IO - #include <iosfwd> -#endif -#include <cstring> -#include <string> -#include <limits> -#include <climits> // for CHAR_BIT -// for min/max: -#include <algorithm> - -#if EIGEN_HAS_CXX11 -#include <array> -#endif - -// for std::is_nothrow_move_assignable -#ifdef EIGEN_INCLUDE_TYPE_TRAITS -#include <type_traits> -#endif - -// for outputting debug info -#ifdef EIGEN_DEBUG_ASSIGN -#include <iostream> -#endif - -// required for __cpuid, needs to be included after cmath -#if EIGEN_COMP_MSVC && EIGEN_ARCH_i386_OR_x86_64 && !EIGEN_OS_WINCE - #include <intrin.h> -#endif - -#if defined(EIGEN_USE_SYCL) - #undef min - #undef max - #undef isnan - #undef isinf - #undef isfinite - #include <SYCL/sycl.hpp> - #include <map> - #include <memory> - #include <utility> - #include <thread> - #ifndef EIGEN_SYCL_LOCAL_THREAD_DIM0 - #define EIGEN_SYCL_LOCAL_THREAD_DIM0 16 - #endif - #ifndef EIGEN_SYCL_LOCAL_THREAD_DIM1 - #define EIGEN_SYCL_LOCAL_THREAD_DIM1 16 - #endif -#endif - - -#if defined EIGEN2_SUPPORT_STAGE40_FULL_EIGEN3_STRICTNESS || defined EIGEN2_SUPPORT_STAGE30_FULL_EIGEN3_API || defined EIGEN2_SUPPORT_STAGE20_RESOLVE_API_CONFLICTS || defined EIGEN2_SUPPORT_STAGE10_FULL_EIGEN2_API || defined EIGEN2_SUPPORT -// This will generate an error message: -#error Eigen2-support is only available up to version 3.2. Please go to "http://eigen.tuxfamily.org/index.php?title=Eigen2" for further information -#endif - -namespace Eigen { - -// we use size_t frequently and we'll never remember to prepend it with std:: every time just to -// ensure QNX/QCC support -using std::size_t; -// gcc 4.6.0 wants std:: for ptrdiff_t -using std::ptrdiff_t; - -} - -/** \defgroup Core_Module Core module - * This is the main module of Eigen providing dense matrix and vector support - * (both fixed and dynamic size) with all the features corresponding to a BLAS library - * and much more... - * - * \code - * #include <Eigen/Core> - * \endcode - */ - -#include "src/Core/util/Constants.h" -#include "src/Core/util/Meta.h" -#include "src/Core/util/ForwardDeclarations.h" -#include "src/Core/util/StaticAssert.h" -#include "src/Core/util/XprHelper.h" -#include "src/Core/util/Memory.h" -#include "src/Core/util/IntegralConstant.h" -#include "src/Core/util/SymbolicIndex.h" - -#include "src/Core/NumTraits.h" -#include "src/Core/MathFunctions.h" -#include "src/Core/GenericPacketMath.h" -#include "src/Core/MathFunctionsImpl.h" -#include "src/Core/arch/Default/ConjHelper.h" -// Generic half float support -#include "src/Core/arch/Default/Half.h" -#include "src/Core/arch/Default/TypeCasting.h" -#include "src/Core/arch/Default/GenericPacketMathFunctionsFwd.h" - -#if defined EIGEN_VECTORIZE_AVX512 - #include "src/Core/arch/SSE/PacketMath.h" - #include "src/Core/arch/SSE/TypeCasting.h" - #include "src/Core/arch/SSE/Complex.h" - #include "src/Core/arch/AVX/PacketMath.h" - #include "src/Core/arch/AVX/TypeCasting.h" - #include "src/Core/arch/AVX/Complex.h" - #include "src/Core/arch/AVX512/PacketMath.h" - #include "src/Core/arch/AVX512/TypeCasting.h" - #include "src/Core/arch/AVX512/Complex.h" - #include "src/Core/arch/SSE/MathFunctions.h" - #include "src/Core/arch/AVX/MathFunctions.h" - #include "src/Core/arch/AVX512/MathFunctions.h" -#elif defined EIGEN_VECTORIZE_AVX - // Use AVX for floats and doubles, SSE for integers - #include "src/Core/arch/SSE/PacketMath.h" - #include "src/Core/arch/SSE/TypeCasting.h" - #include "src/Core/arch/SSE/Complex.h" - #include "src/Core/arch/AVX/PacketMath.h" - #include "src/Core/arch/AVX/TypeCasting.h" - #include "src/Core/arch/AVX/Complex.h" - #include "src/Core/arch/SSE/MathFunctions.h" - #include "src/Core/arch/AVX/MathFunctions.h" -#elif defined EIGEN_VECTORIZE_SSE - #include "src/Core/arch/SSE/PacketMath.h" - #include "src/Core/arch/SSE/TypeCasting.h" - #include "src/Core/arch/SSE/MathFunctions.h" - #include "src/Core/arch/SSE/Complex.h" -#elif defined(EIGEN_VECTORIZE_ALTIVEC) || defined(EIGEN_VECTORIZE_VSX) - #include "src/Core/arch/AltiVec/PacketMath.h" - #include "src/Core/arch/AltiVec/MathFunctions.h" - #include "src/Core/arch/AltiVec/Complex.h" -#elif defined EIGEN_VECTORIZE_NEON - #include "src/Core/arch/NEON/PacketMath.h" - #include "src/Core/arch/NEON/TypeCasting.h" - #include "src/Core/arch/NEON/MathFunctions.h" - #include "src/Core/arch/NEON/Complex.h" -#elif defined EIGEN_VECTORIZE_ZVECTOR - #include "src/Core/arch/ZVector/PacketMath.h" - #include "src/Core/arch/ZVector/MathFunctions.h" - #include "src/Core/arch/ZVector/Complex.h" -#elif defined EIGEN_VECTORIZE_MSA - #include "src/Core/arch/MSA/PacketMath.h" - #include "src/Core/arch/MSA/MathFunctions.h" - #include "src/Core/arch/MSA/Complex.h" -#endif - -#if defined EIGEN_VECTORIZE_GPU - #include "src/Core/arch/GPU/PacketMath.h" - #include "src/Core/arch/GPU/MathFunctions.h" - #include "src/Core/arch/GPU/TypeCasting.h" -#endif - -#if defined(EIGEN_USE_SYCL) - #include "src/Core/arch/SYCL/SyclMemoryModel.h" - #include "src/Core/arch/SYCL/InteropHeaders.h" -#if !defined(EIGEN_DONT_VECTORIZE_SYCL) - #include "src/Core/arch/SYCL/PacketMath.h" - #include "src/Core/arch/SYCL/MathFunctions.h" - #include "src/Core/arch/SYCL/TypeCasting.h" -#endif -#endif - -#include "src/Core/arch/Default/Settings.h" -// This file provides generic implementations valid for scalar as well -#include "src/Core/arch/Default/GenericPacketMathFunctions.h" - -#include "src/Core/functors/TernaryFunctors.h" -#include "src/Core/functors/BinaryFunctors.h" -#include "src/Core/functors/UnaryFunctors.h" -#include "src/Core/functors/NullaryFunctors.h" -#include "src/Core/functors/StlFunctors.h" -#include "src/Core/functors/AssignmentFunctors.h" - -// Specialized functors to enable the processing of complex numbers -// on CUDA devices -#ifdef EIGEN_CUDACC -#include "src/Core/arch/CUDA/Complex.h" -#endif - -#include "src/Core/util/IndexedViewHelper.h" -#include "src/Core/util/ReshapedHelper.h" -#include "src/Core/ArithmeticSequence.h" -#ifndef EIGEN_NO_IO - #include "src/Core/IO.h" -#endif -#include "src/Core/DenseCoeffsBase.h" -#include "src/Core/DenseBase.h" -#include "src/Core/MatrixBase.h" -#include "src/Core/EigenBase.h" - -#include "src/Core/Product.h" -#include "src/Core/CoreEvaluators.h" -#include "src/Core/AssignEvaluator.h" - -#ifndef EIGEN_PARSED_BY_DOXYGEN // work around Doxygen bug triggered by Assign.h r814874 - // at least confirmed with Doxygen 1.5.5 and 1.5.6 - #include "src/Core/Assign.h" -#endif - -#include "src/Core/ArrayBase.h" -#include "src/Core/util/BlasUtil.h" -#include "src/Core/DenseStorage.h" -#include "src/Core/NestByValue.h" - -// #include "src/Core/ForceAlignedAccess.h" - -#include "src/Core/ReturnByValue.h" -#include "src/Core/NoAlias.h" -#include "src/Core/PlainObjectBase.h" -#include "src/Core/Matrix.h" -#include "src/Core/Array.h" -#include "src/Core/CwiseTernaryOp.h" -#include "src/Core/CwiseBinaryOp.h" -#include "src/Core/CwiseUnaryOp.h" -#include "src/Core/CwiseNullaryOp.h" -#include "src/Core/CwiseUnaryView.h" -#include "src/Core/SelfCwiseBinaryOp.h" -#include "src/Core/Dot.h" -#include "src/Core/StableNorm.h" -#include "src/Core/Stride.h" -#include "src/Core/MapBase.h" -#include "src/Core/Map.h" -#include "src/Core/Ref.h" -#include "src/Core/Block.h" -#include "src/Core/VectorBlock.h" -#include "src/Core/IndexedView.h" -#include "src/Core/Reshaped.h" -#include "src/Core/Transpose.h" -#include "src/Core/DiagonalMatrix.h" -#include "src/Core/Diagonal.h" -#include "src/Core/DiagonalProduct.h" -#include "src/Core/Redux.h" -#include "src/Core/Visitor.h" -#include "src/Core/Fuzzy.h" -#include "src/Core/Swap.h" -#include "src/Core/CommaInitializer.h" -#include "src/Core/GeneralProduct.h" -#include "src/Core/Solve.h" -#include "src/Core/Inverse.h" -#include "src/Core/SolverBase.h" -#include "src/Core/PermutationMatrix.h" -#include "src/Core/Transpositions.h" -#include "src/Core/TriangularMatrix.h" -#include "src/Core/SelfAdjointView.h" -#include "src/Core/products/GeneralBlockPanelKernel.h" -#include "src/Core/products/Parallelizer.h" -#include "src/Core/ProductEvaluators.h" -#include "src/Core/products/GeneralMatrixVector.h" -#include "src/Core/products/GeneralMatrixMatrix.h" -#include "src/Core/SolveTriangular.h" -#include "src/Core/products/GeneralMatrixMatrixTriangular.h" -#include "src/Core/products/SelfadjointMatrixVector.h" -#include "src/Core/products/SelfadjointMatrixMatrix.h" -#include "src/Core/products/SelfadjointProduct.h" -#include "src/Core/products/SelfadjointRank2Update.h" -#include "src/Core/products/TriangularMatrixVector.h" -#include "src/Core/products/TriangularMatrixMatrix.h" -#include "src/Core/products/TriangularSolverMatrix.h" -#include "src/Core/products/TriangularSolverVector.h" -#include "src/Core/BandMatrix.h" -#include "src/Core/CoreIterators.h" -#include "src/Core/ConditionEstimator.h" - -#include "src/Core/BooleanRedux.h" -#include "src/Core/Select.h" -#include "src/Core/VectorwiseOp.h" -#include "src/Core/PartialReduxEvaluator.h" -#include "src/Core/Random.h" -#include "src/Core/Replicate.h" -#include "src/Core/Reverse.h" -#include "src/Core/ArrayWrapper.h" -#include "src/Core/StlIterators.h" - -#ifdef EIGEN_USE_BLAS -#include "src/Core/products/GeneralMatrixMatrix_BLAS.h" -#include "src/Core/products/GeneralMatrixVector_BLAS.h" -#include "src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h" -#include "src/Core/products/SelfadjointMatrixMatrix_BLAS.h" -#include "src/Core/products/SelfadjointMatrixVector_BLAS.h" -#include "src/Core/products/TriangularMatrixMatrix_BLAS.h" -#include "src/Core/products/TriangularMatrixVector_BLAS.h" -#include "src/Core/products/TriangularSolverMatrix_BLAS.h" -#endif // EIGEN_USE_BLAS - -#ifdef EIGEN_USE_MKL_VML -#include "src/Core/Assign_MKL.h" -#endif - -#include "src/Core/GlobalFunctions.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_CORE_H diff --git a/external/eigen/include/eigen3/Eigen/Dense b/external/eigen/include/eigen3/Eigen/Dense deleted file mode 100644 index 5768910b..00000000 --- a/external/eigen/include/eigen3/Eigen/Dense +++ /dev/null @@ -1,7 +0,0 @@ -#include "Core" -#include "LU" -#include "Cholesky" -#include "QR" -#include "SVD" -#include "Geometry" -#include "Eigenvalues" diff --git a/external/eigen/include/eigen3/Eigen/Eigen b/external/eigen/include/eigen3/Eigen/Eigen deleted file mode 100644 index 654c8dc6..00000000 --- a/external/eigen/include/eigen3/Eigen/Eigen +++ /dev/null @@ -1,2 +0,0 @@ -#include "Dense" -#include "Sparse" diff --git a/external/eigen/include/eigen3/Eigen/Eigenvalues b/external/eigen/include/eigen3/Eigen/Eigenvalues deleted file mode 100644 index 7d6ac787..00000000 --- a/external/eigen/include/eigen3/Eigen/Eigenvalues +++ /dev/null @@ -1,61 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_EIGENVALUES_MODULE_H -#define EIGEN_EIGENVALUES_MODULE_H - -#include "Core" - -#include "Cholesky" -#include "Jacobi" -#include "Householder" -#include "LU" -#include "Geometry" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup Eigenvalues_Module Eigenvalues module - * - * - * - * This module mainly provides various eigenvalue solvers. - * This module also provides some MatrixBase methods, including: - * - MatrixBase::eigenvalues(), - * - MatrixBase::operatorNorm() - * - * \code - * #include <Eigen/Eigenvalues> - * \endcode - */ - -#include "src/misc/RealSvd2x2.h" -#include "src/Eigenvalues/Tridiagonalization.h" -#include "src/Eigenvalues/RealSchur.h" -#include "src/Eigenvalues/EigenSolver.h" -#include "src/Eigenvalues/SelfAdjointEigenSolver.h" -#include "src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h" -#include "src/Eigenvalues/HessenbergDecomposition.h" -#include "src/Eigenvalues/ComplexSchur.h" -#include "src/Eigenvalues/ComplexEigenSolver.h" -#include "src/Eigenvalues/RealQZ.h" -#include "src/Eigenvalues/GeneralizedEigenSolver.h" -#include "src/Eigenvalues/MatrixBaseEigenvalues.h" -#ifdef EIGEN_USE_LAPACKE -#ifdef EIGEN_USE_MKL -#include "mkl_lapacke.h" -#else -#include "src/misc/lapacke.h" -#endif -#include "src/Eigenvalues/RealSchur_LAPACKE.h" -#include "src/Eigenvalues/ComplexSchur_LAPACKE.h" -#include "src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h" -#endif - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_EIGENVALUES_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/Eigen/Geometry b/external/eigen/include/eigen3/Eigen/Geometry deleted file mode 100644 index 16b4bd6e..00000000 --- a/external/eigen/include/eigen3/Eigen/Geometry +++ /dev/null @@ -1,60 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GEOMETRY_MODULE_H -#define EIGEN_GEOMETRY_MODULE_H - -#include "Core" - -#include "SVD" -#include "LU" -#include <limits> - -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup Geometry_Module Geometry module - * - * This module provides support for: - * - fixed-size homogeneous transformations - * - translation, scaling, 2D and 3D rotations - * - \link Quaternion quaternions \endlink - * - cross products (\ref MatrixBase::cross, \ref MatrixBase::cross3) - * - orthognal vector generation (\ref MatrixBase::unitOrthogonal) - * - some linear components: \link ParametrizedLine parametrized-lines \endlink and \link Hyperplane hyperplanes \endlink - * - \link AlignedBox axis aligned bounding boxes \endlink - * - \link umeyama least-square transformation fitting \endlink - * - * \code - * #include <Eigen/Geometry> - * \endcode - */ - -#include "src/Geometry/OrthoMethods.h" -#include "src/Geometry/EulerAngles.h" - -#include "src/Geometry/Homogeneous.h" -#include "src/Geometry/RotationBase.h" -#include "src/Geometry/Rotation2D.h" -#include "src/Geometry/Quaternion.h" -#include "src/Geometry/AngleAxis.h" -#include "src/Geometry/Transform.h" -#include "src/Geometry/Translation.h" -#include "src/Geometry/Scaling.h" -#include "src/Geometry/Hyperplane.h" -#include "src/Geometry/ParametrizedLine.h" -#include "src/Geometry/AlignedBox.h" -#include "src/Geometry/Umeyama.h" - -// Use the SSE optimized version whenever possible. -#if defined EIGEN_VECTORIZE_SSE -#include "src/Geometry/arch/Geometry_SSE.h" -#endif - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_GEOMETRY_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/Eigen/Householder b/external/eigen/include/eigen3/Eigen/Householder deleted file mode 100644 index 89cd81b1..00000000 --- a/external/eigen/include/eigen3/Eigen/Householder +++ /dev/null @@ -1,30 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_HOUSEHOLDER_MODULE_H -#define EIGEN_HOUSEHOLDER_MODULE_H - -#include "Core" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup Householder_Module Householder module - * This module provides Householder transformations. - * - * \code - * #include <Eigen/Householder> - * \endcode - */ - -#include "src/Householder/Householder.h" -#include "src/Householder/HouseholderSequence.h" -#include "src/Householder/BlockHouseholder.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_HOUSEHOLDER_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/Eigen/IterativeLinearSolvers b/external/eigen/include/eigen3/Eigen/IterativeLinearSolvers deleted file mode 100644 index 957d5750..00000000 --- a/external/eigen/include/eigen3/Eigen/IterativeLinearSolvers +++ /dev/null @@ -1,48 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ITERATIVELINEARSOLVERS_MODULE_H -#define EIGEN_ITERATIVELINEARSOLVERS_MODULE_H - -#include "SparseCore" -#include "OrderingMethods" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** - * \defgroup IterativeLinearSolvers_Module IterativeLinearSolvers module - * - * This module currently provides iterative methods to solve problems of the form \c A \c x = \c b, where \c A is a squared matrix, usually very large and sparse. - * Those solvers are accessible via the following classes: - * - ConjugateGradient for selfadjoint (hermitian) matrices, - * - LeastSquaresConjugateGradient for rectangular least-square problems, - * - BiCGSTAB for general square matrices. - * - * These iterative solvers are associated with some preconditioners: - * - IdentityPreconditioner - not really useful - * - DiagonalPreconditioner - also called Jacobi preconditioner, work very well on diagonal dominant matrices. - * - IncompleteLUT - incomplete LU factorization with dual thresholding - * - * Such problems can also be solved using the direct sparse decomposition modules: SparseCholesky, CholmodSupport, UmfPackSupport, SuperLUSupport. - * - \code - #include <Eigen/IterativeLinearSolvers> - \endcode - */ - -#include "src/IterativeLinearSolvers/SolveWithGuess.h" -#include "src/IterativeLinearSolvers/IterativeSolverBase.h" -#include "src/IterativeLinearSolvers/BasicPreconditioners.h" -#include "src/IterativeLinearSolvers/ConjugateGradient.h" -#include "src/IterativeLinearSolvers/LeastSquareConjugateGradient.h" -#include "src/IterativeLinearSolvers/BiCGSTAB.h" -#include "src/IterativeLinearSolvers/IncompleteLUT.h" -#include "src/IterativeLinearSolvers/IncompleteCholesky.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_ITERATIVELINEARSOLVERS_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/Jacobi b/external/eigen/include/eigen3/Eigen/Jacobi deleted file mode 100644 index 17c1d785..00000000 --- a/external/eigen/include/eigen3/Eigen/Jacobi +++ /dev/null @@ -1,33 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_JACOBI_MODULE_H -#define EIGEN_JACOBI_MODULE_H - -#include "Core" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup Jacobi_Module Jacobi module - * This module provides Jacobi and Givens rotations. - * - * \code - * #include <Eigen/Jacobi> - * \endcode - * - * In addition to listed classes, it defines the two following MatrixBase methods to apply a Jacobi or Givens rotation: - * - MatrixBase::applyOnTheLeft() - * - MatrixBase::applyOnTheRight(). - */ - -#include "src/Jacobi/Jacobi.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_JACOBI_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ - diff --git a/external/eigen/include/eigen3/Eigen/KLUSupport b/external/eigen/include/eigen3/Eigen/KLUSupport deleted file mode 100644 index b23d9053..00000000 --- a/external/eigen/include/eigen3/Eigen/KLUSupport +++ /dev/null @@ -1,41 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_KLUSUPPORT_MODULE_H -#define EIGEN_KLUSUPPORT_MODULE_H - -#include <Eigen/SparseCore> - -#include <Eigen/src/Core/util/DisableStupidWarnings.h> - -extern "C" { -#include <btf.h> -#include <klu.h> - } - -/** \ingroup Support_modules - * \defgroup KLUSupport_Module KLUSupport module - * - * This module provides an interface to the KLU library which is part of the <a href="http://www.suitesparse.com">suitesparse</a> package. - * It provides the following factorization class: - * - class KLU: a sparse LU factorization, well-suited for circuit simulation. - * - * \code - * #include <Eigen/KLUSupport> - * \endcode - * - * In order to use this module, the klu and btf headers must be accessible from the include paths, and your binary must be linked to the klu library and its dependencies. - * The dependencies depend on how umfpack has been compiled. - * For a cmake based project, you can use our FindKLU.cmake module to help you in this task. - * - */ - -#include "src/KLUSupport/KLUSupport.h" - -#include <Eigen/src/Core/util/ReenableStupidWarnings.h> - -#endif // EIGEN_KLUSUPPORT_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/LU b/external/eigen/include/eigen3/Eigen/LU deleted file mode 100644 index 6418a86e..00000000 --- a/external/eigen/include/eigen3/Eigen/LU +++ /dev/null @@ -1,50 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_LU_MODULE_H -#define EIGEN_LU_MODULE_H - -#include "Core" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup LU_Module LU module - * This module includes %LU decomposition and related notions such as matrix inversion and determinant. - * This module defines the following MatrixBase methods: - * - MatrixBase::inverse() - * - MatrixBase::determinant() - * - * \code - * #include <Eigen/LU> - * \endcode - */ - -#include "src/misc/Kernel.h" -#include "src/misc/Image.h" -#include "src/LU/FullPivLU.h" -#include "src/LU/PartialPivLU.h" -#ifdef EIGEN_USE_LAPACKE -#ifdef EIGEN_USE_MKL -#include "mkl_lapacke.h" -#else -#include "src/misc/lapacke.h" -#endif -#include "src/LU/PartialPivLU_LAPACKE.h" -#endif -#include "src/LU/Determinant.h" -#include "src/LU/InverseImpl.h" - -// Use the SSE optimized version whenever possible. At the moment the -// SSE version doesn't compile when AVX is enabled -#if defined EIGEN_VECTORIZE_SSE && !defined EIGEN_VECTORIZE_AVX - #include "src/LU/arch/Inverse_SSE.h" -#endif - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_LU_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/Eigen/MetisSupport b/external/eigen/include/eigen3/Eigen/MetisSupport deleted file mode 100644 index 85c41bf3..00000000 --- a/external/eigen/include/eigen3/Eigen/MetisSupport +++ /dev/null @@ -1,35 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_METISSUPPORT_MODULE_H -#define EIGEN_METISSUPPORT_MODULE_H - -#include "SparseCore" - -#include "src/Core/util/DisableStupidWarnings.h" - -extern "C" { -#include <metis.h> -} - - -/** \ingroup Support_modules - * \defgroup MetisSupport_Module MetisSupport module - * - * \code - * #include <Eigen/MetisSupport> - * \endcode - * This module defines an interface to the METIS reordering package (http://glaros.dtc.umn.edu/gkhome/views/metis). - * It can be used just as any other built-in method as explained in \link OrderingMethods_Module here. \endlink - */ - - -#include "src/MetisSupport/MetisSupport.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_METISSUPPORT_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/OrderingMethods b/external/eigen/include/eigen3/Eigen/OrderingMethods deleted file mode 100644 index 29691a62..00000000 --- a/external/eigen/include/eigen3/Eigen/OrderingMethods +++ /dev/null @@ -1,70 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ORDERINGMETHODS_MODULE_H -#define EIGEN_ORDERINGMETHODS_MODULE_H - -#include "SparseCore" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** - * \defgroup OrderingMethods_Module OrderingMethods module - * - * This module is currently for internal use only - * - * It defines various built-in and external ordering methods for sparse matrices. - * They are typically used to reduce the number of elements during - * the sparse matrix decomposition (LLT, LU, QR). - * Precisely, in a preprocessing step, a permutation matrix P is computed using - * those ordering methods and applied to the columns of the matrix. - * Using for instance the sparse Cholesky decomposition, it is expected that - * the nonzeros elements in LLT(A*P) will be much smaller than that in LLT(A). - * - * - * Usage : - * \code - * #include <Eigen/OrderingMethods> - * \endcode - * - * A simple usage is as a template parameter in the sparse decomposition classes : - * - * \code - * SparseLU<MatrixType, COLAMDOrdering<int> > solver; - * \endcode - * - * \code - * SparseQR<MatrixType, COLAMDOrdering<int> > solver; - * \endcode - * - * It is possible as well to call directly a particular ordering method for your own purpose, - * \code - * AMDOrdering<int> ordering; - * PermutationMatrix<Dynamic, Dynamic, int> perm; - * SparseMatrix<double> A; - * //Fill the matrix ... - * - * ordering(A, perm); // Call AMD - * \endcode - * - * \note Some of these methods (like AMD or METIS), need the sparsity pattern - * of the input matrix to be symmetric. When the matrix is structurally unsymmetric, - * Eigen computes internally the pattern of \f$A^T*A\f$ before calling the method. - * If your matrix is already symmetric (at leat in structure), you can avoid that - * by calling the method with a SelfAdjointView type. - * - * \code - * // Call the ordering on the pattern of the lower triangular matrix A - * ordering(A.selfadjointView<Lower>(), perm); - * \endcode - */ - -#include "src/OrderingMethods/Amd.h" -#include "src/OrderingMethods/Ordering.h" -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_ORDERINGMETHODS_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/PaStiXSupport b/external/eigen/include/eigen3/Eigen/PaStiXSupport deleted file mode 100644 index 234619ac..00000000 --- a/external/eigen/include/eigen3/Eigen/PaStiXSupport +++ /dev/null @@ -1,49 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PASTIXSUPPORT_MODULE_H -#define EIGEN_PASTIXSUPPORT_MODULE_H - -#include "SparseCore" - -#include "src/Core/util/DisableStupidWarnings.h" - -extern "C" { -#include <pastix_nompi.h> -#include <pastix.h> -} - -#ifdef complex -#undef complex -#endif - -/** \ingroup Support_modules - * \defgroup PaStiXSupport_Module PaStiXSupport module - * - * This module provides an interface to the <a href="http://pastix.gforge.inria.fr/">PaSTiX</a> library. - * PaSTiX is a general \b supernodal, \b parallel and \b opensource sparse solver. - * It provides the two following main factorization classes: - * - class PastixLLT : a supernodal, parallel LLt Cholesky factorization. - * - class PastixLDLT: a supernodal, parallel LDLt Cholesky factorization. - * - class PastixLU : a supernodal, parallel LU factorization (optimized for a symmetric pattern). - * - * \code - * #include <Eigen/PaStiXSupport> - * \endcode - * - * In order to use this module, the PaSTiX headers must be accessible from the include paths, and your binary must be linked to the PaSTiX library and its dependencies. - * This wrapper resuires PaStiX version 5.x compiled without MPI support. - * The dependencies depend on how PaSTiX has been compiled. - * For a cmake based project, you can use our FindPaSTiX.cmake module to help you in this task. - * - */ - -#include "src/PaStiXSupport/PaStiXSupport.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_PASTIXSUPPORT_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/PardisoSupport b/external/eigen/include/eigen3/Eigen/PardisoSupport deleted file mode 100644 index 340edf51..00000000 --- a/external/eigen/include/eigen3/Eigen/PardisoSupport +++ /dev/null @@ -1,35 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PARDISOSUPPORT_MODULE_H -#define EIGEN_PARDISOSUPPORT_MODULE_H - -#include "SparseCore" - -#include "src/Core/util/DisableStupidWarnings.h" - -#include <mkl_pardiso.h> - -/** \ingroup Support_modules - * \defgroup PardisoSupport_Module PardisoSupport module - * - * This module brings support for the Intel(R) MKL PARDISO direct sparse solvers. - * - * \code - * #include <Eigen/PardisoSupport> - * \endcode - * - * In order to use this module, the MKL headers must be accessible from the include paths, and your binary must be linked to the MKL library and its dependencies. - * See this \ref TopicUsingIntelMKL "page" for more information on MKL-Eigen integration. - * - */ - -#include "src/PardisoSupport/PardisoSupport.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_PARDISOSUPPORT_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/QR b/external/eigen/include/eigen3/Eigen/QR deleted file mode 100644 index 1be1863a..00000000 --- a/external/eigen/include/eigen3/Eigen/QR +++ /dev/null @@ -1,51 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_QR_MODULE_H -#define EIGEN_QR_MODULE_H - -#include "Core" - -#include "Cholesky" -#include "Jacobi" -#include "Householder" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup QR_Module QR module - * - * - * - * This module provides various QR decompositions - * This module also provides some MatrixBase methods, including: - * - MatrixBase::householderQr() - * - MatrixBase::colPivHouseholderQr() - * - MatrixBase::fullPivHouseholderQr() - * - * \code - * #include <Eigen/QR> - * \endcode - */ - -#include "src/QR/HouseholderQR.h" -#include "src/QR/FullPivHouseholderQR.h" -#include "src/QR/ColPivHouseholderQR.h" -#include "src/QR/CompleteOrthogonalDecomposition.h" -#ifdef EIGEN_USE_LAPACKE -#ifdef EIGEN_USE_MKL -#include "mkl_lapacke.h" -#else -#include "src/misc/lapacke.h" -#endif -#include "src/QR/HouseholderQR_LAPACKE.h" -#include "src/QR/ColPivHouseholderQR_LAPACKE.h" -#endif - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_QR_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/Eigen/QtAlignedMalloc b/external/eigen/include/eigen3/Eigen/QtAlignedMalloc deleted file mode 100644 index 4f07df02..00000000 --- a/external/eigen/include/eigen3/Eigen/QtAlignedMalloc +++ /dev/null @@ -1,40 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_QTMALLOC_MODULE_H -#define EIGEN_QTMALLOC_MODULE_H - -#include "Core" - -#if (!EIGEN_MALLOC_ALREADY_ALIGNED) - -#include "src/Core/util/DisableStupidWarnings.h" - -void *qMalloc(std::size_t size) -{ - return Eigen::internal::aligned_malloc(size); -} - -void qFree(void *ptr) -{ - Eigen::internal::aligned_free(ptr); -} - -void *qRealloc(void *ptr, std::size_t size) -{ - void* newPtr = Eigen::internal::aligned_malloc(size); - std::memcpy(newPtr, ptr, size); - Eigen::internal::aligned_free(ptr); - return newPtr; -} - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif - -#endif // EIGEN_QTMALLOC_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/Eigen/SPQRSupport b/external/eigen/include/eigen3/Eigen/SPQRSupport deleted file mode 100644 index f70390c1..00000000 --- a/external/eigen/include/eigen3/Eigen/SPQRSupport +++ /dev/null @@ -1,34 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPQRSUPPORT_MODULE_H -#define EIGEN_SPQRSUPPORT_MODULE_H - -#include "SparseCore" - -#include "src/Core/util/DisableStupidWarnings.h" - -#include "SuiteSparseQR.hpp" - -/** \ingroup Support_modules - * \defgroup SPQRSupport_Module SuiteSparseQR module - * - * This module provides an interface to the SPQR library, which is part of the <a href="http://www.suitesparse.com">suitesparse</a> package. - * - * \code - * #include <Eigen/SPQRSupport> - * \endcode - * - * In order to use this module, the SPQR headers must be accessible from the include paths, and your binary must be linked to the SPQR library and its dependencies (Cholmod, AMD, COLAMD,...). - * For a cmake based project, you can use our FindSPQR.cmake and FindCholmod.Cmake modules - * - */ - -#include "src/CholmodSupport/CholmodSupport.h" -#include "src/SPQRSupport/SuiteSparseQRSupport.h" - -#endif diff --git a/external/eigen/include/eigen3/Eigen/SVD b/external/eigen/include/eigen3/Eigen/SVD deleted file mode 100644 index 5d0e75f7..00000000 --- a/external/eigen/include/eigen3/Eigen/SVD +++ /dev/null @@ -1,51 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SVD_MODULE_H -#define EIGEN_SVD_MODULE_H - -#include "QR" -#include "Householder" -#include "Jacobi" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup SVD_Module SVD module - * - * - * - * This module provides SVD decomposition for matrices (both real and complex). - * Two decomposition algorithms are provided: - * - JacobiSVD implementing two-sided Jacobi iterations is numerically very accurate, fast for small matrices, but very slow for larger ones. - * - BDCSVD implementing a recursive divide & conquer strategy on top of an upper-bidiagonalization which remains fast for large problems. - * These decompositions are accessible via the respective classes and following MatrixBase methods: - * - MatrixBase::jacobiSvd() - * - MatrixBase::bdcSvd() - * - * \code - * #include <Eigen/SVD> - * \endcode - */ - -#include "src/misc/RealSvd2x2.h" -#include "src/SVD/UpperBidiagonalization.h" -#include "src/SVD/SVDBase.h" -#include "src/SVD/JacobiSVD.h" -#include "src/SVD/BDCSVD.h" -#if defined(EIGEN_USE_LAPACKE) && !defined(EIGEN_USE_LAPACKE_STRICT) -#ifdef EIGEN_USE_MKL -#include "mkl_lapacke.h" -#else -#include "src/misc/lapacke.h" -#endif -#include "src/SVD/JacobiSVD_LAPACKE.h" -#endif - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SVD_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/Eigen/Sparse b/external/eigen/include/eigen3/Eigen/Sparse deleted file mode 100644 index a2ef7a66..00000000 --- a/external/eigen/include/eigen3/Eigen/Sparse +++ /dev/null @@ -1,34 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_MODULE_H -#define EIGEN_SPARSE_MODULE_H - -/** \defgroup Sparse_Module Sparse meta-module - * - * Meta-module including all related modules: - * - \ref SparseCore_Module - * - \ref OrderingMethods_Module - * - \ref SparseCholesky_Module - * - \ref SparseLU_Module - * - \ref SparseQR_Module - * - \ref IterativeLinearSolvers_Module - * - \code - #include <Eigen/Sparse> - \endcode - */ - -#include "SparseCore" -#include "OrderingMethods" -#include "SparseCholesky" -#include "SparseLU" -#include "SparseQR" -#include "IterativeLinearSolvers" - -#endif // EIGEN_SPARSE_MODULE_H - diff --git a/external/eigen/include/eigen3/Eigen/SparseCholesky b/external/eigen/include/eigen3/Eigen/SparseCholesky deleted file mode 100644 index d2b1f127..00000000 --- a/external/eigen/include/eigen3/Eigen/SparseCholesky +++ /dev/null @@ -1,37 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2013 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSECHOLESKY_MODULE_H -#define EIGEN_SPARSECHOLESKY_MODULE_H - -#include "SparseCore" -#include "OrderingMethods" - -#include "src/Core/util/DisableStupidWarnings.h" - -/** - * \defgroup SparseCholesky_Module SparseCholesky module - * - * This module currently provides two variants of the direct sparse Cholesky decomposition for selfadjoint (hermitian) matrices. - * Those decompositions are accessible via the following classes: - * - SimplicialLLt, - * - SimplicialLDLt - * - * Such problems can also be solved using the ConjugateGradient solver from the IterativeLinearSolvers module. - * - * \code - * #include <Eigen/SparseCholesky> - * \endcode - */ - -#include "src/SparseCholesky/SimplicialCholesky.h" -#include "src/SparseCholesky/SimplicialCholesky_impl.h" -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SPARSECHOLESKY_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/SparseCore b/external/eigen/include/eigen3/Eigen/SparseCore deleted file mode 100644 index 76966c4c..00000000 --- a/external/eigen/include/eigen3/Eigen/SparseCore +++ /dev/null @@ -1,69 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSECORE_MODULE_H -#define EIGEN_SPARSECORE_MODULE_H - -#include "Core" - -#include "src/Core/util/DisableStupidWarnings.h" - -#include <vector> -#include <map> -#include <cstdlib> -#include <cstring> -#include <algorithm> - -/** - * \defgroup SparseCore_Module SparseCore module - * - * This module provides a sparse matrix representation, and basic associated matrix manipulations - * and operations. - * - * See the \ref TutorialSparse "Sparse tutorial" - * - * \code - * #include <Eigen/SparseCore> - * \endcode - * - * This module depends on: Core. - */ - -#include "src/SparseCore/SparseUtil.h" -#include "src/SparseCore/SparseMatrixBase.h" -#include "src/SparseCore/SparseAssign.h" -#include "src/SparseCore/CompressedStorage.h" -#include "src/SparseCore/AmbiVector.h" -#include "src/SparseCore/SparseCompressedBase.h" -#include "src/SparseCore/SparseMatrix.h" -#include "src/SparseCore/SparseMap.h" -#include "src/SparseCore/MappedSparseMatrix.h" -#include "src/SparseCore/SparseVector.h" -#include "src/SparseCore/SparseRef.h" -#include "src/SparseCore/SparseCwiseUnaryOp.h" -#include "src/SparseCore/SparseCwiseBinaryOp.h" -#include "src/SparseCore/SparseTranspose.h" -#include "src/SparseCore/SparseBlock.h" -#include "src/SparseCore/SparseDot.h" -#include "src/SparseCore/SparseRedux.h" -#include "src/SparseCore/SparseView.h" -#include "src/SparseCore/SparseDiagonalProduct.h" -#include "src/SparseCore/ConservativeSparseSparseProduct.h" -#include "src/SparseCore/SparseSparseProductWithPruning.h" -#include "src/SparseCore/SparseProduct.h" -#include "src/SparseCore/SparseDenseProduct.h" -#include "src/SparseCore/SparseSelfAdjointView.h" -#include "src/SparseCore/SparseTriangularView.h" -#include "src/SparseCore/TriangularSolver.h" -#include "src/SparseCore/SparsePermutation.h" -#include "src/SparseCore/SparseFuzzy.h" -#include "src/SparseCore/SparseSolverBase.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SPARSECORE_MODULE_H - diff --git a/external/eigen/include/eigen3/Eigen/SparseLU b/external/eigen/include/eigen3/Eigen/SparseLU deleted file mode 100644 index 37c4a5c5..00000000 --- a/external/eigen/include/eigen3/Eigen/SparseLU +++ /dev/null @@ -1,50 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSELU_MODULE_H -#define EIGEN_SPARSELU_MODULE_H - -#include "SparseCore" - -/** - * \defgroup SparseLU_Module SparseLU module - * This module defines a supernodal factorization of general sparse matrices. - * The code is fully optimized for supernode-panel updates with specialized kernels. - * Please, see the documentation of the SparseLU class for more details. - */ - -// Ordering interface -#include "OrderingMethods" - -#include "src/Core/util/DisableStupidWarnings.h" - -#include "src/SparseLU/SparseLU_gemm_kernel.h" - -#include "src/SparseLU/SparseLU_Structs.h" -#include "src/SparseLU/SparseLU_SupernodalMatrix.h" -#include "src/SparseLU/SparseLUImpl.h" -#include "src/SparseCore/SparseColEtree.h" -#include "src/SparseLU/SparseLU_Memory.h" -#include "src/SparseLU/SparseLU_heap_relax_snode.h" -#include "src/SparseLU/SparseLU_relax_snode.h" -#include "src/SparseLU/SparseLU_pivotL.h" -#include "src/SparseLU/SparseLU_panel_dfs.h" -#include "src/SparseLU/SparseLU_kernel_bmod.h" -#include "src/SparseLU/SparseLU_panel_bmod.h" -#include "src/SparseLU/SparseLU_column_dfs.h" -#include "src/SparseLU/SparseLU_column_bmod.h" -#include "src/SparseLU/SparseLU_copy_to_ucol.h" -#include "src/SparseLU/SparseLU_pruneL.h" -#include "src/SparseLU/SparseLU_Utils.h" -#include "src/SparseLU/SparseLU.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SPARSELU_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/SparseQR b/external/eigen/include/eigen3/Eigen/SparseQR deleted file mode 100644 index f5fc5fa7..00000000 --- a/external/eigen/include/eigen3/Eigen/SparseQR +++ /dev/null @@ -1,36 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEQR_MODULE_H -#define EIGEN_SPARSEQR_MODULE_H - -#include "SparseCore" -#include "OrderingMethods" -#include "src/Core/util/DisableStupidWarnings.h" - -/** \defgroup SparseQR_Module SparseQR module - * \brief Provides QR decomposition for sparse matrices - * - * This module provides a simplicial version of the left-looking Sparse QR decomposition. - * The columns of the input matrix should be reordered to limit the fill-in during the - * decomposition. Built-in methods (COLAMD, AMD) or external methods (METIS) can be used to this end. - * See the \link OrderingMethods_Module OrderingMethods\endlink module for the list - * of built-in and external ordering methods. - * - * \code - * #include <Eigen/SparseQR> - * \endcode - * - * - */ - -#include "src/SparseCore/SparseColEtree.h" -#include "src/SparseQR/SparseQR.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif diff --git a/external/eigen/include/eigen3/Eigen/StdDeque b/external/eigen/include/eigen3/Eigen/StdDeque deleted file mode 100644 index bc68397b..00000000 --- a/external/eigen/include/eigen3/Eigen/StdDeque +++ /dev/null @@ -1,27 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STDDEQUE_MODULE_H -#define EIGEN_STDDEQUE_MODULE_H - -#include "Core" -#include <deque> - -#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ - -#define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) - -#else - -#include "src/StlSupport/StdDeque.h" - -#endif - -#endif // EIGEN_STDDEQUE_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/StdList b/external/eigen/include/eigen3/Eigen/StdList deleted file mode 100644 index 4c6262c0..00000000 --- a/external/eigen/include/eigen3/Eigen/StdList +++ /dev/null @@ -1,26 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STDLIST_MODULE_H -#define EIGEN_STDLIST_MODULE_H - -#include "Core" -#include <list> - -#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ - -#define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) - -#else - -#include "src/StlSupport/StdList.h" - -#endif - -#endif // EIGEN_STDLIST_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/StdVector b/external/eigen/include/eigen3/Eigen/StdVector deleted file mode 100644 index 0c4697ad..00000000 --- a/external/eigen/include/eigen3/Eigen/StdVector +++ /dev/null @@ -1,27 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STDVECTOR_MODULE_H -#define EIGEN_STDVECTOR_MODULE_H - -#include "Core" -#include <vector> - -#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ - -#define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...) - -#else - -#include "src/StlSupport/StdVector.h" - -#endif - -#endif // EIGEN_STDVECTOR_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/SuperLUSupport b/external/eigen/include/eigen3/Eigen/SuperLUSupport deleted file mode 100644 index 59312a82..00000000 --- a/external/eigen/include/eigen3/Eigen/SuperLUSupport +++ /dev/null @@ -1,64 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SUPERLUSUPPORT_MODULE_H -#define EIGEN_SUPERLUSUPPORT_MODULE_H - -#include "SparseCore" - -#include "src/Core/util/DisableStupidWarnings.h" - -#ifdef EMPTY -#define EIGEN_EMPTY_WAS_ALREADY_DEFINED -#endif - -typedef int int_t; -#include <slu_Cnames.h> -#include <supermatrix.h> -#include <slu_util.h> - -// slu_util.h defines a preprocessor token named EMPTY which is really polluting, -// so we remove it in favor of a SUPERLU_EMPTY token. -// If EMPTY was already defined then we don't undef it. - -#if defined(EIGEN_EMPTY_WAS_ALREADY_DEFINED) -# undef EIGEN_EMPTY_WAS_ALREADY_DEFINED -#elif defined(EMPTY) -# undef EMPTY -#endif - -#define SUPERLU_EMPTY (-1) - -namespace Eigen { struct SluMatrix; } - -/** \ingroup Support_modules - * \defgroup SuperLUSupport_Module SuperLUSupport module - * - * This module provides an interface to the <a href="http://crd-legacy.lbl.gov/~xiaoye/SuperLU/">SuperLU</a> library. - * It provides the following factorization class: - * - class SuperLU: a supernodal sequential LU factorization. - * - class SuperILU: a supernodal sequential incomplete LU factorization (to be used as a preconditioner for iterative methods). - * - * \warning This wrapper requires at least versions 4.0 of SuperLU. The 3.x versions are not supported. - * - * \warning When including this module, you have to use SUPERLU_EMPTY instead of EMPTY which is no longer defined because it is too polluting. - * - * \code - * #include <Eigen/SuperLUSupport> - * \endcode - * - * In order to use this module, the superlu headers must be accessible from the include paths, and your binary must be linked to the superlu library and its dependencies. - * The dependencies depend on how superlu has been compiled. - * For a cmake based project, you can use our FindSuperLU.cmake module to help you in this task. - * - */ - -#include "src/SuperLUSupport/SuperLUSupport.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SUPERLUSUPPORT_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/UmfPackSupport b/external/eigen/include/eigen3/Eigen/UmfPackSupport deleted file mode 100644 index 00eec808..00000000 --- a/external/eigen/include/eigen3/Eigen/UmfPackSupport +++ /dev/null @@ -1,40 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_UMFPACKSUPPORT_MODULE_H -#define EIGEN_UMFPACKSUPPORT_MODULE_H - -#include "SparseCore" - -#include "src/Core/util/DisableStupidWarnings.h" - -extern "C" { -#include <umfpack.h> -} - -/** \ingroup Support_modules - * \defgroup UmfPackSupport_Module UmfPackSupport module - * - * This module provides an interface to the UmfPack library which is part of the <a href="http://www.suitesparse.com">suitesparse</a> package. - * It provides the following factorization class: - * - class UmfPackLU: a multifrontal sequential LU factorization. - * - * \code - * #include <Eigen/UmfPackSupport> - * \endcode - * - * In order to use this module, the umfpack headers must be accessible from the include paths, and your binary must be linked to the umfpack library and its dependencies. - * The dependencies depend on how umfpack has been compiled. - * For a cmake based project, you can use our FindUmfPack.cmake module to help you in this task. - * - */ - -#include "src/UmfPackSupport/UmfPackSupport.h" - -#include "src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_UMFPACKSUPPORT_MODULE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Cholesky/LDLT.h b/external/eigen/include/eigen3/Eigen/src/Cholesky/LDLT.h deleted file mode 100644 index 67e97ffb..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Cholesky/LDLT.h +++ /dev/null @@ -1,688 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Keir Mierle <mierle@gmail.com> -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2011 Timothy E. Holy <tim.holy@gmail.com > -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_LDLT_H -#define EIGEN_LDLT_H - -namespace Eigen { - -namespace internal { - template<typename _MatrixType, int _UpLo> struct traits<LDLT<_MatrixType, _UpLo> > - : traits<_MatrixType> - { - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - enum { Flags = 0 }; - }; - - template<typename MatrixType, int UpLo> struct LDLT_Traits; - - // PositiveSemiDef means positive semi-definite and non-zero; same for NegativeSemiDef - enum SignMatrix { PositiveSemiDef, NegativeSemiDef, ZeroSign, Indefinite }; -} - -/** \ingroup Cholesky_Module - * - * \class LDLT - * - * \brief Robust Cholesky decomposition of a matrix with pivoting - * - * \tparam _MatrixType the type of the matrix of which to compute the LDL^T Cholesky decomposition - * \tparam _UpLo the triangular part that will be used for the decompositon: Lower (default) or Upper. - * The other triangular part won't be read. - * - * Perform a robust Cholesky decomposition of a positive semidefinite or negative semidefinite - * matrix \f$ A \f$ such that \f$ A = P^TLDL^*P \f$, where P is a permutation matrix, L - * is lower triangular with a unit diagonal and D is a diagonal matrix. - * - * The decomposition uses pivoting to ensure stability, so that L will have - * zeros in the bottom right rank(A) - n submatrix. Avoiding the square root - * on D also stabilizes the computation. - * - * Remember that Cholesky decompositions are not rank-revealing. Also, do not use a Cholesky - * decomposition to determine whether a system of equations has a solution. - * - * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. - * - * \sa MatrixBase::ldlt(), SelfAdjointView::ldlt(), class LLT - */ -template<typename _MatrixType, int _UpLo> class LDLT - : public SolverBase<LDLT<_MatrixType, _UpLo> > -{ - public: - typedef _MatrixType MatrixType; - typedef SolverBase<LDLT> Base; - friend class SolverBase<LDLT>; - - EIGEN_GENERIC_PUBLIC_INTERFACE(LDLT) - enum { - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - UpLo = _UpLo - }; - typedef Matrix<Scalar, RowsAtCompileTime, 1, 0, MaxRowsAtCompileTime, 1> TmpMatrixType; - - typedef Transpositions<RowsAtCompileTime, MaxRowsAtCompileTime> TranspositionType; - typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType; - - typedef internal::LDLT_Traits<MatrixType,UpLo> Traits; - - /** \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via LDLT::compute(const MatrixType&). - */ - LDLT() - : m_matrix(), - m_transpositions(), - m_sign(internal::ZeroSign), - m_isInitialized(false) - {} - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa LDLT() - */ - explicit LDLT(Index size) - : m_matrix(size, size), - m_transpositions(size), - m_temporary(size), - m_sign(internal::ZeroSign), - m_isInitialized(false) - {} - - /** \brief Constructor with decomposition - * - * This calculates the decomposition for the input \a matrix. - * - * \sa LDLT(Index size) - */ - template<typename InputType> - explicit LDLT(const EigenBase<InputType>& matrix) - : m_matrix(matrix.rows(), matrix.cols()), - m_transpositions(matrix.rows()), - m_temporary(matrix.rows()), - m_sign(internal::ZeroSign), - m_isInitialized(false) - { - compute(matrix.derived()); - } - - /** \brief Constructs a LDLT factorization from a given matrix - * - * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref. - * - * \sa LDLT(const EigenBase&) - */ - template<typename InputType> - explicit LDLT(EigenBase<InputType>& matrix) - : m_matrix(matrix.derived()), - m_transpositions(matrix.rows()), - m_temporary(matrix.rows()), - m_sign(internal::ZeroSign), - m_isInitialized(false) - { - compute(matrix.derived()); - } - - /** Clear any existing decomposition - * \sa rankUpdate(w,sigma) - */ - void setZero() - { - m_isInitialized = false; - } - - /** \returns a view of the upper triangular matrix U */ - inline typename Traits::MatrixU matrixU() const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return Traits::getU(m_matrix); - } - - /** \returns a view of the lower triangular matrix L */ - inline typename Traits::MatrixL matrixL() const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return Traits::getL(m_matrix); - } - - /** \returns the permutation matrix P as a transposition sequence. - */ - inline const TranspositionType& transpositionsP() const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return m_transpositions; - } - - /** \returns the coefficients of the diagonal matrix D */ - inline Diagonal<const MatrixType> vectorD() const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return m_matrix.diagonal(); - } - - /** \returns true if the matrix is positive (semidefinite) */ - inline bool isPositive() const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return m_sign == internal::PositiveSemiDef || m_sign == internal::ZeroSign; - } - - /** \returns true if the matrix is negative (semidefinite) */ - inline bool isNegative(void) const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return m_sign == internal::NegativeSemiDef || m_sign == internal::ZeroSign; - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** \returns a solution x of \f$ A x = b \f$ using the current decomposition of A. - * - * This function also supports in-place solves using the syntax <tt>x = decompositionObject.solve(x)</tt> . - * - * \note_about_checking_solutions - * - * More precisely, this method solves \f$ A x = b \f$ using the decomposition \f$ A = P^T L D L^* P \f$ - * by solving the systems \f$ P^T y_1 = b \f$, \f$ L y_2 = y_1 \f$, \f$ D y_3 = y_2 \f$, - * \f$ L^* y_4 = y_3 \f$ and \f$ P x = y_4 \f$ in succession. If the matrix \f$ A \f$ is singular, then - * \f$ D \f$ will also be singular (all the other matrices are invertible). In that case, the - * least-square solution of \f$ D y_3 = y_2 \f$ is computed. This does not mean that this function - * computes the least-square solution of \f$ A x = b \f$ is \f$ A \f$ is singular. - * - * \sa MatrixBase::ldlt(), SelfAdjointView::ldlt() - */ - template<typename Rhs> - inline const Solve<LDLT, Rhs> - solve(const MatrixBase<Rhs>& b) const; - #endif - - template<typename Derived> - bool solveInPlace(MatrixBase<Derived> &bAndX) const; - - template<typename InputType> - LDLT& compute(const EigenBase<InputType>& matrix); - - /** \returns an estimate of the reciprocal condition number of the matrix of - * which \c *this is the LDLT decomposition. - */ - RealScalar rcond() const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return internal::rcond_estimate_helper(m_l1_norm, *this); - } - - template <typename Derived> - LDLT& rankUpdate(const MatrixBase<Derived>& w, const RealScalar& alpha=1); - - /** \returns the internal LDLT decomposition matrix - * - * TODO: document the storage layout - */ - inline const MatrixType& matrixLDLT() const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return m_matrix; - } - - MatrixType reconstructedMatrix() const; - - /** \returns the adjoint of \c *this, that is, a const reference to the decomposition itself as the underlying matrix is self-adjoint. - * - * This method is provided for compatibility with other matrix decompositions, thus enabling generic code such as: - * \code x = decomposition.adjoint().solve(b) \endcode - */ - const LDLT& adjoint() const { return *this; }; - - inline Index rows() const { return m_matrix.rows(); } - inline Index cols() const { return m_matrix.cols(); } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the factorization failed because of a zero pivot. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "LDLT is not initialized."); - return m_info; - } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename RhsType, typename DstType> - void _solve_impl(const RhsType &rhs, DstType &dst) const; - - template<bool Conjugate, typename RhsType, typename DstType> - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const; - #endif - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - /** \internal - * Used to compute and store the Cholesky decomposition A = L D L^* = U^* D U. - * The strict upper part is used during the decomposition, the strict lower - * part correspond to the coefficients of L (its diagonal is equal to 1 and - * is not stored), and the diagonal entries correspond to D. - */ - MatrixType m_matrix; - RealScalar m_l1_norm; - TranspositionType m_transpositions; - TmpMatrixType m_temporary; - internal::SignMatrix m_sign; - bool m_isInitialized; - ComputationInfo m_info; -}; - -namespace internal { - -template<int UpLo> struct ldlt_inplace; - -template<> struct ldlt_inplace<Lower> -{ - template<typename MatrixType, typename TranspositionType, typename Workspace> - static bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign) - { - using std::abs; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename TranspositionType::StorageIndex IndexType; - eigen_assert(mat.rows()==mat.cols()); - const Index size = mat.rows(); - bool found_zero_pivot = false; - bool ret = true; - - if (size <= 1) - { - transpositions.setIdentity(); - if(size==0) sign = ZeroSign; - else if (numext::real(mat.coeff(0,0)) > static_cast<RealScalar>(0) ) sign = PositiveSemiDef; - else if (numext::real(mat.coeff(0,0)) < static_cast<RealScalar>(0)) sign = NegativeSemiDef; - else sign = ZeroSign; - return true; - } - - for (Index k = 0; k < size; ++k) - { - // Find largest diagonal element - Index index_of_biggest_in_corner; - mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner); - index_of_biggest_in_corner += k; - - transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner); - if(k != index_of_biggest_in_corner) - { - // apply the transposition while taking care to consider only - // the lower triangular part - Index s = size-index_of_biggest_in_corner-1; // trailing size after the biggest element - mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k)); - mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s)); - std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner)); - for(Index i=k+1;i<index_of_biggest_in_corner;++i) - { - Scalar tmp = mat.coeffRef(i,k); - mat.coeffRef(i,k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner,i)); - mat.coeffRef(index_of_biggest_in_corner,i) = numext::conj(tmp); - } - if(NumTraits<Scalar>::IsComplex) - mat.coeffRef(index_of_biggest_in_corner,k) = numext::conj(mat.coeff(index_of_biggest_in_corner,k)); - } - - // partition the matrix: - // A00 | - | - - // lu = A10 | A11 | - - // A20 | A21 | A22 - Index rs = size - k - 1; - Block<MatrixType,Dynamic,1> A21(mat,k+1,k,rs,1); - Block<MatrixType,1,Dynamic> A10(mat,k,0,1,k); - Block<MatrixType,Dynamic,Dynamic> A20(mat,k+1,0,rs,k); - - if(k>0) - { - temp.head(k) = mat.diagonal().real().head(k).asDiagonal() * A10.adjoint(); - mat.coeffRef(k,k) -= (A10 * temp.head(k)).value(); - if(rs>0) - A21.noalias() -= A20 * temp.head(k); - } - - // In some previous versions of Eigen (e.g., 3.2.1), the scaling was omitted if the pivot - // was smaller than the cutoff value. However, since LDLT is not rank-revealing - // we should only make sure that we do not introduce INF or NaN values. - // Remark that LAPACK also uses 0 as the cutoff value. - RealScalar realAkk = numext::real(mat.coeffRef(k,k)); - bool pivot_is_valid = (abs(realAkk) > RealScalar(0)); - - if(k==0 && !pivot_is_valid) - { - // The entire diagonal is zero, there is nothing more to do - // except filling the transpositions, and checking whether the matrix is zero. - sign = ZeroSign; - for(Index j = 0; j<size; ++j) - { - transpositions.coeffRef(j) = IndexType(j); - ret = ret && (mat.col(j).tail(size-j-1).array()==Scalar(0)).all(); - } - return ret; - } - - if((rs>0) && pivot_is_valid) - A21 /= realAkk; - else if(rs>0) - ret = ret && (A21.array()==Scalar(0)).all(); - - if(found_zero_pivot && pivot_is_valid) ret = false; // factorization failed - else if(!pivot_is_valid) found_zero_pivot = true; - - if (sign == PositiveSemiDef) { - if (realAkk < static_cast<RealScalar>(0)) sign = Indefinite; - } else if (sign == NegativeSemiDef) { - if (realAkk > static_cast<RealScalar>(0)) sign = Indefinite; - } else if (sign == ZeroSign) { - if (realAkk > static_cast<RealScalar>(0)) sign = PositiveSemiDef; - else if (realAkk < static_cast<RealScalar>(0)) sign = NegativeSemiDef; - } - } - - return ret; - } - - // Reference for the algorithm: Davis and Hager, "Multiple Rank - // Modifications of a Sparse Cholesky Factorization" (Algorithm 1) - // Trivial rearrangements of their computations (Timothy E. Holy) - // allow their algorithm to work for rank-1 updates even if the - // original matrix is not of full rank. - // Here only rank-1 updates are implemented, to reduce the - // requirement for intermediate storage and improve accuracy - template<typename MatrixType, typename WDerived> - static bool updateInPlace(MatrixType& mat, MatrixBase<WDerived>& w, const typename MatrixType::RealScalar& sigma=1) - { - using numext::isfinite; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - - const Index size = mat.rows(); - eigen_assert(mat.cols() == size && w.size()==size); - - RealScalar alpha = 1; - - // Apply the update - for (Index j = 0; j < size; j++) - { - // Check for termination due to an original decomposition of low-rank - if (!(isfinite)(alpha)) - break; - - // Update the diagonal terms - RealScalar dj = numext::real(mat.coeff(j,j)); - Scalar wj = w.coeff(j); - RealScalar swj2 = sigma*numext::abs2(wj); - RealScalar gamma = dj*alpha + swj2; - - mat.coeffRef(j,j) += swj2/alpha; - alpha += swj2/dj; - - - // Update the terms of L - Index rs = size-j-1; - w.tail(rs) -= wj * mat.col(j).tail(rs); - if(gamma != 0) - mat.col(j).tail(rs) += (sigma*numext::conj(wj)/gamma)*w.tail(rs); - } - return true; - } - - template<typename MatrixType, typename TranspositionType, typename Workspace, typename WType> - static bool update(MatrixType& mat, const TranspositionType& transpositions, Workspace& tmp, const WType& w, const typename MatrixType::RealScalar& sigma=1) - { - // Apply the permutation to the input w - tmp = transpositions * w; - - return ldlt_inplace<Lower>::updateInPlace(mat,tmp,sigma); - } -}; - -template<> struct ldlt_inplace<Upper> -{ - template<typename MatrixType, typename TranspositionType, typename Workspace> - static EIGEN_STRONG_INLINE bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign) - { - Transpose<MatrixType> matt(mat); - return ldlt_inplace<Lower>::unblocked(matt, transpositions, temp, sign); - } - - template<typename MatrixType, typename TranspositionType, typename Workspace, typename WType> - static EIGEN_STRONG_INLINE bool update(MatrixType& mat, TranspositionType& transpositions, Workspace& tmp, WType& w, const typename MatrixType::RealScalar& sigma=1) - { - Transpose<MatrixType> matt(mat); - return ldlt_inplace<Lower>::update(matt, transpositions, tmp, w.conjugate(), sigma); - } -}; - -template<typename MatrixType> struct LDLT_Traits<MatrixType,Lower> -{ - typedef const TriangularView<const MatrixType, UnitLower> MatrixL; - typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitUpper> MatrixU; - static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); } - static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); } -}; - -template<typename MatrixType> struct LDLT_Traits<MatrixType,Upper> -{ - typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitLower> MatrixL; - typedef const TriangularView<const MatrixType, UnitUpper> MatrixU; - static inline MatrixL getL(const MatrixType& m) { return MatrixL(m.adjoint()); } - static inline MatrixU getU(const MatrixType& m) { return MatrixU(m); } -}; - -} // end namespace internal - -/** Compute / recompute the LDLT decomposition A = L D L^* = U^* D U of \a matrix - */ -template<typename MatrixType, int _UpLo> -template<typename InputType> -LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::compute(const EigenBase<InputType>& a) -{ - check_template_parameters(); - - eigen_assert(a.rows()==a.cols()); - const Index size = a.rows(); - - m_matrix = a.derived(); - - // Compute matrix L1 norm = max abs column sum. - m_l1_norm = RealScalar(0); - // TODO move this code to SelfAdjointView - for (Index col = 0; col < size; ++col) { - RealScalar abs_col_sum; - if (_UpLo == Lower) - abs_col_sum = m_matrix.col(col).tail(size - col).template lpNorm<1>() + m_matrix.row(col).head(col).template lpNorm<1>(); - else - abs_col_sum = m_matrix.col(col).head(col).template lpNorm<1>() + m_matrix.row(col).tail(size - col).template lpNorm<1>(); - if (abs_col_sum > m_l1_norm) - m_l1_norm = abs_col_sum; - } - - m_transpositions.resize(size); - m_isInitialized = false; - m_temporary.resize(size); - m_sign = internal::ZeroSign; - - m_info = internal::ldlt_inplace<UpLo>::unblocked(m_matrix, m_transpositions, m_temporary, m_sign) ? Success : NumericalIssue; - - m_isInitialized = true; - return *this; -} - -/** Update the LDLT decomposition: given A = L D L^T, efficiently compute the decomposition of A + sigma w w^T. - * \param w a vector to be incorporated into the decomposition. - * \param sigma a scalar, +1 for updates and -1 for "downdates," which correspond to removing previously-added column vectors. Optional; default value is +1. - * \sa setZero() - */ -template<typename MatrixType, int _UpLo> -template<typename Derived> -LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Derived>& w, const typename LDLT<MatrixType,_UpLo>::RealScalar& sigma) -{ - typedef typename TranspositionType::StorageIndex IndexType; - const Index size = w.rows(); - if (m_isInitialized) - { - eigen_assert(m_matrix.rows()==size); - } - else - { - m_matrix.resize(size,size); - m_matrix.setZero(); - m_transpositions.resize(size); - for (Index i = 0; i < size; i++) - m_transpositions.coeffRef(i) = IndexType(i); - m_temporary.resize(size); - m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef; - m_isInitialized = true; - } - - internal::ldlt_inplace<UpLo>::update(m_matrix, m_transpositions, m_temporary, w, sigma); - - return *this; -} - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename _MatrixType, int _UpLo> -template<typename RhsType, typename DstType> -void LDLT<_MatrixType,_UpLo>::_solve_impl(const RhsType &rhs, DstType &dst) const -{ - _solve_impl_transposed<true>(rhs, dst); -} - -template<typename _MatrixType,int _UpLo> -template<bool Conjugate, typename RhsType, typename DstType> -void LDLT<_MatrixType,_UpLo>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const -{ - // dst = P b - dst = m_transpositions * rhs; - - // dst = L^-1 (P b) - // dst = L^-*T (P b) - matrixL().template conjugateIf<!Conjugate>().solveInPlace(dst); - - // dst = D^-* (L^-1 P b) - // dst = D^-1 (L^-*T P b) - // more precisely, use pseudo-inverse of D (see bug 241) - using std::abs; - const typename Diagonal<const MatrixType>::RealReturnType vecD(vectorD()); - // In some previous versions, tolerance was set to the max of 1/highest (or rather numeric_limits::min()) - // and the maximal diagonal entry * epsilon as motivated by LAPACK's xGELSS: - // RealScalar tolerance = numext::maxi(vecD.array().abs().maxCoeff() * NumTraits<RealScalar>::epsilon(),RealScalar(1) / NumTraits<RealScalar>::highest()); - // However, LDLT is not rank revealing, and so adjusting the tolerance wrt to the highest - // diagonal element is not well justified and leads to numerical issues in some cases. - // Moreover, Lapack's xSYTRS routines use 0 for the tolerance. - // Using numeric_limits::min() gives us more robustness to denormals. - RealScalar tolerance = (std::numeric_limits<RealScalar>::min)(); - for (Index i = 0; i < vecD.size(); ++i) - { - if(abs(vecD(i)) > tolerance) - dst.row(i) /= vecD(i); - else - dst.row(i).setZero(); - } - - // dst = L^-* (D^-* L^-1 P b) - // dst = L^-T (D^-1 L^-*T P b) - matrixL().transpose().template conjugateIf<Conjugate>().solveInPlace(dst); - - // dst = P^T (L^-* D^-* L^-1 P b) = A^-1 b - // dst = P^-T (L^-T D^-1 L^-*T P b) = A^-1 b - dst = m_transpositions.transpose() * dst; -} -#endif - -/** \internal use x = ldlt_object.solve(x); - * - * This is the \em in-place version of solve(). - * - * \param bAndX represents both the right-hand side matrix b and result x. - * - * \returns true always! If you need to check for existence of solutions, use another decomposition like LU, QR, or SVD. - * - * This version avoids a copy when the right hand side matrix b is not - * needed anymore. - * - * \sa LDLT::solve(), MatrixBase::ldlt() - */ -template<typename MatrixType,int _UpLo> -template<typename Derived> -bool LDLT<MatrixType,_UpLo>::solveInPlace(MatrixBase<Derived> &bAndX) const -{ - eigen_assert(m_isInitialized && "LDLT is not initialized."); - eigen_assert(m_matrix.rows() == bAndX.rows()); - - bAndX = this->solve(bAndX); - - return true; -} - -/** \returns the matrix represented by the decomposition, - * i.e., it returns the product: P^T L D L^* P. - * This function is provided for debug purpose. */ -template<typename MatrixType, int _UpLo> -MatrixType LDLT<MatrixType,_UpLo>::reconstructedMatrix() const -{ - eigen_assert(m_isInitialized && "LDLT is not initialized."); - const Index size = m_matrix.rows(); - MatrixType res(size,size); - - // P - res.setIdentity(); - res = transpositionsP() * res; - // L^* P - res = matrixU() * res; - // D(L^*P) - res = vectorD().real().asDiagonal() * res; - // L(DL^*P) - res = matrixL() * res; - // P^T (LDL^*P) - res = transpositionsP().transpose() * res; - - return res; -} - -/** \cholesky_module - * \returns the Cholesky decomposition with full pivoting without square root of \c *this - * \sa MatrixBase::ldlt() - */ -template<typename MatrixType, unsigned int UpLo> -inline const LDLT<typename SelfAdjointView<MatrixType, UpLo>::PlainObject, UpLo> -SelfAdjointView<MatrixType, UpLo>::ldlt() const -{ - return LDLT<PlainObject,UpLo>(m_matrix); -} - -/** \cholesky_module - * \returns the Cholesky decomposition with full pivoting without square root of \c *this - * \sa SelfAdjointView::ldlt() - */ -template<typename Derived> -inline const LDLT<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::ldlt() const -{ - return LDLT<PlainObject>(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_LDLT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Cholesky/LLT.h b/external/eigen/include/eigen3/Eigen/src/Cholesky/LLT.h deleted file mode 100644 index 5876966e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Cholesky/LLT.h +++ /dev/null @@ -1,558 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_LLT_H -#define EIGEN_LLT_H - -namespace Eigen { - -namespace internal{ - -template<typename _MatrixType, int _UpLo> struct traits<LLT<_MatrixType, _UpLo> > - : traits<_MatrixType> -{ - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - enum { Flags = 0 }; -}; - -template<typename MatrixType, int UpLo> struct LLT_Traits; -} - -/** \ingroup Cholesky_Module - * - * \class LLT - * - * \brief Standard Cholesky decomposition (LL^T) of a matrix and associated features - * - * \tparam _MatrixType the type of the matrix of which we are computing the LL^T Cholesky decomposition - * \tparam _UpLo the triangular part that will be used for the decompositon: Lower (default) or Upper. - * The other triangular part won't be read. - * - * This class performs a LL^T Cholesky decomposition of a symmetric, positive definite - * matrix A such that A = LL^* = U^*U, where L is lower triangular. - * - * While the Cholesky decomposition is particularly useful to solve selfadjoint problems like D^*D x = b, - * for that purpose, we recommend the Cholesky decomposition without square root which is more stable - * and even faster. Nevertheless, this standard Cholesky decomposition remains useful in many other - * situations like generalised eigen problems with hermitian matrices. - * - * Remember that Cholesky decompositions are not rank-revealing. This LLT decomposition is only stable on positive definite matrices, - * use LDLT instead for the semidefinite case. Also, do not use a Cholesky decomposition to determine whether a system of equations - * has a solution. - * - * Example: \include LLT_example.cpp - * Output: \verbinclude LLT_example.out - * - * \b Performance: for best performance, it is recommended to use a column-major storage format - * with the Lower triangular part (the default), or, equivalently, a row-major storage format - * with the Upper triangular part. Otherwise, you might get a 20% slowdown for the full factorization - * step, and rank-updates can be up to 3 times slower. - * - * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. - * - * Note that during the decomposition, only the lower (or upper, as defined by _UpLo) triangular part of A is considered. - * Therefore, the strict lower part does not have to store correct values. - * - * \sa MatrixBase::llt(), SelfAdjointView::llt(), class LDLT - */ -template<typename _MatrixType, int _UpLo> class LLT - : public SolverBase<LLT<_MatrixType, _UpLo> > -{ - public: - typedef _MatrixType MatrixType; - typedef SolverBase<LLT> Base; - friend class SolverBase<LLT>; - - EIGEN_GENERIC_PUBLIC_INTERFACE(LLT) - enum { - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - enum { - PacketSize = internal::packet_traits<Scalar>::size, - AlignmentMask = int(PacketSize)-1, - UpLo = _UpLo - }; - - typedef internal::LLT_Traits<MatrixType,UpLo> Traits; - - /** - * \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via LLT::compute(const MatrixType&). - */ - LLT() : m_matrix(), m_isInitialized(false) {} - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa LLT() - */ - explicit LLT(Index size) : m_matrix(size, size), - m_isInitialized(false) {} - - template<typename InputType> - explicit LLT(const EigenBase<InputType>& matrix) - : m_matrix(matrix.rows(), matrix.cols()), - m_isInitialized(false) - { - compute(matrix.derived()); - } - - /** \brief Constructs a LLT factorization from a given matrix - * - * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when - * \c MatrixType is a Eigen::Ref. - * - * \sa LLT(const EigenBase&) - */ - template<typename InputType> - explicit LLT(EigenBase<InputType>& matrix) - : m_matrix(matrix.derived()), - m_isInitialized(false) - { - compute(matrix.derived()); - } - - /** \returns a view of the upper triangular matrix U */ - inline typename Traits::MatrixU matrixU() const - { - eigen_assert(m_isInitialized && "LLT is not initialized."); - return Traits::getU(m_matrix); - } - - /** \returns a view of the lower triangular matrix L */ - inline typename Traits::MatrixL matrixL() const - { - eigen_assert(m_isInitialized && "LLT is not initialized."); - return Traits::getL(m_matrix); - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** \returns the solution x of \f$ A x = b \f$ using the current decomposition of A. - * - * Since this LLT class assumes anyway that the matrix A is invertible, the solution - * theoretically exists and is unique regardless of b. - * - * Example: \include LLT_solve.cpp - * Output: \verbinclude LLT_solve.out - * - * \sa solveInPlace(), MatrixBase::llt(), SelfAdjointView::llt() - */ - template<typename Rhs> - inline const Solve<LLT, Rhs> - solve(const MatrixBase<Rhs>& b) const; - #endif - - template<typename Derived> - void solveInPlace(const MatrixBase<Derived> &bAndX) const; - - template<typename InputType> - LLT& compute(const EigenBase<InputType>& matrix); - - /** \returns an estimate of the reciprocal condition number of the matrix of - * which \c *this is the Cholesky decomposition. - */ - RealScalar rcond() const - { - eigen_assert(m_isInitialized && "LLT is not initialized."); - eigen_assert(m_info == Success && "LLT failed because matrix appears to be negative"); - return internal::rcond_estimate_helper(m_l1_norm, *this); - } - - /** \returns the LLT decomposition matrix - * - * TODO: document the storage layout - */ - inline const MatrixType& matrixLLT() const - { - eigen_assert(m_isInitialized && "LLT is not initialized."); - return m_matrix; - } - - MatrixType reconstructedMatrix() const; - - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix.appears not to be positive definite. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "LLT is not initialized."); - return m_info; - } - - /** \returns the adjoint of \c *this, that is, a const reference to the decomposition itself as the underlying matrix is self-adjoint. - * - * This method is provided for compatibility with other matrix decompositions, thus enabling generic code such as: - * \code x = decomposition.adjoint().solve(b) \endcode - */ - const LLT& adjoint() const { return *this; }; - - inline Index rows() const { return m_matrix.rows(); } - inline Index cols() const { return m_matrix.cols(); } - - template<typename VectorType> - LLT & rankUpdate(const VectorType& vec, const RealScalar& sigma = 1); - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename RhsType, typename DstType> - void _solve_impl(const RhsType &rhs, DstType &dst) const; - - template<bool Conjugate, typename RhsType, typename DstType> - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const; - #endif - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - /** \internal - * Used to compute and store L - * The strict upper part is not used and even not initialized. - */ - MatrixType m_matrix; - RealScalar m_l1_norm; - bool m_isInitialized; - ComputationInfo m_info; -}; - -namespace internal { - -template<typename Scalar, int UpLo> struct llt_inplace; - -template<typename MatrixType, typename VectorType> -static Index llt_rank_update_lower(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) -{ - using std::sqrt; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::ColXpr ColXpr; - typedef typename internal::remove_all<ColXpr>::type ColXprCleaned; - typedef typename ColXprCleaned::SegmentReturnType ColXprSegment; - typedef Matrix<Scalar,Dynamic,1> TempVectorType; - typedef typename TempVectorType::SegmentReturnType TempVecSegment; - - Index n = mat.cols(); - eigen_assert(mat.rows()==n && vec.size()==n); - - TempVectorType temp; - - if(sigma>0) - { - // This version is based on Givens rotations. - // It is faster than the other one below, but only works for updates, - // i.e., for sigma > 0 - temp = sqrt(sigma) * vec; - - for(Index i=0; i<n; ++i) - { - JacobiRotation<Scalar> g; - g.makeGivens(mat(i,i), -temp(i), &mat(i,i)); - - Index rs = n-i-1; - if(rs>0) - { - ColXprSegment x(mat.col(i).tail(rs)); - TempVecSegment y(temp.tail(rs)); - apply_rotation_in_the_plane(x, y, g); - } - } - } - else - { - temp = vec; - RealScalar beta = 1; - for(Index j=0; j<n; ++j) - { - RealScalar Ljj = numext::real(mat.coeff(j,j)); - RealScalar dj = numext::abs2(Ljj); - Scalar wj = temp.coeff(j); - RealScalar swj2 = sigma*numext::abs2(wj); - RealScalar gamma = dj*beta + swj2; - - RealScalar x = dj + swj2/beta; - if (x<=RealScalar(0)) - return j; - RealScalar nLjj = sqrt(x); - mat.coeffRef(j,j) = nLjj; - beta += swj2/dj; - - // Update the terms of L - Index rs = n-j-1; - if(rs) - { - temp.tail(rs) -= (wj/Ljj) * mat.col(j).tail(rs); - if(gamma != 0) - mat.col(j).tail(rs) = (nLjj/Ljj) * mat.col(j).tail(rs) + (nLjj * sigma*numext::conj(wj)/gamma)*temp.tail(rs); - } - } - } - return -1; -} - -template<typename Scalar> struct llt_inplace<Scalar, Lower> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - template<typename MatrixType> - static Index unblocked(MatrixType& mat) - { - using std::sqrt; - - eigen_assert(mat.rows()==mat.cols()); - const Index size = mat.rows(); - for(Index k = 0; k < size; ++k) - { - Index rs = size-k-1; // remaining size - - Block<MatrixType,Dynamic,1> A21(mat,k+1,k,rs,1); - Block<MatrixType,1,Dynamic> A10(mat,k,0,1,k); - Block<MatrixType,Dynamic,Dynamic> A20(mat,k+1,0,rs,k); - - RealScalar x = numext::real(mat.coeff(k,k)); - if (k>0) x -= A10.squaredNorm(); - if (x<=RealScalar(0)) - return k; - mat.coeffRef(k,k) = x = sqrt(x); - if (k>0 && rs>0) A21.noalias() -= A20 * A10.adjoint(); - if (rs>0) A21 /= x; - } - return -1; - } - - template<typename MatrixType> - static Index blocked(MatrixType& m) - { - eigen_assert(m.rows()==m.cols()); - Index size = m.rows(); - if(size<32) - return unblocked(m); - - Index blockSize = size/8; - blockSize = (blockSize/16)*16; - blockSize = (std::min)((std::max)(blockSize,Index(8)), Index(128)); - - for (Index k=0; k<size; k+=blockSize) - { - // partition the matrix: - // A00 | - | - - // lu = A10 | A11 | - - // A20 | A21 | A22 - Index bs = (std::min)(blockSize, size-k); - Index rs = size - k - bs; - Block<MatrixType,Dynamic,Dynamic> A11(m,k, k, bs,bs); - Block<MatrixType,Dynamic,Dynamic> A21(m,k+bs,k, rs,bs); - Block<MatrixType,Dynamic,Dynamic> A22(m,k+bs,k+bs,rs,rs); - - Index ret; - if((ret=unblocked(A11))>=0) return k+ret; - if(rs>0) A11.adjoint().template triangularView<Upper>().template solveInPlace<OnTheRight>(A21); - if(rs>0) A22.template selfadjointView<Lower>().rankUpdate(A21,typename NumTraits<RealScalar>::Literal(-1)); // bottleneck - } - return -1; - } - - template<typename MatrixType, typename VectorType> - static Index rankUpdate(MatrixType& mat, const VectorType& vec, const RealScalar& sigma) - { - return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); - } -}; - -template<typename Scalar> struct llt_inplace<Scalar, Upper> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - - template<typename MatrixType> - static EIGEN_STRONG_INLINE Index unblocked(MatrixType& mat) - { - Transpose<MatrixType> matt(mat); - return llt_inplace<Scalar, Lower>::unblocked(matt); - } - template<typename MatrixType> - static EIGEN_STRONG_INLINE Index blocked(MatrixType& mat) - { - Transpose<MatrixType> matt(mat); - return llt_inplace<Scalar, Lower>::blocked(matt); - } - template<typename MatrixType, typename VectorType> - static Index rankUpdate(MatrixType& mat, const VectorType& vec, const RealScalar& sigma) - { - Transpose<MatrixType> matt(mat); - return llt_inplace<Scalar, Lower>::rankUpdate(matt, vec.conjugate(), sigma); - } -}; - -template<typename MatrixType> struct LLT_Traits<MatrixType,Lower> -{ - typedef const TriangularView<const MatrixType, Lower> MatrixL; - typedef const TriangularView<const typename MatrixType::AdjointReturnType, Upper> MatrixU; - static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); } - static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); } - static bool inplace_decomposition(MatrixType& m) - { return llt_inplace<typename MatrixType::Scalar, Lower>::blocked(m)==-1; } -}; - -template<typename MatrixType> struct LLT_Traits<MatrixType,Upper> -{ - typedef const TriangularView<const typename MatrixType::AdjointReturnType, Lower> MatrixL; - typedef const TriangularView<const MatrixType, Upper> MatrixU; - static inline MatrixL getL(const MatrixType& m) { return MatrixL(m.adjoint()); } - static inline MatrixU getU(const MatrixType& m) { return MatrixU(m); } - static bool inplace_decomposition(MatrixType& m) - { return llt_inplace<typename MatrixType::Scalar, Upper>::blocked(m)==-1; } -}; - -} // end namespace internal - -/** Computes / recomputes the Cholesky decomposition A = LL^* = U^*U of \a matrix - * - * \returns a reference to *this - * - * Example: \include TutorialLinAlgComputeTwice.cpp - * Output: \verbinclude TutorialLinAlgComputeTwice.out - */ -template<typename MatrixType, int _UpLo> -template<typename InputType> -LLT<MatrixType,_UpLo>& LLT<MatrixType,_UpLo>::compute(const EigenBase<InputType>& a) -{ - check_template_parameters(); - - eigen_assert(a.rows()==a.cols()); - const Index size = a.rows(); - m_matrix.resize(size, size); - if (!internal::is_same_dense(m_matrix, a.derived())) - m_matrix = a.derived(); - - // Compute matrix L1 norm = max abs column sum. - m_l1_norm = RealScalar(0); - // TODO move this code to SelfAdjointView - for (Index col = 0; col < size; ++col) { - RealScalar abs_col_sum; - if (_UpLo == Lower) - abs_col_sum = m_matrix.col(col).tail(size - col).template lpNorm<1>() + m_matrix.row(col).head(col).template lpNorm<1>(); - else - abs_col_sum = m_matrix.col(col).head(col).template lpNorm<1>() + m_matrix.row(col).tail(size - col).template lpNorm<1>(); - if (abs_col_sum > m_l1_norm) - m_l1_norm = abs_col_sum; - } - - m_isInitialized = true; - bool ok = Traits::inplace_decomposition(m_matrix); - m_info = ok ? Success : NumericalIssue; - - return *this; -} - -/** Performs a rank one update (or dowdate) of the current decomposition. - * If A = LL^* before the rank one update, - * then after it we have LL^* = A + sigma * v v^* where \a v must be a vector - * of same dimension. - */ -template<typename _MatrixType, int _UpLo> -template<typename VectorType> -LLT<_MatrixType,_UpLo> & LLT<_MatrixType,_UpLo>::rankUpdate(const VectorType& v, const RealScalar& sigma) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorType); - eigen_assert(v.size()==m_matrix.cols()); - eigen_assert(m_isInitialized); - if(internal::llt_inplace<typename MatrixType::Scalar, UpLo>::rankUpdate(m_matrix,v,sigma)>=0) - m_info = NumericalIssue; - else - m_info = Success; - - return *this; -} - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename _MatrixType,int _UpLo> -template<typename RhsType, typename DstType> -void LLT<_MatrixType,_UpLo>::_solve_impl(const RhsType &rhs, DstType &dst) const -{ - _solve_impl_transposed<true>(rhs, dst); -} - -template<typename _MatrixType,int _UpLo> -template<bool Conjugate, typename RhsType, typename DstType> -void LLT<_MatrixType,_UpLo>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const -{ - dst = rhs; - - matrixL().template conjugateIf<!Conjugate>().solveInPlace(dst); - matrixU().template conjugateIf<!Conjugate>().solveInPlace(dst); -} -#endif - -/** \internal use x = llt_object.solve(x); - * - * This is the \em in-place version of solve(). - * - * \param bAndX represents both the right-hand side matrix b and result x. - * - * This version avoids a copy when the right hand side matrix b is not needed anymore. - * - * \warning The parameter is only marked 'const' to make the C++ compiler accept a temporary expression here. - * This function will const_cast it, so constness isn't honored here. - * - * \sa LLT::solve(), MatrixBase::llt() - */ -template<typename MatrixType, int _UpLo> -template<typename Derived> -void LLT<MatrixType,_UpLo>::solveInPlace(const MatrixBase<Derived> &bAndX) const -{ - eigen_assert(m_isInitialized && "LLT is not initialized."); - eigen_assert(m_matrix.rows()==bAndX.rows()); - matrixL().solveInPlace(bAndX); - matrixU().solveInPlace(bAndX); -} - -/** \returns the matrix represented by the decomposition, - * i.e., it returns the product: L L^*. - * This function is provided for debug purpose. */ -template<typename MatrixType, int _UpLo> -MatrixType LLT<MatrixType,_UpLo>::reconstructedMatrix() const -{ - eigen_assert(m_isInitialized && "LLT is not initialized."); - return matrixL() * matrixL().adjoint().toDenseMatrix(); -} - -/** \cholesky_module - * \returns the LLT decomposition of \c *this - * \sa SelfAdjointView::llt() - */ -template<typename Derived> -inline const LLT<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::llt() const -{ - return LLT<PlainObject>(derived()); -} - -/** \cholesky_module - * \returns the LLT decomposition of \c *this - * \sa SelfAdjointView::llt() - */ -template<typename MatrixType, unsigned int UpLo> -inline const LLT<typename SelfAdjointView<MatrixType, UpLo>::PlainObject, UpLo> -SelfAdjointView<MatrixType, UpLo>::llt() const -{ - return LLT<PlainObject,UpLo>(m_matrix); -} - -} // end namespace Eigen - -#endif // EIGEN_LLT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Cholesky/LLT_LAPACKE.h b/external/eigen/include/eigen3/Eigen/src/Cholesky/LLT_LAPACKE.h deleted file mode 100644 index bc6489e6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Cholesky/LLT_LAPACKE.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to LAPACKe - * LLt decomposition based on LAPACKE_?potrf function. - ******************************************************************************** -*/ - -#ifndef EIGEN_LLT_LAPACKE_H -#define EIGEN_LLT_LAPACKE_H - -namespace Eigen { - -namespace internal { - -template<typename Scalar> struct lapacke_llt; - -#define EIGEN_LAPACKE_LLT(EIGTYPE, BLASTYPE, LAPACKE_PREFIX) \ -template<> struct lapacke_llt<EIGTYPE> \ -{ \ - template<typename MatrixType> \ - static inline Index potrf(MatrixType& m, char uplo) \ - { \ - lapack_int matrix_order; \ - lapack_int size, lda, info, StorageOrder; \ - EIGTYPE* a; \ - eigen_assert(m.rows()==m.cols()); \ - /* Set up parameters for ?potrf */ \ - size = convert_index<lapack_int>(m.rows()); \ - StorageOrder = MatrixType::Flags&RowMajorBit?RowMajor:ColMajor; \ - matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ - a = &(m.coeffRef(0,0)); \ - lda = convert_index<lapack_int>(m.outerStride()); \ -\ - info = LAPACKE_##LAPACKE_PREFIX##potrf( matrix_order, uplo, size, (BLASTYPE*)a, lda ); \ - info = (info==0) ? -1 : info>0 ? info-1 : size; \ - return info; \ - } \ -}; \ -template<> struct llt_inplace<EIGTYPE, Lower> \ -{ \ - template<typename MatrixType> \ - static Index blocked(MatrixType& m) \ - { \ - return lapacke_llt<EIGTYPE>::potrf(m, 'L'); \ - } \ - template<typename MatrixType, typename VectorType> \ - static Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \ - { return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); } \ -}; \ -template<> struct llt_inplace<EIGTYPE, Upper> \ -{ \ - template<typename MatrixType> \ - static Index blocked(MatrixType& m) \ - { \ - return lapacke_llt<EIGTYPE>::potrf(m, 'U'); \ - } \ - template<typename MatrixType, typename VectorType> \ - static Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \ - { \ - Transpose<MatrixType> matt(mat); \ - return llt_inplace<EIGTYPE, Lower>::rankUpdate(matt, vec.conjugate(), sigma); \ - } \ -}; - -EIGEN_LAPACKE_LLT(double, double, d) -EIGEN_LAPACKE_LLT(float, float, s) -EIGEN_LAPACKE_LLT(dcomplex, lapack_complex_double, z) -EIGEN_LAPACKE_LLT(scomplex, lapack_complex_float, c) - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_LLT_LAPACKE_H diff --git a/external/eigen/include/eigen3/Eigen/src/CholmodSupport/CholmodSupport.h b/external/eigen/include/eigen3/Eigen/src/CholmodSupport/CholmodSupport.h deleted file mode 100644 index adaf5285..00000000 --- a/external/eigen/include/eigen3/Eigen/src/CholmodSupport/CholmodSupport.h +++ /dev/null @@ -1,682 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CHOLMODSUPPORT_H -#define EIGEN_CHOLMODSUPPORT_H - -namespace Eigen { - -namespace internal { - -template<typename Scalar> struct cholmod_configure_matrix; - -template<> struct cholmod_configure_matrix<double> { - template<typename CholmodType> - static void run(CholmodType& mat) { - mat.xtype = CHOLMOD_REAL; - mat.dtype = CHOLMOD_DOUBLE; - } -}; - -template<> struct cholmod_configure_matrix<std::complex<double> > { - template<typename CholmodType> - static void run(CholmodType& mat) { - mat.xtype = CHOLMOD_COMPLEX; - mat.dtype = CHOLMOD_DOUBLE; - } -}; - -// Other scalar types are not yet supported by Cholmod -// template<> struct cholmod_configure_matrix<float> { -// template<typename CholmodType> -// static void run(CholmodType& mat) { -// mat.xtype = CHOLMOD_REAL; -// mat.dtype = CHOLMOD_SINGLE; -// } -// }; -// -// template<> struct cholmod_configure_matrix<std::complex<float> > { -// template<typename CholmodType> -// static void run(CholmodType& mat) { -// mat.xtype = CHOLMOD_COMPLEX; -// mat.dtype = CHOLMOD_SINGLE; -// } -// }; - -} // namespace internal - -/** Wraps the Eigen sparse matrix \a mat into a Cholmod sparse matrix object. - * Note that the data are shared. - */ -template<typename _Scalar, int _Options, typename _StorageIndex> -cholmod_sparse viewAsCholmod(Ref<SparseMatrix<_Scalar,_Options,_StorageIndex> > mat) -{ - cholmod_sparse res; - res.nzmax = mat.nonZeros(); - res.nrow = mat.rows(); - res.ncol = mat.cols(); - res.p = mat.outerIndexPtr(); - res.i = mat.innerIndexPtr(); - res.x = mat.valuePtr(); - res.z = 0; - res.sorted = 1; - if(mat.isCompressed()) - { - res.packed = 1; - res.nz = 0; - } - else - { - res.packed = 0; - res.nz = mat.innerNonZeroPtr(); - } - - res.dtype = 0; - res.stype = -1; - - if (internal::is_same<_StorageIndex,int>::value) - { - res.itype = CHOLMOD_INT; - } - else if (internal::is_same<_StorageIndex,SuiteSparse_long>::value) - { - res.itype = CHOLMOD_LONG; - } - else - { - eigen_assert(false && "Index type not supported yet"); - } - - // setup res.xtype - internal::cholmod_configure_matrix<_Scalar>::run(res); - - res.stype = 0; - - return res; -} - -template<typename _Scalar, int _Options, typename _Index> -const cholmod_sparse viewAsCholmod(const SparseMatrix<_Scalar,_Options,_Index>& mat) -{ - cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<_Scalar,_Options,_Index> >(mat.const_cast_derived())); - return res; -} - -template<typename _Scalar, int _Options, typename _Index> -const cholmod_sparse viewAsCholmod(const SparseVector<_Scalar,_Options,_Index>& mat) -{ - cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<_Scalar,_Options,_Index> >(mat.const_cast_derived())); - return res; -} - -/** Returns a view of the Eigen sparse matrix \a mat as Cholmod sparse matrix. - * The data are not copied but shared. */ -template<typename _Scalar, int _Options, typename _Index, unsigned int UpLo> -cholmod_sparse viewAsCholmod(const SparseSelfAdjointView<const SparseMatrix<_Scalar,_Options,_Index>, UpLo>& mat) -{ - cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<_Scalar,_Options,_Index> >(mat.matrix().const_cast_derived())); - - if(UpLo==Upper) res.stype = 1; - if(UpLo==Lower) res.stype = -1; - // swap stype for rowmajor matrices (only works for real matrices) - EIGEN_STATIC_ASSERT((_Options & RowMajorBit) == 0 || NumTraits<_Scalar>::IsComplex == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); - if(_Options & RowMajorBit) res.stype *=-1; - - return res; -} - -/** Returns a view of the Eigen \b dense matrix \a mat as Cholmod dense matrix. - * The data are not copied but shared. */ -template<typename Derived> -cholmod_dense viewAsCholmod(MatrixBase<Derived>& mat) -{ - EIGEN_STATIC_ASSERT((internal::traits<Derived>::Flags&RowMajorBit)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); - typedef typename Derived::Scalar Scalar; - - cholmod_dense res; - res.nrow = mat.rows(); - res.ncol = mat.cols(); - res.nzmax = res.nrow * res.ncol; - res.d = Derived::IsVectorAtCompileTime ? mat.derived().size() : mat.derived().outerStride(); - res.x = (void*)(mat.derived().data()); - res.z = 0; - - internal::cholmod_configure_matrix<Scalar>::run(res); - - return res; -} - -/** Returns a view of the Cholmod sparse matrix \a cm as an Eigen sparse matrix. - * The data are not copied but shared. */ -template<typename Scalar, int Flags, typename StorageIndex> -MappedSparseMatrix<Scalar,Flags,StorageIndex> viewAsEigen(cholmod_sparse& cm) -{ - return MappedSparseMatrix<Scalar,Flags,StorageIndex> - (cm.nrow, cm.ncol, static_cast<StorageIndex*>(cm.p)[cm.ncol], - static_cast<StorageIndex*>(cm.p), static_cast<StorageIndex*>(cm.i),static_cast<Scalar*>(cm.x) ); -} - -namespace internal { - -// template specializations for int and long that call the correct cholmod method - -#define EIGEN_CHOLMOD_SPECIALIZE0(ret, name) \ - template<typename _StorageIndex> inline ret cm_ ## name (cholmod_common &Common) { return cholmod_ ## name (&Common); } \ - template<> inline ret cm_ ## name<SuiteSparse_long> (cholmod_common &Common) { return cholmod_l_ ## name (&Common); } - -#define EIGEN_CHOLMOD_SPECIALIZE1(ret, name, t1, a1) \ - template<typename _StorageIndex> inline ret cm_ ## name (t1& a1, cholmod_common &Common) { return cholmod_ ## name (&a1, &Common); } \ - template<> inline ret cm_ ## name<SuiteSparse_long> (t1& a1, cholmod_common &Common) { return cholmod_l_ ## name (&a1, &Common); } - -EIGEN_CHOLMOD_SPECIALIZE0(int, start) -EIGEN_CHOLMOD_SPECIALIZE0(int, finish) - -EIGEN_CHOLMOD_SPECIALIZE1(int, free_factor, cholmod_factor*, L) -EIGEN_CHOLMOD_SPECIALIZE1(int, free_dense, cholmod_dense*, X) -EIGEN_CHOLMOD_SPECIALIZE1(int, free_sparse, cholmod_sparse*, A) - -EIGEN_CHOLMOD_SPECIALIZE1(cholmod_factor*, analyze, cholmod_sparse, A) - -template<typename _StorageIndex> inline cholmod_dense* cm_solve (int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common &Common) { return cholmod_solve (sys, &L, &B, &Common); } -template<> inline cholmod_dense* cm_solve<SuiteSparse_long> (int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common &Common) { return cholmod_l_solve (sys, &L, &B, &Common); } - -template<typename _StorageIndex> inline cholmod_sparse* cm_spsolve (int sys, cholmod_factor& L, cholmod_sparse& B, cholmod_common &Common) { return cholmod_spsolve (sys, &L, &B, &Common); } -template<> inline cholmod_sparse* cm_spsolve<SuiteSparse_long> (int sys, cholmod_factor& L, cholmod_sparse& B, cholmod_common &Common) { return cholmod_l_spsolve (sys, &L, &B, &Common); } - -template<typename _StorageIndex> -inline int cm_factorize_p (cholmod_sparse* A, double beta[2], _StorageIndex* fset, std::size_t fsize, cholmod_factor* L, cholmod_common &Common) { return cholmod_factorize_p (A, beta, fset, fsize, L, &Common); } -template<> -inline int cm_factorize_p<SuiteSparse_long> (cholmod_sparse* A, double beta[2], SuiteSparse_long* fset, std::size_t fsize, cholmod_factor* L, cholmod_common &Common) { return cholmod_l_factorize_p (A, beta, fset, fsize, L, &Common); } - -#undef EIGEN_CHOLMOD_SPECIALIZE0 -#undef EIGEN_CHOLMOD_SPECIALIZE1 - -} // namespace internal - - -enum CholmodMode { - CholmodAuto, CholmodSimplicialLLt, CholmodSupernodalLLt, CholmodLDLt -}; - - -/** \ingroup CholmodSupport_Module - * \class CholmodBase - * \brief The base class for the direct Cholesky factorization of Cholmod - * \sa class CholmodSupernodalLLT, class CholmodSimplicialLDLT, class CholmodSimplicialLLT - */ -template<typename _MatrixType, int _UpLo, typename Derived> -class CholmodBase : public SparseSolverBase<Derived> -{ - protected: - typedef SparseSolverBase<Derived> Base; - using Base::derived; - using Base::m_isInitialized; - public: - typedef _MatrixType MatrixType; - enum { UpLo = _UpLo }; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef MatrixType CholMatrixType; - typedef typename MatrixType::StorageIndex StorageIndex; - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - public: - - CholmodBase() - : m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false) - { - EIGEN_STATIC_ASSERT((internal::is_same<double,RealScalar>::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY); - m_shiftOffset[0] = m_shiftOffset[1] = 0.0; - internal::cm_start<StorageIndex>(m_cholmod); - } - - explicit CholmodBase(const MatrixType& matrix) - : m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false) - { - EIGEN_STATIC_ASSERT((internal::is_same<double,RealScalar>::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY); - m_shiftOffset[0] = m_shiftOffset[1] = 0.0; - internal::cm_start<StorageIndex>(m_cholmod); - compute(matrix); - } - - ~CholmodBase() - { - if(m_cholmodFactor) - internal::cm_free_factor<StorageIndex>(m_cholmodFactor, m_cholmod); - internal::cm_finish<StorageIndex>(m_cholmod); - } - - inline StorageIndex cols() const { return internal::convert_index<StorageIndex, Index>(m_cholmodFactor->n); } - inline StorageIndex rows() const { return internal::convert_index<StorageIndex, Index>(m_cholmodFactor->n); } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix.appears to be negative. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - - /** Computes the sparse Cholesky decomposition of \a matrix */ - Derived& compute(const MatrixType& matrix) - { - analyzePattern(matrix); - factorize(matrix); - return derived(); - } - - /** Performs a symbolic decomposition on the sparsity pattern of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize() - */ - void analyzePattern(const MatrixType& matrix) - { - if(m_cholmodFactor) - { - internal::cm_free_factor<StorageIndex>(m_cholmodFactor, m_cholmod); - m_cholmodFactor = 0; - } - cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView<UpLo>()); - m_cholmodFactor = internal::cm_analyze<StorageIndex>(A, m_cholmod); - - this->m_isInitialized = true; - this->m_info = Success; - m_analysisIsOk = true; - m_factorizationIsOk = false; - } - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must have the same sparsity pattern as the matrix on which the symbolic decomposition has been performed. - * - * \sa analyzePattern() - */ - void factorize(const MatrixType& matrix) - { - eigen_assert(m_analysisIsOk && "You must first call analyzePattern()"); - cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView<UpLo>()); - internal::cm_factorize_p<StorageIndex>(&A, m_shiftOffset, 0, 0, m_cholmodFactor, m_cholmod); - - // If the factorization failed, minor is the column at which it did. On success minor == n. - this->m_info = (m_cholmodFactor->minor == m_cholmodFactor->n ? Success : NumericalIssue); - m_factorizationIsOk = true; - } - - /** Returns a reference to the Cholmod's configuration structure to get a full control over the performed operations. - * See the Cholmod user guide for details. */ - cholmod_common& cholmod() { return m_cholmod; } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &dest) const - { - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()"); - const Index size = m_cholmodFactor->n; - EIGEN_UNUSED_VARIABLE(size); - eigen_assert(size==b.rows()); - - // Cholmod needs column-major storage without inner-stride, which corresponds to the default behavior of Ref. - Ref<const Matrix<typename Rhs::Scalar,Dynamic,Dynamic,ColMajor> > b_ref(b.derived()); - - cholmod_dense b_cd = viewAsCholmod(b_ref); - cholmod_dense* x_cd = internal::cm_solve<StorageIndex>(CHOLMOD_A, *m_cholmodFactor, b_cd, m_cholmod); - if(!x_cd) - { - this->m_info = NumericalIssue; - return; - } - // TODO optimize this copy by swapping when possible (be careful with alignment, etc.) - // NOTE Actually, the copy can be avoided by calling cholmod_solve2 instead of cholmod_solve - dest = Matrix<Scalar,Dest::RowsAtCompileTime,Dest::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x),b.rows(),b.cols()); - internal::cm_free_dense<StorageIndex>(x_cd, m_cholmod); - } - - /** \internal */ - template<typename RhsDerived, typename DestDerived> - void _solve_impl(const SparseMatrixBase<RhsDerived> &b, SparseMatrixBase<DestDerived> &dest) const - { - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()"); - const Index size = m_cholmodFactor->n; - EIGEN_UNUSED_VARIABLE(size); - eigen_assert(size==b.rows()); - - // note: cs stands for Cholmod Sparse - Ref<SparseMatrix<typename RhsDerived::Scalar,ColMajor,typename RhsDerived::StorageIndex> > b_ref(b.const_cast_derived()); - cholmod_sparse b_cs = viewAsCholmod(b_ref); - cholmod_sparse* x_cs = internal::cm_spsolve<StorageIndex>(CHOLMOD_A, *m_cholmodFactor, b_cs, m_cholmod); - if(!x_cs) - { - this->m_info = NumericalIssue; - return; - } - // TODO optimize this copy by swapping when possible (be careful with alignment, etc.) - // NOTE cholmod_spsolve in fact just calls the dense solver for blocks of 4 columns at a time (similar to Eigen's sparse solver) - dest.derived() = viewAsEigen<typename DestDerived::Scalar,ColMajor,typename DestDerived::StorageIndex>(*x_cs); - internal::cm_free_sparse<StorageIndex>(x_cs, m_cholmod); - } - #endif // EIGEN_PARSED_BY_DOXYGEN - - - /** Sets the shift parameter that will be used to adjust the diagonal coefficients during the numerical factorization. - * - * During the numerical factorization, an offset term is added to the diagonal coefficients:\n - * \c d_ii = \a offset + \c d_ii - * - * The default is \a offset=0. - * - * \returns a reference to \c *this. - */ - Derived& setShift(const RealScalar& offset) - { - m_shiftOffset[0] = double(offset); - return derived(); - } - - /** \returns the determinant of the underlying matrix from the current factorization */ - Scalar determinant() const - { - using std::exp; - return exp(logDeterminant()); - } - - /** \returns the log determinant of the underlying matrix from the current factorization */ - Scalar logDeterminant() const - { - using std::log; - using numext::real; - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()"); - - RealScalar logDet = 0; - Scalar *x = static_cast<Scalar*>(m_cholmodFactor->x); - if (m_cholmodFactor->is_super) - { - // Supernodal factorization stored as a packed list of dense column-major blocs, - // as described by the following structure: - - // super[k] == index of the first column of the j-th super node - StorageIndex *super = static_cast<StorageIndex*>(m_cholmodFactor->super); - // pi[k] == offset to the description of row indices - StorageIndex *pi = static_cast<StorageIndex*>(m_cholmodFactor->pi); - // px[k] == offset to the respective dense block - StorageIndex *px = static_cast<StorageIndex*>(m_cholmodFactor->px); - - Index nb_super_nodes = m_cholmodFactor->nsuper; - for (Index k=0; k < nb_super_nodes; ++k) - { - StorageIndex ncols = super[k + 1] - super[k]; - StorageIndex nrows = pi[k + 1] - pi[k]; - - Map<const Array<Scalar,1,Dynamic>, 0, InnerStride<> > sk(x + px[k], ncols, InnerStride<>(nrows+1)); - logDet += sk.real().log().sum(); - } - } - else - { - // Simplicial factorization stored as standard CSC matrix. - StorageIndex *p = static_cast<StorageIndex*>(m_cholmodFactor->p); - Index size = m_cholmodFactor->n; - for (Index k=0; k<size; ++k) - logDet += log(real( x[p[k]] )); - } - if (m_cholmodFactor->is_ll) - logDet *= 2.0; - return logDet; - }; - - template<typename Stream> - void dumpMemory(Stream& /*s*/) - {} - - protected: - mutable cholmod_common m_cholmod; - cholmod_factor* m_cholmodFactor; - double m_shiftOffset[2]; - mutable ComputationInfo m_info; - int m_factorizationIsOk; - int m_analysisIsOk; -}; - -/** \ingroup CholmodSupport_Module - * \class CholmodSimplicialLLT - * \brief A simplicial direct Cholesky (LLT) factorization and solver based on Cholmod - * - * This class allows to solve for A.X = B sparse linear problems via a simplicial LL^T Cholesky factorization - * using the Cholmod library. - * This simplicial variant is equivalent to Eigen's built-in SimplicialLLT class. Therefore, it has little practical interest. - * The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices - * X and B can be either dense or sparse. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam _UpLo the triangular part that will be used for the computations. It can be Lower - * or Upper. Default is Lower. - * - * \implsparsesolverconcept - * - * This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non compressed. - * - * \warning Only double precision real and complex scalar types are supported by Cholmod. - * - * \sa \ref TutorialSparseSolverConcept, class CholmodSupernodalLLT, class SimplicialLLT - */ -template<typename _MatrixType, int _UpLo = Lower> -class CholmodSimplicialLLT : public CholmodBase<_MatrixType, _UpLo, CholmodSimplicialLLT<_MatrixType, _UpLo> > -{ - typedef CholmodBase<_MatrixType, _UpLo, CholmodSimplicialLLT> Base; - using Base::m_cholmod; - - public: - - typedef _MatrixType MatrixType; - - CholmodSimplicialLLT() : Base() { init(); } - - CholmodSimplicialLLT(const MatrixType& matrix) : Base() - { - init(); - this->compute(matrix); - } - - ~CholmodSimplicialLLT() {} - protected: - void init() - { - m_cholmod.final_asis = 0; - m_cholmod.supernodal = CHOLMOD_SIMPLICIAL; - m_cholmod.final_ll = 1; - } -}; - - -/** \ingroup CholmodSupport_Module - * \class CholmodSimplicialLDLT - * \brief A simplicial direct Cholesky (LDLT) factorization and solver based on Cholmod - * - * This class allows to solve for A.X = B sparse linear problems via a simplicial LDL^T Cholesky factorization - * using the Cholmod library. - * This simplicial variant is equivalent to Eigen's built-in SimplicialLDLT class. Therefore, it has little practical interest. - * The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices - * X and B can be either dense or sparse. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam _UpLo the triangular part that will be used for the computations. It can be Lower - * or Upper. Default is Lower. - * - * \implsparsesolverconcept - * - * This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non compressed. - * - * \warning Only double precision real and complex scalar types are supported by Cholmod. - * - * \sa \ref TutorialSparseSolverConcept, class CholmodSupernodalLLT, class SimplicialLDLT - */ -template<typename _MatrixType, int _UpLo = Lower> -class CholmodSimplicialLDLT : public CholmodBase<_MatrixType, _UpLo, CholmodSimplicialLDLT<_MatrixType, _UpLo> > -{ - typedef CholmodBase<_MatrixType, _UpLo, CholmodSimplicialLDLT> Base; - using Base::m_cholmod; - - public: - - typedef _MatrixType MatrixType; - - CholmodSimplicialLDLT() : Base() { init(); } - - CholmodSimplicialLDLT(const MatrixType& matrix) : Base() - { - init(); - this->compute(matrix); - } - - ~CholmodSimplicialLDLT() {} - protected: - void init() - { - m_cholmod.final_asis = 1; - m_cholmod.supernodal = CHOLMOD_SIMPLICIAL; - } -}; - -/** \ingroup CholmodSupport_Module - * \class CholmodSupernodalLLT - * \brief A supernodal Cholesky (LLT) factorization and solver based on Cholmod - * - * This class allows to solve for A.X = B sparse linear problems via a supernodal LL^T Cholesky factorization - * using the Cholmod library. - * This supernodal variant performs best on dense enough problems, e.g., 3D FEM, or very high order 2D FEM. - * The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices - * X and B can be either dense or sparse. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam _UpLo the triangular part that will be used for the computations. It can be Lower - * or Upper. Default is Lower. - * - * \implsparsesolverconcept - * - * This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non compressed. - * - * \warning Only double precision real and complex scalar types are supported by Cholmod. - * - * \sa \ref TutorialSparseSolverConcept - */ -template<typename _MatrixType, int _UpLo = Lower> -class CholmodSupernodalLLT : public CholmodBase<_MatrixType, _UpLo, CholmodSupernodalLLT<_MatrixType, _UpLo> > -{ - typedef CholmodBase<_MatrixType, _UpLo, CholmodSupernodalLLT> Base; - using Base::m_cholmod; - - public: - - typedef _MatrixType MatrixType; - - CholmodSupernodalLLT() : Base() { init(); } - - CholmodSupernodalLLT(const MatrixType& matrix) : Base() - { - init(); - this->compute(matrix); - } - - ~CholmodSupernodalLLT() {} - protected: - void init() - { - m_cholmod.final_asis = 1; - m_cholmod.supernodal = CHOLMOD_SUPERNODAL; - } -}; - -/** \ingroup CholmodSupport_Module - * \class CholmodDecomposition - * \brief A general Cholesky factorization and solver based on Cholmod - * - * This class allows to solve for A.X = B sparse linear problems via a LL^T or LDL^T Cholesky factorization - * using the Cholmod library. The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices - * X and B can be either dense or sparse. - * - * This variant permits to change the underlying Cholesky method at runtime. - * On the other hand, it does not provide access to the result of the factorization. - * The default is to let Cholmod automatically choose between a simplicial and supernodal factorization. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam _UpLo the triangular part that will be used for the computations. It can be Lower - * or Upper. Default is Lower. - * - * \implsparsesolverconcept - * - * This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non compressed. - * - * \warning Only double precision real and complex scalar types are supported by Cholmod. - * - * \sa \ref TutorialSparseSolverConcept - */ -template<typename _MatrixType, int _UpLo = Lower> -class CholmodDecomposition : public CholmodBase<_MatrixType, _UpLo, CholmodDecomposition<_MatrixType, _UpLo> > -{ - typedef CholmodBase<_MatrixType, _UpLo, CholmodDecomposition> Base; - using Base::m_cholmod; - - public: - - typedef _MatrixType MatrixType; - - CholmodDecomposition() : Base() { init(); } - - CholmodDecomposition(const MatrixType& matrix) : Base() - { - init(); - this->compute(matrix); - } - - ~CholmodDecomposition() {} - - void setMode(CholmodMode mode) - { - switch(mode) - { - case CholmodAuto: - m_cholmod.final_asis = 1; - m_cholmod.supernodal = CHOLMOD_AUTO; - break; - case CholmodSimplicialLLt: - m_cholmod.final_asis = 0; - m_cholmod.supernodal = CHOLMOD_SIMPLICIAL; - m_cholmod.final_ll = 1; - break; - case CholmodSupernodalLLt: - m_cholmod.final_asis = 1; - m_cholmod.supernodal = CHOLMOD_SUPERNODAL; - break; - case CholmodLDLt: - m_cholmod.final_asis = 1; - m_cholmod.supernodal = CHOLMOD_SIMPLICIAL; - break; - default: - break; - } - } - protected: - void init() - { - m_cholmod.final_asis = 1; - m_cholmod.supernodal = CHOLMOD_AUTO; - } -}; - -} // end namespace Eigen - -#endif // EIGEN_CHOLMODSUPPORT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/ArithmeticSequence.h b/external/eigen/include/eigen3/Eigen/src/Core/ArithmeticSequence.h deleted file mode 100644 index b6200fac..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/ArithmeticSequence.h +++ /dev/null @@ -1,413 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ARITHMETIC_SEQUENCE_H -#define EIGEN_ARITHMETIC_SEQUENCE_H - -namespace Eigen { - -namespace internal { - -#if (!EIGEN_HAS_CXX11) || !((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48) -template<typename T> struct aseq_negate {}; - -template<> struct aseq_negate<Index> { - typedef Index type; -}; - -template<int N> struct aseq_negate<FixedInt<N> > { - typedef FixedInt<-N> type; -}; - -// Compilation error in the following case: -template<> struct aseq_negate<FixedInt<DynamicIndex> > {}; - -template<typename FirstType,typename SizeType,typename IncrType, - bool FirstIsSymbolic=symbolic::is_symbolic<FirstType>::value, - bool SizeIsSymbolic =symbolic::is_symbolic<SizeType>::value> -struct aseq_reverse_first_type { - typedef Index type; -}; - -template<typename FirstType,typename SizeType,typename IncrType> -struct aseq_reverse_first_type<FirstType,SizeType,IncrType,true,true> { - typedef symbolic::AddExpr<FirstType, - symbolic::ProductExpr<symbolic::AddExpr<SizeType,symbolic::ValueExpr<FixedInt<-1> > >, - symbolic::ValueExpr<IncrType> > - > type; -}; - -template<typename SizeType,typename IncrType,typename EnableIf = void> -struct aseq_reverse_first_type_aux { - typedef Index type; -}; - -template<typename SizeType,typename IncrType> -struct aseq_reverse_first_type_aux<SizeType,IncrType,typename internal::enable_if<bool((SizeType::value+IncrType::value)|0x1)>::type> { - typedef FixedInt<(SizeType::value-1)*IncrType::value> type; -}; - -template<typename FirstType,typename SizeType,typename IncrType> -struct aseq_reverse_first_type<FirstType,SizeType,IncrType,true,false> { - typedef typename aseq_reverse_first_type_aux<SizeType,IncrType>::type Aux; - typedef symbolic::AddExpr<FirstType,symbolic::ValueExpr<Aux> > type; -}; - -template<typename FirstType,typename SizeType,typename IncrType> -struct aseq_reverse_first_type<FirstType,SizeType,IncrType,false,true> { - typedef symbolic::AddExpr<symbolic::ProductExpr<symbolic::AddExpr<SizeType,symbolic::ValueExpr<FixedInt<-1> > >, - symbolic::ValueExpr<IncrType> >, - symbolic::ValueExpr<> > type; -}; -#endif - -// Helper to cleanup the type of the increment: -template<typename T> struct cleanup_seq_incr { - typedef typename cleanup_index_type<T,DynamicIndex>::type type; -}; - -} - -//-------------------------------------------------------------------------------- -// seq(first,last,incr) and seqN(first,size,incr) -//-------------------------------------------------------------------------------- - -template<typename FirstType=Index,typename SizeType=Index,typename IncrType=internal::FixedInt<1> > -class ArithmeticSequence; - -template<typename FirstType,typename SizeType,typename IncrType> -ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type, - typename internal::cleanup_index_type<SizeType>::type, - typename internal::cleanup_seq_incr<IncrType>::type > -seqN(FirstType first, SizeType size, IncrType incr); - -/** \class ArithmeticSequence - * \ingroup Core_Module - * - * This class represents an arithmetic progression \f$ a_0, a_1, a_2, ..., a_{n-1}\f$ defined by - * its \em first value \f$ a_0 \f$, its \em size (aka length) \em n, and the \em increment (aka stride) - * that is equal to \f$ a_{i+1}-a_{i}\f$ for any \em i. - * - * It is internally used as the return type of the Eigen::seq and Eigen::seqN functions, and as the input arguments - * of DenseBase::operator()(const RowIndices&, const ColIndices&), and most of the time this is the - * only way it is used. - * - * \tparam FirstType type of the first element, usually an Index, - * but internally it can be a symbolic expression - * \tparam SizeType type representing the size of the sequence, usually an Index - * or a compile time integral constant. Internally, it can also be a symbolic expression - * \tparam IncrType type of the increment, can be a runtime Index, or a compile time integral constant (default is compile-time 1) - * - * \sa Eigen::seq, Eigen::seqN, DenseBase::operator()(const RowIndices&, const ColIndices&), class IndexedView - */ -template<typename FirstType,typename SizeType,typename IncrType> -class ArithmeticSequence -{ -public: - ArithmeticSequence(FirstType first, SizeType size) : m_first(first), m_size(size) {} - ArithmeticSequence(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {} - - enum { - SizeAtCompileTime = internal::get_fixed_value<SizeType>::value, - IncrAtCompileTime = internal::get_fixed_value<IncrType,DynamicIndex>::value - }; - - /** \returns the size, i.e., number of elements, of the sequence */ - Index size() const { return m_size; } - - /** \returns the first element \f$ a_0 \f$ in the sequence */ - Index first() const { return m_first; } - - /** \returns the value \f$ a_i \f$ at index \a i in the sequence. */ - Index operator[](Index i) const { return m_first + i * m_incr; } - - const FirstType& firstObject() const { return m_first; } - const SizeType& sizeObject() const { return m_size; } - const IncrType& incrObject() const { return m_incr; } - -protected: - FirstType m_first; - SizeType m_size; - IncrType m_incr; - -public: - -#if EIGEN_HAS_CXX11 && ((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48) - auto reverse() const -> decltype(Eigen::seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr)) { - return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr); - } -#else -protected: - typedef typename internal::aseq_negate<IncrType>::type ReverseIncrType; - typedef typename internal::aseq_reverse_first_type<FirstType,SizeType,IncrType>::type ReverseFirstType; -public: - ArithmeticSequence<ReverseFirstType,SizeType,ReverseIncrType> - reverse() const { - return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr); - } -#endif -}; - -/** \returns an ArithmeticSequence starting at \a first, of length \a size, and increment \a incr - * - * \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */ -template<typename FirstType,typename SizeType,typename IncrType> -ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type,typename internal::cleanup_seq_incr<IncrType>::type > -seqN(FirstType first, SizeType size, IncrType incr) { - return ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type,typename internal::cleanup_seq_incr<IncrType>::type>(first,size,incr); -} - -/** \returns an ArithmeticSequence starting at \a first, of length \a size, and unit increment - * - * \sa seqN(FirstType,SizeType,IncrType), seq(FirstType,LastType) */ -template<typename FirstType,typename SizeType> -ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type > -seqN(FirstType first, SizeType size) { - return ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type>(first,size); -} - -#ifdef EIGEN_PARSED_BY_DOXYGEN - -/** \returns an ArithmeticSequence starting at \a f, up (or down) to \a l, and with positive (or negative) increment \a incr - * - * It is essentially an alias to: - * \code - * seqN(f, (l-f+incr)/incr, incr); - * \endcode - * - * \sa seqN(FirstType,SizeType,IncrType), seq(FirstType,LastType) - */ -template<typename FirstType,typename LastType, typename IncrType> -auto seq(FirstType f, LastType l, IncrType incr); - -/** \returns an ArithmeticSequence starting at \a f, up (or down) to \a l, and unit increment - * - * It is essentially an alias to: - * \code - * seqN(f,l-f+1); - * \endcode - * - * \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) - */ -template<typename FirstType,typename LastType> -auto seq(FirstType f, LastType l); - -#else // EIGEN_PARSED_BY_DOXYGEN - -#if EIGEN_HAS_CXX11 -template<typename FirstType,typename LastType> -auto seq(FirstType f, LastType l) -> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f), - ( typename internal::cleanup_index_type<LastType>::type(l) - - typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()))) -{ - return seqN(typename internal::cleanup_index_type<FirstType>::type(f), - (typename internal::cleanup_index_type<LastType>::type(l) - -typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())); -} - -template<typename FirstType,typename LastType, typename IncrType> -auto seq(FirstType f, LastType l, IncrType incr) - -> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f), - ( typename internal::cleanup_index_type<LastType>::type(l) - - typename internal::cleanup_index_type<FirstType>::type(f)+typename internal::cleanup_seq_incr<IncrType>::type(incr) - ) / typename internal::cleanup_seq_incr<IncrType>::type(incr), - typename internal::cleanup_seq_incr<IncrType>::type(incr))) -{ - typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType; - return seqN(typename internal::cleanup_index_type<FirstType>::type(f), - ( typename internal::cleanup_index_type<LastType>::type(l) - -typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr)) / CleanedIncrType(incr), - CleanedIncrType(incr)); -} - -#else // EIGEN_HAS_CXX11 - -template<typename FirstType,typename LastType> -typename internal::enable_if<!(symbolic::is_symbolic<FirstType>::value || symbolic::is_symbolic<LastType>::value), - ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,Index> >::type -seq(FirstType f, LastType l) -{ - return seqN(typename internal::cleanup_index_type<FirstType>::type(f), - Index((typename internal::cleanup_index_type<LastType>::type(l)-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()))); -} - -template<typename FirstTypeDerived,typename LastType> -typename internal::enable_if<!symbolic::is_symbolic<LastType>::value, - ArithmeticSequence<FirstTypeDerived, symbolic::AddExpr<symbolic::AddExpr<symbolic::NegateExpr<FirstTypeDerived>,symbolic::ValueExpr<> >, - symbolic::ValueExpr<internal::FixedInt<1> > > > >::type -seq(const symbolic::BaseExpr<FirstTypeDerived> &f, LastType l) -{ - return seqN(f.derived(),(typename internal::cleanup_index_type<LastType>::type(l)-f.derived()+fix<1>())); -} - -template<typename FirstType,typename LastTypeDerived> -typename internal::enable_if<!symbolic::is_symbolic<FirstType>::value, - ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type, - symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::ValueExpr<> >, - symbolic::ValueExpr<internal::FixedInt<1> > > > >::type -seq(FirstType f, const symbolic::BaseExpr<LastTypeDerived> &l) -{ - return seqN(typename internal::cleanup_index_type<FirstType>::type(f),(l.derived()-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())); -} - -template<typename FirstTypeDerived,typename LastTypeDerived> -ArithmeticSequence<FirstTypeDerived, - symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::NegateExpr<FirstTypeDerived> >,symbolic::ValueExpr<internal::FixedInt<1> > > > -seq(const symbolic::BaseExpr<FirstTypeDerived> &f, const symbolic::BaseExpr<LastTypeDerived> &l) -{ - return seqN(f.derived(),(l.derived()-f.derived()+fix<1>())); -} - - -template<typename FirstType,typename LastType, typename IncrType> -typename internal::enable_if<!(symbolic::is_symbolic<FirstType>::value || symbolic::is_symbolic<LastType>::value), - ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,Index,typename internal::cleanup_seq_incr<IncrType>::type> >::type -seq(FirstType f, LastType l, IncrType incr) -{ - typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType; - return seqN(typename internal::cleanup_index_type<FirstType>::type(f), - Index((typename internal::cleanup_index_type<LastType>::type(l)-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr))/CleanedIncrType(incr)), incr); -} - -template<typename FirstTypeDerived,typename LastType, typename IncrType> -typename internal::enable_if<!symbolic::is_symbolic<LastType>::value, - ArithmeticSequence<FirstTypeDerived, - symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<symbolic::NegateExpr<FirstTypeDerived>, - symbolic::ValueExpr<> >, - symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >, - symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >, - typename internal::cleanup_seq_incr<IncrType>::type> >::type -seq(const symbolic::BaseExpr<FirstTypeDerived> &f, LastType l, IncrType incr) -{ - typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType; - return seqN(f.derived(),(typename internal::cleanup_index_type<LastType>::type(l)-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr); -} - -template<typename FirstType,typename LastTypeDerived, typename IncrType> -typename internal::enable_if<!symbolic::is_symbolic<FirstType>::value, - ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type, - symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::ValueExpr<> >, - symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >, - symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >, - typename internal::cleanup_seq_incr<IncrType>::type> >::type -seq(FirstType f, const symbolic::BaseExpr<LastTypeDerived> &l, IncrType incr) -{ - typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType; - return seqN(typename internal::cleanup_index_type<FirstType>::type(f), - (l.derived()-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr))/CleanedIncrType(incr), incr); -} - -template<typename FirstTypeDerived,typename LastTypeDerived, typename IncrType> -ArithmeticSequence<FirstTypeDerived, - symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived, - symbolic::NegateExpr<FirstTypeDerived> >, - symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >, - symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >, - typename internal::cleanup_seq_incr<IncrType>::type> -seq(const symbolic::BaseExpr<FirstTypeDerived> &f, const symbolic::BaseExpr<LastTypeDerived> &l, IncrType incr) -{ - typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType; - return seqN(f.derived(),(l.derived()-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr); -} -#endif // EIGEN_HAS_CXX11 - -#endif // EIGEN_PARSED_BY_DOXYGEN - - -#if EIGEN_HAS_CXX11 || defined(EIGEN_PARSED_BY_DOXYGEN) -/** \cpp11 - * \returns a symbolic ArithmeticSequence representing the last \a size elements with increment \a incr. - * - * It is a shortcut for: \code seqN(last-(size-fix<1>)*incr, size, incr) \endcode - * - * \sa lastN(SizeType), seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */ -template<typename SizeType,typename IncrType> -auto lastN(SizeType size, IncrType incr) --> decltype(seqN(Eigen::last-(size-fix<1>())*incr, size, incr)) -{ - return seqN(Eigen::last-(size-fix<1>())*incr, size, incr); -} - -/** \cpp11 - * \returns a symbolic ArithmeticSequence representing the last \a size elements with a unit increment. - * - * It is a shortcut for: \code seq(last+fix<1>-size, last) \endcode - * - * \sa lastN(SizeType,IncrType, seqN(FirstType,SizeType), seq(FirstType,LastType) */ -template<typename SizeType> -auto lastN(SizeType size) --> decltype(seqN(Eigen::last+fix<1>()-size, size)) -{ - return seqN(Eigen::last+fix<1>()-size, size); -} -#endif - -namespace internal { - -// Convert a symbolic span into a usable one (i.e., remove last/end "keywords") -template<typename T> -struct make_size_type { - typedef typename internal::conditional<symbolic::is_symbolic<T>::value, Index, T>::type type; -}; - -template<typename FirstType,typename SizeType,typename IncrType,int XprSize> -struct IndexedViewCompatibleType<ArithmeticSequence<FirstType,SizeType,IncrType>, XprSize> { - typedef ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType> type; -}; - -template<typename FirstType,typename SizeType,typename IncrType> -ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType> -makeIndexedViewCompatible(const ArithmeticSequence<FirstType,SizeType,IncrType>& ids, Index size,SpecializedType) { - return ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType>( - eval_expr_given_size(ids.firstObject(),size),eval_expr_given_size(ids.sizeObject(),size),ids.incrObject()); -} - -template<typename FirstType,typename SizeType,typename IncrType> -struct get_compile_time_incr<ArithmeticSequence<FirstType,SizeType,IncrType> > { - enum { value = get_fixed_value<IncrType,DynamicIndex>::value }; -}; - -} // end namespace internal - -/** \namespace Eigen::indexing - * \ingroup Core_Module - * - * The sole purpose of this namespace is to be able to import all functions - * and symbols that are expected to be used within operator() for indexing - * and slicing. If you already imported the whole Eigen namespace: - * \code using namespace Eigen; \endcode - * then you are already all set. Otherwise, if you don't want/cannot import - * the whole Eigen namespace, the following line: - * \code using namespace Eigen::indexing; \endcode - * is equivalent to: - * \code - using Eigen::all; - using Eigen::seq; - using Eigen::seqN; - using Eigen::lastN; // c++11 only - using Eigen::last; - using Eigen::lastp1; - using Eigen::fix; - \endcode - */ -namespace indexing { - using Eigen::all; - using Eigen::seq; - using Eigen::seqN; - #if EIGEN_HAS_CXX11 - using Eigen::lastN; - #endif - using Eigen::last; - using Eigen::lastp1; - using Eigen::fix; -} - -} // end namespace Eigen - -#endif // EIGEN_ARITHMETIC_SEQUENCE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Array.h b/external/eigen/include/eigen3/Eigen/src/Core/Array.h deleted file mode 100644 index 64fd02dd..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Array.h +++ /dev/null @@ -1,415 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ARRAY_H -#define EIGEN_ARRAY_H - -namespace Eigen { - -namespace internal { -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > -{ - typedef ArrayXpr XprKind; - typedef ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > XprBase; -}; -} - -/** \class Array - * \ingroup Core_Module - * - * \brief General-purpose arrays with easy API for coefficient-wise operations - * - * The %Array class is very similar to the Matrix class. It provides - * general-purpose one- and two-dimensional arrays. The difference between the - * %Array and the %Matrix class is primarily in the API: the API for the - * %Array class provides easy access to coefficient-wise operations, while the - * API for the %Matrix class provides easy access to linear-algebra - * operations. - * - * See documentation of class Matrix for detailed information on the template parameters - * storage layout. - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAY_PLUGIN. - * - * \sa \blank \ref TutorialArrayClass, \ref TopicClassHierarchy - */ -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -class Array - : public PlainObjectBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > -{ - public: - - typedef PlainObjectBase<Array> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Array) - - enum { Options = _Options }; - typedef typename Base::PlainObject PlainObject; - - protected: - template <typename Derived, typename OtherDerived, bool IsVector> - friend struct internal::conservative_resize_like_impl; - - using Base::m_storage; - - public: - - using Base::base; - using Base::coeff; - using Base::coeffRef; - - /** - * The usage of - * using Base::operator=; - * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped - * the usage of 'using'. This should be done only for operator=. - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other) - { - return Base::operator=(other); - } - - /** Set all the entries to \a value. - * \sa DenseBase::setConstant(), DenseBase::fill() - */ - /* This overload is needed because the usage of - * using Base::operator=; - * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped - * the usage of 'using'. This should be done only for operator=. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array& operator=(const Scalar &value) - { - Base::setConstant(value); - return *this; - } - - /** Copies the value of the expression \a other into \c *this with automatic resizing. - * - * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized), - * it will be initialized. - * - * Note that copying a row-vector into a vector (and conversely) is allowed. - * The resizing, if any, is then done in the appropriate way so that row-vectors - * remain row-vectors and vectors remain vectors. - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array& operator=(const DenseBase<OtherDerived>& other) - { - return Base::_set(other); - } - - /** This is a special case of the templated operator=. Its purpose is to - * prevent a default operator= from hiding the templated operator=. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array& operator=(const Array& other) - { - return Base::_set(other); - } - - /** Default constructor. - * - * For fixed-size matrices, does nothing. - * - * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix - * is called a null matrix. This constructor is the unique way to create null matrices: resizing - * a matrix to 0 is not supported. - * - * \sa resize(Index,Index) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array() : Base() - { - Base::_check_template_params(); - EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - } - -#ifndef EIGEN_PARSED_BY_DOXYGEN - // FIXME is it still needed ?? - /** \internal */ - EIGEN_DEVICE_FUNC - Array(internal::constructor_without_unaligned_array_assert) - : Base(internal::constructor_without_unaligned_array_assert()) - { - Base::_check_template_params(); - EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - } -#endif - -#if EIGEN_HAS_RVALUE_REFERENCES - EIGEN_DEVICE_FUNC - Array(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value) - : Base(std::move(other)) - { - Base::_check_template_params(); - } - EIGEN_DEVICE_FUNC - Array& operator=(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) - { - other.swap(*this); - return *this; - } -#endif - - #if EIGEN_HAS_CXX11 - /** \copydoc PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) - * - * Example: \include Array_variadic_ctor_cxx11.cpp - * Output: \verbinclude Array_variadic_ctor_cxx11.out - * - * \sa Array(const std::initializer_list<std::initializer_list<Scalar>>&) - * \sa Array(const Scalar&), Array(const Scalar&,const Scalar&) - */ - template <typename... ArgTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) - : Base(a0, a1, a2, a3, args...) {} - - /** \brief Constructs an array and initializes it from the coefficients given as initializer-lists grouped by row. \cpp11 - * - * In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients: - * - * Example: \include Array_initializer_list_23_cxx11.cpp - * Output: \verbinclude Array_initializer_list_23_cxx11.out - * - * Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is triggered. - * - * In the case of a compile-time column 1D array, implicit transposition from a single row is allowed. - * Therefore <code> Array<int,Dynamic,1>{{1,2,3,4,5}}</code> is legal and the more verbose syntax - * <code>Array<int,Dynamic,1>{{1},{2},{3},{4},{5}}</code> can be avoided: - * - * Example: \include Array_initializer_list_vector_cxx11.cpp - * Output: \verbinclude Array_initializer_list_vector_cxx11.out - * - * In the case of fixed-sized arrays, the initializer list sizes must exactly match the array sizes, - * and implicit transposition is allowed for compile-time 1D arrays only. - * - * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {} - #endif // end EIGEN_HAS_CXX11 - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename T> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE explicit Array(const T& x) - { - Base::_check_template_params(); - Base::template _init1<T>(x); - } - - template<typename T0, typename T1> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1) - { - Base::_check_template_params(); - this->template _init2<T0,T1>(val0, val1); - } - - #else - /** \brief Constructs a fixed-sized array initialized with coefficients starting at \a data */ - EIGEN_DEVICE_FUNC explicit Array(const Scalar *data); - /** Constructs a vector or row-vector with given dimension. \only_for_vectors - * - * Note that this is only useful for dynamic-size vectors. For fixed-size vectors, - * it is redundant to pass the dimension here, so it makes more sense to use the default - * constructor Array() instead. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE explicit Array(Index dim); - /** constructs an initialized 1x1 Array with the given coefficient - * \sa const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args */ - Array(const Scalar& value); - /** constructs an uninitialized array with \a rows rows and \a cols columns. - * - * This is useful for dynamic-size arrays. For fixed-size arrays, - * it is redundant to pass these parameters, so one should use the default constructor - * Array() instead. */ - Array(Index rows, Index cols); - /** constructs an initialized 2D vector with given coefficients - * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) */ - Array(const Scalar& val0, const Scalar& val1); - #endif // end EIGEN_PARSED_BY_DOXYGEN - - /** constructs an initialized 3D vector with given coefficients - * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2) - { - Base::_check_template_params(); - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3) - m_storage.data()[0] = val0; - m_storage.data()[1] = val1; - m_storage.data()[2] = val2; - } - /** constructs an initialized 4D vector with given coefficients - * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, const Scalar& val3) - { - Base::_check_template_params(); - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4) - m_storage.data()[0] = val0; - m_storage.data()[1] = val1; - m_storage.data()[2] = val2; - m_storage.data()[3] = val3; - } - - /** Copy constructor */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array(const Array& other) - : Base(other) - { } - - private: - struct PrivateType {}; - public: - - /** \sa MatrixBase::operator=(const EigenBase<OtherDerived>&) */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other, - typename internal::enable_if<internal::is_convertible<typename OtherDerived::Scalar,Scalar>::value, - PrivateType>::type = PrivateType()) - : Base(other.derived()) - { } - - EIGEN_DEVICE_FUNC inline Index innerStride() const { return 1; } - EIGEN_DEVICE_FUNC inline Index outerStride() const { return this->innerSize(); } - - #ifdef EIGEN_ARRAY_PLUGIN - #include EIGEN_ARRAY_PLUGIN - #endif - - private: - - template<typename MatrixType, typename OtherDerived, bool SwapPointers> - friend struct internal::matrix_swap_impl; -}; - -/** \defgroup arraytypedefs Global array typedefs - * \ingroup Core_Module - * - * %Eigen defines several typedef shortcuts for most common 1D and 2D array types. - * - * The general patterns are the following: - * - * \c ArrayRowsColsType where \c Rows and \c Cols can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size, - * and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c cd - * for complex double. - * - * For example, \c Array33d is a fixed-size 3x3 array type of doubles, and \c ArrayXXf is a dynamic-size matrix of floats. - * - * There are also \c ArraySizeType which are self-explanatory. For example, \c Array4cf is - * a fixed-size 1D array of 4 complex floats. - * - * With \cpp11, template alias are also defined for common sizes. - * They follow the same pattern as above except that the scalar type suffix is replaced by a - * template parameter, i.e.: - * - `ArrayRowsCols<Type>` where `Rows` and `Cols` can be \c 2,\c 3,\c 4, or \c X for fixed or dynamic size. - * - `ArraySize<Type>` where `Size` can be \c 2,\c 3,\c 4 or \c X for fixed or dynamic size 1D arrays. - * - * \sa class Array - */ - -#define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ -/** \ingroup arraytypedefs */ \ -typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \ -/** \ingroup arraytypedefs */ \ -typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix; - -#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \ -/** \ingroup arraytypedefs */ \ -typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \ -/** \ingroup arraytypedefs */ \ -typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix; - -#define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ -EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \ -EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \ -EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \ -EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \ -EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \ -EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \ -EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4) - -EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i) -EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f) -EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d) -EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>, cf) -EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd) - -#undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES -#undef EIGEN_MAKE_ARRAY_TYPEDEFS -#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS - -#if EIGEN_HAS_CXX11 - -#define EIGEN_MAKE_ARRAY_TYPEDEFS(Size, SizeSuffix) \ -/** \ingroup arraytypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using Array##SizeSuffix##SizeSuffix = Array<Type, Size, Size>; \ -/** \ingroup arraytypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using Array##SizeSuffix = Array<Type, Size, 1>; - -#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Size) \ -/** \ingroup arraytypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using Array##Size##X = Array<Type, Size, Dynamic>; \ -/** \ingroup arraytypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using Array##X##Size = Array<Type, Dynamic, Size>; - -EIGEN_MAKE_ARRAY_TYPEDEFS(2, 2) -EIGEN_MAKE_ARRAY_TYPEDEFS(3, 3) -EIGEN_MAKE_ARRAY_TYPEDEFS(4, 4) -EIGEN_MAKE_ARRAY_TYPEDEFS(Dynamic, X) -EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(2) -EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(3) -EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(4) - -#undef EIGEN_MAKE_ARRAY_TYPEDEFS -#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS - -#endif // EIGEN_HAS_CXX11 - -#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \ -using Eigen::Matrix##SizeSuffix##TypeSuffix; \ -using Eigen::Vector##SizeSuffix##TypeSuffix; \ -using Eigen::RowVector##SizeSuffix##TypeSuffix; - -#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \ - -#define EIGEN_USING_ARRAY_TYPEDEFS \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \ -EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd) - -} // end namespace Eigen - -#endif // EIGEN_ARRAY_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/ArrayBase.h b/external/eigen/include/eigen3/Eigen/src/Core/ArrayBase.h deleted file mode 100644 index ea3dd1c3..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/ArrayBase.h +++ /dev/null @@ -1,226 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ARRAYBASE_H -#define EIGEN_ARRAYBASE_H - -namespace Eigen { - -template<typename ExpressionType> class MatrixWrapper; - -/** \class ArrayBase - * \ingroup Core_Module - * - * \brief Base class for all 1D and 2D array, and related expressions - * - * An array is similar to a dense vector or matrix. While matrices are mathematical - * objects with well defined linear algebra operators, an array is just a collection - * of scalar values arranged in a one or two dimensionnal fashion. As the main consequence, - * all operations applied to an array are performed coefficient wise. Furthermore, - * arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient - * constructors allowing to easily write generic code working for both scalar values - * and arrays. - * - * This class is the base that is inherited by all array expression types. - * - * \tparam Derived is the derived type, e.g., an array or an expression type. - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN. - * - * \sa class MatrixBase, \ref TopicClassHierarchy - */ -template<typename Derived> class ArrayBase - : public DenseBase<Derived> -{ - public: -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** The base class for a given storage type. */ - typedef ArrayBase StorageBaseType; - - typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl; - - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename internal::packet_traits<Scalar>::type PacketScalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - - typedef DenseBase<Derived> Base; - using Base::RowsAtCompileTime; - using Base::ColsAtCompileTime; - using Base::SizeAtCompileTime; - using Base::MaxRowsAtCompileTime; - using Base::MaxColsAtCompileTime; - using Base::MaxSizeAtCompileTime; - using Base::IsVectorAtCompileTime; - using Base::Flags; - - using Base::derived; - using Base::const_cast_derived; - using Base::rows; - using Base::cols; - using Base::size; - using Base::coeff; - using Base::coeffRef; - using Base::lazyAssign; - using Base::operator-; - using Base::operator=; - using Base::operator+=; - using Base::operator-=; - using Base::operator*=; - using Base::operator/=; - - typedef typename Base::CoeffReturnType CoeffReturnType; - -#endif // not EIGEN_PARSED_BY_DOXYGEN - -#ifndef EIGEN_PARSED_BY_DOXYGEN - typedef typename Base::PlainObject PlainObject; - - /** \internal Represents a matrix with all coefficients equal to one another*/ - typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType; -#endif // not EIGEN_PARSED_BY_DOXYGEN - -#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase -#define EIGEN_DOC_UNARY_ADDONS(X,Y) -# include "../plugins/MatrixCwiseUnaryOps.h" -# include "../plugins/ArrayCwiseUnaryOps.h" -# include "../plugins/CommonCwiseBinaryOps.h" -# include "../plugins/MatrixCwiseBinaryOps.h" -# include "../plugins/ArrayCwiseBinaryOps.h" -# ifdef EIGEN_ARRAYBASE_PLUGIN -# include EIGEN_ARRAYBASE_PLUGIN -# endif -#undef EIGEN_CURRENT_STORAGE_BASE_CLASS -#undef EIGEN_DOC_UNARY_ADDONS - - /** Special case of the template operator=, in order to prevent the compiler - * from generating a default operator= (issue hit with g++ 4.1) - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator=(const ArrayBase& other) - { - internal::call_assignment(derived(), other.derived()); - return derived(); - } - - /** Set all the entries to \a value. - * \sa DenseBase::setConstant(), DenseBase::fill() */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator=(const Scalar &value) - { Base::setConstant(value); return derived(); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator+=(const Scalar& scalar); - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator-=(const Scalar& scalar); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator+=(const ArrayBase<OtherDerived>& other); - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator-=(const ArrayBase<OtherDerived>& other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator*=(const ArrayBase<OtherDerived>& other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator/=(const ArrayBase<OtherDerived>& other); - - public: - EIGEN_DEVICE_FUNC - ArrayBase<Derived>& array() { return *this; } - EIGEN_DEVICE_FUNC - const ArrayBase<Derived>& array() const { return *this; } - - /** \returns an \link Eigen::MatrixBase Matrix \endlink expression of this array - * \sa MatrixBase::array() */ - EIGEN_DEVICE_FUNC - MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); } - EIGEN_DEVICE_FUNC - const MatrixWrapper<const Derived> matrix() const { return MatrixWrapper<const Derived>(derived()); } - -// template<typename Dest> -// inline void evalTo(Dest& dst) const { dst = matrix(); } - - protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase) - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase) - - private: - explicit ArrayBase(Index); - ArrayBase(Index,Index); - template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&); - protected: - // mixing arrays and matrices is not legal - template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& ) - {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;} - // mixing arrays and matrices is not legal - template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& ) - {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;} -}; - -/** replaces \c *this by \c *this - \a other. - * - * \returns a reference to \c *this - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & -ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other) -{ - call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -/** replaces \c *this by \c *this + \a other. - * - * \returns a reference to \c *this - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & -ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other) -{ - call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -/** replaces \c *this by \c *this * \a other coefficient wise. - * - * \returns a reference to \c *this - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & -ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other) -{ - call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -/** replaces \c *this by \c *this / \a other coefficient wise. - * - * \returns a reference to \c *this - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & -ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other) -{ - call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -} // end namespace Eigen - -#endif // EIGEN_ARRAYBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/ArrayWrapper.h b/external/eigen/include/eigen3/Eigen/src/Core/ArrayWrapper.h deleted file mode 100644 index 757b3182..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/ArrayWrapper.h +++ /dev/null @@ -1,209 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ARRAYWRAPPER_H -#define EIGEN_ARRAYWRAPPER_H - -namespace Eigen { - -/** \class ArrayWrapper - * \ingroup Core_Module - * - * \brief Expression of a mathematical vector or matrix as an array object - * - * This class is the return type of MatrixBase::array(), and most of the time - * this is the only way it is use. - * - * \sa MatrixBase::array(), class MatrixWrapper - */ - -namespace internal { -template<typename ExpressionType> -struct traits<ArrayWrapper<ExpressionType> > - : public traits<typename remove_all<typename ExpressionType::Nested>::type > -{ - typedef ArrayXpr XprKind; - // Let's remove NestByRefBit - enum { - Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags, - LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0, - Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag - }; -}; -} - -template<typename ExpressionType> -class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> > -{ - public: - typedef ArrayBase<ArrayWrapper> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper) - typedef typename internal::remove_all<ExpressionType>::type NestedExpression; - - typedef typename internal::conditional< - internal::is_lvalue<ExpressionType>::value, - Scalar, - const Scalar - >::type ScalarWithConstIfNotLvalue; - - typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType; - - using Base::coeffRef; - - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {} - - EIGEN_DEVICE_FUNC - inline Index rows() const { return m_expression.rows(); } - EIGEN_DEVICE_FUNC - inline Index cols() const { return m_expression.cols(); } - EIGEN_DEVICE_FUNC - inline Index outerStride() const { return m_expression.outerStride(); } - EIGEN_DEVICE_FUNC - inline Index innerStride() const { return m_expression.innerStride(); } - - EIGEN_DEVICE_FUNC - inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } - EIGEN_DEVICE_FUNC - inline const Scalar* data() const { return m_expression.data(); } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index rowId, Index colId) const - { - return m_expression.coeffRef(rowId, colId); - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index index) const - { - return m_expression.coeffRef(index); - } - - template<typename Dest> - EIGEN_DEVICE_FUNC - inline void evalTo(Dest& dst) const { dst = m_expression; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<NestedExpressionType>::type& - nestedExpression() const - { - return m_expression; - } - - /** Forwards the resizing request to the nested expression - * \sa DenseBase::resize(Index) */ - EIGEN_DEVICE_FUNC - void resize(Index newSize) { m_expression.resize(newSize); } - /** Forwards the resizing request to the nested expression - * \sa DenseBase::resize(Index,Index)*/ - EIGEN_DEVICE_FUNC - void resize(Index rows, Index cols) { m_expression.resize(rows,cols); } - - protected: - NestedExpressionType m_expression; -}; - -/** \class MatrixWrapper - * \ingroup Core_Module - * - * \brief Expression of an array as a mathematical vector or matrix - * - * This class is the return type of ArrayBase::matrix(), and most of the time - * this is the only way it is use. - * - * \sa MatrixBase::matrix(), class ArrayWrapper - */ - -namespace internal { -template<typename ExpressionType> -struct traits<MatrixWrapper<ExpressionType> > - : public traits<typename remove_all<typename ExpressionType::Nested>::type > -{ - typedef MatrixXpr XprKind; - // Let's remove NestByRefBit - enum { - Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags, - LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0, - Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag - }; -}; -} - -template<typename ExpressionType> -class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> > -{ - public: - typedef MatrixBase<MatrixWrapper<ExpressionType> > Base; - EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper) - typedef typename internal::remove_all<ExpressionType>::type NestedExpression; - - typedef typename internal::conditional< - internal::is_lvalue<ExpressionType>::value, - Scalar, - const Scalar - >::type ScalarWithConstIfNotLvalue; - - typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType; - - using Base::coeffRef; - - EIGEN_DEVICE_FUNC - explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {} - - EIGEN_DEVICE_FUNC - inline Index rows() const { return m_expression.rows(); } - EIGEN_DEVICE_FUNC - inline Index cols() const { return m_expression.cols(); } - EIGEN_DEVICE_FUNC - inline Index outerStride() const { return m_expression.outerStride(); } - EIGEN_DEVICE_FUNC - inline Index innerStride() const { return m_expression.innerStride(); } - - EIGEN_DEVICE_FUNC - inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } - EIGEN_DEVICE_FUNC - inline const Scalar* data() const { return m_expression.data(); } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index rowId, Index colId) const - { - return m_expression.derived().coeffRef(rowId, colId); - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index index) const - { - return m_expression.coeffRef(index); - } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<NestedExpressionType>::type& - nestedExpression() const - { - return m_expression; - } - - /** Forwards the resizing request to the nested expression - * \sa DenseBase::resize(Index) */ - EIGEN_DEVICE_FUNC - void resize(Index newSize) { m_expression.resize(newSize); } - /** Forwards the resizing request to the nested expression - * \sa DenseBase::resize(Index,Index)*/ - EIGEN_DEVICE_FUNC - void resize(Index rows, Index cols) { m_expression.resize(rows,cols); } - - protected: - NestedExpressionType m_expression; -}; - -} // end namespace Eigen - -#endif // EIGEN_ARRAYWRAPPER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Assign.h b/external/eigen/include/eigen3/Eigen/src/Core/Assign.h deleted file mode 100644 index 655412ef..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Assign.h +++ /dev/null @@ -1,90 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net> -// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ASSIGN_H -#define EIGEN_ASSIGN_H - -namespace Eigen { - -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived> - ::lazyAssign(const DenseBase<OtherDerived>& other) -{ - enum{ - SameType = internal::is_same<typename Derived::Scalar,typename OtherDerived::Scalar>::value - }; - - EIGEN_STATIC_ASSERT_LVALUE(Derived) - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived) - EIGEN_STATIC_ASSERT(SameType,YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - - eigen_assert(rows() == other.rows() && cols() == other.cols()); - internal::call_assignment_no_alias(derived(),other.derived()); - - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase<OtherDerived>& other) -{ - internal::call_assignment(derived(), other.derived()); - return derived(); -} - -template<typename Derived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase& other) -{ - internal::call_assignment(derived(), other.derived()); - return derived(); -} - -template<typename Derived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const MatrixBase& other) -{ - internal::call_assignment(derived(), other.derived()); - return derived(); -} - -template<typename Derived> -template <typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const DenseBase<OtherDerived>& other) -{ - internal::call_assignment(derived(), other.derived()); - return derived(); -} - -template<typename Derived> -template <typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const EigenBase<OtherDerived>& other) -{ - internal::call_assignment(derived(), other.derived()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other) -{ - other.derived().evalTo(derived()); - return derived(); -} - -} // end namespace Eigen - -#endif // EIGEN_ASSIGN_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/AssignEvaluator.h b/external/eigen/include/eigen3/Eigen/src/Core/AssignEvaluator.h deleted file mode 100644 index 229e2585..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/AssignEvaluator.h +++ /dev/null @@ -1,982 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2011-2012 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ASSIGN_EVALUATOR_H -#define EIGEN_ASSIGN_EVALUATOR_H - -namespace Eigen { - -// This implementation is based on Assign.h - -namespace internal { - -/*************************************************************************** -* Part 1 : the logic deciding a strategy for traversal and unrolling * -***************************************************************************/ - -// copy_using_evaluator_traits is based on assign_traits - -template <typename DstEvaluator, typename SrcEvaluator, typename AssignFunc, int MaxPacketSize = -1> -struct copy_using_evaluator_traits -{ - typedef typename DstEvaluator::XprType Dst; - typedef typename Dst::Scalar DstScalar; - - enum { - DstFlags = DstEvaluator::Flags, - SrcFlags = SrcEvaluator::Flags - }; - -public: - enum { - DstAlignment = DstEvaluator::Alignment, - SrcAlignment = SrcEvaluator::Alignment, - DstHasDirectAccess = (DstFlags & DirectAccessBit) == DirectAccessBit, - JointAlignment = EIGEN_PLAIN_ENUM_MIN(DstAlignment,SrcAlignment) - }; - -private: - enum { - InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime) - : int(DstFlags)&RowMajorBit ? int(Dst::ColsAtCompileTime) - : int(Dst::RowsAtCompileTime), - InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime) - : int(DstFlags)&RowMajorBit ? int(Dst::MaxColsAtCompileTime) - : int(Dst::MaxRowsAtCompileTime), - RestrictedInnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(InnerSize,MaxPacketSize), - RestrictedLinearSize = EIGEN_SIZE_MIN_PREFER_FIXED(Dst::SizeAtCompileTime,MaxPacketSize), - OuterStride = int(outer_stride_at_compile_time<Dst>::ret), - MaxSizeAtCompileTime = Dst::SizeAtCompileTime - }; - - // TODO distinguish between linear traversal and inner-traversals - typedef typename find_best_packet<DstScalar,RestrictedLinearSize>::type LinearPacketType; - typedef typename find_best_packet<DstScalar,RestrictedInnerSize>::type InnerPacketType; - - enum { - LinearPacketSize = unpacket_traits<LinearPacketType>::size, - InnerPacketSize = unpacket_traits<InnerPacketType>::size - }; - -public: - enum { - LinearRequiredAlignment = unpacket_traits<LinearPacketType>::alignment, - InnerRequiredAlignment = unpacket_traits<InnerPacketType>::alignment - }; - -private: - enum { - DstIsRowMajor = DstFlags&RowMajorBit, - SrcIsRowMajor = SrcFlags&RowMajorBit, - StorageOrdersAgree = (int(DstIsRowMajor) == int(SrcIsRowMajor)), - MightVectorize = bool(StorageOrdersAgree) - && (int(DstFlags) & int(SrcFlags) & ActualPacketAccessBit) - && bool(functor_traits<AssignFunc>::PacketAccess), - MayInnerVectorize = MightVectorize - && int(InnerSize)!=Dynamic && int(InnerSize)%int(InnerPacketSize)==0 - && int(OuterStride)!=Dynamic && int(OuterStride)%int(InnerPacketSize)==0 - && (EIGEN_UNALIGNED_VECTORIZE || int(JointAlignment)>=int(InnerRequiredAlignment)), - MayLinearize = bool(StorageOrdersAgree) && (int(DstFlags) & int(SrcFlags) & LinearAccessBit), - MayLinearVectorize = bool(MightVectorize) && bool(MayLinearize) && bool(DstHasDirectAccess) - && (EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment)>=int(LinearRequiredAlignment)) || MaxSizeAtCompileTime == Dynamic), - /* If the destination isn't aligned, we have to do runtime checks and we don't unroll, - so it's only good for large enough sizes. */ - MaySliceVectorize = bool(MightVectorize) && bool(DstHasDirectAccess) - && (int(InnerMaxSize)==Dynamic || int(InnerMaxSize)>=(EIGEN_UNALIGNED_VECTORIZE?InnerPacketSize:(3*InnerPacketSize))) - /* slice vectorization can be slow, so we only want it if the slices are big, which is - indicated by InnerMaxSize rather than InnerSize, think of the case of a dynamic block - in a fixed-size matrix - However, with EIGEN_UNALIGNED_VECTORIZE and unrolling, slice vectorization is still worth it */ - }; - -public: - enum { - Traversal = (int(MayLinearVectorize) && (LinearPacketSize>InnerPacketSize)) ? int(LinearVectorizedTraversal) - : int(MayInnerVectorize) ? int(InnerVectorizedTraversal) - : int(MayLinearVectorize) ? int(LinearVectorizedTraversal) - : int(MaySliceVectorize) ? int(SliceVectorizedTraversal) - : int(MayLinearize) ? int(LinearTraversal) - : int(DefaultTraversal), - Vectorized = int(Traversal) == InnerVectorizedTraversal - || int(Traversal) == LinearVectorizedTraversal - || int(Traversal) == SliceVectorizedTraversal - }; - - typedef typename conditional<int(Traversal)==LinearVectorizedTraversal, LinearPacketType, InnerPacketType>::type PacketType; - -private: - enum { - ActualPacketSize = int(Traversal)==LinearVectorizedTraversal ? LinearPacketSize - : Vectorized ? InnerPacketSize - : 1, - UnrollingLimit = EIGEN_UNROLLING_LIMIT * ActualPacketSize, - MayUnrollCompletely = int(Dst::SizeAtCompileTime) != Dynamic - && int(Dst::SizeAtCompileTime) * (int(DstEvaluator::CoeffReadCost)+int(SrcEvaluator::CoeffReadCost)) <= int(UnrollingLimit), - MayUnrollInner = int(InnerSize) != Dynamic - && int(InnerSize) * (int(DstEvaluator::CoeffReadCost)+int(SrcEvaluator::CoeffReadCost)) <= int(UnrollingLimit) - }; - -public: - enum { - Unrolling = (int(Traversal) == int(InnerVectorizedTraversal) || int(Traversal) == int(DefaultTraversal)) - ? ( - int(MayUnrollCompletely) ? int(CompleteUnrolling) - : int(MayUnrollInner) ? int(InnerUnrolling) - : int(NoUnrolling) - ) - : int(Traversal) == int(LinearVectorizedTraversal) - ? ( bool(MayUnrollCompletely) && ( EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment)>=int(LinearRequiredAlignment))) - ? int(CompleteUnrolling) - : int(NoUnrolling) ) - : int(Traversal) == int(LinearTraversal) - ? ( bool(MayUnrollCompletely) ? int(CompleteUnrolling) - : int(NoUnrolling) ) -#if EIGEN_UNALIGNED_VECTORIZE - : int(Traversal) == int(SliceVectorizedTraversal) - ? ( bool(MayUnrollInner) ? int(InnerUnrolling) - : int(NoUnrolling) ) -#endif - : int(NoUnrolling) - }; - -#ifdef EIGEN_DEBUG_ASSIGN - static void debug() - { - std::cerr << "DstXpr: " << typeid(typename DstEvaluator::XprType).name() << std::endl; - std::cerr << "SrcXpr: " << typeid(typename SrcEvaluator::XprType).name() << std::endl; - std::cerr.setf(std::ios::hex, std::ios::basefield); - std::cerr << "DstFlags" << " = " << DstFlags << " (" << demangle_flags(DstFlags) << " )" << std::endl; - std::cerr << "SrcFlags" << " = " << SrcFlags << " (" << demangle_flags(SrcFlags) << " )" << std::endl; - std::cerr.unsetf(std::ios::hex); - EIGEN_DEBUG_VAR(DstAlignment) - EIGEN_DEBUG_VAR(SrcAlignment) - EIGEN_DEBUG_VAR(LinearRequiredAlignment) - EIGEN_DEBUG_VAR(InnerRequiredAlignment) - EIGEN_DEBUG_VAR(JointAlignment) - EIGEN_DEBUG_VAR(InnerSize) - EIGEN_DEBUG_VAR(InnerMaxSize) - EIGEN_DEBUG_VAR(LinearPacketSize) - EIGEN_DEBUG_VAR(InnerPacketSize) - EIGEN_DEBUG_VAR(ActualPacketSize) - EIGEN_DEBUG_VAR(StorageOrdersAgree) - EIGEN_DEBUG_VAR(MightVectorize) - EIGEN_DEBUG_VAR(MayLinearize) - EIGEN_DEBUG_VAR(MayInnerVectorize) - EIGEN_DEBUG_VAR(MayLinearVectorize) - EIGEN_DEBUG_VAR(MaySliceVectorize) - std::cerr << "Traversal" << " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl; - EIGEN_DEBUG_VAR(SrcEvaluator::CoeffReadCost) - EIGEN_DEBUG_VAR(DstEvaluator::CoeffReadCost) - EIGEN_DEBUG_VAR(Dst::SizeAtCompileTime) - EIGEN_DEBUG_VAR(UnrollingLimit) - EIGEN_DEBUG_VAR(MayUnrollCompletely) - EIGEN_DEBUG_VAR(MayUnrollInner) - std::cerr << "Unrolling" << " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl; - std::cerr << std::endl; - } -#endif -}; - -/*************************************************************************** -* Part 2 : meta-unrollers -***************************************************************************/ - -/************************ -*** Default traversal *** -************************/ - -template<typename Kernel, int Index, int Stop> -struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling -{ - // FIXME: this is not very clean, perhaps this information should be provided by the kernel? - typedef typename Kernel::DstEvaluatorType DstEvaluatorType; - typedef typename DstEvaluatorType::XprType DstXprType; - - enum { - outer = Index / DstXprType::InnerSizeAtCompileTime, - inner = Index % DstXprType::InnerSizeAtCompileTime - }; - - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - kernel.assignCoeffByOuterInner(outer, inner); - copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Index+1, Stop>::run(kernel); - } -}; - -template<typename Kernel, int Stop> -struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Stop, Stop> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { } -}; - -template<typename Kernel, int Index_, int Stop> -struct copy_using_evaluator_DefaultTraversal_InnerUnrolling -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel, Index outer) - { - kernel.assignCoeffByOuterInner(outer, Index_); - copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, Index_+1, Stop>::run(kernel, outer); - } -}; - -template<typename Kernel, int Stop> -struct copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, Stop, Stop> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index) { } -}; - -/*********************** -*** Linear traversal *** -***********************/ - -template<typename Kernel, int Index, int Stop> -struct copy_using_evaluator_LinearTraversal_CompleteUnrolling -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) - { - kernel.assignCoeff(Index); - copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, Index+1, Stop>::run(kernel); - } -}; - -template<typename Kernel, int Stop> -struct copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, Stop, Stop> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { } -}; - -/************************** -*** Inner vectorization *** -**************************/ - -template<typename Kernel, int Index, int Stop> -struct copy_using_evaluator_innervec_CompleteUnrolling -{ - // FIXME: this is not very clean, perhaps this information should be provided by the kernel? - typedef typename Kernel::DstEvaluatorType DstEvaluatorType; - typedef typename DstEvaluatorType::XprType DstXprType; - typedef typename Kernel::PacketType PacketType; - - enum { - outer = Index / DstXprType::InnerSizeAtCompileTime, - inner = Index % DstXprType::InnerSizeAtCompileTime, - SrcAlignment = Kernel::AssignmentTraits::SrcAlignment, - DstAlignment = Kernel::AssignmentTraits::DstAlignment - }; - - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner); - enum { NextIndex = Index + unpacket_traits<PacketType>::size }; - copy_using_evaluator_innervec_CompleteUnrolling<Kernel, NextIndex, Stop>::run(kernel); - } -}; - -template<typename Kernel, int Stop> -struct copy_using_evaluator_innervec_CompleteUnrolling<Kernel, Stop, Stop> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { } -}; - -template<typename Kernel, int Index_, int Stop, int SrcAlignment, int DstAlignment> -struct copy_using_evaluator_innervec_InnerUnrolling -{ - typedef typename Kernel::PacketType PacketType; - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel, Index outer) - { - kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, Index_); - enum { NextIndex = Index_ + unpacket_traits<PacketType>::size }; - copy_using_evaluator_innervec_InnerUnrolling<Kernel, NextIndex, Stop, SrcAlignment, DstAlignment>::run(kernel, outer); - } -}; - -template<typename Kernel, int Stop, int SrcAlignment, int DstAlignment> -struct copy_using_evaluator_innervec_InnerUnrolling<Kernel, Stop, Stop, SrcAlignment, DstAlignment> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &, Index) { } -}; - -/*************************************************************************** -* Part 3 : implementation of all cases -***************************************************************************/ - -// dense_assignment_loop is based on assign_impl - -template<typename Kernel, - int Traversal = Kernel::AssignmentTraits::Traversal, - int Unrolling = Kernel::AssignmentTraits::Unrolling> -struct dense_assignment_loop; - -/************************ -*** Default traversal *** -************************/ - -template<typename Kernel> -struct dense_assignment_loop<Kernel, DefaultTraversal, NoUnrolling> -{ - EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE run(Kernel &kernel) - { - for(Index outer = 0; outer < kernel.outerSize(); ++outer) { - for(Index inner = 0; inner < kernel.innerSize(); ++inner) { - kernel.assignCoeffByOuterInner(outer, inner); - } - } - } -}; - -template<typename Kernel> -struct dense_assignment_loop<Kernel, DefaultTraversal, CompleteUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - typedef typename Kernel::DstEvaluatorType::XprType DstXprType; - copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel); - } -}; - -template<typename Kernel> -struct dense_assignment_loop<Kernel, DefaultTraversal, InnerUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - typedef typename Kernel::DstEvaluatorType::XprType DstXprType; - - const Index outerSize = kernel.outerSize(); - for(Index outer = 0; outer < outerSize; ++outer) - copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, 0, DstXprType::InnerSizeAtCompileTime>::run(kernel, outer); - } -}; - -/*************************** -*** Linear vectorization *** -***************************/ - - -// The goal of unaligned_dense_assignment_loop is simply to factorize the handling -// of the non vectorizable beginning and ending parts - -template <bool IsAligned = false> -struct unaligned_dense_assignment_loop -{ - // if IsAligned = true, then do nothing - template <typename Kernel> - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index, Index) {} -}; - -template <> -struct unaligned_dense_assignment_loop<false> -{ - // MSVC must not inline this functions. If it does, it fails to optimize the - // packet access path. - // FIXME check which version exhibits this issue -#if EIGEN_COMP_MSVC - template <typename Kernel> - static EIGEN_DONT_INLINE void run(Kernel &kernel, - Index start, - Index end) -#else - template <typename Kernel> - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel, - Index start, - Index end) -#endif - { - for (Index index = start; index < end; ++index) - kernel.assignCoeff(index); - } -}; - -template<typename Kernel> -struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, NoUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - const Index size = kernel.size(); - typedef typename Kernel::Scalar Scalar; - typedef typename Kernel::PacketType PacketType; - enum { - requestedAlignment = Kernel::AssignmentTraits::LinearRequiredAlignment, - packetSize = unpacket_traits<PacketType>::size, - dstIsAligned = int(Kernel::AssignmentTraits::DstAlignment)>=int(requestedAlignment), - dstAlignment = packet_traits<Scalar>::AlignedOnScalar ? int(requestedAlignment) - : int(Kernel::AssignmentTraits::DstAlignment), - srcAlignment = Kernel::AssignmentTraits::JointAlignment - }; - const Index alignedStart = dstIsAligned ? 0 : internal::first_aligned<requestedAlignment>(kernel.dstDataPtr(), size); - const Index alignedEnd = alignedStart + ((size-alignedStart)/packetSize)*packetSize; - - unaligned_dense_assignment_loop<dstIsAligned!=0>::run(kernel, 0, alignedStart); - - for(Index index = alignedStart; index < alignedEnd; index += packetSize) - kernel.template assignPacket<dstAlignment, srcAlignment, PacketType>(index); - - unaligned_dense_assignment_loop<>::run(kernel, alignedEnd, size); - } -}; - -template<typename Kernel> -struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, CompleteUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - typedef typename Kernel::DstEvaluatorType::XprType DstXprType; - typedef typename Kernel::PacketType PacketType; - - enum { size = DstXprType::SizeAtCompileTime, - packetSize =unpacket_traits<PacketType>::size, - alignedSize = (size/packetSize)*packetSize }; - - copy_using_evaluator_innervec_CompleteUnrolling<Kernel, 0, alignedSize>::run(kernel); - copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, alignedSize, size>::run(kernel); - } -}; - -/************************** -*** Inner vectorization *** -**************************/ - -template<typename Kernel> -struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, NoUnrolling> -{ - typedef typename Kernel::PacketType PacketType; - enum { - SrcAlignment = Kernel::AssignmentTraits::SrcAlignment, - DstAlignment = Kernel::AssignmentTraits::DstAlignment - }; - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - const Index innerSize = kernel.innerSize(); - const Index outerSize = kernel.outerSize(); - const Index packetSize = unpacket_traits<PacketType>::size; - for(Index outer = 0; outer < outerSize; ++outer) - for(Index inner = 0; inner < innerSize; inner+=packetSize) - kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner); - } -}; - -template<typename Kernel> -struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, CompleteUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - typedef typename Kernel::DstEvaluatorType::XprType DstXprType; - copy_using_evaluator_innervec_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel); - } -}; - -template<typename Kernel> -struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, InnerUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - typedef typename Kernel::DstEvaluatorType::XprType DstXprType; - typedef typename Kernel::AssignmentTraits Traits; - const Index outerSize = kernel.outerSize(); - for(Index outer = 0; outer < outerSize; ++outer) - copy_using_evaluator_innervec_InnerUnrolling<Kernel, 0, DstXprType::InnerSizeAtCompileTime, - Traits::SrcAlignment, Traits::DstAlignment>::run(kernel, outer); - } -}; - -/*********************** -*** Linear traversal *** -***********************/ - -template<typename Kernel> -struct dense_assignment_loop<Kernel, LinearTraversal, NoUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - const Index size = kernel.size(); - for(Index i = 0; i < size; ++i) - kernel.assignCoeff(i); - } -}; - -template<typename Kernel> -struct dense_assignment_loop<Kernel, LinearTraversal, CompleteUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - typedef typename Kernel::DstEvaluatorType::XprType DstXprType; - copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel); - } -}; - -/************************** -*** Slice vectorization *** -***************************/ - -template<typename Kernel> -struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, NoUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - typedef typename Kernel::Scalar Scalar; - typedef typename Kernel::PacketType PacketType; - enum { - packetSize = unpacket_traits<PacketType>::size, - requestedAlignment = int(Kernel::AssignmentTraits::InnerRequiredAlignment), - alignable = packet_traits<Scalar>::AlignedOnScalar || int(Kernel::AssignmentTraits::DstAlignment)>=sizeof(Scalar), - dstIsAligned = int(Kernel::AssignmentTraits::DstAlignment)>=int(requestedAlignment), - dstAlignment = alignable ? int(requestedAlignment) - : int(Kernel::AssignmentTraits::DstAlignment) - }; - const Scalar *dst_ptr = kernel.dstDataPtr(); - if((!bool(dstIsAligned)) && (UIntPtr(dst_ptr) % sizeof(Scalar))>0) - { - // the pointer is not aligned-on scalar, so alignment is not possible - return dense_assignment_loop<Kernel,DefaultTraversal,NoUnrolling>::run(kernel); - } - const Index packetAlignedMask = packetSize - 1; - const Index innerSize = kernel.innerSize(); - const Index outerSize = kernel.outerSize(); - const Index alignedStep = alignable ? (packetSize - kernel.outerStride() % packetSize) & packetAlignedMask : 0; - Index alignedStart = ((!alignable) || bool(dstIsAligned)) ? 0 : internal::first_aligned<requestedAlignment>(dst_ptr, innerSize); - - for(Index outer = 0; outer < outerSize; ++outer) - { - const Index alignedEnd = alignedStart + ((innerSize-alignedStart) & ~packetAlignedMask); - // do the non-vectorizable part of the assignment - for(Index inner = 0; inner<alignedStart ; ++inner) - kernel.assignCoeffByOuterInner(outer, inner); - - // do the vectorizable part of the assignment - for(Index inner = alignedStart; inner<alignedEnd; inner+=packetSize) - kernel.template assignPacketByOuterInner<dstAlignment, Unaligned, PacketType>(outer, inner); - - // do the non-vectorizable part of the assignment - for(Index inner = alignedEnd; inner<innerSize ; ++inner) - kernel.assignCoeffByOuterInner(outer, inner); - - alignedStart = numext::mini((alignedStart+alignedStep)%packetSize, innerSize); - } - } -}; - -#if EIGEN_UNALIGNED_VECTORIZE -template<typename Kernel> -struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, InnerUnrolling> -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) - { - typedef typename Kernel::DstEvaluatorType::XprType DstXprType; - typedef typename Kernel::PacketType PacketType; - - enum { size = DstXprType::InnerSizeAtCompileTime, - packetSize =unpacket_traits<PacketType>::size, - vectorizableSize = (size/packetSize)*packetSize }; - - for(Index outer = 0; outer < kernel.outerSize(); ++outer) - { - copy_using_evaluator_innervec_InnerUnrolling<Kernel, 0, vectorizableSize, 0, 0>::run(kernel, outer); - copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, vectorizableSize, size>::run(kernel, outer); - } - } -}; -#endif - - -/*************************************************************************** -* Part 4 : Generic dense assignment kernel -***************************************************************************/ - -// This class generalize the assignment of a coefficient (or packet) from one dense evaluator -// to another dense writable evaluator. -// It is parametrized by the two evaluators, and the actual assignment functor. -// This abstraction level permits to keep the evaluation loops as simple and as generic as possible. -// One can customize the assignment using this generic dense_assignment_kernel with different -// functors, or by completely overloading it, by-passing a functor. -template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version = Specialized> -class generic_dense_assignment_kernel -{ -protected: - typedef typename DstEvaluatorTypeT::XprType DstXprType; - typedef typename SrcEvaluatorTypeT::XprType SrcXprType; -public: - - typedef DstEvaluatorTypeT DstEvaluatorType; - typedef SrcEvaluatorTypeT SrcEvaluatorType; - typedef typename DstEvaluatorType::Scalar Scalar; - typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor> AssignmentTraits; - typedef typename AssignmentTraits::PacketType PacketType; - - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - generic_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr) - : m_dst(dst), m_src(src), m_functor(func), m_dstExpr(dstExpr) - { - #ifdef EIGEN_DEBUG_ASSIGN - AssignmentTraits::debug(); - #endif - } - - EIGEN_DEVICE_FUNC Index size() const { return m_dstExpr.size(); } - EIGEN_DEVICE_FUNC Index innerSize() const { return m_dstExpr.innerSize(); } - EIGEN_DEVICE_FUNC Index outerSize() const { return m_dstExpr.outerSize(); } - EIGEN_DEVICE_FUNC Index rows() const { return m_dstExpr.rows(); } - EIGEN_DEVICE_FUNC Index cols() const { return m_dstExpr.cols(); } - EIGEN_DEVICE_FUNC Index outerStride() const { return m_dstExpr.outerStride(); } - - EIGEN_DEVICE_FUNC DstEvaluatorType& dstEvaluator() { return m_dst; } - EIGEN_DEVICE_FUNC const SrcEvaluatorType& srcEvaluator() const { return m_src; } - - /// Assign src(row,col) to dst(row,col) through the assignment functor. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col) - { - m_functor.assignCoeff(m_dst.coeffRef(row,col), m_src.coeff(row,col)); - } - - /// \sa assignCoeff(Index,Index) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index index) - { - m_functor.assignCoeff(m_dst.coeffRef(index), m_src.coeff(index)); - } - - /// \sa assignCoeff(Index,Index) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeffByOuterInner(Index outer, Index inner) - { - Index row = rowIndexByOuterInner(outer, inner); - Index col = colIndexByOuterInner(outer, inner); - assignCoeff(row, col); - } - - - template<int StoreMode, int LoadMode, typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index row, Index col) - { - m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(row,col), m_src.template packet<LoadMode,PacketType>(row,col)); - } - - template<int StoreMode, int LoadMode, typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index index) - { - m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(index), m_src.template packet<LoadMode,PacketType>(index)); - } - - template<int StoreMode, int LoadMode, typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner) - { - Index row = rowIndexByOuterInner(outer, inner); - Index col = colIndexByOuterInner(outer, inner); - assignPacket<StoreMode,LoadMode,PacketType>(row, col); - } - - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) - { - typedef typename DstEvaluatorType::ExpressionTraits Traits; - return int(Traits::RowsAtCompileTime) == 1 ? 0 - : int(Traits::ColsAtCompileTime) == 1 ? inner - : int(DstEvaluatorType::Flags)&RowMajorBit ? outer - : inner; - } - - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) - { - typedef typename DstEvaluatorType::ExpressionTraits Traits; - return int(Traits::ColsAtCompileTime) == 1 ? 0 - : int(Traits::RowsAtCompileTime) == 1 ? inner - : int(DstEvaluatorType::Flags)&RowMajorBit ? inner - : outer; - } - - EIGEN_DEVICE_FUNC const Scalar* dstDataPtr() const - { - return m_dstExpr.data(); - } - -protected: - DstEvaluatorType& m_dst; - const SrcEvaluatorType& m_src; - const Functor &m_functor; - // TODO find a way to avoid the needs of the original expression - DstXprType& m_dstExpr; -}; - -// Special kernel used when computing small products whose operands have dynamic dimensions. It ensures that the -// PacketSize used is no larger than 4, thereby increasing the chance that vectorized instructions will be used -// when computing the product. - -template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor> -class restricted_packet_dense_assignment_kernel : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn> -{ -protected: - typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn> Base; - public: - typedef typename Base::Scalar Scalar; - typedef typename Base::DstXprType DstXprType; - typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, 4> AssignmentTraits; - typedef typename AssignmentTraits::PacketType PacketType; - - EIGEN_DEVICE_FUNC restricted_packet_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType& dstExpr) - : Base(dst, src, func, dstExpr) - { - } - }; - -/*************************************************************************** -* Part 5 : Entry point for dense rectangular assignment -***************************************************************************/ - -template<typename DstXprType,typename SrcXprType, typename Functor> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void resize_if_allowed(DstXprType &dst, const SrcXprType& src, const Functor &/*func*/) -{ - EIGEN_ONLY_USED_FOR_DEBUG(dst); - EIGEN_ONLY_USED_FOR_DEBUG(src); - eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); -} - -template<typename DstXprType,typename SrcXprType, typename T1, typename T2> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void resize_if_allowed(DstXprType &dst, const SrcXprType& src, const internal::assign_op<T1,T2> &/*func*/) -{ - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if(((dst.rows()!=dstRows) || (dst.cols()!=dstCols))) - dst.resize(dstRows, dstCols); - eigen_assert(dst.rows() == dstRows && dst.cols() == dstCols); -} - -template<typename DstXprType, typename SrcXprType, typename Functor> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src, const Functor &func) -{ - typedef evaluator<DstXprType> DstEvaluatorType; - typedef evaluator<SrcXprType> SrcEvaluatorType; - - SrcEvaluatorType srcEvaluator(src); - - // NOTE To properly handle A = (A*A.transpose())/s with A rectangular, - // we need to resize the destination after the source evaluator has been created. - resize_if_allowed(dst, src, func); - - DstEvaluatorType dstEvaluator(dst); - - typedef generic_dense_assignment_kernel<DstEvaluatorType,SrcEvaluatorType,Functor> Kernel; - Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived()); - - dense_assignment_loop<Kernel>::run(kernel); -} - -template<typename DstXprType, typename SrcXprType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src) -{ - call_dense_assignment_loop(dst, src, internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>()); -} - -/*************************************************************************** -* Part 6 : Generic assignment -***************************************************************************/ - -// Based on the respective shapes of the destination and source, -// the class AssignmentKind determine the kind of assignment mechanism. -// AssignmentKind must define a Kind typedef. -template<typename DstShape, typename SrcShape> struct AssignmentKind; - -// Assignment kind defined in this file: -struct Dense2Dense {}; -struct EigenBase2EigenBase {}; - -template<typename,typename> struct AssignmentKind { typedef EigenBase2EigenBase Kind; }; -template<> struct AssignmentKind<DenseShape,DenseShape> { typedef Dense2Dense Kind; }; - -// This is the main assignment class -template< typename DstXprType, typename SrcXprType, typename Functor, - typename Kind = typename AssignmentKind< typename evaluator_traits<DstXprType>::Shape , typename evaluator_traits<SrcXprType>::Shape >::Kind, - typename EnableIf = void> -struct Assignment; - - -// The only purpose of this call_assignment() function is to deal with noalias() / "assume-aliasing" and automatic transposition. -// Indeed, I (Gael) think that this concept of "assume-aliasing" was a mistake, and it makes thing quite complicated. -// So this intermediate function removes everything related to "assume-aliasing" such that Assignment -// does not has to bother about these annoying details. - -template<typename Dst, typename Src> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment(Dst& dst, const Src& src) -{ - call_assignment(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>()); -} -template<typename Dst, typename Src> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment(const Dst& dst, const Src& src) -{ - call_assignment(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>()); -} - -// Deal with "assume-aliasing" -template<typename Dst, typename Src, typename Func> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment(Dst& dst, const Src& src, const Func& func, typename enable_if< evaluator_assume_aliasing<Src>::value, void*>::type = 0) -{ - typename plain_matrix_type<Src>::type tmp(src); - call_assignment_no_alias(dst, tmp, func); -} - -template<typename Dst, typename Src, typename Func> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment(Dst& dst, const Src& src, const Func& func, typename enable_if<!evaluator_assume_aliasing<Src>::value, void*>::type = 0) -{ - call_assignment_no_alias(dst, src, func); -} - -// by-pass "assume-aliasing" -// When there is no aliasing, we require that 'dst' has been properly resized -template<typename Dst, template <typename> class StorageBase, typename Src, typename Func> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment(NoAlias<Dst,StorageBase>& dst, const Src& src, const Func& func) -{ - call_assignment_no_alias(dst.expression(), src, func); -} - - -template<typename Dst, typename Src, typename Func> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment_no_alias(Dst& dst, const Src& src, const Func& func) -{ - enum { - NeedToTranspose = ( (int(Dst::RowsAtCompileTime) == 1 && int(Src::ColsAtCompileTime) == 1) - || (int(Dst::ColsAtCompileTime) == 1 && int(Src::RowsAtCompileTime) == 1) - ) && int(Dst::SizeAtCompileTime) != 1 - }; - - typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst>::type ActualDstTypeCleaned; - typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst&>::type ActualDstType; - ActualDstType actualDst(dst); - - // TODO check whether this is the right place to perform these checks: - EIGEN_STATIC_ASSERT_LVALUE(Dst) - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned,Src) - EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar); - - Assignment<ActualDstTypeCleaned,Src,Func>::run(actualDst, src, func); -} - -template<typename Dst, typename Src, typename Func> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_restricted_packet_assignment_no_alias(Dst& dst, const Src& src, const Func& func) -{ - typedef evaluator<Dst> DstEvaluatorType; - typedef evaluator<Src> SrcEvaluatorType; - typedef restricted_packet_dense_assignment_kernel<DstEvaluatorType,SrcEvaluatorType,Func> Kernel; - - EIGEN_STATIC_ASSERT_LVALUE(Dst) - EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename Dst::Scalar,typename Src::Scalar); - - SrcEvaluatorType srcEvaluator(src); - resize_if_allowed(dst, src, func); - - DstEvaluatorType dstEvaluator(dst); - Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived()); - - dense_assignment_loop<Kernel>::run(kernel); -} - -template<typename Dst, typename Src> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment_no_alias(Dst& dst, const Src& src) -{ - call_assignment_no_alias(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>()); -} - -template<typename Dst, typename Src, typename Func> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src, const Func& func) -{ - // TODO check whether this is the right place to perform these checks: - EIGEN_STATIC_ASSERT_LVALUE(Dst) - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Dst,Src) - EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename Dst::Scalar,typename Src::Scalar); - - Assignment<Dst,Src,Func>::run(dst, src, func); -} -template<typename Dst, typename Src> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src) -{ - call_assignment_no_alias_no_transpose(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>()); -} - -// forward declaration -template<typename Dst, typename Src> void check_for_aliasing(const Dst &dst, const Src &src); - -// Generic Dense to Dense assignment -// Note that the last template argument "Weak" is needed to make it possible to perform -// both partial specialization+SFINAE without ambiguous specialization -template< typename DstXprType, typename SrcXprType, typename Functor, typename Weak> -struct Assignment<DstXprType, SrcXprType, Functor, Dense2Dense, Weak> -{ - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const Functor &func) - { -#ifndef EIGEN_NO_DEBUG - internal::check_for_aliasing(dst, src); -#endif - - call_dense_assignment_loop(dst, src, func); - } -}; - -// Generic assignment through evalTo. -// TODO: not sure we have to keep that one, but it helps porting current code to new evaluator mechanism. -// Note that the last template argument "Weak" is needed to make it possible to perform -// both partial specialization+SFINAE without ambiguous specialization -template< typename DstXprType, typename SrcXprType, typename Functor, typename Weak> -struct Assignment<DstXprType, SrcXprType, Functor, EigenBase2EigenBase, Weak> -{ - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); - src.evalTo(dst); - } - - // NOTE The following two functions are templated to avoid their instantiation if not needed - // This is needed because some expressions supports evalTo only and/or have 'void' as scalar type. - template<typename SrcScalarType> - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,SrcScalarType> &/*func*/) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); - src.addTo(dst); - } - - template<typename SrcScalarType> - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,SrcScalarType> &/*func*/) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); - src.subTo(dst); - } -}; - -} // namespace internal - -} // end namespace Eigen - -#endif // EIGEN_ASSIGN_EVALUATOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Assign_MKL.h b/external/eigen/include/eigen3/Eigen/src/Core/Assign_MKL.h deleted file mode 100644 index c6140d18..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Assign_MKL.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr> - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to Intel(R) MKL - * MKL VML support for coefficient-wise unary Eigen expressions like a=b.sin() - ******************************************************************************** -*/ - -#ifndef EIGEN_ASSIGN_VML_H -#define EIGEN_ASSIGN_VML_H - -namespace Eigen { - -namespace internal { - -template<typename Dst, typename Src> -class vml_assign_traits -{ - private: - enum { - DstHasDirectAccess = Dst::Flags & DirectAccessBit, - SrcHasDirectAccess = Src::Flags & DirectAccessBit, - StorageOrdersAgree = (int(Dst::IsRowMajor) == int(Src::IsRowMajor)), - InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime) - : int(Dst::Flags)&RowMajorBit ? int(Dst::ColsAtCompileTime) - : int(Dst::RowsAtCompileTime), - InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime) - : int(Dst::Flags)&RowMajorBit ? int(Dst::MaxColsAtCompileTime) - : int(Dst::MaxRowsAtCompileTime), - MaxSizeAtCompileTime = Dst::SizeAtCompileTime, - - MightEnableVml = StorageOrdersAgree && DstHasDirectAccess && SrcHasDirectAccess && Src::InnerStrideAtCompileTime==1 && Dst::InnerStrideAtCompileTime==1, - MightLinearize = MightEnableVml && (int(Dst::Flags) & int(Src::Flags) & LinearAccessBit), - VmlSize = MightLinearize ? MaxSizeAtCompileTime : InnerMaxSize, - LargeEnough = VmlSize==Dynamic || VmlSize>=EIGEN_MKL_VML_THRESHOLD - }; - public: - enum { - EnableVml = MightEnableVml && LargeEnough, - Traversal = MightLinearize ? LinearTraversal : DefaultTraversal - }; -}; - -#define EIGEN_PP_EXPAND(ARG) ARG -#if !defined (EIGEN_FAST_MATH) || (EIGEN_FAST_MATH != 1) -#define EIGEN_VMLMODE_EXPAND_xLA , VML_HA -#else -#define EIGEN_VMLMODE_EXPAND_xLA , VML_LA -#endif - -#define EIGEN_VMLMODE_EXPAND_x_ - -#define EIGEN_VMLMODE_PREFIX_xLA vm -#define EIGEN_VMLMODE_PREFIX_x_ v -#define EIGEN_VMLMODE_PREFIX(VMLMODE) EIGEN_CAT(EIGEN_VMLMODE_PREFIX_x,VMLMODE) - -#define EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \ - template< typename DstXprType, typename SrcXprNested> \ - struct Assignment<DstXprType, CwiseUnaryOp<scalar_##EIGENOP##_op<EIGENTYPE>, SrcXprNested>, assign_op<EIGENTYPE,EIGENTYPE>, \ - Dense2Dense, typename enable_if<vml_assign_traits<DstXprType,SrcXprNested>::EnableVml>::type> { \ - typedef CwiseUnaryOp<scalar_##EIGENOP##_op<EIGENTYPE>, SrcXprNested> SrcXprType; \ - static void run(DstXprType &dst, const SrcXprType &src, const assign_op<EIGENTYPE,EIGENTYPE> &func) { \ - resize_if_allowed(dst, src, func); \ - eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \ - if(vml_assign_traits<DstXprType,SrcXprNested>::Traversal==LinearTraversal) { \ - VMLOP(dst.size(), (const VMLTYPE*)src.nestedExpression().data(), \ - (VMLTYPE*)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE) ); \ - } else { \ - const Index outerSize = dst.outerSize(); \ - for(Index outer = 0; outer < outerSize; ++outer) { \ - const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.nestedExpression().coeffRef(outer,0)) : \ - &(src.nestedExpression().coeffRef(0, outer)); \ - EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer,0)) : &(dst.coeffRef(0, outer)); \ - VMLOP( dst.innerSize(), (const VMLTYPE*)src_ptr, \ - (VMLTYPE*)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \ - } \ - } \ - } \ - }; \ - - -#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \ - EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),s##VMLOP), float, float, VMLMODE) \ - EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),d##VMLOP), double, double, VMLMODE) - -#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE) \ - EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),c##VMLOP), scomplex, MKL_Complex8, VMLMODE) \ - EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),z##VMLOP), dcomplex, MKL_Complex16, VMLMODE) - -#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS(EIGENOP, VMLOP, VMLMODE) \ - EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \ - EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE) - - -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sin, Sin, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(asin, Asin, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sinh, Sinh, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(cos, Cos, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(acos, Acos, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(cosh, Cosh, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(tan, Tan, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(atan, Atan, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(tanh, Tanh, LA) -// EIGEN_MKL_VML_DECLARE_UNARY_CALLS(abs, Abs, _) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(exp, Exp, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(log, Ln, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(log10, Log10, LA) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sqrt, Sqrt, _) - -EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(square, Sqr, _) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(arg, Arg, _) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(round, Round, _) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(floor, Floor, _) -EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(ceil, Ceil, _) - -#define EIGEN_MKL_VML_DECLARE_POW_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \ - template< typename DstXprType, typename SrcXprNested, typename Plain> \ - struct Assignment<DstXprType, CwiseBinaryOp<scalar_##EIGENOP##_op<EIGENTYPE,EIGENTYPE>, SrcXprNested, \ - const CwiseNullaryOp<internal::scalar_constant_op<EIGENTYPE>,Plain> >, assign_op<EIGENTYPE,EIGENTYPE>, \ - Dense2Dense, typename enable_if<vml_assign_traits<DstXprType,SrcXprNested>::EnableVml>::type> { \ - typedef CwiseBinaryOp<scalar_##EIGENOP##_op<EIGENTYPE,EIGENTYPE>, SrcXprNested, \ - const CwiseNullaryOp<internal::scalar_constant_op<EIGENTYPE>,Plain> > SrcXprType; \ - static void run(DstXprType &dst, const SrcXprType &src, const assign_op<EIGENTYPE,EIGENTYPE> &func) { \ - resize_if_allowed(dst, src, func); \ - eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \ - VMLTYPE exponent = reinterpret_cast<const VMLTYPE&>(src.rhs().functor().m_other); \ - if(vml_assign_traits<DstXprType,SrcXprNested>::Traversal==LinearTraversal) \ - { \ - VMLOP( dst.size(), (const VMLTYPE*)src.lhs().data(), exponent, \ - (VMLTYPE*)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE) ); \ - } else { \ - const Index outerSize = dst.outerSize(); \ - for(Index outer = 0; outer < outerSize; ++outer) { \ - const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.lhs().coeffRef(outer,0)) : \ - &(src.lhs().coeffRef(0, outer)); \ - EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer,0)) : &(dst.coeffRef(0, outer)); \ - VMLOP( dst.innerSize(), (const VMLTYPE*)src_ptr, exponent, \ - (VMLTYPE*)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \ - } \ - } \ - } \ - }; - -EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmsPowx, float, float, LA) -EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmdPowx, double, double, LA) -EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmcPowx, scomplex, MKL_Complex8, LA) -EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmzPowx, dcomplex, MKL_Complex16, LA) - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_ASSIGN_VML_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/BandMatrix.h b/external/eigen/include/eigen3/Eigen/src/Core/BandMatrix.h deleted file mode 100644 index 4978c914..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/BandMatrix.h +++ /dev/null @@ -1,353 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BANDMATRIX_H -#define EIGEN_BANDMATRIX_H - -namespace Eigen { - -namespace internal { - -template<typename Derived> -class BandMatrixBase : public EigenBase<Derived> -{ - public: - - enum { - Flags = internal::traits<Derived>::Flags, - CoeffReadCost = internal::traits<Derived>::CoeffReadCost, - RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, - ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, - MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime, - MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime, - Supers = internal::traits<Derived>::Supers, - Subs = internal::traits<Derived>::Subs, - Options = internal::traits<Derived>::Options - }; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> DenseMatrixType; - typedef typename DenseMatrixType::StorageIndex StorageIndex; - typedef typename internal::traits<Derived>::CoefficientsType CoefficientsType; - typedef EigenBase<Derived> Base; - - protected: - enum { - DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) - ? 1 + Supers + Subs - : Dynamic, - SizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime) - }; - - public: - - using Base::derived; - using Base::rows; - using Base::cols; - - /** \returns the number of super diagonals */ - inline Index supers() const { return derived().supers(); } - - /** \returns the number of sub diagonals */ - inline Index subs() const { return derived().subs(); } - - /** \returns an expression of the underlying coefficient matrix */ - inline const CoefficientsType& coeffs() const { return derived().coeffs(); } - - /** \returns an expression of the underlying coefficient matrix */ - inline CoefficientsType& coeffs() { return derived().coeffs(); } - - /** \returns a vector expression of the \a i -th column, - * only the meaningful part is returned. - * \warning the internal storage must be column major. */ - inline Block<CoefficientsType,Dynamic,1> col(Index i) - { - EIGEN_STATIC_ASSERT((Options&RowMajor)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); - Index start = 0; - Index len = coeffs().rows(); - if (i<=supers()) - { - start = supers()-i; - len = (std::min)(rows(),std::max<Index>(0,coeffs().rows() - (supers()-i))); - } - else if (i>=rows()-subs()) - len = std::max<Index>(0,coeffs().rows() - (i + 1 - rows() + subs())); - return Block<CoefficientsType,Dynamic,1>(coeffs(), start, i, len, 1); - } - - /** \returns a vector expression of the main diagonal */ - inline Block<CoefficientsType,1,SizeAtCompileTime> diagonal() - { return Block<CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(std::min)(rows(),cols())); } - - /** \returns a vector expression of the main diagonal (const version) */ - inline const Block<const CoefficientsType,1,SizeAtCompileTime> diagonal() const - { return Block<const CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(std::min)(rows(),cols())); } - - template<int Index> struct DiagonalIntReturnType { - enum { - ReturnOpposite = (Options&SelfAdjoint) && (((Index)>0 && Supers==0) || ((Index)<0 && Subs==0)), - Conjugate = ReturnOpposite && NumTraits<Scalar>::IsComplex, - ActualIndex = ReturnOpposite ? -Index : Index, - DiagonalSize = (RowsAtCompileTime==Dynamic || ColsAtCompileTime==Dynamic) - ? Dynamic - : (ActualIndex<0 - ? EIGEN_SIZE_MIN_PREFER_DYNAMIC(ColsAtCompileTime, RowsAtCompileTime + ActualIndex) - : EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime, ColsAtCompileTime - ActualIndex)) - }; - typedef Block<CoefficientsType,1, DiagonalSize> BuildType; - typedef typename internal::conditional<Conjugate, - CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>,BuildType >, - BuildType>::type Type; - }; - - /** \returns a vector expression of the \a N -th sub or super diagonal */ - template<int N> inline typename DiagonalIntReturnType<N>::Type diagonal() - { - return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (std::max)(0,N), 1, diagonalLength(N)); - } - - /** \returns a vector expression of the \a N -th sub or super diagonal */ - template<int N> inline const typename DiagonalIntReturnType<N>::Type diagonal() const - { - return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (std::max)(0,N), 1, diagonalLength(N)); - } - - /** \returns a vector expression of the \a i -th sub or super diagonal */ - inline Block<CoefficientsType,1,Dynamic> diagonal(Index i) - { - eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers())); - return Block<CoefficientsType,1,Dynamic>(coeffs(), supers()-i, std::max<Index>(0,i), 1, diagonalLength(i)); - } - - /** \returns a vector expression of the \a i -th sub or super diagonal */ - inline const Block<const CoefficientsType,1,Dynamic> diagonal(Index i) const - { - eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers())); - return Block<const CoefficientsType,1,Dynamic>(coeffs(), supers()-i, std::max<Index>(0,i), 1, diagonalLength(i)); - } - - template<typename Dest> inline void evalTo(Dest& dst) const - { - dst.resize(rows(),cols()); - dst.setZero(); - dst.diagonal() = diagonal(); - for (Index i=1; i<=supers();++i) - dst.diagonal(i) = diagonal(i); - for (Index i=1; i<=subs();++i) - dst.diagonal(-i) = diagonal(-i); - } - - DenseMatrixType toDenseMatrix() const - { - DenseMatrixType res(rows(),cols()); - evalTo(res); - return res; - } - - protected: - - inline Index diagonalLength(Index i) const - { return i<0 ? (std::min)(cols(),rows()+i) : (std::min)(rows(),cols()-i); } -}; - -/** - * \class BandMatrix - * \ingroup Core_Module - * - * \brief Represents a rectangular matrix with a banded storage - * - * \tparam _Scalar Numeric type, i.e. float, double, int - * \tparam _Rows Number of rows, or \b Dynamic - * \tparam _Cols Number of columns, or \b Dynamic - * \tparam _Supers Number of super diagonal - * \tparam _Subs Number of sub diagonal - * \tparam _Options A combination of either \b #RowMajor or \b #ColMajor, and of \b #SelfAdjoint - * The former controls \ref TopicStorageOrders "storage order", and defaults to - * column-major. The latter controls whether the matrix represents a selfadjoint - * matrix in which case either Supers of Subs have to be null. - * - * \sa class TridiagonalMatrix - */ - -template<typename _Scalar, int _Rows, int _Cols, int _Supers, int _Subs, int _Options> -struct traits<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> > -{ - typedef _Scalar Scalar; - typedef Dense StorageKind; - typedef Eigen::Index StorageIndex; - enum { - CoeffReadCost = NumTraits<Scalar>::ReadCost, - RowsAtCompileTime = _Rows, - ColsAtCompileTime = _Cols, - MaxRowsAtCompileTime = _Rows, - MaxColsAtCompileTime = _Cols, - Flags = LvalueBit, - Supers = _Supers, - Subs = _Subs, - Options = _Options, - DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) ? 1 + Supers + Subs : Dynamic - }; - typedef Matrix<Scalar,DataRowsAtCompileTime,ColsAtCompileTime,Options&RowMajor?RowMajor:ColMajor> CoefficientsType; -}; - -template<typename _Scalar, int Rows, int Cols, int Supers, int Subs, int Options> -class BandMatrix : public BandMatrixBase<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Options> > -{ - public: - - typedef typename internal::traits<BandMatrix>::Scalar Scalar; - typedef typename internal::traits<BandMatrix>::StorageIndex StorageIndex; - typedef typename internal::traits<BandMatrix>::CoefficientsType CoefficientsType; - - explicit inline BandMatrix(Index rows=Rows, Index cols=Cols, Index supers=Supers, Index subs=Subs) - : m_coeffs(1+supers+subs,cols), - m_rows(rows), m_supers(supers), m_subs(subs) - { - } - - /** \returns the number of columns */ - inline Index rows() const { return m_rows.value(); } - - /** \returns the number of rows */ - inline Index cols() const { return m_coeffs.cols(); } - - /** \returns the number of super diagonals */ - inline Index supers() const { return m_supers.value(); } - - /** \returns the number of sub diagonals */ - inline Index subs() const { return m_subs.value(); } - - inline const CoefficientsType& coeffs() const { return m_coeffs; } - inline CoefficientsType& coeffs() { return m_coeffs; } - - protected: - - CoefficientsType m_coeffs; - internal::variable_if_dynamic<Index, Rows> m_rows; - internal::variable_if_dynamic<Index, Supers> m_supers; - internal::variable_if_dynamic<Index, Subs> m_subs; -}; - -template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options> -class BandMatrixWrapper; - -template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options> -struct traits<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> > -{ - typedef typename _CoefficientsType::Scalar Scalar; - typedef typename _CoefficientsType::StorageKind StorageKind; - typedef typename _CoefficientsType::StorageIndex StorageIndex; - enum { - CoeffReadCost = internal::traits<_CoefficientsType>::CoeffReadCost, - RowsAtCompileTime = _Rows, - ColsAtCompileTime = _Cols, - MaxRowsAtCompileTime = _Rows, - MaxColsAtCompileTime = _Cols, - Flags = LvalueBit, - Supers = _Supers, - Subs = _Subs, - Options = _Options, - DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) ? 1 + Supers + Subs : Dynamic - }; - typedef _CoefficientsType CoefficientsType; -}; - -template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options> -class BandMatrixWrapper : public BandMatrixBase<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> > -{ - public: - - typedef typename internal::traits<BandMatrixWrapper>::Scalar Scalar; - typedef typename internal::traits<BandMatrixWrapper>::CoefficientsType CoefficientsType; - typedef typename internal::traits<BandMatrixWrapper>::StorageIndex StorageIndex; - - explicit inline BandMatrixWrapper(const CoefficientsType& coeffs, Index rows=_Rows, Index cols=_Cols, Index supers=_Supers, Index subs=_Subs) - : m_coeffs(coeffs), - m_rows(rows), m_supers(supers), m_subs(subs) - { - EIGEN_UNUSED_VARIABLE(cols); - //internal::assert(coeffs.cols()==cols() && (supers()+subs()+1)==coeffs.rows()); - } - - /** \returns the number of columns */ - inline Index rows() const { return m_rows.value(); } - - /** \returns the number of rows */ - inline Index cols() const { return m_coeffs.cols(); } - - /** \returns the number of super diagonals */ - inline Index supers() const { return m_supers.value(); } - - /** \returns the number of sub diagonals */ - inline Index subs() const { return m_subs.value(); } - - inline const CoefficientsType& coeffs() const { return m_coeffs; } - - protected: - - const CoefficientsType& m_coeffs; - internal::variable_if_dynamic<Index, _Rows> m_rows; - internal::variable_if_dynamic<Index, _Supers> m_supers; - internal::variable_if_dynamic<Index, _Subs> m_subs; -}; - -/** - * \class TridiagonalMatrix - * \ingroup Core_Module - * - * \brief Represents a tridiagonal matrix with a compact banded storage - * - * \tparam Scalar Numeric type, i.e. float, double, int - * \tparam Size Number of rows and cols, or \b Dynamic - * \tparam Options Can be 0 or \b SelfAdjoint - * - * \sa class BandMatrix - */ -template<typename Scalar, int Size, int Options> -class TridiagonalMatrix : public BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor> -{ - typedef BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor> Base; - typedef typename Base::StorageIndex StorageIndex; - public: - explicit TridiagonalMatrix(Index size = Size) : Base(size,size,Options&SelfAdjoint?0:1,1) {} - - inline typename Base::template DiagonalIntReturnType<1>::Type super() - { return Base::template diagonal<1>(); } - inline const typename Base::template DiagonalIntReturnType<1>::Type super() const - { return Base::template diagonal<1>(); } - inline typename Base::template DiagonalIntReturnType<-1>::Type sub() - { return Base::template diagonal<-1>(); } - inline const typename Base::template DiagonalIntReturnType<-1>::Type sub() const - { return Base::template diagonal<-1>(); } - protected: -}; - - -struct BandShape {}; - -template<typename _Scalar, int _Rows, int _Cols, int _Supers, int _Subs, int _Options> -struct evaluator_traits<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> > - : public evaluator_traits_base<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> > -{ - typedef BandShape Shape; -}; - -template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options> -struct evaluator_traits<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> > - : public evaluator_traits_base<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> > -{ - typedef BandShape Shape; -}; - -template<> struct AssignmentKind<DenseShape,BandShape> { typedef EigenBase2EigenBase Kind; }; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_BANDMATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Block.h b/external/eigen/include/eigen3/Eigen/src/Core/Block.h deleted file mode 100644 index 6e938ea5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Block.h +++ /dev/null @@ -1,452 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BLOCK_H -#define EIGEN_BLOCK_H - -namespace Eigen { - -namespace internal { -template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> -struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel> > : traits<XprType> -{ - typedef typename traits<XprType>::Scalar Scalar; - typedef typename traits<XprType>::StorageKind StorageKind; - typedef typename traits<XprType>::XprKind XprKind; - typedef typename ref_selector<XprType>::type XprTypeNested; - typedef typename remove_reference<XprTypeNested>::type _XprTypeNested; - enum{ - MatrixRows = traits<XprType>::RowsAtCompileTime, - MatrixCols = traits<XprType>::ColsAtCompileTime, - RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows, - ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols, - MaxRowsAtCompileTime = BlockRows==0 ? 0 - : RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) - : int(traits<XprType>::MaxRowsAtCompileTime), - MaxColsAtCompileTime = BlockCols==0 ? 0 - : ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) - : int(traits<XprType>::MaxColsAtCompileTime), - - XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0, - IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1 - : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0 - : XprTypeIsRowMajor, - HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor), - InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime), - InnerStrideAtCompileTime = HasSameStorageOrderAsXprType - ? int(inner_stride_at_compile_time<XprType>::ret) - : int(outer_stride_at_compile_time<XprType>::ret), - OuterStrideAtCompileTime = HasSameStorageOrderAsXprType - ? int(outer_stride_at_compile_time<XprType>::ret) - : int(inner_stride_at_compile_time<XprType>::ret), - - // FIXME, this traits is rather specialized for dense object and it needs to be cleaned further - FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0, - FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, - Flags = (traits<XprType>::Flags & (DirectAccessBit | (InnerPanel?CompressedAccessBit:0))) | FlagsLvalueBit | FlagsRowMajorBit, - // FIXME DirectAccessBit should not be handled by expressions - // - // Alignment is needed by MapBase's assertions - // We can sefely set it to false here. Internal alignment errors will be detected by an eigen_internal_assert in the respective evaluator - Alignment = 0 - }; -}; - -template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false, - bool HasDirectAccess = internal::has_direct_access<XprType>::ret> class BlockImpl_dense; - -} // end namespace internal - -template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, typename StorageKind> class BlockImpl; - -/** \class Block - * \ingroup Core_Module - * - * \brief Expression of a fixed-size or dynamic-size block - * - * \tparam XprType the type of the expression in which we are taking a block - * \tparam BlockRows the number of rows of the block we are taking at compile time (optional) - * \tparam BlockCols the number of columns of the block we are taking at compile time (optional) - * \tparam InnerPanel is true, if the block maps to a set of rows of a row major matrix or - * to set of columns of a column major matrix (optional). The parameter allows to determine - * at compile time whether aligned access is possible on the block expression. - * - * This class represents an expression of either a fixed-size or dynamic-size block. It is the return - * type of DenseBase::block(Index,Index,Index,Index) and DenseBase::block<int,int>(Index,Index) and - * most of the time this is the only way it is used. - * - * However, if you want to directly maniputate block expressions, - * for instance if you want to write a function returning such an expression, you - * will need to use this class. - * - * Here is an example illustrating the dynamic case: - * \include class_Block.cpp - * Output: \verbinclude class_Block.out - * - * \note Even though this expression has dynamic size, in the case where \a XprType - * has fixed size, this expression inherits a fixed maximal size which means that evaluating - * it does not cause a dynamic memory allocation. - * - * Here is an example illustrating the fixed-size case: - * \include class_FixedBlock.cpp - * Output: \verbinclude class_FixedBlock.out - * - * \sa DenseBase::block(Index,Index,Index,Index), DenseBase::block(Index,Index), class VectorBlock - */ -template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> class Block - : public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> -{ - typedef BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Impl; - public: - //typedef typename Impl::Base Base; - typedef Impl Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(Block) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) - - typedef typename internal::remove_all<XprType>::type NestedExpression; - - /** Column or Row constructor - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Block(XprType& xpr, Index i) : Impl(xpr,i) - { - eigen_assert( (i>=0) && ( - ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows()) - ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols()))); - } - - /** Fixed-size constructor - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Block(XprType& xpr, Index startRow, Index startCol) - : Impl(xpr, startRow, startCol) - { - EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE) - eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows() - && startCol >= 0 && BlockCols >= 0 && startCol + BlockCols <= xpr.cols()); - } - - /** Dynamic-size constructor - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Block(XprType& xpr, - Index startRow, Index startCol, - Index blockRows, Index blockCols) - : Impl(xpr, startRow, startCol, blockRows, blockCols) - { - eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows) - && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols)); - eigen_assert(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows - && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols); - } -}; - -// The generic default implementation for dense block simplu forward to the internal::BlockImpl_dense -// that must be specialized for direct and non-direct access... -template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> -class BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Dense> - : public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel> -{ - typedef internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel> Impl; - typedef typename XprType::StorageIndex StorageIndex; - public: - typedef Impl Base; - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index i) : Impl(xpr,i) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol) : Impl(xpr, startRow, startCol) {} - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols) - : Impl(xpr, startRow, startCol, blockRows, blockCols) {} -}; - -namespace internal { - -/** \internal Internal implementation of dense Blocks in the general case. */ -template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool HasDirectAccess> class BlockImpl_dense - : public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel> >::type -{ - typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType; - typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested; - public: - - typedef typename internal::dense_xpr_base<BlockType>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(BlockType) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense) - - // class InnerIterator; // FIXME apparently never used - - /** Column or Row constructor - */ - EIGEN_DEVICE_FUNC - inline BlockImpl_dense(XprType& xpr, Index i) - : m_xpr(xpr), - // It is a row if and only if BlockRows==1 and BlockCols==XprType::ColsAtCompileTime, - // and it is a column if and only if BlockRows==XprType::RowsAtCompileTime and BlockCols==1, - // all other cases are invalid. - // The case a 1x1 matrix seems ambiguous, but the result is the same anyway. - m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0), - m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0), - m_blockRows(BlockRows==1 ? 1 : xpr.rows()), - m_blockCols(BlockCols==1 ? 1 : xpr.cols()) - {} - - /** Fixed-size constructor - */ - EIGEN_DEVICE_FUNC - inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol) - : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol), - m_blockRows(BlockRows), m_blockCols(BlockCols) - {} - - /** Dynamic-size constructor - */ - EIGEN_DEVICE_FUNC - inline BlockImpl_dense(XprType& xpr, - Index startRow, Index startCol, - Index blockRows, Index blockCols) - : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol), - m_blockRows(blockRows), m_blockCols(blockCols) - {} - - EIGEN_DEVICE_FUNC inline Index rows() const { return m_blockRows.value(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_blockCols.value(); } - - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index rowId, Index colId) - { - EIGEN_STATIC_ASSERT_LVALUE(XprType) - return m_xpr.coeffRef(rowId + m_startRow.value(), colId + m_startCol.value()); - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index rowId, Index colId) const - { - return m_xpr.derived().coeffRef(rowId + m_startRow.value(), colId + m_startCol.value()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const - { - return m_xpr.coeff(rowId + m_startRow.value(), colId + m_startCol.value()); - } - - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index index) - { - EIGEN_STATIC_ASSERT_LVALUE(XprType) - return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), - m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index index) const - { - return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), - m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); - } - - EIGEN_DEVICE_FUNC - inline const CoeffReturnType coeff(Index index) const - { - return m_xpr.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), - m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); - } - - template<int LoadMode> - inline PacketScalar packet(Index rowId, Index colId) const - { - return m_xpr.template packet<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value()); - } - - template<int LoadMode> - inline void writePacket(Index rowId, Index colId, const PacketScalar& val) - { - m_xpr.template writePacket<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value(), val); - } - - template<int LoadMode> - inline PacketScalar packet(Index index) const - { - return m_xpr.template packet<Unaligned> - (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), - m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); - } - - template<int LoadMode> - inline void writePacket(Index index, const PacketScalar& val) - { - m_xpr.template writePacket<Unaligned> - (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), - m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val); - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** \sa MapBase::data() */ - EIGEN_DEVICE_FUNC inline const Scalar* data() const; - EIGEN_DEVICE_FUNC inline Index innerStride() const; - EIGEN_DEVICE_FUNC inline Index outerStride() const; - #endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const - { - return m_xpr; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - XprType& nestedExpression() { return m_xpr; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - StorageIndex startRow() const - { - return m_startRow.value(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - StorageIndex startCol() const - { - return m_startCol.value(); - } - - protected: - - XprTypeNested m_xpr; - const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow; - const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol; - const internal::variable_if_dynamic<StorageIndex, RowsAtCompileTime> m_blockRows; - const internal::variable_if_dynamic<StorageIndex, ColsAtCompileTime> m_blockCols; -}; - -/** \internal Internal implementation of dense Blocks in the direct access case.*/ -template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> -class BlockImpl_dense<XprType,BlockRows,BlockCols, InnerPanel,true> - : public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel> > -{ - typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType; - typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested; - enum { - XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0 - }; - public: - - typedef MapBase<BlockType> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(BlockType) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense) - - /** Column or Row constructor - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - BlockImpl_dense(XprType& xpr, Index i) - : Base(xpr.data() + i * ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && (!XprTypeIsRowMajor)) - || ((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && ( XprTypeIsRowMajor)) ? xpr.innerStride() : xpr.outerStride()), - BlockRows==1 ? 1 : xpr.rows(), - BlockCols==1 ? 1 : xpr.cols()), - m_xpr(xpr), - m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0), - m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0) - { - init(); - } - - /** Fixed-size constructor - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - BlockImpl_dense(XprType& xpr, Index startRow, Index startCol) - : Base(xpr.data()+xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol)), - m_xpr(xpr), m_startRow(startRow), m_startCol(startCol) - { - init(); - } - - /** Dynamic-size constructor - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - BlockImpl_dense(XprType& xpr, - Index startRow, Index startCol, - Index blockRows, Index blockCols) - : Base(xpr.data()+xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol), blockRows, blockCols), - m_xpr(xpr), m_startRow(startRow), m_startCol(startCol) - { - init(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const - { - return m_xpr; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - XprType& nestedExpression() { return m_xpr; } - - /** \sa MapBase::innerStride() */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index innerStride() const - { - return internal::traits<BlockType>::HasSameStorageOrderAsXprType - ? m_xpr.innerStride() - : m_xpr.outerStride(); - } - - /** \sa MapBase::outerStride() */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index outerStride() const - { - return m_outerStride; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - StorageIndex startRow() const - { - return m_startRow.value(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - StorageIndex startCol() const - { - return m_startCol.value(); - } - - #ifndef __SUNPRO_CC - // FIXME sunstudio is not friendly with the above friend... - // META-FIXME there is no 'friend' keyword around here. Is this obsolete? - protected: - #endif - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal used by allowAligned() */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - BlockImpl_dense(XprType& xpr, const Scalar* data, Index blockRows, Index blockCols) - : Base(data, blockRows, blockCols), m_xpr(xpr) - { - init(); - } - #endif - - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void init() - { - m_outerStride = internal::traits<BlockType>::HasSameStorageOrderAsXprType - ? m_xpr.outerStride() - : m_xpr.innerStride(); - } - - XprTypeNested m_xpr; - const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow; - const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol; - Index m_outerStride; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_BLOCK_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/BooleanRedux.h b/external/eigen/include/eigen3/Eigen/src/Core/BooleanRedux.h deleted file mode 100644 index ccf51906..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/BooleanRedux.h +++ /dev/null @@ -1,162 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ALLANDANY_H -#define EIGEN_ALLANDANY_H - -namespace Eigen { - -namespace internal { - -template<typename Derived, int UnrollCount, int Rows> -struct all_unroller -{ - enum { - col = (UnrollCount-1) / Rows, - row = (UnrollCount-1) % Rows - }; - - static inline bool run(const Derived &mat) - { - return all_unroller<Derived, UnrollCount-1, Rows>::run(mat) && mat.coeff(row, col); - } -}; - -template<typename Derived, int Rows> -struct all_unroller<Derived, 0, Rows> -{ - static inline bool run(const Derived &/*mat*/) { return true; } -}; - -template<typename Derived, int Rows> -struct all_unroller<Derived, Dynamic, Rows> -{ - static inline bool run(const Derived &) { return false; } -}; - -template<typename Derived, int UnrollCount, int Rows> -struct any_unroller -{ - enum { - col = (UnrollCount-1) / Rows, - row = (UnrollCount-1) % Rows - }; - - static inline bool run(const Derived &mat) - { - return any_unroller<Derived, UnrollCount-1, Rows>::run(mat) || mat.coeff(row, col); - } -}; - -template<typename Derived, int Rows> -struct any_unroller<Derived, 0, Rows> -{ - static inline bool run(const Derived & /*mat*/) { return false; } -}; - -template<typename Derived, int Rows> -struct any_unroller<Derived, Dynamic, Rows> -{ - static inline bool run(const Derived &) { return false; } -}; - -} // end namespace internal - -/** \returns true if all coefficients are true - * - * Example: \include MatrixBase_all.cpp - * Output: \verbinclude MatrixBase_all.out - * - * \sa any(), Cwise::operator<() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::all() const -{ - typedef internal::evaluator<Derived> Evaluator; - enum { - unroll = SizeAtCompileTime != Dynamic - && SizeAtCompileTime * (Evaluator::CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT - }; - Evaluator evaluator(derived()); - if(unroll) - return internal::all_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, internal::traits<Derived>::RowsAtCompileTime>::run(evaluator); - else - { - for(Index j = 0; j < cols(); ++j) - for(Index i = 0; i < rows(); ++i) - if (!evaluator.coeff(i, j)) return false; - return true; - } -} - -/** \returns true if at least one coefficient is true - * - * \sa all() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::any() const -{ - typedef internal::evaluator<Derived> Evaluator; - enum { - unroll = SizeAtCompileTime != Dynamic - && SizeAtCompileTime * (Evaluator::CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT - }; - Evaluator evaluator(derived()); - if(unroll) - return internal::any_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, internal::traits<Derived>::RowsAtCompileTime>::run(evaluator); - else - { - for(Index j = 0; j < cols(); ++j) - for(Index i = 0; i < rows(); ++i) - if (evaluator.coeff(i, j)) return true; - return false; - } -} - -/** \returns the number of coefficients which evaluate to true - * - * \sa all(), any() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline Eigen::Index DenseBase<Derived>::count() const -{ - return derived().template cast<bool>().template cast<Index>().sum(); -} - -/** \returns true is \c *this contains at least one Not A Number (NaN). - * - * \sa allFinite() - */ -template<typename Derived> -inline bool DenseBase<Derived>::hasNaN() const -{ -#if EIGEN_COMP_MSVC || (defined __FAST_MATH__) - return derived().array().isNaN().any(); -#else - return !((derived().array()==derived().array()).all()); -#endif -} - -/** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values. - * - * \sa hasNaN() - */ -template<typename Derived> -inline bool DenseBase<Derived>::allFinite() const -{ -#if EIGEN_COMP_MSVC || (defined __FAST_MATH__) - return derived().array().isFinite().all(); -#else - return !((derived()-derived()).hasNaN()); -#endif -} - -} // end namespace Eigen - -#endif // EIGEN_ALLANDANY_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/CommaInitializer.h b/external/eigen/include/eigen3/Eigen/src/Core/CommaInitializer.h deleted file mode 100644 index 35fdbb81..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/CommaInitializer.h +++ /dev/null @@ -1,160 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMMAINITIALIZER_H -#define EIGEN_COMMAINITIALIZER_H - -namespace Eigen { - -/** \class CommaInitializer - * \ingroup Core_Module - * - * \brief Helper class used by the comma initializer operator - * - * This class is internally used to implement the comma initializer feature. It is - * the return type of MatrixBase::operator<<, and most of the time this is the only - * way it is used. - * - * \sa \blank \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished() - */ -template<typename XprType> -struct CommaInitializer -{ - typedef typename XprType::Scalar Scalar; - - EIGEN_DEVICE_FUNC - inline CommaInitializer(XprType& xpr, const Scalar& s) - : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1) - { - m_xpr.coeffRef(0,0) = s; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other) - : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows()) - { - m_xpr.block(0, 0, other.rows(), other.cols()) = other; - } - - /* Copy/Move constructor which transfers ownership. This is crucial in - * absence of return value optimization to avoid assertions during destruction. */ - // FIXME in C++11 mode this could be replaced by a proper RValue constructor - EIGEN_DEVICE_FUNC - inline CommaInitializer(const CommaInitializer& o) - : m_xpr(o.m_xpr), m_row(o.m_row), m_col(o.m_col), m_currentBlockRows(o.m_currentBlockRows) { - // Mark original object as finished. In absence of R-value references we need to const_cast: - const_cast<CommaInitializer&>(o).m_row = m_xpr.rows(); - const_cast<CommaInitializer&>(o).m_col = m_xpr.cols(); - const_cast<CommaInitializer&>(o).m_currentBlockRows = 0; - } - - /* inserts a scalar value in the target matrix */ - EIGEN_DEVICE_FUNC - CommaInitializer& operator,(const Scalar& s) - { - if (m_col==m_xpr.cols()) - { - m_row+=m_currentBlockRows; - m_col = 0; - m_currentBlockRows = 1; - eigen_assert(m_row<m_xpr.rows() - && "Too many rows passed to comma initializer (operator<<)"); - } - eigen_assert(m_col<m_xpr.cols() - && "Too many coefficients passed to comma initializer (operator<<)"); - eigen_assert(m_currentBlockRows==1); - m_xpr.coeffRef(m_row, m_col++) = s; - return *this; - } - - /* inserts a matrix expression in the target matrix */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - CommaInitializer& operator,(const DenseBase<OtherDerived>& other) - { - if (m_col==m_xpr.cols() && (other.cols()!=0 || other.rows()!=m_currentBlockRows)) - { - m_row+=m_currentBlockRows; - m_col = 0; - m_currentBlockRows = other.rows(); - eigen_assert(m_row+m_currentBlockRows<=m_xpr.rows() - && "Too many rows passed to comma initializer (operator<<)"); - } - eigen_assert((m_col + other.cols() <= m_xpr.cols()) - && "Too many coefficients passed to comma initializer (operator<<)"); - eigen_assert(m_currentBlockRows==other.rows()); - m_xpr.template block<OtherDerived::RowsAtCompileTime, OtherDerived::ColsAtCompileTime> - (m_row, m_col, other.rows(), other.cols()) = other; - m_col += other.cols(); - return *this; - } - - EIGEN_DEVICE_FUNC - inline ~CommaInitializer() -#if defined VERIFY_RAISES_ASSERT && (!defined EIGEN_NO_ASSERTION_CHECKING) && defined EIGEN_EXCEPTIONS - EIGEN_EXCEPTION_SPEC(Eigen::eigen_assert_exception) -#endif - { - finished(); - } - - /** \returns the built matrix once all its coefficients have been set. - * Calling finished is 100% optional. Its purpose is to write expressions - * like this: - * \code - * quaternion.fromRotationMatrix((Matrix3f() << axis0, axis1, axis2).finished()); - * \endcode - */ - EIGEN_DEVICE_FUNC - inline XprType& finished() { - eigen_assert(((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0) - && m_col == m_xpr.cols() - && "Too few coefficients passed to comma initializer (operator<<)"); - return m_xpr; - } - - XprType& m_xpr; // target expression - Index m_row; // current row id - Index m_col; // current col id - Index m_currentBlockRows; // current block height -}; - -/** \anchor MatrixBaseCommaInitRef - * Convenient operator to set the coefficients of a matrix. - * - * The coefficients must be provided in a row major order and exactly match - * the size of the matrix. Otherwise an assertion is raised. - * - * Example: \include MatrixBase_set.cpp - * Output: \verbinclude MatrixBase_set.out - * - * \note According the c++ standard, the argument expressions of this comma initializer are evaluated in arbitrary order. - * - * \sa CommaInitializer::finished(), class CommaInitializer - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline CommaInitializer<Derived> DenseBase<Derived>::operator<< (const Scalar& s) -{ - return CommaInitializer<Derived>(*static_cast<Derived*>(this), s); -} - -/** \sa operator<<(const Scalar&) */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC inline CommaInitializer<Derived> -DenseBase<Derived>::operator<<(const DenseBase<OtherDerived>& other) -{ - return CommaInitializer<Derived>(*static_cast<Derived *>(this), other); -} - -} // end namespace Eigen - -#endif // EIGEN_COMMAINITIALIZER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/ConditionEstimator.h b/external/eigen/include/eigen3/Eigen/src/Core/ConditionEstimator.h deleted file mode 100644 index 51a2e5f1..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/ConditionEstimator.h +++ /dev/null @@ -1,175 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CONDITIONESTIMATOR_H -#define EIGEN_CONDITIONESTIMATOR_H - -namespace Eigen { - -namespace internal { - -template <typename Vector, typename RealVector, bool IsComplex> -struct rcond_compute_sign { - static inline Vector run(const Vector& v) { - const RealVector v_abs = v.cwiseAbs(); - return (v_abs.array() == static_cast<typename Vector::RealScalar>(0)) - .select(Vector::Ones(v.size()), v.cwiseQuotient(v_abs)); - } -}; - -// Partial specialization to avoid elementwise division for real vectors. -template <typename Vector> -struct rcond_compute_sign<Vector, Vector, false> { - static inline Vector run(const Vector& v) { - return (v.array() < static_cast<typename Vector::RealScalar>(0)) - .select(-Vector::Ones(v.size()), Vector::Ones(v.size())); - } -}; - -/** - * \returns an estimate of ||inv(matrix)||_1 given a decomposition of - * \a matrix that implements .solve() and .adjoint().solve() methods. - * - * This function implements Algorithms 4.1 and 5.1 from - * http://www.maths.manchester.ac.uk/~higham/narep/narep135.pdf - * which also forms the basis for the condition number estimators in - * LAPACK. Since at most 10 calls to the solve method of dec are - * performed, the total cost is O(dims^2), as opposed to O(dims^3) - * needed to compute the inverse matrix explicitly. - * - * The most common usage is in estimating the condition number - * ||matrix||_1 * ||inv(matrix)||_1. The first term ||matrix||_1 can be - * computed directly in O(n^2) operations. - * - * Supports the following decompositions: FullPivLU, PartialPivLU, LDLT, and - * LLT. - * - * \sa FullPivLU, PartialPivLU, LDLT, LLT. - */ -template <typename Decomposition> -typename Decomposition::RealScalar rcond_invmatrix_L1_norm_estimate(const Decomposition& dec) -{ - typedef typename Decomposition::MatrixType MatrixType; - typedef typename Decomposition::Scalar Scalar; - typedef typename Decomposition::RealScalar RealScalar; - typedef typename internal::plain_col_type<MatrixType>::type Vector; - typedef typename internal::plain_col_type<MatrixType, RealScalar>::type RealVector; - const bool is_complex = (NumTraits<Scalar>::IsComplex != 0); - - eigen_assert(dec.rows() == dec.cols()); - const Index n = dec.rows(); - if (n == 0) - return 0; - - // Disable Index to float conversion warning -#ifdef __INTEL_COMPILER - #pragma warning push - #pragma warning ( disable : 2259 ) -#endif - Vector v = dec.solve(Vector::Ones(n) / Scalar(n)); -#ifdef __INTEL_COMPILER - #pragma warning pop -#endif - - // lower_bound is a lower bound on - // ||inv(matrix)||_1 = sup_v ||inv(matrix) v||_1 / ||v||_1 - // and is the objective maximized by the ("super-") gradient ascent - // algorithm below. - RealScalar lower_bound = v.template lpNorm<1>(); - if (n == 1) - return lower_bound; - - // Gradient ascent algorithm follows: We know that the optimum is achieved at - // one of the simplices v = e_i, so in each iteration we follow a - // super-gradient to move towards the optimal one. - RealScalar old_lower_bound = lower_bound; - Vector sign_vector(n); - Vector old_sign_vector; - Index v_max_abs_index = -1; - Index old_v_max_abs_index = v_max_abs_index; - for (int k = 0; k < 4; ++k) - { - sign_vector = internal::rcond_compute_sign<Vector, RealVector, is_complex>::run(v); - if (k > 0 && !is_complex && sign_vector == old_sign_vector) { - // Break if the solution stagnated. - break; - } - // v_max_abs_index = argmax |real( inv(matrix)^T * sign_vector )| - v = dec.adjoint().solve(sign_vector); - v.real().cwiseAbs().maxCoeff(&v_max_abs_index); - if (v_max_abs_index == old_v_max_abs_index) { - // Break if the solution stagnated. - break; - } - // Move to the new simplex e_j, where j = v_max_abs_index. - v = dec.solve(Vector::Unit(n, v_max_abs_index)); // v = inv(matrix) * e_j. - lower_bound = v.template lpNorm<1>(); - if (lower_bound <= old_lower_bound) { - // Break if the gradient step did not increase the lower_bound. - break; - } - if (!is_complex) { - old_sign_vector = sign_vector; - } - old_v_max_abs_index = v_max_abs_index; - old_lower_bound = lower_bound; - } - // The following calculates an independent estimate of ||matrix||_1 by - // multiplying matrix by a vector with entries of slowly increasing - // magnitude and alternating sign: - // v_i = (-1)^{i} (1 + (i / (dim-1))), i = 0,...,dim-1. - // This improvement to Hager's algorithm above is due to Higham. It was - // added to make the algorithm more robust in certain corner cases where - // large elements in the matrix might otherwise escape detection due to - // exact cancellation (especially when op and op_adjoint correspond to a - // sequence of backsubstitutions and permutations), which could cause - // Hager's algorithm to vastly underestimate ||matrix||_1. - Scalar alternating_sign(RealScalar(1)); - for (Index i = 0; i < n; ++i) { - // The static_cast is needed when Scalar is a complex and RealScalar implements expression templates - v[i] = alternating_sign * static_cast<RealScalar>(RealScalar(1) + (RealScalar(i) / (RealScalar(n - 1)))); - alternating_sign = -alternating_sign; - } - v = dec.solve(v); - const RealScalar alternate_lower_bound = (2 * v.template lpNorm<1>()) / (3 * RealScalar(n)); - return numext::maxi(lower_bound, alternate_lower_bound); -} - -/** \brief Reciprocal condition number estimator. - * - * Computing a decomposition of a dense matrix takes O(n^3) operations, while - * this method estimates the condition number quickly and reliably in O(n^2) - * operations. - * - * \returns an estimate of the reciprocal condition number - * (1 / (||matrix||_1 * ||inv(matrix)||_1)) of matrix, given ||matrix||_1 and - * its decomposition. Supports the following decompositions: FullPivLU, - * PartialPivLU, LDLT, and LLT. - * - * \sa FullPivLU, PartialPivLU, LDLT, LLT. - */ -template <typename Decomposition> -typename Decomposition::RealScalar -rcond_estimate_helper(typename Decomposition::RealScalar matrix_norm, const Decomposition& dec) -{ - typedef typename Decomposition::RealScalar RealScalar; - eigen_assert(dec.rows() == dec.cols()); - if (dec.rows() == 0) return NumTraits<RealScalar>::infinity(); - if (matrix_norm == RealScalar(0)) return RealScalar(0); - if (dec.rows() == 1) return RealScalar(1); - const RealScalar inverse_matrix_norm = rcond_invmatrix_L1_norm_estimate(dec); - return (inverse_matrix_norm == RealScalar(0) ? RealScalar(0) - : (RealScalar(1) / inverse_matrix_norm) / matrix_norm); -} - -} // namespace internal - -} // namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/Core/CoreEvaluators.h b/external/eigen/include/eigen3/Eigen/src/Core/CoreEvaluators.h deleted file mode 100644 index a77c0fa8..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/CoreEvaluators.h +++ /dev/null @@ -1,1732 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2011-2012 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_COREEVALUATORS_H -#define EIGEN_COREEVALUATORS_H - -namespace Eigen { - -namespace internal { - -// This class returns the evaluator kind from the expression storage kind. -// Default assumes index based accessors -template<typename StorageKind> -struct storage_kind_to_evaluator_kind { - typedef IndexBased Kind; -}; - -// This class returns the evaluator shape from the expression storage kind. -// It can be Dense, Sparse, Triangular, Diagonal, SelfAdjoint, Band, etc. -template<typename StorageKind> struct storage_kind_to_shape; - -template<> struct storage_kind_to_shape<Dense> { typedef DenseShape Shape; }; -template<> struct storage_kind_to_shape<SolverStorage> { typedef SolverShape Shape; }; -template<> struct storage_kind_to_shape<PermutationStorage> { typedef PermutationShape Shape; }; -template<> struct storage_kind_to_shape<TranspositionsStorage> { typedef TranspositionsShape Shape; }; - -// Evaluators have to be specialized with respect to various criteria such as: -// - storage/structure/shape -// - scalar type -// - etc. -// Therefore, we need specialization of evaluator providing additional template arguments for each kind of evaluators. -// We currently distinguish the following kind of evaluators: -// - unary_evaluator for expressions taking only one arguments (CwiseUnaryOp, CwiseUnaryView, Transpose, MatrixWrapper, ArrayWrapper, Reverse, Replicate) -// - binary_evaluator for expression taking two arguments (CwiseBinaryOp) -// - ternary_evaluator for expression taking three arguments (CwiseTernaryOp) -// - product_evaluator for linear algebra products (Product); special case of binary_evaluator because it requires additional tags for dispatching. -// - mapbase_evaluator for Map, Block, Ref -// - block_evaluator for Block (special dispatching to a mapbase_evaluator or unary_evaluator) - -template< typename T, - typename Arg1Kind = typename evaluator_traits<typename T::Arg1>::Kind, - typename Arg2Kind = typename evaluator_traits<typename T::Arg2>::Kind, - typename Arg3Kind = typename evaluator_traits<typename T::Arg3>::Kind, - typename Arg1Scalar = typename traits<typename T::Arg1>::Scalar, - typename Arg2Scalar = typename traits<typename T::Arg2>::Scalar, - typename Arg3Scalar = typename traits<typename T::Arg3>::Scalar> struct ternary_evaluator; - -template< typename T, - typename LhsKind = typename evaluator_traits<typename T::Lhs>::Kind, - typename RhsKind = typename evaluator_traits<typename T::Rhs>::Kind, - typename LhsScalar = typename traits<typename T::Lhs>::Scalar, - typename RhsScalar = typename traits<typename T::Rhs>::Scalar> struct binary_evaluator; - -template< typename T, - typename Kind = typename evaluator_traits<typename T::NestedExpression>::Kind, - typename Scalar = typename T::Scalar> struct unary_evaluator; - -// evaluator_traits<T> contains traits for evaluator<T> - -template<typename T> -struct evaluator_traits_base -{ - // by default, get evaluator kind and shape from storage - typedef typename storage_kind_to_evaluator_kind<typename traits<T>::StorageKind>::Kind Kind; - typedef typename storage_kind_to_shape<typename traits<T>::StorageKind>::Shape Shape; -}; - -// Default evaluator traits -template<typename T> -struct evaluator_traits : public evaluator_traits_base<T> -{ -}; - -template<typename T, typename Shape = typename evaluator_traits<T>::Shape > -struct evaluator_assume_aliasing { - static const bool value = false; -}; - -// By default, we assume a unary expression: -template<typename T> -struct evaluator : public unary_evaluator<T> -{ - typedef unary_evaluator<T> Base; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const T& xpr) : Base(xpr) {} -}; - - -// TODO: Think about const-correctness -template<typename T> -struct evaluator<const T> - : evaluator<T> -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const T& xpr) : evaluator<T>(xpr) {} -}; - -// ---------- base class for all evaluators ---------- - -template<typename ExpressionType> -struct evaluator_base -{ - // TODO that's not very nice to have to propagate all these traits. They are currently only needed to handle outer,inner indices. - typedef traits<ExpressionType> ExpressionTraits; - - enum { - Alignment = 0 - }; - // noncopyable: - // Don't make this class inherit noncopyable as this kills EBO (Empty Base Optimization) - // and make complex evaluator much larger than then should do. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator_base() {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~evaluator_base() {} -private: - EIGEN_DEVICE_FUNC evaluator_base(const evaluator_base&); - EIGEN_DEVICE_FUNC const evaluator_base& operator=(const evaluator_base&); -}; - -// -------------------- Matrix and Array -------------------- -// -// evaluator<PlainObjectBase> is a common base class for the -// Matrix and Array evaluators. -// Here we directly specialize evaluator. This is not really a unary expression, and it is, by definition, dense, -// so no need for more sophisticated dispatching. - -// this helper permits to completely eliminate m_outerStride if it is known at compiletime. -template<typename Scalar,int OuterStride> class plainobjectbase_evaluator_data { -public: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - plainobjectbase_evaluator_data(const Scalar* ptr, Index outerStride) : data(ptr) - { -#ifndef EIGEN_INTERNAL_DEBUGGING - EIGEN_UNUSED_VARIABLE(outerStride); -#endif - eigen_internal_assert(outerStride==OuterStride); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index outerStride() const { return OuterStride; } - const Scalar *data; -}; - -template<typename Scalar> class plainobjectbase_evaluator_data<Scalar,Dynamic> { -public: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - plainobjectbase_evaluator_data(const Scalar* ptr, Index outerStride) : data(ptr), m_outerStride(outerStride) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index outerStride() const { return m_outerStride; } - const Scalar *data; -protected: - Index m_outerStride; -}; - -template<typename Derived> -struct evaluator<PlainObjectBase<Derived> > - : evaluator_base<Derived> -{ - typedef PlainObjectBase<Derived> PlainObjectType; - typedef typename PlainObjectType::Scalar Scalar; - typedef typename PlainObjectType::CoeffReturnType CoeffReturnType; - - enum { - IsRowMajor = PlainObjectType::IsRowMajor, - IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime, - RowsAtCompileTime = PlainObjectType::RowsAtCompileTime, - ColsAtCompileTime = PlainObjectType::ColsAtCompileTime, - - CoeffReadCost = NumTraits<Scalar>::ReadCost, - Flags = traits<Derived>::EvaluatorFlags, - Alignment = traits<Derived>::Alignment - }; - enum { - // We do not need to know the outer stride for vectors - OuterStrideAtCompileTime = IsVectorAtCompileTime ? 0 - : int(IsRowMajor) ? ColsAtCompileTime - : RowsAtCompileTime - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - evaluator() - : m_d(0,OuterStrideAtCompileTime) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const PlainObjectType& m) - : m_d(m.data(),IsVectorAtCompileTime ? 0 : m.outerStride()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - if (IsRowMajor) - return m_d.data[row * m_d.outerStride() + col]; - else - return m_d.data[row + col * m_d.outerStride()]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_d.data[index]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index col) - { - if (IsRowMajor) - return const_cast<Scalar*>(m_d.data)[row * m_d.outerStride() + col]; - else - return const_cast<Scalar*>(m_d.data)[row + col * m_d.outerStride()]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index index) - { - return const_cast<Scalar*>(m_d.data)[index]; - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - if (IsRowMajor) - return ploadt<PacketType, LoadMode>(m_d.data + row * m_d.outerStride() + col); - else - return ploadt<PacketType, LoadMode>(m_d.data + row + col * m_d.outerStride()); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - return ploadt<PacketType, LoadMode>(m_d.data + index); - } - - template<int StoreMode,typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index row, Index col, const PacketType& x) - { - if (IsRowMajor) - return pstoret<Scalar, PacketType, StoreMode> - (const_cast<Scalar*>(m_d.data) + row * m_d.outerStride() + col, x); - else - return pstoret<Scalar, PacketType, StoreMode> - (const_cast<Scalar*>(m_d.data) + row + col * m_d.outerStride(), x); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketType& x) - { - return pstoret<Scalar, PacketType, StoreMode>(const_cast<Scalar*>(m_d.data) + index, x); - } - -protected: - - plainobjectbase_evaluator_data<Scalar,OuterStrideAtCompileTime> m_d; -}; - -template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols> -struct evaluator<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > - : evaluator<PlainObjectBase<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > > -{ - typedef Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - evaluator() {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const XprType& m) - : evaluator<PlainObjectBase<XprType> >(m) - { } -}; - -template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols> -struct evaluator<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > - : evaluator<PlainObjectBase<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > > -{ - typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - evaluator() {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const XprType& m) - : evaluator<PlainObjectBase<XprType> >(m) - { } -}; - -// -------------------- Transpose -------------------- - -template<typename ArgType> -struct unary_evaluator<Transpose<ArgType>, IndexBased> - : evaluator_base<Transpose<ArgType> > -{ - typedef Transpose<ArgType> XprType; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - Flags = evaluator<ArgType>::Flags ^ RowMajorBit, - Alignment = evaluator<ArgType>::Alignment - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit unary_evaluator(const XprType& t) : m_argImpl(t.nestedExpression()) {} - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_argImpl.coeff(col, row); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_argImpl.coeff(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index col) - { - return m_argImpl.coeffRef(col, row); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename XprType::Scalar& coeffRef(Index index) - { - return m_argImpl.coeffRef(index); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - return m_argImpl.template packet<LoadMode,PacketType>(col, row); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - return m_argImpl.template packet<LoadMode,PacketType>(index); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index row, Index col, const PacketType& x) - { - m_argImpl.template writePacket<StoreMode,PacketType>(col, row, x); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketType& x) - { - m_argImpl.template writePacket<StoreMode,PacketType>(index, x); - } - -protected: - evaluator<ArgType> m_argImpl; -}; - -// -------------------- CwiseNullaryOp -------------------- -// Like Matrix and Array, this is not really a unary expression, so we directly specialize evaluator. -// Likewise, there is not need to more sophisticated dispatching here. - -template<typename Scalar,typename NullaryOp, - bool has_nullary = has_nullary_operator<NullaryOp>::value, - bool has_unary = has_unary_operator<NullaryOp>::value, - bool has_binary = has_binary_operator<NullaryOp>::value> -struct nullary_wrapper -{ - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const { return op(i,j); } - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const { return op(i); } - - template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const { return op.template packetOp<T>(i,j); } - template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const { return op.template packetOp<T>(i); } -}; - -template<typename Scalar,typename NullaryOp> -struct nullary_wrapper<Scalar,NullaryOp,true,false,false> -{ - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType=0, IndexType=0) const { return op(); } - template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType=0, IndexType=0) const { return op.template packetOp<T>(); } -}; - -template<typename Scalar,typename NullaryOp> -struct nullary_wrapper<Scalar,NullaryOp,false,false,true> -{ - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j=0) const { return op(i,j); } - template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j=0) const { return op.template packetOp<T>(i,j); } -}; - -// We need the following specialization for vector-only functors assigned to a runtime vector, -// for instance, using linspace and assigning a RowVectorXd to a MatrixXd or even a row of a MatrixXd. -// In this case, i==0 and j is used for the actual iteration. -template<typename Scalar,typename NullaryOp> -struct nullary_wrapper<Scalar,NullaryOp,false,true,false> -{ - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const { - eigen_assert(i==0 || j==0); - return op(i+j); - } - template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const { - eigen_assert(i==0 || j==0); - return op.template packetOp<T>(i+j); - } - - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const { return op(i); } - template <typename T, typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const { return op.template packetOp<T>(i); } -}; - -template<typename Scalar,typename NullaryOp> -struct nullary_wrapper<Scalar,NullaryOp,false,false,false> {}; - -#if 0 && EIGEN_COMP_MSVC>0 -// Disable this ugly workaround. This is now handled in traits<Ref>::match, -// but this piece of code might still become handly if some other weird compilation -// erros pop up again. - -// MSVC exhibits a weird compilation error when -// compiling: -// Eigen::MatrixXf A = MatrixXf::Random(3,3); -// Ref<const MatrixXf> R = 2.f*A; -// and that has_*ary_operator<scalar_constant_op<float>> have not been instantiated yet. -// The "problem" is that evaluator<2.f*A> is instantiated by traits<Ref>::match<2.f*A> -// and at that time has_*ary_operator<T> returns true regardless of T. -// Then nullary_wrapper is badly instantiated as nullary_wrapper<.,.,true,true,true>. -// The trick is thus to defer the proper instantiation of nullary_wrapper when coeff(), -// and packet() are really instantiated as implemented below: - -// This is a simple wrapper around Index to enforce the re-instantiation of -// has_*ary_operator when needed. -template<typename T> struct nullary_wrapper_workaround_msvc { - nullary_wrapper_workaround_msvc(const T&); - operator T()const; -}; - -template<typename Scalar,typename NullaryOp> -struct nullary_wrapper<Scalar,NullaryOp,true,true,true> -{ - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const { - return nullary_wrapper<Scalar,NullaryOp, - has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value, - has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value, - has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().operator()(op,i,j); - } - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const { - return nullary_wrapper<Scalar,NullaryOp, - has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value, - has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value, - has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().operator()(op,i); - } - - template <typename T, typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const { - return nullary_wrapper<Scalar,NullaryOp, - has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value, - has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value, - has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().template packetOp<T>(op,i,j); - } - template <typename T, typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const { - return nullary_wrapper<Scalar,NullaryOp, - has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value, - has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value, - has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().template packetOp<T>(op,i); - } -}; -#endif // MSVC workaround - -template<typename NullaryOp, typename PlainObjectType> -struct evaluator<CwiseNullaryOp<NullaryOp,PlainObjectType> > - : evaluator_base<CwiseNullaryOp<NullaryOp,PlainObjectType> > -{ - typedef CwiseNullaryOp<NullaryOp,PlainObjectType> XprType; - typedef typename internal::remove_all<PlainObjectType>::type PlainObjectTypeCleaned; - - enum { - CoeffReadCost = internal::functor_traits<NullaryOp>::Cost, - - Flags = (evaluator<PlainObjectTypeCleaned>::Flags - & ( HereditaryBits - | (functor_has_linear_access<NullaryOp>::ret ? LinearAccessBit : 0) - | (functor_traits<NullaryOp>::PacketAccess ? PacketAccessBit : 0))) - | (functor_traits<NullaryOp>::IsRepeatable ? 0 : EvalBeforeNestingBit), - Alignment = AlignedMax - }; - - EIGEN_DEVICE_FUNC explicit evaluator(const XprType& n) - : m_functor(n.functor()), m_wrapper() - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::CoeffReturnType CoeffReturnType; - - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(IndexType row, IndexType col) const - { - return m_wrapper(m_functor, row, col); - } - - template <typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(IndexType index) const - { - return m_wrapper(m_functor,index); - } - - template<int LoadMode, typename PacketType, typename IndexType> - EIGEN_STRONG_INLINE - PacketType packet(IndexType row, IndexType col) const - { - return m_wrapper.template packetOp<PacketType>(m_functor, row, col); - } - - template<int LoadMode, typename PacketType, typename IndexType> - EIGEN_STRONG_INLINE - PacketType packet(IndexType index) const - { - return m_wrapper.template packetOp<PacketType>(m_functor, index); - } - -protected: - const NullaryOp m_functor; - const internal::nullary_wrapper<CoeffReturnType,NullaryOp> m_wrapper; -}; - -// -------------------- CwiseUnaryOp -------------------- - -template<typename UnaryOp, typename ArgType> -struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IndexBased > - : evaluator_base<CwiseUnaryOp<UnaryOp, ArgType> > -{ - typedef CwiseUnaryOp<UnaryOp, ArgType> XprType; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost, - - Flags = evaluator<ArgType>::Flags - & (HereditaryBits | LinearAccessBit | (functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0)), - Alignment = evaluator<ArgType>::Alignment - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit unary_evaluator(const XprType& op) : m_d(op) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_d.func()(m_d.argImpl.coeff(row, col)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_d.func()(m_d.argImpl.coeff(index)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - return m_d.func().packetOp(m_d.argImpl.template packet<LoadMode, PacketType>(row, col)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - return m_d.func().packetOp(m_d.argImpl.template packet<LoadMode, PacketType>(index)); - } - -protected: - - // this helper permits to completely eliminate the functor if it is empty - class Data : private UnaryOp - { - public: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Data(const XprType& xpr) : UnaryOp(xpr.functor()), argImpl(xpr.nestedExpression()) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const UnaryOp& func() const { return static_cast<const UnaryOp&>(*this); } - evaluator<ArgType> argImpl; - }; - - Data m_d; -}; - -// -------------------- CwiseTernaryOp -------------------- - -// this is a ternary expression -template<typename TernaryOp, typename Arg1, typename Arg2, typename Arg3> -struct evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > - : public ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > -{ - typedef CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> XprType; - typedef ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > Base; - - EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : Base(xpr) {} -}; - -template<typename TernaryOp, typename Arg1, typename Arg2, typename Arg3> -struct ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3>, IndexBased, IndexBased> - : evaluator_base<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > -{ - typedef CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> XprType; - - enum { - CoeffReadCost = evaluator<Arg1>::CoeffReadCost + evaluator<Arg2>::CoeffReadCost + evaluator<Arg3>::CoeffReadCost + functor_traits<TernaryOp>::Cost, - - Arg1Flags = evaluator<Arg1>::Flags, - Arg2Flags = evaluator<Arg2>::Flags, - Arg3Flags = evaluator<Arg3>::Flags, - SameType = is_same<typename Arg1::Scalar,typename Arg2::Scalar>::value && is_same<typename Arg1::Scalar,typename Arg3::Scalar>::value, - StorageOrdersAgree = (int(Arg1Flags)&RowMajorBit)==(int(Arg2Flags)&RowMajorBit) && (int(Arg1Flags)&RowMajorBit)==(int(Arg3Flags)&RowMajorBit), - Flags0 = (int(Arg1Flags) | int(Arg2Flags) | int(Arg3Flags)) & ( - HereditaryBits - | (int(Arg1Flags) & int(Arg2Flags) & int(Arg3Flags) & - ( (StorageOrdersAgree ? LinearAccessBit : 0) - | (functor_traits<TernaryOp>::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0) - ) - ) - ), - Flags = (Flags0 & ~RowMajorBit) | (Arg1Flags & RowMajorBit), - Alignment = EIGEN_PLAIN_ENUM_MIN( - EIGEN_PLAIN_ENUM_MIN(evaluator<Arg1>::Alignment, evaluator<Arg2>::Alignment), - evaluator<Arg3>::Alignment) - }; - - EIGEN_DEVICE_FUNC explicit ternary_evaluator(const XprType& xpr) : m_d(xpr) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<TernaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_d.func()(m_d.arg1Impl.coeff(row, col), m_d.arg2Impl.coeff(row, col), m_d.arg3Impl.coeff(row, col)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_d.func()(m_d.arg1Impl.coeff(index), m_d.arg2Impl.coeff(index), m_d.arg3Impl.coeff(index)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - return m_d.func().packetOp(m_d.arg1Impl.template packet<LoadMode,PacketType>(row, col), - m_d.arg2Impl.template packet<LoadMode,PacketType>(row, col), - m_d.arg3Impl.template packet<LoadMode,PacketType>(row, col)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - return m_d.func().packetOp(m_d.arg1Impl.template packet<LoadMode,PacketType>(index), - m_d.arg2Impl.template packet<LoadMode,PacketType>(index), - m_d.arg3Impl.template packet<LoadMode,PacketType>(index)); - } - -protected: - // this helper permits to completely eliminate the functor if it is empty - struct Data : private TernaryOp - { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Data(const XprType& xpr) : TernaryOp(xpr.functor()), arg1Impl(xpr.arg1()), arg2Impl(xpr.arg2()), arg3Impl(xpr.arg3()) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TernaryOp& func() const { return static_cast<const TernaryOp&>(*this); } - evaluator<Arg1> arg1Impl; - evaluator<Arg2> arg2Impl; - evaluator<Arg3> arg3Impl; - }; - - Data m_d; -}; - -// -------------------- CwiseBinaryOp -------------------- - -// this is a binary expression -template<typename BinaryOp, typename Lhs, typename Rhs> -struct evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > - : public binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType; - typedef binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > Base; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const XprType& xpr) : Base(xpr) {} -}; - -template<typename BinaryOp, typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBased> - : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType; - - enum { - CoeffReadCost = evaluator<Lhs>::CoeffReadCost + evaluator<Rhs>::CoeffReadCost + functor_traits<BinaryOp>::Cost, - - LhsFlags = evaluator<Lhs>::Flags, - RhsFlags = evaluator<Rhs>::Flags, - SameType = is_same<typename Lhs::Scalar,typename Rhs::Scalar>::value, - StorageOrdersAgree = (int(LhsFlags)&RowMajorBit)==(int(RhsFlags)&RowMajorBit), - Flags0 = (int(LhsFlags) | int(RhsFlags)) & ( - HereditaryBits - | (int(LhsFlags) & int(RhsFlags) & - ( (StorageOrdersAgree ? LinearAccessBit : 0) - | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0) - ) - ) - ), - Flags = (Flags0 & ~RowMajorBit) | (LhsFlags & RowMajorBit), - Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment,evaluator<Rhs>::Alignment) - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit binary_evaluator(const XprType& xpr) : m_d(xpr) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_d.func()(m_d.lhsImpl.coeff(row, col), m_d.rhsImpl.coeff(row, col)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_d.func()(m_d.lhsImpl.coeff(index), m_d.rhsImpl.coeff(index)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode,PacketType>(row, col), - m_d.rhsImpl.template packet<LoadMode,PacketType>(row, col)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode,PacketType>(index), - m_d.rhsImpl.template packet<LoadMode,PacketType>(index)); - } - -protected: - - // this helper permits to completely eliminate the functor if it is empty - struct Data : private BinaryOp - { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Data(const XprType& xpr) : BinaryOp(xpr.functor()), lhsImpl(xpr.lhs()), rhsImpl(xpr.rhs()) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const BinaryOp& func() const { return static_cast<const BinaryOp&>(*this); } - evaluator<Lhs> lhsImpl; - evaluator<Rhs> rhsImpl; - }; - - Data m_d; -}; - -// -------------------- CwiseUnaryView -------------------- - -template<typename UnaryOp, typename ArgType> -struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased> - : evaluator_base<CwiseUnaryView<UnaryOp, ArgType> > -{ - typedef CwiseUnaryView<UnaryOp, ArgType> XprType; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost, - - Flags = (evaluator<ArgType>::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit)), - - Alignment = 0 // FIXME it is not very clear why alignment is necessarily lost... - }; - - EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& op) : m_d(op) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_d.func()(m_d.argImpl.coeff(row, col)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_d.func()(m_d.argImpl.coeff(index)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index col) - { - return m_d.func()(m_d.argImpl.coeffRef(row, col)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index index) - { - return m_d.func()(m_d.argImpl.coeffRef(index)); - } - -protected: - - // this helper permits to completely eliminate the functor if it is empty - struct Data : private UnaryOp - { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Data(const XprType& xpr) : UnaryOp(xpr.functor()), argImpl(xpr.nestedExpression()) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const UnaryOp& func() const { return static_cast<const UnaryOp&>(*this); } - evaluator<ArgType> argImpl; - }; - - Data m_d; -}; - -// -------------------- Map -------------------- - -// FIXME perhaps the PlainObjectType could be provided by Derived::PlainObject ? -// but that might complicate template specialization -template<typename Derived, typename PlainObjectType> -struct mapbase_evaluator; - -template<typename Derived, typename PlainObjectType> -struct mapbase_evaluator : evaluator_base<Derived> -{ - typedef Derived XprType; - typedef typename XprType::PointerType PointerType; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - enum { - IsRowMajor = XprType::RowsAtCompileTime, - ColsAtCompileTime = XprType::ColsAtCompileTime, - CoeffReadCost = NumTraits<Scalar>::ReadCost - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit mapbase_evaluator(const XprType& map) - : m_data(const_cast<PointerType>(map.data())), - m_innerStride(map.innerStride()), - m_outerStride(map.outerStride()) - { - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(evaluator<Derived>::Flags&PacketAccessBit, internal::inner_stride_at_compile_time<Derived>::ret==1), - PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_data[col * colStride() + row * rowStride()]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_data[index * m_innerStride.value()]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index col) - { - return m_data[col * colStride() + row * rowStride()]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index index) - { - return m_data[index * m_innerStride.value()]; - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - PointerType ptr = m_data + row * rowStride() + col * colStride(); - return internal::ploadt<PacketType, LoadMode>(ptr); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - return internal::ploadt<PacketType, LoadMode>(m_data + index * m_innerStride.value()); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index row, Index col, const PacketType& x) - { - PointerType ptr = m_data + row * rowStride() + col * colStride(); - return internal::pstoret<Scalar, PacketType, StoreMode>(ptr, x); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketType& x) - { - internal::pstoret<Scalar, PacketType, StoreMode>(m_data + index * m_innerStride.value(), x); - } -protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index rowStride() const { return XprType::IsRowMajor ? m_outerStride.value() : m_innerStride.value(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index colStride() const { return XprType::IsRowMajor ? m_innerStride.value() : m_outerStride.value(); } - - PointerType m_data; - const internal::variable_if_dynamic<Index, XprType::InnerStrideAtCompileTime> m_innerStride; - const internal::variable_if_dynamic<Index, XprType::OuterStrideAtCompileTime> m_outerStride; -}; - -template<typename PlainObjectType, int MapOptions, typename StrideType> -struct evaluator<Map<PlainObjectType, MapOptions, StrideType> > - : public mapbase_evaluator<Map<PlainObjectType, MapOptions, StrideType>, PlainObjectType> -{ - typedef Map<PlainObjectType, MapOptions, StrideType> XprType; - typedef typename XprType::Scalar Scalar; - // TODO: should check for smaller packet types once we can handle multi-sized packet types - typedef typename packet_traits<Scalar>::type PacketScalar; - - enum { - InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0 - ? int(PlainObjectType::InnerStrideAtCompileTime) - : int(StrideType::InnerStrideAtCompileTime), - OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0 - ? int(PlainObjectType::OuterStrideAtCompileTime) - : int(StrideType::OuterStrideAtCompileTime), - HasNoInnerStride = InnerStrideAtCompileTime == 1, - HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0, - HasNoStride = HasNoInnerStride && HasNoOuterStride, - IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic, - - PacketAccessMask = bool(HasNoInnerStride) ? ~int(0) : ~int(PacketAccessBit), - LinearAccessMask = bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime) ? ~int(0) : ~int(LinearAccessBit), - Flags = int( evaluator<PlainObjectType>::Flags) & (LinearAccessMask&PacketAccessMask), - - Alignment = int(MapOptions)&int(AlignedMask) - }; - - EIGEN_DEVICE_FUNC explicit evaluator(const XprType& map) - : mapbase_evaluator<XprType, PlainObjectType>(map) - { } -}; - -// -------------------- Ref -------------------- - -template<typename PlainObjectType, int RefOptions, typename StrideType> -struct evaluator<Ref<PlainObjectType, RefOptions, StrideType> > - : public mapbase_evaluator<Ref<PlainObjectType, RefOptions, StrideType>, PlainObjectType> -{ - typedef Ref<PlainObjectType, RefOptions, StrideType> XprType; - - enum { - Flags = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Flags, - Alignment = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Alignment - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const XprType& ref) - : mapbase_evaluator<XprType, PlainObjectType>(ref) - { } -}; - -// -------------------- Block -------------------- - -template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel, - bool HasDirectAccess = internal::has_direct_access<ArgType>::ret> struct block_evaluator; - -template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> -struct evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> > - : block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel> -{ - typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType; - typedef typename XprType::Scalar Scalar; - // TODO: should check for smaller packet types once we can handle multi-sized packet types - typedef typename packet_traits<Scalar>::type PacketScalar; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - - RowsAtCompileTime = traits<XprType>::RowsAtCompileTime, - ColsAtCompileTime = traits<XprType>::ColsAtCompileTime, - MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime, - MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime, - - ArgTypeIsRowMajor = (int(evaluator<ArgType>::Flags)&RowMajorBit) != 0, - IsRowMajor = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? 1 - : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0 - : ArgTypeIsRowMajor, - HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor), - InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime), - InnerStrideAtCompileTime = HasSameStorageOrderAsArgType - ? int(inner_stride_at_compile_time<ArgType>::ret) - : int(outer_stride_at_compile_time<ArgType>::ret), - OuterStrideAtCompileTime = HasSameStorageOrderAsArgType - ? int(outer_stride_at_compile_time<ArgType>::ret) - : int(inner_stride_at_compile_time<ArgType>::ret), - MaskPacketAccessBit = (InnerStrideAtCompileTime == 1 || HasSameStorageOrderAsArgType) ? PacketAccessBit : 0, - - FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || (InnerPanel && (evaluator<ArgType>::Flags&LinearAccessBit))) ? LinearAccessBit : 0, - FlagsRowMajorBit = XprType::Flags&RowMajorBit, - Flags0 = evaluator<ArgType>::Flags & ( (HereditaryBits & ~RowMajorBit) | - DirectAccessBit | - MaskPacketAccessBit), - Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit, - - PacketAlignment = unpacket_traits<PacketScalar>::alignment, - Alignment0 = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) - && (OuterStrideAtCompileTime!=0) - && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % int(PacketAlignment)) == 0)) ? int(PacketAlignment) : 0, - Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ArgType>::Alignment, Alignment0) - }; - typedef block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel> block_evaluator_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const XprType& block) : block_evaluator_type(block) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } -}; - -// no direct-access => dispatch to a unary evaluator -template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> -struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, /*HasDirectAccess*/ false> - : unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> > -{ - typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit block_evaluator(const XprType& block) - : unary_evaluator<XprType>(block) - {} -}; - -template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> -struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBased> - : evaluator_base<Block<ArgType, BlockRows, BlockCols, InnerPanel> > -{ - typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit unary_evaluator(const XprType& block) - : m_argImpl(block.nestedExpression()), - m_startRow(block.startRow()), - m_startCol(block.startCol()), - m_linear_offset(ForwardLinearAccess?(ArgType::IsRowMajor ? block.startRow()*block.nestedExpression().cols() + block.startCol() : block.startCol()*block.nestedExpression().rows() + block.startRow()):0) - { } - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - enum { - RowsAtCompileTime = XprType::RowsAtCompileTime, - ForwardLinearAccess = (InnerPanel || int(XprType::IsRowMajor)==int(ArgType::IsRowMajor)) && bool(evaluator<ArgType>::Flags&LinearAccessBit) - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_argImpl.coeff(m_startRow.value() + row, m_startCol.value() + col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return linear_coeff_impl(index, bool_constant<ForwardLinearAccess>()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index col) - { - return m_argImpl.coeffRef(m_startRow.value() + row, m_startCol.value() + col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index index) - { - return linear_coeffRef_impl(index, bool_constant<ForwardLinearAccess>()); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - return m_argImpl.template packet<LoadMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - if (ForwardLinearAccess) - return m_argImpl.template packet<LoadMode,PacketType>(m_linear_offset.value() + index); - else - return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index row, Index col, const PacketType& x) - { - return m_argImpl.template writePacket<StoreMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col, x); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketType& x) - { - if (ForwardLinearAccess) - return m_argImpl.template writePacket<StoreMode,PacketType>(m_linear_offset.value() + index, x); - else - return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0, - x); - } - -protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType linear_coeff_impl(Index index, internal::true_type /* ForwardLinearAccess */) const - { - return m_argImpl.coeff(m_linear_offset.value() + index); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType linear_coeff_impl(Index index, internal::false_type /* not ForwardLinearAccess */) const - { - return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& linear_coeffRef_impl(Index index, internal::true_type /* ForwardLinearAccess */) - { - return m_argImpl.coeffRef(m_linear_offset.value() + index); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& linear_coeffRef_impl(Index index, internal::false_type /* not ForwardLinearAccess */) - { - return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0); - } - - evaluator<ArgType> m_argImpl; - const variable_if_dynamic<Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow; - const variable_if_dynamic<Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol; - const variable_if_dynamic<Index, ForwardLinearAccess ? Dynamic : 0> m_linear_offset; -}; - -// TODO: This evaluator does not actually use the child evaluator; -// all action is via the data() as returned by the Block expression. - -template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> -struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ true> - : mapbase_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, - typename Block<ArgType, BlockRows, BlockCols, InnerPanel>::PlainObject> -{ - typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType; - typedef typename XprType::Scalar Scalar; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit block_evaluator(const XprType& block) - : mapbase_evaluator<XprType, typename XprType::PlainObject>(block) - { - // TODO: for the 3.3 release, this should be turned to an internal assertion, but let's keep it as is for the beta lifetime - eigen_assert(((internal::UIntPtr(block.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) && "data is not aligned"); - } -}; - - -// -------------------- Select -------------------- -// NOTE shall we introduce a ternary_evaluator? - -// TODO enable vectorization for Select -template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType> -struct evaluator<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> > - : evaluator_base<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> > -{ - typedef Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> XprType; - enum { - CoeffReadCost = evaluator<ConditionMatrixType>::CoeffReadCost - + EIGEN_PLAIN_ENUM_MAX(evaluator<ThenMatrixType>::CoeffReadCost, - evaluator<ElseMatrixType>::CoeffReadCost), - - Flags = (unsigned int)evaluator<ThenMatrixType>::Flags & evaluator<ElseMatrixType>::Flags & HereditaryBits, - - Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ThenMatrixType>::Alignment, evaluator<ElseMatrixType>::Alignment) - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const XprType& select) - : m_conditionImpl(select.conditionMatrix()), - m_thenImpl(select.thenMatrix()), - m_elseImpl(select.elseMatrix()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - if (m_conditionImpl.coeff(row, col)) - return m_thenImpl.coeff(row, col); - else - return m_elseImpl.coeff(row, col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - if (m_conditionImpl.coeff(index)) - return m_thenImpl.coeff(index); - else - return m_elseImpl.coeff(index); - } - -protected: - evaluator<ConditionMatrixType> m_conditionImpl; - evaluator<ThenMatrixType> m_thenImpl; - evaluator<ElseMatrixType> m_elseImpl; -}; - - -// -------------------- Replicate -------------------- - -template<typename ArgType, int RowFactor, int ColFactor> -struct unary_evaluator<Replicate<ArgType, RowFactor, ColFactor> > - : evaluator_base<Replicate<ArgType, RowFactor, ColFactor> > -{ - typedef Replicate<ArgType, RowFactor, ColFactor> XprType; - typedef typename XprType::CoeffReturnType CoeffReturnType; - enum { - Factor = (RowFactor==Dynamic || ColFactor==Dynamic) ? Dynamic : RowFactor*ColFactor - }; - typedef typename internal::nested_eval<ArgType,Factor>::type ArgTypeNested; - typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned; - - enum { - CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost, - LinearAccessMask = XprType::IsVectorAtCompileTime ? LinearAccessBit : 0, - Flags = (evaluator<ArgTypeNestedCleaned>::Flags & (HereditaryBits|LinearAccessMask) & ~RowMajorBit) | (traits<XprType>::Flags & RowMajorBit), - - Alignment = evaluator<ArgTypeNestedCleaned>::Alignment - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit unary_evaluator(const XprType& replicate) - : m_arg(replicate.nestedExpression()), - m_argImpl(m_arg), - m_rows(replicate.nestedExpression().rows()), - m_cols(replicate.nestedExpression().cols()) - {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - // try to avoid using modulo; this is a pure optimization strategy - const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0 - : RowFactor==1 ? row - : row % m_rows.value(); - const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0 - : ColFactor==1 ? col - : col % m_cols.value(); - - return m_argImpl.coeff(actual_row, actual_col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - // try to avoid using modulo; this is a pure optimization strategy - const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1 - ? (ColFactor==1 ? index : index%m_cols.value()) - : (RowFactor==1 ? index : index%m_rows.value()); - - return m_argImpl.coeff(actual_index); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0 - : RowFactor==1 ? row - : row % m_rows.value(); - const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0 - : ColFactor==1 ? col - : col % m_cols.value(); - - return m_argImpl.template packet<LoadMode,PacketType>(actual_row, actual_col); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1 - ? (ColFactor==1 ? index : index%m_cols.value()) - : (RowFactor==1 ? index : index%m_rows.value()); - - return m_argImpl.template packet<LoadMode,PacketType>(actual_index); - } - -protected: - const ArgTypeNested m_arg; - evaluator<ArgTypeNestedCleaned> m_argImpl; - const variable_if_dynamic<Index, ArgType::RowsAtCompileTime> m_rows; - const variable_if_dynamic<Index, ArgType::ColsAtCompileTime> m_cols; -}; - -// -------------------- MatrixWrapper and ArrayWrapper -------------------- -// -// evaluator_wrapper_base<T> is a common base class for the -// MatrixWrapper and ArrayWrapper evaluators. - -template<typename XprType> -struct evaluator_wrapper_base - : evaluator_base<XprType> -{ - typedef typename remove_all<typename XprType::NestedExpressionType>::type ArgType; - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - Flags = evaluator<ArgType>::Flags, - Alignment = evaluator<ArgType>::Alignment - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator_wrapper_base(const ArgType& arg) : m_argImpl(arg) {} - - typedef typename ArgType::Scalar Scalar; - typedef typename ArgType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_argImpl.coeff(row, col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_argImpl.coeff(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index col) - { - return m_argImpl.coeffRef(row, col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index index) - { - return m_argImpl.coeffRef(index); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - return m_argImpl.template packet<LoadMode,PacketType>(row, col); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - return m_argImpl.template packet<LoadMode,PacketType>(index); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index row, Index col, const PacketType& x) - { - m_argImpl.template writePacket<StoreMode>(row, col, x); - } - - template<int StoreMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketType& x) - { - m_argImpl.template writePacket<StoreMode>(index, x); - } - -protected: - evaluator<ArgType> m_argImpl; -}; - -template<typename TArgType> -struct unary_evaluator<MatrixWrapper<TArgType> > - : evaluator_wrapper_base<MatrixWrapper<TArgType> > -{ - typedef MatrixWrapper<TArgType> XprType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit unary_evaluator(const XprType& wrapper) - : evaluator_wrapper_base<MatrixWrapper<TArgType> >(wrapper.nestedExpression()) - { } -}; - -template<typename TArgType> -struct unary_evaluator<ArrayWrapper<TArgType> > - : evaluator_wrapper_base<ArrayWrapper<TArgType> > -{ - typedef ArrayWrapper<TArgType> XprType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit unary_evaluator(const XprType& wrapper) - : evaluator_wrapper_base<ArrayWrapper<TArgType> >(wrapper.nestedExpression()) - { } -}; - - -// -------------------- Reverse -------------------- - -// defined in Reverse.h: -template<typename PacketType, bool ReversePacket> struct reverse_packet_cond; - -template<typename ArgType, int Direction> -struct unary_evaluator<Reverse<ArgType, Direction> > - : evaluator_base<Reverse<ArgType, Direction> > -{ - typedef Reverse<ArgType, Direction> XprType; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - enum { - IsRowMajor = XprType::IsRowMajor, - IsColMajor = !IsRowMajor, - ReverseRow = (Direction == Vertical) || (Direction == BothDirections), - ReverseCol = (Direction == Horizontal) || (Direction == BothDirections), - ReversePacket = (Direction == BothDirections) - || ((Direction == Vertical) && IsColMajor) - || ((Direction == Horizontal) && IsRowMajor), - - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - - // let's enable LinearAccess only with vectorization because of the product overhead - // FIXME enable DirectAccess with negative strides? - Flags0 = evaluator<ArgType>::Flags, - LinearAccess = ( (Direction==BothDirections) && (int(Flags0)&PacketAccessBit) ) - || ((ReverseRow && XprType::ColsAtCompileTime==1) || (ReverseCol && XprType::RowsAtCompileTime==1)) - ? LinearAccessBit : 0, - - Flags = int(Flags0) & (HereditaryBits | PacketAccessBit | LinearAccess), - - Alignment = 0 // FIXME in some rare cases, Alignment could be preserved, like a Vector4f. - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit unary_evaluator(const XprType& reverse) - : m_argImpl(reverse.nestedExpression()), - m_rows(ReverseRow ? reverse.nestedExpression().rows() : 1), - m_cols(ReverseCol ? reverse.nestedExpression().cols() : 1) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_argImpl.coeff(ReverseRow ? m_rows.value() - row - 1 : row, - ReverseCol ? m_cols.value() - col - 1 : col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index col) - { - return m_argImpl.coeffRef(ReverseRow ? m_rows.value() - row - 1 : row, - ReverseCol ? m_cols.value() - col - 1 : col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index index) - { - return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index row, Index col) const - { - enum { - PacketSize = unpacket_traits<PacketType>::size, - OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1, - OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1 - }; - typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet; - return reverse_packet::run(m_argImpl.template packet<LoadMode,PacketType>( - ReverseRow ? m_rows.value() - row - OffsetRow : row, - ReverseCol ? m_cols.value() - col - OffsetCol : col)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - PacketType packet(Index index) const - { - enum { PacketSize = unpacket_traits<PacketType>::size }; - return preverse(m_argImpl.template packet<LoadMode,PacketType>(m_rows.value() * m_cols.value() - index - PacketSize)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index row, Index col, const PacketType& x) - { - // FIXME we could factorize some code with packet(i,j) - enum { - PacketSize = unpacket_traits<PacketType>::size, - OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1, - OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1 - }; - typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet; - m_argImpl.template writePacket<LoadMode>( - ReverseRow ? m_rows.value() - row - OffsetRow : row, - ReverseCol ? m_cols.value() - col - OffsetCol : col, - reverse_packet::run(x)); - } - - template<int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketType& x) - { - enum { PacketSize = unpacket_traits<PacketType>::size }; - m_argImpl.template writePacket<LoadMode> - (m_rows.value() * m_cols.value() - index - PacketSize, preverse(x)); - } - -protected: - evaluator<ArgType> m_argImpl; - - // If we do not reverse rows, then we do not need to know the number of rows; same for columns - // Nonetheless, in this case it is important to set to 1 such that the coeff(index) method works fine for vectors. - const variable_if_dynamic<Index, ReverseRow ? ArgType::RowsAtCompileTime : 1> m_rows; - const variable_if_dynamic<Index, ReverseCol ? ArgType::ColsAtCompileTime : 1> m_cols; -}; - - -// -------------------- Diagonal -------------------- - -template<typename ArgType, int DiagIndex> -struct evaluator<Diagonal<ArgType, DiagIndex> > - : evaluator_base<Diagonal<ArgType, DiagIndex> > -{ - typedef Diagonal<ArgType, DiagIndex> XprType; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - - Flags = (unsigned int)(evaluator<ArgType>::Flags & (HereditaryBits | DirectAccessBit) & ~RowMajorBit) | LinearAccessBit, - - Alignment = 0 - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit evaluator(const XprType& diagonal) - : m_argImpl(diagonal.nestedExpression()), - m_index(diagonal.index()) - { } - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index) const - { - return m_argImpl.coeff(row + rowOffset(), row + colOffset()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index index) const - { - return m_argImpl.coeff(index + rowOffset(), index + colOffset()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index) - { - return m_argImpl.coeffRef(row + rowOffset(), row + colOffset()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index index) - { - return m_argImpl.coeffRef(index + rowOffset(), index + colOffset()); - } - -protected: - evaluator<ArgType> m_argImpl; - const internal::variable_if_dynamicindex<Index, XprType::DiagIndex> m_index; - -private: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowOffset() const { return m_index.value() > 0 ? 0 : -m_index.value(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colOffset() const { return m_index.value() > 0 ? m_index.value() : 0; } -}; - - -//---------------------------------------------------------------------- -// deprecated code -//---------------------------------------------------------------------- - -// -------------------- EvalToTemp -------------------- - -// expression class for evaluating nested expression to a temporary - -template<typename ArgType> class EvalToTemp; - -template<typename ArgType> -struct traits<EvalToTemp<ArgType> > - : public traits<ArgType> -{ }; - -template<typename ArgType> -class EvalToTemp - : public dense_xpr_base<EvalToTemp<ArgType> >::type -{ - public: - - typedef typename dense_xpr_base<EvalToTemp>::type Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp) - - explicit EvalToTemp(const ArgType& arg) - : m_arg(arg) - { } - - const ArgType& arg() const - { - return m_arg; - } - - Index rows() const - { - return m_arg.rows(); - } - - Index cols() const - { - return m_arg.cols(); - } - - private: - const ArgType& m_arg; -}; - -template<typename ArgType> -struct evaluator<EvalToTemp<ArgType> > - : public evaluator<typename ArgType::PlainObject> -{ - typedef EvalToTemp<ArgType> XprType; - typedef typename ArgType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - - EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) - : m_result(xpr.arg()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - } - - // This constructor is used when nesting an EvalTo evaluator in another evaluator - EIGEN_DEVICE_FUNC evaluator(const ArgType& arg) - : m_result(arg) - { - ::new (static_cast<Base*>(this)) Base(m_result); - } - -protected: - PlainObject m_result; -}; - -} // namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COREEVALUATORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/CoreIterators.h b/external/eigen/include/eigen3/Eigen/src/Core/CoreIterators.h deleted file mode 100644 index b9671968..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/CoreIterators.h +++ /dev/null @@ -1,132 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COREITERATORS_H -#define EIGEN_COREITERATORS_H - -namespace Eigen { - -/* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core - */ - -namespace internal { - -template<typename XprType, typename EvaluatorKind> -class inner_iterator_selector; - -} - -/** \class InnerIterator - * \brief An InnerIterator allows to loop over the element of any matrix expression. - * - * \warning To be used with care because an evaluator is constructed every time an InnerIterator iterator is constructed. - * - * TODO: add a usage example - */ -template<typename XprType> -class InnerIterator -{ -protected: - typedef internal::inner_iterator_selector<XprType, typename internal::evaluator_traits<XprType>::Kind> IteratorType; - typedef internal::evaluator<XprType> EvaluatorType; - typedef typename internal::traits<XprType>::Scalar Scalar; -public: - /** Construct an iterator over the \a outerId -th row or column of \a xpr */ - InnerIterator(const XprType &xpr, const Index &outerId) - : m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize()) - {} - - /// \returns the value of the current coefficient. - EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); } - /** Increment the iterator \c *this to the next non-zero coefficient. - * Explicit zeros are not skipped over. To skip explicit zeros, see class SparseView - */ - EIGEN_STRONG_INLINE InnerIterator& operator++() { m_iter.operator++(); return *this; } - EIGEN_STRONG_INLINE InnerIterator& operator+=(Index i) { m_iter.operator+=(i); return *this; } - EIGEN_STRONG_INLINE InnerIterator operator+(Index i) - { InnerIterator result(*this); result+=i; return result; } - - - /// \returns the column or row index of the current coefficient. - EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); } - /// \returns the row index of the current coefficient. - EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); } - /// \returns the column index of the current coefficient. - EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); } - /// \returns \c true if the iterator \c *this still references a valid coefficient. - EIGEN_STRONG_INLINE operator bool() const { return m_iter; } - -protected: - EvaluatorType m_eval; - IteratorType m_iter; -private: - // If you get here, then you're not using the right InnerIterator type, e.g.: - // SparseMatrix<double,RowMajor> A; - // SparseMatrix<double>::InnerIterator it(A,0); - template<typename T> InnerIterator(const EigenBase<T>&,Index outer); -}; - -namespace internal { - -// Generic inner iterator implementation for dense objects -template<typename XprType> -class inner_iterator_selector<XprType, IndexBased> -{ -protected: - typedef evaluator<XprType> EvaluatorType; - typedef typename traits<XprType>::Scalar Scalar; - enum { IsRowMajor = (XprType::Flags&RowMajorBit)==RowMajorBit }; - -public: - EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize) - : m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize) - {} - - EIGEN_STRONG_INLINE Scalar value() const - { - return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner) - : m_eval.coeff(m_inner, m_outer); - } - - EIGEN_STRONG_INLINE inner_iterator_selector& operator++() { m_inner++; return *this; } - - EIGEN_STRONG_INLINE Index index() const { return m_inner; } - inline Index row() const { return IsRowMajor ? m_outer : index(); } - inline Index col() const { return IsRowMajor ? index() : m_outer; } - - EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; } - -protected: - const EvaluatorType& m_eval; - Index m_inner; - const Index m_outer; - const Index m_end; -}; - -// For iterator-based evaluator, inner-iterator is already implemented as -// evaluator<>::InnerIterator -template<typename XprType> -class inner_iterator_selector<XprType, IteratorBased> - : public evaluator<XprType>::InnerIterator -{ -protected: - typedef typename evaluator<XprType>::InnerIterator Base; - typedef evaluator<XprType> EvaluatorType; - -public: - EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &/*innerSize*/) - : Base(eval, outerId) - {} -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COREITERATORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h b/external/eigen/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h deleted file mode 100644 index 8b8de838..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h +++ /dev/null @@ -1,189 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CWISE_BINARY_OP_H -#define EIGEN_CWISE_BINARY_OP_H - -namespace Eigen { - -namespace internal { -template<typename BinaryOp, typename Lhs, typename Rhs> -struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > -{ - // we must not inherit from traits<Lhs> since it has - // the potential to cause problems with MSVC - typedef typename remove_all<Lhs>::type Ancestor; - typedef typename traits<Ancestor>::XprKind XprKind; - enum { - RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime, - ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime, - MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime, - MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime - }; - - // even though we require Lhs and Rhs to have the same scalar type (see CwiseBinaryOp constructor), - // we still want to handle the case when the result type is different. - typedef typename result_of< - BinaryOp( - const typename Lhs::Scalar&, - const typename Rhs::Scalar& - ) - >::type Scalar; - typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind, - typename traits<Rhs>::StorageKind, - BinaryOp>::ret StorageKind; - typedef typename promote_index_type<typename traits<Lhs>::StorageIndex, - typename traits<Rhs>::StorageIndex>::type StorageIndex; - typedef typename Lhs::Nested LhsNested; - typedef typename Rhs::Nested RhsNested; - typedef typename remove_reference<LhsNested>::type _LhsNested; - typedef typename remove_reference<RhsNested>::type _RhsNested; - enum { - Flags = cwise_promote_storage_order<typename traits<Lhs>::StorageKind,typename traits<Rhs>::StorageKind,_LhsNested::Flags & RowMajorBit,_RhsNested::Flags & RowMajorBit>::value - }; -}; -} // end namespace internal - -template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind> -class CwiseBinaryOpImpl; - -/** \class CwiseBinaryOp - * \ingroup Core_Module - * - * \brief Generic expression where a coefficient-wise binary operator is applied to two expressions - * - * \tparam BinaryOp template functor implementing the operator - * \tparam LhsType the type of the left-hand side - * \tparam RhsType the type of the right-hand side - * - * This class represents an expression where a coefficient-wise binary operator is applied to two expressions. - * It is the return type of binary operators, by which we mean only those binary operators where - * both the left-hand side and the right-hand side are Eigen expressions. - * For example, the return type of matrix1+matrix2 is a CwiseBinaryOp. - * - * Most of the time, this is the only way that it is used, so you typically don't have to name - * CwiseBinaryOp types explicitly. - * - * \sa MatrixBase::binaryExpr(const MatrixBase<OtherDerived> &,const CustomBinaryOp &) const, class CwiseUnaryOp, class CwiseNullaryOp - */ -template<typename BinaryOp, typename LhsType, typename RhsType> -class CwiseBinaryOp : - public CwiseBinaryOpImpl< - BinaryOp, LhsType, RhsType, - typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind, - typename internal::traits<RhsType>::StorageKind, - BinaryOp>::ret>, - internal::no_assignment_operator -{ - public: - - typedef typename internal::remove_all<BinaryOp>::type Functor; - typedef typename internal::remove_all<LhsType>::type Lhs; - typedef typename internal::remove_all<RhsType>::type Rhs; - - typedef typename CwiseBinaryOpImpl< - BinaryOp, LhsType, RhsType, - typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind, - typename internal::traits<Rhs>::StorageKind, - BinaryOp>::ret>::Base Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp) - - typedef typename internal::ref_selector<LhsType>::type LhsNested; - typedef typename internal::ref_selector<RhsType>::type RhsNested; - typedef typename internal::remove_reference<LhsNested>::type _LhsNested; - typedef typename internal::remove_reference<RhsNested>::type _RhsNested; - -#if EIGEN_COMP_MSVC && EIGEN_HAS_CXX11 - //Required for Visual Studio or the Copy constructor will probably not get inlined! - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CwiseBinaryOp(const CwiseBinaryOp<BinaryOp,LhsType,RhsType>&) = default; -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CwiseBinaryOp(const Lhs& aLhs, const Rhs& aRhs, const BinaryOp& func = BinaryOp()) - : m_lhs(aLhs), m_rhs(aRhs), m_functor(func) - { - EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename Rhs::Scalar); - // require the sizes to match - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs) - eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index rows() const { - // return the fixed size type if available to enable compile time optimizations - if (internal::traits<typename internal::remove_all<LhsNested>::type>::RowsAtCompileTime==Dynamic) - return m_rhs.rows(); - else - return m_lhs.rows(); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index cols() const { - // return the fixed size type if available to enable compile time optimizations - if (internal::traits<typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime==Dynamic) - return m_rhs.cols(); - else - return m_lhs.cols(); - } - - /** \returns the left hand side nested expression */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const _LhsNested& lhs() const { return m_lhs; } - /** \returns the right hand side nested expression */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const _RhsNested& rhs() const { return m_rhs; } - /** \returns the functor representing the binary operation */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const BinaryOp& functor() const { return m_functor; } - - protected: - LhsNested m_lhs; - RhsNested m_rhs; - const BinaryOp m_functor; -}; - -// Generic API dispatcher -template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind> -class CwiseBinaryOpImpl - : public internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type -{ -public: - typedef typename internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type Base; -}; - -/** replaces \c *this by \c *this - \a other. - * - * \returns a reference to \c *this - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & -MatrixBase<Derived>::operator-=(const MatrixBase<OtherDerived> &other) -{ - call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -/** replaces \c *this by \c *this + \a other. - * - * \returns a reference to \c *this - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & -MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other) -{ - call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -} // end namespace Eigen - -#endif // EIGEN_CWISE_BINARY_OP_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/CwiseNullaryOp.h b/external/eigen/include/eigen3/Eigen/src/Core/CwiseNullaryOp.h deleted file mode 100644 index ddac9df7..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/CwiseNullaryOp.h +++ /dev/null @@ -1,922 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CWISE_NULLARY_OP_H -#define EIGEN_CWISE_NULLARY_OP_H - -namespace Eigen { - -namespace internal { -template<typename NullaryOp, typename PlainObjectType> -struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType> -{ - enum { - Flags = traits<PlainObjectType>::Flags & RowMajorBit - }; -}; - -} // namespace internal - -/** \class CwiseNullaryOp - * \ingroup Core_Module - * - * \brief Generic expression of a matrix where all coefficients are defined by a functor - * - * \tparam NullaryOp template functor implementing the operator - * \tparam PlainObjectType the underlying plain matrix/array type - * - * This class represents an expression of a generic nullary operator. - * It is the return type of the Ones(), Zero(), Constant(), Identity() and Random() methods, - * and most of the time this is the only way it is used. - * - * However, if you want to write a function returning such an expression, you - * will need to use this class. - * - * The functor NullaryOp must expose one of the following method: - <table class="manual"> - <tr ><td>\c operator()() </td><td>if the procedural generation does not depend on the coefficient entries (e.g., random numbers)</td></tr> - <tr class="alt"><td>\c operator()(Index i)</td><td>if the procedural generation makes sense for vectors only and that it depends on the coefficient index \c i (e.g., linspace) </td></tr> - <tr ><td>\c operator()(Index i,Index j)</td><td>if the procedural generation depends on the matrix coordinates \c i, \c j (e.g., to generate a checkerboard with 0 and 1)</td></tr> - </table> - * It is also possible to expose the last two operators if the generation makes sense for matrices but can be optimized for vectors. - * - * See DenseBase::NullaryExpr(Index,const CustomNullaryOp&) for an example binding - * C++11 random number generators. - * - * A nullary expression can also be used to implement custom sophisticated matrix manipulations - * that cannot be covered by the existing set of natively supported matrix manipulations. - * See this \ref TopicCustomizing_NullaryExpr "page" for some examples and additional explanations - * on the behavior of CwiseNullaryOp. - * - * \sa class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr - */ -template<typename NullaryOp, typename PlainObjectType> -class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator -{ - public: - - typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp) - - EIGEN_DEVICE_FUNC - CwiseNullaryOp(Index rows, Index cols, const NullaryOp& func = NullaryOp()) - : m_rows(rows), m_cols(cols), m_functor(func) - { - eigen_assert(rows >= 0 - && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) - && cols >= 0 - && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index rows() const { return m_rows.value(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index cols() const { return m_cols.value(); } - - /** \returns the functor representing the nullary operation */ - EIGEN_DEVICE_FUNC - const NullaryOp& functor() const { return m_functor; } - - protected: - const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows; - const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols; - const NullaryOp m_functor; -}; - - -/** \returns an expression of a matrix defined by a custom functor \a func - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used - * instead. - * - * The template parameter \a CustomNullaryOp is the type of the functor. - * - * \sa class CwiseNullaryOp - */ -template<typename Derived> -template<typename CustomNullaryOp> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const CwiseNullaryOp<CustomNullaryOp,typename DenseBase<Derived>::PlainObject> -#else -const CwiseNullaryOp<CustomNullaryOp,PlainObject> -#endif -DenseBase<Derived>::NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func) -{ - return CwiseNullaryOp<CustomNullaryOp, PlainObject>(rows, cols, func); -} - -/** \returns an expression of a matrix defined by a custom functor \a func - * - * The parameter \a size is the size of the returned vector. - * Must be compatible with this MatrixBase type. - * - * \only_for_vectors - * - * This variant is meant to be used for dynamic-size vector types. For fixed-size types, - * it is redundant to pass \a size as argument, so Zero() should be used - * instead. - * - * The template parameter \a CustomNullaryOp is the type of the functor. - * - * Here is an example with C++11 random generators: \include random_cpp11.cpp - * Output: \verbinclude random_cpp11.out - * - * \sa class CwiseNullaryOp - */ -template<typename Derived> -template<typename CustomNullaryOp> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject> -#else -const CwiseNullaryOp<CustomNullaryOp, PlainObject> -#endif -DenseBase<Derived>::NullaryExpr(Index size, const CustomNullaryOp& func) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, PlainObject>(1, size, func); - else return CwiseNullaryOp<CustomNullaryOp, PlainObject>(size, 1, func); -} - -/** \returns an expression of a matrix defined by a custom functor \a func - * - * This variant is only for fixed-size DenseBase types. For dynamic-size types, you - * need to use the variants taking size arguments. - * - * The template parameter \a CustomNullaryOp is the type of the functor. - * - * \sa class CwiseNullaryOp - */ -template<typename Derived> -template<typename CustomNullaryOp> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject> -#else -const CwiseNullaryOp<CustomNullaryOp, PlainObject> -#endif -DenseBase<Derived>::NullaryExpr(const CustomNullaryOp& func) -{ - return CwiseNullaryOp<CustomNullaryOp, PlainObject>(RowsAtCompileTime, ColsAtCompileTime, func); -} - -/** \returns an expression of a constant matrix of value \a value - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this DenseBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used - * instead. - * - * The template parameter \a CustomNullaryOp is the type of the functor. - * - * \sa class CwiseNullaryOp - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Constant(Index rows, Index cols, const Scalar& value) -{ - return DenseBase<Derived>::NullaryExpr(rows, cols, internal::scalar_constant_op<Scalar>(value)); -} - -/** \returns an expression of a constant matrix of value \a value - * - * The parameter \a size is the size of the returned vector. - * Must be compatible with this DenseBase type. - * - * \only_for_vectors - * - * This variant is meant to be used for dynamic-size vector types. For fixed-size types, - * it is redundant to pass \a size as argument, so Zero() should be used - * instead. - * - * The template parameter \a CustomNullaryOp is the type of the functor. - * - * \sa class CwiseNullaryOp - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Constant(Index size, const Scalar& value) -{ - return DenseBase<Derived>::NullaryExpr(size, internal::scalar_constant_op<Scalar>(value)); -} - -/** \returns an expression of a constant matrix of value \a value - * - * This variant is only for fixed-size DenseBase types. For dynamic-size types, you - * need to use the variants taking size arguments. - * - * The template parameter \a CustomNullaryOp is the type of the functor. - * - * \sa class CwiseNullaryOp - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Constant(const Scalar& value) -{ - EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) - return DenseBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_constant_op<Scalar>(value)); -} - -/** \deprecated because of accuracy loss. In Eigen 3.3, it is an alias for LinSpaced(Index,const Scalar&,const Scalar&) - * - * \only_for_vectors - * - * Example: \include DenseBase_LinSpaced_seq_deprecated.cpp - * Output: \verbinclude DenseBase_LinSpaced_seq_deprecated.out - * - * \sa LinSpaced(Index,const Scalar&, const Scalar&), setLinSpaced(Index,const Scalar&,const Scalar&) - */ -template<typename Derived> -EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType -DenseBase<Derived>::LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return DenseBase<Derived>::NullaryExpr(size, internal::linspaced_op<Scalar>(low,high,size)); -} - -/** \deprecated because of accuracy loss. In Eigen 3.3, it is an alias for LinSpaced(const Scalar&,const Scalar&) - * - * \sa LinSpaced(const Scalar&, const Scalar&) - */ -template<typename Derived> -EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType -DenseBase<Derived>::LinSpaced(Sequential_t, const Scalar& low, const Scalar& high) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) - return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar>(low,high,Derived::SizeAtCompileTime)); -} - -/** - * \brief Sets a linearly spaced vector. - * - * The function generates 'size' equally spaced values in the closed interval [low,high]. - * When size is set to 1, a vector of length 1 containing 'high' is returned. - * - * \only_for_vectors - * - * Example: \include DenseBase_LinSpaced.cpp - * Output: \verbinclude DenseBase_LinSpaced.out - * - * For integer scalar types, an even spacing is possible if and only if the length of the range, - * i.e., \c high-low is a scalar multiple of \c size-1, or if \c size is a scalar multiple of the - * number of values \c high-low+1 (meaning each value can be repeated the same number of time). - * If one of these two considions is not satisfied, then \c high is lowered to the largest value - * satisfying one of this constraint. - * Here are some examples: - * - * Example: \include DenseBase_LinSpacedInt.cpp - * Output: \verbinclude DenseBase_LinSpacedInt.out - * - * \sa setLinSpaced(Index,const Scalar&,const Scalar&), CwiseNullaryOp - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType -DenseBase<Derived>::LinSpaced(Index size, const Scalar& low, const Scalar& high) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return DenseBase<Derived>::NullaryExpr(size, internal::linspaced_op<Scalar>(low,high,size)); -} - -/** - * \copydoc DenseBase::LinSpaced(Index, const Scalar&, const Scalar&) - * Special version for fixed size types which does not require the size parameter. - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType -DenseBase<Derived>::LinSpaced(const Scalar& low, const Scalar& high) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) - return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar>(low,high,Derived::SizeAtCompileTime)); -} - -/** \returns true if all coefficients in this matrix are approximately equal to \a val, to within precision \a prec */ -template<typename Derived> -EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApproxToConstant -(const Scalar& val, const RealScalar& prec) const -{ - typename internal::nested_eval<Derived,1>::type self(derived()); - for(Index j = 0; j < cols(); ++j) - for(Index i = 0; i < rows(); ++i) - if(!internal::isApprox(self.coeff(i, j), val, prec)) - return false; - return true; -} - -/** This is just an alias for isApproxToConstant(). - * - * \returns true if all coefficients in this matrix are approximately equal to \a value, to within precision \a prec */ -template<typename Derived> -EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isConstant -(const Scalar& val, const RealScalar& prec) const -{ - return isApproxToConstant(val, prec); -} - -/** Alias for setConstant(): sets all coefficients in this expression to \a val. - * - * \sa setConstant(), Constant(), class CwiseNullaryOp - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void DenseBase<Derived>::fill(const Scalar& val) -{ - setConstant(val); -} - -/** Sets all coefficients in this expression to value \a val. - * - * \sa fill(), setConstant(Index,const Scalar&), setConstant(Index,Index,const Scalar&), setZero(), setOnes(), Constant(), class CwiseNullaryOp, setZero(), setOnes() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setConstant(const Scalar& val) -{ - return derived() = Constant(rows(), cols(), val); -} - -/** Resizes to the given \a size, and sets all coefficients in this expression to the given value \a val. - * - * \only_for_vectors - * - * Example: \include Matrix_setConstant_int.cpp - * Output: \verbinclude Matrix_setConstant_int.out - * - * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&) - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& -PlainObjectBase<Derived>::setConstant(Index size, const Scalar& val) -{ - resize(size); - return setConstant(val); -} - -/** Resizes to the given size, and sets all coefficients in this expression to the given value \a val. - * - * \param rows the new number of rows - * \param cols the new number of columns - * \param val the value to which all coefficients are set - * - * Example: \include Matrix_setConstant_int_int.cpp - * Output: \verbinclude Matrix_setConstant_int_int.out - * - * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&) - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& -PlainObjectBase<Derived>::setConstant(Index rows, Index cols, const Scalar& val) -{ - resize(rows, cols); - return setConstant(val); -} - -/** - * \brief Sets a linearly spaced vector. - * - * The function generates 'size' equally spaced values in the closed interval [low,high]. - * When size is set to 1, a vector of length 1 containing 'high' is returned. - * - * \only_for_vectors - * - * Example: \include DenseBase_setLinSpaced.cpp - * Output: \verbinclude DenseBase_setLinSpaced.out - * - * For integer scalar types, do not miss the explanations on the definition - * of \link LinSpaced(Index,const Scalar&,const Scalar&) even spacing \endlink. - * - * \sa LinSpaced(Index,const Scalar&,const Scalar&), CwiseNullaryOp - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(Index newSize, const Scalar& low, const Scalar& high) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low,high,newSize)); -} - -/** - * \brief Sets a linearly spaced vector. - * - * The function fills \c *this with equally spaced values in the closed interval [low,high]. - * When size is set to 1, a vector of length 1 containing 'high' is returned. - * - * \only_for_vectors - * - * For integer scalar types, do not miss the explanations on the definition - * of \link LinSpaced(Index,const Scalar&,const Scalar&) even spacing \endlink. - * - * \sa LinSpaced(Index,const Scalar&,const Scalar&), setLinSpaced(Index, const Scalar&, const Scalar&), CwiseNullaryOp - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(const Scalar& low, const Scalar& high) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return setLinSpaced(size(), low, high); -} - -// zero: - -/** \returns an expression of a zero matrix. - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used - * instead. - * - * Example: \include MatrixBase_zero_int_int.cpp - * Output: \verbinclude MatrixBase_zero_int_int.out - * - * \sa Zero(), Zero(Index) - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Zero(Index rows, Index cols) -{ - return Constant(rows, cols, Scalar(0)); -} - -/** \returns an expression of a zero vector. - * - * The parameter \a size is the size of the returned vector. - * Must be compatible with this MatrixBase type. - * - * \only_for_vectors - * - * This variant is meant to be used for dynamic-size vector types. For fixed-size types, - * it is redundant to pass \a size as argument, so Zero() should be used - * instead. - * - * Example: \include MatrixBase_zero_int.cpp - * Output: \verbinclude MatrixBase_zero_int.out - * - * \sa Zero(), Zero(Index,Index) - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Zero(Index size) -{ - return Constant(size, Scalar(0)); -} - -/** \returns an expression of a fixed-size zero matrix or vector. - * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you - * need to use the variants taking size arguments. - * - * Example: \include MatrixBase_zero.cpp - * Output: \verbinclude MatrixBase_zero.out - * - * \sa Zero(Index), Zero(Index,Index) - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Zero() -{ - return Constant(Scalar(0)); -} - -/** \returns true if *this is approximately equal to the zero matrix, - * within the precision given by \a prec. - * - * Example: \include MatrixBase_isZero.cpp - * Output: \verbinclude MatrixBase_isZero.out - * - * \sa class CwiseNullaryOp, Zero() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isZero(const RealScalar& prec) const -{ - typename internal::nested_eval<Derived,1>::type self(derived()); - for(Index j = 0; j < cols(); ++j) - for(Index i = 0; i < rows(); ++i) - if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<Scalar>(1), prec)) - return false; - return true; -} - -/** Sets all coefficients in this expression to zero. - * - * Example: \include MatrixBase_setZero.cpp - * Output: \verbinclude MatrixBase_setZero.out - * - * \sa class CwiseNullaryOp, Zero() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setZero() -{ - return setConstant(Scalar(0)); -} - -/** Resizes to the given \a size, and sets all coefficients in this expression to zero. - * - * \only_for_vectors - * - * Example: \include Matrix_setZero_int.cpp - * Output: \verbinclude Matrix_setZero_int.out - * - * \sa DenseBase::setZero(), setZero(Index,Index), class CwiseNullaryOp, DenseBase::Zero() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& -PlainObjectBase<Derived>::setZero(Index newSize) -{ - resize(newSize); - return setConstant(Scalar(0)); -} - -/** Resizes to the given size, and sets all coefficients in this expression to zero. - * - * \param rows the new number of rows - * \param cols the new number of columns - * - * Example: \include Matrix_setZero_int_int.cpp - * Output: \verbinclude Matrix_setZero_int_int.out - * - * \sa DenseBase::setZero(), setZero(Index), class CwiseNullaryOp, DenseBase::Zero() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& -PlainObjectBase<Derived>::setZero(Index rows, Index cols) -{ - resize(rows, cols); - return setConstant(Scalar(0)); -} - -// ones: - -/** \returns an expression of a matrix where all coefficients equal one. - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so Ones() should be used - * instead. - * - * Example: \include MatrixBase_ones_int_int.cpp - * Output: \verbinclude MatrixBase_ones_int_int.out - * - * \sa Ones(), Ones(Index), isOnes(), class Ones - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Ones(Index rows, Index cols) -{ - return Constant(rows, cols, Scalar(1)); -} - -/** \returns an expression of a vector where all coefficients equal one. - * - * The parameter \a newSize is the size of the returned vector. - * Must be compatible with this MatrixBase type. - * - * \only_for_vectors - * - * This variant is meant to be used for dynamic-size vector types. For fixed-size types, - * it is redundant to pass \a size as argument, so Ones() should be used - * instead. - * - * Example: \include MatrixBase_ones_int.cpp - * Output: \verbinclude MatrixBase_ones_int.out - * - * \sa Ones(), Ones(Index,Index), isOnes(), class Ones - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Ones(Index newSize) -{ - return Constant(newSize, Scalar(1)); -} - -/** \returns an expression of a fixed-size matrix or vector where all coefficients equal one. - * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you - * need to use the variants taking size arguments. - * - * Example: \include MatrixBase_ones.cpp - * Output: \verbinclude MatrixBase_ones.out - * - * \sa Ones(Index), Ones(Index,Index), isOnes(), class Ones - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType -DenseBase<Derived>::Ones() -{ - return Constant(Scalar(1)); -} - -/** \returns true if *this is approximately equal to the matrix where all coefficients - * are equal to 1, within the precision given by \a prec. - * - * Example: \include MatrixBase_isOnes.cpp - * Output: \verbinclude MatrixBase_isOnes.out - * - * \sa class CwiseNullaryOp, Ones() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isOnes -(const RealScalar& prec) const -{ - return isApproxToConstant(Scalar(1), prec); -} - -/** Sets all coefficients in this expression to one. - * - * Example: \include MatrixBase_setOnes.cpp - * Output: \verbinclude MatrixBase_setOnes.out - * - * \sa class CwiseNullaryOp, Ones() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setOnes() -{ - return setConstant(Scalar(1)); -} - -/** Resizes to the given \a newSize, and sets all coefficients in this expression to one. - * - * \only_for_vectors - * - * Example: \include Matrix_setOnes_int.cpp - * Output: \verbinclude Matrix_setOnes_int.out - * - * \sa MatrixBase::setOnes(), setOnes(Index,Index), class CwiseNullaryOp, MatrixBase::Ones() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& -PlainObjectBase<Derived>::setOnes(Index newSize) -{ - resize(newSize); - return setConstant(Scalar(1)); -} - -/** Resizes to the given size, and sets all coefficients in this expression to one. - * - * \param rows the new number of rows - * \param cols the new number of columns - * - * Example: \include Matrix_setOnes_int_int.cpp - * Output: \verbinclude Matrix_setOnes_int_int.out - * - * \sa MatrixBase::setOnes(), setOnes(Index), class CwiseNullaryOp, MatrixBase::Ones() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& -PlainObjectBase<Derived>::setOnes(Index rows, Index cols) -{ - resize(rows, cols); - return setConstant(Scalar(1)); -} - -// Identity: - -/** \returns an expression of the identity matrix (not necessarily square). - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so Identity() should be used - * instead. - * - * Example: \include MatrixBase_identity_int_int.cpp - * Output: \verbinclude MatrixBase_identity_int_int.out - * - * \sa Identity(), setIdentity(), isIdentity() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType -MatrixBase<Derived>::Identity(Index rows, Index cols) -{ - return DenseBase<Derived>::NullaryExpr(rows, cols, internal::scalar_identity_op<Scalar>()); -} - -/** \returns an expression of the identity matrix (not necessarily square). - * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you - * need to use the variant taking size arguments. - * - * Example: \include MatrixBase_identity.cpp - * Output: \verbinclude MatrixBase_identity.out - * - * \sa Identity(Index,Index), setIdentity(), isIdentity() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType -MatrixBase<Derived>::Identity() -{ - EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) - return MatrixBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_identity_op<Scalar>()); -} - -/** \returns true if *this is approximately equal to the identity matrix - * (not necessarily square), - * within the precision given by \a prec. - * - * Example: \include MatrixBase_isIdentity.cpp - * Output: \verbinclude MatrixBase_isIdentity.out - * - * \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), setIdentity() - */ -template<typename Derived> -bool MatrixBase<Derived>::isIdentity -(const RealScalar& prec) const -{ - typename internal::nested_eval<Derived,1>::type self(derived()); - for(Index j = 0; j < cols(); ++j) - { - for(Index i = 0; i < rows(); ++i) - { - if(i == j) - { - if(!internal::isApprox(self.coeff(i, j), static_cast<Scalar>(1), prec)) - return false; - } - else - { - if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<RealScalar>(1), prec)) - return false; - } - } - } - return true; -} - -namespace internal { - -template<typename Derived, bool Big = (Derived::SizeAtCompileTime>=16)> -struct setIdentity_impl -{ - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Derived& run(Derived& m) - { - return m = Derived::Identity(m.rows(), m.cols()); - } -}; - -template<typename Derived> -struct setIdentity_impl<Derived, true> -{ - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Derived& run(Derived& m) - { - m.setZero(); - const Index size = numext::mini(m.rows(), m.cols()); - for(Index i = 0; i < size; ++i) m.coeffRef(i,i) = typename Derived::Scalar(1); - return m; - } -}; - -} // end namespace internal - -/** Writes the identity expression (not necessarily square) into *this. - * - * Example: \include MatrixBase_setIdentity.cpp - * Output: \verbinclude MatrixBase_setIdentity.out - * - * \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), isIdentity() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity() -{ - return internal::setIdentity_impl<Derived>::run(derived()); -} - -/** \brief Resizes to the given size, and writes the identity expression (not necessarily square) into *this. - * - * \param rows the new number of rows - * \param cols the new number of columns - * - * Example: \include Matrix_setIdentity_int_int.cpp - * Output: \verbinclude Matrix_setIdentity_int_int.out - * - * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Identity() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity(Index rows, Index cols) -{ - derived().resize(rows, cols); - return setIdentity(); -} - -/** \returns an expression of the i-th unit (basis) vector. - * - * \only_for_vectors - * - * \sa MatrixBase::Unit(Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(Index newSize, Index i) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i); -} - -/** \returns an expression of the i-th unit (basis) vector. - * - * \only_for_vectors - * - * This variant is for fixed-size vector only. - * - * \sa MatrixBase::Unit(Index,Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(Index i) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return BasisReturnType(SquareMatrixType::Identity(),i); -} - -/** \returns an expression of the X axis unit vector (1{,0}^*) - * - * \only_for_vectors - * - * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitX() -{ return Derived::Unit(0); } - -/** \returns an expression of the Y axis unit vector (0,1{,0}^*) - * - * \only_for_vectors - * - * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitY() -{ return Derived::Unit(1); } - -/** \returns an expression of the Z axis unit vector (0,0,1{,0}^*) - * - * \only_for_vectors - * - * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitZ() -{ return Derived::Unit(2); } - -/** \returns an expression of the W axis unit vector (0,0,0,1) - * - * \only_for_vectors - * - * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitW() -{ return Derived::Unit(3); } - -/** \brief Set the coefficients of \c *this to the i-th unit (basis) vector - * - * \param i index of the unique coefficient to be set to 1 - * - * \only_for_vectors - * - * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Unit(Index,Index) - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setUnit(Index i) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - eigen_assert(i<size()); - derived().setZero(); - derived().coeffRef(i) = Scalar(1); - return derived(); -} - -/** \brief Resizes to the given \a newSize, and writes the i-th unit (basis) vector into *this. - * - * \param newSize the new size of the vector - * \param i index of the unique coefficient to be set to 1 - * - * \only_for_vectors - * - * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Unit(Index,Index) - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setUnit(Index newSize, Index i) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - eigen_assert(i<newSize); - derived().resize(newSize); - return setUnit(i); -} - -} // end namespace Eigen - -#endif // EIGEN_CWISE_NULLARY_OP_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/CwiseTernaryOp.h b/external/eigen/include/eigen3/Eigen/src/Core/CwiseTernaryOp.h deleted file mode 100644 index 9f3576fe..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/CwiseTernaryOp.h +++ /dev/null @@ -1,197 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CWISE_TERNARY_OP_H -#define EIGEN_CWISE_TERNARY_OP_H - -namespace Eigen { - -namespace internal { -template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3> -struct traits<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > { - // we must not inherit from traits<Arg1> since it has - // the potential to cause problems with MSVC - typedef typename remove_all<Arg1>::type Ancestor; - typedef typename traits<Ancestor>::XprKind XprKind; - enum { - RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime, - ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime, - MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime, - MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime - }; - - // even though we require Arg1, Arg2, and Arg3 to have the same scalar type - // (see CwiseTernaryOp constructor), - // we still want to handle the case when the result type is different. - typedef typename result_of<TernaryOp( - const typename Arg1::Scalar&, const typename Arg2::Scalar&, - const typename Arg3::Scalar&)>::type Scalar; - - typedef typename internal::traits<Arg1>::StorageKind StorageKind; - typedef typename internal::traits<Arg1>::StorageIndex StorageIndex; - - typedef typename Arg1::Nested Arg1Nested; - typedef typename Arg2::Nested Arg2Nested; - typedef typename Arg3::Nested Arg3Nested; - typedef typename remove_reference<Arg1Nested>::type _Arg1Nested; - typedef typename remove_reference<Arg2Nested>::type _Arg2Nested; - typedef typename remove_reference<Arg3Nested>::type _Arg3Nested; - enum { Flags = _Arg1Nested::Flags & RowMajorBit }; -}; -} // end namespace internal - -template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3, - typename StorageKind> -class CwiseTernaryOpImpl; - -/** \class CwiseTernaryOp - * \ingroup Core_Module - * - * \brief Generic expression where a coefficient-wise ternary operator is - * applied to two expressions - * - * \tparam TernaryOp template functor implementing the operator - * \tparam Arg1Type the type of the first argument - * \tparam Arg2Type the type of the second argument - * \tparam Arg3Type the type of the third argument - * - * This class represents an expression where a coefficient-wise ternary - * operator is applied to three expressions. - * It is the return type of ternary operators, by which we mean only those - * ternary operators where - * all three arguments are Eigen expressions. - * For example, the return type of betainc(matrix1, matrix2, matrix3) is a - * CwiseTernaryOp. - * - * Most of the time, this is the only way that it is used, so you typically - * don't have to name - * CwiseTernaryOp types explicitly. - * - * \sa MatrixBase::ternaryExpr(const MatrixBase<Argument2> &, const - * MatrixBase<Argument3> &, const CustomTernaryOp &) const, class CwiseBinaryOp, - * class CwiseUnaryOp, class CwiseNullaryOp - */ -template <typename TernaryOp, typename Arg1Type, typename Arg2Type, - typename Arg3Type> -class CwiseTernaryOp : public CwiseTernaryOpImpl< - TernaryOp, Arg1Type, Arg2Type, Arg3Type, - typename internal::traits<Arg1Type>::StorageKind>, - internal::no_assignment_operator -{ - public: - typedef typename internal::remove_all<Arg1Type>::type Arg1; - typedef typename internal::remove_all<Arg2Type>::type Arg2; - typedef typename internal::remove_all<Arg3Type>::type Arg3; - - typedef typename CwiseTernaryOpImpl< - TernaryOp, Arg1Type, Arg2Type, Arg3Type, - typename internal::traits<Arg1Type>::StorageKind>::Base Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseTernaryOp) - - typedef typename internal::ref_selector<Arg1Type>::type Arg1Nested; - typedef typename internal::ref_selector<Arg2Type>::type Arg2Nested; - typedef typename internal::ref_selector<Arg3Type>::type Arg3Nested; - typedef typename internal::remove_reference<Arg1Nested>::type _Arg1Nested; - typedef typename internal::remove_reference<Arg2Nested>::type _Arg2Nested; - typedef typename internal::remove_reference<Arg3Nested>::type _Arg3Nested; - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CwiseTernaryOp(const Arg1& a1, const Arg2& a2, - const Arg3& a3, - const TernaryOp& func = TernaryOp()) - : m_arg1(a1), m_arg2(a2), m_arg3(a3), m_functor(func) { - // require the sizes to match - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg2) - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg3) - - // The index types should match - EIGEN_STATIC_ASSERT((internal::is_same< - typename internal::traits<Arg1Type>::StorageKind, - typename internal::traits<Arg2Type>::StorageKind>::value), - STORAGE_KIND_MUST_MATCH) - EIGEN_STATIC_ASSERT((internal::is_same< - typename internal::traits<Arg1Type>::StorageKind, - typename internal::traits<Arg3Type>::StorageKind>::value), - STORAGE_KIND_MUST_MATCH) - - eigen_assert(a1.rows() == a2.rows() && a1.cols() == a2.cols() && - a1.rows() == a3.rows() && a1.cols() == a3.cols()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index rows() const { - // return the fixed size type if available to enable compile time - // optimizations - if (internal::traits<typename internal::remove_all<Arg1Nested>::type>:: - RowsAtCompileTime == Dynamic && - internal::traits<typename internal::remove_all<Arg2Nested>::type>:: - RowsAtCompileTime == Dynamic) - return m_arg3.rows(); - else if (internal::traits<typename internal::remove_all<Arg1Nested>::type>:: - RowsAtCompileTime == Dynamic && - internal::traits<typename internal::remove_all<Arg3Nested>::type>:: - RowsAtCompileTime == Dynamic) - return m_arg2.rows(); - else - return m_arg1.rows(); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index cols() const { - // return the fixed size type if available to enable compile time - // optimizations - if (internal::traits<typename internal::remove_all<Arg1Nested>::type>:: - ColsAtCompileTime == Dynamic && - internal::traits<typename internal::remove_all<Arg2Nested>::type>:: - ColsAtCompileTime == Dynamic) - return m_arg3.cols(); - else if (internal::traits<typename internal::remove_all<Arg1Nested>::type>:: - ColsAtCompileTime == Dynamic && - internal::traits<typename internal::remove_all<Arg3Nested>::type>:: - ColsAtCompileTime == Dynamic) - return m_arg2.cols(); - else - return m_arg1.cols(); - } - - /** \returns the first argument nested expression */ - EIGEN_DEVICE_FUNC - const _Arg1Nested& arg1() const { return m_arg1; } - /** \returns the first argument nested expression */ - EIGEN_DEVICE_FUNC - const _Arg2Nested& arg2() const { return m_arg2; } - /** \returns the third argument nested expression */ - EIGEN_DEVICE_FUNC - const _Arg3Nested& arg3() const { return m_arg3; } - /** \returns the functor representing the ternary operation */ - EIGEN_DEVICE_FUNC - const TernaryOp& functor() const { return m_functor; } - - protected: - Arg1Nested m_arg1; - Arg2Nested m_arg2; - Arg3Nested m_arg3; - const TernaryOp m_functor; -}; - -// Generic API dispatcher -template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3, - typename StorageKind> -class CwiseTernaryOpImpl - : public internal::generic_xpr_base< - CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >::type { - public: - typedef typename internal::generic_xpr_base< - CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >::type Base; -}; - -} // end namespace Eigen - -#endif // EIGEN_CWISE_TERNARY_OP_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/CwiseUnaryOp.h b/external/eigen/include/eigen3/Eigen/src/Core/CwiseUnaryOp.h deleted file mode 100644 index 1d2dd19f..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/CwiseUnaryOp.h +++ /dev/null @@ -1,103 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CWISE_UNARY_OP_H -#define EIGEN_CWISE_UNARY_OP_H - -namespace Eigen { - -namespace internal { -template<typename UnaryOp, typename XprType> -struct traits<CwiseUnaryOp<UnaryOp, XprType> > - : traits<XprType> -{ - typedef typename result_of< - UnaryOp(const typename XprType::Scalar&) - >::type Scalar; - typedef typename XprType::Nested XprTypeNested; - typedef typename remove_reference<XprTypeNested>::type _XprTypeNested; - enum { - Flags = _XprTypeNested::Flags & RowMajorBit - }; -}; -} - -template<typename UnaryOp, typename XprType, typename StorageKind> -class CwiseUnaryOpImpl; - -/** \class CwiseUnaryOp - * \ingroup Core_Module - * - * \brief Generic expression where a coefficient-wise unary operator is applied to an expression - * - * \tparam UnaryOp template functor implementing the operator - * \tparam XprType the type of the expression to which we are applying the unary operator - * - * This class represents an expression where a unary operator is applied to an expression. - * It is the return type of all operations taking exactly 1 input expression, regardless of the - * presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix - * is considered unary, because only the right-hand side is an expression, and its - * return type is a specialization of CwiseUnaryOp. - * - * Most of the time, this is the only way that it is used, so you typically don't have to name - * CwiseUnaryOp types explicitly. - * - * \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp - */ -template<typename UnaryOp, typename XprType> -class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>, internal::no_assignment_operator -{ - public: - - typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp) - typedef typename internal::ref_selector<XprType>::type XprTypeNested; - typedef typename internal::remove_all<XprType>::type NestedExpression; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) - : m_xpr(xpr), m_functor(func) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index rows() const { return m_xpr.rows(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index cols() const { return m_xpr.cols(); } - - /** \returns the functor representing the unary operation */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const UnaryOp& functor() const { return m_functor; } - - /** \returns the nested expression */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const typename internal::remove_all<XprTypeNested>::type& - nestedExpression() const { return m_xpr; } - - /** \returns the nested expression */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename internal::remove_all<XprTypeNested>::type& - nestedExpression() { return m_xpr; } - - protected: - XprTypeNested m_xpr; - const UnaryOp m_functor; -}; - -// Generic API dispatcher -template<typename UnaryOp, typename XprType, typename StorageKind> -class CwiseUnaryOpImpl - : public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type -{ -public: - typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base; -}; - -} // end namespace Eigen - -#endif // EIGEN_CWISE_UNARY_OP_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/CwiseUnaryView.h b/external/eigen/include/eigen3/Eigen/src/Core/CwiseUnaryView.h deleted file mode 100644 index ff3134d4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/CwiseUnaryView.h +++ /dev/null @@ -1,130 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CWISE_UNARY_VIEW_H -#define EIGEN_CWISE_UNARY_VIEW_H - -namespace Eigen { - -namespace internal { -template<typename ViewOp, typename MatrixType> -struct traits<CwiseUnaryView<ViewOp, MatrixType> > - : traits<MatrixType> -{ - typedef typename result_of< - ViewOp(const typename traits<MatrixType>::Scalar&) - >::type Scalar; - typedef typename MatrixType::Nested MatrixTypeNested; - typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested; - enum { - FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, - Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions - MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret, - // need to cast the sizeof's from size_t to int explicitly, otherwise: - // "error: no integral type can represent all of the enumerator values - InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic - ? int(Dynamic) - : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)), - OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic - ? int(Dynamic) - : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)) - }; -}; -} - -template<typename ViewOp, typename MatrixType, typename StorageKind> -class CwiseUnaryViewImpl; - -/** \class CwiseUnaryView - * \ingroup Core_Module - * - * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector - * - * \tparam ViewOp template functor implementing the view - * \tparam MatrixType the type of the matrix we are applying the unary operator - * - * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector. - * It is the return type of real() and imag(), and most of the time this is the only way it is used. - * - * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp - */ -template<typename ViewOp, typename MatrixType> -class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind> -{ - public: - - typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView) - typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested; - typedef typename internal::remove_all<MatrixType>::type NestedExpression; - - explicit inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp()) - : m_matrix(mat), m_functor(func) {} - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView) - - EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); } - EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); } - - /** \returns the functor representing unary operation */ - const ViewOp& functor() const { return m_functor; } - - /** \returns the nested expression */ - const typename internal::remove_all<MatrixTypeNested>::type& - nestedExpression() const { return m_matrix; } - - /** \returns the nested expression */ - typename internal::remove_reference<MatrixTypeNested>::type& - nestedExpression() { return m_matrix; } - - protected: - MatrixTypeNested m_matrix; - ViewOp m_functor; -}; - -// Generic API dispatcher -template<typename ViewOp, typename XprType, typename StorageKind> -class CwiseUnaryViewImpl - : public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type -{ -public: - typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base; -}; - -template<typename ViewOp, typename MatrixType> -class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense> - : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type -{ - public: - - typedef CwiseUnaryView<ViewOp, MatrixType> Derived; - typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base; - - EIGEN_DENSE_PUBLIC_INTERFACE(Derived) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl) - - EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); } - EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); } - - EIGEN_DEVICE_FUNC inline Index innerStride() const - { - return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar); - } - - EIGEN_DEVICE_FUNC inline Index outerStride() const - { - return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar); - } - protected: - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl) -}; - -} // end namespace Eigen - -#endif // EIGEN_CWISE_UNARY_VIEW_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/DenseBase.h b/external/eigen/include/eigen3/Eigen/src/Core/DenseBase.h deleted file mode 100644 index 59756a49..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/DenseBase.h +++ /dev/null @@ -1,661 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DENSEBASE_H -#define EIGEN_DENSEBASE_H - -namespace Eigen { - -namespace internal { - -// The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type. -// This dummy function simply aims at checking that at compile time. -static inline void check_DenseIndex_is_signed() { - EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE); -} - -} // end namespace internal - -/** \class DenseBase - * \ingroup Core_Module - * - * \brief Base class for all dense matrices, vectors, and arrays - * - * This class is the base that is inherited by all dense objects (matrix, vector, arrays, - * and related expression types). The common Eigen API for dense objects is contained in this class. - * - * \tparam Derived is the derived type, e.g., a matrix type or an expression. - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_DENSEBASE_PLUGIN. - * - * \sa \blank \ref TopicClassHierarchy - */ -template<typename Derived> class DenseBase -#ifndef EIGEN_PARSED_BY_DOXYGEN - : public DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value> -#else - : public DenseCoeffsBase<Derived,DirectWriteAccessors> -#endif // not EIGEN_PARSED_BY_DOXYGEN -{ - public: - - /** Inner iterator type to iterate over the coefficients of a row or column. - * \sa class InnerIterator - */ - typedef Eigen::InnerIterator<Derived> InnerIterator; - - typedef typename internal::traits<Derived>::StorageKind StorageKind; - - /** - * \brief The type used to store indices - * \details This typedef is relevant for types that store multiple indices such as - * PermutationMatrix or Transpositions, otherwise it defaults to Eigen::Index - * \sa \blank \ref TopicPreprocessorDirectives, Eigen::Index, SparseMatrixBase. - */ - typedef typename internal::traits<Derived>::StorageIndex StorageIndex; - - /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc. */ - typedef typename internal::traits<Derived>::Scalar Scalar; - - /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc. - * - * It is an alias for the Scalar type */ - typedef Scalar value_type; - - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value> Base; - - using Base::derived; - using Base::const_cast_derived; - using Base::rows; - using Base::cols; - using Base::size; - using Base::rowIndexByOuterInner; - using Base::colIndexByOuterInner; - using Base::coeff; - using Base::coeffByOuterInner; - using Base::operator(); - using Base::operator[]; - using Base::x; - using Base::y; - using Base::z; - using Base::w; - using Base::stride; - using Base::innerStride; - using Base::outerStride; - using Base::rowStride; - using Base::colStride; - typedef typename Base::CoeffReturnType CoeffReturnType; - - enum { - - RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, - /**< The number of rows at compile-time. This is just a copy of the value provided - * by the \a Derived type. If a value is not known at compile-time, - * it is set to the \a Dynamic constant. - * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */ - - ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, - /**< The number of columns at compile-time. This is just a copy of the value provided - * by the \a Derived type. If a value is not known at compile-time, - * it is set to the \a Dynamic constant. - * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ - - - SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime, - internal::traits<Derived>::ColsAtCompileTime>::ret), - /**< This is equal to the number of coefficients, i.e. the number of - * rows times the number of columns, or to \a Dynamic if this is not - * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ - - MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime, - /**< This value is equal to the maximum possible number of rows that this expression - * might have. If this expression might have an arbitrarily high number of rows, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime - */ - - MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime, - /**< This value is equal to the maximum possible number of columns that this expression - * might have. If this expression might have an arbitrarily high number of columns, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime - */ - - MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime, - internal::traits<Derived>::MaxColsAtCompileTime>::ret), - /**< This value is equal to the maximum possible number of coefficients that this expression - * might have. If this expression might have an arbitrarily high number of coefficients, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime - */ - - IsVectorAtCompileTime = internal::traits<Derived>::RowsAtCompileTime == 1 - || internal::traits<Derived>::ColsAtCompileTime == 1, - /**< This is set to true if either the number of rows or the number of - * columns is known at compile-time to be equal to 1. Indeed, in that case, - * we are dealing with a column-vector (if there is only one column) or with - * a row-vector (if there is only one row). */ - - NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2, - /**< This value is equal to Tensor::NumDimensions, i.e. 0 for scalars, 1 for vectors, - * and 2 for matrices. - */ - - Flags = internal::traits<Derived>::Flags, - /**< This stores expression \ref flags flags which may or may not be inherited by new expressions - * constructed from this one. See the \ref flags "list of flags". - */ - - IsRowMajor = int(Flags) & RowMajorBit, /**< True if this expression has row-major storage order. */ - - InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime) - : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), - - InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret, - OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret - }; - - typedef typename internal::find_best_packet<Scalar,SizeAtCompileTime>::type PacketScalar; - - enum { IsPlainObjectBase = 0 }; - - /** The plain matrix type corresponding to this expression. - * \sa PlainObject */ - typedef Matrix<typename internal::traits<Derived>::Scalar, - internal::traits<Derived>::RowsAtCompileTime, - internal::traits<Derived>::ColsAtCompileTime, - AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor), - internal::traits<Derived>::MaxRowsAtCompileTime, - internal::traits<Derived>::MaxColsAtCompileTime - > PlainMatrix; - - /** The plain array type corresponding to this expression. - * \sa PlainObject */ - typedef Array<typename internal::traits<Derived>::Scalar, - internal::traits<Derived>::RowsAtCompileTime, - internal::traits<Derived>::ColsAtCompileTime, - AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor), - internal::traits<Derived>::MaxRowsAtCompileTime, - internal::traits<Derived>::MaxColsAtCompileTime - > PlainArray; - - /** \brief The plain matrix or array type corresponding to this expression. - * - * This is not necessarily exactly the return type of eval(). In the case of plain matrices, - * the return type of eval() is a const reference to a matrix, not a matrix! It is however guaranteed - * that the return type of eval() is either PlainObject or const PlainObject&. - */ - typedef typename internal::conditional<internal::is_same<typename internal::traits<Derived>::XprKind,MatrixXpr >::value, - PlainMatrix, PlainArray>::type PlainObject; - - /** \returns the number of nonzero coefficients which is in practice the number - * of stored coefficients. */ - EIGEN_DEVICE_FUNC - inline Index nonZeros() const { return size(); } - - /** \returns the outer size. - * - * \note For a vector, this returns just 1. For a matrix (non-vector), this is the major dimension - * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of columns for a - * column-major matrix, and the number of rows for a row-major matrix. */ - EIGEN_DEVICE_FUNC - Index outerSize() const - { - return IsVectorAtCompileTime ? 1 - : int(IsRowMajor) ? this->rows() : this->cols(); - } - - /** \returns the inner size. - * - * \note For a vector, this is just the size. For a matrix (non-vector), this is the minor dimension - * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of rows for a - * column-major matrix, and the number of columns for a row-major matrix. */ - EIGEN_DEVICE_FUNC - Index innerSize() const - { - return IsVectorAtCompileTime ? this->size() - : int(IsRowMajor) ? this->cols() : this->rows(); - } - - /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are - * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does - * nothing else. - */ - EIGEN_DEVICE_FUNC - void resize(Index newSize) - { - EIGEN_ONLY_USED_FOR_DEBUG(newSize); - eigen_assert(newSize == this->size() - && "DenseBase::resize() does not actually allow to resize."); - } - /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are - * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does - * nothing else. - */ - EIGEN_DEVICE_FUNC - void resize(Index rows, Index cols) - { - EIGEN_ONLY_USED_FOR_DEBUG(rows); - EIGEN_ONLY_USED_FOR_DEBUG(cols); - eigen_assert(rows == this->rows() && cols == this->cols() - && "DenseBase::resize() does not actually allow to resize."); - } - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal Represents a matrix with all coefficients equal to one another*/ - typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType; - /** \internal \deprecated Represents a vector with linearly spaced coefficients that allows sequential access only. */ - EIGEN_DEPRECATED typedef CwiseNullaryOp<internal::linspaced_op<Scalar>,PlainObject> SequentialLinSpacedReturnType; - /** \internal Represents a vector with linearly spaced coefficients that allows random access. */ - typedef CwiseNullaryOp<internal::linspaced_op<Scalar>,PlainObject> RandomAccessLinSpacedReturnType; - /** \internal the return type of MatrixBase::eigenvalues() */ - typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType; - -#endif // not EIGEN_PARSED_BY_DOXYGEN - - /** Copies \a other into *this. \returns a reference to *this. */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator=(const DenseBase<OtherDerived>& other); - - /** Special case of the template operator=, in order to prevent the compiler - * from generating a default operator= (issue hit with g++ 4.1) - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator=(const DenseBase& other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - Derived& operator=(const EigenBase<OtherDerived> &other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - Derived& operator+=(const EigenBase<OtherDerived> &other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - Derived& operator-=(const EigenBase<OtherDerived> &other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - Derived& operator=(const ReturnByValue<OtherDerived>& func); - - /** \internal - * Copies \a other into *this without evaluating other. \returns a reference to *this. */ - template<typename OtherDerived> - /** \deprecated */ - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC - Derived& lazyAssign(const DenseBase<OtherDerived>& other); - - EIGEN_DEVICE_FUNC - CommaInitializer<Derived> operator<< (const Scalar& s); - - template<unsigned int Added,unsigned int Removed> - /** \deprecated it now returns \c *this */ - EIGEN_DEPRECATED - const Derived& flagged() const - { return derived(); } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other); - - typedef Transpose<Derived> TransposeReturnType; - EIGEN_DEVICE_FUNC - TransposeReturnType transpose(); - typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType; - EIGEN_DEVICE_FUNC - ConstTransposeReturnType transpose() const; - EIGEN_DEVICE_FUNC - void transposeInPlace(); - - EIGEN_DEVICE_FUNC static const ConstantReturnType - Constant(Index rows, Index cols, const Scalar& value); - EIGEN_DEVICE_FUNC static const ConstantReturnType - Constant(Index size, const Scalar& value); - EIGEN_DEVICE_FUNC static const ConstantReturnType - Constant(const Scalar& value); - - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType - LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high); - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType - LinSpaced(Sequential_t, const Scalar& low, const Scalar& high); - - EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType - LinSpaced(Index size, const Scalar& low, const Scalar& high); - EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType - LinSpaced(const Scalar& low, const Scalar& high); - - template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC - static const CwiseNullaryOp<CustomNullaryOp, PlainObject> - NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func); - template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC - static const CwiseNullaryOp<CustomNullaryOp, PlainObject> - NullaryExpr(Index size, const CustomNullaryOp& func); - template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC - static const CwiseNullaryOp<CustomNullaryOp, PlainObject> - NullaryExpr(const CustomNullaryOp& func); - - EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index rows, Index cols); - EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index size); - EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(); - EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index rows, Index cols); - EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index size); - EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(); - - EIGEN_DEVICE_FUNC void fill(const Scalar& value); - EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value); - EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high); - EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high); - EIGEN_DEVICE_FUNC Derived& setZero(); - EIGEN_DEVICE_FUNC Derived& setOnes(); - EIGEN_DEVICE_FUNC Derived& setRandom(); - - template<typename OtherDerived> EIGEN_DEVICE_FUNC - bool isApprox(const DenseBase<OtherDerived>& other, - const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - EIGEN_DEVICE_FUNC - bool isMuchSmallerThan(const RealScalar& other, - const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - template<typename OtherDerived> EIGEN_DEVICE_FUNC - bool isMuchSmallerThan(const DenseBase<OtherDerived>& other, - const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - - EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - - inline bool hasNaN() const; - inline bool allFinite() const; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator*=(const Scalar& other); - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator/=(const Scalar& other); - - typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType; - /** \returns the matrix or vector obtained by evaluating this expression. - * - * Notice that in the case of a plain matrix or vector (not an expression) this function just returns - * a const reference, in order to avoid a useless copy. - * - * \warning Be careful with eval() and the auto C++ keyword, as detailed in this \link TopicPitfalls_auto_keyword page \endlink. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE EvalReturnType eval() const - { - // Even though MSVC does not honor strong inlining when the return type - // is a dynamic matrix, we desperately need strong inlining for fixed - // size types on MSVC. - return typename internal::eval<Derived>::type(derived()); - } - - /** swaps *this with the expression \a other. - * - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void swap(const DenseBase<OtherDerived>& other) - { - EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); - eigen_assert(rows()==other.rows() && cols()==other.cols()); - call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>()); - } - - /** swaps *this with the matrix or array \a other. - * - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void swap(PlainObjectBase<OtherDerived>& other) - { - eigen_assert(rows()==other.rows() && cols()==other.cols()); - call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC inline const NestByValue<Derived> nestByValue() const; - EIGEN_DEVICE_FUNC inline const ForceAlignedAccess<Derived> forceAlignedAccess() const; - EIGEN_DEVICE_FUNC inline ForceAlignedAccess<Derived> forceAlignedAccess(); - template<bool Enable> EIGEN_DEVICE_FUNC - inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const; - template<bool Enable> EIGEN_DEVICE_FUNC - inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf(); - - EIGEN_DEVICE_FUNC Scalar sum() const; - EIGEN_DEVICE_FUNC Scalar mean() const; - EIGEN_DEVICE_FUNC Scalar trace() const; - - EIGEN_DEVICE_FUNC Scalar prod() const; - - EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const; - EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const; - - template<typename IndexType> EIGEN_DEVICE_FUNC - typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const; - template<typename IndexType> EIGEN_DEVICE_FUNC - typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const; - template<typename IndexType> EIGEN_DEVICE_FUNC - typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const; - template<typename IndexType> EIGEN_DEVICE_FUNC - typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const; - - template<typename BinaryOp> - EIGEN_DEVICE_FUNC - Scalar redux(const BinaryOp& func) const; - - template<typename Visitor> - EIGEN_DEVICE_FUNC - void visit(Visitor& func) const; - - /** \returns a WithFormat proxy object allowing to print a matrix the with given - * format \a fmt. - * - * See class IOFormat for some examples. - * - * \sa class IOFormat, class WithFormat - */ - inline const WithFormat<Derived> format(const IOFormat& fmt) const - { - return WithFormat<Derived>(derived(), fmt); - } - - /** \returns the unique coefficient of a 1x1 expression */ - EIGEN_DEVICE_FUNC - CoeffReturnType value() const - { - EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) - eigen_assert(this->rows() == 1 && this->cols() == 1); - return derived().coeff(0,0); - } - - EIGEN_DEVICE_FUNC bool all() const; - EIGEN_DEVICE_FUNC bool any() const; - EIGEN_DEVICE_FUNC Index count() const; - - typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType; - typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType; - typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType; - typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType; - - /** \returns a VectorwiseOp wrapper of *this for broadcasting and partial reductions - * - * Example: \include MatrixBase_rowwise.cpp - * Output: \verbinclude MatrixBase_rowwise.out - * - * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting - */ - //Code moved here due to a CUDA compiler bug - EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const { - return ConstRowwiseReturnType(derived()); - } - EIGEN_DEVICE_FUNC RowwiseReturnType rowwise(); - - /** \returns a VectorwiseOp wrapper of *this broadcasting and partial reductions - * - * Example: \include MatrixBase_colwise.cpp - * Output: \verbinclude MatrixBase_colwise.out - * - * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting - */ - EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const { - return ConstColwiseReturnType(derived()); - } - EIGEN_DEVICE_FUNC ColwiseReturnType colwise(); - - typedef CwiseNullaryOp<internal::scalar_random_op<Scalar>,PlainObject> RandomReturnType; - static const RandomReturnType Random(Index rows, Index cols); - static const RandomReturnType Random(Index size); - static const RandomReturnType Random(); - - template<typename ThenDerived,typename ElseDerived> - const Select<Derived,ThenDerived,ElseDerived> - select(const DenseBase<ThenDerived>& thenMatrix, - const DenseBase<ElseDerived>& elseMatrix) const; - - template<typename ThenDerived> - inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType> - select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const; - - template<typename ElseDerived> - inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived > - select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const; - - template<int p> RealScalar lpNorm() const; - - template<int RowFactor, int ColFactor> - EIGEN_DEVICE_FUNC - const Replicate<Derived,RowFactor,ColFactor> replicate() const; - /** - * \return an expression of the replication of \c *this - * - * Example: \include MatrixBase_replicate_int_int.cpp - * Output: \verbinclude MatrixBase_replicate_int_int.out - * - * \sa VectorwiseOp::replicate(), DenseBase::replicate<int,int>(), class Replicate - */ - //Code moved here due to a CUDA compiler bug - EIGEN_DEVICE_FUNC - const Replicate<Derived, Dynamic, Dynamic> replicate(Index rowFactor, Index colFactor) const - { - return Replicate<Derived, Dynamic, Dynamic>(derived(), rowFactor, colFactor); - } - - typedef Reverse<Derived, BothDirections> ReverseReturnType; - typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType; - EIGEN_DEVICE_FUNC ReverseReturnType reverse(); - /** This is the const version of reverse(). */ - //Code moved here due to a CUDA compiler bug - EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const - { - return ConstReverseReturnType(derived()); - } - EIGEN_DEVICE_FUNC void reverseInPlace(); - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** STL-like <a href="https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator">RandomAccessIterator</a> - * iterator type as returned by the begin() and end() methods. - */ - typedef random_access_iterator_type iterator; - /** This is the const version of iterator (aka read-only) */ - typedef random_access_iterator_type const_iterator; - #else - typedef typename internal::conditional< (Flags&DirectAccessBit)==DirectAccessBit, - internal::pointer_based_stl_iterator<Derived>, - internal::generic_randaccess_stl_iterator<Derived> - >::type iterator_type; - - typedef typename internal::conditional< (Flags&DirectAccessBit)==DirectAccessBit, - internal::pointer_based_stl_iterator<const Derived>, - internal::generic_randaccess_stl_iterator<const Derived> - >::type const_iterator_type; - - // Stl-style iterators are supported only for vectors. - - typedef typename internal::conditional< IsVectorAtCompileTime, - iterator_type, - void - >::type iterator; - - typedef typename internal::conditional< IsVectorAtCompileTime, - const_iterator_type, - void - >::type const_iterator; - #endif - - inline iterator begin(); - inline const_iterator begin() const; - inline const_iterator cbegin() const; - inline iterator end(); - inline const_iterator end() const; - inline const_iterator cend() const; - -#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase -#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND) -#define EIGEN_DOC_UNARY_ADDONS(X,Y) -# include "../plugins/CommonCwiseUnaryOps.h" -# include "../plugins/BlockMethods.h" -# include "../plugins/IndexedViewMethods.h" -# include "../plugins/ReshapedMethods.h" -# ifdef EIGEN_DENSEBASE_PLUGIN -# include EIGEN_DENSEBASE_PLUGIN -# endif -#undef EIGEN_CURRENT_STORAGE_BASE_CLASS -#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF -#undef EIGEN_DOC_UNARY_ADDONS - - // disable the use of evalTo for dense objects with a nice compilation error - template<typename Dest> - EIGEN_DEVICE_FUNC - inline void evalTo(Dest& ) const - { - EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS); - } - - protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase) - /** Default constructor. Do nothing. */ - EIGEN_DEVICE_FUNC DenseBase() - { - /* Just checks for self-consistency of the flags. - * Only do it when debugging Eigen, as this borders on paranoia and could slow compilation down - */ -#ifdef EIGEN_INTERNAL_DEBUGGING - EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor)) - && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))), - INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION) -#endif - } - - private: - EIGEN_DEVICE_FUNC explicit DenseBase(int); - EIGEN_DEVICE_FUNC DenseBase(int,int); - template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase<OtherDerived>&); -}; - -} // end namespace Eigen - -#endif // EIGEN_DENSEBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h b/external/eigen/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h deleted file mode 100644 index 463b471c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h +++ /dev/null @@ -1,685 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DENSECOEFFSBASE_H -#define EIGEN_DENSECOEFFSBASE_H - -namespace Eigen { - -namespace internal { -template<typename T> struct add_const_on_value_type_if_arithmetic -{ - typedef typename conditional<is_arithmetic<T>::value, T, typename add_const_on_value_type<T>::type>::type type; -}; -} - -/** \brief Base class providing read-only coefficient access to matrices and arrays. - * \ingroup Core_Module - * \tparam Derived Type of the derived class - * - * \note #ReadOnlyAccessors Constant indicating read-only access - * - * This class defines the \c operator() \c const function and friends, which can be used to read specific - * entries of a matrix or array. - * - * \sa DenseCoeffsBase<Derived, WriteAccessors>, DenseCoeffsBase<Derived, DirectAccessors>, - * \ref TopicClassHierarchy - */ -template<typename Derived> -class DenseCoeffsBase<Derived,ReadOnlyAccessors> : public EigenBase<Derived> -{ - public: - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename internal::packet_traits<Scalar>::type PacketScalar; - - // Explanation for this CoeffReturnType typedef. - // - This is the return type of the coeff() method. - // - The LvalueBit means exactly that we can offer a coeffRef() method, which means exactly that we can get references - // to coeffs, which means exactly that we can have coeff() return a const reference (as opposed to returning a value). - // - The is_artihmetic check is required since "const int", "const double", etc. will cause warnings on some systems - // while the declaration of "const T", where T is a non arithmetic type does not. Always returning "const Scalar&" is - // not possible, since the underlying expressions might not offer a valid address the reference could be referring to. - typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&LvalueBit), - const Scalar&, - typename internal::conditional<internal::is_arithmetic<Scalar>::value, Scalar, const Scalar>::type - >::type CoeffReturnType; - - typedef typename internal::add_const_on_value_type_if_arithmetic< - typename internal::packet_traits<Scalar>::type - >::type PacketReturnType; - - typedef EigenBase<Derived> Base; - using Base::rows; - using Base::cols; - using Base::size; - using Base::derived; - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const - { - return int(Derived::RowsAtCompileTime) == 1 ? 0 - : int(Derived::ColsAtCompileTime) == 1 ? inner - : int(Derived::Flags)&RowMajorBit ? outer - : inner; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) const - { - return int(Derived::ColsAtCompileTime) == 1 ? 0 - : int(Derived::RowsAtCompileTime) == 1 ? inner - : int(Derived::Flags)&RowMajorBit ? inner - : outer; - } - - /** Short version: don't use this function, use - * \link operator()(Index,Index) const \endlink instead. - * - * Long version: this function is similar to - * \link operator()(Index,Index) const \endlink, but without the assertion. - * Use this for limiting the performance cost of debugging code when doing - * repeated coefficient access. Only use this when it is guaranteed that the - * parameters \a row and \a col are in range. - * - * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this - * function equivalent to \link operator()(Index,Index) const \endlink. - * - * \sa operator()(Index,Index) const, coeffRef(Index,Index), coeff(Index) const - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const - { - eigen_internal_assert(row >= 0 && row < rows() - && col >= 0 && col < cols()); - return internal::evaluator<Derived>(derived()).coeff(row,col); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const - { - return coeff(rowIndexByOuterInner(outer, inner), - colIndexByOuterInner(outer, inner)); - } - - /** \returns the coefficient at given the given row and column. - * - * \sa operator()(Index,Index), operator[](Index) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType operator()(Index row, Index col) const - { - eigen_assert(row >= 0 && row < rows() - && col >= 0 && col < cols()); - return coeff(row, col); - } - - /** Short version: don't use this function, use - * \link operator[](Index) const \endlink instead. - * - * Long version: this function is similar to - * \link operator[](Index) const \endlink, but without the assertion. - * Use this for limiting the performance cost of debugging code when doing - * repeated coefficient access. Only use this when it is guaranteed that the - * parameter \a index is in range. - * - * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this - * function equivalent to \link operator[](Index) const \endlink. - * - * \sa operator[](Index) const, coeffRef(Index), coeff(Index,Index) const - */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType - coeff(Index index) const - { - EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit, - THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS) - eigen_internal_assert(index >= 0 && index < size()); - return internal::evaluator<Derived>(derived()).coeff(index); - } - - - /** \returns the coefficient at given index. - * - * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit. - * - * \sa operator[](Index), operator()(Index,Index) const, x() const, y() const, - * z() const, w() const - */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType - operator[](Index index) const - { - EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime, - THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD) - eigen_assert(index >= 0 && index < size()); - return coeff(index); - } - - /** \returns the coefficient at given index. - * - * This is synonymous to operator[](Index) const. - * - * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit. - * - * \sa operator[](Index), operator()(Index,Index) const, x() const, y() const, - * z() const, w() const - */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType - operator()(Index index) const - { - eigen_assert(index >= 0 && index < size()); - return coeff(index); - } - - /** equivalent to operator[](0). */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType - x() const { return (*this)[0]; } - - /** equivalent to operator[](1). */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType - y() const - { - EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS); - return (*this)[1]; - } - - /** equivalent to operator[](2). */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType - z() const - { - EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS); - return (*this)[2]; - } - - /** equivalent to operator[](3). */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE CoeffReturnType - w() const - { - EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS); - return (*this)[3]; - } - - /** \internal - * \returns the packet of coefficients starting at the given row and column. It is your responsibility - * to ensure that a packet really starts there. This method is only available on expressions having the - * PacketAccessBit. - * - * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select - * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets - * starting at an address which is a multiple of the packet size. - */ - - template<int LoadMode> - EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const - { - typedef typename internal::packet_traits<Scalar>::type DefaultPacketType; - eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(row,col); - } - - - /** \internal */ - template<int LoadMode> - EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner) const - { - return packet<LoadMode>(rowIndexByOuterInner(outer, inner), - colIndexByOuterInner(outer, inner)); - } - - /** \internal - * \returns the packet of coefficients starting at the given index. It is your responsibility - * to ensure that a packet really starts there. This method is only available on expressions having the - * PacketAccessBit and the LinearAccessBit. - * - * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select - * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets - * starting at an address which is a multiple of the packet size. - */ - - template<int LoadMode> - EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit, - THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS) - typedef typename internal::packet_traits<Scalar>::type DefaultPacketType; - eigen_internal_assert(index >= 0 && index < size()); - return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(index); - } - - protected: - // explanation: DenseBase is doing "using ..." on the methods from DenseCoeffsBase. - // But some methods are only available in the DirectAccess case. - // So we add dummy methods here with these names, so that "using... " doesn't fail. - // It's not private so that the child class DenseBase can access them, and it's not public - // either since it's an implementation detail, so has to be protected. - void coeffRef(); - void coeffRefByOuterInner(); - void writePacket(); - void writePacketByOuterInner(); - void copyCoeff(); - void copyCoeffByOuterInner(); - void copyPacket(); - void copyPacketByOuterInner(); - void stride(); - void innerStride(); - void outerStride(); - void rowStride(); - void colStride(); -}; - -/** \brief Base class providing read/write coefficient access to matrices and arrays. - * \ingroup Core_Module - * \tparam Derived Type of the derived class - * - * \note #WriteAccessors Constant indicating read/write access - * - * This class defines the non-const \c operator() function and friends, which can be used to write specific - * entries of a matrix or array. This class inherits DenseCoeffsBase<Derived, ReadOnlyAccessors> which - * defines the const variant for reading specific entries. - * - * \sa DenseCoeffsBase<Derived, DirectAccessors>, \ref TopicClassHierarchy - */ -template<typename Derived> -class DenseCoeffsBase<Derived, WriteAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors> -{ - public: - - typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base; - - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename internal::packet_traits<Scalar>::type PacketScalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - - using Base::coeff; - using Base::rows; - using Base::cols; - using Base::size; - using Base::derived; - using Base::rowIndexByOuterInner; - using Base::colIndexByOuterInner; - using Base::operator[]; - using Base::operator(); - using Base::x; - using Base::y; - using Base::z; - using Base::w; - - /** Short version: don't use this function, use - * \link operator()(Index,Index) \endlink instead. - * - * Long version: this function is similar to - * \link operator()(Index,Index) \endlink, but without the assertion. - * Use this for limiting the performance cost of debugging code when doing - * repeated coefficient access. Only use this when it is guaranteed that the - * parameters \a row and \a col are in range. - * - * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this - * function equivalent to \link operator()(Index,Index) \endlink. - * - * \sa operator()(Index,Index), coeff(Index, Index) const, coeffRef(Index) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) - { - eigen_internal_assert(row >= 0 && row < rows() - && col >= 0 && col < cols()); - return internal::evaluator<Derived>(derived()).coeffRef(row,col); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - coeffRefByOuterInner(Index outer, Index inner) - { - return coeffRef(rowIndexByOuterInner(outer, inner), - colIndexByOuterInner(outer, inner)); - } - - /** \returns a reference to the coefficient at given the given row and column. - * - * \sa operator[](Index) - */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - operator()(Index row, Index col) - { - eigen_assert(row >= 0 && row < rows() - && col >= 0 && col < cols()); - return coeffRef(row, col); - } - - - /** Short version: don't use this function, use - * \link operator[](Index) \endlink instead. - * - * Long version: this function is similar to - * \link operator[](Index) \endlink, but without the assertion. - * Use this for limiting the performance cost of debugging code when doing - * repeated coefficient access. Only use this when it is guaranteed that the - * parameters \a row and \a col are in range. - * - * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this - * function equivalent to \link operator[](Index) \endlink. - * - * \sa operator[](Index), coeff(Index) const, coeffRef(Index,Index) - */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - coeffRef(Index index) - { - EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit, - THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS) - eigen_internal_assert(index >= 0 && index < size()); - return internal::evaluator<Derived>(derived()).coeffRef(index); - } - - /** \returns a reference to the coefficient at given index. - * - * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit. - * - * \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w() - */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - operator[](Index index) - { - EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime, - THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD) - eigen_assert(index >= 0 && index < size()); - return coeffRef(index); - } - - /** \returns a reference to the coefficient at given index. - * - * This is synonymous to operator[](Index). - * - * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit. - * - * \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w() - */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - operator()(Index index) - { - eigen_assert(index >= 0 && index < size()); - return coeffRef(index); - } - - /** equivalent to operator[](0). */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - x() { return (*this)[0]; } - - /** equivalent to operator[](1). */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - y() - { - EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS); - return (*this)[1]; - } - - /** equivalent to operator[](2). */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - z() - { - EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS); - return (*this)[2]; - } - - /** equivalent to operator[](3). */ - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& - w() - { - EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS); - return (*this)[3]; - } -}; - -/** \brief Base class providing direct read-only coefficient access to matrices and arrays. - * \ingroup Core_Module - * \tparam Derived Type of the derived class - * - * \note #DirectAccessors Constant indicating direct access - * - * This class defines functions to work with strides which can be used to access entries directly. This class - * inherits DenseCoeffsBase<Derived, ReadOnlyAccessors> which defines functions to access entries read-only using - * \c operator() . - * - * \sa \blank \ref TopicClassHierarchy - */ -template<typename Derived> -class DenseCoeffsBase<Derived, DirectAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors> -{ - public: - - typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - - using Base::rows; - using Base::cols; - using Base::size; - using Base::derived; - - /** \returns the pointer increment between two consecutive elements within a slice in the inner direction. - * - * \sa outerStride(), rowStride(), colStride() - */ - EIGEN_DEVICE_FUNC - inline Index innerStride() const - { - return derived().innerStride(); - } - - /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns - * in a column-major matrix). - * - * \sa innerStride(), rowStride(), colStride() - */ - EIGEN_DEVICE_FUNC - inline Index outerStride() const - { - return derived().outerStride(); - } - - // FIXME shall we remove it ? - inline Index stride() const - { - return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); - } - - /** \returns the pointer increment between two consecutive rows. - * - * \sa innerStride(), outerStride(), colStride() - */ - EIGEN_DEVICE_FUNC - inline Index rowStride() const - { - return Derived::IsRowMajor ? outerStride() : innerStride(); - } - - /** \returns the pointer increment between two consecutive columns. - * - * \sa innerStride(), outerStride(), rowStride() - */ - EIGEN_DEVICE_FUNC - inline Index colStride() const - { - return Derived::IsRowMajor ? innerStride() : outerStride(); - } -}; - -/** \brief Base class providing direct read/write coefficient access to matrices and arrays. - * \ingroup Core_Module - * \tparam Derived Type of the derived class - * - * \note #DirectWriteAccessors Constant indicating direct access - * - * This class defines functions to work with strides which can be used to access entries directly. This class - * inherits DenseCoeffsBase<Derived, WriteAccessors> which defines functions to access entries read/write using - * \c operator(). - * - * \sa \blank \ref TopicClassHierarchy - */ -template<typename Derived> -class DenseCoeffsBase<Derived, DirectWriteAccessors> - : public DenseCoeffsBase<Derived, WriteAccessors> -{ - public: - - typedef DenseCoeffsBase<Derived, WriteAccessors> Base; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - - using Base::rows; - using Base::cols; - using Base::size; - using Base::derived; - - /** \returns the pointer increment between two consecutive elements within a slice in the inner direction. - * - * \sa outerStride(), rowStride(), colStride() - */ - EIGEN_DEVICE_FUNC - inline Index innerStride() const - { - return derived().innerStride(); - } - - /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns - * in a column-major matrix). - * - * \sa innerStride(), rowStride(), colStride() - */ - EIGEN_DEVICE_FUNC - inline Index outerStride() const - { - return derived().outerStride(); - } - - // FIXME shall we remove it ? - inline Index stride() const - { - return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); - } - - /** \returns the pointer increment between two consecutive rows. - * - * \sa innerStride(), outerStride(), colStride() - */ - EIGEN_DEVICE_FUNC - inline Index rowStride() const - { - return Derived::IsRowMajor ? outerStride() : innerStride(); - } - - /** \returns the pointer increment between two consecutive columns. - * - * \sa innerStride(), outerStride(), rowStride() - */ - EIGEN_DEVICE_FUNC - inline Index colStride() const - { - return Derived::IsRowMajor ? innerStride() : outerStride(); - } -}; - -namespace internal { - -template<int Alignment, typename Derived, bool JustReturnZero> -struct first_aligned_impl -{ - static inline Index run(const Derived&) - { return 0; } -}; - -template<int Alignment, typename Derived> -struct first_aligned_impl<Alignment, Derived, false> -{ - static inline Index run(const Derived& m) - { - return internal::first_aligned<Alignment>(m.data(), m.size()); - } -}; - -/** \internal \returns the index of the first element of the array stored by \a m that is properly aligned with respect to \a Alignment for vectorization. - * - * \tparam Alignment requested alignment in Bytes. - * - * There is also the variant first_aligned(const Scalar*, Integer) defined in Memory.h. See it for more - * documentation. - */ -template<int Alignment, typename Derived> -static inline Index first_aligned(const DenseBase<Derived>& m) -{ - enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags & DirectAccessBit) }; - return first_aligned_impl<Alignment, Derived, ReturnZero>::run(m.derived()); -} - -template<typename Derived> -static inline Index first_default_aligned(const DenseBase<Derived>& m) -{ - typedef typename Derived::Scalar Scalar; - typedef typename packet_traits<Scalar>::type DefaultPacketType; - return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m); -} - -template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret> -struct inner_stride_at_compile_time -{ - enum { ret = traits<Derived>::InnerStrideAtCompileTime }; -}; - -template<typename Derived> -struct inner_stride_at_compile_time<Derived, false> -{ - enum { ret = 0 }; -}; - -template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret> -struct outer_stride_at_compile_time -{ - enum { ret = traits<Derived>::OuterStrideAtCompileTime }; -}; - -template<typename Derived> -struct outer_stride_at_compile_time<Derived, false> -{ - enum { ret = 0 }; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_DENSECOEFFSBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/DenseStorage.h b/external/eigen/include/eigen3/Eigen/src/Core/DenseStorage.h deleted file mode 100644 index a8bb8a62..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/DenseStorage.h +++ /dev/null @@ -1,590 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIXSTORAGE_H -#define EIGEN_MATRIXSTORAGE_H - -#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN - #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) X; EIGEN_DENSE_STORAGE_CTOR_PLUGIN; -#else - #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) -#endif - -namespace Eigen { - -namespace internal { - -struct constructor_without_unaligned_array_assert {}; - -template<typename T, int Size> -EIGEN_DEVICE_FUNC -void check_static_allocation_size() -{ - // if EIGEN_STACK_ALLOCATION_LIMIT is defined to 0, then no limit - #if EIGEN_STACK_ALLOCATION_LIMIT - EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG); - #endif -} - -/** \internal - * Static array. If the MatrixOrArrayOptions require auto-alignment, the array will be automatically aligned: - * to 16 bytes boundary if the total size is a multiple of 16 bytes. - */ -template <typename T, int Size, int MatrixOrArrayOptions, - int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0 - : compute_default_alignment<T,Size>::value > -struct plain_array -{ - T array[Size]; - - EIGEN_DEVICE_FUNC - plain_array() - { - check_static_allocation_size<T,Size>(); - } - - EIGEN_DEVICE_FUNC - plain_array(constructor_without_unaligned_array_assert) - { - check_static_allocation_size<T,Size>(); - } -}; - -#if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT) - #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) -#elif EIGEN_GNUC_AT_LEAST(4,7) - // GCC 4.7 is too aggressive in its optimizations and remove the alignment test based on the fact the array is declared to be aligned. - // See this bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900 - // Hiding the origin of the array pointer behind a function argument seems to do the trick even if the function is inlined: - template<typename PtrType> - EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) { return array; } - #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \ - eigen_assert((internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (sizemask)) == 0 \ - && "this assertion is explained here: " \ - "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \ - " **** READ THIS WEB PAGE !!! ****"); -#else - #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \ - eigen_assert((internal::UIntPtr(array) & (sizemask)) == 0 \ - && "this assertion is explained here: " \ - "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \ - " **** READ THIS WEB PAGE !!! ****"); -#endif - -template <typename T, int Size, int MatrixOrArrayOptions> -struct plain_array<T, Size, MatrixOrArrayOptions, 8> -{ - EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size]; - - EIGEN_DEVICE_FUNC - plain_array() - { - EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7); - check_static_allocation_size<T,Size>(); - } - - EIGEN_DEVICE_FUNC - plain_array(constructor_without_unaligned_array_assert) - { - check_static_allocation_size<T,Size>(); - } -}; - -template <typename T, int Size, int MatrixOrArrayOptions> -struct plain_array<T, Size, MatrixOrArrayOptions, 16> -{ - EIGEN_ALIGN_TO_BOUNDARY(16) T array[Size]; - - EIGEN_DEVICE_FUNC - plain_array() - { - EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15); - check_static_allocation_size<T,Size>(); - } - - EIGEN_DEVICE_FUNC - plain_array(constructor_without_unaligned_array_assert) - { - check_static_allocation_size<T,Size>(); - } -}; - -template <typename T, int Size, int MatrixOrArrayOptions> -struct plain_array<T, Size, MatrixOrArrayOptions, 32> -{ - EIGEN_ALIGN_TO_BOUNDARY(32) T array[Size]; - - EIGEN_DEVICE_FUNC - plain_array() - { - EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31); - check_static_allocation_size<T,Size>(); - } - - EIGEN_DEVICE_FUNC - plain_array(constructor_without_unaligned_array_assert) - { - check_static_allocation_size<T,Size>(); - } -}; - -template <typename T, int Size, int MatrixOrArrayOptions> -struct plain_array<T, Size, MatrixOrArrayOptions, 64> -{ - EIGEN_ALIGN_TO_BOUNDARY(64) T array[Size]; - - EIGEN_DEVICE_FUNC - plain_array() - { - EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(63); - check_static_allocation_size<T,Size>(); - } - - EIGEN_DEVICE_FUNC - plain_array(constructor_without_unaligned_array_assert) - { - check_static_allocation_size<T,Size>(); - } -}; - -template <typename T, int MatrixOrArrayOptions, int Alignment> -struct plain_array<T, 0, MatrixOrArrayOptions, Alignment> -{ - T array[1]; - EIGEN_DEVICE_FUNC plain_array() {} - EIGEN_DEVICE_FUNC plain_array(constructor_without_unaligned_array_assert) {} -}; - -} // end namespace internal - -/** \internal - * - * \class DenseStorage - * \ingroup Core_Module - * - * \brief Stores the data of a matrix - * - * This class stores the data of fixed-size, dynamic-size or mixed matrices - * in a way as compact as possible. - * - * \sa Matrix - */ -template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage; - -// purely fixed-size matrix -template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage -{ - internal::plain_array<T,Size,_Options> m_data; - public: - EIGEN_DEVICE_FUNC DenseStorage() { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size) - } - EIGEN_DEVICE_FUNC - explicit DenseStorage(internal::constructor_without_unaligned_array_assert) - : m_data(internal::constructor_without_unaligned_array_assert()) {} - EIGEN_DEVICE_FUNC - DenseStorage(const DenseStorage& other) : m_data(other.m_data) { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size) - } - EIGEN_DEVICE_FUNC - DenseStorage& operator=(const DenseStorage& other) - { - if (this != &other) m_data = other.m_data; - return *this; - } - EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) - eigen_internal_assert(size==rows*cols && rows==_Rows && cols==_Cols); - EIGEN_UNUSED_VARIABLE(size); - EIGEN_UNUSED_VARIABLE(rows); - EIGEN_UNUSED_VARIABLE(cols); - } - EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { - numext::swap(m_data, other.m_data); - } - EIGEN_DEVICE_FUNC static Index rows(void) {return _Rows;} - EIGEN_DEVICE_FUNC static Index cols(void) {return _Cols;} - EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {} - EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {} - EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; } - EIGEN_DEVICE_FUNC T *data() { return m_data.array; } -}; - -// null matrix -template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options> -{ - public: - EIGEN_DEVICE_FUNC DenseStorage() {} - EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) {} - EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) {} - EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) { return *this; } - EIGEN_DEVICE_FUNC DenseStorage(Index,Index,Index) {} - EIGEN_DEVICE_FUNC void swap(DenseStorage& ) {} - EIGEN_DEVICE_FUNC static Index rows(void) {return _Rows;} - EIGEN_DEVICE_FUNC static Index cols(void) {return _Cols;} - EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {} - EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {} - EIGEN_DEVICE_FUNC const T *data() const { return 0; } - EIGEN_DEVICE_FUNC T *data() { return 0; } -}; - -// more specializations for null matrices; these are necessary to resolve ambiguities -template<typename T, int _Options> class DenseStorage<T, 0, Dynamic, Dynamic, _Options> -: public DenseStorage<T, 0, 0, 0, _Options> { }; - -template<typename T, int _Rows, int _Options> class DenseStorage<T, 0, _Rows, Dynamic, _Options> -: public DenseStorage<T, 0, 0, 0, _Options> { }; - -template<typename T, int _Cols, int _Options> class DenseStorage<T, 0, Dynamic, _Cols, _Options> -: public DenseStorage<T, 0, 0, 0, _Options> { }; - -// dynamic-size matrix with fixed-size storage -template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options> -{ - internal::plain_array<T,Size,_Options> m_data; - Index m_rows; - Index m_cols; - public: - EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {} - EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) - : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {} - EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows), m_cols(other.m_cols) {} - EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) - { - if (this != &other) - { - m_data = other.m_data; - m_rows = other.m_rows; - m_cols = other.m_cols; - } - return *this; - } - EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index cols) : m_rows(rows), m_cols(cols) {} - EIGEN_DEVICE_FUNC void swap(DenseStorage& other) - { - numext::swap(m_data,other.m_data); - numext::swap(m_rows,other.m_rows); - numext::swap(m_cols,other.m_cols); - } - EIGEN_DEVICE_FUNC Index rows() const {return m_rows;} - EIGEN_DEVICE_FUNC Index cols() const {return m_cols;} - EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; } - EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; } - EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; } - EIGEN_DEVICE_FUNC T *data() { return m_data.array; } -}; - -// dynamic-size matrix with fixed-size storage and fixed width -template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options> -{ - internal::plain_array<T,Size,_Options> m_data; - Index m_rows; - public: - EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {} - EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) - : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {} - EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows) {} - EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) - { - if (this != &other) - { - m_data = other.m_data; - m_rows = other.m_rows; - } - return *this; - } - EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index) : m_rows(rows) {} - EIGEN_DEVICE_FUNC void swap(DenseStorage& other) - { - numext::swap(m_data,other.m_data); - numext::swap(m_rows,other.m_rows); - } - EIGEN_DEVICE_FUNC Index rows(void) const {return m_rows;} - EIGEN_DEVICE_FUNC Index cols(void) const {return _Cols;} - EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index) { m_rows = rows; } - EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index) { m_rows = rows; } - EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; } - EIGEN_DEVICE_FUNC T *data() { return m_data.array; } -}; - -// dynamic-size matrix with fixed-size storage and fixed height -template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options> -{ - internal::plain_array<T,Size,_Options> m_data; - Index m_cols; - public: - EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {} - EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) - : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {} - EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_cols(other.m_cols) {} - EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) - { - if (this != &other) - { - m_data = other.m_data; - m_cols = other.m_cols; - } - return *this; - } - EIGEN_DEVICE_FUNC DenseStorage(Index, Index, Index cols) : m_cols(cols) {} - EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { - numext::swap(m_data,other.m_data); - numext::swap(m_cols,other.m_cols); - } - EIGEN_DEVICE_FUNC Index rows(void) const {return _Rows;} - EIGEN_DEVICE_FUNC Index cols(void) const {return m_cols;} - EIGEN_DEVICE_FUNC void conservativeResize(Index, Index, Index cols) { m_cols = cols; } - EIGEN_DEVICE_FUNC void resize(Index, Index, Index cols) { m_cols = cols; } - EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; } - EIGEN_DEVICE_FUNC T *data() { return m_data.array; } -}; - -// purely dynamic matrix. -template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options> -{ - T *m_data; - Index m_rows; - Index m_cols; - public: - EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0), m_cols(0) {} - EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) - : m_data(0), m_rows(0), m_cols(0) {} - EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) - : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols) - { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) - eigen_internal_assert(size==rows*cols && rows>=0 && cols >=0); - } - EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) - : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*other.m_cols)) - , m_rows(other.m_rows) - , m_cols(other.m_cols) - { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*m_cols) - internal::smart_copy(other.m_data, other.m_data+other.m_rows*other.m_cols, m_data); - } - EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) - { - if (this != &other) - { - DenseStorage tmp(other); - this->swap(tmp); - } - return *this; - } -#if EIGEN_HAS_RVALUE_REFERENCES - EIGEN_DEVICE_FUNC - DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT - : m_data(std::move(other.m_data)) - , m_rows(std::move(other.m_rows)) - , m_cols(std::move(other.m_cols)) - { - other.m_data = nullptr; - other.m_rows = 0; - other.m_cols = 0; - } - EIGEN_DEVICE_FUNC - DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT - { - numext::swap(m_data, other.m_data); - numext::swap(m_rows, other.m_rows); - numext::swap(m_cols, other.m_cols); - return *this; - } -#endif - EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); } - EIGEN_DEVICE_FUNC void swap(DenseStorage& other) - { - numext::swap(m_data,other.m_data); - numext::swap(m_rows,other.m_rows); - numext::swap(m_cols,other.m_cols); - } - EIGEN_DEVICE_FUNC Index rows(void) const {return m_rows;} - EIGEN_DEVICE_FUNC Index cols(void) const {return m_cols;} - void conservativeResize(Index size, Index rows, Index cols) - { - m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols); - m_rows = rows; - m_cols = cols; - } - EIGEN_DEVICE_FUNC void resize(Index size, Index rows, Index cols) - { - if(size != m_rows*m_cols) - { - internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); - if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative - m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size); - else - m_data = 0; - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) - } - m_rows = rows; - m_cols = cols; - } - EIGEN_DEVICE_FUNC const T *data() const { return m_data; } - EIGEN_DEVICE_FUNC T *data() { return m_data; } -}; - -// matrix with dynamic width and fixed height (so that matrix has dynamic size). -template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options> -{ - T *m_data; - Index m_cols; - public: - EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_cols(0) {} - explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {} - EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(cols) - { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) - eigen_internal_assert(size==rows*cols && rows==_Rows && cols >=0); - EIGEN_UNUSED_VARIABLE(rows); - } - EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) - : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(_Rows*other.m_cols)) - , m_cols(other.m_cols) - { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_cols*_Rows) - internal::smart_copy(other.m_data, other.m_data+_Rows*m_cols, m_data); - } - EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) - { - if (this != &other) - { - DenseStorage tmp(other); - this->swap(tmp); - } - return *this; - } -#if EIGEN_HAS_RVALUE_REFERENCES - EIGEN_DEVICE_FUNC - DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT - : m_data(std::move(other.m_data)) - , m_cols(std::move(other.m_cols)) - { - other.m_data = nullptr; - other.m_cols = 0; - } - EIGEN_DEVICE_FUNC - DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT - { - numext::swap(m_data, other.m_data); - numext::swap(m_cols, other.m_cols); - return *this; - } -#endif - EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); } - EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { - numext::swap(m_data,other.m_data); - numext::swap(m_cols,other.m_cols); - } - EIGEN_DEVICE_FUNC static Index rows(void) {return _Rows;} - EIGEN_DEVICE_FUNC Index cols(void) const {return m_cols;} - EIGEN_DEVICE_FUNC void conservativeResize(Index size, Index, Index cols) - { - m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols); - m_cols = cols; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index, Index cols) - { - if(size != _Rows*m_cols) - { - internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); - if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative - m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size); - else - m_data = 0; - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) - } - m_cols = cols; - } - EIGEN_DEVICE_FUNC const T *data() const { return m_data; } - EIGEN_DEVICE_FUNC T *data() { return m_data; } -}; - -// matrix with dynamic height and fixed width (so that matrix has dynamic size). -template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options> -{ - T *m_data; - Index m_rows; - public: - EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0) {} - explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {} - EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows) - { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) - eigen_internal_assert(size==rows*cols && rows>=0 && cols == _Cols); - EIGEN_UNUSED_VARIABLE(cols); - } - EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) - : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*_Cols)) - , m_rows(other.m_rows) - { - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*_Cols) - internal::smart_copy(other.m_data, other.m_data+other.m_rows*_Cols, m_data); - } - EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) - { - if (this != &other) - { - DenseStorage tmp(other); - this->swap(tmp); - } - return *this; - } -#if EIGEN_HAS_RVALUE_REFERENCES - EIGEN_DEVICE_FUNC - DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT - : m_data(std::move(other.m_data)) - , m_rows(std::move(other.m_rows)) - { - other.m_data = nullptr; - other.m_rows = 0; - } - EIGEN_DEVICE_FUNC - DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT - { - numext::swap(m_data, other.m_data); - numext::swap(m_rows, other.m_rows); - return *this; - } -#endif - EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); } - EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { - numext::swap(m_data,other.m_data); - numext::swap(m_rows,other.m_rows); - } - EIGEN_DEVICE_FUNC Index rows(void) const {return m_rows;} - EIGEN_DEVICE_FUNC static Index cols(void) {return _Cols;} - void conservativeResize(Index size, Index rows, Index) - { - m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols); - m_rows = rows; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index rows, Index) - { - if(size != m_rows*_Cols) - { - internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); - if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative - m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size); - else - m_data = 0; - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) - } - m_rows = rows; - } - EIGEN_DEVICE_FUNC const T *data() const { return m_data; } - EIGEN_DEVICE_FUNC T *data() { return m_data; } -}; - -} // end namespace Eigen - -#endif // EIGEN_MATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Diagonal.h b/external/eigen/include/eigen3/Eigen/src/Core/Diagonal.h deleted file mode 100644 index 563135fb..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Diagonal.h +++ /dev/null @@ -1,262 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DIAGONAL_H -#define EIGEN_DIAGONAL_H - -namespace Eigen { - -/** \class Diagonal - * \ingroup Core_Module - * - * \brief Expression of a diagonal/subdiagonal/superdiagonal in a matrix - * - * \param MatrixType the type of the object in which we are taking a sub/main/super diagonal - * \param DiagIndex the index of the sub/super diagonal. The default is 0 and it means the main diagonal. - * A positive value means a superdiagonal, a negative value means a subdiagonal. - * You can also use DynamicIndex so the index can be set at runtime. - * - * The matrix is not required to be square. - * - * This class represents an expression of the main diagonal, or any sub/super diagonal - * of a square matrix. It is the return type of MatrixBase::diagonal() and MatrixBase::diagonal(Index) and most of the - * time this is the only way it is used. - * - * \sa MatrixBase::diagonal(), MatrixBase::diagonal(Index) - */ - -namespace internal { -template<typename MatrixType, int DiagIndex> -struct traits<Diagonal<MatrixType,DiagIndex> > - : traits<MatrixType> -{ - typedef typename ref_selector<MatrixType>::type MatrixTypeNested; - typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested; - typedef typename MatrixType::StorageKind StorageKind; - enum { - RowsAtCompileTime = (int(DiagIndex) == DynamicIndex || int(MatrixType::SizeAtCompileTime) == Dynamic) ? Dynamic - : (EIGEN_PLAIN_ENUM_MIN(MatrixType::RowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0), - MatrixType::ColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))), - ColsAtCompileTime = 1, - MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic - : DiagIndex == DynamicIndex ? EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime, - MatrixType::MaxColsAtCompileTime) - : (EIGEN_PLAIN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0), - MatrixType::MaxColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))), - MaxColsAtCompileTime = 1, - MaskLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, - Flags = (unsigned int)_MatrixTypeNested::Flags & (RowMajorBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit, // FIXME DirectAccessBit should not be handled by expressions - MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret, - InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1, - OuterStrideAtCompileTime = 0 - }; -}; -} - -template<typename MatrixType, int _DiagIndex> class Diagonal - : public internal::dense_xpr_base< Diagonal<MatrixType,_DiagIndex> >::type -{ - public: - - enum { DiagIndex = _DiagIndex }; - typedef typename internal::dense_xpr_base<Diagonal>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal) - - EIGEN_DEVICE_FUNC - explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index) - { - eigen_assert( a_index <= m_matrix.cols() && -a_index <= m_matrix.rows() ); - } - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal) - - EIGEN_DEVICE_FUNC - inline Index rows() const - { - return m_index.value()<0 ? numext::mini<Index>(m_matrix.cols(),m_matrix.rows()+m_index.value()) - : numext::mini<Index>(m_matrix.rows(),m_matrix.cols()-m_index.value()); - } - - EIGEN_DEVICE_FUNC - inline Index cols() const { return 1; } - - EIGEN_DEVICE_FUNC - inline Index innerStride() const - { - return m_matrix.outerStride() + 1; - } - - EIGEN_DEVICE_FUNC - inline Index outerStride() const - { - return 0; - } - - typedef typename internal::conditional< - internal::is_lvalue<MatrixType>::value, - Scalar, - const Scalar - >::type ScalarWithConstIfNotLvalue; - - EIGEN_DEVICE_FUNC - inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.coeffRef(rowOffset(), colOffset())); } - EIGEN_DEVICE_FUNC - inline const Scalar* data() const { return &(m_matrix.coeffRef(rowOffset(), colOffset())); } - - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index row, Index) - { - EIGEN_STATIC_ASSERT_LVALUE(MatrixType) - return m_matrix.coeffRef(row+rowOffset(), row+colOffset()); - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index row, Index) const - { - return m_matrix.coeffRef(row+rowOffset(), row+colOffset()); - } - - EIGEN_DEVICE_FUNC - inline CoeffReturnType coeff(Index row, Index) const - { - return m_matrix.coeff(row+rowOffset(), row+colOffset()); - } - - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index idx) - { - EIGEN_STATIC_ASSERT_LVALUE(MatrixType) - return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset()); - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index idx) const - { - return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset()); - } - - EIGEN_DEVICE_FUNC - inline CoeffReturnType coeff(Index idx) const - { - return m_matrix.coeff(idx+rowOffset(), idx+colOffset()); - } - - EIGEN_DEVICE_FUNC - inline const typename internal::remove_all<typename MatrixType::Nested>::type& - nestedExpression() const - { - return m_matrix; - } - - EIGEN_DEVICE_FUNC - inline Index index() const - { - return m_index.value(); - } - - protected: - typename internal::ref_selector<MatrixType>::non_const_type m_matrix; - const internal::variable_if_dynamicindex<Index, DiagIndex> m_index; - - private: - // some compilers may fail to optimize std::max etc in case of compile-time constants... - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index absDiagIndex() const { return m_index.value()>0 ? m_index.value() : -m_index.value(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index rowOffset() const { return m_index.value()>0 ? 0 : -m_index.value(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index colOffset() const { return m_index.value()>0 ? m_index.value() : 0; } - // trigger a compile-time error if someone try to call packet - template<int LoadMode> typename MatrixType::PacketReturnType packet(Index) const; - template<int LoadMode> typename MatrixType::PacketReturnType packet(Index,Index) const; -}; - -/** \returns an expression of the main diagonal of the matrix \c *this - * - * \c *this is not required to be square. - * - * Example: \include MatrixBase_diagonal.cpp - * Output: \verbinclude MatrixBase_diagonal.out - * - * \sa class Diagonal */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::DiagonalReturnType -MatrixBase<Derived>::diagonal() -{ - return DiagonalReturnType(derived()); -} - -/** This is the const version of diagonal(). */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::ConstDiagonalReturnType -MatrixBase<Derived>::diagonal() const -{ - return ConstDiagonalReturnType(derived()); -} - -/** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this - * - * \c *this is not required to be square. - * - * The template parameter \a DiagIndex represent a super diagonal if \a DiagIndex > 0 - * and a sub diagonal otherwise. \a DiagIndex == 0 is equivalent to the main diagonal. - * - * Example: \include MatrixBase_diagonal_int.cpp - * Output: \verbinclude MatrixBase_diagonal_int.out - * - * \sa MatrixBase::diagonal(), class Diagonal */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::DiagonalDynamicIndexReturnType -MatrixBase<Derived>::diagonal(Index index) -{ - return DiagonalDynamicIndexReturnType(derived(), index); -} - -/** This is the const version of diagonal(Index). */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::ConstDiagonalDynamicIndexReturnType -MatrixBase<Derived>::diagonal(Index index) const -{ - return ConstDiagonalDynamicIndexReturnType(derived(), index); -} - -/** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this - * - * \c *this is not required to be square. - * - * The template parameter \a DiagIndex represent a super diagonal if \a DiagIndex > 0 - * and a sub diagonal otherwise. \a DiagIndex == 0 is equivalent to the main diagonal. - * - * Example: \include MatrixBase_diagonal_template_int.cpp - * Output: \verbinclude MatrixBase_diagonal_template_int.out - * - * \sa MatrixBase::diagonal(), class Diagonal */ -template<typename Derived> -template<int Index_> -EIGEN_DEVICE_FUNC -inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Index_>::Type -MatrixBase<Derived>::diagonal() -{ - return typename DiagonalIndexReturnType<Index_>::Type(derived()); -} - -/** This is the const version of diagonal<int>(). */ -template<typename Derived> -template<int Index_> -EIGEN_DEVICE_FUNC -inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index_>::Type -MatrixBase<Derived>::diagonal() const -{ - return typename ConstDiagonalIndexReturnType<Index_>::Type(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_DIAGONAL_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/DiagonalMatrix.h b/external/eigen/include/eigen3/Eigen/src/Core/DiagonalMatrix.h deleted file mode 100644 index 542685c6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/DiagonalMatrix.h +++ /dev/null @@ -1,391 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DIAGONALMATRIX_H -#define EIGEN_DIAGONALMATRIX_H - -namespace Eigen { - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename Derived> -class DiagonalBase : public EigenBase<Derived> -{ - public: - typedef typename internal::traits<Derived>::DiagonalVectorType DiagonalVectorType; - typedef typename DiagonalVectorType::Scalar Scalar; - typedef typename DiagonalVectorType::RealScalar RealScalar; - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::traits<Derived>::StorageIndex StorageIndex; - - enum { - RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, - ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, - MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime, - MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime, - IsVectorAtCompileTime = 0, - Flags = NoPreferredStorageOrderBit - }; - - typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTime> DenseMatrixType; - typedef DenseMatrixType DenseType; - typedef DiagonalMatrix<Scalar,DiagonalVectorType::SizeAtCompileTime,DiagonalVectorType::MaxSizeAtCompileTime> PlainObject; - - EIGEN_DEVICE_FUNC - inline const Derived& derived() const { return *static_cast<const Derived*>(this); } - EIGEN_DEVICE_FUNC - inline Derived& derived() { return *static_cast<Derived*>(this); } - - EIGEN_DEVICE_FUNC - DenseMatrixType toDenseMatrix() const { return derived(); } - - EIGEN_DEVICE_FUNC - inline const DiagonalVectorType& diagonal() const { return derived().diagonal(); } - EIGEN_DEVICE_FUNC - inline DiagonalVectorType& diagonal() { return derived().diagonal(); } - - EIGEN_DEVICE_FUNC - inline Index rows() const { return diagonal().size(); } - EIGEN_DEVICE_FUNC - inline Index cols() const { return diagonal().size(); } - - template<typename MatrixDerived> - EIGEN_DEVICE_FUNC - const Product<Derived,MatrixDerived,LazyProduct> - operator*(const MatrixBase<MatrixDerived> &matrix) const - { - return Product<Derived, MatrixDerived, LazyProduct>(derived(),matrix.derived()); - } - - typedef DiagonalWrapper<const CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const DiagonalVectorType> > InverseReturnType; - EIGEN_DEVICE_FUNC - inline const InverseReturnType - inverse() const - { - return InverseReturnType(diagonal().cwiseInverse()); - } - - EIGEN_DEVICE_FUNC - inline const DiagonalWrapper<const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DiagonalVectorType,Scalar,product) > - operator*(const Scalar& scalar) const - { - return DiagonalWrapper<const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DiagonalVectorType,Scalar,product) >(diagonal() * scalar); - } - EIGEN_DEVICE_FUNC - friend inline const DiagonalWrapper<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,DiagonalVectorType,product) > - operator*(const Scalar& scalar, const DiagonalBase& other) - { - return DiagonalWrapper<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,DiagonalVectorType,product) >(scalar * other.diagonal()); - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - #ifdef EIGEN_PARSED_BY_DOXYGEN - inline unspecified_expression_type - #else - inline const DiagonalWrapper<const EIGEN_CWISE_BINARY_RETURN_TYPE(DiagonalVectorType,typename OtherDerived::DiagonalVectorType,sum) > - #endif - operator+(const DiagonalBase<OtherDerived>& other) const - { - return (diagonal() + other.diagonal()).asDiagonal(); - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - #ifdef EIGEN_PARSED_BY_DOXYGEN - inline unspecified_expression_type - #else - inline const DiagonalWrapper<const EIGEN_CWISE_BINARY_RETURN_TYPE(DiagonalVectorType,typename OtherDerived::DiagonalVectorType,difference) > - #endif - operator-(const DiagonalBase<OtherDerived>& other) const - { - return (diagonal() - other.diagonal()).asDiagonal(); - } -}; - -#endif - -/** \class DiagonalMatrix - * \ingroup Core_Module - * - * \brief Represents a diagonal matrix with its storage - * - * \param _Scalar the type of coefficients - * \param SizeAtCompileTime the dimension of the matrix, or Dynamic - * \param MaxSizeAtCompileTime the dimension of the matrix, or Dynamic. This parameter is optional and defaults - * to SizeAtCompileTime. Most of the time, you do not need to specify it. - * - * \sa class DiagonalWrapper - */ - -namespace internal { -template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime> -struct traits<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> > - : traits<Matrix<_Scalar,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> > -{ - typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType; - typedef DiagonalShape StorageKind; - enum { - Flags = LvalueBit | NoPreferredStorageOrderBit - }; -}; -} -template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime> -class DiagonalMatrix - : public DiagonalBase<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> > -{ - public: - #ifndef EIGEN_PARSED_BY_DOXYGEN - typedef typename internal::traits<DiagonalMatrix>::DiagonalVectorType DiagonalVectorType; - typedef const DiagonalMatrix& Nested; - typedef _Scalar Scalar; - typedef typename internal::traits<DiagonalMatrix>::StorageKind StorageKind; - typedef typename internal::traits<DiagonalMatrix>::StorageIndex StorageIndex; - #endif - - protected: - - DiagonalVectorType m_diagonal; - - public: - - /** const version of diagonal(). */ - EIGEN_DEVICE_FUNC - inline const DiagonalVectorType& diagonal() const { return m_diagonal; } - /** \returns a reference to the stored vector of diagonal coefficients. */ - EIGEN_DEVICE_FUNC - inline DiagonalVectorType& diagonal() { return m_diagonal; } - - /** Default constructor without initialization */ - EIGEN_DEVICE_FUNC - inline DiagonalMatrix() {} - - /** Constructs a diagonal matrix with given dimension */ - EIGEN_DEVICE_FUNC - explicit inline DiagonalMatrix(Index dim) : m_diagonal(dim) {} - - /** 2D constructor. */ - EIGEN_DEVICE_FUNC - inline DiagonalMatrix(const Scalar& x, const Scalar& y) : m_diagonal(x,y) {} - - /** 3D constructor. */ - EIGEN_DEVICE_FUNC - inline DiagonalMatrix(const Scalar& x, const Scalar& y, const Scalar& z) : m_diagonal(x,y,z) {} - - #if EIGEN_HAS_CXX11 - /** \brief Construct a diagonal matrix with fixed size from an arbitrary number of coefficients. \cpp11 - * - * There exists C++98 anologue constructors for fixed-size diagonal matrices having 2 or 3 coefficients. - * - * \warning To construct a diagonal matrix of fixed size, the number of values passed to this - * constructor must match the fixed dimension of \c *this. - * - * \sa DiagonalMatrix(const Scalar&, const Scalar&) - * \sa DiagonalMatrix(const Scalar&, const Scalar&, const Scalar&) - */ - template <typename... ArgTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - DiagonalMatrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const ArgTypes&... args) - : m_diagonal(a0, a1, a2, args...) {} - - /** \brief Constructs a DiagonalMatrix and initializes it by elements given by an initializer list of initializer - * lists \cpp11 - */ - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE DiagonalMatrix(const std::initializer_list<std::initializer_list<Scalar>>& list) - : m_diagonal(list) {} - #endif // EIGEN_HAS_CXX11 - - /** Copy constructor. */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - inline DiagonalMatrix(const DiagonalBase<OtherDerived>& other) : m_diagonal(other.diagonal()) {} - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /** copy constructor. prevent a default copy constructor from hiding the other templated constructor */ - inline DiagonalMatrix(const DiagonalMatrix& other) : m_diagonal(other.diagonal()) {} - #endif - - /** generic constructor from expression of the diagonal coefficients */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - explicit inline DiagonalMatrix(const MatrixBase<OtherDerived>& other) : m_diagonal(other) - {} - - /** Copy operator. */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - DiagonalMatrix& operator=(const DiagonalBase<OtherDerived>& other) - { - m_diagonal = other.diagonal(); - return *this; - } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /** This is a special case of the templated operator=. Its purpose is to - * prevent a default operator= from hiding the templated operator=. - */ - EIGEN_DEVICE_FUNC - DiagonalMatrix& operator=(const DiagonalMatrix& other) - { - m_diagonal = other.diagonal(); - return *this; - } - #endif - - /** Resizes to given size. */ - EIGEN_DEVICE_FUNC - inline void resize(Index size) { m_diagonal.resize(size); } - /** Sets all coefficients to zero. */ - EIGEN_DEVICE_FUNC - inline void setZero() { m_diagonal.setZero(); } - /** Resizes and sets all coefficients to zero. */ - EIGEN_DEVICE_FUNC - inline void setZero(Index size) { m_diagonal.setZero(size); } - /** Sets this matrix to be the identity matrix of the current size. */ - EIGEN_DEVICE_FUNC - inline void setIdentity() { m_diagonal.setOnes(); } - /** Sets this matrix to be the identity matrix of the given size. */ - EIGEN_DEVICE_FUNC - inline void setIdentity(Index size) { m_diagonal.setOnes(size); } -}; - -/** \class DiagonalWrapper - * \ingroup Core_Module - * - * \brief Expression of a diagonal matrix - * - * \param _DiagonalVectorType the type of the vector of diagonal coefficients - * - * This class is an expression of a diagonal matrix, but not storing its own vector of diagonal coefficients, - * instead wrapping an existing vector expression. It is the return type of MatrixBase::asDiagonal() - * and most of the time this is the only way that it is used. - * - * \sa class DiagonalMatrix, class DiagonalBase, MatrixBase::asDiagonal() - */ - -namespace internal { -template<typename _DiagonalVectorType> -struct traits<DiagonalWrapper<_DiagonalVectorType> > -{ - typedef _DiagonalVectorType DiagonalVectorType; - typedef typename DiagonalVectorType::Scalar Scalar; - typedef typename DiagonalVectorType::StorageIndex StorageIndex; - typedef DiagonalShape StorageKind; - typedef typename traits<DiagonalVectorType>::XprKind XprKind; - enum { - RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, - ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, - MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime, - MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime, - Flags = (traits<DiagonalVectorType>::Flags & LvalueBit) | NoPreferredStorageOrderBit - }; -}; -} - -template<typename _DiagonalVectorType> -class DiagonalWrapper - : public DiagonalBase<DiagonalWrapper<_DiagonalVectorType> >, internal::no_assignment_operator -{ - public: - #ifndef EIGEN_PARSED_BY_DOXYGEN - typedef _DiagonalVectorType DiagonalVectorType; - typedef DiagonalWrapper Nested; - #endif - - /** Constructor from expression of diagonal coefficients to wrap. */ - EIGEN_DEVICE_FUNC - explicit inline DiagonalWrapper(DiagonalVectorType& a_diagonal) : m_diagonal(a_diagonal) {} - - /** \returns a const reference to the wrapped expression of diagonal coefficients. */ - EIGEN_DEVICE_FUNC - const DiagonalVectorType& diagonal() const { return m_diagonal; } - - protected: - typename DiagonalVectorType::Nested m_diagonal; -}; - -/** \returns a pseudo-expression of a diagonal matrix with *this as vector of diagonal coefficients - * - * \only_for_vectors - * - * Example: \include MatrixBase_asDiagonal.cpp - * Output: \verbinclude MatrixBase_asDiagonal.out - * - * \sa class DiagonalWrapper, class DiagonalMatrix, diagonal(), isDiagonal() - **/ -template<typename Derived> -EIGEN_DEVICE_FUNC inline const DiagonalWrapper<const Derived> -MatrixBase<Derived>::asDiagonal() const -{ - return DiagonalWrapper<const Derived>(derived()); -} - -/** \returns true if *this is approximately equal to a diagonal matrix, - * within the precision given by \a prec. - * - * Example: \include MatrixBase_isDiagonal.cpp - * Output: \verbinclude MatrixBase_isDiagonal.out - * - * \sa asDiagonal() - */ -template<typename Derived> -bool MatrixBase<Derived>::isDiagonal(const RealScalar& prec) const -{ - if(cols() != rows()) return false; - RealScalar maxAbsOnDiagonal = static_cast<RealScalar>(-1); - for(Index j = 0; j < cols(); ++j) - { - RealScalar absOnDiagonal = numext::abs(coeff(j,j)); - if(absOnDiagonal > maxAbsOnDiagonal) maxAbsOnDiagonal = absOnDiagonal; - } - for(Index j = 0; j < cols(); ++j) - for(Index i = 0; i < j; ++i) - { - if(!internal::isMuchSmallerThan(coeff(i, j), maxAbsOnDiagonal, prec)) return false; - if(!internal::isMuchSmallerThan(coeff(j, i), maxAbsOnDiagonal, prec)) return false; - } - return true; -} - -namespace internal { - -template<> struct storage_kind_to_shape<DiagonalShape> { typedef DiagonalShape Shape; }; - -struct Diagonal2Dense {}; - -template<> struct AssignmentKind<DenseShape,DiagonalShape> { typedef Diagonal2Dense Kind; }; - -// Diagonal matrix to Dense assignment -template< typename DstXprType, typename SrcXprType, typename Functor> -struct Assignment<DstXprType, SrcXprType, Functor, Diagonal2Dense> -{ - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - dst.setZero(); - dst.diagonal() = src.diagonal(); - } - - static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/) - { dst.diagonal() += src.diagonal(); } - - static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/) - { dst.diagonal() -= src.diagonal(); } -}; - -} // namespace internal - -} // end namespace Eigen - -#endif // EIGEN_DIAGONALMATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/DiagonalProduct.h b/external/eigen/include/eigen3/Eigen/src/Core/DiagonalProduct.h deleted file mode 100644 index 7911d1cd..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/DiagonalProduct.h +++ /dev/null @@ -1,28 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DIAGONALPRODUCT_H -#define EIGEN_DIAGONALPRODUCT_H - -namespace Eigen { - -/** \returns the diagonal matrix product of \c *this by the diagonal matrix \a diagonal. - */ -template<typename Derived> -template<typename DiagonalDerived> -EIGEN_DEVICE_FUNC inline const Product<Derived, DiagonalDerived, LazyProduct> -MatrixBase<Derived>::operator*(const DiagonalBase<DiagonalDerived> &a_diagonal) const -{ - return Product<Derived, DiagonalDerived, LazyProduct>(derived(),a_diagonal.derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_DIAGONALPRODUCT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Dot.h b/external/eigen/include/eigen3/Eigen/src/Core/Dot.h deleted file mode 100644 index 11da432b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Dot.h +++ /dev/null @@ -1,318 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2008, 2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DOT_H -#define EIGEN_DOT_H - -namespace Eigen { - -namespace internal { - -// helper function for dot(). The problem is that if we put that in the body of dot(), then upon calling dot -// with mismatched types, the compiler emits errors about failing to instantiate cwiseProduct BEFORE -// looking at the static assertions. Thus this is a trick to get better compile errors. -template<typename T, typename U, -// the NeedToTranspose condition here is taken straight from Assign.h - bool NeedToTranspose = T::IsVectorAtCompileTime - && U::IsVectorAtCompileTime - && ((int(T::RowsAtCompileTime) == 1 && int(U::ColsAtCompileTime) == 1) - | // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&". - // revert to || as soon as not needed anymore. - (int(T::ColsAtCompileTime) == 1 && int(U::RowsAtCompileTime) == 1)) -> -struct dot_nocheck -{ - typedef scalar_conj_product_op<typename traits<T>::Scalar,typename traits<U>::Scalar> conj_prod; - typedef typename conj_prod::result_type ResScalar; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE - static ResScalar run(const MatrixBase<T>& a, const MatrixBase<U>& b) - { - return a.template binaryExpr<conj_prod>(b).sum(); - } -}; - -template<typename T, typename U> -struct dot_nocheck<T, U, true> -{ - typedef scalar_conj_product_op<typename traits<T>::Scalar,typename traits<U>::Scalar> conj_prod; - typedef typename conj_prod::result_type ResScalar; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE - static ResScalar run(const MatrixBase<T>& a, const MatrixBase<U>& b) - { - return a.transpose().template binaryExpr<conj_prod>(b).sum(); - } -}; - -} // end namespace internal - -/** \fn MatrixBase::dot - * \returns the dot product of *this with other. - * - * \only_for_vectors - * - * \note If the scalar type is complex numbers, then this function returns the hermitian - * (sesquilinear) dot product, conjugate-linear in the first variable and linear in the - * second variable. - * - * \sa squaredNorm(), norm() - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE -typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType -MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived) -#if !(defined(EIGEN_NO_STATIC_ASSERT) && defined(EIGEN_NO_DEBUG)) - typedef internal::scalar_conj_product_op<Scalar,typename OtherDerived::Scalar> func; - EIGEN_CHECK_BINARY_COMPATIBILIY(func,Scalar,typename OtherDerived::Scalar); -#endif - - eigen_assert(size() == other.size()); - - return internal::dot_nocheck<Derived,OtherDerived>::run(*this, other); -} - -//---------- implementation of L2 norm and related functions ---------- - -/** \returns, for vectors, the squared \em l2 norm of \c *this, and for matrices the Frobenius norm. - * In both cases, it consists in the sum of the square of all the matrix entries. - * For vectors, this is also equals to the dot product of \c *this with itself. - * - * \sa dot(), norm(), lpNorm() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename NumTraits<typename internal::traits<Derived>::Scalar>::Real MatrixBase<Derived>::squaredNorm() const -{ - return numext::real((*this).cwiseAbs2().sum()); -} - -/** \returns, for vectors, the \em l2 norm of \c *this, and for matrices the Frobenius norm. - * In both cases, it consists in the square root of the sum of the square of all the matrix entries. - * For vectors, this is also equals to the square root of the dot product of \c *this with itself. - * - * \sa lpNorm(), dot(), squaredNorm() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename NumTraits<typename internal::traits<Derived>::Scalar>::Real MatrixBase<Derived>::norm() const -{ - return numext::sqrt(squaredNorm()); -} - -/** \returns an expression of the quotient of \c *this by its own norm. - * - * \warning If the input vector is too small (i.e., this->norm()==0), - * then this function returns a copy of the input. - * - * \only_for_vectors - * - * \sa norm(), normalize() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::PlainObject -MatrixBase<Derived>::normalized() const -{ - typedef typename internal::nested_eval<Derived,2>::type _Nested; - _Nested n(derived()); - RealScalar z = n.squaredNorm(); - // NOTE: after extensive benchmarking, this conditional does not impact performance, at least on recent x86 CPU - if(z>RealScalar(0)) - return n / numext::sqrt(z); - else - return n; -} - -/** Normalizes the vector, i.e. divides it by its own norm. - * - * \only_for_vectors - * - * \warning If the input vector is too small (i.e., this->norm()==0), then \c *this is left unchanged. - * - * \sa norm(), normalized() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void MatrixBase<Derived>::normalize() -{ - RealScalar z = squaredNorm(); - // NOTE: after extensive benchmarking, this conditional does not impact performance, at least on recent x86 CPU - if(z>RealScalar(0)) - derived() /= numext::sqrt(z); -} - -/** \returns an expression of the quotient of \c *this by its own norm while avoiding underflow and overflow. - * - * \only_for_vectors - * - * This method is analogue to the normalized() method, but it reduces the risk of - * underflow and overflow when computing the norm. - * - * \warning If the input vector is too small (i.e., this->norm()==0), - * then this function returns a copy of the input. - * - * \sa stableNorm(), stableNormalize(), normalized() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::PlainObject -MatrixBase<Derived>::stableNormalized() const -{ - typedef typename internal::nested_eval<Derived,3>::type _Nested; - _Nested n(derived()); - RealScalar w = n.cwiseAbs().maxCoeff(); - RealScalar z = (n/w).squaredNorm(); - if(z>RealScalar(0)) - return n / (numext::sqrt(z)*w); - else - return n; -} - -/** Normalizes the vector while avoid underflow and overflow - * - * \only_for_vectors - * - * This method is analogue to the normalize() method, but it reduces the risk of - * underflow and overflow when computing the norm. - * - * \warning If the input vector is too small (i.e., this->norm()==0), then \c *this is left unchanged. - * - * \sa stableNorm(), stableNormalized(), normalize() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void MatrixBase<Derived>::stableNormalize() -{ - RealScalar w = cwiseAbs().maxCoeff(); - RealScalar z = (derived()/w).squaredNorm(); - if(z>RealScalar(0)) - derived() /= numext::sqrt(z)*w; -} - -//---------- implementation of other norms ---------- - -namespace internal { - -template<typename Derived, int p> -struct lpNorm_selector -{ - typedef typename NumTraits<typename traits<Derived>::Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const MatrixBase<Derived>& m) - { - EIGEN_USING_STD_MATH(pow) - return pow(m.cwiseAbs().array().pow(p).sum(), RealScalar(1)/p); - } -}; - -template<typename Derived> -struct lpNorm_selector<Derived, 1> -{ - EIGEN_DEVICE_FUNC - static inline typename NumTraits<typename traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m) - { - return m.cwiseAbs().sum(); - } -}; - -template<typename Derived> -struct lpNorm_selector<Derived, 2> -{ - EIGEN_DEVICE_FUNC - static inline typename NumTraits<typename traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m) - { - return m.norm(); - } -}; - -template<typename Derived> -struct lpNorm_selector<Derived, Infinity> -{ - typedef typename NumTraits<typename traits<Derived>::Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const MatrixBase<Derived>& m) - { - if(Derived::SizeAtCompileTime==0 || (Derived::SizeAtCompileTime==Dynamic && m.size()==0)) - return RealScalar(0); - return m.cwiseAbs().maxCoeff(); - } -}; - -} // end namespace internal - -/** \returns the \b coefficient-wise \f$ \ell^p \f$ norm of \c *this, that is, returns the p-th root of the sum of the p-th powers of the absolute values - * of the coefficients of \c *this. If \a p is the special value \a Eigen::Infinity, this function returns the \f$ \ell^\infty \f$ - * norm, that is the maximum of the absolute values of the coefficients of \c *this. - * - * In all cases, if \c *this is empty, then the value 0 is returned. - * - * \note For matrices, this function does not compute the <a href="https://en.wikipedia.org/wiki/Operator_norm">operator-norm</a>. That is, if \c *this is a matrix, then its coefficients are interpreted as a 1D vector. Nonetheless, you can easily compute the 1-norm and \f$\infty\f$-norm matrix operator norms using \link TutorialReductionsVisitorsBroadcastingReductionsNorm partial reductions \endlink. - * - * \sa norm() - */ -template<typename Derived> -template<int p> -#ifndef EIGEN_PARSED_BY_DOXYGEN -EIGEN_DEVICE_FUNC inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real -#else -EIGEN_DEVICE_FUNC MatrixBase<Derived>::RealScalar -#endif -MatrixBase<Derived>::lpNorm() const -{ - return internal::lpNorm_selector<Derived, p>::run(*this); -} - -//---------- implementation of isOrthogonal / isUnitary ---------- - -/** \returns true if *this is approximately orthogonal to \a other, - * within the precision given by \a prec. - * - * Example: \include MatrixBase_isOrthogonal.cpp - * Output: \verbinclude MatrixBase_isOrthogonal.out - */ -template<typename Derived> -template<typename OtherDerived> -bool MatrixBase<Derived>::isOrthogonal -(const MatrixBase<OtherDerived>& other, const RealScalar& prec) const -{ - typename internal::nested_eval<Derived,2>::type nested(derived()); - typename internal::nested_eval<OtherDerived,2>::type otherNested(other.derived()); - return numext::abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm(); -} - -/** \returns true if *this is approximately an unitary matrix, - * within the precision given by \a prec. In the case where the \a Scalar - * type is real numbers, a unitary matrix is an orthogonal matrix, whence the name. - * - * \note This can be used to check whether a family of vectors forms an orthonormal basis. - * Indeed, \c m.isUnitary() returns true if and only if the columns (equivalently, the rows) of m form an - * orthonormal basis. - * - * Example: \include MatrixBase_isUnitary.cpp - * Output: \verbinclude MatrixBase_isUnitary.out - */ -template<typename Derived> -bool MatrixBase<Derived>::isUnitary(const RealScalar& prec) const -{ - typename internal::nested_eval<Derived,1>::type self(derived()); - for(Index i = 0; i < cols(); ++i) - { - if(!internal::isApprox(self.col(i).squaredNorm(), static_cast<RealScalar>(1), prec)) - return false; - for(Index j = 0; j < i; ++j) - if(!internal::isMuchSmallerThan(self.col(i).dot(self.col(j)), static_cast<Scalar>(1), prec)) - return false; - } - return true; -} - -} // end namespace Eigen - -#endif // EIGEN_DOT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/EigenBase.h b/external/eigen/include/eigen3/Eigen/src/Core/EigenBase.h deleted file mode 100644 index 0c34fb65..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/EigenBase.h +++ /dev/null @@ -1,160 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_EIGENBASE_H -#define EIGEN_EIGENBASE_H - -namespace Eigen { - -/** \class EigenBase - * \ingroup Core_Module - * - * Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T). - * - * In other words, an EigenBase object is an object that can be copied into a MatrixBase. - * - * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc. - * - * Notice that this class is trivial, it is only used to disambiguate overloaded functions. - * - * \sa \blank \ref TopicClassHierarchy - */ -template<typename Derived> struct EigenBase -{ -// typedef typename internal::plain_matrix_type<Derived>::type PlainObject; - - /** \brief The interface type of indices - * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE. - * \sa StorageIndex, \ref TopicPreprocessorDirectives. - * DEPRECATED: Since Eigen 3.3, its usage is deprecated. Use Eigen::Index instead. - * Deprecation is not marked with a doxygen comment because there are too many existing usages to add the deprecation attribute. - */ - typedef Eigen::Index Index; - - // FIXME is it needed? - typedef typename internal::traits<Derived>::StorageKind StorageKind; - - /** \returns a reference to the derived object */ - EIGEN_DEVICE_FUNC - Derived& derived() { return *static_cast<Derived*>(this); } - /** \returns a const reference to the derived object */ - EIGEN_DEVICE_FUNC - const Derived& derived() const { return *static_cast<const Derived*>(this); } - - EIGEN_DEVICE_FUNC - inline Derived& const_cast_derived() const - { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); } - EIGEN_DEVICE_FUNC - inline const Derived& const_derived() const - { return *static_cast<const Derived*>(this); } - - /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ - EIGEN_DEVICE_FUNC - inline Index rows() const { return derived().rows(); } - /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ - EIGEN_DEVICE_FUNC - inline Index cols() const { return derived().cols(); } - /** \returns the number of coefficients, which is rows()*cols(). - * \sa rows(), cols(), SizeAtCompileTime. */ - EIGEN_DEVICE_FUNC - inline Index size() const { return rows() * cols(); } - - /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */ - template<typename Dest> - EIGEN_DEVICE_FUNC - inline void evalTo(Dest& dst) const - { derived().evalTo(dst); } - - /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */ - template<typename Dest> - EIGEN_DEVICE_FUNC - inline void addTo(Dest& dst) const - { - // This is the default implementation, - // derived class can reimplement it in a more optimized way. - typename Dest::PlainObject res(rows(),cols()); - evalTo(res); - dst += res; - } - - /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */ - template<typename Dest> - EIGEN_DEVICE_FUNC - inline void subTo(Dest& dst) const - { - // This is the default implementation, - // derived class can reimplement it in a more optimized way. - typename Dest::PlainObject res(rows(),cols()); - evalTo(res); - dst -= res; - } - - /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */ - template<typename Dest> - EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const - { - // This is the default implementation, - // derived class can reimplement it in a more optimized way. - dst = dst * this->derived(); - } - - /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */ - template<typename Dest> - EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const - { - // This is the default implementation, - // derived class can reimplement it in a more optimized way. - dst = this->derived() * dst; - } - -}; - -/*************************************************************************** -* Implementation of matrix base methods -***************************************************************************/ - -/** \brief Copies the generic expression \a other into *this. - * - * \details The expression must provide a (templated) evalTo(Derived& dst) const - * function which does the actual job. In practice, this allows any user to write - * its own special matrix without having to modify MatrixBase - * - * \returns a reference to *this. - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other) -{ - call_assignment(derived(), other.derived()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other) -{ - call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other) -{ - call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -} // end namespace Eigen - -#endif // EIGEN_EIGENBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/ForceAlignedAccess.h b/external/eigen/include/eigen3/Eigen/src/Core/ForceAlignedAccess.h deleted file mode 100644 index 7b08b45e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/ForceAlignedAccess.h +++ /dev/null @@ -1,146 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_FORCEALIGNEDACCESS_H -#define EIGEN_FORCEALIGNEDACCESS_H - -namespace Eigen { - -/** \class ForceAlignedAccess - * \ingroup Core_Module - * - * \brief Enforce aligned packet loads and stores regardless of what is requested - * - * \param ExpressionType the type of the object of which we are forcing aligned packet access - * - * This class is the return type of MatrixBase::forceAlignedAccess() - * and most of the time this is the only way it is used. - * - * \sa MatrixBase::forceAlignedAccess() - */ - -namespace internal { -template<typename ExpressionType> -struct traits<ForceAlignedAccess<ExpressionType> > : public traits<ExpressionType> -{}; -} - -template<typename ExpressionType> class ForceAlignedAccess - : public internal::dense_xpr_base< ForceAlignedAccess<ExpressionType> >::type -{ - public: - - typedef typename internal::dense_xpr_base<ForceAlignedAccess>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess) - - EIGEN_DEVICE_FUNC explicit inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {} - - EIGEN_DEVICE_FUNC inline Index rows() const { return m_expression.rows(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_expression.cols(); } - EIGEN_DEVICE_FUNC inline Index outerStride() const { return m_expression.outerStride(); } - EIGEN_DEVICE_FUNC inline Index innerStride() const { return m_expression.innerStride(); } - - EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index row, Index col) const - { - return m_expression.coeff(row, col); - } - - EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col) - { - return m_expression.const_cast_derived().coeffRef(row, col); - } - - EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const - { - return m_expression.coeff(index); - } - - EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index) - { - return m_expression.const_cast_derived().coeffRef(index); - } - - template<int LoadMode> - inline const PacketScalar packet(Index row, Index col) const - { - return m_expression.template packet<Aligned>(row, col); - } - - template<int LoadMode> - inline void writePacket(Index row, Index col, const PacketScalar& x) - { - m_expression.const_cast_derived().template writePacket<Aligned>(row, col, x); - } - - template<int LoadMode> - inline const PacketScalar packet(Index index) const - { - return m_expression.template packet<Aligned>(index); - } - - template<int LoadMode> - inline void writePacket(Index index, const PacketScalar& x) - { - m_expression.const_cast_derived().template writePacket<Aligned>(index, x); - } - - EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; } - - protected: - const ExpressionType& m_expression; - - private: - ForceAlignedAccess& operator=(const ForceAlignedAccess&); -}; - -/** \returns an expression of *this with forced aligned access - * \sa forceAlignedAccessIf(),class ForceAlignedAccess - */ -template<typename Derived> -inline const ForceAlignedAccess<Derived> -MatrixBase<Derived>::forceAlignedAccess() const -{ - return ForceAlignedAccess<Derived>(derived()); -} - -/** \returns an expression of *this with forced aligned access - * \sa forceAlignedAccessIf(), class ForceAlignedAccess - */ -template<typename Derived> -inline ForceAlignedAccess<Derived> -MatrixBase<Derived>::forceAlignedAccess() -{ - return ForceAlignedAccess<Derived>(derived()); -} - -/** \returns an expression of *this with forced aligned access if \a Enable is true. - * \sa forceAlignedAccess(), class ForceAlignedAccess - */ -template<typename Derived> -template<bool Enable> -inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type -MatrixBase<Derived>::forceAlignedAccessIf() const -{ - return derived(); // FIXME This should not work but apparently is never used -} - -/** \returns an expression of *this with forced aligned access if \a Enable is true. - * \sa forceAlignedAccess(), class ForceAlignedAccess - */ -template<typename Derived> -template<bool Enable> -inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type -MatrixBase<Derived>::forceAlignedAccessIf() -{ - return derived(); // FIXME This should not work but apparently is never used -} - -} // end namespace Eigen - -#endif // EIGEN_FORCEALIGNEDACCESS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Fuzzy.h b/external/eigen/include/eigen3/Eigen/src/Core/Fuzzy.h deleted file mode 100644 index 43aa49b2..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Fuzzy.h +++ /dev/null @@ -1,155 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_FUZZY_H -#define EIGEN_FUZZY_H - -namespace Eigen { - -namespace internal -{ - -template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger> -struct isApprox_selector -{ - EIGEN_DEVICE_FUNC - static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) - { - typename internal::nested_eval<Derived,2>::type nested(x); - typename internal::nested_eval<OtherDerived,2>::type otherNested(y); - return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * numext::mini(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum()); - } -}; - -template<typename Derived, typename OtherDerived> -struct isApprox_selector<Derived, OtherDerived, true> -{ - EIGEN_DEVICE_FUNC - static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar&) - { - return x.matrix() == y.matrix(); - } -}; - -template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger> -struct isMuchSmallerThan_object_selector -{ - EIGEN_DEVICE_FUNC - static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) - { - return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum(); - } -}; - -template<typename Derived, typename OtherDerived> -struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true> -{ - EIGEN_DEVICE_FUNC - static bool run(const Derived& x, const OtherDerived&, const typename Derived::RealScalar&) - { - return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix(); - } -}; - -template<typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger> -struct isMuchSmallerThan_scalar_selector -{ - EIGEN_DEVICE_FUNC - static bool run(const Derived& x, const typename Derived::RealScalar& y, const typename Derived::RealScalar& prec) - { - return x.cwiseAbs2().sum() <= numext::abs2(prec * y); - } -}; - -template<typename Derived> -struct isMuchSmallerThan_scalar_selector<Derived, true> -{ - EIGEN_DEVICE_FUNC - static bool run(const Derived& x, const typename Derived::RealScalar&, const typename Derived::RealScalar&) - { - return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix(); - } -}; - -} // end namespace internal - - -/** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \note The fuzzy compares are done multiplicatively. Two vectors \f$ v \f$ and \f$ w \f$ - * are considered to be approximately equal within precision \f$ p \f$ if - * \f[ \Vert v - w \Vert \leqslant p\,\min(\Vert v\Vert, \Vert w\Vert). \f] - * For matrices, the comparison is done using the Hilbert-Schmidt norm (aka Frobenius norm - * L2 norm). - * - * \note Because of the multiplicativeness of this comparison, one can't use this function - * to check whether \c *this is approximately equal to the zero matrix or vector. - * Indeed, \c isApprox(zero) returns false unless \c *this itself is exactly the zero matrix - * or vector. If you want to test whether \c *this is zero, use internal::isMuchSmallerThan(const - * RealScalar&, RealScalar) instead. - * - * \sa internal::isMuchSmallerThan(const RealScalar&, RealScalar) const - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApprox( - const DenseBase<OtherDerived>& other, - const RealScalar& prec -) const -{ - return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec); -} - -/** \returns \c true if the norm of \c *this is much smaller than \a other, - * within the precision determined by \a prec. - * - * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is - * considered to be much smaller than \f$ x \f$ within precision \f$ p \f$ if - * \f[ \Vert v \Vert \leqslant p\,\vert x\vert. \f] - * - * For matrices, the comparison is done using the Hilbert-Schmidt norm. For this reason, - * the value of the reference scalar \a other should come from the Hilbert-Schmidt norm - * of a reference matrix of same dimensions. - * - * \sa isApprox(), isMuchSmallerThan(const DenseBase<OtherDerived>&, RealScalar) const - */ -template<typename Derived> -EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan( - const typename NumTraits<Scalar>::Real& other, - const RealScalar& prec -) const -{ - return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec); -} - -/** \returns \c true if the norm of \c *this is much smaller than the norm of \a other, - * within the precision determined by \a prec. - * - * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is - * considered to be much smaller than a vector \f$ w \f$ within precision \f$ p \f$ if - * \f[ \Vert v \Vert \leqslant p\,\Vert w\Vert. \f] - * For matrices, the comparison is done using the Hilbert-Schmidt norm. - * - * \sa isApprox(), isMuchSmallerThan(const RealScalar&, RealScalar) const - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan( - const DenseBase<OtherDerived>& other, - const RealScalar& prec -) const -{ - return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec); -} - -} // end namespace Eigen - -#endif // EIGEN_FUZZY_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/GeneralProduct.h b/external/eigen/include/eigen3/Eigen/src/Core/GeneralProduct.h deleted file mode 100644 index bf7ef54b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/GeneralProduct.h +++ /dev/null @@ -1,467 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERAL_PRODUCT_H -#define EIGEN_GENERAL_PRODUCT_H - -namespace Eigen { - -enum { - Large = 2, - Small = 3 -}; - -// Define the threshold value to fallback from the generic matrix-matrix product -// implementation (heavy) to the lightweight coeff-based product one. -// See generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct> -// in products/GeneralMatrixMatrix.h for more details. -// TODO This threshold should also be used in the compile-time selector below. -#ifndef EIGEN_GEMM_TO_COEFFBASED_THRESHOLD -// This default value has been obtained on a Haswell architecture. -#define EIGEN_GEMM_TO_COEFFBASED_THRESHOLD 20 -#endif - -namespace internal { - -template<int Rows, int Cols, int Depth> struct product_type_selector; - -template<int Size, int MaxSize> struct product_size_category -{ - enum { - #ifndef EIGEN_GPU_COMPILE_PHASE - is_large = MaxSize == Dynamic || - Size >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD || - (Size==Dynamic && MaxSize>=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD), - #else - is_large = 0, - #endif - value = is_large ? Large - : Size == 1 ? 1 - : Small - }; -}; - -template<typename Lhs, typename Rhs> struct product_type -{ - typedef typename remove_all<Lhs>::type _Lhs; - typedef typename remove_all<Rhs>::type _Rhs; - enum { - MaxRows = traits<_Lhs>::MaxRowsAtCompileTime, - Rows = traits<_Lhs>::RowsAtCompileTime, - MaxCols = traits<_Rhs>::MaxColsAtCompileTime, - Cols = traits<_Rhs>::ColsAtCompileTime, - MaxDepth = EIGEN_SIZE_MIN_PREFER_FIXED(traits<_Lhs>::MaxColsAtCompileTime, - traits<_Rhs>::MaxRowsAtCompileTime), - Depth = EIGEN_SIZE_MIN_PREFER_FIXED(traits<_Lhs>::ColsAtCompileTime, - traits<_Rhs>::RowsAtCompileTime) - }; - - // the splitting into different lines of code here, introducing the _select enums and the typedef below, - // is to work around an internal compiler error with gcc 4.1 and 4.2. -private: - enum { - rows_select = product_size_category<Rows,MaxRows>::value, - cols_select = product_size_category<Cols,MaxCols>::value, - depth_select = product_size_category<Depth,MaxDepth>::value - }; - typedef product_type_selector<rows_select, cols_select, depth_select> selector; - -public: - enum { - value = selector::ret, - ret = selector::ret - }; -#ifdef EIGEN_DEBUG_PRODUCT - static void debug() - { - EIGEN_DEBUG_VAR(Rows); - EIGEN_DEBUG_VAR(Cols); - EIGEN_DEBUG_VAR(Depth); - EIGEN_DEBUG_VAR(rows_select); - EIGEN_DEBUG_VAR(cols_select); - EIGEN_DEBUG_VAR(depth_select); - EIGEN_DEBUG_VAR(value); - } -#endif -}; - -/* The following allows to select the kind of product at compile time - * based on the three dimensions of the product. - * This is a compile time mapping from {1,Small,Large}^3 -> {product types} */ -// FIXME I'm not sure the current mapping is the ideal one. -template<int M, int N> struct product_type_selector<M,N,1> { enum { ret = OuterProduct }; }; -template<int M> struct product_type_selector<M, 1, 1> { enum { ret = LazyCoeffBasedProductMode }; }; -template<int N> struct product_type_selector<1, N, 1> { enum { ret = LazyCoeffBasedProductMode }; }; -template<int Depth> struct product_type_selector<1, 1, Depth> { enum { ret = InnerProduct }; }; -template<> struct product_type_selector<1, 1, 1> { enum { ret = InnerProduct }; }; -template<> struct product_type_selector<Small,1, Small> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<1, Small,Small> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<Small,Small,Small> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<Small, Small, 1> { enum { ret = LazyCoeffBasedProductMode }; }; -template<> struct product_type_selector<Small, Large, 1> { enum { ret = LazyCoeffBasedProductMode }; }; -template<> struct product_type_selector<Large, Small, 1> { enum { ret = LazyCoeffBasedProductMode }; }; -template<> struct product_type_selector<1, Large,Small> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<1, Large,Large> { enum { ret = GemvProduct }; }; -template<> struct product_type_selector<1, Small,Large> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<Large,1, Small> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<Large,1, Large> { enum { ret = GemvProduct }; }; -template<> struct product_type_selector<Small,1, Large> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<Small,Small,Large> { enum { ret = GemmProduct }; }; -template<> struct product_type_selector<Large,Small,Large> { enum { ret = GemmProduct }; }; -template<> struct product_type_selector<Small,Large,Large> { enum { ret = GemmProduct }; }; -template<> struct product_type_selector<Large,Large,Large> { enum { ret = GemmProduct }; }; -template<> struct product_type_selector<Large,Small,Small> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<Small,Large,Small> { enum { ret = CoeffBasedProductMode }; }; -template<> struct product_type_selector<Large,Large,Small> { enum { ret = GemmProduct }; }; - -} // end namespace internal - -/*********************************************************************** -* Implementation of Inner Vector Vector Product -***********************************************************************/ - -// FIXME : maybe the "inner product" could return a Scalar -// instead of a 1x1 matrix ?? -// Pro: more natural for the user -// Cons: this could be a problem if in a meta unrolled algorithm a matrix-matrix -// product ends up to a row-vector times col-vector product... To tackle this use -// case, we could have a specialization for Block<MatrixType,1,1> with: operator=(Scalar x); - -/*********************************************************************** -* Implementation of Outer Vector Vector Product -***********************************************************************/ - -/*********************************************************************** -* Implementation of General Matrix Vector Product -***********************************************************************/ - -/* According to the shape/flags of the matrix we have to distinghish 3 different cases: - * 1 - the matrix is col-major, BLAS compatible and M is large => call fast BLAS-like colmajor routine - * 2 - the matrix is row-major, BLAS compatible and N is large => call fast BLAS-like rowmajor routine - * 3 - all other cases are handled using a simple loop along the outer-storage direction. - * Therefore we need a lower level meta selector. - * Furthermore, if the matrix is the rhs, then the product has to be transposed. - */ -namespace internal { - -template<int Side, int StorageOrder, bool BlasCompatible> -struct gemv_dense_selector; - -} // end namespace internal - -namespace internal { - -template<typename Scalar,int Size,int MaxSize,bool Cond> struct gemv_static_vector_if; - -template<typename Scalar,int Size,int MaxSize> -struct gemv_static_vector_if<Scalar,Size,MaxSize,false> -{ - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { eigen_internal_assert(false && "should never be called"); return 0; } -}; - -template<typename Scalar,int Size> -struct gemv_static_vector_if<Scalar,Size,Dynamic,true> -{ - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { return 0; } -}; - -template<typename Scalar,int Size,int MaxSize> -struct gemv_static_vector_if<Scalar,Size,MaxSize,true> -{ - enum { - ForceAlignment = internal::packet_traits<Scalar>::Vectorizable, - PacketSize = internal::packet_traits<Scalar>::size - }; - #if EIGEN_MAX_STATIC_ALIGN_BYTES!=0 - internal::plain_array<Scalar,EIGEN_SIZE_MIN_PREFER_FIXED(Size,MaxSize),0,EIGEN_PLAIN_ENUM_MIN(AlignedMax,PacketSize)> m_data; - EIGEN_STRONG_INLINE Scalar* data() { return m_data.array; } - #else - // Some architectures cannot align on the stack, - // => let's manually enforce alignment by allocating more data and return the address of the first aligned element. - internal::plain_array<Scalar,EIGEN_SIZE_MIN_PREFER_FIXED(Size,MaxSize)+(ForceAlignment?EIGEN_MAX_ALIGN_BYTES:0),0> m_data; - EIGEN_STRONG_INLINE Scalar* data() { - return ForceAlignment - ? reinterpret_cast<Scalar*>((internal::UIntPtr(m_data.array) & ~(std::size_t(EIGEN_MAX_ALIGN_BYTES-1))) + EIGEN_MAX_ALIGN_BYTES) - : m_data.array; - } - #endif -}; - -// The vector is on the left => transposition -template<int StorageOrder, bool BlasCompatible> -struct gemv_dense_selector<OnTheLeft,StorageOrder,BlasCompatible> -{ - template<typename Lhs, typename Rhs, typename Dest> - static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha) - { - Transpose<Dest> destT(dest); - enum { OtherStorageOrder = StorageOrder == RowMajor ? ColMajor : RowMajor }; - gemv_dense_selector<OnTheRight,OtherStorageOrder,BlasCompatible> - ::run(rhs.transpose(), lhs.transpose(), destT, alpha); - } -}; - -template<> struct gemv_dense_selector<OnTheRight,ColMajor,true> -{ - template<typename Lhs, typename Rhs, typename Dest> - static inline void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha) - { - typedef typename Lhs::Scalar LhsScalar; - typedef typename Rhs::Scalar RhsScalar; - typedef typename Dest::Scalar ResScalar; - typedef typename Dest::RealScalar RealScalar; - - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - - typedef Map<Matrix<ResScalar,Dynamic,1>, EIGEN_PLAIN_ENUM_MIN(AlignedMax,internal::packet_traits<ResScalar>::size)> MappedDest; - - ActualLhsType actualLhs = LhsBlasTraits::extract(lhs); - ActualRhsType actualRhs = RhsBlasTraits::extract(rhs); - - ResScalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(lhs) - * RhsBlasTraits::extractScalarFactor(rhs); - - // make sure Dest is a compile-time vector type (bug 1166) - typedef typename conditional<Dest::IsVectorAtCompileTime, Dest, typename Dest::ColXpr>::type ActualDest; - - enum { - // FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1 - // on, the other hand it is good for the cache to pack the vector anyways... - EvalToDestAtCompileTime = (ActualDest::InnerStrideAtCompileTime==1), - ComplexByReal = (NumTraits<LhsScalar>::IsComplex) && (!NumTraits<RhsScalar>::IsComplex), - MightCannotUseDest = ((!EvalToDestAtCompileTime) || ComplexByReal) && (ActualDest::MaxSizeAtCompileTime!=0) - }; - - typedef const_blas_data_mapper<LhsScalar,Index,ColMajor> LhsMapper; - typedef const_blas_data_mapper<RhsScalar,Index,RowMajor> RhsMapper; - RhsScalar compatibleAlpha = get_factor<ResScalar,RhsScalar>::run(actualAlpha); - - if(!MightCannotUseDest) - { - // shortcut if we are sure to be able to use dest directly, - // this ease the compiler to generate cleaner and more optimzized code for most common cases - general_matrix_vector_product - <Index,LhsScalar,LhsMapper,ColMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run( - actualLhs.rows(), actualLhs.cols(), - LhsMapper(actualLhs.data(), actualLhs.outerStride()), - RhsMapper(actualRhs.data(), actualRhs.innerStride()), - dest.data(), 1, - compatibleAlpha); - } - else - { - gemv_static_vector_if<ResScalar,ActualDest::SizeAtCompileTime,ActualDest::MaxSizeAtCompileTime,MightCannotUseDest> static_dest; - - const bool alphaIsCompatible = (!ComplexByReal) || (numext::imag(actualAlpha)==RealScalar(0)); - const bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible; - - ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(), - evalToDest ? dest.data() : static_dest.data()); - - if(!evalToDest) - { - #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN - Index size = dest.size(); - EIGEN_DENSE_STORAGE_CTOR_PLUGIN - #endif - if(!alphaIsCompatible) - { - MappedDest(actualDestPtr, dest.size()).setZero(); - compatibleAlpha = RhsScalar(1); - } - else - MappedDest(actualDestPtr, dest.size()) = dest; - } - - general_matrix_vector_product - <Index,LhsScalar,LhsMapper,ColMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run( - actualLhs.rows(), actualLhs.cols(), - LhsMapper(actualLhs.data(), actualLhs.outerStride()), - RhsMapper(actualRhs.data(), actualRhs.innerStride()), - actualDestPtr, 1, - compatibleAlpha); - - if (!evalToDest) - { - if(!alphaIsCompatible) - dest.matrix() += actualAlpha * MappedDest(actualDestPtr, dest.size()); - else - dest = MappedDest(actualDestPtr, dest.size()); - } - } - } -}; - -template<> struct gemv_dense_selector<OnTheRight,RowMajor,true> -{ - template<typename Lhs, typename Rhs, typename Dest> - static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha) - { - typedef typename Lhs::Scalar LhsScalar; - typedef typename Rhs::Scalar RhsScalar; - typedef typename Dest::Scalar ResScalar; - - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned; - - typename add_const<ActualLhsType>::type actualLhs = LhsBlasTraits::extract(lhs); - typename add_const<ActualRhsType>::type actualRhs = RhsBlasTraits::extract(rhs); - - ResScalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(lhs) - * RhsBlasTraits::extractScalarFactor(rhs); - - enum { - // FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1 - // on, the other hand it is good for the cache to pack the vector anyways... - DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime==1 || ActualRhsTypeCleaned::MaxSizeAtCompileTime==0 - }; - - gemv_static_vector_if<RhsScalar,ActualRhsTypeCleaned::SizeAtCompileTime,ActualRhsTypeCleaned::MaxSizeAtCompileTime,!DirectlyUseRhs> static_rhs; - - ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,actualRhs.size(), - DirectlyUseRhs ? const_cast<RhsScalar*>(actualRhs.data()) : static_rhs.data()); - - if(!DirectlyUseRhs) - { - #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN - Index size = actualRhs.size(); - EIGEN_DENSE_STORAGE_CTOR_PLUGIN - #endif - Map<typename ActualRhsTypeCleaned::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs; - } - - typedef const_blas_data_mapper<LhsScalar,Index,RowMajor> LhsMapper; - typedef const_blas_data_mapper<RhsScalar,Index,ColMajor> RhsMapper; - general_matrix_vector_product - <Index,LhsScalar,LhsMapper,RowMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run( - actualLhs.rows(), actualLhs.cols(), - LhsMapper(actualLhs.data(), actualLhs.outerStride()), - RhsMapper(actualRhsPtr, 1), - dest.data(), dest.col(0).innerStride(), //NOTE if dest is not a vector at compile-time, then dest.innerStride() might be wrong. (bug 1166) - actualAlpha); - } -}; - -template<> struct gemv_dense_selector<OnTheRight,ColMajor,false> -{ - template<typename Lhs, typename Rhs, typename Dest> - static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha) - { - EIGEN_STATIC_ASSERT((!nested_eval<Lhs,1>::Evaluate),EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE); - // TODO if rhs is large enough it might be beneficial to make sure that dest is sequentially stored in memory, otherwise use a temp - typename nested_eval<Rhs,1>::type actual_rhs(rhs); - const Index size = rhs.rows(); - for(Index k=0; k<size; ++k) - dest += (alpha*actual_rhs.coeff(k)) * lhs.col(k); - } -}; - -template<> struct gemv_dense_selector<OnTheRight,RowMajor,false> -{ - template<typename Lhs, typename Rhs, typename Dest> - static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha) - { - EIGEN_STATIC_ASSERT((!nested_eval<Lhs,1>::Evaluate),EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE); - typename nested_eval<Rhs,Lhs::RowsAtCompileTime>::type actual_rhs(rhs); - const Index rows = dest.rows(); - for(Index i=0; i<rows; ++i) - dest.coeffRef(i) += alpha * (lhs.row(i).cwiseProduct(actual_rhs.transpose())).sum(); - } -}; - -} // end namespace internal - -/*************************************************************************** -* Implementation of matrix base methods -***************************************************************************/ - -/** \returns the matrix product of \c *this and \a other. - * - * \note If instead of the matrix product you want the coefficient-wise product, see Cwise::operator*(). - * - * \sa lazyProduct(), operator*=(const MatrixBase&), Cwise::operator*() - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const Product<Derived, OtherDerived> -MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const -{ - // A note regarding the function declaration: In MSVC, this function will sometimes - // not be inlined since DenseStorage is an unwindable object for dynamic - // matrices and product types are holding a member to store the result. - // Thus it does not help tagging this function with EIGEN_STRONG_INLINE. - enum { - ProductIsValid = Derived::ColsAtCompileTime==Dynamic - || OtherDerived::RowsAtCompileTime==Dynamic - || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime), - AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime, - SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived) - }; - // note to the lost user: - // * for a dot product use: v1.dot(v2) - // * for a coeff-wise product use: v1.cwiseProduct(v2) - EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes), - INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS) - EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors), - INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION) - EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) -#ifdef EIGEN_DEBUG_PRODUCT - internal::product_type<Derived,OtherDerived>::debug(); -#endif - - return Product<Derived, OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the matrix product of \c *this and \a other without implicit evaluation. - * - * The returned product will behave like any other expressions: the coefficients of the product will be - * computed once at a time as requested. This might be useful in some extremely rare cases when only - * a small and no coherent fraction of the result's coefficients have to be computed. - * - * \warning This version of the matrix product can be much much slower. So use it only if you know - * what you are doing and that you measured a true speed improvement. - * - * \sa operator*(const MatrixBase&) - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const Product<Derived,OtherDerived,LazyProduct> -MatrixBase<Derived>::lazyProduct(const MatrixBase<OtherDerived> &other) const -{ - enum { - ProductIsValid = Derived::ColsAtCompileTime==Dynamic - || OtherDerived::RowsAtCompileTime==Dynamic - || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime), - AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime, - SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived) - }; - // note to the lost user: - // * for a dot product use: v1.dot(v2) - // * for a coeff-wise product use: v1.cwiseProduct(v2) - EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes), - INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS) - EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors), - INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION) - EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) - - return Product<Derived,OtherDerived,LazyProduct>(derived(), other.derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_PRODUCT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/GenericPacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/GenericPacketMath.h deleted file mode 100644 index 146d34fb..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/GenericPacketMath.h +++ /dev/null @@ -1,759 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERIC_PACKET_MATH_H -#define EIGEN_GENERIC_PACKET_MATH_H - -namespace Eigen { - -namespace internal { - -/** \internal - * \file GenericPacketMath.h - * - * Default implementation for types not supported by the vectorization. - * In practice these functions are provided to make easier the writing - * of generic vectorized code. - */ - -#ifndef EIGEN_DEBUG_ALIGNED_LOAD -#define EIGEN_DEBUG_ALIGNED_LOAD -#endif - -#ifndef EIGEN_DEBUG_UNALIGNED_LOAD -#define EIGEN_DEBUG_UNALIGNED_LOAD -#endif - -#ifndef EIGEN_DEBUG_ALIGNED_STORE -#define EIGEN_DEBUG_ALIGNED_STORE -#endif - -#ifndef EIGEN_DEBUG_UNALIGNED_STORE -#define EIGEN_DEBUG_UNALIGNED_STORE -#endif - -struct default_packet_traits -{ - enum { - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasNegate = 1, - HasAbs = 1, - HasArg = 0, - HasAbs2 = 1, - HasMin = 1, - HasMax = 1, - HasConj = 1, - HasSetLinear = 1, - HasBlend = 0, - HasReduxp = 1, - - HasDiv = 0, - HasSqrt = 0, - HasRsqrt = 0, - HasExp = 0, - HasExpm1 = 0, - HasLog = 0, - HasLog1p = 0, - HasLog10 = 0, - HasPow = 0, - - HasSin = 0, - HasCos = 0, - HasTan = 0, - HasASin = 0, - HasACos = 0, - HasATan = 0, - HasSinh = 0, - HasCosh = 0, - HasTanh = 0, - HasLGamma = 0, - HasDiGamma = 0, - HasZeta = 0, - HasPolygamma = 0, - HasErf = 0, - HasErfc = 0, - HasNdtri = 0, - HasBessel = 0, - HasIGamma = 0, - HasIGammaDerA = 0, - HasGammaSampleDerAlpha = 0, - HasIGammac = 0, - HasBetaInc = 0, - - HasRound = 0, - HasRint = 0, - HasFloor = 0, - HasCeil = 0, - - HasSign = 0 - }; -}; - -template<typename T> struct packet_traits : default_packet_traits -{ - typedef T type; - typedef T half; - enum { - Vectorizable = 0, - size = 1, - AlignedOnScalar = 0, - HasHalfPacket = 0 - }; - enum { - HasAdd = 0, - HasSub = 0, - HasMul = 0, - HasNegate = 0, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasConj = 0, - HasSetLinear = 0 - }; -}; - -template<typename T> struct packet_traits<const T> : packet_traits<T> { }; - -template <typename Src, typename Tgt> struct type_casting_traits { - enum { - VectorizedCast = 0, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - - -/** \internal \returns static_cast<TgtType>(a) (coeff-wise) */ -template <typename SrcPacket, typename TgtPacket> -EIGEN_DEVICE_FUNC inline TgtPacket -pcast(const SrcPacket& a) { - return static_cast<TgtPacket>(a); -} -template <typename SrcPacket, typename TgtPacket> -EIGEN_DEVICE_FUNC inline TgtPacket -pcast(const SrcPacket& a, const SrcPacket& /*b*/) { - return static_cast<TgtPacket>(a); -} - -template <typename SrcPacket, typename TgtPacket> -EIGEN_DEVICE_FUNC inline TgtPacket -pcast(const SrcPacket& a, const SrcPacket& /*b*/, const SrcPacket& /*c*/, const SrcPacket& /*d*/) { - return static_cast<TgtPacket>(a); -} - -/** \internal \returns reinterpret_cast<Target>(a) */ -template <typename Target, typename Packet> -EIGEN_DEVICE_FUNC inline Target -preinterpret(const Packet& a); /* { return reinterpret_cast<const Target&>(a); } */ - -/** \internal \returns a + b (coeff-wise) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -padd(const Packet& a, const Packet& b) { return a+b; } - -/** \internal \returns a - b (coeff-wise) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -psub(const Packet& a, const Packet& b) { return a-b; } - -/** \internal \returns -a (coeff-wise) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pnegate(const Packet& a) { return -a; } - -/** \internal \returns conj(a) (coeff-wise) */ - -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pconj(const Packet& a) { return numext::conj(a); } - -/** \internal \returns a * b (coeff-wise) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pmul(const Packet& a, const Packet& b) { return a*b; } - -/** \internal \returns a / b (coeff-wise) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pdiv(const Packet& a, const Packet& b) { return a/b; } - -/** \internal \returns the min of \a a and \a b (coeff-wise) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pmin(const Packet& a, const Packet& b) { return numext::mini(a, b); } - -/** \internal \returns the max of \a a and \a b (coeff-wise) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pmax(const Packet& a, const Packet& b) { return numext::maxi(a, b); } - -/** \internal \returns the absolute value of \a a */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pabs(const Packet& a) { using std::abs; return abs(a); } - -/** \internal \returns the phase angle of \a a */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -parg(const Packet& a) { using numext::arg; return arg(a); } - -/** \internal \returns the bitwise and of \a a and \a b */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pand(const Packet& a, const Packet& b) { return a & b; } - -/** \internal \returns the bitwise or of \a a and \a b */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -por(const Packet& a, const Packet& b) { return a | b; } - -/** \internal \returns the bitwise xor of \a a and \a b */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pxor(const Packet& a, const Packet& b) { return a ^ b; } - -/** \internal \returns the bitwise andnot of \a a and \a b */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pandnot(const Packet& a, const Packet& b) { return a & (~b); } - -/** \internal \returns ones */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -ptrue(const Packet& /*a*/) { Packet b; memset((void*)&b, 0xff, sizeof(b)); return b;} - -template <typename RealScalar> -EIGEN_DEVICE_FUNC inline std::complex<RealScalar> ptrue(const std::complex<RealScalar>& /*a*/) { - RealScalar b; - b = ptrue(b); - return std::complex<RealScalar>(b, b); -} - -/** \internal \returns the bitwise not of \a a */ -template <typename Packet> EIGEN_DEVICE_FUNC inline Packet -pnot(const Packet& a) { return pxor(ptrue(a), a);} - -/** \internal \returns \a a shifted by N bits to the right */ -template<int N> EIGEN_DEVICE_FUNC inline int -pshiftright(const int& a) { return a >> N; } -template<int N> EIGEN_DEVICE_FUNC inline long int -pshiftright(const long int& a) { return a >> N; } - -/** \internal \returns \a a shifted by N bits to the left */ -template<int N> EIGEN_DEVICE_FUNC inline int -pshiftleft(const int& a) { return a << N; } -template<int N> EIGEN_DEVICE_FUNC inline long int -pshiftleft(const long int& a) { return a << N; } - -/** \internal \returns the significant and exponent of the underlying floating point numbers - * See https://en.cppreference.com/w/cpp/numeric/math/frexp - */ -template <typename Packet> -EIGEN_DEVICE_FUNC inline Packet pfrexp(const Packet& a, Packet& exponent) { - int exp; - EIGEN_USING_STD_MATH(frexp); - Packet result = frexp(a, &exp); - exponent = static_cast<Packet>(exp); - return result; -} - -/** \internal \returns a * 2^exponent - * See https://en.cppreference.com/w/cpp/numeric/math/ldexp - */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pldexp(const Packet &a, const Packet &exponent) { - EIGEN_USING_STD_MATH(ldexp); - return ldexp(a, static_cast<int>(exponent)); -} - -/** \internal \returns zeros */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pzero(const Packet& a) { return pxor(a,a); } - -template<> EIGEN_DEVICE_FUNC inline float pzero<float>(const float& a) { - EIGEN_UNUSED_VARIABLE(a); - return 0.f; -} - -template<> EIGEN_DEVICE_FUNC inline double pzero<double>(const double& a) { - EIGEN_UNUSED_VARIABLE(a); - return 0.; -} - -/** \internal \returns bits of \a or \b according to the input bit mask \a mask */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pselect(const Packet& mask, const Packet& a, const Packet& b) { - return por(pand(a,mask),pandnot(b,mask)); -} - -template<> EIGEN_DEVICE_FUNC inline float pselect<float>( - const float& mask, const float& a, const float&b) { - return numext::equal_strict(mask,0.f) ? b : a; -} - -template<> EIGEN_DEVICE_FUNC inline double pselect<double>( - const double& mask, const double& a, const double& b) { - return numext::equal_strict(mask,0.) ? b : a; -} - -/** \internal \returns a <= b as a bit mask */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pcmp_le(const Packet& a, const Packet& b) { return a<=b ? ptrue(a) : pzero(a); } - -/** \internal \returns a < b as a bit mask */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pcmp_lt(const Packet& a, const Packet& b) { return a<b ? ptrue(a) : pzero(a); } - -/** \internal \returns a == b as a bit mask */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pcmp_eq(const Packet& a, const Packet& b) { return a==b ? ptrue(a) : pzero(a); } - -/** \internal \returns a < b or a==NaN or b==NaN as a bit mask */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pcmp_lt_or_nan(const Packet& a, const Packet& b) { return pnot(pcmp_le(b,a)); } - -/** \internal \returns a packet version of \a *from, from must be 16 bytes aligned */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pload(const typename unpacket_traits<Packet>::type* from) { return *from; } - -/** \internal \returns a packet version of \a *from, (un-aligned load) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -ploadu(const typename unpacket_traits<Packet>::type* from) { return *from; } - -/** \internal \returns a packet version of \a *from, (un-aligned masked load) - * There is no generic implementation. We only have implementations for specialized - * cases. Generic case should not be called. - */ -template<typename Packet> EIGEN_DEVICE_FUNC inline -typename enable_if<unpacket_traits<Packet>::masked_load_available, Packet>::type -ploadu(const typename unpacket_traits<Packet>::type* from, typename unpacket_traits<Packet>::mask_t umask); - -/** \internal \returns a packet with constant coefficients \a a, e.g.: (a,a,a,a) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pset1(const typename unpacket_traits<Packet>::type& a) { return a; } - -/** \internal \returns a packet with constant coefficients set from bits */ -template<typename Packet,typename BitsType> EIGEN_DEVICE_FUNC inline Packet -pset1frombits(BitsType a); - -/** \internal \returns a packet with constant coefficients \a a[0], e.g.: (a[0],a[0],a[0],a[0]) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pload1(const typename unpacket_traits<Packet>::type *a) { return pset1<Packet>(*a); } - -/** \internal \returns a packet with elements of \a *from duplicated. - * For instance, for a packet of 8 elements, 4 scalars will be read from \a *from and - * duplicated to form: {from[0],from[0],from[1],from[1],from[2],from[2],from[3],from[3]} - * Currently, this function is only used for scalar * complex products. - */ -template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet -ploaddup(const typename unpacket_traits<Packet>::type* from) { return *from; } - -/** \internal \returns a packet with elements of \a *from quadrupled. - * For instance, for a packet of 8 elements, 2 scalars will be read from \a *from and - * replicated to form: {from[0],from[0],from[0],from[0],from[1],from[1],from[1],from[1]} - * Currently, this function is only used in matrix products. - * For packet-size smaller or equal to 4, this function is equivalent to pload1 - */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -ploadquad(const typename unpacket_traits<Packet>::type* from) -{ return pload1<Packet>(from); } - -/** \internal equivalent to - * \code - * a0 = pload1(a+0); - * a1 = pload1(a+1); - * a2 = pload1(a+2); - * a3 = pload1(a+3); - * \endcode - * \sa pset1, pload1, ploaddup, pbroadcast2 - */ -template<typename Packet> EIGEN_DEVICE_FUNC -inline void pbroadcast4(const typename unpacket_traits<Packet>::type *a, - Packet& a0, Packet& a1, Packet& a2, Packet& a3) -{ - a0 = pload1<Packet>(a+0); - a1 = pload1<Packet>(a+1); - a2 = pload1<Packet>(a+2); - a3 = pload1<Packet>(a+3); -} - -/** \internal equivalent to - * \code - * a0 = pload1(a+0); - * a1 = pload1(a+1); - * \endcode - * \sa pset1, pload1, ploaddup, pbroadcast4 - */ -template<typename Packet> EIGEN_DEVICE_FUNC -inline void pbroadcast2(const typename unpacket_traits<Packet>::type *a, - Packet& a0, Packet& a1) -{ - a0 = pload1<Packet>(a+0); - a1 = pload1<Packet>(a+1); -} - -/** \internal \brief Returns a packet with coefficients (a,a+1,...,a+packet_size-1). */ -template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet -plset(const typename unpacket_traits<Packet>::type& a) { return a; } - -/** \internal copy the packet \a from to \a *to, \a to must be 16 bytes aligned */ -template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pstore(Scalar* to, const Packet& from) -{ (*to) = from; } - -/** \internal copy the packet \a from to \a *to, (un-aligned store) */ -template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pstoreu(Scalar* to, const Packet& from) -{ (*to) = from; } - -/** \internal copy the packet \a from to \a *to, (un-aligned store with a mask) - * There is no generic implementation. We only have implementations for specialized - * cases. Generic case should not be called. - */ -template<typename Scalar, typename Packet> -EIGEN_DEVICE_FUNC inline -typename enable_if<unpacket_traits<Packet>::masked_store_available, void>::type -pstoreu(Scalar* to, const Packet& from, typename unpacket_traits<Packet>::mask_t umask); - - template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline Packet pgather(const Scalar* from, Index /*stride*/) - { return ploadu<Packet>(from); } - - template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pscatter(Scalar* to, const Packet& from, Index /*stride*/) - { pstore(to, from); } - -/** \internal tries to do cache prefetching of \a addr */ -template<typename Scalar> EIGEN_DEVICE_FUNC inline void prefetch(const Scalar* addr) -{ -#if defined(EIGEN_HIP_DEVICE_COMPILE) - // do nothing -#elif defined(EIGEN_CUDA_ARCH) -#if defined(__LP64__) - // 64-bit pointer operand constraint for inlined asm - asm(" prefetch.L1 [ %1 ];" : "=l"(addr) : "l"(addr)); -#else - // 32-bit pointer operand constraint for inlined asm - asm(" prefetch.L1 [ %1 ];" : "=r"(addr) : "r"(addr)); -#endif -#elif (!EIGEN_COMP_MSVC) && (EIGEN_COMP_GNUC || EIGEN_COMP_CLANG || EIGEN_COMP_ICC) - __builtin_prefetch(addr); -#endif -} - -/** \internal \returns the first element of a packet */ -template<typename Packet> EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type pfirst(const Packet& a) -{ return a; } - -/** \internal \returns a packet where the element i contains the sum of the packet of \a vec[i] */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -preduxp(const Packet* vecs) { return vecs[0]; } - -/** \internal \returns the sum of the elements of \a a*/ -template<typename Packet> EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux(const Packet& a) -{ return a; } - -/** \internal \returns the sum of the elements of upper and lower half of \a a if \a a is larger than 4. - * For a packet {a0, a1, a2, a3, a4, a5, a6, a7}, it returns a half packet {a0+a4, a1+a5, a2+a6, a3+a7} - * For packet-size smaller or equal to 4, this boils down to a noop. - */ -template<typename Packet> EIGEN_DEVICE_FUNC inline -typename conditional<(unpacket_traits<Packet>::size%8)==0,typename unpacket_traits<Packet>::half,Packet>::type -predux_half_dowto4(const Packet& a) -{ return a; } - -/** \internal \returns the product of the elements of \a a */ -template<typename Packet> EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_mul(const Packet& a) -{ return a; } - -/** \internal \returns the min of the elements of \a a */ -template<typename Packet> EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_min(const Packet& a) -{ return a; } - -/** \internal \returns the max of the elements of \a a */ -template<typename Packet> EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_max(const Packet& a) -{ return a; } - -/** \internal \returns true if all coeffs of \a a means "true" - * It is supposed to be called on values returned by pcmp_*. - */ -// not needed yet -// template<typename Packet> EIGEN_DEVICE_FUNC inline bool predux_all(const Packet& a) -// { return bool(a); } - -/** \internal \returns true if any coeffs of \a a means "true" - * It is supposed to be called on values returned by pcmp_*. - */ -template<typename Packet> EIGEN_DEVICE_FUNC inline bool predux_any(const Packet& a) -{ - // Dirty but generic implementation where "true" is assumed to be non 0 and all the sames. - // It is expected that "true" is either: - // - Scalar(1) - // - bits full of ones (NaN for floats), - // - or first bit equals to 1 (1 for ints, smallest denormal for floats). - // For all these cases, taking the sum is just fine, and this boils down to a no-op for scalars. - return bool(predux(a)); -} - -/** \internal \returns the reversed elements of \a a*/ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet preverse(const Packet& a) -{ return a; } - -/** \internal \returns \a a with real and imaginary part flipped (for complex type only) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pcplxflip(const Packet& a) -{ - return Packet(numext::imag(a),numext::real(a)); -} - -/************************** -* Special math functions -***************************/ - -/** \internal \returns the sine of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet psin(const Packet& a) { EIGEN_USING_STD_MATH(sin); return sin(a); } - -/** \internal \returns the cosine of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pcos(const Packet& a) { EIGEN_USING_STD_MATH(cos); return cos(a); } - -/** \internal \returns the tan of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet ptan(const Packet& a) { EIGEN_USING_STD_MATH(tan); return tan(a); } - -/** \internal \returns the arc sine of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pasin(const Packet& a) { EIGEN_USING_STD_MATH(asin); return asin(a); } - -/** \internal \returns the arc cosine of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pacos(const Packet& a) { EIGEN_USING_STD_MATH(acos); return acos(a); } - -/** \internal \returns the arc tangent of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet patan(const Packet& a) { EIGEN_USING_STD_MATH(atan); return atan(a); } - -/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet psinh(const Packet& a) { EIGEN_USING_STD_MATH(sinh); return sinh(a); } - -/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pcosh(const Packet& a) { EIGEN_USING_STD_MATH(cosh); return cosh(a); } - -/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet ptanh(const Packet& a) { EIGEN_USING_STD_MATH(tanh); return tanh(a); } - -/** \internal \returns the exp of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pexp(const Packet& a) { EIGEN_USING_STD_MATH(exp); return exp(a); } - -/** \internal \returns the expm1 of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pexpm1(const Packet& a) { return numext::expm1(a); } - -/** \internal \returns the log of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet plog(const Packet& a) { EIGEN_USING_STD_MATH(log); return log(a); } - -/** \internal \returns the log1p of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet plog1p(const Packet& a) { return numext::log1p(a); } - -/** \internal \returns the log10 of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet plog10(const Packet& a) { EIGEN_USING_STD_MATH(log10); return log10(a); } - -/** \internal \returns the square-root of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet psqrt(const Packet& a) { EIGEN_USING_STD_MATH(sqrt); return sqrt(a); } - -/** \internal \returns the reciprocal square-root of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet prsqrt(const Packet& a) { - return pdiv(pset1<Packet>(1), psqrt(a)); -} - -/** \internal \returns the rounded value of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pround(const Packet& a) { using numext::round; return round(a); } - -/** \internal \returns the floor of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pfloor(const Packet& a) { using numext::floor; return floor(a); } - -/** \internal \returns the rounded value of \a a (coeff-wise) with current - * rounding mode */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet print(const Packet& a) { using numext::rint; return rint(a); } - -/** \internal \returns the ceil of \a a (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pceil(const Packet& a) { using numext::ceil; return ceil(a); } - -/*************************************************************************** -* The following functions might not have to be overwritten for vectorized types -***************************************************************************/ - -/** \internal copy a packet with constant coefficient \a a (e.g., [a,a,a,a]) to \a *to. \a to must be 16 bytes aligned */ -// NOTE: this function must really be templated on the packet type (think about different packet types for the same scalar type) -template<typename Packet> -inline void pstore1(typename unpacket_traits<Packet>::type* to, const typename unpacket_traits<Packet>::type& a) -{ - pstore(to, pset1<Packet>(a)); -} - -/** \internal \returns a * b + c (coeff-wise) */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pmadd(const Packet& a, - const Packet& b, - const Packet& c) -{ return padd(pmul(a, b),c); } - -/** \internal \returns a packet version of \a *from. - * The pointer \a from must be aligned on a \a Alignment bytes boundary. */ -template<typename Packet, int Alignment> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt(const typename unpacket_traits<Packet>::type* from) -{ - if(Alignment >= unpacket_traits<Packet>::alignment) - return pload<Packet>(from); - else - return ploadu<Packet>(from); -} - -/** \internal copy the packet \a from to \a *to. - * The pointer \a from must be aligned on a \a Alignment bytes boundary. */ -template<typename Scalar, typename Packet, int Alignment> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret(Scalar* to, const Packet& from) -{ - if(Alignment >= unpacket_traits<Packet>::alignment) - pstore(to, from); - else - pstoreu(to, from); -} - -/** \internal \returns a packet version of \a *from. - * Unlike ploadt, ploadt_ro takes advantage of the read-only memory path on the - * hardware if available to speedup the loading of data that won't be modified - * by the current computation. - */ -template<typename Packet, int LoadMode> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt_ro(const typename unpacket_traits<Packet>::type* from) -{ - return ploadt<Packet, LoadMode>(from); -} - -/** \internal default implementation of palign() allowing partial specialization */ -template<int Offset,typename PacketType> -struct palign_impl -{ - // by default data are aligned, so there is nothing to be done :) - static inline void run(PacketType&, const PacketType&) {} -}; - -/** \internal update \a first using the concatenation of the packet_size minus \a Offset last elements - * of \a first and \a Offset first elements of \a second. - * - * This function is currently only used to optimize matrix-vector products on unligned matrices. - * It takes 2 packets that represent a contiguous memory array, and returns a packet starting - * at the position \a Offset. For instance, for packets of 4 elements, we have: - * Input: - * - first = {f0,f1,f2,f3} - * - second = {s0,s1,s2,s3} - * Output: - * - if Offset==0 then {f0,f1,f2,f3} - * - if Offset==1 then {f1,f2,f3,s0} - * - if Offset==2 then {f2,f3,s0,s1} - * - if Offset==3 then {f3,s0,s1,s3} - */ -template<int Offset,typename PacketType> -inline void palign(PacketType& first, const PacketType& second) -{ - palign_impl<Offset,PacketType>::run(first,second); -} - -/*************************************************************************** -* Fast complex products (GCC generates a function call which is very slow) -***************************************************************************/ - -// Eigen+CUDA does not support complexes. -#if !defined(EIGEN_GPUCC) - -template<> inline std::complex<float> pmul(const std::complex<float>& a, const std::complex<float>& b) -{ return std::complex<float>(a.real()*b.real() - a.imag()*b.imag(), a.imag()*b.real() + a.real()*b.imag()); } - -template<> inline std::complex<double> pmul(const std::complex<double>& a, const std::complex<double>& b) -{ return std::complex<double>(a.real()*b.real() - a.imag()*b.imag(), a.imag()*b.real() + a.real()*b.imag()); } - -#endif - - -/*************************************************************************** - * PacketBlock, that is a collection of N packets where the number of words - * in the packet is a multiple of N. -***************************************************************************/ -template <typename Packet,int N=unpacket_traits<Packet>::size> struct PacketBlock { - Packet packet[N]; -}; - -template<typename Packet> EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet,1>& /*kernel*/) { - // Nothing to do in the scalar case, i.e. a 1x1 matrix. -} - -/*************************************************************************** - * Selector, i.e. vector of N boolean values used to select (i.e. blend) - * words from 2 packets. -***************************************************************************/ -template <size_t N> struct Selector { - bool select[N]; -}; - -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pblend(const Selector<unpacket_traits<Packet>::size>& ifPacket, const Packet& thenPacket, const Packet& elsePacket) { - return ifPacket.select[0] ? thenPacket : elsePacket; -} - -/** \internal \returns \a a with the first coefficient replaced by the scalar b */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pinsertfirst(const Packet& a, typename unpacket_traits<Packet>::type b) -{ - // Default implementation based on pblend. - // It must be specialized for higher performance. - Selector<unpacket_traits<Packet>::size> mask; - mask.select[0] = true; - // This for loop should be optimized away by the compiler. - for(Index i=1; i<unpacket_traits<Packet>::size; ++i) - mask.select[i] = false; - return pblend(mask, pset1<Packet>(b), a); -} - -/** \internal \returns \a a with the last coefficient replaced by the scalar b */ -template<typename Packet> EIGEN_DEVICE_FUNC inline Packet -pinsertlast(const Packet& a, typename unpacket_traits<Packet>::type b) -{ - // Default implementation based on pblend. - // It must be specialized for higher performance. - Selector<unpacket_traits<Packet>::size> mask; - // This for loop should be optimized away by the compiler. - for(Index i=0; i<unpacket_traits<Packet>::size-1; ++i) - mask.select[i] = false; - mask.select[unpacket_traits<Packet>::size-1] = true; - return pblend(mask, pset1<Packet>(b), a); -} - -/*************************************************************************** - * Some generic implementations to be used by implementors -***************************************************************************/ - -/** Default implementation of pfrexp for float. - * It is expected to be called by implementers of template<> pfrexp. - */ -template<typename Packet> EIGEN_STRONG_INLINE Packet -pfrexp_float(const Packet& a, Packet& exponent); - -/** Default implementation of pldexp for float. - * It is expected to be called by implementers of template<> pldexp. - */ -template<typename Packet> EIGEN_STRONG_INLINE Packet -pldexp_float(Packet a, Packet exponent); - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_GENERIC_PACKET_MATH_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/GlobalFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/GlobalFunctions.h deleted file mode 100644 index 8d54f92d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/GlobalFunctions.h +++ /dev/null @@ -1,193 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010-2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GLOBAL_FUNCTIONS_H -#define EIGEN_GLOBAL_FUNCTIONS_H - -#ifdef EIGEN_PARSED_BY_DOXYGEN - -#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR,DOC_OP,DOC_DETAILS) \ - /** \returns an expression of the coefficient-wise DOC_OP of \a x - - DOC_DETAILS - - \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_##NAME">Math functions</a>, class CwiseUnaryOp - */ \ - template<typename Derived> \ - inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \ - NAME(const Eigen::ArrayBase<Derived>& x); - -#else - -#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR,DOC_OP,DOC_DETAILS) \ - template<typename Derived> \ - inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \ - (NAME)(const Eigen::ArrayBase<Derived>& x) { \ - return Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived>(x.derived()); \ - } - -#endif // EIGEN_PARSED_BY_DOXYGEN - -#define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME,FUNCTOR) \ - \ - template<typename Derived> \ - struct NAME##_retval<ArrayBase<Derived> > \ - { \ - typedef const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> type; \ - }; \ - template<typename Derived> \ - struct NAME##_impl<ArrayBase<Derived> > \ - { \ - static inline typename NAME##_retval<ArrayBase<Derived> >::type run(const Eigen::ArrayBase<Derived>& x) \ - { \ - return typename NAME##_retval<ArrayBase<Derived> >::type(x.derived()); \ - } \ - }; - -namespace Eigen -{ - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real,scalar_real_op,real part,\sa ArrayBase::real) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(imag,scalar_imag_op,imaginary part,\sa ArrayBase::imag) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(conj,scalar_conjugate_op,complex conjugate,\sa ArrayBase::conjugate) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(inverse,scalar_inverse_op,inverse,\sa ArrayBase::inverse) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sin,scalar_sin_op,sine,\sa ArrayBase::sin) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cos,scalar_cos_op,cosine,\sa ArrayBase::cos) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tan,scalar_tan_op,tangent,\sa ArrayBase::tan) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atan,scalar_atan_op,arc-tangent,\sa ArrayBase::atan) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asin,scalar_asin_op,arc-sine,\sa ArrayBase::asin) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acos,scalar_acos_op,arc-consine,\sa ArrayBase::acos) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op,hyperbolic sine,\sa ArrayBase::sinh) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op,hyperbolic cosine,\sa ArrayBase::cosh) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op,hyperbolic tangent,\sa ArrayBase::tanh) -#if EIGEN_HAS_CXX11_MATH - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asinh,scalar_asinh_op,inverse hyperbolic sine,\sa ArrayBase::asinh) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acosh,scalar_acosh_op,inverse hyperbolic cosine,\sa ArrayBase::acosh) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atanh,scalar_atanh_op,inverse hyperbolic tangent,\sa ArrayBase::atanh) -#endif - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(logistic,scalar_logistic_op,logistic function,\sa ArrayBase::logistic) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op,natural logarithm of the gamma function,\sa ArrayBase::lgamma) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op,derivative of lgamma,\sa ArrayBase::digamma) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op,error function,\sa ArrayBase::erf) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erfc,scalar_erfc_op,complement error function,\sa ArrayBase::erfc) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ndtri,scalar_ndtri_op,inverse normal distribution function,\sa ArrayBase::ndtri) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp,scalar_exp_op,exponential,\sa ArrayBase::exp) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(expm1,scalar_expm1_op,exponential of a value minus 1,\sa ArrayBase::expm1) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op,natural logarithm,\sa Eigen::log10 DOXCOMMA ArrayBase::log) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log1p,scalar_log1p_op,natural logarithm of 1 plus the value,\sa ArrayBase::log1p) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log10,scalar_log10_op,base 10 logarithm,\sa Eigen::log DOXCOMMA ArrayBase::log) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs,scalar_abs_op,absolute value,\sa ArrayBase::abs DOXCOMMA MatrixBase::cwiseAbs) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs2,scalar_abs2_op,squared absolute value,\sa ArrayBase::abs2 DOXCOMMA MatrixBase::cwiseAbs2) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(arg,scalar_arg_op,complex argument,\sa ArrayBase::arg) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sqrt,scalar_sqrt_op,square root,\sa ArrayBase::sqrt DOXCOMMA MatrixBase::cwiseSqrt) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(rsqrt,scalar_rsqrt_op,reciprocal square root,\sa ArrayBase::rsqrt) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(square,scalar_square_op,square (power 2),\sa Eigen::abs2 DOXCOMMA Eigen::pow DOXCOMMA ArrayBase::square) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cube,scalar_cube_op,cube (power 3),\sa Eigen::pow DOXCOMMA ArrayBase::cube) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(rint,scalar_rint_op,nearest integer,\sa Eigen::floor DOXCOMMA Eigen::ceil DOXCOMMA ArrayBase::round) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round,scalar_round_op,nearest integer,\sa Eigen::floor DOXCOMMA Eigen::ceil DOXCOMMA ArrayBase::round) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(floor,scalar_floor_op,nearest integer not greater than the giben value,\sa Eigen::ceil DOXCOMMA ArrayBase::floor) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ceil,scalar_ceil_op,nearest integer not less than the giben value,\sa Eigen::floor DOXCOMMA ArrayBase::ceil) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isnan,scalar_isnan_op,not-a-number test,\sa Eigen::isinf DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isnan) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op,infinite value test,\sa Eigen::isnan DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isinf) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op,finite value test,\sa Eigen::isinf DOXCOMMA Eigen::isnan DOXCOMMA ArrayBase::isfinite) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sign,scalar_sign_op,sign (or 0),\sa ArrayBase::sign) - - /** \returns an expression of the coefficient-wise power of \a x to the given constant \a exponent. - * - * \tparam ScalarExponent is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression (\c Derived::Scalar). - * - * \sa ArrayBase::pow() - * - * \relates ArrayBase - */ -#ifdef EIGEN_PARSED_BY_DOXYGEN - template<typename Derived,typename ScalarExponent> - inline const CwiseBinaryOp<internal::scalar_pow_op<Derived::Scalar,ScalarExponent>,Derived,Constant<ScalarExponent> > - pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent); -#else - template <typename Derived,typename ScalarExponent> - EIGEN_DEVICE_FUNC inline - EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE( - const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<typename Derived::Scalar - EIGEN_COMMA ScalarExponent EIGEN_COMMA - EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type,pow)) - pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent) - { - typedef typename internal::promote_scalar_arg<typename Derived::Scalar,ScalarExponent, - EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type PromotedExponent; - return EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,PromotedExponent,pow)(x.derived(), - typename internal::plain_constant_type<Derived,PromotedExponent>::type(x.derived().rows(), x.derived().cols(), internal::scalar_constant_op<PromotedExponent>(exponent))); - } -#endif - - /** \returns an expression of the coefficient-wise power of \a x to the given array of \a exponents. - * - * This function computes the coefficient-wise power. - * - * Example: \include Cwise_array_power_array.cpp - * Output: \verbinclude Cwise_array_power_array.out - * - * \sa ArrayBase::pow() - * - * \relates ArrayBase - */ - template<typename Derived,typename ExponentDerived> - inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived> - pow(const Eigen::ArrayBase<Derived>& x, const Eigen::ArrayBase<ExponentDerived>& exponents) - { - return Eigen::CwiseBinaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived>( - x.derived(), - exponents.derived() - ); - } - - /** \returns an expression of the coefficient-wise power of the scalar \a x to the given array of \a exponents. - * - * This function computes the coefficient-wise power between a scalar and an array of exponents. - * - * \tparam Scalar is the scalar type of \a x. It must be compatible with the scalar type of the given array expression (\c Derived::Scalar). - * - * Example: \include Cwise_scalar_power_array.cpp - * Output: \verbinclude Cwise_scalar_power_array.out - * - * \sa ArrayBase::pow() - * - * \relates ArrayBase - */ -#ifdef EIGEN_PARSED_BY_DOXYGEN - template<typename Scalar,typename Derived> - inline const CwiseBinaryOp<internal::scalar_pow_op<Scalar,Derived::Scalar>,Constant<Scalar>,Derived> - pow(const Scalar& x,const Eigen::ArrayBase<Derived>& x); -#else - template <typename Scalar, typename Derived> - EIGEN_DEVICE_FUNC inline - EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE( - const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<typename Derived::Scalar - EIGEN_COMMA Scalar EIGEN_COMMA - EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type,Derived,pow)) - pow(const Scalar& x, const Eigen::ArrayBase<Derived>& exponents) { - typedef typename internal::promote_scalar_arg<typename Derived::Scalar,Scalar, - EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type PromotedScalar; - return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedScalar,Derived,pow)( - typename internal::plain_constant_type<Derived,PromotedScalar>::type(exponents.derived().rows(), exponents.derived().cols(), internal::scalar_constant_op<PromotedScalar>(x)), exponents.derived()); - } -#endif - - - namespace internal - { - EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(real,scalar_real_op) - EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(imag,scalar_imag_op) - EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(abs2,scalar_abs2_op) - } -} - -// TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, internal::isApprox...) - -#endif // EIGEN_GLOBAL_FUNCTIONS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/IO.h b/external/eigen/include/eigen3/Eigen/src/Core/IO.h deleted file mode 100644 index e81c3152..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/IO.h +++ /dev/null @@ -1,258 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_IO_H -#define EIGEN_IO_H - -namespace Eigen { - -enum { DontAlignCols = 1 }; -enum { StreamPrecision = -1, - FullPrecision = -2 }; - -namespace internal { -template<typename Derived> -std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat& fmt); -} - -/** \class IOFormat - * \ingroup Core_Module - * - * \brief Stores a set of parameters controlling the way matrices are printed - * - * List of available parameters: - * - \b precision number of digits for floating point values, or one of the special constants \c StreamPrecision and \c FullPrecision. - * The default is the special value \c StreamPrecision which means to use the - * stream's own precision setting, as set for instance using \c cout.precision(3). The other special value - * \c FullPrecision means that the number of digits will be computed to match the full precision of each floating-point - * type. - * - \b flags an OR-ed combination of flags, the default value is 0, the only currently available flag is \c DontAlignCols which - * allows to disable the alignment of columns, resulting in faster code. - * - \b coeffSeparator string printed between two coefficients of the same row - * - \b rowSeparator string printed between two rows - * - \b rowPrefix string printed at the beginning of each row - * - \b rowSuffix string printed at the end of each row - * - \b matPrefix string printed at the beginning of the matrix - * - \b matSuffix string printed at the end of the matrix - * - \b fill character printed to fill the empty space in aligned columns - * - * Example: \include IOFormat.cpp - * Output: \verbinclude IOFormat.out - * - * \sa DenseBase::format(), class WithFormat - */ -struct IOFormat -{ - /** Default constructor, see class IOFormat for the meaning of the parameters */ - IOFormat(int _precision = StreamPrecision, int _flags = 0, - const std::string& _coeffSeparator = " ", - const std::string& _rowSeparator = "\n", const std::string& _rowPrefix="", const std::string& _rowSuffix="", - const std::string& _matPrefix="", const std::string& _matSuffix="", const char _fill=' ') - : matPrefix(_matPrefix), matSuffix(_matSuffix), rowPrefix(_rowPrefix), rowSuffix(_rowSuffix), rowSeparator(_rowSeparator), - rowSpacer(""), coeffSeparator(_coeffSeparator), fill(_fill), precision(_precision), flags(_flags) - { - // TODO check if rowPrefix, rowSuffix or rowSeparator contains a newline - // don't add rowSpacer if columns are not to be aligned - if((flags & DontAlignCols)) - return; - int i = int(matSuffix.length())-1; - while (i>=0 && matSuffix[i]!='\n') - { - rowSpacer += ' '; - i--; - } - } - std::string matPrefix, matSuffix; - std::string rowPrefix, rowSuffix, rowSeparator, rowSpacer; - std::string coeffSeparator; - char fill; - int precision; - int flags; -}; - -/** \class WithFormat - * \ingroup Core_Module - * - * \brief Pseudo expression providing matrix output with given format - * - * \tparam ExpressionType the type of the object on which IO stream operations are performed - * - * This class represents an expression with stream operators controlled by a given IOFormat. - * It is the return type of DenseBase::format() - * and most of the time this is the only way it is used. - * - * See class IOFormat for some examples. - * - * \sa DenseBase::format(), class IOFormat - */ -template<typename ExpressionType> -class WithFormat -{ - public: - - WithFormat(const ExpressionType& matrix, const IOFormat& format) - : m_matrix(matrix), m_format(format) - {} - - friend std::ostream & operator << (std::ostream & s, const WithFormat& wf) - { - return internal::print_matrix(s, wf.m_matrix.eval(), wf.m_format); - } - - protected: - typename ExpressionType::Nested m_matrix; - IOFormat m_format; -}; - -namespace internal { - -// NOTE: This helper is kept for backward compatibility with previous code specializing -// this internal::significant_decimals_impl structure. In the future we should directly -// call digits10() which has been introduced in July 2016 in 3.3. -template<typename Scalar> -struct significant_decimals_impl -{ - static inline int run() - { - return NumTraits<Scalar>::digits10(); - } -}; - -/** \internal - * print the matrix \a _m to the output stream \a s using the output format \a fmt */ -template<typename Derived> -std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat& fmt) -{ - using internal::is_same; - using internal::conditional; - - if(_m.size() == 0) - { - s << fmt.matPrefix << fmt.matSuffix; - return s; - } - - typename Derived::Nested m = _m; - typedef typename Derived::Scalar Scalar; - typedef typename - conditional< - is_same<Scalar, char>::value || - is_same<Scalar, unsigned char>::value || - is_same<Scalar, numext::int8_t>::value || - is_same<Scalar, numext::uint8_t>::value, - int, - typename conditional< - is_same<Scalar, std::complex<char> >::value || - is_same<Scalar, std::complex<unsigned char> >::value || - is_same<Scalar, std::complex<numext::int8_t> >::value || - is_same<Scalar, std::complex<numext::uint8_t> >::value, - std::complex<int>, - const Scalar& - >::type - >::type PrintType; - - Index width = 0; - - std::streamsize explicit_precision; - if(fmt.precision == StreamPrecision) - { - explicit_precision = 0; - } - else if(fmt.precision == FullPrecision) - { - if (NumTraits<Scalar>::IsInteger) - { - explicit_precision = 0; - } - else - { - explicit_precision = significant_decimals_impl<Scalar>::run(); - } - } - else - { - explicit_precision = fmt.precision; - } - - std::streamsize old_precision = 0; - if(explicit_precision) old_precision = s.precision(explicit_precision); - - bool align_cols = !(fmt.flags & DontAlignCols); - if(align_cols) - { - // compute the largest width - for(Index j = 0; j < m.cols(); ++j) - for(Index i = 0; i < m.rows(); ++i) - { - std::stringstream sstr; - sstr.copyfmt(s); - sstr << static_cast<PrintType>(m.coeff(i,j)); - width = std::max<Index>(width, Index(sstr.str().length())); - } - } - std::streamsize old_width = s.width(); - char old_fill_character = s.fill(); - s << fmt.matPrefix; - for(Index i = 0; i < m.rows(); ++i) - { - if (i) - s << fmt.rowSpacer; - s << fmt.rowPrefix; - if(width) { - s.fill(fmt.fill); - s.width(width); - } - s << static_cast<PrintType>(m.coeff(i, 0)); - for(Index j = 1; j < m.cols(); ++j) - { - s << fmt.coeffSeparator; - if(width) { - s.fill(fmt.fill); - s.width(width); - } - s << static_cast<PrintType>(m.coeff(i, j)); - } - s << fmt.rowSuffix; - if( i < m.rows() - 1) - s << fmt.rowSeparator; - } - s << fmt.matSuffix; - if(explicit_precision) s.precision(old_precision); - if(width) { - s.fill(old_fill_character); - s.width(old_width); - } - return s; -} - -} // end namespace internal - -/** \relates DenseBase - * - * Outputs the matrix, to the given stream. - * - * If you wish to print the matrix with a format different than the default, use DenseBase::format(). - * - * It is also possible to change the default format by defining EIGEN_DEFAULT_IO_FORMAT before including Eigen headers. - * If not defined, this will automatically be defined to Eigen::IOFormat(), that is the Eigen::IOFormat with default parameters. - * - * \sa DenseBase::format() - */ -template<typename Derived> -std::ostream & operator << -(std::ostream & s, - const DenseBase<Derived> & m) -{ - return internal::print_matrix(s, m.eval(), EIGEN_DEFAULT_IO_FORMAT); -} - -} // end namespace Eigen - -#endif // EIGEN_IO_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/IndexedView.h b/external/eigen/include/eigen3/Eigen/src/Core/IndexedView.h deleted file mode 100644 index 377f8a5c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/IndexedView.h +++ /dev/null @@ -1,207 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_INDEXED_VIEW_H -#define EIGEN_INDEXED_VIEW_H - -namespace Eigen { - -namespace internal { - -template<typename XprType, typename RowIndices, typename ColIndices> -struct traits<IndexedView<XprType, RowIndices, ColIndices> > - : traits<XprType> -{ - enum { - RowsAtCompileTime = int(array_size<RowIndices>::value), - ColsAtCompileTime = int(array_size<ColIndices>::value), - MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : Dynamic, - MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : Dynamic, - - XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0, - IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1 - : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0 - : XprTypeIsRowMajor, - - RowIncr = int(get_compile_time_incr<RowIndices>::value), - ColIncr = int(get_compile_time_incr<ColIndices>::value), - InnerIncr = IsRowMajor ? ColIncr : RowIncr, - OuterIncr = IsRowMajor ? RowIncr : ColIncr, - - HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor), - XprInnerStride = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time<XprType>::ret) : int(outer_stride_at_compile_time<XprType>::ret), - XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType>::ret) : int(inner_stride_at_compile_time<XprType>::ret), - - InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime, - IsBlockAlike = InnerIncr==1 && OuterIncr==1, - IsInnerPannel = HasSameStorageOrderAsXprType && is_same<AllRange<InnerSize>,typename conditional<XprTypeIsRowMajor,ColIndices,RowIndices>::type>::value, - - InnerStrideAtCompileTime = InnerIncr<0 || InnerIncr==DynamicIndex || XprInnerStride==Dynamic ? Dynamic : XprInnerStride * InnerIncr, - OuterStrideAtCompileTime = OuterIncr<0 || OuterIncr==DynamicIndex || XprOuterstride==Dynamic ? Dynamic : XprOuterstride * OuterIncr, - - ReturnAsScalar = is_same<RowIndices,SingleRange>::value && is_same<ColIndices,SingleRange>::value, - ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike, - ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock), - - // FIXME we deal with compile-time strides if and only if we have DirectAccessBit flag, - // but this is too strict regarding negative strides... - DirectAccessMask = (int(InnerIncr)!=UndefinedIncr && int(OuterIncr)!=UndefinedIncr && InnerIncr>=0 && OuterIncr>=0) ? DirectAccessBit : 0, - FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, - FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0, - Flags = (traits<XprType>::Flags & (HereditaryBits | DirectAccessMask)) | FlagsLvalueBit | FlagsRowMajorBit - }; - - typedef Block<XprType,RowsAtCompileTime,ColsAtCompileTime,IsInnerPannel> BlockType; -}; - -} - -template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind> -class IndexedViewImpl; - - -/** \class IndexedView - * \ingroup Core_Module - * - * \brief Expression of a non-sequential sub-matrix defined by arbitrary sequences of row and column indices - * - * \tparam XprType the type of the expression in which we are taking the intersections of sub-rows and sub-columns - * \tparam RowIndices the type of the object defining the sequence of row indices - * \tparam ColIndices the type of the object defining the sequence of column indices - * - * This class represents an expression of a sub-matrix (or sub-vector) defined as the intersection - * of sub-sets of rows and columns, that are themself defined by generic sequences of row indices \f$ \{r_0,r_1,..r_{m-1}\} \f$ - * and column indices \f$ \{c_0,c_1,..c_{n-1} \}\f$. Let \f$ A \f$ be the nested matrix, then the resulting matrix \f$ B \f$ has \c m - * rows and \c n columns, and its entries are given by: \f$ B(i,j) = A(r_i,c_j) \f$. - * - * The \c RowIndices and \c ColIndices types must be compatible with the following API: - * \code - * <integral type> operator[](Index) const; - * Index size() const; - * \endcode - * - * Typical supported types thus include: - * - std::vector<int> - * - std::valarray<int> - * - std::array<int> - * - Plain C arrays: int[N] - * - Eigen::ArrayXi - * - decltype(ArrayXi::LinSpaced(...)) - * - Any view/expressions of the previous types - * - Eigen::ArithmeticSequence - * - Eigen::internal::AllRange (helper for Eigen::all) - * - Eigen::internal::SingleRange (helper for single index) - * - etc. - * - * In typical usages of %Eigen, this class should never be used directly. It is the return type of - * DenseBase::operator()(const RowIndices&, const ColIndices&). - * - * \sa class Block - */ -template<typename XprType, typename RowIndices, typename ColIndices> -class IndexedView : public IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind> -{ -public: - typedef typename IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>::Base Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(IndexedView) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedView) - - typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested; - typedef typename internal::remove_all<XprType>::type NestedExpression; - - template<typename T0, typename T1> - IndexedView(XprType& xpr, const T0& rowIndices, const T1& colIndices) - : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices) - {} - - /** \returns number of rows */ - Index rows() const { return internal::size(m_rowIndices); } - - /** \returns number of columns */ - Index cols() const { return internal::size(m_colIndices); } - - /** \returns the nested expression */ - const typename internal::remove_all<XprType>::type& - nestedExpression() const { return m_xpr; } - - /** \returns the nested expression */ - typename internal::remove_reference<XprType>::type& - nestedExpression() { return m_xpr; } - - /** \returns a const reference to the object storing/generating the row indices */ - const RowIndices& rowIndices() const { return m_rowIndices; } - - /** \returns a const reference to the object storing/generating the column indices */ - const ColIndices& colIndices() const { return m_colIndices; } - -protected: - MatrixTypeNested m_xpr; - RowIndices m_rowIndices; - ColIndices m_colIndices; -}; - - -// Generic API dispatcher -template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind> -class IndexedViewImpl - : public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type -{ -public: - typedef typename internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type Base; -}; - -namespace internal { - - -template<typename ArgType, typename RowIndices, typename ColIndices> -struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased> - : evaluator_base<IndexedView<ArgType, RowIndices, ColIndices> > -{ - typedef IndexedView<ArgType, RowIndices, ColIndices> XprType; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost /* TODO + cost of row/col index */, - - Flags = (evaluator<ArgType>::Flags & (HereditaryBits /*| LinearAccessBit | DirectAccessBit*/)), - - Alignment = 0 - }; - - EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeff(Index row, Index col) const - { - return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Scalar& coeffRef(Index row, Index col) - { - return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]); - } - -protected: - - evaluator<ArgType> m_argImpl; - const XprType& m_xpr; - -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_INDEXED_VIEW_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Inverse.h b/external/eigen/include/eigen3/Eigen/src/Core/Inverse.h deleted file mode 100644 index 7352d803..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Inverse.h +++ /dev/null @@ -1,117 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014-2019 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_INVERSE_H -#define EIGEN_INVERSE_H - -namespace Eigen { - -template<typename XprType,typename StorageKind> class InverseImpl; - -namespace internal { - -template<typename XprType> -struct traits<Inverse<XprType> > - : traits<typename XprType::PlainObject> -{ - typedef typename XprType::PlainObject PlainObject; - typedef traits<PlainObject> BaseTraits; - enum { - Flags = BaseTraits::Flags & RowMajorBit - }; -}; - -} // end namespace internal - -/** \class Inverse - * - * \brief Expression of the inverse of another expression - * - * \tparam XprType the type of the expression we are taking the inverse - * - * This class represents an abstract expression of A.inverse() - * and most of the time this is the only way it is used. - * - */ -template<typename XprType> -class Inverse : public InverseImpl<XprType,typename internal::traits<XprType>::StorageKind> -{ -public: - typedef typename XprType::StorageIndex StorageIndex; - typedef typename XprType::Scalar Scalar; - typedef typename internal::ref_selector<XprType>::type XprTypeNested; - typedef typename internal::remove_all<XprTypeNested>::type XprTypeNestedCleaned; - typedef typename internal::ref_selector<Inverse>::type Nested; - typedef typename internal::remove_all<XprType>::type NestedExpression; - - explicit EIGEN_DEVICE_FUNC Inverse(const XprType &xpr) - : m_xpr(xpr) - {} - - EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.cols(); } - EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.rows(); } - - EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; } - -protected: - XprTypeNested m_xpr; -}; - -// Generic API dispatcher -template<typename XprType, typename StorageKind> -class InverseImpl - : public internal::generic_xpr_base<Inverse<XprType> >::type -{ -public: - typedef typename internal::generic_xpr_base<Inverse<XprType> >::type Base; - typedef typename XprType::Scalar Scalar; -private: - - Scalar coeff(Index row, Index col) const; - Scalar coeff(Index i) const; -}; - -namespace internal { - -/** \internal - * \brief Default evaluator for Inverse expression. - * - * This default evaluator for Inverse expression simply evaluate the inverse into a temporary - * by a call to internal::call_assignment_no_alias. - * Therefore, inverse implementers only have to specialize Assignment<Dst,Inverse<...>, ...> for - * there own nested expression. - * - * \sa class Inverse - */ -template<typename ArgType> -struct unary_evaluator<Inverse<ArgType> > - : public evaluator<typename Inverse<ArgType>::PlainObject> -{ - typedef Inverse<ArgType> InverseType; - typedef typename InverseType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - - enum { Flags = Base::Flags | EvalBeforeNestingBit }; - - unary_evaluator(const InverseType& inv_xpr) - : m_result(inv_xpr.rows(), inv_xpr.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - internal::call_assignment_no_alias(m_result, inv_xpr); - } - -protected: - PlainObject m_result; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_INVERSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Map.h b/external/eigen/include/eigen3/Eigen/src/Core/Map.h deleted file mode 100644 index c437f1a9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Map.h +++ /dev/null @@ -1,171 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MAP_H -#define EIGEN_MAP_H - -namespace Eigen { - -namespace internal { -template<typename PlainObjectType, int MapOptions, typename StrideType> -struct traits<Map<PlainObjectType, MapOptions, StrideType> > - : public traits<PlainObjectType> -{ - typedef traits<PlainObjectType> TraitsBase; - enum { - PlainObjectTypeInnerSize = ((traits<PlainObjectType>::Flags&RowMajorBit)==RowMajorBit) - ? PlainObjectType::ColsAtCompileTime - : PlainObjectType::RowsAtCompileTime, - - InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0 - ? int(PlainObjectType::InnerStrideAtCompileTime) - : int(StrideType::InnerStrideAtCompileTime), - OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0 - ? (InnerStrideAtCompileTime==Dynamic || PlainObjectTypeInnerSize==Dynamic - ? Dynamic - : int(InnerStrideAtCompileTime) * int(PlainObjectTypeInnerSize)) - : int(StrideType::OuterStrideAtCompileTime), - Alignment = int(MapOptions)&int(AlignedMask), - Flags0 = TraitsBase::Flags & (~NestByRefBit), - Flags = is_lvalue<PlainObjectType>::value ? int(Flags0) : (int(Flags0) & ~LvalueBit) - }; -private: - enum { Options }; // Expressions don't have Options -}; -} - -/** \class Map - * \ingroup Core_Module - * - * \brief A matrix or vector expression mapping an existing array of data. - * - * \tparam PlainObjectType the equivalent matrix type of the mapped data - * \tparam MapOptions specifies the pointer alignment in bytes. It can be: \c #Aligned128, , \c #Aligned64, \c #Aligned32, \c #Aligned16, \c #Aligned8 or \c #Unaligned. - * The default is \c #Unaligned. - * \tparam StrideType optionally specifies strides. By default, Map assumes the memory layout - * of an ordinary, contiguous array. This can be overridden by specifying strides. - * The type passed here must be a specialization of the Stride template, see examples below. - * - * This class represents a matrix or vector expression mapping an existing array of data. - * It can be used to let Eigen interface without any overhead with non-Eigen data structures, - * such as plain C arrays or structures from other libraries. By default, it assumes that the - * data is laid out contiguously in memory. You can however override this by explicitly specifying - * inner and outer strides. - * - * Here's an example of simply mapping a contiguous array as a \ref TopicStorageOrders "column-major" matrix: - * \include Map_simple.cpp - * Output: \verbinclude Map_simple.out - * - * If you need to map non-contiguous arrays, you can do so by specifying strides: - * - * Here's an example of mapping an array as a vector, specifying an inner stride, that is, the pointer - * increment between two consecutive coefficients. Here, we're specifying the inner stride as a compile-time - * fixed value. - * \include Map_inner_stride.cpp - * Output: \verbinclude Map_inner_stride.out - * - * Here's an example of mapping an array while specifying an outer stride. Here, since we're mapping - * as a column-major matrix, 'outer stride' means the pointer increment between two consecutive columns. - * Here, we're specifying the outer stride as a runtime parameter. Note that here \c OuterStride<> is - * a short version of \c OuterStride<Dynamic> because the default template parameter of OuterStride - * is \c Dynamic - * \include Map_outer_stride.cpp - * Output: \verbinclude Map_outer_stride.out - * - * For more details and for an example of specifying both an inner and an outer stride, see class Stride. - * - * \b Tip: to change the array of data mapped by a Map object, you can use the C++ - * placement new syntax: - * - * Example: \include Map_placement_new.cpp - * Output: \verbinclude Map_placement_new.out - * - * This class is the return type of PlainObjectBase::Map() but can also be used directly. - * - * \sa PlainObjectBase::Map(), \ref TopicStorageOrders - */ -template<typename PlainObjectType, int MapOptions, typename StrideType> class Map - : public MapBase<Map<PlainObjectType, MapOptions, StrideType> > -{ - public: - - typedef MapBase<Map> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Map) - - typedef typename Base::PointerType PointerType; - typedef PointerType PointerArgType; - EIGEN_DEVICE_FUNC - inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; } - - EIGEN_DEVICE_FUNC - inline Index innerStride() const - { - return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1; - } - - EIGEN_DEVICE_FUNC - inline Index outerStride() const - { - return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer() - : internal::traits<Map>::OuterStrideAtCompileTime != Dynamic ? Index(internal::traits<Map>::OuterStrideAtCompileTime) - : IsVectorAtCompileTime ? (this->size() * innerStride()) - : int(Flags)&RowMajorBit ? (this->cols() * innerStride()) - : (this->rows() * innerStride()); - } - - /** Constructor in the fixed-size case. - * - * \param dataPtr pointer to the array to map - * \param stride optional Stride object, passing the strides. - */ - EIGEN_DEVICE_FUNC - explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType()) - : Base(cast_to_pointer_type(dataPtr)), m_stride(stride) - { - PlainObjectType::Base::_check_template_params(); - } - - /** Constructor in the dynamic-size vector case. - * - * \param dataPtr pointer to the array to map - * \param size the size of the vector expression - * \param stride optional Stride object, passing the strides. - */ - EIGEN_DEVICE_FUNC - inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType()) - : Base(cast_to_pointer_type(dataPtr), size), m_stride(stride) - { - PlainObjectType::Base::_check_template_params(); - } - - /** Constructor in the dynamic-size matrix case. - * - * \param dataPtr pointer to the array to map - * \param rows the number of rows of the matrix expression - * \param cols the number of columns of the matrix expression - * \param stride optional Stride object, passing the strides. - */ - EIGEN_DEVICE_FUNC - inline Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType& stride = StrideType()) - : Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride) - { - PlainObjectType::Base::_check_template_params(); - } - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map) - - protected: - StrideType m_stride; -}; - - -} // end namespace Eigen - -#endif // EIGEN_MAP_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/MapBase.h b/external/eigen/include/eigen3/Eigen/src/Core/MapBase.h deleted file mode 100644 index 92c3b281..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/MapBase.h +++ /dev/null @@ -1,308 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MAPBASE_H -#define EIGEN_MAPBASE_H - -#define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \ - EIGEN_STATIC_ASSERT((int(internal::evaluator<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \ - YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT) - -namespace Eigen { - -/** \ingroup Core_Module - * - * \brief Base class for dense Map and Block expression with direct access - * - * This base class provides the const low-level accessors (e.g. coeff, coeffRef) of dense - * Map and Block objects with direct access. - * Typical users do not have to directly deal with this class. - * - * This class can be extended by through the macro plugin \c EIGEN_MAPBASE_PLUGIN. - * See \link TopicCustomizing_Plugins customizing Eigen \endlink for details. - * - * The \c Derived class has to provide the following two methods describing the memory layout: - * \code Index innerStride() const; \endcode - * \code Index outerStride() const; \endcode - * - * \sa class Map, class Block - */ -template<typename Derived> class MapBase<Derived, ReadOnlyAccessors> - : public internal::dense_xpr_base<Derived>::type -{ - public: - - typedef typename internal::dense_xpr_base<Derived>::type Base; - enum { - RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, - ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, - InnerStrideAtCompileTime = internal::traits<Derived>::InnerStrideAtCompileTime, - SizeAtCompileTime = Base::SizeAtCompileTime - }; - - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename internal::packet_traits<Scalar>::type PacketScalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef typename internal::conditional< - bool(internal::is_lvalue<Derived>::value), - Scalar *, - const Scalar *>::type - PointerType; - - using Base::derived; -// using Base::RowsAtCompileTime; -// using Base::ColsAtCompileTime; -// using Base::SizeAtCompileTime; - using Base::MaxRowsAtCompileTime; - using Base::MaxColsAtCompileTime; - using Base::MaxSizeAtCompileTime; - using Base::IsVectorAtCompileTime; - using Base::Flags; - using Base::IsRowMajor; - - using Base::rows; - using Base::cols; - using Base::size; - using Base::coeff; - using Base::coeffRef; - using Base::lazyAssign; - using Base::eval; - - using Base::innerStride; - using Base::outerStride; - using Base::rowStride; - using Base::colStride; - - // bug 217 - compile error on ICC 11.1 - using Base::operator=; - - typedef typename Base::CoeffReturnType CoeffReturnType; - - /** \copydoc DenseBase::rows() */ - EIGEN_DEVICE_FUNC inline Index rows() const { return m_rows.value(); } - /** \copydoc DenseBase::cols() */ - EIGEN_DEVICE_FUNC inline Index cols() const { return m_cols.value(); } - - /** Returns a pointer to the first coefficient of the matrix or vector. - * - * \note When addressing this data, make sure to honor the strides returned by innerStride() and outerStride(). - * - * \sa innerStride(), outerStride() - */ - EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; } - - /** \copydoc PlainObjectBase::coeff(Index,Index) const */ - EIGEN_DEVICE_FUNC - inline const Scalar& coeff(Index rowId, Index colId) const - { - return m_data[colId * colStride() + rowId * rowStride()]; - } - - /** \copydoc PlainObjectBase::coeff(Index) const */ - EIGEN_DEVICE_FUNC - inline const Scalar& coeff(Index index) const - { - EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) - return m_data[index * innerStride()]; - } - - /** \copydoc PlainObjectBase::coeffRef(Index,Index) const */ - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index rowId, Index colId) const - { - return this->m_data[colId * colStride() + rowId * rowStride()]; - } - - /** \copydoc PlainObjectBase::coeffRef(Index) const */ - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index index) const - { - EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) - return this->m_data[index * innerStride()]; - } - - /** \internal */ - template<int LoadMode> - inline PacketScalar packet(Index rowId, Index colId) const - { - return internal::ploadt<PacketScalar, LoadMode> - (m_data + (colId * colStride() + rowId * rowStride())); - } - - /** \internal */ - template<int LoadMode> - inline PacketScalar packet(Index index) const - { - EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) - return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride()); - } - - /** \internal Constructor for fixed size matrices or vectors */ - EIGEN_DEVICE_FUNC - explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime) - { - EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) - checkSanity<Derived>(); - } - - /** \internal Constructor for dynamically sized vectors */ - EIGEN_DEVICE_FUNC - inline MapBase(PointerType dataPtr, Index vecSize) - : m_data(dataPtr), - m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)), - m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime)) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - eigen_assert(vecSize >= 0); - eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize); - checkSanity<Derived>(); - } - - /** \internal Constructor for dynamically sized matrices */ - EIGEN_DEVICE_FUNC - inline MapBase(PointerType dataPtr, Index rows, Index cols) - : m_data(dataPtr), m_rows(rows), m_cols(cols) - { - eigen_assert( (dataPtr == 0) - || ( rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) - && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols))); - checkSanity<Derived>(); - } - - #ifdef EIGEN_MAPBASE_PLUGIN - #include EIGEN_MAPBASE_PLUGIN - #endif - - protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase) - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase) - - template<typename T> - EIGEN_DEVICE_FUNC - void checkSanity(typename internal::enable_if<(internal::traits<T>::Alignment>0),void*>::type = 0) const - { -#if EIGEN_MAX_ALIGN_BYTES>0 - // innerStride() is not set yet when this function is called, so we optimistically assume the lowest plausible value: - const Index minInnerStride = InnerStrideAtCompileTime == Dynamic ? 1 : Index(InnerStrideAtCompileTime); - EIGEN_ONLY_USED_FOR_DEBUG(minInnerStride); - eigen_assert(( ((internal::UIntPtr(m_data) % internal::traits<Derived>::Alignment) == 0) - || (cols() * rows() * minInnerStride * sizeof(Scalar)) < internal::traits<Derived>::Alignment ) && "data is not aligned"); -#endif - } - - template<typename T> - EIGEN_DEVICE_FUNC - void checkSanity(typename internal::enable_if<internal::traits<T>::Alignment==0,void*>::type = 0) const - {} - - PointerType m_data; - const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows; - const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols; -}; - -/** \ingroup Core_Module - * - * \brief Base class for non-const dense Map and Block expression with direct access - * - * This base class provides the non-const low-level accessors (e.g. coeff and coeffRef) of - * dense Map and Block objects with direct access. - * It inherits MapBase<Derived, ReadOnlyAccessors> which defines the const variant for reading specific entries. - * - * \sa class Map, class Block - */ -template<typename Derived> class MapBase<Derived, WriteAccessors> - : public MapBase<Derived, ReadOnlyAccessors> -{ - typedef MapBase<Derived, ReadOnlyAccessors> ReadOnlyMapBase; - public: - - typedef MapBase<Derived, ReadOnlyAccessors> Base; - - typedef typename Base::Scalar Scalar; - typedef typename Base::PacketScalar PacketScalar; - typedef typename Base::StorageIndex StorageIndex; - typedef typename Base::PointerType PointerType; - - using Base::derived; - using Base::rows; - using Base::cols; - using Base::size; - using Base::coeff; - using Base::coeffRef; - - using Base::innerStride; - using Base::outerStride; - using Base::rowStride; - using Base::colStride; - - typedef typename internal::conditional< - internal::is_lvalue<Derived>::value, - Scalar, - const Scalar - >::type ScalarWithConstIfNotLvalue; - - EIGEN_DEVICE_FUNC - inline const Scalar* data() const { return this->m_data; } - EIGEN_DEVICE_FUNC - inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error - - EIGEN_DEVICE_FUNC - inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col) - { - return this->m_data[col * colStride() + row * rowStride()]; - } - - EIGEN_DEVICE_FUNC - inline ScalarWithConstIfNotLvalue& coeffRef(Index index) - { - EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) - return this->m_data[index * innerStride()]; - } - - template<int StoreMode> - inline void writePacket(Index row, Index col, const PacketScalar& val) - { - internal::pstoret<Scalar, PacketScalar, StoreMode> - (this->m_data + (col * colStride() + row * rowStride()), val); - } - - template<int StoreMode> - inline void writePacket(Index index, const PacketScalar& val) - { - EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) - internal::pstoret<Scalar, PacketScalar, StoreMode> - (this->m_data + index * innerStride(), val); - } - - EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {} - EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {} - EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) : Base(dataPtr, rows, cols) {} - - EIGEN_DEVICE_FUNC - Derived& operator=(const MapBase& other) - { - ReadOnlyMapBase::Base::operator=(other); - return derived(); - } - - // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base, - // see bugs 821 and 920. - using ReadOnlyMapBase::Base::operator=; - protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase) - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase) -}; - -#undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS - -} // end namespace Eigen - -#endif // EIGEN_MAPBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/MathFunctions.h deleted file mode 100644 index 090ad43b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/MathFunctions.h +++ /dev/null @@ -1,1852 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATHFUNCTIONS_H -#define EIGEN_MATHFUNCTIONS_H - -// source: http://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html -// TODO this should better be moved to NumTraits -#define EIGEN_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406L - -namespace Eigen { - -// On WINCE, std::abs is defined for int only, so let's defined our own overloads: -// This issue has been confirmed with MSVC 2008 only, but the issue might exist for more recent versions too. -#if EIGEN_OS_WINCE && EIGEN_COMP_MSVC && EIGEN_COMP_MSVC<=1500 -long abs(long x) { return (labs(x)); } -double abs(double x) { return (fabs(x)); } -float abs(float x) { return (fabsf(x)); } -long double abs(long double x) { return (fabsl(x)); } -#endif - -namespace internal { - -/** \internal \class global_math_functions_filtering_base - * - * What it does: - * Defines a typedef 'type' as follows: - * - if type T has a member typedef Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl, then - * global_math_functions_filtering_base<T>::type is a typedef for it. - * - otherwise, global_math_functions_filtering_base<T>::type is a typedef for T. - * - * How it's used: - * To allow to defined the global math functions (like sin...) in certain cases, like the Array expressions. - * When you do sin(array1+array2), the object array1+array2 has a complicated expression type, all what you want to know - * is that it inherits ArrayBase. So we implement a partial specialization of sin_impl for ArrayBase<Derived>. - * So we must make sure to use sin_impl<ArrayBase<Derived> > and not sin_impl<Derived>, otherwise our partial specialization - * won't be used. How does sin know that? That's exactly what global_math_functions_filtering_base tells it. - * - * How it's implemented: - * SFINAE in the style of enable_if. Highly susceptible of breaking compilers. With GCC, it sure does work, but if you replace - * the typename dummy by an integer template parameter, it doesn't work anymore! - */ - -template<typename T, typename dummy = void> -struct global_math_functions_filtering_base -{ - typedef T type; -}; - -template<typename T> struct always_void { typedef void type; }; - -template<typename T> -struct global_math_functions_filtering_base - <T, - typename always_void<typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl>::type - > -{ - typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type; -}; - -#define EIGEN_MATHFUNC_IMPL(func, scalar) Eigen::internal::func##_impl<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type> -#define EIGEN_MATHFUNC_RETVAL(func, scalar) typename Eigen::internal::func##_retval<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>::type - -/**************************************************************************** -* Implementation of real * -****************************************************************************/ - -template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex> -struct real_default_impl -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - return x; - } -}; - -template<typename Scalar> -struct real_default_impl<Scalar,true> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - using std::real; - return real(x); - } -}; - -template<typename Scalar> struct real_impl : real_default_impl<Scalar> {}; - -#if defined(EIGEN_GPU_COMPILE_PHASE) -template<typename T> -struct real_impl<std::complex<T> > -{ - typedef T RealScalar; - EIGEN_DEVICE_FUNC - static inline T run(const std::complex<T>& x) - { - return x.real(); - } -}; -#endif - -template<typename Scalar> -struct real_retval -{ - typedef typename NumTraits<Scalar>::Real type; -}; - -/**************************************************************************** -* Implementation of imag * -****************************************************************************/ - -template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex> -struct imag_default_impl -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar&) - { - return RealScalar(0); - } -}; - -template<typename Scalar> -struct imag_default_impl<Scalar,true> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - using std::imag; - return imag(x); - } -}; - -template<typename Scalar> struct imag_impl : imag_default_impl<Scalar> {}; - -#if defined(EIGEN_GPU_COMPILE_PHASE) -template<typename T> -struct imag_impl<std::complex<T> > -{ - typedef T RealScalar; - EIGEN_DEVICE_FUNC - static inline T run(const std::complex<T>& x) - { - return x.imag(); - } -}; -#endif - -template<typename Scalar> -struct imag_retval -{ - typedef typename NumTraits<Scalar>::Real type; -}; - -/**************************************************************************** -* Implementation of real_ref * -****************************************************************************/ - -template<typename Scalar> -struct real_ref_impl -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar& run(Scalar& x) - { - return reinterpret_cast<RealScalar*>(&x)[0]; - } - EIGEN_DEVICE_FUNC - static inline const RealScalar& run(const Scalar& x) - { - return reinterpret_cast<const RealScalar*>(&x)[0]; - } -}; - -template<typename Scalar> -struct real_ref_retval -{ - typedef typename NumTraits<Scalar>::Real & type; -}; - -/**************************************************************************** -* Implementation of imag_ref * -****************************************************************************/ - -template<typename Scalar, bool IsComplex> -struct imag_ref_default_impl -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar& run(Scalar& x) - { - return reinterpret_cast<RealScalar*>(&x)[1]; - } - EIGEN_DEVICE_FUNC - static inline const RealScalar& run(const Scalar& x) - { - return reinterpret_cast<RealScalar*>(&x)[1]; - } -}; - -template<typename Scalar> -struct imag_ref_default_impl<Scalar, false> -{ - EIGEN_DEVICE_FUNC - static inline Scalar run(Scalar&) - { - return Scalar(0); - } - EIGEN_DEVICE_FUNC - static inline const Scalar run(const Scalar&) - { - return Scalar(0); - } -}; - -template<typename Scalar> -struct imag_ref_impl : imag_ref_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {}; - -template<typename Scalar> -struct imag_ref_retval -{ - typedef typename NumTraits<Scalar>::Real & type; -}; - -/**************************************************************************** -* Implementation of conj * -****************************************************************************/ - -template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex> -struct conj_default_impl -{ - EIGEN_DEVICE_FUNC - static inline Scalar run(const Scalar& x) - { - return x; - } -}; - -template<typename Scalar> -struct conj_default_impl<Scalar,true> -{ - EIGEN_DEVICE_FUNC - static inline Scalar run(const Scalar& x) - { - using std::conj; - return conj(x); - } -}; - -template<typename Scalar> struct conj_impl : conj_default_impl<Scalar> {}; - -#if defined(EIGEN_GPU_COMPILE_PHASE) -template<typename T> -struct conj_impl<std::complex<T> > -{ - EIGEN_DEVICE_FUNC - static inline std::complex<T> run(const std::complex<T>& x) - { - return std::complex<T>(x.real(), -x.imag()); - } -}; -#endif - -template<typename Scalar> -struct conj_retval -{ - typedef Scalar type; -}; - -/**************************************************************************** -* Implementation of abs2 * -****************************************************************************/ - -template<typename Scalar,bool IsComplex> -struct abs2_impl_default -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - return x*x; - } -}; - -template<typename Scalar> -struct abs2_impl_default<Scalar, true> // IsComplex -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - return x.real()*x.real() + x.imag()*x.imag(); - } -}; - -template<typename Scalar> -struct abs2_impl -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - return abs2_impl_default<Scalar,NumTraits<Scalar>::IsComplex>::run(x); - } -}; - -template<typename Scalar> -struct abs2_retval -{ - typedef typename NumTraits<Scalar>::Real type; -}; - -/**************************************************************************** -* Implementation of norm1 * -****************************************************************************/ - -template<typename Scalar, bool IsComplex> -struct norm1_default_impl; - -template<typename Scalar> -struct norm1_default_impl<Scalar,true> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - EIGEN_USING_STD_MATH(abs); - return abs(x.real()) + abs(x.imag()); - } -}; - -template<typename Scalar> -struct norm1_default_impl<Scalar, false> -{ - EIGEN_DEVICE_FUNC - static inline Scalar run(const Scalar& x) - { - EIGEN_USING_STD_MATH(abs); - return abs(x); - } -}; - -template<typename Scalar> -struct norm1_impl : norm1_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {}; - -template<typename Scalar> -struct norm1_retval -{ - typedef typename NumTraits<Scalar>::Real type; -}; - -/**************************************************************************** -* Implementation of hypot * -****************************************************************************/ - -template<typename Scalar> struct hypot_impl; - -template<typename Scalar> -struct hypot_retval -{ - typedef typename NumTraits<Scalar>::Real type; -}; - -/**************************************************************************** -* Implementation of cast * -****************************************************************************/ - -template<typename OldType, typename NewType> -struct cast_impl -{ - EIGEN_DEVICE_FUNC - static inline NewType run(const OldType& x) - { - return static_cast<NewType>(x); - } -}; - -// here, for once, we're plainly returning NewType: we don't want cast to do weird things. - -template<typename OldType, typename NewType> -EIGEN_DEVICE_FUNC -inline NewType cast(const OldType& x) -{ - return cast_impl<OldType, NewType>::run(x); -} - -/**************************************************************************** -* Implementation of round * -****************************************************************************/ - -#if EIGEN_HAS_CXX11_MATH - template<typename Scalar> - struct round_impl { - EIGEN_DEVICE_FUNC - static inline Scalar run(const Scalar& x) - { - EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL) - EIGEN_USING_STD_MATH(round); - return round(x); - } - }; -#else - template<typename Scalar> - struct round_impl - { - EIGEN_DEVICE_FUNC - static inline Scalar run(const Scalar& x) - { - EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL) - EIGEN_USING_STD_MATH(floor); - EIGEN_USING_STD_MATH(ceil); - return (x > Scalar(0)) ? floor(x + Scalar(0.5)) : ceil(x - Scalar(0.5)); - } - }; -#endif - -template<typename Scalar> -struct round_retval -{ - typedef Scalar type; -}; - -/**************************************************************************** -* Implementation of rint * -****************************************************************************/ - -template<typename Scalar> -struct rint_impl { - EIGEN_DEVICE_FUNC - static inline Scalar run(const Scalar& x) - { - EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL) -#if EIGEN_HAS_CXX11_MATH - EIGEN_USING_STD_MATH(rint); -#endif - return rint(x); - } -}; - -#if !EIGEN_HAS_CXX11_MATH -template<> -struct rint_impl<double> { - EIGEN_DEVICE_FUNC - static inline double run(const double& x) - { - return ::rint(x); - } -}; -template<> -struct rint_impl<float> { - EIGEN_DEVICE_FUNC - static inline float run(const float& x) - { - return ::rintf(x); - } -}; -#endif - -template<typename Scalar> -struct rint_retval -{ - typedef Scalar type; -}; - -/**************************************************************************** -* Implementation of arg * -****************************************************************************/ - -#if EIGEN_HAS_CXX11_MATH - template<typename Scalar> - struct arg_impl { - EIGEN_DEVICE_FUNC - static inline Scalar run(const Scalar& x) - { - #if defined(EIGEN_HIP_DEVICE_COMPILE) - // HIP does not seem to have a native device side implementation for the math routine "arg" - using std::arg; - #else - EIGEN_USING_STD_MATH(arg); - #endif - return arg(x); - } - }; -#else - template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex> - struct arg_default_impl - { - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - return (x < Scalar(0)) ? Scalar(EIGEN_PI) : Scalar(0); } - }; - - template<typename Scalar> - struct arg_default_impl<Scalar,true> - { - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline RealScalar run(const Scalar& x) - { - EIGEN_USING_STD_MATH(arg); - return arg(x); - } - }; - - template<typename Scalar> struct arg_impl : arg_default_impl<Scalar> {}; -#endif - -template<typename Scalar> -struct arg_retval -{ - typedef typename NumTraits<Scalar>::Real type; -}; - -/**************************************************************************** -* Implementation of expm1 * -****************************************************************************/ - -// This implementation is based on GSL Math's expm1. -namespace std_fallback { - // fallback expm1 implementation in case there is no expm1(Scalar) function in namespace of Scalar, - // or that there is no suitable std::expm1 function available. Implementation - // attributed to Kahan. See: http://www.plunk.org/~hatch/rightway.php. - template<typename Scalar> - EIGEN_DEVICE_FUNC inline Scalar expm1(const Scalar& x) { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) - typedef typename NumTraits<Scalar>::Real RealScalar; - - EIGEN_USING_STD_MATH(exp); - Scalar u = exp(x); - if (numext::equal_strict(u, Scalar(1))) { - return x; - } - Scalar um1 = u - RealScalar(1); - if (numext::equal_strict(um1, Scalar(-1))) { - return RealScalar(-1); - } - - EIGEN_USING_STD_MATH(log); - Scalar logu = log(u); - return numext::equal_strict(u, logu) ? u : (u - RealScalar(1)) * x / logu; - } -} - -template<typename Scalar> -struct expm1_impl { - EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x) - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) - #if EIGEN_HAS_CXX11_MATH - using std::expm1; - #else - using std_fallback::expm1; - #endif - return expm1(x); - } -}; - -// Specialization for complex types that are not supported by std::expm1. -template <typename RealScalar> -struct expm1_impl<std::complex<RealScalar> > { - EIGEN_DEVICE_FUNC static inline std::complex<RealScalar> run( - const std::complex<RealScalar>& x) { - EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar) - RealScalar xr = x.real(); - RealScalar xi = x.imag(); - // expm1(z) = exp(z) - 1 - // = exp(x + i * y) - 1 - // = exp(x) * (cos(y) + i * sin(y)) - 1 - // = exp(x) * cos(y) - 1 + i * exp(x) * sin(y) - // Imag(expm1(z)) = exp(x) * sin(y) - // Real(expm1(z)) = exp(x) * cos(y) - 1 - // = exp(x) * cos(y) - 1. - // = expm1(x) + exp(x) * (cos(y) - 1) - // = expm1(x) + exp(x) * (2 * sin(y / 2) ** 2) - - // TODO better use numext::expm1 and numext::sin (but that would require forward declarations or moving this specialization down). - RealScalar erm1 = expm1_impl<RealScalar>::run(xr); - RealScalar er = erm1 + RealScalar(1.); - EIGEN_USING_STD_MATH(sin); - RealScalar sin2 = sin(xi / RealScalar(2.)); - sin2 = sin2 * sin2; - RealScalar s = sin(xi); - RealScalar real_part = erm1 - RealScalar(2.) * er * sin2; - return std::complex<RealScalar>(real_part, er * s); - } -}; - -template<typename Scalar> -struct expm1_retval -{ - typedef Scalar type; -}; - -/**************************************************************************** -* Implementation of log1p * -****************************************************************************/ - -namespace std_fallback { - // fallback log1p implementation in case there is no log1p(Scalar) function in namespace of Scalar, - // or that there is no suitable std::log1p function available - template<typename Scalar> - EIGEN_DEVICE_FUNC inline Scalar log1p(const Scalar& x) { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_USING_STD_MATH(log); - Scalar x1p = RealScalar(1) + x; - Scalar log_1p = log(x1p); - const bool is_small = numext::equal_strict(x1p, Scalar(1)); - const bool is_inf = numext::equal_strict(x1p, log_1p); - return (is_small || is_inf) ? x : x * (log_1p / (x1p - RealScalar(1))); - } -} - -template<typename Scalar> -struct log1p_impl { - EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x) - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) - #if EIGEN_HAS_CXX11_MATH - using std::log1p; - #else - using std_fallback::log1p; - #endif - return log1p(x); - } -}; - -// Specialization for complex types that are not supported by std::log1p. -template <typename RealScalar> -struct log1p_impl<std::complex<RealScalar> > { - EIGEN_DEVICE_FUNC static inline std::complex<RealScalar> run( - const std::complex<RealScalar>& x) { - EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar) - return std_fallback::log1p(x); - } -}; - -template<typename Scalar> -struct log1p_retval -{ - typedef Scalar type; -}; - -/**************************************************************************** -* Implementation of pow * -****************************************************************************/ - -template<typename ScalarX,typename ScalarY, bool IsInteger = NumTraits<ScalarX>::IsInteger&&NumTraits<ScalarY>::IsInteger> -struct pow_impl -{ - //typedef Scalar retval; - typedef typename ScalarBinaryOpTraits<ScalarX,ScalarY,internal::scalar_pow_op<ScalarX,ScalarY> >::ReturnType result_type; - static EIGEN_DEVICE_FUNC inline result_type run(const ScalarX& x, const ScalarY& y) - { - EIGEN_USING_STD_MATH(pow); - return pow(x, y); - } -}; - -template<typename ScalarX,typename ScalarY> -struct pow_impl<ScalarX,ScalarY, true> -{ - typedef ScalarX result_type; - static EIGEN_DEVICE_FUNC inline ScalarX run(ScalarX x, ScalarY y) - { - ScalarX res(1); - eigen_assert(!NumTraits<ScalarY>::IsSigned || y >= 0); - if(y & 1) res *= x; - y >>= 1; - while(y) - { - x *= x; - if(y&1) res *= x; - y >>= 1; - } - return res; - } -}; - -/**************************************************************************** -* Implementation of random * -****************************************************************************/ - -template<typename Scalar, - bool IsComplex, - bool IsInteger> -struct random_default_impl {}; - -template<typename Scalar> -struct random_impl : random_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {}; - -template<typename Scalar> -struct random_retval -{ - typedef Scalar type; -}; - -template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y); -template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(); - -template<typename Scalar> -struct random_default_impl<Scalar, false, false> -{ - static inline Scalar run(const Scalar& x, const Scalar& y) - { - return x + (y-x) * Scalar(std::rand()) / Scalar(RAND_MAX); - } - static inline Scalar run() - { - return run(Scalar(NumTraits<Scalar>::IsSigned ? -1 : 0), Scalar(1)); - } -}; - -enum { - meta_floor_log2_terminate, - meta_floor_log2_move_up, - meta_floor_log2_move_down, - meta_floor_log2_bogus -}; - -template<unsigned int n, int lower, int upper> struct meta_floor_log2_selector -{ - enum { middle = (lower + upper) / 2, - value = (upper <= lower + 1) ? int(meta_floor_log2_terminate) - : (n < (1 << middle)) ? int(meta_floor_log2_move_down) - : (n==0) ? int(meta_floor_log2_bogus) - : int(meta_floor_log2_move_up) - }; -}; - -template<unsigned int n, - int lower = 0, - int upper = sizeof(unsigned int) * CHAR_BIT - 1, - int selector = meta_floor_log2_selector<n, lower, upper>::value> -struct meta_floor_log2 {}; - -template<unsigned int n, int lower, int upper> -struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_down> -{ - enum { value = meta_floor_log2<n, lower, meta_floor_log2_selector<n, lower, upper>::middle>::value }; -}; - -template<unsigned int n, int lower, int upper> -struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_up> -{ - enum { value = meta_floor_log2<n, meta_floor_log2_selector<n, lower, upper>::middle, upper>::value }; -}; - -template<unsigned int n, int lower, int upper> -struct meta_floor_log2<n, lower, upper, meta_floor_log2_terminate> -{ - enum { value = (n >= ((unsigned int)(1) << (lower+1))) ? lower+1 : lower }; -}; - -template<unsigned int n, int lower, int upper> -struct meta_floor_log2<n, lower, upper, meta_floor_log2_bogus> -{ - // no value, error at compile time -}; - -template<typename Scalar> -struct random_default_impl<Scalar, false, true> -{ - static inline Scalar run(const Scalar& x, const Scalar& y) - { - if (y <= x) - return x; - // ScalarU is the unsigned counterpart of Scalar, possibly Scalar itself. - typedef typename make_unsigned<Scalar>::type ScalarU; - // ScalarX is the widest of ScalarU and unsigned int. - // We'll deal only with ScalarX and unsigned int below thus avoiding signed - // types and arithmetic and signed overflows (which are undefined behavior). - typedef typename conditional<(ScalarU(-1) > unsigned(-1)), ScalarU, unsigned>::type ScalarX; - // The following difference doesn't overflow, provided our integer types are two's - // complement and have the same number of padding bits in signed and unsigned variants. - // This is the case in most modern implementations of C++. - ScalarX range = ScalarX(y) - ScalarX(x); - ScalarX offset = 0; - ScalarX divisor = 1; - ScalarX multiplier = 1; - const unsigned rand_max = RAND_MAX; - if (range <= rand_max) divisor = (rand_max + 1) / (range + 1); - else multiplier = 1 + range / (rand_max + 1); - // Rejection sampling. - do { - offset = (unsigned(std::rand()) * multiplier) / divisor; - } while (offset > range); - return Scalar(ScalarX(x) + offset); - } - - static inline Scalar run() - { -#ifdef EIGEN_MAKING_DOCS - return run(Scalar(NumTraits<Scalar>::IsSigned ? -10 : 0), Scalar(10)); -#else - enum { rand_bits = meta_floor_log2<(unsigned int)(RAND_MAX)+1>::value, - scalar_bits = sizeof(Scalar) * CHAR_BIT, - shift = EIGEN_PLAIN_ENUM_MAX(0, int(rand_bits) - int(scalar_bits)), - offset = NumTraits<Scalar>::IsSigned ? (1 << (EIGEN_PLAIN_ENUM_MIN(rand_bits,scalar_bits)-1)) : 0 - }; - return Scalar((std::rand() >> shift) - offset); -#endif - } -}; - -template<typename Scalar> -struct random_default_impl<Scalar, true, false> -{ - static inline Scalar run(const Scalar& x, const Scalar& y) - { - return Scalar(random(x.real(), y.real()), - random(x.imag(), y.imag())); - } - static inline Scalar run() - { - typedef typename NumTraits<Scalar>::Real RealScalar; - return Scalar(random<RealScalar>(), random<RealScalar>()); - } -}; - -template<typename Scalar> -inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y) -{ - return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(x, y); -} - -template<typename Scalar> -inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random() -{ - return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(); -} - -// Implementation of is* functions - -// std::is* do not work with fast-math and gcc, std::is* are available on MSVC 2013 and newer, as well as in clang. -#if (EIGEN_HAS_CXX11_MATH && !(EIGEN_COMP_GNUC_STRICT && __FINITE_MATH_ONLY__)) || (EIGEN_COMP_MSVC>=1800) || (EIGEN_COMP_CLANG) -#define EIGEN_USE_STD_FPCLASSIFY 1 -#else -#define EIGEN_USE_STD_FPCLASSIFY 0 -#endif - -template<typename T> -EIGEN_DEVICE_FUNC -typename internal::enable_if<internal::is_integral<T>::value,bool>::type -isnan_impl(const T&) { return false; } - -template<typename T> -EIGEN_DEVICE_FUNC -typename internal::enable_if<internal::is_integral<T>::value,bool>::type -isinf_impl(const T&) { return false; } - -template<typename T> -EIGEN_DEVICE_FUNC -typename internal::enable_if<internal::is_integral<T>::value,bool>::type -isfinite_impl(const T&) { return true; } - -template<typename T> -EIGEN_DEVICE_FUNC -typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type -isfinite_impl(const T& x) -{ - #if defined(EIGEN_GPU_COMPILE_PHASE) - return (::isfinite)(x); - #elif EIGEN_USE_STD_FPCLASSIFY - using std::isfinite; - return isfinite EIGEN_NOT_A_MACRO (x); - #else - return x<=NumTraits<T>::highest() && x>=NumTraits<T>::lowest(); - #endif -} - -template<typename T> -EIGEN_DEVICE_FUNC -typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type -isinf_impl(const T& x) -{ - #if defined(EIGEN_GPU_COMPILE_PHASE) - return (::isinf)(x); - #elif EIGEN_USE_STD_FPCLASSIFY - using std::isinf; - return isinf EIGEN_NOT_A_MACRO (x); - #else - return x>NumTraits<T>::highest() || x<NumTraits<T>::lowest(); - #endif -} - -template<typename T> -EIGEN_DEVICE_FUNC -typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type -isnan_impl(const T& x) -{ - #if defined(EIGEN_GPU_COMPILE_PHASE) - return (::isnan)(x); - #elif EIGEN_USE_STD_FPCLASSIFY - using std::isnan; - return isnan EIGEN_NOT_A_MACRO (x); - #else - return x != x; - #endif -} - -#if (!EIGEN_USE_STD_FPCLASSIFY) - -#if EIGEN_COMP_MSVC - -template<typename T> EIGEN_DEVICE_FUNC bool isinf_msvc_helper(T x) -{ - return _fpclass(x)==_FPCLASS_NINF || _fpclass(x)==_FPCLASS_PINF; -} - -//MSVC defines a _isnan builtin function, but for double only -EIGEN_DEVICE_FUNC inline bool isnan_impl(const long double& x) { return _isnan(x)!=0; } -EIGEN_DEVICE_FUNC inline bool isnan_impl(const double& x) { return _isnan(x)!=0; } -EIGEN_DEVICE_FUNC inline bool isnan_impl(const float& x) { return _isnan(x)!=0; } - -EIGEN_DEVICE_FUNC inline bool isinf_impl(const long double& x) { return isinf_msvc_helper(x); } -EIGEN_DEVICE_FUNC inline bool isinf_impl(const double& x) { return isinf_msvc_helper(x); } -EIGEN_DEVICE_FUNC inline bool isinf_impl(const float& x) { return isinf_msvc_helper(x); } - -#elif (defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ && EIGEN_COMP_GNUC) - -#if EIGEN_GNUC_AT_LEAST(5,0) - #define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((optimize("no-finite-math-only"))) -#else - // NOTE the inline qualifier and noinline attribute are both needed: the former is to avoid linking issue (duplicate symbol), - // while the second prevent too aggressive optimizations in fast-math mode: - #define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((noinline,optimize("no-finite-math-only"))) -#endif - -template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const long double& x) { return __builtin_isnan(x); } -template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const double& x) { return __builtin_isnan(x); } -template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const float& x) { return __builtin_isnan(x); } -template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const double& x) { return __builtin_isinf(x); } -template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const float& x) { return __builtin_isinf(x); } -template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const long double& x) { return __builtin_isinf(x); } - -#undef EIGEN_TMP_NOOPT_ATTRIB - -#endif - -#endif - -// The following overload are defined at the end of this file -template<typename T> EIGEN_DEVICE_FUNC bool isfinite_impl(const std::complex<T>& x); -template<typename T> EIGEN_DEVICE_FUNC bool isnan_impl(const std::complex<T>& x); -template<typename T> EIGEN_DEVICE_FUNC bool isinf_impl(const std::complex<T>& x); - -template<typename T> T generic_fast_tanh_float(const T& a_x); -} // end namespace internal - -/**************************************************************************** -* Generic math functions * -****************************************************************************/ - -namespace numext { - -#if (!defined(EIGEN_GPUCC) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC)) -template<typename T> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE T mini(const T& x, const T& y) -{ - EIGEN_USING_STD_MATH(min); - return min EIGEN_NOT_A_MACRO (x,y); -} - -template<typename T> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y) -{ - EIGEN_USING_STD_MATH(max); - return max EIGEN_NOT_A_MACRO (x,y); -} -#else -template<typename T> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE T mini(const T& x, const T& y) -{ - return y < x ? y : x; -} -template<> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE float mini(const float& x, const float& y) -{ - return fminf(x, y); -} -template<> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE double mini(const double& x, const double& y) -{ - return fmin(x, y); -} -template<> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE long double mini(const long double& x, const long double& y) -{ -#if defined(EIGEN_HIPCC) - // no "fminl" on HIP yet - return (x < y) ? x : y; -#else - return fminl(x, y); -#endif -} - -template<typename T> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y) -{ - return x < y ? y : x; -} -template<> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE float maxi(const float& x, const float& y) -{ - return fmaxf(x, y); -} -template<> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE double maxi(const double& x, const double& y) -{ - return fmax(x, y); -} -template<> -EIGEN_DEVICE_FUNC -EIGEN_ALWAYS_INLINE long double maxi(const long double& x, const long double& y) -{ -#if defined(EIGEN_HIPCC) - // no "fmaxl" on HIP yet - return (x > y) ? x : y; -#else - return fmaxl(x, y); -#endif -} -#endif - -#if defined(SYCL_DEVICE_ONLY) - - -#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_long) -#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_long) -#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong) -#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong) -#define SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(NAME, FUNC) \ - SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \ - SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) -#define SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(NAME, FUNC) \ - SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \ - SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) -#define SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(NAME, FUNC) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \ - SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC,cl::sycl::cl_double) -#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(NAME, FUNC) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \ - SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC,cl::sycl::cl_double) -#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(NAME, FUNC, RET_TYPE) \ - SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_float) \ - SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_double) - -#define SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \ -template<> \ - EIGEN_DEVICE_FUNC \ - EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE& x) { \ - return cl::sycl::FUNC(x); \ - } - -#define SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, TYPE) \ - SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, TYPE, TYPE) - -#define SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE1, ARG_TYPE2) \ - template<> \ - EIGEN_DEVICE_FUNC \ - EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE1& x, const ARG_TYPE2& y) { \ - return cl::sycl::FUNC(x, y); \ - } - -#define SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \ - SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE, ARG_TYPE) - -#define SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, TYPE) \ - SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, TYPE, TYPE) - -SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(mini, min) -SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(mini, fmin) -SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(maxi, max) -SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(maxi, fmax) - -#endif - - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(real, Scalar) real(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(const Scalar& x) -{ - return internal::real_ref_impl<Scalar>::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) imag(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(arg, Scalar) arg(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(arg, Scalar)::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(const Scalar& x) -{ - return internal::imag_ref_impl<Scalar>::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) conj(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x); -} - -EIGEN_DEVICE_FUNC -inline bool abs2(bool x) { return x; } - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(const Scalar& x, const Scalar& y) -{ - return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y); -} - -#if defined(SYCL_DEVICE_ONLY) - SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(hypot, hypot) -#endif - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(log1p, Scalar) log1p(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(log1p, Scalar)::run(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log1p, log1p) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float log1p(const float &x) { return ::log1pf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double log1p(const double &x) { return ::log1p(x); } -#endif - -template<typename ScalarX,typename ScalarY> -EIGEN_DEVICE_FUNC -inline typename internal::pow_impl<ScalarX,ScalarY>::result_type pow(const ScalarX& x, const ScalarY& y) -{ - return internal::pow_impl<ScalarX,ScalarY>::run(x, y); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(pow, pow) -#endif - -template<typename T> EIGEN_DEVICE_FUNC bool (isnan) (const T &x) { return internal::isnan_impl(x); } -template<typename T> EIGEN_DEVICE_FUNC bool (isinf) (const T &x) { return internal::isinf_impl(x); } -template<typename T> EIGEN_DEVICE_FUNC bool (isfinite)(const T &x) { return internal::isfinite_impl(x); } - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isnan, isnan, bool) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isinf, isinf, bool) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isfinite, isfinite, bool) -#endif - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(rint, Scalar) rint(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(rint, Scalar)::run(x); -} - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(round, Scalar) round(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(round, Scalar)::run(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(round, round) -#endif - -template<typename T> -EIGEN_DEVICE_FUNC -T (floor)(const T& x) -{ - EIGEN_USING_STD_MATH(floor); - return floor(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(floor, floor) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float floor(const float &x) { return ::floorf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double floor(const double &x) { return ::floor(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC -T (ceil)(const T& x) -{ - EIGEN_USING_STD_MATH(ceil); - return ceil(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(ceil, ceil) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float ceil(const float &x) { return ::ceilf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double ceil(const double &x) { return ::ceil(x); } -#endif - - -/** Log base 2 for 32 bits positive integers. - * Conveniently returns 0 for x==0. */ -inline int log2(int x) -{ - eigen_assert(x>=0); - unsigned int v(x); - static const int table[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - return table[(v * 0x07C4ACDDU) >> 27]; -} - -/** \returns the square root of \a x. - * - * It is essentially equivalent to - * \code using std::sqrt; return sqrt(x); \endcode - * but slightly faster for float/double and some compilers (e.g., gcc), thanks to - * specializations when SSE is enabled. - * - * It's usage is justified in performance critical functions, like norm/normalize. - */ -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T sqrt(const T &x) -{ - EIGEN_USING_STD_MATH(sqrt); - return sqrt(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sqrt, sqrt) -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T log(const T &x) { - EIGEN_USING_STD_MATH(log); - return log(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log, log) -#endif - - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float log(const float &x) { return ::logf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double log(const double &x) { return ::log(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -typename internal::enable_if<NumTraits<T>::IsSigned || NumTraits<T>::IsComplex,typename NumTraits<T>::Real>::type -abs(const T &x) { - EIGEN_USING_STD_MATH(abs); - return abs(x); -} - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -typename internal::enable_if<!(NumTraits<T>::IsSigned || NumTraits<T>::IsComplex),typename NumTraits<T>::Real>::type -abs(const T &x) { - return x; -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(abs, abs) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(abs, fabs) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float abs(const float &x) { return ::fabsf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double abs(const double &x) { return ::fabs(x); } - -template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float abs(const std::complex<float>& x) { - return ::hypotf(x.real(), x.imag()); -} - -template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double abs(const std::complex<double>& x) { - return ::hypot(x.real(), x.imag()); -} -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T exp(const T &x) { - EIGEN_USING_STD_MATH(exp); - return exp(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(exp, exp) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float exp(const float &x) { return ::expf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double exp(const double &x) { return ::exp(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -std::complex<float> exp(const std::complex<float>& x) { - float com = ::expf(x.real()); - float res_real = com * ::cosf(x.imag()); - float res_imag = com * ::sinf(x.imag()); - return std::complex<float>(res_real, res_imag); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -std::complex<double> exp(const std::complex<double>& x) { - double com = ::exp(x.real()); - double res_real = com * ::cos(x.imag()); - double res_imag = com * ::sin(x.imag()); - return std::complex<double>(res_real, res_imag); -} -#endif - -template<typename Scalar> -EIGEN_DEVICE_FUNC -inline EIGEN_MATHFUNC_RETVAL(expm1, Scalar) expm1(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(expm1, Scalar)::run(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(expm1, expm1) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float expm1(const float &x) { return ::expm1f(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double expm1(const double &x) { return ::expm1(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T cos(const T &x) { - EIGEN_USING_STD_MATH(cos); - return cos(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cos,cos) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float cos(const float &x) { return ::cosf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double cos(const double &x) { return ::cos(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T sin(const T &x) { - EIGEN_USING_STD_MATH(sin); - return sin(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sin, sin) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float sin(const float &x) { return ::sinf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double sin(const double &x) { return ::sin(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T tan(const T &x) { - EIGEN_USING_STD_MATH(tan); - return tan(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tan, tan) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float tan(const float &x) { return ::tanf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double tan(const double &x) { return ::tan(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T acos(const T &x) { - EIGEN_USING_STD_MATH(acos); - return acos(x); -} - -#if EIGEN_HAS_CXX11_MATH -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T acosh(const T &x) { - EIGEN_USING_STD_MATH(acosh); - return acosh(x); -} -#endif - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acos, acos) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acosh, acosh) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float acos(const float &x) { return ::acosf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double acos(const double &x) { return ::acos(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T asin(const T &x) { - EIGEN_USING_STD_MATH(asin); - return asin(x); -} - -#if EIGEN_HAS_CXX11_MATH -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T asinh(const T &x) { - EIGEN_USING_STD_MATH(asinh); - return asinh(x); -} -#endif - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asin, asin) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asinh, asinh) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float asin(const float &x) { return ::asinf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double asin(const double &x) { return ::asin(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T atan(const T &x) { - EIGEN_USING_STD_MATH(atan); - return atan(x); -} - -#if EIGEN_HAS_CXX11_MATH -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T atanh(const T &x) { - EIGEN_USING_STD_MATH(atanh); - return atanh(x); -} -#endif - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atan, atan) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atanh, atanh) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float atan(const float &x) { return ::atanf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double atan(const double &x) { return ::atan(x); } -#endif - - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T cosh(const T &x) { - EIGEN_USING_STD_MATH(cosh); - return cosh(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cosh, cosh) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float cosh(const float &x) { return ::coshf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double cosh(const double &x) { return ::cosh(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T sinh(const T &x) { - EIGEN_USING_STD_MATH(sinh); - return sinh(x); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sinh, sinh) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float sinh(const float &x) { return ::sinhf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double sinh(const double &x) { return ::sinh(x); } -#endif - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T tanh(const T &x) { - EIGEN_USING_STD_MATH(tanh); - return tanh(x); -} - -#if (!defined(EIGEN_GPUCC)) && EIGEN_FAST_MATH && !defined(SYCL_DEVICE_ONLY) -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float tanh(float x) { return internal::generic_fast_tanh_float(x); } -#endif - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tanh, tanh) -#endif - -#if defined(EIGEN_GPUCC) -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float tanh(const float &x) { return ::tanhf(x); } - -template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double tanh(const double &x) { return ::tanh(x); } -#endif - -template <typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T fmod(const T& a, const T& b) { - EIGEN_USING_STD_MATH(fmod); - return fmod(a, b); -} - -#if defined(SYCL_DEVICE_ONLY) -SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(fmod, fmod) -#endif - -#if defined(EIGEN_GPUCC) -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float fmod(const float& a, const float& b) { - return ::fmodf(a, b); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double fmod(const double& a, const double& b) { - return ::fmod(a, b); -} -#endif - -#if defined(SYCL_DEVICE_ONLY) -#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY -#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY -#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY -#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY -#undef SYCL_SPECIALIZE_INTEGER_TYPES_BINARY -#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY -#undef SYCL_SPECIALIZE_FLOATING_TYPES_BINARY -#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY -#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE -#undef SYCL_SPECIALIZE_GEN_UNARY_FUNC -#undef SYCL_SPECIALIZE_UNARY_FUNC -#undef SYCL_SPECIALIZE_GEN1_BINARY_FUNC -#undef SYCL_SPECIALIZE_GEN2_BINARY_FUNC -#undef SYCL_SPECIALIZE_BINARY_FUNC -#endif - -} // end namespace numext - -namespace internal { - -template<typename T> -EIGEN_DEVICE_FUNC bool isfinite_impl(const std::complex<T>& x) -{ - return (numext::isfinite)(numext::real(x)) && (numext::isfinite)(numext::imag(x)); -} - -template<typename T> -EIGEN_DEVICE_FUNC bool isnan_impl(const std::complex<T>& x) -{ - return (numext::isnan)(numext::real(x)) || (numext::isnan)(numext::imag(x)); -} - -template<typename T> -EIGEN_DEVICE_FUNC bool isinf_impl(const std::complex<T>& x) -{ - return ((numext::isinf)(numext::real(x)) || (numext::isinf)(numext::imag(x))) && (!(numext::isnan)(x)); -} - -/**************************************************************************** -* Implementation of fuzzy comparisons * -****************************************************************************/ - -template<typename Scalar, - bool IsComplex, - bool IsInteger> -struct scalar_fuzzy_default_impl {}; - -template<typename Scalar> -struct scalar_fuzzy_default_impl<Scalar, false, false> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - template<typename OtherScalar> EIGEN_DEVICE_FUNC - static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec) - { - return numext::abs(x) <= numext::abs(y) * prec; - } - EIGEN_DEVICE_FUNC - static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec) - { - return numext::abs(x - y) <= numext::mini(numext::abs(x), numext::abs(y)) * prec; - } - EIGEN_DEVICE_FUNC - static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar& prec) - { - return x <= y || isApprox(x, y, prec); - } -}; - -template<typename Scalar> -struct scalar_fuzzy_default_impl<Scalar, false, true> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - template<typename OtherScalar> EIGEN_DEVICE_FUNC - static inline bool isMuchSmallerThan(const Scalar& x, const Scalar&, const RealScalar&) - { - return x == Scalar(0); - } - EIGEN_DEVICE_FUNC - static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar&) - { - return x == y; - } - EIGEN_DEVICE_FUNC - static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar&) - { - return x <= y; - } -}; - -template<typename Scalar> -struct scalar_fuzzy_default_impl<Scalar, true, false> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - template<typename OtherScalar> EIGEN_DEVICE_FUNC - static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec) - { - return numext::abs2(x) <= numext::abs2(y) * prec * prec; - } - EIGEN_DEVICE_FUNC - static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec) - { - return numext::abs2(x - y) <= numext::mini(numext::abs2(x), numext::abs2(y)) * prec * prec; - } -}; - -template<typename Scalar> -struct scalar_fuzzy_impl : scalar_fuzzy_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {}; - -template<typename Scalar, typename OtherScalar> EIGEN_DEVICE_FUNC -inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, - const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision()) -{ - return scalar_fuzzy_impl<Scalar>::template isMuchSmallerThan<OtherScalar>(x, y, precision); -} - -template<typename Scalar> EIGEN_DEVICE_FUNC -inline bool isApprox(const Scalar& x, const Scalar& y, - const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision()) -{ - return scalar_fuzzy_impl<Scalar>::isApprox(x, y, precision); -} - -template<typename Scalar> EIGEN_DEVICE_FUNC -inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, - const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision()) -{ - return scalar_fuzzy_impl<Scalar>::isApproxOrLessThan(x, y, precision); -} - -/****************************************** -*** The special case of the bool type *** -******************************************/ - -template<> struct random_impl<bool> -{ - static inline bool run() - { - return random<int>(0,1)==0 ? false : true; - } -}; - -template<> struct scalar_fuzzy_impl<bool> -{ - typedef bool RealScalar; - - template<typename OtherScalar> EIGEN_DEVICE_FUNC - static inline bool isMuchSmallerThan(const bool& x, const bool&, const bool&) - { - return !x; - } - - EIGEN_DEVICE_FUNC - static inline bool isApprox(bool x, bool y, bool) - { - return x == y; - } - - EIGEN_DEVICE_FUNC - static inline bool isApproxOrLessThan(const bool& x, const bool& y, const bool&) - { - return (!x) || y; - } - -}; - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATHFUNCTIONS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/MathFunctionsImpl.h b/external/eigen/include/eigen3/Eigen/src/Core/MathFunctionsImpl.h deleted file mode 100644 index 7af58fad..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/MathFunctionsImpl.h +++ /dev/null @@ -1,106 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) -// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATHFUNCTIONSIMPL_H -#define EIGEN_MATHFUNCTIONSIMPL_H - -namespace Eigen { - -namespace internal { - -/** \internal \returns the hyperbolic tan of \a a (coeff-wise) - Doesn't do anything fancy, just a 13/6-degree rational interpolant which - is accurate up to a couple of ulps in the (approximate) range [-8, 8], - outside of which tanh(x) = +/-1 in single precision. The input is clamped - to the range [-c, c]. The value c is chosen as the smallest value where - the approximation evaluates to exactly 1. In the reange [-0.0004, 0.0004] - the approxmation tanh(x) ~= x is used for better accuracy as x tends to zero. - - This implementation works on both scalars and packets. -*/ -template<typename T> -T generic_fast_tanh_float(const T& a_x) -{ - // Clamp the inputs to the range [-c, c] -#ifdef EIGEN_VECTORIZE_FMA - const T plus_clamp = pset1<T>(7.99881172180175781f); - const T minus_clamp = pset1<T>(-7.99881172180175781f); -#else - const T plus_clamp = pset1<T>(7.90531110763549805f); - const T minus_clamp = pset1<T>(-7.90531110763549805f); -#endif - const T tiny = pset1<T>(0.0004f); - const T x = pmax(pmin(a_x, plus_clamp), minus_clamp); - const T tiny_mask = pcmp_lt(pabs(a_x), tiny); - // The monomial coefficients of the numerator polynomial (odd). - const T alpha_1 = pset1<T>(4.89352455891786e-03f); - const T alpha_3 = pset1<T>(6.37261928875436e-04f); - const T alpha_5 = pset1<T>(1.48572235717979e-05f); - const T alpha_7 = pset1<T>(5.12229709037114e-08f); - const T alpha_9 = pset1<T>(-8.60467152213735e-11f); - const T alpha_11 = pset1<T>(2.00018790482477e-13f); - const T alpha_13 = pset1<T>(-2.76076847742355e-16f); - - // The monomial coefficients of the denominator polynomial (even). - const T beta_0 = pset1<T>(4.89352518554385e-03f); - const T beta_2 = pset1<T>(2.26843463243900e-03f); - const T beta_4 = pset1<T>(1.18534705686654e-04f); - const T beta_6 = pset1<T>(1.19825839466702e-06f); - - // Since the polynomials are odd/even, we need x^2. - const T x2 = pmul(x, x); - - // Evaluate the numerator polynomial p. - T p = pmadd(x2, alpha_13, alpha_11); - p = pmadd(x2, p, alpha_9); - p = pmadd(x2, p, alpha_7); - p = pmadd(x2, p, alpha_5); - p = pmadd(x2, p, alpha_3); - p = pmadd(x2, p, alpha_1); - p = pmul(x, p); - - // Evaluate the denominator polynomial q. - T q = pmadd(x2, beta_6, beta_4); - q = pmadd(x2, q, beta_2); - q = pmadd(x2, q, beta_0); - - // Divide the numerator by the denominator. - return pselect(tiny_mask, x, pdiv(p, q)); -} - -template<typename RealScalar> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -RealScalar positive_real_hypot(const RealScalar& x, const RealScalar& y) -{ - EIGEN_USING_STD_MATH(sqrt); - RealScalar p, qp; - p = numext::maxi(x,y); - if(p==RealScalar(0)) return RealScalar(0); - qp = numext::mini(y,x) / p; - return p * sqrt(RealScalar(1) + qp*qp); -} - -template<typename Scalar> -struct hypot_impl -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - static EIGEN_DEVICE_FUNC - inline RealScalar run(const Scalar& x, const Scalar& y) - { - EIGEN_USING_STD_MATH(abs); - return positive_real_hypot<RealScalar>(abs(x), abs(y)); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATHFUNCTIONSIMPL_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Matrix.h b/external/eigen/include/eigen3/Eigen/src/Core/Matrix.h deleted file mode 100644 index fb723826..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Matrix.h +++ /dev/null @@ -1,563 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIX_H -#define EIGEN_MATRIX_H - -namespace Eigen { - -namespace internal { -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > -{ -private: - enum { size = internal::size_at_compile_time<_Rows,_Cols>::ret }; - typedef typename find_best_packet<_Scalar,size>::type PacketScalar; - enum { - row_major_bit = _Options&RowMajor ? RowMajorBit : 0, - is_dynamic_size_storage = _MaxRows==Dynamic || _MaxCols==Dynamic, - max_size = is_dynamic_size_storage ? Dynamic : _MaxRows*_MaxCols, - default_alignment = compute_default_alignment<_Scalar,max_size>::value, - actual_alignment = ((_Options&DontAlign)==0) ? default_alignment : 0, - required_alignment = unpacket_traits<PacketScalar>::alignment, - packet_access_bit = (packet_traits<_Scalar>::Vectorizable && (EIGEN_UNALIGNED_VECTORIZE || (actual_alignment>=required_alignment))) ? PacketAccessBit : 0 - }; - -public: - typedef _Scalar Scalar; - typedef Dense StorageKind; - typedef Eigen::Index StorageIndex; - typedef MatrixXpr XprKind; - enum { - RowsAtCompileTime = _Rows, - ColsAtCompileTime = _Cols, - MaxRowsAtCompileTime = _MaxRows, - MaxColsAtCompileTime = _MaxCols, - Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret, - Options = _Options, - InnerStrideAtCompileTime = 1, - OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime, - - // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase - EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit, - Alignment = actual_alignment - }; -}; -} - -/** \class Matrix - * \ingroup Core_Module - * - * \brief The matrix class, also used for vectors and row-vectors - * - * The %Matrix class is the work-horse for all \em dense (\ref dense "note") matrices and vectors within Eigen. - * Vectors are matrices with one column, and row-vectors are matrices with one row. - * - * The %Matrix class encompasses \em both fixed-size and dynamic-size objects (\ref fixedsize "note"). - * - * The first three template parameters are required: - * \tparam _Scalar Numeric type, e.g. float, double, int or std::complex<float>. - * User defined scalar types are supported as well (see \ref user_defined_scalars "here"). - * \tparam _Rows Number of rows, or \b Dynamic - * \tparam _Cols Number of columns, or \b Dynamic - * - * The remaining template parameters are optional -- in most cases you don't have to worry about them. - * \tparam _Options A combination of either \b #RowMajor or \b #ColMajor, and of either - * \b #AutoAlign or \b #DontAlign. - * The former controls \ref TopicStorageOrders "storage order", and defaults to column-major. The latter controls alignment, which is required - * for vectorization. It defaults to aligning matrices except for fixed sizes that aren't a multiple of the packet size. - * \tparam _MaxRows Maximum number of rows. Defaults to \a _Rows (\ref maxrows "note"). - * \tparam _MaxCols Maximum number of columns. Defaults to \a _Cols (\ref maxrows "note"). - * - * Eigen provides a number of typedefs covering the usual cases. Here are some examples: - * - * \li \c Matrix2d is a 2x2 square matrix of doubles (\c Matrix<double, 2, 2>) - * \li \c Vector4f is a vector of 4 floats (\c Matrix<float, 4, 1>) - * \li \c RowVector3i is a row-vector of 3 ints (\c Matrix<int, 1, 3>) - * - * \li \c MatrixXf is a dynamic-size matrix of floats (\c Matrix<float, Dynamic, Dynamic>) - * \li \c VectorXf is a dynamic-size vector of floats (\c Matrix<float, Dynamic, 1>) - * - * \li \c Matrix2Xf is a partially fixed-size (dynamic-size) matrix of floats (\c Matrix<float, 2, Dynamic>) - * \li \c MatrixX3d is a partially dynamic-size (fixed-size) matrix of double (\c Matrix<double, Dynamic, 3>) - * - * See \link matrixtypedefs this page \endlink for a complete list of predefined \em %Matrix and \em Vector typedefs. - * - * You can access elements of vectors and matrices using normal subscripting: - * - * \code - * Eigen::VectorXd v(10); - * v[0] = 0.1; - * v[1] = 0.2; - * v(0) = 0.3; - * v(1) = 0.4; - * - * Eigen::MatrixXi m(10, 10); - * m(0, 1) = 1; - * m(0, 2) = 2; - * m(0, 3) = 3; - * \endcode - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIX_PLUGIN. - * - * <i><b>Some notes:</b></i> - * - * <dl> - * <dt><b>\anchor dense Dense versus sparse:</b></dt> - * <dd>This %Matrix class handles dense, not sparse matrices and vectors. For sparse matrices and vectors, see the Sparse module. - * - * Dense matrices and vectors are plain usual arrays of coefficients. All the coefficients are stored, in an ordinary contiguous array. - * This is unlike Sparse matrices and vectors where the coefficients are stored as a list of nonzero coefficients.</dd> - * - * <dt><b>\anchor fixedsize Fixed-size versus dynamic-size:</b></dt> - * <dd>Fixed-size means that the numbers of rows and columns are known are compile-time. In this case, Eigen allocates the array - * of coefficients as a fixed-size array, as a class member. This makes sense for very small matrices, typically up to 4x4, sometimes up - * to 16x16. Larger matrices should be declared as dynamic-size even if one happens to know their size at compile-time. - * - * Dynamic-size means that the numbers of rows or columns are not necessarily known at compile-time. In this case they are runtime - * variables, and the array of coefficients is allocated dynamically on the heap. - * - * Note that \em dense matrices, be they Fixed-size or Dynamic-size, <em>do not</em> expand dynamically in the sense of a std::map. - * If you want this behavior, see the Sparse module.</dd> - * - * <dt><b>\anchor maxrows _MaxRows and _MaxCols:</b></dt> - * <dd>In most cases, one just leaves these parameters to the default values. - * These parameters mean the maximum size of rows and columns that the matrix may have. They are useful in cases - * when the exact numbers of rows and columns are not known are compile-time, but it is known at compile-time that they cannot - * exceed a certain value. This happens when taking dynamic-size blocks inside fixed-size matrices: in this case _MaxRows and _MaxCols - * are the dimensions of the original matrix, while _Rows and _Cols are Dynamic.</dd> - * </dl> - * - * <i><b>ABI and storage layout</b></i> - * - * The table below summarizes the ABI of some possible Matrix instances which is fixed thorough the lifetime of Eigen 3. - * <table class="manual"> - * <tr><th>Matrix type</th><th>Equivalent C structure</th></tr> - * <tr><td>\code Matrix<T,Dynamic,Dynamic> \endcode</td><td>\code - * struct { - * T *data; // with (size_t(data)%EIGEN_MAX_ALIGN_BYTES)==0 - * Eigen::Index rows, cols; - * }; - * \endcode</td></tr> - * <tr class="alt"><td>\code - * Matrix<T,Dynamic,1> - * Matrix<T,1,Dynamic> \endcode</td><td>\code - * struct { - * T *data; // with (size_t(data)%EIGEN_MAX_ALIGN_BYTES)==0 - * Eigen::Index size; - * }; - * \endcode</td></tr> - * <tr><td>\code Matrix<T,Rows,Cols> \endcode</td><td>\code - * struct { - * T data[Rows*Cols]; // with (size_t(data)%A(Rows*Cols*sizeof(T)))==0 - * }; - * \endcode</td></tr> - * <tr class="alt"><td>\code Matrix<T,Dynamic,Dynamic,0,MaxRows,MaxCols> \endcode</td><td>\code - * struct { - * T data[MaxRows*MaxCols]; // with (size_t(data)%A(MaxRows*MaxCols*sizeof(T)))==0 - * Eigen::Index rows, cols; - * }; - * \endcode</td></tr> - * </table> - * Note that in this table Rows, Cols, MaxRows and MaxCols are all positive integers. A(S) is defined to the largest possible power-of-two - * smaller to EIGEN_MAX_STATIC_ALIGN_BYTES. - * - * \see MatrixBase for the majority of the API methods for matrices, \ref TopicClassHierarchy, - * \ref TopicStorageOrders - */ - -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -class Matrix - : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > -{ - public: - - /** \brief Base class typedef. - * \sa PlainObjectBase - */ - typedef PlainObjectBase<Matrix> Base; - - enum { Options = _Options }; - - EIGEN_DENSE_PUBLIC_INTERFACE(Matrix) - - typedef typename Base::PlainObject PlainObject; - - using Base::base; - using Base::coeffRef; - - /** - * \brief Assigns matrices to each other. - * - * \note This is a special case of the templated operator=. Its purpose is - * to prevent a default operator= from hiding the templated operator=. - * - * \callgraph - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other) - { - return Base::_set(other); - } - - /** \internal - * \brief Copies the value of the expression \a other into \c *this with automatic resizing. - * - * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized), - * it will be initialized. - * - * Note that copying a row-vector into a vector (and conversely) is allowed. - * The resizing, if any, is then done in the appropriate way so that row-vectors - * remain row-vectors and vectors remain vectors. - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase<OtherDerived>& other) - { - return Base::_set(other); - } - - /* Here, doxygen failed to copy the brief information when using \copydoc */ - - /** - * \brief Copies the generic expression \a other into *this. - * \copydetails DenseBase::operator=(const EigenBase<OtherDerived> &other) - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other) - { - return Base::operator=(other); - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func) - { - return Base::operator=(func); - } - - /** \brief Default constructor. - * - * For fixed-size matrices, does nothing. - * - * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix - * is called a null matrix. This constructor is the unique way to create null matrices: resizing - * a matrix to 0 is not supported. - * - * \sa resize(Index,Index) - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Matrix() : Base() - { - Base::_check_template_params(); - EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - } - - // FIXME is it still needed - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit Matrix(internal::constructor_without_unaligned_array_assert) - : Base(internal::constructor_without_unaligned_array_assert()) - { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED } - -#if EIGEN_HAS_RVALUE_REFERENCES - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Matrix(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value) - : Base(std::move(other)) - { - Base::_check_template_params(); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Matrix& operator=(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) - { - other.swap(*this); - return *this; - } -#endif - -#if EIGEN_HAS_CXX11 - /** \copydoc PlainObjectBase(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&... args) - * - * Example: \include Matrix_variadic_ctor_cxx11.cpp - * Output: \verbinclude Matrix_variadic_ctor_cxx11.out - * - * \sa Matrix(const std::initializer_list<std::initializer_list<Scalar>>&) - */ - template <typename... ArgTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) - : Base(a0, a1, a2, a3, args...) {} - - /** \brief Constructs a Matrix and initializes it from the coefficients given as initializer-lists grouped by row. \cpp11 - * - * In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients: - * - * Example: \include Matrix_initializer_list_23_cxx11.cpp - * Output: \verbinclude Matrix_initializer_list_23_cxx11.out - * - * Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is triggered. - * - * In the case of a compile-time column vector, implicit transposition from a single row is allowed. - * Therefore <code>VectorXd{{1,2,3,4,5}}</code> is legal and the more verbose syntax - * <code>RowVectorXd{{1},{2},{3},{4},{5}}</code> can be avoided: - * - * Example: \include Matrix_initializer_list_vector_cxx11.cpp - * Output: \verbinclude Matrix_initializer_list_vector_cxx11.out - * - * In the case of fixed-sized matrices, the initializer list sizes must exactly match the matrix sizes, - * and implicit transposition is allowed for compile-time vectors only. - * - * \sa Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) - */ - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {} -#endif // end EIGEN_HAS_CXX11 - -#ifndef EIGEN_PARSED_BY_DOXYGEN - - // This constructor is for both 1x1 matrices and dynamic vectors - template<typename T> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit Matrix(const T& x) - { - Base::_check_template_params(); - Base::template _init1<T>(x); - } - - template<typename T0, typename T1> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Matrix(const T0& x, const T1& y) - { - Base::_check_template_params(); - Base::template _init2<T0,T1>(x, y); - } - - -#else - /** \brief Constructs a fixed-sized matrix initialized with coefficients starting at \a data */ - EIGEN_DEVICE_FUNC - explicit Matrix(const Scalar *data); - - /** \brief Constructs a vector or row-vector with given dimension. \only_for_vectors - * - * This is useful for dynamic-size vectors. For fixed-size vectors, - * it is redundant to pass these parameters, so one should use the default constructor - * Matrix() instead. - * - * \warning This constructor is disabled for fixed-size \c 1x1 matrices. For instance, - * calling Matrix<double,1,1>(1) will call the initialization constructor: Matrix(const Scalar&). - * For fixed-size \c 1x1 matrices it is therefore recommended to use the default - * constructor Matrix() instead, especially when using one of the non standard - * \c EIGEN_INITIALIZE_MATRICES_BY_{ZERO,\c NAN} macros (see \ref TopicPreprocessorDirectives). - */ - EIGEN_STRONG_INLINE explicit Matrix(Index dim); - /** \brief Constructs an initialized 1x1 matrix with the given coefficient - * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) */ - Matrix(const Scalar& x); - /** \brief Constructs an uninitialized matrix with \a rows rows and \a cols columns. - * - * This is useful for dynamic-size matrices. For fixed-size matrices, - * it is redundant to pass these parameters, so one should use the default constructor - * Matrix() instead. - * - * \warning This constructor is disabled for fixed-size \c 1x2 and \c 2x1 vectors. For instance, - * calling Matrix2f(2,1) will call the initialization constructor: Matrix(const Scalar& x, const Scalar& y). - * For fixed-size \c 1x2 or \c 2x1 vectors it is therefore recommended to use the default - * constructor Matrix() instead, especially when using one of the non standard - * \c EIGEN_INITIALIZE_MATRICES_BY_{ZERO,\c NAN} macros (see \ref TopicPreprocessorDirectives). - */ - EIGEN_DEVICE_FUNC - Matrix(Index rows, Index cols); - - /** \brief Constructs an initialized 2D vector with given coefficients - * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) */ - Matrix(const Scalar& x, const Scalar& y); - #endif // end EIGEN_PARSED_BY_DOXYGEN - - /** \brief Constructs an initialized 3D vector with given coefficients - * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z) - { - Base::_check_template_params(); - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3) - m_storage.data()[0] = x; - m_storage.data()[1] = y; - m_storage.data()[2] = z; - } - /** \brief Constructs an initialized 4D vector with given coefficients - * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w) - { - Base::_check_template_params(); - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4) - m_storage.data()[0] = x; - m_storage.data()[1] = y; - m_storage.data()[2] = z; - m_storage.data()[3] = w; - } - - - /** \brief Copy constructor */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other) - { } - - /** \brief Copy constructor for generic expressions. - * \sa MatrixBase::operator=(const EigenBase<OtherDerived>&) - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other) - : Base(other.derived()) - { } - - EIGEN_DEVICE_FUNC inline Index innerStride() const { return 1; } - EIGEN_DEVICE_FUNC inline Index outerStride() const { return this->innerSize(); } - - /////////// Geometry module /////////// - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r); - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r); - - // allow to extend Matrix outside Eigen - #ifdef EIGEN_MATRIX_PLUGIN - #include EIGEN_MATRIX_PLUGIN - #endif - - protected: - template <typename Derived, typename OtherDerived, bool IsVector> - friend struct internal::conservative_resize_like_impl; - - using Base::m_storage; -}; - -/** \defgroup matrixtypedefs Global matrix typedefs - * - * \ingroup Core_Module - * - * %Eigen defines several typedef shortcuts for most common matrix and vector types. - * - * The general patterns are the following: - * - * \c MatrixSizeType where \c Size can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size, - * and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c cd - * for complex double. - * - * For example, \c Matrix3d is a fixed-size 3x3 matrix type of doubles, and \c MatrixXf is a dynamic-size matrix of floats. - * - * There are also \c VectorSizeType and \c RowVectorSizeType which are self-explanatory. For example, \c Vector4cf is - * a fixed-size vector of 4 complex floats. - * - * With \cpp11, template alias are also defined for common sizes. - * They follow the same pattern as above except that the scalar type suffix is replaced by a - * template parameter, i.e.: - * - `MatrixSize<Type>` where `Size` can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size. - * - `MatrixXSize<Type>` and `MatrixSizeX<Type>` where `Size` can be \c 2,\c 3,\c 4 for hybrid dynamic/fixed matrices. - * - `VectorSize<Type>` and `RowVectorSize<Type>` for column and row vectors. - * - * With \cpp11, you can also use fully generic column and row vector types: `Vector<Type,Size>` and `RowVector<Type,Size>`. - * - * \sa class Matrix - */ - -#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ -/** \ingroup matrixtypedefs */ \ -typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \ -/** \ingroup matrixtypedefs */ \ -typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \ -/** \ingroup matrixtypedefs */ \ -typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix; - -#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \ -/** \ingroup matrixtypedefs */ \ -typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \ -/** \ingroup matrixtypedefs */ \ -typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix; - -#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \ -EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \ -EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \ -EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4) - -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i) -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f) -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d) -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf) -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd) - -#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES -#undef EIGEN_MAKE_TYPEDEFS -#undef EIGEN_MAKE_FIXED_TYPEDEFS - -#if EIGEN_HAS_CXX11 - -#define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \ -/** \ingroup matrixtypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using Matrix##SizeSuffix = Matrix<Type, Size, Size>; \ -/** \ingroup matrixtypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using Vector##SizeSuffix = Matrix<Type, Size, 1>; \ -/** \ingroup matrixtypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using RowVector##SizeSuffix = Matrix<Type, 1, Size>; - -#define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \ -/** \ingroup matrixtypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using Matrix##Size##X = Matrix<Type, Size, Dynamic>; \ -/** \ingroup matrixtypedefs */ \ -/** \brief \cpp11 */ \ -template <typename Type> \ -using Matrix##X##Size = Matrix<Type, Dynamic, Size>; - -EIGEN_MAKE_TYPEDEFS(2, 2) -EIGEN_MAKE_TYPEDEFS(3, 3) -EIGEN_MAKE_TYPEDEFS(4, 4) -EIGEN_MAKE_TYPEDEFS(Dynamic, X) -EIGEN_MAKE_FIXED_TYPEDEFS(2) -EIGEN_MAKE_FIXED_TYPEDEFS(3) -EIGEN_MAKE_FIXED_TYPEDEFS(4) - -/** \ingroup matrixtypedefs - * \brief \cpp11 */ -template <typename Type, int Size> -using Vector = Matrix<Type, Size, 1>; - -/** \ingroup matrixtypedefs - * \brief \cpp11 */ -template <typename Type, int Size> -using RowVector = Matrix<Type, 1, Size>; - -#undef EIGEN_MAKE_TYPEDEFS -#undef EIGEN_MAKE_FIXED_TYPEDEFS - -#endif // EIGEN_HAS_CXX11 - -} // end namespace Eigen - -#endif // EIGEN_MATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/MatrixBase.h b/external/eigen/include/eigen3/Eigen/src/Core/MatrixBase.h deleted file mode 100644 index 45c3a596..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/MatrixBase.h +++ /dev/null @@ -1,547 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIXBASE_H -#define EIGEN_MATRIXBASE_H - -namespace Eigen { - -/** \class MatrixBase - * \ingroup Core_Module - * - * \brief Base class for all dense matrices, vectors, and expressions - * - * This class is the base that is inherited by all matrix, vector, and related expression - * types. Most of the Eigen API is contained in this class, and its base classes. Other important - * classes for the Eigen API are Matrix, and VectorwiseOp. - * - * Note that some methods are defined in other modules such as the \ref LU_Module LU module - * for all functions related to matrix inversions. - * - * \tparam Derived is the derived type, e.g. a matrix type, or an expression, etc. - * - * When writing a function taking Eigen objects as argument, if you want your function - * to take as argument any matrix, vector, or expression, just let it take a - * MatrixBase argument. As an example, here is a function printFirstRow which, given - * a matrix, vector, or expression \a x, prints the first row of \a x. - * - * \code - template<typename Derived> - void printFirstRow(const Eigen::MatrixBase<Derived>& x) - { - cout << x.row(0) << endl; - } - * \endcode - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIXBASE_PLUGIN. - * - * \sa \blank \ref TopicClassHierarchy - */ -template<typename Derived> class MatrixBase - : public DenseBase<Derived> -{ - public: -#ifndef EIGEN_PARSED_BY_DOXYGEN - typedef MatrixBase StorageBaseType; - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::traits<Derived>::StorageIndex StorageIndex; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename internal::packet_traits<Scalar>::type PacketScalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - - typedef DenseBase<Derived> Base; - using Base::RowsAtCompileTime; - using Base::ColsAtCompileTime; - using Base::SizeAtCompileTime; - using Base::MaxRowsAtCompileTime; - using Base::MaxColsAtCompileTime; - using Base::MaxSizeAtCompileTime; - using Base::IsVectorAtCompileTime; - using Base::Flags; - - using Base::derived; - using Base::const_cast_derived; - using Base::rows; - using Base::cols; - using Base::size; - using Base::coeff; - using Base::coeffRef; - using Base::lazyAssign; - using Base::eval; - using Base::operator-; - using Base::operator+=; - using Base::operator-=; - using Base::operator*=; - using Base::operator/=; - - typedef typename Base::CoeffReturnType CoeffReturnType; - typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType; - typedef typename Base::RowXpr RowXpr; - typedef typename Base::ColXpr ColXpr; -#endif // not EIGEN_PARSED_BY_DOXYGEN - - - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** type of the equivalent square matrix */ - typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime), - EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType; -#endif // not EIGEN_PARSED_BY_DOXYGEN - - /** \returns the size of the main diagonal, which is min(rows(),cols()). - * \sa rows(), cols(), SizeAtCompileTime. */ - EIGEN_DEVICE_FUNC - inline Index diagonalSize() const { return (numext::mini)(rows(),cols()); } - - typedef typename Base::PlainObject PlainObject; - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal Represents a matrix with all coefficients equal to one another*/ - typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType; - /** \internal the return type of MatrixBase::adjoint() */ - typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>, - ConstTransposeReturnType - >::type AdjointReturnType; - /** \internal Return type of eigenvalues() */ - typedef Matrix<std::complex<RealScalar>, internal::traits<Derived>::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType; - /** \internal the return type of identity */ - typedef CwiseNullaryOp<internal::scalar_identity_op<Scalar>,PlainObject> IdentityReturnType; - /** \internal the return type of unit vectors */ - typedef Block<const CwiseNullaryOp<internal::scalar_identity_op<Scalar>, SquareMatrixType>, - internal::traits<Derived>::RowsAtCompileTime, - internal::traits<Derived>::ColsAtCompileTime> BasisReturnType; -#endif // not EIGEN_PARSED_BY_DOXYGEN - -#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase -#define EIGEN_DOC_UNARY_ADDONS(X,Y) -# include "../plugins/CommonCwiseBinaryOps.h" -# include "../plugins/MatrixCwiseUnaryOps.h" -# include "../plugins/MatrixCwiseBinaryOps.h" -# ifdef EIGEN_MATRIXBASE_PLUGIN -# include EIGEN_MATRIXBASE_PLUGIN -# endif -#undef EIGEN_CURRENT_STORAGE_BASE_CLASS -#undef EIGEN_DOC_UNARY_ADDONS - - /** Special case of the template operator=, in order to prevent the compiler - * from generating a default operator= (issue hit with g++ 4.1) - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator=(const MatrixBase& other); - - // We cannot inherit here via Base::operator= since it is causing - // trouble with MSVC. - - template <typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator=(const DenseBase<OtherDerived>& other); - - template <typename OtherDerived> - EIGEN_DEVICE_FUNC - Derived& operator=(const EigenBase<OtherDerived>& other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - Derived& operator=(const ReturnByValue<OtherDerived>& other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator+=(const MatrixBase<OtherDerived>& other); - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator-=(const MatrixBase<OtherDerived>& other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - const Product<Derived,OtherDerived> - operator*(const MatrixBase<OtherDerived> &other) const; - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - const Product<Derived,OtherDerived,LazyProduct> - lazyProduct(const MatrixBase<OtherDerived> &other) const; - - template<typename OtherDerived> - Derived& operator*=(const EigenBase<OtherDerived>& other); - - template<typename OtherDerived> - void applyOnTheLeft(const EigenBase<OtherDerived>& other); - - template<typename OtherDerived> - void applyOnTheRight(const EigenBase<OtherDerived>& other); - - template<typename DiagonalDerived> - EIGEN_DEVICE_FUNC - const Product<Derived, DiagonalDerived, LazyProduct> - operator*(const DiagonalBase<DiagonalDerived> &diagonal) const; - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType - dot(const MatrixBase<OtherDerived>& other) const; - - EIGEN_DEVICE_FUNC RealScalar squaredNorm() const; - EIGEN_DEVICE_FUNC RealScalar norm() const; - RealScalar stableNorm() const; - RealScalar blueNorm() const; - RealScalar hypotNorm() const; - EIGEN_DEVICE_FUNC const PlainObject normalized() const; - EIGEN_DEVICE_FUNC const PlainObject stableNormalized() const; - EIGEN_DEVICE_FUNC void normalize(); - EIGEN_DEVICE_FUNC void stableNormalize(); - - EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const; - EIGEN_DEVICE_FUNC void adjointInPlace(); - - typedef Diagonal<Derived> DiagonalReturnType; - EIGEN_DEVICE_FUNC - DiagonalReturnType diagonal(); - - typedef typename internal::add_const<Diagonal<const Derived> >::type ConstDiagonalReturnType; - EIGEN_DEVICE_FUNC - ConstDiagonalReturnType diagonal() const; - - template<int Index> struct DiagonalIndexReturnType { typedef Diagonal<Derived,Index> Type; }; - template<int Index> struct ConstDiagonalIndexReturnType { typedef const Diagonal<const Derived,Index> Type; }; - - template<int Index> - EIGEN_DEVICE_FUNC - typename DiagonalIndexReturnType<Index>::Type diagonal(); - - template<int Index> - EIGEN_DEVICE_FUNC - typename ConstDiagonalIndexReturnType<Index>::Type diagonal() const; - - typedef Diagonal<Derived,DynamicIndex> DiagonalDynamicIndexReturnType; - typedef typename internal::add_const<Diagonal<const Derived,DynamicIndex> >::type ConstDiagonalDynamicIndexReturnType; - - EIGEN_DEVICE_FUNC - DiagonalDynamicIndexReturnType diagonal(Index index); - EIGEN_DEVICE_FUNC - ConstDiagonalDynamicIndexReturnType diagonal(Index index) const; - - template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; }; - template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; }; - - template<unsigned int Mode> - EIGEN_DEVICE_FUNC - typename TriangularViewReturnType<Mode>::Type triangularView(); - template<unsigned int Mode> - EIGEN_DEVICE_FUNC - typename ConstTriangularViewReturnType<Mode>::Type triangularView() const; - - template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; }; - template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; }; - - template<unsigned int UpLo> - EIGEN_DEVICE_FUNC - typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView(); - template<unsigned int UpLo> - EIGEN_DEVICE_FUNC - typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const; - - const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0), - const typename NumTraits<Scalar>::Real& m_epsilon = NumTraits<Scalar>::dummy_precision()) const; - EIGEN_DEVICE_FUNC static const IdentityReturnType Identity(); - EIGEN_DEVICE_FUNC static const IdentityReturnType Identity(Index rows, Index cols); - EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index size, Index i); - EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index i); - EIGEN_DEVICE_FUNC static const BasisReturnType UnitX(); - EIGEN_DEVICE_FUNC static const BasisReturnType UnitY(); - EIGEN_DEVICE_FUNC static const BasisReturnType UnitZ(); - EIGEN_DEVICE_FUNC static const BasisReturnType UnitW(); - - EIGEN_DEVICE_FUNC - const DiagonalWrapper<const Derived> asDiagonal() const; - const PermutationWrapper<const Derived> asPermutation() const; - - EIGEN_DEVICE_FUNC - Derived& setIdentity(); - EIGEN_DEVICE_FUNC - Derived& setIdentity(Index rows, Index cols); - EIGEN_DEVICE_FUNC Derived& setUnit(Index i); - EIGEN_DEVICE_FUNC Derived& setUnit(Index newSize, Index i); - - bool isIdentity(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - bool isDiagonal(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - - bool isUpperTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - bool isLowerTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - - template<typename OtherDerived> - bool isOrthogonal(const MatrixBase<OtherDerived>& other, - const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - bool isUnitary(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - - /** \returns true if each coefficients of \c *this and \a other are all exactly equal. - * \warning When using floating point scalar values you probably should rather use a - * fuzzy comparison such as isApprox() - * \sa isApprox(), operator!= */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC inline bool operator==(const MatrixBase<OtherDerived>& other) const - { return cwiseEqual(other).all(); } - - /** \returns true if at least one pair of coefficients of \c *this and \a other are not exactly equal to each other. - * \warning When using floating point scalar values you probably should rather use a - * fuzzy comparison such as isApprox() - * \sa isApprox(), operator== */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC inline bool operator!=(const MatrixBase<OtherDerived>& other) const - { return cwiseNotEqual(other).any(); } - - NoAlias<Derived,Eigen::MatrixBase > EIGEN_DEVICE_FUNC noalias(); - - // TODO forceAlignedAccess is temporarily disabled - // Need to find a nicer workaround. - inline const Derived& forceAlignedAccess() const { return derived(); } - inline Derived& forceAlignedAccess() { return derived(); } - template<bool Enable> inline const Derived& forceAlignedAccessIf() const { return derived(); } - template<bool Enable> inline Derived& forceAlignedAccessIf() { return derived(); } - - EIGEN_DEVICE_FUNC Scalar trace() const; - - template<int p> EIGEN_DEVICE_FUNC RealScalar lpNorm() const; - - EIGEN_DEVICE_FUNC MatrixBase<Derived>& matrix() { return *this; } - EIGEN_DEVICE_FUNC const MatrixBase<Derived>& matrix() const { return *this; } - - /** \returns an \link Eigen::ArrayBase Array \endlink expression of this matrix - * \sa ArrayBase::matrix() */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ArrayWrapper<Derived> array() { return ArrayWrapper<Derived>(derived()); } - /** \returns a const \link Eigen::ArrayBase Array \endlink expression of this matrix - * \sa ArrayBase::matrix() */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArrayWrapper<const Derived> array() const { return ArrayWrapper<const Derived>(derived()); } - -/////////// LU module /////////// - - inline const FullPivLU<PlainObject> fullPivLu() const; - inline const PartialPivLU<PlainObject> partialPivLu() const; - - inline const PartialPivLU<PlainObject> lu() const; - - EIGEN_DEVICE_FUNC - inline const Inverse<Derived> inverse() const; - - template<typename ResultType> - inline void computeInverseAndDetWithCheck( - ResultType& inverse, - typename ResultType::Scalar& determinant, - bool& invertible, - const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision() - ) const; - - template<typename ResultType> - inline void computeInverseWithCheck( - ResultType& inverse, - bool& invertible, - const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision() - ) const; - - EIGEN_DEVICE_FUNC - Scalar determinant() const; - -/////////// Cholesky module /////////// - - inline const LLT<PlainObject> llt() const; - inline const LDLT<PlainObject> ldlt() const; - -/////////// QR module /////////// - - inline const HouseholderQR<PlainObject> householderQr() const; - inline const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const; - inline const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const; - inline const CompleteOrthogonalDecomposition<PlainObject> completeOrthogonalDecomposition() const; - -/////////// Eigenvalues module /////////// - - inline EigenvaluesReturnType eigenvalues() const; - inline RealScalar operatorNorm() const; - -/////////// SVD module /////////// - - inline JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const; - inline BDCSVD<PlainObject> bdcSvd(unsigned int computationOptions = 0) const; - -/////////// Geometry module /////////// - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /// \internal helper struct to form the return type of the cross product - template<typename OtherDerived> struct cross_product_return_type { - typedef typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar; - typedef Matrix<Scalar,MatrixBase::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> type; - }; - #endif // EIGEN_PARSED_BY_DOXYGEN - template<typename OtherDerived> - EIGEN_DEVICE_FUNC -#ifndef EIGEN_PARSED_BY_DOXYGEN - inline typename cross_product_return_type<OtherDerived>::type -#else - inline PlainObject -#endif - cross(const MatrixBase<OtherDerived>& other) const; - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - inline PlainObject cross3(const MatrixBase<OtherDerived>& other) const; - - EIGEN_DEVICE_FUNC - inline PlainObject unitOrthogonal(void) const; - - EIGEN_DEVICE_FUNC - inline Matrix<Scalar,3,1> eulerAngles(Index a0, Index a1, Index a2) const; - - // put this as separate enum value to work around possible GCC 4.3 bug (?) - enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1&&RowsAtCompileTime==1 ? ((internal::traits<Derived>::Flags&RowMajorBit)==RowMajorBit ? Horizontal : Vertical) - : ColsAtCompileTime==1 ? Vertical : Horizontal }; - typedef Homogeneous<Derived, HomogeneousReturnTypeDirection> HomogeneousReturnType; - EIGEN_DEVICE_FUNC - inline HomogeneousReturnType homogeneous() const; - - enum { - SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1 - }; - typedef Block<const Derived, - internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1, - internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne; - typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(ConstStartMinusOne,Scalar,quotient) HNormalizedReturnType; - EIGEN_DEVICE_FUNC - inline const HNormalizedReturnType hnormalized() const; - -////////// Householder module /////////// - - EIGEN_DEVICE_FUNC - void makeHouseholderInPlace(Scalar& tau, RealScalar& beta); - template<typename EssentialPart> - EIGEN_DEVICE_FUNC - void makeHouseholder(EssentialPart& essential, - Scalar& tau, RealScalar& beta) const; - template<typename EssentialPart> - EIGEN_DEVICE_FUNC - void applyHouseholderOnTheLeft(const EssentialPart& essential, - const Scalar& tau, - Scalar* workspace); - template<typename EssentialPart> - EIGEN_DEVICE_FUNC - void applyHouseholderOnTheRight(const EssentialPart& essential, - const Scalar& tau, - Scalar* workspace); - -///////// Jacobi module ///////// - - template<typename OtherScalar> - EIGEN_DEVICE_FUNC - void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j); - template<typename OtherScalar> - EIGEN_DEVICE_FUNC - void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j); - -///////// SparseCore module ///////// - - template<typename OtherDerived> - EIGEN_STRONG_INLINE const typename SparseMatrixBase<OtherDerived>::template CwiseProductDenseReturnType<Derived>::Type - cwiseProduct(const SparseMatrixBase<OtherDerived> &other) const - { - return other.cwiseProduct(derived()); - } - -///////// MatrixFunctions module ///////// - - typedef typename internal::stem_function<Scalar>::type StemFunction; -#define EIGEN_MATRIX_FUNCTION(ReturnType, Name, Description) \ - /** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \ - const ReturnType<Derived> Name() const; -#define EIGEN_MATRIX_FUNCTION_1(ReturnType, Name, Description, Argument) \ - /** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \ - const ReturnType<Derived> Name(Argument) const; - - EIGEN_MATRIX_FUNCTION(MatrixExponentialReturnValue, exp, exponential) - /** \brief Helper function for the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>.*/ - const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const; - EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cosh, hyperbolic cosine) - EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sinh, hyperbolic sine) -#if EIGEN_HAS_CXX11_MATH - EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, atanh, inverse hyperbolic cosine) - EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, acosh, inverse hyperbolic cosine) - EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, asinh, inverse hyperbolic sine) -#endif - EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cos, cosine) - EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sin, sine) - EIGEN_MATRIX_FUNCTION(MatrixSquareRootReturnValue, sqrt, square root) - EIGEN_MATRIX_FUNCTION(MatrixLogarithmReturnValue, log, logarithm) - EIGEN_MATRIX_FUNCTION_1(MatrixPowerReturnValue, pow, power to \c p, const RealScalar& p) - EIGEN_MATRIX_FUNCTION_1(MatrixComplexPowerReturnValue, pow, power to \c p, const std::complex<RealScalar>& p) - - protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(MatrixBase) - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MatrixBase) - - private: - EIGEN_DEVICE_FUNC explicit MatrixBase(int); - EIGEN_DEVICE_FUNC MatrixBase(int,int); - template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit MatrixBase(const MatrixBase<OtherDerived>&); - protected: - // mixing arrays and matrices is not legal - template<typename OtherDerived> Derived& operator+=(const ArrayBase<OtherDerived>& ) - {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;} - // mixing arrays and matrices is not legal - template<typename OtherDerived> Derived& operator-=(const ArrayBase<OtherDerived>& ) - {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;} -}; - - -/*************************************************************************** -* Implementation of matrix base methods -***************************************************************************/ - -/** replaces \c *this by \c *this * \a other. - * - * \returns a reference to \c *this - * - * Example: \include MatrixBase_applyOnTheRight.cpp - * Output: \verbinclude MatrixBase_applyOnTheRight.out - */ -template<typename Derived> -template<typename OtherDerived> -inline Derived& -MatrixBase<Derived>::operator*=(const EigenBase<OtherDerived> &other) -{ - other.derived().applyThisOnTheRight(derived()); - return derived(); -} - -/** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=(). - * - * Example: \include MatrixBase_applyOnTheRight.cpp - * Output: \verbinclude MatrixBase_applyOnTheRight.out - */ -template<typename Derived> -template<typename OtherDerived> -inline void MatrixBase<Derived>::applyOnTheRight(const EigenBase<OtherDerived> &other) -{ - other.derived().applyThisOnTheRight(derived()); -} - -/** replaces \c *this by \a other * \c *this. - * - * Example: \include MatrixBase_applyOnTheLeft.cpp - * Output: \verbinclude MatrixBase_applyOnTheLeft.out - */ -template<typename Derived> -template<typename OtherDerived> -inline void MatrixBase<Derived>::applyOnTheLeft(const EigenBase<OtherDerived> &other) -{ - other.derived().applyThisOnTheLeft(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_MATRIXBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/NestByValue.h b/external/eigen/include/eigen3/Eigen/src/Core/NestByValue.h deleted file mode 100644 index 239bbba6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/NestByValue.h +++ /dev/null @@ -1,85 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_NESTBYVALUE_H -#define EIGEN_NESTBYVALUE_H - -namespace Eigen { - -namespace internal { -template<typename ExpressionType> -struct traits<NestByValue<ExpressionType> > : public traits<ExpressionType> -{ - enum { - Flags = traits<ExpressionType>::Flags & ~NestByRefBit - }; -}; -} - -/** \class NestByValue - * \ingroup Core_Module - * - * \brief Expression which must be nested by value - * - * \tparam ExpressionType the type of the object of which we are requiring nesting-by-value - * - * This class is the return type of MatrixBase::nestByValue() - * and most of the time this is the only way it is used. - * - * \sa MatrixBase::nestByValue() - */ -template<typename ExpressionType> class NestByValue - : public internal::dense_xpr_base< NestByValue<ExpressionType> >::type -{ - public: - - typedef typename internal::dense_xpr_base<NestByValue>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue) - - EIGEN_DEVICE_FUNC explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {} - - EIGEN_DEVICE_FUNC inline Index rows() const { return m_expression.rows(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_expression.cols(); } - - EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; } - - EIGEN_DEVICE_FUNC const ExpressionType& nestedExpression() const { return m_expression; } - - protected: - const ExpressionType m_expression; -}; - -/** \returns an expression of the temporary version of *this. - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline const NestByValue<Derived> -DenseBase<Derived>::nestByValue() const -{ - return NestByValue<Derived>(derived()); -} - -namespace internal { - -// Evaluator of Solve -> eval into a temporary -template<typename ArgType> -struct evaluator<NestByValue<ArgType> > - : public evaluator<ArgType> -{ - typedef evaluator<ArgType> Base; - - EIGEN_DEVICE_FUNC explicit evaluator(const NestByValue<ArgType>& xpr) - : Base(xpr.nestedExpression()) - {} -}; -} - -} // end namespace Eigen - -#endif // EIGEN_NESTBYVALUE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/NoAlias.h b/external/eigen/include/eigen3/Eigen/src/Core/NoAlias.h deleted file mode 100644 index 570283d9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/NoAlias.h +++ /dev/null @@ -1,109 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_NOALIAS_H -#define EIGEN_NOALIAS_H - -namespace Eigen { - -/** \class NoAlias - * \ingroup Core_Module - * - * \brief Pseudo expression providing an operator = assuming no aliasing - * - * \tparam ExpressionType the type of the object on which to do the lazy assignment - * - * This class represents an expression with special assignment operators - * assuming no aliasing between the target expression and the source expression. - * More precisely it alloas to bypass the EvalBeforeAssignBit flag of the source expression. - * It is the return type of MatrixBase::noalias() - * and most of the time this is the only way it is used. - * - * \sa MatrixBase::noalias() - */ -template<typename ExpressionType, template <typename> class StorageBase> -class NoAlias -{ - public: - typedef typename ExpressionType::Scalar Scalar; - - EIGEN_DEVICE_FUNC - explicit NoAlias(ExpressionType& expression) : m_expression(expression) {} - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other) - { - call_assignment_no_alias(m_expression, other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>()); - return m_expression; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other) - { - call_assignment_no_alias(m_expression, other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); - return m_expression; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other) - { - call_assignment_no_alias(m_expression, other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>()); - return m_expression; - } - - EIGEN_DEVICE_FUNC - ExpressionType& expression() const - { - return m_expression; - } - - protected: - ExpressionType& m_expression; -}; - -/** \returns a pseudo expression of \c *this with an operator= assuming - * no aliasing between \c *this and the source expression. - * - * More precisely, noalias() allows to bypass the EvalBeforeAssignBit flag. - * Currently, even though several expressions may alias, only product - * expressions have this flag. Therefore, noalias() is only useful when - * the source expression contains a matrix product. - * - * Here are some examples where noalias is useful: - * \code - * D.noalias() = A * B; - * D.noalias() += A.transpose() * B; - * D.noalias() -= 2 * A * B.adjoint(); - * \endcode - * - * On the other hand the following example will lead to a \b wrong result: - * \code - * A.noalias() = A * B; - * \endcode - * because the result matrix A is also an operand of the matrix product. Therefore, - * there is no alternative than evaluating A * B in a temporary, that is the default - * behavior when you write: - * \code - * A = A * B; - * \endcode - * - * \sa class NoAlias - */ -template<typename Derived> -NoAlias<Derived,MatrixBase> EIGEN_DEVICE_FUNC MatrixBase<Derived>::noalias() -{ - return NoAlias<Derived, Eigen::MatrixBase >(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_NOALIAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/NumTraits.h b/external/eigen/include/eigen3/Eigen/src/Core/NumTraits.h deleted file mode 100644 index 12a7cde6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/NumTraits.h +++ /dev/null @@ -1,289 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_NUMTRAITS_H -#define EIGEN_NUMTRAITS_H - -namespace Eigen { - -namespace internal { - -// default implementation of digits10(), based on numeric_limits if specialized, -// 0 for integer types, and log10(epsilon()) otherwise. -template< typename T, - bool use_numeric_limits = std::numeric_limits<T>::is_specialized, - bool is_integer = NumTraits<T>::IsInteger> -struct default_digits10_impl -{ - EIGEN_DEVICE_FUNC - static int run() { return std::numeric_limits<T>::digits10; } -}; - -template<typename T> -struct default_digits10_impl<T,false,false> // Floating point -{ - EIGEN_DEVICE_FUNC - static int run() { - using std::log10; - using std::ceil; - typedef typename NumTraits<T>::Real Real; - return int(ceil(-log10(NumTraits<Real>::epsilon()))); - } -}; - -template<typename T> -struct default_digits10_impl<T,false,true> // Integer -{ - EIGEN_DEVICE_FUNC - static int run() { return 0; } -}; - - -// default implementation of digits(), based on numeric_limits if specialized, -// 0 for integer types, and log2(epsilon()) otherwise. -template< typename T, - bool use_numeric_limits = std::numeric_limits<T>::is_specialized, - bool is_integer = NumTraits<T>::IsInteger> -struct default_digits_impl -{ - EIGEN_DEVICE_FUNC - static int run() { return std::numeric_limits<T>::digits; } -}; - -template<typename T> -struct default_digits_impl<T,false,false> // Floating point -{ - EIGEN_DEVICE_FUNC - static int run() { - using std::log; - using std::ceil; - typedef typename NumTraits<T>::Real Real; - return int(ceil(-log(NumTraits<Real>::epsilon())/log(static_cast<Real>(2)))); - } -}; - -template<typename T> -struct default_digits_impl<T,false,true> // Integer -{ - EIGEN_DEVICE_FUNC - static int run() { return 0; } -}; - -} // end namespace internal - -/** \class NumTraits - * \ingroup Core_Module - * - * \brief Holds information about the various numeric (i.e. scalar) types allowed by Eigen. - * - * \tparam T the numeric type at hand - * - * This class stores enums, typedefs and static methods giving information about a numeric type. - * - * The provided data consists of: - * \li A typedef \c Real, giving the "real part" type of \a T. If \a T is already real, - * then \c Real is just a typedef to \a T. If \a T is \c std::complex<U> then \c Real - * is a typedef to \a U. - * \li A typedef \c NonInteger, giving the type that should be used for operations producing non-integral values, - * such as quotients, square roots, etc. If \a T is a floating-point type, then this typedef just gives - * \a T again. Note however that many Eigen functions such as internal::sqrt simply refuse to - * take integers. Outside of a few cases, Eigen doesn't do automatic type promotion. Thus, this typedef is - * only intended as a helper for code that needs to explicitly promote types. - * \li A typedef \c Literal giving the type to use for numeric literals such as "2" or "0.5". For instance, for \c std::complex<U>, Literal is defined as \c U. - * Of course, this type must be fully compatible with \a T. In doubt, just use \a T here. - * \li A typedef \a Nested giving the type to use to nest a value inside of the expression tree. If you don't know what - * this means, just use \a T here. - * \li An enum value \a IsComplex. It is equal to 1 if \a T is a \c std::complex - * type, and to 0 otherwise. - * \li An enum value \a IsInteger. It is equal to \c 1 if \a T is an integer type such as \c int, - * and to \c 0 otherwise. - * \li Enum values ReadCost, AddCost and MulCost representing a rough estimate of the number of CPU cycles needed - * to by move / add / mul instructions respectively, assuming the data is already stored in CPU registers. - * Stay vague here. No need to do architecture-specific stuff. If you don't know what this means, just use \c Eigen::HugeCost. - * \li An enum value \a IsSigned. It is equal to \c 1 if \a T is a signed type and to 0 if \a T is unsigned. - * \li An enum value \a RequireInitialization. It is equal to \c 1 if the constructor of the numeric type \a T must - * be called, and to 0 if it is safe not to call it. Default is 0 if \a T is an arithmetic type, and 1 otherwise. - * \li An epsilon() function which, unlike <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon">std::numeric_limits::epsilon()</a>, - * it returns a \a Real instead of a \a T. - * \li A dummy_precision() function returning a weak epsilon value. It is mainly used as a default - * value by the fuzzy comparison operators. - * \li highest() and lowest() functions returning the highest and lowest possible values respectively. - * \li digits10() function returning the number of decimal digits that can be represented without change. This is - * the analogue of <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/digits10">std::numeric_limits<T>::digits10</a> - * which is used as the default implementation if specialized. - */ - -template<typename T> struct GenericNumTraits -{ - enum { - IsInteger = std::numeric_limits<T>::is_integer, - IsSigned = std::numeric_limits<T>::is_signed, - IsComplex = 0, - RequireInitialization = internal::is_arithmetic<T>::value ? 0 : 1, - ReadCost = 1, - AddCost = 1, - MulCost = 1 - }; - - typedef T Real; - typedef typename internal::conditional< - IsInteger, - typename internal::conditional<sizeof(T)<=2, float, double>::type, - T - >::type NonInteger; - typedef T Nested; - typedef T Literal; - - EIGEN_DEVICE_FUNC - static inline Real epsilon() - { - return numext::numeric_limits<T>::epsilon(); - } - - EIGEN_DEVICE_FUNC - static inline int digits10() - { - return internal::default_digits10_impl<T>::run(); - } - - EIGEN_DEVICE_FUNC - static inline int digits() - { - return internal::default_digits_impl<T>::run(); - } - - EIGEN_DEVICE_FUNC - static inline Real dummy_precision() - { - // make sure to override this for floating-point types - return Real(0); - } - - - EIGEN_DEVICE_FUNC - static inline T highest() { - return (numext::numeric_limits<T>::max)(); - } - - EIGEN_DEVICE_FUNC - static inline T lowest() { - return IsInteger ? (numext::numeric_limits<T>::min)() - : static_cast<T>(-(numext::numeric_limits<T>::max)()); - } - - EIGEN_DEVICE_FUNC - static inline T infinity() { - return numext::numeric_limits<T>::infinity(); - } - - EIGEN_DEVICE_FUNC - static inline T quiet_NaN() { - return numext::numeric_limits<T>::quiet_NaN(); - } -}; - -template<typename T> struct NumTraits : GenericNumTraits<T> -{}; - -template<> struct NumTraits<float> - : GenericNumTraits<float> -{ - EIGEN_DEVICE_FUNC - static inline float dummy_precision() { return 1e-5f; } -}; - -template<> struct NumTraits<double> : GenericNumTraits<double> -{ - EIGEN_DEVICE_FUNC - static inline double dummy_precision() { return 1e-12; } -}; - -template<> struct NumTraits<long double> - : GenericNumTraits<long double> -{ - static inline long double dummy_precision() { return 1e-15l; } -}; - -template<typename _Real> struct NumTraits<std::complex<_Real> > - : GenericNumTraits<std::complex<_Real> > -{ - typedef _Real Real; - typedef typename NumTraits<_Real>::Literal Literal; - enum { - IsComplex = 1, - RequireInitialization = NumTraits<_Real>::RequireInitialization, - ReadCost = 2 * NumTraits<_Real>::ReadCost, - AddCost = 2 * NumTraits<Real>::AddCost, - MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost - }; - - EIGEN_DEVICE_FUNC - static inline Real epsilon() { return NumTraits<Real>::epsilon(); } - EIGEN_DEVICE_FUNC - static inline Real dummy_precision() { return NumTraits<Real>::dummy_precision(); } - EIGEN_DEVICE_FUNC - static inline int digits10() { return NumTraits<Real>::digits10(); } -}; - -template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols> -struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > -{ - typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> ArrayType; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Array<RealScalar, Rows, Cols, Options, MaxRows, MaxCols> Real; - typedef typename NumTraits<Scalar>::NonInteger NonIntegerScalar; - typedef Array<NonIntegerScalar, Rows, Cols, Options, MaxRows, MaxCols> NonInteger; - typedef ArrayType & Nested; - typedef typename NumTraits<Scalar>::Literal Literal; - - enum { - IsComplex = NumTraits<Scalar>::IsComplex, - IsInteger = NumTraits<Scalar>::IsInteger, - IsSigned = NumTraits<Scalar>::IsSigned, - RequireInitialization = 1, - ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost, - AddCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost, - MulCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost - }; - - EIGEN_DEVICE_FUNC - static inline RealScalar epsilon() { return NumTraits<RealScalar>::epsilon(); } - EIGEN_DEVICE_FUNC - static inline RealScalar dummy_precision() { return NumTraits<RealScalar>::dummy_precision(); } - - static inline int digits10() { return NumTraits<Scalar>::digits10(); } -}; - -template<> struct NumTraits<std::string> - : GenericNumTraits<std::string> -{ - enum { - RequireInitialization = 1, - ReadCost = HugeCost, - AddCost = HugeCost, - MulCost = HugeCost - }; - - static inline int digits10() { return 0; } - -private: - static inline std::string epsilon(); - static inline std::string dummy_precision(); - static inline std::string lowest(); - static inline std::string highest(); - static inline std::string infinity(); - static inline std::string quiet_NaN(); -}; - -// Empty specialization for void to allow template specialization based on NumTraits<T>::Real with T==void and SFINAE. -template<> struct NumTraits<void> {}; - -} // end namespace Eigen - -#endif // EIGEN_NUMTRAITS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/PartialReduxEvaluator.h b/external/eigen/include/eigen3/Eigen/src/Core/PartialReduxEvaluator.h deleted file mode 100644 index 0be69425..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/PartialReduxEvaluator.h +++ /dev/null @@ -1,232 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011-2018 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PARTIALREDUX_H -#define EIGEN_PARTIALREDUX_H - -namespace Eigen { - -namespace internal { - - -/*************************************************************************** -* -* This file provides evaluators for partial reductions. -* There are two modes: -* -* - scalar path: simply calls the respective function on the column or row. -* -> nothing special here, all the tricky part is handled by the return -* types of VectorwiseOp's members. They embed the functor calling the -* respective DenseBase's member function. -* -* - vectorized path: implements a packet-wise reductions followed by -* some (optional) processing of the outcome, e.g., division by n for mean. -* -* For the vectorized path let's observe that the packet-size and outer-unrolling -* are both decided by the assignement logic. So all we have to do is to decide -* on the inner unrolling. -* -* For the unrolling, we can reuse "internal::redux_vec_unroller" from Redux.h, -* but be need to be careful to specify correct increment. -* -***************************************************************************/ - - -/* logic deciding a strategy for unrolling of vectorized paths */ -template<typename Func, typename Evaluator> -struct packetwise_redux_traits -{ - enum { - OuterSize = int(Evaluator::IsRowMajor) ? Evaluator::RowsAtCompileTime : Evaluator::ColsAtCompileTime, - Cost = OuterSize == Dynamic ? HugeCost - : OuterSize * Evaluator::CoeffReadCost + (OuterSize-1) * functor_traits<Func>::Cost, - Unrolling = Cost <= EIGEN_UNROLLING_LIMIT ? CompleteUnrolling : NoUnrolling - }; - -}; - -/* Value to be returned when size==0 , by default let's return 0 */ -template<typename PacketType,typename Func> -EIGEN_DEVICE_FUNC -PacketType packetwise_redux_empty_value(const Func& ) { return pset1<PacketType>(0); } - -/* For products the default is 1 */ -template<typename PacketType,typename Scalar> -EIGEN_DEVICE_FUNC -PacketType packetwise_redux_empty_value(const scalar_product_op<Scalar,Scalar>& ) { return pset1<PacketType>(1); } - -/* Perform the actual reduction */ -template<typename Func, typename Evaluator, - int Unrolling = packetwise_redux_traits<Func, Evaluator>::Unrolling -> -struct packetwise_redux_impl; - -/* Perform the actual reduction with unrolling */ -template<typename Func, typename Evaluator> -struct packetwise_redux_impl<Func, Evaluator, CompleteUnrolling> -{ - typedef redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime> Base; - typedef typename Evaluator::Scalar Scalar; - - template<typename PacketType> - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE - PacketType run(const Evaluator &eval, const Func& func, Index /*size*/) - { - return redux_vec_unroller<Func, Evaluator, 0, packetwise_redux_traits<Func, Evaluator>::OuterSize>::template run<PacketType>(eval,func); - } -}; - -/* Add a specialization of redux_vec_unroller for size==0 at compiletime. - * This specialization is not required for general reductions, which is - * why it is defined here. - */ -template<typename Func, typename Evaluator, int Start> -struct redux_vec_unroller<Func, Evaluator, Start, 0> -{ - template<typename PacketType> - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE PacketType run(const Evaluator &, const Func& f) - { - return packetwise_redux_empty_value<PacketType>(f); - } -}; - -/* Perform the actual reduction for dynamic sizes */ -template<typename Func, typename Evaluator> -struct packetwise_redux_impl<Func, Evaluator, NoUnrolling> -{ - typedef typename Evaluator::Scalar Scalar; - typedef typename redux_traits<Func, Evaluator>::PacketType PacketScalar; - - template<typename PacketType> - EIGEN_DEVICE_FUNC - static PacketType run(const Evaluator &eval, const Func& func, Index size) - { - if(size==0) - return packetwise_redux_empty_value<PacketType>(func); - - const Index size4 = (size-1)&(~3); - PacketType p = eval.template packetByOuterInner<Unaligned,PacketType>(0,0); - Index i = 1; - // This loop is optimized for instruction pipelining: - // - each iteration generates two independent instructions - // - thanks to branch prediction and out-of-order execution we have independent instructions across loops - for(; i<size4; i+=4) - p = func.packetOp(p, - func.packetOp( - func.packetOp(eval.template packetByOuterInner<Unaligned,PacketType>(i+0,0),eval.template packetByOuterInner<Unaligned,PacketType>(i+1,0)), - func.packetOp(eval.template packetByOuterInner<Unaligned,PacketType>(i+2,0),eval.template packetByOuterInner<Unaligned,PacketType>(i+3,0)))); - for(; i<size; ++i) - p = func.packetOp(p, eval.template packetByOuterInner<Unaligned,PacketType>(i,0)); - return p; - } -}; - -template< typename ArgType, typename MemberOp, int Direction> -struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> > - : evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> > -{ - typedef PartialReduxExpr<ArgType, MemberOp, Direction> XprType; - typedef typename internal::nested_eval<ArgType,1>::type ArgTypeNested; - typedef typename internal::add_const_on_value_type<ArgTypeNested>::type ConstArgTypeNested; - typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned; - typedef typename ArgType::Scalar InputScalar; - typedef typename XprType::Scalar Scalar; - enum { - TraversalSize = Direction==int(Vertical) ? int(ArgType::RowsAtCompileTime) : int(ArgType::ColsAtCompileTime) - }; - typedef typename MemberOp::template Cost<int(TraversalSize)> CostOpType; - enum { - CoeffReadCost = TraversalSize==Dynamic ? HugeCost - : TraversalSize==0 ? 1 - : TraversalSize * evaluator<ArgType>::CoeffReadCost + int(CostOpType::value), - - _ArgFlags = evaluator<ArgType>::Flags, - - _Vectorizable = bool(int(_ArgFlags)&PacketAccessBit) - && bool(MemberOp::Vectorizable) - && (Direction==int(Vertical) ? bool(_ArgFlags&RowMajorBit) : (_ArgFlags&RowMajorBit)==0) - && (TraversalSize!=0), - - Flags = (traits<XprType>::Flags&RowMajorBit) - | (evaluator<ArgType>::Flags&(HereditaryBits&(~RowMajorBit))) - | (_Vectorizable ? PacketAccessBit : 0) - | LinearAccessBit, - - Alignment = 0 // FIXME this will need to be improved once PartialReduxExpr is vectorized - }; - - EIGEN_DEVICE_FUNC explicit evaluator(const XprType xpr) - : m_arg(xpr.nestedExpression()), m_functor(xpr.functor()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(TraversalSize==Dynamic ? HugeCost : (TraversalSize==0 ? 1 : int(CostOpType::value))); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Scalar coeff(Index i, Index j) const - { - return coeff(Direction==Vertical ? j : i); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Scalar coeff(Index index) const - { - return m_functor(m_arg.template subVector<DirectionType(Direction)>(index)); - } - - template<int LoadMode,typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketType packet(Index i, Index j) const - { - return packet<LoadMode,PacketType>(Direction==Vertical ? j : i); - } - - template<int LoadMode,typename PacketType> - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC - PacketType packet(Index idx) const - { - enum { PacketSize = internal::unpacket_traits<PacketType>::size }; - typedef Block<const ArgTypeNestedCleaned, - Direction==Vertical ? int(ArgType::RowsAtCompileTime) : int(PacketSize), - Direction==Vertical ? int(PacketSize) : int(ArgType::ColsAtCompileTime), - true /* InnerPanel */> PanelType; - - PanelType panel(m_arg, - Direction==Vertical ? 0 : idx, - Direction==Vertical ? idx : 0, - Direction==Vertical ? m_arg.rows() : Index(PacketSize), - Direction==Vertical ? Index(PacketSize) : m_arg.cols()); - - // FIXME - // See bug 1612, currently if PacketSize==1 (i.e. complex<double> with 128bits registers) then the storage-order of panel get reversed - // and methods like packetByOuterInner do not make sense anymore in this context. - // So let's just by pass "vectorization" in this case: - if(PacketSize==1) - return internal::pset1<PacketType>(coeff(idx)); - - typedef typename internal::redux_evaluator<PanelType> PanelEvaluator; - PanelEvaluator panel_eval(panel); - typedef typename MemberOp::BinaryOp BinaryOp; - PacketType p = internal::packetwise_redux_impl<BinaryOp,PanelEvaluator>::template run<PacketType>(panel_eval,m_functor.binaryFunc(),m_arg.outerSize()); - return p; - } - -protected: - ConstArgTypeNested m_arg; - const MemberOp m_functor; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PARTIALREDUX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/PermutationMatrix.h b/external/eigen/include/eigen3/Eigen/src/Core/PermutationMatrix.h deleted file mode 100644 index 69401bf4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/PermutationMatrix.h +++ /dev/null @@ -1,605 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PERMUTATIONMATRIX_H -#define EIGEN_PERMUTATIONMATRIX_H - -namespace Eigen { - -namespace internal { - -enum PermPermProduct_t {PermPermProduct}; - -} // end namespace internal - -/** \class PermutationBase - * \ingroup Core_Module - * - * \brief Base class for permutations - * - * \tparam Derived the derived class - * - * This class is the base class for all expressions representing a permutation matrix, - * internally stored as a vector of integers. - * The convention followed here is that if \f$ \sigma \f$ is a permutation, the corresponding permutation matrix - * \f$ P_\sigma \f$ is such that if \f$ (e_1,\ldots,e_p) \f$ is the canonical basis, we have: - * \f[ P_\sigma(e_i) = e_{\sigma(i)}. \f] - * This convention ensures that for any two permutations \f$ \sigma, \tau \f$, we have: - * \f[ P_{\sigma\circ\tau} = P_\sigma P_\tau. \f] - * - * Permutation matrices are square and invertible. - * - * Notice that in addition to the member functions and operators listed here, there also are non-member - * operator* to multiply any kind of permutation object with any kind of matrix expression (MatrixBase) - * on either side. - * - * \sa class PermutationMatrix, class PermutationWrapper - */ -template<typename Derived> -class PermutationBase : public EigenBase<Derived> -{ - typedef internal::traits<Derived> Traits; - typedef EigenBase<Derived> Base; - public: - - #ifndef EIGEN_PARSED_BY_DOXYGEN - typedef typename Traits::IndicesType IndicesType; - enum { - Flags = Traits::Flags, - RowsAtCompileTime = Traits::RowsAtCompileTime, - ColsAtCompileTime = Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Traits::MaxColsAtCompileTime - }; - typedef typename Traits::StorageIndex StorageIndex; - typedef Matrix<StorageIndex,RowsAtCompileTime,ColsAtCompileTime,0,MaxRowsAtCompileTime,MaxColsAtCompileTime> - DenseMatrixType; - typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,StorageIndex> - PlainPermutationType; - typedef PlainPermutationType PlainObject; - using Base::derived; - typedef Inverse<Derived> InverseReturnType; - typedef void Scalar; - #endif - - /** Copies the other permutation into *this */ - template<typename OtherDerived> - Derived& operator=(const PermutationBase<OtherDerived>& other) - { - indices() = other.indices(); - return derived(); - } - - /** Assignment from the Transpositions \a tr */ - template<typename OtherDerived> - Derived& operator=(const TranspositionsBase<OtherDerived>& tr) - { - setIdentity(tr.size()); - for(Index k=size()-1; k>=0; --k) - applyTranspositionOnTheRight(k,tr.coeff(k)); - return derived(); - } - - /** \returns the number of rows */ - inline EIGEN_DEVICE_FUNC Index rows() const { return Index(indices().size()); } - - /** \returns the number of columns */ - inline EIGEN_DEVICE_FUNC Index cols() const { return Index(indices().size()); } - - /** \returns the size of a side of the respective square matrix, i.e., the number of indices */ - inline EIGEN_DEVICE_FUNC Index size() const { return Index(indices().size()); } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename DenseDerived> - void evalTo(MatrixBase<DenseDerived>& other) const - { - other.setZero(); - for (Index i=0; i<rows(); ++i) - other.coeffRef(indices().coeff(i),i) = typename DenseDerived::Scalar(1); - } - #endif - - /** \returns a Matrix object initialized from this permutation matrix. Notice that it - * is inefficient to return this Matrix object by value. For efficiency, favor using - * the Matrix constructor taking EigenBase objects. - */ - DenseMatrixType toDenseMatrix() const - { - return derived(); - } - - /** const version of indices(). */ - const IndicesType& indices() const { return derived().indices(); } - /** \returns a reference to the stored array representing the permutation. */ - IndicesType& indices() { return derived().indices(); } - - /** Resizes to given size. - */ - inline void resize(Index newSize) - { - indices().resize(newSize); - } - - /** Sets *this to be the identity permutation matrix */ - void setIdentity() - { - StorageIndex n = StorageIndex(size()); - for(StorageIndex i = 0; i < n; ++i) - indices().coeffRef(i) = i; - } - - /** Sets *this to be the identity permutation matrix of given size. - */ - void setIdentity(Index newSize) - { - resize(newSize); - setIdentity(); - } - - /** Multiplies *this by the transposition \f$(ij)\f$ on the left. - * - * \returns a reference to *this. - * - * \warning This is much slower than applyTranspositionOnTheRight(Index,Index): - * this has linear complexity and requires a lot of branching. - * - * \sa applyTranspositionOnTheRight(Index,Index) - */ - Derived& applyTranspositionOnTheLeft(Index i, Index j) - { - eigen_assert(i>=0 && j>=0 && i<size() && j<size()); - for(Index k = 0; k < size(); ++k) - { - if(indices().coeff(k) == i) indices().coeffRef(k) = StorageIndex(j); - else if(indices().coeff(k) == j) indices().coeffRef(k) = StorageIndex(i); - } - return derived(); - } - - /** Multiplies *this by the transposition \f$(ij)\f$ on the right. - * - * \returns a reference to *this. - * - * This is a fast operation, it only consists in swapping two indices. - * - * \sa applyTranspositionOnTheLeft(Index,Index) - */ - Derived& applyTranspositionOnTheRight(Index i, Index j) - { - eigen_assert(i>=0 && j>=0 && i<size() && j<size()); - std::swap(indices().coeffRef(i), indices().coeffRef(j)); - return derived(); - } - - /** \returns the inverse permutation matrix. - * - * \note \blank \note_try_to_help_rvo - */ - inline InverseReturnType inverse() const - { return InverseReturnType(derived()); } - /** \returns the tranpose permutation matrix. - * - * \note \blank \note_try_to_help_rvo - */ - inline InverseReturnType transpose() const - { return InverseReturnType(derived()); } - - /**** multiplication helpers to hopefully get RVO ****/ - - -#ifndef EIGEN_PARSED_BY_DOXYGEN - protected: - template<typename OtherDerived> - void assignTranspose(const PermutationBase<OtherDerived>& other) - { - for (Index i=0; i<rows();++i) indices().coeffRef(other.indices().coeff(i)) = i; - } - template<typename Lhs,typename Rhs> - void assignProduct(const Lhs& lhs, const Rhs& rhs) - { - eigen_assert(lhs.cols() == rhs.rows()); - for (Index i=0; i<rows();++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i)); - } -#endif - - public: - - /** \returns the product permutation matrix. - * - * \note \blank \note_try_to_help_rvo - */ - template<typename Other> - inline PlainPermutationType operator*(const PermutationBase<Other>& other) const - { return PlainPermutationType(internal::PermPermProduct, derived(), other.derived()); } - - /** \returns the product of a permutation with another inverse permutation. - * - * \note \blank \note_try_to_help_rvo - */ - template<typename Other> - inline PlainPermutationType operator*(const InverseImpl<Other,PermutationStorage>& other) const - { return PlainPermutationType(internal::PermPermProduct, *this, other.eval()); } - - /** \returns the product of an inverse permutation with another permutation. - * - * \note \blank \note_try_to_help_rvo - */ - template<typename Other> friend - inline PlainPermutationType operator*(const InverseImpl<Other, PermutationStorage>& other, const PermutationBase& perm) - { return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); } - - /** \returns the determinant of the permutation matrix, which is either 1 or -1 depending on the parity of the permutation. - * - * This function is O(\c n) procedure allocating a buffer of \c n booleans. - */ - Index determinant() const - { - Index res = 1; - Index n = size(); - Matrix<bool,RowsAtCompileTime,1,0,MaxRowsAtCompileTime> mask(n); - mask.fill(false); - Index r = 0; - while(r < n) - { - // search for the next seed - while(r<n && mask[r]) r++; - if(r>=n) - break; - // we got one, let's follow it until we are back to the seed - Index k0 = r++; - mask.coeffRef(k0) = true; - for(Index k=indices().coeff(k0); k!=k0; k=indices().coeff(k)) - { - mask.coeffRef(k) = true; - res = -res; - } - } - return res; - } - - protected: - -}; - -namespace internal { -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex> -struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> > - : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> > -{ - typedef PermutationStorage StorageKind; - typedef Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType; - typedef _StorageIndex StorageIndex; - typedef void Scalar; -}; -} - -/** \class PermutationMatrix - * \ingroup Core_Module - * - * \brief Permutation matrix - * - * \tparam SizeAtCompileTime the number of rows/cols, or Dynamic - * \tparam MaxSizeAtCompileTime the maximum number of rows/cols, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it. - * \tparam _StorageIndex the integer type of the indices - * - * This class represents a permutation matrix, internally stored as a vector of integers. - * - * \sa class PermutationBase, class PermutationWrapper, class DiagonalMatrix - */ -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex> -class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> > -{ - typedef PermutationBase<PermutationMatrix> Base; - typedef internal::traits<PermutationMatrix> Traits; - public: - - typedef const PermutationMatrix& Nested; - - #ifndef EIGEN_PARSED_BY_DOXYGEN - typedef typename Traits::IndicesType IndicesType; - typedef typename Traits::StorageIndex StorageIndex; - #endif - - inline PermutationMatrix() - {} - - /** Constructs an uninitialized permutation matrix of given size. - */ - explicit inline PermutationMatrix(Index size) : m_indices(size) - { - eigen_internal_assert(size <= NumTraits<StorageIndex>::highest()); - } - - /** Copy constructor. */ - template<typename OtherDerived> - inline PermutationMatrix(const PermutationBase<OtherDerived>& other) - : m_indices(other.indices()) {} - - /** Generic constructor from expression of the indices. The indices - * array has the meaning that the permutations sends each integer i to indices[i]. - * - * \warning It is your responsibility to check that the indices array that you passes actually - * describes a permutation, i.e., each value between 0 and n-1 occurs exactly once, where n is the - * array's size. - */ - template<typename Other> - explicit inline PermutationMatrix(const MatrixBase<Other>& indices) : m_indices(indices) - {} - - /** Convert the Transpositions \a tr to a permutation matrix */ - template<typename Other> - explicit PermutationMatrix(const TranspositionsBase<Other>& tr) - : m_indices(tr.size()) - { - *this = tr; - } - - /** Copies the other permutation into *this */ - template<typename Other> - PermutationMatrix& operator=(const PermutationBase<Other>& other) - { - m_indices = other.indices(); - return *this; - } - - /** Assignment from the Transpositions \a tr */ - template<typename Other> - PermutationMatrix& operator=(const TranspositionsBase<Other>& tr) - { - return Base::operator=(tr.derived()); - } - - /** const version of indices(). */ - const IndicesType& indices() const { return m_indices; } - /** \returns a reference to the stored array representing the permutation. */ - IndicesType& indices() { return m_indices; } - - - /**** multiplication helpers to hopefully get RVO ****/ - -#ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename Other> - PermutationMatrix(const InverseImpl<Other,PermutationStorage>& other) - : m_indices(other.derived().nestedExpression().size()) - { - eigen_internal_assert(m_indices.size() <= NumTraits<StorageIndex>::highest()); - StorageIndex end = StorageIndex(m_indices.size()); - for (StorageIndex i=0; i<end;++i) - m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i; - } - template<typename Lhs,typename Rhs> - PermutationMatrix(internal::PermPermProduct_t, const Lhs& lhs, const Rhs& rhs) - : m_indices(lhs.indices().size()) - { - Base::assignProduct(lhs,rhs); - } -#endif - - protected: - - IndicesType m_indices; -}; - - -namespace internal { -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess> -struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> > - : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> > -{ - typedef PermutationStorage StorageKind; - typedef Map<const Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, _PacketAccess> IndicesType; - typedef _StorageIndex StorageIndex; - typedef void Scalar; -}; -} - -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess> -class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> - : public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> > -{ - typedef PermutationBase<Map> Base; - typedef internal::traits<Map> Traits; - public: - - #ifndef EIGEN_PARSED_BY_DOXYGEN - typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar StorageIndex; - #endif - - inline Map(const StorageIndex* indicesPtr) - : m_indices(indicesPtr) - {} - - inline Map(const StorageIndex* indicesPtr, Index size) - : m_indices(indicesPtr,size) - {} - - /** Copies the other permutation into *this */ - template<typename Other> - Map& operator=(const PermutationBase<Other>& other) - { return Base::operator=(other.derived()); } - - /** Assignment from the Transpositions \a tr */ - template<typename Other> - Map& operator=(const TranspositionsBase<Other>& tr) - { return Base::operator=(tr.derived()); } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /** This is a special case of the templated operator=. Its purpose is to - * prevent a default operator= from hiding the templated operator=. - */ - Map& operator=(const Map& other) - { - m_indices = other.m_indices; - return *this; - } - #endif - - /** const version of indices(). */ - const IndicesType& indices() const { return m_indices; } - /** \returns a reference to the stored array representing the permutation. */ - IndicesType& indices() { return m_indices; } - - protected: - - IndicesType m_indices; -}; - -template<typename _IndicesType> class TranspositionsWrapper; -namespace internal { -template<typename _IndicesType> -struct traits<PermutationWrapper<_IndicesType> > -{ - typedef PermutationStorage StorageKind; - typedef void Scalar; - typedef typename _IndicesType::Scalar StorageIndex; - typedef _IndicesType IndicesType; - enum { - RowsAtCompileTime = _IndicesType::SizeAtCompileTime, - ColsAtCompileTime = _IndicesType::SizeAtCompileTime, - MaxRowsAtCompileTime = IndicesType::MaxSizeAtCompileTime, - MaxColsAtCompileTime = IndicesType::MaxSizeAtCompileTime, - Flags = 0 - }; -}; -} - -/** \class PermutationWrapper - * \ingroup Core_Module - * - * \brief Class to view a vector of integers as a permutation matrix - * - * \tparam _IndicesType the type of the vector of integer (can be any compatible expression) - * - * This class allows to view any vector expression of integers as a permutation matrix. - * - * \sa class PermutationBase, class PermutationMatrix - */ -template<typename _IndicesType> -class PermutationWrapper : public PermutationBase<PermutationWrapper<_IndicesType> > -{ - typedef PermutationBase<PermutationWrapper> Base; - typedef internal::traits<PermutationWrapper> Traits; - public: - - #ifndef EIGEN_PARSED_BY_DOXYGEN - typedef typename Traits::IndicesType IndicesType; - #endif - - inline PermutationWrapper(const IndicesType& indices) - : m_indices(indices) - {} - - /** const version of indices(). */ - const typename internal::remove_all<typename IndicesType::Nested>::type& - indices() const { return m_indices; } - - protected: - - typename IndicesType::Nested m_indices; -}; - - -/** \returns the matrix with the permutation applied to the columns. - */ -template<typename MatrixDerived, typename PermutationDerived> -EIGEN_DEVICE_FUNC -const Product<MatrixDerived, PermutationDerived, AliasFreeProduct> -operator*(const MatrixBase<MatrixDerived> &matrix, - const PermutationBase<PermutationDerived>& permutation) -{ - return Product<MatrixDerived, PermutationDerived, AliasFreeProduct> - (matrix.derived(), permutation.derived()); -} - -/** \returns the matrix with the permutation applied to the rows. - */ -template<typename PermutationDerived, typename MatrixDerived> -EIGEN_DEVICE_FUNC -const Product<PermutationDerived, MatrixDerived, AliasFreeProduct> -operator*(const PermutationBase<PermutationDerived> &permutation, - const MatrixBase<MatrixDerived>& matrix) -{ - return Product<PermutationDerived, MatrixDerived, AliasFreeProduct> - (permutation.derived(), matrix.derived()); -} - - -template<typename PermutationType> -class InverseImpl<PermutationType, PermutationStorage> - : public EigenBase<Inverse<PermutationType> > -{ - typedef typename PermutationType::PlainPermutationType PlainPermutationType; - typedef internal::traits<PermutationType> PermTraits; - protected: - InverseImpl() {} - public: - typedef Inverse<PermutationType> InverseType; - using EigenBase<Inverse<PermutationType> >::derived; - - #ifndef EIGEN_PARSED_BY_DOXYGEN - typedef typename PermutationType::DenseMatrixType DenseMatrixType; - enum { - RowsAtCompileTime = PermTraits::RowsAtCompileTime, - ColsAtCompileTime = PermTraits::ColsAtCompileTime, - MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime - }; - #endif - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename DenseDerived> - void evalTo(MatrixBase<DenseDerived>& other) const - { - other.setZero(); - for (Index i=0; i<derived().rows();++i) - other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) = typename DenseDerived::Scalar(1); - } - #endif - - /** \return the equivalent permutation matrix */ - PlainPermutationType eval() const { return derived(); } - - DenseMatrixType toDenseMatrix() const { return derived(); } - - /** \returns the matrix with the inverse permutation applied to the columns. - */ - template<typename OtherDerived> friend - const Product<OtherDerived, InverseType, AliasFreeProduct> - operator*(const MatrixBase<OtherDerived>& matrix, const InverseType& trPerm) - { - return Product<OtherDerived, InverseType, AliasFreeProduct>(matrix.derived(), trPerm.derived()); - } - - /** \returns the matrix with the inverse permutation applied to the rows. - */ - template<typename OtherDerived> - const Product<InverseType, OtherDerived, AliasFreeProduct> - operator*(const MatrixBase<OtherDerived>& matrix) const - { - return Product<InverseType, OtherDerived, AliasFreeProduct>(derived(), matrix.derived()); - } -}; - -template<typename Derived> -const PermutationWrapper<const Derived> MatrixBase<Derived>::asPermutation() const -{ - return derived(); -} - -namespace internal { - -template<> struct AssignmentKind<DenseShape,PermutationShape> { typedef EigenBase2EigenBase Kind; }; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PERMUTATIONMATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/PlainObjectBase.h b/external/eigen/include/eigen3/Eigen/src/Core/PlainObjectBase.h deleted file mode 100644 index f6497e9f..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/PlainObjectBase.h +++ /dev/null @@ -1,1117 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DENSESTORAGEBASE_H -#define EIGEN_DENSESTORAGEBASE_H - -#if defined(EIGEN_INITIALIZE_MATRICES_BY_ZERO) -# define EIGEN_INITIALIZE_COEFFS -# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=Scalar(0); -#elif defined(EIGEN_INITIALIZE_MATRICES_BY_NAN) -# define EIGEN_INITIALIZE_COEFFS -# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=std::numeric_limits<Scalar>::quiet_NaN(); -#else -# undef EIGEN_INITIALIZE_COEFFS -# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED -#endif - -namespace Eigen { - -namespace internal { - -template<int MaxSizeAtCompileTime> struct check_rows_cols_for_overflow { - template<typename Index> - EIGEN_DEVICE_FUNC - static EIGEN_ALWAYS_INLINE void run(Index, Index) - { - } -}; - -template<> struct check_rows_cols_for_overflow<Dynamic> { - template<typename Index> - EIGEN_DEVICE_FUNC - static EIGEN_ALWAYS_INLINE void run(Index rows, Index cols) - { - // http://hg.mozilla.org/mozilla-central/file/6c8a909977d3/xpcom/ds/CheckedInt.h#l242 - // we assume Index is signed - Index max_index = (std::size_t(1) << (8 * sizeof(Index) - 1)) - 1; // assume Index is signed - bool error = (rows == 0 || cols == 0) ? false - : (rows > max_index / cols); - if (error) - throw_std_bad_alloc(); - } -}; - -template <typename Derived, - typename OtherDerived = Derived, - bool IsVector = bool(Derived::IsVectorAtCompileTime) && bool(OtherDerived::IsVectorAtCompileTime)> -struct conservative_resize_like_impl; - -template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> struct matrix_swap_impl; - -} // end namespace internal - -#ifdef EIGEN_PARSED_BY_DOXYGEN -namespace doxygen { - -// This is a workaround to doxygen not being able to understand the inheritance logic -// when it is hidden by the dense_xpr_base helper struct. -// Moreover, doxygen fails to include members that are not documented in the declaration body of -// MatrixBase if we inherits MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >, -// this is why we simply inherits MatrixBase, though this does not make sense. - -/** This class is just a workaround for Doxygen and it does not not actually exist. */ -template<typename Derived> struct dense_xpr_base_dispatcher; -/** This class is just a workaround for Doxygen and it does not not actually exist. */ -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -struct dense_xpr_base_dispatcher<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > - : public MatrixBase {}; -/** This class is just a workaround for Doxygen and it does not not actually exist. */ -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -struct dense_xpr_base_dispatcher<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > - : public ArrayBase {}; - -} // namespace doxygen - -/** \class PlainObjectBase - * \ingroup Core_Module - * \brief %Dense storage base class for matrices and arrays. - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_PLAINOBJECTBASE_PLUGIN. - * - * \tparam Derived is the derived type, e.g., a Matrix or Array - * - * \sa \ref TopicClassHierarchy - */ -template<typename Derived> -class PlainObjectBase : public doxygen::dense_xpr_base_dispatcher<Derived> -#else -template<typename Derived> -class PlainObjectBase : public internal::dense_xpr_base<Derived>::type -#endif -{ - public: - enum { Options = internal::traits<Derived>::Options }; - typedef typename internal::dense_xpr_base<Derived>::type Base; - - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::traits<Derived>::Scalar Scalar; - - typedef typename internal::packet_traits<Scalar>::type PacketScalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Derived DenseType; - - using Base::RowsAtCompileTime; - using Base::ColsAtCompileTime; - using Base::SizeAtCompileTime; - using Base::MaxRowsAtCompileTime; - using Base::MaxColsAtCompileTime; - using Base::MaxSizeAtCompileTime; - using Base::IsVectorAtCompileTime; - using Base::Flags; - - template<typename PlainObjectType, int MapOptions, typename StrideType> friend class Eigen::Map; - friend class Eigen::Map<Derived, Unaligned>; - typedef Eigen::Map<Derived, Unaligned> MapType; - friend class Eigen::Map<const Derived, Unaligned>; - typedef const Eigen::Map<const Derived, Unaligned> ConstMapType; -#if EIGEN_MAX_ALIGN_BYTES>0 - // for EIGEN_MAX_ALIGN_BYTES==0, AlignedMax==Unaligned, and many compilers generate warnings for friend-ing a class twice. - friend class Eigen::Map<Derived, AlignedMax>; - friend class Eigen::Map<const Derived, AlignedMax>; -#endif - typedef Eigen::Map<Derived, AlignedMax> AlignedMapType; - typedef const Eigen::Map<const Derived, AlignedMax> ConstAlignedMapType; - template<typename StrideType> struct StridedMapType { typedef Eigen::Map<Derived, Unaligned, StrideType> type; }; - template<typename StrideType> struct StridedConstMapType { typedef Eigen::Map<const Derived, Unaligned, StrideType> type; }; - template<typename StrideType> struct StridedAlignedMapType { typedef Eigen::Map<Derived, AlignedMax, StrideType> type; }; - template<typename StrideType> struct StridedConstAlignedMapType { typedef Eigen::Map<const Derived, AlignedMax, StrideType> type; }; - - protected: - DenseStorage<Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options> m_storage; - - public: - enum { NeedsToAlign = (SizeAtCompileTime != Dynamic) && (internal::traits<Derived>::Alignment>0) }; - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) - - EIGEN_DEVICE_FUNC - Base& base() { return *static_cast<Base*>(this); } - EIGEN_DEVICE_FUNC - const Base& base() const { return *static_cast<const Base*>(this); } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index rows() const { return m_storage.rows(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index cols() const { return m_storage.cols(); } - - /** This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,Index) const - * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts. - * - * See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const for details. */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& coeff(Index rowId, Index colId) const - { - if(Flags & RowMajorBit) - return m_storage.data()[colId + rowId * m_storage.cols()]; - else // column-major - return m_storage.data()[rowId + colId * m_storage.rows()]; - } - - /** This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const - * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts. - * - * See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const for details. */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const - { - return m_storage.data()[index]; - } - - /** This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const - * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts. - * - * See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const for details. */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index rowId, Index colId) - { - if(Flags & RowMajorBit) - return m_storage.data()[colId + rowId * m_storage.cols()]; - else // column-major - return m_storage.data()[rowId + colId * m_storage.rows()]; - } - - /** This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const - * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts. - * - * See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const for details. */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) - { - return m_storage.data()[index]; - } - - /** This is the const version of coeffRef(Index,Index) which is thus synonym of coeff(Index,Index). - * It is provided for convenience. */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& coeffRef(Index rowId, Index colId) const - { - if(Flags & RowMajorBit) - return m_storage.data()[colId + rowId * m_storage.cols()]; - else // column-major - return m_storage.data()[rowId + colId * m_storage.rows()]; - } - - /** This is the const version of coeffRef(Index) which is thus synonym of coeff(Index). - * It is provided for convenience. */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& coeffRef(Index index) const - { - return m_storage.data()[index]; - } - - /** \internal */ - template<int LoadMode> - EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const - { - return internal::ploadt<PacketScalar, LoadMode> - (m_storage.data() + (Flags & RowMajorBit - ? colId + rowId * m_storage.cols() - : rowId + colId * m_storage.rows())); - } - - /** \internal */ - template<int LoadMode> - EIGEN_STRONG_INLINE PacketScalar packet(Index index) const - { - return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index); - } - - /** \internal */ - template<int StoreMode> - EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketScalar& val) - { - internal::pstoret<Scalar, PacketScalar, StoreMode> - (m_storage.data() + (Flags & RowMajorBit - ? colId + rowId * m_storage.cols() - : rowId + colId * m_storage.rows()), val); - } - - /** \internal */ - template<int StoreMode> - EIGEN_STRONG_INLINE void writePacket(Index index, const PacketScalar& val) - { - internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val); - } - - /** \returns a const pointer to the data array of this matrix */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar *data() const - { return m_storage.data(); } - - /** \returns a pointer to the data array of this matrix */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() - { return m_storage.data(); } - - /** Resizes \c *this to a \a rows x \a cols matrix. - * - * This method is intended for dynamic-size matrices, although it is legal to call it on any - * matrix as long as fixed dimensions are left unchanged. If you only want to change the number - * of rows and/or of columns, you can use resize(NoChange_t, Index), resize(Index, NoChange_t). - * - * If the current number of coefficients of \c *this exactly matches the - * product \a rows * \a cols, then no memory allocation is performed and - * the current values are left unchanged. In all other cases, including - * shrinking, the data is reallocated and all previous values are lost. - * - * Example: \include Matrix_resize_int_int.cpp - * Output: \verbinclude Matrix_resize_int_int.out - * - * \sa resize(Index) for vectors, resize(NoChange_t, Index), resize(Index, NoChange_t) - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void resize(Index rows, Index cols) - { - eigen_assert( EIGEN_IMPLIES(RowsAtCompileTime!=Dynamic,rows==RowsAtCompileTime) - && EIGEN_IMPLIES(ColsAtCompileTime!=Dynamic,cols==ColsAtCompileTime) - && EIGEN_IMPLIES(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic,rows<=MaxRowsAtCompileTime) - && EIGEN_IMPLIES(ColsAtCompileTime==Dynamic && MaxColsAtCompileTime!=Dynamic,cols<=MaxColsAtCompileTime) - && rows>=0 && cols>=0 && "Invalid sizes when resizing a matrix or array."); - internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(rows, cols); - #ifdef EIGEN_INITIALIZE_COEFFS - Index size = rows*cols; - bool size_changed = size != this->size(); - m_storage.resize(size, rows, cols); - if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - #else - m_storage.resize(rows*cols, rows, cols); - #endif - } - - /** Resizes \c *this to a vector of length \a size - * - * \only_for_vectors. This method does not work for - * partially dynamic matrices when the static dimension is anything other - * than 1. For example it will not work with Matrix<double, 2, Dynamic>. - * - * Example: \include Matrix_resize_int.cpp - * Output: \verbinclude Matrix_resize_int.out - * - * \sa resize(Index,Index), resize(NoChange_t, Index), resize(Index, NoChange_t) - */ - EIGEN_DEVICE_FUNC - inline void resize(Index size) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(PlainObjectBase) - eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime==Dynamic || size<=MaxSizeAtCompileTime)) || SizeAtCompileTime == size) && size>=0); - #ifdef EIGEN_INITIALIZE_COEFFS - bool size_changed = size != this->size(); - #endif - if(RowsAtCompileTime == 1) - m_storage.resize(size, 1, size); - else - m_storage.resize(size, size, 1); - #ifdef EIGEN_INITIALIZE_COEFFS - if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - #endif - } - - /** Resizes the matrix, changing only the number of columns. For the parameter of type NoChange_t, just pass the special value \c NoChange - * as in the example below. - * - * Example: \include Matrix_resize_NoChange_int.cpp - * Output: \verbinclude Matrix_resize_NoChange_int.out - * - * \sa resize(Index,Index) - */ - EIGEN_DEVICE_FUNC - inline void resize(NoChange_t, Index cols) - { - resize(rows(), cols); - } - - /** Resizes the matrix, changing only the number of rows. For the parameter of type NoChange_t, just pass the special value \c NoChange - * as in the example below. - * - * Example: \include Matrix_resize_int_NoChange.cpp - * Output: \verbinclude Matrix_resize_int_NoChange.out - * - * \sa resize(Index,Index) - */ - EIGEN_DEVICE_FUNC - inline void resize(Index rows, NoChange_t) - { - resize(rows, cols()); - } - - /** Resizes \c *this to have the same dimensions as \a other. - * Takes care of doing all the checking that's needed. - * - * Note that copying a row-vector into a vector (and conversely) is allowed. - * The resizing, if any, is then done in the appropriate way so that row-vectors - * remain row-vectors and vectors remain vectors. - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void resizeLike(const EigenBase<OtherDerived>& _other) - { - const OtherDerived& other = _other.derived(); - internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(other.rows(), other.cols()); - const Index othersize = other.rows()*other.cols(); - if(RowsAtCompileTime == 1) - { - eigen_assert(other.rows() == 1 || other.cols() == 1); - resize(1, othersize); - } - else if(ColsAtCompileTime == 1) - { - eigen_assert(other.rows() == 1 || other.cols() == 1); - resize(othersize, 1); - } - else resize(other.rows(), other.cols()); - } - - /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. - * - * The method is intended for matrices of dynamic size. If you only want to change the number - * of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or - * conservativeResize(Index, NoChange_t). - * - * Matrices are resized relative to the top-left element. In case values need to be - * appended to the matrix they will be uninitialized. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void conservativeResize(Index rows, Index cols) - { - internal::conservative_resize_like_impl<Derived>::run(*this, rows, cols); - } - - /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. - * - * As opposed to conservativeResize(Index rows, Index cols), this version leaves - * the number of columns unchanged. - * - * In case the matrix is growing, new rows will be uninitialized. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void conservativeResize(Index rows, NoChange_t) - { - // Note: see the comment in conservativeResize(Index,Index) - conservativeResize(rows, cols()); - } - - /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. - * - * As opposed to conservativeResize(Index rows, Index cols), this version leaves - * the number of rows unchanged. - * - * In case the matrix is growing, new columns will be uninitialized. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void conservativeResize(NoChange_t, Index cols) - { - // Note: see the comment in conservativeResize(Index,Index) - conservativeResize(rows(), cols); - } - - /** Resizes the vector to \a size while retaining old values. - * - * \only_for_vectors. This method does not work for - * partially dynamic matrices when the static dimension is anything other - * than 1. For example it will not work with Matrix<double, 2, Dynamic>. - * - * When values are appended, they will be uninitialized. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void conservativeResize(Index size) - { - internal::conservative_resize_like_impl<Derived>::run(*this, size); - } - - /** Resizes the matrix to \a rows x \a cols of \c other, while leaving old values untouched. - * - * The method is intended for matrices of dynamic size. If you only want to change the number - * of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or - * conservativeResize(Index, NoChange_t). - * - * Matrices are resized relative to the top-left element. In case values need to be - * appended to the matrix they will copied from \c other. - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void conservativeResizeLike(const DenseBase<OtherDerived>& other) - { - internal::conservative_resize_like_impl<Derived,OtherDerived>::run(*this, other); - } - - /** This is a special case of the templated operator=. Its purpose is to - * prevent a default operator= from hiding the templated operator=. - */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& operator=(const PlainObjectBase& other) - { - return _set(other); - } - - /** \sa MatrixBase::lazyAssign() */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& lazyAssign(const DenseBase<OtherDerived>& other) - { - _resize_to_match(other); - return Base::lazyAssign(other.derived()); - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& operator=(const ReturnByValue<OtherDerived>& func) - { - resize(func.rows(), func.cols()); - return Base::operator=(func); - } - - // Prevent user from trying to instantiate PlainObjectBase objects - // by making all its constructor protected. See bug 1074. - protected: - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PlainObjectBase() : m_storage() - { -// _check_template_params(); -// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - } - -#ifndef EIGEN_PARSED_BY_DOXYGEN - // FIXME is it still needed ? - /** \internal */ - EIGEN_DEVICE_FUNC - explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert) - : m_storage(internal::constructor_without_unaligned_array_assert()) - { -// _check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - } -#endif - -#if EIGEN_HAS_RVALUE_REFERENCES - EIGEN_DEVICE_FUNC - PlainObjectBase(PlainObjectBase&& other) EIGEN_NOEXCEPT - : m_storage( std::move(other.m_storage) ) - { - } - - EIGEN_DEVICE_FUNC - PlainObjectBase& operator=(PlainObjectBase&& other) EIGEN_NOEXCEPT - { - using std::swap; - swap(m_storage, other.m_storage); - return *this; - } -#endif - - /** Copy constructor */ - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PlainObjectBase(const PlainObjectBase& other) - : Base(), m_storage(other.m_storage) { } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PlainObjectBase(Index size, Index rows, Index cols) - : m_storage(size, rows, cols) - { -// _check_template_params(); -// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - } - - #if EIGEN_HAS_CXX11 - /** \brief Construct a row of column vector with fixed size from an arbitrary number of coefficients. \cpp11 - * - * \only_for_vectors - * - * This constructor is for 1D array or vectors with more than 4 coefficients. - * There exists C++98 analogue constructors for fixed-size array/vector having 1, 2, 3, or 4 coefficients. - * - * \warning To construct a column (resp. row) vector of fixed length, the number of values passed to this - * constructor must match the the fixed number of rows (resp. columns) of \c *this. - */ - template <typename... ArgTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) - : m_storage() - { - _check_template_params(); - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, sizeof...(args) + 4); - m_storage.data()[0] = a0; - m_storage.data()[1] = a1; - m_storage.data()[2] = a2; - m_storage.data()[3] = a3; - int i = 4; - auto x = {(m_storage.data()[i++] = args, 0)...}; - static_cast<void>(x); - } - - /** \brief Constructs a Matrix or Array and initializes it by elements given by an initializer list of initializer - * lists \cpp11 - */ - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE PlainObjectBase(const std::initializer_list<std::initializer_list<Scalar>>& list) - : m_storage() - { - _check_template_params(); - - size_t list_size = 0; - if (list.begin() != list.end()) { - list_size = list.begin()->size(); - } - - // This is to allow syntax like VectorXi {{1, 2, 3, 4}} - if (ColsAtCompileTime == 1 && list.size() == 1) { - eigen_assert(list_size == static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic); - resize(list_size, ColsAtCompileTime); - std::copy(list.begin()->begin(), list.begin()->end(), m_storage.data()); - } else { - eigen_assert(list.size() == static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic); - eigen_assert(list_size == static_cast<size_t>(ColsAtCompileTime) || ColsAtCompileTime == Dynamic); - resize(list.size(), list_size); - - Index row_index = 0; - for (const std::initializer_list<Scalar>& row : list) { - eigen_assert(list_size == row.size()); - Index col_index = 0; - for (const Scalar& e : row) { - coeffRef(row_index, col_index) = e; - ++col_index; - } - ++row_index; - } - } - } - #endif // end EIGEN_HAS_CXX11 - - /** \sa PlainObjectBase::operator=(const EigenBase<OtherDerived>&) */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PlainObjectBase(const DenseBase<OtherDerived> &other) - : m_storage() - { - _check_template_params(); - resizeLike(other); - _set_noalias(other); - } - - /** \sa PlainObjectBase::operator=(const EigenBase<OtherDerived>&) */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PlainObjectBase(const EigenBase<OtherDerived> &other) - : m_storage() - { - _check_template_params(); - resizeLike(other); - *this = other.derived(); - } - /** \brief Copy constructor with in-place evaluation */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PlainObjectBase(const ReturnByValue<OtherDerived>& other) - { - _check_template_params(); - // FIXME this does not automatically transpose vectors if necessary - resize(other.rows(), other.cols()); - other.evalTo(this->derived()); - } - - public: - - /** \brief Copies the generic expression \a other into *this. - * \copydetails DenseBase::operator=(const EigenBase<OtherDerived> &other) - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& operator=(const EigenBase<OtherDerived> &other) - { - _resize_to_match(other); - Base::operator=(other.derived()); - return this->derived(); - } - - /** \name Map - * These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects, - * while the AlignedMap() functions return aligned Map objects and thus should be called only with 16-byte-aligned - * \a data pointers. - * - * Here is an example using strides: - * \include Matrix_Map_stride.cpp - * Output: \verbinclude Matrix_Map_stride.out - * - * \see class Map - */ - //@{ - static inline ConstMapType Map(const Scalar* data) - { return ConstMapType(data); } - static inline MapType Map(Scalar* data) - { return MapType(data); } - static inline ConstMapType Map(const Scalar* data, Index size) - { return ConstMapType(data, size); } - static inline MapType Map(Scalar* data, Index size) - { return MapType(data, size); } - static inline ConstMapType Map(const Scalar* data, Index rows, Index cols) - { return ConstMapType(data, rows, cols); } - static inline MapType Map(Scalar* data, Index rows, Index cols) - { return MapType(data, rows, cols); } - - static inline ConstAlignedMapType MapAligned(const Scalar* data) - { return ConstAlignedMapType(data); } - static inline AlignedMapType MapAligned(Scalar* data) - { return AlignedMapType(data); } - static inline ConstAlignedMapType MapAligned(const Scalar* data, Index size) - { return ConstAlignedMapType(data, size); } - static inline AlignedMapType MapAligned(Scalar* data, Index size) - { return AlignedMapType(data, size); } - static inline ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols) - { return ConstAlignedMapType(data, rows, cols); } - static inline AlignedMapType MapAligned(Scalar* data, Index rows, Index cols) - { return AlignedMapType(data, rows, cols); } - - template<int Outer, int Inner> - static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, const Stride<Outer, Inner>& stride) - { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); } - template<int Outer, int Inner> - static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, const Stride<Outer, Inner>& stride) - { return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); } - template<int Outer, int Inner> - static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index size, const Stride<Outer, Inner>& stride) - { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); } - template<int Outer, int Inner> - static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index size, const Stride<Outer, Inner>& stride) - { return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); } - template<int Outer, int Inner> - static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride) - { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); } - template<int Outer, int Inner> - static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride) - { return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); } - - template<int Outer, int Inner> - static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, const Stride<Outer, Inner>& stride) - { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); } - template<int Outer, int Inner> - static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, const Stride<Outer, Inner>& stride) - { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); } - template<int Outer, int Inner> - static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index size, const Stride<Outer, Inner>& stride) - { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); } - template<int Outer, int Inner> - static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index size, const Stride<Outer, Inner>& stride) - { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); } - template<int Outer, int Inner> - static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride) - { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); } - template<int Outer, int Inner> - static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride) - { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); } - //@} - - using Base::setConstant; - EIGEN_DEVICE_FUNC Derived& setConstant(Index size, const Scalar& val); - EIGEN_DEVICE_FUNC Derived& setConstant(Index rows, Index cols, const Scalar& val); - - using Base::setZero; - EIGEN_DEVICE_FUNC Derived& setZero(Index size); - EIGEN_DEVICE_FUNC Derived& setZero(Index rows, Index cols); - - using Base::setOnes; - EIGEN_DEVICE_FUNC Derived& setOnes(Index size); - EIGEN_DEVICE_FUNC Derived& setOnes(Index rows, Index cols); - - using Base::setRandom; - Derived& setRandom(Index size); - Derived& setRandom(Index rows, Index cols); - - #ifdef EIGEN_PLAINOBJECTBASE_PLUGIN - #include EIGEN_PLAINOBJECTBASE_PLUGIN - #endif - - protected: - /** \internal Resizes *this in preparation for assigning \a other to it. - * Takes care of doing all the checking that's needed. - * - * Note that copying a row-vector into a vector (and conversely) is allowed. - * The resizing, if any, is then done in the appropriate way so that row-vectors - * remain row-vectors and vectors remain vectors. - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _resize_to_match(const EigenBase<OtherDerived>& other) - { - #ifdef EIGEN_NO_AUTOMATIC_RESIZING - eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.size()) - : (rows() == other.rows() && cols() == other.cols()))) - && "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined"); - EIGEN_ONLY_USED_FOR_DEBUG(other); - #else - resizeLike(other); - #endif - } - - /** - * \brief Copies the value of the expression \a other into \c *this with automatic resizing. - * - * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized), - * it will be initialized. - * - * Note that copying a row-vector into a vector (and conversely) is allowed. - * The resizing, if any, is then done in the appropriate way so that row-vectors - * remain row-vectors and vectors remain vectors. - * - * \sa operator=(const MatrixBase<OtherDerived>&), _set_noalias() - * - * \internal - */ - // aliasing is dealt once in internal::call_assignment - // so at this stage we have to assume aliasing... and resising has to be done later. - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& _set(const DenseBase<OtherDerived>& other) - { - internal::call_assignment(this->derived(), other.derived()); - return this->derived(); - } - - /** \internal Like _set() but additionally makes the assumption that no aliasing effect can happen (which - * is the case when creating a new matrix) so one can enforce lazy evaluation. - * - * \sa operator=(const MatrixBase<OtherDerived>&), _set() - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& _set_noalias(const DenseBase<OtherDerived>& other) - { - // I don't think we need this resize call since the lazyAssign will anyways resize - // and lazyAssign will be called by the assign selector. - //_resize_to_match(other); - // the 'false' below means to enforce lazy evaluation. We don't use lazyAssign() because - // it wouldn't allow to copy a row-vector into a column-vector. - internal::call_assignment_no_alias(this->derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>()); - return this->derived(); - } - - template<typename T0, typename T1> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init2(Index rows, Index cols, typename internal::enable_if<Base::SizeAtCompileTime!=2,T0>::type* = 0) - { - const bool t0_is_integer_alike = internal::is_valid_index_type<T0>::value; - const bool t1_is_integer_alike = internal::is_valid_index_type<T1>::value; - EIGEN_STATIC_ASSERT(t0_is_integer_alike && - t1_is_integer_alike, - FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED) - resize(rows,cols); - } - - template<typename T0, typename T1> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init2(const T0& val0, const T1& val1, typename internal::enable_if<Base::SizeAtCompileTime==2,T0>::type* = 0) - { - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2) - m_storage.data()[0] = Scalar(val0); - m_storage.data()[1] = Scalar(val1); - } - - template<typename T0, typename T1> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init2(const Index& val0, const Index& val1, - typename internal::enable_if< (!internal::is_same<Index,Scalar>::value) - && (internal::is_same<T0,Index>::value) - && (internal::is_same<T1,Index>::value) - && Base::SizeAtCompileTime==2,T1>::type* = 0) - { - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2) - m_storage.data()[0] = Scalar(val0); - m_storage.data()[1] = Scalar(val1); - } - - // The argument is convertible to the Index type and we either have a non 1x1 Matrix, or a dynamic-sized Array, - // then the argument is meant to be the size of the object. - template<typename T> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(Index size, typename internal::enable_if< (Base::SizeAtCompileTime!=1 || !internal::is_convertible<T, Scalar>::value) - && ((!internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value || Base::SizeAtCompileTime==Dynamic)),T>::type* = 0) - { - // NOTE MSVC 2008 complains if we directly put bool(NumTraits<T>::IsInteger) as the EIGEN_STATIC_ASSERT argument. - const bool is_integer_alike = internal::is_valid_index_type<T>::value; - EIGEN_UNUSED_VARIABLE(is_integer_alike); - EIGEN_STATIC_ASSERT(is_integer_alike, - FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED) - resize(size); - } - - // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar type can be implicitly converted) - template<typename T> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const Scalar& val0, typename internal::enable_if<Base::SizeAtCompileTime==1 && internal::is_convertible<T, Scalar>::value,T>::type* = 0) - { - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1) - m_storage.data()[0] = val0; - } - - // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar type match the index type) - template<typename T> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const Index& val0, - typename internal::enable_if< (!internal::is_same<Index,Scalar>::value) - && (internal::is_same<Index,T>::value) - && Base::SizeAtCompileTime==1 - && internal::is_convertible<T, Scalar>::value,T*>::type* = 0) - { - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1) - m_storage.data()[0] = Scalar(val0); - } - - // Initialize a fixed size matrix from a pointer to raw data - template<typename T> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const Scalar* data){ - this->_set_noalias(ConstMapType(data)); - } - - // Initialize an arbitrary matrix from a dense expression - template<typename T, typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const DenseBase<OtherDerived>& other){ - this->_set_noalias(other); - } - - // Initialize an arbitrary matrix from an object convertible to the Derived type. - template<typename T> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const Derived& other){ - this->_set_noalias(other); - } - - // Initialize an arbitrary matrix from a generic Eigen expression - template<typename T, typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const EigenBase<OtherDerived>& other){ - this->derived() = other; - } - - template<typename T, typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const ReturnByValue<OtherDerived>& other) - { - resize(other.rows(), other.cols()); - other.evalTo(this->derived()); - } - - template<typename T, typename OtherDerived, int ColsAtCompileTime> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const RotationBase<OtherDerived,ColsAtCompileTime>& r) - { - this->derived() = r; - } - - // For fixed-size Array<Scalar,...> - template<typename T> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const Scalar& val0, - typename internal::enable_if< Base::SizeAtCompileTime!=Dynamic - && Base::SizeAtCompileTime!=1 - && internal::is_convertible<T, Scalar>::value - && internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T>::type* = 0) - { - Base::setConstant(val0); - } - - // For fixed-size Array<Index,...> - template<typename T> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _init1(const Index& val0, - typename internal::enable_if< (!internal::is_same<Index,Scalar>::value) - && (internal::is_same<Index,T>::value) - && Base::SizeAtCompileTime!=Dynamic - && Base::SizeAtCompileTime!=1 - && internal::is_convertible<T, Scalar>::value - && internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T*>::type* = 0) - { - Base::setConstant(val0); - } - - template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> - friend struct internal::matrix_swap_impl; - - public: - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal - * \brief Override DenseBase::swap() since for dynamic-sized matrices - * of same type it is enough to swap the data pointers. - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void swap(DenseBase<OtherDerived> & other) - { - enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==Dynamic }; - internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.derived()); - } - - /** \internal - * \brief const version forwarded to DenseBase::swap - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void swap(DenseBase<OtherDerived> const & other) - { Base::swap(other.derived()); } - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void _check_template_params() - { - EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (Options&RowMajor)==RowMajor) - && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (Options&RowMajor)==0) - && ((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0)) - && ((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0)) - && ((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0)) - && ((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0)) - && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic) - && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic) - && (Options & (DontAlign|RowMajor)) == Options), - INVALID_MATRIX_TEMPLATE_PARAMETERS) - } - - enum { IsPlainObjectBase = 1 }; -#endif -}; - -namespace internal { - -template <typename Derived, typename OtherDerived, bool IsVector> -struct conservative_resize_like_impl -{ - #if EIGEN_HAS_TYPE_TRAITS - static const bool IsRelocatable = std::is_trivially_copyable<typename Derived::Scalar>::value; - #else - static const bool IsRelocatable = !NumTraits<typename Derived::Scalar>::RequireInitialization; - #endif - static void run(DenseBase<Derived>& _this, Index rows, Index cols) - { - if (_this.rows() == rows && _this.cols() == cols) return; - EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived) - - if ( IsRelocatable - && (( Derived::IsRowMajor && _this.cols() == cols) || // row-major and we change only the number of rows - (!Derived::IsRowMajor && _this.rows() == rows) )) // column-major and we change only the number of columns - { - internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime>::run(rows, cols); - _this.derived().m_storage.conservativeResize(rows*cols,rows,cols); - } - else - { - // The storage order does not allow us to use reallocation. - typename Derived::PlainObject tmp(rows,cols); - const Index common_rows = numext::mini(rows, _this.rows()); - const Index common_cols = numext::mini(cols, _this.cols()); - tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols); - _this.derived().swap(tmp); - } - } - - static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other) - { - if (_this.rows() == other.rows() && _this.cols() == other.cols()) return; - - // Note: Here is space for improvement. Basically, for conservativeResize(Index,Index), - // neither RowsAtCompileTime or ColsAtCompileTime must be Dynamic. If only one of the - // dimensions is dynamic, one could use either conservativeResize(Index rows, NoChange_t) or - // conservativeResize(NoChange_t, Index cols). For these methods new static asserts like - // EIGEN_STATIC_ASSERT_DYNAMIC_ROWS and EIGEN_STATIC_ASSERT_DYNAMIC_COLS would be good. - EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived) - EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived) - - if ( IsRelocatable && - (( Derived::IsRowMajor && _this.cols() == other.cols()) || // row-major and we change only the number of rows - (!Derived::IsRowMajor && _this.rows() == other.rows()) )) // column-major and we change only the number of columns - { - const Index new_rows = other.rows() - _this.rows(); - const Index new_cols = other.cols() - _this.cols(); - _this.derived().m_storage.conservativeResize(other.size(),other.rows(),other.cols()); - if (new_rows>0) - _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows); - else if (new_cols>0) - _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols); - } - else - { - // The storage order does not allow us to use reallocation. - typename Derived::PlainObject tmp(other); - const Index common_rows = numext::mini(tmp.rows(), _this.rows()); - const Index common_cols = numext::mini(tmp.cols(), _this.cols()); - tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols); - _this.derived().swap(tmp); - } - } -}; - -// Here, the specialization for vectors inherits from the general matrix case -// to allow calling .conservativeResize(rows,cols) on vectors. -template <typename Derived, typename OtherDerived> -struct conservative_resize_like_impl<Derived,OtherDerived,true> - : conservative_resize_like_impl<Derived,OtherDerived,false> -{ - typedef conservative_resize_like_impl<Derived,OtherDerived,false> Base; - using Base::run; - using Base::IsRelocatable; - - static void run(DenseBase<Derived>& _this, Index size) - { - const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : size; - const Index new_cols = Derived::RowsAtCompileTime==1 ? size : 1; - if(IsRelocatable) - _this.derived().m_storage.conservativeResize(size,new_rows,new_cols); - else - Base::run(_this.derived(), new_rows, new_cols); - } - - static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other) - { - if (_this.rows() == other.rows() && _this.cols() == other.cols()) return; - - const Index num_new_elements = other.size() - _this.size(); - - const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : other.rows(); - const Index new_cols = Derived::RowsAtCompileTime==1 ? other.cols() : 1; - if(IsRelocatable) - _this.derived().m_storage.conservativeResize(other.size(),new_rows,new_cols); - else - Base::run(_this.derived(), new_rows, new_cols); - - if (num_new_elements > 0) - _this.tail(num_new_elements) = other.tail(num_new_elements); - } -}; - -template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> -struct matrix_swap_impl -{ - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void run(MatrixTypeA& a, MatrixTypeB& b) - { - a.base().swap(b); - } -}; - -template<typename MatrixTypeA, typename MatrixTypeB> -struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true> -{ - EIGEN_DEVICE_FUNC - static inline void run(MatrixTypeA& a, MatrixTypeB& b) - { - static_cast<typename MatrixTypeA::Base&>(a).m_storage.swap(static_cast<typename MatrixTypeB::Base&>(b).m_storage); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_DENSESTORAGEBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Product.h b/external/eigen/include/eigen3/Eigen/src/Core/Product.h deleted file mode 100644 index 13d5662d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Product.h +++ /dev/null @@ -1,191 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PRODUCT_H -#define EIGEN_PRODUCT_H - -namespace Eigen { - -template<typename Lhs, typename Rhs, int Option, typename StorageKind> class ProductImpl; - -namespace internal { - -template<typename Lhs, typename Rhs, int Option> -struct traits<Product<Lhs, Rhs, Option> > -{ - typedef typename remove_all<Lhs>::type LhsCleaned; - typedef typename remove_all<Rhs>::type RhsCleaned; - typedef traits<LhsCleaned> LhsTraits; - typedef traits<RhsCleaned> RhsTraits; - - typedef MatrixXpr XprKind; - - typedef typename ScalarBinaryOpTraits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar; - typedef typename product_promote_storage_type<typename LhsTraits::StorageKind, - typename RhsTraits::StorageKind, - internal::product_type<Lhs,Rhs>::ret>::ret StorageKind; - typedef typename promote_index_type<typename LhsTraits::StorageIndex, - typename RhsTraits::StorageIndex>::type StorageIndex; - - enum { - RowsAtCompileTime = LhsTraits::RowsAtCompileTime, - ColsAtCompileTime = RhsTraits::ColsAtCompileTime, - MaxRowsAtCompileTime = LhsTraits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = RhsTraits::MaxColsAtCompileTime, - - // FIXME: only needed by GeneralMatrixMatrixTriangular - InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsTraits::ColsAtCompileTime, RhsTraits::RowsAtCompileTime), - - // The storage order is somewhat arbitrary here. The correct one will be determined through the evaluator. - Flags = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? RowMajorBit - : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0 - : ( ((LhsTraits::Flags&NoPreferredStorageOrderBit) && (RhsTraits::Flags&RowMajorBit)) - || ((RhsTraits::Flags&NoPreferredStorageOrderBit) && (LhsTraits::Flags&RowMajorBit)) ) ? RowMajorBit - : NoPreferredStorageOrderBit - }; -}; - -} // end namespace internal - -/** \class Product - * \ingroup Core_Module - * - * \brief Expression of the product of two arbitrary matrices or vectors - * - * \tparam _Lhs the type of the left-hand side expression - * \tparam _Rhs the type of the right-hand side expression - * - * This class represents an expression of the product of two arbitrary matrices. - * - * The other template parameters are: - * \tparam Option can be DefaultProduct, AliasFreeProduct, or LazyProduct - * - */ -template<typename _Lhs, typename _Rhs, int Option> -class Product : public ProductImpl<_Lhs,_Rhs,Option, - typename internal::product_promote_storage_type<typename internal::traits<_Lhs>::StorageKind, - typename internal::traits<_Rhs>::StorageKind, - internal::product_type<_Lhs,_Rhs>::ret>::ret> -{ - public: - - typedef _Lhs Lhs; - typedef _Rhs Rhs; - - typedef typename ProductImpl< - Lhs, Rhs, Option, - typename internal::product_promote_storage_type<typename internal::traits<Lhs>::StorageKind, - typename internal::traits<Rhs>::StorageKind, - internal::product_type<Lhs,Rhs>::ret>::ret>::Base Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(Product) - - typedef typename internal::ref_selector<Lhs>::type LhsNested; - typedef typename internal::ref_selector<Rhs>::type RhsNested; - typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned; - typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) - { - eigen_assert(lhs.cols() == rhs.rows() - && "invalid matrix product" - && "if you wanted a coeff-wise or a dot product use the respective explicit functions"); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index rows() const { return m_lhs.rows(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index cols() const { return m_rhs.cols(); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const LhsNestedCleaned& lhs() const { return m_lhs; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const RhsNestedCleaned& rhs() const { return m_rhs; } - - protected: - - LhsNested m_lhs; - RhsNested m_rhs; -}; - -namespace internal { - -template<typename Lhs, typename Rhs, int Option, int ProductTag = internal::product_type<Lhs,Rhs>::ret> -class dense_product_base - : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type -{}; - -/** Conversion to scalar for inner-products */ -template<typename Lhs, typename Rhs, int Option> -class dense_product_base<Lhs, Rhs, Option, InnerProduct> - : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type -{ - typedef Product<Lhs,Rhs,Option> ProductXpr; - typedef typename internal::dense_xpr_base<ProductXpr>::type Base; -public: - using Base::derived; - typedef typename Base::Scalar Scalar; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator const Scalar() const - { - return internal::evaluator<ProductXpr>(derived()).coeff(0,0); - } -}; - -} // namespace internal - -// Generic API dispatcher -template<typename Lhs, typename Rhs, int Option, typename StorageKind> -class ProductImpl : public internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type -{ - public: - typedef typename internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type Base; -}; - -template<typename Lhs, typename Rhs, int Option> -class ProductImpl<Lhs,Rhs,Option,Dense> - : public internal::dense_product_base<Lhs,Rhs,Option> -{ - typedef Product<Lhs, Rhs, Option> Derived; - - public: - - typedef typename internal::dense_product_base<Lhs, Rhs, Option> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Derived) - protected: - enum { - IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime == Dynamic) && - (ColsAtCompileTime == 1 || ColsAtCompileTime == Dynamic), - EnableCoeff = IsOneByOne || Option==LazyProduct - }; - - public: - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index row, Index col) const - { - EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS); - eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) ); - - return internal::evaluator<Derived>(derived()).coeff(row,col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index i) const - { - EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS); - eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) ); - - return internal::evaluator<Derived>(derived()).coeff(i); - } - - -}; - -} // end namespace Eigen - -#endif // EIGEN_PRODUCT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/ProductEvaluators.h b/external/eigen/include/eigen3/Eigen/src/Core/ProductEvaluators.h deleted file mode 100644 index d53dc30a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/ProductEvaluators.h +++ /dev/null @@ -1,1174 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2011 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_PRODUCTEVALUATORS_H -#define EIGEN_PRODUCTEVALUATORS_H - -namespace Eigen { - -namespace internal { - -/** \internal - * Evaluator of a product expression. - * Since products require special treatments to handle all possible cases, - * we simply defer the evaluation logic to a product_evaluator class - * which offers more partial specialization possibilities. - * - * \sa class product_evaluator - */ -template<typename Lhs, typename Rhs, int Options> -struct evaluator<Product<Lhs, Rhs, Options> > - : public product_evaluator<Product<Lhs, Rhs, Options> > -{ - typedef Product<Lhs, Rhs, Options> XprType; - typedef product_evaluator<XprType> Base; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) : Base(xpr) {} -}; - -// Catch "scalar * ( A * B )" and transform it to "(A*scalar) * B" -// TODO we should apply that rule only if that's really helpful -template<typename Lhs, typename Rhs, typename Scalar1, typename Scalar2, typename Plain1> -struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>, - const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>, - const Product<Lhs, Rhs, DefaultProduct> > > -{ - static const bool value = true; -}; -template<typename Lhs, typename Rhs, typename Scalar1, typename Scalar2, typename Plain1> -struct evaluator<CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>, - const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>, - const Product<Lhs, Rhs, DefaultProduct> > > - : public evaluator<Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> > -{ - typedef CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>, - const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>, - const Product<Lhs, Rhs, DefaultProduct> > XprType; - typedef evaluator<Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> > Base; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) - : Base(xpr.lhs().functor().m_other * xpr.rhs().lhs() * xpr.rhs().rhs()) - {} -}; - - -template<typename Lhs, typename Rhs, int DiagIndex> -struct evaluator<Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> > - : public evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> > -{ - typedef Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> XprType; - typedef evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> > Base; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) - : Base(Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex>( - Product<Lhs, Rhs, LazyProduct>(xpr.nestedExpression().lhs(), xpr.nestedExpression().rhs()), - xpr.index() )) - {} -}; - - -// Helper class to perform a matrix product with the destination at hand. -// Depending on the sizes of the factors, there are different evaluation strategies -// as controlled by internal::product_type. -template< typename Lhs, typename Rhs, - typename LhsShape = typename evaluator_traits<Lhs>::Shape, - typename RhsShape = typename evaluator_traits<Rhs>::Shape, - int ProductType = internal::product_type<Lhs,Rhs>::value> -struct generic_product_impl; - -template<typename Lhs, typename Rhs> -struct evaluator_assume_aliasing<Product<Lhs, Rhs, DefaultProduct> > { - static const bool value = true; -}; - -// This is the default evaluator implementation for products: -// It creates a temporary and call generic_product_impl -template<typename Lhs, typename Rhs, int Options, int ProductTag, typename LhsShape, typename RhsShape> -struct product_evaluator<Product<Lhs, Rhs, Options>, ProductTag, LhsShape, RhsShape> - : public evaluator<typename Product<Lhs, Rhs, Options>::PlainObject> -{ - typedef Product<Lhs, Rhs, Options> XprType; - typedef typename XprType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - enum { - Flags = Base::Flags | EvalBeforeNestingBit - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit product_evaluator(const XprType& xpr) - : m_result(xpr.rows(), xpr.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - -// FIXME shall we handle nested_eval here?, -// if so, then we must take care at removing the call to nested_eval in the specializations (e.g., in permutation_matrix_product, transposition_matrix_product, etc.) -// typedef typename internal::nested_eval<Lhs,Rhs::ColsAtCompileTime>::type LhsNested; -// typedef typename internal::nested_eval<Rhs,Lhs::RowsAtCompileTime>::type RhsNested; -// typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned; -// typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned; -// -// const LhsNested lhs(xpr.lhs()); -// const RhsNested rhs(xpr.rhs()); -// -// generic_product_impl<LhsNestedCleaned, RhsNestedCleaned>::evalTo(m_result, lhs, rhs); - - generic_product_impl<Lhs, Rhs, LhsShape, RhsShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs()); - } - -protected: - PlainObject m_result; -}; - -// The following three shortcuts are enabled only if the scalar types match exactly. -// TODO: we could enable them for different scalar types when the product is not vectorized. - -// Dense = Product -template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar> -struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::assign_op<Scalar,Scalar>, Dense2Dense, - typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type> -{ - typedef Product<Lhs,Rhs,Options> SrcXprType; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - // FIXME shall we handle nested_eval here? - generic_product_impl<Lhs, Rhs>::evalTo(dst, src.lhs(), src.rhs()); - } -}; - -// Dense += Product -template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar> -struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::add_assign_op<Scalar,Scalar>, Dense2Dense, - typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type> -{ - typedef Product<Lhs,Rhs,Options> SrcXprType; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<Scalar,Scalar> &) - { - eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); - // FIXME shall we handle nested_eval here? - generic_product_impl<Lhs, Rhs>::addTo(dst, src.lhs(), src.rhs()); - } -}; - -// Dense -= Product -template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar> -struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::sub_assign_op<Scalar,Scalar>, Dense2Dense, - typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type> -{ - typedef Product<Lhs,Rhs,Options> SrcXprType; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<Scalar,Scalar> &) - { - eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); - // FIXME shall we handle nested_eval here? - generic_product_impl<Lhs, Rhs>::subTo(dst, src.lhs(), src.rhs()); - } -}; - - -// Dense ?= scalar * Product -// TODO we should apply that rule if that's really helpful -// for instance, this is not good for inner products -template< typename DstXprType, typename Lhs, typename Rhs, typename AssignFunc, typename Scalar, typename ScalarBis, typename Plain> -struct Assignment<DstXprType, CwiseBinaryOp<internal::scalar_product_op<ScalarBis,Scalar>, const CwiseNullaryOp<internal::scalar_constant_op<ScalarBis>,Plain>, - const Product<Lhs,Rhs,DefaultProduct> >, AssignFunc, Dense2Dense> -{ - typedef CwiseBinaryOp<internal::scalar_product_op<ScalarBis,Scalar>, - const CwiseNullaryOp<internal::scalar_constant_op<ScalarBis>,Plain>, - const Product<Lhs,Rhs,DefaultProduct> > SrcXprType; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void run(DstXprType &dst, const SrcXprType &src, const AssignFunc& func) - { - call_assignment_no_alias(dst, (src.lhs().functor().m_other * src.rhs().lhs())*src.rhs().rhs(), func); - } -}; - -//---------------------------------------- -// Catch "Dense ?= xpr + Product<>" expression to save one temporary -// FIXME we could probably enable these rules for any product, i.e., not only Dense and DefaultProduct - -template<typename OtherXpr, typename Lhs, typename Rhs> -struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_sum_op<typename OtherXpr::Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, const OtherXpr, - const Product<Lhs,Rhs,DefaultProduct> >, DenseShape > { - static const bool value = true; -}; - -template<typename OtherXpr, typename Lhs, typename Rhs> -struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_difference_op<typename OtherXpr::Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, const OtherXpr, - const Product<Lhs,Rhs,DefaultProduct> >, DenseShape > { - static const bool value = true; -}; - -template<typename DstXprType, typename OtherXpr, typename ProductType, typename Func1, typename Func2> -struct assignment_from_xpr_op_product -{ - template<typename SrcXprType, typename InitialFunc> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void run(DstXprType &dst, const SrcXprType &src, const InitialFunc& /*func*/) - { - call_assignment_no_alias(dst, src.lhs(), Func1()); - call_assignment_no_alias(dst, src.rhs(), Func2()); - } -}; - -#define EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(ASSIGN_OP,BINOP,ASSIGN_OP2) \ - template< typename DstXprType, typename OtherXpr, typename Lhs, typename Rhs, typename DstScalar, typename SrcScalar, typename OtherScalar,typename ProdScalar> \ - struct Assignment<DstXprType, CwiseBinaryOp<internal::BINOP<OtherScalar,ProdScalar>, const OtherXpr, \ - const Product<Lhs,Rhs,DefaultProduct> >, internal::ASSIGN_OP<DstScalar,SrcScalar>, Dense2Dense> \ - : assignment_from_xpr_op_product<DstXprType, OtherXpr, Product<Lhs,Rhs,DefaultProduct>, internal::ASSIGN_OP<DstScalar,OtherScalar>, internal::ASSIGN_OP2<DstScalar,ProdScalar> > \ - {} - -EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_sum_op,add_assign_op); -EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op,scalar_sum_op,add_assign_op); -EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op,scalar_sum_op,sub_assign_op); - -EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_difference_op,sub_assign_op); -EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op,scalar_difference_op,sub_assign_op); -EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op,scalar_difference_op,add_assign_op); - -//---------------------------------------- - -template<typename Lhs, typename Rhs> -struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,InnerProduct> -{ - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - dst.coeffRef(0,0) = (lhs.transpose().cwiseProduct(rhs)).sum(); - } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - dst.coeffRef(0,0) += (lhs.transpose().cwiseProduct(rhs)).sum(); - } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { dst.coeffRef(0,0) -= (lhs.transpose().cwiseProduct(rhs)).sum(); } -}; - - -/*********************************************************************** -* Implementation of outer dense * dense vector product -***********************************************************************/ - -// Column major result -template<typename Dst, typename Lhs, typename Rhs, typename Func> -void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const false_type&) -{ - evaluator<Rhs> rhsEval(rhs); - ei_declare_local_nested_eval(Lhs,lhs,Rhs::SizeAtCompileTime,actual_lhs); - // FIXME if cols is large enough, then it might be useful to make sure that lhs is sequentially stored - // FIXME not very good if rhs is real and lhs complex while alpha is real too - const Index cols = dst.cols(); - for (Index j=0; j<cols; ++j) - func(dst.col(j), rhsEval.coeff(Index(0),j) * actual_lhs); -} - -// Row major result -template<typename Dst, typename Lhs, typename Rhs, typename Func> -void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const true_type&) -{ - evaluator<Lhs> lhsEval(lhs); - ei_declare_local_nested_eval(Rhs,rhs,Lhs::SizeAtCompileTime,actual_rhs); - // FIXME if rows is large enough, then it might be useful to make sure that rhs is sequentially stored - // FIXME not very good if lhs is real and rhs complex while alpha is real too - const Index rows = dst.rows(); - for (Index i=0; i<rows; ++i) - func(dst.row(i), lhsEval.coeff(i,Index(0)) * actual_rhs); -} - -template<typename Lhs, typename Rhs> -struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,OuterProduct> -{ - template<typename T> struct is_row_major : internal::conditional<(int(T::Flags)&RowMajorBit), internal::true_type, internal::false_type>::type {}; - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - // TODO it would be nice to be able to exploit our *_assign_op functors for that purpose - struct set { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() = src; } }; - struct add { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() += src; } }; - struct sub { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() -= src; } }; - struct adds { - Scalar m_scale; - explicit adds(const Scalar& s) : m_scale(s) {} - template<typename Dst, typename Src> void EIGEN_DEVICE_FUNC operator()(const Dst& dst, const Src& src) const { - dst.const_cast_derived() += m_scale * src; - } - }; - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - internal::outer_product_selector_run(dst, lhs, rhs, set(), is_row_major<Dst>()); - } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - internal::outer_product_selector_run(dst, lhs, rhs, add(), is_row_major<Dst>()); - } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - internal::outer_product_selector_run(dst, lhs, rhs, sub(), is_row_major<Dst>()); - } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { - internal::outer_product_selector_run(dst, lhs, rhs, adds(alpha), is_row_major<Dst>()); - } - -}; - - -// This base class provides default implementations for evalTo, addTo, subTo, in terms of scaleAndAddTo -template<typename Lhs, typename Rhs, typename Derived> -struct generic_product_impl_base -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { dst.setZero(); scaleAndAddTo(dst, lhs, rhs, Scalar(1)); } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { scaleAndAddTo(dst,lhs, rhs, Scalar(1)); } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { scaleAndAddTo(dst, lhs, rhs, Scalar(-1)); } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { Derived::scaleAndAddTo(dst,lhs,rhs,alpha); } - -}; - -template<typename Lhs, typename Rhs> -struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct> - : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct> > -{ - typedef typename nested_eval<Lhs,1>::type LhsNested; - typedef typename nested_eval<Rhs,1>::type RhsNested; - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - enum { Side = Lhs::IsVectorAtCompileTime ? OnTheLeft : OnTheRight }; - typedef typename internal::remove_all<typename internal::conditional<int(Side)==OnTheRight,LhsNested,RhsNested>::type>::type MatrixType; - - template<typename Dest> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { - LhsNested actual_lhs(lhs); - RhsNested actual_rhs(rhs); - internal::gemv_dense_selector<Side, - (int(MatrixType::Flags)&RowMajorBit) ? RowMajor : ColMajor, - bool(internal::blas_traits<MatrixType>::HasUsableDirectAccess) - >::run(actual_lhs, actual_rhs, dst, alpha); - } -}; - -template<typename Lhs, typename Rhs> -struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode> -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - // Same as: dst.noalias() = lhs.lazyProduct(rhs); - // but easier on the compiler side - call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::assign_op<typename Dst::Scalar,Scalar>()); - } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - // dst.noalias() += lhs.lazyProduct(rhs); - call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::add_assign_op<typename Dst::Scalar,Scalar>()); - } - - template<typename Dst> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - // dst.noalias() -= lhs.lazyProduct(rhs); - call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::sub_assign_op<typename Dst::Scalar,Scalar>()); - } - - // This is a special evaluation path called from generic_product_impl<...,GemmProduct> in file GeneralMatrixMatrix.h - // This variant tries to extract scalar multiples from both the LHS and RHS and factor them out. For instance: - // dst {,+,-}= (s1*A)*(B*s2) - // will be rewritten as: - // dst {,+,-}= (s1*s2) * (A.lazyProduct(B)) - // There are at least four benefits of doing so: - // 1 - huge performance gain for heap-allocated matrix types as it save costly allocations. - // 2 - it is faster than simply by-passing the heap allocation through stack allocation. - // 3 - it makes this fallback consistent with the heavy GEMM routine. - // 4 - it fully by-passes huge stack allocation attempts when multiplying huge fixed-size matrices. - // (see https://stackoverflow.com/questions/54738495) - // For small fixed sizes matrices, howver, the gains are less obvious, it is sometimes x2 faster, but sometimes x3 slower, - // and the behavior depends also a lot on the compiler... This is why this re-writting strategy is currently - // enabled only when falling back from the main GEMM. - template<typename Dst, typename Func> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void eval_dynamic(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Func &func) - { - enum { - HasScalarFactor = blas_traits<Lhs>::HasScalarFactor || blas_traits<Rhs>::HasScalarFactor, - ConjLhs = blas_traits<Lhs>::NeedToConjugate, - ConjRhs = blas_traits<Rhs>::NeedToConjugate - }; - // FIXME: in c++11 this should be auto, and extractScalarFactor should also return auto - // this is important for real*complex_mat - Scalar actualAlpha = blas_traits<Lhs>::extractScalarFactor(lhs) - * blas_traits<Rhs>::extractScalarFactor(rhs); - eval_dynamic_impl(dst, - blas_traits<Lhs>::extract(lhs).template conjugateIf<ConjLhs>(), - blas_traits<Rhs>::extract(rhs).template conjugateIf<ConjRhs>(), - func, - actualAlpha, - typename conditional<HasScalarFactor,true_type,false_type>::type()); - } - -protected: - - template<typename Dst, typename LhsT, typename RhsT, typename Func, typename Scalar> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void eval_dynamic_impl(Dst& dst, const LhsT& lhs, const RhsT& rhs, const Func &func, const Scalar& s /* == 1 */, false_type) - { - EIGEN_UNUSED_VARIABLE(s); - eigen_internal_assert(s==Scalar(1)); - call_restricted_packet_assignment_no_alias(dst, lhs.lazyProduct(rhs), func); - } - - template<typename Dst, typename LhsT, typename RhsT, typename Func, typename Scalar> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void eval_dynamic_impl(Dst& dst, const LhsT& lhs, const RhsT& rhs, const Func &func, const Scalar& s, true_type) - { - call_restricted_packet_assignment_no_alias(dst, s * lhs.lazyProduct(rhs), func); - } -}; - -// This specialization enforces the use of a coefficient-based evaluation strategy -template<typename Lhs, typename Rhs> -struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,LazyCoeffBasedProductMode> - : generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode> {}; - -// Case 2: Evaluate coeff by coeff -// -// This is mostly taken from CoeffBasedProduct.h -// The main difference is that we add an extra argument to the etor_product_*_impl::run() function -// for the inner dimension of the product, because evaluator object do not know their size. - -template<int Traversal, int UnrollingIndex, typename Lhs, typename Rhs, typename RetScalar> -struct etor_product_coeff_impl; - -template<int StorageOrder, int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl; - -template<typename Lhs, typename Rhs, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, DenseShape> - : evaluator_base<Product<Lhs, Rhs, LazyProduct> > -{ - typedef Product<Lhs, Rhs, LazyProduct> XprType; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit product_evaluator(const XprType& xpr) - : m_lhs(xpr.lhs()), - m_rhs(xpr.rhs()), - m_lhsImpl(m_lhs), // FIXME the creation of the evaluator objects should result in a no-op, but check that! - m_rhsImpl(m_rhs), // Moreover, they are only useful for the packet path, so we could completely disable them when not needed, - // or perhaps declare them on the fly on the packet method... We have experiment to check what's best. - m_innerDim(xpr.lhs().cols()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::MulCost); - EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::AddCost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); -#if 0 - std::cerr << "LhsOuterStrideBytes= " << LhsOuterStrideBytes << "\n"; - std::cerr << "RhsOuterStrideBytes= " << RhsOuterStrideBytes << "\n"; - std::cerr << "LhsAlignment= " << LhsAlignment << "\n"; - std::cerr << "RhsAlignment= " << RhsAlignment << "\n"; - std::cerr << "CanVectorizeLhs= " << CanVectorizeLhs << "\n"; - std::cerr << "CanVectorizeRhs= " << CanVectorizeRhs << "\n"; - std::cerr << "CanVectorizeInner= " << CanVectorizeInner << "\n"; - std::cerr << "EvalToRowMajor= " << EvalToRowMajor << "\n"; - std::cerr << "Alignment= " << Alignment << "\n"; - std::cerr << "Flags= " << Flags << "\n"; -#endif - } - - // Everything below here is taken from CoeffBasedProduct.h - - typedef typename internal::nested_eval<Lhs,Rhs::ColsAtCompileTime>::type LhsNested; - typedef typename internal::nested_eval<Rhs,Lhs::RowsAtCompileTime>::type RhsNested; - - typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned; - typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned; - - typedef evaluator<LhsNestedCleaned> LhsEtorType; - typedef evaluator<RhsNestedCleaned> RhsEtorType; - - enum { - RowsAtCompileTime = LhsNestedCleaned::RowsAtCompileTime, - ColsAtCompileTime = RhsNestedCleaned::ColsAtCompileTime, - InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsNestedCleaned::ColsAtCompileTime, RhsNestedCleaned::RowsAtCompileTime), - MaxRowsAtCompileTime = LhsNestedCleaned::MaxRowsAtCompileTime, - MaxColsAtCompileTime = RhsNestedCleaned::MaxColsAtCompileTime - }; - - typedef typename find_best_packet<Scalar,RowsAtCompileTime>::type LhsVecPacketType; - typedef typename find_best_packet<Scalar,ColsAtCompileTime>::type RhsVecPacketType; - - enum { - - LhsCoeffReadCost = LhsEtorType::CoeffReadCost, - RhsCoeffReadCost = RhsEtorType::CoeffReadCost, - CoeffReadCost = InnerSize==0 ? NumTraits<Scalar>::ReadCost - : InnerSize == Dynamic ? HugeCost - : InnerSize * (NumTraits<Scalar>::MulCost + LhsCoeffReadCost + RhsCoeffReadCost) - + (InnerSize - 1) * NumTraits<Scalar>::AddCost, - - Unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT, - - LhsFlags = LhsEtorType::Flags, - RhsFlags = RhsEtorType::Flags, - - LhsRowMajor = LhsFlags & RowMajorBit, - RhsRowMajor = RhsFlags & RowMajorBit, - - LhsVecPacketSize = unpacket_traits<LhsVecPacketType>::size, - RhsVecPacketSize = unpacket_traits<RhsVecPacketType>::size, - - // Here, we don't care about alignment larger than the usable packet size. - LhsAlignment = EIGEN_PLAIN_ENUM_MIN(LhsEtorType::Alignment,LhsVecPacketSize*int(sizeof(typename LhsNestedCleaned::Scalar))), - RhsAlignment = EIGEN_PLAIN_ENUM_MIN(RhsEtorType::Alignment,RhsVecPacketSize*int(sizeof(typename RhsNestedCleaned::Scalar))), - - SameType = is_same<typename LhsNestedCleaned::Scalar,typename RhsNestedCleaned::Scalar>::value, - - CanVectorizeRhs = bool(RhsRowMajor) && (RhsFlags & PacketAccessBit) && (ColsAtCompileTime!=1), - CanVectorizeLhs = (!LhsRowMajor) && (LhsFlags & PacketAccessBit) && (RowsAtCompileTime!=1), - - EvalToRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1 - : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0 - : (bool(RhsRowMajor) && !CanVectorizeLhs), - - Flags = ((unsigned int)(LhsFlags | RhsFlags) & HereditaryBits & ~RowMajorBit) - | (EvalToRowMajor ? RowMajorBit : 0) - // TODO enable vectorization for mixed types - | (SameType && (CanVectorizeLhs || CanVectorizeRhs) ? PacketAccessBit : 0) - | (XprType::IsVectorAtCompileTime ? LinearAccessBit : 0), - - LhsOuterStrideBytes = int(LhsNestedCleaned::OuterStrideAtCompileTime) * int(sizeof(typename LhsNestedCleaned::Scalar)), - RhsOuterStrideBytes = int(RhsNestedCleaned::OuterStrideAtCompileTime) * int(sizeof(typename RhsNestedCleaned::Scalar)), - - Alignment = bool(CanVectorizeLhs) ? (LhsOuterStrideBytes<=0 || (int(LhsOuterStrideBytes) % EIGEN_PLAIN_ENUM_MAX(1,LhsAlignment))!=0 ? 0 : LhsAlignment) - : bool(CanVectorizeRhs) ? (RhsOuterStrideBytes<=0 || (int(RhsOuterStrideBytes) % EIGEN_PLAIN_ENUM_MAX(1,RhsAlignment))!=0 ? 0 : RhsAlignment) - : 0, - - /* CanVectorizeInner deserves special explanation. It does not affect the product flags. It is not used outside - * of Product. If the Product itself is not a packet-access expression, there is still a chance that the inner - * loop of the product might be vectorized. This is the meaning of CanVectorizeInner. Since it doesn't affect - * the Flags, it is safe to make this value depend on ActualPacketAccessBit, that doesn't affect the ABI. - */ - CanVectorizeInner = SameType - && LhsRowMajor - && (!RhsRowMajor) - && (LhsFlags & RhsFlags & ActualPacketAccessBit) - && (InnerSize % packet_traits<Scalar>::size == 0) - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index row, Index col) const - { - return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum(); - } - - /* Allow index-based non-packet access. It is impossible though to allow index-based packed access, - * which is why we don't set the LinearAccessBit. - * TODO: this seems possible when the result is a vector - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const CoeffReturnType coeff(Index index) const - { - const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? 0 : index; - const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? index : 0; - return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum(); - } - - template<int LoadMode, typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const PacketType packet(Index row, Index col) const - { - PacketType res; - typedef etor_product_packet_impl<bool(int(Flags)&RowMajorBit) ? RowMajor : ColMajor, - Unroll ? int(InnerSize) : Dynamic, - LhsEtorType, RhsEtorType, PacketType, LoadMode> PacketImpl; - PacketImpl::run(row, col, m_lhsImpl, m_rhsImpl, m_innerDim, res); - return res; - } - - template<int LoadMode, typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const PacketType packet(Index index) const - { - const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? 0 : index; - const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? index : 0; - return packet<LoadMode,PacketType>(row,col); - } - -protected: - typename internal::add_const_on_value_type<LhsNested>::type m_lhs; - typename internal::add_const_on_value_type<RhsNested>::type m_rhs; - - LhsEtorType m_lhsImpl; - RhsEtorType m_rhsImpl; - - // TODO: Get rid of m_innerDim if known at compile time - Index m_innerDim; -}; - -template<typename Lhs, typename Rhs> -struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, LazyCoeffBasedProductMode, DenseShape, DenseShape> - : product_evaluator<Product<Lhs, Rhs, LazyProduct>, CoeffBasedProductMode, DenseShape, DenseShape> -{ - typedef Product<Lhs, Rhs, DefaultProduct> XprType; - typedef Product<Lhs, Rhs, LazyProduct> BaseProduct; - typedef product_evaluator<BaseProduct, CoeffBasedProductMode, DenseShape, DenseShape> Base; - enum { - Flags = Base::Flags | EvalBeforeNestingBit - }; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit product_evaluator(const XprType& xpr) - : Base(BaseProduct(xpr.lhs(),xpr.rhs())) - {} -}; - -/**************************************** -*** Coeff based product, Packet path *** -****************************************/ - -template<int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl<RowMajor, UnrollingIndex, Lhs, Rhs, Packet, LoadMode> -{ - static EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet &res) - { - etor_product_packet_impl<RowMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs, innerDim, res); - res = pmadd(pset1<Packet>(lhs.coeff(row, Index(UnrollingIndex-1))), rhs.template packet<LoadMode,Packet>(Index(UnrollingIndex-1), col), res); - } -}; - -template<int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl<ColMajor, UnrollingIndex, Lhs, Rhs, Packet, LoadMode> -{ - static EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet &res) - { - etor_product_packet_impl<ColMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs, innerDim, res); - res = pmadd(lhs.template packet<LoadMode,Packet>(row, Index(UnrollingIndex-1)), pset1<Packet>(rhs.coeff(Index(UnrollingIndex-1), col)), res); - } -}; - -template<typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl<RowMajor, 1, Lhs, Rhs, Packet, LoadMode> -{ - static EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index /*innerDim*/, Packet &res) - { - res = pmul(pset1<Packet>(lhs.coeff(row, Index(0))),rhs.template packet<LoadMode,Packet>(Index(0), col)); - } -}; - -template<typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl<ColMajor, 1, Lhs, Rhs, Packet, LoadMode> -{ - static EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index /*innerDim*/, Packet &res) - { - res = pmul(lhs.template packet<LoadMode,Packet>(row, Index(0)), pset1<Packet>(rhs.coeff(Index(0), col))); - } -}; - -template<typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl<RowMajor, 0, Lhs, Rhs, Packet, LoadMode> -{ - static EIGEN_STRONG_INLINE void run(Index /*row*/, Index /*col*/, const Lhs& /*lhs*/, const Rhs& /*rhs*/, Index /*innerDim*/, Packet &res) - { - res = pset1<Packet>(typename unpacket_traits<Packet>::type(0)); - } -}; - -template<typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl<ColMajor, 0, Lhs, Rhs, Packet, LoadMode> -{ - static EIGEN_STRONG_INLINE void run(Index /*row*/, Index /*col*/, const Lhs& /*lhs*/, const Rhs& /*rhs*/, Index /*innerDim*/, Packet &res) - { - res = pset1<Packet>(typename unpacket_traits<Packet>::type(0)); - } -}; - -template<typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl<RowMajor, Dynamic, Lhs, Rhs, Packet, LoadMode> -{ - static EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet& res) - { - res = pset1<Packet>(typename unpacket_traits<Packet>::type(0)); - for(Index i = 0; i < innerDim; ++i) - res = pmadd(pset1<Packet>(lhs.coeff(row, i)), rhs.template packet<LoadMode,Packet>(i, col), res); - } -}; - -template<typename Lhs, typename Rhs, typename Packet, int LoadMode> -struct etor_product_packet_impl<ColMajor, Dynamic, Lhs, Rhs, Packet, LoadMode> -{ - static EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet& res) - { - res = pset1<Packet>(typename unpacket_traits<Packet>::type(0)); - for(Index i = 0; i < innerDim; ++i) - res = pmadd(lhs.template packet<LoadMode,Packet>(row, i), pset1<Packet>(rhs.coeff(i, col)), res); - } -}; - - -/*************************************************************************** -* Triangular products -***************************************************************************/ -template<int Mode, bool LhsIsTriangular, - typename Lhs, bool LhsIsVector, - typename Rhs, bool RhsIsVector> -struct triangular_product_impl; - -template<typename Lhs, typename Rhs, int ProductTag> -struct generic_product_impl<Lhs,Rhs,TriangularShape,DenseShape,ProductTag> - : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,TriangularShape,DenseShape,ProductTag> > -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - template<typename Dest> - static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { - triangular_product_impl<Lhs::Mode,true,typename Lhs::MatrixType,false,Rhs, Rhs::ColsAtCompileTime==1> - ::run(dst, lhs.nestedExpression(), rhs, alpha); - } -}; - -template<typename Lhs, typename Rhs, int ProductTag> -struct generic_product_impl<Lhs,Rhs,DenseShape,TriangularShape,ProductTag> -: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,TriangularShape,ProductTag> > -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - template<typename Dest> - static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { - triangular_product_impl<Rhs::Mode,false,Lhs,Lhs::RowsAtCompileTime==1, typename Rhs::MatrixType, false>::run(dst, lhs, rhs.nestedExpression(), alpha); - } -}; - - -/*************************************************************************** -* SelfAdjoint products -***************************************************************************/ -template <typename Lhs, int LhsMode, bool LhsIsVector, - typename Rhs, int RhsMode, bool RhsIsVector> -struct selfadjoint_product_impl; - -template<typename Lhs, typename Rhs, int ProductTag> -struct generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag> - : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag> > -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - template<typename Dest> - static EIGEN_DEVICE_FUNC - void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { - selfadjoint_product_impl<typename Lhs::MatrixType,Lhs::Mode,false,Rhs,0,Rhs::IsVectorAtCompileTime>::run(dst, lhs.nestedExpression(), rhs, alpha); - } -}; - -template<typename Lhs, typename Rhs, int ProductTag> -struct generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag> -: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag> > -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - template<typename Dest> - static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { - selfadjoint_product_impl<Lhs,0,Lhs::IsVectorAtCompileTime,typename Rhs::MatrixType,Rhs::Mode,false>::run(dst, lhs, rhs.nestedExpression(), alpha); - } -}; - - -/*************************************************************************** -* Diagonal products -***************************************************************************/ - -template<typename MatrixType, typename DiagonalType, typename Derived, int ProductOrder> -struct diagonal_product_evaluator_base - : evaluator_base<Derived> -{ - typedef typename ScalarBinaryOpTraits<typename MatrixType::Scalar, typename DiagonalType::Scalar>::ReturnType Scalar; -public: - enum { - CoeffReadCost = NumTraits<Scalar>::MulCost + evaluator<MatrixType>::CoeffReadCost + evaluator<DiagonalType>::CoeffReadCost, - - MatrixFlags = evaluator<MatrixType>::Flags, - DiagFlags = evaluator<DiagonalType>::Flags, - - _StorageOrder = (Derived::MaxRowsAtCompileTime==1 && Derived::MaxColsAtCompileTime!=1) ? RowMajor - : (Derived::MaxColsAtCompileTime==1 && Derived::MaxRowsAtCompileTime!=1) ? ColMajor - : MatrixFlags & RowMajorBit ? RowMajor : ColMajor, - _SameStorageOrder = _StorageOrder == (MatrixFlags & RowMajorBit ? RowMajor : ColMajor), - - _ScalarAccessOnDiag = !((int(_StorageOrder) == ColMajor && int(ProductOrder) == OnTheLeft) - ||(int(_StorageOrder) == RowMajor && int(ProductOrder) == OnTheRight)), - _SameTypes = is_same<typename MatrixType::Scalar, typename DiagonalType::Scalar>::value, - // FIXME currently we need same types, but in the future the next rule should be the one - //_Vectorizable = bool(int(MatrixFlags)&PacketAccessBit) && ((!_PacketOnDiag) || (_SameTypes && bool(int(DiagFlags)&PacketAccessBit))), - _Vectorizable = bool(int(MatrixFlags)&PacketAccessBit) - && _SameTypes - && (_SameStorageOrder || (MatrixFlags&LinearAccessBit)==LinearAccessBit) - && (_ScalarAccessOnDiag || (bool(int(DiagFlags)&PacketAccessBit))), - _LinearAccessMask = (MatrixType::RowsAtCompileTime==1 || MatrixType::ColsAtCompileTime==1) ? LinearAccessBit : 0, - Flags = ((HereditaryBits|_LinearAccessMask) & (unsigned int)(MatrixFlags)) | (_Vectorizable ? PacketAccessBit : 0), - Alignment = evaluator<MatrixType>::Alignment, - - AsScalarProduct = (DiagonalType::SizeAtCompileTime==1) - || (DiagonalType::SizeAtCompileTime==Dynamic && MatrixType::RowsAtCompileTime==1 && ProductOrder==OnTheLeft) - || (DiagonalType::SizeAtCompileTime==Dynamic && MatrixType::ColsAtCompileTime==1 && ProductOrder==OnTheRight) - }; - - diagonal_product_evaluator_base(const MatrixType &mat, const DiagonalType &diag) - : m_diagImpl(diag), m_matImpl(mat) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::MulCost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index idx) const - { - if(AsScalarProduct) - return m_diagImpl.coeff(0) * m_matImpl.coeff(idx); - else - return m_diagImpl.coeff(idx) * m_matImpl.coeff(idx); - } - -protected: - template<int LoadMode,typename PacketType> - EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index id, internal::true_type) const - { - return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col), - internal::pset1<PacketType>(m_diagImpl.coeff(id))); - } - - template<int LoadMode,typename PacketType> - EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index id, internal::false_type) const - { - enum { - InnerSize = (MatrixType::Flags & RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime, - DiagonalPacketLoadMode = EIGEN_PLAIN_ENUM_MIN(LoadMode,((InnerSize%16) == 0) ? int(Aligned16) : int(evaluator<DiagonalType>::Alignment)) // FIXME hardcoded 16!! - }; - return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col), - m_diagImpl.template packet<DiagonalPacketLoadMode,PacketType>(id)); - } - - evaluator<DiagonalType> m_diagImpl; - evaluator<MatrixType> m_matImpl; -}; - -// diagonal * dense -template<typename Lhs, typename Rhs, int ProductKind, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DiagonalShape, DenseShape> - : diagonal_product_evaluator_base<Rhs, typename Lhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheLeft> -{ - typedef diagonal_product_evaluator_base<Rhs, typename Lhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheLeft> Base; - using Base::m_diagImpl; - using Base::m_matImpl; - using Base::coeff; - typedef typename Base::Scalar Scalar; - - typedef Product<Lhs, Rhs, ProductKind> XprType; - typedef typename XprType::PlainObject PlainObject; - typedef typename Lhs::DiagonalVectorType DiagonalType; - - - enum { StorageOrder = Base::_StorageOrder }; - - EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) - : Base(xpr.rhs(), xpr.lhs().diagonal()) - { - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const - { - return m_diagImpl.coeff(row) * m_matImpl.coeff(row, col); - } - -#ifndef EIGEN_GPUCC - template<int LoadMode,typename PacketType> - EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const - { - // FIXME: NVCC used to complain about the template keyword, but we have to check whether this is still the case. - // See also similar calls below. - return this->template packet_impl<LoadMode,PacketType>(row,col, row, - typename internal::conditional<int(StorageOrder)==RowMajor, internal::true_type, internal::false_type>::type()); - } - - template<int LoadMode,typename PacketType> - EIGEN_STRONG_INLINE PacketType packet(Index idx) const - { - return packet<LoadMode,PacketType>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx); - } -#endif -}; - -// dense * diagonal -template<typename Lhs, typename Rhs, int ProductKind, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape, DiagonalShape> - : diagonal_product_evaluator_base<Lhs, typename Rhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheRight> -{ - typedef diagonal_product_evaluator_base<Lhs, typename Rhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheRight> Base; - using Base::m_diagImpl; - using Base::m_matImpl; - using Base::coeff; - typedef typename Base::Scalar Scalar; - - typedef Product<Lhs, Rhs, ProductKind> XprType; - typedef typename XprType::PlainObject PlainObject; - - enum { StorageOrder = Base::_StorageOrder }; - - EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) - : Base(xpr.lhs(), xpr.rhs().diagonal()) - { - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const - { - return m_matImpl.coeff(row, col) * m_diagImpl.coeff(col); - } - -#ifndef EIGEN_GPUCC - template<int LoadMode,typename PacketType> - EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const - { - return this->template packet_impl<LoadMode,PacketType>(row,col, col, - typename internal::conditional<int(StorageOrder)==ColMajor, internal::true_type, internal::false_type>::type()); - } - - template<int LoadMode,typename PacketType> - EIGEN_STRONG_INLINE PacketType packet(Index idx) const - { - return packet<LoadMode,PacketType>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx); - } -#endif -}; - -/*************************************************************************** -* Products with permutation matrices -***************************************************************************/ - -/** \internal - * \class permutation_matrix_product - * Internal helper class implementing the product between a permutation matrix and a matrix. - * This class is specialized for DenseShape below and for SparseShape in SparseCore/SparsePermutation.h - */ -template<typename ExpressionType, int Side, bool Transposed, typename ExpressionShape> -struct permutation_matrix_product; - -template<typename ExpressionType, int Side, bool Transposed> -struct permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape> -{ - typedef typename nested_eval<ExpressionType, 1>::type MatrixType; - typedef typename remove_all<MatrixType>::type MatrixTypeCleaned; - - template<typename Dest, typename PermutationType> - static inline void run(Dest& dst, const PermutationType& perm, const ExpressionType& xpr) - { - MatrixType mat(xpr); - const Index n = Side==OnTheLeft ? mat.rows() : mat.cols(); - // FIXME we need an is_same for expression that is not sensitive to constness. For instance - // is_same_xpr<Block<const Matrix>, Block<Matrix> >::value should be true. - //if(is_same<MatrixTypeCleaned,Dest>::value && extract_data(dst) == extract_data(mat)) - if(is_same_dense(dst, mat)) - { - // apply the permutation inplace - Matrix<bool,PermutationType::RowsAtCompileTime,1,0,PermutationType::MaxRowsAtCompileTime> mask(perm.size()); - mask.fill(false); - Index r = 0; - while(r < perm.size()) - { - // search for the next seed - while(r<perm.size() && mask[r]) r++; - if(r>=perm.size()) - break; - // we got one, let's follow it until we are back to the seed - Index k0 = r++; - Index kPrev = k0; - mask.coeffRef(k0) = true; - for(Index k=perm.indices().coeff(k0); k!=k0; k=perm.indices().coeff(k)) - { - Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>(dst, k) - .swap(Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime> - (dst,((Side==OnTheLeft) ^ Transposed) ? k0 : kPrev)); - - mask.coeffRef(k) = true; - kPrev = k; - } - } - } - else - { - for(Index i = 0; i < n; ++i) - { - Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime> - (dst, ((Side==OnTheLeft) ^ Transposed) ? perm.indices().coeff(i) : i) - - = - - Block<const MatrixTypeCleaned,Side==OnTheLeft ? 1 : MatrixTypeCleaned::RowsAtCompileTime,Side==OnTheRight ? 1 : MatrixTypeCleaned::ColsAtCompileTime> - (mat, ((Side==OnTheRight) ^ Transposed) ? perm.indices().coeff(i) : i); - } - } - } -}; - -template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape> -struct generic_product_impl<Lhs, Rhs, PermutationShape, MatrixShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) - { - permutation_matrix_product<Rhs, OnTheLeft, false, MatrixShape>::run(dst, lhs, rhs); - } -}; - -template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape> -struct generic_product_impl<Lhs, Rhs, MatrixShape, PermutationShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) - { - permutation_matrix_product<Lhs, OnTheRight, false, MatrixShape>::run(dst, rhs, lhs); - } -}; - -template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape> -struct generic_product_impl<Inverse<Lhs>, Rhs, PermutationShape, MatrixShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Inverse<Lhs>& lhs, const Rhs& rhs) - { - permutation_matrix_product<Rhs, OnTheLeft, true, MatrixShape>::run(dst, lhs.nestedExpression(), rhs); - } -}; - -template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape> -struct generic_product_impl<Lhs, Inverse<Rhs>, MatrixShape, PermutationShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Inverse<Rhs>& rhs) - { - permutation_matrix_product<Lhs, OnTheRight, true, MatrixShape>::run(dst, rhs.nestedExpression(), lhs); - } -}; - - -/*************************************************************************** -* Products with transpositions matrices -***************************************************************************/ - -// FIXME could we unify Transpositions and Permutation into a single "shape"?? - -/** \internal - * \class transposition_matrix_product - * Internal helper class implementing the product between a permutation matrix and a matrix. - */ -template<typename ExpressionType, int Side, bool Transposed, typename ExpressionShape> -struct transposition_matrix_product -{ - typedef typename nested_eval<ExpressionType, 1>::type MatrixType; - typedef typename remove_all<MatrixType>::type MatrixTypeCleaned; - - template<typename Dest, typename TranspositionType> - static inline void run(Dest& dst, const TranspositionType& tr, const ExpressionType& xpr) - { - MatrixType mat(xpr); - typedef typename TranspositionType::StorageIndex StorageIndex; - const Index size = tr.size(); - StorageIndex j = 0; - - if(!is_same_dense(dst,mat)) - dst = mat; - - for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k) - if(Index(j=tr.coeff(k))!=k) - { - if(Side==OnTheLeft) dst.row(k).swap(dst.row(j)); - else if(Side==OnTheRight) dst.col(k).swap(dst.col(j)); - } - } -}; - -template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape> -struct generic_product_impl<Lhs, Rhs, TranspositionsShape, MatrixShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) - { - transposition_matrix_product<Rhs, OnTheLeft, false, MatrixShape>::run(dst, lhs, rhs); - } -}; - -template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape> -struct generic_product_impl<Lhs, Rhs, MatrixShape, TranspositionsShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) - { - transposition_matrix_product<Lhs, OnTheRight, false, MatrixShape>::run(dst, rhs, lhs); - } -}; - - -template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape> -struct generic_product_impl<Transpose<Lhs>, Rhs, TranspositionsShape, MatrixShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Transpose<Lhs>& lhs, const Rhs& rhs) - { - transposition_matrix_product<Rhs, OnTheLeft, true, MatrixShape>::run(dst, lhs.nestedExpression(), rhs); - } -}; - -template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape> -struct generic_product_impl<Lhs, Transpose<Rhs>, MatrixShape, TranspositionsShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Transpose<Rhs>& rhs) - { - transposition_matrix_product<Lhs, OnTheRight, true, MatrixShape>::run(dst, rhs.nestedExpression(), lhs); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PRODUCT_EVALUATORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Random.h b/external/eigen/include/eigen3/Eigen/src/Core/Random.h deleted file mode 100644 index 486e9ed5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Random.h +++ /dev/null @@ -1,182 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_RANDOM_H -#define EIGEN_RANDOM_H - -namespace Eigen { - -namespace internal { - -template<typename Scalar> struct scalar_random_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op) - inline const Scalar operator() () const { return random<Scalar>(); } -}; - -template<typename Scalar> -struct functor_traits<scalar_random_op<Scalar> > -{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; }; - -} // end namespace internal - -/** \returns a random matrix expression - * - * Numbers are uniformly spread through their whole definition range for integer types, - * and in the [-1:1] range for floating point scalar types. - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * \not_reentrant - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so Random() should be used - * instead. - * - * - * Example: \include MatrixBase_random_int_int.cpp - * Output: \verbinclude MatrixBase_random_int_int.out - * - * This expression has the "evaluate before nesting" flag so that it will be evaluated into - * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected - * behavior with expressions involving random matrices. - * - * See DenseBase::NullaryExpr(Index, const CustomNullaryOp&) for an example using C++11 random generators. - * - * \sa DenseBase::setRandom(), DenseBase::Random(Index), DenseBase::Random() - */ -template<typename Derived> -inline const typename DenseBase<Derived>::RandomReturnType -DenseBase<Derived>::Random(Index rows, Index cols) -{ - return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>()); -} - -/** \returns a random vector expression - * - * Numbers are uniformly spread through their whole definition range for integer types, - * and in the [-1:1] range for floating point scalar types. - * - * The parameter \a size is the size of the returned vector. - * Must be compatible with this MatrixBase type. - * - * \only_for_vectors - * \not_reentrant - * - * This variant is meant to be used for dynamic-size vector types. For fixed-size types, - * it is redundant to pass \a size as argument, so Random() should be used - * instead. - * - * Example: \include MatrixBase_random_int.cpp - * Output: \verbinclude MatrixBase_random_int.out - * - * This expression has the "evaluate before nesting" flag so that it will be evaluated into - * a temporary vector whenever it is nested in a larger expression. This prevents unexpected - * behavior with expressions involving random matrices. - * - * \sa DenseBase::setRandom(), DenseBase::Random(Index,Index), DenseBase::Random() - */ -template<typename Derived> -inline const typename DenseBase<Derived>::RandomReturnType -DenseBase<Derived>::Random(Index size) -{ - return NullaryExpr(size, internal::scalar_random_op<Scalar>()); -} - -/** \returns a fixed-size random matrix or vector expression - * - * Numbers are uniformly spread through their whole definition range for integer types, - * and in the [-1:1] range for floating point scalar types. - * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you - * need to use the variants taking size arguments. - * - * Example: \include MatrixBase_random.cpp - * Output: \verbinclude MatrixBase_random.out - * - * This expression has the "evaluate before nesting" flag so that it will be evaluated into - * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected - * behavior with expressions involving random matrices. - * - * \not_reentrant - * - * \sa DenseBase::setRandom(), DenseBase::Random(Index,Index), DenseBase::Random(Index) - */ -template<typename Derived> -inline const typename DenseBase<Derived>::RandomReturnType -DenseBase<Derived>::Random() -{ - return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>()); -} - -/** Sets all coefficients in this expression to random values. - * - * Numbers are uniformly spread through their whole definition range for integer types, - * and in the [-1:1] range for floating point scalar types. - * - * \not_reentrant - * - * Example: \include MatrixBase_setRandom.cpp - * Output: \verbinclude MatrixBase_setRandom.out - * - * \sa class CwiseNullaryOp, setRandom(Index), setRandom(Index,Index) - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline Derived& DenseBase<Derived>::setRandom() -{ - return *this = Random(rows(), cols()); -} - -/** Resizes to the given \a newSize, and sets all coefficients in this expression to random values. - * - * Numbers are uniformly spread through their whole definition range for integer types, - * and in the [-1:1] range for floating point scalar types. - * - * \only_for_vectors - * \not_reentrant - * - * Example: \include Matrix_setRandom_int.cpp - * Output: \verbinclude Matrix_setRandom_int.out - * - * \sa DenseBase::setRandom(), setRandom(Index,Index), class CwiseNullaryOp, DenseBase::Random() - */ -template<typename Derived> -EIGEN_STRONG_INLINE Derived& -PlainObjectBase<Derived>::setRandom(Index newSize) -{ - resize(newSize); - return setRandom(); -} - -/** Resizes to the given size, and sets all coefficients in this expression to random values. - * - * Numbers are uniformly spread through their whole definition range for integer types, - * and in the [-1:1] range for floating point scalar types. - * - * \not_reentrant - * - * \param rows the new number of rows - * \param cols the new number of columns - * - * Example: \include Matrix_setRandom_int_int.cpp - * Output: \verbinclude Matrix_setRandom_int_int.out - * - * \sa DenseBase::setRandom(), setRandom(Index), class CwiseNullaryOp, DenseBase::Random() - */ -template<typename Derived> -EIGEN_STRONG_INLINE Derived& -PlainObjectBase<Derived>::setRandom(Index rows, Index cols) -{ - resize(rows, cols); - return setRandom(); -} - -} // end namespace Eigen - -#endif // EIGEN_RANDOM_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Redux.h b/external/eigen/include/eigen3/Eigen/src/Core/Redux.h deleted file mode 100644 index 2eef5abc..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Redux.h +++ /dev/null @@ -1,507 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_REDUX_H -#define EIGEN_REDUX_H - -namespace Eigen { - -namespace internal { - -// TODO -// * implement other kind of vectorization -// * factorize code - -/*************************************************************************** -* Part 1 : the logic deciding a strategy for vectorization and unrolling -***************************************************************************/ - -template<typename Func, typename Evaluator> -struct redux_traits -{ -public: - typedef typename find_best_packet<typename Evaluator::Scalar,Evaluator::SizeAtCompileTime>::type PacketType; - enum { - PacketSize = unpacket_traits<PacketType>::size, - InnerMaxSize = int(Evaluator::IsRowMajor) - ? Evaluator::MaxColsAtCompileTime - : Evaluator::MaxRowsAtCompileTime, - OuterMaxSize = int(Evaluator::IsRowMajor) - ? Evaluator::MaxRowsAtCompileTime - : Evaluator::MaxColsAtCompileTime, - SliceVectorizedWork = int(InnerMaxSize)==Dynamic ? Dynamic - : int(OuterMaxSize)==Dynamic ? (int(InnerMaxSize)>=int(PacketSize) ? Dynamic : 0) - : (int(InnerMaxSize)/int(PacketSize)) * int(OuterMaxSize) - }; - - enum { - MightVectorize = (int(Evaluator::Flags)&ActualPacketAccessBit) - && (functor_traits<Func>::PacketAccess), - MayLinearVectorize = bool(MightVectorize) && (int(Evaluator::Flags)&LinearAccessBit), - MaySliceVectorize = bool(MightVectorize) && (int(SliceVectorizedWork)==Dynamic || int(SliceVectorizedWork)>=3) - }; - -public: - enum { - Traversal = int(MayLinearVectorize) ? int(LinearVectorizedTraversal) - : int(MaySliceVectorize) ? int(SliceVectorizedTraversal) - : int(DefaultTraversal) - }; - -public: - enum { - Cost = Evaluator::SizeAtCompileTime == Dynamic ? HugeCost - : Evaluator::SizeAtCompileTime * Evaluator::CoeffReadCost + (Evaluator::SizeAtCompileTime-1) * functor_traits<Func>::Cost, - UnrollingLimit = EIGEN_UNROLLING_LIMIT * (int(Traversal) == int(DefaultTraversal) ? 1 : int(PacketSize)) - }; - -public: - enum { - Unrolling = Cost <= UnrollingLimit ? CompleteUnrolling : NoUnrolling - }; - -#ifdef EIGEN_DEBUG_ASSIGN - static void debug() - { - std::cerr << "Xpr: " << typeid(typename Evaluator::XprType).name() << std::endl; - std::cerr.setf(std::ios::hex, std::ios::basefield); - EIGEN_DEBUG_VAR(Evaluator::Flags) - std::cerr.unsetf(std::ios::hex); - EIGEN_DEBUG_VAR(InnerMaxSize) - EIGEN_DEBUG_VAR(OuterMaxSize) - EIGEN_DEBUG_VAR(SliceVectorizedWork) - EIGEN_DEBUG_VAR(PacketSize) - EIGEN_DEBUG_VAR(MightVectorize) - EIGEN_DEBUG_VAR(MayLinearVectorize) - EIGEN_DEBUG_VAR(MaySliceVectorize) - std::cerr << "Traversal" << " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl; - EIGEN_DEBUG_VAR(UnrollingLimit) - std::cerr << "Unrolling" << " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl; - std::cerr << std::endl; - } -#endif -}; - -/*************************************************************************** -* Part 2 : unrollers -***************************************************************************/ - -/*** no vectorization ***/ - -template<typename Func, typename Evaluator, int Start, int Length> -struct redux_novec_unroller -{ - enum { - HalfLength = Length/2 - }; - - typedef typename Evaluator::Scalar Scalar; - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Evaluator &eval, const Func& func) - { - return func(redux_novec_unroller<Func, Evaluator, Start, HalfLength>::run(eval,func), - redux_novec_unroller<Func, Evaluator, Start+HalfLength, Length-HalfLength>::run(eval,func)); - } -}; - -template<typename Func, typename Evaluator, int Start> -struct redux_novec_unroller<Func, Evaluator, Start, 1> -{ - enum { - outer = Start / Evaluator::InnerSizeAtCompileTime, - inner = Start % Evaluator::InnerSizeAtCompileTime - }; - - typedef typename Evaluator::Scalar Scalar; - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Evaluator &eval, const Func&) - { - return eval.coeffByOuterInner(outer, inner); - } -}; - -// This is actually dead code and will never be called. It is required -// to prevent false warnings regarding failed inlining though -// for 0 length run() will never be called at all. -template<typename Func, typename Evaluator, int Start> -struct redux_novec_unroller<Func, Evaluator, Start, 0> -{ - typedef typename Evaluator::Scalar Scalar; - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Evaluator&, const Func&) { return Scalar(); } -}; - -/*** vectorization ***/ - -template<typename Func, typename Evaluator, int Start, int Length> -struct redux_vec_unroller -{ - template<typename PacketType> - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE PacketType run(const Evaluator &eval, const Func& func) - { - enum { - PacketSize = unpacket_traits<PacketType>::size, - HalfLength = Length/2 - }; - - return func.packetOp( - redux_vec_unroller<Func, Evaluator, Start, HalfLength>::template run<PacketType>(eval,func), - redux_vec_unroller<Func, Evaluator, Start+HalfLength, Length-HalfLength>::template run<PacketType>(eval,func) ); - } -}; - -template<typename Func, typename Evaluator, int Start> -struct redux_vec_unroller<Func, Evaluator, Start, 1> -{ - template<typename PacketType> - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE PacketType run(const Evaluator &eval, const Func&) - { - enum { - PacketSize = unpacket_traits<PacketType>::size, - index = Start * PacketSize, - outer = index / int(Evaluator::InnerSizeAtCompileTime), - inner = index % int(Evaluator::InnerSizeAtCompileTime), - alignment = Evaluator::Alignment - }; - return eval.template packetByOuterInner<alignment,PacketType>(outer, inner); - } -}; - -/*************************************************************************** -* Part 3 : implementation of all cases -***************************************************************************/ - -template<typename Func, typename Evaluator, - int Traversal = redux_traits<Func, Evaluator>::Traversal, - int Unrolling = redux_traits<Func, Evaluator>::Unrolling -> -struct redux_impl; - -template<typename Func, typename Evaluator> -struct redux_impl<Func, Evaluator, DefaultTraversal, NoUnrolling> -{ - typedef typename Evaluator::Scalar Scalar; - - template<typename XprType> - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE - Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr) - { - eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix"); - Scalar res; - res = eval.coeffByOuterInner(0, 0); - for(Index i = 1; i < xpr.innerSize(); ++i) - res = func(res, eval.coeffByOuterInner(0, i)); - for(Index i = 1; i < xpr.outerSize(); ++i) - for(Index j = 0; j < xpr.innerSize(); ++j) - res = func(res, eval.coeffByOuterInner(i, j)); - return res; - } -}; - -template<typename Func, typename Evaluator> -struct redux_impl<Func,Evaluator, DefaultTraversal, CompleteUnrolling> - : redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime> -{ - typedef redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime> Base; - typedef typename Evaluator::Scalar Scalar; - template<typename XprType> - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE - Scalar run(const Evaluator &eval, const Func& func, const XprType& /*xpr*/) - { - return Base::run(eval,func); - } -}; - -template<typename Func, typename Evaluator> -struct redux_impl<Func, Evaluator, LinearVectorizedTraversal, NoUnrolling> -{ - typedef typename Evaluator::Scalar Scalar; - typedef typename redux_traits<Func, Evaluator>::PacketType PacketScalar; - - template<typename XprType> - static Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr) - { - const Index size = xpr.size(); - - const Index packetSize = redux_traits<Func, Evaluator>::PacketSize; - const int packetAlignment = unpacket_traits<PacketScalar>::alignment; - enum { - alignment0 = (bool(Evaluator::Flags & DirectAccessBit) && bool(packet_traits<Scalar>::AlignedOnScalar)) ? int(packetAlignment) : int(Unaligned), - alignment = EIGEN_PLAIN_ENUM_MAX(alignment0, Evaluator::Alignment) - }; - const Index alignedStart = internal::first_default_aligned(xpr); - const Index alignedSize2 = ((size-alignedStart)/(2*packetSize))*(2*packetSize); - const Index alignedSize = ((size-alignedStart)/(packetSize))*(packetSize); - const Index alignedEnd2 = alignedStart + alignedSize2; - const Index alignedEnd = alignedStart + alignedSize; - Scalar res; - if(alignedSize) - { - PacketScalar packet_res0 = eval.template packet<alignment,PacketScalar>(alignedStart); - if(alignedSize>packetSize) // we have at least two packets to partly unroll the loop - { - PacketScalar packet_res1 = eval.template packet<alignment,PacketScalar>(alignedStart+packetSize); - for(Index index = alignedStart + 2*packetSize; index < alignedEnd2; index += 2*packetSize) - { - packet_res0 = func.packetOp(packet_res0, eval.template packet<alignment,PacketScalar>(index)); - packet_res1 = func.packetOp(packet_res1, eval.template packet<alignment,PacketScalar>(index+packetSize)); - } - - packet_res0 = func.packetOp(packet_res0,packet_res1); - if(alignedEnd>alignedEnd2) - packet_res0 = func.packetOp(packet_res0, eval.template packet<alignment,PacketScalar>(alignedEnd2)); - } - res = func.predux(packet_res0); - - for(Index index = 0; index < alignedStart; ++index) - res = func(res,eval.coeff(index)); - - for(Index index = alignedEnd; index < size; ++index) - res = func(res,eval.coeff(index)); - } - else // too small to vectorize anything. - // since this is dynamic-size hence inefficient anyway for such small sizes, don't try to optimize. - { - res = eval.coeff(0); - for(Index index = 1; index < size; ++index) - res = func(res,eval.coeff(index)); - } - - return res; - } -}; - -// NOTE: for SliceVectorizedTraversal we simply bypass unrolling -template<typename Func, typename Evaluator, int Unrolling> -struct redux_impl<Func, Evaluator, SliceVectorizedTraversal, Unrolling> -{ - typedef typename Evaluator::Scalar Scalar; - typedef typename redux_traits<Func, Evaluator>::PacketType PacketType; - - template<typename XprType> - EIGEN_DEVICE_FUNC static Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr) - { - eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix"); - const Index innerSize = xpr.innerSize(); - const Index outerSize = xpr.outerSize(); - enum { - packetSize = redux_traits<Func, Evaluator>::PacketSize - }; - const Index packetedInnerSize = ((innerSize)/packetSize)*packetSize; - Scalar res; - if(packetedInnerSize) - { - PacketType packet_res = eval.template packet<Unaligned,PacketType>(0,0); - for(Index j=0; j<outerSize; ++j) - for(Index i=(j==0?packetSize:0); i<packetedInnerSize; i+=Index(packetSize)) - packet_res = func.packetOp(packet_res, eval.template packetByOuterInner<Unaligned,PacketType>(j,i)); - - res = func.predux(packet_res); - for(Index j=0; j<outerSize; ++j) - for(Index i=packetedInnerSize; i<innerSize; ++i) - res = func(res, eval.coeffByOuterInner(j,i)); - } - else // too small to vectorize anything. - // since this is dynamic-size hence inefficient anyway for such small sizes, don't try to optimize. - { - res = redux_impl<Func, Evaluator, DefaultTraversal, NoUnrolling>::run(eval, func, xpr); - } - - return res; - } -}; - -template<typename Func, typename Evaluator> -struct redux_impl<Func, Evaluator, LinearVectorizedTraversal, CompleteUnrolling> -{ - typedef typename Evaluator::Scalar Scalar; - - typedef typename redux_traits<Func, Evaluator>::PacketType PacketType; - enum { - PacketSize = redux_traits<Func, Evaluator>::PacketSize, - Size = Evaluator::SizeAtCompileTime, - VectorizedSize = (Size / PacketSize) * PacketSize - }; - - template<typename XprType> - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE - Scalar run(const Evaluator &eval, const Func& func, const XprType &xpr) - { - EIGEN_ONLY_USED_FOR_DEBUG(xpr) - eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix"); - if (VectorizedSize > 0) { - Scalar res = func.predux(redux_vec_unroller<Func, Evaluator, 0, Size / PacketSize>::template run<PacketType>(eval,func)); - if (VectorizedSize != Size) - res = func(res,redux_novec_unroller<Func, Evaluator, VectorizedSize, Size-VectorizedSize>::run(eval,func)); - return res; - } - else { - return redux_novec_unroller<Func, Evaluator, 0, Size>::run(eval,func); - } - } -}; - -// evaluator adaptor -template<typename _XprType> -class redux_evaluator : public internal::evaluator<_XprType> -{ - typedef internal::evaluator<_XprType> Base; -public: - typedef _XprType XprType; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit redux_evaluator(const XprType &xpr) : Base(xpr) {} - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename XprType::PacketScalar PacketScalar; - - enum { - MaxRowsAtCompileTime = XprType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = XprType::MaxColsAtCompileTime, - // TODO we should not remove DirectAccessBit and rather find an elegant way to query the alignment offset at runtime from the evaluator - Flags = Base::Flags & ~DirectAccessBit, - IsRowMajor = XprType::IsRowMajor, - SizeAtCompileTime = XprType::SizeAtCompileTime, - InnerSizeAtCompileTime = XprType::InnerSizeAtCompileTime - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - CoeffReturnType coeffByOuterInner(Index outer, Index inner) const - { return Base::coeff(IsRowMajor ? outer : inner, IsRowMajor ? inner : outer); } - - template<int LoadMode, typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketType packetByOuterInner(Index outer, Index inner) const - { return Base::template packet<LoadMode,PacketType>(IsRowMajor ? outer : inner, IsRowMajor ? inner : outer); } - -}; - -} // end namespace internal - -/*************************************************************************** -* Part 4 : public API -***************************************************************************/ - - -/** \returns the result of a full redux operation on the whole matrix or vector using \a func - * - * The template parameter \a BinaryOp is the type of the functor \a func which must be - * an associative operator. Both current C++98 and C++11 functor styles are handled. - * - * \warning the matrix must be not empty, otherwise an assertion is triggered. - * - * \sa DenseBase::sum(), DenseBase::minCoeff(), DenseBase::maxCoeff(), MatrixBase::colwise(), MatrixBase::rowwise() - */ -template<typename Derived> -template<typename Func> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar -DenseBase<Derived>::redux(const Func& func) const -{ - eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix"); - - typedef typename internal::redux_evaluator<Derived> ThisEvaluator; - ThisEvaluator thisEval(derived()); - - // The initial expression is passed to the reducer as an additional argument instead of - // passing it as a member of redux_evaluator to help - return internal::redux_impl<Func, ThisEvaluator>::run(thisEval, func, derived()); -} - -/** \returns the minimum of all coefficients of \c *this. - * \warning the matrix must be not empty, otherwise an assertion is triggered. - * \warning the result is undefined if \c *this contains NaN. - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar -DenseBase<Derived>::minCoeff() const -{ - return derived().redux(Eigen::internal::scalar_min_op<Scalar,Scalar>()); -} - -/** \returns the maximum of all coefficients of \c *this. - * \warning the matrix must be not empty, otherwise an assertion is triggered. - * \warning the result is undefined if \c *this contains NaN. - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar -DenseBase<Derived>::maxCoeff() const -{ - return derived().redux(Eigen::internal::scalar_max_op<Scalar,Scalar>()); -} - -/** \returns the sum of all coefficients of \c *this - * - * If \c *this is empty, then the value 0 is returned. - * - * \sa trace(), prod(), mean() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar -DenseBase<Derived>::sum() const -{ - if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0)) - return Scalar(0); - return derived().redux(Eigen::internal::scalar_sum_op<Scalar,Scalar>()); -} - -/** \returns the mean of all coefficients of *this -* -* \sa trace(), prod(), sum() -*/ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar -DenseBase<Derived>::mean() const -{ -#ifdef __INTEL_COMPILER - #pragma warning push - #pragma warning ( disable : 2259 ) -#endif - return Scalar(derived().redux(Eigen::internal::scalar_sum_op<Scalar,Scalar>())) / Scalar(this->size()); -#ifdef __INTEL_COMPILER - #pragma warning pop -#endif -} - -/** \returns the product of all coefficients of *this - * - * Example: \include MatrixBase_prod.cpp - * Output: \verbinclude MatrixBase_prod.out - * - * \sa sum(), mean(), trace() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar -DenseBase<Derived>::prod() const -{ - if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0)) - return Scalar(1); - return derived().redux(Eigen::internal::scalar_product_op<Scalar>()); -} - -/** \returns the trace of \c *this, i.e. the sum of the coefficients on the main diagonal. - * - * \c *this can be any matrix, not necessarily square. - * - * \sa diagonal(), sum() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar -MatrixBase<Derived>::trace() const -{ - return derived().diagonal().sum(); -} - -} // end namespace Eigen - -#endif // EIGEN_REDUX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Ref.h b/external/eigen/include/eigen3/Eigen/src/Core/Ref.h deleted file mode 100644 index 172c8ffb..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Ref.h +++ /dev/null @@ -1,286 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_REF_H -#define EIGEN_REF_H - -namespace Eigen { - -namespace internal { - -template<typename _PlainObjectType, int _Options, typename _StrideType> -struct traits<Ref<_PlainObjectType, _Options, _StrideType> > - : public traits<Map<_PlainObjectType, _Options, _StrideType> > -{ - typedef _PlainObjectType PlainObjectType; - typedef _StrideType StrideType; - enum { - Options = _Options, - Flags = traits<Map<_PlainObjectType, _Options, _StrideType> >::Flags | NestByRefBit, - Alignment = traits<Map<_PlainObjectType, _Options, _StrideType> >::Alignment - }; - - template<typename Derived> struct match { - enum { - IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime, - HasDirectAccess = internal::has_direct_access<Derived>::ret, - StorageOrderMatch = IsVectorAtCompileTime || ((PlainObjectType::Flags&RowMajorBit)==(Derived::Flags&RowMajorBit)), - InnerStrideMatch = int(StrideType::InnerStrideAtCompileTime)==int(Dynamic) - || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime) - || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1), - OuterStrideMatch = IsVectorAtCompileTime - || int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime), - // NOTE, this indirection of evaluator<Derived>::Alignment is needed - // to workaround a very strange bug in MSVC related to the instantiation - // of has_*ary_operator in evaluator<CwiseNullaryOp>. - // This line is surprisingly very sensitive. For instance, simply adding parenthesis - // as "DerivedAlignment = (int(evaluator<Derived>::Alignment))," will make MSVC fail... - DerivedAlignment = int(evaluator<Derived>::Alignment), - AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(Unaligned)) || (DerivedAlignment >= int(Alignment)), // FIXME the first condition is not very clear, it should be replaced by the required alignment - ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value, - MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch - }; - typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type; - }; - -}; - -template<typename Derived> -struct traits<RefBase<Derived> > : public traits<Derived> {}; - -} - -template<typename Derived> class RefBase - : public MapBase<Derived> -{ - typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType; - typedef typename internal::traits<Derived>::StrideType StrideType; - -public: - - typedef MapBase<Derived> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(RefBase) - - EIGEN_DEVICE_FUNC inline Index innerStride() const - { - return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1; - } - - EIGEN_DEVICE_FUNC inline Index outerStride() const - { - return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer() - : IsVectorAtCompileTime ? this->size() - : int(Flags)&RowMajorBit ? this->cols() - : this->rows(); - } - - EIGEN_DEVICE_FUNC RefBase() - : Base(0,RowsAtCompileTime==Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==Dynamic?0:ColsAtCompileTime), - // Stride<> does not allow default ctor for Dynamic strides, so let' initialize it with dummy values: - m_stride(StrideType::OuterStrideAtCompileTime==Dynamic?0:StrideType::OuterStrideAtCompileTime, - StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime) - {} - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase) - -protected: - - typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase; - - template<typename Expression> - EIGEN_DEVICE_FUNC void construct(Expression& expr) - { - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(PlainObjectType,Expression); - - if(PlainObjectType::RowsAtCompileTime==1) - { - eigen_assert(expr.rows()==1 || expr.cols()==1); - ::new (static_cast<Base*>(this)) Base(expr.data(), 1, expr.size()); - } - else if(PlainObjectType::ColsAtCompileTime==1) - { - eigen_assert(expr.rows()==1 || expr.cols()==1); - ::new (static_cast<Base*>(this)) Base(expr.data(), expr.size(), 1); - } - else - ::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols()); - - if(Expression::IsVectorAtCompileTime && (!PlainObjectType::IsVectorAtCompileTime) && ((Expression::Flags&RowMajorBit)!=(PlainObjectType::Flags&RowMajorBit))) - ::new (&m_stride) StrideBase(expr.innerStride(), StrideType::InnerStrideAtCompileTime==0?0:1); - else - ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(), - StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride()); - } - - StrideBase m_stride; -}; - -/** \class Ref - * \ingroup Core_Module - * - * \brief A matrix or vector expression mapping an existing expression - * - * \tparam PlainObjectType the equivalent matrix type of the mapped data - * \tparam Options specifies the pointer alignment in bytes. It can be: \c #Aligned128, , \c #Aligned64, \c #Aligned32, \c #Aligned16, \c #Aligned8 or \c #Unaligned. - * The default is \c #Unaligned. - * \tparam StrideType optionally specifies strides. By default, Ref implies a contiguous storage along the inner dimension (inner stride==1), - * but accepts a variable outer stride (leading dimension). - * This can be overridden by specifying strides. - * The type passed here must be a specialization of the Stride template, see examples below. - * - * This class provides a way to write non-template functions taking Eigen objects as parameters while limiting the number of copies. - * A Ref<> object can represent either a const expression or a l-value: - * \code - * // in-out argument: - * void foo1(Ref<VectorXf> x); - * - * // read-only const argument: - * void foo2(const Ref<const VectorXf>& x); - * \endcode - * - * In the in-out case, the input argument must satisfy the constraints of the actual Ref<> type, otherwise a compilation issue will be triggered. - * By default, a Ref<VectorXf> can reference any dense vector expression of float having a contiguous memory layout. - * Likewise, a Ref<MatrixXf> can reference any column-major dense matrix expression of float whose column's elements are contiguously stored with - * the possibility to have a constant space in-between each column, i.e. the inner stride must be equal to 1, but the outer stride (or leading dimension) - * can be greater than the number of rows. - * - * In the const case, if the input expression does not match the above requirement, then it is evaluated into a temporary before being passed to the function. - * Here are some examples: - * \code - * MatrixXf A; - * VectorXf a; - * foo1(a.head()); // OK - * foo1(A.col()); // OK - * foo1(A.row()); // Compilation error because here innerstride!=1 - * foo2(A.row()); // Compilation error because A.row() is a 1xN object while foo2 is expecting a Nx1 object - * foo2(A.row().transpose()); // The row is copied into a contiguous temporary - * foo2(2*a); // The expression is evaluated into a temporary - * foo2(A.col().segment(2,4)); // No temporary - * \endcode - * - * The range of inputs that can be referenced without temporary can be enlarged using the last two template parameters. - * Here is an example accepting an innerstride!=1: - * \code - * // in-out argument: - * void foo3(Ref<VectorXf,0,InnerStride<> > x); - * foo3(A.row()); // OK - * \endcode - * The downside here is that the function foo3 might be significantly slower than foo1 because it won't be able to exploit vectorization, and will involve more - * expensive address computations even if the input is contiguously stored in memory. To overcome this issue, one might propose to overload internally calling a - * template function, e.g.: - * \code - * // in the .h: - * void foo(const Ref<MatrixXf>& A); - * void foo(const Ref<MatrixXf,0,Stride<> >& A); - * - * // in the .cpp: - * template<typename TypeOfA> void foo_impl(const TypeOfA& A) { - * ... // crazy code goes here - * } - * void foo(const Ref<MatrixXf>& A) { foo_impl(A); } - * void foo(const Ref<MatrixXf,0,Stride<> >& A) { foo_impl(A); } - * \endcode - * - * See also the following stackoverflow questions for further references: - * - <a href="http://stackoverflow.com/questions/21132538/correct-usage-of-the-eigenref-class">Correct usage of the Eigen::Ref<> class</a> - * - * \sa PlainObjectBase::Map(), \ref TopicStorageOrders - */ -template<typename PlainObjectType, int Options, typename StrideType> class Ref - : public RefBase<Ref<PlainObjectType, Options, StrideType> > -{ - private: - typedef internal::traits<Ref> Traits; - template<typename Derived> - EIGEN_DEVICE_FUNC inline Ref(const PlainObjectBase<Derived>& expr, - typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0); - public: - - typedef RefBase<Ref> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Ref) - - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename Derived> - EIGEN_DEVICE_FUNC inline Ref(PlainObjectBase<Derived>& expr, - typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0) - { - EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); - Base::construct(expr.derived()); - } - template<typename Derived> - EIGEN_DEVICE_FUNC inline Ref(const DenseBase<Derived>& expr, - typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0) - #else - /** Implicit constructor from any dense expression */ - template<typename Derived> - inline Ref(DenseBase<Derived>& expr) - #endif - { - EIGEN_STATIC_ASSERT(bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); - EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); - EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); - Base::construct(expr.const_cast_derived()); - } - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref) - -}; - -// this is the const ref version -template<typename TPlainObjectType, int Options, typename StrideType> class Ref<const TPlainObjectType, Options, StrideType> - : public RefBase<Ref<const TPlainObjectType, Options, StrideType> > -{ - typedef internal::traits<Ref> Traits; - public: - - typedef RefBase<Ref> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Ref) - - template<typename Derived> - EIGEN_DEVICE_FUNC inline Ref(const DenseBase<Derived>& expr, - typename internal::enable_if<bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>::type* = 0) - { -// std::cout << match_helper<Derived>::HasDirectAccess << "," << match_helper<Derived>::OuterStrideMatch << "," << match_helper<Derived>::InnerStrideMatch << "\n"; -// std::cout << int(StrideType::OuterStrideAtCompileTime) << " - " << int(Derived::OuterStrideAtCompileTime) << "\n"; -// std::cout << int(StrideType::InnerStrideAtCompileTime) << " - " << int(Derived::InnerStrideAtCompileTime) << "\n"; - construct(expr.derived(), typename Traits::template match<Derived>::type()); - } - - EIGEN_DEVICE_FUNC inline Ref(const Ref& other) : Base(other) { - // copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy - } - - template<typename OtherRef> - EIGEN_DEVICE_FUNC inline Ref(const RefBase<OtherRef>& other) { - construct(other.derived(), typename Traits::template match<OtherRef>::type()); - } - - protected: - - template<typename Expression> - EIGEN_DEVICE_FUNC void construct(const Expression& expr,internal::true_type) - { - Base::construct(expr); - } - - template<typename Expression> - EIGEN_DEVICE_FUNC void construct(const Expression& expr, internal::false_type) - { - internal::call_assignment_no_alias(m_object,expr,internal::assign_op<Scalar,Scalar>()); - Base::construct(m_object); - } - - protected: - TPlainObjectType m_object; -}; - -} // end namespace Eigen - -#endif // EIGEN_REF_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Replicate.h b/external/eigen/include/eigen3/Eigen/src/Core/Replicate.h deleted file mode 100644 index 0b2d6d74..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Replicate.h +++ /dev/null @@ -1,142 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_REPLICATE_H -#define EIGEN_REPLICATE_H - -namespace Eigen { - -namespace internal { -template<typename MatrixType,int RowFactor,int ColFactor> -struct traits<Replicate<MatrixType,RowFactor,ColFactor> > - : traits<MatrixType> -{ - typedef typename MatrixType::Scalar Scalar; - typedef typename traits<MatrixType>::StorageKind StorageKind; - typedef typename traits<MatrixType>::XprKind XprKind; - typedef typename ref_selector<MatrixType>::type MatrixTypeNested; - typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested; - enum { - RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic - ? Dynamic - : RowFactor * MatrixType::RowsAtCompileTime, - ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic - ? Dynamic - : ColFactor * MatrixType::ColsAtCompileTime, - //FIXME we don't propagate the max sizes !!! - MaxRowsAtCompileTime = RowsAtCompileTime, - MaxColsAtCompileTime = ColsAtCompileTime, - IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1 - : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0 - : (MatrixType::Flags & RowMajorBit) ? 1 : 0, - - // FIXME enable DirectAccess with negative strides? - Flags = IsRowMajor ? RowMajorBit : 0 - }; -}; -} - -/** - * \class Replicate - * \ingroup Core_Module - * - * \brief Expression of the multiple replication of a matrix or vector - * - * \tparam MatrixType the type of the object we are replicating - * \tparam RowFactor number of repetitions at compile time along the vertical direction, can be Dynamic. - * \tparam ColFactor number of repetitions at compile time along the horizontal direction, can be Dynamic. - * - * This class represents an expression of the multiple replication of a matrix or vector. - * It is the return type of DenseBase::replicate() and most of the time - * this is the only way it is used. - * - * \sa DenseBase::replicate() - */ -template<typename MatrixType,int RowFactor,int ColFactor> class Replicate - : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type -{ - typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested; - typedef typename internal::traits<Replicate>::_MatrixTypeNested _MatrixTypeNested; - public: - - typedef typename internal::dense_xpr_base<Replicate>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Replicate) - typedef typename internal::remove_all<MatrixType>::type NestedExpression; - - template<typename OriginalMatrixType> - EIGEN_DEVICE_FUNC - inline explicit Replicate(const OriginalMatrixType& matrix) - : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor) - { - EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value), - THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) - eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic); - } - - template<typename OriginalMatrixType> - EIGEN_DEVICE_FUNC - inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor) - : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) - { - EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value), - THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) - } - - EIGEN_DEVICE_FUNC - inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); } - EIGEN_DEVICE_FUNC - inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); } - - EIGEN_DEVICE_FUNC - const _MatrixTypeNested& nestedExpression() const - { - return m_matrix; - } - - protected: - MatrixTypeNested m_matrix; - const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor; - const internal::variable_if_dynamic<Index, ColFactor> m_colFactor; -}; - -/** - * \return an expression of the replication of \c *this - * - * Example: \include MatrixBase_replicate.cpp - * Output: \verbinclude MatrixBase_replicate.out - * - * \sa VectorwiseOp::replicate(), DenseBase::replicate(Index,Index), class Replicate - */ -template<typename Derived> -template<int RowFactor, int ColFactor> -EIGEN_DEVICE_FUNC const Replicate<Derived,RowFactor,ColFactor> -DenseBase<Derived>::replicate() const -{ - return Replicate<Derived,RowFactor,ColFactor>(derived()); -} - -/** - * \return an expression of the replication of each column (or row) of \c *this - * - * Example: \include DirectionWise_replicate_int.cpp - * Output: \verbinclude DirectionWise_replicate_int.out - * - * \sa VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate - */ -template<typename ExpressionType, int Direction> -EIGEN_DEVICE_FUNC const typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType -VectorwiseOp<ExpressionType,Direction>::replicate(Index factor) const -{ - return typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType - (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1); -} - -} // end namespace Eigen - -#endif // EIGEN_REPLICATE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Reshaped.h b/external/eigen/include/eigen3/Eigen/src/Core/Reshaped.h deleted file mode 100644 index a78fd880..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Reshaped.h +++ /dev/null @@ -1,453 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2014 yoco <peter.xiau@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_RESHAPED_H -#define EIGEN_RESHAPED_H - -namespace Eigen { -namespace internal { - -/** \class Reshaped - * \ingroup Core_Module - * - * \brief Expression of a fixed-size or dynamic-size reshape - * - * \tparam XprType the type of the expression in which we are taking a reshape - * \tparam Rows the number of rows of the reshape we are taking at compile time (optional) - * \tparam Cols the number of columns of the reshape we are taking at compile time (optional) - * \tparam Order can be ColMajor or RowMajor, default is ColMajor. - * - * This class represents an expression of either a fixed-size or dynamic-size reshape. - * It is the return type of DenseBase::reshaped(NRowsType,NColsType) and - * most of the time this is the only way it is used. - * - * However, in C++98, if you want to directly maniputate reshaped expressions, - * for instance if you want to write a function returning such an expression, you - * will need to use this class. In C++11, it is advised to use the \em auto - * keyword for such use cases. - * - * Here is an example illustrating the dynamic case: - * \include class_Reshaped.cpp - * Output: \verbinclude class_Reshaped.out - * - * Here is an example illustrating the fixed-size case: - * \include class_FixedReshaped.cpp - * Output: \verbinclude class_FixedReshaped.out - * - * \sa DenseBase::reshaped(NRowsType,NColsType) - */ - -template<typename XprType, int Rows, int Cols, int Order> -struct traits<Reshaped<XprType, Rows, Cols, Order> > : traits<XprType> -{ - typedef typename traits<XprType>::Scalar Scalar; - typedef typename traits<XprType>::StorageKind StorageKind; - typedef typename traits<XprType>::XprKind XprKind; - enum{ - MatrixRows = traits<XprType>::RowsAtCompileTime, - MatrixCols = traits<XprType>::ColsAtCompileTime, - RowsAtCompileTime = Rows, - ColsAtCompileTime = Cols, - MaxRowsAtCompileTime = Rows, - MaxColsAtCompileTime = Cols, - XpxStorageOrder = ((int(traits<XprType>::Flags) & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor, - ReshapedStorageOrder = (RowsAtCompileTime == 1 && ColsAtCompileTime != 1) ? RowMajor - : (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ? ColMajor - : XpxStorageOrder, - HasSameStorageOrderAsXprType = (ReshapedStorageOrder == XpxStorageOrder), - InnerSize = (ReshapedStorageOrder==int(RowMajor)) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), - InnerStrideAtCompileTime = HasSameStorageOrderAsXprType - ? int(inner_stride_at_compile_time<XprType>::ret) - : Dynamic, - OuterStrideAtCompileTime = Dynamic, - - HasDirectAccess = internal::has_direct_access<XprType>::ret - && (Order==int(XpxStorageOrder)) - && ((evaluator<XprType>::Flags&LinearAccessBit)==LinearAccessBit), - - MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0) - && (InnerStrideAtCompileTime == 1) - ? PacketAccessBit : 0, - //MaskAlignedBit = ((OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ? AlignedBit : 0, - FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, - FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0, - FlagsRowMajorBit = (ReshapedStorageOrder==int(RowMajor)) ? RowMajorBit : 0, - FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0, - Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) | MaskPacketAccessBit), - - Flags = (Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit | FlagsDirectAccessBit) - }; -}; - -template<typename XprType, int Rows, int Cols, int Order, bool HasDirectAccess> class ReshapedImpl_dense; - -} // end namespace internal - -template<typename XprType, int Rows, int Cols, int Order, typename StorageKind> class ReshapedImpl; - -template<typename XprType, int Rows, int Cols, int Order> class Reshaped - : public ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind> -{ - typedef ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind> Impl; - public: - //typedef typename Impl::Base Base; - typedef Impl Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(Reshaped) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reshaped) - - /** Fixed-size constructor - */ - EIGEN_DEVICE_FUNC - inline Reshaped(XprType& xpr) - : Impl(xpr) - { - EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE) - eigen_assert(Rows * Cols == xpr.rows() * xpr.cols()); - } - - /** Dynamic-size constructor - */ - EIGEN_DEVICE_FUNC - inline Reshaped(XprType& xpr, - Index reshapeRows, Index reshapeCols) - : Impl(xpr, reshapeRows, reshapeCols) - { - eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==reshapeRows) - && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==reshapeCols)); - eigen_assert(reshapeRows * reshapeCols == xpr.rows() * xpr.cols()); - } -}; - -// The generic default implementation for dense reshape simply forward to the internal::ReshapedImpl_dense -// that must be specialized for direct and non-direct access... -template<typename XprType, int Rows, int Cols, int Order> -class ReshapedImpl<XprType, Rows, Cols, Order, Dense> - : public internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,internal::traits<Reshaped<XprType,Rows,Cols,Order> >::HasDirectAccess> -{ - typedef internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,internal::traits<Reshaped<XprType,Rows,Cols,Order> >::HasDirectAccess> Impl; - public: - typedef Impl Base; - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl) - EIGEN_DEVICE_FUNC inline ReshapedImpl(XprType& xpr) : Impl(xpr) {} - EIGEN_DEVICE_FUNC inline ReshapedImpl(XprType& xpr, Index reshapeRows, Index reshapeCols) - : Impl(xpr, reshapeRows, reshapeCols) {} -}; - -namespace internal { - -/** \internal Internal implementation of dense Reshaped in the general case. */ -template<typename XprType, int Rows, int Cols, int Order> -class ReshapedImpl_dense<XprType,Rows,Cols,Order,false> - : public internal::dense_xpr_base<Reshaped<XprType, Rows, Cols, Order> >::type -{ - typedef Reshaped<XprType, Rows, Cols, Order> ReshapedType; - public: - - typedef typename internal::dense_xpr_base<ReshapedType>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense) - - typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested; - typedef typename internal::remove_all<XprType>::type NestedExpression; - - class InnerIterator; - - /** Fixed-size constructor - */ - EIGEN_DEVICE_FUNC - inline ReshapedImpl_dense(XprType& xpr) - : m_xpr(xpr), m_rows(Rows), m_cols(Cols) - {} - - /** Dynamic-size constructor - */ - EIGEN_DEVICE_FUNC - inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols) - : m_xpr(xpr), m_rows(nRows), m_cols(nCols) - {} - - EIGEN_DEVICE_FUNC Index rows() const { return m_rows; } - EIGEN_DEVICE_FUNC Index cols() const { return m_cols; } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** \sa MapBase::data() */ - EIGEN_DEVICE_FUNC inline const Scalar* data() const; - EIGEN_DEVICE_FUNC inline Index innerStride() const; - EIGEN_DEVICE_FUNC inline Index outerStride() const; - #endif - - /** \returns the nested expression */ - EIGEN_DEVICE_FUNC - const typename internal::remove_all<XprType>::type& - nestedExpression() const { return m_xpr; } - - /** \returns the nested expression */ - EIGEN_DEVICE_FUNC - typename internal::remove_reference<XprType>::type& - nestedExpression() { return m_xpr; } - - protected: - - MatrixTypeNested m_xpr; - const internal::variable_if_dynamic<Index, Rows> m_rows; - const internal::variable_if_dynamic<Index, Cols> m_cols; -}; - - -/** \internal Internal implementation of dense Reshaped in the direct access case. */ -template<typename XprType, int Rows, int Cols, int Order> -class ReshapedImpl_dense<XprType, Rows, Cols, Order, true> - : public MapBase<Reshaped<XprType, Rows, Cols, Order> > -{ - typedef Reshaped<XprType, Rows, Cols, Order> ReshapedType; - typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested; - public: - - typedef MapBase<ReshapedType> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense) - - /** Fixed-size constructor - */ - EIGEN_DEVICE_FUNC - inline ReshapedImpl_dense(XprType& xpr) - : Base(xpr.data()), m_xpr(xpr) - {} - - /** Dynamic-size constructor - */ - EIGEN_DEVICE_FUNC - inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols) - : Base(xpr.data(), nRows, nCols), - m_xpr(xpr) - {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const - { - return m_xpr; - } - - EIGEN_DEVICE_FUNC - XprType& nestedExpression() { return m_xpr; } - - /** \sa MapBase::innerStride() */ - EIGEN_DEVICE_FUNC - inline Index innerStride() const - { - return m_xpr.innerStride(); - } - - /** \sa MapBase::outerStride() */ - EIGEN_DEVICE_FUNC - inline Index outerStride() const - { - return ((Flags&RowMajorBit)==RowMajorBit) ? this->cols() : this->rows(); - } - - protected: - - XprTypeNested m_xpr; -}; - -// Evaluators -template<typename ArgType, int Rows, int Cols, int Order, bool HasDirectAccess> struct reshaped_evaluator; - -template<typename ArgType, int Rows, int Cols, int Order> -struct evaluator<Reshaped<ArgType, Rows, Cols, Order> > - : reshaped_evaluator<ArgType, Rows, Cols, Order, traits<Reshaped<ArgType,Rows,Cols,Order> >::HasDirectAccess> -{ - typedef Reshaped<ArgType, Rows, Cols, Order> XprType; - typedef typename XprType::Scalar Scalar; - // TODO: should check for smaller packet types - typedef typename packet_traits<Scalar>::type PacketScalar; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - HasDirectAccess = traits<XprType>::HasDirectAccess, - -// RowsAtCompileTime = traits<XprType>::RowsAtCompileTime, -// ColsAtCompileTime = traits<XprType>::ColsAtCompileTime, -// MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime, -// MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime, -// -// InnerStrideAtCompileTime = traits<XprType>::HasSameStorageOrderAsXprType -// ? int(inner_stride_at_compile_time<ArgType>::ret) -// : Dynamic, -// OuterStrideAtCompileTime = Dynamic, - - FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1 || HasDirectAccess) ? LinearAccessBit : 0, - FlagsRowMajorBit = (traits<XprType>::ReshapedStorageOrder==int(RowMajor)) ? RowMajorBit : 0, - FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0, - Flags0 = evaluator<ArgType>::Flags & (HereditaryBits & ~RowMajorBit), - Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit | FlagsDirectAccessBit, - - PacketAlignment = unpacket_traits<PacketScalar>::alignment, - Alignment = evaluator<ArgType>::Alignment - }; - typedef reshaped_evaluator<ArgType, Rows, Cols, Order, HasDirectAccess> reshaped_evaluator_type; - EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : reshaped_evaluator_type(xpr) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } -}; - -template<typename ArgType, int Rows, int Cols, int Order> -struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ false> - : evaluator_base<Reshaped<ArgType, Rows, Cols, Order> > -{ - typedef Reshaped<ArgType, Rows, Cols, Order> XprType; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost /* TODO + cost of index computations */, - - Flags = (evaluator<ArgType>::Flags & (HereditaryBits /*| LinearAccessBit | DirectAccessBit*/)), - - Alignment = 0 - }; - - EIGEN_DEVICE_FUNC explicit reshaped_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - typedef std::pair<Index, Index> RowCol; - - inline RowCol index_remap(Index rowId, Index colId) const - { - if(Order==ColMajor) - { - const Index nth_elem_idx = colId * m_xpr.rows() + rowId; - return RowCol(nth_elem_idx % m_xpr.nestedExpression().rows(), - nth_elem_idx / m_xpr.nestedExpression().rows()); - } - else - { - const Index nth_elem_idx = colId + rowId * m_xpr.cols(); - return RowCol(nth_elem_idx / m_xpr.nestedExpression().cols(), - nth_elem_idx % m_xpr.nestedExpression().cols()); - } - } - - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index rowId, Index colId) - { - EIGEN_STATIC_ASSERT_LVALUE(XprType) - const RowCol row_col = index_remap(rowId, colId); - return m_argImpl.coeffRef(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index rowId, Index colId) const - { - const RowCol row_col = index_remap(rowId, colId); - return m_argImpl.coeffRef(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const - { - const RowCol row_col = index_remap(rowId, colId); - return m_argImpl.coeff(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index index) - { - EIGEN_STATIC_ASSERT_LVALUE(XprType) - const RowCol row_col = index_remap(Rows == 1 ? 0 : index, - Rows == 1 ? index : 0); - return m_argImpl.coeffRef(row_col.first, row_col.second); - - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index index) const - { - const RowCol row_col = index_remap(Rows == 1 ? 0 : index, - Rows == 1 ? index : 0); - return m_argImpl.coeffRef(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - inline const CoeffReturnType coeff(Index index) const - { - const RowCol row_col = index_remap(Rows == 1 ? 0 : index, - Rows == 1 ? index : 0); - return m_argImpl.coeff(row_col.first, row_col.second); - } -#if 0 - EIGEN_DEVICE_FUNC - template<int LoadMode> - inline PacketScalar packet(Index rowId, Index colId) const - { - const RowCol row_col = index_remap(rowId, colId); - return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second); - - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC - inline void writePacket(Index rowId, Index colId, const PacketScalar& val) - { - const RowCol row_col = index_remap(rowId, colId); - m_argImpl.const_cast_derived().template writePacket<Unaligned> - (row_col.first, row_col.second, val); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC - inline PacketScalar packet(Index index) const - { - const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0); - return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC - inline void writePacket(Index index, const PacketScalar& val) - { - const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0); - return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second, val); - } -#endif -protected: - - evaluator<ArgType> m_argImpl; - const XprType& m_xpr; - -}; - -template<typename ArgType, int Rows, int Cols, int Order> -struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ true> -: mapbase_evaluator<Reshaped<ArgType, Rows, Cols, Order>, - typename Reshaped<ArgType, Rows, Cols, Order>::PlainObject> -{ - typedef Reshaped<ArgType, Rows, Cols, Order> XprType; - typedef typename XprType::Scalar Scalar; - - EIGEN_DEVICE_FUNC explicit reshaped_evaluator(const XprType& xpr) - : mapbase_evaluator<XprType, typename XprType::PlainObject>(xpr) - { - // TODO: for the 3.4 release, this should be turned to an internal assertion, but let's keep it as is for the beta lifetime - eigen_assert(((internal::UIntPtr(xpr.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) && "data is not aligned"); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_RESHAPED_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/ReturnByValue.h b/external/eigen/include/eigen3/Eigen/src/Core/ReturnByValue.h deleted file mode 100644 index 11dc86d0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/ReturnByValue.h +++ /dev/null @@ -1,117 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_RETURNBYVALUE_H -#define EIGEN_RETURNBYVALUE_H - -namespace Eigen { - -namespace internal { - -template<typename Derived> -struct traits<ReturnByValue<Derived> > - : public traits<typename traits<Derived>::ReturnType> -{ - enum { - // We're disabling the DirectAccess because e.g. the constructor of - // the Block-with-DirectAccess expression requires to have a coeffRef method. - // Also, we don't want to have to implement the stride stuff. - Flags = (traits<typename traits<Derived>::ReturnType>::Flags - | EvalBeforeNestingBit) & ~DirectAccessBit - }; -}; - -/* The ReturnByValue object doesn't even have a coeff() method. - * So the only way that nesting it in an expression can work, is by evaluating it into a plain matrix. - * So internal::nested always gives the plain return matrix type. - * - * FIXME: I don't understand why we need this specialization: isn't this taken care of by the EvalBeforeNestingBit ?? - * Answer: EvalBeforeNestingBit should be deprecated since we have the evaluators - */ -template<typename Derived,int n,typename PlainObject> -struct nested_eval<ReturnByValue<Derived>, n, PlainObject> -{ - typedef typename traits<Derived>::ReturnType type; -}; - -} // end namespace internal - -/** \class ReturnByValue - * \ingroup Core_Module - * - */ -template<typename Derived> class ReturnByValue - : public internal::dense_xpr_base< ReturnByValue<Derived> >::type, internal::no_assignment_operator -{ - public: - typedef typename internal::traits<Derived>::ReturnType ReturnType; - - typedef typename internal::dense_xpr_base<ReturnByValue>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(ReturnByValue) - - template<typename Dest> - EIGEN_DEVICE_FUNC - inline void evalTo(Dest& dst) const - { static_cast<const Derived*>(this)->evalTo(dst); } - EIGEN_DEVICE_FUNC inline Index rows() const { return static_cast<const Derived*>(this)->rows(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return static_cast<const Derived*>(this)->cols(); } - -#ifndef EIGEN_PARSED_BY_DOXYGEN -#define Unusable YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT - class Unusable{ - Unusable(const Unusable&) {} - Unusable& operator=(const Unusable&) {return *this;} - }; - const Unusable& coeff(Index) const { return *reinterpret_cast<const Unusable*>(this); } - const Unusable& coeff(Index,Index) const { return *reinterpret_cast<const Unusable*>(this); } - Unusable& coeffRef(Index) { return *reinterpret_cast<Unusable*>(this); } - Unusable& coeffRef(Index,Index) { return *reinterpret_cast<Unusable*>(this); } -#undef Unusable -#endif -}; - -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC Derived& DenseBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other) -{ - other.evalTo(derived()); - return derived(); -} - -namespace internal { - -// Expression is evaluated in a temporary; default implementation of Assignment is bypassed so that -// when a ReturnByValue expression is assigned, the evaluator is not constructed. -// TODO: Finalize port to new regime; ReturnByValue should not exist in the expression world - -template<typename Derived> -struct evaluator<ReturnByValue<Derived> > - : public evaluator<typename internal::traits<Derived>::ReturnType> -{ - typedef ReturnByValue<Derived> XprType; - typedef typename internal::traits<Derived>::ReturnType PlainObject; - typedef evaluator<PlainObject> Base; - - EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) - : m_result(xpr.rows(), xpr.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - xpr.evalTo(m_result); - } - -protected: - PlainObject m_result; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_RETURNBYVALUE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Reverse.h b/external/eigen/include/eigen3/Eigen/src/Core/Reverse.h deleted file mode 100644 index 85309392..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Reverse.h +++ /dev/null @@ -1,215 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009 Ricard Marxer <email@ricardmarxer.com> -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_REVERSE_H -#define EIGEN_REVERSE_H - -namespace Eigen { - -namespace internal { - -template<typename MatrixType, int Direction> -struct traits<Reverse<MatrixType, Direction> > - : traits<MatrixType> -{ - typedef typename MatrixType::Scalar Scalar; - typedef typename traits<MatrixType>::StorageKind StorageKind; - typedef typename traits<MatrixType>::XprKind XprKind; - typedef typename ref_selector<MatrixType>::type MatrixTypeNested; - typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - Flags = _MatrixTypeNested::Flags & (RowMajorBit | LvalueBit) - }; -}; - -template<typename PacketType, bool ReversePacket> struct reverse_packet_cond -{ - static inline PacketType run(const PacketType& x) { return preverse(x); } -}; - -template<typename PacketType> struct reverse_packet_cond<PacketType,false> -{ - static inline PacketType run(const PacketType& x) { return x; } -}; - -} // end namespace internal - -/** \class Reverse - * \ingroup Core_Module - * - * \brief Expression of the reverse of a vector or matrix - * - * \tparam MatrixType the type of the object of which we are taking the reverse - * \tparam Direction defines the direction of the reverse operation, can be Vertical, Horizontal, or BothDirections - * - * This class represents an expression of the reverse of a vector. - * It is the return type of MatrixBase::reverse() and VectorwiseOp::reverse() - * and most of the time this is the only way it is used. - * - * \sa MatrixBase::reverse(), VectorwiseOp::reverse() - */ -template<typename MatrixType, int Direction> class Reverse - : public internal::dense_xpr_base< Reverse<MatrixType, Direction> >::type -{ - public: - - typedef typename internal::dense_xpr_base<Reverse>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Reverse) - typedef typename internal::remove_all<MatrixType>::type NestedExpression; - using Base::IsRowMajor; - - protected: - enum { - PacketSize = internal::packet_traits<Scalar>::size, - IsColMajor = !IsRowMajor, - ReverseRow = (Direction == Vertical) || (Direction == BothDirections), - ReverseCol = (Direction == Horizontal) || (Direction == BothDirections), - OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1, - OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1, - ReversePacket = (Direction == BothDirections) - || ((Direction == Vertical) && IsColMajor) - || ((Direction == Horizontal) && IsRowMajor) - }; - typedef internal::reverse_packet_cond<PacketScalar,ReversePacket> reverse_packet; - public: - - EIGEN_DEVICE_FUNC explicit inline Reverse(const MatrixType& matrix) : m_matrix(matrix) { } - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reverse) - - EIGEN_DEVICE_FUNC inline Index rows() const { return m_matrix.rows(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_matrix.cols(); } - - EIGEN_DEVICE_FUNC inline Index innerStride() const - { - return -m_matrix.innerStride(); - } - - EIGEN_DEVICE_FUNC const typename internal::remove_all<typename MatrixType::Nested>::type& - nestedExpression() const - { - return m_matrix; - } - - protected: - typename MatrixType::Nested m_matrix; -}; - -/** \returns an expression of the reverse of *this. - * - * Example: \include MatrixBase_reverse.cpp - * Output: \verbinclude MatrixBase_reverse.out - * - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline typename DenseBase<Derived>::ReverseReturnType -DenseBase<Derived>::reverse() -{ - return ReverseReturnType(derived()); -} - - -//reverse const overload moved DenseBase.h due to a CUDA compiler bug - -/** This is the "in place" version of reverse: it reverses \c *this. - * - * In most cases it is probably better to simply use the reversed expression - * of a matrix. However, when reversing the matrix data itself is really needed, - * then this "in-place" version is probably the right choice because it provides - * the following additional benefits: - * - less error prone: doing the same operation with .reverse() requires special care: - * \code m = m.reverse().eval(); \endcode - * - this API enables reverse operations without the need for a temporary - * - it allows future optimizations (cache friendliness, etc.) - * - * \sa VectorwiseOp::reverseInPlace(), reverse() */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline void DenseBase<Derived>::reverseInPlace() -{ - if(cols()>rows()) - { - Index half = cols()/2; - leftCols(half).swap(rightCols(half).reverse()); - if((cols()%2)==1) - { - Index half2 = rows()/2; - col(half).head(half2).swap(col(half).tail(half2).reverse()); - } - } - else - { - Index half = rows()/2; - topRows(half).swap(bottomRows(half).reverse()); - if((rows()%2)==1) - { - Index half2 = cols()/2; - row(half).head(half2).swap(row(half).tail(half2).reverse()); - } - } -} - -namespace internal { - -template<int Direction> -struct vectorwise_reverse_inplace_impl; - -template<> -struct vectorwise_reverse_inplace_impl<Vertical> -{ - template<typename ExpressionType> - static void run(ExpressionType &xpr) - { - const int HalfAtCompileTime = ExpressionType::RowsAtCompileTime==Dynamic?Dynamic:ExpressionType::RowsAtCompileTime/2; - Index half = xpr.rows()/2; - xpr.topRows(fix<HalfAtCompileTime>(half)) - .swap(xpr.bottomRows(fix<HalfAtCompileTime>(half)).colwise().reverse()); - } -}; - -template<> -struct vectorwise_reverse_inplace_impl<Horizontal> -{ - template<typename ExpressionType> - static void run(ExpressionType &xpr) - { - const int HalfAtCompileTime = ExpressionType::ColsAtCompileTime==Dynamic?Dynamic:ExpressionType::ColsAtCompileTime/2; - Index half = xpr.cols()/2; - xpr.leftCols(fix<HalfAtCompileTime>(half)) - .swap(xpr.rightCols(fix<HalfAtCompileTime>(half)).rowwise().reverse()); - } -}; - -} // end namespace internal - -/** This is the "in place" version of VectorwiseOp::reverse: it reverses each column or row of \c *this. - * - * In most cases it is probably better to simply use the reversed expression - * of a matrix. However, when reversing the matrix data itself is really needed, - * then this "in-place" version is probably the right choice because it provides - * the following additional benefits: - * - less error prone: doing the same operation with .reverse() requires special care: - * \code m = m.reverse().eval(); \endcode - * - this API enables reverse operations without the need for a temporary - * - * \sa DenseBase::reverseInPlace(), reverse() */ -template<typename ExpressionType, int Direction> -EIGEN_DEVICE_FUNC void VectorwiseOp<ExpressionType,Direction>::reverseInPlace() -{ - internal::vectorwise_reverse_inplace_impl<Direction>::run(m_matrix); -} - -} // end namespace Eigen - -#endif // EIGEN_REVERSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Select.h b/external/eigen/include/eigen3/Eigen/src/Core/Select.h deleted file mode 100644 index 79eec1b5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Select.h +++ /dev/null @@ -1,162 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SELECT_H -#define EIGEN_SELECT_H - -namespace Eigen { - -/** \class Select - * \ingroup Core_Module - * - * \brief Expression of a coefficient wise version of the C++ ternary operator ?: - * - * \param ConditionMatrixType the type of the \em condition expression which must be a boolean matrix - * \param ThenMatrixType the type of the \em then expression - * \param ElseMatrixType the type of the \em else expression - * - * This class represents an expression of a coefficient wise version of the C++ ternary operator ?:. - * It is the return type of DenseBase::select() and most of the time this is the only way it is used. - * - * \sa DenseBase::select(const DenseBase<ThenDerived>&, const DenseBase<ElseDerived>&) const - */ - -namespace internal { -template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType> -struct traits<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> > - : traits<ThenMatrixType> -{ - typedef typename traits<ThenMatrixType>::Scalar Scalar; - typedef Dense StorageKind; - typedef typename traits<ThenMatrixType>::XprKind XprKind; - typedef typename ConditionMatrixType::Nested ConditionMatrixNested; - typedef typename ThenMatrixType::Nested ThenMatrixNested; - typedef typename ElseMatrixType::Nested ElseMatrixNested; - enum { - RowsAtCompileTime = ConditionMatrixType::RowsAtCompileTime, - ColsAtCompileTime = ConditionMatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = ConditionMatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = ConditionMatrixType::MaxColsAtCompileTime, - Flags = (unsigned int)ThenMatrixType::Flags & ElseMatrixType::Flags & RowMajorBit - }; -}; -} - -template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType> -class Select : public internal::dense_xpr_base< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::type, - internal::no_assignment_operator -{ - public: - - typedef typename internal::dense_xpr_base<Select>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Select) - - inline EIGEN_DEVICE_FUNC - Select(const ConditionMatrixType& a_conditionMatrix, - const ThenMatrixType& a_thenMatrix, - const ElseMatrixType& a_elseMatrix) - : m_condition(a_conditionMatrix), m_then(a_thenMatrix), m_else(a_elseMatrix) - { - eigen_assert(m_condition.rows() == m_then.rows() && m_condition.rows() == m_else.rows()); - eigen_assert(m_condition.cols() == m_then.cols() && m_condition.cols() == m_else.cols()); - } - - inline EIGEN_DEVICE_FUNC Index rows() const { return m_condition.rows(); } - inline EIGEN_DEVICE_FUNC Index cols() const { return m_condition.cols(); } - - inline EIGEN_DEVICE_FUNC - const Scalar coeff(Index i, Index j) const - { - if (m_condition.coeff(i,j)) - return m_then.coeff(i,j); - else - return m_else.coeff(i,j); - } - - inline EIGEN_DEVICE_FUNC - const Scalar coeff(Index i) const - { - if (m_condition.coeff(i)) - return m_then.coeff(i); - else - return m_else.coeff(i); - } - - inline EIGEN_DEVICE_FUNC const ConditionMatrixType& conditionMatrix() const - { - return m_condition; - } - - inline EIGEN_DEVICE_FUNC const ThenMatrixType& thenMatrix() const - { - return m_then; - } - - inline EIGEN_DEVICE_FUNC const ElseMatrixType& elseMatrix() const - { - return m_else; - } - - protected: - typename ConditionMatrixType::Nested m_condition; - typename ThenMatrixType::Nested m_then; - typename ElseMatrixType::Nested m_else; -}; - - -/** \returns a matrix where each coefficient (i,j) is equal to \a thenMatrix(i,j) - * if \c *this(i,j), and \a elseMatrix(i,j) otherwise. - * - * Example: \include MatrixBase_select.cpp - * Output: \verbinclude MatrixBase_select.out - * - * \sa class Select - */ -template<typename Derived> -template<typename ThenDerived,typename ElseDerived> -inline const Select<Derived,ThenDerived,ElseDerived> -DenseBase<Derived>::select(const DenseBase<ThenDerived>& thenMatrix, - const DenseBase<ElseDerived>& elseMatrix) const -{ - return Select<Derived,ThenDerived,ElseDerived>(derived(), thenMatrix.derived(), elseMatrix.derived()); -} - -/** Version of DenseBase::select(const DenseBase&, const DenseBase&) with - * the \em else expression being a scalar value. - * - * \sa DenseBase::select(const DenseBase<ThenDerived>&, const DenseBase<ElseDerived>&) const, class Select - */ -template<typename Derived> -template<typename ThenDerived> -inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType> -DenseBase<Derived>::select(const DenseBase<ThenDerived>& thenMatrix, - const typename ThenDerived::Scalar& elseScalar) const -{ - return Select<Derived,ThenDerived,typename ThenDerived::ConstantReturnType>( - derived(), thenMatrix.derived(), ThenDerived::Constant(rows(),cols(),elseScalar)); -} - -/** Version of DenseBase::select(const DenseBase&, const DenseBase&) with - * the \em then expression being a scalar value. - * - * \sa DenseBase::select(const DenseBase<ThenDerived>&, const DenseBase<ElseDerived>&) const, class Select - */ -template<typename Derived> -template<typename ElseDerived> -inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived > -DenseBase<Derived>::select(const typename ElseDerived::Scalar& thenScalar, - const DenseBase<ElseDerived>& elseMatrix) const -{ - return Select<Derived,typename ElseDerived::ConstantReturnType,ElseDerived>( - derived(), ElseDerived::Constant(rows(),cols(),thenScalar), elseMatrix.derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_SELECT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/SelfAdjointView.h b/external/eigen/include/eigen3/Eigen/src/Core/SelfAdjointView.h deleted file mode 100644 index 2173799d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/SelfAdjointView.h +++ /dev/null @@ -1,365 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SELFADJOINTMATRIX_H -#define EIGEN_SELFADJOINTMATRIX_H - -namespace Eigen { - -/** \class SelfAdjointView - * \ingroup Core_Module - * - * - * \brief Expression of a selfadjoint matrix from a triangular part of a dense matrix - * - * \param MatrixType the type of the dense matrix storing the coefficients - * \param TriangularPart can be either \c #Lower or \c #Upper - * - * This class is an expression of a sefladjoint matrix from a triangular part of a matrix - * with given dense storage of the coefficients. It is the return type of MatrixBase::selfadjointView() - * and most of the time this is the only way that it is used. - * - * \sa class TriangularBase, MatrixBase::selfadjointView() - */ - -namespace internal { -template<typename MatrixType, unsigned int UpLo> -struct traits<SelfAdjointView<MatrixType, UpLo> > : traits<MatrixType> -{ - typedef typename ref_selector<MatrixType>::non_const_type MatrixTypeNested; - typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned; - typedef MatrixType ExpressionType; - typedef typename MatrixType::PlainObject FullMatrixType; - enum { - Mode = UpLo | SelfAdjoint, - FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, - Flags = MatrixTypeNestedCleaned::Flags & (HereditaryBits|FlagsLvalueBit) - & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)) // FIXME these flags should be preserved - }; -}; -} - - -template<typename _MatrixType, unsigned int UpLo> class SelfAdjointView - : public TriangularBase<SelfAdjointView<_MatrixType, UpLo> > -{ - public: - - typedef _MatrixType MatrixType; - typedef TriangularBase<SelfAdjointView> Base; - typedef typename internal::traits<SelfAdjointView>::MatrixTypeNested MatrixTypeNested; - typedef typename internal::traits<SelfAdjointView>::MatrixTypeNestedCleaned MatrixTypeNestedCleaned; - typedef MatrixTypeNestedCleaned NestedExpression; - - /** \brief The type of coefficients in this matrix */ - typedef typename internal::traits<SelfAdjointView>::Scalar Scalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType; - typedef SelfAdjointView<typename internal::add_const<MatrixType>::type, UpLo> ConstSelfAdjointView; - - enum { - Mode = internal::traits<SelfAdjointView>::Mode, - Flags = internal::traits<SelfAdjointView>::Flags, - TransposeMode = ((Mode & Upper) ? Lower : 0) | ((Mode & Lower) ? Upper : 0) - }; - typedef typename MatrixType::PlainObject PlainObject; - - EIGEN_DEVICE_FUNC - explicit inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix) - { - EIGEN_STATIC_ASSERT(UpLo==Lower || UpLo==Upper,SELFADJOINTVIEW_ACCEPTS_UPPER_AND_LOWER_MODE_ONLY); - } - - EIGEN_DEVICE_FUNC - inline Index rows() const { return m_matrix.rows(); } - EIGEN_DEVICE_FUNC - inline Index cols() const { return m_matrix.cols(); } - EIGEN_DEVICE_FUNC - inline Index outerStride() const { return m_matrix.outerStride(); } - EIGEN_DEVICE_FUNC - inline Index innerStride() const { return m_matrix.innerStride(); } - - /** \sa MatrixBase::coeff() - * \warning the coordinates must fit into the referenced triangular part - */ - EIGEN_DEVICE_FUNC - inline Scalar coeff(Index row, Index col) const - { - Base::check_coordinates_internal(row, col); - return m_matrix.coeff(row, col); - } - - /** \sa MatrixBase::coeffRef() - * \warning the coordinates must fit into the referenced triangular part - */ - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index row, Index col) - { - EIGEN_STATIC_ASSERT_LVALUE(SelfAdjointView); - Base::check_coordinates_internal(row, col); - return m_matrix.coeffRef(row, col); - } - - /** \internal */ - EIGEN_DEVICE_FUNC - const MatrixTypeNestedCleaned& _expression() const { return m_matrix; } - - EIGEN_DEVICE_FUNC - const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; } - EIGEN_DEVICE_FUNC - MatrixTypeNestedCleaned& nestedExpression() { return m_matrix; } - - /** Efficient triangular matrix times vector/matrix product */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - const Product<SelfAdjointView,OtherDerived> - operator*(const MatrixBase<OtherDerived>& rhs) const - { - return Product<SelfAdjointView,OtherDerived>(*this, rhs.derived()); - } - - /** Efficient vector/matrix times triangular matrix product */ - template<typename OtherDerived> friend - EIGEN_DEVICE_FUNC - const Product<OtherDerived,SelfAdjointView> - operator*(const MatrixBase<OtherDerived>& lhs, const SelfAdjointView& rhs) - { - return Product<OtherDerived,SelfAdjointView>(lhs.derived(),rhs); - } - - friend EIGEN_DEVICE_FUNC - const SelfAdjointView<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,MatrixType,product),UpLo> - operator*(const Scalar& s, const SelfAdjointView& mat) - { - return (s*mat.nestedExpression()).template selfadjointView<UpLo>(); - } - - /** Perform a symmetric rank 2 update of the selfadjoint matrix \c *this: - * \f$ this = this + \alpha u v^* + conj(\alpha) v u^* \f$ - * \returns a reference to \c *this - * - * The vectors \a u and \c v \b must be column vectors, however they can be - * a adjoint expression without any overhead. Only the meaningful triangular - * part of the matrix is updated, the rest is left unchanged. - * - * \sa rankUpdate(const MatrixBase<DerivedU>&, Scalar) - */ - template<typename DerivedU, typename DerivedV> - EIGEN_DEVICE_FUNC - SelfAdjointView& rankUpdate(const MatrixBase<DerivedU>& u, const MatrixBase<DerivedV>& v, const Scalar& alpha = Scalar(1)); - - /** Perform a symmetric rank K update of the selfadjoint matrix \c *this: - * \f$ this = this + \alpha ( u u^* ) \f$ where \a u is a vector or matrix. - * - * \returns a reference to \c *this - * - * Note that to perform \f$ this = this + \alpha ( u^* u ) \f$ you can simply - * call this function with u.adjoint(). - * - * \sa rankUpdate(const MatrixBase<DerivedU>&, const MatrixBase<DerivedV>&, Scalar) - */ - template<typename DerivedU> - EIGEN_DEVICE_FUNC - SelfAdjointView& rankUpdate(const MatrixBase<DerivedU>& u, const Scalar& alpha = Scalar(1)); - - /** \returns an expression of a triangular view extracted from the current selfadjoint view of a given triangular part - * - * The parameter \a TriMode can have the following values: \c #Upper, \c #StrictlyUpper, \c #UnitUpper, - * \c #Lower, \c #StrictlyLower, \c #UnitLower. - * - * If \c TriMode references the same triangular part than \c *this, then this method simply return a \c TriangularView of the nested expression, - * otherwise, the nested expression is first transposed, thus returning a \c TriangularView<Transpose<MatrixType>> object. - * - * \sa MatrixBase::triangularView(), class TriangularView - */ - template<unsigned int TriMode> - EIGEN_DEVICE_FUNC - typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), - TriangularView<MatrixType,TriMode>, - TriangularView<typename MatrixType::AdjointReturnType,TriMode> >::type - triangularView() const - { - typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), MatrixType&, typename MatrixType::ConstTransposeReturnType>::type tmp1(m_matrix); - typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), MatrixType&, typename MatrixType::AdjointReturnType>::type tmp2(tmp1); - return typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), - TriangularView<MatrixType,TriMode>, - TriangularView<typename MatrixType::AdjointReturnType,TriMode> >::type(tmp2); - } - - typedef SelfAdjointView<const MatrixConjugateReturnType,UpLo> ConjugateReturnType; - /** \sa MatrixBase::conjugate() const */ - EIGEN_DEVICE_FUNC - inline const ConjugateReturnType conjugate() const - { return ConjugateReturnType(m_matrix.conjugate()); } - - /** \returns an expression of the complex conjugate of \c *this if Cond==true, - * returns \c *this otherwise. - */ - template<bool Cond> - EIGEN_DEVICE_FUNC - inline typename internal::conditional<Cond,ConjugateReturnType,ConstSelfAdjointView>::type - conjugateIf() const - { - typedef typename internal::conditional<Cond,ConjugateReturnType,ConstSelfAdjointView>::type ReturnType; - return ReturnType(m_matrix.template conjugateIf<Cond>()); - } - - typedef SelfAdjointView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType; - /** \sa MatrixBase::adjoint() const */ - EIGEN_DEVICE_FUNC - inline const AdjointReturnType adjoint() const - { return AdjointReturnType(m_matrix.adjoint()); } - - typedef SelfAdjointView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType; - /** \sa MatrixBase::transpose() */ - EIGEN_DEVICE_FUNC - inline TransposeReturnType transpose() - { - EIGEN_STATIC_ASSERT_LVALUE(MatrixType) - typename MatrixType::TransposeReturnType tmp(m_matrix); - return TransposeReturnType(tmp); - } - - typedef SelfAdjointView<const typename MatrixType::ConstTransposeReturnType,TransposeMode> ConstTransposeReturnType; - /** \sa MatrixBase::transpose() const */ - EIGEN_DEVICE_FUNC - inline const ConstTransposeReturnType transpose() const - { - return ConstTransposeReturnType(m_matrix.transpose()); - } - - /** \returns a const expression of the main diagonal of the matrix \c *this - * - * This method simply returns the diagonal of the nested expression, thus by-passing the SelfAdjointView decorator. - * - * \sa MatrixBase::diagonal(), class Diagonal */ - EIGEN_DEVICE_FUNC - typename MatrixType::ConstDiagonalReturnType diagonal() const - { - return typename MatrixType::ConstDiagonalReturnType(m_matrix); - } - -/////////// Cholesky module /////////// - - const LLT<PlainObject, UpLo> llt() const; - const LDLT<PlainObject, UpLo> ldlt() const; - -/////////// Eigenvalue module /////////// - - /** Real part of #Scalar */ - typedef typename NumTraits<Scalar>::Real RealScalar; - /** Return type of eigenvalues() */ - typedef Matrix<RealScalar, internal::traits<MatrixType>::ColsAtCompileTime, 1> EigenvaluesReturnType; - - EIGEN_DEVICE_FUNC - EigenvaluesReturnType eigenvalues() const; - EIGEN_DEVICE_FUNC - RealScalar operatorNorm() const; - - protected: - MatrixTypeNested m_matrix; -}; - - -// template<typename OtherDerived, typename MatrixType, unsigned int UpLo> -// internal::selfadjoint_matrix_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> > -// operator*(const MatrixBase<OtherDerived>& lhs, const SelfAdjointView<MatrixType,UpLo>& rhs) -// { -// return internal::matrix_selfadjoint_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >(lhs.derived(),rhs); -// } - -// selfadjoint to dense matrix - -namespace internal { - -// TODO currently a selfadjoint expression has the form SelfAdjointView<.,.> -// in the future selfadjoint-ness should be defined by the expression traits -// such that Transpose<SelfAdjointView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work) -template<typename MatrixType, unsigned int Mode> -struct evaluator_traits<SelfAdjointView<MatrixType,Mode> > -{ - typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind; - typedef SelfAdjointShape Shape; -}; - -template<int UpLo, int SetOpposite, typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version> -class triangular_dense_assignment_kernel<UpLo,SelfAdjoint,SetOpposite,DstEvaluatorTypeT,SrcEvaluatorTypeT,Functor,Version> - : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version> -{ -protected: - typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version> Base; - typedef typename Base::DstXprType DstXprType; - typedef typename Base::SrcXprType SrcXprType; - using Base::m_dst; - using Base::m_src; - using Base::m_functor; -public: - - typedef typename Base::DstEvaluatorType DstEvaluatorType; - typedef typename Base::SrcEvaluatorType SrcEvaluatorType; - typedef typename Base::Scalar Scalar; - typedef typename Base::AssignmentTraits AssignmentTraits; - - - EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr) - : Base(dst, src, func, dstExpr) - {} - - EIGEN_DEVICE_FUNC void assignCoeff(Index row, Index col) - { - eigen_internal_assert(row!=col); - Scalar tmp = m_src.coeff(row,col); - m_functor.assignCoeff(m_dst.coeffRef(row,col), tmp); - m_functor.assignCoeff(m_dst.coeffRef(col,row), numext::conj(tmp)); - } - - EIGEN_DEVICE_FUNC void assignDiagonalCoeff(Index id) - { - Base::assignCoeff(id,id); - } - - EIGEN_DEVICE_FUNC void assignOppositeCoeff(Index, Index) - { eigen_internal_assert(false && "should never be called"); } -}; - -} // end namespace internal - -/*************************************************************************** -* Implementation of MatrixBase methods -***************************************************************************/ - -/** This is the const version of MatrixBase::selfadjointView() */ -template<typename Derived> -template<unsigned int UpLo> -EIGEN_DEVICE_FUNC typename MatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type -MatrixBase<Derived>::selfadjointView() const -{ - return typename ConstSelfAdjointViewReturnType<UpLo>::Type(derived()); -} - -/** \returns an expression of a symmetric/self-adjoint view extracted from the upper or lower triangular part of the current matrix - * - * The parameter \a UpLo can be either \c #Upper or \c #Lower - * - * Example: \include MatrixBase_selfadjointView.cpp - * Output: \verbinclude MatrixBase_selfadjointView.out - * - * \sa class SelfAdjointView - */ -template<typename Derived> -template<unsigned int UpLo> -EIGEN_DEVICE_FUNC typename MatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type -MatrixBase<Derived>::selfadjointView() -{ - return typename SelfAdjointViewReturnType<UpLo>::Type(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_SELFADJOINTMATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/SelfCwiseBinaryOp.h b/external/eigen/include/eigen3/Eigen/src/Core/SelfCwiseBinaryOp.h deleted file mode 100644 index 7c89c2e2..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/SelfCwiseBinaryOp.h +++ /dev/null @@ -1,47 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SELFCWISEBINARYOP_H -#define EIGEN_SELFCWISEBINARYOP_H - -namespace Eigen { - -// TODO generalize the scalar type of 'other' - -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator*=(const Scalar& other) -{ - internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::mul_assign_op<Scalar,Scalar>()); - return derived(); -} - -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& ArrayBase<Derived>::operator+=(const Scalar& other) -{ - internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::add_assign_op<Scalar,Scalar>()); - return derived(); -} - -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& ArrayBase<Derived>::operator-=(const Scalar& other) -{ - internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::sub_assign_op<Scalar,Scalar>()); - return derived(); -} - -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator/=(const Scalar& other) -{ - internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::div_assign_op<Scalar,Scalar>()); - return derived(); -} - -} // end namespace Eigen - -#endif // EIGEN_SELFCWISEBINARYOP_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Solve.h b/external/eigen/include/eigen3/Eigen/src/Core/Solve.h deleted file mode 100644 index ec4b4a98..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Solve.h +++ /dev/null @@ -1,188 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SOLVE_H -#define EIGEN_SOLVE_H - -namespace Eigen { - -template<typename Decomposition, typename RhsType, typename StorageKind> class SolveImpl; - -/** \class Solve - * \ingroup Core_Module - * - * \brief Pseudo expression representing a solving operation - * - * \tparam Decomposition the type of the matrix or decomposition object - * \tparam Rhstype the type of the right-hand side - * - * This class represents an expression of A.solve(B) - * and most of the time this is the only way it is used. - * - */ -namespace internal { - -// this solve_traits class permits to determine the evaluation type with respect to storage kind (Dense vs Sparse) -template<typename Decomposition, typename RhsType,typename StorageKind> struct solve_traits; - -template<typename Decomposition, typename RhsType> -struct solve_traits<Decomposition,RhsType,Dense> -{ - typedef typename make_proper_matrix_type<typename RhsType::Scalar, - Decomposition::ColsAtCompileTime, - RhsType::ColsAtCompileTime, - RhsType::PlainObject::Options, - Decomposition::MaxColsAtCompileTime, - RhsType::MaxColsAtCompileTime>::type PlainObject; -}; - -template<typename Decomposition, typename RhsType> -struct traits<Solve<Decomposition, RhsType> > - : traits<typename solve_traits<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>::PlainObject> -{ - typedef typename solve_traits<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>::PlainObject PlainObject; - typedef typename promote_index_type<typename Decomposition::StorageIndex, typename RhsType::StorageIndex>::type StorageIndex; - typedef traits<PlainObject> BaseTraits; - enum { - Flags = BaseTraits::Flags & RowMajorBit, - CoeffReadCost = HugeCost - }; -}; - -} - - -template<typename Decomposition, typename RhsType> -class Solve : public SolveImpl<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind> -{ -public: - typedef typename internal::traits<Solve>::PlainObject PlainObject; - typedef typename internal::traits<Solve>::StorageIndex StorageIndex; - - Solve(const Decomposition &dec, const RhsType &rhs) - : m_dec(dec), m_rhs(rhs) - {} - - EIGEN_DEVICE_FUNC Index rows() const { return m_dec.cols(); } - EIGEN_DEVICE_FUNC Index cols() const { return m_rhs.cols(); } - - EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; } - EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; } - -protected: - const Decomposition &m_dec; - const RhsType &m_rhs; -}; - - -// Specialization of the Solve expression for dense results -template<typename Decomposition, typename RhsType> -class SolveImpl<Decomposition,RhsType,Dense> - : public MatrixBase<Solve<Decomposition,RhsType> > -{ - typedef Solve<Decomposition,RhsType> Derived; - -public: - - typedef MatrixBase<Solve<Decomposition,RhsType> > Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Derived) - -private: - - Scalar coeff(Index row, Index col) const; - Scalar coeff(Index i) const; -}; - -// Generic API dispatcher -template<typename Decomposition, typename RhsType, typename StorageKind> -class SolveImpl : public internal::generic_xpr_base<Solve<Decomposition,RhsType>, MatrixXpr, StorageKind>::type -{ - public: - typedef typename internal::generic_xpr_base<Solve<Decomposition,RhsType>, MatrixXpr, StorageKind>::type Base; -}; - -namespace internal { - -// Evaluator of Solve -> eval into a temporary -template<typename Decomposition, typename RhsType> -struct evaluator<Solve<Decomposition,RhsType> > - : public evaluator<typename Solve<Decomposition,RhsType>::PlainObject> -{ - typedef Solve<Decomposition,RhsType> SolveType; - typedef typename SolveType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - - enum { Flags = Base::Flags | EvalBeforeNestingBit }; - - EIGEN_DEVICE_FUNC explicit evaluator(const SolveType& solve) - : m_result(solve.rows(), solve.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - solve.dec()._solve_impl(solve.rhs(), m_result); - } - -protected: - PlainObject m_result; -}; - -// Specialization for "dst = dec.solve(rhs)" -// NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere -template<typename DstXprType, typename DecType, typename RhsType, typename Scalar> -struct Assignment<DstXprType, Solve<DecType,RhsType>, internal::assign_op<Scalar,Scalar>, Dense2Dense> -{ - typedef Solve<DecType,RhsType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - src.dec()._solve_impl(src.rhs(), dst); - } -}; - -// Specialization for "dst = dec.transpose().solve(rhs)" -template<typename DstXprType, typename DecType, typename RhsType, typename Scalar> -struct Assignment<DstXprType, Solve<Transpose<const DecType>,RhsType>, internal::assign_op<Scalar,Scalar>, Dense2Dense> -{ - typedef Solve<Transpose<const DecType>,RhsType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - src.dec().nestedExpression().template _solve_impl_transposed<false>(src.rhs(), dst); - } -}; - -// Specialization for "dst = dec.adjoint().solve(rhs)" -template<typename DstXprType, typename DecType, typename RhsType, typename Scalar> -struct Assignment<DstXprType, Solve<CwiseUnaryOp<internal::scalar_conjugate_op<typename DecType::Scalar>, const Transpose<const DecType> >,RhsType>, - internal::assign_op<Scalar,Scalar>, Dense2Dense> -{ - typedef Solve<CwiseUnaryOp<internal::scalar_conjugate_op<typename DecType::Scalar>, const Transpose<const DecType> >,RhsType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - src.dec().nestedExpression().nestedExpression().template _solve_impl_transposed<true>(src.rhs(), dst); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SOLVE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/SolveTriangular.h b/external/eigen/include/eigen3/Eigen/src/Core/SolveTriangular.h deleted file mode 100644 index 813fef0d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/SolveTriangular.h +++ /dev/null @@ -1,235 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SOLVETRIANGULAR_H -#define EIGEN_SOLVETRIANGULAR_H - -namespace Eigen { - -namespace internal { - -// Forward declarations: -// The following two routines are implemented in the products/TriangularSolver*.h files -template<typename LhsScalar, typename RhsScalar, typename Index, int Side, int Mode, bool Conjugate, int StorageOrder> -struct triangular_solve_vector; - -template <typename Scalar, typename Index, int Side, int Mode, bool Conjugate, int TriStorageOrder, int OtherStorageOrder, int OtherInnerStride> -struct triangular_solve_matrix; - -// small helper struct extracting some traits on the underlying solver operation -template<typename Lhs, typename Rhs, int Side> -class trsolve_traits -{ - private: - enum { - RhsIsVectorAtCompileTime = (Side==OnTheLeft ? Rhs::ColsAtCompileTime : Rhs::RowsAtCompileTime)==1 - }; - public: - enum { - Unrolling = (RhsIsVectorAtCompileTime && Rhs::SizeAtCompileTime != Dynamic && Rhs::SizeAtCompileTime <= 8) - ? CompleteUnrolling : NoUnrolling, - RhsVectors = RhsIsVectorAtCompileTime ? 1 : Dynamic - }; -}; - -template<typename Lhs, typename Rhs, - int Side, // can be OnTheLeft/OnTheRight - int Mode, // can be Upper/Lower | UnitDiag - int Unrolling = trsolve_traits<Lhs,Rhs,Side>::Unrolling, - int RhsVectors = trsolve_traits<Lhs,Rhs,Side>::RhsVectors - > -struct triangular_solver_selector; - -template<typename Lhs, typename Rhs, int Side, int Mode> -struct triangular_solver_selector<Lhs,Rhs,Side,Mode,NoUnrolling,1> -{ - typedef typename Lhs::Scalar LhsScalar; - typedef typename Rhs::Scalar RhsScalar; - typedef blas_traits<Lhs> LhsProductTraits; - typedef typename LhsProductTraits::ExtractType ActualLhsType; - typedef Map<Matrix<RhsScalar,Dynamic,1>, Aligned> MappedRhs; - static void run(const Lhs& lhs, Rhs& rhs) - { - ActualLhsType actualLhs = LhsProductTraits::extract(lhs); - - // FIXME find a way to allow an inner stride if packet_traits<Scalar>::size==1 - - bool useRhsDirectly = Rhs::InnerStrideAtCompileTime==1 || rhs.innerStride()==1; - - ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhs,rhs.size(), - (useRhsDirectly ? rhs.data() : 0)); - - if(!useRhsDirectly) - MappedRhs(actualRhs,rhs.size()) = rhs; - - triangular_solve_vector<LhsScalar, RhsScalar, Index, Side, Mode, LhsProductTraits::NeedToConjugate, - (int(Lhs::Flags) & RowMajorBit) ? RowMajor : ColMajor> - ::run(actualLhs.cols(), actualLhs.data(), actualLhs.outerStride(), actualRhs); - - if(!useRhsDirectly) - rhs = MappedRhs(actualRhs, rhs.size()); - } -}; - -// the rhs is a matrix -template<typename Lhs, typename Rhs, int Side, int Mode> -struct triangular_solver_selector<Lhs,Rhs,Side,Mode,NoUnrolling,Dynamic> -{ - typedef typename Rhs::Scalar Scalar; - typedef blas_traits<Lhs> LhsProductTraits; - typedef typename LhsProductTraits::DirectLinearAccessType ActualLhsType; - - static void run(const Lhs& lhs, Rhs& rhs) - { - typename internal::add_const_on_value_type<ActualLhsType>::type actualLhs = LhsProductTraits::extract(lhs); - - const Index size = lhs.rows(); - const Index othersize = Side==OnTheLeft? rhs.cols() : rhs.rows(); - - typedef internal::gemm_blocking_space<(Rhs::Flags&RowMajorBit) ? RowMajor : ColMajor,Scalar,Scalar, - Rhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxRowsAtCompileTime,4> BlockingType; - - BlockingType blocking(rhs.rows(), rhs.cols(), size, 1, false); - - triangular_solve_matrix<Scalar,Index,Side,Mode,LhsProductTraits::NeedToConjugate,(int(Lhs::Flags) & RowMajorBit) ? RowMajor : ColMajor, - (Rhs::Flags&RowMajorBit) ? RowMajor : ColMajor, Rhs::InnerStrideAtCompileTime> - ::run(size, othersize, &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &rhs.coeffRef(0,0), rhs.innerStride(), rhs.outerStride(), blocking); - } -}; - -/*************************************************************************** -* meta-unrolling implementation -***************************************************************************/ - -template<typename Lhs, typename Rhs, int Mode, int LoopIndex, int Size, - bool Stop = LoopIndex==Size> -struct triangular_solver_unroller; - -template<typename Lhs, typename Rhs, int Mode, int LoopIndex, int Size> -struct triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex,Size,false> { - enum { - IsLower = ((Mode&Lower)==Lower), - DiagIndex = IsLower ? LoopIndex : Size - LoopIndex - 1, - StartIndex = IsLower ? 0 : DiagIndex+1 - }; - static void run(const Lhs& lhs, Rhs& rhs) - { - if (LoopIndex>0) - rhs.coeffRef(DiagIndex) -= lhs.row(DiagIndex).template segment<LoopIndex>(StartIndex).transpose() - .cwiseProduct(rhs.template segment<LoopIndex>(StartIndex)).sum(); - - if(!(Mode & UnitDiag)) - rhs.coeffRef(DiagIndex) /= lhs.coeff(DiagIndex,DiagIndex); - - triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex+1,Size>::run(lhs,rhs); - } -}; - -template<typename Lhs, typename Rhs, int Mode, int LoopIndex, int Size> -struct triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex,Size,true> { - static void run(const Lhs&, Rhs&) {} -}; - -template<typename Lhs, typename Rhs, int Mode> -struct triangular_solver_selector<Lhs,Rhs,OnTheLeft,Mode,CompleteUnrolling,1> { - static void run(const Lhs& lhs, Rhs& rhs) - { triangular_solver_unroller<Lhs,Rhs,Mode,0,Rhs::SizeAtCompileTime>::run(lhs,rhs); } -}; - -template<typename Lhs, typename Rhs, int Mode> -struct triangular_solver_selector<Lhs,Rhs,OnTheRight,Mode,CompleteUnrolling,1> { - static void run(const Lhs& lhs, Rhs& rhs) - { - Transpose<const Lhs> trLhs(lhs); - Transpose<Rhs> trRhs(rhs); - - triangular_solver_unroller<Transpose<const Lhs>,Transpose<Rhs>, - ((Mode&Upper)==Upper ? Lower : Upper) | (Mode&UnitDiag), - 0,Rhs::SizeAtCompileTime>::run(trLhs,trRhs); - } -}; - -} // end namespace internal - -/*************************************************************************** -* TriangularView methods -***************************************************************************/ - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename MatrixType, unsigned int Mode> -template<int Side, typename OtherDerived> -EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType,Mode,Dense>::solveInPlace(const MatrixBase<OtherDerived>& _other) const -{ - OtherDerived& other = _other.const_cast_derived(); - eigen_assert( derived().cols() == derived().rows() && ((Side==OnTheLeft && derived().cols() == other.rows()) || (Side==OnTheRight && derived().cols() == other.cols())) ); - eigen_assert((!(Mode & ZeroDiag)) && bool(Mode & (Upper|Lower))); - // If solving for a 0x0 matrix, nothing to do, simply return. - if (derived().cols() == 0) - return; - - enum { copy = (internal::traits<OtherDerived>::Flags & RowMajorBit) && OtherDerived::IsVectorAtCompileTime && OtherDerived::SizeAtCompileTime!=1}; - typedef typename internal::conditional<copy, - typename internal::plain_matrix_type_column_major<OtherDerived>::type, OtherDerived&>::type OtherCopy; - OtherCopy otherCopy(other); - - internal::triangular_solver_selector<MatrixType, typename internal::remove_reference<OtherCopy>::type, - Side, Mode>::run(derived().nestedExpression(), otherCopy); - - if (copy) - other = otherCopy; -} - -template<typename Derived, unsigned int Mode> -template<int Side, typename Other> -const internal::triangular_solve_retval<Side,TriangularView<Derived,Mode>,Other> -TriangularViewImpl<Derived,Mode,Dense>::solve(const MatrixBase<Other>& other) const -{ - return internal::triangular_solve_retval<Side,TriangularViewType,Other>(derived(), other.derived()); -} -#endif - -namespace internal { - - -template<int Side, typename TriangularType, typename Rhs> -struct traits<triangular_solve_retval<Side, TriangularType, Rhs> > -{ - typedef typename internal::plain_matrix_type_column_major<Rhs>::type ReturnType; -}; - -template<int Side, typename TriangularType, typename Rhs> struct triangular_solve_retval - : public ReturnByValue<triangular_solve_retval<Side, TriangularType, Rhs> > -{ - typedef typename remove_all<typename Rhs::Nested>::type RhsNestedCleaned; - typedef ReturnByValue<triangular_solve_retval> Base; - - triangular_solve_retval(const TriangularType& tri, const Rhs& rhs) - : m_triangularMatrix(tri), m_rhs(rhs) - {} - - inline Index rows() const { return m_rhs.rows(); } - inline Index cols() const { return m_rhs.cols(); } - - template<typename Dest> inline void evalTo(Dest& dst) const - { - if(!is_same_dense(dst,m_rhs)) - dst = m_rhs; - m_triangularMatrix.template solveInPlace<Side>(dst); - } - - protected: - const TriangularType& m_triangularMatrix; - typename Rhs::Nested m_rhs; -}; - -} // namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SOLVETRIANGULAR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/SolverBase.h b/external/eigen/include/eigen3/Eigen/src/Core/SolverBase.h deleted file mode 100644 index 50146104..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/SolverBase.h +++ /dev/null @@ -1,168 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SOLVERBASE_H -#define EIGEN_SOLVERBASE_H - -namespace Eigen { - -namespace internal { - -template<typename Derived> -struct solve_assertion { - template<bool Transpose_, typename Rhs> - static void run(const Derived& solver, const Rhs& b) { solver.template _check_solve_assertion<Transpose_>(b); } -}; - -template<typename Derived> -struct solve_assertion<Transpose<Derived> > -{ - typedef Transpose<Derived> type; - - template<bool Transpose_, typename Rhs> - static void run(const type& transpose, const Rhs& b) - { - internal::solve_assertion<typename internal::remove_all<Derived>::type>::template run<true>(transpose.nestedExpression(), b); - } -}; - -template<typename Scalar, typename Derived> -struct solve_assertion<CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived> > > -{ - typedef CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived> > type; - - template<bool Transpose_, typename Rhs> - static void run(const type& adjoint, const Rhs& b) - { - internal::solve_assertion<typename internal::remove_all<Transpose<Derived> >::type>::template run<true>(adjoint.nestedExpression(), b); - } -}; -} // end namespace internal - -/** \class SolverBase - * \brief A base class for matrix decomposition and solvers - * - * \tparam Derived the actual type of the decomposition/solver. - * - * Any matrix decomposition inheriting this base class provide the following API: - * - * \code - * MatrixType A, b, x; - * DecompositionType dec(A); - * x = dec.solve(b); // solve A * x = b - * x = dec.transpose().solve(b); // solve A^T * x = b - * x = dec.adjoint().solve(b); // solve A' * x = b - * \endcode - * - * \warning Currently, any other usage of transpose() and adjoint() are not supported and will produce compilation errors. - * - * \sa class PartialPivLU, class FullPivLU, class HouseholderQR, class ColPivHouseholderQR, class FullPivHouseholderQR, class CompleteOrthogonalDecomposition, class LLT, class LDLT, class SVDBase - */ -template<typename Derived> -class SolverBase : public EigenBase<Derived> -{ - public: - - typedef EigenBase<Derived> Base; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef Scalar CoeffReturnType; - - template<typename Derived_> - friend struct internal::solve_assertion; - - enum { - RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, - ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, - SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime, - internal::traits<Derived>::ColsAtCompileTime>::ret), - MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime, - MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime, - MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime, - internal::traits<Derived>::MaxColsAtCompileTime>::ret), - IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1 - || internal::traits<Derived>::MaxColsAtCompileTime == 1, - NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2 - }; - - /** Default constructor */ - SolverBase() - {} - - ~SolverBase() - {} - - using Base::derived; - - /** \returns an expression of the solution x of \f$ A x = b \f$ using the current decomposition of A. - */ - template<typename Rhs> - inline const Solve<Derived, Rhs> - solve(const MatrixBase<Rhs>& b) const - { - internal::solve_assertion<typename internal::remove_all<Derived>::type>::template run<false>(derived(), b); - return Solve<Derived, Rhs>(derived(), b.derived()); - } - - /** \internal the return type of transpose() */ - typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType; - /** \returns an expression of the transposed of the factored matrix. - * - * A typical usage is to solve for the transposed problem A^T x = b: - * \code x = dec.transpose().solve(b); \endcode - * - * \sa adjoint(), solve() - */ - inline ConstTransposeReturnType transpose() const - { - return ConstTransposeReturnType(derived()); - } - - /** \internal the return type of adjoint() */ - typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>, - ConstTransposeReturnType - >::type AdjointReturnType; - /** \returns an expression of the adjoint of the factored matrix - * - * A typical usage is to solve for the adjoint problem A' x = b: - * \code x = dec.adjoint().solve(b); \endcode - * - * For real scalar types, this function is equivalent to transpose(). - * - * \sa transpose(), solve() - */ - inline AdjointReturnType adjoint() const - { - return AdjointReturnType(derived().transpose()); - } - - protected: - - template<bool Transpose_, typename Rhs> - void _check_solve_assertion(const Rhs& b) const { - EIGEN_ONLY_USED_FOR_DEBUG(b); - eigen_assert(derived().m_isInitialized && "Solver is not initialized."); - eigen_assert((Transpose_?derived().cols():derived().rows())==b.rows() && "SolverBase::solve(): invalid number of rows of the right hand side matrix b"); - } -}; - -namespace internal { - -template<typename Derived> -struct generic_xpr_base<Derived, MatrixXpr, SolverStorage> -{ - typedef SolverBase<Derived> type; - -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SOLVERBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/StableNorm.h b/external/eigen/include/eigen3/Eigen/src/Core/StableNorm.h deleted file mode 100644 index 77ea3c26..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/StableNorm.h +++ /dev/null @@ -1,264 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STABLENORM_H -#define EIGEN_STABLENORM_H - -namespace Eigen { - -namespace internal { - -template<typename ExpressionType, typename Scalar> -inline void stable_norm_kernel(const ExpressionType& bl, Scalar& ssq, Scalar& scale, Scalar& invScale) -{ - Scalar maxCoeff = bl.cwiseAbs().maxCoeff(); - - if(maxCoeff>scale) - { - ssq = ssq * numext::abs2(scale/maxCoeff); - Scalar tmp = Scalar(1)/maxCoeff; - if(tmp > NumTraits<Scalar>::highest()) - { - invScale = NumTraits<Scalar>::highest(); - scale = Scalar(1)/invScale; - } - else if(maxCoeff>NumTraits<Scalar>::highest()) // we got a INF - { - invScale = Scalar(1); - scale = maxCoeff; - } - else - { - scale = maxCoeff; - invScale = tmp; - } - } - else if(maxCoeff!=maxCoeff) // we got a NaN - { - scale = maxCoeff; - } - - // TODO if the maxCoeff is much much smaller than the current scale, - // then we can neglect this sub vector - if(scale>Scalar(0)) // if scale==0, then bl is 0 - ssq += (bl*invScale).squaredNorm(); -} - -template<typename VectorType, typename RealScalar> -void stable_norm_impl_inner_step(const VectorType &vec, RealScalar& ssq, RealScalar& scale, RealScalar& invScale) -{ - typedef typename VectorType::Scalar Scalar; - const Index blockSize = 4096; - - typedef typename internal::nested_eval<VectorType,2>::type VectorTypeCopy; - typedef typename internal::remove_all<VectorTypeCopy>::type VectorTypeCopyClean; - const VectorTypeCopy copy(vec); - - enum { - CanAlign = ( (int(VectorTypeCopyClean::Flags)&DirectAccessBit) - || (int(internal::evaluator<VectorTypeCopyClean>::Alignment)>0) // FIXME Alignment)>0 might not be enough - ) && (blockSize*sizeof(Scalar)*2<EIGEN_STACK_ALLOCATION_LIMIT) - && (EIGEN_MAX_STATIC_ALIGN_BYTES>0) // if we cannot allocate on the stack, then let's not bother about this optimization - }; - typedef typename internal::conditional<CanAlign, Ref<const Matrix<Scalar,Dynamic,1,0,blockSize,1>, internal::evaluator<VectorTypeCopyClean>::Alignment>, - typename VectorTypeCopyClean::ConstSegmentReturnType>::type SegmentWrapper; - Index n = vec.size(); - - Index bi = internal::first_default_aligned(copy); - if (bi>0) - internal::stable_norm_kernel(copy.head(bi), ssq, scale, invScale); - for (; bi<n; bi+=blockSize) - internal::stable_norm_kernel(SegmentWrapper(copy.segment(bi,numext::mini(blockSize, n - bi))), ssq, scale, invScale); -} - -template<typename VectorType> -typename VectorType::RealScalar -stable_norm_impl(const VectorType &vec, typename enable_if<VectorType::IsVectorAtCompileTime>::type* = 0 ) -{ - using std::sqrt; - using std::abs; - - Index n = vec.size(); - - if(n==1) - return abs(vec.coeff(0)); - - typedef typename VectorType::RealScalar RealScalar; - RealScalar scale(0); - RealScalar invScale(1); - RealScalar ssq(0); // sum of squares - - stable_norm_impl_inner_step(vec, ssq, scale, invScale); - - return scale * sqrt(ssq); -} - -template<typename MatrixType> -typename MatrixType::RealScalar -stable_norm_impl(const MatrixType &mat, typename enable_if<!MatrixType::IsVectorAtCompileTime>::type* = 0 ) -{ - using std::sqrt; - - typedef typename MatrixType::RealScalar RealScalar; - RealScalar scale(0); - RealScalar invScale(1); - RealScalar ssq(0); // sum of squares - - for(Index j=0; j<mat.outerSize(); ++j) - stable_norm_impl_inner_step(mat.innerVector(j), ssq, scale, invScale); - return scale * sqrt(ssq); -} - -template<typename Derived> -inline typename NumTraits<typename traits<Derived>::Scalar>::Real -blueNorm_impl(const EigenBase<Derived>& _vec) -{ - typedef typename Derived::RealScalar RealScalar; - using std::pow; - using std::sqrt; - using std::abs; - const Derived& vec(_vec.derived()); - static bool initialized = false; - static RealScalar b1, b2, s1m, s2m, rbig, relerr; - if(!initialized) - { - int ibeta, it, iemin, iemax, iexp; - RealScalar eps; - // This program calculates the machine-dependent constants - // bl, b2, slm, s2m, relerr overfl - // from the "basic" machine-dependent numbers - // nbig, ibeta, it, iemin, iemax, rbig. - // The following define the basic machine-dependent constants. - // For portability, the PORT subprograms "ilmaeh" and "rlmach" - // are used. For any specific computer, each of the assignment - // statements can be replaced - ibeta = std::numeric_limits<RealScalar>::radix; // base for floating-point numbers - it = NumTraits<RealScalar>::digits(); // number of base-beta digits in mantissa - iemin = std::numeric_limits<RealScalar>::min_exponent; // minimum exponent - iemax = std::numeric_limits<RealScalar>::max_exponent; // maximum exponent - rbig = (std::numeric_limits<RealScalar>::max)(); // largest floating-point number - - iexp = -((1-iemin)/2); - b1 = RealScalar(pow(RealScalar(ibeta),RealScalar(iexp))); // lower boundary of midrange - iexp = (iemax + 1 - it)/2; - b2 = RealScalar(pow(RealScalar(ibeta),RealScalar(iexp))); // upper boundary of midrange - - iexp = (2-iemin)/2; - s1m = RealScalar(pow(RealScalar(ibeta),RealScalar(iexp))); // scaling factor for lower range - iexp = - ((iemax+it)/2); - s2m = RealScalar(pow(RealScalar(ibeta),RealScalar(iexp))); // scaling factor for upper range - - eps = RealScalar(pow(double(ibeta), 1-it)); - relerr = sqrt(eps); // tolerance for neglecting asml - initialized = true; - } - Index n = vec.size(); - RealScalar ab2 = b2 / RealScalar(n); - RealScalar asml = RealScalar(0); - RealScalar amed = RealScalar(0); - RealScalar abig = RealScalar(0); - - for(Index j=0; j<vec.outerSize(); ++j) - { - for(typename Derived::InnerIterator it(vec, j); it; ++it) - { - RealScalar ax = abs(it.value()); - if(ax > ab2) abig += numext::abs2(ax*s2m); - else if(ax < b1) asml += numext::abs2(ax*s1m); - else amed += numext::abs2(ax); - } - } - if(amed!=amed) - return amed; // we got a NaN - if(abig > RealScalar(0)) - { - abig = sqrt(abig); - if(abig > rbig) // overflow, or *this contains INF values - return abig; // return INF - if(amed > RealScalar(0)) - { - abig = abig/s2m; - amed = sqrt(amed); - } - else - return abig/s2m; - } - else if(asml > RealScalar(0)) - { - if (amed > RealScalar(0)) - { - abig = sqrt(amed); - amed = sqrt(asml) / s1m; - } - else - return sqrt(asml)/s1m; - } - else - return sqrt(amed); - asml = numext::mini(abig, amed); - abig = numext::maxi(abig, amed); - if(asml <= abig*relerr) - return abig; - else - return abig * sqrt(RealScalar(1) + numext::abs2(asml/abig)); -} - -} // end namespace internal - -/** \returns the \em l2 norm of \c *this avoiding underflow and overflow. - * This version use a blockwise two passes algorithm: - * 1 - find the absolute largest coefficient \c s - * 2 - compute \f$ s \Vert \frac{*this}{s} \Vert \f$ in a standard way - * - * For architecture/scalar types supporting vectorization, this version - * is faster than blueNorm(). Otherwise the blueNorm() is much faster. - * - * \sa norm(), blueNorm(), hypotNorm() - */ -template<typename Derived> -inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real -MatrixBase<Derived>::stableNorm() const -{ - return internal::stable_norm_impl(derived()); -} - -/** \returns the \em l2 norm of \c *this using the Blue's algorithm. - * A Portable Fortran Program to Find the Euclidean Norm of a Vector, - * ACM TOMS, Vol 4, Issue 1, 1978. - * - * For architecture/scalar types without vectorization, this version - * is much faster than stableNorm(). Otherwise the stableNorm() is faster. - * - * \sa norm(), stableNorm(), hypotNorm() - */ -template<typename Derived> -inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real -MatrixBase<Derived>::blueNorm() const -{ - return internal::blueNorm_impl(*this); -} - -/** \returns the \em l2 norm of \c *this avoiding undeflow and overflow. - * This version use a concatenation of hypot() calls, and it is very slow. - * - * \sa norm(), stableNorm() - */ -template<typename Derived> -inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real -MatrixBase<Derived>::hypotNorm() const -{ - if(size()==1) - return numext::abs(coeff(0,0)); - else - return this->cwiseAbs().redux(internal::scalar_hypot_op<RealScalar>()); -} - -} // end namespace Eigen - -#endif // EIGEN_STABLENORM_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/StlIterators.h b/external/eigen/include/eigen3/Eigen/src/Core/StlIterators.h deleted file mode 100644 index 0d8bd1aa..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/StlIterators.h +++ /dev/null @@ -1,331 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2018 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -namespace Eigen { - -namespace internal { - -template<typename IteratorType> -struct indexed_based_stl_iterator_traits; - -template<typename Derived> -class indexed_based_stl_iterator_base -{ -protected: - typedef indexed_based_stl_iterator_traits<Derived> traits; - typedef typename traits::XprType XprType; - typedef indexed_based_stl_iterator_base<typename traits::non_const_iterator> non_const_iterator; - typedef indexed_based_stl_iterator_base<typename traits::const_iterator> const_iterator; - typedef typename internal::conditional<internal::is_const<XprType>::value,non_const_iterator,const_iterator>::type other_iterator; - // NOTE: in C++03 we cannot declare friend classes through typedefs because we need to write friend class: - friend class indexed_based_stl_iterator_base<typename traits::const_iterator>; - friend class indexed_based_stl_iterator_base<typename traits::non_const_iterator>; -public: - typedef Index difference_type; - typedef std::random_access_iterator_tag iterator_category; - - indexed_based_stl_iterator_base() : mp_xpr(0), m_index(0) {} - indexed_based_stl_iterator_base(XprType& xpr, Index index) : mp_xpr(&xpr), m_index(index) {} - - indexed_based_stl_iterator_base(const non_const_iterator& other) - : mp_xpr(other.mp_xpr), m_index(other.m_index) - {} - - indexed_based_stl_iterator_base& operator=(const non_const_iterator& other) - { - mp_xpr = other.mp_xpr; - m_index = other.m_index; - return *this; - } - - Derived& operator++() { ++m_index; return derived(); } - Derived& operator--() { --m_index; return derived(); } - - Derived operator++(int) { Derived prev(derived()); operator++(); return prev;} - Derived operator--(int) { Derived prev(derived()); operator--(); return prev;} - - friend Derived operator+(const indexed_based_stl_iterator_base& a, Index b) { Derived ret(a.derived()); ret += b; return ret; } - friend Derived operator-(const indexed_based_stl_iterator_base& a, Index b) { Derived ret(a.derived()); ret -= b; return ret; } - friend Derived operator+(Index a, const indexed_based_stl_iterator_base& b) { Derived ret(b.derived()); ret += a; return ret; } - friend Derived operator-(Index a, const indexed_based_stl_iterator_base& b) { Derived ret(b.derived()); ret -= a; return ret; } - - Derived& operator+=(Index b) { m_index += b; return derived(); } - Derived& operator-=(Index b) { m_index -= b; return derived(); } - - difference_type operator-(const indexed_based_stl_iterator_base& other) const - { - eigen_assert(mp_xpr == other.mp_xpr); - return m_index - other.m_index; - } - - difference_type operator-(const other_iterator& other) const - { - eigen_assert(mp_xpr == other.mp_xpr); - return m_index - other.m_index; - } - - bool operator==(const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index == other.m_index; } - bool operator!=(const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index != other.m_index; } - bool operator< (const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index < other.m_index; } - bool operator<=(const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index <= other.m_index; } - bool operator> (const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index > other.m_index; } - bool operator>=(const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index >= other.m_index; } - - bool operator==(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index == other.m_index; } - bool operator!=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index != other.m_index; } - bool operator< (const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index < other.m_index; } - bool operator<=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index <= other.m_index; } - bool operator> (const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index > other.m_index; } - bool operator>=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index >= other.m_index; } - -protected: - - Derived& derived() { return static_cast<Derived&>(*this); } - const Derived& derived() const { return static_cast<const Derived&>(*this); } - - XprType *mp_xpr; - Index m_index; -}; - -template<typename XprType> -class pointer_based_stl_iterator -{ - enum { is_lvalue = internal::is_lvalue<XprType>::value }; - typedef pointer_based_stl_iterator<typename internal::remove_const<XprType>::type> non_const_iterator; - typedef pointer_based_stl_iterator<typename internal::add_const<XprType>::type> const_iterator; - typedef typename internal::conditional<internal::is_const<XprType>::value,non_const_iterator,const_iterator>::type other_iterator; - // NOTE: in C++03 we cannot declare friend classes through typedefs because we need to write friend class: - friend class pointer_based_stl_iterator<typename internal::add_const<XprType>::type>; - friend class pointer_based_stl_iterator<typename internal::remove_const<XprType>::type>; -public: - typedef Index difference_type; - typedef typename XprType::Scalar value_type; - typedef std::random_access_iterator_tag iterator_category; - typedef typename internal::conditional<bool(is_lvalue), value_type*, const value_type*>::type pointer; - typedef typename internal::conditional<bool(is_lvalue), value_type&, const value_type&>::type reference; - - - pointer_based_stl_iterator() : m_ptr(0) {} - pointer_based_stl_iterator(XprType& xpr, Index index) : m_incr(xpr.innerStride()) - { - m_ptr = xpr.data() + index * m_incr.value(); - } - - pointer_based_stl_iterator(const non_const_iterator& other) - : m_ptr(other.m_ptr), m_incr(other.m_incr) - {} - - pointer_based_stl_iterator& operator=(const non_const_iterator& other) - { - m_ptr = other.m_ptr; - m_incr.setValue(other.m_incr); - return *this; - } - - reference operator*() const { return *m_ptr; } - reference operator[](Index i) const { return *(m_ptr+i*m_incr.value()); } - pointer operator->() const { return m_ptr; } - - pointer_based_stl_iterator& operator++() { m_ptr += m_incr.value(); return *this; } - pointer_based_stl_iterator& operator--() { m_ptr -= m_incr.value(); return *this; } - - pointer_based_stl_iterator operator++(int) { pointer_based_stl_iterator prev(*this); operator++(); return prev;} - pointer_based_stl_iterator operator--(int) { pointer_based_stl_iterator prev(*this); operator--(); return prev;} - - friend pointer_based_stl_iterator operator+(const pointer_based_stl_iterator& a, Index b) { pointer_based_stl_iterator ret(a); ret += b; return ret; } - friend pointer_based_stl_iterator operator-(const pointer_based_stl_iterator& a, Index b) { pointer_based_stl_iterator ret(a); ret -= b; return ret; } - friend pointer_based_stl_iterator operator+(Index a, const pointer_based_stl_iterator& b) { pointer_based_stl_iterator ret(b); ret += a; return ret; } - friend pointer_based_stl_iterator operator-(Index a, const pointer_based_stl_iterator& b) { pointer_based_stl_iterator ret(b); ret -= a; return ret; } - - pointer_based_stl_iterator& operator+=(Index b) { m_ptr += b*m_incr.value(); return *this; } - pointer_based_stl_iterator& operator-=(Index b) { m_ptr -= b*m_incr.value(); return *this; } - - difference_type operator-(const pointer_based_stl_iterator& other) const { - return (m_ptr - other.m_ptr)/m_incr.value(); - } - - difference_type operator-(const other_iterator& other) const { - return (m_ptr - other.m_ptr)/m_incr.value(); - } - - bool operator==(const pointer_based_stl_iterator& other) const { return m_ptr == other.m_ptr; } - bool operator!=(const pointer_based_stl_iterator& other) const { return m_ptr != other.m_ptr; } - bool operator< (const pointer_based_stl_iterator& other) const { return m_ptr < other.m_ptr; } - bool operator<=(const pointer_based_stl_iterator& other) const { return m_ptr <= other.m_ptr; } - bool operator> (const pointer_based_stl_iterator& other) const { return m_ptr > other.m_ptr; } - bool operator>=(const pointer_based_stl_iterator& other) const { return m_ptr >= other.m_ptr; } - - bool operator==(const other_iterator& other) const { return m_ptr == other.m_ptr; } - bool operator!=(const other_iterator& other) const { return m_ptr != other.m_ptr; } - bool operator< (const other_iterator& other) const { return m_ptr < other.m_ptr; } - bool operator<=(const other_iterator& other) const { return m_ptr <= other.m_ptr; } - bool operator> (const other_iterator& other) const { return m_ptr > other.m_ptr; } - bool operator>=(const other_iterator& other) const { return m_ptr >= other.m_ptr; } - -protected: - - pointer m_ptr; - internal::variable_if_dynamic<Index, XprType::InnerStrideAtCompileTime> m_incr; -}; - -template<typename _XprType> -struct indexed_based_stl_iterator_traits<generic_randaccess_stl_iterator<_XprType> > -{ - typedef _XprType XprType; - typedef generic_randaccess_stl_iterator<typename internal::remove_const<XprType>::type> non_const_iterator; - typedef generic_randaccess_stl_iterator<typename internal::add_const<XprType>::type> const_iterator; -}; - -template<typename XprType> -class generic_randaccess_stl_iterator : public indexed_based_stl_iterator_base<generic_randaccess_stl_iterator<XprType> > -{ -public: - typedef typename XprType::Scalar value_type; - -protected: - - enum { - has_direct_access = (internal::traits<XprType>::Flags & DirectAccessBit) ? 1 : 0, - is_lvalue = internal::is_lvalue<XprType>::value - }; - - typedef indexed_based_stl_iterator_base<generic_randaccess_stl_iterator> Base; - using Base::m_index; - using Base::mp_xpr; - - // TODO currently const Transpose/Reshape expressions never returns const references, - // so lets return by value too. - //typedef typename internal::conditional<bool(has_direct_access), const value_type&, const value_type>::type read_only_ref_t; - typedef const value_type read_only_ref_t; - -public: - - typedef typename internal::conditional<bool(is_lvalue), value_type *, const value_type *>::type pointer; - typedef typename internal::conditional<bool(is_lvalue), value_type&, read_only_ref_t>::type reference; - - generic_randaccess_stl_iterator() : Base() {} - generic_randaccess_stl_iterator(XprType& xpr, Index index) : Base(xpr,index) {} - generic_randaccess_stl_iterator(const typename Base::non_const_iterator& other) : Base(other) {} - using Base::operator=; - - reference operator*() const { return (*mp_xpr)(m_index); } - reference operator[](Index i) const { return (*mp_xpr)(m_index+i); } - pointer operator->() const { return &((*mp_xpr)(m_index)); } -}; - -template<typename _XprType, DirectionType Direction> -struct indexed_based_stl_iterator_traits<subvector_stl_iterator<_XprType,Direction> > -{ - typedef _XprType XprType; - typedef subvector_stl_iterator<typename internal::remove_const<XprType>::type, Direction> non_const_iterator; - typedef subvector_stl_iterator<typename internal::add_const<XprType>::type, Direction> const_iterator; -}; - -template<typename XprType, DirectionType Direction> -class subvector_stl_iterator : public indexed_based_stl_iterator_base<subvector_stl_iterator<XprType,Direction> > -{ -protected: - - enum { is_lvalue = internal::is_lvalue<XprType>::value }; - - typedef indexed_based_stl_iterator_base<subvector_stl_iterator> Base; - using Base::m_index; - using Base::mp_xpr; - - typedef typename internal::conditional<Direction==Vertical,typename XprType::ColXpr,typename XprType::RowXpr>::type SubVectorType; - typedef typename internal::conditional<Direction==Vertical,typename XprType::ConstColXpr,typename XprType::ConstRowXpr>::type ConstSubVectorType; - - -public: - typedef typename internal::conditional<bool(is_lvalue), SubVectorType, ConstSubVectorType>::type reference; - typedef typename reference::PlainObject value_type; - -private: - class subvector_stl_iterator_ptr - { - public: - subvector_stl_iterator_ptr(const reference &subvector) : m_subvector(subvector) {} - reference* operator->() { return &m_subvector; } - private: - reference m_subvector; - }; -public: - - typedef subvector_stl_iterator_ptr pointer; - - subvector_stl_iterator() : Base() {} - subvector_stl_iterator(XprType& xpr, Index index) : Base(xpr,index) {} - - reference operator*() const { return (*mp_xpr).template subVector<Direction>(m_index); } - reference operator[](Index i) const { return (*mp_xpr).template subVector<Direction>(m_index+i); } - pointer operator->() const { return (*mp_xpr).template subVector<Direction>(m_index); } -}; - -} // namespace internal - - -/** returns an iterator to the first element of the 1D vector or array - * \only_for_vectors - * \sa end(), cbegin() - */ -template<typename Derived> -inline typename DenseBase<Derived>::iterator DenseBase<Derived>::begin() -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return iterator(derived(), 0); -} - -/** const version of begin() */ -template<typename Derived> -inline typename DenseBase<Derived>::const_iterator DenseBase<Derived>::begin() const -{ - return cbegin(); -} - -/** returns a read-only const_iterator to the first element of the 1D vector or array - * \only_for_vectors - * \sa cend(), begin() - */ -template<typename Derived> -inline typename DenseBase<Derived>::const_iterator DenseBase<Derived>::cbegin() const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return const_iterator(derived(), 0); -} - -/** returns an iterator to the element following the last element of the 1D vector or array - * \only_for_vectors - * \sa begin(), cend() - */ -template<typename Derived> -inline typename DenseBase<Derived>::iterator DenseBase<Derived>::end() -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return iterator(derived(), size()); -} - -/** const version of end() */ -template<typename Derived> -inline typename DenseBase<Derived>::const_iterator DenseBase<Derived>::end() const -{ - return cend(); -} - -/** returns a read-only const_iterator to the element following the last element of the 1D vector or array - * \only_for_vectors - * \sa begin(), cend() - */ -template<typename Derived> -inline typename DenseBase<Derived>::const_iterator DenseBase<Derived>::cend() const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return const_iterator(derived(), size()); -} - -} // namespace Eigen diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Stride.h b/external/eigen/include/eigen3/Eigen/src/Core/Stride.h deleted file mode 100644 index 513742f3..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Stride.h +++ /dev/null @@ -1,111 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STRIDE_H -#define EIGEN_STRIDE_H - -namespace Eigen { - -/** \class Stride - * \ingroup Core_Module - * - * \brief Holds strides information for Map - * - * This class holds the strides information for mapping arrays with strides with class Map. - * - * It holds two values: the inner stride and the outer stride. - * - * The inner stride is the pointer increment between two consecutive entries within a given row of a - * row-major matrix or within a given column of a column-major matrix. - * - * The outer stride is the pointer increment between two consecutive rows of a row-major matrix or - * between two consecutive columns of a column-major matrix. - * - * These two values can be passed either at compile-time as template parameters, or at runtime as - * arguments to the constructor. - * - * Indeed, this class takes two template parameters: - * \tparam _OuterStrideAtCompileTime the outer stride, or Dynamic if you want to specify it at runtime. - * \tparam _InnerStrideAtCompileTime the inner stride, or Dynamic if you want to specify it at runtime. - * - * Here is an example: - * \include Map_general_stride.cpp - * Output: \verbinclude Map_general_stride.out - * - * \sa class InnerStride, class OuterStride, \ref TopicStorageOrders - */ -template<int _OuterStrideAtCompileTime, int _InnerStrideAtCompileTime> -class Stride -{ - public: - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - enum { - InnerStrideAtCompileTime = _InnerStrideAtCompileTime, - OuterStrideAtCompileTime = _OuterStrideAtCompileTime - }; - - /** Default constructor, for use when strides are fixed at compile time */ - EIGEN_DEVICE_FUNC - Stride() - : m_outer(OuterStrideAtCompileTime), m_inner(InnerStrideAtCompileTime) - { - eigen_assert(InnerStrideAtCompileTime != Dynamic && OuterStrideAtCompileTime != Dynamic); - } - - /** Constructor allowing to pass the strides at runtime */ - EIGEN_DEVICE_FUNC - Stride(Index outerStride, Index innerStride) - : m_outer(outerStride), m_inner(innerStride) - { - eigen_assert(innerStride>=0 && outerStride>=0); - } - - /** Copy constructor */ - EIGEN_DEVICE_FUNC - Stride(const Stride& other) - : m_outer(other.outer()), m_inner(other.inner()) - {} - - /** \returns the outer stride */ - EIGEN_DEVICE_FUNC - inline Index outer() const { return m_outer.value(); } - /** \returns the inner stride */ - EIGEN_DEVICE_FUNC - inline Index inner() const { return m_inner.value(); } - - protected: - internal::variable_if_dynamic<Index, OuterStrideAtCompileTime> m_outer; - internal::variable_if_dynamic<Index, InnerStrideAtCompileTime> m_inner; -}; - -/** \brief Convenience specialization of Stride to specify only an inner stride - * See class Map for some examples */ -template<int Value> -class InnerStride : public Stride<0, Value> -{ - typedef Stride<0, Value> Base; - public: - EIGEN_DEVICE_FUNC InnerStride() : Base() {} - EIGEN_DEVICE_FUNC InnerStride(Index v) : Base(0, v) {} // FIXME making this explicit could break valid code -}; - -/** \brief Convenience specialization of Stride to specify only an outer stride - * See class Map for some examples */ -template<int Value> -class OuterStride : public Stride<Value, 0> -{ - typedef Stride<Value, 0> Base; - public: - EIGEN_DEVICE_FUNC OuterStride() : Base() {} - EIGEN_DEVICE_FUNC OuterStride(Index v) : Base(v,0) {} // FIXME making this explicit could break valid code -}; - -} // end namespace Eigen - -#endif // EIGEN_STRIDE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Swap.h b/external/eigen/include/eigen3/Eigen/src/Core/Swap.h deleted file mode 100644 index 180a4e5a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Swap.h +++ /dev/null @@ -1,68 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SWAP_H -#define EIGEN_SWAP_H - -namespace Eigen { - -namespace internal { - -// Overload default assignPacket behavior for swapping them -template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT> -class generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, Specialized> - : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn> -{ -protected: - typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn> Base; - using Base::m_dst; - using Base::m_src; - using Base::m_functor; - -public: - typedef typename Base::Scalar Scalar; - typedef typename Base::DstXprType DstXprType; - typedef swap_assign_op<Scalar> Functor; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - generic_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType& dstExpr) - : Base(dst, src, func, dstExpr) - {} - - template<int StoreMode, int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE void assignPacket(Index row, Index col) - { - PacketType tmp = m_src.template packet<LoadMode,PacketType>(row,col); - const_cast<SrcEvaluatorTypeT&>(m_src).template writePacket<LoadMode>(row,col, m_dst.template packet<StoreMode,PacketType>(row,col)); - m_dst.template writePacket<StoreMode>(row,col,tmp); - } - - template<int StoreMode, int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE void assignPacket(Index index) - { - PacketType tmp = m_src.template packet<LoadMode,PacketType>(index); - const_cast<SrcEvaluatorTypeT&>(m_src).template writePacket<LoadMode>(index, m_dst.template packet<StoreMode,PacketType>(index)); - m_dst.template writePacket<StoreMode>(index,tmp); - } - - // TODO find a simple way not to have to copy/paste this function from generic_dense_assignment_kernel, by simple I mean no CRTP (Gael) - template<int StoreMode, int LoadMode, typename PacketType> - EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner) - { - Index row = Base::rowIndexByOuterInner(outer, inner); - Index col = Base::colIndexByOuterInner(outer, inner); - assignPacket<StoreMode,LoadMode,PacketType>(row, col); - } -}; - -} // namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SWAP_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Transpose.h b/external/eigen/include/eigen3/Eigen/src/Core/Transpose.h deleted file mode 100644 index 6dafe1b1..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Transpose.h +++ /dev/null @@ -1,415 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRANSPOSE_H -#define EIGEN_TRANSPOSE_H - -namespace Eigen { - -namespace internal { -template<typename MatrixType> -struct traits<Transpose<MatrixType> > : public traits<MatrixType> -{ - typedef typename ref_selector<MatrixType>::type MatrixTypeNested; - typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedPlain; - enum { - RowsAtCompileTime = MatrixType::ColsAtCompileTime, - ColsAtCompileTime = MatrixType::RowsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, - Flags0 = traits<MatrixTypeNestedPlain>::Flags & ~(LvalueBit | NestByRefBit), - Flags1 = Flags0 | FlagsLvalueBit, - Flags = Flags1 ^ RowMajorBit, - InnerStrideAtCompileTime = inner_stride_at_compile_time<MatrixType>::ret, - OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret - }; -}; -} - -template<typename MatrixType, typename StorageKind> class TransposeImpl; - -/** \class Transpose - * \ingroup Core_Module - * - * \brief Expression of the transpose of a matrix - * - * \tparam MatrixType the type of the object of which we are taking the transpose - * - * This class represents an expression of the transpose of a matrix. - * It is the return type of MatrixBase::transpose() and MatrixBase::adjoint() - * and most of the time this is the only way it is used. - * - * \sa MatrixBase::transpose(), MatrixBase::adjoint() - */ -template<typename MatrixType> class Transpose - : public TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind> -{ - public: - - typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested; - - typedef typename TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose) - typedef typename internal::remove_all<MatrixType>::type NestedExpression; - - EIGEN_DEVICE_FUNC - explicit EIGEN_STRONG_INLINE Transpose(MatrixType& matrix) : m_matrix(matrix) {} - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose) - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index rows() const { return m_matrix.cols(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index cols() const { return m_matrix.rows(); } - - /** \returns the nested expression */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const typename internal::remove_all<MatrixTypeNested>::type& - nestedExpression() const { return m_matrix; } - - /** \returns the nested expression */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename internal::remove_reference<MatrixTypeNested>::type& - nestedExpression() { return m_matrix; } - - /** \internal */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void resize(Index nrows, Index ncols) { - m_matrix.resize(ncols,nrows); - } - - protected: - typename internal::ref_selector<MatrixType>::non_const_type m_matrix; -}; - -namespace internal { - -template<typename MatrixType, bool HasDirectAccess = has_direct_access<MatrixType>::ret> -struct TransposeImpl_base -{ - typedef typename dense_xpr_base<Transpose<MatrixType> >::type type; -}; - -template<typename MatrixType> -struct TransposeImpl_base<MatrixType, false> -{ - typedef typename dense_xpr_base<Transpose<MatrixType> >::type type; -}; - -} // end namespace internal - -// Generic API dispatcher -template<typename XprType, typename StorageKind> -class TransposeImpl - : public internal::generic_xpr_base<Transpose<XprType> >::type -{ -public: - typedef typename internal::generic_xpr_base<Transpose<XprType> >::type Base; -}; - -template<typename MatrixType> class TransposeImpl<MatrixType,Dense> - : public internal::TransposeImpl_base<MatrixType>::type -{ - public: - - typedef typename internal::TransposeImpl_base<MatrixType>::type Base; - using Base::coeffRef; - EIGEN_DENSE_PUBLIC_INTERFACE(Transpose<MatrixType>) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TransposeImpl) - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index innerStride() const { return derived().nestedExpression().innerStride(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index outerStride() const { return derived().nestedExpression().outerStride(); } - - typedef typename internal::conditional< - internal::is_lvalue<MatrixType>::value, - Scalar, - const Scalar - >::type ScalarWithConstIfNotLvalue; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - ScalarWithConstIfNotLvalue* data() { return derived().nestedExpression().data(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Scalar* data() const { return derived().nestedExpression().data(); } - - // FIXME: shall we keep the const version of coeffRef? - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Scalar& coeffRef(Index rowId, Index colId) const - { - return derived().nestedExpression().coeffRef(colId, rowId); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Scalar& coeffRef(Index index) const - { - return derived().nestedExpression().coeffRef(index); - } - protected: - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TransposeImpl) -}; - -/** \returns an expression of the transpose of *this. - * - * Example: \include MatrixBase_transpose.cpp - * Output: \verbinclude MatrixBase_transpose.out - * - * \warning If you want to replace a matrix by its own transpose, do \b NOT do this: - * \code - * m = m.transpose(); // bug!!! caused by aliasing effect - * \endcode - * Instead, use the transposeInPlace() method: - * \code - * m.transposeInPlace(); - * \endcode - * which gives Eigen good opportunities for optimization, or alternatively you can also do: - * \code - * m = m.transpose().eval(); - * \endcode - * - * \sa transposeInPlace(), adjoint() */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -Transpose<Derived> -DenseBase<Derived>::transpose() -{ - return TransposeReturnType(derived()); -} - -/** This is the const version of transpose(). - * - * Make sure you read the warning for transpose() ! - * - * \sa transposeInPlace(), adjoint() */ -template<typename Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename DenseBase<Derived>::ConstTransposeReturnType -DenseBase<Derived>::transpose() const -{ - return ConstTransposeReturnType(derived()); -} - -/** \returns an expression of the adjoint (i.e. conjugate transpose) of *this. - * - * Example: \include MatrixBase_adjoint.cpp - * Output: \verbinclude MatrixBase_adjoint.out - * - * \warning If you want to replace a matrix by its own adjoint, do \b NOT do this: - * \code - * m = m.adjoint(); // bug!!! caused by aliasing effect - * \endcode - * Instead, use the adjointInPlace() method: - * \code - * m.adjointInPlace(); - * \endcode - * which gives Eigen good opportunities for optimization, or alternatively you can also do: - * \code - * m = m.adjoint().eval(); - * \endcode - * - * \sa adjointInPlace(), transpose(), conjugate(), class Transpose, class internal::scalar_conjugate_op */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline const typename MatrixBase<Derived>::AdjointReturnType -MatrixBase<Derived>::adjoint() const -{ - return AdjointReturnType(this->transpose()); -} - -/*************************************************************************** -* "in place" transpose implementation -***************************************************************************/ - -namespace internal { - -template<typename MatrixType, - bool IsSquare = (MatrixType::RowsAtCompileTime == MatrixType::ColsAtCompileTime) && MatrixType::RowsAtCompileTime!=Dynamic, - bool MatchPacketSize = - (int(MatrixType::RowsAtCompileTime) == int(internal::packet_traits<typename MatrixType::Scalar>::size)) - && (internal::evaluator<MatrixType>::Flags&PacketAccessBit) > -struct inplace_transpose_selector; - -template<typename MatrixType> -struct inplace_transpose_selector<MatrixType,true,false> { // square matrix - static void run(MatrixType& m) { - m.matrix().template triangularView<StrictlyUpper>().swap(m.matrix().transpose().template triangularView<StrictlyUpper>()); - } -}; - -// TODO: vectorized path is currently limited to LargestPacketSize x LargestPacketSize cases only. -template<typename MatrixType> -struct inplace_transpose_selector<MatrixType,true,true> { // PacketSize x PacketSize - static void run(MatrixType& m) { - typedef typename MatrixType::Scalar Scalar; - typedef typename internal::packet_traits<typename MatrixType::Scalar>::type Packet; - const Index PacketSize = internal::packet_traits<Scalar>::size; - const Index Alignment = internal::evaluator<MatrixType>::Alignment; - PacketBlock<Packet> A; - for (Index i=0; i<PacketSize; ++i) - A.packet[i] = m.template packetByOuterInner<Alignment>(i,0); - internal::ptranspose(A); - for (Index i=0; i<PacketSize; ++i) - m.template writePacket<Alignment>(m.rowIndexByOuterInner(i,0), m.colIndexByOuterInner(i,0), A.packet[i]); - } -}; - -template<typename MatrixType,bool MatchPacketSize> -struct inplace_transpose_selector<MatrixType,false,MatchPacketSize> { // non square matrix - static void run(MatrixType& m) { - if (m.rows()==m.cols()) - m.matrix().template triangularView<StrictlyUpper>().swap(m.matrix().transpose().template triangularView<StrictlyUpper>()); - else - m = m.transpose().eval(); - } -}; - -} // end namespace internal - -/** This is the "in place" version of transpose(): it replaces \c *this by its own transpose. - * Thus, doing - * \code - * m.transposeInPlace(); - * \endcode - * has the same effect on m as doing - * \code - * m = m.transpose().eval(); - * \endcode - * and is faster and also safer because in the latter line of code, forgetting the eval() results - * in a bug caused by \ref TopicAliasing "aliasing". - * - * Notice however that this method is only useful if you want to replace a matrix by its own transpose. - * If you just need the transpose of a matrix, use transpose(). - * - * \note if the matrix is not square, then \c *this must be a resizable matrix. - * This excludes (non-square) fixed-size matrices, block-expressions and maps. - * - * \sa transpose(), adjoint(), adjointInPlace() */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline void DenseBase<Derived>::transposeInPlace() -{ - eigen_assert((rows() == cols() || (RowsAtCompileTime == Dynamic && ColsAtCompileTime == Dynamic)) - && "transposeInPlace() called on a non-square non-resizable matrix"); - internal::inplace_transpose_selector<Derived>::run(derived()); -} - -/*************************************************************************** -* "in place" adjoint implementation -***************************************************************************/ - -/** This is the "in place" version of adjoint(): it replaces \c *this by its own transpose. - * Thus, doing - * \code - * m.adjointInPlace(); - * \endcode - * has the same effect on m as doing - * \code - * m = m.adjoint().eval(); - * \endcode - * and is faster and also safer because in the latter line of code, forgetting the eval() results - * in a bug caused by aliasing. - * - * Notice however that this method is only useful if you want to replace a matrix by its own adjoint. - * If you just need the adjoint of a matrix, use adjoint(). - * - * \note if the matrix is not square, then \c *this must be a resizable matrix. - * This excludes (non-square) fixed-size matrices, block-expressions and maps. - * - * \sa transpose(), adjoint(), transposeInPlace() */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline void MatrixBase<Derived>::adjointInPlace() -{ - derived() = adjoint().eval(); -} - -#ifndef EIGEN_NO_DEBUG - -// The following is to detect aliasing problems in most common cases. - -namespace internal { - -template<bool DestIsTransposed, typename OtherDerived> -struct check_transpose_aliasing_compile_time_selector -{ - enum { ret = bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed }; -}; - -template<bool DestIsTransposed, typename BinOp, typename DerivedA, typename DerivedB> -struct check_transpose_aliasing_compile_time_selector<DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> > -{ - enum { ret = bool(blas_traits<DerivedA>::IsTransposed) != DestIsTransposed - || bool(blas_traits<DerivedB>::IsTransposed) != DestIsTransposed - }; -}; - -template<typename Scalar, bool DestIsTransposed, typename OtherDerived> -struct check_transpose_aliasing_run_time_selector -{ - static bool run(const Scalar* dest, const OtherDerived& src) - { - return (bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed) && (dest!=0 && dest==(const Scalar*)extract_data(src)); - } -}; - -template<typename Scalar, bool DestIsTransposed, typename BinOp, typename DerivedA, typename DerivedB> -struct check_transpose_aliasing_run_time_selector<Scalar,DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> > -{ - static bool run(const Scalar* dest, const CwiseBinaryOp<BinOp,DerivedA,DerivedB>& src) - { - return ((blas_traits<DerivedA>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(const Scalar*)extract_data(src.lhs()))) - || ((blas_traits<DerivedB>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(const Scalar*)extract_data(src.rhs()))); - } -}; - -// the following selector, checkTransposeAliasing_impl, based on MightHaveTransposeAliasing, -// is because when the condition controlling the assert is known at compile time, ICC emits a warning. -// This is actually a good warning: in expressions that don't have any transposing, the condition is -// known at compile time to be false, and using that, we can avoid generating the code of the assert again -// and again for all these expressions that don't need it. - -template<typename Derived, typename OtherDerived, - bool MightHaveTransposeAliasing - = check_transpose_aliasing_compile_time_selector - <blas_traits<Derived>::IsTransposed,OtherDerived>::ret - > -struct checkTransposeAliasing_impl -{ - static void run(const Derived& dst, const OtherDerived& other) - { - eigen_assert((!check_transpose_aliasing_run_time_selector - <typename Derived::Scalar,blas_traits<Derived>::IsTransposed,OtherDerived> - ::run(extract_data(dst), other)) - && "aliasing detected during transposition, use transposeInPlace() " - "or evaluate the rhs into a temporary using .eval()"); - - } -}; - -template<typename Derived, typename OtherDerived> -struct checkTransposeAliasing_impl<Derived, OtherDerived, false> -{ - static void run(const Derived&, const OtherDerived&) - { - } -}; - -template<typename Dst, typename Src> -void check_for_aliasing(const Dst &dst, const Src &src) -{ - if((!Dst::IsVectorAtCompileTime) && dst.rows()>1 && dst.cols()>1) - internal::checkTransposeAliasing_impl<Dst, Src>::run(dst, src); -} - -} // end namespace internal - -#endif // EIGEN_NO_DEBUG - -} // end namespace Eigen - -#endif // EIGEN_TRANSPOSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Transpositions.h b/external/eigen/include/eigen3/Eigen/src/Core/Transpositions.h deleted file mode 100644 index f6d02f7d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Transpositions.h +++ /dev/null @@ -1,368 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010-2011 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRANSPOSITIONS_H -#define EIGEN_TRANSPOSITIONS_H - -namespace Eigen { - -template<typename Derived> -class TranspositionsBase -{ - typedef internal::traits<Derived> Traits; - - public: - - typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar StorageIndex; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - Derived& derived() { return *static_cast<Derived*>(this); } - const Derived& derived() const { return *static_cast<const Derived*>(this); } - - /** Copies the \a other transpositions into \c *this */ - template<typename OtherDerived> - Derived& operator=(const TranspositionsBase<OtherDerived>& other) - { - indices() = other.indices(); - return derived(); - } - - /** \returns the number of transpositions */ - Index size() const { return indices().size(); } - /** \returns the number of rows of the equivalent permutation matrix */ - Index rows() const { return indices().size(); } - /** \returns the number of columns of the equivalent permutation matrix */ - Index cols() const { return indices().size(); } - - /** Direct access to the underlying index vector */ - inline const StorageIndex& coeff(Index i) const { return indices().coeff(i); } - /** Direct access to the underlying index vector */ - inline StorageIndex& coeffRef(Index i) { return indices().coeffRef(i); } - /** Direct access to the underlying index vector */ - inline const StorageIndex& operator()(Index i) const { return indices()(i); } - /** Direct access to the underlying index vector */ - inline StorageIndex& operator()(Index i) { return indices()(i); } - /** Direct access to the underlying index vector */ - inline const StorageIndex& operator[](Index i) const { return indices()(i); } - /** Direct access to the underlying index vector */ - inline StorageIndex& operator[](Index i) { return indices()(i); } - - /** const version of indices(). */ - const IndicesType& indices() const { return derived().indices(); } - /** \returns a reference to the stored array representing the transpositions. */ - IndicesType& indices() { return derived().indices(); } - - /** Resizes to given size. */ - inline void resize(Index newSize) - { - indices().resize(newSize); - } - - /** Sets \c *this to represents an identity transformation */ - void setIdentity() - { - for(StorageIndex i = 0; i < indices().size(); ++i) - coeffRef(i) = i; - } - - // FIXME: do we want such methods ? - // might be useful when the target matrix expression is complex, e.g.: - // object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..); - /* - template<typename MatrixType> - void applyForwardToRows(MatrixType& mat) const - { - for(Index k=0 ; k<size() ; ++k) - if(m_indices(k)!=k) - mat.row(k).swap(mat.row(m_indices(k))); - } - - template<typename MatrixType> - void applyBackwardToRows(MatrixType& mat) const - { - for(Index k=size()-1 ; k>=0 ; --k) - if(m_indices(k)!=k) - mat.row(k).swap(mat.row(m_indices(k))); - } - */ - - /** \returns the inverse transformation */ - inline Transpose<TranspositionsBase> inverse() const - { return Transpose<TranspositionsBase>(derived()); } - - /** \returns the tranpose transformation */ - inline Transpose<TranspositionsBase> transpose() const - { return Transpose<TranspositionsBase>(derived()); } - - protected: -}; - -namespace internal { -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex> -struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> > - : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> > -{ - typedef Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType; - typedef TranspositionsStorage StorageKind; -}; -} - -/** \class Transpositions - * \ingroup Core_Module - * - * \brief Represents a sequence of transpositions (row/column interchange) - * - * \tparam SizeAtCompileTime the number of transpositions, or Dynamic - * \tparam MaxSizeAtCompileTime the maximum number of transpositions, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it. - * - * This class represents a permutation transformation as a sequence of \em n transpositions - * \f$[T_{n-1} \ldots T_{i} \ldots T_{0}]\f$. It is internally stored as a vector of integers \c indices. - * Each transposition \f$ T_{i} \f$ applied on the left of a matrix (\f$ T_{i} M\f$) interchanges - * the rows \c i and \c indices[i] of the matrix \c M. - * A transposition applied on the right (e.g., \f$ M T_{i}\f$) yields a column interchange. - * - * Compared to the class PermutationMatrix, such a sequence of transpositions is what is - * computed during a decomposition with pivoting, and it is faster when applying the permutation in-place. - * - * To apply a sequence of transpositions to a matrix, simply use the operator * as in the following example: - * \code - * Transpositions tr; - * MatrixXf mat; - * mat = tr * mat; - * \endcode - * In this example, we detect that the matrix appears on both side, and so the transpositions - * are applied in-place without any temporary or extra copy. - * - * \sa class PermutationMatrix - */ - -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex> -class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> > -{ - typedef internal::traits<Transpositions> Traits; - public: - - typedef TranspositionsBase<Transpositions> Base; - typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar StorageIndex; - - inline Transpositions() {} - - /** Copy constructor. */ - template<typename OtherDerived> - inline Transpositions(const TranspositionsBase<OtherDerived>& other) - : m_indices(other.indices()) {} - - /** Generic constructor from expression of the transposition indices. */ - template<typename Other> - explicit inline Transpositions(const MatrixBase<Other>& indices) : m_indices(indices) - {} - - /** Copies the \a other transpositions into \c *this */ - template<typename OtherDerived> - Transpositions& operator=(const TranspositionsBase<OtherDerived>& other) - { - return Base::operator=(other); - } - - /** Constructs an uninitialized permutation matrix of given size. - */ - inline Transpositions(Index size) : m_indices(size) - {} - - /** const version of indices(). */ - const IndicesType& indices() const { return m_indices; } - /** \returns a reference to the stored array representing the transpositions. */ - IndicesType& indices() { return m_indices; } - - protected: - - IndicesType m_indices; -}; - - -namespace internal { -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess> -struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,_PacketAccess> > - : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> > -{ - typedef Map<const Matrix<_StorageIndex,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType; - typedef _StorageIndex StorageIndex; - typedef TranspositionsStorage StorageKind; -}; -} - -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int PacketAccess> -class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess> - : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess> > -{ - typedef internal::traits<Map> Traits; - public: - - typedef TranspositionsBase<Map> Base; - typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar StorageIndex; - - explicit inline Map(const StorageIndex* indicesPtr) - : m_indices(indicesPtr) - {} - - inline Map(const StorageIndex* indicesPtr, Index size) - : m_indices(indicesPtr,size) - {} - - /** Copies the \a other transpositions into \c *this */ - template<typename OtherDerived> - Map& operator=(const TranspositionsBase<OtherDerived>& other) - { - return Base::operator=(other); - } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /** This is a special case of the templated operator=. Its purpose is to - * prevent a default operator= from hiding the templated operator=. - */ - Map& operator=(const Map& other) - { - m_indices = other.m_indices; - return *this; - } - #endif - - /** const version of indices(). */ - const IndicesType& indices() const { return m_indices; } - - /** \returns a reference to the stored array representing the transpositions. */ - IndicesType& indices() { return m_indices; } - - protected: - - IndicesType m_indices; -}; - -namespace internal { -template<typename _IndicesType> -struct traits<TranspositionsWrapper<_IndicesType> > - : traits<PermutationWrapper<_IndicesType> > -{ - typedef TranspositionsStorage StorageKind; -}; -} - -template<typename _IndicesType> -class TranspositionsWrapper - : public TranspositionsBase<TranspositionsWrapper<_IndicesType> > -{ - typedef internal::traits<TranspositionsWrapper> Traits; - public: - - typedef TranspositionsBase<TranspositionsWrapper> Base; - typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar StorageIndex; - - explicit inline TranspositionsWrapper(IndicesType& indices) - : m_indices(indices) - {} - - /** Copies the \a other transpositions into \c *this */ - template<typename OtherDerived> - TranspositionsWrapper& operator=(const TranspositionsBase<OtherDerived>& other) - { - return Base::operator=(other); - } - - /** const version of indices(). */ - const IndicesType& indices() const { return m_indices; } - - /** \returns a reference to the stored array representing the transpositions. */ - IndicesType& indices() { return m_indices; } - - protected: - - typename IndicesType::Nested m_indices; -}; - - - -/** \returns the \a matrix with the \a transpositions applied to the columns. - */ -template<typename MatrixDerived, typename TranspositionsDerived> -EIGEN_DEVICE_FUNC -const Product<MatrixDerived, TranspositionsDerived, AliasFreeProduct> -operator*(const MatrixBase<MatrixDerived> &matrix, - const TranspositionsBase<TranspositionsDerived>& transpositions) -{ - return Product<MatrixDerived, TranspositionsDerived, AliasFreeProduct> - (matrix.derived(), transpositions.derived()); -} - -/** \returns the \a matrix with the \a transpositions applied to the rows. - */ -template<typename TranspositionsDerived, typename MatrixDerived> -EIGEN_DEVICE_FUNC -const Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct> -operator*(const TranspositionsBase<TranspositionsDerived> &transpositions, - const MatrixBase<MatrixDerived>& matrix) -{ - return Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct> - (transpositions.derived(), matrix.derived()); -} - -// Template partial specialization for transposed/inverse transpositions - -namespace internal { - -template<typename Derived> -struct traits<Transpose<TranspositionsBase<Derived> > > - : traits<Derived> -{}; - -} // end namespace internal - -template<typename TranspositionsDerived> -class Transpose<TranspositionsBase<TranspositionsDerived> > -{ - typedef TranspositionsDerived TranspositionType; - typedef typename TranspositionType::IndicesType IndicesType; - public: - - explicit Transpose(const TranspositionType& t) : m_transpositions(t) {} - - Index size() const { return m_transpositions.size(); } - Index rows() const { return m_transpositions.size(); } - Index cols() const { return m_transpositions.size(); } - - /** \returns the \a matrix with the inverse transpositions applied to the columns. - */ - template<typename OtherDerived> friend - const Product<OtherDerived, Transpose, AliasFreeProduct> - operator*(const MatrixBase<OtherDerived>& matrix, const Transpose& trt) - { - return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt); - } - - /** \returns the \a matrix with the inverse transpositions applied to the rows. - */ - template<typename OtherDerived> - const Product<Transpose, OtherDerived, AliasFreeProduct> - operator*(const MatrixBase<OtherDerived>& matrix) const - { - return Product<Transpose, OtherDerived, AliasFreeProduct>(*this, matrix.derived()); - } - - const TranspositionType& nestedExpression() const { return m_transpositions; } - - protected: - const TranspositionType& m_transpositions; -}; - -} // end namespace Eigen - -#endif // EIGEN_TRANSPOSITIONS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/TriangularMatrix.h b/external/eigen/include/eigen3/Eigen/src/Core/TriangularMatrix.h deleted file mode 100644 index 5e2f2de1..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/TriangularMatrix.h +++ /dev/null @@ -1,1001 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRIANGULARMATRIX_H -#define EIGEN_TRIANGULARMATRIX_H - -namespace Eigen { - -namespace internal { - -template<int Side, typename TriangularType, typename Rhs> struct triangular_solve_retval; - -} - -/** \class TriangularBase - * \ingroup Core_Module - * - * \brief Base class for triangular part in a matrix - */ -template<typename Derived> class TriangularBase : public EigenBase<Derived> -{ - public: - - enum { - Mode = internal::traits<Derived>::Mode, - RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, - ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, - MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime, - MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime, - - SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime, - internal::traits<Derived>::ColsAtCompileTime>::ret), - /**< This is equal to the number of coefficients, i.e. the number of - * rows times the number of columns, or to \a Dynamic if this is not - * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ - - MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime, - internal::traits<Derived>::MaxColsAtCompileTime>::ret) - - }; - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::traits<Derived>::StorageIndex StorageIndex; - typedef typename internal::traits<Derived>::FullMatrixType DenseMatrixType; - typedef DenseMatrixType DenseType; - typedef Derived const& Nested; - - EIGEN_DEVICE_FUNC - inline TriangularBase() { eigen_assert(!((Mode&UnitDiag) && (Mode&ZeroDiag))); } - - EIGEN_DEVICE_FUNC - inline Index rows() const { return derived().rows(); } - EIGEN_DEVICE_FUNC - inline Index cols() const { return derived().cols(); } - EIGEN_DEVICE_FUNC - inline Index outerStride() const { return derived().outerStride(); } - EIGEN_DEVICE_FUNC - inline Index innerStride() const { return derived().innerStride(); } - - // dummy resize function - EIGEN_DEVICE_FUNC - void resize(Index rows, Index cols) - { - EIGEN_UNUSED_VARIABLE(rows); - EIGEN_UNUSED_VARIABLE(cols); - eigen_assert(rows==this->rows() && cols==this->cols()); - } - - EIGEN_DEVICE_FUNC - inline Scalar coeff(Index row, Index col) const { return derived().coeff(row,col); } - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index row, Index col) { return derived().coeffRef(row,col); } - - /** \see MatrixBase::copyCoeff(row,col) - */ - template<typename Other> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, Other& other) - { - derived().coeffRef(row, col) = other.coeff(row, col); - } - - EIGEN_DEVICE_FUNC - inline Scalar operator()(Index row, Index col) const - { - check_coordinates(row, col); - return coeff(row,col); - } - EIGEN_DEVICE_FUNC - inline Scalar& operator()(Index row, Index col) - { - check_coordinates(row, col); - return coeffRef(row,col); - } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - EIGEN_DEVICE_FUNC - inline const Derived& derived() const { return *static_cast<const Derived*>(this); } - EIGEN_DEVICE_FUNC - inline Derived& derived() { return *static_cast<Derived*>(this); } - #endif // not EIGEN_PARSED_BY_DOXYGEN - - template<typename DenseDerived> - EIGEN_DEVICE_FUNC - void evalTo(MatrixBase<DenseDerived> &other) const; - template<typename DenseDerived> - EIGEN_DEVICE_FUNC - void evalToLazy(MatrixBase<DenseDerived> &other) const; - - EIGEN_DEVICE_FUNC - DenseMatrixType toDenseMatrix() const - { - DenseMatrixType res(rows(), cols()); - evalToLazy(res); - return res; - } - - protected: - - void check_coordinates(Index row, Index col) const - { - EIGEN_ONLY_USED_FOR_DEBUG(row); - EIGEN_ONLY_USED_FOR_DEBUG(col); - eigen_assert(col>=0 && col<cols() && row>=0 && row<rows()); - const int mode = int(Mode) & ~SelfAdjoint; - EIGEN_ONLY_USED_FOR_DEBUG(mode); - eigen_assert((mode==Upper && col>=row) - || (mode==Lower && col<=row) - || ((mode==StrictlyUpper || mode==UnitUpper) && col>row) - || ((mode==StrictlyLower || mode==UnitLower) && col<row)); - } - - #ifdef EIGEN_INTERNAL_DEBUGGING - void check_coordinates_internal(Index row, Index col) const - { - check_coordinates(row, col); - } - #else - void check_coordinates_internal(Index , Index ) const {} - #endif - -}; - -/** \class TriangularView - * \ingroup Core_Module - * - * \brief Expression of a triangular part in a matrix - * - * \param MatrixType the type of the object in which we are taking the triangular part - * \param Mode the kind of triangular matrix expression to construct. Can be #Upper, - * #Lower, #UnitUpper, #UnitLower, #StrictlyUpper, or #StrictlyLower. - * This is in fact a bit field; it must have either #Upper or #Lower, - * and additionally it may have #UnitDiag or #ZeroDiag or neither. - * - * This class represents a triangular part of a matrix, not necessarily square. Strictly speaking, for rectangular - * matrices one should speak of "trapezoid" parts. This class is the return type - * of MatrixBase::triangularView() and SparseMatrixBase::triangularView(), and most of the time this is the only way it is used. - * - * \sa MatrixBase::triangularView() - */ -namespace internal { -template<typename MatrixType, unsigned int _Mode> -struct traits<TriangularView<MatrixType, _Mode> > : traits<MatrixType> -{ - typedef typename ref_selector<MatrixType>::non_const_type MatrixTypeNested; - typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef; - typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned; - typedef typename MatrixType::PlainObject FullMatrixType; - typedef MatrixType ExpressionType; - enum { - Mode = _Mode, - FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, - Flags = (MatrixTypeNestedCleaned::Flags & (HereditaryBits | FlagsLvalueBit) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit))) - }; -}; -} - -template<typename _MatrixType, unsigned int _Mode, typename StorageKind> class TriangularViewImpl; - -template<typename _MatrixType, unsigned int _Mode> class TriangularView - : public TriangularViewImpl<_MatrixType, _Mode, typename internal::traits<_MatrixType>::StorageKind > -{ - public: - - typedef TriangularViewImpl<_MatrixType, _Mode, typename internal::traits<_MatrixType>::StorageKind > Base; - typedef typename internal::traits<TriangularView>::Scalar Scalar; - typedef _MatrixType MatrixType; - - protected: - typedef typename internal::traits<TriangularView>::MatrixTypeNested MatrixTypeNested; - typedef typename internal::traits<TriangularView>::MatrixTypeNestedNonRef MatrixTypeNestedNonRef; - - typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType; - typedef TriangularView<typename internal::add_const<MatrixType>::type, _Mode> ConstTriangularView; - - public: - - typedef typename internal::traits<TriangularView>::StorageKind StorageKind; - typedef typename internal::traits<TriangularView>::MatrixTypeNestedCleaned NestedExpression; - - enum { - Mode = _Mode, - Flags = internal::traits<TriangularView>::Flags, - TransposeMode = (Mode & Upper ? Lower : 0) - | (Mode & Lower ? Upper : 0) - | (Mode & (UnitDiag)) - | (Mode & (ZeroDiag)), - IsVectorAtCompileTime = false - }; - - EIGEN_DEVICE_FUNC - explicit inline TriangularView(MatrixType& matrix) : m_matrix(matrix) - {} - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TriangularView) - - /** \copydoc EigenBase::rows() */ - EIGEN_DEVICE_FUNC - inline Index rows() const { return m_matrix.rows(); } - /** \copydoc EigenBase::cols() */ - EIGEN_DEVICE_FUNC - inline Index cols() const { return m_matrix.cols(); } - - /** \returns a const reference to the nested expression */ - EIGEN_DEVICE_FUNC - const NestedExpression& nestedExpression() const { return m_matrix; } - - /** \returns a reference to the nested expression */ - EIGEN_DEVICE_FUNC - NestedExpression& nestedExpression() { return m_matrix; } - - typedef TriangularView<const MatrixConjugateReturnType,Mode> ConjugateReturnType; - /** \sa MatrixBase::conjugate() const */ - EIGEN_DEVICE_FUNC - inline const ConjugateReturnType conjugate() const - { return ConjugateReturnType(m_matrix.conjugate()); } - - /** \returns an expression of the complex conjugate of \c *this if Cond==true, - * returns \c *this otherwise. - */ - template<bool Cond> - EIGEN_DEVICE_FUNC - inline typename internal::conditional<Cond,ConjugateReturnType,ConstTriangularView>::type - conjugateIf() const - { - typedef typename internal::conditional<Cond,ConjugateReturnType,ConstTriangularView>::type ReturnType; - return ReturnType(m_matrix.template conjugateIf<Cond>()); - } - - typedef TriangularView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType; - /** \sa MatrixBase::adjoint() const */ - EIGEN_DEVICE_FUNC - inline const AdjointReturnType adjoint() const - { return AdjointReturnType(m_matrix.adjoint()); } - - typedef TriangularView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType; - /** \sa MatrixBase::transpose() */ - EIGEN_DEVICE_FUNC - inline TransposeReturnType transpose() - { - EIGEN_STATIC_ASSERT_LVALUE(MatrixType) - typename MatrixType::TransposeReturnType tmp(m_matrix); - return TransposeReturnType(tmp); - } - - typedef TriangularView<const typename MatrixType::ConstTransposeReturnType,TransposeMode> ConstTransposeReturnType; - /** \sa MatrixBase::transpose() const */ - EIGEN_DEVICE_FUNC - inline const ConstTransposeReturnType transpose() const - { - return ConstTransposeReturnType(m_matrix.transpose()); - } - - template<typename Other> - EIGEN_DEVICE_FUNC - inline const Solve<TriangularView, Other> - solve(const MatrixBase<Other>& other) const - { return Solve<TriangularView, Other>(*this, other.derived()); } - - // workaround MSVC ICE - #if EIGEN_COMP_MSVC - template<int Side, typename Other> - EIGEN_DEVICE_FUNC - inline const internal::triangular_solve_retval<Side,TriangularView, Other> - solve(const MatrixBase<Other>& other) const - { return Base::template solve<Side>(other); } - #else - using Base::solve; - #endif - - /** \returns a selfadjoint view of the referenced triangular part which must be either \c #Upper or \c #Lower. - * - * This is a shortcut for \code this->nestedExpression().selfadjointView<(*this)::Mode>() \endcode - * \sa MatrixBase::selfadjointView() */ - EIGEN_DEVICE_FUNC - SelfAdjointView<MatrixTypeNestedNonRef,Mode> selfadjointView() - { - EIGEN_STATIC_ASSERT((Mode&(UnitDiag|ZeroDiag))==0,PROGRAMMING_ERROR); - return SelfAdjointView<MatrixTypeNestedNonRef,Mode>(m_matrix); - } - - /** This is the const version of selfadjointView() */ - EIGEN_DEVICE_FUNC - const SelfAdjointView<MatrixTypeNestedNonRef,Mode> selfadjointView() const - { - EIGEN_STATIC_ASSERT((Mode&(UnitDiag|ZeroDiag))==0,PROGRAMMING_ERROR); - return SelfAdjointView<MatrixTypeNestedNonRef,Mode>(m_matrix); - } - - - /** \returns the determinant of the triangular matrix - * \sa MatrixBase::determinant() */ - EIGEN_DEVICE_FUNC - Scalar determinant() const - { - if (Mode & UnitDiag) - return 1; - else if (Mode & ZeroDiag) - return 0; - else - return m_matrix.diagonal().prod(); - } - - protected: - - MatrixTypeNested m_matrix; -}; - -/** \ingroup Core_Module - * - * \brief Base class for a triangular part in a \b dense matrix - * - * This class is an abstract base class of class TriangularView, and objects of type TriangularViewImpl cannot be instantiated. - * It extends class TriangularView with additional methods which available for dense expressions only. - * - * \sa class TriangularView, MatrixBase::triangularView() - */ -template<typename _MatrixType, unsigned int _Mode> class TriangularViewImpl<_MatrixType,_Mode,Dense> - : public TriangularBase<TriangularView<_MatrixType, _Mode> > -{ - public: - - typedef TriangularView<_MatrixType, _Mode> TriangularViewType; - typedef TriangularBase<TriangularViewType> Base; - typedef typename internal::traits<TriangularViewType>::Scalar Scalar; - - typedef _MatrixType MatrixType; - typedef typename MatrixType::PlainObject DenseMatrixType; - typedef DenseMatrixType PlainObject; - - public: - using Base::evalToLazy; - using Base::derived; - - typedef typename internal::traits<TriangularViewType>::StorageKind StorageKind; - - enum { - Mode = _Mode, - Flags = internal::traits<TriangularViewType>::Flags - }; - - /** \returns the outer-stride of the underlying dense matrix - * \sa DenseCoeffsBase::outerStride() */ - EIGEN_DEVICE_FUNC - inline Index outerStride() const { return derived().nestedExpression().outerStride(); } - /** \returns the inner-stride of the underlying dense matrix - * \sa DenseCoeffsBase::innerStride() */ - EIGEN_DEVICE_FUNC - inline Index innerStride() const { return derived().nestedExpression().innerStride(); } - - /** \sa MatrixBase::operator+=() */ - template<typename Other> - EIGEN_DEVICE_FUNC - TriangularViewType& operator+=(const DenseBase<Other>& other) { - internal::call_assignment_no_alias(derived(), other.derived(), internal::add_assign_op<Scalar,typename Other::Scalar>()); - return derived(); - } - /** \sa MatrixBase::operator-=() */ - template<typename Other> - EIGEN_DEVICE_FUNC - TriangularViewType& operator-=(const DenseBase<Other>& other) { - internal::call_assignment_no_alias(derived(), other.derived(), internal::sub_assign_op<Scalar,typename Other::Scalar>()); - return derived(); - } - - /** \sa MatrixBase::operator*=() */ - EIGEN_DEVICE_FUNC - TriangularViewType& operator*=(const typename internal::traits<MatrixType>::Scalar& other) { return *this = derived().nestedExpression() * other; } - /** \sa DenseBase::operator/=() */ - EIGEN_DEVICE_FUNC - TriangularViewType& operator/=(const typename internal::traits<MatrixType>::Scalar& other) { return *this = derived().nestedExpression() / other; } - - /** \sa MatrixBase::fill() */ - EIGEN_DEVICE_FUNC - void fill(const Scalar& value) { setConstant(value); } - /** \sa MatrixBase::setConstant() */ - EIGEN_DEVICE_FUNC - TriangularViewType& setConstant(const Scalar& value) - { return *this = MatrixType::Constant(derived().rows(), derived().cols(), value); } - /** \sa MatrixBase::setZero() */ - EIGEN_DEVICE_FUNC - TriangularViewType& setZero() { return setConstant(Scalar(0)); } - /** \sa MatrixBase::setOnes() */ - EIGEN_DEVICE_FUNC - TriangularViewType& setOnes() { return setConstant(Scalar(1)); } - - /** \sa MatrixBase::coeff() - * \warning the coordinates must fit into the referenced triangular part - */ - EIGEN_DEVICE_FUNC - inline Scalar coeff(Index row, Index col) const - { - Base::check_coordinates_internal(row, col); - return derived().nestedExpression().coeff(row, col); - } - - /** \sa MatrixBase::coeffRef() - * \warning the coordinates must fit into the referenced triangular part - */ - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index row, Index col) - { - EIGEN_STATIC_ASSERT_LVALUE(TriangularViewType); - Base::check_coordinates_internal(row, col); - return derived().nestedExpression().coeffRef(row, col); - } - - /** Assigns a triangular matrix to a triangular part of a dense matrix */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - TriangularViewType& operator=(const TriangularBase<OtherDerived>& other); - - /** Shortcut for\code *this = other.other.triangularView<(*this)::Mode>() \endcode */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - TriangularViewType& operator=(const MatrixBase<OtherDerived>& other); - -#ifndef EIGEN_PARSED_BY_DOXYGEN - EIGEN_DEVICE_FUNC - TriangularViewType& operator=(const TriangularViewImpl& other) - { return *this = other.derived().nestedExpression(); } - - template<typename OtherDerived> - /** \deprecated */ - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC - void lazyAssign(const TriangularBase<OtherDerived>& other); - - template<typename OtherDerived> - /** \deprecated */ - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC - void lazyAssign(const MatrixBase<OtherDerived>& other); -#endif - - /** Efficient triangular matrix times vector/matrix product */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - const Product<TriangularViewType,OtherDerived> - operator*(const MatrixBase<OtherDerived>& rhs) const - { - return Product<TriangularViewType,OtherDerived>(derived(), rhs.derived()); - } - - /** Efficient vector/matrix times triangular matrix product */ - template<typename OtherDerived> friend - EIGEN_DEVICE_FUNC - const Product<OtherDerived,TriangularViewType> - operator*(const MatrixBase<OtherDerived>& lhs, const TriangularViewImpl& rhs) - { - return Product<OtherDerived,TriangularViewType>(lhs.derived(),rhs.derived()); - } - - /** \returns the product of the inverse of \c *this with \a other, \a *this being triangular. - * - * This function computes the inverse-matrix matrix product inverse(\c *this) * \a other if - * \a Side==OnTheLeft (the default), or the right-inverse-multiply \a other * inverse(\c *this) if - * \a Side==OnTheRight. - * - * Note that the template parameter \c Side can be omitted, in which case \c Side==OnTheLeft - * - * The matrix \c *this must be triangular and invertible (i.e., all the coefficients of the - * diagonal must be non zero). It works as a forward (resp. backward) substitution if \c *this - * is an upper (resp. lower) triangular matrix. - * - * Example: \include Triangular_solve.cpp - * Output: \verbinclude Triangular_solve.out - * - * This function returns an expression of the inverse-multiply and can works in-place if it is assigned - * to the same matrix or vector \a other. - * - * For users coming from BLAS, this function (and more specifically solveInPlace()) offer - * all the operations supported by the \c *TRSV and \c *TRSM BLAS routines. - * - * \sa TriangularView::solveInPlace() - */ - template<int Side, typename Other> - inline const internal::triangular_solve_retval<Side,TriangularViewType, Other> - solve(const MatrixBase<Other>& other) const; - - /** "in-place" version of TriangularView::solve() where the result is written in \a other - * - * \warning The parameter is only marked 'const' to make the C++ compiler accept a temporary expression here. - * This function will const_cast it, so constness isn't honored here. - * - * Note that the template parameter \c Side can be omitted, in which case \c Side==OnTheLeft - * - * See TriangularView:solve() for the details. - */ - template<int Side, typename OtherDerived> - EIGEN_DEVICE_FUNC - void solveInPlace(const MatrixBase<OtherDerived>& other) const; - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - void solveInPlace(const MatrixBase<OtherDerived>& other) const - { return solveInPlace<OnTheLeft>(other); } - - /** Swaps the coefficients of the common triangular parts of two matrices */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC -#ifdef EIGEN_PARSED_BY_DOXYGEN - void swap(TriangularBase<OtherDerived> &other) -#else - void swap(TriangularBase<OtherDerived> const & other) -#endif - { - EIGEN_STATIC_ASSERT_LVALUE(OtherDerived); - call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>()); - } - - /** Shortcut for \code (*this).swap(other.triangularView<(*this)::Mode>()) \endcode */ - template<typename OtherDerived> - /** \deprecated */ - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC - void swap(MatrixBase<OtherDerived> const & other) - { - EIGEN_STATIC_ASSERT_LVALUE(OtherDerived); - call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>()); - } - - template<typename RhsType, typename DstType> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _solve_impl(const RhsType &rhs, DstType &dst) const { - if(!internal::is_same_dense(dst,rhs)) - dst = rhs; - this->solveInPlace(dst); - } - - template<typename ProductType> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TriangularViewType& _assignProduct(const ProductType& prod, const Scalar& alpha, bool beta); - protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(TriangularViewImpl) - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TriangularViewImpl) - -}; - -/*************************************************************************** -* Implementation of triangular evaluation/assignment -***************************************************************************/ - -#ifndef EIGEN_PARSED_BY_DOXYGEN -// FIXME should we keep that possibility -template<typename MatrixType, unsigned int Mode> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC inline TriangularView<MatrixType, Mode>& -TriangularViewImpl<MatrixType, Mode, Dense>::operator=(const MatrixBase<OtherDerived>& other) -{ - internal::call_assignment_no_alias(derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -// FIXME should we keep that possibility -template<typename MatrixType, unsigned int Mode> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(const MatrixBase<OtherDerived>& other) -{ - internal::call_assignment_no_alias(derived(), other.template triangularView<Mode>()); -} - - - -template<typename MatrixType, unsigned int Mode> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC inline TriangularView<MatrixType, Mode>& -TriangularViewImpl<MatrixType, Mode, Dense>::operator=(const TriangularBase<OtherDerived>& other) -{ - eigen_assert(Mode == int(OtherDerived::Mode)); - internal::call_assignment(derived(), other.derived()); - return derived(); -} - -template<typename MatrixType, unsigned int Mode> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(const TriangularBase<OtherDerived>& other) -{ - eigen_assert(Mode == int(OtherDerived::Mode)); - internal::call_assignment_no_alias(derived(), other.derived()); -} -#endif - -/*************************************************************************** -* Implementation of TriangularBase methods -***************************************************************************/ - -/** Assigns a triangular or selfadjoint matrix to a dense matrix. - * If the matrix is triangular, the opposite part is set to zero. */ -template<typename Derived> -template<typename DenseDerived> -EIGEN_DEVICE_FUNC void TriangularBase<Derived>::evalTo(MatrixBase<DenseDerived> &other) const -{ - evalToLazy(other.derived()); -} - -/*************************************************************************** -* Implementation of TriangularView methods -***************************************************************************/ - -/*************************************************************************** -* Implementation of MatrixBase methods -***************************************************************************/ - -/** - * \returns an expression of a triangular view extracted from the current matrix - * - * The parameter \a Mode can have the following values: \c #Upper, \c #StrictlyUpper, \c #UnitUpper, - * \c #Lower, \c #StrictlyLower, \c #UnitLower. - * - * Example: \include MatrixBase_triangularView.cpp - * Output: \verbinclude MatrixBase_triangularView.out - * - * \sa class TriangularView - */ -template<typename Derived> -template<unsigned int Mode> -EIGEN_DEVICE_FUNC -typename MatrixBase<Derived>::template TriangularViewReturnType<Mode>::Type -MatrixBase<Derived>::triangularView() -{ - return typename TriangularViewReturnType<Mode>::Type(derived()); -} - -/** This is the const version of MatrixBase::triangularView() */ -template<typename Derived> -template<unsigned int Mode> -EIGEN_DEVICE_FUNC -typename MatrixBase<Derived>::template ConstTriangularViewReturnType<Mode>::Type -MatrixBase<Derived>::triangularView() const -{ - return typename ConstTriangularViewReturnType<Mode>::Type(derived()); -} - -/** \returns true if *this is approximately equal to an upper triangular matrix, - * within the precision given by \a prec. - * - * \sa isLowerTriangular() - */ -template<typename Derived> -bool MatrixBase<Derived>::isUpperTriangular(const RealScalar& prec) const -{ - RealScalar maxAbsOnUpperPart = static_cast<RealScalar>(-1); - for(Index j = 0; j < cols(); ++j) - { - Index maxi = numext::mini(j, rows()-1); - for(Index i = 0; i <= maxi; ++i) - { - RealScalar absValue = numext::abs(coeff(i,j)); - if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue; - } - } - RealScalar threshold = maxAbsOnUpperPart * prec; - for(Index j = 0; j < cols(); ++j) - for(Index i = j+1; i < rows(); ++i) - if(numext::abs(coeff(i, j)) > threshold) return false; - return true; -} - -/** \returns true if *this is approximately equal to a lower triangular matrix, - * within the precision given by \a prec. - * - * \sa isUpperTriangular() - */ -template<typename Derived> -bool MatrixBase<Derived>::isLowerTriangular(const RealScalar& prec) const -{ - RealScalar maxAbsOnLowerPart = static_cast<RealScalar>(-1); - for(Index j = 0; j < cols(); ++j) - for(Index i = j; i < rows(); ++i) - { - RealScalar absValue = numext::abs(coeff(i,j)); - if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue; - } - RealScalar threshold = maxAbsOnLowerPart * prec; - for(Index j = 1; j < cols(); ++j) - { - Index maxi = numext::mini(j, rows()-1); - for(Index i = 0; i < maxi; ++i) - if(numext::abs(coeff(i, j)) > threshold) return false; - } - return true; -} - - -/*************************************************************************** -**************************************************************************** -* Evaluators and Assignment of triangular expressions -*************************************************************************** -***************************************************************************/ - -namespace internal { - - -// TODO currently a triangular expression has the form TriangularView<.,.> -// in the future triangular-ness should be defined by the expression traits -// such that Transpose<TriangularView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work) -template<typename MatrixType, unsigned int Mode> -struct evaluator_traits<TriangularView<MatrixType,Mode> > -{ - typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind; - typedef typename glue_shapes<typename evaluator_traits<MatrixType>::Shape, TriangularShape>::type Shape; -}; - -template<typename MatrixType, unsigned int Mode> -struct unary_evaluator<TriangularView<MatrixType,Mode>, IndexBased> - : evaluator<typename internal::remove_all<MatrixType>::type> -{ - typedef TriangularView<MatrixType,Mode> XprType; - typedef evaluator<typename internal::remove_all<MatrixType>::type> Base; - EIGEN_DEVICE_FUNC - unary_evaluator(const XprType &xpr) : Base(xpr.nestedExpression()) {} -}; - -// Additional assignment kinds: -struct Triangular2Triangular {}; -struct Triangular2Dense {}; -struct Dense2Triangular {}; - - -template<typename Kernel, unsigned int Mode, int UnrollCount, bool ClearOpposite> struct triangular_assignment_loop; - - -/** \internal Specialization of the dense assignment kernel for triangular matrices. - * The main difference is that the triangular, diagonal, and opposite parts are processed through three different functions. - * \tparam UpLo must be either Lower or Upper - * \tparam Mode must be either 0, UnitDiag, ZeroDiag, or SelfAdjoint - */ -template<int UpLo, int Mode, int SetOpposite, typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version = Specialized> -class triangular_dense_assignment_kernel : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version> -{ -protected: - typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version> Base; - typedef typename Base::DstXprType DstXprType; - typedef typename Base::SrcXprType SrcXprType; - using Base::m_dst; - using Base::m_src; - using Base::m_functor; -public: - - typedef typename Base::DstEvaluatorType DstEvaluatorType; - typedef typename Base::SrcEvaluatorType SrcEvaluatorType; - typedef typename Base::Scalar Scalar; - typedef typename Base::AssignmentTraits AssignmentTraits; - - - EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr) - : Base(dst, src, func, dstExpr) - {} - -#ifdef EIGEN_INTERNAL_DEBUGGING - EIGEN_DEVICE_FUNC void assignCoeff(Index row, Index col) - { - eigen_internal_assert(row!=col); - Base::assignCoeff(row,col); - } -#else - using Base::assignCoeff; -#endif - - EIGEN_DEVICE_FUNC void assignDiagonalCoeff(Index id) - { - if(Mode==UnitDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(id,id), Scalar(1)); - else if(Mode==ZeroDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(id,id), Scalar(0)); - else if(Mode==0) Base::assignCoeff(id,id); - } - - EIGEN_DEVICE_FUNC void assignOppositeCoeff(Index row, Index col) - { - eigen_internal_assert(row!=col); - if(SetOpposite) - m_functor.assignCoeff(m_dst.coeffRef(row,col), Scalar(0)); - } -}; - -template<int Mode, bool SetOpposite, typename DstXprType, typename SrcXprType, typename Functor> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_triangular_assignment_loop(DstXprType& dst, const SrcXprType& src, const Functor &func) -{ - typedef evaluator<DstXprType> DstEvaluatorType; - typedef evaluator<SrcXprType> SrcEvaluatorType; - - SrcEvaluatorType srcEvaluator(src); - - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - DstEvaluatorType dstEvaluator(dst); - - typedef triangular_dense_assignment_kernel< Mode&(Lower|Upper),Mode&(UnitDiag|ZeroDiag|SelfAdjoint),SetOpposite, - DstEvaluatorType,SrcEvaluatorType,Functor> Kernel; - Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived()); - - enum { - unroll = DstXprType::SizeAtCompileTime != Dynamic - && SrcEvaluatorType::CoeffReadCost < HugeCost - && DstXprType::SizeAtCompileTime * (DstEvaluatorType::CoeffReadCost+SrcEvaluatorType::CoeffReadCost) / 2 <= EIGEN_UNROLLING_LIMIT - }; - - triangular_assignment_loop<Kernel, Mode, unroll ? int(DstXprType::SizeAtCompileTime) : Dynamic, SetOpposite>::run(kernel); -} - -template<int Mode, bool SetOpposite, typename DstXprType, typename SrcXprType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -void call_triangular_assignment_loop(DstXprType& dst, const SrcXprType& src) -{ - call_triangular_assignment_loop<Mode,SetOpposite>(dst, src, internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>()); -} - -template<> struct AssignmentKind<TriangularShape,TriangularShape> { typedef Triangular2Triangular Kind; }; -template<> struct AssignmentKind<DenseShape,TriangularShape> { typedef Triangular2Dense Kind; }; -template<> struct AssignmentKind<TriangularShape,DenseShape> { typedef Dense2Triangular Kind; }; - - -template< typename DstXprType, typename SrcXprType, typename Functor> -struct Assignment<DstXprType, SrcXprType, Functor, Triangular2Triangular> -{ - EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const Functor &func) - { - eigen_assert(int(DstXprType::Mode) == int(SrcXprType::Mode)); - - call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func); - } -}; - -template< typename DstXprType, typename SrcXprType, typename Functor> -struct Assignment<DstXprType, SrcXprType, Functor, Triangular2Dense> -{ - EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const Functor &func) - { - call_triangular_assignment_loop<SrcXprType::Mode, (SrcXprType::Mode&SelfAdjoint)==0>(dst, src, func); - } -}; - -template< typename DstXprType, typename SrcXprType, typename Functor> -struct Assignment<DstXprType, SrcXprType, Functor, Dense2Triangular> -{ - EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const Functor &func) - { - call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func); - } -}; - - -template<typename Kernel, unsigned int Mode, int UnrollCount, bool SetOpposite> -struct triangular_assignment_loop -{ - // FIXME: this is not very clean, perhaps this information should be provided by the kernel? - typedef typename Kernel::DstEvaluatorType DstEvaluatorType; - typedef typename DstEvaluatorType::XprType DstXprType; - - enum { - col = (UnrollCount-1) / DstXprType::RowsAtCompileTime, - row = (UnrollCount-1) % DstXprType::RowsAtCompileTime - }; - - typedef typename Kernel::Scalar Scalar; - - EIGEN_DEVICE_FUNC - static inline void run(Kernel &kernel) - { - triangular_assignment_loop<Kernel, Mode, UnrollCount-1, SetOpposite>::run(kernel); - - if(row==col) - kernel.assignDiagonalCoeff(row); - else if( ((Mode&Lower) && row>col) || ((Mode&Upper) && row<col) ) - kernel.assignCoeff(row,col); - else if(SetOpposite) - kernel.assignOppositeCoeff(row,col); - } -}; - -// prevent buggy user code from causing an infinite recursion -template<typename Kernel, unsigned int Mode, bool SetOpposite> -struct triangular_assignment_loop<Kernel, Mode, 0, SetOpposite> -{ - EIGEN_DEVICE_FUNC - static inline void run(Kernel &) {} -}; - - - -// TODO: experiment with a recursive assignment procedure splitting the current -// triangular part into one rectangular and two triangular parts. - - -template<typename Kernel, unsigned int Mode, bool SetOpposite> -struct triangular_assignment_loop<Kernel, Mode, Dynamic, SetOpposite> -{ - typedef typename Kernel::Scalar Scalar; - EIGEN_DEVICE_FUNC - static inline void run(Kernel &kernel) - { - for(Index j = 0; j < kernel.cols(); ++j) - { - Index maxi = numext::mini(j, kernel.rows()); - Index i = 0; - if (((Mode&Lower) && SetOpposite) || (Mode&Upper)) - { - for(; i < maxi; ++i) - if(Mode&Upper) kernel.assignCoeff(i, j); - else kernel.assignOppositeCoeff(i, j); - } - else - i = maxi; - - if(i<kernel.rows()) // then i==j - kernel.assignDiagonalCoeff(i++); - - if (((Mode&Upper) && SetOpposite) || (Mode&Lower)) - { - for(; i < kernel.rows(); ++i) - if(Mode&Lower) kernel.assignCoeff(i, j); - else kernel.assignOppositeCoeff(i, j); - } - } - } -}; - -} // end namespace internal - -/** Assigns a triangular or selfadjoint matrix to a dense matrix. - * If the matrix is triangular, the opposite part is set to zero. */ -template<typename Derived> -template<typename DenseDerived> -EIGEN_DEVICE_FUNC void TriangularBase<Derived>::evalToLazy(MatrixBase<DenseDerived> &other) const -{ - other.derived().resize(this->rows(), this->cols()); - internal::call_triangular_assignment_loop<Derived::Mode,(Derived::Mode&SelfAdjoint)==0 /* SetOpposite */>(other.derived(), derived().nestedExpression()); -} - -namespace internal { - -// Triangular = Product -template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> -struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular> -{ - typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename SrcXprType::Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - dst._assignProduct(src, 1, 0); - } -}; - -// Triangular += Product -template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> -struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::add_assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular> -{ - typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<Scalar,typename SrcXprType::Scalar> &) - { - dst._assignProduct(src, 1, 1); - } -}; - -// Triangular -= Product -template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> -struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::sub_assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular> -{ - typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<Scalar,typename SrcXprType::Scalar> &) - { - dst._assignProduct(src, -1, 1); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRIANGULARMATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/VectorBlock.h b/external/eigen/include/eigen3/Eigen/src/Core/VectorBlock.h deleted file mode 100644 index 71c5b95e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/VectorBlock.h +++ /dev/null @@ -1,96 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_VECTORBLOCK_H -#define EIGEN_VECTORBLOCK_H - -namespace Eigen { - -namespace internal { -template<typename VectorType, int Size> -struct traits<VectorBlock<VectorType, Size> > - : public traits<Block<VectorType, - traits<VectorType>::Flags & RowMajorBit ? 1 : Size, - traits<VectorType>::Flags & RowMajorBit ? Size : 1> > -{ -}; -} - -/** \class VectorBlock - * \ingroup Core_Module - * - * \brief Expression of a fixed-size or dynamic-size sub-vector - * - * \tparam VectorType the type of the object in which we are taking a sub-vector - * \tparam Size size of the sub-vector we are taking at compile time (optional) - * - * This class represents an expression of either a fixed-size or dynamic-size sub-vector. - * It is the return type of DenseBase::segment(Index,Index) and DenseBase::segment<int>(Index) and - * most of the time this is the only way it is used. - * - * However, if you want to directly manipulate sub-vector expressions, - * for instance if you want to write a function returning such an expression, you - * will need to use this class. - * - * Here is an example illustrating the dynamic case: - * \include class_VectorBlock.cpp - * Output: \verbinclude class_VectorBlock.out - * - * \note Even though this expression has dynamic size, in the case where \a VectorType - * has fixed size, this expression inherits a fixed maximal size which means that evaluating - * it does not cause a dynamic memory allocation. - * - * Here is an example illustrating the fixed-size case: - * \include class_FixedVectorBlock.cpp - * Output: \verbinclude class_FixedVectorBlock.out - * - * \sa class Block, DenseBase::segment(Index,Index,Index,Index), DenseBase::segment(Index,Index) - */ -template<typename VectorType, int Size> class VectorBlock - : public Block<VectorType, - internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size, - internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1> -{ - typedef Block<VectorType, - internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size, - internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1> Base; - enum { - IsColVector = !(internal::traits<VectorType>::Flags & RowMajorBit) - }; - public: - EIGEN_DENSE_PUBLIC_INTERFACE(VectorBlock) - - using Base::operator=; - - /** Dynamic-size constructor - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - VectorBlock(VectorType& vector, Index start, Index size) - : Base(vector, - IsColVector ? start : 0, IsColVector ? 0 : start, - IsColVector ? size : 1, IsColVector ? 1 : size) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock); - } - - /** Fixed-size constructor - */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - VectorBlock(VectorType& vector, Index start) - : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock); - } -}; - - -} // end namespace Eigen - -#endif // EIGEN_VECTORBLOCK_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/VectorwiseOp.h b/external/eigen/include/eigen3/Eigen/src/Core/VectorwiseOp.h deleted file mode 100644 index 274501c6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/VectorwiseOp.h +++ /dev/null @@ -1,760 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2019 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PARTIAL_REDUX_H -#define EIGEN_PARTIAL_REDUX_H - -namespace Eigen { - -/** \class PartialReduxExpr - * \ingroup Core_Module - * - * \brief Generic expression of a partially reduxed matrix - * - * \tparam MatrixType the type of the matrix we are applying the redux operation - * \tparam MemberOp type of the member functor - * \tparam Direction indicates the direction of the redux (#Vertical or #Horizontal) - * - * This class represents an expression of a partial redux operator of a matrix. - * It is the return type of some VectorwiseOp functions, - * and most of the time this is the only way it is used. - * - * \sa class VectorwiseOp - */ - -template< typename MatrixType, typename MemberOp, int Direction> -class PartialReduxExpr; - -namespace internal { -template<typename MatrixType, typename MemberOp, int Direction> -struct traits<PartialReduxExpr<MatrixType, MemberOp, Direction> > - : traits<MatrixType> -{ - typedef typename MemberOp::result_type Scalar; - typedef typename traits<MatrixType>::StorageKind StorageKind; - typedef typename traits<MatrixType>::XprKind XprKind; - typedef typename MatrixType::Scalar InputScalar; - enum { - RowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::RowsAtCompileTime, - ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime, - Flags = RowsAtCompileTime == 1 ? RowMajorBit : 0, - TraversalSize = Direction==Vertical ? MatrixType::RowsAtCompileTime : MatrixType::ColsAtCompileTime - }; -}; -} - -template< typename MatrixType, typename MemberOp, int Direction> -class PartialReduxExpr : public internal::dense_xpr_base< PartialReduxExpr<MatrixType, MemberOp, Direction> >::type, - internal::no_assignment_operator -{ - public: - - typedef typename internal::dense_xpr_base<PartialReduxExpr>::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(PartialReduxExpr) - - EIGEN_DEVICE_FUNC - explicit PartialReduxExpr(const MatrixType& mat, const MemberOp& func = MemberOp()) - : m_matrix(mat), m_functor(func) {} - - EIGEN_DEVICE_FUNC - Index rows() const { return (Direction==Vertical ? 1 : m_matrix.rows()); } - EIGEN_DEVICE_FUNC - Index cols() const { return (Direction==Horizontal ? 1 : m_matrix.cols()); } - - EIGEN_DEVICE_FUNC - typename MatrixType::Nested nestedExpression() const { return m_matrix; } - - EIGEN_DEVICE_FUNC - const MemberOp& functor() const { return m_functor; } - - protected: - typename MatrixType::Nested m_matrix; - const MemberOp m_functor; -}; - -template<typename A,typename B> struct partial_redux_dummy_func; - -#define EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER,COST,VECTORIZABLE,BINARYOP) \ - template <typename ResultType,typename Scalar> \ - struct member_##MEMBER { \ - EIGEN_EMPTY_STRUCT_CTOR(member_##MEMBER) \ - typedef ResultType result_type; \ - typedef BINARYOP<Scalar,Scalar> BinaryOp; \ - template<int Size> struct Cost { enum { value = COST }; }; \ - enum { Vectorizable = VECTORIZABLE }; \ - template<typename XprType> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \ - ResultType operator()(const XprType& mat) const \ - { return mat.MEMBER(); } \ - BinaryOp binaryFunc() const { return BinaryOp(); } \ - } - -#define EIGEN_MEMBER_FUNCTOR(MEMBER,COST) \ - EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER,COST,0,partial_redux_dummy_func) - -namespace internal { - -EIGEN_MEMBER_FUNCTOR(norm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); -EIGEN_MEMBER_FUNCTOR(stableNorm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); -EIGEN_MEMBER_FUNCTOR(blueNorm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); -EIGEN_MEMBER_FUNCTOR(hypotNorm, (Size-1) * functor_traits<scalar_hypot_op<Scalar> >::Cost ); -EIGEN_MEMBER_FUNCTOR(all, (Size-1)*NumTraits<Scalar>::AddCost); -EIGEN_MEMBER_FUNCTOR(any, (Size-1)*NumTraits<Scalar>::AddCost); -EIGEN_MEMBER_FUNCTOR(count, (Size-1)*NumTraits<Scalar>::AddCost); - -EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(sum, (Size-1)*NumTraits<Scalar>::AddCost, 1, internal::scalar_sum_op); -EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(minCoeff, (Size-1)*NumTraits<Scalar>::AddCost, 1, internal::scalar_min_op); -EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(maxCoeff, (Size-1)*NumTraits<Scalar>::AddCost, 1, internal::scalar_max_op); -EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(prod, (Size-1)*NumTraits<Scalar>::MulCost, 1, internal::scalar_product_op); - -template <int p, typename ResultType,typename Scalar> -struct member_lpnorm { - typedef ResultType result_type; - enum { Vectorizable = 0 }; - template<int Size> struct Cost - { enum { value = (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost }; }; - EIGEN_DEVICE_FUNC member_lpnorm() {} - template<typename XprType> - EIGEN_DEVICE_FUNC inline ResultType operator()(const XprType& mat) const - { return mat.template lpNorm<p>(); } -}; - -template <typename BinaryOpT, typename Scalar> -struct member_redux { - typedef BinaryOpT BinaryOp; - typedef typename result_of< - BinaryOp(const Scalar&,const Scalar&) - >::type result_type; - - enum { Vectorizable = functor_traits<BinaryOp>::PacketAccess }; - template<int Size> struct Cost { enum { value = (Size-1) * functor_traits<BinaryOp>::Cost }; }; - EIGEN_DEVICE_FUNC explicit member_redux(const BinaryOp func) : m_functor(func) {} - template<typename Derived> - EIGEN_DEVICE_FUNC inline result_type operator()(const DenseBase<Derived>& mat) const - { return mat.redux(m_functor); } - const BinaryOp& binaryFunc() const { return m_functor; } - const BinaryOp m_functor; -}; -} - -/** \class VectorwiseOp - * \ingroup Core_Module - * - * \brief Pseudo expression providing broadcasting and partial reduction operations - * - * \tparam ExpressionType the type of the object on which to do partial reductions - * \tparam Direction indicates whether to operate on columns (#Vertical) or rows (#Horizontal) - * - * This class represents a pseudo expression with broadcasting and partial reduction features. - * It is the return type of DenseBase::colwise() and DenseBase::rowwise() - * and most of the time this is the only way it is explicitly used. - * - * To understand the logic of rowwise/colwise expression, let's consider a generic case `A.colwise().foo()` - * where `foo` is any method of `VectorwiseOp`. This expression is equivalent to applying `foo()` to each - * column of `A` and then re-assemble the outputs in a matrix expression: - * \code [A.col(0).foo(), A.col(1).foo(), ..., A.col(A.cols()-1).foo()] \endcode - * - * Example: \include MatrixBase_colwise.cpp - * Output: \verbinclude MatrixBase_colwise.out - * - * The begin() and end() methods are obviously exceptions to the previous rule as they - * return STL-compatible begin/end iterators to the rows or columns of the nested expression. - * Typical use cases include for-range-loop and calls to STL algorithms: - * - * Example: \include MatrixBase_colwise_iterator_cxx11.cpp - * Output: \verbinclude MatrixBase_colwise_iterator_cxx11.out - * - * For a partial reduction on an empty input, some rules apply. - * For the sake of clarity, let's consider a vertical reduction: - * - If the number of columns is zero, then a 1x0 row-major vector expression is returned. - * - Otherwise, if the number of rows is zero, then - * - a row vector of zeros is returned for sum-like reductions (sum, squaredNorm, norm, etc.) - * - a row vector of ones is returned for a product reduction (e.g., <code>MatrixXd(n,0).colwise().prod()</code>) - * - an assert is triggered for all other reductions (minCoeff,maxCoeff,redux(bin_op)) - * - * \sa DenseBase::colwise(), DenseBase::rowwise(), class PartialReduxExpr - */ -template<typename ExpressionType, int Direction> class VectorwiseOp -{ - public: - - typedef typename ExpressionType::Scalar Scalar; - typedef typename ExpressionType::RealScalar RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - typedef typename internal::ref_selector<ExpressionType>::non_const_type ExpressionTypeNested; - typedef typename internal::remove_all<ExpressionTypeNested>::type ExpressionTypeNestedCleaned; - - template<template<typename OutScalar,typename InputScalar> class Functor, - typename ReturnScalar=Scalar> struct ReturnType - { - typedef PartialReduxExpr<ExpressionType, - Functor<ReturnScalar,Scalar>, - Direction - > Type; - }; - - template<typename BinaryOp> struct ReduxReturnType - { - typedef PartialReduxExpr<ExpressionType, - internal::member_redux<BinaryOp,Scalar>, - Direction - > Type; - }; - - enum { - isVertical = (Direction==Vertical) ? 1 : 0, - isHorizontal = (Direction==Horizontal) ? 1 : 0 - }; - - protected: - - template<typename OtherDerived> struct ExtendedType { - typedef Replicate<OtherDerived, - isVertical ? 1 : ExpressionType::RowsAtCompileTime, - isHorizontal ? 1 : ExpressionType::ColsAtCompileTime> Type; - }; - - /** \internal - * Replicates a vector to match the size of \c *this */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - typename ExtendedType<OtherDerived>::Type - extendedTo(const DenseBase<OtherDerived>& other) const - { - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isVertical, OtherDerived::MaxColsAtCompileTime==1), - YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED) - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isHorizontal, OtherDerived::MaxRowsAtCompileTime==1), - YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED) - return typename ExtendedType<OtherDerived>::Type - (other.derived(), - isVertical ? 1 : m_matrix.rows(), - isHorizontal ? 1 : m_matrix.cols()); - } - - template<typename OtherDerived> struct OppositeExtendedType { - typedef Replicate<OtherDerived, - isHorizontal ? 1 : ExpressionType::RowsAtCompileTime, - isVertical ? 1 : ExpressionType::ColsAtCompileTime> Type; - }; - - /** \internal - * Replicates a vector in the opposite direction to match the size of \c *this */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - typename OppositeExtendedType<OtherDerived>::Type - extendedToOpposite(const DenseBase<OtherDerived>& other) const - { - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isHorizontal, OtherDerived::MaxColsAtCompileTime==1), - YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED) - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isVertical, OtherDerived::MaxRowsAtCompileTime==1), - YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED) - return typename OppositeExtendedType<OtherDerived>::Type - (other.derived(), - isHorizontal ? 1 : m_matrix.rows(), - isVertical ? 1 : m_matrix.cols()); - } - - public: - EIGEN_DEVICE_FUNC - explicit inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {} - - /** \internal */ - EIGEN_DEVICE_FUNC - inline const ExpressionType& _expression() const { return m_matrix; } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** STL-like <a href="https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator">RandomAccessIterator</a> - * iterator type over the columns or rows as returned by the begin() and end() methods. - */ - random_access_iterator_type iterator; - /** This is the const version of iterator (aka read-only) */ - random_access_iterator_type const_iterator; - #else - typedef internal::subvector_stl_iterator<ExpressionType, DirectionType(Direction)> iterator; - typedef internal::subvector_stl_iterator<const ExpressionType, DirectionType(Direction)> const_iterator; - #endif - - /** returns an iterator to the first row (rowwise) or column (colwise) of the nested expression. - * \sa end(), cbegin() - */ - iterator begin() { return iterator (m_matrix, 0); } - /** const version of begin() */ - const_iterator begin() const { return const_iterator(m_matrix, 0); } - /** const version of begin() */ - const_iterator cbegin() const { return const_iterator(m_matrix, 0); } - - /** returns an iterator to the row (resp. column) following the last row (resp. column) of the nested expression - * \sa begin(), cend() - */ - iterator end() { return iterator (m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); } - /** const version of end() */ - const_iterator end() const { return const_iterator(m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); } - /** const version of end() */ - const_iterator cend() const { return const_iterator(m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); } - - /** \returns a row or column vector expression of \c *this reduxed by \a func - * - * The template parameter \a BinaryOp is the type of the functor - * of the custom redux operator. Note that func must be an associative operator. - * - * \warning the size along the reduction direction must be strictly positive, - * otherwise an assertion is triggered. - * - * \sa class VectorwiseOp, DenseBase::colwise(), DenseBase::rowwise() - */ - template<typename BinaryOp> - EIGEN_DEVICE_FUNC - const typename ReduxReturnType<BinaryOp>::Type - redux(const BinaryOp& func = BinaryOp()) const - { - eigen_assert(redux_length()>0 && "you are using an empty matrix"); - return typename ReduxReturnType<BinaryOp>::Type(_expression(), internal::member_redux<BinaryOp,Scalar>(func)); - } - - typedef typename ReturnType<internal::member_minCoeff>::Type MinCoeffReturnType; - typedef typename ReturnType<internal::member_maxCoeff>::Type MaxCoeffReturnType; - typedef PartialReduxExpr<const CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const ExpressionTypeNestedCleaned>,internal::member_sum<RealScalar,RealScalar>,Direction> SquaredNormReturnType; - typedef CwiseUnaryOp<internal::scalar_sqrt_op<RealScalar>, const SquaredNormReturnType> NormReturnType; - typedef typename ReturnType<internal::member_blueNorm,RealScalar>::Type BlueNormReturnType; - typedef typename ReturnType<internal::member_stableNorm,RealScalar>::Type StableNormReturnType; - typedef typename ReturnType<internal::member_hypotNorm,RealScalar>::Type HypotNormReturnType; - typedef typename ReturnType<internal::member_sum>::Type SumReturnType; - typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(SumReturnType,Scalar,quotient) MeanReturnType; - typedef typename ReturnType<internal::member_all>::Type AllReturnType; - typedef typename ReturnType<internal::member_any>::Type AnyReturnType; - typedef PartialReduxExpr<ExpressionType, internal::member_count<Index,Scalar>, Direction> CountReturnType; - typedef typename ReturnType<internal::member_prod>::Type ProdReturnType; - typedef Reverse<const ExpressionType, Direction> ConstReverseReturnType; - typedef Reverse<ExpressionType, Direction> ReverseReturnType; - - template<int p> struct LpNormReturnType { - typedef PartialReduxExpr<ExpressionType, internal::member_lpnorm<p,RealScalar,Scalar>,Direction> Type; - }; - - /** \returns a row (or column) vector expression of the smallest coefficient - * of each column (or row) of the referenced expression. - * - * \warning the size along the reduction direction must be strictly positive, - * otherwise an assertion is triggered. - * - * \warning the result is undefined if \c *this contains NaN. - * - * Example: \include PartialRedux_minCoeff.cpp - * Output: \verbinclude PartialRedux_minCoeff.out - * - * \sa DenseBase::minCoeff() */ - EIGEN_DEVICE_FUNC - const MinCoeffReturnType minCoeff() const - { - eigen_assert(redux_length()>0 && "you are using an empty matrix"); - return MinCoeffReturnType(_expression()); - } - - /** \returns a row (or column) vector expression of the largest coefficient - * of each column (or row) of the referenced expression. - * - * \warning the size along the reduction direction must be strictly positive, - * otherwise an assertion is triggered. - * - * \warning the result is undefined if \c *this contains NaN. - * - * Example: \include PartialRedux_maxCoeff.cpp - * Output: \verbinclude PartialRedux_maxCoeff.out - * - * \sa DenseBase::maxCoeff() */ - EIGEN_DEVICE_FUNC - const MaxCoeffReturnType maxCoeff() const - { - eigen_assert(redux_length()>0 && "you are using an empty matrix"); - return MaxCoeffReturnType(_expression()); - } - - /** \returns a row (or column) vector expression of the squared norm - * of each column (or row) of the referenced expression. - * This is a vector with real entries, even if the original matrix has complex entries. - * - * Example: \include PartialRedux_squaredNorm.cpp - * Output: \verbinclude PartialRedux_squaredNorm.out - * - * \sa DenseBase::squaredNorm() */ - EIGEN_DEVICE_FUNC - const SquaredNormReturnType squaredNorm() const - { return SquaredNormReturnType(m_matrix.cwiseAbs2()); } - - /** \returns a row (or column) vector expression of the norm - * of each column (or row) of the referenced expression. - * This is a vector with real entries, even if the original matrix has complex entries. - * - * Example: \include PartialRedux_norm.cpp - * Output: \verbinclude PartialRedux_norm.out - * - * \sa DenseBase::norm() */ - EIGEN_DEVICE_FUNC - const NormReturnType norm() const - { return NormReturnType(squaredNorm()); } - - /** \returns a row (or column) vector expression of the norm - * of each column (or row) of the referenced expression. - * This is a vector with real entries, even if the original matrix has complex entries. - * - * Example: \include PartialRedux_norm.cpp - * Output: \verbinclude PartialRedux_norm.out - * - * \sa DenseBase::norm() */ - template<int p> - EIGEN_DEVICE_FUNC - const typename LpNormReturnType<p>::Type lpNorm() const - { return typename LpNormReturnType<p>::Type(_expression()); } - - - /** \returns a row (or column) vector expression of the norm - * of each column (or row) of the referenced expression, using - * Blue's algorithm. - * This is a vector with real entries, even if the original matrix has complex entries. - * - * \sa DenseBase::blueNorm() */ - EIGEN_DEVICE_FUNC - const BlueNormReturnType blueNorm() const - { return BlueNormReturnType(_expression()); } - - - /** \returns a row (or column) vector expression of the norm - * of each column (or row) of the referenced expression, avoiding - * underflow and overflow. - * This is a vector with real entries, even if the original matrix has complex entries. - * - * \sa DenseBase::stableNorm() */ - EIGEN_DEVICE_FUNC - const StableNormReturnType stableNorm() const - { return StableNormReturnType(_expression()); } - - - /** \returns a row (or column) vector expression of the norm - * of each column (or row) of the referenced expression, avoiding - * underflow and overflow using a concatenation of hypot() calls. - * This is a vector with real entries, even if the original matrix has complex entries. - * - * \sa DenseBase::hypotNorm() */ - EIGEN_DEVICE_FUNC - const HypotNormReturnType hypotNorm() const - { return HypotNormReturnType(_expression()); } - - /** \returns a row (or column) vector expression of the sum - * of each column (or row) of the referenced expression. - * - * Example: \include PartialRedux_sum.cpp - * Output: \verbinclude PartialRedux_sum.out - * - * \sa DenseBase::sum() */ - EIGEN_DEVICE_FUNC - const SumReturnType sum() const - { return SumReturnType(_expression()); } - - /** \returns a row (or column) vector expression of the mean - * of each column (or row) of the referenced expression. - * - * \sa DenseBase::mean() */ - EIGEN_DEVICE_FUNC - const MeanReturnType mean() const - { return sum() / Scalar(Direction==Vertical?m_matrix.rows():m_matrix.cols()); } - - /** \returns a row (or column) vector expression representing - * whether \b all coefficients of each respective column (or row) are \c true. - * This expression can be assigned to a vector with entries of type \c bool. - * - * \sa DenseBase::all() */ - EIGEN_DEVICE_FUNC - const AllReturnType all() const - { return AllReturnType(_expression()); } - - /** \returns a row (or column) vector expression representing - * whether \b at \b least one coefficient of each respective column (or row) is \c true. - * This expression can be assigned to a vector with entries of type \c bool. - * - * \sa DenseBase::any() */ - EIGEN_DEVICE_FUNC - const AnyReturnType any() const - { return AnyReturnType(_expression()); } - - /** \returns a row (or column) vector expression representing - * the number of \c true coefficients of each respective column (or row). - * This expression can be assigned to a vector whose entries have the same type as is used to - * index entries of the original matrix; for dense matrices, this is \c std::ptrdiff_t . - * - * Example: \include PartialRedux_count.cpp - * Output: \verbinclude PartialRedux_count.out - * - * \sa DenseBase::count() */ - EIGEN_DEVICE_FUNC - const CountReturnType count() const - { return CountReturnType(_expression()); } - - /** \returns a row (or column) vector expression of the product - * of each column (or row) of the referenced expression. - * - * Example: \include PartialRedux_prod.cpp - * Output: \verbinclude PartialRedux_prod.out - * - * \sa DenseBase::prod() */ - EIGEN_DEVICE_FUNC - const ProdReturnType prod() const - { return ProdReturnType(_expression()); } - - - /** \returns a matrix expression - * where each column (or row) are reversed. - * - * Example: \include Vectorwise_reverse.cpp - * Output: \verbinclude Vectorwise_reverse.out - * - * \sa DenseBase::reverse() */ - EIGEN_DEVICE_FUNC - const ConstReverseReturnType reverse() const - { return ConstReverseReturnType( _expression() ); } - - /** \returns a writable matrix expression - * where each column (or row) are reversed. - * - * \sa reverse() const */ - EIGEN_DEVICE_FUNC - ReverseReturnType reverse() - { return ReverseReturnType( _expression() ); } - - typedef Replicate<ExpressionType,(isVertical?Dynamic:1),(isHorizontal?Dynamic:1)> ReplicateReturnType; - EIGEN_DEVICE_FUNC - const ReplicateReturnType replicate(Index factor) const; - - /** - * \return an expression of the replication of each column (or row) of \c *this - * - * Example: \include DirectionWise_replicate.cpp - * Output: \verbinclude DirectionWise_replicate.out - * - * \sa VectorwiseOp::replicate(Index), DenseBase::replicate(), class Replicate - */ - // NOTE implemented here because of sunstudio's compilation errors - // isVertical*Factor+isHorizontal instead of (isVertical?Factor:1) to handle CUDA bug with ternary operator - template<int Factor> const Replicate<ExpressionType,isVertical*Factor+isHorizontal,isHorizontal*Factor+isVertical> - EIGEN_DEVICE_FUNC - replicate(Index factor = Factor) const - { - return Replicate<ExpressionType,(isVertical?Factor:1),(isHorizontal?Factor:1)> - (_expression(),isVertical?factor:1,isHorizontal?factor:1); - } - -/////////// Artithmetic operators /////////// - - /** Copies the vector \a other to each subvector of \c *this */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - ExpressionType& operator=(const DenseBase<OtherDerived>& other) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - //eigen_assert((m_matrix.isNull()) == (other.isNull())); FIXME - return m_matrix = extendedTo(other.derived()); - } - - /** Adds the vector \a other to each subvector of \c *this */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - ExpressionType& operator+=(const DenseBase<OtherDerived>& other) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - return m_matrix += extendedTo(other.derived()); - } - - /** Substracts the vector \a other to each subvector of \c *this */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - ExpressionType& operator-=(const DenseBase<OtherDerived>& other) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - return m_matrix -= extendedTo(other.derived()); - } - - /** Multiples each subvector of \c *this by the vector \a other */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - ExpressionType& operator*=(const DenseBase<OtherDerived>& other) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - m_matrix *= extendedTo(other.derived()); - return m_matrix; - } - - /** Divides each subvector of \c *this by the vector \a other */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - ExpressionType& operator/=(const DenseBase<OtherDerived>& other) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - m_matrix /= extendedTo(other.derived()); - return m_matrix; - } - - /** Returns the expression of the sum of the vector \a other to each subvector of \c *this */ - template<typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC - CwiseBinaryOp<internal::scalar_sum_op<Scalar,typename OtherDerived::Scalar>, - const ExpressionTypeNestedCleaned, - const typename ExtendedType<OtherDerived>::Type> - operator+(const DenseBase<OtherDerived>& other) const - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - return m_matrix + extendedTo(other.derived()); - } - - /** Returns the expression of the difference between each subvector of \c *this and the vector \a other */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - CwiseBinaryOp<internal::scalar_difference_op<Scalar,typename OtherDerived::Scalar>, - const ExpressionTypeNestedCleaned, - const typename ExtendedType<OtherDerived>::Type> - operator-(const DenseBase<OtherDerived>& other) const - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - return m_matrix - extendedTo(other.derived()); - } - - /** Returns the expression where each subvector is the product of the vector \a other - * by the corresponding subvector of \c *this */ - template<typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC - CwiseBinaryOp<internal::scalar_product_op<Scalar>, - const ExpressionTypeNestedCleaned, - const typename ExtendedType<OtherDerived>::Type> - EIGEN_DEVICE_FUNC - operator*(const DenseBase<OtherDerived>& other) const - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - return m_matrix * extendedTo(other.derived()); - } - - /** Returns the expression where each subvector is the quotient of the corresponding - * subvector of \c *this by the vector \a other */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, - const ExpressionTypeNestedCleaned, - const typename ExtendedType<OtherDerived>::Type> - operator/(const DenseBase<OtherDerived>& other) const - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType) - EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived) - return m_matrix / extendedTo(other.derived()); - } - - /** \returns an expression where each column (or row) of the referenced matrix are normalized. - * The referenced matrix is \b not modified. - * \sa MatrixBase::normalized(), normalize() - */ - EIGEN_DEVICE_FUNC - CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, - const ExpressionTypeNestedCleaned, - const typename OppositeExtendedType<NormReturnType>::Type> - normalized() const { return m_matrix.cwiseQuotient(extendedToOpposite(this->norm())); } - - - /** Normalize in-place each row or columns of the referenced matrix. - * \sa MatrixBase::normalize(), normalized() - */ - EIGEN_DEVICE_FUNC void normalize() { - m_matrix = this->normalized(); - } - - EIGEN_DEVICE_FUNC inline void reverseInPlace(); - -/////////// Geometry module /////////// - - typedef Homogeneous<ExpressionType,Direction> HomogeneousReturnType; - EIGEN_DEVICE_FUNC - HomogeneousReturnType homogeneous() const; - - typedef typename ExpressionType::PlainObject CrossReturnType; - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - const CrossReturnType cross(const MatrixBase<OtherDerived>& other) const; - - enum { - HNormalized_Size = Direction==Vertical ? internal::traits<ExpressionType>::RowsAtCompileTime - : internal::traits<ExpressionType>::ColsAtCompileTime, - HNormalized_SizeMinusOne = HNormalized_Size==Dynamic ? Dynamic : HNormalized_Size-1 - }; - typedef Block<const ExpressionType, - Direction==Vertical ? int(HNormalized_SizeMinusOne) - : int(internal::traits<ExpressionType>::RowsAtCompileTime), - Direction==Horizontal ? int(HNormalized_SizeMinusOne) - : int(internal::traits<ExpressionType>::ColsAtCompileTime)> - HNormalized_Block; - typedef Block<const ExpressionType, - Direction==Vertical ? 1 : int(internal::traits<ExpressionType>::RowsAtCompileTime), - Direction==Horizontal ? 1 : int(internal::traits<ExpressionType>::ColsAtCompileTime)> - HNormalized_Factors; - typedef CwiseBinaryOp<internal::scalar_quotient_op<typename internal::traits<ExpressionType>::Scalar>, - const HNormalized_Block, - const Replicate<HNormalized_Factors, - Direction==Vertical ? HNormalized_SizeMinusOne : 1, - Direction==Horizontal ? HNormalized_SizeMinusOne : 1> > - HNormalizedReturnType; - - EIGEN_DEVICE_FUNC - const HNormalizedReturnType hnormalized() const; - - protected: - Index redux_length() const - { - return Direction==Vertical ? m_matrix.rows() : m_matrix.cols(); - } - ExpressionTypeNested m_matrix; -}; - -//const colwise moved to DenseBase.h due to CUDA compiler bug - - -/** \returns a writable VectorwiseOp wrapper of *this providing additional partial reduction operations - * - * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline typename DenseBase<Derived>::ColwiseReturnType -DenseBase<Derived>::colwise() -{ - return ColwiseReturnType(derived()); -} - -//const rowwise moved to DenseBase.h due to CUDA compiler bug - - -/** \returns a writable VectorwiseOp wrapper of *this providing additional partial reduction operations - * - * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline typename DenseBase<Derived>::RowwiseReturnType -DenseBase<Derived>::rowwise() -{ - return RowwiseReturnType(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_PARTIAL_REDUX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/Visitor.h b/external/eigen/include/eigen3/Eigen/src/Core/Visitor.h deleted file mode 100644 index 67a69c54..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/Visitor.h +++ /dev/null @@ -1,309 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_VISITOR_H -#define EIGEN_VISITOR_H - -namespace Eigen { - -namespace internal { - -template<typename Visitor, typename Derived, int UnrollCount> -struct visitor_impl -{ - enum { - col = (UnrollCount-1) / Derived::RowsAtCompileTime, - row = (UnrollCount-1) % Derived::RowsAtCompileTime - }; - - EIGEN_DEVICE_FUNC - static inline void run(const Derived &mat, Visitor& visitor) - { - visitor_impl<Visitor, Derived, UnrollCount-1>::run(mat, visitor); - visitor(mat.coeff(row, col), row, col); - } -}; - -template<typename Visitor, typename Derived> -struct visitor_impl<Visitor, Derived, 1> -{ - EIGEN_DEVICE_FUNC - static inline void run(const Derived &mat, Visitor& visitor) - { - return visitor.init(mat.coeff(0, 0), 0, 0); - } -}; - -// This specialization enables visitors on empty matrices at compile-time -template<typename Visitor, typename Derived> -struct visitor_impl<Visitor, Derived, 0> { - EIGEN_DEVICE_FUNC - static inline void run(const Derived &/*mat*/, Visitor& /*visitor*/) - {} -}; - -template<typename Visitor, typename Derived> -struct visitor_impl<Visitor, Derived, Dynamic> -{ - EIGEN_DEVICE_FUNC - static inline void run(const Derived& mat, Visitor& visitor) - { - visitor.init(mat.coeff(0,0), 0, 0); - for(Index i = 1; i < mat.rows(); ++i) - visitor(mat.coeff(i, 0), i, 0); - for(Index j = 1; j < mat.cols(); ++j) - for(Index i = 0; i < mat.rows(); ++i) - visitor(mat.coeff(i, j), i, j); - } -}; - -// evaluator adaptor -template<typename XprType> -class visitor_evaluator -{ -public: - EIGEN_DEVICE_FUNC - explicit visitor_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {} - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - enum { - RowsAtCompileTime = XprType::RowsAtCompileTime, - CoeffReadCost = internal::evaluator<XprType>::CoeffReadCost - }; - - EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.rows(); } - EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.cols(); } - EIGEN_DEVICE_FUNC Index size() const { return m_xpr.size(); } - - EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col) const - { return m_evaluator.coeff(row, col); } - -protected: - internal::evaluator<XprType> m_evaluator; - const XprType &m_xpr; -}; -} // end namespace internal - -/** Applies the visitor \a visitor to the whole coefficients of the matrix or vector. - * - * The template parameter \a Visitor is the type of the visitor and provides the following interface: - * \code - * struct MyVisitor { - * // called for the first coefficient - * void init(const Scalar& value, Index i, Index j); - * // called for all other coefficients - * void operator() (const Scalar& value, Index i, Index j); - * }; - * \endcode - * - * \note compared to one or two \em for \em loops, visitors offer automatic - * unrolling for small fixed size matrix. - * - * \note if the matrix is empty, then the visitor is left unchanged. - * - * \sa minCoeff(Index*,Index*), maxCoeff(Index*,Index*), DenseBase::redux() - */ -template<typename Derived> -template<typename Visitor> -EIGEN_DEVICE_FUNC -void DenseBase<Derived>::visit(Visitor& visitor) const -{ - if(size()==0) - return; - - typedef typename internal::visitor_evaluator<Derived> ThisEvaluator; - ThisEvaluator thisEval(derived()); - - enum { - unroll = SizeAtCompileTime != Dynamic - && SizeAtCompileTime * ThisEvaluator::CoeffReadCost + (SizeAtCompileTime-1) * internal::functor_traits<Visitor>::Cost <= EIGEN_UNROLLING_LIMIT - }; - return internal::visitor_impl<Visitor, ThisEvaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(thisEval, visitor); -} - -namespace internal { - -/** \internal - * \brief Base class to implement min and max visitors - */ -template <typename Derived> -struct coeff_visitor -{ - // default initialization to avoid countless invalid maybe-uninitialized warnings by gcc - EIGEN_DEVICE_FUNC - coeff_visitor() : row(-1), col(-1), res(0) {} - typedef typename Derived::Scalar Scalar; - Index row, col; - Scalar res; - EIGEN_DEVICE_FUNC - inline void init(const Scalar& value, Index i, Index j) - { - res = value; - row = i; - col = j; - } -}; - -/** \internal - * \brief Visitor computing the min coefficient with its value and coordinates - * - * \sa DenseBase::minCoeff(Index*, Index*) - */ -template <typename Derived> -struct min_coeff_visitor : coeff_visitor<Derived> -{ - typedef typename Derived::Scalar Scalar; - EIGEN_DEVICE_FUNC - void operator() (const Scalar& value, Index i, Index j) - { - if(value < this->res) - { - this->res = value; - this->row = i; - this->col = j; - } - } -}; - -template<typename Scalar> -struct functor_traits<min_coeff_visitor<Scalar> > { - enum { - Cost = NumTraits<Scalar>::AddCost - }; -}; - -/** \internal - * \brief Visitor computing the max coefficient with its value and coordinates - * - * \sa DenseBase::maxCoeff(Index*, Index*) - */ -template <typename Derived> -struct max_coeff_visitor : coeff_visitor<Derived> -{ - typedef typename Derived::Scalar Scalar; - EIGEN_DEVICE_FUNC - void operator() (const Scalar& value, Index i, Index j) - { - if(value > this->res) - { - this->res = value; - this->row = i; - this->col = j; - } - } -}; - -template<typename Scalar> -struct functor_traits<max_coeff_visitor<Scalar> > { - enum { - Cost = NumTraits<Scalar>::AddCost - }; -}; - -} // end namespace internal - -/** \fn DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const - * \returns the minimum of all coefficients of *this and puts in *row and *col its location. - * - * \warning the matrix must be not empty, otherwise an assertion is triggered. - * - * \warning the result is undefined if \c *this contains NaN. - * - * \sa DenseBase::minCoeff(Index*), DenseBase::maxCoeff(Index*,Index*), DenseBase::visit(), DenseBase::minCoeff() - */ -template<typename Derived> -template<typename IndexType> -EIGEN_DEVICE_FUNC -typename internal::traits<Derived>::Scalar -DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const -{ - eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix"); - - internal::min_coeff_visitor<Derived> minVisitor; - this->visit(minVisitor); - *rowId = minVisitor.row; - if (colId) *colId = minVisitor.col; - return minVisitor.res; -} - -/** \returns the minimum of all coefficients of *this and puts in *index its location. - * - * \warning the matrix must be not empty, otherwise an assertion is triggered. - * - * \warning the result is undefined if \c *this contains NaN. - * - * \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::visit(), DenseBase::minCoeff() - */ -template<typename Derived> -template<typename IndexType> -EIGEN_DEVICE_FUNC -typename internal::traits<Derived>::Scalar -DenseBase<Derived>::minCoeff(IndexType* index) const -{ - eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix"); - - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - internal::min_coeff_visitor<Derived> minVisitor; - this->visit(minVisitor); - *index = IndexType((RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row); - return minVisitor.res; -} - -/** \fn DenseBase<Derived>::maxCoeff(IndexType* rowId, IndexType* colId) const - * \returns the maximum of all coefficients of *this and puts in *row and *col its location. - * - * \warning the matrix must be not empty, otherwise an assertion is triggered. - * - * \warning the result is undefined if \c *this contains NaN. - * - * \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visit(), DenseBase::maxCoeff() - */ -template<typename Derived> -template<typename IndexType> -EIGEN_DEVICE_FUNC -typename internal::traits<Derived>::Scalar -DenseBase<Derived>::maxCoeff(IndexType* rowPtr, IndexType* colPtr) const -{ - eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix"); - - internal::max_coeff_visitor<Derived> maxVisitor; - this->visit(maxVisitor); - *rowPtr = maxVisitor.row; - if (colPtr) *colPtr = maxVisitor.col; - return maxVisitor.res; -} - -/** \returns the maximum of all coefficients of *this and puts in *index its location. - * - * \warning the matrix must be not empty, otherwise an assertion is triggered. - * - * \warning the result is undefined if \c *this contains NaN. - * - * \sa DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::maxCoeff() - */ -template<typename Derived> -template<typename IndexType> -EIGEN_DEVICE_FUNC -typename internal::traits<Derived>::Scalar -DenseBase<Derived>::maxCoeff(IndexType* index) const -{ - eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix"); - - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - internal::max_coeff_visitor<Derived> maxVisitor; - this->visit(maxVisitor); - *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row; - return maxVisitor.res; -} - -} // end namespace Eigen - -#endif // EIGEN_VISITOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/Complex.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/Complex.h deleted file mode 100644 index f97efd47..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/Complex.h +++ /dev/null @@ -1,471 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner (benoit.steiner.goog@gmail.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX_AVX_H -#define EIGEN_COMPLEX_AVX_H - -namespace Eigen { - -namespace internal { - -//---------- float ---------- -struct Packet4cf -{ - EIGEN_STRONG_INLINE Packet4cf() {} - EIGEN_STRONG_INLINE explicit Packet4cf(const __m256& a) : v(a) {} - __m256 v; -}; - -#ifndef EIGEN_VECTORIZE_AVX512 -template<> struct packet_traits<std::complex<float> > : default_packet_traits -{ - typedef Packet4cf type; - typedef Packet2cf half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 1, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0 - }; -}; -#endif - -template<> struct unpacket_traits<Packet4cf> { typedef std::complex<float> type; enum {size=4, alignment=Aligned32, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2cf half; }; - -template<> EIGEN_STRONG_INLINE Packet4cf padd<Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_add_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cf psub<Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_sub_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cf pnegate(const Packet4cf& a) -{ - return Packet4cf(pnegate(a.v)); -} -template<> EIGEN_STRONG_INLINE Packet4cf pconj(const Packet4cf& a) -{ - const __m256 mask = _mm256_castsi256_ps(_mm256_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000)); - return Packet4cf(_mm256_xor_ps(a.v,mask)); -} - -template<> EIGEN_STRONG_INLINE Packet4cf pmul<Packet4cf>(const Packet4cf& a, const Packet4cf& b) -{ - __m256 tmp1 = _mm256_mul_ps(_mm256_moveldup_ps(a.v), b.v); - __m256 tmp2 = _mm256_mul_ps(_mm256_movehdup_ps(a.v), _mm256_permute_ps(b.v, _MM_SHUFFLE(2,3,0,1))); - __m256 result = _mm256_addsub_ps(tmp1, tmp2); - return Packet4cf(result); -} - -template <> -EIGEN_STRONG_INLINE Packet4cf pcmp_eq(const Packet4cf& a, const Packet4cf& b) { - __m256 eq = _mm256_cmp_ps(a.v, b.v, _CMP_EQ_OQ); - return Packet4cf(_mm256_and_ps(eq, _mm256_permute_ps(eq, 0xb1))); -} - -template<> EIGEN_STRONG_INLINE Packet4cf ptrue<Packet4cf>(const Packet4cf& a) { return Packet4cf(ptrue(Packet8f(a.v))); } -template<> EIGEN_STRONG_INLINE Packet4cf pnot<Packet4cf>(const Packet4cf& a) { return Packet4cf(pnot(Packet8f(a.v))); } -template<> EIGEN_STRONG_INLINE Packet4cf pand <Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_and_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cf por <Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_or_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cf pxor <Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_xor_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cf pandnot<Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_andnot_ps(b.v,a.v)); } - -template<> EIGEN_STRONG_INLINE Packet4cf pload <Packet4cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet4cf(pload<Packet8f>(&numext::real_ref(*from))); } -template<> EIGEN_STRONG_INLINE Packet4cf ploadu<Packet4cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet4cf(ploadu<Packet8f>(&numext::real_ref(*from))); } - - -template<> EIGEN_STRONG_INLINE Packet4cf pset1<Packet4cf>(const std::complex<float>& from) -{ - return Packet4cf(_mm256_castpd_ps(_mm256_broadcast_sd((const double*)(const void*)&from))); -} - -template<> EIGEN_STRONG_INLINE Packet4cf ploaddup<Packet4cf>(const std::complex<float>* from) -{ - // FIXME The following might be optimized using _mm256_movedup_pd - Packet2cf a = ploaddup<Packet2cf>(from); - Packet2cf b = ploaddup<Packet2cf>(from+1); - return Packet4cf(_mm256_insertf128_ps(_mm256_castps128_ps256(a.v), b.v, 1)); -} - -template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float>* to, const Packet4cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float>* to, const Packet4cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), from.v); } - -template<> EIGEN_DEVICE_FUNC inline Packet4cf pgather<std::complex<float>, Packet4cf>(const std::complex<float>* from, Index stride) -{ - return Packet4cf(_mm256_set_ps(std::imag(from[3*stride]), std::real(from[3*stride]), - std::imag(from[2*stride]), std::real(from[2*stride]), - std::imag(from[1*stride]), std::real(from[1*stride]), - std::imag(from[0*stride]), std::real(from[0*stride]))); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet4cf>(std::complex<float>* to, const Packet4cf& from, Index stride) -{ - __m128 low = _mm256_extractf128_ps(from.v, 0); - to[stride*0] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(low, low, 0)), - _mm_cvtss_f32(_mm_shuffle_ps(low, low, 1))); - to[stride*1] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(low, low, 2)), - _mm_cvtss_f32(_mm_shuffle_ps(low, low, 3))); - - __m128 high = _mm256_extractf128_ps(from.v, 1); - to[stride*2] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(high, high, 0)), - _mm_cvtss_f32(_mm_shuffle_ps(high, high, 1))); - to[stride*3] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(high, high, 2)), - _mm_cvtss_f32(_mm_shuffle_ps(high, high, 3))); - -} - -template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet4cf>(const Packet4cf& a) -{ - return pfirst(Packet2cf(_mm256_castps256_ps128(a.v))); -} - -template<> EIGEN_STRONG_INLINE Packet4cf preverse(const Packet4cf& a) { - __m128 low = _mm256_extractf128_ps(a.v, 0); - __m128 high = _mm256_extractf128_ps(a.v, 1); - __m128d lowd = _mm_castps_pd(low); - __m128d highd = _mm_castps_pd(high); - low = _mm_castpd_ps(_mm_shuffle_pd(lowd,lowd,0x1)); - high = _mm_castpd_ps(_mm_shuffle_pd(highd,highd,0x1)); - __m256 result = _mm256_setzero_ps(); - result = _mm256_insertf128_ps(result, low, 1); - result = _mm256_insertf128_ps(result, high, 0); - return Packet4cf(result); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet4cf>(const Packet4cf& a) -{ - return predux(padd(Packet2cf(_mm256_extractf128_ps(a.v,0)), - Packet2cf(_mm256_extractf128_ps(a.v,1)))); -} - -template<> EIGEN_STRONG_INLINE Packet4cf preduxp<Packet4cf>(const Packet4cf* vecs) -{ - Packet8f t0 = _mm256_shuffle_ps(vecs[0].v, vecs[0].v, _MM_SHUFFLE(3, 1, 2 ,0)); - Packet8f t1 = _mm256_shuffle_ps(vecs[1].v, vecs[1].v, _MM_SHUFFLE(3, 1, 2 ,0)); - t0 = _mm256_hadd_ps(t0,t1); - Packet8f t2 = _mm256_shuffle_ps(vecs[2].v, vecs[2].v, _MM_SHUFFLE(3, 1, 2 ,0)); - Packet8f t3 = _mm256_shuffle_ps(vecs[3].v, vecs[3].v, _MM_SHUFFLE(3, 1, 2 ,0)); - t2 = _mm256_hadd_ps(t2,t3); - - t1 = _mm256_permute2f128_ps(t0,t2, 0 + (2<<4)); - t3 = _mm256_permute2f128_ps(t0,t2, 1 + (3<<4)); - - return Packet4cf(_mm256_add_ps(t1,t3)); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet4cf>(const Packet4cf& a) -{ - return predux_mul(pmul(Packet2cf(_mm256_extractf128_ps(a.v, 0)), - Packet2cf(_mm256_extractf128_ps(a.v, 1)))); -} - -template<int Offset> -struct palign_impl<Offset,Packet4cf> -{ - static EIGEN_STRONG_INLINE void run(Packet4cf& first, const Packet4cf& second) - { - if (Offset==0) return; - palign_impl<Offset*2,Packet8f>::run(first.v, second.v); - } -}; - -template<> struct conj_helper<Packet4cf, Packet4cf, false,true> -{ - EIGEN_STRONG_INLINE Packet4cf pmadd(const Packet4cf& x, const Packet4cf& y, const Packet4cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet4cf pmul(const Packet4cf& a, const Packet4cf& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet4cf, Packet4cf, true,false> -{ - EIGEN_STRONG_INLINE Packet4cf pmadd(const Packet4cf& x, const Packet4cf& y, const Packet4cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet4cf pmul(const Packet4cf& a, const Packet4cf& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet4cf, Packet4cf, true,true> -{ - EIGEN_STRONG_INLINE Packet4cf pmadd(const Packet4cf& x, const Packet4cf& y, const Packet4cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet4cf pmul(const Packet4cf& a, const Packet4cf& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet4cf,Packet8f) - -template<> EIGEN_STRONG_INLINE Packet4cf pdiv<Packet4cf>(const Packet4cf& a, const Packet4cf& b) -{ - Packet4cf num = pmul(a, pconj(b)); - __m256 tmp = _mm256_mul_ps(b.v, b.v); - __m256 tmp2 = _mm256_shuffle_ps(tmp,tmp,0xB1); - __m256 denom = _mm256_add_ps(tmp, tmp2); - return Packet4cf(_mm256_div_ps(num.v, denom)); -} - -template<> EIGEN_STRONG_INLINE Packet4cf pcplxflip<Packet4cf>(const Packet4cf& x) -{ - return Packet4cf(_mm256_shuffle_ps(x.v, x.v, _MM_SHUFFLE(2, 3, 0 ,1))); -} - -//---------- double ---------- -struct Packet2cd -{ - EIGEN_STRONG_INLINE Packet2cd() {} - EIGEN_STRONG_INLINE explicit Packet2cd(const __m256d& a) : v(a) {} - __m256d v; -}; - -#ifndef EIGEN_VECTORIZE_AVX512 -template<> struct packet_traits<std::complex<double> > : default_packet_traits -{ - typedef Packet2cd type; - typedef Packet1cd half; - enum { - Vectorizable = 1, - AlignedOnScalar = 0, - size = 2, - HasHalfPacket = 1, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0 - }; -}; -#endif - -template<> struct unpacket_traits<Packet2cd> { typedef std::complex<double> type; enum {size=2, alignment=Aligned32, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet1cd half; }; - -template<> EIGEN_STRONG_INLINE Packet2cd padd<Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_add_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cd psub<Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_sub_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cd pnegate(const Packet2cd& a) { return Packet2cd(pnegate(a.v)); } -template<> EIGEN_STRONG_INLINE Packet2cd pconj(const Packet2cd& a) -{ - const __m256d mask = _mm256_castsi256_pd(_mm256_set_epi32(0x80000000,0x0,0x0,0x0,0x80000000,0x0,0x0,0x0)); - return Packet2cd(_mm256_xor_pd(a.v,mask)); -} - -template<> EIGEN_STRONG_INLINE Packet2cd pmul<Packet2cd>(const Packet2cd& a, const Packet2cd& b) -{ - __m256d tmp1 = _mm256_shuffle_pd(a.v,a.v,0x0); - __m256d even = _mm256_mul_pd(tmp1, b.v); - __m256d tmp2 = _mm256_shuffle_pd(a.v,a.v,0xF); - __m256d tmp3 = _mm256_shuffle_pd(b.v,b.v,0x5); - __m256d odd = _mm256_mul_pd(tmp2, tmp3); - return Packet2cd(_mm256_addsub_pd(even, odd)); -} - -template <> -EIGEN_STRONG_INLINE Packet2cd pcmp_eq(const Packet2cd& a, const Packet2cd& b) { - __m256d eq = _mm256_cmp_pd(a.v, b.v, _CMP_EQ_OQ); - return Packet2cd(pand(eq, _mm256_permute_pd(eq, 0x5))); -} - -template<> EIGEN_STRONG_INLINE Packet2cd ptrue<Packet2cd>(const Packet2cd& a) { return Packet2cd(ptrue(Packet4d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet2cd pnot<Packet2cd>(const Packet2cd& a) { return Packet2cd(pnot(Packet4d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet2cd pand <Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_and_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cd por <Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_or_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cd pxor <Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_xor_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cd pandnot<Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_andnot_pd(b.v,a.v)); } - -template<> EIGEN_STRONG_INLINE Packet2cd pload <Packet2cd>(const std::complex<double>* from) -{ EIGEN_DEBUG_ALIGNED_LOAD return Packet2cd(pload<Packet4d>((const double*)from)); } -template<> EIGEN_STRONG_INLINE Packet2cd ploadu<Packet2cd>(const std::complex<double>* from) -{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cd(ploadu<Packet4d>((const double*)from)); } - -template<> EIGEN_STRONG_INLINE Packet2cd pset1<Packet2cd>(const std::complex<double>& from) -{ - // in case casting to a __m128d* is really not safe, then we can still fallback to this version: (much slower though) -// return Packet2cd(_mm256_loadu2_m128d((const double*)&from,(const double*)&from)); - return Packet2cd(_mm256_broadcast_pd((const __m128d*)(const void*)&from)); -} - -template<> EIGEN_STRONG_INLINE Packet2cd ploaddup<Packet2cd>(const std::complex<double>* from) { return pset1<Packet2cd>(*from); } - -template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet2cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet2cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, from.v); } - -template<> EIGEN_DEVICE_FUNC inline Packet2cd pgather<std::complex<double>, Packet2cd>(const std::complex<double>* from, Index stride) -{ - return Packet2cd(_mm256_set_pd(std::imag(from[1*stride]), std::real(from[1*stride]), - std::imag(from[0*stride]), std::real(from[0*stride]))); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet2cd>(std::complex<double>* to, const Packet2cd& from, Index stride) -{ - __m128d low = _mm256_extractf128_pd(from.v, 0); - to[stride*0] = std::complex<double>(_mm_cvtsd_f64(low), _mm_cvtsd_f64(_mm_shuffle_pd(low, low, 1))); - __m128d high = _mm256_extractf128_pd(from.v, 1); - to[stride*1] = std::complex<double>(_mm_cvtsd_f64(high), _mm_cvtsd_f64(_mm_shuffle_pd(high, high, 1))); -} - -template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet2cd>(const Packet2cd& a) -{ - __m128d low = _mm256_extractf128_pd(a.v, 0); - EIGEN_ALIGN16 double res[2]; - _mm_store_pd(res, low); - return std::complex<double>(res[0],res[1]); -} - -template<> EIGEN_STRONG_INLINE Packet2cd preverse(const Packet2cd& a) { - __m256d result = _mm256_permute2f128_pd(a.v, a.v, 1); - return Packet2cd(result); -} - -template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet2cd>(const Packet2cd& a) -{ - return predux(padd(Packet1cd(_mm256_extractf128_pd(a.v,0)), - Packet1cd(_mm256_extractf128_pd(a.v,1)))); -} - -template<> EIGEN_STRONG_INLINE Packet2cd preduxp<Packet2cd>(const Packet2cd* vecs) -{ - Packet4d t0 = _mm256_permute2f128_pd(vecs[0].v,vecs[1].v, 0 + (2<<4)); - Packet4d t1 = _mm256_permute2f128_pd(vecs[0].v,vecs[1].v, 1 + (3<<4)); - - return Packet2cd(_mm256_add_pd(t0,t1)); -} - -template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet2cd>(const Packet2cd& a) -{ - return predux(pmul(Packet1cd(_mm256_extractf128_pd(a.v,0)), - Packet1cd(_mm256_extractf128_pd(a.v,1)))); -} - -template<int Offset> -struct palign_impl<Offset,Packet2cd> -{ - static EIGEN_STRONG_INLINE void run(Packet2cd& first, const Packet2cd& second) - { - if (Offset==0) return; - palign_impl<Offset*2,Packet4d>::run(first.v, second.v); - } -}; - -template<> struct conj_helper<Packet2cd, Packet2cd, false,true> -{ - EIGEN_STRONG_INLINE Packet2cd pmadd(const Packet2cd& x, const Packet2cd& y, const Packet2cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cd pmul(const Packet2cd& a, const Packet2cd& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet2cd, Packet2cd, true,false> -{ - EIGEN_STRONG_INLINE Packet2cd pmadd(const Packet2cd& x, const Packet2cd& y, const Packet2cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cd pmul(const Packet2cd& a, const Packet2cd& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet2cd, Packet2cd, true,true> -{ - EIGEN_STRONG_INLINE Packet2cd pmadd(const Packet2cd& x, const Packet2cd& y, const Packet2cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cd pmul(const Packet2cd& a, const Packet2cd& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cd,Packet4d) - -template<> EIGEN_STRONG_INLINE Packet2cd pdiv<Packet2cd>(const Packet2cd& a, const Packet2cd& b) -{ - Packet2cd num = pmul(a, pconj(b)); - __m256d tmp = _mm256_mul_pd(b.v, b.v); - __m256d denom = _mm256_hadd_pd(tmp, tmp); - return Packet2cd(_mm256_div_pd(num.v, denom)); -} - -template<> EIGEN_STRONG_INLINE Packet2cd pcplxflip<Packet2cd>(const Packet2cd& x) -{ - return Packet2cd(_mm256_shuffle_pd(x.v, x.v, 0x5)); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4cf,4>& kernel) { - __m256d P0 = _mm256_castps_pd(kernel.packet[0].v); - __m256d P1 = _mm256_castps_pd(kernel.packet[1].v); - __m256d P2 = _mm256_castps_pd(kernel.packet[2].v); - __m256d P3 = _mm256_castps_pd(kernel.packet[3].v); - - __m256d T0 = _mm256_shuffle_pd(P0, P1, 15); - __m256d T1 = _mm256_shuffle_pd(P0, P1, 0); - __m256d T2 = _mm256_shuffle_pd(P2, P3, 15); - __m256d T3 = _mm256_shuffle_pd(P2, P3, 0); - - kernel.packet[1].v = _mm256_castpd_ps(_mm256_permute2f128_pd(T0, T2, 32)); - kernel.packet[3].v = _mm256_castpd_ps(_mm256_permute2f128_pd(T0, T2, 49)); - kernel.packet[0].v = _mm256_castpd_ps(_mm256_permute2f128_pd(T1, T3, 32)); - kernel.packet[2].v = _mm256_castpd_ps(_mm256_permute2f128_pd(T1, T3, 49)); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet2cd,2>& kernel) { - __m256d tmp = _mm256_permute2f128_pd(kernel.packet[0].v, kernel.packet[1].v, 0+(2<<4)); - kernel.packet[1].v = _mm256_permute2f128_pd(kernel.packet[0].v, kernel.packet[1].v, 1+(3<<4)); - kernel.packet[0].v = tmp; -} - -template<> EIGEN_STRONG_INLINE Packet4cf pinsertfirst(const Packet4cf& a, std::complex<float> b) -{ - return Packet4cf(_mm256_blend_ps(a.v,pset1<Packet4cf>(b).v,1|2)); -} - -template<> EIGEN_STRONG_INLINE Packet2cd pinsertfirst(const Packet2cd& a, std::complex<double> b) -{ - return Packet2cd(_mm256_blend_pd(a.v,pset1<Packet2cd>(b).v,1|2)); -} - -template<> EIGEN_STRONG_INLINE Packet4cf pinsertlast(const Packet4cf& a, std::complex<float> b) -{ - return Packet4cf(_mm256_blend_ps(a.v,pset1<Packet4cf>(b).v,(1<<7)|(1<<6))); -} - -template<> EIGEN_STRONG_INLINE Packet2cd pinsertlast(const Packet2cd& a, std::complex<double> b) -{ - return Packet2cd(_mm256_blend_pd(a.v,pset1<Packet2cd>(b).v,(1<<3)|(1<<2))); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_AVX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/MathFunctions.h deleted file mode 100644 index c5394430..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/MathFunctions.h +++ /dev/null @@ -1,160 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATH_FUNCTIONS_AVX_H -#define EIGEN_MATH_FUNCTIONS_AVX_H - -/* The sin and cos functions of this file are loosely derived from - * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/ - */ - -namespace Eigen { - -namespace internal { - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f -psin<Packet8f>(const Packet8f& _x) { - return psin_float(_x); -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f -pcos<Packet8f>(const Packet8f& _x) { - return pcos_float(_x); -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f -plog<Packet8f>(const Packet8f& _x) { - return plog_float(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet8f plog1p<Packet8f>(const Packet8f& _x) { - return generic_plog1p(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet8f pexpm1<Packet8f>(const Packet8f& _x) { - return generic_expm1(_x); -} - -// Exponential function. Works by writing "x = m*log(2) + r" where -// "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then -// "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1). -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f -pexp<Packet8f>(const Packet8f& _x) { - return pexp_float(_x); -} - -// Hyperbolic Tangent function. -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f -ptanh<Packet8f>(const Packet8f& x) { - return internal::generic_fast_tanh_float(x); -} - -// Exponential function for doubles. -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4d -pexp<Packet4d>(const Packet4d& x) { - return pexp_double(x); -} - -// Functions for sqrt. -// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step -// of Newton's method, at a cost of 1-2 bits of precision as opposed to the -// exact solution. It does not handle +inf, or denormalized numbers correctly. -// The main advantage of this approach is not just speed, but also the fact that -// it can be inlined and pipelined with other computations, further reducing its -// effective latency. This is similar to Quake3's fast inverse square root. -// For detail see here: http://www.beyond3d.com/content/articles/8/ -#if EIGEN_FAST_MATH -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f -psqrt<Packet8f>(const Packet8f& _x) { - Packet8f half = pmul(_x, pset1<Packet8f>(.5f)); - Packet8f denormal_mask = _mm256_and_ps( - _mm256_cmp_ps(_x, pset1<Packet8f>((std::numeric_limits<float>::min)()), - _CMP_LT_OQ), - _mm256_cmp_ps(_x, _mm256_setzero_ps(), _CMP_GE_OQ)); - - // Compute approximate reciprocal sqrt. - Packet8f x = _mm256_rsqrt_ps(_x); - // Do a single step of Newton's iteration. - x = pmul(x, psub(pset1<Packet8f>(1.5f), pmul(half, pmul(x,x)))); - // Flush results for denormals to zero. - return _mm256_andnot_ps(denormal_mask, pmul(_x,x)); -} -#else -template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet8f psqrt<Packet8f>(const Packet8f& x) { - return _mm256_sqrt_ps(x); -} -#endif -template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4d psqrt<Packet4d>(const Packet4d& x) { - return _mm256_sqrt_pd(x); -} -#if EIGEN_FAST_MATH - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet8f prsqrt<Packet8f>(const Packet8f& _x) { - _EIGEN_DECLARE_CONST_Packet8f_FROM_INT(inf, 0x7f800000); - _EIGEN_DECLARE_CONST_Packet8f(one_point_five, 1.5f); - _EIGEN_DECLARE_CONST_Packet8f(minus_half, -0.5f); - _EIGEN_DECLARE_CONST_Packet8f_FROM_INT(flt_min, 0x00800000); - - Packet8f neg_half = pmul(_x, p8f_minus_half); - - // select only the inverse sqrt of positive normal inputs (denormals are - // flushed to zero and cause infs as well). - Packet8f lt_min_mask = _mm256_cmp_ps(_x, p8f_flt_min, _CMP_LT_OQ); - Packet8f inf_mask = _mm256_cmp_ps(_x, p8f_inf, _CMP_EQ_OQ); - Packet8f not_normal_finite_mask = _mm256_or_ps(lt_min_mask, inf_mask); - - // Compute an approximate result using the rsqrt intrinsic. - Packet8f y_approx = _mm256_rsqrt_ps(_x); - - // Do a single step of Newton-Raphson iteration to improve the approximation. - // This uses the formula y_{n+1} = y_n * (1.5 - y_n * (0.5 * x) * y_n). - // It is essential to evaluate the inner term like this because forming - // y_n^2 may over- or underflow. - Packet8f y_newton = pmul(y_approx, pmadd(y_approx, pmul(neg_half, y_approx), p8f_one_point_five)); - - // Select the result of the Newton-Raphson step for positive normal arguments. - // For other arguments, choose the output of the intrinsic. This will - // return rsqrt(+inf) = 0, rsqrt(x) = NaN if x < 0, and rsqrt(x) = +inf if - // x is zero or a positive denormalized float (equivalent to flushing positive - // denormalized inputs to zero). - return pselect<Packet8f>(not_normal_finite_mask, y_approx, y_newton); -} - -#else -template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet8f prsqrt<Packet8f>(const Packet8f& x) { - _EIGEN_DECLARE_CONST_Packet8f(one, 1.0f); - return _mm256_div_ps(p8f_one, _mm256_sqrt_ps(x)); -} -#endif - -template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4d prsqrt<Packet4d>(const Packet4d& x) { - _EIGEN_DECLARE_CONST_Packet4d(one, 1.0); - return _mm256_div_pd(p4d_one, _mm256_sqrt_pd(x)); -} - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATH_FUNCTIONS_AVX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/PacketMath.h deleted file mode 100644 index 11c7bcb4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/PacketMath.h +++ /dev/null @@ -1,1238 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner (benoit.steiner.goog@gmail.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PACKET_MATH_AVX_H -#define EIGEN_PACKET_MATH_AVX_H - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD -#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 -#endif - -#if !defined(EIGEN_VECTORIZE_AVX512) && !defined(EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS) -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 16 -#endif - -#ifdef EIGEN_VECTORIZE_FMA -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#endif -#endif - -typedef __m256 Packet8f; -typedef __m256i Packet8i; -typedef __m256d Packet4d; -typedef struct { - __m128i x; -} Packet8h; - -template<> struct is_arithmetic<__m256> { enum { value = true }; }; -template<> struct is_arithmetic<__m256i> { enum { value = true }; }; -template<> struct is_arithmetic<__m256d> { enum { value = true }; }; -template<> struct is_arithmetic<Packet8h> { enum { value = true }; }; - -#define _EIGEN_DECLARE_CONST_Packet8f(NAME,X) \ - const Packet8f p8f_##NAME = pset1<Packet8f>(X) - -#define _EIGEN_DECLARE_CONST_Packet4d(NAME,X) \ - const Packet4d p4d_##NAME = pset1<Packet4d>(X) - -#define _EIGEN_DECLARE_CONST_Packet8f_FROM_INT(NAME,X) \ - const Packet8f p8f_##NAME = _mm256_castsi256_ps(pset1<Packet8i>(X)) - -#define _EIGEN_DECLARE_CONST_Packet8i(NAME,X) \ - const Packet8i p8i_##NAME = pset1<Packet8i>(X) - -// Use the packet_traits defined in AVX512/PacketMath.h instead if we're going -// to leverage AVX512 instructions. -#ifndef EIGEN_VECTORIZE_AVX512 -template<> struct packet_traits<float> : default_packet_traits -{ - typedef Packet8f type; - typedef Packet4f half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 8, - HasHalfPacket = 1, - - HasDiv = 1, - HasSin = EIGEN_FAST_MATH, - HasCos = EIGEN_FAST_MATH, - HasLog = 1, - HasLog1p = 1, - HasExpm1 = 1, - HasExp = 1, - HasNdtri = 1, - HasBessel = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasTanh = EIGEN_FAST_MATH, - HasErf = EIGEN_FAST_MATH, - HasBlend = 1, - HasRound = 1, - HasFloor = 1, - HasCeil = 1, - HasRint = 1 - }; -}; -template<> struct packet_traits<double> : default_packet_traits -{ - typedef Packet4d type; - typedef Packet2d half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=4, - HasHalfPacket = 1, - - HasDiv = 1, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasBlend = 1, - HasRound = 1, - HasFloor = 1, - HasCeil = 1 - }; -}; - -template <> -struct packet_traits<Eigen::half> : default_packet_traits { - typedef Packet8h type; - // There is no half-size packet for Packet8h. - typedef Packet8h half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 8, - HasHalfPacket = 0, - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasConj = 0, - HasSetLinear = 0, - HasSqrt = 0, - HasRsqrt = 0, - HasExp = 0, - HasLog = 0, - HasBlend = 0 - }; -}; -#endif - -template<> struct scalar_div_cost<float,true> { enum { value = 14 }; }; -template<> struct scalar_div_cost<double,true> { enum { value = 16 }; }; - -/* Proper support for integers is only provided by AVX2. In the meantime, we'll - use SSE instructions and packets to deal with integers. -template<> struct packet_traits<int> : default_packet_traits -{ - typedef Packet8i type; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=8 - }; -}; -*/ - -template<> struct unpacket_traits<Packet8f> { - typedef float type; - typedef Packet4f half; - typedef Packet8i integer_packet; - typedef uint8_t mask_t; - enum {size=8, alignment=Aligned32, vectorizable=true, masked_load_available=true, masked_store_available=true}; -}; -template<> struct unpacket_traits<Packet4d> { - typedef double type; - typedef Packet2d half; - enum {size=4, alignment=Aligned32, vectorizable=true, masked_load_available=false, masked_store_available=false}; -}; -template<> struct unpacket_traits<Packet8i> { typedef int type; typedef Packet4i half; enum {size=8, alignment=Aligned32, vectorizable=false, masked_load_available=false, masked_store_available=false}; }; - -template<> EIGEN_STRONG_INLINE Packet8f pset1<Packet8f>(const float& from) { return _mm256_set1_ps(from); } -template<> EIGEN_STRONG_INLINE Packet4d pset1<Packet4d>(const double& from) { return _mm256_set1_pd(from); } -template<> EIGEN_STRONG_INLINE Packet8i pset1<Packet8i>(const int& from) { return _mm256_set1_epi32(from); } - -template<> EIGEN_STRONG_INLINE Packet8f pset1frombits<Packet8f>(unsigned int from) { return _mm256_castsi256_ps(pset1<Packet8i>(from)); } - -template<> EIGEN_STRONG_INLINE Packet8f pzero(const Packet8f& /*a*/) { return _mm256_setzero_ps(); } -template<> EIGEN_STRONG_INLINE Packet4d pzero(const Packet4d& /*a*/) { return _mm256_setzero_pd(); } -template<> EIGEN_STRONG_INLINE Packet8i pzero(const Packet8i& /*a*/) { return _mm256_setzero_si256(); } - -template<> EIGEN_STRONG_INLINE Packet8f pload1<Packet8f>(const float* from) { return _mm256_broadcast_ss(from); } -template<> EIGEN_STRONG_INLINE Packet4d pload1<Packet4d>(const double* from) { return _mm256_broadcast_sd(from); } - -template<> EIGEN_STRONG_INLINE Packet8f plset<Packet8f>(const float& a) { return _mm256_add_ps(_mm256_set1_ps(a), _mm256_set_ps(7.0,6.0,5.0,4.0,3.0,2.0,1.0,0.0)); } -template<> EIGEN_STRONG_INLINE Packet4d plset<Packet4d>(const double& a) { return _mm256_add_pd(_mm256_set1_pd(a), _mm256_set_pd(3.0,2.0,1.0,0.0)); } - -template<> EIGEN_STRONG_INLINE Packet8f padd<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_add_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4d padd<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_add_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet8i padd<Packet8i>(const Packet8i& a, const Packet8i& b) { -#ifdef EIGEN_VECTORIZE_AVX2 - return _mm256_add_epi32(a,b); -#else - __m128i lo = _mm_add_epi32(_mm256_extractf128_si256(a, 0), _mm256_extractf128_si256(b, 0)); - __m128i hi = _mm_add_epi32(_mm256_extractf128_si256(a, 1), _mm256_extractf128_si256(b, 1)); - return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f psub<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_sub_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4d psub<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_sub_pd(a,b); } - -template<> EIGEN_STRONG_INLINE Packet8f pnegate(const Packet8f& a) -{ - return _mm256_sub_ps(_mm256_set1_ps(0.0),a); -} -template<> EIGEN_STRONG_INLINE Packet4d pnegate(const Packet4d& a) -{ - return _mm256_sub_pd(_mm256_set1_pd(0.0),a); -} - -template<> EIGEN_STRONG_INLINE Packet8f pconj(const Packet8f& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet4d pconj(const Packet4d& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet8i pconj(const Packet8i& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet8f pmul<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_mul_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4d pmul<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_mul_pd(a,b); } - - -template<> EIGEN_STRONG_INLINE Packet8f pdiv<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_div_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4d pdiv<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_div_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet8i pdiv<Packet8i>(const Packet8i& /*a*/, const Packet8i& /*b*/) -{ eigen_assert(false && "packet integer division are not supported by AVX"); - return pset1<Packet8i>(0); -} - -#ifdef EIGEN_VECTORIZE_FMA -template<> EIGEN_STRONG_INLINE Packet8f pmadd(const Packet8f& a, const Packet8f& b, const Packet8f& c) { -#if ( (EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<80) || (EIGEN_COMP_CLANG) ) - // Clang stupidly generates a vfmadd213ps instruction plus some vmovaps on registers, - // and even register spilling with clang>=6.0 (bug 1637). - // Gcc stupidly generates a vfmadd132ps instruction. - // So let's enforce it to generate a vfmadd231ps instruction since the most common use - // case is to accumulate the result of the product. - Packet8f res = c; - __asm__("vfmadd231ps %[a], %[b], %[c]" : [c] "+x" (res) : [a] "x" (a), [b] "x" (b)); - return res; -#else - return _mm256_fmadd_ps(a,b,c); -#endif -} -template<> EIGEN_STRONG_INLINE Packet4d pmadd(const Packet4d& a, const Packet4d& b, const Packet4d& c) { -#if ( (EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<80) || (EIGEN_COMP_CLANG) ) - // see above - Packet4d res = c; - __asm__("vfmadd231pd %[a], %[b], %[c]" : [c] "+x" (res) : [a] "x" (a), [b] "x" (b)); - return res; -#else - return _mm256_fmadd_pd(a,b,c); -#endif -} -#endif - -template<> EIGEN_STRONG_INLINE Packet8f pmin<Packet8f>(const Packet8f& a, const Packet8f& b) { -#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63 - // There appears to be a bug in GCC, by which the optimizer may flip - // the argument order in calls to _mm_min_ps/_mm_max_ps, so we have to - // resort to inline ASM here. This is supposed to be fixed in gcc6.3, - // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867 - Packet8f res; - asm("vminps %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b)); - return res; -#else - // Arguments are swapped to match NaN propagation behavior of std::min. - return _mm256_min_ps(b,a); -#endif -} -template<> EIGEN_STRONG_INLINE Packet4d pmin<Packet4d>(const Packet4d& a, const Packet4d& b) { -#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63 - // See pmin above - Packet4d res; - asm("vminpd %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b)); - return res; -#else - // Arguments are swapped to match NaN propagation behavior of std::min. - return _mm256_min_pd(b,a); -#endif -} -template<> EIGEN_STRONG_INLINE Packet8f pmax<Packet8f>(const Packet8f& a, const Packet8f& b) { -#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63 - // See pmin above - Packet8f res; - asm("vmaxps %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b)); - return res; -#else - // Arguments are swapped to match NaN propagation behavior of std::max. - return _mm256_max_ps(b,a); -#endif -} -template<> EIGEN_STRONG_INLINE Packet4d pmax<Packet4d>(const Packet4d& a, const Packet4d& b) { -#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63 - // See pmin above - Packet4d res; - asm("vmaxpd %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b)); - return res; -#else - // Arguments are swapped to match NaN propagation behavior of std::max. - return _mm256_max_pd(b,a); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f pcmp_le(const Packet8f& a, const Packet8f& b) { return _mm256_cmp_ps(a,b,_CMP_LE_OQ); } -template<> EIGEN_STRONG_INLINE Packet8f pcmp_lt(const Packet8f& a, const Packet8f& b) { return _mm256_cmp_ps(a,b,_CMP_LT_OQ); } -template<> EIGEN_STRONG_INLINE Packet8f pcmp_lt_or_nan(const Packet8f& a, const Packet8f& b) { return _mm256_cmp_ps(a, b, _CMP_NGE_UQ); } -template<> EIGEN_STRONG_INLINE Packet8f pcmp_eq(const Packet8f& a, const Packet8f& b) { return _mm256_cmp_ps(a,b,_CMP_EQ_OQ); } - -template<> EIGEN_STRONG_INLINE Packet4d pcmp_le(const Packet4d& a, const Packet4d& b) { return _mm256_cmp_pd(a,b,_CMP_LE_OQ); } -template<> EIGEN_STRONG_INLINE Packet4d pcmp_lt(const Packet4d& a, const Packet4d& b) { return _mm256_cmp_pd(a,b,_CMP_LT_OQ); } -template<> EIGEN_STRONG_INLINE Packet4d pcmp_lt_or_nan(const Packet4d& a, const Packet4d& b) { return _mm256_cmp_pd(a, b, _CMP_NGE_UQ); } -template<> EIGEN_STRONG_INLINE Packet4d pcmp_eq(const Packet4d& a, const Packet4d& b) { return _mm256_cmp_pd(a,b,_CMP_EQ_OQ); } - - -template<> EIGEN_STRONG_INLINE Packet8i pcmp_eq(const Packet8i& a, const Packet8i& b) { -#ifdef EIGEN_VECTORIZE_AVX2 - return _mm256_cmpeq_epi32(a,b); -#else - __m128i lo = _mm_cmpeq_epi32(_mm256_extractf128_si256(a, 0), _mm256_extractf128_si256(b, 0)); - __m128i hi = _mm_cmpeq_epi32(_mm256_extractf128_si256(a, 1), _mm256_extractf128_si256(b, 1)); - return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f print<Packet8f>(const Packet8f& a) { return _mm256_round_ps(a, _MM_FROUND_CUR_DIRECTION); } -template<> EIGEN_STRONG_INLINE Packet4d print<Packet4d>(const Packet4d& a) { return _mm256_round_pd(a, _MM_FROUND_CUR_DIRECTION); } - -template<> EIGEN_STRONG_INLINE Packet8f pceil<Packet8f>(const Packet8f& a) { return _mm256_ceil_ps(a); } -template<> EIGEN_STRONG_INLINE Packet4d pceil<Packet4d>(const Packet4d& a) { return _mm256_ceil_pd(a); } - -template<> EIGEN_STRONG_INLINE Packet8f pfloor<Packet8f>(const Packet8f& a) { return _mm256_floor_ps(a); } -template<> EIGEN_STRONG_INLINE Packet4d pfloor<Packet4d>(const Packet4d& a) { return _mm256_floor_pd(a); } - - -template<> EIGEN_STRONG_INLINE Packet8i ptrue<Packet8i>(const Packet8i& a) { -#ifdef EIGEN_VECTORIZE_AVX2 - // vpcmpeqd has lower latency than the more general vcmpps - return _mm256_cmpeq_epi32(a,a); -#else - const __m256 b = _mm256_castsi256_ps(a); - return _mm256_castps_si256(_mm256_cmp_ps(b,b,_CMP_TRUE_UQ)); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f ptrue<Packet8f>(const Packet8f& a) { -#ifdef EIGEN_VECTORIZE_AVX2 - // vpcmpeqd has lower latency than the more general vcmpps - const __m256i b = _mm256_castps_si256(a); - return _mm256_castsi256_ps(_mm256_cmpeq_epi32(b,b)); -#else - return _mm256_cmp_ps(a,a,_CMP_TRUE_UQ); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4d ptrue<Packet4d>(const Packet4d& a) { -#ifdef EIGEN_VECTORIZE_AVX2 - // vpcmpeqq has lower latency than the more general vcmppd - const __m256i b = _mm256_castpd_si256(a); - return _mm256_castsi256_pd(_mm256_cmpeq_epi64(b,b)); -#else - return _mm256_cmp_pd(a,a,_CMP_TRUE_UQ); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f pand<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_and_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4d pand<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_and_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet8i pand<Packet8i>(const Packet8i& a, const Packet8i& b) { -#ifdef EIGEN_VECTORIZE_AVX2 - return _mm256_and_si256(a,b); -#else - return _mm256_castps_si256(_mm256_and_ps(_mm256_castsi256_ps(a),_mm256_castsi256_ps(b))); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f por<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_or_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4d por<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_or_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet8i por<Packet8i>(const Packet8i& a, const Packet8i& b) { -#ifdef EIGEN_VECTORIZE_AVX2 - return _mm256_or_si256(a,b); -#else - return _mm256_castps_si256(_mm256_or_ps(_mm256_castsi256_ps(a),_mm256_castsi256_ps(b))); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f pxor<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_xor_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4d pxor<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_xor_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet8i pxor<Packet8i>(const Packet8i& a, const Packet8i& b) { -#ifdef EIGEN_VECTORIZE_AVX2 - return _mm256_xor_si256(a,b); -#else - return _mm256_castps_si256(_mm256_xor_ps(_mm256_castsi256_ps(a),_mm256_castsi256_ps(b))); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f pandnot<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_andnot_ps(b,a); } -template<> EIGEN_STRONG_INLINE Packet4d pandnot<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_andnot_pd(b,a); } -template<> EIGEN_STRONG_INLINE Packet8i pandnot<Packet8i>(const Packet8i& a, const Packet8i& b) { -#ifdef EIGEN_VECTORIZE_AVX2 - return _mm256_andnot_si256(b,a); -#else - return _mm256_castps_si256(_mm256_andnot_ps(_mm256_castsi256_ps(b),_mm256_castsi256_ps(a))); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f pround<Packet8f>(const Packet8f& a) -{ - const Packet8f mask = pset1frombits<Packet8f>(0x80000000u); - const Packet8f prev0dot5 = pset1frombits<Packet8f>(0x3EFFFFFFu); - return _mm256_round_ps(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO); -} -template<> EIGEN_STRONG_INLINE Packet4d pround<Packet4d>(const Packet4d& a) -{ - const Packet4d mask = _mm256_castsi256_pd(_mm256_set_epi64x(0x8000000000000000ull, 0x8000000000000000ull, 0x8000000000000000ull, 0x8000000000000000ull)); - const Packet4d prev0dot5 = _mm256_castsi256_pd(_mm256_set_epi64x(0x3FDFFFFFFFFFFFFFull, 0x3FDFFFFFFFFFFFFFull, 0x3FDFFFFFFFFFFFFFull, 0x3FDFFFFFFFFFFFFFull)); - return _mm256_round_pd(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO); -} - -template<> EIGEN_STRONG_INLINE Packet8f pselect<Packet8f>(const Packet8f& mask, const Packet8f& a, const Packet8f& b) -{ return _mm256_blendv_ps(b,a,mask); } -template<> EIGEN_STRONG_INLINE Packet4d pselect<Packet4d>(const Packet4d& mask, const Packet4d& a, const Packet4d& b) -{ return _mm256_blendv_pd(b,a,mask); } - -template<int N> EIGEN_STRONG_INLINE Packet8i pshiftright(Packet8i a) { -#ifdef EIGEN_VECTORIZE_AVX2 - return _mm256_srli_epi32(a, N); -#else - __m128i lo = _mm_srli_epi32(_mm256_extractf128_si256(a, 0), N); - __m128i hi = _mm_srli_epi32(_mm256_extractf128_si256(a, 1), N); - return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1); -#endif -} - -template<int N> EIGEN_STRONG_INLINE Packet8i pshiftleft(Packet8i a) { -#ifdef EIGEN_VECTORIZE_AVX2 - return _mm256_slli_epi32(a, N); -#else - __m128i lo = _mm_slli_epi32(_mm256_extractf128_si256(a, 0), N); - __m128i hi = _mm_slli_epi32(_mm256_extractf128_si256(a, 1), N); - return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8f pload<Packet8f>(const float* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm256_load_ps(from); } -template<> EIGEN_STRONG_INLINE Packet4d pload<Packet4d>(const double* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm256_load_pd(from); } -template<> EIGEN_STRONG_INLINE Packet8i pload<Packet8i>(const int* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm256_load_si256(reinterpret_cast<const __m256i*>(from)); } - -template<> EIGEN_STRONG_INLINE Packet8f ploadu<Packet8f>(const float* from) { EIGEN_DEBUG_UNALIGNED_LOAD return _mm256_loadu_ps(from); } -template<> EIGEN_STRONG_INLINE Packet4d ploadu<Packet4d>(const double* from) { EIGEN_DEBUG_UNALIGNED_LOAD return _mm256_loadu_pd(from); } -template<> EIGEN_STRONG_INLINE Packet8i ploadu<Packet8i>(const int* from) { EIGEN_DEBUG_UNALIGNED_LOAD return _mm256_loadu_si256(reinterpret_cast<const __m256i*>(from)); } - -template<> EIGEN_STRONG_INLINE Packet8f ploadu<Packet8f>(const float* from, uint8_t umask) { - Packet8i mask = _mm256_set1_epi8(static_cast<char>(umask)); - const Packet8i bit_mask = _mm256_set_epi32(0xffffff7f, 0xffffffbf, 0xffffffdf, 0xffffffef, 0xfffffff7, 0xfffffffb, 0xfffffffd, 0xfffffffe); - mask = por<Packet8i>(mask, bit_mask); - mask = pcmp_eq<Packet8i>(mask, _mm256_set1_epi32(0xffffffff)); - EIGEN_DEBUG_UNALIGNED_LOAD return _mm256_maskload_ps(from, mask); -} - -// Loads 4 floats from memory a returns the packet {a0, a0 a1, a1, a2, a2, a3, a3} -template<> EIGEN_STRONG_INLINE Packet8f ploaddup<Packet8f>(const float* from) -{ - // TODO try to find a way to avoid the need of a temporary register -// Packet8f tmp = _mm256_castps128_ps256(_mm_loadu_ps(from)); -// tmp = _mm256_insertf128_ps(tmp, _mm_movehl_ps(_mm256_castps256_ps128(tmp),_mm256_castps256_ps128(tmp)), 1); -// return _mm256_unpacklo_ps(tmp,tmp); - - // _mm256_insertf128_ps is very slow on Haswell, thus: - Packet8f tmp = _mm256_broadcast_ps((const __m128*)(const void*)from); - // mimic an "inplace" permutation of the lower 128bits using a blend - tmp = _mm256_blend_ps(tmp,_mm256_castps128_ps256(_mm_permute_ps( _mm256_castps256_ps128(tmp), _MM_SHUFFLE(1,0,1,0))), 15); - // then we can perform a consistent permutation on the global register to get everything in shape: - return _mm256_permute_ps(tmp, _MM_SHUFFLE(3,3,2,2)); -} -// Loads 2 doubles from memory a returns the packet {a0, a0 a1, a1} -template<> EIGEN_STRONG_INLINE Packet4d ploaddup<Packet4d>(const double* from) -{ - Packet4d tmp = _mm256_broadcast_pd((const __m128d*)(const void*)from); - return _mm256_permute_pd(tmp, 3<<2); -} - -// Loads 2 floats from memory a returns the packet {a0, a0 a0, a0, a1, a1, a1, a1} -template<> EIGEN_STRONG_INLINE Packet8f ploadquad<Packet8f>(const float* from) -{ - Packet8f tmp = _mm256_castps128_ps256(_mm_broadcast_ss(from)); - return _mm256_insertf128_ps(tmp, _mm_broadcast_ss(from+1), 1); -} - -template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet8f& from) { EIGEN_DEBUG_ALIGNED_STORE _mm256_store_ps(to, from); } -template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet4d& from) { EIGEN_DEBUG_ALIGNED_STORE _mm256_store_pd(to, from); } -template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet8i& from) { EIGEN_DEBUG_ALIGNED_STORE _mm256_storeu_si256(reinterpret_cast<__m256i*>(to), from); } - -template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet8f& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm256_storeu_ps(to, from); } -template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet4d& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm256_storeu_pd(to, from); } -template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet8i& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm256_storeu_si256(reinterpret_cast<__m256i*>(to), from); } - -template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet8f& from, uint8_t umask) { - Packet8i mask = _mm256_set1_epi8(static_cast<char>(umask)); - const Packet8i bit_mask = _mm256_set_epi32(0xffffff7f, 0xffffffbf, 0xffffffdf, 0xffffffef, 0xfffffff7, 0xfffffffb, 0xfffffffd, 0xfffffffe); - mask = por<Packet8i>(mask, bit_mask); - mask = pcmp_eq<Packet8i>(mask, _mm256_set1_epi32(0xffffffff)); - EIGEN_DEBUG_UNALIGNED_STORE return _mm256_maskstore_ps(to, mask, from); -} - -// NOTE: leverage _mm256_i32gather_ps and _mm256_i32gather_pd if AVX2 instructions are available -// NOTE: for the record the following seems to be slower: return _mm256_i32gather_ps(from, _mm256_set1_epi32(stride), 4); -template<> EIGEN_DEVICE_FUNC inline Packet8f pgather<float, Packet8f>(const float* from, Index stride) -{ - return _mm256_set_ps(from[7*stride], from[6*stride], from[5*stride], from[4*stride], - from[3*stride], from[2*stride], from[1*stride], from[0*stride]); -} -template<> EIGEN_DEVICE_FUNC inline Packet4d pgather<double, Packet4d>(const double* from, Index stride) -{ - return _mm256_set_pd(from[3*stride], from[2*stride], from[1*stride], from[0*stride]); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet8f>(float* to, const Packet8f& from, Index stride) -{ - __m128 low = _mm256_extractf128_ps(from, 0); - to[stride*0] = _mm_cvtss_f32(low); - to[stride*1] = _mm_cvtss_f32(_mm_shuffle_ps(low, low, 1)); - to[stride*2] = _mm_cvtss_f32(_mm_shuffle_ps(low, low, 2)); - to[stride*3] = _mm_cvtss_f32(_mm_shuffle_ps(low, low, 3)); - - __m128 high = _mm256_extractf128_ps(from, 1); - to[stride*4] = _mm_cvtss_f32(high); - to[stride*5] = _mm_cvtss_f32(_mm_shuffle_ps(high, high, 1)); - to[stride*6] = _mm_cvtss_f32(_mm_shuffle_ps(high, high, 2)); - to[stride*7] = _mm_cvtss_f32(_mm_shuffle_ps(high, high, 3)); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet4d>(double* to, const Packet4d& from, Index stride) -{ - __m128d low = _mm256_extractf128_pd(from, 0); - to[stride*0] = _mm_cvtsd_f64(low); - to[stride*1] = _mm_cvtsd_f64(_mm_shuffle_pd(low, low, 1)); - __m128d high = _mm256_extractf128_pd(from, 1); - to[stride*2] = _mm_cvtsd_f64(high); - to[stride*3] = _mm_cvtsd_f64(_mm_shuffle_pd(high, high, 1)); -} - -template<> EIGEN_STRONG_INLINE void pstore1<Packet8f>(float* to, const float& a) -{ - Packet8f pa = pset1<Packet8f>(a); - pstore(to, pa); -} -template<> EIGEN_STRONG_INLINE void pstore1<Packet4d>(double* to, const double& a) -{ - Packet4d pa = pset1<Packet4d>(a); - pstore(to, pa); -} -template<> EIGEN_STRONG_INLINE void pstore1<Packet8i>(int* to, const int& a) -{ - Packet8i pa = pset1<Packet8i>(a); - pstore(to, pa); -} - -#ifndef EIGEN_VECTORIZE_AVX512 -template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } -template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } -template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } -#endif - -template<> EIGEN_STRONG_INLINE float pfirst<Packet8f>(const Packet8f& a) { - return _mm_cvtss_f32(_mm256_castps256_ps128(a)); -} -template<> EIGEN_STRONG_INLINE double pfirst<Packet4d>(const Packet4d& a) { - return _mm_cvtsd_f64(_mm256_castpd256_pd128(a)); -} -template<> EIGEN_STRONG_INLINE int pfirst<Packet8i>(const Packet8i& a) { - return _mm_cvtsi128_si32(_mm256_castsi256_si128(a)); -} - - -template<> EIGEN_STRONG_INLINE Packet8f preverse(const Packet8f& a) -{ - __m256 tmp = _mm256_shuffle_ps(a,a,0x1b); - return _mm256_permute2f128_ps(tmp, tmp, 1); -} -template<> EIGEN_STRONG_INLINE Packet4d preverse(const Packet4d& a) -{ - __m256d tmp = _mm256_shuffle_pd(a,a,5); - return _mm256_permute2f128_pd(tmp, tmp, 1); - #if 0 - // This version is unlikely to be faster as _mm256_shuffle_ps and _mm256_permute_pd - // exhibit the same latency/throughput, but it is here for future reference/benchmarking... - __m256d swap_halves = _mm256_permute2f128_pd(a,a,1); - return _mm256_permute_pd(swap_halves,5); - #endif -} - -// pabs should be ok -template<> EIGEN_STRONG_INLINE Packet8f pabs(const Packet8f& a) -{ - const Packet8f mask = _mm256_castsi256_ps(_mm256_setr_epi32(0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF)); - return _mm256_and_ps(a,mask); -} -template<> EIGEN_STRONG_INLINE Packet4d pabs(const Packet4d& a) -{ - const Packet4d mask = _mm256_castsi256_pd(_mm256_setr_epi32(0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF)); - return _mm256_and_pd(a,mask); -} - -template<> EIGEN_STRONG_INLINE Packet8f pfrexp<Packet8f>(const Packet8f& a, Packet8f& exponent) { - return pfrexp_float(a,exponent); -} - -template<> EIGEN_STRONG_INLINE Packet8f pldexp<Packet8f>(const Packet8f& a, const Packet8f& exponent) { - return pldexp_float(a,exponent); -} - -template<> EIGEN_STRONG_INLINE Packet4d pldexp<Packet4d>(const Packet4d& a, const Packet4d& exponent) { - // Build e=2^n by constructing the exponents in a 128-bit vector and - // shifting them to where they belong in double-precision values. - Packet4i cst_1023 = pset1<Packet4i>(1023); - __m128i emm0 = _mm256_cvtpd_epi32(exponent); - emm0 = _mm_add_epi32(emm0, cst_1023); - emm0 = _mm_shuffle_epi32(emm0, _MM_SHUFFLE(3, 1, 2, 0)); - __m128i lo = _mm_slli_epi64(emm0, 52); - __m128i hi = _mm_slli_epi64(_mm_srli_epi64(emm0, 32), 52); - __m256i e = _mm256_insertf128_si256(_mm256_setzero_si256(), lo, 0); - e = _mm256_insertf128_si256(e, hi, 1); - return pmul(a,_mm256_castsi256_pd(e)); -} - -// preduxp should be ok -// FIXME: why is this ok? why isn't the simply implementation working as expected? -template<> EIGEN_STRONG_INLINE Packet8f preduxp<Packet8f>(const Packet8f* vecs) -{ - __m256 hsum1 = _mm256_hadd_ps(vecs[0], vecs[1]); - __m256 hsum2 = _mm256_hadd_ps(vecs[2], vecs[3]); - __m256 hsum3 = _mm256_hadd_ps(vecs[4], vecs[5]); - __m256 hsum4 = _mm256_hadd_ps(vecs[6], vecs[7]); - - __m256 hsum5 = _mm256_hadd_ps(hsum1, hsum1); - __m256 hsum6 = _mm256_hadd_ps(hsum2, hsum2); - __m256 hsum7 = _mm256_hadd_ps(hsum3, hsum3); - __m256 hsum8 = _mm256_hadd_ps(hsum4, hsum4); - - __m256 perm1 = _mm256_permute2f128_ps(hsum5, hsum5, 0x23); - __m256 perm2 = _mm256_permute2f128_ps(hsum6, hsum6, 0x23); - __m256 perm3 = _mm256_permute2f128_ps(hsum7, hsum7, 0x23); - __m256 perm4 = _mm256_permute2f128_ps(hsum8, hsum8, 0x23); - - __m256 sum1 = _mm256_add_ps(perm1, hsum5); - __m256 sum2 = _mm256_add_ps(perm2, hsum6); - __m256 sum3 = _mm256_add_ps(perm3, hsum7); - __m256 sum4 = _mm256_add_ps(perm4, hsum8); - - __m256 blend1 = _mm256_blend_ps(sum1, sum2, 0xcc); - __m256 blend2 = _mm256_blend_ps(sum3, sum4, 0xcc); - - __m256 final = _mm256_blend_ps(blend1, blend2, 0xf0); - return final; -} -template<> EIGEN_STRONG_INLINE Packet4d preduxp<Packet4d>(const Packet4d* vecs) -{ - Packet4d tmp0, tmp1; - - tmp0 = _mm256_hadd_pd(vecs[0], vecs[1]); - tmp0 = _mm256_add_pd(tmp0, _mm256_permute2f128_pd(tmp0, tmp0, 1)); - - tmp1 = _mm256_hadd_pd(vecs[2], vecs[3]); - tmp1 = _mm256_add_pd(tmp1, _mm256_permute2f128_pd(tmp1, tmp1, 1)); - - return _mm256_blend_pd(tmp0, tmp1, 0xC); -} - -template<> EIGEN_STRONG_INLINE float predux<Packet8f>(const Packet8f& a) -{ - return predux(Packet4f(_mm_add_ps(_mm256_castps256_ps128(a),_mm256_extractf128_ps(a,1)))); -} -template<> EIGEN_STRONG_INLINE double predux<Packet4d>(const Packet4d& a) -{ - return predux(Packet2d(_mm_add_pd(_mm256_castpd256_pd128(a),_mm256_extractf128_pd(a,1)))); -} - -template<> EIGEN_STRONG_INLINE Packet4f predux_half_dowto4<Packet8f>(const Packet8f& a) -{ - return _mm_add_ps(_mm256_castps256_ps128(a),_mm256_extractf128_ps(a,1)); -} - -template<> EIGEN_STRONG_INLINE float predux_mul<Packet8f>(const Packet8f& a) -{ - Packet8f tmp; - tmp = _mm256_mul_ps(a, _mm256_permute2f128_ps(a,a,1)); - tmp = _mm256_mul_ps(tmp, _mm256_shuffle_ps(tmp,tmp,_MM_SHUFFLE(1,0,3,2))); - return pfirst(_mm256_mul_ps(tmp, _mm256_shuffle_ps(tmp,tmp,1))); -} -template<> EIGEN_STRONG_INLINE double predux_mul<Packet4d>(const Packet4d& a) -{ - Packet4d tmp; - tmp = _mm256_mul_pd(a, _mm256_permute2f128_pd(a,a,1)); - return pfirst(_mm256_mul_pd(tmp, _mm256_shuffle_pd(tmp,tmp,1))); -} - -template<> EIGEN_STRONG_INLINE float predux_min<Packet8f>(const Packet8f& a) -{ - Packet8f tmp = _mm256_min_ps(a, _mm256_permute2f128_ps(a,a,1)); - tmp = _mm256_min_ps(tmp, _mm256_shuffle_ps(tmp,tmp,_MM_SHUFFLE(1,0,3,2))); - return pfirst(_mm256_min_ps(tmp, _mm256_shuffle_ps(tmp,tmp,1))); -} -template<> EIGEN_STRONG_INLINE double predux_min<Packet4d>(const Packet4d& a) -{ - Packet4d tmp = _mm256_min_pd(a, _mm256_permute2f128_pd(a,a,1)); - return pfirst(_mm256_min_pd(tmp, _mm256_shuffle_pd(tmp, tmp, 1))); -} - -template<> EIGEN_STRONG_INLINE float predux_max<Packet8f>(const Packet8f& a) -{ - Packet8f tmp = _mm256_max_ps(a, _mm256_permute2f128_ps(a,a,1)); - tmp = _mm256_max_ps(tmp, _mm256_shuffle_ps(tmp,tmp,_MM_SHUFFLE(1,0,3,2))); - return pfirst(_mm256_max_ps(tmp, _mm256_shuffle_ps(tmp,tmp,1))); -} - -template<> EIGEN_STRONG_INLINE double predux_max<Packet4d>(const Packet4d& a) -{ - Packet4d tmp = _mm256_max_pd(a, _mm256_permute2f128_pd(a,a,1)); - return pfirst(_mm256_max_pd(tmp, _mm256_shuffle_pd(tmp, tmp, 1))); -} - -// not needed yet -// template<> EIGEN_STRONG_INLINE bool predux_all(const Packet8f& x) -// { -// return _mm256_movemask_ps(x)==0xFF; -// } - -template<> EIGEN_STRONG_INLINE bool predux_any(const Packet8f& x) -{ - return _mm256_movemask_ps(x)!=0; -} - -template<int Offset> -struct palign_impl<Offset,Packet8f> -{ - static EIGEN_STRONG_INLINE void run(Packet8f& first, const Packet8f& second) - { - if (Offset==1) - { - first = _mm256_blend_ps(first, second, 1); - Packet8f tmp1 = _mm256_permute_ps (first, _MM_SHUFFLE(0,3,2,1)); - Packet8f tmp2 = _mm256_permute2f128_ps (tmp1, tmp1, 1); - first = _mm256_blend_ps(tmp1, tmp2, 0x88); - } - else if (Offset==2) - { - first = _mm256_blend_ps(first, second, 3); - Packet8f tmp1 = _mm256_permute_ps (first, _MM_SHUFFLE(1,0,3,2)); - Packet8f tmp2 = _mm256_permute2f128_ps (tmp1, tmp1, 1); - first = _mm256_blend_ps(tmp1, tmp2, 0xcc); - } - else if (Offset==3) - { - first = _mm256_blend_ps(first, second, 7); - Packet8f tmp1 = _mm256_permute_ps (first, _MM_SHUFFLE(2,1,0,3)); - Packet8f tmp2 = _mm256_permute2f128_ps (tmp1, tmp1, 1); - first = _mm256_blend_ps(tmp1, tmp2, 0xee); - } - else if (Offset==4) - { - first = _mm256_blend_ps(first, second, 15); - Packet8f tmp1 = _mm256_permute_ps (first, _MM_SHUFFLE(3,2,1,0)); - Packet8f tmp2 = _mm256_permute2f128_ps (tmp1, tmp1, 1); - first = _mm256_permute_ps(tmp2, _MM_SHUFFLE(3,2,1,0)); - } - else if (Offset==5) - { - first = _mm256_blend_ps(first, second, 31); - first = _mm256_permute2f128_ps(first, first, 1); - Packet8f tmp = _mm256_permute_ps (first, _MM_SHUFFLE(0,3,2,1)); - first = _mm256_permute2f128_ps(tmp, tmp, 1); - first = _mm256_blend_ps(tmp, first, 0x88); - } - else if (Offset==6) - { - first = _mm256_blend_ps(first, second, 63); - first = _mm256_permute2f128_ps(first, first, 1); - Packet8f tmp = _mm256_permute_ps (first, _MM_SHUFFLE(1,0,3,2)); - first = _mm256_permute2f128_ps(tmp, tmp, 1); - first = _mm256_blend_ps(tmp, first, 0xcc); - } - else if (Offset==7) - { - first = _mm256_blend_ps(first, second, 127); - first = _mm256_permute2f128_ps(first, first, 1); - Packet8f tmp = _mm256_permute_ps (first, _MM_SHUFFLE(2,1,0,3)); - first = _mm256_permute2f128_ps(tmp, tmp, 1); - first = _mm256_blend_ps(tmp, first, 0xee); - } - } -}; - -template<int Offset> -struct palign_impl<Offset,Packet4d> -{ - static EIGEN_STRONG_INLINE void run(Packet4d& first, const Packet4d& second) - { - if (Offset==1) - { - first = _mm256_blend_pd(first, second, 1); - __m256d tmp = _mm256_permute_pd(first, 5); - first = _mm256_permute2f128_pd(tmp, tmp, 1); - first = _mm256_blend_pd(tmp, first, 0xA); - } - else if (Offset==2) - { - first = _mm256_blend_pd(first, second, 3); - first = _mm256_permute2f128_pd(first, first, 1); - } - else if (Offset==3) - { - first = _mm256_blend_pd(first, second, 7); - __m256d tmp = _mm256_permute_pd(first, 5); - first = _mm256_permute2f128_pd(tmp, tmp, 1); - first = _mm256_blend_pd(tmp, first, 5); - } - } -}; - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet8f,8>& kernel) { - __m256 T0 = _mm256_unpacklo_ps(kernel.packet[0], kernel.packet[1]); - __m256 T1 = _mm256_unpackhi_ps(kernel.packet[0], kernel.packet[1]); - __m256 T2 = _mm256_unpacklo_ps(kernel.packet[2], kernel.packet[3]); - __m256 T3 = _mm256_unpackhi_ps(kernel.packet[2], kernel.packet[3]); - __m256 T4 = _mm256_unpacklo_ps(kernel.packet[4], kernel.packet[5]); - __m256 T5 = _mm256_unpackhi_ps(kernel.packet[4], kernel.packet[5]); - __m256 T6 = _mm256_unpacklo_ps(kernel.packet[6], kernel.packet[7]); - __m256 T7 = _mm256_unpackhi_ps(kernel.packet[6], kernel.packet[7]); - __m256 S0 = _mm256_shuffle_ps(T0,T2,_MM_SHUFFLE(1,0,1,0)); - __m256 S1 = _mm256_shuffle_ps(T0,T2,_MM_SHUFFLE(3,2,3,2)); - __m256 S2 = _mm256_shuffle_ps(T1,T3,_MM_SHUFFLE(1,0,1,0)); - __m256 S3 = _mm256_shuffle_ps(T1,T3,_MM_SHUFFLE(3,2,3,2)); - __m256 S4 = _mm256_shuffle_ps(T4,T6,_MM_SHUFFLE(1,0,1,0)); - __m256 S5 = _mm256_shuffle_ps(T4,T6,_MM_SHUFFLE(3,2,3,2)); - __m256 S6 = _mm256_shuffle_ps(T5,T7,_MM_SHUFFLE(1,0,1,0)); - __m256 S7 = _mm256_shuffle_ps(T5,T7,_MM_SHUFFLE(3,2,3,2)); - kernel.packet[0] = _mm256_permute2f128_ps(S0, S4, 0x20); - kernel.packet[1] = _mm256_permute2f128_ps(S1, S5, 0x20); - kernel.packet[2] = _mm256_permute2f128_ps(S2, S6, 0x20); - kernel.packet[3] = _mm256_permute2f128_ps(S3, S7, 0x20); - kernel.packet[4] = _mm256_permute2f128_ps(S0, S4, 0x31); - kernel.packet[5] = _mm256_permute2f128_ps(S1, S5, 0x31); - kernel.packet[6] = _mm256_permute2f128_ps(S2, S6, 0x31); - kernel.packet[7] = _mm256_permute2f128_ps(S3, S7, 0x31); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet8f,4>& kernel) { - __m256 T0 = _mm256_unpacklo_ps(kernel.packet[0], kernel.packet[1]); - __m256 T1 = _mm256_unpackhi_ps(kernel.packet[0], kernel.packet[1]); - __m256 T2 = _mm256_unpacklo_ps(kernel.packet[2], kernel.packet[3]); - __m256 T3 = _mm256_unpackhi_ps(kernel.packet[2], kernel.packet[3]); - - __m256 S0 = _mm256_shuffle_ps(T0,T2,_MM_SHUFFLE(1,0,1,0)); - __m256 S1 = _mm256_shuffle_ps(T0,T2,_MM_SHUFFLE(3,2,3,2)); - __m256 S2 = _mm256_shuffle_ps(T1,T3,_MM_SHUFFLE(1,0,1,0)); - __m256 S3 = _mm256_shuffle_ps(T1,T3,_MM_SHUFFLE(3,2,3,2)); - - kernel.packet[0] = _mm256_permute2f128_ps(S0, S1, 0x20); - kernel.packet[1] = _mm256_permute2f128_ps(S2, S3, 0x20); - kernel.packet[2] = _mm256_permute2f128_ps(S0, S1, 0x31); - kernel.packet[3] = _mm256_permute2f128_ps(S2, S3, 0x31); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4d,4>& kernel) { - __m256d T0 = _mm256_shuffle_pd(kernel.packet[0], kernel.packet[1], 15); - __m256d T1 = _mm256_shuffle_pd(kernel.packet[0], kernel.packet[1], 0); - __m256d T2 = _mm256_shuffle_pd(kernel.packet[2], kernel.packet[3], 15); - __m256d T3 = _mm256_shuffle_pd(kernel.packet[2], kernel.packet[3], 0); - - kernel.packet[1] = _mm256_permute2f128_pd(T0, T2, 32); - kernel.packet[3] = _mm256_permute2f128_pd(T0, T2, 49); - kernel.packet[0] = _mm256_permute2f128_pd(T1, T3, 32); - kernel.packet[2] = _mm256_permute2f128_pd(T1, T3, 49); -} - -template<> EIGEN_STRONG_INLINE Packet8f pblend(const Selector<8>& ifPacket, const Packet8f& thenPacket, const Packet8f& elsePacket) { - const __m256 zero = _mm256_setzero_ps(); - const __m256 select = _mm256_set_ps(ifPacket.select[7], ifPacket.select[6], ifPacket.select[5], ifPacket.select[4], ifPacket.select[3], ifPacket.select[2], ifPacket.select[1], ifPacket.select[0]); - __m256 false_mask = _mm256_cmp_ps(select, zero, _CMP_EQ_UQ); - return _mm256_blendv_ps(thenPacket, elsePacket, false_mask); -} -template<> EIGEN_STRONG_INLINE Packet4d pblend(const Selector<4>& ifPacket, const Packet4d& thenPacket, const Packet4d& elsePacket) { - const __m256d zero = _mm256_setzero_pd(); - const __m256d select = _mm256_set_pd(ifPacket.select[3], ifPacket.select[2], ifPacket.select[1], ifPacket.select[0]); - __m256d false_mask = _mm256_cmp_pd(select, zero, _CMP_EQ_UQ); - return _mm256_blendv_pd(thenPacket, elsePacket, false_mask); -} - -template<> EIGEN_STRONG_INLINE Packet8f pinsertfirst(const Packet8f& a, float b) -{ - return _mm256_blend_ps(a,pset1<Packet8f>(b),1); -} - -template<> EIGEN_STRONG_INLINE Packet4d pinsertfirst(const Packet4d& a, double b) -{ - return _mm256_blend_pd(a,pset1<Packet4d>(b),1); -} - -template<> EIGEN_STRONG_INLINE Packet8f pinsertlast(const Packet8f& a, float b) -{ - return _mm256_blend_ps(a,pset1<Packet8f>(b),(1<<7)); -} - -template<> EIGEN_STRONG_INLINE Packet4d pinsertlast(const Packet4d& a, double b) -{ - return _mm256_blend_pd(a,pset1<Packet4d>(b),(1<<3)); -} - - -// Packet math for Eigen::half -template<> struct unpacket_traits<Packet8h> { typedef Eigen::half type; enum {size=8, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet8h half; }; - -template<> EIGEN_STRONG_INLINE Packet8h pset1<Packet8h>(const Eigen::half& from) { - Packet8h result; - result.x = _mm_set1_epi16(from.x); - return result; -} - -template<> EIGEN_STRONG_INLINE Eigen::half pfirst<Packet8h>(const Packet8h& from) { - return half_impl::raw_uint16_to_half(static_cast<unsigned short>(_mm_extract_epi16(from.x, 0))); -} - -template<> EIGEN_STRONG_INLINE Packet8h pload<Packet8h>(const Eigen::half* from) { - Packet8h result; - result.x = _mm_load_si128(reinterpret_cast<const __m128i*>(from)); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet8h ploadu<Packet8h>(const Eigen::half* from) { - Packet8h result; - result.x = _mm_loadu_si128(reinterpret_cast<const __m128i*>(from)); - return result; -} - -template<> EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const Packet8h& from) { - _mm_store_si128(reinterpret_cast<__m128i*>(to), from.x); -} - -template<> EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const Packet8h& from) { - _mm_storeu_si128(reinterpret_cast<__m128i*>(to), from.x); -} - -template<> EIGEN_STRONG_INLINE Packet8h -ploaddup<Packet8h>(const Eigen::half* from) { - Packet8h result; - unsigned short a = from[0].x; - unsigned short b = from[1].x; - unsigned short c = from[2].x; - unsigned short d = from[3].x; - result.x = _mm_set_epi16(d, d, c, c, b, b, a, a); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet8h -ploadquad<Packet8h>(const Eigen::half* from) { - Packet8h result; - unsigned short a = from[0].x; - unsigned short b = from[1].x; - result.x = _mm_set_epi16(b, b, b, b, a, a, a, a); - return result; -} - -EIGEN_STRONG_INLINE Packet8f half2float(const Packet8h& a) { -#ifdef EIGEN_HAS_FP16_C - return _mm256_cvtph_ps(a.x); -#else - EIGEN_ALIGN32 Eigen::half aux[8]; - pstore(aux, a); - float f0(aux[0]); - float f1(aux[1]); - float f2(aux[2]); - float f3(aux[3]); - float f4(aux[4]); - float f5(aux[5]); - float f6(aux[6]); - float f7(aux[7]); - - return _mm256_set_ps(f7, f6, f5, f4, f3, f2, f1, f0); -#endif -} - -EIGEN_STRONG_INLINE Packet8h float2half(const Packet8f& a) { -#ifdef EIGEN_HAS_FP16_C - Packet8h result; - result.x = _mm256_cvtps_ph(a, _MM_FROUND_TO_NEAREST_INT|_MM_FROUND_NO_EXC); - return result; -#else - EIGEN_ALIGN32 float aux[8]; - pstore(aux, a); - Eigen::half h0(aux[0]); - Eigen::half h1(aux[1]); - Eigen::half h2(aux[2]); - Eigen::half h3(aux[3]); - Eigen::half h4(aux[4]); - Eigen::half h5(aux[5]); - Eigen::half h6(aux[6]); - Eigen::half h7(aux[7]); - - Packet8h result; - result.x = _mm_set_epi16(h7.x, h6.x, h5.x, h4.x, h3.x, h2.x, h1.x, h0.x); - return result; -#endif -} - -template<> EIGEN_STRONG_INLINE Packet8h ptrue(const Packet8h& a) { - Packet8h r; r.x = _mm_cmpeq_epi32(a.x, a.x); return r; -} - -template<> EIGEN_STRONG_INLINE Packet8h por(const Packet8h& a,const Packet8h& b) { - // in some cases Packet4i is a wrapper around __m128i, so we either need to - // cast to Packet4i to directly call the intrinsics as below: - Packet8h r; r.x = _mm_or_si128(a.x,b.x); return r; -} -template<> EIGEN_STRONG_INLINE Packet8h pxor(const Packet8h& a,const Packet8h& b) { - Packet8h r; r.x = _mm_xor_si128(a.x,b.x); return r; -} -template<> EIGEN_STRONG_INLINE Packet8h pand(const Packet8h& a,const Packet8h& b) { - Packet8h r; r.x = _mm_and_si128(a.x,b.x); return r; -} -template<> EIGEN_STRONG_INLINE Packet8h pandnot(const Packet8h& a,const Packet8h& b) { - Packet8h r; r.x = _mm_andnot_si128(b.x,a.x); return r; -} - -template<> EIGEN_STRONG_INLINE Packet8h pselect(const Packet8h& mask, const Packet8h& a, const Packet8h& b) { - Packet8h r; r.x = _mm_blendv_epi8(b.x, a.x, mask.x); return r; -} - -template<> EIGEN_STRONG_INLINE Packet8h pcmp_eq(const Packet8h& a,const Packet8h& b) { - Packet8f af = half2float(a); - Packet8f bf = half2float(b); - Packet8f rf = pcmp_eq(af, bf); - // Pack the 32-bit flags into 16-bits flags. - Packet8h result; result.x = _mm_packs_epi32(_mm256_extractf128_si256(_mm256_castps_si256(rf), 0), - _mm256_extractf128_si256(_mm256_castps_si256(rf), 1)); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet8h pconj(const Packet8h& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet8h pnegate(const Packet8h& a) { - Packet8h sign_mask; sign_mask.x = _mm_set1_epi16(static_cast<unsigned short>(0x8000)); - Packet8h result; result.x = _mm_xor_si128(a.x, sign_mask.x); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet8h padd<Packet8h>(const Packet8h& a, const Packet8h& b) { - Packet8f af = half2float(a); - Packet8f bf = half2float(b); - Packet8f rf = padd(af, bf); - return float2half(rf); -} - -template<> EIGEN_STRONG_INLINE Packet8h psub<Packet8h>(const Packet8h& a, const Packet8h& b) { - Packet8f af = half2float(a); - Packet8f bf = half2float(b); - Packet8f rf = psub(af, bf); - return float2half(rf); -} - -template<> EIGEN_STRONG_INLINE Packet8h pmul<Packet8h>(const Packet8h& a, const Packet8h& b) { - Packet8f af = half2float(a); - Packet8f bf = half2float(b); - Packet8f rf = pmul(af, bf); - return float2half(rf); -} - -template<> EIGEN_STRONG_INLINE Packet8h pdiv<Packet8h>(const Packet8h& a, const Packet8h& b) { - Packet8f af = half2float(a); - Packet8f bf = half2float(b); - Packet8f rf = pdiv(af, bf); - return float2half(rf); -} - -template<> EIGEN_STRONG_INLINE Packet8h pgather<Eigen::half, Packet8h>(const Eigen::half* from, Index stride) -{ - Packet8h result; - result.x = _mm_set_epi16(from[7*stride].x, from[6*stride].x, from[5*stride].x, from[4*stride].x, from[3*stride].x, from[2*stride].x, from[1*stride].x, from[0*stride].x); - return result; -} - -template<> EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet8h>(Eigen::half* to, const Packet8h& from, Index stride) -{ - EIGEN_ALIGN32 Eigen::half aux[8]; - pstore(aux, from); - to[stride*0].x = aux[0].x; - to[stride*1].x = aux[1].x; - to[stride*2].x = aux[2].x; - to[stride*3].x = aux[3].x; - to[stride*4].x = aux[4].x; - to[stride*5].x = aux[5].x; - to[stride*6].x = aux[6].x; - to[stride*7].x = aux[7].x; -} - -template<> EIGEN_STRONG_INLINE Eigen::half predux<Packet8h>(const Packet8h& a) { - Packet8f af = half2float(a); - float reduced = predux<Packet8f>(af); - return Eigen::half(reduced); -} - -template<> EIGEN_STRONG_INLINE Eigen::half predux_max<Packet8h>(const Packet8h& a) { - Packet8f af = half2float(a); - float reduced = predux_max<Packet8f>(af); - return Eigen::half(reduced); -} - -template<> EIGEN_STRONG_INLINE Eigen::half predux_min<Packet8h>(const Packet8h& a) { - Packet8f af = half2float(a); - float reduced = predux_min<Packet8f>(af); - return Eigen::half(reduced); -} - -template<> EIGEN_STRONG_INLINE Eigen::half predux_mul<Packet8h>(const Packet8h& a) { - Packet8f af = half2float(a); - float reduced = predux_mul<Packet8f>(af); - return Eigen::half(reduced); -} - -template<> EIGEN_STRONG_INLINE Packet8h preduxp<Packet8h>(const Packet8h* p) { - Packet8f pf[8]; - pf[0] = half2float(p[0]); - pf[1] = half2float(p[1]); - pf[2] = half2float(p[2]); - pf[3] = half2float(p[3]); - pf[4] = half2float(p[4]); - pf[5] = half2float(p[5]); - pf[6] = half2float(p[6]); - pf[7] = half2float(p[7]); - Packet8f reduced = preduxp<Packet8f>(pf); - return float2half(reduced); -} - -template<> EIGEN_STRONG_INLINE Packet8h preverse(const Packet8h& a) -{ - __m128i m = _mm_setr_epi8(14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1); - Packet8h res; - res.x = _mm_shuffle_epi8(a.x,m); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet8h pinsertfirst(const Packet8h& a, Eigen::half b) -{ - Packet8h res; - res.x = _mm_insert_epi16(a.x,int(b.x),0); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet8h pinsertlast(const Packet8h& a, Eigen::half b) -{ - Packet8h res; - res.x = _mm_insert_epi16(a.x,int(b.x),7); - return res; -} - -template<int Offset> -struct palign_impl<Offset,Packet8h> -{ - static EIGEN_STRONG_INLINE void run(Packet8h& first, const Packet8h& second) - { - if (Offset!=0) - first.x = _mm_alignr_epi8(second.x,first.x, Offset*2); - } -}; - -EIGEN_STRONG_INLINE void -ptranspose(PacketBlock<Packet8h,8>& kernel) { - __m128i a = kernel.packet[0].x; - __m128i b = kernel.packet[1].x; - __m128i c = kernel.packet[2].x; - __m128i d = kernel.packet[3].x; - __m128i e = kernel.packet[4].x; - __m128i f = kernel.packet[5].x; - __m128i g = kernel.packet[6].x; - __m128i h = kernel.packet[7].x; - - __m128i a03b03 = _mm_unpacklo_epi16(a, b); - __m128i c03d03 = _mm_unpacklo_epi16(c, d); - __m128i e03f03 = _mm_unpacklo_epi16(e, f); - __m128i g03h03 = _mm_unpacklo_epi16(g, h); - __m128i a47b47 = _mm_unpackhi_epi16(a, b); - __m128i c47d47 = _mm_unpackhi_epi16(c, d); - __m128i e47f47 = _mm_unpackhi_epi16(e, f); - __m128i g47h47 = _mm_unpackhi_epi16(g, h); - - __m128i a01b01c01d01 = _mm_unpacklo_epi32(a03b03, c03d03); - __m128i a23b23c23d23 = _mm_unpackhi_epi32(a03b03, c03d03); - __m128i e01f01g01h01 = _mm_unpacklo_epi32(e03f03, g03h03); - __m128i e23f23g23h23 = _mm_unpackhi_epi32(e03f03, g03h03); - __m128i a45b45c45d45 = _mm_unpacklo_epi32(a47b47, c47d47); - __m128i a67b67c67d67 = _mm_unpackhi_epi32(a47b47, c47d47); - __m128i e45f45g45h45 = _mm_unpacklo_epi32(e47f47, g47h47); - __m128i e67f67g67h67 = _mm_unpackhi_epi32(e47f47, g47h47); - - __m128i a0b0c0d0e0f0g0h0 = _mm_unpacklo_epi64(a01b01c01d01, e01f01g01h01); - __m128i a1b1c1d1e1f1g1h1 = _mm_unpackhi_epi64(a01b01c01d01, e01f01g01h01); - __m128i a2b2c2d2e2f2g2h2 = _mm_unpacklo_epi64(a23b23c23d23, e23f23g23h23); - __m128i a3b3c3d3e3f3g3h3 = _mm_unpackhi_epi64(a23b23c23d23, e23f23g23h23); - __m128i a4b4c4d4e4f4g4h4 = _mm_unpacklo_epi64(a45b45c45d45, e45f45g45h45); - __m128i a5b5c5d5e5f5g5h5 = _mm_unpackhi_epi64(a45b45c45d45, e45f45g45h45); - __m128i a6b6c6d6e6f6g6h6 = _mm_unpacklo_epi64(a67b67c67d67, e67f67g67h67); - __m128i a7b7c7d7e7f7g7h7 = _mm_unpackhi_epi64(a67b67c67d67, e67f67g67h67); - - kernel.packet[0].x = a0b0c0d0e0f0g0h0; - kernel.packet[1].x = a1b1c1d1e1f1g1h1; - kernel.packet[2].x = a2b2c2d2e2f2g2h2; - kernel.packet[3].x = a3b3c3d3e3f3g3h3; - kernel.packet[4].x = a4b4c4d4e4f4g4h4; - kernel.packet[5].x = a5b5c5d5e5f5g5h5; - kernel.packet[6].x = a6b6c6d6e6f6g6h6; - kernel.packet[7].x = a7b7c7d7e7f7g7h7; -} - -EIGEN_STRONG_INLINE void -ptranspose(PacketBlock<Packet8h,4>& kernel) { - EIGEN_ALIGN32 Eigen::half in[4][8]; - pstore<Eigen::half>(in[0], kernel.packet[0]); - pstore<Eigen::half>(in[1], kernel.packet[1]); - pstore<Eigen::half>(in[2], kernel.packet[2]); - pstore<Eigen::half>(in[3], kernel.packet[3]); - - EIGEN_ALIGN32 Eigen::half out[4][8]; - - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { - out[i][j] = in[j][2*i]; - } - for (int j = 0; j < 4; ++j) { - out[i][j+4] = in[j][2*i+1]; - } - } - - kernel.packet[0] = pload<Packet8h>(out[0]); - kernel.packet[1] = pload<Packet8h>(out[1]); - kernel.packet[2] = pload<Packet8h>(out[2]); - kernel.packet[3] = pload<Packet8h>(out[3]); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PACKET_MATH_AVX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/TypeCasting.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/TypeCasting.h deleted file mode 100644 index 18104358..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX/TypeCasting.h +++ /dev/null @@ -1,89 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TYPE_CASTING_AVX_H -#define EIGEN_TYPE_CASTING_AVX_H - -namespace Eigen { - -namespace internal { - -// For now we use SSE to handle integers, so we can't use AVX instructions to cast -// from int to float -template <> -struct type_casting_traits<float, int> { - enum { - VectorizedCast = 0, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template <> -struct type_casting_traits<int, float> { - enum { - VectorizedCast = 0, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - - - -template<> EIGEN_STRONG_INLINE Packet8i pcast<Packet8f, Packet8i>(const Packet8f& a) { - return _mm256_cvttps_epi32(a); -} - -template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8i, Packet8f>(const Packet8i& a) { - return _mm256_cvtepi32_ps(a); -} - -template<> EIGEN_STRONG_INLINE Packet8i preinterpret<Packet8i,Packet8f>(const Packet8f& a) { - return _mm256_castps_si256(a); -} - -template<> EIGEN_STRONG_INLINE Packet8f preinterpret<Packet8f,Packet8i>(const Packet8i& a) { - return _mm256_castsi256_ps(a); -} - -#ifndef EIGEN_VECTORIZE_AVX512 - -template <> -struct type_casting_traits<Eigen::half, float> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8h, Packet8f>(const Packet8h& a) { - return half2float(a); -} - -template <> -struct type_casting_traits<float, Eigen::half> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -#endif // EIGEN_VECTORIZE_AVX512 - -template<> EIGEN_STRONG_INLINE Packet8h pcast<Packet8f, Packet8h>(const Packet8f& a) { - return float2half(a); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TYPE_CASTING_AVX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/Complex.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/Complex.h deleted file mode 100644 index 9ee7a284..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/Complex.h +++ /dev/null @@ -1,492 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2018 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX_AVX512_H -#define EIGEN_COMPLEX_AVX512_H - -namespace Eigen { - -namespace internal { - -//---------- float ---------- -struct Packet8cf -{ - EIGEN_STRONG_INLINE Packet8cf() {} - EIGEN_STRONG_INLINE explicit Packet8cf(const __m512& a) : v(a) {} - __m512 v; -}; - -template<> struct packet_traits<std::complex<float> > : default_packet_traits -{ - typedef Packet8cf type; - typedef Packet4cf half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 8, - HasHalfPacket = 1, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0, - HasReduxp = 0 - }; -}; - -template<> struct unpacket_traits<Packet8cf> { - typedef std::complex<float> type; - enum { - size = 8, - alignment=unpacket_traits<Packet16f>::alignment, - vectorizable=true, - masked_load_available=false, - masked_store_available=false - }; - typedef Packet4cf half; -}; - -template<> EIGEN_STRONG_INLINE Packet8cf ptrue<Packet8cf>(const Packet8cf& a) { return Packet8cf(ptrue(Packet16f(a.v))); } -template<> EIGEN_STRONG_INLINE Packet8cf pnot<Packet8cf>(const Packet8cf& a) { return Packet8cf(pnot(Packet16f(a.v))); } -template<> EIGEN_STRONG_INLINE Packet8cf padd<Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(_mm512_add_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet8cf psub<Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(_mm512_sub_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet8cf pnegate(const Packet8cf& a) -{ - return Packet8cf(pnegate(a.v)); -} -template<> EIGEN_STRONG_INLINE Packet8cf pconj(const Packet8cf& a) -{ - const __m512 mask = _mm512_castsi512_ps(_mm512_setr_epi32( - 0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000, - 0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000)); - return Packet8cf(pxor(a.v,mask)); -} - -template<> EIGEN_STRONG_INLINE Packet8cf pmul<Packet8cf>(const Packet8cf& a, const Packet8cf& b) -{ - __m512 tmp2 = _mm512_mul_ps(_mm512_movehdup_ps(a.v), _mm512_permute_ps(b.v, _MM_SHUFFLE(2,3,0,1))); - return Packet8cf(_mm512_fmaddsub_ps(_mm512_moveldup_ps(a.v), b.v, tmp2)); -} - -template<> EIGEN_STRONG_INLINE Packet8cf pand <Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(pand(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet8cf por <Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(por(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet8cf pxor <Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(pxor(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet8cf pandnot<Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(pandnot(a.v,b.v)); } - -template <> -EIGEN_STRONG_INLINE Packet8cf pcmp_eq(const Packet8cf& a, const Packet8cf& b) { - __m512 eq = pcmp_eq<Packet16f>(a.v, b.v); - return Packet8cf(pand(eq, _mm512_permute_ps(eq, 0xB1))); -} - -template<> EIGEN_STRONG_INLINE Packet8cf pload <Packet8cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet8cf(pload<Packet16f>(&numext::real_ref(*from))); } -template<> EIGEN_STRONG_INLINE Packet8cf ploadu<Packet8cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet8cf(ploadu<Packet16f>(&numext::real_ref(*from))); } - - -template<> EIGEN_STRONG_INLINE Packet8cf pset1<Packet8cf>(const std::complex<float>& from) -{ - return Packet8cf(_mm512_castpd_ps(pload1<Packet8d>((const double*)(const void*)&from))); -} - -template<> EIGEN_STRONG_INLINE Packet8cf ploaddup<Packet8cf>(const std::complex<float>* from) -{ - return Packet8cf( _mm512_castpd_ps( ploaddup<Packet8d>((const double*)(const void*)from )) ); -} -template<> EIGEN_STRONG_INLINE Packet8cf ploadquad<Packet8cf>(const std::complex<float>* from) -{ - return Packet8cf( _mm512_castpd_ps( ploadquad<Packet8d>((const double*)(const void*)from )) ); -} - -template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float>* to, const Packet8cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float>* to, const Packet8cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), from.v); } - -template<> EIGEN_DEVICE_FUNC inline Packet8cf pgather<std::complex<float>, Packet8cf>(const std::complex<float>* from, Index stride) -{ - return Packet8cf(_mm512_castpd_ps(pgather<double,Packet8d>((const double*)(const void*)from, stride))); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet8cf>(std::complex<float>* to, const Packet8cf& from, Index stride) -{ - pscatter((double*)(void*)to, _mm512_castps_pd(from.v), stride); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet8cf>(const Packet8cf& a) -{ - return pfirst(Packet2cf(_mm512_castps512_ps128(a.v))); -} - -template<> EIGEN_STRONG_INLINE Packet8cf preverse(const Packet8cf& a) { - return Packet8cf(_mm512_castsi512_ps( - _mm512_permutexvar_epi64( _mm512_set_epi32(0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7), - _mm512_castps_si512(a.v)))); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet8cf>(const Packet8cf& a) -{ - return predux(padd(Packet4cf(extract256<0>(a.v)), - Packet4cf(extract256<1>(a.v)))); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet8cf>(const Packet8cf& a) -{ - return predux_mul(pmul(Packet4cf(extract256<0>(a.v)), - Packet4cf(extract256<1>(a.v)))); -} - -template <> -EIGEN_STRONG_INLINE Packet4cf predux_half_dowto4<Packet8cf>(const Packet8cf& a) { - __m256 lane0 = extract256<0>(a.v); - __m256 lane1 = extract256<1>(a.v); - __m256 res = _mm256_add_ps(lane0, lane1); - return Packet4cf(res); -} - -template<int Offset> -struct palign_impl<Offset,Packet8cf> -{ - static EIGEN_STRONG_INLINE void run(Packet8cf& first, const Packet8cf& second) - { - if (Offset==0) return; - palign_impl<Offset*2,Packet16f>::run(first.v, second.v); - } -}; - -template<> struct conj_helper<Packet8cf, Packet8cf, false,true> -{ - EIGEN_STRONG_INLINE Packet8cf pmadd(const Packet8cf& x, const Packet8cf& y, const Packet8cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet8cf pmul(const Packet8cf& a, const Packet8cf& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet8cf, Packet8cf, true,false> -{ - EIGEN_STRONG_INLINE Packet8cf pmadd(const Packet8cf& x, const Packet8cf& y, const Packet8cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet8cf pmul(const Packet8cf& a, const Packet8cf& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet8cf, Packet8cf, true,true> -{ - EIGEN_STRONG_INLINE Packet8cf pmadd(const Packet8cf& x, const Packet8cf& y, const Packet8cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet8cf pmul(const Packet8cf& a, const Packet8cf& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet8cf,Packet16f) - -template<> EIGEN_STRONG_INLINE Packet8cf pdiv<Packet8cf>(const Packet8cf& a, const Packet8cf& b) -{ - Packet8cf num = pmul(a, pconj(b)); - __m512 tmp = _mm512_mul_ps(b.v, b.v); - __m512 tmp2 = _mm512_shuffle_ps(tmp,tmp,0xB1); - __m512 denom = _mm512_add_ps(tmp, tmp2); - return Packet8cf(_mm512_div_ps(num.v, denom)); -} - -template<> EIGEN_STRONG_INLINE Packet8cf pcplxflip<Packet8cf>(const Packet8cf& x) -{ - return Packet8cf(_mm512_shuffle_ps(x.v, x.v, _MM_SHUFFLE(2, 3, 0 ,1))); -} - -//---------- double ---------- -struct Packet4cd -{ - EIGEN_STRONG_INLINE Packet4cd() {} - EIGEN_STRONG_INLINE explicit Packet4cd(const __m512d& a) : v(a) {} - __m512d v; -}; - -template<> struct packet_traits<std::complex<double> > : default_packet_traits -{ - typedef Packet4cd type; - typedef Packet2cd half; - enum { - Vectorizable = 1, - AlignedOnScalar = 0, - size = 4, - HasHalfPacket = 1, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0, - HasReduxp = 0 - }; -}; - -template<> struct unpacket_traits<Packet4cd> { - typedef std::complex<double> type; - enum { - size = 4, - alignment = unpacket_traits<Packet8d>::alignment, - vectorizable=true, - masked_load_available=false, - masked_store_available=false - }; - typedef Packet2cd half; -}; - -template<> EIGEN_STRONG_INLINE Packet4cd padd<Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(_mm512_add_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cd psub<Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(_mm512_sub_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cd pnegate(const Packet4cd& a) { return Packet4cd(pnegate(a.v)); } -template<> EIGEN_STRONG_INLINE Packet4cd pconj(const Packet4cd& a) -{ - const __m512d mask = _mm512_castsi512_pd( - _mm512_set_epi32(0x80000000,0x0,0x0,0x0,0x80000000,0x0,0x0,0x0, - 0x80000000,0x0,0x0,0x0,0x80000000,0x0,0x0,0x0)); - return Packet4cd(pxor(a.v,mask)); -} - -template<> EIGEN_STRONG_INLINE Packet4cd pmul<Packet4cd>(const Packet4cd& a, const Packet4cd& b) -{ - __m512d tmp1 = _mm512_shuffle_pd(a.v,a.v,0x0); - __m512d tmp2 = _mm512_shuffle_pd(a.v,a.v,0xFF); - __m512d tmp3 = _mm512_shuffle_pd(b.v,b.v,0x55); - __m512d odd = _mm512_mul_pd(tmp2, tmp3); - return Packet4cd(_mm512_fmaddsub_pd(tmp1, b.v, odd)); -} - -template<> EIGEN_STRONG_INLINE Packet4cd ptrue<Packet4cd>(const Packet4cd& a) { return Packet4cd(ptrue(Packet8d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet4cd pnot<Packet4cd>(const Packet4cd& a) { return Packet4cd(pnot(Packet8d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet4cd pand <Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(pand(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cd por <Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(por(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cd pxor <Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(pxor(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet4cd pandnot<Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(pandnot(a.v,b.v)); } - -template <> -EIGEN_STRONG_INLINE Packet4cd pcmp_eq(const Packet4cd& a, const Packet4cd& b) { - __m512d eq = pcmp_eq<Packet8d>(a.v, b.v); - return Packet4cd(pand(eq, _mm512_permute_pd(eq, 0x55))); -} - -template<> EIGEN_STRONG_INLINE Packet4cd pload <Packet4cd>(const std::complex<double>* from) -{ EIGEN_DEBUG_ALIGNED_LOAD return Packet4cd(pload<Packet8d>((const double*)from)); } -template<> EIGEN_STRONG_INLINE Packet4cd ploadu<Packet4cd>(const std::complex<double>* from) -{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet4cd(ploadu<Packet8d>((const double*)from)); } - -template<> EIGEN_STRONG_INLINE Packet4cd pset1<Packet4cd>(const std::complex<double>& from) -{ - #ifdef EIGEN_VECTORIZE_AVX512DQ - return Packet4cd(_mm512_broadcast_f64x2(pset1<Packet1cd>(from).v)); - #else - return Packet4cd(_mm512_castps_pd(_mm512_broadcast_f32x4( _mm_castpd_ps(pset1<Packet1cd>(from).v)))); - #endif -} - -template<> EIGEN_STRONG_INLINE Packet4cd ploaddup<Packet4cd>(const std::complex<double>* from) { - return Packet4cd(_mm512_insertf64x4( - _mm512_castpd256_pd512(ploaddup<Packet2cd>(from).v), ploaddup<Packet2cd>(from+1).v, 1)); -} - -template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet4cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet4cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, from.v); } - -template<> EIGEN_DEVICE_FUNC inline Packet4cd pgather<std::complex<double>, Packet4cd>(const std::complex<double>* from, Index stride) -{ - return Packet4cd(_mm512_insertf64x4(_mm512_castpd256_pd512( - _mm256_insertf128_pd(_mm256_castpd128_pd256(ploadu<Packet1cd>(from+0*stride).v), ploadu<Packet1cd>(from+1*stride).v,1)), - _mm256_insertf128_pd(_mm256_castpd128_pd256(ploadu<Packet1cd>(from+2*stride).v), ploadu<Packet1cd>(from+3*stride).v,1), 1)); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet4cd>(std::complex<double>* to, const Packet4cd& from, Index stride) -{ - __m512i fromi = _mm512_castpd_si512(from.v); - double* tod = (double*)(void*)to; - _mm_storeu_pd(tod+0*stride, _mm_castsi128_pd(_mm512_extracti32x4_epi32(fromi,0)) ); - _mm_storeu_pd(tod+2*stride, _mm_castsi128_pd(_mm512_extracti32x4_epi32(fromi,1)) ); - _mm_storeu_pd(tod+4*stride, _mm_castsi128_pd(_mm512_extracti32x4_epi32(fromi,2)) ); - _mm_storeu_pd(tod+6*stride, _mm_castsi128_pd(_mm512_extracti32x4_epi32(fromi,3)) ); -} - -template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet4cd>(const Packet4cd& a) -{ - __m128d low = extract128<0>(a.v); - EIGEN_ALIGN16 double res[2]; - _mm_store_pd(res, low); - return std::complex<double>(res[0],res[1]); -} - -template<> EIGEN_STRONG_INLINE Packet4cd preverse(const Packet4cd& a) { - return Packet4cd(_mm512_shuffle_f64x2(a.v, a.v, EIGEN_SSE_SHUFFLE_MASK(3,2,1,0))); -} - -template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet4cd>(const Packet4cd& a) -{ - return predux(padd(Packet2cd(_mm512_extractf64x4_pd(a.v,0)), - Packet2cd(_mm512_extractf64x4_pd(a.v,1)))); -} - -template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet4cd>(const Packet4cd& a) -{ - return predux_mul(pmul(Packet2cd(_mm512_extractf64x4_pd(a.v,0)), - Packet2cd(_mm512_extractf64x4_pd(a.v,1)))); -} - -template<int Offset> -struct palign_impl<Offset,Packet4cd> -{ - static EIGEN_STRONG_INLINE void run(Packet4cd& first, const Packet4cd& second) - { - if (Offset==0) return; - palign_impl<Offset*2,Packet8d>::run(first.v, second.v); - } -}; - -template<> struct conj_helper<Packet4cd, Packet4cd, false,true> -{ - EIGEN_STRONG_INLINE Packet4cd pmadd(const Packet4cd& x, const Packet4cd& y, const Packet4cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet4cd pmul(const Packet4cd& a, const Packet4cd& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet4cd, Packet4cd, true,false> -{ - EIGEN_STRONG_INLINE Packet4cd pmadd(const Packet4cd& x, const Packet4cd& y, const Packet4cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet4cd pmul(const Packet4cd& a, const Packet4cd& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet4cd, Packet4cd, true,true> -{ - EIGEN_STRONG_INLINE Packet4cd pmadd(const Packet4cd& x, const Packet4cd& y, const Packet4cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet4cd pmul(const Packet4cd& a, const Packet4cd& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet4cd,Packet8d) - -template<> EIGEN_STRONG_INLINE Packet4cd pdiv<Packet4cd>(const Packet4cd& a, const Packet4cd& b) -{ - Packet4cd num = pmul(a, pconj(b)); - __m512d tmp = _mm512_mul_pd(b.v, b.v); - __m512d denom = padd(_mm512_permute_pd(tmp,0x55), tmp); - return Packet4cd(_mm512_div_pd(num.v, denom)); -} - -template<> EIGEN_STRONG_INLINE Packet4cd pcplxflip<Packet4cd>(const Packet4cd& x) -{ - return Packet4cd(_mm512_permute_pd(x.v,0x55)); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet8cf,4>& kernel) { - PacketBlock<Packet8d,4> pb; - - pb.packet[0] = _mm512_castps_pd(kernel.packet[0].v); - pb.packet[1] = _mm512_castps_pd(kernel.packet[1].v); - pb.packet[2] = _mm512_castps_pd(kernel.packet[2].v); - pb.packet[3] = _mm512_castps_pd(kernel.packet[3].v); - ptranspose(pb); - kernel.packet[0].v = _mm512_castpd_ps(pb.packet[0]); - kernel.packet[1].v = _mm512_castpd_ps(pb.packet[1]); - kernel.packet[2].v = _mm512_castpd_ps(pb.packet[2]); - kernel.packet[3].v = _mm512_castpd_ps(pb.packet[3]); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet8cf,8>& kernel) { - PacketBlock<Packet8d,8> pb; - - pb.packet[0] = _mm512_castps_pd(kernel.packet[0].v); - pb.packet[1] = _mm512_castps_pd(kernel.packet[1].v); - pb.packet[2] = _mm512_castps_pd(kernel.packet[2].v); - pb.packet[3] = _mm512_castps_pd(kernel.packet[3].v); - pb.packet[4] = _mm512_castps_pd(kernel.packet[4].v); - pb.packet[5] = _mm512_castps_pd(kernel.packet[5].v); - pb.packet[6] = _mm512_castps_pd(kernel.packet[6].v); - pb.packet[7] = _mm512_castps_pd(kernel.packet[7].v); - ptranspose(pb); - kernel.packet[0].v = _mm512_castpd_ps(pb.packet[0]); - kernel.packet[1].v = _mm512_castpd_ps(pb.packet[1]); - kernel.packet[2].v = _mm512_castpd_ps(pb.packet[2]); - kernel.packet[3].v = _mm512_castpd_ps(pb.packet[3]); - kernel.packet[4].v = _mm512_castpd_ps(pb.packet[4]); - kernel.packet[5].v = _mm512_castpd_ps(pb.packet[5]); - kernel.packet[6].v = _mm512_castpd_ps(pb.packet[6]); - kernel.packet[7].v = _mm512_castpd_ps(pb.packet[7]); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4cd,4>& kernel) { - __m512d T0 = _mm512_shuffle_f64x2(kernel.packet[0].v, kernel.packet[1].v, EIGEN_SSE_SHUFFLE_MASK(0,1,0,1)); // [a0 a1 b0 b1] - __m512d T1 = _mm512_shuffle_f64x2(kernel.packet[0].v, kernel.packet[1].v, EIGEN_SSE_SHUFFLE_MASK(2,3,2,3)); // [a2 a3 b2 b3] - __m512d T2 = _mm512_shuffle_f64x2(kernel.packet[2].v, kernel.packet[3].v, EIGEN_SSE_SHUFFLE_MASK(0,1,0,1)); // [c0 c1 d0 d1] - __m512d T3 = _mm512_shuffle_f64x2(kernel.packet[2].v, kernel.packet[3].v, EIGEN_SSE_SHUFFLE_MASK(2,3,2,3)); // [c2 c3 d2 d3] - - kernel.packet[3] = Packet4cd(_mm512_shuffle_f64x2(T1, T3, EIGEN_SSE_SHUFFLE_MASK(1,3,1,3))); // [a3 b3 c3 d3] - kernel.packet[2] = Packet4cd(_mm512_shuffle_f64x2(T1, T3, EIGEN_SSE_SHUFFLE_MASK(0,2,0,2))); // [a2 b2 c2 d2] - kernel.packet[1] = Packet4cd(_mm512_shuffle_f64x2(T0, T2, EIGEN_SSE_SHUFFLE_MASK(1,3,1,3))); // [a1 b1 c1 d1] - kernel.packet[0] = Packet4cd(_mm512_shuffle_f64x2(T0, T2, EIGEN_SSE_SHUFFLE_MASK(0,2,0,2))); // [a0 b0 c0 d0] -} - -template<> EIGEN_STRONG_INLINE Packet8cf pinsertfirst(const Packet8cf& a, std::complex<float> b) -{ - Packet2cf tmp = Packet2cf(_mm512_extractf32x4_ps(a.v,0)); - tmp = pinsertfirst(tmp, b); - return Packet8cf( _mm512_insertf32x4(a.v, tmp.v, 0) ); -} - -template<> EIGEN_STRONG_INLINE Packet4cd pinsertfirst(const Packet4cd& a, std::complex<double> b) -{ - return Packet4cd(_mm512_castsi512_pd( _mm512_inserti32x4(_mm512_castpd_si512(a.v), _mm_castpd_si128(pset1<Packet1cd>(b).v), 0) )); -} - -template<> EIGEN_STRONG_INLINE Packet8cf pinsertlast(const Packet8cf& a, std::complex<float> b) -{ - Packet2cf tmp = Packet2cf(_mm512_extractf32x4_ps(a.v,3) ); - tmp = pinsertlast(tmp, b); - return Packet8cf( _mm512_insertf32x4(a.v, tmp.v, 3) ); -} - -template<> EIGEN_STRONG_INLINE Packet4cd pinsertlast(const Packet4cd& a, std::complex<double> b) -{ - return Packet4cd(_mm512_castsi512_pd( _mm512_inserti32x4(_mm512_castpd_si512(a.v), _mm_castpd_si128(pset1<Packet1cd>(b).v), 3) )); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_AVX512_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/MathFunctions.h deleted file mode 100644 index 67043d01..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/MathFunctions.h +++ /dev/null @@ -1,446 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@gmail.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_ -#define THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_ - -namespace Eigen { - -namespace internal { - -// Disable the code for older versions of gcc that don't support many of the required avx512 instrinsics. -#if EIGEN_GNUC_AT_LEAST(5, 3) || EIGEN_COMP_CLANG || EIGEN_COMP_MSVC >= 1923 - -#define _EIGEN_DECLARE_CONST_Packet16f(NAME, X) \ - const Packet16f p16f_##NAME = pset1<Packet16f>(X) - -#define _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(NAME, X) \ - const Packet16f p16f_##NAME = preinterpret<Packet16f,Packet16i>(pset1<Packet16i>(X)) - -#define _EIGEN_DECLARE_CONST_Packet8d(NAME, X) \ - const Packet8d p8d_##NAME = pset1<Packet8d>(X) - -#define _EIGEN_DECLARE_CONST_Packet8d_FROM_INT64(NAME, X) \ - const Packet8d p8d_##NAME = _mm512_castsi512_pd(_mm512_set1_epi64(X)) - -// Natural logarithm -// Computes log(x) as log(2^e * m) = C*e + log(m), where the constant C =log(2) -// and m is in the range [sqrt(1/2),sqrt(2)). In this range, the logarithm can -// be easily approximated by a polynomial centered on m=1 for stability. -#if defined(EIGEN_VECTORIZE_AVX512DQ) -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f -plog<Packet16f>(const Packet16f& _x) { - Packet16f x = _x; - _EIGEN_DECLARE_CONST_Packet16f(1, 1.0f); - _EIGEN_DECLARE_CONST_Packet16f(half, 0.5f); - _EIGEN_DECLARE_CONST_Packet16f(126f, 126.0f); - - _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(inv_mant_mask, ~0x7f800000); - - // The smallest non denormalized float number. - _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(min_norm_pos, 0x00800000); - _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(minus_inf, 0xff800000); - _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(pos_inf, 0x7f800000); - _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(nan, 0x7fc00000); - - // Polynomial coefficients. - _EIGEN_DECLARE_CONST_Packet16f(cephes_SQRTHF, 0.707106781186547524f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p0, 7.0376836292E-2f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p1, -1.1514610310E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p2, 1.1676998740E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p3, -1.2420140846E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p4, +1.4249322787E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p5, -1.6668057665E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p6, +2.0000714765E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p7, -2.4999993993E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_p8, +3.3333331174E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_q1, -2.12194440e-4f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_log_q2, 0.693359375f); - - // invalid_mask is set to true when x is NaN - __mmask16 invalid_mask = _mm512_cmp_ps_mask(x, _mm512_setzero_ps(), _CMP_NGE_UQ); - __mmask16 iszero_mask = _mm512_cmp_ps_mask(x, _mm512_setzero_ps(), _CMP_EQ_OQ); - - // Truncate input values to the minimum positive normal. - x = pmax(x, p16f_min_norm_pos); - - // Extract the shifted exponents. - Packet16f emm0 = _mm512_cvtepi32_ps(_mm512_srli_epi32((preinterpret<Packet16i,Packet16f>(x)), 23)); - Packet16f e = _mm512_sub_ps(emm0, p16f_126f); - - // Set the exponents to -1, i.e. x are in the range [0.5,1). - x = _mm512_and_ps(x, p16f_inv_mant_mask); - x = _mm512_or_ps(x, p16f_half); - - // part2: Shift the inputs from the range [0.5,1) to [sqrt(1/2),sqrt(2)) - // and shift by -1. The values are then centered around 0, which improves - // the stability of the polynomial evaluation. - // if( x < SQRTHF ) { - // e -= 1; - // x = x + x - 1.0; - // } else { x = x - 1.0; } - __mmask16 mask = _mm512_cmp_ps_mask(x, p16f_cephes_SQRTHF, _CMP_LT_OQ); - Packet16f tmp = _mm512_mask_blend_ps(mask, _mm512_setzero_ps(), x); - x = psub(x, p16f_1); - e = psub(e, _mm512_mask_blend_ps(mask, _mm512_setzero_ps(), p16f_1)); - x = padd(x, tmp); - - Packet16f x2 = pmul(x, x); - Packet16f x3 = pmul(x2, x); - - // Evaluate the polynomial approximant of degree 8 in three parts, probably - // to improve instruction-level parallelism. - Packet16f y, y1, y2; - y = pmadd(p16f_cephes_log_p0, x, p16f_cephes_log_p1); - y1 = pmadd(p16f_cephes_log_p3, x, p16f_cephes_log_p4); - y2 = pmadd(p16f_cephes_log_p6, x, p16f_cephes_log_p7); - y = pmadd(y, x, p16f_cephes_log_p2); - y1 = pmadd(y1, x, p16f_cephes_log_p5); - y2 = pmadd(y2, x, p16f_cephes_log_p8); - y = pmadd(y, x3, y1); - y = pmadd(y, x3, y2); - y = pmul(y, x3); - - // Add the logarithm of the exponent back to the result of the interpolation. - y1 = pmul(e, p16f_cephes_log_q1); - tmp = pmul(x2, p16f_half); - y = padd(y, y1); - x = psub(x, tmp); - y2 = pmul(e, p16f_cephes_log_q2); - x = padd(x, y); - x = padd(x, y2); - - __mmask16 pos_inf_mask = _mm512_cmp_ps_mask(_x,p16f_pos_inf,_CMP_EQ_OQ); - // Filter out invalid inputs, i.e.: - // - negative arg will be NAN, - // - 0 will be -INF. - // - +INF will be +INF - return _mm512_mask_blend_ps(iszero_mask, - _mm512_mask_blend_ps(invalid_mask, - _mm512_mask_blend_ps(pos_inf_mask,x,p16f_pos_inf), - p16f_nan), - p16f_minus_inf); -} -#endif - -// Exponential function. Works by writing "x = m*log(2) + r" where -// "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then -// "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1). -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f -pexp<Packet16f>(const Packet16f& _x) { - _EIGEN_DECLARE_CONST_Packet16f(1, 1.0f); - _EIGEN_DECLARE_CONST_Packet16f(half, 0.5f); - _EIGEN_DECLARE_CONST_Packet16f(127, 127.0f); - - _EIGEN_DECLARE_CONST_Packet16f(exp_hi, 88.3762626647950f); - _EIGEN_DECLARE_CONST_Packet16f(exp_lo, -88.3762626647949f); - - _EIGEN_DECLARE_CONST_Packet16f(cephes_LOG2EF, 1.44269504088896341f); - - _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p0, 1.9875691500E-4f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p1, 1.3981999507E-3f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p2, 8.3334519073E-3f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p3, 4.1665795894E-2f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p4, 1.6666665459E-1f); - _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p5, 5.0000001201E-1f); - - // Clamp x. - Packet16f x = pmax(pmin(_x, p16f_exp_hi), p16f_exp_lo); - - // Express exp(x) as exp(m*ln(2) + r), start by extracting - // m = floor(x/ln(2) + 0.5). - Packet16f m = _mm512_floor_ps(pmadd(x, p16f_cephes_LOG2EF, p16f_half)); - - // Get r = x - m*ln(2). Note that we can do this without losing more than one - // ulp precision due to the FMA instruction. - _EIGEN_DECLARE_CONST_Packet16f(nln2, -0.6931471805599453f); - Packet16f r = _mm512_fmadd_ps(m, p16f_nln2, x); - Packet16f r2 = pmul(r, r); - - // TODO(gonnet): Split into odd/even polynomials and try to exploit - // instruction-level parallelism. - Packet16f y = p16f_cephes_exp_p0; - y = pmadd(y, r, p16f_cephes_exp_p1); - y = pmadd(y, r, p16f_cephes_exp_p2); - y = pmadd(y, r, p16f_cephes_exp_p3); - y = pmadd(y, r, p16f_cephes_exp_p4); - y = pmadd(y, r, p16f_cephes_exp_p5); - y = pmadd(y, r2, r); - y = padd(y, p16f_1); - - // Build emm0 = 2^m. - Packet16i emm0 = _mm512_cvttps_epi32(padd(m, p16f_127)); - emm0 = _mm512_slli_epi32(emm0, 23); - - // Return 2^m * exp(r). - return pmax(pmul(y, _mm512_castsi512_ps(emm0)), _x); -} - -/*template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8d -pexp<Packet8d>(const Packet8d& _x) { - Packet8d x = _x; - - _EIGEN_DECLARE_CONST_Packet8d(1, 1.0); - _EIGEN_DECLARE_CONST_Packet8d(2, 2.0); - - _EIGEN_DECLARE_CONST_Packet8d(exp_hi, 709.437); - _EIGEN_DECLARE_CONST_Packet8d(exp_lo, -709.436139303); - - _EIGEN_DECLARE_CONST_Packet8d(cephes_LOG2EF, 1.4426950408889634073599); - - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_p0, 1.26177193074810590878e-4); - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_p1, 3.02994407707441961300e-2); - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_p2, 9.99999999999999999910e-1); - - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_q0, 3.00198505138664455042e-6); - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_q1, 2.52448340349684104192e-3); - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_q2, 2.27265548208155028766e-1); - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_q3, 2.00000000000000000009e0); - - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_C1, 0.693145751953125); - _EIGEN_DECLARE_CONST_Packet8d(cephes_exp_C2, 1.42860682030941723212e-6); - - // clamp x - x = pmax(pmin(x, p8d_exp_hi), p8d_exp_lo); - - // Express exp(x) as exp(g + n*log(2)). - const Packet8d n = - _mm512_mul_round_pd(p8d_cephes_LOG2EF, x, _MM_FROUND_TO_NEAREST_INT); - - // Get the remainder modulo log(2), i.e. the "g" described above. Subtract - // n*log(2) out in two steps, i.e. n*C1 + n*C2, C1+C2=log2 to get the last - // digits right. - const Packet8d nC1 = pmul(n, p8d_cephes_exp_C1); - const Packet8d nC2 = pmul(n, p8d_cephes_exp_C2); - x = psub(x, nC1); - x = psub(x, nC2); - - const Packet8d x2 = pmul(x, x); - - // Evaluate the numerator polynomial of the rational interpolant. - Packet8d px = p8d_cephes_exp_p0; - px = pmadd(px, x2, p8d_cephes_exp_p1); - px = pmadd(px, x2, p8d_cephes_exp_p2); - px = pmul(px, x); - - // Evaluate the denominator polynomial of the rational interpolant. - Packet8d qx = p8d_cephes_exp_q0; - qx = pmadd(qx, x2, p8d_cephes_exp_q1); - qx = pmadd(qx, x2, p8d_cephes_exp_q2); - qx = pmadd(qx, x2, p8d_cephes_exp_q3); - - // I don't really get this bit, copied from the SSE2 routines, so... - // TODO(gonnet): Figure out what is going on here, perhaps find a better - // rational interpolant? - x = _mm512_div_pd(px, psub(qx, px)); - x = pmadd(p8d_2, x, p8d_1); - - // Build e=2^n. - const Packet8d e = _mm512_castsi512_pd(_mm512_slli_epi64( - _mm512_add_epi64(_mm512_cvtpd_epi64(n), _mm512_set1_epi64(1023)), 52)); - - // Construct the result 2^n * exp(g) = e * x. The max is used to catch - // non-finite values in the input. - return pmax(pmul(x, e), _x); - }*/ - - -// Functions for sqrt. -// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step -// of Newton's method, at a cost of 1-2 bits of precision as opposed to the -// exact solution. The main advantage of this approach is not just speed, but -// also the fact that it can be inlined and pipelined with other computations, -// further reducing its effective latency. -#if EIGEN_FAST_MATH -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f -psqrt<Packet16f>(const Packet16f& _x) { - Packet16f neg_half = pmul(_x, pset1<Packet16f>(-.5f)); - __mmask16 denormal_mask = _mm512_kand( - _mm512_cmp_ps_mask(_x, pset1<Packet16f>((std::numeric_limits<float>::min)()), - _CMP_LT_OQ), - _mm512_cmp_ps_mask(_x, _mm512_setzero_ps(), _CMP_GE_OQ)); - - Packet16f x = _mm512_rsqrt14_ps(_x); - - // Do a single step of Newton's iteration. - x = pmul(x, pmadd(neg_half, pmul(x, x), pset1<Packet16f>(1.5f))); - - // Flush results for denormals to zero. - return _mm512_mask_blend_ps(denormal_mask, pmul(_x,x), _mm512_setzero_ps()); -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8d -psqrt<Packet8d>(const Packet8d& _x) { - Packet8d neg_half = pmul(_x, pset1<Packet8d>(-.5)); - __mmask16 denormal_mask = _mm512_kand( - _mm512_cmp_pd_mask(_x, pset1<Packet8d>((std::numeric_limits<double>::min)()), - _CMP_LT_OQ), - _mm512_cmp_pd_mask(_x, _mm512_setzero_pd(), _CMP_GE_OQ)); - - Packet8d x = _mm512_rsqrt14_pd(_x); - - // Do a single step of Newton's iteration. - x = pmul(x, pmadd(neg_half, pmul(x, x), pset1<Packet8d>(1.5))); - - // Do a second step of Newton's iteration. - x = pmul(x, pmadd(neg_half, pmul(x, x), pset1<Packet8d>(1.5))); - - return _mm512_mask_blend_pd(denormal_mask, pmul(_x,x), _mm512_setzero_pd()); -} -#else -template <> -EIGEN_STRONG_INLINE Packet16f psqrt<Packet16f>(const Packet16f& x) { - return _mm512_sqrt_ps(x); -} -template <> -EIGEN_STRONG_INLINE Packet8d psqrt<Packet8d>(const Packet8d& x) { - return _mm512_sqrt_pd(x); -} -#endif - -// prsqrt for float. -#if defined(EIGEN_VECTORIZE_AVX512ER) - -template <> -EIGEN_STRONG_INLINE Packet16f prsqrt<Packet16f>(const Packet16f& x) { - return _mm512_rsqrt28_ps(x); -} - -#elif EIGEN_FAST_MATH - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f -prsqrt<Packet16f>(const Packet16f& _x) { - _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(inf, 0x7f800000); - _EIGEN_DECLARE_CONST_Packet16f(one_point_five, 1.5f); - _EIGEN_DECLARE_CONST_Packet16f(minus_half, -0.5f); - - Packet16f neg_half = pmul(_x, p16f_minus_half); - - // Identity infinite, negative and denormal arguments. - __mmask16 inf_mask = _mm512_cmp_ps_mask(_x, p16f_inf, _CMP_EQ_OQ); - __mmask16 not_pos_mask = _mm512_cmp_ps_mask(_x, _mm512_setzero_ps(), _CMP_LE_OQ); - __mmask16 not_finite_pos_mask = not_pos_mask | inf_mask; - - // Compute an approximate result using the rsqrt intrinsic, forcing +inf - // for denormals for consistency with AVX and SSE implementations. - Packet16f y_approx = _mm512_rsqrt14_ps(_x); - - // Do a single step of Newton-Raphson iteration to improve the approximation. - // This uses the formula y_{n+1} = y_n * (1.5 - y_n * (0.5 * x) * y_n). - // It is essential to evaluate the inner term like this because forming - // y_n^2 may over- or underflow. - Packet16f y_newton = pmul(y_approx, pmadd(y_approx, pmul(neg_half, y_approx), p16f_one_point_five)); - - // Select the result of the Newton-Raphson step for positive finite arguments. - // For other arguments, choose the output of the intrinsic. This will - // return rsqrt(+inf) = 0, rsqrt(x) = NaN if x < 0, and rsqrt(0) = +inf. - return _mm512_mask_blend_ps(not_finite_pos_mask, y_newton, y_approx); - } - -#else - -template <> -EIGEN_STRONG_INLINE Packet16f prsqrt<Packet16f>(const Packet16f& x) { - _EIGEN_DECLARE_CONST_Packet16f(one, 1.0f); - return _mm512_div_ps(p16f_one, _mm512_sqrt_ps(x)); -} - -#endif - -// prsqrt for double. -#if EIGEN_FAST_MATH -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8d -prsqrt<Packet8d>(const Packet8d& _x) { - _EIGEN_DECLARE_CONST_Packet8d(one_point_five, 1.5); - _EIGEN_DECLARE_CONST_Packet8d(minus_half, -0.5); - _EIGEN_DECLARE_CONST_Packet8d_FROM_INT64(inf, 0x7ff0000000000000LL); - - Packet8d neg_half = pmul(_x, p8d_minus_half); - - // Identity infinite, negative and denormal arguments. - __mmask8 inf_mask = _mm512_cmp_pd_mask(_x, p8d_inf, _CMP_EQ_OQ); - __mmask8 not_pos_mask = _mm512_cmp_pd_mask(_x, _mm512_setzero_pd(), _CMP_LE_OQ); - __mmask8 not_finite_pos_mask = not_pos_mask | inf_mask; - - // Compute an approximate result using the rsqrt intrinsic, forcing +inf - // for denormals for consistency with AVX and SSE implementations. -#if defined(EIGEN_VECTORIZE_AVX512ER) - Packet8d y_approx = _mm512_rsqrt28_pd(_x); -#else - Packet8d y_approx = _mm512_rsqrt14_pd(_x); -#endif - // Do one or two steps of Newton-Raphson's to improve the approximation, depending on the - // starting accuracy (either 2^-14 or 2^-28, depending on whether AVX512ER is available). - // The Newton-Raphson algorithm has quadratic convergence and roughly doubles the number - // of correct digits for each step. - // This uses the formula y_{n+1} = y_n * (1.5 - y_n * (0.5 * x) * y_n). - // It is essential to evaluate the inner term like this because forming - // y_n^2 may over- or underflow. - Packet8d y_newton = pmul(y_approx, pmadd(neg_half, pmul(y_approx, y_approx), p8d_one_point_five)); -#if !defined(EIGEN_VECTORIZE_AVX512ER) - y_newton = pmul(y_newton, pmadd(y_newton, pmul(neg_half, y_newton), p8d_one_point_five)); -#endif - // Select the result of the Newton-Raphson step for positive finite arguments. - // For other arguments, choose the output of the intrinsic. This will - // return rsqrt(+inf) = 0, rsqrt(x) = NaN if x < 0, and rsqrt(0) = +inf. - return _mm512_mask_blend_pd(not_finite_pos_mask, y_newton, y_approx); -} -#else -template <> -EIGEN_STRONG_INLINE Packet8d prsqrt<Packet8d>(const Packet8d& x) { - _EIGEN_DECLARE_CONST_Packet8d(one, 1.0f); - return _mm512_div_pd(p8d_one, _mm512_sqrt_pd(x)); -} -#endif - -#if defined(EIGEN_VECTORIZE_AVX512DQ) -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet16f plog1p<Packet16f>(const Packet16f& _x) { - return generic_plog1p(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet16f pexpm1<Packet16f>(const Packet16f& _x) { - return generic_expm1(_x); -} -#endif - -#endif - - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f -psin<Packet16f>(const Packet16f& _x) { - return psin_float(_x); -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f -pcos<Packet16f>(const Packet16f& _x) { - return pcos_float(_x); -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f -ptanh<Packet16f>(const Packet16f& _x) { - return internal::generic_fast_tanh_float(_x); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_ diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/PacketMath.h deleted file mode 100644 index a53f9bc6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/PacketMath.h +++ /dev/null @@ -1,1929 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Benoit Steiner (benoit.steiner.goog@gmail.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PACKET_MATH_AVX512_H -#define EIGEN_PACKET_MATH_AVX512_H - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD -#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 -#endif - -#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32 -#endif - -#ifdef EIGEN_VECTORIZE_FMA -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#endif -#endif - -typedef __m512 Packet16f; -typedef __m512i Packet16i; -typedef __m512d Packet8d; - -template <> -struct is_arithmetic<__m512> { - enum { value = true }; -}; -template <> -struct is_arithmetic<__m512i> { - enum { value = true }; -}; -template <> -struct is_arithmetic<__m512d> { - enum { value = true }; -}; -typedef struct { - __m256i x; -} Packet16h; - - -template<> struct is_arithmetic<Packet16h> { enum { value = true }; }; - -template <> -struct packet_traits<half> : default_packet_traits { - typedef Packet16h type; - // There is no half-size packet for Packet16h. - typedef Packet16h half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 16, - HasHalfPacket = 0, - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasConj = 0, - HasSetLinear = 0, - HasSqrt = 0, - HasRsqrt = 0, - HasExp = 0, - HasLog = 0, - HasBlend = 0 - }; -}; - -template<> struct packet_traits<float> : default_packet_traits -{ - typedef Packet16f type; - typedef Packet8f half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 16, - HasHalfPacket = 1, - HasBlend = 0, - HasSin = EIGEN_FAST_MATH, - HasCos = EIGEN_FAST_MATH, -#if EIGEN_GNUC_AT_LEAST(5, 3) || (!EIGEN_COMP_GNUC_STRICT) -#ifdef EIGEN_VECTORIZE_AVX512DQ - HasLog = 1, - HasLog1p = 1, - HasExpm1 = 1, - HasNdtri = 1, - HasBessel = 1, -#endif - HasExp = 1, - HasSqrt = EIGEN_FAST_MATH, - HasRsqrt = EIGEN_FAST_MATH, - HasTanh = EIGEN_FAST_MATH, - HasErf = EIGEN_FAST_MATH, -#endif - HasDiv = 1 - }; - }; -template<> struct packet_traits<double> : default_packet_traits -{ - typedef Packet8d type; - typedef Packet4d half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 8, - HasHalfPacket = 1, -#if EIGEN_GNUC_AT_LEAST(5, 3) || (!EIGEN_COMP_GNUC_STRICT) - HasSqrt = EIGEN_FAST_MATH, - HasRsqrt = EIGEN_FAST_MATH, -#endif - HasDiv = 1 - }; -}; - -/* TODO Implement AVX512 for integers -template<> struct packet_traits<int> : default_packet_traits -{ - typedef Packet16i type; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=8 - }; -}; -*/ - -template <> -struct unpacket_traits<Packet16f> { - typedef float type; - typedef Packet8f half; - typedef Packet16i integer_packet; - typedef uint16_t mask_t; - enum { size = 16, alignment=Aligned64, vectorizable=true, masked_load_available=true, masked_store_available=true }; -}; -template <> -struct unpacket_traits<Packet8d> { - typedef double type; - typedef Packet4d half; - enum { size = 8, alignment=Aligned64, vectorizable=true, masked_load_available=false, masked_store_available=false }; -}; -template <> -struct unpacket_traits<Packet16i> { - typedef int type; - typedef Packet8i half; - enum { size = 16, alignment=Aligned64, vectorizable=false, masked_load_available=false, masked_store_available=false }; -}; - -template<> -struct unpacket_traits<Packet16h> { - typedef Eigen::half type; - typedef Packet16h half; - enum {size=16, alignment=Aligned32, vectorizable=true, masked_load_available=false, masked_store_available=false}; -}; - -template <> -EIGEN_STRONG_INLINE Packet16f pset1<Packet16f>(const float& from) { - return _mm512_set1_ps(from); -} -template <> -EIGEN_STRONG_INLINE Packet8d pset1<Packet8d>(const double& from) { - return _mm512_set1_pd(from); -} -template <> -EIGEN_STRONG_INLINE Packet16i pset1<Packet16i>(const int& from) { - return _mm512_set1_epi32(from); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pset1frombits<Packet16f>(unsigned int from) { - return _mm512_castsi512_ps(_mm512_set1_epi32(from)); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pload1<Packet16f>(const float* from) { - return _mm512_broadcastss_ps(_mm_load_ps1(from)); -} -template <> -EIGEN_STRONG_INLINE Packet8d pload1<Packet8d>(const double* from) { - return _mm512_set1_pd(*from); -} - -template <> -EIGEN_STRONG_INLINE Packet16f plset<Packet16f>(const float& a) { - return _mm512_add_ps( - _mm512_set1_ps(a), - _mm512_set_ps(15.0f, 14.0f, 13.0f, 12.0f, 11.0f, 10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f, - 4.0f, 3.0f, 2.0f, 1.0f, 0.0f)); -} -template <> -EIGEN_STRONG_INLINE Packet8d plset<Packet8d>(const double& a) { - return _mm512_add_pd(_mm512_set1_pd(a), - _mm512_set_pd(7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0)); -} - -template <> -EIGEN_STRONG_INLINE Packet16f padd<Packet16f>(const Packet16f& a, - const Packet16f& b) { - return _mm512_add_ps(a, b); -} -template <> -EIGEN_STRONG_INLINE Packet8d padd<Packet8d>(const Packet8d& a, - const Packet8d& b) { - return _mm512_add_pd(a, b); -} -template <> -EIGEN_STRONG_INLINE Packet16i padd<Packet16i>(const Packet16i& a, - const Packet16i& b) { - return _mm512_add_epi32(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet16f psub<Packet16f>(const Packet16f& a, - const Packet16f& b) { - return _mm512_sub_ps(a, b); -} -template <> -EIGEN_STRONG_INLINE Packet8d psub<Packet8d>(const Packet8d& a, - const Packet8d& b) { - return _mm512_sub_pd(a, b); -} -template <> -EIGEN_STRONG_INLINE Packet16i psub<Packet16i>(const Packet16i& a, - const Packet16i& b) { - return _mm512_sub_epi32(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pnegate(const Packet16f& a) { - return _mm512_sub_ps(_mm512_set1_ps(0.0), a); -} -template <> -EIGEN_STRONG_INLINE Packet8d pnegate(const Packet8d& a) { - return _mm512_sub_pd(_mm512_set1_pd(0.0), a); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pconj(const Packet16f& a) { - return a; -} -template <> -EIGEN_STRONG_INLINE Packet8d pconj(const Packet8d& a) { - return a; -} -template <> -EIGEN_STRONG_INLINE Packet16i pconj(const Packet16i& a) { - return a; -} - -template <> -EIGEN_STRONG_INLINE Packet16f pmul<Packet16f>(const Packet16f& a, - const Packet16f& b) { - return _mm512_mul_ps(a, b); -} -template <> -EIGEN_STRONG_INLINE Packet8d pmul<Packet8d>(const Packet8d& a, - const Packet8d& b) { - return _mm512_mul_pd(a, b); -} -template <> -EIGEN_STRONG_INLINE Packet16i pmul<Packet16i>(const Packet16i& a, - const Packet16i& b) { - return _mm512_mul_epi32(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pdiv<Packet16f>(const Packet16f& a, - const Packet16f& b) { - return _mm512_div_ps(a, b); -} -template <> -EIGEN_STRONG_INLINE Packet8d pdiv<Packet8d>(const Packet8d& a, - const Packet8d& b) { - return _mm512_div_pd(a, b); -} - -#ifdef EIGEN_VECTORIZE_FMA -template <> -EIGEN_STRONG_INLINE Packet16f pmadd(const Packet16f& a, const Packet16f& b, - const Packet16f& c) { - return _mm512_fmadd_ps(a, b, c); -} -template <> -EIGEN_STRONG_INLINE Packet8d pmadd(const Packet8d& a, const Packet8d& b, - const Packet8d& c) { - return _mm512_fmadd_pd(a, b, c); -} -#endif - -template <> -EIGEN_DEVICE_FUNC inline Packet16f pselect(const Packet16f& mask, - const Packet16f& a, - const Packet16f& b) { - __mmask16 mask16 = _mm512_cmp_epi32_mask( - _mm512_castps_si512(mask), _mm512_setzero_epi32(), _MM_CMPINT_EQ); - return _mm512_mask_blend_ps(mask16, a, b); -} - -template <> -EIGEN_DEVICE_FUNC inline Packet8d pselect(const Packet8d& mask, - const Packet8d& a, - const Packet8d& b) { - __mmask8 mask8 = _mm512_cmp_epi64_mask(_mm512_castpd_si512(mask), - _mm512_setzero_epi32(), _MM_CMPINT_EQ); - return _mm512_mask_blend_pd(mask8, a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pmin<Packet16f>(const Packet16f& a, - const Packet16f& b) { - // Arguments are reversed to match NaN propagation behavior of std::min. - return _mm512_min_ps(b, a); -} -template <> -EIGEN_STRONG_INLINE Packet8d pmin<Packet8d>(const Packet8d& a, - const Packet8d& b) { - // Arguments are reversed to match NaN propagation behavior of std::min. - return _mm512_min_pd(b, a); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pmax<Packet16f>(const Packet16f& a, - const Packet16f& b) { - // Arguments are reversed to match NaN propagation behavior of std::max. - return _mm512_max_ps(b, a); -} -template <> -EIGEN_STRONG_INLINE Packet8d pmax<Packet8d>(const Packet8d& a, - const Packet8d& b) { - // Arguments are reversed to match NaN propagation behavior of std::max. - return _mm512_max_pd(b, a); -} - -#ifdef EIGEN_VECTORIZE_AVX512DQ -template<int I_> EIGEN_STRONG_INLINE Packet8f extract256(Packet16f x) { return _mm512_extractf32x8_ps(x,I_); } -template<int I_> EIGEN_STRONG_INLINE Packet2d extract128(Packet8d x) { return _mm512_extractf64x2_pd(x,I_); } -EIGEN_STRONG_INLINE Packet16f cat256(Packet8f a, Packet8f b) { return _mm512_insertf32x8(_mm512_castps256_ps512(a),b,1); } -#else -// AVX512F does not define _mm512_extractf32x8_ps to extract _m256 from _m512 -template<int I_> EIGEN_STRONG_INLINE Packet8f extract256(Packet16f x) { - return _mm256_castsi256_ps(_mm512_extracti64x4_epi64( _mm512_castps_si512(x),I_)); -} - -// AVX512F does not define _mm512_extractf64x2_pd to extract _m128 from _m512 -template<int I_> EIGEN_STRONG_INLINE Packet2d extract128(Packet8d x) { - return _mm_castsi128_pd(_mm512_extracti32x4_epi32( _mm512_castpd_si512(x),I_)); -} - -EIGEN_STRONG_INLINE Packet16f cat256(Packet8f a, Packet8f b) { - return _mm512_castsi512_ps(_mm512_inserti64x4(_mm512_castsi256_si512(_mm256_castps_si256(a)), - _mm256_castps_si256(b),1)); -} -#endif - -template <> -EIGEN_STRONG_INLINE Packet16f pcmp_eq(const Packet16f& a, const Packet16f& b) { - __mmask16 mask = _mm512_cmp_ps_mask(a, b, _CMP_EQ_OQ); - return _mm512_castsi512_ps( - _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu)); -} -template<> EIGEN_STRONG_INLINE Packet16f pcmp_le(const Packet16f& a, const Packet16f& b) { - __mmask16 mask = _mm512_cmp_ps_mask(a, b, _CMP_LE_OQ); - return _mm512_castsi512_ps( - _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu)); -} - -template<> EIGEN_STRONG_INLINE Packet16f pcmp_lt(const Packet16f& a, const Packet16f& b) { - __mmask16 mask = _mm512_cmp_ps_mask(a, b, _CMP_LT_OQ); - return _mm512_castsi512_ps( - _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu)); -} - -template<> EIGEN_STRONG_INLINE Packet16f pcmp_lt_or_nan(const Packet16f& a, const Packet16f& b) { - __mmask16 mask = _mm512_cmp_ps_mask(a, b, _CMP_NGT_UQ); - return _mm512_castsi512_ps( - _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu)); -} - -template<> EIGEN_STRONG_INLINE Packet16i pcmp_eq(const Packet16i& a, const Packet16i& b) { - __mmask16 mask = _mm512_cmp_epi32_mask(a, b, _CMP_EQ_OQ); - return _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu); -} - - -template <> -EIGEN_STRONG_INLINE Packet8d pcmp_eq(const Packet8d& a, const Packet8d& b) { - __mmask8 mask = _mm512_cmp_pd_mask(a, b, _CMP_EQ_OQ); - return _mm512_castsi512_pd( - _mm512_mask_set1_epi64(_mm512_set1_epi64(0), mask, 0xffffffffffffffffu)); -} -template <> -EIGEN_STRONG_INLINE Packet8d pcmp_le(const Packet8d& a, const Packet8d& b) { - __mmask8 mask = _mm512_cmp_pd_mask(a, b, _CMP_LE_OQ); - return _mm512_castsi512_pd( - _mm512_mask_set1_epi64(_mm512_set1_epi64(0), mask, 0xffffffffffffffffu)); -} -template <> -EIGEN_STRONG_INLINE Packet8d pcmp_lt(const Packet8d& a, const Packet8d& b) { - __mmask8 mask = _mm512_cmp_pd_mask(a, b, _CMP_LT_OQ); - return _mm512_castsi512_pd( - _mm512_mask_set1_epi64(_mm512_set1_epi64(0), mask, 0xffffffffffffffffu)); -} -template <> -EIGEN_STRONG_INLINE Packet8d pcmp_lt_or_nan(const Packet8d& a, const Packet8d& b) { - __mmask8 mask = _mm512_cmp_pd_mask(a, b, _CMP_NGT_UQ); - return _mm512_castsi512_pd( - _mm512_mask_set1_epi64(_mm512_set1_epi64(0), mask, 0xffffffffffffffffu)); -} - -template <> -EIGEN_STRONG_INLINE Packet16i ptrue<Packet16i>(const Packet16i& /*a*/) { - return _mm512_set1_epi32(0xffffffffu); -} - -template <> -EIGEN_STRONG_INLINE Packet16f ptrue<Packet16f>(const Packet16f& a) { - return _mm512_castsi512_ps(ptrue<Packet16i>(_mm512_castps_si512(a))); -} - -template <> -EIGEN_STRONG_INLINE Packet8d ptrue<Packet8d>(const Packet8d& a) { - return _mm512_castsi512_pd(ptrue<Packet16i>(_mm512_castpd_si512(a))); -} - -template <> -EIGEN_STRONG_INLINE Packet16i pand<Packet16i>(const Packet16i& a, - const Packet16i& b) { - return _mm512_and_si512(a,b); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pand<Packet16f>(const Packet16f& a, - const Packet16f& b) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - return _mm512_and_ps(a, b); -#else - return _mm512_castsi512_ps(pand(_mm512_castps_si512(a),_mm512_castps_si512(b))); -#endif -} -template <> -EIGEN_STRONG_INLINE Packet8d pand<Packet8d>(const Packet8d& a, - const Packet8d& b) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - return _mm512_and_pd(a, b); -#else - Packet8d res = _mm512_undefined_pd(); - Packet4d lane0_a = _mm512_extractf64x4_pd(a, 0); - Packet4d lane0_b = _mm512_extractf64x4_pd(b, 0); - res = _mm512_insertf64x4(res, _mm256_and_pd(lane0_a, lane0_b), 0); - - Packet4d lane1_a = _mm512_extractf64x4_pd(a, 1); - Packet4d lane1_b = _mm512_extractf64x4_pd(b, 1); - res = _mm512_insertf64x4(res, _mm256_and_pd(lane1_a, lane1_b), 1); - - return res; -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet16i por<Packet16i>(const Packet16i& a, const Packet16i& b) { - return _mm512_or_si512(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet16f por<Packet16f>(const Packet16f& a, const Packet16f& b) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - return _mm512_or_ps(a, b); -#else - return _mm512_castsi512_ps(por(_mm512_castps_si512(a),_mm512_castps_si512(b))); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet8d por<Packet8d>(const Packet8d& a, - const Packet8d& b) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - return _mm512_or_pd(a, b); -#else - return _mm512_castsi512_pd(por(_mm512_castpd_si512(a),_mm512_castpd_si512(b))); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet16i pxor<Packet16i>(const Packet16i& a, const Packet16i& b) { - return _mm512_xor_si512(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pxor<Packet16f>(const Packet16f& a, const Packet16f& b) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - return _mm512_xor_ps(a, b); -#else - return _mm512_castsi512_ps(pxor(_mm512_castps_si512(a),_mm512_castps_si512(b))); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet8d pxor<Packet8d>(const Packet8d& a, const Packet8d& b) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - return _mm512_xor_pd(a, b); -#else - return _mm512_castsi512_pd(pxor(_mm512_castpd_si512(a),_mm512_castpd_si512(b))); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet16i pandnot<Packet16i>(const Packet16i& a, const Packet16i& b) { - return _mm512_andnot_si512(b, a); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pandnot<Packet16f>(const Packet16f& a, const Packet16f& b) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - return _mm512_andnot_ps(b, a); -#else - return _mm512_castsi512_ps(pandnot(_mm512_castps_si512(a),_mm512_castps_si512(b))); -#endif -} -template <> -EIGEN_STRONG_INLINE Packet8d pandnot<Packet8d>(const Packet8d& a,const Packet8d& b) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - return _mm512_andnot_pd(b, a); -#else - return _mm512_castsi512_pd(pandnot(_mm512_castpd_si512(a),_mm512_castpd_si512(b))); -#endif -} - -template<int N> EIGEN_STRONG_INLINE Packet16i pshiftleft(Packet16i a) { - return _mm512_slli_epi32(a, N); -} - -template <> -EIGEN_STRONG_INLINE Packet16f pload<Packet16f>(const float* from) { - EIGEN_DEBUG_ALIGNED_LOAD return _mm512_load_ps(from); -} -template <> -EIGEN_STRONG_INLINE Packet8d pload<Packet8d>(const double* from) { - EIGEN_DEBUG_ALIGNED_LOAD return _mm512_load_pd(from); -} -template <> -EIGEN_STRONG_INLINE Packet16i pload<Packet16i>(const int* from) { - EIGEN_DEBUG_ALIGNED_LOAD return _mm512_load_si512( - reinterpret_cast<const __m512i*>(from)); -} - -template <> -EIGEN_STRONG_INLINE Packet16f ploadu<Packet16f>(const float* from) { - EIGEN_DEBUG_UNALIGNED_LOAD return _mm512_loadu_ps(from); -} -template <> -EIGEN_STRONG_INLINE Packet8d ploadu<Packet8d>(const double* from) { - EIGEN_DEBUG_UNALIGNED_LOAD return _mm512_loadu_pd(from); -} -template <> -EIGEN_STRONG_INLINE Packet16i ploadu<Packet16i>(const int* from) { - EIGEN_DEBUG_UNALIGNED_LOAD return _mm512_loadu_si512( - reinterpret_cast<const __m512i*>(from)); -} - -template <> -EIGEN_STRONG_INLINE Packet16f ploadu<Packet16f>(const float* from, uint16_t umask) { - __mmask16 mask = static_cast<__mmask16>(umask); - EIGEN_DEBUG_UNALIGNED_LOAD return _mm512_maskz_loadu_ps(mask, from); -} - -// Loads 8 floats from memory a returns the packet -// {a0, a0 a1, a1, a2, a2, a3, a3, a4, a4, a5, a5, a6, a6, a7, a7} -template <> -EIGEN_STRONG_INLINE Packet16f ploaddup<Packet16f>(const float* from) { - // an unaligned load is required here as there is no requirement - // on the alignment of input pointer 'from' - __m256i low_half = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(from)); - __m512 even_elements = _mm512_castsi512_ps(_mm512_cvtepu32_epi64(low_half)); - __m512 pairs = _mm512_permute_ps(even_elements, _MM_SHUFFLE(2, 2, 0, 0)); - return pairs; -} - -#ifdef EIGEN_VECTORIZE_AVX512DQ -// FIXME: this does not look optimal, better load a Packet4d and shuffle... -// Loads 4 doubles from memory a returns the packet {a0, a0 a1, a1, a2, a2, a3, -// a3} -template <> -EIGEN_STRONG_INLINE Packet8d ploaddup<Packet8d>(const double* from) { - __m512d x = _mm512_setzero_pd(); - x = _mm512_insertf64x2(x, _mm_loaddup_pd(&from[0]), 0); - x = _mm512_insertf64x2(x, _mm_loaddup_pd(&from[1]), 1); - x = _mm512_insertf64x2(x, _mm_loaddup_pd(&from[2]), 2); - x = _mm512_insertf64x2(x, _mm_loaddup_pd(&from[3]), 3); - return x; -} -#else -template <> -EIGEN_STRONG_INLINE Packet8d ploaddup<Packet8d>(const double* from) { - __m512d x = _mm512_setzero_pd(); - x = _mm512_mask_broadcastsd_pd(x, 0x3<<0, _mm_load_sd(from+0)); - x = _mm512_mask_broadcastsd_pd(x, 0x3<<2, _mm_load_sd(from+1)); - x = _mm512_mask_broadcastsd_pd(x, 0x3<<4, _mm_load_sd(from+2)); - x = _mm512_mask_broadcastsd_pd(x, 0x3<<6, _mm_load_sd(from+3)); - return x; -} -#endif - -// Loads 4 floats from memory a returns the packet -// {a0, a0 a0, a0, a1, a1, a1, a1, a2, a2, a2, a2, a3, a3, a3, a3} -template <> -EIGEN_STRONG_INLINE Packet16f ploadquad<Packet16f>(const float* from) { - Packet16f tmp = _mm512_castps128_ps512(ploadu<Packet4f>(from)); - const Packet16i scatter_mask = _mm512_set_epi32(3,3,3,3, 2,2,2,2, 1,1,1,1, 0,0,0,0); - return _mm512_permutexvar_ps(scatter_mask, tmp); -} - -// Loads 2 doubles from memory a returns the packet -// {a0, a0 a0, a0, a1, a1, a1, a1} -template <> -EIGEN_STRONG_INLINE Packet8d ploadquad<Packet8d>(const double* from) { - __m256d lane0 = _mm256_set1_pd(*from); - __m256d lane1 = _mm256_set1_pd(*(from+1)); - __m512d tmp = _mm512_undefined_pd(); - tmp = _mm512_insertf64x4(tmp, lane0, 0); - return _mm512_insertf64x4(tmp, lane1, 1); -} - -template <> -EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet16f& from) { - EIGEN_DEBUG_ALIGNED_STORE _mm512_store_ps(to, from); -} -template <> -EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet8d& from) { - EIGEN_DEBUG_ALIGNED_STORE _mm512_store_pd(to, from); -} -template <> -EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet16i& from) { - EIGEN_DEBUG_ALIGNED_STORE _mm512_storeu_si512(reinterpret_cast<__m512i*>(to), - from); -} - -template <> -EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet16f& from) { - EIGEN_DEBUG_UNALIGNED_STORE _mm512_storeu_ps(to, from); -} -template <> -EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet8d& from) { - EIGEN_DEBUG_UNALIGNED_STORE _mm512_storeu_pd(to, from); -} -template <> -EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet16i& from) { - EIGEN_DEBUG_UNALIGNED_STORE _mm512_storeu_si512( - reinterpret_cast<__m512i*>(to), from); -} -template <> -EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet16f& from, uint16_t umask) { - __mmask16 mask = static_cast<__mmask16>(umask); - EIGEN_DEBUG_UNALIGNED_STORE return _mm512_mask_storeu_ps(to, mask, from); -} - -template <> -EIGEN_DEVICE_FUNC inline Packet16f pgather<float, Packet16f>(const float* from, - Index stride) { - Packet16i stride_vector = _mm512_set1_epi32(convert_index<int>(stride)); - Packet16i stride_multiplier = - _mm512_set_epi32(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); - Packet16i indices = _mm512_mullo_epi32(stride_vector, stride_multiplier); - - return _mm512_i32gather_ps(indices, from, 4); -} -template <> -EIGEN_DEVICE_FUNC inline Packet8d pgather<double, Packet8d>(const double* from, - Index stride) { - Packet8i stride_vector = _mm256_set1_epi32(convert_index<int>(stride)); - Packet8i stride_multiplier = _mm256_set_epi32(7, 6, 5, 4, 3, 2, 1, 0); - Packet8i indices = _mm256_mullo_epi32(stride_vector, stride_multiplier); - - return _mm512_i32gather_pd(indices, from, 8); -} - -template <> -EIGEN_DEVICE_FUNC inline void pscatter<float, Packet16f>(float* to, - const Packet16f& from, - Index stride) { - Packet16i stride_vector = _mm512_set1_epi32(convert_index<int>(stride)); - Packet16i stride_multiplier = - _mm512_set_epi32(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); - Packet16i indices = _mm512_mullo_epi32(stride_vector, stride_multiplier); - _mm512_i32scatter_ps(to, indices, from, 4); -} -template <> -EIGEN_DEVICE_FUNC inline void pscatter<double, Packet8d>(double* to, - const Packet8d& from, - Index stride) { - Packet8i stride_vector = _mm256_set1_epi32(convert_index<int>(stride)); - Packet8i stride_multiplier = _mm256_set_epi32(7, 6, 5, 4, 3, 2, 1, 0); - Packet8i indices = _mm256_mullo_epi32(stride_vector, stride_multiplier); - _mm512_i32scatter_pd(to, indices, from, 8); -} - -template <> -EIGEN_STRONG_INLINE void pstore1<Packet16f>(float* to, const float& a) { - Packet16f pa = pset1<Packet16f>(a); - pstore(to, pa); -} -template <> -EIGEN_STRONG_INLINE void pstore1<Packet8d>(double* to, const double& a) { - Packet8d pa = pset1<Packet8d>(a); - pstore(to, pa); -} -template <> -EIGEN_STRONG_INLINE void pstore1<Packet16i>(int* to, const int& a) { - Packet16i pa = pset1<Packet16i>(a); - pstore(to, pa); -} - -template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } -template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } -template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } - -template <> -EIGEN_STRONG_INLINE float pfirst<Packet16f>(const Packet16f& a) { - return _mm_cvtss_f32(_mm512_extractf32x4_ps(a, 0)); -} -template <> -EIGEN_STRONG_INLINE double pfirst<Packet8d>(const Packet8d& a) { - return _mm_cvtsd_f64(_mm256_extractf128_pd(_mm512_extractf64x4_pd(a, 0), 0)); -} -template <> -EIGEN_STRONG_INLINE int pfirst<Packet16i>(const Packet16i& a) { - return _mm_extract_epi32(_mm512_extracti32x4_epi32(a, 0), 0); -} - -template<> EIGEN_STRONG_INLINE Packet16f preverse(const Packet16f& a) -{ - return _mm512_permutexvar_ps(_mm512_set_epi32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), a); -} - -template<> EIGEN_STRONG_INLINE Packet8d preverse(const Packet8d& a) -{ - return _mm512_permutexvar_pd(_mm512_set_epi32(0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7), a); -} - -template<> EIGEN_STRONG_INLINE Packet16f pabs(const Packet16f& a) -{ - // _mm512_abs_ps intrinsic not found, so hack around it - return _mm512_castsi512_ps(_mm512_and_si512(_mm512_castps_si512(a), _mm512_set1_epi32(0x7fffffff))); -} -template <> -EIGEN_STRONG_INLINE Packet8d pabs(const Packet8d& a) { - // _mm512_abs_ps intrinsic not found, so hack around it - return _mm512_castsi512_pd(_mm512_and_si512(_mm512_castpd_si512(a), - _mm512_set1_epi64(0x7fffffffffffffff))); -} - -#ifdef EIGEN_VECTORIZE_AVX512DQ -// AVX512F does not define _mm512_extractf32x8_ps to extract _m256 from _m512 -#define EIGEN_EXTRACT_8f_FROM_16f(INPUT, OUTPUT) \ - __m256 OUTPUT##_0 = _mm512_extractf32x8_ps(INPUT, 0); \ - __m256 OUTPUT##_1 = _mm512_extractf32x8_ps(INPUT, 1) -#else -#define EIGEN_EXTRACT_8f_FROM_16f(INPUT, OUTPUT) \ - __m256 OUTPUT##_0 = _mm256_insertf128_ps( \ - _mm256_castps128_ps256(_mm512_extractf32x4_ps(INPUT, 0)), \ - _mm512_extractf32x4_ps(INPUT, 1), 1); \ - __m256 OUTPUT##_1 = _mm256_insertf128_ps( \ - _mm256_castps128_ps256(_mm512_extractf32x4_ps(INPUT, 2)), \ - _mm512_extractf32x4_ps(INPUT, 3), 1); -#endif - -#ifdef EIGEN_VECTORIZE_AVX512DQ -#define EIGEN_INSERT_8f_INTO_16f(OUTPUT, INPUTA, INPUTB) \ - OUTPUT = _mm512_insertf32x8(_mm512_castps256_ps512(INPUTA), INPUTB, 1); -#else -#define EIGEN_INSERT_8f_INTO_16f(OUTPUT, INPUTA, INPUTB) \ - OUTPUT = _mm512_undefined_ps(); \ - OUTPUT = _mm512_insertf32x4(OUTPUT, _mm256_extractf128_ps(INPUTA, 0), 0); \ - OUTPUT = _mm512_insertf32x4(OUTPUT, _mm256_extractf128_ps(INPUTA, 1), 1); \ - OUTPUT = _mm512_insertf32x4(OUTPUT, _mm256_extractf128_ps(INPUTB, 0), 2); \ - OUTPUT = _mm512_insertf32x4(OUTPUT, _mm256_extractf128_ps(INPUTB, 1), 3); -#endif -template<> EIGEN_STRONG_INLINE Packet16f preduxp<Packet16f>(const Packet16f* -vecs) -{ - EIGEN_EXTRACT_8f_FROM_16f(vecs[0], vecs0); - EIGEN_EXTRACT_8f_FROM_16f(vecs[1], vecs1); - EIGEN_EXTRACT_8f_FROM_16f(vecs[2], vecs2); - EIGEN_EXTRACT_8f_FROM_16f(vecs[3], vecs3); - EIGEN_EXTRACT_8f_FROM_16f(vecs[4], vecs4); - EIGEN_EXTRACT_8f_FROM_16f(vecs[5], vecs5); - EIGEN_EXTRACT_8f_FROM_16f(vecs[6], vecs6); - EIGEN_EXTRACT_8f_FROM_16f(vecs[7], vecs7); - EIGEN_EXTRACT_8f_FROM_16f(vecs[8], vecs8); - EIGEN_EXTRACT_8f_FROM_16f(vecs[9], vecs9); - EIGEN_EXTRACT_8f_FROM_16f(vecs[10], vecs10); - EIGEN_EXTRACT_8f_FROM_16f(vecs[11], vecs11); - EIGEN_EXTRACT_8f_FROM_16f(vecs[12], vecs12); - EIGEN_EXTRACT_8f_FROM_16f(vecs[13], vecs13); - EIGEN_EXTRACT_8f_FROM_16f(vecs[14], vecs14); - EIGEN_EXTRACT_8f_FROM_16f(vecs[15], vecs15); - - __m256 hsum1 = _mm256_hadd_ps(vecs0_0, vecs1_0); - __m256 hsum2 = _mm256_hadd_ps(vecs2_0, vecs3_0); - __m256 hsum3 = _mm256_hadd_ps(vecs4_0, vecs5_0); - __m256 hsum4 = _mm256_hadd_ps(vecs6_0, vecs7_0); - - __m256 hsum5 = _mm256_hadd_ps(hsum1, hsum1); - __m256 hsum6 = _mm256_hadd_ps(hsum2, hsum2); - __m256 hsum7 = _mm256_hadd_ps(hsum3, hsum3); - __m256 hsum8 = _mm256_hadd_ps(hsum4, hsum4); - - __m256 perm1 = _mm256_permute2f128_ps(hsum5, hsum5, 0x23); - __m256 perm2 = _mm256_permute2f128_ps(hsum6, hsum6, 0x23); - __m256 perm3 = _mm256_permute2f128_ps(hsum7, hsum7, 0x23); - __m256 perm4 = _mm256_permute2f128_ps(hsum8, hsum8, 0x23); - - __m256 sum1 = _mm256_add_ps(perm1, hsum5); - __m256 sum2 = _mm256_add_ps(perm2, hsum6); - __m256 sum3 = _mm256_add_ps(perm3, hsum7); - __m256 sum4 = _mm256_add_ps(perm4, hsum8); - - __m256 blend1 = _mm256_blend_ps(sum1, sum2, 0xcc); - __m256 blend2 = _mm256_blend_ps(sum3, sum4, 0xcc); - - __m256 final = _mm256_blend_ps(blend1, blend2, 0xf0); - - hsum1 = _mm256_hadd_ps(vecs0_1, vecs1_1); - hsum2 = _mm256_hadd_ps(vecs2_1, vecs3_1); - hsum3 = _mm256_hadd_ps(vecs4_1, vecs5_1); - hsum4 = _mm256_hadd_ps(vecs6_1, vecs7_1); - - hsum5 = _mm256_hadd_ps(hsum1, hsum1); - hsum6 = _mm256_hadd_ps(hsum2, hsum2); - hsum7 = _mm256_hadd_ps(hsum3, hsum3); - hsum8 = _mm256_hadd_ps(hsum4, hsum4); - - perm1 = _mm256_permute2f128_ps(hsum5, hsum5, 0x23); - perm2 = _mm256_permute2f128_ps(hsum6, hsum6, 0x23); - perm3 = _mm256_permute2f128_ps(hsum7, hsum7, 0x23); - perm4 = _mm256_permute2f128_ps(hsum8, hsum8, 0x23); - - sum1 = _mm256_add_ps(perm1, hsum5); - sum2 = _mm256_add_ps(perm2, hsum6); - sum3 = _mm256_add_ps(perm3, hsum7); - sum4 = _mm256_add_ps(perm4, hsum8); - - blend1 = _mm256_blend_ps(sum1, sum2, 0xcc); - blend2 = _mm256_blend_ps(sum3, sum4, 0xcc); - - final = _mm256_add_ps(final, _mm256_blend_ps(blend1, blend2, 0xf0)); - - hsum1 = _mm256_hadd_ps(vecs8_0, vecs9_0); - hsum2 = _mm256_hadd_ps(vecs10_0, vecs11_0); - hsum3 = _mm256_hadd_ps(vecs12_0, vecs13_0); - hsum4 = _mm256_hadd_ps(vecs14_0, vecs15_0); - - hsum5 = _mm256_hadd_ps(hsum1, hsum1); - hsum6 = _mm256_hadd_ps(hsum2, hsum2); - hsum7 = _mm256_hadd_ps(hsum3, hsum3); - hsum8 = _mm256_hadd_ps(hsum4, hsum4); - - perm1 = _mm256_permute2f128_ps(hsum5, hsum5, 0x23); - perm2 = _mm256_permute2f128_ps(hsum6, hsum6, 0x23); - perm3 = _mm256_permute2f128_ps(hsum7, hsum7, 0x23); - perm4 = _mm256_permute2f128_ps(hsum8, hsum8, 0x23); - - sum1 = _mm256_add_ps(perm1, hsum5); - sum2 = _mm256_add_ps(perm2, hsum6); - sum3 = _mm256_add_ps(perm3, hsum7); - sum4 = _mm256_add_ps(perm4, hsum8); - - blend1 = _mm256_blend_ps(sum1, sum2, 0xcc); - blend2 = _mm256_blend_ps(sum3, sum4, 0xcc); - - __m256 final_1 = _mm256_blend_ps(blend1, blend2, 0xf0); - - hsum1 = _mm256_hadd_ps(vecs8_1, vecs9_1); - hsum2 = _mm256_hadd_ps(vecs10_1, vecs11_1); - hsum3 = _mm256_hadd_ps(vecs12_1, vecs13_1); - hsum4 = _mm256_hadd_ps(vecs14_1, vecs15_1); - - hsum5 = _mm256_hadd_ps(hsum1, hsum1); - hsum6 = _mm256_hadd_ps(hsum2, hsum2); - hsum7 = _mm256_hadd_ps(hsum3, hsum3); - hsum8 = _mm256_hadd_ps(hsum4, hsum4); - - perm1 = _mm256_permute2f128_ps(hsum5, hsum5, 0x23); - perm2 = _mm256_permute2f128_ps(hsum6, hsum6, 0x23); - perm3 = _mm256_permute2f128_ps(hsum7, hsum7, 0x23); - perm4 = _mm256_permute2f128_ps(hsum8, hsum8, 0x23); - - sum1 = _mm256_add_ps(perm1, hsum5); - sum2 = _mm256_add_ps(perm2, hsum6); - sum3 = _mm256_add_ps(perm3, hsum7); - sum4 = _mm256_add_ps(perm4, hsum8); - - blend1 = _mm256_blend_ps(sum1, sum2, 0xcc); - blend2 = _mm256_blend_ps(sum3, sum4, 0xcc); - - final_1 = _mm256_add_ps(final_1, _mm256_blend_ps(blend1, blend2, 0xf0)); - - __m512 final_output; - - EIGEN_INSERT_8f_INTO_16f(final_output, final, final_1); - return final_output; -} - -template<> EIGEN_STRONG_INLINE Packet8d preduxp<Packet8d>(const Packet8d* vecs) -{ - Packet4d vecs0_0 = _mm512_extractf64x4_pd(vecs[0], 0); - Packet4d vecs0_1 = _mm512_extractf64x4_pd(vecs[0], 1); - - Packet4d vecs1_0 = _mm512_extractf64x4_pd(vecs[1], 0); - Packet4d vecs1_1 = _mm512_extractf64x4_pd(vecs[1], 1); - - Packet4d vecs2_0 = _mm512_extractf64x4_pd(vecs[2], 0); - Packet4d vecs2_1 = _mm512_extractf64x4_pd(vecs[2], 1); - - Packet4d vecs3_0 = _mm512_extractf64x4_pd(vecs[3], 0); - Packet4d vecs3_1 = _mm512_extractf64x4_pd(vecs[3], 1); - - Packet4d vecs4_0 = _mm512_extractf64x4_pd(vecs[4], 0); - Packet4d vecs4_1 = _mm512_extractf64x4_pd(vecs[4], 1); - - Packet4d vecs5_0 = _mm512_extractf64x4_pd(vecs[5], 0); - Packet4d vecs5_1 = _mm512_extractf64x4_pd(vecs[5], 1); - - Packet4d vecs6_0 = _mm512_extractf64x4_pd(vecs[6], 0); - Packet4d vecs6_1 = _mm512_extractf64x4_pd(vecs[6], 1); - - Packet4d vecs7_0 = _mm512_extractf64x4_pd(vecs[7], 0); - Packet4d vecs7_1 = _mm512_extractf64x4_pd(vecs[7], 1); - - Packet4d tmp0, tmp1; - - tmp0 = _mm256_hadd_pd(vecs0_0, vecs1_0); - tmp0 = _mm256_add_pd(tmp0, _mm256_permute2f128_pd(tmp0, tmp0, 1)); - - tmp1 = _mm256_hadd_pd(vecs2_0, vecs3_0); - tmp1 = _mm256_add_pd(tmp1, _mm256_permute2f128_pd(tmp1, tmp1, 1)); - - __m256d final_0 = _mm256_blend_pd(tmp0, tmp1, 0xC); - - tmp0 = _mm256_hadd_pd(vecs0_1, vecs1_1); - tmp0 = _mm256_add_pd(tmp0, _mm256_permute2f128_pd(tmp0, tmp0, 1)); - - tmp1 = _mm256_hadd_pd(vecs2_1, vecs3_1); - tmp1 = _mm256_add_pd(tmp1, _mm256_permute2f128_pd(tmp1, tmp1, 1)); - - final_0 = _mm256_add_pd(final_0, _mm256_blend_pd(tmp0, tmp1, 0xC)); - - tmp0 = _mm256_hadd_pd(vecs4_0, vecs5_0); - tmp0 = _mm256_add_pd(tmp0, _mm256_permute2f128_pd(tmp0, tmp0, 1)); - - tmp1 = _mm256_hadd_pd(vecs6_0, vecs7_0); - tmp1 = _mm256_add_pd(tmp1, _mm256_permute2f128_pd(tmp1, tmp1, 1)); - - __m256d final_1 = _mm256_blend_pd(tmp0, tmp1, 0xC); - - tmp0 = _mm256_hadd_pd(vecs4_1, vecs5_1); - tmp0 = _mm256_add_pd(tmp0, _mm256_permute2f128_pd(tmp0, tmp0, 1)); - - tmp1 = _mm256_hadd_pd(vecs6_1, vecs7_1); - tmp1 = _mm256_add_pd(tmp1, _mm256_permute2f128_pd(tmp1, tmp1, 1)); - - final_1 = _mm256_add_pd(final_1, _mm256_blend_pd(tmp0, tmp1, 0xC)); - - __m512d final_output = _mm512_castpd256_pd512(final_0); - - return _mm512_insertf64x4(final_output, final_1, 1); -} - -template <> -EIGEN_STRONG_INLINE float predux<Packet16f>(const Packet16f& a) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - __m256 lane0 = _mm512_extractf32x8_ps(a, 0); - __m256 lane1 = _mm512_extractf32x8_ps(a, 1); - Packet8f x = _mm256_add_ps(lane0, lane1); - return predux<Packet8f>(x); -#else - __m128 lane0 = _mm512_extractf32x4_ps(a, 0); - __m128 lane1 = _mm512_extractf32x4_ps(a, 1); - __m128 lane2 = _mm512_extractf32x4_ps(a, 2); - __m128 lane3 = _mm512_extractf32x4_ps(a, 3); - __m128 sum = _mm_add_ps(_mm_add_ps(lane0, lane1), _mm_add_ps(lane2, lane3)); - sum = _mm_hadd_ps(sum, sum); - sum = _mm_hadd_ps(sum, _mm_permute_ps(sum, 1)); - return _mm_cvtss_f32(sum); -#endif -} -template <> -EIGEN_STRONG_INLINE double predux<Packet8d>(const Packet8d& a) { - __m256d lane0 = _mm512_extractf64x4_pd(a, 0); - __m256d lane1 = _mm512_extractf64x4_pd(a, 1); - __m256d sum = _mm256_add_pd(lane0, lane1); - __m256d tmp0 = _mm256_hadd_pd(sum, _mm256_permute2f128_pd(sum, sum, 1)); - return _mm_cvtsd_f64(_mm256_castpd256_pd128(_mm256_hadd_pd(tmp0, tmp0))); -} - -template <> -EIGEN_STRONG_INLINE Packet8f predux_half_dowto4<Packet16f>(const Packet16f& a) { -#ifdef EIGEN_VECTORIZE_AVX512DQ - __m256 lane0 = _mm512_extractf32x8_ps(a, 0); - __m256 lane1 = _mm512_extractf32x8_ps(a, 1); - return _mm256_add_ps(lane0, lane1); -#else - __m128 lane0 = _mm512_extractf32x4_ps(a, 0); - __m128 lane1 = _mm512_extractf32x4_ps(a, 1); - __m128 lane2 = _mm512_extractf32x4_ps(a, 2); - __m128 lane3 = _mm512_extractf32x4_ps(a, 3); - __m128 sum0 = _mm_add_ps(lane0, lane2); - __m128 sum1 = _mm_add_ps(lane1, lane3); - return _mm256_insertf128_ps(_mm256_castps128_ps256(sum0), sum1, 1); -#endif -} -template <> -EIGEN_STRONG_INLINE Packet4d predux_half_dowto4<Packet8d>(const Packet8d& a) { - __m256d lane0 = _mm512_extractf64x4_pd(a, 0); - __m256d lane1 = _mm512_extractf64x4_pd(a, 1); - __m256d res = _mm256_add_pd(lane0, lane1); - return res; -} - -template <> -EIGEN_STRONG_INLINE float predux_mul<Packet16f>(const Packet16f& a) { -//#ifdef EIGEN_VECTORIZE_AVX512DQ -#if 0 - Packet8f lane0 = _mm512_extractf32x8_ps(a, 0); - Packet8f lane1 = _mm512_extractf32x8_ps(a, 1); - Packet8f res = pmul(lane0, lane1); - res = pmul(res, _mm256_permute2f128_ps(res, res, 1)); - res = pmul(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 3, 2))); - return pfirst(pmul(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 0, 1)))); -#else - __m128 lane0 = _mm512_extractf32x4_ps(a, 0); - __m128 lane1 = _mm512_extractf32x4_ps(a, 1); - __m128 lane2 = _mm512_extractf32x4_ps(a, 2); - __m128 lane3 = _mm512_extractf32x4_ps(a, 3); - __m128 res = pmul(pmul(lane0, lane1), pmul(lane2, lane3)); - res = pmul(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 3, 2))); - return pfirst(pmul(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 0, 1)))); -#endif -} -template <> -EIGEN_STRONG_INLINE double predux_mul<Packet8d>(const Packet8d& a) { - __m256d lane0 = _mm512_extractf64x4_pd(a, 0); - __m256d lane1 = _mm512_extractf64x4_pd(a, 1); - __m256d res = pmul(lane0, lane1); - res = pmul(res, _mm256_permute2f128_pd(res, res, 1)); - return pfirst(pmul(res, _mm256_shuffle_pd(res, res, 1))); -} - -template <> -EIGEN_STRONG_INLINE float predux_min<Packet16f>(const Packet16f& a) { - __m128 lane0 = _mm512_extractf32x4_ps(a, 0); - __m128 lane1 = _mm512_extractf32x4_ps(a, 1); - __m128 lane2 = _mm512_extractf32x4_ps(a, 2); - __m128 lane3 = _mm512_extractf32x4_ps(a, 3); - __m128 res = _mm_min_ps(_mm_min_ps(lane0, lane1), _mm_min_ps(lane2, lane3)); - res = _mm_min_ps(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 3, 2))); - return pfirst(_mm_min_ps(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 0, 1)))); -} -template <> -EIGEN_STRONG_INLINE double predux_min<Packet8d>(const Packet8d& a) { - __m256d lane0 = _mm512_extractf64x4_pd(a, 0); - __m256d lane1 = _mm512_extractf64x4_pd(a, 1); - __m256d res = _mm256_min_pd(lane0, lane1); - res = _mm256_min_pd(res, _mm256_permute2f128_pd(res, res, 1)); - return pfirst(_mm256_min_pd(res, _mm256_shuffle_pd(res, res, 1))); -} - -template <> -EIGEN_STRONG_INLINE float predux_max<Packet16f>(const Packet16f& a) { - __m128 lane0 = _mm512_extractf32x4_ps(a, 0); - __m128 lane1 = _mm512_extractf32x4_ps(a, 1); - __m128 lane2 = _mm512_extractf32x4_ps(a, 2); - __m128 lane3 = _mm512_extractf32x4_ps(a, 3); - __m128 res = _mm_max_ps(_mm_max_ps(lane0, lane1), _mm_max_ps(lane2, lane3)); - res = _mm_max_ps(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 3, 2))); - return pfirst(_mm_max_ps(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 0, 1)))); -} - -template <> -EIGEN_STRONG_INLINE double predux_max<Packet8d>(const Packet8d& a) { - __m256d lane0 = _mm512_extractf64x4_pd(a, 0); - __m256d lane1 = _mm512_extractf64x4_pd(a, 1); - __m256d res = _mm256_max_pd(lane0, lane1); - res = _mm256_max_pd(res, _mm256_permute2f128_pd(res, res, 1)); - return pfirst(_mm256_max_pd(res, _mm256_shuffle_pd(res, res, 1))); -} - -template<> EIGEN_STRONG_INLINE bool predux_any(const Packet16f& x) -{ - Packet16i xi = _mm512_castps_si512(x); - __mmask16 tmp = _mm512_test_epi32_mask(xi,xi); - return !_mm512_kortestz(tmp,tmp); -} - -template <int Offset> -struct palign_impl<Offset, Packet16f> { - static EIGEN_STRONG_INLINE void run(Packet16f& first, - const Packet16f& second) { - if (Offset != 0) { - __m512i first_idx = _mm512_set_epi32( - Offset + 15, Offset + 14, Offset + 13, Offset + 12, Offset + 11, - Offset + 10, Offset + 9, Offset + 8, Offset + 7, Offset + 6, - Offset + 5, Offset + 4, Offset + 3, Offset + 2, Offset + 1, Offset); - - __m512i second_idx = - _mm512_set_epi32(Offset - 1, Offset - 2, Offset - 3, Offset - 4, - Offset - 5, Offset - 6, Offset - 7, Offset - 8, - Offset - 9, Offset - 10, Offset - 11, Offset - 12, - Offset - 13, Offset - 14, Offset - 15, Offset - 16); - - unsigned short mask = 0xFFFF; - mask <<= (16 - Offset); - - first = _mm512_permutexvar_ps(first_idx, first); - Packet16f tmp = _mm512_permutexvar_ps(second_idx, second); - first = _mm512_mask_blend_ps(mask, first, tmp); - } - } -}; -template <int Offset> -struct palign_impl<Offset, Packet8d> { - static EIGEN_STRONG_INLINE void run(Packet8d& first, const Packet8d& second) { - if (Offset != 0) { - __m512i first_idx = _mm512_set_epi32( - 0, Offset + 7, 0, Offset + 6, 0, Offset + 5, 0, Offset + 4, 0, - Offset + 3, 0, Offset + 2, 0, Offset + 1, 0, Offset); - - __m512i second_idx = _mm512_set_epi32( - 0, Offset - 1, 0, Offset - 2, 0, Offset - 3, 0, Offset - 4, 0, - Offset - 5, 0, Offset - 6, 0, Offset - 7, 0, Offset - 8); - - unsigned char mask = 0xFF; - mask <<= (8 - Offset); - - first = _mm512_permutexvar_pd(first_idx, first); - Packet8d tmp = _mm512_permutexvar_pd(second_idx, second); - first = _mm512_mask_blend_pd(mask, first, tmp); - } - } -}; - - -#define PACK_OUTPUT(OUTPUT, INPUT, INDEX, STRIDE) \ - EIGEN_INSERT_8f_INTO_16f(OUTPUT[INDEX], INPUT[INDEX], INPUT[INDEX + STRIDE]); - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet16f, 16>& kernel) { - __m512 T0 = _mm512_unpacklo_ps(kernel.packet[0], kernel.packet[1]); - __m512 T1 = _mm512_unpackhi_ps(kernel.packet[0], kernel.packet[1]); - __m512 T2 = _mm512_unpacklo_ps(kernel.packet[2], kernel.packet[3]); - __m512 T3 = _mm512_unpackhi_ps(kernel.packet[2], kernel.packet[3]); - __m512 T4 = _mm512_unpacklo_ps(kernel.packet[4], kernel.packet[5]); - __m512 T5 = _mm512_unpackhi_ps(kernel.packet[4], kernel.packet[5]); - __m512 T6 = _mm512_unpacklo_ps(kernel.packet[6], kernel.packet[7]); - __m512 T7 = _mm512_unpackhi_ps(kernel.packet[6], kernel.packet[7]); - __m512 T8 = _mm512_unpacklo_ps(kernel.packet[8], kernel.packet[9]); - __m512 T9 = _mm512_unpackhi_ps(kernel.packet[8], kernel.packet[9]); - __m512 T10 = _mm512_unpacklo_ps(kernel.packet[10], kernel.packet[11]); - __m512 T11 = _mm512_unpackhi_ps(kernel.packet[10], kernel.packet[11]); - __m512 T12 = _mm512_unpacklo_ps(kernel.packet[12], kernel.packet[13]); - __m512 T13 = _mm512_unpackhi_ps(kernel.packet[12], kernel.packet[13]); - __m512 T14 = _mm512_unpacklo_ps(kernel.packet[14], kernel.packet[15]); - __m512 T15 = _mm512_unpackhi_ps(kernel.packet[14], kernel.packet[15]); - __m512 S0 = _mm512_shuffle_ps(T0, T2, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S1 = _mm512_shuffle_ps(T0, T2, _MM_SHUFFLE(3, 2, 3, 2)); - __m512 S2 = _mm512_shuffle_ps(T1, T3, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S3 = _mm512_shuffle_ps(T1, T3, _MM_SHUFFLE(3, 2, 3, 2)); - __m512 S4 = _mm512_shuffle_ps(T4, T6, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S5 = _mm512_shuffle_ps(T4, T6, _MM_SHUFFLE(3, 2, 3, 2)); - __m512 S6 = _mm512_shuffle_ps(T5, T7, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S7 = _mm512_shuffle_ps(T5, T7, _MM_SHUFFLE(3, 2, 3, 2)); - __m512 S8 = _mm512_shuffle_ps(T8, T10, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S9 = _mm512_shuffle_ps(T8, T10, _MM_SHUFFLE(3, 2, 3, 2)); - __m512 S10 = _mm512_shuffle_ps(T9, T11, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S11 = _mm512_shuffle_ps(T9, T11, _MM_SHUFFLE(3, 2, 3, 2)); - __m512 S12 = _mm512_shuffle_ps(T12, T14, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S13 = _mm512_shuffle_ps(T12, T14, _MM_SHUFFLE(3, 2, 3, 2)); - __m512 S14 = _mm512_shuffle_ps(T13, T15, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S15 = _mm512_shuffle_ps(T13, T15, _MM_SHUFFLE(3, 2, 3, 2)); - - EIGEN_EXTRACT_8f_FROM_16f(S0, S0); - EIGEN_EXTRACT_8f_FROM_16f(S1, S1); - EIGEN_EXTRACT_8f_FROM_16f(S2, S2); - EIGEN_EXTRACT_8f_FROM_16f(S3, S3); - EIGEN_EXTRACT_8f_FROM_16f(S4, S4); - EIGEN_EXTRACT_8f_FROM_16f(S5, S5); - EIGEN_EXTRACT_8f_FROM_16f(S6, S6); - EIGEN_EXTRACT_8f_FROM_16f(S7, S7); - EIGEN_EXTRACT_8f_FROM_16f(S8, S8); - EIGEN_EXTRACT_8f_FROM_16f(S9, S9); - EIGEN_EXTRACT_8f_FROM_16f(S10, S10); - EIGEN_EXTRACT_8f_FROM_16f(S11, S11); - EIGEN_EXTRACT_8f_FROM_16f(S12, S12); - EIGEN_EXTRACT_8f_FROM_16f(S13, S13); - EIGEN_EXTRACT_8f_FROM_16f(S14, S14); - EIGEN_EXTRACT_8f_FROM_16f(S15, S15); - - PacketBlock<Packet8f, 32> tmp; - - tmp.packet[0] = _mm256_permute2f128_ps(S0_0, S4_0, 0x20); - tmp.packet[1] = _mm256_permute2f128_ps(S1_0, S5_0, 0x20); - tmp.packet[2] = _mm256_permute2f128_ps(S2_0, S6_0, 0x20); - tmp.packet[3] = _mm256_permute2f128_ps(S3_0, S7_0, 0x20); - tmp.packet[4] = _mm256_permute2f128_ps(S0_0, S4_0, 0x31); - tmp.packet[5] = _mm256_permute2f128_ps(S1_0, S5_0, 0x31); - tmp.packet[6] = _mm256_permute2f128_ps(S2_0, S6_0, 0x31); - tmp.packet[7] = _mm256_permute2f128_ps(S3_0, S7_0, 0x31); - - tmp.packet[8] = _mm256_permute2f128_ps(S0_1, S4_1, 0x20); - tmp.packet[9] = _mm256_permute2f128_ps(S1_1, S5_1, 0x20); - tmp.packet[10] = _mm256_permute2f128_ps(S2_1, S6_1, 0x20); - tmp.packet[11] = _mm256_permute2f128_ps(S3_1, S7_1, 0x20); - tmp.packet[12] = _mm256_permute2f128_ps(S0_1, S4_1, 0x31); - tmp.packet[13] = _mm256_permute2f128_ps(S1_1, S5_1, 0x31); - tmp.packet[14] = _mm256_permute2f128_ps(S2_1, S6_1, 0x31); - tmp.packet[15] = _mm256_permute2f128_ps(S3_1, S7_1, 0x31); - - // Second set of _m256 outputs - tmp.packet[16] = _mm256_permute2f128_ps(S8_0, S12_0, 0x20); - tmp.packet[17] = _mm256_permute2f128_ps(S9_0, S13_0, 0x20); - tmp.packet[18] = _mm256_permute2f128_ps(S10_0, S14_0, 0x20); - tmp.packet[19] = _mm256_permute2f128_ps(S11_0, S15_0, 0x20); - tmp.packet[20] = _mm256_permute2f128_ps(S8_0, S12_0, 0x31); - tmp.packet[21] = _mm256_permute2f128_ps(S9_0, S13_0, 0x31); - tmp.packet[22] = _mm256_permute2f128_ps(S10_0, S14_0, 0x31); - tmp.packet[23] = _mm256_permute2f128_ps(S11_0, S15_0, 0x31); - - tmp.packet[24] = _mm256_permute2f128_ps(S8_1, S12_1, 0x20); - tmp.packet[25] = _mm256_permute2f128_ps(S9_1, S13_1, 0x20); - tmp.packet[26] = _mm256_permute2f128_ps(S10_1, S14_1, 0x20); - tmp.packet[27] = _mm256_permute2f128_ps(S11_1, S15_1, 0x20); - tmp.packet[28] = _mm256_permute2f128_ps(S8_1, S12_1, 0x31); - tmp.packet[29] = _mm256_permute2f128_ps(S9_1, S13_1, 0x31); - tmp.packet[30] = _mm256_permute2f128_ps(S10_1, S14_1, 0x31); - tmp.packet[31] = _mm256_permute2f128_ps(S11_1, S15_1, 0x31); - - // Pack them into the output - PACK_OUTPUT(kernel.packet, tmp.packet, 0, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 1, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 2, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 3, 16); - - PACK_OUTPUT(kernel.packet, tmp.packet, 4, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 5, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 6, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 7, 16); - - PACK_OUTPUT(kernel.packet, tmp.packet, 8, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 9, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 10, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 11, 16); - - PACK_OUTPUT(kernel.packet, tmp.packet, 12, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 13, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 14, 16); - PACK_OUTPUT(kernel.packet, tmp.packet, 15, 16); -} -#define PACK_OUTPUT_2(OUTPUT, INPUT, INDEX, STRIDE) \ - EIGEN_INSERT_8f_INTO_16f(OUTPUT[INDEX], INPUT[2 * INDEX], \ - INPUT[2 * INDEX + STRIDE]); - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet16f, 4>& kernel) { - __m512 T0 = _mm512_unpacklo_ps(kernel.packet[0], kernel.packet[1]); - __m512 T1 = _mm512_unpackhi_ps(kernel.packet[0], kernel.packet[1]); - __m512 T2 = _mm512_unpacklo_ps(kernel.packet[2], kernel.packet[3]); - __m512 T3 = _mm512_unpackhi_ps(kernel.packet[2], kernel.packet[3]); - - __m512 S0 = _mm512_shuffle_ps(T0, T2, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S1 = _mm512_shuffle_ps(T0, T2, _MM_SHUFFLE(3, 2, 3, 2)); - __m512 S2 = _mm512_shuffle_ps(T1, T3, _MM_SHUFFLE(1, 0, 1, 0)); - __m512 S3 = _mm512_shuffle_ps(T1, T3, _MM_SHUFFLE(3, 2, 3, 2)); - - EIGEN_EXTRACT_8f_FROM_16f(S0, S0); - EIGEN_EXTRACT_8f_FROM_16f(S1, S1); - EIGEN_EXTRACT_8f_FROM_16f(S2, S2); - EIGEN_EXTRACT_8f_FROM_16f(S3, S3); - - PacketBlock<Packet8f, 8> tmp; - - tmp.packet[0] = _mm256_permute2f128_ps(S0_0, S1_0, 0x20); - tmp.packet[1] = _mm256_permute2f128_ps(S2_0, S3_0, 0x20); - tmp.packet[2] = _mm256_permute2f128_ps(S0_0, S1_0, 0x31); - tmp.packet[3] = _mm256_permute2f128_ps(S2_0, S3_0, 0x31); - - tmp.packet[4] = _mm256_permute2f128_ps(S0_1, S1_1, 0x20); - tmp.packet[5] = _mm256_permute2f128_ps(S2_1, S3_1, 0x20); - tmp.packet[6] = _mm256_permute2f128_ps(S0_1, S1_1, 0x31); - tmp.packet[7] = _mm256_permute2f128_ps(S2_1, S3_1, 0x31); - - PACK_OUTPUT_2(kernel.packet, tmp.packet, 0, 1); - PACK_OUTPUT_2(kernel.packet, tmp.packet, 1, 1); - PACK_OUTPUT_2(kernel.packet, tmp.packet, 2, 1); - PACK_OUTPUT_2(kernel.packet, tmp.packet, 3, 1); -} - -#define PACK_OUTPUT_SQ_D(OUTPUT, INPUT, INDEX, STRIDE) \ - OUTPUT[INDEX] = _mm512_insertf64x4(OUTPUT[INDEX], INPUT[INDEX], 0); \ - OUTPUT[INDEX] = _mm512_insertf64x4(OUTPUT[INDEX], INPUT[INDEX + STRIDE], 1); - -#define PACK_OUTPUT_D(OUTPUT, INPUT, INDEX, STRIDE) \ - OUTPUT[INDEX] = _mm512_insertf64x4(OUTPUT[INDEX], INPUT[(2 * INDEX)], 0); \ - OUTPUT[INDEX] = \ - _mm512_insertf64x4(OUTPUT[INDEX], INPUT[(2 * INDEX) + STRIDE], 1); - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet8d, 4>& kernel) { - __m512d T0 = _mm512_shuffle_pd(kernel.packet[0], kernel.packet[1], 0); - __m512d T1 = _mm512_shuffle_pd(kernel.packet[0], kernel.packet[1], 0xff); - __m512d T2 = _mm512_shuffle_pd(kernel.packet[2], kernel.packet[3], 0); - __m512d T3 = _mm512_shuffle_pd(kernel.packet[2], kernel.packet[3], 0xff); - - PacketBlock<Packet4d, 8> tmp; - - tmp.packet[0] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 0), - _mm512_extractf64x4_pd(T2, 0), 0x20); - tmp.packet[1] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 0), - _mm512_extractf64x4_pd(T3, 0), 0x20); - tmp.packet[2] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 0), - _mm512_extractf64x4_pd(T2, 0), 0x31); - tmp.packet[3] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 0), - _mm512_extractf64x4_pd(T3, 0), 0x31); - - tmp.packet[4] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 1), - _mm512_extractf64x4_pd(T2, 1), 0x20); - tmp.packet[5] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 1), - _mm512_extractf64x4_pd(T3, 1), 0x20); - tmp.packet[6] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 1), - _mm512_extractf64x4_pd(T2, 1), 0x31); - tmp.packet[7] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 1), - _mm512_extractf64x4_pd(T3, 1), 0x31); - - PACK_OUTPUT_D(kernel.packet, tmp.packet, 0, 1); - PACK_OUTPUT_D(kernel.packet, tmp.packet, 1, 1); - PACK_OUTPUT_D(kernel.packet, tmp.packet, 2, 1); - PACK_OUTPUT_D(kernel.packet, tmp.packet, 3, 1); -} - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet8d, 8>& kernel) { - __m512d T0 = _mm512_unpacklo_pd(kernel.packet[0], kernel.packet[1]); - __m512d T1 = _mm512_unpackhi_pd(kernel.packet[0], kernel.packet[1]); - __m512d T2 = _mm512_unpacklo_pd(kernel.packet[2], kernel.packet[3]); - __m512d T3 = _mm512_unpackhi_pd(kernel.packet[2], kernel.packet[3]); - __m512d T4 = _mm512_unpacklo_pd(kernel.packet[4], kernel.packet[5]); - __m512d T5 = _mm512_unpackhi_pd(kernel.packet[4], kernel.packet[5]); - __m512d T6 = _mm512_unpacklo_pd(kernel.packet[6], kernel.packet[7]); - __m512d T7 = _mm512_unpackhi_pd(kernel.packet[6], kernel.packet[7]); - - PacketBlock<Packet4d, 16> tmp; - - tmp.packet[0] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 0), - _mm512_extractf64x4_pd(T2, 0), 0x20); - tmp.packet[1] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 0), - _mm512_extractf64x4_pd(T3, 0), 0x20); - tmp.packet[2] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 0), - _mm512_extractf64x4_pd(T2, 0), 0x31); - tmp.packet[3] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 0), - _mm512_extractf64x4_pd(T3, 0), 0x31); - - tmp.packet[4] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 1), - _mm512_extractf64x4_pd(T2, 1), 0x20); - tmp.packet[5] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 1), - _mm512_extractf64x4_pd(T3, 1), 0x20); - tmp.packet[6] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 1), - _mm512_extractf64x4_pd(T2, 1), 0x31); - tmp.packet[7] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 1), - _mm512_extractf64x4_pd(T3, 1), 0x31); - - tmp.packet[8] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T4, 0), - _mm512_extractf64x4_pd(T6, 0), 0x20); - tmp.packet[9] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T5, 0), - _mm512_extractf64x4_pd(T7, 0), 0x20); - tmp.packet[10] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T4, 0), - _mm512_extractf64x4_pd(T6, 0), 0x31); - tmp.packet[11] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T5, 0), - _mm512_extractf64x4_pd(T7, 0), 0x31); - - tmp.packet[12] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T4, 1), - _mm512_extractf64x4_pd(T6, 1), 0x20); - tmp.packet[13] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T5, 1), - _mm512_extractf64x4_pd(T7, 1), 0x20); - tmp.packet[14] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T4, 1), - _mm512_extractf64x4_pd(T6, 1), 0x31); - tmp.packet[15] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T5, 1), - _mm512_extractf64x4_pd(T7, 1), 0x31); - - PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 0, 8); - PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 1, 8); - PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 2, 8); - PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 3, 8); - - PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 4, 8); - PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 5, 8); - PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 6, 8); - PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 7, 8); -} -template <> -EIGEN_STRONG_INLINE Packet16f pblend(const Selector<16>& /*ifPacket*/, - const Packet16f& /*thenPacket*/, - const Packet16f& /*elsePacket*/) { - assert(false && "To be implemented"); - return Packet16f(); -} -template <> -EIGEN_STRONG_INLINE Packet8d pblend(const Selector<8>& ifPacket, - const Packet8d& thenPacket, - const Packet8d& elsePacket) { - __mmask8 m = (ifPacket.select[0] ) - | (ifPacket.select[1]<<1) - | (ifPacket.select[2]<<2) - | (ifPacket.select[3]<<3) - | (ifPacket.select[4]<<4) - | (ifPacket.select[5]<<5) - | (ifPacket.select[6]<<6) - | (ifPacket.select[7]<<7); - return _mm512_mask_blend_pd(m, elsePacket, thenPacket); -} - -template<> EIGEN_STRONG_INLINE Packet16f pinsertfirst(const Packet16f& a, float b) -{ - return _mm512_mask_broadcastss_ps(a, (1), _mm_load_ss(&b)); -} - -template<> EIGEN_STRONG_INLINE Packet8d pinsertfirst(const Packet8d& a, double b) -{ - return _mm512_mask_broadcastsd_pd(a, (1), _mm_load_sd(&b)); -} - -template<> EIGEN_STRONG_INLINE Packet16f pinsertlast(const Packet16f& a, float b) -{ - return _mm512_mask_broadcastss_ps(a, (1<<15), _mm_load_ss(&b)); -} - -template<> EIGEN_STRONG_INLINE Packet8d pinsertlast(const Packet8d& a, double b) -{ - return _mm512_mask_broadcastsd_pd(a, (1<<7), _mm_load_sd(&b)); -} - -template<> EIGEN_STRONG_INLINE Packet16i pcast<Packet16f, Packet16i>(const Packet16f& a) { - return _mm512_cvttps_epi32(a); -} - -template<> EIGEN_STRONG_INLINE Packet16f pcast<Packet16i, Packet16f>(const Packet16i& a) { - return _mm512_cvtepi32_ps(a); -} - -template<> EIGEN_STRONG_INLINE Packet16i preinterpret<Packet16i,Packet16f>(const Packet16f& a) { - return _mm512_castps_si512(a); -} - -template<> EIGEN_STRONG_INLINE Packet16f preinterpret<Packet16f,Packet16i>(const Packet16i& a) { - return _mm512_castsi512_ps(a); -} - - -// Packet math for Eigen::half -template<> EIGEN_STRONG_INLINE Packet16h pset1<Packet16h>(const Eigen::half& from) { - Packet16h result; - result.x = _mm256_set1_epi16(from.x); - return result; -} - -template<> EIGEN_STRONG_INLINE Eigen::half pfirst<Packet16h>(const Packet16h& from) { - return half_impl::raw_uint16_to_half(static_cast<unsigned short>(_mm256_extract_epi16(from.x, 0))); -} - -template<> EIGEN_STRONG_INLINE Packet16h pload<Packet16h>(const Eigen::half* from) { - Packet16h result; - result.x = _mm256_load_si256(reinterpret_cast<const __m256i*>(from)); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet16h ploadu<Packet16h>(const Eigen::half* from) { - Packet16h result; - result.x = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(from)); - return result; -} - -template<> EIGEN_STRONG_INLINE void pstore<half>(Eigen::half* to, const Packet16h& from) { - // (void*) -> workaround clang warning: - // cast from 'Eigen::half *' to '__m256i *' increases required alignment from 2 to 32 - _mm256_store_si256((__m256i*)(void*)to, from.x); -} - -template<> EIGEN_STRONG_INLINE void pstoreu<half>(Eigen::half* to, const Packet16h& from) { - // (void*) -> workaround clang warning: - // cast from 'Eigen::half *' to '__m256i *' increases required alignment from 2 to 32 - _mm256_storeu_si256((__m256i*)(void*)to, from.x); -} - -template<> EIGEN_STRONG_INLINE Packet16h -ploaddup<Packet16h>(const Eigen::half* from) { - Packet16h result; - unsigned short a = from[0].x; - unsigned short b = from[1].x; - unsigned short c = from[2].x; - unsigned short d = from[3].x; - unsigned short e = from[4].x; - unsigned short f = from[5].x; - unsigned short g = from[6].x; - unsigned short h = from[7].x; - result.x = _mm256_set_epi16(h, h, g, g, f, f, e, e, d, d, c, c, b, b, a, a); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet16h -ploadquad(const Eigen::half* from) { - Packet16h result; - unsigned short a = from[0].x; - unsigned short b = from[1].x; - unsigned short c = from[2].x; - unsigned short d = from[3].x; - result.x = _mm256_set_epi16(d, d, d, d, c, c, c, c, b, b, b, b, a, a, a, a); - return result; -} - -EIGEN_STRONG_INLINE Packet16f half2float(const Packet16h& a) { -#ifdef EIGEN_HAS_FP16_C - return _mm512_cvtph_ps(a.x); -#else - EIGEN_ALIGN64 half aux[16]; - pstore(aux, a); - float f0(aux[0]); - float f1(aux[1]); - float f2(aux[2]); - float f3(aux[3]); - float f4(aux[4]); - float f5(aux[5]); - float f6(aux[6]); - float f7(aux[7]); - float f8(aux[8]); - float f9(aux[9]); - float fa(aux[10]); - float fb(aux[11]); - float fc(aux[12]); - float fd(aux[13]); - float fe(aux[14]); - float ff(aux[15]); - - return _mm512_set_ps( - ff, fe, fd, fc, fb, fa, f9, f8, f7, f6, f5, f4, f3, f2, f1, f0); -#endif -} - -EIGEN_STRONG_INLINE Packet16h float2half(const Packet16f& a) { -#ifdef EIGEN_HAS_FP16_C - Packet16h result; - result.x = _mm512_cvtps_ph(a, _MM_FROUND_TO_NEAREST_INT|_MM_FROUND_NO_EXC); - return result; -#else - EIGEN_ALIGN64 float aux[16]; - pstore(aux, a); - half h0(aux[0]); - half h1(aux[1]); - half h2(aux[2]); - half h3(aux[3]); - half h4(aux[4]); - half h5(aux[5]); - half h6(aux[6]); - half h7(aux[7]); - half h8(aux[8]); - half h9(aux[9]); - half ha(aux[10]); - half hb(aux[11]); - half hc(aux[12]); - half hd(aux[13]); - half he(aux[14]); - half hf(aux[15]); - - Packet16h result; - result.x = _mm256_set_epi16( - hf.x, he.x, hd.x, hc.x, hb.x, ha.x, h9.x, h8.x, - h7.x, h6.x, h5.x, h4.x, h3.x, h2.x, h1.x, h0.x); - return result; -#endif -} - -template<> EIGEN_STRONG_INLINE Packet16h pnot(const Packet16h& a) { - Packet16h r; r.x = _mm256_xor_si256(a.x, pcmp_eq(a.x, a.x)); return r; -} - -template<> EIGEN_STRONG_INLINE Packet16h ptrue(const Packet16h& a) { - Packet16h r; r.x = Packet8i(ptrue(a.x)); return r; -} - -template<> EIGEN_STRONG_INLINE Packet16h por(const Packet16h& a,const Packet16h& b) { - // in some cases Packet8i is a wrapper around __m256i, so we need to - // cast to Packet8i to call the correct overload. - Packet16h r; r.x = por(Packet8i(a.x),Packet8i(b.x)); return r; -} -template<> EIGEN_STRONG_INLINE Packet16h pxor(const Packet16h& a,const Packet16h& b) { - Packet16h r; r.x = pxor(Packet8i(a.x),Packet8i(b.x)); return r; -} -template<> EIGEN_STRONG_INLINE Packet16h pand(const Packet16h& a,const Packet16h& b) { - Packet16h r; r.x = pand(Packet8i(a.x),Packet8i(b.x)); return r; -} -template<> EIGEN_STRONG_INLINE Packet16h pandnot(const Packet16h& a,const Packet16h& b) { - Packet16h r; r.x = pandnot(Packet8i(a.x),Packet8i(b.x)); return r; -} - -template<> EIGEN_STRONG_INLINE Packet16h pselect(const Packet16h& mask, const Packet16h& a, const Packet16h& b) { - Packet16h r; r.x = _mm256_blendv_epi8(b.x, a.x, mask.x); return r; -} - -template<> EIGEN_STRONG_INLINE Packet16h pcmp_eq(const Packet16h& a,const Packet16h& b) { - Packet16f af = half2float(a); - Packet16f bf = half2float(b); - Packet16f rf = pcmp_eq(af, bf); - // Pack the 32-bit flags into 16-bits flags. - __m256i lo = _mm256_castps_si256(extract256<0>(rf)); - __m256i hi = _mm256_castps_si256(extract256<1>(rf)); - __m128i result_lo = _mm_packs_epi32(_mm256_extractf128_si256(lo, 0), - _mm256_extractf128_si256(lo, 1)); - __m128i result_hi = _mm_packs_epi32(_mm256_extractf128_si256(hi, 0), - _mm256_extractf128_si256(hi, 1)); - Packet16h result; result.x = _mm256_insertf128_si256(_mm256_castsi128_si256(result_lo), result_hi, 1); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet16h pnegate(const Packet16h& a) { - Packet16h sign_mask; sign_mask.x = _mm256_set1_epi16(static_cast<unsigned short>(0x8000)); - Packet16h result; result.x = _mm256_xor_si256(a.x, sign_mask.x); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet16h padd<Packet16h>(const Packet16h& a, const Packet16h& b) { - Packet16f af = half2float(a); - Packet16f bf = half2float(b); - Packet16f rf = padd(af, bf); - return float2half(rf); -} - -template<> EIGEN_STRONG_INLINE Packet16h psub<Packet16h>(const Packet16h& a, const Packet16h& b) { - Packet16f af = half2float(a); - Packet16f bf = half2float(b); - Packet16f rf = psub(af, bf); - return float2half(rf); -} - -template<> EIGEN_STRONG_INLINE Packet16h pmul<Packet16h>(const Packet16h& a, const Packet16h& b) { - Packet16f af = half2float(a); - Packet16f bf = half2float(b); - Packet16f rf = pmul(af, bf); - return float2half(rf); -} - -template<> EIGEN_STRONG_INLINE Packet16h pdiv<Packet16h>(const Packet16h& a, const Packet16h& b) { - Packet16f af = half2float(a); - Packet16f bf = half2float(b); - Packet16f rf = pdiv(af, bf); - return float2half(rf); -} - -template<> EIGEN_STRONG_INLINE half predux<Packet16h>(const Packet16h& from) { - Packet16f from_float = half2float(from); - return half(predux(from_float)); -} - -template<> EIGEN_STRONG_INLINE half predux_mul<Packet16h>(const Packet16h& from) { - Packet16f from_float = half2float(from); - return half(predux_mul(from_float)); -} - -template<> EIGEN_STRONG_INLINE Packet16h preduxp<Packet16h>(const Packet16h* p) { - Packet16f pf[16]; - pf[0] = half2float(p[0]); - pf[1] = half2float(p[1]); - pf[2] = half2float(p[2]); - pf[3] = half2float(p[3]); - pf[4] = half2float(p[4]); - pf[5] = half2float(p[5]); - pf[6] = half2float(p[6]); - pf[7] = half2float(p[7]); - pf[8] = half2float(p[8]); - pf[9] = half2float(p[9]); - pf[10] = half2float(p[10]); - pf[11] = half2float(p[11]); - pf[12] = half2float(p[12]); - pf[13] = half2float(p[13]); - pf[14] = half2float(p[14]); - pf[15] = half2float(p[15]); - Packet16f reduced = preduxp<Packet16f>(pf); - return float2half(reduced); -} - -template<> EIGEN_STRONG_INLINE Packet16h preverse(const Packet16h& a) -{ - __m128i m = _mm_setr_epi8(14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1); - Packet16h res; - res.x = _mm256_insertf128_si256( - _mm256_castsi128_si256(_mm_shuffle_epi8(_mm256_extractf128_si256(a.x,1),m)), - _mm_shuffle_epi8(_mm256_extractf128_si256(a.x,0),m), 1); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet16h pinsertfirst(const Packet16h& a, Eigen::half b) -{ - Packet16h res; - res.x = _mm256_insert_epi16(a.x,b.x,0); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet16h pinsertlast(const Packet16h& a, Eigen::half b) -{ - Packet16h res; - res.x = _mm256_insert_epi16(a.x,b.x,15); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet16h pgather<Eigen::half, Packet16h>(const Eigen::half* from, Index stride) -{ - Packet16h result; - result.x = _mm256_set_epi16( - from[15*stride].x, from[14*stride].x, from[13*stride].x, from[12*stride].x, - from[11*stride].x, from[10*stride].x, from[9*stride].x, from[8*stride].x, - from[7*stride].x, from[6*stride].x, from[5*stride].x, from[4*stride].x, - from[3*stride].x, from[2*stride].x, from[1*stride].x, from[0*stride].x); - return result; -} - -template<> EIGEN_STRONG_INLINE void pscatter<half, Packet16h>(half* to, const Packet16h& from, Index stride) -{ - EIGEN_ALIGN64 half aux[16]; - pstore(aux, from); - to[stride*0].x = aux[0].x; - to[stride*1].x = aux[1].x; - to[stride*2].x = aux[2].x; - to[stride*3].x = aux[3].x; - to[stride*4].x = aux[4].x; - to[stride*5].x = aux[5].x; - to[stride*6].x = aux[6].x; - to[stride*7].x = aux[7].x; - to[stride*8].x = aux[8].x; - to[stride*9].x = aux[9].x; - to[stride*10].x = aux[10].x; - to[stride*11].x = aux[11].x; - to[stride*12].x = aux[12].x; - to[stride*13].x = aux[13].x; - to[stride*14].x = aux[14].x; - to[stride*15].x = aux[15].x; -} - -EIGEN_STRONG_INLINE void -ptranspose(PacketBlock<Packet16h,16>& kernel) { - __m256i a = kernel.packet[0].x; - __m256i b = kernel.packet[1].x; - __m256i c = kernel.packet[2].x; - __m256i d = kernel.packet[3].x; - __m256i e = kernel.packet[4].x; - __m256i f = kernel.packet[5].x; - __m256i g = kernel.packet[6].x; - __m256i h = kernel.packet[7].x; - __m256i i = kernel.packet[8].x; - __m256i j = kernel.packet[9].x; - __m256i k = kernel.packet[10].x; - __m256i l = kernel.packet[11].x; - __m256i m = kernel.packet[12].x; - __m256i n = kernel.packet[13].x; - __m256i o = kernel.packet[14].x; - __m256i p = kernel.packet[15].x; - - __m256i ab_07 = _mm256_unpacklo_epi16(a, b); - __m256i cd_07 = _mm256_unpacklo_epi16(c, d); - __m256i ef_07 = _mm256_unpacklo_epi16(e, f); - __m256i gh_07 = _mm256_unpacklo_epi16(g, h); - __m256i ij_07 = _mm256_unpacklo_epi16(i, j); - __m256i kl_07 = _mm256_unpacklo_epi16(k, l); - __m256i mn_07 = _mm256_unpacklo_epi16(m, n); - __m256i op_07 = _mm256_unpacklo_epi16(o, p); - - __m256i ab_8f = _mm256_unpackhi_epi16(a, b); - __m256i cd_8f = _mm256_unpackhi_epi16(c, d); - __m256i ef_8f = _mm256_unpackhi_epi16(e, f); - __m256i gh_8f = _mm256_unpackhi_epi16(g, h); - __m256i ij_8f = _mm256_unpackhi_epi16(i, j); - __m256i kl_8f = _mm256_unpackhi_epi16(k, l); - __m256i mn_8f = _mm256_unpackhi_epi16(m, n); - __m256i op_8f = _mm256_unpackhi_epi16(o, p); - - __m256i abcd_03 = _mm256_unpacklo_epi32(ab_07, cd_07); - __m256i abcd_47 = _mm256_unpackhi_epi32(ab_07, cd_07); - __m256i efgh_03 = _mm256_unpacklo_epi32(ef_07, gh_07); - __m256i efgh_47 = _mm256_unpackhi_epi32(ef_07, gh_07); - __m256i ijkl_03 = _mm256_unpacklo_epi32(ij_07, kl_07); - __m256i ijkl_47 = _mm256_unpackhi_epi32(ij_07, kl_07); - __m256i mnop_03 = _mm256_unpacklo_epi32(mn_07, op_07); - __m256i mnop_47 = _mm256_unpackhi_epi32(mn_07, op_07); - - __m256i abcd_8b = _mm256_unpacklo_epi32(ab_8f, cd_8f); - __m256i abcd_cf = _mm256_unpackhi_epi32(ab_8f, cd_8f); - __m256i efgh_8b = _mm256_unpacklo_epi32(ef_8f, gh_8f); - __m256i efgh_cf = _mm256_unpackhi_epi32(ef_8f, gh_8f); - __m256i ijkl_8b = _mm256_unpacklo_epi32(ij_8f, kl_8f); - __m256i ijkl_cf = _mm256_unpackhi_epi32(ij_8f, kl_8f); - __m256i mnop_8b = _mm256_unpacklo_epi32(mn_8f, op_8f); - __m256i mnop_cf = _mm256_unpackhi_epi32(mn_8f, op_8f); - - __m256i abcdefgh_01 = _mm256_unpacklo_epi64(abcd_03, efgh_03); - __m256i abcdefgh_23 = _mm256_unpackhi_epi64(abcd_03, efgh_03); - __m256i ijklmnop_01 = _mm256_unpacklo_epi64(ijkl_03, mnop_03); - __m256i ijklmnop_23 = _mm256_unpackhi_epi64(ijkl_03, mnop_03); - __m256i abcdefgh_45 = _mm256_unpacklo_epi64(abcd_47, efgh_47); - __m256i abcdefgh_67 = _mm256_unpackhi_epi64(abcd_47, efgh_47); - __m256i ijklmnop_45 = _mm256_unpacklo_epi64(ijkl_47, mnop_47); - __m256i ijklmnop_67 = _mm256_unpackhi_epi64(ijkl_47, mnop_47); - __m256i abcdefgh_89 = _mm256_unpacklo_epi64(abcd_8b, efgh_8b); - __m256i abcdefgh_ab = _mm256_unpackhi_epi64(abcd_8b, efgh_8b); - __m256i ijklmnop_89 = _mm256_unpacklo_epi64(ijkl_8b, mnop_8b); - __m256i ijklmnop_ab = _mm256_unpackhi_epi64(ijkl_8b, mnop_8b); - __m256i abcdefgh_cd = _mm256_unpacklo_epi64(abcd_cf, efgh_cf); - __m256i abcdefgh_ef = _mm256_unpackhi_epi64(abcd_cf, efgh_cf); - __m256i ijklmnop_cd = _mm256_unpacklo_epi64(ijkl_cf, mnop_cf); - __m256i ijklmnop_ef = _mm256_unpackhi_epi64(ijkl_cf, mnop_cf); - - // NOTE: no unpacklo/hi instr in this case, so using permute instr. - __m256i a_p_0 = _mm256_permute2x128_si256(abcdefgh_01, ijklmnop_01, 0x20); - __m256i a_p_1 = _mm256_permute2x128_si256(abcdefgh_23, ijklmnop_23, 0x20); - __m256i a_p_2 = _mm256_permute2x128_si256(abcdefgh_45, ijklmnop_45, 0x20); - __m256i a_p_3 = _mm256_permute2x128_si256(abcdefgh_67, ijklmnop_67, 0x20); - __m256i a_p_4 = _mm256_permute2x128_si256(abcdefgh_89, ijklmnop_89, 0x20); - __m256i a_p_5 = _mm256_permute2x128_si256(abcdefgh_ab, ijklmnop_ab, 0x20); - __m256i a_p_6 = _mm256_permute2x128_si256(abcdefgh_cd, ijklmnop_cd, 0x20); - __m256i a_p_7 = _mm256_permute2x128_si256(abcdefgh_ef, ijklmnop_ef, 0x20); - __m256i a_p_8 = _mm256_permute2x128_si256(abcdefgh_01, ijklmnop_01, 0x31); - __m256i a_p_9 = _mm256_permute2x128_si256(abcdefgh_23, ijklmnop_23, 0x31); - __m256i a_p_a = _mm256_permute2x128_si256(abcdefgh_45, ijklmnop_45, 0x31); - __m256i a_p_b = _mm256_permute2x128_si256(abcdefgh_67, ijklmnop_67, 0x31); - __m256i a_p_c = _mm256_permute2x128_si256(abcdefgh_89, ijklmnop_89, 0x31); - __m256i a_p_d = _mm256_permute2x128_si256(abcdefgh_ab, ijklmnop_ab, 0x31); - __m256i a_p_e = _mm256_permute2x128_si256(abcdefgh_cd, ijklmnop_cd, 0x31); - __m256i a_p_f = _mm256_permute2x128_si256(abcdefgh_ef, ijklmnop_ef, 0x31); - - kernel.packet[0].x = a_p_0; - kernel.packet[1].x = a_p_1; - kernel.packet[2].x = a_p_2; - kernel.packet[3].x = a_p_3; - kernel.packet[4].x = a_p_4; - kernel.packet[5].x = a_p_5; - kernel.packet[6].x = a_p_6; - kernel.packet[7].x = a_p_7; - kernel.packet[8].x = a_p_8; - kernel.packet[9].x = a_p_9; - kernel.packet[10].x = a_p_a; - kernel.packet[11].x = a_p_b; - kernel.packet[12].x = a_p_c; - kernel.packet[13].x = a_p_d; - kernel.packet[14].x = a_p_e; - kernel.packet[15].x = a_p_f; -} - -EIGEN_STRONG_INLINE void -ptranspose(PacketBlock<Packet16h,8>& kernel) { - EIGEN_ALIGN64 half in[8][16]; - pstore<half>(in[0], kernel.packet[0]); - pstore<half>(in[1], kernel.packet[1]); - pstore<half>(in[2], kernel.packet[2]); - pstore<half>(in[3], kernel.packet[3]); - pstore<half>(in[4], kernel.packet[4]); - pstore<half>(in[5], kernel.packet[5]); - pstore<half>(in[6], kernel.packet[6]); - pstore<half>(in[7], kernel.packet[7]); - - EIGEN_ALIGN64 half out[8][16]; - - for (int i = 0; i < 8; ++i) { - for (int j = 0; j < 8; ++j) { - out[i][j] = in[j][2*i]; - } - for (int j = 0; j < 8; ++j) { - out[i][j+8] = in[j][2*i+1]; - } - } - - kernel.packet[0] = pload<Packet16h>(out[0]); - kernel.packet[1] = pload<Packet16h>(out[1]); - kernel.packet[2] = pload<Packet16h>(out[2]); - kernel.packet[3] = pload<Packet16h>(out[3]); - kernel.packet[4] = pload<Packet16h>(out[4]); - kernel.packet[5] = pload<Packet16h>(out[5]); - kernel.packet[6] = pload<Packet16h>(out[6]); - kernel.packet[7] = pload<Packet16h>(out[7]); -} - -EIGEN_STRONG_INLINE void -ptranspose(PacketBlock<Packet16h,4>& kernel) { - EIGEN_ALIGN64 half in[4][16]; - pstore<half>(in[0], kernel.packet[0]); - pstore<half>(in[1], kernel.packet[1]); - pstore<half>(in[2], kernel.packet[2]); - pstore<half>(in[3], kernel.packet[3]); - - EIGEN_ALIGN64 half out[4][16]; - - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { - out[i][j] = in[j][4*i]; - } - for (int j = 0; j < 4; ++j) { - out[i][j+4] = in[j][4*i+1]; - } - for (int j = 0; j < 4; ++j) { - out[i][j+8] = in[j][4*i+2]; - } - for (int j = 0; j < 4; ++j) { - out[i][j+12] = in[j][4*i+3]; - } - } - - kernel.packet[0] = pload<Packet16h>(out[0]); - kernel.packet[1] = pload<Packet16h>(out[1]); - kernel.packet[2] = pload<Packet16h>(out[2]); - kernel.packet[3] = pload<Packet16h>(out[3]); -} - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PACKET_MATH_AVX512_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/TypeCasting.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/TypeCasting.h deleted file mode 100644 index a8217694..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AVX512/TypeCasting.h +++ /dev/null @@ -1,47 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2019 Rasmus Munk Larsen <rmlarsen@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TYPE_CASTING_AVX512_H -#define EIGEN_TYPE_CASTING_AVX512_H - -namespace Eigen { - -namespace internal { - -template <> -struct type_casting_traits<half, float> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template<> EIGEN_STRONG_INLINE Packet16f pcast<Packet16h, Packet16f>(const Packet16h& a) { - return half2float(a); -} - -template <> -struct type_casting_traits<float, half> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template<> EIGEN_STRONG_INLINE Packet16h pcast<Packet16f, Packet16h>(const Packet16f& a) { - return float2half(a); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TYPE_CASTING_AVX512_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/Complex.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/Complex.h deleted file mode 100644 index 62df67ac..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/Complex.h +++ /dev/null @@ -1,447 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010-2016 Konstantinos Margaritis <markos@freevec.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX32_ALTIVEC_H -#define EIGEN_COMPLEX32_ALTIVEC_H - -namespace Eigen { - -namespace internal { - -static Packet4ui p4ui_CONJ_XOR = vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_MZERO);//{ 0x00000000, 0x80000000, 0x00000000, 0x80000000 }; -#ifdef __VSX__ -#if defined(_BIG_ENDIAN) -static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2d_MZERO, (Packet4ui) p2l_ZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 }; -static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_MZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 }; -#else -static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_MZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 }; -static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2d_MZERO, (Packet4ui) p2l_ZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 }; -#endif -#endif - -//---------- float ---------- -struct Packet2cf -{ - EIGEN_STRONG_INLINE explicit Packet2cf() : v(p4f_ZERO) {} - EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {} - Packet4f v; -}; - -template<> struct packet_traits<std::complex<float> > : default_packet_traits -{ - typedef Packet2cf type; - typedef Packet2cf half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 2, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, -#ifdef __VSX__ - HasBlend = 1, -#endif - HasSetLinear = 0 - }; -}; - -template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2cf half; }; - -template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from) -{ - Packet2cf res; - if((std::ptrdiff_t(&from) % 16) == 0) - res.v = pload<Packet4f>((const float *)&from); - else - res.v = ploadu<Packet4f>((const float *)&from); - res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) { return Packet2cf(pload<Packet4f>((const float *) from)); } -template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { return Packet2cf(ploadu<Packet4f>((const float*) from)); } -template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); } - -template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { pstore((float*)to, from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { pstoreu((float*)to, from.v); } - -template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from, Index stride) -{ - EIGEN_ALIGN16 std::complex<float> af[2]; - af[0] = from[0*stride]; - af[1] = from[1*stride]; - return pload<Packet2cf>(af); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from, Index stride) -{ - EIGEN_ALIGN16 std::complex<float> af[2]; - pstore<std::complex<float> >((std::complex<float> *) af, from); - to[0*stride] = af[0]; - to[1*stride] = af[1]; -} - -template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(a.v + b.v); } -template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(a.v - b.v); } -template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate(a.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) { return Packet2cf(pxor<Packet4f>(a.v, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR))); } - -template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - Packet4f v1, v2; - - // Permute and multiply the real parts of a and b - v1 = vec_perm(a.v, a.v, p16uc_PSET32_WODD); - // Get the imaginary parts of a - v2 = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN); - // multiply a_re * b - v1 = vec_madd(v1, b.v, p4f_ZERO); - // multiply a_im * b and get the conjugate result - v2 = vec_madd(v2, b.v, p4f_ZERO); - v2 = reinterpret_cast<Packet4f>(pxor(v2, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR))); - // permute back to a proper order - v2 = vec_perm(v2, v2, p16uc_COMPLEX32_REV); - - return Packet2cf(padd<Packet4f>(v1, v2)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pand<Packet4f>(a.v, b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(por<Packet4f>(a.v, b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pxor<Packet4f>(a.v, b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pandnot<Packet4f>(a.v, b.v)); } - -template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { EIGEN_PPC_PREFETCH(addr); } - -template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a) -{ - EIGEN_ALIGN16 std::complex<float> res[2]; - pstore((float *)&res, a.v); - - return res[0]; -} - -template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) -{ - Packet4f rev_a; - rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX32_REV2); - return Packet2cf(rev_a); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a) -{ - Packet4f b; - b = vec_sld(a.v, a.v, 8); - b = padd<Packet4f>(a.v, b); - return pfirst<Packet2cf>(Packet2cf(b)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs) -{ - Packet4f b1, b2; -#ifdef _BIG_ENDIAN - b1 = vec_sld(vecs[0].v, vecs[1].v, 8); - b2 = vec_sld(vecs[1].v, vecs[0].v, 8); -#else - b1 = vec_sld(vecs[1].v, vecs[0].v, 8); - b2 = vec_sld(vecs[0].v, vecs[1].v, 8); -#endif - b2 = vec_sld(b2, b2, 8); - b2 = padd<Packet4f>(b1, b2); - - return Packet2cf(b2); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a) -{ - Packet4f b; - Packet2cf prod; - b = vec_sld(a.v, a.v, 8); - prod = pmul<Packet2cf>(a, Packet2cf(b)); - - return pfirst<Packet2cf>(prod); -} - -template<int Offset> -struct palign_impl<Offset,Packet2cf> -{ - static EIGEN_STRONG_INLINE void run(Packet2cf& first, const Packet2cf& second) - { - if (Offset==1) - { -#ifdef _BIG_ENDIAN - first.v = vec_sld(first.v, second.v, 8); -#else - first.v = vec_sld(second.v, first.v, 8); -#endif - } - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, false,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, true,false> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, true,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f) - -template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - // TODO optimize it for AltiVec - Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a, b); - Packet4f s = pmul<Packet4f>(b.v, b.v); - return Packet2cf(pdiv(res.v, padd<Packet4f>(s, vec_perm(s, s, p16uc_COMPLEX32_REV)))); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& x) -{ - return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV)); -} - -EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel) -{ - Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI); - kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO); - kernel.packet[0].v = tmp; -} - -template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b) { - Packet4f eq = reinterpret_cast<Packet4f>(vec_cmpeq(a.v,b.v)); - return Packet2cf(vec_and(eq, vec_perm(eq, eq, p16uc_COMPLEX32_REV))); -} - -#ifdef __VSX__ -template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) { - Packet2cf result; - result.v = reinterpret_cast<Packet4f>(pblend<Packet2d>(ifPacket, reinterpret_cast<Packet2d>(thenPacket.v), reinterpret_cast<Packet2d>(elsePacket.v))); - return result; -} -#endif - -//---------- double ---------- -#ifdef __VSX__ -struct Packet1cd -{ - EIGEN_STRONG_INLINE Packet1cd() {} - EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {} - Packet2d v; -}; - -template<> struct packet_traits<std::complex<double> > : default_packet_traits -{ - typedef Packet1cd type; - typedef Packet1cd half; - enum { - Vectorizable = 1, - AlignedOnScalar = 0, - size = 1, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0 - }; -}; - -template<> struct unpacket_traits<Packet1cd> { typedef std::complex<double> type; enum {size=1, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet1cd half; }; - -template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from) { return Packet1cd(pload<Packet2d>((const double*)from)); } -template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) { return Packet1cd(ploadu<Packet2d>((const double*)from)); } -template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { pstore((double*)to, from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { pstoreu((double*)to, from.v); } - -template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from) -{ /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); } - -template<> EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>(const std::complex<double>* from, Index stride) -{ - EIGEN_ALIGN16 std::complex<double> af[2]; - af[0] = from[0*stride]; - af[1] = from[1*stride]; - return pload<Packet1cd>(af); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to, const Packet1cd& from, Index stride) -{ - EIGEN_ALIGN16 std::complex<double> af[2]; - pstore<std::complex<double> >(af, from); - to[0*stride] = af[0]; - to[1*stride] = af[1]; -} - -template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v + b.v); } -template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v - b.v); } -template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(Packet2d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) { return Packet1cd(pxor(a.v, reinterpret_cast<Packet2d>(p2ul_CONJ_XOR2))); } - -template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ - Packet2d a_re, a_im, v1, v2; - - // Permute and multiply the real parts of a and b - a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI); - // Get the imaginary parts of a - a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO); - // multiply a_re * b - v1 = vec_madd(a_re, b.v, p2d_ZERO); - // multiply a_im * b and get the conjugate result - v2 = vec_madd(a_im, b.v, p2d_ZERO); - v2 = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(v2), reinterpret_cast<Packet4ui>(v2), 8)); - v2 = pxor(v2, reinterpret_cast<Packet2d>(p2ul_CONJ_XOR1)); - - return Packet1cd(padd<Packet2d>(v1, v2)); -} - -template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pand(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(por(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pxor(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pandnot(a.v, b.v)); } - -template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); } - -template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { EIGEN_PPC_PREFETCH(addr); } - -template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a) -{ - EIGEN_ALIGN16 std::complex<double> res[2]; - pstore<std::complex<double> >(res, a); - - return res[0]; -} - -template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; } - -template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) { return pfirst(a); } -template<> EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(const Packet1cd* vecs) { return vecs[0]; } - -template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) { return pfirst(a); } - -template<int Offset> -struct palign_impl<Offset,Packet1cd> -{ - static EIGEN_STRONG_INLINE void run(Packet1cd& /*first*/, const Packet1cd& /*second*/) - { - // FIXME is it sure we never have to align a Packet1cd? - // Even though a std::complex<double> has 16 bytes, it is not necessarily aligned on a 16 bytes boundary... - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, false,true> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, true,false> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, true,true> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d) - -template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ - // TODO optimize it for AltiVec - Packet1cd res = conj_helper<Packet1cd,Packet1cd,false,true>().pmul(a,b); - Packet2d s = pmul<Packet2d>(b.v, b.v); - return Packet1cd(pdiv(res.v, padd<Packet2d>(s, vec_perm(s, s, p16uc_REVERSE64)))); -} - -EIGEN_STRONG_INLINE Packet1cd pcplxflip/*<Packet1cd>*/(const Packet1cd& x) -{ - return Packet1cd(preverse(Packet2d(x.v))); -} - -EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd,2>& kernel) -{ - Packet2d tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI); - kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO); - kernel.packet[0].v = tmp; -} - -template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b) { - // Compare real and imaginary parts of a and b to get the mask vector: - // [re(a)==re(b), im(a)==im(b)] - Packet2d eq = reinterpret_cast<Packet2d>(vec_cmpeq(a.v,b.v)); - // Swap real/imag elements in the mask in to get: - // [im(a)==im(b), re(a)==re(b)] - Packet2d eq_swapped = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(eq), reinterpret_cast<Packet4ui>(eq), 8)); - // Return re(a)==re(b) & im(a)==im(b) by computing bitwise AND of eq and eq_swapped - return Packet1cd(vec_and(eq, eq_swapped)); -} - -#endif // __VSX__ -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX32_ALTIVEC_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/MathFunctions.h deleted file mode 100644 index 3a7a3293..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/MathFunctions.h +++ /dev/null @@ -1,90 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007 Julien Pommier -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATH_FUNCTIONS_ALTIVEC_H -#define EIGEN_MATH_FUNCTIONS_ALTIVEC_H - -namespace Eigen { - -namespace internal { - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f plog<Packet4f>(const Packet4f& _x) -{ - return plog_float(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f pexp<Packet4f>(const Packet4f& _x) -{ - return pexp_float(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f psin<Packet4f>(const Packet4f& _x) -{ - return psin_float(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f pcos<Packet4f>(const Packet4f& _x) -{ - return pcos_float(_x); -} - -#ifndef EIGEN_COMP_CLANG -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f prsqrt<Packet4f>(const Packet4f& x) -{ - return vec_rsqrt(x); -} -#endif - -#ifdef __VSX__ -#ifndef EIGEN_COMP_CLANG -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d prsqrt<Packet2d>(const Packet2d& x) -{ - return vec_rsqrt(x); -} -#endif - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f psqrt<Packet4f>(const Packet4f& x) -{ - return vec_sqrt(x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d psqrt<Packet2d>(const Packet2d& x) -{ - return vec_sqrt(x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d pexp<Packet2d>(const Packet2d& _x) -{ - return pexp_double(_x); -} -#endif - -// Hyperbolic Tangent function. -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f -ptanh<Packet4f>(const Packet4f& x) { - return internal::generic_fast_tanh_float(x); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATH_FUNCTIONS_ALTIVEC_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/PacketMath.h deleted file mode 100644 index 154442cf..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/AltiVec/PacketMath.h +++ /dev/null @@ -1,1190 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2016 Konstantinos Margaritis <markos@freevec.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PACKET_MATH_ALTIVEC_H -#define EIGEN_PACKET_MATH_ALTIVEC_H - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD -#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 4 -#endif - -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#endif - -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD -#endif - -// NOTE Altivec has 32 registers, but Eigen only accepts a value of 8 or 16 -#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32 -#endif - -typedef __vector float Packet4f; -typedef __vector int Packet4i; -typedef __vector unsigned int Packet4ui; -typedef __vector __bool int Packet4bi; -typedef __vector short int Packet8i; -typedef __vector unsigned char Packet16uc; - -// We don't want to write the same code all the time, but we need to reuse the constants -// and it doesn't really work to declare them global, so we define macros instead - -#define _EIGEN_DECLARE_CONST_FAST_Packet4f(NAME,X) \ - Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(vec_splat_s32(X)) - -#define _EIGEN_DECLARE_CONST_FAST_Packet4i(NAME,X) \ - Packet4i p4i_##NAME = vec_splat_s32(X) - -#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \ - Packet4f p4f_##NAME = pset1<Packet4f>(X) - -#define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \ - Packet4i p4i_##NAME = pset1<Packet4i>(X) - -#define _EIGEN_DECLARE_CONST_Packet2d(NAME,X) \ - Packet2d p2d_##NAME = pset1<Packet2d>(X) - -#define _EIGEN_DECLARE_CONST_Packet2l(NAME,X) \ - Packet2l p2l_##NAME = pset1<Packet2l>(X) - -#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \ - const Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(pset1<Packet4i>(X)) - -#define DST_CHAN 1 -#define DST_CTRL(size, count, stride) (((size) << 24) | ((count) << 16) | (stride)) - - -// These constants are endian-agnostic -static _EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0); //{ 0.0, 0.0, 0.0, 0.0} -static _EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,} -static _EIGEN_DECLARE_CONST_FAST_Packet4i(ONE,1); //{ 1, 1, 1, 1} -static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS16,-16); //{ -16, -16, -16, -16} -static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1,-1); //{ -1, -1, -1, -1} -static Packet4f p4f_MZERO = (Packet4f) vec_sl((Packet4ui)p4i_MINUS1, (Packet4ui)p4i_MINUS1); //{ 0x80000000, 0x80000000, 0x80000000, 0x80000000} -#ifndef __VSX__ -static Packet4f p4f_ONE = vec_ctf(p4i_ONE, 0); //{ 1.0, 1.0, 1.0, 1.0} -#endif - -static Packet4f p4f_COUNTDOWN = { 0.0, 1.0, 2.0, 3.0 }; -static Packet4i p4i_COUNTDOWN = { 0, 1, 2, 3 }; - -static Packet16uc p16uc_REVERSE32 = { 12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3 }; -static Packet16uc p16uc_DUPLICATE32_HI = { 0,1,2,3, 0,1,2,3, 4,5,6,7, 4,5,6,7 }; - -// Handle endianness properly while loading constants -// Define global static constants: -#ifdef _BIG_ENDIAN -static Packet16uc p16uc_FORWARD = vec_lvsl(0, (float*)0); -#ifdef __VSX__ -static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; -#endif -static Packet16uc p16uc_PSET32_WODD = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 }; -static Packet16uc p16uc_PSET32_WEVEN = vec_sld(p16uc_DUPLICATE32_HI, (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 }; -static Packet16uc p16uc_HALF64_0_16 = vec_sld((Packet16uc)p4i_ZERO, vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 3), 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16}; -#else -static Packet16uc p16uc_FORWARD = p16uc_REVERSE32; -static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; -static Packet16uc p16uc_PSET32_WODD = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 1), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 }; -static Packet16uc p16uc_PSET32_WEVEN = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 }; -static Packet16uc p16uc_HALF64_0_16 = vec_sld(vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 0), (Packet16uc)p4i_ZERO, 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16}; -#endif // _BIG_ENDIAN - -static Packet16uc p16uc_PSET64_HI = (Packet16uc) vec_mergeh((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 }; -static Packet16uc p16uc_PSET64_LO = (Packet16uc) vec_mergel((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 8,9,10,11, 12,13,14,15, 8,9,10,11, 12,13,14,15 }; -static Packet16uc p16uc_TRANSPOSE64_HI = p16uc_PSET64_HI + p16uc_HALF64_0_16; //{ 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23}; -static Packet16uc p16uc_TRANSPOSE64_LO = p16uc_PSET64_LO + p16uc_HALF64_0_16; //{ 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31}; - -static Packet16uc p16uc_COMPLEX32_REV = vec_sld(p16uc_REVERSE32, p16uc_REVERSE32, 8); //{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 }; - -#ifdef _BIG_ENDIAN -static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; -#else -static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_PSET64_HI, p16uc_PSET64_LO, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; -#endif // _BIG_ENDIAN - -#if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC - #define EIGEN_PPC_PREFETCH(ADDR) __builtin_prefetch(ADDR); -#else - #define EIGEN_PPC_PREFETCH(ADDR) asm( " dcbt [%[addr]]\n" :: [addr] "r" (ADDR) : "cc" ); -#endif - -template <> -struct packet_traits<float> : default_packet_traits { - typedef Packet4f type; - typedef Packet4f half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 1, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasMin = 1, - HasMax = 1, - HasAbs = 1, - HasSin = EIGEN_FAST_MATH, - HasCos = EIGEN_FAST_MATH, - HasLog = 1, - HasExp = 1, -#ifdef __VSX__ - HasSqrt = 1, -#if !EIGEN_COMP_CLANG - HasRsqrt = 1, -#else - HasRsqrt = 0, -#endif -#else - HasSqrt = 0, - HasRsqrt = 0, - HasTanh = EIGEN_FAST_MATH, - HasErf = EIGEN_FAST_MATH, -#endif - HasRound = 1, - HasFloor = 1, - HasCeil = 1, - HasNegate = 1, - HasBlend = 1 - }; -}; -template <> -struct packet_traits<int> : default_packet_traits { - typedef Packet4i type; - typedef Packet4i half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 0, - HasBlend = 1 - }; -}; - -template<> struct unpacket_traits<Packet4f> -{ - typedef float type; - typedef Packet4f half; - typedef Packet4i integer_packet; - enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; -}; -template<> struct unpacket_traits<Packet4i> -{ - typedef int type; - typedef Packet4i half; - enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; -}; - -inline std::ostream & operator <<(std::ostream & s, const Packet16uc & v) -{ - union { - Packet16uc v; - unsigned char n[16]; - } vt; - vt.v = v; - for (int i=0; i< 16; i++) - s << (int)vt.n[i] << ", "; - return s; -} - -inline std::ostream & operator <<(std::ostream & s, const Packet4f & v) -{ - union { - Packet4f v; - float n[4]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; - return s; -} - -inline std::ostream & operator <<(std::ostream & s, const Packet4i & v) -{ - union { - Packet4i v; - int n[4]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; - return s; -} - -inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v) -{ - union { - Packet4ui v; - unsigned int n[4]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; - return s; -} - -// Need to define them first or we get specialization after instantiation errors -template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) -{ - // some versions of GCC throw "unused-but-set-parameter". - // ignoring these warnings for now. - EIGEN_UNUSED_VARIABLE(from); - EIGEN_DEBUG_ALIGNED_LOAD - return vec_ld(0, from); -} - -template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) -{ - // some versions of GCC throw "unused-but-set-parameter". - // ignoring these warnings for now. - EIGEN_UNUSED_VARIABLE(from); - EIGEN_DEBUG_ALIGNED_LOAD - return vec_ld(0, from); -} - -template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) -{ - // some versions of GCC throw "unused-but-set-parameter" (float *to). - // ignoring these warnings for now. - EIGEN_UNUSED_VARIABLE(to); - EIGEN_DEBUG_ALIGNED_STORE - vec_st(from, 0, to); -} - -template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from) -{ - // some versions of GCC throw "unused-but-set-parameter" (float *to). - // ignoring these warnings for now. - EIGEN_UNUSED_VARIABLE(to); - EIGEN_DEBUG_ALIGNED_STORE - vec_st(from, 0, to); -} - -template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { - Packet4f v = {from, from, from, from}; - return v; -} - -template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) { - Packet4i v = {from, from, from, from}; - return v; -} - -template<> EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(unsigned int from) { - return reinterpret_cast<Packet4f>(pset1<Packet4i>(from)); -} - -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet4f>(const float *a, - Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) -{ - a3 = pload<Packet4f>(a); - a0 = vec_splat(a3, 0); - a1 = vec_splat(a3, 1); - a2 = vec_splat(a3, 2); - a3 = vec_splat(a3, 3); -} -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet4i>(const int *a, - Packet4i& a0, Packet4i& a1, Packet4i& a2, Packet4i& a3) -{ - a3 = pload<Packet4i>(a); - a0 = vec_splat(a3, 0); - a1 = vec_splat(a3, 1); - a2 = vec_splat(a3, 2); - a3 = vec_splat(a3, 3); -} - -template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) -{ - EIGEN_ALIGN16 float af[4]; - af[0] = from[0*stride]; - af[1] = from[1*stride]; - af[2] = from[2*stride]; - af[3] = from[3*stride]; - return pload<Packet4f>(af); -} -template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride) -{ - EIGEN_ALIGN16 int ai[4]; - ai[0] = from[0*stride]; - ai[1] = from[1*stride]; - ai[2] = from[2*stride]; - ai[3] = from[3*stride]; - return pload<Packet4i>(ai); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) -{ - EIGEN_ALIGN16 float af[4]; - pstore<float>(af, from); - to[0*stride] = af[0]; - to[1*stride] = af[1]; - to[2*stride] = af[2]; - to[3*stride] = af[3]; -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride) -{ - EIGEN_ALIGN16 int ai[4]; - pstore<int>((int *)ai, from); - to[0*stride] = ai[0]; - to[1*stride] = ai[1]; - to[2*stride] = ai[2]; - to[3*stride] = ai[3]; -} - -template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) { return pset1<Packet4f>(a) + p4f_COUNTDOWN; } -template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return pset1<Packet4i>(a) + p4i_COUNTDOWN; } - -template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return a + b; } -template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return a + b; } - -template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return a - b; } -template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return a - b; } - -template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return p4f_ZERO - a; } -template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return p4i_ZERO - a; } - -template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_madd(a,b, p4f_MZERO); } -template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { return a * b; } - -template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) -{ -#ifndef __VSX__ // VSX actually provides a div instruction - Packet4f t, y_0, y_1; - - // Altivec does not offer a divide instruction, we have to do a reciprocal approximation - y_0 = vec_re(b); - - // Do one Newton-Raphson iteration to get the needed accuracy - t = vec_nmsub(y_0, b, p4f_ONE); - y_1 = vec_madd(y_0, t, y_0); - - return vec_madd(a, y_1, p4f_MZERO); -#else - return vec_div(a, b); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& /*a*/, const Packet4i& /*b*/) -{ eigen_assert(false && "packet integer division are not supported by AltiVec"); - return pset1<Packet4i>(0); -} - -// for some weird raisons, it has to be overloaded for packet of integers -template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) { return vec_madd(a,b,c); } -template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return a*b + c; } - -template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - #ifdef __VSX__ - // NOTE: about 10% slower than vec_min, but consistent with std::min and SSE regarding NaN - Packet4f ret; - __asm__ ("xvcmpgesp %x0,%x1,%x2\n\txxsel %x0,%x1,%x2,%x0" : "=&wa" (ret) : "wa" (a), "wa" (b)); - return ret; - #else - return vec_min(a, b); - #endif -} -template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_min(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - #ifdef __VSX__ - // NOTE: about 10% slower than vec_max, but consistent with std::max and SSE regarding NaN - Packet4f ret; - __asm__ ("xvcmpgtsp %x0,%x2,%x1\n\txxsel %x0,%x1,%x2,%x0" : "=&wa" (ret) : "wa" (a), "wa" (b)); - return ret; - #else - return vec_max(a, b); - #endif -} -template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_max(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4f pcmp_le(const Packet4f& a, const Packet4f& b) { return reinterpret_cast<Packet4f>(vec_cmple(a,b)); } -template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt(const Packet4f& a, const Packet4f& b) { return reinterpret_cast<Packet4f>(vec_cmplt(a,b)); } -template<> EIGEN_STRONG_INLINE Packet4f pcmp_eq(const Packet4f& a, const Packet4f& b) { return reinterpret_cast<Packet4f>(vec_cmpeq(a,b)); } -template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt_or_nan(const Packet4f& a, const Packet4f& b) { - Packet4f c = reinterpret_cast<Packet4f>(vec_cmpge(a,b)); - return vec_nor(c,c); -} -template<> EIGEN_STRONG_INLINE Packet4i pcmp_eq(const Packet4i& a, const Packet4i& b) { return reinterpret_cast<Packet4i>(vec_cmpeq(a,b)); } - -template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, b); } -template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_or(a, b); } -template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_or(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_xor(a, b); } -template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_xor(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, vec_nor(b, b)); } -template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, vec_nor(b, b)); } - -template<> EIGEN_STRONG_INLINE Packet4f pselect(const Packet4f& mask, const Packet4f& a, const Packet4f& b) { - return vec_sel(b, a, reinterpret_cast<Packet4ui>(mask)); -} - -template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) { return vec_round(a); } -template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) { return vec_ceil(a); } -template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) { return vec_floor(a); } - -#ifdef _BIG_ENDIAN -template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) -{ - EIGEN_DEBUG_ALIGNED_LOAD - Packet16uc MSQ, LSQ; - Packet16uc mask; - MSQ = vec_ld(0, (unsigned char *)from); // most significant quadword - LSQ = vec_ld(15, (unsigned char *)from); // least significant quadword - mask = vec_lvsl(0, from); // create the permute mask - return (Packet4f) vec_perm(MSQ, LSQ, mask); // align the data - -} -template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) -{ - EIGEN_DEBUG_ALIGNED_LOAD - // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html - Packet16uc MSQ, LSQ; - Packet16uc mask; - MSQ = vec_ld(0, (unsigned char *)from); // most significant quadword - LSQ = vec_ld(15, (unsigned char *)from); // least significant quadword - mask = vec_lvsl(0, from); // create the permute mask - return (Packet4i) vec_perm(MSQ, LSQ, mask); // align the data -} -#else -// We also need to redefine little endian loading of Packet4i/Packet4f using VSX -template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) -{ - EIGEN_DEBUG_UNALIGNED_LOAD - return vec_vsx_ld(0, from); -} -template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) -{ - EIGEN_DEBUG_UNALIGNED_LOAD - return vec_vsx_ld(0, from); -} -#endif - -template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) -{ - Packet4f p; - if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet4f>(from); - else p = ploadu<Packet4f>(from); - return vec_perm(p, p, p16uc_DUPLICATE32_HI); -} -template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from) -{ - Packet4i p; - if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet4i>(from); - else p = ploadu<Packet4i>(from); - return vec_perm(p, p, p16uc_DUPLICATE32_HI); -} - -#ifdef _BIG_ENDIAN -template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) -{ - EIGEN_DEBUG_UNALIGNED_STORE - // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html - // Warning: not thread safe! - Packet16uc MSQ, LSQ, edges; - Packet16uc edgeAlign, align; - - MSQ = vec_ld(0, (unsigned char *)to); // most significant quadword - LSQ = vec_ld(15, (unsigned char *)to); // least significant quadword - edgeAlign = vec_lvsl(0, to); // permute map to extract edges - edges=vec_perm(LSQ,MSQ,edgeAlign); // extract the edges - align = vec_lvsr( 0, to ); // permute map to misalign data - MSQ = vec_perm(edges,(Packet16uc)from,align); // misalign the data (MSQ) - LSQ = vec_perm((Packet16uc)from,edges,align); // misalign the data (LSQ) - vec_st( LSQ, 15, (unsigned char *)to ); // Store the LSQ part first - vec_st( MSQ, 0, (unsigned char *)to ); // Store the MSQ part -} -template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) -{ - EIGEN_DEBUG_UNALIGNED_STORE - // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html - // Warning: not thread safe! - Packet16uc MSQ, LSQ, edges; - Packet16uc edgeAlign, align; - - MSQ = vec_ld(0, (unsigned char *)to); // most significant quadword - LSQ = vec_ld(15, (unsigned char *)to); // least significant quadword - edgeAlign = vec_lvsl(0, to); // permute map to extract edges - edges=vec_perm(LSQ, MSQ, edgeAlign); // extract the edges - align = vec_lvsr( 0, to ); // permute map to misalign data - MSQ = vec_perm(edges, (Packet16uc) from, align); // misalign the data (MSQ) - LSQ = vec_perm((Packet16uc) from, edges, align); // misalign the data (LSQ) - vec_st( LSQ, 15, (unsigned char *)to ); // Store the LSQ part first - vec_st( MSQ, 0, (unsigned char *)to ); // Store the MSQ part -} -#else -// We also need to redefine little endian loading of Packet4i/Packet4f using VSX -template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) -{ - EIGEN_DEBUG_UNALIGNED_STORE - vec_vsx_st(from, 0, to); -} -template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) -{ - EIGEN_DEBUG_UNALIGNED_STORE - vec_vsx_st(from, 0, to); -} -#endif - -template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { EIGEN_PPC_PREFETCH(addr); } -template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { EIGEN_PPC_PREFETCH(addr); } - -template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { EIGEN_ALIGN16 float x; vec_ste(a, 0, &x); return x; } -template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { EIGEN_ALIGN16 int x; vec_ste(a, 0, &x); return x; } - -template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) -{ - return reinterpret_cast<Packet4f>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32)); -} -template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) -{ - return reinterpret_cast<Packet4i>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32)); } - -template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) { return vec_abs(a); } -template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) { return vec_abs(a); } - -template<int N> EIGEN_STRONG_INLINE Packet4i pshiftright(Packet4i a) -{ return vec_sr(a,reinterpret_cast<Packet4ui>(pset1<Packet4i>(N))); } -template<int N> EIGEN_STRONG_INLINE Packet4i pshiftleft(Packet4i a) -{ return vec_sl(a,reinterpret_cast<Packet4ui>(pset1<Packet4i>(N))); } - -template<> EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(const Packet4f& a, Packet4f& exponent) { - return pfrexp_float(a,exponent); -} - -template<> EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(const Packet4f& a, const Packet4f& exponent) { - return pldexp_float(a,exponent); -} - -template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) -{ - Packet4f b, sum; - b = vec_sld(a, a, 8); - sum = a + b; - b = vec_sld(sum, sum, 4); - sum += b; - return pfirst(sum); -} - -template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) -{ - Packet4f v[4], sum[4]; - - // It's easier and faster to transpose then add as columns - // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation - // Do the transpose, first set of moves - v[0] = vec_mergeh(vecs[0], vecs[2]); - v[1] = vec_mergel(vecs[0], vecs[2]); - v[2] = vec_mergeh(vecs[1], vecs[3]); - v[3] = vec_mergel(vecs[1], vecs[3]); - // Get the resulting vectors - sum[0] = vec_mergeh(v[0], v[2]); - sum[1] = vec_mergel(v[0], v[2]); - sum[2] = vec_mergeh(v[1], v[3]); - sum[3] = vec_mergel(v[1], v[3]); - - // Now do the summation: - // Lines 0+1 - sum[0] = sum[0] + sum[1]; - // Lines 2+3 - sum[1] = sum[2] + sum[3]; - // Add the results - sum[0] = sum[0] + sum[1]; - - return sum[0]; -} - -template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a) -{ - Packet4i sum; - sum = vec_sums(a, p4i_ZERO); -#ifdef _BIG_ENDIAN - sum = vec_sld(sum, p4i_ZERO, 12); -#else - sum = vec_sld(p4i_ZERO, sum, 4); -#endif - return pfirst(sum); -} - -template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs) -{ - Packet4i v[4], sum[4]; - - // It's easier and faster to transpose then add as columns - // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation - // Do the transpose, first set of moves - v[0] = vec_mergeh(vecs[0], vecs[2]); - v[1] = vec_mergel(vecs[0], vecs[2]); - v[2] = vec_mergeh(vecs[1], vecs[3]); - v[3] = vec_mergel(vecs[1], vecs[3]); - // Get the resulting vectors - sum[0] = vec_mergeh(v[0], v[2]); - sum[1] = vec_mergel(v[0], v[2]); - sum[2] = vec_mergeh(v[1], v[3]); - sum[3] = vec_mergel(v[1], v[3]); - - // Now do the summation: - // Lines 0+1 - sum[0] = sum[0] + sum[1]; - // Lines 2+3 - sum[1] = sum[2] + sum[3]; - // Add the results - sum[0] = sum[0] + sum[1]; - - return sum[0]; -} - -// Other reduction functions: -// mul -template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) -{ - Packet4f prod; - prod = pmul(a, vec_sld(a, a, 8)); - return pfirst(pmul(prod, vec_sld(prod, prod, 4))); -} - -template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a) -{ - EIGEN_ALIGN16 int aux[4]; - pstore(aux, a); - return aux[0] * aux[1] * aux[2] * aux[3]; -} - -// min -template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) -{ - Packet4f b, res; - b = vec_min(a, vec_sld(a, a, 8)); - res = vec_min(b, vec_sld(b, b, 4)); - return pfirst(res); -} - -template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a) -{ - Packet4i b, res; - b = vec_min(a, vec_sld(a, a, 8)); - res = vec_min(b, vec_sld(b, b, 4)); - return pfirst(res); -} - -// max -template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) -{ - Packet4f b, res; - b = vec_max(a, vec_sld(a, a, 8)); - res = vec_max(b, vec_sld(b, b, 4)); - return pfirst(res); -} - -template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a) -{ - Packet4i b, res; - b = vec_max(a, vec_sld(a, a, 8)); - res = vec_max(b, vec_sld(b, b, 4)); - return pfirst(res); -} - -template<> EIGEN_STRONG_INLINE bool predux_any(const Packet4f& x) -{ - return vec_any_ne(x, pzero(x)); -} - -template<int Offset> -struct palign_impl<Offset,Packet4f> -{ - static EIGEN_STRONG_INLINE void run(Packet4f& first, const Packet4f& second) - { -#ifdef _BIG_ENDIAN - switch (Offset % 4) { - case 1: - first = vec_sld(first, second, 4); break; - case 2: - first = vec_sld(first, second, 8); break; - case 3: - first = vec_sld(first, second, 12); break; - } -#else - switch (Offset % 4) { - case 1: - first = vec_sld(second, first, 12); break; - case 2: - first = vec_sld(second, first, 8); break; - case 3: - first = vec_sld(second, first, 4); break; - } -#endif - } -}; - -template<int Offset> -struct palign_impl<Offset,Packet4i> -{ - static EIGEN_STRONG_INLINE void run(Packet4i& first, const Packet4i& second) - { -#ifdef _BIG_ENDIAN - switch (Offset % 4) { - case 1: - first = vec_sld(first, second, 4); break; - case 2: - first = vec_sld(first, second, 8); break; - case 3: - first = vec_sld(first, second, 12); break; - } -#else - switch (Offset % 4) { - case 1: - first = vec_sld(second, first, 12); break; - case 2: - first = vec_sld(second, first, 8); break; - case 3: - first = vec_sld(second, first, 4); break; - } -#endif - } -}; - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4f,4>& kernel) { - Packet4f t0, t1, t2, t3; - t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]); - t1 = vec_mergel(kernel.packet[0], kernel.packet[2]); - t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]); - t3 = vec_mergel(kernel.packet[1], kernel.packet[3]); - kernel.packet[0] = vec_mergeh(t0, t2); - kernel.packet[1] = vec_mergel(t0, t2); - kernel.packet[2] = vec_mergeh(t1, t3); - kernel.packet[3] = vec_mergel(t1, t3); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4i,4>& kernel) { - Packet4i t0, t1, t2, t3; - t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]); - t1 = vec_mergel(kernel.packet[0], kernel.packet[2]); - t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]); - t3 = vec_mergel(kernel.packet[1], kernel.packet[3]); - kernel.packet[0] = vec_mergeh(t0, t2); - kernel.packet[1] = vec_mergel(t0, t2); - kernel.packet[2] = vec_mergeh(t1, t3); - kernel.packet[3] = vec_mergel(t1, t3); -} - -template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) { - Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] }; - Packet4ui mask = reinterpret_cast<Packet4ui>(vec_cmpeq(reinterpret_cast<Packet4ui>(select), reinterpret_cast<Packet4ui>(p4i_ONE))); - return vec_sel(elsePacket, thenPacket, mask); -} - -template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) { - Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] }; - Packet4ui mask = reinterpret_cast<Packet4ui>(vec_cmpeq(reinterpret_cast<Packet4ui>(select), reinterpret_cast<Packet4ui>(p4i_ONE))); - return vec_sel(elsePacket, thenPacket, mask); -} - - -template <> -struct type_casting_traits<float, int> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template <> -struct type_casting_traits<int, float> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - - -template<> EIGEN_STRONG_INLINE Packet4i pcast<Packet4f, Packet4i>(const Packet4f& a) { - return vec_cts(a,0); -} - -template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4i, Packet4f>(const Packet4i& a) { - return vec_ctf(a,0); -} - -template<> EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i,Packet4f>(const Packet4f& a) { - return reinterpret_cast<Packet4i>(a); -} - -template<> EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f,Packet4i>(const Packet4i& a) { - return reinterpret_cast<Packet4f>(a); -} - - - -//---------- double ---------- -#ifdef __VSX__ -typedef __vector double Packet2d; -typedef __vector unsigned long long Packet2ul; -typedef __vector long long Packet2l; -#if EIGEN_COMP_CLANG -typedef Packet2ul Packet2bl; -#else -typedef __vector __bool long Packet2bl; -#endif - -static Packet2l p2l_ONE = { 1, 1 }; -static Packet2l p2l_ZERO = reinterpret_cast<Packet2l>(p4i_ZERO); -static Packet2d p2d_ONE = { 1.0, 1.0 }; -static Packet2d p2d_ZERO = reinterpret_cast<Packet2d>(p4f_ZERO); -static Packet2d p2d_MZERO = { -0.0, -0.0 }; - -#ifdef _BIG_ENDIAN -static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(p2d_ZERO), reinterpret_cast<Packet4f>(p2d_ONE), 8)); -#else -static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(p2d_ONE), reinterpret_cast<Packet4f>(p2d_ZERO), 8)); -#endif - -template<int index> Packet2d vec_splat_dbl(Packet2d& a); - -template<> EIGEN_STRONG_INLINE Packet2d vec_splat_dbl<0>(Packet2d& a) -{ - return reinterpret_cast<Packet2d>(vec_perm(a, a, p16uc_PSET64_HI)); -} - -template<> EIGEN_STRONG_INLINE Packet2d vec_splat_dbl<1>(Packet2d& a) -{ - return reinterpret_cast<Packet2d>(vec_perm(a, a, p16uc_PSET64_LO)); -} - -template<> struct packet_traits<double> : default_packet_traits -{ - typedef Packet2d type; - typedef Packet2d half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=2, - HasHalfPacket = 1, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasMin = 1, - HasMax = 1, - HasAbs = 1, - HasSin = 0, - HasCos = 0, - HasLog = 0, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasRound = 1, - HasFloor = 1, - HasCeil = 1, - HasNegate = 1, - HasBlend = 1 - }; -}; - -template<> struct unpacket_traits<Packet2d> { typedef double type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2d half; }; - -inline std::ostream & operator <<(std::ostream & s, const Packet2l & v) -{ - union { - Packet2l v; - int64_t n[2]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1]; - return s; -} - -inline std::ostream & operator <<(std::ostream & s, const Packet2d & v) -{ - union { - Packet2d v; - double n[2]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1]; - return s; -} - -// Need to define them first or we get specialization after instantiation errors -template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) -{ - EIGEN_DEBUG_ALIGNED_LOAD - return vec_xl(0, const_cast<double *>(from)); // cast needed by Clang -} - -template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) -{ - EIGEN_DEBUG_ALIGNED_STORE - vec_xst(from, 0, to); -} - -template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { - Packet2d v = {from, from}; - return v; -} - -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet2d>(const double *a, - Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3) -{ - a1 = pload<Packet2d>(a); - a0 = vec_splat_dbl<0>(a1); - a1 = vec_splat_dbl<1>(a1); - a3 = pload<Packet2d>(a+2); - a2 = vec_splat_dbl<0>(a3); - a3 = vec_splat_dbl<1>(a3); -} - -template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride) -{ - EIGEN_ALIGN16 double af[2]; - af[0] = from[0*stride]; - af[1] = from[1*stride]; - return pload<Packet2d>(af); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride) -{ - EIGEN_ALIGN16 double af[2]; - pstore<double>(af, from); - to[0*stride] = af[0]; - to[1*stride] = af[1]; -} - -template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return pset1<Packet2d>(a) + p2d_COUNTDOWN; } - -template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return a + b; } - -template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return a - b; } - -template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return p2d_ZERO - a; } - -template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_madd(a,b,p2d_MZERO); } -template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_div(a,b); } - -// for some weird raisons, it has to be overloaded for packet of integers -template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return vec_madd(a, b, c); } - -template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) -{ - // NOTE: about 10% slower than vec_min, but consistent with std::min and SSE regarding NaN - Packet2d ret; - __asm__ ("xvcmpgedp %x0,%x1,%x2\n\txxsel %x0,%x1,%x2,%x0" : "=&wa" (ret) : "wa" (a), "wa" (b)); - return ret; - } - -template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) -{ - // NOTE: about 10% slower than vec_max, but consistent with std::max and SSE regarding NaN - Packet2d ret; - __asm__ ("xvcmpgtdp %x0,%x2,%x1\n\txxsel %x0,%x1,%x2,%x0" : "=&wa" (ret) : "wa" (a), "wa" (b)); - return ret; -} - -template<> EIGEN_STRONG_INLINE Packet2d pcmp_le(const Packet2d& a, const Packet2d& b) { return reinterpret_cast<Packet2d>(vec_cmple(a,b)); } -template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt(const Packet2d& a, const Packet2d& b) { return reinterpret_cast<Packet2d>(vec_cmplt(a,b)); } -template<> EIGEN_STRONG_INLINE Packet2d pcmp_eq(const Packet2d& a, const Packet2d& b) { return reinterpret_cast<Packet2d>(vec_cmpeq(a,b)); } -template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt_or_nan(const Packet2d& a, const Packet2d& b) { - Packet2d c = reinterpret_cast<Packet2d>(vec_cmpge(a,b)); - return vec_nor(c,c); -} - -template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, b); } - -template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_or(a, b); } - -template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_xor(a, b); } - -template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, vec_nor(b, b)); } - -template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) { return vec_round(a); } -template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return vec_ceil(a); } -template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return vec_floor(a); } - -template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) -{ - EIGEN_DEBUG_UNALIGNED_LOAD - return vec_vsx_ld(0, from); -} - -template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) -{ - Packet2d p; - if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet2d>(from); - else p = ploadu<Packet2d>(from); - return vec_splat_dbl<0>(p); -} - -template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) -{ - EIGEN_DEBUG_UNALIGNED_STORE - vec_vsx_st(from, 0, to); -} - -template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_PPC_PREFETCH(addr); } - -template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { EIGEN_ALIGN16 double x[2]; pstore<double>(x, a); return x[0]; } - -template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) -{ - return reinterpret_cast<Packet2d>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE64)); -} -template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) { return vec_abs(a); } - -// VSX support varies between different compilers and even different -// versions of the same compiler. For gcc version >= 4.9.3, we can use -// vec_cts to efficiently convert Packet2d to Packet2l. Otherwise, use -// a slow version that works with older compilers. -// Update: apparently vec_cts/vec_ctf intrinsics for 64-bit doubles -// are buggy, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70963 -static inline Packet2l ConvertToPacket2l(const Packet2d& x) { -#if EIGEN_GNUC_AT_LEAST(5, 4) || \ - (EIGEN_GNUC_AT(6, 1) && __GNUC_PATCHLEVEL__ >= 1) - return vec_cts(x, 0); // TODO: check clang version. -#else - double tmp[2]; - memcpy(tmp, &x, sizeof(tmp)); - Packet2l l = { static_cast<long long>(tmp[0]), - static_cast<long long>(tmp[1]) }; - return l; -#endif -} - -template<> EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(const Packet2d& a, const Packet2d& exponent) { - - // build 2^n - Packet2l emm0 = ConvertToPacket2l(exponent); - -#ifdef __POWER8_VECTOR__ - const Packet2l p2l_1023 = { 1023, 1023 }; - const Packet2ul p2ul_52 = { 52, 52 }; - emm0 = vec_add(emm0, p2l_1023); - emm0 = vec_sl(emm0, p2ul_52); -#else - // Code is a bit complex for POWER7. There is actually a - // vec_xxsldi intrinsic but it is not supported by some gcc versions. - // So we shift (52-32) bits and do a word swap with zeros. - const Packet4i p4i_1023 = pset1<Packet4i>(1023); - const Packet4i p4i_20 = pset1<Packet4i>(20); // 52 - 32 - - Packet4i emm04i = reinterpret_cast<Packet4i>(emm0); - emm04i = vec_add(emm04i, p4i_1023); - emm04i = vec_sl(emm04i, reinterpret_cast<Packet4ui>(p4i_20)); - static const Packet16uc perm = { - 0x14, 0x15, 0x16, 0x17, 0x00, 0x01, 0x02, 0x03, - 0x1c, 0x1d, 0x1e, 0x1f, 0x08, 0x09, 0x0a, 0x0b }; -#ifdef _BIG_ENDIAN - emm0 = reinterpret_cast<Packet2l>(vec_perm(p4i_ZERO, emm04i, perm)); -#else - emm0 = reinterpret_cast<Packet2l>(vec_perm(emm04i, p4i_ZERO, perm)); -#endif - -#endif - - return pmul(a, reinterpret_cast<Packet2d>(emm0)); -} - -template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) -{ - Packet2d b, sum; - b = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(a), reinterpret_cast<Packet4f>(a), 8)); - sum = a + b; - return pfirst<Packet2d>(sum); -} - -template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs) -{ - Packet2d v[2], sum; - v[0] = vecs[0] + reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(vecs[0]), reinterpret_cast<Packet4f>(vecs[0]), 8)); - v[1] = vecs[1] + reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(vecs[1]), reinterpret_cast<Packet4f>(vecs[1]), 8)); - -#ifdef _BIG_ENDIAN - sum = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(v[0]), reinterpret_cast<Packet4f>(v[1]), 8)); -#else - sum = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(v[1]), reinterpret_cast<Packet4f>(v[0]), 8)); -#endif - - return sum; -} -// Other reduction functions: -// mul -template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) -{ - return pfirst(pmul(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8)))); -} - -// min -template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) -{ - return pfirst(pmin(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8)))); -} - -// max -template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) -{ - return pfirst(pmax(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8)))); -} - -template<int Offset> -struct palign_impl<Offset,Packet2d> -{ - static EIGEN_STRONG_INLINE void run(Packet2d& first, const Packet2d& second) - { - if (Offset == 1) -#ifdef _BIG_ENDIAN - first = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(first), reinterpret_cast<Packet4ui>(second), 8)); -#else - first = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(second), reinterpret_cast<Packet4ui>(first), 8)); -#endif - } -}; - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet2d,2>& kernel) { - Packet2d t0, t1; - t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI); - t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO); - kernel.packet[0] = t0; - kernel.packet[1] = t1; -} - -template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) { - Packet2l select = { ifPacket.select[0], ifPacket.select[1] }; - Packet2bl mask = reinterpret_cast<Packet2bl>( vec_cmpeq(reinterpret_cast<Packet2d>(select), reinterpret_cast<Packet2d>(p2l_ONE)) ); - return vec_sel(elsePacket, thenPacket, mask); -} -#endif // __VSX__ -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PACKET_MATH_ALTIVEC_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/CUDA/Complex.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/CUDA/Complex.h deleted file mode 100644 index 57d1201f..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/CUDA/Complex.h +++ /dev/null @@ -1,103 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX_CUDA_H -#define EIGEN_COMPLEX_CUDA_H - -// clang-format off - -namespace Eigen { - -namespace internal { - -#if defined(EIGEN_CUDACC) && defined(EIGEN_USE_GPU) - -// Many std::complex methods such as operator+, operator-, operator* and -// operator/ are not constexpr. Due to this, clang does not treat them as device -// functions and thus Eigen functors making use of these operators fail to -// compile. Here, we manually specialize these functors for complex types when -// building for CUDA to avoid non-constexpr methods. - -// Sum -template<typename T> struct scalar_sum_op<const std::complex<T>, const std::complex<T> > : binary_op_base<const std::complex<T>, const std::complex<T> > { - typedef typename std::complex<T> result_type; - - EIGEN_EMPTY_STRUCT_CTOR(scalar_sum_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator() (const std::complex<T>& a, const std::complex<T>& b) const { - return std::complex<T>(numext::real(a) + numext::real(b), - numext::imag(a) + numext::imag(b)); - } -}; - -template<typename T> struct scalar_sum_op<std::complex<T>, std::complex<T> > : scalar_sum_op<const std::complex<T>, const std::complex<T> > {}; - - -// Difference -template<typename T> struct scalar_difference_op<const std::complex<T>, const std::complex<T> > : binary_op_base<const std::complex<T>, const std::complex<T> > { - typedef typename std::complex<T> result_type; - - EIGEN_EMPTY_STRUCT_CTOR(scalar_difference_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator() (const std::complex<T>& a, const std::complex<T>& b) const { - return std::complex<T>(numext::real(a) - numext::real(b), - numext::imag(a) - numext::imag(b)); - } -}; - -template<typename T> struct scalar_difference_op<std::complex<T>, std::complex<T> > : scalar_difference_op<const std::complex<T>, const std::complex<T> > {}; - - -// Product -template<typename T> struct scalar_product_op<const std::complex<T>, const std::complex<T> > : binary_op_base<const std::complex<T>, const std::complex<T> > { - enum { - Vectorizable = packet_traits<std::complex<T> >::HasMul - }; - typedef typename std::complex<T> result_type; - - EIGEN_EMPTY_STRUCT_CTOR(scalar_product_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator() (const std::complex<T>& a, const std::complex<T>& b) const { - const T a_real = numext::real(a); - const T a_imag = numext::imag(a); - const T b_real = numext::real(b); - const T b_imag = numext::imag(b); - return std::complex<T>(a_real * b_real - a_imag * b_imag, - a_real * b_imag + a_imag * b_real); - } -}; - -template<typename T> struct scalar_product_op<std::complex<T>, std::complex<T> > : scalar_product_op<const std::complex<T>, const std::complex<T> > {}; - - -// Quotient -template<typename T> struct scalar_quotient_op<const std::complex<T>, const std::complex<T> > : binary_op_base<const std::complex<T>, const std::complex<T> > { - enum { - Vectorizable = packet_traits<std::complex<T> >::HasDiv - }; - typedef typename std::complex<T> result_type; - - EIGEN_EMPTY_STRUCT_CTOR(scalar_quotient_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator() (const std::complex<T>& a, const std::complex<T>& b) const { - const T a_real = numext::real(a); - const T a_imag = numext::imag(a); - const T b_real = numext::real(b); - const T b_imag = numext::imag(b); - const T norm = T(1) / (b_real * b_real + b_imag * b_imag); - return std::complex<T>((a_real * b_real + a_imag * b_imag) * norm, - (a_imag * b_real - a_real * b_imag) * norm); - } -}; - -template<typename T> struct scalar_quotient_op<std::complex<T>, std::complex<T> > : scalar_quotient_op<const std::complex<T>, const std::complex<T> > {}; - -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_CUDA_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/ConjHelper.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/ConjHelper.h deleted file mode 100644 index 4cfe34e0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/ConjHelper.h +++ /dev/null @@ -1,29 +0,0 @@ - -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ARCH_CONJ_HELPER_H -#define EIGEN_ARCH_CONJ_HELPER_H - -#define EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(PACKET_CPLX, PACKET_REAL) \ - template<> struct conj_helper<PACKET_REAL, PACKET_CPLX, false,false> { \ - EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_REAL& x, const PACKET_CPLX& y, const PACKET_CPLX& c) const \ - { return padd(c, pmul(x,y)); } \ - EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_REAL& x, const PACKET_CPLX& y) const \ - { return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x, y.v)); } \ - }; \ - \ - template<> struct conj_helper<PACKET_CPLX, PACKET_REAL, false,false> { \ - EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_CPLX& x, const PACKET_REAL& y, const PACKET_CPLX& c) const \ - { return padd(c, pmul(x,y)); } \ - EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_CPLX& x, const PACKET_REAL& y) const \ - { return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x.v, y)); } \ - }; - -#endif // EIGEN_ARCH_CONJ_HELPER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h deleted file mode 100644 index 2b69512e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ /dev/null @@ -1,655 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007 Julien Pommier -// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) -// Copyright (C) 2009-2019 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* The exp and log functions of this file initially come from - * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/ - */ - -#ifndef EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_H -#define EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_H - -namespace Eigen { -namespace internal { - -template<typename Packet> EIGEN_STRONG_INLINE Packet -pfrexp_float(const Packet& a, Packet& exponent) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - const Packet cst_126f = pset1<Packet>(126.0f); - const Packet cst_half = pset1<Packet>(0.5f); - const Packet cst_inv_mant_mask = pset1frombits<Packet>(~0x7f800000u); - exponent = psub(pcast<PacketI,Packet>(pshiftright<23>(preinterpret<PacketI>(a))), cst_126f); - return por(pand(a, cst_inv_mant_mask), cst_half); -} - -template<typename Packet> EIGEN_STRONG_INLINE Packet -pldexp_float(Packet a, Packet exponent) -{ - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - const Packet cst_127 = pset1<Packet>(127.f); - // return a * 2^exponent - PacketI ei = pcast<Packet,PacketI>(padd(exponent, cst_127)); - return pmul(a, preinterpret<Packet>(pshiftleft<23>(ei))); -} - -// Natural logarithm -// Computes log(x) as log(2^e * m) = C*e + log(m), where the constant C =log(2) -// and m is in the range [sqrt(1/2),sqrt(2)). In this range, the logarithm can -// be easily approximated by a polynomial centered on m=1 for stability. -// TODO(gonnet): Further reduce the interval allowing for lower-degree -// polynomial interpolants -> ... -> profit! -template <typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet plog_float(const Packet _x) -{ - Packet x = _x; - - const Packet cst_1 = pset1<Packet>(1.0f); - const Packet cst_half = pset1<Packet>(0.5f); - // The smallest non denormalized float number. - const Packet cst_min_norm_pos = pset1frombits<Packet>( 0x00800000u); - const Packet cst_minus_inf = pset1frombits<Packet>( 0xff800000u); - const Packet cst_pos_inf = pset1frombits<Packet>( 0x7f800000u); - - // Polynomial coefficients. - const Packet cst_cephes_SQRTHF = pset1<Packet>(0.707106781186547524f); - const Packet cst_cephes_log_p0 = pset1<Packet>(7.0376836292E-2f); - const Packet cst_cephes_log_p1 = pset1<Packet>(-1.1514610310E-1f); - const Packet cst_cephes_log_p2 = pset1<Packet>(1.1676998740E-1f); - const Packet cst_cephes_log_p3 = pset1<Packet>(-1.2420140846E-1f); - const Packet cst_cephes_log_p4 = pset1<Packet>(+1.4249322787E-1f); - const Packet cst_cephes_log_p5 = pset1<Packet>(-1.6668057665E-1f); - const Packet cst_cephes_log_p6 = pset1<Packet>(+2.0000714765E-1f); - const Packet cst_cephes_log_p7 = pset1<Packet>(-2.4999993993E-1f); - const Packet cst_cephes_log_p8 = pset1<Packet>(+3.3333331174E-1f); - const Packet cst_cephes_log_q1 = pset1<Packet>(-2.12194440e-4f); - const Packet cst_cephes_log_q2 = pset1<Packet>(0.693359375f); - - // Truncate input values to the minimum positive normal. - x = pmax(x, cst_min_norm_pos); - - Packet e; - // extract significant in the range [0.5,1) and exponent - x = pfrexp(x,e); - - // part2: Shift the inputs from the range [0.5,1) to [sqrt(1/2),sqrt(2)) - // and shift by -1. The values are then centered around 0, which improves - // the stability of the polynomial evaluation. - // if( x < SQRTHF ) { - // e -= 1; - // x = x + x - 1.0; - // } else { x = x - 1.0; } - Packet mask = pcmp_lt(x, cst_cephes_SQRTHF); - Packet tmp = pand(x, mask); - x = psub(x, cst_1); - e = psub(e, pand(cst_1, mask)); - x = padd(x, tmp); - - Packet x2 = pmul(x, x); - Packet x3 = pmul(x2, x); - - // Evaluate the polynomial approximant of degree 8 in three parts, probably - // to improve instruction-level parallelism. - Packet y, y1, y2; - y = pmadd(cst_cephes_log_p0, x, cst_cephes_log_p1); - y1 = pmadd(cst_cephes_log_p3, x, cst_cephes_log_p4); - y2 = pmadd(cst_cephes_log_p6, x, cst_cephes_log_p7); - y = pmadd(y, x, cst_cephes_log_p2); - y1 = pmadd(y1, x, cst_cephes_log_p5); - y2 = pmadd(y2, x, cst_cephes_log_p8); - y = pmadd(y, x3, y1); - y = pmadd(y, x3, y2); - y = pmul(y, x3); - - // Add the logarithm of the exponent back to the result of the interpolation. - y1 = pmul(e, cst_cephes_log_q1); - tmp = pmul(x2, cst_half); - y = padd(y, y1); - x = psub(x, tmp); - y2 = pmul(e, cst_cephes_log_q2); - x = padd(x, y); - x = padd(x, y2); - - Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x)); - Packet iszero_mask = pcmp_eq(_x,pzero(_x)); - Packet pos_inf_mask = pcmp_eq(_x,cst_pos_inf); - // Filter out invalid inputs, i.e.: - // - negative arg will be NAN - // - 0 will be -INF - // - +INF will be +INF - return pselect(iszero_mask, cst_minus_inf, - por(pselect(pos_inf_mask,cst_pos_inf,x), invalid_mask)); -} - -/** \internal \returns log(1 + x) computed using W. Kahan's formula. - See: http://www.plunk.org/~hatch/rightway.php - */ -template<typename Packet> -Packet generic_plog1p(const Packet& x) -{ - typedef typename unpacket_traits<Packet>::type ScalarType; - const Packet one = pset1<Packet>(ScalarType(1)); - Packet xp1 = padd(x, one); - Packet small_mask = pcmp_eq(xp1, one); - Packet log1 = plog(xp1); - Packet inf_mask = pcmp_eq(xp1, log1); - Packet log_large = pmul(x, pdiv(log1, psub(xp1, one))); - return pselect(por(small_mask, inf_mask), x, log_large); -} - -/** \internal \returns exp(x)-1 computed using W. Kahan's formula. - See: http://www.plunk.org/~hatch/rightway.php - */ -template<typename Packet> -Packet generic_expm1(const Packet& x) -{ - typedef typename unpacket_traits<Packet>::type ScalarType; - const Packet one = pset1<Packet>(ScalarType(1)); - const Packet neg_one = pset1<Packet>(ScalarType(-1)); - Packet u = pexp(x); - Packet one_mask = pcmp_eq(u, one); - Packet u_minus_one = psub(u, one); - Packet neg_one_mask = pcmp_eq(u_minus_one, neg_one); - Packet logu = plog(u); - // The following comparison is to catch the case where - // exp(x) = +inf. It is written in this way to avoid having - // to form the constant +inf, which depends on the packet - // type. - Packet pos_inf_mask = pcmp_eq(logu, u); - Packet expm1 = pmul(u_minus_one, pdiv(x, logu)); - expm1 = pselect(pos_inf_mask, u, expm1); - return pselect(one_mask, - x, - pselect(neg_one_mask, - neg_one, - expm1)); -} - - -// Exponential function. Works by writing "x = m*log(2) + r" where -// "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then -// "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1). -template <typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet pexp_float(const Packet _x) -{ - const Packet cst_1 = pset1<Packet>(1.0f); - const Packet cst_half = pset1<Packet>(0.5f); - const Packet cst_exp_hi = pset1<Packet>( 88.3762626647950f); - const Packet cst_exp_lo = pset1<Packet>(-88.3762626647949f); - - const Packet cst_cephes_LOG2EF = pset1<Packet>(1.44269504088896341f); - const Packet cst_cephes_exp_p0 = pset1<Packet>(1.9875691500E-4f); - const Packet cst_cephes_exp_p1 = pset1<Packet>(1.3981999507E-3f); - const Packet cst_cephes_exp_p2 = pset1<Packet>(8.3334519073E-3f); - const Packet cst_cephes_exp_p3 = pset1<Packet>(4.1665795894E-2f); - const Packet cst_cephes_exp_p4 = pset1<Packet>(1.6666665459E-1f); - const Packet cst_cephes_exp_p5 = pset1<Packet>(5.0000001201E-1f); - - // Clamp x. - Packet x = pmax(pmin(_x, cst_exp_hi), cst_exp_lo); - - // Express exp(x) as exp(m*ln(2) + r), start by extracting - // m = floor(x/ln(2) + 0.5). - Packet m = pfloor(pmadd(x, cst_cephes_LOG2EF, cst_half)); - - // Get r = x - m*ln(2). If no FMA instructions are available, m*ln(2) is - // subtracted out in two parts, m*C1+m*C2 = m*ln(2), to avoid accumulating - // truncation errors. - Packet r; -#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD - const Packet cst_nln2 = pset1<Packet>(-0.6931471805599453f); - r = pmadd(m, cst_nln2, x); -#else - const Packet cst_cephes_exp_C1 = pset1<Packet>(0.693359375f); - const Packet cst_cephes_exp_C2 = pset1<Packet>(-2.12194440e-4f); - r = psub(x, pmul(m, cst_cephes_exp_C1)); - r = psub(r, pmul(m, cst_cephes_exp_C2)); -#endif - - Packet r2 = pmul(r, r); - - // TODO(gonnet): Split into odd/even polynomials and try to exploit - // instruction-level parallelism. - Packet y = cst_cephes_exp_p0; - y = pmadd(y, r, cst_cephes_exp_p1); - y = pmadd(y, r, cst_cephes_exp_p2); - y = pmadd(y, r, cst_cephes_exp_p3); - y = pmadd(y, r, cst_cephes_exp_p4); - y = pmadd(y, r, cst_cephes_exp_p5); - y = pmadd(y, r2, r); - y = padd(y, cst_1); - - // Return 2^m * exp(r). - return pmax(pldexp(y,m), _x); -} - -// make it the default path for scalar float -template<> -EIGEN_DEVICE_FUNC inline float pexp(const float& a) { return pexp_float(a); } - -template <typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet pexp_double(const Packet _x) -{ - Packet x = _x; - - const Packet cst_1 = pset1<Packet>(1.0); - const Packet cst_2 = pset1<Packet>(2.0); - const Packet cst_half = pset1<Packet>(0.5); - - const Packet cst_exp_hi = pset1<Packet>(709.437); - const Packet cst_exp_lo = pset1<Packet>(-709.436139303); - - const Packet cst_cephes_LOG2EF = pset1<Packet>(1.4426950408889634073599); - const Packet cst_cephes_exp_p0 = pset1<Packet>(1.26177193074810590878e-4); - const Packet cst_cephes_exp_p1 = pset1<Packet>(3.02994407707441961300e-2); - const Packet cst_cephes_exp_p2 = pset1<Packet>(9.99999999999999999910e-1); - const Packet cst_cephes_exp_q0 = pset1<Packet>(3.00198505138664455042e-6); - const Packet cst_cephes_exp_q1 = pset1<Packet>(2.52448340349684104192e-3); - const Packet cst_cephes_exp_q2 = pset1<Packet>(2.27265548208155028766e-1); - const Packet cst_cephes_exp_q3 = pset1<Packet>(2.00000000000000000009e0); - const Packet cst_cephes_exp_C1 = pset1<Packet>(0.693145751953125); - const Packet cst_cephes_exp_C2 = pset1<Packet>(1.42860682030941723212e-6); - - Packet tmp, fx; - - // clamp x - x = pmax(pmin(x, cst_exp_hi), cst_exp_lo); - // Express exp(x) as exp(g + n*log(2)). - fx = pmadd(cst_cephes_LOG2EF, x, cst_half); - - // Get the integer modulus of log(2), i.e. the "n" described above. - fx = pfloor(fx); - - // Get the remainder modulo log(2), i.e. the "g" described above. Subtract - // n*log(2) out in two steps, i.e. n*C1 + n*C2, C1+C2=log2 to get the last - // digits right. - tmp = pmul(fx, cst_cephes_exp_C1); - Packet z = pmul(fx, cst_cephes_exp_C2); - x = psub(x, tmp); - x = psub(x, z); - - Packet x2 = pmul(x, x); - - // Evaluate the numerator polynomial of the rational interpolant. - Packet px = cst_cephes_exp_p0; - px = pmadd(px, x2, cst_cephes_exp_p1); - px = pmadd(px, x2, cst_cephes_exp_p2); - px = pmul(px, x); - - // Evaluate the denominator polynomial of the rational interpolant. - Packet qx = cst_cephes_exp_q0; - qx = pmadd(qx, x2, cst_cephes_exp_q1); - qx = pmadd(qx, x2, cst_cephes_exp_q2); - qx = pmadd(qx, x2, cst_cephes_exp_q3); - - // I don't really get this bit, copied from the SSE2 routines, so... - // TODO(gonnet): Figure out what is going on here, perhaps find a better - // rational interpolant? - x = pdiv(px, psub(qx, px)); - x = pmadd(cst_2, x, cst_1); - - // Construct the result 2^n * exp(g) = e * x. The max is used to catch - // non-finite values in the input. - return pmax(pldexp(x,fx), _x); -} - -// make it the default path for scalar double -template<> -EIGEN_DEVICE_FUNC inline double pexp(const double& a) { return pexp_double(a); } - -// The following code is inspired by the following stack-overflow answer: -// https://stackoverflow.com/questions/30463616/payne-hanek-algorithm-implementation-in-c/30465751#30465751 -// It has been largely optimized: -// - By-pass calls to frexp. -// - Aligned loads of required 96 bits of 2/pi. This is accomplished by -// (1) balancing the mantissa and exponent to the required bits of 2/pi are -// aligned on 8-bits, and (2) replicating the storage of the bits of 2/pi. -// - Avoid a branch in rounding and extraction of the remaining fractional part. -// Overall, I measured a speed up higher than x2 on x86-64. -inline float trig_reduce_huge (float xf, int *quadrant) -{ - using Eigen::numext::int32_t; - using Eigen::numext::uint32_t; - using Eigen::numext::int64_t; - using Eigen::numext::uint64_t; - - const double pio2_62 = 3.4061215800865545e-19; // pi/2 * 2^-62 - const uint64_t zero_dot_five = uint64_t(1) << 61; // 0.5 in 2.62-bit fixed-point foramt - - // 192 bits of 2/pi for Payne-Hanek reduction - // Bits are introduced by packet of 8 to enable aligned reads. - static const uint32_t two_over_pi [] = - { - 0x00000028, 0x000028be, 0x0028be60, 0x28be60db, - 0xbe60db93, 0x60db9391, 0xdb939105, 0x9391054a, - 0x91054a7f, 0x054a7f09, 0x4a7f09d5, 0x7f09d5f4, - 0x09d5f47d, 0xd5f47d4d, 0xf47d4d37, 0x7d4d3770, - 0x4d377036, 0x377036d8, 0x7036d8a5, 0x36d8a566, - 0xd8a5664f, 0xa5664f10, 0x664f10e4, 0x4f10e410, - 0x10e41000, 0xe4100000 - }; - - uint32_t xi = numext::as_uint(xf); - // Below, -118 = -126 + 8. - // -126 is to get the exponent, - // +8 is to enable alignment of 2/pi's bits on 8 bits. - // This is possible because the fractional part of x as only 24 meaningful bits. - uint32_t e = (xi >> 23) - 118; - // Extract the mantissa and shift it to align it wrt the exponent - xi = ((xi & 0x007fffffu)| 0x00800000u) << (e & 0x7); - - uint32_t i = e >> 3; - uint32_t twoopi_1 = two_over_pi[i-1]; - uint32_t twoopi_2 = two_over_pi[i+3]; - uint32_t twoopi_3 = two_over_pi[i+7]; - - // Compute x * 2/pi in 2.62-bit fixed-point format. - uint64_t p; - p = uint64_t(xi) * twoopi_3; - p = uint64_t(xi) * twoopi_2 + (p >> 32); - p = (uint64_t(xi * twoopi_1) << 32) + p; - - // Round to nearest: add 0.5 and extract integral part. - uint64_t q = (p + zero_dot_five) >> 62; - *quadrant = int(q); - // Now it remains to compute "r = x - q*pi/2" with high accuracy, - // since we have p=x/(pi/2) with high accuracy, we can more efficiently compute r as: - // r = (p-q)*pi/2, - // where the product can be be carried out with sufficient accuracy using double precision. - p -= q<<62; - return float(double(int64_t(p)) * pio2_62); -} - -template<bool ComputeSine,typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -#if EIGEN_GNUC_AT_LEAST(4,4) && EIGEN_COMP_GNUC_STRICT -__attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif -Packet psincos_float(const Packet& _x) -{ -// Workaround -ffast-math aggressive optimizations -// See bug 1674 -#if EIGEN_COMP_CLANG && defined(EIGEN_VECTORIZE_SSE) -#define EIGEN_SINCOS_DONT_OPT(X) __asm__ ("" : "+x" (X)); -#else -#define EIGEN_SINCOS_DONT_OPT(X) -#endif - - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(0x80000000u); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_SINCOS_DONT_OPT(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x*4/pi - - // Reduce x by y octants to get: -Pi/4 <= x <= +Pi/4 - // using "Extended precision modular arithmetic" - #if defined(EIGEN_HAS_SINGLE_INSTRUCTION_MADD) - // This version requires true FMA for high accuracy - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - const float huge_th = ComputeSine ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); - #else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - const float huge_th = ComputeSine ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_SINCOS_DONT_OPT(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_SINCOS_DONT_OPT(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - - // For the record, the following set of coefficients maintain 2ULP up - // to a slightly larger range: - // const float huge_th = ComputeSine ? 51981.f : 39086.125f; - // but it slightly fails to maintain 1ULP for two values of sin below pi. - // x = pmadd(y, pset1<Packet>(-3.140625/2.), x); - // x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); - // x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); - // x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - - // For the record, with only 3 iterations it is possible to maintain - // 1 ULP up to 3PI (maybe more) and 2ULP up to 255. - // The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee - #endif - - if(predux_any(pcmp_le(pset1<Packet>(huge_th),pabs(_x)))) - { - const int PacketSize = unpacket_traits<Packet>::size; - EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; - EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; - EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) int y_int2[PacketSize]; - pstoreu(vals, pabs(_x)); - pstoreu(x_cpy, x); - pstoreu(y_int2, y_int); - for(int k=0; k<PacketSize;++k) - { - float val = vals[k]; - if(val>=huge_th && (numext::isfinite)(val)) - x_cpy[k] = trig_reduce_huge(val,&y_int2[k]); - } - x = ploadu<Packet>(x_cpy); - y_int = ploadu<PacketI>(y_int2); - } - - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = ComputeSine ? pxor(_x, preinterpret<Packet>(pshiftleft<30>(y_int))) - : preinterpret<Packet>(pshiftleft<30>(padd(y_int,csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x,x); - - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f )); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f )); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>( 0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - y = ComputeSine ? pselect(poly_mask,y2,y1) - : pselect(poly_mask,y1,y2); - - // Update the sign and filter huge inputs - return pxor(y, sign_bit); - -#undef EIGEN_SINCOS_DONT_OPT -} - -template<typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet psin_float(const Packet& x) -{ - return psincos_float<true>(x); -} - -template<typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet pcos_float(const Packet& x) -{ - return psincos_float<false>(x); -} - -/* polevl (modified for Eigen) - * - * Evaluate polynomial - * - * - * - * SYNOPSIS: - * - * int N; - * Scalar x, y, coef[N+1]; - * - * y = polevl<decltype(x), N>( x, coef); - * - * - * - * DESCRIPTION: - * - * Evaluates polynomial of degree N: - * - * 2 N - * y = C + C x + C x +...+ C x - * 0 1 2 N - * - * Coefficients are stored in reverse order: - * - * coef[0] = C , ..., coef[N] = C . - * N 0 - * - * The function p1evl() assumes that coef[N] = 1.0 and is - * omitted from the array. Its calling arguments are - * otherwise the same as polevl(). - * - * - * The Eigen implementation is templatized. For best speed, store - * coef as a const array (constexpr), e.g. - * - * const double coef[] = {1.0, 2.0, 3.0, ...}; - * - */ -template <typename Packet, int N> -struct ppolevl { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet& x, const typename unpacket_traits<Packet>::type coeff[]) { - EIGEN_STATIC_ASSERT((N > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - return pmadd(ppolevl<Packet, N-1>::run(x, coeff), x, pset1<Packet>(coeff[N])); - } -}; - -template <typename Packet> -struct ppolevl<Packet, 0> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet& x, const typename unpacket_traits<Packet>::type coeff[]) { - EIGEN_UNUSED_VARIABLE(x); - return pset1<Packet>(coeff[0]); - } -}; - -/* chbevl (modified for Eigen) - * - * Evaluate Chebyshev series - * - * - * - * SYNOPSIS: - * - * int N; - * Scalar x, y, coef[N], chebevl(); - * - * y = chbevl( x, coef, N ); - * - * - * - * DESCRIPTION: - * - * Evaluates the series - * - * N-1 - * - ' - * y = > coef[i] T (x/2) - * - i - * i=0 - * - * of Chebyshev polynomials Ti at argument x/2. - * - * Coefficients are stored in reverse order, i.e. the zero - * order term is last in the array. Note N is the number of - * coefficients, not the order. - * - * If coefficients are for the interval a to b, x must - * have been transformed to x -> 2(2x - b - a)/(b-a) before - * entering the routine. This maps x from (a, b) to (-1, 1), - * over which the Chebyshev polynomials are defined. - * - * If the coefficients are for the inverted interval, in - * which (a, b) is mapped to (1/b, 1/a), the transformation - * required is x -> 2(2ab/x - b - a)/(b-a). If b is infinity, - * this becomes x -> 4a/x - 1. - * - * - * - * SPEED: - * - * Taking advantage of the recurrence properties of the - * Chebyshev polynomials, the routine requires one more - * addition per loop than evaluating a nested polynomial of - * the same degree. - * - */ - -template <typename Packet, int N> -struct pchebevl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Packet run(Packet x, const typename unpacket_traits<Packet>::type coef[]) { - typedef typename unpacket_traits<Packet>::type Scalar; - Packet b0 = pset1<Packet>(coef[0]); - Packet b1 = pset1<Packet>(static_cast<Scalar>(0.f)); - Packet b2; - - for (int i = 1; i < N; i++) { - b2 = b1; - b1 = b0; - b0 = psub(pmadd(x, b1, pset1<Packet>(coef[i])), b2); - } - - return pmul(pset1<Packet>(static_cast<Scalar>(0.5f)), psub(b0, b2)); - } -}; - -} // end namespace internal -} // end namespace Eigen - -#endif // EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h deleted file mode 100644 index 68153cae..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h +++ /dev/null @@ -1,69 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2019 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H -#define EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H - -namespace Eigen { -namespace internal { - -// Forward declarations of the generic math functions -// implemented in GenericPacketMathFunctions.h -// This is needed to workaround a circular dependency. - -template<typename Packet> EIGEN_STRONG_INLINE Packet -pfrexp_float(const Packet& a, Packet& exponent); - -template<typename Packet> EIGEN_STRONG_INLINE Packet -pldexp_float(Packet a, Packet exponent); - -/** \internal \returns log(x) for single precision float */ -template <typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet plog_float(const Packet _x); - -/** \internal \returns log(1 + x) */ -template<typename Packet> -Packet generic_plog1p(const Packet& x); - -/** \internal \returns exp(x)-1 */ -template<typename Packet> -Packet generic_expm1(const Packet& x); - -/** \internal \returns exp(x) for single precision float */ -template <typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet pexp_float(const Packet _x); - -/** \internal \returns exp(x) for double precision real numbers */ -template <typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet pexp_double(const Packet _x); - -/** \internal \returns sin(x) for single precision float */ -template<typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet psin_float(const Packet& x); - -/** \internal \returns cos(x) for single precision float */ -template<typename Packet> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet pcos_float(const Packet& x); - -template <typename Packet, int N> struct ppolevl; - -} // end namespace internal -} // end namespace Eigen - -#endif // EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/Half.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/Half.h deleted file mode 100644 index 56782b34..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/Half.h +++ /dev/null @@ -1,756 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// The conversion routines are Copyright (c) Fabian Giesen, 2016. -// The original license follows: -// -// Copyright (c) Fabian Giesen, 2016 -// All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted. -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Standard 16-bit float type, mostly useful for GPUs. Defines a new -// type Eigen::half (inheriting either from CUDA's or HIP's __half struct) with -// operator overloads such that it behaves basically as an arithmetic -// type. It will be quite slow on CPUs (so it is recommended to stay -// in fp32 for CPUs, except for simple parameter conversions, I/O -// to disk and the likes), but fast on GPUs. - - -#ifndef EIGEN_HALF_H -#define EIGEN_HALF_H - -#if __cplusplus > 199711L -#define EIGEN_EXPLICIT_CAST(tgt_type) explicit operator tgt_type() -#else -#define EIGEN_EXPLICIT_CAST(tgt_type) operator tgt_type() -#endif - - -namespace Eigen { - -struct half; - -namespace half_impl { - -#if !defined(EIGEN_HAS_GPU_FP16) -// Make our own __half_raw definition that is similar to CUDA's. -struct __half_raw { - EIGEN_DEVICE_FUNC __half_raw() : x(0) {} - explicit EIGEN_DEVICE_FUNC __half_raw(unsigned short raw) : x(raw) {} - unsigned short x; -}; -#elif defined(EIGEN_HAS_HIP_FP16) - // Nothing to do here - // HIP fp16 header file has a definition for __half_raw -#elif defined(EIGEN_HAS_CUDA_FP16) - #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000 -// In CUDA < 9.0, __half is the equivalent of CUDA 9's __half_raw - typedef __half __half_raw; - #endif // defined(EIGEN_HAS_CUDA_FP16) - -#elif defined(SYCL_DEVICE_ONLY) -typedef cl::sycl::half __half_raw; - -#endif - -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw raw_uint16_to_half(unsigned short x); -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne(float ff); -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float half_to_float(__half_raw h); - -struct half_base : public __half_raw { - EIGEN_DEVICE_FUNC half_base() {} - EIGEN_DEVICE_FUNC half_base(const __half_raw& h) : __half_raw(h) {} - -#if defined(EIGEN_HAS_GPU_FP16) - #if defined(EIGEN_HAS_HIP_FP16) - EIGEN_DEVICE_FUNC half_base(const __half& h) { x = __half_as_ushort(h); } - #elif defined(EIGEN_HAS_CUDA_FP16) - #if (defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000) - EIGEN_DEVICE_FUNC half_base(const __half& h) : __half_raw(*(__half_raw*)&h) {} - #endif - #endif -#endif -}; - -} // namespace half_impl - -// Class definition. -struct half : public half_impl::half_base { - - // Writing this out as separate #if-else blocks to make the code easier to follow - // The same applies to most #if-else blocks in this file -#if !defined(EIGEN_HAS_GPU_FP16) - typedef half_impl::__half_raw __half_raw; -#elif defined(EIGEN_HAS_HIP_FP16) - // Nothing to do here - // HIP fp16 header file has a definition for __half_raw -#elif defined(EIGEN_HAS_CUDA_FP16) - // Note that EIGEN_CUDA_SDK_VER is set to 0 even when compiling with HIP, so - // (EIGEN_CUDA_SDK_VER < 90000) is true even for HIP! So keeping this within - // #if defined(EIGEN_HAS_CUDA_FP16) is needed - #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000 - typedef half_impl::__half_raw __half_raw; - #endif -#endif - - EIGEN_DEVICE_FUNC half() {} - - EIGEN_DEVICE_FUNC half(const __half_raw& h) : half_impl::half_base(h) {} - -#if defined(EIGEN_HAS_GPU_FP16) - #if defined(EIGEN_HAS_HIP_FP16) - EIGEN_DEVICE_FUNC half(const __half& h) : half_impl::half_base(h) {} - #elif defined(EIGEN_HAS_CUDA_FP16) - #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000 - EIGEN_DEVICE_FUNC half(const __half& h) : half_impl::half_base(h) {} - #endif - #endif -#endif - - - explicit EIGEN_DEVICE_FUNC half(bool b) - : half_impl::half_base(half_impl::raw_uint16_to_half(b ? 0x3c00 : 0)) {} - template<class T> - explicit EIGEN_DEVICE_FUNC half(const T& val) - : half_impl::half_base(half_impl::float_to_half_rtne(static_cast<float>(val))) {} - explicit EIGEN_DEVICE_FUNC half(float f) - : half_impl::half_base(half_impl::float_to_half_rtne(f)) {} - - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(bool) const { - // +0.0 and -0.0 become false, everything else becomes true. - return (x & 0x7fff) != 0; - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(signed char) const { - return static_cast<signed char>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(unsigned char) const { - return static_cast<unsigned char>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(short) const { - return static_cast<short>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(unsigned short) const { - return static_cast<unsigned short>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(int) const { - return static_cast<int>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(unsigned int) const { - return static_cast<unsigned int>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(long) const { - return static_cast<long>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(unsigned long) const { - return static_cast<unsigned long>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(long long) const { - return static_cast<long long>(half_impl::half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(unsigned long long) const { - return static_cast<unsigned long long>(half_to_float(*this)); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(float) const { - return half_impl::half_to_float(*this); - } - EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(double) const { - return static_cast<double>(half_impl::half_to_float(*this)); - } -}; - -} // end namespace Eigen - -namespace std { -template<> -struct numeric_limits<Eigen::half> { - static const bool is_specialized = true; - static const bool is_signed = true; - static const bool is_integer = false; - static const bool is_exact = false; - static const bool has_infinity = true; - static const bool has_quiet_NaN = true; - static const bool has_signaling_NaN = true; - static const float_denorm_style has_denorm = denorm_present; - static const bool has_denorm_loss = false; - static const std::float_round_style round_style = std::round_to_nearest; - static const bool is_iec559 = false; - static const bool is_bounded = false; - static const bool is_modulo = false; - static const int digits = 11; - static const int digits10 = 3; // according to http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html - static const int max_digits10 = 5; // according to http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html - static const int radix = 2; - static const int min_exponent = -13; - static const int min_exponent10 = -4; - static const int max_exponent = 16; - static const int max_exponent10 = 4; - static const bool traps = true; - static const bool tinyness_before = false; - - static Eigen::half (min)() { return Eigen::half_impl::raw_uint16_to_half(0x400); } - static Eigen::half lowest() { return Eigen::half_impl::raw_uint16_to_half(0xfbff); } - static Eigen::half (max)() { return Eigen::half_impl::raw_uint16_to_half(0x7bff); } - static Eigen::half epsilon() { return Eigen::half_impl::raw_uint16_to_half(0x0800); } - static Eigen::half round_error() { return Eigen::half(0.5); } - static Eigen::half infinity() { return Eigen::half_impl::raw_uint16_to_half(0x7c00); } - static Eigen::half quiet_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7e00); } - static Eigen::half signaling_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7e00); } - static Eigen::half denorm_min() { return Eigen::half_impl::raw_uint16_to_half(0x1); } -}; - -// If std::numeric_limits<T> is specialized, should also specialize -// std::numeric_limits<const T>, std::numeric_limits<volatile T>, and -// std::numeric_limits<const volatile T> -// https://stackoverflow.com/a/16519653/ -template<> -struct numeric_limits<const Eigen::half> : numeric_limits<Eigen::half> {}; -template<> -struct numeric_limits<volatile Eigen::half> : numeric_limits<Eigen::half> {}; -template<> -struct numeric_limits<const volatile Eigen::half> : numeric_limits<Eigen::half> {}; -} // end namespace std - -namespace Eigen { - -namespace half_impl { - -#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && \ - EIGEN_CUDA_ARCH >= 530) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(HIP_DEVICE_COMPILE)) -#define EIGEN_HAS_NATIVE_FP16 -#endif - -// Intrinsics for native fp16 support. Note that on current hardware, -// these are no faster than fp32 arithmetic (you need to use the half2 -// versions to get the ALU speed increased), but you do save the -// conversion steps back and forth. - -#if defined(EIGEN_HAS_NATIVE_FP16) -EIGEN_STRONG_INLINE __device__ half operator + (const half& a, const half& b) { -#if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000 - return __hadd(::__half(a), ::__half(b)); -#else - return __hadd(a, b); -#endif -} -EIGEN_STRONG_INLINE __device__ half operator * (const half& a, const half& b) { - return __hmul(a, b); -} -EIGEN_STRONG_INLINE __device__ half operator - (const half& a, const half& b) { - return __hsub(a, b); -} -EIGEN_STRONG_INLINE __device__ half operator / (const half& a, const half& b) { -#if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000 - return __hdiv(a, b); -#else - float num = __half2float(a); - float denom = __half2float(b); - return __float2half(num / denom); -#endif -} -EIGEN_STRONG_INLINE __device__ half operator - (const half& a) { - return __hneg(a); -} -EIGEN_STRONG_INLINE __device__ half& operator += (half& a, const half& b) { - a = a + b; - return a; -} -EIGEN_STRONG_INLINE __device__ half& operator *= (half& a, const half& b) { - a = a * b; - return a; -} -EIGEN_STRONG_INLINE __device__ half& operator -= (half& a, const half& b) { - a = a - b; - return a; -} -EIGEN_STRONG_INLINE __device__ half& operator /= (half& a, const half& b) { - a = a / b; - return a; -} -EIGEN_STRONG_INLINE __device__ bool operator == (const half& a, const half& b) { - return __heq(a, b); -} -EIGEN_STRONG_INLINE __device__ bool operator != (const half& a, const half& b) { - return __hne(a, b); -} -EIGEN_STRONG_INLINE __device__ bool operator < (const half& a, const half& b) { - return __hlt(a, b); -} -EIGEN_STRONG_INLINE __device__ bool operator <= (const half& a, const half& b) { - return __hle(a, b); -} -EIGEN_STRONG_INLINE __device__ bool operator > (const half& a, const half& b) { - return __hgt(a, b); -} -EIGEN_STRONG_INLINE __device__ bool operator >= (const half& a, const half& b) { - return __hge(a, b); -} - -#endif - -// We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler, -// invoked by NVCC’ (e.g. on MacOS). The former needs to see both host and device implementation -// of the functions, while the latter can only deal with one of them. -#if !defined(EIGEN_HAS_NATIVE_FP16) || (EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC) // Emulate support for half floats - -#if EIGEN_COMP_CLANG && defined(EIGEN_CUDACC) -// We need to provide emulated *host-side* FP16 operators for clang. -#pragma push_macro("EIGEN_DEVICE_FUNC") -#undef EIGEN_DEVICE_FUNC -#if defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_HAS_NATIVE_FP16) -#define EIGEN_DEVICE_FUNC __host__ -#else // both host and device need emulated ops. -#define EIGEN_DEVICE_FUNC __host__ __device__ -#endif -#endif - -// Definitions for CPUs and older HIP+CUDA, mostly working through conversion -// to/from fp32. - -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator + (const half& a, const half& b) { - return half(float(a) + float(b)); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator * (const half& a, const half& b) { - return half(float(a) * float(b)); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (const half& a, const half& b) { - return half(float(a) - float(b)); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator / (const half& a, const half& b) { - return half(float(a) / float(b)); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (const half& a) { - half result; - result.x = a.x ^ 0x8000; - return result; -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator += (half& a, const half& b) { - a = half(float(a) + float(b)); - return a; -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator *= (half& a, const half& b) { - a = half(float(a) * float(b)); - return a; -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator -= (half& a, const half& b) { - a = half(float(a) - float(b)); - return a; -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator /= (half& a, const half& b) { - a = half(float(a) / float(b)); - return a; -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator == (const half& a, const half& b) { - return numext::equal_strict(float(a),float(b)); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator != (const half& a, const half& b) { - return numext::not_equal_strict(float(a), float(b)); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator < (const half& a, const half& b) { - return float(a) < float(b); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator <= (const half& a, const half& b) { - return float(a) <= float(b); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator > (const half& a, const half& b) { - return float(a) > float(b); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator >= (const half& a, const half& b) { - return float(a) >= float(b); -} - -#if defined(__clang__) && defined(__CUDA__) -#pragma pop_macro("EIGEN_DEVICE_FUNC") -#endif -#endif // Emulate support for half floats - -// Division by an index. Do it in full float precision to avoid accuracy -// issues in converting the denominator to half. -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator / (const half& a, Index b) { - return half(static_cast<float>(a) / static_cast<float>(b)); -} - -// Conversion routines, including fallbacks for the host or older CUDA. -// Note that newer Intel CPUs (Haswell or newer) have vectorized versions of -// these in hardware. If we need more performance on older/other CPUs, they are -// also possible to vectorize directly. - -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw raw_uint16_to_half(unsigned short x) { - __half_raw h; - h.x = x; - return h; -} - -union float32_bits { - unsigned int u; - float f; -}; - -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne(float ff) { -#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - __half tmp_ff = __float2half(ff); - return *(__half_raw*)&tmp_ff; - -#elif defined(EIGEN_HAS_FP16_C) - __half_raw h; - h.x = _cvtss_sh(ff, 0); - return h; - -#else - float32_bits f; f.f = ff; - - const float32_bits f32infty = { 255 << 23 }; - const float32_bits f16max = { (127 + 16) << 23 }; - const float32_bits denorm_magic = { ((127 - 15) + (23 - 10) + 1) << 23 }; - unsigned int sign_mask = 0x80000000u; - __half_raw o; - o.x = static_cast<unsigned short>(0x0u); - - unsigned int sign = f.u & sign_mask; - f.u ^= sign; - - // NOTE all the integer compares in this function can be safely - // compiled into signed compares since all operands are below - // 0x80000000. Important if you want fast straight SSE2 code - // (since there's no unsigned PCMPGTD). - - if (f.u >= f16max.u) { // result is Inf or NaN (all exponent bits set) - o.x = (f.u > f32infty.u) ? 0x7e00 : 0x7c00; // NaN->qNaN and Inf->Inf - } else { // (De)normalized number or zero - if (f.u < (113 << 23)) { // resulting FP16 is subnormal or zero - // use a magic value to align our 10 mantissa bits at the bottom of - // the float. as long as FP addition is round-to-nearest-even this - // just works. - f.f += denorm_magic.f; - - // and one integer subtract of the bias later, we have our final float! - o.x = static_cast<unsigned short>(f.u - denorm_magic.u); - } else { - unsigned int mant_odd = (f.u >> 13) & 1; // resulting mantissa is odd - - // update exponent, rounding bias part 1 - f.u += ((unsigned int)(15 - 127) << 23) + 0xfff; - // rounding bias part 2 - f.u += mant_odd; - // take the bits! - o.x = static_cast<unsigned short>(f.u >> 13); - } - } - - o.x |= static_cast<unsigned short>(sign >> 16); - return o; -#endif -} - -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float half_to_float(__half_raw h) { -#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - return __half2float(h); - -#elif defined(EIGEN_HAS_FP16_C) - return _cvtsh_ss(h.x); - -#else - const float32_bits magic = { 113 << 23 }; - const unsigned int shifted_exp = 0x7c00 << 13; // exponent mask after shift - float32_bits o; - - o.u = (h.x & 0x7fff) << 13; // exponent/mantissa bits - unsigned int exp = shifted_exp & o.u; // just the exponent - o.u += (127 - 15) << 23; // exponent adjust - - // handle exponent special cases - if (exp == shifted_exp) { // Inf/NaN? - o.u += (128 - 16) << 23; // extra exp adjust - } else if (exp == 0) { // Zero/Denormal? - o.u += 1 << 23; // extra exp adjust - o.f -= magic.f; // renormalize - } - - o.u |= (h.x & 0x8000) << 16; // sign bit - return o.f; -#endif -} - -// --- standard functions --- - -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isinf)(const half& a) { - return (a.x & 0x7fff) == 0x7c00; -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isnan)(const half& a) { -#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - return __hisnan(a); -#else - return (a.x & 0x7fff) > 0x7c00; -#endif -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isfinite)(const half& a) { - return !(isinf EIGEN_NOT_A_MACRO (a)) && !(isnan EIGEN_NOT_A_MACRO (a)); -} - -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half abs(const half& a) { - half result; - result.x = a.x & 0x7FFF; - return result; -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half exp(const half& a) { -#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \ - defined(EIGEN_HIP_DEVICE_COMPILE) - return half(hexp(a)); -#else - return half(::expf(float(a))); -#endif -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half expm1(const half& a) { - return half(numext::expm1(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log(const half& a) { -#if (defined(EIGEN_HAS_CUDA_FP16) && EIGEN_CUDA_SDK_VER >= 80000 && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - return half(::hlog(a)); -#else - return half(::logf(float(a))); -#endif -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log1p(const half& a) { - return half(numext::log1p(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log10(const half& a) { - return half(::log10f(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sqrt(const half& a) { -#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \ - defined(EIGEN_HIP_DEVICE_COMPILE) - return half(hsqrt(a)); -#else - return half(::sqrtf(float(a))); -#endif -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half& a, const half& b) { - return half(::powf(float(a), float(b))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sin(const half& a) { - return half(::sinf(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half cos(const half& a) { - return half(::cosf(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tan(const half& a) { - return half(::tanf(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tanh(const half& a) { - return half(::tanhf(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half floor(const half& a) { -#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \ - defined(EIGEN_HIP_DEVICE_COMPILE) - return half(hfloor(a)); -#else - return half(::floorf(float(a))); -#endif -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half ceil(const half& a) { -#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \ - defined(EIGEN_HIP_DEVICE_COMPILE) - return half(hceil(a)); -#else - return half(::ceilf(float(a))); -#endif -} - -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half (min)(const half& a, const half& b) { -#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - return __hlt(b, a) ? b : a; -#else - const float f1 = static_cast<float>(a); - const float f2 = static_cast<float>(b); - return f2 < f1 ? b : a; -#endif -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half (max)(const half& a, const half& b) { -#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - return __hlt(a, b) ? b : a; -#else - const float f1 = static_cast<float>(a); - const float f2 = static_cast<float>(b); - return f1 < f2 ? b : a; -#endif -} - -#ifndef EIGEN_NO_IO -EIGEN_ALWAYS_INLINE std::ostream& operator << (std::ostream& os, const half& v) { - os << static_cast<float>(v); - return os; -} -#endif - -} // end namespace half_impl - -// import Eigen::half_impl::half into Eigen namespace -// using half_impl::half; - -namespace internal { - -template<> -struct random_default_impl<half, false, false> -{ - static inline half run(const half& x, const half& y) - { - return x + (y-x) * half(float(std::rand()) / float(RAND_MAX)); - } - static inline half run() - { - return run(half(-1.f), half(1.f)); - } -}; - -template<> struct is_arithmetic<half> { enum { value = true }; }; - -} // end namespace internal - -template<> struct NumTraits<Eigen::half> - : GenericNumTraits<Eigen::half> -{ - enum { - IsSigned = true, - IsInteger = false, - IsComplex = false, - RequireInitialization = false - }; - - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Eigen::half epsilon() { - return half_impl::raw_uint16_to_half(0x0800); - } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Eigen::half dummy_precision() { return Eigen::half(1e-2f); } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Eigen::half highest() { - return half_impl::raw_uint16_to_half(0x7bff); - } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Eigen::half lowest() { - return half_impl::raw_uint16_to_half(0xfbff); - } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Eigen::half infinity() { - return half_impl::raw_uint16_to_half(0x7c00); - } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Eigen::half quiet_NaN() { - return half_impl::raw_uint16_to_half(0x7c01); - } -}; - -} // end namespace Eigen - -// C-like standard mathematical functions and trancendentals. -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half fabsh(const Eigen::half& a) { - Eigen::half result; - result.x = a.x & 0x7FFF; - return result; -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half exph(const Eigen::half& a) { - return Eigen::half(::expf(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half logh(const Eigen::half& a) { -#if (EIGEN_CUDA_SDK_VER >= 80000 && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \ - defined(EIGEN_HIP_DEVICE_COMPILE) - return Eigen::half(::hlog(a)); -#else - return Eigen::half(::logf(float(a))); -#endif -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half sqrth(const Eigen::half& a) { - return Eigen::half(::sqrtf(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half powh(const Eigen::half& a, const Eigen::half& b) { - return Eigen::half(::powf(float(a), float(b))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half floorh(const Eigen::half& a) { - return Eigen::half(::floorf(float(a))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half ceilh(const Eigen::half& a) { - return Eigen::half(::ceilf(float(a))); -} - -namespace std { - -#if __cplusplus > 199711L -template <> -struct hash<Eigen::half> { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t operator()(const Eigen::half& a) const { - return static_cast<std::size_t>(a.x); - } -}; -#endif - -} // end namespace std - - -// Add the missing shfl_xor intrinsic -#if (defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \ - defined(EIGEN_HIP_DEVICE_COMPILE) - -__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_xor(Eigen::half var, int laneMask, int width=warpSize) { - #if (EIGEN_CUDA_SDK_VER < 90000) || \ - defined(EIGEN_HAS_HIP_FP16) - return static_cast<Eigen::half>(__shfl_xor(static_cast<float>(var), laneMask, width)); - #else - return static_cast<Eigen::half>(__shfl_xor_sync(0xFFFFFFFF, static_cast<float>(var), laneMask, width)); - #endif -} -#endif - -// ldg() has an overload for __half_raw, but we also need one for Eigen::half. -#if (defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350) || \ - defined(EIGEN_HIP_DEVICE_COMPILE) -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half __ldg(const Eigen::half* ptr) { - return Eigen::half_impl::raw_uint16_to_half( - __ldg(reinterpret_cast<const unsigned short*>(ptr))); -} -#endif - - -#if defined(EIGEN_GPU_COMPILE_PHASE) -namespace Eigen { -namespace numext { - -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -bool (isnan)(const Eigen::half& h) { - return (half_impl::isnan)(h); -} - -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -bool (isinf)(const Eigen::half& h) { - return (half_impl::isinf)(h); -} - -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -bool (isfinite)(const Eigen::half& h) { - return (half_impl::isfinite)(h); -} - -} // namespace Eigen -} // namespace numext -#endif - -#endif // EIGEN_HALF_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/Settings.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/Settings.h deleted file mode 100644 index a5c3ada4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/Settings.h +++ /dev/null @@ -1,49 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -/* All the parameters defined in this file can be specialized in the - * architecture specific files, and/or by the user. - * More to come... */ - -#ifndef EIGEN_DEFAULT_SETTINGS_H -#define EIGEN_DEFAULT_SETTINGS_H - -/** Defines the maximal loop size to enable meta unrolling of loops. - * Note that the value here is expressed in Eigen's own notion of "number of FLOPS", - * it does not correspond to the number of iterations or the number of instructions - */ -#ifndef EIGEN_UNROLLING_LIMIT -#define EIGEN_UNROLLING_LIMIT 110 -#endif - -/** Defines the threshold between a "small" and a "large" matrix. - * This threshold is mainly used to select the proper product implementation. - */ -#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD -#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 -#endif - -/** Defines the maximal width of the blocks used in the triangular product and solver - * for vectors (level 2 blas xTRMV and xTRSV). The default is 8. - */ -#ifndef EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH -#define EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH 8 -#endif - - -/** Defines the default number of registers available for that architecture. - * Currently it must be 8 or 16. Other values will fail. - */ -#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 8 -#endif - -#endif // EIGEN_DEFAULT_SETTINGS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/TypeCasting.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/TypeCasting.h deleted file mode 100644 index b6df9846..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/Default/TypeCasting.h +++ /dev/null @@ -1,77 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> -// Copyright (C) 2019 Rasmus Munk Larsen <rmlarsen@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERIC_TYPE_CASTING_H -#define EIGEN_GENERIC_TYPE_CASTING_H - -namespace Eigen { - -namespace internal { - -template<> -struct scalar_cast_op<float, Eigen::half> { - EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op) - typedef Eigen::half result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half operator() (const float& a) const { - #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - return __float2half(a); - #else - return Eigen::half(a); - #endif - } -}; - -template<> -struct functor_traits<scalar_cast_op<float, Eigen::half> > -{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; }; - - -template<> -struct scalar_cast_op<int, Eigen::half> { - EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op) - typedef Eigen::half result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half operator() (const int& a) const { - #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - return __float2half(static_cast<float>(a)); - #else - return Eigen::half(static_cast<float>(a)); - #endif - } -}; - -template<> -struct functor_traits<scalar_cast_op<int, Eigen::half> > -{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; }; - - -template<> -struct scalar_cast_op<Eigen::half, float> { - EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op) - typedef float result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float operator() (const Eigen::half& a) const { - #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - return __half2float(a); - #else - return static_cast<float>(a); - #endif - } -}; - -template<> -struct functor_traits<scalar_cast_op<Eigen::half, float> > -{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; }; - -} -} - -#endif // EIGEN_GENERIC_TYPE_CASTING_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/MathFunctions.h deleted file mode 100644 index d2b3a256..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/MathFunctions.h +++ /dev/null @@ -1,103 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATH_FUNCTIONS_GPU_H -#define EIGEN_MATH_FUNCTIONS_GPU_H - -namespace Eigen { - -namespace internal { - -// Make sure this is only available when targeting a GPU: we don't want to -// introduce conflicts between these packet_traits definitions and the ones -// we'll use on the host side (SSE, AVX, ...) -#if defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU) -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 plog<float4>(const float4& a) -{ - return make_float4(logf(a.x), logf(a.y), logf(a.z), logf(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 plog<double2>(const double2& a) -{ - using ::log; - return make_double2(log(a.x), log(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 plog1p<float4>(const float4& a) -{ - return make_float4(log1pf(a.x), log1pf(a.y), log1pf(a.z), log1pf(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 plog1p<double2>(const double2& a) -{ - return make_double2(log1p(a.x), log1p(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 pexp<float4>(const float4& a) -{ - return make_float4(expf(a.x), expf(a.y), expf(a.z), expf(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 pexp<double2>(const double2& a) -{ - using ::exp; - return make_double2(exp(a.x), exp(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 pexpm1<float4>(const float4& a) -{ - return make_float4(expm1f(a.x), expm1f(a.y), expm1f(a.z), expm1f(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 pexpm1<double2>(const double2& a) -{ - return make_double2(expm1(a.x), expm1(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 psqrt<float4>(const float4& a) -{ - return make_float4(sqrtf(a.x), sqrtf(a.y), sqrtf(a.z), sqrtf(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 psqrt<double2>(const double2& a) -{ - using ::sqrt; - return make_double2(sqrt(a.x), sqrt(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 prsqrt<float4>(const float4& a) -{ - return make_float4(rsqrtf(a.x), rsqrtf(a.y), rsqrtf(a.z), rsqrtf(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 prsqrt<double2>(const double2& a) -{ - return make_double2(rsqrt(a.x), rsqrt(a.y)); -} - - -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATH_FUNCTIONS_GPU_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/PacketMath.h deleted file mode 100644 index 9e18c514..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/PacketMath.h +++ /dev/null @@ -1,1040 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PACKET_MATH_GPU_H -#define EIGEN_PACKET_MATH_GPU_H - -namespace Eigen { - -namespace internal { - -// Make sure this is only available when targeting a GPU: we don't want to -// introduce conflicts between these packet_traits definitions and the ones -// we'll use on the host side (SSE, AVX, ...) -#if defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU) -template<> struct is_arithmetic<float4> { enum { value = true }; }; -template<> struct is_arithmetic<double2> { enum { value = true }; }; - -template<> struct packet_traits<float> : default_packet_traits -{ - typedef float4 type; - typedef float4 half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=4, - HasHalfPacket = 0, - - HasDiv = 1, - HasSin = 0, - HasCos = 0, - HasLog = 1, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasLGamma = 1, - HasDiGamma = 1, - HasZeta = 1, - HasPolygamma = 1, - HasErf = 1, - HasErfc = 1, - HasNdtri = 1, - HasBessel = 1, - HasIGamma = 1, - HasIGammaDerA = 1, - HasGammaSampleDerAlpha = 1, - HasIGammac = 1, - HasBetaInc = 1, - - HasBlend = 0, - HasFloor = 1, - }; -}; - -template<> struct packet_traits<double> : default_packet_traits -{ - typedef double2 type; - typedef double2 half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=2, - HasHalfPacket = 0, - - HasDiv = 1, - HasLog = 1, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasLGamma = 1, - HasDiGamma = 1, - HasZeta = 1, - HasPolygamma = 1, - HasErf = 1, - HasErfc = 1, - HasNdtri = 1, - HasBessel = 1, - HasIGamma = 1, - HasIGammaDerA = 1, - HasGammaSampleDerAlpha = 1, - HasIGammac = 1, - HasBetaInc = 1, - - HasBlend = 0, - HasFloor = 1, - }; -}; - - -template<> struct unpacket_traits<float4> { typedef float type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef float4 half; }; -template<> struct unpacket_traits<double2> { typedef double type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef double2 half; }; - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pset1<float4>(const float& from) { - return make_float4(from, from, from, from); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pset1<double2>(const double& from) { - return make_double2(from, from); -} - -// We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler, -// invoked by NVCC’ (e.g. on MacOS). The former needs to see both host and device implementation -// of the functions, while the latter can only deal with one of them. -#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC) -namespace { - -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_and(const float& a, - const float& b) { - return __int_as_float(__float_as_int(a) & __float_as_int(b)); -} -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bitwise_and(const double& a, - const double& b) { - return __longlong_as_double(__double_as_longlong(a) & - __double_as_longlong(b)); -} - -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_or(const float& a, - const float& b) { - return __int_as_float(__float_as_int(a) | __float_as_int(b)); -} -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bitwise_or(const double& a, - const double& b) { - return __longlong_as_double(__double_as_longlong(a) | - __double_as_longlong(b)); -} - -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_xor(const float& a, - const float& b) { - return __int_as_float(__float_as_int(a) ^ __float_as_int(b)); -} -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bitwise_xor(const double& a, - const double& b) { - return __longlong_as_double(__double_as_longlong(a) ^ - __double_as_longlong(b)); -} - -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_andnot(const float& a, - const float& b) { - return __int_as_float(__float_as_int(a) & ~__float_as_int(b)); -} -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bitwise_andnot(const double& a, - const double& b) { - return __longlong_as_double(__double_as_longlong(a) & - ~__double_as_longlong(b)); -} -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float eq_mask(const float& a, - const float& b) { - return __int_as_float(a == b ? 0xffffffffu : 0u); -} -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double eq_mask(const double& a, - const double& b) { - return __longlong_as_double(a == b ? 0xffffffffffffffffull : 0ull); -} - -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float lt_mask(const float& a, - const float& b) { - return __int_as_float(a < b ? 0xffffffffu : 0u); -} -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double lt_mask(const double& a, - const double& b) { - return __longlong_as_double(a < b ? 0xffffffffffffffffull : 0ull); -} - -} // namespace - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pand<float4>(const float4& a, - const float4& b) { - return make_float4(bitwise_and(a.x, b.x), bitwise_and(a.y, b.y), - bitwise_and(a.z, b.z), bitwise_and(a.w, b.w)); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pand<double2>(const double2& a, - const double2& b) { - return make_double2(bitwise_and(a.x, b.x), bitwise_and(a.y, b.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 por<float4>(const float4& a, - const float4& b) { - return make_float4(bitwise_or(a.x, b.x), bitwise_or(a.y, b.y), - bitwise_or(a.z, b.z), bitwise_or(a.w, b.w)); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 por<double2>(const double2& a, - const double2& b) { - return make_double2(bitwise_or(a.x, b.x), bitwise_or(a.y, b.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pxor<float4>(const float4& a, - const float4& b) { - return make_float4(bitwise_xor(a.x, b.x), bitwise_xor(a.y, b.y), - bitwise_xor(a.z, b.z), bitwise_xor(a.w, b.w)); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pxor<double2>(const double2& a, - const double2& b) { - return make_double2(bitwise_xor(a.x, b.x), bitwise_xor(a.y, b.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pandnot<float4>(const float4& a, - const float4& b) { - return make_float4(bitwise_andnot(a.x, b.x), bitwise_andnot(a.y, b.y), - bitwise_andnot(a.z, b.z), bitwise_andnot(a.w, b.w)); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pandnot<double2>(const double2& a, const double2& b) { - return make_double2(bitwise_andnot(a.x, b.x), bitwise_andnot(a.y, b.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcmp_eq<float4>(const float4& a, - const float4& b) { - return make_float4(eq_mask(a.x, b.x), eq_mask(a.y, b.y), eq_mask(a.z, b.z), - eq_mask(a.w, b.w)); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcmp_lt<float4>(const float4& a, - const float4& b) { - return make_float4(lt_mask(a.x, b.x), lt_mask(a.y, b.y), lt_mask(a.z, b.z), - lt_mask(a.w, b.w)); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pcmp_eq<double2>(const double2& a, const double2& b) { - return make_double2(eq_mask(a.x, b.x), eq_mask(a.y, b.y)); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pcmp_lt<double2>(const double2& a, const double2& b) { - return make_double2(lt_mask(a.x, b.x), lt_mask(a.y, b.y)); -} -#endif // EIGEN_CUDA_ARCH || defined(EIGEN_HIP_DEVICE_COMPILE) - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plset<float4>(const float& a) { - return make_float4(a, a+1, a+2, a+3); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 plset<double2>(const double& a) { - return make_double2(a, a+1); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 padd<float4>(const float4& a, const float4& b) { - return make_float4(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 padd<double2>(const double2& a, const double2& b) { - return make_double2(a.x+b.x, a.y+b.y); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 psub<float4>(const float4& a, const float4& b) { - return make_float4(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 psub<double2>(const double2& a, const double2& b) { - return make_double2(a.x-b.x, a.y-b.y); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pnegate(const float4& a) { - return make_float4(-a.x, -a.y, -a.z, -a.w); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pnegate(const double2& a) { - return make_double2(-a.x, -a.y); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pconj(const float4& a) { return a; } -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pconj(const double2& a) { return a; } - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmul<float4>(const float4& a, const float4& b) { - return make_float4(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmul<double2>(const double2& a, const double2& b) { - return make_double2(a.x*b.x, a.y*b.y); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pdiv<float4>(const float4& a, const float4& b) { - return make_float4(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pdiv<double2>(const double2& a, const double2& b) { - return make_double2(a.x/b.x, a.y/b.y); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmin<float4>(const float4& a, const float4& b) { - return make_float4(fminf(a.x, b.x), fminf(a.y, b.y), fminf(a.z, b.z), fminf(a.w, b.w)); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmin<double2>(const double2& a, const double2& b) { - return make_double2(fmin(a.x, b.x), fmin(a.y, b.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmax<float4>(const float4& a, const float4& b) { - return make_float4(fmaxf(a.x, b.x), fmaxf(a.y, b.y), fmaxf(a.z, b.z), fmaxf(a.w, b.w)); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmax<double2>(const double2& a, const double2& b) { - return make_double2(fmax(a.x, b.x), fmax(a.y, b.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pload<float4>(const float* from) { - return *reinterpret_cast<const float4*>(from); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pload<double2>(const double* from) { - return *reinterpret_cast<const double2*>(from); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 ploadu<float4>(const float* from) { - return make_float4(from[0], from[1], from[2], from[3]); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 ploadu<double2>(const double* from) { - return make_double2(from[0], from[1]); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 ploaddup<float4>(const float* from) { - return make_float4(from[0], from[0], from[1], from[1]); -} -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 ploaddup<double2>(const double* from) { - return make_double2(from[0], from[0]); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstore<float>(float* to, const float4& from) { - *reinterpret_cast<float4*>(to) = from; -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstore<double>(double* to, const double2& from) { - *reinterpret_cast<double2*>(to) = from; -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const float4& from) { - to[0] = from.x; - to[1] = from.y; - to[2] = from.z; - to[3] = from.w; -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const double2& from) { - to[0] = from.x; - to[1] = from.y; -} - -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float4 ploadt_ro<float4, Aligned>(const float* from) { -#if defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350 - return __ldg((const float4*)from); -#else - return make_float4(from[0], from[1], from[2], from[3]); -#endif -} -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double2 ploadt_ro<double2, Aligned>(const double* from) { -#if defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350 - return __ldg((const double2*)from); -#else - return make_double2(from[0], from[1]); -#endif -} - -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float4 ploadt_ro<float4, Unaligned>(const float* from) { -#if defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350 - return make_float4(__ldg(from+0), __ldg(from+1), __ldg(from+2), __ldg(from+3)); -#else - return make_float4(from[0], from[1], from[2], from[3]); -#endif -} -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double2 ploadt_ro<double2, Unaligned>(const double* from) { -#if defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350 - return make_double2(__ldg(from+0), __ldg(from+1)); -#else - return make_double2(from[0], from[1]); -#endif -} - -template<> EIGEN_DEVICE_FUNC inline float4 pgather<float, float4>(const float* from, Index stride) { - return make_float4(from[0*stride], from[1*stride], from[2*stride], from[3*stride]); -} - -template<> EIGEN_DEVICE_FUNC inline double2 pgather<double, double2>(const double* from, Index stride) { - return make_double2(from[0*stride], from[1*stride]); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<float, float4>(float* to, const float4& from, Index stride) { - to[stride*0] = from.x; - to[stride*1] = from.y; - to[stride*2] = from.z; - to[stride*3] = from.w; -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<double, double2>(double* to, const double2& from, Index stride) { - to[stride*0] = from.x; - to[stride*1] = from.y; -} - -template<> EIGEN_DEVICE_FUNC inline float pfirst<float4>(const float4& a) { - return a.x; -} -template<> EIGEN_DEVICE_FUNC inline double pfirst<double2>(const double2& a) { - return a.x; -} - -template<> EIGEN_DEVICE_FUNC inline float predux<float4>(const float4& a) { - return a.x + a.y + a.z + a.w; -} -template<> EIGEN_DEVICE_FUNC inline double predux<double2>(const double2& a) { - return a.x + a.y; -} - -template<> EIGEN_DEVICE_FUNC inline float predux_max<float4>(const float4& a) { - return fmaxf(fmaxf(a.x, a.y), fmaxf(a.z, a.w)); -} -template<> EIGEN_DEVICE_FUNC inline double predux_max<double2>(const double2& a) { - return fmax(a.x, a.y); -} - -template<> EIGEN_DEVICE_FUNC inline float predux_min<float4>(const float4& a) { - return fminf(fminf(a.x, a.y), fminf(a.z, a.w)); -} -template<> EIGEN_DEVICE_FUNC inline double predux_min<double2>(const double2& a) { - return fmin(a.x, a.y); -} - -template<> EIGEN_DEVICE_FUNC inline float predux_mul<float4>(const float4& a) { - return a.x * a.y * a.z * a.w; -} -template<> EIGEN_DEVICE_FUNC inline double predux_mul<double2>(const double2& a) { - return a.x * a.y; -} - -template<> EIGEN_DEVICE_FUNC inline float4 pabs<float4>(const float4& a) { - return make_float4(fabsf(a.x), fabsf(a.y), fabsf(a.z), fabsf(a.w)); -} -template<> EIGEN_DEVICE_FUNC inline double2 pabs<double2>(const double2& a) { - return make_double2(fabs(a.x), fabs(a.y)); -} - -template<> EIGEN_DEVICE_FUNC inline float4 pfloor<float4>(const float4& a) { - return make_float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w)); -} -template<> EIGEN_DEVICE_FUNC inline double2 pfloor<double2>(const double2& a) { - return make_double2(floor(a.x), floor(a.y)); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<float4,4>& kernel) { - float tmp = kernel.packet[0].y; - kernel.packet[0].y = kernel.packet[1].x; - kernel.packet[1].x = tmp; - - tmp = kernel.packet[0].z; - kernel.packet[0].z = kernel.packet[2].x; - kernel.packet[2].x = tmp; - - tmp = kernel.packet[0].w; - kernel.packet[0].w = kernel.packet[3].x; - kernel.packet[3].x = tmp; - - tmp = kernel.packet[1].z; - kernel.packet[1].z = kernel.packet[2].y; - kernel.packet[2].y = tmp; - - tmp = kernel.packet[1].w; - kernel.packet[1].w = kernel.packet[3].y; - kernel.packet[3].y = tmp; - - tmp = kernel.packet[2].w; - kernel.packet[2].w = kernel.packet[3].z; - kernel.packet[3].z = tmp; -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<double2,2>& kernel) { - double tmp = kernel.packet[0].y; - kernel.packet[0].y = kernel.packet[1].x; - kernel.packet[1].x = tmp; -} - -#endif - -// Packet math for Eigen::half -// Most of the following operations require arch >= 3.0 -#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDACC) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIPCC) && defined(EIGEN_HIP_DEVICE_COMPILE)) || \ - (defined(EIGEN_HAS_CUDA_FP16) && defined(__clang__) && defined(__CUDA__)) - -template<> struct is_arithmetic<half2> { enum { value = true }; }; - -template<> struct packet_traits<Eigen::half> : default_packet_traits -{ - typedef half2 type; - typedef half2 half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=2, - HasHalfPacket = 0, - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasExp = 1, - HasExpm1 = 1, - HasLog = 1, - HasLog1p = 1 - }; -}; - -template<> struct unpacket_traits<half2> { typedef Eigen::half type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef half2 half; }; - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pset1<half2>(const Eigen::half& from) { -#if !defined(EIGEN_CUDA_ARCH) && !defined(EIGEN_HIP_DEVICE_COMPILE) - half2 r; - r.x = from; - r.y = from; - return r; -#else - return __half2half2(from); -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pload<half2>(const Eigen::half* from) { - return *reinterpret_cast<const half2*>(from); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ploadu<half2>(const Eigen::half* from) { - return __halves2half2(from[0], from[1]); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ploaddup<half2>(const Eigen::half* from) { - return __halves2half2(from[0], from[0]); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const half2& from) { - *reinterpret_cast<half2*>(to) = from; -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const half2& from) { -#if !defined(EIGEN_CUDA_ARCH) && !defined(EIGEN_HIP_DEVICE_COMPILE) - to[0] = from.x; - to[1] = from.y; -#else - to[0] = __low2half(from); - to[1] = __high2half(from); -#endif -} - -template<> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE half2 ploadt_ro<half2, Aligned>(const Eigen::half* from) { - -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __ldg((const half2*)from); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 350 - return __ldg((const half2*)from); -#else - return __halves2half2(*(from+0), *(from+1)); -#endif - -#endif -} - -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE half2 ploadt_ro<half2, Unaligned>(const Eigen::half* from) { - -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __halves2half2(__ldg(from+0), __ldg(from+1)); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 350 - return __halves2half2(__ldg(from+0), __ldg(from+1)); -#else - return __halves2half2(*(from+0), *(from+1)); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pgather<Eigen::half, half2>(const Eigen::half* from, Index stride) { - return __halves2half2(from[0*stride], from[1*stride]); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<Eigen::half, half2>(Eigen::half* to, const half2& from, Index stride) { - to[stride*0] = __low2half(from); - to[stride*1] = __high2half(from); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half pfirst<half2>(const half2& a) { - return __low2half(a); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pabs<half2>(const half2& a) { - half a1 = __low2half(a); - half a2 = __high2half(a); - half result1 = half_impl::raw_uint16_to_half(a1.x & 0x7FFF); - half result2 = half_impl::raw_uint16_to_half(a2.x & 0x7FFF); - return __halves2half2(result1, result2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ptrue<half2>(const half2& a) { - half true_half = half_impl::raw_uint16_to_half(0xffffu); - return pset1<half2>(true_half); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pzero<half2>(const half2& a) { - half false_half = half_impl::raw_uint16_to_half(0x0000u); - return pset1<half2>(false_half); -} - -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void -ptranspose(PacketBlock<half2,2>& kernel) { - __half a1 = __low2half(kernel.packet[0]); - __half a2 = __high2half(kernel.packet[0]); - __half b1 = __low2half(kernel.packet[1]); - __half b2 = __high2half(kernel.packet[1]); - kernel.packet[0] = __halves2half2(a1, b1); - kernel.packet[1] = __halves2half2(a2, b2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plset<half2>(const Eigen::half& a) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __halves2half2(a, __hadd(a, __float2half(1.0f))); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - return __halves2half2(a, __hadd(a, __float2half(1.0f))); -#else - float f = __half2float(a) + 1.0f; - return __halves2half2(a, __float2half(f)); -#endif - -#endif -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pselect<half2>(const half2& mask, - const half2& a, - const half2& b) { - half mask_low = __low2half(mask); - half mask_high = __high2half(mask); - half result_low = mask_low == half(0) ? __low2half(b) : __low2half(a); - half result_high = mask_high == half(0) ? __high2half(b) : __high2half(a); - return __halves2half2(result_low, result_high); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcmp_eq<half2>(const half2& a, - const half2& b) { - half true_half = half_impl::raw_uint16_to_half(0xffffu); - half false_half = half_impl::raw_uint16_to_half(0x0000u); - half a1 = __low2half(a); - half a2 = __high2half(a); - half b1 = __low2half(b); - half b2 = __high2half(b); - half eq1 = __half2float(a1) == __half2float(b1) ? true_half : false_half; - half eq2 = __half2float(a2) == __half2float(b2) ? true_half : false_half; - return __halves2half2(eq1, eq2); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcmp_lt<half2>(const half2& a, - const half2& b) { - half true_half = half_impl::raw_uint16_to_half(0xffffu); - half false_half = half_impl::raw_uint16_to_half(0x0000u); - half a1 = __low2half(a); - half a2 = __high2half(a); - half b1 = __low2half(b); - half b2 = __high2half(b); - half eq1 = __half2float(a1) < __half2float(b1) ? true_half : false_half; - half eq2 = __half2float(a2) < __half2float(b2) ? true_half : false_half; - return __halves2half2(eq1, eq2); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pand<half2>(const half2& a, - const half2& b) { - half a1 = __low2half(a); - half a2 = __high2half(a); - half b1 = __low2half(b); - half b2 = __high2half(b); - half result1 = half_impl::raw_uint16_to_half(a1.x & b1.x); - half result2 = half_impl::raw_uint16_to_half(a2.x & b2.x); - return __halves2half2(result1, result2); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 por<half2>(const half2& a, - const half2& b) { - half a1 = __low2half(a); - half a2 = __high2half(a); - half b1 = __low2half(b); - half b2 = __high2half(b); - half result1 = half_impl::raw_uint16_to_half(a1.x | b1.x); - half result2 = half_impl::raw_uint16_to_half(a2.x | b2.x); - return __halves2half2(result1, result2); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pxor<half2>(const half2& a, - const half2& b) { - half a1 = __low2half(a); - half a2 = __high2half(a); - half b1 = __low2half(b); - half b2 = __high2half(b); - half result1 = half_impl::raw_uint16_to_half(a1.x ^ b1.x); - half result2 = half_impl::raw_uint16_to_half(a2.x ^ b2.x); - return __halves2half2(result1, result2); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pandnot<half2>(const half2& a, - const half2& b) { - half a1 = __low2half(a); - half a2 = __high2half(a); - half b1 = __low2half(b); - half b2 = __high2half(b); - half result1 = half_impl::raw_uint16_to_half(a1.x & ~b1.x); - half result2 = half_impl::raw_uint16_to_half(a2.x & ~b2.x); - return __halves2half2(result1, result2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 padd<half2>(const half2& a, const half2& b) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __hadd2(a, b); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - return __hadd2(a, b); -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - float b1 = __low2float(b); - float b2 = __high2float(b); - float r1 = a1 + b1; - float r2 = a2 + b2; - return __floats2half2_rn(r1, r2); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 psub<half2>(const half2& a, const half2& b) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __hsub2(a, b); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - return __hsub2(a, b); -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - float b1 = __low2float(b); - float b2 = __high2float(b); - float r1 = a1 - b1; - float r2 = a2 - b2; - return __floats2half2_rn(r1, r2); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pnegate(const half2& a) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __hneg2(a); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - return __hneg2(a); -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - return __floats2half2_rn(-a1, -a2); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pconj(const half2& a) { return a; } - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmul<half2>(const half2& a, const half2& b) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __hmul2(a, b); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - return __hmul2(a, b); -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - float b1 = __low2float(b); - float b2 = __high2float(b); - float r1 = a1 * b1; - float r2 = a2 * b2; - return __floats2half2_rn(r1, r2); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmadd<half2>(const half2& a, const half2& b, const half2& c) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __hfma2(a, b, c); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - return __hfma2(a, b, c); -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - float b1 = __low2float(b); - float b2 = __high2float(b); - float c1 = __low2float(c); - float c2 = __high2float(c); - float r1 = a1 * b1 + c1; - float r2 = a2 * b2 + c2; - return __floats2half2_rn(r1, r2); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pdiv<half2>(const half2& a, const half2& b) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __h2div(a, b); - -#else // EIGEN_CUDA_ARCH - - float a1 = __low2float(a); - float a2 = __high2float(a); - float b1 = __low2float(b); - float b2 = __high2float(b); - float r1 = a1 / b1; - float r2 = a2 / b2; - return __floats2half2_rn(r1, r2); - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmin<half2>(const half2& a, const half2& b) { - float a1 = __low2float(a); - float a2 = __high2float(a); - float b1 = __low2float(b); - float b2 = __high2float(b); - __half r1 = a1 < b1 ? __low2half(a) : __low2half(b); - __half r2 = a2 < b2 ? __high2half(a) : __high2half(b); - return __halves2half2(r1, r2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmax<half2>(const half2& a, const half2& b) { - float a1 = __low2float(a); - float a2 = __high2float(a); - float b1 = __low2float(b); - float b2 = __high2float(b); - __half r1 = a1 > b1 ? __low2half(a) : __low2half(b); - __half r2 = a2 > b2 ? __high2half(a) : __high2half(b); - return __halves2half2(r1, r2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux<half2>(const half2& a) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __hadd(__low2half(a), __high2half(a)); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - return __hadd(__low2half(a), __high2half(a)); -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - return Eigen::half(__float2half(a1 + a2)); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_max<half2>(const half2& a) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - __half first = __low2half(a); - __half second = __high2half(a); - return __hgt(first, second) ? first : second; - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - __half first = __low2half(a); - __half second = __high2half(a); - return __hgt(first, second) ? first : second; -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - return a1 > a2 ? __low2half(a) : __high2half(a); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_min<half2>(const half2& a) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - __half first = __low2half(a); - __half second = __high2half(a); - return __hlt(first, second) ? first : second; - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - __half first = __low2half(a); - __half second = __high2half(a); - return __hlt(first, second) ? first : second; -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - return a1 < a2 ? __low2half(a) : __high2half(a); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_mul<half2>(const half2& a) { -#if defined(EIGEN_HIP_DEVICE_COMPILE) - - return __hmul(__low2half(a), __high2half(a)); - -#else // EIGEN_CUDA_ARCH - -#if EIGEN_CUDA_ARCH >= 530 - return __hmul(__low2half(a), __high2half(a)); -#else - float a1 = __low2float(a); - float a2 = __high2float(a); - return Eigen::half(__float2half(a1 * a2)); -#endif - -#endif -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plog1p<half2>(const half2& a) { - float a1 = __low2float(a); - float a2 = __high2float(a); - float r1 = log1pf(a1); - float r2 = log1pf(a2); - return __floats2half2_rn(r1, r2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pexpm1<half2>(const half2& a) { - float a1 = __low2float(a); - float a2 = __high2float(a); - float r1 = expm1f(a1); - float r2 = expm1f(a2); - return __floats2half2_rn(r1, r2); -} - -#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \ - defined(EIGEN_HIP_DEVICE_COMPILE) - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -half2 plog<half2>(const half2& a) { - return h2log(a); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -half2 pexp<half2>(const half2& a) { - return h2exp(a); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -half2 psqrt<half2>(const half2& a) { - return h2sqrt(a); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -half2 prsqrt<half2>(const half2& a) { - return h2rsqrt(a); -} - -#else - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plog<half2>(const half2& a) { - float a1 = __low2float(a); - float a2 = __high2float(a); - float r1 = logf(a1); - float r2 = logf(a2); - return __floats2half2_rn(r1, r2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pexp<half2>(const half2& a) { - float a1 = __low2float(a); - float a2 = __high2float(a); - float r1 = expf(a1); - float r2 = expf(a2); - return __floats2half2_rn(r1, r2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 psqrt<half2>(const half2& a) { - float a1 = __low2float(a); - float a2 = __high2float(a); - float r1 = sqrtf(a1); - float r2 = sqrtf(a2); - return __floats2half2_rn(r1, r2); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 prsqrt<half2>(const half2& a) { - float a1 = __low2float(a); - float a2 = __high2float(a); - float r1 = rsqrtf(a1); - float r2 = rsqrtf(a2); - return __floats2half2_rn(r1, r2); -} -#endif - -#endif - -} // end namespace internal - -} // end namespace Eigen - - -#endif // EIGEN_PACKET_MATH_GPU_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/TypeCasting.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/TypeCasting.h deleted file mode 100644 index c278f3fe..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/GPU/TypeCasting.h +++ /dev/null @@ -1,55 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TYPE_CASTING_GPU_H -#define EIGEN_TYPE_CASTING_GPU_H - -namespace Eigen { - -namespace internal { - -#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \ - (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE)) - -template <> -struct type_casting_traits<Eigen::half, float> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 2, - TgtCoeffRatio = 1 - }; -}; - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast<half2, float4>(const half2& a, const half2& b) { - float2 r1 = __half22float2(a); - float2 r2 = __half22float2(b); - return make_float4(r1.x, r1.y, r2.x, r2.y); -} - -template <> -struct type_casting_traits<float, Eigen::half> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 2 - }; -}; - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcast<float4, half2>(const float4& a) { - // Simply discard the second half of the input - return __floats2half2_rn(a.x, a.y); -} - -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TYPE_CASTING_GPU_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/HIP/hcc/math_constants.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/HIP/hcc/math_constants.h deleted file mode 100644 index 25375a0a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/HIP/hcc/math_constants.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * math_constants.h - - * HIP equivalent of the CUDA header of the same name - */ - -#ifndef __MATH_CONSTANTS_H__ -#define __MATH_CONSTANTS_H__ - -/* single precision constants */ - -#define HIPRT_INF_F __int_as_float(0x7f800000) -#define HIPRT_NAN_F __int_as_float(0x7fffffff) -#define HIPRT_MIN_DENORM_F __int_as_float(0x00000001) -#define HIPRT_MAX_NORMAL_F __int_as_float(0x7f7fffff) -#define HIPRT_NEG_ZERO_F __int_as_float(0x80000000) -#define HIPRT_ZERO_F 0.0f -#define HIPRT_ONE_F 1.0f - -/* double precision constants */ -#define HIPRT_INF __hiloint2double(0x7ff00000, 0x00000000) -#define HIPRT_NAN __hiloint2double(0xfff80000, 0x00000000) - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/Complex.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/Complex.h deleted file mode 100644 index c09e1e4f..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/Complex.h +++ /dev/null @@ -1,759 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2018 Wave Computing, Inc. -// Written by: -// Chris Larsen -// Alexey Frunze (afrunze@wavecomp.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX_MSA_H -#define EIGEN_COMPLEX_MSA_H - -#include <iostream> - -namespace Eigen { - -namespace internal { - -//---------- float ---------- -struct Packet2cf { - EIGEN_STRONG_INLINE Packet2cf() { - } - EIGEN_STRONG_INLINE explicit Packet2cf(const std::complex<float>& a, - const std::complex<float>& b) { - Packet4f t = { std::real(a), std::imag(a), std::real(b), std::imag(b) }; - v = t; - } - EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) { - } - EIGEN_STRONG_INLINE Packet2cf(const Packet2cf& a) : v(a.v) { - } - EIGEN_STRONG_INLINE Packet2cf& operator=(const Packet2cf& b) { - v = b.v; - return *this; - } - EIGEN_STRONG_INLINE Packet2cf conjugate(void) const { - return Packet2cf((Packet4f)__builtin_msa_bnegi_d((v2u64)v, 63)); - } - EIGEN_STRONG_INLINE Packet2cf& operator*=(const Packet2cf& b) { - Packet4f v1, v2; - - // Get the real values of a | a1_re | a1_re | a2_re | a2_re | - v1 = (Packet4f)__builtin_msa_ilvev_w((v4i32)v, (v4i32)v); - // Get the imag values of a | a1_im | a1_im | a2_im | a2_im | - v2 = (Packet4f)__builtin_msa_ilvod_w((v4i32)v, (v4i32)v); - // Multiply the real a with b - v1 = pmul(v1, b.v); - // Multiply the imag a with b - v2 = pmul(v2, b.v); - // Conjugate v2 - v2 = Packet2cf(v2).conjugate().v; - // Swap real/imag elements in v2. - v2 = (Packet4f)__builtin_msa_shf_w((v4i32)v2, EIGEN_MSA_SHF_I8(1, 0, 3, 2)); - // Add and return the result - v = padd(v1, v2); - return *this; - } - EIGEN_STRONG_INLINE Packet2cf operator*(const Packet2cf& b) const { - return Packet2cf(*this) *= b; - } - EIGEN_STRONG_INLINE Packet2cf& operator+=(const Packet2cf& b) { - v = padd(v, b.v); - return *this; - } - EIGEN_STRONG_INLINE Packet2cf operator+(const Packet2cf& b) const { - return Packet2cf(*this) += b; - } - EIGEN_STRONG_INLINE Packet2cf& operator-=(const Packet2cf& b) { - v = psub(v, b.v); - return *this; - } - EIGEN_STRONG_INLINE Packet2cf operator-(const Packet2cf& b) const { - return Packet2cf(*this) -= b; - } - EIGEN_STRONG_INLINE Packet2cf& operator/=(const Packet2cf& b) { - *this *= b.conjugate(); - Packet4f s = pmul<Packet4f>(b.v, b.v); - s = padd(s, (Packet4f)__builtin_msa_shf_w((v4i32)s, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); - v = pdiv(v, s); - return *this; - } - EIGEN_STRONG_INLINE Packet2cf operator/(const Packet2cf& b) const { - return Packet2cf(*this) /= b; - } - EIGEN_STRONG_INLINE Packet2cf operator-(void) const { - return Packet2cf(pnegate(v)); - } - - Packet4f v; -}; - -inline std::ostream& operator<<(std::ostream& os, const Packet2cf& value) { - os << "[ (" << value.v[0] << ", " << value.v[1] - << "i)," - " (" - << value.v[2] << ", " << value.v[3] << "i) ]"; - return os; -} - -template <> -struct packet_traits<std::complex<float> > : default_packet_traits { - typedef Packet2cf type; - typedef Packet2cf half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 2, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0, - HasBlend = 1 - }; -}; - -template <> -struct unpacket_traits<Packet2cf> { - typedef std::complex<float> type; - enum { size = 2, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false }; - typedef Packet2cf half; -}; - -template <> -EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from) { - EIGEN_MSA_DEBUG; - - float f0 = from.real(), f1 = from.imag(); - Packet4f v0 = { f0, f0, f0, f0 }; - Packet4f v1 = { f1, f1, f1, f1 }; - return Packet2cf((Packet4f)__builtin_msa_ilvr_w((Packet4i)v1, (Packet4i)v0)); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { - EIGEN_MSA_DEBUG; - - return a + b; -} - -template <> -EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { - EIGEN_MSA_DEBUG; - - return a - b; -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { - EIGEN_MSA_DEBUG; - - return -a; -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) { - EIGEN_MSA_DEBUG; - - return a.conjugate(); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { - EIGEN_MSA_DEBUG; - - return a * b; -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pand<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { - EIGEN_MSA_DEBUG; - - return Packet2cf(pand(a.v, b.v)); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf por<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { - EIGEN_MSA_DEBUG; - - return Packet2cf(por(a.v, b.v)); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pxor<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { - EIGEN_MSA_DEBUG; - - return Packet2cf(pxor(a.v, b.v)); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { - EIGEN_MSA_DEBUG; - - return Packet2cf(pandnot(a.v, b.v)); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>((const float*)from)); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>((const float*)from)); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { - EIGEN_MSA_DEBUG; - - return pset1<Packet2cf>(*from); -} - -template <> -EIGEN_STRONG_INLINE void pstore<std::complex<float> >(std::complex<float>* to, - const Packet2cf& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_STORE pstore<float>((float*)to, from.v); -} - -template <> -EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float>* to, - const Packet2cf& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_STORE pstoreu<float>((float*)to, from.v); -} - -template <> -EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>( - const std::complex<float>* from, Index stride) { - EIGEN_MSA_DEBUG; - - return Packet2cf(from[0 * stride], from[1 * stride]); -} - -template <> -EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, - const Packet2cf& from, - Index stride) { - EIGEN_MSA_DEBUG; - - *to = std::complex<float>(from.v[0], from.v[1]); - to += stride; - *to = std::complex<float>(from.v[2], from.v[3]); -} - -template <> -EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float>* addr) { - EIGEN_MSA_DEBUG; - - prefetch(reinterpret_cast<const float*>(addr)); -} - -template <> -EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a) { - EIGEN_MSA_DEBUG; - - return std::complex<float>(a.v[0], a.v[1]); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) { - EIGEN_MSA_DEBUG; - - return Packet2cf((Packet4f)__builtin_msa_shf_w((v4i32)a.v, EIGEN_MSA_SHF_I8(2, 3, 0, 1))); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& a) { - EIGEN_MSA_DEBUG; - - return Packet2cf((Packet4f)__builtin_msa_shf_w((v4i32)a.v, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); -} - -template <> -EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a) { - EIGEN_MSA_DEBUG; - - Packet4f value = (Packet4f)preverse((Packet2d)a.v); - value += a.v; - return std::complex<float>(value[0], value[1]); -} - -template <> -EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs) { - EIGEN_MSA_DEBUG; - - Packet4f sum1, sum2, sum; - - // Add the first two 64-bit float32x2_t of vecs[0] - sum1 = (Packet4f)__builtin_msa_ilvr_d((v2i64)vecs[1].v, (v2i64)vecs[0].v); - sum2 = (Packet4f)__builtin_msa_ilvl_d((v2i64)vecs[1].v, (v2i64)vecs[0].v); - sum = padd(sum1, sum2); - - return Packet2cf(sum); -} - -template <> -EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a) { - EIGEN_MSA_DEBUG; - - return std::complex<float>((a.v[0] * a.v[2]) - (a.v[1] * a.v[3]), - (a.v[0] * a.v[3]) + (a.v[1] * a.v[2])); -} - -template <int Offset> -struct palign_impl<Offset, Packet2cf> { - EIGEN_STRONG_INLINE static void run(Packet2cf& first, const Packet2cf& second) { - if (Offset == 1) { - first.v = (Packet4f)__builtin_msa_sldi_b((v16i8)second.v, (v16i8)first.v, Offset * 8); - } - } -}; - -template <> -struct conj_helper<Packet2cf, Packet2cf, false, true> { - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, - const Packet2cf& c) const { - return padd(pmul(x, y), c); - } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const { - return internal::pmul(a, pconj(b)); - } -}; - -template <> -struct conj_helper<Packet2cf, Packet2cf, true, false> { - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, - const Packet2cf& c) const { - return padd(pmul(x, y), c); - } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const { - return internal::pmul(pconj(a), b); - } -}; - -template <> -struct conj_helper<Packet2cf, Packet2cf, true, true> { - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, - const Packet2cf& c) const { - return padd(pmul(x, y), c); - } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf, Packet4f) - -template <> -EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { - EIGEN_MSA_DEBUG; - - return a / b; -} - -inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet2cf, 2>& value) { - os << "[ " << value.packet[0] << ", " << std::endl << " " << value.packet[1] << " ]"; - return os; -} - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2cf, 2>& kernel) { - EIGEN_MSA_DEBUG; - - Packet4f tmp = - (Packet4f)__builtin_msa_ilvl_d((v2i64)kernel.packet[1].v, (v2i64)kernel.packet[0].v); - kernel.packet[0].v = - (Packet4f)__builtin_msa_ilvr_d((v2i64)kernel.packet[1].v, (v2i64)kernel.packet[0].v); - kernel.packet[1].v = tmp; -} - -template <> -EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, - const Packet2cf& elsePacket) { - return (Packet2cf)(Packet4f)pblend<Packet2d>(ifPacket, (Packet2d)thenPacket.v, - (Packet2d)elsePacket.v); -} - -//---------- double ---------- - -struct Packet1cd { - EIGEN_STRONG_INLINE Packet1cd() { - } - EIGEN_STRONG_INLINE explicit Packet1cd(const std::complex<double>& a) { - v[0] = std::real(a); - v[1] = std::imag(a); - } - EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) { - } - EIGEN_STRONG_INLINE Packet1cd(const Packet1cd& a) : v(a.v) { - } - EIGEN_STRONG_INLINE Packet1cd& operator=(const Packet1cd& b) { - v = b.v; - return *this; - } - EIGEN_STRONG_INLINE Packet1cd conjugate(void) const { - static const v2u64 p2ul_CONJ_XOR = { 0x0, 0x8000000000000000 }; - return (Packet1cd)pxor(v, (Packet2d)p2ul_CONJ_XOR); - } - EIGEN_STRONG_INLINE Packet1cd& operator*=(const Packet1cd& b) { - Packet2d v1, v2; - - // Get the real values of a | a1_re | a1_re - v1 = (Packet2d)__builtin_msa_ilvev_d((v2i64)v, (v2i64)v); - // Get the imag values of a | a1_im | a1_im - v2 = (Packet2d)__builtin_msa_ilvod_d((v2i64)v, (v2i64)v); - // Multiply the real a with b - v1 = pmul(v1, b.v); - // Multiply the imag a with b - v2 = pmul(v2, b.v); - // Conjugate v2 - v2 = Packet1cd(v2).conjugate().v; - // Swap real/imag elements in v2. - v2 = (Packet2d)__builtin_msa_shf_w((v4i32)v2, EIGEN_MSA_SHF_I8(2, 3, 0, 1)); - // Add and return the result - v = padd(v1, v2); - return *this; - } - EIGEN_STRONG_INLINE Packet1cd operator*(const Packet1cd& b) const { - return Packet1cd(*this) *= b; - } - EIGEN_STRONG_INLINE Packet1cd& operator+=(const Packet1cd& b) { - v = padd(v, b.v); - return *this; - } - EIGEN_STRONG_INLINE Packet1cd operator+(const Packet1cd& b) const { - return Packet1cd(*this) += b; - } - EIGEN_STRONG_INLINE Packet1cd& operator-=(const Packet1cd& b) { - v = psub(v, b.v); - return *this; - } - EIGEN_STRONG_INLINE Packet1cd operator-(const Packet1cd& b) const { - return Packet1cd(*this) -= b; - } - EIGEN_STRONG_INLINE Packet1cd& operator/=(const Packet1cd& b) { - *this *= b.conjugate(); - Packet2d s = pmul<Packet2d>(b.v, b.v); - s = padd(s, preverse<Packet2d>(s)); - v = pdiv(v, s); - return *this; - } - EIGEN_STRONG_INLINE Packet1cd operator/(const Packet1cd& b) const { - return Packet1cd(*this) /= b; - } - EIGEN_STRONG_INLINE Packet1cd operator-(void) const { - return Packet1cd(pnegate(v)); - } - - Packet2d v; -}; - -inline std::ostream& operator<<(std::ostream& os, const Packet1cd& value) { - os << "[ (" << value.v[0] << ", " << value.v[1] << "i) ]"; - return os; -} - -template <> -struct packet_traits<std::complex<double> > : default_packet_traits { - typedef Packet1cd type; - typedef Packet1cd half; - enum { - Vectorizable = 1, - AlignedOnScalar = 0, - size = 1, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0 - }; -}; - -template <> -struct unpacket_traits<Packet1cd> { - typedef std::complex<double> type; - enum { size = 1, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false }; - typedef Packet1cd half; -}; - -template <> -EIGEN_STRONG_INLINE Packet1cd pload<Packet1cd>(const std::complex<double>* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from)); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from)); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from) { - EIGEN_MSA_DEBUG; - - return Packet1cd(from); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { - EIGEN_MSA_DEBUG; - - return a + b; -} - -template <> -EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { - EIGEN_MSA_DEBUG; - - return a - b; -} - -template <> -EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { - EIGEN_MSA_DEBUG; - - return -a; -} - -template <> -EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) { - EIGEN_MSA_DEBUG; - - return a.conjugate(); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { - EIGEN_MSA_DEBUG; - - return a * b; -} - -template <> -EIGEN_STRONG_INLINE Packet1cd pand<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { - EIGEN_MSA_DEBUG; - - return Packet1cd(pand(a.v, b.v)); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd por<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { - EIGEN_MSA_DEBUG; - - return Packet1cd(por(a.v, b.v)); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd pxor<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { - EIGEN_MSA_DEBUG; - - return Packet1cd(pxor(a.v, b.v)); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { - EIGEN_MSA_DEBUG; - - return Packet1cd(pandnot(a.v, b.v)); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { - EIGEN_MSA_DEBUG; - - return pset1<Packet1cd>(*from); -} - -template <> -EIGEN_STRONG_INLINE void pstore<std::complex<double> >(std::complex<double>* to, - const Packet1cd& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_STORE pstore<double>((double*)to, from.v); -} - -template <> -EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double>* to, - const Packet1cd& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_STORE pstoreu<double>((double*)to, from.v); -} - -template <> -EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double>* addr) { - EIGEN_MSA_DEBUG; - - prefetch(reinterpret_cast<const double*>(addr)); -} - -template <> -EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>( - const std::complex<double>* from, Index stride __attribute__((unused))) { - EIGEN_MSA_DEBUG; - - Packet1cd res; - res.v[0] = std::real(from[0]); - res.v[1] = std::imag(from[0]); - return res; -} - -template <> -EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to, - const Packet1cd& from, - Index stride - __attribute__((unused))) { - EIGEN_MSA_DEBUG; - - pstore(to, from); -} - -template <> -EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a) { - EIGEN_MSA_DEBUG; - - return std::complex<double>(a.v[0], a.v[1]); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { - EIGEN_MSA_DEBUG; - - return a; -} - -template <> -EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) { - EIGEN_MSA_DEBUG; - - return pfirst(a); -} - -template <> -EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(const Packet1cd* vecs) { - EIGEN_MSA_DEBUG; - - return vecs[0]; -} - -template <> -EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) { - EIGEN_MSA_DEBUG; - - return pfirst(a); -} - -template <int Offset> -struct palign_impl<Offset, Packet1cd> { - static EIGEN_STRONG_INLINE void run(Packet1cd& /*first*/, const Packet1cd& /*second*/) { - // FIXME is it sure we never have to align a Packet1cd? - // Even though a std::complex<double> has 16 bytes, it is not necessarily aligned on a 16 bytes - // boundary... - } -}; - -template <> -struct conj_helper<Packet1cd, Packet1cd, false, true> { - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, - const Packet1cd& c) const { - return padd(pmul(x, y), c); - } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const { - return internal::pmul(a, pconj(b)); - } -}; - -template <> -struct conj_helper<Packet1cd, Packet1cd, true, false> { - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, - const Packet1cd& c) const { - return padd(pmul(x, y), c); - } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const { - return internal::pmul(pconj(a), b); - } -}; - -template <> -struct conj_helper<Packet1cd, Packet1cd, true, true> { - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, - const Packet1cd& c) const { - return padd(pmul(x, y), c); - } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd, Packet2d) - -template <> -EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { - EIGEN_MSA_DEBUG; - - return a / b; -} - -EIGEN_STRONG_INLINE Packet1cd pcplxflip /*<Packet1cd>*/ (const Packet1cd& x) { - EIGEN_MSA_DEBUG; - - return Packet1cd(preverse(Packet2d(x.v))); -} - -inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet1cd, 2>& value) { - os << "[ " << value.packet[0] << ", " << std::endl << " " << value.packet[1] << " ]"; - return os; -} - -EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd, 2>& kernel) { - EIGEN_MSA_DEBUG; - - Packet2d v1, v2; - - v1 = (Packet2d)__builtin_msa_ilvev_d((v2i64)kernel.packet[0].v, (v2i64)kernel.packet[1].v); - // Get the imag values of a - v2 = (Packet2d)__builtin_msa_ilvod_d((v2i64)kernel.packet[0].v, (v2i64)kernel.packet[1].v); - - kernel.packet[0].v = v1; - kernel.packet[1].v = v2; -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_MSA_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/MathFunctions.h deleted file mode 100644 index f5181b90..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/MathFunctions.h +++ /dev/null @@ -1,387 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007 Julien Pommier -// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) -// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// Copyright (C) 2018 Wave Computing, Inc. -// Written by: -// Chris Larsen -// Alexey Frunze (afrunze@wavecomp.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* The sin, cos, exp, and log functions of this file come from - * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/ - */ - -/* The tanh function of this file is an adaptation of - * template<typename T> T generic_fast_tanh_float(const T&) - * from MathFunctionsImpl.h. - */ - -#ifndef EIGEN_MATH_FUNCTIONS_MSA_H -#define EIGEN_MATH_FUNCTIONS_MSA_H - -namespace Eigen { - -namespace internal { - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f -plog<Packet4f>(const Packet4f& _x) { - static _EIGEN_DECLARE_CONST_Packet4f(cephes_SQRTHF, 0.707106781186547524f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p0, 7.0376836292e-2f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p1, -1.1514610310e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p2, 1.1676998740e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p3, -1.2420140846e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p4, +1.4249322787e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p5, -1.6668057665e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p6, +2.0000714765e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p7, -2.4999993993e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p8, +3.3333331174e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_q1, -2.12194440e-4f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_q2, 0.693359375f); - static _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f); - static _EIGEN_DECLARE_CONST_Packet4f(1, 1.0f); - - // Convert negative argument into NAN (quiet negative, to be specific). - Packet4f zero = (Packet4f)__builtin_msa_ldi_w(0); - Packet4i neg_mask = __builtin_msa_fclt_w(_x, zero); - Packet4i zero_mask = __builtin_msa_fceq_w(_x, zero); - Packet4f non_neg_x_or_nan = padd(_x, (Packet4f)neg_mask); // Add 0.0 or NAN. - Packet4f x = non_neg_x_or_nan; - - // Extract exponent from x = mantissa * 2**exponent, where 1.0 <= mantissa < 2.0. - // N.B. the exponent is one less of what frexpf() would return. - Packet4i e_int = __builtin_msa_ftint_s_w(__builtin_msa_flog2_w(x)); - // Multiply x by 2**(-exponent-1) to get 0.5 <= x < 1.0 as from frexpf(). - x = __builtin_msa_fexp2_w(x, (Packet4i)__builtin_msa_nori_b((v16u8)e_int, 0)); - - /* - if (x < SQRTHF) { - x = x + x - 1.0; - } else { - e += 1; - x = x - 1.0; - } - */ - Packet4f xx = padd(x, x); - Packet4i ge_mask = __builtin_msa_fcle_w(p4f_cephes_SQRTHF, x); - e_int = psub(e_int, ge_mask); - x = (Packet4f)__builtin_msa_bsel_v((v16u8)ge_mask, (v16u8)xx, (v16u8)x); - x = psub(x, p4f_1); - Packet4f e = __builtin_msa_ffint_s_w(e_int); - - Packet4f x2 = pmul(x, x); - Packet4f x3 = pmul(x2, x); - - Packet4f y, y1, y2; - y = pmadd(p4f_cephes_log_p0, x, p4f_cephes_log_p1); - y1 = pmadd(p4f_cephes_log_p3, x, p4f_cephes_log_p4); - y2 = pmadd(p4f_cephes_log_p6, x, p4f_cephes_log_p7); - y = pmadd(y, x, p4f_cephes_log_p2); - y1 = pmadd(y1, x, p4f_cephes_log_p5); - y2 = pmadd(y2, x, p4f_cephes_log_p8); - y = pmadd(y, x3, y1); - y = pmadd(y, x3, y2); - y = pmul(y, x3); - - y = pmadd(e, p4f_cephes_log_q1, y); - x = __builtin_msa_fmsub_w(x, x2, p4f_half); - x = padd(x, y); - x = pmadd(e, p4f_cephes_log_q2, x); - - // x is now the logarithm result candidate. We still need to handle the - // extreme arguments of zero and positive infinity, though. - // N.B. if the argument is +INFINITY, x is NAN because the polynomial terms - // contain infinities of both signs (see the coefficients and code above). - // INFINITY - INFINITY is NAN. - - // If the argument is +INFINITY, make it the new result candidate. - // To achieve that we choose the smaller of the result candidate and the - // argument. - // This is correct for all finite pairs of values (the logarithm is smaller - // than the argument). - // This is also correct in the special case when the argument is +INFINITY - // and the result candidate is NAN. This is because the fmin.df instruction - // prefers non-NANs to NANs. - x = __builtin_msa_fmin_w(x, non_neg_x_or_nan); - - // If the argument is zero (including -0.0), the result becomes -INFINITY. - Packet4i neg_infs = __builtin_msa_slli_w(zero_mask, 23); - x = (Packet4f)__builtin_msa_bsel_v((v16u8)zero_mask, (v16u8)x, (v16u8)neg_infs); - - return x; -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f -pexp<Packet4f>(const Packet4f& _x) { - // Limiting single-precision pexp's argument to [-128, +128] lets pexp - // reach 0 and INFINITY naturally. - static _EIGEN_DECLARE_CONST_Packet4f(exp_lo, -128.0f); - static _EIGEN_DECLARE_CONST_Packet4f(exp_hi, +128.0f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_LOG2EF, 1.44269504088896341f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C1, 0.693359375f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C2, -2.12194440e-4f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p0, 1.9875691500e-4f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p1, 1.3981999507e-3f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p2, 8.3334519073e-3f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p3, 4.1665795894e-2f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p4, 1.6666665459e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p5, 5.0000001201e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f); - static _EIGEN_DECLARE_CONST_Packet4f(1, 1.0f); - - Packet4f x = _x; - - // Clamp x. - x = (Packet4f)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_w(x, p4f_exp_lo), (v16u8)x, - (v16u8)p4f_exp_lo); - x = (Packet4f)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_w(p4f_exp_hi, x), (v16u8)x, - (v16u8)p4f_exp_hi); - - // Round to nearest integer by adding 0.5 (with x's sign) and truncating. - Packet4f x2_add = (Packet4f)__builtin_msa_binsli_w((v4u32)p4f_half, (v4u32)x, 0); - Packet4f x2 = pmadd(x, p4f_cephes_LOG2EF, x2_add); - Packet4i x2_int = __builtin_msa_ftrunc_s_w(x2); - Packet4f x2_int_f = __builtin_msa_ffint_s_w(x2_int); - - x = __builtin_msa_fmsub_w(x, x2_int_f, p4f_cephes_exp_C1); - x = __builtin_msa_fmsub_w(x, x2_int_f, p4f_cephes_exp_C2); - - Packet4f z = pmul(x, x); - - Packet4f y = p4f_cephes_exp_p0; - y = pmadd(y, x, p4f_cephes_exp_p1); - y = pmadd(y, x, p4f_cephes_exp_p2); - y = pmadd(y, x, p4f_cephes_exp_p3); - y = pmadd(y, x, p4f_cephes_exp_p4); - y = pmadd(y, x, p4f_cephes_exp_p5); - y = pmadd(y, z, x); - y = padd(y, p4f_1); - - // y *= 2**exponent. - y = __builtin_msa_fexp2_w(y, x2_int); - - return y; -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f -ptanh<Packet4f>(const Packet4f& _x) { - static _EIGEN_DECLARE_CONST_Packet4f(tanh_tiny, 1e-4f); - static _EIGEN_DECLARE_CONST_Packet4f(tanh_hi, 9.0f); - // The monomial coefficients of the numerator polynomial (odd). - static _EIGEN_DECLARE_CONST_Packet4f(alpha_1, 4.89352455891786e-3f); - static _EIGEN_DECLARE_CONST_Packet4f(alpha_3, 6.37261928875436e-4f); - static _EIGEN_DECLARE_CONST_Packet4f(alpha_5, 1.48572235717979e-5f); - static _EIGEN_DECLARE_CONST_Packet4f(alpha_7, 5.12229709037114e-8f); - static _EIGEN_DECLARE_CONST_Packet4f(alpha_9, -8.60467152213735e-11f); - static _EIGEN_DECLARE_CONST_Packet4f(alpha_11, 2.00018790482477e-13f); - static _EIGEN_DECLARE_CONST_Packet4f(alpha_13, -2.76076847742355e-16f); - // The monomial coefficients of the denominator polynomial (even). - static _EIGEN_DECLARE_CONST_Packet4f(beta_0, 4.89352518554385e-3f); - static _EIGEN_DECLARE_CONST_Packet4f(beta_2, 2.26843463243900e-3f); - static _EIGEN_DECLARE_CONST_Packet4f(beta_4, 1.18534705686654e-4f); - static _EIGEN_DECLARE_CONST_Packet4f(beta_6, 1.19825839466702e-6f); - - Packet4f x = pabs(_x); - Packet4i tiny_mask = __builtin_msa_fclt_w(x, p4f_tanh_tiny); - - // Clamp the inputs to the range [-9, 9] since anything outside - // this range is -/+1.0f in single-precision. - x = (Packet4f)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_w(p4f_tanh_hi, x), (v16u8)x, - (v16u8)p4f_tanh_hi); - - // Since the polynomials are odd/even, we need x**2. - Packet4f x2 = pmul(x, x); - - // Evaluate the numerator polynomial p. - Packet4f p = pmadd(x2, p4f_alpha_13, p4f_alpha_11); - p = pmadd(x2, p, p4f_alpha_9); - p = pmadd(x2, p, p4f_alpha_7); - p = pmadd(x2, p, p4f_alpha_5); - p = pmadd(x2, p, p4f_alpha_3); - p = pmadd(x2, p, p4f_alpha_1); - p = pmul(x, p); - - // Evaluate the denominator polynomial q. - Packet4f q = pmadd(x2, p4f_beta_6, p4f_beta_4); - q = pmadd(x2, q, p4f_beta_2); - q = pmadd(x2, q, p4f_beta_0); - - // Divide the numerator by the denominator. - p = pdiv(p, q); - - // Reinstate the sign. - p = (Packet4f)__builtin_msa_binsli_w((v4u32)p, (v4u32)_x, 0); - - // When the argument is very small in magnitude it's more accurate to just return it. - p = (Packet4f)__builtin_msa_bsel_v((v16u8)tiny_mask, (v16u8)p, (v16u8)_x); - - return p; -} - -template <bool sine> -Packet4f psincos_inner_msa_float(const Packet4f& _x) { - static _EIGEN_DECLARE_CONST_Packet4f(sincos_max_arg, 13176795.0f); // Approx. (2**24) / (4/Pi). - static _EIGEN_DECLARE_CONST_Packet4f(minus_cephes_DP1, -0.78515625f); - static _EIGEN_DECLARE_CONST_Packet4f(minus_cephes_DP2, -2.4187564849853515625e-4f); - static _EIGEN_DECLARE_CONST_Packet4f(minus_cephes_DP3, -3.77489497744594108e-8f); - static _EIGEN_DECLARE_CONST_Packet4f(sincof_p0, -1.9515295891e-4f); - static _EIGEN_DECLARE_CONST_Packet4f(sincof_p1, 8.3321608736e-3f); - static _EIGEN_DECLARE_CONST_Packet4f(sincof_p2, -1.6666654611e-1f); - static _EIGEN_DECLARE_CONST_Packet4f(coscof_p0, 2.443315711809948e-5f); - static _EIGEN_DECLARE_CONST_Packet4f(coscof_p1, -1.388731625493765e-3f); - static _EIGEN_DECLARE_CONST_Packet4f(coscof_p2, 4.166664568298827e-2f); - static _EIGEN_DECLARE_CONST_Packet4f(cephes_FOPI, 1.27323954473516f); // 4/Pi. - static _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f); - static _EIGEN_DECLARE_CONST_Packet4f(1, 1.0f); - - Packet4f x = pabs(_x); - - // Translate infinite arguments into NANs. - Packet4f zero_or_nan_if_inf = psub(_x, _x); - x = padd(x, zero_or_nan_if_inf); - // Prevent sin/cos from generating values larger than 1.0 in magnitude - // for very large arguments by setting x to 0.0. - Packet4i small_or_nan_mask = __builtin_msa_fcult_w(x, p4f_sincos_max_arg); - x = pand(x, (Packet4f)small_or_nan_mask); - - // Scale x by 4/Pi to find x's octant. - Packet4f y = pmul(x, p4f_cephes_FOPI); - // Get the octant. We'll reduce x by this number of octants or by one more than it. - Packet4i y_int = __builtin_msa_ftrunc_s_w(y); - // x's from even-numbered octants will translate to octant 0: [0, +Pi/4]. - // x's from odd-numbered octants will translate to octant -1: [-Pi/4, 0]. - // Adjustment for odd-numbered octants: octant = (octant + 1) & (~1). - Packet4i y_int1 = __builtin_msa_addvi_w(y_int, 1); - Packet4i y_int2 = (Packet4i)__builtin_msa_bclri_w((Packet4ui)y_int1, 0); // bclri = bit-clear - y = __builtin_msa_ffint_s_w(y_int2); - - // Compute the sign to apply to the polynomial. - Packet4i sign_mask = sine ? pxor(__builtin_msa_slli_w(y_int1, 29), (Packet4i)_x) - : __builtin_msa_slli_w(__builtin_msa_addvi_w(y_int, 3), 29); - - // Get the polynomial selection mask. - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet4i poly_mask = __builtin_msa_ceqi_w(__builtin_msa_slli_w(y_int2, 30), 0); - - // Reduce x by y octants to get: -Pi/4 <= x <= +Pi/4. - // The magic pass: "Extended precision modular arithmetic" - // x = ((x - y * DP1) - y * DP2) - y * DP3 - Packet4f tmp1 = pmul(y, p4f_minus_cephes_DP1); - Packet4f tmp2 = pmul(y, p4f_minus_cephes_DP2); - Packet4f tmp3 = pmul(y, p4f_minus_cephes_DP3); - x = padd(x, tmp1); - x = padd(x, tmp2); - x = padd(x, tmp3); - - // Evaluate the cos(x) polynomial. - y = p4f_coscof_p0; - Packet4f z = pmul(x, x); - y = pmadd(y, z, p4f_coscof_p1); - y = pmadd(y, z, p4f_coscof_p2); - y = pmul(y, z); - y = pmul(y, z); - y = __builtin_msa_fmsub_w(y, z, p4f_half); - y = padd(y, p4f_1); - - // Evaluate the sin(x) polynomial. - Packet4f y2 = p4f_sincof_p0; - y2 = pmadd(y2, z, p4f_sincof_p1); - y2 = pmadd(y2, z, p4f_sincof_p2); - y2 = pmul(y2, z); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - y = sine ? (Packet4f)__builtin_msa_bsel_v((v16u8)poly_mask, (v16u8)y, (v16u8)y2) - : (Packet4f)__builtin_msa_bsel_v((v16u8)poly_mask, (v16u8)y2, (v16u8)y); - - // Update the sign. - sign_mask = pxor(sign_mask, (Packet4i)y); - y = (Packet4f)__builtin_msa_binsli_w((v4u32)y, (v4u32)sign_mask, 0); // binsli = bit-insert-left - return y; -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f -psin<Packet4f>(const Packet4f& x) { - return psincos_inner_msa_float</* sine */ true>(x); -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f -pcos<Packet4f>(const Packet4f& x) { - return psincos_inner_msa_float</* sine */ false>(x); -} - -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2d -pexp<Packet2d>(const Packet2d& _x) { - // Limiting double-precision pexp's argument to [-1024, +1024] lets pexp - // reach 0 and INFINITY naturally. - static _EIGEN_DECLARE_CONST_Packet2d(exp_lo, -1024.0); - static _EIGEN_DECLARE_CONST_Packet2d(exp_hi, +1024.0); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_LOG2EF, 1.4426950408889634073599); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C1, 0.693145751953125); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C2, 1.42860682030941723212e-6); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p0, 1.26177193074810590878e-4); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p1, 3.02994407707441961300e-2); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p2, 9.99999999999999999910e-1); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q0, 3.00198505138664455042e-6); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q1, 2.52448340349684104192e-3); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q2, 2.27265548208155028766e-1); - static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q3, 2.00000000000000000009e0); - static _EIGEN_DECLARE_CONST_Packet2d(half, 0.5); - static _EIGEN_DECLARE_CONST_Packet2d(1, 1.0); - static _EIGEN_DECLARE_CONST_Packet2d(2, 2.0); - - Packet2d x = _x; - - // Clamp x. - x = (Packet2d)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_d(x, p2d_exp_lo), (v16u8)x, - (v16u8)p2d_exp_lo); - x = (Packet2d)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_d(p2d_exp_hi, x), (v16u8)x, - (v16u8)p2d_exp_hi); - - // Round to nearest integer by adding 0.5 (with x's sign) and truncating. - Packet2d x2_add = (Packet2d)__builtin_msa_binsli_d((v2u64)p2d_half, (v2u64)x, 0); - Packet2d x2 = pmadd(x, p2d_cephes_LOG2EF, x2_add); - Packet2l x2_long = __builtin_msa_ftrunc_s_d(x2); - Packet2d x2_long_d = __builtin_msa_ffint_s_d(x2_long); - - x = __builtin_msa_fmsub_d(x, x2_long_d, p2d_cephes_exp_C1); - x = __builtin_msa_fmsub_d(x, x2_long_d, p2d_cephes_exp_C2); - - x2 = pmul(x, x); - - Packet2d px = p2d_cephes_exp_p0; - px = pmadd(px, x2, p2d_cephes_exp_p1); - px = pmadd(px, x2, p2d_cephes_exp_p2); - px = pmul(px, x); - - Packet2d qx = p2d_cephes_exp_q0; - qx = pmadd(qx, x2, p2d_cephes_exp_q1); - qx = pmadd(qx, x2, p2d_cephes_exp_q2); - qx = pmadd(qx, x2, p2d_cephes_exp_q3); - - x = pdiv(px, psub(qx, px)); - x = pmadd(p2d_2, x, p2d_1); - - // x *= 2**exponent. - x = __builtin_msa_fexp2_d(x, x2_long); - - return x; -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATH_FUNCTIONS_MSA_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/PacketMath.h deleted file mode 100644 index 94ee0e30..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/MSA/PacketMath.h +++ /dev/null @@ -1,1318 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2018 Wave Computing, Inc. -// Written by: -// Chris Larsen -// Alexey Frunze (afrunze@wavecomp.com) -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PACKET_MATH_MSA_H -#define EIGEN_PACKET_MATH_MSA_H - -#include <iostream> -#include <string> - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD -#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 -#endif - -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#endif - -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD -#endif - -#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32 -#endif - -#if 0 -#define EIGEN_MSA_DEBUG \ - static bool firstTime = true; \ - do { \ - if (firstTime) { \ - std::cout << __FILE__ << ':' << __LINE__ << ':' << __FUNCTION__ << std::endl; \ - firstTime = false; \ - } \ - } while (0) -#else -#define EIGEN_MSA_DEBUG -#endif - -#define EIGEN_MSA_SHF_I8(a, b, c, d) (((d) << 6) | ((c) << 4) | ((b) << 2) | (a)) - -typedef v4f32 Packet4f; -typedef v4i32 Packet4i; -typedef v4u32 Packet4ui; - -#define _EIGEN_DECLARE_CONST_Packet4f(NAME, X) const Packet4f p4f_##NAME = { X, X, X, X } -#define _EIGEN_DECLARE_CONST_Packet4i(NAME, X) const Packet4i p4i_##NAME = { X, X, X, X } -#define _EIGEN_DECLARE_CONST_Packet4ui(NAME, X) const Packet4ui p4ui_##NAME = { X, X, X, X } - -inline std::ostream& operator<<(std::ostream& os, const Packet4f& value) { - os << "[ " << value[0] << ", " << value[1] << ", " << value[2] << ", " << value[3] << " ]"; - return os; -} - -inline std::ostream& operator<<(std::ostream& os, const Packet4i& value) { - os << "[ " << value[0] << ", " << value[1] << ", " << value[2] << ", " << value[3] << " ]"; - return os; -} - -inline std::ostream& operator<<(std::ostream& os, const Packet4ui& value) { - os << "[ " << value[0] << ", " << value[1] << ", " << value[2] << ", " << value[3] << " ]"; - return os; -} - -template <> -struct packet_traits<float> : default_packet_traits { - typedef Packet4f type; - typedef Packet4f half; // Packet2f intrinsics not implemented yet - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, // Packet2f intrinsics not implemented yet - // FIXME check the Has* - HasDiv = 1, - HasSin = EIGEN_FAST_MATH, - HasCos = EIGEN_FAST_MATH, - HasTanh = EIGEN_FAST_MATH, - HasErf = EIGEN_FAST_MATH, - HasLog = 1, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasRound = 1, - HasFloor = 1, - HasCeil = 1, - HasBlend = 1 - }; -}; - -template <> -struct packet_traits<int32_t> : default_packet_traits { - typedef Packet4i type; - typedef Packet4i half; // Packet2i intrinsics not implemented yet - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, // Packet2i intrinsics not implemented yet - // FIXME check the Has* - HasDiv = 1, - HasBlend = 1 - }; -}; - -template <> -struct unpacket_traits<Packet4f> { - typedef float type; - enum { size = 4, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false }; - typedef Packet4f half; -}; - -template <> -struct unpacket_traits<Packet4i> { - typedef int32_t type; - enum { size = 4, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false }; - typedef Packet4i half; -}; - -template <> -EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { - EIGEN_MSA_DEBUG; - - Packet4f v = { from, from, from, from }; - return v; -} - -template <> -EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int32_t& from) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fill_w(from); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pload1<Packet4f>(const float* from) { - EIGEN_MSA_DEBUG; - - float f = *from; - Packet4f v = { f, f, f, f }; - return v; -} - -template <> -EIGEN_STRONG_INLINE Packet4i pload1<Packet4i>(const int32_t* from) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fill_w(*from); -} - -template <> -EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fadd_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_addv_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) { - EIGEN_MSA_DEBUG; - - static const Packet4f countdown = { 0.0f, 1.0f, 2.0f, 3.0f }; - return padd(pset1<Packet4f>(a), countdown); -} - -template <> -EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int32_t& a) { - EIGEN_MSA_DEBUG; - - static const Packet4i countdown = { 0, 1, 2, 3 }; - return padd(pset1<Packet4i>(a), countdown); -} - -template <> -EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fsub_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_subv_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - return (Packet4f)__builtin_msa_bnegi_w((v4u32)a, 31); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_addvi_w((v4i32)__builtin_msa_nori_b((v16u8)a, 0), 1); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - return a; -} - -template <> -EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - return a; -} - -template <> -EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fmul_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_mulv_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fdiv_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_div_s_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fmadd_w(c, a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { - EIGEN_MSA_DEBUG; - - // Use "asm" construct to avoid __builtin_msa_maddv_w GNU C bug. - Packet4i value = c; - __asm__("maddv.w %w[value], %w[a], %w[b]\n" - // Outputs - : [value] "+f"(value) - // Inputs - : [a] "f"(a), [b] "f"(b)); - return value; -} - -template <> -EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - - return (Packet4f)__builtin_msa_and_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return (Packet4i)__builtin_msa_and_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - - return (Packet4f)__builtin_msa_or_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return (Packet4i)__builtin_msa_or_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - - return (Packet4f)__builtin_msa_xor_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return (Packet4i)__builtin_msa_xor_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - - return pand(a, (Packet4f)__builtin_msa_xori_b((v16u8)b, 255)); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return pand(a, (Packet4i)__builtin_msa_xori_b((v16u8)b, 255)); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - -#if EIGEN_FAST_MATH - // This prefers numbers to NaNs. - return __builtin_msa_fmin_w(a, b); -#else - // This prefers NaNs to numbers. - Packet4i aNaN = __builtin_msa_fcun_w(a, a); - Packet4i aMinOrNaN = por(__builtin_msa_fclt_w(a, b), aNaN); - return (Packet4f)__builtin_msa_bsel_v((v16u8)aMinOrNaN, (v16u8)b, (v16u8)a); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_min_s_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) { - EIGEN_MSA_DEBUG; - -#if EIGEN_FAST_MATH - // This prefers numbers to NaNs. - return __builtin_msa_fmax_w(a, b); -#else - // This prefers NaNs to numbers. - Packet4i aNaN = __builtin_msa_fcun_w(a, a); - Packet4i aMaxOrNaN = por(__builtin_msa_fclt_w(b, a), aNaN); - return (Packet4f)__builtin_msa_bsel_v((v16u8)aMaxOrNaN, (v16u8)b, (v16u8)a); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_max_s_w(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_LOAD return (Packet4f)__builtin_msa_ld_w(const_cast<float*>(from), 0); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int32_t* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_LOAD return __builtin_msa_ld_w(const_cast<int32_t*>(from), 0); -} - -template <> -EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_LOAD return (Packet4f)__builtin_msa_ld_w(const_cast<float*>(from), 0); -} - -template <> -EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int32_t* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_LOAD return (Packet4i)__builtin_msa_ld_w(const_cast<int32_t*>(from), 0); -} - -template <> -EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) { - EIGEN_MSA_DEBUG; - - float f0 = from[0], f1 = from[1]; - Packet4f v0 = { f0, f0, f0, f0 }; - Packet4f v1 = { f1, f1, f1, f1 }; - return (Packet4f)__builtin_msa_ilvr_d((v2i64)v1, (v2i64)v0); -} - -template <> -EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int32_t* from) { - EIGEN_MSA_DEBUG; - - int32_t i0 = from[0], i1 = from[1]; - Packet4i v0 = { i0, i0, i0, i0 }; - Packet4i v1 = { i1, i1, i1, i1 }; - return (Packet4i)__builtin_msa_ilvr_d((v2i64)v1, (v2i64)v0); -} - -template <> -EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_STORE __builtin_msa_st_w((Packet4i)from, to, 0); -} - -template <> -EIGEN_STRONG_INLINE void pstore<int32_t>(int32_t* to, const Packet4i& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_STORE __builtin_msa_st_w(from, to, 0); -} - -template <> -EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_STORE __builtin_msa_st_w((Packet4i)from, to, 0); -} - -template <> -EIGEN_STRONG_INLINE void pstoreu<int32_t>(int32_t* to, const Packet4i& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_STORE __builtin_msa_st_w(from, to, 0); -} - -template <> -EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) { - EIGEN_MSA_DEBUG; - - float f = *from; - Packet4f v = { f, f, f, f }; - v[1] = from[stride]; - v[2] = from[2 * stride]; - v[3] = from[3 * stride]; - return v; -} - -template <> -EIGEN_DEVICE_FUNC inline Packet4i pgather<int32_t, Packet4i>(const int32_t* from, Index stride) { - EIGEN_MSA_DEBUG; - - int32_t i = *from; - Packet4i v = { i, i, i, i }; - v[1] = from[stride]; - v[2] = from[2 * stride]; - v[3] = from[3 * stride]; - return v; -} - -template <> -EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, - Index stride) { - EIGEN_MSA_DEBUG; - - *to = from[0]; - to += stride; - *to = from[1]; - to += stride; - *to = from[2]; - to += stride; - *to = from[3]; -} - -template <> -EIGEN_DEVICE_FUNC inline void pscatter<int32_t, Packet4i>(int32_t* to, const Packet4i& from, - Index stride) { - EIGEN_MSA_DEBUG; - - *to = from[0]; - to += stride; - *to = from[1]; - to += stride; - *to = from[2]; - to += stride; - *to = from[3]; -} - -template <> -EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { - EIGEN_MSA_DEBUG; - - __builtin_prefetch(addr); -} - -template <> -EIGEN_STRONG_INLINE void prefetch<int32_t>(const int32_t* addr) { - EIGEN_MSA_DEBUG; - - __builtin_prefetch(addr); -} - -template <> -EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - return a[0]; -} - -template <> -EIGEN_STRONG_INLINE int32_t pfirst<Packet4i>(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - return a[0]; -} - -template <> -EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - return (Packet4f)__builtin_msa_shf_w((v4i32)a, EIGEN_MSA_SHF_I8(3, 2, 1, 0)); -} - -template <> -EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(3, 2, 1, 0)); -} - -template <> -EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - return (Packet4f)__builtin_msa_bclri_w((v4u32)a, 31); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - Packet4i zero = __builtin_msa_ldi_w(0); - return __builtin_msa_add_a_w(zero, a); -} - -template <> -EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - Packet4f s = padd(a, (Packet4f)__builtin_msa_shf_w((v4i32)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1))); - s = padd(s, (Packet4f)__builtin_msa_shf_w((v4i32)s, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); - return s[0]; -} - -template <> -EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) { - EIGEN_MSA_DEBUG; - - v4i32 tmp1, tmp2, tmp3, tmp4; - Packet4f sum; - - tmp1 = __builtin_msa_ilvr_w((v4i32)vecs[1], (v4i32)vecs[0]); - tmp2 = __builtin_msa_ilvr_w((v4i32)vecs[3], (v4i32)vecs[2]); - tmp3 = __builtin_msa_ilvl_w((v4i32)vecs[1], (v4i32)vecs[0]); - tmp4 = __builtin_msa_ilvl_w((v4i32)vecs[3], (v4i32)vecs[2]); - - sum = (Packet4f)__builtin_msa_ilvr_d((v2i64)tmp2, (v2i64)tmp1); - sum = padd(sum, (Packet4f)__builtin_msa_ilvod_d((v2i64)tmp2, (v2i64)tmp1)); - sum = padd(sum, (Packet4f)__builtin_msa_ilvr_d((v2i64)tmp4, (v2i64)tmp3)); - sum = padd(sum, (Packet4f)__builtin_msa_ilvod_d((v2i64)tmp4, (v2i64)tmp3)); - - return sum; -} - -template <> -EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs) { - EIGEN_MSA_DEBUG; - - v4i32 tmp1, tmp2, tmp3, tmp4; - Packet4i sum; - - tmp1 = __builtin_msa_ilvr_w((v4i32)vecs[1], (v4i32)vecs[0]); - tmp2 = __builtin_msa_ilvr_w((v4i32)vecs[3], (v4i32)vecs[2]); - tmp3 = __builtin_msa_ilvl_w((v4i32)vecs[1], (v4i32)vecs[0]); - tmp4 = __builtin_msa_ilvl_w((v4i32)vecs[3], (v4i32)vecs[2]); - - sum = (Packet4i)__builtin_msa_ilvr_d((v2i64)tmp2, (v2i64)tmp1); - sum = padd(sum, (Packet4i)__builtin_msa_ilvod_d((v2i64)tmp2, (v2i64)tmp1)); - sum = padd(sum, (Packet4i)__builtin_msa_ilvr_d((v2i64)tmp4, (v2i64)tmp3)); - sum = padd(sum, (Packet4i)__builtin_msa_ilvod_d((v2i64)tmp4, (v2i64)tmp3)); - - return sum; -} - -template <> -EIGEN_STRONG_INLINE int32_t predux<Packet4i>(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - Packet4i s = padd(a, __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(2, 3, 0, 1))); - s = padd(s, __builtin_msa_shf_w(s, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); - return s[0]; -} - -// Other reduction functions: -// mul -template <> -EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - Packet4f p = pmul(a, (Packet4f)__builtin_msa_shf_w((v4i32)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1))); - p = pmul(p, (Packet4f)__builtin_msa_shf_w((v4i32)p, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); - return p[0]; -} - -template <> -EIGEN_STRONG_INLINE int32_t predux_mul<Packet4i>(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - Packet4i p = pmul(a, __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(2, 3, 0, 1))); - p = pmul(p, __builtin_msa_shf_w(p, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); - return p[0]; -} - -// min -template <> -EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - // Swap 64-bit halves of a. - Packet4f swapped = (Packet4f)__builtin_msa_shf_w((Packet4i)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)); -#if !EIGEN_FAST_MATH - // Detect presence of NaNs from pairs a[0]-a[2] and a[1]-a[3] as two 32-bit - // masks of all zeroes/ones in low 64 bits. - v16u8 unord = (v16u8)__builtin_msa_fcun_w(a, swapped); - // Combine the two masks into one: 64 ones if no NaNs, otherwise 64 zeroes. - unord = (v16u8)__builtin_msa_ceqi_d((v2i64)unord, 0); -#endif - // Continue with min computation. - Packet4f v = __builtin_msa_fmin_w(a, swapped); - v = __builtin_msa_fmin_w( - v, (Packet4f)__builtin_msa_shf_w((Packet4i)v, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); -#if !EIGEN_FAST_MATH - // Based on the mask select between v and 4 qNaNs. - v16u8 qnans = (v16u8)__builtin_msa_fill_w(0x7FC00000); - v = (Packet4f)__builtin_msa_bsel_v(unord, qnans, (v16u8)v); -#endif - return v[0]; -} - -template <> -EIGEN_STRONG_INLINE int32_t predux_min<Packet4i>(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - Packet4i m = pmin(a, __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(2, 3, 0, 1))); - m = pmin(m, __builtin_msa_shf_w(m, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); - return m[0]; -} - -// max -template <> -EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - // Swap 64-bit halves of a. - Packet4f swapped = (Packet4f)__builtin_msa_shf_w((Packet4i)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)); -#if !EIGEN_FAST_MATH - // Detect presence of NaNs from pairs a[0]-a[2] and a[1]-a[3] as two 32-bit - // masks of all zeroes/ones in low 64 bits. - v16u8 unord = (v16u8)__builtin_msa_fcun_w(a, swapped); - // Combine the two masks into one: 64 ones if no NaNs, otherwise 64 zeroes. - unord = (v16u8)__builtin_msa_ceqi_d((v2i64)unord, 0); -#endif - // Continue with max computation. - Packet4f v = __builtin_msa_fmax_w(a, swapped); - v = __builtin_msa_fmax_w( - v, (Packet4f)__builtin_msa_shf_w((Packet4i)v, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); -#if !EIGEN_FAST_MATH - // Based on the mask select between v and 4 qNaNs. - v16u8 qnans = (v16u8)__builtin_msa_fill_w(0x7FC00000); - v = (Packet4f)__builtin_msa_bsel_v(unord, qnans, (v16u8)v); -#endif - return v[0]; -} - -template <> -EIGEN_STRONG_INLINE int32_t predux_max<Packet4i>(const Packet4i& a) { - EIGEN_MSA_DEBUG; - - Packet4i m = pmax(a, __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(2, 3, 0, 1))); - m = pmax(m, __builtin_msa_shf_w(m, EIGEN_MSA_SHF_I8(1, 0, 3, 2))); - return m[0]; -} - -#define PALIGN_MSA(Offset, Type, Command) \ - template <> \ - struct palign_impl<Offset, Type> { \ - EIGEN_STRONG_INLINE static void run(Type& first, const Type& second) { \ - if (Offset != 0) first = (Type)(Command((v16i8)second, (v16i8)first, Offset * 4)); \ - } \ - }; - -PALIGN_MSA(0, Packet4f, __builtin_msa_sldi_b) -PALIGN_MSA(1, Packet4f, __builtin_msa_sldi_b) -PALIGN_MSA(2, Packet4f, __builtin_msa_sldi_b) -PALIGN_MSA(3, Packet4f, __builtin_msa_sldi_b) -PALIGN_MSA(0, Packet4i, __builtin_msa_sldi_b) -PALIGN_MSA(1, Packet4i, __builtin_msa_sldi_b) -PALIGN_MSA(2, Packet4i, __builtin_msa_sldi_b) -PALIGN_MSA(3, Packet4i, __builtin_msa_sldi_b) - -#undef PALIGN_MSA - -inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet4f, 4>& value) { - os << "[ " << value.packet[0] << "," << std::endl - << " " << value.packet[1] << "," << std::endl - << " " << value.packet[2] << "," << std::endl - << " " << value.packet[3] << " ]"; - return os; -} - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f, 4>& kernel) { - EIGEN_MSA_DEBUG; - - v4i32 tmp1, tmp2, tmp3, tmp4; - - tmp1 = __builtin_msa_ilvr_w((v4i32)kernel.packet[1], (v4i32)kernel.packet[0]); - tmp2 = __builtin_msa_ilvr_w((v4i32)kernel.packet[3], (v4i32)kernel.packet[2]); - tmp3 = __builtin_msa_ilvl_w((v4i32)kernel.packet[1], (v4i32)kernel.packet[0]); - tmp4 = __builtin_msa_ilvl_w((v4i32)kernel.packet[3], (v4i32)kernel.packet[2]); - - kernel.packet[0] = (Packet4f)__builtin_msa_ilvr_d((v2i64)tmp2, (v2i64)tmp1); - kernel.packet[1] = (Packet4f)__builtin_msa_ilvod_d((v2i64)tmp2, (v2i64)tmp1); - kernel.packet[2] = (Packet4f)__builtin_msa_ilvr_d((v2i64)tmp4, (v2i64)tmp3); - kernel.packet[3] = (Packet4f)__builtin_msa_ilvod_d((v2i64)tmp4, (v2i64)tmp3); -} - -inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet4i, 4>& value) { - os << "[ " << value.packet[0] << "," << std::endl - << " " << value.packet[1] << "," << std::endl - << " " << value.packet[2] << "," << std::endl - << " " << value.packet[3] << " ]"; - return os; -} - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4i, 4>& kernel) { - EIGEN_MSA_DEBUG; - - v4i32 tmp1, tmp2, tmp3, tmp4; - - tmp1 = __builtin_msa_ilvr_w(kernel.packet[1], kernel.packet[0]); - tmp2 = __builtin_msa_ilvr_w(kernel.packet[3], kernel.packet[2]); - tmp3 = __builtin_msa_ilvl_w(kernel.packet[1], kernel.packet[0]); - tmp4 = __builtin_msa_ilvl_w(kernel.packet[3], kernel.packet[2]); - - kernel.packet[0] = (Packet4i)__builtin_msa_ilvr_d((v2i64)tmp2, (v2i64)tmp1); - kernel.packet[1] = (Packet4i)__builtin_msa_ilvod_d((v2i64)tmp2, (v2i64)tmp1); - kernel.packet[2] = (Packet4i)__builtin_msa_ilvr_d((v2i64)tmp4, (v2i64)tmp3); - kernel.packet[3] = (Packet4i)__builtin_msa_ilvod_d((v2i64)tmp4, (v2i64)tmp3); -} - -template <> -EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f& a) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fsqrt_w(a); -} - -template <> -EIGEN_STRONG_INLINE Packet4f prsqrt(const Packet4f& a) { - EIGEN_MSA_DEBUG; - -#if EIGEN_FAST_MATH - return __builtin_msa_frsqrt_w(a); -#else - Packet4f ones = __builtin_msa_ffint_s_w(__builtin_msa_ldi_w(1)); - return pdiv(ones, psqrt(a)); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) { - Packet4f v = a; - int32_t old_mode, new_mode; - asm volatile( - "cfcmsa %[old_mode], $1\n" - "ori %[new_mode], %[old_mode], 3\n" // 3 = round towards -INFINITY. - "ctcmsa $1, %[new_mode]\n" - "frint.w %w[v], %w[v]\n" - "ctcmsa $1, %[old_mode]\n" - : // outputs - [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode), - [v] "+f"(v) - : // inputs - : // clobbers - ); - return v; -} - -template <> -EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) { - Packet4f v = a; - int32_t old_mode, new_mode; - asm volatile( - "cfcmsa %[old_mode], $1\n" - "ori %[new_mode], %[old_mode], 3\n" - "xori %[new_mode], %[new_mode], 1\n" // 2 = round towards +INFINITY. - "ctcmsa $1, %[new_mode]\n" - "frint.w %w[v], %w[v]\n" - "ctcmsa $1, %[old_mode]\n" - : // outputs - [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode), - [v] "+f"(v) - : // inputs - : // clobbers - ); - return v; -} - -template <> -EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) { - Packet4f v = a; - int32_t old_mode, new_mode; - asm volatile( - "cfcmsa %[old_mode], $1\n" - "ori %[new_mode], %[old_mode], 3\n" - "xori %[new_mode], %[new_mode], 3\n" // 0 = round to nearest, ties to even. - "ctcmsa $1, %[new_mode]\n" - "frint.w %w[v], %w[v]\n" - "ctcmsa $1, %[old_mode]\n" - : // outputs - [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode), - [v] "+f"(v) - : // inputs - : // clobbers - ); - return v; -} - -template <> -EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, - const Packet4f& elsePacket) { - Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], - ifPacket.select[3] }; - Packet4i mask = __builtin_msa_ceqi_w((Packet4i)select, 0); - return (Packet4f)__builtin_msa_bsel_v((v16u8)mask, (v16u8)thenPacket, (v16u8)elsePacket); -} - -template <> -EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, - const Packet4i& elsePacket) { - Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], - ifPacket.select[3] }; - Packet4i mask = __builtin_msa_ceqi_w((Packet4i)select, 0); - return (Packet4i)__builtin_msa_bsel_v((v16u8)mask, (v16u8)thenPacket, (v16u8)elsePacket); -} - -//---------- double ---------- - -typedef v2f64 Packet2d; -typedef v2i64 Packet2l; -typedef v2u64 Packet2ul; - -#define _EIGEN_DECLARE_CONST_Packet2d(NAME, X) const Packet2d p2d_##NAME = { X, X } -#define _EIGEN_DECLARE_CONST_Packet2l(NAME, X) const Packet2l p2l_##NAME = { X, X } -#define _EIGEN_DECLARE_CONST_Packet2ul(NAME, X) const Packet2ul p2ul_##NAME = { X, X } - -inline std::ostream& operator<<(std::ostream& os, const Packet2d& value) { - os << "[ " << value[0] << ", " << value[1] << " ]"; - return os; -} - -inline std::ostream& operator<<(std::ostream& os, const Packet2l& value) { - os << "[ " << value[0] << ", " << value[1] << " ]"; - return os; -} - -inline std::ostream& operator<<(std::ostream& os, const Packet2ul& value) { - os << "[ " << value[0] << ", " << value[1] << " ]"; - return os; -} - -template <> -struct packet_traits<double> : default_packet_traits { - typedef Packet2d type; - typedef Packet2d half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 2, - HasHalfPacket = 0, - // FIXME check the Has* - HasDiv = 1, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasRound = 1, - HasFloor = 1, - HasCeil = 1, - HasBlend = 1 - }; -}; - -template <> -struct unpacket_traits<Packet2d> { - typedef double type; - enum { size = 2, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false }; - typedef Packet2d half; -}; - -template <> -EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { - EIGEN_MSA_DEBUG; - - Packet2d value = { from, from }; - return value; -} - -template <> -EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fadd_d(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { - EIGEN_MSA_DEBUG; - - static const Packet2d countdown = { 0.0, 1.0 }; - return padd(pset1<Packet2d>(a), countdown); -} - -template <> -EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fsub_d(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { - EIGEN_MSA_DEBUG; - - return (Packet2d)__builtin_msa_bnegi_d((v2u64)a, 63); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { - EIGEN_MSA_DEBUG; - - return a; -} - -template <> -EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fmul_d(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fdiv_d(a, b); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fmadd_d(c, a, b); -} - -// Logical Operations are not supported for float, so we have to reinterpret casts using MSA -// intrinsics -template <> -EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - - return (Packet2d)__builtin_msa_and_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - - return (Packet2d)__builtin_msa_or_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - - return (Packet2d)__builtin_msa_xor_v((v16u8)a, (v16u8)b); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - - return pand(a, (Packet2d)__builtin_msa_xori_b((v16u8)b, 255)); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_LOAD return (Packet2d)__builtin_msa_ld_d(const_cast<double*>(from), 0); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - -#if EIGEN_FAST_MATH - // This prefers numbers to NaNs. - return __builtin_msa_fmin_d(a, b); -#else - // This prefers NaNs to numbers. - v2i64 aNaN = __builtin_msa_fcun_d(a, a); - v2i64 aMinOrNaN = por(__builtin_msa_fclt_d(a, b), aNaN); - return (Packet2d)__builtin_msa_bsel_v((v16u8)aMinOrNaN, (v16u8)b, (v16u8)a); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { - EIGEN_MSA_DEBUG; - -#if EIGEN_FAST_MATH - // This prefers numbers to NaNs. - return __builtin_msa_fmax_d(a, b); -#else - // This prefers NaNs to numbers. - v2i64 aNaN = __builtin_msa_fcun_d(a, a); - v2i64 aMaxOrNaN = por(__builtin_msa_fclt_d(b, a), aNaN); - return (Packet2d)__builtin_msa_bsel_v((v16u8)aMaxOrNaN, (v16u8)b, (v16u8)a); -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_LOAD return (Packet2d)__builtin_msa_ld_d(const_cast<double*>(from), 0); -} - -template <> -EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) { - EIGEN_MSA_DEBUG; - - Packet2d value = { *from, *from }; - return value; -} - -template <> -EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_ALIGNED_STORE __builtin_msa_st_d((v2i64)from, to, 0); -} - -template <> -EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) { - EIGEN_MSA_DEBUG; - - EIGEN_DEBUG_UNALIGNED_STORE __builtin_msa_st_d((v2i64)from, to, 0); -} - -template <> -EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride) { - EIGEN_MSA_DEBUG; - - Packet2d value; - value[0] = *from; - from += stride; - value[1] = *from; - return value; -} - -template <> -EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, - Index stride) { - EIGEN_MSA_DEBUG; - - *to = from[0]; - to += stride; - *to = from[1]; -} - -template <> -EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { - EIGEN_MSA_DEBUG; - - __builtin_prefetch(addr); -} - -template <> -EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { - EIGEN_MSA_DEBUG; - - return a[0]; -} - -template <> -EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) { - EIGEN_MSA_DEBUG; - - return (Packet2d)__builtin_msa_shf_w((v4i32)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)); -} - -template <> -EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) { - EIGEN_MSA_DEBUG; - - return (Packet2d)__builtin_msa_bclri_d((v2u64)a, 63); -} - -template <> -EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) { - EIGEN_MSA_DEBUG; - - Packet2d s = padd(a, preverse(a)); - return s[0]; -} - -template <> -EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs) { - EIGEN_MSA_DEBUG; - - Packet2d v0 = (Packet2d)__builtin_msa_ilvev_d((v2i64)vecs[1], (v2i64)vecs[0]); - Packet2d v1 = (Packet2d)__builtin_msa_ilvod_d((v2i64)vecs[1], (v2i64)vecs[0]); - - return padd(v0, v1); -} - -// Other reduction functions: -// mul -template <> -EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) { - EIGEN_MSA_DEBUG; - - Packet2d p = pmul(a, preverse(a)); - return p[0]; -} - -// min -template <> -EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) { - EIGEN_MSA_DEBUG; - -#if EIGEN_FAST_MATH - Packet2d swapped = (Packet2d)__builtin_msa_shf_w((Packet4i)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)); - Packet2d v = __builtin_msa_fmin_d(a, swapped); - return v[0]; -#else - double a0 = a[0], a1 = a[1]; - return ((numext::isnan)(a0) || a0 < a1) ? a0 : a1; -#endif -} - -// max -template <> -EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) { - EIGEN_MSA_DEBUG; - -#if EIGEN_FAST_MATH - Packet2d swapped = (Packet2d)__builtin_msa_shf_w((Packet4i)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)); - Packet2d v = __builtin_msa_fmax_d(a, swapped); - return v[0]; -#else - double a0 = a[0], a1 = a[1]; - return ((numext::isnan)(a0) || a0 > a1) ? a0 : a1; -#endif -} - -template <> -EIGEN_STRONG_INLINE Packet2d psqrt(const Packet2d& a) { - EIGEN_MSA_DEBUG; - - return __builtin_msa_fsqrt_d(a); -} - -template <> -EIGEN_STRONG_INLINE Packet2d prsqrt(const Packet2d& a) { - EIGEN_MSA_DEBUG; - -#if EIGEN_FAST_MATH - return __builtin_msa_frsqrt_d(a); -#else - Packet2d ones = __builtin_msa_ffint_s_d(__builtin_msa_ldi_d(1)); - return pdiv(ones, psqrt(a)); -#endif -} - -#define PALIGN_MSA(Offset, Type, Command) \ - template <> \ - struct palign_impl<Offset, Type> { \ - EIGEN_STRONG_INLINE static void run(Type& first, const Type& second) { \ - if (Offset != 0) first = (Type)(Command((v16i8)second, (v16i8)first, Offset * 8)); \ - } \ - }; - -PALIGN_MSA(0, Packet2d, __builtin_msa_sldi_b) -PALIGN_MSA(1, Packet2d, __builtin_msa_sldi_b) - -#undef PALIGN_MSA - -inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet2d, 2>& value) { - os << "[ " << value.packet[0] << "," << std::endl << " " << value.packet[1] << " ]"; - return os; -} - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2d, 2>& kernel) { - EIGEN_MSA_DEBUG; - - Packet2d trn1 = (Packet2d)__builtin_msa_ilvev_d((v2i64)kernel.packet[1], (v2i64)kernel.packet[0]); - Packet2d trn2 = (Packet2d)__builtin_msa_ilvod_d((v2i64)kernel.packet[1], (v2i64)kernel.packet[0]); - kernel.packet[0] = trn1; - kernel.packet[1] = trn2; -} - -template <> -EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { - Packet2d v = a; - int32_t old_mode, new_mode; - asm volatile( - "cfcmsa %[old_mode], $1\n" - "ori %[new_mode], %[old_mode], 3\n" // 3 = round towards -INFINITY. - "ctcmsa $1, %[new_mode]\n" - "frint.d %w[v], %w[v]\n" - "ctcmsa $1, %[old_mode]\n" - : // outputs - [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode), - [v] "+f"(v) - : // inputs - : // clobbers - ); - return v; -} - -template <> -EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { - Packet2d v = a; - int32_t old_mode, new_mode; - asm volatile( - "cfcmsa %[old_mode], $1\n" - "ori %[new_mode], %[old_mode], 3\n" - "xori %[new_mode], %[new_mode], 1\n" // 2 = round towards +INFINITY. - "ctcmsa $1, %[new_mode]\n" - "frint.d %w[v], %w[v]\n" - "ctcmsa $1, %[old_mode]\n" - : // outputs - [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode), - [v] "+f"(v) - : // inputs - : // clobbers - ); - return v; -} - -template <> -EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) { - Packet2d v = a; - int32_t old_mode, new_mode; - asm volatile( - "cfcmsa %[old_mode], $1\n" - "ori %[new_mode], %[old_mode], 3\n" - "xori %[new_mode], %[new_mode], 3\n" // 0 = round to nearest, ties to even. - "ctcmsa $1, %[new_mode]\n" - "frint.d %w[v], %w[v]\n" - "ctcmsa $1, %[old_mode]\n" - : // outputs - [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode), - [v] "+f"(v) - : // inputs - : // clobbers - ); - return v; -} - -template <> -EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, - const Packet2d& elsePacket) { - Packet2ul select = { ifPacket.select[0], ifPacket.select[1] }; - Packet2l mask = __builtin_msa_ceqi_d((Packet2l)select, 0); - return (Packet2d)__builtin_msa_bsel_v((v16u8)mask, (v16u8)thenPacket, (v16u8)elsePacket); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PACKET_MATH_MSA_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/Complex.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/Complex.h deleted file mode 100644 index c1d0c650..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/Complex.h +++ /dev/null @@ -1,522 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Konstantinos Margaritis <markos@freevec.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX_NEON_H -#define EIGEN_COMPLEX_NEON_H - -namespace Eigen { - -namespace internal { - -inline uint32x4_t p4ui_CONJ_XOR() -{ -// See bug 1325, clang fails to call vld1q_u64. -#if EIGEN_COMP_CLANG - uint32x4_t ret = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 }; - return ret; -#else - static const uint32_t conj_XOR_DATA[] = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 }; - return vld1q_u32( conj_XOR_DATA ); -#endif -} - -inline uint32x2_t p2ui_CONJ_XOR() -{ - static const uint32_t conj_XOR_DATA[] = { 0x00000000, 0x80000000 }; - return vld1_u32( conj_XOR_DATA ); -} - -//---------- float ---------- -struct Packet2cf -{ - EIGEN_STRONG_INLINE Packet2cf() {} - EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {} - Packet4f v; -}; - -template<> struct packet_traits<std::complex<float> > : default_packet_traits -{ - typedef Packet2cf type; - typedef Packet2cf half; - enum - { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 2, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0 - }; -}; - -template<> struct unpacket_traits<Packet2cf> -{ - typedef std::complex<float> type; - typedef Packet2cf half; - enum - { - size = 2, - alignment = Aligned16, - vectorizable = true, - masked_load_available = false, - masked_store_available = false - }; -}; - -template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from) -{ - const float32x2_t r64 = vld1_f32(reinterpret_cast<const float*>(&from)); - return Packet2cf(vcombine_f32(r64, r64)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ return Packet2cf(padd<Packet4f>(a.v, b.v)); } - -template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ return Packet2cf(psub<Packet4f>(a.v, b.v)); } - -template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate<Packet4f>(a.v)); } - -template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) -{ - const Packet4ui b = vreinterpretq_u32_f32(a.v); - return Packet2cf(vreinterpretq_f32_u32(veorq_u32(b, p4ui_CONJ_XOR()))); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - Packet4f v1, v2; - - // Get the real values of a | a1_re | a1_re | a2_re | a2_re | - v1 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 0), vdup_lane_f32(vget_high_f32(a.v), 0)); - // Get the imag values of a | a1_im | a1_im | a2_im | a2_im | - v2 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 1), vdup_lane_f32(vget_high_f32(a.v), 1)); - // Multiply the real a with b - v1 = vmulq_f32(v1, b.v); - // Multiply the imag a with b - v2 = vmulq_f32(v2, b.v); - // Conjugate v2 - v2 = vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(v2), p4ui_CONJ_XOR())); - // Swap real/imag elements in v2. - v2 = vrev64q_f32(v2); - // Add and return the result - return Packet2cf(vaddq_f32(v1, v2)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b) -{ - // Compare real and imaginary parts of a and b to get the mask vector: - // [re(a[0])==re(b[0]), im(a[0])==im(b[0]), re(a[1])==re(b[1]), im(a[1])==im(b[1])] - Packet4f eq = pcmp_eq<Packet4f>(a.v, b.v); - // Swap real/imag elements in the mask in to get: - // [im(a[0])==im(b[0]), re(a[0])==re(b[0]), im(a[1])==im(b[1]), re(a[1])==re(b[1])] - Packet4f eq_swapped = vrev64q_f32(eq); - // Return re(a)==re(b) && im(a)==im(b) by computing bitwise AND of eq and eq_swapped - return Packet2cf(pand<Packet4f>(eq, eq_swapped)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pand<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ return Packet2cf(vreinterpretq_f32_u32(vandq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v)))); } - -template<> EIGEN_STRONG_INLINE Packet2cf por<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v)))); } - -template<> EIGEN_STRONG_INLINE Packet2cf pxor<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ return Packet2cf(vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v)))); } - -template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ return Packet2cf(vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v)))); } - -template<> EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) -{ EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>(reinterpret_cast<const float*>(from))); } - -template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) -{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>(reinterpret_cast<const float*>(from))); } - -template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) -{ return pset1<Packet2cf>(*from); } - -template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> *to, const Packet2cf& from) -{ EIGEN_DEBUG_ALIGNED_STORE pstore(reinterpret_cast<float*>(to), from.v); } - -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> *to, const Packet2cf& from) -{ EIGEN_DEBUG_UNALIGNED_STORE pstoreu(reinterpret_cast<float*>(to), from.v); } - -template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>( - const std::complex<float>* from, Index stride) -{ - Packet4f res = vdupq_n_f32(std::real(from[0*stride])); - res = vsetq_lane_f32(std::imag(from[0*stride]), res, 1); - res = vsetq_lane_f32(std::real(from[1*stride]), res, 2); - res = vsetq_lane_f32(std::imag(from[1*stride]), res, 3); - return Packet2cf(res); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>( - std::complex<float>* to, const Packet2cf& from, Index stride) -{ - to[stride*0] = std::complex<float>(vgetq_lane_f32(from.v, 0), vgetq_lane_f32(from.v, 1)); - to[stride*1] = std::complex<float>(vgetq_lane_f32(from.v, 2), vgetq_lane_f32(from.v, 3)); -} - -template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> *addr) -{ EIGEN_ARM_PREFETCH(reinterpret_cast<const float*>(addr)); } - -template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a) -{ - EIGEN_ALIGN16 std::complex<float> x[2]; - vst1q_f32(reinterpret_cast<float*>(x), a.v); - return x[0]; -} - -template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) -{ return Packet2cf(vcombine_f32(vget_high_f32(a.v), vget_low_f32(a.v))); } - -template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& a) -{ return Packet2cf(vrev64q_f32(a.v)); } - -template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a) -{ - std::complex<float> s; - vst1_f32(reinterpret_cast<float*>(&s), vadd_f32(vget_low_f32(a.v), vget_high_f32(a.v))); - return s; -} - -template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs) -{ - const Packet4f sum1 = vcombine_f32(vget_low_f32(vecs[0].v), vget_low_f32(vecs[1].v)); - const Packet4f sum2 = vcombine_f32(vget_high_f32(vecs[0].v), vget_high_f32(vecs[1].v)); - return Packet2cf(vaddq_f32(sum1, sum2)); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a) -{ - float32x2_t a1, a2, v1, v2, prod; - std::complex<float> s; - - a1 = vget_low_f32(a.v); - a2 = vget_high_f32(a.v); - // Get the real values of a | a1_re | a1_re | a2_re | a2_re | - v1 = vdup_lane_f32(a1, 0); - // Get the real values of a | a1_im | a1_im | a2_im | a2_im | - v2 = vdup_lane_f32(a1, 1); - // Multiply the real a with b - v1 = vmul_f32(v1, a2); - // Multiply the imag a with b - v2 = vmul_f32(v2, a2); - // Conjugate v2 - v2 = vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(v2), p2ui_CONJ_XOR())); - // Swap real/imag elements in v2. - v2 = vrev64_f32(v2); - // Add v1, v2 - prod = vadd_f32(v1, v2); - - vst1_f32(reinterpret_cast<float*>(&s), prod); - - return s; -} - -template<int Offset> -struct palign_impl<Offset,Packet2cf> -{ - EIGEN_STRONG_INLINE static void run(Packet2cf& first, const Packet2cf& second) - { - if (Offset == 1) - first.v = vextq_f32(first.v, second.v, 2); - } -}; - -template<> struct conj_helper<Packet2cf,Packet2cf,false,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { return internal::pmul(a, pconj(b)); } -}; - -template<> struct conj_helper<Packet2cf,Packet2cf,true,false> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { return internal::pmul(pconj(a), b); } -}; - -template<> struct conj_helper<Packet2cf,Packet2cf,true,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { return pconj(internal::pmul(a,b)); } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f) - -template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - // TODO optimize it for NEON - Packet2cf res = conj_helper<Packet2cf, Packet2cf, false, true>().pmul(a,b); - Packet4f s, rev_s; - - // this computes the norm - s = vmulq_f32(b.v, b.v); - rev_s = vrev64q_f32(s); - - return Packet2cf(pdiv<Packet4f>(res.v, vaddq_f32(s, rev_s))); -} - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2cf, 2>& kernel) -{ - Packet4f tmp = vcombine_f32(vget_high_f32(kernel.packet[0].v), vget_high_f32(kernel.packet[1].v)); - kernel.packet[0].v = vcombine_f32(vget_low_f32(kernel.packet[0].v), vget_low_f32(kernel.packet[1].v)); - kernel.packet[1].v = tmp; -} - -//---------- double ---------- -#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG - -// See bug 1325, clang fails to call vld1q_u64. -#if EIGEN_COMP_CLANG - static uint64x2_t p2ul_CONJ_XOR = {0x0, 0x8000000000000000}; -#else - const uint64_t p2ul_conj_XOR_DATA[] = { 0x0, 0x8000000000000000 }; - static uint64x2_t p2ul_CONJ_XOR = vld1q_u64( p2ul_conj_XOR_DATA ); -#endif - -struct Packet1cd -{ - EIGEN_STRONG_INLINE Packet1cd() {} - EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {} - Packet2d v; -}; - -template<> struct packet_traits<std::complex<double> > : default_packet_traits -{ - typedef Packet1cd type; - typedef Packet1cd half; - enum - { - Vectorizable = 1, - AlignedOnScalar = 0, - size = 1, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0 - }; -}; - -template<> struct unpacket_traits<Packet1cd> -{ - typedef std::complex<double> type; - enum - { - size=1, - alignment=Aligned16, - vectorizable=true, - masked_load_available=false, - masked_store_available=false - }; - typedef Packet1cd half; -}; - -template<> EIGEN_STRONG_INLINE Packet1cd pload<Packet1cd>(const std::complex<double>* from) -{ EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>(reinterpret_cast<const double*>(from))); } - -template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) -{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>(reinterpret_cast<const double*>(from))); } - -template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from) -{ - /* here we really have to use unaligned loads :( */ - return ploadu<Packet1cd>(&from); -} - -template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ return Packet1cd(padd<Packet2d>(a.v, b.v)); } - -template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ return Packet1cd(psub<Packet2d>(a.v, b.v)); } - -template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) -{ return Packet1cd(pnegate<Packet2d>(a.v)); } - -template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) -{ return Packet1cd(vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a.v), p2ul_CONJ_XOR))); } - -template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ - Packet2d v1, v2; - - // Get the real values of a - v1 = vdupq_lane_f64(vget_low_f64(a.v), 0); - // Get the imag values of a - v2 = vdupq_lane_f64(vget_high_f64(a.v), 0); - // Multiply the real a with b - v1 = vmulq_f64(v1, b.v); - // Multiply the imag a with b - v2 = vmulq_f64(v2, b.v); - // Conjugate v2 - v2 = vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(v2), p2ul_CONJ_XOR)); - // Swap real/imag elements in v2. - v2 = preverse<Packet2d>(v2); - // Add and return the result - return Packet1cd(vaddq_f64(v1, v2)); -} - -template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b) -{ - // Compare real and imaginary parts of a and b to get the mask vector: - // [re(a)==re(b), im(a)==im(b)] - Packet2d eq = pcmp_eq<Packet2d>(a.v, b.v); - // Swap real/imag elements in the mask in to get: - // [im(a)==im(b), re(a)==re(b)] - Packet2d eq_swapped = vreinterpretq_f64_u32(vrev64q_u32(vreinterpretq_u32_f64(eq))); - // Return re(a)==re(b) & im(a)==im(b) by computing bitwise AND of eq and eq_swapped - return Packet1cd(pand<Packet2d>(eq, eq_swapped)); -} - -template<> EIGEN_STRONG_INLINE Packet1cd pand<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ return Packet1cd(vreinterpretq_f64_u64(vandq_u64(vreinterpretq_u64_f64(a.v),vreinterpretq_u64_f64(b.v)))); } - -template<> EIGEN_STRONG_INLINE Packet1cd por<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ return Packet1cd(vreinterpretq_f64_u64(vorrq_u64(vreinterpretq_u64_f64(a.v),vreinterpretq_u64_f64(b.v)))); } - -template<> EIGEN_STRONG_INLINE Packet1cd pxor<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ return Packet1cd(vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a.v),vreinterpretq_u64_f64(b.v)))); } - -template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ return Packet1cd(vreinterpretq_f64_u64(vbicq_u64(vreinterpretq_u64_f64(a.v),vreinterpretq_u64_f64(b.v)))); } - -template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) -{ return pset1<Packet1cd>(*from); } - -template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> *to, const Packet1cd& from) -{ EIGEN_DEBUG_ALIGNED_STORE pstore(reinterpret_cast<double*>(to), from.v); } - -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> *to, const Packet1cd& from) -{ EIGEN_DEBUG_UNALIGNED_STORE pstoreu(reinterpret_cast<double*>(to), from.v); } - -template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> *addr) -{ EIGEN_ARM_PREFETCH(reinterpret_cast<const double*>(addr)); } - -template<> EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>( - const std::complex<double>* from, Index stride) -{ - Packet2d res = pset1<Packet2d>(0.0); - res = vsetq_lane_f64(std::real(from[0*stride]), res, 0); - res = vsetq_lane_f64(std::imag(from[0*stride]), res, 1); - return Packet1cd(res); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>( - std::complex<double>* to, const Packet1cd& from, Index stride) -{ to[stride*0] = std::complex<double>(vgetq_lane_f64(from.v, 0), vgetq_lane_f64(from.v, 1)); } - -template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a) -{ - EIGEN_ALIGN16 std::complex<double> res; - pstore<std::complex<double> >(&res, a); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; } - -template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) { return pfirst(a); } - -template<> EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(const Packet1cd* vecs) { return vecs[0]; } - -template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) { return pfirst(a); } - -template<int Offset> -struct palign_impl<Offset,Packet1cd> -{ - static EIGEN_STRONG_INLINE void run(Packet1cd& /*first*/, const Packet1cd& /*second*/) - { - // FIXME is it sure we never have to align a Packet1cd? - // Even though a std::complex<double> has 16 bytes, it is not necessarily aligned on a 16 bytes boundary... - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, false,true> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { return internal::pmul(a, pconj(b)); } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, true,false> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { return internal::pmul(pconj(a), b); } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, true,true> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { return pconj(internal::pmul(a,b)); } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d) - -template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ - // TODO optimize it for NEON - Packet1cd res = conj_helper<Packet1cd,Packet1cd,false,true>().pmul(a,b); - Packet2d s = pmul<Packet2d>(b.v, b.v); - Packet2d rev_s = preverse<Packet2d>(s); - - return Packet1cd(pdiv(res.v, padd<Packet2d>(s,rev_s))); -} - -EIGEN_STRONG_INLINE Packet1cd pcplxflip/*<Packet1cd>*/(const Packet1cd& x) -{ return Packet1cd(preverse(Packet2d(x.v))); } - -EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd,2>& kernel) -{ - Packet2d tmp = vcombine_f64(vget_high_f64(kernel.packet[0].v), vget_high_f64(kernel.packet[1].v)); - kernel.packet[0].v = vcombine_f64(vget_low_f64(kernel.packet[0].v), vget_low_f64(kernel.packet[1].v)); - kernel.packet[1].v = tmp; -} -#endif // EIGEN_ARCH_ARM64 - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_NEON_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/MathFunctions.h deleted file mode 100644 index 510f2ea1..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/MathFunctions.h +++ /dev/null @@ -1,35 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATH_FUNCTIONS_NEON_H -#define EIGEN_MATH_FUNCTIONS_NEON_H - -namespace Eigen { - -namespace internal { - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f pexp<Packet4f>(const Packet4f& x) -{ return pexp_float(x); } - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f plog<Packet4f>(const Packet4f& x) -{ return plog_float(x); } - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f psin<Packet4f>(const Packet4f& x) -{ return psin_float(x); } - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f pcos<Packet4f>(const Packet4f& x) -{ return pcos_float(x); } - -// Hyperbolic Tangent function. -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f ptanh<Packet4f>(const Packet4f& x) -{ return internal::generic_fast_tanh_float(x); } - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATH_FUNCTIONS_NEON_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/PacketMath.h deleted file mode 100644 index be1c3b98..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/PacketMath.h +++ /dev/null @@ -1,800 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Konstantinos Margaritis <markos@freevec.org> -// Heavily based on Gael's SSE version. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PACKET_MATH_NEON_H -#define EIGEN_PACKET_MATH_NEON_H - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD -#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 -#endif - -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#endif - -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD -#endif - -#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS -#if EIGEN_ARCH_ARM64 -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32 -#else -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 16 -#endif -#endif - -#if EIGEN_COMP_MSVC - -// In MSVC's arm_neon.h header file, all NEON vector types -// are aliases to the same underlying type __n128. -// We thus have to wrap them to make them different C++ types. -// (See also bug 1428) - -template<typename T,int unique_id> -struct eigen_packet_wrapper -{ - operator T&() { return m_val; } - operator const T&() const { return m_val; } - eigen_packet_wrapper() {} - eigen_packet_wrapper(const T &v) : m_val(v) {} - eigen_packet_wrapper& operator=(const T &v) - { - m_val = v; - return *this; - } - - T m_val; -}; -typedef eigen_packet_wrapper<float32x2_t,0> Packet2f; -typedef eigen_packet_wrapper<float32x4_t,1> Packet4f; -typedef eigen_packet_wrapper<int32x2_t ,2> Packet2i; -typedef eigen_packet_wrapper<int32x4_t ,3> Packet4i; -typedef eigen_packet_wrapper<uint32x4_t ,4> Packet4ui; - -#else - -typedef float32x2_t Packet2f; -typedef float32x4_t Packet4f; -typedef int32x2_t Packet2i; -typedef int32x4_t Packet4i; -typedef uint32x4_t Packet4ui; - -#endif // EIGEN_COMP_MSVC - -#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \ - const Packet4f p4f_##NAME = pset1<Packet4f>(X) - -#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \ - const Packet4f p4f_##NAME = vreinterpretq_f32_u32(pset1<int32_t>(X)) - -#define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \ - const Packet4i p4i_##NAME = pset1<Packet4i>(X) - -#if EIGEN_ARCH_ARM64 - // __builtin_prefetch tends to do nothing on ARM64 compilers because the - // prefetch instructions there are too detailed for __builtin_prefetch to map - // meaningfully to them. - #define EIGEN_ARM_PREFETCH(ADDR) __asm__ __volatile__("prfm pldl1keep, [%[addr]]\n" ::[addr] "r"(ADDR) : ); -#elif EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC - #define EIGEN_ARM_PREFETCH(ADDR) __builtin_prefetch(ADDR); -#elif defined __pld - #define EIGEN_ARM_PREFETCH(ADDR) __pld(ADDR) -#elif EIGEN_ARCH_ARM32 - #define EIGEN_ARM_PREFETCH(ADDR) __asm__ __volatile__ ("pld [%[addr]]\n" :: [addr] "r" (ADDR) : ); -#else - // by default no explicit prefetching - #define EIGEN_ARM_PREFETCH(ADDR) -#endif - -template <> -struct packet_traits<float> : default_packet_traits -{ - typedef Packet4f type; - typedef Packet4f half; // Packet2f intrinsics not implemented yet - enum - { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, // Packet2f intrinsics not implemented yet - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasNegate = 1, - HasAbs = 1, - HasArg = 0, - HasAbs2 = 1, - HasMin = 1, - HasMax = 1, - HasConj = 1, - HasSetLinear = 0, - HasBlend = 0, - HasReduxp = 1, - - HasDiv = 1, - HasFloor = 1, - - HasSin = EIGEN_FAST_MATH, - HasCos = EIGEN_FAST_MATH, - HasLog = 1, - HasExp = 1, - HasSqrt = 0, - HasTanh = EIGEN_FAST_MATH, - HasErf = EIGEN_FAST_MATH - }; -}; - -template <> -struct packet_traits<int32_t> : default_packet_traits -{ - typedef Packet4i type; - typedef Packet4i half; // Packet2i intrinsics not implemented yet - enum - { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, // Packet2i intrinsics not implemented yet - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasNegate = 1, - HasAbs = 1, - HasArg = 0, - HasAbs2 = 1, - HasMin = 1, - HasMax = 1, - HasConj = 1, - HasSetLinear = 0, - HasBlend = 0, - HasReduxp = 1 - }; -}; - -#if EIGEN_GNUC_AT_MOST(4, 4) && !EIGEN_COMP_LLVM -// workaround gcc 4.2, 4.3 and 4.4 compilatin issue -EIGEN_STRONG_INLINE float32x4_t vld1q_f32(const float* x) { return ::vld1q_f32((const float32_t*)x); } -EIGEN_STRONG_INLINE float32x2_t vld1_f32(const float* x) { return ::vld1_f32 ((const float32_t*)x); } -EIGEN_STRONG_INLINE float32x2_t vld1_dup_f32(const float* x) { return ::vld1_dup_f32 ((const float32_t*)x); } -EIGEN_STRONG_INLINE void vst1q_f32(float* to, float32x4_t from) { ::vst1q_f32((float32_t*)to,from); } -EIGEN_STRONG_INLINE void vst1_f32 (float* to, float32x2_t from) { ::vst1_f32 ((float32_t*)to,from); } -#endif - -template<> struct unpacket_traits<Packet4f> -{ - typedef float type; - typedef Packet4f half; - typedef Packet4i integer_packet; - enum - { - size = 4, - alignment = Aligned16, - vectorizable = true, - masked_load_available = false, - masked_store_available = false - }; -}; -template<> struct unpacket_traits<Packet4i> -{ - typedef int32_t type; - typedef Packet4i half; - enum - { - size = 4, - alignment = Aligned16, - vectorizable = true, - masked_load_available = false, - masked_store_available = false - }; -}; - -template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { return vdupq_n_f32(from); } -template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int32_t& from) { return vdupq_n_s32(from); } - -template<> EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(unsigned int from) -{ return vreinterpretq_f32_u32(vdupq_n_u32(from)); } - -template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) -{ - const float c[] = {0.0f,1.0f,2.0f,3.0f}; - return vaddq_f32(pset1<Packet4f>(a), vld1q_f32(c)); -} -template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int32_t& a) -{ - const int32_t c[] = {0,1,2,3}; - return vaddq_s32(pset1<Packet4i>(a), vld1q_s32(c)); -} - -template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return vaddq_f32(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return vaddq_s32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return vsubq_f32(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return vsubq_s32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return vnegq_f32(a); } -template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return vnegq_s32(a); } - -template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return vmulq_f32(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { return vmulq_s32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) -{ -#if EIGEN_ARCH_ARM64 - return vdivq_f32(a,b); -#else - Packet4f inv, restep, div; - - // NEON does not offer a divide instruction, we have to do a reciprocal approximation - // However NEON in contrast to other SIMD engines (AltiVec/SSE), offers - // a reciprocal estimate AND a reciprocal step -which saves a few instructions - // vrecpeq_f32() returns an estimate to 1/b, which we will finetune with - // Newton-Raphson and vrecpsq_f32() - inv = vrecpeq_f32(b); - - // This returns a differential, by which we will have to multiply inv to get a better - // approximation of 1/b. - restep = vrecpsq_f32(b, inv); - inv = vmulq_f32(restep, inv); - - // Finally, multiply a by 1/b and get the wanted result of the division. - div = vmulq_f32(a, inv); - - return div; -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& /*a*/, const Packet4i& /*b*/) -{ - eigen_assert(false && "packet integer division are not supported by NEON"); - return pset1<Packet4i>(0); -} - -// Clang/ARM wrongly advertises __ARM_FEATURE_FMA even when it's not available, -// then implements a slow software scalar fallback calling fmaf()! -// Filed LLVM bug: -// https://llvm.org/bugs/show_bug.cgi?id=27216 -#if (defined __ARM_FEATURE_FMA) && !(EIGEN_COMP_CLANG && EIGEN_ARCH_ARM) -// See bug 936. -// FMA is available on VFPv4 i.e. when compiling with -mfpu=neon-vfpv4. -// FMA is a true fused multiply-add i.e. only 1 rounding at the end, no intermediate rounding. -// MLA is not fused i.e. does 2 roundings. -// In addition to giving better accuracy, FMA also gives better performance here on a Krait (Nexus 4): -// MLA: 10 GFlop/s ; FMA: 12 GFlops/s. -template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) -{ return vfmaq_f32(c,a,b); } -#else -template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) -{ -#if EIGEN_COMP_CLANG && EIGEN_ARCH_ARM - // Clang/ARM will replace VMLA by VMUL+VADD at least for some values of -mcpu, - // at least -mcpu=cortex-a8 and -mcpu=cortex-a7. Since the former is the default on - // -march=armv7-a, that is a very common case. - // See e.g. this thread: - // http://lists.llvm.org/pipermail/llvm-dev/2013-December/068806.html - // Filed LLVM bug: - // https://llvm.org/bugs/show_bug.cgi?id=27219 - Packet4f r = c; - asm volatile( - "vmla.f32 %q[r], %q[a], %q[b]" - : [r] "+w" (r) - : [a] "w" (a), - [b] "w" (b) - : ); - return r; -#else - return vmlaq_f32(c,a,b); -#endif -} -#endif - -// No FMA instruction for int, so use MLA unconditionally. -template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) -{ return vmlaq_s32(c,a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) { return vminq_f32(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vminq_s32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) { return vmaxq_f32(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vmaxq_s32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pcmp_le<Packet4f>(const Packet4f& a, const Packet4f& b) -{ return vreinterpretq_f32_u32(vcleq_f32(a,b)); } -template<> EIGEN_STRONG_INLINE Packet4i pcmp_le<Packet4i>(const Packet4i& a, const Packet4i& b) -{ return vreinterpretq_s32_u32(vcleq_s32(a,b)); } - -template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt<Packet4f>(const Packet4f& a, const Packet4f& b) -{ return vreinterpretq_f32_u32(vcltq_f32(a,b)); } -template<> EIGEN_STRONG_INLINE Packet4i pcmp_lt<Packet4i>(const Packet4i& a, const Packet4i& b) -{ return vreinterpretq_s32_u32(vcltq_s32(a,b)); } - -template<> EIGEN_STRONG_INLINE Packet4f pcmp_eq<Packet4f>(const Packet4f& a, const Packet4f& b) -{ return vreinterpretq_f32_u32(vceqq_f32(a,b)); } -template<> EIGEN_STRONG_INLINE Packet4i pcmp_eq<Packet4i>(const Packet4i& a, const Packet4i& b) -{ return vreinterpretq_s32_u32(vceqq_s32(a,b)); } - -template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt_or_nan<Packet4f>(const Packet4f& a, const Packet4f& b) -{ return vreinterpretq_f32_u32(vmvnq_u32(vcgeq_f32(a,b))); } - -template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) -{ - const Packet4f cst_1 = pset1<Packet4f>(1.0f); - /* perform a floorf */ - Packet4f tmp = vcvtq_f32_s32(vcvtq_s32_f32(a)); - - /* if greater, substract 1 */ - Packet4ui mask = vcgtq_f32(tmp, a); - mask = vandq_u32(mask, vreinterpretq_u32_f32(cst_1)); - return vsubq_f32(tmp, vreinterpretq_f32_u32(mask)); -} - -// Logical Operations are not supported for float, so we have to reinterpret casts using NEON intrinsics -template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) -{ return vreinterpretq_f32_u32(vandq_u32(vreinterpretq_u32_f32(a),vreinterpretq_u32_f32(b))); } - -template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vandq_s32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) -{ return vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a),vreinterpretq_u32_f32(b))); } -template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vorrq_s32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) -{ return vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a),vreinterpretq_u32_f32(b))); } -template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return veorq_s32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) -{ return vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a),vreinterpretq_u32_f32(b))); } -template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) -{ return vbicq_s32(a,b); } - -template<int N> EIGEN_STRONG_INLINE Packet4i pshiftright(Packet4i a) { return vshrq_n_s32(a,N); } -template<int N> EIGEN_STRONG_INLINE Packet4i pshiftleft(Packet4i a) { return vshlq_n_s32(a,N); } - -template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) -{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_f32(from); } -template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int32_t* from) -{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s32(from); } - -template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) -{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_f32(from); } -template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int32_t* from) -{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s32(from); } - -template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) -{ return vcombine_f32(vld1_dup_f32(from), vld1_dup_f32(from+1)); } -template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int32_t* from) -{ return vcombine_s32(vld1_dup_s32(from), vld1_dup_s32(from+1)); } - -template<> EIGEN_STRONG_INLINE Packet4f ploadquad<Packet4f>(const float* from) { return vld1q_dup_f32(from); } -template<> EIGEN_STRONG_INLINE Packet4i ploadquad<Packet4i>(const int32_t* from) { return vld1q_dup_s32(from); } - -template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) -{ EIGEN_DEBUG_ALIGNED_STORE vst1q_f32(to,from); } -template<> EIGEN_STRONG_INLINE void pstore<int32_t>(int32_t* to, const Packet4i& from) -{ EIGEN_DEBUG_ALIGNED_STORE vst1q_s32(to,from); } - -template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) -{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_f32(to,from); } -template<> EIGEN_STRONG_INLINE void pstoreu<int32_t>(int32_t* to, const Packet4i& from) -{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_s32(to,from); } - -template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) -{ - Packet4f res = vld1q_dup_f32(from); - res = vld1q_lane_f32(from + 1*stride, res, 1); - res = vld1q_lane_f32(from + 2*stride, res, 2); - res = vld1q_lane_f32(from + 3*stride, res, 3); - return res; -} -template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int32_t, Packet4i>(const int32_t* from, Index stride) -{ - Packet4i res = vld1q_dup_s32(from); - res = vld1q_lane_s32(from + 1*stride, res, 1); - res = vld1q_lane_s32(from + 2*stride, res, 2); - res = vld1q_lane_s32(from + 3*stride, res, 3); - return res; -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) -{ - vst1q_lane_f32(to + stride*0, from, 0); - vst1q_lane_f32(to + stride*1, from, 1); - vst1q_lane_f32(to + stride*2, from, 2); - vst1q_lane_f32(to + stride*3, from, 3); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<int32_t, Packet4i>(int32_t* to, const Packet4i& from, Index stride) -{ - vst1q_lane_s32(to + stride*0, from, 0); - vst1q_lane_s32(to + stride*1, from, 1); - vst1q_lane_s32(to + stride*2, from, 2); - vst1q_lane_s32(to + stride*3, from, 3); -} - -template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { EIGEN_ARM_PREFETCH(addr); } -template<> EIGEN_STRONG_INLINE void prefetch<int32_t>(const int32_t* addr) { EIGEN_ARM_PREFETCH(addr); } - -template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { return vgetq_lane_f32(a,0); } -template<> EIGEN_STRONG_INLINE int32_t pfirst<Packet4i>(const Packet4i& a) { return vgetq_lane_s32(a,0); } - -template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) -{ - const float32x4_t a_r64 = vrev64q_f32(a); - return vcombine_f32(vget_high_f32(a_r64), vget_low_f32(a_r64)); -} -template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) -{ - const int32x4_t a_r64 = vrev64q_s32(a); - return vcombine_s32(vget_high_s32(a_r64), vget_low_s32(a_r64)); -} -template<> EIGEN_STRONG_INLINE Packet4ui preverse(const Packet4ui& a) -{ - const uint32x4_t a_r64 = vrev64q_u32(a); - return vcombine_u32(vget_high_u32(a_r64), vget_low_u32(a_r64)); -} - -template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) { return vabsq_f32(a); } -template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) { return vabsq_s32(a); } - -template<> EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(const Packet4f& a, Packet4f& exponent) -{ return pfrexp_float(a,exponent); } - -template<> EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(const Packet4f& a, const Packet4f& exponent) -{ return pldexp_float(a,exponent); } - -template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) -{ - const float32x2_t sum = vadd_f32(vget_low_f32(a), vget_high_f32(a)); - return vget_lane_f32(vpadd_f32(sum, sum), 0); -} -template<> EIGEN_STRONG_INLINE int32_t predux<Packet4i>(const Packet4i& a) -{ - const int32x2_t sum = vadd_s32(vget_low_s32(a), vget_high_s32(a)); - return vget_lane_s32(vpadd_s32(sum, sum), 0); -} - -template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) -{ - const float32x4x2_t vtrn1 = vzipq_f32(vecs[0], vecs[2]); - const float32x4x2_t vtrn2 = vzipq_f32(vecs[1], vecs[3]); - const float32x4x2_t res1 = vzipq_f32(vtrn1.val[0], vtrn2.val[0]); - const float32x4x2_t res2 = vzipq_f32(vtrn1.val[1], vtrn2.val[1]); - return vaddq_f32(vaddq_f32(res1.val[0], res1.val[1]), vaddq_f32(res2.val[0], res2.val[1])); -} -template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs) -{ - const int32x4x2_t vtrn1 = vzipq_s32(vecs[0], vecs[2]); - const int32x4x2_t vtrn2 = vzipq_s32(vecs[1], vecs[3]); - const int32x4x2_t res1 = vzipq_s32(vtrn1.val[0], vtrn2.val[0]); - const int32x4x2_t res2 = vzipq_s32(vtrn1.val[1], vtrn2.val[1]); - return vaddq_s32(vaddq_s32(res1.val[0], res1.val[1]), vaddq_s32(res2.val[0], res2.val[1])); -} - -// Other reduction functions: -// mul -template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) -{ - // Get the product of a_lo * a_hi -> |a1*a3|a2*a4| - const float32x2_t prod = vmul_f32(vget_low_f32(a), vget_high_f32(a)); - // Multiply prod with its swapped value |a2*a4|a1*a3| - return vget_lane_f32(vmul_f32(prod, vrev64_f32(prod)), 0); -} -template<> EIGEN_STRONG_INLINE int32_t predux_mul<Packet4i>(const Packet4i& a) -{ - // Get the product of a_lo * a_hi -> |a1*a3|a2*a4| - const int32x2_t prod = vmul_s32(vget_low_s32(a), vget_high_s32(a)); - // Multiply prod with its swapped value |a2*a4|a1*a3| - return vget_lane_s32(vmul_s32(prod, vrev64_s32(prod)), 0); -} - -// min -template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) -{ - const float32x2_t min = vmin_f32(vget_low_f32(a), vget_high_f32(a)); - return vget_lane_f32(vpmin_f32(min, min), 0); -} -template<> EIGEN_STRONG_INLINE int32_t predux_min<Packet4i>(const Packet4i& a) -{ - const int32x2_t min = vmin_s32(vget_low_s32(a), vget_high_s32(a)); - return vget_lane_s32(vpmin_s32(min, min), 0); -} - -// max -template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) -{ - const float32x2_t max = vmax_f32(vget_low_f32(a), vget_high_f32(a)); - return vget_lane_f32(vpmax_f32(max, max), 0); -} -template<> EIGEN_STRONG_INLINE int32_t predux_max<Packet4i>(const Packet4i& a) -{ - const int32x2_t max = vmax_s32(vget_low_s32(a), vget_high_s32(a)); - return vget_lane_s32(vpmax_s32(max, max), 0); -} - -template<> EIGEN_STRONG_INLINE bool predux_any(const Packet4f& x) -{ - uint32x2_t tmp = vorr_u32(vget_low_u32( vreinterpretq_u32_f32(x)), - vget_high_u32(vreinterpretq_u32_f32(x))); - return vget_lane_u32(vpmax_u32(tmp, tmp), 0); -} - -// this PALIGN_NEON business is to work around a bug in LLVM Clang 3.0 causing incorrect compilation errors, -// see bug 347 and this LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=11074 -#define PALIGN_NEON(Offset,Type,Command) \ -template<>\ -struct palign_impl<Offset,Type>\ -{\ - EIGEN_STRONG_INLINE static void run(Type& first, const Type& second)\ - {\ - if (Offset!=0)\ - first = Command(first, second, Offset);\ - }\ -};\ - -PALIGN_NEON(0, Packet4f, vextq_f32) -PALIGN_NEON(1, Packet4f, vextq_f32) -PALIGN_NEON(2, Packet4f, vextq_f32) -PALIGN_NEON(3, Packet4f, vextq_f32) - -PALIGN_NEON(0, Packet4i, vextq_s32) -PALIGN_NEON(1, Packet4i, vextq_s32) -PALIGN_NEON(2, Packet4i, vextq_s32) -PALIGN_NEON(3, Packet4i, vextq_s32) - -#undef PALIGN_NEON - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f, 4>& kernel) -{ - const float32x4x2_t tmp1 = vzipq_f32(kernel.packet[0], kernel.packet[1]); - const float32x4x2_t tmp2 = vzipq_f32(kernel.packet[2], kernel.packet[3]); - - kernel.packet[0] = vcombine_f32(vget_low_f32(tmp1.val[0]), vget_low_f32(tmp2.val[0])); - kernel.packet[1] = vcombine_f32(vget_high_f32(tmp1.val[0]), vget_high_f32(tmp2.val[0])); - kernel.packet[2] = vcombine_f32(vget_low_f32(tmp1.val[1]), vget_low_f32(tmp2.val[1])); - kernel.packet[3] = vcombine_f32(vget_high_f32(tmp1.val[1]), vget_high_f32(tmp2.val[1])); -} - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4i, 4>& kernel) -{ - const int32x4x2_t tmp1 = vzipq_s32(kernel.packet[0], kernel.packet[1]); - const int32x4x2_t tmp2 = vzipq_s32(kernel.packet[2], kernel.packet[3]); - - kernel.packet[0] = vcombine_s32(vget_low_s32(tmp1.val[0]), vget_low_s32(tmp2.val[0])); - kernel.packet[1] = vcombine_s32(vget_high_s32(tmp1.val[0]), vget_high_s32(tmp2.val[0])); - kernel.packet[2] = vcombine_s32(vget_low_s32(tmp1.val[1]), vget_low_s32(tmp2.val[1])); - kernel.packet[3] = vcombine_s32(vget_high_s32(tmp1.val[1]), vget_high_s32(tmp2.val[1])); -} - -//---------- double ---------- - -// Clang 3.5 in the iOS toolchain has an ICE triggered by NEON intrisics for double. -// Confirmed at least with __apple_build_version__ = 6000054. -#ifdef __apple_build_version__ -// Let's hope that by the time __apple_build_version__ hits the 601* range, the bug will be fixed. -// https://gist.github.com/yamaya/2924292 suggests that the 3 first digits are only updated with -// major toolchain updates. -#define EIGEN_APPLE_DOUBLE_NEON_BUG (__apple_build_version__ < 6010000) -#else -#define EIGEN_APPLE_DOUBLE_NEON_BUG 0 -#endif - -#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG - -// Bug 907: workaround missing declarations of the following two functions in the ADK -// Defining these functions as templates ensures that if these intrinsics are -// already defined in arm_neon.h, then our workaround doesn't cause a conflict -// and has lower priority in overload resolution. -template <typename T> uint64x2_t vreinterpretq_u64_f64(T a) { return (uint64x2_t) a; } - -template <typename T> float64x2_t vreinterpretq_f64_u64(T a) { return (float64x2_t) a; } - -typedef float64x2_t Packet2d; -typedef float64x1_t Packet1d; - -template<> struct packet_traits<double> : default_packet_traits -{ - typedef Packet2d type; - typedef Packet2d half; - enum - { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 2, - HasHalfPacket = 0, - - HasDiv = 1, - // FIXME check the Has* - HasSin = 0, - HasCos = 0, - HasLog = 0, - HasExp = 0, - HasSqrt = 0 - }; -}; - -template<> struct unpacket_traits<Packet2d> -{ - typedef double type; - enum - { - size = 2, - alignment = Aligned16, - vectorizable = true, - masked_load_available = false, - masked_store_available = false - }; - typedef Packet2d half; -}; - -template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { return vdupq_n_f64(from); } - -template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) -{ - const double c[] = {0.0,1.0}; - return vaddq_f64(pset1<Packet2d>(a), vld1q_f64(c)); -} - -template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return vaddq_f64(a,b); } - -template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return vsubq_f64(a,b); } - -template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return vnegq_f64(a); } - -template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return vmulq_f64(a,b); } - -template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return vdivq_f64(a,b); } - -#ifdef __ARM_FEATURE_FMA -// See bug 936. See above comment about FMA for float. -template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) -{ return vfmaq_f64(c,a,b); } -#else -template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) -{ return vmlaq_f64(c,a,b); } -#endif - -template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { return vminq_f64(a,b); } - -template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { return vmaxq_f64(a,b); } - -// Logical Operations are not supported for float, so we have to reinterpret casts using NEON intrinsics -template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) -{ return vreinterpretq_f64_u64(vandq_u64(vreinterpretq_u64_f64(a),vreinterpretq_u64_f64(b))); } - -template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) -{ return vreinterpretq_f64_u64(vorrq_u64(vreinterpretq_u64_f64(a),vreinterpretq_u64_f64(b))); } - -template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) -{ return vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a),vreinterpretq_u64_f64(b))); } - -template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) -{ return vreinterpretq_f64_u64(vbicq_u64(vreinterpretq_u64_f64(a),vreinterpretq_u64_f64(b))); } - -template<> EIGEN_STRONG_INLINE Packet2d pcmp_le(const Packet2d& a, const Packet2d& b) -{ return vreinterpretq_f64_u64(vcleq_f64(a,b)); } - -template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt(const Packet2d& a, const Packet2d& b) -{ return vreinterpretq_f64_u64(vcltq_f64(a,b)); } - -template<> EIGEN_STRONG_INLINE Packet2d pcmp_eq(const Packet2d& a, const Packet2d& b) -{ return vreinterpretq_f64_u64(vceqq_f64(a,b)); } - -template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) -{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_f64(from); } - -template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) -{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_f64(from); } - -template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) { return vld1q_dup_f64(from); } -template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) -{ EIGEN_DEBUG_ALIGNED_STORE vst1q_f64(to,from); } - -template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) -{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_f64(to,from); } - -template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride) -{ - Packet2d res = pset1<Packet2d>(0.0); - res = vld1q_lane_f64(from + 0*stride, res, 0); - res = vld1q_lane_f64(from + 1*stride, res, 1); - return res; -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride) -{ - vst1q_lane_f64(to + stride*0, from, 0); - vst1q_lane_f64(to + stride*1, from, 1); -} - -template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_ARM_PREFETCH(addr); } - -// FIXME only store the 2 first elements ? -template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { return vgetq_lane_f64(a,0); } - -template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) -{ return vcombine_f64(vget_high_f64(a), vget_low_f64(a)); } - -template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) { return vabsq_f64(a); } - -#if EIGEN_COMP_CLANG && defined(__apple_build_version__) -// workaround ICE, see bug 907 -template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) -{ return (vget_low_f64(a) + vget_high_f64(a))[0]; } -#else -template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) -{ return vget_lane_f64(vget_low_f64(a) + vget_high_f64(a), 0); } -#endif - -template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs) -{ - return vaddq_f64(vzip1q_f64(vecs[0], vecs[1]), vzip2q_f64(vecs[0], vecs[1])); -} -// Other reduction functions: -// mul -#if EIGEN_COMP_CLANG && defined(__apple_build_version__) -template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) -{ return (vget_low_f64(a) * vget_high_f64(a))[0]; } -#else -template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) -{ return vget_lane_f64(vget_low_f64(a) * vget_high_f64(a), 0); } -#endif - -// min -template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) -{ return vgetq_lane_f64(vpminq_f64(a,a), 0); } - -// max -template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) -{ return vgetq_lane_f64(vpmaxq_f64(a,a), 0); } - -// this PALIGN_NEON business is to work around a bug in LLVM Clang 3.0 causing incorrect compilation errors, -// see bug 347 and this LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=11074 -#define PALIGN_NEON(Offset,Type,Command) \ -template<>\ -struct palign_impl<Offset,Type>\ -{\ - EIGEN_STRONG_INLINE static void run(Type& first, const Type& second)\ - {\ - if (Offset!=0)\ - first = Command(first, second, Offset);\ - }\ -};\ - -PALIGN_NEON(0, Packet2d, vextq_f64) -PALIGN_NEON(1, Packet2d, vextq_f64) -#undef PALIGN_NEON - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet2d, 2>& kernel) -{ - const float64x2_t tmp1 = vzip1q_f64(kernel.packet[0], kernel.packet[1]); - const float64x2_t tmp2 = vzip2q_f64(kernel.packet[0], kernel.packet[1]); - - kernel.packet[0] = tmp1; - kernel.packet[1] = tmp2; -} -#endif // EIGEN_ARCH_ARM64 - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PACKET_MATH_NEON_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/TypeCasting.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/TypeCasting.h deleted file mode 100644 index 5eb03be2..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/NEON/TypeCasting.h +++ /dev/null @@ -1,34 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2018 Rasmus Munk Larsen <rmlarsen@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TYPE_CASTING_NEON_H -#define EIGEN_TYPE_CASTING_NEON_H - -namespace Eigen { - -namespace internal { - -template<> struct type_casting_traits<float,numext::int32_t> -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; -template<> struct type_casting_traits<numext::int32_t,float> -{ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; }; - -template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4i,Packet4f>(const Packet4i& a) { return vcvtq_f32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet4i pcast<Packet4f,Packet4i>(const Packet4f& a) { return vcvtq_s32_f32(a); } - -template<> EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f,Packet4i>(const Packet4i& a) -{ return vreinterpretq_f32_s32(a); } -template<> EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i,Packet4f>(const Packet4f& a) -{ return vreinterpretq_s32_f32(a); } - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TYPE_CASTING_NEON_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/Complex.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/Complex.h deleted file mode 100644 index b3b1b485..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/Complex.h +++ /dev/null @@ -1,488 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX_SSE_H -#define EIGEN_COMPLEX_SSE_H - -namespace Eigen { - -namespace internal { - -//---------- float ---------- -struct Packet2cf -{ - EIGEN_STRONG_INLINE Packet2cf() {} - EIGEN_STRONG_INLINE explicit Packet2cf(const __m128& a) : v(a) {} - __m128 v; -}; - -// Use the packet_traits defined in AVX/PacketMath.h instead if we're going -// to leverage AVX instructions. -#ifndef EIGEN_VECTORIZE_AVX -template<> struct packet_traits<std::complex<float> > : default_packet_traits -{ - typedef Packet2cf type; - typedef Packet2cf half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 2, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0, - HasBlend = 1 - }; -}; -#endif - -template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2cf half; }; - -template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_add_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_sub_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) -{ - const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000)); - return Packet2cf(_mm_xor_ps(a.v,mask)); -} -template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) -{ - const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000)); - return Packet2cf(_mm_xor_ps(a.v,mask)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - #ifdef EIGEN_VECTORIZE_SSE3 - return Packet2cf(_mm_addsub_ps(_mm_mul_ps(_mm_moveldup_ps(a.v), b.v), - _mm_mul_ps(_mm_movehdup_ps(a.v), - vec4f_swizzle1(b.v, 1, 0, 3, 2)))); -// return Packet2cf(_mm_addsub_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), -// _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3), -// vec4f_swizzle1(b.v, 1, 0, 3, 2)))); - #else - const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x00000000,0x80000000,0x00000000)); - return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), - _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3), - vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask))); - #endif -} - -template<> EIGEN_STRONG_INLINE Packet2cf ptrue <Packet2cf>(const Packet2cf& a) { return Packet2cf(ptrue(Packet4f(a.v))); } -template<> EIGEN_STRONG_INLINE Packet2cf pnot <Packet2cf>(const Packet2cf& a) { return Packet2cf(pnot(Packet4f(a.v))); } - -template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_and_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_or_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_xor_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_andnot_ps(b.v,a.v)); } - -template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>(&numext::real_ref(*from))); } -template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>(&numext::real_ref(*from))); } - -template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from) -{ - Packet2cf res; -#if EIGEN_GNUC_AT_MOST(4,2) - // Workaround annoying "may be used uninitialized in this function" warning with gcc 4.2 - res.v = _mm_loadl_pi(_mm_set1_ps(0.0f), reinterpret_cast<const __m64*>(&from)); -#elif EIGEN_GNUC_AT_LEAST(4,6) - // Suppress annoying "may be used uninitialized in this function" warning with gcc >= 4.6 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wuninitialized" - res.v = _mm_loadl_pi(res.v, (const __m64*)&from); - #pragma GCC diagnostic pop -#else - res.v = _mm_loadl_pi(res.v, (const __m64*)&from); -#endif - return Packet2cf(_mm_movelh_ps(res.v,res.v)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); } - -template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), Packet4f(from.v)); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), Packet4f(from.v)); } - - -template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from, Index stride) -{ - return Packet2cf(_mm_set_ps(std::imag(from[1*stride]), std::real(from[1*stride]), - std::imag(from[0*stride]), std::real(from[0*stride]))); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from, Index stride) -{ - to[stride*0] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 0)), - _mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 1))); - to[stride*1] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 2)), - _mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 3))); -} - -template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } - -template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a) -{ - #if EIGEN_GNUC_AT_MOST(4,3) - // Workaround gcc 4.2 ICE - this is not performance wise ideal, but who cares... - // This workaround also fix invalid code generation with gcc 4.3 - EIGEN_ALIGN16 std::complex<float> res[2]; - _mm_store_ps((float*)res, a.v); - return res[0]; - #else - std::complex<float> res; - _mm_storel_pi((__m64*)&res, a.v); - return res; - #endif -} - -template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) { return Packet2cf(_mm_castpd_ps(preverse(Packet2d(_mm_castps_pd(a.v))))); } - -template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a) -{ - return pfirst(Packet2cf(_mm_add_ps(a.v, _mm_movehl_ps(a.v,a.v)))); -} - -template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs) -{ - return Packet2cf(_mm_add_ps(_mm_movelh_ps(vecs[0].v,vecs[1].v), _mm_movehl_ps(vecs[1].v,vecs[0].v))); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a) -{ - return pfirst(pmul(a, Packet2cf(_mm_movehl_ps(a.v,a.v)))); -} - -template<int Offset> -struct palign_impl<Offset,Packet2cf> -{ - static EIGEN_STRONG_INLINE void run(Packet2cf& first, const Packet2cf& second) - { - if (Offset==1) - { - first.v = _mm_movehl_ps(first.v, first.v); - first.v = _mm_movelh_ps(first.v, second.v); - } - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, false,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - #ifdef EIGEN_VECTORIZE_SSE3 - return internal::pmul(a, pconj(b)); - #else - const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000)); - return Packet2cf(_mm_add_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask), - _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3), - vec4f_swizzle1(b.v, 1, 0, 3, 2)))); - #endif - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, true,false> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - #ifdef EIGEN_VECTORIZE_SSE3 - return internal::pmul(pconj(a), b); - #else - const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000)); - return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), - _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3), - vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask))); - #endif - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, true,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - #ifdef EIGEN_VECTORIZE_SSE3 - return pconj(internal::pmul(a, b)); - #else - const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000)); - return Packet2cf(_mm_sub_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask), - _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3), - vec4f_swizzle1(b.v, 1, 0, 3, 2)))); - #endif - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f) - -template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - // TODO optimize it for SSE3 and 4 - Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b); - __m128 s = _mm_mul_ps(b.v,b.v); - return Packet2cf(_mm_div_ps(res.v,_mm_add_ps(s,_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(s), 0xb1))))); -} - -EIGEN_STRONG_INLINE Packet2cf pcplxflip/* <Packet2cf> */(const Packet2cf& x) -{ - return Packet2cf(vec4f_swizzle1(x.v, 1, 0, 3, 2)); -} - - -//---------- double ---------- -struct Packet1cd -{ - EIGEN_STRONG_INLINE Packet1cd() {} - EIGEN_STRONG_INLINE explicit Packet1cd(const __m128d& a) : v(a) {} - __m128d v; -}; - -// Use the packet_traits defined in AVX/PacketMath.h instead if we're going -// to leverage AVX instructions. -#ifndef EIGEN_VECTORIZE_AVX -template<> struct packet_traits<std::complex<double> > : default_packet_traits -{ - typedef Packet1cd type; - typedef Packet1cd half; - enum { - Vectorizable = 1, - AlignedOnScalar = 0, - size = 1, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0 - }; -}; -#endif - -template<> struct unpacket_traits<Packet1cd> { typedef std::complex<double> type; enum {size=1, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet1cd half; }; - -template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_add_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_sub_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(Packet2d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) -{ - const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0)); - return Packet1cd(_mm_xor_pd(a.v,mask)); -} - -template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ - #ifdef EIGEN_VECTORIZE_SSE3 - return Packet1cd(_mm_addsub_pd(_mm_mul_pd(_mm_movedup_pd(a.v), b.v), - _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1), - vec2d_swizzle1(b.v, 1, 0)))); - #else - const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0)); - return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), - _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1), - vec2d_swizzle1(b.v, 1, 0)), mask))); - #endif -} - -template<> EIGEN_STRONG_INLINE Packet1cd ptrue <Packet1cd>(const Packet1cd& a) { return Packet1cd(ptrue(Packet2d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet1cd pnot <Packet1cd>(const Packet1cd& a) { return Packet1cd(pnot(Packet2d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_and_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_or_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_xor_pd(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_andnot_pd(b.v,a.v)); } - -// FIXME force unaligned load, this is a temporary fix -template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from) -{ EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from)); } -template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) -{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from)); } -template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from) -{ /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); } - -template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); } - -// FIXME force unaligned store, this is a temporary fix -template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, Packet2d(from.v)); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, Packet2d(from.v)); } - -template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } - -template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a) -{ - EIGEN_ALIGN16 double res[2]; - _mm_store_pd(res, a.v); - return std::complex<double>(res[0],res[1]); -} - -template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; } - -template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) -{ - return pfirst(a); -} - -template<> EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(const Packet1cd* vecs) -{ - return vecs[0]; -} - -template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) -{ - return pfirst(a); -} - -template<int Offset> -struct palign_impl<Offset,Packet1cd> -{ - static EIGEN_STRONG_INLINE void run(Packet1cd& /*first*/, const Packet1cd& /*second*/) - { - // FIXME is it sure we never have to align a Packet1cd? - // Even though a std::complex<double> has 16 bytes, it is not necessarily aligned on a 16 bytes boundary... - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, false,true> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - #ifdef EIGEN_VECTORIZE_SSE3 - return internal::pmul(a, pconj(b)); - #else - const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0)); - return Packet1cd(_mm_add_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask), - _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1), - vec2d_swizzle1(b.v, 1, 0)))); - #endif - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, true,false> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - #ifdef EIGEN_VECTORIZE_SSE3 - return internal::pmul(pconj(a), b); - #else - const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0)); - return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), - _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1), - vec2d_swizzle1(b.v, 1, 0)), mask))); - #endif - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, true,true> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - #ifdef EIGEN_VECTORIZE_SSE3 - return pconj(internal::pmul(a, b)); - #else - const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0)); - return Packet1cd(_mm_sub_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask), - _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1), - vec2d_swizzle1(b.v, 1, 0)))); - #endif - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d) - -template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ - // TODO optimize it for SSE3 and 4 - Packet1cd res = conj_helper<Packet1cd,Packet1cd,false,true>().pmul(a,b); - __m128d s = _mm_mul_pd(b.v,b.v); - return Packet1cd(_mm_div_pd(res.v, _mm_add_pd(s,_mm_shuffle_pd(s, s, 0x1)))); -} - -EIGEN_STRONG_INLINE Packet1cd pcplxflip/* <Packet1cd> */(const Packet1cd& x) -{ - return Packet1cd(preverse(Packet2d(x.v))); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet2cf,2>& kernel) { - __m128d w1 = _mm_castps_pd(kernel.packet[0].v); - __m128d w2 = _mm_castps_pd(kernel.packet[1].v); - - __m128 tmp = _mm_castpd_ps(_mm_unpackhi_pd(w1, w2)); - kernel.packet[0].v = _mm_castpd_ps(_mm_unpacklo_pd(w1, w2)); - kernel.packet[1].v = tmp; -} - -template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b) -{ - __m128 eq = _mm_cmpeq_ps(a.v, b.v); - return Packet2cf(pand<Packet4f>(eq, vec4f_swizzle1(eq, 1, 0, 3, 2))); -} - -template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b) -{ - __m128d eq = _mm_cmpeq_pd(a.v, b.v); - return Packet1cd(pand<Packet2d>(eq, vec2d_swizzle1(eq, 1, 0))); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) { - __m128d result = pblend<Packet2d>(ifPacket, _mm_castps_pd(thenPacket.v), _mm_castps_pd(elsePacket.v)); - return Packet2cf(_mm_castpd_ps(result)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pinsertfirst(const Packet2cf& a, std::complex<float> b) -{ - return Packet2cf(_mm_loadl_pi(a.v, reinterpret_cast<const __m64*>(&b))); -} - -template<> EIGEN_STRONG_INLINE Packet1cd pinsertfirst(const Packet1cd&, std::complex<double> b) -{ - return pset1<Packet1cd>(b); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pinsertlast(const Packet2cf& a, std::complex<float> b) -{ - return Packet2cf(_mm_loadh_pi(a.v, reinterpret_cast<const __m64*>(&b))); -} - -template<> EIGEN_STRONG_INLINE Packet1cd pinsertlast(const Packet1cd&, std::complex<double> b) -{ - return pset1<Packet1cd>(b); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_SSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/MathFunctions.h deleted file mode 100644 index 92c1eecc..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/MathFunctions.h +++ /dev/null @@ -1,182 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007 Julien Pommier -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* The sin and cos and functions of this file come from - * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/ - */ - -#ifndef EIGEN_MATH_FUNCTIONS_SSE_H -#define EIGEN_MATH_FUNCTIONS_SSE_H - -namespace Eigen { - -namespace internal { - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f plog<Packet4f>(const Packet4f& _x) { - return plog_float(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f plog1p<Packet4f>(const Packet4f& _x) { - return generic_plog1p(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f pexpm1<Packet4f>(const Packet4f& _x) { - return generic_expm1(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f pexp<Packet4f>(const Packet4f& _x) -{ - return pexp_float(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d pexp<Packet2d>(const Packet2d& x) -{ - return pexp_double(x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f psin<Packet4f>(const Packet4f& _x) -{ - return psin_float(_x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f pcos<Packet4f>(const Packet4f& _x) -{ - return pcos_float(_x); -} - -#if EIGEN_FAST_MATH - -// Functions for sqrt. -// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step -// of Newton's method, at a cost of 1-2 bits of precision as opposed to the -// exact solution. It does not handle +inf, or denormalized numbers correctly. -// The main advantage of this approach is not just speed, but also the fact that -// it can be inlined and pipelined with other computations, further reducing its -// effective latency. This is similar to Quake3's fast inverse square root. -// For detail see here: http://www.beyond3d.com/content/articles/8/ -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f psqrt<Packet4f>(const Packet4f& _x) -{ - Packet4f half = pmul(_x, pset1<Packet4f>(.5f)); - Packet4f denormal_mask = _mm_and_ps( - _mm_cmpge_ps(_x, _mm_setzero_ps()), - _mm_cmplt_ps(_x, pset1<Packet4f>((std::numeric_limits<float>::min)()))); - - // Compute approximate reciprocal sqrt. - Packet4f x = _mm_rsqrt_ps(_x); - // Do a single step of Newton's iteration. - x = pmul(x, psub(pset1<Packet4f>(1.5f), pmul(half, pmul(x,x)))); - // Flush results for denormals to zero. - return _mm_andnot_ps(denormal_mask, pmul(_x,x)); -} - -#else - -template<>EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f psqrt<Packet4f>(const Packet4f& x) { return _mm_sqrt_ps(x); } - -#endif - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d psqrt<Packet2d>(const Packet2d& x) { return _mm_sqrt_pd(x); } - -#if EIGEN_FAST_MATH - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f prsqrt<Packet4f>(const Packet4f& _x) { - _EIGEN_DECLARE_CONST_Packet4f(one_point_five, 1.5f); - _EIGEN_DECLARE_CONST_Packet4f(minus_half, -0.5f); - _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(inf, 0x7f800000u); - _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(flt_min, 0x00800000u); - - Packet4f neg_half = pmul(_x, p4f_minus_half); - - // Identity infinite, zero, negative and denormal arguments. - Packet4f lt_min_mask = _mm_cmplt_ps(_x, p4f_flt_min); - Packet4f inf_mask = _mm_cmpeq_ps(_x, p4f_inf); - Packet4f not_normal_finite_mask = _mm_or_ps(lt_min_mask, inf_mask); - - // Compute an approximate result using the rsqrt intrinsic. - Packet4f y_approx = _mm_rsqrt_ps(_x); - - // Do a single step of Newton-Raphson iteration to improve the approximation. - // This uses the formula y_{n+1} = y_n * (1.5 - y_n * (0.5 * x) * y_n). - // It is essential to evaluate the inner term like this because forming - // y_n^2 may over- or underflow. - Packet4f y_newton = pmul( - y_approx, pmadd(y_approx, pmul(neg_half, y_approx), p4f_one_point_five)); - - // Select the result of the Newton-Raphson step for positive normal arguments. - // For other arguments, choose the output of the intrinsic. This will - // return rsqrt(+inf) = 0, rsqrt(x) = NaN if x < 0, and rsqrt(x) = +inf if - // x is zero or a positive denormalized float (equivalent to flushing positive - // denormalized inputs to zero). - return pselect<Packet4f>(not_normal_finite_mask, y_approx, y_newton); -} - -#else - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f prsqrt<Packet4f>(const Packet4f& x) { - // Unfortunately we can't use the much faster mm_rqsrt_ps since it only provides an approximation. - return _mm_div_ps(pset1<Packet4f>(1.0f), _mm_sqrt_ps(x)); -} - -#endif - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d prsqrt<Packet2d>(const Packet2d& x) { - // Unfortunately we can't use the much faster mm_rqsrt_pd since it only provides an approximation. - return _mm_div_pd(pset1<Packet2d>(1.0), _mm_sqrt_pd(x)); -} - -// Hyperbolic Tangent function. -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f -ptanh<Packet4f>(const Packet4f& x) { - return internal::generic_fast_tanh_float(x); -} - -} // end namespace internal - -namespace numext { - -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float sqrt(const float &x) -{ - return internal::pfirst(internal::Packet4f(_mm_sqrt_ss(_mm_set_ss(x)))); -} - -template<> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double sqrt(const double &x) -{ -#if EIGEN_COMP_GNUC_STRICT - // This works around a GCC bug generating poor code for _mm_sqrt_pd - // See https://gitlab.com/libeigen/eigen/commit/8dca9f97e38970 - return internal::pfirst(internal::Packet2d(__builtin_ia32_sqrtsd(_mm_set_sd(x)))); -#else - return internal::pfirst(internal::Packet2d(_mm_sqrt_pd(_mm_set_sd(x)))); -#endif -} - -} // end namespace numex - -} // end namespace Eigen - -#endif // EIGEN_MATH_FUNCTIONS_SSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h deleted file mode 100644 index d6a4a5c7..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h +++ /dev/null @@ -1,1307 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PACKET_MATH_SSE_H -#define EIGEN_PACKET_MATH_SSE_H - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD -#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 -#endif - -#if !defined(EIGEN_VECTORIZE_AVX) && !defined(EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS) -// 32 bits => 8 registers -// 64 bits => 16 registers -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS (2*sizeof(void*)) -#endif - -#ifdef EIGEN_VECTORIZE_FMA -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD 1 -#endif -#endif - -#if ((defined EIGEN_VECTORIZE_AVX) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_MINGW) && (__GXX_ABI_VERSION < 1004)) || EIGEN_OS_QNX -// With GCC's default ABI version, a __m128 or __m256 are the same types and therefore we cannot -// have overloads for both types without linking error. -// One solution is to increase ABI version using -fabi-version=4 (or greater). -// Otherwise, we workaround this inconvenience by wrapping 128bit types into the following helper -// structure: -template<typename T> -struct eigen_packet_wrapper -{ - EIGEN_ALWAYS_INLINE operator T&() { return m_val; } - EIGEN_ALWAYS_INLINE operator const T&() const { return m_val; } - EIGEN_ALWAYS_INLINE eigen_packet_wrapper() {} - EIGEN_ALWAYS_INLINE eigen_packet_wrapper(const T &v) : m_val(v) {} - EIGEN_ALWAYS_INLINE eigen_packet_wrapper& operator=(const T &v) { - m_val = v; - return *this; - } - - T m_val; -}; -typedef eigen_packet_wrapper<__m128> Packet4f; -typedef eigen_packet_wrapper<__m128i> Packet4i; -typedef eigen_packet_wrapper<__m128d> Packet2d; -#else -typedef __m128 Packet4f; -typedef __m128i Packet4i; -typedef __m128d Packet2d; -#endif - -template<> struct is_arithmetic<__m128> { enum { value = true }; }; -template<> struct is_arithmetic<__m128i> { enum { value = true }; }; -template<> struct is_arithmetic<__m128d> { enum { value = true }; }; - -#define EIGEN_SSE_SHUFFLE_MASK(p,q,r,s) ((s)<<6|(r)<<4|(q)<<2|(p)) - -#define vec4f_swizzle1(v,p,q,r,s) \ - (_mm_castsi128_ps(_mm_shuffle_epi32( _mm_castps_si128(v), EIGEN_SSE_SHUFFLE_MASK(p,q,r,s)))) - -#define vec4i_swizzle1(v,p,q,r,s) \ - (_mm_shuffle_epi32( v, EIGEN_SSE_SHUFFLE_MASK(p,q,r,s))) - -#define vec2d_swizzle1(v,p,q) \ - (_mm_castsi128_pd(_mm_shuffle_epi32( _mm_castpd_si128(v), EIGEN_SSE_SHUFFLE_MASK(2*p,2*p+1,2*q,2*q+1)))) - -#define vec4f_swizzle2(a,b,p,q,r,s) \ - (_mm_shuffle_ps( (a), (b), EIGEN_SSE_SHUFFLE_MASK(p,q,r,s))) - -#define vec4i_swizzle2(a,b,p,q,r,s) \ - (_mm_castps_si128( (_mm_shuffle_ps( _mm_castsi128_ps(a), _mm_castsi128_ps(b), EIGEN_SSE_SHUFFLE_MASK(p,q,r,s))))) - -#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \ - const Packet4f p4f_##NAME = pset1<Packet4f>(X) - -#define _EIGEN_DECLARE_CONST_Packet2d(NAME,X) \ - const Packet2d p2d_##NAME = pset1<Packet2d>(X) - -#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \ - const Packet4f p4f_##NAME = pset1frombits<Packet4f>(X) - -#define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \ - const Packet4i p4i_##NAME = pset1<Packet4i>(X) - - -// Use the packet_traits defined in AVX/PacketMath.h instead if we're going -// to leverage AVX instructions. -#ifndef EIGEN_VECTORIZE_AVX -template <> -struct packet_traits<float> : default_packet_traits { - typedef Packet4f type; - typedef Packet4f half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, - - HasDiv = 1, - HasSin = EIGEN_FAST_MATH, - HasCos = EIGEN_FAST_MATH, - HasLog = 1, - HasLog1p = 1, - HasExpm1 = 1, - HasNdtri = 1, - HasExp = 1, - HasBessel = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasTanh = EIGEN_FAST_MATH, - HasErf = EIGEN_FAST_MATH, - HasBlend = 1, - HasFloor = 1 - -#ifdef EIGEN_VECTORIZE_SSE4_1 - , - HasRint = 1, - HasRound = 1, - HasCeil = 1 -#endif - }; -}; -template <> -struct packet_traits<double> : default_packet_traits { - typedef Packet2d type; - typedef Packet2d half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=2, - HasHalfPacket = 0, - - HasDiv = 1, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasBlend = 1 - -#ifdef EIGEN_VECTORIZE_SSE4_1 - , - HasRound = 1, - HasRint = 1, - HasFloor = 1, - HasCeil = 1 -#endif - }; -}; -#endif -template<> struct packet_traits<int> : default_packet_traits -{ - typedef Packet4i type; - typedef Packet4i half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=4, - - HasBlend = 1 - }; -}; - -template<> struct unpacket_traits<Packet4f> { - typedef float type; - typedef Packet4f half; - typedef Packet4i integer_packet; - enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; -}; -template<> struct unpacket_traits<Packet2d> { - typedef double type; - typedef Packet2d half; - enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; -}; -template<> struct unpacket_traits<Packet4i> { - typedef int type; - typedef Packet4i half; - enum {size=4, alignment=Aligned16, vectorizable=false, masked_load_available=false, masked_store_available=false}; -}; - -#ifndef EIGEN_VECTORIZE_AVX -template<> struct scalar_div_cost<float,true> { enum { value = 7 }; }; -template<> struct scalar_div_cost<double,true> { enum { value = 8 }; }; -#endif - -#if EIGEN_COMP_MSVC==1500 -// Workaround MSVC 9 internal compiler error. -// TODO: It has been detected with win64 builds (amd64), so let's check whether it also happens in 32bits+SSE mode -// TODO: let's check whether there does not exist a better fix, like adding a pset0() function. (it crashed on pset1(0)). -template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { return _mm_set_ps(from,from,from,from); } -template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { return _mm_set_pd(from,from); } -template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) { return _mm_set_epi32(from,from,from,from); } -#else -template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { return _mm_set_ps1(from); } -template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { return _mm_set1_pd(from); } -template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) { return _mm_set1_epi32(from); } -#endif - -template<> EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(unsigned int from) { return _mm_castsi128_ps(pset1<Packet4i>(from)); } - -template<> EIGEN_STRONG_INLINE Packet4f pzero(const Packet4f& /*a*/) { return _mm_setzero_ps(); } -template<> EIGEN_STRONG_INLINE Packet2d pzero(const Packet2d& /*a*/) { return _mm_setzero_pd(); } -template<> EIGEN_STRONG_INLINE Packet4i pzero(const Packet4i& /*a*/) { return _mm_setzero_si128(); } - -// GCC generates a shufps instruction for _mm_set1_ps/_mm_load1_ps instead of the more efficient pshufd instruction. -// However, using inrinsics for pset1 makes gcc to generate crappy code in some cases (see bug 203) -// Using inline assembly is also not an option because then gcc fails to reorder properly the instructions. -// Therefore, we introduced the pload1 functions to be used in product kernels for which bug 203 does not apply. -// Also note that with AVX, we want it to generate a vbroadcastss. -#if EIGEN_COMP_GNUC_STRICT && (!defined __AVX__) -template<> EIGEN_STRONG_INLINE Packet4f pload1<Packet4f>(const float *from) { - return vec4f_swizzle1(_mm_load_ss(from),0,0,0,0); -} -#endif - -template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) { return _mm_add_ps(pset1<Packet4f>(a), _mm_set_ps(3,2,1,0)); } -template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return _mm_add_pd(pset1<Packet2d>(a),_mm_set_pd(1,0)); } -template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return _mm_add_epi32(pset1<Packet4i>(a),_mm_set_epi32(3,2,1,0)); } - -template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_add_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_add_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_add_epi32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_sub_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_sub_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_sub_epi32(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) -{ - const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000)); - return _mm_xor_ps(a,mask); -} -template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) -{ - const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0,0x80000000,0x0,0x80000000)); - return _mm_xor_pd(a,mask); -} -template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) -{ - return psub(Packet4i(_mm_setr_epi32(0,0,0,0)), a); -} - -template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_mul_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_mul_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_mullo_epi32(a,b); -#else - // this version is slightly faster than 4 scalar products - return vec4i_swizzle1( - vec4i_swizzle2( - _mm_mul_epu32(a,b), - _mm_mul_epu32(vec4i_swizzle1(a,1,0,3,2), - vec4i_swizzle1(b,1,0,3,2)), - 0,2,0,2), - 0,2,1,3); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_div_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_div_pd(a,b); } - -// for some weird raisons, it has to be overloaded for packet of integers -template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return padd(pmul(a,b), c); } -#ifdef EIGEN_VECTORIZE_FMA -template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) { return _mm_fmadd_ps(a,b,c); } -template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return _mm_fmadd_pd(a,b,c); } -#endif - -#ifdef EIGEN_VECTORIZE_SSE4_1 -template<> EIGEN_DEVICE_FUNC inline Packet4f pselect(const Packet4f& mask, const Packet4f& a, const Packet4f& b) { return _mm_blendv_ps(b,a,mask); } - -template<> EIGEN_DEVICE_FUNC inline Packet2d pselect(const Packet2d& mask, const Packet2d& a, const Packet2d& b) { return _mm_blendv_pd(b,a,mask); } -#endif - -template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) { -#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63 - // There appears to be a bug in GCC, by which the optimizer may - // flip the argument order in calls to _mm_min_ps, so we have to - // resort to inline ASM here. This is supposed to be fixed in gcc6.3, - // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867 - #ifdef EIGEN_VECTORIZE_AVX - Packet4f res; - asm("vminps %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b)); - #else - Packet4f res = b; - asm("minps %[a], %[res]" : [res] "+x" (res) : [a] "x" (a)); - #endif - return res; -#else - // Arguments are reversed to match NaN propagation behavior of std::min. - return _mm_min_ps(b, a); -#endif -} -template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { -#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63 - // There appears to be a bug in GCC, by which the optimizer may - // flip the argument order in calls to _mm_min_pd, so we have to - // resort to inline ASM here. This is supposed to be fixed in gcc6.3, - // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867 - #ifdef EIGEN_VECTORIZE_AVX - Packet2d res; - asm("vminpd %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b)); - #else - Packet2d res = b; - asm("minpd %[a], %[res]" : [res] "+x" (res) : [a] "x" (a)); - #endif - return res; -#else - // Arguments are reversed to match NaN propagation behavior of std::min. - return _mm_min_pd(b, a); -#endif -} -template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_min_epi32(a,b); -#else - // after some bench, this version *is* faster than a scalar implementation - Packet4i mask = _mm_cmplt_epi32(a,b); - return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b)); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) { -#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63 - // There appears to be a bug in GCC, by which the optimizer may - // flip the argument order in calls to _mm_max_ps, so we have to - // resort to inline ASM here. This is supposed to be fixed in gcc6.3, - // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867 - #ifdef EIGEN_VECTORIZE_AVX - Packet4f res; - asm("vmaxps %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b)); - #else - Packet4f res = b; - asm("maxps %[a], %[res]" : [res] "+x" (res) : [a] "x" (a)); - #endif - return res; -#else - // Arguments are reversed to match NaN propagation behavior of std::max. - return _mm_max_ps(b, a); -#endif -} -template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { -#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63 - // There appears to be a bug in GCC, by which the optimizer may - // flip the argument order in calls to _mm_max_pd, so we have to - // resort to inline ASM here. This is supposed to be fixed in gcc6.3, - // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867 - #ifdef EIGEN_VECTORIZE_AVX - Packet2d res; - asm("vmaxpd %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b)); - #else - Packet2d res = b; - asm("maxpd %[a], %[res]" : [res] "+x" (res) : [a] "x" (a)); - #endif - return res; -#else - // Arguments are reversed to match NaN propagation behavior of std::max. - return _mm_max_pd(b, a); -#endif -} -template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_max_epi32(a,b); -#else - // after some bench, this version *is* faster than a scalar implementation - Packet4i mask = _mm_cmpgt_epi32(a,b); - return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b)); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4f pcmp_le(const Packet4f& a, const Packet4f& b) { return _mm_cmple_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt(const Packet4f& a, const Packet4f& b) { return _mm_cmplt_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt_or_nan(const Packet4f& a, const Packet4f& b) { return _mm_cmpnge_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet4f pcmp_eq(const Packet4f& a, const Packet4f& b) { return _mm_cmpeq_ps(a,b); } - -template<> EIGEN_STRONG_INLINE Packet2d pcmp_le(const Packet2d& a, const Packet2d& b) { return _mm_cmple_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt(const Packet2d& a, const Packet2d& b) { return _mm_cmplt_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt_or_nan(const Packet2d& a, const Packet2d& b) { return _mm_cmpnge_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d pcmp_eq(const Packet2d& a, const Packet2d& b) { return _mm_cmpeq_pd(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4i pcmp_lt(const Packet4i& a, const Packet4i& b) { return _mm_cmplt_epi32(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i pcmp_eq(const Packet4i& a, const Packet4i& b) { return _mm_cmpeq_epi32(a,b); } - - -template<> EIGEN_STRONG_INLINE Packet4i ptrue<Packet4i>(const Packet4i& a) { return _mm_cmpeq_epi32(a, a); } -template<> EIGEN_STRONG_INLINE Packet4f -ptrue<Packet4f>(const Packet4f& a) { - Packet4i b = _mm_castps_si128(a); - return _mm_castsi128_ps(_mm_cmpeq_epi32(b, b)); -} -template<> EIGEN_STRONG_INLINE Packet2d -ptrue<Packet2d>(const Packet2d& a) { - Packet4i b = _mm_castpd_si128(a); - return _mm_castsi128_pd(_mm_cmpeq_epi32(b, b)); -} - -template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_and_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_and_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_and_si128(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_or_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_or_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_or_si128(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_xor_ps(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_xor_pd(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_xor_si128(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_andnot_ps(b,a); } -template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_andnot_pd(b,a); } -template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_andnot_si128(b,a); } - -template<int N> EIGEN_STRONG_INLINE Packet4i pshiftright(Packet4i a) { return _mm_srli_epi32(a,N); } -template<int N> EIGEN_STRONG_INLINE Packet4i pshiftleft(Packet4i a) { return _mm_slli_epi32(a,N); } - -#ifdef EIGEN_VECTORIZE_SSE4_1 -template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) -{ - // Unfortunatly _mm_round_ps doesn't have a rounding mode to implement numext::round. - const Packet4f mask = pset1frombits<Packet4f>(0x80000000u); - const Packet4f prev0dot5 = pset1frombits<Packet4f>(0x3EFFFFFFu); - return _mm_round_ps(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO); -} - -template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) -{ - const Packet2d mask = _mm_castsi128_pd(_mm_set_epi64x(0x8000000000000000ull, 0x8000000000000000ull)); - const Packet2d prev0dot5 = _mm_castsi128_pd(_mm_set_epi64x(0x3FDFFFFFFFFFFFFFull, 0x3FDFFFFFFFFFFFFFull)); - return _mm_round_pd(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO); -} - -template<> EIGEN_STRONG_INLINE Packet4f print<Packet4f>(const Packet4f& a) { return _mm_round_ps(a, _MM_FROUND_CUR_DIRECTION); } -template<> EIGEN_STRONG_INLINE Packet2d print<Packet2d>(const Packet2d& a) { return _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION); } - -template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) { return _mm_ceil_ps(a); } -template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return _mm_ceil_pd(a); } - -template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) { return _mm_floor_ps(a); } -template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return _mm_floor_pd(a); } -#else -template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) -{ - const Packet4f cst_1 = pset1<Packet4f>(1.0f); - Packet4i emm0 = _mm_cvttps_epi32(a); - Packet4f tmp = _mm_cvtepi32_ps(emm0); - /* if greater, substract 1 */ - Packet4f mask = _mm_cmpgt_ps(tmp, a); - mask = pand(mask, cst_1); - return psub(tmp, mask); -} - -// WARNING: this pfloor implementation makes sense for small inputs only, -// It is currently only used by pexp and not exposed through HasFloor. -template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) -{ - const Packet2d cst_1 = pset1<Packet2d>(1.0); - Packet4i emm0 = _mm_cvttpd_epi32(a); - Packet2d tmp = _mm_cvtepi32_pd(emm0); - /* if greater, substract 1 */ - Packet2d mask = _mm_cmpgt_pd(tmp, a); - mask = pand(mask, cst_1); - return psub(tmp, mask); -} -#endif - -template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_ps(from); } -template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_pd(from); } -template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_si128(reinterpret_cast<const __m128i*>(from)); } - -#if EIGEN_COMP_MSVC - template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) { - EIGEN_DEBUG_UNALIGNED_LOAD - #if (EIGEN_COMP_MSVC==1600) - // NOTE Some version of MSVC10 generates bad code when using _mm_loadu_ps - // (i.e., it does not generate an unaligned load!! - __m128 res = _mm_loadl_pi(_mm_set1_ps(0.0f), (const __m64*)(from)); - res = _mm_loadh_pi(res, (const __m64*)(from+2)); - return res; - #else - return _mm_loadu_ps(from); - #endif - } -#else -// NOTE: with the code below, MSVC's compiler crashes! - -template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) -{ - EIGEN_DEBUG_UNALIGNED_LOAD - return _mm_loadu_ps(from); -} -#endif - -template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) -{ - EIGEN_DEBUG_UNALIGNED_LOAD - return _mm_loadu_pd(from); -} -template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) -{ - EIGEN_DEBUG_UNALIGNED_LOAD - return _mm_loadu_si128(reinterpret_cast<const __m128i*>(from)); -} - - -template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) -{ - return vec4f_swizzle1(_mm_castpd_ps(_mm_load_sd(reinterpret_cast<const double*>(from))), 0, 0, 1, 1); -} -template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) -{ return pset1<Packet2d>(from[0]); } -template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from) -{ - Packet4i tmp; - tmp = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(from)); - return vec4i_swizzle1(tmp, 0, 0, 1, 1); -} - -template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_ps(to, from); } -template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_pd(to, from); } -template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(reinterpret_cast<__m128i*>(to), from); } - -template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_pd(to, from); } -template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_ps(to, from); } -template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_si128(reinterpret_cast<__m128i*>(to), from); } - -template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) -{ - return _mm_set_ps(from[3*stride], from[2*stride], from[1*stride], from[0*stride]); -} -template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride) -{ - return _mm_set_pd(from[1*stride], from[0*stride]); -} -template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride) -{ - return _mm_set_epi32(from[3*stride], from[2*stride], from[1*stride], from[0*stride]); - } - -template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) -{ - to[stride*0] = _mm_cvtss_f32(from); - to[stride*1] = _mm_cvtss_f32(_mm_shuffle_ps(from, from, 1)); - to[stride*2] = _mm_cvtss_f32(_mm_shuffle_ps(from, from, 2)); - to[stride*3] = _mm_cvtss_f32(_mm_shuffle_ps(from, from, 3)); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride) -{ - to[stride*0] = _mm_cvtsd_f64(from); - to[stride*1] = _mm_cvtsd_f64(_mm_shuffle_pd(from, from, 1)); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride) -{ - to[stride*0] = _mm_cvtsi128_si32(from); - to[stride*1] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 1)); - to[stride*2] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 2)); - to[stride*3] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 3)); -} - -// some compilers might be tempted to perform multiple moves instead of using a vector path. -template<> EIGEN_STRONG_INLINE void pstore1<Packet4f>(float* to, const float& a) -{ - Packet4f pa = _mm_set_ss(a); - pstore(to, Packet4f(vec4f_swizzle1(pa,0,0,0,0))); -} -// some compilers might be tempted to perform multiple moves instead of using a vector path. -template<> EIGEN_STRONG_INLINE void pstore1<Packet2d>(double* to, const double& a) -{ - Packet2d pa = _mm_set_sd(a); - pstore(to, Packet2d(vec2d_swizzle1(pa,0,0))); -} - -#if EIGEN_COMP_PGI && EIGEN_COMP_PGI < 1900 -typedef const void * SsePrefetchPtrType; -#else -typedef const char * SsePrefetchPtrType; -#endif - -#ifndef EIGEN_VECTORIZE_AVX -template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } -template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } -template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); } -#endif - -#if EIGEN_COMP_MSVC_STRICT && EIGEN_OS_WIN64 -// The temporary variable fixes an internal compilation error in vs <= 2008 and a wrong-result bug in vs 2010 -// Direct of the struct members fixed bug #62. -template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { return a.m128_f32[0]; } -template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { return a.m128d_f64[0]; } -template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int x = _mm_cvtsi128_si32(a); return x; } -#elif EIGEN_COMP_MSVC_STRICT -// The temporary variable fixes an internal compilation error in vs <= 2008 and a wrong-result bug in vs 2010 -template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float x = _mm_cvtss_f32(a); return x; } -template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { double x = _mm_cvtsd_f64(a); return x; } -template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int x = _mm_cvtsi128_si32(a); return x; } -#else -template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { return _mm_cvtss_f32(a); } -template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { return _mm_cvtsd_f64(a); } -template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { return _mm_cvtsi128_si32(a); } -#endif - -template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) -{ return _mm_shuffle_ps(a,a,0x1B); } -template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) -{ return _mm_shuffle_pd(a,a,0x1); } -template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) -{ return _mm_shuffle_epi32(a,0x1B); } - -template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) -{ - const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF)); - return _mm_and_ps(a,mask); -} -template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) -{ - const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF)); - return _mm_and_pd(a,mask); -} -template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) -{ - #ifdef EIGEN_VECTORIZE_SSSE3 - return _mm_abs_epi32(a); - #else - Packet4i aux = _mm_srai_epi32(a,31); - return _mm_sub_epi32(_mm_xor_si128(a,aux),aux); - #endif -} - -template<> EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(const Packet4f& a, Packet4f& exponent) { - return pfrexp_float(a,exponent); -} - -template<> EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(const Packet4f& a, const Packet4f& exponent) { - return pldexp_float(a,exponent); -} - -template<> EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(const Packet2d& a, const Packet2d& exponent) { - const Packet4i cst_1023_0 = _mm_setr_epi32(1023, 1023, 0, 0); - Packet4i emm0 = _mm_cvttpd_epi32(exponent); - emm0 = padd(emm0, cst_1023_0); - emm0 = _mm_slli_epi32(emm0, 20); - emm0 = _mm_shuffle_epi32(emm0, _MM_SHUFFLE(1,2,0,3)); - return pmul(a, Packet2d(_mm_castsi128_pd(emm0))); -} - -// with AVX, the default implementations based on pload1 are faster -#ifndef __AVX__ -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet4f>(const float *a, - Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) -{ - a3 = pload<Packet4f>(a); - a0 = vec4f_swizzle1(a3, 0,0,0,0); - a1 = vec4f_swizzle1(a3, 1,1,1,1); - a2 = vec4f_swizzle1(a3, 2,2,2,2); - a3 = vec4f_swizzle1(a3, 3,3,3,3); -} -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet2d>(const double *a, - Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3) -{ -#ifdef EIGEN_VECTORIZE_SSE3 - a0 = _mm_loaddup_pd(a+0); - a1 = _mm_loaddup_pd(a+1); - a2 = _mm_loaddup_pd(a+2); - a3 = _mm_loaddup_pd(a+3); -#else - a1 = pload<Packet2d>(a); - a0 = vec2d_swizzle1(a1, 0,0); - a1 = vec2d_swizzle1(a1, 1,1); - a3 = pload<Packet2d>(a+2); - a2 = vec2d_swizzle1(a3, 0,0); - a3 = vec2d_swizzle1(a3, 1,1); -#endif -} -#endif - -EIGEN_STRONG_INLINE void punpackp(Packet4f* vecs) -{ - vecs[1] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x55)); - vecs[2] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xAA)); - vecs[3] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xFF)); - vecs[0] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x00)); -} - -#ifdef EIGEN_VECTORIZE_SSE3 -template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) -{ - return _mm_hadd_ps(_mm_hadd_ps(vecs[0], vecs[1]),_mm_hadd_ps(vecs[2], vecs[3])); -} - -template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs) -{ - return _mm_hadd_pd(vecs[0], vecs[1]); -} - -#else -template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) -{ - Packet4f tmp0, tmp1, tmp2; - tmp0 = _mm_unpacklo_ps(vecs[0], vecs[1]); - tmp1 = _mm_unpackhi_ps(vecs[0], vecs[1]); - tmp2 = _mm_unpackhi_ps(vecs[2], vecs[3]); - tmp0 = _mm_add_ps(tmp0, tmp1); - tmp1 = _mm_unpacklo_ps(vecs[2], vecs[3]); - tmp1 = _mm_add_ps(tmp1, tmp2); - tmp2 = _mm_movehl_ps(tmp1, tmp0); - tmp0 = _mm_movelh_ps(tmp0, tmp1); - return _mm_add_ps(tmp0, tmp2); -} - -template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs) -{ - return _mm_add_pd(_mm_unpacklo_pd(vecs[0], vecs[1]), _mm_unpackhi_pd(vecs[0], vecs[1])); -} -#endif // SSE3 - -template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) -{ - // Disable SSE3 _mm_hadd_pd that is extremely slow on all existing Intel's architectures - // (from Nehalem to Haswell) -// #ifdef EIGEN_VECTORIZE_SSE3 -// Packet4f tmp = _mm_add_ps(a, vec4f_swizzle1(a,2,3,2,3)); -// return pfirst<Packet4f>(_mm_hadd_ps(tmp, tmp)); -// #else - Packet4f tmp = _mm_add_ps(a, _mm_movehl_ps(a,a)); - return pfirst<Packet4f>(_mm_add_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1))); -// #endif -} - -template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) -{ - // Disable SSE3 _mm_hadd_pd that is extremely slow on all existing Intel's architectures - // (from Nehalem to Haswell) -// #ifdef EIGEN_VECTORIZE_SSE3 -// return pfirst<Packet2d>(_mm_hadd_pd(a, a)); -// #else - return pfirst<Packet2d>(_mm_add_sd(a, _mm_unpackhi_pd(a,a))); -// #endif -} - -#ifdef EIGEN_VECTORIZE_SSSE3 -template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs) -{ - return _mm_hadd_epi32(_mm_hadd_epi32(vecs[0], vecs[1]),_mm_hadd_epi32(vecs[2], vecs[3])); -} -template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a) -{ - Packet4i tmp0 = _mm_hadd_epi32(a,a); - return pfirst<Packet4i>(_mm_hadd_epi32(tmp0,tmp0)); -} -#else -template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a) -{ - Packet4i tmp = _mm_add_epi32(a, _mm_unpackhi_epi64(a,a)); - return pfirst(tmp) + pfirst<Packet4i>(_mm_shuffle_epi32(tmp, 1)); -} - -template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs) -{ - Packet4i tmp0, tmp1, tmp2; - tmp0 = _mm_unpacklo_epi32(vecs[0], vecs[1]); - tmp1 = _mm_unpackhi_epi32(vecs[0], vecs[1]); - tmp2 = _mm_unpackhi_epi32(vecs[2], vecs[3]); - tmp0 = _mm_add_epi32(tmp0, tmp1); - tmp1 = _mm_unpacklo_epi32(vecs[2], vecs[3]); - tmp1 = _mm_add_epi32(tmp1, tmp2); - tmp2 = _mm_unpacklo_epi64(tmp0, tmp1); - tmp0 = _mm_unpackhi_epi64(tmp0, tmp1); - return _mm_add_epi32(tmp0, tmp2); -} -#endif -// Other reduction functions: - -// mul -template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) -{ - Packet4f tmp = _mm_mul_ps(a, _mm_movehl_ps(a,a)); - return pfirst<Packet4f>(_mm_mul_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1))); -} -template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) -{ - return pfirst<Packet2d>(_mm_mul_sd(a, _mm_unpackhi_pd(a,a))); -} -template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a) -{ - // after some experiments, it is seems this is the fastest way to implement it - // for GCC (eg., reusing pmul is very slow !) - // TODO try to call _mm_mul_epu32 directly - EIGEN_ALIGN16 int aux[4]; - pstore(aux, a); - return (aux[0] * aux[1]) * (aux[2] * aux[3]); -} - -// min -template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) -{ - Packet4f tmp = _mm_min_ps(a, _mm_movehl_ps(a,a)); - return pfirst<Packet4f>(_mm_min_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1))); -} -template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) -{ - return pfirst<Packet2d>(_mm_min_sd(a, _mm_unpackhi_pd(a,a))); -} -template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - Packet4i tmp = _mm_min_epi32(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(0,0,3,2))); - return pfirst<Packet4i>(_mm_min_epi32(tmp,_mm_shuffle_epi32(tmp, 1))); -#else - // after some experiments, it is seems this is the fastest way to implement it - // for GCC (eg., it does not like using std::min after the pstore !!) - EIGEN_ALIGN16 int aux[4]; - pstore(aux, a); - int aux0 = aux[0]<aux[1] ? aux[0] : aux[1]; - int aux2 = aux[2]<aux[3] ? aux[2] : aux[3]; - return aux0<aux2 ? aux0 : aux2; -#endif // EIGEN_VECTORIZE_SSE4_1 -} - -// max -template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) -{ - Packet4f tmp = _mm_max_ps(a, _mm_movehl_ps(a,a)); - return pfirst<Packet4f>(_mm_max_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1))); -} -template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) -{ - return pfirst<Packet2d>(_mm_max_sd(a, _mm_unpackhi_pd(a,a))); -} -template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - Packet4i tmp = _mm_max_epi32(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(0,0,3,2))); - return pfirst<Packet4i>(_mm_max_epi32(tmp,_mm_shuffle_epi32(tmp, 1))); -#else - // after some experiments, it is seems this is the fastest way to implement it - // for GCC (eg., it does not like using std::min after the pstore !!) - EIGEN_ALIGN16 int aux[4]; - pstore(aux, a); - int aux0 = aux[0]>aux[1] ? aux[0] : aux[1]; - int aux2 = aux[2]>aux[3] ? aux[2] : aux[3]; - return aux0>aux2 ? aux0 : aux2; -#endif // EIGEN_VECTORIZE_SSE4_1 -} - -// not needed yet -// template<> EIGEN_STRONG_INLINE bool predux_all(const Packet4f& x) -// { -// return _mm_movemask_ps(x) == 0xF; -// } - -template<> EIGEN_STRONG_INLINE bool predux_any(const Packet4f& x) -{ - return _mm_movemask_ps(x) != 0x0; -} - -#if EIGEN_COMP_GNUC -// template <> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) -// { -// Packet4f res = b; -// asm("mulps %[a], %[b] \n\taddps %[c], %[b]" : [b] "+x" (res) : [a] "x" (a), [c] "x" (c)); -// return res; -// } -// EIGEN_STRONG_INLINE Packet4i _mm_alignr_epi8(const Packet4i& a, const Packet4i& b, const int i) -// { -// Packet4i res = a; -// asm("palignr %[i], %[a], %[b] " : [b] "+x" (res) : [a] "x" (a), [i] "i" (i)); -// return res; -// } -#endif - -#ifdef EIGEN_VECTORIZE_SSSE3 -// SSSE3 versions -template<int Offset> -struct palign_impl<Offset,Packet4f> -{ - static EIGEN_STRONG_INLINE void run(Packet4f& first, const Packet4f& second) - { - if (Offset!=0) - first = _mm_castsi128_ps(_mm_alignr_epi8(_mm_castps_si128(second), _mm_castps_si128(first), Offset*4)); - } -}; - -template<int Offset> -struct palign_impl<Offset,Packet4i> -{ - static EIGEN_STRONG_INLINE void run(Packet4i& first, const Packet4i& second) - { - if (Offset!=0) - first = _mm_alignr_epi8(second,first, Offset*4); - } -}; - -template<int Offset> -struct palign_impl<Offset,Packet2d> -{ - static EIGEN_STRONG_INLINE void run(Packet2d& first, const Packet2d& second) - { - if (Offset==1) - first = _mm_castsi128_pd(_mm_alignr_epi8(_mm_castpd_si128(second), _mm_castpd_si128(first), 8)); - } -}; -#else -// SSE2 versions -template<int Offset> -struct palign_impl<Offset,Packet4f> -{ - static EIGEN_STRONG_INLINE void run(Packet4f& first, const Packet4f& second) - { - if (Offset==1) - { - first = _mm_move_ss(first,second); - first = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(first),0x39)); - } - else if (Offset==2) - { - first = _mm_movehl_ps(first,first); - first = _mm_movelh_ps(first,second); - } - else if (Offset==3) - { - first = _mm_move_ss(first,second); - first = _mm_shuffle_ps(first,second,0x93); - } - } -}; - -template<int Offset> -struct palign_impl<Offset,Packet4i> -{ - static EIGEN_STRONG_INLINE void run(Packet4i& first, const Packet4i& second) - { - if (Offset==1) - { - first = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(first),_mm_castsi128_ps(second))); - first = _mm_shuffle_epi32(first,0x39); - } - else if (Offset==2) - { - first = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(first))); - first = _mm_castps_si128(_mm_movelh_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(second))); - } - else if (Offset==3) - { - first = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(first),_mm_castsi128_ps(second))); - first = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(second),0x93)); - } - } -}; - -template<int Offset> -struct palign_impl<Offset,Packet2d> -{ - static EIGEN_STRONG_INLINE void run(Packet2d& first, const Packet2d& second) - { - if (Offset==1) - { - first = _mm_castps_pd(_mm_movehl_ps(_mm_castpd_ps(first),_mm_castpd_ps(first))); - first = _mm_castps_pd(_mm_movelh_ps(_mm_castpd_ps(first),_mm_castpd_ps(second))); - } - } -}; -#endif - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4f,4>& kernel) { - _MM_TRANSPOSE4_PS(kernel.packet[0], kernel.packet[1], kernel.packet[2], kernel.packet[3]); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet2d,2>& kernel) { - __m128d tmp = _mm_unpackhi_pd(kernel.packet[0], kernel.packet[1]); - kernel.packet[0] = _mm_unpacklo_pd(kernel.packet[0], kernel.packet[1]); - kernel.packet[1] = tmp; -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4i,4>& kernel) { - __m128i T0 = _mm_unpacklo_epi32(kernel.packet[0], kernel.packet[1]); - __m128i T1 = _mm_unpacklo_epi32(kernel.packet[2], kernel.packet[3]); - __m128i T2 = _mm_unpackhi_epi32(kernel.packet[0], kernel.packet[1]); - __m128i T3 = _mm_unpackhi_epi32(kernel.packet[2], kernel.packet[3]); - - kernel.packet[0] = _mm_unpacklo_epi64(T0, T1); - kernel.packet[1] = _mm_unpackhi_epi64(T0, T1); - kernel.packet[2] = _mm_unpacklo_epi64(T2, T3); - kernel.packet[3] = _mm_unpackhi_epi64(T2, T3); -} - -template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) { - const __m128i zero = _mm_setzero_si128(); - const __m128i select = _mm_set_epi32(ifPacket.select[3], ifPacket.select[2], ifPacket.select[1], ifPacket.select[0]); - __m128i false_mask = _mm_cmpeq_epi32(select, zero); -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_blendv_epi8(thenPacket, elsePacket, false_mask); -#else - return _mm_or_si128(_mm_andnot_si128(false_mask, thenPacket), _mm_and_si128(false_mask, elsePacket)); -#endif -} -template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) { - const __m128 zero = _mm_setzero_ps(); - const __m128 select = _mm_set_ps(ifPacket.select[3], ifPacket.select[2], ifPacket.select[1], ifPacket.select[0]); - __m128 false_mask = _mm_cmpeq_ps(select, zero); -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_blendv_ps(thenPacket, elsePacket, false_mask); -#else - return _mm_or_ps(_mm_andnot_ps(false_mask, thenPacket), _mm_and_ps(false_mask, elsePacket)); -#endif -} -template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) { - const __m128d zero = _mm_setzero_pd(); - const __m128d select = _mm_set_pd(ifPacket.select[1], ifPacket.select[0]); - __m128d false_mask = _mm_cmpeq_pd(select, zero); -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_blendv_pd(thenPacket, elsePacket, false_mask); -#else - return _mm_or_pd(_mm_andnot_pd(false_mask, thenPacket), _mm_and_pd(false_mask, elsePacket)); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4f pinsertfirst(const Packet4f& a, float b) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_blend_ps(a,pset1<Packet4f>(b),1); -#else - return _mm_move_ss(a, _mm_load_ss(&b)); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet2d pinsertfirst(const Packet2d& a, double b) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_blend_pd(a,pset1<Packet2d>(b),1); -#else - return _mm_move_sd(a, _mm_load_sd(&b)); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4f pinsertlast(const Packet4f& a, float b) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_blend_ps(a,pset1<Packet4f>(b),(1<<3)); -#else - const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x0,0x0,0x0,0xFFFFFFFF)); - return _mm_or_ps(_mm_andnot_ps(mask, a), _mm_and_ps(mask, pset1<Packet4f>(b))); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet2d pinsertlast(const Packet2d& a, double b) -{ -#ifdef EIGEN_VECTORIZE_SSE4_1 - return _mm_blend_pd(a,pset1<Packet2d>(b),(1<<1)); -#else - const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0,0x0,0xFFFFFFFF,0xFFFFFFFF)); - return _mm_or_pd(_mm_andnot_pd(mask, a), _mm_and_pd(mask, pset1<Packet2d>(b))); -#endif -} - -// Scalar path for pmadd with FMA to ensure consistency with vectorized path. -#ifdef EIGEN_VECTORIZE_FMA -template<> EIGEN_STRONG_INLINE float pmadd(const float& a, const float& b, const float& c) { - return ::fmaf(a,b,c); -} -template<> EIGEN_STRONG_INLINE double pmadd(const double& a, const double& b, const double& c) { - return ::fma(a,b,c); -} -#endif - - -// Packet math for Eigen::half -// Disable the following code since it's broken on too many platforms / compilers. -//#elif defined(EIGEN_VECTORIZE_SSE) && (!EIGEN_ARCH_x86_64) && (!EIGEN_COMP_MSVC) -#if 0 - -typedef struct { - __m64 x; -} Packet4h; - - -template<> struct is_arithmetic<Packet4h> { enum { value = true }; }; - -template <> -struct packet_traits<Eigen::half> : default_packet_traits { - typedef Packet4h type; - // There is no half-size packet for Packet4h. - typedef Packet4h half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 0, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasConj = 0, - HasSetLinear = 0, - HasSqrt = 0, - HasRsqrt = 0, - HasExp = 0, - HasLog = 0, - HasBlend = 0 - }; -}; - - -template<> struct unpacket_traits<Packet4h> { typedef Eigen::half type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4h half; }; - -template<> EIGEN_STRONG_INLINE Packet4h pset1<Packet4h>(const Eigen::half& from) { - Packet4h result; - result.x = _mm_set1_pi16(from.x); - return result; -} - -template<> EIGEN_STRONG_INLINE Eigen::half pfirst<Packet4h>(const Packet4h& from) { - return half_impl::raw_uint16_to_half(static_cast<unsigned short>(_mm_cvtsi64_si32(from.x))); -} - -template<> EIGEN_STRONG_INLINE Packet4h pconj(const Packet4h& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet4h padd<Packet4h>(const Packet4h& a, const Packet4h& b) { - __int64_t a64 = _mm_cvtm64_si64(a.x); - __int64_t b64 = _mm_cvtm64_si64(b.x); - - Eigen::half h[4]; - - Eigen::half ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64)); - Eigen::half hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64)); - h[0] = ha + hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 16)); - h[1] = ha + hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 32)); - h[2] = ha + hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 48)); - h[3] = ha + hb; - Packet4h result; - result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet4h psub<Packet4h>(const Packet4h& a, const Packet4h& b) { - __int64_t a64 = _mm_cvtm64_si64(a.x); - __int64_t b64 = _mm_cvtm64_si64(b.x); - - Eigen::half h[4]; - - Eigen::half ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64)); - Eigen::half hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64)); - h[0] = ha - hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 16)); - h[1] = ha - hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 32)); - h[2] = ha - hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 48)); - h[3] = ha - hb; - Packet4h result; - result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet4h pmul<Packet4h>(const Packet4h& a, const Packet4h& b) { - __int64_t a64 = _mm_cvtm64_si64(a.x); - __int64_t b64 = _mm_cvtm64_si64(b.x); - - Eigen::half h[4]; - - Eigen::half ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64)); - Eigen::half hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64)); - h[0] = ha * hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 16)); - h[1] = ha * hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 32)); - h[2] = ha * hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 48)); - h[3] = ha * hb; - Packet4h result; - result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet4h pdiv<Packet4h>(const Packet4h& a, const Packet4h& b) { - __int64_t a64 = _mm_cvtm64_si64(a.x); - __int64_t b64 = _mm_cvtm64_si64(b.x); - - Eigen::half h[4]; - - Eigen::half ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64)); - Eigen::half hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64)); - h[0] = ha / hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 16)); - h[1] = ha / hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 32)); - h[2] = ha / hb; - ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48)); - hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 48)); - h[3] = ha / hb; - Packet4h result; - result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet4h pload<Packet4h>(const Eigen::half* from) { - Packet4h result; - result.x = _mm_cvtsi64_m64(*reinterpret_cast<const __int64_t*>(from)); - return result; -} - -template<> EIGEN_STRONG_INLINE Packet4h ploadu<Packet4h>(const Eigen::half* from) { - Packet4h result; - result.x = _mm_cvtsi64_m64(*reinterpret_cast<const __int64_t*>(from)); - return result; -} - -template<> EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const Packet4h& from) { - __int64_t r = _mm_cvtm64_si64(from.x); - *(reinterpret_cast<__int64_t*>(to)) = r; -} - -template<> EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const Packet4h& from) { - __int64_t r = _mm_cvtm64_si64(from.x); - *(reinterpret_cast<__int64_t*>(to)) = r; -} - -template<> EIGEN_STRONG_INLINE Packet4h -ploadquad<Packet4h>(const Eigen::half* from) { - return pset1<Packet4h>(*from); -} - -template<> EIGEN_STRONG_INLINE Packet4h pgather<Eigen::half, Packet4h>(const Eigen::half* from, Index stride) -{ - Packet4h result; - result.x = _mm_set_pi16(from[3*stride].x, from[2*stride].x, from[1*stride].x, from[0*stride].x); - return result; -} - -template<> EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet4h>(Eigen::half* to, const Packet4h& from, Index stride) -{ - __int64_t a = _mm_cvtm64_si64(from.x); - to[stride*0].x = static_cast<unsigned short>(a); - to[stride*1].x = static_cast<unsigned short>(a >> 16); - to[stride*2].x = static_cast<unsigned short>(a >> 32); - to[stride*3].x = static_cast<unsigned short>(a >> 48); -} - -EIGEN_STRONG_INLINE void -ptranspose(PacketBlock<Packet4h,4>& kernel) { - __m64 T0 = _mm_unpacklo_pi16(kernel.packet[0].x, kernel.packet[1].x); - __m64 T1 = _mm_unpacklo_pi16(kernel.packet[2].x, kernel.packet[3].x); - __m64 T2 = _mm_unpackhi_pi16(kernel.packet[0].x, kernel.packet[1].x); - __m64 T3 = _mm_unpackhi_pi16(kernel.packet[2].x, kernel.packet[3].x); - - kernel.packet[0].x = _mm_unpacklo_pi32(T0, T1); - kernel.packet[1].x = _mm_unpackhi_pi32(T0, T1); - kernel.packet[2].x = _mm_unpacklo_pi32(T2, T3); - kernel.packet[3].x = _mm_unpackhi_pi32(T2, T3); -} - -#endif - - -} // end namespace internal - -} // end namespace Eigen - -#if EIGEN_COMP_PGI && EIGEN_COMP_PGI < 1900 -// PGI++ does not define the following intrinsics in C++ mode. -static inline __m128 _mm_castpd_ps (__m128d x) { return reinterpret_cast<__m128&>(x); } -static inline __m128i _mm_castpd_si128(__m128d x) { return reinterpret_cast<__m128i&>(x); } -static inline __m128d _mm_castps_pd (__m128 x) { return reinterpret_cast<__m128d&>(x); } -static inline __m128i _mm_castps_si128(__m128 x) { return reinterpret_cast<__m128i&>(x); } -static inline __m128 _mm_castsi128_ps(__m128i x) { return reinterpret_cast<__m128&>(x); } -static inline __m128d _mm_castsi128_pd(__m128i x) { return reinterpret_cast<__m128d&>(x); } -#endif - -#endif // EIGEN_PACKET_MATH_SSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/TypeCasting.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/TypeCasting.h deleted file mode 100644 index 1b8e9a55..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SSE/TypeCasting.h +++ /dev/null @@ -1,135 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TYPE_CASTING_SSE_H -#define EIGEN_TYPE_CASTING_SSE_H - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_VECTORIZE_AVX -template <> -struct type_casting_traits<float, int> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template <> -struct type_casting_traits<int, float> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template <> -struct type_casting_traits<double, float> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 2, - TgtCoeffRatio = 1 - }; -}; - -template <> -struct type_casting_traits<float, double> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 2 - }; -}; -#endif - -template<> EIGEN_STRONG_INLINE Packet4i pcast<Packet4f, Packet4i>(const Packet4f& a) { - return _mm_cvttps_epi32(a); -} - -template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4i, Packet4f>(const Packet4i& a) { - return _mm_cvtepi32_ps(a); -} - -template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet2d, Packet4f>(const Packet2d& a, const Packet2d& b) { - return _mm_shuffle_ps(_mm_cvtpd_ps(a), _mm_cvtpd_ps(b), (1 << 2) | (1 << 6)); -} - -template<> EIGEN_STRONG_INLINE Packet2d pcast<Packet4f, Packet2d>(const Packet4f& a) { - // Simply discard the second half of the input - return _mm_cvtps_pd(a); -} - -template<> EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i,Packet4f>(const Packet4f& a) { - return _mm_castps_si128(a); -} - -template<> EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f,Packet4i>(const Packet4i& a) { - return _mm_castsi128_ps(a); -} - - -// Disable the following code since it's broken on too many platforms / compilers. -//#elif defined(EIGEN_VECTORIZE_SSE) && (!EIGEN_ARCH_x86_64) && (!EIGEN_COMP_MSVC) -#if 0 - -template <> -struct type_casting_traits<Eigen::half, float> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4h, Packet4f>(const Packet4h& a) { - __int64_t a64 = _mm_cvtm64_si64(a.x); - Eigen::half h = raw_uint16_to_half(static_cast<unsigned short>(a64)); - float f1 = static_cast<float>(h); - h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16)); - float f2 = static_cast<float>(h); - h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32)); - float f3 = static_cast<float>(h); - h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48)); - float f4 = static_cast<float>(h); - return _mm_set_ps(f4, f3, f2, f1); -} - -template <> -struct type_casting_traits<float, Eigen::half> { - enum { - VectorizedCast = 1, - SrcCoeffRatio = 1, - TgtCoeffRatio = 1 - }; -}; - -template<> EIGEN_STRONG_INLINE Packet4h pcast<Packet4f, Packet4h>(const Packet4f& a) { - EIGEN_ALIGN16 float aux[4]; - pstore(aux, a); - Eigen::half h0(aux[0]); - Eigen::half h1(aux[1]); - Eigen::half h2(aux[2]); - Eigen::half h3(aux[3]); - - Packet4h result; - result.x = _mm_set_pi16(h3.x, h2.x, h1.x, h0.x); - return result; -} - -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TYPE_CASTING_SSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/InteropHeaders.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/InteropHeaders.h deleted file mode 100644 index 710059d5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/InteropHeaders.h +++ /dev/null @@ -1,229 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/***************************************************************** - * InteropHeaders.h - * - * \brief: - * InteropHeaders - * - *****************************************************************/ - -#ifndef EIGEN_INTEROP_HEADERS_SYCL_H -#define EIGEN_INTEROP_HEADERS_SYCL_H - -namespace Eigen { - -#if !defined(EIGEN_DONT_VECTORIZE_SYCL) - -namespace internal { - -template <int has_blend, int lengths> -struct sycl_packet_traits : default_packet_traits { - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = lengths, - HasHalfPacket = 0, - HasDiv = 1, - HasLog = 1, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasSin = 1, - HasCos = 1, - HasTan = 1, - HasASin = 1, - HasACos = 1, - HasATan = 1, - HasSinh = 1, - HasCosh = 1, - HasTanh = 1, - HasLGamma = 0, - HasDiGamma = 0, - HasZeta = 0, - HasPolygamma = 0, - HasErf = 0, - HasErfc = 0, - HasNdtri = 0, - HasIGamma = 0, - HasIGammac = 0, - HasBetaInc = 0, - HasBlend = has_blend, - HasMax = 1, - HasMin = 1, - HasMul = 1, - HasAdd = 1, - HasFloor = 1, - HasRound = 1, - HasRint = 1, - HasLog1p = 1, - HasExpm1 = 1, - HasCeil = 1, - }; -}; - -#ifdef SYCL_DEVICE_ONLY -#define SYCL_PACKET_TRAITS(packet_type, has_blend, unpacket_type, lengths) \ - template <> \ - struct packet_traits<unpacket_type> \ - : sycl_packet_traits<has_blend, lengths> { \ - typedef packet_type type; \ - typedef packet_type half; \ - }; - -SYCL_PACKET_TRAITS(cl::sycl::cl_float4, 1, float, 4) -SYCL_PACKET_TRAITS(cl::sycl::cl_float4, 1, const float, 4) -SYCL_PACKET_TRAITS(cl::sycl::cl_double2, 0, double, 2) -SYCL_PACKET_TRAITS(cl::sycl::cl_double2, 0, const double, 2) -#undef SYCL_PACKET_TRAITS - -// Make sure this is only available when targeting a GPU: we don't want to -// introduce conflicts between these packet_traits definitions and the ones -// we'll use on the host side (SSE, AVX, ...) -#define SYCL_ARITHMETIC(packet_type) \ - template <> \ - struct is_arithmetic<packet_type> { \ - enum { value = true }; \ - }; -SYCL_ARITHMETIC(cl::sycl::cl_float4) -SYCL_ARITHMETIC(cl::sycl::cl_double2) -#undef SYCL_ARITHMETIC - -#define SYCL_UNPACKET_TRAITS(packet_type, unpacket_type, lengths) \ - template <> \ - struct unpacket_traits<packet_type> { \ - typedef unpacket_type type; \ - enum { size = lengths, vectorizable = true, alignment = Aligned16 }; \ - typedef packet_type half; \ - }; -SYCL_UNPACKET_TRAITS(cl::sycl::cl_float4, float, 4) -SYCL_UNPACKET_TRAITS(cl::sycl::cl_double2, double, 2) - -#undef SYCL_UNPACKET_TRAITS -#endif - -} // end namespace internal - -#endif - -namespace TensorSycl { -namespace internal { - -template <typename PacketReturnType, int PacketSize> -struct PacketWrapper; -// This function should never get called on the device -#ifndef SYCL_DEVICE_ONLY -template <typename PacketReturnType, int PacketSize> -struct PacketWrapper { - typedef typename ::Eigen::internal::unpacket_traits<PacketReturnType>::type - Scalar; - template <typename Index> - EIGEN_DEVICE_FUNC static Scalar scalarize(Index, PacketReturnType &) { - eigen_assert(false && "THERE IS NO PACKETIZE VERSION FOR THE CHOSEN TYPE"); - abort(); - } - EIGEN_DEVICE_FUNC static PacketReturnType convert_to_packet_type(Scalar in, - Scalar) { - return ::Eigen::internal::template plset<PacketReturnType>(in); - } - EIGEN_DEVICE_FUNC static void set_packet(PacketReturnType, Scalar *) { - eigen_assert(false && "THERE IS NO PACKETIZE VERSION FOR THE CHOSEN TYPE"); - abort(); - } -}; - -#elif defined(SYCL_DEVICE_ONLY) -template <typename PacketReturnType> -struct PacketWrapper<PacketReturnType, 4> { - typedef typename ::Eigen::internal::unpacket_traits<PacketReturnType>::type - Scalar; - template <typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index index, PacketReturnType &in) { - switch (index) { - case 0: - return in.x(); - case 1: - return in.y(); - case 2: - return in.z(); - case 3: - return in.w(); - default: - //INDEX MUST BE BETWEEN 0 and 3.There is no abort function in SYCL kernel. so we cannot use abort here. - // The code will never reach here - __builtin_unreachable(); - } - __builtin_unreachable(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static PacketReturnType convert_to_packet_type( - Scalar in, Scalar other) { - return PacketReturnType(in, other, other, other); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) { - lhs = PacketReturnType(rhs[0], rhs[1], rhs[2], rhs[3]); - } -}; - -template <typename PacketReturnType> -struct PacketWrapper<PacketReturnType, 1> { - typedef typename ::Eigen::internal::unpacket_traits<PacketReturnType>::type - Scalar; - template <typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index, PacketReturnType &in) { - return in; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static PacketReturnType convert_to_packet_type(Scalar in, - Scalar) { - return PacketReturnType(in); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) { - lhs = rhs[0]; - } -}; - -template <typename PacketReturnType> -struct PacketWrapper<PacketReturnType, 2> { - typedef typename ::Eigen::internal::unpacket_traits<PacketReturnType>::type - Scalar; - template <typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index index, PacketReturnType &in) { - switch (index) { - case 0: - return in.x(); - case 1: - return in.y(); - default: - //INDEX MUST BE BETWEEN 0 and 1.There is no abort function in SYCL kernel. so we cannot use abort here. - // The code will never reach here - __builtin_unreachable(); - } - __builtin_unreachable(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static PacketReturnType convert_to_packet_type( - Scalar in, Scalar other) { - return PacketReturnType(in, other); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) { - lhs = PacketReturnType(rhs[0], rhs[1]); - } -}; - -#endif - -} // end namespace internal -} // end namespace TensorSycl -} // end namespace Eigen - -#endif // EIGEN_INTEROP_HEADERS_SYCL_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/MathFunctions.h deleted file mode 100644 index a96625e2..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/MathFunctions.h +++ /dev/null @@ -1,289 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/***************************************************************** - * MathFunctions.h - * - * \brief: - * MathFunctions - * - *****************************************************************/ - -#ifndef EIGEN_MATH_FUNCTIONS_SYCL_H -#define EIGEN_MATH_FUNCTIONS_SYCL_H - -namespace Eigen { - -namespace internal { - -// Make sure this is only available when targeting a GPU: we don't want to -// introduce conflicts between these packet_traits definitions and the ones -// we'll use on the host side (SSE, AVX, ...) -#if defined(SYCL_DEVICE_ONLY) -#define SYCL_PLOG(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type plog<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::log(a); \ - } - -SYCL_PLOG(cl::sycl::cl_float4) -SYCL_PLOG(cl::sycl::cl_double2) -#undef SYCL_PLOG - -#define SYCL_PLOG1P(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type plog1p<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::log1p(a); \ - } - -SYCL_PLOG1P(cl::sycl::cl_float4) -SYCL_PLOG1P(cl::sycl::cl_double2) -#undef SYCL_PLOG1P - -#define SYCL_PLOG10(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type plog10<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::log10(a); \ - } - -SYCL_PLOG10(cl::sycl::cl_float4) -SYCL_PLOG10(cl::sycl::cl_double2) -#undef SYCL_PLOG10 - -#define SYCL_PEXP(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pexp<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::exp(a); \ - } - -SYCL_PEXP(cl::sycl::cl_float4) -SYCL_PEXP(cl::sycl::cl_double2) -#undef SYCL_PEXP - -#define SYCL_PEXPM1(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pexpm1<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::expm1(a); \ - } - -SYCL_PEXPM1(cl::sycl::cl_float4) -SYCL_PEXPM1(cl::sycl::cl_double2) -#undef SYCL_PEXPM1 - -#define SYCL_PSQRT(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type psqrt<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::sqrt(a); \ - } - -SYCL_PSQRT(cl::sycl::cl_float4) -SYCL_PSQRT(cl::sycl::cl_double2) -#undef SYCL_PSQRT - -#define SYCL_PRSQRT(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type prsqrt<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::rsqrt(a); \ - } - -SYCL_PRSQRT(cl::sycl::cl_float4) -SYCL_PRSQRT(cl::sycl::cl_double2) -#undef SYCL_PRSQRT - -/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */ -#define SYCL_PSIN(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type psin<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::sin(a); \ - } - -SYCL_PSIN(cl::sycl::cl_float4) -SYCL_PSIN(cl::sycl::cl_double2) -#undef SYCL_PSIN - -/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */ -#define SYCL_PCOS(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pcos<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::cos(a); \ - } - -SYCL_PCOS(cl::sycl::cl_float4) -SYCL_PCOS(cl::sycl::cl_double2) -#undef SYCL_PCOS - -/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */ -#define SYCL_PTAN(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type ptan<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::tan(a); \ - } - -SYCL_PTAN(cl::sycl::cl_float4) -SYCL_PTAN(cl::sycl::cl_double2) -#undef SYCL_PTAN - -/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */ -#define SYCL_PASIN(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pasin<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::asin(a); \ - } - -SYCL_PASIN(cl::sycl::cl_float4) -SYCL_PASIN(cl::sycl::cl_double2) -#undef SYCL_PASIN - -/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */ -#define SYCL_PACOS(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pacos<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::acos(a); \ - } - -SYCL_PACOS(cl::sycl::cl_float4) -SYCL_PACOS(cl::sycl::cl_double2) -#undef SYCL_PACOS - -/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */ -#define SYCL_PATAN(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type patan<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::atan(a); \ - } - -SYCL_PATAN(cl::sycl::cl_float4) -SYCL_PATAN(cl::sycl::cl_double2) -#undef SYCL_PATAN - -/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */ -#define SYCL_PSINH(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type psinh<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::sinh(a); \ - } - -SYCL_PSINH(cl::sycl::cl_float4) -SYCL_PSINH(cl::sycl::cl_double2) -#undef SYCL_PSINH - -/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */ -#define SYCL_PCOSH(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pcosh<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::cosh(a); \ - } - -SYCL_PCOSH(cl::sycl::cl_float4) -SYCL_PCOSH(cl::sycl::cl_double2) -#undef SYCL_PCOSH - -/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */ -#define SYCL_PTANH(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type ptanh<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::tanh(a); \ - } - -SYCL_PTANH(cl::sycl::cl_float4) -SYCL_PTANH(cl::sycl::cl_double2) -#undef SYCL_PTANH - -#define SYCL_PCEIL(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pceil<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::ceil(a); \ - } - -SYCL_PCEIL(cl::sycl::cl_float4) -SYCL_PCEIL(cl::sycl::cl_double2) -#undef SYCL_PCEIL - -#define SYCL_PROUND(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pround<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::round(a); \ - } - -SYCL_PROUND(cl::sycl::cl_float4) -SYCL_PROUND(cl::sycl::cl_double2) -#undef SYCL_PROUND - -#define SYCL_PRINT(packet_type) \ - template<> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type print<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::rint(a); \ - } - -SYCL_PRINT(cl::sycl::cl_float4) -SYCL_PRINT(cl::sycl::cl_double2) -#undef SYCL_PRINT - -#define SYCL_FLOOR(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pfloor<packet_type>( \ - const packet_type& a) { \ - return cl::sycl::floor(a); \ - } - -SYCL_FLOOR(cl::sycl::cl_float4) -SYCL_FLOOR(cl::sycl::cl_double2) -#undef SYCL_FLOOR - -#define SYCL_PMIN(packet_type, expr) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pmin<packet_type>( \ - const packet_type& a, const packet_type& b) { \ - return expr; \ - } - -SYCL_PMIN(cl::sycl::cl_float4, cl::sycl::fmin(a, b)) -SYCL_PMIN(cl::sycl::cl_double2, cl::sycl::fmin(a, b)) -#undef SYCL_PMIN - -#define SYCL_PMAX(packet_type, expr) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pmax<packet_type>( \ - const packet_type& a, const packet_type& b) { \ - return expr; \ - } - -SYCL_PMAX(cl::sycl::cl_float4, cl::sycl::fmax(a, b)) -SYCL_PMAX(cl::sycl::cl_double2, cl::sycl::fmax(a, b)) -#undef SYCL_PMAX - -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATH_FUNCTIONS_SYCL_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/PacketMath.h deleted file mode 100644 index b11b5af9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/PacketMath.h +++ /dev/null @@ -1,670 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/***************************************************************** - * PacketMath.h - * - * \brief: - * PacketMath - * - *****************************************************************/ - -#ifndef EIGEN_PACKET_MATH_SYCL_H -#define EIGEN_PACKET_MATH_SYCL_H -#include <type_traits> -namespace Eigen { - -namespace internal { -#ifdef SYCL_DEVICE_ONLY - -#define SYCL_PLOADT_RO(address_space_target) \ - template <typename packet_type, int Alignment> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type ploadt_ro( \ - typename cl::sycl::multi_ptr< \ - const typename unpacket_traits<packet_type>::type, \ - cl::sycl::access::address_space::address_space_target>::pointer_t \ - from) { \ - typedef typename unpacket_traits<packet_type>::type scalar; \ - typedef cl::sycl::multi_ptr< \ - scalar, cl::sycl::access::address_space::address_space_target> \ - multi_ptr; \ - auto res = packet_type( \ - static_cast<typename unpacket_traits<packet_type>::type>(0)); \ - res.load(0, multi_ptr(const_cast<typename multi_ptr::pointer_t>(from))); \ - return res; \ - } - -SYCL_PLOADT_RO(global_space) -SYCL_PLOADT_RO(local_space) -#undef SYCL_PLOADT_RO -#endif - -template <typename packet_type, int Alignment, typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type -ploadt_ro(const Eigen::TensorSycl::internal::RangeAccess< - cl::sycl::access::mode::read_write, T>& from) { - return ploadt_ro<packet_type, Alignment>(from.get_pointer()); -} - -#ifdef SYCL_DEVICE_ONLY -#define SYCL_PLOAD(address_space_target, Alignment, AlignedType) \ - template <typename packet_type> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pload##AlignedType( \ - typename cl::sycl::multi_ptr< \ - const typename unpacket_traits<packet_type>::type, \ - cl::sycl::access::address_space::address_space_target>::pointer_t \ - from) { \ - return ploadt_ro<packet_type, Alignment>(from); \ - } - -// global space -SYCL_PLOAD(global_space, Unaligned, u) -SYCL_PLOAD(global_space, Aligned, ) -// local space -SYCL_PLOAD(local_space, Unaligned, u) -SYCL_PLOAD(local_space, Aligned, ) - -#undef SYCL_PLOAD -#endif - -#define SYCL_PLOAD(Alignment, AlignedType) \ - template <typename packet_type> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pload##AlignedType( \ - const Eigen::TensorSycl::internal::RangeAccess< \ - cl::sycl::access::mode::read_write, \ - typename unpacket_traits<packet_type>::type> \ - from) { \ - return ploadt_ro<packet_type, Alignment>(from); \ - } -SYCL_PLOAD(Unaligned, u) -SYCL_PLOAD(Aligned, ) -#undef SYCL_PLOAD - -#ifdef SYCL_DEVICE_ONLY -/** \internal \returns a packet version of \a *from. - * The pointer \a from must be aligned on a \a Alignment bytes boundary. */ -#define SYCL_PLOADT(address_space_target) \ - template <typename packet_type, int Alignment> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type ploadt( \ - typename cl::sycl::multi_ptr< \ - const typename unpacket_traits<packet_type>::type, \ - cl::sycl::access::address_space::address_space_target>::pointer_t \ - from) { \ - if (Alignment >= unpacket_traits<packet_type>::alignment) \ - return pload<packet_type>(from); \ - else \ - return ploadu<packet_type>(from); \ - } - -// global space -SYCL_PLOADT(global_space) -// local space -SYCL_PLOADT(local_space) -#undef SYCL_PLOADT -#endif - -template <typename packet_type, int Alignment> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type -ploadt(const Eigen::TensorSycl::internal::RangeAccess< - cl::sycl::access::mode::read_write, - typename unpacket_traits<packet_type>::type>& from) { - return ploadt<packet_type, Alignment>(from.get_pointer()); -} -#ifdef SYCL_DEVICE_ONLY - -// private_space -#define SYCL_PLOADT_RO_SPECIAL(packet_type, Alignment) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type \ - ploadt_ro<packet_type, Alignment>( \ - const typename unpacket_traits<packet_type>::type* from) { \ - typedef typename unpacket_traits<packet_type>::type scalar; \ - auto res = packet_type(static_cast<scalar>(0)); \ - res.template load<cl::sycl::access::address_space::private_space>( \ - 0, const_cast<scalar*>(from)); \ - return res; \ - } - -SYCL_PLOADT_RO_SPECIAL(cl::sycl::cl_float4, Aligned) -SYCL_PLOADT_RO_SPECIAL(cl::sycl::cl_double2, Aligned) -SYCL_PLOADT_RO_SPECIAL(cl::sycl::cl_float4, Unaligned) -SYCL_PLOADT_RO_SPECIAL(cl::sycl::cl_double2, Unaligned) - -#define SYCL_PLOAD_SPECIAL(packet_type, alignment_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pload##alignment_type( \ - const typename unpacket_traits<packet_type>::type* from) { \ - typedef typename unpacket_traits<packet_type>::type scalar; \ - auto res = packet_type(static_cast<scalar>(0)); \ - res.template load<cl::sycl::access::address_space::private_space>( \ - 0, const_cast<scalar*>(from)); \ - return res; \ - } -SYCL_PLOAD_SPECIAL(cl::sycl::cl_float4, ) -SYCL_PLOAD_SPECIAL(cl::sycl::cl_double2, ) -SYCL_PLOAD_SPECIAL(cl::sycl::cl_float4, u) -SYCL_PLOAD_SPECIAL(cl::sycl::cl_double2, u) - -#undef SYCL_PLOAD_SPECIAL - -#define SYCL_PSTORE(scalar, packet_type, address_space_target, alignment) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstore##alignment( \ - typename cl::sycl::multi_ptr< \ - scalar, \ - cl::sycl::access::address_space::address_space_target>::pointer_t \ - to, \ - const packet_type& from) { \ - typedef cl::sycl::multi_ptr< \ - scalar, cl::sycl::access::address_space::address_space_target> \ - multi_ptr; \ - from.store(0, multi_ptr(to)); \ - } - -// global space -SYCL_PSTORE(float, cl::sycl::cl_float4, global_space, ) -SYCL_PSTORE(float, cl::sycl::cl_float4, global_space, u) -SYCL_PSTORE(double, cl::sycl::cl_double2, global_space, ) -SYCL_PSTORE(double, cl::sycl::cl_double2, global_space, u) -SYCL_PSTORE(float, cl::sycl::cl_float4, local_space, ) -SYCL_PSTORE(float, cl::sycl::cl_float4, local_space, u) -SYCL_PSTORE(double, cl::sycl::cl_double2, local_space, ) -SYCL_PSTORE(double, cl::sycl::cl_double2, local_space, u) - -SYCL_PSTORE(float, cl::sycl::cl_float4, private_space, ) -SYCL_PSTORE(float, cl::sycl::cl_float4, private_space, u) -SYCL_PSTORE(double, cl::sycl::cl_double2, private_space, ) -SYCL_PSTORE(double, cl::sycl::cl_double2, private_space, u) -#undef SYCL_PSTORE - -#define SYCL_PSTORE_T(address_space_target) \ - template <typename scalar, typename packet_type, int Alignment> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret( \ - typename cl::sycl::multi_ptr< \ - scalar, \ - cl::sycl::access::address_space::address_space_target>::pointer_t \ - to, \ - const packet_type& from) { \ - if (Alignment) \ - pstore(to, from); \ - else \ - pstoreu(to, from); \ - } - -SYCL_PSTORE_T(global_space) - -SYCL_PSTORE_T(local_space) - -#undef SYCL_PSTORE_T - -#define SYCL_PSET1(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pset1<packet_type>( \ - const typename unpacket_traits<packet_type>::type& from) { \ - return packet_type(from); \ - } - -// global space -SYCL_PSET1(cl::sycl::cl_float4) -SYCL_PSET1(cl::sycl::cl_double2) - -#undef SYCL_PSET1 - -template <typename packet_type> -struct get_base_packet { - template <typename sycl_multi_pointer> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type - get_ploaddup(sycl_multi_pointer) {} - - template <typename sycl_multi_pointer> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type - get_pgather(sycl_multi_pointer, Index) {} -}; - -template <> -struct get_base_packet<cl::sycl::cl_float4> { - template <typename sycl_multi_pointer> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_float4 get_ploaddup( - sycl_multi_pointer from) { - return cl::sycl::cl_float4(from[0], from[0], from[1], from[1]); - } - template <typename sycl_multi_pointer> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_float4 get_pgather( - sycl_multi_pointer from, Index stride) { - return cl::sycl::cl_float4(from[0 * stride], from[1 * stride], - from[2 * stride], from[3 * stride]); - } - - template <typename sycl_multi_pointer> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set_pscatter( - sycl_multi_pointer to, const cl::sycl::cl_float4& from, Index stride) { - auto tmp = stride; - to[0] = from.x(); - to[tmp] = from.y(); - to[tmp += stride] = from.z(); - to[tmp += stride] = from.w(); - } - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_float4 set_plset( - const float& a) { - return cl::sycl::cl_float4(static_cast<float>(a), static_cast<float>(a + 1), - static_cast<float>(a + 2), - static_cast<float>(a + 3)); - } -}; - -template <> -struct get_base_packet<cl::sycl::cl_double2> { - template <typename sycl_multi_pointer> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_double2 - get_ploaddup(const sycl_multi_pointer from) { - return cl::sycl::cl_double2(from[0], from[0]); - } - - template <typename sycl_multi_pointer, typename Index> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_double2 get_pgather( - const sycl_multi_pointer from, Index stride) { - return cl::sycl::cl_double2(from[0 * stride], from[1 * stride]); - } - - template <typename sycl_multi_pointer> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set_pscatter( - sycl_multi_pointer to, const cl::sycl::cl_double2& from, Index stride) { - to[0] = from.x(); - to[stride] = from.y(); - } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_double2 set_plset( - const double& a) { - return cl::sycl::cl_double2(static_cast<double>(a), - static_cast<double>(a + 1)); - } -}; - -#define SYCL_PLOAD_DUP(address_space_target) \ - template <typename packet_type> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type ploaddup( \ - typename cl::sycl::multi_ptr< \ - const typename unpacket_traits<packet_type>::type, \ - cl::sycl::access::address_space::address_space_target>::pointer_t \ - from) { \ - return get_base_packet<packet_type>::get_ploaddup(from); \ - } - -// global space -SYCL_PLOAD_DUP(global_space) -// local_space -SYCL_PLOAD_DUP(local_space) -#undef SYCL_PLOAD_DUP - -#define SYCL_PLOAD_DUP_SPECILIZE(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type ploaddup<packet_type>( \ - const typename unpacket_traits<packet_type>::type* from) { \ - return get_base_packet<packet_type>::get_ploaddup(from); \ - } - -SYCL_PLOAD_DUP_SPECILIZE(cl::sycl::cl_float4) -SYCL_PLOAD_DUP_SPECILIZE(cl::sycl::cl_double2) - -#undef SYCL_PLOAD_DUP_SPECILIZE - -#define SYCL_PLSET(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type plset<packet_type>( \ - const typename unpacket_traits<packet_type>::type& a) { \ - return get_base_packet<packet_type>::set_plset(a); \ - } - -SYCL_PLSET(cl::sycl::cl_float4) -SYCL_PLSET(cl::sycl::cl_double2) - -#undef SYCL_PLSET - -#define SYCL_PGATHER(address_space_target) \ - template <typename Scalar, typename packet_type> \ - EIGEN_DEVICE_FUNC inline packet_type pgather( \ - typename cl::sycl::multi_ptr< \ - const typename unpacket_traits<packet_type>::type, \ - cl::sycl::access::address_space::address_space_target>::pointer_t \ - from, \ - Index stride) { \ - return get_base_packet<packet_type>::get_pgather(from, stride); \ - } - -// global space -SYCL_PGATHER(global_space) -// local space -SYCL_PGATHER(local_space) - -#undef SYCL_PGATHER - -#define SYCL_PGATHER_SPECILIZE(scalar, packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type \ - pgather<scalar, packet_type>( \ - const typename unpacket_traits<packet_type>::type* from, Index stride) { \ - return get_base_packet<packet_type>::get_pgather(from, stride); \ - } - -SYCL_PGATHER_SPECILIZE(float, cl::sycl::cl_float4) -SYCL_PGATHER_SPECILIZE(double, cl::sycl::cl_double2) - -#undef SYCL_PGATHER_SPECILIZE - -#define SYCL_PSCATTER(address_space_target) \ - template <typename Scalar, typename packet_type> \ - EIGEN_DEVICE_FUNC inline void pscatter( \ - typename cl::sycl::multi_ptr< \ - typename unpacket_traits<packet_type>::type, \ - cl::sycl::access::address_space::address_space_target>::pointer_t \ - to, \ - const packet_type& from, Index stride) { \ - get_base_packet<packet_type>::set_pscatter(to, from, stride); \ - } - -// global space -SYCL_PSCATTER(global_space) -// local space -SYCL_PSCATTER(local_space) - -#undef SYCL_PSCATTER - -#define SYCL_PSCATTER_SPECILIZE(scalar, packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<scalar, packet_type>( \ - typename unpacket_traits<packet_type>::type * to, \ - const packet_type& from, Index stride) { \ - get_base_packet<packet_type>::set_pscatter(to, from, stride); \ - } - -SYCL_PSCATTER_SPECILIZE(float, cl::sycl::cl_float4) -SYCL_PSCATTER_SPECILIZE(double, cl::sycl::cl_double2) - -#undef SYCL_PSCATTER_SPECILIZE - -#define SYCL_PMAD(packet_type) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pmadd( \ - const packet_type& a, const packet_type& b, const packet_type& c) { \ - return cl::sycl::mad(a, b, c); \ - } - -SYCL_PMAD(cl::sycl::cl_float4) -SYCL_PMAD(cl::sycl::cl_double2) -#undef SYCL_PMAD - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float pfirst<cl::sycl::cl_float4>( - const cl::sycl::cl_float4& a) { - return a.x(); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double pfirst<cl::sycl::cl_double2>( - const cl::sycl::cl_double2& a) { - return a.x(); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float predux<cl::sycl::cl_float4>( - const cl::sycl::cl_float4& a) { - return a.x() + a.y() + a.z() + a.w(); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double predux<cl::sycl::cl_double2>( - const cl::sycl::cl_double2& a) { - return a.x() + a.y(); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float predux_max<cl::sycl::cl_float4>( - const cl::sycl::cl_float4& a) { - return cl::sycl::fmax(cl::sycl::fmax(a.x(), a.y()), - cl::sycl::fmax(a.z(), a.w())); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double predux_max<cl::sycl::cl_double2>( - const cl::sycl::cl_double2& a) { - return cl::sycl::fmax(a.x(), a.y()); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float predux_min<cl::sycl::cl_float4>( - const cl::sycl::cl_float4& a) { - return cl::sycl::fmin(cl::sycl::fmin(a.x(), a.y()), - cl::sycl::fmin(a.z(), a.w())); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double predux_min<cl::sycl::cl_double2>( - const cl::sycl::cl_double2& a) { - return cl::sycl::fmin(a.x(), a.y()); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float predux_mul<cl::sycl::cl_float4>( - const cl::sycl::cl_float4& a) { - return a.x() * a.y() * a.z() * a.w(); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double predux_mul<cl::sycl::cl_double2>( - const cl::sycl::cl_double2& a) { - return a.x() * a.y(); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 -pabs<cl::sycl::cl_float4>(const cl::sycl::cl_float4& a) { - return cl::sycl::cl_float4(cl::sycl::fabs(a.x()), cl::sycl::fabs(a.y()), - cl::sycl::fabs(a.z()), cl::sycl::fabs(a.w())); -} -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_double2 -pabs<cl::sycl::cl_double2>(const cl::sycl::cl_double2& a) { - return cl::sycl::cl_double2(cl::sycl::fabs(a.x()), cl::sycl::fabs(a.y())); -} - -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet sycl_pcmp_le(const Packet &a, - const Packet &b) { - return ((a <= b) - .template convert<typename unpacket_traits<Packet>::type, - cl::sycl::rounding_mode::automatic>()); -} - -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet sycl_pcmp_lt(const Packet &a, - const Packet &b) { - return ((a < b) - .template convert<typename unpacket_traits<Packet>::type, - cl::sycl::rounding_mode::automatic>()); -} - -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet sycl_pcmp_eq(const Packet &a, - const Packet &b) { - return ((a == b) - .template convert<typename unpacket_traits<Packet>::type, - cl::sycl::rounding_mode::automatic>()); -} - -#define SYCL_PCMP(OP, TYPE) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TYPE pcmp_##OP<TYPE>(const TYPE &a, \ - const TYPE &b) { \ - return sycl_pcmp_##OP<TYPE>(a, b); \ - } - -SYCL_PCMP(le, cl::sycl::cl_float4) -SYCL_PCMP(lt, cl::sycl::cl_float4) -SYCL_PCMP(eq, cl::sycl::cl_float4) -SYCL_PCMP(le, cl::sycl::cl_double2) -SYCL_PCMP(lt, cl::sycl::cl_double2) -SYCL_PCMP(eq, cl::sycl::cl_double2) -#undef SYCL_PCMP - -template <typename T> struct convert_to_integer; - -template <> struct convert_to_integer<float> { - using type = int; - using packet_type = cl::sycl::cl_int4; -}; -template <> struct convert_to_integer<double> { - using type = long; - using packet_type = cl::sycl::cl_long2; -}; - -template <typename PacketIn> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename convert_to_integer< - typename unpacket_traits<PacketIn>::type>::packet_type -vector_as_int(const PacketIn &p) { - return ( - p.template convert<typename convert_to_integer< - typename unpacket_traits<PacketIn>::type>::type, - cl::sycl::rounding_mode::automatic>()); -} - -template <typename packetOut, typename PacketIn> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packetOut -convert_vector(const PacketIn &p) { - return (p.template convert<typename unpacket_traits<packetOut>::type, - cl::sycl::rounding_mode::automatic>()); -} - -#define SYCL_PAND(TYPE) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TYPE pand<TYPE>(const TYPE &a, \ - const TYPE &b) { \ - return convert_vector<TYPE>(vector_as_int(a) & vector_as_int(b)); \ - } -SYCL_PAND(cl::sycl::cl_float4) -SYCL_PAND(cl::sycl::cl_double2) -#undef SYCL_PAND - -#define SYCL_POR(TYPE) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TYPE por<TYPE>(const TYPE &a, \ - const TYPE &b) { \ - return convert_vector<TYPE>(vector_as_int(a) | vector_as_int(b)); \ - } - -SYCL_POR(cl::sycl::cl_float4) -SYCL_POR(cl::sycl::cl_double2) -#undef SYCL_POR - -#define SYCL_PXOR(TYPE) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TYPE pxor<TYPE>(const TYPE &a, \ - const TYPE &b) { \ - return convert_vector<TYPE>(vector_as_int(a) ^ vector_as_int(b)); \ - } - -SYCL_PXOR(cl::sycl::cl_float4) -SYCL_PXOR(cl::sycl::cl_double2) -#undef SYCL_PXOR - -#define SYCL_PANDNOT(TYPE) \ - template <> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TYPE pandnot<TYPE>(const TYPE &a, \ - const TYPE &b) { \ - return convert_vector<TYPE>(vector_as_int(a) & (~vector_as_int(b))); \ - } -SYCL_PANDNOT(cl::sycl::cl_float4) -SYCL_PANDNOT(cl::sycl::cl_double2) -#undef SYCL_PANDNOT - -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void ptranspose( - PacketBlock<cl::sycl::cl_float4, 4>& kernel) { - float tmp = kernel.packet[0].y(); - kernel.packet[0].y() = kernel.packet[1].x(); - kernel.packet[1].x() = tmp; - - tmp = kernel.packet[0].z(); - kernel.packet[0].z() = kernel.packet[2].x(); - kernel.packet[2].x() = tmp; - - tmp = kernel.packet[0].w(); - kernel.packet[0].w() = kernel.packet[3].x(); - kernel.packet[3].x() = tmp; - - tmp = kernel.packet[1].z(); - kernel.packet[1].z() = kernel.packet[2].y(); - kernel.packet[2].y() = tmp; - - tmp = kernel.packet[1].w(); - kernel.packet[1].w() = kernel.packet[3].y(); - kernel.packet[3].y() = tmp; - - tmp = kernel.packet[2].w(); - kernel.packet[2].w() = kernel.packet[3].z(); - kernel.packet[3].z() = tmp; -} - -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void ptranspose( - PacketBlock<cl::sycl::cl_double2, 2>& kernel) { - double tmp = kernel.packet[0].y(); - kernel.packet[0].y() = kernel.packet[1].x(); - kernel.packet[1].x() = tmp; -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 pblend( - const Selector<unpacket_traits<cl::sycl::cl_float4>::size>& ifPacket, - const cl::sycl::cl_float4& thenPacket, - const cl::sycl::cl_float4& elsePacket) { - cl::sycl::cl_int4 condition( - ifPacket.select[0] ? 0 : -1, ifPacket.select[1] ? 0 : -1, - ifPacket.select[2] ? 0 : -1, ifPacket.select[3] ? 0 : -1); - return cl::sycl::select(thenPacket, elsePacket, condition); -} - -template <> -inline cl::sycl::cl_double2 pblend( - const Selector<unpacket_traits<cl::sycl::cl_double2>::size>& ifPacket, - const cl::sycl::cl_double2& thenPacket, - const cl::sycl::cl_double2& elsePacket) { - cl::sycl::cl_long2 condition(ifPacket.select[0] ? 0 : -1, - ifPacket.select[1] ? 0 : -1); - return cl::sycl::select(thenPacket, elsePacket, condition); -} -#endif // SYCL_DEVICE_ONLY - -#define SYCL_PSTORE(alignment) \ - template <typename packet_type> \ - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstore##alignment( \ - const Eigen::TensorSycl::internal::RangeAccess< \ - cl::sycl::access::mode::read_write, \ - typename unpacket_traits<packet_type>::type>& to, \ - const packet_type& from) { \ - pstore##alignment(to.get_pointer(), from); \ - } - -// global space -SYCL_PSTORE() -SYCL_PSTORE(u) - -#undef SYCL_PSTORE - -template <typename scalar, typename packet_type, int Alignment> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret( - Eigen::TensorSycl::internal::RangeAccess< - cl::sycl::access::mode::read_write, - typename unpacket_traits<packet_type>::type> - to, - const packet_type& from) { - pstoret<scalar, packet_type, Alignment>(to.get_pointer(), from); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PACKET_MATH_SYCL_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h deleted file mode 100644 index f81e59db..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h +++ /dev/null @@ -1,694 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2017 Codeplay Software Limited - * This Source Code Form is subject to the terms of the Mozilla - * Public License v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * SyclMemoryModel.h - * - * Description: - * Interface for SYCL buffers to behave as a non-dereferenceable pointer - * Interface for Placeholder accessor to behave as a pointer on both host - * and device - * - * Authors: - * - * Ruyman Reyes Codeplay Software Ltd. - * Mehdi Goli Codeplay Software Ltd. - * Vanya Yaneva Codeplay Software Ltd. - * - **************************************************************************/ - -#if defined(EIGEN_USE_SYCL) && \ - !defined(EIGEN_CXX11_TENSOR_TENSOR_SYCL_STORAGE_MEMORY_H) -#define EIGEN_CXX11_TENSOR_TENSOR_SYCL_STORAGE_MEMORY_H - -#include <CL/sycl.hpp> -#ifdef EIGEN_EXCEPTIONS -#include <stdexcept> -#endif -#include <cstddef> -#include <queue> -#include <set> -#include <unordered_map> - -namespace Eigen { -namespace TensorSycl { -namespace internal { - -using sycl_acc_target = cl::sycl::access::target; -using sycl_acc_mode = cl::sycl::access::mode; - -/** - * Default values for template arguments - */ -using buffer_data_type_t = uint8_t; -const sycl_acc_target default_acc_target = sycl_acc_target::global_buffer; -const sycl_acc_mode default_acc_mode = sycl_acc_mode::read_write; - -/** - * PointerMapper - * Associates fake pointers with buffers. - * - */ -class PointerMapper { - public: - using base_ptr_t = std::intptr_t; - - /* Structure of a virtual pointer - * - * |================================================| - * | POINTER ADDRESS | - * |================================================| - */ - struct virtual_pointer_t { - /* Type for the pointers - */ - base_ptr_t m_contents; - - /** Conversions from virtual_pointer_t to - * void * should just reinterpret_cast the integer number - */ - operator void *() const { return reinterpret_cast<void *>(m_contents); } - - /** - * Convert back to the integer number. - */ - operator base_ptr_t() const { return m_contents; } - - /** - * Add a certain value to the pointer to create a - * new pointer to that offset - */ - virtual_pointer_t operator+(size_t off) { return m_contents + off; } - - /* Numerical order for sorting pointers in containers. */ - bool operator<(virtual_pointer_t rhs) const { - return (static_cast<base_ptr_t>(m_contents) < - static_cast<base_ptr_t>(rhs.m_contents)); - } - - bool operator>(virtual_pointer_t rhs) const { - return (static_cast<base_ptr_t>(m_contents) > - static_cast<base_ptr_t>(rhs.m_contents)); - } - - /** - * Numerical order for sorting pointers in containers - */ - bool operator==(virtual_pointer_t rhs) const { - return (static_cast<base_ptr_t>(m_contents) == - static_cast<base_ptr_t>(rhs.m_contents)); - } - - /** - * Simple forward to the equality overload. - */ - bool operator!=(virtual_pointer_t rhs) const { - return !(this->operator==(rhs)); - } - - /** - * Converts a void * into a virtual pointer structure. - * Note that this will only work if the void * was - * already a virtual_pointer_t, but we have no way of - * checking - */ - virtual_pointer_t(const void *ptr) - : m_contents(reinterpret_cast<base_ptr_t>(ptr)){}; - - /** - * Creates a virtual_pointer_t from the given integer - * number - */ - virtual_pointer_t(base_ptr_t u) : m_contents(u){}; - }; - - /* Definition of a null pointer - */ - const virtual_pointer_t null_virtual_ptr = nullptr; - - /** - * Whether if a pointer is null or not. - * A pointer is nullptr if the value is of null_virtual_ptr - */ - static inline bool is_nullptr(virtual_pointer_t ptr) { - return (static_cast<void *>(ptr) == nullptr); - } - - /* basic type for all buffers - */ - using buffer_t = cl::sycl::buffer_mem; - - /** - * Node that stores information about a device allocation. - * Nodes are sorted by size to organise a free list of nodes - * that can be recovered. - */ - struct pMapNode_t { - buffer_t m_buffer; - size_t m_size; - bool m_free; - - pMapNode_t(buffer_t b, size_t size, bool f) - : m_buffer{b}, m_size{size}, m_free{f} { - m_buffer.set_final_data(nullptr); - } - - bool operator<=(const pMapNode_t &rhs) { return (m_size <= rhs.m_size); } - }; - - /** Storage of the pointer / buffer tree - */ - using pointerMap_t = std::map<virtual_pointer_t, pMapNode_t>; - - /** - * Obtain the insertion point in the pointer map for - * a pointer of the given size. - * \param requiredSize Size attemted to reclaim - */ - typename pointerMap_t::iterator get_insertion_point(size_t requiredSize) { - typename pointerMap_t::iterator retVal; - bool reuse = false; - if (!m_freeList.empty()) { - // try to re-use an existing block - for (auto freeElem : m_freeList) { - if (freeElem->second.m_size >= requiredSize) { - retVal = freeElem; - reuse = true; - // Element is not going to be free anymore - m_freeList.erase(freeElem); - break; - } - } - } - if (!reuse) { - retVal = std::prev(m_pointerMap.end()); - } - return retVal; - } - - /** - * Returns an iterator to the node that stores the information - * of the given virtual pointer from the given pointer map structure. - * If pointer is not found, throws std::out_of_range. - * If the pointer map structure is empty, throws std::out_of_range - * - * \param pMap the pointerMap_t structure storing all the pointers - * \param virtual_pointer_ptr The virtual pointer to obtain the node of - * \throws std::out:of_range if the pointer is not found or pMap is empty - */ - typename pointerMap_t::iterator get_node(const virtual_pointer_t ptr) { - if (this->count() == 0) { - m_pointerMap.clear(); - EIGEN_THROW_X(std::out_of_range("There are no pointers allocated\n")); - - } - if (is_nullptr(ptr)) { - m_pointerMap.clear(); - EIGEN_THROW_X(std::out_of_range("Cannot access null pointer\n")); - } - // The previous element to the lower bound is the node that - // holds this memory address - auto node = m_pointerMap.lower_bound(ptr); - // If the value of the pointer is not the one of the node - // then we return the previous one - if (node == std::end(m_pointerMap)) { - --node; - } else if (node->first != ptr) { - if (node == std::begin(m_pointerMap)) { - m_pointerMap.clear(); - EIGEN_THROW_X( - std::out_of_range("The pointer is not registered in the map\n")); - - } - --node; - } - - return node; - } - - /* get_buffer. - * Returns a buffer from the map using the pointer address - */ - template <typename buffer_data_type = buffer_data_type_t> - cl::sycl::buffer<buffer_data_type, 1> get_buffer( - const virtual_pointer_t ptr) { - using sycl_buffer_t = cl::sycl::buffer<buffer_data_type, 1>; - - // get_node() returns a `buffer_mem`, so we need to cast it to a `buffer<>`. - // We can do this without the `buffer_mem` being a pointer, as we - // only declare member variables in the base class (`buffer_mem`) and not in - // the child class (`buffer<>). - auto node = get_node(ptr); - eigen_assert(node->first == ptr || node->first < ptr); - eigen_assert(ptr < static_cast<virtual_pointer_t>(node->second.m_size + - node->first)); - return *(static_cast<sycl_buffer_t *>(&node->second.m_buffer)); - } - - /** - * @brief Returns an accessor to the buffer of the given virtual pointer - * @param accessMode - * @param accessTarget - * @param ptr The virtual pointer - */ - template <sycl_acc_mode access_mode = default_acc_mode, - sycl_acc_target access_target = default_acc_target, - typename buffer_data_type = buffer_data_type_t> - cl::sycl::accessor<buffer_data_type, 1, access_mode, access_target> - get_access(const virtual_pointer_t ptr) { - auto buf = get_buffer<buffer_data_type>(ptr); - return buf.template get_access<access_mode, access_target>(); - } - - /** - * @brief Returns an accessor to the buffer of the given virtual pointer - * in the given command group scope - * @param accessMode - * @param accessTarget - * @param ptr The virtual pointer - * @param cgh Reference to the command group scope - */ - template <sycl_acc_mode access_mode = default_acc_mode, - sycl_acc_target access_target = default_acc_target, - typename buffer_data_type = buffer_data_type_t> - cl::sycl::accessor<buffer_data_type, 1, access_mode, access_target> - get_access(const virtual_pointer_t ptr, cl::sycl::handler &cgh) { - auto buf = get_buffer<buffer_data_type>(ptr); - return buf.template get_access<access_mode, access_target>(cgh); - } - - /* - * Returns the offset from the base address of this pointer. - */ - inline std::ptrdiff_t get_offset(const virtual_pointer_t ptr) { - // The previous element to the lower bound is the node that - // holds this memory address - auto node = get_node(ptr); - auto start = node->first; - eigen_assert(start == ptr || start < ptr); - eigen_assert(ptr < start + node->second.m_size); - return (ptr - start); - } - - /* - * Returns the number of elements by which the given pointer is offset from - * the base address. - */ - template <typename buffer_data_type> - inline size_t get_element_offset(const virtual_pointer_t ptr) { - return get_offset(ptr) / sizeof(buffer_data_type); - } - - /** - * Constructs the PointerMapper structure. - */ - PointerMapper(base_ptr_t baseAddress = 4096) - : m_pointerMap{}, m_freeList{}, m_baseAddress{baseAddress} { - if (m_baseAddress == 0) { - EIGEN_THROW_X(std::invalid_argument("Base address cannot be zero\n")); - } - }; - - /** - * PointerMapper cannot be copied or moved - */ - PointerMapper(const PointerMapper &) = delete; - - /** - * Empty the pointer list - */ - inline void clear() { - m_freeList.clear(); - m_pointerMap.clear(); - } - - /* add_pointer. - * Adds an existing pointer to the map and returns the virtual pointer id. - */ - inline virtual_pointer_t add_pointer(const buffer_t &b) { - return add_pointer_impl(b); - } - - /* add_pointer. - * Adds a pointer to the map and returns the virtual pointer id. - */ - inline virtual_pointer_t add_pointer(buffer_t &&b) { - return add_pointer_impl(b); - } - - /** - * @brief Fuses the given node with the previous nodes in the - * pointer map if they are free - * - * @param node A reference to the free node to be fused - */ - void fuse_forward(typename pointerMap_t::iterator &node) { - while (node != std::prev(m_pointerMap.end())) { - // if following node is free - // remove it and extend the current node with its size - auto fwd_node = std::next(node); - if (!fwd_node->second.m_free) { - break; - } - auto fwd_size = fwd_node->second.m_size; - m_freeList.erase(fwd_node); - m_pointerMap.erase(fwd_node); - - node->second.m_size += fwd_size; - } - } - - /** - * @brief Fuses the given node with the following nodes in the - * pointer map if they are free - * - * @param node A reference to the free node to be fused - */ - void fuse_backward(typename pointerMap_t::iterator &node) { - while (node != m_pointerMap.begin()) { - // if previous node is free, extend it - // with the size of the current one - auto prev_node = std::prev(node); - if (!prev_node->second.m_free) { - break; - } - prev_node->second.m_size += node->second.m_size; - - // remove the current node - m_freeList.erase(node); - m_pointerMap.erase(node); - - // point to the previous node - node = prev_node; - } - } - - /* remove_pointer. - * Removes the given pointer from the map. - * The pointer is allowed to be reused only if ReUse if true. - */ - template <bool ReUse = true> - void remove_pointer(const virtual_pointer_t ptr) { - if (is_nullptr(ptr)) { - return; - } - auto node = this->get_node(ptr); - - node->second.m_free = true; - m_freeList.emplace(node); - - // Fuse the node - // with free nodes before and after it - fuse_forward(node); - fuse_backward(node); - - // If after fusing the node is the last one - // simply remove it (since it is free) - if (node == std::prev(m_pointerMap.end())) { - m_freeList.erase(node); - m_pointerMap.erase(node); - } - } - - /* count. - * Return the number of active pointers (i.e, pointers that - * have been malloc but not freed). - */ - size_t count() const { return (m_pointerMap.size() - m_freeList.size()); } - - private: - /* add_pointer_impl. - * Adds a pointer to the map and returns the virtual pointer id. - * BufferT is either a const buffer_t& or a buffer_t&&. - */ - template <class BufferT> - virtual_pointer_t add_pointer_impl(BufferT b) { - virtual_pointer_t retVal = nullptr; - size_t bufSize = b.get_count(); - pMapNode_t p{b, bufSize, false}; - // If this is the first pointer: - if (m_pointerMap.empty()) { - virtual_pointer_t initialVal{m_baseAddress}; - m_pointerMap.emplace(initialVal, p); - return initialVal; - } - - auto lastElemIter = get_insertion_point(bufSize); - // We are recovering an existing free node - if (lastElemIter->second.m_free) { - lastElemIter->second.m_buffer = b; - lastElemIter->second.m_free = false; - - // If the recovered node is bigger than the inserted one - // add a new free node with the remaining space - if (lastElemIter->second.m_size > bufSize) { - // create a new node with the remaining space - auto remainingSize = lastElemIter->second.m_size - bufSize; - pMapNode_t p2{b, remainingSize, true}; - - // update size of the current node - lastElemIter->second.m_size = bufSize; - - // add the new free node - auto newFreePtr = lastElemIter->first + bufSize; - auto freeNode = m_pointerMap.emplace(newFreePtr, p2).first; - m_freeList.emplace(freeNode); - } - - retVal = lastElemIter->first; - } else { - size_t lastSize = lastElemIter->second.m_size; - retVal = lastElemIter->first + lastSize; - m_pointerMap.emplace(retVal, p); - } - return retVal; - } - - /** - * Compare two iterators to pointer map entries according to - * the size of the allocation on the device. - */ - struct SortBySize { - bool operator()(typename pointerMap_t::iterator a, - typename pointerMap_t::iterator b) const { - return ((a->first < b->first) && (a->second <= b->second)) || - ((a->first < b->first) && (b->second <= a->second)); - } - }; - - /* Maps the pointer addresses to buffer and size pairs. - */ - pointerMap_t m_pointerMap; - - /* List of free nodes available for re-using - */ - std::set<typename pointerMap_t::iterator, SortBySize> m_freeList; - - /* Base address used when issuing the first virtual pointer, allows users - * to specify alignment. Cannot be zero. */ - std::intptr_t m_baseAddress; -}; - -/* remove_pointer. - * Removes the given pointer from the map. - * The pointer is allowed to be reused only if ReUse if true. - */ -template <> -inline void PointerMapper::remove_pointer<false>(const virtual_pointer_t ptr) { - if (is_nullptr(ptr)) { - return; - } - m_pointerMap.erase(this->get_node(ptr)); -} - -/** - * Malloc-like interface to the pointer-mapper. - * Given a size, creates a byte-typed buffer and returns a - * fake pointer to keep track of it. - * \param size Size in bytes of the desired allocation - * \throw cl::sycl::exception if error while creating the buffer - */ -inline void *SYCLmalloc(size_t size, PointerMapper &pMap) { - if (size == 0) { - return nullptr; - } - // Create a generic buffer of the given size - using buffer_t = cl::sycl::buffer<buffer_data_type_t, 1>; - auto thePointer = pMap.add_pointer(buffer_t(cl::sycl::range<1>{size})); - // Store the buffer on the global list - return static_cast<void *>(thePointer); -} - -/** - * Free-like interface to the pointer mapper. - * Given a fake-pointer created with the virtual-pointer malloc, - * destroys the buffer and remove it from the list. - * If ReUse is false, the pointer is not added to the freeList, - * it should be false only for sub-buffers. - */ -template <bool ReUse = true, typename PointerMapper> -inline void SYCLfree(void *ptr, PointerMapper &pMap) { - pMap.template remove_pointer<ReUse>(ptr); -} - -/** - * Clear all the memory allocated by SYCL. - */ -template <typename PointerMapper> -inline void SYCLfreeAll(PointerMapper &pMap) { - pMap.clear(); -} - -template <cl::sycl::access::mode AcMd, typename T> -struct RangeAccess { - static const auto global_access = cl::sycl::access::target::global_buffer; - static const auto is_place_holder = cl::sycl::access::placeholder::true_t; - typedef T scalar_t; - typedef scalar_t &ref_t; - typedef typename cl::sycl::global_ptr<scalar_t>::pointer_t ptr_t; - - // the accessor type does not necessarily the same as T - typedef cl::sycl::accessor<scalar_t, 1, AcMd, global_access, is_place_holder> - accessor; - - typedef RangeAccess<AcMd, T> self_t; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RangeAccess(accessor access, - size_t offset, - std::intptr_t virtual_ptr) - : access_(access), offset_(offset), virtual_ptr_(virtual_ptr) {} - - RangeAccess(cl::sycl::buffer<scalar_t, 1> buff = - cl::sycl::buffer<scalar_t, 1>(cl::sycl::range<1>(1))) - : access_{accessor{buff}}, offset_(0), virtual_ptr_(-1) {} - - // This should be only used for null constructor on the host side - RangeAccess(std::nullptr_t) : RangeAccess() {} - // This template parameter must be removed and scalar_t should be replaced - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptr_t get_pointer() const { - return (access_.get_pointer().get() + offset_); - } - template <typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t &operator+=(Index offset) { - offset_ += (offset); - return *this; - } - template <typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t operator+(Index offset) const { - return self_t(access_, offset_ + offset, virtual_ptr_); - } - template <typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t operator-(Index offset) const { - return self_t(access_, offset_ - offset, virtual_ptr_); - } - template <typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t &operator-=(Index offset) { - offset_ -= offset; - return *this; - } - - // THIS IS FOR NULL COMPARISON ONLY - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend bool operator==( - const RangeAccess &lhs, std::nullptr_t) { - return ((lhs.virtual_ptr_ == -1)); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend bool operator!=( - const RangeAccess &lhs, std::nullptr_t i) { - return !(lhs == i); - } - - // THIS IS FOR NULL COMPARISON ONLY - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend bool operator==( - std::nullptr_t, const RangeAccess &rhs) { - return ((rhs.virtual_ptr_ == -1)); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend bool operator!=( - std::nullptr_t i, const RangeAccess &rhs) { - return !(i == rhs); - } - // Prefix operator (Increment and return value) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t &operator++() { - offset_++; - return (*this); - } - - // Postfix operator (Return value and increment) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t operator++(int i) { - EIGEN_UNUSED_VARIABLE(i); - self_t temp_iterator(*this); - offset_++; - return temp_iterator; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t get_size() const { - return (access_.get_count() - offset_); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t get_offset() const { - return offset_; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set_offset(std::ptrdiff_t offset) { - offset_ = offset; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ref_t operator*() const { - return *get_pointer(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ref_t operator*() { - return *get_pointer(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptr_t operator->() = delete; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ref_t operator[](int x) { - return *(get_pointer() + x); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ref_t operator[](int x) const { - return *(get_pointer() + x); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_t *get_virtual_pointer() const { - return reinterpret_cast<scalar_t *>(virtual_ptr_ + - (offset_ * sizeof(scalar_t))); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit operator bool() const { - return (virtual_ptr_ != -1); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator RangeAccess<AcMd, const T>() { - return RangeAccess<AcMd, const T>(access_, offset_, virtual_ptr_); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - operator RangeAccess<AcMd, const T>() const { - return RangeAccess<AcMd, const T>(access_, offset_, virtual_ptr_); - } - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind( - cl::sycl::handler &cgh) const { - cgh.require(access_); - } - - private: - accessor access_; - size_t offset_; - std::intptr_t virtual_ptr_; // the location of the buffer in the map -}; - -template <cl::sycl::access::mode AcMd, typename T> -struct RangeAccess<AcMd, const T> : RangeAccess<AcMd, T> { - typedef RangeAccess<AcMd, T> Base; - using Base::Base; -}; - -} // namespace internal -} // namespace TensorSycl -} // namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_SYCL_STORAGE_MEMORY_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/TypeCasting.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/TypeCasting.h deleted file mode 100644 index 9208ab21..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/SYCL/TypeCasting.h +++ /dev/null @@ -1,85 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/***************************************************************** - * TypeCasting.h - * - * \brief: - * TypeCasting - * - *****************************************************************/ - -#ifndef EIGEN_TYPE_CASTING_SYCL_H -#define EIGEN_TYPE_CASTING_SYCL_H - -namespace Eigen { - -namespace internal { -#ifdef SYCL_DEVICE_ONLY -template <> -struct type_casting_traits<float, int> { - enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; -}; - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_int4 -pcast<cl::sycl::cl_float4, cl::sycl::cl_int4>(const cl::sycl::cl_float4& a) { - return a - .template convert<cl::sycl::cl_int, cl::sycl::rounding_mode::automatic>(); -} - -template <> -struct type_casting_traits<int, float> { - enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 }; -}; - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 -pcast<cl::sycl::cl_int4, cl::sycl::cl_float4>(const cl::sycl::cl_int4& a) { - return a.template convert<cl::sycl::cl_float, - cl::sycl::rounding_mode::automatic>(); -} - -template <> -struct type_casting_traits<double, float> { - enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 }; -}; - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 -pcast<cl::sycl::cl_double2, cl::sycl::cl_float4>( - const cl::sycl::cl_double2& a, const cl::sycl::cl_double2& b) { - auto a1 = a.template convert<cl::sycl::cl_float, - cl::sycl::rounding_mode::automatic>(); - auto b1 = b.template convert<cl::sycl::cl_float, - cl::sycl::rounding_mode::automatic>(); - return cl::sycl::float4(a1.x(), a1.y(), b1.x(), b1.y()); -} - -template <> -struct type_casting_traits<float, double> { - enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 }; -}; - -template <> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_double2 -pcast<cl::sycl::cl_float4, cl::sycl::cl_double2>(const cl::sycl::cl_float4& a) { - // Simply discard the second half of the input - return cl::sycl::cl_double2(a.x(), a.y()); -} - -#endif -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TYPE_CASTING_SYCL_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/Complex.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/Complex.h deleted file mode 100644 index 8939619f..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/Complex.h +++ /dev/null @@ -1,563 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX32_ALTIVEC_H -#define EIGEN_COMPLEX32_ALTIVEC_H - -namespace Eigen { - -namespace internal { - -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) -static Packet4ui p4ui_CONJ_XOR = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 }; //vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_MZERO); -#endif - -static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2d_ZERO_, (Packet4ui) p2l_ZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 }; -static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_ZERO_, 8);//{ 0x8000000000000000, 0x0000000000000000 }; - -struct Packet1cd -{ - EIGEN_STRONG_INLINE Packet1cd() {} - EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {} - Packet2d v; -}; - -struct Packet2cf -{ - EIGEN_STRONG_INLINE Packet2cf() {} - EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {} -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12) - union { - Packet4f v; - Packet1cd cd[2]; - }; -#else - Packet4f v; -#endif -}; - -template<> struct packet_traits<std::complex<float> > : default_packet_traits -{ - typedef Packet2cf type; - typedef Packet2cf half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 2, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasBlend = 1, - HasSetLinear = 0 - }; -}; - - -template<> struct packet_traits<std::complex<double> > : default_packet_traits -{ - typedef Packet1cd type; - typedef Packet1cd half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 1, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasNegate = 1, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasSetLinear = 0 - }; -}; - -template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2cf half; }; -template<> struct unpacket_traits<Packet1cd> { typedef std::complex<double> type; enum {size=1, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet1cd half; }; - -/* Forward declaration */ -EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel); - -/* complex<double> first */ -template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from)); } -template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from)); } -template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, from.v); } - -template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from) -{ /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); } - -template<> EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>(const std::complex<double>* from, Index stride EIGEN_UNUSED) -{ - return pload<Packet1cd>(from); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to, const Packet1cd& from, Index stride EIGEN_UNUSED) -{ - pstore<std::complex<double> >(to, from); -} -template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v + b.v); } -template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v - b.v); } -template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(Packet2d(a.v))); } -template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) { return Packet1cd((Packet2d)vec_xor((Packet2d)a.v, (Packet2d)p2ul_CONJ_XOR2)); } -template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ - Packet2d a_re, a_im, v1, v2; - - // Permute and multiply the real parts of a and b - a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI); - // Get the imaginary parts of a - a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO); - // multiply a_re * b - v1 = vec_madd(a_re, b.v, p2d_ZERO); - // multiply a_im * b and get the conjugate result - v2 = vec_madd(a_im, b.v, p2d_ZERO); - v2 = (Packet2d) vec_sld((Packet4ui)v2, (Packet4ui)v2, 8); - v2 = (Packet2d) vec_xor((Packet2d)v2, (Packet2d) p2ul_CONJ_XOR1); - - return Packet1cd(v1 + v2); -} -template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(vec_and(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(vec_or(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(vec_xor(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet1cd pandnot <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(vec_and(a.v, vec_nor(b.v,b.v))); } -template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); } - -template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); } - -template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a) -{ - std::complex<double> EIGEN_ALIGN16 res; - pstore<std::complex<double> >(&res, a); - - return res; -} - -template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; } -template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) -{ - return pfirst(a); -} -template<> EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(const Packet1cd* vecs) -{ - return vecs[0]; -} -template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) -{ - return pfirst(a); -} -template<int Offset> -struct palign_impl<Offset,Packet1cd> -{ - static EIGEN_STRONG_INLINE void run(Packet1cd& /*first*/, const Packet1cd& /*second*/) - { - // FIXME is it sure we never have to align a Packet1cd? - // Even though a std::complex<double> has 16 bytes, it is not necessarily aligned on a 16 bytes boundary... - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, false,true> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, true,false> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet1cd, Packet1cd, true,true> -{ - EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d) - -template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b) -{ - // TODO optimize it for AltiVec - Packet1cd res = conj_helper<Packet1cd,Packet1cd,false,true>().pmul(a,b); - Packet2d s = vec_madd(b.v, b.v, p2d_ZERO_); - return Packet1cd(pdiv(res.v, s + vec_perm(s, s, p16uc_REVERSE64))); -} - -EIGEN_STRONG_INLINE Packet1cd pcplxflip/*<Packet1cd>*/(const Packet1cd& x) -{ - return Packet1cd(preverse(Packet2d(x.v))); -} - -EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd,2>& kernel) -{ - Packet2d tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI); - kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO); - kernel.packet[0].v = tmp; -} - -/* complex<float> follows */ -template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>((const float*)from)); } -template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>((const float*)from)); } -template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((float*)to, from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((float*)to, from.v); } - -template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a) -{ - std::complex<float> EIGEN_ALIGN16 res[2]; - pstore<std::complex<float> >(res, a); - - return res[0]; -} - - -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12) -template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from) -{ - Packet2cf res; - res.cd[0] = Packet1cd(vec_ld2f((const float *)&from)); - res.cd[1] = res.cd[0]; - return res; -} -#else -template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from) -{ - Packet2cf res; - if((std::ptrdiff_t(&from) % 16) == 0) - res.v = pload<Packet4f>((const float *)&from); - else - res.v = ploadu<Packet4f>((const float *)&from); - res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI); - return res; -} -#endif - -template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from, Index stride) -{ - std::complex<float> EIGEN_ALIGN16 af[2]; - af[0] = from[0*stride]; - af[1] = from[1*stride]; - return pload<Packet2cf>(af); -} -template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from, Index stride) -{ - std::complex<float> EIGEN_ALIGN16 af[2]; - pstore<std::complex<float> >((std::complex<float> *) af, from); - to[0*stride] = af[0]; - to[1*stride] = af[1]; -} - -template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(padd<Packet4f>(a.v, b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(psub<Packet4f>(a.v, b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate(Packet4f(a.v))); } - -template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pand<Packet4f>(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(por<Packet4f>(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pxor<Packet4f>(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pandnot<Packet4f>(a.v,b.v)); } - -template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); } - -template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); } - - -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12) -template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) -{ - Packet2cf res; - res.v.v4f[0] = pconj(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[0]))).v; - res.v.v4f[1] = pconj(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[1]))).v; - return res; -} - -template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - Packet2cf res; - res.v.v4f[0] = pmul(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[0])), Packet1cd(reinterpret_cast<Packet2d>(b.v.v4f[0]))).v; - res.v.v4f[1] = pmul(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[1])), Packet1cd(reinterpret_cast<Packet2d>(b.v.v4f[1]))).v; - return res; -} - -template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) -{ - Packet2cf res; - res.cd[0] = a.cd[1]; - res.cd[1] = a.cd[0]; - return res; -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a) -{ - std::complex<float> res; - Packet1cd b = padd<Packet1cd>(a.cd[0], a.cd[1]); - vec_st2f(b.v, (float*)&res); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs) -{ - PacketBlock<Packet2cf,2> transpose; - transpose.packet[0] = vecs[0]; - transpose.packet[1] = vecs[1]; - ptranspose(transpose); - - return padd<Packet2cf>(transpose.packet[0], transpose.packet[1]); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a) -{ - std::complex<float> res; - Packet1cd b = pmul<Packet1cd>(a.cd[0], a.cd[1]); - vec_st2f(b.v, (float*)&res); - return res; -} - -template<int Offset> -struct palign_impl<Offset,Packet2cf> -{ - static EIGEN_STRONG_INLINE void run(Packet2cf& first, const Packet2cf& second) - { - if (Offset == 1) { - first.cd[0] = first.cd[1]; - first.cd[1] = second.cd[0]; - } - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, false,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, true,false> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, true,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f) - -template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - // TODO optimize it for AltiVec - Packet2cf res; - res.cd[0] = pdiv<Packet1cd>(a.cd[0], b.cd[0]); - res.cd[1] = pdiv<Packet1cd>(a.cd[1], b.cd[1]); - return res; -} - -EIGEN_STRONG_INLINE Packet2cf pcplxflip/*<Packet2cf>*/(const Packet2cf& x) -{ - Packet2cf res; - res.cd[0] = pcplxflip(x.cd[0]); - res.cd[1] = pcplxflip(x.cd[1]); - return res; -} - -EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel) -{ - Packet1cd tmp = kernel.packet[0].cd[1]; - kernel.packet[0].cd[1] = kernel.packet[1].cd[0]; - kernel.packet[1].cd[0] = tmp; -} - -template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) { - Packet2cf result; - const Selector<4> ifPacket4 = { ifPacket.select[0], ifPacket.select[0], ifPacket.select[1], ifPacket.select[1] }; - result.v = pblend<Packet4f>(ifPacket4, thenPacket.v, elsePacket.v); - return result; -} -#else -template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) { return Packet2cf(pxor<Packet4f>(a.v, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR))); } -template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - Packet4f a_re, a_im, prod, prod_im; - - // Permute and multiply the real parts of a and b - a_re = vec_perm(a.v, a.v, p16uc_PSET32_WODD); - - // Get the imaginary parts of a - a_im = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN); - - // multiply a_im * b and get the conjugate result - prod_im = a_im * b.v; - prod_im = pxor<Packet4f>(prod_im, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR)); - // permute back to a proper order - prod_im = vec_perm(prod_im, prod_im, p16uc_COMPLEX32_REV); - - // multiply a_re * b, add prod_im - prod = pmadd<Packet4f>(a_re, b.v, prod_im); - - return Packet2cf(prod); -} - -template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) -{ - Packet4f rev_a; - rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX32_REV2); - return Packet2cf(rev_a); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a) -{ - Packet4f b; - b = vec_sld(a.v, a.v, 8); - b = padd<Packet4f>(a.v, b); - return pfirst<Packet2cf>(Packet2cf(b)); -} - -template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs) -{ - Packet4f b1, b2; - b1 = vec_sld(vecs[0].v, vecs[1].v, 8); - b2 = vec_sld(vecs[1].v, vecs[0].v, 8); - b2 = vec_sld(b2, b2, 8); - b2 = padd<Packet4f>(b1, b2); - - return Packet2cf(b2); -} - -template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a) -{ - Packet4f b; - Packet2cf prod; - b = vec_sld(a.v, a.v, 8); - prod = pmul<Packet2cf>(a, Packet2cf(b)); - - return pfirst<Packet2cf>(prod); -} - -template<int Offset> -struct palign_impl<Offset,Packet2cf> -{ - static EIGEN_STRONG_INLINE void run(Packet2cf& first, const Packet2cf& second) - { - if (Offset==1) - { - first.v = vec_sld(first.v, second.v, 8); - } - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, false,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return internal::pmul(a, pconj(b)); - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, true,false> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return internal::pmul(pconj(a), b); - } -}; - -template<> struct conj_helper<Packet2cf, Packet2cf, true,true> -{ - EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const - { return padd(pmul(x,y),c); } - - EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const - { - return pconj(internal::pmul(a, b)); - } -}; - -EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f) - -template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) -{ - // TODO optimize it for AltiVec - Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a, b); - Packet4f s = pmul<Packet4f>(b.v, b.v); - return Packet2cf(pdiv(res.v, padd<Packet4f>(s, vec_perm(s, s, p16uc_COMPLEX32_REV)))); -} - -template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& x) -{ - return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV)); -} - -EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel) -{ - Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI); - kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO); - kernel.packet[0].v = tmp; -} - -template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) { - Packet2cf result; - result.v = reinterpret_cast<Packet4f>(pblend<Packet2d>(ifPacket, reinterpret_cast<Packet2d>(thenPacket.v), reinterpret_cast<Packet2d>(elsePacket.v))); - return result; -} -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX32_ALTIVEC_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/MathFunctions.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/MathFunctions.h deleted file mode 100644 index 689ecc70..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/MathFunctions.h +++ /dev/null @@ -1,239 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007 Julien Pommier -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* The sin, cos, exp, and log functions of this file come from - * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/ - */ - -#ifndef EIGEN_MATH_FUNCTIONS_ALTIVEC_H -#define EIGEN_MATH_FUNCTIONS_ALTIVEC_H - -namespace Eigen { - -namespace internal { - -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) -static _EIGEN_DECLARE_CONST_Packet4f(1 , 1.0f); -static _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f); -static _EIGEN_DECLARE_CONST_Packet4i(0x7f, 0x7f); -static _EIGEN_DECLARE_CONST_Packet4i(23, 23); - -static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(inv_mant_mask, ~0x7f800000); - -/* the smallest non denormalized float number */ -static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(min_norm_pos, 0x00800000); -static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(minus_inf, 0xff800000); // -1.f/0.f -static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(minus_nan, 0xffffffff); - -/* natural logarithm computed for 4 simultaneous float - return NaN for x <= 0 -*/ -static _EIGEN_DECLARE_CONST_Packet4f(cephes_SQRTHF, 0.707106781186547524f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p0, 7.0376836292E-2f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p1, - 1.1514610310E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p2, 1.1676998740E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p3, - 1.2420140846E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p4, + 1.4249322787E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p5, - 1.6668057665E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p6, + 2.0000714765E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p7, - 2.4999993993E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p8, + 3.3333331174E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_q1, -2.12194440e-4f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_q2, 0.693359375f); - -static _EIGEN_DECLARE_CONST_Packet4f(exp_hi, 88.3762626647950f); -static _EIGEN_DECLARE_CONST_Packet4f(exp_lo, -88.3762626647949f); - -static _EIGEN_DECLARE_CONST_Packet4f(cephes_LOG2EF, 1.44269504088896341f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C1, 0.693359375f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C2, -2.12194440e-4f); - -static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p0, 1.9875691500E-4f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p1, 1.3981999507E-3f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p2, 8.3334519073E-3f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p3, 4.1665795894E-2f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p4, 1.6666665459E-1f); -static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p5, 5.0000001201E-1f); -#endif - -static _EIGEN_DECLARE_CONST_Packet2d(1 , 1.0); -static _EIGEN_DECLARE_CONST_Packet2d(2 , 2.0); -static _EIGEN_DECLARE_CONST_Packet2d(half, 0.5); - -static _EIGEN_DECLARE_CONST_Packet2d(exp_hi, 709.437); -static _EIGEN_DECLARE_CONST_Packet2d(exp_lo, -709.436139303); - -static _EIGEN_DECLARE_CONST_Packet2d(cephes_LOG2EF, 1.4426950408889634073599); - -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p0, 1.26177193074810590878e-4); -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p1, 3.02994407707441961300e-2); -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p2, 9.99999999999999999910e-1); - -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q0, 3.00198505138664455042e-6); -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q1, 2.52448340349684104192e-3); -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q2, 2.27265548208155028766e-1); -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q3, 2.00000000000000000009e0); - -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C1, 0.693145751953125); -static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C2, 1.42860682030941723212e-6); - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d pexp<Packet2d>(const Packet2d& _x) -{ - Packet2d x = _x; - - Packet2d tmp, fx; - Packet2l emm0; - - // clamp x - x = pmax(pmin(x, p2d_exp_hi), p2d_exp_lo); - /* express exp(x) as exp(g + n*log(2)) */ - fx = pmadd(p2d_cephes_LOG2EF, x, p2d_half); - - fx = vec_floor(fx); - - tmp = pmul(fx, p2d_cephes_exp_C1); - Packet2d z = pmul(fx, p2d_cephes_exp_C2); - x = psub(x, tmp); - x = psub(x, z); - - Packet2d x2 = pmul(x,x); - - Packet2d px = p2d_cephes_exp_p0; - px = pmadd(px, x2, p2d_cephes_exp_p1); - px = pmadd(px, x2, p2d_cephes_exp_p2); - px = pmul (px, x); - - Packet2d qx = p2d_cephes_exp_q0; - qx = pmadd(qx, x2, p2d_cephes_exp_q1); - qx = pmadd(qx, x2, p2d_cephes_exp_q2); - qx = pmadd(qx, x2, p2d_cephes_exp_q3); - - x = pdiv(px,psub(qx,px)); - x = pmadd(p2d_2,x,p2d_1); - - // build 2^n - emm0 = vec_ctsl(fx, 0); - - static const Packet2l p2l_1023 = { 1023, 1023 }; - static const Packet2ul p2ul_52 = { 52, 52 }; - - emm0 = emm0 + p2l_1023; - emm0 = emm0 << reinterpret_cast<Packet2l>(p2ul_52); - - // Altivec's max & min operators just drop silent NaNs. Check NaNs in - // inputs and return them unmodified. - Packet2ul isnumber_mask = reinterpret_cast<Packet2ul>(vec_cmpeq(_x, _x)); - return vec_sel(_x, pmax(pmul(x, reinterpret_cast<Packet2d>(emm0)), _x), - isnumber_mask); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f pexp<Packet4f>(const Packet4f& _x) -{ -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) -/* - Packet4f x = _x; - - Packet4f tmp, fx; - Packet4i emm0; - - // clamp x - x = pmax(pmin(x, p4f_exp_hi), p4f_exp_lo); - - // express exp(x) as exp(g + n*log(2)) - fx = pmadd(x, p4f_cephes_LOG2EF, p4f_half); - - fx = pfloor(fx); - - tmp = pmul(fx, p4f_cephes_exp_C1); - Packet4f z = pmul(fx, p4f_cephes_exp_C2); - x = psub(x, tmp); - x = psub(x, z); - - z = pmul(x,x); - - Packet4f y = p4f_cephes_exp_p0; - y = pmadd(y, x, p4f_cephes_exp_p1); - y = pmadd(y, x, p4f_cephes_exp_p2); - y = pmadd(y, x, p4f_cephes_exp_p3); - y = pmadd(y, x, p4f_cephes_exp_p4); - y = pmadd(y, x, p4f_cephes_exp_p5); - y = pmadd(y, z, x); - y = padd(y, p4f_1); - - // build 2^n - emm0 = vec_cts(fx, 0); - emm0 = emm0 + p4i_0x7f; - emm0 = emm0 << reinterpret_cast<Packet4i>(p4i_23); - - // Altivec's max & min operators just drop silent NaNs. Check NaNs in - // inputs and return them unmodified. - Packet4ui isnumber_mask = reinterpret_cast<Packet4ui>(vec_cmpeq(_x, _x)); - return vec_sel(_x, pmax(pmul(y, reinterpret_cast<Packet4f>(emm0)), _x), - isnumber_mask);*/ - return _x; -#else - Packet4f res; - res.v4f[0] = pexp<Packet2d>(_x.v4f[0]); - res.v4f[1] = pexp<Packet2d>(_x.v4f[1]); - return res; -#endif -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d psqrt<Packet2d>(const Packet2d& x) -{ - return vec_sqrt(x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f psqrt<Packet4f>(const Packet4f& x) -{ - Packet4f res; -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) - res = vec_sqrt(x); -#else - res.v4f[0] = psqrt<Packet2d>(x.v4f[0]); - res.v4f[1] = psqrt<Packet2d>(x.v4f[1]); -#endif - return res; -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet2d prsqrt<Packet2d>(const Packet2d& x) { - return pset1<Packet2d>(1.0) / psqrt<Packet2d>(x); -} - -template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet4f prsqrt<Packet4f>(const Packet4f& x) { - Packet4f res; -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) - res = pset1<Packet4f>(1.0) / psqrt<Packet4f>(x); -#else - res.v4f[0] = prsqrt<Packet2d>(x.v4f[0]); - res.v4f[1] = prsqrt<Packet2d>(x.v4f[1]); -#endif - return res; -} - -// Hyperbolic Tangent function. -template <> -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f -ptanh<Packet4f>(const Packet4f& x) { - return internal::generic_fast_tanh_float(x); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MATH_FUNCTIONS_ALTIVEC_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/PacketMath.h b/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/PacketMath.h deleted file mode 100644 index 5036106c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/arch/ZVector/PacketMath.h +++ /dev/null @@ -1,1193 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PACKET_MATH_ZVECTOR_H -#define EIGEN_PACKET_MATH_ZVECTOR_H - -#include <stdint.h> - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD -#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 16 -#endif - -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD -#endif - -#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD -#define EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD -#endif - -#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS -#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32 -#endif - -typedef __vector int Packet4i; -typedef __vector unsigned int Packet4ui; -typedef __vector __bool int Packet4bi; -typedef __vector short int Packet8i; -typedef __vector unsigned char Packet16uc; -typedef __vector double Packet2d; -typedef __vector unsigned long long Packet2ul; -typedef __vector long long Packet2l; - -// Z14 has builtin support for float vectors -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) -typedef __vector float Packet4f; -#else -typedef struct { - Packet2d v4f[2]; -} Packet4f; -#endif - -typedef union { - int32_t i[4]; - uint32_t ui[4]; - int64_t l[2]; - uint64_t ul[2]; - double d[2]; - float f[4]; - Packet4i v4i; - Packet4ui v4ui; - Packet2l v2l; - Packet2ul v2ul; - Packet2d v2d; -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) - Packet4f v4f; -#endif -} Packet; - -// We don't want to write the same code all the time, but we need to reuse the constants -// and it doesn't really work to declare them global, so we define macros instead - -#define _EIGEN_DECLARE_CONST_FAST_Packet4i(NAME,X) \ - Packet4i p4i_##NAME = reinterpret_cast<Packet4i>(vec_splat_s32(X)) - -#define _EIGEN_DECLARE_CONST_FAST_Packet2d(NAME,X) \ - Packet2d p2d_##NAME = reinterpret_cast<Packet2d>(vec_splat_s64(X)) - -#define _EIGEN_DECLARE_CONST_FAST_Packet2l(NAME,X) \ - Packet2l p2l_##NAME = reinterpret_cast<Packet2l>(vec_splat_s64(X)) - -#define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \ - Packet4i p4i_##NAME = pset1<Packet4i>(X) - -#define _EIGEN_DECLARE_CONST_Packet2d(NAME,X) \ - Packet2d p2d_##NAME = pset1<Packet2d>(X) - -#define _EIGEN_DECLARE_CONST_Packet2l(NAME,X) \ - Packet2l p2l_##NAME = pset1<Packet2l>(X) - -// These constants are endian-agnostic -static _EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,} -static _EIGEN_DECLARE_CONST_FAST_Packet4i(ONE, 1); //{ 1, 1, 1, 1} - -static _EIGEN_DECLARE_CONST_FAST_Packet2d(ZERO, 0); -static _EIGEN_DECLARE_CONST_FAST_Packet2l(ZERO, 0); -static _EIGEN_DECLARE_CONST_FAST_Packet2l(ONE, 1); - -static Packet2d p2d_ONE = { 1.0, 1.0 }; -static Packet2d p2d_ZERO_ = { -0.0, -0.0 }; - -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) -#define _EIGEN_DECLARE_CONST_FAST_Packet4f(NAME,X) \ - Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(vec_splat_s32(X)) - -#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \ - Packet4f p4f_##NAME = pset1<Packet4f>(X) - -#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \ - const Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(pset1<Packet4i>(X)) - -static _EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0); //{ 0.0, 0.0, 0.0, 0.0} -static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1,-1); //{ -1, -1, -1, -1} -static Packet4f p4f_MZERO = { 0x80000000, 0x80000000, 0x80000000, 0x80000000}; -#endif - -static Packet4i p4i_COUNTDOWN = { 0, 1, 2, 3 }; -static Packet4f p4f_COUNTDOWN = { 0.0, 1.0, 2.0, 3.0 }; -static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet16uc>(p2d_ZERO), reinterpret_cast<Packet16uc>(p2d_ONE), 8)); - -static Packet16uc p16uc_PSET64_HI = { 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 }; -static Packet16uc p16uc_DUPLICATE32_HI = { 0,1,2,3, 0,1,2,3, 4,5,6,7, 4,5,6,7 }; - -// Mask alignment -#define _EIGEN_MASK_ALIGNMENT 0xfffffffffffffff0 - -#define _EIGEN_ALIGNED_PTR(x) ((std::ptrdiff_t)(x) & _EIGEN_MASK_ALIGNMENT) - -// Handle endianness properly while loading constants -// Define global static constants: - -static Packet16uc p16uc_FORWARD = { 0,1,2,3, 4,5,6,7, 8,9,10,11, 12,13,14,15 }; -static Packet16uc p16uc_REVERSE32 = { 12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3 }; -static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; - -static Packet16uc p16uc_PSET32_WODD = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 }; -static Packet16uc p16uc_PSET32_WEVEN = vec_sld(p16uc_DUPLICATE32_HI, (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 }; -/*static Packet16uc p16uc_HALF64_0_16 = vec_sld((Packet16uc)p4i_ZERO, vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 3), 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16}; - -static Packet16uc p16uc_PSET64_HI = (Packet16uc) vec_mergeh((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };*/ -static Packet16uc p16uc_PSET64_LO = (Packet16uc) vec_mergel((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 8,9,10,11, 12,13,14,15, 8,9,10,11, 12,13,14,15 }; -/*static Packet16uc p16uc_TRANSPOSE64_HI = vec_add(p16uc_PSET64_HI, p16uc_HALF64_0_16); //{ 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23}; -static Packet16uc p16uc_TRANSPOSE64_LO = vec_add(p16uc_PSET64_LO, p16uc_HALF64_0_16); //{ 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31};*/ -static Packet16uc p16uc_TRANSPOSE64_HI = { 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23}; -static Packet16uc p16uc_TRANSPOSE64_LO = { 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31}; - -static Packet16uc p16uc_COMPLEX32_REV = vec_sld(p16uc_REVERSE32, p16uc_REVERSE32, 8); //{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 }; - -static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; - - -#if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC - #define EIGEN_ZVECTOR_PREFETCH(ADDR) __builtin_prefetch(ADDR); -#else - #define EIGEN_ZVECTOR_PREFETCH(ADDR) asm( " pfd [%[addr]]\n" :: [addr] "r" (ADDR) : "cc" ); -#endif - -template<> struct packet_traits<int> : default_packet_traits -{ - typedef Packet4i type; - typedef Packet4i half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasBlend = 1 - }; -}; - -template <> -struct packet_traits<float> : default_packet_traits { - typedef Packet4f type; - typedef Packet4f half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasMin = 1, - HasMax = 1, - HasAbs = 1, - HasSin = 0, - HasCos = 0, - HasLog = 0, -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) - HasExp = 0, -#else - HasExp = 1, -#endif - HasSqrt = 1, - HasRsqrt = 1, - HasTanh = 1, - HasErf = 1, - HasRound = 1, - HasFloor = 1, - HasCeil = 1, - HasNegate = 1, - HasBlend = 1 - }; -}; - -template<> struct packet_traits<double> : default_packet_traits -{ - typedef Packet2d type; - typedef Packet2d half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size=2, - HasHalfPacket = 1, - - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasMin = 1, - HasMax = 1, - HasAbs = 1, - HasSin = 0, - HasCos = 0, - HasLog = 0, - HasExp = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasRound = 1, - HasFloor = 1, - HasCeil = 1, - HasNegate = 1, - HasBlend = 1 - }; -}; - -template<> struct unpacket_traits<Packet4i> { typedef int type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4i half; }; -template<> struct unpacket_traits<Packet4f> { typedef float type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4f half; }; -template<> struct unpacket_traits<Packet2d> { typedef double type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2d half; }; - -/* Forward declaration */ -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f,4>& kernel); - -inline std::ostream & operator <<(std::ostream & s, const Packet4i & v) -{ - Packet vt; - vt.v4i = v; - s << vt.i[0] << ", " << vt.i[1] << ", " << vt.i[2] << ", " << vt.i[3]; - return s; -} - -inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v) -{ - Packet vt; - vt.v4ui = v; - s << vt.ui[0] << ", " << vt.ui[1] << ", " << vt.ui[2] << ", " << vt.ui[3]; - return s; -} - -inline std::ostream & operator <<(std::ostream & s, const Packet2l & v) -{ - Packet vt; - vt.v2l = v; - s << vt.l[0] << ", " << vt.l[1]; - return s; -} - -inline std::ostream & operator <<(std::ostream & s, const Packet2ul & v) -{ - Packet vt; - vt.v2ul = v; - s << vt.ul[0] << ", " << vt.ul[1] ; - return s; -} - -inline std::ostream & operator <<(std::ostream & s, const Packet2d & v) -{ - Packet vt; - vt.v2d = v; - s << vt.d[0] << ", " << vt.d[1]; - return s; -} - -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12) -inline std::ostream & operator <<(std::ostream & s, const Packet4f & v) -{ - Packet vt; - vt.v4f = v; - s << vt.f[0] << ", " << vt.f[1] << ", " << vt.f[2] << ", " << vt.f[3]; - return s; -} -#endif - - -template<int Offset> -struct palign_impl<Offset,Packet4i> -{ - static EIGEN_STRONG_INLINE void run(Packet4i& first, const Packet4i& second) - { - switch (Offset % 4) { - case 1: - first = vec_sld(first, second, 4); break; - case 2: - first = vec_sld(first, second, 8); break; - case 3: - first = vec_sld(first, second, 12); break; - } - } -}; - -template<int Offset> -struct palign_impl<Offset,Packet2d> -{ - static EIGEN_STRONG_INLINE void run(Packet2d& first, const Packet2d& second) - { - if (Offset == 1) - first = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(first), reinterpret_cast<Packet4i>(second), 8)); - } -}; - -template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_LOAD - Packet *vfrom; - vfrom = (Packet *) from; - return vfrom->v4i; -} - -template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_LOAD - Packet *vfrom; - vfrom = (Packet *) from; - return vfrom->v2d; -} - -template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_STORE - Packet *vto; - vto = (Packet *) to; - vto->v4i = from; -} - -template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_STORE - Packet *vto; - vto = (Packet *) to; - vto->v2d = from; -} - -template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) -{ - return vec_splats(from); -} -template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { - return vec_splats(from); -} - -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet4i>(const int *a, - Packet4i& a0, Packet4i& a1, Packet4i& a2, Packet4i& a3) -{ - a3 = pload<Packet4i>(a); - a0 = vec_splat(a3, 0); - a1 = vec_splat(a3, 1); - a2 = vec_splat(a3, 2); - a3 = vec_splat(a3, 3); -} - -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet2d>(const double *a, - Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3) -{ - a1 = pload<Packet2d>(a); - a0 = vec_splat(a1, 0); - a1 = vec_splat(a1, 1); - a3 = pload<Packet2d>(a+2); - a2 = vec_splat(a3, 0); - a3 = vec_splat(a3, 1); -} - -template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride) -{ - int EIGEN_ALIGN16 ai[4]; - ai[0] = from[0*stride]; - ai[1] = from[1*stride]; - ai[2] = from[2*stride]; - ai[3] = from[3*stride]; - return pload<Packet4i>(ai); -} - -template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride) -{ - double EIGEN_ALIGN16 af[2]; - af[0] = from[0*stride]; - af[1] = from[1*stride]; - return pload<Packet2d>(af); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride) -{ - int EIGEN_ALIGN16 ai[4]; - pstore<int>((int *)ai, from); - to[0*stride] = ai[0]; - to[1*stride] = ai[1]; - to[2*stride] = ai[2]; - to[3*stride] = ai[3]; -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride) -{ - double EIGEN_ALIGN16 af[2]; - pstore<double>(af, from); - to[0*stride] = af[0]; - to[1*stride] = af[1]; -} - -template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a + b); } -template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a + b); } - -template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a - b); } -template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a - b); } - -template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a * b); } -template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a * b); } - -template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a / b); } -template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a / b); } - -template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return (-a); } -template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return (-a); } - -template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return padd<Packet4i>(pmul<Packet4i>(a, b), c); } -template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return vec_madd(a, b, c); } - -template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return padd<Packet4i>(pset1<Packet4i>(a), p4i_COUNTDOWN); } -template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return padd<Packet2d>(pset1<Packet2d>(a), p2d_COUNTDOWN); } - -template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_min(a, b); } -template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_min(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_max(a, b); } -template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_max(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, b); } -template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_or(a, b); } -template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_or(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_xor(a, b); } -template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_xor(a, b); } - -template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return pand<Packet4i>(a, vec_nor(b, b)); } -template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, vec_nor(b, b)); } - -template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) { return vec_round(a); } -template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return vec_ceil(a); } -template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return vec_floor(a); } - -template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) { return pload<Packet4i>(from); } -template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) { return pload<Packet2d>(from); } - - -template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from) -{ - Packet4i p = pload<Packet4i>(from); - return vec_perm(p, p, p16uc_DUPLICATE32_HI); -} - -template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) -{ - Packet2d p = pload<Packet2d>(from); - return vec_perm(p, p, p16uc_PSET64_HI); -} - -template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) { pstore<int>(to, from); } -template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) { pstore<double>(to, from); } - -template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { EIGEN_ZVECTOR_PREFETCH(addr); } -template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_ZVECTOR_PREFETCH(addr); } - -template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int EIGEN_ALIGN16 x[4]; pstore(x, a); return x[0]; } -template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { double EIGEN_ALIGN16 x[2]; pstore(x, a); return x[0]; } - -template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) -{ - return reinterpret_cast<Packet4i>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32)); -} - -template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) -{ - return reinterpret_cast<Packet2d>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE64)); -} - -template<> EIGEN_STRONG_INLINE Packet4i pabs<Packet4i>(const Packet4i& a) { return vec_abs(a); } -template<> EIGEN_STRONG_INLINE Packet2d pabs<Packet2d>(const Packet2d& a) { return vec_abs(a); } - -template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a) -{ - Packet4i b, sum; - b = vec_sld(a, a, 8); - sum = padd<Packet4i>(a, b); - b = vec_sld(sum, sum, 4); - sum = padd<Packet4i>(sum, b); - return pfirst(sum); -} - -template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) -{ - Packet2d b, sum; - b = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8)); - sum = padd<Packet2d>(a, b); - return pfirst(sum); -} - -template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs) -{ - Packet4i v[4], sum[4]; - - // It's easier and faster to transpose then add as columns - // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation - // Do the transpose, first set of moves - v[0] = vec_mergeh(vecs[0], vecs[2]); - v[1] = vec_mergel(vecs[0], vecs[2]); - v[2] = vec_mergeh(vecs[1], vecs[3]); - v[3] = vec_mergel(vecs[1], vecs[3]); - // Get the resulting vectors - sum[0] = vec_mergeh(v[0], v[2]); - sum[1] = vec_mergel(v[0], v[2]); - sum[2] = vec_mergeh(v[1], v[3]); - sum[3] = vec_mergel(v[1], v[3]); - - // Now do the summation: - // Lines 0+1 - sum[0] = padd<Packet4i>(sum[0], sum[1]); - // Lines 2+3 - sum[1] = padd<Packet4i>(sum[2], sum[3]); - // Add the results - sum[0] = padd<Packet4i>(sum[0], sum[1]); - - return sum[0]; -} - -template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs) -{ - Packet2d v[2], sum; - v[0] = padd<Packet2d>(vecs[0], reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(vecs[0]), reinterpret_cast<Packet4ui>(vecs[0]), 8))); - v[1] = padd<Packet2d>(vecs[1], reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(vecs[1]), reinterpret_cast<Packet4ui>(vecs[1]), 8))); - - sum = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(v[0]), reinterpret_cast<Packet4ui>(v[1]), 8)); - - return sum; -} - -// Other reduction functions: -// mul -template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a) -{ - EIGEN_ALIGN16 int aux[4]; - pstore(aux, a); - return aux[0] * aux[1] * aux[2] * aux[3]; -} - -template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) -{ - return pfirst(pmul(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8)))); -} - -// min -template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a) -{ - Packet4i b, res; - b = pmin<Packet4i>(a, vec_sld(a, a, 8)); - res = pmin<Packet4i>(b, vec_sld(b, b, 4)); - return pfirst(res); -} - -template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) -{ - return pfirst(pmin<Packet2d>(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8)))); -} - -// max -template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a) -{ - Packet4i b, res; - b = pmax<Packet4i>(a, vec_sld(a, a, 8)); - res = pmax<Packet4i>(b, vec_sld(b, b, 4)); - return pfirst(res); -} - -// max -template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) -{ - return pfirst(pmax<Packet2d>(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8)))); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4i,4>& kernel) { - Packet4i t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]); - Packet4i t1 = vec_mergel(kernel.packet[0], kernel.packet[2]); - Packet4i t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]); - Packet4i t3 = vec_mergel(kernel.packet[1], kernel.packet[3]); - kernel.packet[0] = vec_mergeh(t0, t2); - kernel.packet[1] = vec_mergel(t0, t2); - kernel.packet[2] = vec_mergeh(t1, t3); - kernel.packet[3] = vec_mergel(t1, t3); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet2d,2>& kernel) { - Packet2d t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI); - Packet2d t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO); - kernel.packet[0] = t0; - kernel.packet[1] = t1; -} - -template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) { - Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] }; - Packet4ui mask = vec_cmpeq(select, reinterpret_cast<Packet4ui>(p4i_ONE)); - return vec_sel(elsePacket, thenPacket, mask); -} - - -template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) { - Packet2ul select = { ifPacket.select[0], ifPacket.select[1] }; - Packet2ul mask = vec_cmpeq(select, reinterpret_cast<Packet2ul>(p2l_ONE)); - return vec_sel(elsePacket, thenPacket, mask); -} - -/* z13 has no vector float support so we emulate that with double - z14 has proper vector float support. -*/ -#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12) -/* Helper function to simulate a vec_splat_packet4f - */ -template<int element> EIGEN_STRONG_INLINE Packet4f vec_splat_packet4f(const Packet4f& from) -{ - Packet4f splat; - switch (element) { - case 0: - splat.v4f[0] = vec_splat(from.v4f[0], 0); - splat.v4f[1] = splat.v4f[0]; - break; - case 1: - splat.v4f[0] = vec_splat(from.v4f[0], 1); - splat.v4f[1] = splat.v4f[0]; - break; - case 2: - splat.v4f[0] = vec_splat(from.v4f[1], 0); - splat.v4f[1] = splat.v4f[0]; - break; - case 3: - splat.v4f[0] = vec_splat(from.v4f[1], 1); - splat.v4f[1] = splat.v4f[0]; - break; - } - return splat; -} - -/* This is a tricky one, we have to translate float alignment to vector elements of sizeof double - */ -template<int Offset> -struct palign_impl<Offset,Packet4f> -{ - static EIGEN_STRONG_INLINE void run(Packet4f& first, const Packet4f& second) - { - switch (Offset % 4) { - case 1: - first.v4f[0] = vec_sld(first.v4f[0], first.v4f[1], 8); - first.v4f[1] = vec_sld(first.v4f[1], second.v4f[0], 8); - break; - case 2: - first.v4f[0] = first.v4f[1]; - first.v4f[1] = second.v4f[0]; - break; - case 3: - first.v4f[0] = vec_sld(first.v4f[1], second.v4f[0], 8); - first.v4f[1] = vec_sld(second.v4f[0], second.v4f[1], 8); - break; - } - } -}; - -template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_LOAD - Packet4f vfrom; - vfrom.v4f[0] = vec_ld2f(&from[0]); - vfrom.v4f[1] = vec_ld2f(&from[2]); - return vfrom; -} - -template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_STORE - vec_st2f(from.v4f[0], &to[0]); - vec_st2f(from.v4f[1], &to[2]); -} - -template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) -{ - Packet4f to; - to.v4f[0] = pset1<Packet2d>(static_cast<const double&>(from)); - to.v4f[1] = to.v4f[0]; - return to; -} - -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet4f>(const float *a, - Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) -{ - a3 = pload<Packet4f>(a); - a0 = vec_splat_packet4f<0>(a3); - a1 = vec_splat_packet4f<1>(a3); - a2 = vec_splat_packet4f<2>(a3); - a3 = vec_splat_packet4f<3>(a3); -} - -template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) -{ - float EIGEN_ALIGN16 ai[4]; - ai[0] = from[0*stride]; - ai[1] = from[1*stride]; - ai[2] = from[2*stride]; - ai[3] = from[3*stride]; - return pload<Packet4f>(ai); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) -{ - float EIGEN_ALIGN16 ai[4]; - pstore<float>((float *)ai, from); - to[0*stride] = ai[0]; - to[1*stride] = ai[1]; - to[2*stride] = ai[2]; - to[3*stride] = ai[3]; -} - -template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f c; - c.v4f[0] = a.v4f[0] + b.v4f[0]; - c.v4f[1] = a.v4f[1] + b.v4f[1]; - return c; -} - -template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f c; - c.v4f[0] = a.v4f[0] - b.v4f[0]; - c.v4f[1] = a.v4f[1] - b.v4f[1]; - return c; -} - -template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f c; - c.v4f[0] = a.v4f[0] * b.v4f[0]; - c.v4f[1] = a.v4f[1] * b.v4f[1]; - return c; -} - -template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f c; - c.v4f[0] = a.v4f[0] / b.v4f[0]; - c.v4f[1] = a.v4f[1] / b.v4f[1]; - return c; -} - -template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) -{ - Packet4f c; - c.v4f[0] = -a.v4f[0]; - c.v4f[1] = -a.v4f[1]; - return c; -} - -template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) -{ - Packet4f res; - res.v4f[0] = vec_madd(a.v4f[0], b.v4f[0], c.v4f[0]); - res.v4f[1] = vec_madd(a.v4f[1], b.v4f[1], c.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f res; - res.v4f[0] = pmin(a.v4f[0], b.v4f[0]); - res.v4f[1] = pmin(a.v4f[1], b.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f res; - res.v4f[0] = pmax(a.v4f[0], b.v4f[0]); - res.v4f[1] = pmax(a.v4f[1], b.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f res; - res.v4f[0] = pand(a.v4f[0], b.v4f[0]); - res.v4f[1] = pand(a.v4f[1], b.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f res; - res.v4f[0] = pand(a.v4f[0], b.v4f[0]); - res.v4f[1] = pand(a.v4f[1], b.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f res; - res.v4f[0] = pand(a.v4f[0], b.v4f[0]); - res.v4f[1] = pand(a.v4f[1], b.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - Packet4f res; - res.v4f[0] = pandnot(a.v4f[0], b.v4f[0]); - res.v4f[1] = pandnot(a.v4f[1], b.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) -{ - Packet4f res; - res.v4f[0] = vec_round(a.v4f[0]); - res.v4f[1] = vec_round(a.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) -{ - Packet4f res; - res.v4f[0] = vec_ceil(a.v4f[0]); - res.v4f[1] = vec_ceil(a.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) -{ - Packet4f res; - res.v4f[0] = vec_floor(a.v4f[0]); - res.v4f[1] = vec_floor(a.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) -{ - Packet4f p = pload<Packet4f>(from); - p.v4f[1] = vec_splat(p.v4f[0], 1); - p.v4f[0] = vec_splat(p.v4f[0], 0); - return p; -} - -template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float EIGEN_ALIGN16 x[2]; vec_st2f(a.v4f[0], &x[0]); return x[0]; } - -template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) -{ - Packet4f rev; - rev.v4f[0] = preverse<Packet2d>(a.v4f[1]); - rev.v4f[1] = preverse<Packet2d>(a.v4f[0]); - return rev; -} - -template<> EIGEN_STRONG_INLINE Packet4f pabs<Packet4f>(const Packet4f& a) -{ - Packet4f res; - res.v4f[0] = pabs(a.v4f[0]); - res.v4f[1] = pabs(a.v4f[1]); - return res; -} - -template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) -{ - Packet2d sum; - sum = padd<Packet2d>(a.v4f[0], a.v4f[1]); - double first = predux<Packet2d>(sum); - return static_cast<float>(first); -} - -template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) -{ - PacketBlock<Packet4f,4> transpose; - transpose.packet[0] = vecs[0]; - transpose.packet[1] = vecs[1]; - transpose.packet[2] = vecs[2]; - transpose.packet[3] = vecs[3]; - ptranspose(transpose); - - Packet4f sum = padd(transpose.packet[0], transpose.packet[1]); - sum = padd(sum, transpose.packet[2]); - sum = padd(sum, transpose.packet[3]); - return sum; -} - -template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) -{ - // Return predux_mul<Packet2d> of the subvectors product - return static_cast<float>(pfirst(predux_mul(pmul(a.v4f[0], a.v4f[1])))); -} - -template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) -{ - Packet2d b, res; - b = pmin<Packet2d>(a.v4f[0], a.v4f[1]); - res = pmin<Packet2d>(b, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 8))); - return static_cast<float>(pfirst(res)); -} - -template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) -{ - Packet2d b, res; - b = pmax<Packet2d>(a.v4f[0], a.v4f[1]); - res = pmax<Packet2d>(b, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 8))); - return static_cast<float>(pfirst(res)); -} - -/* Split the Packet4f PacketBlock into 4 Packet2d PacketBlocks and transpose each one - */ -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4f,4>& kernel) { - PacketBlock<Packet2d,2> t0,t1,t2,t3; - // copy top-left 2x2 Packet2d block - t0.packet[0] = kernel.packet[0].v4f[0]; - t0.packet[1] = kernel.packet[1].v4f[0]; - - // copy top-right 2x2 Packet2d block - t1.packet[0] = kernel.packet[0].v4f[1]; - t1.packet[1] = kernel.packet[1].v4f[1]; - - // copy bottom-left 2x2 Packet2d block - t2.packet[0] = kernel.packet[2].v4f[0]; - t2.packet[1] = kernel.packet[3].v4f[0]; - - // copy bottom-right 2x2 Packet2d block - t3.packet[0] = kernel.packet[2].v4f[1]; - t3.packet[1] = kernel.packet[3].v4f[1]; - - // Transpose all 2x2 blocks - ptranspose(t0); - ptranspose(t1); - ptranspose(t2); - ptranspose(t3); - - // Copy back transposed blocks, but exchange t1 and t2 due to transposition - kernel.packet[0].v4f[0] = t0.packet[0]; - kernel.packet[0].v4f[1] = t2.packet[0]; - kernel.packet[1].v4f[0] = t0.packet[1]; - kernel.packet[1].v4f[1] = t2.packet[1]; - kernel.packet[2].v4f[0] = t1.packet[0]; - kernel.packet[2].v4f[1] = t3.packet[0]; - kernel.packet[3].v4f[0] = t1.packet[1]; - kernel.packet[3].v4f[1] = t3.packet[1]; -} - -template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) { - Packet2ul select_hi = { ifPacket.select[0], ifPacket.select[1] }; - Packet2ul select_lo = { ifPacket.select[2], ifPacket.select[3] }; - Packet2ul mask_hi = vec_cmpeq(select_hi, reinterpret_cast<Packet2ul>(p2l_ONE)); - Packet2ul mask_lo = vec_cmpeq(select_lo, reinterpret_cast<Packet2ul>(p2l_ONE)); - Packet4f result; - result.v4f[0] = vec_sel(elsePacket.v4f[0], thenPacket.v4f[0], mask_hi); - result.v4f[1] = vec_sel(elsePacket.v4f[1], thenPacket.v4f[1], mask_lo); - return result; -} -#else -template<int Offset> -struct palign_impl<Offset,Packet4f> -{ - static EIGEN_STRONG_INLINE void run(Packet4f& first, const Packet4f& second) - { - switch (Offset % 4) { - case 1: - first = vec_sld(first, second, 4); break; - case 2: - first = vec_sld(first, second, 8); break; - case 3: - first = vec_sld(first, second, 12); break; - } - } -}; - -template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_LOAD - Packet *vfrom; - vfrom = (Packet *) from; - return vfrom->v4f; -} - -template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_STORE - Packet *vto; - vto = (Packet *) to; - vto->v4f = from; -} - -template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) -{ - return vec_splats(from); -} - -template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet4f>(const float *a, - Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) -{ - a3 = pload<Packet4f>(a); - a0 = vec_splat(a3, 0); - a1 = vec_splat(a3, 1); - a2 = vec_splat(a3, 2); - a3 = vec_splat(a3, 3); -} - -template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) -{ - float EIGEN_ALIGN16 af[4]; - af[0] = from[0*stride]; - af[1] = from[1*stride]; - af[2] = from[2*stride]; - af[3] = from[3*stride]; - return pload<Packet4f>(af); -} - -template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) -{ - float EIGEN_ALIGN16 af[4]; - pstore<float>((float*)af, from); - to[0*stride] = af[0]; - to[1*stride] = af[1]; - to[2*stride] = af[2]; - to[3*stride] = af[3]; -} - -template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a + b); } -template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a - b); } -template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a * b); } -template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a / b); } -template<> EIGEN_STRONG_INLINE Packet4f pnegate<Packet4f>(const Packet4f& a) { return (-a); } -template<> EIGEN_STRONG_INLINE Packet4f pconj<Packet4f> (const Packet4f& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet4f pmadd<Packet4f> (const Packet4f& a, const Packet4f& b, const Packet4f& c) { return vec_madd(a, b, c); } -template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_min(a, b); } -template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_max(a, b); } -template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_and(a, b); } -template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_or(a, b); } -template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_xor(a, b); } -template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, vec_nor(b, b)); } -template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f> (const Packet4f& a) { return vec_round(a); } -template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f> (const Packet4f& a) { return vec_ceil(a); } -template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f> (const Packet4f& a) { return vec_floor(a); } -template<> EIGEN_STRONG_INLINE Packet4f pabs<Packet4f> (const Packet4f& a) { return vec_abs(a); } -template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float EIGEN_ALIGN16 x[4]; pstore(x, a); return x[0]; } - -template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) -{ - Packet4f p = pload<Packet4f>(from); - return vec_perm(p, p, p16uc_DUPLICATE32_HI); -} - -template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) -{ - return reinterpret_cast<Packet4f>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32)); -} - -template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) -{ - Packet4f b, sum; - b = vec_sld(a, a, 8); - sum = padd<Packet4f>(a, b); - b = vec_sld(sum, sum, 4); - sum = padd<Packet4f>(sum, b); - return pfirst(sum); -} - -template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) -{ - Packet4f v[4], sum[4]; - - // It's easier and faster to transpose then add as columns - // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation - // Do the transpose, first set of moves - v[0] = vec_mergeh(vecs[0], vecs[2]); - v[1] = vec_mergel(vecs[0], vecs[2]); - v[2] = vec_mergeh(vecs[1], vecs[3]); - v[3] = vec_mergel(vecs[1], vecs[3]); - // Get the resulting vectors - sum[0] = vec_mergeh(v[0], v[2]); - sum[1] = vec_mergel(v[0], v[2]); - sum[2] = vec_mergeh(v[1], v[3]); - sum[3] = vec_mergel(v[1], v[3]); - - // Now do the summation: - // Lines 0+1 - sum[0] = padd<Packet4f>(sum[0], sum[1]); - // Lines 2+3 - sum[1] = padd<Packet4f>(sum[2], sum[3]); - // Add the results - sum[0] = padd<Packet4f>(sum[0], sum[1]); - - return sum[0]; -} - -// Other reduction functions: -// mul -template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) -{ - Packet4f prod; - prod = pmul(a, vec_sld(a, a, 8)); - return pfirst(pmul(prod, vec_sld(prod, prod, 4))); -} - -// min -template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) -{ - Packet4f b, res; - b = pmin<Packet4f>(a, vec_sld(a, a, 8)); - res = pmin<Packet4f>(b, vec_sld(b, b, 4)); - return pfirst(res); -} - -// max -template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) -{ - Packet4f b, res; - b = pmax<Packet4f>(a, vec_sld(a, a, 8)); - res = pmax<Packet4f>(b, vec_sld(b, b, 4)); - return pfirst(res); -} - -EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4f,4>& kernel) { - Packet4f t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]); - Packet4f t1 = vec_mergel(kernel.packet[0], kernel.packet[2]); - Packet4f t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]); - Packet4f t3 = vec_mergel(kernel.packet[1], kernel.packet[3]); - kernel.packet[0] = vec_mergeh(t0, t2); - kernel.packet[1] = vec_mergel(t0, t2); - kernel.packet[2] = vec_mergeh(t1, t3); - kernel.packet[3] = vec_mergel(t1, t3); -} - -template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) { - Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] }; - Packet4ui mask = vec_cmpeq(select, reinterpret_cast<Packet4ui>(p4i_ONE)); - return vec_sel(elsePacket, thenPacket, mask); -} - -#endif - -template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { EIGEN_ZVECTOR_PREFETCH(addr); } -template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f> (const float* from) { return pload<Packet4f>(from); } -template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) { pstore<float>(to, from); } -template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f> (const float& a) { return padd<Packet4f>(pset1<Packet4f>(a), p4f_COUNTDOWN); } - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PACKET_MATH_ZVECTOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/functors/AssignmentFunctors.h b/external/eigen/include/eigen3/Eigen/src/Core/functors/AssignmentFunctors.h deleted file mode 100644 index bf64ef4e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/functors/AssignmentFunctors.h +++ /dev/null @@ -1,177 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ASSIGNMENT_FUNCTORS_H -#define EIGEN_ASSIGNMENT_FUNCTORS_H - -namespace Eigen { - -namespace internal { - -/** \internal - * \brief Template functor for scalar/packet assignment - * - */ -template<typename DstScalar,typename SrcScalar> struct assign_op { - - EIGEN_EMPTY_STRUCT_CTOR(assign_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a = b; } - - template<int Alignment, typename Packet> - EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const - { internal::pstoret<DstScalar,Packet,Alignment>(a,b); } -}; - -// Empty overload for void type (used by PermutationMatrix) -template<typename DstScalar> struct assign_op<DstScalar,void> {}; - -template<typename DstScalar,typename SrcScalar> -struct functor_traits<assign_op<DstScalar,SrcScalar> > { - enum { - Cost = NumTraits<DstScalar>::ReadCost, - PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::Vectorizable && packet_traits<SrcScalar>::Vectorizable - }; -}; - -/** \internal - * \brief Template functor for scalar/packet assignment with addition - * - */ -template<typename DstScalar,typename SrcScalar> struct add_assign_op { - - EIGEN_EMPTY_STRUCT_CTOR(add_assign_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a += b; } - - template<int Alignment, typename Packet> - EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const - { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::padd(internal::ploadt<Packet,Alignment>(a),b)); } -}; -template<typename DstScalar,typename SrcScalar> -struct functor_traits<add_assign_op<DstScalar,SrcScalar> > { - enum { - Cost = NumTraits<DstScalar>::ReadCost + NumTraits<DstScalar>::AddCost, - PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasAdd - }; -}; - -/** \internal - * \brief Template functor for scalar/packet assignment with subtraction - * - */ -template<typename DstScalar,typename SrcScalar> struct sub_assign_op { - - EIGEN_EMPTY_STRUCT_CTOR(sub_assign_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a -= b; } - - template<int Alignment, typename Packet> - EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const - { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::psub(internal::ploadt<Packet,Alignment>(a),b)); } -}; -template<typename DstScalar,typename SrcScalar> -struct functor_traits<sub_assign_op<DstScalar,SrcScalar> > { - enum { - Cost = NumTraits<DstScalar>::ReadCost + NumTraits<DstScalar>::AddCost, - PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasSub - }; -}; - -/** \internal - * \brief Template functor for scalar/packet assignment with multiplication - * - */ -template<typename DstScalar, typename SrcScalar=DstScalar> -struct mul_assign_op { - - EIGEN_EMPTY_STRUCT_CTOR(mul_assign_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a *= b; } - - template<int Alignment, typename Packet> - EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const - { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::pmul(internal::ploadt<Packet,Alignment>(a),b)); } -}; -template<typename DstScalar, typename SrcScalar> -struct functor_traits<mul_assign_op<DstScalar,SrcScalar> > { - enum { - Cost = NumTraits<DstScalar>::ReadCost + NumTraits<DstScalar>::MulCost, - PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasMul - }; -}; - -/** \internal - * \brief Template functor for scalar/packet assignment with diviving - * - */ -template<typename DstScalar, typename SrcScalar=DstScalar> struct div_assign_op { - - EIGEN_EMPTY_STRUCT_CTOR(div_assign_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a /= b; } - - template<int Alignment, typename Packet> - EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const - { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::pdiv(internal::ploadt<Packet,Alignment>(a),b)); } -}; -template<typename DstScalar, typename SrcScalar> -struct functor_traits<div_assign_op<DstScalar,SrcScalar> > { - enum { - Cost = NumTraits<DstScalar>::ReadCost + NumTraits<DstScalar>::MulCost, - PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasDiv - }; -}; - -/** \internal - * \brief Template functor for scalar/packet assignment with swapping - * - * It works as follow. For a non-vectorized evaluation loop, we have: - * for(i) func(A.coeffRef(i), B.coeff(i)); - * where B is a SwapWrapper expression. The trick is to make SwapWrapper::coeff behaves like a non-const coeffRef. - * Actually, SwapWrapper might not even be needed since even if B is a plain expression, since it has to be writable - * B.coeff already returns a const reference to the underlying scalar value. - * - * The case of a vectorized loop is more tricky: - * for(i,j) func.assignPacket<A_Align>(&A.coeffRef(i,j), B.packet<B_Align>(i,j)); - * Here, B must be a SwapWrapper whose packet function actually returns a proxy object holding a Scalar*, - * the actual alignment and Packet type. - * - */ -template<typename Scalar> struct swap_assign_op { - - EIGEN_EMPTY_STRUCT_CTOR(swap_assign_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Scalar& a, const Scalar& b) const - { -#ifdef EIGEN_GPUCC - // FIXME is there some kind of cuda::swap? - Scalar t=b; const_cast<Scalar&>(b)=a; a=t; -#else - using std::swap; - swap(a,const_cast<Scalar&>(b)); -#endif - } -}; -template<typename Scalar> -struct functor_traits<swap_assign_op<Scalar> > { - enum { - Cost = 3 * NumTraits<Scalar>::ReadCost, - PacketAccess = - #if defined(EIGEN_VECTORIZE_AVX) && EIGEN_COMP_CLANG && (EIGEN_COMP_CLANG<800 || defined(__apple_build_version__)) - // This is a partial workaround for a bug in clang generating bad code - // when mixing 256/512 bits loads and 128 bits moves. - // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1684 - // https://bugs.llvm.org/show_bug.cgi?id=40815 - 0 - #else - packet_traits<Scalar>::Vectorizable - #endif - }; -}; - -} // namespace internal - -} // namespace Eigen - -#endif // EIGEN_ASSIGNMENT_FUNCTORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/functors/BinaryFunctors.h b/external/eigen/include/eigen3/Eigen/src/Core/functors/BinaryFunctors.h deleted file mode 100644 index 401d597d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/functors/BinaryFunctors.h +++ /dev/null @@ -1,475 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BINARY_FUNCTORS_H -#define EIGEN_BINARY_FUNCTORS_H - -namespace Eigen { - -namespace internal { - -//---------- associative binary functors ---------- - -template<typename Arg1, typename Arg2> -struct binary_op_base -{ - typedef Arg1 first_argument_type; - typedef Arg2 second_argument_type; -}; - -/** \internal - * \brief Template functor to compute the sum of two scalars - * - * \sa class CwiseBinaryOp, MatrixBase::operator+, class VectorwiseOp, DenseBase::sum() - */ -template<typename LhsScalar,typename RhsScalar> -struct scalar_sum_op : binary_op_base<LhsScalar,RhsScalar> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_sum_op>::ReturnType result_type; -#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN - EIGEN_EMPTY_STRUCT_CTOR(scalar_sum_op) -#else - scalar_sum_op() { - EIGEN_SCALAR_BINARY_OP_PLUGIN - } -#endif - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a + b; } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const - { return internal::padd(a,b); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const - { return internal::predux(a); } -}; -template<typename LhsScalar,typename RhsScalar> -struct functor_traits<scalar_sum_op<LhsScalar,RhsScalar> > { - enum { - Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2, // rough estimate! - PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasAdd && packet_traits<RhsScalar>::HasAdd - // TODO vectorize mixed sum - }; -}; - -/** \internal - * \brief Template specialization to deprecate the summation of boolean expressions. - * This is required to solve Bug 426. - * \sa DenseBase::count(), DenseBase::any(), ArrayBase::cast(), MatrixBase::cast() - */ -template<> struct scalar_sum_op<bool,bool> : scalar_sum_op<int,int> { - EIGEN_DEPRECATED - scalar_sum_op() {} -}; - - -/** \internal - * \brief Template functor to compute the product of two scalars - * - * \sa class CwiseBinaryOp, Cwise::operator*(), class VectorwiseOp, MatrixBase::redux() - */ -template<typename LhsScalar,typename RhsScalar> -struct scalar_product_op : binary_op_base<LhsScalar,RhsScalar> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_product_op>::ReturnType result_type; -#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN - EIGEN_EMPTY_STRUCT_CTOR(scalar_product_op) -#else - scalar_product_op() { - EIGEN_SCALAR_BINARY_OP_PLUGIN - } -#endif - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const - { return internal::pmul(a,b); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const - { return internal::predux_mul(a); } -}; -template<typename LhsScalar,typename RhsScalar> -struct functor_traits<scalar_product_op<LhsScalar,RhsScalar> > { - enum { - Cost = (NumTraits<LhsScalar>::MulCost + NumTraits<RhsScalar>::MulCost)/2, // rough estimate! - PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasMul && packet_traits<RhsScalar>::HasMul - // TODO vectorize mixed product - }; -}; - -/** \internal - * \brief Template functor to compute the conjugate product of two scalars - * - * This is a short cut for conj(x) * y which is needed for optimization purpose; in Eigen2 support mode, this becomes x * conj(y) - */ -template<typename LhsScalar,typename RhsScalar> -struct scalar_conj_product_op : binary_op_base<LhsScalar,RhsScalar> -{ - - enum { - Conj = NumTraits<LhsScalar>::IsComplex - }; - - typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_conj_product_op>::ReturnType result_type; - - EIGEN_EMPTY_STRUCT_CTOR(scalar_conj_product_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const - { return conj_helper<LhsScalar,RhsScalar,Conj,false>().pmul(a,b); } - - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const - { return conj_helper<Packet,Packet,Conj,false>().pmul(a,b); } -}; -template<typename LhsScalar,typename RhsScalar> -struct functor_traits<scalar_conj_product_op<LhsScalar,RhsScalar> > { - enum { - Cost = NumTraits<LhsScalar>::MulCost, - PacketAccess = internal::is_same<LhsScalar, RhsScalar>::value && packet_traits<LhsScalar>::HasMul - }; -}; - -/** \internal - * \brief Template functor to compute the min of two scalars - * - * \sa class CwiseBinaryOp, MatrixBase::cwiseMin, class VectorwiseOp, MatrixBase::minCoeff() - */ -template<typename LhsScalar,typename RhsScalar> -struct scalar_min_op : binary_op_base<LhsScalar,RhsScalar> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_min_op>::ReturnType result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_min_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return numext::mini(a, b); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const - { return internal::pmin(a,b); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const - { return internal::predux_min(a); } -}; -template<typename LhsScalar,typename RhsScalar> -struct functor_traits<scalar_min_op<LhsScalar,RhsScalar> > { - enum { - Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2, - PacketAccess = internal::is_same<LhsScalar, RhsScalar>::value && packet_traits<LhsScalar>::HasMin - }; -}; - -/** \internal - * \brief Template functor to compute the max of two scalars - * - * \sa class CwiseBinaryOp, MatrixBase::cwiseMax, class VectorwiseOp, MatrixBase::maxCoeff() - */ -template<typename LhsScalar,typename RhsScalar> -struct scalar_max_op : binary_op_base<LhsScalar,RhsScalar> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_max_op>::ReturnType result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_max_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return numext::maxi(a, b); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const - { return internal::pmax(a,b); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const - { return internal::predux_max(a); } -}; -template<typename LhsScalar,typename RhsScalar> -struct functor_traits<scalar_max_op<LhsScalar,RhsScalar> > { - enum { - Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2, - PacketAccess = internal::is_same<LhsScalar, RhsScalar>::value && packet_traits<LhsScalar>::HasMax - }; -}; - -/** \internal - * \brief Template functors for comparison of two scalars - * \todo Implement packet-comparisons - */ -template<typename LhsScalar, typename RhsScalar, ComparisonName cmp> struct scalar_cmp_op; - -template<typename LhsScalar, typename RhsScalar, ComparisonName cmp> -struct functor_traits<scalar_cmp_op<LhsScalar,RhsScalar, cmp> > { - enum { - Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2, - PacketAccess = false - }; -}; - -template<ComparisonName Cmp, typename LhsScalar, typename RhsScalar> -struct result_of<scalar_cmp_op<LhsScalar, RhsScalar, Cmp>(LhsScalar,RhsScalar)> { - typedef bool type; -}; - - -template<typename LhsScalar, typename RhsScalar> -struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_EQ> : binary_op_base<LhsScalar,RhsScalar> -{ - typedef bool result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a==b;} -}; -template<typename LhsScalar, typename RhsScalar> -struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_LT> : binary_op_base<LhsScalar,RhsScalar> -{ - typedef bool result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a<b;} -}; -template<typename LhsScalar, typename RhsScalar> -struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_LE> : binary_op_base<LhsScalar,RhsScalar> -{ - typedef bool result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a<=b;} -}; -template<typename LhsScalar, typename RhsScalar> -struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_GT> : binary_op_base<LhsScalar,RhsScalar> -{ - typedef bool result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a>b;} -}; -template<typename LhsScalar, typename RhsScalar> -struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_GE> : binary_op_base<LhsScalar,RhsScalar> -{ - typedef bool result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a>=b;} -}; -template<typename LhsScalar, typename RhsScalar> -struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_UNORD> : binary_op_base<LhsScalar,RhsScalar> -{ - typedef bool result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return !(a<=b || b<=a);} -}; -template<typename LhsScalar, typename RhsScalar> -struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_NEQ> : binary_op_base<LhsScalar,RhsScalar> -{ - typedef bool result_type; - EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a!=b;} -}; - - -/** \internal - * \brief Template functor to compute the hypot of two \b positive \b and \b real scalars - * - * \sa MatrixBase::stableNorm(), class Redux - */ -template<typename Scalar> -struct scalar_hypot_op<Scalar,Scalar> : binary_op_base<Scalar,Scalar> -{ - EIGEN_EMPTY_STRUCT_CTOR(scalar_hypot_op) - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar &x, const Scalar &y) const - { - // This functor is used by hypotNorm only for which it is faster to first apply abs - // on all coefficients prior to reduction through hypot. - // This way we avoid calling abs on positive and real entries, and this also permits - // to seamlessly handle complexes. Otherwise we would have to handle both real and complexes - // through the same functor... - return internal::positive_real_hypot(x,y); - } -}; -template<typename Scalar> -struct functor_traits<scalar_hypot_op<Scalar,Scalar> > { - enum - { - Cost = 3 * NumTraits<Scalar>::AddCost + - 2 * NumTraits<Scalar>::MulCost + - 2 * scalar_div_cost<Scalar,false>::value, - PacketAccess = false - }; -}; - -/** \internal - * \brief Template functor to compute the pow of two scalars - */ -template<typename Scalar, typename Exponent> -struct scalar_pow_op : binary_op_base<Scalar,Exponent> -{ - typedef typename ScalarBinaryOpTraits<Scalar,Exponent,scalar_pow_op>::ReturnType result_type; -#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN - EIGEN_EMPTY_STRUCT_CTOR(scalar_pow_op) -#else - scalar_pow_op() { - typedef Scalar LhsScalar; - typedef Exponent RhsScalar; - EIGEN_SCALAR_BINARY_OP_PLUGIN - } -#endif - EIGEN_DEVICE_FUNC - inline result_type operator() (const Scalar& a, const Exponent& b) const { return numext::pow(a, b); } -}; -template<typename Scalar, typename Exponent> -struct functor_traits<scalar_pow_op<Scalar,Exponent> > { - enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; -}; - - - -//---------- non associative binary functors ---------- - -/** \internal - * \brief Template functor to compute the difference of two scalars - * - * \sa class CwiseBinaryOp, MatrixBase::operator- - */ -template<typename LhsScalar,typename RhsScalar> -struct scalar_difference_op : binary_op_base<LhsScalar,RhsScalar> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_difference_op>::ReturnType result_type; -#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN - EIGEN_EMPTY_STRUCT_CTOR(scalar_difference_op) -#else - scalar_difference_op() { - EIGEN_SCALAR_BINARY_OP_PLUGIN - } -#endif - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a - b; } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const - { return internal::psub(a,b); } -}; -template<typename LhsScalar,typename RhsScalar> -struct functor_traits<scalar_difference_op<LhsScalar,RhsScalar> > { - enum { - Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2, - PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasSub && packet_traits<RhsScalar>::HasSub - }; -}; - -/** \internal - * \brief Template functor to compute the quotient of two scalars - * - * \sa class CwiseBinaryOp, Cwise::operator/() - */ -template<typename LhsScalar,typename RhsScalar> -struct scalar_quotient_op : binary_op_base<LhsScalar,RhsScalar> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_quotient_op>::ReturnType result_type; -#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN - EIGEN_EMPTY_STRUCT_CTOR(scalar_quotient_op) -#else - scalar_quotient_op() { - EIGEN_SCALAR_BINARY_OP_PLUGIN - } -#endif - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a / b; } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const - { return internal::pdiv(a,b); } -}; -template<typename LhsScalar,typename RhsScalar> -struct functor_traits<scalar_quotient_op<LhsScalar,RhsScalar> > { - typedef typename scalar_quotient_op<LhsScalar,RhsScalar>::result_type result_type; - enum { - PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasDiv && packet_traits<RhsScalar>::HasDiv, - Cost = scalar_div_cost<result_type,PacketAccess>::value - }; -}; - - - -/** \internal - * \brief Template functor to compute the and of two booleans - * - * \sa class CwiseBinaryOp, ArrayBase::operator&& - */ -struct scalar_boolean_and_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_and_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a && b; } -}; -template<> struct functor_traits<scalar_boolean_and_op> { - enum { - Cost = NumTraits<bool>::AddCost, - PacketAccess = false - }; -}; - -/** \internal - * \brief Template functor to compute the or of two booleans - * - * \sa class CwiseBinaryOp, ArrayBase::operator|| - */ -struct scalar_boolean_or_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_or_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a || b; } -}; -template<> struct functor_traits<scalar_boolean_or_op> { - enum { - Cost = NumTraits<bool>::AddCost, - PacketAccess = false - }; -}; - -/** \internal - * \brief Template functor to compute the xor of two booleans - * - * \sa class CwiseBinaryOp, ArrayBase::operator^ - */ -struct scalar_boolean_xor_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_xor_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a ^ b; } -}; -template<> struct functor_traits<scalar_boolean_xor_op> { - enum { - Cost = NumTraits<bool>::AddCost, - PacketAccess = false - }; -}; - - - -//---------- binary functors bound to a constant, thus appearing as a unary functor ---------- - -// The following two classes permits to turn any binary functor into a unary one with one argument bound to a constant value. -// They are analogues to std::binder1st/binder2nd but with the following differences: -// - they are compatible with packetOp -// - they are portable across C++ versions (the std::binder* are deprecated in C++11) -template<typename BinaryOp> struct bind1st_op : BinaryOp { - - typedef typename BinaryOp::first_argument_type first_argument_type; - typedef typename BinaryOp::second_argument_type second_argument_type; - typedef typename BinaryOp::result_type result_type; - - EIGEN_DEVICE_FUNC explicit bind1st_op(const first_argument_type &val) : m_value(val) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const second_argument_type& b) const { return BinaryOp::operator()(m_value,b); } - - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& b) const - { return BinaryOp::packetOp(internal::pset1<Packet>(m_value), b); } - - first_argument_type m_value; -}; -template<typename BinaryOp> struct functor_traits<bind1st_op<BinaryOp> > : functor_traits<BinaryOp> {}; - - -template<typename BinaryOp> struct bind2nd_op : BinaryOp { - - typedef typename BinaryOp::first_argument_type first_argument_type; - typedef typename BinaryOp::second_argument_type second_argument_type; - typedef typename BinaryOp::result_type result_type; - - EIGEN_DEVICE_FUNC explicit bind2nd_op(const second_argument_type &val) : m_value(val) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const first_argument_type& a) const { return BinaryOp::operator()(a,m_value); } - - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const - { return BinaryOp::packetOp(a,internal::pset1<Packet>(m_value)); } - - second_argument_type m_value; -}; -template<typename BinaryOp> struct functor_traits<bind2nd_op<BinaryOp> > : functor_traits<BinaryOp> {}; - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_BINARY_FUNCTORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/functors/NullaryFunctors.h b/external/eigen/include/eigen3/Eigen/src/Core/functors/NullaryFunctors.h deleted file mode 100644 index 16b645f9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/functors/NullaryFunctors.h +++ /dev/null @@ -1,189 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_NULLARY_FUNCTORS_H -#define EIGEN_NULLARY_FUNCTORS_H - -namespace Eigen { - -namespace internal { - -template<typename Scalar> -struct scalar_constant_op { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_constant_op(const scalar_constant_op& other) : m_other(other.m_other) { } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_constant_op(const Scalar& other) : m_other(other) { } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const { return m_other; } - template<typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const PacketType packetOp() const { return internal::pset1<PacketType>(m_other); } - const Scalar m_other; -}; -template<typename Scalar> -struct functor_traits<scalar_constant_op<Scalar> > -{ enum { Cost = 0 /* as the constant value should be loaded in register only once for the whole expression */, - PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = true }; }; - -template<typename Scalar> struct scalar_identity_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_identity_op) - template<typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (IndexType row, IndexType col) const { return row==col ? Scalar(1) : Scalar(0); } -}; -template<typename Scalar> -struct functor_traits<scalar_identity_op<Scalar> > -{ enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = false, IsRepeatable = true }; }; - -template <typename Scalar, bool IsInteger> struct linspaced_op_impl; - -template <typename Scalar> -struct linspaced_op_impl<Scalar,/*IsInteger*/false> -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - - linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) : - m_low(low), m_high(high), m_size1(num_steps==1 ? 1 : num_steps-1), m_step(num_steps==1 ? Scalar() : (high-low)/RealScalar(num_steps-1)), - m_flip(numext::abs(high)<numext::abs(low)) - {} - - template<typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (IndexType i) const { - if(m_flip) - return (i==0)? m_low : (m_high - RealScalar(m_size1-i)*m_step); - else - return (i==m_size1)? m_high : (m_low + RealScalar(i)*m_step); - } - - template<typename Packet, typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(IndexType i) const - { - // Principle: - // [low, ..., low] + ( [step, ..., step] * ( [i, ..., i] + [0, ..., size] ) ) - if(m_flip) - { - Packet pi = plset<Packet>(Scalar(i-m_size1)); - Packet res = padd(pset1<Packet>(m_high), pmul(pset1<Packet>(m_step), pi)); - if(i==0) - res = pinsertfirst(res, m_low); - return res; - } - else - { - Packet pi = plset<Packet>(Scalar(i)); - Packet res = padd(pset1<Packet>(m_low), pmul(pset1<Packet>(m_step), pi)); - if(i==m_size1-unpacket_traits<Packet>::size+1) - res = pinsertlast(res, m_high); - return res; - } - } - - const Scalar m_low; - const Scalar m_high; - const Index m_size1; - const Scalar m_step; - const bool m_flip; -}; - -template <typename Scalar> -struct linspaced_op_impl<Scalar,/*IsInteger*/true> -{ - linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) : - m_low(low), - m_multiplier((high-low)/convert_index<Scalar>(num_steps<=1 ? 1 : num_steps-1)), - m_divisor(convert_index<Scalar>((high>=low?num_steps:-num_steps)+(high-low))/((numext::abs(high-low)+1)==0?1:(numext::abs(high-low)+1))), - m_use_divisor(num_steps>1 && (numext::abs(high-low)+1)<num_steps) - {} - - template<typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Scalar operator() (IndexType i) const - { - if(m_use_divisor) return m_low + convert_index<Scalar>(i)/m_divisor; - else return m_low + convert_index<Scalar>(i)*m_multiplier; - } - - const Scalar m_low; - const Scalar m_multiplier; - const Scalar m_divisor; - const bool m_use_divisor; -}; - -// ----- Linspace functor ---------------------------------------------------------------- - -// Forward declaration (we default to random access which does not really give -// us a speed gain when using packet access but it allows to use the functor in -// nested expressions). -template <typename Scalar> struct linspaced_op; -template <typename Scalar> struct functor_traits< linspaced_op<Scalar> > -{ - enum - { - Cost = 1, - PacketAccess = (!NumTraits<Scalar>::IsInteger) && packet_traits<Scalar>::HasSetLinear && packet_traits<Scalar>::HasBlend, - /*&& ((!NumTraits<Scalar>::IsInteger) || packet_traits<Scalar>::HasDiv),*/ // <- vectorization for integer is currently disabled - IsRepeatable = true - }; -}; -template <typename Scalar> struct linspaced_op -{ - linspaced_op(const Scalar& low, const Scalar& high, Index num_steps) - : impl((num_steps==1 ? high : low),high,num_steps) - {} - - template<typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (IndexType i) const { return impl(i); } - - template<typename Packet,typename IndexType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(IndexType i) const { return impl.template packetOp<Packet>(i); } - - // This proxy object handles the actual required temporaries and the different - // implementations (integer vs. floating point). - const linspaced_op_impl<Scalar,NumTraits<Scalar>::IsInteger> impl; -}; - -// Linear access is automatically determined from the operator() prototypes available for the given functor. -// If it exposes an operator()(i,j), then we assume the i and j coefficients are required independently -// and linear access is not possible. In all other cases, linear access is enabled. -// Users should not have to deal with this structure. -template<typename Functor> struct functor_has_linear_access { enum { ret = !has_binary_operator<Functor>::value }; }; - -// For unreliable compilers, let's specialize the has_*ary_operator -// helpers so that at least built-in nullary functors work fine. -#if !( (EIGEN_COMP_MSVC>1600) || (EIGEN_GNUC_AT_LEAST(4,8)) || (EIGEN_COMP_ICC>=1600)) -template<typename Scalar,typename IndexType> -struct has_nullary_operator<scalar_constant_op<Scalar>,IndexType> { enum { value = 1}; }; -template<typename Scalar,typename IndexType> -struct has_unary_operator<scalar_constant_op<Scalar>,IndexType> { enum { value = 0}; }; -template<typename Scalar,typename IndexType> -struct has_binary_operator<scalar_constant_op<Scalar>,IndexType> { enum { value = 0}; }; - -template<typename Scalar,typename IndexType> -struct has_nullary_operator<scalar_identity_op<Scalar>,IndexType> { enum { value = 0}; }; -template<typename Scalar,typename IndexType> -struct has_unary_operator<scalar_identity_op<Scalar>,IndexType> { enum { value = 0}; }; -template<typename Scalar,typename IndexType> -struct has_binary_operator<scalar_identity_op<Scalar>,IndexType> { enum { value = 1}; }; - -template<typename Scalar,typename IndexType> -struct has_nullary_operator<linspaced_op<Scalar>,IndexType> { enum { value = 0}; }; -template<typename Scalar,typename IndexType> -struct has_unary_operator<linspaced_op<Scalar>,IndexType> { enum { value = 1}; }; -template<typename Scalar,typename IndexType> -struct has_binary_operator<linspaced_op<Scalar>,IndexType> { enum { value = 0}; }; - -template<typename Scalar,typename IndexType> -struct has_nullary_operator<scalar_random_op<Scalar>,IndexType> { enum { value = 1}; }; -template<typename Scalar,typename IndexType> -struct has_unary_operator<scalar_random_op<Scalar>,IndexType> { enum { value = 0}; }; -template<typename Scalar,typename IndexType> -struct has_binary_operator<scalar_random_op<Scalar>,IndexType> { enum { value = 0}; }; -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_NULLARY_FUNCTORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/functors/StlFunctors.h b/external/eigen/include/eigen3/Eigen/src/Core/functors/StlFunctors.h deleted file mode 100644 index 9c1d7585..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/functors/StlFunctors.h +++ /dev/null @@ -1,136 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STL_FUNCTORS_H -#define EIGEN_STL_FUNCTORS_H - -namespace Eigen { - -namespace internal { - -// default functor traits for STL functors: - -template<typename T> -struct functor_traits<std::multiplies<T> > -{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::divides<T> > -{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::plus<T> > -{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::minus<T> > -{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::negate<T> > -{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::logical_or<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::logical_and<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::logical_not<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::greater<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::less<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::greater_equal<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::less_equal<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::equal_to<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::not_equal_to<T> > -{ enum { Cost = 1, PacketAccess = false }; }; - -#if (__cplusplus < 201103L) && (EIGEN_COMP_MSVC <= 1900) -// std::binder* are deprecated since c++11 and will be removed in c++17 -template<typename T> -struct functor_traits<std::binder2nd<T> > -{ enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; }; - -template<typename T> -struct functor_traits<std::binder1st<T> > -{ enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; }; -#endif - -#if (__cplusplus < 201703L) && (EIGEN_COMP_MSVC < 1910) -// std::unary_negate is deprecated since c++17 and will be removed in c++20 -template<typename T> -struct functor_traits<std::unary_negate<T> > -{ enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; }; - -// std::binary_negate is deprecated since c++17 and will be removed in c++20 -template<typename T> -struct functor_traits<std::binary_negate<T> > -{ enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; }; -#endif - -#ifdef EIGEN_STDEXT_SUPPORT - -template<typename T0,typename T1> -struct functor_traits<std::project1st<T0,T1> > -{ enum { Cost = 0, PacketAccess = false }; }; - -template<typename T0,typename T1> -struct functor_traits<std::project2nd<T0,T1> > -{ enum { Cost = 0, PacketAccess = false }; }; - -template<typename T0,typename T1> -struct functor_traits<std::select2nd<std::pair<T0,T1> > > -{ enum { Cost = 0, PacketAccess = false }; }; - -template<typename T0,typename T1> -struct functor_traits<std::select1st<std::pair<T0,T1> > > -{ enum { Cost = 0, PacketAccess = false }; }; - -template<typename T0,typename T1> -struct functor_traits<std::unary_compose<T0,T1> > -{ enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost, PacketAccess = false }; }; - -template<typename T0,typename T1,typename T2> -struct functor_traits<std::binary_compose<T0,T1,T2> > -{ enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost + functor_traits<T2>::Cost, PacketAccess = false }; }; - -#endif // EIGEN_STDEXT_SUPPORT - -// allow to add new functors and specializations of functor_traits from outside Eigen. -// this macro is really needed because functor_traits must be specialized after it is declared but before it is used... -#ifdef EIGEN_FUNCTORS_PLUGIN -#include EIGEN_FUNCTORS_PLUGIN -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_STL_FUNCTORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/functors/TernaryFunctors.h b/external/eigen/include/eigen3/Eigen/src/Core/functors/TernaryFunctors.h deleted file mode 100644 index b254e96c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/functors/TernaryFunctors.h +++ /dev/null @@ -1,25 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TERNARY_FUNCTORS_H -#define EIGEN_TERNARY_FUNCTORS_H - -namespace Eigen { - -namespace internal { - -//---------- associative ternary functors ---------- - - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TERNARY_FUNCTORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/functors/UnaryFunctors.h b/external/eigen/include/eigen3/Eigen/src/Core/functors/UnaryFunctors.h deleted file mode 100644 index a07ddaa3..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/functors/UnaryFunctors.h +++ /dev/null @@ -1,1036 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_UNARY_FUNCTORS_H -#define EIGEN_UNARY_FUNCTORS_H - -namespace Eigen { - -namespace internal { - -/** \internal - * \brief Template functor to compute the opposite of a scalar - * - * \sa class CwiseUnaryOp, MatrixBase::operator- - */ -template<typename Scalar> struct scalar_opposite_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_opposite_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return -a; } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const - { return internal::pnegate(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_opposite_op<Scalar> > -{ enum { - Cost = NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasNegate }; -}; - -/** \internal - * \brief Template functor to compute the absolute value of a scalar - * - * \sa class CwiseUnaryOp, Cwise::abs - */ -template<typename Scalar> struct scalar_abs_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_abs_op) - typedef typename NumTraits<Scalar>::Real result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::abs(a); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const - { return internal::pabs(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_abs_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasAbs - }; -}; - -/** \internal - * \brief Template functor to compute the score of a scalar, to chose a pivot - * - * \sa class CwiseUnaryOp - */ -template<typename Scalar> struct scalar_score_coeff_op : scalar_abs_op<Scalar> -{ - typedef void Score_is_abs; -}; -template<typename Scalar> -struct functor_traits<scalar_score_coeff_op<Scalar> > : functor_traits<scalar_abs_op<Scalar> > {}; - -/* Avoid recomputing abs when we know the score and they are the same. Not a true Eigen functor. */ -template<typename Scalar, typename=void> struct abs_knowing_score -{ - EIGEN_EMPTY_STRUCT_CTOR(abs_knowing_score) - typedef typename NumTraits<Scalar>::Real result_type; - template<typename Score> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a, const Score&) const { return numext::abs(a); } -}; -template<typename Scalar> struct abs_knowing_score<Scalar, typename scalar_score_coeff_op<Scalar>::Score_is_abs> -{ - EIGEN_EMPTY_STRUCT_CTOR(abs_knowing_score) - typedef typename NumTraits<Scalar>::Real result_type; - template<typename Scal> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scal&, const result_type& a) const { return a; } -}; - -/** \internal - * \brief Template functor to compute the squared absolute value of a scalar - * - * \sa class CwiseUnaryOp, Cwise::abs2 - */ -template<typename Scalar> struct scalar_abs2_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_abs2_op) - typedef typename NumTraits<Scalar>::Real result_type; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::abs2(a); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const - { return internal::pmul(a,a); } -}; -template<typename Scalar> -struct functor_traits<scalar_abs2_op<Scalar> > -{ enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasAbs2 }; }; - -/** \internal - * \brief Template functor to compute the conjugate of a complex value - * - * \sa class CwiseUnaryOp, MatrixBase::conjugate() - */ -template<typename Scalar> struct scalar_conjugate_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_conjugate_op) - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { using numext::conj; return conj(a); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const { return internal::pconj(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_conjugate_op<Scalar> > -{ - enum { - Cost = 0, - // Yes the cost is zero even for complexes because in most cases for which - // the cost is used, conjugation turns to be a no-op. Some examples: - // cost(a*conj(b)) == cost(a*b) - // cost(a+conj(b)) == cost(a+b) - // <etc. - // If we don't set it to zero, then: - // A.conjugate().lazyProduct(B.conjugate()) - // will bake its operands. We definitely don't want that! - PacketAccess = packet_traits<Scalar>::HasConj - }; -}; - -/** \internal - * \brief Template functor to compute the phase angle of a complex - * - * \sa class CwiseUnaryOp, Cwise::arg - */ -template<typename Scalar> struct scalar_arg_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_arg_op) - typedef typename NumTraits<Scalar>::Real result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { using numext::arg; return arg(a); } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const - { return internal::parg(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_arg_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::IsComplex ? 5 * NumTraits<Scalar>::MulCost : NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasArg - }; -}; -/** \internal - * \brief Template functor to cast a scalar to another type - * - * \sa class CwiseUnaryOp, MatrixBase::cast() - */ -template<typename Scalar, typename NewType> -struct scalar_cast_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op) - typedef NewType result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const NewType operator() (const Scalar& a) const { return cast<Scalar, NewType>(a); } -}; -template<typename Scalar, typename NewType> -struct functor_traits<scalar_cast_op<Scalar,NewType> > -{ enum { Cost = is_same<Scalar, NewType>::value ? 0 : NumTraits<NewType>::AddCost, PacketAccess = false }; }; - -/** \internal - * \brief Template functor to extract the real part of a complex - * - * \sa class CwiseUnaryOp, MatrixBase::real() - */ -template<typename Scalar> -struct scalar_real_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_real_op) - typedef typename NumTraits<Scalar>::Real result_type; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::real(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_real_op<Scalar> > -{ enum { Cost = 0, PacketAccess = false }; }; - -/** \internal - * \brief Template functor to extract the imaginary part of a complex - * - * \sa class CwiseUnaryOp, MatrixBase::imag() - */ -template<typename Scalar> -struct scalar_imag_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_op) - typedef typename NumTraits<Scalar>::Real result_type; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::imag(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_imag_op<Scalar> > -{ enum { Cost = 0, PacketAccess = false }; }; - -/** \internal - * \brief Template functor to extract the real part of a complex as a reference - * - * \sa class CwiseUnaryOp, MatrixBase::real() - */ -template<typename Scalar> -struct scalar_real_ref_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_real_ref_op) - typedef typename NumTraits<Scalar>::Real result_type; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::real_ref(*const_cast<Scalar*>(&a)); } -}; -template<typename Scalar> -struct functor_traits<scalar_real_ref_op<Scalar> > -{ enum { Cost = 0, PacketAccess = false }; }; - -/** \internal - * \brief Template functor to extract the imaginary part of a complex as a reference - * - * \sa class CwiseUnaryOp, MatrixBase::imag() - */ -template<typename Scalar> -struct scalar_imag_ref_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_ref_op) - typedef typename NumTraits<Scalar>::Real result_type; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::imag_ref(*const_cast<Scalar*>(&a)); } -}; -template<typename Scalar> -struct functor_traits<scalar_imag_ref_op<Scalar> > -{ enum { Cost = 0, PacketAccess = false }; }; - -/** \internal - * - * \brief Template functor to compute the exponential of a scalar - * - * \sa class CwiseUnaryOp, Cwise::exp() - */ -template<typename Scalar> struct scalar_exp_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_exp_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::exp(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pexp(a); } -}; -template <typename Scalar> -struct functor_traits<scalar_exp_op<Scalar> > { - enum { - PacketAccess = packet_traits<Scalar>::HasExp, - // The following numbers are based on the AVX implementation. -#ifdef EIGEN_VECTORIZE_FMA - // Haswell can issue 2 add/mul/madd per cycle. - Cost = - (sizeof(Scalar) == 4 - // float: 8 pmadd, 4 pmul, 2 padd/psub, 6 other - ? (8 * NumTraits<Scalar>::AddCost + 6 * NumTraits<Scalar>::MulCost) - // double: 7 pmadd, 5 pmul, 3 padd/psub, 1 div, 13 other - : (14 * NumTraits<Scalar>::AddCost + - 6 * NumTraits<Scalar>::MulCost + - scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value)) -#else - Cost = - (sizeof(Scalar) == 4 - // float: 7 pmadd, 6 pmul, 4 padd/psub, 10 other - ? (21 * NumTraits<Scalar>::AddCost + 13 * NumTraits<Scalar>::MulCost) - // double: 7 pmadd, 5 pmul, 3 padd/psub, 1 div, 13 other - : (23 * NumTraits<Scalar>::AddCost + - 12 * NumTraits<Scalar>::MulCost + - scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value)) -#endif - }; -}; - -/** \internal - * - * \brief Template functor to compute the exponential of a scalar - 1. - * - * \sa class CwiseUnaryOp, ArrayBase::expm1() - */ -template<typename Scalar> struct scalar_expm1_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_expm1_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::expm1(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pexpm1(a); } -}; -template <typename Scalar> -struct functor_traits<scalar_expm1_op<Scalar> > { - enum { - PacketAccess = packet_traits<Scalar>::HasExpm1, - Cost = functor_traits<scalar_exp_op<Scalar> >::Cost // TODO measure cost of expm1 - }; -}; - -/** \internal - * - * \brief Template functor to compute the logarithm of a scalar - * - * \sa class CwiseUnaryOp, ArrayBase::log() - */ -template<typename Scalar> struct scalar_log_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_log_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::log(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog(a); } -}; -template <typename Scalar> -struct functor_traits<scalar_log_op<Scalar> > { - enum { - PacketAccess = packet_traits<Scalar>::HasLog, - Cost = - (PacketAccess - // The following numbers are based on the AVX implementation. -#ifdef EIGEN_VECTORIZE_FMA - // 8 pmadd, 6 pmul, 8 padd/psub, 16 other, can issue 2 add/mul/madd per cycle. - ? (20 * NumTraits<Scalar>::AddCost + 7 * NumTraits<Scalar>::MulCost) -#else - // 8 pmadd, 6 pmul, 8 padd/psub, 20 other - ? (36 * NumTraits<Scalar>::AddCost + 14 * NumTraits<Scalar>::MulCost) -#endif - // Measured cost of std::log. - : sizeof(Scalar)==4 ? 40 : 85) - }; -}; - -/** \internal - * - * \brief Template functor to compute the logarithm of 1 plus a scalar value - * - * \sa class CwiseUnaryOp, ArrayBase::log1p() - */ -template<typename Scalar> struct scalar_log1p_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_log1p_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::log1p(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog1p(a); } -}; -template <typename Scalar> -struct functor_traits<scalar_log1p_op<Scalar> > { - enum { - PacketAccess = packet_traits<Scalar>::HasLog1p, - Cost = functor_traits<scalar_log_op<Scalar> >::Cost // TODO measure cost of log1p - }; -}; - -/** \internal - * - * \brief Template functor to compute the base-10 logarithm of a scalar - * - * \sa class CwiseUnaryOp, Cwise::log10() - */ -template<typename Scalar> struct scalar_log10_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_log10_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { EIGEN_USING_STD_MATH(log10) return log10(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog10(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_log10_op<Scalar> > -{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasLog10 }; }; - -/** \internal - * \brief Template functor to compute the square root of a scalar - * \sa class CwiseUnaryOp, Cwise::sqrt() - */ -template<typename Scalar> struct scalar_sqrt_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_sqrt_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sqrt(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psqrt(a); } -}; -template <typename Scalar> -struct functor_traits<scalar_sqrt_op<Scalar> > { - enum { -#if EIGEN_FAST_MATH - // The following numbers are based on the AVX implementation. - Cost = (sizeof(Scalar) == 8 ? 28 - // 4 pmul, 1 pmadd, 3 other - : (3 * NumTraits<Scalar>::AddCost + - 5 * NumTraits<Scalar>::MulCost)), -#else - // The following numbers are based on min VSQRT throughput on Haswell. - Cost = (sizeof(Scalar) == 8 ? 28 : 14), -#endif - PacketAccess = packet_traits<Scalar>::HasSqrt - }; -}; - -/** \internal - * \brief Template functor to compute the reciprocal square root of a scalar - * \sa class CwiseUnaryOp, Cwise::rsqrt() - */ -template<typename Scalar> struct scalar_rsqrt_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_rsqrt_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return Scalar(1)/numext::sqrt(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::prsqrt(a); } -}; - -template<typename Scalar> -struct functor_traits<scalar_rsqrt_op<Scalar> > -{ enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasRsqrt - }; -}; - -/** \internal - * \brief Template functor to compute the cosine of a scalar - * \sa class CwiseUnaryOp, ArrayBase::cos() - */ -template<typename Scalar> struct scalar_cos_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_cos_op) - EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return numext::cos(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pcos(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_cos_op<Scalar> > -{ - enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasCos - }; -}; - -/** \internal - * \brief Template functor to compute the sine of a scalar - * \sa class CwiseUnaryOp, ArrayBase::sin() - */ -template<typename Scalar> struct scalar_sin_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_sin_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sin(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psin(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_sin_op<Scalar> > -{ - enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasSin - }; -}; - - -/** \internal - * \brief Template functor to compute the tan of a scalar - * \sa class CwiseUnaryOp, ArrayBase::tan() - */ -template<typename Scalar> struct scalar_tan_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_tan_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::tan(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::ptan(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_tan_op<Scalar> > -{ - enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasTan - }; -}; - -/** \internal - * \brief Template functor to compute the arc cosine of a scalar - * \sa class CwiseUnaryOp, ArrayBase::acos() - */ -template<typename Scalar> struct scalar_acos_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_acos_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::acos(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pacos(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_acos_op<Scalar> > -{ - enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasACos - }; -}; - -/** \internal - * \brief Template functor to compute the arc sine of a scalar - * \sa class CwiseUnaryOp, ArrayBase::asin() - */ -template<typename Scalar> struct scalar_asin_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_asin_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::asin(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pasin(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_asin_op<Scalar> > -{ - enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasASin - }; -}; - - -/** \internal - * \brief Template functor to compute the atan of a scalar - * \sa class CwiseUnaryOp, ArrayBase::atan() - */ -template<typename Scalar> struct scalar_atan_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_atan_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::atan(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::patan(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_atan_op<Scalar> > -{ - enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasATan - }; -}; - -/** \internal - * \brief Template functor to compute the tanh of a scalar - * \sa class CwiseUnaryOp, ArrayBase::tanh() - */ -template <typename Scalar> -struct scalar_tanh_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_tanh_op) - EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::tanh(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& x) const { return ptanh(x); } -}; - -template <typename Scalar> -struct functor_traits<scalar_tanh_op<Scalar> > { - enum { - PacketAccess = packet_traits<Scalar>::HasTanh, - Cost = ( (EIGEN_FAST_MATH && is_same<Scalar,float>::value) -// The following numbers are based on the AVX implementation, -#ifdef EIGEN_VECTORIZE_FMA - // Haswell can issue 2 add/mul/madd per cycle. - // 9 pmadd, 2 pmul, 1 div, 2 other - ? (2 * NumTraits<Scalar>::AddCost + - 6 * NumTraits<Scalar>::MulCost + - scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value) -#else - ? (11 * NumTraits<Scalar>::AddCost + - 11 * NumTraits<Scalar>::MulCost + - scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value) -#endif - // This number assumes a naive implementation of tanh - : (6 * NumTraits<Scalar>::AddCost + - 3 * NumTraits<Scalar>::MulCost + - 2 * scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value + - functor_traits<scalar_exp_op<Scalar> >::Cost)) - }; -}; - -#if EIGEN_HAS_CXX11_MATH -/** \internal - * \brief Template functor to compute the atanh of a scalar - * \sa class CwiseUnaryOp, ArrayBase::atanh() - */ -template <typename Scalar> -struct scalar_atanh_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_atanh_op) - EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::atanh(a); } -}; - -template <typename Scalar> -struct functor_traits<scalar_atanh_op<Scalar> > { - enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; -}; -#endif - -/** \internal - * \brief Template functor to compute the sinh of a scalar - * \sa class CwiseUnaryOp, ArrayBase::sinh() - */ -template<typename Scalar> struct scalar_sinh_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_sinh_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sinh(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psinh(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_sinh_op<Scalar> > -{ - enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasSinh - }; -}; - -#if EIGEN_HAS_CXX11_MATH -/** \internal - * \brief Template functor to compute the asinh of a scalar - * \sa class CwiseUnaryOp, ArrayBase::asinh() - */ -template <typename Scalar> -struct scalar_asinh_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_asinh_op) - EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::asinh(a); } -}; - -template <typename Scalar> -struct functor_traits<scalar_asinh_op<Scalar> > { - enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; -}; -#endif - -/** \internal - * \brief Template functor to compute the cosh of a scalar - * \sa class CwiseUnaryOp, ArrayBase::cosh() - */ -template<typename Scalar> struct scalar_cosh_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_cosh_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::cosh(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pcosh(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_cosh_op<Scalar> > -{ - enum { - Cost = 5 * NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasCosh - }; -}; - -#if EIGEN_HAS_CXX11_MATH -/** \internal - * \brief Template functor to compute the acosh of a scalar - * \sa class CwiseUnaryOp, ArrayBase::acosh() - */ -template <typename Scalar> -struct scalar_acosh_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_acosh_op) - EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::acosh(a); } -}; - -template <typename Scalar> -struct functor_traits<scalar_acosh_op<Scalar> > { - enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; -}; -#endif - -/** \internal - * \brief Template functor to compute the inverse of a scalar - * \sa class CwiseUnaryOp, Cwise::inverse() - */ -template<typename Scalar> -struct scalar_inverse_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_inverse_op) - EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return Scalar(1)/a; } - template<typename Packet> - EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const - { return internal::pdiv(pset1<Packet>(Scalar(1)),a); } -}; -template <typename Scalar> -struct functor_traits<scalar_inverse_op<Scalar> > { - enum { - PacketAccess = packet_traits<Scalar>::HasDiv, - Cost = scalar_div_cost<Scalar, PacketAccess>::value - }; -}; - -/** \internal - * \brief Template functor to compute the square of a scalar - * \sa class CwiseUnaryOp, Cwise::square() - */ -template<typename Scalar> -struct scalar_square_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_square_op) - EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return a*a; } - template<typename Packet> - EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const - { return internal::pmul(a,a); } -}; -template<typename Scalar> -struct functor_traits<scalar_square_op<Scalar> > -{ enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; }; - -/** \internal - * \brief Template functor to compute the cube of a scalar - * \sa class CwiseUnaryOp, Cwise::cube() - */ -template<typename Scalar> -struct scalar_cube_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_cube_op) - EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return a*a*a; } - template<typename Packet> - EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const - { return internal::pmul(a,pmul(a,a)); } -}; -template<typename Scalar> -struct functor_traits<scalar_cube_op<Scalar> > -{ enum { Cost = 2*NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; }; - -/** \internal - * \brief Template functor to compute the rounded value of a scalar - * \sa class CwiseUnaryOp, ArrayBase::round() - */ -template<typename Scalar> struct scalar_round_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_round_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::round(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pround(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_round_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasRound - }; -}; - -/** \internal - * \brief Template functor to compute the floor of a scalar - * \sa class CwiseUnaryOp, ArrayBase::floor() - */ -template<typename Scalar> struct scalar_floor_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_floor_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::floor(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pfloor(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_floor_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasFloor - }; -}; - -/** \internal - * \brief Template functor to compute the rounded (with current rounding mode) value of a scalar - * \sa class CwiseUnaryOp, ArrayBase::rint() - */ -template<typename Scalar> struct scalar_rint_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_rint_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::rint(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::print(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_rint_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasRint - }; -}; - -/** \internal - * \brief Template functor to compute the ceil of a scalar - * \sa class CwiseUnaryOp, ArrayBase::ceil() - */ -template<typename Scalar> struct scalar_ceil_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_ceil_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::ceil(a); } - template <typename Packet> - EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pceil(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_ceil_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::MulCost, - PacketAccess = packet_traits<Scalar>::HasCeil - }; -}; - -/** \internal - * \brief Template functor to compute whether a scalar is NaN - * \sa class CwiseUnaryOp, ArrayBase::isnan() - */ -template<typename Scalar> struct scalar_isnan_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_isnan_op) - typedef bool result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { -#if defined(SYCL_DEVICE_ONLY) - return numext::isnan(a); -#else - return (numext::isnan)(a); -#endif - } -}; -template<typename Scalar> -struct functor_traits<scalar_isnan_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::MulCost, - PacketAccess = false - }; -}; - -/** \internal - * \brief Template functor to check whether a scalar is +/-inf - * \sa class CwiseUnaryOp, ArrayBase::isinf() - */ -template<typename Scalar> struct scalar_isinf_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_isinf_op) - typedef bool result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { -#if defined(SYCL_DEVICE_ONLY) - return numext::isinf(a); -#else - return (numext::isinf)(a); -#endif - } -}; -template<typename Scalar> -struct functor_traits<scalar_isinf_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::MulCost, - PacketAccess = false - }; -}; - -/** \internal - * \brief Template functor to check whether a scalar has a finite value - * \sa class CwiseUnaryOp, ArrayBase::isfinite() - */ -template<typename Scalar> struct scalar_isfinite_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_isfinite_op) - typedef bool result_type; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { -#if defined(SYCL_DEVICE_ONLY) - return numext::isfinite(a); -#else - return (numext::isfinite)(a); -#endif - } -}; -template<typename Scalar> -struct functor_traits<scalar_isfinite_op<Scalar> > -{ - enum { - Cost = NumTraits<Scalar>::MulCost, - PacketAccess = false - }; -}; - -/** \internal - * \brief Template functor to compute the logical not of a boolean - * - * \sa class CwiseUnaryOp, ArrayBase::operator! - */ -template<typename Scalar> struct scalar_boolean_not_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_not_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a) const { return !a; } -}; -template<typename Scalar> -struct functor_traits<scalar_boolean_not_op<Scalar> > { - enum { - Cost = NumTraits<bool>::AddCost, - PacketAccess = false - }; -}; - -/** \internal - * \brief Template functor to compute the signum of a scalar - * \sa class CwiseUnaryOp, Cwise::sign() - */ -template<typename Scalar,bool iscpx=(NumTraits<Scalar>::IsComplex!=0) > struct scalar_sign_op; -template<typename Scalar> -struct scalar_sign_op<Scalar,false> { - EIGEN_EMPTY_STRUCT_CTOR(scalar_sign_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const - { - return Scalar( (a>Scalar(0)) - (a<Scalar(0)) ); - } - //TODO - //template <typename Packet> - //EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psign(a); } -}; -template<typename Scalar> -struct scalar_sign_op<Scalar,true> { - EIGEN_EMPTY_STRUCT_CTOR(scalar_sign_op) - EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const - { - typedef typename NumTraits<Scalar>::Real real_type; - real_type aa = numext::abs(a); - if (aa==real_type(0)) - return Scalar(0); - aa = real_type(1)/aa; - return Scalar(a.real()*aa, a.imag()*aa ); - } - //TODO - //template <typename Packet> - //EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psign(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_sign_op<Scalar> > -{ enum { - Cost = - NumTraits<Scalar>::IsComplex - ? ( 8*NumTraits<Scalar>::MulCost ) // roughly - : ( 3*NumTraits<Scalar>::AddCost), - PacketAccess = packet_traits<Scalar>::HasSign - }; -}; - -/** \internal - * \brief Template functor to compute the logistic function of a scalar - * \sa class CwiseUnaryOp, ArrayBase::logistic() - */ -template <typename T> -struct scalar_logistic_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_logistic_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const { - const T one = T(1); - return one / (one + numext::exp(-x)); - } - - template <typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Packet packetOp(const Packet& x) const { - const Packet one = pset1<Packet>(T(1)); - return pdiv(one, padd(one, pexp(pnegate(x)))); - } -}; - -#ifndef EIGEN_GPU_COMPILE_PHASE -/** \internal - * \brief Template specialization of the logistic function for float. - * - * Uses just a 9/10-degree rational interpolant which - * interpolates 1/(1+exp(-x)) - 0.5 up to a couple of ulps in the range - * [-9, 18]. Below -9 we use the more accurate approximation - * 1/(1+exp(-x)) ~= exp(x), and above 18 the logistic function is 1 withing - * one ulp. The shifted logistic is interpolated because it was easier to - * make the fit converge. - * - */ -template <> -struct scalar_logistic_op<float> { - EIGEN_EMPTY_STRUCT_CTOR(scalar_logistic_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float operator()(const float& x) const { - // The upper cut-off is the smallest x for which the rational approximation evaluates to 1. - // Choosing this value saves us a few instructions clamping the results at the end. -#ifdef EIGEN_VECTORIZE_FMA - const float cutoff_upper = 15.7243833541870117f; -#else - const float cutoff_upper = 15.6437711715698242f; -#endif - const float cutoff_lower = -9.f; - if (x > cutoff_upper) return 1.0f; - else if (x < cutoff_lower) return numext::exp(x); - else return 1.0f / (1.0f + numext::exp(-x)); - } - - template <typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Packet packetOp(const Packet& _x) const { - const Packet cutoff_lower = pset1<Packet>(-9.f); - const Packet lt_mask = pcmp_lt<Packet>(_x, cutoff_lower); - const bool any_small = predux(lt_mask); - - // Clamp the input to be at most 'cutoff_upper'. -#ifdef EIGEN_VECTORIZE_FMA - const Packet cutoff_upper = pset1<Packet>(15.7243833541870117f); -#else - const Packet cutoff_upper = pset1<Packet>(15.6437711715698242f); -#endif - const Packet x = pmin(_x, cutoff_upper); - - // The monomial coefficients of the numerator polynomial (odd). - const Packet alpha_1 = pset1<Packet>(2.48287947061529e-01f); - const Packet alpha_3 = pset1<Packet>(8.51377133304701e-03f); - const Packet alpha_5 = pset1<Packet>(6.08574864600143e-05f); - const Packet alpha_7 = pset1<Packet>(1.15627324459942e-07f); - const Packet alpha_9 = pset1<Packet>(4.37031012579801e-11f); - - // The monomial coefficients of the denominator polynomial (even). - const Packet beta_0 = pset1<Packet>(9.93151921023180e-01f); - const Packet beta_2 = pset1<Packet>(1.16817656904453e-01f); - const Packet beta_4 = pset1<Packet>(1.70198817374094e-03f); - const Packet beta_6 = pset1<Packet>(6.29106785017040e-06f); - const Packet beta_8 = pset1<Packet>(5.76102136993427e-09f); - const Packet beta_10 = pset1<Packet>(6.10247389755681e-13f); - - // Since the polynomials are odd/even, we need x^2. - const Packet x2 = pmul(x, x); - - // Evaluate the numerator polynomial p. - Packet p = pmadd(x2, alpha_9, alpha_7); - p = pmadd(x2, p, alpha_5); - p = pmadd(x2, p, alpha_3); - p = pmadd(x2, p, alpha_1); - p = pmul(x, p); - - // Evaluate the denominator polynomial q. - Packet q = pmadd(x2, beta_10, beta_8); - q = pmadd(x2, q, beta_6); - q = pmadd(x2, q, beta_4); - q = pmadd(x2, q, beta_2); - q = pmadd(x2, q, beta_0); - // Divide the numerator by the denominator and shift it up. - const Packet logistic = padd(pdiv(p, q), pset1<Packet>(0.5f)); - if (EIGEN_PREDICT_FALSE(any_small)) { - const Packet exponential = pexp(_x); - return pselect(lt_mask, exponential, logistic); - } else { - return logistic; - } - } -}; -#endif // #ifndef EIGEN_GPU_COMPILE_PHASE - -template <typename T> -struct functor_traits<scalar_logistic_op<T> > { - enum { - // The cost estimate for float here here is for the common(?) case where - // all arguments are greater than -9. - Cost = scalar_div_cost<T, packet_traits<T>::HasDiv>::value + - (internal::is_same<T, float>::value - ? NumTraits<T>::AddCost * 15 + NumTraits<T>::MulCost * 11 - : NumTraits<T>::AddCost * 2 + - functor_traits<scalar_exp_op<T> >::Cost), - PacketAccess = - packet_traits<T>::HasAdd && packet_traits<T>::HasDiv && - (internal::is_same<T, float>::value - ? packet_traits<T>::HasMul && packet_traits<T>::HasMax && - packet_traits<T>::HasMin - : packet_traits<T>::HasNegate && packet_traits<T>::HasExp) - }; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_FUNCTORS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h b/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h deleted file mode 100644 index d0dc14db..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h +++ /dev/null @@ -1,2787 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERAL_BLOCK_PANEL_H -#define EIGEN_GENERAL_BLOCK_PANEL_H - - -namespace Eigen { - -namespace internal { - -enum GEBPPacketSizeType { - GEBPPacketFull = 0, - GEBPPacketHalf, - GEBPPacketQuarter -}; - -template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs=false, bool _ConjRhs=false, int Arch=Architecture::Target, int _PacketSize=GEBPPacketFull> -class gebp_traits; - - -/** \internal \returns b if a<=0, and returns a otherwise. */ -inline std::ptrdiff_t manage_caching_sizes_helper(std::ptrdiff_t a, std::ptrdiff_t b) -{ - return a<=0 ? b : a; -} - -#if EIGEN_ARCH_i386_OR_x86_64 -const std::ptrdiff_t defaultL1CacheSize = 32*1024; -const std::ptrdiff_t defaultL2CacheSize = 256*1024; -const std::ptrdiff_t defaultL3CacheSize = 2*1024*1024; -#elif EIGEN_ARCH_PPC -const std::ptrdiff_t defaultL1CacheSize = 64*1024; -const std::ptrdiff_t defaultL2CacheSize = 512*1024; -const std::ptrdiff_t defaultL3CacheSize = 4*1024*1024; -#else -const std::ptrdiff_t defaultL1CacheSize = 16*1024; -const std::ptrdiff_t defaultL2CacheSize = 512*1024; -const std::ptrdiff_t defaultL3CacheSize = 512*1024; -#endif - -/** \internal */ -struct CacheSizes { - CacheSizes(): m_l1(-1),m_l2(-1),m_l3(-1) { - int l1CacheSize, l2CacheSize, l3CacheSize; - queryCacheSizes(l1CacheSize, l2CacheSize, l3CacheSize); - m_l1 = manage_caching_sizes_helper(l1CacheSize, defaultL1CacheSize); - m_l2 = manage_caching_sizes_helper(l2CacheSize, defaultL2CacheSize); - m_l3 = manage_caching_sizes_helper(l3CacheSize, defaultL3CacheSize); - } - - std::ptrdiff_t m_l1; - std::ptrdiff_t m_l2; - std::ptrdiff_t m_l3; -}; - - -/** \internal */ -inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1, std::ptrdiff_t* l2, std::ptrdiff_t* l3) -{ - static CacheSizes m_cacheSizes; - - if(action==SetAction) - { - // set the cpu cache size and cache all block sizes from a global cache size in byte - eigen_internal_assert(l1!=0 && l2!=0); - m_cacheSizes.m_l1 = *l1; - m_cacheSizes.m_l2 = *l2; - m_cacheSizes.m_l3 = *l3; - } - else if(action==GetAction) - { - eigen_internal_assert(l1!=0 && l2!=0); - *l1 = m_cacheSizes.m_l1; - *l2 = m_cacheSizes.m_l2; - *l3 = m_cacheSizes.m_l3; - } - else - { - eigen_internal_assert(false); - } -} - -/* Helper for computeProductBlockingSizes. - * - * Given a m x k times k x n matrix product of scalar types \c LhsScalar and \c RhsScalar, - * this function computes the blocking size parameters along the respective dimensions - * for matrix products and related algorithms. The blocking sizes depends on various - * parameters: - * - the L1 and L2 cache sizes, - * - the register level blocking sizes defined by gebp_traits, - * - the number of scalars that fit into a packet (when vectorization is enabled). - * - * \sa setCpuCacheSizes */ - -template<typename LhsScalar, typename RhsScalar, int KcFactor, typename Index> -void evaluateProductBlockingSizesHeuristic(Index& k, Index& m, Index& n, Index num_threads = 1) -{ - typedef gebp_traits<LhsScalar,RhsScalar> Traits; - - // Explanations: - // Let's recall that the product algorithms form mc x kc vertical panels A' on the lhs and - // kc x nc blocks B' on the rhs. B' has to fit into L2/L3 cache. Moreover, A' is processed - // per mr x kc horizontal small panels where mr is the blocking size along the m dimension - // at the register level. This small horizontal panel has to stay within L1 cache. - std::ptrdiff_t l1, l2, l3; - manage_caching_sizes(GetAction, &l1, &l2, &l3); - #ifdef EIGEN_VECTORIZE_AVX512 - // We need to find a rationale for that, but without this adjustment, - // performance with AVX512 is pretty bad, like -20% slower. - // One reason is that with increasing packet-size, the blocking size k - // has to become pretty small if we want that 1 lhs panel fit within L1. - // For instance, with the 3pX4 kernel and double, the size of the lhs+rhs panels are: - // k*(3*64 + 4*8) Bytes, with l1=32kBytes, and k%8=0, we have k=144. - // This is quite small for a good reuse of the accumulation registers. - l1 *= 4; - #endif - - if (num_threads > 1) { - typedef typename Traits::ResScalar ResScalar; - enum { - kdiv = KcFactor * (Traits::mr * sizeof(LhsScalar) + Traits::nr * sizeof(RhsScalar)), - ksub = Traits::mr * Traits::nr * sizeof(ResScalar), - kr = 8, - mr = Traits::mr, - nr = Traits::nr - }; - // Increasing k gives us more time to prefetch the content of the "C" - // registers. However once the latency is hidden there is no point in - // increasing the value of k, so we'll cap it at 320 (value determined - // experimentally). - const Index k_cache = (numext::mini<Index>)((l1-ksub)/kdiv, 320); - if (k_cache < k) { - k = k_cache - (k_cache % kr); - eigen_internal_assert(k > 0); - } - - const Index n_cache = (l2-l1) / (nr * sizeof(RhsScalar) * k); - const Index n_per_thread = numext::div_ceil(n, num_threads); - if (n_cache <= n_per_thread) { - // Don't exceed the capacity of the l2 cache. - eigen_internal_assert(n_cache >= static_cast<Index>(nr)); - n = n_cache - (n_cache % nr); - eigen_internal_assert(n > 0); - } else { - n = (numext::mini<Index>)(n, (n_per_thread + nr - 1) - ((n_per_thread + nr - 1) % nr)); - } - - if (l3 > l2) { - // l3 is shared between all cores, so we'll give each thread its own chunk of l3. - const Index m_cache = (l3-l2) / (sizeof(LhsScalar) * k * num_threads); - const Index m_per_thread = numext::div_ceil(m, num_threads); - if(m_cache < m_per_thread && m_cache >= static_cast<Index>(mr)) { - m = m_cache - (m_cache % mr); - eigen_internal_assert(m > 0); - } else { - m = (numext::mini<Index>)(m, (m_per_thread + mr - 1) - ((m_per_thread + mr - 1) % mr)); - } - } - } - else { - // In unit tests we do not want to use extra large matrices, - // so we reduce the cache size to check the blocking strategy is not flawed -#ifdef EIGEN_DEBUG_SMALL_PRODUCT_BLOCKS - l1 = 9*1024; - l2 = 32*1024; - l3 = 512*1024; -#endif - - // Early return for small problems because the computation below are time consuming for small problems. - // Perhaps it would make more sense to consider k*n*m?? - // Note that for very tiny problem, this function should be bypassed anyway - // because we use the coefficient-based implementation for them. - if((numext::maxi)(k,(numext::maxi)(m,n))<48) - return; - - typedef typename Traits::ResScalar ResScalar; - enum { - k_peeling = 8, - k_div = KcFactor * (Traits::mr * sizeof(LhsScalar) + Traits::nr * sizeof(RhsScalar)), - k_sub = Traits::mr * Traits::nr * sizeof(ResScalar) - }; - - // ---- 1st level of blocking on L1, yields kc ---- - - // Blocking on the third dimension (i.e., k) is chosen so that an horizontal panel - // of size mr x kc of the lhs plus a vertical panel of kc x nr of the rhs both fits within L1 cache. - // We also include a register-level block of the result (mx x nr). - // (In an ideal world only the lhs panel would stay in L1) - // Moreover, kc has to be a multiple of 8 to be compatible with loop peeling, leading to a maximum blocking size of: - const Index max_kc = numext::maxi<Index>(((l1-k_sub)/k_div) & (~(k_peeling-1)),1); - const Index old_k = k; - if(k>max_kc) - { - // We are really blocking on the third dimension: - // -> reduce blocking size to make sure the last block is as large as possible - // while keeping the same number of sweeps over the result. - k = (k%max_kc)==0 ? max_kc - : max_kc - k_peeling * ((max_kc-1-(k%max_kc))/(k_peeling*(k/max_kc+1))); - - eigen_internal_assert(((old_k/k) == (old_k/max_kc)) && "the number of sweeps has to remain the same"); - } - - // ---- 2nd level of blocking on max(L2,L3), yields nc ---- - - // TODO find a reliable way to get the actual amount of cache per core to use for 2nd level blocking, that is: - // actual_l2 = max(l2, l3/nb_core_sharing_l3) - // The number below is quite conservative: it is better to underestimate the cache size rather than overestimating it) - // For instance, it corresponds to 6MB of L3 shared among 4 cores. - #ifdef EIGEN_DEBUG_SMALL_PRODUCT_BLOCKS - const Index actual_l2 = l3; - #else - const Index actual_l2 = 1572864; // == 1.5 MB - #endif - - // Here, nc is chosen such that a block of kc x nc of the rhs fit within half of L2. - // The second half is implicitly reserved to access the result and lhs coefficients. - // When k<max_kc, then nc can arbitrarily growth. In practice, it seems to be fruitful - // to limit this growth: we bound nc to growth by a factor x1.5. - // However, if the entire lhs block fit within L1, then we are not going to block on the rows at all, - // and it becomes fruitful to keep the packed rhs blocks in L1 if there is enough remaining space. - Index max_nc; - const Index lhs_bytes = m * k * sizeof(LhsScalar); - const Index remaining_l1 = l1- k_sub - lhs_bytes; - if(remaining_l1 >= Index(Traits::nr*sizeof(RhsScalar))*k) - { - // L1 blocking - max_nc = remaining_l1 / (k*sizeof(RhsScalar)); - } - else - { - // L2 blocking - max_nc = (3*actual_l2)/(2*2*max_kc*sizeof(RhsScalar)); - } - // WARNING Below, we assume that Traits::nr is a power of two. - Index nc = numext::mini<Index>(actual_l2/(2*k*sizeof(RhsScalar)), max_nc) & (~(Traits::nr-1)); - if(n>nc) - { - // We are really blocking over the columns: - // -> reduce blocking size to make sure the last block is as large as possible - // while keeping the same number of sweeps over the packed lhs. - // Here we allow one more sweep if this gives us a perfect match, thus the commented "-1" - n = (n%nc)==0 ? nc - : (nc - Traits::nr * ((nc/*-1*/-(n%nc))/(Traits::nr*(n/nc+1)))); - } - else if(old_k==k) - { - // So far, no blocking at all, i.e., kc==k, and nc==n. - // In this case, let's perform a blocking over the rows such that the packed lhs data is kept in cache L1/L2 - // TODO: part of this blocking strategy is now implemented within the kernel itself, so the L1-based heuristic here should be obsolete. - Index problem_size = k*n*sizeof(LhsScalar); - Index actual_lm = actual_l2; - Index max_mc = m; - if(problem_size<=1024) - { - // problem is small enough to keep in L1 - // Let's choose m such that lhs's block fit in 1/3 of L1 - actual_lm = l1; - } - else if(l3!=0 && problem_size<=32768) - { - // we have both L2 and L3, and problem is small enough to be kept in L2 - // Let's choose m such that lhs's block fit in 1/3 of L2 - actual_lm = l2; - max_mc = (numext::mini<Index>)(576,max_mc); - } - Index mc = (numext::mini<Index>)(actual_lm/(3*k*sizeof(LhsScalar)), max_mc); - if (mc > Traits::mr) mc -= mc % Traits::mr; - else if (mc==0) return; - m = (m%mc)==0 ? mc - : (mc - Traits::mr * ((mc/*-1*/-(m%mc))/(Traits::mr*(m/mc+1)))); - } - } -} - -template <typename Index> -inline bool useSpecificBlockingSizes(Index& k, Index& m, Index& n) -{ -#ifdef EIGEN_TEST_SPECIFIC_BLOCKING_SIZES - if (EIGEN_TEST_SPECIFIC_BLOCKING_SIZES) { - k = numext::mini<Index>(k, EIGEN_TEST_SPECIFIC_BLOCKING_SIZE_K); - m = numext::mini<Index>(m, EIGEN_TEST_SPECIFIC_BLOCKING_SIZE_M); - n = numext::mini<Index>(n, EIGEN_TEST_SPECIFIC_BLOCKING_SIZE_N); - return true; - } -#else - EIGEN_UNUSED_VARIABLE(k) - EIGEN_UNUSED_VARIABLE(m) - EIGEN_UNUSED_VARIABLE(n) -#endif - return false; -} - -/** \brief Computes the blocking parameters for a m x k times k x n matrix product - * - * \param[in,out] k Input: the third dimension of the product. Output: the blocking size along the same dimension. - * \param[in,out] m Input: the number of rows of the left hand side. Output: the blocking size along the same dimension. - * \param[in,out] n Input: the number of columns of the right hand side. Output: the blocking size along the same dimension. - * - * Given a m x k times k x n matrix product of scalar types \c LhsScalar and \c RhsScalar, - * this function computes the blocking size parameters along the respective dimensions - * for matrix products and related algorithms. - * - * The blocking size parameters may be evaluated: - * - either by a heuristic based on cache sizes; - * - or using fixed prescribed values (for testing purposes). - * - * \sa setCpuCacheSizes */ - -template<typename LhsScalar, typename RhsScalar, int KcFactor, typename Index> -void computeProductBlockingSizes(Index& k, Index& m, Index& n, Index num_threads = 1) -{ - if (!useSpecificBlockingSizes(k, m, n)) { - evaluateProductBlockingSizesHeuristic<LhsScalar, RhsScalar, KcFactor, Index>(k, m, n, num_threads); - } -} - -template<typename LhsScalar, typename RhsScalar, typename Index> -inline void computeProductBlockingSizes(Index& k, Index& m, Index& n, Index num_threads = 1) -{ - computeProductBlockingSizes<LhsScalar,RhsScalar,1,Index>(k, m, n, num_threads); -} - -#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD - #define CJMADD(CJ,A,B,C,T) C = CJ.pmadd(A,B,C); -#else - - // FIXME (a bit overkill maybe ?) - - template<typename CJ, typename A, typename B, typename C, typename T> struct gebp_madd_selector { - EIGEN_ALWAYS_INLINE static void run(const CJ& cj, A& a, B& b, C& c, T& /*t*/) - { - c = cj.pmadd(a,b,c); - } - }; - - template<typename CJ, typename T> struct gebp_madd_selector<CJ,T,T,T,T> { - EIGEN_ALWAYS_INLINE static void run(const CJ& cj, T& a, T& b, T& c, T& t) - { - t = b; t = cj.pmul(a,t); c = padd(c,t); - } - }; - - template<typename CJ, typename A, typename B, typename C, typename T> - EIGEN_STRONG_INLINE void gebp_madd(const CJ& cj, A& a, B& b, C& c, T& t) - { - gebp_madd_selector<CJ,A,B,C,T>::run(cj,a,b,c,t); - } - - #define CJMADD(CJ,A,B,C,T) gebp_madd(CJ,A,B,C,T); -// #define CJMADD(CJ,A,B,C,T) T = B; T = CJ.pmul(A,T); C = padd(C,T); -#endif - -template <typename RhsPacket, typename RhsPacketx4, int registers_taken> -struct RhsPanelHelper { - private: - static const int remaining_registers = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS - registers_taken; - public: - typedef typename conditional<remaining_registers>=4, RhsPacketx4, RhsPacket>::type type; -}; - -template <typename Packet> -struct QuadPacket -{ - Packet B_0, B1, B2, B3; - const Packet& get(const FixedInt<0>&) const { return B_0; } - const Packet& get(const FixedInt<1>&) const { return B1; } - const Packet& get(const FixedInt<2>&) const { return B2; } - const Packet& get(const FixedInt<3>&) const { return B3; } -}; - -template <int N, typename T1, typename T2, typename T3> -struct packet_conditional { typedef T3 type; }; - -template <typename T1, typename T2, typename T3> -struct packet_conditional<GEBPPacketFull, T1, T2, T3> { typedef T1 type; }; - -template <typename T1, typename T2, typename T3> -struct packet_conditional<GEBPPacketHalf, T1, T2, T3> { typedef T2 type; }; - -#define PACKET_DECL_COND_PREFIX(prefix, name, packet_size) \ - typedef typename packet_conditional<packet_size, \ - typename packet_traits<name ## Scalar>::type, \ - typename packet_traits<name ## Scalar>::half, \ - typename unpacket_traits<typename packet_traits<name ## Scalar>::half>::half>::type \ - prefix ## name ## Packet - -#define PACKET_DECL_COND(name, packet_size) \ - typedef typename packet_conditional<packet_size, \ - typename packet_traits<name ## Scalar>::type, \ - typename packet_traits<name ## Scalar>::half, \ - typename unpacket_traits<typename packet_traits<name ## Scalar>::half>::half>::type \ - name ## Packet - -#define PACKET_DECL_COND_SCALAR_PREFIX(prefix, packet_size) \ - typedef typename packet_conditional<packet_size, \ - typename packet_traits<Scalar>::type, \ - typename packet_traits<Scalar>::half, \ - typename unpacket_traits<typename packet_traits<Scalar>::half>::half>::type \ - prefix ## ScalarPacket - -#define PACKET_DECL_COND_SCALAR(packet_size) \ - typedef typename packet_conditional<packet_size, \ - typename packet_traits<Scalar>::type, \ - typename packet_traits<Scalar>::half, \ - typename unpacket_traits<typename packet_traits<Scalar>::half>::half>::type \ - ScalarPacket - -/* Vectorization logic - * real*real: unpack rhs to constant packets, ... - * - * cd*cd : unpack rhs to (b_r,b_r), (b_i,b_i), mul to get (a_r b_r,a_i b_r) (a_r b_i,a_i b_i), - * storing each res packet into two packets (2x2), - * at the end combine them: swap the second and addsub them - * cf*cf : same but with 2x4 blocks - * cplx*real : unpack rhs to constant packets, ... - * real*cplx : load lhs as (a0,a0,a1,a1), and mul as usual - */ -template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs, bool _ConjRhs, int Arch, int _PacketSize> -class gebp_traits -{ -public: - typedef _LhsScalar LhsScalar; - typedef _RhsScalar RhsScalar; - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - - PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Res, _PacketSize); - - enum { - ConjLhs = _ConjLhs, - ConjRhs = _ConjRhs, - Vectorizable = unpacket_traits<_LhsPacket>::vectorizable && unpacket_traits<_RhsPacket>::vectorizable, - LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1, - RhsPacketSize = Vectorizable ? unpacket_traits<_RhsPacket>::size : 1, - ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1, - - NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS, - - // register block size along the N direction must be 1 or 4 - nr = 4, - - // register block size along the M direction (currently, this one cannot be modified) - default_mr = (EIGEN_PLAIN_ENUM_MIN(16,NumberOfRegisters)/2/nr)*LhsPacketSize, -#if defined(EIGEN_HAS_SINGLE_INSTRUCTION_MADD) && !defined(EIGEN_VECTORIZE_ALTIVEC) && !defined(EIGEN_VECTORIZE_VSX) \ - && ((!EIGEN_COMP_MSVC) || (EIGEN_COMP_MSVC>=1914)) - // we assume 16 registers or more - // See bug 992, if the scalar type is not vectorizable but that EIGEN_HAS_SINGLE_INSTRUCTION_MADD is defined, - // then using 3*LhsPacketSize triggers non-implemented paths in syrk. - // Bug 1515: MSVC prior to v19.14 yields to register spilling. - mr = Vectorizable ? 3*LhsPacketSize : default_mr, -#else - mr = default_mr, -#endif - - LhsProgress = LhsPacketSize, - RhsProgress = 1 - }; - - - typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket; - typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket; - typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket; - typedef LhsPacket LhsPacket4Packing; - - typedef QuadPacket<RhsPacket> RhsPacketx4; - typedef ResPacket AccPacket; - - EIGEN_STRONG_INLINE void initAcc(AccPacket& p) - { - p = pset1<ResPacket>(ResScalar(0)); - } - - template<typename RhsPacketType> - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketType& dest) const - { - dest = pset1<RhsPacketType>(*b); - } - - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const - { - pbroadcast4(b, dest.B_0, dest.B1, dest.B2, dest.B3); - } - - template<typename RhsPacketType> - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacketType& dest) const - { - loadRhs(b, dest); - } - - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const - { - } - - EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const - { - dest = ploadquad<RhsPacket>(b); - } - - template<typename LhsPacketType> - EIGEN_STRONG_INLINE void loadLhs(const LhsScalar* a, LhsPacketType& dest) const - { - dest = pload<LhsPacketType>(a); - } - - template<typename LhsPacketType> - EIGEN_STRONG_INLINE void loadLhsUnaligned(const LhsScalar* a, LhsPacketType& dest) const - { - dest = ploadu<LhsPacketType>(a); - } - - template<typename LhsPacketType, typename RhsPacketType, typename AccPacketType, typename LaneIdType> - EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const LaneIdType&) const - { - conj_helper<LhsPacketType,RhsPacketType,ConjLhs,ConjRhs> cj; - // It would be a lot cleaner to call pmadd all the time. Unfortunately if we - // let gcc allocate the register in which to store the result of the pmul - // (in the case where there is no FMA) gcc fails to figure out how to avoid - // spilling register. -#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD - EIGEN_UNUSED_VARIABLE(tmp); - c = cj.pmadd(a,b,c); -#else - tmp = b; tmp = cj.pmul(a,tmp); c = padd(c,tmp); -#endif - } - - template<typename LhsPacketType, typename AccPacketType, typename LaneIdType> - EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketx4& b, AccPacketType& c, RhsPacket& tmp, const LaneIdType& lane) const - { - madd(a, b.get(lane), c, tmp, lane); - } - - EIGEN_STRONG_INLINE void acc(const AccPacket& c, const ResPacket& alpha, ResPacket& r) const - { - r = pmadd(c,alpha,r); - } - - template<typename ResPacketHalf> - EIGEN_STRONG_INLINE void acc(const ResPacketHalf& c, const ResPacketHalf& alpha, ResPacketHalf& r) const - { - r = pmadd(c,alpha,r); - } - -}; - -template<typename RealScalar, bool _ConjLhs, int Arch, int _PacketSize> -class gebp_traits<std::complex<RealScalar>, RealScalar, _ConjLhs, false, Arch, _PacketSize> -{ -public: - typedef std::complex<RealScalar> LhsScalar; - typedef RealScalar RhsScalar; - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - - PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Res, _PacketSize); - - enum { - ConjLhs = _ConjLhs, - ConjRhs = false, - Vectorizable = unpacket_traits<_LhsPacket>::vectorizable && unpacket_traits<_RhsPacket>::vectorizable, - LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1, - RhsPacketSize = Vectorizable ? unpacket_traits<_RhsPacket>::size : 1, - ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1, - - NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS, - nr = 4, -#if defined(EIGEN_HAS_SINGLE_INSTRUCTION_MADD) && !defined(EIGEN_VECTORIZE_ALTIVEC) && !defined(EIGEN_VECTORIZE_VSX) - // we assume 16 registers - mr = 3*LhsPacketSize, -#else - mr = (EIGEN_PLAIN_ENUM_MIN(16,NumberOfRegisters)/2/nr)*LhsPacketSize, -#endif - - LhsProgress = LhsPacketSize, - RhsProgress = 1 - }; - - typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket; - typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket; - typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket; - typedef LhsPacket LhsPacket4Packing; - - typedef QuadPacket<RhsPacket> RhsPacketx4; - - typedef ResPacket AccPacket; - - EIGEN_STRONG_INLINE void initAcc(AccPacket& p) - { - p = pset1<ResPacket>(ResScalar(0)); - } - - template<typename RhsPacketType> - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketType& dest) const - { - dest = pset1<RhsPacketType>(*b); - } - - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const - { - pbroadcast4(b, dest.B_0, dest.B1, dest.B2, dest.B3); - } - - template<typename RhsPacketType> - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacketType& dest) const - { - loadRhs(b, dest); - } - - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const - {} - - EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const - { - loadRhsQuad_impl(b,dest, typename conditional<RhsPacketSize==16,true_type,false_type>::type()); - } - - EIGEN_STRONG_INLINE void loadRhsQuad_impl(const RhsScalar* b, RhsPacket& dest, const true_type&) const - { - // FIXME we can do better! - // what we want here is a ploadheight - RhsScalar tmp[4] = {b[0],b[0],b[1],b[1]}; - dest = ploadquad<RhsPacket>(tmp); - } - - EIGEN_STRONG_INLINE void loadRhsQuad_impl(const RhsScalar* b, RhsPacket& dest, const false_type&) const - { - eigen_internal_assert(RhsPacketSize<=8); - dest = pset1<RhsPacket>(*b); - } - - EIGEN_STRONG_INLINE void loadLhs(const LhsScalar* a, LhsPacket& dest) const - { - dest = pload<LhsPacket>(a); - } - - template<typename LhsPacketType> - EIGEN_STRONG_INLINE void loadLhsUnaligned(const LhsScalar* a, LhsPacketType& dest) const - { - dest = ploadu<LhsPacketType>(a); - } - - template <typename LhsPacketType, typename RhsPacketType, typename AccPacketType, typename LaneIdType> - EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const LaneIdType&) const - { - madd_impl(a, b, c, tmp, typename conditional<Vectorizable,true_type,false_type>::type()); - } - - template <typename LhsPacketType, typename RhsPacketType, typename AccPacketType> - EIGEN_STRONG_INLINE void madd_impl(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const true_type&) const - { -#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD - EIGEN_UNUSED_VARIABLE(tmp); - c.v = pmadd(a.v,b,c.v); -#else - tmp = b; tmp = pmul(a.v,tmp); c.v = padd(c.v,tmp); -#endif - } - - EIGEN_STRONG_INLINE void madd_impl(const LhsScalar& a, const RhsScalar& b, ResScalar& c, RhsScalar& /*tmp*/, const false_type&) const - { - c += a * b; - } - - template<typename LhsPacketType, typename AccPacketType, typename LaneIdType> - EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketx4& b, AccPacketType& c, RhsPacket& tmp, const LaneIdType& lane) const - { - madd(a, b.get(lane), c, tmp, lane); - } - - template <typename ResPacketType, typename AccPacketType> - EIGEN_STRONG_INLINE void acc(const AccPacketType& c, const ResPacketType& alpha, ResPacketType& r) const - { - conj_helper<ResPacketType,ResPacketType,ConjLhs,false> cj; - r = cj.pmadd(c,alpha,r); - } - -protected: -}; - -template<typename Packet> -struct DoublePacket -{ - Packet first; - Packet second; -}; - -template<typename Packet> -DoublePacket<Packet> padd(const DoublePacket<Packet> &a, const DoublePacket<Packet> &b) -{ - DoublePacket<Packet> res; - res.first = padd(a.first, b.first); - res.second = padd(a.second,b.second); - return res; -} - -// note that for DoublePacket<RealPacket> the "4" in "downto4" -// corresponds to the number of complexes, so it means "8" -// it terms of real coefficients. - -template<typename Packet> -const DoublePacket<Packet>& -predux_half_dowto4(const DoublePacket<Packet> &a, - typename enable_if<unpacket_traits<Packet>::size<=8>::type* = 0) -{ - return a; -} - -template<typename Packet> -DoublePacket<typename unpacket_traits<Packet>::half> -predux_half_dowto4(const DoublePacket<Packet> &a, - typename enable_if<unpacket_traits<Packet>::size==16>::type* = 0) -{ - // yes, that's pretty hackish :( - DoublePacket<typename unpacket_traits<Packet>::half> res; - typedef std::complex<typename unpacket_traits<Packet>::type> Cplx; - typedef typename packet_traits<Cplx>::type CplxPacket; - res.first = predux_half_dowto4(CplxPacket(a.first)).v; - res.second = predux_half_dowto4(CplxPacket(a.second)).v; - return res; -} - -// same here, "quad" actually means "8" in terms of real coefficients -template<typename Scalar, typename RealPacket> -void loadQuadToDoublePacket(const Scalar* b, DoublePacket<RealPacket>& dest, - typename enable_if<unpacket_traits<RealPacket>::size<=8>::type* = 0) -{ - dest.first = pset1<RealPacket>(numext::real(*b)); - dest.second = pset1<RealPacket>(numext::imag(*b)); -} - -template<typename Scalar, typename RealPacket> -void loadQuadToDoublePacket(const Scalar* b, DoublePacket<RealPacket>& dest, - typename enable_if<unpacket_traits<RealPacket>::size==16>::type* = 0) -{ - // yes, that's pretty hackish too :( - typedef typename NumTraits<Scalar>::Real RealScalar; - RealScalar r[4] = {numext::real(b[0]), numext::real(b[0]), numext::real(b[1]), numext::real(b[1])}; - RealScalar i[4] = {numext::imag(b[0]), numext::imag(b[0]), numext::imag(b[1]), numext::imag(b[1])}; - dest.first = ploadquad<RealPacket>(r); - dest.second = ploadquad<RealPacket>(i); -} - - -template<typename Packet> struct unpacket_traits<DoublePacket<Packet> > { - typedef DoublePacket<typename unpacket_traits<Packet>::half> half; -}; -// template<typename Packet> -// DoublePacket<Packet> pmadd(const DoublePacket<Packet> &a, const DoublePacket<Packet> &b) -// { -// DoublePacket<Packet> res; -// res.first = padd(a.first, b.first); -// res.second = padd(a.second,b.second); -// return res; -// } - -template<typename RealScalar, bool _ConjLhs, bool _ConjRhs, int Arch, int _PacketSize> -class gebp_traits<std::complex<RealScalar>, std::complex<RealScalar>, _ConjLhs, _ConjRhs, Arch, _PacketSize > -{ -public: - typedef std::complex<RealScalar> Scalar; - typedef std::complex<RealScalar> LhsScalar; - typedef std::complex<RealScalar> RhsScalar; - typedef std::complex<RealScalar> ResScalar; - - PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Res, _PacketSize); - PACKET_DECL_COND(Real, _PacketSize); - PACKET_DECL_COND_SCALAR(_PacketSize); - - enum { - ConjLhs = _ConjLhs, - ConjRhs = _ConjRhs, - Vectorizable = unpacket_traits<RealPacket>::vectorizable - && unpacket_traits<ScalarPacket>::vectorizable, - ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1, - LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1, - RhsPacketSize = Vectorizable ? unpacket_traits<RhsScalar>::size : 1, - RealPacketSize = Vectorizable ? unpacket_traits<RealPacket>::size : 1, - - // FIXME: should depend on NumberOfRegisters - nr = 4, - mr = ResPacketSize, - - LhsProgress = ResPacketSize, - RhsProgress = 1 - }; - - typedef DoublePacket<RealPacket> DoublePacketType; - - typedef typename conditional<Vectorizable,ScalarPacket,Scalar>::type LhsPacket4Packing; - typedef typename conditional<Vectorizable,RealPacket, Scalar>::type LhsPacket; - typedef typename conditional<Vectorizable,DoublePacketType,Scalar>::type RhsPacket; - typedef typename conditional<Vectorizable,ScalarPacket,Scalar>::type ResPacket; - typedef typename conditional<Vectorizable,DoublePacketType,Scalar>::type AccPacket; - - // this actualy holds 8 packets! - typedef QuadPacket<RhsPacket> RhsPacketx4; - - EIGEN_STRONG_INLINE void initAcc(Scalar& p) { p = Scalar(0); } - - EIGEN_STRONG_INLINE void initAcc(DoublePacketType& p) - { - p.first = pset1<RealPacket>(RealScalar(0)); - p.second = pset1<RealPacket>(RealScalar(0)); - } - - // Scalar path - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, ScalarPacket& dest) const - { - dest = pset1<ScalarPacket>(*b); - } - - // Vectorized path - template<typename RealPacketType> - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, DoublePacket<RealPacketType>& dest) const - { - dest.first = pset1<RealPacketType>(numext::real(*b)); - dest.second = pset1<RealPacketType>(numext::imag(*b)); - } - - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const - { - loadRhs(b, dest.B_0); - loadRhs(b + 1, dest.B1); - loadRhs(b + 2, dest.B2); - loadRhs(b + 3, dest.B3); - } - - // Scalar path - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, ScalarPacket& dest) const - { - loadRhs(b, dest); - } - - // Vectorized path - template<typename RealPacketType> - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, DoublePacket<RealPacketType>& dest) const - { - loadRhs(b, dest); - } - - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const {} - - EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, ResPacket& dest) const - { - loadRhs(b,dest); - } - EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, DoublePacketType& dest) const - { - loadQuadToDoublePacket(b,dest); - } - - // nothing special here - EIGEN_STRONG_INLINE void loadLhs(const LhsScalar* a, LhsPacket& dest) const - { - dest = pload<LhsPacket>((const typename unpacket_traits<LhsPacket>::type*)(a)); - } - - template<typename LhsPacketType> - EIGEN_STRONG_INLINE void loadLhsUnaligned(const LhsScalar* a, LhsPacketType& dest) const - { - dest = ploadu<LhsPacketType>((const typename unpacket_traits<LhsPacketType>::type*)(a)); - } - - template<typename LhsPacketType, typename RhsPacketType, typename ResPacketType, typename TmpType, typename LaneIdType> - EIGEN_STRONG_INLINE - typename enable_if<!is_same<RhsPacketType,RhsPacketx4>::value>::type - madd(const LhsPacketType& a, const RhsPacketType& b, DoublePacket<ResPacketType>& c, TmpType& /*tmp*/, const LaneIdType&) const - { - c.first = padd(pmul(a,b.first), c.first); - c.second = padd(pmul(a,b.second),c.second); - } - - template<typename LaneIdType> - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacket& b, ResPacket& c, RhsPacket& /*tmp*/, const LaneIdType&) const - { - c = cj.pmadd(a,b,c); - } - - template<typename LhsPacketType, typename AccPacketType, typename LaneIdType> - EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketx4& b, AccPacketType& c, RhsPacket& tmp, const LaneIdType& lane) const - { - madd(a, b.get(lane), c, tmp, lane); - } - - EIGEN_STRONG_INLINE void acc(const Scalar& c, const Scalar& alpha, Scalar& r) const { r += alpha * c; } - - template<typename RealPacketType, typename ResPacketType> - EIGEN_STRONG_INLINE void acc(const DoublePacket<RealPacketType>& c, const ResPacketType& alpha, ResPacketType& r) const - { - // assemble c - ResPacketType tmp; - if((!ConjLhs)&&(!ConjRhs)) - { - tmp = pcplxflip(pconj(ResPacketType(c.second))); - tmp = padd(ResPacketType(c.first),tmp); - } - else if((!ConjLhs)&&(ConjRhs)) - { - tmp = pconj(pcplxflip(ResPacketType(c.second))); - tmp = padd(ResPacketType(c.first),tmp); - } - else if((ConjLhs)&&(!ConjRhs)) - { - tmp = pcplxflip(ResPacketType(c.second)); - tmp = padd(pconj(ResPacketType(c.first)),tmp); - } - else if((ConjLhs)&&(ConjRhs)) - { - tmp = pcplxflip(ResPacketType(c.second)); - tmp = psub(pconj(ResPacketType(c.first)),tmp); - } - - r = pmadd(tmp,alpha,r); - } - -protected: - conj_helper<LhsScalar,RhsScalar,ConjLhs,ConjRhs> cj; -}; - -template<typename RealScalar, bool _ConjRhs, int Arch, int _PacketSize> -class gebp_traits<RealScalar, std::complex<RealScalar>, false, _ConjRhs, Arch, _PacketSize > -{ -public: - typedef std::complex<RealScalar> Scalar; - typedef RealScalar LhsScalar; - typedef Scalar RhsScalar; - typedef Scalar ResScalar; - - PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Res, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Real, _PacketSize); - PACKET_DECL_COND_SCALAR_PREFIX(_, _PacketSize); - -#undef PACKET_DECL_COND_SCALAR_PREFIX -#undef PACKET_DECL_COND_PREFIX -#undef PACKET_DECL_COND_SCALAR -#undef PACKET_DECL_COND - - enum { - ConjLhs = false, - ConjRhs = _ConjRhs, - Vectorizable = unpacket_traits<_RealPacket>::vectorizable - && unpacket_traits<_ScalarPacket>::vectorizable, - LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1, - RhsPacketSize = Vectorizable ? unpacket_traits<_RhsPacket>::size : 1, - ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1, - - NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS, - // FIXME: should depend on NumberOfRegisters - nr = 4, - mr = (EIGEN_PLAIN_ENUM_MIN(16,NumberOfRegisters)/2/nr)*ResPacketSize, - - LhsProgress = ResPacketSize, - RhsProgress = 1 - }; - - typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket; - typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket; - typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket; - typedef LhsPacket LhsPacket4Packing; - typedef QuadPacket<RhsPacket> RhsPacketx4; - typedef ResPacket AccPacket; - - EIGEN_STRONG_INLINE void initAcc(AccPacket& p) - { - p = pset1<ResPacket>(ResScalar(0)); - } - - template<typename RhsPacketType> - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketType& dest) const - { - dest = pset1<RhsPacketType>(*b); - } - - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const - { - pbroadcast4(b, dest.B_0, dest.B1, dest.B2, dest.B3); - } - - template<typename RhsPacketType> - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacketType& dest) const - { - loadRhs(b, dest); - } - - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const - {} - - EIGEN_STRONG_INLINE void loadLhs(const LhsScalar* a, LhsPacket& dest) const - { - dest = ploaddup<LhsPacket>(a); - } - - EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const - { - dest = ploadquad<RhsPacket>(b); - } - - template<typename LhsPacketType> - EIGEN_STRONG_INLINE void loadLhsUnaligned(const LhsScalar* a, LhsPacketType& dest) const - { - dest = ploaddup<LhsPacketType>(a); - } - - template <typename LhsPacketType, typename RhsPacketType, typename AccPacketType, typename LaneIdType> - EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const LaneIdType&) const - { - madd_impl(a, b, c, tmp, typename conditional<Vectorizable,true_type,false_type>::type()); - } - - template <typename LhsPacketType, typename RhsPacketType, typename AccPacketType> - EIGEN_STRONG_INLINE void madd_impl(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const true_type&) const - { -#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD - EIGEN_UNUSED_VARIABLE(tmp); - c.v = pmadd(a,b.v,c.v); -#else - tmp = b; tmp.v = pmul(a,tmp.v); c = padd(c,tmp); -#endif - - } - - EIGEN_STRONG_INLINE void madd_impl(const LhsScalar& a, const RhsScalar& b, ResScalar& c, RhsScalar& /*tmp*/, const false_type&) const - { - c += a * b; - } - - template<typename LhsPacketType, typename AccPacketType, typename LaneIdType> - EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketx4& b, AccPacketType& c, RhsPacket& tmp, const LaneIdType& lane) const - { - madd(a, b.get(lane), c, tmp, lane); - } - - template <typename ResPacketType, typename AccPacketType> - EIGEN_STRONG_INLINE void acc(const AccPacketType& c, const ResPacketType& alpha, ResPacketType& r) const - { - conj_helper<ResPacketType,ResPacketType,false,ConjRhs> cj; - r = cj.pmadd(alpha,c,r); - } - -protected: - -}; - - -#if EIGEN_ARCH_ARM64 && defined EIGEN_VECTORIZE_NEON - -template<> -struct gebp_traits <float, float, false, false,Architecture::NEON,GEBPPacketFull> - : gebp_traits<float,float,false,false,Architecture::Generic,GEBPPacketFull> -{ - typedef float RhsPacket; - - typedef float32x4_t RhsPacketx4; - - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacket& dest) const - { - dest = *b; - } - - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const - { - dest = vld1q_f32(b); - } - - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacket& dest) const - { - dest = *b; - } - - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacketx4& dest) const - {} - - EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const - { - loadRhs(b,dest); - } - - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacket& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<0>&) const - { - c = vfmaq_n_f32(c, a, b); - } - - // NOTE: Template parameter inference failed when compiled with Android NDK: - // "candidate template ignored: could not match 'FixedInt<N>' against 'Eigen::internal::FixedInt<0>". - - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<0>&) const - { madd_helper<0>(a, b, c); } - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<1>&) const - { madd_helper<1>(a, b, c); } - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<2>&) const - { madd_helper<2>(a, b, c); } - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<3>&) const - { madd_helper<3>(a, b, c); } - - private: - template<int LaneID> - EIGEN_STRONG_INLINE void madd_helper(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c) const - { - #if EIGEN_COMP_GNUC_STRICT && !(EIGEN_GNUC_AT_LEAST(9,0)) - // workaround gcc issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89101 - // vfmaq_laneq_f32 is implemented through a costly dup - if(LaneID==0) asm("fmla %0.4s, %1.4s, %2.s[0]\n" : "+w" (c) : "w" (a), "w" (b) : ); - else if(LaneID==1) asm("fmla %0.4s, %1.4s, %2.s[1]\n" : "+w" (c) : "w" (a), "w" (b) : ); - else if(LaneID==2) asm("fmla %0.4s, %1.4s, %2.s[2]\n" : "+w" (c) : "w" (a), "w" (b) : ); - else if(LaneID==3) asm("fmla %0.4s, %1.4s, %2.s[3]\n" : "+w" (c) : "w" (a), "w" (b) : ); - #else - c = vfmaq_laneq_f32(c, a, b, LaneID); - #endif - } -}; - - -template<> -struct gebp_traits <double, double, false, false,Architecture::NEON> - : gebp_traits<double,double,false,false,Architecture::Generic> -{ - typedef double RhsPacket; - - struct RhsPacketx4 { - float64x2_t B_0, B_1; - }; - - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacket& dest) const - { - dest = *b; - } - - EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const - { - dest.B_0 = vld1q_f64(b); - dest.B_1 = vld1q_f64(b+2); - } - - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacket& dest) const - { - loadRhs(b,dest); - } - - EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacketx4& dest) const - {} - - EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const - { - loadRhs(b,dest); - } - - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacket& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<0>&) const - { - c = vfmaq_n_f64(c, a, b); - } - - // NOTE: Template parameter inference failed when compiled with Android NDK: - // "candidate template ignored: could not match 'FixedInt<N>' against 'Eigen::internal::FixedInt<0>". - - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<0>&) const - { madd_helper<0>(a, b, c); } - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<1>&) const - { madd_helper<1>(a, b, c); } - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<2>&) const - { madd_helper<2>(a, b, c); } - EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<3>&) const - { madd_helper<3>(a, b, c); } - - private: - template <int LaneID> - EIGEN_STRONG_INLINE void madd_helper(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c) const - { - #if EIGEN_COMP_GNUC_STRICT && !(EIGEN_GNUC_AT_LEAST(9,0)) - // workaround gcc issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89101 - // vfmaq_laneq_f64 is implemented through a costly dup - if(LaneID==0) asm("fmla %0.2d, %1.2d, %2.d[0]\n" : "+w" (c) : "w" (a), "w" (b.B_0) : ); - else if(LaneID==1) asm("fmla %0.2d, %1.2d, %2.d[1]\n" : "+w" (c) : "w" (a), "w" (b.B_0) : ); - else if(LaneID==2) asm("fmla %0.2d, %1.2d, %2.d[0]\n" : "+w" (c) : "w" (a), "w" (b.B_1) : ); - else if(LaneID==3) asm("fmla %0.2d, %1.2d, %2.d[1]\n" : "+w" (c) : "w" (a), "w" (b.B_1) : ); - #else - if(LaneID==0) c = vfmaq_laneq_f64(c, a, b.B_0, 0); - else if(LaneID==1) c = vfmaq_laneq_f64(c, a, b.B_0, 1); - else if(LaneID==2) c = vfmaq_laneq_f64(c, a, b.B_1, 0); - else if(LaneID==3) c = vfmaq_laneq_f64(c, a, b.B_1, 1); - #endif - } -}; - -#endif - -/* optimized General packed Block * packed Panel product kernel - * - * Mixing type logic: C += A * B - * | A | B | comments - * |real |cplx | no vectorization yet, would require to pack A with duplication - * |cplx |real | easy vectorization - */ -template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs> -struct gebp_kernel -{ - typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target> Traits; - typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target,GEBPPacketHalf> HalfTraits; - typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target,GEBPPacketQuarter> QuarterTraits; - - typedef typename Traits::ResScalar ResScalar; - typedef typename Traits::LhsPacket LhsPacket; - typedef typename Traits::RhsPacket RhsPacket; - typedef typename Traits::ResPacket ResPacket; - typedef typename Traits::AccPacket AccPacket; - typedef typename Traits::RhsPacketx4 RhsPacketx4; - - typedef typename RhsPanelHelper<RhsPacket, RhsPacketx4, 15>::type RhsPanel15; - - typedef gebp_traits<RhsScalar,LhsScalar,ConjugateRhs,ConjugateLhs,Architecture::Target> SwappedTraits; - - typedef typename SwappedTraits::ResScalar SResScalar; - typedef typename SwappedTraits::LhsPacket SLhsPacket; - typedef typename SwappedTraits::RhsPacket SRhsPacket; - typedef typename SwappedTraits::ResPacket SResPacket; - typedef typename SwappedTraits::AccPacket SAccPacket; - - typedef typename HalfTraits::LhsPacket LhsPacketHalf; - typedef typename HalfTraits::RhsPacket RhsPacketHalf; - typedef typename HalfTraits::ResPacket ResPacketHalf; - typedef typename HalfTraits::AccPacket AccPacketHalf; - - typedef typename QuarterTraits::LhsPacket LhsPacketQuarter; - typedef typename QuarterTraits::RhsPacket RhsPacketQuarter; - typedef typename QuarterTraits::ResPacket ResPacketQuarter; - typedef typename QuarterTraits::AccPacket AccPacketQuarter; - - typedef typename DataMapper::LinearMapper LinearMapper; - - enum { - Vectorizable = Traits::Vectorizable, - LhsProgress = Traits::LhsProgress, - LhsProgressHalf = HalfTraits::LhsProgress, - LhsProgressQuarter = QuarterTraits::LhsProgress, - RhsProgress = Traits::RhsProgress, - RhsProgressHalf = HalfTraits::RhsProgress, - RhsProgressQuarter = QuarterTraits::RhsProgress, - ResPacketSize = Traits::ResPacketSize - }; - - EIGEN_DONT_INLINE - void operator()(const DataMapper& res, const LhsScalar* blockA, const RhsScalar* blockB, - Index rows, Index depth, Index cols, ResScalar alpha, - Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0); -}; - -template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs, -int SwappedLhsProgress = gebp_traits<RhsScalar,LhsScalar,ConjugateRhs,ConjugateLhs,Architecture::Target>::LhsProgress> -struct last_row_process_16_packets -{ - typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target> Traits; - typedef gebp_traits<RhsScalar,LhsScalar,ConjugateRhs,ConjugateLhs,Architecture::Target> SwappedTraits; - - typedef typename Traits::ResScalar ResScalar; - typedef typename SwappedTraits::LhsPacket SLhsPacket; - typedef typename SwappedTraits::RhsPacket SRhsPacket; - typedef typename SwappedTraits::ResPacket SResPacket; - typedef typename SwappedTraits::AccPacket SAccPacket; - - EIGEN_STRONG_INLINE void operator()(const DataMapper& res, SwappedTraits &straits, const LhsScalar* blA, - const RhsScalar* blB, Index depth, const Index endk, Index i, Index j2, - ResScalar alpha, SAccPacket &C0) - { - EIGEN_UNUSED_VARIABLE(res); - EIGEN_UNUSED_VARIABLE(straits); - EIGEN_UNUSED_VARIABLE(blA); - EIGEN_UNUSED_VARIABLE(blB); - EIGEN_UNUSED_VARIABLE(depth); - EIGEN_UNUSED_VARIABLE(endk); - EIGEN_UNUSED_VARIABLE(i); - EIGEN_UNUSED_VARIABLE(j2); - EIGEN_UNUSED_VARIABLE(alpha); - EIGEN_UNUSED_VARIABLE(C0); - } -}; - - -template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs> -struct last_row_process_16_packets<LhsScalar, RhsScalar, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs, 16> { - typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target> Traits; - typedef gebp_traits<RhsScalar,LhsScalar,ConjugateRhs,ConjugateLhs,Architecture::Target> SwappedTraits; - - typedef typename Traits::ResScalar ResScalar; - typedef typename SwappedTraits::LhsPacket SLhsPacket; - typedef typename SwappedTraits::RhsPacket SRhsPacket; - typedef typename SwappedTraits::ResPacket SResPacket; - typedef typename SwappedTraits::AccPacket SAccPacket; - - EIGEN_STRONG_INLINE void operator()(const DataMapper& res, SwappedTraits &straits, const LhsScalar* blA, - const RhsScalar* blB, Index depth, const Index endk, Index i, Index j2, - ResScalar alpha, SAccPacket &C0) - { - typedef typename unpacket_traits<typename unpacket_traits<SResPacket>::half>::half SResPacketQuarter; - typedef typename unpacket_traits<typename unpacket_traits<SLhsPacket>::half>::half SLhsPacketQuarter; - typedef typename unpacket_traits<typename unpacket_traits<SRhsPacket>::half>::half SRhsPacketQuarter; - typedef typename unpacket_traits<typename unpacket_traits<SAccPacket>::half>::half SAccPacketQuarter; - - SResPacketQuarter R = res.template gatherPacket<SResPacketQuarter>(i, j2); - SResPacketQuarter alphav = pset1<SResPacketQuarter>(alpha); - - if (depth - endk > 0) - { - // We have to handle the last row(s) of the rhs, which - // correspond to a half-packet - SAccPacketQuarter c0 = predux_half_dowto4(predux_half_dowto4(C0)); - - for (Index kk = endk; kk < depth; kk++) - { - SLhsPacketQuarter a0; - SRhsPacketQuarter b0; - straits.loadLhsUnaligned(blB, a0); - straits.loadRhs(blA, b0); - straits.madd(a0,b0,c0,b0, fix<0>); - blB += SwappedTraits::LhsProgress/4; - blA += 1; - } - straits.acc(c0, alphav, R); - } - else - { - straits.acc(predux_half_dowto4(predux_half_dowto4(C0)), alphav, R); - } - res.scatterPacket(i, j2, R); - } -}; - -template<int nr, Index LhsProgress, Index RhsProgress, typename LhsScalar, typename RhsScalar, typename ResScalar, typename AccPacket, typename LhsPacket, typename RhsPacket, typename ResPacket, typename GEBPTraits, typename LinearMapper, typename DataMapper> -struct lhs_process_one_packet -{ - typedef typename GEBPTraits::RhsPacketx4 RhsPacketx4; - - EIGEN_STRONG_INLINE void peeled_kc_onestep(Index K, const LhsScalar* blA, const RhsScalar* blB, GEBPTraits traits, LhsPacket *A0, RhsPacketx4 *rhs_panel, RhsPacket *T0, AccPacket *C0, AccPacket *C1, AccPacket *C2, AccPacket *C3) - { - EIGEN_ASM_COMMENT("begin step of gebp micro kernel 1X4"); - EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); - traits.loadLhs(&blA[(0+1*K)*LhsProgress], *A0); - traits.loadRhs(&blB[(0+4*K)*RhsProgress], *rhs_panel); - traits.madd(*A0, *rhs_panel, *C0, *T0, fix<0>); - traits.madd(*A0, *rhs_panel, *C1, *T0, fix<1>); - traits.madd(*A0, *rhs_panel, *C2, *T0, fix<2>); - traits.madd(*A0, *rhs_panel, *C3, *T0, fix<3>); - #if EIGEN_GNUC_AT_LEAST(6,0) && defined(EIGEN_VECTORIZE_SSE) - __asm__ ("" : "+x,m" (*A0)); - #endif - EIGEN_ASM_COMMENT("end step of gebp micro kernel 1X4"); - } - - EIGEN_STRONG_INLINE void operator()( - const DataMapper& res, const LhsScalar* blockA, const RhsScalar* blockB, ResScalar alpha, - Index peelStart, Index peelEnd, Index strideA, Index strideB, Index offsetA, Index offsetB, - int prefetch_res_offset, Index peeled_kc, Index pk, Index cols, Index depth, Index packet_cols4) - { - GEBPTraits traits; - - // loops on each largest micro horizontal panel of lhs - // (LhsProgress x depth) - for(Index i=peelStart; i<peelEnd; i+=LhsProgress) - { - // loops on each largest micro vertical panel of rhs (depth * nr) - for(Index j2=0; j2<packet_cols4; j2+=nr) - { - // We select a LhsProgress x nr micro block of res - // which is entirely stored into 1 x nr registers. - - const LhsScalar* blA = &blockA[i*strideA+offsetA*(LhsProgress)]; - prefetch(&blA[0]); - - // gets res block as register - AccPacket C0, C1, C2, C3; - traits.initAcc(C0); - traits.initAcc(C1); - traits.initAcc(C2); - traits.initAcc(C3); - // To improve instruction pipelining, let's double the accumulation registers: - // even k will accumulate in C*, while odd k will accumulate in D*. - // This trick is crutial to get good performance with FMA, otherwise it is - // actually faster to perform separated MUL+ADD because of a naturally - // better instruction-level parallelism. - AccPacket D0, D1, D2, D3; - traits.initAcc(D0); - traits.initAcc(D1); - traits.initAcc(D2); - traits.initAcc(D3); - - LinearMapper r0 = res.getLinearMapper(i, j2 + 0); - LinearMapper r1 = res.getLinearMapper(i, j2 + 1); - LinearMapper r2 = res.getLinearMapper(i, j2 + 2); - LinearMapper r3 = res.getLinearMapper(i, j2 + 3); - - r0.prefetch(prefetch_res_offset); - r1.prefetch(prefetch_res_offset); - r2.prefetch(prefetch_res_offset); - r3.prefetch(prefetch_res_offset); - - // performs "inner" products - const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr]; - prefetch(&blB[0]); - LhsPacket A0, A1; - - for(Index k=0; k<peeled_kc; k+=pk) - { - EIGEN_ASM_COMMENT("begin gebp micro kernel 1/half/quarterX4"); - RhsPacketx4 rhs_panel; - RhsPacket T0; - - internal::prefetch(blB+(48+0)); - peeled_kc_onestep(0, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3); - peeled_kc_onestep(1, blA, blB, traits, &A1, &rhs_panel, &T0, &D0, &D1, &D2, &D3); - peeled_kc_onestep(2, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3); - peeled_kc_onestep(3, blA, blB, traits, &A1, &rhs_panel, &T0, &D0, &D1, &D2, &D3); - internal::prefetch(blB+(48+16)); - peeled_kc_onestep(4, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3); - peeled_kc_onestep(5, blA, blB, traits, &A1, &rhs_panel, &T0, &D0, &D1, &D2, &D3); - peeled_kc_onestep(6, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3); - peeled_kc_onestep(7, blA, blB, traits, &A1, &rhs_panel, &T0, &D0, &D1, &D2, &D3); - - blB += pk*4*RhsProgress; - blA += pk*LhsProgress; - - EIGEN_ASM_COMMENT("end gebp micro kernel 1/half/quarterX4"); - } - C0 = padd(C0,D0); - C1 = padd(C1,D1); - C2 = padd(C2,D2); - C3 = padd(C3,D3); - - // process remaining peeled loop - for(Index k=peeled_kc; k<depth; k++) - { - RhsPacketx4 rhs_panel; - RhsPacket T0; - peeled_kc_onestep(0, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3); - blB += 4*RhsProgress; - blA += LhsProgress; - } - - ResPacket R0, R1; - ResPacket alphav = pset1<ResPacket>(alpha); - - R0 = r0.template loadPacket<ResPacket>(0); - R1 = r1.template loadPacket<ResPacket>(0); - traits.acc(C0, alphav, R0); - traits.acc(C1, alphav, R1); - r0.storePacket(0, R0); - r1.storePacket(0, R1); - - R0 = r2.template loadPacket<ResPacket>(0); - R1 = r3.template loadPacket<ResPacket>(0); - traits.acc(C2, alphav, R0); - traits.acc(C3, alphav, R1); - r2.storePacket(0, R0); - r3.storePacket(0, R1); - } - - // Deal with remaining columns of the rhs - for(Index j2=packet_cols4; j2<cols; j2++) - { - // One column at a time - const LhsScalar* blA = &blockA[i*strideA+offsetA*(LhsProgress)]; - prefetch(&blA[0]); - - // gets res block as register - AccPacket C0; - traits.initAcc(C0); - - LinearMapper r0 = res.getLinearMapper(i, j2); - - // performs "inner" products - const RhsScalar* blB = &blockB[j2*strideB+offsetB]; - LhsPacket A0; - - for(Index k= 0; k<peeled_kc; k+=pk) - { - EIGEN_ASM_COMMENT("begin gebp micro kernel 1/half/quarterX1"); - RhsPacket B_0; - -#define EIGEN_GEBGP_ONESTEP(K) \ - do { \ - EIGEN_ASM_COMMENT("begin step of gebp micro kernel 1/half/quarterX1"); \ - EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); \ - /* FIXME: why unaligned???? */ \ - traits.loadLhsUnaligned(&blA[(0+1*K)*LhsProgress], A0); \ - traits.loadRhs(&blB[(0+K)*RhsProgress], B_0); \ - traits.madd(A0, B_0, C0, B_0, fix<0>); \ - EIGEN_ASM_COMMENT("end step of gebp micro kernel 1/half/quarterX1"); \ - } while(false); - - EIGEN_GEBGP_ONESTEP(0); - EIGEN_GEBGP_ONESTEP(1); - EIGEN_GEBGP_ONESTEP(2); - EIGEN_GEBGP_ONESTEP(3); - EIGEN_GEBGP_ONESTEP(4); - EIGEN_GEBGP_ONESTEP(5); - EIGEN_GEBGP_ONESTEP(6); - EIGEN_GEBGP_ONESTEP(7); - - blB += pk*RhsProgress; - blA += pk*LhsProgress; - - EIGEN_ASM_COMMENT("end gebp micro kernel 1/half/quarterX1"); - } - - // process remaining peeled loop - for(Index k=peeled_kc; k<depth; k++) - { - RhsPacket B_0; - EIGEN_GEBGP_ONESTEP(0); - blB += RhsProgress; - blA += LhsProgress; - } -#undef EIGEN_GEBGP_ONESTEP - ResPacket R0; - ResPacket alphav = pset1<ResPacket>(alpha); - R0 = r0.template loadPacket<ResPacket>(0); - traits.acc(C0, alphav, R0); - r0.storePacket(0, R0); - } - } - } -}; - -template<int nr, Index LhsProgress, Index RhsProgress, typename LhsScalar, typename RhsScalar, typename ResScalar, typename AccPacket, typename LhsPacket, typename RhsPacket, typename ResPacket, typename GEBPTraits, typename LinearMapper, typename DataMapper> -struct lhs_process_fraction_of_packet : lhs_process_one_packet<nr, LhsProgress, RhsProgress, LhsScalar, RhsScalar, ResScalar, AccPacket, LhsPacket, RhsPacket, ResPacket, GEBPTraits, LinearMapper, DataMapper> -{ - -EIGEN_STRONG_INLINE void peeled_kc_onestep(Index K, const LhsScalar* blA, const RhsScalar* blB, GEBPTraits traits, LhsPacket *A0, RhsPacket *B_0, RhsPacket *B1, RhsPacket *B2, RhsPacket *B3, AccPacket *C0, AccPacket *C1, AccPacket *C2, AccPacket *C3) - { - EIGEN_ASM_COMMENT("begin step of gebp micro kernel 1X4"); - EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); - traits.loadLhsUnaligned(&blA[(0+1*K)*(LhsProgress)], *A0); - traits.broadcastRhs(&blB[(0+4*K)*RhsProgress], *B_0, *B1, *B2, *B3); - traits.madd(*A0, *B_0, *C0, *B_0); - traits.madd(*A0, *B1, *C1, *B1); - traits.madd(*A0, *B2, *C2, *B2); - traits.madd(*A0, *B3, *C3, *B3); - EIGEN_ASM_COMMENT("end step of gebp micro kernel 1X4"); - } -}; - -template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs> -EIGEN_DONT_INLINE -void gebp_kernel<LhsScalar,RhsScalar,Index,DataMapper,mr,nr,ConjugateLhs,ConjugateRhs> - ::operator()(const DataMapper& res, const LhsScalar* blockA, const RhsScalar* blockB, - Index rows, Index depth, Index cols, ResScalar alpha, - Index strideA, Index strideB, Index offsetA, Index offsetB) - { - Traits traits; - SwappedTraits straits; - - if(strideA==-1) strideA = depth; - if(strideB==-1) strideB = depth; - conj_helper<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs> cj; - Index packet_cols4 = nr>=4 ? (cols/4) * 4 : 0; - const Index peeled_mc3 = mr>=3*Traits::LhsProgress ? (rows/(3*LhsProgress))*(3*LhsProgress) : 0; - const Index peeled_mc2 = mr>=2*Traits::LhsProgress ? peeled_mc3+((rows-peeled_mc3)/(2*LhsProgress))*(2*LhsProgress) : 0; - const Index peeled_mc1 = mr>=1*Traits::LhsProgress ? peeled_mc2+((rows-peeled_mc2)/(1*LhsProgress))*(1*LhsProgress) : 0; - const Index peeled_mc_half = mr>=LhsProgressHalf ? peeled_mc1+((rows-peeled_mc1)/(LhsProgressHalf))*(LhsProgressHalf) : 0; - const Index peeled_mc_quarter = mr>=LhsProgressQuarter ? peeled_mc_half+((rows-peeled_mc_half)/(LhsProgressQuarter))*(LhsProgressQuarter) : 0; - enum { pk = 8 }; // NOTE Such a large peeling factor is important for large matrices (~ +5% when >1000 on Haswell) - const Index peeled_kc = depth & ~(pk-1); - const int prefetch_res_offset = 32/sizeof(ResScalar); -// const Index depth2 = depth & ~1; - - //---------- Process 3 * LhsProgress rows at once ---------- - // This corresponds to 3*LhsProgress x nr register blocks. - // Usually, make sense only with FMA - if(mr>=3*Traits::LhsProgress) - { - // Here, the general idea is to loop on each largest micro horizontal panel of the lhs (3*Traits::LhsProgress x depth) - // and on each largest micro vertical panel of the rhs (depth * nr). - // Blocking sizes, i.e., 'depth' has been computed so that the micro horizontal panel of the lhs fit in L1. - // However, if depth is too small, we can extend the number of rows of these horizontal panels. - // This actual number of rows is computed as follow: - const Index l1 = defaultL1CacheSize; // in Bytes, TODO, l1 should be passed to this function. - // The max(1, ...) here is needed because we may be using blocking params larger than what our known l1 cache size - // suggests we should be using: either because our known l1 cache size is inaccurate (e.g. on Android, we can only guess), - // or because we are testing specific blocking sizes. - const Index actual_panel_rows = (3*LhsProgress) * std::max<Index>(1,( (l1 - sizeof(ResScalar)*mr*nr - depth*nr*sizeof(RhsScalar)) / (depth * sizeof(LhsScalar) * 3*LhsProgress) )); - for(Index i1=0; i1<peeled_mc3; i1+=actual_panel_rows) - { - const Index actual_panel_end = (std::min)(i1+actual_panel_rows, peeled_mc3); - for(Index j2=0; j2<packet_cols4; j2+=nr) - { - for(Index i=i1; i<actual_panel_end; i+=3*LhsProgress) - { - - // We selected a 3*Traits::LhsProgress x nr micro block of res which is entirely - // stored into 3 x nr registers. - - const LhsScalar* blA = &blockA[i*strideA+offsetA*(3*LhsProgress)]; - prefetch(&blA[0]); - - // gets res block as register - AccPacket C0, C1, C2, C3, - C4, C5, C6, C7, - C8, C9, C10, C11; - traits.initAcc(C0); traits.initAcc(C1); traits.initAcc(C2); traits.initAcc(C3); - traits.initAcc(C4); traits.initAcc(C5); traits.initAcc(C6); traits.initAcc(C7); - traits.initAcc(C8); traits.initAcc(C9); traits.initAcc(C10); traits.initAcc(C11); - - LinearMapper r0 = res.getLinearMapper(i, j2 + 0); - LinearMapper r1 = res.getLinearMapper(i, j2 + 1); - LinearMapper r2 = res.getLinearMapper(i, j2 + 2); - LinearMapper r3 = res.getLinearMapper(i, j2 + 3); - - r0.prefetch(0); - r1.prefetch(0); - r2.prefetch(0); - r3.prefetch(0); - - // performs "inner" products - const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr]; - prefetch(&blB[0]); - LhsPacket A0, A1; - - for(Index k=0; k<peeled_kc; k+=pk) - { - EIGEN_ASM_COMMENT("begin gebp micro kernel 3pX4"); - // 15 registers are taken (12 for acc, 2 for lhs). - RhsPanel15 rhs_panel; - RhsPacket T0; - LhsPacket A2; - #if EIGEN_COMP_GNUC_STRICT && EIGEN_ARCH_ARM64 && defined(EIGEN_VECTORIZE_NEON) && !(EIGEN_GNUC_AT_LEAST(9,0)) - // see http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1633 - // without this workaround A0, A1, and A2 are loaded in the same register, - // which is not good for pipelining - #define EIGEN_GEBP_3PX4_REGISTER_ALLOC_WORKAROUND __asm__ ("" : "+w,m" (A0), "+w,m" (A1), "+w,m" (A2)); - #else - #define EIGEN_GEBP_3PX4_REGISTER_ALLOC_WORKAROUND - #endif -#define EIGEN_GEBP_ONESTEP(K) \ - do { \ - EIGEN_ASM_COMMENT("begin step of gebp micro kernel 3pX4"); \ - EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); \ - internal::prefetch(blA + (3 * K + 16) * LhsProgress); \ - if (EIGEN_ARCH_ARM || EIGEN_ARCH_MIPS) { \ - internal::prefetch(blB + (4 * K + 16) * RhsProgress); \ - } /* Bug 953 */ \ - traits.loadLhs(&blA[(0 + 3 * K) * LhsProgress], A0); \ - traits.loadLhs(&blA[(1 + 3 * K) * LhsProgress], A1); \ - traits.loadLhs(&blA[(2 + 3 * K) * LhsProgress], A2); \ - EIGEN_GEBP_3PX4_REGISTER_ALLOC_WORKAROUND \ - traits.loadRhs(blB + (0+4*K) * Traits::RhsProgress, rhs_panel); \ - traits.madd(A0, rhs_panel, C0, T0, fix<0>); \ - traits.madd(A1, rhs_panel, C4, T0, fix<0>); \ - traits.madd(A2, rhs_panel, C8, T0, fix<0>); \ - traits.updateRhs(blB + (1+4*K) * Traits::RhsProgress, rhs_panel); \ - traits.madd(A0, rhs_panel, C1, T0, fix<1>); \ - traits.madd(A1, rhs_panel, C5, T0, fix<1>); \ - traits.madd(A2, rhs_panel, C9, T0, fix<1>); \ - traits.updateRhs(blB + (2+4*K) * Traits::RhsProgress, rhs_panel); \ - traits.madd(A0, rhs_panel, C2, T0, fix<2>); \ - traits.madd(A1, rhs_panel, C6, T0, fix<2>); \ - traits.madd(A2, rhs_panel, C10, T0, fix<2>); \ - traits.updateRhs(blB + (3+4*K) * Traits::RhsProgress, rhs_panel); \ - traits.madd(A0, rhs_panel, C3, T0, fix<3>); \ - traits.madd(A1, rhs_panel, C7, T0, fix<3>); \ - traits.madd(A2, rhs_panel, C11, T0, fix<3>); \ - EIGEN_ASM_COMMENT("end step of gebp micro kernel 3pX4"); \ - } while (false) - - internal::prefetch(blB); - EIGEN_GEBP_ONESTEP(0); - EIGEN_GEBP_ONESTEP(1); - EIGEN_GEBP_ONESTEP(2); - EIGEN_GEBP_ONESTEP(3); - EIGEN_GEBP_ONESTEP(4); - EIGEN_GEBP_ONESTEP(5); - EIGEN_GEBP_ONESTEP(6); - EIGEN_GEBP_ONESTEP(7); - - blB += pk*4*RhsProgress; - blA += pk*3*Traits::LhsProgress; - - EIGEN_ASM_COMMENT("end gebp micro kernel 3pX4"); - } - // process remaining peeled loop - for(Index k=peeled_kc; k<depth; k++) - { - RhsPanel15 rhs_panel; - RhsPacket T0; - LhsPacket A2; - EIGEN_GEBP_ONESTEP(0); - blB += 4*RhsProgress; - blA += 3*Traits::LhsProgress; - } - -#undef EIGEN_GEBP_ONESTEP - - ResPacket R0, R1, R2; - ResPacket alphav = pset1<ResPacket>(alpha); - - R0 = r0.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R1 = r0.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - R2 = r0.template loadPacket<ResPacket>(2 * Traits::ResPacketSize); - traits.acc(C0, alphav, R0); - traits.acc(C4, alphav, R1); - traits.acc(C8, alphav, R2); - r0.storePacket(0 * Traits::ResPacketSize, R0); - r0.storePacket(1 * Traits::ResPacketSize, R1); - r0.storePacket(2 * Traits::ResPacketSize, R2); - - R0 = r1.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R1 = r1.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - R2 = r1.template loadPacket<ResPacket>(2 * Traits::ResPacketSize); - traits.acc(C1, alphav, R0); - traits.acc(C5, alphav, R1); - traits.acc(C9, alphav, R2); - r1.storePacket(0 * Traits::ResPacketSize, R0); - r1.storePacket(1 * Traits::ResPacketSize, R1); - r1.storePacket(2 * Traits::ResPacketSize, R2); - - R0 = r2.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R1 = r2.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - R2 = r2.template loadPacket<ResPacket>(2 * Traits::ResPacketSize); - traits.acc(C2, alphav, R0); - traits.acc(C6, alphav, R1); - traits.acc(C10, alphav, R2); - r2.storePacket(0 * Traits::ResPacketSize, R0); - r2.storePacket(1 * Traits::ResPacketSize, R1); - r2.storePacket(2 * Traits::ResPacketSize, R2); - - R0 = r3.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R1 = r3.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - R2 = r3.template loadPacket<ResPacket>(2 * Traits::ResPacketSize); - traits.acc(C3, alphav, R0); - traits.acc(C7, alphav, R1); - traits.acc(C11, alphav, R2); - r3.storePacket(0 * Traits::ResPacketSize, R0); - r3.storePacket(1 * Traits::ResPacketSize, R1); - r3.storePacket(2 * Traits::ResPacketSize, R2); - } - } - - // Deal with remaining columns of the rhs - for(Index j2=packet_cols4; j2<cols; j2++) - { - for(Index i=i1; i<actual_panel_end; i+=3*LhsProgress) - { - // One column at a time - const LhsScalar* blA = &blockA[i*strideA+offsetA*(3*Traits::LhsProgress)]; - prefetch(&blA[0]); - - // gets res block as register - AccPacket C0, C4, C8; - traits.initAcc(C0); - traits.initAcc(C4); - traits.initAcc(C8); - - LinearMapper r0 = res.getLinearMapper(i, j2); - r0.prefetch(0); - - // performs "inner" products - const RhsScalar* blB = &blockB[j2*strideB+offsetB]; - LhsPacket A0, A1, A2; - - for(Index k=0; k<peeled_kc; k+=pk) - { - EIGEN_ASM_COMMENT("begin gebp micro kernel 3pX1"); - RhsPacket B_0; -#define EIGEN_GEBGP_ONESTEP(K) \ - do { \ - EIGEN_ASM_COMMENT("begin step of gebp micro kernel 3pX1"); \ - EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); \ - traits.loadLhs(&blA[(0 + 3 * K) * LhsProgress], A0); \ - traits.loadLhs(&blA[(1 + 3 * K) * LhsProgress], A1); \ - traits.loadLhs(&blA[(2 + 3 * K) * LhsProgress], A2); \ - traits.loadRhs(&blB[(0 + K) * RhsProgress], B_0); \ - traits.madd(A0, B_0, C0, B_0, fix<0>); \ - traits.madd(A1, B_0, C4, B_0, fix<0>); \ - traits.madd(A2, B_0, C8, B_0, fix<0>); \ - EIGEN_ASM_COMMENT("end step of gebp micro kernel 3pX1"); \ - } while (false) - - EIGEN_GEBGP_ONESTEP(0); - EIGEN_GEBGP_ONESTEP(1); - EIGEN_GEBGP_ONESTEP(2); - EIGEN_GEBGP_ONESTEP(3); - EIGEN_GEBGP_ONESTEP(4); - EIGEN_GEBGP_ONESTEP(5); - EIGEN_GEBGP_ONESTEP(6); - EIGEN_GEBGP_ONESTEP(7); - - blB += pk*RhsProgress; - blA += pk*3*Traits::LhsProgress; - - EIGEN_ASM_COMMENT("end gebp micro kernel 3pX1"); - } - - // process remaining peeled loop - for(Index k=peeled_kc; k<depth; k++) - { - RhsPacket B_0; - EIGEN_GEBGP_ONESTEP(0); - blB += RhsProgress; - blA += 3*Traits::LhsProgress; - } -#undef EIGEN_GEBGP_ONESTEP - ResPacket R0, R1, R2; - ResPacket alphav = pset1<ResPacket>(alpha); - - R0 = r0.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R1 = r0.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - R2 = r0.template loadPacket<ResPacket>(2 * Traits::ResPacketSize); - traits.acc(C0, alphav, R0); - traits.acc(C4, alphav, R1); - traits.acc(C8, alphav, R2); - r0.storePacket(0 * Traits::ResPacketSize, R0); - r0.storePacket(1 * Traits::ResPacketSize, R1); - r0.storePacket(2 * Traits::ResPacketSize, R2); - } - } - } - } - - //---------- Process 2 * LhsProgress rows at once ---------- - if(mr>=2*Traits::LhsProgress) - { - const Index l1 = defaultL1CacheSize; // in Bytes, TODO, l1 should be passed to this function. - // The max(1, ...) here is needed because we may be using blocking params larger than what our known l1 cache size - // suggests we should be using: either because our known l1 cache size is inaccurate (e.g. on Android, we can only guess), - // or because we are testing specific blocking sizes. - Index actual_panel_rows = (2*LhsProgress) * std::max<Index>(1,( (l1 - sizeof(ResScalar)*mr*nr - depth*nr*sizeof(RhsScalar)) / (depth * sizeof(LhsScalar) * 2*LhsProgress) )); - - for(Index i1=peeled_mc3; i1<peeled_mc2; i1+=actual_panel_rows) - { - Index actual_panel_end = (std::min)(i1+actual_panel_rows, peeled_mc2); - for(Index j2=0; j2<packet_cols4; j2+=nr) - { - for(Index i=i1; i<actual_panel_end; i+=2*LhsProgress) - { - - // We selected a 2*Traits::LhsProgress x nr micro block of res which is entirely - // stored into 2 x nr registers. - - const LhsScalar* blA = &blockA[i*strideA+offsetA*(2*Traits::LhsProgress)]; - prefetch(&blA[0]); - - // gets res block as register - AccPacket C0, C1, C2, C3, - C4, C5, C6, C7; - traits.initAcc(C0); traits.initAcc(C1); traits.initAcc(C2); traits.initAcc(C3); - traits.initAcc(C4); traits.initAcc(C5); traits.initAcc(C6); traits.initAcc(C7); - - LinearMapper r0 = res.getLinearMapper(i, j2 + 0); - LinearMapper r1 = res.getLinearMapper(i, j2 + 1); - LinearMapper r2 = res.getLinearMapper(i, j2 + 2); - LinearMapper r3 = res.getLinearMapper(i, j2 + 3); - - r0.prefetch(prefetch_res_offset); - r1.prefetch(prefetch_res_offset); - r2.prefetch(prefetch_res_offset); - r3.prefetch(prefetch_res_offset); - - // performs "inner" products - const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr]; - prefetch(&blB[0]); - LhsPacket A0, A1; - - for(Index k=0; k<peeled_kc; k+=pk) - { - EIGEN_ASM_COMMENT("begin gebp micro kernel 2pX4"); - RhsPacketx4 rhs_panel; - RhsPacket T0; - - // NOTE: the begin/end asm comments below work around bug 935! - // but they are not enough for gcc>=6 without FMA (bug 1637) - #if EIGEN_GNUC_AT_LEAST(6,0) && defined(EIGEN_VECTORIZE_SSE) - #define EIGEN_GEBP_2PX4_SPILLING_WORKAROUND __asm__ ("" : [a0] "+x,m" (A0),[a1] "+x,m" (A1)); - #else - #define EIGEN_GEBP_2PX4_SPILLING_WORKAROUND - #endif -#define EIGEN_GEBGP_ONESTEP(K) \ - do { \ - EIGEN_ASM_COMMENT("begin step of gebp micro kernel 2pX4"); \ - traits.loadLhs(&blA[(0 + 2 * K) * LhsProgress], A0); \ - traits.loadLhs(&blA[(1 + 2 * K) * LhsProgress], A1); \ - traits.loadRhs(&blB[(0 + 4 * K) * RhsProgress], rhs_panel); \ - traits.madd(A0, rhs_panel, C0, T0, fix<0>); \ - traits.madd(A1, rhs_panel, C4, T0, fix<0>); \ - traits.madd(A0, rhs_panel, C1, T0, fix<1>); \ - traits.madd(A1, rhs_panel, C5, T0, fix<1>); \ - traits.madd(A0, rhs_panel, C2, T0, fix<2>); \ - traits.madd(A1, rhs_panel, C6, T0, fix<2>); \ - traits.madd(A0, rhs_panel, C3, T0, fix<3>); \ - traits.madd(A1, rhs_panel, C7, T0, fix<3>); \ - EIGEN_GEBP_2PX4_SPILLING_WORKAROUND \ - EIGEN_ASM_COMMENT("end step of gebp micro kernel 2pX4"); \ - } while (false) - - internal::prefetch(blB+(48+0)); - EIGEN_GEBGP_ONESTEP(0); - EIGEN_GEBGP_ONESTEP(1); - EIGEN_GEBGP_ONESTEP(2); - EIGEN_GEBGP_ONESTEP(3); - internal::prefetch(blB+(48+16)); - EIGEN_GEBGP_ONESTEP(4); - EIGEN_GEBGP_ONESTEP(5); - EIGEN_GEBGP_ONESTEP(6); - EIGEN_GEBGP_ONESTEP(7); - - blB += pk*4*RhsProgress; - blA += pk*(2*Traits::LhsProgress); - - EIGEN_ASM_COMMENT("end gebp micro kernel 2pX4"); - } - // process remaining peeled loop - for(Index k=peeled_kc; k<depth; k++) - { - RhsPacketx4 rhs_panel; - RhsPacket T0; - EIGEN_GEBGP_ONESTEP(0); - blB += 4*RhsProgress; - blA += 2*Traits::LhsProgress; - } -#undef EIGEN_GEBGP_ONESTEP - - ResPacket R0, R1, R2, R3; - ResPacket alphav = pset1<ResPacket>(alpha); - - R0 = r0.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R1 = r0.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - R2 = r1.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R3 = r1.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - traits.acc(C0, alphav, R0); - traits.acc(C4, alphav, R1); - traits.acc(C1, alphav, R2); - traits.acc(C5, alphav, R3); - r0.storePacket(0 * Traits::ResPacketSize, R0); - r0.storePacket(1 * Traits::ResPacketSize, R1); - r1.storePacket(0 * Traits::ResPacketSize, R2); - r1.storePacket(1 * Traits::ResPacketSize, R3); - - R0 = r2.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R1 = r2.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - R2 = r3.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R3 = r3.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - traits.acc(C2, alphav, R0); - traits.acc(C6, alphav, R1); - traits.acc(C3, alphav, R2); - traits.acc(C7, alphav, R3); - r2.storePacket(0 * Traits::ResPacketSize, R0); - r2.storePacket(1 * Traits::ResPacketSize, R1); - r3.storePacket(0 * Traits::ResPacketSize, R2); - r3.storePacket(1 * Traits::ResPacketSize, R3); - } - } - - // Deal with remaining columns of the rhs - for(Index j2=packet_cols4; j2<cols; j2++) - { - for(Index i=i1; i<actual_panel_end; i+=2*LhsProgress) - { - // One column at a time - const LhsScalar* blA = &blockA[i*strideA+offsetA*(2*Traits::LhsProgress)]; - prefetch(&blA[0]); - - // gets res block as register - AccPacket C0, C4; - traits.initAcc(C0); - traits.initAcc(C4); - - LinearMapper r0 = res.getLinearMapper(i, j2); - r0.prefetch(prefetch_res_offset); - - // performs "inner" products - const RhsScalar* blB = &blockB[j2*strideB+offsetB]; - LhsPacket A0, A1; - - for(Index k=0; k<peeled_kc; k+=pk) - { - EIGEN_ASM_COMMENT("begin gebp micro kernel 2pX1"); - RhsPacket B_0, B1; - -#define EIGEN_GEBGP_ONESTEP(K) \ - do { \ - EIGEN_ASM_COMMENT("begin step of gebp micro kernel 2pX1"); \ - EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); \ - traits.loadLhs(&blA[(0+2*K)*LhsProgress], A0); \ - traits.loadLhs(&blA[(1+2*K)*LhsProgress], A1); \ - traits.loadRhs(&blB[(0+K)*RhsProgress], B_0); \ - traits.madd(A0, B_0, C0, B1, fix<0>); \ - traits.madd(A1, B_0, C4, B_0, fix<0>); \ - EIGEN_ASM_COMMENT("end step of gebp micro kernel 2pX1"); \ - } while(false) - - EIGEN_GEBGP_ONESTEP(0); - EIGEN_GEBGP_ONESTEP(1); - EIGEN_GEBGP_ONESTEP(2); - EIGEN_GEBGP_ONESTEP(3); - EIGEN_GEBGP_ONESTEP(4); - EIGEN_GEBGP_ONESTEP(5); - EIGEN_GEBGP_ONESTEP(6); - EIGEN_GEBGP_ONESTEP(7); - - blB += pk*RhsProgress; - blA += pk*2*Traits::LhsProgress; - - EIGEN_ASM_COMMENT("end gebp micro kernel 2pX1"); - } - - // process remaining peeled loop - for(Index k=peeled_kc; k<depth; k++) - { - RhsPacket B_0, B1; - EIGEN_GEBGP_ONESTEP(0); - blB += RhsProgress; - blA += 2*Traits::LhsProgress; - } -#undef EIGEN_GEBGP_ONESTEP - ResPacket R0, R1; - ResPacket alphav = pset1<ResPacket>(alpha); - - R0 = r0.template loadPacket<ResPacket>(0 * Traits::ResPacketSize); - R1 = r0.template loadPacket<ResPacket>(1 * Traits::ResPacketSize); - traits.acc(C0, alphav, R0); - traits.acc(C4, alphav, R1); - r0.storePacket(0 * Traits::ResPacketSize, R0); - r0.storePacket(1 * Traits::ResPacketSize, R1); - } - } - } - } - //---------- Process 1 * LhsProgress rows at once ---------- - if(mr>=1*Traits::LhsProgress) - { - lhs_process_one_packet<nr, LhsProgress, RhsProgress, LhsScalar, RhsScalar, ResScalar, AccPacket, LhsPacket, RhsPacket, ResPacket, Traits, LinearMapper, DataMapper> p; - p(res, blockA, blockB, alpha, peeled_mc2, peeled_mc1, strideA, strideB, offsetA, offsetB, prefetch_res_offset, peeled_kc, pk, cols, depth, packet_cols4); - } - //---------- Process LhsProgressHalf rows at once ---------- - if((LhsProgressHalf < LhsProgress) && mr>=LhsProgressHalf) - { - lhs_process_fraction_of_packet<nr, LhsProgressHalf, RhsProgressHalf, LhsScalar, RhsScalar, ResScalar, AccPacketHalf, LhsPacketHalf, RhsPacketHalf, ResPacketHalf, HalfTraits, LinearMapper, DataMapper> p; - p(res, blockA, blockB, alpha, peeled_mc1, peeled_mc_half, strideA, strideB, offsetA, offsetB, prefetch_res_offset, peeled_kc, pk, cols, depth, packet_cols4); - } - //---------- Process LhsProgressQuarter rows at once ---------- - if((LhsProgressQuarter < LhsProgressHalf) && mr>=LhsProgressQuarter) - { - lhs_process_fraction_of_packet<nr, LhsProgressQuarter, RhsProgressQuarter, LhsScalar, RhsScalar, ResScalar, AccPacketQuarter, LhsPacketQuarter, RhsPacketQuarter, ResPacketQuarter, QuarterTraits, LinearMapper, DataMapper> p; - p(res, blockA, blockB, alpha, peeled_mc_half, peeled_mc_quarter, strideA, strideB, offsetA, offsetB, prefetch_res_offset, peeled_kc, pk, cols, depth, packet_cols4); - } - //---------- Process remaining rows, 1 at once ---------- - if(peeled_mc_quarter<rows) - { - // loop on each panel of the rhs - for(Index j2=0; j2<packet_cols4; j2+=nr) - { - // loop on each row of the lhs (1*LhsProgress x depth) - for(Index i=peeled_mc_quarter; i<rows; i+=1) - { - const LhsScalar* blA = &blockA[i*strideA+offsetA]; - prefetch(&blA[0]); - const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr]; - - // If LhsProgress is 8 or 16, it assumes that there is a - // half or quarter packet, respectively, of the same size as - // nr (which is currently 4) for the return type. - const int SResPacketHalfSize = unpacket_traits<typename unpacket_traits<SResPacket>::half>::size; - const int SResPacketQuarterSize = unpacket_traits<typename unpacket_traits<typename unpacket_traits<SResPacket>::half>::half>::size; - if ((SwappedTraits::LhsProgress % 4) == 0 && - (SwappedTraits::LhsProgress<=16) && - (SwappedTraits::LhsProgress!=8 || SResPacketHalfSize==nr) && - (SwappedTraits::LhsProgress!=16 || SResPacketQuarterSize==nr)) - { - SAccPacket C0, C1, C2, C3; - straits.initAcc(C0); - straits.initAcc(C1); - straits.initAcc(C2); - straits.initAcc(C3); - - const Index spk = (std::max)(1,SwappedTraits::LhsProgress/4); - const Index endk = (depth/spk)*spk; - const Index endk4 = (depth/(spk*4))*(spk*4); - - Index k=0; - for(; k<endk4; k+=4*spk) - { - SLhsPacket A0,A1; - SRhsPacket B_0,B_1; - - straits.loadLhsUnaligned(blB+0*SwappedTraits::LhsProgress, A0); - straits.loadLhsUnaligned(blB+1*SwappedTraits::LhsProgress, A1); - - straits.loadRhsQuad(blA+0*spk, B_0); - straits.loadRhsQuad(blA+1*spk, B_1); - straits.madd(A0,B_0,C0,B_0, fix<0>); - straits.madd(A1,B_1,C1,B_1, fix<0>); - - straits.loadLhsUnaligned(blB+2*SwappedTraits::LhsProgress, A0); - straits.loadLhsUnaligned(blB+3*SwappedTraits::LhsProgress, A1); - straits.loadRhsQuad(blA+2*spk, B_0); - straits.loadRhsQuad(blA+3*spk, B_1); - straits.madd(A0,B_0,C2,B_0, fix<0>); - straits.madd(A1,B_1,C3,B_1, fix<0>); - - blB += 4*SwappedTraits::LhsProgress; - blA += 4*spk; - } - C0 = padd(padd(C0,C1),padd(C2,C3)); - for(; k<endk; k+=spk) - { - SLhsPacket A0; - SRhsPacket B_0; - - straits.loadLhsUnaligned(blB, A0); - straits.loadRhsQuad(blA, B_0); - straits.madd(A0,B_0,C0,B_0, fix<0>); - - blB += SwappedTraits::LhsProgress; - blA += spk; - } - if(SwappedTraits::LhsProgress==8) - { - // Special case where we have to first reduce the accumulation register C0 - typedef typename conditional<SwappedTraits::LhsProgress>=8,typename unpacket_traits<SResPacket>::half,SResPacket>::type SResPacketHalf; - typedef typename conditional<SwappedTraits::LhsProgress>=8,typename unpacket_traits<SLhsPacket>::half,SLhsPacket>::type SLhsPacketHalf; - typedef typename conditional<SwappedTraits::LhsProgress>=8,typename unpacket_traits<SRhsPacket>::half,SRhsPacket>::type SRhsPacketHalf; - typedef typename conditional<SwappedTraits::LhsProgress>=8,typename unpacket_traits<SAccPacket>::half,SAccPacket>::type SAccPacketHalf; - - SResPacketHalf R = res.template gatherPacket<SResPacketHalf>(i, j2); - SResPacketHalf alphav = pset1<SResPacketHalf>(alpha); - - if(depth-endk>0) - { - // We have to handle the last row of the rhs which corresponds to a half-packet - SLhsPacketHalf a0; - SRhsPacketHalf b0; - straits.loadLhsUnaligned(blB, a0); - straits.loadRhs(blA, b0); - SAccPacketHalf c0 = predux_half_dowto4(C0); - straits.madd(a0,b0,c0,b0, fix<0>); - straits.acc(c0, alphav, R); - } - else - { - straits.acc(predux_half_dowto4(C0), alphav, R); - } - res.scatterPacket(i, j2, R); - } - else if (SwappedTraits::LhsProgress==16) - { - // Special case where we have to first reduce the - // accumulation register C0. We specialize the block in - // template form, so that LhsProgress < 16 paths don't - // fail to compile - last_row_process_16_packets<LhsScalar, RhsScalar, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs> p; - p(res, straits, blA, blB, depth, endk, i, j2,alpha, C0); - } - else - { - SResPacket R = res.template gatherPacket<SResPacket>(i, j2); - SResPacket alphav = pset1<SResPacket>(alpha); - straits.acc(C0, alphav, R); - res.scatterPacket(i, j2, R); - } - } - else // scalar path - { - // get a 1 x 4 res block as registers - ResScalar C0(0), C1(0), C2(0), C3(0); - - for(Index k=0; k<depth; k++) - { - LhsScalar A0; - RhsScalar B_0, B_1; - - A0 = blA[k]; - - B_0 = blB[0]; - B_1 = blB[1]; - CJMADD(cj,A0,B_0,C0, B_0); - CJMADD(cj,A0,B_1,C1, B_1); - - B_0 = blB[2]; - B_1 = blB[3]; - CJMADD(cj,A0,B_0,C2, B_0); - CJMADD(cj,A0,B_1,C3, B_1); - - blB += 4; - } - res(i, j2 + 0) += alpha * C0; - res(i, j2 + 1) += alpha * C1; - res(i, j2 + 2) += alpha * C2; - res(i, j2 + 3) += alpha * C3; - } - } - } - // remaining columns - for(Index j2=packet_cols4; j2<cols; j2++) - { - // loop on each row of the lhs (1*LhsProgress x depth) - for(Index i=peeled_mc_quarter; i<rows; i+=1) - { - const LhsScalar* blA = &blockA[i*strideA+offsetA]; - prefetch(&blA[0]); - // gets a 1 x 1 res block as registers - ResScalar C0(0); - const RhsScalar* blB = &blockB[j2*strideB+offsetB]; - for(Index k=0; k<depth; k++) - { - LhsScalar A0 = blA[k]; - RhsScalar B_0 = blB[k]; - CJMADD(cj, A0, B_0, C0, B_0); - } - res(i, j2) += alpha * C0; - } - } - } - } - - -#undef CJMADD - -// pack a block of the lhs -// The traversal is as follow (mr==4): -// 0 4 8 12 ... -// 1 5 9 13 ... -// 2 6 10 14 ... -// 3 7 11 15 ... -// -// 16 20 24 28 ... -// 17 21 25 29 ... -// 18 22 26 30 ... -// 19 23 27 31 ... -// -// 32 33 34 35 ... -// 36 36 38 39 ... -template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode> -struct gemm_pack_lhs<Scalar, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode> -{ - typedef typename DataMapper::LinearMapper LinearMapper; - EIGEN_DONT_INLINE void operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0); -}; - -template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode> -EIGEN_DONT_INLINE void gemm_pack_lhs<Scalar, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode> - ::operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset) -{ - typedef typename unpacket_traits<Packet>::half HalfPacket; - typedef typename unpacket_traits<typename unpacket_traits<Packet>::half>::half QuarterPacket; - enum { PacketSize = unpacket_traits<Packet>::size, - HalfPacketSize = unpacket_traits<HalfPacket>::size, - QuarterPacketSize = unpacket_traits<QuarterPacket>::size, - HasHalf = (int)HalfPacketSize < (int)PacketSize, - HasQuarter = (int)QuarterPacketSize < (int)HalfPacketSize}; - - EIGEN_ASM_COMMENT("EIGEN PRODUCT PACK LHS"); - EIGEN_UNUSED_VARIABLE(stride); - EIGEN_UNUSED_VARIABLE(offset); - eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride)); - eigen_assert( ((Pack1%PacketSize)==0 && Pack1<=4*PacketSize) || (Pack1<=4) ); - conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj; - Index count = 0; - - const Index peeled_mc3 = Pack1>=3*PacketSize ? (rows/(3*PacketSize))*(3*PacketSize) : 0; - const Index peeled_mc2 = Pack1>=2*PacketSize ? peeled_mc3+((rows-peeled_mc3)/(2*PacketSize))*(2*PacketSize) : 0; - const Index peeled_mc1 = Pack1>=1*PacketSize ? peeled_mc2+((rows-peeled_mc2)/(1*PacketSize))*(1*PacketSize) : 0; - const Index peeled_mc_half = Pack1>=HalfPacketSize ? peeled_mc1+((rows-peeled_mc1)/(HalfPacketSize))*(HalfPacketSize) : 0; - const Index peeled_mc_quarter = Pack1>=QuarterPacketSize ? (rows/(QuarterPacketSize))*(QuarterPacketSize) : 0; - const Index last_lhs_progress = rows > peeled_mc_quarter ? (rows - peeled_mc_quarter) & ~1 : 0; - const Index peeled_mc0 = Pack2>=PacketSize ? peeled_mc_quarter - : Pack2>1 && last_lhs_progress ? (rows/last_lhs_progress)*last_lhs_progress : 0; - - Index i=0; - - // Pack 3 packets - if(Pack1>=3*PacketSize) - { - for(; i<peeled_mc3; i+=3*PacketSize) - { - if(PanelMode) count += (3*PacketSize) * offset; - - for(Index k=0; k<depth; k++) - { - Packet A, B, C; - A = lhs.template loadPacket<Packet>(i+0*PacketSize, k); - B = lhs.template loadPacket<Packet>(i+1*PacketSize, k); - C = lhs.template loadPacket<Packet>(i+2*PacketSize, k); - pstore(blockA+count, cj.pconj(A)); count+=PacketSize; - pstore(blockA+count, cj.pconj(B)); count+=PacketSize; - pstore(blockA+count, cj.pconj(C)); count+=PacketSize; - } - if(PanelMode) count += (3*PacketSize) * (stride-offset-depth); - } - } - // Pack 2 packets - if(Pack1>=2*PacketSize) - { - for(; i<peeled_mc2; i+=2*PacketSize) - { - if(PanelMode) count += (2*PacketSize) * offset; - - for(Index k=0; k<depth; k++) - { - Packet A, B; - A = lhs.template loadPacket<Packet>(i+0*PacketSize, k); - B = lhs.template loadPacket<Packet>(i+1*PacketSize, k); - pstore(blockA+count, cj.pconj(A)); count+=PacketSize; - pstore(blockA+count, cj.pconj(B)); count+=PacketSize; - } - if(PanelMode) count += (2*PacketSize) * (stride-offset-depth); - } - } - // Pack 1 packets - if(Pack1>=1*PacketSize) - { - for(; i<peeled_mc1; i+=1*PacketSize) - { - if(PanelMode) count += (1*PacketSize) * offset; - - for(Index k=0; k<depth; k++) - { - Packet A; - A = lhs.template loadPacket<Packet>(i+0*PacketSize, k); - pstore(blockA+count, cj.pconj(A)); - count+=PacketSize; - } - if(PanelMode) count += (1*PacketSize) * (stride-offset-depth); - } - } - // Pack half packets - if(HasHalf && Pack1>=HalfPacketSize) - { - for(; i<peeled_mc_half; i+=HalfPacketSize) - { - if(PanelMode) count += (HalfPacketSize) * offset; - - for(Index k=0; k<depth; k++) - { - HalfPacket A; - A = lhs.template loadPacket<HalfPacket>(i+0*(HalfPacketSize), k); - pstoreu(blockA+count, cj.pconj(A)); - count+=HalfPacketSize; - } - if(PanelMode) count += (HalfPacketSize) * (stride-offset-depth); - } - } - // Pack quarter packets - if(HasQuarter && Pack1>=QuarterPacketSize) - { - for(; i<peeled_mc_quarter; i+=QuarterPacketSize) - { - if(PanelMode) count += (QuarterPacketSize) * offset; - - for(Index k=0; k<depth; k++) - { - QuarterPacket A; - A = lhs.template loadPacket<QuarterPacket>(i+0*(QuarterPacketSize), k); - pstoreu(blockA+count, cj.pconj(A)); - count+=QuarterPacketSize; - } - if(PanelMode) count += (QuarterPacketSize) * (stride-offset-depth); - } - } - // Pack2 may be *smaller* than PacketSize—that happens for - // products like real * complex, where we have to go half the - // progress on the lhs in order to duplicate those operands to - // address both real & imaginary parts on the rhs. This portion will - // pack those half ones until they match the number expected on the - // last peeling loop at this point (for the rhs). - if(Pack2<PacketSize && Pack2>1) - { - for(; i<peeled_mc0; i+=last_lhs_progress) - { - if(PanelMode) count += last_lhs_progress * offset; - - for(Index k=0; k<depth; k++) - for(Index w=0; w<last_lhs_progress; w++) - blockA[count++] = cj(lhs(i+w, k)); - - if(PanelMode) count += last_lhs_progress * (stride-offset-depth); - } - } - // Pack scalars - for(; i<rows; i++) - { - if(PanelMode) count += offset; - for(Index k=0; k<depth; k++) - blockA[count++] = cj(lhs(i, k)); - if(PanelMode) count += (stride-offset-depth); - } -} - -template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode> -struct gemm_pack_lhs<Scalar, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode> -{ - typedef typename DataMapper::LinearMapper LinearMapper; - EIGEN_DONT_INLINE void operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0); -}; - -template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode> -EIGEN_DONT_INLINE void gemm_pack_lhs<Scalar, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode> - ::operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset) -{ - typedef typename unpacket_traits<Packet>::half HalfPacket; - typedef typename unpacket_traits<typename unpacket_traits<Packet>::half>::half QuarterPacket; - enum { PacketSize = unpacket_traits<Packet>::size, - HalfPacketSize = unpacket_traits<HalfPacket>::size, - QuarterPacketSize = unpacket_traits<QuarterPacket>::size, - HasHalf = (int)HalfPacketSize < (int)PacketSize, - HasQuarter = (int)QuarterPacketSize < (int)HalfPacketSize}; - - EIGEN_ASM_COMMENT("EIGEN PRODUCT PACK LHS"); - EIGEN_UNUSED_VARIABLE(stride); - EIGEN_UNUSED_VARIABLE(offset); - eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride)); - conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj; - Index count = 0; - bool gone_half = false, gone_quarter = false, gone_last = false; - - Index i = 0; - int pack = Pack1; - int psize = PacketSize; - while(pack>0) - { - Index remaining_rows = rows-i; - Index peeled_mc = gone_last ? Pack2>1 ? (rows/pack)*pack : 0 : i+(remaining_rows/pack)*pack; - Index starting_pos = i; - for(; i<peeled_mc; i+=pack) - { - if(PanelMode) count += pack * offset; - - Index k=0; - if(pack>=psize && psize >= QuarterPacketSize) - { - const Index peeled_k = (depth/psize)*psize; - for(; k<peeled_k; k+=psize) - { - for (Index m = 0; m < pack; m += psize) - { - if (psize == PacketSize) { - PacketBlock<Packet> kernel; - for (int p = 0; p < psize; ++p) kernel.packet[p] = lhs.template loadPacket<Packet>(i+p+m, k); - ptranspose(kernel); - for (int p = 0; p < psize; ++p) pstore(blockA+count+m+(pack)*p, cj.pconj(kernel.packet[p])); - } else if (HasHalf && psize == HalfPacketSize) { - gone_half = true; - PacketBlock<HalfPacket> kernel_half; - for (int p = 0; p < psize; ++p) kernel_half.packet[p] = lhs.template loadPacket<HalfPacket>(i+p+m, k); - ptranspose(kernel_half); - for (int p = 0; p < psize; ++p) pstore(blockA+count+m+(pack)*p, cj.pconj(kernel_half.packet[p])); - } else if (HasQuarter && psize == QuarterPacketSize) { - gone_quarter = true; - PacketBlock<QuarterPacket> kernel_quarter; - for (int p = 0; p < psize; ++p) kernel_quarter.packet[p] = lhs.template loadPacket<QuarterPacket>(i+p+m, k); - ptranspose(kernel_quarter); - for (int p = 0; p < psize; ++p) pstore(blockA+count+m+(pack)*p, cj.pconj(kernel_quarter.packet[p])); - } - } - count += psize*pack; - } - } - - for(; k<depth; k++) - { - Index w=0; - for(; w<pack-3; w+=4) - { - Scalar a(cj(lhs(i+w+0, k))), - b(cj(lhs(i+w+1, k))), - c(cj(lhs(i+w+2, k))), - d(cj(lhs(i+w+3, k))); - blockA[count++] = a; - blockA[count++] = b; - blockA[count++] = c; - blockA[count++] = d; - } - if(pack%4) - for(;w<pack;++w) - blockA[count++] = cj(lhs(i+w, k)); - } - - if(PanelMode) count += pack * (stride-offset-depth); - } - - pack -= psize; - Index left = rows - i; - if (pack <= 0) { - if (!gone_last && - (starting_pos == i || left >= psize/2 || left >= psize/4) && - ((psize/2 == HalfPacketSize && HasHalf && !gone_half) || - (psize/2 == QuarterPacketSize && HasQuarter && !gone_quarter))) { - psize /= 2; - pack = psize; - continue; - } - // Pack2 may be *smaller* than PacketSize—that happens for - // products like real * complex, where we have to go half the - // progress on the lhs in order to duplicate those operands to - // address both real & imaginary parts on the rhs. This portion will - // pack those half ones until they match the number expected on the - // last peeling loop at this point (for the rhs). - if (Pack2 < PacketSize && !gone_last) { - gone_last = true; - psize = pack = left & ~1; - } - } - } - - for(; i<rows; i++) - { - if(PanelMode) count += offset; - for(Index k=0; k<depth; k++) - blockA[count++] = cj(lhs(i, k)); - if(PanelMode) count += (stride-offset-depth); - } -} - -// copy a complete panel of the rhs -// this version is optimized for column major matrices -// The traversal order is as follow: (nr==4): -// 0 1 2 3 12 13 14 15 24 27 -// 4 5 6 7 16 17 18 19 25 28 -// 8 9 10 11 20 21 22 23 26 29 -// . . . . . . . . . . -template<typename Scalar, typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode> -struct gemm_pack_rhs<Scalar, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode> -{ - typedef typename packet_traits<Scalar>::type Packet; - typedef typename DataMapper::LinearMapper LinearMapper; - enum { PacketSize = packet_traits<Scalar>::size }; - EIGEN_DONT_INLINE void operator()(Scalar* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0); -}; - -template<typename Scalar, typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode> -EIGEN_DONT_INLINE void gemm_pack_rhs<Scalar, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode> - ::operator()(Scalar* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset) -{ - EIGEN_ASM_COMMENT("EIGEN PRODUCT PACK RHS COLMAJOR"); - EIGEN_UNUSED_VARIABLE(stride); - EIGEN_UNUSED_VARIABLE(offset); - eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride)); - conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj; - Index packet_cols8 = nr>=8 ? (cols/8) * 8 : 0; - Index packet_cols4 = nr>=4 ? (cols/4) * 4 : 0; - Index count = 0; - const Index peeled_k = (depth/PacketSize)*PacketSize; -// if(nr>=8) -// { -// for(Index j2=0; j2<packet_cols8; j2+=8) -// { -// // skip what we have before -// if(PanelMode) count += 8 * offset; -// const Scalar* b0 = &rhs[(j2+0)*rhsStride]; -// const Scalar* b1 = &rhs[(j2+1)*rhsStride]; -// const Scalar* b2 = &rhs[(j2+2)*rhsStride]; -// const Scalar* b3 = &rhs[(j2+3)*rhsStride]; -// const Scalar* b4 = &rhs[(j2+4)*rhsStride]; -// const Scalar* b5 = &rhs[(j2+5)*rhsStride]; -// const Scalar* b6 = &rhs[(j2+6)*rhsStride]; -// const Scalar* b7 = &rhs[(j2+7)*rhsStride]; -// Index k=0; -// if(PacketSize==8) // TODO enable vectorized transposition for PacketSize==4 -// { -// for(; k<peeled_k; k+=PacketSize) { -// PacketBlock<Packet> kernel; -// for (int p = 0; p < PacketSize; ++p) { -// kernel.packet[p] = ploadu<Packet>(&rhs[(j2+p)*rhsStride+k]); -// } -// ptranspose(kernel); -// for (int p = 0; p < PacketSize; ++p) { -// pstoreu(blockB+count, cj.pconj(kernel.packet[p])); -// count+=PacketSize; -// } -// } -// } -// for(; k<depth; k++) -// { -// blockB[count+0] = cj(b0[k]); -// blockB[count+1] = cj(b1[k]); -// blockB[count+2] = cj(b2[k]); -// blockB[count+3] = cj(b3[k]); -// blockB[count+4] = cj(b4[k]); -// blockB[count+5] = cj(b5[k]); -// blockB[count+6] = cj(b6[k]); -// blockB[count+7] = cj(b7[k]); -// count += 8; -// } -// // skip what we have after -// if(PanelMode) count += 8 * (stride-offset-depth); -// } -// } - - if(nr>=4) - { - for(Index j2=packet_cols8; j2<packet_cols4; j2+=4) - { - // skip what we have before - if(PanelMode) count += 4 * offset; - const LinearMapper dm0 = rhs.getLinearMapper(0, j2 + 0); - const LinearMapper dm1 = rhs.getLinearMapper(0, j2 + 1); - const LinearMapper dm2 = rhs.getLinearMapper(0, j2 + 2); - const LinearMapper dm3 = rhs.getLinearMapper(0, j2 + 3); - - Index k=0; - if((PacketSize%4)==0) // TODO enable vectorized transposition for PacketSize==2 ?? - { - for(; k<peeled_k; k+=PacketSize) { - PacketBlock<Packet,(PacketSize%4)==0?4:PacketSize> kernel; - kernel.packet[0 ] = dm0.template loadPacket<Packet>(k); - kernel.packet[1%PacketSize] = dm1.template loadPacket<Packet>(k); - kernel.packet[2%PacketSize] = dm2.template loadPacket<Packet>(k); - kernel.packet[3%PacketSize] = dm3.template loadPacket<Packet>(k); - ptranspose(kernel); - pstoreu(blockB+count+0*PacketSize, cj.pconj(kernel.packet[0])); - pstoreu(blockB+count+1*PacketSize, cj.pconj(kernel.packet[1%PacketSize])); - pstoreu(blockB+count+2*PacketSize, cj.pconj(kernel.packet[2%PacketSize])); - pstoreu(blockB+count+3*PacketSize, cj.pconj(kernel.packet[3%PacketSize])); - count+=4*PacketSize; - } - } - for(; k<depth; k++) - { - blockB[count+0] = cj(dm0(k)); - blockB[count+1] = cj(dm1(k)); - blockB[count+2] = cj(dm2(k)); - blockB[count+3] = cj(dm3(k)); - count += 4; - } - // skip what we have after - if(PanelMode) count += 4 * (stride-offset-depth); - } - } - - // copy the remaining columns one at a time (nr==1) - for(Index j2=packet_cols4; j2<cols; ++j2) - { - if(PanelMode) count += offset; - const LinearMapper dm0 = rhs.getLinearMapper(0, j2); - for(Index k=0; k<depth; k++) - { - blockB[count] = cj(dm0(k)); - count += 1; - } - if(PanelMode) count += (stride-offset-depth); - } -} - -// this version is optimized for row major matrices -template<typename Scalar, typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode> -struct gemm_pack_rhs<Scalar, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode> -{ - typedef typename packet_traits<Scalar>::type Packet; - typedef typename DataMapper::LinearMapper LinearMapper; - enum { PacketSize = packet_traits<Scalar>::size }; - EIGEN_DONT_INLINE void operator()(Scalar* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0); -}; - -template<typename Scalar, typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode> -EIGEN_DONT_INLINE void gemm_pack_rhs<Scalar, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode> - ::operator()(Scalar* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset) -{ - EIGEN_ASM_COMMENT("EIGEN PRODUCT PACK RHS ROWMAJOR"); - EIGEN_UNUSED_VARIABLE(stride); - EIGEN_UNUSED_VARIABLE(offset); - eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride)); - conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj; - Index packet_cols8 = nr>=8 ? (cols/8) * 8 : 0; - Index packet_cols4 = nr>=4 ? (cols/4) * 4 : 0; - Index count = 0; - -// if(nr>=8) -// { -// for(Index j2=0; j2<packet_cols8; j2+=8) -// { -// // skip what we have before -// if(PanelMode) count += 8 * offset; -// for(Index k=0; k<depth; k++) -// { -// if (PacketSize==8) { -// Packet A = ploadu<Packet>(&rhs[k*rhsStride + j2]); -// pstoreu(blockB+count, cj.pconj(A)); -// } else if (PacketSize==4) { -// Packet A = ploadu<Packet>(&rhs[k*rhsStride + j2]); -// Packet B = ploadu<Packet>(&rhs[k*rhsStride + j2 + PacketSize]); -// pstoreu(blockB+count, cj.pconj(A)); -// pstoreu(blockB+count+PacketSize, cj.pconj(B)); -// } else { -// const Scalar* b0 = &rhs[k*rhsStride + j2]; -// blockB[count+0] = cj(b0[0]); -// blockB[count+1] = cj(b0[1]); -// blockB[count+2] = cj(b0[2]); -// blockB[count+3] = cj(b0[3]); -// blockB[count+4] = cj(b0[4]); -// blockB[count+5] = cj(b0[5]); -// blockB[count+6] = cj(b0[6]); -// blockB[count+7] = cj(b0[7]); -// } -// count += 8; -// } -// // skip what we have after -// if(PanelMode) count += 8 * (stride-offset-depth); -// } -// } - if(nr>=4) - { - for(Index j2=packet_cols8; j2<packet_cols4; j2+=4) - { - // skip what we have before - if(PanelMode) count += 4 * offset; - for(Index k=0; k<depth; k++) - { - if (PacketSize==4) { - Packet A = rhs.template loadPacket<Packet>(k, j2); - pstoreu(blockB+count, cj.pconj(A)); - count += PacketSize; - } else { - const LinearMapper dm0 = rhs.getLinearMapper(k, j2); - blockB[count+0] = cj(dm0(0)); - blockB[count+1] = cj(dm0(1)); - blockB[count+2] = cj(dm0(2)); - blockB[count+3] = cj(dm0(3)); - count += 4; - } - } - // skip what we have after - if(PanelMode) count += 4 * (stride-offset-depth); - } - } - // copy the remaining columns one at a time (nr==1) - for(Index j2=packet_cols4; j2<cols; ++j2) - { - if(PanelMode) count += offset; - for(Index k=0; k<depth; k++) - { - blockB[count] = cj(rhs(k, j2)); - count += 1; - } - if(PanelMode) count += stride-offset-depth; - } -} - -} // end namespace internal - -/** \returns the currently set level 1 cpu cache size (in bytes) used to estimate the ideal blocking size parameters. - * \sa setCpuCacheSize */ -inline std::ptrdiff_t l1CacheSize() -{ - std::ptrdiff_t l1, l2, l3; - internal::manage_caching_sizes(GetAction, &l1, &l2, &l3); - return l1; -} - -/** \returns the currently set level 2 cpu cache size (in bytes) used to estimate the ideal blocking size parameters. - * \sa setCpuCacheSize */ -inline std::ptrdiff_t l2CacheSize() -{ - std::ptrdiff_t l1, l2, l3; - internal::manage_caching_sizes(GetAction, &l1, &l2, &l3); - return l2; -} - -/** \returns the currently set level 3 cpu cache size (in bytes) used to estimate the ideal blocking size paramete\ -rs. -* \sa setCpuCacheSize */ -inline std::ptrdiff_t l3CacheSize() -{ - std::ptrdiff_t l1, l2, l3; - internal::manage_caching_sizes(GetAction, &l1, &l2, &l3); - return l3; -} - -/** Set the cpu L1 and L2 cache sizes (in bytes). - * These values are use to adjust the size of the blocks - * for the algorithms working per blocks. - * - * \sa computeProductBlockingSizes */ -inline void setCpuCacheSizes(std::ptrdiff_t l1, std::ptrdiff_t l2, std::ptrdiff_t l3) -{ - internal::manage_caching_sizes(SetAction, &l1, &l2, &l3); -} - -} // end namespace Eigen - -#endif // EIGEN_GENERAL_BLOCK_PANEL_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h b/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h deleted file mode 100644 index 508c05c9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h +++ /dev/null @@ -1,517 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERAL_MATRIX_MATRIX_H -#define EIGEN_GENERAL_MATRIX_MATRIX_H - -namespace Eigen { - -namespace internal { - -template<typename _LhsScalar, typename _RhsScalar> class level3_blocking; - -/* Specialization for a row-major destination matrix => simple transposition of the product */ -template< - typename Index, - typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs, - typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride> -struct general_matrix_matrix_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,RowMajor,ResInnerStride> -{ - typedef gebp_traits<RhsScalar,LhsScalar> Traits; - - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - static EIGEN_STRONG_INLINE void run( - Index rows, Index cols, Index depth, - const LhsScalar* lhs, Index lhsStride, - const RhsScalar* rhs, Index rhsStride, - ResScalar* res, Index resIncr, Index resStride, - ResScalar alpha, - level3_blocking<RhsScalar,LhsScalar>& blocking, - GemmParallelInfo<Index>* info = 0) - { - // transpose the product such that the result is column major - general_matrix_matrix_product<Index, - RhsScalar, RhsStorageOrder==RowMajor ? ColMajor : RowMajor, ConjugateRhs, - LhsScalar, LhsStorageOrder==RowMajor ? ColMajor : RowMajor, ConjugateLhs, - ColMajor,ResInnerStride> - ::run(cols,rows,depth,rhs,rhsStride,lhs,lhsStride,res,resIncr,resStride,alpha,blocking,info); - } -}; - -/* Specialization for a col-major destination matrix - * => Blocking algorithm following Goto's paper */ -template< - typename Index, - typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs, - typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride> -struct general_matrix_matrix_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride> -{ - -typedef gebp_traits<LhsScalar,RhsScalar> Traits; - -typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; -static void run(Index rows, Index cols, Index depth, - const LhsScalar* _lhs, Index lhsStride, - const RhsScalar* _rhs, Index rhsStride, - ResScalar* _res, Index resIncr, Index resStride, - ResScalar alpha, - level3_blocking<LhsScalar,RhsScalar>& blocking, - GemmParallelInfo<Index>* info = 0) -{ - typedef const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> LhsMapper; - typedef const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> RhsMapper; - typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor,Unaligned,ResInnerStride> ResMapper; - LhsMapper lhs(_lhs, lhsStride); - RhsMapper rhs(_rhs, rhsStride); - ResMapper res(_res, resStride, resIncr); - - Index kc = blocking.kc(); // cache block size along the K direction - Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction - Index nc = (std::min)(cols,blocking.nc()); // cache block size along the N direction - - gemm_pack_lhs<LhsScalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs; - gemm_pack_rhs<RhsScalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs; - gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp; - -#ifdef EIGEN_HAS_OPENMP - if(info) - { - // this is the parallel version! - int tid = omp_get_thread_num(); - int threads = omp_get_num_threads(); - - LhsScalar* blockA = blocking.blockA(); - eigen_internal_assert(blockA!=0); - - std::size_t sizeB = kc*nc; - ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, 0); - - // For each horizontal panel of the rhs, and corresponding vertical panel of the lhs... - for(Index k=0; k<depth; k+=kc) - { - const Index actual_kc = (std::min)(k+kc,depth)-k; // => rows of B', and cols of the A' - - // In order to reduce the chance that a thread has to wait for the other, - // let's start by packing B'. - pack_rhs(blockB, rhs.getSubMapper(k,0), actual_kc, nc); - - // Pack A_k to A' in a parallel fashion: - // each thread packs the sub block A_k,i to A'_i where i is the thread id. - - // However, before copying to A'_i, we have to make sure that no other thread is still using it, - // i.e., we test that info[tid].users equals 0. - // Then, we set info[tid].users to the number of threads to mark that all other threads are going to use it. - while(info[tid].users!=0) {} - info[tid].users = threads; - - pack_lhs(blockA+info[tid].lhs_start*actual_kc, lhs.getSubMapper(info[tid].lhs_start,k), actual_kc, info[tid].lhs_length); - - // Notify the other threads that the part A'_i is ready to go. - info[tid].sync = k; - - // Computes C_i += A' * B' per A'_i - for(int shift=0; shift<threads; ++shift) - { - int i = (tid+shift)%threads; - - // At this point we have to make sure that A'_i has been updated by the thread i, - // we use testAndSetOrdered to mimic a volatile access. - // However, no need to wait for the B' part which has been updated by the current thread! - if (shift>0) { - while(info[i].sync!=k) { - } - } - - gebp(res.getSubMapper(info[i].lhs_start, 0), blockA+info[i].lhs_start*actual_kc, blockB, info[i].lhs_length, actual_kc, nc, alpha); - } - - // Then keep going as usual with the remaining B' - for(Index j=nc; j<cols; j+=nc) - { - const Index actual_nc = (std::min)(j+nc,cols)-j; - - // pack B_k,j to B' - pack_rhs(blockB, rhs.getSubMapper(k,j), actual_kc, actual_nc); - - // C_j += A' * B' - gebp(res.getSubMapper(0, j), blockA, blockB, rows, actual_kc, actual_nc, alpha); - } - - // Release all the sub blocks A'_i of A' for the current thread, - // i.e., we simply decrement the number of users by 1 - for(Index i=0; i<threads; ++i) -#if !EIGEN_HAS_CXX11_ATOMIC - #pragma omp atomic -#endif - info[i].users -= 1; - } - } - else -#endif // EIGEN_HAS_OPENMP - { - EIGEN_UNUSED_VARIABLE(info); - - // this is the sequential version! - std::size_t sizeA = kc*mc; - std::size_t sizeB = kc*nc; - - ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA()); - ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB()); - - const bool pack_rhs_once = mc!=rows && kc==depth && nc==cols; - - // For each horizontal panel of the rhs, and corresponding panel of the lhs... - for(Index i2=0; i2<rows; i2+=mc) - { - const Index actual_mc = (std::min)(i2+mc,rows)-i2; - - for(Index k2=0; k2<depth; k2+=kc) - { - const Index actual_kc = (std::min)(k2+kc,depth)-k2; - - // OK, here we have selected one horizontal panel of rhs and one vertical panel of lhs. - // => Pack lhs's panel into a sequential chunk of memory (L2/L3 caching) - // Note that this panel will be read as many times as the number of blocks in the rhs's - // horizontal panel which is, in practice, a very low number. - pack_lhs(blockA, lhs.getSubMapper(i2,k2), actual_kc, actual_mc); - - // For each kc x nc block of the rhs's horizontal panel... - for(Index j2=0; j2<cols; j2+=nc) - { - const Index actual_nc = (std::min)(j2+nc,cols)-j2; - - // We pack the rhs's block into a sequential chunk of memory (L2 caching) - // Note that this block will be read a very high number of times, which is equal to the number of - // micro horizontal panel of the large rhs's panel (e.g., rows/12 times). - if((!pack_rhs_once) || i2==0) - pack_rhs(blockB, rhs.getSubMapper(k2,j2), actual_kc, actual_nc); - - // Everything is packed, we can now call the panel * block kernel: - gebp(res.getSubMapper(i2, j2), blockA, blockB, actual_mc, actual_kc, actual_nc, alpha); - } - } - } - } -} - -}; - -/********************************************************************************* -* Specialization of generic_product_impl for "large" GEMM, i.e., -* implementation of the high level wrapper to general_matrix_matrix_product -**********************************************************************************/ - -template<typename Scalar, typename Index, typename Gemm, typename Lhs, typename Rhs, typename Dest, typename BlockingType> -struct gemm_functor -{ - gemm_functor(const Lhs& lhs, const Rhs& rhs, Dest& dest, const Scalar& actualAlpha, BlockingType& blocking) - : m_lhs(lhs), m_rhs(rhs), m_dest(dest), m_actualAlpha(actualAlpha), m_blocking(blocking) - {} - - void initParallelSession(Index num_threads) const - { - m_blocking.initParallel(m_lhs.rows(), m_rhs.cols(), m_lhs.cols(), num_threads); - m_blocking.allocateA(); - } - - void operator() (Index row, Index rows, Index col=0, Index cols=-1, GemmParallelInfo<Index>* info=0) const - { - if(cols==-1) - cols = m_rhs.cols(); - - Gemm::run(rows, cols, m_lhs.cols(), - &m_lhs.coeffRef(row,0), m_lhs.outerStride(), - &m_rhs.coeffRef(0,col), m_rhs.outerStride(), - (Scalar*)&(m_dest.coeffRef(row,col)), m_dest.innerStride(), m_dest.outerStride(), - m_actualAlpha, m_blocking, info); - } - - typedef typename Gemm::Traits Traits; - - protected: - const Lhs& m_lhs; - const Rhs& m_rhs; - Dest& m_dest; - Scalar m_actualAlpha; - BlockingType& m_blocking; -}; - -template<int StorageOrder, typename LhsScalar, typename RhsScalar, int MaxRows, int MaxCols, int MaxDepth, int KcFactor=1, -bool FiniteAtCompileTime = MaxRows!=Dynamic && MaxCols!=Dynamic && MaxDepth != Dynamic> class gemm_blocking_space; - -template<typename _LhsScalar, typename _RhsScalar> -class level3_blocking -{ - typedef _LhsScalar LhsScalar; - typedef _RhsScalar RhsScalar; - - protected: - LhsScalar* m_blockA; - RhsScalar* m_blockB; - - Index m_mc; - Index m_nc; - Index m_kc; - - public: - - level3_blocking() - : m_blockA(0), m_blockB(0), m_mc(0), m_nc(0), m_kc(0) - {} - - inline Index mc() const { return m_mc; } - inline Index nc() const { return m_nc; } - inline Index kc() const { return m_kc; } - - inline LhsScalar* blockA() { return m_blockA; } - inline RhsScalar* blockB() { return m_blockB; } -}; - -template<int StorageOrder, typename _LhsScalar, typename _RhsScalar, int MaxRows, int MaxCols, int MaxDepth, int KcFactor> -class gemm_blocking_space<StorageOrder,_LhsScalar,_RhsScalar,MaxRows, MaxCols, MaxDepth, KcFactor, true /* == FiniteAtCompileTime */> - : public level3_blocking< - typename conditional<StorageOrder==RowMajor,_RhsScalar,_LhsScalar>::type, - typename conditional<StorageOrder==RowMajor,_LhsScalar,_RhsScalar>::type> -{ - enum { - Transpose = StorageOrder==RowMajor, - ActualRows = Transpose ? MaxCols : MaxRows, - ActualCols = Transpose ? MaxRows : MaxCols - }; - typedef typename conditional<Transpose,_RhsScalar,_LhsScalar>::type LhsScalar; - typedef typename conditional<Transpose,_LhsScalar,_RhsScalar>::type RhsScalar; - typedef gebp_traits<LhsScalar,RhsScalar> Traits; - enum { - SizeA = ActualRows * MaxDepth, - SizeB = ActualCols * MaxDepth - }; - -#if EIGEN_MAX_STATIC_ALIGN_BYTES >= EIGEN_DEFAULT_ALIGN_BYTES - EIGEN_ALIGN_MAX LhsScalar m_staticA[SizeA]; - EIGEN_ALIGN_MAX RhsScalar m_staticB[SizeB]; -#else - EIGEN_ALIGN_MAX char m_staticA[SizeA * sizeof(LhsScalar) + EIGEN_DEFAULT_ALIGN_BYTES-1]; - EIGEN_ALIGN_MAX char m_staticB[SizeB * sizeof(RhsScalar) + EIGEN_DEFAULT_ALIGN_BYTES-1]; -#endif - - public: - - gemm_blocking_space(Index /*rows*/, Index /*cols*/, Index /*depth*/, Index /*num_threads*/, bool /*full_rows = false*/) - { - this->m_mc = ActualRows; - this->m_nc = ActualCols; - this->m_kc = MaxDepth; -#if EIGEN_MAX_STATIC_ALIGN_BYTES >= EIGEN_DEFAULT_ALIGN_BYTES - this->m_blockA = m_staticA; - this->m_blockB = m_staticB; -#else - this->m_blockA = reinterpret_cast<LhsScalar*>((internal::UIntPtr(m_staticA) + (EIGEN_DEFAULT_ALIGN_BYTES-1)) & ~std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1)); - this->m_blockB = reinterpret_cast<RhsScalar*>((internal::UIntPtr(m_staticB) + (EIGEN_DEFAULT_ALIGN_BYTES-1)) & ~std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1)); -#endif - } - - void initParallel(Index, Index, Index, Index) - {} - - inline void allocateA() {} - inline void allocateB() {} - inline void allocateAll() {} -}; - -template<int StorageOrder, typename _LhsScalar, typename _RhsScalar, int MaxRows, int MaxCols, int MaxDepth, int KcFactor> -class gemm_blocking_space<StorageOrder,_LhsScalar,_RhsScalar,MaxRows, MaxCols, MaxDepth, KcFactor, false> - : public level3_blocking< - typename conditional<StorageOrder==RowMajor,_RhsScalar,_LhsScalar>::type, - typename conditional<StorageOrder==RowMajor,_LhsScalar,_RhsScalar>::type> -{ - enum { - Transpose = StorageOrder==RowMajor - }; - typedef typename conditional<Transpose,_RhsScalar,_LhsScalar>::type LhsScalar; - typedef typename conditional<Transpose,_LhsScalar,_RhsScalar>::type RhsScalar; - typedef gebp_traits<LhsScalar,RhsScalar> Traits; - - Index m_sizeA; - Index m_sizeB; - - public: - - gemm_blocking_space(Index rows, Index cols, Index depth, Index num_threads, bool l3_blocking) - { - this->m_mc = Transpose ? cols : rows; - this->m_nc = Transpose ? rows : cols; - this->m_kc = depth; - - if(l3_blocking) - { - computeProductBlockingSizes<LhsScalar,RhsScalar,KcFactor>(this->m_kc, this->m_mc, this->m_nc, num_threads); - } - else // no l3 blocking - { - Index n = this->m_nc; - computeProductBlockingSizes<LhsScalar,RhsScalar,KcFactor>(this->m_kc, this->m_mc, n, num_threads); - } - - m_sizeA = this->m_mc * this->m_kc; - m_sizeB = this->m_kc * this->m_nc; - } - - void initParallel(Index rows, Index cols, Index depth, Index num_threads) - { - this->m_mc = Transpose ? cols : rows; - this->m_nc = Transpose ? rows : cols; - this->m_kc = depth; - - eigen_internal_assert(this->m_blockA==0 && this->m_blockB==0); - Index m = this->m_mc; - computeProductBlockingSizes<LhsScalar,RhsScalar,KcFactor>(this->m_kc, m, this->m_nc, num_threads); - m_sizeA = this->m_mc * this->m_kc; - m_sizeB = this->m_kc * this->m_nc; - } - - void allocateA() - { - if(this->m_blockA==0) - this->m_blockA = aligned_new<LhsScalar>(m_sizeA); - } - - void allocateB() - { - if(this->m_blockB==0) - this->m_blockB = aligned_new<RhsScalar>(m_sizeB); - } - - void allocateAll() - { - allocateA(); - allocateB(); - } - - ~gemm_blocking_space() - { - aligned_delete(this->m_blockA, m_sizeA); - aligned_delete(this->m_blockB, m_sizeB); - } -}; - -} // end namespace internal - -namespace internal { - -template<typename Lhs, typename Rhs> -struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct> - : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct> > -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - typedef typename Lhs::Scalar LhsScalar; - typedef typename Rhs::Scalar RhsScalar; - - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; - typedef typename internal::remove_all<ActualLhsType>::type ActualLhsTypeCleaned; - - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned; - - enum { - MaxDepthAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(Lhs::MaxColsAtCompileTime,Rhs::MaxRowsAtCompileTime) - }; - - typedef generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode> lazyproduct; - - template<typename Dst> - static void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=404 for a discussion and helper program - // to determine the following heuristic. - // EIGEN_GEMM_TO_COEFFBASED_THRESHOLD is typically defined to 20 in GeneralProduct.h, - // unless it has been specialized by the user or for a given architecture. - // Note that the condition rhs.rows()>0 was required because lazy product is (was?) not happy with empty inputs. - // I'm not sure it is still required. - if((rhs.rows()+dst.rows()+dst.cols())<EIGEN_GEMM_TO_COEFFBASED_THRESHOLD && rhs.rows()>0) - lazyproduct::eval_dynamic(dst, lhs, rhs, internal::assign_op<typename Dst::Scalar,Scalar>()); - else - { - dst.setZero(); - scaleAndAddTo(dst, lhs, rhs, Scalar(1)); - } - } - - template<typename Dst> - static void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - if((rhs.rows()+dst.rows()+dst.cols())<EIGEN_GEMM_TO_COEFFBASED_THRESHOLD && rhs.rows()>0) - lazyproduct::eval_dynamic(dst, lhs, rhs, internal::add_assign_op<typename Dst::Scalar,Scalar>()); - else - scaleAndAddTo(dst,lhs, rhs, Scalar(1)); - } - - template<typename Dst> - static void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) - { - if((rhs.rows()+dst.rows()+dst.cols())<EIGEN_GEMM_TO_COEFFBASED_THRESHOLD && rhs.rows()>0) - lazyproduct::eval_dynamic(dst, lhs, rhs, internal::sub_assign_op<typename Dst::Scalar,Scalar>()); - else - scaleAndAddTo(dst, lhs, rhs, Scalar(-1)); - } - - template<typename Dest> - static void scaleAndAddTo(Dest& dst, const Lhs& a_lhs, const Rhs& a_rhs, const Scalar& alpha) - { - eigen_assert(dst.rows()==a_lhs.rows() && dst.cols()==a_rhs.cols()); - if(a_lhs.cols()==0 || a_lhs.rows()==0 || a_rhs.cols()==0) - return; - - // Fallback to GEMV if either the lhs or rhs is a runtime vector - if (dst.cols() == 1) - { - typename Dest::ColXpr dst_vec(dst.col(0)); - return internal::generic_product_impl<Lhs,typename Rhs::ConstColXpr,DenseShape,DenseShape,GemvProduct> - ::scaleAndAddTo(dst_vec, a_lhs, a_rhs.col(0), alpha); - } - else if (dst.rows() == 1) - { - typename Dest::RowXpr dst_vec(dst.row(0)); - return internal::generic_product_impl<typename Lhs::ConstRowXpr,Rhs,DenseShape,DenseShape,GemvProduct> - ::scaleAndAddTo(dst_vec, a_lhs.row(0), a_rhs, alpha); - } - - typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs); - typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs); - - Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(a_lhs) - * RhsBlasTraits::extractScalarFactor(a_rhs); - - typedef internal::gemm_blocking_space<(Dest::Flags&RowMajorBit) ? RowMajor : ColMajor,LhsScalar,RhsScalar, - Dest::MaxRowsAtCompileTime,Dest::MaxColsAtCompileTime,MaxDepthAtCompileTime> BlockingType; - - typedef internal::gemm_functor< - Scalar, Index, - internal::general_matrix_matrix_product< - Index, - LhsScalar, (ActualLhsTypeCleaned::Flags&RowMajorBit) ? RowMajor : ColMajor, bool(LhsBlasTraits::NeedToConjugate), - RhsScalar, (ActualRhsTypeCleaned::Flags&RowMajorBit) ? RowMajor : ColMajor, bool(RhsBlasTraits::NeedToConjugate), - (Dest::Flags&RowMajorBit) ? RowMajor : ColMajor, - Dest::InnerStrideAtCompileTime>, - ActualLhsTypeCleaned, ActualRhsTypeCleaned, Dest, BlockingType> GemmFunctor; - - BlockingType blocking(dst.rows(), dst.cols(), lhs.cols(), 1, true); - internal::parallelize_gemm<(Dest::MaxRowsAtCompileTime>32 || Dest::MaxRowsAtCompileTime==Dynamic)> - (GemmFunctor(lhs, rhs, dst, actualAlpha, blocking), a_lhs.rows(), a_rhs.cols(), a_lhs.cols(), Dest::Flags&RowMajorBit); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_GENERAL_MATRIX_MATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h b/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h deleted file mode 100644 index 6ba0d9bd..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +++ /dev/null @@ -1,317 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H -#define EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H - -namespace Eigen { - -template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjLhs, bool ConjRhs> -struct selfadjoint_rank1_update; - -namespace internal { - -/********************************************************************** -* This file implements a general A * B product while -* evaluating only one triangular part of the product. -* This is a more general version of self adjoint product (C += A A^T) -* as the level 3 SYRK Blas routine. -**********************************************************************/ - -// forward declarations (defined at the end of this file) -template<typename LhsScalar, typename RhsScalar, typename Index, int mr, int nr, bool ConjLhs, bool ConjRhs, int ResInnerStride, int UpLo> -struct tribb_kernel; - -/* Optimized matrix-matrix product evaluating only one triangular half */ -template <typename Index, - typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs, - typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs, - int ResStorageOrder, int ResInnerStride, int UpLo, int Version = Specialized> -struct general_matrix_matrix_triangular_product; - -// as usual if the result is row major => we transpose the product -template <typename Index, typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs, - typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride, int UpLo, int Version> -struct general_matrix_matrix_triangular_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,RowMajor,ResInnerStride,UpLo,Version> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - static EIGEN_STRONG_INLINE void run(Index size, Index depth,const LhsScalar* lhs, Index lhsStride, - const RhsScalar* rhs, Index rhsStride, ResScalar* res, Index resIncr, Index resStride, - const ResScalar& alpha, level3_blocking<RhsScalar,LhsScalar>& blocking) - { - general_matrix_matrix_triangular_product<Index, - RhsScalar, RhsStorageOrder==RowMajor ? ColMajor : RowMajor, ConjugateRhs, - LhsScalar, LhsStorageOrder==RowMajor ? ColMajor : RowMajor, ConjugateLhs, - ColMajor, ResInnerStride, UpLo==Lower?Upper:Lower> - ::run(size,depth,rhs,rhsStride,lhs,lhsStride,res,resIncr,resStride,alpha,blocking); - } -}; - -template <typename Index, typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs, - typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride, int UpLo, int Version> -struct general_matrix_matrix_triangular_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,UpLo,Version> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - static EIGEN_STRONG_INLINE void run(Index size, Index depth,const LhsScalar* _lhs, Index lhsStride, - const RhsScalar* _rhs, Index rhsStride, - ResScalar* _res, Index resIncr, Index resStride, - const ResScalar& alpha, level3_blocking<LhsScalar,RhsScalar>& blocking) - { - typedef gebp_traits<LhsScalar,RhsScalar> Traits; - - typedef const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> LhsMapper; - typedef const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> RhsMapper; - typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper; - LhsMapper lhs(_lhs,lhsStride); - RhsMapper rhs(_rhs,rhsStride); - ResMapper res(_res, resStride, resIncr); - - Index kc = blocking.kc(); - Index mc = (std::min)(size,blocking.mc()); - - // !!! mc must be a multiple of nr: - if(mc > Traits::nr) - mc = (mc/Traits::nr)*Traits::nr; - - std::size_t sizeA = kc*mc; - std::size_t sizeB = kc*size; - - ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA()); - ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB()); - - gemm_pack_lhs<LhsScalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs; - gemm_pack_rhs<RhsScalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs; - gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp; - tribb_kernel<LhsScalar, RhsScalar, Index, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs, ResInnerStride, UpLo> sybb; - - for(Index k2=0; k2<depth; k2+=kc) - { - const Index actual_kc = (std::min)(k2+kc,depth)-k2; - - // note that the actual rhs is the transpose/adjoint of mat - pack_rhs(blockB, rhs.getSubMapper(k2,0), actual_kc, size); - - for(Index i2=0; i2<size; i2+=mc) - { - const Index actual_mc = (std::min)(i2+mc,size)-i2; - - pack_lhs(blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc); - - // the selected actual_mc * size panel of res is split into three different part: - // 1 - before the diagonal => processed with gebp or skipped - // 2 - the actual_mc x actual_mc symmetric block => processed with a special kernel - // 3 - after the diagonal => processed with gebp or skipped - if (UpLo==Lower) - gebp(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, - (std::min)(size,i2), alpha, -1, -1, 0, 0); - - sybb(_res+resStride*i2 + resIncr*i2, resIncr, resStride, blockA, blockB + actual_kc*i2, actual_mc, actual_kc, alpha); - - if (UpLo==Upper) - { - Index j2 = i2+actual_mc; - gebp(res.getSubMapper(i2, j2), blockA, blockB+actual_kc*j2, actual_mc, - actual_kc, (std::max)(Index(0), size-j2), alpha, -1, -1, 0, 0); - } - } - } - } -}; - -// Optimized packed Block * packed Block product kernel evaluating only one given triangular part -// This kernel is built on top of the gebp kernel: -// - the current destination block is processed per panel of actual_mc x BlockSize -// where BlockSize is set to the minimal value allowing gebp to be as fast as possible -// - then, as usual, each panel is split into three parts along the diagonal, -// the sub blocks above and below the diagonal are processed as usual, -// while the triangular block overlapping the diagonal is evaluated into a -// small temporary buffer which is then accumulated into the result using a -// triangular traversal. -template<typename LhsScalar, typename RhsScalar, typename Index, int mr, int nr, bool ConjLhs, bool ConjRhs, int ResInnerStride, int UpLo> -struct tribb_kernel -{ - typedef gebp_traits<LhsScalar,RhsScalar,ConjLhs,ConjRhs> Traits; - typedef typename Traits::ResScalar ResScalar; - - enum { - BlockSize = meta_least_common_multiple<EIGEN_PLAIN_ENUM_MAX(mr,nr),EIGEN_PLAIN_ENUM_MIN(mr,nr)>::ret - }; - void operator()(ResScalar* _res, Index resIncr, Index resStride, const LhsScalar* blockA, const RhsScalar* blockB, Index size, Index depth, const ResScalar& alpha) - { - typedef blas_data_mapper<ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper; - typedef blas_data_mapper<ResScalar, Index, ColMajor, Unaligned> BufferMapper; - ResMapper res(_res, resStride, resIncr); - gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, mr, nr, ConjLhs, ConjRhs> gebp_kernel1; - gebp_kernel<LhsScalar, RhsScalar, Index, BufferMapper, mr, nr, ConjLhs, ConjRhs> gebp_kernel2; - - Matrix<ResScalar,BlockSize,BlockSize,ColMajor> buffer((internal::constructor_without_unaligned_array_assert())); - - // let's process the block per panel of actual_mc x BlockSize, - // again, each is split into three parts, etc. - for (Index j=0; j<size; j+=BlockSize) - { - Index actualBlockSize = std::min<Index>(BlockSize,size - j); - const RhsScalar* actual_b = blockB+j*depth; - - if(UpLo==Upper) - gebp_kernel1(res.getSubMapper(0, j), blockA, actual_b, j, depth, actualBlockSize, alpha, - -1, -1, 0, 0); - - // selfadjoint micro block - { - Index i = j; - buffer.setZero(); - // 1 - apply the kernel on the temporary buffer - gebp_kernel2(BufferMapper(buffer.data(), BlockSize), blockA+depth*i, actual_b, actualBlockSize, depth, actualBlockSize, alpha, - -1, -1, 0, 0); - - // 2 - triangular accumulation - for(Index j1=0; j1<actualBlockSize; ++j1) - { - typename ResMapper::LinearMapper r = res.getLinearMapper(i,j+j1); - for(Index i1=UpLo==Lower ? j1 : 0; - UpLo==Lower ? i1<actualBlockSize : i1<=j1; ++i1) - r(i1) += buffer(i1,j1); - } - } - - if(UpLo==Lower) - { - Index i = j+actualBlockSize; - gebp_kernel1(res.getSubMapper(i, j), blockA+depth*i, actual_b, size-i, - depth, actualBlockSize, alpha, -1, -1, 0, 0); - } - } - } -}; - -} // end namespace internal - -// high level API - -template<typename MatrixType, typename ProductType, int UpLo, bool IsOuterProduct> -struct general_product_to_triangular_selector; - - -template<typename MatrixType, typename ProductType, int UpLo> -struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,true> -{ - static void run(MatrixType& mat, const ProductType& prod, const typename MatrixType::Scalar& alpha, bool beta) - { - typedef typename MatrixType::Scalar Scalar; - - typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs; - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs; - typedef typename internal::remove_all<ActualLhs>::type _ActualLhs; - typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs()); - - typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs; - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs; - typedef typename internal::remove_all<ActualRhs>::type _ActualRhs; - typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs()); - - Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived()); - - if(!beta) - mat.template triangularView<UpLo>().setZero(); - - enum { - StorageOrder = (internal::traits<MatrixType>::Flags&RowMajorBit) ? RowMajor : ColMajor, - UseLhsDirectly = _ActualLhs::InnerStrideAtCompileTime==1, - UseRhsDirectly = _ActualRhs::InnerStrideAtCompileTime==1 - }; - - internal::gemv_static_vector_if<Scalar,Lhs::SizeAtCompileTime,Lhs::MaxSizeAtCompileTime,!UseLhsDirectly> static_lhs; - ei_declare_aligned_stack_constructed_variable(Scalar, actualLhsPtr, actualLhs.size(), - (UseLhsDirectly ? const_cast<Scalar*>(actualLhs.data()) : static_lhs.data())); - if(!UseLhsDirectly) Map<typename _ActualLhs::PlainObject>(actualLhsPtr, actualLhs.size()) = actualLhs; - - internal::gemv_static_vector_if<Scalar,Rhs::SizeAtCompileTime,Rhs::MaxSizeAtCompileTime,!UseRhsDirectly> static_rhs; - ei_declare_aligned_stack_constructed_variable(Scalar, actualRhsPtr, actualRhs.size(), - (UseRhsDirectly ? const_cast<Scalar*>(actualRhs.data()) : static_rhs.data())); - if(!UseRhsDirectly) Map<typename _ActualRhs::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs; - - - selfadjoint_rank1_update<Scalar,Index,StorageOrder,UpLo, - LhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex, - RhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex> - ::run(actualLhs.size(), mat.data(), mat.outerStride(), actualLhsPtr, actualRhsPtr, actualAlpha); - } -}; - -template<typename MatrixType, typename ProductType, int UpLo> -struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,false> -{ - static void run(MatrixType& mat, const ProductType& prod, const typename MatrixType::Scalar& alpha, bool beta) - { - typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs; - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs; - typedef typename internal::remove_all<ActualLhs>::type _ActualLhs; - typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs()); - - typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs; - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs; - typedef typename internal::remove_all<ActualRhs>::type _ActualRhs; - typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs()); - - typename ProductType::Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived()); - - if(!beta) - mat.template triangularView<UpLo>().setZero(); - - enum { - IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0, - LhsIsRowMajor = _ActualLhs::Flags&RowMajorBit ? 1 : 0, - RhsIsRowMajor = _ActualRhs::Flags&RowMajorBit ? 1 : 0, - SkipDiag = (UpLo&(UnitDiag|ZeroDiag))!=0 - }; - - Index size = mat.cols(); - if(SkipDiag) - size--; - Index depth = actualLhs.cols(); - - typedef internal::gemm_blocking_space<IsRowMajor ? RowMajor : ColMajor,typename Lhs::Scalar,typename Rhs::Scalar, - MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime, _ActualRhs::MaxColsAtCompileTime> BlockingType; - - BlockingType blocking(size, size, depth, 1, false); - - internal::general_matrix_matrix_triangular_product<Index, - typename Lhs::Scalar, LhsIsRowMajor ? RowMajor : ColMajor, LhsBlasTraits::NeedToConjugate, - typename Rhs::Scalar, RhsIsRowMajor ? RowMajor : ColMajor, RhsBlasTraits::NeedToConjugate, - IsRowMajor ? RowMajor : ColMajor, MatrixType::InnerStrideAtCompileTime, UpLo&(Lower|Upper)> - ::run(size, depth, - &actualLhs.coeffRef(SkipDiag&&(UpLo&Lower)==Lower ? 1 : 0,0), actualLhs.outerStride(), - &actualRhs.coeffRef(0,SkipDiag&&(UpLo&Upper)==Upper ? 1 : 0), actualRhs.outerStride(), - mat.data() + (SkipDiag ? (bool(IsRowMajor) != ((UpLo&Lower)==Lower) ? mat.innerStride() : mat.outerStride() ) : 0), - mat.innerStride(), mat.outerStride(), actualAlpha, blocking); - } -}; - -template<typename MatrixType, unsigned int UpLo> -template<typename ProductType> -EIGEN_DEVICE_FUNC TriangularView<MatrixType,UpLo>& TriangularViewImpl<MatrixType,UpLo,Dense>::_assignProduct(const ProductType& prod, const Scalar& alpha, bool beta) -{ - EIGEN_STATIC_ASSERT((UpLo&UnitDiag)==0, WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED); - eigen_assert(derived().nestedExpression().rows() == prod.rows() && derived().cols() == prod.cols()); - - general_product_to_triangular_selector<MatrixType, ProductType, UpLo, internal::traits<ProductType>::InnerSize==1>::run(derived().nestedExpression().const_cast_derived(), prod, alpha, beta); - - return derived(); -} - -} // end namespace Eigen - -#endif // EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h b/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h deleted file mode 100644 index 9a650ec2..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to BLAS F77 - * Level 3 BLAS SYRK/HERK implementation. - ******************************************************************************** -*/ - -#ifndef EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H -#define EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H - -namespace Eigen { - -namespace internal { - -template <typename Index, typename Scalar, int AStorageOrder, bool ConjugateA, int ResStorageOrder, int UpLo> -struct general_matrix_matrix_rankupdate : - general_matrix_matrix_triangular_product< - Index,Scalar,AStorageOrder,ConjugateA,Scalar,AStorageOrder,ConjugateA,ResStorageOrder,1,UpLo,BuiltIn> {}; - - -// try to go to BLAS specialization -#define EIGEN_BLAS_RANKUPDATE_SPECIALIZE(Scalar) \ -template <typename Index, int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs, int UpLo> \ -struct general_matrix_matrix_triangular_product<Index,Scalar,LhsStorageOrder,ConjugateLhs, \ - Scalar,RhsStorageOrder,ConjugateRhs,ColMajor,1,UpLo,Specialized> { \ - static EIGEN_STRONG_INLINE void run(Index size, Index depth,const Scalar* lhs, Index lhsStride, \ - const Scalar* rhs, Index rhsStride, Scalar* res, Index resIncr, Index resStride, Scalar alpha, level3_blocking<Scalar, Scalar>& blocking) \ - { \ - if ( lhs==rhs && ((UpLo&(Lower|Upper))==UpLo) ) { \ - general_matrix_matrix_rankupdate<Index,Scalar,LhsStorageOrder,ConjugateLhs,ColMajor,UpLo> \ - ::run(size,depth,lhs,lhsStride,rhs,rhsStride,res,resStride,alpha,blocking); \ - } else { \ - general_matrix_matrix_triangular_product<Index, \ - Scalar, LhsStorageOrder, ConjugateLhs, \ - Scalar, RhsStorageOrder, ConjugateRhs, \ - ColMajor, 1, UpLo, BuiltIn> \ - ::run(size,depth,lhs,lhsStride,rhs,rhsStride,res,resIncr,resStride,alpha,blocking); \ - } \ - } \ -}; - -EIGEN_BLAS_RANKUPDATE_SPECIALIZE(double) -EIGEN_BLAS_RANKUPDATE_SPECIALIZE(float) -// TODO handle complex cases -// EIGEN_BLAS_RANKUPDATE_SPECIALIZE(dcomplex) -// EIGEN_BLAS_RANKUPDATE_SPECIALIZE(scomplex) - -// SYRK for float/double -#define EIGEN_BLAS_RANKUPDATE_R(EIGTYPE, BLASTYPE, BLASFUNC) \ -template <typename Index, int AStorageOrder, bool ConjugateA, int UpLo> \ -struct general_matrix_matrix_rankupdate<Index,EIGTYPE,AStorageOrder,ConjugateA,ColMajor,UpLo> { \ - enum { \ - IsLower = (UpLo&Lower) == Lower, \ - LowUp = IsLower ? Lower : Upper, \ - conjA = ((AStorageOrder==ColMajor) && ConjugateA) ? 1 : 0 \ - }; \ - static EIGEN_STRONG_INLINE void run(Index size, Index depth,const EIGTYPE* lhs, Index lhsStride, \ - const EIGTYPE* /*rhs*/, Index /*rhsStride*/, EIGTYPE* res, Index resStride, EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \ - { \ - /* typedef Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> MatrixRhs;*/ \ -\ - BlasIndex lda=convert_index<BlasIndex>(lhsStride), ldc=convert_index<BlasIndex>(resStride), n=convert_index<BlasIndex>(size), k=convert_index<BlasIndex>(depth); \ - char uplo=((IsLower) ? 'L' : 'U'), trans=((AStorageOrder==RowMajor) ? 'T':'N'); \ - EIGTYPE beta(1); \ - BLASFUNC(&uplo, &trans, &n, &k, (const BLASTYPE*)&numext::real_ref(alpha), lhs, &lda, (const BLASTYPE*)&numext::real_ref(beta), res, &ldc); \ - } \ -}; - -// HERK for complex data -#define EIGEN_BLAS_RANKUPDATE_C(EIGTYPE, BLASTYPE, RTYPE, BLASFUNC) \ -template <typename Index, int AStorageOrder, bool ConjugateA, int UpLo> \ -struct general_matrix_matrix_rankupdate<Index,EIGTYPE,AStorageOrder,ConjugateA,ColMajor,UpLo> { \ - enum { \ - IsLower = (UpLo&Lower) == Lower, \ - LowUp = IsLower ? Lower : Upper, \ - conjA = (((AStorageOrder==ColMajor) && ConjugateA) || ((AStorageOrder==RowMajor) && !ConjugateA)) ? 1 : 0 \ - }; \ - static EIGEN_STRONG_INLINE void run(Index size, Index depth,const EIGTYPE* lhs, Index lhsStride, \ - const EIGTYPE* /*rhs*/, Index /*rhsStride*/, EIGTYPE* res, Index resStride, EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \ - { \ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, AStorageOrder> MatrixType; \ -\ - BlasIndex lda=convert_index<BlasIndex>(lhsStride), ldc=convert_index<BlasIndex>(resStride), n=convert_index<BlasIndex>(size), k=convert_index<BlasIndex>(depth); \ - char uplo=((IsLower) ? 'L' : 'U'), trans=((AStorageOrder==RowMajor) ? 'C':'N'); \ - RTYPE alpha_, beta_; \ - const EIGTYPE* a_ptr; \ -\ - alpha_ = alpha.real(); \ - beta_ = 1.0; \ -/* Copy with conjugation in some cases*/ \ - MatrixType a; \ - if (conjA) { \ - Map<const MatrixType, 0, OuterStride<> > mapA(lhs,n,k,OuterStride<>(lhsStride)); \ - a = mapA.conjugate(); \ - lda = a.outerStride(); \ - a_ptr = a.data(); \ - } else a_ptr=lhs; \ - BLASFUNC(&uplo, &trans, &n, &k, &alpha_, (BLASTYPE*)a_ptr, &lda, &beta_, (BLASTYPE*)res, &ldc); \ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_RANKUPDATE_R(double, double, dsyrk) -EIGEN_BLAS_RANKUPDATE_R(float, float, ssyrk) -#else -EIGEN_BLAS_RANKUPDATE_R(double, double, dsyrk_) -EIGEN_BLAS_RANKUPDATE_R(float, float, ssyrk_) -#endif - -// TODO hanlde complex cases -// EIGEN_BLAS_RANKUPDATE_C(dcomplex, double, double, zherk_) -// EIGEN_BLAS_RANKUPDATE_C(scomplex, float, float, cherk_) - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h b/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h deleted file mode 100644 index 71abf401..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to BLAS F77 - * General matrix-matrix product functionality based on ?GEMM. - ******************************************************************************** -*/ - -#ifndef EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H -#define EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H - -namespace Eigen { - -namespace internal { - -/********************************************************************** -* This file implements general matrix-matrix multiplication using BLAS -* gemm function via partial specialization of -* general_matrix_matrix_product::run(..) method for float, double, -* std::complex<float> and std::complex<double> types -**********************************************************************/ - -// gemm specialization - -#define GEMM_SPECIALIZATION(EIGTYPE, EIGPREFIX, BLASTYPE, BLASFUNC) \ -template< \ - typename Index, \ - int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs> \ -struct general_matrix_matrix_product<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,RhsStorageOrder,ConjugateRhs,ColMajor,1> \ -{ \ -typedef gebp_traits<EIGTYPE,EIGTYPE> Traits; \ -\ -static void run(Index rows, Index cols, Index depth, \ - const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsStride, \ - EIGTYPE* res, Index resIncr, Index resStride, \ - EIGTYPE alpha, \ - level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/, \ - GemmParallelInfo<Index>* /*info = 0*/) \ -{ \ - using std::conj; \ -\ - EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \ - eigen_assert(resIncr == 1); \ - char transa, transb; \ - BlasIndex m, n, k, lda, ldb, ldc; \ - const EIGTYPE *a, *b; \ - EIGTYPE beta(1); \ - MatrixX##EIGPREFIX a_tmp, b_tmp; \ -\ -/* Set transpose options */ \ - transa = (LhsStorageOrder==RowMajor) ? ((ConjugateLhs) ? 'C' : 'T') : 'N'; \ - transb = (RhsStorageOrder==RowMajor) ? ((ConjugateRhs) ? 'C' : 'T') : 'N'; \ -\ -/* Set m, n, k */ \ - m = convert_index<BlasIndex>(rows); \ - n = convert_index<BlasIndex>(cols); \ - k = convert_index<BlasIndex>(depth); \ -\ -/* Set lda, ldb, ldc */ \ - lda = convert_index<BlasIndex>(lhsStride); \ - ldb = convert_index<BlasIndex>(rhsStride); \ - ldc = convert_index<BlasIndex>(resStride); \ -\ -/* Set a, b, c */ \ - if ((LhsStorageOrder==ColMajor) && (ConjugateLhs)) { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,m,k,OuterStride<>(lhsStride)); \ - a_tmp = lhs.conjugate(); \ - a = a_tmp.data(); \ - lda = convert_index<BlasIndex>(a_tmp.outerStride()); \ - } else a = _lhs; \ -\ - if ((RhsStorageOrder==ColMajor) && (ConjugateRhs)) { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,k,n,OuterStride<>(rhsStride)); \ - b_tmp = rhs.conjugate(); \ - b = b_tmp.data(); \ - ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \ - } else b = _rhs; \ -\ - BLASFUNC(&transa, &transb, &m, &n, &k, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \ -}}; - -#ifdef EIGEN_USE_MKL -GEMM_SPECIALIZATION(double, d, double, dgemm) -GEMM_SPECIALIZATION(float, f, float, sgemm) -GEMM_SPECIALIZATION(dcomplex, cd, MKL_Complex16, zgemm) -GEMM_SPECIALIZATION(scomplex, cf, MKL_Complex8, cgemm) -#else -GEMM_SPECIALIZATION(double, d, double, dgemm_) -GEMM_SPECIALIZATION(float, f, float, sgemm_) -GEMM_SPECIALIZATION(dcomplex, cd, double, zgemm_) -GEMM_SPECIALIZATION(scomplex, cf, float, cgemm_) -#endif - -} // end namespase internal - -} // end namespace Eigen - -#endif // EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixVector.h b/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixVector.h deleted file mode 100644 index dfb6aebc..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixVector.h +++ /dev/null @@ -1,518 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERAL_MATRIX_VECTOR_H -#define EIGEN_GENERAL_MATRIX_VECTOR_H - -namespace Eigen { - -namespace internal { - -enum GEMVPacketSizeType { - GEMVPacketFull = 0, - GEMVPacketHalf, - GEMVPacketQuarter -}; - -template <int N, typename T1, typename T2, typename T3> -struct gemv_packet_cond { typedef T3 type; }; - -template <typename T1, typename T2, typename T3> -struct gemv_packet_cond<GEMVPacketFull, T1, T2, T3> { typedef T1 type; }; - -template <typename T1, typename T2, typename T3> -struct gemv_packet_cond<GEMVPacketHalf, T1, T2, T3> { typedef T2 type; }; - -template<typename LhsScalar, typename RhsScalar, int _PacketSize=GEMVPacketFull> -class gemv_traits -{ - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - -#define PACKET_DECL_COND_PREFIX(prefix, name, packet_size) \ - typedef typename gemv_packet_cond<packet_size, \ - typename packet_traits<name ## Scalar>::type, \ - typename packet_traits<name ## Scalar>::half, \ - typename unpacket_traits<typename packet_traits<name ## Scalar>::half>::half>::type \ - prefix ## name ## Packet - - PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize); - PACKET_DECL_COND_PREFIX(_, Res, _PacketSize); -#undef PACKET_DECL_COND_PREFIX - -public: - enum { - Vectorizable = unpacket_traits<_LhsPacket>::vectorizable && - unpacket_traits<_RhsPacket>::vectorizable && - int(unpacket_traits<_LhsPacket>::size)==int(unpacket_traits<_RhsPacket>::size), - LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1, - RhsPacketSize = Vectorizable ? unpacket_traits<_RhsPacket>::size : 1, - ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1 - }; - - typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket; - typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket; - typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket; -}; - - -/* Optimized col-major matrix * vector product: - * This algorithm processes the matrix per vertical panels, - * which are then processed horizontaly per chunck of 8*PacketSize x 1 vertical segments. - * - * Mixing type logic: C += alpha * A * B - * | A | B |alpha| comments - * |real |cplx |cplx | no vectorization - * |real |cplx |real | alpha is converted to a cplx when calling the run function, no vectorization - * |cplx |real |cplx | invalid, the caller has to do tmp: = A * B; C += alpha*tmp - * |cplx |real |real | optimal case, vectorization possible via real-cplx mul - * - * The same reasoning apply for the transposed case. - */ -template<typename Index, typename LhsScalar, typename LhsMapper, bool ConjugateLhs, typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version> -struct general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,ConjugateLhs,RhsScalar,RhsMapper,ConjugateRhs,Version> -{ - typedef gemv_traits<LhsScalar,RhsScalar> Traits; - typedef gemv_traits<LhsScalar,RhsScalar,GEMVPacketHalf> HalfTraits; - typedef gemv_traits<LhsScalar,RhsScalar,GEMVPacketQuarter> QuarterTraits; - - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - - typedef typename Traits::LhsPacket LhsPacket; - typedef typename Traits::RhsPacket RhsPacket; - typedef typename Traits::ResPacket ResPacket; - - typedef typename HalfTraits::LhsPacket LhsPacketHalf; - typedef typename HalfTraits::RhsPacket RhsPacketHalf; - typedef typename HalfTraits::ResPacket ResPacketHalf; - - typedef typename QuarterTraits::LhsPacket LhsPacketQuarter; - typedef typename QuarterTraits::RhsPacket RhsPacketQuarter; - typedef typename QuarterTraits::ResPacket ResPacketQuarter; - -EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE static void run( - Index rows, Index cols, - const LhsMapper& lhs, - const RhsMapper& rhs, - ResScalar* res, Index resIncr, - RhsScalar alpha); -}; - -template<typename Index, typename LhsScalar, typename LhsMapper, bool ConjugateLhs, typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version> -EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE void general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,ConjugateLhs,RhsScalar,RhsMapper,ConjugateRhs,Version>::run( - Index rows, Index cols, - const LhsMapper& alhs, - const RhsMapper& rhs, - ResScalar* res, Index resIncr, - RhsScalar alpha) -{ - EIGEN_UNUSED_VARIABLE(resIncr); - eigen_internal_assert(resIncr==1); - - // The following copy tells the compiler that lhs's attributes are not modified outside this function - // This helps GCC to generate propoer code. - LhsMapper lhs(alhs); - - conj_helper<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs> cj; - conj_helper<LhsPacket,RhsPacket,ConjugateLhs,ConjugateRhs> pcj; - conj_helper<LhsPacketHalf,RhsPacketHalf,ConjugateLhs,ConjugateRhs> pcj_half; - conj_helper<LhsPacketQuarter,RhsPacketQuarter,ConjugateLhs,ConjugateRhs> pcj_quarter; - - const Index lhsStride = lhs.stride(); - // TODO: for padded aligned inputs, we could enable aligned reads - enum { LhsAlignment = Unaligned, - ResPacketSize = Traits::ResPacketSize, - ResPacketSizeHalf = HalfTraits::ResPacketSize, - ResPacketSizeQuarter = QuarterTraits::ResPacketSize, - LhsPacketSize = Traits::LhsPacketSize, - HasHalf = (int)ResPacketSizeHalf < (int)ResPacketSize, - HasQuarter = (int)ResPacketSizeQuarter < (int)ResPacketSizeHalf - }; - - const Index n8 = rows-8*ResPacketSize+1; - const Index n4 = rows-4*ResPacketSize+1; - const Index n3 = rows-3*ResPacketSize+1; - const Index n2 = rows-2*ResPacketSize+1; - const Index n1 = rows-1*ResPacketSize+1; - const Index n_half = rows-1*ResPacketSizeHalf+1; - const Index n_quarter = rows-1*ResPacketSizeQuarter+1; - - // TODO: improve the following heuristic: - const Index block_cols = cols<128 ? cols : (lhsStride*sizeof(LhsScalar)<32000?16:4); - ResPacket palpha = pset1<ResPacket>(alpha); - ResPacketHalf palpha_half = pset1<ResPacketHalf>(alpha); - ResPacketQuarter palpha_quarter = pset1<ResPacketQuarter>(alpha); - - for(Index j2=0; j2<cols; j2+=block_cols) - { - Index jend = numext::mini(j2+block_cols,cols); - Index i=0; - for(; i<n8; i+=ResPacketSize*8) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)), - c1 = pset1<ResPacket>(ResScalar(0)), - c2 = pset1<ResPacket>(ResScalar(0)), - c3 = pset1<ResPacket>(ResScalar(0)), - c4 = pset1<ResPacket>(ResScalar(0)), - c5 = pset1<ResPacket>(ResScalar(0)), - c6 = pset1<ResPacket>(ResScalar(0)), - c7 = pset1<ResPacket>(ResScalar(0)); - - for(Index j=j2; j<jend; j+=1) - { - RhsPacket b0 = pset1<RhsPacket>(rhs(j,0)); - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*0,j),b0,c0); - c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*1,j),b0,c1); - c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*2,j),b0,c2); - c3 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*3,j),b0,c3); - c4 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*4,j),b0,c4); - c5 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*5,j),b0,c5); - c6 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*6,j),b0,c6); - c7 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*7,j),b0,c7); - } - pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0))); - pstoreu(res+i+ResPacketSize*1, pmadd(c1,palpha,ploadu<ResPacket>(res+i+ResPacketSize*1))); - pstoreu(res+i+ResPacketSize*2, pmadd(c2,palpha,ploadu<ResPacket>(res+i+ResPacketSize*2))); - pstoreu(res+i+ResPacketSize*3, pmadd(c3,palpha,ploadu<ResPacket>(res+i+ResPacketSize*3))); - pstoreu(res+i+ResPacketSize*4, pmadd(c4,palpha,ploadu<ResPacket>(res+i+ResPacketSize*4))); - pstoreu(res+i+ResPacketSize*5, pmadd(c5,palpha,ploadu<ResPacket>(res+i+ResPacketSize*5))); - pstoreu(res+i+ResPacketSize*6, pmadd(c6,palpha,ploadu<ResPacket>(res+i+ResPacketSize*6))); - pstoreu(res+i+ResPacketSize*7, pmadd(c7,palpha,ploadu<ResPacket>(res+i+ResPacketSize*7))); - } - if(i<n4) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)), - c1 = pset1<ResPacket>(ResScalar(0)), - c2 = pset1<ResPacket>(ResScalar(0)), - c3 = pset1<ResPacket>(ResScalar(0)); - - for(Index j=j2; j<jend; j+=1) - { - RhsPacket b0 = pset1<RhsPacket>(rhs(j,0)); - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*0,j),b0,c0); - c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*1,j),b0,c1); - c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*2,j),b0,c2); - c3 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*3,j),b0,c3); - } - pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0))); - pstoreu(res+i+ResPacketSize*1, pmadd(c1,palpha,ploadu<ResPacket>(res+i+ResPacketSize*1))); - pstoreu(res+i+ResPacketSize*2, pmadd(c2,palpha,ploadu<ResPacket>(res+i+ResPacketSize*2))); - pstoreu(res+i+ResPacketSize*3, pmadd(c3,palpha,ploadu<ResPacket>(res+i+ResPacketSize*3))); - - i+=ResPacketSize*4; - } - if(i<n3) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)), - c1 = pset1<ResPacket>(ResScalar(0)), - c2 = pset1<ResPacket>(ResScalar(0)); - - for(Index j=j2; j<jend; j+=1) - { - RhsPacket b0 = pset1<RhsPacket>(rhs(j,0)); - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*0,j),b0,c0); - c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*1,j),b0,c1); - c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*2,j),b0,c2); - } - pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0))); - pstoreu(res+i+ResPacketSize*1, pmadd(c1,palpha,ploadu<ResPacket>(res+i+ResPacketSize*1))); - pstoreu(res+i+ResPacketSize*2, pmadd(c2,palpha,ploadu<ResPacket>(res+i+ResPacketSize*2))); - - i+=ResPacketSize*3; - } - if(i<n2) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)), - c1 = pset1<ResPacket>(ResScalar(0)); - - for(Index j=j2; j<jend; j+=1) - { - RhsPacket b0 = pset1<RhsPacket>(rhs(j,0)); - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*0,j),b0,c0); - c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*1,j),b0,c1); - } - pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0))); - pstoreu(res+i+ResPacketSize*1, pmadd(c1,palpha,ploadu<ResPacket>(res+i+ResPacketSize*1))); - i+=ResPacketSize*2; - } - if(i<n1) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)); - for(Index j=j2; j<jend; j+=1) - { - RhsPacket b0 = pset1<RhsPacket>(rhs(j,0)); - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+0,j),b0,c0); - } - pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0))); - i+=ResPacketSize; - } - if(HasHalf && i<n_half) - { - ResPacketHalf c0 = pset1<ResPacketHalf>(ResScalar(0)); - for(Index j=j2; j<jend; j+=1) - { - RhsPacketHalf b0 = pset1<RhsPacketHalf>(rhs(j,0)); - c0 = pcj_half.pmadd(lhs.template load<LhsPacketHalf,LhsAlignment>(i+0,j),b0,c0); - } - pstoreu(res+i+ResPacketSizeHalf*0, pmadd(c0,palpha_half,ploadu<ResPacketHalf>(res+i+ResPacketSizeHalf*0))); - i+=ResPacketSizeHalf; - } - if(HasQuarter && i<n_quarter) - { - ResPacketQuarter c0 = pset1<ResPacketQuarter>(ResScalar(0)); - for(Index j=j2; j<jend; j+=1) - { - RhsPacketQuarter b0 = pset1<RhsPacketQuarter>(rhs(j,0)); - c0 = pcj_quarter.pmadd(lhs.template load<LhsPacketQuarter,LhsAlignment>(i+0,j),b0,c0); - } - pstoreu(res+i+ResPacketSizeQuarter*0, pmadd(c0,palpha_quarter,ploadu<ResPacketQuarter>(res+i+ResPacketSizeQuarter*0))); - i+=ResPacketSizeQuarter; - } - for(;i<rows;++i) - { - ResScalar c0(0); - for(Index j=j2; j<jend; j+=1) - c0 += cj.pmul(lhs(i,j), rhs(j,0)); - res[i] += alpha*c0; - } - } -} - -/* Optimized row-major matrix * vector product: - * This algorithm processes 4 rows at once that allows to both reduce - * the number of load/stores of the result by a factor 4 and to reduce - * the instruction dependency. Moreover, we know that all bands have the - * same alignment pattern. - * - * Mixing type logic: - * - alpha is always a complex (or converted to a complex) - * - no vectorization - */ -template<typename Index, typename LhsScalar, typename LhsMapper, bool ConjugateLhs, typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version> -struct general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,ConjugateLhs,RhsScalar,RhsMapper,ConjugateRhs,Version> -{ - typedef gemv_traits<LhsScalar,RhsScalar> Traits; - typedef gemv_traits<LhsScalar,RhsScalar,GEMVPacketHalf> HalfTraits; - typedef gemv_traits<LhsScalar,RhsScalar,GEMVPacketQuarter> QuarterTraits; - - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - - typedef typename Traits::LhsPacket LhsPacket; - typedef typename Traits::RhsPacket RhsPacket; - typedef typename Traits::ResPacket ResPacket; - - typedef typename HalfTraits::LhsPacket LhsPacketHalf; - typedef typename HalfTraits::RhsPacket RhsPacketHalf; - typedef typename HalfTraits::ResPacket ResPacketHalf; - - typedef typename QuarterTraits::LhsPacket LhsPacketQuarter; - typedef typename QuarterTraits::RhsPacket RhsPacketQuarter; - typedef typename QuarterTraits::ResPacket ResPacketQuarter; - -EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE static void run( - Index rows, Index cols, - const LhsMapper& lhs, - const RhsMapper& rhs, - ResScalar* res, Index resIncr, - ResScalar alpha); -}; - -template<typename Index, typename LhsScalar, typename LhsMapper, bool ConjugateLhs, typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version> -EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE void general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,ConjugateLhs,RhsScalar,RhsMapper,ConjugateRhs,Version>::run( - Index rows, Index cols, - const LhsMapper& alhs, - const RhsMapper& rhs, - ResScalar* res, Index resIncr, - ResScalar alpha) -{ - // The following copy tells the compiler that lhs's attributes are not modified outside this function - // This helps GCC to generate propoer code. - LhsMapper lhs(alhs); - - eigen_internal_assert(rhs.stride()==1); - conj_helper<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs> cj; - conj_helper<LhsPacket,RhsPacket,ConjugateLhs,ConjugateRhs> pcj; - conj_helper<LhsPacketHalf,RhsPacketHalf,ConjugateLhs,ConjugateRhs> pcj_half; - conj_helper<LhsPacketQuarter,RhsPacketQuarter,ConjugateLhs,ConjugateRhs> pcj_quarter; - - // TODO: fine tune the following heuristic. The rationale is that if the matrix is very large, - // processing 8 rows at once might be counter productive wrt cache. - const Index n8 = lhs.stride()*sizeof(LhsScalar)>32000 ? 0 : rows-7; - const Index n4 = rows-3; - const Index n2 = rows-1; - - // TODO: for padded aligned inputs, we could enable aligned reads - enum { LhsAlignment = Unaligned, - ResPacketSize = Traits::ResPacketSize, - ResPacketSizeHalf = HalfTraits::ResPacketSize, - ResPacketSizeQuarter = QuarterTraits::ResPacketSize, - LhsPacketSize = Traits::LhsPacketSize, - LhsPacketSizeHalf = HalfTraits::LhsPacketSize, - LhsPacketSizeQuarter = QuarterTraits::LhsPacketSize, - HasHalf = (int)ResPacketSizeHalf < (int)ResPacketSize, - HasQuarter = (int)ResPacketSizeQuarter < (int)ResPacketSizeHalf - }; - - Index i=0; - for(; i<n8; i+=8) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)), - c1 = pset1<ResPacket>(ResScalar(0)), - c2 = pset1<ResPacket>(ResScalar(0)), - c3 = pset1<ResPacket>(ResScalar(0)), - c4 = pset1<ResPacket>(ResScalar(0)), - c5 = pset1<ResPacket>(ResScalar(0)), - c6 = pset1<ResPacket>(ResScalar(0)), - c7 = pset1<ResPacket>(ResScalar(0)); - - Index j=0; - for(; j+LhsPacketSize<=cols; j+=LhsPacketSize) - { - RhsPacket b0 = rhs.template load<RhsPacket, Unaligned>(j,0); - - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+0,j),b0,c0); - c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+1,j),b0,c1); - c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+2,j),b0,c2); - c3 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+3,j),b0,c3); - c4 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+4,j),b0,c4); - c5 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+5,j),b0,c5); - c6 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+6,j),b0,c6); - c7 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+7,j),b0,c7); - } - ResScalar cc0 = predux(c0); - ResScalar cc1 = predux(c1); - ResScalar cc2 = predux(c2); - ResScalar cc3 = predux(c3); - ResScalar cc4 = predux(c4); - ResScalar cc5 = predux(c5); - ResScalar cc6 = predux(c6); - ResScalar cc7 = predux(c7); - for(; j<cols; ++j) - { - RhsScalar b0 = rhs(j,0); - - cc0 += cj.pmul(lhs(i+0,j), b0); - cc1 += cj.pmul(lhs(i+1,j), b0); - cc2 += cj.pmul(lhs(i+2,j), b0); - cc3 += cj.pmul(lhs(i+3,j), b0); - cc4 += cj.pmul(lhs(i+4,j), b0); - cc5 += cj.pmul(lhs(i+5,j), b0); - cc6 += cj.pmul(lhs(i+6,j), b0); - cc7 += cj.pmul(lhs(i+7,j), b0); - } - res[(i+0)*resIncr] += alpha*cc0; - res[(i+1)*resIncr] += alpha*cc1; - res[(i+2)*resIncr] += alpha*cc2; - res[(i+3)*resIncr] += alpha*cc3; - res[(i+4)*resIncr] += alpha*cc4; - res[(i+5)*resIncr] += alpha*cc5; - res[(i+6)*resIncr] += alpha*cc6; - res[(i+7)*resIncr] += alpha*cc7; - } - for(; i<n4; i+=4) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)), - c1 = pset1<ResPacket>(ResScalar(0)), - c2 = pset1<ResPacket>(ResScalar(0)), - c3 = pset1<ResPacket>(ResScalar(0)); - - Index j=0; - for(; j+LhsPacketSize<=cols; j+=LhsPacketSize) - { - RhsPacket b0 = rhs.template load<RhsPacket, Unaligned>(j,0); - - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+0,j),b0,c0); - c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+1,j),b0,c1); - c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+2,j),b0,c2); - c3 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+3,j),b0,c3); - } - ResScalar cc0 = predux(c0); - ResScalar cc1 = predux(c1); - ResScalar cc2 = predux(c2); - ResScalar cc3 = predux(c3); - for(; j<cols; ++j) - { - RhsScalar b0 = rhs(j,0); - - cc0 += cj.pmul(lhs(i+0,j), b0); - cc1 += cj.pmul(lhs(i+1,j), b0); - cc2 += cj.pmul(lhs(i+2,j), b0); - cc3 += cj.pmul(lhs(i+3,j), b0); - } - res[(i+0)*resIncr] += alpha*cc0; - res[(i+1)*resIncr] += alpha*cc1; - res[(i+2)*resIncr] += alpha*cc2; - res[(i+3)*resIncr] += alpha*cc3; - } - for(; i<n2; i+=2) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)), - c1 = pset1<ResPacket>(ResScalar(0)); - - Index j=0; - for(; j+LhsPacketSize<=cols; j+=LhsPacketSize) - { - RhsPacket b0 = rhs.template load<RhsPacket, Unaligned>(j,0); - - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+0,j),b0,c0); - c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+1,j),b0,c1); - } - ResScalar cc0 = predux(c0); - ResScalar cc1 = predux(c1); - for(; j<cols; ++j) - { - RhsScalar b0 = rhs(j,0); - - cc0 += cj.pmul(lhs(i+0,j), b0); - cc1 += cj.pmul(lhs(i+1,j), b0); - } - res[(i+0)*resIncr] += alpha*cc0; - res[(i+1)*resIncr] += alpha*cc1; - } - for(; i<rows; ++i) - { - ResPacket c0 = pset1<ResPacket>(ResScalar(0)); - ResPacketHalf c0_h = pset1<ResPacketHalf>(ResScalar(0)); - ResPacketQuarter c0_q = pset1<ResPacketQuarter>(ResScalar(0)); - Index j=0; - for(; j+LhsPacketSize<=cols; j+=LhsPacketSize) - { - RhsPacket b0 = rhs.template load<RhsPacket,Unaligned>(j,0); - c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i,j),b0,c0); - } - ResScalar cc0 = predux(c0); - if (HasHalf) { - for(; j+LhsPacketSizeHalf<=cols; j+=LhsPacketSizeHalf) - { - RhsPacketHalf b0 = rhs.template load<RhsPacketHalf,Unaligned>(j,0); - c0_h = pcj_half.pmadd(lhs.template load<LhsPacketHalf,LhsAlignment>(i,j),b0,c0_h); - } - cc0 += predux(c0_h); - } - if (HasQuarter) { - for(; j+LhsPacketSizeQuarter<=cols; j+=LhsPacketSizeQuarter) - { - RhsPacketQuarter b0 = rhs.template load<RhsPacketQuarter,Unaligned>(j,0); - c0_q = pcj_quarter.pmadd(lhs.template load<LhsPacketQuarter,LhsAlignment>(i,j),b0,c0_q); - } - cc0 += predux(c0_q); - } - for(; j<cols; ++j) - { - cc0 += cj.pmul(lhs(i,j), rhs(j,0)); - } - res[i*resIncr] += alpha*cc0; - } -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_GENERAL_MATRIX_VECTOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h b/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h deleted file mode 100644 index 6e36c2b3..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to BLAS F77 - * General matrix-vector product functionality based on ?GEMV. - ******************************************************************************** -*/ - -#ifndef EIGEN_GENERAL_MATRIX_VECTOR_BLAS_H -#define EIGEN_GENERAL_MATRIX_VECTOR_BLAS_H - -namespace Eigen { - -namespace internal { - -/********************************************************************** -* This file implements general matrix-vector multiplication using BLAS -* gemv function via partial specialization of -* general_matrix_vector_product::run(..) method for float, double, -* std::complex<float> and std::complex<double> types -**********************************************************************/ - -// gemv specialization - -template<typename Index, typename LhsScalar, int StorageOrder, bool ConjugateLhs, typename RhsScalar, bool ConjugateRhs> -struct general_matrix_vector_product_gemv; - -#define EIGEN_BLAS_GEMV_SPECIALIZE(Scalar) \ -template<typename Index, bool ConjugateLhs, bool ConjugateRhs> \ -struct general_matrix_vector_product<Index,Scalar,const_blas_data_mapper<Scalar,Index,ColMajor>,ColMajor,ConjugateLhs,Scalar,const_blas_data_mapper<Scalar,Index,RowMajor>,ConjugateRhs,Specialized> { \ -static void run( \ - Index rows, Index cols, \ - const const_blas_data_mapper<Scalar,Index,ColMajor> &lhs, \ - const const_blas_data_mapper<Scalar,Index,RowMajor> &rhs, \ - Scalar* res, Index resIncr, Scalar alpha) \ -{ \ - if (ConjugateLhs) { \ - general_matrix_vector_product<Index,Scalar,const_blas_data_mapper<Scalar,Index,ColMajor>,ColMajor,ConjugateLhs,Scalar,const_blas_data_mapper<Scalar,Index,RowMajor>,ConjugateRhs,BuiltIn>::run( \ - rows, cols, lhs, rhs, res, resIncr, alpha); \ - } else { \ - general_matrix_vector_product_gemv<Index,Scalar,ColMajor,ConjugateLhs,Scalar,ConjugateRhs>::run( \ - rows, cols, lhs.data(), lhs.stride(), rhs.data(), rhs.stride(), res, resIncr, alpha); \ - } \ -} \ -}; \ -template<typename Index, bool ConjugateLhs, bool ConjugateRhs> \ -struct general_matrix_vector_product<Index,Scalar,const_blas_data_mapper<Scalar,Index,RowMajor>,RowMajor,ConjugateLhs,Scalar,const_blas_data_mapper<Scalar,Index,ColMajor>,ConjugateRhs,Specialized> { \ -static void run( \ - Index rows, Index cols, \ - const const_blas_data_mapper<Scalar,Index,RowMajor> &lhs, \ - const const_blas_data_mapper<Scalar,Index,ColMajor> &rhs, \ - Scalar* res, Index resIncr, Scalar alpha) \ -{ \ - general_matrix_vector_product_gemv<Index,Scalar,RowMajor,ConjugateLhs,Scalar,ConjugateRhs>::run( \ - rows, cols, lhs.data(), lhs.stride(), rhs.data(), rhs.stride(), res, resIncr, alpha); \ -} \ -}; \ - -EIGEN_BLAS_GEMV_SPECIALIZE(double) -EIGEN_BLAS_GEMV_SPECIALIZE(float) -EIGEN_BLAS_GEMV_SPECIALIZE(dcomplex) -EIGEN_BLAS_GEMV_SPECIALIZE(scomplex) - -#define EIGEN_BLAS_GEMV_SPECIALIZATION(EIGTYPE,BLASTYPE,BLASFUNC) \ -template<typename Index, int LhsStorageOrder, bool ConjugateLhs, bool ConjugateRhs> \ -struct general_matrix_vector_product_gemv<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,ConjugateRhs> \ -{ \ -typedef Matrix<EIGTYPE,Dynamic,1,ColMajor> GEMVVector;\ -\ -static void run( \ - Index rows, Index cols, \ - const EIGTYPE* lhs, Index lhsStride, \ - const EIGTYPE* rhs, Index rhsIncr, \ - EIGTYPE* res, Index resIncr, EIGTYPE alpha) \ -{ \ - BlasIndex m=convert_index<BlasIndex>(rows), n=convert_index<BlasIndex>(cols), \ - lda=convert_index<BlasIndex>(lhsStride), incx=convert_index<BlasIndex>(rhsIncr), incy=convert_index<BlasIndex>(resIncr); \ - const EIGTYPE beta(1); \ - const EIGTYPE *x_ptr; \ - char trans=(LhsStorageOrder==ColMajor) ? 'N' : (ConjugateLhs) ? 'C' : 'T'; \ - if (LhsStorageOrder==RowMajor) { \ - m = convert_index<BlasIndex>(cols); \ - n = convert_index<BlasIndex>(rows); \ - }\ - GEMVVector x_tmp; \ - if (ConjugateRhs) { \ - Map<const GEMVVector, 0, InnerStride<> > map_x(rhs,cols,1,InnerStride<>(incx)); \ - x_tmp=map_x.conjugate(); \ - x_ptr=x_tmp.data(); \ - incx=1; \ - } else x_ptr=rhs; \ - BLASFUNC(&trans, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)lhs, &lda, (const BLASTYPE*)x_ptr, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &incy); \ -}\ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_GEMV_SPECIALIZATION(double, double, dgemv) -EIGEN_BLAS_GEMV_SPECIALIZATION(float, float, sgemv) -EIGEN_BLAS_GEMV_SPECIALIZATION(dcomplex, MKL_Complex16, zgemv) -EIGEN_BLAS_GEMV_SPECIALIZATION(scomplex, MKL_Complex8 , cgemv) -#else -EIGEN_BLAS_GEMV_SPECIALIZATION(double, double, dgemv_) -EIGEN_BLAS_GEMV_SPECIALIZATION(float, float, sgemv_) -EIGEN_BLAS_GEMV_SPECIALIZATION(dcomplex, double, zgemv_) -EIGEN_BLAS_GEMV_SPECIALIZATION(scomplex, float, cgemv_) -#endif - -} // end namespase internal - -} // end namespace Eigen - -#endif // EIGEN_GENERAL_MATRIX_VECTOR_BLAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/Parallelizer.h b/external/eigen/include/eigen3/Eigen/src/Core/products/Parallelizer.h deleted file mode 100644 index 3bdd30e5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/Parallelizer.h +++ /dev/null @@ -1,180 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PARALLELIZER_H -#define EIGEN_PARALLELIZER_H - -#if EIGEN_HAS_CXX11_ATOMIC -#include <atomic> -#endif - -namespace Eigen { - -namespace internal { - -/** \internal */ -inline void manage_multi_threading(Action action, int* v) -{ - static int m_maxThreads = -1; - EIGEN_UNUSED_VARIABLE(m_maxThreads); - - if(action==SetAction) - { - eigen_internal_assert(v!=0); - m_maxThreads = *v; - } - else if(action==GetAction) - { - eigen_internal_assert(v!=0); - #ifdef EIGEN_HAS_OPENMP - if(m_maxThreads>0) - *v = m_maxThreads; - else - *v = omp_get_max_threads(); - #else - *v = 1; - #endif - } - else - { - eigen_internal_assert(false); - } -} - -} - -/** Must be call first when calling Eigen from multiple threads */ -inline void initParallel() -{ - int nbt; - internal::manage_multi_threading(GetAction, &nbt); - std::ptrdiff_t l1, l2, l3; - internal::manage_caching_sizes(GetAction, &l1, &l2, &l3); -} - -/** \returns the max number of threads reserved for Eigen - * \sa setNbThreads */ -inline int nbThreads() -{ - int ret; - internal::manage_multi_threading(GetAction, &ret); - return ret; -} - -/** Sets the max number of threads reserved for Eigen - * \sa nbThreads */ -inline void setNbThreads(int v) -{ - internal::manage_multi_threading(SetAction, &v); -} - -namespace internal { - -template<typename Index> struct GemmParallelInfo -{ - GemmParallelInfo() : sync(-1), users(0), lhs_start(0), lhs_length(0) {} - - // volatile is not enough on all architectures (see bug 1572) - // to guarantee that when thread A says to thread B that it is - // done with packing a block, then all writes have been really - // carried out... C++11 memory model+atomic guarantees this. -#if EIGEN_HAS_CXX11_ATOMIC - std::atomic<Index> sync; - std::atomic<int> users; -#else - Index volatile sync; - int volatile users; -#endif - - Index lhs_start; - Index lhs_length; -}; - -template<bool Condition, typename Functor, typename Index> -void parallelize_gemm(const Functor& func, Index rows, Index cols, Index depth, bool transpose) -{ - // TODO when EIGEN_USE_BLAS is defined, - // we should still enable OMP for other scalar types - // Without C++11, we have to disable GEMM's parallelization on - // non x86 architectures because there volatile is not enough for our purpose. - // See bug 1572. -#if (! defined(EIGEN_HAS_OPENMP)) || defined(EIGEN_USE_BLAS) || ((!EIGEN_HAS_CXX11_ATOMIC) && !(EIGEN_ARCH_i386_OR_x86_64)) - // FIXME the transpose variable is only needed to properly split - // the matrix product when multithreading is enabled. This is a temporary - // fix to support row-major destination matrices. This whole - // parallelizer mechanism has to be redesigned anyway. - EIGEN_UNUSED_VARIABLE(depth); - EIGEN_UNUSED_VARIABLE(transpose); - func(0,rows, 0,cols); -#else - - // Dynamically check whether we should enable or disable OpenMP. - // The conditions are: - // - the max number of threads we can create is greater than 1 - // - we are not already in a parallel code - // - the sizes are large enough - - // compute the maximal number of threads from the size of the product: - // This first heuristic takes into account that the product kernel is fully optimized when working with nr columns at once. - Index size = transpose ? rows : cols; - Index pb_max_threads = std::max<Index>(1,size / Functor::Traits::nr); - - // compute the maximal number of threads from the total amount of work: - double work = static_cast<double>(rows) * static_cast<double>(cols) * - static_cast<double>(depth); - double kMinTaskSize = 50000; // FIXME improve this heuristic. - pb_max_threads = std::max<Index>(1, std::min<Index>(pb_max_threads, static_cast<Index>( work / kMinTaskSize ) )); - - // compute the number of threads we are going to use - Index threads = std::min<Index>(nbThreads(), pb_max_threads); - - // if multi-threading is explicitly disabled, not useful, or if we already are in a parallel session, - // then abort multi-threading - // FIXME omp_get_num_threads()>1 only works for openmp, what if the user does not use openmp? - if((!Condition) || (threads==1) || (omp_get_num_threads()>1)) - return func(0,rows, 0,cols); - - Eigen::initParallel(); - func.initParallelSession(threads); - - if(transpose) - std::swap(rows,cols); - - ei_declare_aligned_stack_constructed_variable(GemmParallelInfo<Index>,info,threads,0); - - #pragma omp parallel num_threads(threads) - { - Index i = omp_get_thread_num(); - // Note that the actual number of threads might be lower than the number of request ones. - Index actual_threads = omp_get_num_threads(); - - Index blockCols = (cols / actual_threads) & ~Index(0x3); - Index blockRows = (rows / actual_threads); - blockRows = (blockRows/Functor::Traits::mr)*Functor::Traits::mr; - - Index r0 = i*blockRows; - Index actualBlockRows = (i+1==actual_threads) ? rows-r0 : blockRows; - - Index c0 = i*blockCols; - Index actualBlockCols = (i+1==actual_threads) ? cols-c0 : blockCols; - - info[i].lhs_start = r0; - info[i].lhs_length = actualBlockRows; - - if(transpose) func(c0, actualBlockCols, 0, rows, info); - else func(0, rows, c0, actualBlockCols, info); - } -#endif -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PARALLELIZER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixMatrix.h b/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixMatrix.h deleted file mode 100644 index 33ecf10f..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +++ /dev/null @@ -1,544 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SELFADJOINT_MATRIX_MATRIX_H -#define EIGEN_SELFADJOINT_MATRIX_MATRIX_H - -namespace Eigen { - -namespace internal { - -// pack a selfadjoint block diagonal for use with the gebp_kernel -template<typename Scalar, typename Index, int Pack1, int Pack2_dummy, int StorageOrder> -struct symm_pack_lhs -{ - template<int BlockRows> inline - void pack(Scalar* blockA, const const_blas_data_mapper<Scalar,Index,StorageOrder>& lhs, Index cols, Index i, Index& count) - { - // normal copy - for(Index k=0; k<i; k++) - for(Index w=0; w<BlockRows; w++) - blockA[count++] = lhs(i+w,k); // normal - // symmetric copy - Index h = 0; - for(Index k=i; k<i+BlockRows; k++) - { - for(Index w=0; w<h; w++) - blockA[count++] = numext::conj(lhs(k, i+w)); // transposed - - blockA[count++] = numext::real(lhs(k,k)); // real (diagonal) - - for(Index w=h+1; w<BlockRows; w++) - blockA[count++] = lhs(i+w, k); // normal - ++h; - } - // transposed copy - for(Index k=i+BlockRows; k<cols; k++) - for(Index w=0; w<BlockRows; w++) - blockA[count++] = numext::conj(lhs(k, i+w)); // transposed - } - void operator()(Scalar* blockA, const Scalar* _lhs, Index lhsStride, Index cols, Index rows) - { - typedef typename unpacket_traits<typename packet_traits<Scalar>::type>::half HalfPacket; - typedef typename unpacket_traits<typename unpacket_traits<typename packet_traits<Scalar>::type>::half>::half QuarterPacket; - enum { PacketSize = packet_traits<Scalar>::size, - HalfPacketSize = unpacket_traits<HalfPacket>::size, - QuarterPacketSize = unpacket_traits<QuarterPacket>::size, - HasHalf = (int)HalfPacketSize < (int)PacketSize, - HasQuarter = (int)QuarterPacketSize < (int)HalfPacketSize}; - - const_blas_data_mapper<Scalar,Index,StorageOrder> lhs(_lhs,lhsStride); - Index count = 0; - //Index peeled_mc3 = (rows/Pack1)*Pack1; - - const Index peeled_mc3 = Pack1>=3*PacketSize ? (rows/(3*PacketSize))*(3*PacketSize) : 0; - const Index peeled_mc2 = Pack1>=2*PacketSize ? peeled_mc3+((rows-peeled_mc3)/(2*PacketSize))*(2*PacketSize) : 0; - const Index peeled_mc1 = Pack1>=1*PacketSize ? peeled_mc2+((rows-peeled_mc2)/(1*PacketSize))*(1*PacketSize) : 0; - const Index peeled_mc_half = Pack1>=HalfPacketSize ? peeled_mc1+((rows-peeled_mc1)/(HalfPacketSize))*(HalfPacketSize) : 0; - const Index peeled_mc_quarter = Pack1>=QuarterPacketSize ? peeled_mc_half+((rows-peeled_mc_half)/(QuarterPacketSize))*(QuarterPacketSize) : 0; - - if(Pack1>=3*PacketSize) - for(Index i=0; i<peeled_mc3; i+=3*PacketSize) - pack<3*PacketSize>(blockA, lhs, cols, i, count); - - if(Pack1>=2*PacketSize) - for(Index i=peeled_mc3; i<peeled_mc2; i+=2*PacketSize) - pack<2*PacketSize>(blockA, lhs, cols, i, count); - - if(Pack1>=1*PacketSize) - for(Index i=peeled_mc2; i<peeled_mc1; i+=1*PacketSize) - pack<1*PacketSize>(blockA, lhs, cols, i, count); - - if(HasHalf && Pack1>=HalfPacketSize) - for(Index i=peeled_mc1; i<peeled_mc_half; i+=HalfPacketSize) - pack<HalfPacketSize>(blockA, lhs, cols, i, count); - - if(HasQuarter && Pack1>=QuarterPacketSize) - for(Index i=peeled_mc_half; i<peeled_mc_quarter; i+=QuarterPacketSize) - pack<QuarterPacketSize>(blockA, lhs, cols, i, count); - - // do the same with mr==1 - for(Index i=peeled_mc_quarter; i<rows; i++) - { - for(Index k=0; k<i; k++) - blockA[count++] = lhs(i, k); // normal - - blockA[count++] = numext::real(lhs(i, i)); // real (diagonal) - - for(Index k=i+1; k<cols; k++) - blockA[count++] = numext::conj(lhs(k, i)); // transposed - } - } -}; - -template<typename Scalar, typename Index, int nr, int StorageOrder> -struct symm_pack_rhs -{ - enum { PacketSize = packet_traits<Scalar>::size }; - void operator()(Scalar* blockB, const Scalar* _rhs, Index rhsStride, Index rows, Index cols, Index k2) - { - Index end_k = k2 + rows; - Index count = 0; - const_blas_data_mapper<Scalar,Index,StorageOrder> rhs(_rhs,rhsStride); - Index packet_cols8 = nr>=8 ? (cols/8) * 8 : 0; - Index packet_cols4 = nr>=4 ? (cols/4) * 4 : 0; - - // first part: normal case - for(Index j2=0; j2<k2; j2+=nr) - { - for(Index k=k2; k<end_k; k++) - { - blockB[count+0] = rhs(k,j2+0); - blockB[count+1] = rhs(k,j2+1); - if (nr>=4) - { - blockB[count+2] = rhs(k,j2+2); - blockB[count+3] = rhs(k,j2+3); - } - if (nr>=8) - { - blockB[count+4] = rhs(k,j2+4); - blockB[count+5] = rhs(k,j2+5); - blockB[count+6] = rhs(k,j2+6); - blockB[count+7] = rhs(k,j2+7); - } - count += nr; - } - } - - // second part: diagonal block - Index end8 = nr>=8 ? (std::min)(k2+rows,packet_cols8) : k2; - if(nr>=8) - { - for(Index j2=k2; j2<end8; j2+=8) - { - // again we can split vertically in three different parts (transpose, symmetric, normal) - // transpose - for(Index k=k2; k<j2; k++) - { - blockB[count+0] = numext::conj(rhs(j2+0,k)); - blockB[count+1] = numext::conj(rhs(j2+1,k)); - blockB[count+2] = numext::conj(rhs(j2+2,k)); - blockB[count+3] = numext::conj(rhs(j2+3,k)); - blockB[count+4] = numext::conj(rhs(j2+4,k)); - blockB[count+5] = numext::conj(rhs(j2+5,k)); - blockB[count+6] = numext::conj(rhs(j2+6,k)); - blockB[count+7] = numext::conj(rhs(j2+7,k)); - count += 8; - } - // symmetric - Index h = 0; - for(Index k=j2; k<j2+8; k++) - { - // normal - for (Index w=0 ; w<h; ++w) - blockB[count+w] = rhs(k,j2+w); - - blockB[count+h] = numext::real(rhs(k,k)); - - // transpose - for (Index w=h+1 ; w<8; ++w) - blockB[count+w] = numext::conj(rhs(j2+w,k)); - count += 8; - ++h; - } - // normal - for(Index k=j2+8; k<end_k; k++) - { - blockB[count+0] = rhs(k,j2+0); - blockB[count+1] = rhs(k,j2+1); - blockB[count+2] = rhs(k,j2+2); - blockB[count+3] = rhs(k,j2+3); - blockB[count+4] = rhs(k,j2+4); - blockB[count+5] = rhs(k,j2+5); - blockB[count+6] = rhs(k,j2+6); - blockB[count+7] = rhs(k,j2+7); - count += 8; - } - } - } - if(nr>=4) - { - for(Index j2=end8; j2<(std::min)(k2+rows,packet_cols4); j2+=4) - { - // again we can split vertically in three different parts (transpose, symmetric, normal) - // transpose - for(Index k=k2; k<j2; k++) - { - blockB[count+0] = numext::conj(rhs(j2+0,k)); - blockB[count+1] = numext::conj(rhs(j2+1,k)); - blockB[count+2] = numext::conj(rhs(j2+2,k)); - blockB[count+3] = numext::conj(rhs(j2+3,k)); - count += 4; - } - // symmetric - Index h = 0; - for(Index k=j2; k<j2+4; k++) - { - // normal - for (Index w=0 ; w<h; ++w) - blockB[count+w] = rhs(k,j2+w); - - blockB[count+h] = numext::real(rhs(k,k)); - - // transpose - for (Index w=h+1 ; w<4; ++w) - blockB[count+w] = numext::conj(rhs(j2+w,k)); - count += 4; - ++h; - } - // normal - for(Index k=j2+4; k<end_k; k++) - { - blockB[count+0] = rhs(k,j2+0); - blockB[count+1] = rhs(k,j2+1); - blockB[count+2] = rhs(k,j2+2); - blockB[count+3] = rhs(k,j2+3); - count += 4; - } - } - } - - // third part: transposed - if(nr>=8) - { - for(Index j2=k2+rows; j2<packet_cols8; j2+=8) - { - for(Index k=k2; k<end_k; k++) - { - blockB[count+0] = numext::conj(rhs(j2+0,k)); - blockB[count+1] = numext::conj(rhs(j2+1,k)); - blockB[count+2] = numext::conj(rhs(j2+2,k)); - blockB[count+3] = numext::conj(rhs(j2+3,k)); - blockB[count+4] = numext::conj(rhs(j2+4,k)); - blockB[count+5] = numext::conj(rhs(j2+5,k)); - blockB[count+6] = numext::conj(rhs(j2+6,k)); - blockB[count+7] = numext::conj(rhs(j2+7,k)); - count += 8; - } - } - } - if(nr>=4) - { - for(Index j2=(std::max)(packet_cols8,k2+rows); j2<packet_cols4; j2+=4) - { - for(Index k=k2; k<end_k; k++) - { - blockB[count+0] = numext::conj(rhs(j2+0,k)); - blockB[count+1] = numext::conj(rhs(j2+1,k)); - blockB[count+2] = numext::conj(rhs(j2+2,k)); - blockB[count+3] = numext::conj(rhs(j2+3,k)); - count += 4; - } - } - } - - // copy the remaining columns one at a time (=> the same with nr==1) - for(Index j2=packet_cols4; j2<cols; ++j2) - { - // transpose - Index half = (std::min)(end_k,j2); - for(Index k=k2; k<half; k++) - { - blockB[count] = numext::conj(rhs(j2,k)); - count += 1; - } - - if(half==j2 && half<k2+rows) - { - blockB[count] = numext::real(rhs(j2,j2)); - count += 1; - } - else - half--; - - // normal - for(Index k=half+1; k<k2+rows; k++) - { - blockB[count] = rhs(k,j2); - count += 1; - } - } - } -}; - -/* Optimized selfadjoint matrix * matrix (_SYMM) product built on top of - * the general matrix matrix product. - */ -template <typename Scalar, typename Index, - int LhsStorageOrder, bool LhsSelfAdjoint, bool ConjugateLhs, - int RhsStorageOrder, bool RhsSelfAdjoint, bool ConjugateRhs, - int ResStorageOrder, int ResInnerStride> -struct product_selfadjoint_matrix; - -template <typename Scalar, typename Index, - int LhsStorageOrder, bool LhsSelfAdjoint, bool ConjugateLhs, - int RhsStorageOrder, bool RhsSelfAdjoint, bool ConjugateRhs, - int ResInnerStride> -struct product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,LhsSelfAdjoint,ConjugateLhs, RhsStorageOrder,RhsSelfAdjoint,ConjugateRhs,RowMajor,ResInnerStride> -{ - - static EIGEN_STRONG_INLINE void run( - Index rows, Index cols, - const Scalar* lhs, Index lhsStride, - const Scalar* rhs, Index rhsStride, - Scalar* res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking) - { - product_selfadjoint_matrix<Scalar, Index, - EIGEN_LOGICAL_XOR(RhsSelfAdjoint,RhsStorageOrder==RowMajor) ? ColMajor : RowMajor, - RhsSelfAdjoint, NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(RhsSelfAdjoint,ConjugateRhs), - EIGEN_LOGICAL_XOR(LhsSelfAdjoint,LhsStorageOrder==RowMajor) ? ColMajor : RowMajor, - LhsSelfAdjoint, NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(LhsSelfAdjoint,ConjugateLhs), - ColMajor,ResInnerStride> - ::run(cols, rows, rhs, rhsStride, lhs, lhsStride, res, resIncr, resStride, alpha, blocking); - } -}; - -template <typename Scalar, typename Index, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride> -struct product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,true,ConjugateLhs, RhsStorageOrder,false,ConjugateRhs,ColMajor,ResInnerStride> -{ - - static EIGEN_DONT_INLINE void run( - Index rows, Index cols, - const Scalar* _lhs, Index lhsStride, - const Scalar* _rhs, Index rhsStride, - Scalar* res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking); -}; - -template <typename Scalar, typename Index, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride> -EIGEN_DONT_INLINE void product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,true,ConjugateLhs, RhsStorageOrder,false,ConjugateRhs,ColMajor,ResInnerStride>::run( - Index rows, Index cols, - const Scalar* _lhs, Index lhsStride, - const Scalar* _rhs, Index rhsStride, - Scalar* _res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking) - { - Index size = rows; - - typedef gebp_traits<Scalar,Scalar> Traits; - - typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper; - typedef const_blas_data_mapper<Scalar, Index, (LhsStorageOrder == RowMajor) ? ColMajor : RowMajor> LhsTransposeMapper; - typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper; - typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper; - LhsMapper lhs(_lhs,lhsStride); - LhsTransposeMapper lhs_transpose(_lhs,lhsStride); - RhsMapper rhs(_rhs,rhsStride); - ResMapper res(_res, resStride, resIncr); - - Index kc = blocking.kc(); // cache block size along the K direction - Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction - // kc must be smaller than mc - kc = (std::min)(kc,mc); - std::size_t sizeA = kc*mc; - std::size_t sizeB = kc*cols; - ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA()); - ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB()); - - gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel; - symm_pack_lhs<Scalar, Index, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs; - gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs; - gemm_pack_lhs<Scalar, Index, LhsTransposeMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder==RowMajor?ColMajor:RowMajor, true> pack_lhs_transposed; - - for(Index k2=0; k2<size; k2+=kc) - { - const Index actual_kc = (std::min)(k2+kc,size)-k2; - - // we have selected one row panel of rhs and one column panel of lhs - // pack rhs's panel into a sequential chunk of memory - // and expand each coeff to a constant packet for further reuse - pack_rhs(blockB, rhs.getSubMapper(k2,0), actual_kc, cols); - - // the select lhs's panel has to be split in three different parts: - // 1 - the transposed panel above the diagonal block => transposed packed copy - // 2 - the diagonal block => special packed copy - // 3 - the panel below the diagonal block => generic packed copy - for(Index i2=0; i2<k2; i2+=mc) - { - const Index actual_mc = (std::min)(i2+mc,k2)-i2; - // transposed packed copy - pack_lhs_transposed(blockA, lhs_transpose.getSubMapper(i2, k2), actual_kc, actual_mc); - - gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, cols, alpha); - } - // the block diagonal - { - const Index actual_mc = (std::min)(k2+kc,size)-k2; - // symmetric packed copy - pack_lhs(blockA, &lhs(k2,k2), lhsStride, actual_kc, actual_mc); - - gebp_kernel(res.getSubMapper(k2, 0), blockA, blockB, actual_mc, actual_kc, cols, alpha); - } - - for(Index i2=k2+kc; i2<size; i2+=mc) - { - const Index actual_mc = (std::min)(i2+mc,size)-i2; - gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder,false>() - (blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc); - - gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, cols, alpha); - } - } - } - -// matrix * selfadjoint product -template <typename Scalar, typename Index, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride> -struct product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,false,ConjugateLhs, RhsStorageOrder,true,ConjugateRhs,ColMajor,ResInnerStride> -{ - - static EIGEN_DONT_INLINE void run( - Index rows, Index cols, - const Scalar* _lhs, Index lhsStride, - const Scalar* _rhs, Index rhsStride, - Scalar* res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking); -}; - -template <typename Scalar, typename Index, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride> -EIGEN_DONT_INLINE void product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,false,ConjugateLhs, RhsStorageOrder,true,ConjugateRhs,ColMajor,ResInnerStride>::run( - Index rows, Index cols, - const Scalar* _lhs, Index lhsStride, - const Scalar* _rhs, Index rhsStride, - Scalar* _res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking) - { - Index size = cols; - - typedef gebp_traits<Scalar,Scalar> Traits; - - typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper; - typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper; - LhsMapper lhs(_lhs,lhsStride); - ResMapper res(_res,resStride, resIncr); - - Index kc = blocking.kc(); // cache block size along the K direction - Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction - std::size_t sizeA = kc*mc; - std::size_t sizeB = kc*cols; - ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA()); - ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB()); - - gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel; - gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs; - symm_pack_rhs<Scalar, Index, Traits::nr,RhsStorageOrder> pack_rhs; - - for(Index k2=0; k2<size; k2+=kc) - { - const Index actual_kc = (std::min)(k2+kc,size)-k2; - - pack_rhs(blockB, _rhs, rhsStride, actual_kc, cols, k2); - - // => GEPP - for(Index i2=0; i2<rows; i2+=mc) - { - const Index actual_mc = (std::min)(i2+mc,rows)-i2; - pack_lhs(blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc); - - gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, cols, alpha); - } - } - } - -} // end namespace internal - -/*************************************************************************** -* Wrapper to product_selfadjoint_matrix -***************************************************************************/ - -namespace internal { - -template<typename Lhs, int LhsMode, typename Rhs, int RhsMode> -struct selfadjoint_product_impl<Lhs,LhsMode,false,Rhs,RhsMode,false> -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - - enum { - LhsIsUpper = (LhsMode&(Upper|Lower))==Upper, - LhsIsSelfAdjoint = (LhsMode&SelfAdjoint)==SelfAdjoint, - RhsIsUpper = (RhsMode&(Upper|Lower))==Upper, - RhsIsSelfAdjoint = (RhsMode&SelfAdjoint)==SelfAdjoint - }; - - template<typename Dest> - static void run(Dest &dst, const Lhs &a_lhs, const Rhs &a_rhs, const Scalar& alpha) - { - eigen_assert(dst.rows()==a_lhs.rows() && dst.cols()==a_rhs.cols()); - - typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs); - typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs); - - Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(a_lhs) - * RhsBlasTraits::extractScalarFactor(a_rhs); - - typedef internal::gemm_blocking_space<(Dest::Flags&RowMajorBit) ? RowMajor : ColMajor,Scalar,Scalar, - Lhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxColsAtCompileTime,1> BlockingType; - - BlockingType blocking(lhs.rows(), rhs.cols(), lhs.cols(), 1, false); - - internal::product_selfadjoint_matrix<Scalar, Index, - EIGEN_LOGICAL_XOR(LhsIsUpper,internal::traits<Lhs>::Flags &RowMajorBit) ? RowMajor : ColMajor, LhsIsSelfAdjoint, - NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(LhsIsUpper,bool(LhsBlasTraits::NeedToConjugate)), - EIGEN_LOGICAL_XOR(RhsIsUpper,internal::traits<Rhs>::Flags &RowMajorBit) ? RowMajor : ColMajor, RhsIsSelfAdjoint, - NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(RhsIsUpper,bool(RhsBlasTraits::NeedToConjugate)), - internal::traits<Dest>::Flags&RowMajorBit ? RowMajor : ColMajor, - Dest::InnerStrideAtCompileTime> - ::run( - lhs.rows(), rhs.cols(), // sizes - &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info - &rhs.coeffRef(0,0), rhs.outerStride(), // rhs info - &dst.coeffRef(0,0), dst.innerStride(), dst.outerStride(), // result info - actualAlpha, blocking // alpha - ); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SELFADJOINT_MATRIX_MATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h b/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h deleted file mode 100644 index 61396dbd..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +++ /dev/null @@ -1,295 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - ******************************************************************************** - * Content : Eigen bindings to BLAS F77 - * Self adjoint matrix * matrix product functionality based on ?SYMM/?HEMM. - ******************************************************************************** -*/ - -#ifndef EIGEN_SELFADJOINT_MATRIX_MATRIX_BLAS_H -#define EIGEN_SELFADJOINT_MATRIX_MATRIX_BLAS_H - -namespace Eigen { - -namespace internal { - - -/* Optimized selfadjoint matrix * matrix (?SYMM/?HEMM) product */ - -#define EIGEN_BLAS_SYMM_L(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \ -template <typename Index, \ - int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs> \ -struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,true,ConjugateLhs,RhsStorageOrder,false,ConjugateRhs,ColMajor,1> \ -{\ -\ - static void run( \ - Index rows, Index cols, \ - const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsStride, \ - EIGTYPE* res, Index resIncr, Index resStride, \ - EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \ - { \ - EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \ - eigen_assert(resIncr == 1); \ - char side='L', uplo='L'; \ - BlasIndex m, n, lda, ldb, ldc; \ - const EIGTYPE *a, *b; \ - EIGTYPE beta(1); \ - MatrixX##EIGPREFIX b_tmp; \ -\ -/* Set transpose options */ \ -/* Set m, n, k */ \ - m = convert_index<BlasIndex>(rows); \ - n = convert_index<BlasIndex>(cols); \ -\ -/* Set lda, ldb, ldc */ \ - lda = convert_index<BlasIndex>(lhsStride); \ - ldb = convert_index<BlasIndex>(rhsStride); \ - ldc = convert_index<BlasIndex>(resStride); \ -\ -/* Set a, b, c */ \ - if (LhsStorageOrder==RowMajor) uplo='U'; \ - a = _lhs; \ -\ - if (RhsStorageOrder==RowMajor) { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \ - b_tmp = rhs.adjoint(); \ - b = b_tmp.data(); \ - ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \ - } else b = _rhs; \ -\ - BLASFUNC(&side, &uplo, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \ -\ - } \ -}; - - -#define EIGEN_BLAS_HEMM_L(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \ -template <typename Index, \ - int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs> \ -struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,true,ConjugateLhs,RhsStorageOrder,false,ConjugateRhs,ColMajor,1> \ -{\ - static void run( \ - Index rows, Index cols, \ - const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsStride, \ - EIGTYPE* res, Index resIncr, Index resStride, \ - EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \ - { \ - EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \ - eigen_assert(resIncr == 1); \ - char side='L', uplo='L'; \ - BlasIndex m, n, lda, ldb, ldc; \ - const EIGTYPE *a, *b; \ - EIGTYPE beta(1); \ - MatrixX##EIGPREFIX b_tmp; \ - Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder> a_tmp; \ -\ -/* Set transpose options */ \ -/* Set m, n, k */ \ - m = convert_index<BlasIndex>(rows); \ - n = convert_index<BlasIndex>(cols); \ -\ -/* Set lda, ldb, ldc */ \ - lda = convert_index<BlasIndex>(lhsStride); \ - ldb = convert_index<BlasIndex>(rhsStride); \ - ldc = convert_index<BlasIndex>(resStride); \ -\ -/* Set a, b, c */ \ - if (((LhsStorageOrder==ColMajor) && ConjugateLhs) || ((LhsStorageOrder==RowMajor) && (!ConjugateLhs))) { \ - Map<const Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder>, 0, OuterStride<> > lhs(_lhs,m,m,OuterStride<>(lhsStride)); \ - a_tmp = lhs.conjugate(); \ - a = a_tmp.data(); \ - lda = convert_index<BlasIndex>(a_tmp.outerStride()); \ - } else a = _lhs; \ - if (LhsStorageOrder==RowMajor) uplo='U'; \ -\ - if (RhsStorageOrder==ColMajor && (!ConjugateRhs)) { \ - b = _rhs; } \ - else { \ - if (RhsStorageOrder==ColMajor && ConjugateRhs) { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,m,n,OuterStride<>(rhsStride)); \ - b_tmp = rhs.conjugate(); \ - } else \ - if (ConjugateRhs) { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \ - b_tmp = rhs.adjoint(); \ - } else { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \ - b_tmp = rhs.transpose(); \ - } \ - b = b_tmp.data(); \ - ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \ - } \ -\ - BLASFUNC(&side, &uplo, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \ -\ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_SYMM_L(double, double, d, dsymm) -EIGEN_BLAS_SYMM_L(float, float, f, ssymm) -EIGEN_BLAS_HEMM_L(dcomplex, MKL_Complex16, cd, zhemm) -EIGEN_BLAS_HEMM_L(scomplex, MKL_Complex8, cf, chemm) -#else -EIGEN_BLAS_SYMM_L(double, double, d, dsymm_) -EIGEN_BLAS_SYMM_L(float, float, f, ssymm_) -EIGEN_BLAS_HEMM_L(dcomplex, double, cd, zhemm_) -EIGEN_BLAS_HEMM_L(scomplex, float, cf, chemm_) -#endif - -/* Optimized matrix * selfadjoint matrix (?SYMM/?HEMM) product */ - -#define EIGEN_BLAS_SYMM_R(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \ -template <typename Index, \ - int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs> \ -struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,false,ConjugateLhs,RhsStorageOrder,true,ConjugateRhs,ColMajor,1> \ -{\ -\ - static void run( \ - Index rows, Index cols, \ - const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsStride, \ - EIGTYPE* res, Index resIncr, Index resStride, \ - EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \ - { \ - EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \ - eigen_assert(resIncr == 1); \ - char side='R', uplo='L'; \ - BlasIndex m, n, lda, ldb, ldc; \ - const EIGTYPE *a, *b; \ - EIGTYPE beta(1); \ - MatrixX##EIGPREFIX b_tmp; \ -\ -/* Set m, n, k */ \ - m = convert_index<BlasIndex>(rows); \ - n = convert_index<BlasIndex>(cols); \ -\ -/* Set lda, ldb, ldc */ \ - lda = convert_index<BlasIndex>(rhsStride); \ - ldb = convert_index<BlasIndex>(lhsStride); \ - ldc = convert_index<BlasIndex>(resStride); \ -\ -/* Set a, b, c */ \ - if (RhsStorageOrder==RowMajor) uplo='U'; \ - a = _rhs; \ -\ - if (LhsStorageOrder==RowMajor) { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(rhsStride)); \ - b_tmp = lhs.adjoint(); \ - b = b_tmp.data(); \ - ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \ - } else b = _lhs; \ -\ - BLASFUNC(&side, &uplo, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \ -\ - } \ -}; - - -#define EIGEN_BLAS_HEMM_R(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \ -template <typename Index, \ - int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs> \ -struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,false,ConjugateLhs,RhsStorageOrder,true,ConjugateRhs,ColMajor,1> \ -{\ - static void run( \ - Index rows, Index cols, \ - const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsStride, \ - EIGTYPE* res, Index resIncr, Index resStride, \ - EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \ - { \ - EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \ - eigen_assert(resIncr == 1); \ - char side='R', uplo='L'; \ - BlasIndex m, n, lda, ldb, ldc; \ - const EIGTYPE *a, *b; \ - EIGTYPE beta(1); \ - MatrixX##EIGPREFIX b_tmp; \ - Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> a_tmp; \ -\ -/* Set m, n, k */ \ - m = convert_index<BlasIndex>(rows); \ - n = convert_index<BlasIndex>(cols); \ -\ -/* Set lda, ldb, ldc */ \ - lda = convert_index<BlasIndex>(rhsStride); \ - ldb = convert_index<BlasIndex>(lhsStride); \ - ldc = convert_index<BlasIndex>(resStride); \ -\ -/* Set a, b, c */ \ - if (((RhsStorageOrder==ColMajor) && ConjugateRhs) || ((RhsStorageOrder==RowMajor) && (!ConjugateRhs))) { \ - Map<const Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder>, 0, OuterStride<> > rhs(_rhs,n,n,OuterStride<>(rhsStride)); \ - a_tmp = rhs.conjugate(); \ - a = a_tmp.data(); \ - lda = convert_index<BlasIndex>(a_tmp.outerStride()); \ - } else a = _rhs; \ - if (RhsStorageOrder==RowMajor) uplo='U'; \ -\ - if (LhsStorageOrder==ColMajor && (!ConjugateLhs)) { \ - b = _lhs; } \ - else { \ - if (LhsStorageOrder==ColMajor && ConjugateLhs) { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,m,n,OuterStride<>(lhsStride)); \ - b_tmp = lhs.conjugate(); \ - } else \ - if (ConjugateLhs) { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(lhsStride)); \ - b_tmp = lhs.adjoint(); \ - } else { \ - Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(lhsStride)); \ - b_tmp = lhs.transpose(); \ - } \ - b = b_tmp.data(); \ - ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \ - } \ -\ - BLASFUNC(&side, &uplo, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_SYMM_R(double, double, d, dsymm) -EIGEN_BLAS_SYMM_R(float, float, f, ssymm) -EIGEN_BLAS_HEMM_R(dcomplex, MKL_Complex16, cd, zhemm) -EIGEN_BLAS_HEMM_R(scomplex, MKL_Complex8, cf, chemm) -#else -EIGEN_BLAS_SYMM_R(double, double, d, dsymm_) -EIGEN_BLAS_SYMM_R(float, float, f, ssymm_) -EIGEN_BLAS_HEMM_R(dcomplex, double, cd, zhemm_) -EIGEN_BLAS_HEMM_R(scomplex, float, cf, chemm_) -#endif -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SELFADJOINT_MATRIX_MATRIX_BLAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector.h b/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector.h deleted file mode 100644 index d38fd72b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector.h +++ /dev/null @@ -1,262 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_H -#define EIGEN_SELFADJOINT_MATRIX_VECTOR_H - -namespace Eigen { - -namespace internal { - -/* Optimized selfadjoint matrix * vector product: - * This algorithm processes 2 columns at once that allows to both reduce - * the number of load/stores of the result by a factor 2 and to reduce - * the instruction dependency. - */ - -template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs, int Version=Specialized> -struct selfadjoint_matrix_vector_product; - -template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs, int Version> -struct selfadjoint_matrix_vector_product - -{ -static EIGEN_DONT_INLINE EIGEN_DEVICE_FUNC -void run( - Index size, - const Scalar* lhs, Index lhsStride, - const Scalar* rhs, - Scalar* res, - Scalar alpha); -}; - -template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs, int Version> -EIGEN_DONT_INLINE EIGEN_DEVICE_FUNC -void selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,Version>::run( - Index size, - const Scalar* lhs, Index lhsStride, - const Scalar* rhs, - Scalar* res, - Scalar alpha) -{ - typedef typename packet_traits<Scalar>::type Packet; - typedef typename NumTraits<Scalar>::Real RealScalar; - const Index PacketSize = sizeof(Packet)/sizeof(Scalar); - - enum { - IsRowMajor = StorageOrder==RowMajor ? 1 : 0, - IsLower = UpLo == Lower ? 1 : 0, - FirstTriangular = IsRowMajor == IsLower - }; - - conj_helper<Scalar,Scalar,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, IsRowMajor), ConjugateRhs> cj0; - conj_helper<Scalar,Scalar,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, !IsRowMajor), ConjugateRhs> cj1; - conj_helper<RealScalar,Scalar,false, ConjugateRhs> cjd; - - conj_helper<Packet,Packet,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, IsRowMajor), ConjugateRhs> pcj0; - conj_helper<Packet,Packet,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, !IsRowMajor), ConjugateRhs> pcj1; - - Scalar cjAlpha = ConjugateRhs ? numext::conj(alpha) : alpha; - - Index bound = numext::maxi(Index(0), size-8) & 0xfffffffe; - if (FirstTriangular) - bound = size - bound; - - for (Index j=FirstTriangular ? bound : 0; - j<(FirstTriangular ? size : bound);j+=2) - { - const Scalar* EIGEN_RESTRICT A0 = lhs + j*lhsStride; - const Scalar* EIGEN_RESTRICT A1 = lhs + (j+1)*lhsStride; - - Scalar t0 = cjAlpha * rhs[j]; - Packet ptmp0 = pset1<Packet>(t0); - Scalar t1 = cjAlpha * rhs[j+1]; - Packet ptmp1 = pset1<Packet>(t1); - - Scalar t2(0); - Packet ptmp2 = pset1<Packet>(t2); - Scalar t3(0); - Packet ptmp3 = pset1<Packet>(t3); - - Index starti = FirstTriangular ? 0 : j+2; - Index endi = FirstTriangular ? j : size; - Index alignedStart = (starti) + internal::first_default_aligned(&res[starti], endi-starti); - Index alignedEnd = alignedStart + ((endi-alignedStart)/(PacketSize))*(PacketSize); - - res[j] += cjd.pmul(numext::real(A0[j]), t0); - res[j+1] += cjd.pmul(numext::real(A1[j+1]), t1); - if(FirstTriangular) - { - res[j] += cj0.pmul(A1[j], t1); - t3 += cj1.pmul(A1[j], rhs[j]); - } - else - { - res[j+1] += cj0.pmul(A0[j+1],t0); - t2 += cj1.pmul(A0[j+1], rhs[j+1]); - } - - for (Index i=starti; i<alignedStart; ++i) - { - res[i] += cj0.pmul(A0[i], t0) + cj0.pmul(A1[i],t1); - t2 += cj1.pmul(A0[i], rhs[i]); - t3 += cj1.pmul(A1[i], rhs[i]); - } - // Yes this an optimization for gcc 4.3 and 4.4 (=> huge speed up) - // gcc 4.2 does this optimization automatically. - const Scalar* EIGEN_RESTRICT a0It = A0 + alignedStart; - const Scalar* EIGEN_RESTRICT a1It = A1 + alignedStart; - const Scalar* EIGEN_RESTRICT rhsIt = rhs + alignedStart; - Scalar* EIGEN_RESTRICT resIt = res + alignedStart; - for (Index i=alignedStart; i<alignedEnd; i+=PacketSize) - { - Packet A0i = ploadu<Packet>(a0It); a0It += PacketSize; - Packet A1i = ploadu<Packet>(a1It); a1It += PacketSize; - Packet Bi = ploadu<Packet>(rhsIt); rhsIt += PacketSize; // FIXME should be aligned in most cases - Packet Xi = pload <Packet>(resIt); - - Xi = pcj0.pmadd(A0i,ptmp0, pcj0.pmadd(A1i,ptmp1,Xi)); - ptmp2 = pcj1.pmadd(A0i, Bi, ptmp2); - ptmp3 = pcj1.pmadd(A1i, Bi, ptmp3); - pstore(resIt,Xi); resIt += PacketSize; - } - for (Index i=alignedEnd; i<endi; i++) - { - res[i] += cj0.pmul(A0[i], t0) + cj0.pmul(A1[i],t1); - t2 += cj1.pmul(A0[i], rhs[i]); - t3 += cj1.pmul(A1[i], rhs[i]); - } - - res[j] += alpha * (t2 + predux(ptmp2)); - res[j+1] += alpha * (t3 + predux(ptmp3)); - } - for (Index j=FirstTriangular ? 0 : bound;j<(FirstTriangular ? bound : size);j++) - { - const Scalar* EIGEN_RESTRICT A0 = lhs + j*lhsStride; - - Scalar t1 = cjAlpha * rhs[j]; - Scalar t2(0); - res[j] += cjd.pmul(numext::real(A0[j]), t1); - for (Index i=FirstTriangular ? 0 : j+1; i<(FirstTriangular ? j : size); i++) - { - res[i] += cj0.pmul(A0[i], t1); - t2 += cj1.pmul(A0[i], rhs[i]); - } - res[j] += alpha * t2; - } -} - -} // end namespace internal - -/*************************************************************************** -* Wrapper to product_selfadjoint_vector -***************************************************************************/ - -namespace internal { - -template<typename Lhs, int LhsMode, typename Rhs> -struct selfadjoint_product_impl<Lhs,LhsMode,false,Rhs,0,true> -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; - typedef typename internal::remove_all<ActualLhsType>::type ActualLhsTypeCleaned; - - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned; - - enum { LhsUpLo = LhsMode&(Upper|Lower) }; - - template<typename Dest> - static EIGEN_DEVICE_FUNC - void run(Dest& dest, const Lhs &a_lhs, const Rhs &a_rhs, const Scalar& alpha) - { - typedef typename Dest::Scalar ResScalar; - typedef typename Rhs::Scalar RhsScalar; - typedef Map<Matrix<ResScalar,Dynamic,1>, EIGEN_PLAIN_ENUM_MIN(AlignedMax,internal::packet_traits<ResScalar>::size)> MappedDest; - - eigen_assert(dest.rows()==a_lhs.rows() && dest.cols()==a_rhs.cols()); - - typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs); - typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs); - - Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(a_lhs) - * RhsBlasTraits::extractScalarFactor(a_rhs); - - enum { - EvalToDest = (Dest::InnerStrideAtCompileTime==1), - UseRhs = (ActualRhsTypeCleaned::InnerStrideAtCompileTime==1) - }; - - internal::gemv_static_vector_if<ResScalar,Dest::SizeAtCompileTime,Dest::MaxSizeAtCompileTime,!EvalToDest> static_dest; - internal::gemv_static_vector_if<RhsScalar,ActualRhsTypeCleaned::SizeAtCompileTime,ActualRhsTypeCleaned::MaxSizeAtCompileTime,!UseRhs> static_rhs; - - ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(), - EvalToDest ? dest.data() : static_dest.data()); - - ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,rhs.size(), - UseRhs ? const_cast<RhsScalar*>(rhs.data()) : static_rhs.data()); - - if(!EvalToDest) - { - #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN - Index size = dest.size(); - EIGEN_DENSE_STORAGE_CTOR_PLUGIN - #endif - MappedDest(actualDestPtr, dest.size()) = dest; - } - - if(!UseRhs) - { - #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN - Index size = rhs.size(); - EIGEN_DENSE_STORAGE_CTOR_PLUGIN - #endif - Map<typename ActualRhsTypeCleaned::PlainObject>(actualRhsPtr, rhs.size()) = rhs; - } - - - internal::selfadjoint_matrix_vector_product<Scalar, Index, (internal::traits<ActualLhsTypeCleaned>::Flags&RowMajorBit) ? RowMajor : ColMajor, - int(LhsUpLo), bool(LhsBlasTraits::NeedToConjugate), bool(RhsBlasTraits::NeedToConjugate)>::run - ( - lhs.rows(), // size - &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info - actualRhsPtr, // rhs info - actualDestPtr, // result info - actualAlpha // scale factor - ); - - if(!EvalToDest) - dest = MappedDest(actualDestPtr, dest.size()); - } -}; - -template<typename Lhs, typename Rhs, int RhsMode> -struct selfadjoint_product_impl<Lhs,0,true,Rhs,RhsMode,false> -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - enum { RhsUpLo = RhsMode&(Upper|Lower) }; - - template<typename Dest> - static void run(Dest& dest, const Lhs &a_lhs, const Rhs &a_rhs, const Scalar& alpha) - { - // let's simply transpose the product - Transpose<Dest> destT(dest); - selfadjoint_product_impl<Transpose<const Rhs>, int(RhsUpLo)==Upper ? Lower : Upper, false, - Transpose<const Lhs>, 0, true>::run(destT, a_rhs.transpose(), a_lhs.transpose(), alpha); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h b/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h deleted file mode 100644 index 1238345e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to BLAS F77 - * Selfadjoint matrix-vector product functionality based on ?SYMV/HEMV. - ******************************************************************************** -*/ - -#ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H -#define EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H - -namespace Eigen { - -namespace internal { - -/********************************************************************** -* This file implements selfadjoint matrix-vector multiplication using BLAS -**********************************************************************/ - -// symv/hemv specialization - -template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> -struct selfadjoint_matrix_vector_product_symv : - selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,BuiltIn> {}; - -#define EIGEN_BLAS_SYMV_SPECIALIZE(Scalar) \ -template<typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \ -struct selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,Specialized> { \ -static void run( \ - Index size, const Scalar* lhs, Index lhsStride, \ - const Scalar* _rhs, Scalar* res, Scalar alpha) { \ - enum {\ - IsColMajor = StorageOrder==ColMajor \ - }; \ - if (IsColMajor == ConjugateLhs) {\ - selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,BuiltIn>::run( \ - size, lhs, lhsStride, _rhs, res, alpha); \ - } else {\ - selfadjoint_matrix_vector_product_symv<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs>::run( \ - size, lhs, lhsStride, _rhs, res, alpha); \ - }\ - } \ -}; \ - -EIGEN_BLAS_SYMV_SPECIALIZE(double) -EIGEN_BLAS_SYMV_SPECIALIZE(float) -EIGEN_BLAS_SYMV_SPECIALIZE(dcomplex) -EIGEN_BLAS_SYMV_SPECIALIZE(scomplex) - -#define EIGEN_BLAS_SYMV_SPECIALIZATION(EIGTYPE,BLASTYPE,BLASFUNC) \ -template<typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \ -struct selfadjoint_matrix_vector_product_symv<EIGTYPE,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs> \ -{ \ -typedef Matrix<EIGTYPE,Dynamic,1,ColMajor> SYMVVector;\ -\ -static void run( \ -Index size, const EIGTYPE* lhs, Index lhsStride, \ -const EIGTYPE* _rhs, EIGTYPE* res, EIGTYPE alpha) \ -{ \ - enum {\ - IsRowMajor = StorageOrder==RowMajor ? 1 : 0, \ - IsLower = UpLo == Lower ? 1 : 0 \ - }; \ - BlasIndex n=convert_index<BlasIndex>(size), lda=convert_index<BlasIndex>(lhsStride), incx=1, incy=1; \ - EIGTYPE beta(1); \ - const EIGTYPE *x_ptr; \ - char uplo=(IsRowMajor) ? (IsLower ? 'U' : 'L') : (IsLower ? 'L' : 'U'); \ - SYMVVector x_tmp; \ - if (ConjugateRhs) { \ - Map<const SYMVVector, 0 > map_x(_rhs,size,1); \ - x_tmp=map_x.conjugate(); \ - x_ptr=x_tmp.data(); \ - } else x_ptr=_rhs; \ - BLASFUNC(&uplo, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)lhs, &lda, (const BLASTYPE*)x_ptr, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &incy); \ -}\ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv) -EIGEN_BLAS_SYMV_SPECIALIZATION(float, float, ssymv) -EIGEN_BLAS_SYMV_SPECIALIZATION(dcomplex, MKL_Complex16, zhemv) -EIGEN_BLAS_SYMV_SPECIALIZATION(scomplex, MKL_Complex8, chemv) -#else -EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv_) -EIGEN_BLAS_SYMV_SPECIALIZATION(float, float, ssymv_) -EIGEN_BLAS_SYMV_SPECIALIZATION(dcomplex, double, zhemv_) -EIGEN_BLAS_SYMV_SPECIALIZATION(scomplex, float, chemv_) -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointProduct.h b/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointProduct.h deleted file mode 100644 index 61e8894e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointProduct.h +++ /dev/null @@ -1,133 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SELFADJOINT_PRODUCT_H -#define EIGEN_SELFADJOINT_PRODUCT_H - -/********************************************************************** -* This file implements a self adjoint product: C += A A^T updating only -* half of the selfadjoint matrix C. -* It corresponds to the level 3 SYRK and level 2 SYR Blas routines. -**********************************************************************/ - -namespace Eigen { - - -template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs> -struct selfadjoint_rank1_update<Scalar,Index,ColMajor,UpLo,ConjLhs,ConjRhs> -{ - static void run(Index size, Scalar* mat, Index stride, const Scalar* vecX, const Scalar* vecY, const Scalar& alpha) - { - internal::conj_if<ConjRhs> cj; - typedef Map<const Matrix<Scalar,Dynamic,1> > OtherMap; - typedef typename internal::conditional<ConjLhs,typename OtherMap::ConjugateReturnType,const OtherMap&>::type ConjLhsType; - for (Index i=0; i<size; ++i) - { - Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i+(UpLo==Lower ? i : 0), (UpLo==Lower ? size-i : (i+1))) - += (alpha * cj(vecY[i])) * ConjLhsType(OtherMap(vecX+(UpLo==Lower ? i : 0),UpLo==Lower ? size-i : (i+1))); - } - } -}; - -template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs> -struct selfadjoint_rank1_update<Scalar,Index,RowMajor,UpLo,ConjLhs,ConjRhs> -{ - static void run(Index size, Scalar* mat, Index stride, const Scalar* vecX, const Scalar* vecY, const Scalar& alpha) - { - selfadjoint_rank1_update<Scalar,Index,ColMajor,UpLo==Lower?Upper:Lower,ConjRhs,ConjLhs>::run(size,mat,stride,vecY,vecX,alpha); - } -}; - -template<typename MatrixType, typename OtherType, int UpLo, bool OtherIsVector = OtherType::IsVectorAtCompileTime> -struct selfadjoint_product_selector; - -template<typename MatrixType, typename OtherType, int UpLo> -struct selfadjoint_product_selector<MatrixType,OtherType,UpLo,true> -{ - static void run(MatrixType& mat, const OtherType& other, const typename MatrixType::Scalar& alpha) - { - typedef typename MatrixType::Scalar Scalar; - typedef internal::blas_traits<OtherType> OtherBlasTraits; - typedef typename OtherBlasTraits::DirectLinearAccessType ActualOtherType; - typedef typename internal::remove_all<ActualOtherType>::type _ActualOtherType; - typename internal::add_const_on_value_type<ActualOtherType>::type actualOther = OtherBlasTraits::extract(other.derived()); - - Scalar actualAlpha = alpha * OtherBlasTraits::extractScalarFactor(other.derived()); - - enum { - StorageOrder = (internal::traits<MatrixType>::Flags&RowMajorBit) ? RowMajor : ColMajor, - UseOtherDirectly = _ActualOtherType::InnerStrideAtCompileTime==1 - }; - internal::gemv_static_vector_if<Scalar,OtherType::SizeAtCompileTime,OtherType::MaxSizeAtCompileTime,!UseOtherDirectly> static_other; - - ei_declare_aligned_stack_constructed_variable(Scalar, actualOtherPtr, other.size(), - (UseOtherDirectly ? const_cast<Scalar*>(actualOther.data()) : static_other.data())); - - if(!UseOtherDirectly) - Map<typename _ActualOtherType::PlainObject>(actualOtherPtr, actualOther.size()) = actualOther; - - selfadjoint_rank1_update<Scalar,Index,StorageOrder,UpLo, - OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex, - (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex> - ::run(other.size(), mat.data(), mat.outerStride(), actualOtherPtr, actualOtherPtr, actualAlpha); - } -}; - -template<typename MatrixType, typename OtherType, int UpLo> -struct selfadjoint_product_selector<MatrixType,OtherType,UpLo,false> -{ - static void run(MatrixType& mat, const OtherType& other, const typename MatrixType::Scalar& alpha) - { - typedef typename MatrixType::Scalar Scalar; - typedef internal::blas_traits<OtherType> OtherBlasTraits; - typedef typename OtherBlasTraits::DirectLinearAccessType ActualOtherType; - typedef typename internal::remove_all<ActualOtherType>::type _ActualOtherType; - typename internal::add_const_on_value_type<ActualOtherType>::type actualOther = OtherBlasTraits::extract(other.derived()); - - Scalar actualAlpha = alpha * OtherBlasTraits::extractScalarFactor(other.derived()); - - enum { - IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0, - OtherIsRowMajor = _ActualOtherType::Flags&RowMajorBit ? 1 : 0 - }; - - Index size = mat.cols(); - Index depth = actualOther.cols(); - - typedef internal::gemm_blocking_space<IsRowMajor ? RowMajor : ColMajor,Scalar,Scalar, - MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime, _ActualOtherType::MaxColsAtCompileTime> BlockingType; - - BlockingType blocking(size, size, depth, 1, false); - - - internal::general_matrix_matrix_triangular_product<Index, - Scalar, OtherIsRowMajor ? RowMajor : ColMajor, OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex, - Scalar, OtherIsRowMajor ? ColMajor : RowMajor, (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex, - IsRowMajor ? RowMajor : ColMajor, MatrixType::InnerStrideAtCompileTime, UpLo> - ::run(size, depth, - &actualOther.coeffRef(0,0), actualOther.outerStride(), &actualOther.coeffRef(0,0), actualOther.outerStride(), - mat.data(), mat.innerStride(), mat.outerStride(), actualAlpha, blocking); - } -}; - -// high level API - -template<typename MatrixType, unsigned int UpLo> -template<typename DerivedU> -EIGEN_DEVICE_FUNC SelfAdjointView<MatrixType,UpLo>& SelfAdjointView<MatrixType,UpLo> -::rankUpdate(const MatrixBase<DerivedU>& u, const Scalar& alpha) -{ - selfadjoint_product_selector<MatrixType,DerivedU,UpLo>::run(_expression().const_cast_derived(), u.derived(), alpha); - - return *this; -} - -} // end namespace Eigen - -#endif // EIGEN_SELFADJOINT_PRODUCT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointRank2Update.h b/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointRank2Update.h deleted file mode 100644 index 09209f73..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/SelfadjointRank2Update.h +++ /dev/null @@ -1,94 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SELFADJOINTRANK2UPTADE_H -#define EIGEN_SELFADJOINTRANK2UPTADE_H - -namespace Eigen { - -namespace internal { - -/* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu' - * It corresponds to the Level2 syr2 BLAS routine - */ - -template<typename Scalar, typename Index, typename UType, typename VType, int UpLo> -struct selfadjoint_rank2_update_selector; - -template<typename Scalar, typename Index, typename UType, typename VType> -struct selfadjoint_rank2_update_selector<Scalar,Index,UType,VType,Lower> -{ - static EIGEN_DEVICE_FUNC - void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha) - { - const Index size = u.size(); - for (Index i=0; i<size; ++i) - { - Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i+i, size-i) += - (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.tail(size-i) - + (alpha * numext::conj(v.coeff(i))) * u.tail(size-i); - } - } -}; - -template<typename Scalar, typename Index, typename UType, typename VType> -struct selfadjoint_rank2_update_selector<Scalar,Index,UType,VType,Upper> -{ - static void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha) - { - const Index size = u.size(); - for (Index i=0; i<size; ++i) - Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i, i+1) += - (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.head(i+1) - + (alpha * numext::conj(v.coeff(i))) * u.head(i+1); - } -}; - -template<bool Cond, typename T> struct conj_expr_if - : conditional<!Cond, const T&, - CwiseUnaryOp<scalar_conjugate_op<typename traits<T>::Scalar>,T> > {}; - -} // end namespace internal - -template<typename MatrixType, unsigned int UpLo> -template<typename DerivedU, typename DerivedV> -EIGEN_DEVICE_FUNC SelfAdjointView<MatrixType,UpLo>& SelfAdjointView<MatrixType,UpLo> -::rankUpdate(const MatrixBase<DerivedU>& u, const MatrixBase<DerivedV>& v, const Scalar& alpha) -{ - typedef internal::blas_traits<DerivedU> UBlasTraits; - typedef typename UBlasTraits::DirectLinearAccessType ActualUType; - typedef typename internal::remove_all<ActualUType>::type _ActualUType; - typename internal::add_const_on_value_type<ActualUType>::type actualU = UBlasTraits::extract(u.derived()); - - typedef internal::blas_traits<DerivedV> VBlasTraits; - typedef typename VBlasTraits::DirectLinearAccessType ActualVType; - typedef typename internal::remove_all<ActualVType>::type _ActualVType; - typename internal::add_const_on_value_type<ActualVType>::type actualV = VBlasTraits::extract(v.derived()); - - // If MatrixType is row major, then we use the routine for lower triangular in the upper triangular case and - // vice versa, and take the complex conjugate of all coefficients and vector entries. - - enum { IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0 }; - Scalar actualAlpha = alpha * UBlasTraits::extractScalarFactor(u.derived()) - * numext::conj(VBlasTraits::extractScalarFactor(v.derived())); - if (IsRowMajor) - actualAlpha = numext::conj(actualAlpha); - - typedef typename internal::remove_all<typename internal::conj_expr_if<IsRowMajor ^ UBlasTraits::NeedToConjugate,_ActualUType>::type>::type UType; - typedef typename internal::remove_all<typename internal::conj_expr_if<IsRowMajor ^ VBlasTraits::NeedToConjugate,_ActualVType>::type>::type VType; - internal::selfadjoint_rank2_update_selector<Scalar, Index, UType, VType, - (IsRowMajor ? int(UpLo==Upper ? Lower : Upper) : UpLo)> - ::run(_expression().const_cast_derived().data(),_expression().outerStride(),UType(actualU),VType(actualV),actualAlpha); - - return *this; -} - -} // end namespace Eigen - -#endif // EIGEN_SELFADJOINTRANK2UPTADE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixMatrix.h b/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixMatrix.h deleted file mode 100644 index f0c60507..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixMatrix.h +++ /dev/null @@ -1,472 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRIANGULAR_MATRIX_MATRIX_H -#define EIGEN_TRIANGULAR_MATRIX_MATRIX_H - -namespace Eigen { - -namespace internal { - -// template<typename Scalar, int mr, int StorageOrder, bool Conjugate, int Mode> -// struct gemm_pack_lhs_triangular -// { -// Matrix<Scalar,mr,mr, -// void operator()(Scalar* blockA, const EIGEN_RESTRICT Scalar* _lhs, int lhsStride, int depth, int rows) -// { -// conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj; -// const_blas_data_mapper<Scalar, StorageOrder> lhs(_lhs,lhsStride); -// int count = 0; -// const int peeled_mc = (rows/mr)*mr; -// for(int i=0; i<peeled_mc; i+=mr) -// { -// for(int k=0; k<depth; k++) -// for(int w=0; w<mr; w++) -// blockA[count++] = cj(lhs(i+w, k)); -// } -// for(int i=peeled_mc; i<rows; i++) -// { -// for(int k=0; k<depth; k++) -// blockA[count++] = cj(lhs(i, k)); -// } -// } -// }; - -/* Optimized triangular matrix * matrix (_TRMM++) product built on top of - * the general matrix matrix product. - */ -template <typename Scalar, typename Index, - int Mode, bool LhsIsTriangular, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResStorageOrder, int ResInnerStride, - int Version = Specialized> -struct product_triangular_matrix_matrix; - -template <typename Scalar, typename Index, - int Mode, bool LhsIsTriangular, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride, int Version> -struct product_triangular_matrix_matrix<Scalar,Index,Mode,LhsIsTriangular, - LhsStorageOrder,ConjugateLhs, - RhsStorageOrder,ConjugateRhs,RowMajor,ResInnerStride,Version> -{ - static EIGEN_STRONG_INLINE void run( - Index rows, Index cols, Index depth, - const Scalar* lhs, Index lhsStride, - const Scalar* rhs, Index rhsStride, - Scalar* res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking) - { - product_triangular_matrix_matrix<Scalar, Index, - (Mode&(UnitDiag|ZeroDiag)) | ((Mode&Upper) ? Lower : Upper), - (!LhsIsTriangular), - RhsStorageOrder==RowMajor ? ColMajor : RowMajor, - ConjugateRhs, - LhsStorageOrder==RowMajor ? ColMajor : RowMajor, - ConjugateLhs, - ColMajor, ResInnerStride> - ::run(cols, rows, depth, rhs, rhsStride, lhs, lhsStride, res, resIncr, resStride, alpha, blocking); - } -}; - -// implements col-major += alpha * op(triangular) * op(general) -template <typename Scalar, typename Index, int Mode, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride, int Version> -struct product_triangular_matrix_matrix<Scalar,Index,Mode,true, - LhsStorageOrder,ConjugateLhs, - RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,Version> -{ - - typedef gebp_traits<Scalar,Scalar> Traits; - enum { - SmallPanelWidth = 2 * EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr), - IsLower = (Mode&Lower) == Lower, - SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1 - }; - - static EIGEN_DONT_INLINE void run( - Index _rows, Index _cols, Index _depth, - const Scalar* _lhs, Index lhsStride, - const Scalar* _rhs, Index rhsStride, - Scalar* res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking); -}; - -template <typename Scalar, typename Index, int Mode, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride, int Version> -EIGEN_DONT_INLINE void product_triangular_matrix_matrix<Scalar,Index,Mode,true, - LhsStorageOrder,ConjugateLhs, - RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,Version>::run( - Index _rows, Index _cols, Index _depth, - const Scalar* _lhs, Index lhsStride, - const Scalar* _rhs, Index rhsStride, - Scalar* _res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking) - { - // strip zeros - Index diagSize = (std::min)(_rows,_depth); - Index rows = IsLower ? _rows : diagSize; - Index depth = IsLower ? diagSize : _depth; - Index cols = _cols; - - typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper; - typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper; - typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper; - LhsMapper lhs(_lhs,lhsStride); - RhsMapper rhs(_rhs,rhsStride); - ResMapper res(_res, resStride, resIncr); - - Index kc = blocking.kc(); // cache block size along the K direction - Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction - // The small panel size must not be larger than blocking size. - // Usually this should never be the case because SmallPanelWidth^2 is very small - // compared to L2 cache size, but let's be safe: - Index panelWidth = (std::min)(Index(SmallPanelWidth),(std::min)(kc,mc)); - - std::size_t sizeA = kc*mc; - std::size_t sizeB = kc*cols; - - ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA()); - ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB()); - - // To work around an "error: member reference base type 'Matrix<...> - // (Eigen::internal::constructor_without_unaligned_array_assert (*)())' is - // not a structure or union" compilation error in nvcc (tested V8.0.61), - // create a dummy internal::constructor_without_unaligned_array_assert - // object to pass to the Matrix constructor. - internal::constructor_without_unaligned_array_assert a; - Matrix<Scalar,SmallPanelWidth,SmallPanelWidth,LhsStorageOrder> triangularBuffer(a); - triangularBuffer.setZero(); - if((Mode&ZeroDiag)==ZeroDiag) - triangularBuffer.diagonal().setZero(); - else - triangularBuffer.diagonal().setOnes(); - - gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel; - gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs; - gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs; - - for(Index k2=IsLower ? depth : 0; - IsLower ? k2>0 : k2<depth; - IsLower ? k2-=kc : k2+=kc) - { - Index actual_kc = (std::min)(IsLower ? k2 : depth-k2, kc); - Index actual_k2 = IsLower ? k2-actual_kc : k2; - - // align blocks with the end of the triangular part for trapezoidal lhs - if((!IsLower)&&(k2<rows)&&(k2+actual_kc>rows)) - { - actual_kc = rows-k2; - k2 = k2+actual_kc-kc; - } - - pack_rhs(blockB, rhs.getSubMapper(actual_k2,0), actual_kc, cols); - - // the selected lhs's panel has to be split in three different parts: - // 1 - the part which is zero => skip it - // 2 - the diagonal block => special kernel - // 3 - the dense panel below (lower case) or above (upper case) the diagonal block => GEPP - - // the block diagonal, if any: - if(IsLower || actual_k2<rows) - { - // for each small vertical panels of lhs - for (Index k1=0; k1<actual_kc; k1+=panelWidth) - { - Index actualPanelWidth = std::min<Index>(actual_kc-k1, panelWidth); - Index lengthTarget = IsLower ? actual_kc-k1-actualPanelWidth : k1; - Index startBlock = actual_k2+k1; - Index blockBOffset = k1; - - // => GEBP with the micro triangular block - // The trick is to pack this micro block while filling the opposite triangular part with zeros. - // To this end we do an extra triangular copy to a small temporary buffer - for (Index k=0;k<actualPanelWidth;++k) - { - if (SetDiag) - triangularBuffer.coeffRef(k,k) = lhs(startBlock+k,startBlock+k); - for (Index i=IsLower ? k+1 : 0; IsLower ? i<actualPanelWidth : i<k; ++i) - triangularBuffer.coeffRef(i,k) = lhs(startBlock+i,startBlock+k); - } - pack_lhs(blockA, LhsMapper(triangularBuffer.data(), triangularBuffer.outerStride()), actualPanelWidth, actualPanelWidth); - - gebp_kernel(res.getSubMapper(startBlock, 0), blockA, blockB, - actualPanelWidth, actualPanelWidth, cols, alpha, - actualPanelWidth, actual_kc, 0, blockBOffset); - - // GEBP with remaining micro panel - if (lengthTarget>0) - { - Index startTarget = IsLower ? actual_k2+k1+actualPanelWidth : actual_k2; - - pack_lhs(blockA, lhs.getSubMapper(startTarget,startBlock), actualPanelWidth, lengthTarget); - - gebp_kernel(res.getSubMapper(startTarget, 0), blockA, blockB, - lengthTarget, actualPanelWidth, cols, alpha, - actualPanelWidth, actual_kc, 0, blockBOffset); - } - } - } - // the part below (lower case) or above (upper case) the diagonal => GEPP - { - Index start = IsLower ? k2 : 0; - Index end = IsLower ? rows : (std::min)(actual_k2,rows); - for(Index i2=start; i2<end; i2+=mc) - { - const Index actual_mc = (std::min)(i2+mc,end)-i2; - gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr,Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder,false>() - (blockA, lhs.getSubMapper(i2, actual_k2), actual_kc, actual_mc); - - gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, - actual_kc, cols, alpha, -1, -1, 0, 0); - } - } - } - } - -// implements col-major += alpha * op(general) * op(triangular) -template <typename Scalar, typename Index, int Mode, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride, int Version> -struct product_triangular_matrix_matrix<Scalar,Index,Mode,false, - LhsStorageOrder,ConjugateLhs, - RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,Version> -{ - typedef gebp_traits<Scalar,Scalar> Traits; - enum { - SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr), - IsLower = (Mode&Lower) == Lower, - SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1 - }; - - static EIGEN_DONT_INLINE void run( - Index _rows, Index _cols, Index _depth, - const Scalar* _lhs, Index lhsStride, - const Scalar* _rhs, Index rhsStride, - Scalar* res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking); -}; - -template <typename Scalar, typename Index, int Mode, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResInnerStride, int Version> -EIGEN_DONT_INLINE void product_triangular_matrix_matrix<Scalar,Index,Mode,false, - LhsStorageOrder,ConjugateLhs, - RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,Version>::run( - Index _rows, Index _cols, Index _depth, - const Scalar* _lhs, Index lhsStride, - const Scalar* _rhs, Index rhsStride, - Scalar* _res, Index resIncr, Index resStride, - const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking) - { - const Index PacketBytes = packet_traits<Scalar>::size*sizeof(Scalar); - // strip zeros - Index diagSize = (std::min)(_cols,_depth); - Index rows = _rows; - Index depth = IsLower ? _depth : diagSize; - Index cols = IsLower ? diagSize : _cols; - - typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper; - typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper; - typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper; - LhsMapper lhs(_lhs,lhsStride); - RhsMapper rhs(_rhs,rhsStride); - ResMapper res(_res, resStride, resIncr); - - Index kc = blocking.kc(); // cache block size along the K direction - Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction - - std::size_t sizeA = kc*mc; - std::size_t sizeB = kc*cols+EIGEN_MAX_ALIGN_BYTES/sizeof(Scalar); - - ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA()); - ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB()); - - internal::constructor_without_unaligned_array_assert a; - Matrix<Scalar,SmallPanelWidth,SmallPanelWidth,RhsStorageOrder> triangularBuffer(a); - triangularBuffer.setZero(); - if((Mode&ZeroDiag)==ZeroDiag) - triangularBuffer.diagonal().setZero(); - else - triangularBuffer.diagonal().setOnes(); - - gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel; - gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs; - gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs; - gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder,false,true> pack_rhs_panel; - - for(Index k2=IsLower ? 0 : depth; - IsLower ? k2<depth : k2>0; - IsLower ? k2+=kc : k2-=kc) - { - Index actual_kc = (std::min)(IsLower ? depth-k2 : k2, kc); - Index actual_k2 = IsLower ? k2 : k2-actual_kc; - - // align blocks with the end of the triangular part for trapezoidal rhs - if(IsLower && (k2<cols) && (actual_k2+actual_kc>cols)) - { - actual_kc = cols-k2; - k2 = actual_k2 + actual_kc - kc; - } - - // remaining size - Index rs = IsLower ? (std::min)(cols,actual_k2) : cols - k2; - // size of the triangular part - Index ts = (IsLower && actual_k2>=cols) ? 0 : actual_kc; - - Scalar* geb = blockB+ts*ts; - geb = geb + internal::first_aligned<PacketBytes>(geb,PacketBytes/sizeof(Scalar)); - - pack_rhs(geb, rhs.getSubMapper(actual_k2,IsLower ? 0 : k2), actual_kc, rs); - - // pack the triangular part of the rhs padding the unrolled blocks with zeros - if(ts>0) - { - for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth) - { - Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth); - Index actual_j2 = actual_k2 + j2; - Index panelOffset = IsLower ? j2+actualPanelWidth : 0; - Index panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2; - // general part - pack_rhs_panel(blockB+j2*actual_kc, - rhs.getSubMapper(actual_k2+panelOffset, actual_j2), - panelLength, actualPanelWidth, - actual_kc, panelOffset); - - // append the triangular part via a temporary buffer - for (Index j=0;j<actualPanelWidth;++j) - { - if (SetDiag) - triangularBuffer.coeffRef(j,j) = rhs(actual_j2+j,actual_j2+j); - for (Index k=IsLower ? j+1 : 0; IsLower ? k<actualPanelWidth : k<j; ++k) - triangularBuffer.coeffRef(k,j) = rhs(actual_j2+k,actual_j2+j); - } - - pack_rhs_panel(blockB+j2*actual_kc, - RhsMapper(triangularBuffer.data(), triangularBuffer.outerStride()), - actualPanelWidth, actualPanelWidth, - actual_kc, j2); - } - } - - for (Index i2=0; i2<rows; i2+=mc) - { - const Index actual_mc = (std::min)(mc,rows-i2); - pack_lhs(blockA, lhs.getSubMapper(i2, actual_k2), actual_kc, actual_mc); - - // triangular kernel - if(ts>0) - { - for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth) - { - Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth); - Index panelLength = IsLower ? actual_kc-j2 : j2+actualPanelWidth; - Index blockOffset = IsLower ? j2 : 0; - - gebp_kernel(res.getSubMapper(i2, actual_k2 + j2), - blockA, blockB+j2*actual_kc, - actual_mc, panelLength, actualPanelWidth, - alpha, - actual_kc, actual_kc, // strides - blockOffset, blockOffset);// offsets - } - } - gebp_kernel(res.getSubMapper(i2, IsLower ? 0 : k2), - blockA, geb, actual_mc, actual_kc, rs, - alpha, - -1, -1, 0, 0); - } - } - } - -/*************************************************************************** -* Wrapper to product_triangular_matrix_matrix -***************************************************************************/ - -} // end namespace internal - -namespace internal { -template<int Mode, bool LhsIsTriangular, typename Lhs, typename Rhs> -struct triangular_product_impl<Mode,LhsIsTriangular,Lhs,false,Rhs,false> -{ - template<typename Dest> static void run(Dest& dst, const Lhs &a_lhs, const Rhs &a_rhs, const typename Dest::Scalar& alpha) - { - typedef typename Lhs::Scalar LhsScalar; - typedef typename Rhs::Scalar RhsScalar; - typedef typename Dest::Scalar Scalar; - - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; - typedef typename internal::remove_all<ActualLhsType>::type ActualLhsTypeCleaned; - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned; - - typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs); - typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs); - - LhsScalar lhs_alpha = LhsBlasTraits::extractScalarFactor(a_lhs); - RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(a_rhs); - Scalar actualAlpha = alpha * lhs_alpha * rhs_alpha; - - typedef internal::gemm_blocking_space<(Dest::Flags&RowMajorBit) ? RowMajor : ColMajor,Scalar,Scalar, - Lhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxColsAtCompileTime,4> BlockingType; - - enum { IsLower = (Mode&Lower) == Lower }; - Index stripedRows = ((!LhsIsTriangular) || (IsLower)) ? lhs.rows() : (std::min)(lhs.rows(),lhs.cols()); - Index stripedCols = ((LhsIsTriangular) || (!IsLower)) ? rhs.cols() : (std::min)(rhs.cols(),rhs.rows()); - Index stripedDepth = LhsIsTriangular ? ((!IsLower) ? lhs.cols() : (std::min)(lhs.cols(),lhs.rows())) - : ((IsLower) ? rhs.rows() : (std::min)(rhs.rows(),rhs.cols())); - - BlockingType blocking(stripedRows, stripedCols, stripedDepth, 1, false); - - internal::product_triangular_matrix_matrix<Scalar, Index, - Mode, LhsIsTriangular, - (internal::traits<ActualLhsTypeCleaned>::Flags&RowMajorBit) ? RowMajor : ColMajor, LhsBlasTraits::NeedToConjugate, - (internal::traits<ActualRhsTypeCleaned>::Flags&RowMajorBit) ? RowMajor : ColMajor, RhsBlasTraits::NeedToConjugate, - (internal::traits<Dest >::Flags&RowMajorBit) ? RowMajor : ColMajor, Dest::InnerStrideAtCompileTime> - ::run( - stripedRows, stripedCols, stripedDepth, // sizes - &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info - &rhs.coeffRef(0,0), rhs.outerStride(), // rhs info - &dst.coeffRef(0,0), dst.innerStride(), dst.outerStride(), // result info - actualAlpha, blocking - ); - - // Apply correction if the diagonal is unit and a scalar factor was nested: - if ((Mode&UnitDiag)==UnitDiag) - { - if (LhsIsTriangular && lhs_alpha!=LhsScalar(1)) - { - Index diagSize = (std::min)(lhs.rows(),lhs.cols()); - dst.topRows(diagSize) -= ((lhs_alpha-LhsScalar(1))*a_rhs).topRows(diagSize); - } - else if ((!LhsIsTriangular) && rhs_alpha!=RhsScalar(1)) - { - Index diagSize = (std::min)(rhs.rows(),rhs.cols()); - dst.leftCols(diagSize) -= (rhs_alpha-RhsScalar(1))*a_lhs.leftCols(diagSize); - } - } - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRIANGULAR_MATRIX_MATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h b/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h deleted file mode 100644 index a98d12e4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +++ /dev/null @@ -1,317 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to BLAS F77 - * Triangular matrix * matrix product functionality based on ?TRMM. - ******************************************************************************** -*/ - -#ifndef EIGEN_TRIANGULAR_MATRIX_MATRIX_BLAS_H -#define EIGEN_TRIANGULAR_MATRIX_MATRIX_BLAS_H - -namespace Eigen { - -namespace internal { - - -template <typename Scalar, typename Index, - int Mode, bool LhsIsTriangular, - int LhsStorageOrder, bool ConjugateLhs, - int RhsStorageOrder, bool ConjugateRhs, - int ResStorageOrder> -struct product_triangular_matrix_matrix_trmm : - product_triangular_matrix_matrix<Scalar,Index,Mode, - LhsIsTriangular,LhsStorageOrder,ConjugateLhs, - RhsStorageOrder, ConjugateRhs, ResStorageOrder, 1, BuiltIn> {}; - - -// try to go to BLAS specialization -#define EIGEN_BLAS_TRMM_SPECIALIZE(Scalar, LhsIsTriangular) \ -template <typename Index, int Mode, \ - int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs> \ -struct product_triangular_matrix_matrix<Scalar,Index, Mode, LhsIsTriangular, \ - LhsStorageOrder,ConjugateLhs, RhsStorageOrder,ConjugateRhs,ColMajor,1,Specialized> { \ - static inline void run(Index _rows, Index _cols, Index _depth, const Scalar* _lhs, Index lhsStride,\ - const Scalar* _rhs, Index rhsStride, Scalar* res, Index resIncr, Index resStride, Scalar alpha, level3_blocking<Scalar,Scalar>& blocking) { \ - EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \ - eigen_assert(resIncr == 1); \ - product_triangular_matrix_matrix_trmm<Scalar,Index,Mode, \ - LhsIsTriangular,LhsStorageOrder,ConjugateLhs, \ - RhsStorageOrder, ConjugateRhs, ColMajor>::run( \ - _rows, _cols, _depth, _lhs, lhsStride, _rhs, rhsStride, res, resStride, alpha, blocking); \ - } \ -}; - -EIGEN_BLAS_TRMM_SPECIALIZE(double, true) -EIGEN_BLAS_TRMM_SPECIALIZE(double, false) -EIGEN_BLAS_TRMM_SPECIALIZE(dcomplex, true) -EIGEN_BLAS_TRMM_SPECIALIZE(dcomplex, false) -EIGEN_BLAS_TRMM_SPECIALIZE(float, true) -EIGEN_BLAS_TRMM_SPECIALIZE(float, false) -EIGEN_BLAS_TRMM_SPECIALIZE(scomplex, true) -EIGEN_BLAS_TRMM_SPECIALIZE(scomplex, false) - -// implements col-major += alpha * op(triangular) * op(general) -#define EIGEN_BLAS_TRMM_L(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \ -template <typename Index, int Mode, \ - int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs> \ -struct product_triangular_matrix_matrix_trmm<EIGTYPE,Index,Mode,true, \ - LhsStorageOrder,ConjugateLhs,RhsStorageOrder,ConjugateRhs,ColMajor> \ -{ \ - enum { \ - IsLower = (Mode&Lower) == Lower, \ - SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1, \ - IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \ - IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \ - LowUp = IsLower ? Lower : Upper, \ - conjA = ((LhsStorageOrder==ColMajor) && ConjugateLhs) ? 1 : 0 \ - }; \ -\ - static void run( \ - Index _rows, Index _cols, Index _depth, \ - const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsStride, \ - EIGTYPE* res, Index resStride, \ - EIGTYPE alpha, level3_blocking<EIGTYPE,EIGTYPE>& blocking) \ - { \ - Index diagSize = (std::min)(_rows,_depth); \ - Index rows = IsLower ? _rows : diagSize; \ - Index depth = IsLower ? diagSize : _depth; \ - Index cols = _cols; \ -\ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder> MatrixLhs; \ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> MatrixRhs; \ -\ -/* Non-square case - doesn't fit to BLAS ?TRMM. Fall to default triangular product or call BLAS ?GEMM*/ \ - if (rows != depth) { \ -\ - /* FIXME handle mkl_domain_get_max_threads */ \ - /*int nthr = mkl_domain_get_max_threads(EIGEN_BLAS_DOMAIN_BLAS);*/ int nthr = 1;\ -\ - if (((nthr==1) && (((std::max)(rows,depth)-diagSize)/(double)diagSize < 0.5))) { \ - /* Most likely no benefit to call TRMM or GEMM from BLAS */ \ - product_triangular_matrix_matrix<EIGTYPE,Index,Mode,true, \ - LhsStorageOrder,ConjugateLhs, RhsStorageOrder, ConjugateRhs, ColMajor, 1, BuiltIn>::run( \ - _rows, _cols, _depth, _lhs, lhsStride, _rhs, rhsStride, res, 1, resStride, alpha, blocking); \ - /*std::cout << "TRMM_L: A is not square! Go to Eigen TRMM implementation!\n";*/ \ - } else { \ - /* Make sense to call GEMM */ \ - Map<const MatrixLhs, 0, OuterStride<> > lhsMap(_lhs,rows,depth,OuterStride<>(lhsStride)); \ - MatrixLhs aa_tmp=lhsMap.template triangularView<Mode>(); \ - BlasIndex aStride = convert_index<BlasIndex>(aa_tmp.outerStride()); \ - gemm_blocking_space<ColMajor,EIGTYPE,EIGTYPE,Dynamic,Dynamic,Dynamic> gemm_blocking(_rows,_cols,_depth, 1, true); \ - general_matrix_matrix_product<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,RhsStorageOrder,ConjugateRhs,ColMajor,1>::run( \ - rows, cols, depth, aa_tmp.data(), aStride, _rhs, rhsStride, res, 1, resStride, alpha, gemm_blocking, 0); \ -\ - /*std::cout << "TRMM_L: A is not square! Go to BLAS GEMM implementation! " << nthr<<" \n";*/ \ - } \ - return; \ - } \ - char side = 'L', transa, uplo, diag = 'N'; \ - EIGTYPE *b; \ - const EIGTYPE *a; \ - BlasIndex m, n, lda, ldb; \ -\ -/* Set m, n */ \ - m = convert_index<BlasIndex>(diagSize); \ - n = convert_index<BlasIndex>(cols); \ -\ -/* Set trans */ \ - transa = (LhsStorageOrder==RowMajor) ? ((ConjugateLhs) ? 'C' : 'T') : 'N'; \ -\ -/* Set b, ldb */ \ - Map<const MatrixRhs, 0, OuterStride<> > rhs(_rhs,depth,cols,OuterStride<>(rhsStride)); \ - MatrixX##EIGPREFIX b_tmp; \ -\ - if (ConjugateRhs) b_tmp = rhs.conjugate(); else b_tmp = rhs; \ - b = b_tmp.data(); \ - ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \ -\ -/* Set uplo */ \ - uplo = IsLower ? 'L' : 'U'; \ - if (LhsStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \ -/* Set a, lda */ \ - Map<const MatrixLhs, 0, OuterStride<> > lhs(_lhs,rows,depth,OuterStride<>(lhsStride)); \ - MatrixLhs a_tmp; \ -\ - if ((conjA!=0) || (SetDiag==0)) { \ - if (conjA) a_tmp = lhs.conjugate(); else a_tmp = lhs; \ - if (IsZeroDiag) \ - a_tmp.diagonal().setZero(); \ - else if (IsUnitDiag) \ - a_tmp.diagonal().setOnes();\ - a = a_tmp.data(); \ - lda = convert_index<BlasIndex>(a_tmp.outerStride()); \ - } else { \ - a = _lhs; \ - lda = convert_index<BlasIndex>(lhsStride); \ - } \ - /*std::cout << "TRMM_L: A is square! Go to BLAS TRMM implementation! \n";*/ \ -/* call ?trmm*/ \ - BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (BLASTYPE*)b, &ldb); \ -\ -/* Add op(a_triangular)*b into res*/ \ - Map<MatrixX##EIGPREFIX, 0, OuterStride<> > res_tmp(res,rows,cols,OuterStride<>(resStride)); \ - res_tmp=res_tmp+b_tmp; \ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_TRMM_L(double, double, d, dtrmm) -EIGEN_BLAS_TRMM_L(dcomplex, MKL_Complex16, cd, ztrmm) -EIGEN_BLAS_TRMM_L(float, float, f, strmm) -EIGEN_BLAS_TRMM_L(scomplex, MKL_Complex8, cf, ctrmm) -#else -EIGEN_BLAS_TRMM_L(double, double, d, dtrmm_) -EIGEN_BLAS_TRMM_L(dcomplex, double, cd, ztrmm_) -EIGEN_BLAS_TRMM_L(float, float, f, strmm_) -EIGEN_BLAS_TRMM_L(scomplex, float, cf, ctrmm_) -#endif - -// implements col-major += alpha * op(general) * op(triangular) -#define EIGEN_BLAS_TRMM_R(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \ -template <typename Index, int Mode, \ - int LhsStorageOrder, bool ConjugateLhs, \ - int RhsStorageOrder, bool ConjugateRhs> \ -struct product_triangular_matrix_matrix_trmm<EIGTYPE,Index,Mode,false, \ - LhsStorageOrder,ConjugateLhs,RhsStorageOrder,ConjugateRhs,ColMajor> \ -{ \ - enum { \ - IsLower = (Mode&Lower) == Lower, \ - SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1, \ - IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \ - IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \ - LowUp = IsLower ? Lower : Upper, \ - conjA = ((RhsStorageOrder==ColMajor) && ConjugateRhs) ? 1 : 0 \ - }; \ -\ - static void run( \ - Index _rows, Index _cols, Index _depth, \ - const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsStride, \ - EIGTYPE* res, Index resStride, \ - EIGTYPE alpha, level3_blocking<EIGTYPE,EIGTYPE>& blocking) \ - { \ - Index diagSize = (std::min)(_cols,_depth); \ - Index rows = _rows; \ - Index depth = IsLower ? _depth : diagSize; \ - Index cols = IsLower ? diagSize : _cols; \ -\ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder> MatrixLhs; \ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> MatrixRhs; \ -\ -/* Non-square case - doesn't fit to BLAS ?TRMM. Fall to default triangular product or call BLAS ?GEMM*/ \ - if (cols != depth) { \ -\ - int nthr = 1 /*mkl_domain_get_max_threads(EIGEN_BLAS_DOMAIN_BLAS)*/; \ -\ - if ((nthr==1) && (((std::max)(cols,depth)-diagSize)/(double)diagSize < 0.5)) { \ - /* Most likely no benefit to call TRMM or GEMM from BLAS*/ \ - product_triangular_matrix_matrix<EIGTYPE,Index,Mode,false, \ - LhsStorageOrder,ConjugateLhs, RhsStorageOrder, ConjugateRhs, ColMajor, 1, BuiltIn>::run( \ - _rows, _cols, _depth, _lhs, lhsStride, _rhs, rhsStride, res, 1, resStride, alpha, blocking); \ - /*std::cout << "TRMM_R: A is not square! Go to Eigen TRMM implementation!\n";*/ \ - } else { \ - /* Make sense to call GEMM */ \ - Map<const MatrixRhs, 0, OuterStride<> > rhsMap(_rhs,depth,cols, OuterStride<>(rhsStride)); \ - MatrixRhs aa_tmp=rhsMap.template triangularView<Mode>(); \ - BlasIndex aStride = convert_index<BlasIndex>(aa_tmp.outerStride()); \ - gemm_blocking_space<ColMajor,EIGTYPE,EIGTYPE,Dynamic,Dynamic,Dynamic> gemm_blocking(_rows,_cols,_depth, 1, true); \ - general_matrix_matrix_product<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,RhsStorageOrder,ConjugateRhs,ColMajor,1>::run( \ - rows, cols, depth, _lhs, lhsStride, aa_tmp.data(), aStride, res, 1, resStride, alpha, gemm_blocking, 0); \ -\ - /*std::cout << "TRMM_R: A is not square! Go to BLAS GEMM implementation! " << nthr<<" \n";*/ \ - } \ - return; \ - } \ - char side = 'R', transa, uplo, diag = 'N'; \ - EIGTYPE *b; \ - const EIGTYPE *a; \ - BlasIndex m, n, lda, ldb; \ -\ -/* Set m, n */ \ - m = convert_index<BlasIndex>(rows); \ - n = convert_index<BlasIndex>(diagSize); \ -\ -/* Set trans */ \ - transa = (RhsStorageOrder==RowMajor) ? ((ConjugateRhs) ? 'C' : 'T') : 'N'; \ -\ -/* Set b, ldb */ \ - Map<const MatrixLhs, 0, OuterStride<> > lhs(_lhs,rows,depth,OuterStride<>(lhsStride)); \ - MatrixX##EIGPREFIX b_tmp; \ -\ - if (ConjugateLhs) b_tmp = lhs.conjugate(); else b_tmp = lhs; \ - b = b_tmp.data(); \ - ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \ -\ -/* Set uplo */ \ - uplo = IsLower ? 'L' : 'U'; \ - if (RhsStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \ -/* Set a, lda */ \ - Map<const MatrixRhs, 0, OuterStride<> > rhs(_rhs,depth,cols, OuterStride<>(rhsStride)); \ - MatrixRhs a_tmp; \ -\ - if ((conjA!=0) || (SetDiag==0)) { \ - if (conjA) a_tmp = rhs.conjugate(); else a_tmp = rhs; \ - if (IsZeroDiag) \ - a_tmp.diagonal().setZero(); \ - else if (IsUnitDiag) \ - a_tmp.diagonal().setOnes();\ - a = a_tmp.data(); \ - lda = convert_index<BlasIndex>(a_tmp.outerStride()); \ - } else { \ - a = _rhs; \ - lda = convert_index<BlasIndex>(rhsStride); \ - } \ - /*std::cout << "TRMM_R: A is square! Go to BLAS TRMM implementation! \n";*/ \ -/* call ?trmm*/ \ - BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (BLASTYPE*)b, &ldb); \ -\ -/* Add op(a_triangular)*b into res*/ \ - Map<MatrixX##EIGPREFIX, 0, OuterStride<> > res_tmp(res,rows,cols,OuterStride<>(resStride)); \ - res_tmp=res_tmp+b_tmp; \ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_TRMM_R(double, double, d, dtrmm) -EIGEN_BLAS_TRMM_R(dcomplex, MKL_Complex16, cd, ztrmm) -EIGEN_BLAS_TRMM_R(float, float, f, strmm) -EIGEN_BLAS_TRMM_R(scomplex, MKL_Complex8, cf, ctrmm) -#else -EIGEN_BLAS_TRMM_R(double, double, d, dtrmm_) -EIGEN_BLAS_TRMM_R(dcomplex, double, cd, ztrmm_) -EIGEN_BLAS_TRMM_R(float, float, f, strmm_) -EIGEN_BLAS_TRMM_R(scomplex, float, cf, ctrmm_) -#endif -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRIANGULAR_MATRIX_MATRIX_BLAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixVector.h b/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixVector.h deleted file mode 100644 index 76bfa159..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixVector.h +++ /dev/null @@ -1,350 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRIANGULARMATRIXVECTOR_H -#define EIGEN_TRIANGULARMATRIXVECTOR_H - -namespace Eigen { - -namespace internal { - -template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int StorageOrder, int Version=Specialized> -struct triangular_matrix_vector_product; - -template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int Version> -struct triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,ColMajor,Version> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - enum { - IsLower = ((Mode&Lower)==Lower), - HasUnitDiag = (Mode & UnitDiag)==UnitDiag, - HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag - }; - static EIGEN_DONT_INLINE void run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride, - const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const RhsScalar& alpha); -}; - -template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int Version> -EIGEN_DONT_INLINE void triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,ColMajor,Version> - ::run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride, - const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const RhsScalar& alpha) - { - static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; - Index size = (std::min)(_rows,_cols); - Index rows = IsLower ? _rows : (std::min)(_rows,_cols); - Index cols = IsLower ? (std::min)(_rows,_cols) : _cols; - - typedef Map<const Matrix<LhsScalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > LhsMap; - const LhsMap lhs(_lhs,rows,cols,OuterStride<>(lhsStride)); - typename conj_expr_if<ConjLhs,LhsMap>::type cjLhs(lhs); - - typedef Map<const Matrix<RhsScalar,Dynamic,1>, 0, InnerStride<> > RhsMap; - const RhsMap rhs(_rhs,cols,InnerStride<>(rhsIncr)); - typename conj_expr_if<ConjRhs,RhsMap>::type cjRhs(rhs); - - typedef Map<Matrix<ResScalar,Dynamic,1> > ResMap; - ResMap res(_res,rows); - - typedef const_blas_data_mapper<LhsScalar,Index,ColMajor> LhsMapper; - typedef const_blas_data_mapper<RhsScalar,Index,RowMajor> RhsMapper; - - for (Index pi=0; pi<size; pi+=PanelWidth) - { - Index actualPanelWidth = (std::min)(PanelWidth, size-pi); - for (Index k=0; k<actualPanelWidth; ++k) - { - Index i = pi + k; - Index s = IsLower ? ((HasUnitDiag||HasZeroDiag) ? i+1 : i ) : pi; - Index r = IsLower ? actualPanelWidth-k : k+1; - if ((!(HasUnitDiag||HasZeroDiag)) || (--r)>0) - res.segment(s,r) += (alpha * cjRhs.coeff(i)) * cjLhs.col(i).segment(s,r); - if (HasUnitDiag) - res.coeffRef(i) += alpha * cjRhs.coeff(i); - } - Index r = IsLower ? rows - pi - actualPanelWidth : pi; - if (r>0) - { - Index s = IsLower ? pi+actualPanelWidth : 0; - general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,ConjLhs,RhsScalar,RhsMapper,ConjRhs,BuiltIn>::run( - r, actualPanelWidth, - LhsMapper(&lhs.coeffRef(s,pi), lhsStride), - RhsMapper(&rhs.coeffRef(pi), rhsIncr), - &res.coeffRef(s), resIncr, alpha); - } - } - if((!IsLower) && cols>size) - { - general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,ConjLhs,RhsScalar,RhsMapper,ConjRhs>::run( - rows, cols-size, - LhsMapper(&lhs.coeffRef(0,size), lhsStride), - RhsMapper(&rhs.coeffRef(size), rhsIncr), - _res, resIncr, alpha); - } - } - -template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs,int Version> -struct triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,RowMajor,Version> -{ - typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar; - enum { - IsLower = ((Mode&Lower)==Lower), - HasUnitDiag = (Mode & UnitDiag)==UnitDiag, - HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag - }; - static EIGEN_DONT_INLINE void run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride, - const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const ResScalar& alpha); -}; - -template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs,int Version> -EIGEN_DONT_INLINE void triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,RowMajor,Version> - ::run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride, - const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const ResScalar& alpha) - { - static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; - Index diagSize = (std::min)(_rows,_cols); - Index rows = IsLower ? _rows : diagSize; - Index cols = IsLower ? diagSize : _cols; - - typedef Map<const Matrix<LhsScalar,Dynamic,Dynamic,RowMajor>, 0, OuterStride<> > LhsMap; - const LhsMap lhs(_lhs,rows,cols,OuterStride<>(lhsStride)); - typename conj_expr_if<ConjLhs,LhsMap>::type cjLhs(lhs); - - typedef Map<const Matrix<RhsScalar,Dynamic,1> > RhsMap; - const RhsMap rhs(_rhs,cols); - typename conj_expr_if<ConjRhs,RhsMap>::type cjRhs(rhs); - - typedef Map<Matrix<ResScalar,Dynamic,1>, 0, InnerStride<> > ResMap; - ResMap res(_res,rows,InnerStride<>(resIncr)); - - typedef const_blas_data_mapper<LhsScalar,Index,RowMajor> LhsMapper; - typedef const_blas_data_mapper<RhsScalar,Index,RowMajor> RhsMapper; - - for (Index pi=0; pi<diagSize; pi+=PanelWidth) - { - Index actualPanelWidth = (std::min)(PanelWidth, diagSize-pi); - for (Index k=0; k<actualPanelWidth; ++k) - { - Index i = pi + k; - Index s = IsLower ? pi : ((HasUnitDiag||HasZeroDiag) ? i+1 : i); - Index r = IsLower ? k+1 : actualPanelWidth-k; - if ((!(HasUnitDiag||HasZeroDiag)) || (--r)>0) - res.coeffRef(i) += alpha * (cjLhs.row(i).segment(s,r).cwiseProduct(cjRhs.segment(s,r).transpose())).sum(); - if (HasUnitDiag) - res.coeffRef(i) += alpha * cjRhs.coeff(i); - } - Index r = IsLower ? pi : cols - pi - actualPanelWidth; - if (r>0) - { - Index s = IsLower ? 0 : pi + actualPanelWidth; - general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,ConjLhs,RhsScalar,RhsMapper,ConjRhs,BuiltIn>::run( - actualPanelWidth, r, - LhsMapper(&lhs.coeffRef(pi,s), lhsStride), - RhsMapper(&rhs.coeffRef(s), rhsIncr), - &res.coeffRef(pi), resIncr, alpha); - } - } - if(IsLower && rows>diagSize) - { - general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,ConjLhs,RhsScalar,RhsMapper,ConjRhs>::run( - rows-diagSize, cols, - LhsMapper(&lhs.coeffRef(diagSize,0), lhsStride), - RhsMapper(&rhs.coeffRef(0), rhsIncr), - &res.coeffRef(diagSize), resIncr, alpha); - } - } - -/*************************************************************************** -* Wrapper to product_triangular_vector -***************************************************************************/ - -template<int Mode,int StorageOrder> -struct trmv_selector; - -} // end namespace internal - -namespace internal { - -template<int Mode, typename Lhs, typename Rhs> -struct triangular_product_impl<Mode,true,Lhs,false,Rhs,true> -{ - template<typename Dest> static void run(Dest& dst, const Lhs &lhs, const Rhs &rhs, const typename Dest::Scalar& alpha) - { - eigen_assert(dst.rows()==lhs.rows() && dst.cols()==rhs.cols()); - - internal::trmv_selector<Mode,(int(internal::traits<Lhs>::Flags)&RowMajorBit) ? RowMajor : ColMajor>::run(lhs, rhs, dst, alpha); - } -}; - -template<int Mode, typename Lhs, typename Rhs> -struct triangular_product_impl<Mode,false,Lhs,true,Rhs,false> -{ - template<typename Dest> static void run(Dest& dst, const Lhs &lhs, const Rhs &rhs, const typename Dest::Scalar& alpha) - { - eigen_assert(dst.rows()==lhs.rows() && dst.cols()==rhs.cols()); - - Transpose<Dest> dstT(dst); - internal::trmv_selector<(Mode & (UnitDiag|ZeroDiag)) | ((Mode & Lower) ? Upper : Lower), - (int(internal::traits<Rhs>::Flags)&RowMajorBit) ? ColMajor : RowMajor> - ::run(rhs.transpose(),lhs.transpose(), dstT, alpha); - } -}; - -} // end namespace internal - -namespace internal { - -// TODO: find a way to factorize this piece of code with gemv_selector since the logic is exactly the same. - -template<int Mode> struct trmv_selector<Mode,ColMajor> -{ - template<typename Lhs, typename Rhs, typename Dest> - static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha) - { - typedef typename Lhs::Scalar LhsScalar; - typedef typename Rhs::Scalar RhsScalar; - typedef typename Dest::Scalar ResScalar; - typedef typename Dest::RealScalar RealScalar; - - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - - typedef Map<Matrix<ResScalar,Dynamic,1>, EIGEN_PLAIN_ENUM_MIN(AlignedMax,internal::packet_traits<ResScalar>::size)> MappedDest; - - typename internal::add_const_on_value_type<ActualLhsType>::type actualLhs = LhsBlasTraits::extract(lhs); - typename internal::add_const_on_value_type<ActualRhsType>::type actualRhs = RhsBlasTraits::extract(rhs); - - LhsScalar lhs_alpha = LhsBlasTraits::extractScalarFactor(lhs); - RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(rhs); - ResScalar actualAlpha = alpha * lhs_alpha * rhs_alpha; - - enum { - // FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1 - // on, the other hand it is good for the cache to pack the vector anyways... - EvalToDestAtCompileTime = Dest::InnerStrideAtCompileTime==1, - ComplexByReal = (NumTraits<LhsScalar>::IsComplex) && (!NumTraits<RhsScalar>::IsComplex), - MightCannotUseDest = (Dest::InnerStrideAtCompileTime!=1) || ComplexByReal - }; - - gemv_static_vector_if<ResScalar,Dest::SizeAtCompileTime,Dest::MaxSizeAtCompileTime,MightCannotUseDest> static_dest; - - bool alphaIsCompatible = (!ComplexByReal) || (numext::imag(actualAlpha)==RealScalar(0)); - bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible; - - RhsScalar compatibleAlpha = get_factor<ResScalar,RhsScalar>::run(actualAlpha); - - ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(), - evalToDest ? dest.data() : static_dest.data()); - - if(!evalToDest) - { - #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN - Index size = dest.size(); - EIGEN_DENSE_STORAGE_CTOR_PLUGIN - #endif - if(!alphaIsCompatible) - { - MappedDest(actualDestPtr, dest.size()).setZero(); - compatibleAlpha = RhsScalar(1); - } - else - MappedDest(actualDestPtr, dest.size()) = dest; - } - - internal::triangular_matrix_vector_product - <Index,Mode, - LhsScalar, LhsBlasTraits::NeedToConjugate, - RhsScalar, RhsBlasTraits::NeedToConjugate, - ColMajor> - ::run(actualLhs.rows(),actualLhs.cols(), - actualLhs.data(),actualLhs.outerStride(), - actualRhs.data(),actualRhs.innerStride(), - actualDestPtr,1,compatibleAlpha); - - if (!evalToDest) - { - if(!alphaIsCompatible) - dest += actualAlpha * MappedDest(actualDestPtr, dest.size()); - else - dest = MappedDest(actualDestPtr, dest.size()); - } - - if ( ((Mode&UnitDiag)==UnitDiag) && (lhs_alpha!=LhsScalar(1)) ) - { - Index diagSize = (std::min)(lhs.rows(),lhs.cols()); - dest.head(diagSize) -= (lhs_alpha-LhsScalar(1))*rhs.head(diagSize); - } - } -}; - -template<int Mode> struct trmv_selector<Mode,RowMajor> -{ - template<typename Lhs, typename Rhs, typename Dest> - static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha) - { - typedef typename Lhs::Scalar LhsScalar; - typedef typename Rhs::Scalar RhsScalar; - typedef typename Dest::Scalar ResScalar; - - typedef internal::blas_traits<Lhs> LhsBlasTraits; - typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; - typedef internal::blas_traits<Rhs> RhsBlasTraits; - typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; - typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned; - - typename add_const<ActualLhsType>::type actualLhs = LhsBlasTraits::extract(lhs); - typename add_const<ActualRhsType>::type actualRhs = RhsBlasTraits::extract(rhs); - - LhsScalar lhs_alpha = LhsBlasTraits::extractScalarFactor(lhs); - RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(rhs); - ResScalar actualAlpha = alpha * lhs_alpha * rhs_alpha; - - enum { - DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime==1 - }; - - gemv_static_vector_if<RhsScalar,ActualRhsTypeCleaned::SizeAtCompileTime,ActualRhsTypeCleaned::MaxSizeAtCompileTime,!DirectlyUseRhs> static_rhs; - - ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,actualRhs.size(), - DirectlyUseRhs ? const_cast<RhsScalar*>(actualRhs.data()) : static_rhs.data()); - - if(!DirectlyUseRhs) - { - #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN - Index size = actualRhs.size(); - EIGEN_DENSE_STORAGE_CTOR_PLUGIN - #endif - Map<typename ActualRhsTypeCleaned::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs; - } - - internal::triangular_matrix_vector_product - <Index,Mode, - LhsScalar, LhsBlasTraits::NeedToConjugate, - RhsScalar, RhsBlasTraits::NeedToConjugate, - RowMajor> - ::run(actualLhs.rows(),actualLhs.cols(), - actualLhs.data(),actualLhs.outerStride(), - actualRhsPtr,1, - dest.data(),dest.innerStride(), - actualAlpha); - - if ( ((Mode&UnitDiag)==UnitDiag) && (lhs_alpha!=LhsScalar(1)) ) - { - Index diagSize = (std::min)(lhs.rows(),lhs.cols()); - dest.head(diagSize) -= (lhs_alpha-LhsScalar(1))*rhs.head(diagSize); - } - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRIANGULARMATRIXVECTOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h b/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h deleted file mode 100644 index 3d47a2b9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +++ /dev/null @@ -1,255 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to BLAS F77 - * Triangular matrix-vector product functionality based on ?TRMV. - ******************************************************************************** -*/ - -#ifndef EIGEN_TRIANGULAR_MATRIX_VECTOR_BLAS_H -#define EIGEN_TRIANGULAR_MATRIX_VECTOR_BLAS_H - -namespace Eigen { - -namespace internal { - -/********************************************************************** -* This file implements triangular matrix-vector multiplication using BLAS -**********************************************************************/ - -// trmv/hemv specialization - -template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int StorageOrder> -struct triangular_matrix_vector_product_trmv : - triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,StorageOrder,BuiltIn> {}; - -#define EIGEN_BLAS_TRMV_SPECIALIZE(Scalar) \ -template<typename Index, int Mode, bool ConjLhs, bool ConjRhs> \ -struct triangular_matrix_vector_product<Index,Mode,Scalar,ConjLhs,Scalar,ConjRhs,ColMajor,Specialized> { \ - static void run(Index _rows, Index _cols, const Scalar* _lhs, Index lhsStride, \ - const Scalar* _rhs, Index rhsIncr, Scalar* _res, Index resIncr, Scalar alpha) { \ - triangular_matrix_vector_product_trmv<Index,Mode,Scalar,ConjLhs,Scalar,ConjRhs,ColMajor>::run( \ - _rows, _cols, _lhs, lhsStride, _rhs, rhsIncr, _res, resIncr, alpha); \ - } \ -}; \ -template<typename Index, int Mode, bool ConjLhs, bool ConjRhs> \ -struct triangular_matrix_vector_product<Index,Mode,Scalar,ConjLhs,Scalar,ConjRhs,RowMajor,Specialized> { \ - static void run(Index _rows, Index _cols, const Scalar* _lhs, Index lhsStride, \ - const Scalar* _rhs, Index rhsIncr, Scalar* _res, Index resIncr, Scalar alpha) { \ - triangular_matrix_vector_product_trmv<Index,Mode,Scalar,ConjLhs,Scalar,ConjRhs,RowMajor>::run( \ - _rows, _cols, _lhs, lhsStride, _rhs, rhsIncr, _res, resIncr, alpha); \ - } \ -}; - -EIGEN_BLAS_TRMV_SPECIALIZE(double) -EIGEN_BLAS_TRMV_SPECIALIZE(float) -EIGEN_BLAS_TRMV_SPECIALIZE(dcomplex) -EIGEN_BLAS_TRMV_SPECIALIZE(scomplex) - -// implements col-major: res += alpha * op(triangular) * vector -#define EIGEN_BLAS_TRMV_CM(EIGTYPE, BLASTYPE, EIGPREFIX, BLASPREFIX, BLASPOSTFIX) \ -template<typename Index, int Mode, bool ConjLhs, bool ConjRhs> \ -struct triangular_matrix_vector_product_trmv<Index,Mode,EIGTYPE,ConjLhs,EIGTYPE,ConjRhs,ColMajor> { \ - enum { \ - IsLower = (Mode&Lower) == Lower, \ - SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1, \ - IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \ - IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \ - LowUp = IsLower ? Lower : Upper \ - }; \ - static void run(Index _rows, Index _cols, const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsIncr, EIGTYPE* _res, Index resIncr, EIGTYPE alpha) \ - { \ - if (ConjLhs || IsZeroDiag) { \ - triangular_matrix_vector_product<Index,Mode,EIGTYPE,ConjLhs,EIGTYPE,ConjRhs,ColMajor,BuiltIn>::run( \ - _rows, _cols, _lhs, lhsStride, _rhs, rhsIncr, _res, resIncr, alpha); \ - return; \ - }\ - Index size = (std::min)(_rows,_cols); \ - Index rows = IsLower ? _rows : size; \ - Index cols = IsLower ? size : _cols; \ -\ - typedef VectorX##EIGPREFIX VectorRhs; \ - EIGTYPE *x, *y;\ -\ -/* Set x*/ \ - Map<const VectorRhs, 0, InnerStride<> > rhs(_rhs,cols,InnerStride<>(rhsIncr)); \ - VectorRhs x_tmp; \ - if (ConjRhs) x_tmp = rhs.conjugate(); else x_tmp = rhs; \ - x = x_tmp.data(); \ -\ -/* Square part handling */\ -\ - char trans, uplo, diag; \ - BlasIndex m, n, lda, incx, incy; \ - EIGTYPE const *a; \ - EIGTYPE beta(1); \ -\ -/* Set m, n */ \ - n = convert_index<BlasIndex>(size); \ - lda = convert_index<BlasIndex>(lhsStride); \ - incx = 1; \ - incy = convert_index<BlasIndex>(resIncr); \ -\ -/* Set uplo, trans and diag*/ \ - trans = 'N'; \ - uplo = IsLower ? 'L' : 'U'; \ - diag = IsUnitDiag ? 'U' : 'N'; \ -\ -/* call ?TRMV*/ \ - BLASPREFIX##trmv##BLASPOSTFIX(&uplo, &trans, &diag, &n, (const BLASTYPE*)_lhs, &lda, (BLASTYPE*)x, &incx); \ -\ -/* Add op(a_tr)rhs into res*/ \ - BLASPREFIX##axpy##BLASPOSTFIX(&n, (const BLASTYPE*)&numext::real_ref(alpha),(const BLASTYPE*)x, &incx, (BLASTYPE*)_res, &incy); \ -/* Non-square case - doesn't fit to BLAS ?TRMV. Fall to default triangular product*/ \ - if (size<(std::max)(rows,cols)) { \ - if (ConjRhs) x_tmp = rhs.conjugate(); else x_tmp = rhs; \ - x = x_tmp.data(); \ - if (size<rows) { \ - y = _res + size*resIncr; \ - a = _lhs + size; \ - m = convert_index<BlasIndex>(rows-size); \ - n = convert_index<BlasIndex>(size); \ - } \ - else { \ - x += size; \ - y = _res; \ - a = _lhs + size*lda; \ - m = convert_index<BlasIndex>(size); \ - n = convert_index<BlasIndex>(cols-size); \ - } \ - BLASPREFIX##gemv##BLASPOSTFIX(&trans, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)x, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)y, &incy); \ - } \ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_TRMV_CM(double, double, d, d,) -EIGEN_BLAS_TRMV_CM(dcomplex, MKL_Complex16, cd, z,) -EIGEN_BLAS_TRMV_CM(float, float, f, s,) -EIGEN_BLAS_TRMV_CM(scomplex, MKL_Complex8, cf, c,) -#else -EIGEN_BLAS_TRMV_CM(double, double, d, d, _) -EIGEN_BLAS_TRMV_CM(dcomplex, double, cd, z, _) -EIGEN_BLAS_TRMV_CM(float, float, f, s, _) -EIGEN_BLAS_TRMV_CM(scomplex, float, cf, c, _) -#endif - -// implements row-major: res += alpha * op(triangular) * vector -#define EIGEN_BLAS_TRMV_RM(EIGTYPE, BLASTYPE, EIGPREFIX, BLASPREFIX, BLASPOSTFIX) \ -template<typename Index, int Mode, bool ConjLhs, bool ConjRhs> \ -struct triangular_matrix_vector_product_trmv<Index,Mode,EIGTYPE,ConjLhs,EIGTYPE,ConjRhs,RowMajor> { \ - enum { \ - IsLower = (Mode&Lower) == Lower, \ - SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1, \ - IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \ - IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \ - LowUp = IsLower ? Lower : Upper \ - }; \ - static void run(Index _rows, Index _cols, const EIGTYPE* _lhs, Index lhsStride, \ - const EIGTYPE* _rhs, Index rhsIncr, EIGTYPE* _res, Index resIncr, EIGTYPE alpha) \ - { \ - if (IsZeroDiag) { \ - triangular_matrix_vector_product<Index,Mode,EIGTYPE,ConjLhs,EIGTYPE,ConjRhs,RowMajor,BuiltIn>::run( \ - _rows, _cols, _lhs, lhsStride, _rhs, rhsIncr, _res, resIncr, alpha); \ - return; \ - }\ - Index size = (std::min)(_rows,_cols); \ - Index rows = IsLower ? _rows : size; \ - Index cols = IsLower ? size : _cols; \ -\ - typedef VectorX##EIGPREFIX VectorRhs; \ - EIGTYPE *x, *y;\ -\ -/* Set x*/ \ - Map<const VectorRhs, 0, InnerStride<> > rhs(_rhs,cols,InnerStride<>(rhsIncr)); \ - VectorRhs x_tmp; \ - if (ConjRhs) x_tmp = rhs.conjugate(); else x_tmp = rhs; \ - x = x_tmp.data(); \ -\ -/* Square part handling */\ -\ - char trans, uplo, diag; \ - BlasIndex m, n, lda, incx, incy; \ - EIGTYPE const *a; \ - EIGTYPE beta(1); \ -\ -/* Set m, n */ \ - n = convert_index<BlasIndex>(size); \ - lda = convert_index<BlasIndex>(lhsStride); \ - incx = 1; \ - incy = convert_index<BlasIndex>(resIncr); \ -\ -/* Set uplo, trans and diag*/ \ - trans = ConjLhs ? 'C' : 'T'; \ - uplo = IsLower ? 'U' : 'L'; \ - diag = IsUnitDiag ? 'U' : 'N'; \ -\ -/* call ?TRMV*/ \ - BLASPREFIX##trmv##BLASPOSTFIX(&uplo, &trans, &diag, &n, (const BLASTYPE*)_lhs, &lda, (BLASTYPE*)x, &incx); \ -\ -/* Add op(a_tr)rhs into res*/ \ - BLASPREFIX##axpy##BLASPOSTFIX(&n, (const BLASTYPE*)&numext::real_ref(alpha),(const BLASTYPE*)x, &incx, (BLASTYPE*)_res, &incy); \ -/* Non-square case - doesn't fit to BLAS ?TRMV. Fall to default triangular product*/ \ - if (size<(std::max)(rows,cols)) { \ - if (ConjRhs) x_tmp = rhs.conjugate(); else x_tmp = rhs; \ - x = x_tmp.data(); \ - if (size<rows) { \ - y = _res + size*resIncr; \ - a = _lhs + size*lda; \ - m = convert_index<BlasIndex>(rows-size); \ - n = convert_index<BlasIndex>(size); \ - } \ - else { \ - x += size; \ - y = _res; \ - a = _lhs + size; \ - m = convert_index<BlasIndex>(size); \ - n = convert_index<BlasIndex>(cols-size); \ - } \ - BLASPREFIX##gemv##BLASPOSTFIX(&trans, &n, &m, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)x, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)y, &incy); \ - } \ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_TRMV_RM(double, double, d, d,) -EIGEN_BLAS_TRMV_RM(dcomplex, MKL_Complex16, cd, z,) -EIGEN_BLAS_TRMV_RM(float, float, f, s,) -EIGEN_BLAS_TRMV_RM(scomplex, MKL_Complex8, cf, c,) -#else -EIGEN_BLAS_TRMV_RM(double, double, d, d,_) -EIGEN_BLAS_TRMV_RM(dcomplex, double, cd, z,_) -EIGEN_BLAS_TRMV_RM(float, float, f, s,_) -EIGEN_BLAS_TRMV_RM(scomplex, float, cf, c,_) -#endif - -} // end namespase internal - -} // end namespace Eigen - -#endif // EIGEN_TRIANGULAR_MATRIX_VECTOR_BLAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverMatrix.h b/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverMatrix.h deleted file mode 100644 index 0dcf3bb5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverMatrix.h +++ /dev/null @@ -1,335 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRIANGULAR_SOLVER_MATRIX_H -#define EIGEN_TRIANGULAR_SOLVER_MATRIX_H - -namespace Eigen { - -namespace internal { - -// if the rhs is row major, let's transpose the product -template <typename Scalar, typename Index, int Side, int Mode, bool Conjugate, int TriStorageOrder, int OtherInnerStride> -struct triangular_solve_matrix<Scalar,Index,Side,Mode,Conjugate,TriStorageOrder,RowMajor,OtherInnerStride> -{ - static void run( - Index size, Index cols, - const Scalar* tri, Index triStride, - Scalar* _other, Index otherIncr, Index otherStride, - level3_blocking<Scalar,Scalar>& blocking) - { - triangular_solve_matrix< - Scalar, Index, Side==OnTheLeft?OnTheRight:OnTheLeft, - (Mode&UnitDiag) | ((Mode&Upper) ? Lower : Upper), - NumTraits<Scalar>::IsComplex && Conjugate, - TriStorageOrder==RowMajor ? ColMajor : RowMajor, ColMajor, OtherInnerStride> - ::run(size, cols, tri, triStride, _other, otherIncr, otherStride, blocking); - } -}; - -/* Optimized triangular solver with multiple right hand side and the triangular matrix on the left - */ -template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder,int OtherInnerStride> -struct triangular_solve_matrix<Scalar,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor,OtherInnerStride> -{ - static EIGEN_DONT_INLINE void run( - Index size, Index otherSize, - const Scalar* _tri, Index triStride, - Scalar* _other, Index otherIncr, Index otherStride, - level3_blocking<Scalar,Scalar>& blocking); -}; -template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder, int OtherInnerStride> -EIGEN_DONT_INLINE void triangular_solve_matrix<Scalar,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor,OtherInnerStride>::run( - Index size, Index otherSize, - const Scalar* _tri, Index triStride, - Scalar* _other, Index otherIncr, Index otherStride, - level3_blocking<Scalar,Scalar>& blocking) - { - Index cols = otherSize; - - typedef const_blas_data_mapper<Scalar, Index, TriStorageOrder> TriMapper; - typedef blas_data_mapper<Scalar, Index, ColMajor, Unaligned, OtherInnerStride> OtherMapper; - TriMapper tri(_tri, triStride); - OtherMapper other(_other, otherStride, otherIncr); - - typedef gebp_traits<Scalar,Scalar> Traits; - - enum { - SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr), - IsLower = (Mode&Lower) == Lower - }; - - Index kc = blocking.kc(); // cache block size along the K direction - Index mc = (std::min)(size,blocking.mc()); // cache block size along the M direction - - std::size_t sizeA = kc*mc; - std::size_t sizeB = kc*cols; - - ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA()); - ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB()); - - conj_if<Conjugate> conj; - gebp_kernel<Scalar, Scalar, Index, OtherMapper, Traits::mr, Traits::nr, Conjugate, false> gebp_kernel; - gemm_pack_lhs<Scalar, Index, TriMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, TriStorageOrder> pack_lhs; - gemm_pack_rhs<Scalar, Index, OtherMapper, Traits::nr, ColMajor, false, true> pack_rhs; - - // the goal here is to subdivise the Rhs panels such that we keep some cache - // coherence when accessing the rhs elements - std::ptrdiff_t l1, l2, l3; - manage_caching_sizes(GetAction, &l1, &l2, &l3); - Index subcols = cols>0 ? l2/(4 * sizeof(Scalar) * std::max<Index>(otherStride,size)) : 0; - subcols = std::max<Index>((subcols/Traits::nr)*Traits::nr, Traits::nr); - - for(Index k2=IsLower ? 0 : size; - IsLower ? k2<size : k2>0; - IsLower ? k2+=kc : k2-=kc) - { - const Index actual_kc = (std::min)(IsLower ? size-k2 : k2, kc); - - // We have selected and packed a big horizontal panel R1 of rhs. Let B be the packed copy of this panel, - // and R2 the remaining part of rhs. The corresponding vertical panel of lhs is split into - // A11 (the triangular part) and A21 the remaining rectangular part. - // Then the high level algorithm is: - // - B = R1 => general block copy (done during the next step) - // - R1 = A11^-1 B => tricky part - // - update B from the new R1 => actually this has to be performed continuously during the above step - // - R2 -= A21 * B => GEPP - - // The tricky part: compute R1 = A11^-1 B while updating B from R1 - // The idea is to split A11 into multiple small vertical panels. - // Each panel can be split into a small triangular part T1k which is processed without optimization, - // and the remaining small part T2k which is processed using gebp with appropriate block strides - for(Index j2=0; j2<cols; j2+=subcols) - { - Index actual_cols = (std::min)(cols-j2,subcols); - // for each small vertical panels [T1k^T, T2k^T]^T of lhs - for (Index k1=0; k1<actual_kc; k1+=SmallPanelWidth) - { - Index actualPanelWidth = std::min<Index>(actual_kc-k1, SmallPanelWidth); - // tr solve - for (Index k=0; k<actualPanelWidth; ++k) - { - // TODO write a small kernel handling this (can be shared with trsv) - Index i = IsLower ? k2+k1+k : k2-k1-k-1; - Index rs = actualPanelWidth - k - 1; // remaining size - Index s = TriStorageOrder==RowMajor ? (IsLower ? k2+k1 : i+1) - : IsLower ? i+1 : i-rs; - - Scalar a = (Mode & UnitDiag) ? Scalar(1) : Scalar(1)/conj(tri(i,i)); - for (Index j=j2; j<j2+actual_cols; ++j) - { - if (TriStorageOrder==RowMajor) - { - Scalar b(0); - const Scalar* l = &tri(i,s); - typename OtherMapper::LinearMapper r = other.getLinearMapper(s,j); - for (Index i3=0; i3<k; ++i3) - b += conj(l[i3]) * r(i3); - - other(i,j) = (other(i,j) - b)*a; - } - else - { - Scalar b = (other(i,j) *= a); - typename OtherMapper::LinearMapper r = other.getLinearMapper(s,j); - typename TriMapper::LinearMapper l = tri.getLinearMapper(s,i); - for (Index i3=0;i3<rs;++i3) - r(i3) -= b * conj(l(i3)); - } - } - } - - Index lengthTarget = actual_kc-k1-actualPanelWidth; - Index startBlock = IsLower ? k2+k1 : k2-k1-actualPanelWidth; - Index blockBOffset = IsLower ? k1 : lengthTarget; - - // update the respective rows of B from other - pack_rhs(blockB+actual_kc*j2, other.getSubMapper(startBlock,j2), actualPanelWidth, actual_cols, actual_kc, blockBOffset); - - // GEBP - if (lengthTarget>0) - { - Index startTarget = IsLower ? k2+k1+actualPanelWidth : k2-actual_kc; - - pack_lhs(blockA, tri.getSubMapper(startTarget,startBlock), actualPanelWidth, lengthTarget); - - gebp_kernel(other.getSubMapper(startTarget,j2), blockA, blockB+actual_kc*j2, lengthTarget, actualPanelWidth, actual_cols, Scalar(-1), - actualPanelWidth, actual_kc, 0, blockBOffset); - } - } - } - - // R2 -= A21 * B => GEPP - { - Index start = IsLower ? k2+kc : 0; - Index end = IsLower ? size : k2-kc; - for(Index i2=start; i2<end; i2+=mc) - { - const Index actual_mc = (std::min)(mc,end-i2); - if (actual_mc>0) - { - pack_lhs(blockA, tri.getSubMapper(i2, IsLower ? k2 : k2-kc), actual_kc, actual_mc); - - gebp_kernel(other.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, cols, Scalar(-1), -1, -1, 0, 0); - } - } - } - } - } - -/* Optimized triangular solver with multiple left hand sides and the triangular matrix on the right - */ -template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder, int OtherInnerStride> -struct triangular_solve_matrix<Scalar,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor,OtherInnerStride> -{ - static EIGEN_DONT_INLINE void run( - Index size, Index otherSize, - const Scalar* _tri, Index triStride, - Scalar* _other, Index otherIncr, Index otherStride, - level3_blocking<Scalar,Scalar>& blocking); -}; -template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder, int OtherInnerStride> -EIGEN_DONT_INLINE void triangular_solve_matrix<Scalar,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor,OtherInnerStride>::run( - Index size, Index otherSize, - const Scalar* _tri, Index triStride, - Scalar* _other, Index otherIncr, Index otherStride, - level3_blocking<Scalar,Scalar>& blocking) - { - Index rows = otherSize; - typedef typename NumTraits<Scalar>::Real RealScalar; - - typedef blas_data_mapper<Scalar, Index, ColMajor, Unaligned, OtherInnerStride> LhsMapper; - typedef const_blas_data_mapper<Scalar, Index, TriStorageOrder> RhsMapper; - LhsMapper lhs(_other, otherStride, otherIncr); - RhsMapper rhs(_tri, triStride); - - typedef gebp_traits<Scalar,Scalar> Traits; - enum { - RhsStorageOrder = TriStorageOrder, - SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr), - IsLower = (Mode&Lower) == Lower - }; - - Index kc = blocking.kc(); // cache block size along the K direction - Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction - - std::size_t sizeA = kc*mc; - std::size_t sizeB = kc*size; - - ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA()); - ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB()); - - conj_if<Conjugate> conj; - gebp_kernel<Scalar, Scalar, Index, LhsMapper, Traits::mr, Traits::nr, false, Conjugate> gebp_kernel; - gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs; - gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr, RhsStorageOrder,false,true> pack_rhs_panel; - gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, ColMajor, false, true> pack_lhs_panel; - - for(Index k2=IsLower ? size : 0; - IsLower ? k2>0 : k2<size; - IsLower ? k2-=kc : k2+=kc) - { - const Index actual_kc = (std::min)(IsLower ? k2 : size-k2, kc); - Index actual_k2 = IsLower ? k2-actual_kc : k2 ; - - Index startPanel = IsLower ? 0 : k2+actual_kc; - Index rs = IsLower ? actual_k2 : size - actual_k2 - actual_kc; - Scalar* geb = blockB+actual_kc*actual_kc; - - if (rs>0) pack_rhs(geb, rhs.getSubMapper(actual_k2,startPanel), actual_kc, rs); - - // triangular packing (we only pack the panels off the diagonal, - // neglecting the blocks overlapping the diagonal - { - for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth) - { - Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth); - Index actual_j2 = actual_k2 + j2; - Index panelOffset = IsLower ? j2+actualPanelWidth : 0; - Index panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2; - - if (panelLength>0) - pack_rhs_panel(blockB+j2*actual_kc, - rhs.getSubMapper(actual_k2+panelOffset, actual_j2), - panelLength, actualPanelWidth, - actual_kc, panelOffset); - } - } - - for(Index i2=0; i2<rows; i2+=mc) - { - const Index actual_mc = (std::min)(mc,rows-i2); - - // triangular solver kernel - { - // for each small block of the diagonal (=> vertical panels of rhs) - for (Index j2 = IsLower - ? (actual_kc - ((actual_kc%SmallPanelWidth) ? Index(actual_kc%SmallPanelWidth) - : Index(SmallPanelWidth))) - : 0; - IsLower ? j2>=0 : j2<actual_kc; - IsLower ? j2-=SmallPanelWidth : j2+=SmallPanelWidth) - { - Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth); - Index absolute_j2 = actual_k2 + j2; - Index panelOffset = IsLower ? j2+actualPanelWidth : 0; - Index panelLength = IsLower ? actual_kc - j2 - actualPanelWidth : j2; - - // GEBP - if(panelLength>0) - { - gebp_kernel(lhs.getSubMapper(i2,absolute_j2), - blockA, blockB+j2*actual_kc, - actual_mc, panelLength, actualPanelWidth, - Scalar(-1), - actual_kc, actual_kc, // strides - panelOffset, panelOffset); // offsets - } - - // unblocked triangular solve - for (Index k=0; k<actualPanelWidth; ++k) - { - Index j = IsLower ? absolute_j2+actualPanelWidth-k-1 : absolute_j2+k; - - typename LhsMapper::LinearMapper r = lhs.getLinearMapper(i2,j); - for (Index k3=0; k3<k; ++k3) - { - Scalar b = conj(rhs(IsLower ? j+1+k3 : absolute_j2+k3,j)); - typename LhsMapper::LinearMapper a = lhs.getLinearMapper(i2,IsLower ? j+1+k3 : absolute_j2+k3); - for (Index i=0; i<actual_mc; ++i) - r(i) -= a(i) * b; - } - if((Mode & UnitDiag)==0) - { - Scalar inv_rjj = RealScalar(1)/conj(rhs(j,j)); - for (Index i=0; i<actual_mc; ++i) - r(i) *= inv_rjj; - } - } - - // pack the just computed part of lhs to A - pack_lhs_panel(blockA, lhs.getSubMapper(i2,absolute_j2), - actualPanelWidth, actual_mc, - actual_kc, j2); - } - } - - if (rs>0) - gebp_kernel(lhs.getSubMapper(i2, startPanel), blockA, geb, - actual_mc, actual_kc, rs, Scalar(-1), - -1, -1, 0, 0); - } - } - } - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h b/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h deleted file mode 100644 index 621194ce..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to BLAS F77 - * Triangular matrix * matrix product functionality based on ?TRMM. - ******************************************************************************** -*/ - -#ifndef EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H -#define EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H - -namespace Eigen { - -namespace internal { - -// implements LeftSide op(triangular)^-1 * general -#define EIGEN_BLAS_TRSM_L(EIGTYPE, BLASTYPE, BLASFUNC) \ -template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \ -struct triangular_solve_matrix<EIGTYPE,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor,1> \ -{ \ - enum { \ - IsLower = (Mode&Lower) == Lower, \ - IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \ - IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \ - conjA = ((TriStorageOrder==ColMajor) && Conjugate) ? 1 : 0 \ - }; \ - static void run( \ - Index size, Index otherSize, \ - const EIGTYPE* _tri, Index triStride, \ - EIGTYPE* _other, Index otherIncr, Index otherStride, level3_blocking<EIGTYPE,EIGTYPE>& /*blocking*/) \ - { \ - EIGEN_ONLY_USED_FOR_DEBUG(otherIncr); \ - eigen_assert(otherIncr == 1); \ - BlasIndex m = convert_index<BlasIndex>(size), n = convert_index<BlasIndex>(otherSize), lda, ldb; \ - char side = 'L', uplo, diag='N', transa; \ - /* Set alpha_ */ \ - EIGTYPE alpha(1); \ - ldb = convert_index<BlasIndex>(otherStride);\ -\ - const EIGTYPE *a; \ -/* Set trans */ \ - transa = (TriStorageOrder==RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \ -/* Set uplo */ \ - uplo = IsLower ? 'L' : 'U'; \ - if (TriStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \ -/* Set a, lda */ \ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \ - Map<const MatrixTri, 0, OuterStride<> > tri(_tri,size,size,OuterStride<>(triStride)); \ - MatrixTri a_tmp; \ -\ - if (conjA) { \ - a_tmp = tri.conjugate(); \ - a = a_tmp.data(); \ - lda = convert_index<BlasIndex>(a_tmp.outerStride()); \ - } else { \ - a = _tri; \ - lda = convert_index<BlasIndex>(triStride); \ - } \ - if (IsUnitDiag) diag='U'; \ -/* call ?trsm*/ \ - BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (BLASTYPE*)_other, &ldb); \ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_TRSM_L(double, double, dtrsm) -EIGEN_BLAS_TRSM_L(dcomplex, MKL_Complex16, ztrsm) -EIGEN_BLAS_TRSM_L(float, float, strsm) -EIGEN_BLAS_TRSM_L(scomplex, MKL_Complex8, ctrsm) -#else -EIGEN_BLAS_TRSM_L(double, double, dtrsm_) -EIGEN_BLAS_TRSM_L(dcomplex, double, ztrsm_) -EIGEN_BLAS_TRSM_L(float, float, strsm_) -EIGEN_BLAS_TRSM_L(scomplex, float, ctrsm_) -#endif - -// implements RightSide general * op(triangular)^-1 -#define EIGEN_BLAS_TRSM_R(EIGTYPE, BLASTYPE, BLASFUNC) \ -template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \ -struct triangular_solve_matrix<EIGTYPE,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor,1> \ -{ \ - enum { \ - IsLower = (Mode&Lower) == Lower, \ - IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \ - IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \ - conjA = ((TriStorageOrder==ColMajor) && Conjugate) ? 1 : 0 \ - }; \ - static void run( \ - Index size, Index otherSize, \ - const EIGTYPE* _tri, Index triStride, \ - EIGTYPE* _other, Index otherIncr, Index otherStride, level3_blocking<EIGTYPE,EIGTYPE>& /*blocking*/) \ - { \ - EIGEN_ONLY_USED_FOR_DEBUG(otherIncr); \ - eigen_assert(otherIncr == 1); \ - BlasIndex m = convert_index<BlasIndex>(otherSize), n = convert_index<BlasIndex>(size), lda, ldb; \ - char side = 'R', uplo, diag='N', transa; \ - /* Set alpha_ */ \ - EIGTYPE alpha(1); \ - ldb = convert_index<BlasIndex>(otherStride);\ -\ - const EIGTYPE *a; \ -/* Set trans */ \ - transa = (TriStorageOrder==RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \ -/* Set uplo */ \ - uplo = IsLower ? 'L' : 'U'; \ - if (TriStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \ -/* Set a, lda */ \ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \ - Map<const MatrixTri, 0, OuterStride<> > tri(_tri,size,size,OuterStride<>(triStride)); \ - MatrixTri a_tmp; \ -\ - if (conjA) { \ - a_tmp = tri.conjugate(); \ - a = a_tmp.data(); \ - lda = convert_index<BlasIndex>(a_tmp.outerStride()); \ - } else { \ - a = _tri; \ - lda = convert_index<BlasIndex>(triStride); \ - } \ - if (IsUnitDiag) diag='U'; \ -/* call ?trsm*/ \ - BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (BLASTYPE*)_other, &ldb); \ - /*std::cout << "TRMS_L specialization!\n";*/ \ - } \ -}; - -#ifdef EIGEN_USE_MKL -EIGEN_BLAS_TRSM_R(double, double, dtrsm) -EIGEN_BLAS_TRSM_R(dcomplex, MKL_Complex16, ztrsm) -EIGEN_BLAS_TRSM_R(float, float, strsm) -EIGEN_BLAS_TRSM_R(scomplex, MKL_Complex8, ctrsm) -#else -EIGEN_BLAS_TRSM_R(double, double, dtrsm_) -EIGEN_BLAS_TRSM_R(dcomplex, double, ztrsm_) -EIGEN_BLAS_TRSM_R(float, float, strsm_) -EIGEN_BLAS_TRSM_R(scomplex, float, ctrsm_) -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverVector.h b/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverVector.h deleted file mode 100644 index 64731701..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/products/TriangularSolverVector.h +++ /dev/null @@ -1,148 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRIANGULAR_SOLVER_VECTOR_H -#define EIGEN_TRIANGULAR_SOLVER_VECTOR_H - -namespace Eigen { - -namespace internal { - -template<typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate, int StorageOrder> -struct triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheRight, Mode, Conjugate, StorageOrder> -{ - static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) - { - triangular_solve_vector<LhsScalar,RhsScalar,Index,OnTheLeft, - ((Mode&Upper)==Upper ? Lower : Upper) | (Mode&UnitDiag), - Conjugate,StorageOrder==RowMajor?ColMajor:RowMajor - >::run(size, _lhs, lhsStride, rhs); - } -}; - -// forward and backward substitution, row-major, rhs is a vector -template<typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate> -struct triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheLeft, Mode, Conjugate, RowMajor> -{ - enum { - IsLower = ((Mode&Lower)==Lower) - }; - static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) - { - typedef Map<const Matrix<LhsScalar,Dynamic,Dynamic,RowMajor>, 0, OuterStride<> > LhsMap; - const LhsMap lhs(_lhs,size,size,OuterStride<>(lhsStride)); - - typedef const_blas_data_mapper<LhsScalar,Index,RowMajor> LhsMapper; - typedef const_blas_data_mapper<RhsScalar,Index,ColMajor> RhsMapper; - - typename internal::conditional< - Conjugate, - const CwiseUnaryOp<typename internal::scalar_conjugate_op<LhsScalar>,LhsMap>, - const LhsMap&> - ::type cjLhs(lhs); - static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; - for(Index pi=IsLower ? 0 : size; - IsLower ? pi<size : pi>0; - IsLower ? pi+=PanelWidth : pi-=PanelWidth) - { - Index actualPanelWidth = (std::min)(IsLower ? size - pi : pi, PanelWidth); - - Index r = IsLower ? pi : size - pi; // remaining size - if (r > 0) - { - // let's directly call the low level product function because: - // 1 - it is faster to compile - // 2 - it is slightly faster at runtime - Index startRow = IsLower ? pi : pi-actualPanelWidth; - Index startCol = IsLower ? 0 : pi; - - general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,Conjugate,RhsScalar,RhsMapper,false>::run( - actualPanelWidth, r, - LhsMapper(&lhs.coeffRef(startRow,startCol), lhsStride), - RhsMapper(rhs + startCol, 1), - rhs + startRow, 1, - RhsScalar(-1)); - } - - for(Index k=0; k<actualPanelWidth; ++k) - { - Index i = IsLower ? pi+k : pi-k-1; - Index s = IsLower ? pi : i+1; - if (k>0) - rhs[i] -= (cjLhs.row(i).segment(s,k).transpose().cwiseProduct(Map<const Matrix<RhsScalar,Dynamic,1> >(rhs+s,k))).sum(); - - if((!(Mode & UnitDiag)) && numext::not_equal_strict(rhs[i],RhsScalar(0))) - rhs[i] /= cjLhs(i,i); - } - } - } -}; - -// forward and backward substitution, column-major, rhs is a vector -template<typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate> -struct triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheLeft, Mode, Conjugate, ColMajor> -{ - enum { - IsLower = ((Mode&Lower)==Lower) - }; - static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) - { - typedef Map<const Matrix<LhsScalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > LhsMap; - const LhsMap lhs(_lhs,size,size,OuterStride<>(lhsStride)); - typedef const_blas_data_mapper<LhsScalar,Index,ColMajor> LhsMapper; - typedef const_blas_data_mapper<RhsScalar,Index,ColMajor> RhsMapper; - typename internal::conditional<Conjugate, - const CwiseUnaryOp<typename internal::scalar_conjugate_op<LhsScalar>,LhsMap>, - const LhsMap& - >::type cjLhs(lhs); - static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; - - for(Index pi=IsLower ? 0 : size; - IsLower ? pi<size : pi>0; - IsLower ? pi+=PanelWidth : pi-=PanelWidth) - { - Index actualPanelWidth = (std::min)(IsLower ? size - pi : pi, PanelWidth); - Index startBlock = IsLower ? pi : pi-actualPanelWidth; - Index endBlock = IsLower ? pi + actualPanelWidth : 0; - - for(Index k=0; k<actualPanelWidth; ++k) - { - Index i = IsLower ? pi+k : pi-k-1; - if(numext::not_equal_strict(rhs[i],RhsScalar(0))) - { - if(!(Mode & UnitDiag)) - rhs[i] /= cjLhs.coeff(i,i); - - Index r = actualPanelWidth - k - 1; // remaining size - Index s = IsLower ? i+1 : i-r; - if (r>0) - Map<Matrix<RhsScalar,Dynamic,1> >(rhs+s,r) -= rhs[i] * cjLhs.col(i).segment(s,r); - } - } - Index r = IsLower ? size - endBlock : startBlock; // remaining size - if (r > 0) - { - // let's directly call the low level product function because: - // 1 - it is faster to compile - // 2 - it is slightly faster at runtime - general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,Conjugate,RhsScalar,RhsMapper,false>::run( - r, actualPanelWidth, - LhsMapper(&lhs.coeffRef(endBlock,startBlock), lhsStride), - RhsMapper(rhs+startBlock, 1), - rhs+endBlock, 1, RhsScalar(-1)); - } - } - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRIANGULAR_SOLVER_VECTOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/BlasUtil.h b/external/eigen/include/eigen3/Eigen/src/Core/util/BlasUtil.h deleted file mode 100644 index 643558cb..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/BlasUtil.h +++ /dev/null @@ -1,500 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BLASUTIL_H -#define EIGEN_BLASUTIL_H - -// This file contains many lightweight helper classes used to -// implement and control fast level 2 and level 3 BLAS-like routines. - -namespace Eigen { - -namespace internal { - -// forward declarations -template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs=false, bool ConjugateRhs=false> -struct gebp_kernel; - -template<typename Scalar, typename Index, typename DataMapper, int nr, int StorageOrder, bool Conjugate = false, bool PanelMode=false> -struct gemm_pack_rhs; - -template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, int StorageOrder, bool Conjugate = false, bool PanelMode = false> -struct gemm_pack_lhs; - -template< - typename Index, - typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs, - typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs, - int ResStorageOrder, int ResInnerStride> -struct general_matrix_matrix_product; - -template<typename Index, - typename LhsScalar, typename LhsMapper, int LhsStorageOrder, bool ConjugateLhs, - typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version=Specialized> -struct general_matrix_vector_product; - - -template<bool Conjugate> struct conj_if; - -template<> struct conj_if<true> { - template<typename T> - inline T operator()(const T& x) const { return numext::conj(x); } - template<typename T> - inline T pconj(const T& x) const { return internal::pconj(x); } -}; - -template<> struct conj_if<false> { - template<typename T> - inline const T& operator()(const T& x) const { return x; } - template<typename T> - inline const T& pconj(const T& x) const { return x; } -}; - -// Generic implementation for custom complex types. -template<typename LhsScalar, typename RhsScalar, bool ConjLhs, bool ConjRhs> -struct conj_helper -{ - typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar>::ReturnType Scalar; - - EIGEN_STRONG_INLINE Scalar pmadd(const LhsScalar& x, const RhsScalar& y, const Scalar& c) const - { return padd(c, pmul(x,y)); } - - EIGEN_STRONG_INLINE Scalar pmul(const LhsScalar& x, const RhsScalar& y) const - { return conj_if<ConjLhs>()(x) * conj_if<ConjRhs>()(y); } -}; - -template<typename Scalar> struct conj_helper<Scalar,Scalar,false,false> -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar pmadd(const Scalar& x, const Scalar& y, const Scalar& c) const { return internal::pmadd(x,y,c); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar pmul(const Scalar& x, const Scalar& y) const { return internal::pmul(x,y); } -}; - -template<typename RealScalar> struct conj_helper<std::complex<RealScalar>, std::complex<RealScalar>, false,true> -{ - typedef std::complex<RealScalar> Scalar; - EIGEN_STRONG_INLINE Scalar pmadd(const Scalar& x, const Scalar& y, const Scalar& c) const - { return c + pmul(x,y); } - - EIGEN_STRONG_INLINE Scalar pmul(const Scalar& x, const Scalar& y) const - { return Scalar(numext::real(x)*numext::real(y) + numext::imag(x)*numext::imag(y), numext::imag(x)*numext::real(y) - numext::real(x)*numext::imag(y)); } -}; - -template<typename RealScalar> struct conj_helper<std::complex<RealScalar>, std::complex<RealScalar>, true,false> -{ - typedef std::complex<RealScalar> Scalar; - EIGEN_STRONG_INLINE Scalar pmadd(const Scalar& x, const Scalar& y, const Scalar& c) const - { return c + pmul(x,y); } - - EIGEN_STRONG_INLINE Scalar pmul(const Scalar& x, const Scalar& y) const - { return Scalar(numext::real(x)*numext::real(y) + numext::imag(x)*numext::imag(y), numext::real(x)*numext::imag(y) - numext::imag(x)*numext::real(y)); } -}; - -template<typename RealScalar> struct conj_helper<std::complex<RealScalar>, std::complex<RealScalar>, true,true> -{ - typedef std::complex<RealScalar> Scalar; - EIGEN_STRONG_INLINE Scalar pmadd(const Scalar& x, const Scalar& y, const Scalar& c) const - { return c + pmul(x,y); } - - EIGEN_STRONG_INLINE Scalar pmul(const Scalar& x, const Scalar& y) const - { return Scalar(numext::real(x)*numext::real(y) - numext::imag(x)*numext::imag(y), - numext::real(x)*numext::imag(y) - numext::imag(x)*numext::real(y)); } -}; - -template<typename RealScalar,bool Conj> struct conj_helper<std::complex<RealScalar>, RealScalar, Conj,false> -{ - typedef std::complex<RealScalar> Scalar; - EIGEN_STRONG_INLINE Scalar pmadd(const Scalar& x, const RealScalar& y, const Scalar& c) const - { return padd(c, pmul(x,y)); } - EIGEN_STRONG_INLINE Scalar pmul(const Scalar& x, const RealScalar& y) const - { return conj_if<Conj>()(x)*y; } -}; - -template<typename RealScalar,bool Conj> struct conj_helper<RealScalar, std::complex<RealScalar>, false,Conj> -{ - typedef std::complex<RealScalar> Scalar; - EIGEN_STRONG_INLINE Scalar pmadd(const RealScalar& x, const Scalar& y, const Scalar& c) const - { return padd(c, pmul(x,y)); } - EIGEN_STRONG_INLINE Scalar pmul(const RealScalar& x, const Scalar& y) const - { return x*conj_if<Conj>()(y); } -}; - -template<typename From,typename To> struct get_factor { - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE To run(const From& x) { return To(x); } -}; - -template<typename Scalar> struct get_factor<Scalar,typename NumTraits<Scalar>::Real> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE typename NumTraits<Scalar>::Real run(const Scalar& x) { return numext::real(x); } -}; - - -template<typename Scalar, typename Index> -class BlasVectorMapper { - public: - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BlasVectorMapper(Scalar *data) : m_data(data) {} - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar operator()(Index i) const { - return m_data[i]; - } - template <typename Packet, int AlignmentType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet load(Index i) const { - return ploadt<Packet, AlignmentType>(m_data + i); - } - - template <typename Packet> - EIGEN_DEVICE_FUNC bool aligned(Index i) const { - return (UIntPtr(m_data+i)%sizeof(Packet))==0; - } - - protected: - Scalar* m_data; -}; - -template<typename Scalar, typename Index, int AlignmentType, int Incr=1> -class BlasLinearMapper; - -template<typename Scalar, typename Index, int AlignmentType> -class BlasLinearMapper<Scalar,Index,AlignmentType> -{ -public: - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BlasLinearMapper(Scalar *data, Index incr=1) - : m_data(data) - { - EIGEN_ONLY_USED_FOR_DEBUG(incr); - eigen_assert(incr==1); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void prefetch(int i) const { - internal::prefetch(&operator()(i)); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar& operator()(Index i) const { - return m_data[i]; - } - - template<typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(Index i) const { - return ploadt<PacketType, AlignmentType>(m_data + i); - } - - template<typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void storePacket(Index i, const PacketType &p) const { - pstoret<Scalar, PacketType, AlignmentType>(m_data + i, p); - } - -protected: - Scalar *m_data; -}; - -// Lightweight helper class to access matrix coefficients. -template<typename Scalar, typename Index, int StorageOrder, int AlignmentType = Unaligned, int Incr = 1> -class blas_data_mapper; - -template<typename Scalar, typename Index, int StorageOrder, int AlignmentType> -class blas_data_mapper<Scalar,Index,StorageOrder,AlignmentType,1> -{ -public: - typedef BlasLinearMapper<Scalar, Index, AlignmentType> LinearMapper; - typedef BlasVectorMapper<Scalar, Index> VectorMapper; - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE blas_data_mapper(Scalar* data, Index stride, Index incr=1) - : m_data(data), m_stride(stride) - { - EIGEN_ONLY_USED_FOR_DEBUG(incr); - eigen_assert(incr==1); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType> - getSubMapper(Index i, Index j) const { - return blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType>(&operator()(i, j), m_stride); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LinearMapper getLinearMapper(Index i, Index j) const { - return LinearMapper(&operator()(i, j)); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE VectorMapper getVectorMapper(Index i, Index j) const { - return VectorMapper(&operator()(i, j)); - } - - - EIGEN_DEVICE_FUNC - EIGEN_ALWAYS_INLINE Scalar& operator()(Index i, Index j) const { - return m_data[StorageOrder==RowMajor ? j + i*m_stride : i + j*m_stride]; - } - - template<typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(Index i, Index j) const { - return ploadt<PacketType, AlignmentType>(&operator()(i, j)); - } - - template <typename PacketT, int AlignmentT> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT load(Index i, Index j) const { - return ploadt<PacketT, AlignmentT>(&operator()(i, j)); - } - - template<typename SubPacket> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void scatterPacket(Index i, Index j, const SubPacket &p) const { - pscatter<Scalar, SubPacket>(&operator()(i, j), p, m_stride); - } - - template<typename SubPacket> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE SubPacket gatherPacket(Index i, Index j) const { - return pgather<Scalar, SubPacket>(&operator()(i, j), m_stride); - } - - EIGEN_DEVICE_FUNC const Index stride() const { return m_stride; } - EIGEN_DEVICE_FUNC const Scalar* data() const { return m_data; } - - EIGEN_DEVICE_FUNC Index firstAligned(Index size) const { - if (UIntPtr(m_data)%sizeof(Scalar)) { - return -1; - } - return internal::first_default_aligned(m_data, size); - } - -protected: - Scalar* EIGEN_RESTRICT m_data; - const Index m_stride; -}; - -// Implementation of non-natural increment (i.e. inner-stride != 1) -// The exposed API is not complete yet compared to the Incr==1 case -// because some features makes less sense in this case. -template<typename Scalar, typename Index, int AlignmentType, int Incr> -class BlasLinearMapper -{ -public: - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BlasLinearMapper(Scalar *data,Index incr) : m_data(data), m_incr(incr) {} - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void prefetch(int i) const { - internal::prefetch(&operator()(i)); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar& operator()(Index i) const { - return m_data[i*m_incr.value()]; - } - - template<typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(Index i) const { - return pgather<Scalar,PacketType>(m_data + i*m_incr.value(), m_incr.value()); - } - - template<typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void storePacket(Index i, const PacketType &p) const { - pscatter<Scalar, PacketType>(m_data + i*m_incr.value(), p, m_incr.value()); - } - -protected: - Scalar *m_data; - const internal::variable_if_dynamic<Index,Incr> m_incr; -}; - -template<typename Scalar, typename Index, int StorageOrder, int AlignmentType,int Incr> -class blas_data_mapper -{ -public: - typedef BlasLinearMapper<Scalar, Index, AlignmentType,Incr> LinearMapper; - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE blas_data_mapper(Scalar* data, Index stride, Index incr) : m_data(data), m_stride(stride), m_incr(incr) {} - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE blas_data_mapper - getSubMapper(Index i, Index j) const { - return blas_data_mapper(&operator()(i, j), m_stride, m_incr.value()); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LinearMapper getLinearMapper(Index i, Index j) const { - return LinearMapper(&operator()(i, j), m_incr.value()); - } - - EIGEN_DEVICE_FUNC - EIGEN_ALWAYS_INLINE Scalar& operator()(Index i, Index j) const { - return m_data[StorageOrder==RowMajor ? j*m_incr.value() + i*m_stride : i*m_incr.value() + j*m_stride]; - } - - template<typename PacketType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(Index i, Index j) const { - return pgather<Scalar,PacketType>(&operator()(i, j),m_incr.value()); - } - - template <typename PacketT, int AlignmentT> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT load(Index i, Index j) const { - return pgather<Scalar,PacketT>(&operator()(i, j),m_incr.value()); - } - - template<typename SubPacket> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void scatterPacket(Index i, Index j, const SubPacket &p) const { - pscatter<Scalar, SubPacket>(&operator()(i, j), p, m_stride); - } - - template<typename SubPacket> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE SubPacket gatherPacket(Index i, Index j) const { - return pgather<Scalar, SubPacket>(&operator()(i, j), m_stride); - } - -protected: - Scalar* EIGEN_RESTRICT m_data; - const Index m_stride; - const internal::variable_if_dynamic<Index,Incr> m_incr; -}; - -// lightweight helper class to access matrix coefficients (const version) -template<typename Scalar, typename Index, int StorageOrder> -class const_blas_data_mapper : public blas_data_mapper<const Scalar, Index, StorageOrder> { - public: - EIGEN_ALWAYS_INLINE const_blas_data_mapper(const Scalar *data, Index stride) : blas_data_mapper<const Scalar, Index, StorageOrder>(data, stride) {} - - EIGEN_ALWAYS_INLINE const_blas_data_mapper<Scalar, Index, StorageOrder> getSubMapper(Index i, Index j) const { - return const_blas_data_mapper<Scalar, Index, StorageOrder>(&(this->operator()(i, j)), this->m_stride); - } -}; - - -/* Helper class to analyze the factors of a Product expression. - * In particular it allows to pop out operator-, scalar multiples, - * and conjugate */ -template<typename XprType> struct blas_traits -{ - typedef typename traits<XprType>::Scalar Scalar; - typedef const XprType& ExtractType; - typedef XprType _ExtractType; - enum { - IsComplex = NumTraits<Scalar>::IsComplex, - IsTransposed = false, - NeedToConjugate = false, - HasUsableDirectAccess = ( (int(XprType::Flags)&DirectAccessBit) - && ( bool(XprType::IsVectorAtCompileTime) - || int(inner_stride_at_compile_time<XprType>::ret) == 1) - ) ? 1 : 0, - HasScalarFactor = false - }; - typedef typename conditional<bool(HasUsableDirectAccess), - ExtractType, - typename _ExtractType::PlainObject - >::type DirectLinearAccessType; - static inline EIGEN_DEVICE_FUNC ExtractType extract(const XprType& x) { return x; } - static inline EIGEN_DEVICE_FUNC const Scalar extractScalarFactor(const XprType&) { return Scalar(1); } -}; - -// pop conjugate -template<typename Scalar, typename NestedXpr> -struct blas_traits<CwiseUnaryOp<scalar_conjugate_op<Scalar>, NestedXpr> > - : blas_traits<NestedXpr> -{ - typedef blas_traits<NestedXpr> Base; - typedef CwiseUnaryOp<scalar_conjugate_op<Scalar>, NestedXpr> XprType; - typedef typename Base::ExtractType ExtractType; - - enum { - IsComplex = NumTraits<Scalar>::IsComplex, - NeedToConjugate = Base::NeedToConjugate ? 0 : IsComplex - }; - static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } - static inline Scalar extractScalarFactor(const XprType& x) { return conj(Base::extractScalarFactor(x.nestedExpression())); } -}; - -// pop scalar multiple -template<typename Scalar, typename NestedXpr, typename Plain> -struct blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain>, NestedXpr> > - : blas_traits<NestedXpr> -{ - enum { - HasScalarFactor = true - }; - typedef blas_traits<NestedXpr> Base; - typedef CwiseBinaryOp<scalar_product_op<Scalar>, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain>, NestedXpr> XprType; - typedef typename Base::ExtractType ExtractType; - static inline EIGEN_DEVICE_FUNC ExtractType extract(const XprType& x) { return Base::extract(x.rhs()); } - static inline EIGEN_DEVICE_FUNC Scalar extractScalarFactor(const XprType& x) - { return x.lhs().functor().m_other * Base::extractScalarFactor(x.rhs()); } -}; -template<typename Scalar, typename NestedXpr, typename Plain> -struct blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, NestedXpr, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain> > > - : blas_traits<NestedXpr> -{ - enum { - HasScalarFactor = true - }; - typedef blas_traits<NestedXpr> Base; - typedef CwiseBinaryOp<scalar_product_op<Scalar>, NestedXpr, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain> > XprType; - typedef typename Base::ExtractType ExtractType; - static inline ExtractType extract(const XprType& x) { return Base::extract(x.lhs()); } - static inline Scalar extractScalarFactor(const XprType& x) - { return Base::extractScalarFactor(x.lhs()) * x.rhs().functor().m_other; } -}; -template<typename Scalar, typename Plain1, typename Plain2> -struct blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain1>, - const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain2> > > - : blas_traits<CwiseNullaryOp<scalar_constant_op<Scalar>,Plain1> > -{}; - -// pop opposite -template<typename Scalar, typename NestedXpr> -struct blas_traits<CwiseUnaryOp<scalar_opposite_op<Scalar>, NestedXpr> > - : blas_traits<NestedXpr> -{ - enum { - HasScalarFactor = true - }; - typedef blas_traits<NestedXpr> Base; - typedef CwiseUnaryOp<scalar_opposite_op<Scalar>, NestedXpr> XprType; - typedef typename Base::ExtractType ExtractType; - static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); } - static inline Scalar extractScalarFactor(const XprType& x) - { return - Base::extractScalarFactor(x.nestedExpression()); } -}; - -// pop/push transpose -template<typename NestedXpr> -struct blas_traits<Transpose<NestedXpr> > - : blas_traits<NestedXpr> -{ - typedef typename NestedXpr::Scalar Scalar; - typedef blas_traits<NestedXpr> Base; - typedef Transpose<NestedXpr> XprType; - typedef Transpose<const typename Base::_ExtractType> ExtractType; // const to get rid of a compile error; anyway blas traits are only used on the RHS - typedef Transpose<const typename Base::_ExtractType> _ExtractType; - typedef typename conditional<bool(Base::HasUsableDirectAccess), - ExtractType, - typename ExtractType::PlainObject - >::type DirectLinearAccessType; - enum { - IsTransposed = Base::IsTransposed ? 0 : 1 - }; - static inline ExtractType extract(const XprType& x) { return ExtractType(Base::extract(x.nestedExpression())); } - static inline Scalar extractScalarFactor(const XprType& x) { return Base::extractScalarFactor(x.nestedExpression()); } -}; - -template<typename T> -struct blas_traits<const T> - : blas_traits<T> -{}; - -template<typename T, bool HasUsableDirectAccess=blas_traits<T>::HasUsableDirectAccess> -struct extract_data_selector { - static const typename T::Scalar* run(const T& m) - { - return blas_traits<T>::extract(m).data(); - } -}; - -template<typename T> -struct extract_data_selector<T,false> { - static typename T::Scalar* run(const T&) { return 0; } -}; - -template<typename T> const typename T::Scalar* extract_data(const T& m) -{ - return extract_data_selector<T>::run(m); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_BLASUTIL_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h b/external/eigen/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h deleted file mode 100644 index 271795a0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h +++ /dev/null @@ -1,486 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2018 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CONFIGURE_VECTORIZATION_H -#define EIGEN_CONFIGURE_VECTORIZATION_H - -//------------------------------------------------------------------------------------------ -// Static and dynamic alignment control -// -// The main purpose of this section is to define EIGEN_MAX_ALIGN_BYTES and EIGEN_MAX_STATIC_ALIGN_BYTES -// as the maximal boundary in bytes on which dynamically and statically allocated data may be alignment respectively. -// The values of EIGEN_MAX_ALIGN_BYTES and EIGEN_MAX_STATIC_ALIGN_BYTES can be specified by the user. If not, -// a default value is automatically computed based on architecture, compiler, and OS. -// -// This section also defines macros EIGEN_ALIGN_TO_BOUNDARY(N) and the shortcuts EIGEN_ALIGN{8,16,32,_MAX} -// to be used to declare statically aligned buffers. -//------------------------------------------------------------------------------------------ - - -/* EIGEN_ALIGN_TO_BOUNDARY(n) forces data to be n-byte aligned. This is used to satisfy SIMD requirements. - * However, we do that EVEN if vectorization (EIGEN_VECTORIZE) is disabled, - * so that vectorization doesn't affect binary compatibility. - * - * If we made alignment depend on whether or not EIGEN_VECTORIZE is defined, it would be impossible to link - * vectorized and non-vectorized code. - * - * FIXME: this code can be cleaned up once we switch to proper C++11 only. - */ -#if (defined EIGEN_CUDACC) - #define EIGEN_ALIGN_TO_BOUNDARY(n) __align__(n) - #define EIGEN_ALIGNOF(x) __alignof(x) -#elif EIGEN_HAS_ALIGNAS - #define EIGEN_ALIGN_TO_BOUNDARY(n) alignas(n) - #define EIGEN_ALIGNOF(x) alignof(x) -#elif EIGEN_COMP_GNUC || EIGEN_COMP_PGI || EIGEN_COMP_IBM || EIGEN_COMP_ARM - #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n))) - #define EIGEN_ALIGNOF(x) __alignof(x) -#elif EIGEN_COMP_MSVC - #define EIGEN_ALIGN_TO_BOUNDARY(n) __declspec(align(n)) - #define EIGEN_ALIGNOF(x) __alignof(x) -#elif EIGEN_COMP_SUNCC - // FIXME not sure about this one: - #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n))) - #define EIGEN_ALIGNOF(x) __alignof(x) -#else - #error Please tell me what is the equivalent of alignas(n) and alignof(x) for your compiler -#endif - -// If the user explicitly disable vectorization, then we also disable alignment -#if defined(EIGEN_DONT_VECTORIZE) - #if defined(EIGEN_GPUCC) - // GPU code is always vectorized and requires memory alignment for - // statically allocated buffers. - #define EIGEN_IDEAL_MAX_ALIGN_BYTES 16 - #else - #define EIGEN_IDEAL_MAX_ALIGN_BYTES 0 - #endif -#elif defined(__AVX512F__) - // 64 bytes static alignment is preferred only if really required - #define EIGEN_IDEAL_MAX_ALIGN_BYTES 64 -#elif defined(__AVX__) - // 32 bytes static alignment is preferred only if really required - #define EIGEN_IDEAL_MAX_ALIGN_BYTES 32 -#else - #define EIGEN_IDEAL_MAX_ALIGN_BYTES 16 -#endif - - -// EIGEN_MIN_ALIGN_BYTES defines the minimal value for which the notion of explicit alignment makes sense -#define EIGEN_MIN_ALIGN_BYTES 16 - -// Defined the boundary (in bytes) on which the data needs to be aligned. Note -// that unless EIGEN_ALIGN is defined and not equal to 0, the data may not be -// aligned at all regardless of the value of this #define. - -#if (defined(EIGEN_DONT_ALIGN_STATICALLY) || defined(EIGEN_DONT_ALIGN)) && defined(EIGEN_MAX_STATIC_ALIGN_BYTES) && EIGEN_MAX_STATIC_ALIGN_BYTES>0 -#error EIGEN_MAX_STATIC_ALIGN_BYTES and EIGEN_DONT_ALIGN[_STATICALLY] are both defined with EIGEN_MAX_STATIC_ALIGN_BYTES!=0. Use EIGEN_MAX_STATIC_ALIGN_BYTES=0 as a synonym of EIGEN_DONT_ALIGN_STATICALLY. -#endif - -// EIGEN_DONT_ALIGN_STATICALLY and EIGEN_DONT_ALIGN are deprecated -// They imply EIGEN_MAX_STATIC_ALIGN_BYTES=0 -#if defined(EIGEN_DONT_ALIGN_STATICALLY) || defined(EIGEN_DONT_ALIGN) - #ifdef EIGEN_MAX_STATIC_ALIGN_BYTES - #undef EIGEN_MAX_STATIC_ALIGN_BYTES - #endif - #define EIGEN_MAX_STATIC_ALIGN_BYTES 0 -#endif - -#ifndef EIGEN_MAX_STATIC_ALIGN_BYTES - - // Try to automatically guess what is the best default value for EIGEN_MAX_STATIC_ALIGN_BYTES - - // 16 byte alignment is only useful for vectorization. Since it affects the ABI, we need to enable - // 16 byte alignment on all platforms where vectorization might be enabled. In theory we could always - // enable alignment, but it can be a cause of problems on some platforms, so we just disable it in - // certain common platform (compiler+architecture combinations) to avoid these problems. - // Only static alignment is really problematic (relies on nonstandard compiler extensions), - // try to keep heap alignment even when we have to disable static alignment. - #if EIGEN_COMP_GNUC && !(EIGEN_ARCH_i386_OR_x86_64 || EIGEN_ARCH_ARM_OR_ARM64 || EIGEN_ARCH_PPC || EIGEN_ARCH_IA64 || EIGEN_ARCH_MIPS) - #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1 - #elif EIGEN_ARCH_ARM_OR_ARM64 && EIGEN_COMP_GNUC_STRICT && EIGEN_GNUC_AT_MOST(4, 6) - // Old versions of GCC on ARM, at least 4.4, were once seen to have buggy static alignment support. - // Not sure which version fixed it, hopefully it doesn't affect 4.7, which is still somewhat in use. - // 4.8 and newer seem definitely unaffected. - #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1 - #else - #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 0 - #endif - - // static alignment is completely disabled with GCC 3, Sun Studio, and QCC/QNX - #if !EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT \ - && !EIGEN_GCC3_OR_OLDER \ - && !EIGEN_COMP_SUNCC \ - && !EIGEN_OS_QNX - #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 1 - #else - #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 0 - #endif - - #if EIGEN_ARCH_WANTS_STACK_ALIGNMENT - #define EIGEN_MAX_STATIC_ALIGN_BYTES EIGEN_IDEAL_MAX_ALIGN_BYTES - #else - #define EIGEN_MAX_STATIC_ALIGN_BYTES 0 - #endif - -#endif - -// If EIGEN_MAX_ALIGN_BYTES is defined, then it is considered as an upper bound for EIGEN_MAX_STATIC_ALIGN_BYTES -#if defined(EIGEN_MAX_ALIGN_BYTES) && EIGEN_MAX_ALIGN_BYTES<EIGEN_MAX_STATIC_ALIGN_BYTES -#undef EIGEN_MAX_STATIC_ALIGN_BYTES -#define EIGEN_MAX_STATIC_ALIGN_BYTES EIGEN_MAX_ALIGN_BYTES -#endif - -#if EIGEN_MAX_STATIC_ALIGN_BYTES==0 && !defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT) - #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT -#endif - -// At this stage, EIGEN_MAX_STATIC_ALIGN_BYTES>0 is the true test whether we want to align arrays on the stack or not. -// It takes into account both the user choice to explicitly enable/disable alignment (by setting EIGEN_MAX_STATIC_ALIGN_BYTES) -// and the architecture config (EIGEN_ARCH_WANTS_STACK_ALIGNMENT). -// Henceforth, only EIGEN_MAX_STATIC_ALIGN_BYTES should be used. - - -// Shortcuts to EIGEN_ALIGN_TO_BOUNDARY -#define EIGEN_ALIGN8 EIGEN_ALIGN_TO_BOUNDARY(8) -#define EIGEN_ALIGN16 EIGEN_ALIGN_TO_BOUNDARY(16) -#define EIGEN_ALIGN32 EIGEN_ALIGN_TO_BOUNDARY(32) -#define EIGEN_ALIGN64 EIGEN_ALIGN_TO_BOUNDARY(64) -#if EIGEN_MAX_STATIC_ALIGN_BYTES>0 -#define EIGEN_ALIGN_MAX EIGEN_ALIGN_TO_BOUNDARY(EIGEN_MAX_STATIC_ALIGN_BYTES) -#else -#define EIGEN_ALIGN_MAX -#endif - - -// Dynamic alignment control - -#if defined(EIGEN_DONT_ALIGN) && defined(EIGEN_MAX_ALIGN_BYTES) && EIGEN_MAX_ALIGN_BYTES>0 -#error EIGEN_MAX_ALIGN_BYTES and EIGEN_DONT_ALIGN are both defined with EIGEN_MAX_ALIGN_BYTES!=0. Use EIGEN_MAX_ALIGN_BYTES=0 as a synonym of EIGEN_DONT_ALIGN. -#endif - -#ifdef EIGEN_DONT_ALIGN - #ifdef EIGEN_MAX_ALIGN_BYTES - #undef EIGEN_MAX_ALIGN_BYTES - #endif - #define EIGEN_MAX_ALIGN_BYTES 0 -#elif !defined(EIGEN_MAX_ALIGN_BYTES) - #define EIGEN_MAX_ALIGN_BYTES EIGEN_IDEAL_MAX_ALIGN_BYTES -#endif - -#if EIGEN_IDEAL_MAX_ALIGN_BYTES > EIGEN_MAX_ALIGN_BYTES -#define EIGEN_DEFAULT_ALIGN_BYTES EIGEN_IDEAL_MAX_ALIGN_BYTES -#else -#define EIGEN_DEFAULT_ALIGN_BYTES EIGEN_MAX_ALIGN_BYTES -#endif - - -#ifndef EIGEN_UNALIGNED_VECTORIZE -#define EIGEN_UNALIGNED_VECTORIZE 1 -#endif - -//---------------------------------------------------------------------- - -// if alignment is disabled, then disable vectorization. Note: EIGEN_MAX_ALIGN_BYTES is the proper check, it takes into -// account both the user's will (EIGEN_MAX_ALIGN_BYTES,EIGEN_DONT_ALIGN) and our own platform checks -#if EIGEN_MAX_ALIGN_BYTES==0 - #ifndef EIGEN_DONT_VECTORIZE - #define EIGEN_DONT_VECTORIZE - #endif -#endif - - -// The following (except #include <malloc.h> and _M_IX86_FP ??) can likely be -// removed as gcc 4.1 and msvc 2008 are not supported anyways. -#if EIGEN_COMP_MSVC - #include <malloc.h> // for _aligned_malloc -- need it regardless of whether vectorization is enabled - #if (EIGEN_COMP_MSVC >= 1500) // 2008 or later - // a user reported that in 64-bit mode, MSVC doesn't care to define _M_IX86_FP. - #if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || EIGEN_ARCH_x86_64 - #define EIGEN_SSE2_ON_MSVC_2008_OR_LATER - #endif - #endif -#else - #if (defined __SSE2__) && ( (!EIGEN_COMP_GNUC) || EIGEN_COMP_ICC || EIGEN_GNUC_AT_LEAST(4,2) ) - #define EIGEN_SSE2_ON_NON_MSVC_BUT_NOT_OLD_GCC - #endif -#endif - -#if !(defined(EIGEN_DONT_VECTORIZE) || defined(EIGEN_GPUCC)) - - #if defined (EIGEN_SSE2_ON_NON_MSVC_BUT_NOT_OLD_GCC) || defined(EIGEN_SSE2_ON_MSVC_2008_OR_LATER) - - // Defines symbols for compile-time detection of which instructions are - // used. - // EIGEN_VECTORIZE_YY is defined if and only if the instruction set YY is used - #define EIGEN_VECTORIZE - #define EIGEN_VECTORIZE_SSE - #define EIGEN_VECTORIZE_SSE2 - - // Detect sse3/ssse3/sse4: - // gcc and icc defines __SSE3__, ... - // there is no way to know about this on msvc. You can define EIGEN_VECTORIZE_SSE* if you - // want to force the use of those instructions with msvc. - #ifdef __SSE3__ - #define EIGEN_VECTORIZE_SSE3 - #endif - #ifdef __SSSE3__ - #define EIGEN_VECTORIZE_SSSE3 - #endif - #ifdef __SSE4_1__ - #define EIGEN_VECTORIZE_SSE4_1 - #endif - #ifdef __SSE4_2__ - #define EIGEN_VECTORIZE_SSE4_2 - #endif - #ifdef __AVX__ - #ifndef EIGEN_USE_SYCL - #define EIGEN_VECTORIZE_AVX - #endif - #define EIGEN_VECTORIZE_SSE3 - #define EIGEN_VECTORIZE_SSSE3 - #define EIGEN_VECTORIZE_SSE4_1 - #define EIGEN_VECTORIZE_SSE4_2 - #endif - #ifdef __AVX2__ - #ifndef EIGEN_USE_SYCL - #define EIGEN_VECTORIZE_AVX2 - #define EIGEN_VECTORIZE_AVX - #endif - #define EIGEN_VECTORIZE_SSE3 - #define EIGEN_VECTORIZE_SSSE3 - #define EIGEN_VECTORIZE_SSE4_1 - #define EIGEN_VECTORIZE_SSE4_2 - #endif - #if defined(__FMA__) || (EIGEN_COMP_MSVC && defined(__AVX2__)) - // MSVC does not expose a switch dedicated for FMA - // For MSVC, AVX2 => FMA - #define EIGEN_VECTORIZE_FMA - #endif - #if defined(__AVX512F__) - #ifndef EIGEN_VECTORIZE_FMA - #if EIGEN_COMP_GNUC - #error Please add -mfma to your compiler flags: compiling with -mavx512f alone without SSE/AVX FMA is not supported (bug 1638). - #else - #error Please enable FMA in your compiler flags (e.g. -mfma): compiling with AVX512 alone without SSE/AVX FMA is not supported (bug 1638). - #endif - #endif - #ifndef EIGEN_USE_SYCL - #define EIGEN_VECTORIZE_AVX512 - #define EIGEN_VECTORIZE_AVX2 - #define EIGEN_VECTORIZE_AVX - #endif - #define EIGEN_VECTORIZE_FMA - #define EIGEN_VECTORIZE_SSE3 - #define EIGEN_VECTORIZE_SSSE3 - #define EIGEN_VECTORIZE_SSE4_1 - #define EIGEN_VECTORIZE_SSE4_2 - #ifndef EIGEN_USE_SYCL - #ifdef __AVX512DQ__ - #define EIGEN_VECTORIZE_AVX512DQ - #endif - #ifdef __AVX512ER__ - #define EIGEN_VECTORIZE_AVX512ER - #endif - #endif - #endif - - // Disable AVX support on broken xcode versions - #if defined(__apple_build_version__) && (__apple_build_version__ == 11000033 ) && ( __MAC_OS_X_VERSION_MIN_REQUIRED == 101500 ) - // A nasty bug in the clang compiler shipped with xcode in a common compilation situation - // when XCode 11.0 and Mac deployment target macOS 10.15 is https://trac.macports.org/ticket/58776#no1 - #ifdef EIGEN_VECTORIZE_AVX - #undef EIGEN_VECTORIZE_AVX - #warning "Disabling AVX support: clang compiler shipped with XCode 11.[012] generates broken assembly with -macosx-version-min=10.15 and AVX enabled. " - #ifdef EIGEN_VECTORIZE_AVX2 - #undef EIGEN_VECTORIZE_AVX2 - #endif - #ifdef EIGEN_VECTORIZE_FMA - #undef EIGEN_VECTORIZE_FMA - #endif - #ifdef EIGEN_VECTORIZE_AVX512 - #undef EIGEN_VECTORIZE_AVX512 - #endif - #ifdef EIGEN_VECTORIZE_AVX512DQ - #undef EIGEN_VECTORIZE_AVX512DQ - #endif - #ifdef EIGEN_VECTORIZE_AVX512ER - #undef EIGEN_VECTORIZE_AVX512ER - #endif - #endif - // NOTE: Confirmed test failures in XCode 11.0, and XCode 11.2 with -macosx-version-min=10.15 and AVX - // NOTE using -macosx-version-min=10.15 with Xcode 11.0 results in runtime segmentation faults in many tests, 11.2 produce core dumps in 3 tests - // NOTE using -macosx-version-min=10.14 produces functioning and passing tests in all cases - // NOTE __clang_version__ "11.0.0 (clang-1100.0.33.8)" XCode 11.0 <- Produces many segfault and core dumping tests - // with -macosx-version-min=10.15 and AVX - // NOTE __clang_version__ "11.0.0 (clang-1100.0.33.12)" XCode 11.2 <- Produces 3 core dumping tests with - // -macosx-version-min=10.15 and AVX - #endif - - // include files - - // This extern "C" works around a MINGW-w64 compilation issue - // https://sourceforge.net/tracker/index.php?func=detail&aid=3018394&group_id=202880&atid=983354 - // In essence, intrin.h is included by windows.h and also declares intrinsics (just as emmintrin.h etc. below do). - // However, intrin.h uses an extern "C" declaration, and g++ thus complains of duplicate declarations - // with conflicting linkage. The linkage for intrinsics doesn't matter, but at that stage the compiler doesn't know; - // so, to avoid compile errors when windows.h is included after Eigen/Core, ensure intrinsics are extern "C" here too. - // notice that since these are C headers, the extern "C" is theoretically needed anyways. - extern "C" { - // In theory we should only include immintrin.h and not the other *mmintrin.h header files directly. - // Doing so triggers some issues with ICC. However old gcc versions seems to not have this file, thus: - #if EIGEN_COMP_ICC >= 1110 - #include <immintrin.h> - #else - #include <mmintrin.h> - #include <emmintrin.h> - #include <xmmintrin.h> - #ifdef EIGEN_VECTORIZE_SSE3 - #include <pmmintrin.h> - #endif - #ifdef EIGEN_VECTORIZE_SSSE3 - #include <tmmintrin.h> - #endif - #ifdef EIGEN_VECTORIZE_SSE4_1 - #include <smmintrin.h> - #endif - #ifdef EIGEN_VECTORIZE_SSE4_2 - #include <nmmintrin.h> - #endif - #if defined(EIGEN_VECTORIZE_AVX) || defined(EIGEN_VECTORIZE_AVX512) - #include <immintrin.h> - #endif - #endif - } // end extern "C" - - #elif defined __VSX__ - - #define EIGEN_VECTORIZE - #define EIGEN_VECTORIZE_VSX - #include <altivec.h> - // We need to #undef all these ugly tokens defined in <altivec.h> - // => use __vector instead of vector - #undef bool - #undef vector - #undef pixel - - #elif defined __ALTIVEC__ - - #define EIGEN_VECTORIZE - #define EIGEN_VECTORIZE_ALTIVEC - #include <altivec.h> - // We need to #undef all these ugly tokens defined in <altivec.h> - // => use __vector instead of vector - #undef bool - #undef vector - #undef pixel - - #elif (defined __ARM_NEON) || (defined __ARM_NEON__) - - #define EIGEN_VECTORIZE - #define EIGEN_VECTORIZE_NEON - #include <arm_neon.h> - - #elif (defined __s390x__ && defined __VEC__) - - #define EIGEN_VECTORIZE - #define EIGEN_VECTORIZE_ZVECTOR - #include <vecintrin.h> - - #elif defined __mips_msa - - // Limit MSA optimizations to little-endian CPUs for now. - // TODO: Perhaps, eventually support MSA optimizations on big-endian CPUs? - #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - #if defined(__LP64__) - #define EIGEN_MIPS_64 - #else - #define EIGEN_MIPS_32 - #endif - #define EIGEN_VECTORIZE - #define EIGEN_VECTORIZE_MSA - #include <msa.h> - #endif - - #endif -#endif - -#if defined(__F16C__) && (!defined(EIGEN_GPUCC) && (!defined(EIGEN_COMP_CLANG) || EIGEN_COMP_CLANG>=380)) - // We can use the optimized fp16 to float and float to fp16 conversion routines - #define EIGEN_HAS_FP16_C - - #if defined(EIGEN_COMP_CLANG) - // Workaround for clang: The FP16C intrinsics for clang are included by - // immintrin.h, as opposed to emmintrin.h as suggested by Intel: - // https://software.intel.com/sites/landingpage/IntrinsicsGuide/#othertechs=FP16C&expand=1711 - #include <immintrin.h> - #endif -#endif - -#if defined EIGEN_CUDACC - #define EIGEN_VECTORIZE_GPU - #include <vector_types.h> - #if EIGEN_CUDA_SDK_VER >= 70500 - #define EIGEN_HAS_CUDA_FP16 - #endif -#endif - -#if defined(EIGEN_HAS_CUDA_FP16) - #include <cuda_runtime_api.h> - #include <cuda_fp16.h> -#endif - -#if defined(EIGEN_HIPCC) - #define EIGEN_VECTORIZE_GPU - #include <hip/hip_vector_types.h> -#endif - -#if defined(EIGEN_HIP_DEVICE_COMPILE) - #define EIGEN_HAS_HIP_FP16 - #include <hip/hip_fp16.h> -#endif - - -/** \brief Namespace containing all symbols from the %Eigen library. */ -namespace Eigen { - -inline static const char *SimdInstructionSetsInUse(void) { -#if defined(EIGEN_VECTORIZE_AVX512) - return "AVX512, FMA, AVX2, AVX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2"; -#elif defined(EIGEN_VECTORIZE_AVX) - return "AVX SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2"; -#elif defined(EIGEN_VECTORIZE_SSE4_2) - return "SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2"; -#elif defined(EIGEN_VECTORIZE_SSE4_1) - return "SSE, SSE2, SSE3, SSSE3, SSE4.1"; -#elif defined(EIGEN_VECTORIZE_SSSE3) - return "SSE, SSE2, SSE3, SSSE3"; -#elif defined(EIGEN_VECTORIZE_SSE3) - return "SSE, SSE2, SSE3"; -#elif defined(EIGEN_VECTORIZE_SSE2) - return "SSE, SSE2"; -#elif defined(EIGEN_VECTORIZE_ALTIVEC) - return "AltiVec"; -#elif defined(EIGEN_VECTORIZE_VSX) - return "VSX"; -#elif defined(EIGEN_VECTORIZE_NEON) - return "ARM NEON"; -#elif defined(EIGEN_VECTORIZE_ZVECTOR) - return "S390X ZVECTOR"; -#elif defined(EIGEN_VECTORIZE_MSA) - return "MIPS MSA"; -#else - return "None"; -#endif -} - -} // end namespace Eigen - - -#endif // EIGEN_CONFIGURE_VECTORIZATION_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/Constants.h b/external/eigen/include/eigen3/Eigen/src/Core/util/Constants.h deleted file mode 100644 index 7ada8219..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/Constants.h +++ /dev/null @@ -1,550 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CONSTANTS_H -#define EIGEN_CONSTANTS_H - -namespace Eigen { - -/** This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is - * stored in some runtime variable. - * - * Changing the value of Dynamic breaks the ABI, as Dynamic is often used as a template parameter for Matrix. - */ -const int Dynamic = -1; - -/** This value means that a signed quantity (e.g., a signed index) is not known at compile-time, and that instead its value - * has to be specified at runtime. - */ -const int DynamicIndex = 0xffffff; - -/** This value means that the increment to go from one value to another in a sequence is not constant for each step. - */ -const int UndefinedIncr = 0xfffffe; - -/** This value means +Infinity; it is currently used only as the p parameter to MatrixBase::lpNorm<int>(). - * The value Infinity there means the L-infinity norm. - */ -const int Infinity = -1; - -/** This value means that the cost to evaluate an expression coefficient is either very expensive or - * cannot be known at compile time. - * - * This value has to be positive to (1) simplify cost computation, and (2) allow to distinguish between a very expensive and very very expensive expressions. - * It thus must also be large enough to make sure unrolling won't happen and that sub expressions will be evaluated, but not too large to avoid overflow. - */ -const int HugeCost = 10000; - -/** \defgroup flags Flags - * \ingroup Core_Module - * - * These are the possible bits which can be OR'ed to constitute the flags of a matrix or - * expression. - * - * It is important to note that these flags are a purely compile-time notion. They are a compile-time property of - * an expression type, implemented as enum's. They are not stored in memory at runtime, and they do not incur any - * runtime overhead. - * - * \sa MatrixBase::Flags - */ - -/** \ingroup flags - * - * for a matrix, this means that the storage order is row-major. - * If this bit is not set, the storage order is column-major. - * For an expression, this determines the storage order of - * the matrix created by evaluation of that expression. - * \sa \blank \ref TopicStorageOrders */ -const unsigned int RowMajorBit = 0x1; - -/** \ingroup flags - * means the expression should be evaluated by the calling expression */ -const unsigned int EvalBeforeNestingBit = 0x2; - -/** \ingroup flags - * \deprecated - * means the expression should be evaluated before any assignment */ -EIGEN_DEPRECATED -const unsigned int EvalBeforeAssigningBit = 0x4; // FIXME deprecated - -/** \ingroup flags - * - * Short version: means the expression might be vectorized - * - * Long version: means that the coefficients can be handled by packets - * and start at a memory location whose alignment meets the requirements - * of the present CPU architecture for optimized packet access. In the fixed-size - * case, there is the additional condition that it be possible to access all the - * coefficients by packets (this implies the requirement that the size be a multiple of 16 bytes, - * and that any nontrivial strides don't break the alignment). In the dynamic-size case, - * there is no such condition on the total size and strides, so it might not be possible to access - * all coeffs by packets. - * - * \note This bit can be set regardless of whether vectorization is actually enabled. - * To check for actual vectorizability, see \a ActualPacketAccessBit. - */ -const unsigned int PacketAccessBit = 0x8; - -#ifdef EIGEN_VECTORIZE -/** \ingroup flags - * - * If vectorization is enabled (EIGEN_VECTORIZE is defined) this constant - * is set to the value \a PacketAccessBit. - * - * If vectorization is not enabled (EIGEN_VECTORIZE is not defined) this constant - * is set to the value 0. - */ -const unsigned int ActualPacketAccessBit = PacketAccessBit; -#else -const unsigned int ActualPacketAccessBit = 0x0; -#endif - -/** \ingroup flags - * - * Short version: means the expression can be seen as 1D vector. - * - * Long version: means that one can access the coefficients - * of this expression by coeff(int), and coeffRef(int) in the case of a lvalue expression. These - * index-based access methods are guaranteed - * to not have to do any runtime computation of a (row, col)-pair from the index, so that it - * is guaranteed that whenever it is available, index-based access is at least as fast as - * (row,col)-based access. Expressions for which that isn't possible don't have the LinearAccessBit. - * - * If both PacketAccessBit and LinearAccessBit are set, then the - * packets of this expression can be accessed by packet(int), and writePacket(int) in the case of a - * lvalue expression. - * - * Typically, all vector expressions have the LinearAccessBit, but there is one exception: - * Product expressions don't have it, because it would be troublesome for vectorization, even when the - * Product is a vector expression. Thus, vector Product expressions allow index-based coefficient access but - * not index-based packet access, so they don't have the LinearAccessBit. - */ -const unsigned int LinearAccessBit = 0x10; - -/** \ingroup flags - * - * Means the expression has a coeffRef() method, i.e. is writable as its individual coefficients are directly addressable. - * This rules out read-only expressions. - * - * Note that DirectAccessBit and LvalueBit are mutually orthogonal, as there are examples of expression having one but note - * the other: - * \li writable expressions that don't have a very simple memory layout as a strided array, have LvalueBit but not DirectAccessBit - * \li Map-to-const expressions, for example Map<const Matrix>, have DirectAccessBit but not LvalueBit - * - * Expressions having LvalueBit also have their coeff() method returning a const reference instead of returning a new value. - */ -const unsigned int LvalueBit = 0x20; - -/** \ingroup flags - * - * Means that the underlying array of coefficients can be directly accessed as a plain strided array. The memory layout - * of the array of coefficients must be exactly the natural one suggested by rows(), cols(), - * outerStride(), innerStride(), and the RowMajorBit. This rules out expressions such as Diagonal, whose coefficients, - * though referencable, do not have such a regular memory layout. - * - * See the comment on LvalueBit for an explanation of how LvalueBit and DirectAccessBit are mutually orthogonal. - */ -const unsigned int DirectAccessBit = 0x40; - -/** \deprecated \ingroup flags - * - * means the first coefficient packet is guaranteed to be aligned. - * An expression cannot has the AlignedBit without the PacketAccessBit flag. - * In other words, this means we are allow to perform an aligned packet access to the first element regardless - * of the expression kind: - * \code - * expression.packet<Aligned>(0); - * \endcode - */ -EIGEN_DEPRECATED const unsigned int AlignedBit = 0x80; - -const unsigned int NestByRefBit = 0x100; - -/** \ingroup flags - * - * for an expression, this means that the storage order - * can be either row-major or column-major. - * The precise choice will be decided at evaluation time or when - * combined with other expressions. - * \sa \blank \ref RowMajorBit, \ref TopicStorageOrders */ -const unsigned int NoPreferredStorageOrderBit = 0x200; - -/** \ingroup flags - * - * Means that the underlying coefficients can be accessed through pointers to the sparse (un)compressed storage format, - * that is, the expression provides: - * \code - inline const Scalar* valuePtr() const; - inline const Index* innerIndexPtr() const; - inline const Index* outerIndexPtr() const; - inline const Index* innerNonZeroPtr() const; - \endcode - */ -const unsigned int CompressedAccessBit = 0x400; - - -// list of flags that are inherited by default -const unsigned int HereditaryBits = RowMajorBit - | EvalBeforeNestingBit; - -/** \defgroup enums Enumerations - * \ingroup Core_Module - * - * Various enumerations used in %Eigen. Many of these are used as template parameters. - */ - -/** \ingroup enums - * Enum containing possible values for the \c Mode or \c UpLo parameter of - * MatrixBase::selfadjointView() and MatrixBase::triangularView(), and selfadjoint solvers. */ -enum UpLoType { - /** View matrix as a lower triangular matrix. */ - Lower=0x1, - /** View matrix as an upper triangular matrix. */ - Upper=0x2, - /** %Matrix has ones on the diagonal; to be used in combination with #Lower or #Upper. */ - UnitDiag=0x4, - /** %Matrix has zeros on the diagonal; to be used in combination with #Lower or #Upper. */ - ZeroDiag=0x8, - /** View matrix as a lower triangular matrix with ones on the diagonal. */ - UnitLower=UnitDiag|Lower, - /** View matrix as an upper triangular matrix with ones on the diagonal. */ - UnitUpper=UnitDiag|Upper, - /** View matrix as a lower triangular matrix with zeros on the diagonal. */ - StrictlyLower=ZeroDiag|Lower, - /** View matrix as an upper triangular matrix with zeros on the diagonal. */ - StrictlyUpper=ZeroDiag|Upper, - /** Used in BandMatrix and SelfAdjointView to indicate that the matrix is self-adjoint. */ - SelfAdjoint=0x10, - /** Used to support symmetric, non-selfadjoint, complex matrices. */ - Symmetric=0x20 -}; - -/** \ingroup enums - * Enum for indicating whether a buffer is aligned or not. */ -enum AlignmentType { - Unaligned=0, /**< Data pointer has no specific alignment. */ - Aligned8=8, /**< Data pointer is aligned on a 8 bytes boundary. */ - Aligned16=16, /**< Data pointer is aligned on a 16 bytes boundary. */ - Aligned32=32, /**< Data pointer is aligned on a 32 bytes boundary. */ - Aligned64=64, /**< Data pointer is aligned on a 64 bytes boundary. */ - Aligned128=128, /**< Data pointer is aligned on a 128 bytes boundary. */ - AlignedMask=255, - Aligned=16, /**< \deprecated Synonym for Aligned16. */ -#if EIGEN_MAX_ALIGN_BYTES==128 - AlignedMax = Aligned128 -#elif EIGEN_MAX_ALIGN_BYTES==64 - AlignedMax = Aligned64 -#elif EIGEN_MAX_ALIGN_BYTES==32 - AlignedMax = Aligned32 -#elif EIGEN_MAX_ALIGN_BYTES==16 - AlignedMax = Aligned16 -#elif EIGEN_MAX_ALIGN_BYTES==8 - AlignedMax = Aligned8 -#elif EIGEN_MAX_ALIGN_BYTES==0 - AlignedMax = Unaligned -#else -#error Invalid value for EIGEN_MAX_ALIGN_BYTES -#endif -}; - -/** \ingroup enums - * Enum containing possible values for the \p Direction parameter of - * Reverse, PartialReduxExpr and VectorwiseOp. */ -enum DirectionType { - /** For Reverse, all columns are reversed; - * for PartialReduxExpr and VectorwiseOp, act on columns. */ - Vertical, - /** For Reverse, all rows are reversed; - * for PartialReduxExpr and VectorwiseOp, act on rows. */ - Horizontal, - /** For Reverse, both rows and columns are reversed; - * not used for PartialReduxExpr and VectorwiseOp. */ - BothDirections -}; - -/** \internal \ingroup enums - * Enum to specify how to traverse the entries of a matrix. */ -enum TraversalType { - /** \internal Default traversal, no vectorization, no index-based access */ - DefaultTraversal, - /** \internal No vectorization, use index-based access to have only one for loop instead of 2 nested loops */ - LinearTraversal, - /** \internal Equivalent to a slice vectorization for fixed-size matrices having good alignment - * and good size */ - InnerVectorizedTraversal, - /** \internal Vectorization path using a single loop plus scalar loops for the - * unaligned boundaries */ - LinearVectorizedTraversal, - /** \internal Generic vectorization path using one vectorized loop per row/column with some - * scalar loops to handle the unaligned boundaries */ - SliceVectorizedTraversal, - /** \internal Special case to properly handle incompatible scalar types or other defecting cases*/ - InvalidTraversal, - /** \internal Evaluate all entries at once */ - AllAtOnceTraversal -}; - -/** \internal \ingroup enums - * Enum to specify whether to unroll loops when traversing over the entries of a matrix. */ -enum UnrollingType { - /** \internal Do not unroll loops. */ - NoUnrolling, - /** \internal Unroll only the inner loop, but not the outer loop. */ - InnerUnrolling, - /** \internal Unroll both the inner and the outer loop. If there is only one loop, - * because linear traversal is used, then unroll that loop. */ - CompleteUnrolling -}; - -/** \internal \ingroup enums - * Enum to specify whether to use the default (built-in) implementation or the specialization. */ -enum SpecializedType { - Specialized, - BuiltIn -}; - -/** \ingroup enums - * Enum containing possible values for the \p _Options template parameter of - * Matrix, Array and BandMatrix. */ -enum StorageOptions { - /** Storage order is column major (see \ref TopicStorageOrders). */ - ColMajor = 0, - /** Storage order is row major (see \ref TopicStorageOrders). */ - RowMajor = 0x1, // it is only a coincidence that this is equal to RowMajorBit -- don't rely on that - /** Align the matrix itself if it is vectorizable fixed-size */ - AutoAlign = 0, - /** Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated, may still be requested to be aligned) */ // FIXME --- clarify the situation - DontAlign = 0x2 -}; - -/** \ingroup enums - * Enum for specifying whether to apply or solve on the left or right. */ -enum SideType { - /** Apply transformation on the left. */ - OnTheLeft = 1, - /** Apply transformation on the right. */ - OnTheRight = 2 -}; - - - -/* the following used to be written as: - * - * struct NoChange_t {}; - * namespace { - * EIGEN_UNUSED NoChange_t NoChange; - * } - * - * on the ground that it feels dangerous to disambiguate overloaded functions on enum/integer types. - * However, this leads to "variable declared but never referenced" warnings on Intel Composer XE, - * and we do not know how to get rid of them (bug 450). - */ - -enum NoChange_t { NoChange }; -enum Sequential_t { Sequential }; -enum Default_t { Default }; - -/** \internal \ingroup enums - * Used in AmbiVector. */ -enum AmbiVectorMode { - IsDense = 0, - IsSparse -}; - -/** \ingroup enums - * Used as template parameter in DenseCoeffBase and MapBase to indicate - * which accessors should be provided. */ -enum AccessorLevels { - /** Read-only access via a member function. */ - ReadOnlyAccessors, - /** Read/write access via member functions. */ - WriteAccessors, - /** Direct read-only access to the coefficients. */ - DirectAccessors, - /** Direct read/write access to the coefficients. */ - DirectWriteAccessors -}; - -/** \ingroup enums - * Enum with options to give to various decompositions. */ -enum DecompositionOptions { - /** \internal Not used (meant for LDLT?). */ - Pivoting = 0x01, - /** \internal Not used (meant for LDLT?). */ - NoPivoting = 0x02, - /** Used in JacobiSVD to indicate that the square matrix U is to be computed. */ - ComputeFullU = 0x04, - /** Used in JacobiSVD to indicate that the thin matrix U is to be computed. */ - ComputeThinU = 0x08, - /** Used in JacobiSVD to indicate that the square matrix V is to be computed. */ - ComputeFullV = 0x10, - /** Used in JacobiSVD to indicate that the thin matrix V is to be computed. */ - ComputeThinV = 0x20, - /** Used in SelfAdjointEigenSolver and GeneralizedSelfAdjointEigenSolver to specify - * that only the eigenvalues are to be computed and not the eigenvectors. */ - EigenvaluesOnly = 0x40, - /** Used in SelfAdjointEigenSolver and GeneralizedSelfAdjointEigenSolver to specify - * that both the eigenvalues and the eigenvectors are to be computed. */ - ComputeEigenvectors = 0x80, - /** \internal */ - EigVecMask = EigenvaluesOnly | ComputeEigenvectors, - /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should - * solve the generalized eigenproblem \f$ Ax = \lambda B x \f$. */ - Ax_lBx = 0x100, - /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should - * solve the generalized eigenproblem \f$ ABx = \lambda x \f$. */ - ABx_lx = 0x200, - /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should - * solve the generalized eigenproblem \f$ BAx = \lambda x \f$. */ - BAx_lx = 0x400, - /** \internal */ - GenEigMask = Ax_lBx | ABx_lx | BAx_lx -}; - -/** \ingroup enums - * Possible values for the \p QRPreconditioner template parameter of JacobiSVD. */ -enum QRPreconditioners { - /** Do not specify what is to be done if the SVD of a non-square matrix is asked for. */ - NoQRPreconditioner, - /** Use a QR decomposition without pivoting as the first step. */ - HouseholderQRPreconditioner, - /** Use a QR decomposition with column pivoting as the first step. */ - ColPivHouseholderQRPreconditioner, - /** Use a QR decomposition with full pivoting as the first step. */ - FullPivHouseholderQRPreconditioner -}; - -#ifdef Success -#error The preprocessor symbol 'Success' is defined, possibly by the X11 header file X.h -#endif - -/** \ingroup enums - * Enum for reporting the status of a computation. */ -enum ComputationInfo { - /** Computation was successful. */ - Success = 0, - /** The provided data did not satisfy the prerequisites. */ - NumericalIssue = 1, - /** Iterative procedure did not converge. */ - NoConvergence = 2, - /** The inputs are invalid, or the algorithm has been improperly called. - * When assertions are enabled, such errors trigger an assert. */ - InvalidInput = 3 -}; - -/** \ingroup enums - * Enum used to specify how a particular transformation is stored in a matrix. - * \sa Transform, Hyperplane::transform(). */ -enum TransformTraits { - /** Transformation is an isometry. */ - Isometry = 0x1, - /** Transformation is an affine transformation stored as a (Dim+1)^2 matrix whose last row is - * assumed to be [0 ... 0 1]. */ - Affine = 0x2, - /** Transformation is an affine transformation stored as a (Dim) x (Dim+1) matrix. */ - AffineCompact = 0x10 | Affine, - /** Transformation is a general projective transformation stored as a (Dim+1)^2 matrix. */ - Projective = 0x20 -}; - -/** \internal \ingroup enums - * Enum used to choose between implementation depending on the computer architecture. */ -namespace Architecture -{ - enum Type { - Generic = 0x0, - SSE = 0x1, - AltiVec = 0x2, - VSX = 0x3, - NEON = 0x4, - MSA = 0x5, -#if defined EIGEN_VECTORIZE_SSE - Target = SSE -#elif defined EIGEN_VECTORIZE_ALTIVEC - Target = AltiVec -#elif defined EIGEN_VECTORIZE_VSX - Target = VSX -#elif defined EIGEN_VECTORIZE_NEON - Target = NEON -#elif defined EIGEN_VECTORIZE_MSA - Target = MSA -#else - Target = Generic -#endif - }; -} - -/** \internal \ingroup enums - * Enum used as template parameter in Product and product evaluators. */ -enum ProductImplType -{ DefaultProduct=0, LazyProduct, AliasFreeProduct, CoeffBasedProductMode, LazyCoeffBasedProductMode, OuterProduct, InnerProduct, GemvProduct, GemmProduct }; - -/** \internal \ingroup enums - * Enum used in experimental parallel implementation. */ -enum Action {GetAction, SetAction}; - -/** The type used to identify a dense storage. */ -struct Dense {}; - -/** The type used to identify a general sparse storage. */ -struct Sparse {}; - -/** The type used to identify a general solver (factored) storage. */ -struct SolverStorage {}; - -/** The type used to identify a permutation storage. */ -struct PermutationStorage {}; - -/** The type used to identify a permutation storage. */ -struct TranspositionsStorage {}; - -/** The type used to identify a matrix expression */ -struct MatrixXpr {}; - -/** The type used to identify an array expression */ -struct ArrayXpr {}; - -// An evaluator must define its shape. By default, it can be one of the following: -struct DenseShape { static std::string debugName() { return "DenseShape"; } }; -struct SolverShape { static std::string debugName() { return "SolverShape"; } }; -struct HomogeneousShape { static std::string debugName() { return "HomogeneousShape"; } }; -struct DiagonalShape { static std::string debugName() { return "DiagonalShape"; } }; -struct BandShape { static std::string debugName() { return "BandShape"; } }; -struct TriangularShape { static std::string debugName() { return "TriangularShape"; } }; -struct SelfAdjointShape { static std::string debugName() { return "SelfAdjointShape"; } }; -struct PermutationShape { static std::string debugName() { return "PermutationShape"; } }; -struct TranspositionsShape { static std::string debugName() { return "TranspositionsShape"; } }; -struct SparseShape { static std::string debugName() { return "SparseShape"; } }; - -namespace internal { - - // random access iterators based on coeff*() accessors. -struct IndexBased {}; - -// evaluator based on iterators to access coefficients. -struct IteratorBased {}; - -/** \internal - * Constants for comparison functors - */ -enum ComparisonName { - cmp_EQ = 0, - cmp_LT = 1, - cmp_LE = 2, - cmp_UNORD = 3, - cmp_NEQ = 4, - cmp_GT = 5, - cmp_GE = 6 -}; -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CONSTANTS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/DisableStupidWarnings.h b/external/eigen/include/eigen3/Eigen/src/Core/util/DisableStupidWarnings.h deleted file mode 100644 index 4501d324..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/DisableStupidWarnings.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef EIGEN_WARNINGS_DISABLED -#define EIGEN_WARNINGS_DISABLED - -#ifdef _MSC_VER - // 4100 - unreferenced formal parameter (occurred e.g. in aligned_allocator::destroy(pointer p)) - // 4101 - unreferenced local variable - // 4181 - qualifier applied to reference type ignored - // 4211 - nonstandard extension used : redefined extern to static - // 4244 - 'argument' : conversion from 'type1' to 'type2', possible loss of data - // 4273 - QtAlignedMalloc, inconsistent DLL linkage - // 4324 - structure was padded due to declspec(align()) - // 4503 - decorated name length exceeded, name was truncated - // 4512 - assignment operator could not be generated - // 4522 - 'class' : multiple assignment operators specified - // 4700 - uninitialized local variable 'xyz' used - // 4714 - function marked as __forceinline not inlined - // 4717 - 'function' : recursive on all control paths, function will cause runtime stack overflow - // 4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning) - #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS - #pragma warning( push ) - #endif - #pragma warning( disable : 4100 4101 4181 4211 4244 4273 4324 4503 4512 4522 4700 4714 4717 4800) - -#elif defined __INTEL_COMPILER - // 2196 - routine is both "inline" and "noinline" ("noinline" assumed) - // ICC 12 generates this warning even without any inline keyword, when defining class methods 'inline' i.e. inside of class body - // typedef that may be a reference type. - // 279 - controlling expression is constant - // ICC 12 generates this warning on assert(constant_expression_depending_on_template_params) and frankly this is a legitimate use case. - // 1684 - conversion from pointer to same-sized integral type (potential portability problem) - // 2259 - non-pointer conversion from "Eigen::Index={ptrdiff_t={long}}" to "int" may lose significant bits - #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS - #pragma warning push - #endif - #pragma warning disable 2196 279 1684 2259 - -#elif defined __clang__ - // -Wconstant-logical-operand - warning: use of logical && with constant operand; switch to bitwise & or remove constant - // this is really a stupid warning as it warns on compile-time expressions involving enums - #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS - #pragma clang diagnostic push - #endif - #pragma clang diagnostic ignored "-Wconstant-logical-operand" - #if __clang_major__ >= 3 && __clang_minor__ >= 5 - #pragma clang diagnostic ignored "-Wabsolute-value" - #endif - #if ( defined(__ALTIVEC__) || defined(__VSX__) ) && __cplusplus < 201103L - // warning: generic selections are a C11-specific feature - // ignoring warnings thrown at vec_ctf in Altivec/PacketMath.h - #pragma clang diagnostic ignored "-Wc11-extensions" - #endif - -#elif defined __GNUC__ - - #if (!defined(EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS)) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) - #pragma GCC diagnostic push - #endif - // g++ warns about local variables shadowing member functions, which is too strict - #pragma GCC diagnostic ignored "-Wshadow" - #if __GNUC__ == 4 && __GNUC_MINOR__ < 8 - // Until g++-4.7 there are warnings when comparing unsigned int vs 0, even in templated functions: - #pragma GCC diagnostic ignored "-Wtype-limits" - #endif - #if __GNUC__>=6 - #pragma GCC diagnostic ignored "-Wignored-attributes" - #endif - #if __GNUC__==7 - // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325 - #pragma GCC diagnostic ignored "-Wattributes" - #endif -#endif - -#if defined __NVCC__ - #pragma diag_suppress boolean_controlling_expr_is_constant - // Disable the "statement is unreachable" message - #pragma diag_suppress code_is_unreachable - // Disable the "dynamic initialization in unreachable code" message - #pragma diag_suppress initialization_not_reachable - // Disable the "invalid error number" message that we get with older versions of nvcc - #pragma diag_suppress 1222 - // Disable the "calling a __host__ function from a __host__ __device__ function is not allowed" messages (yes, there are many of them and they seem to change with every version of the compiler) - #pragma diag_suppress 2527 - #pragma diag_suppress 2529 - #pragma diag_suppress 2651 - #pragma diag_suppress 2653 - #pragma diag_suppress 2668 - #pragma diag_suppress 2669 - #pragma diag_suppress 2670 - #pragma diag_suppress 2671 - #pragma diag_suppress 2735 - #pragma diag_suppress 2737 - #pragma diag_suppress 2739 -#endif - -#else -// warnings already disabled: -# ifndef EIGEN_WARNINGS_DISABLED_2 -# define EIGEN_WARNINGS_DISABLED_2 -# elif defined(EIGEN_INTERNAL_DEBUGGING) -# error "Do not include \"DisableStupidWarnings.h\" recursively more than twice!" -# endif - -#endif // not EIGEN_WARNINGS_DISABLED diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h b/external/eigen/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h deleted file mode 100644 index 953f52af..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h +++ /dev/null @@ -1,320 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_FORWARDDECLARATIONS_H -#define EIGEN_FORWARDDECLARATIONS_H - -namespace Eigen { -namespace internal { - -template<typename T> struct traits; - -// here we say once and for all that traits<const T> == traits<T> -// When constness must affect traits, it has to be constness on template parameters on which T itself depends. -// For example, traits<Map<const T> > != traits<Map<T> >, but -// traits<const Map<T> > == traits<Map<T> > -template<typename T> struct traits<const T> : traits<T> {}; - -template<typename Derived> struct has_direct_access -{ - enum { ret = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0 }; -}; - -template<typename Derived> struct accessors_level -{ - enum { has_direct_access = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0, - has_write_access = (traits<Derived>::Flags & LvalueBit) ? 1 : 0, - value = has_direct_access ? (has_write_access ? DirectWriteAccessors : DirectAccessors) - : (has_write_access ? WriteAccessors : ReadOnlyAccessors) - }; -}; - -template<typename T> struct evaluator_traits; - -template< typename T> struct evaluator; - -} // end namespace internal - -template<typename T> struct NumTraits; - -template<typename Derived> struct EigenBase; -template<typename Derived> class DenseBase; -template<typename Derived> class PlainObjectBase; -template<typename Derived, int Level> class DenseCoeffsBase; - -template<typename _Scalar, int _Rows, int _Cols, - int _Options = AutoAlign | -#if EIGEN_GNUC_AT(3,4) - // workaround a bug in at least gcc 3.4.6 - // the innermost ?: ternary operator is misparsed. We write it slightly - // differently and this makes gcc 3.4.6 happy, but it's ugly. - // The error would only show up with EIGEN_DEFAULT_TO_ROW_MAJOR is defined - // (when EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION is RowMajor) - ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor - : !(_Cols==1 && _Rows!=1) ? EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION - : Eigen::ColMajor ), -#else - ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor - : (_Cols==1 && _Rows!=1) ? Eigen::ColMajor - : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ), -#endif - int _MaxRows = _Rows, - int _MaxCols = _Cols -> class Matrix; - -template<typename Derived> class MatrixBase; -template<typename Derived> class ArrayBase; - -template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged; -template<typename ExpressionType, template <typename> class StorageBase > class NoAlias; -template<typename ExpressionType> class NestByValue; -template<typename ExpressionType> class ForceAlignedAccess; -template<typename ExpressionType> class SwapWrapper; - -template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false> class Block; -template<typename XprType, typename RowIndices, typename ColIndices> class IndexedView; -template<typename XprType, int Rows=Dynamic, int Cols=Dynamic, int Order=0> class Reshaped; - -template<typename MatrixType, int Size=Dynamic> class VectorBlock; -template<typename MatrixType> class Transpose; -template<typename MatrixType> class Conjugate; -template<typename NullaryOp, typename MatrixType> class CwiseNullaryOp; -template<typename UnaryOp, typename MatrixType> class CwiseUnaryOp; -template<typename ViewOp, typename MatrixType> class CwiseUnaryView; -template<typename BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp; -template<typename TernaryOp, typename Arg1, typename Arg2, typename Arg3> class CwiseTernaryOp; -template<typename Decomposition, typename Rhstype> class Solve; -template<typename XprType> class Inverse; - -template<typename Lhs, typename Rhs, int Option = DefaultProduct> class Product; - -template<typename Derived> class DiagonalBase; -template<typename _DiagonalVectorType> class DiagonalWrapper; -template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime=SizeAtCompileTime> class DiagonalMatrix; -template<typename MatrixType, typename DiagonalType, int ProductOrder> class DiagonalProduct; -template<typename MatrixType, int Index = 0> class Diagonal; -template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime, typename IndexType=int> class PermutationMatrix; -template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime, typename IndexType=int> class Transpositions; -template<typename Derived> class PermutationBase; -template<typename Derived> class TranspositionsBase; -template<typename _IndicesType> class PermutationWrapper; -template<typename _IndicesType> class TranspositionsWrapper; - -template<typename Derived, - int Level = internal::accessors_level<Derived>::has_write_access ? WriteAccessors : ReadOnlyAccessors -> class MapBase; -template<int InnerStrideAtCompileTime, int OuterStrideAtCompileTime> class Stride; -template<int Value = Dynamic> class InnerStride; -template<int Value = Dynamic> class OuterStride; -template<typename MatrixType, int MapOptions=Unaligned, typename StrideType = Stride<0,0> > class Map; -template<typename Derived> class RefBase; -template<typename PlainObjectType, int Options = 0, - typename StrideType = typename internal::conditional<PlainObjectType::IsVectorAtCompileTime,InnerStride<1>,OuterStride<> >::type > class Ref; - -template<typename Derived> class TriangularBase; -template<typename MatrixType, unsigned int Mode> class TriangularView; -template<typename MatrixType, unsigned int Mode> class SelfAdjointView; -template<typename MatrixType> class SparseView; -template<typename ExpressionType> class WithFormat; -template<typename MatrixType> struct CommaInitializer; -template<typename Derived> class ReturnByValue; -template<typename ExpressionType> class ArrayWrapper; -template<typename ExpressionType> class MatrixWrapper; -template<typename Derived> class SolverBase; -template<typename XprType> class InnerIterator; - -namespace internal { -template<typename XprType> class generic_randaccess_stl_iterator; -template<typename XprType> class pointer_based_stl_iterator; -template<typename XprType, DirectionType Direction> class subvector_stl_iterator; -template<typename DecompositionType> struct kernel_retval_base; -template<typename DecompositionType> struct kernel_retval; -template<typename DecompositionType> struct image_retval_base; -template<typename DecompositionType> struct image_retval; -} // end namespace internal - -namespace internal { -template<typename _Scalar, int Rows=Dynamic, int Cols=Dynamic, int Supers=Dynamic, int Subs=Dynamic, int Options=0> class BandMatrix; -} - -namespace internal { -template<typename Lhs, typename Rhs> struct product_type; - -template<bool> struct EnableIf; - -/** \internal - * \class product_evaluator - * Products need their own evaluator with more template arguments allowing for - * easier partial template specializations. - */ -template< typename T, - int ProductTag = internal::product_type<typename T::Lhs,typename T::Rhs>::ret, - typename LhsShape = typename evaluator_traits<typename T::Lhs>::Shape, - typename RhsShape = typename evaluator_traits<typename T::Rhs>::Shape, - typename LhsScalar = typename traits<typename T::Lhs>::Scalar, - typename RhsScalar = typename traits<typename T::Rhs>::Scalar - > struct product_evaluator; -} - -template<typename Lhs, typename Rhs, - int ProductType = internal::product_type<Lhs,Rhs>::value> -struct ProductReturnType; - -// this is a workaround for sun CC -template<typename Lhs, typename Rhs> struct LazyProductReturnType; - -namespace internal { - -// Provides scalar/packet-wise product and product with accumulation -// with optional conjugation of the arguments. -template<typename LhsScalar, typename RhsScalar, bool ConjLhs=false, bool ConjRhs=false> struct conj_helper; - -template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_sum_op; -template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_difference_op; -template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_conj_product_op; -template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_min_op; -template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_max_op; -template<typename Scalar> struct scalar_opposite_op; -template<typename Scalar> struct scalar_conjugate_op; -template<typename Scalar> struct scalar_real_op; -template<typename Scalar> struct scalar_imag_op; -template<typename Scalar> struct scalar_abs_op; -template<typename Scalar> struct scalar_abs2_op; -template<typename Scalar> struct scalar_sqrt_op; -template<typename Scalar> struct scalar_rsqrt_op; -template<typename Scalar> struct scalar_exp_op; -template<typename Scalar> struct scalar_log_op; -template<typename Scalar> struct scalar_cos_op; -template<typename Scalar> struct scalar_sin_op; -template<typename Scalar> struct scalar_acos_op; -template<typename Scalar> struct scalar_asin_op; -template<typename Scalar> struct scalar_tan_op; -template<typename Scalar> struct scalar_inverse_op; -template<typename Scalar> struct scalar_square_op; -template<typename Scalar> struct scalar_cube_op; -template<typename Scalar, typename NewType> struct scalar_cast_op; -template<typename Scalar> struct scalar_random_op; -template<typename Scalar> struct scalar_constant_op; -template<typename Scalar> struct scalar_identity_op; -template<typename Scalar,bool iscpx> struct scalar_sign_op; -template<typename Scalar,typename ScalarExponent> struct scalar_pow_op; -template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_hypot_op; -template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_product_op; -template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_quotient_op; - -// SpecialFunctions module -template<typename Scalar> struct scalar_lgamma_op; -template<typename Scalar> struct scalar_digamma_op; -template<typename Scalar> struct scalar_erf_op; -template<typename Scalar> struct scalar_erfc_op; -template<typename Scalar> struct scalar_ndtri_op; -template<typename Scalar> struct scalar_igamma_op; -template<typename Scalar> struct scalar_igammac_op; -template<typename Scalar> struct scalar_zeta_op; -template<typename Scalar> struct scalar_betainc_op; - -// Bessel functions in SpecialFunctions module -template<typename Scalar> struct scalar_bessel_i0_op; -template<typename Scalar> struct scalar_bessel_i0e_op; -template<typename Scalar> struct scalar_bessel_i1_op; -template<typename Scalar> struct scalar_bessel_i1e_op; -template<typename Scalar> struct scalar_bessel_j0_op; -template<typename Scalar> struct scalar_bessel_y0_op; -template<typename Scalar> struct scalar_bessel_j1_op; -template<typename Scalar> struct scalar_bessel_y1_op; -template<typename Scalar> struct scalar_bessel_k0_op; -template<typename Scalar> struct scalar_bessel_k0e_op; -template<typename Scalar> struct scalar_bessel_k1_op; -template<typename Scalar> struct scalar_bessel_k1e_op; - - -} // end namespace internal - -struct IOFormat; - -// Array module -template<typename _Scalar, int _Rows, int _Cols, - int _Options = AutoAlign | -#if EIGEN_GNUC_AT(3,4) - // workaround a bug in at least gcc 3.4.6 - // the innermost ?: ternary operator is misparsed. We write it slightly - // differently and this makes gcc 3.4.6 happy, but it's ugly. - // The error would only show up with EIGEN_DEFAULT_TO_ROW_MAJOR is defined - // (when EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION is RowMajor) - ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor - : !(_Cols==1 && _Rows!=1) ? EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION - : Eigen::ColMajor ), -#else - ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor - : (_Cols==1 && _Rows!=1) ? Eigen::ColMajor - : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ), -#endif - int _MaxRows = _Rows, int _MaxCols = _Cols> class Array; -template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType> class Select; -template<typename MatrixType, typename BinaryOp, int Direction> class PartialReduxExpr; -template<typename ExpressionType, int Direction> class VectorwiseOp; -template<typename MatrixType,int RowFactor,int ColFactor> class Replicate; -template<typename MatrixType, int Direction = BothDirections> class Reverse; - -template<typename MatrixType> class FullPivLU; -template<typename MatrixType> class PartialPivLU; -namespace internal { -template<typename MatrixType> struct inverse_impl; -} -template<typename MatrixType> class HouseholderQR; -template<typename MatrixType> class ColPivHouseholderQR; -template<typename MatrixType> class FullPivHouseholderQR; -template<typename MatrixType> class CompleteOrthogonalDecomposition; -template<typename MatrixType> class SVDBase; -template<typename MatrixType, int QRPreconditioner = ColPivHouseholderQRPreconditioner> class JacobiSVD; -template<typename MatrixType> class BDCSVD; -template<typename MatrixType, int UpLo = Lower> class LLT; -template<typename MatrixType, int UpLo = Lower> class LDLT; -template<typename VectorsType, typename CoeffsType, int Side=OnTheLeft> class HouseholderSequence; -template<typename Scalar> class JacobiRotation; - -// Geometry module: -template<typename Derived, int _Dim> class RotationBase; -template<typename Lhs, typename Rhs> class Cross; -template<typename Derived> class QuaternionBase; -template<typename Scalar> class Rotation2D; -template<typename Scalar> class AngleAxis; -template<typename Scalar,int Dim> class Translation; -template<typename Scalar,int Dim> class AlignedBox; -template<typename Scalar, int Options = AutoAlign> class Quaternion; -template<typename Scalar,int Dim,int Mode,int _Options=AutoAlign> class Transform; -template <typename _Scalar, int _AmbientDim, int Options=AutoAlign> class ParametrizedLine; -template <typename _Scalar, int _AmbientDim, int Options=AutoAlign> class Hyperplane; -template<typename Scalar> class UniformScaling; -template<typename MatrixType,int Direction> class Homogeneous; - -// Sparse module: -template<typename Derived> class SparseMatrixBase; - -// MatrixFunctions module -template<typename Derived> struct MatrixExponentialReturnValue; -template<typename Derived> class MatrixFunctionReturnValue; -template<typename Derived> class MatrixSquareRootReturnValue; -template<typename Derived> class MatrixLogarithmReturnValue; -template<typename Derived> class MatrixPowerReturnValue; -template<typename Derived> class MatrixComplexPowerReturnValue; - -namespace internal { -template <typename Scalar> -struct stem_function -{ - typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar; - typedef ComplexScalar type(ComplexScalar, int); -}; -} - -} // end namespace Eigen - -#endif // EIGEN_FORWARDDECLARATIONS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/IndexedViewHelper.h b/external/eigen/include/eigen3/Eigen/src/Core/util/IndexedViewHelper.h deleted file mode 100644 index 1cda8506..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/IndexedViewHelper.h +++ /dev/null @@ -1,186 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_INDEXED_VIEW_HELPER_H -#define EIGEN_INDEXED_VIEW_HELPER_H - -namespace Eigen { - -namespace internal { -struct symbolic_last_tag {}; -} - -/** \var last - * \ingroup Core_Module - * - * Can be used as a parameter to Eigen::seq and Eigen::seqN functions to symbolically reference the last element/row/columns - * of the underlying vector or matrix once passed to DenseBase::operator()(const RowIndices&, const ColIndices&). - * - * This symbolic placeholder supports standard arithmetic operations. - * - * A typical usage example would be: - * \code - * using namespace Eigen; - * using Eigen::last; - * VectorXd v(n); - * v(seq(2,last-2)).setOnes(); - * \endcode - * - * \sa end - */ -static const symbolic::SymbolExpr<internal::symbolic_last_tag> last; // PLEASE use Eigen::last instead of Eigen::placeholders::last - -/** \var lastp1 - * \ingroup Core_Module - * - * Can be used as a parameter to Eigen::seq and Eigen::seqN functions to symbolically - * reference the last+1 element/row/columns of the underlying vector or matrix once - * passed to DenseBase::operator()(const RowIndices&, const ColIndices&). - * - * This symbolic placeholder supports standard arithmetic operations. - * It is essentially an alias to last+fix<1>. - * - * \sa last - */ -#ifdef EIGEN_PARSED_BY_DOXYGEN -static const auto lastp1 = last+fix<1>; -#else -// Using a FixedExpr<1> expression is important here to make sure the compiler -// can fully optimize the computation starting indices with zero overhead. -static const symbolic::AddExpr<symbolic::SymbolExpr<internal::symbolic_last_tag>,symbolic::ValueExpr<Eigen::internal::FixedInt<1> > > lastp1(last+fix<1>()); -#endif - -namespace internal { - - // Replace symbolic last/end "keywords" by their true runtime value -inline Index eval_expr_given_size(Index x, Index /* size */) { return x; } - -template<int N> -FixedInt<N> eval_expr_given_size(FixedInt<N> x, Index /*size*/) { return x; } - -template<typename Derived> -Index eval_expr_given_size(const symbolic::BaseExpr<Derived> &x, Index size) -{ - return x.derived().eval(last=size-1); -} - -// Extract increment/step at compile time -template<typename T, typename EnableIf = void> struct get_compile_time_incr { - enum { value = UndefinedIncr }; -}; - -// Analogue of std::get<0>(x), but tailored for our needs. -template<typename T> -Index first(const T& x) { return x.first(); } - -// IndexedViewCompatibleType/makeIndexedViewCompatible turn an arbitrary object of type T into something usable by MatrixSlice -// The generic implementation is a no-op -template<typename T,int XprSize,typename EnableIf=void> -struct IndexedViewCompatibleType { - typedef T type; -}; - -template<typename T,typename Q> -const T& makeIndexedViewCompatible(const T& x, Index /*size*/, Q) { return x; } - -//-------------------------------------------------------------------------------- -// Handling of a single Index -//-------------------------------------------------------------------------------- - -struct SingleRange { - enum { - SizeAtCompileTime = 1 - }; - SingleRange(Index val) : m_value(val) {} - Index operator[](Index) const { return m_value; } - Index size() const { return 1; } - Index first() const { return m_value; } - Index m_value; -}; - -template<> struct get_compile_time_incr<SingleRange> { - enum { value = 1 }; // 1 or 0 ?? -}; - -// Turn a single index into something that looks like an array (i.e., that exposes a .size(), and operator[](int) methods) -template<typename T, int XprSize> -struct IndexedViewCompatibleType<T,XprSize,typename internal::enable_if<internal::is_integral<T>::value>::type> { - // Here we could simply use Array, but maybe it's less work for the compiler to use - // a simpler wrapper as SingleRange - //typedef Eigen::Array<Index,1,1> type; - typedef SingleRange type; -}; - -template<typename T, int XprSize> -struct IndexedViewCompatibleType<T, XprSize, typename enable_if<symbolic::is_symbolic<T>::value>::type> { - typedef SingleRange type; -}; - - -template<typename T> -typename enable_if<symbolic::is_symbolic<T>::value,SingleRange>::type -makeIndexedViewCompatible(const T& id, Index size, SpecializedType) { - return eval_expr_given_size(id,size); -} - -//-------------------------------------------------------------------------------- -// Handling of all -//-------------------------------------------------------------------------------- - -struct all_t { all_t() {} }; - -// Convert a symbolic 'all' into a usable range type -template<int XprSize> -struct AllRange { - enum { SizeAtCompileTime = XprSize }; - AllRange(Index size = XprSize) : m_size(size) {} - Index operator[](Index i) const { return i; } - Index size() const { return m_size.value(); } - Index first() const { return 0; } - variable_if_dynamic<Index,XprSize> m_size; -}; - -template<int XprSize> -struct IndexedViewCompatibleType<all_t,XprSize> { - typedef AllRange<XprSize> type; -}; - -template<typename XprSizeType> -inline AllRange<get_fixed_value<XprSizeType>::value> makeIndexedViewCompatible(all_t , XprSizeType size, SpecializedType) { - return AllRange<get_fixed_value<XprSizeType>::value>(size); -} - -template<int Size> struct get_compile_time_incr<AllRange<Size> > { - enum { value = 1 }; -}; - -} // end namespace internal - - -/** \var all - * \ingroup Core_Module - * Can be used as a parameter to DenseBase::operator()(const RowIndices&, const ColIndices&) to index all rows or columns - */ -static const Eigen::internal::all_t all; // PLEASE use Eigen::all instead of Eigen::placeholders::all - - -namespace placeholders { - typedef symbolic::SymbolExpr<internal::symbolic_last_tag> last_t; - typedef symbolic::AddExpr<symbolic::SymbolExpr<internal::symbolic_last_tag>,symbolic::ValueExpr<Eigen::internal::FixedInt<1> > > end_t; - typedef Eigen::internal::all_t all_t; - - EIGEN_DEPRECATED static const all_t all = Eigen::all; // PLEASE use Eigen::all instead of Eigen::placeholders::all - EIGEN_DEPRECATED static const last_t last = Eigen::last; // PLEASE use Eigen::last instead of Eigen::placeholders::last - EIGEN_DEPRECATED static const end_t end = Eigen::lastp1; // PLEASE use Eigen::lastp1 instead of Eigen::placeholders::end -} - -} // end namespace Eigen - -#endif // EIGEN_INDEXED_VIEW_HELPER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/IntegralConstant.h b/external/eigen/include/eigen3/Eigen/src/Core/util/IntegralConstant.h deleted file mode 100644 index caeea232..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/IntegralConstant.h +++ /dev/null @@ -1,272 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_INTEGRAL_CONSTANT_H -#define EIGEN_INTEGRAL_CONSTANT_H - -namespace Eigen { - -namespace internal { - -template<int N> class FixedInt; -template<int N> class VariableAndFixedInt; - -/** \internal - * \class FixedInt - * - * This class embeds a compile-time integer \c N. - * - * It is similar to c++11 std::integral_constant<int,N> but with some additional features - * such as: - * - implicit conversion to int - * - arithmetic and some bitwise operators: -, +, *, /, %, &, | - * - c++98/14 compatibility with fix<N> and fix<N>() syntax to define integral constants. - * - * It is strongly discouraged to directly deal with this class FixedInt. Instances are expcected to - * be created by the user using Eigen::fix<N> or Eigen::fix<N>(). In C++98-11, the former syntax does - * not create a FixedInt<N> instance but rather a point to function that needs to be \em cleaned-up - * using the generic helper: - * \code - * internal::cleanup_index_type<T>::type - * internal::cleanup_index_type<T,DynamicKey>::type - * \endcode - * where T can a FixedInt<N>, a pointer to function FixedInt<N> (*)(), or numerous other integer-like representations. - * \c DynamicKey is either Dynamic (default) or DynamicIndex and used to identify true compile-time values. - * - * For convenience, you can extract the compile-time value \c N in a generic way using the following helper: - * \code - * internal::get_fixed_value<T,DefaultVal>::value - * \endcode - * that will give you \c N if T equals FixedInt<N> or FixedInt<N> (*)(), and \c DefaultVal if T does not embed any compile-time value (e.g., T==int). - * - * \sa fix<N>, class VariableAndFixedInt - */ -template<int N> class FixedInt -{ -public: - static const int value = N; - operator int() const { return value; } - FixedInt() {} - FixedInt( VariableAndFixedInt<N> other) { - #ifndef EIGEN_INTERNAL_DEBUGGING - EIGEN_UNUSED_VARIABLE(other); - #endif - eigen_internal_assert(int(other)==N); - } - - FixedInt<-N> operator-() const { return FixedInt<-N>(); } - template<int M> - FixedInt<N+M> operator+( FixedInt<M>) const { return FixedInt<N+M>(); } - template<int M> - FixedInt<N-M> operator-( FixedInt<M>) const { return FixedInt<N-M>(); } - template<int M> - FixedInt<N*M> operator*( FixedInt<M>) const { return FixedInt<N*M>(); } - template<int M> - FixedInt<N/M> operator/( FixedInt<M>) const { return FixedInt<N/M>(); } - template<int M> - FixedInt<N%M> operator%( FixedInt<M>) const { return FixedInt<N%M>(); } - template<int M> - FixedInt<N|M> operator|( FixedInt<M>) const { return FixedInt<N|M>(); } - template<int M> - FixedInt<N&M> operator&( FixedInt<M>) const { return FixedInt<N&M>(); } - -#if EIGEN_HAS_CXX14 - // Needed in C++14 to allow fix<N>(): - FixedInt operator() () const { return *this; } - - VariableAndFixedInt<N> operator() (int val) const { return VariableAndFixedInt<N>(val); } -#else - FixedInt ( FixedInt<N> (*)() ) {} -#endif - -#if EIGEN_HAS_CXX11 - FixedInt(std::integral_constant<int,N>) {} -#endif -}; - -/** \internal - * \class VariableAndFixedInt - * - * This class embeds both a compile-time integer \c N and a runtime integer. - * Both values are supposed to be equal unless the compile-time value \c N has a special - * value meaning that the runtime-value should be used. Depending on the context, this special - * value can be either Eigen::Dynamic (for positive quantities) or Eigen::DynamicIndex (for - * quantities that can be negative). - * - * It is the return-type of the function Eigen::fix<N>(int), and most of the time this is the only - * way it is used. It is strongly discouraged to directly deal with instances of VariableAndFixedInt. - * Indeed, in order to write generic code, it is the responsibility of the callee to properly convert - * it to either a true compile-time quantity (i.e. a FixedInt<N>), or to a runtime quantity (e.g., an Index) - * using the following generic helper: - * \code - * internal::cleanup_index_type<T>::type - * internal::cleanup_index_type<T,DynamicKey>::type - * \endcode - * where T can be a template instantiation of VariableAndFixedInt or numerous other integer-like representations. - * \c DynamicKey is either Dynamic (default) or DynamicIndex and used to identify true compile-time values. - * - * For convenience, you can also extract the compile-time value \c N using the following helper: - * \code - * internal::get_fixed_value<T,DefaultVal>::value - * \endcode - * that will give you \c N if T equals VariableAndFixedInt<N>, and \c DefaultVal if T does not embed any compile-time value (e.g., T==int). - * - * \sa fix<N>(int), class FixedInt - */ -template<int N> class VariableAndFixedInt -{ -public: - static const int value = N; - operator int() const { return m_value; } - VariableAndFixedInt(int val) { m_value = val; } -protected: - int m_value; -}; - -template<typename T, int Default=Dynamic> struct get_fixed_value { - static const int value = Default; -}; - -template<int N,int Default> struct get_fixed_value<FixedInt<N>,Default> { - static const int value = N; -}; - -#if !EIGEN_HAS_CXX14 -template<int N,int Default> struct get_fixed_value<FixedInt<N> (*)(),Default> { - static const int value = N; -}; -#endif - -template<int N,int Default> struct get_fixed_value<VariableAndFixedInt<N>,Default> { - static const int value = N ; -}; - -template<typename T, int N, int Default> -struct get_fixed_value<variable_if_dynamic<T,N>,Default> { - static const int value = N; -}; - -template<typename T> EIGEN_DEVICE_FUNC Index get_runtime_value(const T &x) { return x; } -#if !EIGEN_HAS_CXX14 -template<int N> EIGEN_DEVICE_FUNC Index get_runtime_value(FixedInt<N> (*)()) { return N; } -#endif - -// Cleanup integer/FixedInt/VariableAndFixedInt/etc types: - -// By default, no cleanup: -template<typename T, int DynamicKey=Dynamic, typename EnableIf=void> struct cleanup_index_type { typedef T type; }; - -// Convert any integral type (e.g., short, int, unsigned int, etc.) to Eigen::Index -template<typename T, int DynamicKey> struct cleanup_index_type<T,DynamicKey,typename internal::enable_if<internal::is_integral<T>::value>::type> { typedef Index type; }; - -#if !EIGEN_HAS_CXX14 -// In c++98/c++11, fix<N> is a pointer to function that we better cleanup to a true FixedInt<N>: -template<int N, int DynamicKey> struct cleanup_index_type<FixedInt<N> (*)(), DynamicKey> { typedef FixedInt<N> type; }; -#endif - -// If VariableAndFixedInt does not match DynamicKey, then we turn it to a pure compile-time value: -template<int N, int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<N>, DynamicKey> { typedef FixedInt<N> type; }; -// If VariableAndFixedInt matches DynamicKey, then we turn it to a pure runtime-value (aka Index): -template<int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<DynamicKey>, DynamicKey> { typedef Index type; }; - -#if EIGEN_HAS_CXX11 -template<int N, int DynamicKey> struct cleanup_index_type<std::integral_constant<int,N>, DynamicKey> { typedef FixedInt<N> type; }; -#endif - -} // end namespace internal - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -#if EIGEN_HAS_CXX14 -template<int N> -static const internal::FixedInt<N> fix{}; -#else -template<int N> -inline internal::FixedInt<N> fix() { return internal::FixedInt<N>(); } - -// The generic typename T is mandatory. Otherwise, a code like fix<N> could refer to either the function above or this next overload. -// This way a code like fix<N> can only refer to the previous function. -template<int N,typename T> -inline internal::VariableAndFixedInt<N> fix(T val) { return internal::VariableAndFixedInt<N>(internal::convert_index<int>(val)); } -#endif - -#else // EIGEN_PARSED_BY_DOXYGEN - -/** \var fix<N>() - * \ingroup Core_Module - * - * This \em identifier permits to construct an object embedding a compile-time integer \c N. - * - * \tparam N the compile-time integer value - * - * It is typically used in conjunction with the Eigen::seq and Eigen::seqN functions to pass compile-time values to them: - * \code - * seqN(10,fix<4>,fix<-3>) // <=> [10 7 4 1] - * \endcode - * - * See also the function fix(int) to pass both a compile-time and runtime value. - * - * In c++14, it is implemented as: - * \code - * template<int N> static const internal::FixedInt<N> fix{}; - * \endcode - * where internal::FixedInt<N> is an internal template class similar to - * <a href="http://en.cppreference.com/w/cpp/types/integral_constant">\c std::integral_constant </a><tt> <int,N> </tt> - * Here, \c fix<N> is thus an object of type \c internal::FixedInt<N>. - * - * In c++98/11, it is implemented as a function: - * \code - * template<int N> inline internal::FixedInt<N> fix(); - * \endcode - * Here internal::FixedInt<N> is thus a pointer to function. - * - * If for some reason you want a true object in c++98 then you can write: \code fix<N>() \endcode which is also valid in c++14. - * - * \sa fix<N>(int), seq, seqN - */ -template<int N> -static const auto fix(); - -/** \fn fix<N>(int) - * \ingroup Core_Module - * - * This function returns an object embedding both a compile-time integer \c N, and a fallback runtime value \a val. - * - * \tparam N the compile-time integer value - * \param val the fallback runtime integer value - * - * This function is a more general version of the \ref fix identifier/function that can be used in template code - * where the compile-time value could turn out to actually mean "undefined at compile-time". For positive integers - * such as a size or a dimension, this case is identified by Eigen::Dynamic, whereas runtime signed integers - * (e.g., an increment/stride) are identified as Eigen::DynamicIndex. In such a case, the runtime value \a val - * will be used as a fallback. - * - * A typical use case would be: - * \code - * template<typename Derived> void foo(const MatrixBase<Derived> &mat) { - * const int N = Derived::RowsAtCompileTime==Dynamic ? Dynamic : Derived::RowsAtCompileTime/2; - * const int n = mat.rows()/2; - * ... mat( seqN(0,fix<N>(n) ) ...; - * } - * \endcode - * In this example, the function Eigen::seqN knows that the second argument is expected to be a size. - * If the passed compile-time value N equals Eigen::Dynamic, then the proxy object returned by fix will be dissmissed, and converted to an Eigen::Index of value \c n. - * Otherwise, the runtime-value \c n will be dissmissed, and the returned ArithmeticSequence will be of the exact same type as <tt> seqN(0,fix<N>) </tt>. - * - * \sa fix, seqN, class ArithmeticSequence - */ -template<int N> -static const auto fix(int val); - -#endif // EIGEN_PARSED_BY_DOXYGEN - -} // end namespace Eigen - -#endif // EIGEN_INTEGRAL_CONSTANT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/MKL_support.h b/external/eigen/include/eigen3/Eigen/src/Core/util/MKL_support.h deleted file mode 100644 index 17963fad..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/MKL_support.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to Intel(R) MKL - * Include file with common MKL declarations - ******************************************************************************** -*/ - -#ifndef EIGEN_MKL_SUPPORT_H -#define EIGEN_MKL_SUPPORT_H - -#ifdef EIGEN_USE_MKL_ALL - #ifndef EIGEN_USE_BLAS - #define EIGEN_USE_BLAS - #endif - #ifndef EIGEN_USE_LAPACKE - #define EIGEN_USE_LAPACKE - #endif - #ifndef EIGEN_USE_MKL_VML - #define EIGEN_USE_MKL_VML - #endif -#endif - -#ifdef EIGEN_USE_LAPACKE_STRICT - #define EIGEN_USE_LAPACKE -#endif - -#if defined(EIGEN_USE_MKL_VML) && !defined(EIGEN_USE_MKL) - #define EIGEN_USE_MKL -#endif - - -#if defined EIGEN_USE_MKL -# if (!defined MKL_DIRECT_CALL) && (!defined EIGEN_MKL_NO_DIRECT_CALL) -# define MKL_DIRECT_CALL -# define MKL_DIRECT_CALL_JUST_SET -# endif -# include <mkl.h> -/*Check IMKL version for compatibility: < 10.3 is not usable with Eigen*/ -# ifndef INTEL_MKL_VERSION -# undef EIGEN_USE_MKL /* INTEL_MKL_VERSION is not even defined on older versions */ -# elif INTEL_MKL_VERSION < 100305 /* the intel-mkl-103-release-notes say this was when the lapacke.h interface was added*/ -# undef EIGEN_USE_MKL -# endif -# ifndef EIGEN_USE_MKL - /*If the MKL version is too old, undef everything*/ -# undef EIGEN_USE_MKL_ALL -# undef EIGEN_USE_LAPACKE -# undef EIGEN_USE_MKL_VML -# undef EIGEN_USE_LAPACKE_STRICT -# undef EIGEN_USE_LAPACKE -# ifdef MKL_DIRECT_CALL_JUST_SET -# undef MKL_DIRECT_CALL -# endif -# endif -#endif - -#if defined EIGEN_USE_MKL - -#define EIGEN_MKL_VML_THRESHOLD 128 - -/* MKL_DOMAIN_BLAS, etc are defined only in 10.3 update 7 */ -/* MKL_BLAS, etc are not defined in 11.2 */ -#ifdef MKL_DOMAIN_ALL -#define EIGEN_MKL_DOMAIN_ALL MKL_DOMAIN_ALL -#else -#define EIGEN_MKL_DOMAIN_ALL MKL_ALL -#endif - -#ifdef MKL_DOMAIN_BLAS -#define EIGEN_MKL_DOMAIN_BLAS MKL_DOMAIN_BLAS -#else -#define EIGEN_MKL_DOMAIN_BLAS MKL_BLAS -#endif - -#ifdef MKL_DOMAIN_FFT -#define EIGEN_MKL_DOMAIN_FFT MKL_DOMAIN_FFT -#else -#define EIGEN_MKL_DOMAIN_FFT MKL_FFT -#endif - -#ifdef MKL_DOMAIN_VML -#define EIGEN_MKL_DOMAIN_VML MKL_DOMAIN_VML -#else -#define EIGEN_MKL_DOMAIN_VML MKL_VML -#endif - -#ifdef MKL_DOMAIN_PARDISO -#define EIGEN_MKL_DOMAIN_PARDISO MKL_DOMAIN_PARDISO -#else -#define EIGEN_MKL_DOMAIN_PARDISO MKL_PARDISO -#endif -#endif - -#if defined(EIGEN_USE_BLAS) && !defined(EIGEN_USE_MKL) -#include "../../misc/blas.h" -#endif - -namespace Eigen { - -typedef std::complex<double> dcomplex; -typedef std::complex<float> scomplex; - -#if defined(EIGEN_USE_MKL) -typedef MKL_INT BlasIndex; -#else -typedef int BlasIndex; -#endif - -} // end namespace Eigen - - -#endif // EIGEN_MKL_SUPPORT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/Macros.h b/external/eigen/include/eigen3/Eigen/src/Core/util/Macros.h deleted file mode 100644 index d0499a1c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/Macros.h +++ /dev/null @@ -1,1299 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MACROS_H -#define EIGEN_MACROS_H - -//------------------------------------------------------------------------------------------ -// Eigen version and basic defaults -//------------------------------------------------------------------------------------------ - -#define EIGEN_WORLD_VERSION 3 -#define EIGEN_MAJOR_VERSION 3 -#define EIGEN_MINOR_VERSION 90 - -#define EIGEN_VERSION_AT_LEAST(x,y,z) (EIGEN_WORLD_VERSION>x || (EIGEN_WORLD_VERSION>=x && \ - (EIGEN_MAJOR_VERSION>y || (EIGEN_MAJOR_VERSION>=y && \ - EIGEN_MINOR_VERSION>=z)))) - -#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR -#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Eigen::RowMajor -#else -#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Eigen::ColMajor -#endif - -#ifndef EIGEN_DEFAULT_DENSE_INDEX_TYPE -#define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t -#endif - -// Upperbound on the C++ version to use. -// Expected values are 03, 11, 14, 17, etc. -// By default, let's use an arbitrarily large C++ version. -#ifndef EIGEN_MAX_CPP_VER -#define EIGEN_MAX_CPP_VER 99 -#endif - -/** Allows to disable some optimizations which might affect the accuracy of the result. - * Such optimization are enabled by default, and set EIGEN_FAST_MATH to 0 to disable them. - * They currently include: - * - single precision ArrayBase::sin() and ArrayBase::cos() for SSE and AVX vectorization. - */ -#ifndef EIGEN_FAST_MATH -#define EIGEN_FAST_MATH 1 -#endif - -#ifndef EIGEN_STACK_ALLOCATION_LIMIT -// 131072 == 128 KB -#define EIGEN_STACK_ALLOCATION_LIMIT 131072 -#endif - -//------------------------------------------------------------------------------------------ -// Compiler identification, EIGEN_COMP_* -//------------------------------------------------------------------------------------------ - -/// \internal EIGEN_COMP_GNUC set to 1 for all compilers compatible with GCC -#ifdef __GNUC__ - #define EIGEN_COMP_GNUC (__GNUC__*10+__GNUC_MINOR__) -#else - #define EIGEN_COMP_GNUC 0 -#endif - -/// \internal EIGEN_COMP_CLANG set to major+minor version (e.g., 307 for clang 3.7) if the compiler is clang -#if defined(__clang__) - #define EIGEN_COMP_CLANG (__clang_major__*100+__clang_minor__) -#else - #define EIGEN_COMP_CLANG 0 -#endif - - -/// \internal EIGEN_COMP_LLVM set to 1 if the compiler backend is llvm -#if defined(__llvm__) - #define EIGEN_COMP_LLVM 1 -#else - #define EIGEN_COMP_LLVM 0 -#endif - -/// \internal EIGEN_COMP_ICC set to __INTEL_COMPILER if the compiler is Intel compiler, 0 otherwise -#if defined(__INTEL_COMPILER) - #define EIGEN_COMP_ICC __INTEL_COMPILER -#else - #define EIGEN_COMP_ICC 0 -#endif - -/// \internal EIGEN_COMP_MINGW set to 1 if the compiler is mingw -#if defined(__MINGW32__) - #define EIGEN_COMP_MINGW 1 -#else - #define EIGEN_COMP_MINGW 0 -#endif - -/// \internal EIGEN_COMP_SUNCC set to 1 if the compiler is Solaris Studio -#if defined(__SUNPRO_CC) - #define EIGEN_COMP_SUNCC 1 -#else - #define EIGEN_COMP_SUNCC 0 -#endif - -/// \internal EIGEN_COMP_MSVC set to _MSC_VER if the compiler is Microsoft Visual C++, 0 otherwise. -#if defined(_MSC_VER) - #define EIGEN_COMP_MSVC _MSC_VER -#else - #define EIGEN_COMP_MSVC 0 -#endif - -#if defined(__NVCC__) -#if defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 9) - #define EIGEN_COMP_NVCC ((__CUDACC_VER_MAJOR__ * 10000) + (__CUDACC_VER_MINOR__ * 100)) -#elif defined(__CUDACC_VER__) - #define EIGEN_COMP_NVCC __CUDACC_VER__ -#else - #error "NVCC did not define compiler version." -#endif -#else - #define EIGEN_COMP_NVCC 0 -#endif - -// For the record, here is a table summarizing the possible values for EIGEN_COMP_MSVC: -// name ver MSC_VER -// 2008 9 1500 -// 2010 10 1600 -// 2012 11 1700 -// 2013 12 1800 -// 2015 14 1900 -// "15" 15 1900 -// 2017-14.1 15.0 1910 -// 2017-14.11 15.3 1911 -// 2017-14.12 15.5 1912 -// 2017-14.13 15.6 1913 -// 2017-14.14 15.7 1914 - -/// \internal EIGEN_COMP_MSVC_LANG set to _MSVC_LANG if the compiler is Microsoft Visual C++, 0 otherwise. -#if defined(_MSVC_LANG) - #define EIGEN_COMP_MSVC_LANG _MSVC_LANG -#else - #define EIGEN_COMP_MSVC_LANG 0 -#endif - -// For the record, here is a table summarizing the possible values for EIGEN_COMP_MSVC_LANG: -// MSVC option Standard MSVC_LANG -// /std:c++14 (default as of VS 2019) C++14 201402L -// /std:c++17 C++17 201703L -// /std:c++latest >C++17 >201703L - -/// \internal EIGEN_COMP_MSVC_STRICT set to 1 if the compiler is really Microsoft Visual C++ and not ,e.g., ICC or clang-cl -#if EIGEN_COMP_MSVC && !(EIGEN_COMP_ICC || EIGEN_COMP_LLVM || EIGEN_COMP_CLANG) - #define EIGEN_COMP_MSVC_STRICT _MSC_VER -#else - #define EIGEN_COMP_MSVC_STRICT 0 -#endif - -/// \internal EIGEN_COMP_IBM set to xlc version if the compiler is IBM XL C++ -// XLC version -// 3.1 0x0301 -// 4.5 0x0405 -// 5.0 0x0500 -// 12.1 0x0C01 -#if defined(__IBMCPP__) || defined(__xlc__) || defined(__ibmxl__) - #define EIGEN_COMP_IBM __xlC__ -#else - #define EIGEN_COMP_IBM 0 -#endif - -/// \internal EIGEN_COMP_PGI set to PGI version if the compiler is Portland Group Compiler -#if defined(__PGI) - #define EIGEN_COMP_PGI (__PGIC__*100+__PGIC_MINOR__) -#else - #define EIGEN_COMP_PGI 0 -#endif - -/// \internal EIGEN_COMP_ARM set to 1 if the compiler is ARM Compiler -#if defined(__CC_ARM) || defined(__ARMCC_VERSION) - #define EIGEN_COMP_ARM 1 -#else - #define EIGEN_COMP_ARM 0 -#endif - -/// \internal EIGEN_COMP_EMSCRIPTEN set to 1 if the compiler is Emscripten Compiler -#if defined(__EMSCRIPTEN__) - #define EIGEN_COMP_EMSCRIPTEN 1 -#else - #define EIGEN_COMP_EMSCRIPTEN 0 -#endif - - -/// \internal EIGEN_GNUC_STRICT set to 1 if the compiler is really GCC and not a compatible compiler (e.g., ICC, clang, mingw, etc.) -#if EIGEN_COMP_GNUC && !(EIGEN_COMP_CLANG || EIGEN_COMP_ICC || EIGEN_COMP_MINGW || EIGEN_COMP_PGI || EIGEN_COMP_IBM || EIGEN_COMP_ARM || EIGEN_COMP_EMSCRIPTEN) - #define EIGEN_COMP_GNUC_STRICT 1 -#else - #define EIGEN_COMP_GNUC_STRICT 0 -#endif - - -#if EIGEN_COMP_GNUC - #define EIGEN_GNUC_AT_LEAST(x,y) ((__GNUC__==x && __GNUC_MINOR__>=y) || __GNUC__>x) - #define EIGEN_GNUC_AT_MOST(x,y) ((__GNUC__==x && __GNUC_MINOR__<=y) || __GNUC__<x) - #define EIGEN_GNUC_AT(x,y) ( __GNUC__==x && __GNUC_MINOR__==y ) -#else - #define EIGEN_GNUC_AT_LEAST(x,y) 0 - #define EIGEN_GNUC_AT_MOST(x,y) 0 - #define EIGEN_GNUC_AT(x,y) 0 -#endif - -// FIXME: could probably be removed as we do not support gcc 3.x anymore -#if EIGEN_COMP_GNUC && (__GNUC__ <= 3) -#define EIGEN_GCC3_OR_OLDER 1 -#else -#define EIGEN_GCC3_OR_OLDER 0 -#endif - - - -//------------------------------------------------------------------------------------------ -// Architecture identification, EIGEN_ARCH_* -//------------------------------------------------------------------------------------------ - - -#if defined(__x86_64__) || defined(_M_X64) || defined(__amd64) - #define EIGEN_ARCH_x86_64 1 -#else - #define EIGEN_ARCH_x86_64 0 -#endif - -#if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__i386) - #define EIGEN_ARCH_i386 1 -#else - #define EIGEN_ARCH_i386 0 -#endif - -#if EIGEN_ARCH_x86_64 || EIGEN_ARCH_i386 - #define EIGEN_ARCH_i386_OR_x86_64 1 -#else - #define EIGEN_ARCH_i386_OR_x86_64 0 -#endif - -/// \internal EIGEN_ARCH_ARM set to 1 if the architecture is ARM -#if defined(__arm__) - #define EIGEN_ARCH_ARM 1 -#else - #define EIGEN_ARCH_ARM 0 -#endif - -/// \internal EIGEN_ARCH_ARM64 set to 1 if the architecture is ARM64 -#if defined(__aarch64__) - #define EIGEN_ARCH_ARM64 1 -#else - #define EIGEN_ARCH_ARM64 0 -#endif - -#if EIGEN_ARCH_ARM || EIGEN_ARCH_ARM64 - #define EIGEN_ARCH_ARM_OR_ARM64 1 -#else - #define EIGEN_ARCH_ARM_OR_ARM64 0 -#endif - -/// \internal EIGEN_ARCH_MIPS set to 1 if the architecture is MIPS -#if defined(__mips__) || defined(__mips) - #define EIGEN_ARCH_MIPS 1 -#else - #define EIGEN_ARCH_MIPS 0 -#endif - -/// \internal EIGEN_ARCH_SPARC set to 1 if the architecture is SPARC -#if defined(__sparc__) || defined(__sparc) - #define EIGEN_ARCH_SPARC 1 -#else - #define EIGEN_ARCH_SPARC 0 -#endif - -/// \internal EIGEN_ARCH_IA64 set to 1 if the architecture is Intel Itanium -#if defined(__ia64__) - #define EIGEN_ARCH_IA64 1 -#else - #define EIGEN_ARCH_IA64 0 -#endif - -/// \internal EIGEN_ARCH_PPC set to 1 if the architecture is PowerPC -#if defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC) - #define EIGEN_ARCH_PPC 1 -#else - #define EIGEN_ARCH_PPC 0 -#endif - - - -//------------------------------------------------------------------------------------------ -// Operating system identification, EIGEN_OS_* -//------------------------------------------------------------------------------------------ - -/// \internal EIGEN_OS_UNIX set to 1 if the OS is a unix variant -#if defined(__unix__) || defined(__unix) - #define EIGEN_OS_UNIX 1 -#else - #define EIGEN_OS_UNIX 0 -#endif - -/// \internal EIGEN_OS_LINUX set to 1 if the OS is based on Linux kernel -#if defined(__linux__) - #define EIGEN_OS_LINUX 1 -#else - #define EIGEN_OS_LINUX 0 -#endif - -/// \internal EIGEN_OS_ANDROID set to 1 if the OS is Android -// note: ANDROID is defined when using ndk_build, __ANDROID__ is defined when using a standalone toolchain. -#if defined(__ANDROID__) || defined(ANDROID) - #define EIGEN_OS_ANDROID 1 -#else - #define EIGEN_OS_ANDROID 0 -#endif - -/// \internal EIGEN_OS_GNULINUX set to 1 if the OS is GNU Linux and not Linux-based OS (e.g., not android) -#if defined(__gnu_linux__) && !(EIGEN_OS_ANDROID) - #define EIGEN_OS_GNULINUX 1 -#else - #define EIGEN_OS_GNULINUX 0 -#endif - -/// \internal EIGEN_OS_BSD set to 1 if the OS is a BSD variant -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) - #define EIGEN_OS_BSD 1 -#else - #define EIGEN_OS_BSD 0 -#endif - -/// \internal EIGEN_OS_MAC set to 1 if the OS is MacOS -#if defined(__APPLE__) - #define EIGEN_OS_MAC 1 -#else - #define EIGEN_OS_MAC 0 -#endif - -/// \internal EIGEN_OS_QNX set to 1 if the OS is QNX -#if defined(__QNX__) - #define EIGEN_OS_QNX 1 -#else - #define EIGEN_OS_QNX 0 -#endif - -/// \internal EIGEN_OS_WIN set to 1 if the OS is Windows based -#if defined(_WIN32) - #define EIGEN_OS_WIN 1 -#else - #define EIGEN_OS_WIN 0 -#endif - -/// \internal EIGEN_OS_WIN64 set to 1 if the OS is Windows 64bits -#if defined(_WIN64) - #define EIGEN_OS_WIN64 1 -#else - #define EIGEN_OS_WIN64 0 -#endif - -/// \internal EIGEN_OS_WINCE set to 1 if the OS is Windows CE -#if defined(_WIN32_WCE) - #define EIGEN_OS_WINCE 1 -#else - #define EIGEN_OS_WINCE 0 -#endif - -/// \internal EIGEN_OS_CYGWIN set to 1 if the OS is Windows/Cygwin -#if defined(__CYGWIN__) - #define EIGEN_OS_CYGWIN 1 -#else - #define EIGEN_OS_CYGWIN 0 -#endif - -/// \internal EIGEN_OS_WIN_STRICT set to 1 if the OS is really Windows and not some variants -#if EIGEN_OS_WIN && !( EIGEN_OS_WINCE || EIGEN_OS_CYGWIN ) - #define EIGEN_OS_WIN_STRICT 1 -#else - #define EIGEN_OS_WIN_STRICT 0 -#endif - -/// \internal EIGEN_OS_SUN set to __SUNPRO_C if the OS is SUN -// compiler solaris __SUNPRO_C -// version studio -// 5.7 10 0x570 -// 5.8 11 0x580 -// 5.9 12 0x590 -// 5.10 12.1 0x5100 -// 5.11 12.2 0x5110 -// 5.12 12.3 0x5120 -#if (defined(sun) || defined(__sun)) && !(defined(__SVR4) || defined(__svr4__)) - #define EIGEN_OS_SUN __SUNPRO_C -#else - #define EIGEN_OS_SUN 0 -#endif - -/// \internal EIGEN_OS_SOLARIS set to 1 if the OS is Solaris -#if (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__)) - #define EIGEN_OS_SOLARIS 1 -#else - #define EIGEN_OS_SOLARIS 0 -#endif - - -//------------------------------------------------------------------------------------------ -// Detect GPU compilers and architectures -//------------------------------------------------------------------------------------------ - -// NVCC is not supported as the target platform for HIPCC -// Note that this also makes EIGEN_CUDACC and EIGEN_HIPCC mutually exclusive -#if defined(__NVCC__) && defined(__HIPCC__) - #error "NVCC as the target platform for HIPCC is currently not supported." -#endif - -#if defined(__CUDACC__) && !defined(EIGEN_NO_CUDA) - // Means the compiler is either nvcc or clang with CUDA enabled - #define EIGEN_CUDACC __CUDACC__ -#endif - -#if defined(__CUDA_ARCH__) && !defined(EIGEN_NO_CUDA) - // Means we are generating code for the device - #define EIGEN_CUDA_ARCH __CUDA_ARCH__ -#endif - -#if defined(EIGEN_CUDACC) -#include <cuda.h> - #define EIGEN_CUDA_SDK_VER (CUDA_VERSION * 10) -#else - #define EIGEN_CUDA_SDK_VER 0 -#endif - -#if defined(__HIPCC__) && !defined(EIGEN_NO_HIP) - // Means the compiler is HIPCC (analogous to EIGEN_CUDACC, but for HIP) - #define EIGEN_HIPCC __HIPCC__ - - // We need to include hip_runtime.h here because it pulls in - // ++ hip_common.h which contains the define for __HIP_DEVICE_COMPILE__ - // ++ host_defines.h which contains the defines for the __host__ and __device__ macros - #include <hip/hip_runtime.h> - - #if defined(__HIP_DEVICE_COMPILE__) - // analogous to EIGEN_CUDA_ARCH, but for HIP - #define EIGEN_HIP_DEVICE_COMPILE __HIP_DEVICE_COMPILE__ - #endif -#endif - -// Unify CUDA/HIPCC - -#if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC) -// -// If either EIGEN_CUDACC or EIGEN_HIPCC is defined, then define EIGEN_GPUCC -// -#define EIGEN_GPUCC -// -// EIGEN_HIPCC implies the HIP compiler and is used to tweak Eigen code for use in HIP kernels -// EIGEN_CUDACC implies the CUDA compiler and is used to tweak Eigen code for use in CUDA kernels -// -// In most cases the same tweaks are required to the Eigen code to enable in both the HIP and CUDA kernels. -// For those cases, the corresponding code should be guarded with -// #if defined(EIGEN_GPUCC) -// instead of -// #if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC) -// -// For cases where the tweak is specific to HIP, the code should be guarded with -// #if defined(EIGEN_HIPCC) -// -// For cases where the tweak is specific to CUDA, the code should be guarded with -// #if defined(EIGEN_CUDACC) -// -#endif - -#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE) -// -// If either EIGEN_CUDA_ARCH or EIGEN_HIP_DEVICE_COMPILE is defined, then define EIGEN_GPU_COMPILE_PHASE -// -#define EIGEN_GPU_COMPILE_PHASE -// -// GPU compilers (HIPCC, NVCC) typically do two passes over the source code, -// + one to compile the source for the "host" (ie CPU) -// + another to compile the source for the "device" (ie. GPU) -// -// Code that needs to enabled only during the either the "host" or "device" compilation phase -// needs to be guarded with a macro that indicates the current compilation phase -// -// EIGEN_HIP_DEVICE_COMPILE implies the device compilation phase in HIP -// EIGEN_CUDA_ARCH implies the device compilation phase in CUDA -// -// In most cases, the "host" / "device" specific code is the same for both HIP and CUDA -// For those cases, the code should be guarded with -// #if defined(EIGEN_GPU_COMPILE_PHASE) -// instead of -// #if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE) -// -// For cases where the tweak is specific to HIP, the code should be guarded with -// #if defined(EIGEN_HIP_DEVICE_COMPILE) -// -// For cases where the tweak is specific to CUDA, the code should be guarded with -// #if defined(EIGEN_CUDA_ARCH) -// -#endif - -#if defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__) -// EIGEN_USE_SYCL is a user-defined macro while __SYCL_DEVICE_ONLY__ is a compiler-defined macro. -// In most cases we want to check if both macros are defined which can be done using the define below. -#define SYCL_DEVICE_ONLY -#endif - -//------------------------------------------------------------------------------------------ -// Detect Compiler/Architecture/OS specific features -//------------------------------------------------------------------------------------------ - -#if EIGEN_GNUC_AT_MOST(4,3) && !EIGEN_COMP_CLANG - // see bug 89 - #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 0 -#else - #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 1 -#endif - -// Cross compiler wrapper around LLVM's __has_builtin -#ifdef __has_builtin -# define EIGEN_HAS_BUILTIN(x) __has_builtin(x) -#else -# define EIGEN_HAS_BUILTIN(x) 0 -#endif - -// A Clang feature extension to determine compiler features. -// We use it to determine 'cxx_rvalue_references' -#ifndef __has_feature -# define __has_feature(x) 0 -#endif - -// Some old compilers do not support template specializations like: -// template<typename T,int N> void foo(const T x[N]); -#if !( EIGEN_COMP_CLANG && ( (EIGEN_COMP_CLANG<309) \ - || (defined(__apple_build_version__) && (__apple_build_version__ < 9000000))) \ - || EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<49) -#define EIGEN_HAS_STATIC_ARRAY_TEMPLATE 1 -#else -#define EIGEN_HAS_STATIC_ARRAY_TEMPLATE 0 -#endif - - -// The macro EIGEN_COMP_CXXVER defines the c++ verson expected by the compiler. -// For instance, if compiling with gcc and -std=c++17, then EIGEN_COMP_CXXVER -// is defined to 17. -#if (defined(__cplusplus) && (__cplusplus > 201402L) || EIGEN_COMP_MSVC_LANG > 201402L) -#define EIGEN_COMP_CXXVER 17 -#elif (defined(__cplusplus) && (__cplusplus > 201103L) || EIGEN_COMP_MSVC >= 1910) -#define EIGEN_COMP_CXXVER 14 -#elif (defined(__cplusplus) && (__cplusplus >= 201103L) || EIGEN_COMP_MSVC >= 1900) -#define EIGEN_COMP_CXXVER 11 -#else -#define EIGEN_COMP_CXXVER 03 -#endif - - -// The macros EIGEN_HAS_CXX?? defines a rough estimate of available c++ features -// but in practice we should not rely on them but rather on the availabilty of -// individual features as defined later. -// This is why there is no EIGEN_HAS_CXX17. -// FIXME: get rid of EIGEN_HAS_CXX14 and maybe even EIGEN_HAS_CXX11. -#if EIGEN_MAX_CPP_VER>=11 && EIGEN_COMP_CXXVER>=11 -#define EIGEN_HAS_CXX11 1 -#else -#define EIGEN_HAS_CXX11 0 -#endif - -#if EIGEN_MAX_CPP_VER>=14 && EIGEN_COMP_CXXVER>=14 -#define EIGEN_HAS_CXX14 1 -#else -#define EIGEN_HAS_CXX14 0 -#endif - -// Do we support r-value references? -#ifndef EIGEN_HAS_RVALUE_REFERENCES -#if EIGEN_MAX_CPP_VER>=11 && \ - (__has_feature(cxx_rvalue_references) || \ - (defined(__cplusplus) && __cplusplus >= 201103L) || \ - (EIGEN_COMP_MSVC >= 1600)) - #define EIGEN_HAS_RVALUE_REFERENCES 1 -#else - #define EIGEN_HAS_RVALUE_REFERENCES 0 -#endif -#endif - -// Does the compiler support C99? -// Need to include <cmath> to make sure _GLIBCXX_USE_C99 gets defined -#include <cmath> -#ifndef EIGEN_HAS_C99_MATH -#if EIGEN_MAX_CPP_VER>=11 && \ - ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)) \ - || (defined(__GNUC__) && defined(_GLIBCXX_USE_C99)) \ - || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) \ - || (EIGEN_COMP_MSVC >= 1900) || defined(SYCL_DEVICE_ONLY)) - #define EIGEN_HAS_C99_MATH 1 -#else - #define EIGEN_HAS_C99_MATH 0 -#endif -#endif - -// Does the compiler support result_of? -// It's likely that MSVC 2013 supports result_of but I couldn't not find a good source for that, -// so let's be conservative. -#ifndef EIGEN_HAS_STD_RESULT_OF -#if EIGEN_MAX_CPP_VER>=11 && \ - (__has_feature(cxx_lambdas) || (defined(__cplusplus) && __cplusplus >= 201103L) || EIGEN_COMP_MSVC >= 1900) -#define EIGEN_HAS_STD_RESULT_OF 1 -#else -#define EIGEN_HAS_STD_RESULT_OF 0 -#endif -#endif - -#ifndef EIGEN_HAS_ALIGNAS -#if EIGEN_MAX_CPP_VER>=11 && EIGEN_HAS_CXX11 && \ - ( __has_feature(cxx_alignas) \ - || EIGEN_HAS_CXX14 \ - || (EIGEN_COMP_MSVC >= 1800) \ - || (EIGEN_GNUC_AT_LEAST(4,8)) \ - || (EIGEN_COMP_CLANG>=305) \ - || (EIGEN_COMP_ICC>=1500) \ - || (EIGEN_COMP_PGI>=1500) \ - || (EIGEN_COMP_SUNCC>=0x5130)) -#define EIGEN_HAS_ALIGNAS 1 -#else -#define EIGEN_HAS_ALIGNAS 0 -#endif -#endif - -// Does the compiler support type_traits? -// - full support of type traits was added only to GCC 5.1.0. -// - 20150626 corresponds to the last release of 4.x libstdc++ -#ifndef EIGEN_HAS_TYPE_TRAITS -#if EIGEN_MAX_CPP_VER>=11 && (EIGEN_HAS_CXX11 || EIGEN_COMP_MSVC >= 1700) \ - && ((!EIGEN_COMP_GNUC_STRICT) || EIGEN_GNUC_AT_LEAST(5, 1)) \ - && ((!defined(__GLIBCXX__)) || __GLIBCXX__ > 20150626) -#define EIGEN_HAS_TYPE_TRAITS 1 -#define EIGEN_INCLUDE_TYPE_TRAITS -#else -#define EIGEN_HAS_TYPE_TRAITS 0 -#endif -#endif - -// Does the compiler support variadic templates? -#ifndef EIGEN_HAS_VARIADIC_TEMPLATES -#if EIGEN_MAX_CPP_VER>=11 && (__cplusplus > 199711L || EIGEN_COMP_MSVC >= 1900) \ - && (!defined(__NVCC__) || !EIGEN_ARCH_ARM_OR_ARM64 || (EIGEN_COMP_NVCC >= 80000) ) - // ^^ Disable the use of variadic templates when compiling with versions of nvcc older than 8.0 on ARM devices: - // this prevents nvcc from crashing when compiling Eigen on Tegra X1 -#define EIGEN_HAS_VARIADIC_TEMPLATES 1 -#elif EIGEN_MAX_CPP_VER>=11 && (__cplusplus > 199711L || EIGEN_COMP_MSVC >= 1900) && defined(SYCL_DEVICE_ONLY) -#define EIGEN_HAS_VARIADIC_TEMPLATES 1 -#else -#define EIGEN_HAS_VARIADIC_TEMPLATES 0 -#endif -#endif - -// Does the compiler fully support const expressions? (as in c++14) -#ifndef EIGEN_HAS_CONSTEXPR - #if defined(EIGEN_CUDACC) - // Const expressions are supported provided that c++11 is enabled and we're using either clang or nvcc 7.5 or above - #if EIGEN_MAX_CPP_VER>=14 && (__cplusplus > 199711L && (EIGEN_COMP_CLANG || EIGEN_COMP_NVCC >= 70500)) - #define EIGEN_HAS_CONSTEXPR 1 - #endif - #elif EIGEN_MAX_CPP_VER>=14 && (__has_feature(cxx_relaxed_constexpr) || (defined(__cplusplus) && __cplusplus >= 201402L) || \ - (EIGEN_GNUC_AT_LEAST(4,8) && (__cplusplus > 199711L)) || \ - (EIGEN_COMP_CLANG >= 306 && (__cplusplus > 199711L))) - #define EIGEN_HAS_CONSTEXPR 1 - #endif - - #ifndef EIGEN_HAS_CONSTEXPR - #define EIGEN_HAS_CONSTEXPR 0 - #endif - -#endif // EIGEN_HAS_CONSTEXPR - -// Does the compiler support C++11 math? -// Let's be conservative and enable the default C++11 implementation only if we are sure it exists -#ifndef EIGEN_HAS_CXX11_MATH - #if EIGEN_MAX_CPP_VER>=11 && ((__cplusplus > 201103L) || (__cplusplus >= 201103L) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_MSVC || EIGEN_COMP_ICC) \ - && (EIGEN_ARCH_i386_OR_x86_64) && (EIGEN_OS_GNULINUX || EIGEN_OS_WIN_STRICT || EIGEN_OS_MAC)) - #define EIGEN_HAS_CXX11_MATH 1 - #else - #define EIGEN_HAS_CXX11_MATH 0 - #endif -#endif - -// Does the compiler support proper C++11 containers? -#ifndef EIGEN_HAS_CXX11_CONTAINERS - #if EIGEN_MAX_CPP_VER>=11 && \ - ((__cplusplus > 201103L) \ - || ((__cplusplus >= 201103L) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_ICC>=1400)) \ - || EIGEN_COMP_MSVC >= 1900) - #define EIGEN_HAS_CXX11_CONTAINERS 1 - #else - #define EIGEN_HAS_CXX11_CONTAINERS 0 - #endif -#endif - -// Does the compiler support C++11 noexcept? -#ifndef EIGEN_HAS_CXX11_NOEXCEPT - #if EIGEN_MAX_CPP_VER>=11 && \ - (__has_feature(cxx_noexcept) \ - || (__cplusplus > 201103L) \ - || ((__cplusplus >= 201103L) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_ICC>=1400)) \ - || EIGEN_COMP_MSVC >= 1900) - #define EIGEN_HAS_CXX11_NOEXCEPT 1 - #else - #define EIGEN_HAS_CXX11_NOEXCEPT 0 - #endif -#endif - -#ifndef EIGEN_HAS_CXX11_ATOMIC - #if EIGEN_MAX_CPP_VER>=11 && \ - (__has_feature(cxx_atomic) \ - || (__cplusplus > 201103L) \ - || ((__cplusplus >= 201103L) && (EIGEN_COMP_MSVC==0 || EIGEN_COMP_MSVC >= 1700))) - #define EIGEN_HAS_CXX11_ATOMIC 1 - #else - #define EIGEN_HAS_CXX11_ATOMIC 0 - #endif -#endif - -#ifndef EIGEN_HAS_CXX11_OVERRIDE_FINAL - #if EIGEN_MAX_CPP_VER>=11 && \ - (__cplusplus >= 201103L || EIGEN_COMP_MSVC >= 1700) - #define EIGEN_HAS_CXX11_OVERRIDE_FINAL 1 - #else - #define EIGEN_HAS_CXX11_OVERRIDE_FINAL 0 - #endif -#endif - -// NOTE: the required Apple's clang version is very conservative -// and it could be that XCode 9 works just fine. -// NOTE: the MSVC version is based on https://en.cppreference.com/w/cpp/compiler_support -// and not tested. -#ifndef EIGEN_HAS_CXX17_OVERALIGN -#if EIGEN_MAX_CPP_VER>=17 && EIGEN_COMP_CXXVER>=17 && ( \ - (EIGEN_COMP_MSVC >= 1912) \ - || (EIGEN_GNUC_AT_LEAST(7,0)) \ - || ((!defined(__apple_build_version__)) && (EIGEN_COMP_CLANG>=500)) \ - || (( defined(__apple_build_version__)) && (__apple_build_version__>=10000000)) \ - ) -#define EIGEN_HAS_CXX17_OVERALIGN 1 -#else -#define EIGEN_HAS_CXX17_OVERALIGN 0 -#endif -#endif - -#if defined(EIGEN_CUDACC) && EIGEN_HAS_CONSTEXPR - // While available already with c++11, this is useful mostly starting with c++14 and relaxed constexpr rules - #if defined(__NVCC__) - // nvcc considers constexpr functions as __host__ __device__ with the option --expt-relaxed-constexpr - #ifdef __CUDACC_RELAXED_CONSTEXPR__ - #define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC - #endif - #elif defined(__clang__) && defined(__CUDA__) && __has_feature(cxx_relaxed_constexpr) - // clang++ always considers constexpr functions as implicitly __host__ __device__ - #define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC - #endif -#endif - -// Does the compiler support the __int128 and __uint128_t extensions for 128-bit -// integer arithmetic? -// -// Clang and GCC define __SIZEOF_INT128__ when these extensions are supported, -// but we avoid using them in certain cases: -// -// * Building using Clang for Windows, where the Clang runtime library has -// 128-bit support only on LP64 architectures, but Windows is LLP64. -#ifndef EIGEN_HAS_BUILTIN_INT128 -#if defined(__SIZEOF_INT128__) && !(EIGEN_OS_WIN && EIGEN_COMP_CLANG) -#define EIGEN_HAS_BUILTIN_INT128 1 -#else -#define EIGEN_HAS_BUILTIN_INT128 0 -#endif -#endif - -//------------------------------------------------------------------------------------------ -// Preprocessor programming helpers -//------------------------------------------------------------------------------------------ - -// This macro can be used to prevent from macro expansion, e.g.: -// std::max EIGEN_NOT_A_MACRO(a,b) -#define EIGEN_NOT_A_MACRO - -#define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl; - -// concatenate two tokens -#define EIGEN_CAT2(a,b) a ## b -#define EIGEN_CAT(a,b) EIGEN_CAT2(a,b) - -#define EIGEN_COMMA , - -// convert a token to a string -#define EIGEN_MAKESTRING2(a) #a -#define EIGEN_MAKESTRING(a) EIGEN_MAKESTRING2(a) - -// EIGEN_STRONG_INLINE is a stronger version of the inline, using __forceinline on MSVC, -// but it still doesn't use GCC's always_inline. This is useful in (common) situations where MSVC needs forceinline -// but GCC is still doing fine with just inline. -#ifndef EIGEN_STRONG_INLINE -#if EIGEN_COMP_MSVC || EIGEN_COMP_ICC -#define EIGEN_STRONG_INLINE __forceinline -#else -#define EIGEN_STRONG_INLINE inline -#endif -#endif - -// EIGEN_ALWAYS_INLINE is the stronget, it has the effect of making the function inline and adding every possible -// attribute to maximize inlining. This should only be used when really necessary: in particular, -// it uses __attribute__((always_inline)) on GCC, which most of the time is useless and can severely harm compile times. -// FIXME with the always_inline attribute, -// gcc 3.4.x and 4.1 reports the following compilation error: -// Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const' -// : function body not available -// See also bug 1367 -#if EIGEN_GNUC_AT_LEAST(4,2) && !defined(SYCL_DEVICE_ONLY) -#define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) inline -#else -#define EIGEN_ALWAYS_INLINE EIGEN_STRONG_INLINE -#endif - -#if EIGEN_COMP_GNUC -#define EIGEN_DONT_INLINE __attribute__((noinline)) -#elif EIGEN_COMP_MSVC -#define EIGEN_DONT_INLINE __declspec(noinline) -#else -#define EIGEN_DONT_INLINE -#endif - -#if EIGEN_COMP_GNUC -#define EIGEN_PERMISSIVE_EXPR __extension__ -#else -#define EIGEN_PERMISSIVE_EXPR -#endif - -// GPU stuff - -// Disable some features when compiling with GPU compilers (NVCC/clang-cuda/SYCL/HIPCC) -#if defined(EIGEN_CUDACC) || defined(SYCL_DEVICE_ONLY) || defined(EIGEN_HIPCC) - // Do not try asserts on device code - #ifndef EIGEN_NO_DEBUG - #define EIGEN_NO_DEBUG - #endif - - #ifdef EIGEN_INTERNAL_DEBUGGING - #undef EIGEN_INTERNAL_DEBUGGING - #endif - - #ifdef EIGEN_EXCEPTIONS - #undef EIGEN_EXCEPTIONS - #endif -#endif - -#if defined(SYCL_DEVICE_ONLY) - #ifndef EIGEN_DONT_VECTORIZE - #define EIGEN_DONT_VECTORIZE - #endif - #define EIGEN_DEVICE_FUNC __attribute__((flatten)) __attribute__((always_inline)) -// All functions callable from CUDA/HIP code must be qualified with __device__ -#elif defined(EIGEN_GPUCC) - #define EIGEN_DEVICE_FUNC __host__ __device__ -#else - #define EIGEN_DEVICE_FUNC -#endif - - -// this macro allows to get rid of linking errors about multiply defined functions. -// - static is not very good because it prevents definitions from different object files to be merged. -// So static causes the resulting linked executable to be bloated with multiple copies of the same function. -// - inline is not perfect either as it unwantedly hints the compiler toward inlining the function. -#define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC -#define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC inline - -#ifdef NDEBUG -# ifndef EIGEN_NO_DEBUG -# define EIGEN_NO_DEBUG -# endif -#endif - -// eigen_plain_assert is where we implement the workaround for the assert() bug in GCC <= 4.3, see bug 89 -#ifdef EIGEN_NO_DEBUG - #ifdef SYCL_DEVICE_ONLY // used to silence the warning on SYCL device - #define eigen_plain_assert(x) EIGEN_UNUSED_VARIABLE(x) - #else - #define eigen_plain_assert(x) - #endif -#else - #if EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO - namespace Eigen { - namespace internal { - inline bool copy_bool(bool b) { return b; } - } - } - #define eigen_plain_assert(x) assert(x) - #else - // work around bug 89 - #include <cstdlib> // for abort - #include <iostream> // for std::cerr - - namespace Eigen { - namespace internal { - // trivial function copying a bool. Must be EIGEN_DONT_INLINE, so we implement it after including Eigen headers. - // see bug 89. - namespace { - EIGEN_DONT_INLINE bool copy_bool(bool b) { return b; } - } - inline void assert_fail(const char *condition, const char *function, const char *file, int line) - { - std::cerr << "assertion failed: " << condition << " in function " << function << " at " << file << ":" << line << std::endl; - abort(); - } - } - } - #define eigen_plain_assert(x) \ - do { \ - if(!Eigen::internal::copy_bool(x)) \ - Eigen::internal::assert_fail(EIGEN_MAKESTRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__); \ - } while(false) - #endif -#endif - -// eigen_assert can be overridden -#ifndef eigen_assert -#define eigen_assert(x) eigen_plain_assert(x) -#endif - -#ifdef EIGEN_INTERNAL_DEBUGGING -#define eigen_internal_assert(x) eigen_assert(x) -#else -#define eigen_internal_assert(x) -#endif - -#ifdef EIGEN_NO_DEBUG -#define EIGEN_ONLY_USED_FOR_DEBUG(x) EIGEN_UNUSED_VARIABLE(x) -#else -#define EIGEN_ONLY_USED_FOR_DEBUG(x) -#endif - -#ifndef EIGEN_NO_DEPRECATED_WARNING - #if EIGEN_COMP_GNUC - #define EIGEN_DEPRECATED __attribute__((deprecated)) - #elif EIGEN_COMP_MSVC - #define EIGEN_DEPRECATED __declspec(deprecated) - #else - #define EIGEN_DEPRECATED - #endif -#else - #define EIGEN_DEPRECATED -#endif - -#if EIGEN_COMP_GNUC -#define EIGEN_UNUSED __attribute__((unused)) -#else -#define EIGEN_UNUSED -#endif - -// Suppresses 'unused variable' warnings. -namespace Eigen { - namespace internal { - template<typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ignore_unused_variable(const T&) {} - } -} -#define EIGEN_UNUSED_VARIABLE(var) Eigen::internal::ignore_unused_variable(var); - -#if !defined(EIGEN_ASM_COMMENT) - #if EIGEN_COMP_GNUC && (EIGEN_ARCH_i386_OR_x86_64 || EIGEN_ARCH_ARM_OR_ARM64) - #define EIGEN_ASM_COMMENT(X) __asm__("#" X) - #else - #define EIGEN_ASM_COMMENT(X) - #endif -#endif - - -#if EIGEN_COMP_MSVC - // NOTE MSVC often gives C4127 warnings with compiletime if statements. See bug 1362. - // This workaround is ugly, but it does the job. -# define EIGEN_CONST_CONDITIONAL(cond) (void)0, cond -#else -# define EIGEN_CONST_CONDITIONAL(cond) cond -#endif - -#ifdef EIGEN_DONT_USE_RESTRICT_KEYWORD - #define EIGEN_RESTRICT -#endif -#ifndef EIGEN_RESTRICT - #define EIGEN_RESTRICT __restrict -#endif - - -#ifndef EIGEN_DEFAULT_IO_FORMAT -#ifdef EIGEN_MAKING_DOCS -// format used in Eigen's documentation -// needed to define it here as escaping characters in CMake add_definition's argument seems very problematic. -#define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(3, 0, " ", "\n", "", "") -#else -#define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat() -#endif -#endif - -// just an empty macro ! -#define EIGEN_EMPTY - - -// When compiling CUDA/HIP device code with NVCC or HIPCC -// pull in math functions from the global namespace. -// In host mode, and when device code is compiled with clang, -// use the std versions. -#if (defined(EIGEN_CUDA_ARCH) && defined(__NVCC__)) || defined(EIGEN_HIP_DEVICE_COMPILE) - #define EIGEN_USING_STD_MATH(FUNC) using ::FUNC; -#else - #define EIGEN_USING_STD_MATH(FUNC) using std::FUNC; -#endif - - -// When compiling HIP device code with HIPCC, certain functions -// from the stdlib need to be pulled in from the global namespace -// (as opposed to from the std:: namespace). This is because HIPCC -// does not natively support all the std:: routines in device code. -// Instead it contains header files that declare the corresponding -// routines in the global namespace such they can be used in device code. -#if defined(EIGEN_HIP_DEVICE_COMPILE) - #define EIGEN_USING_STD(FUNC) using ::FUNC; -#else - #define EIGEN_USING_STD(FUNC) using std::FUNC; -#endif - - -#if EIGEN_COMP_MSVC_STRICT && (EIGEN_COMP_MSVC < 1900 || EIGEN_COMP_NVCC) - // for older MSVC versions, as well as 1900 && CUDA 8, using the base operator is sufficient (cf Bugs 1000, 1324) - #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \ - using Base::operator =; -#elif EIGEN_COMP_CLANG // workaround clang bug (see http://forum.kde.org/viewtopic.php?f=74&t=102653) - #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \ - using Base::operator =; \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \ - template <typename OtherDerived> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const DenseBase<OtherDerived>& other) { Base::operator=(other.derived()); return *this; } -#else - #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \ - using Base::operator =; \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \ - { \ - Base::operator=(other); \ - return *this; \ - } -#endif - - -/** - * \internal - * \brief Macro to explicitly define the default copy constructor. - * This is necessary, because the implicit definition is deprecated if the copy-assignment is overridden. - */ -#if EIGEN_HAS_CXX11 -#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS) EIGEN_DEVICE_FUNC CLASS(const CLASS&) = default; -#else -#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS) -#endif - - - -/** \internal - * \brief Macro to manually inherit assignment operators. - * This is necessary, because the implicitly defined assignment operator gets deleted when a custom operator= is defined. - * With C++11 or later this also default-implements the copy-constructor - */ -#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ - EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \ - EIGEN_DEFAULT_COPY_CONSTRUCTOR(Derived) - -/** \internal - * \brief Macro to manually define default constructors and destructors. - * This is necessary when the copy constructor is re-defined. - * For empty helper classes this should usually be protected, to avoid accidentally creating empty objects. - * - * Hiding the default destructor lead to problems in C++03 mode together with boost::multiprecision - */ -#if EIGEN_HAS_CXX11 -#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived) \ - EIGEN_DEVICE_FUNC Derived() = default; \ - EIGEN_DEVICE_FUNC ~Derived() = default; -#else -#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived) \ - EIGEN_DEVICE_FUNC Derived() {}; \ - /* EIGEN_DEVICE_FUNC ~Derived() {}; */ -#endif - - - - - -/** -* Just a side note. Commenting within defines works only by documenting -* behind the object (via '!<'). Comments cannot be multi-line and thus -* we have these extra long lines. What is confusing doxygen over here is -* that we use '\' and basically have a bunch of typedefs with their -* documentation in a single line. -**/ - -#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ - typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; /*!< \brief Numeric type, e.g. float, double, int or std::complex<float>. */ \ - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; /*!< \brief The underlying numeric type for composed scalar types. \details In cases where Scalar is e.g. std::complex<T>, T were corresponding to RealScalar. */ \ - typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ \ - typedef typename Eigen::internal::ref_selector<Derived>::type Nested; \ - typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \ - typedef typename Eigen::internal::traits<Derived>::StorageIndex StorageIndex; \ - enum CompileTimeTraits \ - { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \ - ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \ - Flags = Eigen::internal::traits<Derived>::Flags, \ - SizeAtCompileTime = Base::SizeAtCompileTime, \ - MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ - IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \ - using Base::derived; \ - using Base::const_cast_derived; - - -// FIXME Maybe the EIGEN_DENSE_PUBLIC_INTERFACE could be removed as importing PacketScalar is rarely needed -#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \ - EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ - typedef typename Base::PacketScalar PacketScalar; - - -#define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) -#define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b) - -// EIGEN_SIZE_MIN_PREFER_DYNAMIC gives the min between compile-time sizes. 0 has absolute priority, followed by 1, -// followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over -// finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3. -#define EIGEN_SIZE_MIN_PREFER_DYNAMIC(a,b) (((int)a == 0 || (int)b == 0) ? 0 \ - : ((int)a == 1 || (int)b == 1) ? 1 \ - : ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \ - : ((int)a <= (int)b) ? (int)a : (int)b) - -// EIGEN_SIZE_MIN_PREFER_FIXED is a variant of EIGEN_SIZE_MIN_PREFER_DYNAMIC comparing MaxSizes. The difference is that finite values -// now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is -// (between 0 and 3), it is not more than 3. -#define EIGEN_SIZE_MIN_PREFER_FIXED(a,b) (((int)a == 0 || (int)b == 0) ? 0 \ - : ((int)a == 1 || (int)b == 1) ? 1 \ - : ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \ - : ((int)a == Dynamic) ? (int)b \ - : ((int)b == Dynamic) ? (int)a \ - : ((int)a <= (int)b) ? (int)a : (int)b) - -// see EIGEN_SIZE_MIN_PREFER_DYNAMIC. No need for a separate variant for MaxSizes here. -#define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \ - : ((int)a >= (int)b) ? (int)a : (int)b) - -#define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b))) - -#define EIGEN_IMPLIES(a,b) (!(a) || (b)) - -#if EIGEN_HAS_BUILTIN(__builtin_expect) || EIGEN_COMP_GNUC -#define EIGEN_PREDICT_FALSE(x) (__builtin_expect(x, false)) -#define EIGEN_PREDICT_TRUE(x) (__builtin_expect(false || (x), true)) -#else -#define EIGEN_PREDICT_FALSE(x) (x) -#define EIGEN_PREDICT_TRUE(x) (x) -#endif - -// the expression type of a standard coefficient wise binary operation -#define EIGEN_CWISE_BINARY_RETURN_TYPE(LHS,RHS,OPNAME) \ - CwiseBinaryOp< \ - EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)< \ - typename internal::traits<LHS>::Scalar, \ - typename internal::traits<RHS>::Scalar \ - >, \ - const LHS, \ - const RHS \ - > - -#define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,OPNAME) \ - template<typename OtherDerived> \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,OPNAME) \ - (METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \ - { \ - return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,OPNAME)(derived(), other.derived()); \ - } - -#define EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,TYPEA,TYPEB) \ - (Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<TYPEA,TYPEB,EIGEN_CAT(EIGEN_CAT(Eigen::internal::scalar_,OPNAME),_op)<TYPEA,TYPEB> > >::value) - -#define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR,SCALAR,OPNAME) \ - CwiseBinaryOp<EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)<typename internal::traits<EXPR>::Scalar,SCALAR>, const EXPR, \ - const typename internal::plain_constant_type<EXPR,SCALAR>::type> - -#define EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(SCALAR,EXPR,OPNAME) \ - CwiseBinaryOp<EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)<SCALAR,typename internal::traits<EXPR>::Scalar>, \ - const typename internal::plain_constant_type<EXPR,SCALAR>::type, const EXPR> - -// Workaround for MSVC 2010 (see ML thread "patch with compile for for MSVC 2010") -#if EIGEN_COMP_MSVC_STRICT && (EIGEN_COMP_MSVC_STRICT<=1600) -#define EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(X) typename internal::enable_if<true,X>::type -#else -#define EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(X) X -#endif - -#define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD,OPNAME) \ - template <typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \ - EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<Scalar EIGEN_COMMA T EIGEN_COMMA EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,Scalar,T)>::type,OPNAME))\ - (METHOD)(const T& scalar) const { \ - typedef typename internal::promote_scalar_arg<Scalar,T,EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,Scalar,T)>::type PromotedT; \ - return EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,PromotedT,OPNAME)(derived(), \ - typename internal::plain_constant_type<Derived,PromotedT>::type(derived().rows(), derived().cols(), internal::scalar_constant_op<PromotedT>(scalar))); \ - } - -#define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \ - template <typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend \ - EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<Scalar EIGEN_COMMA T EIGEN_COMMA EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,T,Scalar)>::type,Derived,OPNAME)) \ - (METHOD)(const T& scalar, const StorageBaseType& matrix) { \ - typedef typename internal::promote_scalar_arg<Scalar,T,EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,T,Scalar)>::type PromotedT; \ - return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedT,Derived,OPNAME)( \ - typename internal::plain_constant_type<Derived,PromotedT>::type(matrix.derived().rows(), matrix.derived().cols(), internal::scalar_constant_op<PromotedT>(scalar)), matrix.derived()); \ - } - -#define EIGEN_MAKE_SCALAR_BINARY_OP(METHOD,OPNAME) \ - EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \ - EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD,OPNAME) - - -#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(EIGEN_CUDA_ARCH) && !defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_USE_SYCL) && !defined(EIGEN_HIP_DEVICE_COMPILE) - #define EIGEN_EXCEPTIONS -#endif - - -#ifdef EIGEN_EXCEPTIONS -# define EIGEN_THROW_X(X) throw X -# define EIGEN_THROW throw -# define EIGEN_TRY try -# define EIGEN_CATCH(X) catch (X) -#else -# if defined(EIGEN_CUDA_ARCH) -# define EIGEN_THROW_X(X) asm("trap;") -# define EIGEN_THROW asm("trap;") -# elif defined(EIGEN_HIP_DEVICE_COMPILE) -# define EIGEN_THROW_X(X) asm("s_trap 0") -# define EIGEN_THROW asm("s_trap 0") -# else -# define EIGEN_THROW_X(X) std::abort() -# define EIGEN_THROW std::abort() -# endif -# define EIGEN_TRY if (true) -# define EIGEN_CATCH(X) else -#endif - - -#if EIGEN_HAS_CXX11_NOEXCEPT -# define EIGEN_INCLUDE_TYPE_TRAITS -# define EIGEN_NOEXCEPT noexcept -# define EIGEN_NOEXCEPT_IF(x) noexcept(x) -# define EIGEN_NO_THROW noexcept(true) -# define EIGEN_EXCEPTION_SPEC(X) noexcept(false) -#else -# define EIGEN_NOEXCEPT -# define EIGEN_NOEXCEPT_IF(x) -# define EIGEN_NO_THROW throw() -# if EIGEN_COMP_MSVC || EIGEN_COMP_CXXVER>=17 - // MSVC does not support exception specifications (warning C4290), - // and they are deprecated in c++11 anyway. This is even an error in c++17. -# define EIGEN_EXCEPTION_SPEC(X) throw() -# else -# define EIGEN_EXCEPTION_SPEC(X) throw(X) -# endif -#endif - -#if EIGEN_HAS_VARIADIC_TEMPLATES -// The all function is used to enable a variadic version of eigen_assert which can take a parameter pack as its input. -namespace Eigen { -namespace internal { - -inline bool all(){ return true; } - -template<typename T, typename ...Ts> -bool all(T t, Ts ... ts){ return t && all(ts...); } - -} -} -#endif - -#if EIGEN_HAS_CXX11_OVERRIDE_FINAL -// provide override and final specifiers if they are available: -# define EIGEN_OVERRIDE override -# define EIGEN_FINAL final -#else -# define EIGEN_OVERRIDE -# define EIGEN_FINAL -#endif - -// Wrapping #pragma unroll in a macro since it is required for SYCL -#if defined(SYCL_DEVICE_ONLY) - #if defined(_MSC_VER) - #define EIGEN_UNROLL_LOOP __pragma(unroll) - #else - #define EIGEN_UNROLL_LOOP _Pragma("unroll") - #endif -#else - #define EIGEN_UNROLL_LOOP -#endif - -#endif // EIGEN_MACROS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/Memory.h b/external/eigen/include/eigen3/Eigen/src/Core/util/Memory.h deleted file mode 100644 index 1b12544d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/Memory.h +++ /dev/null @@ -1,1126 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2008-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009 Kenneth Riddile <kfriddile@yahoo.com> -// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com> -// Copyright (C) 2010 Thomas Capricelli <orzel@freehackers.org> -// Copyright (C) 2013 Pavel Holoborodko <pavel@holoborodko.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -/***************************************************************************** -*** Platform checks for aligned malloc functions *** -*****************************************************************************/ - -#ifndef EIGEN_MEMORY_H -#define EIGEN_MEMORY_H - -#ifndef EIGEN_MALLOC_ALREADY_ALIGNED - -// Try to determine automatically if malloc is already aligned. - -// On 64-bit systems, glibc's malloc returns 16-byte-aligned pointers, see: -// http://www.gnu.org/s/libc/manual/html_node/Aligned-Memory-Blocks.html -// This is true at least since glibc 2.8. -// This leaves the question how to detect 64-bit. According to this document, -// http://gcc.fyxm.net/summit/2003/Porting%20to%2064%20bit.pdf -// page 114, "[The] LP64 model [...] is used by all 64-bit UNIX ports" so it's indeed -// quite safe, at least within the context of glibc, to equate 64-bit with LP64. -#if defined(__GLIBC__) && ((__GLIBC__>=2 && __GLIBC_MINOR__ >= 8) || __GLIBC__>2) \ - && defined(__LP64__) && ! defined( __SANITIZE_ADDRESS__ ) && (EIGEN_DEFAULT_ALIGN_BYTES == 16) - #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 1 -#else - #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 0 -#endif - -// FreeBSD 6 seems to have 16-byte aligned malloc -// See http://svn.freebsd.org/viewvc/base/stable/6/lib/libc/stdlib/malloc.c?view=markup -// FreeBSD 7 seems to have 16-byte aligned malloc except on ARM and MIPS architectures -// See http://svn.freebsd.org/viewvc/base/stable/7/lib/libc/stdlib/malloc.c?view=markup -#if defined(__FreeBSD__) && !(EIGEN_ARCH_ARM || EIGEN_ARCH_MIPS) && (EIGEN_DEFAULT_ALIGN_BYTES == 16) - #define EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED 1 -#else - #define EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED 0 -#endif - -#if (EIGEN_OS_MAC && (EIGEN_DEFAULT_ALIGN_BYTES == 16)) \ - || (EIGEN_OS_WIN64 && (EIGEN_DEFAULT_ALIGN_BYTES == 16)) \ - || EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED \ - || EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED - #define EIGEN_MALLOC_ALREADY_ALIGNED 1 -#else - #define EIGEN_MALLOC_ALREADY_ALIGNED 0 -#endif - -#endif - -namespace Eigen { - -namespace internal { - -EIGEN_DEVICE_FUNC -inline void throw_std_bad_alloc() -{ - #ifdef EIGEN_EXCEPTIONS - throw std::bad_alloc(); - #else - std::size_t huge = static_cast<std::size_t>(-1); - #if defined(EIGEN_HIPCC) - // - // calls to "::operator new" are to be treated as opaque function calls (i.e no inlining), - // and as a consequence the code in the #else block triggers the hipcc warning : - // "no overloaded function has restriction specifiers that are compatible with the ambient context" - // - // "throw_std_bad_alloc" has the EIGEN_DEVICE_FUNC attribute, so it seems that hipcc expects - // the same on "operator new" - // Reverting code back to the old version in this #if block for the hipcc compiler - // - new int[huge]; - #else - ::operator new(huge); - #endif - #endif -} - -/***************************************************************************** -*** Implementation of handmade aligned functions *** -*****************************************************************************/ - -/* ----- Hand made implementations of aligned malloc/free and realloc ----- */ - -/** \internal Like malloc, but the returned pointer is guaranteed to be 16-byte aligned. - * Fast, but wastes 16 additional bytes of memory. Does not throw any exception. - */ -EIGEN_DEVICE_FUNC inline void* handmade_aligned_malloc(std::size_t size, std::size_t alignment = EIGEN_DEFAULT_ALIGN_BYTES) -{ - eigen_assert(alignment >= sizeof(void*) && (alignment & (alignment-1)) == 0 && "Alignment must be at least sizeof(void*) and a power of 2"); - - EIGEN_USING_STD(malloc) - void *original = malloc(size+alignment); - - if (original == 0) return 0; - void *aligned = reinterpret_cast<void*>((reinterpret_cast<std::size_t>(original) & ~(std::size_t(alignment-1))) + alignment); - *(reinterpret_cast<void**>(aligned) - 1) = original; - return aligned; -} - -/** \internal Frees memory allocated with handmade_aligned_malloc */ -EIGEN_DEVICE_FUNC inline void handmade_aligned_free(void *ptr) -{ - if (ptr) { - EIGEN_USING_STD(free) - free(*(reinterpret_cast<void**>(ptr) - 1)); - } -} - -/** \internal - * \brief Reallocates aligned memory. - * Since we know that our handmade version is based on std::malloc - * we can use std::realloc to implement efficient reallocation. - */ -inline void* handmade_aligned_realloc(void* ptr, std::size_t size, std::size_t = 0) -{ - if (ptr == 0) return handmade_aligned_malloc(size); - void *original = *(reinterpret_cast<void**>(ptr) - 1); - std::ptrdiff_t previous_offset = static_cast<char *>(ptr)-static_cast<char *>(original); - original = std::realloc(original,size+EIGEN_DEFAULT_ALIGN_BYTES); - if (original == 0) return 0; - void *aligned = reinterpret_cast<void*>((reinterpret_cast<std::size_t>(original) & ~(std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1))) + EIGEN_DEFAULT_ALIGN_BYTES); - void *previous_aligned = static_cast<char *>(original)+previous_offset; - if(aligned!=previous_aligned) - std::memmove(aligned, previous_aligned, size); - - *(reinterpret_cast<void**>(aligned) - 1) = original; - return aligned; -} - -/***************************************************************************** -*** Implementation of portable aligned versions of malloc/free/realloc *** -*****************************************************************************/ - -#ifdef EIGEN_NO_MALLOC -EIGEN_DEVICE_FUNC inline void check_that_malloc_is_allowed() -{ - eigen_assert(false && "heap allocation is forbidden (EIGEN_NO_MALLOC is defined)"); -} -#elif defined EIGEN_RUNTIME_NO_MALLOC -EIGEN_DEVICE_FUNC inline bool is_malloc_allowed_impl(bool update, bool new_value = false) -{ - static bool value = true; - if (update == 1) - value = new_value; - return value; -} -EIGEN_DEVICE_FUNC inline bool is_malloc_allowed() { return is_malloc_allowed_impl(false); } -EIGEN_DEVICE_FUNC inline bool set_is_malloc_allowed(bool new_value) { return is_malloc_allowed_impl(true, new_value); } -EIGEN_DEVICE_FUNC inline void check_that_malloc_is_allowed() -{ - eigen_assert(is_malloc_allowed() && "heap allocation is forbidden (EIGEN_RUNTIME_NO_MALLOC is defined and g_is_malloc_allowed is false)"); -} -#else -EIGEN_DEVICE_FUNC inline void check_that_malloc_is_allowed() -{} -#endif - -/** \internal Allocates \a size bytes. The returned pointer is guaranteed to have 16 or 32 bytes alignment depending on the requirements. - * On allocation error, the returned pointer is null, and std::bad_alloc is thrown. - */ -EIGEN_DEVICE_FUNC inline void* aligned_malloc(std::size_t size) -{ - check_that_malloc_is_allowed(); - - void *result; - #if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED - - EIGEN_USING_STD(malloc) - result = malloc(size); - - #if EIGEN_DEFAULT_ALIGN_BYTES==16 - eigen_assert((size<16 || (std::size_t(result)%16)==0) && "System's malloc returned an unaligned pointer. Compile with EIGEN_MALLOC_ALREADY_ALIGNED=0 to fallback to handmade aligned memory allocator."); - #endif - #else - result = handmade_aligned_malloc(size); - #endif - - if(!result && size) - throw_std_bad_alloc(); - - return result; -} - -/** \internal Frees memory allocated with aligned_malloc. */ -EIGEN_DEVICE_FUNC inline void aligned_free(void *ptr) -{ - #if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED - - EIGEN_USING_STD(free) - free(ptr); - - #else - handmade_aligned_free(ptr); - #endif -} - -/** - * \internal - * \brief Reallocates an aligned block of memory. - * \throws std::bad_alloc on allocation failure - */ -inline void* aligned_realloc(void *ptr, std::size_t new_size, std::size_t old_size) -{ - EIGEN_UNUSED_VARIABLE(old_size); - - void *result; -#if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED - result = std::realloc(ptr,new_size); -#else - result = handmade_aligned_realloc(ptr,new_size,old_size); -#endif - - if (!result && new_size) - throw_std_bad_alloc(); - - return result; -} - -/***************************************************************************** -*** Implementation of conditionally aligned functions *** -*****************************************************************************/ - -/** \internal Allocates \a size bytes. If Align is true, then the returned ptr is 16-byte-aligned. - * On allocation error, the returned pointer is null, and a std::bad_alloc is thrown. - */ -template<bool Align> EIGEN_DEVICE_FUNC inline void* conditional_aligned_malloc(std::size_t size) -{ - return aligned_malloc(size); -} - -template<> EIGEN_DEVICE_FUNC inline void* conditional_aligned_malloc<false>(std::size_t size) -{ - check_that_malloc_is_allowed(); - - EIGEN_USING_STD(malloc) - void *result = malloc(size); - - if(!result && size) - throw_std_bad_alloc(); - return result; -} - -/** \internal Frees memory allocated with conditional_aligned_malloc */ -template<bool Align> EIGEN_DEVICE_FUNC inline void conditional_aligned_free(void *ptr) -{ - aligned_free(ptr); -} - -template<> EIGEN_DEVICE_FUNC inline void conditional_aligned_free<false>(void *ptr) -{ - EIGEN_USING_STD(free) - free(ptr); -} - -template<bool Align> inline void* conditional_aligned_realloc(void* ptr, std::size_t new_size, std::size_t old_size) -{ - return aligned_realloc(ptr, new_size, old_size); -} - -template<> inline void* conditional_aligned_realloc<false>(void* ptr, std::size_t new_size, std::size_t) -{ - return std::realloc(ptr, new_size); -} - -/***************************************************************************** -*** Construction/destruction of array elements *** -*****************************************************************************/ - -/** \internal Destructs the elements of an array. - * The \a size parameters tells on how many objects to call the destructor of T. - */ -template<typename T> EIGEN_DEVICE_FUNC inline void destruct_elements_of_array(T *ptr, std::size_t size) -{ - // always destruct an array starting from the end. - if(ptr) - while(size) ptr[--size].~T(); -} - -/** \internal Constructs the elements of an array. - * The \a size parameter tells on how many objects to call the constructor of T. - */ -template<typename T> EIGEN_DEVICE_FUNC inline T* construct_elements_of_array(T *ptr, std::size_t size) -{ - std::size_t i; - EIGEN_TRY - { - for (i = 0; i < size; ++i) ::new (ptr + i) T; - return ptr; - } - EIGEN_CATCH(...) - { - destruct_elements_of_array(ptr, i); - EIGEN_THROW; - } - return NULL; -} - -/***************************************************************************** -*** Implementation of aligned new/delete-like functions *** -*****************************************************************************/ - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void check_size_for_overflow(std::size_t size) -{ - if(size > std::size_t(-1) / sizeof(T)) - throw_std_bad_alloc(); -} - -/** \internal Allocates \a size objects of type T. The returned pointer is guaranteed to have 16 bytes alignment. - * On allocation error, the returned pointer is undefined, but a std::bad_alloc is thrown. - * The default constructor of T is called. - */ -template<typename T> EIGEN_DEVICE_FUNC inline T* aligned_new(std::size_t size) -{ - check_size_for_overflow<T>(size); - T *result = reinterpret_cast<T*>(aligned_malloc(sizeof(T)*size)); - EIGEN_TRY - { - return construct_elements_of_array(result, size); - } - EIGEN_CATCH(...) - { - aligned_free(result); - EIGEN_THROW; - } - return result; -} - -template<typename T, bool Align> EIGEN_DEVICE_FUNC inline T* conditional_aligned_new(std::size_t size) -{ - check_size_for_overflow<T>(size); - T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size)); - EIGEN_TRY - { - return construct_elements_of_array(result, size); - } - EIGEN_CATCH(...) - { - conditional_aligned_free<Align>(result); - EIGEN_THROW; - } - return result; -} - -/** \internal Deletes objects constructed with aligned_new - * The \a size parameters tells on how many objects to call the destructor of T. - */ -template<typename T> EIGEN_DEVICE_FUNC inline void aligned_delete(T *ptr, std::size_t size) -{ - destruct_elements_of_array<T>(ptr, size); - Eigen::internal::aligned_free(ptr); -} - -/** \internal Deletes objects constructed with conditional_aligned_new - * The \a size parameters tells on how many objects to call the destructor of T. - */ -template<typename T, bool Align> EIGEN_DEVICE_FUNC inline void conditional_aligned_delete(T *ptr, std::size_t size) -{ - destruct_elements_of_array<T>(ptr, size); - conditional_aligned_free<Align>(ptr); -} - -template<typename T, bool Align> EIGEN_DEVICE_FUNC inline T* conditional_aligned_realloc_new(T* pts, std::size_t new_size, std::size_t old_size) -{ - check_size_for_overflow<T>(new_size); - check_size_for_overflow<T>(old_size); - if(new_size < old_size) - destruct_elements_of_array(pts+new_size, old_size-new_size); - T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size)); - if(new_size > old_size) - { - EIGEN_TRY - { - construct_elements_of_array(result+old_size, new_size-old_size); - } - EIGEN_CATCH(...) - { - conditional_aligned_free<Align>(result); - EIGEN_THROW; - } - } - return result; -} - - -template<typename T, bool Align> EIGEN_DEVICE_FUNC inline T* conditional_aligned_new_auto(std::size_t size) -{ - if(size==0) - return 0; // short-cut. Also fixes Bug 884 - check_size_for_overflow<T>(size); - T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size)); - if(NumTraits<T>::RequireInitialization) - { - EIGEN_TRY - { - construct_elements_of_array(result, size); - } - EIGEN_CATCH(...) - { - conditional_aligned_free<Align>(result); - EIGEN_THROW; - } - } - return result; -} - -template<typename T, bool Align> inline T* conditional_aligned_realloc_new_auto(T* pts, std::size_t new_size, std::size_t old_size) -{ - check_size_for_overflow<T>(new_size); - check_size_for_overflow<T>(old_size); - if(NumTraits<T>::RequireInitialization && (new_size < old_size)) - destruct_elements_of_array(pts+new_size, old_size-new_size); - T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size)); - if(NumTraits<T>::RequireInitialization && (new_size > old_size)) - { - EIGEN_TRY - { - construct_elements_of_array(result+old_size, new_size-old_size); - } - EIGEN_CATCH(...) - { - conditional_aligned_free<Align>(result); - EIGEN_THROW; - } - } - return result; -} - -template<typename T, bool Align> EIGEN_DEVICE_FUNC inline void conditional_aligned_delete_auto(T *ptr, std::size_t size) -{ - if(NumTraits<T>::RequireInitialization) - destruct_elements_of_array<T>(ptr, size); - conditional_aligned_free<Align>(ptr); -} - -/****************************************************************************/ - -/** \internal Returns the index of the first element of the array that is well aligned with respect to the requested \a Alignment. - * - * \tparam Alignment requested alignment in Bytes. - * \param array the address of the start of the array - * \param size the size of the array - * - * \note If no element of the array is well aligned or the requested alignment is not a multiple of a scalar, - * the size of the array is returned. For example with SSE, the requested alignment is typically 16-bytes. If - * packet size for the given scalar type is 1, then everything is considered well-aligned. - * - * \note Otherwise, if the Alignment is larger that the scalar size, we rely on the assumptions that sizeof(Scalar) is a - * power of 2. On the other hand, we do not assume that the array address is a multiple of sizeof(Scalar), as that fails for - * example with Scalar=double on certain 32-bit platforms, see bug #79. - * - * There is also the variant first_aligned(const MatrixBase&) defined in DenseCoeffsBase.h. - * \sa first_default_aligned() - */ -template<int Alignment, typename Scalar, typename Index> -EIGEN_DEVICE_FUNC inline Index first_aligned(const Scalar* array, Index size) -{ - const Index ScalarSize = sizeof(Scalar); - const Index AlignmentSize = Alignment / ScalarSize; - const Index AlignmentMask = AlignmentSize-1; - - if(AlignmentSize<=1) - { - // Either the requested alignment if smaller than a scalar, or it exactly match a 1 scalar - // so that all elements of the array have the same alignment. - return 0; - } - else if( (UIntPtr(array) & (sizeof(Scalar)-1)) || (Alignment%ScalarSize)!=0) - { - // The array is not aligned to the size of a single scalar, or the requested alignment is not a multiple of the scalar size. - // Consequently, no element of the array is well aligned. - return size; - } - else - { - Index first = (AlignmentSize - (Index((UIntPtr(array)/sizeof(Scalar))) & AlignmentMask)) & AlignmentMask; - return (first < size) ? first : size; - } -} - -/** \internal Returns the index of the first element of the array that is well aligned with respect the largest packet requirement. - * \sa first_aligned(Scalar*,Index) and first_default_aligned(DenseBase<Derived>) */ -template<typename Scalar, typename Index> -EIGEN_DEVICE_FUNC inline Index first_default_aligned(const Scalar* array, Index size) -{ - typedef typename packet_traits<Scalar>::type DefaultPacketType; - return first_aligned<unpacket_traits<DefaultPacketType>::alignment>(array, size); -} - -/** \internal Returns the smallest integer multiple of \a base and greater or equal to \a size - */ -template<typename Index> -inline Index first_multiple(Index size, Index base) -{ - return ((size+base-1)/base)*base; -} - -// std::copy is much slower than memcpy, so let's introduce a smart_copy which -// use memcpy on trivial types, i.e., on types that does not require an initialization ctor. -template<typename T, bool UseMemcpy> struct smart_copy_helper; - -template<typename T> EIGEN_DEVICE_FUNC void smart_copy(const T* start, const T* end, T* target) -{ - smart_copy_helper<T,!NumTraits<T>::RequireInitialization>::run(start, end, target); -} - -template<typename T> struct smart_copy_helper<T,true> { - EIGEN_DEVICE_FUNC static inline void run(const T* start, const T* end, T* target) - { - IntPtr size = IntPtr(end)-IntPtr(start); - if(size==0) return; - eigen_internal_assert(start!=0 && end!=0 && target!=0); - EIGEN_USING_STD(memcpy) - memcpy(target, start, size); - } -}; - -template<typename T> struct smart_copy_helper<T,false> { - EIGEN_DEVICE_FUNC static inline void run(const T* start, const T* end, T* target) - { std::copy(start, end, target); } -}; - -// intelligent memmove. falls back to std::memmove for POD types, uses std::copy otherwise. -template<typename T, bool UseMemmove> struct smart_memmove_helper; - -template<typename T> void smart_memmove(const T* start, const T* end, T* target) -{ - smart_memmove_helper<T,!NumTraits<T>::RequireInitialization>::run(start, end, target); -} - -template<typename T> struct smart_memmove_helper<T,true> { - static inline void run(const T* start, const T* end, T* target) - { - IntPtr size = IntPtr(end)-IntPtr(start); - if(size==0) return; - eigen_internal_assert(start!=0 && end!=0 && target!=0); - std::memmove(target, start, size); - } -}; - -template<typename T> struct smart_memmove_helper<T,false> { - static inline void run(const T* start, const T* end, T* target) - { - if (UIntPtr(target) < UIntPtr(start)) - { - std::copy(start, end, target); - } - else - { - std::ptrdiff_t count = (std::ptrdiff_t(end)-std::ptrdiff_t(start)) / sizeof(T); - std::copy_backward(start, end, target + count); - } - } -}; - - -/***************************************************************************** -*** Implementation of runtime stack allocation (falling back to malloc) *** -*****************************************************************************/ - -// you can overwrite Eigen's default behavior regarding alloca by defining EIGEN_ALLOCA -// to the appropriate stack allocation function -#if ! defined EIGEN_ALLOCA && ! defined EIGEN_GPU_COMPILE_PHASE - #if EIGEN_OS_LINUX || EIGEN_OS_MAC || (defined alloca) - #define EIGEN_ALLOCA alloca - #elif EIGEN_COMP_MSVC - #define EIGEN_ALLOCA _alloca - #endif -#endif - -// With clang -Oz -mthumb, alloca changes the stack pointer in a way that is -// not allowed in Thumb2. -DEIGEN_STACK_ALLOCATION_LIMIT=0 doesn't work because -// the compiler still emits bad code because stack allocation checks use "<=". -// TODO: Eliminate after https://bugs.llvm.org/show_bug.cgi?id=23772 -// is fixed. -#if defined(__clang__) && defined(__thumb__) - #undef EIGEN_ALLOCA -#endif - -// This helper class construct the allocated memory, and takes care of destructing and freeing the handled data -// at destruction time. In practice this helper class is mainly useful to avoid memory leak in case of exceptions. -template<typename T> class aligned_stack_memory_handler : noncopyable -{ - public: - /* Creates a stack_memory_handler responsible for the buffer \a ptr of size \a size. - * Note that \a ptr can be 0 regardless of the other parameters. - * This constructor takes care of constructing/initializing the elements of the buffer if required by the scalar type T (see NumTraits<T>::RequireInitialization). - * In this case, the buffer elements will also be destructed when this handler will be destructed. - * Finally, if \a dealloc is true, then the pointer \a ptr is freed. - **/ - EIGEN_DEVICE_FUNC - aligned_stack_memory_handler(T* ptr, std::size_t size, bool dealloc) - : m_ptr(ptr), m_size(size), m_deallocate(dealloc) - { - if(NumTraits<T>::RequireInitialization && m_ptr) - Eigen::internal::construct_elements_of_array(m_ptr, size); - } - EIGEN_DEVICE_FUNC - ~aligned_stack_memory_handler() - { - if(NumTraits<T>::RequireInitialization && m_ptr) - Eigen::internal::destruct_elements_of_array<T>(m_ptr, m_size); - if(m_deallocate) - Eigen::internal::aligned_free(m_ptr); - } - protected: - T* m_ptr; - std::size_t m_size; - bool m_deallocate; -}; - -#ifdef EIGEN_ALLOCA - -template<typename Xpr, int NbEvaluations, - bool MapExternalBuffer = nested_eval<Xpr,NbEvaluations>::Evaluate && Xpr::MaxSizeAtCompileTime==Dynamic - > -struct local_nested_eval_wrapper -{ - static const bool NeedExternalBuffer = false; - typedef typename Xpr::Scalar Scalar; - typedef typename nested_eval<Xpr,NbEvaluations>::type ObjectType; - ObjectType object; - - EIGEN_DEVICE_FUNC - local_nested_eval_wrapper(const Xpr& xpr, Scalar* ptr) : object(xpr) - { - EIGEN_UNUSED_VARIABLE(ptr); - eigen_internal_assert(ptr==0); - } -}; - -template<typename Xpr, int NbEvaluations> -struct local_nested_eval_wrapper<Xpr,NbEvaluations,true> -{ - static const bool NeedExternalBuffer = true; - typedef typename Xpr::Scalar Scalar; - typedef typename plain_object_eval<Xpr>::type PlainObject; - typedef Map<PlainObject,EIGEN_DEFAULT_ALIGN_BYTES> ObjectType; - ObjectType object; - - EIGEN_DEVICE_FUNC - local_nested_eval_wrapper(const Xpr& xpr, Scalar* ptr) - : object(ptr==0 ? reinterpret_cast<Scalar*>(Eigen::internal::aligned_malloc(sizeof(Scalar)*xpr.size())) : ptr, xpr.rows(), xpr.cols()), - m_deallocate(ptr==0) - { - if(NumTraits<Scalar>::RequireInitialization && object.data()) - Eigen::internal::construct_elements_of_array(object.data(), object.size()); - object = xpr; - } - - EIGEN_DEVICE_FUNC - ~local_nested_eval_wrapper() - { - if(NumTraits<Scalar>::RequireInitialization && object.data()) - Eigen::internal::destruct_elements_of_array(object.data(), object.size()); - if(m_deallocate) - Eigen::internal::aligned_free(object.data()); - } - -private: - bool m_deallocate; -}; - -#endif // EIGEN_ALLOCA - -template<typename T> class scoped_array : noncopyable -{ - T* m_ptr; -public: - explicit scoped_array(std::ptrdiff_t size) - { - m_ptr = new T[size]; - } - ~scoped_array() - { - delete[] m_ptr; - } - T& operator[](std::ptrdiff_t i) { return m_ptr[i]; } - const T& operator[](std::ptrdiff_t i) const { return m_ptr[i]; } - T* &ptr() { return m_ptr; } - const T* ptr() const { return m_ptr; } - operator const T*() const { return m_ptr; } -}; - -template<typename T> void swap(scoped_array<T> &a,scoped_array<T> &b) -{ - std::swap(a.ptr(),b.ptr()); -} - -} // end namespace internal - -/** \internal - * - * The macro ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) declares, allocates, - * and construct an aligned buffer named NAME of SIZE elements of type TYPE on the stack - * if the size in bytes is smaller than EIGEN_STACK_ALLOCATION_LIMIT, and if stack allocation is supported by the platform - * (currently, this is Linux, OSX and Visual Studio only). Otherwise the memory is allocated on the heap. - * The allocated buffer is automatically deleted when exiting the scope of this declaration. - * If BUFFER is non null, then the declared variable is simply an alias for BUFFER, and no allocation/deletion occurs. - * Here is an example: - * \code - * { - * ei_declare_aligned_stack_constructed_variable(float,data,size,0); - * // use data[0] to data[size-1] - * } - * \endcode - * The underlying stack allocation function can controlled with the EIGEN_ALLOCA preprocessor token. - * - * The macro ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) is analogue to - * \code - * typename internal::nested_eval<XPRT_T,N>::type NAME(XPR); - * \endcode - * with the advantage of using aligned stack allocation even if the maximal size of XPR at compile time is unknown. - * This is accomplished through alloca if this later is supported and if the required number of bytes - * is below EIGEN_STACK_ALLOCATION_LIMIT. - */ -#ifdef EIGEN_ALLOCA - - #if EIGEN_DEFAULT_ALIGN_BYTES>0 - // We always manually re-align the result of EIGEN_ALLOCA. - // If alloca is already aligned, the compiler should be smart enough to optimize away the re-alignment. - #define EIGEN_ALIGNED_ALLOCA(SIZE) reinterpret_cast<void*>((internal::UIntPtr(EIGEN_ALLOCA(SIZE+EIGEN_DEFAULT_ALIGN_BYTES-1)) + EIGEN_DEFAULT_ALIGN_BYTES-1) & ~(std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1))) - #else - #define EIGEN_ALIGNED_ALLOCA(SIZE) EIGEN_ALLOCA(SIZE) - #endif - - #define ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) \ - Eigen::internal::check_size_for_overflow<TYPE>(SIZE); \ - TYPE* NAME = (BUFFER)!=0 ? (BUFFER) \ - : reinterpret_cast<TYPE*>( \ - (sizeof(TYPE)*SIZE<=EIGEN_STACK_ALLOCATION_LIMIT) ? EIGEN_ALIGNED_ALLOCA(sizeof(TYPE)*SIZE) \ - : Eigen::internal::aligned_malloc(sizeof(TYPE)*SIZE) ); \ - Eigen::internal::aligned_stack_memory_handler<TYPE> EIGEN_CAT(NAME,_stack_memory_destructor)((BUFFER)==0 ? NAME : 0,SIZE,sizeof(TYPE)*SIZE>EIGEN_STACK_ALLOCATION_LIMIT) - - - #define ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) \ - Eigen::internal::local_nested_eval_wrapper<XPR_T,N> EIGEN_CAT(NAME,_wrapper)(XPR, reinterpret_cast<typename XPR_T::Scalar*>( \ - ( (Eigen::internal::local_nested_eval_wrapper<XPR_T,N>::NeedExternalBuffer) && ((sizeof(typename XPR_T::Scalar)*XPR.size())<=EIGEN_STACK_ALLOCATION_LIMIT) ) \ - ? EIGEN_ALIGNED_ALLOCA( sizeof(typename XPR_T::Scalar)*XPR.size() ) : 0 ) ) ; \ - typename Eigen::internal::local_nested_eval_wrapper<XPR_T,N>::ObjectType NAME(EIGEN_CAT(NAME,_wrapper).object) - -#else - - #define ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) \ - Eigen::internal::check_size_for_overflow<TYPE>(SIZE); \ - TYPE* NAME = (BUFFER)!=0 ? BUFFER : reinterpret_cast<TYPE*>(Eigen::internal::aligned_malloc(sizeof(TYPE)*SIZE)); \ - Eigen::internal::aligned_stack_memory_handler<TYPE> EIGEN_CAT(NAME,_stack_memory_destructor)((BUFFER)==0 ? NAME : 0,SIZE,true) - - -#define ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) typename Eigen::internal::nested_eval<XPR_T,N>::type NAME(XPR) - -#endif - - -/***************************************************************************** -*** Implementation of EIGEN_MAKE_ALIGNED_OPERATOR_NEW [_IF] *** -*****************************************************************************/ - -#if EIGEN_HAS_CXX17_OVERALIGN - -// C++17 -> no need to bother about alignment anymore :) - -#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) -#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) -#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW -#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size) - -#else - -#if EIGEN_MAX_ALIGN_BYTES!=0 - #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \ - void* operator new(std::size_t size, const std::nothrow_t&) EIGEN_NO_THROW { \ - EIGEN_TRY { return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); } \ - EIGEN_CATCH (...) { return 0; } \ - } - #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \ - void *operator new(std::size_t size) { \ - return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \ - } \ - void *operator new[](std::size_t size) { \ - return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \ - } \ - void operator delete(void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \ - void operator delete[](void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \ - void operator delete(void * ptr, std::size_t /* sz */) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \ - void operator delete[](void * ptr, std::size_t /* sz */) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \ - /* in-place new and delete. since (at least afaik) there is no actual */ \ - /* memory allocated we can safely let the default implementation handle */ \ - /* this particular case. */ \ - static void *operator new(std::size_t size, void *ptr) { return ::operator new(size,ptr); } \ - static void *operator new[](std::size_t size, void* ptr) { return ::operator new[](size,ptr); } \ - void operator delete(void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete(memory,ptr); } \ - void operator delete[](void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete[](memory,ptr); } \ - /* nothrow-new (returns zero instead of std::bad_alloc) */ \ - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \ - void operator delete(void *ptr, const std::nothrow_t&) EIGEN_NO_THROW { \ - Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); \ - } \ - typedef void eigen_aligned_operator_new_marker_type; -#else - #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) -#endif - -#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(true) -#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size) \ - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(bool( \ - ((Size)!=Eigen::Dynamic) && \ - (((EIGEN_MAX_ALIGN_BYTES>=16) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES )==0)) || \ - ((EIGEN_MAX_ALIGN_BYTES>=32) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES/2)==0)) || \ - ((EIGEN_MAX_ALIGN_BYTES>=64) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES/4)==0)) ))) - -#endif - -/****************************************************************************/ - -/** \class aligned_allocator -* \ingroup Core_Module -* -* \brief STL compatible allocator to use with types requiring a non standrad alignment. -* -* The memory is aligned as for dynamically aligned matrix/array types such as MatrixXd. -* By default, it will thus provide at least 16 bytes alignment and more in following cases: -* - 32 bytes alignment if AVX is enabled. -* - 64 bytes alignment if AVX512 is enabled. -* -* This can be controlled using the \c EIGEN_MAX_ALIGN_BYTES macro as documented -* \link TopicPreprocessorDirectivesPerformance there \endlink. -* -* Example: -* \code -* // Matrix4f requires 16 bytes alignment: -* std::map< int, Matrix4f, std::less<int>, -* aligned_allocator<std::pair<const int, Matrix4f> > > my_map_mat4; -* // Vector3f does not require 16 bytes alignment, no need to use Eigen's allocator: -* std::map< int, Vector3f > my_map_vec3; -* \endcode -* -* \sa \blank \ref TopicStlContainers. -*/ -template<class T> -class aligned_allocator : public std::allocator<T> -{ -public: - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef T* pointer; - typedef const T* const_pointer; - typedef T& reference; - typedef const T& const_reference; - typedef T value_type; - - template<class U> - struct rebind - { - typedef aligned_allocator<U> other; - }; - - aligned_allocator() : std::allocator<T>() {} - - aligned_allocator(const aligned_allocator& other) : std::allocator<T>(other) {} - - template<class U> - aligned_allocator(const aligned_allocator<U>& other) : std::allocator<T>(other) {} - - ~aligned_allocator() {} - - #if EIGEN_COMP_GNUC_STRICT && EIGEN_GNUC_AT_LEAST(7,0) - // In gcc std::allocator::max_size() is bugged making gcc triggers a warning: - // eigen/Eigen/src/Core/util/Memory.h:189:12: warning: argument 1 value '18446744073709551612' exceeds maximum object size 9223372036854775807 - // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87544 - size_type max_size() const { - return (std::numeric_limits<std::ptrdiff_t>::max)()/sizeof(T); - } - #endif - - pointer allocate(size_type num, const void* /*hint*/ = 0) - { - internal::check_size_for_overflow<T>(num); - return static_cast<pointer>( internal::aligned_malloc(num * sizeof(T)) ); - } - - void deallocate(pointer p, size_type /*num*/) - { - internal::aligned_free(p); - } -}; - -//---------- Cache sizes ---------- - -#if !defined(EIGEN_NO_CPUID) -# if EIGEN_COMP_GNUC && EIGEN_ARCH_i386_OR_x86_64 -# if defined(__PIC__) && EIGEN_ARCH_i386 - // Case for x86 with PIC -# define EIGEN_CPUID(abcd,func,id) \ - __asm__ __volatile__ ("xchgl %%ebx, %k1;cpuid; xchgl %%ebx,%k1": "=a" (abcd[0]), "=&r" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func), "c" (id)); -# elif defined(__PIC__) && EIGEN_ARCH_x86_64 - // Case for x64 with PIC. In theory this is only a problem with recent gcc and with medium or large code model, not with the default small code model. - // However, we cannot detect which code model is used, and the xchg overhead is negligible anyway. -# define EIGEN_CPUID(abcd,func,id) \ - __asm__ __volatile__ ("xchg{q}\t{%%}rbx, %q1; cpuid; xchg{q}\t{%%}rbx, %q1": "=a" (abcd[0]), "=&r" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "0" (func), "2" (id)); -# else - // Case for x86_64 or x86 w/o PIC -# define EIGEN_CPUID(abcd,func,id) \ - __asm__ __volatile__ ("cpuid": "=a" (abcd[0]), "=b" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "0" (func), "2" (id) ); -# endif -# elif EIGEN_COMP_MSVC -# if (EIGEN_COMP_MSVC > 1500) && EIGEN_ARCH_i386_OR_x86_64 -# define EIGEN_CPUID(abcd,func,id) __cpuidex((int*)abcd,func,id) -# endif -# endif -#endif - -namespace internal { - -#ifdef EIGEN_CPUID - -inline bool cpuid_is_vendor(int abcd[4], const int vendor[3]) -{ - return abcd[1]==vendor[0] && abcd[3]==vendor[1] && abcd[2]==vendor[2]; -} - -inline void queryCacheSizes_intel_direct(int& l1, int& l2, int& l3) -{ - int abcd[4]; - l1 = l2 = l3 = 0; - int cache_id = 0; - int cache_type = 0; - do { - abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0; - EIGEN_CPUID(abcd,0x4,cache_id); - cache_type = (abcd[0] & 0x0F) >> 0; - if(cache_type==1||cache_type==3) // data or unified cache - { - int cache_level = (abcd[0] & 0xE0) >> 5; // A[7:5] - int ways = (abcd[1] & 0xFFC00000) >> 22; // B[31:22] - int partitions = (abcd[1] & 0x003FF000) >> 12; // B[21:12] - int line_size = (abcd[1] & 0x00000FFF) >> 0; // B[11:0] - int sets = (abcd[2]); // C[31:0] - - int cache_size = (ways+1) * (partitions+1) * (line_size+1) * (sets+1); - - switch(cache_level) - { - case 1: l1 = cache_size; break; - case 2: l2 = cache_size; break; - case 3: l3 = cache_size; break; - default: break; - } - } - cache_id++; - } while(cache_type>0 && cache_id<16); -} - -inline void queryCacheSizes_intel_codes(int& l1, int& l2, int& l3) -{ - int abcd[4]; - abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0; - l1 = l2 = l3 = 0; - EIGEN_CPUID(abcd,0x00000002,0); - unsigned char * bytes = reinterpret_cast<unsigned char *>(abcd)+2; - bool check_for_p2_core2 = false; - for(int i=0; i<14; ++i) - { - switch(bytes[i]) - { - case 0x0A: l1 = 8; break; // 0Ah data L1 cache, 8 KB, 2 ways, 32 byte lines - case 0x0C: l1 = 16; break; // 0Ch data L1 cache, 16 KB, 4 ways, 32 byte lines - case 0x0E: l1 = 24; break; // 0Eh data L1 cache, 24 KB, 6 ways, 64 byte lines - case 0x10: l1 = 16; break; // 10h data L1 cache, 16 KB, 4 ways, 32 byte lines (IA-64) - case 0x15: l1 = 16; break; // 15h code L1 cache, 16 KB, 4 ways, 32 byte lines (IA-64) - case 0x2C: l1 = 32; break; // 2Ch data L1 cache, 32 KB, 8 ways, 64 byte lines - case 0x30: l1 = 32; break; // 30h code L1 cache, 32 KB, 8 ways, 64 byte lines - case 0x60: l1 = 16; break; // 60h data L1 cache, 16 KB, 8 ways, 64 byte lines, sectored - case 0x66: l1 = 8; break; // 66h data L1 cache, 8 KB, 4 ways, 64 byte lines, sectored - case 0x67: l1 = 16; break; // 67h data L1 cache, 16 KB, 4 ways, 64 byte lines, sectored - case 0x68: l1 = 32; break; // 68h data L1 cache, 32 KB, 4 ways, 64 byte lines, sectored - case 0x1A: l2 = 96; break; // code and data L2 cache, 96 KB, 6 ways, 64 byte lines (IA-64) - case 0x22: l3 = 512; break; // code and data L3 cache, 512 KB, 4 ways (!), 64 byte lines, dual-sectored - case 0x23: l3 = 1024; break; // code and data L3 cache, 1024 KB, 8 ways, 64 byte lines, dual-sectored - case 0x25: l3 = 2048; break; // code and data L3 cache, 2048 KB, 8 ways, 64 byte lines, dual-sectored - case 0x29: l3 = 4096; break; // code and data L3 cache, 4096 KB, 8 ways, 64 byte lines, dual-sectored - case 0x39: l2 = 128; break; // code and data L2 cache, 128 KB, 4 ways, 64 byte lines, sectored - case 0x3A: l2 = 192; break; // code and data L2 cache, 192 KB, 6 ways, 64 byte lines, sectored - case 0x3B: l2 = 128; break; // code and data L2 cache, 128 KB, 2 ways, 64 byte lines, sectored - case 0x3C: l2 = 256; break; // code and data L2 cache, 256 KB, 4 ways, 64 byte lines, sectored - case 0x3D: l2 = 384; break; // code and data L2 cache, 384 KB, 6 ways, 64 byte lines, sectored - case 0x3E: l2 = 512; break; // code and data L2 cache, 512 KB, 4 ways, 64 byte lines, sectored - case 0x40: l2 = 0; break; // no integrated L2 cache (P6 core) or L3 cache (P4 core) - case 0x41: l2 = 128; break; // code and data L2 cache, 128 KB, 4 ways, 32 byte lines - case 0x42: l2 = 256; break; // code and data L2 cache, 256 KB, 4 ways, 32 byte lines - case 0x43: l2 = 512; break; // code and data L2 cache, 512 KB, 4 ways, 32 byte lines - case 0x44: l2 = 1024; break; // code and data L2 cache, 1024 KB, 4 ways, 32 byte lines - case 0x45: l2 = 2048; break; // code and data L2 cache, 2048 KB, 4 ways, 32 byte lines - case 0x46: l3 = 4096; break; // code and data L3 cache, 4096 KB, 4 ways, 64 byte lines - case 0x47: l3 = 8192; break; // code and data L3 cache, 8192 KB, 8 ways, 64 byte lines - case 0x48: l2 = 3072; break; // code and data L2 cache, 3072 KB, 12 ways, 64 byte lines - case 0x49: if(l2!=0) l3 = 4096; else {check_for_p2_core2=true; l3 = l2 = 4096;} break;// code and data L3 cache, 4096 KB, 16 ways, 64 byte lines (P4) or L2 for core2 - case 0x4A: l3 = 6144; break; // code and data L3 cache, 6144 KB, 12 ways, 64 byte lines - case 0x4B: l3 = 8192; break; // code and data L3 cache, 8192 KB, 16 ways, 64 byte lines - case 0x4C: l3 = 12288; break; // code and data L3 cache, 12288 KB, 12 ways, 64 byte lines - case 0x4D: l3 = 16384; break; // code and data L3 cache, 16384 KB, 16 ways, 64 byte lines - case 0x4E: l2 = 6144; break; // code and data L2 cache, 6144 KB, 24 ways, 64 byte lines - case 0x78: l2 = 1024; break; // code and data L2 cache, 1024 KB, 4 ways, 64 byte lines - case 0x79: l2 = 128; break; // code and data L2 cache, 128 KB, 8 ways, 64 byte lines, dual-sectored - case 0x7A: l2 = 256; break; // code and data L2 cache, 256 KB, 8 ways, 64 byte lines, dual-sectored - case 0x7B: l2 = 512; break; // code and data L2 cache, 512 KB, 8 ways, 64 byte lines, dual-sectored - case 0x7C: l2 = 1024; break; // code and data L2 cache, 1024 KB, 8 ways, 64 byte lines, dual-sectored - case 0x7D: l2 = 2048; break; // code and data L2 cache, 2048 KB, 8 ways, 64 byte lines - case 0x7E: l2 = 256; break; // code and data L2 cache, 256 KB, 8 ways, 128 byte lines, sect. (IA-64) - case 0x7F: l2 = 512; break; // code and data L2 cache, 512 KB, 2 ways, 64 byte lines - case 0x80: l2 = 512; break; // code and data L2 cache, 512 KB, 8 ways, 64 byte lines - case 0x81: l2 = 128; break; // code and data L2 cache, 128 KB, 8 ways, 32 byte lines - case 0x82: l2 = 256; break; // code and data L2 cache, 256 KB, 8 ways, 32 byte lines - case 0x83: l2 = 512; break; // code and data L2 cache, 512 KB, 8 ways, 32 byte lines - case 0x84: l2 = 1024; break; // code and data L2 cache, 1024 KB, 8 ways, 32 byte lines - case 0x85: l2 = 2048; break; // code and data L2 cache, 2048 KB, 8 ways, 32 byte lines - case 0x86: l2 = 512; break; // code and data L2 cache, 512 KB, 4 ways, 64 byte lines - case 0x87: l2 = 1024; break; // code and data L2 cache, 1024 KB, 8 ways, 64 byte lines - case 0x88: l3 = 2048; break; // code and data L3 cache, 2048 KB, 4 ways, 64 byte lines (IA-64) - case 0x89: l3 = 4096; break; // code and data L3 cache, 4096 KB, 4 ways, 64 byte lines (IA-64) - case 0x8A: l3 = 8192; break; // code and data L3 cache, 8192 KB, 4 ways, 64 byte lines (IA-64) - case 0x8D: l3 = 3072; break; // code and data L3 cache, 3072 KB, 12 ways, 128 byte lines (IA-64) - - default: break; - } - } - if(check_for_p2_core2 && l2 == l3) - l3 = 0; - l1 *= 1024; - l2 *= 1024; - l3 *= 1024; -} - -inline void queryCacheSizes_intel(int& l1, int& l2, int& l3, int max_std_funcs) -{ - if(max_std_funcs>=4) - queryCacheSizes_intel_direct(l1,l2,l3); - else - queryCacheSizes_intel_codes(l1,l2,l3); -} - -inline void queryCacheSizes_amd(int& l1, int& l2, int& l3) -{ - int abcd[4]; - abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0; - EIGEN_CPUID(abcd,0x80000005,0); - l1 = (abcd[2] >> 24) * 1024; // C[31:24] = L1 size in KB - abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0; - EIGEN_CPUID(abcd,0x80000006,0); - l2 = (abcd[2] >> 16) * 1024; // C[31;16] = l2 cache size in KB - l3 = ((abcd[3] & 0xFFFC000) >> 18) * 512 * 1024; // D[31;18] = l3 cache size in 512KB -} -#endif - -/** \internal - * Queries and returns the cache sizes in Bytes of the L1, L2, and L3 data caches respectively */ -inline void queryCacheSizes(int& l1, int& l2, int& l3) -{ - #ifdef EIGEN_CPUID - int abcd[4]; - const int GenuineIntel[] = {0x756e6547, 0x49656e69, 0x6c65746e}; - const int AuthenticAMD[] = {0x68747541, 0x69746e65, 0x444d4163}; - const int AMDisbetter_[] = {0x69444d41, 0x74656273, 0x21726574}; // "AMDisbetter!" - - // identify the CPU vendor - EIGEN_CPUID(abcd,0x0,0); - int max_std_funcs = abcd[1]; - if(cpuid_is_vendor(abcd,GenuineIntel)) - queryCacheSizes_intel(l1,l2,l3,max_std_funcs); - else if(cpuid_is_vendor(abcd,AuthenticAMD) || cpuid_is_vendor(abcd,AMDisbetter_)) - queryCacheSizes_amd(l1,l2,l3); - else - // by default let's use Intel's API - queryCacheSizes_intel(l1,l2,l3,max_std_funcs); - - // here is the list of other vendors: -// ||cpuid_is_vendor(abcd,"VIA VIA VIA ") -// ||cpuid_is_vendor(abcd,"CyrixInstead") -// ||cpuid_is_vendor(abcd,"CentaurHauls") -// ||cpuid_is_vendor(abcd,"GenuineTMx86") -// ||cpuid_is_vendor(abcd,"TransmetaCPU") -// ||cpuid_is_vendor(abcd,"RiseRiseRise") -// ||cpuid_is_vendor(abcd,"Geode by NSC") -// ||cpuid_is_vendor(abcd,"SiS SiS SiS ") -// ||cpuid_is_vendor(abcd,"UMC UMC UMC ") -// ||cpuid_is_vendor(abcd,"NexGenDriven") - #else - l1 = l2 = l3 = -1; - #endif -} - -/** \internal - * \returns the size in Bytes of the L1 data cache */ -inline int queryL1CacheSize() -{ - int l1(-1), l2, l3; - queryCacheSizes(l1,l2,l3); - return l1; -} - -/** \internal - * \returns the size in Bytes of the L2 or L3 cache if this later is present */ -inline int queryTopLevelCacheSize() -{ - int l1, l2(-1), l3(-1); - queryCacheSizes(l1,l2,l3); - return (std::max)(l2,l3); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MEMORY_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/Meta.h b/external/eigen/include/eigen3/Eigen/src/Core/util/Meta.h deleted file mode 100644 index 301077fa..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/Meta.h +++ /dev/null @@ -1,719 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_META_H -#define EIGEN_META_H - -#if defined(EIGEN_GPU_COMPILE_PHASE) - - #include <cfloat> - - #if defined(EIGEN_CUDA_ARCH) - #include <math_constants.h> - #endif - - #if defined(EIGEN_HIP_DEVICE_COMPILE) - #include "Eigen/src/Core/arch/HIP/hcc/math_constants.h" - #endif - -#endif - -#if EIGEN_COMP_ICC>=1600 && __cplusplus >= 201103L -#include <cstdint> -#endif - -namespace Eigen { - -typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex; - -/** - * \brief The Index type as used for the API. - * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE. - * \sa \blank \ref TopicPreprocessorDirectives, StorageIndex. - */ - -typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE Index; - -namespace internal { - -/** \internal - * \file Meta.h - * This file contains generic metaprogramming classes which are not specifically related to Eigen. - * \note In case you wonder, yes we're aware that Boost already provides all these features, - * we however don't want to add a dependency to Boost. - */ - -// Only recent versions of ICC complain about using ptrdiff_t to hold pointers, -// and older versions do not provide *intptr_t types. -#if EIGEN_COMP_ICC>=1600 && __cplusplus >= 201103L -typedef std::intptr_t IntPtr; -typedef std::uintptr_t UIntPtr; -#else -typedef std::ptrdiff_t IntPtr; -typedef std::size_t UIntPtr; -#endif - -struct true_type { enum { value = 1 }; }; -struct false_type { enum { value = 0 }; }; - -template<bool Condition> -struct bool_constant; - -template<> -struct bool_constant<true> : true_type {}; - -template<> -struct bool_constant<false> : false_type {}; - -template<bool Condition, typename Then, typename Else> -struct conditional { typedef Then type; }; - -template<typename Then, typename Else> -struct conditional <false, Then, Else> { typedef Else type; }; - -template<typename T> struct remove_reference { typedef T type; }; -template<typename T> struct remove_reference<T&> { typedef T type; }; - -template<typename T> struct remove_pointer { typedef T type; }; -template<typename T> struct remove_pointer<T*> { typedef T type; }; -template<typename T> struct remove_pointer<T*const> { typedef T type; }; - -template <class T> struct remove_const { typedef T type; }; -template <class T> struct remove_const<const T> { typedef T type; }; -template <class T> struct remove_const<const T[]> { typedef T type[]; }; -template <class T, unsigned int Size> struct remove_const<const T[Size]> { typedef T type[Size]; }; - -template<typename T> struct remove_all { typedef T type; }; -template<typename T> struct remove_all<const T> { typedef typename remove_all<T>::type type; }; -template<typename T> struct remove_all<T const&> { typedef typename remove_all<T>::type type; }; -template<typename T> struct remove_all<T&> { typedef typename remove_all<T>::type type; }; -template<typename T> struct remove_all<T const*> { typedef typename remove_all<T>::type type; }; -template<typename T> struct remove_all<T*> { typedef typename remove_all<T>::type type; }; - -template<typename T> struct is_arithmetic { enum { value = false }; }; -template<> struct is_arithmetic<float> { enum { value = true }; }; -template<> struct is_arithmetic<double> { enum { value = true }; }; -template<> struct is_arithmetic<long double> { enum { value = true }; }; -template<> struct is_arithmetic<bool> { enum { value = true }; }; -template<> struct is_arithmetic<char> { enum { value = true }; }; -template<> struct is_arithmetic<signed char> { enum { value = true }; }; -template<> struct is_arithmetic<unsigned char> { enum { value = true }; }; -template<> struct is_arithmetic<signed short> { enum { value = true }; }; -template<> struct is_arithmetic<unsigned short>{ enum { value = true }; }; -template<> struct is_arithmetic<signed int> { enum { value = true }; }; -template<> struct is_arithmetic<unsigned int> { enum { value = true }; }; -template<> struct is_arithmetic<signed long> { enum { value = true }; }; -template<> struct is_arithmetic<unsigned long> { enum { value = true }; }; - -template<typename T, typename U> struct is_same { enum { value = 0 }; }; -template<typename T> struct is_same<T,T> { enum { value = 1 }; }; - -template< class T > -struct is_void : is_same<void, typename remove_const<T>::type> {}; - -#if EIGEN_HAS_CXX11 -template<> struct is_arithmetic<signed long long> { enum { value = true }; }; -template<> struct is_arithmetic<unsigned long long> { enum { value = true }; }; -using std::is_integral; -#else -template<typename T> struct is_integral { enum { value = false }; }; -template<> struct is_integral<bool> { enum { value = true }; }; -template<> struct is_integral<char> { enum { value = true }; }; -template<> struct is_integral<signed char> { enum { value = true }; }; -template<> struct is_integral<unsigned char> { enum { value = true }; }; -template<> struct is_integral<signed short> { enum { value = true }; }; -template<> struct is_integral<unsigned short> { enum { value = true }; }; -template<> struct is_integral<signed int> { enum { value = true }; }; -template<> struct is_integral<unsigned int> { enum { value = true }; }; -template<> struct is_integral<signed long> { enum { value = true }; }; -template<> struct is_integral<unsigned long> { enum { value = true }; }; -#if EIGEN_COMP_MSVC -template<> struct is_integral<signed __int64> { enum { value = true }; }; -template<> struct is_integral<unsigned __int64> { enum { value = true }; }; -#endif -#endif - -#if EIGEN_HAS_CXX11 -using std::make_unsigned; -#else -// TODO: Possibly improve this implementation of make_unsigned. -// It is currently used only by -// template<typename Scalar> struct random_default_impl<Scalar, false, true>. -template<typename> struct make_unsigned; -template<> struct make_unsigned<char> { typedef unsigned char type; }; -template<> struct make_unsigned<signed char> { typedef unsigned char type; }; -template<> struct make_unsigned<unsigned char> { typedef unsigned char type; }; -template<> struct make_unsigned<signed short> { typedef unsigned short type; }; -template<> struct make_unsigned<unsigned short> { typedef unsigned short type; }; -template<> struct make_unsigned<signed int> { typedef unsigned int type; }; -template<> struct make_unsigned<unsigned int> { typedef unsigned int type; }; -template<> struct make_unsigned<signed long> { typedef unsigned long type; }; -template<> struct make_unsigned<unsigned long> { typedef unsigned long type; }; -#if EIGEN_COMP_MSVC -template<> struct make_unsigned<signed __int64> { typedef unsigned __int64 type; }; -template<> struct make_unsigned<unsigned __int64> { typedef unsigned __int64 type; }; -#endif -#endif - -template <typename T> struct add_const { typedef const T type; }; -template <typename T> struct add_const<T&> { typedef T& type; }; - -template <typename T> struct is_const { enum { value = 0 }; }; -template <typename T> struct is_const<T const> { enum { value = 1 }; }; - -template<typename T> struct add_const_on_value_type { typedef const T type; }; -template<typename T> struct add_const_on_value_type<T&> { typedef T const& type; }; -template<typename T> struct add_const_on_value_type<T*> { typedef T const* type; }; -template<typename T> struct add_const_on_value_type<T* const> { typedef T const* const type; }; -template<typename T> struct add_const_on_value_type<T const* const> { typedef T const* const type; }; - -#if EIGEN_HAS_CXX11 - -using std::is_convertible; - -#else - -template<typename From, typename To> -struct is_convertible_impl -{ -private: - struct any_conversion - { - template <typename T> any_conversion(const volatile T&); - template <typename T> any_conversion(T&); - }; - struct yes {int a[1];}; - struct no {int a[2];}; - - template<typename T> - static yes test(T, int); - - template<typename T> - static no test(any_conversion, ...); - -public: - static typename internal::remove_reference<From>::type* ms_from; -#ifdef __INTEL_COMPILER - #pragma warning push - #pragma warning ( disable : 2259 ) -#endif - enum { value = sizeof(test<To>(*ms_from, 0))==sizeof(yes) }; -#ifdef __INTEL_COMPILER - #pragma warning pop -#endif -}; - -template<typename From, typename To> -struct is_convertible -{ - enum { value = is_convertible_impl<From,To>::value }; -}; - -template<typename T> -struct is_convertible<T,T&> { enum { value = false }; }; - -template<typename T> -struct is_convertible<const T,const T&> { enum { value = true }; }; - -#endif - -/** \internal Allows to enable/disable an overload - * according to a compile time condition. - */ -template<bool Condition, typename T=void> struct enable_if; - -template<typename T> struct enable_if<true,T> -{ typedef T type; }; - -#if defined(EIGEN_GPU_COMPILE_PHASE) -#if !defined(__FLT_EPSILON__) -#define __FLT_EPSILON__ FLT_EPSILON -#define __DBL_EPSILON__ DBL_EPSILON -#endif - -namespace device { - -template<typename T> struct numeric_limits -{ - EIGEN_DEVICE_FUNC - static T epsilon() { return 0; } - static T (max)() { assert(false && "Highest not supported for this type"); } - static T (min)() { assert(false && "Lowest not supported for this type"); } - static T infinity() { assert(false && "Infinity not supported for this type"); } - static T quiet_NaN() { assert(false && "quiet_NaN not supported for this type"); } -}; -template<> struct numeric_limits<float> -{ - EIGEN_DEVICE_FUNC - static float epsilon() { return __FLT_EPSILON__; } - EIGEN_DEVICE_FUNC - static float (max)() { - #if defined(EIGEN_CUDA_ARCH) - return CUDART_MAX_NORMAL_F; - #else - return HIPRT_MAX_NORMAL_F; - #endif - } - EIGEN_DEVICE_FUNC - static float (min)() { return FLT_MIN; } - EIGEN_DEVICE_FUNC - static float infinity() { - #if defined(EIGEN_CUDA_ARCH) - return CUDART_INF_F; - #else - return HIPRT_INF_F; - #endif - } - EIGEN_DEVICE_FUNC - static float quiet_NaN() { - #if defined(EIGEN_CUDA_ARCH) - return CUDART_NAN_F; - #else - return HIPRT_NAN_F; - #endif - } -}; -template<> struct numeric_limits<double> -{ - EIGEN_DEVICE_FUNC - static double epsilon() { return __DBL_EPSILON__; } - EIGEN_DEVICE_FUNC - static double (max)() { return DBL_MAX; } - EIGEN_DEVICE_FUNC - static double (min)() { return DBL_MIN; } - EIGEN_DEVICE_FUNC - static double infinity() { - #if defined(EIGEN_CUDA_ARCH) - return CUDART_INF; - #else - return HIPRT_INF; - #endif - } - EIGEN_DEVICE_FUNC - static double quiet_NaN() { - #if defined(EIGEN_CUDA_ARCH) - return CUDART_NAN; - #else - return HIPRT_NAN; - #endif - } -}; -template<> struct numeric_limits<int> -{ - EIGEN_DEVICE_FUNC - static int epsilon() { return 0; } - EIGEN_DEVICE_FUNC - static int (max)() { return INT_MAX; } - EIGEN_DEVICE_FUNC - static int (min)() { return INT_MIN; } -}; -template<> struct numeric_limits<unsigned int> -{ - EIGEN_DEVICE_FUNC - static unsigned int epsilon() { return 0; } - EIGEN_DEVICE_FUNC - static unsigned int (max)() { return UINT_MAX; } - EIGEN_DEVICE_FUNC - static unsigned int (min)() { return 0; } -}; -template<> struct numeric_limits<long> -{ - EIGEN_DEVICE_FUNC - static long epsilon() { return 0; } - EIGEN_DEVICE_FUNC - static long (max)() { return LONG_MAX; } - EIGEN_DEVICE_FUNC - static long (min)() { return LONG_MIN; } -}; -template<> struct numeric_limits<unsigned long> -{ - EIGEN_DEVICE_FUNC - static unsigned long epsilon() { return 0; } - EIGEN_DEVICE_FUNC - static unsigned long (max)() { return ULONG_MAX; } - EIGEN_DEVICE_FUNC - static unsigned long (min)() { return 0; } -}; -template<> struct numeric_limits<long long> -{ - EIGEN_DEVICE_FUNC - static long long epsilon() { return 0; } - EIGEN_DEVICE_FUNC - static long long (max)() { return LLONG_MAX; } - EIGEN_DEVICE_FUNC - static long long (min)() { return LLONG_MIN; } -}; -template<> struct numeric_limits<unsigned long long> -{ - EIGEN_DEVICE_FUNC - static unsigned long long epsilon() { return 0; } - EIGEN_DEVICE_FUNC - static unsigned long long (max)() { return ULLONG_MAX; } - EIGEN_DEVICE_FUNC - static unsigned long long (min)() { return 0; } -}; - -} - -#endif - -/** \internal - * A base class do disable default copy ctor and copy assignment operator. - */ -class noncopyable -{ - EIGEN_DEVICE_FUNC noncopyable(const noncopyable&); - EIGEN_DEVICE_FUNC const noncopyable& operator=(const noncopyable&); -protected: - EIGEN_DEVICE_FUNC noncopyable() {} - EIGEN_DEVICE_FUNC ~noncopyable() {} -}; - -/** \internal - * Provides access to the number of elements in the object of as a compile-time constant expression. - * It "returns" Eigen::Dynamic if the size cannot be resolved at compile-time (default). - * - * Similar to std::tuple_size, but more general. - * - * It currently supports: - * - any types T defining T::SizeAtCompileTime - * - plain C arrays as T[N] - * - std::array (c++11) - * - some internal types such as SingleRange and AllRange - * - * The second template parameter eases SFINAE-based specializations. - */ -template<typename T, typename EnableIf = void> struct array_size { - enum { value = Dynamic }; -}; - -template<typename T> struct array_size<T,typename internal::enable_if<((T::SizeAtCompileTime&0)==0)>::type> { - enum { value = T::SizeAtCompileTime }; -}; - -template<typename T, int N> struct array_size<const T (&)[N]> { - enum { value = N }; -}; -template<typename T, int N> struct array_size<T (&)[N]> { - enum { value = N }; -}; - -#if EIGEN_HAS_CXX11 -template<typename T, std::size_t N> struct array_size<const std::array<T,N> > { - enum { value = N }; -}; -template<typename T, std::size_t N> struct array_size<std::array<T,N> > { - enum { value = N }; -}; -#endif - -/** \internal - * Analogue of the std::size free function. - * It returns the size of the container or view \a x of type \c T - * - * It currently supports: - * - any types T defining a member T::size() const - * - plain C arrays as T[N] - * - */ -template<typename T> -Index size(const T& x) { return x.size(); } - -template<typename T,std::size_t N> -Index size(const T (&) [N]) { return N; } - -/** \internal - * Convenient struct to get the result type of a unary or binary functor. - * - * It supports both the current STL mechanism (using the result_type member) as well as - * upcoming next STL generation (using a templated result member). - * If none of these members is provided, then the type of the first argument is returned. FIXME, that behavior is a pretty bad hack. - */ -#if EIGEN_HAS_STD_RESULT_OF -template<typename T> struct result_of { - typedef typename std::result_of<T>::type type1; - typedef typename remove_all<type1>::type type; -}; -#else -template<typename T> struct result_of { }; - -struct has_none {int a[1];}; -struct has_std_result_type {int a[2];}; -struct has_tr1_result {int a[3];}; - -template<typename Func, typename ArgType, int SizeOf=sizeof(has_none)> -struct unary_result_of_select {typedef typename internal::remove_all<ArgType>::type type;}; - -template<typename Func, typename ArgType> -struct unary_result_of_select<Func, ArgType, sizeof(has_std_result_type)> {typedef typename Func::result_type type;}; - -template<typename Func, typename ArgType> -struct unary_result_of_select<Func, ArgType, sizeof(has_tr1_result)> {typedef typename Func::template result<Func(ArgType)>::type type;}; - -template<typename Func, typename ArgType> -struct result_of<Func(ArgType)> { - template<typename T> - static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); - template<typename T> - static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType)>::type const * = 0); - static has_none testFunctor(...); - - // note that the following indirection is needed for gcc-3.3 - enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))}; - typedef typename unary_result_of_select<Func, ArgType, FunctorType>::type type; -}; - -template<typename Func, typename ArgType0, typename ArgType1, int SizeOf=sizeof(has_none)> -struct binary_result_of_select {typedef typename internal::remove_all<ArgType0>::type type;}; - -template<typename Func, typename ArgType0, typename ArgType1> -struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_std_result_type)> -{typedef typename Func::result_type type;}; - -template<typename Func, typename ArgType0, typename ArgType1> -struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_tr1_result)> -{typedef typename Func::template result<Func(ArgType0,ArgType1)>::type type;}; - -template<typename Func, typename ArgType0, typename ArgType1> -struct result_of<Func(ArgType0,ArgType1)> { - template<typename T> - static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); - template<typename T> - static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1)>::type const * = 0); - static has_none testFunctor(...); - - // note that the following indirection is needed for gcc-3.3 - enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))}; - typedef typename binary_result_of_select<Func, ArgType0, ArgType1, FunctorType>::type type; -}; - -template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2, int SizeOf=sizeof(has_none)> -struct ternary_result_of_select {typedef typename internal::remove_all<ArgType0>::type type;}; - -template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2> -struct ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, sizeof(has_std_result_type)> -{typedef typename Func::result_type type;}; - -template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2> -struct ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, sizeof(has_tr1_result)> -{typedef typename Func::template result<Func(ArgType0,ArgType1,ArgType2)>::type type;}; - -template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2> -struct result_of<Func(ArgType0,ArgType1,ArgType2)> { - template<typename T> - static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); - template<typename T> - static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1,ArgType2)>::type const * = 0); - static has_none testFunctor(...); - - // note that the following indirection is needed for gcc-3.3 - enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))}; - typedef typename ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, FunctorType>::type type; -}; -#endif - -struct meta_yes { char a[1]; }; -struct meta_no { char a[2]; }; - -// Check whether T::ReturnType does exist -template <typename T> -struct has_ReturnType -{ - template <typename C> static meta_yes testFunctor(C const *, typename C::ReturnType const * = 0); - template <typename C> static meta_no testFunctor(...); - - enum { value = sizeof(testFunctor<T>(static_cast<T*>(0))) == sizeof(meta_yes) }; -}; - -template<typename T> const T* return_ptr(); - -template <typename T, typename IndexType=Index> -struct has_nullary_operator -{ - template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()())>0)>::type * = 0); - static meta_no testFunctor(...); - - enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) }; -}; - -template <typename T, typename IndexType=Index> -struct has_unary_operator -{ - template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()(IndexType(0)))>0)>::type * = 0); - static meta_no testFunctor(...); - - enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) }; -}; - -template <typename T, typename IndexType=Index> -struct has_binary_operator -{ - template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()(IndexType(0),IndexType(0)))>0)>::type * = 0); - static meta_no testFunctor(...); - - enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) }; -}; - -/** \internal In short, it computes int(sqrt(\a Y)) with \a Y an integer. - * Usage example: \code meta_sqrt<1023>::ret \endcode - */ -template<int Y, - int InfX = 0, - int SupX = ((Y==1) ? 1 : Y/2), - bool Done = ((SupX-InfX)<=1 ? true : ((SupX*SupX <= Y) && ((SupX+1)*(SupX+1) > Y))) > - // use ?: instead of || just to shut up a stupid gcc 4.3 warning -class meta_sqrt -{ - enum { - MidX = (InfX+SupX)/2, - TakeInf = MidX*MidX > Y ? 1 : 0, - NewInf = int(TakeInf) ? InfX : int(MidX), - NewSup = int(TakeInf) ? int(MidX) : SupX - }; - public: - enum { ret = meta_sqrt<Y,NewInf,NewSup>::ret }; -}; - -template<int Y, int InfX, int SupX> -class meta_sqrt<Y, InfX, SupX, true> { public: enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; }; - - -/** \internal Computes the least common multiple of two positive integer A and B - * at compile-time. It implements a naive algorithm testing all multiples of A. - * It thus works better if A>=B. - */ -template<int A, int B, int K=1, bool Done = ((A*K)%B)==0> -struct meta_least_common_multiple -{ - enum { ret = meta_least_common_multiple<A,B,K+1>::ret }; -}; -template<int A, int B, int K> -struct meta_least_common_multiple<A,B,K,true> -{ - enum { ret = A*K }; -}; - -/** \internal determines whether the product of two numeric types is allowed and what the return type is */ -template<typename T, typename U> struct scalar_product_traits -{ - enum { Defined = 0 }; -}; - -// FIXME quick workaround around current limitation of result_of -// template<typename Scalar, typename ArgType0, typename ArgType1> -// struct result_of<scalar_product_op<Scalar>(ArgType0,ArgType1)> { -// typedef typename scalar_product_traits<typename remove_all<ArgType0>::type, typename remove_all<ArgType1>::type>::ReturnType type; -// }; - -/** \internal Obtains a POD type suitable to use as storage for an object of a size - * of at most Len bytes, aligned as specified by \c Align. - */ -template<unsigned Len, unsigned Align> -struct aligned_storage { - struct type { - EIGEN_ALIGN_TO_BOUNDARY(Align) unsigned char data[Len]; - }; -}; - -} // end namespace internal - -namespace numext { - -#if defined(EIGEN_GPU_COMPILE_PHASE) -template<typename T> EIGEN_DEVICE_FUNC void swap(T &a, T &b) { T tmp = b; b = a; a = tmp; } -#else -template<typename T> EIGEN_STRONG_INLINE void swap(T &a, T &b) { std::swap(a,b); } -#endif - -#if defined(EIGEN_GPU_COMPILE_PHASE) -using internal::device::numeric_limits; -#else -using std::numeric_limits; -#endif - -// Integer division with rounding up. -// T is assumed to be an integer type with a>=0, and b>0 -template<typename T> -EIGEN_DEVICE_FUNC -T div_ceil(const T &a, const T &b) -{ - return (a+b-1) / b; -} - -// The aim of the following functions is to bypass -Wfloat-equal warnings -// when we really want a strict equality comparison on floating points. -template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC -bool equal_strict(const X& x,const Y& y) { return x == y; } - -#if !defined(EIGEN_GPU_COMPILE_PHASE) || (!defined(EIGEN_CUDA_ARCH) && defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC)) -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC -bool equal_strict(const float& x,const float& y) { return std::equal_to<float>()(x,y); } - -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC -bool equal_strict(const double& x,const double& y) { return std::equal_to<double>()(x,y); } -#endif - -template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC -bool not_equal_strict(const X& x,const Y& y) { return x != y; } - -#if !defined(EIGEN_GPU_COMPILE_PHASE) || (!defined(EIGEN_CUDA_ARCH) && defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC)) -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC -bool not_equal_strict(const float& x,const float& y) { return std::not_equal_to<float>()(x,y); } - -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC -bool not_equal_strict(const double& x,const double& y) { return std::not_equal_to<double>()(x,y); } -#endif - -/** \internal extract the bits of the float \a x */ -inline unsigned int as_uint(float x) -{ - unsigned int ret; - std::memcpy(&ret, &x, sizeof(float)); - return ret; -} - -} // end namespace numext - -} // end namespace Eigen - -// Define portable (u)int{32,64} types -#if EIGEN_HAS_CXX11 -#include <cstdint> -namespace Eigen { -namespace numext { -typedef std::uint8_t uint8_t; -typedef std::int8_t int8_t; -typedef std::uint16_t uint16_t; -typedef std::int16_t int16_t; -typedef std::uint32_t uint32_t; -typedef std::int32_t int32_t; -typedef std::uint64_t uint64_t; -typedef std::int64_t int64_t; -} -} -#else -// Without c++11, all compilers able to compile Eigen also -// provides the C99 stdint.h header file. -#include <stdint.h> -namespace Eigen { -namespace numext { -typedef ::uint8_t uint8_t; -typedef ::int8_t int8_t; -typedef ::uint16_t uint16_t; -typedef ::int16_t int16_t; -typedef ::uint32_t uint32_t; -typedef ::int32_t int32_t; -typedef ::uint64_t uint64_t; -typedef ::int64_t int64_t; -} -} -#endif - -#endif // EIGEN_META_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/NonMPL2.h b/external/eigen/include/eigen3/Eigen/src/Core/util/NonMPL2.h deleted file mode 100644 index 1af67cf1..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/NonMPL2.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifdef EIGEN_MPL2_ONLY -#error Including non-MPL2 code in EIGEN_MPL2_ONLY mode -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/ReenableStupidWarnings.h b/external/eigen/include/eigen3/Eigen/src/Core/util/ReenableStupidWarnings.h deleted file mode 100644 index 1ce6fd1b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/ReenableStupidWarnings.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef EIGEN_WARNINGS_DISABLED_2 -// "DisableStupidWarnings.h" was included twice recursively: Do not reenable warnings yet! -# undef EIGEN_WARNINGS_DISABLED_2 - -#elif defined(EIGEN_WARNINGS_DISABLED) -#undef EIGEN_WARNINGS_DISABLED - -#ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS - #ifdef _MSC_VER - #pragma warning( pop ) - #elif defined __INTEL_COMPILER - #pragma warning pop - #elif defined __clang__ - #pragma clang diagnostic pop - #elif defined __GNUC__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) - #pragma GCC diagnostic pop - #endif - - #if defined __NVCC__ -// Don't reenable the diagnostic messages, as it turns out these messages need -// to be disabled at the point of the template instantiation (i.e the user code) -// otherwise they'll be triggered by nvcc. -// #pragma diag_default code_is_unreachable -// #pragma diag_default initialization_not_reachable -// #pragma diag_default 2651 -// #pragma diag_default 2653 - #endif - -#endif - -#endif // EIGEN_WARNINGS_DISABLED diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/ReshapedHelper.h b/external/eigen/include/eigen3/Eigen/src/Core/util/ReshapedHelper.h deleted file mode 100644 index 41243213..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/ReshapedHelper.h +++ /dev/null @@ -1,51 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_RESHAPED_HELPER_H -#define EIGEN_RESHAPED_HELPER_H - -namespace Eigen { - -enum AutoSize_t { AutoSize }; -const int AutoOrder = 2; - -namespace internal { - -template<typename SizeType,typename OtherSize, int TotalSize> -struct get_compiletime_reshape_size { - enum { value = get_fixed_value<SizeType>::value }; -}; - -template<typename SizeType> -Index get_runtime_reshape_size(SizeType size, Index /*other*/, Index /*total*/) { - return internal::get_runtime_value(size); -} - -template<typename OtherSize, int TotalSize> -struct get_compiletime_reshape_size<AutoSize_t,OtherSize,TotalSize> { - enum { - other_size = get_fixed_value<OtherSize>::value, - value = (TotalSize==Dynamic || other_size==Dynamic) ? Dynamic : TotalSize / other_size }; -}; - -inline Index get_runtime_reshape_size(AutoSize_t /*size*/, Index other, Index total) { - return total/other; -} - -template<int Flags, int Order> -struct get_compiletime_reshape_order { - enum { value = Order == AutoOrder ? Flags & RowMajorBit : Order }; -}; - -} - -} // end namespace Eigen - -#endif // EIGEN_RESHAPED_HELPER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/StaticAssert.h b/external/eigen/include/eigen3/Eigen/src/Core/util/StaticAssert.h deleted file mode 100644 index 95107ff3..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/StaticAssert.h +++ /dev/null @@ -1,220 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STATIC_ASSERT_H -#define EIGEN_STATIC_ASSERT_H - -/* Some notes on Eigen's static assertion mechanism: - * - * - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean - * expression, and MSG an enum listed in struct internal::static_assertion<true> - * - * - define EIGEN_NO_STATIC_ASSERT to disable them (and save compilation time) - * in that case, the static assertion is converted to the following runtime assert: - * eigen_assert(CONDITION && "MSG") - * - * - currently EIGEN_STATIC_ASSERT can only be used in function scope - * - */ - -#ifndef EIGEN_STATIC_ASSERT -#ifndef EIGEN_NO_STATIC_ASSERT - - #if EIGEN_MAX_CPP_VER>=11 && (__has_feature(cxx_static_assert) || (defined(__cplusplus) && __cplusplus >= 201103L) || (EIGEN_COMP_MSVC >= 1600)) - - // if native static_assert is enabled, let's use it - #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG); - - #else // not CXX0X - - namespace Eigen { - - namespace internal { - - template<bool condition> - struct static_assertion {}; - - template<> - struct static_assertion<true> - { - enum { - YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX=1, - YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES=1, - YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES=1, - THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE=1, - THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE=1, - THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE=1, - OUT_OF_RANGE_ACCESS=1, - YOU_MADE_A_PROGRAMMING_MISTAKE=1, - EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT=1, - EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE=1, - YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR=1, - YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR=1, - UNALIGNED_LOAD_AND_STORE_OPERATIONS_UNIMPLEMENTED_ON_ALTIVEC=1, - THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES=1, - FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED=1, - NUMERIC_TYPE_MUST_BE_REAL=1, - COEFFICIENT_WRITE_ACCESS_TO_SELFADJOINT_NOT_SUPPORTED=1, - WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED=1, - THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE=1, - INVALID_MATRIX_PRODUCT=1, - INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS=1, - INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION=1, - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY=1, - THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES=1, - THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES=1, - INVALID_MATRIX_TEMPLATE_PARAMETERS=1, - INVALID_MATRIXBASE_TEMPLATE_PARAMETERS=1, - BOTH_MATRICES_MUST_HAVE_THE_SAME_STORAGE_ORDER=1, - THIS_METHOD_IS_ONLY_FOR_DIAGONAL_MATRIX=1, - THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE=1, - THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES=1, - YOU_ALREADY_SPECIFIED_THIS_STRIDE=1, - INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION=1, - THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD=1, - PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1=1, - THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS=1, - YOU_CANNOT_MIX_ARRAYS_AND_MATRICES=1, - YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION=1, - THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY=1, - YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT=1, - THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS=1, - THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS=1, - THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL=1, - THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES=1, - YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED=1, - YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED=1, - THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE=1, - THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH=1, - OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG=1, - IMPLICIT_CONVERSION_TO_SCALAR_IS_FOR_INNER_PRODUCT_ONLY=1, - STORAGE_LAYOUT_DOES_NOT_MATCH=1, - EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT__INVALID_COST_VALUE=1, - THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS=1, - MATRIX_FREE_CONJUGATE_GRADIENT_IS_COMPATIBLE_WITH_UPPER_UNION_LOWER_MODE_ONLY=1, - THIS_TYPE_IS_NOT_SUPPORTED=1, - STORAGE_KIND_MUST_MATCH=1, - STORAGE_INDEX_MUST_MATCH=1, - CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY=1, - SELFADJOINTVIEW_ACCEPTS_UPPER_AND_LOWER_MODE_ONLY=1, - INVALID_TEMPLATE_PARAMETER=1, - GPU_TENSOR_CONTRACTION_DOES_NOT_SUPPORT_OUTPUT_KERNELS=1 - }; - }; - - } // end namespace internal - - } // end namespace Eigen - - // Specialized implementation for MSVC to avoid "conditional - // expression is constant" warnings. This implementation doesn't - // appear to work under GCC, hence the multiple implementations. - #if EIGEN_COMP_MSVC - - #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \ - {Eigen::internal::static_assertion<bool(CONDITION)>::MSG;} - - #else - // In some cases clang interprets bool(CONDITION) as function declaration - #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \ - if (Eigen::internal::static_assertion<static_cast<bool>(CONDITION)>::MSG) {} - - #endif - - #endif // not CXX0X - -#else // EIGEN_NO_STATIC_ASSERT - - #define EIGEN_STATIC_ASSERT(CONDITION,MSG) eigen_assert((CONDITION) && #MSG); - -#endif // EIGEN_NO_STATIC_ASSERT -#endif // EIGEN_STATIC_ASSERT - -// static assertion failing if the type \a TYPE is not a vector type -#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \ - EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \ - YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX) - -// static assertion failing if the type \a TYPE is not fixed-size -#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \ - EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \ - YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR) - -// static assertion failing if the type \a TYPE is not dynamic-size -#define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \ - EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \ - YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR) - -// static assertion failing if the type \a TYPE is not a vector type of the given size -#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \ - EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \ - THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE) - -// static assertion failing if the type \a TYPE is not a vector type of the given size -#define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \ - EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \ - THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE) - -// static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size) -#define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \ - EIGEN_STATIC_ASSERT( \ - (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \ - || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \ - || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\ - YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES) - -#define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \ - ( \ - (int(Eigen::internal::size_of_xpr_at_compile_time<TYPE0>::ret)==0 && int(Eigen::internal::size_of_xpr_at_compile_time<TYPE1>::ret)==0) \ - || (\ - (int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \ - || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \ - || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \ - && (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \ - || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \ - || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\ - ) \ - ) - -#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \ - EIGEN_STATIC_ASSERT(!Eigen::NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES) - - -// static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes -#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \ - EIGEN_STATIC_ASSERT( \ - EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\ - YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES) - -#define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \ - EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Eigen::Dynamic) && \ - (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Eigen::Dynamic), \ - THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS) - -#define EIGEN_STATIC_ASSERT_LVALUE(Derived) \ - EIGEN_STATIC_ASSERT(Eigen::internal::is_lvalue<Derived>::value, \ - THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY) - -#define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived) \ - EIGEN_STATIC_ASSERT((Eigen::internal::is_same<typename Eigen::internal::traits<Derived>::XprKind, ArrayXpr>::value), \ - THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES) - -#define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2) \ - EIGEN_STATIC_ASSERT((Eigen::internal::is_same<typename Eigen::internal::traits<Derived1>::XprKind, \ - typename Eigen::internal::traits<Derived2>::XprKind \ - >::value), \ - YOU_CANNOT_MIX_ARRAYS_AND_MATRICES) - -// Check that a cost value is positive, and that is stay within a reasonable range -// TODO this check could be enabled for internal debugging only -#define EIGEN_INTERNAL_CHECK_COST_VALUE(C) \ - EIGEN_STATIC_ASSERT((C)>=0 && (C)<=HugeCost*HugeCost, EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT__INVALID_COST_VALUE); - -#endif // EIGEN_STATIC_ASSERT_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/SymbolicIndex.h b/external/eigen/include/eigen3/Eigen/src/Core/util/SymbolicIndex.h deleted file mode 100644 index 17cf46f0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/SymbolicIndex.h +++ /dev/null @@ -1,293 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SYMBOLIC_INDEX_H -#define EIGEN_SYMBOLIC_INDEX_H - -namespace Eigen { - -/** \namespace Eigen::symbolic - * \ingroup Core_Module - * - * This namespace defines a set of classes and functions to build and evaluate symbolic expressions of scalar type Index. - * Here is a simple example: - * - * \code - * // First step, defines symbols: - * struct x_tag {}; static const symbolic::SymbolExpr<x_tag> x; - * struct y_tag {}; static const symbolic::SymbolExpr<y_tag> y; - * struct z_tag {}; static const symbolic::SymbolExpr<z_tag> z; - * - * // Defines an expression: - * auto expr = (x+3)/y+z; - * - * // And evaluate it: (c++14) - * std::cout << expr.eval(x=6,y=3,z=-13) << "\n"; - * - * // In c++98/11, only one symbol per expression is supported for now: - * auto expr98 = (3-x)/2; - * std::cout << expr98.eval(x=6) << "\n"; - * \endcode - * - * It is currently only used internally to define and manipulate the Eigen::last and Eigen::lastp1 symbols in Eigen::seq and Eigen::seqN. - * - */ -namespace symbolic { - -template<typename Tag> class Symbol; -template<typename Arg0> class NegateExpr; -template<typename Arg1,typename Arg2> class AddExpr; -template<typename Arg1,typename Arg2> class ProductExpr; -template<typename Arg1,typename Arg2> class QuotientExpr; - -// A simple wrapper around an integral value to provide the eval method. -// We could also use a free-function symbolic_eval... -template<typename IndexType=Index> -class ValueExpr { -public: - ValueExpr(IndexType val) : m_value(val) {} - template<typename T> - IndexType eval_impl(const T&) const { return m_value; } -protected: - IndexType m_value; -}; - -// Specialization for compile-time value, -// It is similar to ValueExpr(N) but this version helps the compiler to generate better code. -template<int N> -class ValueExpr<internal::FixedInt<N> > { -public: - ValueExpr() {} - template<typename T> - Index eval_impl(const T&) const { return N; } -}; - - -/** \class BaseExpr - * \ingroup Core_Module - * Common base class of any symbolic expressions - */ -template<typename Derived> -class BaseExpr -{ -public: - const Derived& derived() const { return *static_cast<const Derived*>(this); } - - /** Evaluate the expression given the \a values of the symbols. - * - * \param values defines the values of the symbols, it can either be a SymbolValue or a std::tuple of SymbolValue - * as constructed by SymbolExpr::operator= operator. - * - */ - template<typename T> - Index eval(const T& values) const { return derived().eval_impl(values); } - -#if EIGEN_HAS_CXX14 - template<typename... Types> - Index eval(Types&&... values) const { return derived().eval_impl(std::make_tuple(values...)); } -#endif - - NegateExpr<Derived> operator-() const { return NegateExpr<Derived>(derived()); } - - AddExpr<Derived,ValueExpr<> > operator+(Index b) const - { return AddExpr<Derived,ValueExpr<> >(derived(), b); } - AddExpr<Derived,ValueExpr<> > operator-(Index a) const - { return AddExpr<Derived,ValueExpr<> >(derived(), -a); } - ProductExpr<Derived,ValueExpr<> > operator*(Index a) const - { return ProductExpr<Derived,ValueExpr<> >(derived(),a); } - QuotientExpr<Derived,ValueExpr<> > operator/(Index a) const - { return QuotientExpr<Derived,ValueExpr<> >(derived(),a); } - - friend AddExpr<Derived,ValueExpr<> > operator+(Index a, const BaseExpr& b) - { return AddExpr<Derived,ValueExpr<> >(b.derived(), a); } - friend AddExpr<NegateExpr<Derived>,ValueExpr<> > operator-(Index a, const BaseExpr& b) - { return AddExpr<NegateExpr<Derived>,ValueExpr<> >(-b.derived(), a); } - friend ProductExpr<ValueExpr<>,Derived> operator*(Index a, const BaseExpr& b) - { return ProductExpr<ValueExpr<>,Derived>(a,b.derived()); } - friend QuotientExpr<ValueExpr<>,Derived> operator/(Index a, const BaseExpr& b) - { return QuotientExpr<ValueExpr<>,Derived>(a,b.derived()); } - - template<int N> - AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N>) const - { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(), ValueExpr<internal::FixedInt<N> >()); } - template<int N> - AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > > operator-(internal::FixedInt<N>) const - { return AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > >(derived(), ValueExpr<internal::FixedInt<-N> >()); } - template<int N> - ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator*(internal::FixedInt<N>) const - { return ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); } - template<int N> - QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator/(internal::FixedInt<N>) const - { return QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); } - - template<int N> - friend AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N>, const BaseExpr& b) - { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(b.derived(), ValueExpr<internal::FixedInt<N> >()); } - template<int N> - friend AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > > operator-(internal::FixedInt<N>, const BaseExpr& b) - { return AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > >(-b.derived(), ValueExpr<internal::FixedInt<N> >()); } - template<int N> - friend ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator*(internal::FixedInt<N>, const BaseExpr& b) - { return ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); } - template<int N> - friend QuotientExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator/(internal::FixedInt<N>, const BaseExpr& b) - { return QuotientExpr<ValueExpr<internal::FixedInt<N> > ,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); } - -#if (!EIGEN_HAS_CXX14) - template<int N> - AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N> (*)()) const - { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(), ValueExpr<internal::FixedInt<N> >()); } - template<int N> - AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > > operator-(internal::FixedInt<N> (*)()) const - { return AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > >(derived(), ValueExpr<internal::FixedInt<-N> >()); } - template<int N> - ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator*(internal::FixedInt<N> (*)()) const - { return ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); } - template<int N> - QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator/(internal::FixedInt<N> (*)()) const - { return QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); } - - template<int N> - friend AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N> (*)(), const BaseExpr& b) - { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(b.derived(), ValueExpr<internal::FixedInt<N> >()); } - template<int N> - friend AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > > operator-(internal::FixedInt<N> (*)(), const BaseExpr& b) - { return AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > >(-b.derived(), ValueExpr<internal::FixedInt<N> >()); } - template<int N> - friend ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator*(internal::FixedInt<N> (*)(), const BaseExpr& b) - { return ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); } - template<int N> - friend QuotientExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator/(internal::FixedInt<N> (*)(), const BaseExpr& b) - { return QuotientExpr<ValueExpr<internal::FixedInt<N> > ,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); } -#endif - - - template<typename OtherDerived> - AddExpr<Derived,OtherDerived> operator+(const BaseExpr<OtherDerived> &b) const - { return AddExpr<Derived,OtherDerived>(derived(), b.derived()); } - - template<typename OtherDerived> - AddExpr<Derived,NegateExpr<OtherDerived> > operator-(const BaseExpr<OtherDerived> &b) const - { return AddExpr<Derived,NegateExpr<OtherDerived> >(derived(), -b.derived()); } - - template<typename OtherDerived> - ProductExpr<Derived,OtherDerived> operator*(const BaseExpr<OtherDerived> &b) const - { return ProductExpr<Derived,OtherDerived>(derived(), b.derived()); } - - template<typename OtherDerived> - QuotientExpr<Derived,OtherDerived> operator/(const BaseExpr<OtherDerived> &b) const - { return QuotientExpr<Derived,OtherDerived>(derived(), b.derived()); } -}; - -template<typename T> -struct is_symbolic { - // BaseExpr has no conversion ctor, so we only have to check whether T can be statically cast to its base class BaseExpr<T>. - enum { value = internal::is_convertible<T,BaseExpr<T> >::value }; -}; - -/** Represents the actual value of a symbol identified by its tag - * - * It is the return type of SymbolValue::operator=, and most of the time this is only way it is used. - */ -template<typename Tag> -class SymbolValue -{ -public: - /** Default constructor from the value \a val */ - SymbolValue(Index val) : m_value(val) {} - - /** \returns the stored value of the symbol */ - Index value() const { return m_value; } -protected: - Index m_value; -}; - -/** Expression of a symbol uniquely identified by the template parameter type \c tag */ -template<typename tag> -class SymbolExpr : public BaseExpr<SymbolExpr<tag> > -{ -public: - /** Alias to the template parameter \c tag */ - typedef tag Tag; - - SymbolExpr() {} - - /** Associate the value \a val to the given symbol \c *this, uniquely identified by its \c Tag. - * - * The returned object should be passed to ExprBase::eval() to evaluate a given expression with this specified runtime-time value. - */ - SymbolValue<Tag> operator=(Index val) const { - return SymbolValue<Tag>(val); - } - - Index eval_impl(const SymbolValue<Tag> &values) const { return values.value(); } - -#if EIGEN_HAS_CXX14 - // C++14 versions suitable for multiple symbols - template<typename... Types> - Index eval_impl(const std::tuple<Types...>& values) const { return std::get<SymbolValue<Tag> >(values).value(); } -#endif -}; - -template<typename Arg0> -class NegateExpr : public BaseExpr<NegateExpr<Arg0> > -{ -public: - NegateExpr(const Arg0& arg0) : m_arg0(arg0) {} - - template<typename T> - Index eval_impl(const T& values) const { return -m_arg0.eval_impl(values); } -protected: - Arg0 m_arg0; -}; - -template<typename Arg0, typename Arg1> -class AddExpr : public BaseExpr<AddExpr<Arg0,Arg1> > -{ -public: - AddExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {} - - template<typename T> - Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) + m_arg1.eval_impl(values); } -protected: - Arg0 m_arg0; - Arg1 m_arg1; -}; - -template<typename Arg0, typename Arg1> -class ProductExpr : public BaseExpr<ProductExpr<Arg0,Arg1> > -{ -public: - ProductExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {} - - template<typename T> - Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) * m_arg1.eval_impl(values); } -protected: - Arg0 m_arg0; - Arg1 m_arg1; -}; - -template<typename Arg0, typename Arg1> -class QuotientExpr : public BaseExpr<QuotientExpr<Arg0,Arg1> > -{ -public: - QuotientExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {} - - template<typename T> - Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) / m_arg1.eval_impl(values); } -protected: - Arg0 m_arg0; - Arg1 m_arg1; -}; - -} // end namespace symbolic - -} // end namespace Eigen - -#endif // EIGEN_SYMBOLIC_INDEX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Core/util/XprHelper.h b/external/eigen/include/eigen3/Eigen/src/Core/util/XprHelper.h deleted file mode 100644 index fd2db56a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Core/util/XprHelper.h +++ /dev/null @@ -1,864 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_XPRHELPER_H -#define EIGEN_XPRHELPER_H - -// just a workaround because GCC seems to not really like empty structs -// FIXME: gcc 4.3 generates bad code when strict-aliasing is enabled -// so currently we simply disable this optimization for gcc 4.3 -#if EIGEN_COMP_GNUC && !EIGEN_GNUC_AT(4,3) - #define EIGEN_EMPTY_STRUCT_CTOR(X) \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE X() {} \ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE X(const X& ) {} -#else - #define EIGEN_EMPTY_STRUCT_CTOR(X) -#endif - -namespace Eigen { - -namespace internal { - -template<typename IndexDest, typename IndexSrc> -EIGEN_DEVICE_FUNC -inline IndexDest convert_index(const IndexSrc& idx) { - // for sizeof(IndexDest)>=sizeof(IndexSrc) compilers should be able to optimize this away: - eigen_internal_assert(idx <= NumTraits<IndexDest>::highest() && "Index value to big for target type"); - return IndexDest(idx); -} - -// true if T can be considered as an integral index (i.e., and integral type or enum) -template<typename T> struct is_valid_index_type -{ - enum { value = -#if EIGEN_HAS_TYPE_TRAITS - internal::is_integral<T>::value || std::is_enum<T>::value -#elif EIGEN_COMP_MSVC - internal::is_integral<T>::value || __is_enum(T) -#else - // without C++11, we use is_convertible to Index instead of is_integral in order to treat enums as Index. - internal::is_convertible<T,Index>::value && !internal::is_same<T,float>::value && !is_same<T,double>::value -#endif - }; -}; - -// true if both types are not valid index types -template<typename RowIndices, typename ColIndices> -struct valid_indexed_view_overload { - enum { value = !(internal::is_valid_index_type<RowIndices>::value && internal::is_valid_index_type<ColIndices>::value) }; -}; - -// promote_scalar_arg is an helper used in operation between an expression and a scalar, like: -// expression * scalar -// Its role is to determine how the type T of the scalar operand should be promoted given the scalar type ExprScalar of the given expression. -// The IsSupported template parameter must be provided by the caller as: internal::has_ReturnType<ScalarBinaryOpTraits<ExprScalar,T,op> >::value using the proper order for ExprScalar and T. -// Then the logic is as follows: -// - if the operation is natively supported as defined by IsSupported, then the scalar type is not promoted, and T is returned. -// - otherwise, NumTraits<ExprScalar>::Literal is returned if T is implicitly convertible to NumTraits<ExprScalar>::Literal AND that this does not imply a float to integer conversion. -// - otherwise, ExprScalar is returned if T is implicitly convertible to ExprScalar AND that this does not imply a float to integer conversion. -// - In all other cases, the promoted type is not defined, and the respective operation is thus invalid and not available (SFINAE). -template<typename ExprScalar,typename T, bool IsSupported> -struct promote_scalar_arg; - -template<typename S,typename T> -struct promote_scalar_arg<S,T,true> -{ - typedef T type; -}; - -// Recursively check safe conversion to PromotedType, and then ExprScalar if they are different. -template<typename ExprScalar,typename T,typename PromotedType, - bool ConvertibleToLiteral = internal::is_convertible<T,PromotedType>::value, - bool IsSafe = NumTraits<T>::IsInteger || !NumTraits<PromotedType>::IsInteger> -struct promote_scalar_arg_unsupported; - -// Start recursion with NumTraits<ExprScalar>::Literal -template<typename S,typename T> -struct promote_scalar_arg<S,T,false> : promote_scalar_arg_unsupported<S,T,typename NumTraits<S>::Literal> {}; - -// We found a match! -template<typename S,typename T, typename PromotedType> -struct promote_scalar_arg_unsupported<S,T,PromotedType,true,true> -{ - typedef PromotedType type; -}; - -// No match, but no real-to-integer issues, and ExprScalar and current PromotedType are different, -// so let's try to promote to ExprScalar -template<typename ExprScalar,typename T, typename PromotedType> -struct promote_scalar_arg_unsupported<ExprScalar,T,PromotedType,false,true> - : promote_scalar_arg_unsupported<ExprScalar,T,ExprScalar> -{}; - -// Unsafe real-to-integer, let's stop. -template<typename S,typename T, typename PromotedType, bool ConvertibleToLiteral> -struct promote_scalar_arg_unsupported<S,T,PromotedType,ConvertibleToLiteral,false> {}; - -// T is not even convertible to ExprScalar, let's stop. -template<typename S,typename T> -struct promote_scalar_arg_unsupported<S,T,S,false,true> {}; - -//classes inheriting no_assignment_operator don't generate a default operator=. -class no_assignment_operator -{ - private: - no_assignment_operator& operator=(const no_assignment_operator&); - protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(no_assignment_operator) - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(no_assignment_operator) -}; - -/** \internal return the index type with the largest number of bits */ -template<typename I1, typename I2> -struct promote_index_type -{ - typedef typename conditional<(sizeof(I1)<sizeof(I2)), I2, I1>::type type; -}; - -/** \internal If the template parameter Value is Dynamic, this class is just a wrapper around a T variable that - * can be accessed using value() and setValue(). - * Otherwise, this class is an empty structure and value() just returns the template parameter Value. - */ -template<typename T, int Value> class variable_if_dynamic -{ - public: - EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamic) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit variable_if_dynamic(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T value() { return T(Value); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator T() const { return T(Value); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void setValue(T) {} -}; - -template<typename T> class variable_if_dynamic<T, Dynamic> -{ - T m_value; - EIGEN_DEVICE_FUNC variable_if_dynamic() { eigen_assert(false); } - public: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit variable_if_dynamic(T value) : m_value(value) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T value() const { return m_value; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator T() const { return m_value; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void setValue(T value) { m_value = value; } -}; - -/** \internal like variable_if_dynamic but for DynamicIndex - */ -template<typename T, int Value> class variable_if_dynamicindex -{ - public: - EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamicindex) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit variable_if_dynamicindex(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T value() { return T(Value); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void setValue(T) {} -}; - -template<typename T> class variable_if_dynamicindex<T, DynamicIndex> -{ - T m_value; - EIGEN_DEVICE_FUNC variable_if_dynamicindex() { eigen_assert(false); } - public: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit variable_if_dynamicindex(T value) : m_value(value) {} - EIGEN_DEVICE_FUNC T EIGEN_STRONG_INLINE value() const { return m_value; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void setValue(T value) { m_value = value; } -}; - -template<typename T> struct functor_traits -{ - enum - { - Cost = 10, - PacketAccess = false, - IsRepeatable = false - }; -}; - -template<typename T> struct packet_traits; - -template<typename T> struct unpacket_traits -{ - typedef T type; - typedef T half; - enum - { - size = 1, - alignment = 1, - vectorizable = false, - masked_load_available=false, - masked_store_available=false - }; -}; - -template<int Size, typename PacketType, - bool Stop = Size==Dynamic || (Size%unpacket_traits<PacketType>::size)==0 || is_same<PacketType,typename unpacket_traits<PacketType>::half>::value> -struct find_best_packet_helper; - -template< int Size, typename PacketType> -struct find_best_packet_helper<Size,PacketType,true> -{ - typedef PacketType type; -}; - -template<int Size, typename PacketType> -struct find_best_packet_helper<Size,PacketType,false> -{ - typedef typename find_best_packet_helper<Size,typename unpacket_traits<PacketType>::half>::type type; -}; - -template<typename T, int Size> -struct find_best_packet -{ - typedef typename find_best_packet_helper<Size,typename packet_traits<T>::type>::type type; -}; - -#if EIGEN_MAX_STATIC_ALIGN_BYTES>0 -template<int ArrayBytes, int AlignmentBytes, - bool Match = bool((ArrayBytes%AlignmentBytes)==0), - bool TryHalf = bool(EIGEN_MIN_ALIGN_BYTES<AlignmentBytes) > -struct compute_default_alignment_helper -{ - enum { value = 0 }; -}; - -template<int ArrayBytes, int AlignmentBytes, bool TryHalf> -struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, true, TryHalf> // Match -{ - enum { value = AlignmentBytes }; -}; - -template<int ArrayBytes, int AlignmentBytes> -struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, false, true> // Try-half -{ - // current packet too large, try with an half-packet - enum { value = compute_default_alignment_helper<ArrayBytes, AlignmentBytes/2>::value }; -}; -#else -// If static alignment is disabled, no need to bother. -// This also avoids a division by zero in "bool Match = bool((ArrayBytes%AlignmentBytes)==0)" -template<int ArrayBytes, int AlignmentBytes> -struct compute_default_alignment_helper -{ - enum { value = 0 }; -}; -#endif - -template<typename T, int Size> struct compute_default_alignment { - enum { value = compute_default_alignment_helper<Size*sizeof(T),EIGEN_MAX_STATIC_ALIGN_BYTES>::value }; -}; - -template<typename T> struct compute_default_alignment<T,Dynamic> { - enum { value = EIGEN_MAX_ALIGN_BYTES }; -}; - -template<typename _Scalar, int _Rows, int _Cols, - int _Options = AutoAlign | - ( (_Rows==1 && _Cols!=1) ? RowMajor - : (_Cols==1 && _Rows!=1) ? ColMajor - : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ), - int _MaxRows = _Rows, - int _MaxCols = _Cols -> class make_proper_matrix_type -{ - enum { - IsColVector = _Cols==1 && _Rows!=1, - IsRowVector = _Rows==1 && _Cols!=1, - Options = IsColVector ? (_Options | ColMajor) & ~RowMajor - : IsRowVector ? (_Options | RowMajor) & ~ColMajor - : _Options - }; - public: - typedef Matrix<_Scalar, _Rows, _Cols, Options, _MaxRows, _MaxCols> type; -}; - -template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols> -class compute_matrix_flags -{ - enum { row_major_bit = Options&RowMajor ? RowMajorBit : 0 }; - public: - // FIXME currently we still have to handle DirectAccessBit at the expression level to handle DenseCoeffsBase<> - // and then propagate this information to the evaluator's flags. - // However, I (Gael) think that DirectAccessBit should only matter at the evaluation stage. - enum { ret = DirectAccessBit | LvalueBit | NestByRefBit | row_major_bit }; -}; - -template<int _Rows, int _Cols> struct size_at_compile_time -{ - enum { ret = (_Rows==Dynamic || _Cols==Dynamic) ? Dynamic : _Rows * _Cols }; -}; - -template<typename XprType> struct size_of_xpr_at_compile_time -{ - enum { ret = size_at_compile_time<traits<XprType>::RowsAtCompileTime,traits<XprType>::ColsAtCompileTime>::ret }; -}; - -/* plain_matrix_type : the difference from eval is that plain_matrix_type is always a plain matrix type, - * whereas eval is a const reference in the case of a matrix - */ - -template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct plain_matrix_type; -template<typename T, typename BaseClassType, int Flags> struct plain_matrix_type_dense; -template<typename T> struct plain_matrix_type<T,Dense> -{ - typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind, traits<T>::Flags>::type type; -}; -template<typename T> struct plain_matrix_type<T,DiagonalShape> -{ - typedef typename T::PlainObject type; -}; - -template<typename T, int Flags> struct plain_matrix_type_dense<T,MatrixXpr,Flags> -{ - typedef Matrix<typename traits<T>::Scalar, - traits<T>::RowsAtCompileTime, - traits<T>::ColsAtCompileTime, - AutoAlign | (Flags&RowMajorBit ? RowMajor : ColMajor), - traits<T>::MaxRowsAtCompileTime, - traits<T>::MaxColsAtCompileTime - > type; -}; - -template<typename T, int Flags> struct plain_matrix_type_dense<T,ArrayXpr,Flags> -{ - typedef Array<typename traits<T>::Scalar, - traits<T>::RowsAtCompileTime, - traits<T>::ColsAtCompileTime, - AutoAlign | (Flags&RowMajorBit ? RowMajor : ColMajor), - traits<T>::MaxRowsAtCompileTime, - traits<T>::MaxColsAtCompileTime - > type; -}; - -/* eval : the return type of eval(). For matrices, this is just a const reference - * in order to avoid a useless copy - */ - -template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct eval; - -template<typename T> struct eval<T,Dense> -{ - typedef typename plain_matrix_type<T>::type type; -// typedef typename T::PlainObject type; -// typedef T::Matrix<typename traits<T>::Scalar, -// traits<T>::RowsAtCompileTime, -// traits<T>::ColsAtCompileTime, -// AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor), -// traits<T>::MaxRowsAtCompileTime, -// traits<T>::MaxColsAtCompileTime -// > type; -}; - -template<typename T> struct eval<T,DiagonalShape> -{ - typedef typename plain_matrix_type<T>::type type; -}; - -// for matrices, no need to evaluate, just use a const reference to avoid a useless copy -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -struct eval<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense> -{ - typedef const Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type; -}; - -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -struct eval<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense> -{ - typedef const Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type; -}; - - -/* similar to plain_matrix_type, but using the evaluator's Flags */ -template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct plain_object_eval; - -template<typename T> -struct plain_object_eval<T,Dense> -{ - typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind, evaluator<T>::Flags>::type type; -}; - - -/* plain_matrix_type_column_major : same as plain_matrix_type but guaranteed to be column-major - */ -template<typename T> struct plain_matrix_type_column_major -{ - enum { Rows = traits<T>::RowsAtCompileTime, - Cols = traits<T>::ColsAtCompileTime, - MaxRows = traits<T>::MaxRowsAtCompileTime, - MaxCols = traits<T>::MaxColsAtCompileTime - }; - typedef Matrix<typename traits<T>::Scalar, - Rows, - Cols, - (MaxRows==1&&MaxCols!=1) ? RowMajor : ColMajor, - MaxRows, - MaxCols - > type; -}; - -/* plain_matrix_type_row_major : same as plain_matrix_type but guaranteed to be row-major - */ -template<typename T> struct plain_matrix_type_row_major -{ - enum { Rows = traits<T>::RowsAtCompileTime, - Cols = traits<T>::ColsAtCompileTime, - MaxRows = traits<T>::MaxRowsAtCompileTime, - MaxCols = traits<T>::MaxColsAtCompileTime - }; - typedef Matrix<typename traits<T>::Scalar, - Rows, - Cols, - (MaxCols==1&&MaxRows!=1) ? ColMajor : RowMajor, - MaxRows, - MaxCols - > type; -}; - -/** \internal The reference selector for template expressions. The idea is that we don't - * need to use references for expressions since they are light weight proxy - * objects which should generate no copying overhead. */ -template <typename T> -struct ref_selector -{ - typedef typename conditional< - bool(traits<T>::Flags & NestByRefBit), - T const&, - const T - >::type type; - - typedef typename conditional< - bool(traits<T>::Flags & NestByRefBit), - T &, - T - >::type non_const_type; -}; - -/** \internal Adds the const qualifier on the value-type of T2 if and only if T1 is a const type */ -template<typename T1, typename T2> -struct transfer_constness -{ - typedef typename conditional< - bool(internal::is_const<T1>::value), - typename internal::add_const_on_value_type<T2>::type, - T2 - >::type type; -}; - - -// However, we still need a mechanism to detect whether an expression which is evaluated multiple time -// has to be evaluated into a temporary. -// That's the purpose of this new nested_eval helper: -/** \internal Determines how a given expression should be nested when evaluated multiple times. - * For example, when you do a * (b+c), Eigen will determine how the expression b+c should be - * evaluated into the bigger product expression. The choice is between nesting the expression b+c as-is, or - * evaluating that expression b+c into a temporary variable d, and nest d so that the resulting expression is - * a*d. Evaluating can be beneficial for example if every coefficient access in the resulting expression causes - * many coefficient accesses in the nested expressions -- as is the case with matrix product for example. - * - * \tparam T the type of the expression being nested. - * \tparam n the number of coefficient accesses in the nested expression for each coefficient access in the bigger expression. - * \tparam PlainObject the type of the temporary if needed. - */ -template<typename T, int n, typename PlainObject = typename plain_object_eval<T>::type> struct nested_eval -{ - enum { - ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost, - CoeffReadCost = evaluator<T>::CoeffReadCost, // NOTE What if an evaluator evaluate itself into a temporary? - // Then CoeffReadCost will be small (e.g., 1) but we still have to evaluate, especially if n>1. - // This situation is already taken care by the EvalBeforeNestingBit flag, which is turned ON - // for all evaluator creating a temporary. This flag is then propagated by the parent evaluators. - // Another solution could be to count the number of temps? - NAsInteger = n == Dynamic ? HugeCost : n, - CostEval = (NAsInteger+1) * ScalarReadCost + CoeffReadCost, - CostNoEval = NAsInteger * CoeffReadCost, - Evaluate = (int(evaluator<T>::Flags) & EvalBeforeNestingBit) || (int(CostEval) < int(CostNoEval)) - }; - - typedef typename conditional<Evaluate, PlainObject, typename ref_selector<T>::type>::type type; -}; - -template<typename T> -EIGEN_DEVICE_FUNC -inline T* const_cast_ptr(const T* ptr) -{ - return const_cast<T*>(ptr); -} - -template<typename Derived, typename XprKind = typename traits<Derived>::XprKind> -struct dense_xpr_base -{ - /* dense_xpr_base should only ever be used on dense expressions, thus falling either into the MatrixXpr or into the ArrayXpr cases */ -}; - -template<typename Derived> -struct dense_xpr_base<Derived, MatrixXpr> -{ - typedef MatrixBase<Derived> type; -}; - -template<typename Derived> -struct dense_xpr_base<Derived, ArrayXpr> -{ - typedef ArrayBase<Derived> type; -}; - -template<typename Derived, typename XprKind = typename traits<Derived>::XprKind, typename StorageKind = typename traits<Derived>::StorageKind> -struct generic_xpr_base; - -template<typename Derived, typename XprKind> -struct generic_xpr_base<Derived, XprKind, Dense> -{ - typedef typename dense_xpr_base<Derived,XprKind>::type type; -}; - -template<typename XprType, typename CastType> struct cast_return_type -{ - typedef typename XprType::Scalar CurrentScalarType; - typedef typename remove_all<CastType>::type _CastType; - typedef typename _CastType::Scalar NewScalarType; - typedef typename conditional<is_same<CurrentScalarType,NewScalarType>::value, - const XprType&,CastType>::type type; -}; - -template <typename A, typename B> struct promote_storage_type; - -template <typename A> struct promote_storage_type<A,A> -{ - typedef A ret; -}; -template <typename A> struct promote_storage_type<A, const A> -{ - typedef A ret; -}; -template <typename A> struct promote_storage_type<const A, A> -{ - typedef A ret; -}; - -/** \internal Specify the "storage kind" of applying a coefficient-wise - * binary operations between two expressions of kinds A and B respectively. - * The template parameter Functor permits to specialize the resulting storage kind wrt to - * the functor. - * The default rules are as follows: - * \code - * A op A -> A - * A op dense -> dense - * dense op B -> dense - * sparse op dense -> sparse - * dense op sparse -> sparse - * \endcode - */ -template <typename A, typename B, typename Functor> struct cwise_promote_storage_type; - -template <typename A, typename Functor> struct cwise_promote_storage_type<A,A,Functor> { typedef A ret; }; -template <typename Functor> struct cwise_promote_storage_type<Dense,Dense,Functor> { typedef Dense ret; }; -template <typename A, typename Functor> struct cwise_promote_storage_type<A,Dense,Functor> { typedef Dense ret; }; -template <typename B, typename Functor> struct cwise_promote_storage_type<Dense,B,Functor> { typedef Dense ret; }; -template <typename Functor> struct cwise_promote_storage_type<Sparse,Dense,Functor> { typedef Sparse ret; }; -template <typename Functor> struct cwise_promote_storage_type<Dense,Sparse,Functor> { typedef Sparse ret; }; - -template <typename LhsKind, typename RhsKind, int LhsOrder, int RhsOrder> struct cwise_promote_storage_order { - enum { value = LhsOrder }; -}; - -template <typename LhsKind, int LhsOrder, int RhsOrder> struct cwise_promote_storage_order<LhsKind,Sparse,LhsOrder,RhsOrder> { enum { value = RhsOrder }; }; -template <typename RhsKind, int LhsOrder, int RhsOrder> struct cwise_promote_storage_order<Sparse,RhsKind,LhsOrder,RhsOrder> { enum { value = LhsOrder }; }; -template <int Order> struct cwise_promote_storage_order<Sparse,Sparse,Order,Order> { enum { value = Order }; }; - - -/** \internal Specify the "storage kind" of multiplying an expression of kind A with kind B. - * The template parameter ProductTag permits to specialize the resulting storage kind wrt to - * some compile-time properties of the product: GemmProduct, GemvProduct, OuterProduct, InnerProduct. - * The default rules are as follows: - * \code - * K * K -> K - * dense * K -> dense - * K * dense -> dense - * diag * K -> K - * K * diag -> K - * Perm * K -> K - * K * Perm -> K - * \endcode - */ -template <typename A, typename B, int ProductTag> struct product_promote_storage_type; - -template <typename A, int ProductTag> struct product_promote_storage_type<A, A, ProductTag> { typedef A ret;}; -template <int ProductTag> struct product_promote_storage_type<Dense, Dense, ProductTag> { typedef Dense ret;}; -template <typename A, int ProductTag> struct product_promote_storage_type<A, Dense, ProductTag> { typedef Dense ret; }; -template <typename B, int ProductTag> struct product_promote_storage_type<Dense, B, ProductTag> { typedef Dense ret; }; - -template <typename A, int ProductTag> struct product_promote_storage_type<A, DiagonalShape, ProductTag> { typedef A ret; }; -template <typename B, int ProductTag> struct product_promote_storage_type<DiagonalShape, B, ProductTag> { typedef B ret; }; -template <int ProductTag> struct product_promote_storage_type<Dense, DiagonalShape, ProductTag> { typedef Dense ret; }; -template <int ProductTag> struct product_promote_storage_type<DiagonalShape, Dense, ProductTag> { typedef Dense ret; }; - -template <typename A, int ProductTag> struct product_promote_storage_type<A, PermutationStorage, ProductTag> { typedef A ret; }; -template <typename B, int ProductTag> struct product_promote_storage_type<PermutationStorage, B, ProductTag> { typedef B ret; }; -template <int ProductTag> struct product_promote_storage_type<Dense, PermutationStorage, ProductTag> { typedef Dense ret; }; -template <int ProductTag> struct product_promote_storage_type<PermutationStorage, Dense, ProductTag> { typedef Dense ret; }; - -/** \internal gives the plain matrix or array type to store a row/column/diagonal of a matrix type. - * \tparam Scalar optional parameter allowing to pass a different scalar type than the one of the MatrixType. - */ -template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar> -struct plain_row_type -{ - typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime, - ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType; - typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime, - ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType; - - typedef typename conditional< - is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value, - MatrixRowType, - ArrayRowType - >::type type; -}; - -template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar> -struct plain_col_type -{ - typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1, - ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> MatrixColType; - typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1, - ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> ArrayColType; - - typedef typename conditional< - is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value, - MatrixColType, - ArrayColType - >::type type; -}; - -template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar> -struct plain_diag_type -{ - enum { diag_size = EIGEN_SIZE_MIN_PREFER_DYNAMIC(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime), - max_diag_size = EIGEN_SIZE_MIN_PREFER_FIXED(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime) - }; - typedef Matrix<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> MatrixDiagType; - typedef Array<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> ArrayDiagType; - - typedef typename conditional< - is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value, - MatrixDiagType, - ArrayDiagType - >::type type; -}; - -template<typename Expr,typename Scalar = typename Expr::Scalar> -struct plain_constant_type -{ - enum { Options = (traits<Expr>::Flags&RowMajorBit)?RowMajor:0 }; - - typedef Array<Scalar, traits<Expr>::RowsAtCompileTime, traits<Expr>::ColsAtCompileTime, - Options, traits<Expr>::MaxRowsAtCompileTime,traits<Expr>::MaxColsAtCompileTime> array_type; - - typedef Matrix<Scalar, traits<Expr>::RowsAtCompileTime, traits<Expr>::ColsAtCompileTime, - Options, traits<Expr>::MaxRowsAtCompileTime,traits<Expr>::MaxColsAtCompileTime> matrix_type; - - typedef CwiseNullaryOp<scalar_constant_op<Scalar>, const typename conditional<is_same< typename traits<Expr>::XprKind, MatrixXpr >::value, matrix_type, array_type>::type > type; -}; - -template<typename ExpressionType> -struct is_lvalue -{ - enum { value = (!bool(is_const<ExpressionType>::value)) && - bool(traits<ExpressionType>::Flags & LvalueBit) }; -}; - -template<typename T> struct is_diagonal -{ enum { ret = false }; }; - -template<typename T> struct is_diagonal<DiagonalBase<T> > -{ enum { ret = true }; }; - -template<typename T> struct is_diagonal<DiagonalWrapper<T> > -{ enum { ret = true }; }; - -template<typename T, int S> struct is_diagonal<DiagonalMatrix<T,S> > -{ enum { ret = true }; }; - - -template<typename T> struct is_identity -{ enum { value = false }; }; - -template<typename T> struct is_identity<CwiseNullaryOp<internal::scalar_identity_op<typename T::Scalar>, T> > -{ enum { value = true }; }; - - -template<typename S1, typename S2> struct glue_shapes; -template<> struct glue_shapes<DenseShape,TriangularShape> { typedef TriangularShape type; }; - -template<typename T1, typename T2> -struct possibly_same_dense { - enum { value = has_direct_access<T1>::ret && has_direct_access<T2>::ret && is_same<typename T1::Scalar,typename T2::Scalar>::value }; -}; - -template<typename T1, typename T2> -EIGEN_DEVICE_FUNC -bool is_same_dense(const T1 &mat1, const T2 &mat2, typename enable_if<possibly_same_dense<T1,T2>::value>::type * = 0) -{ - return (mat1.data()==mat2.data()) && (mat1.innerStride()==mat2.innerStride()) && (mat1.outerStride()==mat2.outerStride()); -} - -template<typename T1, typename T2> -EIGEN_DEVICE_FUNC -bool is_same_dense(const T1 &, const T2 &, typename enable_if<!possibly_same_dense<T1,T2>::value>::type * = 0) -{ - return false; -} - -// Internal helper defining the cost of a scalar division for the type T. -// The default heuristic can be specialized for each scalar type and architecture. -template<typename T,bool Vectorized=false,typename EnableIf = void> -struct scalar_div_cost { - enum { value = 8*NumTraits<T>::MulCost }; -}; - -template<typename T,bool Vectorized> -struct scalar_div_cost<std::complex<T>, Vectorized> { - enum { value = 2*scalar_div_cost<T>::value - + 6*NumTraits<T>::MulCost - + 3*NumTraits<T>::AddCost - }; -}; - - -template<bool Vectorized> -struct scalar_div_cost<signed long,Vectorized,typename conditional<sizeof(long)==8,void,false_type>::type> { enum { value = 24 }; }; -template<bool Vectorized> -struct scalar_div_cost<unsigned long,Vectorized,typename conditional<sizeof(long)==8,void,false_type>::type> { enum { value = 21 }; }; - - -#ifdef EIGEN_DEBUG_ASSIGN -std::string demangle_traversal(int t) -{ - if(t==DefaultTraversal) return "DefaultTraversal"; - if(t==LinearTraversal) return "LinearTraversal"; - if(t==InnerVectorizedTraversal) return "InnerVectorizedTraversal"; - if(t==LinearVectorizedTraversal) return "LinearVectorizedTraversal"; - if(t==SliceVectorizedTraversal) return "SliceVectorizedTraversal"; - return "?"; -} -std::string demangle_unrolling(int t) -{ - if(t==NoUnrolling) return "NoUnrolling"; - if(t==InnerUnrolling) return "InnerUnrolling"; - if(t==CompleteUnrolling) return "CompleteUnrolling"; - return "?"; -} -std::string demangle_flags(int f) -{ - std::string res; - if(f&RowMajorBit) res += " | RowMajor"; - if(f&PacketAccessBit) res += " | Packet"; - if(f&LinearAccessBit) res += " | Linear"; - if(f&LvalueBit) res += " | Lvalue"; - if(f&DirectAccessBit) res += " | Direct"; - if(f&NestByRefBit) res += " | NestByRef"; - if(f&NoPreferredStorageOrderBit) res += " | NoPreferredStorageOrderBit"; - - return res; -} -#endif - -} // end namespace internal - - -/** \class ScalarBinaryOpTraits - * \ingroup Core_Module - * - * \brief Determines whether the given binary operation of two numeric types is allowed and what the scalar return type is. - * - * This class permits to control the scalar return type of any binary operation performed on two different scalar types through (partial) template specializations. - * - * For instance, let \c U1, \c U2 and \c U3 be three user defined scalar types for which most operations between instances of \c U1 and \c U2 returns an \c U3. - * You can let %Eigen knows that by defining: - \code - template<typename BinaryOp> - struct ScalarBinaryOpTraits<U1,U2,BinaryOp> { typedef U3 ReturnType; }; - template<typename BinaryOp> - struct ScalarBinaryOpTraits<U2,U1,BinaryOp> { typedef U3 ReturnType; }; - \endcode - * You can then explicitly disable some particular operations to get more explicit error messages: - \code - template<> - struct ScalarBinaryOpTraits<U1,U2,internal::scalar_max_op<U1,U2> > {}; - \endcode - * Or customize the return type for individual operation: - \code - template<> - struct ScalarBinaryOpTraits<U1,U2,internal::scalar_sum_op<U1,U2> > { typedef U1 ReturnType; }; - \endcode - * - * By default, the following generic combinations are supported: - <table class="manual"> - <tr><th>ScalarA</th><th>ScalarB</th><th>BinaryOp</th><th>ReturnType</th><th>Note</th></tr> - <tr ><td>\c T </td><td>\c T </td><td>\c * </td><td>\c T </td><td></td></tr> - <tr class="alt"><td>\c NumTraits<T>::Real </td><td>\c T </td><td>\c * </td><td>\c T </td><td>Only if \c NumTraits<T>::IsComplex </td></tr> - <tr ><td>\c T </td><td>\c NumTraits<T>::Real </td><td>\c * </td><td>\c T </td><td>Only if \c NumTraits<T>::IsComplex </td></tr> - </table> - * - * \sa CwiseBinaryOp - */ -template<typename ScalarA, typename ScalarB, typename BinaryOp=internal::scalar_product_op<ScalarA,ScalarB> > -struct ScalarBinaryOpTraits -#ifndef EIGEN_PARSED_BY_DOXYGEN - // for backward compatibility, use the hints given by the (deprecated) internal::scalar_product_traits class. - : internal::scalar_product_traits<ScalarA,ScalarB> -#endif // EIGEN_PARSED_BY_DOXYGEN -{}; - -template<typename T, typename BinaryOp> -struct ScalarBinaryOpTraits<T,T,BinaryOp> -{ - typedef T ReturnType; -}; - -template <typename T, typename BinaryOp> -struct ScalarBinaryOpTraits<T, typename NumTraits<typename internal::enable_if<NumTraits<T>::IsComplex,T>::type>::Real, BinaryOp> -{ - typedef T ReturnType; -}; -template <typename T, typename BinaryOp> -struct ScalarBinaryOpTraits<typename NumTraits<typename internal::enable_if<NumTraits<T>::IsComplex,T>::type>::Real, T, BinaryOp> -{ - typedef T ReturnType; -}; - -// For Matrix * Permutation -template<typename T, typename BinaryOp> -struct ScalarBinaryOpTraits<T,void,BinaryOp> -{ - typedef T ReturnType; -}; - -// For Permutation * Matrix -template<typename T, typename BinaryOp> -struct ScalarBinaryOpTraits<void,T,BinaryOp> -{ - typedef T ReturnType; -}; - -// for Permutation*Permutation -template<typename BinaryOp> -struct ScalarBinaryOpTraits<void,void,BinaryOp> -{ - typedef void ReturnType; -}; - -// We require Lhs and Rhs to have "compatible" scalar types. -// It is tempting to always allow mixing different types but remember that this is often impossible in the vectorized paths. -// So allowing mixing different types gives very unexpected errors when enabling vectorization, when the user tries to -// add together a float matrix and a double matrix. -#define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP,LHS,RHS) \ - EIGEN_STATIC_ASSERT((Eigen::internal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS,BINOP> >::value), \ - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - -} // end namespace Eigen - -#endif // EIGEN_XPRHELPER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexEigenSolver.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexEigenSolver.h deleted file mode 100644 index 081e918f..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexEigenSolver.h +++ /dev/null @@ -1,346 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Claire Maurice -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX_EIGEN_SOLVER_H -#define EIGEN_COMPLEX_EIGEN_SOLVER_H - -#include "./ComplexSchur.h" - -namespace Eigen { - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class ComplexEigenSolver - * - * \brief Computes eigenvalues and eigenvectors of general complex matrices - * - * \tparam _MatrixType the type of the matrix of which we are - * computing the eigendecomposition; this is expected to be an - * instantiation of the Matrix class template. - * - * The eigenvalues and eigenvectors of a matrix \f$ A \f$ are scalars - * \f$ \lambda \f$ and vectors \f$ v \f$ such that \f$ Av = \lambda v - * \f$. If \f$ D \f$ is a diagonal matrix with the eigenvalues on - * the diagonal, and \f$ V \f$ is a matrix with the eigenvectors as - * its columns, then \f$ A V = V D \f$. The matrix \f$ V \f$ is - * almost always invertible, in which case we have \f$ A = V D V^{-1} - * \f$. This is called the eigendecomposition. - * - * The main function in this class is compute(), which computes the - * eigenvalues and eigenvectors of a given function. The - * documentation for that function contains an example showing the - * main features of the class. - * - * \sa class EigenSolver, class SelfAdjointEigenSolver - */ -template<typename _MatrixType> class ComplexEigenSolver -{ - public: - - /** \brief Synonym for the template parameter \p _MatrixType. */ - typedef _MatrixType MatrixType; - - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - Options = MatrixType::Options, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - /** \brief Scalar type for matrices of type #MatrixType. */ - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - /** \brief Complex scalar type for #MatrixType. - * - * This is \c std::complex<Scalar> if #Scalar is real (e.g., - * \c float or \c double) and just \c Scalar if #Scalar is - * complex. - */ - typedef std::complex<RealScalar> ComplexScalar; - - /** \brief Type for vector of eigenvalues as returned by eigenvalues(). - * - * This is a column vector with entries of type #ComplexScalar. - * The length of the vector is the size of #MatrixType. - */ - typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options&(~RowMajor), MaxColsAtCompileTime, 1> EigenvalueType; - - /** \brief Type for matrix of eigenvectors as returned by eigenvectors(). - * - * This is a square matrix with entries of type #ComplexScalar. - * The size is the same as the size of #MatrixType. - */ - typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> EigenvectorType; - - /** \brief Default constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via compute(). - */ - ComplexEigenSolver() - : m_eivec(), - m_eivalues(), - m_schur(), - m_isInitialized(false), - m_eigenvectorsOk(false), - m_matX() - {} - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa ComplexEigenSolver() - */ - explicit ComplexEigenSolver(Index size) - : m_eivec(size, size), - m_eivalues(size), - m_schur(size), - m_isInitialized(false), - m_eigenvectorsOk(false), - m_matX(size, size) - {} - - /** \brief Constructor; computes eigendecomposition of given matrix. - * - * \param[in] matrix Square matrix whose eigendecomposition is to be computed. - * \param[in] computeEigenvectors If true, both the eigenvectors and the - * eigenvalues are computed; if false, only the eigenvalues are - * computed. - * - * This constructor calls compute() to compute the eigendecomposition. - */ - template<typename InputType> - explicit ComplexEigenSolver(const EigenBase<InputType>& matrix, bool computeEigenvectors = true) - : m_eivec(matrix.rows(),matrix.cols()), - m_eivalues(matrix.cols()), - m_schur(matrix.rows()), - m_isInitialized(false), - m_eigenvectorsOk(false), - m_matX(matrix.rows(),matrix.cols()) - { - compute(matrix.derived(), computeEigenvectors); - } - - /** \brief Returns the eigenvectors of given matrix. - * - * \returns A const reference to the matrix whose columns are the eigenvectors. - * - * \pre Either the constructor - * ComplexEigenSolver(const MatrixType& matrix, bool) or the member - * function compute(const MatrixType& matrix, bool) has been called before - * to compute the eigendecomposition of a matrix, and - * \p computeEigenvectors was set to true (the default). - * - * This function returns a matrix whose columns are the eigenvectors. Column - * \f$ k \f$ is an eigenvector corresponding to eigenvalue number \f$ k - * \f$ as returned by eigenvalues(). The eigenvectors are normalized to - * have (Euclidean) norm equal to one. The matrix returned by this - * function is the matrix \f$ V \f$ in the eigendecomposition \f$ A = V D - * V^{-1} \f$, if it exists. - * - * Example: \include ComplexEigenSolver_eigenvectors.cpp - * Output: \verbinclude ComplexEigenSolver_eigenvectors.out - */ - const EigenvectorType& eigenvectors() const - { - eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - return m_eivec; - } - - /** \brief Returns the eigenvalues of given matrix. - * - * \returns A const reference to the column vector containing the eigenvalues. - * - * \pre Either the constructor - * ComplexEigenSolver(const MatrixType& matrix, bool) or the member - * function compute(const MatrixType& matrix, bool) has been called before - * to compute the eigendecomposition of a matrix. - * - * This function returns a column vector containing the - * eigenvalues. Eigenvalues are repeated according to their - * algebraic multiplicity, so there are as many eigenvalues as - * rows in the matrix. The eigenvalues are not sorted in any particular - * order. - * - * Example: \include ComplexEigenSolver_eigenvalues.cpp - * Output: \verbinclude ComplexEigenSolver_eigenvalues.out - */ - const EigenvalueType& eigenvalues() const - { - eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized."); - return m_eivalues; - } - - /** \brief Computes eigendecomposition of given matrix. - * - * \param[in] matrix Square matrix whose eigendecomposition is to be computed. - * \param[in] computeEigenvectors If true, both the eigenvectors and the - * eigenvalues are computed; if false, only the eigenvalues are - * computed. - * \returns Reference to \c *this - * - * This function computes the eigenvalues of the complex matrix \p matrix. - * The eigenvalues() function can be used to retrieve them. If - * \p computeEigenvectors is true, then the eigenvectors are also computed - * and can be retrieved by calling eigenvectors(). - * - * The matrix is first reduced to Schur form using the - * ComplexSchur class. The Schur decomposition is then used to - * compute the eigenvalues and eigenvectors. - * - * The cost of the computation is dominated by the cost of the - * Schur decomposition, which is \f$ O(n^3) \f$ where \f$ n \f$ - * is the size of the matrix. - * - * Example: \include ComplexEigenSolver_compute.cpp - * Output: \verbinclude ComplexEigenSolver_compute.out - */ - template<typename InputType> - ComplexEigenSolver& compute(const EigenBase<InputType>& matrix, bool computeEigenvectors = true); - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, \c NoConvergence otherwise. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized."); - return m_schur.info(); - } - - /** \brief Sets the maximum number of iterations allowed. */ - ComplexEigenSolver& setMaxIterations(Index maxIters) - { - m_schur.setMaxIterations(maxIters); - return *this; - } - - /** \brief Returns the maximum number of iterations. */ - Index getMaxIterations() - { - return m_schur.getMaxIterations(); - } - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - EigenvectorType m_eivec; - EigenvalueType m_eivalues; - ComplexSchur<MatrixType> m_schur; - bool m_isInitialized; - bool m_eigenvectorsOk; - EigenvectorType m_matX; - - private: - void doComputeEigenvectors(RealScalar matrixnorm); - void sortEigenvalues(bool computeEigenvectors); -}; - - -template<typename MatrixType> -template<typename InputType> -ComplexEigenSolver<MatrixType>& -ComplexEigenSolver<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeEigenvectors) -{ - check_template_parameters(); - - // this code is inspired from Jampack - eigen_assert(matrix.cols() == matrix.rows()); - - // Do a complex Schur decomposition, A = U T U^* - // The eigenvalues are on the diagonal of T. - m_schur.compute(matrix.derived(), computeEigenvectors); - - if(m_schur.info() == Success) - { - m_eivalues = m_schur.matrixT().diagonal(); - if(computeEigenvectors) - doComputeEigenvectors(m_schur.matrixT().norm()); - sortEigenvalues(computeEigenvectors); - } - - m_isInitialized = true; - m_eigenvectorsOk = computeEigenvectors; - return *this; -} - - -template<typename MatrixType> -void ComplexEigenSolver<MatrixType>::doComputeEigenvectors(RealScalar matrixnorm) -{ - const Index n = m_eivalues.size(); - - matrixnorm = numext::maxi(matrixnorm,(std::numeric_limits<RealScalar>::min)()); - - // Compute X such that T = X D X^(-1), where D is the diagonal of T. - // The matrix X is unit triangular. - m_matX = EigenvectorType::Zero(n, n); - for(Index k=n-1 ; k>=0 ; k--) - { - m_matX.coeffRef(k,k) = ComplexScalar(1.0,0.0); - // Compute X(i,k) using the (i,k) entry of the equation X T = D X - for(Index i=k-1 ; i>=0 ; i--) - { - m_matX.coeffRef(i,k) = -m_schur.matrixT().coeff(i,k); - if(k-i-1>0) - m_matX.coeffRef(i,k) -= (m_schur.matrixT().row(i).segment(i+1,k-i-1) * m_matX.col(k).segment(i+1,k-i-1)).value(); - ComplexScalar z = m_schur.matrixT().coeff(i,i) - m_schur.matrixT().coeff(k,k); - if(z==ComplexScalar(0)) - { - // If the i-th and k-th eigenvalue are equal, then z equals 0. - // Use a small value instead, to prevent division by zero. - numext::real_ref(z) = NumTraits<RealScalar>::epsilon() * matrixnorm; - } - m_matX.coeffRef(i,k) = m_matX.coeff(i,k) / z; - } - } - - // Compute V as V = U X; now A = U T U^* = U X D X^(-1) U^* = V D V^(-1) - m_eivec.noalias() = m_schur.matrixU() * m_matX; - // .. and normalize the eigenvectors - for(Index k=0 ; k<n ; k++) - { - m_eivec.col(k).normalize(); - } -} - - -template<typename MatrixType> -void ComplexEigenSolver<MatrixType>::sortEigenvalues(bool computeEigenvectors) -{ - const Index n = m_eivalues.size(); - for (Index i=0; i<n; i++) - { - Index k; - m_eivalues.cwiseAbs().tail(n-i).minCoeff(&k); - if (k != 0) - { - k += i; - std::swap(m_eivalues[k],m_eivalues[i]); - if(computeEigenvectors) - m_eivec.col(i).swap(m_eivec.col(k)); - } - } -} - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_EIGEN_SOLVER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexSchur.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexSchur.h deleted file mode 100644 index fc71468f..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexSchur.h +++ /dev/null @@ -1,462 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Claire Maurice -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLEX_SCHUR_H -#define EIGEN_COMPLEX_SCHUR_H - -#include "./HessenbergDecomposition.h" - -namespace Eigen { - -namespace internal { -template<typename MatrixType, bool IsComplex> struct complex_schur_reduce_to_hessenberg; -} - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class ComplexSchur - * - * \brief Performs a complex Schur decomposition of a real or complex square matrix - * - * \tparam _MatrixType the type of the matrix of which we are - * computing the Schur decomposition; this is expected to be an - * instantiation of the Matrix class template. - * - * Given a real or complex square matrix A, this class computes the - * Schur decomposition: \f$ A = U T U^*\f$ where U is a unitary - * complex matrix, and T is a complex upper triangular matrix. The - * diagonal of the matrix T corresponds to the eigenvalues of the - * matrix A. - * - * Call the function compute() to compute the Schur decomposition of - * a given matrix. Alternatively, you can use the - * ComplexSchur(const MatrixType&, bool) constructor which computes - * the Schur decomposition at construction time. Once the - * decomposition is computed, you can use the matrixU() and matrixT() - * functions to retrieve the matrices U and V in the decomposition. - * - * \note This code is inspired from Jampack - * - * \sa class RealSchur, class EigenSolver, class ComplexEigenSolver - */ -template<typename _MatrixType> class ComplexSchur -{ - public: - typedef _MatrixType MatrixType; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - Options = MatrixType::Options, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - /** \brief Scalar type for matrices of type \p _MatrixType. */ - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - /** \brief Complex scalar type for \p _MatrixType. - * - * This is \c std::complex<Scalar> if #Scalar is real (e.g., - * \c float or \c double) and just \c Scalar if #Scalar is - * complex. - */ - typedef std::complex<RealScalar> ComplexScalar; - - /** \brief Type for the matrices in the Schur decomposition. - * - * This is a square matrix with entries of type #ComplexScalar. - * The size is the same as the size of \p _MatrixType. - */ - typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> ComplexMatrixType; - - /** \brief Default constructor. - * - * \param [in] size Positive integer, size of the matrix whose Schur decomposition will be computed. - * - * The default constructor is useful in cases in which the user - * intends to perform decompositions via compute(). The \p size - * parameter is only used as a hint. It is not an error to give a - * wrong \p size, but it may impair performance. - * - * \sa compute() for an example. - */ - explicit ComplexSchur(Index size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime) - : m_matT(size,size), - m_matU(size,size), - m_hess(size), - m_isInitialized(false), - m_matUisUptodate(false), - m_maxIters(-1) - {} - - /** \brief Constructor; computes Schur decomposition of given matrix. - * - * \param[in] matrix Square matrix whose Schur decomposition is to be computed. - * \param[in] computeU If true, both T and U are computed; if false, only T is computed. - * - * This constructor calls compute() to compute the Schur decomposition. - * - * \sa matrixT() and matrixU() for examples. - */ - template<typename InputType> - explicit ComplexSchur(const EigenBase<InputType>& matrix, bool computeU = true) - : m_matT(matrix.rows(),matrix.cols()), - m_matU(matrix.rows(),matrix.cols()), - m_hess(matrix.rows()), - m_isInitialized(false), - m_matUisUptodate(false), - m_maxIters(-1) - { - compute(matrix.derived(), computeU); - } - - /** \brief Returns the unitary matrix in the Schur decomposition. - * - * \returns A const reference to the matrix U. - * - * It is assumed that either the constructor - * ComplexSchur(const MatrixType& matrix, bool computeU) or the - * member function compute(const MatrixType& matrix, bool computeU) - * has been called before to compute the Schur decomposition of a - * matrix, and that \p computeU was set to true (the default - * value). - * - * Example: \include ComplexSchur_matrixU.cpp - * Output: \verbinclude ComplexSchur_matrixU.out - */ - const ComplexMatrixType& matrixU() const - { - eigen_assert(m_isInitialized && "ComplexSchur is not initialized."); - eigen_assert(m_matUisUptodate && "The matrix U has not been computed during the ComplexSchur decomposition."); - return m_matU; - } - - /** \brief Returns the triangular matrix in the Schur decomposition. - * - * \returns A const reference to the matrix T. - * - * It is assumed that either the constructor - * ComplexSchur(const MatrixType& matrix, bool computeU) or the - * member function compute(const MatrixType& matrix, bool computeU) - * has been called before to compute the Schur decomposition of a - * matrix. - * - * Note that this function returns a plain square matrix. If you want to reference - * only the upper triangular part, use: - * \code schur.matrixT().triangularView<Upper>() \endcode - * - * Example: \include ComplexSchur_matrixT.cpp - * Output: \verbinclude ComplexSchur_matrixT.out - */ - const ComplexMatrixType& matrixT() const - { - eigen_assert(m_isInitialized && "ComplexSchur is not initialized."); - return m_matT; - } - - /** \brief Computes Schur decomposition of given matrix. - * - * \param[in] matrix Square matrix whose Schur decomposition is to be computed. - * \param[in] computeU If true, both T and U are computed; if false, only T is computed. - - * \returns Reference to \c *this - * - * The Schur decomposition is computed by first reducing the - * matrix to Hessenberg form using the class - * HessenbergDecomposition. The Hessenberg matrix is then reduced - * to triangular form by performing QR iterations with a single - * shift. The cost of computing the Schur decomposition depends - * on the number of iterations; as a rough guide, it may be taken - * on the number of iterations; as a rough guide, it may be taken - * to be \f$25n^3\f$ complex flops, or \f$10n^3\f$ complex flops - * if \a computeU is false. - * - * Example: \include ComplexSchur_compute.cpp - * Output: \verbinclude ComplexSchur_compute.out - * - * \sa compute(const MatrixType&, bool, Index) - */ - template<typename InputType> - ComplexSchur& compute(const EigenBase<InputType>& matrix, bool computeU = true); - - /** \brief Compute Schur decomposition from a given Hessenberg matrix - * \param[in] matrixH Matrix in Hessenberg form H - * \param[in] matrixQ orthogonal matrix Q that transform a matrix A to H : A = Q H Q^T - * \param computeU Computes the matriX U of the Schur vectors - * \return Reference to \c *this - * - * This routine assumes that the matrix is already reduced in Hessenberg form matrixH - * using either the class HessenbergDecomposition or another mean. - * It computes the upper quasi-triangular matrix T of the Schur decomposition of H - * When computeU is true, this routine computes the matrix U such that - * A = U T U^T = (QZ) T (QZ)^T = Q H Q^T where A is the initial matrix - * - * NOTE Q is referenced if computeU is true; so, if the initial orthogonal matrix - * is not available, the user should give an identity matrix (Q.setIdentity()) - * - * \sa compute(const MatrixType&, bool) - */ - template<typename HessMatrixType, typename OrthMatrixType> - ComplexSchur& computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU=true); - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, \c NoConvergence otherwise. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "ComplexSchur is not initialized."); - return m_info; - } - - /** \brief Sets the maximum number of iterations allowed. - * - * If not specified by the user, the maximum number of iterations is m_maxIterationsPerRow times the size - * of the matrix. - */ - ComplexSchur& setMaxIterations(Index maxIters) - { - m_maxIters = maxIters; - return *this; - } - - /** \brief Returns the maximum number of iterations. */ - Index getMaxIterations() - { - return m_maxIters; - } - - /** \brief Maximum number of iterations per row. - * - * If not otherwise specified, the maximum number of iterations is this number times the size of the - * matrix. It is currently set to 30. - */ - static const int m_maxIterationsPerRow = 30; - - protected: - ComplexMatrixType m_matT, m_matU; - HessenbergDecomposition<MatrixType> m_hess; - ComputationInfo m_info; - bool m_isInitialized; - bool m_matUisUptodate; - Index m_maxIters; - - private: - bool subdiagonalEntryIsNeglegible(Index i); - ComplexScalar computeShift(Index iu, Index iter); - void reduceToTriangularForm(bool computeU); - friend struct internal::complex_schur_reduce_to_hessenberg<MatrixType, NumTraits<Scalar>::IsComplex>; -}; - -/** If m_matT(i+1,i) is neglegible in floating point arithmetic - * compared to m_matT(i,i) and m_matT(j,j), then set it to zero and - * return true, else return false. */ -template<typename MatrixType> -inline bool ComplexSchur<MatrixType>::subdiagonalEntryIsNeglegible(Index i) -{ - RealScalar d = numext::norm1(m_matT.coeff(i,i)) + numext::norm1(m_matT.coeff(i+1,i+1)); - RealScalar sd = numext::norm1(m_matT.coeff(i+1,i)); - if (internal::isMuchSmallerThan(sd, d, NumTraits<RealScalar>::epsilon())) - { - m_matT.coeffRef(i+1,i) = ComplexScalar(0); - return true; - } - return false; -} - - -/** Compute the shift in the current QR iteration. */ -template<typename MatrixType> -typename ComplexSchur<MatrixType>::ComplexScalar ComplexSchur<MatrixType>::computeShift(Index iu, Index iter) -{ - using std::abs; - if (iter == 10 || iter == 20) - { - // exceptional shift, taken from http://www.netlib.org/eispack/comqr.f - return abs(numext::real(m_matT.coeff(iu,iu-1))) + abs(numext::real(m_matT.coeff(iu-1,iu-2))); - } - - // compute the shift as one of the eigenvalues of t, the 2x2 - // diagonal block on the bottom of the active submatrix - Matrix<ComplexScalar,2,2> t = m_matT.template block<2,2>(iu-1,iu-1); - RealScalar normt = t.cwiseAbs().sum(); - t /= normt; // the normalization by sf is to avoid under/overflow - - ComplexScalar b = t.coeff(0,1) * t.coeff(1,0); - ComplexScalar c = t.coeff(0,0) - t.coeff(1,1); - ComplexScalar disc = sqrt(c*c + RealScalar(4)*b); - ComplexScalar det = t.coeff(0,0) * t.coeff(1,1) - b; - ComplexScalar trace = t.coeff(0,0) + t.coeff(1,1); - ComplexScalar eival1 = (trace + disc) / RealScalar(2); - ComplexScalar eival2 = (trace - disc) / RealScalar(2); - RealScalar eival1_norm = numext::norm1(eival1); - RealScalar eival2_norm = numext::norm1(eival2); - // A division by zero can only occur if eival1==eival2==0. - // In this case, det==0, and all we have to do is checking that eival2_norm!=0 - if(eival1_norm > eival2_norm) - eival2 = det / eival1; - else if(eival2_norm!=RealScalar(0)) - eival1 = det / eival2; - - // choose the eigenvalue closest to the bottom entry of the diagonal - if(numext::norm1(eival1-t.coeff(1,1)) < numext::norm1(eival2-t.coeff(1,1))) - return normt * eival1; - else - return normt * eival2; -} - - -template<typename MatrixType> -template<typename InputType> -ComplexSchur<MatrixType>& ComplexSchur<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeU) -{ - m_matUisUptodate = false; - eigen_assert(matrix.cols() == matrix.rows()); - - if(matrix.cols() == 1) - { - m_matT = matrix.derived().template cast<ComplexScalar>(); - if(computeU) m_matU = ComplexMatrixType::Identity(1,1); - m_info = Success; - m_isInitialized = true; - m_matUisUptodate = computeU; - return *this; - } - - internal::complex_schur_reduce_to_hessenberg<MatrixType, NumTraits<Scalar>::IsComplex>::run(*this, matrix.derived(), computeU); - computeFromHessenberg(m_matT, m_matU, computeU); - return *this; -} - -template<typename MatrixType> -template<typename HessMatrixType, typename OrthMatrixType> -ComplexSchur<MatrixType>& ComplexSchur<MatrixType>::computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU) -{ - m_matT = matrixH; - if(computeU) - m_matU = matrixQ; - reduceToTriangularForm(computeU); - return *this; -} -namespace internal { - -/* Reduce given matrix to Hessenberg form */ -template<typename MatrixType, bool IsComplex> -struct complex_schur_reduce_to_hessenberg -{ - // this is the implementation for the case IsComplex = true - static void run(ComplexSchur<MatrixType>& _this, const MatrixType& matrix, bool computeU) - { - _this.m_hess.compute(matrix); - _this.m_matT = _this.m_hess.matrixH(); - if(computeU) _this.m_matU = _this.m_hess.matrixQ(); - } -}; - -template<typename MatrixType> -struct complex_schur_reduce_to_hessenberg<MatrixType, false> -{ - static void run(ComplexSchur<MatrixType>& _this, const MatrixType& matrix, bool computeU) - { - typedef typename ComplexSchur<MatrixType>::ComplexScalar ComplexScalar; - - // Note: m_hess is over RealScalar; m_matT and m_matU is over ComplexScalar - _this.m_hess.compute(matrix); - _this.m_matT = _this.m_hess.matrixH().template cast<ComplexScalar>(); - if(computeU) - { - // This may cause an allocation which seems to be avoidable - MatrixType Q = _this.m_hess.matrixQ(); - _this.m_matU = Q.template cast<ComplexScalar>(); - } - } -}; - -} // end namespace internal - -// Reduce the Hessenberg matrix m_matT to triangular form by QR iteration. -template<typename MatrixType> -void ComplexSchur<MatrixType>::reduceToTriangularForm(bool computeU) -{ - Index maxIters = m_maxIters; - if (maxIters == -1) - maxIters = m_maxIterationsPerRow * m_matT.rows(); - - // The matrix m_matT is divided in three parts. - // Rows 0,...,il-1 are decoupled from the rest because m_matT(il,il-1) is zero. - // Rows il,...,iu is the part we are working on (the active submatrix). - // Rows iu+1,...,end are already brought in triangular form. - Index iu = m_matT.cols() - 1; - Index il; - Index iter = 0; // number of iterations we are working on the (iu,iu) element - Index totalIter = 0; // number of iterations for whole matrix - - while(true) - { - // find iu, the bottom row of the active submatrix - while(iu > 0) - { - if(!subdiagonalEntryIsNeglegible(iu-1)) break; - iter = 0; - --iu; - } - - // if iu is zero then we are done; the whole matrix is triangularized - if(iu==0) break; - - // if we spent too many iterations, we give up - iter++; - totalIter++; - if(totalIter > maxIters) break; - - // find il, the top row of the active submatrix - il = iu-1; - while(il > 0 && !subdiagonalEntryIsNeglegible(il-1)) - { - --il; - } - - /* perform the QR step using Givens rotations. The first rotation - creates a bulge; the (il+2,il) element becomes nonzero. This - bulge is chased down to the bottom of the active submatrix. */ - - ComplexScalar shift = computeShift(iu, iter); - JacobiRotation<ComplexScalar> rot; - rot.makeGivens(m_matT.coeff(il,il) - shift, m_matT.coeff(il+1,il)); - m_matT.rightCols(m_matT.cols()-il).applyOnTheLeft(il, il+1, rot.adjoint()); - m_matT.topRows((std::min)(il+2,iu)+1).applyOnTheRight(il, il+1, rot); - if(computeU) m_matU.applyOnTheRight(il, il+1, rot); - - for(Index i=il+1 ; i<iu ; i++) - { - rot.makeGivens(m_matT.coeffRef(i,i-1), m_matT.coeffRef(i+1,i-1), &m_matT.coeffRef(i,i-1)); - m_matT.coeffRef(i+1,i-1) = ComplexScalar(0); - m_matT.rightCols(m_matT.cols()-i).applyOnTheLeft(i, i+1, rot.adjoint()); - m_matT.topRows((std::min)(i+2,iu)+1).applyOnTheRight(i, i+1, rot); - if(computeU) m_matU.applyOnTheRight(i, i+1, rot); - } - } - - if(totalIter <= maxIters) - m_info = Success; - else - m_info = NoConvergence; - - m_isInitialized = true; - m_matUisUptodate = computeU; -} - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_SCHUR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h deleted file mode 100644 index 4980a3ed..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to LAPACKe - * Complex Schur needed to complex unsymmetrical eigenvalues/eigenvectors. - ******************************************************************************** -*/ - -#ifndef EIGEN_COMPLEX_SCHUR_LAPACKE_H -#define EIGEN_COMPLEX_SCHUR_LAPACKE_H - -namespace Eigen { - -/** \internal Specialization for the data types supported by LAPACKe */ - -#define EIGEN_LAPACKE_SCHUR_COMPLEX(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, LAPACKE_PREFIX_U, EIGCOLROW, LAPACKE_COLROW) \ -template<> template<typename InputType> inline \ -ComplexSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >& \ -ComplexSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >::compute(const EigenBase<InputType>& matrix, bool computeU) \ -{ \ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> MatrixType; \ - typedef MatrixType::RealScalar RealScalar; \ - typedef std::complex<RealScalar> ComplexScalar; \ -\ - eigen_assert(matrix.cols() == matrix.rows()); \ -\ - m_matUisUptodate = false; \ - if(matrix.cols() == 1) \ - { \ - m_matT = matrix.derived().template cast<ComplexScalar>(); \ - if(computeU) m_matU = ComplexMatrixType::Identity(1,1); \ - m_info = Success; \ - m_isInitialized = true; \ - m_matUisUptodate = computeU; \ - return *this; \ - } \ - lapack_int n = internal::convert_index<lapack_int>(matrix.cols()), sdim, info; \ - lapack_int matrix_order = LAPACKE_COLROW; \ - char jobvs, sort='N'; \ - LAPACK_##LAPACKE_PREFIX_U##_SELECT1 select = 0; \ - jobvs = (computeU) ? 'V' : 'N'; \ - m_matU.resize(n, n); \ - lapack_int ldvs = internal::convert_index<lapack_int>(m_matU.outerStride()); \ - m_matT = matrix; \ - lapack_int lda = internal::convert_index<lapack_int>(m_matT.outerStride()); \ - Matrix<EIGTYPE, Dynamic, Dynamic> w; \ - w.resize(n, 1);\ - info = LAPACKE_##LAPACKE_PREFIX##gees( matrix_order, jobvs, sort, select, n, (LAPACKE_TYPE*)m_matT.data(), lda, &sdim, (LAPACKE_TYPE*)w.data(), (LAPACKE_TYPE*)m_matU.data(), ldvs ); \ - if(info == 0) \ - m_info = Success; \ - else \ - m_info = NoConvergence; \ -\ - m_isInitialized = true; \ - m_matUisUptodate = computeU; \ - return *this; \ -\ -} - -EIGEN_LAPACKE_SCHUR_COMPLEX(dcomplex, lapack_complex_double, z, Z, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_SCHUR_COMPLEX(scomplex, lapack_complex_float, c, C, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_SCHUR_COMPLEX(dcomplex, lapack_complex_double, z, Z, RowMajor, LAPACK_ROW_MAJOR) -EIGEN_LAPACKE_SCHUR_COMPLEX(scomplex, lapack_complex_float, c, C, RowMajor, LAPACK_ROW_MAJOR) - -} // end namespace Eigen - -#endif // EIGEN_COMPLEX_SCHUR_LAPACKE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/EigenSolver.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/EigenSolver.h deleted file mode 100644 index 572b29e4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/EigenSolver.h +++ /dev/null @@ -1,622 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_EIGENSOLVER_H -#define EIGEN_EIGENSOLVER_H - -#include "./RealSchur.h" - -namespace Eigen { - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class EigenSolver - * - * \brief Computes eigenvalues and eigenvectors of general matrices - * - * \tparam _MatrixType the type of the matrix of which we are computing the - * eigendecomposition; this is expected to be an instantiation of the Matrix - * class template. Currently, only real matrices are supported. - * - * The eigenvalues and eigenvectors of a matrix \f$ A \f$ are scalars - * \f$ \lambda \f$ and vectors \f$ v \f$ such that \f$ Av = \lambda v \f$. If - * \f$ D \f$ is a diagonal matrix with the eigenvalues on the diagonal, and - * \f$ V \f$ is a matrix with the eigenvectors as its columns, then \f$ A V = - * V D \f$. The matrix \f$ V \f$ is almost always invertible, in which case we - * have \f$ A = V D V^{-1} \f$. This is called the eigendecomposition. - * - * The eigenvalues and eigenvectors of a matrix may be complex, even when the - * matrix is real. However, we can choose real matrices \f$ V \f$ and \f$ D - * \f$ satisfying \f$ A V = V D \f$, just like the eigendecomposition, if the - * matrix \f$ D \f$ is not required to be diagonal, but if it is allowed to - * have blocks of the form - * \f[ \begin{bmatrix} u & v \\ -v & u \end{bmatrix} \f] - * (where \f$ u \f$ and \f$ v \f$ are real numbers) on the diagonal. These - * blocks correspond to complex eigenvalue pairs \f$ u \pm iv \f$. We call - * this variant of the eigendecomposition the pseudo-eigendecomposition. - * - * Call the function compute() to compute the eigenvalues and eigenvectors of - * a given matrix. Alternatively, you can use the - * EigenSolver(const MatrixType&, bool) constructor which computes the - * eigenvalues and eigenvectors at construction time. Once the eigenvalue and - * eigenvectors are computed, they can be retrieved with the eigenvalues() and - * eigenvectors() functions. The pseudoEigenvalueMatrix() and - * pseudoEigenvectors() methods allow the construction of the - * pseudo-eigendecomposition. - * - * The documentation for EigenSolver(const MatrixType&, bool) contains an - * example of the typical use of this class. - * - * \note The implementation is adapted from - * <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> (public domain). - * Their code is based on EISPACK. - * - * \sa MatrixBase::eigenvalues(), class ComplexEigenSolver, class SelfAdjointEigenSolver - */ -template<typename _MatrixType> class EigenSolver -{ - public: - - /** \brief Synonym for the template parameter \p _MatrixType. */ - typedef _MatrixType MatrixType; - - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - Options = MatrixType::Options, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - /** \brief Scalar type for matrices of type #MatrixType. */ - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - /** \brief Complex scalar type for #MatrixType. - * - * This is \c std::complex<Scalar> if #Scalar is real (e.g., - * \c float or \c double) and just \c Scalar if #Scalar is - * complex. - */ - typedef std::complex<RealScalar> ComplexScalar; - - /** \brief Type for vector of eigenvalues as returned by eigenvalues(). - * - * This is a column vector with entries of type #ComplexScalar. - * The length of the vector is the size of #MatrixType. - */ - typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> EigenvalueType; - - /** \brief Type for matrix of eigenvectors as returned by eigenvectors(). - * - * This is a square matrix with entries of type #ComplexScalar. - * The size is the same as the size of #MatrixType. - */ - typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> EigenvectorsType; - - /** \brief Default constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via EigenSolver::compute(const MatrixType&, bool). - * - * \sa compute() for an example. - */ - EigenSolver() : m_eivec(), m_eivalues(), m_isInitialized(false), m_eigenvectorsOk(false), m_realSchur(), m_matT(), m_tmp() {} - - /** \brief Default constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa EigenSolver() - */ - explicit EigenSolver(Index size) - : m_eivec(size, size), - m_eivalues(size), - m_isInitialized(false), - m_eigenvectorsOk(false), - m_realSchur(size), - m_matT(size, size), - m_tmp(size) - {} - - /** \brief Constructor; computes eigendecomposition of given matrix. - * - * \param[in] matrix Square matrix whose eigendecomposition is to be computed. - * \param[in] computeEigenvectors If true, both the eigenvectors and the - * eigenvalues are computed; if false, only the eigenvalues are - * computed. - * - * This constructor calls compute() to compute the eigenvalues - * and eigenvectors. - * - * Example: \include EigenSolver_EigenSolver_MatrixType.cpp - * Output: \verbinclude EigenSolver_EigenSolver_MatrixType.out - * - * \sa compute() - */ - template<typename InputType> - explicit EigenSolver(const EigenBase<InputType>& matrix, bool computeEigenvectors = true) - : m_eivec(matrix.rows(), matrix.cols()), - m_eivalues(matrix.cols()), - m_isInitialized(false), - m_eigenvectorsOk(false), - m_realSchur(matrix.cols()), - m_matT(matrix.rows(), matrix.cols()), - m_tmp(matrix.cols()) - { - compute(matrix.derived(), computeEigenvectors); - } - - /** \brief Returns the eigenvectors of given matrix. - * - * \returns %Matrix whose columns are the (possibly complex) eigenvectors. - * - * \pre Either the constructor - * EigenSolver(const MatrixType&,bool) or the member function - * compute(const MatrixType&, bool) has been called before, and - * \p computeEigenvectors was set to true (the default). - * - * Column \f$ k \f$ of the returned matrix is an eigenvector corresponding - * to eigenvalue number \f$ k \f$ as returned by eigenvalues(). The - * eigenvectors are normalized to have (Euclidean) norm equal to one. The - * matrix returned by this function is the matrix \f$ V \f$ in the - * eigendecomposition \f$ A = V D V^{-1} \f$, if it exists. - * - * Example: \include EigenSolver_eigenvectors.cpp - * Output: \verbinclude EigenSolver_eigenvectors.out - * - * \sa eigenvalues(), pseudoEigenvectors() - */ - EigenvectorsType eigenvectors() const; - - /** \brief Returns the pseudo-eigenvectors of given matrix. - * - * \returns Const reference to matrix whose columns are the pseudo-eigenvectors. - * - * \pre Either the constructor - * EigenSolver(const MatrixType&,bool) or the member function - * compute(const MatrixType&, bool) has been called before, and - * \p computeEigenvectors was set to true (the default). - * - * The real matrix \f$ V \f$ returned by this function and the - * block-diagonal matrix \f$ D \f$ returned by pseudoEigenvalueMatrix() - * satisfy \f$ AV = VD \f$. - * - * Example: \include EigenSolver_pseudoEigenvectors.cpp - * Output: \verbinclude EigenSolver_pseudoEigenvectors.out - * - * \sa pseudoEigenvalueMatrix(), eigenvectors() - */ - const MatrixType& pseudoEigenvectors() const - { - eigen_assert(m_isInitialized && "EigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - return m_eivec; - } - - /** \brief Returns the block-diagonal matrix in the pseudo-eigendecomposition. - * - * \returns A block-diagonal matrix. - * - * \pre Either the constructor - * EigenSolver(const MatrixType&,bool) or the member function - * compute(const MatrixType&, bool) has been called before. - * - * The matrix \f$ D \f$ returned by this function is real and - * block-diagonal. The blocks on the diagonal are either 1-by-1 or 2-by-2 - * blocks of the form - * \f$ \begin{bmatrix} u & v \\ -v & u \end{bmatrix} \f$. - * These blocks are not sorted in any particular order. - * The matrix \f$ D \f$ and the matrix \f$ V \f$ returned by - * pseudoEigenvectors() satisfy \f$ AV = VD \f$. - * - * \sa pseudoEigenvectors() for an example, eigenvalues() - */ - MatrixType pseudoEigenvalueMatrix() const; - - /** \brief Returns the eigenvalues of given matrix. - * - * \returns A const reference to the column vector containing the eigenvalues. - * - * \pre Either the constructor - * EigenSolver(const MatrixType&,bool) or the member function - * compute(const MatrixType&, bool) has been called before. - * - * The eigenvalues are repeated according to their algebraic multiplicity, - * so there are as many eigenvalues as rows in the matrix. The eigenvalues - * are not sorted in any particular order. - * - * Example: \include EigenSolver_eigenvalues.cpp - * Output: \verbinclude EigenSolver_eigenvalues.out - * - * \sa eigenvectors(), pseudoEigenvalueMatrix(), - * MatrixBase::eigenvalues() - */ - const EigenvalueType& eigenvalues() const - { - eigen_assert(m_isInitialized && "EigenSolver is not initialized."); - return m_eivalues; - } - - /** \brief Computes eigendecomposition of given matrix. - * - * \param[in] matrix Square matrix whose eigendecomposition is to be computed. - * \param[in] computeEigenvectors If true, both the eigenvectors and the - * eigenvalues are computed; if false, only the eigenvalues are - * computed. - * \returns Reference to \c *this - * - * This function computes the eigenvalues of the real matrix \p matrix. - * The eigenvalues() function can be used to retrieve them. If - * \p computeEigenvectors is true, then the eigenvectors are also computed - * and can be retrieved by calling eigenvectors(). - * - * The matrix is first reduced to real Schur form using the RealSchur - * class. The Schur decomposition is then used to compute the eigenvalues - * and eigenvectors. - * - * The cost of the computation is dominated by the cost of the - * Schur decomposition, which is very approximately \f$ 25n^3 \f$ - * (where \f$ n \f$ is the size of the matrix) if \p computeEigenvectors - * is true, and \f$ 10n^3 \f$ if \p computeEigenvectors is false. - * - * This method reuses of the allocated data in the EigenSolver object. - * - * Example: \include EigenSolver_compute.cpp - * Output: \verbinclude EigenSolver_compute.out - */ - template<typename InputType> - EigenSolver& compute(const EigenBase<InputType>& matrix, bool computeEigenvectors = true); - - /** \returns NumericalIssue if the input contains INF or NaN values or overflow occurred. Returns Success otherwise. */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "EigenSolver is not initialized."); - return m_info; - } - - /** \brief Sets the maximum number of iterations allowed. */ - EigenSolver& setMaxIterations(Index maxIters) - { - m_realSchur.setMaxIterations(maxIters); - return *this; - } - - /** \brief Returns the maximum number of iterations. */ - Index getMaxIterations() - { - return m_realSchur.getMaxIterations(); - } - - private: - void doComputeEigenvectors(); - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL); - } - - MatrixType m_eivec; - EigenvalueType m_eivalues; - bool m_isInitialized; - bool m_eigenvectorsOk; - ComputationInfo m_info; - RealSchur<MatrixType> m_realSchur; - MatrixType m_matT; - - typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ColumnVectorType; - ColumnVectorType m_tmp; -}; - -template<typename MatrixType> -MatrixType EigenSolver<MatrixType>::pseudoEigenvalueMatrix() const -{ - eigen_assert(m_isInitialized && "EigenSolver is not initialized."); - const RealScalar precision = RealScalar(2)*NumTraits<RealScalar>::epsilon(); - Index n = m_eivalues.rows(); - MatrixType matD = MatrixType::Zero(n,n); - for (Index i=0; i<n; ++i) - { - if (internal::isMuchSmallerThan(numext::imag(m_eivalues.coeff(i)), numext::real(m_eivalues.coeff(i)), precision)) - matD.coeffRef(i,i) = numext::real(m_eivalues.coeff(i)); - else - { - matD.template block<2,2>(i,i) << numext::real(m_eivalues.coeff(i)), numext::imag(m_eivalues.coeff(i)), - -numext::imag(m_eivalues.coeff(i)), numext::real(m_eivalues.coeff(i)); - ++i; - } - } - return matD; -} - -template<typename MatrixType> -typename EigenSolver<MatrixType>::EigenvectorsType EigenSolver<MatrixType>::eigenvectors() const -{ - eigen_assert(m_isInitialized && "EigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - const RealScalar precision = RealScalar(2)*NumTraits<RealScalar>::epsilon(); - Index n = m_eivec.cols(); - EigenvectorsType matV(n,n); - for (Index j=0; j<n; ++j) - { - if (internal::isMuchSmallerThan(numext::imag(m_eivalues.coeff(j)), numext::real(m_eivalues.coeff(j)), precision) || j+1==n) - { - // we have a real eigen value - matV.col(j) = m_eivec.col(j).template cast<ComplexScalar>(); - matV.col(j).normalize(); - } - else - { - // we have a pair of complex eigen values - for (Index i=0; i<n; ++i) - { - matV.coeffRef(i,j) = ComplexScalar(m_eivec.coeff(i,j), m_eivec.coeff(i,j+1)); - matV.coeffRef(i,j+1) = ComplexScalar(m_eivec.coeff(i,j), -m_eivec.coeff(i,j+1)); - } - matV.col(j).normalize(); - matV.col(j+1).normalize(); - ++j; - } - } - return matV; -} - -template<typename MatrixType> -template<typename InputType> -EigenSolver<MatrixType>& -EigenSolver<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeEigenvectors) -{ - check_template_parameters(); - - using std::sqrt; - using std::abs; - using numext::isfinite; - eigen_assert(matrix.cols() == matrix.rows()); - - // Reduce to real Schur form. - m_realSchur.compute(matrix.derived(), computeEigenvectors); - - m_info = m_realSchur.info(); - - if (m_info == Success) - { - m_matT = m_realSchur.matrixT(); - if (computeEigenvectors) - m_eivec = m_realSchur.matrixU(); - - // Compute eigenvalues from matT - m_eivalues.resize(matrix.cols()); - Index i = 0; - while (i < matrix.cols()) - { - if (i == matrix.cols() - 1 || m_matT.coeff(i+1, i) == Scalar(0)) - { - m_eivalues.coeffRef(i) = m_matT.coeff(i, i); - if(!(isfinite)(m_eivalues.coeffRef(i))) - { - m_isInitialized = true; - m_eigenvectorsOk = false; - m_info = NumericalIssue; - return *this; - } - ++i; - } - else - { - Scalar p = Scalar(0.5) * (m_matT.coeff(i, i) - m_matT.coeff(i+1, i+1)); - Scalar z; - // Compute z = sqrt(abs(p * p + m_matT.coeff(i+1, i) * m_matT.coeff(i, i+1))); - // without overflow - { - Scalar t0 = m_matT.coeff(i+1, i); - Scalar t1 = m_matT.coeff(i, i+1); - Scalar maxval = numext::maxi<Scalar>(abs(p),numext::maxi<Scalar>(abs(t0),abs(t1))); - t0 /= maxval; - t1 /= maxval; - Scalar p0 = p/maxval; - z = maxval * sqrt(abs(p0 * p0 + t0 * t1)); - } - - m_eivalues.coeffRef(i) = ComplexScalar(m_matT.coeff(i+1, i+1) + p, z); - m_eivalues.coeffRef(i+1) = ComplexScalar(m_matT.coeff(i+1, i+1) + p, -z); - if(!((isfinite)(m_eivalues.coeffRef(i)) && (isfinite)(m_eivalues.coeffRef(i+1)))) - { - m_isInitialized = true; - m_eigenvectorsOk = false; - m_info = NumericalIssue; - return *this; - } - i += 2; - } - } - - // Compute eigenvectors. - if (computeEigenvectors) - doComputeEigenvectors(); - } - - m_isInitialized = true; - m_eigenvectorsOk = computeEigenvectors; - - return *this; -} - - -template<typename MatrixType> -void EigenSolver<MatrixType>::doComputeEigenvectors() -{ - using std::abs; - const Index size = m_eivec.cols(); - const Scalar eps = NumTraits<Scalar>::epsilon(); - - // inefficient! this is already computed in RealSchur - Scalar norm(0); - for (Index j = 0; j < size; ++j) - { - norm += m_matT.row(j).segment((std::max)(j-1,Index(0)), size-(std::max)(j-1,Index(0))).cwiseAbs().sum(); - } - - // Backsubstitute to find vectors of upper triangular form - if (norm == Scalar(0)) - { - return; - } - - for (Index n = size-1; n >= 0; n--) - { - Scalar p = m_eivalues.coeff(n).real(); - Scalar q = m_eivalues.coeff(n).imag(); - - // Scalar vector - if (q == Scalar(0)) - { - Scalar lastr(0), lastw(0); - Index l = n; - - m_matT.coeffRef(n,n) = Scalar(1); - for (Index i = n-1; i >= 0; i--) - { - Scalar w = m_matT.coeff(i,i) - p; - Scalar r = m_matT.row(i).segment(l,n-l+1).dot(m_matT.col(n).segment(l, n-l+1)); - - if (m_eivalues.coeff(i).imag() < Scalar(0)) - { - lastw = w; - lastr = r; - } - else - { - l = i; - if (m_eivalues.coeff(i).imag() == Scalar(0)) - { - if (w != Scalar(0)) - m_matT.coeffRef(i,n) = -r / w; - else - m_matT.coeffRef(i,n) = -r / (eps * norm); - } - else // Solve real equations - { - Scalar x = m_matT.coeff(i,i+1); - Scalar y = m_matT.coeff(i+1,i); - Scalar denom = (m_eivalues.coeff(i).real() - p) * (m_eivalues.coeff(i).real() - p) + m_eivalues.coeff(i).imag() * m_eivalues.coeff(i).imag(); - Scalar t = (x * lastr - lastw * r) / denom; - m_matT.coeffRef(i,n) = t; - if (abs(x) > abs(lastw)) - m_matT.coeffRef(i+1,n) = (-r - w * t) / x; - else - m_matT.coeffRef(i+1,n) = (-lastr - y * t) / lastw; - } - - // Overflow control - Scalar t = abs(m_matT.coeff(i,n)); - if ((eps * t) * t > Scalar(1)) - m_matT.col(n).tail(size-i) /= t; - } - } - } - else if (q < Scalar(0) && n > 0) // Complex vector - { - Scalar lastra(0), lastsa(0), lastw(0); - Index l = n-1; - - // Last vector component imaginary so matrix is triangular - if (abs(m_matT.coeff(n,n-1)) > abs(m_matT.coeff(n-1,n))) - { - m_matT.coeffRef(n-1,n-1) = q / m_matT.coeff(n,n-1); - m_matT.coeffRef(n-1,n) = -(m_matT.coeff(n,n) - p) / m_matT.coeff(n,n-1); - } - else - { - ComplexScalar cc = ComplexScalar(Scalar(0),-m_matT.coeff(n-1,n)) / ComplexScalar(m_matT.coeff(n-1,n-1)-p,q); - m_matT.coeffRef(n-1,n-1) = numext::real(cc); - m_matT.coeffRef(n-1,n) = numext::imag(cc); - } - m_matT.coeffRef(n,n-1) = Scalar(0); - m_matT.coeffRef(n,n) = Scalar(1); - for (Index i = n-2; i >= 0; i--) - { - Scalar ra = m_matT.row(i).segment(l, n-l+1).dot(m_matT.col(n-1).segment(l, n-l+1)); - Scalar sa = m_matT.row(i).segment(l, n-l+1).dot(m_matT.col(n).segment(l, n-l+1)); - Scalar w = m_matT.coeff(i,i) - p; - - if (m_eivalues.coeff(i).imag() < Scalar(0)) - { - lastw = w; - lastra = ra; - lastsa = sa; - } - else - { - l = i; - if (m_eivalues.coeff(i).imag() == RealScalar(0)) - { - ComplexScalar cc = ComplexScalar(-ra,-sa) / ComplexScalar(w,q); - m_matT.coeffRef(i,n-1) = numext::real(cc); - m_matT.coeffRef(i,n) = numext::imag(cc); - } - else - { - // Solve complex equations - Scalar x = m_matT.coeff(i,i+1); - Scalar y = m_matT.coeff(i+1,i); - Scalar vr = (m_eivalues.coeff(i).real() - p) * (m_eivalues.coeff(i).real() - p) + m_eivalues.coeff(i).imag() * m_eivalues.coeff(i).imag() - q * q; - Scalar vi = (m_eivalues.coeff(i).real() - p) * Scalar(2) * q; - if ((vr == Scalar(0)) && (vi == Scalar(0))) - vr = eps * norm * (abs(w) + abs(q) + abs(x) + abs(y) + abs(lastw)); - - ComplexScalar cc = ComplexScalar(x*lastra-lastw*ra+q*sa,x*lastsa-lastw*sa-q*ra) / ComplexScalar(vr,vi); - m_matT.coeffRef(i,n-1) = numext::real(cc); - m_matT.coeffRef(i,n) = numext::imag(cc); - if (abs(x) > (abs(lastw) + abs(q))) - { - m_matT.coeffRef(i+1,n-1) = (-ra - w * m_matT.coeff(i,n-1) + q * m_matT.coeff(i,n)) / x; - m_matT.coeffRef(i+1,n) = (-sa - w * m_matT.coeff(i,n) - q * m_matT.coeff(i,n-1)) / x; - } - else - { - cc = ComplexScalar(-lastra-y*m_matT.coeff(i,n-1),-lastsa-y*m_matT.coeff(i,n)) / ComplexScalar(lastw,q); - m_matT.coeffRef(i+1,n-1) = numext::real(cc); - m_matT.coeffRef(i+1,n) = numext::imag(cc); - } - } - - // Overflow control - Scalar t = numext::maxi<Scalar>(abs(m_matT.coeff(i,n-1)),abs(m_matT.coeff(i,n))); - if ((eps * t) * t > Scalar(1)) - m_matT.block(i, n-1, size-i, 2) /= t; - - } - } - - // We handled a pair of complex conjugate eigenvalues, so need to skip them both - n--; - } - else - { - eigen_assert(0 && "Internal bug in EigenSolver (INF or NaN has not been detected)"); // this should not happen - } - } - - // Back transformation to get eigenvectors of original matrix - for (Index j = size-1; j >= 0; j--) - { - m_tmp.noalias() = m_eivec.leftCols(j+1) * m_matT.col(j).segment(0, j+1); - m_eivec.col(j) = m_tmp; - } -} - -} // end namespace Eigen - -#endif // EIGEN_EIGENSOLVER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h deleted file mode 100644 index 87d789b3..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h +++ /dev/null @@ -1,418 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012-2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk> -// Copyright (C) 2016 Tobias Wood <tobias@spinicist.org.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERALIZEDEIGENSOLVER_H -#define EIGEN_GENERALIZEDEIGENSOLVER_H - -#include "./RealQZ.h" - -namespace Eigen { - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class GeneralizedEigenSolver - * - * \brief Computes the generalized eigenvalues and eigenvectors of a pair of general matrices - * - * \tparam _MatrixType the type of the matrices of which we are computing the - * eigen-decomposition; this is expected to be an instantiation of the Matrix - * class template. Currently, only real matrices are supported. - * - * The generalized eigenvalues and eigenvectors of a matrix pair \f$ A \f$ and \f$ B \f$ are scalars - * \f$ \lambda \f$ and vectors \f$ v \f$ such that \f$ Av = \lambda Bv \f$. If - * \f$ D \f$ is a diagonal matrix with the eigenvalues on the diagonal, and - * \f$ V \f$ is a matrix with the eigenvectors as its columns, then \f$ A V = - * B V D \f$. The matrix \f$ V \f$ is almost always invertible, in which case we - * have \f$ A = B V D V^{-1} \f$. This is called the generalized eigen-decomposition. - * - * The generalized eigenvalues and eigenvectors of a matrix pair may be complex, even when the - * matrices are real. Moreover, the generalized eigenvalue might be infinite if the matrix B is - * singular. To workaround this difficulty, the eigenvalues are provided as a pair of complex \f$ \alpha \f$ - * and real \f$ \beta \f$ such that: \f$ \lambda_i = \alpha_i / \beta_i \f$. If \f$ \beta_i \f$ is (nearly) zero, - * then one can consider the well defined left eigenvalue \f$ \mu = \beta_i / \alpha_i\f$ such that: - * \f$ \mu_i A v_i = B v_i \f$, or even \f$ \mu_i u_i^T A = u_i^T B \f$ where \f$ u_i \f$ is - * called the left eigenvector. - * - * Call the function compute() to compute the generalized eigenvalues and eigenvectors of - * a given matrix pair. Alternatively, you can use the - * GeneralizedEigenSolver(const MatrixType&, const MatrixType&, bool) constructor which computes the - * eigenvalues and eigenvectors at construction time. Once the eigenvalue and - * eigenvectors are computed, they can be retrieved with the eigenvalues() and - * eigenvectors() functions. - * - * Here is an usage example of this class: - * Example: \include GeneralizedEigenSolver.cpp - * Output: \verbinclude GeneralizedEigenSolver.out - * - * \sa MatrixBase::eigenvalues(), class ComplexEigenSolver, class SelfAdjointEigenSolver - */ -template<typename _MatrixType> class GeneralizedEigenSolver -{ - public: - - /** \brief Synonym for the template parameter \p _MatrixType. */ - typedef _MatrixType MatrixType; - - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - Options = MatrixType::Options, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - /** \brief Scalar type for matrices of type #MatrixType. */ - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - /** \brief Complex scalar type for #MatrixType. - * - * This is \c std::complex<Scalar> if #Scalar is real (e.g., - * \c float or \c double) and just \c Scalar if #Scalar is - * complex. - */ - typedef std::complex<RealScalar> ComplexScalar; - - /** \brief Type for vector of real scalar values eigenvalues as returned by betas(). - * - * This is a column vector with entries of type #Scalar. - * The length of the vector is the size of #MatrixType. - */ - typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> VectorType; - - /** \brief Type for vector of complex scalar values eigenvalues as returned by alphas(). - * - * This is a column vector with entries of type #ComplexScalar. - * The length of the vector is the size of #MatrixType. - */ - typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ComplexVectorType; - - /** \brief Expression type for the eigenvalues as returned by eigenvalues(). - */ - typedef CwiseBinaryOp<internal::scalar_quotient_op<ComplexScalar,Scalar>,ComplexVectorType,VectorType> EigenvalueType; - - /** \brief Type for matrix of eigenvectors as returned by eigenvectors(). - * - * This is a square matrix with entries of type #ComplexScalar. - * The size is the same as the size of #MatrixType. - */ - typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> EigenvectorsType; - - /** \brief Default constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via EigenSolver::compute(const MatrixType&, bool). - * - * \sa compute() for an example. - */ - GeneralizedEigenSolver() - : m_eivec(), - m_alphas(), - m_betas(), - m_valuesOkay(false), - m_vectorsOkay(false), - m_realQZ() - {} - - /** \brief Default constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa GeneralizedEigenSolver() - */ - explicit GeneralizedEigenSolver(Index size) - : m_eivec(size, size), - m_alphas(size), - m_betas(size), - m_valuesOkay(false), - m_vectorsOkay(false), - m_realQZ(size), - m_tmp(size) - {} - - /** \brief Constructor; computes the generalized eigendecomposition of given matrix pair. - * - * \param[in] A Square matrix whose eigendecomposition is to be computed. - * \param[in] B Square matrix whose eigendecomposition is to be computed. - * \param[in] computeEigenvectors If true, both the eigenvectors and the - * eigenvalues are computed; if false, only the eigenvalues are computed. - * - * This constructor calls compute() to compute the generalized eigenvalues - * and eigenvectors. - * - * \sa compute() - */ - GeneralizedEigenSolver(const MatrixType& A, const MatrixType& B, bool computeEigenvectors = true) - : m_eivec(A.rows(), A.cols()), - m_alphas(A.cols()), - m_betas(A.cols()), - m_valuesOkay(false), - m_vectorsOkay(false), - m_realQZ(A.cols()), - m_tmp(A.cols()) - { - compute(A, B, computeEigenvectors); - } - - /* \brief Returns the computed generalized eigenvectors. - * - * \returns %Matrix whose columns are the (possibly complex) right eigenvectors. - * i.e. the eigenvectors that solve (A - l*B)x = 0. The ordering matches the eigenvalues. - * - * \pre Either the constructor - * GeneralizedEigenSolver(const MatrixType&,const MatrixType&, bool) or the member function - * compute(const MatrixType&, const MatrixType& bool) has been called before, and - * \p computeEigenvectors was set to true (the default). - * - * \sa eigenvalues() - */ - EigenvectorsType eigenvectors() const { - eigen_assert(m_vectorsOkay && "Eigenvectors for GeneralizedEigenSolver were not calculated."); - return m_eivec; - } - - /** \brief Returns an expression of the computed generalized eigenvalues. - * - * \returns An expression of the column vector containing the eigenvalues. - * - * It is a shortcut for \code this->alphas().cwiseQuotient(this->betas()); \endcode - * Not that betas might contain zeros. It is therefore not recommended to use this function, - * but rather directly deal with the alphas and betas vectors. - * - * \pre Either the constructor - * GeneralizedEigenSolver(const MatrixType&,const MatrixType&,bool) or the member function - * compute(const MatrixType&,const MatrixType&,bool) has been called before. - * - * The eigenvalues are repeated according to their algebraic multiplicity, - * so there are as many eigenvalues as rows in the matrix. The eigenvalues - * are not sorted in any particular order. - * - * \sa alphas(), betas(), eigenvectors() - */ - EigenvalueType eigenvalues() const - { - eigen_assert(m_valuesOkay && "GeneralizedEigenSolver is not initialized."); - return EigenvalueType(m_alphas,m_betas); - } - - /** \returns A const reference to the vectors containing the alpha values - * - * This vector permits to reconstruct the j-th eigenvalues as alphas(i)/betas(j). - * - * \sa betas(), eigenvalues() */ - ComplexVectorType alphas() const - { - eigen_assert(m_valuesOkay && "GeneralizedEigenSolver is not initialized."); - return m_alphas; - } - - /** \returns A const reference to the vectors containing the beta values - * - * This vector permits to reconstruct the j-th eigenvalues as alphas(i)/betas(j). - * - * \sa alphas(), eigenvalues() */ - VectorType betas() const - { - eigen_assert(m_valuesOkay && "GeneralizedEigenSolver is not initialized."); - return m_betas; - } - - /** \brief Computes generalized eigendecomposition of given matrix. - * - * \param[in] A Square matrix whose eigendecomposition is to be computed. - * \param[in] B Square matrix whose eigendecomposition is to be computed. - * \param[in] computeEigenvectors If true, both the eigenvectors and the - * eigenvalues are computed; if false, only the eigenvalues are - * computed. - * \returns Reference to \c *this - * - * This function computes the eigenvalues of the real matrix \p matrix. - * The eigenvalues() function can be used to retrieve them. If - * \p computeEigenvectors is true, then the eigenvectors are also computed - * and can be retrieved by calling eigenvectors(). - * - * The matrix is first reduced to real generalized Schur form using the RealQZ - * class. The generalized Schur decomposition is then used to compute the eigenvalues - * and eigenvectors. - * - * The cost of the computation is dominated by the cost of the - * generalized Schur decomposition. - * - * This method reuses of the allocated data in the GeneralizedEigenSolver object. - */ - GeneralizedEigenSolver& compute(const MatrixType& A, const MatrixType& B, bool computeEigenvectors = true); - - ComputationInfo info() const - { - eigen_assert(m_valuesOkay && "EigenSolver is not initialized."); - return m_realQZ.info(); - } - - /** Sets the maximal number of iterations allowed. - */ - GeneralizedEigenSolver& setMaxIterations(Index maxIters) - { - m_realQZ.setMaxIterations(maxIters); - return *this; - } - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL); - } - - EigenvectorsType m_eivec; - ComplexVectorType m_alphas; - VectorType m_betas; - bool m_valuesOkay, m_vectorsOkay; - RealQZ<MatrixType> m_realQZ; - ComplexVectorType m_tmp; -}; - -template<typename MatrixType> -GeneralizedEigenSolver<MatrixType>& -GeneralizedEigenSolver<MatrixType>::compute(const MatrixType& A, const MatrixType& B, bool computeEigenvectors) -{ - check_template_parameters(); - - using std::sqrt; - using std::abs; - eigen_assert(A.cols() == A.rows() && B.cols() == A.rows() && B.cols() == B.rows()); - Index size = A.cols(); - m_valuesOkay = false; - m_vectorsOkay = false; - // Reduce to generalized real Schur form: - // A = Q S Z and B = Q T Z - m_realQZ.compute(A, B, computeEigenvectors); - if (m_realQZ.info() == Success) - { - // Resize storage - m_alphas.resize(size); - m_betas.resize(size); - if (computeEigenvectors) - { - m_eivec.resize(size,size); - m_tmp.resize(size); - } - - // Aliases: - Map<VectorType> v(reinterpret_cast<Scalar*>(m_tmp.data()), size); - ComplexVectorType &cv = m_tmp; - const MatrixType &mS = m_realQZ.matrixS(); - const MatrixType &mT = m_realQZ.matrixT(); - - Index i = 0; - while (i < size) - { - if (i == size - 1 || mS.coeff(i+1, i) == Scalar(0)) - { - // Real eigenvalue - m_alphas.coeffRef(i) = mS.diagonal().coeff(i); - m_betas.coeffRef(i) = mT.diagonal().coeff(i); - if (computeEigenvectors) - { - v.setConstant(Scalar(0.0)); - v.coeffRef(i) = Scalar(1.0); - // For singular eigenvalues do nothing more - if(abs(m_betas.coeffRef(i)) >= (std::numeric_limits<RealScalar>::min)()) - { - // Non-singular eigenvalue - const Scalar alpha = real(m_alphas.coeffRef(i)); - const Scalar beta = m_betas.coeffRef(i); - for (Index j = i-1; j >= 0; j--) - { - const Index st = j+1; - const Index sz = i-j; - if (j > 0 && mS.coeff(j, j-1) != Scalar(0)) - { - // 2x2 block - Matrix<Scalar, 2, 1> rhs = (alpha*mT.template block<2,Dynamic>(j-1,st,2,sz) - beta*mS.template block<2,Dynamic>(j-1,st,2,sz)) .lazyProduct( v.segment(st,sz) ); - Matrix<Scalar, 2, 2> lhs = beta * mS.template block<2,2>(j-1,j-1) - alpha * mT.template block<2,2>(j-1,j-1); - v.template segment<2>(j-1) = lhs.partialPivLu().solve(rhs); - j--; - } - else - { - v.coeffRef(j) = -v.segment(st,sz).transpose().cwiseProduct(beta*mS.block(j,st,1,sz) - alpha*mT.block(j,st,1,sz)).sum() / (beta*mS.coeffRef(j,j) - alpha*mT.coeffRef(j,j)); - } - } - } - m_eivec.col(i).real().noalias() = m_realQZ.matrixZ().transpose() * v; - m_eivec.col(i).real().normalize(); - m_eivec.col(i).imag().setConstant(0); - } - ++i; - } - else - { - // We need to extract the generalized eigenvalues of the pair of a general 2x2 block S and a positive diagonal 2x2 block T - // Then taking beta=T_00*T_11, we can avoid any division, and alpha is the eigenvalues of A = (U^-1 * S * U) * diag(T_11,T_00): - - // T = [a 0] - // [0 b] - RealScalar a = mT.diagonal().coeff(i), - b = mT.diagonal().coeff(i+1); - const RealScalar beta = m_betas.coeffRef(i) = m_betas.coeffRef(i+1) = a*b; - - // ^^ NOTE: using diagonal()(i) instead of coeff(i,i) workarounds a MSVC bug. - Matrix<RealScalar,2,2> S2 = mS.template block<2,2>(i,i) * Matrix<Scalar,2,1>(b,a).asDiagonal(); - - Scalar p = Scalar(0.5) * (S2.coeff(0,0) - S2.coeff(1,1)); - Scalar z = sqrt(abs(p * p + S2.coeff(1,0) * S2.coeff(0,1))); - const ComplexScalar alpha = ComplexScalar(S2.coeff(1,1) + p, (beta > 0) ? z : -z); - m_alphas.coeffRef(i) = conj(alpha); - m_alphas.coeffRef(i+1) = alpha; - - if (computeEigenvectors) { - // Compute eigenvector in position (i+1) and then position (i) is just the conjugate - cv.setZero(); - cv.coeffRef(i+1) = Scalar(1.0); - // here, the "static_cast" workaound expression template issues. - cv.coeffRef(i) = -(static_cast<Scalar>(beta*mS.coeffRef(i,i+1)) - alpha*mT.coeffRef(i,i+1)) - / (static_cast<Scalar>(beta*mS.coeffRef(i,i)) - alpha*mT.coeffRef(i,i)); - for (Index j = i-1; j >= 0; j--) - { - const Index st = j+1; - const Index sz = i+1-j; - if (j > 0 && mS.coeff(j, j-1) != Scalar(0)) - { - // 2x2 block - Matrix<ComplexScalar, 2, 1> rhs = (alpha*mT.template block<2,Dynamic>(j-1,st,2,sz) - beta*mS.template block<2,Dynamic>(j-1,st,2,sz)) .lazyProduct( cv.segment(st,sz) ); - Matrix<ComplexScalar, 2, 2> lhs = beta * mS.template block<2,2>(j-1,j-1) - alpha * mT.template block<2,2>(j-1,j-1); - cv.template segment<2>(j-1) = lhs.partialPivLu().solve(rhs); - j--; - } else { - cv.coeffRef(j) = cv.segment(st,sz).transpose().cwiseProduct(beta*mS.block(j,st,1,sz) - alpha*mT.block(j,st,1,sz)).sum() - / (alpha*mT.coeffRef(j,j) - static_cast<Scalar>(beta*mS.coeffRef(j,j))); - } - } - m_eivec.col(i+1).noalias() = (m_realQZ.matrixZ().transpose() * cv); - m_eivec.col(i+1).normalize(); - m_eivec.col(i) = m_eivec.col(i+1).conjugate(); - } - i += 2; - } - } - - m_valuesOkay = true; - m_vectorsOkay = computeEigenvectors; - } - return *this; -} - -} // end namespace Eigen - -#endif // EIGEN_GENERALIZEDEIGENSOLVER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h deleted file mode 100644 index d0f9091b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h +++ /dev/null @@ -1,226 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GENERALIZEDSELFADJOINTEIGENSOLVER_H -#define EIGEN_GENERALIZEDSELFADJOINTEIGENSOLVER_H - -#include "./Tridiagonalization.h" - -namespace Eigen { - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class GeneralizedSelfAdjointEigenSolver - * - * \brief Computes eigenvalues and eigenvectors of the generalized selfadjoint eigen problem - * - * \tparam _MatrixType the type of the matrix of which we are computing the - * eigendecomposition; this is expected to be an instantiation of the Matrix - * class template. - * - * This class solves the generalized eigenvalue problem - * \f$ Av = \lambda Bv \f$. In this case, the matrix \f$ A \f$ should be - * selfadjoint and the matrix \f$ B \f$ should be positive definite. - * - * Only the \b lower \b triangular \b part of the input matrix is referenced. - * - * Call the function compute() to compute the eigenvalues and eigenvectors of - * a given matrix. Alternatively, you can use the - * GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int) - * constructor which computes the eigenvalues and eigenvectors at construction time. - * Once the eigenvalue and eigenvectors are computed, they can be retrieved with the eigenvalues() - * and eigenvectors() functions. - * - * The documentation for GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int) - * contains an example of the typical use of this class. - * - * \sa class SelfAdjointEigenSolver, class EigenSolver, class ComplexEigenSolver - */ -template<typename _MatrixType> -class GeneralizedSelfAdjointEigenSolver : public SelfAdjointEigenSolver<_MatrixType> -{ - typedef SelfAdjointEigenSolver<_MatrixType> Base; - public: - - typedef _MatrixType MatrixType; - - /** \brief Default constructor for fixed-size matrices. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via compute(). This constructor - * can only be used if \p _MatrixType is a fixed-size matrix; use - * GeneralizedSelfAdjointEigenSolver(Index) for dynamic-size matrices. - */ - GeneralizedSelfAdjointEigenSolver() : Base() {} - - /** \brief Constructor, pre-allocates memory for dynamic-size matrices. - * - * \param [in] size Positive integer, size of the matrix whose - * eigenvalues and eigenvectors will be computed. - * - * This constructor is useful for dynamic-size matrices, when the user - * intends to perform decompositions via compute(). The \p size - * parameter is only used as a hint. It is not an error to give a wrong - * \p size, but it may impair performance. - * - * \sa compute() for an example - */ - explicit GeneralizedSelfAdjointEigenSolver(Index size) - : Base(size) - {} - - /** \brief Constructor; computes generalized eigendecomposition of given matrix pencil. - * - * \param[in] matA Selfadjoint matrix in matrix pencil. - * Only the lower triangular part of the matrix is referenced. - * \param[in] matB Positive-definite matrix in matrix pencil. - * Only the lower triangular part of the matrix is referenced. - * \param[in] options A or-ed set of flags {#ComputeEigenvectors,#EigenvaluesOnly} | {#Ax_lBx,#ABx_lx,#BAx_lx}. - * Default is #ComputeEigenvectors|#Ax_lBx. - * - * This constructor calls compute(const MatrixType&, const MatrixType&, int) - * to compute the eigenvalues and (if requested) the eigenvectors of the - * generalized eigenproblem \f$ Ax = \lambda B x \f$ with \a matA the - * selfadjoint matrix \f$ A \f$ and \a matB the positive definite matrix - * \f$ B \f$. Each eigenvector \f$ x \f$ satisfies the property - * \f$ x^* B x = 1 \f$. The eigenvectors are computed if - * \a options contains ComputeEigenvectors. - * - * In addition, the two following variants can be solved via \p options: - * - \c ABx_lx: \f$ ABx = \lambda x \f$ - * - \c BAx_lx: \f$ BAx = \lambda x \f$ - * - * Example: \include SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType2.cpp - * Output: \verbinclude SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType2.out - * - * \sa compute(const MatrixType&, const MatrixType&, int) - */ - GeneralizedSelfAdjointEigenSolver(const MatrixType& matA, const MatrixType& matB, - int options = ComputeEigenvectors|Ax_lBx) - : Base(matA.cols()) - { - compute(matA, matB, options); - } - - /** \brief Computes generalized eigendecomposition of given matrix pencil. - * - * \param[in] matA Selfadjoint matrix in matrix pencil. - * Only the lower triangular part of the matrix is referenced. - * \param[in] matB Positive-definite matrix in matrix pencil. - * Only the lower triangular part of the matrix is referenced. - * \param[in] options A or-ed set of flags {#ComputeEigenvectors,#EigenvaluesOnly} | {#Ax_lBx,#ABx_lx,#BAx_lx}. - * Default is #ComputeEigenvectors|#Ax_lBx. - * - * \returns Reference to \c *this - * - * According to \p options, this function computes eigenvalues and (if requested) - * the eigenvectors of one of the following three generalized eigenproblems: - * - \c Ax_lBx: \f$ Ax = \lambda B x \f$ - * - \c ABx_lx: \f$ ABx = \lambda x \f$ - * - \c BAx_lx: \f$ BAx = \lambda x \f$ - * with \a matA the selfadjoint matrix \f$ A \f$ and \a matB the positive definite - * matrix \f$ B \f$. - * In addition, each eigenvector \f$ x \f$ satisfies the property \f$ x^* B x = 1 \f$. - * - * The eigenvalues() function can be used to retrieve - * the eigenvalues. If \p options contains ComputeEigenvectors, then the - * eigenvectors are also computed and can be retrieved by calling - * eigenvectors(). - * - * The implementation uses LLT to compute the Cholesky decomposition - * \f$ B = LL^* \f$ and computes the classical eigendecomposition - * of the selfadjoint matrix \f$ L^{-1} A (L^*)^{-1} \f$ if \p options contains Ax_lBx - * and of \f$ L^{*} A L \f$ otherwise. This solves the - * generalized eigenproblem, because any solution of the generalized - * eigenproblem \f$ Ax = \lambda B x \f$ corresponds to a solution - * \f$ L^{-1} A (L^*)^{-1} (L^* x) = \lambda (L^* x) \f$ of the - * eigenproblem for \f$ L^{-1} A (L^*)^{-1} \f$. Similar statements - * can be made for the two other variants. - * - * Example: \include SelfAdjointEigenSolver_compute_MatrixType2.cpp - * Output: \verbinclude SelfAdjointEigenSolver_compute_MatrixType2.out - * - * \sa GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int) - */ - GeneralizedSelfAdjointEigenSolver& compute(const MatrixType& matA, const MatrixType& matB, - int options = ComputeEigenvectors|Ax_lBx); - - protected: - -}; - - -template<typename MatrixType> -GeneralizedSelfAdjointEigenSolver<MatrixType>& GeneralizedSelfAdjointEigenSolver<MatrixType>:: -compute(const MatrixType& matA, const MatrixType& matB, int options) -{ - eigen_assert(matA.cols()==matA.rows() && matB.rows()==matA.rows() && matB.cols()==matB.rows()); - eigen_assert((options&~(EigVecMask|GenEigMask))==0 - && (options&EigVecMask)!=EigVecMask - && ((options&GenEigMask)==0 || (options&GenEigMask)==Ax_lBx - || (options&GenEigMask)==ABx_lx || (options&GenEigMask)==BAx_lx) - && "invalid option parameter"); - - bool computeEigVecs = ((options&EigVecMask)==0) || ((options&EigVecMask)==ComputeEigenvectors); - - // Compute the cholesky decomposition of matB = L L' = U'U - LLT<MatrixType> cholB(matB); - - int type = (options&GenEigMask); - if(type==0) - type = Ax_lBx; - - if(type==Ax_lBx) - { - // compute C = inv(L) A inv(L') - MatrixType matC = matA.template selfadjointView<Lower>(); - cholB.matrixL().template solveInPlace<OnTheLeft>(matC); - cholB.matrixU().template solveInPlace<OnTheRight>(matC); - - Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly ); - - // transform back the eigen vectors: evecs = inv(U) * evecs - if(computeEigVecs) - cholB.matrixU().solveInPlace(Base::m_eivec); - } - else if(type==ABx_lx) - { - // compute C = L' A L - MatrixType matC = matA.template selfadjointView<Lower>(); - matC = matC * cholB.matrixL(); - matC = cholB.matrixU() * matC; - - Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly); - - // transform back the eigen vectors: evecs = inv(U) * evecs - if(computeEigVecs) - cholB.matrixU().solveInPlace(Base::m_eivec); - } - else if(type==BAx_lx) - { - // compute C = L' A L - MatrixType matC = matA.template selfadjointView<Lower>(); - matC = matC * cholB.matrixL(); - matC = cholB.matrixU() * matC; - - Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly); - - // transform back the eigen vectors: evecs = L * evecs - if(computeEigVecs) - Base::m_eivec = cholB.matrixL() * Base::m_eivec; - } - - return *this; -} - -} // end namespace Eigen - -#endif // EIGEN_GENERALIZEDSELFADJOINTEIGENSOLVER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/HessenbergDecomposition.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/HessenbergDecomposition.h deleted file mode 100644 index d947dac4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/HessenbergDecomposition.h +++ /dev/null @@ -1,374 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_HESSENBERGDECOMPOSITION_H -#define EIGEN_HESSENBERGDECOMPOSITION_H - -namespace Eigen { - -namespace internal { - -template<typename MatrixType> struct HessenbergDecompositionMatrixHReturnType; -template<typename MatrixType> -struct traits<HessenbergDecompositionMatrixHReturnType<MatrixType> > -{ - typedef MatrixType ReturnType; -}; - -} - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class HessenbergDecomposition - * - * \brief Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation - * - * \tparam _MatrixType the type of the matrix of which we are computing the Hessenberg decomposition - * - * This class performs an Hessenberg decomposition of a matrix \f$ A \f$. In - * the real case, the Hessenberg decomposition consists of an orthogonal - * matrix \f$ Q \f$ and a Hessenberg matrix \f$ H \f$ such that \f$ A = Q H - * Q^T \f$. An orthogonal matrix is a matrix whose inverse equals its - * transpose (\f$ Q^{-1} = Q^T \f$). A Hessenberg matrix has zeros below the - * subdiagonal, so it is almost upper triangular. The Hessenberg decomposition - * of a complex matrix is \f$ A = Q H Q^* \f$ with \f$ Q \f$ unitary (that is, - * \f$ Q^{-1} = Q^* \f$). - * - * Call the function compute() to compute the Hessenberg decomposition of a - * given matrix. Alternatively, you can use the - * HessenbergDecomposition(const MatrixType&) constructor which computes the - * Hessenberg decomposition at construction time. Once the decomposition is - * computed, you can use the matrixH() and matrixQ() functions to construct - * the matrices H and Q in the decomposition. - * - * The documentation for matrixH() contains an example of the typical use of - * this class. - * - * \sa class ComplexSchur, class Tridiagonalization, \ref QR_Module "QR Module" - */ -template<typename _MatrixType> class HessenbergDecomposition -{ - public: - - /** \brief Synonym for the template parameter \p _MatrixType. */ - typedef _MatrixType MatrixType; - - enum { - Size = MatrixType::RowsAtCompileTime, - SizeMinusOne = Size == Dynamic ? Dynamic : Size - 1, - Options = MatrixType::Options, - MaxSize = MatrixType::MaxRowsAtCompileTime, - MaxSizeMinusOne = MaxSize == Dynamic ? Dynamic : MaxSize - 1 - }; - - /** \brief Scalar type for matrices of type #MatrixType. */ - typedef typename MatrixType::Scalar Scalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - /** \brief Type for vector of Householder coefficients. - * - * This is column vector with entries of type #Scalar. The length of the - * vector is one less than the size of #MatrixType, if it is a fixed-side - * type. - */ - typedef Matrix<Scalar, SizeMinusOne, 1, Options & ~RowMajor, MaxSizeMinusOne, 1> CoeffVectorType; - - /** \brief Return type of matrixQ() */ - typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename CoeffVectorType::ConjugateReturnType>::type> HouseholderSequenceType; - - typedef internal::HessenbergDecompositionMatrixHReturnType<MatrixType> MatrixHReturnType; - - /** \brief Default constructor; the decomposition will be computed later. - * - * \param [in] size The size of the matrix whose Hessenberg decomposition will be computed. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via compute(). The \p size parameter is only - * used as a hint. It is not an error to give a wrong \p size, but it may - * impair performance. - * - * \sa compute() for an example. - */ - explicit HessenbergDecomposition(Index size = Size==Dynamic ? 2 : Size) - : m_matrix(size,size), - m_temp(size), - m_isInitialized(false) - { - if(size>1) - m_hCoeffs.resize(size-1); - } - - /** \brief Constructor; computes Hessenberg decomposition of given matrix. - * - * \param[in] matrix Square matrix whose Hessenberg decomposition is to be computed. - * - * This constructor calls compute() to compute the Hessenberg - * decomposition. - * - * \sa matrixH() for an example. - */ - template<typename InputType> - explicit HessenbergDecomposition(const EigenBase<InputType>& matrix) - : m_matrix(matrix.derived()), - m_temp(matrix.rows()), - m_isInitialized(false) - { - if(matrix.rows()<2) - { - m_isInitialized = true; - return; - } - m_hCoeffs.resize(matrix.rows()-1,1); - _compute(m_matrix, m_hCoeffs, m_temp); - m_isInitialized = true; - } - - /** \brief Computes Hessenberg decomposition of given matrix. - * - * \param[in] matrix Square matrix whose Hessenberg decomposition is to be computed. - * \returns Reference to \c *this - * - * The Hessenberg decomposition is computed by bringing the columns of the - * matrix successively in the required form using Householder reflections - * (see, e.g., Algorithm 7.4.2 in Golub \& Van Loan, <i>%Matrix - * Computations</i>). The cost is \f$ 10n^3/3 \f$ flops, where \f$ n \f$ - * denotes the size of the given matrix. - * - * This method reuses of the allocated data in the HessenbergDecomposition - * object. - * - * Example: \include HessenbergDecomposition_compute.cpp - * Output: \verbinclude HessenbergDecomposition_compute.out - */ - template<typename InputType> - HessenbergDecomposition& compute(const EigenBase<InputType>& matrix) - { - m_matrix = matrix.derived(); - if(matrix.rows()<2) - { - m_isInitialized = true; - return *this; - } - m_hCoeffs.resize(matrix.rows()-1,1); - _compute(m_matrix, m_hCoeffs, m_temp); - m_isInitialized = true; - return *this; - } - - /** \brief Returns the Householder coefficients. - * - * \returns a const reference to the vector of Householder coefficients - * - * \pre Either the constructor HessenbergDecomposition(const MatrixType&) - * or the member function compute(const MatrixType&) has been called - * before to compute the Hessenberg decomposition of a matrix. - * - * The Householder coefficients allow the reconstruction of the matrix - * \f$ Q \f$ in the Hessenberg decomposition from the packed data. - * - * \sa packedMatrix(), \ref Householder_Module "Householder module" - */ - const CoeffVectorType& householderCoefficients() const - { - eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized."); - return m_hCoeffs; - } - - /** \brief Returns the internal representation of the decomposition - * - * \returns a const reference to a matrix with the internal representation - * of the decomposition. - * - * \pre Either the constructor HessenbergDecomposition(const MatrixType&) - * or the member function compute(const MatrixType&) has been called - * before to compute the Hessenberg decomposition of a matrix. - * - * The returned matrix contains the following information: - * - the upper part and lower sub-diagonal represent the Hessenberg matrix H - * - the rest of the lower part contains the Householder vectors that, combined with - * Householder coefficients returned by householderCoefficients(), - * allows to reconstruct the matrix Q as - * \f$ Q = H_{N-1} \ldots H_1 H_0 \f$. - * Here, the matrices \f$ H_i \f$ are the Householder transformations - * \f$ H_i = (I - h_i v_i v_i^T) \f$ - * where \f$ h_i \f$ is the \f$ i \f$th Householder coefficient and - * \f$ v_i \f$ is the Householder vector defined by - * \f$ v_i = [ 0, \ldots, 0, 1, M(i+2,i), \ldots, M(N-1,i) ]^T \f$ - * with M the matrix returned by this function. - * - * See LAPACK for further details on this packed storage. - * - * Example: \include HessenbergDecomposition_packedMatrix.cpp - * Output: \verbinclude HessenbergDecomposition_packedMatrix.out - * - * \sa householderCoefficients() - */ - const MatrixType& packedMatrix() const - { - eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized."); - return m_matrix; - } - - /** \brief Reconstructs the orthogonal matrix Q in the decomposition - * - * \returns object representing the matrix Q - * - * \pre Either the constructor HessenbergDecomposition(const MatrixType&) - * or the member function compute(const MatrixType&) has been called - * before to compute the Hessenberg decomposition of a matrix. - * - * This function returns a light-weight object of template class - * HouseholderSequence. You can either apply it directly to a matrix or - * you can convert it to a matrix of type #MatrixType. - * - * \sa matrixH() for an example, class HouseholderSequence - */ - HouseholderSequenceType matrixQ() const - { - eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized."); - return HouseholderSequenceType(m_matrix, m_hCoeffs.conjugate()) - .setLength(m_matrix.rows() - 1) - .setShift(1); - } - - /** \brief Constructs the Hessenberg matrix H in the decomposition - * - * \returns expression object representing the matrix H - * - * \pre Either the constructor HessenbergDecomposition(const MatrixType&) - * or the member function compute(const MatrixType&) has been called - * before to compute the Hessenberg decomposition of a matrix. - * - * The object returned by this function constructs the Hessenberg matrix H - * when it is assigned to a matrix or otherwise evaluated. The matrix H is - * constructed from the packed matrix as returned by packedMatrix(): The - * upper part (including the subdiagonal) of the packed matrix contains - * the matrix H. It may sometimes be better to directly use the packed - * matrix instead of constructing the matrix H. - * - * Example: \include HessenbergDecomposition_matrixH.cpp - * Output: \verbinclude HessenbergDecomposition_matrixH.out - * - * \sa matrixQ(), packedMatrix() - */ - MatrixHReturnType matrixH() const - { - eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized."); - return MatrixHReturnType(*this); - } - - private: - - typedef Matrix<Scalar, 1, Size, Options | RowMajor, 1, MaxSize> VectorType; - typedef typename NumTraits<Scalar>::Real RealScalar; - static void _compute(MatrixType& matA, CoeffVectorType& hCoeffs, VectorType& temp); - - protected: - MatrixType m_matrix; - CoeffVectorType m_hCoeffs; - VectorType m_temp; - bool m_isInitialized; -}; - -/** \internal - * Performs a tridiagonal decomposition of \a matA in place. - * - * \param matA the input selfadjoint matrix - * \param hCoeffs returned Householder coefficients - * - * The result is written in the lower triangular part of \a matA. - * - * Implemented from Golub's "%Matrix Computations", algorithm 8.3.1. - * - * \sa packedMatrix() - */ -template<typename MatrixType> -void HessenbergDecomposition<MatrixType>::_compute(MatrixType& matA, CoeffVectorType& hCoeffs, VectorType& temp) -{ - eigen_assert(matA.rows()==matA.cols()); - Index n = matA.rows(); - temp.resize(n); - for (Index i = 0; i<n-1; ++i) - { - // let's consider the vector v = i-th column starting at position i+1 - Index remainingSize = n-i-1; - RealScalar beta; - Scalar h; - matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta); - matA.col(i).coeffRef(i+1) = beta; - hCoeffs.coeffRef(i) = h; - - // Apply similarity transformation to remaining columns, - // i.e., compute A = H A H' - - // A = H A - matA.bottomRightCorner(remainingSize, remainingSize) - .applyHouseholderOnTheLeft(matA.col(i).tail(remainingSize-1), h, &temp.coeffRef(0)); - - // A = A H' - matA.rightCols(remainingSize) - .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize-1), numext::conj(h), &temp.coeffRef(0)); - } -} - -namespace internal { - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \brief Expression type for return value of HessenbergDecomposition::matrixH() - * - * \tparam MatrixType type of matrix in the Hessenberg decomposition - * - * Objects of this type represent the Hessenberg matrix in the Hessenberg - * decomposition of some matrix. The object holds a reference to the - * HessenbergDecomposition class until the it is assigned or evaluated for - * some other reason (the reference should remain valid during the life time - * of this object). This class is the return type of - * HessenbergDecomposition::matrixH(); there is probably no other use for this - * class. - */ -template<typename MatrixType> struct HessenbergDecompositionMatrixHReturnType -: public ReturnByValue<HessenbergDecompositionMatrixHReturnType<MatrixType> > -{ - public: - /** \brief Constructor. - * - * \param[in] hess Hessenberg decomposition - */ - HessenbergDecompositionMatrixHReturnType(const HessenbergDecomposition<MatrixType>& hess) : m_hess(hess) { } - - /** \brief Hessenberg matrix in decomposition. - * - * \param[out] result Hessenberg matrix in decomposition \p hess which - * was passed to the constructor - */ - template <typename ResultType> - inline void evalTo(ResultType& result) const - { - result = m_hess.packedMatrix(); - Index n = result.rows(); - if (n>2) - result.bottomLeftCorner(n-2, n-2).template triangularView<Lower>().setZero(); - } - - Index rows() const { return m_hess.packedMatrix().rows(); } - Index cols() const { return m_hess.packedMatrix().cols(); } - - protected: - const HessenbergDecomposition<MatrixType>& m_hess; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_HESSENBERGDECOMPOSITION_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h deleted file mode 100644 index 66e5a3db..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h +++ /dev/null @@ -1,158 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIXBASEEIGENVALUES_H -#define EIGEN_MATRIXBASEEIGENVALUES_H - -namespace Eigen { - -namespace internal { - -template<typename Derived, bool IsComplex> -struct eigenvalues_selector -{ - // this is the implementation for the case IsComplex = true - static inline typename MatrixBase<Derived>::EigenvaluesReturnType const - run(const MatrixBase<Derived>& m) - { - typedef typename Derived::PlainObject PlainObject; - PlainObject m_eval(m); - return ComplexEigenSolver<PlainObject>(m_eval, false).eigenvalues(); - } -}; - -template<typename Derived> -struct eigenvalues_selector<Derived, false> -{ - static inline typename MatrixBase<Derived>::EigenvaluesReturnType const - run(const MatrixBase<Derived>& m) - { - typedef typename Derived::PlainObject PlainObject; - PlainObject m_eval(m); - return EigenSolver<PlainObject>(m_eval, false).eigenvalues(); - } -}; - -} // end namespace internal - -/** \brief Computes the eigenvalues of a matrix - * \returns Column vector containing the eigenvalues. - * - * \eigenvalues_module - * This function computes the eigenvalues with the help of the EigenSolver - * class (for real matrices) or the ComplexEigenSolver class (for complex - * matrices). - * - * The eigenvalues are repeated according to their algebraic multiplicity, - * so there are as many eigenvalues as rows in the matrix. - * - * The SelfAdjointView class provides a better algorithm for selfadjoint - * matrices. - * - * Example: \include MatrixBase_eigenvalues.cpp - * Output: \verbinclude MatrixBase_eigenvalues.out - * - * \sa EigenSolver::eigenvalues(), ComplexEigenSolver::eigenvalues(), - * SelfAdjointView::eigenvalues() - */ -template<typename Derived> -inline typename MatrixBase<Derived>::EigenvaluesReturnType -MatrixBase<Derived>::eigenvalues() const -{ - return internal::eigenvalues_selector<Derived, NumTraits<Scalar>::IsComplex>::run(derived()); -} - -/** \brief Computes the eigenvalues of a matrix - * \returns Column vector containing the eigenvalues. - * - * \eigenvalues_module - * This function computes the eigenvalues with the help of the - * SelfAdjointEigenSolver class. The eigenvalues are repeated according to - * their algebraic multiplicity, so there are as many eigenvalues as rows in - * the matrix. - * - * Example: \include SelfAdjointView_eigenvalues.cpp - * Output: \verbinclude SelfAdjointView_eigenvalues.out - * - * \sa SelfAdjointEigenSolver::eigenvalues(), MatrixBase::eigenvalues() - */ -template<typename MatrixType, unsigned int UpLo> -EIGEN_DEVICE_FUNC inline typename SelfAdjointView<MatrixType, UpLo>::EigenvaluesReturnType -SelfAdjointView<MatrixType, UpLo>::eigenvalues() const -{ - PlainObject thisAsMatrix(*this); - return SelfAdjointEigenSolver<PlainObject>(thisAsMatrix, false).eigenvalues(); -} - - - -/** \brief Computes the L2 operator norm - * \returns Operator norm of the matrix. - * - * \eigenvalues_module - * This function computes the L2 operator norm of a matrix, which is also - * known as the spectral norm. The norm of a matrix \f$ A \f$ is defined to be - * \f[ \|A\|_2 = \max_x \frac{\|Ax\|_2}{\|x\|_2} \f] - * where the maximum is over all vectors and the norm on the right is the - * Euclidean vector norm. The norm equals the largest singular value, which is - * the square root of the largest eigenvalue of the positive semi-definite - * matrix \f$ A^*A \f$. - * - * The current implementation uses the eigenvalues of \f$ A^*A \f$, as computed - * by SelfAdjointView::eigenvalues(), to compute the operator norm of a - * matrix. The SelfAdjointView class provides a better algorithm for - * selfadjoint matrices. - * - * Example: \include MatrixBase_operatorNorm.cpp - * Output: \verbinclude MatrixBase_operatorNorm.out - * - * \sa SelfAdjointView::eigenvalues(), SelfAdjointView::operatorNorm() - */ -template<typename Derived> -inline typename MatrixBase<Derived>::RealScalar -MatrixBase<Derived>::operatorNorm() const -{ - using std::sqrt; - typename Derived::PlainObject m_eval(derived()); - // FIXME if it is really guaranteed that the eigenvalues are already sorted, - // then we don't need to compute a maxCoeff() here, comparing the 1st and last ones is enough. - return sqrt((m_eval*m_eval.adjoint()) - .eval() - .template selfadjointView<Lower>() - .eigenvalues() - .maxCoeff() - ); -} - -/** \brief Computes the L2 operator norm - * \returns Operator norm of the matrix. - * - * \eigenvalues_module - * This function computes the L2 operator norm of a self-adjoint matrix. For a - * self-adjoint matrix, the operator norm is the largest eigenvalue. - * - * The current implementation uses the eigenvalues of the matrix, as computed - * by eigenvalues(), to compute the operator norm of the matrix. - * - * Example: \include SelfAdjointView_operatorNorm.cpp - * Output: \verbinclude SelfAdjointView_operatorNorm.out - * - * \sa eigenvalues(), MatrixBase::operatorNorm() - */ -template<typename MatrixType, unsigned int UpLo> -EIGEN_DEVICE_FUNC inline typename SelfAdjointView<MatrixType, UpLo>::RealScalar -SelfAdjointView<MatrixType, UpLo>::operatorNorm() const -{ - return eigenvalues().cwiseAbs().maxCoeff(); -} - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealQZ.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealQZ.h deleted file mode 100644 index 50913018..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealQZ.h +++ /dev/null @@ -1,657 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Alexey Korepanov <kaikaikai@yandex.ru> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_REAL_QZ_H -#define EIGEN_REAL_QZ_H - -namespace Eigen { - - /** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class RealQZ - * - * \brief Performs a real QZ decomposition of a pair of square matrices - * - * \tparam _MatrixType the type of the matrix of which we are computing the - * real QZ decomposition; this is expected to be an instantiation of the - * Matrix class template. - * - * Given a real square matrices A and B, this class computes the real QZ - * decomposition: \f$ A = Q S Z \f$, \f$ B = Q T Z \f$ where Q and Z are - * real orthogonal matrixes, T is upper-triangular matrix, and S is upper - * quasi-triangular matrix. An orthogonal matrix is a matrix whose - * inverse is equal to its transpose, \f$ U^{-1} = U^T \f$. A quasi-triangular - * matrix is a block-triangular matrix whose diagonal consists of 1-by-1 - * blocks and 2-by-2 blocks where further reduction is impossible due to - * complex eigenvalues. - * - * The eigenvalues of the pencil \f$ A - z B \f$ can be obtained from - * 1x1 and 2x2 blocks on the diagonals of S and T. - * - * Call the function compute() to compute the real QZ decomposition of a - * given pair of matrices. Alternatively, you can use the - * RealQZ(const MatrixType& B, const MatrixType& B, bool computeQZ) - * constructor which computes the real QZ decomposition at construction - * time. Once the decomposition is computed, you can use the matrixS(), - * matrixT(), matrixQ() and matrixZ() functions to retrieve the matrices - * S, T, Q and Z in the decomposition. If computeQZ==false, some time - * is saved by not computing matrices Q and Z. - * - * Example: \include RealQZ_compute.cpp - * Output: \include RealQZ_compute.out - * - * \note The implementation is based on the algorithm in "Matrix Computations" - * by Gene H. Golub and Charles F. Van Loan, and a paper "An algorithm for - * generalized eigenvalue problems" by C.B.Moler and G.W.Stewart. - * - * \sa class RealSchur, class ComplexSchur, class EigenSolver, class ComplexEigenSolver - */ - - template<typename _MatrixType> class RealQZ - { - public: - typedef _MatrixType MatrixType; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - Options = MatrixType::Options, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - typedef typename MatrixType::Scalar Scalar; - typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> EigenvalueType; - typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ColumnVectorType; - - /** \brief Default constructor. - * - * \param [in] size Positive integer, size of the matrix whose QZ decomposition will be computed. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via compute(). The \p size parameter is only - * used as a hint. It is not an error to give a wrong \p size, but it may - * impair performance. - * - * \sa compute() for an example. - */ - explicit RealQZ(Index size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime) : - m_S(size, size), - m_T(size, size), - m_Q(size, size), - m_Z(size, size), - m_workspace(size*2), - m_maxIters(400), - m_isInitialized(false), - m_computeQZ(true) - {} - - /** \brief Constructor; computes real QZ decomposition of given matrices - * - * \param[in] A Matrix A. - * \param[in] B Matrix B. - * \param[in] computeQZ If false, A and Z are not computed. - * - * This constructor calls compute() to compute the QZ decomposition. - */ - RealQZ(const MatrixType& A, const MatrixType& B, bool computeQZ = true) : - m_S(A.rows(),A.cols()), - m_T(A.rows(),A.cols()), - m_Q(A.rows(),A.cols()), - m_Z(A.rows(),A.cols()), - m_workspace(A.rows()*2), - m_maxIters(400), - m_isInitialized(false), - m_computeQZ(true) - { - compute(A, B, computeQZ); - } - - /** \brief Returns matrix Q in the QZ decomposition. - * - * \returns A const reference to the matrix Q. - */ - const MatrixType& matrixQ() const { - eigen_assert(m_isInitialized && "RealQZ is not initialized."); - eigen_assert(m_computeQZ && "The matrices Q and Z have not been computed during the QZ decomposition."); - return m_Q; - } - - /** \brief Returns matrix Z in the QZ decomposition. - * - * \returns A const reference to the matrix Z. - */ - const MatrixType& matrixZ() const { - eigen_assert(m_isInitialized && "RealQZ is not initialized."); - eigen_assert(m_computeQZ && "The matrices Q and Z have not been computed during the QZ decomposition."); - return m_Z; - } - - /** \brief Returns matrix S in the QZ decomposition. - * - * \returns A const reference to the matrix S. - */ - const MatrixType& matrixS() const { - eigen_assert(m_isInitialized && "RealQZ is not initialized."); - return m_S; - } - - /** \brief Returns matrix S in the QZ decomposition. - * - * \returns A const reference to the matrix S. - */ - const MatrixType& matrixT() const { - eigen_assert(m_isInitialized && "RealQZ is not initialized."); - return m_T; - } - - /** \brief Computes QZ decomposition of given matrix. - * - * \param[in] A Matrix A. - * \param[in] B Matrix B. - * \param[in] computeQZ If false, A and Z are not computed. - * \returns Reference to \c *this - */ - RealQZ& compute(const MatrixType& A, const MatrixType& B, bool computeQZ = true); - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, \c NoConvergence otherwise. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "RealQZ is not initialized."); - return m_info; - } - - /** \brief Returns number of performed QR-like iterations. - */ - Index iterations() const - { - eigen_assert(m_isInitialized && "RealQZ is not initialized."); - return m_global_iter; - } - - /** Sets the maximal number of iterations allowed to converge to one eigenvalue - * or decouple the problem. - */ - RealQZ& setMaxIterations(Index maxIters) - { - m_maxIters = maxIters; - return *this; - } - - private: - - MatrixType m_S, m_T, m_Q, m_Z; - Matrix<Scalar,Dynamic,1> m_workspace; - ComputationInfo m_info; - Index m_maxIters; - bool m_isInitialized; - bool m_computeQZ; - Scalar m_normOfT, m_normOfS; - Index m_global_iter; - - typedef Matrix<Scalar,3,1> Vector3s; - typedef Matrix<Scalar,2,1> Vector2s; - typedef Matrix<Scalar,2,2> Matrix2s; - typedef JacobiRotation<Scalar> JRs; - - void hessenbergTriangular(); - void computeNorms(); - Index findSmallSubdiagEntry(Index iu); - Index findSmallDiagEntry(Index f, Index l); - void splitOffTwoRows(Index i); - void pushDownZero(Index z, Index f, Index l); - void step(Index f, Index l, Index iter); - - }; // RealQZ - - /** \internal Reduces S and T to upper Hessenberg - triangular form */ - template<typename MatrixType> - void RealQZ<MatrixType>::hessenbergTriangular() - { - - const Index dim = m_S.cols(); - - // perform QR decomposition of T, overwrite T with R, save Q - HouseholderQR<MatrixType> qrT(m_T); - m_T = qrT.matrixQR(); - m_T.template triangularView<StrictlyLower>().setZero(); - m_Q = qrT.householderQ(); - // overwrite S with Q* S - m_S.applyOnTheLeft(m_Q.adjoint()); - // init Z as Identity - if (m_computeQZ) - m_Z = MatrixType::Identity(dim,dim); - // reduce S to upper Hessenberg with Givens rotations - for (Index j=0; j<=dim-3; j++) { - for (Index i=dim-1; i>=j+2; i--) { - JRs G; - // kill S(i,j) - if(m_S.coeff(i,j) != 0) - { - G.makeGivens(m_S.coeff(i-1,j), m_S.coeff(i,j), &m_S.coeffRef(i-1, j)); - m_S.coeffRef(i,j) = Scalar(0.0); - m_S.rightCols(dim-j-1).applyOnTheLeft(i-1,i,G.adjoint()); - m_T.rightCols(dim-i+1).applyOnTheLeft(i-1,i,G.adjoint()); - // update Q - if (m_computeQZ) - m_Q.applyOnTheRight(i-1,i,G); - } - // kill T(i,i-1) - if(m_T.coeff(i,i-1)!=Scalar(0)) - { - G.makeGivens(m_T.coeff(i,i), m_T.coeff(i,i-1), &m_T.coeffRef(i,i)); - m_T.coeffRef(i,i-1) = Scalar(0.0); - m_S.applyOnTheRight(i,i-1,G); - m_T.topRows(i).applyOnTheRight(i,i-1,G); - // update Z - if (m_computeQZ) - m_Z.applyOnTheLeft(i,i-1,G.adjoint()); - } - } - } - } - - /** \internal Computes vector L1 norms of S and T when in Hessenberg-Triangular form already */ - template<typename MatrixType> - inline void RealQZ<MatrixType>::computeNorms() - { - const Index size = m_S.cols(); - m_normOfS = Scalar(0.0); - m_normOfT = Scalar(0.0); - for (Index j = 0; j < size; ++j) - { - m_normOfS += m_S.col(j).segment(0, (std::min)(size,j+2)).cwiseAbs().sum(); - m_normOfT += m_T.row(j).segment(j, size - j).cwiseAbs().sum(); - } - } - - - /** \internal Look for single small sub-diagonal element S(res, res-1) and return res (or 0) */ - template<typename MatrixType> - inline Index RealQZ<MatrixType>::findSmallSubdiagEntry(Index iu) - { - using std::abs; - Index res = iu; - while (res > 0) - { - Scalar s = abs(m_S.coeff(res-1,res-1)) + abs(m_S.coeff(res,res)); - if (s == Scalar(0.0)) - s = m_normOfS; - if (abs(m_S.coeff(res,res-1)) < NumTraits<Scalar>::epsilon() * s) - break; - res--; - } - return res; - } - - /** \internal Look for single small diagonal element T(res, res) for res between f and l, and return res (or f-1) */ - template<typename MatrixType> - inline Index RealQZ<MatrixType>::findSmallDiagEntry(Index f, Index l) - { - using std::abs; - Index res = l; - while (res >= f) { - if (abs(m_T.coeff(res,res)) <= NumTraits<Scalar>::epsilon() * m_normOfT) - break; - res--; - } - return res; - } - - /** \internal decouple 2x2 diagonal block in rows i, i+1 if eigenvalues are real */ - template<typename MatrixType> - inline void RealQZ<MatrixType>::splitOffTwoRows(Index i) - { - using std::abs; - using std::sqrt; - const Index dim=m_S.cols(); - if (abs(m_S.coeff(i+1,i))==Scalar(0)) - return; - Index j = findSmallDiagEntry(i,i+1); - if (j==i-1) - { - // block of (S T^{-1}) - Matrix2s STi = m_T.template block<2,2>(i,i).template triangularView<Upper>(). - template solve<OnTheRight>(m_S.template block<2,2>(i,i)); - Scalar p = Scalar(0.5)*(STi(0,0)-STi(1,1)); - Scalar q = p*p + STi(1,0)*STi(0,1); - if (q>=0) { - Scalar z = sqrt(q); - // one QR-like iteration for ABi - lambda I - // is enough - when we know exact eigenvalue in advance, - // convergence is immediate - JRs G; - if (p>=0) - G.makeGivens(p + z, STi(1,0)); - else - G.makeGivens(p - z, STi(1,0)); - m_S.rightCols(dim-i).applyOnTheLeft(i,i+1,G.adjoint()); - m_T.rightCols(dim-i).applyOnTheLeft(i,i+1,G.adjoint()); - // update Q - if (m_computeQZ) - m_Q.applyOnTheRight(i,i+1,G); - - G.makeGivens(m_T.coeff(i+1,i+1), m_T.coeff(i+1,i)); - m_S.topRows(i+2).applyOnTheRight(i+1,i,G); - m_T.topRows(i+2).applyOnTheRight(i+1,i,G); - // update Z - if (m_computeQZ) - m_Z.applyOnTheLeft(i+1,i,G.adjoint()); - - m_S.coeffRef(i+1,i) = Scalar(0.0); - m_T.coeffRef(i+1,i) = Scalar(0.0); - } - } - else - { - pushDownZero(j,i,i+1); - } - } - - /** \internal use zero in T(z,z) to zero S(l,l-1), working in block f..l */ - template<typename MatrixType> - inline void RealQZ<MatrixType>::pushDownZero(Index z, Index f, Index l) - { - JRs G; - const Index dim = m_S.cols(); - for (Index zz=z; zz<l; zz++) - { - // push 0 down - Index firstColS = zz>f ? (zz-1) : zz; - G.makeGivens(m_T.coeff(zz, zz+1), m_T.coeff(zz+1, zz+1)); - m_S.rightCols(dim-firstColS).applyOnTheLeft(zz,zz+1,G.adjoint()); - m_T.rightCols(dim-zz).applyOnTheLeft(zz,zz+1,G.adjoint()); - m_T.coeffRef(zz+1,zz+1) = Scalar(0.0); - // update Q - if (m_computeQZ) - m_Q.applyOnTheRight(zz,zz+1,G); - // kill S(zz+1, zz-1) - if (zz>f) - { - G.makeGivens(m_S.coeff(zz+1, zz), m_S.coeff(zz+1,zz-1)); - m_S.topRows(zz+2).applyOnTheRight(zz, zz-1,G); - m_T.topRows(zz+1).applyOnTheRight(zz, zz-1,G); - m_S.coeffRef(zz+1,zz-1) = Scalar(0.0); - // update Z - if (m_computeQZ) - m_Z.applyOnTheLeft(zz,zz-1,G.adjoint()); - } - } - // finally kill S(l,l-1) - G.makeGivens(m_S.coeff(l,l), m_S.coeff(l,l-1)); - m_S.applyOnTheRight(l,l-1,G); - m_T.applyOnTheRight(l,l-1,G); - m_S.coeffRef(l,l-1)=Scalar(0.0); - // update Z - if (m_computeQZ) - m_Z.applyOnTheLeft(l,l-1,G.adjoint()); - } - - /** \internal QR-like iterative step for block f..l */ - template<typename MatrixType> - inline void RealQZ<MatrixType>::step(Index f, Index l, Index iter) - { - using std::abs; - const Index dim = m_S.cols(); - - // x, y, z - Scalar x, y, z; - if (iter==10) - { - // Wilkinson ad hoc shift - const Scalar - a11=m_S.coeff(f+0,f+0), a12=m_S.coeff(f+0,f+1), - a21=m_S.coeff(f+1,f+0), a22=m_S.coeff(f+1,f+1), a32=m_S.coeff(f+2,f+1), - b12=m_T.coeff(f+0,f+1), - b11i=Scalar(1.0)/m_T.coeff(f+0,f+0), - b22i=Scalar(1.0)/m_T.coeff(f+1,f+1), - a87=m_S.coeff(l-1,l-2), - a98=m_S.coeff(l-0,l-1), - b77i=Scalar(1.0)/m_T.coeff(l-2,l-2), - b88i=Scalar(1.0)/m_T.coeff(l-1,l-1); - Scalar ss = abs(a87*b77i) + abs(a98*b88i), - lpl = Scalar(1.5)*ss, - ll = ss*ss; - x = ll + a11*a11*b11i*b11i - lpl*a11*b11i + a12*a21*b11i*b22i - - a11*a21*b12*b11i*b11i*b22i; - y = a11*a21*b11i*b11i - lpl*a21*b11i + a21*a22*b11i*b22i - - a21*a21*b12*b11i*b11i*b22i; - z = a21*a32*b11i*b22i; - } - else if (iter==16) - { - // another exceptional shift - x = m_S.coeff(f,f)/m_T.coeff(f,f)-m_S.coeff(l,l)/m_T.coeff(l,l) + m_S.coeff(l,l-1)*m_T.coeff(l-1,l) / - (m_T.coeff(l-1,l-1)*m_T.coeff(l,l)); - y = m_S.coeff(f+1,f)/m_T.coeff(f,f); - z = 0; - } - else if (iter>23 && !(iter%8)) - { - // extremely exceptional shift - x = internal::random<Scalar>(-1.0,1.0); - y = internal::random<Scalar>(-1.0,1.0); - z = internal::random<Scalar>(-1.0,1.0); - } - else - { - // Compute the shifts: (x,y,z,0...) = (AB^-1 - l1 I) (AB^-1 - l2 I) e1 - // where l1 and l2 are the eigenvalues of the 2x2 matrix C = U V^-1 where - // U and V are 2x2 bottom right sub matrices of A and B. Thus: - // = AB^-1AB^-1 + l1 l2 I - (l1+l2)(AB^-1) - // = AB^-1AB^-1 + det(M) - tr(M)(AB^-1) - // Since we are only interested in having x, y, z with a correct ratio, we have: - const Scalar - a11 = m_S.coeff(f,f), a12 = m_S.coeff(f,f+1), - a21 = m_S.coeff(f+1,f), a22 = m_S.coeff(f+1,f+1), - a32 = m_S.coeff(f+2,f+1), - - a88 = m_S.coeff(l-1,l-1), a89 = m_S.coeff(l-1,l), - a98 = m_S.coeff(l,l-1), a99 = m_S.coeff(l,l), - - b11 = m_T.coeff(f,f), b12 = m_T.coeff(f,f+1), - b22 = m_T.coeff(f+1,f+1), - - b88 = m_T.coeff(l-1,l-1), b89 = m_T.coeff(l-1,l), - b99 = m_T.coeff(l,l); - - x = ( (a88/b88 - a11/b11)*(a99/b99 - a11/b11) - (a89/b99)*(a98/b88) + (a98/b88)*(b89/b99)*(a11/b11) ) * (b11/a21) - + a12/b22 - (a11/b11)*(b12/b22); - y = (a22/b22-a11/b11) - (a21/b11)*(b12/b22) - (a88/b88-a11/b11) - (a99/b99-a11/b11) + (a98/b88)*(b89/b99); - z = a32/b22; - } - - JRs G; - - for (Index k=f; k<=l-2; k++) - { - // variables for Householder reflections - Vector2s essential2; - Scalar tau, beta; - - Vector3s hr(x,y,z); - - // Q_k to annihilate S(k+1,k-1) and S(k+2,k-1) - hr.makeHouseholderInPlace(tau, beta); - essential2 = hr.template bottomRows<2>(); - Index fc=(std::max)(k-1,Index(0)); // first col to update - m_S.template middleRows<3>(k).rightCols(dim-fc).applyHouseholderOnTheLeft(essential2, tau, m_workspace.data()); - m_T.template middleRows<3>(k).rightCols(dim-fc).applyHouseholderOnTheLeft(essential2, tau, m_workspace.data()); - if (m_computeQZ) - m_Q.template middleCols<3>(k).applyHouseholderOnTheRight(essential2, tau, m_workspace.data()); - if (k>f) - m_S.coeffRef(k+2,k-1) = m_S.coeffRef(k+1,k-1) = Scalar(0.0); - - // Z_{k1} to annihilate T(k+2,k+1) and T(k+2,k) - hr << m_T.coeff(k+2,k+2),m_T.coeff(k+2,k),m_T.coeff(k+2,k+1); - hr.makeHouseholderInPlace(tau, beta); - essential2 = hr.template bottomRows<2>(); - { - Index lr = (std::min)(k+4,dim); // last row to update - Map<Matrix<Scalar,Dynamic,1> > tmp(m_workspace.data(),lr); - // S - tmp = m_S.template middleCols<2>(k).topRows(lr) * essential2; - tmp += m_S.col(k+2).head(lr); - m_S.col(k+2).head(lr) -= tau*tmp; - m_S.template middleCols<2>(k).topRows(lr) -= (tau*tmp) * essential2.adjoint(); - // T - tmp = m_T.template middleCols<2>(k).topRows(lr) * essential2; - tmp += m_T.col(k+2).head(lr); - m_T.col(k+2).head(lr) -= tau*tmp; - m_T.template middleCols<2>(k).topRows(lr) -= (tau*tmp) * essential2.adjoint(); - } - if (m_computeQZ) - { - // Z - Map<Matrix<Scalar,1,Dynamic> > tmp(m_workspace.data(),dim); - tmp = essential2.adjoint()*(m_Z.template middleRows<2>(k)); - tmp += m_Z.row(k+2); - m_Z.row(k+2) -= tau*tmp; - m_Z.template middleRows<2>(k) -= essential2 * (tau*tmp); - } - m_T.coeffRef(k+2,k) = m_T.coeffRef(k+2,k+1) = Scalar(0.0); - - // Z_{k2} to annihilate T(k+1,k) - G.makeGivens(m_T.coeff(k+1,k+1), m_T.coeff(k+1,k)); - m_S.applyOnTheRight(k+1,k,G); - m_T.applyOnTheRight(k+1,k,G); - // update Z - if (m_computeQZ) - m_Z.applyOnTheLeft(k+1,k,G.adjoint()); - m_T.coeffRef(k+1,k) = Scalar(0.0); - - // update x,y,z - x = m_S.coeff(k+1,k); - y = m_S.coeff(k+2,k); - if (k < l-2) - z = m_S.coeff(k+3,k); - } // loop over k - - // Q_{n-1} to annihilate y = S(l,l-2) - G.makeGivens(x,y); - m_S.applyOnTheLeft(l-1,l,G.adjoint()); - m_T.applyOnTheLeft(l-1,l,G.adjoint()); - if (m_computeQZ) - m_Q.applyOnTheRight(l-1,l,G); - m_S.coeffRef(l,l-2) = Scalar(0.0); - - // Z_{n-1} to annihilate T(l,l-1) - G.makeGivens(m_T.coeff(l,l),m_T.coeff(l,l-1)); - m_S.applyOnTheRight(l,l-1,G); - m_T.applyOnTheRight(l,l-1,G); - if (m_computeQZ) - m_Z.applyOnTheLeft(l,l-1,G.adjoint()); - m_T.coeffRef(l,l-1) = Scalar(0.0); - } - - template<typename MatrixType> - RealQZ<MatrixType>& RealQZ<MatrixType>::compute(const MatrixType& A_in, const MatrixType& B_in, bool computeQZ) - { - - const Index dim = A_in.cols(); - - eigen_assert (A_in.rows()==dim && A_in.cols()==dim - && B_in.rows()==dim && B_in.cols()==dim - && "Need square matrices of the same dimension"); - - m_isInitialized = true; - m_computeQZ = computeQZ; - m_S = A_in; m_T = B_in; - m_workspace.resize(dim*2); - m_global_iter = 0; - - // entrance point: hessenberg triangular decomposition - hessenbergTriangular(); - // compute L1 vector norms of T, S into m_normOfS, m_normOfT - computeNorms(); - - Index l = dim-1, - f, - local_iter = 0; - - while (l>0 && local_iter<m_maxIters) - { - f = findSmallSubdiagEntry(l); - // now rows and columns f..l (including) decouple from the rest of the problem - if (f>0) m_S.coeffRef(f,f-1) = Scalar(0.0); - if (f == l) // One root found - { - l--; - local_iter = 0; - } - else if (f == l-1) // Two roots found - { - splitOffTwoRows(f); - l -= 2; - local_iter = 0; - } - else // No convergence yet - { - // if there's zero on diagonal of T, we can isolate an eigenvalue with Givens rotations - Index z = findSmallDiagEntry(f,l); - if (z>=f) - { - // zero found - pushDownZero(z,f,l); - } - else - { - // We are sure now that S.block(f,f, l-f+1,l-f+1) is underuced upper-Hessenberg - // and T.block(f,f, l-f+1,l-f+1) is invertible uper-triangular, which allows to - // apply a QR-like iteration to rows and columns f..l. - step(f,l, local_iter); - local_iter++; - m_global_iter++; - } - } - } - // check if we converged before reaching iterations limit - m_info = (local_iter<m_maxIters) ? Success : NoConvergence; - - // For each non triangular 2x2 diagonal block of S, - // reduce the respective 2x2 diagonal block of T to positive diagonal form using 2x2 SVD. - // This step is not mandatory for QZ, but it does help further extraction of eigenvalues/eigenvectors, - // and is in par with Lapack/Matlab QZ. - if(m_info==Success) - { - for(Index i=0; i<dim-1; ++i) - { - if(m_S.coeff(i+1, i) != Scalar(0)) - { - JacobiRotation<Scalar> j_left, j_right; - internal::real_2x2_jacobi_svd(m_T, i, i+1, &j_left, &j_right); - - // Apply resulting Jacobi rotations - m_S.applyOnTheLeft(i,i+1,j_left); - m_S.applyOnTheRight(i,i+1,j_right); - m_T.applyOnTheLeft(i,i+1,j_left); - m_T.applyOnTheRight(i,i+1,j_right); - m_T(i+1,i) = m_T(i,i+1) = Scalar(0); - - if(m_computeQZ) { - m_Q.applyOnTheRight(i,i+1,j_left.transpose()); - m_Z.applyOnTheLeft(i,i+1,j_right.transpose()); - } - - i++; - } - } - } - - return *this; - } // end compute - -} // end namespace Eigen - -#endif //EIGEN_REAL_QZ diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealSchur.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealSchur.h deleted file mode 100644 index 7304ef34..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealSchur.h +++ /dev/null @@ -1,558 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_REAL_SCHUR_H -#define EIGEN_REAL_SCHUR_H - -#include "./HessenbergDecomposition.h" - -namespace Eigen { - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class RealSchur - * - * \brief Performs a real Schur decomposition of a square matrix - * - * \tparam _MatrixType the type of the matrix of which we are computing the - * real Schur decomposition; this is expected to be an instantiation of the - * Matrix class template. - * - * Given a real square matrix A, this class computes the real Schur - * decomposition: \f$ A = U T U^T \f$ where U is a real orthogonal matrix and - * T is a real quasi-triangular matrix. An orthogonal matrix is a matrix whose - * inverse is equal to its transpose, \f$ U^{-1} = U^T \f$. A quasi-triangular - * matrix is a block-triangular matrix whose diagonal consists of 1-by-1 - * blocks and 2-by-2 blocks with complex eigenvalues. The eigenvalues of the - * blocks on the diagonal of T are the same as the eigenvalues of the matrix - * A, and thus the real Schur decomposition is used in EigenSolver to compute - * the eigendecomposition of a matrix. - * - * Call the function compute() to compute the real Schur decomposition of a - * given matrix. Alternatively, you can use the RealSchur(const MatrixType&, bool) - * constructor which computes the real Schur decomposition at construction - * time. Once the decomposition is computed, you can use the matrixU() and - * matrixT() functions to retrieve the matrices U and T in the decomposition. - * - * The documentation of RealSchur(const MatrixType&, bool) contains an example - * of the typical use of this class. - * - * \note The implementation is adapted from - * <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> (public domain). - * Their code is based on EISPACK. - * - * \sa class ComplexSchur, class EigenSolver, class ComplexEigenSolver - */ -template<typename _MatrixType> class RealSchur -{ - public: - typedef _MatrixType MatrixType; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - Options = MatrixType::Options, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - typedef typename MatrixType::Scalar Scalar; - typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> EigenvalueType; - typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ColumnVectorType; - - /** \brief Default constructor. - * - * \param [in] size Positive integer, size of the matrix whose Schur decomposition will be computed. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via compute(). The \p size parameter is only - * used as a hint. It is not an error to give a wrong \p size, but it may - * impair performance. - * - * \sa compute() for an example. - */ - explicit RealSchur(Index size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime) - : m_matT(size, size), - m_matU(size, size), - m_workspaceVector(size), - m_hess(size), - m_isInitialized(false), - m_matUisUptodate(false), - m_maxIters(-1) - { } - - /** \brief Constructor; computes real Schur decomposition of given matrix. - * - * \param[in] matrix Square matrix whose Schur decomposition is to be computed. - * \param[in] computeU If true, both T and U are computed; if false, only T is computed. - * - * This constructor calls compute() to compute the Schur decomposition. - * - * Example: \include RealSchur_RealSchur_MatrixType.cpp - * Output: \verbinclude RealSchur_RealSchur_MatrixType.out - */ - template<typename InputType> - explicit RealSchur(const EigenBase<InputType>& matrix, bool computeU = true) - : m_matT(matrix.rows(),matrix.cols()), - m_matU(matrix.rows(),matrix.cols()), - m_workspaceVector(matrix.rows()), - m_hess(matrix.rows()), - m_isInitialized(false), - m_matUisUptodate(false), - m_maxIters(-1) - { - compute(matrix.derived(), computeU); - } - - /** \brief Returns the orthogonal matrix in the Schur decomposition. - * - * \returns A const reference to the matrix U. - * - * \pre Either the constructor RealSchur(const MatrixType&, bool) or the - * member function compute(const MatrixType&, bool) has been called before - * to compute the Schur decomposition of a matrix, and \p computeU was set - * to true (the default value). - * - * \sa RealSchur(const MatrixType&, bool) for an example - */ - const MatrixType& matrixU() const - { - eigen_assert(m_isInitialized && "RealSchur is not initialized."); - eigen_assert(m_matUisUptodate && "The matrix U has not been computed during the RealSchur decomposition."); - return m_matU; - } - - /** \brief Returns the quasi-triangular matrix in the Schur decomposition. - * - * \returns A const reference to the matrix T. - * - * \pre Either the constructor RealSchur(const MatrixType&, bool) or the - * member function compute(const MatrixType&, bool) has been called before - * to compute the Schur decomposition of a matrix. - * - * \sa RealSchur(const MatrixType&, bool) for an example - */ - const MatrixType& matrixT() const - { - eigen_assert(m_isInitialized && "RealSchur is not initialized."); - return m_matT; - } - - /** \brief Computes Schur decomposition of given matrix. - * - * \param[in] matrix Square matrix whose Schur decomposition is to be computed. - * \param[in] computeU If true, both T and U are computed; if false, only T is computed. - * \returns Reference to \c *this - * - * The Schur decomposition is computed by first reducing the matrix to - * Hessenberg form using the class HessenbergDecomposition. The Hessenberg - * matrix is then reduced to triangular form by performing Francis QR - * iterations with implicit double shift. The cost of computing the Schur - * decomposition depends on the number of iterations; as a rough guide, it - * may be taken to be \f$25n^3\f$ flops if \a computeU is true and - * \f$10n^3\f$ flops if \a computeU is false. - * - * Example: \include RealSchur_compute.cpp - * Output: \verbinclude RealSchur_compute.out - * - * \sa compute(const MatrixType&, bool, Index) - */ - template<typename InputType> - RealSchur& compute(const EigenBase<InputType>& matrix, bool computeU = true); - - /** \brief Computes Schur decomposition of a Hessenberg matrix H = Z T Z^T - * \param[in] matrixH Matrix in Hessenberg form H - * \param[in] matrixQ orthogonal matrix Q that transform a matrix A to H : A = Q H Q^T - * \param computeU Computes the matriX U of the Schur vectors - * \return Reference to \c *this - * - * This routine assumes that the matrix is already reduced in Hessenberg form matrixH - * using either the class HessenbergDecomposition or another mean. - * It computes the upper quasi-triangular matrix T of the Schur decomposition of H - * When computeU is true, this routine computes the matrix U such that - * A = U T U^T = (QZ) T (QZ)^T = Q H Q^T where A is the initial matrix - * - * NOTE Q is referenced if computeU is true; so, if the initial orthogonal matrix - * is not available, the user should give an identity matrix (Q.setIdentity()) - * - * \sa compute(const MatrixType&, bool) - */ - template<typename HessMatrixType, typename OrthMatrixType> - RealSchur& computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU); - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, \c NoConvergence otherwise. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "RealSchur is not initialized."); - return m_info; - } - - /** \brief Sets the maximum number of iterations allowed. - * - * If not specified by the user, the maximum number of iterations is m_maxIterationsPerRow times the size - * of the matrix. - */ - RealSchur& setMaxIterations(Index maxIters) - { - m_maxIters = maxIters; - return *this; - } - - /** \brief Returns the maximum number of iterations. */ - Index getMaxIterations() - { - return m_maxIters; - } - - /** \brief Maximum number of iterations per row. - * - * If not otherwise specified, the maximum number of iterations is this number times the size of the - * matrix. It is currently set to 40. - */ - static const int m_maxIterationsPerRow = 40; - - private: - - MatrixType m_matT; - MatrixType m_matU; - ColumnVectorType m_workspaceVector; - HessenbergDecomposition<MatrixType> m_hess; - ComputationInfo m_info; - bool m_isInitialized; - bool m_matUisUptodate; - Index m_maxIters; - - typedef Matrix<Scalar,3,1> Vector3s; - - Scalar computeNormOfT(); - Index findSmallSubdiagEntry(Index iu, const Scalar& considerAsZero); - void splitOffTwoRows(Index iu, bool computeU, const Scalar& exshift); - void computeShift(Index iu, Index iter, Scalar& exshift, Vector3s& shiftInfo); - void initFrancisQRStep(Index il, Index iu, const Vector3s& shiftInfo, Index& im, Vector3s& firstHouseholderVector); - void performFrancisQRStep(Index il, Index im, Index iu, bool computeU, const Vector3s& firstHouseholderVector, Scalar* workspace); -}; - - -template<typename MatrixType> -template<typename InputType> -RealSchur<MatrixType>& RealSchur<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeU) -{ - const Scalar considerAsZero = (std::numeric_limits<Scalar>::min)(); - - eigen_assert(matrix.cols() == matrix.rows()); - Index maxIters = m_maxIters; - if (maxIters == -1) - maxIters = m_maxIterationsPerRow * matrix.rows(); - - Scalar scale = matrix.derived().cwiseAbs().maxCoeff(); - if(scale<considerAsZero) - { - m_matT.setZero(matrix.rows(),matrix.cols()); - if(computeU) - m_matU.setIdentity(matrix.rows(),matrix.cols()); - m_info = Success; - m_isInitialized = true; - m_matUisUptodate = computeU; - return *this; - } - - // Step 1. Reduce to Hessenberg form - m_hess.compute(matrix.derived()/scale); - - // Step 2. Reduce to real Schur form - // Note: we copy m_hess.matrixQ() into m_matU here and not in computeFromHessenberg - // to be able to pass our working-space buffer for the Householder to Dense evaluation. - m_workspaceVector.resize(matrix.cols()); - if(computeU) - m_hess.matrixQ().evalTo(m_matU, m_workspaceVector); - computeFromHessenberg(m_hess.matrixH(), m_matU, computeU); - - m_matT *= scale; - - return *this; -} -template<typename MatrixType> -template<typename HessMatrixType, typename OrthMatrixType> -RealSchur<MatrixType>& RealSchur<MatrixType>::computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU) -{ - using std::abs; - - m_matT = matrixH; - m_workspaceVector.resize(m_matT.cols()); - if(computeU && !internal::is_same_dense(m_matU,matrixQ)) - m_matU = matrixQ; - - Index maxIters = m_maxIters; - if (maxIters == -1) - maxIters = m_maxIterationsPerRow * matrixH.rows(); - Scalar* workspace = &m_workspaceVector.coeffRef(0); - - // The matrix m_matT is divided in three parts. - // Rows 0,...,il-1 are decoupled from the rest because m_matT(il,il-1) is zero. - // Rows il,...,iu is the part we are working on (the active window). - // Rows iu+1,...,end are already brought in triangular form. - Index iu = m_matT.cols() - 1; - Index iter = 0; // iteration count for current eigenvalue - Index totalIter = 0; // iteration count for whole matrix - Scalar exshift(0); // sum of exceptional shifts - Scalar norm = computeNormOfT(); - // sub-diagonal entries smaller than considerAsZero will be treated as zero. - // We use eps^2 to enable more precision in small eigenvalues. - Scalar considerAsZero = numext::maxi<Scalar>( norm * numext::abs2(NumTraits<Scalar>::epsilon()), - (std::numeric_limits<Scalar>::min)() ); - - if(norm!=Scalar(0)) - { - while (iu >= 0) - { - Index il = findSmallSubdiagEntry(iu,considerAsZero); - - // Check for convergence - if (il == iu) // One root found - { - m_matT.coeffRef(iu,iu) = m_matT.coeff(iu,iu) + exshift; - if (iu > 0) - m_matT.coeffRef(iu, iu-1) = Scalar(0); - iu--; - iter = 0; - } - else if (il == iu-1) // Two roots found - { - splitOffTwoRows(iu, computeU, exshift); - iu -= 2; - iter = 0; - } - else // No convergence yet - { - // The firstHouseholderVector vector has to be initialized to something to get rid of a silly GCC warning (-O1 -Wall -DNDEBUG ) - Vector3s firstHouseholderVector = Vector3s::Zero(), shiftInfo; - computeShift(iu, iter, exshift, shiftInfo); - iter = iter + 1; - totalIter = totalIter + 1; - if (totalIter > maxIters) break; - Index im; - initFrancisQRStep(il, iu, shiftInfo, im, firstHouseholderVector); - performFrancisQRStep(il, im, iu, computeU, firstHouseholderVector, workspace); - } - } - } - if(totalIter <= maxIters) - m_info = Success; - else - m_info = NoConvergence; - - m_isInitialized = true; - m_matUisUptodate = computeU; - return *this; -} - -/** \internal Computes and returns vector L1 norm of T */ -template<typename MatrixType> -inline typename MatrixType::Scalar RealSchur<MatrixType>::computeNormOfT() -{ - const Index size = m_matT.cols(); - // FIXME to be efficient the following would requires a triangular reduxion code - // Scalar norm = m_matT.upper().cwiseAbs().sum() - // + m_matT.bottomLeftCorner(size-1,size-1).diagonal().cwiseAbs().sum(); - Scalar norm(0); - for (Index j = 0; j < size; ++j) - norm += m_matT.col(j).segment(0, (std::min)(size,j+2)).cwiseAbs().sum(); - return norm; -} - -/** \internal Look for single small sub-diagonal element and returns its index */ -template<typename MatrixType> -inline Index RealSchur<MatrixType>::findSmallSubdiagEntry(Index iu, const Scalar& considerAsZero) -{ - using std::abs; - Index res = iu; - while (res > 0) - { - Scalar s = abs(m_matT.coeff(res-1,res-1)) + abs(m_matT.coeff(res,res)); - - s = numext::maxi<Scalar>(s * NumTraits<Scalar>::epsilon(), considerAsZero); - - if (abs(m_matT.coeff(res,res-1)) <= s) - break; - res--; - } - return res; -} - -/** \internal Update T given that rows iu-1 and iu decouple from the rest. */ -template<typename MatrixType> -inline void RealSchur<MatrixType>::splitOffTwoRows(Index iu, bool computeU, const Scalar& exshift) -{ - using std::sqrt; - using std::abs; - const Index size = m_matT.cols(); - - // The eigenvalues of the 2x2 matrix [a b; c d] are - // trace +/- sqrt(discr/4) where discr = tr^2 - 4*det, tr = a + d, det = ad - bc - Scalar p = Scalar(0.5) * (m_matT.coeff(iu-1,iu-1) - m_matT.coeff(iu,iu)); - Scalar q = p * p + m_matT.coeff(iu,iu-1) * m_matT.coeff(iu-1,iu); // q = tr^2 / 4 - det = discr/4 - m_matT.coeffRef(iu,iu) += exshift; - m_matT.coeffRef(iu-1,iu-1) += exshift; - - if (q >= Scalar(0)) // Two real eigenvalues - { - Scalar z = sqrt(abs(q)); - JacobiRotation<Scalar> rot; - if (p >= Scalar(0)) - rot.makeGivens(p + z, m_matT.coeff(iu, iu-1)); - else - rot.makeGivens(p - z, m_matT.coeff(iu, iu-1)); - - m_matT.rightCols(size-iu+1).applyOnTheLeft(iu-1, iu, rot.adjoint()); - m_matT.topRows(iu+1).applyOnTheRight(iu-1, iu, rot); - m_matT.coeffRef(iu, iu-1) = Scalar(0); - if (computeU) - m_matU.applyOnTheRight(iu-1, iu, rot); - } - - if (iu > 1) - m_matT.coeffRef(iu-1, iu-2) = Scalar(0); -} - -/** \internal Form shift in shiftInfo, and update exshift if an exceptional shift is performed. */ -template<typename MatrixType> -inline void RealSchur<MatrixType>::computeShift(Index iu, Index iter, Scalar& exshift, Vector3s& shiftInfo) -{ - using std::sqrt; - using std::abs; - shiftInfo.coeffRef(0) = m_matT.coeff(iu,iu); - shiftInfo.coeffRef(1) = m_matT.coeff(iu-1,iu-1); - shiftInfo.coeffRef(2) = m_matT.coeff(iu,iu-1) * m_matT.coeff(iu-1,iu); - - // Wilkinson's original ad hoc shift - if (iter == 10) - { - exshift += shiftInfo.coeff(0); - for (Index i = 0; i <= iu; ++i) - m_matT.coeffRef(i,i) -= shiftInfo.coeff(0); - Scalar s = abs(m_matT.coeff(iu,iu-1)) + abs(m_matT.coeff(iu-1,iu-2)); - shiftInfo.coeffRef(0) = Scalar(0.75) * s; - shiftInfo.coeffRef(1) = Scalar(0.75) * s; - shiftInfo.coeffRef(2) = Scalar(-0.4375) * s * s; - } - - // MATLAB's new ad hoc shift - if (iter == 30) - { - Scalar s = (shiftInfo.coeff(1) - shiftInfo.coeff(0)) / Scalar(2.0); - s = s * s + shiftInfo.coeff(2); - if (s > Scalar(0)) - { - s = sqrt(s); - if (shiftInfo.coeff(1) < shiftInfo.coeff(0)) - s = -s; - s = s + (shiftInfo.coeff(1) - shiftInfo.coeff(0)) / Scalar(2.0); - s = shiftInfo.coeff(0) - shiftInfo.coeff(2) / s; - exshift += s; - for (Index i = 0; i <= iu; ++i) - m_matT.coeffRef(i,i) -= s; - shiftInfo.setConstant(Scalar(0.964)); - } - } -} - -/** \internal Compute index im at which Francis QR step starts and the first Householder vector. */ -template<typename MatrixType> -inline void RealSchur<MatrixType>::initFrancisQRStep(Index il, Index iu, const Vector3s& shiftInfo, Index& im, Vector3s& firstHouseholderVector) -{ - using std::abs; - Vector3s& v = firstHouseholderVector; // alias to save typing - - for (im = iu-2; im >= il; --im) - { - const Scalar Tmm = m_matT.coeff(im,im); - const Scalar r = shiftInfo.coeff(0) - Tmm; - const Scalar s = shiftInfo.coeff(1) - Tmm; - v.coeffRef(0) = (r * s - shiftInfo.coeff(2)) / m_matT.coeff(im+1,im) + m_matT.coeff(im,im+1); - v.coeffRef(1) = m_matT.coeff(im+1,im+1) - Tmm - r - s; - v.coeffRef(2) = m_matT.coeff(im+2,im+1); - if (im == il) { - break; - } - const Scalar lhs = m_matT.coeff(im,im-1) * (abs(v.coeff(1)) + abs(v.coeff(2))); - const Scalar rhs = v.coeff(0) * (abs(m_matT.coeff(im-1,im-1)) + abs(Tmm) + abs(m_matT.coeff(im+1,im+1))); - if (abs(lhs) < NumTraits<Scalar>::epsilon() * rhs) - break; - } -} - -/** \internal Perform a Francis QR step involving rows il:iu and columns im:iu. */ -template<typename MatrixType> -inline void RealSchur<MatrixType>::performFrancisQRStep(Index il, Index im, Index iu, bool computeU, const Vector3s& firstHouseholderVector, Scalar* workspace) -{ - eigen_assert(im >= il); - eigen_assert(im <= iu-2); - - const Index size = m_matT.cols(); - - for (Index k = im; k <= iu-2; ++k) - { - bool firstIteration = (k == im); - - Vector3s v; - if (firstIteration) - v = firstHouseholderVector; - else - v = m_matT.template block<3,1>(k,k-1); - - Scalar tau, beta; - Matrix<Scalar, 2, 1> ess; - v.makeHouseholder(ess, tau, beta); - - if (beta != Scalar(0)) // if v is not zero - { - if (firstIteration && k > il) - m_matT.coeffRef(k,k-1) = -m_matT.coeff(k,k-1); - else if (!firstIteration) - m_matT.coeffRef(k,k-1) = beta; - - // These Householder transformations form the O(n^3) part of the algorithm - m_matT.block(k, k, 3, size-k).applyHouseholderOnTheLeft(ess, tau, workspace); - m_matT.block(0, k, (std::min)(iu,k+3) + 1, 3).applyHouseholderOnTheRight(ess, tau, workspace); - if (computeU) - m_matU.block(0, k, size, 3).applyHouseholderOnTheRight(ess, tau, workspace); - } - } - - Matrix<Scalar, 2, 1> v = m_matT.template block<2,1>(iu-1, iu-2); - Scalar tau, beta; - Matrix<Scalar, 1, 1> ess; - v.makeHouseholder(ess, tau, beta); - - if (beta != Scalar(0)) // if v is not zero - { - m_matT.coeffRef(iu-1, iu-2) = beta; - m_matT.block(iu-1, iu-1, 2, size-iu+1).applyHouseholderOnTheLeft(ess, tau, workspace); - m_matT.block(0, iu-1, iu+1, 2).applyHouseholderOnTheRight(ess, tau, workspace); - if (computeU) - m_matU.block(0, iu-1, size, 2).applyHouseholderOnTheRight(ess, tau, workspace); - } - - // clean up pollution due to round-off errors - for (Index i = im+2; i <= iu; ++i) - { - m_matT.coeffRef(i,i-2) = Scalar(0); - if (i > im+2) - m_matT.coeffRef(i,i-3) = Scalar(0); - } -} - -} // end namespace Eigen - -#endif // EIGEN_REAL_SCHUR_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h deleted file mode 100644 index 2c225171..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to LAPACKe - * Real Schur needed to real unsymmetrical eigenvalues/eigenvectors. - ******************************************************************************** -*/ - -#ifndef EIGEN_REAL_SCHUR_LAPACKE_H -#define EIGEN_REAL_SCHUR_LAPACKE_H - -namespace Eigen { - -/** \internal Specialization for the data types supported by LAPACKe */ - -#define EIGEN_LAPACKE_SCHUR_REAL(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, LAPACKE_PREFIX_U, EIGCOLROW, LAPACKE_COLROW) \ -template<> template<typename InputType> inline \ -RealSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >& \ -RealSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >::compute(const EigenBase<InputType>& matrix, bool computeU) \ -{ \ - eigen_assert(matrix.cols() == matrix.rows()); \ -\ - lapack_int n = internal::convert_index<lapack_int>(matrix.cols()), sdim, info; \ - lapack_int matrix_order = LAPACKE_COLROW; \ - char jobvs, sort='N'; \ - LAPACK_##LAPACKE_PREFIX_U##_SELECT2 select = 0; \ - jobvs = (computeU) ? 'V' : 'N'; \ - m_matU.resize(n, n); \ - lapack_int ldvs = internal::convert_index<lapack_int>(m_matU.outerStride()); \ - m_matT = matrix; \ - lapack_int lda = internal::convert_index<lapack_int>(m_matT.outerStride()); \ - Matrix<EIGTYPE, Dynamic, Dynamic> wr, wi; \ - wr.resize(n, 1); wi.resize(n, 1); \ - info = LAPACKE_##LAPACKE_PREFIX##gees( matrix_order, jobvs, sort, select, n, (LAPACKE_TYPE*)m_matT.data(), lda, &sdim, (LAPACKE_TYPE*)wr.data(), (LAPACKE_TYPE*)wi.data(), (LAPACKE_TYPE*)m_matU.data(), ldvs ); \ - if(info == 0) \ - m_info = Success; \ - else \ - m_info = NoConvergence; \ -\ - m_isInitialized = true; \ - m_matUisUptodate = computeU; \ - return *this; \ -\ -} - -EIGEN_LAPACKE_SCHUR_REAL(double, double, d, D, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_SCHUR_REAL(float, float, s, S, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_SCHUR_REAL(double, double, d, D, RowMajor, LAPACK_ROW_MAJOR) -EIGEN_LAPACKE_SCHUR_REAL(float, float, s, S, RowMajor, LAPACK_ROW_MAJOR) - -} // end namespace Eigen - -#endif // EIGEN_REAL_SCHUR_LAPACKE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h deleted file mode 100644 index 9bbce652..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +++ /dev/null @@ -1,879 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SELFADJOINTEIGENSOLVER_H -#define EIGEN_SELFADJOINTEIGENSOLVER_H - -#include "./Tridiagonalization.h" - -namespace Eigen { - -template<typename _MatrixType> -class GeneralizedSelfAdjointEigenSolver; - -namespace internal { -template<typename SolverType,int Size,bool IsComplex> struct direct_selfadjoint_eigenvalues; - -template<typename MatrixType, typename DiagType, typename SubDiagType> -EIGEN_DEVICE_FUNC -ComputationInfo computeFromTridiagonal_impl(DiagType& diag, SubDiagType& subdiag, const Index maxIterations, bool computeEigenvectors, MatrixType& eivec); -} - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class SelfAdjointEigenSolver - * - * \brief Computes eigenvalues and eigenvectors of selfadjoint matrices - * - * \tparam _MatrixType the type of the matrix of which we are computing the - * eigendecomposition; this is expected to be an instantiation of the Matrix - * class template. - * - * A matrix \f$ A \f$ is selfadjoint if it equals its adjoint. For real - * matrices, this means that the matrix is symmetric: it equals its - * transpose. This class computes the eigenvalues and eigenvectors of a - * selfadjoint matrix. These are the scalars \f$ \lambda \f$ and vectors - * \f$ v \f$ such that \f$ Av = \lambda v \f$. The eigenvalues of a - * selfadjoint matrix are always real. If \f$ D \f$ is a diagonal matrix with - * the eigenvalues on the diagonal, and \f$ V \f$ is a matrix with the - * eigenvectors as its columns, then \f$ A = V D V^{-1} \f$ (for selfadjoint - * matrices, the matrix \f$ V \f$ is always invertible). This is called the - * eigendecomposition. - * - * The algorithm exploits the fact that the matrix is selfadjoint, making it - * faster and more accurate than the general purpose eigenvalue algorithms - * implemented in EigenSolver and ComplexEigenSolver. - * - * Only the \b lower \b triangular \b part of the input matrix is referenced. - * - * Call the function compute() to compute the eigenvalues and eigenvectors of - * a given matrix. Alternatively, you can use the - * SelfAdjointEigenSolver(const MatrixType&, int) constructor which computes - * the eigenvalues and eigenvectors at construction time. Once the eigenvalue - * and eigenvectors are computed, they can be retrieved with the eigenvalues() - * and eigenvectors() functions. - * - * The documentation for SelfAdjointEigenSolver(const MatrixType&, int) - * contains an example of the typical use of this class. - * - * To solve the \em generalized eigenvalue problem \f$ Av = \lambda Bv \f$ and - * the likes, see the class GeneralizedSelfAdjointEigenSolver. - * - * \sa MatrixBase::eigenvalues(), class EigenSolver, class ComplexEigenSolver - */ -template<typename _MatrixType> class SelfAdjointEigenSolver -{ - public: - - typedef _MatrixType MatrixType; - enum { - Size = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - Options = MatrixType::Options, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - /** \brief Scalar type for matrices of type \p _MatrixType. */ - typedef typename MatrixType::Scalar Scalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - typedef Matrix<Scalar,Size,Size,ColMajor,MaxColsAtCompileTime,MaxColsAtCompileTime> EigenvectorsType; - - /** \brief Real scalar type for \p _MatrixType. - * - * This is just \c Scalar if #Scalar is real (e.g., \c float or - * \c double), and the type of the real part of \c Scalar if #Scalar is - * complex. - */ - typedef typename NumTraits<Scalar>::Real RealScalar; - - friend struct internal::direct_selfadjoint_eigenvalues<SelfAdjointEigenSolver,Size,NumTraits<Scalar>::IsComplex>; - - /** \brief Type for vector of eigenvalues as returned by eigenvalues(). - * - * This is a column vector with entries of type #RealScalar. - * The length of the vector is the size of \p _MatrixType. - */ - typedef typename internal::plain_col_type<MatrixType, RealScalar>::type RealVectorType; - typedef Tridiagonalization<MatrixType> TridiagonalizationType; - typedef typename TridiagonalizationType::SubDiagonalType SubDiagonalType; - - /** \brief Default constructor for fixed-size matrices. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via compute(). This constructor - * can only be used if \p _MatrixType is a fixed-size matrix; use - * SelfAdjointEigenSolver(Index) for dynamic-size matrices. - * - * Example: \include SelfAdjointEigenSolver_SelfAdjointEigenSolver.cpp - * Output: \verbinclude SelfAdjointEigenSolver_SelfAdjointEigenSolver.out - */ - EIGEN_DEVICE_FUNC - SelfAdjointEigenSolver() - : m_eivec(), - m_eivalues(), - m_subdiag(), - m_info(InvalidInput), - m_isInitialized(false), - m_eigenvectorsOk(false) - { } - - /** \brief Constructor, pre-allocates memory for dynamic-size matrices. - * - * \param [in] size Positive integer, size of the matrix whose - * eigenvalues and eigenvectors will be computed. - * - * This constructor is useful for dynamic-size matrices, when the user - * intends to perform decompositions via compute(). The \p size - * parameter is only used as a hint. It is not an error to give a wrong - * \p size, but it may impair performance. - * - * \sa compute() for an example - */ - EIGEN_DEVICE_FUNC - explicit SelfAdjointEigenSolver(Index size) - : m_eivec(size, size), - m_eivalues(size), - m_subdiag(size > 1 ? size - 1 : 1), - m_isInitialized(false), - m_eigenvectorsOk(false) - {} - - /** \brief Constructor; computes eigendecomposition of given matrix. - * - * \param[in] matrix Selfadjoint matrix whose eigendecomposition is to - * be computed. Only the lower triangular part of the matrix is referenced. - * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly. - * - * This constructor calls compute(const MatrixType&, int) to compute the - * eigenvalues of the matrix \p matrix. The eigenvectors are computed if - * \p options equals #ComputeEigenvectors. - * - * Example: \include SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType.cpp - * Output: \verbinclude SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType.out - * - * \sa compute(const MatrixType&, int) - */ - template<typename InputType> - EIGEN_DEVICE_FUNC - explicit SelfAdjointEigenSolver(const EigenBase<InputType>& matrix, int options = ComputeEigenvectors) - : m_eivec(matrix.rows(), matrix.cols()), - m_eivalues(matrix.cols()), - m_subdiag(matrix.rows() > 1 ? matrix.rows() - 1 : 1), - m_isInitialized(false), - m_eigenvectorsOk(false) - { - compute(matrix.derived(), options); - } - - /** \brief Computes eigendecomposition of given matrix. - * - * \param[in] matrix Selfadjoint matrix whose eigendecomposition is to - * be computed. Only the lower triangular part of the matrix is referenced. - * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly. - * \returns Reference to \c *this - * - * This function computes the eigenvalues of \p matrix. The eigenvalues() - * function can be used to retrieve them. If \p options equals #ComputeEigenvectors, - * then the eigenvectors are also computed and can be retrieved by - * calling eigenvectors(). - * - * This implementation uses a symmetric QR algorithm. The matrix is first - * reduced to tridiagonal form using the Tridiagonalization class. The - * tridiagonal matrix is then brought to diagonal form with implicit - * symmetric QR steps with Wilkinson shift. Details can be found in - * Section 8.3 of Golub \& Van Loan, <i>%Matrix Computations</i>. - * - * The cost of the computation is about \f$ 9n^3 \f$ if the eigenvectors - * are required and \f$ 4n^3/3 \f$ if they are not required. - * - * This method reuses the memory in the SelfAdjointEigenSolver object that - * was allocated when the object was constructed, if the size of the - * matrix does not change. - * - * Example: \include SelfAdjointEigenSolver_compute_MatrixType.cpp - * Output: \verbinclude SelfAdjointEigenSolver_compute_MatrixType.out - * - * \sa SelfAdjointEigenSolver(const MatrixType&, int) - */ - template<typename InputType> - EIGEN_DEVICE_FUNC - SelfAdjointEigenSolver& compute(const EigenBase<InputType>& matrix, int options = ComputeEigenvectors); - - /** \brief Computes eigendecomposition of given matrix using a closed-form algorithm - * - * This is a variant of compute(const MatrixType&, int options) which - * directly solves the underlying polynomial equation. - * - * Currently only 2x2 and 3x3 matrices for which the sizes are known at compile time are supported (e.g., Matrix3d). - * - * This method is usually significantly faster than the QR iterative algorithm - * but it might also be less accurate. It is also worth noting that - * for 3x3 matrices it involves trigonometric operations which are - * not necessarily available for all scalar types. - * - * For the 3x3 case, we observed the following worst case relative error regarding the eigenvalues: - * - double: 1e-8 - * - float: 1e-3 - * - * \sa compute(const MatrixType&, int options) - */ - EIGEN_DEVICE_FUNC - SelfAdjointEigenSolver& computeDirect(const MatrixType& matrix, int options = ComputeEigenvectors); - - /** - *\brief Computes the eigen decomposition from a tridiagonal symmetric matrix - * - * \param[in] diag The vector containing the diagonal of the matrix. - * \param[in] subdiag The subdiagonal of the matrix. - * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly. - * \returns Reference to \c *this - * - * This function assumes that the matrix has been reduced to tridiagonal form. - * - * \sa compute(const MatrixType&, int) for more information - */ - SelfAdjointEigenSolver& computeFromTridiagonal(const RealVectorType& diag, const SubDiagonalType& subdiag , int options=ComputeEigenvectors); - - /** \brief Returns the eigenvectors of given matrix. - * - * \returns A const reference to the matrix whose columns are the eigenvectors. - * - * \pre The eigenvectors have been computed before. - * - * Column \f$ k \f$ of the returned matrix is an eigenvector corresponding - * to eigenvalue number \f$ k \f$ as returned by eigenvalues(). The - * eigenvectors are normalized to have (Euclidean) norm equal to one. If - * this object was used to solve the eigenproblem for the selfadjoint - * matrix \f$ A \f$, then the matrix returned by this function is the - * matrix \f$ V \f$ in the eigendecomposition \f$ A = V D V^{-1} \f$. - * - * Example: \include SelfAdjointEigenSolver_eigenvectors.cpp - * Output: \verbinclude SelfAdjointEigenSolver_eigenvectors.out - * - * \sa eigenvalues() - */ - EIGEN_DEVICE_FUNC - const EigenvectorsType& eigenvectors() const - { - eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - return m_eivec; - } - - /** \brief Returns the eigenvalues of given matrix. - * - * \returns A const reference to the column vector containing the eigenvalues. - * - * \pre The eigenvalues have been computed before. - * - * The eigenvalues are repeated according to their algebraic multiplicity, - * so there are as many eigenvalues as rows in the matrix. The eigenvalues - * are sorted in increasing order. - * - * Example: \include SelfAdjointEigenSolver_eigenvalues.cpp - * Output: \verbinclude SelfAdjointEigenSolver_eigenvalues.out - * - * \sa eigenvectors(), MatrixBase::eigenvalues() - */ - EIGEN_DEVICE_FUNC - const RealVectorType& eigenvalues() const - { - eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized."); - return m_eivalues; - } - - /** \brief Computes the positive-definite square root of the matrix. - * - * \returns the positive-definite square root of the matrix - * - * \pre The eigenvalues and eigenvectors of a positive-definite matrix - * have been computed before. - * - * The square root of a positive-definite matrix \f$ A \f$ is the - * positive-definite matrix whose square equals \f$ A \f$. This function - * uses the eigendecomposition \f$ A = V D V^{-1} \f$ to compute the - * square root as \f$ A^{1/2} = V D^{1/2} V^{-1} \f$. - * - * Example: \include SelfAdjointEigenSolver_operatorSqrt.cpp - * Output: \verbinclude SelfAdjointEigenSolver_operatorSqrt.out - * - * \sa operatorInverseSqrt(), <a href="unsupported/group__MatrixFunctions__Module.html">MatrixFunctions Module</a> - */ - EIGEN_DEVICE_FUNC - MatrixType operatorSqrt() const - { - eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - return m_eivec * m_eivalues.cwiseSqrt().asDiagonal() * m_eivec.adjoint(); - } - - /** \brief Computes the inverse square root of the matrix. - * - * \returns the inverse positive-definite square root of the matrix - * - * \pre The eigenvalues and eigenvectors of a positive-definite matrix - * have been computed before. - * - * This function uses the eigendecomposition \f$ A = V D V^{-1} \f$ to - * compute the inverse square root as \f$ V D^{-1/2} V^{-1} \f$. This is - * cheaper than first computing the square root with operatorSqrt() and - * then its inverse with MatrixBase::inverse(). - * - * Example: \include SelfAdjointEigenSolver_operatorInverseSqrt.cpp - * Output: \verbinclude SelfAdjointEigenSolver_operatorInverseSqrt.out - * - * \sa operatorSqrt(), MatrixBase::inverse(), <a href="unsupported/group__MatrixFunctions__Module.html">MatrixFunctions Module</a> - */ - EIGEN_DEVICE_FUNC - MatrixType operatorInverseSqrt() const - { - eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - return m_eivec * m_eivalues.cwiseInverse().cwiseSqrt().asDiagonal() * m_eivec.adjoint(); - } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, \c NoConvergence otherwise. - */ - EIGEN_DEVICE_FUNC - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized."); - return m_info; - } - - /** \brief Maximum number of iterations. - * - * The algorithm terminates if it does not converge within m_maxIterations * n iterations, where n - * denotes the size of the matrix. This value is currently set to 30 (copied from LAPACK). - */ - static const int m_maxIterations = 30; - - protected: - static EIGEN_DEVICE_FUNC - void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - EigenvectorsType m_eivec; - RealVectorType m_eivalues; - typename TridiagonalizationType::SubDiagonalType m_subdiag; - ComputationInfo m_info; - bool m_isInitialized; - bool m_eigenvectorsOk; -}; - -namespace internal { -/** \internal - * - * \eigenvalues_module \ingroup Eigenvalues_Module - * - * Performs a QR step on a tridiagonal symmetric matrix represented as a - * pair of two vectors \a diag and \a subdiag. - * - * \param diag the diagonal part of the input selfadjoint tridiagonal matrix - * \param subdiag the sub-diagonal part of the input selfadjoint tridiagonal matrix - * \param start starting index of the submatrix to work on - * \param end last+1 index of the submatrix to work on - * \param matrixQ pointer to the column-major matrix holding the eigenvectors, can be 0 - * \param n size of the input matrix - * - * For compilation efficiency reasons, this procedure does not use eigen expression - * for its arguments. - * - * Implemented from Golub's "Matrix Computations", algorithm 8.3.2: - * "implicit symmetric QR step with Wilkinson shift" - */ -template<int StorageOrder,typename RealScalar, typename Scalar, typename Index> -EIGEN_DEVICE_FUNC -static void tridiagonal_qr_step(RealScalar* diag, RealScalar* subdiag, Index start, Index end, Scalar* matrixQ, Index n); -} - -template<typename MatrixType> -template<typename InputType> -EIGEN_DEVICE_FUNC -SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType> -::compute(const EigenBase<InputType>& a_matrix, int options) -{ - check_template_parameters(); - - const InputType &matrix(a_matrix.derived()); - - EIGEN_USING_STD_MATH(abs); - eigen_assert(matrix.cols() == matrix.rows()); - eigen_assert((options&~(EigVecMask|GenEigMask))==0 - && (options&EigVecMask)!=EigVecMask - && "invalid option parameter"); - bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors; - Index n = matrix.cols(); - m_eivalues.resize(n,1); - - if(n==1) - { - m_eivec = matrix; - m_eivalues.coeffRef(0,0) = numext::real(m_eivec.coeff(0,0)); - if(computeEigenvectors) - m_eivec.setOnes(n,n); - m_info = Success; - m_isInitialized = true; - m_eigenvectorsOk = computeEigenvectors; - return *this; - } - - // declare some aliases - RealVectorType& diag = m_eivalues; - EigenvectorsType& mat = m_eivec; - - // map the matrix coefficients to [-1:1] to avoid over- and underflow. - mat = matrix.template triangularView<Lower>(); - RealScalar scale = mat.cwiseAbs().maxCoeff(); - if(scale==RealScalar(0)) scale = RealScalar(1); - mat.template triangularView<Lower>() /= scale; - m_subdiag.resize(n-1); - internal::tridiagonalization_inplace(mat, diag, m_subdiag, computeEigenvectors); - - m_info = internal::computeFromTridiagonal_impl(diag, m_subdiag, m_maxIterations, computeEigenvectors, m_eivec); - - // scale back the eigen values - m_eivalues *= scale; - - m_isInitialized = true; - m_eigenvectorsOk = computeEigenvectors; - return *this; -} - -template<typename MatrixType> -SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType> -::computeFromTridiagonal(const RealVectorType& diag, const SubDiagonalType& subdiag , int options) -{ - //TODO : Add an option to scale the values beforehand - bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors; - - m_eivalues = diag; - m_subdiag = subdiag; - if (computeEigenvectors) - { - m_eivec.setIdentity(diag.size(), diag.size()); - } - m_info = internal::computeFromTridiagonal_impl(m_eivalues, m_subdiag, m_maxIterations, computeEigenvectors, m_eivec); - - m_isInitialized = true; - m_eigenvectorsOk = computeEigenvectors; - return *this; -} - -namespace internal { -/** - * \internal - * \brief Compute the eigendecomposition from a tridiagonal matrix - * - * \param[in,out] diag : On input, the diagonal of the matrix, on output the eigenvalues - * \param[in,out] subdiag : The subdiagonal part of the matrix (entries are modified during the decomposition) - * \param[in] maxIterations : the maximum number of iterations - * \param[in] computeEigenvectors : whether the eigenvectors have to be computed or not - * \param[out] eivec : The matrix to store the eigenvectors if computeEigenvectors==true. Must be allocated on input. - * \returns \c Success or \c NoConvergence - */ -template<typename MatrixType, typename DiagType, typename SubDiagType> -EIGEN_DEVICE_FUNC -ComputationInfo computeFromTridiagonal_impl(DiagType& diag, SubDiagType& subdiag, const Index maxIterations, bool computeEigenvectors, MatrixType& eivec) -{ - EIGEN_USING_STD_MATH(abs); - - ComputationInfo info; - typedef typename MatrixType::Scalar Scalar; - - Index n = diag.size(); - Index end = n-1; - Index start = 0; - Index iter = 0; // total number of iterations - - typedef typename DiagType::RealScalar RealScalar; - const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)(); - const RealScalar precision = RealScalar(2)*NumTraits<RealScalar>::epsilon(); - - while (end>0) - { - for (Index i = start; i<end; ++i) - if (internal::isMuchSmallerThan(abs(subdiag[i]),(abs(diag[i])+abs(diag[i+1])),precision) || abs(subdiag[i]) <= considerAsZero) - subdiag[i] = 0; - - // find the largest unreduced block - while (end>0 && subdiag[end-1]==RealScalar(0)) - { - end--; - } - if (end<=0) - break; - - // if we spent too many iterations, we give up - iter++; - if(iter > maxIterations * n) break; - - start = end - 1; - while (start>0 && subdiag[start-1]!=0) - start--; - - internal::tridiagonal_qr_step<MatrixType::Flags&RowMajorBit ? RowMajor : ColMajor>(diag.data(), subdiag.data(), start, end, computeEigenvectors ? eivec.data() : (Scalar*)0, n); - } - if (iter <= maxIterations * n) - info = Success; - else - info = NoConvergence; - - // Sort eigenvalues and corresponding vectors. - // TODO make the sort optional ? - // TODO use a better sort algorithm !! - if (info == Success) - { - for (Index i = 0; i < n-1; ++i) - { - Index k; - diag.segment(i,n-i).minCoeff(&k); - if (k > 0) - { - numext::swap(diag[i], diag[k+i]); - if(computeEigenvectors) - eivec.col(i).swap(eivec.col(k+i)); - } - } - } - return info; -} - -template<typename SolverType,int Size,bool IsComplex> struct direct_selfadjoint_eigenvalues -{ - EIGEN_DEVICE_FUNC - static inline void run(SolverType& eig, const typename SolverType::MatrixType& A, int options) - { eig.compute(A,options); } -}; - -template<typename SolverType> struct direct_selfadjoint_eigenvalues<SolverType,3,false> -{ - typedef typename SolverType::MatrixType MatrixType; - typedef typename SolverType::RealVectorType VectorType; - typedef typename SolverType::Scalar Scalar; - typedef typename SolverType::EigenvectorsType EigenvectorsType; - - - /** \internal - * Computes the roots of the characteristic polynomial of \a m. - * For numerical stability m.trace() should be near zero and to avoid over- or underflow m should be normalized. - */ - EIGEN_DEVICE_FUNC - static inline void computeRoots(const MatrixType& m, VectorType& roots) - { - EIGEN_USING_STD_MATH(sqrt) - EIGEN_USING_STD_MATH(atan2) - EIGEN_USING_STD_MATH(cos) - EIGEN_USING_STD_MATH(sin) - const Scalar s_inv3 = Scalar(1)/Scalar(3); - const Scalar s_sqrt3 = sqrt(Scalar(3)); - - // The characteristic equation is x^3 - c2*x^2 + c1*x - c0 = 0. The - // eigenvalues are the roots to this equation, all guaranteed to be - // real-valued, because the matrix is symmetric. - Scalar c0 = m(0,0)*m(1,1)*m(2,2) + Scalar(2)*m(1,0)*m(2,0)*m(2,1) - m(0,0)*m(2,1)*m(2,1) - m(1,1)*m(2,0)*m(2,0) - m(2,2)*m(1,0)*m(1,0); - Scalar c1 = m(0,0)*m(1,1) - m(1,0)*m(1,0) + m(0,0)*m(2,2) - m(2,0)*m(2,0) + m(1,1)*m(2,2) - m(2,1)*m(2,1); - Scalar c2 = m(0,0) + m(1,1) + m(2,2); - - // Construct the parameters used in classifying the roots of the equation - // and in solving the equation for the roots in closed form. - Scalar c2_over_3 = c2*s_inv3; - Scalar a_over_3 = (c2*c2_over_3 - c1)*s_inv3; - a_over_3 = numext::maxi(a_over_3, Scalar(0)); - - Scalar half_b = Scalar(0.5)*(c0 + c2_over_3*(Scalar(2)*c2_over_3*c2_over_3 - c1)); - - Scalar q = a_over_3*a_over_3*a_over_3 - half_b*half_b; - q = numext::maxi(q, Scalar(0)); - - // Compute the eigenvalues by solving for the roots of the polynomial. - Scalar rho = sqrt(a_over_3); - Scalar theta = atan2(sqrt(q),half_b)*s_inv3; // since sqrt(q) > 0, atan2 is in [0, pi] and theta is in [0, pi/3] - Scalar cos_theta = cos(theta); - Scalar sin_theta = sin(theta); - // roots are already sorted, since cos is monotonically decreasing on [0, pi] - roots(0) = c2_over_3 - rho*(cos_theta + s_sqrt3*sin_theta); // == 2*rho*cos(theta+2pi/3) - roots(1) = c2_over_3 - rho*(cos_theta - s_sqrt3*sin_theta); // == 2*rho*cos(theta+ pi/3) - roots(2) = c2_over_3 + Scalar(2)*rho*cos_theta; - } - - EIGEN_DEVICE_FUNC - static inline bool extract_kernel(MatrixType& mat, Ref<VectorType> res, Ref<VectorType> representative) - { - EIGEN_USING_STD_MATH(abs); - EIGEN_USING_STD_MATH(sqrt); - Index i0; - // Find non-zero column i0 (by construction, there must exist a non zero coefficient on the diagonal): - mat.diagonal().cwiseAbs().maxCoeff(&i0); - // mat.col(i0) is a good candidate for an orthogonal vector to the current eigenvector, - // so let's save it: - representative = mat.col(i0); - Scalar n0, n1; - VectorType c0, c1; - n0 = (c0 = representative.cross(mat.col((i0+1)%3))).squaredNorm(); - n1 = (c1 = representative.cross(mat.col((i0+2)%3))).squaredNorm(); - if(n0>n1) res = c0/sqrt(n0); - else res = c1/sqrt(n1); - - return true; - } - - EIGEN_DEVICE_FUNC - static inline void run(SolverType& solver, const MatrixType& mat, int options) - { - eigen_assert(mat.cols() == 3 && mat.cols() == mat.rows()); - eigen_assert((options&~(EigVecMask|GenEigMask))==0 - && (options&EigVecMask)!=EigVecMask - && "invalid option parameter"); - bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors; - - EigenvectorsType& eivecs = solver.m_eivec; - VectorType& eivals = solver.m_eivalues; - - // Shift the matrix to the mean eigenvalue and map the matrix coefficients to [-1:1] to avoid over- and underflow. - Scalar shift = mat.trace() / Scalar(3); - // TODO Avoid this copy. Currently it is necessary to suppress bogus values when determining maxCoeff and for computing the eigenvectors later - MatrixType scaledMat = mat.template selfadjointView<Lower>(); - scaledMat.diagonal().array() -= shift; - Scalar scale = scaledMat.cwiseAbs().maxCoeff(); - if(scale > 0) scaledMat /= scale; // TODO for scale==0 we could save the remaining operations - - // compute the eigenvalues - computeRoots(scaledMat,eivals); - - // compute the eigenvectors - if(computeEigenvectors) - { - if((eivals(2)-eivals(0))<=Eigen::NumTraits<Scalar>::epsilon()) - { - // All three eigenvalues are numerically the same - eivecs.setIdentity(); - } - else - { - MatrixType tmp; - tmp = scaledMat; - - // Compute the eigenvector of the most distinct eigenvalue - Scalar d0 = eivals(2) - eivals(1); - Scalar d1 = eivals(1) - eivals(0); - Index k(0), l(2); - if(d0 > d1) - { - numext::swap(k,l); - d0 = d1; - } - - // Compute the eigenvector of index k - { - tmp.diagonal().array () -= eivals(k); - // By construction, 'tmp' is of rank 2, and its kernel corresponds to the respective eigenvector. - extract_kernel(tmp, eivecs.col(k), eivecs.col(l)); - } - - // Compute eigenvector of index l - if(d0<=2*Eigen::NumTraits<Scalar>::epsilon()*d1) - { - // If d0 is too small, then the two other eigenvalues are numerically the same, - // and thus we only have to ortho-normalize the near orthogonal vector we saved above. - eivecs.col(l) -= eivecs.col(k).dot(eivecs.col(l))*eivecs.col(l); - eivecs.col(l).normalize(); - } - else - { - tmp = scaledMat; - tmp.diagonal().array () -= eivals(l); - - VectorType dummy; - extract_kernel(tmp, eivecs.col(l), dummy); - } - - // Compute last eigenvector from the other two - eivecs.col(1) = eivecs.col(2).cross(eivecs.col(0)).normalized(); - } - } - - // Rescale back to the original size. - eivals *= scale; - eivals.array() += shift; - - solver.m_info = Success; - solver.m_isInitialized = true; - solver.m_eigenvectorsOk = computeEigenvectors; - } -}; - -// 2x2 direct eigenvalues decomposition, code from Hauke Heibel -template<typename SolverType> -struct direct_selfadjoint_eigenvalues<SolverType,2,false> -{ - typedef typename SolverType::MatrixType MatrixType; - typedef typename SolverType::RealVectorType VectorType; - typedef typename SolverType::Scalar Scalar; - typedef typename SolverType::EigenvectorsType EigenvectorsType; - - EIGEN_DEVICE_FUNC - static inline void computeRoots(const MatrixType& m, VectorType& roots) - { - EIGEN_USING_STD_MATH(sqrt); - const Scalar t0 = Scalar(0.5) * sqrt( numext::abs2(m(0,0)-m(1,1)) + Scalar(4)*numext::abs2(m(1,0))); - const Scalar t1 = Scalar(0.5) * (m(0,0) + m(1,1)); - roots(0) = t1 - t0; - roots(1) = t1 + t0; - } - - EIGEN_DEVICE_FUNC - static inline void run(SolverType& solver, const MatrixType& mat, int options) - { - EIGEN_USING_STD_MATH(sqrt); - EIGEN_USING_STD_MATH(abs); - - eigen_assert(mat.cols() == 2 && mat.cols() == mat.rows()); - eigen_assert((options&~(EigVecMask|GenEigMask))==0 - && (options&EigVecMask)!=EigVecMask - && "invalid option parameter"); - bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors; - - EigenvectorsType& eivecs = solver.m_eivec; - VectorType& eivals = solver.m_eivalues; - - // Shift the matrix to the mean eigenvalue and map the matrix coefficients to [-1:1] to avoid over- and underflow. - Scalar shift = mat.trace() / Scalar(2); - MatrixType scaledMat = mat; - scaledMat.coeffRef(0,1) = mat.coeff(1,0); - scaledMat.diagonal().array() -= shift; - Scalar scale = scaledMat.cwiseAbs().maxCoeff(); - if(scale > Scalar(0)) - scaledMat /= scale; - - // Compute the eigenvalues - computeRoots(scaledMat,eivals); - - // compute the eigen vectors - if(computeEigenvectors) - { - if((eivals(1)-eivals(0))<=abs(eivals(1))*Eigen::NumTraits<Scalar>::epsilon()) - { - eivecs.setIdentity(); - } - else - { - scaledMat.diagonal().array () -= eivals(1); - Scalar a2 = numext::abs2(scaledMat(0,0)); - Scalar c2 = numext::abs2(scaledMat(1,1)); - Scalar b2 = numext::abs2(scaledMat(1,0)); - if(a2>c2) - { - eivecs.col(1) << -scaledMat(1,0), scaledMat(0,0); - eivecs.col(1) /= sqrt(a2+b2); - } - else - { - eivecs.col(1) << -scaledMat(1,1), scaledMat(1,0); - eivecs.col(1) /= sqrt(c2+b2); - } - - eivecs.col(0) << eivecs.col(1).unitOrthogonal(); - } - } - - // Rescale back to the original size. - eivals *= scale; - eivals.array() += shift; - - solver.m_info = Success; - solver.m_isInitialized = true; - solver.m_eigenvectorsOk = computeEigenvectors; - } -}; - -} - -template<typename MatrixType> -EIGEN_DEVICE_FUNC -SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType> -::computeDirect(const MatrixType& matrix, int options) -{ - internal::direct_selfadjoint_eigenvalues<SelfAdjointEigenSolver,Size,NumTraits<Scalar>::IsComplex>::run(*this,matrix,options); - return *this; -} - -namespace internal { -template<int StorageOrder,typename RealScalar, typename Scalar, typename Index> -EIGEN_DEVICE_FUNC -static void tridiagonal_qr_step(RealScalar* diag, RealScalar* subdiag, Index start, Index end, Scalar* matrixQ, Index n) -{ - EIGEN_USING_STD_MATH(abs); - RealScalar td = (diag[end-1] - diag[end])*RealScalar(0.5); - RealScalar e = subdiag[end-1]; - // Note that thanks to scaling, e^2 or td^2 cannot overflow, however they can still - // underflow thus leading to inf/NaN values when using the following commented code: -// RealScalar e2 = numext::abs2(subdiag[end-1]); -// RealScalar mu = diag[end] - e2 / (td + (td>0 ? 1 : -1) * sqrt(td*td + e2)); - // This explain the following, somewhat more complicated, version: - RealScalar mu = diag[end]; - if(td==RealScalar(0)) - mu -= abs(e); - else - { - RealScalar e2 = numext::abs2(subdiag[end-1]); - RealScalar h = numext::hypot(td,e); - if(e2==RealScalar(0)) mu -= (e / (td + (td>RealScalar(0) ? RealScalar(1) : RealScalar(-1)))) * (e / h); - else mu -= e2 / (td + (td>RealScalar(0) ? h : -h)); - } - - RealScalar x = diag[start] - mu; - RealScalar z = subdiag[start]; - for (Index k = start; k < end; ++k) - { - JacobiRotation<RealScalar> rot; - rot.makeGivens(x, z); - - // do T = G' T G - RealScalar sdk = rot.s() * diag[k] + rot.c() * subdiag[k]; - RealScalar dkp1 = rot.s() * subdiag[k] + rot.c() * diag[k+1]; - - diag[k] = rot.c() * (rot.c() * diag[k] - rot.s() * subdiag[k]) - rot.s() * (rot.c() * subdiag[k] - rot.s() * diag[k+1]); - diag[k+1] = rot.s() * sdk + rot.c() * dkp1; - subdiag[k] = rot.c() * sdk - rot.s() * dkp1; - - - if (k > start) - subdiag[k - 1] = rot.c() * subdiag[k-1] - rot.s() * z; - - x = subdiag[k]; - - if (k < end - 1) - { - z = -rot.s() * subdiag[k+1]; - subdiag[k + 1] = rot.c() * subdiag[k+1]; - } - - // apply the givens rotation to the unit matrix Q = Q * G - if (matrixQ) - { - // FIXME if StorageOrder == RowMajor this operation is not very efficient - Map<Matrix<Scalar,Dynamic,Dynamic,StorageOrder> > q(matrixQ,n,n); - q.applyOnTheRight(k,k+1,rot); - } - } -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SELFADJOINTEIGENSOLVER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h deleted file mode 100644 index b0c947dc..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to LAPACKe - * Self-adjoint eigenvalues/eigenvectors. - ******************************************************************************** -*/ - -#ifndef EIGEN_SAEIGENSOLVER_LAPACKE_H -#define EIGEN_SAEIGENSOLVER_LAPACKE_H - -namespace Eigen { - -/** \internal Specialization for the data types supported by LAPACKe */ - -#define EIGEN_LAPACKE_EIG_SELFADJ_2(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_NAME, EIGCOLROW ) \ -template<> template<typename InputType> inline \ -SelfAdjointEigenSolver<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >& \ -SelfAdjointEigenSolver<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >::compute(const EigenBase<InputType>& matrix, int options) \ -{ \ - eigen_assert(matrix.cols() == matrix.rows()); \ - eigen_assert((options&~(EigVecMask|GenEigMask))==0 \ - && (options&EigVecMask)!=EigVecMask \ - && "invalid option parameter"); \ - bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors; \ - lapack_int n = internal::convert_index<lapack_int>(matrix.cols()), lda, info; \ - m_eivalues.resize(n,1); \ - m_subdiag.resize(n-1); \ - m_eivec = matrix; \ -\ - if(n==1) \ - { \ - m_eivalues.coeffRef(0,0) = numext::real(m_eivec.coeff(0,0)); \ - if(computeEigenvectors) m_eivec.setOnes(n,n); \ - m_info = Success; \ - m_isInitialized = true; \ - m_eigenvectorsOk = computeEigenvectors; \ - return *this; \ - } \ -\ - lda = internal::convert_index<lapack_int>(m_eivec.outerStride()); \ - char jobz, uplo='L'/*, range='A'*/; \ - jobz = computeEigenvectors ? 'V' : 'N'; \ -\ - info = LAPACKE_##LAPACKE_NAME( LAPACK_COL_MAJOR, jobz, uplo, n, (LAPACKE_TYPE*)m_eivec.data(), lda, (LAPACKE_RTYPE*)m_eivalues.data() ); \ - m_info = (info==0) ? Success : NoConvergence; \ - m_isInitialized = true; \ - m_eigenvectorsOk = computeEigenvectors; \ - return *this; \ -} - -#define EIGEN_LAPACKE_EIG_SELFADJ(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_NAME ) \ - EIGEN_LAPACKE_EIG_SELFADJ_2(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_NAME, ColMajor ) \ - EIGEN_LAPACKE_EIG_SELFADJ_2(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_NAME, RowMajor ) - -EIGEN_LAPACKE_EIG_SELFADJ(double, double, double, dsyev) -EIGEN_LAPACKE_EIG_SELFADJ(float, float, float, ssyev) -EIGEN_LAPACKE_EIG_SELFADJ(dcomplex, lapack_complex_double, double, zheev) -EIGEN_LAPACKE_EIG_SELFADJ(scomplex, lapack_complex_float, float, cheev) - -} // end namespace Eigen - -#endif // EIGEN_SAEIGENSOLVER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/Tridiagonalization.h b/external/eigen/include/eigen3/Eigen/src/Eigenvalues/Tridiagonalization.h deleted file mode 100644 index c5c1acf4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Eigenvalues/Tridiagonalization.h +++ /dev/null @@ -1,561 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRIDIAGONALIZATION_H -#define EIGEN_TRIDIAGONALIZATION_H - -namespace Eigen { - -namespace internal { - -template<typename MatrixType> struct TridiagonalizationMatrixTReturnType; -template<typename MatrixType> -struct traits<TridiagonalizationMatrixTReturnType<MatrixType> > - : public traits<typename MatrixType::PlainObject> -{ - typedef typename MatrixType::PlainObject ReturnType; // FIXME shall it be a BandMatrix? - enum { Flags = 0 }; -}; - -template<typename MatrixType, typename CoeffVectorType> -EIGEN_DEVICE_FUNC -void tridiagonalization_inplace(MatrixType& matA, CoeffVectorType& hCoeffs); -} - -/** \eigenvalues_module \ingroup Eigenvalues_Module - * - * - * \class Tridiagonalization - * - * \brief Tridiagonal decomposition of a selfadjoint matrix - * - * \tparam _MatrixType the type of the matrix of which we are computing the - * tridiagonal decomposition; this is expected to be an instantiation of the - * Matrix class template. - * - * This class performs a tridiagonal decomposition of a selfadjoint matrix \f$ A \f$ such that: - * \f$ A = Q T Q^* \f$ where \f$ Q \f$ is unitary and \f$ T \f$ a real symmetric tridiagonal matrix. - * - * A tridiagonal matrix is a matrix which has nonzero elements only on the - * main diagonal and the first diagonal below and above it. The Hessenberg - * decomposition of a selfadjoint matrix is in fact a tridiagonal - * decomposition. This class is used in SelfAdjointEigenSolver to compute the - * eigenvalues and eigenvectors of a selfadjoint matrix. - * - * Call the function compute() to compute the tridiagonal decomposition of a - * given matrix. Alternatively, you can use the Tridiagonalization(const MatrixType&) - * constructor which computes the tridiagonal Schur decomposition at - * construction time. Once the decomposition is computed, you can use the - * matrixQ() and matrixT() functions to retrieve the matrices Q and T in the - * decomposition. - * - * The documentation of Tridiagonalization(const MatrixType&) contains an - * example of the typical use of this class. - * - * \sa class HessenbergDecomposition, class SelfAdjointEigenSolver - */ -template<typename _MatrixType> class Tridiagonalization -{ - public: - - /** \brief Synonym for the template parameter \p _MatrixType. */ - typedef _MatrixType MatrixType; - - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - - enum { - Size = MatrixType::RowsAtCompileTime, - SizeMinusOne = Size == Dynamic ? Dynamic : (Size > 1 ? Size - 1 : 1), - Options = MatrixType::Options, - MaxSize = MatrixType::MaxRowsAtCompileTime, - MaxSizeMinusOne = MaxSize == Dynamic ? Dynamic : (MaxSize > 1 ? MaxSize - 1 : 1) - }; - - typedef Matrix<Scalar, SizeMinusOne, 1, Options & ~RowMajor, MaxSizeMinusOne, 1> CoeffVectorType; - typedef typename internal::plain_col_type<MatrixType, RealScalar>::type DiagonalType; - typedef Matrix<RealScalar, SizeMinusOne, 1, Options & ~RowMajor, MaxSizeMinusOne, 1> SubDiagonalType; - typedef typename internal::remove_all<typename MatrixType::RealReturnType>::type MatrixTypeRealView; - typedef internal::TridiagonalizationMatrixTReturnType<MatrixTypeRealView> MatrixTReturnType; - - typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - typename internal::add_const_on_value_type<typename Diagonal<const MatrixType>::RealReturnType>::type, - const Diagonal<const MatrixType> - >::type DiagonalReturnType; - - typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - typename internal::add_const_on_value_type<typename Diagonal<const MatrixType, -1>::RealReturnType>::type, - const Diagonal<const MatrixType, -1> - >::type SubDiagonalReturnType; - - /** \brief Return type of matrixQ() */ - typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename CoeffVectorType::ConjugateReturnType>::type> HouseholderSequenceType; - - /** \brief Default constructor. - * - * \param [in] size Positive integer, size of the matrix whose tridiagonal - * decomposition will be computed. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via compute(). The \p size parameter is only - * used as a hint. It is not an error to give a wrong \p size, but it may - * impair performance. - * - * \sa compute() for an example. - */ - explicit Tridiagonalization(Index size = Size==Dynamic ? 2 : Size) - : m_matrix(size,size), - m_hCoeffs(size > 1 ? size-1 : 1), - m_isInitialized(false) - {} - - /** \brief Constructor; computes tridiagonal decomposition of given matrix. - * - * \param[in] matrix Selfadjoint matrix whose tridiagonal decomposition - * is to be computed. - * - * This constructor calls compute() to compute the tridiagonal decomposition. - * - * Example: \include Tridiagonalization_Tridiagonalization_MatrixType.cpp - * Output: \verbinclude Tridiagonalization_Tridiagonalization_MatrixType.out - */ - template<typename InputType> - explicit Tridiagonalization(const EigenBase<InputType>& matrix) - : m_matrix(matrix.derived()), - m_hCoeffs(matrix.cols() > 1 ? matrix.cols()-1 : 1), - m_isInitialized(false) - { - internal::tridiagonalization_inplace(m_matrix, m_hCoeffs); - m_isInitialized = true; - } - - /** \brief Computes tridiagonal decomposition of given matrix. - * - * \param[in] matrix Selfadjoint matrix whose tridiagonal decomposition - * is to be computed. - * \returns Reference to \c *this - * - * The tridiagonal decomposition is computed by bringing the columns of - * the matrix successively in the required form using Householder - * reflections. The cost is \f$ 4n^3/3 \f$ flops, where \f$ n \f$ denotes - * the size of the given matrix. - * - * This method reuses of the allocated data in the Tridiagonalization - * object, if the size of the matrix does not change. - * - * Example: \include Tridiagonalization_compute.cpp - * Output: \verbinclude Tridiagonalization_compute.out - */ - template<typename InputType> - Tridiagonalization& compute(const EigenBase<InputType>& matrix) - { - m_matrix = matrix.derived(); - m_hCoeffs.resize(matrix.rows()-1, 1); - internal::tridiagonalization_inplace(m_matrix, m_hCoeffs); - m_isInitialized = true; - return *this; - } - - /** \brief Returns the Householder coefficients. - * - * \returns a const reference to the vector of Householder coefficients - * - * \pre Either the constructor Tridiagonalization(const MatrixType&) or - * the member function compute(const MatrixType&) has been called before - * to compute the tridiagonal decomposition of a matrix. - * - * The Householder coefficients allow the reconstruction of the matrix - * \f$ Q \f$ in the tridiagonal decomposition from the packed data. - * - * Example: \include Tridiagonalization_householderCoefficients.cpp - * Output: \verbinclude Tridiagonalization_householderCoefficients.out - * - * \sa packedMatrix(), \ref Householder_Module "Householder module" - */ - inline CoeffVectorType householderCoefficients() const - { - eigen_assert(m_isInitialized && "Tridiagonalization is not initialized."); - return m_hCoeffs; - } - - /** \brief Returns the internal representation of the decomposition - * - * \returns a const reference to a matrix with the internal representation - * of the decomposition. - * - * \pre Either the constructor Tridiagonalization(const MatrixType&) or - * the member function compute(const MatrixType&) has been called before - * to compute the tridiagonal decomposition of a matrix. - * - * The returned matrix contains the following information: - * - the strict upper triangular part is equal to the input matrix A. - * - the diagonal and lower sub-diagonal represent the real tridiagonal - * symmetric matrix T. - * - the rest of the lower part contains the Householder vectors that, - * combined with Householder coefficients returned by - * householderCoefficients(), allows to reconstruct the matrix Q as - * \f$ Q = H_{N-1} \ldots H_1 H_0 \f$. - * Here, the matrices \f$ H_i \f$ are the Householder transformations - * \f$ H_i = (I - h_i v_i v_i^T) \f$ - * where \f$ h_i \f$ is the \f$ i \f$th Householder coefficient and - * \f$ v_i \f$ is the Householder vector defined by - * \f$ v_i = [ 0, \ldots, 0, 1, M(i+2,i), \ldots, M(N-1,i) ]^T \f$ - * with M the matrix returned by this function. - * - * See LAPACK for further details on this packed storage. - * - * Example: \include Tridiagonalization_packedMatrix.cpp - * Output: \verbinclude Tridiagonalization_packedMatrix.out - * - * \sa householderCoefficients() - */ - inline const MatrixType& packedMatrix() const - { - eigen_assert(m_isInitialized && "Tridiagonalization is not initialized."); - return m_matrix; - } - - /** \brief Returns the unitary matrix Q in the decomposition - * - * \returns object representing the matrix Q - * - * \pre Either the constructor Tridiagonalization(const MatrixType&) or - * the member function compute(const MatrixType&) has been called before - * to compute the tridiagonal decomposition of a matrix. - * - * This function returns a light-weight object of template class - * HouseholderSequence. You can either apply it directly to a matrix or - * you can convert it to a matrix of type #MatrixType. - * - * \sa Tridiagonalization(const MatrixType&) for an example, - * matrixT(), class HouseholderSequence - */ - HouseholderSequenceType matrixQ() const - { - eigen_assert(m_isInitialized && "Tridiagonalization is not initialized."); - return HouseholderSequenceType(m_matrix, m_hCoeffs.conjugate()) - .setLength(m_matrix.rows() - 1) - .setShift(1); - } - - /** \brief Returns an expression of the tridiagonal matrix T in the decomposition - * - * \returns expression object representing the matrix T - * - * \pre Either the constructor Tridiagonalization(const MatrixType&) or - * the member function compute(const MatrixType&) has been called before - * to compute the tridiagonal decomposition of a matrix. - * - * Currently, this function can be used to extract the matrix T from internal - * data and copy it to a dense matrix object. In most cases, it may be - * sufficient to directly use the packed matrix or the vector expressions - * returned by diagonal() and subDiagonal() instead of creating a new - * dense copy matrix with this function. - * - * \sa Tridiagonalization(const MatrixType&) for an example, - * matrixQ(), packedMatrix(), diagonal(), subDiagonal() - */ - MatrixTReturnType matrixT() const - { - eigen_assert(m_isInitialized && "Tridiagonalization is not initialized."); - return MatrixTReturnType(m_matrix.real()); - } - - /** \brief Returns the diagonal of the tridiagonal matrix T in the decomposition. - * - * \returns expression representing the diagonal of T - * - * \pre Either the constructor Tridiagonalization(const MatrixType&) or - * the member function compute(const MatrixType&) has been called before - * to compute the tridiagonal decomposition of a matrix. - * - * Example: \include Tridiagonalization_diagonal.cpp - * Output: \verbinclude Tridiagonalization_diagonal.out - * - * \sa matrixT(), subDiagonal() - */ - DiagonalReturnType diagonal() const; - - /** \brief Returns the subdiagonal of the tridiagonal matrix T in the decomposition. - * - * \returns expression representing the subdiagonal of T - * - * \pre Either the constructor Tridiagonalization(const MatrixType&) or - * the member function compute(const MatrixType&) has been called before - * to compute the tridiagonal decomposition of a matrix. - * - * \sa diagonal() for an example, matrixT() - */ - SubDiagonalReturnType subDiagonal() const; - - protected: - - MatrixType m_matrix; - CoeffVectorType m_hCoeffs; - bool m_isInitialized; -}; - -template<typename MatrixType> -typename Tridiagonalization<MatrixType>::DiagonalReturnType -Tridiagonalization<MatrixType>::diagonal() const -{ - eigen_assert(m_isInitialized && "Tridiagonalization is not initialized."); - return m_matrix.diagonal().real(); -} - -template<typename MatrixType> -typename Tridiagonalization<MatrixType>::SubDiagonalReturnType -Tridiagonalization<MatrixType>::subDiagonal() const -{ - eigen_assert(m_isInitialized && "Tridiagonalization is not initialized."); - return m_matrix.template diagonal<-1>().real(); -} - -namespace internal { - -/** \internal - * Performs a tridiagonal decomposition of the selfadjoint matrix \a matA in-place. - * - * \param[in,out] matA On input the selfadjoint matrix. Only the \b lower triangular part is referenced. - * On output, the strict upper part is left unchanged, and the lower triangular part - * represents the T and Q matrices in packed format has detailed below. - * \param[out] hCoeffs returned Householder coefficients (see below) - * - * On output, the tridiagonal selfadjoint matrix T is stored in the diagonal - * and lower sub-diagonal of the matrix \a matA. - * The unitary matrix Q is represented in a compact way as a product of - * Householder reflectors \f$ H_i \f$ such that: - * \f$ Q = H_{N-1} \ldots H_1 H_0 \f$. - * The Householder reflectors are defined as - * \f$ H_i = (I - h_i v_i v_i^T) \f$ - * where \f$ h_i = hCoeffs[i]\f$ is the \f$ i \f$th Householder coefficient and - * \f$ v_i \f$ is the Householder vector defined by - * \f$ v_i = [ 0, \ldots, 0, 1, matA(i+2,i), \ldots, matA(N-1,i) ]^T \f$. - * - * Implemented from Golub's "Matrix Computations", algorithm 8.3.1. - * - * \sa Tridiagonalization::packedMatrix() - */ -template<typename MatrixType, typename CoeffVectorType> -EIGEN_DEVICE_FUNC -void tridiagonalization_inplace(MatrixType& matA, CoeffVectorType& hCoeffs) -{ - using numext::conj; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - Index n = matA.rows(); - eigen_assert(n==matA.cols()); - eigen_assert(n==hCoeffs.size()+1 || n==1); - - for (Index i = 0; i<n-1; ++i) - { - Index remainingSize = n-i-1; - RealScalar beta; - Scalar h; - matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta); - - // Apply similarity transformation to remaining columns, - // i.e., A = H A H' where H = I - h v v' and v = matA.col(i).tail(n-i-1) - matA.col(i).coeffRef(i+1) = 1; - - hCoeffs.tail(n-i-1).noalias() = (matA.bottomRightCorner(remainingSize,remainingSize).template selfadjointView<Lower>() - * (conj(h) * matA.col(i).tail(remainingSize))); - - hCoeffs.tail(n-i-1) += (conj(h)*RealScalar(-0.5)*(hCoeffs.tail(remainingSize).dot(matA.col(i).tail(remainingSize)))) * matA.col(i).tail(n-i-1); - - matA.bottomRightCorner(remainingSize, remainingSize).template selfadjointView<Lower>() - .rankUpdate(matA.col(i).tail(remainingSize), hCoeffs.tail(remainingSize), Scalar(-1)); - - matA.col(i).coeffRef(i+1) = beta; - hCoeffs.coeffRef(i) = h; - } -} - -// forward declaration, implementation at the end of this file -template<typename MatrixType, - int Size=MatrixType::ColsAtCompileTime, - bool IsComplex=NumTraits<typename MatrixType::Scalar>::IsComplex> -struct tridiagonalization_inplace_selector; - -/** \brief Performs a full tridiagonalization in place - * - * \param[in,out] mat On input, the selfadjoint matrix whose tridiagonal - * decomposition is to be computed. Only the lower triangular part referenced. - * The rest is left unchanged. On output, the orthogonal matrix Q - * in the decomposition if \p extractQ is true. - * \param[out] diag The diagonal of the tridiagonal matrix T in the - * decomposition. - * \param[out] subdiag The subdiagonal of the tridiagonal matrix T in - * the decomposition. - * \param[in] extractQ If true, the orthogonal matrix Q in the - * decomposition is computed and stored in \p mat. - * - * Computes the tridiagonal decomposition of the selfadjoint matrix \p mat in place - * such that \f$ mat = Q T Q^* \f$ where \f$ Q \f$ is unitary and \f$ T \f$ a real - * symmetric tridiagonal matrix. - * - * The tridiagonal matrix T is passed to the output parameters \p diag and \p subdiag. If - * \p extractQ is true, then the orthogonal matrix Q is passed to \p mat. Otherwise the lower - * part of the matrix \p mat is destroyed. - * - * The vectors \p diag and \p subdiag are not resized. The function - * assumes that they are already of the correct size. The length of the - * vector \p diag should equal the number of rows in \p mat, and the - * length of the vector \p subdiag should be one left. - * - * This implementation contains an optimized path for 3-by-3 matrices - * which is especially useful for plane fitting. - * - * \note Currently, it requires two temporary vectors to hold the intermediate - * Householder coefficients, and to reconstruct the matrix Q from the Householder - * reflectors. - * - * Example (this uses the same matrix as the example in - * Tridiagonalization::Tridiagonalization(const MatrixType&)): - * \include Tridiagonalization_decomposeInPlace.cpp - * Output: \verbinclude Tridiagonalization_decomposeInPlace.out - * - * \sa class Tridiagonalization - */ -template<typename MatrixType, typename DiagonalType, typename SubDiagonalType> -EIGEN_DEVICE_FUNC -void tridiagonalization_inplace(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, bool extractQ) -{ - eigen_assert(mat.cols()==mat.rows() && diag.size()==mat.rows() && subdiag.size()==mat.rows()-1); - tridiagonalization_inplace_selector<MatrixType>::run(mat, diag, subdiag, extractQ); -} - -/** \internal - * General full tridiagonalization - */ -template<typename MatrixType, int Size, bool IsComplex> -struct tridiagonalization_inplace_selector -{ - typedef typename Tridiagonalization<MatrixType>::CoeffVectorType CoeffVectorType; - typedef typename Tridiagonalization<MatrixType>::HouseholderSequenceType HouseholderSequenceType; - template<typename DiagonalType, typename SubDiagonalType> - static EIGEN_DEVICE_FUNC - void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, bool extractQ) - { - CoeffVectorType hCoeffs(mat.cols()-1); - tridiagonalization_inplace(mat,hCoeffs); - diag = mat.diagonal().real(); - subdiag = mat.template diagonal<-1>().real(); - if(extractQ) - mat = HouseholderSequenceType(mat, hCoeffs.conjugate()) - .setLength(mat.rows() - 1) - .setShift(1); - } -}; - -/** \internal - * Specialization for 3x3 real matrices. - * Especially useful for plane fitting. - */ -template<typename MatrixType> -struct tridiagonalization_inplace_selector<MatrixType,3,false> -{ - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - - template<typename DiagonalType, typename SubDiagonalType> - static void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, bool extractQ) - { - using std::sqrt; - const RealScalar tol = (std::numeric_limits<RealScalar>::min)(); - diag[0] = mat(0,0); - RealScalar v1norm2 = numext::abs2(mat(2,0)); - if(v1norm2 <= tol) - { - diag[1] = mat(1,1); - diag[2] = mat(2,2); - subdiag[0] = mat(1,0); - subdiag[1] = mat(2,1); - if (extractQ) - mat.setIdentity(); - } - else - { - RealScalar beta = sqrt(numext::abs2(mat(1,0)) + v1norm2); - RealScalar invBeta = RealScalar(1)/beta; - Scalar m01 = mat(1,0) * invBeta; - Scalar m02 = mat(2,0) * invBeta; - Scalar q = RealScalar(2)*m01*mat(2,1) + m02*(mat(2,2) - mat(1,1)); - diag[1] = mat(1,1) + m02*q; - diag[2] = mat(2,2) - m02*q; - subdiag[0] = beta; - subdiag[1] = mat(2,1) - m01 * q; - if (extractQ) - { - mat << 1, 0, 0, - 0, m01, m02, - 0, m02, -m01; - } - } - } -}; - -/** \internal - * Trivial specialization for 1x1 matrices - */ -template<typename MatrixType, bool IsComplex> -struct tridiagonalization_inplace_selector<MatrixType,1,IsComplex> -{ - typedef typename MatrixType::Scalar Scalar; - - template<typename DiagonalType, typename SubDiagonalType> - static EIGEN_DEVICE_FUNC - void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType&, bool extractQ) - { - diag(0,0) = numext::real(mat(0,0)); - if(extractQ) - mat(0,0) = Scalar(1); - } -}; - -/** \internal - * \eigenvalues_module \ingroup Eigenvalues_Module - * - * \brief Expression type for return value of Tridiagonalization::matrixT() - * - * \tparam MatrixType type of underlying dense matrix - */ -template<typename MatrixType> struct TridiagonalizationMatrixTReturnType -: public ReturnByValue<TridiagonalizationMatrixTReturnType<MatrixType> > -{ - public: - /** \brief Constructor. - * - * \param[in] mat The underlying dense matrix - */ - TridiagonalizationMatrixTReturnType(const MatrixType& mat) : m_matrix(mat) { } - - template <typename ResultType> - inline void evalTo(ResultType& result) const - { - result.setZero(); - result.template diagonal<1>() = m_matrix.template diagonal<-1>().conjugate(); - result.diagonal() = m_matrix.diagonal(); - result.template diagonal<-1>() = m_matrix.template diagonal<-1>(); - } - - Index rows() const { return m_matrix.rows(); } - Index cols() const { return m_matrix.cols(); } - - protected: - typename MatrixType::Nested m_matrix; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRIDIAGONALIZATION_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/AlignedBox.h b/external/eigen/include/eigen3/Eigen/src/Geometry/AlignedBox.h deleted file mode 100644 index c902d8f0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/AlignedBox.h +++ /dev/null @@ -1,392 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ALIGNEDBOX_H -#define EIGEN_ALIGNEDBOX_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * - * \class AlignedBox - * - * \brief An axis aligned box - * - * \tparam _Scalar the type of the scalar coefficients - * \tparam _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic. - * - * This class represents an axis aligned box as a pair of the minimal and maximal corners. - * \warning The result of most methods is undefined when applied to an empty box. You can check for empty boxes using isEmpty(). - * \sa alignedboxtypedefs - */ -template <typename _Scalar, int _AmbientDim> -class AlignedBox -{ -public: -EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim) - enum { AmbientDimAtCompileTime = _AmbientDim }; - typedef _Scalar Scalar; - typedef NumTraits<Scalar> ScalarTraits; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - typedef typename ScalarTraits::Real RealScalar; - typedef typename ScalarTraits::NonInteger NonInteger; - typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType; - typedef CwiseBinaryOp<internal::scalar_sum_op<Scalar>, const VectorType, const VectorType> VectorTypeSum; - - /** Define constants to name the corners of a 1D, 2D or 3D axis aligned bounding box */ - enum CornerType - { - /** 1D names @{ */ - Min=0, Max=1, - /** @} */ - - /** Identifier for 2D corner @{ */ - BottomLeft=0, BottomRight=1, - TopLeft=2, TopRight=3, - /** @} */ - - /** Identifier for 3D corner @{ */ - BottomLeftFloor=0, BottomRightFloor=1, - TopLeftFloor=2, TopRightFloor=3, - BottomLeftCeil=4, BottomRightCeil=5, - TopLeftCeil=6, TopRightCeil=7 - /** @} */ - }; - - - /** Default constructor initializing a null box. */ - EIGEN_DEVICE_FUNC inline AlignedBox() - { if (EIGEN_CONST_CONDITIONAL(AmbientDimAtCompileTime!=Dynamic)) setEmpty(); } - - /** Constructs a null box with \a _dim the dimension of the ambient space. */ - EIGEN_DEVICE_FUNC inline explicit AlignedBox(Index _dim) : m_min(_dim), m_max(_dim) - { setEmpty(); } - - /** Constructs a box with extremities \a _min and \a _max. - * \warning If either component of \a _min is larger than the same component of \a _max, the constructed box is empty. */ - template<typename OtherVectorType1, typename OtherVectorType2> - EIGEN_DEVICE_FUNC inline AlignedBox(const OtherVectorType1& _min, const OtherVectorType2& _max) : m_min(_min), m_max(_max) {} - - /** Constructs a box containing a single point \a p. */ - template<typename Derived> - EIGEN_DEVICE_FUNC inline explicit AlignedBox(const MatrixBase<Derived>& p) : m_min(p), m_max(m_min) - { } - - EIGEN_DEVICE_FUNC ~AlignedBox() {} - - /** \returns the dimension in which the box holds */ - EIGEN_DEVICE_FUNC inline Index dim() const { return AmbientDimAtCompileTime==Dynamic ? m_min.size() : Index(AmbientDimAtCompileTime); } - - /** \deprecated use isEmpty() */ - EIGEN_DEVICE_FUNC inline bool isNull() const { return isEmpty(); } - - /** \deprecated use setEmpty() */ - EIGEN_DEVICE_FUNC inline void setNull() { setEmpty(); } - - /** \returns true if the box is empty. - * \sa setEmpty */ - EIGEN_DEVICE_FUNC inline bool isEmpty() const { return (m_min.array() > m_max.array()).any(); } - - /** Makes \c *this an empty box. - * \sa isEmpty */ - EIGEN_DEVICE_FUNC inline void setEmpty() - { - m_min.setConstant( ScalarTraits::highest() ); - m_max.setConstant( ScalarTraits::lowest() ); - } - - /** \returns the minimal corner */ - EIGEN_DEVICE_FUNC inline const VectorType& (min)() const { return m_min; } - /** \returns a non const reference to the minimal corner */ - EIGEN_DEVICE_FUNC inline VectorType& (min)() { return m_min; } - /** \returns the maximal corner */ - EIGEN_DEVICE_FUNC inline const VectorType& (max)() const { return m_max; } - /** \returns a non const reference to the maximal corner */ - EIGEN_DEVICE_FUNC inline VectorType& (max)() { return m_max; } - - /** \returns the center of the box */ - EIGEN_DEVICE_FUNC inline const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, quotient) - center() const - { return (m_min+m_max)/RealScalar(2); } - - /** \returns the lengths of the sides of the bounding box. - * Note that this function does not get the same - * result for integral or floating scalar types: see - */ - EIGEN_DEVICE_FUNC inline const CwiseBinaryOp< internal::scalar_difference_op<Scalar,Scalar>, const VectorType, const VectorType> sizes() const - { return m_max - m_min; } - - /** \returns the volume of the bounding box */ - EIGEN_DEVICE_FUNC inline Scalar volume() const - { return sizes().prod(); } - - /** \returns an expression for the bounding box diagonal vector - * if the length of the diagonal is needed: diagonal().norm() - * will provide it. - */ - EIGEN_DEVICE_FUNC inline CwiseBinaryOp< internal::scalar_difference_op<Scalar,Scalar>, const VectorType, const VectorType> diagonal() const - { return sizes(); } - - /** \returns the vertex of the bounding box at the corner defined by - * the corner-id corner. It works only for a 1D, 2D or 3D bounding box. - * For 1D bounding boxes corners are named by 2 enum constants: - * BottomLeft and BottomRight. - * For 2D bounding boxes, corners are named by 4 enum constants: - * BottomLeft, BottomRight, TopLeft, TopRight. - * For 3D bounding boxes, the following names are added: - * BottomLeftCeil, BottomRightCeil, TopLeftCeil, TopRightCeil. - */ - EIGEN_DEVICE_FUNC inline VectorType corner(CornerType corner) const - { - EIGEN_STATIC_ASSERT(_AmbientDim <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE); - - VectorType res; - - Index mult = 1; - for(Index d=0; d<dim(); ++d) - { - if( mult & corner ) res[d] = m_max[d]; - else res[d] = m_min[d]; - mult *= 2; - } - return res; - } - - /** \returns a random point inside the bounding box sampled with - * a uniform distribution */ - EIGEN_DEVICE_FUNC inline VectorType sample() const - { - VectorType r(dim()); - for(Index d=0; d<dim(); ++d) - { - if(!ScalarTraits::IsInteger) - { - r[d] = m_min[d] + (m_max[d]-m_min[d]) - * internal::random<Scalar>(Scalar(0), Scalar(1)); - } - else - r[d] = internal::random(m_min[d], m_max[d]); - } - return r; - } - - /** \returns true if the point \a p is inside the box \c *this. */ - template<typename Derived> - EIGEN_DEVICE_FUNC inline bool contains(const MatrixBase<Derived>& p) const - { - typename internal::nested_eval<Derived,2>::type p_n(p.derived()); - return (m_min.array()<=p_n.array()).all() && (p_n.array()<=m_max.array()).all(); - } - - /** \returns true if the box \a b is entirely inside the box \c *this. */ - EIGEN_DEVICE_FUNC inline bool contains(const AlignedBox& b) const - { return (m_min.array()<=(b.min)().array()).all() && ((b.max)().array()<=m_max.array()).all(); } - - /** \returns true if the box \a b is intersecting the box \c *this. - * \sa intersection, clamp */ - EIGEN_DEVICE_FUNC inline bool intersects(const AlignedBox& b) const - { return (m_min.array()<=(b.max)().array()).all() && ((b.min)().array()<=m_max.array()).all(); } - - /** Extends \c *this such that it contains the point \a p and returns a reference to \c *this. - * \sa extend(const AlignedBox&) */ - template<typename Derived> - EIGEN_DEVICE_FUNC inline AlignedBox& extend(const MatrixBase<Derived>& p) - { - typename internal::nested_eval<Derived,2>::type p_n(p.derived()); - m_min = m_min.cwiseMin(p_n); - m_max = m_max.cwiseMax(p_n); - return *this; - } - - /** Extends \c *this such that it contains the box \a b and returns a reference to \c *this. - * \sa merged, extend(const MatrixBase&) */ - EIGEN_DEVICE_FUNC inline AlignedBox& extend(const AlignedBox& b) - { - m_min = m_min.cwiseMin(b.m_min); - m_max = m_max.cwiseMax(b.m_max); - return *this; - } - - /** Clamps \c *this by the box \a b and returns a reference to \c *this. - * \note If the boxes don't intersect, the resulting box is empty. - * \sa intersection(), intersects() */ - EIGEN_DEVICE_FUNC inline AlignedBox& clamp(const AlignedBox& b) - { - m_min = m_min.cwiseMax(b.m_min); - m_max = m_max.cwiseMin(b.m_max); - return *this; - } - - /** Returns an AlignedBox that is the intersection of \a b and \c *this - * \note If the boxes don't intersect, the resulting box is empty. - * \sa intersects(), clamp, contains() */ - EIGEN_DEVICE_FUNC inline AlignedBox intersection(const AlignedBox& b) const - {return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max)); } - - /** Returns an AlignedBox that is the union of \a b and \c *this. - * \note Merging with an empty box may result in a box bigger than \c *this. - * \sa extend(const AlignedBox&) */ - EIGEN_DEVICE_FUNC inline AlignedBox merged(const AlignedBox& b) const - { return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max)); } - - /** Translate \c *this by the vector \a t and returns a reference to \c *this. */ - template<typename Derived> - EIGEN_DEVICE_FUNC inline AlignedBox& translate(const MatrixBase<Derived>& a_t) - { - const typename internal::nested_eval<Derived,2>::type t(a_t.derived()); - m_min += t; - m_max += t; - return *this; - } - - /** \returns the squared distance between the point \a p and the box \c *this, - * and zero if \a p is inside the box. - * \sa exteriorDistance(const MatrixBase&), squaredExteriorDistance(const AlignedBox&) - */ - template<typename Derived> - EIGEN_DEVICE_FUNC inline Scalar squaredExteriorDistance(const MatrixBase<Derived>& p) const; - - /** \returns the squared distance between the boxes \a b and \c *this, - * and zero if the boxes intersect. - * \sa exteriorDistance(const AlignedBox&), squaredExteriorDistance(const MatrixBase&) - */ - EIGEN_DEVICE_FUNC inline Scalar squaredExteriorDistance(const AlignedBox& b) const; - - /** \returns the distance between the point \a p and the box \c *this, - * and zero if \a p is inside the box. - * \sa squaredExteriorDistance(const MatrixBase&), exteriorDistance(const AlignedBox&) - */ - template<typename Derived> - EIGEN_DEVICE_FUNC inline NonInteger exteriorDistance(const MatrixBase<Derived>& p) const - { EIGEN_USING_STD_MATH(sqrt) return sqrt(NonInteger(squaredExteriorDistance(p))); } - - /** \returns the distance between the boxes \a b and \c *this, - * and zero if the boxes intersect. - * \sa squaredExteriorDistance(const AlignedBox&), exteriorDistance(const MatrixBase&) - */ - EIGEN_DEVICE_FUNC inline NonInteger exteriorDistance(const AlignedBox& b) const - { EIGEN_USING_STD_MATH(sqrt) return sqrt(NonInteger(squaredExteriorDistance(b))); } - - /** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<AlignedBox, - AlignedBox<NewScalarType,AmbientDimAtCompileTime> >::type cast() const - { - return typename internal::cast_return_type<AlignedBox, - AlignedBox<NewScalarType,AmbientDimAtCompileTime> >::type(*this); - } - - /** Copy constructor with scalar type conversion */ - template<typename OtherScalarType> - EIGEN_DEVICE_FUNC inline explicit AlignedBox(const AlignedBox<OtherScalarType,AmbientDimAtCompileTime>& other) - { - m_min = (other.min)().template cast<Scalar>(); - m_max = (other.max)().template cast<Scalar>(); - } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - EIGEN_DEVICE_FUNC bool isApprox(const AlignedBox& other, const RealScalar& prec = ScalarTraits::dummy_precision()) const - { return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec); } - -protected: - - VectorType m_min, m_max; -}; - - - -template<typename Scalar,int AmbientDim> -template<typename Derived> -EIGEN_DEVICE_FUNC inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const MatrixBase<Derived>& a_p) const -{ - typename internal::nested_eval<Derived,2*AmbientDim>::type p(a_p.derived()); - Scalar dist2(0); - Scalar aux; - for (Index k=0; k<dim(); ++k) - { - if( m_min[k] > p[k] ) - { - aux = m_min[k] - p[k]; - dist2 += aux*aux; - } - else if( p[k] > m_max[k] ) - { - aux = p[k] - m_max[k]; - dist2 += aux*aux; - } - } - return dist2; -} - -template<typename Scalar,int AmbientDim> -EIGEN_DEVICE_FUNC inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const AlignedBox& b) const -{ - Scalar dist2(0); - Scalar aux; - for (Index k=0; k<dim(); ++k) - { - if( m_min[k] > b.m_max[k] ) - { - aux = m_min[k] - b.m_max[k]; - dist2 += aux*aux; - } - else if( b.m_min[k] > m_max[k] ) - { - aux = b.m_min[k] - m_max[k]; - dist2 += aux*aux; - } - } - return dist2; -} - -/** \defgroup alignedboxtypedefs Global aligned box typedefs - * - * \ingroup Geometry_Module - * - * Eigen defines several typedef shortcuts for most common aligned box types. - * - * The general patterns are the following: - * - * \c AlignedBoxSizeType where \c Size can be \c 1, \c 2,\c 3,\c 4 for fixed size boxes or \c X for dynamic size, - * and where \c Type can be \c i for integer, \c f for float, \c d for double. - * - * For example, \c AlignedBox3d is a fixed-size 3x3 aligned box type of doubles, and \c AlignedBoxXf is a dynamic-size aligned box of floats. - * - * \sa class AlignedBox - */ - -#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ -/** \ingroup alignedboxtypedefs */ \ -typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix; - -#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 1, 1) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \ -EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) - -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i) -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f) -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d) - -#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES -#undef EIGEN_MAKE_TYPEDEFS - -} // end namespace Eigen - -#endif // EIGEN_ALIGNEDBOX_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/AngleAxis.h b/external/eigen/include/eigen3/Eigen/src/Geometry/AngleAxis.h deleted file mode 100644 index 83ee1be4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/AngleAxis.h +++ /dev/null @@ -1,247 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ANGLEAXIS_H -#define EIGEN_ANGLEAXIS_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * \class AngleAxis - * - * \brief Represents a 3D rotation as a rotation angle around an arbitrary 3D axis - * - * \param _Scalar the scalar type, i.e., the type of the coefficients. - * - * \warning When setting up an AngleAxis object, the axis vector \b must \b be \b normalized. - * - * The following two typedefs are provided for convenience: - * \li \c AngleAxisf for \c float - * \li \c AngleAxisd for \c double - * - * Combined with MatrixBase::Unit{X,Y,Z}, AngleAxis can be used to easily - * mimic Euler-angles. Here is an example: - * \include AngleAxis_mimic_euler.cpp - * Output: \verbinclude AngleAxis_mimic_euler.out - * - * \note This class is not aimed to be used to store a rotation transformation, - * but rather to make easier the creation of other rotation (Quaternion, rotation Matrix) - * and transformation objects. - * - * \sa class Quaternion, class Transform, MatrixBase::UnitX() - */ - -namespace internal { -template<typename _Scalar> struct traits<AngleAxis<_Scalar> > -{ - typedef _Scalar Scalar; -}; -} - -template<typename _Scalar> -class AngleAxis : public RotationBase<AngleAxis<_Scalar>,3> -{ - typedef RotationBase<AngleAxis<_Scalar>,3> Base; - -public: - - using Base::operator*; - - enum { Dim = 3 }; - /** the scalar type of the coefficients */ - typedef _Scalar Scalar; - typedef Matrix<Scalar,3,3> Matrix3; - typedef Matrix<Scalar,3,1> Vector3; - typedef Quaternion<Scalar> QuaternionType; - -protected: - - Vector3 m_axis; - Scalar m_angle; - -public: - - /** Default constructor without initialization. */ - EIGEN_DEVICE_FUNC AngleAxis() {} - /** Constructs and initialize the angle-axis rotation from an \a angle in radian - * and an \a axis which \b must \b be \b normalized. - * - * \warning If the \a axis vector is not normalized, then the angle-axis object - * represents an invalid rotation. */ - template<typename Derived> - EIGEN_DEVICE_FUNC - inline AngleAxis(const Scalar& angle, const MatrixBase<Derived>& axis) : m_axis(axis), m_angle(angle) {} - /** Constructs and initialize the angle-axis rotation from a quaternion \a q. - * This function implicitly normalizes the quaternion \a q. - */ - template<typename QuatDerived> - EIGEN_DEVICE_FUNC inline explicit AngleAxis(const QuaternionBase<QuatDerived>& q) { *this = q; } - /** Constructs and initialize the angle-axis rotation from a 3x3 rotation matrix. */ - template<typename Derived> - EIGEN_DEVICE_FUNC inline explicit AngleAxis(const MatrixBase<Derived>& m) { *this = m; } - - /** \returns the value of the rotation angle in radian */ - EIGEN_DEVICE_FUNC Scalar angle() const { return m_angle; } - /** \returns a read-write reference to the stored angle in radian */ - EIGEN_DEVICE_FUNC Scalar& angle() { return m_angle; } - - /** \returns the rotation axis */ - EIGEN_DEVICE_FUNC const Vector3& axis() const { return m_axis; } - /** \returns a read-write reference to the stored rotation axis. - * - * \warning The rotation axis must remain a \b unit vector. - */ - EIGEN_DEVICE_FUNC Vector3& axis() { return m_axis; } - - /** Concatenates two rotations */ - EIGEN_DEVICE_FUNC inline QuaternionType operator* (const AngleAxis& other) const - { return QuaternionType(*this) * QuaternionType(other); } - - /** Concatenates two rotations */ - EIGEN_DEVICE_FUNC inline QuaternionType operator* (const QuaternionType& other) const - { return QuaternionType(*this) * other; } - - /** Concatenates two rotations */ - friend EIGEN_DEVICE_FUNC inline QuaternionType operator* (const QuaternionType& a, const AngleAxis& b) - { return a * QuaternionType(b); } - - /** \returns the inverse rotation, i.e., an angle-axis with opposite rotation angle */ - EIGEN_DEVICE_FUNC AngleAxis inverse() const - { return AngleAxis(-m_angle, m_axis); } - - template<class QuatDerived> - EIGEN_DEVICE_FUNC AngleAxis& operator=(const QuaternionBase<QuatDerived>& q); - template<typename Derived> - EIGEN_DEVICE_FUNC AngleAxis& operator=(const MatrixBase<Derived>& m); - - template<typename Derived> - EIGEN_DEVICE_FUNC AngleAxis& fromRotationMatrix(const MatrixBase<Derived>& m); - EIGEN_DEVICE_FUNC Matrix3 toRotationMatrix(void) const; - - /** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<AngleAxis,AngleAxis<NewScalarType> >::type cast() const - { return typename internal::cast_return_type<AngleAxis,AngleAxis<NewScalarType> >::type(*this); } - - /** Copy constructor with scalar type conversion */ - template<typename OtherScalarType> - EIGEN_DEVICE_FUNC inline explicit AngleAxis(const AngleAxis<OtherScalarType>& other) - { - m_axis = other.axis().template cast<Scalar>(); - m_angle = Scalar(other.angle()); - } - - EIGEN_DEVICE_FUNC static inline const AngleAxis Identity() { return AngleAxis(Scalar(0), Vector3::UnitX()); } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - EIGEN_DEVICE_FUNC bool isApprox(const AngleAxis& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const - { return m_axis.isApprox(other.m_axis, prec) && internal::isApprox(m_angle,other.m_angle, prec); } -}; - -/** \ingroup Geometry_Module - * single precision angle-axis type */ -typedef AngleAxis<float> AngleAxisf; -/** \ingroup Geometry_Module - * double precision angle-axis type */ -typedef AngleAxis<double> AngleAxisd; - -/** Set \c *this from a \b unit quaternion. - * - * The resulting axis is normalized, and the computed angle is in the [0,pi] range. - * - * This function implicitly normalizes the quaternion \a q. - */ -template<typename Scalar> -template<typename QuatDerived> -EIGEN_DEVICE_FUNC AngleAxis<Scalar>& AngleAxis<Scalar>::operator=(const QuaternionBase<QuatDerived>& q) -{ - EIGEN_USING_STD_MATH(atan2) - EIGEN_USING_STD_MATH(abs) - Scalar n = q.vec().norm(); - if(n<NumTraits<Scalar>::epsilon()) - n = q.vec().stableNorm(); - - if (n != Scalar(0)) - { - m_angle = Scalar(2)*atan2(n, abs(q.w())); - if(q.w() < Scalar(0)) - n = -n; - m_axis = q.vec() / n; - } - else - { - m_angle = Scalar(0); - m_axis << Scalar(1), Scalar(0), Scalar(0); - } - return *this; -} - -/** Set \c *this from a 3x3 rotation matrix \a mat. - */ -template<typename Scalar> -template<typename Derived> -EIGEN_DEVICE_FUNC AngleAxis<Scalar>& AngleAxis<Scalar>::operator=(const MatrixBase<Derived>& mat) -{ - // Since a direct conversion would not be really faster, - // let's use the robust Quaternion implementation: - return *this = QuaternionType(mat); -} - -/** -* \brief Sets \c *this from a 3x3 rotation matrix. -**/ -template<typename Scalar> -template<typename Derived> -EIGEN_DEVICE_FUNC AngleAxis<Scalar>& AngleAxis<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat) -{ - return *this = QuaternionType(mat); -} - -/** Constructs and \returns an equivalent 3x3 rotation matrix. - */ -template<typename Scalar> -typename AngleAxis<Scalar>::Matrix3 -EIGEN_DEVICE_FUNC AngleAxis<Scalar>::toRotationMatrix(void) const -{ - EIGEN_USING_STD_MATH(sin) - EIGEN_USING_STD_MATH(cos) - Matrix3 res; - Vector3 sin_axis = sin(m_angle) * m_axis; - Scalar c = cos(m_angle); - Vector3 cos1_axis = (Scalar(1)-c) * m_axis; - - Scalar tmp; - tmp = cos1_axis.x() * m_axis.y(); - res.coeffRef(0,1) = tmp - sin_axis.z(); - res.coeffRef(1,0) = tmp + sin_axis.z(); - - tmp = cos1_axis.x() * m_axis.z(); - res.coeffRef(0,2) = tmp + sin_axis.y(); - res.coeffRef(2,0) = tmp - sin_axis.y(); - - tmp = cos1_axis.y() * m_axis.z(); - res.coeffRef(1,2) = tmp - sin_axis.x(); - res.coeffRef(2,1) = tmp + sin_axis.x(); - - res.diagonal() = (cos1_axis.cwiseProduct(m_axis)).array() + c; - - return res; -} - -} // end namespace Eigen - -#endif // EIGEN_ANGLEAXIS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/EulerAngles.h b/external/eigen/include/eigen3/Eigen/src/Geometry/EulerAngles.h deleted file mode 100644 index c633268a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/EulerAngles.h +++ /dev/null @@ -1,114 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_EULERANGLES_H -#define EIGEN_EULERANGLES_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * - * \returns the Euler-angles of the rotation matrix \c *this using the convention defined by the triplet (\a a0,\a a1,\a a2) - * - * Each of the three parameters \a a0,\a a1,\a a2 represents the respective rotation axis as an integer in {0,1,2}. - * For instance, in: - * \code Vector3f ea = mat.eulerAngles(2, 0, 2); \endcode - * "2" represents the z axis and "0" the x axis, etc. The returned angles are such that - * we have the following equality: - * \code - * mat == AngleAxisf(ea[0], Vector3f::UnitZ()) - * * AngleAxisf(ea[1], Vector3f::UnitX()) - * * AngleAxisf(ea[2], Vector3f::UnitZ()); \endcode - * This corresponds to the right-multiply conventions (with right hand side frames). - * - * The returned angles are in the ranges [0:pi]x[-pi:pi]x[-pi:pi]. - * - * \sa class AngleAxis - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline Matrix<typename MatrixBase<Derived>::Scalar,3,1> -MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const -{ - EIGEN_USING_STD_MATH(atan2) - EIGEN_USING_STD_MATH(sin) - EIGEN_USING_STD_MATH(cos) - /* Implemented from Graphics Gems IV */ - EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3) - - Matrix<Scalar,3,1> res; - typedef Matrix<typename Derived::Scalar,2,1> Vector2; - - const Index odd = ((a0+1)%3 == a1) ? 0 : 1; - const Index i = a0; - const Index j = (a0 + 1 + odd)%3; - const Index k = (a0 + 2 - odd)%3; - - if (a0==a2) - { - res[0] = atan2(coeff(j,i), coeff(k,i)); - if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0))) - { - if(res[0] > Scalar(0)) { - res[0] -= Scalar(EIGEN_PI); - } - else { - res[0] += Scalar(EIGEN_PI); - } - Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm(); - res[1] = -atan2(s2, coeff(i,i)); - } - else - { - Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm(); - res[1] = atan2(s2, coeff(i,i)); - } - - // With a=(0,1,0), we have i=0; j=1; k=2, and after computing the first two angles, - // we can compute their respective rotation, and apply its inverse to M. Since the result must - // be a rotation around x, we have: - // - // c2 s1.s2 c1.s2 1 0 0 - // 0 c1 -s1 * M = 0 c3 s3 - // -s2 s1.c2 c1.c2 0 -s3 c3 - // - // Thus: m11.c1 - m21.s1 = c3 & m12.c1 - m22.s1 = s3 - - Scalar s1 = sin(res[0]); - Scalar c1 = cos(res[0]); - res[2] = atan2(c1*coeff(j,k)-s1*coeff(k,k), c1*coeff(j,j) - s1 * coeff(k,j)); - } - else - { - res[0] = atan2(coeff(j,k), coeff(k,k)); - Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm(); - if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0))) { - if(res[0] > Scalar(0)) { - res[0] -= Scalar(EIGEN_PI); - } - else { - res[0] += Scalar(EIGEN_PI); - } - res[1] = atan2(-coeff(i,k), -c2); - } - else - res[1] = atan2(-coeff(i,k), c2); - Scalar s1 = sin(res[0]); - Scalar c1 = cos(res[0]); - res[2] = atan2(s1*coeff(k,i)-c1*coeff(j,i), c1*coeff(j,j) - s1 * coeff(k,j)); - } - if (!odd) - res = -res; - - return res; -} - -} // end namespace Eigen - -#endif // EIGEN_EULERANGLES_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/Homogeneous.h b/external/eigen/include/eigen3/Eigen/src/Geometry/Homogeneous.h deleted file mode 100644 index 5f0da1a9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/Homogeneous.h +++ /dev/null @@ -1,497 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_HOMOGENEOUS_H -#define EIGEN_HOMOGENEOUS_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * \class Homogeneous - * - * \brief Expression of one (or a set of) homogeneous vector(s) - * - * \param MatrixType the type of the object in which we are making homogeneous - * - * This class represents an expression of one (or a set of) homogeneous vector(s). - * It is the return type of MatrixBase::homogeneous() and most of the time - * this is the only way it is used. - * - * \sa MatrixBase::homogeneous() - */ - -namespace internal { - -template<typename MatrixType,int Direction> -struct traits<Homogeneous<MatrixType,Direction> > - : traits<MatrixType> -{ - typedef typename traits<MatrixType>::StorageKind StorageKind; - typedef typename ref_selector<MatrixType>::type MatrixTypeNested; - typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested; - enum { - RowsPlusOne = (MatrixType::RowsAtCompileTime != Dynamic) ? - int(MatrixType::RowsAtCompileTime) + 1 : Dynamic, - ColsPlusOne = (MatrixType::ColsAtCompileTime != Dynamic) ? - int(MatrixType::ColsAtCompileTime) + 1 : Dynamic, - RowsAtCompileTime = Direction==Vertical ? RowsPlusOne : MatrixType::RowsAtCompileTime, - ColsAtCompileTime = Direction==Horizontal ? ColsPlusOne : MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = RowsAtCompileTime, - MaxColsAtCompileTime = ColsAtCompileTime, - TmpFlags = _MatrixTypeNested::Flags & HereditaryBits, - Flags = ColsAtCompileTime==1 ? (TmpFlags & ~RowMajorBit) - : RowsAtCompileTime==1 ? (TmpFlags | RowMajorBit) - : TmpFlags - }; -}; - -template<typename MatrixType,typename Lhs> struct homogeneous_left_product_impl; -template<typename MatrixType,typename Rhs> struct homogeneous_right_product_impl; - -} // end namespace internal - -template<typename MatrixType,int _Direction> class Homogeneous - : public MatrixBase<Homogeneous<MatrixType,_Direction> >, internal::no_assignment_operator -{ - public: - - typedef MatrixType NestedExpression; - enum { Direction = _Direction }; - - typedef MatrixBase<Homogeneous> Base; - EIGEN_DENSE_PUBLIC_INTERFACE(Homogeneous) - - EIGEN_DEVICE_FUNC explicit inline Homogeneous(const MatrixType& matrix) - : m_matrix(matrix) - {} - - EIGEN_DEVICE_FUNC inline Index rows() const { return m_matrix.rows() + (int(Direction)==Vertical ? 1 : 0); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_matrix.cols() + (int(Direction)==Horizontal ? 1 : 0); } - - EIGEN_DEVICE_FUNC const NestedExpression& nestedExpression() const { return m_matrix; } - - template<typename Rhs> - EIGEN_DEVICE_FUNC inline const Product<Homogeneous,Rhs> - operator* (const MatrixBase<Rhs>& rhs) const - { - eigen_assert(int(Direction)==Horizontal); - return Product<Homogeneous,Rhs>(*this,rhs.derived()); - } - - template<typename Lhs> friend - EIGEN_DEVICE_FUNC inline const Product<Lhs,Homogeneous> - operator* (const MatrixBase<Lhs>& lhs, const Homogeneous& rhs) - { - eigen_assert(int(Direction)==Vertical); - return Product<Lhs,Homogeneous>(lhs.derived(),rhs); - } - - template<typename Scalar, int Dim, int Mode, int Options> friend - EIGEN_DEVICE_FUNC inline const Product<Transform<Scalar,Dim,Mode,Options>, Homogeneous > - operator* (const Transform<Scalar,Dim,Mode,Options>& lhs, const Homogeneous& rhs) - { - eigen_assert(int(Direction)==Vertical); - return Product<Transform<Scalar,Dim,Mode,Options>, Homogeneous>(lhs,rhs); - } - - template<typename Func> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::result_of<Func(Scalar,Scalar)>::type - redux(const Func& func) const - { - return func(m_matrix.redux(func), Scalar(1)); - } - - protected: - typename MatrixType::Nested m_matrix; -}; - -/** \geometry_module \ingroup Geometry_Module - * - * \returns a vector expression that is one longer than the vector argument, with the value 1 symbolically appended as the last coefficient. - * - * This can be used to convert affine coordinates to homogeneous coordinates. - * - * \only_for_vectors - * - * Example: \include MatrixBase_homogeneous.cpp - * Output: \verbinclude MatrixBase_homogeneous.out - * - * \sa VectorwiseOp::homogeneous(), class Homogeneous - */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::HomogeneousReturnType -MatrixBase<Derived>::homogeneous() const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return HomogeneousReturnType(derived()); -} - -/** \geometry_module \ingroup Geometry_Module - * - * \returns an expression where the value 1 is symbolically appended as the final coefficient to each column (or row) of the matrix. - * - * This can be used to convert affine coordinates to homogeneous coordinates. - * - * Example: \include VectorwiseOp_homogeneous.cpp - * Output: \verbinclude VectorwiseOp_homogeneous.out - * - * \sa MatrixBase::homogeneous(), class Homogeneous */ -template<typename ExpressionType, int Direction> -EIGEN_DEVICE_FUNC inline Homogeneous<ExpressionType,Direction> -VectorwiseOp<ExpressionType,Direction>::homogeneous() const -{ - return HomogeneousReturnType(_expression()); -} - -/** \geometry_module \ingroup Geometry_Module - * - * \brief homogeneous normalization - * - * \returns a vector expression of the N-1 first coefficients of \c *this divided by that last coefficient. - * - * This can be used to convert homogeneous coordinates to affine coordinates. - * - * It is essentially a shortcut for: - * \code - this->head(this->size()-1)/this->coeff(this->size()-1); - \endcode - * - * Example: \include MatrixBase_hnormalized.cpp - * Output: \verbinclude MatrixBase_hnormalized.out - * - * \sa VectorwiseOp::hnormalized() */ -template<typename Derived> -EIGEN_DEVICE_FUNC inline const typename MatrixBase<Derived>::HNormalizedReturnType -MatrixBase<Derived>::hnormalized() const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return ConstStartMinusOne(derived(),0,0, - ColsAtCompileTime==1?size()-1:1, - ColsAtCompileTime==1?1:size()-1) / coeff(size()-1); -} - -/** \geometry_module \ingroup Geometry_Module - * - * \brief column or row-wise homogeneous normalization - * - * \returns an expression of the first N-1 coefficients of each column (or row) of \c *this divided by the last coefficient of each column (or row). - * - * This can be used to convert homogeneous coordinates to affine coordinates. - * - * It is conceptually equivalent to calling MatrixBase::hnormalized() to each column (or row) of \c *this. - * - * Example: \include DirectionWise_hnormalized.cpp - * Output: \verbinclude DirectionWise_hnormalized.out - * - * \sa MatrixBase::hnormalized() */ -template<typename ExpressionType, int Direction> -EIGEN_DEVICE_FUNC inline const typename VectorwiseOp<ExpressionType,Direction>::HNormalizedReturnType -VectorwiseOp<ExpressionType,Direction>::hnormalized() const -{ - return HNormalized_Block(_expression(),0,0, - Direction==Vertical ? _expression().rows()-1 : _expression().rows(), - Direction==Horizontal ? _expression().cols()-1 : _expression().cols()).cwiseQuotient( - Replicate<HNormalized_Factors, - Direction==Vertical ? HNormalized_SizeMinusOne : 1, - Direction==Horizontal ? HNormalized_SizeMinusOne : 1> - (HNormalized_Factors(_expression(), - Direction==Vertical ? _expression().rows()-1:0, - Direction==Horizontal ? _expression().cols()-1:0, - Direction==Vertical ? 1 : _expression().rows(), - Direction==Horizontal ? 1 : _expression().cols()), - Direction==Vertical ? _expression().rows()-1 : 1, - Direction==Horizontal ? _expression().cols()-1 : 1)); -} - -namespace internal { - -template<typename MatrixOrTransformType> -struct take_matrix_for_product -{ - typedef MatrixOrTransformType type; - EIGEN_DEVICE_FUNC static const type& run(const type &x) { return x; } -}; - -template<typename Scalar, int Dim, int Mode,int Options> -struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> > -{ - typedef Transform<Scalar, Dim, Mode, Options> TransformType; - typedef typename internal::add_const<typename TransformType::ConstAffinePart>::type type; - EIGEN_DEVICE_FUNC static type run (const TransformType& x) { return x.affine(); } -}; - -template<typename Scalar, int Dim, int Options> -struct take_matrix_for_product<Transform<Scalar, Dim, Projective, Options> > -{ - typedef Transform<Scalar, Dim, Projective, Options> TransformType; - typedef typename TransformType::MatrixType type; - EIGEN_DEVICE_FUNC static const type& run (const TransformType& x) { return x.matrix(); } -}; - -template<typename MatrixType,typename Lhs> -struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> > -{ - typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType; - typedef typename remove_all<MatrixType>::type MatrixTypeCleaned; - typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned; - typedef typename make_proper_matrix_type< - typename traits<MatrixTypeCleaned>::Scalar, - LhsMatrixTypeCleaned::RowsAtCompileTime, - MatrixTypeCleaned::ColsAtCompileTime, - MatrixTypeCleaned::PlainObject::Options, - LhsMatrixTypeCleaned::MaxRowsAtCompileTime, - MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType; -}; - -template<typename MatrixType,typename Lhs> -struct homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> - : public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> > -{ - typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType; - typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned; - typedef typename remove_all<typename LhsMatrixTypeCleaned::Nested>::type LhsMatrixTypeNested; - EIGEN_DEVICE_FUNC homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs) - : m_lhs(take_matrix_for_product<Lhs>::run(lhs)), - m_rhs(rhs) - {} - - EIGEN_DEVICE_FUNC inline Index rows() const { return m_lhs.rows(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_rhs.cols(); } - - template<typename Dest> EIGEN_DEVICE_FUNC void evalTo(Dest& dst) const - { - // FIXME investigate how to allow lazy evaluation of this product when possible - dst = Block<const LhsMatrixTypeNested, - LhsMatrixTypeNested::RowsAtCompileTime, - LhsMatrixTypeNested::ColsAtCompileTime==Dynamic?Dynamic:LhsMatrixTypeNested::ColsAtCompileTime-1> - (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs; - dst += m_lhs.col(m_lhs.cols()-1).rowwise() - .template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols()); - } - - typename LhsMatrixTypeCleaned::Nested m_lhs; - typename MatrixType::Nested m_rhs; -}; - -template<typename MatrixType,typename Rhs> -struct traits<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> > -{ - typedef typename make_proper_matrix_type<typename traits<MatrixType>::Scalar, - MatrixType::RowsAtCompileTime, - Rhs::ColsAtCompileTime, - MatrixType::PlainObject::Options, - MatrixType::MaxRowsAtCompileTime, - Rhs::MaxColsAtCompileTime>::type ReturnType; -}; - -template<typename MatrixType,typename Rhs> -struct homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> - : public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> > -{ - typedef typename remove_all<typename Rhs::Nested>::type RhsNested; - EIGEN_DEVICE_FUNC homogeneous_right_product_impl(const MatrixType& lhs, const Rhs& rhs) - : m_lhs(lhs), m_rhs(rhs) - {} - - EIGEN_DEVICE_FUNC inline Index rows() const { return m_lhs.rows(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_rhs.cols(); } - - template<typename Dest> EIGEN_DEVICE_FUNC void evalTo(Dest& dst) const - { - // FIXME investigate how to allow lazy evaluation of this product when possible - dst = m_lhs * Block<const RhsNested, - RhsNested::RowsAtCompileTime==Dynamic?Dynamic:RhsNested::RowsAtCompileTime-1, - RhsNested::ColsAtCompileTime> - (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols()); - dst += m_rhs.row(m_rhs.rows()-1).colwise() - .template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows()); - } - - typename MatrixType::Nested m_lhs; - typename Rhs::Nested m_rhs; -}; - -template<typename ArgType,int Direction> -struct evaluator_traits<Homogeneous<ArgType,Direction> > -{ - typedef typename storage_kind_to_evaluator_kind<typename ArgType::StorageKind>::Kind Kind; - typedef HomogeneousShape Shape; -}; - -template<> struct AssignmentKind<DenseShape,HomogeneousShape> { typedef Dense2Dense Kind; }; - - -template<typename ArgType,int Direction> -struct unary_evaluator<Homogeneous<ArgType,Direction>, IndexBased> - : evaluator<typename Homogeneous<ArgType,Direction>::PlainObject > -{ - typedef Homogeneous<ArgType,Direction> XprType; - typedef typename XprType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - - EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& op) - : Base(), m_temp(op) - { - ::new (static_cast<Base*>(this)) Base(m_temp); - } - -protected: - PlainObject m_temp; -}; - -// dense = homogeneous -template< typename DstXprType, typename ArgType, typename Scalar> -struct Assignment<DstXprType, Homogeneous<ArgType,Vertical>, internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense> -{ - typedef Homogeneous<ArgType,Vertical> SrcXprType; - EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename ArgType::Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression(); - dst.row(dst.rows()-1).setOnes(); - } -}; - -// dense = homogeneous -template< typename DstXprType, typename ArgType, typename Scalar> -struct Assignment<DstXprType, Homogeneous<ArgType,Horizontal>, internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense> -{ - typedef Homogeneous<ArgType,Horizontal> SrcXprType; - EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename ArgType::Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression(); - dst.col(dst.cols()-1).setOnes(); - } -}; - -template<typename LhsArg, typename Rhs, int ProductTag> -struct generic_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs, HomogeneousShape, DenseShape, ProductTag> -{ - template<typename Dest> - EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const Homogeneous<LhsArg,Horizontal>& lhs, const Rhs& rhs) - { - homogeneous_right_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs>(lhs.nestedExpression(), rhs).evalTo(dst); - } -}; - -template<typename Lhs,typename Rhs> -struct homogeneous_right_product_refactoring_helper -{ - enum { - Dim = Lhs::ColsAtCompileTime, - Rows = Lhs::RowsAtCompileTime - }; - typedef typename Rhs::template ConstNRowsBlockXpr<Dim>::Type LinearBlockConst; - typedef typename remove_const<LinearBlockConst>::type LinearBlock; - typedef typename Rhs::ConstRowXpr ConstantColumn; - typedef Replicate<const ConstantColumn,Rows,1> ConstantBlock; - typedef Product<Lhs,LinearBlock,LazyProduct> LinearProduct; - typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr; -}; - -template<typename Lhs, typename Rhs, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, HomogeneousShape, DenseShape> - : public evaluator<typename homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs>::Xpr> -{ - typedef Product<Lhs, Rhs, LazyProduct> XprType; - typedef homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs> helper; - typedef typename helper::ConstantBlock ConstantBlock; - typedef typename helper::Xpr RefactoredXpr; - typedef evaluator<RefactoredXpr> Base; - - EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) - : Base( xpr.lhs().nestedExpression() .lazyProduct( xpr.rhs().template topRows<helper::Dim>(xpr.lhs().nestedExpression().cols()) ) - + ConstantBlock(xpr.rhs().row(xpr.rhs().rows()-1),xpr.lhs().rows(), 1) ) - {} -}; - -template<typename Lhs, typename RhsArg, int ProductTag> -struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag> -{ - template<typename Dest> - EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const Lhs& lhs, const Homogeneous<RhsArg,Vertical>& rhs) - { - homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, Lhs>(lhs, rhs.nestedExpression()).evalTo(dst); - } -}; - -// TODO: the following specialization is to address a regression from 3.2 to 3.3 -// In the future, this path should be optimized. -template<typename Lhs, typename RhsArg, int ProductTag> -struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, TriangularShape, HomogeneousShape, ProductTag> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Homogeneous<RhsArg,Vertical>& rhs) - { - dst.noalias() = lhs * rhs.eval(); - } -}; - -template<typename Lhs,typename Rhs> -struct homogeneous_left_product_refactoring_helper -{ - enum { - Dim = Rhs::RowsAtCompileTime, - Cols = Rhs::ColsAtCompileTime - }; - typedef typename Lhs::template ConstNColsBlockXpr<Dim>::Type LinearBlockConst; - typedef typename remove_const<LinearBlockConst>::type LinearBlock; - typedef typename Lhs::ConstColXpr ConstantColumn; - typedef Replicate<const ConstantColumn,1,Cols> ConstantBlock; - typedef Product<LinearBlock,Rhs,LazyProduct> LinearProduct; - typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr; -}; - -template<typename Lhs, typename Rhs, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, HomogeneousShape> - : public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression>::Xpr> -{ - typedef Product<Lhs, Rhs, LazyProduct> XprType; - typedef homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression> helper; - typedef typename helper::ConstantBlock ConstantBlock; - typedef typename helper::Xpr RefactoredXpr; - typedef evaluator<RefactoredXpr> Base; - - EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) - : Base( xpr.lhs().template leftCols<helper::Dim>(xpr.rhs().nestedExpression().rows()) .lazyProduct( xpr.rhs().nestedExpression() ) - + ConstantBlock(xpr.lhs().col(xpr.lhs().cols()-1),1,xpr.rhs().cols()) ) - {} -}; - -template<typename Scalar, int Dim, int Mode,int Options, typename RhsArg, int ProductTag> -struct generic_product_impl<Transform<Scalar,Dim,Mode,Options>, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag> -{ - typedef Transform<Scalar,Dim,Mode,Options> TransformType; - template<typename Dest> - EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const TransformType& lhs, const Homogeneous<RhsArg,Vertical>& rhs) - { - homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, TransformType>(lhs, rhs.nestedExpression()).evalTo(dst); - } -}; - -template<typename ExpressionType, int Side, bool Transposed> -struct permutation_matrix_product<ExpressionType, Side, Transposed, HomogeneousShape> - : public permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape> -{}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_HOMOGENEOUS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/Hyperplane.h b/external/eigen/include/eigen3/Eigen/src/Geometry/Hyperplane.h deleted file mode 100644 index cebe0355..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/Hyperplane.h +++ /dev/null @@ -1,282 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_HYPERPLANE_H -#define EIGEN_HYPERPLANE_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * \class Hyperplane - * - * \brief A hyperplane - * - * A hyperplane is an affine subspace of dimension n-1 in a space of dimension n. - * For example, a hyperplane in a plane is a line; a hyperplane in 3-space is a plane. - * - * \tparam _Scalar the scalar type, i.e., the type of the coefficients - * \tparam _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic. - * Notice that the dimension of the hyperplane is _AmbientDim-1. - * - * This class represents an hyperplane as the zero set of the implicit equation - * \f$ n \cdot x + d = 0 \f$ where \f$ n \f$ is a unit normal vector of the plane (linear part) - * and \f$ d \f$ is the distance (offset) to the origin. - */ -template <typename _Scalar, int _AmbientDim, int _Options> -class Hyperplane -{ -public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim==Dynamic ? Dynamic : _AmbientDim+1) - enum { - AmbientDimAtCompileTime = _AmbientDim, - Options = _Options - }; - typedef _Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType; - typedef Matrix<Scalar,Index(AmbientDimAtCompileTime)==Dynamic - ? Dynamic - : Index(AmbientDimAtCompileTime)+1,1,Options> Coefficients; - typedef Block<Coefficients,AmbientDimAtCompileTime,1> NormalReturnType; - typedef const Block<const Coefficients,AmbientDimAtCompileTime,1> ConstNormalReturnType; - - /** Default constructor without initialization */ - EIGEN_DEVICE_FUNC inline Hyperplane() {} - - template<int OtherOptions> - EIGEN_DEVICE_FUNC Hyperplane(const Hyperplane<Scalar,AmbientDimAtCompileTime,OtherOptions>& other) - : m_coeffs(other.coeffs()) - {} - - /** Constructs a dynamic-size hyperplane with \a _dim the dimension - * of the ambient space */ - EIGEN_DEVICE_FUNC inline explicit Hyperplane(Index _dim) : m_coeffs(_dim+1) {} - - /** Construct a plane from its normal \a n and a point \a e onto the plane. - * \warning the vector normal is assumed to be normalized. - */ - EIGEN_DEVICE_FUNC inline Hyperplane(const VectorType& n, const VectorType& e) - : m_coeffs(n.size()+1) - { - normal() = n; - offset() = -n.dot(e); - } - - /** Constructs a plane from its normal \a n and distance to the origin \a d - * such that the algebraic equation of the plane is \f$ n \cdot x + d = 0 \f$. - * \warning the vector normal is assumed to be normalized. - */ - EIGEN_DEVICE_FUNC inline Hyperplane(const VectorType& n, const Scalar& d) - : m_coeffs(n.size()+1) - { - normal() = n; - offset() = d; - } - - /** Constructs a hyperplane passing through the two points. If the dimension of the ambient space - * is greater than 2, then there isn't uniqueness, so an arbitrary choice is made. - */ - EIGEN_DEVICE_FUNC static inline Hyperplane Through(const VectorType& p0, const VectorType& p1) - { - Hyperplane result(p0.size()); - result.normal() = (p1 - p0).unitOrthogonal(); - result.offset() = -p0.dot(result.normal()); - return result; - } - - /** Constructs a hyperplane passing through the three points. The dimension of the ambient space - * is required to be exactly 3. - */ - EIGEN_DEVICE_FUNC static inline Hyperplane Through(const VectorType& p0, const VectorType& p1, const VectorType& p2) - { - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 3) - Hyperplane result(p0.size()); - VectorType v0(p2 - p0), v1(p1 - p0); - result.normal() = v0.cross(v1); - RealScalar norm = result.normal().norm(); - if(norm <= v0.norm() * v1.norm() * NumTraits<RealScalar>::epsilon()) - { - Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose(); - JacobiSVD<Matrix<Scalar,2,3> > svd(m, ComputeFullV); - result.normal() = svd.matrixV().col(2); - } - else - result.normal() /= norm; - result.offset() = -p0.dot(result.normal()); - return result; - } - - /** Constructs a hyperplane passing through the parametrized line \a parametrized. - * If the dimension of the ambient space is greater than 2, then there isn't uniqueness, - * so an arbitrary choice is made. - */ - // FIXME to be consistent with the rest this could be implemented as a static Through function ?? - EIGEN_DEVICE_FUNC explicit Hyperplane(const ParametrizedLine<Scalar, AmbientDimAtCompileTime>& parametrized) - { - normal() = parametrized.direction().unitOrthogonal(); - offset() = -parametrized.origin().dot(normal()); - } - - EIGEN_DEVICE_FUNC ~Hyperplane() {} - - /** \returns the dimension in which the plane holds */ - EIGEN_DEVICE_FUNC inline Index dim() const { return AmbientDimAtCompileTime==Dynamic ? m_coeffs.size()-1 : Index(AmbientDimAtCompileTime); } - - /** normalizes \c *this */ - EIGEN_DEVICE_FUNC void normalize(void) - { - m_coeffs /= normal().norm(); - } - - /** \returns the signed distance between the plane \c *this and a point \a p. - * \sa absDistance() - */ - EIGEN_DEVICE_FUNC inline Scalar signedDistance(const VectorType& p) const { return normal().dot(p) + offset(); } - - /** \returns the absolute distance between the plane \c *this and a point \a p. - * \sa signedDistance() - */ - EIGEN_DEVICE_FUNC inline Scalar absDistance(const VectorType& p) const { return numext::abs(signedDistance(p)); } - - /** \returns the projection of a point \a p onto the plane \c *this. - */ - EIGEN_DEVICE_FUNC inline VectorType projection(const VectorType& p) const { return p - signedDistance(p) * normal(); } - - /** \returns a constant reference to the unit normal vector of the plane, which corresponds - * to the linear part of the implicit equation. - */ - EIGEN_DEVICE_FUNC inline ConstNormalReturnType normal() const { return ConstNormalReturnType(m_coeffs,0,0,dim(),1); } - - /** \returns a non-constant reference to the unit normal vector of the plane, which corresponds - * to the linear part of the implicit equation. - */ - EIGEN_DEVICE_FUNC inline NormalReturnType normal() { return NormalReturnType(m_coeffs,0,0,dim(),1); } - - /** \returns the distance to the origin, which is also the "constant term" of the implicit equation - * \warning the vector normal is assumed to be normalized. - */ - EIGEN_DEVICE_FUNC inline const Scalar& offset() const { return m_coeffs.coeff(dim()); } - - /** \returns a non-constant reference to the distance to the origin, which is also the constant part - * of the implicit equation */ - EIGEN_DEVICE_FUNC inline Scalar& offset() { return m_coeffs(dim()); } - - /** \returns a constant reference to the coefficients c_i of the plane equation: - * \f$ c_0*x_0 + ... + c_{d-1}*x_{d-1} + c_d = 0 \f$ - */ - EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs; } - - /** \returns a non-constant reference to the coefficients c_i of the plane equation: - * \f$ c_0*x_0 + ... + c_{d-1}*x_{d-1} + c_d = 0 \f$ - */ - EIGEN_DEVICE_FUNC inline Coefficients& coeffs() { return m_coeffs; } - - /** \returns the intersection of *this with \a other. - * - * \warning The ambient space must be a plane, i.e. have dimension 2, so that \c *this and \a other are lines. - * - * \note If \a other is approximately parallel to *this, this method will return any point on *this. - */ - EIGEN_DEVICE_FUNC VectorType intersection(const Hyperplane& other) const - { - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2) - Scalar det = coeffs().coeff(0) * other.coeffs().coeff(1) - coeffs().coeff(1) * other.coeffs().coeff(0); - // since the line equations ax+by=c are normalized with a^2+b^2=1, the following tests - // whether the two lines are approximately parallel. - if(internal::isMuchSmallerThan(det, Scalar(1))) - { // special case where the two lines are approximately parallel. Pick any point on the first line. - if(numext::abs(coeffs().coeff(1))>numext::abs(coeffs().coeff(0))) - return VectorType(coeffs().coeff(1), -coeffs().coeff(2)/coeffs().coeff(1)-coeffs().coeff(0)); - else - return VectorType(-coeffs().coeff(2)/coeffs().coeff(0)-coeffs().coeff(1), coeffs().coeff(0)); - } - else - { // general case - Scalar invdet = Scalar(1) / det; - return VectorType(invdet*(coeffs().coeff(1)*other.coeffs().coeff(2)-other.coeffs().coeff(1)*coeffs().coeff(2)), - invdet*(other.coeffs().coeff(0)*coeffs().coeff(2)-coeffs().coeff(0)*other.coeffs().coeff(2))); - } - } - - /** Applies the transformation matrix \a mat to \c *this and returns a reference to \c *this. - * - * \param mat the Dim x Dim transformation matrix - * \param traits specifies whether the matrix \a mat represents an #Isometry - * or a more generic #Affine transformation. The default is #Affine. - */ - template<typename XprType> - EIGEN_DEVICE_FUNC inline Hyperplane& transform(const MatrixBase<XprType>& mat, TransformTraits traits = Affine) - { - if (traits==Affine) - { - normal() = mat.inverse().transpose() * normal(); - m_coeffs /= normal().norm(); - } - else if (traits==Isometry) - normal() = mat * normal(); - else - { - eigen_assert(0 && "invalid traits value in Hyperplane::transform()"); - } - return *this; - } - - /** Applies the transformation \a t to \c *this and returns a reference to \c *this. - * - * \param t the transformation of dimension Dim - * \param traits specifies whether the transformation \a t represents an #Isometry - * or a more generic #Affine transformation. The default is #Affine. - * Other kind of transformations are not supported. - */ - template<int TrOptions> - EIGEN_DEVICE_FUNC inline Hyperplane& transform(const Transform<Scalar,AmbientDimAtCompileTime,Affine,TrOptions>& t, - TransformTraits traits = Affine) - { - transform(t.linear(), traits); - offset() -= normal().dot(t.translation()); - return *this; - } - - /** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Hyperplane, - Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type cast() const - { - return typename internal::cast_return_type<Hyperplane, - Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*this); - } - - /** Copy constructor with scalar type conversion */ - template<typename OtherScalarType,int OtherOptions> - EIGEN_DEVICE_FUNC inline explicit Hyperplane(const Hyperplane<OtherScalarType,AmbientDimAtCompileTime,OtherOptions>& other) - { m_coeffs = other.coeffs().template cast<Scalar>(); } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - template<int OtherOptions> - EIGEN_DEVICE_FUNC bool isApprox(const Hyperplane<Scalar,AmbientDimAtCompileTime,OtherOptions>& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const - { return m_coeffs.isApprox(other.m_coeffs, prec); } - -protected: - - Coefficients m_coeffs; -}; - -} // end namespace Eigen - -#endif // EIGEN_HYPERPLANE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/OrthoMethods.h b/external/eigen/include/eigen3/Eigen/src/Geometry/OrthoMethods.h deleted file mode 100644 index 524aebe1..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/OrthoMethods.h +++ /dev/null @@ -1,235 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ORTHOMETHODS_H -#define EIGEN_ORTHOMETHODS_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * \returns the cross product of \c *this and \a other - * - * Here is a very good explanation of cross-product: http://xkcd.com/199/ - * - * With complex numbers, the cross product is implemented as - * \f$ (\mathbf{a}+i\mathbf{b}) \times (\mathbf{c}+i\mathbf{d}) = (\mathbf{a} \times \mathbf{c} - \mathbf{b} \times \mathbf{d}) - i(\mathbf{a} \times \mathbf{d} - \mathbf{b} \times \mathbf{c})\f$ - * - * \sa MatrixBase::cross3() - */ -template<typename Derived> -template<typename OtherDerived> -#ifndef EIGEN_PARSED_BY_DOXYGEN -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type -#else -typename MatrixBase<Derived>::PlainObject -#endif -MatrixBase<Derived>::cross(const MatrixBase<OtherDerived>& other) const -{ - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3) - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3) - - // Note that there is no need for an expression here since the compiler - // optimize such a small temporary very well (even within a complex expression) - typename internal::nested_eval<Derived,2>::type lhs(derived()); - typename internal::nested_eval<OtherDerived,2>::type rhs(other.derived()); - return typename cross_product_return_type<OtherDerived>::type( - numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)), - numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)), - numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)) - ); -} - -namespace internal { - -template< int Arch,typename VectorLhs,typename VectorRhs, - typename Scalar = typename VectorLhs::Scalar, - bool Vectorizable = bool((VectorLhs::Flags&VectorRhs::Flags)&PacketAccessBit)> -struct cross3_impl { - EIGEN_DEVICE_FUNC static inline typename internal::plain_matrix_type<VectorLhs>::type - run(const VectorLhs& lhs, const VectorRhs& rhs) - { - return typename internal::plain_matrix_type<VectorLhs>::type( - numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)), - numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)), - numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)), - 0 - ); - } -}; - -} - -/** \geometry_module \ingroup Geometry_Module - * - * \returns the cross product of \c *this and \a other using only the x, y, and z coefficients - * - * The size of \c *this and \a other must be four. This function is especially useful - * when using 4D vectors instead of 3D ones to get advantage of SSE/AltiVec vectorization. - * - * \sa MatrixBase::cross() - */ -template<typename Derived> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::PlainObject -MatrixBase<Derived>::cross3(const MatrixBase<OtherDerived>& other) const -{ - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,4) - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,4) - - typedef typename internal::nested_eval<Derived,2>::type DerivedNested; - typedef typename internal::nested_eval<OtherDerived,2>::type OtherDerivedNested; - DerivedNested lhs(derived()); - OtherDerivedNested rhs(other.derived()); - - return internal::cross3_impl<Architecture::Target, - typename internal::remove_all<DerivedNested>::type, - typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs); -} - -/** \geometry_module \ingroup Geometry_Module - * - * \returns a matrix expression of the cross product of each column or row - * of the referenced expression with the \a other vector. - * - * The referenced matrix must have one dimension equal to 3. - * The result matrix has the same dimensions than the referenced one. - * - * \sa MatrixBase::cross() */ -template<typename ExpressionType, int Direction> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -const typename VectorwiseOp<ExpressionType,Direction>::CrossReturnType -VectorwiseOp<ExpressionType,Direction>::cross(const MatrixBase<OtherDerived>& other) const -{ - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3) - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - - typename internal::nested_eval<ExpressionType,2>::type mat(_expression()); - typename internal::nested_eval<OtherDerived,2>::type vec(other.derived()); - - CrossReturnType res(_expression().rows(),_expression().cols()); - if(Direction==Vertical) - { - eigen_assert(CrossReturnType::RowsAtCompileTime==3 && "the matrix must have exactly 3 rows"); - res.row(0) = (mat.row(1) * vec.coeff(2) - mat.row(2) * vec.coeff(1)).conjugate(); - res.row(1) = (mat.row(2) * vec.coeff(0) - mat.row(0) * vec.coeff(2)).conjugate(); - res.row(2) = (mat.row(0) * vec.coeff(1) - mat.row(1) * vec.coeff(0)).conjugate(); - } - else - { - eigen_assert(CrossReturnType::ColsAtCompileTime==3 && "the matrix must have exactly 3 columns"); - res.col(0) = (mat.col(1) * vec.coeff(2) - mat.col(2) * vec.coeff(1)).conjugate(); - res.col(1) = (mat.col(2) * vec.coeff(0) - mat.col(0) * vec.coeff(2)).conjugate(); - res.col(2) = (mat.col(0) * vec.coeff(1) - mat.col(1) * vec.coeff(0)).conjugate(); - } - return res; -} - -namespace internal { - -template<typename Derived, int Size = Derived::SizeAtCompileTime> -struct unitOrthogonal_selector -{ - typedef typename plain_matrix_type<Derived>::type VectorType; - typedef typename traits<Derived>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Matrix<Scalar,2,1> Vector2; - EIGEN_DEVICE_FUNC - static inline VectorType run(const Derived& src) - { - VectorType perp = VectorType::Zero(src.size()); - Index maxi = 0; - Index sndi = 0; - src.cwiseAbs().maxCoeff(&maxi); - if (maxi==0) - sndi = 1; - RealScalar invnm = RealScalar(1)/(Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm(); - perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm; - perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm; - - return perp; - } -}; - -template<typename Derived> -struct unitOrthogonal_selector<Derived,3> -{ - typedef typename plain_matrix_type<Derived>::type VectorType; - typedef typename traits<Derived>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - EIGEN_DEVICE_FUNC - static inline VectorType run(const Derived& src) - { - VectorType perp; - /* Let us compute the crossed product of *this with a vector - * that is not too close to being colinear to *this. - */ - - /* unless the x and y coords are both close to zero, we can - * simply take ( -y, x, 0 ) and normalize it. - */ - if((!isMuchSmallerThan(src.x(), src.z())) - || (!isMuchSmallerThan(src.y(), src.z()))) - { - RealScalar invnm = RealScalar(1)/src.template head<2>().norm(); - perp.coeffRef(0) = -numext::conj(src.y())*invnm; - perp.coeffRef(1) = numext::conj(src.x())*invnm; - perp.coeffRef(2) = 0; - } - /* if both x and y are close to zero, then the vector is close - * to the z-axis, so it's far from colinear to the x-axis for instance. - * So we take the crossed product with (1,0,0) and normalize it. - */ - else - { - RealScalar invnm = RealScalar(1)/src.template tail<2>().norm(); - perp.coeffRef(0) = 0; - perp.coeffRef(1) = -numext::conj(src.z())*invnm; - perp.coeffRef(2) = numext::conj(src.y())*invnm; - } - - return perp; - } -}; - -template<typename Derived> -struct unitOrthogonal_selector<Derived,2> -{ - typedef typename plain_matrix_type<Derived>::type VectorType; - EIGEN_DEVICE_FUNC - static inline VectorType run(const Derived& src) - { return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized(); } -}; - -} // end namespace internal - -/** \geometry_module \ingroup Geometry_Module - * - * \returns a unit vector which is orthogonal to \c *this - * - * The size of \c *this must be at least 2. If the size is exactly 2, - * then the returned vector is a counter clock wise rotation of \c *this, i.e., (-y,x).normalized(). - * - * \sa cross() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC typename MatrixBase<Derived>::PlainObject -MatrixBase<Derived>::unitOrthogonal() const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return internal::unitOrthogonal_selector<Derived>::run(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_ORTHOMETHODS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/ParametrizedLine.h b/external/eigen/include/eigen3/Eigen/src/Geometry/ParametrizedLine.h deleted file mode 100644 index 3929ca87..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/ParametrizedLine.h +++ /dev/null @@ -1,232 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PARAMETRIZEDLINE_H -#define EIGEN_PARAMETRIZEDLINE_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * \class ParametrizedLine - * - * \brief A parametrized line - * - * A parametrized line is defined by an origin point \f$ \mathbf{o} \f$ and a unit - * direction vector \f$ \mathbf{d} \f$ such that the line corresponds to - * the set \f$ l(t) = \mathbf{o} + t \mathbf{d} \f$, \f$ t \in \mathbf{R} \f$. - * - * \tparam _Scalar the scalar type, i.e., the type of the coefficients - * \tparam _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic. - */ -template <typename _Scalar, int _AmbientDim, int _Options> -class ParametrizedLine -{ -public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim) - enum { - AmbientDimAtCompileTime = _AmbientDim, - Options = _Options - }; - typedef _Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - typedef Matrix<Scalar,AmbientDimAtCompileTime,1,Options> VectorType; - - /** Default constructor without initialization */ - EIGEN_DEVICE_FUNC inline ParametrizedLine() {} - - template<int OtherOptions> - EIGEN_DEVICE_FUNC ParametrizedLine(const ParametrizedLine<Scalar,AmbientDimAtCompileTime,OtherOptions>& other) - : m_origin(other.origin()), m_direction(other.direction()) - {} - - /** Constructs a dynamic-size line with \a _dim the dimension - * of the ambient space */ - EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(Index _dim) : m_origin(_dim), m_direction(_dim) {} - - /** Initializes a parametrized line of direction \a direction and origin \a origin. - * \warning the vector direction is assumed to be normalized. - */ - EIGEN_DEVICE_FUNC ParametrizedLine(const VectorType& origin, const VectorType& direction) - : m_origin(origin), m_direction(direction) {} - - template <int OtherOptions> - EIGEN_DEVICE_FUNC explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane); - - /** Constructs a parametrized line going from \a p0 to \a p1. */ - EIGEN_DEVICE_FUNC static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1) - { return ParametrizedLine(p0, (p1-p0).normalized()); } - - EIGEN_DEVICE_FUNC ~ParametrizedLine() {} - - /** \returns the dimension in which the line holds */ - EIGEN_DEVICE_FUNC inline Index dim() const { return m_direction.size(); } - - EIGEN_DEVICE_FUNC const VectorType& origin() const { return m_origin; } - EIGEN_DEVICE_FUNC VectorType& origin() { return m_origin; } - - EIGEN_DEVICE_FUNC const VectorType& direction() const { return m_direction; } - EIGEN_DEVICE_FUNC VectorType& direction() { return m_direction; } - - /** \returns the squared distance of a point \a p to its projection onto the line \c *this. - * \sa distance() - */ - EIGEN_DEVICE_FUNC RealScalar squaredDistance(const VectorType& p) const - { - VectorType diff = p - origin(); - return (diff - direction().dot(diff) * direction()).squaredNorm(); - } - /** \returns the distance of a point \a p to its projection onto the line \c *this. - * \sa squaredDistance() - */ - EIGEN_DEVICE_FUNC RealScalar distance(const VectorType& p) const { EIGEN_USING_STD_MATH(sqrt) return sqrt(squaredDistance(p)); } - - /** \returns the projection of a point \a p onto the line \c *this. */ - EIGEN_DEVICE_FUNC VectorType projection(const VectorType& p) const - { return origin() + direction().dot(p-origin()) * direction(); } - - EIGEN_DEVICE_FUNC VectorType pointAt(const Scalar& t) const; - - template <int OtherOptions> - EIGEN_DEVICE_FUNC Scalar intersectionParameter(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const; - - template <int OtherOptions> - EIGEN_DEVICE_FUNC Scalar intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const; - - template <int OtherOptions> - EIGEN_DEVICE_FUNC VectorType intersectionPoint(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const; - - /** Applies the transformation matrix \a mat to \c *this and returns a reference to \c *this. - * - * \param mat the Dim x Dim transformation matrix - * \param traits specifies whether the matrix \a mat represents an #Isometry - * or a more generic #Affine transformation. The default is #Affine. - */ - template<typename XprType> - EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(const MatrixBase<XprType>& mat, TransformTraits traits = Affine) - { - if (traits==Affine) - direction() = (mat * direction()).normalized(); - else if (traits==Isometry) - direction() = mat * direction(); - else - { - eigen_assert(0 && "invalid traits value in ParametrizedLine::transform()"); - } - origin() = mat * origin(); - return *this; - } - - /** Applies the transformation \a t to \c *this and returns a reference to \c *this. - * - * \param t the transformation of dimension Dim - * \param traits specifies whether the transformation \a t represents an #Isometry - * or a more generic #Affine transformation. The default is #Affine. - * Other kind of transformations are not supported. - */ - template<int TrOptions> - EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(const Transform<Scalar,AmbientDimAtCompileTime,Affine,TrOptions>& t, - TransformTraits traits = Affine) - { - transform(t.linear(), traits); - origin() += t.translation(); - return *this; - } - -/** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<ParametrizedLine, - ParametrizedLine<NewScalarType,AmbientDimAtCompileTime,Options> >::type cast() const - { - return typename internal::cast_return_type<ParametrizedLine, - ParametrizedLine<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*this); - } - - /** Copy constructor with scalar type conversion */ - template<typename OtherScalarType,int OtherOptions> - EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(const ParametrizedLine<OtherScalarType,AmbientDimAtCompileTime,OtherOptions>& other) - { - m_origin = other.origin().template cast<Scalar>(); - m_direction = other.direction().template cast<Scalar>(); - } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - EIGEN_DEVICE_FUNC bool isApprox(const ParametrizedLine& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const - { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); } - -protected: - - VectorType m_origin, m_direction; -}; - -/** Constructs a parametrized line from a 2D hyperplane - * - * \warning the ambient space must have dimension 2 such that the hyperplane actually describes a line - */ -template <typename _Scalar, int _AmbientDim, int _Options> -template <int OtherOptions> -EIGEN_DEVICE_FUNC inline ParametrizedLine<_Scalar, _AmbientDim,_Options>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim,OtherOptions>& hyperplane) -{ - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2) - direction() = hyperplane.normal().unitOrthogonal(); - origin() = -hyperplane.normal()*hyperplane.offset(); -} - -/** \returns the point at \a t along this line - */ -template <typename _Scalar, int _AmbientDim, int _Options> -EIGEN_DEVICE_FUNC inline typename ParametrizedLine<_Scalar, _AmbientDim,_Options>::VectorType -ParametrizedLine<_Scalar, _AmbientDim,_Options>::pointAt(const _Scalar& t) const -{ - return origin() + (direction()*t); -} - -/** \returns the parameter value of the intersection between \c *this and the given \a hyperplane - */ -template <typename _Scalar, int _AmbientDim, int _Options> -template <int OtherOptions> -EIGEN_DEVICE_FUNC inline _Scalar ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersectionParameter(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const -{ - return -(hyperplane.offset()+hyperplane.normal().dot(origin())) - / hyperplane.normal().dot(direction()); -} - - -/** \deprecated use intersectionParameter() - * \returns the parameter value of the intersection between \c *this and the given \a hyperplane - */ -template <typename _Scalar, int _AmbientDim, int _Options> -template <int OtherOptions> -EIGEN_DEVICE_FUNC inline _Scalar ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const -{ - return intersectionParameter(hyperplane); -} - -/** \returns the point of the intersection between \c *this and the given hyperplane - */ -template <typename _Scalar, int _AmbientDim, int _Options> -template <int OtherOptions> -EIGEN_DEVICE_FUNC inline typename ParametrizedLine<_Scalar, _AmbientDim,_Options>::VectorType -ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersectionPoint(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const -{ - return pointAt(intersectionParameter(hyperplane)); -} - -} // end namespace Eigen - -#endif // EIGEN_PARAMETRIZEDLINE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/Quaternion.h b/external/eigen/include/eigen3/Eigen/src/Geometry/Quaternion.h deleted file mode 100644 index 7b2c4d89..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/Quaternion.h +++ /dev/null @@ -1,847 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Mathieu Gautier <mathieu.gautier@cea.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_QUATERNION_H -#define EIGEN_QUATERNION_H -namespace Eigen { - - -/*************************************************************************** -* Definition of QuaternionBase<Derived> -* The implementation is at the end of the file -***************************************************************************/ - -namespace internal { -template<typename Other, - int OtherRows=Other::RowsAtCompileTime, - int OtherCols=Other::ColsAtCompileTime> -struct quaternionbase_assign_impl; -} - -/** \geometry_module \ingroup Geometry_Module - * \class QuaternionBase - * \brief Base class for quaternion expressions - * \tparam Derived derived type (CRTP) - * \sa class Quaternion - */ -template<class Derived> -class QuaternionBase : public RotationBase<Derived, 3> -{ - public: - typedef RotationBase<Derived, 3> Base; - - using Base::operator*; - using Base::derived; - - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef typename internal::traits<Derived>::Coefficients Coefficients; - typedef typename Coefficients::CoeffReturnType CoeffReturnType; - typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&LvalueBit), - Scalar&, CoeffReturnType>::type NonConstCoeffReturnType; - - - enum { - Flags = Eigen::internal::traits<Derived>::Flags - }; - - // typedef typename Matrix<Scalar,4,1> Coefficients; - /** the type of a 3D vector */ - typedef Matrix<Scalar,3,1> Vector3; - /** the equivalent rotation matrix type */ - typedef Matrix<Scalar,3,3> Matrix3; - /** the equivalent angle-axis type */ - typedef AngleAxis<Scalar> AngleAxisType; - - - - /** \returns the \c x coefficient */ - EIGEN_DEVICE_FUNC inline CoeffReturnType x() const { return this->derived().coeffs().coeff(0); } - /** \returns the \c y coefficient */ - EIGEN_DEVICE_FUNC inline CoeffReturnType y() const { return this->derived().coeffs().coeff(1); } - /** \returns the \c z coefficient */ - EIGEN_DEVICE_FUNC inline CoeffReturnType z() const { return this->derived().coeffs().coeff(2); } - /** \returns the \c w coefficient */ - EIGEN_DEVICE_FUNC inline CoeffReturnType w() const { return this->derived().coeffs().coeff(3); } - - /** \returns a reference to the \c x coefficient (if Derived is a non-const lvalue) */ - EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType x() { return this->derived().coeffs().x(); } - /** \returns a reference to the \c y coefficient (if Derived is a non-const lvalue) */ - EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType y() { return this->derived().coeffs().y(); } - /** \returns a reference to the \c z coefficient (if Derived is a non-const lvalue) */ - EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType z() { return this->derived().coeffs().z(); } - /** \returns a reference to the \c w coefficient (if Derived is a non-const lvalue) */ - EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType w() { return this->derived().coeffs().w(); } - - /** \returns a read-only vector expression of the imaginary part (x,y,z) */ - EIGEN_DEVICE_FUNC inline const VectorBlock<const Coefficients,3> vec() const { return coeffs().template head<3>(); } - - /** \returns a vector expression of the imaginary part (x,y,z) */ - EIGEN_DEVICE_FUNC inline VectorBlock<Coefficients,3> vec() { return coeffs().template head<3>(); } - - /** \returns a read-only vector expression of the coefficients (x,y,z,w) */ - EIGEN_DEVICE_FUNC inline const typename internal::traits<Derived>::Coefficients& coeffs() const { return derived().coeffs(); } - - /** \returns a vector expression of the coefficients (x,y,z,w) */ - EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Coefficients& coeffs() { return derived().coeffs(); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE QuaternionBase<Derived>& operator=(const QuaternionBase<Derived>& other); - template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const QuaternionBase<OtherDerived>& other); - -// disabled this copy operator as it is giving very strange compilation errors when compiling -// test_stdvector with GCC 4.4.2. This looks like a GCC bug though, so feel free to re-enable it if it's -// useful; however notice that we already have the templated operator= above and e.g. in MatrixBase -// we didn't have to add, in addition to templated operator=, such a non-templated copy operator. -// Derived& operator=(const QuaternionBase& other) -// { return operator=<Derived>(other); } - - EIGEN_DEVICE_FUNC Derived& operator=(const AngleAxisType& aa); - template<class OtherDerived> EIGEN_DEVICE_FUNC Derived& operator=(const MatrixBase<OtherDerived>& m); - - /** \returns a quaternion representing an identity rotation - * \sa MatrixBase::Identity() - */ - EIGEN_DEVICE_FUNC static inline Quaternion<Scalar> Identity() { return Quaternion<Scalar>(Scalar(1), Scalar(0), Scalar(0), Scalar(0)); } - - /** \sa QuaternionBase::Identity(), MatrixBase::setIdentity() - */ - EIGEN_DEVICE_FUNC inline QuaternionBase& setIdentity() { coeffs() << Scalar(0), Scalar(0), Scalar(0), Scalar(1); return *this; } - - /** \returns the squared norm of the quaternion's coefficients - * \sa QuaternionBase::norm(), MatrixBase::squaredNorm() - */ - EIGEN_DEVICE_FUNC inline Scalar squaredNorm() const { return coeffs().squaredNorm(); } - - /** \returns the norm of the quaternion's coefficients - * \sa QuaternionBase::squaredNorm(), MatrixBase::norm() - */ - EIGEN_DEVICE_FUNC inline Scalar norm() const { return coeffs().norm(); } - - /** Normalizes the quaternion \c *this - * \sa normalized(), MatrixBase::normalize() */ - EIGEN_DEVICE_FUNC inline void normalize() { coeffs().normalize(); } - /** \returns a normalized copy of \c *this - * \sa normalize(), MatrixBase::normalized() */ - EIGEN_DEVICE_FUNC inline Quaternion<Scalar> normalized() const { return Quaternion<Scalar>(coeffs().normalized()); } - - /** \returns the dot product of \c *this and \a other - * Geometrically speaking, the dot product of two unit quaternions - * corresponds to the cosine of half the angle between the two rotations. - * \sa angularDistance() - */ - template<class OtherDerived> EIGEN_DEVICE_FUNC inline Scalar dot(const QuaternionBase<OtherDerived>& other) const { return coeffs().dot(other.coeffs()); } - - template<class OtherDerived> EIGEN_DEVICE_FUNC Scalar angularDistance(const QuaternionBase<OtherDerived>& other) const; - - /** \returns an equivalent 3x3 rotation matrix */ - EIGEN_DEVICE_FUNC Matrix3 toRotationMatrix() const; - - /** \returns the quaternion which transform \a a into \a b through a rotation */ - template<typename Derived1, typename Derived2> - EIGEN_DEVICE_FUNC Derived& setFromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b); - - template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion<Scalar> operator* (const QuaternionBase<OtherDerived>& q) const; - template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*= (const QuaternionBase<OtherDerived>& q); - - /** \returns the quaternion describing the inverse rotation */ - EIGEN_DEVICE_FUNC Quaternion<Scalar> inverse() const; - - /** \returns the conjugated quaternion */ - EIGEN_DEVICE_FUNC Quaternion<Scalar> conjugate() const; - - template<class OtherDerived> EIGEN_DEVICE_FUNC Quaternion<Scalar> slerp(const Scalar& t, const QuaternionBase<OtherDerived>& other) const; - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - template<class OtherDerived> - EIGEN_DEVICE_FUNC bool isApprox(const QuaternionBase<OtherDerived>& other, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const - { return coeffs().isApprox(other.coeffs(), prec); } - - /** return the result vector of \a v through the rotation*/ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Vector3 _transformVector(const Vector3& v) const; - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Derived,Quaternion<NewScalarType> >::type cast() const; - - #else - - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline - typename internal::enable_if<internal::is_same<Scalar,NewScalarType>::value,const Derived&>::type cast() const - { - return derived(); - } - - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline - typename internal::enable_if<!internal::is_same<Scalar,NewScalarType>::value,Quaternion<NewScalarType> >::type cast() const - { - return Quaternion<NewScalarType>(coeffs().template cast<NewScalarType>()); - } - #endif - -#ifdef EIGEN_QUATERNIONBASE_PLUGIN -# include EIGEN_QUATERNIONBASE_PLUGIN -#endif -protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(QuaternionBase) - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(QuaternionBase) -}; - -/*************************************************************************** -* Definition/implementation of Quaternion<Scalar> -***************************************************************************/ - -/** \geometry_module \ingroup Geometry_Module - * - * \class Quaternion - * - * \brief The quaternion class used to represent 3D orientations and rotations - * - * \tparam _Scalar the scalar type, i.e., the type of the coefficients - * \tparam _Options controls the memory alignment of the coefficients. Can be \# AutoAlign or \# DontAlign. Default is AutoAlign. - * - * This class represents a quaternion \f$ w+xi+yj+zk \f$ that is a convenient representation of - * orientations and rotations of objects in three dimensions. Compared to other representations - * like Euler angles or 3x3 matrices, quaternions offer the following advantages: - * \li \b compact storage (4 scalars) - * \li \b efficient to compose (28 flops), - * \li \b stable spherical interpolation - * - * The following two typedefs are provided for convenience: - * \li \c Quaternionf for \c float - * \li \c Quaterniond for \c double - * - * \warning Operations interpreting the quaternion as rotation have undefined behavior if the quaternion is not normalized. - * - * \sa class AngleAxis, class Transform - */ - -namespace internal { -template<typename _Scalar,int _Options> -struct traits<Quaternion<_Scalar,_Options> > -{ - typedef Quaternion<_Scalar,_Options> PlainObject; - typedef _Scalar Scalar; - typedef Matrix<_Scalar,4,1,_Options> Coefficients; - enum{ - Alignment = internal::traits<Coefficients>::Alignment, - Flags = LvalueBit - }; -}; -} - -template<typename _Scalar, int _Options> -class Quaternion : public QuaternionBase<Quaternion<_Scalar,_Options> > -{ -public: - typedef QuaternionBase<Quaternion<_Scalar,_Options> > Base; - enum { NeedsAlignment = internal::traits<Quaternion>::Alignment>0 }; - - typedef _Scalar Scalar; - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Quaternion) - using Base::operator*=; - - typedef typename internal::traits<Quaternion>::Coefficients Coefficients; - typedef typename Base::AngleAxisType AngleAxisType; - - /** Default constructor leaving the quaternion uninitialized. */ - EIGEN_DEVICE_FUNC inline Quaternion() {} - - /** Constructs and initializes the quaternion \f$ w+xi+yj+zk \f$ from - * its four coefficients \a w, \a x, \a y and \a z. - * - * \warning Note the order of the arguments: the real \a w coefficient first, - * while internally the coefficients are stored in the following order: - * [\c x, \c y, \c z, \c w] - */ - EIGEN_DEVICE_FUNC inline Quaternion(const Scalar& w, const Scalar& x, const Scalar& y, const Scalar& z) : m_coeffs(x, y, z, w){} - - /** Constructs and initialize a quaternion from the array data */ - EIGEN_DEVICE_FUNC explicit inline Quaternion(const Scalar* data) : m_coeffs(data) {} - - /** Copy constructor */ - template<class Derived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion(const QuaternionBase<Derived>& other) { this->Base::operator=(other); } - - /** Constructs and initializes a quaternion from the angle-axis \a aa */ - EIGEN_DEVICE_FUNC explicit inline Quaternion(const AngleAxisType& aa) { *this = aa; } - - /** Constructs and initializes a quaternion from either: - * - a rotation matrix expression, - * - a 4D vector expression representing quaternion coefficients. - */ - template<typename Derived> - EIGEN_DEVICE_FUNC explicit inline Quaternion(const MatrixBase<Derived>& other) { *this = other; } - - /** Explicit copy constructor with scalar conversion */ - template<typename OtherScalar, int OtherOptions> - EIGEN_DEVICE_FUNC explicit inline Quaternion(const Quaternion<OtherScalar, OtherOptions>& other) - { m_coeffs = other.coeffs().template cast<Scalar>(); } - -#if EIGEN_HAS_RVALUE_REFERENCES - // We define a copy constructor, which means we don't get an implicit move constructor or assignment operator. - /** Default move constructor */ - EIGEN_DEVICE_FUNC inline Quaternion(Quaternion&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value) - : m_coeffs(std::move(other.coeffs())) - {} - - /** Default move assignment operator */ - EIGEN_DEVICE_FUNC Quaternion& operator=(Quaternion&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) - { - m_coeffs = std::move(other.coeffs()); - return *this; - } -#endif - - EIGEN_DEVICE_FUNC static Quaternion UnitRandom(); - - template<typename Derived1, typename Derived2> - EIGEN_DEVICE_FUNC static Quaternion FromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b); - - EIGEN_DEVICE_FUNC inline Coefficients& coeffs() { return m_coeffs;} - EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs;} - - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(bool(NeedsAlignment)) - -#ifdef EIGEN_QUATERNION_PLUGIN -# include EIGEN_QUATERNION_PLUGIN -#endif - -protected: - Coefficients m_coeffs; - -#ifndef EIGEN_PARSED_BY_DOXYGEN - static EIGEN_STRONG_INLINE void _check_template_params() - { - EIGEN_STATIC_ASSERT( (_Options & DontAlign) == _Options, - INVALID_MATRIX_TEMPLATE_PARAMETERS) - } -#endif -}; - -/** \ingroup Geometry_Module - * single precision quaternion type */ -typedef Quaternion<float> Quaternionf; -/** \ingroup Geometry_Module - * double precision quaternion type */ -typedef Quaternion<double> Quaterniond; - -/*************************************************************************** -* Specialization of Map<Quaternion<Scalar>> -***************************************************************************/ - -namespace internal { - template<typename _Scalar, int _Options> - struct traits<Map<Quaternion<_Scalar>, _Options> > : traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> > - { - typedef Map<Matrix<_Scalar,4,1>, _Options> Coefficients; - }; -} - -namespace internal { - template<typename _Scalar, int _Options> - struct traits<Map<const Quaternion<_Scalar>, _Options> > : traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> > - { - typedef Map<const Matrix<_Scalar,4,1>, _Options> Coefficients; - typedef traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> > TraitsBase; - enum { - Flags = TraitsBase::Flags & ~LvalueBit - }; - }; -} - -/** \ingroup Geometry_Module - * \brief Quaternion expression mapping a constant memory buffer - * - * \tparam _Scalar the type of the Quaternion coefficients - * \tparam _Options see class Map - * - * This is a specialization of class Map for Quaternion. This class allows to view - * a 4 scalar memory buffer as an Eigen's Quaternion object. - * - * \sa class Map, class Quaternion, class QuaternionBase - */ -template<typename _Scalar, int _Options> -class Map<const Quaternion<_Scalar>, _Options > - : public QuaternionBase<Map<const Quaternion<_Scalar>, _Options> > -{ - public: - typedef QuaternionBase<Map<const Quaternion<_Scalar>, _Options> > Base; - - typedef _Scalar Scalar; - typedef typename internal::traits<Map>::Coefficients Coefficients; - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map) - using Base::operator*=; - - /** Constructs a Mapped Quaternion object from the pointer \a coeffs - * - * The pointer \a coeffs must reference the four coefficients of Quaternion in the following order: - * \code *coeffs == {x, y, z, w} \endcode - * - * If the template parameter _Options is set to #Aligned, then the pointer coeffs must be aligned. */ - EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE Map(const Scalar* coeffs) : m_coeffs(coeffs) {} - - EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs;} - - protected: - const Coefficients m_coeffs; -}; - -/** \ingroup Geometry_Module - * \brief Expression of a quaternion from a memory buffer - * - * \tparam _Scalar the type of the Quaternion coefficients - * \tparam _Options see class Map - * - * This is a specialization of class Map for Quaternion. This class allows to view - * a 4 scalar memory buffer as an Eigen's Quaternion object. - * - * \sa class Map, class Quaternion, class QuaternionBase - */ -template<typename _Scalar, int _Options> -class Map<Quaternion<_Scalar>, _Options > - : public QuaternionBase<Map<Quaternion<_Scalar>, _Options> > -{ - public: - typedef QuaternionBase<Map<Quaternion<_Scalar>, _Options> > Base; - - typedef _Scalar Scalar; - typedef typename internal::traits<Map>::Coefficients Coefficients; - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map) - using Base::operator*=; - - /** Constructs a Mapped Quaternion object from the pointer \a coeffs - * - * The pointer \a coeffs must reference the four coefficients of Quaternion in the following order: - * \code *coeffs == {x, y, z, w} \endcode - * - * If the template parameter _Options is set to #Aligned, then the pointer coeffs must be aligned. */ - EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE Map(Scalar* coeffs) : m_coeffs(coeffs) {} - - EIGEN_DEVICE_FUNC inline Coefficients& coeffs() { return m_coeffs; } - EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs; } - - protected: - Coefficients m_coeffs; -}; - -/** \ingroup Geometry_Module - * Map an unaligned array of single precision scalars as a quaternion */ -typedef Map<Quaternion<float>, 0> QuaternionMapf; -/** \ingroup Geometry_Module - * Map an unaligned array of double precision scalars as a quaternion */ -typedef Map<Quaternion<double>, 0> QuaternionMapd; -/** \ingroup Geometry_Module - * Map a 16-byte aligned array of single precision scalars as a quaternion */ -typedef Map<Quaternion<float>, Aligned> QuaternionMapAlignedf; -/** \ingroup Geometry_Module - * Map a 16-byte aligned array of double precision scalars as a quaternion */ -typedef Map<Quaternion<double>, Aligned> QuaternionMapAlignedd; - -/*************************************************************************** -* Implementation of QuaternionBase methods -***************************************************************************/ - -// Generic Quaternion * Quaternion product -// This product can be specialized for a given architecture via the Arch template argument. -namespace internal { -template<int Arch, class Derived1, class Derived2, typename Scalar> struct quat_product -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Quaternion<Scalar> run(const QuaternionBase<Derived1>& a, const QuaternionBase<Derived2>& b){ - return Quaternion<Scalar> - ( - a.w() * b.w() - a.x() * b.x() - a.y() * b.y() - a.z() * b.z(), - a.w() * b.x() + a.x() * b.w() + a.y() * b.z() - a.z() * b.y(), - a.w() * b.y() + a.y() * b.w() + a.z() * b.x() - a.x() * b.z(), - a.w() * b.z() + a.z() * b.w() + a.x() * b.y() - a.y() * b.x() - ); - } -}; -} - -/** \returns the concatenation of two rotations as a quaternion-quaternion product */ -template <class Derived> -template <class OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion<typename internal::traits<Derived>::Scalar> -QuaternionBase<Derived>::operator* (const QuaternionBase<OtherDerived>& other) const -{ - EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename OtherDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - return internal::quat_product<Architecture::Target, Derived, OtherDerived, - typename internal::traits<Derived>::Scalar>::run(*this, other); -} - -/** \sa operator*(Quaternion) */ -template <class Derived> -template <class OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator*= (const QuaternionBase<OtherDerived>& other) -{ - derived() = derived() * other.derived(); - return derived(); -} - -/** Rotation of a vector by a quaternion. - * \remarks If the quaternion is used to rotate several points (>1) - * then it is much more efficient to first convert it to a 3x3 Matrix. - * Comparison of the operation cost for n transformations: - * - Quaternion2: 30n - * - Via a Matrix3: 24 + 15n - */ -template <class Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename QuaternionBase<Derived>::Vector3 -QuaternionBase<Derived>::_transformVector(const Vector3& v) const -{ - // Note that this algorithm comes from the optimization by hand - // of the conversion to a Matrix followed by a Matrix/Vector product. - // It appears to be much faster than the common algorithm found - // in the literature (30 versus 39 flops). It also requires two - // Vector3 as temporaries. - Vector3 uv = this->vec().cross(v); - uv += uv; - return v + this->w() * uv + this->vec().cross(uv); -} - -template<class Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE QuaternionBase<Derived>& QuaternionBase<Derived>::operator=(const QuaternionBase<Derived>& other) -{ - coeffs() = other.coeffs(); - return derived(); -} - -template<class Derived> -template<class OtherDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator=(const QuaternionBase<OtherDerived>& other) -{ - coeffs() = other.coeffs(); - return derived(); -} - -/** Set \c *this from an angle-axis \a aa and returns a reference to \c *this - */ -template<class Derived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator=(const AngleAxisType& aa) -{ - EIGEN_USING_STD_MATH(cos) - EIGEN_USING_STD_MATH(sin) - Scalar ha = Scalar(0.5)*aa.angle(); // Scalar(0.5) to suppress precision loss warnings - this->w() = cos(ha); - this->vec() = sin(ha) * aa.axis(); - return derived(); -} - -/** Set \c *this from the expression \a xpr: - * - if \a xpr is a 4x1 vector, then \a xpr is assumed to be a quaternion - * - if \a xpr is a 3x3 matrix, then \a xpr is assumed to be rotation matrix - * and \a xpr is converted to a quaternion - */ - -template<class Derived> -template<class MatrixDerived> -EIGEN_DEVICE_FUNC inline Derived& QuaternionBase<Derived>::operator=(const MatrixBase<MatrixDerived>& xpr) -{ - EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename MatrixDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - internal::quaternionbase_assign_impl<MatrixDerived>::run(*this, xpr.derived()); - return derived(); -} - -/** Convert the quaternion to a 3x3 rotation matrix. The quaternion is required to - * be normalized, otherwise the result is undefined. - */ -template<class Derived> -EIGEN_DEVICE_FUNC inline typename QuaternionBase<Derived>::Matrix3 -QuaternionBase<Derived>::toRotationMatrix(void) const -{ - // NOTE if inlined, then gcc 4.2 and 4.4 get rid of the temporary (not gcc 4.3 !!) - // if not inlined then the cost of the return by value is huge ~ +35%, - // however, not inlining this function is an order of magnitude slower, so - // it has to be inlined, and so the return by value is not an issue - Matrix3 res; - - const Scalar tx = Scalar(2)*this->x(); - const Scalar ty = Scalar(2)*this->y(); - const Scalar tz = Scalar(2)*this->z(); - const Scalar twx = tx*this->w(); - const Scalar twy = ty*this->w(); - const Scalar twz = tz*this->w(); - const Scalar txx = tx*this->x(); - const Scalar txy = ty*this->x(); - const Scalar txz = tz*this->x(); - const Scalar tyy = ty*this->y(); - const Scalar tyz = tz*this->y(); - const Scalar tzz = tz*this->z(); - - res.coeffRef(0,0) = Scalar(1)-(tyy+tzz); - res.coeffRef(0,1) = txy-twz; - res.coeffRef(0,2) = txz+twy; - res.coeffRef(1,0) = txy+twz; - res.coeffRef(1,1) = Scalar(1)-(txx+tzz); - res.coeffRef(1,2) = tyz-twx; - res.coeffRef(2,0) = txz-twy; - res.coeffRef(2,1) = tyz+twx; - res.coeffRef(2,2) = Scalar(1)-(txx+tyy); - - return res; -} - -/** Sets \c *this to be a quaternion representing a rotation between - * the two arbitrary vectors \a a and \a b. In other words, the built - * rotation represent a rotation sending the line of direction \a a - * to the line of direction \a b, both lines passing through the origin. - * - * \returns a reference to \c *this. - * - * Note that the two input vectors do \b not have to be normalized, and - * do not need to have the same norm. - */ -template<class Derived> -template<typename Derived1, typename Derived2> -EIGEN_DEVICE_FUNC inline Derived& QuaternionBase<Derived>::setFromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b) -{ - EIGEN_USING_STD_MATH(sqrt) - Vector3 v0 = a.normalized(); - Vector3 v1 = b.normalized(); - Scalar c = v1.dot(v0); - - // if dot == -1, vectors are nearly opposites - // => accurately compute the rotation axis by computing the - // intersection of the two planes. This is done by solving: - // x^T v0 = 0 - // x^T v1 = 0 - // under the constraint: - // ||x|| = 1 - // which yields a singular value problem - if (c < Scalar(-1)+NumTraits<Scalar>::dummy_precision()) - { - c = numext::maxi(c,Scalar(-1)); - Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose(); - JacobiSVD<Matrix<Scalar,2,3> > svd(m, ComputeFullV); - Vector3 axis = svd.matrixV().col(2); - - Scalar w2 = (Scalar(1)+c)*Scalar(0.5); - this->w() = sqrt(w2); - this->vec() = axis * sqrt(Scalar(1) - w2); - return derived(); - } - Vector3 axis = v0.cross(v1); - Scalar s = sqrt((Scalar(1)+c)*Scalar(2)); - Scalar invs = Scalar(1)/s; - this->vec() = axis * invs; - this->w() = s * Scalar(0.5); - - return derived(); -} - -/** \returns a random unit quaternion following a uniform distribution law on SO(3) - * - * \note The implementation is based on http://planning.cs.uiuc.edu/node198.html - */ -template<typename Scalar, int Options> -EIGEN_DEVICE_FUNC Quaternion<Scalar,Options> Quaternion<Scalar,Options>::UnitRandom() -{ - EIGEN_USING_STD_MATH(sqrt) - EIGEN_USING_STD_MATH(sin) - EIGEN_USING_STD_MATH(cos) - const Scalar u1 = internal::random<Scalar>(0, 1), - u2 = internal::random<Scalar>(0, 2*EIGEN_PI), - u3 = internal::random<Scalar>(0, 2*EIGEN_PI); - const Scalar a = sqrt(Scalar(1) - u1), - b = sqrt(u1); - return Quaternion (a * sin(u2), a * cos(u2), b * sin(u3), b * cos(u3)); -} - - -/** Returns a quaternion representing a rotation between - * the two arbitrary vectors \a a and \a b. In other words, the built - * rotation represent a rotation sending the line of direction \a a - * to the line of direction \a b, both lines passing through the origin. - * - * \returns resulting quaternion - * - * Note that the two input vectors do \b not have to be normalized, and - * do not need to have the same norm. - */ -template<typename Scalar, int Options> -template<typename Derived1, typename Derived2> -EIGEN_DEVICE_FUNC Quaternion<Scalar,Options> Quaternion<Scalar,Options>::FromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b) -{ - Quaternion quat; - quat.setFromTwoVectors(a, b); - return quat; -} - - -/** \returns the multiplicative inverse of \c *this - * Note that in most cases, i.e., if you simply want the opposite rotation, - * and/or the quaternion is normalized, then it is enough to use the conjugate. - * - * \sa QuaternionBase::conjugate() - */ -template <class Derived> -EIGEN_DEVICE_FUNC inline Quaternion<typename internal::traits<Derived>::Scalar> QuaternionBase<Derived>::inverse() const -{ - // FIXME should this function be called multiplicativeInverse and conjugate() be called inverse() or opposite() ?? - Scalar n2 = this->squaredNorm(); - if (n2 > Scalar(0)) - return Quaternion<Scalar>(conjugate().coeffs() / n2); - else - { - // return an invalid result to flag the error - return Quaternion<Scalar>(Coefficients::Zero()); - } -} - -// Generic conjugate of a Quaternion -namespace internal { -template<int Arch, class Derived, typename Scalar> struct quat_conj -{ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Quaternion<Scalar> run(const QuaternionBase<Derived>& q){ - return Quaternion<Scalar>(q.w(),-q.x(),-q.y(),-q.z()); - } -}; -} - -/** \returns the conjugate of the \c *this which is equal to the multiplicative inverse - * if the quaternion is normalized. - * The conjugate of a quaternion represents the opposite rotation. - * - * \sa Quaternion2::inverse() - */ -template <class Derived> -EIGEN_DEVICE_FUNC inline Quaternion<typename internal::traits<Derived>::Scalar> -QuaternionBase<Derived>::conjugate() const -{ - return internal::quat_conj<Architecture::Target, Derived, - typename internal::traits<Derived>::Scalar>::run(*this); - -} - -/** \returns the angle (in radian) between two rotations - * \sa dot() - */ -template <class Derived> -template <class OtherDerived> -EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Scalar -QuaternionBase<Derived>::angularDistance(const QuaternionBase<OtherDerived>& other) const -{ - EIGEN_USING_STD_MATH(atan2) - Quaternion<Scalar> d = (*this) * other.conjugate(); - return Scalar(2) * atan2( d.vec().norm(), numext::abs(d.w()) ); -} - - - -/** \returns the spherical linear interpolation between the two quaternions - * \c *this and \a other at the parameter \a t in [0;1]. - * - * This represents an interpolation for a constant motion between \c *this and \a other, - * see also http://en.wikipedia.org/wiki/Slerp. - */ -template <class Derived> -template <class OtherDerived> -EIGEN_DEVICE_FUNC Quaternion<typename internal::traits<Derived>::Scalar> -QuaternionBase<Derived>::slerp(const Scalar& t, const QuaternionBase<OtherDerived>& other) const -{ - EIGEN_USING_STD_MATH(acos) - EIGEN_USING_STD_MATH(sin) - const Scalar one = Scalar(1) - NumTraits<Scalar>::epsilon(); - Scalar d = this->dot(other); - Scalar absD = numext::abs(d); - - Scalar scale0; - Scalar scale1; - - if(absD>=one) - { - scale0 = Scalar(1) - t; - scale1 = t; - } - else - { - // theta is the angle between the 2 quaternions - Scalar theta = acos(absD); - Scalar sinTheta = sin(theta); - - scale0 = sin( ( Scalar(1) - t ) * theta) / sinTheta; - scale1 = sin( ( t * theta) ) / sinTheta; - } - if(d<Scalar(0)) scale1 = -scale1; - - return Quaternion<Scalar>(scale0 * coeffs() + scale1 * other.coeffs()); -} - -namespace internal { - -// set from a rotation matrix -template<typename Other> -struct quaternionbase_assign_impl<Other,3,3> -{ - typedef typename Other::Scalar Scalar; - template<class Derived> EIGEN_DEVICE_FUNC static inline void run(QuaternionBase<Derived>& q, const Other& a_mat) - { - const typename internal::nested_eval<Other,2>::type mat(a_mat); - EIGEN_USING_STD_MATH(sqrt) - // This algorithm comes from "Quaternion Calculus and Fast Animation", - // Ken Shoemake, 1987 SIGGRAPH course notes - Scalar t = mat.trace(); - if (t > Scalar(0)) - { - t = sqrt(t + Scalar(1.0)); - q.w() = Scalar(0.5)*t; - t = Scalar(0.5)/t; - q.x() = (mat.coeff(2,1) - mat.coeff(1,2)) * t; - q.y() = (mat.coeff(0,2) - mat.coeff(2,0)) * t; - q.z() = (mat.coeff(1,0) - mat.coeff(0,1)) * t; - } - else - { - Index i = 0; - if (mat.coeff(1,1) > mat.coeff(0,0)) - i = 1; - if (mat.coeff(2,2) > mat.coeff(i,i)) - i = 2; - Index j = (i+1)%3; - Index k = (j+1)%3; - - t = sqrt(mat.coeff(i,i)-mat.coeff(j,j)-mat.coeff(k,k) + Scalar(1.0)); - q.coeffs().coeffRef(i) = Scalar(0.5) * t; - t = Scalar(0.5)/t; - q.w() = (mat.coeff(k,j)-mat.coeff(j,k))*t; - q.coeffs().coeffRef(j) = (mat.coeff(j,i)+mat.coeff(i,j))*t; - q.coeffs().coeffRef(k) = (mat.coeff(k,i)+mat.coeff(i,k))*t; - } - } -}; - -// set from a vector of coefficients assumed to be a quaternion -template<typename Other> -struct quaternionbase_assign_impl<Other,4,1> -{ - typedef typename Other::Scalar Scalar; - template<class Derived> EIGEN_DEVICE_FUNC static inline void run(QuaternionBase<Derived>& q, const Other& vec) - { - q.coeffs() = vec; - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_QUATERNION_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/Rotation2D.h b/external/eigen/include/eigen3/Eigen/src/Geometry/Rotation2D.h deleted file mode 100644 index 884b7d0e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/Rotation2D.h +++ /dev/null @@ -1,199 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ROTATION2D_H -#define EIGEN_ROTATION2D_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * \class Rotation2D - * - * \brief Represents a rotation/orientation in a 2 dimensional space. - * - * \tparam _Scalar the scalar type, i.e., the type of the coefficients - * - * This class is equivalent to a single scalar representing a counter clock wise rotation - * as a single angle in radian. It provides some additional features such as the automatic - * conversion from/to a 2x2 rotation matrix. Moreover this class aims to provide a similar - * interface to Quaternion in order to facilitate the writing of generic algorithms - * dealing with rotations. - * - * \sa class Quaternion, class Transform - */ - -namespace internal { - -template<typename _Scalar> struct traits<Rotation2D<_Scalar> > -{ - typedef _Scalar Scalar; -}; -} // end namespace internal - -template<typename _Scalar> -class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2> -{ - typedef RotationBase<Rotation2D<_Scalar>,2> Base; - -public: - - using Base::operator*; - - enum { Dim = 2 }; - /** the scalar type of the coefficients */ - typedef _Scalar Scalar; - typedef Matrix<Scalar,2,1> Vector2; - typedef Matrix<Scalar,2,2> Matrix2; - -protected: - - Scalar m_angle; - -public: - - /** Construct a 2D counter clock wise rotation from the angle \a a in radian. */ - EIGEN_DEVICE_FUNC explicit inline Rotation2D(const Scalar& a) : m_angle(a) {} - - /** Default constructor wihtout initialization. The represented rotation is undefined. */ - EIGEN_DEVICE_FUNC Rotation2D() {} - - /** Construct a 2D rotation from a 2x2 rotation matrix \a mat. - * - * \sa fromRotationMatrix() - */ - template<typename Derived> - EIGEN_DEVICE_FUNC explicit Rotation2D(const MatrixBase<Derived>& m) - { - fromRotationMatrix(m.derived()); - } - - /** \returns the rotation angle */ - EIGEN_DEVICE_FUNC inline Scalar angle() const { return m_angle; } - - /** \returns a read-write reference to the rotation angle */ - EIGEN_DEVICE_FUNC inline Scalar& angle() { return m_angle; } - - /** \returns the rotation angle in [0,2pi] */ - EIGEN_DEVICE_FUNC inline Scalar smallestPositiveAngle() const { - Scalar tmp = numext::fmod(m_angle,Scalar(2*EIGEN_PI)); - return tmp<Scalar(0) ? tmp + Scalar(2*EIGEN_PI) : tmp; - } - - /** \returns the rotation angle in [-pi,pi] */ - EIGEN_DEVICE_FUNC inline Scalar smallestAngle() const { - Scalar tmp = numext::fmod(m_angle,Scalar(2*EIGEN_PI)); - if(tmp>Scalar(EIGEN_PI)) tmp -= Scalar(2*EIGEN_PI); - else if(tmp<-Scalar(EIGEN_PI)) tmp += Scalar(2*EIGEN_PI); - return tmp; - } - - /** \returns the inverse rotation */ - EIGEN_DEVICE_FUNC inline Rotation2D inverse() const { return Rotation2D(-m_angle); } - - /** Concatenates two rotations */ - EIGEN_DEVICE_FUNC inline Rotation2D operator*(const Rotation2D& other) const - { return Rotation2D(m_angle + other.m_angle); } - - /** Concatenates two rotations */ - EIGEN_DEVICE_FUNC inline Rotation2D& operator*=(const Rotation2D& other) - { m_angle += other.m_angle; return *this; } - - /** Applies the rotation to a 2D vector */ - EIGEN_DEVICE_FUNC Vector2 operator* (const Vector2& vec) const - { return toRotationMatrix() * vec; } - - template<typename Derived> - EIGEN_DEVICE_FUNC Rotation2D& fromRotationMatrix(const MatrixBase<Derived>& m); - EIGEN_DEVICE_FUNC Matrix2 toRotationMatrix() const; - - /** Set \c *this from a 2x2 rotation matrix \a mat. - * In other words, this function extract the rotation angle from the rotation matrix. - * - * This method is an alias for fromRotationMatrix() - * - * \sa fromRotationMatrix() - */ - template<typename Derived> - EIGEN_DEVICE_FUNC Rotation2D& operator=(const MatrixBase<Derived>& m) - { return fromRotationMatrix(m.derived()); } - - /** \returns the spherical interpolation between \c *this and \a other using - * parameter \a t. It is in fact equivalent to a linear interpolation. - */ - EIGEN_DEVICE_FUNC inline Rotation2D slerp(const Scalar& t, const Rotation2D& other) const - { - Scalar dist = Rotation2D(other.m_angle-m_angle).smallestAngle(); - return Rotation2D(m_angle + dist*t); - } - - /** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const - { return typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); } - - /** Copy constructor with scalar type conversion */ - template<typename OtherScalarType> - EIGEN_DEVICE_FUNC inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other) - { - m_angle = Scalar(other.angle()); - } - - EIGEN_DEVICE_FUNC static inline Rotation2D Identity() { return Rotation2D(0); } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - EIGEN_DEVICE_FUNC bool isApprox(const Rotation2D& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const - { return internal::isApprox(m_angle,other.m_angle, prec); } - -}; - -/** \ingroup Geometry_Module - * single precision 2D rotation type */ -typedef Rotation2D<float> Rotation2Df; -/** \ingroup Geometry_Module - * double precision 2D rotation type */ -typedef Rotation2D<double> Rotation2Dd; - -/** Set \c *this from a 2x2 rotation matrix \a mat. - * In other words, this function extract the rotation angle - * from the rotation matrix. - */ -template<typename Scalar> -template<typename Derived> -EIGEN_DEVICE_FUNC Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat) -{ - EIGEN_USING_STD_MATH(atan2) - EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE) - m_angle = atan2(mat.coeff(1,0), mat.coeff(0,0)); - return *this; -} - -/** Constructs and \returns an equivalent 2x2 rotation matrix. - */ -template<typename Scalar> -typename Rotation2D<Scalar>::Matrix2 -EIGEN_DEVICE_FUNC Rotation2D<Scalar>::toRotationMatrix(void) const -{ - EIGEN_USING_STD_MATH(sin) - EIGEN_USING_STD_MATH(cos) - Scalar sinA = sin(m_angle); - Scalar cosA = cos(m_angle); - return (Matrix2() << cosA, -sinA, sinA, cosA).finished(); -} - -} // end namespace Eigen - -#endif // EIGEN_ROTATION2D_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/RotationBase.h b/external/eigen/include/eigen3/Eigen/src/Geometry/RotationBase.h deleted file mode 100644 index f0ee0bd0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/RotationBase.h +++ /dev/null @@ -1,206 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ROTATIONBASE_H -#define EIGEN_ROTATIONBASE_H - -namespace Eigen { - -// forward declaration -namespace internal { -template<typename RotationDerived, typename MatrixType, bool IsVector=MatrixType::IsVectorAtCompileTime> -struct rotation_base_generic_product_selector; -} - -/** \class RotationBase - * - * \brief Common base class for compact rotation representations - * - * \tparam Derived is the derived type, i.e., a rotation type - * \tparam _Dim the dimension of the space - */ -template<typename Derived, int _Dim> -class RotationBase -{ - public: - enum { Dim = _Dim }; - /** the scalar type of the coefficients */ - typedef typename internal::traits<Derived>::Scalar Scalar; - - /** corresponding linear transformation matrix type */ - typedef Matrix<Scalar,Dim,Dim> RotationMatrixType; - typedef Matrix<Scalar,Dim,1> VectorType; - - public: - EIGEN_DEVICE_FUNC inline const Derived& derived() const { return *static_cast<const Derived*>(this); } - EIGEN_DEVICE_FUNC inline Derived& derived() { return *static_cast<Derived*>(this); } - - /** \returns an equivalent rotation matrix */ - EIGEN_DEVICE_FUNC inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); } - - /** \returns an equivalent rotation matrix - * This function is added to be conform with the Transform class' naming scheme. - */ - EIGEN_DEVICE_FUNC inline RotationMatrixType matrix() const { return derived().toRotationMatrix(); } - - /** \returns the inverse rotation */ - EIGEN_DEVICE_FUNC inline Derived inverse() const { return derived().inverse(); } - - /** \returns the concatenation of the rotation \c *this with a translation \a t */ - EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Isometry> operator*(const Translation<Scalar,Dim>& t) const - { return Transform<Scalar,Dim,Isometry>(*this) * t; } - - /** \returns the concatenation of the rotation \c *this with a uniform scaling \a s */ - EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const UniformScaling<Scalar>& s) const - { return toRotationMatrix() * s.factor(); } - - /** \returns the concatenation of the rotation \c *this with a generic expression \a e - * \a e can be: - * - a DimxDim linear transformation matrix - * - a DimxDim diagonal matrix (axis aligned scaling) - * - a vector of size Dim - */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::rotation_base_generic_product_selector<Derived,OtherDerived,OtherDerived::IsVectorAtCompileTime>::ReturnType - operator*(const EigenBase<OtherDerived>& e) const - { return internal::rotation_base_generic_product_selector<Derived,OtherDerived>::run(derived(), e.derived()); } - - /** \returns the concatenation of a linear transformation \a l with the rotation \a r */ - template<typename OtherDerived> friend - EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r) - { return l.derived() * r.toRotationMatrix(); } - - /** \returns the concatenation of a scaling \a l with the rotation \a r */ - EIGEN_DEVICE_FUNC friend inline Transform<Scalar,Dim,Affine> operator*(const DiagonalMatrix<Scalar,Dim>& l, const Derived& r) - { - Transform<Scalar,Dim,Affine> res(r); - res.linear().applyOnTheLeft(l); - return res; - } - - /** \returns the concatenation of the rotation \c *this with a transformation \a t */ - template<int Mode, int Options> - EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode> operator*(const Transform<Scalar,Dim,Mode,Options>& t) const - { return toRotationMatrix() * t; } - - template<typename OtherVectorType> - EIGEN_DEVICE_FUNC inline VectorType _transformVector(const OtherVectorType& v) const - { return toRotationMatrix() * v; } -}; - -namespace internal { - -// implementation of the generic product rotation * matrix -template<typename RotationDerived, typename MatrixType> -struct rotation_base_generic_product_selector<RotationDerived,MatrixType,false> -{ - enum { Dim = RotationDerived::Dim }; - typedef Matrix<typename RotationDerived::Scalar,Dim,Dim> ReturnType; - EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const MatrixType& m) - { return r.toRotationMatrix() * m; } -}; - -template<typename RotationDerived, typename Scalar, int Dim, int MaxDim> -struct rotation_base_generic_product_selector< RotationDerived, DiagonalMatrix<Scalar,Dim,MaxDim>, false > -{ - typedef Transform<Scalar,Dim,Affine> ReturnType; - EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const DiagonalMatrix<Scalar,Dim,MaxDim>& m) - { - ReturnType res(r); - res.linear() *= m; - return res; - } -}; - -template<typename RotationDerived,typename OtherVectorType> -struct rotation_base_generic_product_selector<RotationDerived,OtherVectorType,true> -{ - enum { Dim = RotationDerived::Dim }; - typedef Matrix<typename RotationDerived::Scalar,Dim,1> ReturnType; - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE ReturnType run(const RotationDerived& r, const OtherVectorType& v) - { - return r._transformVector(v); - } -}; - -} // end namespace internal - -/** \geometry_module - * - * \brief Constructs a Dim x Dim rotation matrix from the rotation \a r - */ -template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols> -::Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r) -{ - EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim)) - *this = r.toRotationMatrix(); -} - -/** \geometry_module - * - * \brief Set a Dim x Dim rotation matrix from the rotation \a r - */ -template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>& -Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols> -::operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r) -{ - EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim)) - return *this = r.toRotationMatrix(); -} - -namespace internal { - -/** \internal - * - * Helper function to return an arbitrary rotation object to a rotation matrix. - * - * \tparam Scalar the numeric type of the matrix coefficients - * \tparam Dim the dimension of the current space - * - * It returns a Dim x Dim fixed size matrix. - * - * Default specializations are provided for: - * - any scalar type (2D), - * - any matrix expression, - * - any type based on RotationBase (e.g., Quaternion, AngleAxis, Rotation2D) - * - * Currently toRotationMatrix is only used by Transform. - * - * \sa class Transform, class Rotation2D, class Quaternion, class AngleAxis - */ -template<typename Scalar, int Dim> -EIGEN_DEVICE_FUNC static inline Matrix<Scalar,2,2> toRotationMatrix(const Scalar& s) -{ - EIGEN_STATIC_ASSERT(Dim==2,YOU_MADE_A_PROGRAMMING_MISTAKE) - return Rotation2D<Scalar>(s).toRotationMatrix(); -} - -template<typename Scalar, int Dim, typename OtherDerived> -EIGEN_DEVICE_FUNC static inline Matrix<Scalar,Dim,Dim> toRotationMatrix(const RotationBase<OtherDerived,Dim>& r) -{ - return r.toRotationMatrix(); -} - -template<typename Scalar, int Dim, typename OtherDerived> -EIGEN_DEVICE_FUNC static inline const MatrixBase<OtherDerived>& toRotationMatrix(const MatrixBase<OtherDerived>& mat) -{ - EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime==Dim && OtherDerived::ColsAtCompileTime==Dim, - YOU_MADE_A_PROGRAMMING_MISTAKE) - return mat; -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_ROTATIONBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/Scaling.h b/external/eigen/include/eigen3/Eigen/src/Geometry/Scaling.h deleted file mode 100644 index df650fda..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/Scaling.h +++ /dev/null @@ -1,188 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SCALING_H -#define EIGEN_SCALING_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * \class Scaling - * - * \brief Represents a generic uniform scaling transformation - * - * \tparam _Scalar the scalar type, i.e., the type of the coefficients. - * - * This class represent a uniform scaling transformation. It is the return - * type of Scaling(Scalar), and most of the time this is the only way it - * is used. In particular, this class is not aimed to be used to store a scaling transformation, - * but rather to make easier the constructions and updates of Transform objects. - * - * To represent an axis aligned scaling, use the DiagonalMatrix class. - * - * \sa Scaling(), class DiagonalMatrix, MatrixBase::asDiagonal(), class Translation, class Transform - */ - -namespace internal -{ - // This helper helps nvcc+MSVC to properly parse this file. - // See bug 1412. - template <typename Scalar, int Dim, int Mode> - struct uniformscaling_times_affine_returntype - { - enum - { - NewMode = int(Mode) == int(Isometry) ? Affine : Mode - }; - typedef Transform <Scalar, Dim, NewMode> type; - }; -} - -template<typename _Scalar> -class UniformScaling -{ -public: - /** the scalar type of the coefficients */ - typedef _Scalar Scalar; - -protected: - - Scalar m_factor; - -public: - - /** Default constructor without initialization. */ - UniformScaling() {} - /** Constructs and initialize a uniform scaling transformation */ - explicit inline UniformScaling(const Scalar& s) : m_factor(s) {} - - inline const Scalar& factor() const { return m_factor; } - inline Scalar& factor() { return m_factor; } - - /** Concatenates two uniform scaling */ - inline UniformScaling operator* (const UniformScaling& other) const - { return UniformScaling(m_factor * other.factor()); } - - /** Concatenates a uniform scaling and a translation */ - template<int Dim> - inline Transform<Scalar,Dim,Affine> operator* (const Translation<Scalar,Dim>& t) const; - - /** Concatenates a uniform scaling and an affine transformation */ - template<int Dim, int Mode, int Options> - inline typename - internal::uniformscaling_times_affine_returntype<Scalar,Dim,Mode>::type - operator* (const Transform<Scalar, Dim, Mode, Options>& t) const - { - typename internal::uniformscaling_times_affine_returntype<Scalar,Dim,Mode>::type res = t; - res.prescale(factor()); - return res; - } - - /** Concatenates a uniform scaling and a linear transformation matrix */ - // TODO returns an expression - template<typename Derived> - inline typename Eigen::internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const - { return other * m_factor; } - - template<typename Derived,int Dim> - inline Matrix<Scalar,Dim,Dim> operator*(const RotationBase<Derived,Dim>& r) const - { return r.toRotationMatrix() * m_factor; } - - /** \returns the inverse scaling */ - inline UniformScaling inverse() const - { return UniformScaling(Scalar(1)/m_factor); } - - /** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - inline UniformScaling<NewScalarType> cast() const - { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); } - - /** Copy constructor with scalar type conversion */ - template<typename OtherScalarType> - inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other) - { m_factor = Scalar(other.factor()); } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - bool isApprox(const UniformScaling& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const - { return internal::isApprox(m_factor, other.factor(), prec); } - -}; - -/** \addtogroup Geometry_Module */ -//@{ - -/** Concatenates a linear transformation matrix and a uniform scaling - * \relates UniformScaling - */ -// NOTE this operator is defined in MatrixBase and not as a friend function -// of UniformScaling to fix an internal crash of Intel's ICC -template<typename Derived,typename Scalar> -EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,Scalar,product) -operator*(const MatrixBase<Derived>& matrix, const UniformScaling<Scalar>& s) -{ return matrix.derived() * s.factor(); } - -/** Constructs a uniform scaling from scale factor \a s */ -inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); } -/** Constructs a uniform scaling from scale factor \a s */ -inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); } -/** Constructs a uniform scaling from scale factor \a s */ -template<typename RealScalar> -inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s) -{ return UniformScaling<std::complex<RealScalar> >(s); } - -/** Constructs a 2D axis aligned scaling */ -template<typename Scalar> -inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy) -{ return DiagonalMatrix<Scalar,2>(sx, sy); } -/** Constructs a 3D axis aligned scaling */ -template<typename Scalar> -inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz) -{ return DiagonalMatrix<Scalar,3>(sx, sy, sz); } - -/** Constructs an axis aligned scaling expression from vector expression \a coeffs - * This is an alias for coeffs.asDiagonal() - */ -template<typename Derived> -inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs) -{ return coeffs.asDiagonal(); } - -/** \deprecated */ -typedef DiagonalMatrix<float, 2> AlignedScaling2f; -/** \deprecated */ -typedef DiagonalMatrix<double,2> AlignedScaling2d; -/** \deprecated */ -typedef DiagonalMatrix<float, 3> AlignedScaling3f; -/** \deprecated */ -typedef DiagonalMatrix<double,3> AlignedScaling3d; -//@} - -template<typename Scalar> -template<int Dim> -inline Transform<Scalar,Dim,Affine> -UniformScaling<Scalar>::operator* (const Translation<Scalar,Dim>& t) const -{ - Transform<Scalar,Dim,Affine> res; - res.matrix().setZero(); - res.linear().diagonal().fill(factor()); - res.translation() = factor() * t.vector(); - res(Dim,Dim) = Scalar(1); - return res; -} - -} // end namespace Eigen - -#endif // EIGEN_SCALING_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/Transform.h b/external/eigen/include/eigen3/Eigen/src/Geometry/Transform.h deleted file mode 100644 index c87b5fed..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/Transform.h +++ /dev/null @@ -1,1570 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRANSFORM_H -#define EIGEN_TRANSFORM_H - -namespace Eigen { - -namespace internal { - -template<typename Transform> -struct transform_traits -{ - enum - { - Dim = Transform::Dim, - HDim = Transform::HDim, - Mode = Transform::Mode, - IsProjective = (int(Mode)==int(Projective)) - }; -}; - -template< typename TransformType, - typename MatrixType, - int Case = transform_traits<TransformType>::IsProjective ? 0 - : int(MatrixType::RowsAtCompileTime) == int(transform_traits<TransformType>::HDim) ? 1 - : 2, - int RhsCols = MatrixType::ColsAtCompileTime> -struct transform_right_product_impl; - -template< typename Other, - int Mode, - int Options, - int Dim, - int HDim, - int OtherRows=Other::RowsAtCompileTime, - int OtherCols=Other::ColsAtCompileTime> -struct transform_left_product_impl; - -template< typename Lhs, - typename Rhs, - bool AnyProjective = - transform_traits<Lhs>::IsProjective || - transform_traits<Rhs>::IsProjective> -struct transform_transform_product_impl; - -template< typename Other, - int Mode, - int Options, - int Dim, - int HDim, - int OtherRows=Other::RowsAtCompileTime, - int OtherCols=Other::ColsAtCompileTime> -struct transform_construct_from_matrix; - -template<typename TransformType> struct transform_take_affine_part; - -template<typename _Scalar, int _Dim, int _Mode, int _Options> -struct traits<Transform<_Scalar,_Dim,_Mode,_Options> > -{ - typedef _Scalar Scalar; - typedef Eigen::Index StorageIndex; - typedef Dense StorageKind; - enum { - Dim1 = _Dim==Dynamic ? _Dim : _Dim + 1, - RowsAtCompileTime = _Mode==Projective ? Dim1 : _Dim, - ColsAtCompileTime = Dim1, - MaxRowsAtCompileTime = RowsAtCompileTime, - MaxColsAtCompileTime = ColsAtCompileTime, - Flags = 0 - }; -}; - -template<int Mode> struct transform_make_affine; - -} // end namespace internal - -/** \geometry_module \ingroup Geometry_Module - * - * \class Transform - * - * \brief Represents an homogeneous transformation in a N dimensional space - * - * \tparam _Scalar the scalar type, i.e., the type of the coefficients - * \tparam _Dim the dimension of the space - * \tparam _Mode the type of the transformation. Can be: - * - #Affine: the transformation is stored as a (Dim+1)^2 matrix, - * where the last row is assumed to be [0 ... 0 1]. - * - #AffineCompact: the transformation is stored as a (Dim)x(Dim+1) matrix. - * - #Projective: the transformation is stored as a (Dim+1)^2 matrix - * without any assumption. - * - #Isometry: same as #Affine with the additional assumption that - * the linear part represents a rotation. This assumption is exploited - * to speed up some functions such as inverse() and rotation(). - * \tparam _Options has the same meaning as in class Matrix. It allows to specify DontAlign and/or RowMajor. - * These Options are passed directly to the underlying matrix type. - * - * The homography is internally represented and stored by a matrix which - * is available through the matrix() method. To understand the behavior of - * this class you have to think a Transform object as its internal - * matrix representation. The chosen convention is right multiply: - * - * \code v' = T * v \endcode - * - * Therefore, an affine transformation matrix M is shaped like this: - * - * \f$ \left( \begin{array}{cc} - * linear & translation\\ - * 0 ... 0 & 1 - * \end{array} \right) \f$ - * - * Note that for a projective transformation the last row can be anything, - * and then the interpretation of different parts might be slightly different. - * - * However, unlike a plain matrix, the Transform class provides many features - * simplifying both its assembly and usage. In particular, it can be composed - * with any other transformations (Transform,Translation,RotationBase,DiagonalMatrix) - * and can be directly used to transform implicit homogeneous vectors. All these - * operations are handled via the operator*. For the composition of transformations, - * its principle consists to first convert the right/left hand sides of the product - * to a compatible (Dim+1)^2 matrix and then perform a pure matrix product. - * Of course, internally, operator* tries to perform the minimal number of operations - * according to the nature of each terms. Likewise, when applying the transform - * to points, the latters are automatically promoted to homogeneous vectors - * before doing the matrix product. The conventions to homogeneous representations - * are performed as follow: - * - * \b Translation t (Dim)x(1): - * \f$ \left( \begin{array}{cc} - * I & t \\ - * 0\,...\,0 & 1 - * \end{array} \right) \f$ - * - * \b Rotation R (Dim)x(Dim): - * \f$ \left( \begin{array}{cc} - * R & 0\\ - * 0\,...\,0 & 1 - * \end{array} \right) \f$ - *<!-- - * \b Linear \b Matrix L (Dim)x(Dim): - * \f$ \left( \begin{array}{cc} - * L & 0\\ - * 0\,...\,0 & 1 - * \end{array} \right) \f$ - * - * \b Affine \b Matrix A (Dim)x(Dim+1): - * \f$ \left( \begin{array}{c} - * A\\ - * 0\,...\,0\,1 - * \end{array} \right) \f$ - *--> - * \b Scaling \b DiagonalMatrix S (Dim)x(Dim): - * \f$ \left( \begin{array}{cc} - * S & 0\\ - * 0\,...\,0 & 1 - * \end{array} \right) \f$ - * - * \b Column \b point v (Dim)x(1): - * \f$ \left( \begin{array}{c} - * v\\ - * 1 - * \end{array} \right) \f$ - * - * \b Set \b of \b column \b points V1...Vn (Dim)x(n): - * \f$ \left( \begin{array}{ccc} - * v_1 & ... & v_n\\ - * 1 & ... & 1 - * \end{array} \right) \f$ - * - * The concatenation of a Transform object with any kind of other transformation - * always returns a Transform object. - * - * A little exception to the "as pure matrix product" rule is the case of the - * transformation of non homogeneous vectors by an affine transformation. In - * that case the last matrix row can be ignored, and the product returns non - * homogeneous vectors. - * - * Since, for instance, a Dim x Dim matrix is interpreted as a linear transformation, - * it is not possible to directly transform Dim vectors stored in a Dim x Dim matrix. - * The solution is either to use a Dim x Dynamic matrix or explicitly request a - * vector transformation by making the vector homogeneous: - * \code - * m' = T * m.colwise().homogeneous(); - * \endcode - * Note that there is zero overhead. - * - * Conversion methods from/to Qt's QMatrix and QTransform are available if the - * preprocessor token EIGEN_QT_SUPPORT is defined. - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_TRANSFORM_PLUGIN. - * - * \sa class Matrix, class Quaternion - */ -template<typename _Scalar, int _Dim, int _Mode, int _Options> -class Transform -{ -public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim==Dynamic ? Dynamic : (_Dim+1)*(_Dim+1)) - enum { - Mode = _Mode, - Options = _Options, - Dim = _Dim, ///< space dimension in which the transformation holds - HDim = _Dim+1, ///< size of a respective homogeneous vector - Rows = int(Mode)==(AffineCompact) ? Dim : HDim - }; - /** the scalar type of the coefficients */ - typedef _Scalar Scalar; - typedef Eigen::Index StorageIndex; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - /** type of the matrix used to represent the transformation */ - typedef typename internal::make_proper_matrix_type<Scalar,Rows,HDim,Options>::type MatrixType; - /** constified MatrixType */ - typedef const MatrixType ConstMatrixType; - /** type of the matrix used to represent the linear part of the transformation */ - typedef Matrix<Scalar,Dim,Dim,Options> LinearMatrixType; - /** type of read/write reference to the linear part of the transformation */ - typedef Block<MatrixType,Dim,Dim,int(Mode)==(AffineCompact) && (Options&RowMajor)==0> LinearPart; - /** type of read reference to the linear part of the transformation */ - typedef const Block<ConstMatrixType,Dim,Dim,int(Mode)==(AffineCompact) && (Options&RowMajor)==0> ConstLinearPart; - /** type of read/write reference to the affine part of the transformation */ - typedef typename internal::conditional<int(Mode)==int(AffineCompact), - MatrixType&, - Block<MatrixType,Dim,HDim> >::type AffinePart; - /** type of read reference to the affine part of the transformation */ - typedef typename internal::conditional<int(Mode)==int(AffineCompact), - const MatrixType&, - const Block<const MatrixType,Dim,HDim> >::type ConstAffinePart; - /** type of a vector */ - typedef Matrix<Scalar,Dim,1> VectorType; - /** type of a read/write reference to the translation part of the rotation */ - typedef Block<MatrixType,Dim,1,!(internal::traits<MatrixType>::Flags & RowMajorBit)> TranslationPart; - /** type of a read reference to the translation part of the rotation */ - typedef const Block<ConstMatrixType,Dim,1,!(internal::traits<MatrixType>::Flags & RowMajorBit)> ConstTranslationPart; - /** corresponding translation type */ - typedef Translation<Scalar,Dim> TranslationType; - - // this intermediate enum is needed to avoid an ICE with gcc 3.4 and 4.0 - enum { TransformTimeDiagonalMode = ((Mode==int(Isometry))?Affine:int(Mode)) }; - /** The return type of the product between a diagonal matrix and a transform */ - typedef Transform<Scalar,Dim,TransformTimeDiagonalMode> TransformTimeDiagonalReturnType; - -protected: - - MatrixType m_matrix; - -public: - - /** Default constructor without initialization of the meaningful coefficients. - * If Mode==Affine or Mode==Isometry, then the last row is set to [0 ... 0 1] */ - EIGEN_DEVICE_FUNC inline Transform() - { - check_template_params(); - internal::transform_make_affine<(int(Mode)==Affine || int(Mode)==Isometry) ? Affine : AffineCompact>::run(m_matrix); - } - - EIGEN_DEVICE_FUNC inline Transform(const Transform& other) - { - check_template_params(); - m_matrix = other.m_matrix; - } - - EIGEN_DEVICE_FUNC inline explicit Transform(const TranslationType& t) - { - check_template_params(); - *this = t; - } - EIGEN_DEVICE_FUNC inline explicit Transform(const UniformScaling<Scalar>& s) - { - check_template_params(); - *this = s; - } - template<typename Derived> - EIGEN_DEVICE_FUNC inline explicit Transform(const RotationBase<Derived, Dim>& r) - { - check_template_params(); - *this = r; - } - - EIGEN_DEVICE_FUNC inline Transform& operator=(const Transform& other) - { m_matrix = other.m_matrix; return *this; } - - typedef internal::transform_take_affine_part<Transform> take_affine_part; - - /** Constructs and initializes a transformation from a Dim^2 or a (Dim+1)^2 matrix. */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC inline explicit Transform(const EigenBase<OtherDerived>& other) - { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar,typename OtherDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY); - - check_template_params(); - internal::transform_construct_from_matrix<OtherDerived,Mode,Options,Dim,HDim>::run(this, other.derived()); - } - - /** Set \c *this from a Dim^2 or (Dim+1)^2 matrix. */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC inline Transform& operator=(const EigenBase<OtherDerived>& other) - { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar,typename OtherDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY); - - internal::transform_construct_from_matrix<OtherDerived,Mode,Options,Dim,HDim>::run(this, other.derived()); - return *this; - } - - template<int OtherOptions> - EIGEN_DEVICE_FUNC inline Transform(const Transform<Scalar,Dim,Mode,OtherOptions>& other) - { - check_template_params(); - // only the options change, we can directly copy the matrices - m_matrix = other.matrix(); - } - - template<int OtherMode,int OtherOptions> - EIGEN_DEVICE_FUNC inline Transform(const Transform<Scalar,Dim,OtherMode,OtherOptions>& other) - { - check_template_params(); - // prevent conversions as: - // Affine | AffineCompact | Isometry = Projective - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(OtherMode==int(Projective), Mode==int(Projective)), - YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION) - - // prevent conversions as: - // Isometry = Affine | AffineCompact - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(OtherMode==int(Affine)||OtherMode==int(AffineCompact), Mode!=int(Isometry)), - YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION) - - enum { ModeIsAffineCompact = Mode == int(AffineCompact), - OtherModeIsAffineCompact = OtherMode == int(AffineCompact) - }; - - if(EIGEN_CONST_CONDITIONAL(ModeIsAffineCompact == OtherModeIsAffineCompact)) - { - // We need the block expression because the code is compiled for all - // combinations of transformations and will trigger a compile time error - // if one tries to assign the matrices directly - m_matrix.template block<Dim,Dim+1>(0,0) = other.matrix().template block<Dim,Dim+1>(0,0); - makeAffine(); - } - else if(EIGEN_CONST_CONDITIONAL(OtherModeIsAffineCompact)) - { - typedef typename Transform<Scalar,Dim,OtherMode,OtherOptions>::MatrixType OtherMatrixType; - internal::transform_construct_from_matrix<OtherMatrixType,Mode,Options,Dim,HDim>::run(this, other.matrix()); - } - else - { - // here we know that Mode == AffineCompact and OtherMode != AffineCompact. - // if OtherMode were Projective, the static assert above would already have caught it. - // So the only possibility is that OtherMode == Affine - linear() = other.linear(); - translation() = other.translation(); - } - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC Transform(const ReturnByValue<OtherDerived>& other) - { - check_template_params(); - other.evalTo(*this); - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC Transform& operator=(const ReturnByValue<OtherDerived>& other) - { - other.evalTo(*this); - return *this; - } - - #ifdef EIGEN_QT_SUPPORT - inline Transform(const QMatrix& other); - inline Transform& operator=(const QMatrix& other); - inline QMatrix toQMatrix(void) const; - inline Transform(const QTransform& other); - inline Transform& operator=(const QTransform& other); - inline QTransform toQTransform(void) const; - #endif - - EIGEN_DEVICE_FUNC Index rows() const { return int(Mode)==int(Projective) ? m_matrix.cols() : (m_matrix.cols()-1); } - EIGEN_DEVICE_FUNC Index cols() const { return m_matrix.cols(); } - - /** shortcut for m_matrix(row,col); - * \sa MatrixBase::operator(Index,Index) const */ - EIGEN_DEVICE_FUNC inline Scalar operator() (Index row, Index col) const { return m_matrix(row,col); } - /** shortcut for m_matrix(row,col); - * \sa MatrixBase::operator(Index,Index) */ - EIGEN_DEVICE_FUNC inline Scalar& operator() (Index row, Index col) { return m_matrix(row,col); } - - /** \returns a read-only expression of the transformation matrix */ - EIGEN_DEVICE_FUNC inline const MatrixType& matrix() const { return m_matrix; } - /** \returns a writable expression of the transformation matrix */ - EIGEN_DEVICE_FUNC inline MatrixType& matrix() { return m_matrix; } - - /** \returns a read-only expression of the linear part of the transformation */ - EIGEN_DEVICE_FUNC inline ConstLinearPart linear() const { return ConstLinearPart(m_matrix,0,0); } - /** \returns a writable expression of the linear part of the transformation */ - EIGEN_DEVICE_FUNC inline LinearPart linear() { return LinearPart(m_matrix,0,0); } - - /** \returns a read-only expression of the Dim x HDim affine part of the transformation */ - EIGEN_DEVICE_FUNC inline ConstAffinePart affine() const { return take_affine_part::run(m_matrix); } - /** \returns a writable expression of the Dim x HDim affine part of the transformation */ - EIGEN_DEVICE_FUNC inline AffinePart affine() { return take_affine_part::run(m_matrix); } - - /** \returns a read-only expression of the translation vector of the transformation */ - EIGEN_DEVICE_FUNC inline ConstTranslationPart translation() const { return ConstTranslationPart(m_matrix,0,Dim); } - /** \returns a writable expression of the translation vector of the transformation */ - EIGEN_DEVICE_FUNC inline TranslationPart translation() { return TranslationPart(m_matrix,0,Dim); } - - /** \returns an expression of the product between the transform \c *this and a matrix expression \a other. - * - * The right-hand-side \a other can be either: - * \li an homogeneous vector of size Dim+1, - * \li a set of homogeneous vectors of size Dim+1 x N, - * \li a transformation matrix of size Dim+1 x Dim+1. - * - * Moreover, if \c *this represents an affine transformation (i.e., Mode!=Projective), then \a other can also be: - * \li a point of size Dim (computes: \code this->linear() * other + this->translation()\endcode), - * \li a set of N points as a Dim x N matrix (computes: \code (this->linear() * other).colwise() + this->translation()\endcode), - * - * In all cases, the return type is a matrix or vector of same sizes as the right-hand-side \a other. - * - * If you want to interpret \a other as a linear or affine transformation, then first convert it to a Transform<> type, - * or do your own cooking. - * - * Finally, if you want to apply Affine transformations to vectors, then explicitly apply the linear part only: - * \code - * Affine3f A; - * Vector3f v1, v2; - * v2 = A.linear() * v1; - * \endcode - * - */ - // note: this function is defined here because some compilers cannot find the respective declaration - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename internal::transform_right_product_impl<Transform, OtherDerived>::ResultType - operator * (const EigenBase<OtherDerived> &other) const - { return internal::transform_right_product_impl<Transform, OtherDerived>::run(*this,other.derived()); } - - /** \returns the product expression of a transformation matrix \a a times a transform \a b - * - * The left hand side \a other can be either: - * \li a linear transformation matrix of size Dim x Dim, - * \li an affine transformation matrix of size Dim x Dim+1, - * \li a general transformation matrix of size Dim+1 x Dim+1. - */ - template<typename OtherDerived> friend - EIGEN_DEVICE_FUNC inline const typename internal::transform_left_product_impl<OtherDerived,Mode,Options,_Dim,_Dim+1>::ResultType - operator * (const EigenBase<OtherDerived> &a, const Transform &b) - { return internal::transform_left_product_impl<OtherDerived,Mode,Options,Dim,HDim>::run(a.derived(),b); } - - /** \returns The product expression of a transform \a a times a diagonal matrix \a b - * - * The rhs diagonal matrix is interpreted as an affine scaling transformation. The - * product results in a Transform of the same type (mode) as the lhs only if the lhs - * mode is no isometry. In that case, the returned transform is an affinity. - */ - template<typename DiagonalDerived> - EIGEN_DEVICE_FUNC inline const TransformTimeDiagonalReturnType - operator * (const DiagonalBase<DiagonalDerived> &b) const - { - TransformTimeDiagonalReturnType res(*this); - res.linearExt() *= b; - return res; - } - - /** \returns The product expression of a diagonal matrix \a a times a transform \a b - * - * The lhs diagonal matrix is interpreted as an affine scaling transformation. The - * product results in a Transform of the same type (mode) as the lhs only if the lhs - * mode is no isometry. In that case, the returned transform is an affinity. - */ - template<typename DiagonalDerived> - EIGEN_DEVICE_FUNC friend inline TransformTimeDiagonalReturnType - operator * (const DiagonalBase<DiagonalDerived> &a, const Transform &b) - { - TransformTimeDiagonalReturnType res; - res.linear().noalias() = a*b.linear(); - res.translation().noalias() = a*b.translation(); - if (EIGEN_CONST_CONDITIONAL(Mode!=int(AffineCompact))) - res.matrix().row(Dim) = b.matrix().row(Dim); - return res; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC inline Transform& operator*=(const EigenBase<OtherDerived>& other) { return *this = *this * other; } - - /** Concatenates two transformations */ - EIGEN_DEVICE_FUNC inline const Transform operator * (const Transform& other) const - { - return internal::transform_transform_product_impl<Transform,Transform>::run(*this,other); - } - - #if EIGEN_COMP_ICC -private: - // this intermediate structure permits to workaround a bug in ICC 11: - // error: template instantiation resulted in unexpected function type of "Eigen::Transform<double, 3, 32, 0> - // (const Eigen::Transform<double, 3, 2, 0> &) const" - // (the meaning of a name may have changed since the template declaration -- the type of the template is: - // "Eigen::internal::transform_transform_product_impl<Eigen::Transform<double, 3, 32, 0>, - // Eigen::Transform<double, 3, Mode, Options>, <expression>>::ResultType (const Eigen::Transform<double, 3, Mode, Options> &) const") - // - template<int OtherMode,int OtherOptions> struct icc_11_workaround - { - typedef internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> > ProductType; - typedef typename ProductType::ResultType ResultType; - }; - -public: - /** Concatenates two different transformations */ - template<int OtherMode,int OtherOptions> - inline typename icc_11_workaround<OtherMode,OtherOptions>::ResultType - operator * (const Transform<Scalar,Dim,OtherMode,OtherOptions>& other) const - { - typedef typename icc_11_workaround<OtherMode,OtherOptions>::ProductType ProductType; - return ProductType::run(*this,other); - } - #else - /** Concatenates two different transformations */ - template<int OtherMode,int OtherOptions> - EIGEN_DEVICE_FUNC inline typename internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> >::ResultType - operator * (const Transform<Scalar,Dim,OtherMode,OtherOptions>& other) const - { - return internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> >::run(*this,other); - } - #endif - - /** \sa MatrixBase::setIdentity() */ - EIGEN_DEVICE_FUNC void setIdentity() { m_matrix.setIdentity(); } - - /** - * \brief Returns an identity transformation. - * \todo In the future this function should be returning a Transform expression. - */ - EIGEN_DEVICE_FUNC static const Transform Identity() - { - return Transform(MatrixType::Identity()); - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - inline Transform& scale(const MatrixBase<OtherDerived> &other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - inline Transform& prescale(const MatrixBase<OtherDerived> &other); - - EIGEN_DEVICE_FUNC inline Transform& scale(const Scalar& s); - EIGEN_DEVICE_FUNC inline Transform& prescale(const Scalar& s); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - inline Transform& translate(const MatrixBase<OtherDerived> &other); - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - inline Transform& pretranslate(const MatrixBase<OtherDerived> &other); - - template<typename RotationType> - EIGEN_DEVICE_FUNC - inline Transform& rotate(const RotationType& rotation); - - template<typename RotationType> - EIGEN_DEVICE_FUNC - inline Transform& prerotate(const RotationType& rotation); - - EIGEN_DEVICE_FUNC Transform& shear(const Scalar& sx, const Scalar& sy); - EIGEN_DEVICE_FUNC Transform& preshear(const Scalar& sx, const Scalar& sy); - - EIGEN_DEVICE_FUNC inline Transform& operator=(const TranslationType& t); - - EIGEN_DEVICE_FUNC - inline Transform& operator*=(const TranslationType& t) { return translate(t.vector()); } - - EIGEN_DEVICE_FUNC inline Transform operator*(const TranslationType& t) const; - - EIGEN_DEVICE_FUNC - inline Transform& operator=(const UniformScaling<Scalar>& t); - - EIGEN_DEVICE_FUNC - inline Transform& operator*=(const UniformScaling<Scalar>& s) { return scale(s.factor()); } - - EIGEN_DEVICE_FUNC - inline TransformTimeDiagonalReturnType operator*(const UniformScaling<Scalar>& s) const - { - TransformTimeDiagonalReturnType res = *this; - res.scale(s.factor()); - return res; - } - - EIGEN_DEVICE_FUNC - inline Transform& operator*=(const DiagonalMatrix<Scalar,Dim>& s) { linearExt() *= s; return *this; } - - template<typename Derived> - EIGEN_DEVICE_FUNC inline Transform& operator=(const RotationBase<Derived,Dim>& r); - template<typename Derived> - EIGEN_DEVICE_FUNC inline Transform& operator*=(const RotationBase<Derived,Dim>& r) { return rotate(r.toRotationMatrix()); } - template<typename Derived> - EIGEN_DEVICE_FUNC inline Transform operator*(const RotationBase<Derived,Dim>& r) const; - - typedef typename internal::conditional<int(Mode)==Isometry,ConstLinearPart,const LinearMatrixType>::type RotationReturnType; - EIGEN_DEVICE_FUNC RotationReturnType rotation() const; - - template<typename RotationMatrixType, typename ScalingMatrixType> - EIGEN_DEVICE_FUNC - void computeRotationScaling(RotationMatrixType *rotation, ScalingMatrixType *scaling) const; - template<typename ScalingMatrixType, typename RotationMatrixType> - EIGEN_DEVICE_FUNC - void computeScalingRotation(ScalingMatrixType *scaling, RotationMatrixType *rotation) const; - - template<typename PositionDerived, typename OrientationType, typename ScaleDerived> - EIGEN_DEVICE_FUNC - Transform& fromPositionOrientationScale(const MatrixBase<PositionDerived> &position, - const OrientationType& orientation, const MatrixBase<ScaleDerived> &scale); - - EIGEN_DEVICE_FUNC - inline Transform inverse(TransformTraits traits = (TransformTraits)Mode) const; - - /** \returns a const pointer to the column major internal matrix */ - EIGEN_DEVICE_FUNC const Scalar* data() const { return m_matrix.data(); } - /** \returns a non-const pointer to the column major internal matrix */ - EIGEN_DEVICE_FUNC Scalar* data() { return m_matrix.data(); } - - /** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Transform,Transform<NewScalarType,Dim,Mode,Options> >::type cast() const - { return typename internal::cast_return_type<Transform,Transform<NewScalarType,Dim,Mode,Options> >::type(*this); } - - /** Copy constructor with scalar type conversion */ - template<typename OtherScalarType> - EIGEN_DEVICE_FUNC inline explicit Transform(const Transform<OtherScalarType,Dim,Mode,Options>& other) - { - check_template_params(); - m_matrix = other.matrix().template cast<Scalar>(); - } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - EIGEN_DEVICE_FUNC bool isApprox(const Transform& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const - { return m_matrix.isApprox(other.m_matrix, prec); } - - /** Sets the last row to [0 ... 0 1] - */ - EIGEN_DEVICE_FUNC void makeAffine() - { - internal::transform_make_affine<int(Mode)>::run(m_matrix); - } - - /** \internal - * \returns the Dim x Dim linear part if the transformation is affine, - * and the HDim x Dim part for projective transformations. - */ - EIGEN_DEVICE_FUNC inline Block<MatrixType,int(Mode)==int(Projective)?HDim:Dim,Dim> linearExt() - { return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); } - /** \internal - * \returns the Dim x Dim linear part if the transformation is affine, - * and the HDim x Dim part for projective transformations. - */ - EIGEN_DEVICE_FUNC inline const Block<MatrixType,int(Mode)==int(Projective)?HDim:Dim,Dim> linearExt() const - { return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); } - - /** \internal - * \returns the translation part if the transformation is affine, - * and the last column for projective transformations. - */ - EIGEN_DEVICE_FUNC inline Block<MatrixType,int(Mode)==int(Projective)?HDim:Dim,1> translationExt() - { return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); } - /** \internal - * \returns the translation part if the transformation is affine, - * and the last column for projective transformations. - */ - EIGEN_DEVICE_FUNC inline const Block<MatrixType,int(Mode)==int(Projective)?HDim:Dim,1> translationExt() const - { return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); } - - - #ifdef EIGEN_TRANSFORM_PLUGIN - #include EIGEN_TRANSFORM_PLUGIN - #endif - -protected: - #ifndef EIGEN_PARSED_BY_DOXYGEN - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void check_template_params() - { - EIGEN_STATIC_ASSERT((Options & (DontAlign|RowMajor)) == Options, INVALID_MATRIX_TEMPLATE_PARAMETERS) - } - #endif - -}; - -/** \ingroup Geometry_Module */ -typedef Transform<float,2,Isometry> Isometry2f; -/** \ingroup Geometry_Module */ -typedef Transform<float,3,Isometry> Isometry3f; -/** \ingroup Geometry_Module */ -typedef Transform<double,2,Isometry> Isometry2d; -/** \ingroup Geometry_Module */ -typedef Transform<double,3,Isometry> Isometry3d; - -/** \ingroup Geometry_Module */ -typedef Transform<float,2,Affine> Affine2f; -/** \ingroup Geometry_Module */ -typedef Transform<float,3,Affine> Affine3f; -/** \ingroup Geometry_Module */ -typedef Transform<double,2,Affine> Affine2d; -/** \ingroup Geometry_Module */ -typedef Transform<double,3,Affine> Affine3d; - -/** \ingroup Geometry_Module */ -typedef Transform<float,2,AffineCompact> AffineCompact2f; -/** \ingroup Geometry_Module */ -typedef Transform<float,3,AffineCompact> AffineCompact3f; -/** \ingroup Geometry_Module */ -typedef Transform<double,2,AffineCompact> AffineCompact2d; -/** \ingroup Geometry_Module */ -typedef Transform<double,3,AffineCompact> AffineCompact3d; - -/** \ingroup Geometry_Module */ -typedef Transform<float,2,Projective> Projective2f; -/** \ingroup Geometry_Module */ -typedef Transform<float,3,Projective> Projective3f; -/** \ingroup Geometry_Module */ -typedef Transform<double,2,Projective> Projective2d; -/** \ingroup Geometry_Module */ -typedef Transform<double,3,Projective> Projective3d; - -/************************** -*** Optional QT support *** -**************************/ - -#ifdef EIGEN_QT_SUPPORT -/** Initializes \c *this from a QMatrix assuming the dimension is 2. - * - * This function is available only if the token EIGEN_QT_SUPPORT is defined. - */ -template<typename Scalar, int Dim, int Mode,int Options> -Transform<Scalar,Dim,Mode,Options>::Transform(const QMatrix& other) -{ - check_template_params(); - *this = other; -} - -/** Set \c *this from a QMatrix assuming the dimension is 2. - * - * This function is available only if the token EIGEN_QT_SUPPORT is defined. - */ -template<typename Scalar, int Dim, int Mode,int Options> -Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const QMatrix& other) -{ - EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE) - if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact))) - m_matrix << other.m11(), other.m21(), other.dx(), - other.m12(), other.m22(), other.dy(); - else - m_matrix << other.m11(), other.m21(), other.dx(), - other.m12(), other.m22(), other.dy(), - 0, 0, 1; - return *this; -} - -/** \returns a QMatrix from \c *this assuming the dimension is 2. - * - * \warning this conversion might loss data if \c *this is not affine - * - * This function is available only if the token EIGEN_QT_SUPPORT is defined. - */ -template<typename Scalar, int Dim, int Mode, int Options> -QMatrix Transform<Scalar,Dim,Mode,Options>::toQMatrix(void) const -{ - check_template_params(); - EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE) - return QMatrix(m_matrix.coeff(0,0), m_matrix.coeff(1,0), - m_matrix.coeff(0,1), m_matrix.coeff(1,1), - m_matrix.coeff(0,2), m_matrix.coeff(1,2)); -} - -/** Initializes \c *this from a QTransform assuming the dimension is 2. - * - * This function is available only if the token EIGEN_QT_SUPPORT is defined. - */ -template<typename Scalar, int Dim, int Mode,int Options> -Transform<Scalar,Dim,Mode,Options>::Transform(const QTransform& other) -{ - check_template_params(); - *this = other; -} - -/** Set \c *this from a QTransform assuming the dimension is 2. - * - * This function is available only if the token EIGEN_QT_SUPPORT is defined. - */ -template<typename Scalar, int Dim, int Mode, int Options> -Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const QTransform& other) -{ - check_template_params(); - EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE) - if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact))) - m_matrix << other.m11(), other.m21(), other.dx(), - other.m12(), other.m22(), other.dy(); - else - m_matrix << other.m11(), other.m21(), other.dx(), - other.m12(), other.m22(), other.dy(), - other.m13(), other.m23(), other.m33(); - return *this; -} - -/** \returns a QTransform from \c *this assuming the dimension is 2. - * - * This function is available only if the token EIGEN_QT_SUPPORT is defined. - */ -template<typename Scalar, int Dim, int Mode, int Options> -QTransform Transform<Scalar,Dim,Mode,Options>::toQTransform(void) const -{ - EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE) - if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact))) - return QTransform(m_matrix.coeff(0,0), m_matrix.coeff(1,0), - m_matrix.coeff(0,1), m_matrix.coeff(1,1), - m_matrix.coeff(0,2), m_matrix.coeff(1,2)); - else - return QTransform(m_matrix.coeff(0,0), m_matrix.coeff(1,0), m_matrix.coeff(2,0), - m_matrix.coeff(0,1), m_matrix.coeff(1,1), m_matrix.coeff(2,1), - m_matrix.coeff(0,2), m_matrix.coeff(1,2), m_matrix.coeff(2,2)); -} -#endif - -/********************* -*** Procedural API *** -*********************/ - -/** Applies on the right the non uniform scale transformation represented - * by the vector \a other to \c *this and returns a reference to \c *this. - * \sa prescale() - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::scale(const MatrixBase<OtherDerived> &other) -{ - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim)) - EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) - linearExt().noalias() = (linearExt() * other.asDiagonal()); - return *this; -} - -/** Applies on the right a uniform scale of a factor \a c to \c *this - * and returns a reference to \c *this. - * \sa prescale(Scalar) - */ -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::scale(const Scalar& s) -{ - EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) - linearExt() *= s; - return *this; -} - -/** Applies on the left the non uniform scale transformation represented - * by the vector \a other to \c *this and returns a reference to \c *this. - * \sa scale() - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::prescale(const MatrixBase<OtherDerived> &other) -{ - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim)) - EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) - affine().noalias() = (other.asDiagonal() * affine()); - return *this; -} - -/** Applies on the left a uniform scale of a factor \a c to \c *this - * and returns a reference to \c *this. - * \sa scale(Scalar) - */ -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::prescale(const Scalar& s) -{ - EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) - m_matrix.template topRows<Dim>() *= s; - return *this; -} - -/** Applies on the right the translation matrix represented by the vector \a other - * to \c *this and returns a reference to \c *this. - * \sa pretranslate() - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::translate(const MatrixBase<OtherDerived> &other) -{ - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim)) - translationExt() += linearExt() * other; - return *this; -} - -/** Applies on the left the translation matrix represented by the vector \a other - * to \c *this and returns a reference to \c *this. - * \sa translate() - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::pretranslate(const MatrixBase<OtherDerived> &other) -{ - EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim)) - if(EIGEN_CONST_CONDITIONAL(int(Mode)==int(Projective))) - affine() += other * m_matrix.row(Dim); - else - translation() += other; - return *this; -} - -/** Applies on the right the rotation represented by the rotation \a rotation - * to \c *this and returns a reference to \c *this. - * - * The template parameter \a RotationType is the type of the rotation which - * must be known by internal::toRotationMatrix<>. - * - * Natively supported types includes: - * - any scalar (2D), - * - a Dim x Dim matrix expression, - * - a Quaternion (3D), - * - a AngleAxis (3D) - * - * This mechanism is easily extendable to support user types such as Euler angles, - * or a pair of Quaternion for 4D rotations. - * - * \sa rotate(Scalar), class Quaternion, class AngleAxis, prerotate(RotationType) - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename RotationType> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::rotate(const RotationType& rotation) -{ - linearExt() *= internal::toRotationMatrix<Scalar,Dim>(rotation); - return *this; -} - -/** Applies on the left the rotation represented by the rotation \a rotation - * to \c *this and returns a reference to \c *this. - * - * See rotate() for further details. - * - * \sa rotate() - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename RotationType> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::prerotate(const RotationType& rotation) -{ - m_matrix.template block<Dim,HDim>(0,0) = internal::toRotationMatrix<Scalar,Dim>(rotation) - * m_matrix.template block<Dim,HDim>(0,0); - return *this; -} - -/** Applies on the right the shear transformation represented - * by the vector \a other to \c *this and returns a reference to \c *this. - * \warning 2D only. - * \sa preshear() - */ -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::shear(const Scalar& sx, const Scalar& sy) -{ - EIGEN_STATIC_ASSERT(int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE) - EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) - VectorType tmp = linear().col(0)*sy + linear().col(1); - linear() << linear().col(0) + linear().col(1)*sx, tmp; - return *this; -} - -/** Applies on the left the shear transformation represented - * by the vector \a other to \c *this and returns a reference to \c *this. - * \warning 2D only. - * \sa shear() - */ -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::preshear(const Scalar& sx, const Scalar& sy) -{ - EIGEN_STATIC_ASSERT(int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE) - EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS) - m_matrix.template block<Dim,HDim>(0,0) = LinearMatrixType(1, sx, sy, 1) * m_matrix.template block<Dim,HDim>(0,0); - return *this; -} - -/****************************************************** -*** Scaling, Translation and Rotation compatibility *** -******************************************************/ - -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const TranslationType& t) -{ - linear().setIdentity(); - translation() = t.vector(); - makeAffine(); - return *this; -} - -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options> Transform<Scalar,Dim,Mode,Options>::operator*(const TranslationType& t) const -{ - Transform res = *this; - res.translate(t.vector()); - return res; -} - -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const UniformScaling<Scalar>& s) -{ - m_matrix.setZero(); - linear().diagonal().fill(s.factor()); - makeAffine(); - return *this; -} - -template<typename Scalar, int Dim, int Mode, int Options> -template<typename Derived> -EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const RotationBase<Derived,Dim>& r) -{ - linear() = internal::toRotationMatrix<Scalar,Dim>(r); - translation().setZero(); - makeAffine(); - return *this; -} - -template<typename Scalar, int Dim, int Mode, int Options> -template<typename Derived> -EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options> Transform<Scalar,Dim,Mode,Options>::operator*(const RotationBase<Derived,Dim>& r) const -{ - Transform res = *this; - res.rotate(r.derived()); - return res; -} - -/************************ -*** Special functions *** -************************/ - -namespace internal { -template<int Mode> struct transform_rotation_impl { - template<typename TransformType> - EIGEN_DEVICE_FUNC static inline - const typename TransformType::LinearMatrixType run(const TransformType& t) - { - typedef typename TransformType::LinearMatrixType LinearMatrixType; - LinearMatrixType result; - t.computeRotationScaling(&result, (LinearMatrixType*)0); - return result; - } -}; -template<> struct transform_rotation_impl<Isometry> { - template<typename TransformType> - EIGEN_DEVICE_FUNC static inline - typename TransformType::ConstLinearPart run(const TransformType& t) - { - return t.linear(); - } -}; -} -/** \returns the rotation part of the transformation - * - * If Mode==Isometry, then this method is an alias for linear(), - * otherwise it calls computeRotationScaling() to extract the rotation - * through a SVD decomposition. - * - * \svd_module - * - * \sa computeRotationScaling(), computeScalingRotation(), class SVD - */ -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC -typename Transform<Scalar,Dim,Mode,Options>::RotationReturnType -Transform<Scalar,Dim,Mode,Options>::rotation() const -{ - return internal::transform_rotation_impl<Mode>::run(*this); -} - - -/** decomposes the linear part of the transformation as a product rotation x scaling, the scaling being - * not necessarily positive. - * - * If either pointer is zero, the corresponding computation is skipped. - * - * - * - * \svd_module - * - * \sa computeScalingRotation(), rotation(), class SVD - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename RotationMatrixType, typename ScalingMatrixType> -EIGEN_DEVICE_FUNC void Transform<Scalar,Dim,Mode,Options>::computeRotationScaling(RotationMatrixType *rotation, ScalingMatrixType *scaling) const -{ - JacobiSVD<LinearMatrixType> svd(linear(), ComputeFullU | ComputeFullV); - - Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant(); // so x has absolute value 1 - VectorType sv(svd.singularValues()); - sv.coeffRef(0) *= x; - if(scaling) *scaling = svd.matrixV() * sv.asDiagonal() * svd.matrixV().adjoint(); - if(rotation) - { - LinearMatrixType m(svd.matrixU()); - m.col(0) /= x; - *rotation = m * svd.matrixV().adjoint(); - } -} - -/** decomposes the linear part of the transformation as a product scaling x rotation, the scaling being - * not necessarily positive. - * - * If either pointer is zero, the corresponding computation is skipped. - * - * - * - * \svd_module - * - * \sa computeRotationScaling(), rotation(), class SVD - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename ScalingMatrixType, typename RotationMatrixType> -EIGEN_DEVICE_FUNC void Transform<Scalar,Dim,Mode,Options>::computeScalingRotation(ScalingMatrixType *scaling, RotationMatrixType *rotation) const -{ - JacobiSVD<LinearMatrixType> svd(linear(), ComputeFullU | ComputeFullV); - - Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant(); // so x has absolute value 1 - VectorType sv(svd.singularValues()); - sv.coeffRef(0) *= x; - if(scaling) *scaling = svd.matrixU() * sv.asDiagonal() * svd.matrixU().adjoint(); - if(rotation) - { - LinearMatrixType m(svd.matrixU()); - m.col(0) /= x; - *rotation = m * svd.matrixV().adjoint(); - } -} - -/** Convenient method to set \c *this from a position, orientation and scale - * of a 3D object. - */ -template<typename Scalar, int Dim, int Mode, int Options> -template<typename PositionDerived, typename OrientationType, typename ScaleDerived> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>& -Transform<Scalar,Dim,Mode,Options>::fromPositionOrientationScale(const MatrixBase<PositionDerived> &position, - const OrientationType& orientation, const MatrixBase<ScaleDerived> &scale) -{ - linear() = internal::toRotationMatrix<Scalar,Dim>(orientation); - linear() *= scale.asDiagonal(); - translation() = position; - makeAffine(); - return *this; -} - -namespace internal { - -template<int Mode> -struct transform_make_affine -{ - template<typename MatrixType> - EIGEN_DEVICE_FUNC static void run(MatrixType &mat) - { - static const int Dim = MatrixType::ColsAtCompileTime-1; - mat.template block<1,Dim>(Dim,0).setZero(); - mat.coeffRef(Dim,Dim) = typename MatrixType::Scalar(1); - } -}; - -template<> -struct transform_make_affine<AffineCompact> -{ - template<typename MatrixType> EIGEN_DEVICE_FUNC static void run(MatrixType &) { } -}; - -// selector needed to avoid taking the inverse of a 3x4 matrix -template<typename TransformType, int Mode=TransformType::Mode> -struct projective_transform_inverse -{ - EIGEN_DEVICE_FUNC static inline void run(const TransformType&, TransformType&) - {} -}; - -template<typename TransformType> -struct projective_transform_inverse<TransformType, Projective> -{ - EIGEN_DEVICE_FUNC static inline void run(const TransformType& m, TransformType& res) - { - res.matrix() = m.matrix().inverse(); - } -}; - -} // end namespace internal - - -/** - * - * \returns the inverse transformation according to some given knowledge - * on \c *this. - * - * \param hint allows to optimize the inversion process when the transformation - * is known to be not a general transformation (optional). The possible values are: - * - #Projective if the transformation is not necessarily affine, i.e., if the - * last row is not guaranteed to be [0 ... 0 1] - * - #Affine if the last row can be assumed to be [0 ... 0 1] - * - #Isometry if the transformation is only a concatenations of translations - * and rotations. - * The default is the template class parameter \c Mode. - * - * \warning unless \a traits is always set to NoShear or NoScaling, this function - * requires the generic inverse method of MatrixBase defined in the LU module. If - * you forget to include this module, then you will get hard to debug linking errors. - * - * \sa MatrixBase::inverse() - */ -template<typename Scalar, int Dim, int Mode, int Options> -EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options> -Transform<Scalar,Dim,Mode,Options>::inverse(TransformTraits hint) const -{ - Transform res; - if (hint == Projective) - { - internal::projective_transform_inverse<Transform>::run(*this, res); - } - else - { - if (hint == Isometry) - { - res.matrix().template topLeftCorner<Dim,Dim>() = linear().transpose(); - } - else if(hint&Affine) - { - res.matrix().template topLeftCorner<Dim,Dim>() = linear().inverse(); - } - else - { - eigen_assert(false && "Invalid transform traits in Transform::Inverse"); - } - // translation and remaining parts - res.matrix().template topRightCorner<Dim,1>() - = - res.matrix().template topLeftCorner<Dim,Dim>() * translation(); - res.makeAffine(); // we do need this, because in the beginning res is uninitialized - } - return res; -} - -namespace internal { - -/***************************************************** -*** Specializations of take affine part *** -*****************************************************/ - -template<typename TransformType> struct transform_take_affine_part { - typedef typename TransformType::MatrixType MatrixType; - typedef typename TransformType::AffinePart AffinePart; - typedef typename TransformType::ConstAffinePart ConstAffinePart; - static inline AffinePart run(MatrixType& m) - { return m.template block<TransformType::Dim,TransformType::HDim>(0,0); } - static inline ConstAffinePart run(const MatrixType& m) - { return m.template block<TransformType::Dim,TransformType::HDim>(0,0); } -}; - -template<typename Scalar, int Dim, int Options> -struct transform_take_affine_part<Transform<Scalar,Dim,AffineCompact, Options> > { - typedef typename Transform<Scalar,Dim,AffineCompact,Options>::MatrixType MatrixType; - static inline MatrixType& run(MatrixType& m) { return m; } - static inline const MatrixType& run(const MatrixType& m) { return m; } -}; - -/***************************************************** -*** Specializations of construct from matrix *** -*****************************************************/ - -template<typename Other, int Mode, int Options, int Dim, int HDim> -struct transform_construct_from_matrix<Other, Mode,Options,Dim,HDim, Dim,Dim> -{ - static inline void run(Transform<typename Other::Scalar,Dim,Mode,Options> *transform, const Other& other) - { - transform->linear() = other; - transform->translation().setZero(); - transform->makeAffine(); - } -}; - -template<typename Other, int Mode, int Options, int Dim, int HDim> -struct transform_construct_from_matrix<Other, Mode,Options,Dim,HDim, Dim,HDim> -{ - static inline void run(Transform<typename Other::Scalar,Dim,Mode,Options> *transform, const Other& other) - { - transform->affine() = other; - transform->makeAffine(); - } -}; - -template<typename Other, int Mode, int Options, int Dim, int HDim> -struct transform_construct_from_matrix<Other, Mode,Options,Dim,HDim, HDim,HDim> -{ - static inline void run(Transform<typename Other::Scalar,Dim,Mode,Options> *transform, const Other& other) - { transform->matrix() = other; } -}; - -template<typename Other, int Options, int Dim, int HDim> -struct transform_construct_from_matrix<Other, AffineCompact,Options,Dim,HDim, HDim,HDim> -{ - static inline void run(Transform<typename Other::Scalar,Dim,AffineCompact,Options> *transform, const Other& other) - { transform->matrix() = other.template block<Dim,HDim>(0,0); } -}; - -/********************************************************** -*** Specializations of operator* with rhs EigenBase *** -**********************************************************/ - -template<int LhsMode,int RhsMode> -struct transform_product_result -{ - enum - { - Mode = - (LhsMode == (int)Projective || RhsMode == (int)Projective ) ? Projective : - (LhsMode == (int)Affine || RhsMode == (int)Affine ) ? Affine : - (LhsMode == (int)AffineCompact || RhsMode == (int)AffineCompact ) ? AffineCompact : - (LhsMode == (int)Isometry || RhsMode == (int)Isometry ) ? Isometry : Projective - }; -}; - -template< typename TransformType, typename MatrixType, int RhsCols> -struct transform_right_product_impl< TransformType, MatrixType, 0, RhsCols> -{ - typedef typename MatrixType::PlainObject ResultType; - - static EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other) - { - return T.matrix() * other; - } -}; - -template< typename TransformType, typename MatrixType, int RhsCols> -struct transform_right_product_impl< TransformType, MatrixType, 1, RhsCols> -{ - enum { - Dim = TransformType::Dim, - HDim = TransformType::HDim, - OtherRows = MatrixType::RowsAtCompileTime, - OtherCols = MatrixType::ColsAtCompileTime - }; - - typedef typename MatrixType::PlainObject ResultType; - - static EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other) - { - EIGEN_STATIC_ASSERT(OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); - - typedef Block<ResultType, Dim, OtherCols, int(MatrixType::RowsAtCompileTime)==Dim> TopLeftLhs; - - ResultType res(other.rows(),other.cols()); - TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() = T.affine() * other; - res.row(OtherRows-1) = other.row(OtherRows-1); - - return res; - } -}; - -template< typename TransformType, typename MatrixType, int RhsCols> -struct transform_right_product_impl< TransformType, MatrixType, 2, RhsCols> -{ - enum { - Dim = TransformType::Dim, - HDim = TransformType::HDim, - OtherRows = MatrixType::RowsAtCompileTime, - OtherCols = MatrixType::ColsAtCompileTime - }; - - typedef typename MatrixType::PlainObject ResultType; - - static EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other) - { - EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); - - typedef Block<ResultType, Dim, OtherCols, true> TopLeftLhs; - ResultType res(Replicate<typename TransformType::ConstTranslationPart, 1, OtherCols>(T.translation(),1,other.cols())); - TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() += T.linear() * other; - - return res; - } -}; - -template< typename TransformType, typename MatrixType > -struct transform_right_product_impl< TransformType, MatrixType, 2, 1> // rhs is a vector of size Dim -{ - typedef typename TransformType::MatrixType TransformMatrix; - enum { - Dim = TransformType::Dim, - HDim = TransformType::HDim, - OtherRows = MatrixType::RowsAtCompileTime, - WorkingRows = EIGEN_PLAIN_ENUM_MIN(TransformMatrix::RowsAtCompileTime,HDim) - }; - - typedef typename MatrixType::PlainObject ResultType; - - static EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other) - { - EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); - - Matrix<typename ResultType::Scalar, Dim+1, 1> rhs; - rhs.template head<Dim>() = other; rhs[Dim] = typename ResultType::Scalar(1); - Matrix<typename ResultType::Scalar, WorkingRows, 1> res(T.matrix() * rhs); - return res.template head<Dim>(); - } -}; - -/********************************************************** -*** Specializations of operator* with lhs EigenBase *** -**********************************************************/ - -// generic HDim x HDim matrix * T => Projective -template<typename Other,int Mode, int Options, int Dim, int HDim> -struct transform_left_product_impl<Other,Mode,Options,Dim,HDim, HDim,HDim> -{ - typedef Transform<typename Other::Scalar,Dim,Mode,Options> TransformType; - typedef typename TransformType::MatrixType MatrixType; - typedef Transform<typename Other::Scalar,Dim,Projective,Options> ResultType; - static ResultType run(const Other& other,const TransformType& tr) - { return ResultType(other * tr.matrix()); } -}; - -// generic HDim x HDim matrix * AffineCompact => Projective -template<typename Other, int Options, int Dim, int HDim> -struct transform_left_product_impl<Other,AffineCompact,Options,Dim,HDim, HDim,HDim> -{ - typedef Transform<typename Other::Scalar,Dim,AffineCompact,Options> TransformType; - typedef typename TransformType::MatrixType MatrixType; - typedef Transform<typename Other::Scalar,Dim,Projective,Options> ResultType; - static ResultType run(const Other& other,const TransformType& tr) - { - ResultType res; - res.matrix().noalias() = other.template block<HDim,Dim>(0,0) * tr.matrix(); - res.matrix().col(Dim) += other.col(Dim); - return res; - } -}; - -// affine matrix * T -template<typename Other,int Mode, int Options, int Dim, int HDim> -struct transform_left_product_impl<Other,Mode,Options,Dim,HDim, Dim,HDim> -{ - typedef Transform<typename Other::Scalar,Dim,Mode,Options> TransformType; - typedef typename TransformType::MatrixType MatrixType; - typedef TransformType ResultType; - static ResultType run(const Other& other,const TransformType& tr) - { - ResultType res; - res.affine().noalias() = other * tr.matrix(); - res.matrix().row(Dim) = tr.matrix().row(Dim); - return res; - } -}; - -// affine matrix * AffineCompact -template<typename Other, int Options, int Dim, int HDim> -struct transform_left_product_impl<Other,AffineCompact,Options,Dim,HDim, Dim,HDim> -{ - typedef Transform<typename Other::Scalar,Dim,AffineCompact,Options> TransformType; - typedef typename TransformType::MatrixType MatrixType; - typedef TransformType ResultType; - static ResultType run(const Other& other,const TransformType& tr) - { - ResultType res; - res.matrix().noalias() = other.template block<Dim,Dim>(0,0) * tr.matrix(); - res.translation() += other.col(Dim); - return res; - } -}; - -// linear matrix * T -template<typename Other,int Mode, int Options, int Dim, int HDim> -struct transform_left_product_impl<Other,Mode,Options,Dim,HDim, Dim,Dim> -{ - typedef Transform<typename Other::Scalar,Dim,Mode,Options> TransformType; - typedef typename TransformType::MatrixType MatrixType; - typedef TransformType ResultType; - static ResultType run(const Other& other, const TransformType& tr) - { - TransformType res; - if(Mode!=int(AffineCompact)) - res.matrix().row(Dim) = tr.matrix().row(Dim); - res.matrix().template topRows<Dim>().noalias() - = other * tr.matrix().template topRows<Dim>(); - return res; - } -}; - -/********************************************************** -*** Specializations of operator* with another Transform *** -**********************************************************/ - -template<typename Scalar, int Dim, int LhsMode, int LhsOptions, int RhsMode, int RhsOptions> -struct transform_transform_product_impl<Transform<Scalar,Dim,LhsMode,LhsOptions>,Transform<Scalar,Dim,RhsMode,RhsOptions>,false > -{ - enum { ResultMode = transform_product_result<LhsMode,RhsMode>::Mode }; - typedef Transform<Scalar,Dim,LhsMode,LhsOptions> Lhs; - typedef Transform<Scalar,Dim,RhsMode,RhsOptions> Rhs; - typedef Transform<Scalar,Dim,ResultMode,LhsOptions> ResultType; - static ResultType run(const Lhs& lhs, const Rhs& rhs) - { - ResultType res; - res.linear() = lhs.linear() * rhs.linear(); - res.translation() = lhs.linear() * rhs.translation() + lhs.translation(); - res.makeAffine(); - return res; - } -}; - -template<typename Scalar, int Dim, int LhsMode, int LhsOptions, int RhsMode, int RhsOptions> -struct transform_transform_product_impl<Transform<Scalar,Dim,LhsMode,LhsOptions>,Transform<Scalar,Dim,RhsMode,RhsOptions>,true > -{ - typedef Transform<Scalar,Dim,LhsMode,LhsOptions> Lhs; - typedef Transform<Scalar,Dim,RhsMode,RhsOptions> Rhs; - typedef Transform<Scalar,Dim,Projective> ResultType; - static ResultType run(const Lhs& lhs, const Rhs& rhs) - { - return ResultType( lhs.matrix() * rhs.matrix() ); - } -}; - -template<typename Scalar, int Dim, int LhsOptions, int RhsOptions> -struct transform_transform_product_impl<Transform<Scalar,Dim,AffineCompact,LhsOptions>,Transform<Scalar,Dim,Projective,RhsOptions>,true > -{ - typedef Transform<Scalar,Dim,AffineCompact,LhsOptions> Lhs; - typedef Transform<Scalar,Dim,Projective,RhsOptions> Rhs; - typedef Transform<Scalar,Dim,Projective> ResultType; - static ResultType run(const Lhs& lhs, const Rhs& rhs) - { - ResultType res; - res.matrix().template topRows<Dim>() = lhs.matrix() * rhs.matrix(); - res.matrix().row(Dim) = rhs.matrix().row(Dim); - return res; - } -}; - -template<typename Scalar, int Dim, int LhsOptions, int RhsOptions> -struct transform_transform_product_impl<Transform<Scalar,Dim,Projective,LhsOptions>,Transform<Scalar,Dim,AffineCompact,RhsOptions>,true > -{ - typedef Transform<Scalar,Dim,Projective,LhsOptions> Lhs; - typedef Transform<Scalar,Dim,AffineCompact,RhsOptions> Rhs; - typedef Transform<Scalar,Dim,Projective> ResultType; - static ResultType run(const Lhs& lhs, const Rhs& rhs) - { - ResultType res(lhs.matrix().template leftCols<Dim>() * rhs.matrix()); - res.matrix().col(Dim) += lhs.matrix().col(Dim); - return res; - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_TRANSFORM_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/Translation.h b/external/eigen/include/eigen3/Eigen/src/Geometry/Translation.h deleted file mode 100644 index 8c229012..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/Translation.h +++ /dev/null @@ -1,202 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_TRANSLATION_H -#define EIGEN_TRANSLATION_H - -namespace Eigen { - -/** \geometry_module \ingroup Geometry_Module - * - * \class Translation - * - * \brief Represents a translation transformation - * - * \tparam _Scalar the scalar type, i.e., the type of the coefficients. - * \tparam _Dim the dimension of the space, can be a compile time value or Dynamic - * - * \note This class is not aimed to be used to store a translation transformation, - * but rather to make easier the constructions and updates of Transform objects. - * - * \sa class Scaling, class Transform - */ -template<typename _Scalar, int _Dim> -class Translation -{ -public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim) - /** dimension of the space */ - enum { Dim = _Dim }; - /** the scalar type of the coefficients */ - typedef _Scalar Scalar; - /** corresponding vector type */ - typedef Matrix<Scalar,Dim,1> VectorType; - /** corresponding linear transformation matrix type */ - typedef Matrix<Scalar,Dim,Dim> LinearMatrixType; - /** corresponding affine transformation type */ - typedef Transform<Scalar,Dim,Affine> AffineTransformType; - /** corresponding isometric transformation type */ - typedef Transform<Scalar,Dim,Isometry> IsometryTransformType; - -protected: - - VectorType m_coeffs; - -public: - - /** Default constructor without initialization. */ - EIGEN_DEVICE_FUNC Translation() {} - /** */ - EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy) - { - eigen_assert(Dim==2); - m_coeffs.x() = sx; - m_coeffs.y() = sy; - } - /** */ - EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz) - { - eigen_assert(Dim==3); - m_coeffs.x() = sx; - m_coeffs.y() = sy; - m_coeffs.z() = sz; - } - /** Constructs and initialize the translation transformation from a vector of translation coefficients */ - EIGEN_DEVICE_FUNC explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {} - - /** \brief Returns the x-translation by value. **/ - EIGEN_DEVICE_FUNC inline Scalar x() const { return m_coeffs.x(); } - /** \brief Returns the y-translation by value. **/ - EIGEN_DEVICE_FUNC inline Scalar y() const { return m_coeffs.y(); } - /** \brief Returns the z-translation by value. **/ - EIGEN_DEVICE_FUNC inline Scalar z() const { return m_coeffs.z(); } - - /** \brief Returns the x-translation as a reference. **/ - EIGEN_DEVICE_FUNC inline Scalar& x() { return m_coeffs.x(); } - /** \brief Returns the y-translation as a reference. **/ - EIGEN_DEVICE_FUNC inline Scalar& y() { return m_coeffs.y(); } - /** \brief Returns the z-translation as a reference. **/ - EIGEN_DEVICE_FUNC inline Scalar& z() { return m_coeffs.z(); } - - EIGEN_DEVICE_FUNC const VectorType& vector() const { return m_coeffs; } - EIGEN_DEVICE_FUNC VectorType& vector() { return m_coeffs; } - - EIGEN_DEVICE_FUNC const VectorType& translation() const { return m_coeffs; } - EIGEN_DEVICE_FUNC VectorType& translation() { return m_coeffs; } - - /** Concatenates two translation */ - EIGEN_DEVICE_FUNC inline Translation operator* (const Translation& other) const - { return Translation(m_coeffs + other.m_coeffs); } - - /** Concatenates a translation and a uniform scaling */ - EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const; - - /** Concatenates a translation and a linear transformation */ - template<typename OtherDerived> - EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const; - - /** Concatenates a translation and a rotation */ - template<typename Derived> - EIGEN_DEVICE_FUNC inline IsometryTransformType operator*(const RotationBase<Derived,Dim>& r) const - { return *this * IsometryTransformType(r); } - - /** \returns the concatenation of a linear transformation \a l with the translation \a t */ - // its a nightmare to define a templated friend function outside its declaration - template<typename OtherDerived> friend - EIGEN_DEVICE_FUNC inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation& t) - { - AffineTransformType res; - res.matrix().setZero(); - res.linear() = linear.derived(); - res.translation() = linear.derived() * t.m_coeffs; - res.matrix().row(Dim).setZero(); - res(Dim,Dim) = Scalar(1); - return res; - } - - /** Concatenates a translation and a transformation */ - template<int Mode, int Options> - EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim,Mode,Options>& t) const - { - Transform<Scalar,Dim,Mode> res = t; - res.pretranslate(m_coeffs); - return res; - } - - /** Applies translation to vector */ - template<typename Derived> - inline typename internal::enable_if<Derived::IsVectorAtCompileTime,VectorType>::type - operator* (const MatrixBase<Derived>& vec) const - { return m_coeffs + vec.derived(); } - - /** \returns the inverse translation (opposite) */ - Translation inverse() const { return Translation(-m_coeffs); } - - static const Translation Identity() { return Translation(VectorType::Zero()); } - - /** \returns \c *this with scalar type casted to \a NewScalarType - * - * Note that if \a NewScalarType is equal to the current scalar type of \c *this - * then this function smartly returns a const reference to \c *this. - */ - template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const - { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); } - - /** Copy constructor with scalar type conversion */ - template<typename OtherScalarType> - EIGEN_DEVICE_FUNC inline explicit Translation(const Translation<OtherScalarType,Dim>& other) - { m_coeffs = other.vector().template cast<Scalar>(); } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - EIGEN_DEVICE_FUNC bool isApprox(const Translation& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const - { return m_coeffs.isApprox(other.m_coeffs, prec); } - -}; - -/** \addtogroup Geometry_Module */ -//@{ -typedef Translation<float, 2> Translation2f; -typedef Translation<double,2> Translation2d; -typedef Translation<float, 3> Translation3f; -typedef Translation<double,3> Translation3d; -//@} - -template<typename Scalar, int Dim> -EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType -Translation<Scalar,Dim>::operator* (const UniformScaling<Scalar>& other) const -{ - AffineTransformType res; - res.matrix().setZero(); - res.linear().diagonal().fill(other.factor()); - res.translation() = m_coeffs; - res(Dim,Dim) = Scalar(1); - return res; -} - -template<typename Scalar, int Dim> -template<typename OtherDerived> -EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType -Translation<Scalar,Dim>::operator* (const EigenBase<OtherDerived>& linear) const -{ - AffineTransformType res; - res.matrix().setZero(); - res.linear() = linear.derived(); - res.translation() = m_coeffs; - res.matrix().row(Dim).setZero(); - res(Dim,Dim) = Scalar(1); - return res; -} - -} // end namespace Eigen - -#endif // EIGEN_TRANSLATION_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/Umeyama.h b/external/eigen/include/eigen3/Eigen/src/Geometry/Umeyama.h deleted file mode 100644 index 6b755008..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/Umeyama.h +++ /dev/null @@ -1,166 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Hauke Heibel <hauke.heibel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_UMEYAMA_H -#define EIGEN_UMEYAMA_H - -// This file requires the user to include -// * Eigen/Core -// * Eigen/LU -// * Eigen/SVD -// * Eigen/Array - -namespace Eigen { - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -// These helpers are required since it allows to use mixed types as parameters -// for the Umeyama. The problem with mixed parameters is that the return type -// cannot trivially be deduced when float and double types are mixed. -namespace internal { - -// Compile time return type deduction for different MatrixBase types. -// Different means here different alignment and parameters but the same underlying -// real scalar type. -template<typename MatrixType, typename OtherMatrixType> -struct umeyama_transform_matrix_type -{ - enum { - MinRowsAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(MatrixType::RowsAtCompileTime, OtherMatrixType::RowsAtCompileTime), - - // When possible we want to choose some small fixed size value since the result - // is likely to fit on the stack. So here, EIGEN_SIZE_MIN_PREFER_DYNAMIC is not what we want. - HomogeneousDimension = int(MinRowsAtCompileTime) == Dynamic ? Dynamic : int(MinRowsAtCompileTime)+1 - }; - - typedef Matrix<typename traits<MatrixType>::Scalar, - HomogeneousDimension, - HomogeneousDimension, - AutoAlign | (traits<MatrixType>::Flags & RowMajorBit ? RowMajor : ColMajor), - HomogeneousDimension, - HomogeneousDimension - > type; -}; - -} - -#endif - -/** -* \geometry_module \ingroup Geometry_Module -* -* \brief Returns the transformation between two point sets. -* -* The algorithm is based on: -* "Least-squares estimation of transformation parameters between two point patterns", -* Shinji Umeyama, PAMI 1991, DOI: 10.1109/34.88573 -* -* It estimates parameters \f$ c, \mathbf{R}, \f$ and \f$ \mathbf{t} \f$ such that -* \f{align*} -* \frac{1}{n} \sum_{i=1}^n \vert\vert y_i - (c\mathbf{R}x_i + \mathbf{t}) \vert\vert_2^2 -* \f} -* is minimized. -* -* The algorithm is based on the analysis of the covariance matrix -* \f$ \Sigma_{\mathbf{x}\mathbf{y}} \in \mathbb{R}^{d \times d} \f$ -* of the input point sets \f$ \mathbf{x} \f$ and \f$ \mathbf{y} \f$ where -* \f$d\f$ is corresponding to the dimension (which is typically small). -* The analysis is involving the SVD having a complexity of \f$O(d^3)\f$ -* though the actual computational effort lies in the covariance -* matrix computation which has an asymptotic lower bound of \f$O(dm)\f$ when -* the input point sets have dimension \f$d \times m\f$. -* -* Currently the method is working only for floating point matrices. -* -* \todo Should the return type of umeyama() become a Transform? -* -* \param src Source points \f$ \mathbf{x} = \left( x_1, \hdots, x_n \right) \f$. -* \param dst Destination points \f$ \mathbf{y} = \left( y_1, \hdots, y_n \right) \f$. -* \param with_scaling Sets \f$ c=1 \f$ when <code>false</code> is passed. -* \return The homogeneous transformation -* \f{align*} -* T = \begin{bmatrix} c\mathbf{R} & \mathbf{t} \\ \mathbf{0} & 1 \end{bmatrix} -* \f} -* minimizing the residual above. This transformation is always returned as an -* Eigen::Matrix. -*/ -template <typename Derived, typename OtherDerived> -typename internal::umeyama_transform_matrix_type<Derived, OtherDerived>::type -umeyama(const MatrixBase<Derived>& src, const MatrixBase<OtherDerived>& dst, bool with_scaling = true) -{ - typedef typename internal::umeyama_transform_matrix_type<Derived, OtherDerived>::type TransformationMatrixType; - typedef typename internal::traits<TransformationMatrixType>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - - EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL) - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename internal::traits<OtherDerived>::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - - enum { Dimension = EIGEN_SIZE_MIN_PREFER_DYNAMIC(Derived::RowsAtCompileTime, OtherDerived::RowsAtCompileTime) }; - - typedef Matrix<Scalar, Dimension, 1> VectorType; - typedef Matrix<Scalar, Dimension, Dimension> MatrixType; - typedef typename internal::plain_matrix_type_row_major<Derived>::type RowMajorMatrixType; - - const Index m = src.rows(); // dimension - const Index n = src.cols(); // number of measurements - - // required for demeaning ... - const RealScalar one_over_n = RealScalar(1) / static_cast<RealScalar>(n); - - // computation of mean - const VectorType src_mean = src.rowwise().sum() * one_over_n; - const VectorType dst_mean = dst.rowwise().sum() * one_over_n; - - // demeaning of src and dst points - const RowMajorMatrixType src_demean = src.colwise() - src_mean; - const RowMajorMatrixType dst_demean = dst.colwise() - dst_mean; - - // Eq. (36)-(37) - const Scalar src_var = src_demean.rowwise().squaredNorm().sum() * one_over_n; - - // Eq. (38) - const MatrixType sigma = one_over_n * dst_demean * src_demean.transpose(); - - JacobiSVD<MatrixType> svd(sigma, ComputeFullU | ComputeFullV); - - // Initialize the resulting transformation with an identity matrix... - TransformationMatrixType Rt = TransformationMatrixType::Identity(m+1,m+1); - - // Eq. (39) - VectorType S = VectorType::Ones(m); - - if ( svd.matrixU().determinant() * svd.matrixV().determinant() < 0 ) - S(m-1) = -1; - - // Eq. (40) and (43) - Rt.block(0,0,m,m).noalias() = svd.matrixU() * S.asDiagonal() * svd.matrixV().transpose(); - - if (with_scaling) - { - // Eq. (42) - const Scalar c = Scalar(1)/src_var * svd.singularValues().dot(S); - - // Eq. (41) - Rt.col(m).head(m) = dst_mean; - Rt.col(m).head(m).noalias() -= c*Rt.topLeftCorner(m,m)*src_mean; - Rt.block(0,0,m,m) *= c; - } - else - { - Rt.col(m).head(m) = dst_mean; - Rt.col(m).head(m).noalias() -= Rt.topLeftCorner(m,m)*src_mean; - } - - return Rt; -} - -} // end namespace Eigen - -#endif // EIGEN_UMEYAMA_H diff --git a/external/eigen/include/eigen3/Eigen/src/Geometry/arch/Geometry_SSE.h b/external/eigen/include/eigen3/Eigen/src/Geometry/arch/Geometry_SSE.h deleted file mode 100644 index 108cc9f8..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Geometry/arch/Geometry_SSE.h +++ /dev/null @@ -1,170 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Rohit Garg <rpg.314@gmail.com> -// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GEOMETRY_SSE_H -#define EIGEN_GEOMETRY_SSE_H - -namespace Eigen { - -namespace internal { - -template<class Derived, class OtherDerived> -struct quat_product<Architecture::SSE, Derived, OtherDerived, float> -{ - enum { - AAlignment = traits<Derived>::Alignment, - BAlignment = traits<OtherDerived>::Alignment, - ResAlignment = traits<Quaternion<float> >::Alignment - }; - static inline Quaternion<float> run(const QuaternionBase<Derived>& _a, const QuaternionBase<OtherDerived>& _b) - { - evaluator<typename Derived::Coefficients> ae(_a.coeffs()); - evaluator<typename OtherDerived::Coefficients> be(_b.coeffs()); - Quaternion<float> res; - const Packet4f mask = _mm_setr_ps(0.f,0.f,0.f,-0.f); - Packet4f a = ae.template packet<AAlignment,Packet4f>(0); - Packet4f b = be.template packet<BAlignment,Packet4f>(0); - Packet4f s1 = pmul(vec4f_swizzle1(a,1,2,0,2),vec4f_swizzle1(b,2,0,1,2)); - Packet4f s2 = pmul(vec4f_swizzle1(a,3,3,3,1),vec4f_swizzle1(b,0,1,2,1)); - pstoret<float,Packet4f,ResAlignment>( - &res.x(), - padd(psub(pmul(a,vec4f_swizzle1(b,3,3,3,3)), - pmul(vec4f_swizzle1(a,2,0,1,0), - vec4f_swizzle1(b,1,2,0,0))), - pxor(mask,padd(s1,s2)))); - - return res; - } -}; - -template<class Derived> -struct quat_conj<Architecture::SSE, Derived, float> -{ - enum { - ResAlignment = traits<Quaternion<float> >::Alignment - }; - static inline Quaternion<float> run(const QuaternionBase<Derived>& q) - { - evaluator<typename Derived::Coefficients> qe(q.coeffs()); - Quaternion<float> res; - const Packet4f mask = _mm_setr_ps(-0.f,-0.f,-0.f,0.f); - pstoret<float,Packet4f,ResAlignment>(&res.x(), pxor(mask, qe.template packet<traits<Derived>::Alignment,Packet4f>(0))); - return res; - } -}; - - -template<typename VectorLhs,typename VectorRhs> -struct cross3_impl<Architecture::SSE,VectorLhs,VectorRhs,float,true> -{ - enum { - ResAlignment = traits<typename plain_matrix_type<VectorLhs>::type>::Alignment - }; - static inline typename plain_matrix_type<VectorLhs>::type - run(const VectorLhs& lhs, const VectorRhs& rhs) - { - evaluator<VectorLhs> lhs_eval(lhs); - evaluator<VectorRhs> rhs_eval(rhs); - Packet4f a = lhs_eval.template packet<traits<VectorLhs>::Alignment,Packet4f>(0); - Packet4f b = rhs_eval.template packet<traits<VectorRhs>::Alignment,Packet4f>(0); - Packet4f mul1 = pmul(vec4f_swizzle1(a,1,2,0,3),vec4f_swizzle1(b,2,0,1,3)); - Packet4f mul2 = pmul(vec4f_swizzle1(a,2,0,1,3),vec4f_swizzle1(b,1,2,0,3)); - typename plain_matrix_type<VectorLhs>::type res; - pstoret<float,Packet4f,ResAlignment>(&res.x(),psub(mul1,mul2)); - return res; - } -}; - - - - -template<class Derived, class OtherDerived> -struct quat_product<Architecture::SSE, Derived, OtherDerived, double> -{ - enum { - BAlignment = traits<OtherDerived>::Alignment, - ResAlignment = traits<Quaternion<double> >::Alignment - }; - - static inline Quaternion<double> run(const QuaternionBase<Derived>& _a, const QuaternionBase<OtherDerived>& _b) - { - const Packet2d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0)); - - Quaternion<double> res; - - evaluator<typename Derived::Coefficients> ae(_a.coeffs()); - evaluator<typename OtherDerived::Coefficients> be(_b.coeffs()); - - const double* a = _a.coeffs().data(); - Packet2d b_xy = be.template packet<BAlignment,Packet2d>(0); - Packet2d b_zw = be.template packet<BAlignment,Packet2d>(2); - Packet2d a_xx = pset1<Packet2d>(a[0]); - Packet2d a_yy = pset1<Packet2d>(a[1]); - Packet2d a_zz = pset1<Packet2d>(a[2]); - Packet2d a_ww = pset1<Packet2d>(a[3]); - - // two temporaries: - Packet2d t1, t2; - - /* - * t1 = ww*xy + yy*zw - * t2 = zz*xy - xx*zw - * res.xy = t1 +/- swap(t2) - */ - t1 = padd(pmul(a_ww, b_xy), pmul(a_yy, b_zw)); - t2 = psub(pmul(a_zz, b_xy), pmul(a_xx, b_zw)); -#ifdef EIGEN_VECTORIZE_SSE3 - EIGEN_UNUSED_VARIABLE(mask) - pstoret<double,Packet2d,ResAlignment>(&res.x(), _mm_addsub_pd(t1, preverse(t2))); -#else - pstoret<double,Packet2d,ResAlignment>(&res.x(), padd(t1, pxor(mask,preverse(t2)))); -#endif - - /* - * t1 = ww*zw - yy*xy - * t2 = zz*zw + xx*xy - * res.zw = t1 -/+ swap(t2) = swap( swap(t1) +/- t2) - */ - t1 = psub(pmul(a_ww, b_zw), pmul(a_yy, b_xy)); - t2 = padd(pmul(a_zz, b_zw), pmul(a_xx, b_xy)); -#ifdef EIGEN_VECTORIZE_SSE3 - EIGEN_UNUSED_VARIABLE(mask) - pstoret<double,Packet2d,ResAlignment>(&res.z(), preverse(_mm_addsub_pd(preverse(t1), t2))); -#else - pstoret<double,Packet2d,ResAlignment>(&res.z(), psub(t1, pxor(mask,preverse(t2)))); -#endif - - return res; -} -}; - -template<class Derived> -struct quat_conj<Architecture::SSE, Derived, double> -{ - enum { - ResAlignment = traits<Quaternion<double> >::Alignment - }; - static inline Quaternion<double> run(const QuaternionBase<Derived>& q) - { - evaluator<typename Derived::Coefficients> qe(q.coeffs()); - Quaternion<double> res; - const Packet2d mask0 = _mm_setr_pd(-0.,-0.); - const Packet2d mask2 = _mm_setr_pd(-0.,0.); - pstoret<double,Packet2d,ResAlignment>(&res.x(), pxor(mask0, qe.template packet<traits<Derived>::Alignment,Packet2d>(0))); - pstoret<double,Packet2d,ResAlignment>(&res.z(), pxor(mask2, qe.template packet<traits<Derived>::Alignment,Packet2d>(2))); - return res; - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_GEOMETRY_SSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/Householder/BlockHouseholder.h b/external/eigen/include/eigen3/Eigen/src/Householder/BlockHouseholder.h deleted file mode 100644 index 39ce1c2a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Householder/BlockHouseholder.h +++ /dev/null @@ -1,110 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Vincent Lejeune -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BLOCK_HOUSEHOLDER_H -#define EIGEN_BLOCK_HOUSEHOLDER_H - -// This file contains some helper function to deal with block householder reflectors - -namespace Eigen { - -namespace internal { - -/** \internal */ -// template<typename TriangularFactorType,typename VectorsType,typename CoeffsType> -// void make_block_householder_triangular_factor(TriangularFactorType& triFactor, const VectorsType& vectors, const CoeffsType& hCoeffs) -// { -// typedef typename VectorsType::Scalar Scalar; -// const Index nbVecs = vectors.cols(); -// eigen_assert(triFactor.rows() == nbVecs && triFactor.cols() == nbVecs && vectors.rows()>=nbVecs); -// -// for(Index i = 0; i < nbVecs; i++) -// { -// Index rs = vectors.rows() - i; -// // Warning, note that hCoeffs may alias with vectors. -// // It is then necessary to copy it before modifying vectors(i,i). -// typename CoeffsType::Scalar h = hCoeffs(i); -// // This hack permits to pass trough nested Block<> and Transpose<> expressions. -// Scalar *Vii_ptr = const_cast<Scalar*>(vectors.data() + vectors.outerStride()*i + vectors.innerStride()*i); -// Scalar Vii = *Vii_ptr; -// *Vii_ptr = Scalar(1); -// triFactor.col(i).head(i).noalias() = -h * vectors.block(i, 0, rs, i).adjoint() -// * vectors.col(i).tail(rs); -// *Vii_ptr = Vii; -// // FIXME add .noalias() once the triangular product can work inplace -// triFactor.col(i).head(i) = triFactor.block(0,0,i,i).template triangularView<Upper>() -// * triFactor.col(i).head(i); -// triFactor(i,i) = hCoeffs(i); -// } -// } - -/** \internal */ -// This variant avoid modifications in vectors -template<typename TriangularFactorType,typename VectorsType,typename CoeffsType> -void make_block_householder_triangular_factor(TriangularFactorType& triFactor, const VectorsType& vectors, const CoeffsType& hCoeffs) -{ - const Index nbVecs = vectors.cols(); - eigen_assert(triFactor.rows() == nbVecs && triFactor.cols() == nbVecs && vectors.rows()>=nbVecs); - - for(Index i = nbVecs-1; i >=0 ; --i) - { - Index rs = vectors.rows() - i - 1; - Index rt = nbVecs-i-1; - - if(rt>0) - { - triFactor.row(i).tail(rt).noalias() = -hCoeffs(i) * vectors.col(i).tail(rs).adjoint() - * vectors.bottomRightCorner(rs, rt).template triangularView<UnitLower>(); - - // FIXME use the following line with .noalias() once the triangular product can work inplace - // triFactor.row(i).tail(rt) = triFactor.row(i).tail(rt) * triFactor.bottomRightCorner(rt,rt).template triangularView<Upper>(); - for(Index j=nbVecs-1; j>i; --j) - { - typename TriangularFactorType::Scalar z = triFactor(i,j); - triFactor(i,j) = z * triFactor(j,j); - if(nbVecs-j-1>0) - triFactor.row(i).tail(nbVecs-j-1) += z * triFactor.row(j).tail(nbVecs-j-1); - } - - } - triFactor(i,i) = hCoeffs(i); - } -} - -/** \internal - * if forward then perform mat = H0 * H1 * H2 * mat - * otherwise perform mat = H2 * H1 * H0 * mat - */ -template<typename MatrixType,typename VectorsType,typename CoeffsType> -void apply_block_householder_on_the_left(MatrixType& mat, const VectorsType& vectors, const CoeffsType& hCoeffs, bool forward) -{ - enum { TFactorSize = MatrixType::ColsAtCompileTime }; - Index nbVecs = vectors.cols(); - Matrix<typename MatrixType::Scalar, TFactorSize, TFactorSize, RowMajor> T(nbVecs,nbVecs); - - if(forward) make_block_householder_triangular_factor(T, vectors, hCoeffs); - else make_block_householder_triangular_factor(T, vectors, hCoeffs.conjugate()); - const TriangularView<const VectorsType, UnitLower> V(vectors); - - // A -= V T V^* A - Matrix<typename MatrixType::Scalar,VectorsType::ColsAtCompileTime,MatrixType::ColsAtCompileTime, - (VectorsType::MaxColsAtCompileTime==1 && MatrixType::MaxColsAtCompileTime!=1)?RowMajor:ColMajor, - VectorsType::MaxColsAtCompileTime,MatrixType::MaxColsAtCompileTime> tmp = V.adjoint() * mat; - // FIXME add .noalias() once the triangular product can work inplace - if(forward) tmp = T.template triangularView<Upper>() * tmp; - else tmp = T.template triangularView<Upper>().adjoint() * tmp; - mat.noalias() -= V * tmp; -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_BLOCK_HOUSEHOLDER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Householder/Householder.h b/external/eigen/include/eigen3/Eigen/src/Householder/Householder.h deleted file mode 100644 index 5bc037f0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Householder/Householder.h +++ /dev/null @@ -1,176 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_HOUSEHOLDER_H -#define EIGEN_HOUSEHOLDER_H - -namespace Eigen { - -namespace internal { -template<int n> struct decrement_size -{ - enum { - ret = n==Dynamic ? n : n-1 - }; -}; -} - -/** Computes the elementary reflector H such that: - * \f$ H *this = [ beta 0 ... 0]^T \f$ - * where the transformation H is: - * \f$ H = I - tau v v^*\f$ - * and the vector v is: - * \f$ v^T = [1 essential^T] \f$ - * - * The essential part of the vector \c v is stored in *this. - * - * On output: - * \param tau the scaling factor of the Householder transformation - * \param beta the result of H * \c *this - * - * \sa MatrixBase::makeHouseholder(), MatrixBase::applyHouseholderOnTheLeft(), - * MatrixBase::applyHouseholderOnTheRight() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC -void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta) -{ - VectorBlock<Derived, internal::decrement_size<Base::SizeAtCompileTime>::ret> essentialPart(derived(), 1, size()-1); - makeHouseholder(essentialPart, tau, beta); -} - -/** Computes the elementary reflector H such that: - * \f$ H *this = [ beta 0 ... 0]^T \f$ - * where the transformation H is: - * \f$ H = I - tau v v^*\f$ - * and the vector v is: - * \f$ v^T = [1 essential^T] \f$ - * - * On output: - * \param essential the essential part of the vector \c v - * \param tau the scaling factor of the Householder transformation - * \param beta the result of H * \c *this - * - * \sa MatrixBase::makeHouseholderInPlace(), MatrixBase::applyHouseholderOnTheLeft(), - * MatrixBase::applyHouseholderOnTheRight() - */ -template<typename Derived> -template<typename EssentialPart> -EIGEN_DEVICE_FUNC -void MatrixBase<Derived>::makeHouseholder( - EssentialPart& essential, - Scalar& tau, - RealScalar& beta) const -{ - using std::sqrt; - using numext::conj; - - EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart) - VectorBlock<const Derived, EssentialPart::SizeAtCompileTime> tail(derived(), 1, size()-1); - - RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm(); - Scalar c0 = coeff(0); - const RealScalar tol = (std::numeric_limits<RealScalar>::min)(); - - if(tailSqNorm <= tol && numext::abs2(numext::imag(c0))<=tol) - { - tau = RealScalar(0); - beta = numext::real(c0); - essential.setZero(); - } - else - { - beta = sqrt(numext::abs2(c0) + tailSqNorm); - if (numext::real(c0)>=RealScalar(0)) - beta = -beta; - essential = tail / (c0 - beta); - tau = conj((beta - c0) / beta); - } -} - -/** Apply the elementary reflector H given by - * \f$ H = I - tau v v^*\f$ - * with - * \f$ v^T = [1 essential^T] \f$ - * from the left to a vector or matrix. - * - * On input: - * \param essential the essential part of the vector \c v - * \param tau the scaling factor of the Householder transformation - * \param workspace a pointer to working space with at least - * this->cols() entries - * - * \sa MatrixBase::makeHouseholder(), MatrixBase::makeHouseholderInPlace(), - * MatrixBase::applyHouseholderOnTheRight() - */ -template<typename Derived> -template<typename EssentialPart> -EIGEN_DEVICE_FUNC -void MatrixBase<Derived>::applyHouseholderOnTheLeft( - const EssentialPart& essential, - const Scalar& tau, - Scalar* workspace) -{ - if(rows() == 1) - { - *this *= Scalar(1)-tau; - } - else if(tau!=Scalar(0)) - { - Map<typename internal::plain_row_type<PlainObject>::type> tmp(workspace,cols()); - Block<Derived, EssentialPart::SizeAtCompileTime, Derived::ColsAtCompileTime> bottom(derived(), 1, 0, rows()-1, cols()); - tmp.noalias() = essential.adjoint() * bottom; - tmp += this->row(0); - this->row(0) -= tau * tmp; - bottom.noalias() -= tau * essential * tmp; - } -} - -/** Apply the elementary reflector H given by - * \f$ H = I - tau v v^*\f$ - * with - * \f$ v^T = [1 essential^T] \f$ - * from the right to a vector or matrix. - * - * On input: - * \param essential the essential part of the vector \c v - * \param tau the scaling factor of the Householder transformation - * \param workspace a pointer to working space with at least - * this->rows() entries - * - * \sa MatrixBase::makeHouseholder(), MatrixBase::makeHouseholderInPlace(), - * MatrixBase::applyHouseholderOnTheLeft() - */ -template<typename Derived> -template<typename EssentialPart> -EIGEN_DEVICE_FUNC -void MatrixBase<Derived>::applyHouseholderOnTheRight( - const EssentialPart& essential, - const Scalar& tau, - Scalar* workspace) -{ - if(cols() == 1) - { - *this *= Scalar(1)-tau; - } - else if(tau!=Scalar(0)) - { - Map<typename internal::plain_col_type<PlainObject>::type> tmp(workspace,rows()); - Block<Derived, Derived::RowsAtCompileTime, EssentialPart::SizeAtCompileTime> right(derived(), 0, 1, rows(), cols()-1); - tmp.noalias() = right * essential; - tmp += this->col(0); - this->col(0) -= tau * tmp; - right.noalias() -= tau * tmp * essential.adjoint(); - } -} - -} // end namespace Eigen - -#endif // EIGEN_HOUSEHOLDER_H diff --git a/external/eigen/include/eigen3/Eigen/src/Householder/HouseholderSequence.h b/external/eigen/include/eigen3/Eigen/src/Householder/HouseholderSequence.h deleted file mode 100644 index 9318c281..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Householder/HouseholderSequence.h +++ /dev/null @@ -1,545 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_HOUSEHOLDER_SEQUENCE_H -#define EIGEN_HOUSEHOLDER_SEQUENCE_H - -namespace Eigen { - -/** \ingroup Householder_Module - * \householder_module - * \class HouseholderSequence - * \brief Sequence of Householder reflections acting on subspaces with decreasing size - * \tparam VectorsType type of matrix containing the Householder vectors - * \tparam CoeffsType type of vector containing the Householder coefficients - * \tparam Side either OnTheLeft (the default) or OnTheRight - * - * This class represents a product sequence of Householder reflections where the first Householder reflection - * acts on the whole space, the second Householder reflection leaves the one-dimensional subspace spanned by - * the first unit vector invariant, the third Householder reflection leaves the two-dimensional subspace - * spanned by the first two unit vectors invariant, and so on up to the last reflection which leaves all but - * one dimensions invariant and acts only on the last dimension. Such sequences of Householder reflections - * are used in several algorithms to zero out certain parts of a matrix. Indeed, the methods - * HessenbergDecomposition::matrixQ(), Tridiagonalization::matrixQ(), HouseholderQR::householderQ(), - * and ColPivHouseholderQR::householderQ() all return a %HouseholderSequence. - * - * More precisely, the class %HouseholderSequence represents an \f$ n \times n \f$ matrix \f$ H \f$ of the - * form \f$ H = \prod_{i=0}^{n-1} H_i \f$ where the i-th Householder reflection is \f$ H_i = I - h_i v_i - * v_i^* \f$. The i-th Householder coefficient \f$ h_i \f$ is a scalar and the i-th Householder vector \f$ - * v_i \f$ is a vector of the form - * \f[ - * v_i = [\underbrace{0, \ldots, 0}_{i-1\mbox{ zeros}}, 1, \underbrace{*, \ldots,*}_{n-i\mbox{ arbitrary entries}} ]. - * \f] - * The last \f$ n-i \f$ entries of \f$ v_i \f$ are called the essential part of the Householder vector. - * - * Typical usages are listed below, where H is a HouseholderSequence: - * \code - * A.applyOnTheRight(H); // A = A * H - * A.applyOnTheLeft(H); // A = H * A - * A.applyOnTheRight(H.adjoint()); // A = A * H^* - * A.applyOnTheLeft(H.adjoint()); // A = H^* * A - * MatrixXd Q = H; // conversion to a dense matrix - * \endcode - * In addition to the adjoint, you can also apply the inverse (=adjoint), the transpose, and the conjugate operators. - * - * See the documentation for HouseholderSequence(const VectorsType&, const CoeffsType&) for an example. - * - * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() - */ - -namespace internal { - -template<typename VectorsType, typename CoeffsType, int Side> -struct traits<HouseholderSequence<VectorsType,CoeffsType,Side> > -{ - typedef typename VectorsType::Scalar Scalar; - typedef typename VectorsType::StorageIndex StorageIndex; - typedef typename VectorsType::StorageKind StorageKind; - enum { - RowsAtCompileTime = Side==OnTheLeft ? traits<VectorsType>::RowsAtCompileTime - : traits<VectorsType>::ColsAtCompileTime, - ColsAtCompileTime = RowsAtCompileTime, - MaxRowsAtCompileTime = Side==OnTheLeft ? traits<VectorsType>::MaxRowsAtCompileTime - : traits<VectorsType>::MaxColsAtCompileTime, - MaxColsAtCompileTime = MaxRowsAtCompileTime, - Flags = 0 - }; -}; - -struct HouseholderSequenceShape {}; - -template<typename VectorsType, typename CoeffsType, int Side> -struct evaluator_traits<HouseholderSequence<VectorsType,CoeffsType,Side> > - : public evaluator_traits_base<HouseholderSequence<VectorsType,CoeffsType,Side> > -{ - typedef HouseholderSequenceShape Shape; -}; - -template<typename VectorsType, typename CoeffsType, int Side> -struct hseq_side_dependent_impl -{ - typedef Block<const VectorsType, Dynamic, 1> EssentialVectorType; - typedef HouseholderSequence<VectorsType, CoeffsType, OnTheLeft> HouseholderSequenceType; - static EIGEN_DEVICE_FUNC inline const EssentialVectorType essentialVector(const HouseholderSequenceType& h, Index k) - { - Index start = k+1+h.m_shift; - return Block<const VectorsType,Dynamic,1>(h.m_vectors, start, k, h.rows()-start, 1); - } -}; - -template<typename VectorsType, typename CoeffsType> -struct hseq_side_dependent_impl<VectorsType, CoeffsType, OnTheRight> -{ - typedef Transpose<Block<const VectorsType, 1, Dynamic> > EssentialVectorType; - typedef HouseholderSequence<VectorsType, CoeffsType, OnTheRight> HouseholderSequenceType; - static inline const EssentialVectorType essentialVector(const HouseholderSequenceType& h, Index k) - { - Index start = k+1+h.m_shift; - return Block<const VectorsType,1,Dynamic>(h.m_vectors, k, start, 1, h.rows()-start).transpose(); - } -}; - -template<typename OtherScalarType, typename MatrixType> struct matrix_type_times_scalar_type -{ - typedef typename ScalarBinaryOpTraits<OtherScalarType, typename MatrixType::Scalar>::ReturnType - ResultScalar; - typedef Matrix<ResultScalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime, - 0, MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime> Type; -}; - -} // end namespace internal - -template<typename VectorsType, typename CoeffsType, int Side> class HouseholderSequence - : public EigenBase<HouseholderSequence<VectorsType,CoeffsType,Side> > -{ - typedef typename internal::hseq_side_dependent_impl<VectorsType,CoeffsType,Side>::EssentialVectorType EssentialVectorType; - - public: - enum { - RowsAtCompileTime = internal::traits<HouseholderSequence>::RowsAtCompileTime, - ColsAtCompileTime = internal::traits<HouseholderSequence>::ColsAtCompileTime, - MaxRowsAtCompileTime = internal::traits<HouseholderSequence>::MaxRowsAtCompileTime, - MaxColsAtCompileTime = internal::traits<HouseholderSequence>::MaxColsAtCompileTime - }; - typedef typename internal::traits<HouseholderSequence>::Scalar Scalar; - - typedef HouseholderSequence< - typename internal::conditional<NumTraits<Scalar>::IsComplex, - typename internal::remove_all<typename VectorsType::ConjugateReturnType>::type, - VectorsType>::type, - typename internal::conditional<NumTraits<Scalar>::IsComplex, - typename internal::remove_all<typename CoeffsType::ConjugateReturnType>::type, - CoeffsType>::type, - Side - > ConjugateReturnType; - - typedef HouseholderSequence< - VectorsType, - typename internal::conditional<NumTraits<Scalar>::IsComplex, - typename internal::remove_all<typename CoeffsType::ConjugateReturnType>::type, - CoeffsType>::type, - Side - > AdjointReturnType; - - typedef HouseholderSequence< - typename internal::conditional<NumTraits<Scalar>::IsComplex, - typename internal::remove_all<typename VectorsType::ConjugateReturnType>::type, - VectorsType>::type, - CoeffsType, - Side - > TransposeReturnType; - - typedef HouseholderSequence< - typename internal::add_const<VectorsType>::type, - typename internal::add_const<CoeffsType>::type, - Side - > ConstHouseholderSequence; - - /** \brief Constructor. - * \param[in] v %Matrix containing the essential parts of the Householder vectors - * \param[in] h Vector containing the Householder coefficients - * - * Constructs the Householder sequence with coefficients given by \p h and vectors given by \p v. The - * i-th Householder coefficient \f$ h_i \f$ is given by \p h(i) and the essential part of the i-th - * Householder vector \f$ v_i \f$ is given by \p v(k,i) with \p k > \p i (the subdiagonal part of the - * i-th column). If \p v has fewer columns than rows, then the Householder sequence contains as many - * Householder reflections as there are columns. - * - * \note The %HouseholderSequence object stores \p v and \p h by reference. - * - * Example: \include HouseholderSequence_HouseholderSequence.cpp - * Output: \verbinclude HouseholderSequence_HouseholderSequence.out - * - * \sa setLength(), setShift() - */ - EIGEN_DEVICE_FUNC - HouseholderSequence(const VectorsType& v, const CoeffsType& h) - : m_vectors(v), m_coeffs(h), m_reverse(false), m_length(v.diagonalSize()), - m_shift(0) - { - } - - /** \brief Copy constructor. */ - EIGEN_DEVICE_FUNC - HouseholderSequence(const HouseholderSequence& other) - : m_vectors(other.m_vectors), - m_coeffs(other.m_coeffs), - m_reverse(other.m_reverse), - m_length(other.m_length), - m_shift(other.m_shift) - { - } - - /** \brief Number of rows of transformation viewed as a matrix. - * \returns Number of rows - * \details This equals the dimension of the space that the transformation acts on. - */ - EIGEN_DEVICE_FUNC - Index rows() const { return Side==OnTheLeft ? m_vectors.rows() : m_vectors.cols(); } - - /** \brief Number of columns of transformation viewed as a matrix. - * \returns Number of columns - * \details This equals the dimension of the space that the transformation acts on. - */ - EIGEN_DEVICE_FUNC - Index cols() const { return rows(); } - - /** \brief Essential part of a Householder vector. - * \param[in] k Index of Householder reflection - * \returns Vector containing non-trivial entries of k-th Householder vector - * - * This function returns the essential part of the Householder vector \f$ v_i \f$. This is a vector of - * length \f$ n-i \f$ containing the last \f$ n-i \f$ entries of the vector - * \f[ - * v_i = [\underbrace{0, \ldots, 0}_{i-1\mbox{ zeros}}, 1, \underbrace{*, \ldots,*}_{n-i\mbox{ arbitrary entries}} ]. - * \f] - * The index \f$ i \f$ equals \p k + shift(), corresponding to the k-th column of the matrix \p v - * passed to the constructor. - * - * \sa setShift(), shift() - */ - EIGEN_DEVICE_FUNC - const EssentialVectorType essentialVector(Index k) const - { - eigen_assert(k >= 0 && k < m_length); - return internal::hseq_side_dependent_impl<VectorsType,CoeffsType,Side>::essentialVector(*this, k); - } - - /** \brief %Transpose of the Householder sequence. */ - TransposeReturnType transpose() const - { - return TransposeReturnType(m_vectors.conjugate(), m_coeffs) - .setReverseFlag(!m_reverse) - .setLength(m_length) - .setShift(m_shift); - } - - /** \brief Complex conjugate of the Householder sequence. */ - ConjugateReturnType conjugate() const - { - return ConjugateReturnType(m_vectors.conjugate(), m_coeffs.conjugate()) - .setReverseFlag(m_reverse) - .setLength(m_length) - .setShift(m_shift); - } - - /** \returns an expression of the complex conjugate of \c *this if Cond==true, - * returns \c *this otherwise. - */ - template<bool Cond> - EIGEN_DEVICE_FUNC - inline typename internal::conditional<Cond,ConjugateReturnType,ConstHouseholderSequence>::type - conjugateIf() const - { - typedef typename internal::conditional<Cond,ConjugateReturnType,ConstHouseholderSequence>::type ReturnType; - return ReturnType(m_vectors.template conjugateIf<Cond>(), m_coeffs.template conjugateIf<Cond>()); - } - - /** \brief Adjoint (conjugate transpose) of the Householder sequence. */ - AdjointReturnType adjoint() const - { - return AdjointReturnType(m_vectors, m_coeffs.conjugate()) - .setReverseFlag(!m_reverse) - .setLength(m_length) - .setShift(m_shift); - } - - /** \brief Inverse of the Householder sequence (equals the adjoint). */ - AdjointReturnType inverse() const { return adjoint(); } - - /** \internal */ - template<typename DestType> - inline EIGEN_DEVICE_FUNC - void evalTo(DestType& dst) const - { - Matrix<Scalar, DestType::RowsAtCompileTime, 1, - AutoAlign|ColMajor, DestType::MaxRowsAtCompileTime, 1> workspace(rows()); - evalTo(dst, workspace); - } - - /** \internal */ - template<typename Dest, typename Workspace> - EIGEN_DEVICE_FUNC - void evalTo(Dest& dst, Workspace& workspace) const - { - workspace.resize(rows()); - Index vecs = m_length; - if(internal::is_same_dense(dst,m_vectors)) - { - // in-place - dst.diagonal().setOnes(); - dst.template triangularView<StrictlyUpper>().setZero(); - for(Index k = vecs-1; k >= 0; --k) - { - Index cornerSize = rows() - k - m_shift; - if(m_reverse) - dst.bottomRightCorner(cornerSize, cornerSize) - .applyHouseholderOnTheRight(essentialVector(k), m_coeffs.coeff(k), workspace.data()); - else - dst.bottomRightCorner(cornerSize, cornerSize) - .applyHouseholderOnTheLeft(essentialVector(k), m_coeffs.coeff(k), workspace.data()); - - // clear the off diagonal vector - dst.col(k).tail(rows()-k-1).setZero(); - } - // clear the remaining columns if needed - for(Index k = 0; k<cols()-vecs ; ++k) - dst.col(k).tail(rows()-k-1).setZero(); - } - else if(m_length>BlockSize) - { - dst.setIdentity(rows(), rows()); - if(m_reverse) - applyThisOnTheLeft(dst,workspace,true); - else - applyThisOnTheLeft(dst,workspace,true); - } - else - { - dst.setIdentity(rows(), rows()); - for(Index k = vecs-1; k >= 0; --k) - { - Index cornerSize = rows() - k - m_shift; - if(m_reverse) - dst.bottomRightCorner(cornerSize, cornerSize) - .applyHouseholderOnTheRight(essentialVector(k), m_coeffs.coeff(k), workspace.data()); - else - dst.bottomRightCorner(cornerSize, cornerSize) - .applyHouseholderOnTheLeft(essentialVector(k), m_coeffs.coeff(k), workspace.data()); - } - } - } - - /** \internal */ - template<typename Dest> inline void applyThisOnTheRight(Dest& dst) const - { - Matrix<Scalar,1,Dest::RowsAtCompileTime,RowMajor,1,Dest::MaxRowsAtCompileTime> workspace(dst.rows()); - applyThisOnTheRight(dst, workspace); - } - - /** \internal */ - template<typename Dest, typename Workspace> - inline void applyThisOnTheRight(Dest& dst, Workspace& workspace) const - { - workspace.resize(dst.rows()); - for(Index k = 0; k < m_length; ++k) - { - Index actual_k = m_reverse ? m_length-k-1 : k; - dst.rightCols(rows()-m_shift-actual_k) - .applyHouseholderOnTheRight(essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data()); - } - } - - /** \internal */ - template<typename Dest> inline void applyThisOnTheLeft(Dest& dst, bool inputIsIdentity = false) const - { - Matrix<Scalar,1,Dest::ColsAtCompileTime,RowMajor,1,Dest::MaxColsAtCompileTime> workspace; - applyThisOnTheLeft(dst, workspace, inputIsIdentity); - } - - /** \internal */ - template<typename Dest, typename Workspace> - inline void applyThisOnTheLeft(Dest& dst, Workspace& workspace, bool inputIsIdentity = false) const - { - if(inputIsIdentity && m_reverse) - inputIsIdentity = false; - // if the entries are large enough, then apply the reflectors by block - if(m_length>=BlockSize && dst.cols()>1) - { - // Make sure we have at least 2 useful blocks, otherwise it is point-less: - Index blockSize = m_length<Index(2*BlockSize) ? (m_length+1)/2 : Index(BlockSize); - for(Index i = 0; i < m_length; i+=blockSize) - { - Index end = m_reverse ? (std::min)(m_length,i+blockSize) : m_length-i; - Index k = m_reverse ? i : (std::max)(Index(0),end-blockSize); - Index bs = end-k; - Index start = k + m_shift; - - typedef Block<typename internal::remove_all<VectorsType>::type,Dynamic,Dynamic> SubVectorsType; - SubVectorsType sub_vecs1(m_vectors.const_cast_derived(), Side==OnTheRight ? k : start, - Side==OnTheRight ? start : k, - Side==OnTheRight ? bs : m_vectors.rows()-start, - Side==OnTheRight ? m_vectors.cols()-start : bs); - typename internal::conditional<Side==OnTheRight, Transpose<SubVectorsType>, SubVectorsType&>::type sub_vecs(sub_vecs1); - - Index dstStart = dst.rows()-rows()+m_shift+k; - Index dstRows = rows()-m_shift-k; - Block<Dest,Dynamic,Dynamic> sub_dst(dst, - dstStart, - inputIsIdentity ? dstStart : 0, - dstRows, - inputIsIdentity ? dstRows : dst.cols()); - apply_block_householder_on_the_left(sub_dst, sub_vecs, m_coeffs.segment(k, bs), !m_reverse); - } - } - else - { - workspace.resize(dst.cols()); - for(Index k = 0; k < m_length; ++k) - { - Index actual_k = m_reverse ? k : m_length-k-1; - Index dstStart = rows()-m_shift-actual_k; - dst.bottomRightCorner(dstStart, inputIsIdentity ? dstStart : dst.cols()) - .applyHouseholderOnTheLeft(essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data()); - } - } - } - - /** \brief Computes the product of a Householder sequence with a matrix. - * \param[in] other %Matrix being multiplied. - * \returns Expression object representing the product. - * - * This function computes \f$ HM \f$ where \f$ H \f$ is the Householder sequence represented by \p *this - * and \f$ M \f$ is the matrix \p other. - */ - template<typename OtherDerived> - typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type operator*(const MatrixBase<OtherDerived>& other) const - { - typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type - res(other.template cast<typename internal::matrix_type_times_scalar_type<Scalar,OtherDerived>::ResultScalar>()); - applyThisOnTheLeft(res, internal::is_identity<OtherDerived>::value && res.rows()==res.cols()); - return res; - } - - template<typename _VectorsType, typename _CoeffsType, int _Side> friend struct internal::hseq_side_dependent_impl; - - /** \brief Sets the length of the Householder sequence. - * \param [in] length New value for the length. - * - * By default, the length \f$ n \f$ of the Householder sequence \f$ H = H_0 H_1 \ldots H_{n-1} \f$ is set - * to the number of columns of the matrix \p v passed to the constructor, or the number of rows if that - * is smaller. After this function is called, the length equals \p length. - * - * \sa length() - */ - EIGEN_DEVICE_FUNC - HouseholderSequence& setLength(Index length) - { - m_length = length; - return *this; - } - - /** \brief Sets the shift of the Householder sequence. - * \param [in] shift New value for the shift. - * - * By default, a %HouseholderSequence object represents \f$ H = H_0 H_1 \ldots H_{n-1} \f$ and the i-th - * column of the matrix \p v passed to the constructor corresponds to the i-th Householder - * reflection. After this function is called, the object represents \f$ H = H_{\mathrm{shift}} - * H_{\mathrm{shift}+1} \ldots H_{n-1} \f$ and the i-th column of \p v corresponds to the (shift+i)-th - * Householder reflection. - * - * \sa shift() - */ - EIGEN_DEVICE_FUNC - HouseholderSequence& setShift(Index shift) - { - m_shift = shift; - return *this; - } - - EIGEN_DEVICE_FUNC - Index length() const { return m_length; } /**< \brief Returns the length of the Householder sequence. */ - - EIGEN_DEVICE_FUNC - Index shift() const { return m_shift; } /**< \brief Returns the shift of the Householder sequence. */ - - /* Necessary for .adjoint() and .conjugate() */ - template <typename VectorsType2, typename CoeffsType2, int Side2> friend class HouseholderSequence; - - protected: - - /** \internal - * \brief Sets the reverse flag. - * \param [in] reverse New value of the reverse flag. - * - * By default, the reverse flag is not set. If the reverse flag is set, then this object represents - * \f$ H^r = H_{n-1} \ldots H_1 H_0 \f$ instead of \f$ H = H_0 H_1 \ldots H_{n-1} \f$. - * \note For real valued HouseholderSequence this is equivalent to transposing \f$ H \f$. - * - * \sa reverseFlag(), transpose(), adjoint() - */ - HouseholderSequence& setReverseFlag(bool reverse) - { - m_reverse = reverse; - return *this; - } - - bool reverseFlag() const { return m_reverse; } /**< \internal \brief Returns the reverse flag. */ - - typename VectorsType::Nested m_vectors; - typename CoeffsType::Nested m_coeffs; - bool m_reverse; - Index m_length; - Index m_shift; - enum { BlockSize = 48 }; -}; - -/** \brief Computes the product of a matrix with a Householder sequence. - * \param[in] other %Matrix being multiplied. - * \param[in] h %HouseholderSequence being multiplied. - * \returns Expression object representing the product. - * - * This function computes \f$ MH \f$ where \f$ M \f$ is the matrix \p other and \f$ H \f$ is the - * Householder sequence represented by \p h. - */ -template<typename OtherDerived, typename VectorsType, typename CoeffsType, int Side> -typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar,OtherDerived>::Type operator*(const MatrixBase<OtherDerived>& other, const HouseholderSequence<VectorsType,CoeffsType,Side>& h) -{ - typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar,OtherDerived>::Type - res(other.template cast<typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar,OtherDerived>::ResultScalar>()); - h.applyThisOnTheRight(res); - return res; -} - -/** \ingroup Householder_Module \householder_module - * \brief Convenience function for constructing a Householder sequence. - * \returns A HouseholderSequence constructed from the specified arguments. - */ -template<typename VectorsType, typename CoeffsType> -HouseholderSequence<VectorsType,CoeffsType> householderSequence(const VectorsType& v, const CoeffsType& h) -{ - return HouseholderSequence<VectorsType,CoeffsType,OnTheLeft>(v, h); -} - -/** \ingroup Householder_Module \householder_module - * \brief Convenience function for constructing a Householder sequence. - * \returns A HouseholderSequence constructed from the specified arguments. - * \details This function differs from householderSequence() in that the template argument \p OnTheSide of - * the constructed HouseholderSequence is set to OnTheRight, instead of the default OnTheLeft. - */ -template<typename VectorsType, typename CoeffsType> -HouseholderSequence<VectorsType,CoeffsType,OnTheRight> rightHouseholderSequence(const VectorsType& v, const CoeffsType& h) -{ - return HouseholderSequence<VectorsType,CoeffsType,OnTheRight>(v, h); -} - -} // end namespace Eigen - -#endif // EIGEN_HOUSEHOLDER_SEQUENCE_H diff --git a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h b/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h deleted file mode 100644 index f66c846e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h +++ /dev/null @@ -1,226 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BASIC_PRECONDITIONERS_H -#define EIGEN_BASIC_PRECONDITIONERS_H - -namespace Eigen { - -/** \ingroup IterativeLinearSolvers_Module - * \brief A preconditioner based on the digonal entries - * - * This class allows to approximately solve for A.x = b problems assuming A is a diagonal matrix. - * In other words, this preconditioner neglects all off diagonal entries and, in Eigen's language, solves for: - \code - A.diagonal().asDiagonal() . x = b - \endcode - * - * \tparam _Scalar the type of the scalar. - * - * \implsparsesolverconcept - * - * This preconditioner is suitable for both selfadjoint and general problems. - * The diagonal entries are pre-inverted and stored into a dense vector. - * - * \note A variant that has yet to be implemented would attempt to preserve the norm of each column. - * - * \sa class LeastSquareDiagonalPreconditioner, class ConjugateGradient - */ -template <typename _Scalar> -class DiagonalPreconditioner -{ - typedef _Scalar Scalar; - typedef Matrix<Scalar,Dynamic,1> Vector; - public: - typedef typename Vector::StorageIndex StorageIndex; - enum { - ColsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic - }; - - DiagonalPreconditioner() : m_isInitialized(false) {} - - template<typename MatType> - explicit DiagonalPreconditioner(const MatType& mat) : m_invdiag(mat.cols()) - { - compute(mat); - } - - Index rows() const { return m_invdiag.size(); } - Index cols() const { return m_invdiag.size(); } - - template<typename MatType> - DiagonalPreconditioner& analyzePattern(const MatType& ) - { - return *this; - } - - template<typename MatType> - DiagonalPreconditioner& factorize(const MatType& mat) - { - m_invdiag.resize(mat.cols()); - for(int j=0; j<mat.outerSize(); ++j) - { - typename MatType::InnerIterator it(mat,j); - while(it && it.index()!=j) ++it; - if(it && it.index()==j && it.value()!=Scalar(0)) - m_invdiag(j) = Scalar(1)/it.value(); - else - m_invdiag(j) = Scalar(1); - } - m_isInitialized = true; - return *this; - } - - template<typename MatType> - DiagonalPreconditioner& compute(const MatType& mat) - { - return factorize(mat); - } - - /** \internal */ - template<typename Rhs, typename Dest> - void _solve_impl(const Rhs& b, Dest& x) const - { - x = m_invdiag.array() * b.array() ; - } - - template<typename Rhs> inline const Solve<DiagonalPreconditioner, Rhs> - solve(const MatrixBase<Rhs>& b) const - { - eigen_assert(m_isInitialized && "DiagonalPreconditioner is not initialized."); - eigen_assert(m_invdiag.size()==b.rows() - && "DiagonalPreconditioner::solve(): invalid number of rows of the right hand side matrix b"); - return Solve<DiagonalPreconditioner, Rhs>(*this, b.derived()); - } - - ComputationInfo info() { return Success; } - - protected: - Vector m_invdiag; - bool m_isInitialized; -}; - -/** \ingroup IterativeLinearSolvers_Module - * \brief Jacobi preconditioner for LeastSquaresConjugateGradient - * - * This class allows to approximately solve for A' A x = A' b problems assuming A' A is a diagonal matrix. - * In other words, this preconditioner neglects all off diagonal entries and, in Eigen's language, solves for: - \code - (A.adjoint() * A).diagonal().asDiagonal() * x = b - \endcode - * - * \tparam _Scalar the type of the scalar. - * - * \implsparsesolverconcept - * - * The diagonal entries are pre-inverted and stored into a dense vector. - * - * \sa class LeastSquaresConjugateGradient, class DiagonalPreconditioner - */ -template <typename _Scalar> -class LeastSquareDiagonalPreconditioner : public DiagonalPreconditioner<_Scalar> -{ - typedef _Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef DiagonalPreconditioner<_Scalar> Base; - using Base::m_invdiag; - public: - - LeastSquareDiagonalPreconditioner() : Base() {} - - template<typename MatType> - explicit LeastSquareDiagonalPreconditioner(const MatType& mat) : Base() - { - compute(mat); - } - - template<typename MatType> - LeastSquareDiagonalPreconditioner& analyzePattern(const MatType& ) - { - return *this; - } - - template<typename MatType> - LeastSquareDiagonalPreconditioner& factorize(const MatType& mat) - { - // Compute the inverse squared-norm of each column of mat - m_invdiag.resize(mat.cols()); - if(MatType::IsRowMajor) - { - m_invdiag.setZero(); - for(Index j=0; j<mat.outerSize(); ++j) - { - for(typename MatType::InnerIterator it(mat,j); it; ++it) - m_invdiag(it.index()) += numext::abs2(it.value()); - } - for(Index j=0; j<mat.cols(); ++j) - if(numext::real(m_invdiag(j))>RealScalar(0)) - m_invdiag(j) = RealScalar(1)/numext::real(m_invdiag(j)); - } - else - { - for(Index j=0; j<mat.outerSize(); ++j) - { - RealScalar sum = mat.col(j).squaredNorm(); - if(sum>RealScalar(0)) - m_invdiag(j) = RealScalar(1)/sum; - else - m_invdiag(j) = RealScalar(1); - } - } - Base::m_isInitialized = true; - return *this; - } - - template<typename MatType> - LeastSquareDiagonalPreconditioner& compute(const MatType& mat) - { - return factorize(mat); - } - - ComputationInfo info() { return Success; } - - protected: -}; - -/** \ingroup IterativeLinearSolvers_Module - * \brief A naive preconditioner which approximates any matrix as the identity matrix - * - * \implsparsesolverconcept - * - * \sa class DiagonalPreconditioner - */ -class IdentityPreconditioner -{ - public: - - IdentityPreconditioner() {} - - template<typename MatrixType> - explicit IdentityPreconditioner(const MatrixType& ) {} - - template<typename MatrixType> - IdentityPreconditioner& analyzePattern(const MatrixType& ) { return *this; } - - template<typename MatrixType> - IdentityPreconditioner& factorize(const MatrixType& ) { return *this; } - - template<typename MatrixType> - IdentityPreconditioner& compute(const MatrixType& ) { return *this; } - - template<typename Rhs> - inline const Rhs& solve(const Rhs& b) const { return b; } - - ComputationInfo info() { return Success; } -}; - -} // end namespace Eigen - -#endif // EIGEN_BASIC_PRECONDITIONERS_H diff --git a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h b/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h deleted file mode 100644 index 153acef6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +++ /dev/null @@ -1,212 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BICGSTAB_H -#define EIGEN_BICGSTAB_H - -namespace Eigen { - -namespace internal { - -/** \internal Low-level bi conjugate gradient stabilized algorithm - * \param mat The matrix A - * \param rhs The right hand side vector b - * \param x On input and initial solution, on output the computed solution. - * \param precond A preconditioner being able to efficiently solve for an - * approximation of Ax=b (regardless of b) - * \param iters On input the max number of iteration, on output the number of performed iterations. - * \param tol_error On input the tolerance error, on output an estimation of the relative error. - * \return false in the case of numerical issue, for example a break down of BiCGSTAB. - */ -template<typename MatrixType, typename Rhs, typename Dest, typename Preconditioner> -bool bicgstab(const MatrixType& mat, const Rhs& rhs, Dest& x, - const Preconditioner& precond, Index& iters, - typename Dest::RealScalar& tol_error) -{ - using std::sqrt; - using std::abs; - typedef typename Dest::RealScalar RealScalar; - typedef typename Dest::Scalar Scalar; - typedef Matrix<Scalar,Dynamic,1> VectorType; - RealScalar tol = tol_error; - Index maxIters = iters; - - Index n = mat.cols(); - VectorType r = rhs - mat * x; - VectorType r0 = r; - - RealScalar r0_sqnorm = r0.squaredNorm(); - RealScalar rhs_sqnorm = rhs.squaredNorm(); - if(rhs_sqnorm == 0) - { - x.setZero(); - return true; - } - Scalar rho = 1; - Scalar alpha = 1; - Scalar w = 1; - - VectorType v = VectorType::Zero(n), p = VectorType::Zero(n); - VectorType y(n), z(n); - VectorType kt(n), ks(n); - - VectorType s(n), t(n); - - RealScalar tol2 = tol*tol*rhs_sqnorm; - RealScalar eps2 = NumTraits<Scalar>::epsilon()*NumTraits<Scalar>::epsilon(); - Index i = 0; - Index restarts = 0; - - while ( r.squaredNorm() > tol2 && i<maxIters ) - { - Scalar rho_old = rho; - - rho = r0.dot(r); - if (abs(rho) < eps2*r0_sqnorm) - { - // The new residual vector became too orthogonal to the arbitrarily chosen direction r0 - // Let's restart with a new r0: - r = rhs - mat * x; - r0 = r; - rho = r0_sqnorm = r.squaredNorm(); - if(restarts++ == 0) - i = 0; - } - Scalar beta = (rho/rho_old) * (alpha / w); - p = r + beta * (p - w * v); - - y = precond.solve(p); - - v.noalias() = mat * y; - - alpha = rho / r0.dot(v); - s = r - alpha * v; - - z = precond.solve(s); - t.noalias() = mat * z; - - RealScalar tmp = t.squaredNorm(); - if(tmp>RealScalar(0)) - w = t.dot(s) / tmp; - else - w = Scalar(0); - x += alpha * y + w * z; - r = s - w * t; - ++i; - } - tol_error = sqrt(r.squaredNorm()/rhs_sqnorm); - iters = i; - return true; -} - -} - -template< typename _MatrixType, - typename _Preconditioner = DiagonalPreconditioner<typename _MatrixType::Scalar> > -class BiCGSTAB; - -namespace internal { - -template< typename _MatrixType, typename _Preconditioner> -struct traits<BiCGSTAB<_MatrixType,_Preconditioner> > -{ - typedef _MatrixType MatrixType; - typedef _Preconditioner Preconditioner; -}; - -} - -/** \ingroup IterativeLinearSolvers_Module - * \brief A bi conjugate gradient stabilized solver for sparse square problems - * - * This class allows to solve for A.x = b sparse linear problems using a bi conjugate gradient - * stabilized algorithm. The vectors x and b can be either dense or sparse. - * - * \tparam _MatrixType the type of the sparse matrix A, can be a dense or a sparse matrix. - * \tparam _Preconditioner the type of the preconditioner. Default is DiagonalPreconditioner - * - * \implsparsesolverconcept - * - * The maximal number of iterations and tolerance value can be controlled via the setMaxIterations() - * and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations - * and NumTraits<Scalar>::epsilon() for the tolerance. - * - * The tolerance corresponds to the relative residual error: |Ax-b|/|b| - * - * \b Performance: when using sparse matrices, best performance is achied for a row-major sparse matrix format. - * Moreover, in this case multi-threading can be exploited if the user code is compiled with OpenMP enabled. - * See \ref TopicMultiThreading for details. - * - * This class can be used as the direct solver classes. Here is a typical usage example: - * \include BiCGSTAB_simple.cpp - * - * By default the iterations start with x=0 as an initial guess of the solution. - * One can control the start using the solveWithGuess() method. - * - * BiCGSTAB can also be used in a matrix-free context, see the following \link MatrixfreeSolverExample example \endlink. - * - * \sa class SimplicialCholesky, DiagonalPreconditioner, IdentityPreconditioner - */ -template< typename _MatrixType, typename _Preconditioner> -class BiCGSTAB : public IterativeSolverBase<BiCGSTAB<_MatrixType,_Preconditioner> > -{ - typedef IterativeSolverBase<BiCGSTAB> Base; - using Base::matrix; - using Base::m_error; - using Base::m_iterations; - using Base::m_info; - using Base::m_isInitialized; -public: - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef _Preconditioner Preconditioner; - -public: - - /** Default constructor. */ - BiCGSTAB() : Base() {} - - /** Initialize the solver with matrix \a A for further \c Ax=b solving. - * - * This constructor is a shortcut for the default constructor followed - * by a call to compute(). - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - explicit BiCGSTAB(const EigenBase<MatrixDerived>& A) : Base(A.derived()) {} - - ~BiCGSTAB() {} - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_vector_with_guess_impl(const Rhs& b, Dest& x) const - { - m_iterations = Base::maxIterations(); - m_error = Base::m_tolerance; - - bool ret = internal::bicgstab(matrix(), b, x, Base::m_preconditioner, m_iterations, m_error); - - m_info = (!ret) ? NumericalIssue - : m_error <= Base::m_tolerance ? Success - : NoConvergence; - } - -protected: - -}; - -} // end namespace Eigen - -#endif // EIGEN_BICGSTAB_H diff --git a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h b/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h deleted file mode 100644 index 96e8b9f8..00000000 --- a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h +++ /dev/null @@ -1,229 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CONJUGATE_GRADIENT_H -#define EIGEN_CONJUGATE_GRADIENT_H - -namespace Eigen { - -namespace internal { - -/** \internal Low-level conjugate gradient algorithm - * \param mat The matrix A - * \param rhs The right hand side vector b - * \param x On input and initial solution, on output the computed solution. - * \param precond A preconditioner being able to efficiently solve for an - * approximation of Ax=b (regardless of b) - * \param iters On input the max number of iteration, on output the number of performed iterations. - * \param tol_error On input the tolerance error, on output an estimation of the relative error. - */ -template<typename MatrixType, typename Rhs, typename Dest, typename Preconditioner> -EIGEN_DONT_INLINE -void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x, - const Preconditioner& precond, Index& iters, - typename Dest::RealScalar& tol_error) -{ - using std::sqrt; - using std::abs; - typedef typename Dest::RealScalar RealScalar; - typedef typename Dest::Scalar Scalar; - typedef Matrix<Scalar,Dynamic,1> VectorType; - - RealScalar tol = tol_error; - Index maxIters = iters; - - Index n = mat.cols(); - - VectorType residual = rhs - mat * x; //initial residual - - RealScalar rhsNorm2 = rhs.squaredNorm(); - if(rhsNorm2 == 0) - { - x.setZero(); - iters = 0; - tol_error = 0; - return; - } - const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)(); - RealScalar threshold = numext::maxi(tol*tol*rhsNorm2,considerAsZero); - RealScalar residualNorm2 = residual.squaredNorm(); - if (residualNorm2 < threshold) - { - iters = 0; - tol_error = sqrt(residualNorm2 / rhsNorm2); - return; - } - - VectorType p(n); - p = precond.solve(residual); // initial search direction - - VectorType z(n), tmp(n); - RealScalar absNew = numext::real(residual.dot(p)); // the square of the absolute value of r scaled by invM - Index i = 0; - while(i < maxIters) - { - tmp.noalias() = mat * p; // the bottleneck of the algorithm - - Scalar alpha = absNew / p.dot(tmp); // the amount we travel on dir - x += alpha * p; // update solution - residual -= alpha * tmp; // update residual - - residualNorm2 = residual.squaredNorm(); - if(residualNorm2 < threshold) - break; - - z = precond.solve(residual); // approximately solve for "A z = residual" - - RealScalar absOld = absNew; - absNew = numext::real(residual.dot(z)); // update the absolute value of r - RealScalar beta = absNew / absOld; // calculate the Gram-Schmidt value used to create the new search direction - p = z + beta * p; // update search direction - i++; - } - tol_error = sqrt(residualNorm2 / rhsNorm2); - iters = i; -} - -} - -template< typename _MatrixType, int _UpLo=Lower, - typename _Preconditioner = DiagonalPreconditioner<typename _MatrixType::Scalar> > -class ConjugateGradient; - -namespace internal { - -template< typename _MatrixType, int _UpLo, typename _Preconditioner> -struct traits<ConjugateGradient<_MatrixType,_UpLo,_Preconditioner> > -{ - typedef _MatrixType MatrixType; - typedef _Preconditioner Preconditioner; -}; - -} - -/** \ingroup IterativeLinearSolvers_Module - * \brief A conjugate gradient solver for sparse (or dense) self-adjoint problems - * - * This class allows to solve for A.x = b linear problems using an iterative conjugate gradient algorithm. - * The matrix A must be selfadjoint. The matrix A and the vectors x and b can be either dense or sparse. - * - * \tparam _MatrixType the type of the matrix A, can be a dense or a sparse matrix. - * \tparam _UpLo the triangular part that will be used for the computations. It can be Lower, - * \c Upper, or \c Lower|Upper in which the full matrix entries will be considered. - * Default is \c Lower, best performance is \c Lower|Upper. - * \tparam _Preconditioner the type of the preconditioner. Default is DiagonalPreconditioner - * - * \implsparsesolverconcept - * - * The maximal number of iterations and tolerance value can be controlled via the setMaxIterations() - * and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations - * and NumTraits<Scalar>::epsilon() for the tolerance. - * - * The tolerance corresponds to the relative residual error: |Ax-b|/|b| - * - * \b Performance: Even though the default value of \c _UpLo is \c Lower, significantly higher performance is - * achieved when using a complete matrix and \b Lower|Upper as the \a _UpLo template parameter. Moreover, in this - * case multi-threading can be exploited if the user code is compiled with OpenMP enabled. - * See \ref TopicMultiThreading for details. - * - * This class can be used as the direct solver classes. Here is a typical usage example: - \code - int n = 10000; - VectorXd x(n), b(n); - SparseMatrix<double> A(n,n); - // fill A and b - ConjugateGradient<SparseMatrix<double>, Lower|Upper> cg; - cg.compute(A); - x = cg.solve(b); - std::cout << "#iterations: " << cg.iterations() << std::endl; - std::cout << "estimated error: " << cg.error() << std::endl; - // update b, and solve again - x = cg.solve(b); - \endcode - * - * By default the iterations start with x=0 as an initial guess of the solution. - * One can control the start using the solveWithGuess() method. - * - * ConjugateGradient can also be used in a matrix-free context, see the following \link MatrixfreeSolverExample example \endlink. - * - * \sa class LeastSquaresConjugateGradient, class SimplicialCholesky, DiagonalPreconditioner, IdentityPreconditioner - */ -template< typename _MatrixType, int _UpLo, typename _Preconditioner> -class ConjugateGradient : public IterativeSolverBase<ConjugateGradient<_MatrixType,_UpLo,_Preconditioner> > -{ - typedef IterativeSolverBase<ConjugateGradient> Base; - using Base::matrix; - using Base::m_error; - using Base::m_iterations; - using Base::m_info; - using Base::m_isInitialized; -public: - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef _Preconditioner Preconditioner; - - enum { - UpLo = _UpLo - }; - -public: - - /** Default constructor. */ - ConjugateGradient() : Base() {} - - /** Initialize the solver with matrix \a A for further \c Ax=b solving. - * - * This constructor is a shortcut for the default constructor followed - * by a call to compute(). - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - explicit ConjugateGradient(const EigenBase<MatrixDerived>& A) : Base(A.derived()) {} - - ~ConjugateGradient() {} - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_vector_with_guess_impl(const Rhs& b, Dest& x) const - { - typedef typename Base::MatrixWrapper MatrixWrapper; - typedef typename Base::ActualMatrixType ActualMatrixType; - enum { - TransposeInput = (!MatrixWrapper::MatrixFree) - && (UpLo==(Lower|Upper)) - && (!MatrixType::IsRowMajor) - && (!NumTraits<Scalar>::IsComplex) - }; - typedef typename internal::conditional<TransposeInput,Transpose<const ActualMatrixType>, ActualMatrixType const&>::type RowMajorWrapper; - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(MatrixWrapper::MatrixFree,UpLo==(Lower|Upper)),MATRIX_FREE_CONJUGATE_GRADIENT_IS_COMPATIBLE_WITH_UPPER_UNION_LOWER_MODE_ONLY); - typedef typename internal::conditional<UpLo==(Lower|Upper), - RowMajorWrapper, - typename MatrixWrapper::template ConstSelfAdjointViewReturnType<UpLo>::Type - >::type SelfAdjointWrapper; - - m_iterations = Base::maxIterations(); - m_error = Base::m_tolerance; - - RowMajorWrapper row_mat(matrix()); - internal::conjugate_gradient(SelfAdjointWrapper(row_mat), b, x, Base::m_preconditioner, m_iterations, m_error); - m_info = m_error <= Base::m_tolerance ? Success : NoConvergence; - } - -protected: - -}; - -} // end namespace Eigen - -#endif // EIGEN_CONJUGATE_GRADIENT_H diff --git a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h b/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h deleted file mode 100644 index e5d0308e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h +++ /dev/null @@ -1,394 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_INCOMPLETE_CHOlESKY_H -#define EIGEN_INCOMPLETE_CHOlESKY_H - -#include <vector> -#include <list> - -namespace Eigen { -/** - * \brief Modified Incomplete Cholesky with dual threshold - * - * References : C-J. Lin and J. J. Moré, Incomplete Cholesky Factorizations with - * Limited memory, SIAM J. Sci. Comput. 21(1), pp. 24-45, 1999 - * - * \tparam Scalar the scalar type of the input matrices - * \tparam _UpLo The triangular part that will be used for the computations. It can be Lower - * or Upper. Default is Lower. - * \tparam _OrderingType The ordering method to use, either AMDOrdering<> or NaturalOrdering<>. Default is AMDOrdering<int>, - * unless EIGEN_MPL2_ONLY is defined, in which case the default is NaturalOrdering<int>. - * - * \implsparsesolverconcept - * - * It performs the following incomplete factorization: \f$ S P A P' S \approx L L' \f$ - * where L is a lower triangular factor, S is a diagonal scaling matrix, and P is a - * fill-in reducing permutation as computed by the ordering method. - * - * \b Shifting \b strategy: Let \f$ B = S P A P' S \f$ be the scaled matrix on which the factorization is carried out, - * and \f$ \beta \f$ be the minimum value of the diagonal. If \f$ \beta > 0 \f$ then, the factorization is directly performed - * on the matrix B. Otherwise, the factorization is performed on the shifted matrix \f$ B + (\sigma+|\beta| I \f$ where - * \f$ \sigma \f$ is the initial shift value as returned and set by setInitialShift() method. The default value is \f$ \sigma = 10^{-3} \f$. - * If the factorization fails, then the shift in doubled until it succeed or a maximum of ten attempts. If it still fails, as returned by - * the info() method, then you can either increase the initial shift, or better use another preconditioning technique. - * - */ -template <typename Scalar, int _UpLo = Lower, typename _OrderingType = AMDOrdering<int> > -class IncompleteCholesky : public SparseSolverBase<IncompleteCholesky<Scalar,_UpLo,_OrderingType> > -{ - protected: - typedef SparseSolverBase<IncompleteCholesky<Scalar,_UpLo,_OrderingType> > Base; - using Base::m_isInitialized; - public: - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef _OrderingType OrderingType; - typedef typename OrderingType::PermutationType PermutationType; - typedef typename PermutationType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar,ColMajor,StorageIndex> FactorType; - typedef Matrix<Scalar,Dynamic,1> VectorSx; - typedef Matrix<RealScalar,Dynamic,1> VectorRx; - typedef Matrix<StorageIndex,Dynamic, 1> VectorIx; - typedef std::vector<std::list<StorageIndex> > VectorList; - enum { UpLo = _UpLo }; - enum { - ColsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic - }; - public: - - /** Default constructor leaving the object in a partly non-initialized stage. - * - * You must call compute() or the pair analyzePattern()/factorize() to make it valid. - * - * \sa IncompleteCholesky(const MatrixType&) - */ - IncompleteCholesky() : m_initialShift(1e-3),m_analysisIsOk(false),m_factorizationIsOk(false) {} - - /** Constructor computing the incomplete factorization for the given matrix \a matrix. - */ - template<typename MatrixType> - IncompleteCholesky(const MatrixType& matrix) : m_initialShift(1e-3),m_analysisIsOk(false),m_factorizationIsOk(false) - { - compute(matrix); - } - - /** \returns number of rows of the factored matrix */ - Index rows() const { return m_L.rows(); } - - /** \returns number of columns of the factored matrix */ - Index cols() const { return m_L.cols(); } - - - /** \brief Reports whether previous computation was successful. - * - * It triggers an assertion if \c *this has not been initialized through the respective constructor, - * or a call to compute() or analyzePattern(). - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix appears to be negative. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "IncompleteCholesky is not initialized."); - return m_info; - } - - /** \brief Set the initial shift parameter \f$ \sigma \f$. - */ - void setInitialShift(RealScalar shift) { m_initialShift = shift; } - - /** \brief Computes the fill reducing permutation vector using the sparsity pattern of \a mat - */ - template<typename MatrixType> - void analyzePattern(const MatrixType& mat) - { - OrderingType ord; - PermutationType pinv; - ord(mat.template selfadjointView<UpLo>(), pinv); - if(pinv.size()>0) m_perm = pinv.inverse(); - else m_perm.resize(0); - m_L.resize(mat.rows(), mat.cols()); - m_analysisIsOk = true; - m_isInitialized = true; - m_info = Success; - } - - /** \brief Performs the numerical factorization of the input matrix \a mat - * - * The method analyzePattern() or compute() must have been called beforehand - * with a matrix having the same pattern. - * - * \sa compute(), analyzePattern() - */ - template<typename MatrixType> - void factorize(const MatrixType& mat); - - /** Computes or re-computes the incomplete Cholesky factorization of the input matrix \a mat - * - * It is a shortcut for a sequential call to the analyzePattern() and factorize() methods. - * - * \sa analyzePattern(), factorize() - */ - template<typename MatrixType> - void compute(const MatrixType& mat) - { - analyzePattern(mat); - factorize(mat); - } - - // internal - template<typename Rhs, typename Dest> - void _solve_impl(const Rhs& b, Dest& x) const - { - eigen_assert(m_factorizationIsOk && "factorize() should be called first"); - if (m_perm.rows() == b.rows()) x = m_perm * b; - else x = b; - x = m_scale.asDiagonal() * x; - x = m_L.template triangularView<Lower>().solve(x); - x = m_L.adjoint().template triangularView<Upper>().solve(x); - x = m_scale.asDiagonal() * x; - if (m_perm.rows() == b.rows()) - x = m_perm.inverse() * x; - } - - /** \returns the sparse lower triangular factor L */ - const FactorType& matrixL() const { eigen_assert("m_factorizationIsOk"); return m_L; } - - /** \returns a vector representing the scaling factor S */ - const VectorRx& scalingS() const { eigen_assert("m_factorizationIsOk"); return m_scale; } - - /** \returns the fill-in reducing permutation P (can be empty for a natural ordering) */ - const PermutationType& permutationP() const { eigen_assert("m_analysisIsOk"); return m_perm; } - - protected: - FactorType m_L; // The lower part stored in CSC - VectorRx m_scale; // The vector for scaling the matrix - RealScalar m_initialShift; // The initial shift parameter - bool m_analysisIsOk; - bool m_factorizationIsOk; - ComputationInfo m_info; - PermutationType m_perm; - - private: - inline void updateList(Ref<const VectorIx> colPtr, Ref<VectorIx> rowIdx, Ref<VectorSx> vals, const Index& col, const Index& jk, VectorIx& firstElt, VectorList& listCol); -}; - -// Based on the following paper: -// C-J. Lin and J. J. Moré, Incomplete Cholesky Factorizations with -// Limited memory, SIAM J. Sci. Comput. 21(1), pp. 24-45, 1999 -// http://ftp.mcs.anl.gov/pub/tech_reports/reports/P682.pdf -template<typename Scalar, int _UpLo, typename OrderingType> -template<typename _MatrixType> -void IncompleteCholesky<Scalar,_UpLo, OrderingType>::factorize(const _MatrixType& mat) -{ - using std::sqrt; - eigen_assert(m_analysisIsOk && "analyzePattern() should be called first"); - - // Dropping strategy : Keep only the p largest elements per column, where p is the number of elements in the column of the original matrix. Other strategies will be added - - // Apply the fill-reducing permutation computed in analyzePattern() - if (m_perm.rows() == mat.rows() ) // To detect the null permutation - { - // The temporary is needed to make sure that the diagonal entry is properly sorted - FactorType tmp(mat.rows(), mat.cols()); - tmp = mat.template selfadjointView<_UpLo>().twistedBy(m_perm); - m_L.template selfadjointView<Lower>() = tmp.template selfadjointView<Lower>(); - } - else - { - m_L.template selfadjointView<Lower>() = mat.template selfadjointView<_UpLo>(); - } - - Index n = m_L.cols(); - Index nnz = m_L.nonZeros(); - Map<VectorSx> vals(m_L.valuePtr(), nnz); //values - Map<VectorIx> rowIdx(m_L.innerIndexPtr(), nnz); //Row indices - Map<VectorIx> colPtr( m_L.outerIndexPtr(), n+1); // Pointer to the beginning of each row - VectorIx firstElt(n-1); // for each j, points to the next entry in vals that will be used in the factorization - VectorList listCol(n); // listCol(j) is a linked list of columns to update column j - VectorSx col_vals(n); // Store a nonzero values in each column - VectorIx col_irow(n); // Row indices of nonzero elements in each column - VectorIx col_pattern(n); - col_pattern.fill(-1); - StorageIndex col_nnz; - - - // Computes the scaling factors - m_scale.resize(n); - m_scale.setZero(); - for (Index j = 0; j < n; j++) - for (Index k = colPtr[j]; k < colPtr[j+1]; k++) - { - m_scale(j) += numext::abs2(vals(k)); - if(rowIdx[k]!=j) - m_scale(rowIdx[k]) += numext::abs2(vals(k)); - } - - m_scale = m_scale.cwiseSqrt().cwiseSqrt(); - - for (Index j = 0; j < n; ++j) - if(m_scale(j)>(std::numeric_limits<RealScalar>::min)()) - m_scale(j) = RealScalar(1)/m_scale(j); - else - m_scale(j) = 1; - - // TODO disable scaling if not needed, i.e., if it is roughly uniform? (this will make solve() faster) - - // Scale and compute the shift for the matrix - RealScalar mindiag = NumTraits<RealScalar>::highest(); - for (Index j = 0; j < n; j++) - { - for (Index k = colPtr[j]; k < colPtr[j+1]; k++) - vals[k] *= (m_scale(j)*m_scale(rowIdx[k])); - eigen_internal_assert(rowIdx[colPtr[j]]==j && "IncompleteCholesky: only the lower triangular part must be stored"); - mindiag = numext::mini(numext::real(vals[colPtr[j]]), mindiag); - } - - FactorType L_save = m_L; - - RealScalar shift = 0; - if(mindiag <= RealScalar(0.)) - shift = m_initialShift - mindiag; - - m_info = NumericalIssue; - - // Try to perform the incomplete factorization using the current shift - int iter = 0; - do - { - // Apply the shift to the diagonal elements of the matrix - for (Index j = 0; j < n; j++) - vals[colPtr[j]] += shift; - - // jki version of the Cholesky factorization - Index j=0; - for (; j < n; ++j) - { - // Left-looking factorization of the j-th column - // First, load the j-th column into col_vals - Scalar diag = vals[colPtr[j]]; // It is assumed that only the lower part is stored - col_nnz = 0; - for (Index i = colPtr[j] + 1; i < colPtr[j+1]; i++) - { - StorageIndex l = rowIdx[i]; - col_vals(col_nnz) = vals[i]; - col_irow(col_nnz) = l; - col_pattern(l) = col_nnz; - col_nnz++; - } - { - typename std::list<StorageIndex>::iterator k; - // Browse all previous columns that will update column j - for(k = listCol[j].begin(); k != listCol[j].end(); k++) - { - Index jk = firstElt(*k); // First element to use in the column - eigen_internal_assert(rowIdx[jk]==j); - Scalar v_j_jk = numext::conj(vals[jk]); - - jk += 1; - for (Index i = jk; i < colPtr[*k+1]; i++) - { - StorageIndex l = rowIdx[i]; - if(col_pattern[l]<0) - { - col_vals(col_nnz) = vals[i] * v_j_jk; - col_irow[col_nnz] = l; - col_pattern(l) = col_nnz; - col_nnz++; - } - else - col_vals(col_pattern[l]) -= vals[i] * v_j_jk; - } - updateList(colPtr,rowIdx,vals, *k, jk, firstElt, listCol); - } - } - - // Scale the current column - if(numext::real(diag) <= 0) - { - if(++iter>=10) - return; - - // increase shift - shift = numext::maxi(m_initialShift,RealScalar(2)*shift); - // restore m_L, col_pattern, and listCol - vals = Map<const VectorSx>(L_save.valuePtr(), nnz); - rowIdx = Map<const VectorIx>(L_save.innerIndexPtr(), nnz); - colPtr = Map<const VectorIx>(L_save.outerIndexPtr(), n+1); - col_pattern.fill(-1); - for(Index i=0; i<n; ++i) - listCol[i].clear(); - - break; - } - - RealScalar rdiag = sqrt(numext::real(diag)); - vals[colPtr[j]] = rdiag; - for (Index k = 0; k<col_nnz; ++k) - { - Index i = col_irow[k]; - //Scale - col_vals(k) /= rdiag; - //Update the remaining diagonals with col_vals - vals[colPtr[i]] -= numext::abs2(col_vals(k)); - } - // Select the largest p elements - // p is the original number of elements in the column (without the diagonal) - Index p = colPtr[j+1] - colPtr[j] - 1 ; - Ref<VectorSx> cvals = col_vals.head(col_nnz); - Ref<VectorIx> cirow = col_irow.head(col_nnz); - internal::QuickSplit(cvals,cirow, p); - // Insert the largest p elements in the matrix - Index cpt = 0; - for (Index i = colPtr[j]+1; i < colPtr[j+1]; i++) - { - vals[i] = col_vals(cpt); - rowIdx[i] = col_irow(cpt); - // restore col_pattern: - col_pattern(col_irow(cpt)) = -1; - cpt++; - } - // Get the first smallest row index and put it after the diagonal element - Index jk = colPtr(j)+1; - updateList(colPtr,rowIdx,vals,j,jk,firstElt,listCol); - } - - if(j==n) - { - m_factorizationIsOk = true; - m_info = Success; - } - } while(m_info!=Success); -} - -template<typename Scalar, int _UpLo, typename OrderingType> -inline void IncompleteCholesky<Scalar,_UpLo, OrderingType>::updateList(Ref<const VectorIx> colPtr, Ref<VectorIx> rowIdx, Ref<VectorSx> vals, const Index& col, const Index& jk, VectorIx& firstElt, VectorList& listCol) -{ - if (jk < colPtr(col+1) ) - { - Index p = colPtr(col+1) - jk; - Index minpos; - rowIdx.segment(jk,p).minCoeff(&minpos); - minpos += jk; - if (rowIdx(minpos) != rowIdx(jk)) - { - //Swap - std::swap(rowIdx(jk),rowIdx(minpos)); - std::swap(vals(jk),vals(minpos)); - } - firstElt(col) = internal::convert_index<StorageIndex,Index>(jk); - listCol[rowIdx(jk)].push_back(internal::convert_index<StorageIndex,Index>(col)); - } -} - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h b/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h deleted file mode 100644 index 09436cb6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h +++ /dev/null @@ -1,453 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_INCOMPLETE_LUT_H -#define EIGEN_INCOMPLETE_LUT_H - - -namespace Eigen { - -namespace internal { - -/** \internal - * Compute a quick-sort split of a vector - * On output, the vector row is permuted such that its elements satisfy - * abs(row(i)) >= abs(row(ncut)) if i<ncut - * abs(row(i)) <= abs(row(ncut)) if i>ncut - * \param row The vector of values - * \param ind The array of index for the elements in @p row - * \param ncut The number of largest elements to keep - **/ -template <typename VectorV, typename VectorI> -Index QuickSplit(VectorV &row, VectorI &ind, Index ncut) -{ - typedef typename VectorV::RealScalar RealScalar; - using std::swap; - using std::abs; - Index mid; - Index n = row.size(); /* length of the vector */ - Index first, last ; - - ncut--; /* to fit the zero-based indices */ - first = 0; - last = n-1; - if (ncut < first || ncut > last ) return 0; - - do { - mid = first; - RealScalar abskey = abs(row(mid)); - for (Index j = first + 1; j <= last; j++) { - if ( abs(row(j)) > abskey) { - ++mid; - swap(row(mid), row(j)); - swap(ind(mid), ind(j)); - } - } - /* Interchange for the pivot element */ - swap(row(mid), row(first)); - swap(ind(mid), ind(first)); - - if (mid > ncut) last = mid - 1; - else if (mid < ncut ) first = mid + 1; - } while (mid != ncut ); - - return 0; /* mid is equal to ncut */ -} - -}// end namespace internal - -/** \ingroup IterativeLinearSolvers_Module - * \class IncompleteLUT - * \brief Incomplete LU factorization with dual-threshold strategy - * - * \implsparsesolverconcept - * - * During the numerical factorization, two dropping rules are used : - * 1) any element whose magnitude is less than some tolerance is dropped. - * This tolerance is obtained by multiplying the input tolerance @p droptol - * by the average magnitude of all the original elements in the current row. - * 2) After the elimination of the row, only the @p fill largest elements in - * the L part and the @p fill largest elements in the U part are kept - * (in addition to the diagonal element ). Note that @p fill is computed from - * the input parameter @p fillfactor which is used the ratio to control the fill_in - * relatively to the initial number of nonzero elements. - * - * The two extreme cases are when @p droptol=0 (to keep all the @p fill*2 largest elements) - * and when @p fill=n/2 with @p droptol being different to zero. - * - * References : Yousef Saad, ILUT: A dual threshold incomplete LU factorization, - * Numerical Linear Algebra with Applications, 1(4), pp 387-402, 1994. - * - * NOTE : The following implementation is derived from the ILUT implementation - * in the SPARSKIT package, Copyright (C) 2005, the Regents of the University of Minnesota - * released under the terms of the GNU LGPL: - * http://www-users.cs.umn.edu/~saad/software/SPARSKIT/README - * However, Yousef Saad gave us permission to relicense his ILUT code to MPL2. - * See the Eigen mailing list archive, thread: ILUT, date: July 8, 2012: - * http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2012/07/msg00064.html - * alternatively, on GMANE: - * http://comments.gmane.org/gmane.comp.lib.eigen/3302 - */ -template <typename _Scalar, typename _StorageIndex = int> -class IncompleteLUT : public SparseSolverBase<IncompleteLUT<_Scalar, _StorageIndex> > -{ - protected: - typedef SparseSolverBase<IncompleteLUT> Base; - using Base::m_isInitialized; - public: - typedef _Scalar Scalar; - typedef _StorageIndex StorageIndex; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Matrix<Scalar,Dynamic,1> Vector; - typedef Matrix<StorageIndex,Dynamic,1> VectorI; - typedef SparseMatrix<Scalar,RowMajor,StorageIndex> FactorType; - - enum { - ColsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic - }; - - public: - - IncompleteLUT() - : m_droptol(NumTraits<Scalar>::dummy_precision()), m_fillfactor(10), - m_analysisIsOk(false), m_factorizationIsOk(false) - {} - - template<typename MatrixType> - explicit IncompleteLUT(const MatrixType& mat, const RealScalar& droptol=NumTraits<Scalar>::dummy_precision(), int fillfactor = 10) - : m_droptol(droptol),m_fillfactor(fillfactor), - m_analysisIsOk(false),m_factorizationIsOk(false) - { - eigen_assert(fillfactor != 0); - compute(mat); - } - - Index rows() const { return m_lu.rows(); } - - Index cols() const { return m_lu.cols(); } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix.appears to be negative. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "IncompleteLUT is not initialized."); - return m_info; - } - - template<typename MatrixType> - void analyzePattern(const MatrixType& amat); - - template<typename MatrixType> - void factorize(const MatrixType& amat); - - /** - * Compute an incomplete LU factorization with dual threshold on the matrix mat - * No pivoting is done in this version - * - **/ - template<typename MatrixType> - IncompleteLUT& compute(const MatrixType& amat) - { - analyzePattern(amat); - factorize(amat); - return *this; - } - - void setDroptol(const RealScalar& droptol); - void setFillfactor(int fillfactor); - - template<typename Rhs, typename Dest> - void _solve_impl(const Rhs& b, Dest& x) const - { - x = m_Pinv * b; - x = m_lu.template triangularView<UnitLower>().solve(x); - x = m_lu.template triangularView<Upper>().solve(x); - x = m_P * x; - } - -protected: - - /** keeps off-diagonal entries; drops diagonal entries */ - struct keep_diag { - inline bool operator() (const Index& row, const Index& col, const Scalar&) const - { - return row!=col; - } - }; - -protected: - - FactorType m_lu; - RealScalar m_droptol; - int m_fillfactor; - bool m_analysisIsOk; - bool m_factorizationIsOk; - ComputationInfo m_info; - PermutationMatrix<Dynamic,Dynamic,StorageIndex> m_P; // Fill-reducing permutation - PermutationMatrix<Dynamic,Dynamic,StorageIndex> m_Pinv; // Inverse permutation -}; - -/** - * Set control parameter droptol - * \param droptol Drop any element whose magnitude is less than this tolerance - **/ -template<typename Scalar, typename StorageIndex> -void IncompleteLUT<Scalar,StorageIndex>::setDroptol(const RealScalar& droptol) -{ - this->m_droptol = droptol; -} - -/** - * Set control parameter fillfactor - * \param fillfactor This is used to compute the number @p fill_in of largest elements to keep on each row. - **/ -template<typename Scalar, typename StorageIndex> -void IncompleteLUT<Scalar,StorageIndex>::setFillfactor(int fillfactor) -{ - this->m_fillfactor = fillfactor; -} - -template <typename Scalar, typename StorageIndex> -template<typename _MatrixType> -void IncompleteLUT<Scalar,StorageIndex>::analyzePattern(const _MatrixType& amat) -{ - // Compute the Fill-reducing permutation - // Since ILUT does not perform any numerical pivoting, - // it is highly preferable to keep the diagonal through symmetric permutations. - // To this end, let's symmetrize the pattern and perform AMD on it. - SparseMatrix<Scalar,ColMajor, StorageIndex> mat1 = amat; - SparseMatrix<Scalar,ColMajor, StorageIndex> mat2 = amat.transpose(); - // FIXME for a matrix with nearly symmetric pattern, mat2+mat1 is the appropriate choice. - // on the other hand for a really non-symmetric pattern, mat2*mat1 should be preferred... - SparseMatrix<Scalar,ColMajor, StorageIndex> AtA = mat2 + mat1; - AMDOrdering<StorageIndex> ordering; - ordering(AtA,m_P); - m_Pinv = m_P.inverse(); // cache the inverse permutation - m_analysisIsOk = true; - m_factorizationIsOk = false; - m_isInitialized = true; -} - -template <typename Scalar, typename StorageIndex> -template<typename _MatrixType> -void IncompleteLUT<Scalar,StorageIndex>::factorize(const _MatrixType& amat) -{ - using std::sqrt; - using std::swap; - using std::abs; - using internal::convert_index; - - eigen_assert((amat.rows() == amat.cols()) && "The factorization should be done on a square matrix"); - Index n = amat.cols(); // Size of the matrix - m_lu.resize(n,n); - // Declare Working vectors and variables - Vector u(n) ; // real values of the row -- maximum size is n -- - VectorI ju(n); // column position of the values in u -- maximum size is n - VectorI jr(n); // Indicate the position of the nonzero elements in the vector u -- A zero location is indicated by -1 - - // Apply the fill-reducing permutation - eigen_assert(m_analysisIsOk && "You must first call analyzePattern()"); - SparseMatrix<Scalar,RowMajor, StorageIndex> mat; - mat = amat.twistedBy(m_Pinv); - - // Initialization - jr.fill(-1); - ju.fill(0); - u.fill(0); - - // number of largest elements to keep in each row: - Index fill_in = (amat.nonZeros()*m_fillfactor)/n + 1; - if (fill_in > n) fill_in = n; - - // number of largest nonzero elements to keep in the L and the U part of the current row: - Index nnzL = fill_in/2; - Index nnzU = nnzL; - m_lu.reserve(n * (nnzL + nnzU + 1)); - - // global loop over the rows of the sparse matrix - for (Index ii = 0; ii < n; ii++) - { - // 1 - copy the lower and the upper part of the row i of mat in the working vector u - - Index sizeu = 1; // number of nonzero elements in the upper part of the current row - Index sizel = 0; // number of nonzero elements in the lower part of the current row - ju(ii) = convert_index<StorageIndex>(ii); - u(ii) = 0; - jr(ii) = convert_index<StorageIndex>(ii); - RealScalar rownorm = 0; - - typename FactorType::InnerIterator j_it(mat, ii); // Iterate through the current row ii - for (; j_it; ++j_it) - { - Index k = j_it.index(); - if (k < ii) - { - // copy the lower part - ju(sizel) = convert_index<StorageIndex>(k); - u(sizel) = j_it.value(); - jr(k) = convert_index<StorageIndex>(sizel); - ++sizel; - } - else if (k == ii) - { - u(ii) = j_it.value(); - } - else - { - // copy the upper part - Index jpos = ii + sizeu; - ju(jpos) = convert_index<StorageIndex>(k); - u(jpos) = j_it.value(); - jr(k) = convert_index<StorageIndex>(jpos); - ++sizeu; - } - rownorm += numext::abs2(j_it.value()); - } - - // 2 - detect possible zero row - if(rownorm==0) - { - m_info = NumericalIssue; - return; - } - // Take the 2-norm of the current row as a relative tolerance - rownorm = sqrt(rownorm); - - // 3 - eliminate the previous nonzero rows - Index jj = 0; - Index len = 0; - while (jj < sizel) - { - // In order to eliminate in the correct order, - // we must select first the smallest column index among ju(jj:sizel) - Index k; - Index minrow = ju.segment(jj,sizel-jj).minCoeff(&k); // k is relative to the segment - k += jj; - if (minrow != ju(jj)) - { - // swap the two locations - Index j = ju(jj); - swap(ju(jj), ju(k)); - jr(minrow) = convert_index<StorageIndex>(jj); - jr(j) = convert_index<StorageIndex>(k); - swap(u(jj), u(k)); - } - // Reset this location - jr(minrow) = -1; - - // Start elimination - typename FactorType::InnerIterator ki_it(m_lu, minrow); - while (ki_it && ki_it.index() < minrow) ++ki_it; - eigen_internal_assert(ki_it && ki_it.col()==minrow); - Scalar fact = u(jj) / ki_it.value(); - - // drop too small elements - if(abs(fact) <= m_droptol) - { - jj++; - continue; - } - - // linear combination of the current row ii and the row minrow - ++ki_it; - for (; ki_it; ++ki_it) - { - Scalar prod = fact * ki_it.value(); - Index j = ki_it.index(); - Index jpos = jr(j); - if (jpos == -1) // fill-in element - { - Index newpos; - if (j >= ii) // dealing with the upper part - { - newpos = ii + sizeu; - sizeu++; - eigen_internal_assert(sizeu<=n); - } - else // dealing with the lower part - { - newpos = sizel; - sizel++; - eigen_internal_assert(sizel<=ii); - } - ju(newpos) = convert_index<StorageIndex>(j); - u(newpos) = -prod; - jr(j) = convert_index<StorageIndex>(newpos); - } - else - u(jpos) -= prod; - } - // store the pivot element - u(len) = fact; - ju(len) = convert_index<StorageIndex>(minrow); - ++len; - - jj++; - } // end of the elimination on the row ii - - // reset the upper part of the pointer jr to zero - for(Index k = 0; k <sizeu; k++) jr(ju(ii+k)) = -1; - - // 4 - partially sort and insert the elements in the m_lu matrix - - // sort the L-part of the row - sizel = len; - len = (std::min)(sizel, nnzL); - typename Vector::SegmentReturnType ul(u.segment(0, sizel)); - typename VectorI::SegmentReturnType jul(ju.segment(0, sizel)); - internal::QuickSplit(ul, jul, len); - - // store the largest m_fill elements of the L part - m_lu.startVec(ii); - for(Index k = 0; k < len; k++) - m_lu.insertBackByOuterInnerUnordered(ii,ju(k)) = u(k); - - // store the diagonal element - // apply a shifting rule to avoid zero pivots (we are doing an incomplete factorization) - if (u(ii) == Scalar(0)) - u(ii) = sqrt(m_droptol) * rownorm; - m_lu.insertBackByOuterInnerUnordered(ii, ii) = u(ii); - - // sort the U-part of the row - // apply the dropping rule first - len = 0; - for(Index k = 1; k < sizeu; k++) - { - if(abs(u(ii+k)) > m_droptol * rownorm ) - { - ++len; - u(ii + len) = u(ii + k); - ju(ii + len) = ju(ii + k); - } - } - sizeu = len + 1; // +1 to take into account the diagonal element - len = (std::min)(sizeu, nnzU); - typename Vector::SegmentReturnType uu(u.segment(ii+1, sizeu-1)); - typename VectorI::SegmentReturnType juu(ju.segment(ii+1, sizeu-1)); - internal::QuickSplit(uu, juu, len); - - // store the largest elements of the U part - for(Index k = ii + 1; k < ii + len; k++) - m_lu.insertBackByOuterInnerUnordered(ii,ju(k)) = u(k); - } - m_lu.finalize(); - m_lu.makeCompressed(); - - m_factorizationIsOk = true; - m_info = Success; -} - -} // end namespace Eigen - -#endif // EIGEN_INCOMPLETE_LUT_H diff --git a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h b/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h deleted file mode 100644 index 13ba9a55..00000000 --- a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h +++ /dev/null @@ -1,444 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ITERATIVE_SOLVER_BASE_H -#define EIGEN_ITERATIVE_SOLVER_BASE_H - -namespace Eigen { - -namespace internal { - -template<typename MatrixType> -struct is_ref_compatible_impl -{ -private: - template <typename T0> - struct any_conversion - { - template <typename T> any_conversion(const volatile T&); - template <typename T> any_conversion(T&); - }; - struct yes {int a[1];}; - struct no {int a[2];}; - - template<typename T> - static yes test(const Ref<const T>&, int); - template<typename T> - static no test(any_conversion<T>, ...); - -public: - static MatrixType ms_from; - enum { value = sizeof(test<MatrixType>(ms_from, 0))==sizeof(yes) }; -}; - -template<typename MatrixType> -struct is_ref_compatible -{ - enum { value = is_ref_compatible_impl<typename remove_all<MatrixType>::type>::value }; -}; - -template<typename MatrixType, bool MatrixFree = !internal::is_ref_compatible<MatrixType>::value> -class generic_matrix_wrapper; - -// We have an explicit matrix at hand, compatible with Ref<> -template<typename MatrixType> -class generic_matrix_wrapper<MatrixType,false> -{ -public: - typedef Ref<const MatrixType> ActualMatrixType; - template<int UpLo> struct ConstSelfAdjointViewReturnType { - typedef typename ActualMatrixType::template ConstSelfAdjointViewReturnType<UpLo>::Type Type; - }; - - enum { - MatrixFree = false - }; - - generic_matrix_wrapper() - : m_dummy(0,0), m_matrix(m_dummy) - {} - - template<typename InputType> - generic_matrix_wrapper(const InputType &mat) - : m_matrix(mat) - {} - - const ActualMatrixType& matrix() const - { - return m_matrix; - } - - template<typename MatrixDerived> - void grab(const EigenBase<MatrixDerived> &mat) - { - m_matrix.~Ref<const MatrixType>(); - ::new (&m_matrix) Ref<const MatrixType>(mat.derived()); - } - - void grab(const Ref<const MatrixType> &mat) - { - if(&(mat.derived()) != &m_matrix) - { - m_matrix.~Ref<const MatrixType>(); - ::new (&m_matrix) Ref<const MatrixType>(mat); - } - } - -protected: - MatrixType m_dummy; // used to default initialize the Ref<> object - ActualMatrixType m_matrix; -}; - -// MatrixType is not compatible with Ref<> -> matrix-free wrapper -template<typename MatrixType> -class generic_matrix_wrapper<MatrixType,true> -{ -public: - typedef MatrixType ActualMatrixType; - template<int UpLo> struct ConstSelfAdjointViewReturnType - { - typedef ActualMatrixType Type; - }; - - enum { - MatrixFree = true - }; - - generic_matrix_wrapper() - : mp_matrix(0) - {} - - generic_matrix_wrapper(const MatrixType &mat) - : mp_matrix(&mat) - {} - - const ActualMatrixType& matrix() const - { - return *mp_matrix; - } - - void grab(const MatrixType &mat) - { - mp_matrix = &mat; - } - -protected: - const ActualMatrixType *mp_matrix; -}; - -} - -/** \ingroup IterativeLinearSolvers_Module - * \brief Base class for linear iterative solvers - * - * \sa class SimplicialCholesky, DiagonalPreconditioner, IdentityPreconditioner - */ -template< typename Derived> -class IterativeSolverBase : public SparseSolverBase<Derived> -{ -protected: - typedef SparseSolverBase<Derived> Base; - using Base::m_isInitialized; - -public: - typedef typename internal::traits<Derived>::MatrixType MatrixType; - typedef typename internal::traits<Derived>::Preconditioner Preconditioner; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef typename MatrixType::RealScalar RealScalar; - - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - -public: - - using Base::derived; - - /** Default constructor. */ - IterativeSolverBase() - { - init(); - } - - /** Initialize the solver with matrix \a A for further \c Ax=b solving. - * - * This constructor is a shortcut for the default constructor followed - * by a call to compute(). - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - explicit IterativeSolverBase(const EigenBase<MatrixDerived>& A) - : m_matrixWrapper(A.derived()) - { - init(); - compute(matrix()); - } - - ~IterativeSolverBase() {} - - /** Initializes the iterative solver for the sparsity pattern of the matrix \a A for further solving \c Ax=b problems. - * - * Currently, this function mostly calls analyzePattern on the preconditioner. In the future - * we might, for instance, implement column reordering for faster matrix vector products. - */ - template<typename MatrixDerived> - Derived& analyzePattern(const EigenBase<MatrixDerived>& A) - { - grab(A.derived()); - m_preconditioner.analyzePattern(matrix()); - m_isInitialized = true; - m_analysisIsOk = true; - m_info = m_preconditioner.info(); - return derived(); - } - - /** Initializes the iterative solver with the numerical values of the matrix \a A for further solving \c Ax=b problems. - * - * Currently, this function mostly calls factorize on the preconditioner. - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - Derived& factorize(const EigenBase<MatrixDerived>& A) - { - eigen_assert(m_analysisIsOk && "You must first call analyzePattern()"); - grab(A.derived()); - m_preconditioner.factorize(matrix()); - m_factorizationIsOk = true; - m_info = m_preconditioner.info(); - return derived(); - } - - /** Initializes the iterative solver with the matrix \a A for further solving \c Ax=b problems. - * - * Currently, this function mostly initializes/computes the preconditioner. In the future - * we might, for instance, implement column reordering for faster matrix vector products. - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - Derived& compute(const EigenBase<MatrixDerived>& A) - { - grab(A.derived()); - m_preconditioner.compute(matrix()); - m_isInitialized = true; - m_analysisIsOk = true; - m_factorizationIsOk = true; - m_info = m_preconditioner.info(); - return derived(); - } - - /** \internal */ - Index rows() const { return matrix().rows(); } - - /** \internal */ - Index cols() const { return matrix().cols(); } - - /** \returns the tolerance threshold used by the stopping criteria. - * \sa setTolerance() - */ - RealScalar tolerance() const { return m_tolerance; } - - /** Sets the tolerance threshold used by the stopping criteria. - * - * This value is used as an upper bound to the relative residual error: |Ax-b|/|b|. - * The default value is the machine precision given by NumTraits<Scalar>::epsilon() - */ - Derived& setTolerance(const RealScalar& tolerance) - { - m_tolerance = tolerance; - return derived(); - } - - /** \returns a read-write reference to the preconditioner for custom configuration. */ - Preconditioner& preconditioner() { return m_preconditioner; } - - /** \returns a read-only reference to the preconditioner. */ - const Preconditioner& preconditioner() const { return m_preconditioner; } - - /** \returns the max number of iterations. - * It is either the value set by setMaxIterations or, by default, - * twice the number of columns of the matrix. - */ - Index maxIterations() const - { - return (m_maxIterations<0) ? 2*matrix().cols() : m_maxIterations; - } - - /** Sets the max number of iterations. - * Default is twice the number of columns of the matrix. - */ - Derived& setMaxIterations(Index maxIters) - { - m_maxIterations = maxIters; - return derived(); - } - - /** \returns the number of iterations performed during the last solve */ - Index iterations() const - { - eigen_assert(m_isInitialized && "ConjugateGradient is not initialized."); - return m_iterations; - } - - /** \returns the tolerance error reached during the last solve. - * It is a close approximation of the true relative residual error |Ax-b|/|b|. - */ - RealScalar error() const - { - eigen_assert(m_isInitialized && "ConjugateGradient is not initialized."); - return m_error; - } - - /** \returns the solution x of \f$ A x = b \f$ using the current decomposition of A - * and \a x0 as an initial solution. - * - * \sa solve(), compute() - */ - template<typename Rhs,typename Guess> - inline const SolveWithGuess<Derived, Rhs, Guess> - solveWithGuess(const MatrixBase<Rhs>& b, const Guess& x0) const - { - eigen_assert(m_isInitialized && "Solver is not initialized."); - eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b"); - return SolveWithGuess<Derived, Rhs, Guess>(derived(), b.derived(), x0); - } - - /** \returns Success if the iterations converged, and NoConvergence otherwise. */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "IterativeSolverBase is not initialized."); - return m_info; - } - - /** \internal */ - template<typename Rhs, typename DestDerived> - void _solve_with_guess_impl(const Rhs& b, SparseMatrixBase<DestDerived> &aDest) const - { - eigen_assert(rows()==b.rows()); - - Index rhsCols = b.cols(); - Index size = b.rows(); - DestDerived& dest(aDest.derived()); - typedef typename DestDerived::Scalar DestScalar; - Eigen::Matrix<DestScalar,Dynamic,1> tb(size); - Eigen::Matrix<DestScalar,Dynamic,1> tx(cols()); - // We do not directly fill dest because sparse expressions have to be free of aliasing issue. - // For non square least-square problems, b and dest might not have the same size whereas they might alias each-other. - typename DestDerived::PlainObject tmp(cols(),rhsCols); - ComputationInfo global_info = Success; - for(Index k=0; k<rhsCols; ++k) - { - tb = b.col(k); - tx = dest.col(k); - derived()._solve_vector_with_guess_impl(tb,tx); - tmp.col(k) = tx.sparseView(0); - - // The call to _solve_vector_with_guess_impl updates m_info, so if it failed for a previous column - // we need to restore it to the worst value. - if(m_info==NumericalIssue) - global_info = NumericalIssue; - else if(m_info==NoConvergence) - global_info = NoConvergence; - } - m_info = global_info; - dest.swap(tmp); - } - - template<typename Rhs, typename DestDerived> - typename internal::enable_if<Rhs::ColsAtCompileTime!=1 && DestDerived::ColsAtCompileTime!=1>::type - _solve_with_guess_impl(const Rhs& b, MatrixBase<DestDerived> &aDest) const - { - eigen_assert(rows()==b.rows()); - - Index rhsCols = b.cols(); - DestDerived& dest(aDest.derived()); - ComputationInfo global_info = Success; - for(Index k=0; k<rhsCols; ++k) - { - typename DestDerived::ColXpr xk(dest,k); - typename Rhs::ConstColXpr bk(b,k); - derived()._solve_vector_with_guess_impl(bk,xk); - - // The call to _solve_vector_with_guess updates m_info, so if it failed for a previous column - // we need to restore it to the worst value. - if(m_info==NumericalIssue) - global_info = NumericalIssue; - else if(m_info==NoConvergence) - global_info = NoConvergence; - } - m_info = global_info; - } - - template<typename Rhs, typename DestDerived> - typename internal::enable_if<Rhs::ColsAtCompileTime==1 || DestDerived::ColsAtCompileTime==1>::type - _solve_with_guess_impl(const Rhs& b, MatrixBase<DestDerived> &dest) const - { - derived()._solve_vector_with_guess_impl(b,dest.derived()); - } - - /** \internal default initial guess = 0 */ - template<typename Rhs,typename Dest> - void _solve_impl(const Rhs& b, Dest& x) const - { - x.setZero(); - derived()._solve_with_guess_impl(b,x); - } - -protected: - void init() - { - m_isInitialized = false; - m_analysisIsOk = false; - m_factorizationIsOk = false; - m_maxIterations = -1; - m_tolerance = NumTraits<Scalar>::epsilon(); - } - - typedef internal::generic_matrix_wrapper<MatrixType> MatrixWrapper; - typedef typename MatrixWrapper::ActualMatrixType ActualMatrixType; - - const ActualMatrixType& matrix() const - { - return m_matrixWrapper.matrix(); - } - - template<typename InputType> - void grab(const InputType &A) - { - m_matrixWrapper.grab(A); - } - - MatrixWrapper m_matrixWrapper; - Preconditioner m_preconditioner; - - Index m_maxIterations; - RealScalar m_tolerance; - - mutable RealScalar m_error; - mutable Index m_iterations; - mutable ComputationInfo m_info; - mutable bool m_analysisIsOk, m_factorizationIsOk; -}; - -} // end namespace Eigen - -#endif // EIGEN_ITERATIVE_SOLVER_BASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h b/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h deleted file mode 100644 index 203fd0ec..00000000 --- a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h +++ /dev/null @@ -1,198 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_LEAST_SQUARE_CONJUGATE_GRADIENT_H -#define EIGEN_LEAST_SQUARE_CONJUGATE_GRADIENT_H - -namespace Eigen { - -namespace internal { - -/** \internal Low-level conjugate gradient algorithm for least-square problems - * \param mat The matrix A - * \param rhs The right hand side vector b - * \param x On input and initial solution, on output the computed solution. - * \param precond A preconditioner being able to efficiently solve for an - * approximation of A'Ax=b (regardless of b) - * \param iters On input the max number of iteration, on output the number of performed iterations. - * \param tol_error On input the tolerance error, on output an estimation of the relative error. - */ -template<typename MatrixType, typename Rhs, typename Dest, typename Preconditioner> -EIGEN_DONT_INLINE -void least_square_conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x, - const Preconditioner& precond, Index& iters, - typename Dest::RealScalar& tol_error) -{ - using std::sqrt; - using std::abs; - typedef typename Dest::RealScalar RealScalar; - typedef typename Dest::Scalar Scalar; - typedef Matrix<Scalar,Dynamic,1> VectorType; - - RealScalar tol = tol_error; - Index maxIters = iters; - - Index m = mat.rows(), n = mat.cols(); - - VectorType residual = rhs - mat * x; - VectorType normal_residual = mat.adjoint() * residual; - - RealScalar rhsNorm2 = (mat.adjoint()*rhs).squaredNorm(); - if(rhsNorm2 == 0) - { - x.setZero(); - iters = 0; - tol_error = 0; - return; - } - RealScalar threshold = tol*tol*rhsNorm2; - RealScalar residualNorm2 = normal_residual.squaredNorm(); - if (residualNorm2 < threshold) - { - iters = 0; - tol_error = sqrt(residualNorm2 / rhsNorm2); - return; - } - - VectorType p(n); - p = precond.solve(normal_residual); // initial search direction - - VectorType z(n), tmp(m); - RealScalar absNew = numext::real(normal_residual.dot(p)); // the square of the absolute value of r scaled by invM - Index i = 0; - while(i < maxIters) - { - tmp.noalias() = mat * p; - - Scalar alpha = absNew / tmp.squaredNorm(); // the amount we travel on dir - x += alpha * p; // update solution - residual -= alpha * tmp; // update residual - normal_residual = mat.adjoint() * residual; // update residual of the normal equation - - residualNorm2 = normal_residual.squaredNorm(); - if(residualNorm2 < threshold) - break; - - z = precond.solve(normal_residual); // approximately solve for "A'A z = normal_residual" - - RealScalar absOld = absNew; - absNew = numext::real(normal_residual.dot(z)); // update the absolute value of r - RealScalar beta = absNew / absOld; // calculate the Gram-Schmidt value used to create the new search direction - p = z + beta * p; // update search direction - i++; - } - tol_error = sqrt(residualNorm2 / rhsNorm2); - iters = i; -} - -} - -template< typename _MatrixType, - typename _Preconditioner = LeastSquareDiagonalPreconditioner<typename _MatrixType::Scalar> > -class LeastSquaresConjugateGradient; - -namespace internal { - -template< typename _MatrixType, typename _Preconditioner> -struct traits<LeastSquaresConjugateGradient<_MatrixType,_Preconditioner> > -{ - typedef _MatrixType MatrixType; - typedef _Preconditioner Preconditioner; -}; - -} - -/** \ingroup IterativeLinearSolvers_Module - * \brief A conjugate gradient solver for sparse (or dense) least-square problems - * - * This class allows to solve for A x = b linear problems using an iterative conjugate gradient algorithm. - * The matrix A can be non symmetric and rectangular, but the matrix A' A should be positive-definite to guaranty stability. - * Otherwise, the SparseLU or SparseQR classes might be preferable. - * The matrix A and the vectors x and b can be either dense or sparse. - * - * \tparam _MatrixType the type of the matrix A, can be a dense or a sparse matrix. - * \tparam _Preconditioner the type of the preconditioner. Default is LeastSquareDiagonalPreconditioner - * - * \implsparsesolverconcept - * - * The maximal number of iterations and tolerance value can be controlled via the setMaxIterations() - * and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations - * and NumTraits<Scalar>::epsilon() for the tolerance. - * - * This class can be used as the direct solver classes. Here is a typical usage example: - \code - int m=1000000, n = 10000; - VectorXd x(n), b(m); - SparseMatrix<double> A(m,n); - // fill A and b - LeastSquaresConjugateGradient<SparseMatrix<double> > lscg; - lscg.compute(A); - x = lscg.solve(b); - std::cout << "#iterations: " << lscg.iterations() << std::endl; - std::cout << "estimated error: " << lscg.error() << std::endl; - // update b, and solve again - x = lscg.solve(b); - \endcode - * - * By default the iterations start with x=0 as an initial guess of the solution. - * One can control the start using the solveWithGuess() method. - * - * \sa class ConjugateGradient, SparseLU, SparseQR - */ -template< typename _MatrixType, typename _Preconditioner> -class LeastSquaresConjugateGradient : public IterativeSolverBase<LeastSquaresConjugateGradient<_MatrixType,_Preconditioner> > -{ - typedef IterativeSolverBase<LeastSquaresConjugateGradient> Base; - using Base::matrix; - using Base::m_error; - using Base::m_iterations; - using Base::m_info; - using Base::m_isInitialized; -public: - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef _Preconditioner Preconditioner; - -public: - - /** Default constructor. */ - LeastSquaresConjugateGradient() : Base() {} - - /** Initialize the solver with matrix \a A for further \c Ax=b solving. - * - * This constructor is a shortcut for the default constructor followed - * by a call to compute(). - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - explicit LeastSquaresConjugateGradient(const EigenBase<MatrixDerived>& A) : Base(A.derived()) {} - - ~LeastSquaresConjugateGradient() {} - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_vector_with_guess_impl(const Rhs& b, Dest& x) const - { - m_iterations = Base::maxIterations(); - m_error = Base::m_tolerance; - - internal::least_square_conjugate_gradient(matrix(), b, x, Base::m_preconditioner, m_iterations, m_error); - m_info = m_error <= Base::m_tolerance ? Success : NoConvergence; - } - -}; - -} // end namespace Eigen - -#endif // EIGEN_LEAST_SQUARE_CONJUGATE_GRADIENT_H diff --git a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h b/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h deleted file mode 100644 index 79e1e481..00000000 --- a/external/eigen/include/eigen3/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h +++ /dev/null @@ -1,115 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SOLVEWITHGUESS_H -#define EIGEN_SOLVEWITHGUESS_H - -namespace Eigen { - -template<typename Decomposition, typename RhsType, typename GuessType> class SolveWithGuess; - -/** \class SolveWithGuess - * \ingroup IterativeLinearSolvers_Module - * - * \brief Pseudo expression representing a solving operation - * - * \tparam Decomposition the type of the matrix or decomposion object - * \tparam Rhstype the type of the right-hand side - * - * This class represents an expression of A.solve(B) - * and most of the time this is the only way it is used. - * - */ -namespace internal { - - -template<typename Decomposition, typename RhsType, typename GuessType> -struct traits<SolveWithGuess<Decomposition, RhsType, GuessType> > - : traits<Solve<Decomposition,RhsType> > -{}; - -} - - -template<typename Decomposition, typename RhsType, typename GuessType> -class SolveWithGuess : public internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type -{ -public: - typedef typename internal::traits<SolveWithGuess>::Scalar Scalar; - typedef typename internal::traits<SolveWithGuess>::PlainObject PlainObject; - typedef typename internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type Base; - typedef typename internal::ref_selector<SolveWithGuess>::type Nested; - - SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess) - : m_dec(dec), m_rhs(rhs), m_guess(guess) - {} - - EIGEN_DEVICE_FUNC Index rows() const { return m_dec.cols(); } - EIGEN_DEVICE_FUNC Index cols() const { return m_rhs.cols(); } - - EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; } - EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; } - EIGEN_DEVICE_FUNC const GuessType& guess() const { return m_guess; } - -protected: - const Decomposition &m_dec; - const RhsType &m_rhs; - const GuessType &m_guess; - -private: - Scalar coeff(Index row, Index col) const; - Scalar coeff(Index i) const; -}; - -namespace internal { - -// Evaluator of SolveWithGuess -> eval into a temporary -template<typename Decomposition, typename RhsType, typename GuessType> -struct evaluator<SolveWithGuess<Decomposition,RhsType, GuessType> > - : public evaluator<typename SolveWithGuess<Decomposition,RhsType,GuessType>::PlainObject> -{ - typedef SolveWithGuess<Decomposition,RhsType,GuessType> SolveType; - typedef typename SolveType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - - evaluator(const SolveType& solve) - : m_result(solve.rows(), solve.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - m_result = solve.guess(); - solve.dec()._solve_with_guess_impl(solve.rhs(), m_result); - } - -protected: - PlainObject m_result; -}; - -// Specialization for "dst = dec.solveWithGuess(rhs)" -// NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere -template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar> -struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar,Scalar>, Dense2Dense> -{ - typedef SolveWithGuess<DecType,RhsType,GuessType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - dst = src.guess(); - src.dec()._solve_with_guess_impl(src.rhs(), dst/*, src.guess()*/); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SOLVEWITHGUESS_H diff --git a/external/eigen/include/eigen3/Eigen/src/Jacobi/Jacobi.h b/external/eigen/include/eigen3/Eigen/src/Jacobi/Jacobi.h deleted file mode 100644 index bfb9dcb0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/Jacobi/Jacobi.h +++ /dev/null @@ -1,483 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_JACOBI_H -#define EIGEN_JACOBI_H - -namespace Eigen { - -/** \ingroup Jacobi_Module - * \jacobi_module - * \class JacobiRotation - * \brief Rotation given by a cosine-sine pair. - * - * This class represents a Jacobi or Givens rotation. - * This is a 2D rotation in the plane \c J of angle \f$ \theta \f$ defined by - * its cosine \c c and sine \c s as follow: - * \f$ J = \left ( \begin{array}{cc} c & \overline s \\ -s & \overline c \end{array} \right ) \f$ - * - * You can apply the respective counter-clockwise rotation to a column vector \c v by - * applying its adjoint on the left: \f$ v = J^* v \f$ that translates to the following Eigen code: - * \code - * v.applyOnTheLeft(J.adjoint()); - * \endcode - * - * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() - */ -template<typename Scalar> class JacobiRotation -{ - public: - typedef typename NumTraits<Scalar>::Real RealScalar; - - /** Default constructor without any initialization. */ - EIGEN_DEVICE_FUNC - JacobiRotation() {} - - /** Construct a planar rotation from a cosine-sine pair (\a c, \c s). */ - EIGEN_DEVICE_FUNC - JacobiRotation(const Scalar& c, const Scalar& s) : m_c(c), m_s(s) {} - - EIGEN_DEVICE_FUNC Scalar& c() { return m_c; } - EIGEN_DEVICE_FUNC Scalar c() const { return m_c; } - EIGEN_DEVICE_FUNC Scalar& s() { return m_s; } - EIGEN_DEVICE_FUNC Scalar s() const { return m_s; } - - /** Concatenates two planar rotation */ - EIGEN_DEVICE_FUNC - JacobiRotation operator*(const JacobiRotation& other) - { - using numext::conj; - return JacobiRotation(m_c * other.m_c - conj(m_s) * other.m_s, - conj(m_c * conj(other.m_s) + conj(m_s) * conj(other.m_c))); - } - - /** Returns the transposed transformation */ - EIGEN_DEVICE_FUNC - JacobiRotation transpose() const { using numext::conj; return JacobiRotation(m_c, -conj(m_s)); } - - /** Returns the adjoint transformation */ - EIGEN_DEVICE_FUNC - JacobiRotation adjoint() const { using numext::conj; return JacobiRotation(conj(m_c), -m_s); } - - template<typename Derived> - EIGEN_DEVICE_FUNC - bool makeJacobi(const MatrixBase<Derived>&, Index p, Index q); - EIGEN_DEVICE_FUNC - bool makeJacobi(const RealScalar& x, const Scalar& y, const RealScalar& z); - - EIGEN_DEVICE_FUNC - void makeGivens(const Scalar& p, const Scalar& q, Scalar* r=0); - - protected: - EIGEN_DEVICE_FUNC - void makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::true_type); - EIGEN_DEVICE_FUNC - void makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::false_type); - - Scalar m_c, m_s; -}; - -/** Makes \c *this as a Jacobi rotation \a J such that applying \a J on both the right and left sides of the selfadjoint 2x2 matrix - * \f$ B = \left ( \begin{array}{cc} x & y \\ \overline y & z \end{array} \right )\f$ yields a diagonal matrix \f$ A = J^* B J \f$ - * - * \sa MatrixBase::makeJacobi(const MatrixBase<Derived>&, Index, Index), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() - */ -template<typename Scalar> -EIGEN_DEVICE_FUNC -bool JacobiRotation<Scalar>::makeJacobi(const RealScalar& x, const Scalar& y, const RealScalar& z) -{ - using std::sqrt; - using std::abs; - - RealScalar deno = RealScalar(2)*abs(y); - if(deno < (std::numeric_limits<RealScalar>::min)()) - { - m_c = Scalar(1); - m_s = Scalar(0); - return false; - } - else - { - RealScalar tau = (x-z)/deno; - RealScalar w = sqrt(numext::abs2(tau) + RealScalar(1)); - RealScalar t; - if(tau>RealScalar(0)) - { - t = RealScalar(1) / (tau + w); - } - else - { - t = RealScalar(1) / (tau - w); - } - RealScalar sign_t = t > RealScalar(0) ? RealScalar(1) : RealScalar(-1); - RealScalar n = RealScalar(1) / sqrt(numext::abs2(t)+RealScalar(1)); - m_s = - sign_t * (numext::conj(y) / abs(y)) * abs(t) * n; - m_c = n; - return true; - } -} - -/** Makes \c *this as a Jacobi rotation \c J such that applying \a J on both the right and left sides of the 2x2 selfadjoint matrix - * \f$ B = \left ( \begin{array}{cc} \text{this}_{pp} & \text{this}_{pq} \\ (\text{this}_{pq})^* & \text{this}_{qq} \end{array} \right )\f$ yields - * a diagonal matrix \f$ A = J^* B J \f$ - * - * Example: \include Jacobi_makeJacobi.cpp - * Output: \verbinclude Jacobi_makeJacobi.out - * - * \sa JacobiRotation::makeJacobi(RealScalar, Scalar, RealScalar), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() - */ -template<typename Scalar> -template<typename Derived> -EIGEN_DEVICE_FUNC -inline bool JacobiRotation<Scalar>::makeJacobi(const MatrixBase<Derived>& m, Index p, Index q) -{ - return makeJacobi(numext::real(m.coeff(p,p)), m.coeff(p,q), numext::real(m.coeff(q,q))); -} - -/** Makes \c *this as a Givens rotation \c G such that applying \f$ G^* \f$ to the left of the vector - * \f$ V = \left ( \begin{array}{c} p \\ q \end{array} \right )\f$ yields: - * \f$ G^* V = \left ( \begin{array}{c} r \\ 0 \end{array} \right )\f$. - * - * The value of \a r is returned if \a r is not null (the default is null). - * Also note that G is built such that the cosine is always real. - * - * Example: \include Jacobi_makeGivens.cpp - * Output: \verbinclude Jacobi_makeGivens.out - * - * This function implements the continuous Givens rotation generation algorithm - * found in Anderson (2000), Discontinuous Plane Rotations and the Symmetric Eigenvalue Problem. - * LAPACK Working Note 150, University of Tennessee, UT-CS-00-454, December 4, 2000. - * - * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() - */ -template<typename Scalar> -EIGEN_DEVICE_FUNC -void JacobiRotation<Scalar>::makeGivens(const Scalar& p, const Scalar& q, Scalar* r) -{ - makeGivens(p, q, r, typename internal::conditional<NumTraits<Scalar>::IsComplex, internal::true_type, internal::false_type>::type()); -} - - -// specialization for complexes -template<typename Scalar> -EIGEN_DEVICE_FUNC -void JacobiRotation<Scalar>::makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::true_type) -{ - using std::sqrt; - using std::abs; - using numext::conj; - - if(q==Scalar(0)) - { - m_c = numext::real(p)<0 ? Scalar(-1) : Scalar(1); - m_s = 0; - if(r) *r = m_c * p; - } - else if(p==Scalar(0)) - { - m_c = 0; - m_s = -q/abs(q); - if(r) *r = abs(q); - } - else - { - RealScalar p1 = numext::norm1(p); - RealScalar q1 = numext::norm1(q); - if(p1>=q1) - { - Scalar ps = p / p1; - RealScalar p2 = numext::abs2(ps); - Scalar qs = q / p1; - RealScalar q2 = numext::abs2(qs); - - RealScalar u = sqrt(RealScalar(1) + q2/p2); - if(numext::real(p)<RealScalar(0)) - u = -u; - - m_c = Scalar(1)/u; - m_s = -qs*conj(ps)*(m_c/p2); - if(r) *r = p * u; - } - else - { - Scalar ps = p / q1; - RealScalar p2 = numext::abs2(ps); - Scalar qs = q / q1; - RealScalar q2 = numext::abs2(qs); - - RealScalar u = q1 * sqrt(p2 + q2); - if(numext::real(p)<RealScalar(0)) - u = -u; - - p1 = abs(p); - ps = p/p1; - m_c = p1/u; - m_s = -conj(ps) * (q/u); - if(r) *r = ps * u; - } - } -} - -// specialization for reals -template<typename Scalar> -EIGEN_DEVICE_FUNC -void JacobiRotation<Scalar>::makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::false_type) -{ - using std::sqrt; - using std::abs; - if(q==Scalar(0)) - { - m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1); - m_s = Scalar(0); - if(r) *r = abs(p); - } - else if(p==Scalar(0)) - { - m_c = Scalar(0); - m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1); - if(r) *r = abs(q); - } - else if(abs(p) > abs(q)) - { - Scalar t = q/p; - Scalar u = sqrt(Scalar(1) + numext::abs2(t)); - if(p<Scalar(0)) - u = -u; - m_c = Scalar(1)/u; - m_s = -t * m_c; - if(r) *r = p * u; - } - else - { - Scalar t = p/q; - Scalar u = sqrt(Scalar(1) + numext::abs2(t)); - if(q<Scalar(0)) - u = -u; - m_s = -Scalar(1)/u; - m_c = -t * m_s; - if(r) *r = q * u; - } - -} - -/**************************************************************************************** -* Implementation of MatrixBase methods -****************************************************************************************/ - -namespace internal { -/** \jacobi_module - * Applies the clock wise 2D rotation \a j to the set of 2D vectors of coordinates \a x and \a y: - * \f$ \left ( \begin{array}{cc} x \\ y \end{array} \right ) = J \left ( \begin{array}{cc} x \\ y \end{array} \right ) \f$ - * - * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight() - */ -template<typename VectorX, typename VectorY, typename OtherScalar> -EIGEN_DEVICE_FUNC -void apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y, const JacobiRotation<OtherScalar>& j); -} - -/** \jacobi_module - * Applies the rotation in the plane \a j to the rows \a p and \a q of \c *this, i.e., it computes B = J * B, - * with \f$ B = \left ( \begin{array}{cc} \text{*this.row}(p) \\ \text{*this.row}(q) \end{array} \right ) \f$. - * - * \sa class JacobiRotation, MatrixBase::applyOnTheRight(), internal::apply_rotation_in_the_plane() - */ -template<typename Derived> -template<typename OtherScalar> -EIGEN_DEVICE_FUNC -inline void MatrixBase<Derived>::applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j) -{ - RowXpr x(this->row(p)); - RowXpr y(this->row(q)); - internal::apply_rotation_in_the_plane(x, y, j); -} - -/** \ingroup Jacobi_Module - * Applies the rotation in the plane \a j to the columns \a p and \a q of \c *this, i.e., it computes B = B * J - * with \f$ B = \left ( \begin{array}{cc} \text{*this.col}(p) & \text{*this.col}(q) \end{array} \right ) \f$. - * - * \sa class JacobiRotation, MatrixBase::applyOnTheLeft(), internal::apply_rotation_in_the_plane() - */ -template<typename Derived> -template<typename OtherScalar> -EIGEN_DEVICE_FUNC -inline void MatrixBase<Derived>::applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j) -{ - ColXpr x(this->col(p)); - ColXpr y(this->col(q)); - internal::apply_rotation_in_the_plane(x, y, j.transpose()); -} - -namespace internal { - -template<typename Scalar, typename OtherScalar, - int SizeAtCompileTime, int MinAlignment, bool Vectorizable> -struct apply_rotation_in_the_plane_selector -{ - static EIGEN_DEVICE_FUNC - inline void run(Scalar *x, Index incrx, Scalar *y, Index incry, Index size, OtherScalar c, OtherScalar s) - { - for(Index i=0; i<size; ++i) - { - Scalar xi = *x; - Scalar yi = *y; - *x = c * xi + numext::conj(s) * yi; - *y = -s * xi + numext::conj(c) * yi; - x += incrx; - y += incry; - } - } -}; - -template<typename Scalar, typename OtherScalar, - int SizeAtCompileTime, int MinAlignment> -struct apply_rotation_in_the_plane_selector<Scalar,OtherScalar,SizeAtCompileTime,MinAlignment,true /* vectorizable */> -{ - static inline void run(Scalar *x, Index incrx, Scalar *y, Index incry, Index size, OtherScalar c, OtherScalar s) - { - enum { - PacketSize = packet_traits<Scalar>::size, - OtherPacketSize = packet_traits<OtherScalar>::size - }; - typedef typename packet_traits<Scalar>::type Packet; - typedef typename packet_traits<OtherScalar>::type OtherPacket; - - /*** dynamic-size vectorized paths ***/ - if(SizeAtCompileTime == Dynamic && ((incrx==1 && incry==1) || PacketSize == 1)) - { - // both vectors are sequentially stored in memory => vectorization - enum { Peeling = 2 }; - - Index alignedStart = internal::first_default_aligned(y, size); - Index alignedEnd = alignedStart + ((size-alignedStart)/PacketSize)*PacketSize; - - const OtherPacket pc = pset1<OtherPacket>(c); - const OtherPacket ps = pset1<OtherPacket>(s); - conj_helper<OtherPacket,Packet,NumTraits<OtherScalar>::IsComplex,false> pcj; - conj_helper<OtherPacket,Packet,false,false> pm; - - for(Index i=0; i<alignedStart; ++i) - { - Scalar xi = x[i]; - Scalar yi = y[i]; - x[i] = c * xi + numext::conj(s) * yi; - y[i] = -s * xi + numext::conj(c) * yi; - } - - Scalar* EIGEN_RESTRICT px = x + alignedStart; - Scalar* EIGEN_RESTRICT py = y + alignedStart; - - if(internal::first_default_aligned(x, size)==alignedStart) - { - for(Index i=alignedStart; i<alignedEnd; i+=PacketSize) - { - Packet xi = pload<Packet>(px); - Packet yi = pload<Packet>(py); - pstore(px, padd(pm.pmul(pc,xi),pcj.pmul(ps,yi))); - pstore(py, psub(pcj.pmul(pc,yi),pm.pmul(ps,xi))); - px += PacketSize; - py += PacketSize; - } - } - else - { - Index peelingEnd = alignedStart + ((size-alignedStart)/(Peeling*PacketSize))*(Peeling*PacketSize); - for(Index i=alignedStart; i<peelingEnd; i+=Peeling*PacketSize) - { - Packet xi = ploadu<Packet>(px); - Packet xi1 = ploadu<Packet>(px+PacketSize); - Packet yi = pload <Packet>(py); - Packet yi1 = pload <Packet>(py+PacketSize); - pstoreu(px, padd(pm.pmul(pc,xi),pcj.pmul(ps,yi))); - pstoreu(px+PacketSize, padd(pm.pmul(pc,xi1),pcj.pmul(ps,yi1))); - pstore (py, psub(pcj.pmul(pc,yi),pm.pmul(ps,xi))); - pstore (py+PacketSize, psub(pcj.pmul(pc,yi1),pm.pmul(ps,xi1))); - px += Peeling*PacketSize; - py += Peeling*PacketSize; - } - if(alignedEnd!=peelingEnd) - { - Packet xi = ploadu<Packet>(x+peelingEnd); - Packet yi = pload <Packet>(y+peelingEnd); - pstoreu(x+peelingEnd, padd(pm.pmul(pc,xi),pcj.pmul(ps,yi))); - pstore (y+peelingEnd, psub(pcj.pmul(pc,yi),pm.pmul(ps,xi))); - } - } - - for(Index i=alignedEnd; i<size; ++i) - { - Scalar xi = x[i]; - Scalar yi = y[i]; - x[i] = c * xi + numext::conj(s) * yi; - y[i] = -s * xi + numext::conj(c) * yi; - } - } - - /*** fixed-size vectorized path ***/ - else if(SizeAtCompileTime != Dynamic && MinAlignment>0) // FIXME should be compared to the required alignment - { - const OtherPacket pc = pset1<OtherPacket>(c); - const OtherPacket ps = pset1<OtherPacket>(s); - conj_helper<OtherPacket,Packet,NumTraits<OtherPacket>::IsComplex,false> pcj; - conj_helper<OtherPacket,Packet,false,false> pm; - Scalar* EIGEN_RESTRICT px = x; - Scalar* EIGEN_RESTRICT py = y; - for(Index i=0; i<size; i+=PacketSize) - { - Packet xi = pload<Packet>(px); - Packet yi = pload<Packet>(py); - pstore(px, padd(pm.pmul(pc,xi),pcj.pmul(ps,yi))); - pstore(py, psub(pcj.pmul(pc,yi),pm.pmul(ps,xi))); - px += PacketSize; - py += PacketSize; - } - } - - /*** non-vectorized path ***/ - else - { - apply_rotation_in_the_plane_selector<Scalar,OtherScalar,SizeAtCompileTime,MinAlignment,false>::run(x,incrx,y,incry,size,c,s); - } - } -}; - -template<typename VectorX, typename VectorY, typename OtherScalar> -EIGEN_DEVICE_FUNC -void /*EIGEN_DONT_INLINE*/ apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y, const JacobiRotation<OtherScalar>& j) -{ - typedef typename VectorX::Scalar Scalar; - const bool Vectorizable = (VectorX::Flags & VectorY::Flags & PacketAccessBit) - && (int(packet_traits<Scalar>::size) == int(packet_traits<OtherScalar>::size)); - - eigen_assert(xpr_x.size() == xpr_y.size()); - Index size = xpr_x.size(); - Index incrx = xpr_x.derived().innerStride(); - Index incry = xpr_y.derived().innerStride(); - - Scalar* EIGEN_RESTRICT x = &xpr_x.derived().coeffRef(0); - Scalar* EIGEN_RESTRICT y = &xpr_y.derived().coeffRef(0); - - OtherScalar c = j.c(); - OtherScalar s = j.s(); - if (c==OtherScalar(1) && s==OtherScalar(0)) - return; - - apply_rotation_in_the_plane_selector< - Scalar,OtherScalar, - VectorX::SizeAtCompileTime, - EIGEN_PLAIN_ENUM_MIN(evaluator<VectorX>::Alignment, evaluator<VectorY>::Alignment), - Vectorizable>::run(x,incrx,y,incry,size,c,s); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_JACOBI_H diff --git a/external/eigen/include/eigen3/Eigen/src/KLUSupport/KLUSupport.h b/external/eigen/include/eigen3/Eigen/src/KLUSupport/KLUSupport.h deleted file mode 100644 index d2633a93..00000000 --- a/external/eigen/include/eigen3/Eigen/src/KLUSupport/KLUSupport.h +++ /dev/null @@ -1,358 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Kyle Macfarlan <kyle.macfarlan@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_KLUSUPPORT_H -#define EIGEN_KLUSUPPORT_H - -namespace Eigen { - -/* TODO extract L, extract U, compute det, etc... */ - -/** \ingroup KLUSupport_Module - * \brief A sparse LU factorization and solver based on KLU - * - * This class allows to solve for A.X = B sparse linear problems via a LU factorization - * using the KLU library. The sparse matrix A must be squared and full rank. - * The vectors or matrices X and B can be either dense or sparse. - * - * \warning The input matrix A should be in a \b compressed and \b column-major form. - * Otherwise an expensive copy will be made. You can call the inexpensive makeCompressed() to get a compressed matrix. - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class UmfPackLU, class SparseLU - */ - - -inline int klu_solve(klu_symbolic *Symbolic, klu_numeric *Numeric, Index ldim, Index nrhs, double B [ ], klu_common *Common, double) { - return klu_solve(Symbolic, Numeric, internal::convert_index<int>(ldim), internal::convert_index<int>(nrhs), B, Common); -} - -inline int klu_solve(klu_symbolic *Symbolic, klu_numeric *Numeric, Index ldim, Index nrhs, std::complex<double>B[], klu_common *Common, std::complex<double>) { - return klu_z_solve(Symbolic, Numeric, internal::convert_index<int>(ldim), internal::convert_index<int>(nrhs), &numext::real_ref(B[0]), Common); -} - -inline int klu_tsolve(klu_symbolic *Symbolic, klu_numeric *Numeric, Index ldim, Index nrhs, double B[], klu_common *Common, double) { - return klu_tsolve(Symbolic, Numeric, internal::convert_index<int>(ldim), internal::convert_index<int>(nrhs), B, Common); -} - -inline int klu_tsolve(klu_symbolic *Symbolic, klu_numeric *Numeric, Index ldim, Index nrhs, std::complex<double>B[], klu_common *Common, std::complex<double>) { - return klu_z_tsolve(Symbolic, Numeric, internal::convert_index<int>(ldim), internal::convert_index<int>(nrhs), &numext::real_ref(B[0]), 0, Common); -} - -inline klu_numeric* klu_factor(int Ap [ ], int Ai [ ], double Ax [ ], klu_symbolic *Symbolic, klu_common *Common, double) { - return klu_factor(Ap, Ai, Ax, Symbolic, Common); -} - -inline klu_numeric* klu_factor(int Ap[], int Ai[], std::complex<double> Ax[], klu_symbolic *Symbolic, klu_common *Common, std::complex<double>) { - return klu_z_factor(Ap, Ai, &numext::real_ref(Ax[0]), Symbolic, Common); -} - - -template<typename _MatrixType> -class KLU : public SparseSolverBase<KLU<_MatrixType> > -{ - protected: - typedef SparseSolverBase<KLU<_MatrixType> > Base; - using Base::m_isInitialized; - public: - using Base::_solve_impl; - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef Matrix<Scalar,Dynamic,1> Vector; - typedef Matrix<int, 1, MatrixType::ColsAtCompileTime> IntRowVectorType; - typedef Matrix<int, MatrixType::RowsAtCompileTime, 1> IntColVectorType; - typedef SparseMatrix<Scalar> LUMatrixType; - typedef SparseMatrix<Scalar,ColMajor,int> KLUMatrixType; - typedef Ref<const KLUMatrixType, StandardCompressedFormat> KLUMatrixRef; - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - public: - - KLU() - : m_dummy(0,0), mp_matrix(m_dummy) - { - init(); - } - - template<typename InputMatrixType> - explicit KLU(const InputMatrixType& matrix) - : mp_matrix(matrix) - { - init(); - compute(matrix); - } - - ~KLU() - { - if(m_symbolic) klu_free_symbolic(&m_symbolic,&m_common); - if(m_numeric) klu_free_numeric(&m_numeric,&m_common); - } - - inline Index rows() const { return mp_matrix.rows(); } - inline Index cols() const { return mp_matrix.cols(); } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix.appears to be negative. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } -#if 0 // not implemented yet - inline const LUMatrixType& matrixL() const - { - if (m_extractedDataAreDirty) extractData(); - return m_l; - } - - inline const LUMatrixType& matrixU() const - { - if (m_extractedDataAreDirty) extractData(); - return m_u; - } - - inline const IntColVectorType& permutationP() const - { - if (m_extractedDataAreDirty) extractData(); - return m_p; - } - - inline const IntRowVectorType& permutationQ() const - { - if (m_extractedDataAreDirty) extractData(); - return m_q; - } -#endif - /** Computes the sparse Cholesky decomposition of \a matrix - * Note that the matrix should be column-major, and in compressed format for best performance. - * \sa SparseMatrix::makeCompressed(). - */ - template<typename InputMatrixType> - void compute(const InputMatrixType& matrix) - { - if(m_symbolic) klu_free_symbolic(&m_symbolic, &m_common); - if(m_numeric) klu_free_numeric(&m_numeric, &m_common); - grab(matrix.derived()); - analyzePattern_impl(); - factorize_impl(); - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize(), compute() - */ - template<typename InputMatrixType> - void analyzePattern(const InputMatrixType& matrix) - { - if(m_symbolic) klu_free_symbolic(&m_symbolic, &m_common); - if(m_numeric) klu_free_numeric(&m_numeric, &m_common); - - grab(matrix.derived()); - - analyzePattern_impl(); - } - - - /** Provides access to the control settings array used by KLU. - * - * See KLU documentation for details. - */ - inline const klu_common& kluCommon() const - { - return m_common; - } - - /** Provides access to the control settings array used by UmfPack. - * - * If this array contains NaN's, the default values are used. - * - * See KLU documentation for details. - */ - inline klu_common& kluCommon() - { - return m_common; - } - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must has the same sparcity than the matrix on which the pattern anylysis has been performed. - * - * \sa analyzePattern(), compute() - */ - template<typename InputMatrixType> - void factorize(const InputMatrixType& matrix) - { - eigen_assert(m_analysisIsOk && "KLU: you must first call analyzePattern()"); - if(m_numeric) - klu_free_numeric(&m_numeric,&m_common); - - grab(matrix.derived()); - - factorize_impl(); - } - - /** \internal */ - template<typename BDerived,typename XDerived> - bool _solve_impl(const MatrixBase<BDerived> &b, MatrixBase<XDerived> &x) const; - -#if 0 // not implemented yet - Scalar determinant() const; - - void extractData() const; -#endif - - protected: - - void init() - { - m_info = InvalidInput; - m_isInitialized = false; - m_numeric = 0; - m_symbolic = 0; - m_extractedDataAreDirty = true; - - klu_defaults(&m_common); - } - - void analyzePattern_impl() - { - m_info = InvalidInput; - m_analysisIsOk = false; - m_factorizationIsOk = false; - m_symbolic = klu_analyze(internal::convert_index<int>(mp_matrix.rows()), - const_cast<StorageIndex*>(mp_matrix.outerIndexPtr()), const_cast<StorageIndex*>(mp_matrix.innerIndexPtr()), - &m_common); - if (m_symbolic) { - m_isInitialized = true; - m_info = Success; - m_analysisIsOk = true; - m_extractedDataAreDirty = true; - } - } - - void factorize_impl() - { - - m_numeric = klu_factor(const_cast<StorageIndex*>(mp_matrix.outerIndexPtr()), const_cast<StorageIndex*>(mp_matrix.innerIndexPtr()), const_cast<Scalar*>(mp_matrix.valuePtr()), - m_symbolic, &m_common, Scalar()); - - - m_info = m_numeric ? Success : NumericalIssue; - m_factorizationIsOk = m_numeric ? 1 : 0; - m_extractedDataAreDirty = true; - } - - template<typename MatrixDerived> - void grab(const EigenBase<MatrixDerived> &A) - { - mp_matrix.~KLUMatrixRef(); - ::new (&mp_matrix) KLUMatrixRef(A.derived()); - } - - void grab(const KLUMatrixRef &A) - { - if(&(A.derived()) != &mp_matrix) - { - mp_matrix.~KLUMatrixRef(); - ::new (&mp_matrix) KLUMatrixRef(A); - } - } - - // cached data to reduce reallocation, etc. -#if 0 // not implemented yet - mutable LUMatrixType m_l; - mutable LUMatrixType m_u; - mutable IntColVectorType m_p; - mutable IntRowVectorType m_q; -#endif - - KLUMatrixType m_dummy; - KLUMatrixRef mp_matrix; - - klu_numeric* m_numeric; - klu_symbolic* m_symbolic; - klu_common m_common; - mutable ComputationInfo m_info; - int m_factorizationIsOk; - int m_analysisIsOk; - mutable bool m_extractedDataAreDirty; - - private: - KLU(const KLU& ) { } -}; - -#if 0 // not implemented yet -template<typename MatrixType> -void KLU<MatrixType>::extractData() const -{ - if (m_extractedDataAreDirty) - { - eigen_assert(false && "KLU: extractData Not Yet Implemented"); - - // get size of the data - int lnz, unz, rows, cols, nz_udiag; - umfpack_get_lunz(&lnz, &unz, &rows, &cols, &nz_udiag, m_numeric, Scalar()); - - // allocate data - m_l.resize(rows,(std::min)(rows,cols)); - m_l.resizeNonZeros(lnz); - - m_u.resize((std::min)(rows,cols),cols); - m_u.resizeNonZeros(unz); - - m_p.resize(rows); - m_q.resize(cols); - - // extract - umfpack_get_numeric(m_l.outerIndexPtr(), m_l.innerIndexPtr(), m_l.valuePtr(), - m_u.outerIndexPtr(), m_u.innerIndexPtr(), m_u.valuePtr(), - m_p.data(), m_q.data(), 0, 0, 0, m_numeric); - - m_extractedDataAreDirty = false; - } -} - -template<typename MatrixType> -typename KLU<MatrixType>::Scalar KLU<MatrixType>::determinant() const -{ - eigen_assert(false && "KLU: extractData Not Yet Implemented"); - return Scalar(); -} -#endif - -template<typename MatrixType> -template<typename BDerived,typename XDerived> -bool KLU<MatrixType>::_solve_impl(const MatrixBase<BDerived> &b, MatrixBase<XDerived> &x) const -{ - Index rhsCols = b.cols(); - EIGEN_STATIC_ASSERT((XDerived::Flags&RowMajorBit)==0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or analyzePattern()/factorize()"); - - x = b; - int info = klu_solve(m_symbolic, m_numeric, b.rows(), rhsCols, x.const_cast_derived().data(), const_cast<klu_common*>(&m_common), Scalar()); - - m_info = info!=0 ? Success : NumericalIssue; - return true; -} - -} // end namespace Eigen - -#endif // EIGEN_KLUSUPPORT_H diff --git a/external/eigen/include/eigen3/Eigen/src/LU/Determinant.h b/external/eigen/include/eigen3/Eigen/src/LU/Determinant.h deleted file mode 100644 index 3a41e6fc..00000000 --- a/external/eigen/include/eigen3/Eigen/src/LU/Determinant.h +++ /dev/null @@ -1,117 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DETERMINANT_H -#define EIGEN_DETERMINANT_H - -namespace Eigen { - -namespace internal { - -template<typename Derived> -EIGEN_DEVICE_FUNC -inline const typename Derived::Scalar bruteforce_det3_helper -(const MatrixBase<Derived>& matrix, int a, int b, int c) -{ - return matrix.coeff(0,a) - * (matrix.coeff(1,b) * matrix.coeff(2,c) - matrix.coeff(1,c) * matrix.coeff(2,b)); -} - -template<typename Derived, - int DeterminantType = Derived::RowsAtCompileTime -> struct determinant_impl -{ - static inline typename traits<Derived>::Scalar run(const Derived& m) - { - if(Derived::ColsAtCompileTime==Dynamic && m.rows()==0) - return typename traits<Derived>::Scalar(1); - return m.partialPivLu().determinant(); - } -}; - -template<typename Derived> struct determinant_impl<Derived, 1> -{ - static inline EIGEN_DEVICE_FUNC - typename traits<Derived>::Scalar run(const Derived& m) - { - return m.coeff(0,0); - } -}; - -template<typename Derived> struct determinant_impl<Derived, 2> -{ - static inline EIGEN_DEVICE_FUNC - typename traits<Derived>::Scalar run(const Derived& m) - { - return m.coeff(0,0) * m.coeff(1,1) - m.coeff(1,0) * m.coeff(0,1); - } -}; - -template<typename Derived> struct determinant_impl<Derived, 3> -{ - static inline EIGEN_DEVICE_FUNC - typename traits<Derived>::Scalar run(const Derived& m) - { - return bruteforce_det3_helper(m,0,1,2) - - bruteforce_det3_helper(m,1,0,2) - + bruteforce_det3_helper(m,2,0,1); - } -}; - -template<typename Derived> struct determinant_impl<Derived, 4> -{ - typedef typename traits<Derived>::Scalar Scalar; - static EIGEN_DEVICE_FUNC - Scalar run(const Derived& m) - { - Scalar d2_01 = det2(m, 0, 1); - Scalar d2_02 = det2(m, 0, 2); - Scalar d2_03 = det2(m, 0, 3); - Scalar d2_12 = det2(m, 1, 2); - Scalar d2_13 = det2(m, 1, 3); - Scalar d2_23 = det2(m, 2, 3); - Scalar d3_0 = det3(m, 1,d2_23, 2,d2_13, 3,d2_12); - Scalar d3_1 = det3(m, 0,d2_23, 2,d2_03, 3,d2_02); - Scalar d3_2 = det3(m, 0,d2_13, 1,d2_03, 3,d2_01); - Scalar d3_3 = det3(m, 0,d2_12, 1,d2_02, 2,d2_01); - return internal::pmadd(-m(0,3),d3_0, m(1,3)*d3_1) + - internal::pmadd(-m(2,3),d3_2, m(3,3)*d3_3); - } -protected: - static EIGEN_DEVICE_FUNC - Scalar det2(const Derived& m, Index i0, Index i1) - { - return m(i0,0) * m(i1,1) - m(i1,0) * m(i0,1); - } - - static EIGEN_DEVICE_FUNC - Scalar det3(const Derived& m, Index i0, const Scalar& d0, Index i1, const Scalar& d1, Index i2, const Scalar& d2) - { - return internal::pmadd(m(i0,2), d0, internal::pmadd(-m(i1,2), d1, m(i2,2)*d2)); - } -}; - -} // end namespace internal - -/** \lu_module - * - * \returns the determinant of this matrix - */ -template<typename Derived> -EIGEN_DEVICE_FUNC -inline typename internal::traits<Derived>::Scalar MatrixBase<Derived>::determinant() const -{ - eigen_assert(rows() == cols()); - typedef typename internal::nested_eval<Derived,Base::RowsAtCompileTime>::type Nested; - return internal::determinant_impl<typename internal::remove_all<Nested>::type>::run(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_DETERMINANT_H diff --git a/external/eigen/include/eigen3/Eigen/src/LU/FullPivLU.h b/external/eigen/include/eigen3/Eigen/src/LU/FullPivLU.h deleted file mode 100644 index ef93ec5e..00000000 --- a/external/eigen/include/eigen3/Eigen/src/LU/FullPivLU.h +++ /dev/null @@ -1,875 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_LU_H -#define EIGEN_LU_H - -namespace Eigen { - -namespace internal { -template<typename _MatrixType> struct traits<FullPivLU<_MatrixType> > - : traits<_MatrixType> -{ - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - enum { Flags = 0 }; -}; - -} // end namespace internal - -/** \ingroup LU_Module - * - * \class FullPivLU - * - * \brief LU decomposition of a matrix with complete pivoting, and related features - * - * \tparam _MatrixType the type of the matrix of which we are computing the LU decomposition - * - * This class represents a LU decomposition of any matrix, with complete pivoting: the matrix A is - * decomposed as \f$ A = P^{-1} L U Q^{-1} \f$ where L is unit-lower-triangular, U is - * upper-triangular, and P and Q are permutation matrices. This is a rank-revealing LU - * decomposition. The eigenvalues (diagonal coefficients) of U are sorted in such a way that any - * zeros are at the end. - * - * This decomposition provides the generic approach to solving systems of linear equations, computing - * the rank, invertibility, inverse, kernel, and determinant. - * - * This LU decomposition is very stable and well tested with large matrices. However there are use cases where the SVD - * decomposition is inherently more stable and/or flexible. For example, when computing the kernel of a matrix, - * working with the SVD allows to select the smallest singular values of the matrix, something that - * the LU decomposition doesn't see. - * - * The data of the LU decomposition can be directly accessed through the methods matrixLU(), - * permutationP(), permutationQ(). - * - * As an example, here is how the original matrix can be retrieved: - * \include class_FullPivLU.cpp - * Output: \verbinclude class_FullPivLU.out - * - * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. - * - * \sa MatrixBase::fullPivLu(), MatrixBase::determinant(), MatrixBase::inverse() - */ -template<typename _MatrixType> class FullPivLU - : public SolverBase<FullPivLU<_MatrixType> > -{ - public: - typedef _MatrixType MatrixType; - typedef SolverBase<FullPivLU> Base; - friend class SolverBase<FullPivLU>; - - EIGEN_GENERIC_PUBLIC_INTERFACE(FullPivLU) - enum { - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - typedef typename internal::plain_row_type<MatrixType, StorageIndex>::type IntRowVectorType; - typedef typename internal::plain_col_type<MatrixType, StorageIndex>::type IntColVectorType; - typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationQType; - typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationPType; - typedef typename MatrixType::PlainObject PlainObject; - - /** - * \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via LU::compute(const MatrixType&). - */ - FullPivLU(); - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa FullPivLU() - */ - FullPivLU(Index rows, Index cols); - - /** Constructor. - * - * \param matrix the matrix of which to compute the LU decomposition. - * It is required to be nonzero. - */ - template<typename InputType> - explicit FullPivLU(const EigenBase<InputType>& matrix); - - /** \brief Constructs a LU factorization from a given matrix - * - * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref. - * - * \sa FullPivLU(const EigenBase&) - */ - template<typename InputType> - explicit FullPivLU(EigenBase<InputType>& matrix); - - /** Computes the LU decomposition of the given matrix. - * - * \param matrix the matrix of which to compute the LU decomposition. - * It is required to be nonzero. - * - * \returns a reference to *this - */ - template<typename InputType> - FullPivLU& compute(const EigenBase<InputType>& matrix) { - m_lu = matrix.derived(); - computeInPlace(); - return *this; - } - - /** \returns the LU decomposition matrix: the upper-triangular part is U, the - * unit-lower-triangular part is L (at least for square matrices; in the non-square - * case, special care is needed, see the documentation of class FullPivLU). - * - * \sa matrixL(), matrixU() - */ - inline const MatrixType& matrixLU() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return m_lu; - } - - /** \returns the number of nonzero pivots in the LU decomposition. - * Here nonzero is meant in the exact sense, not in a fuzzy sense. - * So that notion isn't really intrinsically interesting, but it is - * still useful when implementing algorithms. - * - * \sa rank() - */ - inline Index nonzeroPivots() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return m_nonzero_pivots; - } - - /** \returns the absolute value of the biggest pivot, i.e. the biggest - * diagonal coefficient of U. - */ - RealScalar maxPivot() const { return m_maxpivot; } - - /** \returns the permutation matrix P - * - * \sa permutationQ() - */ - EIGEN_DEVICE_FUNC inline const PermutationPType& permutationP() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return m_p; - } - - /** \returns the permutation matrix Q - * - * \sa permutationP() - */ - inline const PermutationQType& permutationQ() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return m_q; - } - - /** \returns the kernel of the matrix, also called its null-space. The columns of the returned matrix - * will form a basis of the kernel. - * - * \note If the kernel has dimension zero, then the returned matrix is a column-vector filled with zeros. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - * - * Example: \include FullPivLU_kernel.cpp - * Output: \verbinclude FullPivLU_kernel.out - * - * \sa image() - */ - inline const internal::kernel_retval<FullPivLU> kernel() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return internal::kernel_retval<FullPivLU>(*this); - } - - /** \returns the image of the matrix, also called its column-space. The columns of the returned matrix - * will form a basis of the image (column-space). - * - * \param originalMatrix the original matrix, of which *this is the LU decomposition. - * The reason why it is needed to pass it here, is that this allows - * a large optimization, as otherwise this method would need to reconstruct it - * from the LU decomposition. - * - * \note If the image has dimension zero, then the returned matrix is a column-vector filled with zeros. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - * - * Example: \include FullPivLU_image.cpp - * Output: \verbinclude FullPivLU_image.out - * - * \sa kernel() - */ - inline const internal::image_retval<FullPivLU> - image(const MatrixType& originalMatrix) const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return internal::image_retval<FullPivLU>(*this, originalMatrix); - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** \return a solution x to the equation Ax=b, where A is the matrix of which - * *this is the LU decomposition. - * - * \param b the right-hand-side of the equation to solve. Can be a vector or a matrix, - * the only requirement in order for the equation to make sense is that - * b.rows()==A.rows(), where A is the matrix of which *this is the LU decomposition. - * - * \returns a solution. - * - * \note_about_checking_solutions - * - * \note_about_arbitrary_choice_of_solution - * \note_about_using_kernel_to_study_multiple_solutions - * - * Example: \include FullPivLU_solve.cpp - * Output: \verbinclude FullPivLU_solve.out - * - * \sa TriangularView::solve(), kernel(), inverse() - */ - template<typename Rhs> - inline const Solve<FullPivLU, Rhs> - solve(const MatrixBase<Rhs>& b) const; - #endif - - /** \returns an estimate of the reciprocal condition number of the matrix of which \c *this is - the LU decomposition. - */ - inline RealScalar rcond() const - { - eigen_assert(m_isInitialized && "PartialPivLU is not initialized."); - return internal::rcond_estimate_helper(m_l1_norm, *this); - } - - /** \returns the determinant of the matrix of which - * *this is the LU decomposition. It has only linear complexity - * (that is, O(n) where n is the dimension of the square matrix) - * as the LU decomposition has already been computed. - * - * \note This is only for square matrices. - * - * \note For fixed-size matrices of size up to 4, MatrixBase::determinant() offers - * optimized paths. - * - * \warning a determinant can be very big or small, so for matrices - * of large enough dimension, there is a risk of overflow/underflow. - * - * \sa MatrixBase::determinant() - */ - typename internal::traits<MatrixType>::Scalar determinant() const; - - /** Allows to prescribe a threshold to be used by certain methods, such as rank(), - * who need to determine when pivots are to be considered nonzero. This is not used for the - * LU decomposition itself. - * - * When it needs to get the threshold value, Eigen calls threshold(). By default, this - * uses a formula to automatically determine a reasonable threshold. - * Once you have called the present method setThreshold(const RealScalar&), - * your value is used instead. - * - * \param threshold The new value to use as the threshold. - * - * A pivot will be considered nonzero if its absolute value is strictly greater than - * \f$ \vert pivot \vert \leqslant threshold \times \vert maxpivot \vert \f$ - * where maxpivot is the biggest pivot. - * - * If you want to come back to the default behavior, call setThreshold(Default_t) - */ - FullPivLU& setThreshold(const RealScalar& threshold) - { - m_usePrescribedThreshold = true; - m_prescribedThreshold = threshold; - return *this; - } - - /** Allows to come back to the default behavior, letting Eigen use its default formula for - * determining the threshold. - * - * You should pass the special object Eigen::Default as parameter here. - * \code lu.setThreshold(Eigen::Default); \endcode - * - * See the documentation of setThreshold(const RealScalar&). - */ - FullPivLU& setThreshold(Default_t) - { - m_usePrescribedThreshold = false; - return *this; - } - - /** Returns the threshold that will be used by certain methods such as rank(). - * - * See the documentation of setThreshold(const RealScalar&). - */ - RealScalar threshold() const - { - eigen_assert(m_isInitialized || m_usePrescribedThreshold); - return m_usePrescribedThreshold ? m_prescribedThreshold - // this formula comes from experimenting (see "LU precision tuning" thread on the list) - // and turns out to be identical to Higham's formula used already in LDLt. - : NumTraits<Scalar>::epsilon() * RealScalar(m_lu.diagonalSize()); - } - - /** \returns the rank of the matrix of which *this is the LU decomposition. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline Index rank() const - { - using std::abs; - eigen_assert(m_isInitialized && "LU is not initialized."); - RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); - Index result = 0; - for(Index i = 0; i < m_nonzero_pivots; ++i) - result += (abs(m_lu.coeff(i,i)) > premultiplied_threshold); - return result; - } - - /** \returns the dimension of the kernel of the matrix of which *this is the LU decomposition. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline Index dimensionOfKernel() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return cols() - rank(); - } - - /** \returns true if the matrix of which *this is the LU decomposition represents an injective - * linear map, i.e. has trivial kernel; false otherwise. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isInjective() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return rank() == cols(); - } - - /** \returns true if the matrix of which *this is the LU decomposition represents a surjective - * linear map; false otherwise. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isSurjective() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return rank() == rows(); - } - - /** \returns true if the matrix of which *this is the LU decomposition is invertible. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isInvertible() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return isInjective() && (m_lu.rows() == m_lu.cols()); - } - - /** \returns the inverse of the matrix of which *this is the LU decomposition. - * - * \note If this matrix is not invertible, the returned matrix has undefined coefficients. - * Use isInvertible() to first determine whether this matrix is invertible. - * - * \sa MatrixBase::inverse() - */ - inline const Inverse<FullPivLU> inverse() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - eigen_assert(m_lu.rows() == m_lu.cols() && "You can't take the inverse of a non-square matrix!"); - return Inverse<FullPivLU>(*this); - } - - MatrixType reconstructedMatrix() const; - - EIGEN_DEVICE_FUNC inline Index rows() const { return m_lu.rows(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_lu.cols(); } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename RhsType, typename DstType> - void _solve_impl(const RhsType &rhs, DstType &dst) const; - - template<bool Conjugate, typename RhsType, typename DstType> - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const; - #endif - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - void computeInPlace(); - - MatrixType m_lu; - PermutationPType m_p; - PermutationQType m_q; - IntColVectorType m_rowsTranspositions; - IntRowVectorType m_colsTranspositions; - Index m_nonzero_pivots; - RealScalar m_l1_norm; - RealScalar m_maxpivot, m_prescribedThreshold; - signed char m_det_pq; - bool m_isInitialized, m_usePrescribedThreshold; -}; - -template<typename MatrixType> -FullPivLU<MatrixType>::FullPivLU() - : m_isInitialized(false), m_usePrescribedThreshold(false) -{ -} - -template<typename MatrixType> -FullPivLU<MatrixType>::FullPivLU(Index rows, Index cols) - : m_lu(rows, cols), - m_p(rows), - m_q(cols), - m_rowsTranspositions(rows), - m_colsTranspositions(cols), - m_isInitialized(false), - m_usePrescribedThreshold(false) -{ -} - -template<typename MatrixType> -template<typename InputType> -FullPivLU<MatrixType>::FullPivLU(const EigenBase<InputType>& matrix) - : m_lu(matrix.rows(), matrix.cols()), - m_p(matrix.rows()), - m_q(matrix.cols()), - m_rowsTranspositions(matrix.rows()), - m_colsTranspositions(matrix.cols()), - m_isInitialized(false), - m_usePrescribedThreshold(false) -{ - compute(matrix.derived()); -} - -template<typename MatrixType> -template<typename InputType> -FullPivLU<MatrixType>::FullPivLU(EigenBase<InputType>& matrix) - : m_lu(matrix.derived()), - m_p(matrix.rows()), - m_q(matrix.cols()), - m_rowsTranspositions(matrix.rows()), - m_colsTranspositions(matrix.cols()), - m_isInitialized(false), - m_usePrescribedThreshold(false) -{ - computeInPlace(); -} - -template<typename MatrixType> -void FullPivLU<MatrixType>::computeInPlace() -{ - check_template_parameters(); - - // the permutations are stored as int indices, so just to be sure: - eigen_assert(m_lu.rows()<=NumTraits<int>::highest() && m_lu.cols()<=NumTraits<int>::highest()); - - m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff(); - - const Index size = m_lu.diagonalSize(); - const Index rows = m_lu.rows(); - const Index cols = m_lu.cols(); - - // will store the transpositions, before we accumulate them at the end. - // can't accumulate on-the-fly because that will be done in reverse order for the rows. - m_rowsTranspositions.resize(m_lu.rows()); - m_colsTranspositions.resize(m_lu.cols()); - Index number_of_transpositions = 0; // number of NONTRIVIAL transpositions, i.e. m_rowsTranspositions[i]!=i - - m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case) - m_maxpivot = RealScalar(0); - - for(Index k = 0; k < size; ++k) - { - // First, we need to find the pivot. - - // biggest coefficient in the remaining bottom-right corner (starting at row k, col k) - Index row_of_biggest_in_corner, col_of_biggest_in_corner; - typedef internal::scalar_score_coeff_op<Scalar> Scoring; - typedef typename Scoring::result_type Score; - Score biggest_in_corner; - biggest_in_corner = m_lu.bottomRightCorner(rows-k, cols-k) - .unaryExpr(Scoring()) - .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner); - row_of_biggest_in_corner += k; // correct the values! since they were computed in the corner, - col_of_biggest_in_corner += k; // need to add k to them. - - if(biggest_in_corner==Score(0)) - { - // before exiting, make sure to initialize the still uninitialized transpositions - // in a sane state without destroying what we already have. - m_nonzero_pivots = k; - for(Index i = k; i < size; ++i) - { - m_rowsTranspositions.coeffRef(i) = internal::convert_index<StorageIndex>(i); - m_colsTranspositions.coeffRef(i) = internal::convert_index<StorageIndex>(i); - } - break; - } - - RealScalar abs_pivot = internal::abs_knowing_score<Scalar>()(m_lu(row_of_biggest_in_corner, col_of_biggest_in_corner), biggest_in_corner); - if(abs_pivot > m_maxpivot) m_maxpivot = abs_pivot; - - // Now that we've found the pivot, we need to apply the row/col swaps to - // bring it to the location (k,k). - - m_rowsTranspositions.coeffRef(k) = internal::convert_index<StorageIndex>(row_of_biggest_in_corner); - m_colsTranspositions.coeffRef(k) = internal::convert_index<StorageIndex>(col_of_biggest_in_corner); - if(k != row_of_biggest_in_corner) { - m_lu.row(k).swap(m_lu.row(row_of_biggest_in_corner)); - ++number_of_transpositions; - } - if(k != col_of_biggest_in_corner) { - m_lu.col(k).swap(m_lu.col(col_of_biggest_in_corner)); - ++number_of_transpositions; - } - - // Now that the pivot is at the right location, we update the remaining - // bottom-right corner by Gaussian elimination. - - if(k<rows-1) - m_lu.col(k).tail(rows-k-1) /= m_lu.coeff(k,k); - if(k<size-1) - m_lu.block(k+1,k+1,rows-k-1,cols-k-1).noalias() -= m_lu.col(k).tail(rows-k-1) * m_lu.row(k).tail(cols-k-1); - } - - // the main loop is over, we still have to accumulate the transpositions to find the - // permutations P and Q - - m_p.setIdentity(rows); - for(Index k = size-1; k >= 0; --k) - m_p.applyTranspositionOnTheRight(k, m_rowsTranspositions.coeff(k)); - - m_q.setIdentity(cols); - for(Index k = 0; k < size; ++k) - m_q.applyTranspositionOnTheRight(k, m_colsTranspositions.coeff(k)); - - m_det_pq = (number_of_transpositions%2) ? -1 : 1; - - m_isInitialized = true; -} - -template<typename MatrixType> -typename internal::traits<MatrixType>::Scalar FullPivLU<MatrixType>::determinant() const -{ - eigen_assert(m_isInitialized && "LU is not initialized."); - eigen_assert(m_lu.rows() == m_lu.cols() && "You can't take the determinant of a non-square matrix!"); - return Scalar(m_det_pq) * Scalar(m_lu.diagonal().prod()); -} - -/** \returns the matrix represented by the decomposition, - * i.e., it returns the product: \f$ P^{-1} L U Q^{-1} \f$. - * This function is provided for debug purposes. */ -template<typename MatrixType> -MatrixType FullPivLU<MatrixType>::reconstructedMatrix() const -{ - eigen_assert(m_isInitialized && "LU is not initialized."); - const Index smalldim = (std::min)(m_lu.rows(), m_lu.cols()); - // LU - MatrixType res(m_lu.rows(),m_lu.cols()); - // FIXME the .toDenseMatrix() should not be needed... - res = m_lu.leftCols(smalldim) - .template triangularView<UnitLower>().toDenseMatrix() - * m_lu.topRows(smalldim) - .template triangularView<Upper>().toDenseMatrix(); - - // P^{-1}(LU) - res = m_p.inverse() * res; - - // (P^{-1}LU)Q^{-1} - res = res * m_q.inverse(); - - return res; -} - -/********* Implementation of kernel() **************************************************/ - -namespace internal { -template<typename _MatrixType> -struct kernel_retval<FullPivLU<_MatrixType> > - : kernel_retval_base<FullPivLU<_MatrixType> > -{ - EIGEN_MAKE_KERNEL_HELPERS(FullPivLU<_MatrixType>) - - enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED( - MatrixType::MaxColsAtCompileTime, - MatrixType::MaxRowsAtCompileTime) - }; - - template<typename Dest> void evalTo(Dest& dst) const - { - using std::abs; - const Index cols = dec().matrixLU().cols(), dimker = cols - rank(); - if(dimker == 0) - { - // The Kernel is just {0}, so it doesn't have a basis properly speaking, but let's - // avoid crashing/asserting as that depends on floating point calculations. Let's - // just return a single column vector filled with zeros. - dst.setZero(); - return; - } - - /* Let us use the following lemma: - * - * Lemma: If the matrix A has the LU decomposition PAQ = LU, - * then Ker A = Q(Ker U). - * - * Proof: trivial: just keep in mind that P, Q, L are invertible. - */ - - /* Thus, all we need to do is to compute Ker U, and then apply Q. - * - * U is upper triangular, with eigenvalues sorted so that any zeros appear at the end. - * Thus, the diagonal of U ends with exactly - * dimKer zero's. Let us use that to construct dimKer linearly - * independent vectors in Ker U. - */ - - Matrix<Index, Dynamic, 1, 0, MaxSmallDimAtCompileTime, 1> pivots(rank()); - RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold(); - Index p = 0; - for(Index i = 0; i < dec().nonzeroPivots(); ++i) - if(abs(dec().matrixLU().coeff(i,i)) > premultiplied_threshold) - pivots.coeffRef(p++) = i; - eigen_internal_assert(p == rank()); - - // we construct a temporaty trapezoid matrix m, by taking the U matrix and - // permuting the rows and cols to bring the nonnegligible pivots to the top of - // the main diagonal. We need that to be able to apply our triangular solvers. - // FIXME when we get triangularView-for-rectangular-matrices, this can be simplified - Matrix<typename MatrixType::Scalar, Dynamic, Dynamic, MatrixType::Options, - MaxSmallDimAtCompileTime, MatrixType::MaxColsAtCompileTime> - m(dec().matrixLU().block(0, 0, rank(), cols)); - for(Index i = 0; i < rank(); ++i) - { - if(i) m.row(i).head(i).setZero(); - m.row(i).tail(cols-i) = dec().matrixLU().row(pivots.coeff(i)).tail(cols-i); - } - m.block(0, 0, rank(), rank()); - m.block(0, 0, rank(), rank()).template triangularView<StrictlyLower>().setZero(); - for(Index i = 0; i < rank(); ++i) - m.col(i).swap(m.col(pivots.coeff(i))); - - // ok, we have our trapezoid matrix, we can apply the triangular solver. - // notice that the math behind this suggests that we should apply this to the - // negative of the RHS, but for performance we just put the negative sign elsewhere, see below. - m.topLeftCorner(rank(), rank()) - .template triangularView<Upper>().solveInPlace( - m.topRightCorner(rank(), dimker) - ); - - // now we must undo the column permutation that we had applied! - for(Index i = rank()-1; i >= 0; --i) - m.col(i).swap(m.col(pivots.coeff(i))); - - // see the negative sign in the next line, that's what we were talking about above. - for(Index i = 0; i < rank(); ++i) dst.row(dec().permutationQ().indices().coeff(i)) = -m.row(i).tail(dimker); - for(Index i = rank(); i < cols; ++i) dst.row(dec().permutationQ().indices().coeff(i)).setZero(); - for(Index k = 0; k < dimker; ++k) dst.coeffRef(dec().permutationQ().indices().coeff(rank()+k), k) = Scalar(1); - } -}; - -/***** Implementation of image() *****************************************************/ - -template<typename _MatrixType> -struct image_retval<FullPivLU<_MatrixType> > - : image_retval_base<FullPivLU<_MatrixType> > -{ - EIGEN_MAKE_IMAGE_HELPERS(FullPivLU<_MatrixType>) - - enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED( - MatrixType::MaxColsAtCompileTime, - MatrixType::MaxRowsAtCompileTime) - }; - - template<typename Dest> void evalTo(Dest& dst) const - { - using std::abs; - if(rank() == 0) - { - // The Image is just {0}, so it doesn't have a basis properly speaking, but let's - // avoid crashing/asserting as that depends on floating point calculations. Let's - // just return a single column vector filled with zeros. - dst.setZero(); - return; - } - - Matrix<Index, Dynamic, 1, 0, MaxSmallDimAtCompileTime, 1> pivots(rank()); - RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold(); - Index p = 0; - for(Index i = 0; i < dec().nonzeroPivots(); ++i) - if(abs(dec().matrixLU().coeff(i,i)) > premultiplied_threshold) - pivots.coeffRef(p++) = i; - eigen_internal_assert(p == rank()); - - for(Index i = 0; i < rank(); ++i) - dst.col(i) = originalMatrix().col(dec().permutationQ().indices().coeff(pivots.coeff(i))); - } -}; - -/***** Implementation of solve() *****************************************************/ - -} // end namespace internal - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename _MatrixType> -template<typename RhsType, typename DstType> -void FullPivLU<_MatrixType>::_solve_impl(const RhsType &rhs, DstType &dst) const -{ - /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}. - * So we proceed as follows: - * Step 1: compute c = P * rhs. - * Step 2: replace c by the solution x to Lx = c. Exists because L is invertible. - * Step 3: replace c by the solution x to Ux = c. May or may not exist. - * Step 4: result = Q * c; - */ - - const Index rows = this->rows(), - cols = this->cols(), - nonzero_pivots = this->rank(); - const Index smalldim = (std::min)(rows, cols); - - if(nonzero_pivots == 0) - { - dst.setZero(); - return; - } - - typename RhsType::PlainObject c(rhs.rows(), rhs.cols()); - - // Step 1 - c = permutationP() * rhs; - - // Step 2 - m_lu.topLeftCorner(smalldim,smalldim) - .template triangularView<UnitLower>() - .solveInPlace(c.topRows(smalldim)); - if(rows>cols) - c.bottomRows(rows-cols) -= m_lu.bottomRows(rows-cols) * c.topRows(cols); - - // Step 3 - m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots) - .template triangularView<Upper>() - .solveInPlace(c.topRows(nonzero_pivots)); - - // Step 4 - for(Index i = 0; i < nonzero_pivots; ++i) - dst.row(permutationQ().indices().coeff(i)) = c.row(i); - for(Index i = nonzero_pivots; i < m_lu.cols(); ++i) - dst.row(permutationQ().indices().coeff(i)).setZero(); -} - -template<typename _MatrixType> -template<bool Conjugate, typename RhsType, typename DstType> -void FullPivLU<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const -{ - /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}, - * and since permutations are real and unitary, we can write this - * as A^T = Q U^T L^T P, - * So we proceed as follows: - * Step 1: compute c = Q^T rhs. - * Step 2: replace c by the solution x to U^T x = c. May or may not exist. - * Step 3: replace c by the solution x to L^T x = c. - * Step 4: result = P^T c. - * If Conjugate is true, replace "^T" by "^*" above. - */ - - const Index rows = this->rows(), cols = this->cols(), - nonzero_pivots = this->rank(); - const Index smalldim = (std::min)(rows, cols); - - if(nonzero_pivots == 0) - { - dst.setZero(); - return; - } - - typename RhsType::PlainObject c(rhs.rows(), rhs.cols()); - - // Step 1 - c = permutationQ().inverse() * rhs; - - // Step 2 - m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots) - .template triangularView<Upper>() - .transpose() - .template conjugateIf<Conjugate>() - .solveInPlace(c.topRows(nonzero_pivots)); - - // Step 3 - m_lu.topLeftCorner(smalldim, smalldim) - .template triangularView<UnitLower>() - .transpose() - .template conjugateIf<Conjugate>() - .solveInPlace(c.topRows(smalldim)); - - // Step 4 - PermutationPType invp = permutationP().inverse().eval(); - for(Index i = 0; i < smalldim; ++i) - dst.row(invp.indices().coeff(i)) = c.row(i); - for(Index i = smalldim; i < rows; ++i) - dst.row(invp.indices().coeff(i)).setZero(); -} - -#endif - -namespace internal { - - -/***** Implementation of inverse() *****************************************************/ -template<typename DstXprType, typename MatrixType> -struct Assignment<DstXprType, Inverse<FullPivLU<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename FullPivLU<MatrixType>::Scalar>, Dense2Dense> -{ - typedef FullPivLU<MatrixType> LuType; - typedef Inverse<LuType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename MatrixType::Scalar> &) - { - dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols())); - } -}; -} // end namespace internal - -/******* MatrixBase methods *****************************************************************/ - -/** \lu_module - * - * \return the full-pivoting LU decomposition of \c *this. - * - * \sa class FullPivLU - */ -template<typename Derived> -inline const FullPivLU<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::fullPivLu() const -{ - return FullPivLU<PlainObject>(eval()); -} - -} // end namespace Eigen - -#endif // EIGEN_LU_H diff --git a/external/eigen/include/eigen3/Eigen/src/LU/InverseImpl.h b/external/eigen/include/eigen3/Eigen/src/LU/InverseImpl.h deleted file mode 100644 index 1bab00c0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/LU/InverseImpl.h +++ /dev/null @@ -1,417 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_INVERSE_IMPL_H -#define EIGEN_INVERSE_IMPL_H - -namespace Eigen { - -namespace internal { - -/********************************** -*** General case implementation *** -**********************************/ - -template<typename MatrixType, typename ResultType, int Size = MatrixType::RowsAtCompileTime> -struct compute_inverse -{ - EIGEN_DEVICE_FUNC - static inline void run(const MatrixType& matrix, ResultType& result) - { - result = matrix.partialPivLu().inverse(); - } -}; - -template<typename MatrixType, typename ResultType, int Size = MatrixType::RowsAtCompileTime> -struct compute_inverse_and_det_with_check { /* nothing! general case not supported. */ }; - -/**************************** -*** Size 1 implementation *** -****************************/ - -template<typename MatrixType, typename ResultType> -struct compute_inverse<MatrixType, ResultType, 1> -{ - EIGEN_DEVICE_FUNC - static inline void run(const MatrixType& matrix, ResultType& result) - { - typedef typename MatrixType::Scalar Scalar; - internal::evaluator<MatrixType> matrixEval(matrix); - result.coeffRef(0,0) = Scalar(1) / matrixEval.coeff(0,0); - } -}; - -template<typename MatrixType, typename ResultType> -struct compute_inverse_and_det_with_check<MatrixType, ResultType, 1> -{ - EIGEN_DEVICE_FUNC - static inline void run( - const MatrixType& matrix, - const typename MatrixType::RealScalar& absDeterminantThreshold, - ResultType& result, - typename ResultType::Scalar& determinant, - bool& invertible - ) - { - using std::abs; - determinant = matrix.coeff(0,0); - invertible = abs(determinant) > absDeterminantThreshold; - if(invertible) result.coeffRef(0,0) = typename ResultType::Scalar(1) / determinant; - } -}; - -/**************************** -*** Size 2 implementation *** -****************************/ - -template<typename MatrixType, typename ResultType> -EIGEN_DEVICE_FUNC -inline void compute_inverse_size2_helper( - const MatrixType& matrix, const typename ResultType::Scalar& invdet, - ResultType& result) -{ - result.coeffRef(0,0) = matrix.coeff(1,1) * invdet; - result.coeffRef(1,0) = -matrix.coeff(1,0) * invdet; - result.coeffRef(0,1) = -matrix.coeff(0,1) * invdet; - result.coeffRef(1,1) = matrix.coeff(0,0) * invdet; -} - -template<typename MatrixType, typename ResultType> -struct compute_inverse<MatrixType, ResultType, 2> -{ - EIGEN_DEVICE_FUNC - static inline void run(const MatrixType& matrix, ResultType& result) - { - typedef typename ResultType::Scalar Scalar; - const Scalar invdet = typename MatrixType::Scalar(1) / matrix.determinant(); - compute_inverse_size2_helper(matrix, invdet, result); - } -}; - -template<typename MatrixType, typename ResultType> -struct compute_inverse_and_det_with_check<MatrixType, ResultType, 2> -{ - EIGEN_DEVICE_FUNC - static inline void run( - const MatrixType& matrix, - const typename MatrixType::RealScalar& absDeterminantThreshold, - ResultType& inverse, - typename ResultType::Scalar& determinant, - bool& invertible - ) - { - using std::abs; - typedef typename ResultType::Scalar Scalar; - determinant = matrix.determinant(); - invertible = abs(determinant) > absDeterminantThreshold; - if(!invertible) return; - const Scalar invdet = Scalar(1) / determinant; - compute_inverse_size2_helper(matrix, invdet, inverse); - } -}; - -/**************************** -*** Size 3 implementation *** -****************************/ - -template<typename MatrixType, int i, int j> -EIGEN_DEVICE_FUNC -inline typename MatrixType::Scalar cofactor_3x3(const MatrixType& m) -{ - enum { - i1 = (i+1) % 3, - i2 = (i+2) % 3, - j1 = (j+1) % 3, - j2 = (j+2) % 3 - }; - return m.coeff(i1, j1) * m.coeff(i2, j2) - - m.coeff(i1, j2) * m.coeff(i2, j1); -} - -template<typename MatrixType, typename ResultType> -EIGEN_DEVICE_FUNC -inline void compute_inverse_size3_helper( - const MatrixType& matrix, - const typename ResultType::Scalar& invdet, - const Matrix<typename ResultType::Scalar,3,1>& cofactors_col0, - ResultType& result) -{ - result.row(0) = cofactors_col0 * invdet; - result.coeffRef(1,0) = cofactor_3x3<MatrixType,0,1>(matrix) * invdet; - result.coeffRef(1,1) = cofactor_3x3<MatrixType,1,1>(matrix) * invdet; - result.coeffRef(1,2) = cofactor_3x3<MatrixType,2,1>(matrix) * invdet; - result.coeffRef(2,0) = cofactor_3x3<MatrixType,0,2>(matrix) * invdet; - result.coeffRef(2,1) = cofactor_3x3<MatrixType,1,2>(matrix) * invdet; - result.coeffRef(2,2) = cofactor_3x3<MatrixType,2,2>(matrix) * invdet; -} - -template<typename MatrixType, typename ResultType> -struct compute_inverse<MatrixType, ResultType, 3> -{ - EIGEN_DEVICE_FUNC - static inline void run(const MatrixType& matrix, ResultType& result) - { - typedef typename ResultType::Scalar Scalar; - Matrix<typename MatrixType::Scalar,3,1> cofactors_col0; - cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix); - cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix); - cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix); - const Scalar det = (cofactors_col0.cwiseProduct(matrix.col(0))).sum(); - const Scalar invdet = Scalar(1) / det; - compute_inverse_size3_helper(matrix, invdet, cofactors_col0, result); - } -}; - -template<typename MatrixType, typename ResultType> -struct compute_inverse_and_det_with_check<MatrixType, ResultType, 3> -{ - EIGEN_DEVICE_FUNC - static inline void run( - const MatrixType& matrix, - const typename MatrixType::RealScalar& absDeterminantThreshold, - ResultType& inverse, - typename ResultType::Scalar& determinant, - bool& invertible - ) - { - using std::abs; - typedef typename ResultType::Scalar Scalar; - Matrix<Scalar,3,1> cofactors_col0; - cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix); - cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix); - cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix); - determinant = (cofactors_col0.cwiseProduct(matrix.col(0))).sum(); - invertible = abs(determinant) > absDeterminantThreshold; - if(!invertible) return; - const Scalar invdet = Scalar(1) / determinant; - compute_inverse_size3_helper(matrix, invdet, cofactors_col0, inverse); - } -}; - -/**************************** -*** Size 4 implementation *** -****************************/ - -template<typename Derived> -EIGEN_DEVICE_FUNC -inline const typename Derived::Scalar general_det3_helper -(const MatrixBase<Derived>& matrix, int i1, int i2, int i3, int j1, int j2, int j3) -{ - return matrix.coeff(i1,j1) - * (matrix.coeff(i2,j2) * matrix.coeff(i3,j3) - matrix.coeff(i2,j3) * matrix.coeff(i3,j2)); -} - -template<typename MatrixType, int i, int j> -EIGEN_DEVICE_FUNC -inline typename MatrixType::Scalar cofactor_4x4(const MatrixType& matrix) -{ - enum { - i1 = (i+1) % 4, - i2 = (i+2) % 4, - i3 = (i+3) % 4, - j1 = (j+1) % 4, - j2 = (j+2) % 4, - j3 = (j+3) % 4 - }; - return general_det3_helper(matrix, i1, i2, i3, j1, j2, j3) - + general_det3_helper(matrix, i2, i3, i1, j1, j2, j3) - + general_det3_helper(matrix, i3, i1, i2, j1, j2, j3); -} - -template<int Arch, typename Scalar, typename MatrixType, typename ResultType> -struct compute_inverse_size4 -{ - EIGEN_DEVICE_FUNC - static void run(const MatrixType& matrix, ResultType& result) - { - result.coeffRef(0,0) = cofactor_4x4<MatrixType,0,0>(matrix); - result.coeffRef(1,0) = -cofactor_4x4<MatrixType,0,1>(matrix); - result.coeffRef(2,0) = cofactor_4x4<MatrixType,0,2>(matrix); - result.coeffRef(3,0) = -cofactor_4x4<MatrixType,0,3>(matrix); - result.coeffRef(0,2) = cofactor_4x4<MatrixType,2,0>(matrix); - result.coeffRef(1,2) = -cofactor_4x4<MatrixType,2,1>(matrix); - result.coeffRef(2,2) = cofactor_4x4<MatrixType,2,2>(matrix); - result.coeffRef(3,2) = -cofactor_4x4<MatrixType,2,3>(matrix); - result.coeffRef(0,1) = -cofactor_4x4<MatrixType,1,0>(matrix); - result.coeffRef(1,1) = cofactor_4x4<MatrixType,1,1>(matrix); - result.coeffRef(2,1) = -cofactor_4x4<MatrixType,1,2>(matrix); - result.coeffRef(3,1) = cofactor_4x4<MatrixType,1,3>(matrix); - result.coeffRef(0,3) = -cofactor_4x4<MatrixType,3,0>(matrix); - result.coeffRef(1,3) = cofactor_4x4<MatrixType,3,1>(matrix); - result.coeffRef(2,3) = -cofactor_4x4<MatrixType,3,2>(matrix); - result.coeffRef(3,3) = cofactor_4x4<MatrixType,3,3>(matrix); - result /= (matrix.col(0).cwiseProduct(result.row(0).transpose())).sum(); - } -}; - -template<typename MatrixType, typename ResultType> -struct compute_inverse<MatrixType, ResultType, 4> - : compute_inverse_size4<Architecture::Target, typename MatrixType::Scalar, - MatrixType, ResultType> -{ -}; - -template<typename MatrixType, typename ResultType> -struct compute_inverse_and_det_with_check<MatrixType, ResultType, 4> -{ - EIGEN_DEVICE_FUNC - static inline void run( - const MatrixType& matrix, - const typename MatrixType::RealScalar& absDeterminantThreshold, - ResultType& inverse, - typename ResultType::Scalar& determinant, - bool& invertible - ) - { - using std::abs; - determinant = matrix.determinant(); - invertible = abs(determinant) > absDeterminantThreshold; - if(invertible) compute_inverse<MatrixType, ResultType>::run(matrix, inverse); - } -}; - -/************************* -*** MatrixBase methods *** -*************************/ - -} // end namespace internal - -namespace internal { - -// Specialization for "dense = dense_xpr.inverse()" -template<typename DstXprType, typename XprType> -struct Assignment<DstXprType, Inverse<XprType>, internal::assign_op<typename DstXprType::Scalar,typename XprType::Scalar>, Dense2Dense> -{ - typedef Inverse<XprType> SrcXprType; - EIGEN_DEVICE_FUNC - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename XprType::Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - const int Size = EIGEN_PLAIN_ENUM_MIN(XprType::ColsAtCompileTime,DstXprType::ColsAtCompileTime); - EIGEN_ONLY_USED_FOR_DEBUG(Size); - eigen_assert(( (Size<=1) || (Size>4) || (extract_data(src.nestedExpression())!=extract_data(dst))) - && "Aliasing problem detected in inverse(), you need to do inverse().eval() here."); - - typedef typename internal::nested_eval<XprType,XprType::ColsAtCompileTime>::type ActualXprType; - typedef typename internal::remove_all<ActualXprType>::type ActualXprTypeCleanded; - - ActualXprType actual_xpr(src.nestedExpression()); - - compute_inverse<ActualXprTypeCleanded, DstXprType>::run(actual_xpr, dst); - } -}; - - -} // end namespace internal - -/** \lu_module - * - * \returns the matrix inverse of this matrix. - * - * For small fixed sizes up to 4x4, this method uses cofactors. - * In the general case, this method uses class PartialPivLU. - * - * \note This matrix must be invertible, otherwise the result is undefined. If you need an - * invertibility check, do the following: - * \li for fixed sizes up to 4x4, use computeInverseAndDetWithCheck(). - * \li for the general case, use class FullPivLU. - * - * Example: \include MatrixBase_inverse.cpp - * Output: \verbinclude MatrixBase_inverse.out - * - * \sa computeInverseAndDetWithCheck() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC -inline const Inverse<Derived> MatrixBase<Derived>::inverse() const -{ - EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsInteger,THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES) - eigen_assert(rows() == cols()); - return Inverse<Derived>(derived()); -} - -/** \lu_module - * - * Computation of matrix inverse and determinant, with invertibility check. - * - * This is only for fixed-size square matrices of size up to 4x4. - * - * \param inverse Reference to the matrix in which to store the inverse. - * \param determinant Reference to the variable in which to store the determinant. - * \param invertible Reference to the bool variable in which to store whether the matrix is invertible. - * \param absDeterminantThreshold Optional parameter controlling the invertibility check. - * The matrix will be declared invertible if the absolute value of its - * determinant is greater than this threshold. - * - * Example: \include MatrixBase_computeInverseAndDetWithCheck.cpp - * Output: \verbinclude MatrixBase_computeInverseAndDetWithCheck.out - * - * \sa inverse(), computeInverseWithCheck() - */ -template<typename Derived> -template<typename ResultType> -inline void MatrixBase<Derived>::computeInverseAndDetWithCheck( - ResultType& inverse, - typename ResultType::Scalar& determinant, - bool& invertible, - const RealScalar& absDeterminantThreshold - ) const -{ - // i'd love to put some static assertions there, but SFINAE means that they have no effect... - eigen_assert(rows() == cols()); - // for 2x2, it's worth giving a chance to avoid evaluating. - // for larger sizes, evaluating has negligible cost and limits code size. - typedef typename internal::conditional< - RowsAtCompileTime == 2, - typename internal::remove_all<typename internal::nested_eval<Derived, 2>::type>::type, - PlainObject - >::type MatrixType; - internal::compute_inverse_and_det_with_check<MatrixType, ResultType>::run - (derived(), absDeterminantThreshold, inverse, determinant, invertible); -} - -/** \lu_module - * - * Computation of matrix inverse, with invertibility check. - * - * This is only for fixed-size square matrices of size up to 4x4. - * - * \param inverse Reference to the matrix in which to store the inverse. - * \param invertible Reference to the bool variable in which to store whether the matrix is invertible. - * \param absDeterminantThreshold Optional parameter controlling the invertibility check. - * The matrix will be declared invertible if the absolute value of its - * determinant is greater than this threshold. - * - * Example: \include MatrixBase_computeInverseWithCheck.cpp - * Output: \verbinclude MatrixBase_computeInverseWithCheck.out - * - * \sa inverse(), computeInverseAndDetWithCheck() - */ -template<typename Derived> -template<typename ResultType> -inline void MatrixBase<Derived>::computeInverseWithCheck( - ResultType& inverse, - bool& invertible, - const RealScalar& absDeterminantThreshold - ) const -{ - Scalar determinant; - // i'd love to put some static assertions there, but SFINAE means that they have no effect... - eigen_assert(rows() == cols()); - computeInverseAndDetWithCheck(inverse,determinant,invertible,absDeterminantThreshold); -} - -} // end namespace Eigen - -#endif // EIGEN_INVERSE_IMPL_H diff --git a/external/eigen/include/eigen3/Eigen/src/LU/PartialPivLU.h b/external/eigen/include/eigen3/Eigen/src/LU/PartialPivLU.h deleted file mode 100644 index b8938013..00000000 --- a/external/eigen/include/eigen3/Eigen/src/LU/PartialPivLU.h +++ /dev/null @@ -1,619 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PARTIALLU_H -#define EIGEN_PARTIALLU_H - -namespace Eigen { - -namespace internal { -template<typename _MatrixType> struct traits<PartialPivLU<_MatrixType> > - : traits<_MatrixType> -{ - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - typedef traits<_MatrixType> BaseTraits; - enum { - Flags = BaseTraits::Flags & RowMajorBit, - CoeffReadCost = Dynamic - }; -}; - -template<typename T,typename Derived> -struct enable_if_ref; -// { -// typedef Derived type; -// }; - -template<typename T,typename Derived> -struct enable_if_ref<Ref<T>,Derived> { - typedef Derived type; -}; - -} // end namespace internal - -/** \ingroup LU_Module - * - * \class PartialPivLU - * - * \brief LU decomposition of a matrix with partial pivoting, and related features - * - * \tparam _MatrixType the type of the matrix of which we are computing the LU decomposition - * - * This class represents a LU decomposition of a \b square \b invertible matrix, with partial pivoting: the matrix A - * is decomposed as A = PLU where L is unit-lower-triangular, U is upper-triangular, and P - * is a permutation matrix. - * - * Typically, partial pivoting LU decomposition is only considered numerically stable for square invertible - * matrices. Thus LAPACK's dgesv and dgesvx require the matrix to be square and invertible. The present class - * does the same. It will assert that the matrix is square, but it won't (actually it can't) check that the - * matrix is invertible: it is your task to check that you only use this decomposition on invertible matrices. - * - * The guaranteed safe alternative, working for all matrices, is the full pivoting LU decomposition, provided - * by class FullPivLU. - * - * This is \b not a rank-revealing LU decomposition. Many features are intentionally absent from this class, - * such as rank computation. If you need these features, use class FullPivLU. - * - * This LU decomposition is suitable to invert invertible matrices. It is what MatrixBase::inverse() uses - * in the general case. - * On the other hand, it is \b not suitable to determine whether a given matrix is invertible. - * - * The data of the LU decomposition can be directly accessed through the methods matrixLU(), permutationP(). - * - * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. - * - * \sa MatrixBase::partialPivLu(), MatrixBase::determinant(), MatrixBase::inverse(), MatrixBase::computeInverse(), class FullPivLU - */ -template<typename _MatrixType> class PartialPivLU - : public SolverBase<PartialPivLU<_MatrixType> > -{ - public: - - typedef _MatrixType MatrixType; - typedef SolverBase<PartialPivLU> Base; - friend class SolverBase<PartialPivLU>; - - EIGEN_GENERIC_PUBLIC_INTERFACE(PartialPivLU) - enum { - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType; - typedef Transpositions<RowsAtCompileTime, MaxRowsAtCompileTime> TranspositionType; - typedef typename MatrixType::PlainObject PlainObject; - - /** - * \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via PartialPivLU::compute(const MatrixType&). - */ - PartialPivLU(); - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa PartialPivLU() - */ - explicit PartialPivLU(Index size); - - /** Constructor. - * - * \param matrix the matrix of which to compute the LU decomposition. - * - * \warning The matrix should have full rank (e.g. if it's square, it should be invertible). - * If you need to deal with non-full rank, use class FullPivLU instead. - */ - template<typename InputType> - explicit PartialPivLU(const EigenBase<InputType>& matrix); - - /** Constructor for \link InplaceDecomposition inplace decomposition \endlink - * - * \param matrix the matrix of which to compute the LU decomposition. - * - * \warning The matrix should have full rank (e.g. if it's square, it should be invertible). - * If you need to deal with non-full rank, use class FullPivLU instead. - */ - template<typename InputType> - explicit PartialPivLU(EigenBase<InputType>& matrix); - - template<typename InputType> - PartialPivLU& compute(const EigenBase<InputType>& matrix) { - m_lu = matrix.derived(); - compute(); - return *this; - } - - /** \returns the LU decomposition matrix: the upper-triangular part is U, the - * unit-lower-triangular part is L (at least for square matrices; in the non-square - * case, special care is needed, see the documentation of class FullPivLU). - * - * \sa matrixL(), matrixU() - */ - inline const MatrixType& matrixLU() const - { - eigen_assert(m_isInitialized && "PartialPivLU is not initialized."); - return m_lu; - } - - /** \returns the permutation matrix P. - */ - inline const PermutationType& permutationP() const - { - eigen_assert(m_isInitialized && "PartialPivLU is not initialized."); - return m_p; - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** This method returns the solution x to the equation Ax=b, where A is the matrix of which - * *this is the LU decomposition. - * - * \param b the right-hand-side of the equation to solve. Can be a vector or a matrix, - * the only requirement in order for the equation to make sense is that - * b.rows()==A.rows(), where A is the matrix of which *this is the LU decomposition. - * - * \returns the solution. - * - * Example: \include PartialPivLU_solve.cpp - * Output: \verbinclude PartialPivLU_solve.out - * - * Since this PartialPivLU class assumes anyway that the matrix A is invertible, the solution - * theoretically exists and is unique regardless of b. - * - * \sa TriangularView::solve(), inverse(), computeInverse() - */ - template<typename Rhs> - inline const Solve<PartialPivLU, Rhs> - solve(const MatrixBase<Rhs>& b) const; - #endif - - /** \returns an estimate of the reciprocal condition number of the matrix of which \c *this is - the LU decomposition. - */ - inline RealScalar rcond() const - { - eigen_assert(m_isInitialized && "PartialPivLU is not initialized."); - return internal::rcond_estimate_helper(m_l1_norm, *this); - } - - /** \returns the inverse of the matrix of which *this is the LU decomposition. - * - * \warning The matrix being decomposed here is assumed to be invertible. If you need to check for - * invertibility, use class FullPivLU instead. - * - * \sa MatrixBase::inverse(), LU::inverse() - */ - inline const Inverse<PartialPivLU> inverse() const - { - eigen_assert(m_isInitialized && "PartialPivLU is not initialized."); - return Inverse<PartialPivLU>(*this); - } - - /** \returns the determinant of the matrix of which - * *this is the LU decomposition. It has only linear complexity - * (that is, O(n) where n is the dimension of the square matrix) - * as the LU decomposition has already been computed. - * - * \note For fixed-size matrices of size up to 4, MatrixBase::determinant() offers - * optimized paths. - * - * \warning a determinant can be very big or small, so for matrices - * of large enough dimension, there is a risk of overflow/underflow. - * - * \sa MatrixBase::determinant() - */ - Scalar determinant() const; - - MatrixType reconstructedMatrix() const; - - inline Index rows() const { return m_lu.rows(); } - inline Index cols() const { return m_lu.cols(); } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename RhsType, typename DstType> - EIGEN_DEVICE_FUNC - void _solve_impl(const RhsType &rhs, DstType &dst) const { - /* The decomposition PA = LU can be rewritten as A = P^{-1} L U. - * So we proceed as follows: - * Step 1: compute c = Pb. - * Step 2: replace c by the solution x to Lx = c. - * Step 3: replace c by the solution x to Ux = c. - */ - - // Step 1 - dst = permutationP() * rhs; - - // Step 2 - m_lu.template triangularView<UnitLower>().solveInPlace(dst); - - // Step 3 - m_lu.template triangularView<Upper>().solveInPlace(dst); - } - - template<bool Conjugate, typename RhsType, typename DstType> - EIGEN_DEVICE_FUNC - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const { - /* The decomposition PA = LU can be rewritten as A^T = U^T L^T P. - * So we proceed as follows: - * Step 1: compute c as the solution to L^T c = b - * Step 2: replace c by the solution x to U^T x = c. - * Step 3: update c = P^-1 c. - */ - - eigen_assert(rhs.rows() == m_lu.cols()); - - // Step 1 - dst = m_lu.template triangularView<Upper>().transpose() - .template conjugateIf<Conjugate>().solve(rhs); - // Step 2 - m_lu.template triangularView<UnitLower>().transpose() - .template conjugateIf<Conjugate>().solveInPlace(dst); - // Step 3 - dst = permutationP().transpose() * dst; - } - #endif - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - void compute(); - - MatrixType m_lu; - PermutationType m_p; - TranspositionType m_rowsTranspositions; - RealScalar m_l1_norm; - signed char m_det_p; - bool m_isInitialized; -}; - -template<typename MatrixType> -PartialPivLU<MatrixType>::PartialPivLU() - : m_lu(), - m_p(), - m_rowsTranspositions(), - m_l1_norm(0), - m_det_p(0), - m_isInitialized(false) -{ -} - -template<typename MatrixType> -PartialPivLU<MatrixType>::PartialPivLU(Index size) - : m_lu(size, size), - m_p(size), - m_rowsTranspositions(size), - m_l1_norm(0), - m_det_p(0), - m_isInitialized(false) -{ -} - -template<typename MatrixType> -template<typename InputType> -PartialPivLU<MatrixType>::PartialPivLU(const EigenBase<InputType>& matrix) - : m_lu(matrix.rows(),matrix.cols()), - m_p(matrix.rows()), - m_rowsTranspositions(matrix.rows()), - m_l1_norm(0), - m_det_p(0), - m_isInitialized(false) -{ - compute(matrix.derived()); -} - -template<typename MatrixType> -template<typename InputType> -PartialPivLU<MatrixType>::PartialPivLU(EigenBase<InputType>& matrix) - : m_lu(matrix.derived()), - m_p(matrix.rows()), - m_rowsTranspositions(matrix.rows()), - m_l1_norm(0), - m_det_p(0), - m_isInitialized(false) -{ - compute(); -} - -namespace internal { - -/** \internal This is the blocked version of fullpivlu_unblocked() */ -template<typename Scalar, int StorageOrder, typename PivIndex, int SizeAtCompileTime=Dynamic> -struct partial_lu_impl -{ - static const int UnBlockedBound = 16; - static const bool UnBlockedAtCompileTime = SizeAtCompileTime!=Dynamic && SizeAtCompileTime<=UnBlockedBound; - static const int ActualSizeAtCompileTime = UnBlockedAtCompileTime ? SizeAtCompileTime : Dynamic; - // Remaining rows and columns at compile-time: - static const int RRows = SizeAtCompileTime==2 ? 1 : Dynamic; - static const int RCols = SizeAtCompileTime==2 ? 1 : Dynamic; - typedef Matrix<Scalar, ActualSizeAtCompileTime, ActualSizeAtCompileTime, StorageOrder> MatrixType; - typedef Ref<MatrixType> MatrixTypeRef; - typedef Ref<Matrix<Scalar, Dynamic, Dynamic, StorageOrder> > BlockType; - typedef typename MatrixType::RealScalar RealScalar; - - /** \internal performs the LU decomposition in-place of the matrix \a lu - * using an unblocked algorithm. - * - * In addition, this function returns the row transpositions in the - * vector \a row_transpositions which must have a size equal to the number - * of columns of the matrix \a lu, and an integer \a nb_transpositions - * which returns the actual number of transpositions. - * - * \returns The index of the first pivot which is exactly zero if any, or a negative number otherwise. - */ - static Index unblocked_lu(MatrixTypeRef& lu, PivIndex* row_transpositions, PivIndex& nb_transpositions) - { - typedef scalar_score_coeff_op<Scalar> Scoring; - typedef typename Scoring::result_type Score; - const Index rows = lu.rows(); - const Index cols = lu.cols(); - const Index size = (std::min)(rows,cols); - // For small compile-time matrices it is worth processing the last row separately: - // speedup: +100% for 2x2, +10% for others. - const Index endk = UnBlockedAtCompileTime ? size-1 : size; - nb_transpositions = 0; - Index first_zero_pivot = -1; - for(Index k = 0; k < endk; ++k) - { - int rrows = internal::convert_index<int>(rows-k-1); - int rcols = internal::convert_index<int>(cols-k-1); - - Index row_of_biggest_in_col; - Score biggest_in_corner - = lu.col(k).tail(rows-k).unaryExpr(Scoring()).maxCoeff(&row_of_biggest_in_col); - row_of_biggest_in_col += k; - - row_transpositions[k] = PivIndex(row_of_biggest_in_col); - - if(biggest_in_corner != Score(0)) - { - if(k != row_of_biggest_in_col) - { - lu.row(k).swap(lu.row(row_of_biggest_in_col)); - ++nb_transpositions; - } - - lu.col(k).tail(fix<RRows>(rrows)) /= lu.coeff(k,k); - } - else if(first_zero_pivot==-1) - { - // the pivot is exactly zero, we record the index of the first pivot which is exactly 0, - // and continue the factorization such we still have A = PLU - first_zero_pivot = k; - } - - if(k<rows-1) - lu.bottomRightCorner(fix<RRows>(rrows),fix<RCols>(rcols)).noalias() -= lu.col(k).tail(fix<RRows>(rrows)) * lu.row(k).tail(fix<RCols>(rcols)); - } - - // special handling of the last entry - if(UnBlockedAtCompileTime) - { - Index k = endk; - row_transpositions[k] = PivIndex(k); - if (Scoring()(lu(k, k)) == Score(0) && first_zero_pivot == -1) - first_zero_pivot = k; - } - - return first_zero_pivot; - } - - /** \internal performs the LU decomposition in-place of the matrix represented - * by the variables \a rows, \a cols, \a lu_data, and \a lu_stride using a - * recursive, blocked algorithm. - * - * In addition, this function returns the row transpositions in the - * vector \a row_transpositions which must have a size equal to the number - * of columns of the matrix \a lu, and an integer \a nb_transpositions - * which returns the actual number of transpositions. - * - * \returns The index of the first pivot which is exactly zero if any, or a negative number otherwise. - * - * \note This very low level interface using pointers, etc. is to: - * 1 - reduce the number of instantiations to the strict minimum - * 2 - avoid infinite recursion of the instantiations with Block<Block<Block<...> > > - */ - static Index blocked_lu(Index rows, Index cols, Scalar* lu_data, Index luStride, PivIndex* row_transpositions, PivIndex& nb_transpositions, Index maxBlockSize=256) - { - MatrixTypeRef lu = MatrixType::Map(lu_data,rows, cols, OuterStride<>(luStride)); - - const Index size = (std::min)(rows,cols); - - // if the matrix is too small, no blocking: - if(UnBlockedAtCompileTime || size<=UnBlockedBound) - { - return unblocked_lu(lu, row_transpositions, nb_transpositions); - } - - // automatically adjust the number of subdivisions to the size - // of the matrix so that there is enough sub blocks: - Index blockSize; - { - blockSize = size/8; - blockSize = (blockSize/16)*16; - blockSize = (std::min)((std::max)(blockSize,Index(8)), maxBlockSize); - } - - nb_transpositions = 0; - Index first_zero_pivot = -1; - for(Index k = 0; k < size; k+=blockSize) - { - Index bs = (std::min)(size-k,blockSize); // actual size of the block - Index trows = rows - k - bs; // trailing rows - Index tsize = size - k - bs; // trailing size - - // partition the matrix: - // A00 | A01 | A02 - // lu = A_0 | A_1 | A_2 = A10 | A11 | A12 - // A20 | A21 | A22 - BlockType A_0 = lu.block(0,0,rows,k); - BlockType A_2 = lu.block(0,k+bs,rows,tsize); - BlockType A11 = lu.block(k,k,bs,bs); - BlockType A12 = lu.block(k,k+bs,bs,tsize); - BlockType A21 = lu.block(k+bs,k,trows,bs); - BlockType A22 = lu.block(k+bs,k+bs,trows,tsize); - - PivIndex nb_transpositions_in_panel; - // recursively call the blocked LU algorithm on [A11^T A21^T]^T - // with a very small blocking size: - Index ret = blocked_lu(trows+bs, bs, &lu.coeffRef(k,k), luStride, - row_transpositions+k, nb_transpositions_in_panel, 16); - if(ret>=0 && first_zero_pivot==-1) - first_zero_pivot = k+ret; - - nb_transpositions += nb_transpositions_in_panel; - // update permutations and apply them to A_0 - for(Index i=k; i<k+bs; ++i) - { - Index piv = (row_transpositions[i] += internal::convert_index<PivIndex>(k)); - A_0.row(i).swap(A_0.row(piv)); - } - - if(trows) - { - // apply permutations to A_2 - for(Index i=k;i<k+bs; ++i) - A_2.row(i).swap(A_2.row(row_transpositions[i])); - - // A12 = A11^-1 A12 - A11.template triangularView<UnitLower>().solveInPlace(A12); - - A22.noalias() -= A21 * A12; - } - } - return first_zero_pivot; - } -}; - -/** \internal performs the LU decomposition with partial pivoting in-place. - */ -template<typename MatrixType, typename TranspositionType> -void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, typename TranspositionType::StorageIndex& nb_transpositions) -{ - eigen_assert(lu.cols() == row_transpositions.size()); - eigen_assert((&row_transpositions.coeffRef(1)-&row_transpositions.coeffRef(0)) == 1); - - partial_lu_impl - < typename MatrixType::Scalar, MatrixType::Flags&RowMajorBit?RowMajor:ColMajor, - typename TranspositionType::StorageIndex, - EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::RowsAtCompileTime,MatrixType::ColsAtCompileTime)> - ::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpositions.coeffRef(0), nb_transpositions); -} - -} // end namespace internal - -template<typename MatrixType> -void PartialPivLU<MatrixType>::compute() -{ - check_template_parameters(); - - // the row permutation is stored as int indices, so just to be sure: - eigen_assert(m_lu.rows()<NumTraits<int>::highest()); - - if(m_lu.cols()>0) - m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff(); - else - m_l1_norm = RealScalar(0); - - eigen_assert(m_lu.rows() == m_lu.cols() && "PartialPivLU is only for square (and moreover invertible) matrices"); - const Index size = m_lu.rows(); - - m_rowsTranspositions.resize(size); - - typename TranspositionType::StorageIndex nb_transpositions; - internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions); - m_det_p = (nb_transpositions%2) ? -1 : 1; - - m_p = m_rowsTranspositions; - - m_isInitialized = true; -} - -template<typename MatrixType> -typename PartialPivLU<MatrixType>::Scalar PartialPivLU<MatrixType>::determinant() const -{ - eigen_assert(m_isInitialized && "PartialPivLU is not initialized."); - return Scalar(m_det_p) * m_lu.diagonal().prod(); -} - -/** \returns the matrix represented by the decomposition, - * i.e., it returns the product: P^{-1} L U. - * This function is provided for debug purpose. */ -template<typename MatrixType> -MatrixType PartialPivLU<MatrixType>::reconstructedMatrix() const -{ - eigen_assert(m_isInitialized && "LU is not initialized."); - // LU - MatrixType res = m_lu.template triangularView<UnitLower>().toDenseMatrix() - * m_lu.template triangularView<Upper>(); - - // P^{-1}(LU) - res = m_p.inverse() * res; - - return res; -} - -/***** Implementation details *****************************************************/ - -namespace internal { - -/***** Implementation of inverse() *****************************************************/ -template<typename DstXprType, typename MatrixType> -struct Assignment<DstXprType, Inverse<PartialPivLU<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename PartialPivLU<MatrixType>::Scalar>, Dense2Dense> -{ - typedef PartialPivLU<MatrixType> LuType; - typedef Inverse<LuType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename LuType::Scalar> &) - { - dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols())); - } -}; -} // end namespace internal - -/******** MatrixBase methods *******/ - -/** \lu_module - * - * \return the partial-pivoting LU decomposition of \c *this. - * - * \sa class PartialPivLU - */ -template<typename Derived> -inline const PartialPivLU<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::partialPivLu() const -{ - return PartialPivLU<PlainObject>(eval()); -} - -/** \lu_module - * - * Synonym of partialPivLu(). - * - * \return the partial-pivoting LU decomposition of \c *this. - * - * \sa class PartialPivLU - */ -template<typename Derived> -inline const PartialPivLU<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::lu() const -{ - return PartialPivLU<PlainObject>(eval()); -} - -} // end namespace Eigen - -#endif // EIGEN_PARTIALLU_H diff --git a/external/eigen/include/eigen3/Eigen/src/LU/PartialPivLU_LAPACKE.h b/external/eigen/include/eigen3/Eigen/src/LU/PartialPivLU_LAPACKE.h deleted file mode 100644 index 755168a9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/LU/PartialPivLU_LAPACKE.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to LAPACKe - * LU decomposition with partial pivoting based on LAPACKE_?getrf function. - ******************************************************************************** -*/ - -#ifndef EIGEN_PARTIALLU_LAPACK_H -#define EIGEN_PARTIALLU_LAPACK_H - -namespace Eigen { - -namespace internal { - -/** \internal Specialization for the data types supported by LAPACKe */ - -#define EIGEN_LAPACKE_LU_PARTPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \ -template<int StorageOrder> \ -struct partial_lu_impl<EIGTYPE, StorageOrder, lapack_int> \ -{ \ - /* \internal performs the LU decomposition in-place of the matrix represented */ \ - static lapack_int blocked_lu(Index rows, Index cols, EIGTYPE* lu_data, Index luStride, lapack_int* row_transpositions, lapack_int& nb_transpositions, lapack_int maxBlockSize=256) \ - { \ - EIGEN_UNUSED_VARIABLE(maxBlockSize);\ - lapack_int matrix_order, first_zero_pivot; \ - lapack_int m, n, lda, *ipiv, info; \ - EIGTYPE* a; \ -/* Set up parameters for ?getrf */ \ - matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ - lda = convert_index<lapack_int>(luStride); \ - a = lu_data; \ - ipiv = row_transpositions; \ - m = convert_index<lapack_int>(rows); \ - n = convert_index<lapack_int>(cols); \ - nb_transpositions = 0; \ -\ - info = LAPACKE_##LAPACKE_PREFIX##getrf( matrix_order, m, n, (LAPACKE_TYPE*)a, lda, ipiv ); \ -\ - for(int i=0;i<m;i++) { ipiv[i]--; if (ipiv[i]!=i) nb_transpositions++; } \ -\ - eigen_assert(info >= 0); \ -/* something should be done with nb_transpositions */ \ -\ - first_zero_pivot = info; \ - return first_zero_pivot; \ - } \ -}; - -EIGEN_LAPACKE_LU_PARTPIV(double, double, d) -EIGEN_LAPACKE_LU_PARTPIV(float, float, s) -EIGEN_LAPACKE_LU_PARTPIV(dcomplex, lapack_complex_double, z) -EIGEN_LAPACKE_LU_PARTPIV(scomplex, lapack_complex_float, c) - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_PARTIALLU_LAPACK_H diff --git a/external/eigen/include/eigen3/Eigen/src/LU/arch/Inverse_SSE.h b/external/eigen/include/eigen3/Eigen/src/LU/arch/Inverse_SSE.h deleted file mode 100644 index 4dce2ef2..00000000 --- a/external/eigen/include/eigen3/Eigen/src/LU/arch/Inverse_SSE.h +++ /dev/null @@ -1,338 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2001 Intel Corporation -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// The SSE code for the 4x4 float and double matrix inverse in this file -// comes from the following Intel's library: -// http://software.intel.com/en-us/articles/optimized-matrix-library-for-use-with-the-intel-pentiumr-4-processors-sse2-instructions/ -// -// Here is the respective copyright and license statement: -// -// Copyright (c) 2001 Intel Corporation. -// -// Permition is granted to use, copy, distribute and prepare derivative works -// of this library for any purpose and without fee, provided, that the above -// copyright notice and this statement appear in all copies. -// Intel makes no representations about the suitability of this software for -// any purpose, and specifically disclaims all warranties. -// See LEGAL.TXT for all the legal information. - -#ifndef EIGEN_INVERSE_SSE_H -#define EIGEN_INVERSE_SSE_H - -namespace Eigen { - -namespace internal { - -template<typename MatrixType, typename ResultType> -struct compute_inverse_size4<Architecture::SSE, float, MatrixType, ResultType> -{ - enum { - MatrixAlignment = traits<MatrixType>::Alignment, - ResultAlignment = traits<ResultType>::Alignment, - StorageOrdersMatch = (MatrixType::Flags&RowMajorBit) == (ResultType::Flags&RowMajorBit) - }; - typedef typename conditional<(MatrixType::Flags&LinearAccessBit),MatrixType const &,typename MatrixType::PlainObject>::type ActualMatrixType; - - static void run(const MatrixType& mat, ResultType& result) - { - ActualMatrixType matrix(mat); - const Packet4f p4f_sign_PNNP = _mm_castsi128_ps(_mm_set_epi32(0x00000000, 0x80000000, 0x80000000, 0x00000000)); - - // Load the full matrix into registers - __m128 _L1 = matrix.template packet<MatrixAlignment>( 0); - __m128 _L2 = matrix.template packet<MatrixAlignment>( 4); - __m128 _L3 = matrix.template packet<MatrixAlignment>( 8); - __m128 _L4 = matrix.template packet<MatrixAlignment>(12); - - // The inverse is calculated using "Divide and Conquer" technique. The - // original matrix is divide into four 2x2 sub-matrices. Since each - // register holds four matrix element, the smaller matrices are - // represented as a registers. Hence we get a better locality of the - // calculations. - - __m128 A, B, C, D; // the four sub-matrices - if(!StorageOrdersMatch) - { - A = _mm_unpacklo_ps(_L1, _L2); - B = _mm_unpacklo_ps(_L3, _L4); - C = _mm_unpackhi_ps(_L1, _L2); - D = _mm_unpackhi_ps(_L3, _L4); - } - else - { - A = _mm_movelh_ps(_L1, _L2); - B = _mm_movehl_ps(_L2, _L1); - C = _mm_movelh_ps(_L3, _L4); - D = _mm_movehl_ps(_L4, _L3); - } - - __m128 iA, iB, iC, iD, // partial inverse of the sub-matrices - DC, AB; - __m128 dA, dB, dC, dD; // determinant of the sub-matrices - __m128 det, d, d1, d2; - __m128 rd; // reciprocal of the determinant - - // AB = A# * B - AB = _mm_mul_ps(_mm_shuffle_ps(A,A,0x0F), B); - AB = _mm_sub_ps(AB,_mm_mul_ps(_mm_shuffle_ps(A,A,0xA5), _mm_shuffle_ps(B,B,0x4E))); - // DC = D# * C - DC = _mm_mul_ps(_mm_shuffle_ps(D,D,0x0F), C); - DC = _mm_sub_ps(DC,_mm_mul_ps(_mm_shuffle_ps(D,D,0xA5), _mm_shuffle_ps(C,C,0x4E))); - - // dA = |A| - dA = _mm_mul_ps(_mm_shuffle_ps(A, A, 0x5F),A); - dA = _mm_sub_ss(dA, _mm_movehl_ps(dA,dA)); - // dB = |B| - dB = _mm_mul_ps(_mm_shuffle_ps(B, B, 0x5F),B); - dB = _mm_sub_ss(dB, _mm_movehl_ps(dB,dB)); - - // dC = |C| - dC = _mm_mul_ps(_mm_shuffle_ps(C, C, 0x5F),C); - dC = _mm_sub_ss(dC, _mm_movehl_ps(dC,dC)); - // dD = |D| - dD = _mm_mul_ps(_mm_shuffle_ps(D, D, 0x5F),D); - dD = _mm_sub_ss(dD, _mm_movehl_ps(dD,dD)); - - // d = trace(AB*DC) = trace(A#*B*D#*C) - d = _mm_mul_ps(_mm_shuffle_ps(DC,DC,0xD8),AB); - - // iD = C*A#*B - iD = _mm_mul_ps(_mm_shuffle_ps(C,C,0xA0), _mm_movelh_ps(AB,AB)); - iD = _mm_add_ps(iD,_mm_mul_ps(_mm_shuffle_ps(C,C,0xF5), _mm_movehl_ps(AB,AB))); - // iA = B*D#*C - iA = _mm_mul_ps(_mm_shuffle_ps(B,B,0xA0), _mm_movelh_ps(DC,DC)); - iA = _mm_add_ps(iA,_mm_mul_ps(_mm_shuffle_ps(B,B,0xF5), _mm_movehl_ps(DC,DC))); - - // d = trace(AB*DC) = trace(A#*B*D#*C) [continue] - d = _mm_add_ps(d, _mm_movehl_ps(d, d)); - d = _mm_add_ss(d, _mm_shuffle_ps(d, d, 1)); - d1 = _mm_mul_ss(dA,dD); - d2 = _mm_mul_ss(dB,dC); - - // iD = D*|A| - C*A#*B - iD = _mm_sub_ps(_mm_mul_ps(D,_mm_shuffle_ps(dA,dA,0)), iD); - - // iA = A*|D| - B*D#*C; - iA = _mm_sub_ps(_mm_mul_ps(A,_mm_shuffle_ps(dD,dD,0)), iA); - - // det = |A|*|D| + |B|*|C| - trace(A#*B*D#*C) - det = _mm_sub_ss(_mm_add_ss(d1,d2),d); - rd = _mm_div_ss(_mm_set_ss(1.0f), det); - -// #ifdef ZERO_SINGULAR -// rd = _mm_and_ps(_mm_cmpneq_ss(det,_mm_setzero_ps()), rd); -// #endif - - // iB = D * (A#B)# = D*B#*A - iB = _mm_mul_ps(D, _mm_shuffle_ps(AB,AB,0x33)); - iB = _mm_sub_ps(iB, _mm_mul_ps(_mm_shuffle_ps(D,D,0xB1), _mm_shuffle_ps(AB,AB,0x66))); - // iC = A * (D#C)# = A*C#*D - iC = _mm_mul_ps(A, _mm_shuffle_ps(DC,DC,0x33)); - iC = _mm_sub_ps(iC, _mm_mul_ps(_mm_shuffle_ps(A,A,0xB1), _mm_shuffle_ps(DC,DC,0x66))); - - rd = _mm_shuffle_ps(rd,rd,0); - rd = _mm_xor_ps(rd, p4f_sign_PNNP); - - // iB = C*|B| - D*B#*A - iB = _mm_sub_ps(_mm_mul_ps(C,_mm_shuffle_ps(dB,dB,0)), iB); - - // iC = B*|C| - A*C#*D; - iC = _mm_sub_ps(_mm_mul_ps(B,_mm_shuffle_ps(dC,dC,0)), iC); - - // iX = iX / det - iA = _mm_mul_ps(rd,iA); - iB = _mm_mul_ps(rd,iB); - iC = _mm_mul_ps(rd,iC); - iD = _mm_mul_ps(rd,iD); - - Index res_stride = result.outerStride(); - float* res = result.data(); - pstoret<float, Packet4f, ResultAlignment>(res+0, _mm_shuffle_ps(iA,iB,0x77)); - pstoret<float, Packet4f, ResultAlignment>(res+res_stride, _mm_shuffle_ps(iA,iB,0x22)); - pstoret<float, Packet4f, ResultAlignment>(res+2*res_stride, _mm_shuffle_ps(iC,iD,0x77)); - pstoret<float, Packet4f, ResultAlignment>(res+3*res_stride, _mm_shuffle_ps(iC,iD,0x22)); - } - -}; - -template<typename MatrixType, typename ResultType> -struct compute_inverse_size4<Architecture::SSE, double, MatrixType, ResultType> -{ - enum { - MatrixAlignment = traits<MatrixType>::Alignment, - ResultAlignment = traits<ResultType>::Alignment, - StorageOrdersMatch = (MatrixType::Flags&RowMajorBit) == (ResultType::Flags&RowMajorBit) - }; - typedef typename conditional<(MatrixType::Flags&LinearAccessBit),MatrixType const &,typename MatrixType::PlainObject>::type ActualMatrixType; - - static void run(const MatrixType& mat, ResultType& result) - { - ActualMatrixType matrix(mat); - const __m128d _Sign_NP = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0)); - const __m128d _Sign_PN = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0)); - - // The inverse is calculated using "Divide and Conquer" technique. The - // original matrix is divide into four 2x2 sub-matrices. Since each - // register of the matrix holds two elements, the smaller matrices are - // consisted of two registers. Hence we get a better locality of the - // calculations. - - // the four sub-matrices - __m128d A1, A2, B1, B2, C1, C2, D1, D2; - - if(StorageOrdersMatch) - { - A1 = matrix.template packet<MatrixAlignment>( 0); B1 = matrix.template packet<MatrixAlignment>( 2); - A2 = matrix.template packet<MatrixAlignment>( 4); B2 = matrix.template packet<MatrixAlignment>( 6); - C1 = matrix.template packet<MatrixAlignment>( 8); D1 = matrix.template packet<MatrixAlignment>(10); - C2 = matrix.template packet<MatrixAlignment>(12); D2 = matrix.template packet<MatrixAlignment>(14); - } - else - { - __m128d tmp; - A1 = matrix.template packet<MatrixAlignment>( 0); C1 = matrix.template packet<MatrixAlignment>( 2); - A2 = matrix.template packet<MatrixAlignment>( 4); C2 = matrix.template packet<MatrixAlignment>( 6); - tmp = A1; - A1 = _mm_unpacklo_pd(A1,A2); - A2 = _mm_unpackhi_pd(tmp,A2); - tmp = C1; - C1 = _mm_unpacklo_pd(C1,C2); - C2 = _mm_unpackhi_pd(tmp,C2); - - B1 = matrix.template packet<MatrixAlignment>( 8); D1 = matrix.template packet<MatrixAlignment>(10); - B2 = matrix.template packet<MatrixAlignment>(12); D2 = matrix.template packet<MatrixAlignment>(14); - tmp = B1; - B1 = _mm_unpacklo_pd(B1,B2); - B2 = _mm_unpackhi_pd(tmp,B2); - tmp = D1; - D1 = _mm_unpacklo_pd(D1,D2); - D2 = _mm_unpackhi_pd(tmp,D2); - } - - __m128d iA1, iA2, iB1, iB2, iC1, iC2, iD1, iD2, // partial invese of the sub-matrices - DC1, DC2, AB1, AB2; - __m128d dA, dB, dC, dD; // determinant of the sub-matrices - __m128d det, d1, d2, rd; - - // dA = |A| - dA = _mm_shuffle_pd(A2, A2, 1); - dA = _mm_mul_pd(A1, dA); - dA = _mm_sub_sd(dA, _mm_shuffle_pd(dA,dA,3)); - // dB = |B| - dB = _mm_shuffle_pd(B2, B2, 1); - dB = _mm_mul_pd(B1, dB); - dB = _mm_sub_sd(dB, _mm_shuffle_pd(dB,dB,3)); - - // AB = A# * B - AB1 = _mm_mul_pd(B1, _mm_shuffle_pd(A2,A2,3)); - AB2 = _mm_mul_pd(B2, _mm_shuffle_pd(A1,A1,0)); - AB1 = _mm_sub_pd(AB1, _mm_mul_pd(B2, _mm_shuffle_pd(A1,A1,3))); - AB2 = _mm_sub_pd(AB2, _mm_mul_pd(B1, _mm_shuffle_pd(A2,A2,0))); - - // dC = |C| - dC = _mm_shuffle_pd(C2, C2, 1); - dC = _mm_mul_pd(C1, dC); - dC = _mm_sub_sd(dC, _mm_shuffle_pd(dC,dC,3)); - // dD = |D| - dD = _mm_shuffle_pd(D2, D2, 1); - dD = _mm_mul_pd(D1, dD); - dD = _mm_sub_sd(dD, _mm_shuffle_pd(dD,dD,3)); - - // DC = D# * C - DC1 = _mm_mul_pd(C1, _mm_shuffle_pd(D2,D2,3)); - DC2 = _mm_mul_pd(C2, _mm_shuffle_pd(D1,D1,0)); - DC1 = _mm_sub_pd(DC1, _mm_mul_pd(C2, _mm_shuffle_pd(D1,D1,3))); - DC2 = _mm_sub_pd(DC2, _mm_mul_pd(C1, _mm_shuffle_pd(D2,D2,0))); - - // rd = trace(AB*DC) = trace(A#*B*D#*C) - d1 = _mm_mul_pd(AB1, _mm_shuffle_pd(DC1, DC2, 0)); - d2 = _mm_mul_pd(AB2, _mm_shuffle_pd(DC1, DC2, 3)); - rd = _mm_add_pd(d1, d2); - rd = _mm_add_sd(rd, _mm_shuffle_pd(rd, rd,3)); - - // iD = C*A#*B - iD1 = _mm_mul_pd(AB1, _mm_shuffle_pd(C1,C1,0)); - iD2 = _mm_mul_pd(AB1, _mm_shuffle_pd(C2,C2,0)); - iD1 = _mm_add_pd(iD1, _mm_mul_pd(AB2, _mm_shuffle_pd(C1,C1,3))); - iD2 = _mm_add_pd(iD2, _mm_mul_pd(AB2, _mm_shuffle_pd(C2,C2,3))); - - // iA = B*D#*C - iA1 = _mm_mul_pd(DC1, _mm_shuffle_pd(B1,B1,0)); - iA2 = _mm_mul_pd(DC1, _mm_shuffle_pd(B2,B2,0)); - iA1 = _mm_add_pd(iA1, _mm_mul_pd(DC2, _mm_shuffle_pd(B1,B1,3))); - iA2 = _mm_add_pd(iA2, _mm_mul_pd(DC2, _mm_shuffle_pd(B2,B2,3))); - - // iD = D*|A| - C*A#*B - dA = _mm_shuffle_pd(dA,dA,0); - iD1 = _mm_sub_pd(_mm_mul_pd(D1, dA), iD1); - iD2 = _mm_sub_pd(_mm_mul_pd(D2, dA), iD2); - - // iA = A*|D| - B*D#*C; - dD = _mm_shuffle_pd(dD,dD,0); - iA1 = _mm_sub_pd(_mm_mul_pd(A1, dD), iA1); - iA2 = _mm_sub_pd(_mm_mul_pd(A2, dD), iA2); - - d1 = _mm_mul_sd(dA, dD); - d2 = _mm_mul_sd(dB, dC); - - // iB = D * (A#B)# = D*B#*A - iB1 = _mm_mul_pd(D1, _mm_shuffle_pd(AB2,AB1,1)); - iB2 = _mm_mul_pd(D2, _mm_shuffle_pd(AB2,AB1,1)); - iB1 = _mm_sub_pd(iB1, _mm_mul_pd(_mm_shuffle_pd(D1,D1,1), _mm_shuffle_pd(AB2,AB1,2))); - iB2 = _mm_sub_pd(iB2, _mm_mul_pd(_mm_shuffle_pd(D2,D2,1), _mm_shuffle_pd(AB2,AB1,2))); - - // det = |A|*|D| + |B|*|C| - trace(A#*B*D#*C) - det = _mm_add_sd(d1, d2); - det = _mm_sub_sd(det, rd); - - // iC = A * (D#C)# = A*C#*D - iC1 = _mm_mul_pd(A1, _mm_shuffle_pd(DC2,DC1,1)); - iC2 = _mm_mul_pd(A2, _mm_shuffle_pd(DC2,DC1,1)); - iC1 = _mm_sub_pd(iC1, _mm_mul_pd(_mm_shuffle_pd(A1,A1,1), _mm_shuffle_pd(DC2,DC1,2))); - iC2 = _mm_sub_pd(iC2, _mm_mul_pd(_mm_shuffle_pd(A2,A2,1), _mm_shuffle_pd(DC2,DC1,2))); - - rd = _mm_div_sd(_mm_set_sd(1.0), det); -// #ifdef ZERO_SINGULAR -// rd = _mm_and_pd(_mm_cmpneq_sd(det,_mm_setzero_pd()), rd); -// #endif - rd = _mm_shuffle_pd(rd,rd,0); - - // iB = C*|B| - D*B#*A - dB = _mm_shuffle_pd(dB,dB,0); - iB1 = _mm_sub_pd(_mm_mul_pd(C1, dB), iB1); - iB2 = _mm_sub_pd(_mm_mul_pd(C2, dB), iB2); - - d1 = _mm_xor_pd(rd, _Sign_PN); - d2 = _mm_xor_pd(rd, _Sign_NP); - - // iC = B*|C| - A*C#*D; - dC = _mm_shuffle_pd(dC,dC,0); - iC1 = _mm_sub_pd(_mm_mul_pd(B1, dC), iC1); - iC2 = _mm_sub_pd(_mm_mul_pd(B2, dC), iC2); - - Index res_stride = result.outerStride(); - double* res = result.data(); - pstoret<double, Packet2d, ResultAlignment>(res+0, _mm_mul_pd(_mm_shuffle_pd(iA2, iA1, 3), d1)); - pstoret<double, Packet2d, ResultAlignment>(res+res_stride, _mm_mul_pd(_mm_shuffle_pd(iA2, iA1, 0), d2)); - pstoret<double, Packet2d, ResultAlignment>(res+2, _mm_mul_pd(_mm_shuffle_pd(iB2, iB1, 3), d1)); - pstoret<double, Packet2d, ResultAlignment>(res+res_stride+2, _mm_mul_pd(_mm_shuffle_pd(iB2, iB1, 0), d2)); - pstoret<double, Packet2d, ResultAlignment>(res+2*res_stride, _mm_mul_pd(_mm_shuffle_pd(iC2, iC1, 3), d1)); - pstoret<double, Packet2d, ResultAlignment>(res+3*res_stride, _mm_mul_pd(_mm_shuffle_pd(iC2, iC1, 0), d2)); - pstoret<double, Packet2d, ResultAlignment>(res+2*res_stride+2,_mm_mul_pd(_mm_shuffle_pd(iD2, iD1, 3), d1)); - pstoret<double, Packet2d, ResultAlignment>(res+3*res_stride+2,_mm_mul_pd(_mm_shuffle_pd(iD2, iD1, 0), d2)); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_INVERSE_SSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/MetisSupport/MetisSupport.h b/external/eigen/include/eigen3/Eigen/src/MetisSupport/MetisSupport.h deleted file mode 100644 index 4c15304a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/MetisSupport/MetisSupport.h +++ /dev/null @@ -1,137 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -#ifndef METIS_SUPPORT_H -#define METIS_SUPPORT_H - -namespace Eigen { -/** - * Get the fill-reducing ordering from the METIS package - * - * If A is the original matrix and Ap is the permuted matrix, - * the fill-reducing permutation is defined as follows : - * Row (column) i of A is the matperm(i) row (column) of Ap. - * WARNING: As computed by METIS, this corresponds to the vector iperm (instead of perm) - */ -template <typename StorageIndex> -class MetisOrdering -{ -public: - typedef PermutationMatrix<Dynamic,Dynamic,StorageIndex> PermutationType; - typedef Matrix<StorageIndex,Dynamic,1> IndexVector; - - template <typename MatrixType> - void get_symmetrized_graph(const MatrixType& A) - { - Index m = A.cols(); - eigen_assert((A.rows() == A.cols()) && "ONLY FOR SQUARED MATRICES"); - // Get the transpose of the input matrix - MatrixType At = A.transpose(); - // Get the number of nonzeros elements in each row/col of At+A - Index TotNz = 0; - IndexVector visited(m); - visited.setConstant(-1); - for (StorageIndex j = 0; j < m; j++) - { - // Compute the union structure of of A(j,:) and At(j,:) - visited(j) = j; // Do not include the diagonal element - // Get the nonzeros in row/column j of A - for (typename MatrixType::InnerIterator it(A, j); it; ++it) - { - Index idx = it.index(); // Get the row index (for column major) or column index (for row major) - if (visited(idx) != j ) - { - visited(idx) = j; - ++TotNz; - } - } - //Get the nonzeros in row/column j of At - for (typename MatrixType::InnerIterator it(At, j); it; ++it) - { - Index idx = it.index(); - if(visited(idx) != j) - { - visited(idx) = j; - ++TotNz; - } - } - } - // Reserve place for A + At - m_indexPtr.resize(m+1); - m_innerIndices.resize(TotNz); - - // Now compute the real adjacency list of each column/row - visited.setConstant(-1); - StorageIndex CurNz = 0; - for (StorageIndex j = 0; j < m; j++) - { - m_indexPtr(j) = CurNz; - - visited(j) = j; // Do not include the diagonal element - // Add the pattern of row/column j of A to A+At - for (typename MatrixType::InnerIterator it(A,j); it; ++it) - { - StorageIndex idx = it.index(); // Get the row index (for column major) or column index (for row major) - if (visited(idx) != j ) - { - visited(idx) = j; - m_innerIndices(CurNz) = idx; - CurNz++; - } - } - //Add the pattern of row/column j of At to A+At - for (typename MatrixType::InnerIterator it(At, j); it; ++it) - { - StorageIndex idx = it.index(); - if(visited(idx) != j) - { - visited(idx) = j; - m_innerIndices(CurNz) = idx; - ++CurNz; - } - } - } - m_indexPtr(m) = CurNz; - } - - template <typename MatrixType> - void operator() (const MatrixType& A, PermutationType& matperm) - { - StorageIndex m = internal::convert_index<StorageIndex>(A.cols()); // must be StorageIndex, because it is passed by address to METIS - IndexVector perm(m),iperm(m); - // First, symmetrize the matrix graph. - get_symmetrized_graph(A); - int output_error; - - // Call the fill-reducing routine from METIS - output_error = METIS_NodeND(&m, m_indexPtr.data(), m_innerIndices.data(), NULL, NULL, perm.data(), iperm.data()); - - if(output_error != METIS_OK) - { - //FIXME The ordering interface should define a class of possible errors - std::cerr << "ERROR WHILE CALLING THE METIS PACKAGE \n"; - return; - } - - // Get the fill-reducing permutation - //NOTE: If Ap is the permuted matrix then perm and iperm vectors are defined as follows - // Row (column) i of Ap is the perm(i) row(column) of A, and row (column) i of A is the iperm(i) row(column) of Ap - - matperm.resize(m); - for (int j = 0; j < m; j++) - matperm.indices()(iperm(j)) = j; - - } - - protected: - IndexVector m_indexPtr; // Pointer to the adjacenccy list of each row/column - IndexVector m_innerIndices; // Adjacency list -}; - -}// end namespace eigen -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Amd.h b/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Amd.h deleted file mode 100644 index 7ca3f33b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Amd.h +++ /dev/null @@ -1,435 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* -NOTE: this routine has been adapted from the CSparse library: - -Copyright (c) 2006, Timothy A. Davis. -http://www.suitesparse.com - -The author of CSparse, Timothy A. Davis., has executed a license with Google LLC -to permit distribution of this code and derivative works as part of Eigen under -the Mozilla Public License v. 2.0, as stated at the top of this file. -*/ - -#ifndef EIGEN_SPARSE_AMD_H -#define EIGEN_SPARSE_AMD_H - -namespace Eigen { - -namespace internal { - -template<typename T> inline T amd_flip(const T& i) { return -i-2; } -template<typename T> inline T amd_unflip(const T& i) { return i<0 ? amd_flip(i) : i; } -template<typename T0, typename T1> inline bool amd_marked(const T0* w, const T1& j) { return w[j]<0; } -template<typename T0, typename T1> inline void amd_mark(const T0* w, const T1& j) { return w[j] = amd_flip(w[j]); } - -/* clear w */ -template<typename StorageIndex> -static StorageIndex cs_wclear (StorageIndex mark, StorageIndex lemax, StorageIndex *w, StorageIndex n) -{ - StorageIndex k; - if(mark < 2 || (mark + lemax < 0)) - { - for(k = 0; k < n; k++) - if(w[k] != 0) - w[k] = 1; - mark = 2; - } - return (mark); /* at this point, w[0..n-1] < mark holds */ -} - -/* depth-first search and postorder of a tree rooted at node j */ -template<typename StorageIndex> -StorageIndex cs_tdfs(StorageIndex j, StorageIndex k, StorageIndex *head, const StorageIndex *next, StorageIndex *post, StorageIndex *stack) -{ - StorageIndex i, p, top = 0; - if(!head || !next || !post || !stack) return (-1); /* check inputs */ - stack[0] = j; /* place j on the stack */ - while (top >= 0) /* while (stack is not empty) */ - { - p = stack[top]; /* p = top of stack */ - i = head[p]; /* i = youngest child of p */ - if(i == -1) - { - top--; /* p has no unordered children left */ - post[k++] = p; /* node p is the kth postordered node */ - } - else - { - head[p] = next[i]; /* remove i from children of p */ - stack[++top] = i; /* start dfs on child node i */ - } - } - return k; -} - - -/** \internal - * \ingroup OrderingMethods_Module - * Approximate minimum degree ordering algorithm. - * - * \param[in] C the input selfadjoint matrix stored in compressed column major format. - * \param[out] perm the permutation P reducing the fill-in of the input matrix \a C - * - * Note that the input matrix \a C must be complete, that is both the upper and lower parts have to be stored, as well as the diagonal entries. - * On exit the values of C are destroyed */ -template<typename Scalar, typename StorageIndex> -void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,StorageIndex>& C, PermutationMatrix<Dynamic,Dynamic,StorageIndex>& perm) -{ - using std::sqrt; - - StorageIndex d, dk, dext, lemax = 0, e, elenk, eln, i, j, k, k1, - k2, k3, jlast, ln, dense, nzmax, mindeg = 0, nvi, nvj, nvk, mark, wnvi, - ok, nel = 0, p, p1, p2, p3, p4, pj, pk, pk1, pk2, pn, q, t, h; - - StorageIndex n = StorageIndex(C.cols()); - dense = std::max<StorageIndex> (16, StorageIndex(10 * sqrt(double(n)))); /* find dense threshold */ - dense = (std::min)(n-2, dense); - - StorageIndex cnz = StorageIndex(C.nonZeros()); - perm.resize(n+1); - t = cnz + cnz/5 + 2*n; /* add elbow room to C */ - C.resizeNonZeros(t); - - // get workspace - ei_declare_aligned_stack_constructed_variable(StorageIndex,W,8*(n+1),0); - StorageIndex* len = W; - StorageIndex* nv = W + (n+1); - StorageIndex* next = W + 2*(n+1); - StorageIndex* head = W + 3*(n+1); - StorageIndex* elen = W + 4*(n+1); - StorageIndex* degree = W + 5*(n+1); - StorageIndex* w = W + 6*(n+1); - StorageIndex* hhead = W + 7*(n+1); - StorageIndex* last = perm.indices().data(); /* use P as workspace for last */ - - /* --- Initialize quotient graph ---------------------------------------- */ - StorageIndex* Cp = C.outerIndexPtr(); - StorageIndex* Ci = C.innerIndexPtr(); - for(k = 0; k < n; k++) - len[k] = Cp[k+1] - Cp[k]; - len[n] = 0; - nzmax = t; - - for(i = 0; i <= n; i++) - { - head[i] = -1; // degree list i is empty - last[i] = -1; - next[i] = -1; - hhead[i] = -1; // hash list i is empty - nv[i] = 1; // node i is just one node - w[i] = 1; // node i is alive - elen[i] = 0; // Ek of node i is empty - degree[i] = len[i]; // degree of node i - } - mark = internal::cs_wclear<StorageIndex>(0, 0, w, n); /* clear w */ - - /* --- Initialize degree lists ------------------------------------------ */ - for(i = 0; i < n; i++) - { - bool has_diag = false; - for(p = Cp[i]; p<Cp[i+1]; ++p) - if(Ci[p]==i) - { - has_diag = true; - break; - } - - d = degree[i]; - if(d == 1 && has_diag) /* node i is empty */ - { - elen[i] = -2; /* element i is dead */ - nel++; - Cp[i] = -1; /* i is a root of assembly tree */ - w[i] = 0; - } - else if(d > dense || !has_diag) /* node i is dense or has no structural diagonal element */ - { - nv[i] = 0; /* absorb i into element n */ - elen[i] = -1; /* node i is dead */ - nel++; - Cp[i] = amd_flip (n); - nv[n]++; - } - else - { - if(head[d] != -1) last[head[d]] = i; - next[i] = head[d]; /* put node i in degree list d */ - head[d] = i; - } - } - - elen[n] = -2; /* n is a dead element */ - Cp[n] = -1; /* n is a root of assembly tree */ - w[n] = 0; /* n is a dead element */ - - while (nel < n) /* while (selecting pivots) do */ - { - /* --- Select node of minimum approximate degree -------------------- */ - for(k = -1; mindeg < n && (k = head[mindeg]) == -1; mindeg++) {} - if(next[k] != -1) last[next[k]] = -1; - head[mindeg] = next[k]; /* remove k from degree list */ - elenk = elen[k]; /* elenk = |Ek| */ - nvk = nv[k]; /* # of nodes k represents */ - nel += nvk; /* nv[k] nodes of A eliminated */ - - /* --- Garbage collection ------------------------------------------- */ - if(elenk > 0 && cnz + mindeg >= nzmax) - { - for(j = 0; j < n; j++) - { - if((p = Cp[j]) >= 0) /* j is a live node or element */ - { - Cp[j] = Ci[p]; /* save first entry of object */ - Ci[p] = amd_flip (j); /* first entry is now amd_flip(j) */ - } - } - for(q = 0, p = 0; p < cnz; ) /* scan all of memory */ - { - if((j = amd_flip (Ci[p++])) >= 0) /* found object j */ - { - Ci[q] = Cp[j]; /* restore first entry of object */ - Cp[j] = q++; /* new pointer to object j */ - for(k3 = 0; k3 < len[j]-1; k3++) Ci[q++] = Ci[p++]; - } - } - cnz = q; /* Ci[cnz...nzmax-1] now free */ - } - - /* --- Construct new element ---------------------------------------- */ - dk = 0; - nv[k] = -nvk; /* flag k as in Lk */ - p = Cp[k]; - pk1 = (elenk == 0) ? p : cnz; /* do in place if elen[k] == 0 */ - pk2 = pk1; - for(k1 = 1; k1 <= elenk + 1; k1++) - { - if(k1 > elenk) - { - e = k; /* search the nodes in k */ - pj = p; /* list of nodes starts at Ci[pj]*/ - ln = len[k] - elenk; /* length of list of nodes in k */ - } - else - { - e = Ci[p++]; /* search the nodes in e */ - pj = Cp[e]; - ln = len[e]; /* length of list of nodes in e */ - } - for(k2 = 1; k2 <= ln; k2++) - { - i = Ci[pj++]; - if((nvi = nv[i]) <= 0) continue; /* node i dead, or seen */ - dk += nvi; /* degree[Lk] += size of node i */ - nv[i] = -nvi; /* negate nv[i] to denote i in Lk*/ - Ci[pk2++] = i; /* place i in Lk */ - if(next[i] != -1) last[next[i]] = last[i]; - if(last[i] != -1) /* remove i from degree list */ - { - next[last[i]] = next[i]; - } - else - { - head[degree[i]] = next[i]; - } - } - if(e != k) - { - Cp[e] = amd_flip (k); /* absorb e into k */ - w[e] = 0; /* e is now a dead element */ - } - } - if(elenk != 0) cnz = pk2; /* Ci[cnz...nzmax] is free */ - degree[k] = dk; /* external degree of k - |Lk\i| */ - Cp[k] = pk1; /* element k is in Ci[pk1..pk2-1] */ - len[k] = pk2 - pk1; - elen[k] = -2; /* k is now an element */ - - /* --- Find set differences ----------------------------------------- */ - mark = internal::cs_wclear<StorageIndex>(mark, lemax, w, n); /* clear w if necessary */ - for(pk = pk1; pk < pk2; pk++) /* scan 1: find |Le\Lk| */ - { - i = Ci[pk]; - if((eln = elen[i]) <= 0) continue;/* skip if elen[i] empty */ - nvi = -nv[i]; /* nv[i] was negated */ - wnvi = mark - nvi; - for(p = Cp[i]; p <= Cp[i] + eln - 1; p++) /* scan Ei */ - { - e = Ci[p]; - if(w[e] >= mark) - { - w[e] -= nvi; /* decrement |Le\Lk| */ - } - else if(w[e] != 0) /* ensure e is a live element */ - { - w[e] = degree[e] + wnvi; /* 1st time e seen in scan 1 */ - } - } - } - - /* --- Degree update ------------------------------------------------ */ - for(pk = pk1; pk < pk2; pk++) /* scan2: degree update */ - { - i = Ci[pk]; /* consider node i in Lk */ - p1 = Cp[i]; - p2 = p1 + elen[i] - 1; - pn = p1; - for(h = 0, d = 0, p = p1; p <= p2; p++) /* scan Ei */ - { - e = Ci[p]; - if(w[e] != 0) /* e is an unabsorbed element */ - { - dext = w[e] - mark; /* dext = |Le\Lk| */ - if(dext > 0) - { - d += dext; /* sum up the set differences */ - Ci[pn++] = e; /* keep e in Ei */ - h += e; /* compute the hash of node i */ - } - else - { - Cp[e] = amd_flip (k); /* aggressive absorb. e->k */ - w[e] = 0; /* e is a dead element */ - } - } - } - elen[i] = pn - p1 + 1; /* elen[i] = |Ei| */ - p3 = pn; - p4 = p1 + len[i]; - for(p = p2 + 1; p < p4; p++) /* prune edges in Ai */ - { - j = Ci[p]; - if((nvj = nv[j]) <= 0) continue; /* node j dead or in Lk */ - d += nvj; /* degree(i) += |j| */ - Ci[pn++] = j; /* place j in node list of i */ - h += j; /* compute hash for node i */ - } - if(d == 0) /* check for mass elimination */ - { - Cp[i] = amd_flip (k); /* absorb i into k */ - nvi = -nv[i]; - dk -= nvi; /* |Lk| -= |i| */ - nvk += nvi; /* |k| += nv[i] */ - nel += nvi; - nv[i] = 0; - elen[i] = -1; /* node i is dead */ - } - else - { - degree[i] = std::min<StorageIndex> (degree[i], d); /* update degree(i) */ - Ci[pn] = Ci[p3]; /* move first node to end */ - Ci[p3] = Ci[p1]; /* move 1st el. to end of Ei */ - Ci[p1] = k; /* add k as 1st element in of Ei */ - len[i] = pn - p1 + 1; /* new len of adj. list of node i */ - h %= n; /* finalize hash of i */ - next[i] = hhead[h]; /* place i in hash bucket */ - hhead[h] = i; - last[i] = h; /* save hash of i in last[i] */ - } - } /* scan2 is done */ - degree[k] = dk; /* finalize |Lk| */ - lemax = std::max<StorageIndex>(lemax, dk); - mark = internal::cs_wclear<StorageIndex>(mark+lemax, lemax, w, n); /* clear w */ - - /* --- Supernode detection ------------------------------------------ */ - for(pk = pk1; pk < pk2; pk++) - { - i = Ci[pk]; - if(nv[i] >= 0) continue; /* skip if i is dead */ - h = last[i]; /* scan hash bucket of node i */ - i = hhead[h]; - hhead[h] = -1; /* hash bucket will be empty */ - for(; i != -1 && next[i] != -1; i = next[i], mark++) - { - ln = len[i]; - eln = elen[i]; - for(p = Cp[i]+1; p <= Cp[i] + ln-1; p++) w[Ci[p]] = mark; - jlast = i; - for(j = next[i]; j != -1; ) /* compare i with all j */ - { - ok = (len[j] == ln) && (elen[j] == eln); - for(p = Cp[j] + 1; ok && p <= Cp[j] + ln - 1; p++) - { - if(w[Ci[p]] != mark) ok = 0; /* compare i and j*/ - } - if(ok) /* i and j are identical */ - { - Cp[j] = amd_flip (i); /* absorb j into i */ - nv[i] += nv[j]; - nv[j] = 0; - elen[j] = -1; /* node j is dead */ - j = next[j]; /* delete j from hash bucket */ - next[jlast] = j; - } - else - { - jlast = j; /* j and i are different */ - j = next[j]; - } - } - } - } - - /* --- Finalize new element------------------------------------------ */ - for(p = pk1, pk = pk1; pk < pk2; pk++) /* finalize Lk */ - { - i = Ci[pk]; - if((nvi = -nv[i]) <= 0) continue;/* skip if i is dead */ - nv[i] = nvi; /* restore nv[i] */ - d = degree[i] + dk - nvi; /* compute external degree(i) */ - d = std::min<StorageIndex> (d, n - nel - nvi); - if(head[d] != -1) last[head[d]] = i; - next[i] = head[d]; /* put i back in degree list */ - last[i] = -1; - head[d] = i; - mindeg = std::min<StorageIndex> (mindeg, d); /* find new minimum degree */ - degree[i] = d; - Ci[p++] = i; /* place i in Lk */ - } - nv[k] = nvk; /* # nodes absorbed into k */ - if((len[k] = p-pk1) == 0) /* length of adj list of element k*/ - { - Cp[k] = -1; /* k is a root of the tree */ - w[k] = 0; /* k is now a dead element */ - } - if(elenk != 0) cnz = p; /* free unused space in Lk */ - } - - /* --- Postordering ----------------------------------------------------- */ - for(i = 0; i < n; i++) Cp[i] = amd_flip (Cp[i]);/* fix assembly tree */ - for(j = 0; j <= n; j++) head[j] = -1; - for(j = n; j >= 0; j--) /* place unordered nodes in lists */ - { - if(nv[j] > 0) continue; /* skip if j is an element */ - next[j] = head[Cp[j]]; /* place j in list of its parent */ - head[Cp[j]] = j; - } - for(e = n; e >= 0; e--) /* place elements in lists */ - { - if(nv[e] <= 0) continue; /* skip unless e is an element */ - if(Cp[e] != -1) - { - next[e] = head[Cp[e]]; /* place e in list of its parent */ - head[Cp[e]] = e; - } - } - for(k = 0, i = 0; i <= n; i++) /* postorder the assembly tree */ - { - if(Cp[i] == -1) k = internal::cs_tdfs<StorageIndex>(i, k, head, next, perm.indices().data(), w); - } - - perm.indices().conservativeResize(n); -} - -} // namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_AMD_H diff --git a/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Eigen_Colamd.h b/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Eigen_Colamd.h deleted file mode 100644 index 8e339a70..00000000 --- a/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Eigen_Colamd.h +++ /dev/null @@ -1,1863 +0,0 @@ -// // This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Desire Nuentsa Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// This file is modified from the colamd/symamd library. The copyright is below - -// The authors of the code itself are Stefan I. Larimore and Timothy A. -// Davis (davis@cise.ufl.edu), University of Florida. The algorithm was -// developed in collaboration with John Gilbert, Xerox PARC, and Esmond -// Ng, Oak Ridge National Laboratory. -// -// Date: -// -// September 8, 2003. Version 2.3. -// -// Acknowledgements: -// -// This work was supported by the National Science Foundation, under -// grants DMS-9504974 and DMS-9803599. -// -// Notice: -// -// Copyright (c) 1998-2003 by the University of Florida. -// All Rights Reserved. -// -// THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY -// EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. -// -// Permission is hereby granted to use, copy, modify, and/or distribute -// this program, provided that the Copyright, this License, and the -// Availability of the original version is retained on all copies and made -// accessible to the end-user of any code or package that includes COLAMD -// or any modified version of COLAMD. -// -// Availability: -// -// The colamd/symamd library is available at -// -// http://www.suitesparse.com - - -#ifndef EIGEN_COLAMD_H -#define EIGEN_COLAMD_H - -namespace internal { - -namespace Colamd { - -/* Ensure that debugging is turned off: */ -#ifndef COLAMD_NDEBUG -#define COLAMD_NDEBUG -#endif /* NDEBUG */ - - -/* ========================================================================== */ -/* === Knob and statistics definitions ====================================== */ -/* ========================================================================== */ - -/* size of the knobs [ ] array. Only knobs [0..1] are currently used. */ -const int NKnobs = 20; - -/* number of output statistics. Only stats [0..6] are currently used. */ -const int NStats = 20; - -/* Indices into knobs and stats array. */ -enum KnobsStatsIndex { - /* knobs [0] and stats [0]: dense row knob and output statistic. */ - DenseRow = 0, - - /* knobs [1] and stats [1]: dense column knob and output statistic. */ - DenseCol = 1, - - /* stats [2]: memory defragmentation count output statistic */ - DefragCount = 2, - - /* stats [3]: colamd status: zero OK, > 0 warning or notice, < 0 error */ - Status = 3, - - /* stats [4..6]: error info, or info on jumbled columns */ - Info1 = 4, - Info2 = 5, - Info3 = 6 -}; - -/* error codes returned in stats [3]: */ -enum Status { - Ok = 0, - OkButJumbled = 1, - ErrorANotPresent = -1, - ErrorPNotPresent = -2, - ErrorNrowNegative = -3, - ErrorNcolNegative = -4, - ErrorNnzNegative = -5, - ErrorP0Nonzero = -6, - ErrorATooSmall = -7, - ErrorColLengthNegative = -8, - ErrorRowIndexOutOfBounds = -9, - ErrorOutOfMemory = -10, - ErrorInternalError = -999 -}; -/* ========================================================================== */ -/* === Definitions ========================================================== */ -/* ========================================================================== */ - -template <typename IndexType> -IndexType ones_complement(const IndexType r) { - return (-(r)-1); -} - -/* -------------------------------------------------------------------------- */ -const int Empty = -1; - -/* Row and column status */ -enum RowColumnStatus { - Alive = 0, - Dead = -1 -}; - -/* Column status */ -enum ColumnStatus { - DeadPrincipal = -1, - DeadNonPrincipal = -2 -}; - -/* ========================================================================== */ -/* === Colamd reporting mechanism =========================================== */ -/* ========================================================================== */ - -// == Row and Column structures == -template <typename IndexType> -struct ColStructure -{ - IndexType start ; /* index for A of first row in this column, or Dead */ - /* if column is dead */ - IndexType length ; /* number of rows in this column */ - union - { - IndexType thickness ; /* number of original columns represented by this */ - /* col, if the column is alive */ - IndexType parent ; /* parent in parent tree super-column structure, if */ - /* the column is dead */ - } shared1 ; - union - { - IndexType score ; /* the score used to maintain heap, if col is alive */ - IndexType order ; /* pivot ordering of this column, if col is dead */ - } shared2 ; - union - { - IndexType headhash ; /* head of a hash bucket, if col is at the head of */ - /* a degree list */ - IndexType hash ; /* hash value, if col is not in a degree list */ - IndexType prev ; /* previous column in degree list, if col is in a */ - /* degree list (but not at the head of a degree list) */ - } shared3 ; - union - { - IndexType degree_next ; /* next column, if col is in a degree list */ - IndexType hash_next ; /* next column, if col is in a hash list */ - } shared4 ; - - inline bool is_dead() const { return start < Alive; } - - inline bool is_alive() const { return start >= Alive; } - - inline bool is_dead_principal() const { return start == DeadPrincipal; } - - inline void kill_principal() { start = DeadPrincipal; } - - inline void kill_non_principal() { start = DeadNonPrincipal; } - -}; - -template <typename IndexType> -struct RowStructure -{ - IndexType start ; /* index for A of first col in this row */ - IndexType length ; /* number of principal columns in this row */ - union - { - IndexType degree ; /* number of principal & non-principal columns in row */ - IndexType p ; /* used as a row pointer in init_rows_cols () */ - } shared1 ; - union - { - IndexType mark ; /* for computing set differences and marking dead rows*/ - IndexType first_column ;/* first column in row (used in garbage collection) */ - } shared2 ; - - inline bool is_dead() const { return shared2.mark < Alive; } - - inline bool is_alive() const { return shared2.mark >= Alive; } - - inline void kill() { shared2.mark = Dead; } - -}; - -/* ========================================================================== */ -/* === Colamd recommended memory size ======================================= */ -/* ========================================================================== */ - -/* - The recommended length Alen of the array A passed to colamd is given by - the COLAMD_RECOMMENDED (nnz, n_row, n_col) macro. It returns -1 if any - argument is negative. 2*nnz space is required for the row and column - indices of the matrix. colamd_c (n_col) + colamd_r (n_row) space is - required for the Col and Row arrays, respectively, which are internal to - colamd. An additional n_col space is the minimal amount of "elbow room", - and nnz/5 more space is recommended for run time efficiency. - - This macro is not needed when using symamd. - - Explicit typecast to IndexType added Sept. 23, 2002, COLAMD version 2.2, to avoid - gcc -pedantic warning messages. -*/ -template <typename IndexType> -inline IndexType colamd_c(IndexType n_col) -{ return IndexType( ((n_col) + 1) * sizeof (ColStructure<IndexType>) / sizeof (IndexType) ) ; } - -template <typename IndexType> -inline IndexType colamd_r(IndexType n_row) -{ return IndexType(((n_row) + 1) * sizeof (RowStructure<IndexType>) / sizeof (IndexType)); } - -// Prototypes of non-user callable routines -template <typename IndexType> -static IndexType init_rows_cols (IndexType n_row, IndexType n_col, RowStructure<IndexType> Row [], ColStructure<IndexType> col [], IndexType A [], IndexType p [], IndexType stats[NStats] ); - -template <typename IndexType> -static void init_scoring (IndexType n_row, IndexType n_col, RowStructure<IndexType> Row [], ColStructure<IndexType> Col [], IndexType A [], IndexType head [], double knobs[NKnobs], IndexType *p_n_row2, IndexType *p_n_col2, IndexType *p_max_deg); - -template <typename IndexType> -static IndexType find_ordering (IndexType n_row, IndexType n_col, IndexType Alen, RowStructure<IndexType> Row [], ColStructure<IndexType> Col [], IndexType A [], IndexType head [], IndexType n_col2, IndexType max_deg, IndexType pfree); - -template <typename IndexType> -static void order_children (IndexType n_col, ColStructure<IndexType> Col [], IndexType p []); - -template <typename IndexType> -static void detect_super_cols (ColStructure<IndexType> Col [], IndexType A [], IndexType head [], IndexType row_start, IndexType row_length ) ; - -template <typename IndexType> -static IndexType garbage_collection (IndexType n_row, IndexType n_col, RowStructure<IndexType> Row [], ColStructure<IndexType> Col [], IndexType A [], IndexType *pfree) ; - -template <typename IndexType> -static inline IndexType clear_mark (IndexType n_row, RowStructure<IndexType> Row [] ) ; - -/* === No debugging ========================================================= */ - -#define COLAMD_DEBUG0(params) ; -#define COLAMD_DEBUG1(params) ; -#define COLAMD_DEBUG2(params) ; -#define COLAMD_DEBUG3(params) ; -#define COLAMD_DEBUG4(params) ; - -#define COLAMD_ASSERT(expression) ((void) 0) - - -/** - * \brief Returns the recommended value of Alen - * - * Returns recommended value of Alen for use by colamd. - * Returns -1 if any input argument is negative. - * The use of this routine or macro is optional. - * Note that the macro uses its arguments more than once, - * so be careful for side effects, if you pass expressions as arguments to COLAMD_RECOMMENDED. - * - * \param nnz nonzeros in A - * \param n_row number of rows in A - * \param n_col number of columns in A - * \return recommended value of Alen for use by colamd - */ -template <typename IndexType> -inline IndexType recommended ( IndexType nnz, IndexType n_row, IndexType n_col) -{ - if ((nnz) < 0 || (n_row) < 0 || (n_col) < 0) - return (-1); - else - return (2 * (nnz) + colamd_c (n_col) + colamd_r (n_row) + (n_col) + ((nnz) / 5)); -} - -/** - * \brief set default parameters The use of this routine is optional. - * - * Colamd: rows with more than (knobs [DenseRow] * n_col) - * entries are removed prior to ordering. Columns with more than - * (knobs [DenseCol] * n_row) entries are removed prior to - * ordering, and placed last in the output column ordering. - * - * DenseRow and DenseCol are defined as 0 and 1, - * respectively, in colamd.h. Default values of these two knobs - * are both 0.5. Currently, only knobs [0] and knobs [1] are - * used, but future versions may use more knobs. If so, they will - * be properly set to their defaults by the future version of - * colamd_set_defaults, so that the code that calls colamd will - * not need to change, assuming that you either use - * colamd_set_defaults, or pass a (double *) NULL pointer as the - * knobs array to colamd or symamd. - * - * \param knobs parameter settings for colamd - */ - -static inline void set_defaults(double knobs[NKnobs]) -{ - /* === Local variables ================================================== */ - - int i ; - - if (!knobs) - { - return ; /* no knobs to initialize */ - } - for (i = 0 ; i < NKnobs ; i++) - { - knobs [i] = 0 ; - } - knobs [Colamd::DenseRow] = 0.5 ; /* ignore rows over 50% dense */ - knobs [Colamd::DenseCol] = 0.5 ; /* ignore columns over 50% dense */ -} - -/** - * \brief Computes a column ordering using the column approximate minimum degree ordering - * - * Computes a column ordering (Q) of A such that P(AQ)=LU or - * (AQ)'AQ=LL' have less fill-in and require fewer floating point - * operations than factorizing the unpermuted matrix A or A'A, - * respectively. - * - * - * \param n_row number of rows in A - * \param n_col number of columns in A - * \param Alen, size of the array A - * \param A row indices of the matrix, of size ALen - * \param p column pointers of A, of size n_col+1 - * \param knobs parameter settings for colamd - * \param stats colamd output statistics and error codes - */ -template <typename IndexType> -static bool compute_ordering(IndexType n_row, IndexType n_col, IndexType Alen, IndexType *A, IndexType *p, double knobs[NKnobs], IndexType stats[NStats]) -{ - /* === Local variables ================================================== */ - - IndexType i ; /* loop index */ - IndexType nnz ; /* nonzeros in A */ - IndexType Row_size ; /* size of Row [], in integers */ - IndexType Col_size ; /* size of Col [], in integers */ - IndexType need ; /* minimum required length of A */ - Colamd::RowStructure<IndexType> *Row ; /* pointer into A of Row [0..n_row] array */ - Colamd::ColStructure<IndexType> *Col ; /* pointer into A of Col [0..n_col] array */ - IndexType n_col2 ; /* number of non-dense, non-empty columns */ - IndexType n_row2 ; /* number of non-dense, non-empty rows */ - IndexType ngarbage ; /* number of garbage collections performed */ - IndexType max_deg ; /* maximum row degree */ - double default_knobs [NKnobs] ; /* default knobs array */ - - - /* === Check the input arguments ======================================== */ - - if (!stats) - { - COLAMD_DEBUG0 (("colamd: stats not present\n")) ; - return (false) ; - } - for (i = 0 ; i < NStats ; i++) - { - stats [i] = 0 ; - } - stats [Colamd::Status] = Colamd::Ok ; - stats [Colamd::Info1] = -1 ; - stats [Colamd::Info2] = -1 ; - - if (!A) /* A is not present */ - { - stats [Colamd::Status] = Colamd::ErrorANotPresent ; - COLAMD_DEBUG0 (("colamd: A not present\n")) ; - return (false) ; - } - - if (!p) /* p is not present */ - { - stats [Colamd::Status] = Colamd::ErrorPNotPresent ; - COLAMD_DEBUG0 (("colamd: p not present\n")) ; - return (false) ; - } - - if (n_row < 0) /* n_row must be >= 0 */ - { - stats [Colamd::Status] = Colamd::ErrorNrowNegative ; - stats [Colamd::Info1] = n_row ; - COLAMD_DEBUG0 (("colamd: nrow negative %d\n", n_row)) ; - return (false) ; - } - - if (n_col < 0) /* n_col must be >= 0 */ - { - stats [Colamd::Status] = Colamd::ErrorNcolNegative ; - stats [Colamd::Info1] = n_col ; - COLAMD_DEBUG0 (("colamd: ncol negative %d\n", n_col)) ; - return (false) ; - } - - nnz = p [n_col] ; - if (nnz < 0) /* nnz must be >= 0 */ - { - stats [Colamd::Status] = Colamd::ErrorNnzNegative ; - stats [Colamd::Info1] = nnz ; - COLAMD_DEBUG0 (("colamd: number of entries negative %d\n", nnz)) ; - return (false) ; - } - - if (p [0] != 0) - { - stats [Colamd::Status] = Colamd::ErrorP0Nonzero ; - stats [Colamd::Info1] = p [0] ; - COLAMD_DEBUG0 (("colamd: p[0] not zero %d\n", p [0])) ; - return (false) ; - } - - /* === If no knobs, set default knobs =================================== */ - - if (!knobs) - { - set_defaults (default_knobs) ; - knobs = default_knobs ; - } - - /* === Allocate the Row and Col arrays from array A ===================== */ - - Col_size = colamd_c (n_col) ; - Row_size = colamd_r (n_row) ; - need = 2*nnz + n_col + Col_size + Row_size ; - - if (need > Alen) - { - /* not enough space in array A to perform the ordering */ - stats [Colamd::Status] = Colamd::ErrorATooSmall ; - stats [Colamd::Info1] = need ; - stats [Colamd::Info2] = Alen ; - COLAMD_DEBUG0 (("colamd: Need Alen >= %d, given only Alen = %d\n", need,Alen)); - return (false) ; - } - - Alen -= Col_size + Row_size ; - Col = (ColStructure<IndexType> *) &A [Alen] ; - Row = (RowStructure<IndexType> *) &A [Alen + Col_size] ; - - /* === Construct the row and column data structures ===================== */ - - if (!Colamd::init_rows_cols (n_row, n_col, Row, Col, A, p, stats)) - { - /* input matrix is invalid */ - COLAMD_DEBUG0 (("colamd: Matrix invalid\n")) ; - return (false) ; - } - - /* === Initialize scores, kill dense rows/columns ======================= */ - - Colamd::init_scoring (n_row, n_col, Row, Col, A, p, knobs, - &n_row2, &n_col2, &max_deg) ; - - /* === Order the supercolumns =========================================== */ - - ngarbage = Colamd::find_ordering (n_row, n_col, Alen, Row, Col, A, p, - n_col2, max_deg, 2*nnz) ; - - /* === Order the non-principal columns ================================== */ - - Colamd::order_children (n_col, Col, p) ; - - /* === Return statistics in stats ======================================= */ - - stats [Colamd::DenseRow] = n_row - n_row2 ; - stats [Colamd::DenseCol] = n_col - n_col2 ; - stats [Colamd::DefragCount] = ngarbage ; - COLAMD_DEBUG0 (("colamd: done.\n")) ; - return (true) ; -} - -/* ========================================================================== */ -/* === NON-USER-CALLABLE ROUTINES: ========================================== */ -/* ========================================================================== */ - -/* There are no user-callable routines beyond this point in the file */ - -/* ========================================================================== */ -/* === init_rows_cols ======================================================= */ -/* ========================================================================== */ - -/* - Takes the column form of the matrix in A and creates the row form of the - matrix. Also, row and column attributes are stored in the Col and Row - structs. If the columns are un-sorted or contain duplicate row indices, - this routine will also sort and remove duplicate row indices from the - column form of the matrix. Returns false if the matrix is invalid, - true otherwise. Not user-callable. -*/ -template <typename IndexType> -static IndexType init_rows_cols /* returns true if OK, or false otherwise */ - ( - /* === Parameters ======================================================= */ - - IndexType n_row, /* number of rows of A */ - IndexType n_col, /* number of columns of A */ - RowStructure<IndexType> Row [], /* of size n_row+1 */ - ColStructure<IndexType> Col [], /* of size n_col+1 */ - IndexType A [], /* row indices of A, of size Alen */ - IndexType p [], /* pointers to columns in A, of size n_col+1 */ - IndexType stats [NStats] /* colamd statistics */ - ) -{ - /* === Local variables ================================================== */ - - IndexType col ; /* a column index */ - IndexType row ; /* a row index */ - IndexType *cp ; /* a column pointer */ - IndexType *cp_end ; /* a pointer to the end of a column */ - IndexType *rp ; /* a row pointer */ - IndexType *rp_end ; /* a pointer to the end of a row */ - IndexType last_row ; /* previous row */ - - /* === Initialize columns, and check column pointers ==================== */ - - for (col = 0 ; col < n_col ; col++) - { - Col [col].start = p [col] ; - Col [col].length = p [col+1] - p [col] ; - - if ((Col [col].length) < 0) // extra parentheses to work-around gcc bug 10200 - { - /* column pointers must be non-decreasing */ - stats [Colamd::Status] = Colamd::ErrorColLengthNegative ; - stats [Colamd::Info1] = col ; - stats [Colamd::Info2] = Col [col].length ; - COLAMD_DEBUG0 (("colamd: col %d length %d < 0\n", col, Col [col].length)) ; - return (false) ; - } - - Col [col].shared1.thickness = 1 ; - Col [col].shared2.score = 0 ; - Col [col].shared3.prev = Empty ; - Col [col].shared4.degree_next = Empty ; - } - - /* p [0..n_col] no longer needed, used as "head" in subsequent routines */ - - /* === Scan columns, compute row degrees, and check row indices ========= */ - - stats [Info3] = 0 ; /* number of duplicate or unsorted row indices*/ - - for (row = 0 ; row < n_row ; row++) - { - Row [row].length = 0 ; - Row [row].shared2.mark = -1 ; - } - - for (col = 0 ; col < n_col ; col++) - { - last_row = -1 ; - - cp = &A [p [col]] ; - cp_end = &A [p [col+1]] ; - - while (cp < cp_end) - { - row = *cp++ ; - - /* make sure row indices within range */ - if (row < 0 || row >= n_row) - { - stats [Colamd::Status] = Colamd::ErrorRowIndexOutOfBounds ; - stats [Colamd::Info1] = col ; - stats [Colamd::Info2] = row ; - stats [Colamd::Info3] = n_row ; - COLAMD_DEBUG0 (("colamd: row %d col %d out of bounds\n", row, col)) ; - return (false) ; - } - - if (row <= last_row || Row [row].shared2.mark == col) - { - /* row index are unsorted or repeated (or both), thus col */ - /* is jumbled. This is a notice, not an error condition. */ - stats [Colamd::Status] = Colamd::OkButJumbled ; - stats [Colamd::Info1] = col ; - stats [Colamd::Info2] = row ; - (stats [Colamd::Info3]) ++ ; - COLAMD_DEBUG1 (("colamd: row %d col %d unsorted/duplicate\n",row,col)); - } - - if (Row [row].shared2.mark != col) - { - Row [row].length++ ; - } - else - { - /* this is a repeated entry in the column, */ - /* it will be removed */ - Col [col].length-- ; - } - - /* mark the row as having been seen in this column */ - Row [row].shared2.mark = col ; - - last_row = row ; - } - } - - /* === Compute row pointers ============================================= */ - - /* row form of the matrix starts directly after the column */ - /* form of matrix in A */ - Row [0].start = p [n_col] ; - Row [0].shared1.p = Row [0].start ; - Row [0].shared2.mark = -1 ; - for (row = 1 ; row < n_row ; row++) - { - Row [row].start = Row [row-1].start + Row [row-1].length ; - Row [row].shared1.p = Row [row].start ; - Row [row].shared2.mark = -1 ; - } - - /* === Create row form ================================================== */ - - if (stats [Status] == OkButJumbled) - { - /* if cols jumbled, watch for repeated row indices */ - for (col = 0 ; col < n_col ; col++) - { - cp = &A [p [col]] ; - cp_end = &A [p [col+1]] ; - while (cp < cp_end) - { - row = *cp++ ; - if (Row [row].shared2.mark != col) - { - A [(Row [row].shared1.p)++] = col ; - Row [row].shared2.mark = col ; - } - } - } - } - else - { - /* if cols not jumbled, we don't need the mark (this is faster) */ - for (col = 0 ; col < n_col ; col++) - { - cp = &A [p [col]] ; - cp_end = &A [p [col+1]] ; - while (cp < cp_end) - { - A [(Row [*cp++].shared1.p)++] = col ; - } - } - } - - /* === Clear the row marks and set row degrees ========================== */ - - for (row = 0 ; row < n_row ; row++) - { - Row [row].shared2.mark = 0 ; - Row [row].shared1.degree = Row [row].length ; - } - - /* === See if we need to re-create columns ============================== */ - - if (stats [Status] == OkButJumbled) - { - COLAMD_DEBUG0 (("colamd: reconstructing column form, matrix jumbled\n")) ; - - - /* === Compute col pointers ========================================= */ - - /* col form of the matrix starts at A [0]. */ - /* Note, we may have a gap between the col form and the row */ - /* form if there were duplicate entries, if so, it will be */ - /* removed upon the first garbage collection */ - Col [0].start = 0 ; - p [0] = Col [0].start ; - for (col = 1 ; col < n_col ; col++) - { - /* note that the lengths here are for pruned columns, i.e. */ - /* no duplicate row indices will exist for these columns */ - Col [col].start = Col [col-1].start + Col [col-1].length ; - p [col] = Col [col].start ; - } - - /* === Re-create col form =========================================== */ - - for (row = 0 ; row < n_row ; row++) - { - rp = &A [Row [row].start] ; - rp_end = rp + Row [row].length ; - while (rp < rp_end) - { - A [(p [*rp++])++] = row ; - } - } - } - - /* === Done. Matrix is not (or no longer) jumbled ====================== */ - - return (true) ; -} - - -/* ========================================================================== */ -/* === init_scoring ========================================================= */ -/* ========================================================================== */ - -/* - Kills dense or empty columns and rows, calculates an initial score for - each column, and places all columns in the degree lists. Not user-callable. -*/ -template <typename IndexType> -static void init_scoring - ( - /* === Parameters ======================================================= */ - - IndexType n_row, /* number of rows of A */ - IndexType n_col, /* number of columns of A */ - RowStructure<IndexType> Row [], /* of size n_row+1 */ - ColStructure<IndexType> Col [], /* of size n_col+1 */ - IndexType A [], /* column form and row form of A */ - IndexType head [], /* of size n_col+1 */ - double knobs [NKnobs],/* parameters */ - IndexType *p_n_row2, /* number of non-dense, non-empty rows */ - IndexType *p_n_col2, /* number of non-dense, non-empty columns */ - IndexType *p_max_deg /* maximum row degree */ - ) -{ - /* === Local variables ================================================== */ - - IndexType c ; /* a column index */ - IndexType r, row ; /* a row index */ - IndexType *cp ; /* a column pointer */ - IndexType deg ; /* degree of a row or column */ - IndexType *cp_end ; /* a pointer to the end of a column */ - IndexType *new_cp ; /* new column pointer */ - IndexType col_length ; /* length of pruned column */ - IndexType score ; /* current column score */ - IndexType n_col2 ; /* number of non-dense, non-empty columns */ - IndexType n_row2 ; /* number of non-dense, non-empty rows */ - IndexType dense_row_count ; /* remove rows with more entries than this */ - IndexType dense_col_count ; /* remove cols with more entries than this */ - IndexType min_score ; /* smallest column score */ - IndexType max_deg ; /* maximum row degree */ - IndexType next_col ; /* Used to add to degree list.*/ - - - /* === Extract knobs ==================================================== */ - - dense_row_count = numext::maxi(IndexType(0), numext::mini(IndexType(knobs [Colamd::DenseRow] * n_col), n_col)) ; - dense_col_count = numext::maxi(IndexType(0), numext::mini(IndexType(knobs [Colamd::DenseCol] * n_row), n_row)) ; - COLAMD_DEBUG1 (("colamd: densecount: %d %d\n", dense_row_count, dense_col_count)) ; - max_deg = 0 ; - n_col2 = n_col ; - n_row2 = n_row ; - - /* === Kill empty columns =============================================== */ - - /* Put the empty columns at the end in their natural order, so that LU */ - /* factorization can proceed as far as possible. */ - for (c = n_col-1 ; c >= 0 ; c--) - { - deg = Col [c].length ; - if (deg == 0) - { - /* this is a empty column, kill and order it last */ - Col [c].shared2.order = --n_col2 ; - Col[c].kill_principal() ; - } - } - COLAMD_DEBUG1 (("colamd: null columns killed: %d\n", n_col - n_col2)) ; - - /* === Kill dense columns =============================================== */ - - /* Put the dense columns at the end, in their natural order */ - for (c = n_col-1 ; c >= 0 ; c--) - { - /* skip any dead columns */ - if (Col[c].is_dead()) - { - continue ; - } - deg = Col [c].length ; - if (deg > dense_col_count) - { - /* this is a dense column, kill and order it last */ - Col [c].shared2.order = --n_col2 ; - /* decrement the row degrees */ - cp = &A [Col [c].start] ; - cp_end = cp + Col [c].length ; - while (cp < cp_end) - { - Row [*cp++].shared1.degree-- ; - } - Col[c].kill_principal() ; - } - } - COLAMD_DEBUG1 (("colamd: Dense and null columns killed: %d\n", n_col - n_col2)) ; - - /* === Kill dense and empty rows ======================================== */ - - for (r = 0 ; r < n_row ; r++) - { - deg = Row [r].shared1.degree ; - COLAMD_ASSERT (deg >= 0 && deg <= n_col) ; - if (deg > dense_row_count || deg == 0) - { - /* kill a dense or empty row */ - Row[r].kill() ; - --n_row2 ; - } - else - { - /* keep track of max degree of remaining rows */ - max_deg = numext::maxi(max_deg, deg) ; - } - } - COLAMD_DEBUG1 (("colamd: Dense and null rows killed: %d\n", n_row - n_row2)) ; - - /* === Compute initial column scores ==================================== */ - - /* At this point the row degrees are accurate. They reflect the number */ - /* of "live" (non-dense) columns in each row. No empty rows exist. */ - /* Some "live" columns may contain only dead rows, however. These are */ - /* pruned in the code below. */ - - /* now find the initial matlab score for each column */ - for (c = n_col-1 ; c >= 0 ; c--) - { - /* skip dead column */ - if (Col[c].is_dead()) - { - continue ; - } - score = 0 ; - cp = &A [Col [c].start] ; - new_cp = cp ; - cp_end = cp + Col [c].length ; - while (cp < cp_end) - { - /* get a row */ - row = *cp++ ; - /* skip if dead */ - if (Row[row].is_dead()) - { - continue ; - } - /* compact the column */ - *new_cp++ = row ; - /* add row's external degree */ - score += Row [row].shared1.degree - 1 ; - /* guard against integer overflow */ - score = numext::mini(score, n_col) ; - } - /* determine pruned column length */ - col_length = (IndexType) (new_cp - &A [Col [c].start]) ; - if (col_length == 0) - { - /* a newly-made null column (all rows in this col are "dense" */ - /* and have already been killed) */ - COLAMD_DEBUG2 (("Newly null killed: %d\n", c)) ; - Col [c].shared2.order = --n_col2 ; - Col[c].kill_principal() ; - } - else - { - /* set column length and set score */ - COLAMD_ASSERT (score >= 0) ; - COLAMD_ASSERT (score <= n_col) ; - Col [c].length = col_length ; - Col [c].shared2.score = score ; - } - } - COLAMD_DEBUG1 (("colamd: Dense, null, and newly-null columns killed: %d\n", - n_col-n_col2)) ; - - /* At this point, all empty rows and columns are dead. All live columns */ - /* are "clean" (containing no dead rows) and simplicial (no supercolumns */ - /* yet). Rows may contain dead columns, but all live rows contain at */ - /* least one live column. */ - - /* === Initialize degree lists ========================================== */ - - - /* clear the hash buckets */ - for (c = 0 ; c <= n_col ; c++) - { - head [c] = Empty ; - } - min_score = n_col ; - /* place in reverse order, so low column indices are at the front */ - /* of the lists. This is to encourage natural tie-breaking */ - for (c = n_col-1 ; c >= 0 ; c--) - { - /* only add principal columns to degree lists */ - if (Col[c].is_alive()) - { - COLAMD_DEBUG4 (("place %d score %d minscore %d ncol %d\n", - c, Col [c].shared2.score, min_score, n_col)) ; - - /* === Add columns score to DList =============================== */ - - score = Col [c].shared2.score ; - - COLAMD_ASSERT (min_score >= 0) ; - COLAMD_ASSERT (min_score <= n_col) ; - COLAMD_ASSERT (score >= 0) ; - COLAMD_ASSERT (score <= n_col) ; - COLAMD_ASSERT (head [score] >= Empty) ; - - /* now add this column to dList at proper score location */ - next_col = head [score] ; - Col [c].shared3.prev = Empty ; - Col [c].shared4.degree_next = next_col ; - - /* if there already was a column with the same score, set its */ - /* previous pointer to this new column */ - if (next_col != Empty) - { - Col [next_col].shared3.prev = c ; - } - head [score] = c ; - - /* see if this score is less than current min */ - min_score = numext::mini(min_score, score) ; - - - } - } - - - /* === Return number of remaining columns, and max row degree =========== */ - - *p_n_col2 = n_col2 ; - *p_n_row2 = n_row2 ; - *p_max_deg = max_deg ; -} - - -/* ========================================================================== */ -/* === find_ordering ======================================================== */ -/* ========================================================================== */ - -/* - Order the principal columns of the supercolumn form of the matrix - (no supercolumns on input). Uses a minimum approximate column minimum - degree ordering method. Not user-callable. -*/ -template <typename IndexType> -static IndexType find_ordering /* return the number of garbage collections */ - ( - /* === Parameters ======================================================= */ - - IndexType n_row, /* number of rows of A */ - IndexType n_col, /* number of columns of A */ - IndexType Alen, /* size of A, 2*nnz + n_col or larger */ - RowStructure<IndexType> Row [], /* of size n_row+1 */ - ColStructure<IndexType> Col [], /* of size n_col+1 */ - IndexType A [], /* column form and row form of A */ - IndexType head [], /* of size n_col+1 */ - IndexType n_col2, /* Remaining columns to order */ - IndexType max_deg, /* Maximum row degree */ - IndexType pfree /* index of first free slot (2*nnz on entry) */ - ) -{ - /* === Local variables ================================================== */ - - IndexType k ; /* current pivot ordering step */ - IndexType pivot_col ; /* current pivot column */ - IndexType *cp ; /* a column pointer */ - IndexType *rp ; /* a row pointer */ - IndexType pivot_row ; /* current pivot row */ - IndexType *new_cp ; /* modified column pointer */ - IndexType *new_rp ; /* modified row pointer */ - IndexType pivot_row_start ; /* pointer to start of pivot row */ - IndexType pivot_row_degree ; /* number of columns in pivot row */ - IndexType pivot_row_length ; /* number of supercolumns in pivot row */ - IndexType pivot_col_score ; /* score of pivot column */ - IndexType needed_memory ; /* free space needed for pivot row */ - IndexType *cp_end ; /* pointer to the end of a column */ - IndexType *rp_end ; /* pointer to the end of a row */ - IndexType row ; /* a row index */ - IndexType col ; /* a column index */ - IndexType max_score ; /* maximum possible score */ - IndexType cur_score ; /* score of current column */ - unsigned int hash ; /* hash value for supernode detection */ - IndexType head_column ; /* head of hash bucket */ - IndexType first_col ; /* first column in hash bucket */ - IndexType tag_mark ; /* marker value for mark array */ - IndexType row_mark ; /* Row [row].shared2.mark */ - IndexType set_difference ; /* set difference size of row with pivot row */ - IndexType min_score ; /* smallest column score */ - IndexType col_thickness ; /* "thickness" (no. of columns in a supercol) */ - IndexType max_mark ; /* maximum value of tag_mark */ - IndexType pivot_col_thickness ; /* number of columns represented by pivot col */ - IndexType prev_col ; /* Used by Dlist operations. */ - IndexType next_col ; /* Used by Dlist operations. */ - IndexType ngarbage ; /* number of garbage collections performed */ - - - /* === Initialization and clear mark ==================================== */ - - max_mark = INT_MAX - n_col ; /* INT_MAX defined in <limits.h> */ - tag_mark = Colamd::clear_mark (n_row, Row) ; - min_score = 0 ; - ngarbage = 0 ; - COLAMD_DEBUG1 (("colamd: Ordering, n_col2=%d\n", n_col2)) ; - - /* === Order the columns ================================================ */ - - for (k = 0 ; k < n_col2 ; /* 'k' is incremented below */) - { - - /* === Select pivot column, and order it ============================ */ - - /* make sure degree list isn't empty */ - COLAMD_ASSERT (min_score >= 0) ; - COLAMD_ASSERT (min_score <= n_col) ; - COLAMD_ASSERT (head [min_score] >= Empty) ; - - /* get pivot column from head of minimum degree list */ - while (min_score < n_col && head [min_score] == Empty) - { - min_score++ ; - } - pivot_col = head [min_score] ; - COLAMD_ASSERT (pivot_col >= 0 && pivot_col <= n_col) ; - next_col = Col [pivot_col].shared4.degree_next ; - head [min_score] = next_col ; - if (next_col != Empty) - { - Col [next_col].shared3.prev = Empty ; - } - - COLAMD_ASSERT (Col[pivot_col].is_alive()) ; - COLAMD_DEBUG3 (("Pivot col: %d\n", pivot_col)) ; - - /* remember score for defrag check */ - pivot_col_score = Col [pivot_col].shared2.score ; - - /* the pivot column is the kth column in the pivot order */ - Col [pivot_col].shared2.order = k ; - - /* increment order count by column thickness */ - pivot_col_thickness = Col [pivot_col].shared1.thickness ; - k += pivot_col_thickness ; - COLAMD_ASSERT (pivot_col_thickness > 0) ; - - /* === Garbage_collection, if necessary ============================= */ - - needed_memory = numext::mini(pivot_col_score, n_col - k) ; - if (pfree + needed_memory >= Alen) - { - pfree = Colamd::garbage_collection (n_row, n_col, Row, Col, A, &A [pfree]) ; - ngarbage++ ; - /* after garbage collection we will have enough */ - COLAMD_ASSERT (pfree + needed_memory < Alen) ; - /* garbage collection has wiped out the Row[].shared2.mark array */ - tag_mark = Colamd::clear_mark (n_row, Row) ; - - } - - /* === Compute pivot row pattern ==================================== */ - - /* get starting location for this new merged row */ - pivot_row_start = pfree ; - - /* initialize new row counts to zero */ - pivot_row_degree = 0 ; - - /* tag pivot column as having been visited so it isn't included */ - /* in merged pivot row */ - Col [pivot_col].shared1.thickness = -pivot_col_thickness ; - - /* pivot row is the union of all rows in the pivot column pattern */ - cp = &A [Col [pivot_col].start] ; - cp_end = cp + Col [pivot_col].length ; - while (cp < cp_end) - { - /* get a row */ - row = *cp++ ; - COLAMD_DEBUG4 (("Pivot col pattern %d %d\n", Row[row].is_alive(), row)) ; - /* skip if row is dead */ - if (Row[row].is_dead()) - { - continue ; - } - rp = &A [Row [row].start] ; - rp_end = rp + Row [row].length ; - while (rp < rp_end) - { - /* get a column */ - col = *rp++ ; - /* add the column, if alive and untagged */ - col_thickness = Col [col].shared1.thickness ; - if (col_thickness > 0 && Col[col].is_alive()) - { - /* tag column in pivot row */ - Col [col].shared1.thickness = -col_thickness ; - COLAMD_ASSERT (pfree < Alen) ; - /* place column in pivot row */ - A [pfree++] = col ; - pivot_row_degree += col_thickness ; - } - } - } - - /* clear tag on pivot column */ - Col [pivot_col].shared1.thickness = pivot_col_thickness ; - max_deg = numext::maxi(max_deg, pivot_row_degree) ; - - - /* === Kill all rows used to construct pivot row ==================== */ - - /* also kill pivot row, temporarily */ - cp = &A [Col [pivot_col].start] ; - cp_end = cp + Col [pivot_col].length ; - while (cp < cp_end) - { - /* may be killing an already dead row */ - row = *cp++ ; - COLAMD_DEBUG3 (("Kill row in pivot col: %d\n", row)) ; - Row[row].kill() ; - } - - /* === Select a row index to use as the new pivot row =============== */ - - pivot_row_length = pfree - pivot_row_start ; - if (pivot_row_length > 0) - { - /* pick the "pivot" row arbitrarily (first row in col) */ - pivot_row = A [Col [pivot_col].start] ; - COLAMD_DEBUG3 (("Pivotal row is %d\n", pivot_row)) ; - } - else - { - /* there is no pivot row, since it is of zero length */ - pivot_row = Empty ; - COLAMD_ASSERT (pivot_row_length == 0) ; - } - COLAMD_ASSERT (Col [pivot_col].length > 0 || pivot_row_length == 0) ; - - /* === Approximate degree computation =============================== */ - - /* Here begins the computation of the approximate degree. The column */ - /* score is the sum of the pivot row "length", plus the size of the */ - /* set differences of each row in the column minus the pattern of the */ - /* pivot row itself. The column ("thickness") itself is also */ - /* excluded from the column score (we thus use an approximate */ - /* external degree). */ - - /* The time taken by the following code (compute set differences, and */ - /* add them up) is proportional to the size of the data structure */ - /* being scanned - that is, the sum of the sizes of each column in */ - /* the pivot row. Thus, the amortized time to compute a column score */ - /* is proportional to the size of that column (where size, in this */ - /* context, is the column "length", or the number of row indices */ - /* in that column). The number of row indices in a column is */ - /* monotonically non-decreasing, from the length of the original */ - /* column on input to colamd. */ - - /* === Compute set differences ====================================== */ - - COLAMD_DEBUG3 (("** Computing set differences phase. **\n")) ; - - /* pivot row is currently dead - it will be revived later. */ - - COLAMD_DEBUG3 (("Pivot row: ")) ; - /* for each column in pivot row */ - rp = &A [pivot_row_start] ; - rp_end = rp + pivot_row_length ; - while (rp < rp_end) - { - col = *rp++ ; - COLAMD_ASSERT (Col[col].is_alive() && col != pivot_col) ; - COLAMD_DEBUG3 (("Col: %d\n", col)) ; - - /* clear tags used to construct pivot row pattern */ - col_thickness = -Col [col].shared1.thickness ; - COLAMD_ASSERT (col_thickness > 0) ; - Col [col].shared1.thickness = col_thickness ; - - /* === Remove column from degree list =========================== */ - - cur_score = Col [col].shared2.score ; - prev_col = Col [col].shared3.prev ; - next_col = Col [col].shared4.degree_next ; - COLAMD_ASSERT (cur_score >= 0) ; - COLAMD_ASSERT (cur_score <= n_col) ; - COLAMD_ASSERT (cur_score >= Empty) ; - if (prev_col == Empty) - { - head [cur_score] = next_col ; - } - else - { - Col [prev_col].shared4.degree_next = next_col ; - } - if (next_col != Empty) - { - Col [next_col].shared3.prev = prev_col ; - } - - /* === Scan the column ========================================== */ - - cp = &A [Col [col].start] ; - cp_end = cp + Col [col].length ; - while (cp < cp_end) - { - /* get a row */ - row = *cp++ ; - /* skip if dead */ - if (Row[row].is_dead()) - { - continue ; - } - row_mark = Row [row].shared2.mark ; - COLAMD_ASSERT (row != pivot_row) ; - set_difference = row_mark - tag_mark ; - /* check if the row has been seen yet */ - if (set_difference < 0) - { - COLAMD_ASSERT (Row [row].shared1.degree <= max_deg) ; - set_difference = Row [row].shared1.degree ; - } - /* subtract column thickness from this row's set difference */ - set_difference -= col_thickness ; - COLAMD_ASSERT (set_difference >= 0) ; - /* absorb this row if the set difference becomes zero */ - if (set_difference == 0) - { - COLAMD_DEBUG3 (("aggressive absorption. Row: %d\n", row)) ; - Row[row].kill() ; - } - else - { - /* save the new mark */ - Row [row].shared2.mark = set_difference + tag_mark ; - } - } - } - - - /* === Add up set differences for each column ======================= */ - - COLAMD_DEBUG3 (("** Adding set differences phase. **\n")) ; - - /* for each column in pivot row */ - rp = &A [pivot_row_start] ; - rp_end = rp + pivot_row_length ; - while (rp < rp_end) - { - /* get a column */ - col = *rp++ ; - COLAMD_ASSERT (Col[col].is_alive() && col != pivot_col) ; - hash = 0 ; - cur_score = 0 ; - cp = &A [Col [col].start] ; - /* compact the column */ - new_cp = cp ; - cp_end = cp + Col [col].length ; - - COLAMD_DEBUG4 (("Adding set diffs for Col: %d.\n", col)) ; - - while (cp < cp_end) - { - /* get a row */ - row = *cp++ ; - COLAMD_ASSERT(row >= 0 && row < n_row) ; - /* skip if dead */ - if (Row [row].is_dead()) - { - continue ; - } - row_mark = Row [row].shared2.mark ; - COLAMD_ASSERT (row_mark > tag_mark) ; - /* compact the column */ - *new_cp++ = row ; - /* compute hash function */ - hash += row ; - /* add set difference */ - cur_score += row_mark - tag_mark ; - /* integer overflow... */ - cur_score = numext::mini(cur_score, n_col) ; - } - - /* recompute the column's length */ - Col [col].length = (IndexType) (new_cp - &A [Col [col].start]) ; - - /* === Further mass elimination ================================= */ - - if (Col [col].length == 0) - { - COLAMD_DEBUG4 (("further mass elimination. Col: %d\n", col)) ; - /* nothing left but the pivot row in this column */ - Col[col].kill_principal() ; - pivot_row_degree -= Col [col].shared1.thickness ; - COLAMD_ASSERT (pivot_row_degree >= 0) ; - /* order it */ - Col [col].shared2.order = k ; - /* increment order count by column thickness */ - k += Col [col].shared1.thickness ; - } - else - { - /* === Prepare for supercolumn detection ==================== */ - - COLAMD_DEBUG4 (("Preparing supercol detection for Col: %d.\n", col)) ; - - /* save score so far */ - Col [col].shared2.score = cur_score ; - - /* add column to hash table, for supercolumn detection */ - hash %= n_col + 1 ; - - COLAMD_DEBUG4 ((" Hash = %d, n_col = %d.\n", hash, n_col)) ; - COLAMD_ASSERT (hash <= n_col) ; - - head_column = head [hash] ; - if (head_column > Empty) - { - /* degree list "hash" is non-empty, use prev (shared3) of */ - /* first column in degree list as head of hash bucket */ - first_col = Col [head_column].shared3.headhash ; - Col [head_column].shared3.headhash = col ; - } - else - { - /* degree list "hash" is empty, use head as hash bucket */ - first_col = - (head_column + 2) ; - head [hash] = - (col + 2) ; - } - Col [col].shared4.hash_next = first_col ; - - /* save hash function in Col [col].shared3.hash */ - Col [col].shared3.hash = (IndexType) hash ; - COLAMD_ASSERT (Col[col].is_alive()) ; - } - } - - /* The approximate external column degree is now computed. */ - - /* === Supercolumn detection ======================================== */ - - COLAMD_DEBUG3 (("** Supercolumn detection phase. **\n")) ; - - Colamd::detect_super_cols (Col, A, head, pivot_row_start, pivot_row_length) ; - - /* === Kill the pivotal column ====================================== */ - - Col[pivot_col].kill_principal() ; - - /* === Clear mark =================================================== */ - - tag_mark += (max_deg + 1) ; - if (tag_mark >= max_mark) - { - COLAMD_DEBUG2 (("clearing tag_mark\n")) ; - tag_mark = Colamd::clear_mark (n_row, Row) ; - } - - /* === Finalize the new pivot row, and column scores ================ */ - - COLAMD_DEBUG3 (("** Finalize scores phase. **\n")) ; - - /* for each column in pivot row */ - rp = &A [pivot_row_start] ; - /* compact the pivot row */ - new_rp = rp ; - rp_end = rp + pivot_row_length ; - while (rp < rp_end) - { - col = *rp++ ; - /* skip dead columns */ - if (Col[col].is_dead()) - { - continue ; - } - *new_rp++ = col ; - /* add new pivot row to column */ - A [Col [col].start + (Col [col].length++)] = pivot_row ; - - /* retrieve score so far and add on pivot row's degree. */ - /* (we wait until here for this in case the pivot */ - /* row's degree was reduced due to mass elimination). */ - cur_score = Col [col].shared2.score + pivot_row_degree ; - - /* calculate the max possible score as the number of */ - /* external columns minus the 'k' value minus the */ - /* columns thickness */ - max_score = n_col - k - Col [col].shared1.thickness ; - - /* make the score the external degree of the union-of-rows */ - cur_score -= Col [col].shared1.thickness ; - - /* make sure score is less or equal than the max score */ - cur_score = numext::mini(cur_score, max_score) ; - COLAMD_ASSERT (cur_score >= 0) ; - - /* store updated score */ - Col [col].shared2.score = cur_score ; - - /* === Place column back in degree list ========================= */ - - COLAMD_ASSERT (min_score >= 0) ; - COLAMD_ASSERT (min_score <= n_col) ; - COLAMD_ASSERT (cur_score >= 0) ; - COLAMD_ASSERT (cur_score <= n_col) ; - COLAMD_ASSERT (head [cur_score] >= Empty) ; - next_col = head [cur_score] ; - Col [col].shared4.degree_next = next_col ; - Col [col].shared3.prev = Empty ; - if (next_col != Empty) - { - Col [next_col].shared3.prev = col ; - } - head [cur_score] = col ; - - /* see if this score is less than current min */ - min_score = numext::mini(min_score, cur_score) ; - - } - - /* === Resurrect the new pivot row ================================== */ - - if (pivot_row_degree > 0) - { - /* update pivot row length to reflect any cols that were killed */ - /* during super-col detection and mass elimination */ - Row [pivot_row].start = pivot_row_start ; - Row [pivot_row].length = (IndexType) (new_rp - &A[pivot_row_start]) ; - Row [pivot_row].shared1.degree = pivot_row_degree ; - Row [pivot_row].shared2.mark = 0 ; - /* pivot row is no longer dead */ - } - } - - /* === All principal columns have now been ordered ====================== */ - - return (ngarbage) ; -} - - -/* ========================================================================== */ -/* === order_children ======================================================= */ -/* ========================================================================== */ - -/* - The find_ordering routine has ordered all of the principal columns (the - representatives of the supercolumns). The non-principal columns have not - yet been ordered. This routine orders those columns by walking up the - parent tree (a column is a child of the column which absorbed it). The - final permutation vector is then placed in p [0 ... n_col-1], with p [0] - being the first column, and p [n_col-1] being the last. It doesn't look - like it at first glance, but be assured that this routine takes time linear - in the number of columns. Although not immediately obvious, the time - taken by this routine is O (n_col), that is, linear in the number of - columns. Not user-callable. -*/ -template <typename IndexType> -static inline void order_children -( - /* === Parameters ======================================================= */ - - IndexType n_col, /* number of columns of A */ - ColStructure<IndexType> Col [], /* of size n_col+1 */ - IndexType p [] /* p [0 ... n_col-1] is the column permutation*/ - ) -{ - /* === Local variables ================================================== */ - - IndexType i ; /* loop counter for all columns */ - IndexType c ; /* column index */ - IndexType parent ; /* index of column's parent */ - IndexType order ; /* column's order */ - - /* === Order each non-principal column ================================== */ - - for (i = 0 ; i < n_col ; i++) - { - /* find an un-ordered non-principal column */ - COLAMD_ASSERT (col_is_dead(Col, i)) ; - if (!Col[i].is_dead_principal() && Col [i].shared2.order == Empty) - { - parent = i ; - /* once found, find its principal parent */ - do - { - parent = Col [parent].shared1.parent ; - } while (!Col[parent].is_dead_principal()) ; - - /* now, order all un-ordered non-principal columns along path */ - /* to this parent. collapse tree at the same time */ - c = i ; - /* get order of parent */ - order = Col [parent].shared2.order ; - - do - { - COLAMD_ASSERT (Col [c].shared2.order == Empty) ; - - /* order this column */ - Col [c].shared2.order = order++ ; - /* collaps tree */ - Col [c].shared1.parent = parent ; - - /* get immediate parent of this column */ - c = Col [c].shared1.parent ; - - /* continue until we hit an ordered column. There are */ - /* guaranteed not to be anymore unordered columns */ - /* above an ordered column */ - } while (Col [c].shared2.order == Empty) ; - - /* re-order the super_col parent to largest order for this group */ - Col [parent].shared2.order = order ; - } - } - - /* === Generate the permutation ========================================= */ - - for (c = 0 ; c < n_col ; c++) - { - p [Col [c].shared2.order] = c ; - } -} - - -/* ========================================================================== */ -/* === detect_super_cols ==================================================== */ -/* ========================================================================== */ - -/* - Detects supercolumns by finding matches between columns in the hash buckets. - Check amongst columns in the set A [row_start ... row_start + row_length-1]. - The columns under consideration are currently *not* in the degree lists, - and have already been placed in the hash buckets. - - The hash bucket for columns whose hash function is equal to h is stored - as follows: - - if head [h] is >= 0, then head [h] contains a degree list, so: - - head [h] is the first column in degree bucket h. - Col [head [h]].headhash gives the first column in hash bucket h. - - otherwise, the degree list is empty, and: - - -(head [h] + 2) is the first column in hash bucket h. - - For a column c in a hash bucket, Col [c].shared3.prev is NOT a "previous - column" pointer. Col [c].shared3.hash is used instead as the hash number - for that column. The value of Col [c].shared4.hash_next is the next column - in the same hash bucket. - - Assuming no, or "few" hash collisions, the time taken by this routine is - linear in the sum of the sizes (lengths) of each column whose score has - just been computed in the approximate degree computation. - Not user-callable. -*/ -template <typename IndexType> -static void detect_super_cols -( - /* === Parameters ======================================================= */ - - ColStructure<IndexType> Col [], /* of size n_col+1 */ - IndexType A [], /* row indices of A */ - IndexType head [], /* head of degree lists and hash buckets */ - IndexType row_start, /* pointer to set of columns to check */ - IndexType row_length /* number of columns to check */ -) -{ - /* === Local variables ================================================== */ - - IndexType hash ; /* hash value for a column */ - IndexType *rp ; /* pointer to a row */ - IndexType c ; /* a column index */ - IndexType super_c ; /* column index of the column to absorb into */ - IndexType *cp1 ; /* column pointer for column super_c */ - IndexType *cp2 ; /* column pointer for column c */ - IndexType length ; /* length of column super_c */ - IndexType prev_c ; /* column preceding c in hash bucket */ - IndexType i ; /* loop counter */ - IndexType *rp_end ; /* pointer to the end of the row */ - IndexType col ; /* a column index in the row to check */ - IndexType head_column ; /* first column in hash bucket or degree list */ - IndexType first_col ; /* first column in hash bucket */ - - /* === Consider each column in the row ================================== */ - - rp = &A [row_start] ; - rp_end = rp + row_length ; - while (rp < rp_end) - { - col = *rp++ ; - if (Col[col].is_dead()) - { - continue ; - } - - /* get hash number for this column */ - hash = Col [col].shared3.hash ; - COLAMD_ASSERT (hash <= n_col) ; - - /* === Get the first column in this hash bucket ===================== */ - - head_column = head [hash] ; - if (head_column > Empty) - { - first_col = Col [head_column].shared3.headhash ; - } - else - { - first_col = - (head_column + 2) ; - } - - /* === Consider each column in the hash bucket ====================== */ - - for (super_c = first_col ; super_c != Empty ; - super_c = Col [super_c].shared4.hash_next) - { - COLAMD_ASSERT (Col [super_c].is_alive()) ; - COLAMD_ASSERT (Col [super_c].shared3.hash == hash) ; - length = Col [super_c].length ; - - /* prev_c is the column preceding column c in the hash bucket */ - prev_c = super_c ; - - /* === Compare super_c with all columns after it ================ */ - - for (c = Col [super_c].shared4.hash_next ; - c != Empty ; c = Col [c].shared4.hash_next) - { - COLAMD_ASSERT (c != super_c) ; - COLAMD_ASSERT (Col[c].is_alive()) ; - COLAMD_ASSERT (Col [c].shared3.hash == hash) ; - - /* not identical if lengths or scores are different */ - if (Col [c].length != length || - Col [c].shared2.score != Col [super_c].shared2.score) - { - prev_c = c ; - continue ; - } - - /* compare the two columns */ - cp1 = &A [Col [super_c].start] ; - cp2 = &A [Col [c].start] ; - - for (i = 0 ; i < length ; i++) - { - /* the columns are "clean" (no dead rows) */ - COLAMD_ASSERT ( cp1->is_alive() ); - COLAMD_ASSERT ( cp2->is_alive() ); - /* row indices will same order for both supercols, */ - /* no gather scatter necessary */ - if (*cp1++ != *cp2++) - { - break ; - } - } - - /* the two columns are different if the for-loop "broke" */ - if (i != length) - { - prev_c = c ; - continue ; - } - - /* === Got it! two columns are identical =================== */ - - COLAMD_ASSERT (Col [c].shared2.score == Col [super_c].shared2.score) ; - - Col [super_c].shared1.thickness += Col [c].shared1.thickness ; - Col [c].shared1.parent = super_c ; - Col[c].kill_non_principal() ; - /* order c later, in order_children() */ - Col [c].shared2.order = Empty ; - /* remove c from hash bucket */ - Col [prev_c].shared4.hash_next = Col [c].shared4.hash_next ; - } - } - - /* === Empty this hash bucket ======================================= */ - - if (head_column > Empty) - { - /* corresponding degree list "hash" is not empty */ - Col [head_column].shared3.headhash = Empty ; - } - else - { - /* corresponding degree list "hash" is empty */ - head [hash] = Empty ; - } - } -} - - -/* ========================================================================== */ -/* === garbage_collection =================================================== */ -/* ========================================================================== */ - -/* - Defragments and compacts columns and rows in the workspace A. Used when - all available memory has been used while performing row merging. Returns - the index of the first free position in A, after garbage collection. The - time taken by this routine is linear is the size of the array A, which is - itself linear in the number of nonzeros in the input matrix. - Not user-callable. -*/ -template <typename IndexType> -static IndexType garbage_collection /* returns the new value of pfree */ - ( - /* === Parameters ======================================================= */ - - IndexType n_row, /* number of rows */ - IndexType n_col, /* number of columns */ - RowStructure<IndexType> Row [], /* row info */ - ColStructure<IndexType> Col [], /* column info */ - IndexType A [], /* A [0 ... Alen-1] holds the matrix */ - IndexType *pfree /* &A [0] ... pfree is in use */ - ) -{ - /* === Local variables ================================================== */ - - IndexType *psrc ; /* source pointer */ - IndexType *pdest ; /* destination pointer */ - IndexType j ; /* counter */ - IndexType r ; /* a row index */ - IndexType c ; /* a column index */ - IndexType length ; /* length of a row or column */ - - /* === Defragment the columns =========================================== */ - - pdest = &A[0] ; - for (c = 0 ; c < n_col ; c++) - { - if (Col[c].is_alive()) - { - psrc = &A [Col [c].start] ; - - /* move and compact the column */ - COLAMD_ASSERT (pdest <= psrc) ; - Col [c].start = (IndexType) (pdest - &A [0]) ; - length = Col [c].length ; - for (j = 0 ; j < length ; j++) - { - r = *psrc++ ; - if (Row[r].is_alive()) - { - *pdest++ = r ; - } - } - Col [c].length = (IndexType) (pdest - &A [Col [c].start]) ; - } - } - - /* === Prepare to defragment the rows =================================== */ - - for (r = 0 ; r < n_row ; r++) - { - if (Row[r].is_alive()) - { - if (Row [r].length == 0) - { - /* this row is of zero length. cannot compact it, so kill it */ - COLAMD_DEBUG3 (("Defrag row kill\n")) ; - Row[r].kill() ; - } - else - { - /* save first column index in Row [r].shared2.first_column */ - psrc = &A [Row [r].start] ; - Row [r].shared2.first_column = *psrc ; - COLAMD_ASSERT (Row[r].is_alive()) ; - /* flag the start of the row with the one's complement of row */ - *psrc = ones_complement(r) ; - - } - } - } - - /* === Defragment the rows ============================================== */ - - psrc = pdest ; - while (psrc < pfree) - { - /* find a negative number ... the start of a row */ - if (*psrc++ < 0) - { - psrc-- ; - /* get the row index */ - r = ones_complement(*psrc) ; - COLAMD_ASSERT (r >= 0 && r < n_row) ; - /* restore first column index */ - *psrc = Row [r].shared2.first_column ; - COLAMD_ASSERT (Row[r].is_alive()) ; - - /* move and compact the row */ - COLAMD_ASSERT (pdest <= psrc) ; - Row [r].start = (IndexType) (pdest - &A [0]) ; - length = Row [r].length ; - for (j = 0 ; j < length ; j++) - { - c = *psrc++ ; - if (Col[c].is_alive()) - { - *pdest++ = c ; - } - } - Row [r].length = (IndexType) (pdest - &A [Row [r].start]) ; - - } - } - /* ensure we found all the rows */ - COLAMD_ASSERT (debug_rows == 0) ; - - /* === Return the new value of pfree ==================================== */ - - return ((IndexType) (pdest - &A [0])) ; -} - - -/* ========================================================================== */ -/* === clear_mark =========================================================== */ -/* ========================================================================== */ - -/* - Clears the Row [].shared2.mark array, and returns the new tag_mark. - Return value is the new tag_mark. Not user-callable. -*/ -template <typename IndexType> -static inline IndexType clear_mark /* return the new value for tag_mark */ - ( - /* === Parameters ======================================================= */ - - IndexType n_row, /* number of rows in A */ - RowStructure<IndexType> Row [] /* Row [0 ... n_row-1].shared2.mark is set to zero */ - ) -{ - /* === Local variables ================================================== */ - - IndexType r ; - - for (r = 0 ; r < n_row ; r++) - { - if (Row[r].is_alive()) - { - Row [r].shared2.mark = 0 ; - } - } - return (1) ; -} - -} // namespace Colamd - -} // namespace internal -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Ordering.h b/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Ordering.h deleted file mode 100644 index c5789701..00000000 --- a/external/eigen/include/eigen3/Eigen/src/OrderingMethods/Ordering.h +++ /dev/null @@ -1,153 +0,0 @@ - -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ORDERING_H -#define EIGEN_ORDERING_H - -namespace Eigen { - -#include "Eigen_Colamd.h" - -namespace internal { - -/** \internal - * \ingroup OrderingMethods_Module - * \param[in] A the input non-symmetric matrix - * \param[out] symmat the symmetric pattern A^T+A from the input matrix \a A. - * FIXME: The values should not be considered here - */ -template<typename MatrixType> -void ordering_helper_at_plus_a(const MatrixType& A, MatrixType& symmat) -{ - MatrixType C; - C = A.transpose(); // NOTE: Could be costly - for (int i = 0; i < C.rows(); i++) - { - for (typename MatrixType::InnerIterator it(C, i); it; ++it) - it.valueRef() = typename MatrixType::Scalar(0); - } - symmat = C + A; -} - -} - -/** \ingroup OrderingMethods_Module - * \class AMDOrdering - * - * Functor computing the \em approximate \em minimum \em degree ordering - * If the matrix is not structurally symmetric, an ordering of A^T+A is computed - * \tparam StorageIndex The type of indices of the matrix - * \sa COLAMDOrdering - */ -template <typename StorageIndex> -class AMDOrdering -{ - public: - typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType; - - /** Compute the permutation vector from a sparse matrix - * This routine is much faster if the input matrix is column-major - */ - template <typename MatrixType> - void operator()(const MatrixType& mat, PermutationType& perm) - { - // Compute the symmetric pattern - SparseMatrix<typename MatrixType::Scalar, ColMajor, StorageIndex> symm; - internal::ordering_helper_at_plus_a(mat,symm); - - // Call the AMD routine - //m_mat.prune(keep_diag()); - internal::minimum_degree_ordering(symm, perm); - } - - /** Compute the permutation with a selfadjoint matrix */ - template <typename SrcType, unsigned int SrcUpLo> - void operator()(const SparseSelfAdjointView<SrcType, SrcUpLo>& mat, PermutationType& perm) - { - SparseMatrix<typename SrcType::Scalar, ColMajor, StorageIndex> C; C = mat; - - // Call the AMD routine - // m_mat.prune(keep_diag()); //Remove the diagonal elements - internal::minimum_degree_ordering(C, perm); - } -}; - -/** \ingroup OrderingMethods_Module - * \class NaturalOrdering - * - * Functor computing the natural ordering (identity) - * - * \note Returns an empty permutation matrix - * \tparam StorageIndex The type of indices of the matrix - */ -template <typename StorageIndex> -class NaturalOrdering -{ - public: - typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType; - - /** Compute the permutation vector from a column-major sparse matrix */ - template <typename MatrixType> - void operator()(const MatrixType& /*mat*/, PermutationType& perm) - { - perm.resize(0); - } - -}; - -/** \ingroup OrderingMethods_Module - * \class COLAMDOrdering - * - * \tparam StorageIndex The type of indices of the matrix - * - * Functor computing the \em column \em approximate \em minimum \em degree ordering - * The matrix should be in column-major and \b compressed format (see SparseMatrix::makeCompressed()). - */ -template<typename StorageIndex> -class COLAMDOrdering -{ - public: - typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType; - typedef Matrix<StorageIndex, Dynamic, 1> IndexVector; - - /** Compute the permutation vector \a perm form the sparse matrix \a mat - * \warning The input sparse matrix \a mat must be in compressed mode (see SparseMatrix::makeCompressed()). - */ - template <typename MatrixType> - void operator() (const MatrixType& mat, PermutationType& perm) - { - eigen_assert(mat.isCompressed() && "COLAMDOrdering requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it to COLAMDOrdering"); - - StorageIndex m = StorageIndex(mat.rows()); - StorageIndex n = StorageIndex(mat.cols()); - StorageIndex nnz = StorageIndex(mat.nonZeros()); - // Get the recommended value of Alen to be used by colamd - StorageIndex Alen = internal::Colamd::recommended(nnz, m, n); - // Set the default parameters - double knobs [internal::Colamd::NKnobs]; - StorageIndex stats [internal::Colamd::NStats]; - internal::Colamd::set_defaults(knobs); - - IndexVector p(n+1), A(Alen); - for(StorageIndex i=0; i <= n; i++) p(i) = mat.outerIndexPtr()[i]; - for(StorageIndex i=0; i < nnz; i++) A(i) = mat.innerIndexPtr()[i]; - // Call Colamd routine to compute the ordering - StorageIndex info = internal::Colamd::compute_ordering(m, n, Alen, A.data(), p.data(), knobs, stats); - EIGEN_UNUSED_VARIABLE(info); - eigen_assert( info && "COLAMD failed " ); - - perm.resize(n); - for (StorageIndex i = 0; i < n; i++) perm.indices()(p(i)) = i; - } -}; - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/PaStiXSupport/PaStiXSupport.h b/external/eigen/include/eigen3/Eigen/src/PaStiXSupport/PaStiXSupport.h deleted file mode 100644 index 37426877..00000000 --- a/external/eigen/include/eigen3/Eigen/src/PaStiXSupport/PaStiXSupport.h +++ /dev/null @@ -1,678 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PASTIXSUPPORT_H -#define EIGEN_PASTIXSUPPORT_H - -namespace Eigen { - -#if defined(DCOMPLEX) - #define PASTIX_COMPLEX COMPLEX - #define PASTIX_DCOMPLEX DCOMPLEX -#else - #define PASTIX_COMPLEX std::complex<float> - #define PASTIX_DCOMPLEX std::complex<double> -#endif - -/** \ingroup PaStiXSupport_Module - * \brief Interface to the PaStix solver - * - * This class is used to solve the linear systems A.X = B via the PaStix library. - * The matrix can be either real or complex, symmetric or not. - * - * \sa TutorialSparseDirectSolvers - */ -template<typename _MatrixType, bool IsStrSym = false> class PastixLU; -template<typename _MatrixType, int Options> class PastixLLT; -template<typename _MatrixType, int Options> class PastixLDLT; - -namespace internal -{ - - template<class Pastix> struct pastix_traits; - - template<typename _MatrixType> - struct pastix_traits< PastixLU<_MatrixType> > - { - typedef _MatrixType MatrixType; - typedef typename _MatrixType::Scalar Scalar; - typedef typename _MatrixType::RealScalar RealScalar; - typedef typename _MatrixType::StorageIndex StorageIndex; - }; - - template<typename _MatrixType, int Options> - struct pastix_traits< PastixLLT<_MatrixType,Options> > - { - typedef _MatrixType MatrixType; - typedef typename _MatrixType::Scalar Scalar; - typedef typename _MatrixType::RealScalar RealScalar; - typedef typename _MatrixType::StorageIndex StorageIndex; - }; - - template<typename _MatrixType, int Options> - struct pastix_traits< PastixLDLT<_MatrixType,Options> > - { - typedef _MatrixType MatrixType; - typedef typename _MatrixType::Scalar Scalar; - typedef typename _MatrixType::RealScalar RealScalar; - typedef typename _MatrixType::StorageIndex StorageIndex; - }; - - inline void eigen_pastix(pastix_data_t **pastix_data, int pastix_comm, int n, int *ptr, int *idx, float *vals, int *perm, int * invp, float *x, int nbrhs, int *iparm, double *dparm) - { - if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; } - if (nbrhs == 0) {x = NULL; nbrhs=1;} - s_pastix(pastix_data, pastix_comm, n, ptr, idx, vals, perm, invp, x, nbrhs, iparm, dparm); - } - - inline void eigen_pastix(pastix_data_t **pastix_data, int pastix_comm, int n, int *ptr, int *idx, double *vals, int *perm, int * invp, double *x, int nbrhs, int *iparm, double *dparm) - { - if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; } - if (nbrhs == 0) {x = NULL; nbrhs=1;} - d_pastix(pastix_data, pastix_comm, n, ptr, idx, vals, perm, invp, x, nbrhs, iparm, dparm); - } - - inline void eigen_pastix(pastix_data_t **pastix_data, int pastix_comm, int n, int *ptr, int *idx, std::complex<float> *vals, int *perm, int * invp, std::complex<float> *x, int nbrhs, int *iparm, double *dparm) - { - if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; } - if (nbrhs == 0) {x = NULL; nbrhs=1;} - c_pastix(pastix_data, pastix_comm, n, ptr, idx, reinterpret_cast<PASTIX_COMPLEX*>(vals), perm, invp, reinterpret_cast<PASTIX_COMPLEX*>(x), nbrhs, iparm, dparm); - } - - inline void eigen_pastix(pastix_data_t **pastix_data, int pastix_comm, int n, int *ptr, int *idx, std::complex<double> *vals, int *perm, int * invp, std::complex<double> *x, int nbrhs, int *iparm, double *dparm) - { - if (n == 0) { ptr = NULL; idx = NULL; vals = NULL; } - if (nbrhs == 0) {x = NULL; nbrhs=1;} - z_pastix(pastix_data, pastix_comm, n, ptr, idx, reinterpret_cast<PASTIX_DCOMPLEX*>(vals), perm, invp, reinterpret_cast<PASTIX_DCOMPLEX*>(x), nbrhs, iparm, dparm); - } - - // Convert the matrix to Fortran-style Numbering - template <typename MatrixType> - void c_to_fortran_numbering (MatrixType& mat) - { - if ( !(mat.outerIndexPtr()[0]) ) - { - int i; - for(i = 0; i <= mat.rows(); ++i) - ++mat.outerIndexPtr()[i]; - for(i = 0; i < mat.nonZeros(); ++i) - ++mat.innerIndexPtr()[i]; - } - } - - // Convert to C-style Numbering - template <typename MatrixType> - void fortran_to_c_numbering (MatrixType& mat) - { - // Check the Numbering - if ( mat.outerIndexPtr()[0] == 1 ) - { // Convert to C-style numbering - int i; - for(i = 0; i <= mat.rows(); ++i) - --mat.outerIndexPtr()[i]; - for(i = 0; i < mat.nonZeros(); ++i) - --mat.innerIndexPtr()[i]; - } - } -} - -// This is the base class to interface with PaStiX functions. -// Users should not used this class directly. -template <class Derived> -class PastixBase : public SparseSolverBase<Derived> -{ - protected: - typedef SparseSolverBase<Derived> Base; - using Base::derived; - using Base::m_isInitialized; - public: - using Base::_solve_impl; - - typedef typename internal::pastix_traits<Derived>::MatrixType _MatrixType; - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef Matrix<Scalar,Dynamic,1> Vector; - typedef SparseMatrix<Scalar, ColMajor> ColSpMatrix; - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - public: - - PastixBase() : m_initisOk(false), m_analysisIsOk(false), m_factorizationIsOk(false), m_pastixdata(0), m_size(0) - { - init(); - } - - ~PastixBase() - { - clean(); - } - - template<typename Rhs,typename Dest> - bool _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &x) const; - - /** Returns a reference to the integer vector IPARM of PaStiX parameters - * to modify the default parameters. - * The statistics related to the different phases of factorization and solve are saved here as well - * \sa analyzePattern() factorize() - */ - Array<StorageIndex,IPARM_SIZE,1>& iparm() - { - return m_iparm; - } - - /** Return a reference to a particular index parameter of the IPARM vector - * \sa iparm() - */ - - int& iparm(int idxparam) - { - return m_iparm(idxparam); - } - - /** Returns a reference to the double vector DPARM of PaStiX parameters - * The statistics related to the different phases of factorization and solve are saved here as well - * \sa analyzePattern() factorize() - */ - Array<double,DPARM_SIZE,1>& dparm() - { - return m_dparm; - } - - - /** Return a reference to a particular index parameter of the DPARM vector - * \sa dparm() - */ - double& dparm(int idxparam) - { - return m_dparm(idxparam); - } - - inline Index cols() const { return m_size; } - inline Index rows() const { return m_size; } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the PaStiX reports a problem - * \c InvalidInput if the input matrix is invalid - * - * \sa iparm() - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - - protected: - - // Initialize the Pastix data structure, check the matrix - void init(); - - // Compute the ordering and the symbolic factorization - void analyzePattern(ColSpMatrix& mat); - - // Compute the numerical factorization - void factorize(ColSpMatrix& mat); - - // Free all the data allocated by Pastix - void clean() - { - eigen_assert(m_initisOk && "The Pastix structure should be allocated first"); - m_iparm(IPARM_START_TASK) = API_TASK_CLEAN; - m_iparm(IPARM_END_TASK) = API_TASK_CLEAN; - internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, 0, 0, 0, (Scalar*)0, - m_perm.data(), m_invp.data(), 0, 0, m_iparm.data(), m_dparm.data()); - } - - void compute(ColSpMatrix& mat); - - int m_initisOk; - int m_analysisIsOk; - int m_factorizationIsOk; - mutable ComputationInfo m_info; - mutable pastix_data_t *m_pastixdata; // Data structure for pastix - mutable int m_comm; // The MPI communicator identifier - mutable Array<int,IPARM_SIZE,1> m_iparm; // integer vector for the input parameters - mutable Array<double,DPARM_SIZE,1> m_dparm; // Scalar vector for the input parameters - mutable Matrix<StorageIndex,Dynamic,1> m_perm; // Permutation vector - mutable Matrix<StorageIndex,Dynamic,1> m_invp; // Inverse permutation vector - mutable int m_size; // Size of the matrix -}; - - /** Initialize the PaStiX data structure. - *A first call to this function fills iparm and dparm with the default PaStiX parameters - * \sa iparm() dparm() - */ -template <class Derived> -void PastixBase<Derived>::init() -{ - m_size = 0; - m_iparm.setZero(IPARM_SIZE); - m_dparm.setZero(DPARM_SIZE); - - m_iparm(IPARM_MODIFY_PARAMETER) = API_NO; - pastix(&m_pastixdata, MPI_COMM_WORLD, - 0, 0, 0, 0, - 0, 0, 0, 1, m_iparm.data(), m_dparm.data()); - - m_iparm[IPARM_MATRIX_VERIFICATION] = API_NO; - m_iparm[IPARM_VERBOSE] = API_VERBOSE_NOT; - m_iparm[IPARM_ORDERING] = API_ORDER_SCOTCH; - m_iparm[IPARM_INCOMPLETE] = API_NO; - m_iparm[IPARM_OOC_LIMIT] = 2000; - m_iparm[IPARM_RHS_MAKING] = API_RHS_B; - m_iparm(IPARM_MATRIX_VERIFICATION) = API_NO; - - m_iparm(IPARM_START_TASK) = API_TASK_INIT; - m_iparm(IPARM_END_TASK) = API_TASK_INIT; - internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, 0, 0, 0, (Scalar*)0, - 0, 0, 0, 0, m_iparm.data(), m_dparm.data()); - - // Check the returned error - if(m_iparm(IPARM_ERROR_NUMBER)) { - m_info = InvalidInput; - m_initisOk = false; - } - else { - m_info = Success; - m_initisOk = true; - } -} - -template <class Derived> -void PastixBase<Derived>::compute(ColSpMatrix& mat) -{ - eigen_assert(mat.rows() == mat.cols() && "The input matrix should be squared"); - - analyzePattern(mat); - factorize(mat); - - m_iparm(IPARM_MATRIX_VERIFICATION) = API_NO; -} - - -template <class Derived> -void PastixBase<Derived>::analyzePattern(ColSpMatrix& mat) -{ - eigen_assert(m_initisOk && "The initialization of PaSTiX failed"); - - // clean previous calls - if(m_size>0) - clean(); - - m_size = internal::convert_index<int>(mat.rows()); - m_perm.resize(m_size); - m_invp.resize(m_size); - - m_iparm(IPARM_START_TASK) = API_TASK_ORDERING; - m_iparm(IPARM_END_TASK) = API_TASK_ANALYSE; - internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, m_size, mat.outerIndexPtr(), mat.innerIndexPtr(), - mat.valuePtr(), m_perm.data(), m_invp.data(), 0, 0, m_iparm.data(), m_dparm.data()); - - // Check the returned error - if(m_iparm(IPARM_ERROR_NUMBER)) - { - m_info = NumericalIssue; - m_analysisIsOk = false; - } - else - { - m_info = Success; - m_analysisIsOk = true; - } -} - -template <class Derived> -void PastixBase<Derived>::factorize(ColSpMatrix& mat) -{ -// if(&m_cpyMat != &mat) m_cpyMat = mat; - eigen_assert(m_analysisIsOk && "The analysis phase should be called before the factorization phase"); - m_iparm(IPARM_START_TASK) = API_TASK_NUMFACT; - m_iparm(IPARM_END_TASK) = API_TASK_NUMFACT; - m_size = internal::convert_index<int>(mat.rows()); - - internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, m_size, mat.outerIndexPtr(), mat.innerIndexPtr(), - mat.valuePtr(), m_perm.data(), m_invp.data(), 0, 0, m_iparm.data(), m_dparm.data()); - - // Check the returned error - if(m_iparm(IPARM_ERROR_NUMBER)) - { - m_info = NumericalIssue; - m_factorizationIsOk = false; - m_isInitialized = false; - } - else - { - m_info = Success; - m_factorizationIsOk = true; - m_isInitialized = true; - } -} - -/* Solve the system */ -template<typename Base> -template<typename Rhs,typename Dest> -bool PastixBase<Base>::_solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &x) const -{ - eigen_assert(m_isInitialized && "The matrix should be factorized first"); - EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0, - THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); - int rhs = 1; - - x = b; /* on return, x is overwritten by the computed solution */ - - for (int i = 0; i < b.cols(); i++){ - m_iparm[IPARM_START_TASK] = API_TASK_SOLVE; - m_iparm[IPARM_END_TASK] = API_TASK_REFINE; - - internal::eigen_pastix(&m_pastixdata, MPI_COMM_WORLD, internal::convert_index<int>(x.rows()), 0, 0, 0, - m_perm.data(), m_invp.data(), &x(0, i), rhs, m_iparm.data(), m_dparm.data()); - } - - // Check the returned error - m_info = m_iparm(IPARM_ERROR_NUMBER)==0 ? Success : NumericalIssue; - - return m_iparm(IPARM_ERROR_NUMBER)==0; -} - -/** \ingroup PaStiXSupport_Module - * \class PastixLU - * \brief Sparse direct LU solver based on PaStiX library - * - * This class is used to solve the linear systems A.X = B with a supernodal LU - * factorization in the PaStiX library. The matrix A should be squared and nonsingular - * PaStiX requires that the matrix A has a symmetric structural pattern. - * This interface can symmetrize the input matrix otherwise. - * The vectors or matrices X and B can be either dense or sparse. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam IsStrSym Indicates if the input matrix has a symmetric pattern, default is false - * NOTE : Note that if the analysis and factorization phase are called separately, - * the input matrix will be symmetrized at each call, hence it is advised to - * symmetrize the matrix in a end-user program and set \p IsStrSym to true - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class SparseLU - * - */ -template<typename _MatrixType, bool IsStrSym> -class PastixLU : public PastixBase< PastixLU<_MatrixType> > -{ - public: - typedef _MatrixType MatrixType; - typedef PastixBase<PastixLU<MatrixType> > Base; - typedef typename Base::ColSpMatrix ColSpMatrix; - typedef typename MatrixType::StorageIndex StorageIndex; - - public: - PastixLU() : Base() - { - init(); - } - - explicit PastixLU(const MatrixType& matrix):Base() - { - init(); - compute(matrix); - } - /** Compute the LU supernodal factorization of \p matrix. - * iparm and dparm can be used to tune the PaStiX parameters. - * see the PaStiX user's manual - * \sa analyzePattern() factorize() - */ - void compute (const MatrixType& matrix) - { - m_structureIsUptodate = false; - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::compute(temp); - } - /** Compute the LU symbolic factorization of \p matrix using its sparsity pattern. - * Several ordering methods can be used at this step. See the PaStiX user's manual. - * The result of this operation can be used with successive matrices having the same pattern as \p matrix - * \sa factorize() - */ - void analyzePattern(const MatrixType& matrix) - { - m_structureIsUptodate = false; - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::analyzePattern(temp); - } - - /** Compute the LU supernodal factorization of \p matrix - * WARNING The matrix \p matrix should have the same structural pattern - * as the same used in the analysis phase. - * \sa analyzePattern() - */ - void factorize(const MatrixType& matrix) - { - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::factorize(temp); - } - protected: - - void init() - { - m_structureIsUptodate = false; - m_iparm(IPARM_SYM) = API_SYM_NO; - m_iparm(IPARM_FACTORIZATION) = API_FACT_LU; - } - - void grabMatrix(const MatrixType& matrix, ColSpMatrix& out) - { - if(IsStrSym) - out = matrix; - else - { - if(!m_structureIsUptodate) - { - // update the transposed structure - m_transposedStructure = matrix.transpose(); - - // Set the elements of the matrix to zero - for (Index j=0; j<m_transposedStructure.outerSize(); ++j) - for(typename ColSpMatrix::InnerIterator it(m_transposedStructure, j); it; ++it) - it.valueRef() = 0.0; - - m_structureIsUptodate = true; - } - - out = m_transposedStructure + matrix; - } - internal::c_to_fortran_numbering(out); - } - - using Base::m_iparm; - using Base::m_dparm; - - ColSpMatrix m_transposedStructure; - bool m_structureIsUptodate; -}; - -/** \ingroup PaStiXSupport_Module - * \class PastixLLT - * \brief A sparse direct supernodal Cholesky (LLT) factorization and solver based on the PaStiX library - * - * This class is used to solve the linear systems A.X = B via a LL^T supernodal Cholesky factorization - * available in the PaStiX library. The matrix A should be symmetric and positive definite - * WARNING Selfadjoint complex matrices are not supported in the current version of PaStiX - * The vectors or matrices X and B can be either dense or sparse - * - * \tparam MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam UpLo The part of the matrix to use : Lower or Upper. The default is Lower as required by PaStiX - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class SimplicialLLT - */ -template<typename _MatrixType, int _UpLo> -class PastixLLT : public PastixBase< PastixLLT<_MatrixType, _UpLo> > -{ - public: - typedef _MatrixType MatrixType; - typedef PastixBase<PastixLLT<MatrixType, _UpLo> > Base; - typedef typename Base::ColSpMatrix ColSpMatrix; - - public: - enum { UpLo = _UpLo }; - PastixLLT() : Base() - { - init(); - } - - explicit PastixLLT(const MatrixType& matrix):Base() - { - init(); - compute(matrix); - } - - /** Compute the L factor of the LL^T supernodal factorization of \p matrix - * \sa analyzePattern() factorize() - */ - void compute (const MatrixType& matrix) - { - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::compute(temp); - } - - /** Compute the LL^T symbolic factorization of \p matrix using its sparsity pattern - * The result of this operation can be used with successive matrices having the same pattern as \p matrix - * \sa factorize() - */ - void analyzePattern(const MatrixType& matrix) - { - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::analyzePattern(temp); - } - /** Compute the LL^T supernodal numerical factorization of \p matrix - * \sa analyzePattern() - */ - void factorize(const MatrixType& matrix) - { - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::factorize(temp); - } - protected: - using Base::m_iparm; - - void init() - { - m_iparm(IPARM_SYM) = API_SYM_YES; - m_iparm(IPARM_FACTORIZATION) = API_FACT_LLT; - } - - void grabMatrix(const MatrixType& matrix, ColSpMatrix& out) - { - out.resize(matrix.rows(), matrix.cols()); - // Pastix supports only lower, column-major matrices - out.template selfadjointView<Lower>() = matrix.template selfadjointView<UpLo>(); - internal::c_to_fortran_numbering(out); - } -}; - -/** \ingroup PaStiXSupport_Module - * \class PastixLDLT - * \brief A sparse direct supernodal Cholesky (LLT) factorization and solver based on the PaStiX library - * - * This class is used to solve the linear systems A.X = B via a LDL^T supernodal Cholesky factorization - * available in the PaStiX library. The matrix A should be symmetric and positive definite - * WARNING Selfadjoint complex matrices are not supported in the current version of PaStiX - * The vectors or matrices X and B can be either dense or sparse - * - * \tparam MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam UpLo The part of the matrix to use : Lower or Upper. The default is Lower as required by PaStiX - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class SimplicialLDLT - */ -template<typename _MatrixType, int _UpLo> -class PastixLDLT : public PastixBase< PastixLDLT<_MatrixType, _UpLo> > -{ - public: - typedef _MatrixType MatrixType; - typedef PastixBase<PastixLDLT<MatrixType, _UpLo> > Base; - typedef typename Base::ColSpMatrix ColSpMatrix; - - public: - enum { UpLo = _UpLo }; - PastixLDLT():Base() - { - init(); - } - - explicit PastixLDLT(const MatrixType& matrix):Base() - { - init(); - compute(matrix); - } - - /** Compute the L and D factors of the LDL^T factorization of \p matrix - * \sa analyzePattern() factorize() - */ - void compute (const MatrixType& matrix) - { - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::compute(temp); - } - - /** Compute the LDL^T symbolic factorization of \p matrix using its sparsity pattern - * The result of this operation can be used with successive matrices having the same pattern as \p matrix - * \sa factorize() - */ - void analyzePattern(const MatrixType& matrix) - { - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::analyzePattern(temp); - } - /** Compute the LDL^T supernodal numerical factorization of \p matrix - * - */ - void factorize(const MatrixType& matrix) - { - ColSpMatrix temp; - grabMatrix(matrix, temp); - Base::factorize(temp); - } - - protected: - using Base::m_iparm; - - void init() - { - m_iparm(IPARM_SYM) = API_SYM_YES; - m_iparm(IPARM_FACTORIZATION) = API_FACT_LDLT; - } - - void grabMatrix(const MatrixType& matrix, ColSpMatrix& out) - { - // Pastix supports only lower, column-major matrices - out.resize(matrix.rows(), matrix.cols()); - out.template selfadjointView<Lower>() = matrix.template selfadjointView<UpLo>(); - internal::c_to_fortran_numbering(out); - } -}; - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/PardisoSupport/PardisoSupport.h b/external/eigen/include/eigen3/Eigen/src/PardisoSupport/PardisoSupport.h deleted file mode 100644 index f89b79bd..00000000 --- a/external/eigen/include/eigen3/Eigen/src/PardisoSupport/PardisoSupport.h +++ /dev/null @@ -1,545 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to Intel(R) MKL PARDISO - ******************************************************************************** -*/ - -#ifndef EIGEN_PARDISOSUPPORT_H -#define EIGEN_PARDISOSUPPORT_H - -namespace Eigen { - -template<typename _MatrixType> class PardisoLU; -template<typename _MatrixType, int Options=Upper> class PardisoLLT; -template<typename _MatrixType, int Options=Upper> class PardisoLDLT; - -namespace internal -{ - template<typename IndexType> - struct pardiso_run_selector - { - static IndexType run( _MKL_DSS_HANDLE_t pt, IndexType maxfct, IndexType mnum, IndexType type, IndexType phase, IndexType n, void *a, - IndexType *ia, IndexType *ja, IndexType *perm, IndexType nrhs, IndexType *iparm, IndexType msglvl, void *b, void *x) - { - IndexType error = 0; - ::pardiso(pt, &maxfct, &mnum, &type, &phase, &n, a, ia, ja, perm, &nrhs, iparm, &msglvl, b, x, &error); - return error; - } - }; - template<> - struct pardiso_run_selector<long long int> - { - typedef long long int IndexType; - static IndexType run( _MKL_DSS_HANDLE_t pt, IndexType maxfct, IndexType mnum, IndexType type, IndexType phase, IndexType n, void *a, - IndexType *ia, IndexType *ja, IndexType *perm, IndexType nrhs, IndexType *iparm, IndexType msglvl, void *b, void *x) - { - IndexType error = 0; - ::pardiso_64(pt, &maxfct, &mnum, &type, &phase, &n, a, ia, ja, perm, &nrhs, iparm, &msglvl, b, x, &error); - return error; - } - }; - - template<class Pardiso> struct pardiso_traits; - - template<typename _MatrixType> - struct pardiso_traits< PardisoLU<_MatrixType> > - { - typedef _MatrixType MatrixType; - typedef typename _MatrixType::Scalar Scalar; - typedef typename _MatrixType::RealScalar RealScalar; - typedef typename _MatrixType::StorageIndex StorageIndex; - }; - - template<typename _MatrixType, int Options> - struct pardiso_traits< PardisoLLT<_MatrixType, Options> > - { - typedef _MatrixType MatrixType; - typedef typename _MatrixType::Scalar Scalar; - typedef typename _MatrixType::RealScalar RealScalar; - typedef typename _MatrixType::StorageIndex StorageIndex; - }; - - template<typename _MatrixType, int Options> - struct pardiso_traits< PardisoLDLT<_MatrixType, Options> > - { - typedef _MatrixType MatrixType; - typedef typename _MatrixType::Scalar Scalar; - typedef typename _MatrixType::RealScalar RealScalar; - typedef typename _MatrixType::StorageIndex StorageIndex; - }; - -} // end namespace internal - -template<class Derived> -class PardisoImpl : public SparseSolverBase<Derived> -{ - protected: - typedef SparseSolverBase<Derived> Base; - using Base::derived; - using Base::m_isInitialized; - - typedef internal::pardiso_traits<Derived> Traits; - public: - using Base::_solve_impl; - - typedef typename Traits::MatrixType MatrixType; - typedef typename Traits::Scalar Scalar; - typedef typename Traits::RealScalar RealScalar; - typedef typename Traits::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar,RowMajor,StorageIndex> SparseMatrixType; - typedef Matrix<Scalar,Dynamic,1> VectorType; - typedef Matrix<StorageIndex, 1, MatrixType::ColsAtCompileTime> IntRowVectorType; - typedef Matrix<StorageIndex, MatrixType::RowsAtCompileTime, 1> IntColVectorType; - typedef Array<StorageIndex,64,1,DontAlign> ParameterType; - enum { - ScalarIsComplex = NumTraits<Scalar>::IsComplex, - ColsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic - }; - - PardisoImpl() - : m_analysisIsOk(false), m_factorizationIsOk(false) - { - eigen_assert((sizeof(StorageIndex) >= sizeof(_INTEGER_t) && sizeof(StorageIndex) <= 8) && "Non-supported index type"); - m_iparm.setZero(); - m_msglvl = 0; // No output - m_isInitialized = false; - } - - ~PardisoImpl() - { - pardisoRelease(); - } - - inline Index cols() const { return m_size; } - inline Index rows() const { return m_size; } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix appears to be negative. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - - /** \warning for advanced usage only. - * \returns a reference to the parameter array controlling PARDISO. - * See the PARDISO manual to know how to use it. */ - ParameterType& pardisoParameterArray() - { - return m_iparm; - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize() - */ - Derived& analyzePattern(const MatrixType& matrix); - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must has the same sparcity than the matrix on which the symbolic decomposition has been performed. - * - * \sa analyzePattern() - */ - Derived& factorize(const MatrixType& matrix); - - Derived& compute(const MatrixType& matrix); - - template<typename Rhs,typename Dest> - void _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &dest) const; - - protected: - void pardisoRelease() - { - if(m_isInitialized) // Factorization ran at least once - { - internal::pardiso_run_selector<StorageIndex>::run(m_pt, 1, 1, m_type, -1, internal::convert_index<StorageIndex>(m_size),0, 0, 0, m_perm.data(), 0, - m_iparm.data(), m_msglvl, NULL, NULL); - m_isInitialized = false; - } - } - - void pardisoInit(int type) - { - m_type = type; - bool symmetric = std::abs(m_type) < 10; - m_iparm[0] = 1; // No solver default - m_iparm[1] = 2; // use Metis for the ordering - m_iparm[2] = 0; // Reserved. Set to zero. (??Numbers of processors, value of OMP_NUM_THREADS??) - m_iparm[3] = 0; // No iterative-direct algorithm - m_iparm[4] = 0; // No user fill-in reducing permutation - m_iparm[5] = 0; // Write solution into x, b is left unchanged - m_iparm[6] = 0; // Not in use - m_iparm[7] = 2; // Max numbers of iterative refinement steps - m_iparm[8] = 0; // Not in use - m_iparm[9] = 13; // Perturb the pivot elements with 1E-13 - m_iparm[10] = symmetric ? 0 : 1; // Use nonsymmetric permutation and scaling MPS - m_iparm[11] = 0; // Not in use - m_iparm[12] = symmetric ? 0 : 1; // Maximum weighted matching algorithm is switched-off (default for symmetric). - // Try m_iparm[12] = 1 in case of inappropriate accuracy - m_iparm[13] = 0; // Output: Number of perturbed pivots - m_iparm[14] = 0; // Not in use - m_iparm[15] = 0; // Not in use - m_iparm[16] = 0; // Not in use - m_iparm[17] = -1; // Output: Number of nonzeros in the factor LU - m_iparm[18] = -1; // Output: Mflops for LU factorization - m_iparm[19] = 0; // Output: Numbers of CG Iterations - - m_iparm[20] = 0; // 1x1 pivoting - m_iparm[26] = 0; // No matrix checker - m_iparm[27] = (sizeof(RealScalar) == 4) ? 1 : 0; - m_iparm[34] = 1; // C indexing - m_iparm[36] = 0; // CSR - m_iparm[59] = 0; // 0 - In-Core ; 1 - Automatic switch between In-Core and Out-of-Core modes ; 2 - Out-of-Core - - memset(m_pt, 0, sizeof(m_pt)); - } - - protected: - // cached data to reduce reallocation, etc. - - void manageErrorCode(Index error) const - { - switch(error) - { - case 0: - m_info = Success; - break; - case -4: - case -7: - m_info = NumericalIssue; - break; - default: - m_info = InvalidInput; - } - } - - mutable SparseMatrixType m_matrix; - mutable ComputationInfo m_info; - bool m_analysisIsOk, m_factorizationIsOk; - StorageIndex m_type, m_msglvl; - mutable void *m_pt[64]; - mutable ParameterType m_iparm; - mutable IntColVectorType m_perm; - Index m_size; - -}; - -template<class Derived> -Derived& PardisoImpl<Derived>::compute(const MatrixType& a) -{ - m_size = a.rows(); - eigen_assert(a.rows() == a.cols()); - - pardisoRelease(); - m_perm.setZero(m_size); - derived().getMatrix(a); - - Index error; - error = internal::pardiso_run_selector<StorageIndex>::run(m_pt, 1, 1, m_type, 12, internal::convert_index<StorageIndex>(m_size), - m_matrix.valuePtr(), m_matrix.outerIndexPtr(), m_matrix.innerIndexPtr(), - m_perm.data(), 0, m_iparm.data(), m_msglvl, NULL, NULL); - manageErrorCode(error); - m_analysisIsOk = true; - m_factorizationIsOk = true; - m_isInitialized = true; - return derived(); -} - -template<class Derived> -Derived& PardisoImpl<Derived>::analyzePattern(const MatrixType& a) -{ - m_size = a.rows(); - eigen_assert(m_size == a.cols()); - - pardisoRelease(); - m_perm.setZero(m_size); - derived().getMatrix(a); - - Index error; - error = internal::pardiso_run_selector<StorageIndex>::run(m_pt, 1, 1, m_type, 11, internal::convert_index<StorageIndex>(m_size), - m_matrix.valuePtr(), m_matrix.outerIndexPtr(), m_matrix.innerIndexPtr(), - m_perm.data(), 0, m_iparm.data(), m_msglvl, NULL, NULL); - - manageErrorCode(error); - m_analysisIsOk = true; - m_factorizationIsOk = false; - m_isInitialized = true; - return derived(); -} - -template<class Derived> -Derived& PardisoImpl<Derived>::factorize(const MatrixType& a) -{ - eigen_assert(m_analysisIsOk && "You must first call analyzePattern()"); - eigen_assert(m_size == a.rows() && m_size == a.cols()); - - derived().getMatrix(a); - - Index error; - error = internal::pardiso_run_selector<StorageIndex>::run(m_pt, 1, 1, m_type, 22, internal::convert_index<StorageIndex>(m_size), - m_matrix.valuePtr(), m_matrix.outerIndexPtr(), m_matrix.innerIndexPtr(), - m_perm.data(), 0, m_iparm.data(), m_msglvl, NULL, NULL); - - manageErrorCode(error); - m_factorizationIsOk = true; - return derived(); -} - -template<class Derived> -template<typename BDerived,typename XDerived> -void PardisoImpl<Derived>::_solve_impl(const MatrixBase<BDerived> &b, MatrixBase<XDerived>& x) const -{ - if(m_iparm[0] == 0) // Factorization was not computed - { - m_info = InvalidInput; - return; - } - - //Index n = m_matrix.rows(); - Index nrhs = Index(b.cols()); - eigen_assert(m_size==b.rows()); - eigen_assert(((MatrixBase<BDerived>::Flags & RowMajorBit) == 0 || nrhs == 1) && "Row-major right hand sides are not supported"); - eigen_assert(((MatrixBase<XDerived>::Flags & RowMajorBit) == 0 || nrhs == 1) && "Row-major matrices of unknowns are not supported"); - eigen_assert(((nrhs == 1) || b.outerStride() == b.rows())); - - -// switch (transposed) { -// case SvNoTrans : m_iparm[11] = 0 ; break; -// case SvTranspose : m_iparm[11] = 2 ; break; -// case SvAdjoint : m_iparm[11] = 1 ; break; -// default: -// //std::cerr << "Eigen: transposition option \"" << transposed << "\" not supported by the PARDISO backend\n"; -// m_iparm[11] = 0; -// } - - Scalar* rhs_ptr = const_cast<Scalar*>(b.derived().data()); - Matrix<Scalar,Dynamic,Dynamic,ColMajor> tmp; - - // Pardiso cannot solve in-place - if(rhs_ptr == x.derived().data()) - { - tmp = b; - rhs_ptr = tmp.data(); - } - - Index error; - error = internal::pardiso_run_selector<StorageIndex>::run(m_pt, 1, 1, m_type, 33, internal::convert_index<StorageIndex>(m_size), - m_matrix.valuePtr(), m_matrix.outerIndexPtr(), m_matrix.innerIndexPtr(), - m_perm.data(), internal::convert_index<StorageIndex>(nrhs), m_iparm.data(), m_msglvl, - rhs_ptr, x.derived().data()); - - manageErrorCode(error); -} - - -/** \ingroup PardisoSupport_Module - * \class PardisoLU - * \brief A sparse direct LU factorization and solver based on the PARDISO library - * - * This class allows to solve for A.X = B sparse linear problems via a direct LU factorization - * using the Intel MKL PARDISO library. The sparse matrix A must be squared and invertible. - * The vectors or matrices X and B can be either dense or sparse. - * - * By default, it runs in in-core mode. To enable PARDISO's out-of-core feature, set: - * \code solver.pardisoParameterArray()[59] = 1; \endcode - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class SparseLU - */ -template<typename MatrixType> -class PardisoLU : public PardisoImpl< PardisoLU<MatrixType> > -{ - protected: - typedef PardisoImpl<PardisoLU> Base; - using Base::pardisoInit; - using Base::m_matrix; - friend class PardisoImpl< PardisoLU<MatrixType> >; - - public: - - typedef typename Base::Scalar Scalar; - typedef typename Base::RealScalar RealScalar; - - using Base::compute; - using Base::solve; - - PardisoLU() - : Base() - { - pardisoInit(Base::ScalarIsComplex ? 13 : 11); - } - - explicit PardisoLU(const MatrixType& matrix) - : Base() - { - pardisoInit(Base::ScalarIsComplex ? 13 : 11); - compute(matrix); - } - protected: - void getMatrix(const MatrixType& matrix) - { - m_matrix = matrix; - m_matrix.makeCompressed(); - } -}; - -/** \ingroup PardisoSupport_Module - * \class PardisoLLT - * \brief A sparse direct Cholesky (LLT) factorization and solver based on the PARDISO library - * - * This class allows to solve for A.X = B sparse linear problems via a LL^T Cholesky factorization - * using the Intel MKL PARDISO library. The sparse matrix A must be selfajoint and positive definite. - * The vectors or matrices X and B can be either dense or sparse. - * - * By default, it runs in in-core mode. To enable PARDISO's out-of-core feature, set: - * \code solver.pardisoParameterArray()[59] = 1; \endcode - * - * \tparam MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam UpLo can be any bitwise combination of Upper, Lower. The default is Upper, meaning only the upper triangular part has to be used. - * Upper|Lower can be used to tell both triangular parts can be used as input. - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class SimplicialLLT - */ -template<typename MatrixType, int _UpLo> -class PardisoLLT : public PardisoImpl< PardisoLLT<MatrixType,_UpLo> > -{ - protected: - typedef PardisoImpl< PardisoLLT<MatrixType,_UpLo> > Base; - using Base::pardisoInit; - using Base::m_matrix; - friend class PardisoImpl< PardisoLLT<MatrixType,_UpLo> >; - - public: - - typedef typename Base::Scalar Scalar; - typedef typename Base::RealScalar RealScalar; - typedef typename Base::StorageIndex StorageIndex; - enum { UpLo = _UpLo }; - using Base::compute; - - PardisoLLT() - : Base() - { - pardisoInit(Base::ScalarIsComplex ? 4 : 2); - } - - explicit PardisoLLT(const MatrixType& matrix) - : Base() - { - pardisoInit(Base::ScalarIsComplex ? 4 : 2); - compute(matrix); - } - - protected: - - void getMatrix(const MatrixType& matrix) - { - // PARDISO supports only upper, row-major matrices - PermutationMatrix<Dynamic,Dynamic,StorageIndex> p_null; - m_matrix.resize(matrix.rows(), matrix.cols()); - m_matrix.template selfadjointView<Upper>() = matrix.template selfadjointView<UpLo>().twistedBy(p_null); - m_matrix.makeCompressed(); - } -}; - -/** \ingroup PardisoSupport_Module - * \class PardisoLDLT - * \brief A sparse direct Cholesky (LDLT) factorization and solver based on the PARDISO library - * - * This class allows to solve for A.X = B sparse linear problems via a LDL^T Cholesky factorization - * using the Intel MKL PARDISO library. The sparse matrix A is assumed to be selfajoint and positive definite. - * For complex matrices, A can also be symmetric only, see the \a Options template parameter. - * The vectors or matrices X and B can be either dense or sparse. - * - * By default, it runs in in-core mode. To enable PARDISO's out-of-core feature, set: - * \code solver.pardisoParameterArray()[59] = 1; \endcode - * - * \tparam MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam Options can be any bitwise combination of Upper, Lower, and Symmetric. The default is Upper, meaning only the upper triangular part has to be used. - * Symmetric can be used for symmetric, non-selfadjoint complex matrices, the default being to assume a selfadjoint matrix. - * Upper|Lower can be used to tell both triangular parts can be used as input. - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class SimplicialLDLT - */ -template<typename MatrixType, int Options> -class PardisoLDLT : public PardisoImpl< PardisoLDLT<MatrixType,Options> > -{ - protected: - typedef PardisoImpl< PardisoLDLT<MatrixType,Options> > Base; - using Base::pardisoInit; - using Base::m_matrix; - friend class PardisoImpl< PardisoLDLT<MatrixType,Options> >; - - public: - - typedef typename Base::Scalar Scalar; - typedef typename Base::RealScalar RealScalar; - typedef typename Base::StorageIndex StorageIndex; - using Base::compute; - enum { UpLo = Options&(Upper|Lower) }; - - PardisoLDLT() - : Base() - { - pardisoInit(Base::ScalarIsComplex ? ( bool(Options&Symmetric) ? 6 : -4 ) : -2); - } - - explicit PardisoLDLT(const MatrixType& matrix) - : Base() - { - pardisoInit(Base::ScalarIsComplex ? ( bool(Options&Symmetric) ? 6 : -4 ) : -2); - compute(matrix); - } - - void getMatrix(const MatrixType& matrix) - { - // PARDISO supports only upper, row-major matrices - PermutationMatrix<Dynamic,Dynamic,StorageIndex> p_null; - m_matrix.resize(matrix.rows(), matrix.cols()); - m_matrix.template selfadjointView<Upper>() = matrix.template selfadjointView<UpLo>().twistedBy(p_null); - m_matrix.makeCompressed(); - } -}; - -} // end namespace Eigen - -#endif // EIGEN_PARDISOSUPPORT_H diff --git a/external/eigen/include/eigen3/Eigen/src/QR/ColPivHouseholderQR.h b/external/eigen/include/eigen3/Eigen/src/QR/ColPivHouseholderQR.h deleted file mode 100644 index 9b677e9b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/QR/ColPivHouseholderQR.h +++ /dev/null @@ -1,674 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_H -#define EIGEN_COLPIVOTINGHOUSEHOLDERQR_H - -namespace Eigen { - -namespace internal { -template<typename _MatrixType> struct traits<ColPivHouseholderQR<_MatrixType> > - : traits<_MatrixType> -{ - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - enum { Flags = 0 }; -}; - -} // end namespace internal - -/** \ingroup QR_Module - * - * \class ColPivHouseholderQR - * - * \brief Householder rank-revealing QR decomposition of a matrix with column-pivoting - * - * \tparam _MatrixType the type of the matrix of which we are computing the QR decomposition - * - * This class performs a rank-revealing QR decomposition of a matrix \b A into matrices \b P, \b Q and \b R - * such that - * \f[ - * \mathbf{A} \, \mathbf{P} = \mathbf{Q} \, \mathbf{R} - * \f] - * by using Householder transformations. Here, \b P is a permutation matrix, \b Q a unitary matrix and \b R an - * upper triangular matrix. - * - * This decomposition performs column pivoting in order to be rank-revealing and improve - * numerical stability. It is slower than HouseholderQR, and faster than FullPivHouseholderQR. - * - * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. - * - * \sa MatrixBase::colPivHouseholderQr() - */ -template<typename _MatrixType> class ColPivHouseholderQR - : public SolverBase<ColPivHouseholderQR<_MatrixType> > -{ - public: - - typedef _MatrixType MatrixType; - typedef SolverBase<ColPivHouseholderQR> Base; - friend class SolverBase<ColPivHouseholderQR>; - - EIGEN_GENERIC_PUBLIC_INTERFACE(ColPivHouseholderQR) - enum { - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType; - typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationType; - typedef typename internal::plain_row_type<MatrixType, Index>::type IntRowVectorType; - typedef typename internal::plain_row_type<MatrixType>::type RowVectorType; - typedef typename internal::plain_row_type<MatrixType, RealScalar>::type RealRowVectorType; - typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename HCoeffsType::ConjugateReturnType>::type> HouseholderSequenceType; - typedef typename MatrixType::PlainObject PlainObject; - - private: - - typedef typename PermutationType::StorageIndex PermIndexType; - - public: - - /** - * \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via ColPivHouseholderQR::compute(const MatrixType&). - */ - ColPivHouseholderQR() - : m_qr(), - m_hCoeffs(), - m_colsPermutation(), - m_colsTranspositions(), - m_temp(), - m_colNormsUpdated(), - m_colNormsDirect(), - m_isInitialized(false), - m_usePrescribedThreshold(false) {} - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa ColPivHouseholderQR() - */ - ColPivHouseholderQR(Index rows, Index cols) - : m_qr(rows, cols), - m_hCoeffs((std::min)(rows,cols)), - m_colsPermutation(PermIndexType(cols)), - m_colsTranspositions(cols), - m_temp(cols), - m_colNormsUpdated(cols), - m_colNormsDirect(cols), - m_isInitialized(false), - m_usePrescribedThreshold(false) {} - - /** \brief Constructs a QR factorization from a given matrix - * - * This constructor computes the QR factorization of the matrix \a matrix by calling - * the method compute(). It is a short cut for: - * - * \code - * ColPivHouseholderQR<MatrixType> qr(matrix.rows(), matrix.cols()); - * qr.compute(matrix); - * \endcode - * - * \sa compute() - */ - template<typename InputType> - explicit ColPivHouseholderQR(const EigenBase<InputType>& matrix) - : m_qr(matrix.rows(), matrix.cols()), - m_hCoeffs((std::min)(matrix.rows(),matrix.cols())), - m_colsPermutation(PermIndexType(matrix.cols())), - m_colsTranspositions(matrix.cols()), - m_temp(matrix.cols()), - m_colNormsUpdated(matrix.cols()), - m_colNormsDirect(matrix.cols()), - m_isInitialized(false), - m_usePrescribedThreshold(false) - { - compute(matrix.derived()); - } - - /** \brief Constructs a QR factorization from a given matrix - * - * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref. - * - * \sa ColPivHouseholderQR(const EigenBase&) - */ - template<typename InputType> - explicit ColPivHouseholderQR(EigenBase<InputType>& matrix) - : m_qr(matrix.derived()), - m_hCoeffs((std::min)(matrix.rows(),matrix.cols())), - m_colsPermutation(PermIndexType(matrix.cols())), - m_colsTranspositions(matrix.cols()), - m_temp(matrix.cols()), - m_colNormsUpdated(matrix.cols()), - m_colNormsDirect(matrix.cols()), - m_isInitialized(false), - m_usePrescribedThreshold(false) - { - computeInPlace(); - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** This method finds a solution x to the equation Ax=b, where A is the matrix of which - * *this is the QR decomposition, if any exists. - * - * \param b the right-hand-side of the equation to solve. - * - * \returns a solution. - * - * \note_about_checking_solutions - * - * \note_about_arbitrary_choice_of_solution - * - * Example: \include ColPivHouseholderQR_solve.cpp - * Output: \verbinclude ColPivHouseholderQR_solve.out - */ - template<typename Rhs> - inline const Solve<ColPivHouseholderQR, Rhs> - solve(const MatrixBase<Rhs>& b) const; - #endif - - HouseholderSequenceType householderQ() const; - HouseholderSequenceType matrixQ() const - { - return householderQ(); - } - - /** \returns a reference to the matrix where the Householder QR decomposition is stored - */ - const MatrixType& matrixQR() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return m_qr; - } - - /** \returns a reference to the matrix where the result Householder QR is stored - * \warning The strict lower part of this matrix contains internal values. - * Only the upper triangular part should be referenced. To get it, use - * \code matrixR().template triangularView<Upper>() \endcode - * For rank-deficient matrices, use - * \code - * matrixR().topLeftCorner(rank(), rank()).template triangularView<Upper>() - * \endcode - */ - const MatrixType& matrixR() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return m_qr; - } - - template<typename InputType> - ColPivHouseholderQR& compute(const EigenBase<InputType>& matrix); - - /** \returns a const reference to the column permutation matrix */ - const PermutationType& colsPermutation() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return m_colsPermutation; - } - - /** \returns the absolute value of the determinant of the matrix of which - * *this is the QR decomposition. It has only linear complexity - * (that is, O(n) where n is the dimension of the square matrix) - * as the QR decomposition has already been computed. - * - * \note This is only for square matrices. - * - * \warning a determinant can be very big or small, so for matrices - * of large enough dimension, there is a risk of overflow/underflow. - * One way to work around that is to use logAbsDeterminant() instead. - * - * \sa logAbsDeterminant(), MatrixBase::determinant() - */ - typename MatrixType::RealScalar absDeterminant() const; - - /** \returns the natural log of the absolute value of the determinant of the matrix of which - * *this is the QR decomposition. It has only linear complexity - * (that is, O(n) where n is the dimension of the square matrix) - * as the QR decomposition has already been computed. - * - * \note This is only for square matrices. - * - * \note This method is useful to work around the risk of overflow/underflow that's inherent - * to determinant computation. - * - * \sa absDeterminant(), MatrixBase::determinant() - */ - typename MatrixType::RealScalar logAbsDeterminant() const; - - /** \returns the rank of the matrix of which *this is the QR decomposition. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline Index rank() const - { - using std::abs; - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); - Index result = 0; - for(Index i = 0; i < m_nonzero_pivots; ++i) - result += (abs(m_qr.coeff(i,i)) > premultiplied_threshold); - return result; - } - - /** \returns the dimension of the kernel of the matrix of which *this is the QR decomposition. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline Index dimensionOfKernel() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return cols() - rank(); - } - - /** \returns true if the matrix of which *this is the QR decomposition represents an injective - * linear map, i.e. has trivial kernel; false otherwise. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isInjective() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return rank() == cols(); - } - - /** \returns true if the matrix of which *this is the QR decomposition represents a surjective - * linear map; false otherwise. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isSurjective() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return rank() == rows(); - } - - /** \returns true if the matrix of which *this is the QR decomposition is invertible. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isInvertible() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return isInjective() && isSurjective(); - } - - /** \returns the inverse of the matrix of which *this is the QR decomposition. - * - * \note If this matrix is not invertible, the returned matrix has undefined coefficients. - * Use isInvertible() to first determine whether this matrix is invertible. - */ - inline const Inverse<ColPivHouseholderQR> inverse() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return Inverse<ColPivHouseholderQR>(*this); - } - - inline Index rows() const { return m_qr.rows(); } - inline Index cols() const { return m_qr.cols(); } - - /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q. - * - * For advanced uses only. - */ - const HCoeffsType& hCoeffs() const { return m_hCoeffs; } - - /** Allows to prescribe a threshold to be used by certain methods, such as rank(), - * who need to determine when pivots are to be considered nonzero. This is not used for the - * QR decomposition itself. - * - * When it needs to get the threshold value, Eigen calls threshold(). By default, this - * uses a formula to automatically determine a reasonable threshold. - * Once you have called the present method setThreshold(const RealScalar&), - * your value is used instead. - * - * \param threshold The new value to use as the threshold. - * - * A pivot will be considered nonzero if its absolute value is strictly greater than - * \f$ \vert pivot \vert \leqslant threshold \times \vert maxpivot \vert \f$ - * where maxpivot is the biggest pivot. - * - * If you want to come back to the default behavior, call setThreshold(Default_t) - */ - ColPivHouseholderQR& setThreshold(const RealScalar& threshold) - { - m_usePrescribedThreshold = true; - m_prescribedThreshold = threshold; - return *this; - } - - /** Allows to come back to the default behavior, letting Eigen use its default formula for - * determining the threshold. - * - * You should pass the special object Eigen::Default as parameter here. - * \code qr.setThreshold(Eigen::Default); \endcode - * - * See the documentation of setThreshold(const RealScalar&). - */ - ColPivHouseholderQR& setThreshold(Default_t) - { - m_usePrescribedThreshold = false; - return *this; - } - - /** Returns the threshold that will be used by certain methods such as rank(). - * - * See the documentation of setThreshold(const RealScalar&). - */ - RealScalar threshold() const - { - eigen_assert(m_isInitialized || m_usePrescribedThreshold); - return m_usePrescribedThreshold ? m_prescribedThreshold - // this formula comes from experimenting (see "LU precision tuning" thread on the list) - // and turns out to be identical to Higham's formula used already in LDLt. - : NumTraits<Scalar>::epsilon() * RealScalar(m_qr.diagonalSize()); - } - - /** \returns the number of nonzero pivots in the QR decomposition. - * Here nonzero is meant in the exact sense, not in a fuzzy sense. - * So that notion isn't really intrinsically interesting, but it is - * still useful when implementing algorithms. - * - * \sa rank() - */ - inline Index nonzeroPivots() const - { - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return m_nonzero_pivots; - } - - /** \returns the absolute value of the biggest pivot, i.e. the biggest - * diagonal coefficient of R. - */ - RealScalar maxPivot() const { return m_maxpivot; } - - /** \brief Reports whether the QR factorization was successful. - * - * \note This function always returns \c Success. It is provided for compatibility - * with other factorization routines. - * \returns \c Success - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return Success; - } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename RhsType, typename DstType> - void _solve_impl(const RhsType &rhs, DstType &dst) const; - - template<bool Conjugate, typename RhsType, typename DstType> - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const; - #endif - - protected: - - friend class CompleteOrthogonalDecomposition<MatrixType>; - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - void computeInPlace(); - - MatrixType m_qr; - HCoeffsType m_hCoeffs; - PermutationType m_colsPermutation; - IntRowVectorType m_colsTranspositions; - RowVectorType m_temp; - RealRowVectorType m_colNormsUpdated; - RealRowVectorType m_colNormsDirect; - bool m_isInitialized, m_usePrescribedThreshold; - RealScalar m_prescribedThreshold, m_maxpivot; - Index m_nonzero_pivots; - Index m_det_pq; -}; - -template<typename MatrixType> -typename MatrixType::RealScalar ColPivHouseholderQR<MatrixType>::absDeterminant() const -{ - using std::abs; - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return abs(m_qr.diagonal().prod()); -} - -template<typename MatrixType> -typename MatrixType::RealScalar ColPivHouseholderQR<MatrixType>::logAbsDeterminant() const -{ - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return m_qr.diagonal().cwiseAbs().array().log().sum(); -} - -/** Performs the QR factorization of the given matrix \a matrix. The result of - * the factorization is stored into \c *this, and a reference to \c *this - * is returned. - * - * \sa class ColPivHouseholderQR, ColPivHouseholderQR(const MatrixType&) - */ -template<typename MatrixType> -template<typename InputType> -ColPivHouseholderQR<MatrixType>& ColPivHouseholderQR<MatrixType>::compute(const EigenBase<InputType>& matrix) -{ - m_qr = matrix.derived(); - computeInPlace(); - return *this; -} - -template<typename MatrixType> -void ColPivHouseholderQR<MatrixType>::computeInPlace() -{ - check_template_parameters(); - - // the column permutation is stored as int indices, so just to be sure: - eigen_assert(m_qr.cols()<=NumTraits<int>::highest()); - - using std::abs; - - Index rows = m_qr.rows(); - Index cols = m_qr.cols(); - Index size = m_qr.diagonalSize(); - - m_hCoeffs.resize(size); - - m_temp.resize(cols); - - m_colsTranspositions.resize(m_qr.cols()); - Index number_of_transpositions = 0; - - m_colNormsUpdated.resize(cols); - m_colNormsDirect.resize(cols); - for (Index k = 0; k < cols; ++k) { - // colNormsDirect(k) caches the most recent directly computed norm of - // column k. - m_colNormsDirect.coeffRef(k) = m_qr.col(k).norm(); - m_colNormsUpdated.coeffRef(k) = m_colNormsDirect.coeffRef(k); - } - - RealScalar threshold_helper = numext::abs2<RealScalar>(m_colNormsUpdated.maxCoeff() * NumTraits<RealScalar>::epsilon()) / RealScalar(rows); - RealScalar norm_downdate_threshold = numext::sqrt(NumTraits<RealScalar>::epsilon()); - - m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case) - m_maxpivot = RealScalar(0); - - for(Index k = 0; k < size; ++k) - { - // first, we look up in our table m_colNormsUpdated which column has the biggest norm - Index biggest_col_index; - RealScalar biggest_col_sq_norm = numext::abs2(m_colNormsUpdated.tail(cols-k).maxCoeff(&biggest_col_index)); - biggest_col_index += k; - - // Track the number of meaningful pivots but do not stop the decomposition to make - // sure that the initial matrix is properly reproduced. See bug 941. - if(m_nonzero_pivots==size && biggest_col_sq_norm < threshold_helper * RealScalar(rows-k)) - m_nonzero_pivots = k; - - // apply the transposition to the columns - m_colsTranspositions.coeffRef(k) = biggest_col_index; - if(k != biggest_col_index) { - m_qr.col(k).swap(m_qr.col(biggest_col_index)); - std::swap(m_colNormsUpdated.coeffRef(k), m_colNormsUpdated.coeffRef(biggest_col_index)); - std::swap(m_colNormsDirect.coeffRef(k), m_colNormsDirect.coeffRef(biggest_col_index)); - ++number_of_transpositions; - } - - // generate the householder vector, store it below the diagonal - RealScalar beta; - m_qr.col(k).tail(rows-k).makeHouseholderInPlace(m_hCoeffs.coeffRef(k), beta); - - // apply the householder transformation to the diagonal coefficient - m_qr.coeffRef(k,k) = beta; - - // remember the maximum absolute value of diagonal coefficients - if(abs(beta) > m_maxpivot) m_maxpivot = abs(beta); - - // apply the householder transformation - m_qr.bottomRightCorner(rows-k, cols-k-1) - .applyHouseholderOnTheLeft(m_qr.col(k).tail(rows-k-1), m_hCoeffs.coeffRef(k), &m_temp.coeffRef(k+1)); - - // update our table of norms of the columns - for (Index j = k + 1; j < cols; ++j) { - // The following implements the stable norm downgrade step discussed in - // http://www.netlib.org/lapack/lawnspdf/lawn176.pdf - // and used in LAPACK routines xGEQPF and xGEQP3. - // See lines 278-297 in http://www.netlib.org/lapack/explore-html/dc/df4/sgeqpf_8f_source.html - if (m_colNormsUpdated.coeffRef(j) != RealScalar(0)) { - RealScalar temp = abs(m_qr.coeffRef(k, j)) / m_colNormsUpdated.coeffRef(j); - temp = (RealScalar(1) + temp) * (RealScalar(1) - temp); - temp = temp < RealScalar(0) ? RealScalar(0) : temp; - RealScalar temp2 = temp * numext::abs2<RealScalar>(m_colNormsUpdated.coeffRef(j) / - m_colNormsDirect.coeffRef(j)); - if (temp2 <= norm_downdate_threshold) { - // The updated norm has become too inaccurate so re-compute the column - // norm directly. - m_colNormsDirect.coeffRef(j) = m_qr.col(j).tail(rows - k - 1).norm(); - m_colNormsUpdated.coeffRef(j) = m_colNormsDirect.coeffRef(j); - } else { - m_colNormsUpdated.coeffRef(j) *= numext::sqrt(temp); - } - } - } - } - - m_colsPermutation.setIdentity(PermIndexType(cols)); - for(PermIndexType k = 0; k < size/*m_nonzero_pivots*/; ++k) - m_colsPermutation.applyTranspositionOnTheRight(k, PermIndexType(m_colsTranspositions.coeff(k))); - - m_det_pq = (number_of_transpositions%2) ? -1 : 1; - m_isInitialized = true; -} - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename _MatrixType> -template<typename RhsType, typename DstType> -void ColPivHouseholderQR<_MatrixType>::_solve_impl(const RhsType &rhs, DstType &dst) const -{ - const Index nonzero_pivots = nonzeroPivots(); - - if(nonzero_pivots == 0) - { - dst.setZero(); - return; - } - - typename RhsType::PlainObject c(rhs); - - c.applyOnTheLeft(householderQ().setLength(nonzero_pivots).adjoint() ); - - m_qr.topLeftCorner(nonzero_pivots, nonzero_pivots) - .template triangularView<Upper>() - .solveInPlace(c.topRows(nonzero_pivots)); - - for(Index i = 0; i < nonzero_pivots; ++i) dst.row(m_colsPermutation.indices().coeff(i)) = c.row(i); - for(Index i = nonzero_pivots; i < cols(); ++i) dst.row(m_colsPermutation.indices().coeff(i)).setZero(); -} - -template<typename _MatrixType> -template<bool Conjugate, typename RhsType, typename DstType> -void ColPivHouseholderQR<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const -{ - const Index nonzero_pivots = nonzeroPivots(); - - if(nonzero_pivots == 0) - { - dst.setZero(); - return; - } - - typename RhsType::PlainObject c(m_colsPermutation.transpose()*rhs); - - m_qr.topLeftCorner(nonzero_pivots, nonzero_pivots) - .template triangularView<Upper>() - .transpose().template conjugateIf<Conjugate>() - .solveInPlace(c.topRows(nonzero_pivots)); - - dst.topRows(nonzero_pivots) = c.topRows(nonzero_pivots); - dst.bottomRows(rows()-nonzero_pivots).setZero(); - - dst.applyOnTheLeft(householderQ().setLength(nonzero_pivots).template conjugateIf<!Conjugate>() ); -} -#endif - -namespace internal { - -template<typename DstXprType, typename MatrixType> -struct Assignment<DstXprType, Inverse<ColPivHouseholderQR<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename ColPivHouseholderQR<MatrixType>::Scalar>, Dense2Dense> -{ - typedef ColPivHouseholderQR<MatrixType> QrType; - typedef Inverse<QrType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename QrType::Scalar> &) - { - dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols())); - } -}; - -} // end namespace internal - -/** \returns the matrix Q as a sequence of householder transformations. - * You can extract the meaningful part only by using: - * \code qr.householderQ().setLength(qr.nonzeroPivots()) \endcode*/ -template<typename MatrixType> -typename ColPivHouseholderQR<MatrixType>::HouseholderSequenceType ColPivHouseholderQR<MatrixType> - ::householderQ() const -{ - eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); - return HouseholderSequenceType(m_qr, m_hCoeffs.conjugate()); -} - -/** \return the column-pivoting Householder QR decomposition of \c *this. - * - * \sa class ColPivHouseholderQR - */ -template<typename Derived> -const ColPivHouseholderQR<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::colPivHouseholderQr() const -{ - return ColPivHouseholderQR<PlainObject>(eval()); -} - -} // end namespace Eigen - -#endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_H diff --git a/external/eigen/include/eigen3/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h b/external/eigen/include/eigen3/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h deleted file mode 100644 index 4e9651f8..00000000 --- a/external/eigen/include/eigen3/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to LAPACKe - * Householder QR decomposition of a matrix with column pivoting based on - * LAPACKE_?geqp3 function. - ******************************************************************************** -*/ - -#ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H -#define EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H - -namespace Eigen { - -/** \internal Specialization for the data types supported by LAPACKe */ - -#define EIGEN_LAPACKE_QR_COLPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW) \ -template<> template<typename InputType> inline \ -ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >& \ -ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >::compute( \ - const EigenBase<InputType>& matrix) \ -\ -{ \ - using std::abs; \ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \ - typedef MatrixType::RealScalar RealScalar; \ - Index rows = matrix.rows();\ - Index cols = matrix.cols();\ -\ - m_qr = matrix;\ - Index size = m_qr.diagonalSize();\ - m_hCoeffs.resize(size);\ -\ - m_colsTranspositions.resize(cols);\ - /*Index number_of_transpositions = 0;*/ \ -\ - m_nonzero_pivots = 0; \ - m_maxpivot = RealScalar(0);\ - m_colsPermutation.resize(cols); \ - m_colsPermutation.indices().setZero(); \ -\ - lapack_int lda = internal::convert_index<lapack_int,Index>(m_qr.outerStride()); \ - lapack_int matrix_order = LAPACKE_COLROW; \ - LAPACKE_##LAPACKE_PREFIX##geqp3( matrix_order, internal::convert_index<lapack_int,Index>(rows), internal::convert_index<lapack_int,Index>(cols), \ - (LAPACKE_TYPE*)m_qr.data(), lda, (lapack_int*)m_colsPermutation.indices().data(), (LAPACKE_TYPE*)m_hCoeffs.data()); \ - m_isInitialized = true; \ - m_maxpivot=m_qr.diagonal().cwiseAbs().maxCoeff(); \ - m_hCoeffs.adjointInPlace(); \ - RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); \ - lapack_int *perm = m_colsPermutation.indices().data(); \ - for(Index i=0;i<size;i++) { \ - m_nonzero_pivots += (abs(m_qr.coeff(i,i)) > premultiplied_threshold);\ - } \ - for(Index i=0;i<cols;i++) perm[i]--;\ -\ - /*m_det_pq = (number_of_transpositions%2) ? -1 : 1; // TODO: It's not needed now; fix upon availability in Eigen */ \ -\ - return *this; \ -} - -EIGEN_LAPACKE_QR_COLPIV(double, double, d, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_QR_COLPIV(float, float, s, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_QR_COLPIV(dcomplex, lapack_complex_double, z, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_QR_COLPIV(scomplex, lapack_complex_float, c, ColMajor, LAPACK_COL_MAJOR) - -EIGEN_LAPACKE_QR_COLPIV(double, double, d, RowMajor, LAPACK_ROW_MAJOR) -EIGEN_LAPACKE_QR_COLPIV(float, float, s, RowMajor, LAPACK_ROW_MAJOR) -EIGEN_LAPACKE_QR_COLPIV(dcomplex, lapack_complex_double, z, RowMajor, LAPACK_ROW_MAJOR) -EIGEN_LAPACKE_QR_COLPIV(scomplex, lapack_complex_float, c, RowMajor, LAPACK_ROW_MAJOR) - -} // end namespace Eigen - -#endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H diff --git a/external/eigen/include/eigen3/Eigen/src/QR/CompleteOrthogonalDecomposition.h b/external/eigen/include/eigen3/Eigen/src/QR/CompleteOrthogonalDecomposition.h deleted file mode 100644 index 486d3373..00000000 --- a/external/eigen/include/eigen3/Eigen/src/QR/CompleteOrthogonalDecomposition.h +++ /dev/null @@ -1,635 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Rasmus Munk Larsen <rmlarsen@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H -#define EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H - -namespace Eigen { - -namespace internal { -template <typename _MatrixType> -struct traits<CompleteOrthogonalDecomposition<_MatrixType> > - : traits<_MatrixType> { - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - enum { Flags = 0 }; -}; - -} // end namespace internal - -/** \ingroup QR_Module - * - * \class CompleteOrthogonalDecomposition - * - * \brief Complete orthogonal decomposition (COD) of a matrix. - * - * \param MatrixType the type of the matrix of which we are computing the COD. - * - * This class performs a rank-revealing complete orthogonal decomposition of a - * matrix \b A into matrices \b P, \b Q, \b T, and \b Z such that - * \f[ - * \mathbf{A} \, \mathbf{P} = \mathbf{Q} \, - * \begin{bmatrix} \mathbf{T} & \mathbf{0} \\ - * \mathbf{0} & \mathbf{0} \end{bmatrix} \, \mathbf{Z} - * \f] - * by using Householder transformations. Here, \b P is a permutation matrix, - * \b Q and \b Z are unitary matrices and \b T an upper triangular matrix of - * size rank-by-rank. \b A may be rank deficient. - * - * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. - * - * \sa MatrixBase::completeOrthogonalDecomposition() - */ -template <typename _MatrixType> class CompleteOrthogonalDecomposition - : public SolverBase<CompleteOrthogonalDecomposition<_MatrixType> > -{ - public: - typedef _MatrixType MatrixType; - typedef SolverBase<CompleteOrthogonalDecomposition> Base; - - template<typename Derived> - friend struct internal::solve_assertion; - - EIGEN_GENERIC_PUBLIC_INTERFACE(CompleteOrthogonalDecomposition) - enum { - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType; - typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> - PermutationType; - typedef typename internal::plain_row_type<MatrixType, Index>::type - IntRowVectorType; - typedef typename internal::plain_row_type<MatrixType>::type RowVectorType; - typedef typename internal::plain_row_type<MatrixType, RealScalar>::type - RealRowVectorType; - typedef HouseholderSequence< - MatrixType, typename internal::remove_all< - typename HCoeffsType::ConjugateReturnType>::type> - HouseholderSequenceType; - typedef typename MatrixType::PlainObject PlainObject; - - private: - typedef typename PermutationType::Index PermIndexType; - - public: - /** - * \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via - * \c CompleteOrthogonalDecomposition::compute(const* MatrixType&). - */ - CompleteOrthogonalDecomposition() : m_cpqr(), m_zCoeffs(), m_temp() {} - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa CompleteOrthogonalDecomposition() - */ - CompleteOrthogonalDecomposition(Index rows, Index cols) - : m_cpqr(rows, cols), m_zCoeffs((std::min)(rows, cols)), m_temp(cols) {} - - /** \brief Constructs a complete orthogonal decomposition from a given - * matrix. - * - * This constructor computes the complete orthogonal decomposition of the - * matrix \a matrix by calling the method compute(). The default - * threshold for rank determination will be used. It is a short cut for: - * - * \code - * CompleteOrthogonalDecomposition<MatrixType> cod(matrix.rows(), - * matrix.cols()); - * cod.setThreshold(Default); - * cod.compute(matrix); - * \endcode - * - * \sa compute() - */ - template <typename InputType> - explicit CompleteOrthogonalDecomposition(const EigenBase<InputType>& matrix) - : m_cpqr(matrix.rows(), matrix.cols()), - m_zCoeffs((std::min)(matrix.rows(), matrix.cols())), - m_temp(matrix.cols()) - { - compute(matrix.derived()); - } - - /** \brief Constructs a complete orthogonal decomposition from a given matrix - * - * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref. - * - * \sa CompleteOrthogonalDecomposition(const EigenBase&) - */ - template<typename InputType> - explicit CompleteOrthogonalDecomposition(EigenBase<InputType>& matrix) - : m_cpqr(matrix.derived()), - m_zCoeffs((std::min)(matrix.rows(), matrix.cols())), - m_temp(matrix.cols()) - { - computeInPlace(); - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** This method computes the minimum-norm solution X to a least squares - * problem \f[\mathrm{minimize} \|A X - B\|, \f] where \b A is the matrix of - * which \c *this is the complete orthogonal decomposition. - * - * \param b the right-hand sides of the problem to solve. - * - * \returns a solution. - * - */ - template <typename Rhs> - inline const Solve<CompleteOrthogonalDecomposition, Rhs> solve( - const MatrixBase<Rhs>& b) const; - #endif - - HouseholderSequenceType householderQ(void) const; - HouseholderSequenceType matrixQ(void) const { return m_cpqr.householderQ(); } - - /** \returns the matrix \b Z. - */ - MatrixType matrixZ() const { - MatrixType Z = MatrixType::Identity(m_cpqr.cols(), m_cpqr.cols()); - applyZOnTheLeftInPlace<false>(Z); - return Z; - } - - /** \returns a reference to the matrix where the complete orthogonal - * decomposition is stored - */ - const MatrixType& matrixQTZ() const { return m_cpqr.matrixQR(); } - - /** \returns a reference to the matrix where the complete orthogonal - * decomposition is stored. - * \warning The strict lower part and \code cols() - rank() \endcode right - * columns of this matrix contains internal values. - * Only the upper triangular part should be referenced. To get it, use - * \code matrixT().template triangularView<Upper>() \endcode - * For rank-deficient matrices, use - * \code - * matrixR().topLeftCorner(rank(), rank()).template triangularView<Upper>() - * \endcode - */ - const MatrixType& matrixT() const { return m_cpqr.matrixQR(); } - - template <typename InputType> - CompleteOrthogonalDecomposition& compute(const EigenBase<InputType>& matrix) { - // Compute the column pivoted QR factorization A P = Q R. - m_cpqr.compute(matrix); - computeInPlace(); - return *this; - } - - /** \returns a const reference to the column permutation matrix */ - const PermutationType& colsPermutation() const { - return m_cpqr.colsPermutation(); - } - - /** \returns the absolute value of the determinant of the matrix of which - * *this is the complete orthogonal decomposition. It has only linear - * complexity (that is, O(n) where n is the dimension of the square matrix) - * as the complete orthogonal decomposition has already been computed. - * - * \note This is only for square matrices. - * - * \warning a determinant can be very big or small, so for matrices - * of large enough dimension, there is a risk of overflow/underflow. - * One way to work around that is to use logAbsDeterminant() instead. - * - * \sa logAbsDeterminant(), MatrixBase::determinant() - */ - typename MatrixType::RealScalar absDeterminant() const; - - /** \returns the natural log of the absolute value of the determinant of the - * matrix of which *this is the complete orthogonal decomposition. It has - * only linear complexity (that is, O(n) where n is the dimension of the - * square matrix) as the complete orthogonal decomposition has already been - * computed. - * - * \note This is only for square matrices. - * - * \note This method is useful to work around the risk of overflow/underflow - * that's inherent to determinant computation. - * - * \sa absDeterminant(), MatrixBase::determinant() - */ - typename MatrixType::RealScalar logAbsDeterminant() const; - - /** \returns the rank of the matrix of which *this is the complete orthogonal - * decomposition. - * - * \note This method has to determine which pivots should be considered - * nonzero. For that, it uses the threshold value that you can control by - * calling setThreshold(const RealScalar&). - */ - inline Index rank() const { return m_cpqr.rank(); } - - /** \returns the dimension of the kernel of the matrix of which *this is the - * complete orthogonal decomposition. - * - * \note This method has to determine which pivots should be considered - * nonzero. For that, it uses the threshold value that you can control by - * calling setThreshold(const RealScalar&). - */ - inline Index dimensionOfKernel() const { return m_cpqr.dimensionOfKernel(); } - - /** \returns true if the matrix of which *this is the decomposition represents - * an injective linear map, i.e. has trivial kernel; false otherwise. - * - * \note This method has to determine which pivots should be considered - * nonzero. For that, it uses the threshold value that you can control by - * calling setThreshold(const RealScalar&). - */ - inline bool isInjective() const { return m_cpqr.isInjective(); } - - /** \returns true if the matrix of which *this is the decomposition represents - * a surjective linear map; false otherwise. - * - * \note This method has to determine which pivots should be considered - * nonzero. For that, it uses the threshold value that you can control by - * calling setThreshold(const RealScalar&). - */ - inline bool isSurjective() const { return m_cpqr.isSurjective(); } - - /** \returns true if the matrix of which *this is the complete orthogonal - * decomposition is invertible. - * - * \note This method has to determine which pivots should be considered - * nonzero. For that, it uses the threshold value that you can control by - * calling setThreshold(const RealScalar&). - */ - inline bool isInvertible() const { return m_cpqr.isInvertible(); } - - /** \returns the pseudo-inverse of the matrix of which *this is the complete - * orthogonal decomposition. - * \warning: Do not compute \c this->pseudoInverse()*rhs to solve a linear systems. - * It is more efficient and numerically stable to call \c this->solve(rhs). - */ - inline const Inverse<CompleteOrthogonalDecomposition> pseudoInverse() const - { - eigen_assert(m_cpqr.m_isInitialized && "CompleteOrthogonalDecomposition is not initialized."); - return Inverse<CompleteOrthogonalDecomposition>(*this); - } - - inline Index rows() const { return m_cpqr.rows(); } - inline Index cols() const { return m_cpqr.cols(); } - - /** \returns a const reference to the vector of Householder coefficients used - * to represent the factor \c Q. - * - * For advanced uses only. - */ - inline const HCoeffsType& hCoeffs() const { return m_cpqr.hCoeffs(); } - - /** \returns a const reference to the vector of Householder coefficients - * used to represent the factor \c Z. - * - * For advanced uses only. - */ - const HCoeffsType& zCoeffs() const { return m_zCoeffs; } - - /** Allows to prescribe a threshold to be used by certain methods, such as - * rank(), who need to determine when pivots are to be considered nonzero. - * Most be called before calling compute(). - * - * When it needs to get the threshold value, Eigen calls threshold(). By - * default, this uses a formula to automatically determine a reasonable - * threshold. Once you have called the present method - * setThreshold(const RealScalar&), your value is used instead. - * - * \param threshold The new value to use as the threshold. - * - * A pivot will be considered nonzero if its absolute value is strictly - * greater than - * \f$ \vert pivot \vert \leqslant threshold \times \vert maxpivot \vert \f$ - * where maxpivot is the biggest pivot. - * - * If you want to come back to the default behavior, call - * setThreshold(Default_t) - */ - CompleteOrthogonalDecomposition& setThreshold(const RealScalar& threshold) { - m_cpqr.setThreshold(threshold); - return *this; - } - - /** Allows to come back to the default behavior, letting Eigen use its default - * formula for determining the threshold. - * - * You should pass the special object Eigen::Default as parameter here. - * \code qr.setThreshold(Eigen::Default); \endcode - * - * See the documentation of setThreshold(const RealScalar&). - */ - CompleteOrthogonalDecomposition& setThreshold(Default_t) { - m_cpqr.setThreshold(Default); - return *this; - } - - /** Returns the threshold that will be used by certain methods such as rank(). - * - * See the documentation of setThreshold(const RealScalar&). - */ - RealScalar threshold() const { return m_cpqr.threshold(); } - - /** \returns the number of nonzero pivots in the complete orthogonal - * decomposition. Here nonzero is meant in the exact sense, not in a - * fuzzy sense. So that notion isn't really intrinsically interesting, - * but it is still useful when implementing algorithms. - * - * \sa rank() - */ - inline Index nonzeroPivots() const { return m_cpqr.nonzeroPivots(); } - - /** \returns the absolute value of the biggest pivot, i.e. the biggest - * diagonal coefficient of R. - */ - inline RealScalar maxPivot() const { return m_cpqr.maxPivot(); } - - /** \brief Reports whether the complete orthogonal decomposition was - * successful. - * - * \note This function always returns \c Success. It is provided for - * compatibility - * with other factorization routines. - * \returns \c Success - */ - ComputationInfo info() const { - eigen_assert(m_cpqr.m_isInitialized && "Decomposition is not initialized."); - return Success; - } - -#ifndef EIGEN_PARSED_BY_DOXYGEN - template <typename RhsType, typename DstType> - void _solve_impl(const RhsType& rhs, DstType& dst) const; - - template<bool Conjugate, typename RhsType, typename DstType> - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const; -#endif - - protected: - static void check_template_parameters() { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - template<bool Transpose_, typename Rhs> - void _check_solve_assertion(const Rhs& b) const { - EIGEN_ONLY_USED_FOR_DEBUG(b); - eigen_assert(m_cpqr.m_isInitialized && "CompleteOrthogonalDecomposition is not initialized."); - eigen_assert((Transpose_?derived().cols():derived().rows())==b.rows() && "CompleteOrthogonalDecomposition::solve(): invalid number of rows of the right hand side matrix b"); - } - - void computeInPlace(); - - /** Overwrites \b rhs with \f$ \mathbf{Z} * \mathbf{rhs} \f$ or - * \f$ \mathbf{\overline Z} * \mathbf{rhs} \f$ if \c Conjugate - * is set to \c true. - */ - template <bool Conjugate, typename Rhs> - void applyZOnTheLeftInPlace(Rhs& rhs) const; - - /** Overwrites \b rhs with \f$ \mathbf{Z}^* * \mathbf{rhs} \f$. - */ - template <typename Rhs> - void applyZAdjointOnTheLeftInPlace(Rhs& rhs) const; - - ColPivHouseholderQR<MatrixType> m_cpqr; - HCoeffsType m_zCoeffs; - RowVectorType m_temp; -}; - -template <typename MatrixType> -typename MatrixType::RealScalar -CompleteOrthogonalDecomposition<MatrixType>::absDeterminant() const { - return m_cpqr.absDeterminant(); -} - -template <typename MatrixType> -typename MatrixType::RealScalar -CompleteOrthogonalDecomposition<MatrixType>::logAbsDeterminant() const { - return m_cpqr.logAbsDeterminant(); -} - -/** Performs the complete orthogonal decomposition of the given matrix \a - * matrix. The result of the factorization is stored into \c *this, and a - * reference to \c *this is returned. - * - * \sa class CompleteOrthogonalDecomposition, - * CompleteOrthogonalDecomposition(const MatrixType&) - */ -template <typename MatrixType> -void CompleteOrthogonalDecomposition<MatrixType>::computeInPlace() -{ - check_template_parameters(); - - // the column permutation is stored as int indices, so just to be sure: - eigen_assert(m_cpqr.cols() <= NumTraits<int>::highest()); - - const Index rank = m_cpqr.rank(); - const Index cols = m_cpqr.cols(); - const Index rows = m_cpqr.rows(); - m_zCoeffs.resize((std::min)(rows, cols)); - m_temp.resize(cols); - - if (rank < cols) { - // We have reduced the (permuted) matrix to the form - // [R11 R12] - // [ 0 R22] - // where R11 is r-by-r (r = rank) upper triangular, R12 is - // r-by-(n-r), and R22 is empty or the norm of R22 is negligible. - // We now compute the complete orthogonal decomposition by applying - // Householder transformations from the right to the upper trapezoidal - // matrix X = [R11 R12] to zero out R12 and obtain the factorization - // [R11 R12] = [T11 0] * Z, where T11 is r-by-r upper triangular and - // Z = Z(0) * Z(1) ... Z(r-1) is an n-by-n orthogonal matrix. - // We store the data representing Z in R12 and m_zCoeffs. - for (Index k = rank - 1; k >= 0; --k) { - if (k != rank - 1) { - // Given the API for Householder reflectors, it is more convenient if - // we swap the leading parts of columns k and r-1 (zero-based) to form - // the matrix X_k = [X(0:k, k), X(0:k, r:n)] - m_cpqr.m_qr.col(k).head(k + 1).swap( - m_cpqr.m_qr.col(rank - 1).head(k + 1)); - } - // Construct Householder reflector Z(k) to zero out the last row of X_k, - // i.e. choose Z(k) such that - // [X(k, k), X(k, r:n)] * Z(k) = [beta, 0, .., 0]. - RealScalar beta; - m_cpqr.m_qr.row(k) - .tail(cols - rank + 1) - .makeHouseholderInPlace(m_zCoeffs(k), beta); - m_cpqr.m_qr(k, rank - 1) = beta; - if (k > 0) { - // Apply Z(k) to the first k rows of X_k - m_cpqr.m_qr.topRightCorner(k, cols - rank + 1) - .applyHouseholderOnTheRight( - m_cpqr.m_qr.row(k).tail(cols - rank).adjoint(), m_zCoeffs(k), - &m_temp(0)); - } - if (k != rank - 1) { - // Swap X(0:k,k) back to its proper location. - m_cpqr.m_qr.col(k).head(k + 1).swap( - m_cpqr.m_qr.col(rank - 1).head(k + 1)); - } - } - } -} - -template <typename MatrixType> -template <bool Conjugate, typename Rhs> -void CompleteOrthogonalDecomposition<MatrixType>::applyZOnTheLeftInPlace( - Rhs& rhs) const { - const Index cols = this->cols(); - const Index nrhs = rhs.cols(); - const Index rank = this->rank(); - Matrix<typename Rhs::Scalar, Dynamic, 1> temp((std::max)(cols, nrhs)); - for (Index k = rank-1; k >= 0; --k) { - if (k != rank - 1) { - rhs.row(k).swap(rhs.row(rank - 1)); - } - rhs.middleRows(rank - 1, cols - rank + 1) - .applyHouseholderOnTheLeft( - matrixQTZ().row(k).tail(cols - rank).transpose().template conjugateIf<!Conjugate>(), zCoeffs().template conjugateIf<Conjugate>()(k), - &temp(0)); - if (k != rank - 1) { - rhs.row(k).swap(rhs.row(rank - 1)); - } - } -} - -template <typename MatrixType> -template <typename Rhs> -void CompleteOrthogonalDecomposition<MatrixType>::applyZAdjointOnTheLeftInPlace( - Rhs& rhs) const { - const Index cols = this->cols(); - const Index nrhs = rhs.cols(); - const Index rank = this->rank(); - Matrix<typename Rhs::Scalar, Dynamic, 1> temp((std::max)(cols, nrhs)); - for (Index k = 0; k < rank; ++k) { - if (k != rank - 1) { - rhs.row(k).swap(rhs.row(rank - 1)); - } - rhs.middleRows(rank - 1, cols - rank + 1) - .applyHouseholderOnTheLeft( - matrixQTZ().row(k).tail(cols - rank).adjoint(), zCoeffs()(k), - &temp(0)); - if (k != rank - 1) { - rhs.row(k).swap(rhs.row(rank - 1)); - } - } -} - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template <typename _MatrixType> -template <typename RhsType, typename DstType> -void CompleteOrthogonalDecomposition<_MatrixType>::_solve_impl( - const RhsType& rhs, DstType& dst) const { - const Index rank = this->rank(); - if (rank == 0) { - dst.setZero(); - return; - } - - // Compute c = Q^* * rhs - typename RhsType::PlainObject c(rhs); - c.applyOnTheLeft(matrixQ().setLength(rank).adjoint()); - - // Solve T z = c(1:rank, :) - dst.topRows(rank) = matrixT() - .topLeftCorner(rank, rank) - .template triangularView<Upper>() - .solve(c.topRows(rank)); - - const Index cols = this->cols(); - if (rank < cols) { - // Compute y = Z^* * [ z ] - // [ 0 ] - dst.bottomRows(cols - rank).setZero(); - applyZAdjointOnTheLeftInPlace(dst); - } - - // Undo permutation to get x = P^{-1} * y. - dst = colsPermutation() * dst; -} - -template<typename _MatrixType> -template<bool Conjugate, typename RhsType, typename DstType> -void CompleteOrthogonalDecomposition<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const -{ - const Index rank = this->rank(); - - if (rank == 0) { - dst.setZero(); - return; - } - - typename RhsType::PlainObject c(colsPermutation().transpose()*rhs); - - if (rank < cols()) { - applyZOnTheLeftInPlace<!Conjugate>(c); - } - - matrixT().topLeftCorner(rank, rank) - .template triangularView<Upper>() - .transpose().template conjugateIf<Conjugate>() - .solveInPlace(c.topRows(rank)); - - dst.topRows(rank) = c.topRows(rank); - dst.bottomRows(rows()-rank).setZero(); - - dst.applyOnTheLeft(householderQ().setLength(rank).template conjugateIf<!Conjugate>() ); -} -#endif - -namespace internal { - -template<typename MatrixType> -struct traits<Inverse<CompleteOrthogonalDecomposition<MatrixType> > > - : traits<typename Transpose<typename MatrixType::PlainObject>::PlainObject> -{ - enum { Flags = 0 }; -}; - -template<typename DstXprType, typename MatrixType> -struct Assignment<DstXprType, Inverse<CompleteOrthogonalDecomposition<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename CompleteOrthogonalDecomposition<MatrixType>::Scalar>, Dense2Dense> -{ - typedef CompleteOrthogonalDecomposition<MatrixType> CodType; - typedef Inverse<CodType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename CodType::Scalar> &) - { - typedef Matrix<typename CodType::Scalar, CodType::RowsAtCompileTime, CodType::RowsAtCompileTime, 0, CodType::MaxRowsAtCompileTime, CodType::MaxRowsAtCompileTime> IdentityMatrixType; - dst = src.nestedExpression().solve(IdentityMatrixType::Identity(src.cols(), src.cols())); - } -}; - -} // end namespace internal - -/** \returns the matrix Q as a sequence of householder transformations */ -template <typename MatrixType> -typename CompleteOrthogonalDecomposition<MatrixType>::HouseholderSequenceType -CompleteOrthogonalDecomposition<MatrixType>::householderQ() const { - return m_cpqr.householderQ(); -} - -/** \return the complete orthogonal decomposition of \c *this. - * - * \sa class CompleteOrthogonalDecomposition - */ -template <typename Derived> -const CompleteOrthogonalDecomposition<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::completeOrthogonalDecomposition() const { - return CompleteOrthogonalDecomposition<PlainObject>(eval()); -} - -} // end namespace Eigen - -#endif // EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H diff --git a/external/eigen/include/eigen3/Eigen/src/QR/FullPivHouseholderQR.h b/external/eigen/include/eigen3/Eigen/src/QR/FullPivHouseholderQR.h deleted file mode 100644 index d0664a1d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/QR/FullPivHouseholderQR.h +++ /dev/null @@ -1,713 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_FULLPIVOTINGHOUSEHOLDERQR_H -#define EIGEN_FULLPIVOTINGHOUSEHOLDERQR_H - -namespace Eigen { - -namespace internal { - -template<typename _MatrixType> struct traits<FullPivHouseholderQR<_MatrixType> > - : traits<_MatrixType> -{ - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - enum { Flags = 0 }; -}; - -template<typename MatrixType> struct FullPivHouseholderQRMatrixQReturnType; - -template<typename MatrixType> -struct traits<FullPivHouseholderQRMatrixQReturnType<MatrixType> > -{ - typedef typename MatrixType::PlainObject ReturnType; -}; - -} // end namespace internal - -/** \ingroup QR_Module - * - * \class FullPivHouseholderQR - * - * \brief Householder rank-revealing QR decomposition of a matrix with full pivoting - * - * \tparam _MatrixType the type of the matrix of which we are computing the QR decomposition - * - * This class performs a rank-revealing QR decomposition of a matrix \b A into matrices \b P, \b P', \b Q and \b R - * such that - * \f[ - * \mathbf{P} \, \mathbf{A} \, \mathbf{P}' = \mathbf{Q} \, \mathbf{R} - * \f] - * by using Householder transformations. Here, \b P and \b P' are permutation matrices, \b Q a unitary matrix - * and \b R an upper triangular matrix. - * - * This decomposition performs a very prudent full pivoting in order to be rank-revealing and achieve optimal - * numerical stability. The trade-off is that it is slower than HouseholderQR and ColPivHouseholderQR. - * - * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. - * - * \sa MatrixBase::fullPivHouseholderQr() - */ -template<typename _MatrixType> class FullPivHouseholderQR - : public SolverBase<FullPivHouseholderQR<_MatrixType> > -{ - public: - - typedef _MatrixType MatrixType; - typedef SolverBase<FullPivHouseholderQR> Base; - friend class SolverBase<FullPivHouseholderQR>; - - EIGEN_GENERIC_PUBLIC_INTERFACE(FullPivHouseholderQR) - enum { - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - typedef internal::FullPivHouseholderQRMatrixQReturnType<MatrixType> MatrixQReturnType; - typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType; - typedef Matrix<StorageIndex, 1, - EIGEN_SIZE_MIN_PREFER_DYNAMIC(ColsAtCompileTime,RowsAtCompileTime), RowMajor, 1, - EIGEN_SIZE_MIN_PREFER_FIXED(MaxColsAtCompileTime,MaxRowsAtCompileTime)> IntDiagSizeVectorType; - typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationType; - typedef typename internal::plain_row_type<MatrixType>::type RowVectorType; - typedef typename internal::plain_col_type<MatrixType>::type ColVectorType; - typedef typename MatrixType::PlainObject PlainObject; - - /** \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via FullPivHouseholderQR::compute(const MatrixType&). - */ - FullPivHouseholderQR() - : m_qr(), - m_hCoeffs(), - m_rows_transpositions(), - m_cols_transpositions(), - m_cols_permutation(), - m_temp(), - m_isInitialized(false), - m_usePrescribedThreshold(false) {} - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa FullPivHouseholderQR() - */ - FullPivHouseholderQR(Index rows, Index cols) - : m_qr(rows, cols), - m_hCoeffs((std::min)(rows,cols)), - m_rows_transpositions((std::min)(rows,cols)), - m_cols_transpositions((std::min)(rows,cols)), - m_cols_permutation(cols), - m_temp(cols), - m_isInitialized(false), - m_usePrescribedThreshold(false) {} - - /** \brief Constructs a QR factorization from a given matrix - * - * This constructor computes the QR factorization of the matrix \a matrix by calling - * the method compute(). It is a short cut for: - * - * \code - * FullPivHouseholderQR<MatrixType> qr(matrix.rows(), matrix.cols()); - * qr.compute(matrix); - * \endcode - * - * \sa compute() - */ - template<typename InputType> - explicit FullPivHouseholderQR(const EigenBase<InputType>& matrix) - : m_qr(matrix.rows(), matrix.cols()), - m_hCoeffs((std::min)(matrix.rows(), matrix.cols())), - m_rows_transpositions((std::min)(matrix.rows(), matrix.cols())), - m_cols_transpositions((std::min)(matrix.rows(), matrix.cols())), - m_cols_permutation(matrix.cols()), - m_temp(matrix.cols()), - m_isInitialized(false), - m_usePrescribedThreshold(false) - { - compute(matrix.derived()); - } - - /** \brief Constructs a QR factorization from a given matrix - * - * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref. - * - * \sa FullPivHouseholderQR(const EigenBase&) - */ - template<typename InputType> - explicit FullPivHouseholderQR(EigenBase<InputType>& matrix) - : m_qr(matrix.derived()), - m_hCoeffs((std::min)(matrix.rows(), matrix.cols())), - m_rows_transpositions((std::min)(matrix.rows(), matrix.cols())), - m_cols_transpositions((std::min)(matrix.rows(), matrix.cols())), - m_cols_permutation(matrix.cols()), - m_temp(matrix.cols()), - m_isInitialized(false), - m_usePrescribedThreshold(false) - { - computeInPlace(); - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** This method finds a solution x to the equation Ax=b, where A is the matrix of which - * \c *this is the QR decomposition. - * - * \param b the right-hand-side of the equation to solve. - * - * \returns the exact or least-square solution if the rank is greater or equal to the number of columns of A, - * and an arbitrary solution otherwise. - * - * \note_about_checking_solutions - * - * \note_about_arbitrary_choice_of_solution - * - * Example: \include FullPivHouseholderQR_solve.cpp - * Output: \verbinclude FullPivHouseholderQR_solve.out - */ - template<typename Rhs> - inline const Solve<FullPivHouseholderQR, Rhs> - solve(const MatrixBase<Rhs>& b) const; - #endif - - /** \returns Expression object representing the matrix Q - */ - MatrixQReturnType matrixQ(void) const; - - /** \returns a reference to the matrix where the Householder QR decomposition is stored - */ - const MatrixType& matrixQR() const - { - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return m_qr; - } - - template<typename InputType> - FullPivHouseholderQR& compute(const EigenBase<InputType>& matrix); - - /** \returns a const reference to the column permutation matrix */ - const PermutationType& colsPermutation() const - { - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return m_cols_permutation; - } - - /** \returns a const reference to the vector of indices representing the rows transpositions */ - const IntDiagSizeVectorType& rowsTranspositions() const - { - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return m_rows_transpositions; - } - - /** \returns the absolute value of the determinant of the matrix of which - * *this is the QR decomposition. It has only linear complexity - * (that is, O(n) where n is the dimension of the square matrix) - * as the QR decomposition has already been computed. - * - * \note This is only for square matrices. - * - * \warning a determinant can be very big or small, so for matrices - * of large enough dimension, there is a risk of overflow/underflow. - * One way to work around that is to use logAbsDeterminant() instead. - * - * \sa logAbsDeterminant(), MatrixBase::determinant() - */ - typename MatrixType::RealScalar absDeterminant() const; - - /** \returns the natural log of the absolute value of the determinant of the matrix of which - * *this is the QR decomposition. It has only linear complexity - * (that is, O(n) where n is the dimension of the square matrix) - * as the QR decomposition has already been computed. - * - * \note This is only for square matrices. - * - * \note This method is useful to work around the risk of overflow/underflow that's inherent - * to determinant computation. - * - * \sa absDeterminant(), MatrixBase::determinant() - */ - typename MatrixType::RealScalar logAbsDeterminant() const; - - /** \returns the rank of the matrix of which *this is the QR decomposition. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline Index rank() const - { - using std::abs; - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); - Index result = 0; - for(Index i = 0; i < m_nonzero_pivots; ++i) - result += (abs(m_qr.coeff(i,i)) > premultiplied_threshold); - return result; - } - - /** \returns the dimension of the kernel of the matrix of which *this is the QR decomposition. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline Index dimensionOfKernel() const - { - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return cols() - rank(); - } - - /** \returns true if the matrix of which *this is the QR decomposition represents an injective - * linear map, i.e. has trivial kernel; false otherwise. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isInjective() const - { - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return rank() == cols(); - } - - /** \returns true if the matrix of which *this is the QR decomposition represents a surjective - * linear map; false otherwise. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isSurjective() const - { - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return rank() == rows(); - } - - /** \returns true if the matrix of which *this is the QR decomposition is invertible. - * - * \note This method has to determine which pivots should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline bool isInvertible() const - { - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return isInjective() && isSurjective(); - } - - /** \returns the inverse of the matrix of which *this is the QR decomposition. - * - * \note If this matrix is not invertible, the returned matrix has undefined coefficients. - * Use isInvertible() to first determine whether this matrix is invertible. - */ - inline const Inverse<FullPivHouseholderQR> inverse() const - { - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return Inverse<FullPivHouseholderQR>(*this); - } - - inline Index rows() const { return m_qr.rows(); } - inline Index cols() const { return m_qr.cols(); } - - /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q. - * - * For advanced uses only. - */ - const HCoeffsType& hCoeffs() const { return m_hCoeffs; } - - /** Allows to prescribe a threshold to be used by certain methods, such as rank(), - * who need to determine when pivots are to be considered nonzero. This is not used for the - * QR decomposition itself. - * - * When it needs to get the threshold value, Eigen calls threshold(). By default, this - * uses a formula to automatically determine a reasonable threshold. - * Once you have called the present method setThreshold(const RealScalar&), - * your value is used instead. - * - * \param threshold The new value to use as the threshold. - * - * A pivot will be considered nonzero if its absolute value is strictly greater than - * \f$ \vert pivot \vert \leqslant threshold \times \vert maxpivot \vert \f$ - * where maxpivot is the biggest pivot. - * - * If you want to come back to the default behavior, call setThreshold(Default_t) - */ - FullPivHouseholderQR& setThreshold(const RealScalar& threshold) - { - m_usePrescribedThreshold = true; - m_prescribedThreshold = threshold; - return *this; - } - - /** Allows to come back to the default behavior, letting Eigen use its default formula for - * determining the threshold. - * - * You should pass the special object Eigen::Default as parameter here. - * \code qr.setThreshold(Eigen::Default); \endcode - * - * See the documentation of setThreshold(const RealScalar&). - */ - FullPivHouseholderQR& setThreshold(Default_t) - { - m_usePrescribedThreshold = false; - return *this; - } - - /** Returns the threshold that will be used by certain methods such as rank(). - * - * See the documentation of setThreshold(const RealScalar&). - */ - RealScalar threshold() const - { - eigen_assert(m_isInitialized || m_usePrescribedThreshold); - return m_usePrescribedThreshold ? m_prescribedThreshold - // this formula comes from experimenting (see "LU precision tuning" thread on the list) - // and turns out to be identical to Higham's formula used already in LDLt. - : NumTraits<Scalar>::epsilon() * RealScalar(m_qr.diagonalSize()); - } - - /** \returns the number of nonzero pivots in the QR decomposition. - * Here nonzero is meant in the exact sense, not in a fuzzy sense. - * So that notion isn't really intrinsically interesting, but it is - * still useful when implementing algorithms. - * - * \sa rank() - */ - inline Index nonzeroPivots() const - { - eigen_assert(m_isInitialized && "LU is not initialized."); - return m_nonzero_pivots; - } - - /** \returns the absolute value of the biggest pivot, i.e. the biggest - * diagonal coefficient of U. - */ - RealScalar maxPivot() const { return m_maxpivot; } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename RhsType, typename DstType> - void _solve_impl(const RhsType &rhs, DstType &dst) const; - - template<bool Conjugate, typename RhsType, typename DstType> - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const; - #endif - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - void computeInPlace(); - - MatrixType m_qr; - HCoeffsType m_hCoeffs; - IntDiagSizeVectorType m_rows_transpositions; - IntDiagSizeVectorType m_cols_transpositions; - PermutationType m_cols_permutation; - RowVectorType m_temp; - bool m_isInitialized, m_usePrescribedThreshold; - RealScalar m_prescribedThreshold, m_maxpivot; - Index m_nonzero_pivots; - RealScalar m_precision; - Index m_det_pq; -}; - -template<typename MatrixType> -typename MatrixType::RealScalar FullPivHouseholderQR<MatrixType>::absDeterminant() const -{ - using std::abs; - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return abs(m_qr.diagonal().prod()); -} - -template<typename MatrixType> -typename MatrixType::RealScalar FullPivHouseholderQR<MatrixType>::logAbsDeterminant() const -{ - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return m_qr.diagonal().cwiseAbs().array().log().sum(); -} - -/** Performs the QR factorization of the given matrix \a matrix. The result of - * the factorization is stored into \c *this, and a reference to \c *this - * is returned. - * - * \sa class FullPivHouseholderQR, FullPivHouseholderQR(const MatrixType&) - */ -template<typename MatrixType> -template<typename InputType> -FullPivHouseholderQR<MatrixType>& FullPivHouseholderQR<MatrixType>::compute(const EigenBase<InputType>& matrix) -{ - m_qr = matrix.derived(); - computeInPlace(); - return *this; -} - -template<typename MatrixType> -void FullPivHouseholderQR<MatrixType>::computeInPlace() -{ - check_template_parameters(); - - using std::abs; - Index rows = m_qr.rows(); - Index cols = m_qr.cols(); - Index size = (std::min)(rows,cols); - - - m_hCoeffs.resize(size); - - m_temp.resize(cols); - - m_precision = NumTraits<Scalar>::epsilon() * RealScalar(size); - - m_rows_transpositions.resize(size); - m_cols_transpositions.resize(size); - Index number_of_transpositions = 0; - - RealScalar biggest(0); - - m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case) - m_maxpivot = RealScalar(0); - - for (Index k = 0; k < size; ++k) - { - Index row_of_biggest_in_corner, col_of_biggest_in_corner; - typedef internal::scalar_score_coeff_op<Scalar> Scoring; - typedef typename Scoring::result_type Score; - - Score score = m_qr.bottomRightCorner(rows-k, cols-k) - .unaryExpr(Scoring()) - .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner); - row_of_biggest_in_corner += k; - col_of_biggest_in_corner += k; - RealScalar biggest_in_corner = internal::abs_knowing_score<Scalar>()(m_qr(row_of_biggest_in_corner, col_of_biggest_in_corner), score); - if(k==0) biggest = biggest_in_corner; - - // if the corner is negligible, then we have less than full rank, and we can finish early - if(internal::isMuchSmallerThan(biggest_in_corner, biggest, m_precision)) - { - m_nonzero_pivots = k; - for(Index i = k; i < size; i++) - { - m_rows_transpositions.coeffRef(i) = internal::convert_index<StorageIndex>(i); - m_cols_transpositions.coeffRef(i) = internal::convert_index<StorageIndex>(i); - m_hCoeffs.coeffRef(i) = Scalar(0); - } - break; - } - - m_rows_transpositions.coeffRef(k) = internal::convert_index<StorageIndex>(row_of_biggest_in_corner); - m_cols_transpositions.coeffRef(k) = internal::convert_index<StorageIndex>(col_of_biggest_in_corner); - if(k != row_of_biggest_in_corner) { - m_qr.row(k).tail(cols-k).swap(m_qr.row(row_of_biggest_in_corner).tail(cols-k)); - ++number_of_transpositions; - } - if(k != col_of_biggest_in_corner) { - m_qr.col(k).swap(m_qr.col(col_of_biggest_in_corner)); - ++number_of_transpositions; - } - - RealScalar beta; - m_qr.col(k).tail(rows-k).makeHouseholderInPlace(m_hCoeffs.coeffRef(k), beta); - m_qr.coeffRef(k,k) = beta; - - // remember the maximum absolute value of diagonal coefficients - if(abs(beta) > m_maxpivot) m_maxpivot = abs(beta); - - m_qr.bottomRightCorner(rows-k, cols-k-1) - .applyHouseholderOnTheLeft(m_qr.col(k).tail(rows-k-1), m_hCoeffs.coeffRef(k), &m_temp.coeffRef(k+1)); - } - - m_cols_permutation.setIdentity(cols); - for(Index k = 0; k < size; ++k) - m_cols_permutation.applyTranspositionOnTheRight(k, m_cols_transpositions.coeff(k)); - - m_det_pq = (number_of_transpositions%2) ? -1 : 1; - m_isInitialized = true; -} - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename _MatrixType> -template<typename RhsType, typename DstType> -void FullPivHouseholderQR<_MatrixType>::_solve_impl(const RhsType &rhs, DstType &dst) const -{ - const Index l_rank = rank(); - - // FIXME introduce nonzeroPivots() and use it here. and more generally, - // make the same improvements in this dec as in FullPivLU. - if(l_rank==0) - { - dst.setZero(); - return; - } - - typename RhsType::PlainObject c(rhs); - - Matrix<typename RhsType::Scalar,1,RhsType::ColsAtCompileTime> temp(rhs.cols()); - for (Index k = 0; k < l_rank; ++k) - { - Index remainingSize = rows()-k; - c.row(k).swap(c.row(m_rows_transpositions.coeff(k))); - c.bottomRightCorner(remainingSize, rhs.cols()) - .applyHouseholderOnTheLeft(m_qr.col(k).tail(remainingSize-1), - m_hCoeffs.coeff(k), &temp.coeffRef(0)); - } - - m_qr.topLeftCorner(l_rank, l_rank) - .template triangularView<Upper>() - .solveInPlace(c.topRows(l_rank)); - - for(Index i = 0; i < l_rank; ++i) dst.row(m_cols_permutation.indices().coeff(i)) = c.row(i); - for(Index i = l_rank; i < cols(); ++i) dst.row(m_cols_permutation.indices().coeff(i)).setZero(); -} - -template<typename _MatrixType> -template<bool Conjugate, typename RhsType, typename DstType> -void FullPivHouseholderQR<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const -{ - const Index l_rank = rank(); - - if(l_rank == 0) - { - dst.setZero(); - return; - } - - typename RhsType::PlainObject c(m_cols_permutation.transpose()*rhs); - - m_qr.topLeftCorner(l_rank, l_rank) - .template triangularView<Upper>() - .transpose().template conjugateIf<Conjugate>() - .solveInPlace(c.topRows(l_rank)); - - dst.topRows(l_rank) = c.topRows(l_rank); - dst.bottomRows(rows()-l_rank).setZero(); - - Matrix<Scalar, 1, DstType::ColsAtCompileTime> temp(dst.cols()); - const Index size = (std::min)(rows(), cols()); - for (Index k = size-1; k >= 0; --k) - { - Index remainingSize = rows()-k; - - dst.bottomRightCorner(remainingSize, dst.cols()) - .applyHouseholderOnTheLeft(m_qr.col(k).tail(remainingSize-1).template conjugateIf<!Conjugate>(), - m_hCoeffs.template conjugateIf<Conjugate>().coeff(k), &temp.coeffRef(0)); - - dst.row(k).swap(dst.row(m_rows_transpositions.coeff(k))); - } -} -#endif - -namespace internal { - -template<typename DstXprType, typename MatrixType> -struct Assignment<DstXprType, Inverse<FullPivHouseholderQR<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename FullPivHouseholderQR<MatrixType>::Scalar>, Dense2Dense> -{ - typedef FullPivHouseholderQR<MatrixType> QrType; - typedef Inverse<QrType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename QrType::Scalar> &) - { - dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols())); - } -}; - -/** \ingroup QR_Module - * - * \brief Expression type for return value of FullPivHouseholderQR::matrixQ() - * - * \tparam MatrixType type of underlying dense matrix - */ -template<typename MatrixType> struct FullPivHouseholderQRMatrixQReturnType - : public ReturnByValue<FullPivHouseholderQRMatrixQReturnType<MatrixType> > -{ -public: - typedef typename FullPivHouseholderQR<MatrixType>::IntDiagSizeVectorType IntDiagSizeVectorType; - typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType; - typedef Matrix<typename MatrixType::Scalar, 1, MatrixType::RowsAtCompileTime, RowMajor, 1, - MatrixType::MaxRowsAtCompileTime> WorkVectorType; - - FullPivHouseholderQRMatrixQReturnType(const MatrixType& qr, - const HCoeffsType& hCoeffs, - const IntDiagSizeVectorType& rowsTranspositions) - : m_qr(qr), - m_hCoeffs(hCoeffs), - m_rowsTranspositions(rowsTranspositions) - {} - - template <typename ResultType> - void evalTo(ResultType& result) const - { - const Index rows = m_qr.rows(); - WorkVectorType workspace(rows); - evalTo(result, workspace); - } - - template <typename ResultType> - void evalTo(ResultType& result, WorkVectorType& workspace) const - { - using numext::conj; - // compute the product H'_0 H'_1 ... H'_n-1, - // where H_k is the k-th Householder transformation I - h_k v_k v_k' - // and v_k is the k-th Householder vector [1,m_qr(k+1,k), m_qr(k+2,k), ...] - const Index rows = m_qr.rows(); - const Index cols = m_qr.cols(); - const Index size = (std::min)(rows, cols); - workspace.resize(rows); - result.setIdentity(rows, rows); - for (Index k = size-1; k >= 0; k--) - { - result.block(k, k, rows-k, rows-k) - .applyHouseholderOnTheLeft(m_qr.col(k).tail(rows-k-1), conj(m_hCoeffs.coeff(k)), &workspace.coeffRef(k)); - result.row(k).swap(result.row(m_rowsTranspositions.coeff(k))); - } - } - - Index rows() const { return m_qr.rows(); } - Index cols() const { return m_qr.rows(); } - -protected: - typename MatrixType::Nested m_qr; - typename HCoeffsType::Nested m_hCoeffs; - typename IntDiagSizeVectorType::Nested m_rowsTranspositions; -}; - -// template<typename MatrixType> -// struct evaluator<FullPivHouseholderQRMatrixQReturnType<MatrixType> > -// : public evaluator<ReturnByValue<FullPivHouseholderQRMatrixQReturnType<MatrixType> > > -// {}; - -} // end namespace internal - -template<typename MatrixType> -inline typename FullPivHouseholderQR<MatrixType>::MatrixQReturnType FullPivHouseholderQR<MatrixType>::matrixQ() const -{ - eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); - return MatrixQReturnType(m_qr, m_hCoeffs, m_rows_transpositions); -} - -/** \return the full-pivoting Householder QR decomposition of \c *this. - * - * \sa class FullPivHouseholderQR - */ -template<typename Derived> -const FullPivHouseholderQR<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::fullPivHouseholderQr() const -{ - return FullPivHouseholderQR<PlainObject>(eval()); -} - -} // end namespace Eigen - -#endif // EIGEN_FULLPIVOTINGHOUSEHOLDERQR_H diff --git a/external/eigen/include/eigen3/Eigen/src/QR/HouseholderQR.h b/external/eigen/include/eigen3/Eigen/src/QR/HouseholderQR.h deleted file mode 100644 index 801739fb..00000000 --- a/external/eigen/include/eigen3/Eigen/src/QR/HouseholderQR.h +++ /dev/null @@ -1,434 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2010 Vincent Lejeune -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_QR_H -#define EIGEN_QR_H - -namespace Eigen { - -namespace internal { -template<typename _MatrixType> struct traits<HouseholderQR<_MatrixType> > - : traits<_MatrixType> -{ - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - enum { Flags = 0 }; -}; - -} // end namespace internal - -/** \ingroup QR_Module - * - * - * \class HouseholderQR - * - * \brief Householder QR decomposition of a matrix - * - * \tparam _MatrixType the type of the matrix of which we are computing the QR decomposition - * - * This class performs a QR decomposition of a matrix \b A into matrices \b Q and \b R - * such that - * \f[ - * \mathbf{A} = \mathbf{Q} \, \mathbf{R} - * \f] - * by using Householder transformations. Here, \b Q a unitary matrix and \b R an upper triangular matrix. - * The result is stored in a compact way compatible with LAPACK. - * - * Note that no pivoting is performed. This is \b not a rank-revealing decomposition. - * If you want that feature, use FullPivHouseholderQR or ColPivHouseholderQR instead. - * - * This Householder QR decomposition is faster, but less numerically stable and less feature-full than - * FullPivHouseholderQR or ColPivHouseholderQR. - * - * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. - * - * \sa MatrixBase::householderQr() - */ -template<typename _MatrixType> class HouseholderQR - : public SolverBase<HouseholderQR<_MatrixType> > -{ - public: - - typedef _MatrixType MatrixType; - typedef SolverBase<HouseholderQR> Base; - friend class SolverBase<HouseholderQR>; - - EIGEN_GENERIC_PUBLIC_INTERFACE(HouseholderQR) - enum { - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime, (MatrixType::Flags&RowMajorBit) ? RowMajor : ColMajor, MaxRowsAtCompileTime, MaxRowsAtCompileTime> MatrixQType; - typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType; - typedef typename internal::plain_row_type<MatrixType>::type RowVectorType; - typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename HCoeffsType::ConjugateReturnType>::type> HouseholderSequenceType; - - /** - * \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via HouseholderQR::compute(const MatrixType&). - */ - HouseholderQR() : m_qr(), m_hCoeffs(), m_temp(), m_isInitialized(false) {} - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem \a size. - * \sa HouseholderQR() - */ - HouseholderQR(Index rows, Index cols) - : m_qr(rows, cols), - m_hCoeffs((std::min)(rows,cols)), - m_temp(cols), - m_isInitialized(false) {} - - /** \brief Constructs a QR factorization from a given matrix - * - * This constructor computes the QR factorization of the matrix \a matrix by calling - * the method compute(). It is a short cut for: - * - * \code - * HouseholderQR<MatrixType> qr(matrix.rows(), matrix.cols()); - * qr.compute(matrix); - * \endcode - * - * \sa compute() - */ - template<typename InputType> - explicit HouseholderQR(const EigenBase<InputType>& matrix) - : m_qr(matrix.rows(), matrix.cols()), - m_hCoeffs((std::min)(matrix.rows(),matrix.cols())), - m_temp(matrix.cols()), - m_isInitialized(false) - { - compute(matrix.derived()); - } - - - /** \brief Constructs a QR factorization from a given matrix - * - * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when - * \c MatrixType is a Eigen::Ref. - * - * \sa HouseholderQR(const EigenBase&) - */ - template<typename InputType> - explicit HouseholderQR(EigenBase<InputType>& matrix) - : m_qr(matrix.derived()), - m_hCoeffs((std::min)(matrix.rows(),matrix.cols())), - m_temp(matrix.cols()), - m_isInitialized(false) - { - computeInPlace(); - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** This method finds a solution x to the equation Ax=b, where A is the matrix of which - * *this is the QR decomposition, if any exists. - * - * \param b the right-hand-side of the equation to solve. - * - * \returns a solution. - * - * \note_about_checking_solutions - * - * \note_about_arbitrary_choice_of_solution - * - * Example: \include HouseholderQR_solve.cpp - * Output: \verbinclude HouseholderQR_solve.out - */ - template<typename Rhs> - inline const Solve<HouseholderQR, Rhs> - solve(const MatrixBase<Rhs>& b) const; - #endif - - /** This method returns an expression of the unitary matrix Q as a sequence of Householder transformations. - * - * The returned expression can directly be used to perform matrix products. It can also be assigned to a dense Matrix object. - * Here is an example showing how to recover the full or thin matrix Q, as well as how to perform matrix products using operator*: - * - * Example: \include HouseholderQR_householderQ.cpp - * Output: \verbinclude HouseholderQR_householderQ.out - */ - HouseholderSequenceType householderQ() const - { - eigen_assert(m_isInitialized && "HouseholderQR is not initialized."); - return HouseholderSequenceType(m_qr, m_hCoeffs.conjugate()); - } - - /** \returns a reference to the matrix where the Householder QR decomposition is stored - * in a LAPACK-compatible way. - */ - const MatrixType& matrixQR() const - { - eigen_assert(m_isInitialized && "HouseholderQR is not initialized."); - return m_qr; - } - - template<typename InputType> - HouseholderQR& compute(const EigenBase<InputType>& matrix) { - m_qr = matrix.derived(); - computeInPlace(); - return *this; - } - - /** \returns the absolute value of the determinant of the matrix of which - * *this is the QR decomposition. It has only linear complexity - * (that is, O(n) where n is the dimension of the square matrix) - * as the QR decomposition has already been computed. - * - * \note This is only for square matrices. - * - * \warning a determinant can be very big or small, so for matrices - * of large enough dimension, there is a risk of overflow/underflow. - * One way to work around that is to use logAbsDeterminant() instead. - * - * \sa logAbsDeterminant(), MatrixBase::determinant() - */ - typename MatrixType::RealScalar absDeterminant() const; - - /** \returns the natural log of the absolute value of the determinant of the matrix of which - * *this is the QR decomposition. It has only linear complexity - * (that is, O(n) where n is the dimension of the square matrix) - * as the QR decomposition has already been computed. - * - * \note This is only for square matrices. - * - * \note This method is useful to work around the risk of overflow/underflow that's inherent - * to determinant computation. - * - * \sa absDeterminant(), MatrixBase::determinant() - */ - typename MatrixType::RealScalar logAbsDeterminant() const; - - inline Index rows() const { return m_qr.rows(); } - inline Index cols() const { return m_qr.cols(); } - - /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q. - * - * For advanced uses only. - */ - const HCoeffsType& hCoeffs() const { return m_hCoeffs; } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename RhsType, typename DstType> - void _solve_impl(const RhsType &rhs, DstType &dst) const; - - template<bool Conjugate, typename RhsType, typename DstType> - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const; - #endif - - protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - void computeInPlace(); - - MatrixType m_qr; - HCoeffsType m_hCoeffs; - RowVectorType m_temp; - bool m_isInitialized; -}; - -template<typename MatrixType> -typename MatrixType::RealScalar HouseholderQR<MatrixType>::absDeterminant() const -{ - using std::abs; - eigen_assert(m_isInitialized && "HouseholderQR is not initialized."); - eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return abs(m_qr.diagonal().prod()); -} - -template<typename MatrixType> -typename MatrixType::RealScalar HouseholderQR<MatrixType>::logAbsDeterminant() const -{ - eigen_assert(m_isInitialized && "HouseholderQR is not initialized."); - eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return m_qr.diagonal().cwiseAbs().array().log().sum(); -} - -namespace internal { - -/** \internal */ -template<typename MatrixQR, typename HCoeffs> -void householder_qr_inplace_unblocked(MatrixQR& mat, HCoeffs& hCoeffs, typename MatrixQR::Scalar* tempData = 0) -{ - typedef typename MatrixQR::Scalar Scalar; - typedef typename MatrixQR::RealScalar RealScalar; - Index rows = mat.rows(); - Index cols = mat.cols(); - Index size = (std::min)(rows,cols); - - eigen_assert(hCoeffs.size() == size); - - typedef Matrix<Scalar,MatrixQR::ColsAtCompileTime,1> TempType; - TempType tempVector; - if(tempData==0) - { - tempVector.resize(cols); - tempData = tempVector.data(); - } - - for(Index k = 0; k < size; ++k) - { - Index remainingRows = rows - k; - Index remainingCols = cols - k - 1; - - RealScalar beta; - mat.col(k).tail(remainingRows).makeHouseholderInPlace(hCoeffs.coeffRef(k), beta); - mat.coeffRef(k,k) = beta; - - // apply H to remaining part of m_qr from the left - mat.bottomRightCorner(remainingRows, remainingCols) - .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows-1), hCoeffs.coeffRef(k), tempData+k+1); - } -} - -/** \internal */ -template<typename MatrixQR, typename HCoeffs, - typename MatrixQRScalar = typename MatrixQR::Scalar, - bool InnerStrideIsOne = (MatrixQR::InnerStrideAtCompileTime == 1 && HCoeffs::InnerStrideAtCompileTime == 1)> -struct householder_qr_inplace_blocked -{ - // This is specialized for LAPACK-supported Scalar types in HouseholderQR_LAPACKE.h - static void run(MatrixQR& mat, HCoeffs& hCoeffs, Index maxBlockSize=32, - typename MatrixQR::Scalar* tempData = 0) - { - typedef typename MatrixQR::Scalar Scalar; - typedef Block<MatrixQR,Dynamic,Dynamic> BlockType; - - Index rows = mat.rows(); - Index cols = mat.cols(); - Index size = (std::min)(rows, cols); - - typedef Matrix<Scalar,Dynamic,1,ColMajor,MatrixQR::MaxColsAtCompileTime,1> TempType; - TempType tempVector; - if(tempData==0) - { - tempVector.resize(cols); - tempData = tempVector.data(); - } - - Index blockSize = (std::min)(maxBlockSize,size); - - Index k = 0; - for (k = 0; k < size; k += blockSize) - { - Index bs = (std::min)(size-k,blockSize); // actual size of the block - Index tcols = cols - k - bs; // trailing columns - Index brows = rows-k; // rows of the block - - // partition the matrix: - // A00 | A01 | A02 - // mat = A10 | A11 | A12 - // A20 | A21 | A22 - // and performs the qr dec of [A11^T A12^T]^T - // and update [A21^T A22^T]^T using level 3 operations. - // Finally, the algorithm continue on A22 - - BlockType A11_21 = mat.block(k,k,brows,bs); - Block<HCoeffs,Dynamic,1> hCoeffsSegment = hCoeffs.segment(k,bs); - - householder_qr_inplace_unblocked(A11_21, hCoeffsSegment, tempData); - - if(tcols) - { - BlockType A21_22 = mat.block(k,k+bs,brows,tcols); - apply_block_householder_on_the_left(A21_22,A11_21,hCoeffsSegment, false); // false == backward - } - } - } -}; - -} // end namespace internal - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename _MatrixType> -template<typename RhsType, typename DstType> -void HouseholderQR<_MatrixType>::_solve_impl(const RhsType &rhs, DstType &dst) const -{ - const Index rank = (std::min)(rows(), cols()); - - typename RhsType::PlainObject c(rhs); - - c.applyOnTheLeft(householderQ().setLength(rank).adjoint() ); - - m_qr.topLeftCorner(rank, rank) - .template triangularView<Upper>() - .solveInPlace(c.topRows(rank)); - - dst.topRows(rank) = c.topRows(rank); - dst.bottomRows(cols()-rank).setZero(); -} - -template<typename _MatrixType> -template<bool Conjugate, typename RhsType, typename DstType> -void HouseholderQR<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const -{ - const Index rank = (std::min)(rows(), cols()); - - typename RhsType::PlainObject c(rhs); - - m_qr.topLeftCorner(rank, rank) - .template triangularView<Upper>() - .transpose().template conjugateIf<Conjugate>() - .solveInPlace(c.topRows(rank)); - - dst.topRows(rank) = c.topRows(rank); - dst.bottomRows(rows()-rank).setZero(); - - dst.applyOnTheLeft(householderQ().setLength(rank).template conjugateIf<!Conjugate>() ); -} -#endif - -/** Performs the QR factorization of the given matrix \a matrix. The result of - * the factorization is stored into \c *this, and a reference to \c *this - * is returned. - * - * \sa class HouseholderQR, HouseholderQR(const MatrixType&) - */ -template<typename MatrixType> -void HouseholderQR<MatrixType>::computeInPlace() -{ - check_template_parameters(); - - Index rows = m_qr.rows(); - Index cols = m_qr.cols(); - Index size = (std::min)(rows,cols); - - m_hCoeffs.resize(size); - - m_temp.resize(cols); - - internal::householder_qr_inplace_blocked<MatrixType, HCoeffsType>::run(m_qr, m_hCoeffs, 48, m_temp.data()); - - m_isInitialized = true; -} - -/** \return the Householder QR decomposition of \c *this. - * - * \sa class HouseholderQR - */ -template<typename Derived> -const HouseholderQR<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::householderQr() const -{ - return HouseholderQR<PlainObject>(eval()); -} - -} // end namespace Eigen - -#endif // EIGEN_QR_H diff --git a/external/eigen/include/eigen3/Eigen/src/QR/HouseholderQR_LAPACKE.h b/external/eigen/include/eigen3/Eigen/src/QR/HouseholderQR_LAPACKE.h deleted file mode 100644 index 1dc7d536..00000000 --- a/external/eigen/include/eigen3/Eigen/src/QR/HouseholderQR_LAPACKE.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to LAPACKe - * Householder QR decomposition of a matrix w/o pivoting based on - * LAPACKE_?geqrf function. - ******************************************************************************** -*/ - -#ifndef EIGEN_QR_LAPACKE_H -#define EIGEN_QR_LAPACKE_H - -namespace Eigen { - -namespace internal { - -/** \internal Specialization for the data types supported by LAPACKe */ - -#define EIGEN_LAPACKE_QR_NOPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \ -template<typename MatrixQR, typename HCoeffs> \ -struct householder_qr_inplace_blocked<MatrixQR, HCoeffs, EIGTYPE, true> \ -{ \ - static void run(MatrixQR& mat, HCoeffs& hCoeffs, Index = 32, \ - typename MatrixQR::Scalar* = 0) \ - { \ - lapack_int m = (lapack_int) mat.rows(); \ - lapack_int n = (lapack_int) mat.cols(); \ - lapack_int lda = (lapack_int) mat.outerStride(); \ - lapack_int matrix_order = (MatrixQR::IsRowMajor) ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ - LAPACKE_##LAPACKE_PREFIX##geqrf( matrix_order, m, n, (LAPACKE_TYPE*)mat.data(), lda, (LAPACKE_TYPE*)hCoeffs.data()); \ - hCoeffs.adjointInPlace(); \ - } \ -}; - -EIGEN_LAPACKE_QR_NOPIV(double, double, d) -EIGEN_LAPACKE_QR_NOPIV(float, float, s) -EIGEN_LAPACKE_QR_NOPIV(dcomplex, lapack_complex_double, z) -EIGEN_LAPACKE_QR_NOPIV(scomplex, lapack_complex_float, c) - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_QR_LAPACKE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h b/external/eigen/include/eigen3/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h deleted file mode 100644 index 013c7ae7..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h +++ /dev/null @@ -1,335 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Desire Nuentsa <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SUITESPARSEQRSUPPORT_H -#define EIGEN_SUITESPARSEQRSUPPORT_H - -namespace Eigen { - - template<typename MatrixType> class SPQR; - template<typename SPQRType> struct SPQRMatrixQReturnType; - template<typename SPQRType> struct SPQRMatrixQTransposeReturnType; - template <typename SPQRType, typename Derived> struct SPQR_QProduct; - namespace internal { - template <typename SPQRType> struct traits<SPQRMatrixQReturnType<SPQRType> > - { - typedef typename SPQRType::MatrixType ReturnType; - }; - template <typename SPQRType> struct traits<SPQRMatrixQTransposeReturnType<SPQRType> > - { - typedef typename SPQRType::MatrixType ReturnType; - }; - template <typename SPQRType, typename Derived> struct traits<SPQR_QProduct<SPQRType, Derived> > - { - typedef typename Derived::PlainObject ReturnType; - }; - } // End namespace internal - -/** - * \ingroup SPQRSupport_Module - * \class SPQR - * \brief Sparse QR factorization based on SuiteSparseQR library - * - * This class is used to perform a multithreaded and multifrontal rank-revealing QR decomposition - * of sparse matrices. The result is then used to solve linear leasts_square systems. - * Clearly, a QR factorization is returned such that A*P = Q*R where : - * - * P is the column permutation. Use colsPermutation() to get it. - * - * Q is the orthogonal matrix represented as Householder reflectors. - * Use matrixQ() to get an expression and matrixQ().transpose() to get the transpose. - * You can then apply it to a vector. - * - * R is the sparse triangular factor. Use matrixQR() to get it as SparseMatrix. - * NOTE : The Index type of R is always SuiteSparse_long. You can get it with SPQR::Index - * - * \tparam _MatrixType The type of the sparse matrix A, must be a column-major SparseMatrix<> - * - * \implsparsesolverconcept - * - * - */ -template<typename _MatrixType> -class SPQR : public SparseSolverBase<SPQR<_MatrixType> > -{ - protected: - typedef SparseSolverBase<SPQR<_MatrixType> > Base; - using Base::m_isInitialized; - public: - typedef typename _MatrixType::Scalar Scalar; - typedef typename _MatrixType::RealScalar RealScalar; - typedef SuiteSparse_long StorageIndex ; - typedef SparseMatrix<Scalar, ColMajor, StorageIndex> MatrixType; - typedef Map<PermutationMatrix<Dynamic, Dynamic, StorageIndex> > PermutationType; - enum { - ColsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic - }; - public: - SPQR() - : m_analysisIsOk(false), - m_factorizationIsOk(false), - m_isRUpToDate(false), - m_ordering(SPQR_ORDERING_DEFAULT), - m_allow_tol(SPQR_DEFAULT_TOL), - m_tolerance (NumTraits<Scalar>::epsilon()), - m_cR(0), - m_E(0), - m_H(0), - m_HPinv(0), - m_HTau(0), - m_useDefaultThreshold(true) - { - cholmod_l_start(&m_cc); - } - - explicit SPQR(const _MatrixType& matrix) - : m_analysisIsOk(false), - m_factorizationIsOk(false), - m_isRUpToDate(false), - m_ordering(SPQR_ORDERING_DEFAULT), - m_allow_tol(SPQR_DEFAULT_TOL), - m_tolerance (NumTraits<Scalar>::epsilon()), - m_cR(0), - m_E(0), - m_H(0), - m_HPinv(0), - m_HTau(0), - m_useDefaultThreshold(true) - { - cholmod_l_start(&m_cc); - compute(matrix); - } - - ~SPQR() - { - SPQR_free(); - cholmod_l_finish(&m_cc); - } - void SPQR_free() - { - cholmod_l_free_sparse(&m_H, &m_cc); - cholmod_l_free_sparse(&m_cR, &m_cc); - cholmod_l_free_dense(&m_HTau, &m_cc); - std::free(m_E); - std::free(m_HPinv); - } - - void compute(const _MatrixType& matrix) - { - if(m_isInitialized) SPQR_free(); - - MatrixType mat(matrix); - - /* Compute the default threshold as in MatLab, see: - * Tim Davis, "Algorithm 915, SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing - * Sparse QR Factorization, ACM Trans. on Math. Soft. 38(1), 2011, Page 8:3 - */ - RealScalar pivotThreshold = m_tolerance; - if(m_useDefaultThreshold) - { - RealScalar max2Norm = 0.0; - for (int j = 0; j < mat.cols(); j++) max2Norm = numext::maxi(max2Norm, mat.col(j).norm()); - if(max2Norm==RealScalar(0)) - max2Norm = RealScalar(1); - pivotThreshold = 20 * (mat.rows() + mat.cols()) * max2Norm * NumTraits<RealScalar>::epsilon(); - } - cholmod_sparse A; - A = viewAsCholmod(mat); - m_rows = matrix.rows(); - Index col = matrix.cols(); - m_rank = SuiteSparseQR<Scalar>(m_ordering, pivotThreshold, col, &A, - &m_cR, &m_E, &m_H, &m_HPinv, &m_HTau, &m_cc); - - if (!m_cR) - { - m_info = NumericalIssue; - m_isInitialized = false; - return; - } - m_info = Success; - m_isInitialized = true; - m_isRUpToDate = false; - } - /** - * Get the number of rows of the input matrix and the Q matrix - */ - inline Index rows() const {return m_rows; } - - /** - * Get the number of columns of the input matrix. - */ - inline Index cols() const { return m_cR->ncol; } - - template<typename Rhs, typename Dest> - void _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &dest) const - { - eigen_assert(m_isInitialized && " The QR factorization should be computed first, call compute()"); - eigen_assert(b.cols()==1 && "This method is for vectors only"); - - //Compute Q^T * b - typename Dest::PlainObject y, y2; - y = matrixQ().transpose() * b; - - // Solves with the triangular matrix R - Index rk = this->rank(); - y2 = y; - y.resize((std::max)(cols(),Index(y.rows())),y.cols()); - y.topRows(rk) = this->matrixR().topLeftCorner(rk, rk).template triangularView<Upper>().solve(y2.topRows(rk)); - - // Apply the column permutation - // colsPermutation() performs a copy of the permutation, - // so let's apply it manually: - for(Index i = 0; i < rk; ++i) dest.row(m_E[i]) = y.row(i); - for(Index i = rk; i < cols(); ++i) dest.row(m_E[i]).setZero(); - -// y.bottomRows(y.rows()-rk).setZero(); -// dest = colsPermutation() * y.topRows(cols()); - - m_info = Success; - } - - /** \returns the sparse triangular factor R. It is a sparse matrix - */ - const MatrixType matrixR() const - { - eigen_assert(m_isInitialized && " The QR factorization should be computed first, call compute()"); - if(!m_isRUpToDate) { - m_R = viewAsEigen<Scalar,ColMajor, typename MatrixType::StorageIndex>(*m_cR); - m_isRUpToDate = true; - } - return m_R; - } - /// Get an expression of the matrix Q - SPQRMatrixQReturnType<SPQR> matrixQ() const - { - return SPQRMatrixQReturnType<SPQR>(*this); - } - /// Get the permutation that was applied to columns of A - PermutationType colsPermutation() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return PermutationType(m_E, m_cR->ncol); - } - /** - * Gets the rank of the matrix. - * It should be equal to matrixQR().cols if the matrix is full-rank - */ - Index rank() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_cc.SPQR_istat[4]; - } - /// Set the fill-reducing ordering method to be used - void setSPQROrdering(int ord) { m_ordering = ord;} - /// Set the tolerance tol to treat columns with 2-norm < =tol as zero - void setPivotThreshold(const RealScalar& tol) - { - m_useDefaultThreshold = false; - m_tolerance = tol; - } - - /** \returns a pointer to the SPQR workspace */ - cholmod_common *cholmodCommon() const { return &m_cc; } - - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the sparse QR can not be computed - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - protected: - bool m_analysisIsOk; - bool m_factorizationIsOk; - mutable bool m_isRUpToDate; - mutable ComputationInfo m_info; - int m_ordering; // Ordering method to use, see SPQR's manual - int m_allow_tol; // Allow to use some tolerance during numerical factorization. - RealScalar m_tolerance; // treat columns with 2-norm below this tolerance as zero - mutable cholmod_sparse *m_cR; // The sparse R factor in cholmod format - mutable MatrixType m_R; // The sparse matrix R in Eigen format - mutable StorageIndex *m_E; // The permutation applied to columns - mutable cholmod_sparse *m_H; //The householder vectors - mutable StorageIndex *m_HPinv; // The row permutation of H - mutable cholmod_dense *m_HTau; // The Householder coefficients - mutable Index m_rank; // The rank of the matrix - mutable cholmod_common m_cc; // Workspace and parameters - bool m_useDefaultThreshold; // Use default threshold - Index m_rows; - template<typename ,typename > friend struct SPQR_QProduct; -}; - -template <typename SPQRType, typename Derived> -struct SPQR_QProduct : ReturnByValue<SPQR_QProduct<SPQRType,Derived> > -{ - typedef typename SPQRType::Scalar Scalar; - typedef typename SPQRType::StorageIndex StorageIndex; - //Define the constructor to get reference to argument types - SPQR_QProduct(const SPQRType& spqr, const Derived& other, bool transpose) : m_spqr(spqr),m_other(other),m_transpose(transpose) {} - - inline Index rows() const { return m_transpose ? m_spqr.rows() : m_spqr.cols(); } - inline Index cols() const { return m_other.cols(); } - // Assign to a vector - template<typename ResType> - void evalTo(ResType& res) const - { - cholmod_dense y_cd; - cholmod_dense *x_cd; - int method = m_transpose ? SPQR_QTX : SPQR_QX; - cholmod_common *cc = m_spqr.cholmodCommon(); - y_cd = viewAsCholmod(m_other.const_cast_derived()); - x_cd = SuiteSparseQR_qmult<Scalar>(method, m_spqr.m_H, m_spqr.m_HTau, m_spqr.m_HPinv, &y_cd, cc); - res = Matrix<Scalar,ResType::RowsAtCompileTime,ResType::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x), x_cd->nrow, x_cd->ncol); - cholmod_l_free_dense(&x_cd, cc); - } - const SPQRType& m_spqr; - const Derived& m_other; - bool m_transpose; - -}; -template<typename SPQRType> -struct SPQRMatrixQReturnType{ - - SPQRMatrixQReturnType(const SPQRType& spqr) : m_spqr(spqr) {} - template<typename Derived> - SPQR_QProduct<SPQRType, Derived> operator*(const MatrixBase<Derived>& other) - { - return SPQR_QProduct<SPQRType,Derived>(m_spqr,other.derived(),false); - } - SPQRMatrixQTransposeReturnType<SPQRType> adjoint() const - { - return SPQRMatrixQTransposeReturnType<SPQRType>(m_spqr); - } - // To use for operations with the transpose of Q - SPQRMatrixQTransposeReturnType<SPQRType> transpose() const - { - return SPQRMatrixQTransposeReturnType<SPQRType>(m_spqr); - } - const SPQRType& m_spqr; -}; - -template<typename SPQRType> -struct SPQRMatrixQTransposeReturnType{ - SPQRMatrixQTransposeReturnType(const SPQRType& spqr) : m_spqr(spqr) {} - template<typename Derived> - SPQR_QProduct<SPQRType,Derived> operator*(const MatrixBase<Derived>& other) - { - return SPQR_QProduct<SPQRType,Derived>(m_spqr,other.derived(), true); - } - const SPQRType& m_spqr; -}; - -}// End namespace Eigen -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/SVD/BDCSVD.h b/external/eigen/include/eigen3/Eigen/src/SVD/BDCSVD.h deleted file mode 100644 index bcec45f5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SVD/BDCSVD.h +++ /dev/null @@ -1,1350 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// We used the "A Divide-And-Conquer Algorithm for the Bidiagonal SVD" -// research report written by Ming Gu and Stanley C.Eisenstat -// The code variable names correspond to the names they used in their -// report -// -// Copyright (C) 2013 Gauthier Brun <brun.gauthier@gmail.com> -// Copyright (C) 2013 Nicolas Carre <nicolas.carre@ensimag.fr> -// Copyright (C) 2013 Jean Ceccato <jean.ceccato@ensimag.fr> -// Copyright (C) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr> -// Copyright (C) 2013 Jitse Niesen <jitse@maths.leeds.ac.uk> -// Copyright (C) 2014-2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BDCSVD_H -#define EIGEN_BDCSVD_H -// #define EIGEN_BDCSVD_DEBUG_VERBOSE -// #define EIGEN_BDCSVD_SANITY_CHECKS - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS -#undef eigen_internal_assert -#define eigen_internal_assert(X) assert(X); -#endif - -namespace Eigen { - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE -IOFormat bdcsvdfmt(8, 0, ", ", "\n", " [", "]"); -#endif - -template<typename _MatrixType> class BDCSVD; - -namespace internal { - -template<typename _MatrixType> -struct traits<BDCSVD<_MatrixType> > - : traits<_MatrixType> -{ - typedef _MatrixType MatrixType; -}; - -} // end namespace internal - - -/** \ingroup SVD_Module - * - * - * \class BDCSVD - * - * \brief class Bidiagonal Divide and Conquer SVD - * - * \tparam _MatrixType the type of the matrix of which we are computing the SVD decomposition - * - * This class first reduces the input matrix to bi-diagonal form using class UpperBidiagonalization, - * and then performs a divide-and-conquer diagonalization. Small blocks are diagonalized using class JacobiSVD. - * You can control the switching size with the setSwitchSize() method, default is 16. - * For small matrice (<16), it is thus preferable to directly use JacobiSVD. For larger ones, BDCSVD is highly - * recommended and can several order of magnitude faster. - * - * \warning this algorithm is unlikely to provide accurate result when compiled with unsafe math optimizations. - * For instance, this concerns Intel's compiler (ICC), which performs such optimization by default unless - * you compile with the \c -fp-model \c precise option. Likewise, the \c -ffast-math option of GCC or clang will - * significantly degrade the accuracy. - * - * \sa class JacobiSVD - */ -template<typename _MatrixType> -class BDCSVD : public SVDBase<BDCSVD<_MatrixType> > -{ - typedef SVDBase<BDCSVD> Base; - -public: - using Base::rows; - using Base::cols; - using Base::computeU; - using Base::computeV; - - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; - typedef typename NumTraits<RealScalar>::Literal Literal; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime, ColsAtCompileTime), - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime, MaxColsAtCompileTime), - MatrixOptions = MatrixType::Options - }; - - typedef typename Base::MatrixUType MatrixUType; - typedef typename Base::MatrixVType MatrixVType; - typedef typename Base::SingularValuesType SingularValuesType; - - typedef Matrix<Scalar, Dynamic, Dynamic, ColMajor> MatrixX; - typedef Matrix<RealScalar, Dynamic, Dynamic, ColMajor> MatrixXr; - typedef Matrix<RealScalar, Dynamic, 1> VectorType; - typedef Array<RealScalar, Dynamic, 1> ArrayXr; - typedef Array<Index,1,Dynamic> ArrayXi; - typedef Ref<ArrayXr> ArrayRef; - typedef Ref<ArrayXi> IndicesRef; - - /** \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via BDCSVD::compute(const MatrixType&). - */ - BDCSVD() : m_algoswap(16), m_isTranspose(false), m_compU(false), m_compV(false), m_numIters(0) - {} - - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem size. - * \sa BDCSVD() - */ - BDCSVD(Index rows, Index cols, unsigned int computationOptions = 0) - : m_algoswap(16), m_numIters(0) - { - allocate(rows, cols, computationOptions); - } - - /** \brief Constructor performing the decomposition of given matrix. - * - * \param matrix the matrix to decompose - * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed. - * By default, none is computed. This is a bit - field, the possible bits are #ComputeFullU, #ComputeThinU, - * #ComputeFullV, #ComputeThinV. - * - * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not - * available with the (non - default) FullPivHouseholderQR preconditioner. - */ - BDCSVD(const MatrixType& matrix, unsigned int computationOptions = 0) - : m_algoswap(16), m_numIters(0) - { - compute(matrix, computationOptions); - } - - ~BDCSVD() - { - } - - /** \brief Method performing the decomposition of given matrix using custom options. - * - * \param matrix the matrix to decompose - * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed. - * By default, none is computed. This is a bit - field, the possible bits are #ComputeFullU, #ComputeThinU, - * #ComputeFullV, #ComputeThinV. - * - * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not - * available with the (non - default) FullPivHouseholderQR preconditioner. - */ - BDCSVD& compute(const MatrixType& matrix, unsigned int computationOptions); - - /** \brief Method performing the decomposition of given matrix using current options. - * - * \param matrix the matrix to decompose - * - * This method uses the current \a computationOptions, as already passed to the constructor or to compute(const MatrixType&, unsigned int). - */ - BDCSVD& compute(const MatrixType& matrix) - { - return compute(matrix, this->m_computationOptions); - } - - void setSwitchSize(int s) - { - eigen_assert(s>3 && "BDCSVD the size of the algo switch has to be greater than 3"); - m_algoswap = s; - } - -private: - void allocate(Index rows, Index cols, unsigned int computationOptions); - void divide(Index firstCol, Index lastCol, Index firstRowW, Index firstColW, Index shift); - void computeSVDofM(Index firstCol, Index n, MatrixXr& U, VectorType& singVals, MatrixXr& V); - void computeSingVals(const ArrayRef& col0, const ArrayRef& diag, const IndicesRef& perm, VectorType& singVals, ArrayRef shifts, ArrayRef mus); - void perturbCol0(const ArrayRef& col0, const ArrayRef& diag, const IndicesRef& perm, const VectorType& singVals, const ArrayRef& shifts, const ArrayRef& mus, ArrayRef zhat); - void computeSingVecs(const ArrayRef& zhat, const ArrayRef& diag, const IndicesRef& perm, const VectorType& singVals, const ArrayRef& shifts, const ArrayRef& mus, MatrixXr& U, MatrixXr& V); - void deflation43(Index firstCol, Index shift, Index i, Index size); - void deflation44(Index firstColu , Index firstColm, Index firstRowW, Index firstColW, Index i, Index j, Index size); - void deflation(Index firstCol, Index lastCol, Index k, Index firstRowW, Index firstColW, Index shift); - template<typename HouseholderU, typename HouseholderV, typename NaiveU, typename NaiveV> - void copyUV(const HouseholderU &householderU, const HouseholderV &householderV, const NaiveU &naiveU, const NaiveV &naivev); - void structured_update(Block<MatrixXr,Dynamic,Dynamic> A, const MatrixXr &B, Index n1); - static RealScalar secularEq(RealScalar x, const ArrayRef& col0, const ArrayRef& diag, const IndicesRef &perm, const ArrayRef& diagShifted, RealScalar shift); - -protected: - MatrixXr m_naiveU, m_naiveV; - MatrixXr m_computed; - Index m_nRec; - ArrayXr m_workspace; - ArrayXi m_workspaceI; - int m_algoswap; - bool m_isTranspose, m_compU, m_compV; - - using Base::m_singularValues; - using Base::m_diagSize; - using Base::m_computeFullU; - using Base::m_computeFullV; - using Base::m_computeThinU; - using Base::m_computeThinV; - using Base::m_matrixU; - using Base::m_matrixV; - using Base::m_isInitialized; - using Base::m_nonzeroSingularValues; - -public: - int m_numIters; -}; //end class BDCSVD - - -// Method to allocate and initialize matrix and attributes -template<typename MatrixType> -void BDCSVD<MatrixType>::allocate(Eigen::Index rows, Eigen::Index cols, unsigned int computationOptions) -{ - m_isTranspose = (cols > rows); - - if (Base::allocate(rows, cols, computationOptions)) - return; - - m_computed = MatrixXr::Zero(m_diagSize + 1, m_diagSize ); - m_compU = computeV(); - m_compV = computeU(); - if (m_isTranspose) - std::swap(m_compU, m_compV); - - if (m_compU) m_naiveU = MatrixXr::Zero(m_diagSize + 1, m_diagSize + 1 ); - else m_naiveU = MatrixXr::Zero(2, m_diagSize + 1 ); - - if (m_compV) m_naiveV = MatrixXr::Zero(m_diagSize, m_diagSize); - - m_workspace.resize((m_diagSize+1)*(m_diagSize+1)*3); - m_workspaceI.resize(3*m_diagSize); -}// end allocate - -template<typename MatrixType> -BDCSVD<MatrixType>& BDCSVD<MatrixType>::compute(const MatrixType& matrix, unsigned int computationOptions) -{ -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "\n\n\n======================================================================================================================\n\n\n"; -#endif - allocate(matrix.rows(), matrix.cols(), computationOptions); - using std::abs; - - const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)(); - - //**** step -1 - If the problem is too small, directly falls back to JacobiSVD and return - if(matrix.cols() < m_algoswap) - { - // FIXME this line involves temporaries - JacobiSVD<MatrixType> jsvd(matrix,computationOptions); - if(computeU()) m_matrixU = jsvd.matrixU(); - if(computeV()) m_matrixV = jsvd.matrixV(); - m_singularValues = jsvd.singularValues(); - m_nonzeroSingularValues = jsvd.nonzeroSingularValues(); - m_isInitialized = true; - return *this; - } - - //**** step 0 - Copy the input matrix and apply scaling to reduce over/under-flows - RealScalar scale = matrix.cwiseAbs().maxCoeff(); - if(scale==Literal(0)) scale = Literal(1); - MatrixX copy; - if (m_isTranspose) copy = matrix.adjoint()/scale; - else copy = matrix/scale; - - //**** step 1 - Bidiagonalization - // FIXME this line involves temporaries - internal::UpperBidiagonalization<MatrixX> bid(copy); - - //**** step 2 - Divide & Conquer - m_naiveU.setZero(); - m_naiveV.setZero(); - // FIXME this line involves a temporary matrix - m_computed.topRows(m_diagSize) = bid.bidiagonal().toDenseMatrix().transpose(); - m_computed.template bottomRows<1>().setZero(); - divide(0, m_diagSize - 1, 0, 0, 0); - - //**** step 3 - Copy singular values and vectors - for (int i=0; i<m_diagSize; i++) - { - RealScalar a = abs(m_computed.coeff(i, i)); - m_singularValues.coeffRef(i) = a * scale; - if (a<considerZero) - { - m_nonzeroSingularValues = i; - m_singularValues.tail(m_diagSize - i - 1).setZero(); - break; - } - else if (i == m_diagSize - 1) - { - m_nonzeroSingularValues = i + 1; - break; - } - } - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE -// std::cout << "m_naiveU\n" << m_naiveU << "\n\n"; -// std::cout << "m_naiveV\n" << m_naiveV << "\n\n"; -#endif - if(m_isTranspose) copyUV(bid.householderV(), bid.householderU(), m_naiveV, m_naiveU); - else copyUV(bid.householderU(), bid.householderV(), m_naiveU, m_naiveV); - - m_isInitialized = true; - return *this; -}// end compute - - -template<typename MatrixType> -template<typename HouseholderU, typename HouseholderV, typename NaiveU, typename NaiveV> -void BDCSVD<MatrixType>::copyUV(const HouseholderU &householderU, const HouseholderV &householderV, const NaiveU &naiveU, const NaiveV &naiveV) -{ - // Note exchange of U and V: m_matrixU is set from m_naiveV and vice versa - if (computeU()) - { - Index Ucols = m_computeThinU ? m_diagSize : householderU.cols(); - m_matrixU = MatrixX::Identity(householderU.cols(), Ucols); - m_matrixU.topLeftCorner(m_diagSize, m_diagSize) = naiveV.template cast<Scalar>().topLeftCorner(m_diagSize, m_diagSize); - householderU.applyThisOnTheLeft(m_matrixU); // FIXME this line involves a temporary buffer - } - if (computeV()) - { - Index Vcols = m_computeThinV ? m_diagSize : householderV.cols(); - m_matrixV = MatrixX::Identity(householderV.cols(), Vcols); - m_matrixV.topLeftCorner(m_diagSize, m_diagSize) = naiveU.template cast<Scalar>().topLeftCorner(m_diagSize, m_diagSize); - householderV.applyThisOnTheLeft(m_matrixV); // FIXME this line involves a temporary buffer - } -} - -/** \internal - * Performs A = A * B exploiting the special structure of the matrix A. Splitting A as: - * A = [A1] - * [A2] - * such that A1.rows()==n1, then we assume that at least half of the columns of A1 and A2 are zeros. - * We can thus pack them prior to the the matrix product. However, this is only worth the effort if the matrix is large - * enough. - */ -template<typename MatrixType> -void BDCSVD<MatrixType>::structured_update(Block<MatrixXr,Dynamic,Dynamic> A, const MatrixXr &B, Index n1) -{ - Index n = A.rows(); - if(n>100) - { - // If the matrices are large enough, let's exploit the sparse structure of A by - // splitting it in half (wrt n1), and packing the non-zero columns. - Index n2 = n - n1; - Map<MatrixXr> A1(m_workspace.data() , n1, n); - Map<MatrixXr> A2(m_workspace.data()+ n1*n, n2, n); - Map<MatrixXr> B1(m_workspace.data()+ n*n, n, n); - Map<MatrixXr> B2(m_workspace.data()+2*n*n, n, n); - Index k1=0, k2=0; - for(Index j=0; j<n; ++j) - { - if( (A.col(j).head(n1).array()!=Literal(0)).any() ) - { - A1.col(k1) = A.col(j).head(n1); - B1.row(k1) = B.row(j); - ++k1; - } - if( (A.col(j).tail(n2).array()!=Literal(0)).any() ) - { - A2.col(k2) = A.col(j).tail(n2); - B2.row(k2) = B.row(j); - ++k2; - } - } - - A.topRows(n1).noalias() = A1.leftCols(k1) * B1.topRows(k1); - A.bottomRows(n2).noalias() = A2.leftCols(k2) * B2.topRows(k2); - } - else - { - Map<MatrixXr,Aligned> tmp(m_workspace.data(),n,n); - tmp.noalias() = A*B; - A = tmp; - } -} - -// The divide algorithm is done "in place", we are always working on subsets of the same matrix. The divide methods takes as argument the -// place of the submatrix we are currently working on. - -//@param firstCol : The Index of the first column of the submatrix of m_computed and for m_naiveU; -//@param lastCol : The Index of the last column of the submatrix of m_computed and for m_naiveU; -// lastCol + 1 - firstCol is the size of the submatrix. -//@param firstRowW : The Index of the first row of the matrix W that we are to change. (see the reference paper section 1 for more information on W) -//@param firstRowW : Same as firstRowW with the column. -//@param shift : Each time one takes the left submatrix, one must add 1 to the shift. Why? Because! We actually want the last column of the U submatrix -// to become the first column (*coeff) and to shift all the other columns to the right. There are more details on the reference paper. -template<typename MatrixType> -void BDCSVD<MatrixType>::divide (Eigen::Index firstCol, Eigen::Index lastCol, Eigen::Index firstRowW, Eigen::Index firstColW, Eigen::Index shift) -{ - // requires rows = cols + 1; - using std::pow; - using std::sqrt; - using std::abs; - const Index n = lastCol - firstCol + 1; - const Index k = n/2; - const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)(); - RealScalar alphaK; - RealScalar betaK; - RealScalar r0; - RealScalar lambda, phi, c0, s0; - VectorType l, f; - // We use the other algorithm which is more efficient for small - // matrices. - if (n < m_algoswap) - { - // FIXME this line involves temporaries - JacobiSVD<MatrixXr> b(m_computed.block(firstCol, firstCol, n + 1, n), ComputeFullU | (m_compV ? ComputeFullV : 0)); - if (m_compU) - m_naiveU.block(firstCol, firstCol, n + 1, n + 1).real() = b.matrixU(); - else - { - m_naiveU.row(0).segment(firstCol, n + 1).real() = b.matrixU().row(0); - m_naiveU.row(1).segment(firstCol, n + 1).real() = b.matrixU().row(n); - } - if (m_compV) m_naiveV.block(firstRowW, firstColW, n, n).real() = b.matrixV(); - m_computed.block(firstCol + shift, firstCol + shift, n + 1, n).setZero(); - m_computed.diagonal().segment(firstCol + shift, n) = b.singularValues().head(n); - return; - } - // We use the divide and conquer algorithm - alphaK = m_computed(firstCol + k, firstCol + k); - betaK = m_computed(firstCol + k + 1, firstCol + k); - // The divide must be done in that order in order to have good results. Divide change the data inside the submatrices - // and the divide of the right submatrice reads one column of the left submatrice. That's why we need to treat the - // right submatrix before the left one. - divide(k + 1 + firstCol, lastCol, k + 1 + firstRowW, k + 1 + firstColW, shift); - divide(firstCol, k - 1 + firstCol, firstRowW, firstColW + 1, shift + 1); - - if (m_compU) - { - lambda = m_naiveU(firstCol + k, firstCol + k); - phi = m_naiveU(firstCol + k + 1, lastCol + 1); - } - else - { - lambda = m_naiveU(1, firstCol + k); - phi = m_naiveU(0, lastCol + 1); - } - r0 = sqrt((abs(alphaK * lambda) * abs(alphaK * lambda)) + abs(betaK * phi) * abs(betaK * phi)); - if (m_compU) - { - l = m_naiveU.row(firstCol + k).segment(firstCol, k); - f = m_naiveU.row(firstCol + k + 1).segment(firstCol + k + 1, n - k - 1); - } - else - { - l = m_naiveU.row(1).segment(firstCol, k); - f = m_naiveU.row(0).segment(firstCol + k + 1, n - k - 1); - } - if (m_compV) m_naiveV(firstRowW+k, firstColW) = Literal(1); - if (r0<considerZero) - { - c0 = Literal(1); - s0 = Literal(0); - } - else - { - c0 = alphaK * lambda / r0; - s0 = betaK * phi / r0; - } - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(m_naiveU.allFinite()); - assert(m_naiveV.allFinite()); - assert(m_computed.allFinite()); -#endif - - if (m_compU) - { - MatrixXr q1 (m_naiveU.col(firstCol + k).segment(firstCol, k + 1)); - // we shiftW Q1 to the right - for (Index i = firstCol + k - 1; i >= firstCol; i--) - m_naiveU.col(i + 1).segment(firstCol, k + 1) = m_naiveU.col(i).segment(firstCol, k + 1); - // we shift q1 at the left with a factor c0 - m_naiveU.col(firstCol).segment( firstCol, k + 1) = (q1 * c0); - // last column = q1 * - s0 - m_naiveU.col(lastCol + 1).segment(firstCol, k + 1) = (q1 * ( - s0)); - // first column = q2 * s0 - m_naiveU.col(firstCol).segment(firstCol + k + 1, n - k) = m_naiveU.col(lastCol + 1).segment(firstCol + k + 1, n - k) * s0; - // q2 *= c0 - m_naiveU.col(lastCol + 1).segment(firstCol + k + 1, n - k) *= c0; - } - else - { - RealScalar q1 = m_naiveU(0, firstCol + k); - // we shift Q1 to the right - for (Index i = firstCol + k - 1; i >= firstCol; i--) - m_naiveU(0, i + 1) = m_naiveU(0, i); - // we shift q1 at the left with a factor c0 - m_naiveU(0, firstCol) = (q1 * c0); - // last column = q1 * - s0 - m_naiveU(0, lastCol + 1) = (q1 * ( - s0)); - // first column = q2 * s0 - m_naiveU(1, firstCol) = m_naiveU(1, lastCol + 1) *s0; - // q2 *= c0 - m_naiveU(1, lastCol + 1) *= c0; - m_naiveU.row(1).segment(firstCol + 1, k).setZero(); - m_naiveU.row(0).segment(firstCol + k + 1, n - k - 1).setZero(); - } - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(m_naiveU.allFinite()); - assert(m_naiveV.allFinite()); - assert(m_computed.allFinite()); -#endif - - m_computed(firstCol + shift, firstCol + shift) = r0; - m_computed.col(firstCol + shift).segment(firstCol + shift + 1, k) = alphaK * l.transpose().real(); - m_computed.col(firstCol + shift).segment(firstCol + shift + k + 1, n - k - 1) = betaK * f.transpose().real(); - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - ArrayXr tmp1 = (m_computed.block(firstCol+shift, firstCol+shift, n, n)).jacobiSvd().singularValues(); -#endif - // Second part: try to deflate singular values in combined matrix - deflation(firstCol, lastCol, k, firstRowW, firstColW, shift); -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - ArrayXr tmp2 = (m_computed.block(firstCol+shift, firstCol+shift, n, n)).jacobiSvd().singularValues(); - std::cout << "\n\nj1 = " << tmp1.transpose().format(bdcsvdfmt) << "\n"; - std::cout << "j2 = " << tmp2.transpose().format(bdcsvdfmt) << "\n\n"; - std::cout << "err: " << ((tmp1-tmp2).abs()>1e-12*tmp2.abs()).transpose() << "\n"; - static int count = 0; - std::cout << "# " << ++count << "\n\n"; - assert((tmp1-tmp2).matrix().norm() < 1e-14*tmp2.matrix().norm()); -// assert(count<681); -// assert(((tmp1-tmp2).abs()<1e-13*tmp2.abs()).all()); -#endif - - // Third part: compute SVD of combined matrix - MatrixXr UofSVD, VofSVD; - VectorType singVals; - computeSVDofM(firstCol + shift, n, UofSVD, singVals, VofSVD); - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(UofSVD.allFinite()); - assert(VofSVD.allFinite()); -#endif - - if (m_compU) - structured_update(m_naiveU.block(firstCol, firstCol, n + 1, n + 1), UofSVD, (n+2)/2); - else - { - Map<Matrix<RealScalar,2,Dynamic>,Aligned> tmp(m_workspace.data(),2,n+1); - tmp.noalias() = m_naiveU.middleCols(firstCol, n+1) * UofSVD; - m_naiveU.middleCols(firstCol, n + 1) = tmp; - } - - if (m_compV) structured_update(m_naiveV.block(firstRowW, firstColW, n, n), VofSVD, (n+1)/2); - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(m_naiveU.allFinite()); - assert(m_naiveV.allFinite()); - assert(m_computed.allFinite()); -#endif - - m_computed.block(firstCol + shift, firstCol + shift, n, n).setZero(); - m_computed.block(firstCol + shift, firstCol + shift, n, n).diagonal() = singVals; -}// end divide - -// Compute SVD of m_computed.block(firstCol, firstCol, n + 1, n); this block only has non-zeros in -// the first column and on the diagonal and has undergone deflation, so diagonal is in increasing -// order except for possibly the (0,0) entry. The computed SVD is stored U, singVals and V, except -// that if m_compV is false, then V is not computed. Singular values are sorted in decreasing order. -// -// TODO Opportunities for optimization: better root finding algo, better stopping criterion, better -// handling of round-off errors, be consistent in ordering -// For instance, to solve the secular equation using FMM, see http://www.stat.uchicago.edu/~lekheng/courses/302/classics/greengard-rokhlin.pdf -template <typename MatrixType> -void BDCSVD<MatrixType>::computeSVDofM(Eigen::Index firstCol, Eigen::Index n, MatrixXr& U, VectorType& singVals, MatrixXr& V) -{ - const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)(); - using std::abs; - ArrayRef col0 = m_computed.col(firstCol).segment(firstCol, n); - m_workspace.head(n) = m_computed.block(firstCol, firstCol, n, n).diagonal(); - ArrayRef diag = m_workspace.head(n); - diag(0) = Literal(0); - - // Allocate space for singular values and vectors - singVals.resize(n); - U.resize(n+1, n+1); - if (m_compV) V.resize(n, n); - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - if (col0.hasNaN() || diag.hasNaN()) - std::cout << "\n\nHAS NAN\n\n"; -#endif - - // Many singular values might have been deflated, the zero ones have been moved to the end, - // but others are interleaved and we must ignore them at this stage. - // To this end, let's compute a permutation skipping them: - Index actual_n = n; - while(actual_n>1 && diag(actual_n-1)==Literal(0)) {--actual_n; eigen_internal_assert(col0(actual_n)==Literal(0)); } - Index m = 0; // size of the deflated problem - for(Index k=0;k<actual_n;++k) - if(abs(col0(k))>considerZero) - m_workspaceI(m++) = k; - Map<ArrayXi> perm(m_workspaceI.data(),m); - - Map<ArrayXr> shifts(m_workspace.data()+1*n, n); - Map<ArrayXr> mus(m_workspace.data()+2*n, n); - Map<ArrayXr> zhat(m_workspace.data()+3*n, n); - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "computeSVDofM using:\n"; - std::cout << " z: " << col0.transpose() << "\n"; - std::cout << " d: " << diag.transpose() << "\n"; -#endif - - // Compute singVals, shifts, and mus - computeSingVals(col0, diag, perm, singVals, shifts, mus); - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << " j: " << (m_computed.block(firstCol, firstCol, n, n)).jacobiSvd().singularValues().transpose().reverse() << "\n\n"; - std::cout << " sing-val: " << singVals.transpose() << "\n"; - std::cout << " mu: " << mus.transpose() << "\n"; - std::cout << " shift: " << shifts.transpose() << "\n"; - - { - std::cout << "\n\n mus: " << mus.head(actual_n).transpose() << "\n\n"; - std::cout << " check1 (expect0) : " << ((singVals.array()-(shifts+mus)) / singVals.array()).head(actual_n).transpose() << "\n\n"; - assert((((singVals.array()-(shifts+mus)) / singVals.array()).head(actual_n) >= 0).all()); - std::cout << " check2 (>0) : " << ((singVals.array()-diag) / singVals.array()).head(actual_n).transpose() << "\n\n"; - assert((((singVals.array()-diag) / singVals.array()).head(actual_n) >= 0).all()); - } -#endif - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(singVals.allFinite()); - assert(mus.allFinite()); - assert(shifts.allFinite()); -#endif - - // Compute zhat - perturbCol0(col0, diag, perm, singVals, shifts, mus, zhat); -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << " zhat: " << zhat.transpose() << "\n"; -#endif - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(zhat.allFinite()); -#endif - - computeSingVecs(zhat, diag, perm, singVals, shifts, mus, U, V); - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "U^T U: " << (U.transpose() * U - MatrixXr(MatrixXr::Identity(U.cols(),U.cols()))).norm() << "\n"; - std::cout << "V^T V: " << (V.transpose() * V - MatrixXr(MatrixXr::Identity(V.cols(),V.cols()))).norm() << "\n"; -#endif - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(m_naiveU.allFinite()); - assert(m_naiveV.allFinite()); - assert(m_computed.allFinite()); - assert(U.allFinite()); - assert(V.allFinite()); -// assert((U.transpose() * U - MatrixXr(MatrixXr::Identity(U.cols(),U.cols()))).norm() < 100*NumTraits<RealScalar>::epsilon() * n); -// assert((V.transpose() * V - MatrixXr(MatrixXr::Identity(V.cols(),V.cols()))).norm() < 100*NumTraits<RealScalar>::epsilon() * n); -#endif - - // Because of deflation, the singular values might not be completely sorted. - // Fortunately, reordering them is a O(n) problem - for(Index i=0; i<actual_n-1; ++i) - { - if(singVals(i)>singVals(i+1)) - { - using std::swap; - swap(singVals(i),singVals(i+1)); - U.col(i).swap(U.col(i+1)); - if(m_compV) V.col(i).swap(V.col(i+1)); - } - } - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - { - bool singular_values_sorted = (((singVals.segment(1,actual_n-1)-singVals.head(actual_n-1))).array() >= 0).all(); - if(!singular_values_sorted) - std::cout << "Singular values are not sorted: " << singVals.segment(1,actual_n).transpose() << "\n"; - assert(singular_values_sorted); - } -#endif - - // Reverse order so that singular values in increased order - // Because of deflation, the zeros singular-values are already at the end - singVals.head(actual_n).reverseInPlace(); - U.leftCols(actual_n).rowwise().reverseInPlace(); - if (m_compV) V.leftCols(actual_n).rowwise().reverseInPlace(); - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - JacobiSVD<MatrixXr> jsvd(m_computed.block(firstCol, firstCol, n, n) ); - std::cout << " * j: " << jsvd.singularValues().transpose() << "\n\n"; - std::cout << " * sing-val: " << singVals.transpose() << "\n"; -// std::cout << " * err: " << ((jsvd.singularValues()-singVals)>1e-13*singVals.norm()).transpose() << "\n"; -#endif -} - -template <typename MatrixType> -typename BDCSVD<MatrixType>::RealScalar BDCSVD<MatrixType>::secularEq(RealScalar mu, const ArrayRef& col0, const ArrayRef& diag, const IndicesRef &perm, const ArrayRef& diagShifted, RealScalar shift) -{ - Index m = perm.size(); - RealScalar res = Literal(1); - for(Index i=0; i<m; ++i) - { - Index j = perm(i); - // The following expression could be rewritten to involve only a single division, - // but this would make the expression more sensitive to overflow. - res += (col0(j) / (diagShifted(j) - mu)) * (col0(j) / (diag(j) + shift + mu)); - } - return res; - -} - -template <typename MatrixType> -void BDCSVD<MatrixType>::computeSingVals(const ArrayRef& col0, const ArrayRef& diag, const IndicesRef &perm, - VectorType& singVals, ArrayRef shifts, ArrayRef mus) -{ - using std::abs; - using std::swap; - using std::sqrt; - - Index n = col0.size(); - Index actual_n = n; - // Note that here actual_n is computed based on col0(i)==0 instead of diag(i)==0 as above - // because 1) we have diag(i)==0 => col0(i)==0 and 2) if col0(i)==0, then diag(i) is already a singular value. - while(actual_n>1 && col0(actual_n-1)==Literal(0)) --actual_n; - - for (Index k = 0; k < n; ++k) - { - if (col0(k) == Literal(0) || actual_n==1) - { - // if col0(k) == 0, then entry is deflated, so singular value is on diagonal - // if actual_n==1, then the deflated problem is already diagonalized - singVals(k) = k==0 ? col0(0) : diag(k); - mus(k) = Literal(0); - shifts(k) = k==0 ? col0(0) : diag(k); - continue; - } - - // otherwise, use secular equation to find singular value - RealScalar left = diag(k); - RealScalar right; // was: = (k != actual_n-1) ? diag(k+1) : (diag(actual_n-1) + col0.matrix().norm()); - if(k==actual_n-1) - right = (diag(actual_n-1) + col0.matrix().norm()); - else - { - // Skip deflated singular values, - // recall that at this stage we assume that z[j]!=0 and all entries for which z[j]==0 have been put aside. - // This should be equivalent to using perm[] - Index l = k+1; - while(col0(l)==Literal(0)) { ++l; eigen_internal_assert(l<actual_n); } - right = diag(l); - } - - // first decide whether it's closer to the left end or the right end - RealScalar mid = left + (right-left) / Literal(2); - RealScalar fMid = secularEq(mid, col0, diag, perm, diag, Literal(0)); -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "right-left = " << right-left << "\n"; -// std::cout << "fMid = " << fMid << " " << secularEq(mid-left, col0, diag, perm, ArrayXr(diag-left), left) -// << " " << secularEq(mid-right, col0, diag, perm, ArrayXr(diag-right), right) << "\n"; - std::cout << " = " << secularEq(left+RealScalar(0.000001)*(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.1) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.2) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.3) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.4) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.49) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.5) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.51) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.6) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.7) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.8) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.9) *(right-left), col0, diag, perm, diag, 0) - << " " << secularEq(left+RealScalar(0.999999)*(right-left), col0, diag, perm, diag, 0) << "\n"; -#endif - RealScalar shift = (k == actual_n-1 || fMid > Literal(0)) ? left : right; - - // measure everything relative to shift - Map<ArrayXr> diagShifted(m_workspace.data()+4*n, n); - diagShifted = diag - shift; - - if(k!=actual_n-1) - { - // check that after the shift, f(mid) is still negative: - RealScalar midShifted = (right - left) / RealScalar(2); - if(shift==right) - midShifted = -midShifted; - RealScalar fMidShifted = secularEq(midShifted, col0, diag, perm, diagShifted, shift); - if(fMidShifted>0) - { - // fMid was erroneous, fix it: - shift = fMidShifted > Literal(0) ? left : right; - diagShifted = diag - shift; - } - } - - // initial guess - RealScalar muPrev, muCur; - if (shift == left) - { - muPrev = (right - left) * RealScalar(0.1); - if (k == actual_n-1) muCur = right - left; - else muCur = (right - left) * RealScalar(0.5); - } - else - { - muPrev = -(right - left) * RealScalar(0.1); - muCur = -(right - left) * RealScalar(0.5); - } - - RealScalar fPrev = secularEq(muPrev, col0, diag, perm, diagShifted, shift); - RealScalar fCur = secularEq(muCur, col0, diag, perm, diagShifted, shift); - if (abs(fPrev) < abs(fCur)) - { - swap(fPrev, fCur); - swap(muPrev, muCur); - } - - // rational interpolation: fit a function of the form a / mu + b through the two previous - // iterates and use its zero to compute the next iterate - bool useBisection = fPrev*fCur>Literal(0); - while (fCur!=Literal(0) && abs(muCur - muPrev) > Literal(8) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(abs(muCur), abs(muPrev)) && abs(fCur - fPrev)>NumTraits<RealScalar>::epsilon() && !useBisection) - { - ++m_numIters; - - // Find a and b such that the function f(mu) = a / mu + b matches the current and previous samples. - RealScalar a = (fCur - fPrev) / (Literal(1)/muCur - Literal(1)/muPrev); - RealScalar b = fCur - a / muCur; - // And find mu such that f(mu)==0: - RealScalar muZero = -a/b; - RealScalar fZero = secularEq(muZero, col0, diag, perm, diagShifted, shift); - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert((numext::isfinite)(fZero)); -#endif - - muPrev = muCur; - fPrev = fCur; - muCur = muZero; - fCur = fZero; - - if (shift == left && (muCur < Literal(0) || muCur > right - left)) useBisection = true; - if (shift == right && (muCur < -(right - left) || muCur > Literal(0))) useBisection = true; - if (abs(fCur)>abs(fPrev)) useBisection = true; - } - - // fall back on bisection method if rational interpolation did not work - if (useBisection) - { -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "useBisection for k = " << k << ", actual_n = " << actual_n << "\n"; -#endif - RealScalar leftShifted, rightShifted; - if (shift == left) - { - // to avoid overflow, we must have mu > max(real_min, |z(k)|/sqrt(real_max)), - // the factor 2 is to be more conservative - leftShifted = numext::maxi<RealScalar>( (std::numeric_limits<RealScalar>::min)(), Literal(2) * abs(col0(k)) / sqrt((std::numeric_limits<RealScalar>::max)()) ); - - // check that we did it right: - eigen_internal_assert( (numext::isfinite)( (col0(k)/leftShifted)*(col0(k)/(diag(k)+shift+leftShifted)) ) ); - // I don't understand why the case k==0 would be special there: - // if (k == 0) rightShifted = right - left; else - rightShifted = (k==actual_n-1) ? right : ((right - left) * RealScalar(0.51)); // theoretically we can take 0.5, but let's be safe - } - else - { - leftShifted = -(right - left) * RealScalar(0.51); - if(k+1<n) - rightShifted = -numext::maxi<RealScalar>( (std::numeric_limits<RealScalar>::min)(), abs(col0(k+1)) / sqrt((std::numeric_limits<RealScalar>::max)()) ); - else - rightShifted = -(std::numeric_limits<RealScalar>::min)(); - } - - RealScalar fLeft = secularEq(leftShifted, col0, diag, perm, diagShifted, shift); - eigen_internal_assert(fLeft<Literal(0)); - -#if defined EIGEN_INTERNAL_DEBUGGING || defined EIGEN_BDCSVD_SANITY_CHECKS - RealScalar fRight = secularEq(rightShifted, col0, diag, perm, diagShifted, shift); -#endif - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - if(!(numext::isfinite)(fLeft)) - std::cout << "f(" << leftShifted << ") =" << fLeft << " ; " << left << " " << shift << " " << right << "\n"; - assert((numext::isfinite)(fLeft)); - - if(!(numext::isfinite)(fRight)) - std::cout << "f(" << rightShifted << ") =" << fRight << " ; " << left << " " << shift << " " << right << "\n"; - // assert((numext::isfinite)(fRight)); -#endif - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - if(!(fLeft * fRight<0)) - { - std::cout << "f(leftShifted) using leftShifted=" << leftShifted << " ; diagShifted(1:10):" << diagShifted.head(10).transpose() << "\n ; " - << "left==shift=" << bool(left==shift) << " ; left-shift = " << (left-shift) << "\n"; - std::cout << "k=" << k << ", " << fLeft << " * " << fRight << " == " << fLeft * fRight << " ; " - << "[" << left << " .. " << right << "] -> [" << leftShifted << " " << rightShifted << "], shift=" << shift - << " , f(right)=" << secularEq(0, col0, diag, perm, diagShifted, shift) - << " == " << secularEq(right, col0, diag, perm, diag, 0) << " == " << fRight << "\n"; - } -#endif - eigen_internal_assert(fLeft * fRight < Literal(0)); - - if(fLeft<Literal(0)) - { - while (rightShifted - leftShifted > Literal(2) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(abs(leftShifted), abs(rightShifted))) - { - RealScalar midShifted = (leftShifted + rightShifted) / Literal(2); - fMid = secularEq(midShifted, col0, diag, perm, diagShifted, shift); - eigen_internal_assert((numext::isfinite)(fMid)); - - if (fLeft * fMid < Literal(0)) - { - rightShifted = midShifted; - } - else - { - leftShifted = midShifted; - fLeft = fMid; - } - } - muCur = (leftShifted + rightShifted) / Literal(2); - } - else - { - // We have a problem as shifting on the left or right give either a positive or negative value - // at the middle of [left,right]... - // Instead fo abbording or entering an infinite loop, - // let's just use the middle as the estimated zero-crossing: - muCur = (right - left) * RealScalar(0.5); - if(shift == right) - muCur = -muCur; - } - } - - singVals[k] = shift + muCur; - shifts[k] = shift; - mus[k] = muCur; - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - if(k+1<n) - std::cout << "found " << singVals[k] << " == " << shift << " + " << muCur << " from " << diag(k) << " .. " << diag(k+1) << "\n"; -#endif -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(k==0 || singVals[k]>=singVals[k-1]); - assert(singVals[k]>=diag(k)); -#endif - - // perturb singular value slightly if it equals diagonal entry to avoid division by zero later - // (deflation is supposed to avoid this from happening) - // - this does no seem to be necessary anymore - -// if (singVals[k] == left) singVals[k] *= 1 + NumTraits<RealScalar>::epsilon(); -// if (singVals[k] == right) singVals[k] *= 1 - NumTraits<RealScalar>::epsilon(); - } -} - - -// zhat is perturbation of col0 for which singular vectors can be computed stably (see Section 3.1) -template <typename MatrixType> -void BDCSVD<MatrixType>::perturbCol0 - (const ArrayRef& col0, const ArrayRef& diag, const IndicesRef &perm, const VectorType& singVals, - const ArrayRef& shifts, const ArrayRef& mus, ArrayRef zhat) -{ - using std::sqrt; - Index n = col0.size(); - Index m = perm.size(); - if(m==0) - { - zhat.setZero(); - return; - } - Index lastIdx = perm(m-1); - // The offset permits to skip deflated entries while computing zhat - for (Index k = 0; k < n; ++k) - { - if (col0(k) == Literal(0)) // deflated - zhat(k) = Literal(0); - else - { - // see equation (3.6) - RealScalar dk = diag(k); - RealScalar prod = (singVals(lastIdx) + dk) * (mus(lastIdx) + (shifts(lastIdx) - dk)); -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - if(prod<0) { - std::cout << "k = " << k << " ; z(k)=" << col0(k) << ", diag(k)=" << dk << "\n"; - std::cout << "prod = " << "(" << singVals(lastIdx) << " + " << dk << ") * (" << mus(lastIdx) << " + (" << shifts(lastIdx) << " - " << dk << "))" << "\n"; - std::cout << " = " << singVals(lastIdx) + dk << " * " << mus(lastIdx) + (shifts(lastIdx) - dk) << "\n"; - } - assert(prod>=0); -#endif - - for(Index l = 0; l<m; ++l) - { - Index i = perm(l); - if(i!=k) - { -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - if(i>=k && (l==0 || l-1>=m)) - { - std::cout << "Error in perturbCol0\n"; - std::cout << " " << k << "/" << n << " " << l << "/" << m << " " << i << "/" << n << " ; " << col0(k) << " " << diag(k) << " " << "\n"; - std::cout << " " <<diag(i) << "\n"; - Index j = (i<k /*|| l==0*/) ? i : perm(l-1); - std::cout << " " << "j=" << j << "\n"; - } -#endif - Index j = i<k ? i : perm(l-1); -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - if(!(dk!=Literal(0) || diag(i)!=Literal(0))) - { - std::cout << "k=" << k << ", i=" << i << ", l=" << l << ", perm.size()=" << perm.size() << "\n"; - } - assert(dk!=Literal(0) || diag(i)!=Literal(0)); -#endif - prod *= ((singVals(j)+dk) / ((diag(i)+dk))) * ((mus(j)+(shifts(j)-dk)) / ((diag(i)-dk))); -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(prod>=0); -#endif -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - if(i!=k && numext::abs(((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) - 1) > 0.9 ) - std::cout << " " << ((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) << " == (" << (singVals(j)+dk) << " * " << (mus(j)+(shifts(j)-dk)) - << ") / (" << (diag(i)+dk) << " * " << (diag(i)-dk) << ")\n"; -#endif - } - } -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "zhat(" << k << ") = sqrt( " << prod << ") ; " << (singVals(lastIdx) + dk) << " * " << mus(lastIdx) + shifts(lastIdx) << " - " << dk << "\n"; -#endif - RealScalar tmp = sqrt(prod); -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert((numext::isfinite)(tmp)); -#endif - zhat(k) = col0(k) > Literal(0) ? RealScalar(tmp) : RealScalar(-tmp); - } - } -} - -// compute singular vectors -template <typename MatrixType> -void BDCSVD<MatrixType>::computeSingVecs - (const ArrayRef& zhat, const ArrayRef& diag, const IndicesRef &perm, const VectorType& singVals, - const ArrayRef& shifts, const ArrayRef& mus, MatrixXr& U, MatrixXr& V) -{ - Index n = zhat.size(); - Index m = perm.size(); - - for (Index k = 0; k < n; ++k) - { - if (zhat(k) == Literal(0)) - { - U.col(k) = VectorType::Unit(n+1, k); - if (m_compV) V.col(k) = VectorType::Unit(n, k); - } - else - { - U.col(k).setZero(); - for(Index l=0;l<m;++l) - { - Index i = perm(l); - U(i,k) = zhat(i)/(((diag(i) - shifts(k)) - mus(k)) )/( (diag(i) + singVals[k])); - } - U(n,k) = Literal(0); - U.col(k).normalize(); - - if (m_compV) - { - V.col(k).setZero(); - for(Index l=1;l<m;++l) - { - Index i = perm(l); - V(i,k) = diag(i) * zhat(i) / (((diag(i) - shifts(k)) - mus(k)) )/( (diag(i) + singVals[k])); - } - V(0,k) = Literal(-1); - V.col(k).normalize(); - } - } - } - U.col(n) = VectorType::Unit(n+1, n); -} - - -// page 12_13 -// i >= 1, di almost null and zi non null. -// We use a rotation to zero out zi applied to the left of M -template <typename MatrixType> -void BDCSVD<MatrixType>::deflation43(Eigen::Index firstCol, Eigen::Index shift, Eigen::Index i, Eigen::Index size) -{ - using std::abs; - using std::sqrt; - using std::pow; - Index start = firstCol + shift; - RealScalar c = m_computed(start, start); - RealScalar s = m_computed(start+i, start); - RealScalar r = numext::hypot(c,s); - if (r == Literal(0)) - { - m_computed(start+i, start+i) = Literal(0); - return; - } - m_computed(start,start) = r; - m_computed(start+i, start) = Literal(0); - m_computed(start+i, start+i) = Literal(0); - - JacobiRotation<RealScalar> J(c/r,-s/r); - if (m_compU) m_naiveU.middleRows(firstCol, size+1).applyOnTheRight(firstCol, firstCol+i, J); - else m_naiveU.applyOnTheRight(firstCol, firstCol+i, J); -}// end deflation 43 - - -// page 13 -// i,j >= 1, i!=j and |di - dj| < epsilon * norm2(M) -// We apply two rotations to have zj = 0; -// TODO deflation44 is still broken and not properly tested -template <typename MatrixType> -void BDCSVD<MatrixType>::deflation44(Eigen::Index firstColu , Eigen::Index firstColm, Eigen::Index firstRowW, Eigen::Index firstColW, Eigen::Index i, Eigen::Index j, Eigen::Index size) -{ - using std::abs; - using std::sqrt; - using std::conj; - using std::pow; - RealScalar c = m_computed(firstColm+i, firstColm); - RealScalar s = m_computed(firstColm+j, firstColm); - RealScalar r = sqrt(numext::abs2(c) + numext::abs2(s)); -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "deflation 4.4: " << i << "," << j << " -> " << c << " " << s << " " << r << " ; " - << m_computed(firstColm + i-1, firstColm) << " " - << m_computed(firstColm + i, firstColm) << " " - << m_computed(firstColm + i+1, firstColm) << " " - << m_computed(firstColm + i+2, firstColm) << "\n"; - std::cout << m_computed(firstColm + i-1, firstColm + i-1) << " " - << m_computed(firstColm + i, firstColm+i) << " " - << m_computed(firstColm + i+1, firstColm+i+1) << " " - << m_computed(firstColm + i+2, firstColm+i+2) << "\n"; -#endif - if (r==Literal(0)) - { - m_computed(firstColm + i, firstColm + i) = m_computed(firstColm + j, firstColm + j); - return; - } - c/=r; - s/=r; - m_computed(firstColm + i, firstColm) = r; - m_computed(firstColm + j, firstColm + j) = m_computed(firstColm + i, firstColm + i); - m_computed(firstColm + j, firstColm) = Literal(0); - - JacobiRotation<RealScalar> J(c,-s); - if (m_compU) m_naiveU.middleRows(firstColu, size+1).applyOnTheRight(firstColu + i, firstColu + j, J); - else m_naiveU.applyOnTheRight(firstColu+i, firstColu+j, J); - if (m_compV) m_naiveV.middleRows(firstRowW, size).applyOnTheRight(firstColW + i, firstColW + j, J); -}// end deflation 44 - - -// acts on block from (firstCol+shift, firstCol+shift) to (lastCol+shift, lastCol+shift) [inclusive] -template <typename MatrixType> -void BDCSVD<MatrixType>::deflation(Eigen::Index firstCol, Eigen::Index lastCol, Eigen::Index k, Eigen::Index firstRowW, Eigen::Index firstColW, Eigen::Index shift) -{ - using std::sqrt; - using std::abs; - const Index length = lastCol + 1 - firstCol; - - Block<MatrixXr,Dynamic,1> col0(m_computed, firstCol+shift, firstCol+shift, length, 1); - Diagonal<MatrixXr> fulldiag(m_computed); - VectorBlock<Diagonal<MatrixXr>,Dynamic> diag(fulldiag, firstCol+shift, length); - - const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)(); - RealScalar maxDiag = diag.tail((std::max)(Index(1),length-1)).cwiseAbs().maxCoeff(); - RealScalar epsilon_strict = numext::maxi<RealScalar>(considerZero,NumTraits<RealScalar>::epsilon() * maxDiag); - RealScalar epsilon_coarse = Literal(8) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(col0.cwiseAbs().maxCoeff(), maxDiag); - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(m_naiveU.allFinite()); - assert(m_naiveV.allFinite()); - assert(m_computed.allFinite()); -#endif - -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "\ndeflate:" << diag.head(k+1).transpose() << " | " << diag.segment(k+1,length-k-1).transpose() << "\n"; -#endif - - //condition 4.1 - if (diag(0) < epsilon_coarse) - { -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "deflation 4.1, because " << diag(0) << " < " << epsilon_coarse << "\n"; -#endif - diag(0) = epsilon_coarse; - } - - //condition 4.2 - for (Index i=1;i<length;++i) - if (abs(col0(i)) < epsilon_strict) - { -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "deflation 4.2, set z(" << i << ") to zero because " << abs(col0(i)) << " < " << epsilon_strict << " (diag(" << i << ")=" << diag(i) << ")\n"; -#endif - col0(i) = Literal(0); - } - - //condition 4.3 - for (Index i=1;i<length; i++) - if (diag(i) < epsilon_coarse) - { -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "deflation 4.3, cancel z(" << i << ")=" << col0(i) << " because diag(" << i << ")=" << diag(i) << " < " << epsilon_coarse << "\n"; -#endif - deflation43(firstCol, shift, i, length); - } - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(m_naiveU.allFinite()); - assert(m_naiveV.allFinite()); - assert(m_computed.allFinite()); -#endif -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "to be sorted: " << diag.transpose() << "\n\n"; - std::cout << " : " << col0.transpose() << "\n\n"; -#endif - { - // Check for total deflation - // If we have a total deflation, then we have to consider col0(0)==diag(0) as a singular value during sorting - bool total_deflation = (col0.tail(length-1).array()<considerZero).all(); - - // Sort the diagonal entries, since diag(1:k-1) and diag(k:length) are already sorted, let's do a sorted merge. - // First, compute the respective permutation. - Index *permutation = m_workspaceI.data(); - { - permutation[0] = 0; - Index p = 1; - - // Move deflated diagonal entries at the end. - for(Index i=1; i<length; ++i) - if(abs(diag(i))<considerZero) - permutation[p++] = i; - - Index i=1, j=k+1; - for( ; p < length; ++p) - { - if (i > k) permutation[p] = j++; - else if (j >= length) permutation[p] = i++; - else if (diag(i) < diag(j)) permutation[p] = j++; - else permutation[p] = i++; - } - } - - // If we have a total deflation, then we have to insert diag(0) at the right place - if(total_deflation) - { - for(Index i=1; i<length; ++i) - { - Index pi = permutation[i]; - if(abs(diag(pi))<considerZero || diag(0)<diag(pi)) - permutation[i-1] = permutation[i]; - else - { - permutation[i-1] = 0; - break; - } - } - } - - // Current index of each col, and current column of each index - Index *realInd = m_workspaceI.data()+length; - Index *realCol = m_workspaceI.data()+2*length; - - for(int pos = 0; pos< length; pos++) - { - realCol[pos] = pos; - realInd[pos] = pos; - } - - for(Index i = total_deflation?0:1; i < length; i++) - { - const Index pi = permutation[length - (total_deflation ? i+1 : i)]; - const Index J = realCol[pi]; - - using std::swap; - // swap diagonal and first column entries: - swap(diag(i), diag(J)); - if(i!=0 && J!=0) swap(col0(i), col0(J)); - - // change columns - if (m_compU) m_naiveU.col(firstCol+i).segment(firstCol, length + 1).swap(m_naiveU.col(firstCol+J).segment(firstCol, length + 1)); - else m_naiveU.col(firstCol+i).segment(0, 2) .swap(m_naiveU.col(firstCol+J).segment(0, 2)); - if (m_compV) m_naiveV.col(firstColW + i).segment(firstRowW, length).swap(m_naiveV.col(firstColW + J).segment(firstRowW, length)); - - //update real pos - const Index realI = realInd[i]; - realCol[realI] = J; - realCol[pi] = i; - realInd[J] = realI; - realInd[i] = pi; - } - } -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "sorted: " << diag.transpose().format(bdcsvdfmt) << "\n"; - std::cout << " : " << col0.transpose() << "\n\n"; -#endif - - //condition 4.4 - { - Index i = length-1; - while(i>0 && (abs(diag(i))<considerZero || abs(col0(i))<considerZero)) --i; - for(; i>1;--i) - if( (diag(i) - diag(i-1)) < NumTraits<RealScalar>::epsilon()*maxDiag ) - { -#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE - std::cout << "deflation 4.4 with i = " << i << " because " << diag(i) << " - " << diag(i-1) << " == " << (diag(i) - diag(i-1)) << " < " << NumTraits<RealScalar>::epsilon()*/*diag(i)*/maxDiag << "\n"; -#endif - eigen_internal_assert(abs(diag(i) - diag(i-1))<epsilon_coarse && " diagonal entries are not properly sorted"); - deflation44(firstCol, firstCol + shift, firstRowW, firstColW, i-1, i, length); - } - } - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - for(Index j=2;j<length;++j) - assert(diag(j-1)<=diag(j) || abs(diag(j))<considerZero); -#endif - -#ifdef EIGEN_BDCSVD_SANITY_CHECKS - assert(m_naiveU.allFinite()); - assert(m_naiveV.allFinite()); - assert(m_computed.allFinite()); -#endif -}//end deflation - -#if !defined(EIGEN_GPUCC) -/** \svd_module - * - * \return the singular value decomposition of \c *this computed by Divide & Conquer algorithm - * - * \sa class BDCSVD - */ -template<typename Derived> -BDCSVD<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::bdcSvd(unsigned int computationOptions) const -{ - return BDCSVD<PlainObject>(*this, computationOptions); -} -#endif - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/SVD/JacobiSVD.h b/external/eigen/include/eigen3/Eigen/src/SVD/JacobiSVD.h deleted file mode 100644 index 2b689110..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SVD/JacobiSVD.h +++ /dev/null @@ -1,805 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2013-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_JACOBISVD_H -#define EIGEN_JACOBISVD_H - -namespace Eigen { - -namespace internal { -// forward declaration (needed by ICC) -// the empty body is required by MSVC -template<typename MatrixType, int QRPreconditioner, - bool IsComplex = NumTraits<typename MatrixType::Scalar>::IsComplex> -struct svd_precondition_2x2_block_to_be_real {}; - -/*** QR preconditioners (R-SVD) - *** - *** Their role is to reduce the problem of computing the SVD to the case of a square matrix. - *** This approach, known as R-SVD, is an optimization for rectangular-enough matrices, and is a requirement for - *** JacobiSVD which by itself is only able to work on square matrices. - ***/ - -enum { PreconditionIfMoreColsThanRows, PreconditionIfMoreRowsThanCols }; - -template<typename MatrixType, int QRPreconditioner, int Case> -struct qr_preconditioner_should_do_anything -{ - enum { a = MatrixType::RowsAtCompileTime != Dynamic && - MatrixType::ColsAtCompileTime != Dynamic && - MatrixType::ColsAtCompileTime <= MatrixType::RowsAtCompileTime, - b = MatrixType::RowsAtCompileTime != Dynamic && - MatrixType::ColsAtCompileTime != Dynamic && - MatrixType::RowsAtCompileTime <= MatrixType::ColsAtCompileTime, - ret = !( (QRPreconditioner == NoQRPreconditioner) || - (Case == PreconditionIfMoreColsThanRows && bool(a)) || - (Case == PreconditionIfMoreRowsThanCols && bool(b)) ) - }; -}; - -template<typename MatrixType, int QRPreconditioner, int Case, - bool DoAnything = qr_preconditioner_should_do_anything<MatrixType, QRPreconditioner, Case>::ret -> struct qr_preconditioner_impl {}; - -template<typename MatrixType, int QRPreconditioner, int Case> -class qr_preconditioner_impl<MatrixType, QRPreconditioner, Case, false> -{ -public: - void allocate(const JacobiSVD<MatrixType, QRPreconditioner>&) {} - bool run(JacobiSVD<MatrixType, QRPreconditioner>&, const MatrixType&) - { - return false; - } -}; - -/*** preconditioner using FullPivHouseholderQR ***/ - -template<typename MatrixType> -class qr_preconditioner_impl<MatrixType, FullPivHouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true> -{ -public: - typedef typename MatrixType::Scalar Scalar; - enum - { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime - }; - typedef Matrix<Scalar, 1, RowsAtCompileTime, RowMajor, 1, MaxRowsAtCompileTime> WorkspaceType; - - void allocate(const JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd) - { - if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols()) - { - m_qr.~QRType(); - ::new (&m_qr) QRType(svd.rows(), svd.cols()); - } - if (svd.m_computeFullU) m_workspace.resize(svd.rows()); - } - - bool run(JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix) - { - if(matrix.rows() > matrix.cols()) - { - m_qr.compute(matrix); - svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>(); - if(svd.m_computeFullU) m_qr.matrixQ().evalTo(svd.m_matrixU, m_workspace); - if(svd.computeV()) svd.m_matrixV = m_qr.colsPermutation(); - return true; - } - return false; - } -private: - typedef FullPivHouseholderQR<MatrixType> QRType; - QRType m_qr; - WorkspaceType m_workspace; -}; - -template<typename MatrixType> -class qr_preconditioner_impl<MatrixType, FullPivHouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true> -{ -public: - typedef typename MatrixType::Scalar Scalar; - enum - { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - TrOptions = RowsAtCompileTime==1 ? (MatrixType::Options & ~(RowMajor)) - : ColsAtCompileTime==1 ? (MatrixType::Options | RowMajor) - : MatrixType::Options - }; - typedef Matrix<Scalar, ColsAtCompileTime, RowsAtCompileTime, TrOptions, MaxColsAtCompileTime, MaxRowsAtCompileTime> - TransposeTypeWithSameStorageOrder; - - void allocate(const JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd) - { - if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols()) - { - m_qr.~QRType(); - ::new (&m_qr) QRType(svd.cols(), svd.rows()); - } - m_adjoint.resize(svd.cols(), svd.rows()); - if (svd.m_computeFullV) m_workspace.resize(svd.cols()); - } - - bool run(JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix) - { - if(matrix.cols() > matrix.rows()) - { - m_adjoint = matrix.adjoint(); - m_qr.compute(m_adjoint); - svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint(); - if(svd.m_computeFullV) m_qr.matrixQ().evalTo(svd.m_matrixV, m_workspace); - if(svd.computeU()) svd.m_matrixU = m_qr.colsPermutation(); - return true; - } - else return false; - } -private: - typedef FullPivHouseholderQR<TransposeTypeWithSameStorageOrder> QRType; - QRType m_qr; - TransposeTypeWithSameStorageOrder m_adjoint; - typename internal::plain_row_type<MatrixType>::type m_workspace; -}; - -/*** preconditioner using ColPivHouseholderQR ***/ - -template<typename MatrixType> -class qr_preconditioner_impl<MatrixType, ColPivHouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true> -{ -public: - void allocate(const JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd) - { - if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols()) - { - m_qr.~QRType(); - ::new (&m_qr) QRType(svd.rows(), svd.cols()); - } - if (svd.m_computeFullU) m_workspace.resize(svd.rows()); - else if (svd.m_computeThinU) m_workspace.resize(svd.cols()); - } - - bool run(JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix) - { - if(matrix.rows() > matrix.cols()) - { - m_qr.compute(matrix); - svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>(); - if(svd.m_computeFullU) m_qr.householderQ().evalTo(svd.m_matrixU, m_workspace); - else if(svd.m_computeThinU) - { - svd.m_matrixU.setIdentity(matrix.rows(), matrix.cols()); - m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixU, m_workspace); - } - if(svd.computeV()) svd.m_matrixV = m_qr.colsPermutation(); - return true; - } - return false; - } - -private: - typedef ColPivHouseholderQR<MatrixType> QRType; - QRType m_qr; - typename internal::plain_col_type<MatrixType>::type m_workspace; -}; - -template<typename MatrixType> -class qr_preconditioner_impl<MatrixType, ColPivHouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true> -{ -public: - typedef typename MatrixType::Scalar Scalar; - enum - { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - TrOptions = RowsAtCompileTime==1 ? (MatrixType::Options & ~(RowMajor)) - : ColsAtCompileTime==1 ? (MatrixType::Options | RowMajor) - : MatrixType::Options - }; - - typedef Matrix<Scalar, ColsAtCompileTime, RowsAtCompileTime, TrOptions, MaxColsAtCompileTime, MaxRowsAtCompileTime> - TransposeTypeWithSameStorageOrder; - - void allocate(const JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd) - { - if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols()) - { - m_qr.~QRType(); - ::new (&m_qr) QRType(svd.cols(), svd.rows()); - } - if (svd.m_computeFullV) m_workspace.resize(svd.cols()); - else if (svd.m_computeThinV) m_workspace.resize(svd.rows()); - m_adjoint.resize(svd.cols(), svd.rows()); - } - - bool run(JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix) - { - if(matrix.cols() > matrix.rows()) - { - m_adjoint = matrix.adjoint(); - m_qr.compute(m_adjoint); - - svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint(); - if(svd.m_computeFullV) m_qr.householderQ().evalTo(svd.m_matrixV, m_workspace); - else if(svd.m_computeThinV) - { - svd.m_matrixV.setIdentity(matrix.cols(), matrix.rows()); - m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixV, m_workspace); - } - if(svd.computeU()) svd.m_matrixU = m_qr.colsPermutation(); - return true; - } - else return false; - } - -private: - typedef ColPivHouseholderQR<TransposeTypeWithSameStorageOrder> QRType; - QRType m_qr; - TransposeTypeWithSameStorageOrder m_adjoint; - typename internal::plain_row_type<MatrixType>::type m_workspace; -}; - -/*** preconditioner using HouseholderQR ***/ - -template<typename MatrixType> -class qr_preconditioner_impl<MatrixType, HouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true> -{ -public: - void allocate(const JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd) - { - if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols()) - { - m_qr.~QRType(); - ::new (&m_qr) QRType(svd.rows(), svd.cols()); - } - if (svd.m_computeFullU) m_workspace.resize(svd.rows()); - else if (svd.m_computeThinU) m_workspace.resize(svd.cols()); - } - - bool run(JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd, const MatrixType& matrix) - { - if(matrix.rows() > matrix.cols()) - { - m_qr.compute(matrix); - svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>(); - if(svd.m_computeFullU) m_qr.householderQ().evalTo(svd.m_matrixU, m_workspace); - else if(svd.m_computeThinU) - { - svd.m_matrixU.setIdentity(matrix.rows(), matrix.cols()); - m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixU, m_workspace); - } - if(svd.computeV()) svd.m_matrixV.setIdentity(matrix.cols(), matrix.cols()); - return true; - } - return false; - } -private: - typedef HouseholderQR<MatrixType> QRType; - QRType m_qr; - typename internal::plain_col_type<MatrixType>::type m_workspace; -}; - -template<typename MatrixType> -class qr_preconditioner_impl<MatrixType, HouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true> -{ -public: - typedef typename MatrixType::Scalar Scalar; - enum - { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - Options = MatrixType::Options - }; - - typedef Matrix<Scalar, ColsAtCompileTime, RowsAtCompileTime, Options, MaxColsAtCompileTime, MaxRowsAtCompileTime> - TransposeTypeWithSameStorageOrder; - - void allocate(const JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd) - { - if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols()) - { - m_qr.~QRType(); - ::new (&m_qr) QRType(svd.cols(), svd.rows()); - } - if (svd.m_computeFullV) m_workspace.resize(svd.cols()); - else if (svd.m_computeThinV) m_workspace.resize(svd.rows()); - m_adjoint.resize(svd.cols(), svd.rows()); - } - - bool run(JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd, const MatrixType& matrix) - { - if(matrix.cols() > matrix.rows()) - { - m_adjoint = matrix.adjoint(); - m_qr.compute(m_adjoint); - - svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint(); - if(svd.m_computeFullV) m_qr.householderQ().evalTo(svd.m_matrixV, m_workspace); - else if(svd.m_computeThinV) - { - svd.m_matrixV.setIdentity(matrix.cols(), matrix.rows()); - m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixV, m_workspace); - } - if(svd.computeU()) svd.m_matrixU.setIdentity(matrix.rows(), matrix.rows()); - return true; - } - else return false; - } - -private: - typedef HouseholderQR<TransposeTypeWithSameStorageOrder> QRType; - QRType m_qr; - TransposeTypeWithSameStorageOrder m_adjoint; - typename internal::plain_row_type<MatrixType>::type m_workspace; -}; - -/*** 2x2 SVD implementation - *** - *** JacobiSVD consists in performing a series of 2x2 SVD subproblems - ***/ - -template<typename MatrixType, int QRPreconditioner> -struct svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner, false> -{ - typedef JacobiSVD<MatrixType, QRPreconditioner> SVD; - typedef typename MatrixType::RealScalar RealScalar; - static bool run(typename SVD::WorkMatrixType&, SVD&, Index, Index, RealScalar&) { return true; } -}; - -template<typename MatrixType, int QRPreconditioner> -struct svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner, true> -{ - typedef JacobiSVD<MatrixType, QRPreconditioner> SVD; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - static bool run(typename SVD::WorkMatrixType& work_matrix, SVD& svd, Index p, Index q, RealScalar& maxDiagEntry) - { - using std::sqrt; - using std::abs; - Scalar z; - JacobiRotation<Scalar> rot; - RealScalar n = sqrt(numext::abs2(work_matrix.coeff(p,p)) + numext::abs2(work_matrix.coeff(q,p))); - - const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)(); - const RealScalar precision = NumTraits<Scalar>::epsilon(); - - if(n==0) - { - // make sure first column is zero - work_matrix.coeffRef(p,p) = work_matrix.coeffRef(q,p) = Scalar(0); - - if(abs(numext::imag(work_matrix.coeff(p,q)))>considerAsZero) - { - // work_matrix.coeff(p,q) can be zero if work_matrix.coeff(q,p) is not zero but small enough to underflow when computing n - z = abs(work_matrix.coeff(p,q)) / work_matrix.coeff(p,q); - work_matrix.row(p) *= z; - if(svd.computeU()) svd.m_matrixU.col(p) *= conj(z); - } - if(abs(numext::imag(work_matrix.coeff(q,q)))>considerAsZero) - { - z = abs(work_matrix.coeff(q,q)) / work_matrix.coeff(q,q); - work_matrix.row(q) *= z; - if(svd.computeU()) svd.m_matrixU.col(q) *= conj(z); - } - // otherwise the second row is already zero, so we have nothing to do. - } - else - { - rot.c() = conj(work_matrix.coeff(p,p)) / n; - rot.s() = work_matrix.coeff(q,p) / n; - work_matrix.applyOnTheLeft(p,q,rot); - if(svd.computeU()) svd.m_matrixU.applyOnTheRight(p,q,rot.adjoint()); - if(abs(numext::imag(work_matrix.coeff(p,q)))>considerAsZero) - { - z = abs(work_matrix.coeff(p,q)) / work_matrix.coeff(p,q); - work_matrix.col(q) *= z; - if(svd.computeV()) svd.m_matrixV.col(q) *= z; - } - if(abs(numext::imag(work_matrix.coeff(q,q)))>considerAsZero) - { - z = abs(work_matrix.coeff(q,q)) / work_matrix.coeff(q,q); - work_matrix.row(q) *= z; - if(svd.computeU()) svd.m_matrixU.col(q) *= conj(z); - } - } - - // update largest diagonal entry - maxDiagEntry = numext::maxi<RealScalar>(maxDiagEntry,numext::maxi<RealScalar>(abs(work_matrix.coeff(p,p)), abs(work_matrix.coeff(q,q)))); - // and check whether the 2x2 block is already diagonal - RealScalar threshold = numext::maxi<RealScalar>(considerAsZero, precision * maxDiagEntry); - return abs(work_matrix.coeff(p,q))>threshold || abs(work_matrix.coeff(q,p)) > threshold; - } -}; - -template<typename _MatrixType, int QRPreconditioner> -struct traits<JacobiSVD<_MatrixType,QRPreconditioner> > - : traits<_MatrixType> -{ - typedef _MatrixType MatrixType; -}; - -} // end namespace internal - -/** \ingroup SVD_Module - * - * - * \class JacobiSVD - * - * \brief Two-sided Jacobi SVD decomposition of a rectangular matrix - * - * \tparam _MatrixType the type of the matrix of which we are computing the SVD decomposition - * \tparam QRPreconditioner this optional parameter allows to specify the type of QR decomposition that will be used internally - * for the R-SVD step for non-square matrices. See discussion of possible values below. - * - * SVD decomposition consists in decomposing any n-by-p matrix \a A as a product - * \f[ A = U S V^* \f] - * where \a U is a n-by-n unitary, \a V is a p-by-p unitary, and \a S is a n-by-p real positive matrix which is zero outside of its main diagonal; - * the diagonal entries of S are known as the \em singular \em values of \a A and the columns of \a U and \a V are known as the left - * and right \em singular \em vectors of \a A respectively. - * - * Singular values are always sorted in decreasing order. - * - * This JacobiSVD decomposition computes only the singular values by default. If you want \a U or \a V, you need to ask for them explicitly. - * - * You can ask for only \em thin \a U or \a V to be computed, meaning the following. In case of a rectangular n-by-p matrix, letting \a m be the - * smaller value among \a n and \a p, there are only \a m singular vectors; the remaining columns of \a U and \a V do not correspond to actual - * singular vectors. Asking for \em thin \a U or \a V means asking for only their \a m first columns to be formed. So \a U is then a n-by-m matrix, - * and \a V is then a p-by-m matrix. Notice that thin \a U and \a V are all you need for (least squares) solving. - * - * Here's an example demonstrating basic usage: - * \include JacobiSVD_basic.cpp - * Output: \verbinclude JacobiSVD_basic.out - * - * This JacobiSVD class is a two-sided Jacobi R-SVD decomposition, ensuring optimal reliability and accuracy. The downside is that it's slower than - * bidiagonalizing SVD algorithms for large square matrices; however its complexity is still \f$ O(n^2p) \f$ where \a n is the smaller dimension and - * \a p is the greater dimension, meaning that it is still of the same order of complexity as the faster bidiagonalizing R-SVD algorithms. - * In particular, like any R-SVD, it takes advantage of non-squareness in that its complexity is only linear in the greater dimension. - * - * If the input matrix has inf or nan coefficients, the result of the computation is undefined, but the computation is guaranteed to - * terminate in finite (and reasonable) time. - * - * The possible values for QRPreconditioner are: - * \li ColPivHouseholderQRPreconditioner is the default. In practice it's very safe. It uses column-pivoting QR. - * \li FullPivHouseholderQRPreconditioner, is the safest and slowest. It uses full-pivoting QR. - * Contrary to other QRs, it doesn't allow computing thin unitaries. - * \li HouseholderQRPreconditioner is the fastest, and less safe and accurate than the pivoting variants. It uses non-pivoting QR. - * This is very similar in safety and accuracy to the bidiagonalization process used by bidiagonalizing SVD algorithms (since bidiagonalization - * is inherently non-pivoting). However the resulting SVD is still more reliable than bidiagonalizing SVDs because the Jacobi-based iterarive - * process is more reliable than the optimized bidiagonal SVD iterations. - * \li NoQRPreconditioner allows not to use a QR preconditioner at all. This is useful if you know that you will only be computing - * JacobiSVD decompositions of square matrices. Non-square matrices require a QR preconditioner. Using this option will result in - * faster compilation and smaller executable code. It won't significantly speed up computation, since JacobiSVD is always checking - * if QR preconditioning is needed before applying it anyway. - * - * \sa MatrixBase::jacobiSvd() - */ -template<typename _MatrixType, int QRPreconditioner> class JacobiSVD - : public SVDBase<JacobiSVD<_MatrixType,QRPreconditioner> > -{ - typedef SVDBase<JacobiSVD> Base; - public: - - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime), - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime,MaxColsAtCompileTime), - MatrixOptions = MatrixType::Options - }; - - typedef typename Base::MatrixUType MatrixUType; - typedef typename Base::MatrixVType MatrixVType; - typedef typename Base::SingularValuesType SingularValuesType; - - typedef typename internal::plain_row_type<MatrixType>::type RowType; - typedef typename internal::plain_col_type<MatrixType>::type ColType; - typedef Matrix<Scalar, DiagSizeAtCompileTime, DiagSizeAtCompileTime, - MatrixOptions, MaxDiagSizeAtCompileTime, MaxDiagSizeAtCompileTime> - WorkMatrixType; - - /** \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via JacobiSVD::compute(const MatrixType&). - */ - JacobiSVD() - {} - - - /** \brief Default Constructor with memory preallocation - * - * Like the default constructor but with preallocation of the internal data - * according to the specified problem size. - * \sa JacobiSVD() - */ - JacobiSVD(Index rows, Index cols, unsigned int computationOptions = 0) - { - allocate(rows, cols, computationOptions); - } - - /** \brief Constructor performing the decomposition of given matrix. - * - * \param matrix the matrix to decompose - * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed. - * By default, none is computed. This is a bit-field, the possible bits are #ComputeFullU, #ComputeThinU, - * #ComputeFullV, #ComputeThinV. - * - * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not - * available with the (non-default) FullPivHouseholderQR preconditioner. - */ - explicit JacobiSVD(const MatrixType& matrix, unsigned int computationOptions = 0) - { - compute(matrix, computationOptions); - } - - /** \brief Method performing the decomposition of given matrix using custom options. - * - * \param matrix the matrix to decompose - * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed. - * By default, none is computed. This is a bit-field, the possible bits are #ComputeFullU, #ComputeThinU, - * #ComputeFullV, #ComputeThinV. - * - * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not - * available with the (non-default) FullPivHouseholderQR preconditioner. - */ - JacobiSVD& compute(const MatrixType& matrix, unsigned int computationOptions); - - /** \brief Method performing the decomposition of given matrix using current options. - * - * \param matrix the matrix to decompose - * - * This method uses the current \a computationOptions, as already passed to the constructor or to compute(const MatrixType&, unsigned int). - */ - JacobiSVD& compute(const MatrixType& matrix) - { - return compute(matrix, m_computationOptions); - } - - using Base::computeU; - using Base::computeV; - using Base::rows; - using Base::cols; - using Base::rank; - - private: - void allocate(Index rows, Index cols, unsigned int computationOptions); - - protected: - using Base::m_matrixU; - using Base::m_matrixV; - using Base::m_singularValues; - using Base::m_isInitialized; - using Base::m_isAllocated; - using Base::m_usePrescribedThreshold; - using Base::m_computeFullU; - using Base::m_computeThinU; - using Base::m_computeFullV; - using Base::m_computeThinV; - using Base::m_computationOptions; - using Base::m_nonzeroSingularValues; - using Base::m_rows; - using Base::m_cols; - using Base::m_diagSize; - using Base::m_prescribedThreshold; - WorkMatrixType m_workMatrix; - - template<typename __MatrixType, int _QRPreconditioner, bool _IsComplex> - friend struct internal::svd_precondition_2x2_block_to_be_real; - template<typename __MatrixType, int _QRPreconditioner, int _Case, bool _DoAnything> - friend struct internal::qr_preconditioner_impl; - - internal::qr_preconditioner_impl<MatrixType, QRPreconditioner, internal::PreconditionIfMoreColsThanRows> m_qr_precond_morecols; - internal::qr_preconditioner_impl<MatrixType, QRPreconditioner, internal::PreconditionIfMoreRowsThanCols> m_qr_precond_morerows; - MatrixType m_scaledMatrix; -}; - -template<typename MatrixType, int QRPreconditioner> -void JacobiSVD<MatrixType, QRPreconditioner>::allocate(Eigen::Index rows, Eigen::Index cols, unsigned int computationOptions) -{ - eigen_assert(rows >= 0 && cols >= 0); - - if (m_isAllocated && - rows == m_rows && - cols == m_cols && - computationOptions == m_computationOptions) - { - return; - } - - m_rows = rows; - m_cols = cols; - m_isInitialized = false; - m_isAllocated = true; - m_computationOptions = computationOptions; - m_computeFullU = (computationOptions & ComputeFullU) != 0; - m_computeThinU = (computationOptions & ComputeThinU) != 0; - m_computeFullV = (computationOptions & ComputeFullV) != 0; - m_computeThinV = (computationOptions & ComputeThinV) != 0; - eigen_assert(!(m_computeFullU && m_computeThinU) && "JacobiSVD: you can't ask for both full and thin U"); - eigen_assert(!(m_computeFullV && m_computeThinV) && "JacobiSVD: you can't ask for both full and thin V"); - eigen_assert(EIGEN_IMPLIES(m_computeThinU || m_computeThinV, MatrixType::ColsAtCompileTime==Dynamic) && - "JacobiSVD: thin U and V are only available when your matrix has a dynamic number of columns."); - if (QRPreconditioner == FullPivHouseholderQRPreconditioner) - { - eigen_assert(!(m_computeThinU || m_computeThinV) && - "JacobiSVD: can't compute thin U or thin V with the FullPivHouseholderQR preconditioner. " - "Use the ColPivHouseholderQR preconditioner instead."); - } - m_diagSize = (std::min)(m_rows, m_cols); - m_singularValues.resize(m_diagSize); - if(RowsAtCompileTime==Dynamic) - m_matrixU.resize(m_rows, m_computeFullU ? m_rows - : m_computeThinU ? m_diagSize - : 0); - if(ColsAtCompileTime==Dynamic) - m_matrixV.resize(m_cols, m_computeFullV ? m_cols - : m_computeThinV ? m_diagSize - : 0); - m_workMatrix.resize(m_diagSize, m_diagSize); - - if(m_cols>m_rows) m_qr_precond_morecols.allocate(*this); - if(m_rows>m_cols) m_qr_precond_morerows.allocate(*this); - if(m_rows!=m_cols) m_scaledMatrix.resize(rows,cols); -} - -template<typename MatrixType, int QRPreconditioner> -JacobiSVD<MatrixType, QRPreconditioner>& -JacobiSVD<MatrixType, QRPreconditioner>::compute(const MatrixType& matrix, unsigned int computationOptions) -{ - using std::abs; - allocate(matrix.rows(), matrix.cols(), computationOptions); - - // currently we stop when we reach precision 2*epsilon as the last bit of precision can require an unreasonable number of iterations, - // only worsening the precision of U and V as we accumulate more rotations - const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon(); - - // limit for denormal numbers to be considered zero in order to avoid infinite loops (see bug 286) - const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)(); - - // Scaling factor to reduce over/under-flows - RealScalar scale = matrix.cwiseAbs().maxCoeff(); - if(scale==RealScalar(0)) scale = RealScalar(1); - - /*** step 1. The R-SVD step: we use a QR decomposition to reduce to the case of a square matrix */ - - if(m_rows!=m_cols) - { - m_scaledMatrix = matrix / scale; - m_qr_precond_morecols.run(*this, m_scaledMatrix); - m_qr_precond_morerows.run(*this, m_scaledMatrix); - } - else - { - m_workMatrix = matrix.block(0,0,m_diagSize,m_diagSize) / scale; - if(m_computeFullU) m_matrixU.setIdentity(m_rows,m_rows); - if(m_computeThinU) m_matrixU.setIdentity(m_rows,m_diagSize); - if(m_computeFullV) m_matrixV.setIdentity(m_cols,m_cols); - if(m_computeThinV) m_matrixV.setIdentity(m_cols, m_diagSize); - } - - /*** step 2. The main Jacobi SVD iteration. ***/ - RealScalar maxDiagEntry = m_workMatrix.cwiseAbs().diagonal().maxCoeff(); - - bool finished = false; - while(!finished) - { - finished = true; - - // do a sweep: for all index pairs (p,q), perform SVD of the corresponding 2x2 sub-matrix - - for(Index p = 1; p < m_diagSize; ++p) - { - for(Index q = 0; q < p; ++q) - { - // if this 2x2 sub-matrix is not diagonal already... - // notice that this comparison will evaluate to false if any NaN is involved, ensuring that NaN's don't - // keep us iterating forever. Similarly, small denormal numbers are considered zero. - RealScalar threshold = numext::maxi<RealScalar>(considerAsZero, precision * maxDiagEntry); - if(abs(m_workMatrix.coeff(p,q))>threshold || abs(m_workMatrix.coeff(q,p)) > threshold) - { - finished = false; - // perform SVD decomposition of 2x2 sub-matrix corresponding to indices p,q to make it diagonal - // the complex to real operation returns true if the updated 2x2 block is not already diagonal - if(internal::svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner>::run(m_workMatrix, *this, p, q, maxDiagEntry)) - { - JacobiRotation<RealScalar> j_left, j_right; - internal::real_2x2_jacobi_svd(m_workMatrix, p, q, &j_left, &j_right); - - // accumulate resulting Jacobi rotations - m_workMatrix.applyOnTheLeft(p,q,j_left); - if(computeU()) m_matrixU.applyOnTheRight(p,q,j_left.transpose()); - - m_workMatrix.applyOnTheRight(p,q,j_right); - if(computeV()) m_matrixV.applyOnTheRight(p,q,j_right); - - // keep track of the largest diagonal coefficient - maxDiagEntry = numext::maxi<RealScalar>(maxDiagEntry,numext::maxi<RealScalar>(abs(m_workMatrix.coeff(p,p)), abs(m_workMatrix.coeff(q,q)))); - } - } - } - } - } - - /*** step 3. The work matrix is now diagonal, so ensure it's positive so its diagonal entries are the singular values ***/ - - for(Index i = 0; i < m_diagSize; ++i) - { - // For a complex matrix, some diagonal coefficients might note have been - // treated by svd_precondition_2x2_block_to_be_real, and the imaginary part - // of some diagonal entry might not be null. - if(NumTraits<Scalar>::IsComplex && abs(numext::imag(m_workMatrix.coeff(i,i)))>considerAsZero) - { - RealScalar a = abs(m_workMatrix.coeff(i,i)); - m_singularValues.coeffRef(i) = abs(a); - if(computeU()) m_matrixU.col(i) *= m_workMatrix.coeff(i,i)/a; - } - else - { - // m_workMatrix.coeff(i,i) is already real, no difficulty: - RealScalar a = numext::real(m_workMatrix.coeff(i,i)); - m_singularValues.coeffRef(i) = abs(a); - if(computeU() && (a<RealScalar(0))) m_matrixU.col(i) = -m_matrixU.col(i); - } - } - - m_singularValues *= scale; - - /*** step 4. Sort singular values in descending order and compute the number of nonzero singular values ***/ - - m_nonzeroSingularValues = m_diagSize; - for(Index i = 0; i < m_diagSize; i++) - { - Index pos; - RealScalar maxRemainingSingularValue = m_singularValues.tail(m_diagSize-i).maxCoeff(&pos); - if(maxRemainingSingularValue == RealScalar(0)) - { - m_nonzeroSingularValues = i; - break; - } - if(pos) - { - pos += i; - std::swap(m_singularValues.coeffRef(i), m_singularValues.coeffRef(pos)); - if(computeU()) m_matrixU.col(pos).swap(m_matrixU.col(i)); - if(computeV()) m_matrixV.col(pos).swap(m_matrixV.col(i)); - } - } - - m_isInitialized = true; - return *this; -} - -/** \svd_module - * - * \return the singular value decomposition of \c *this computed by two-sided - * Jacobi transformations. - * - * \sa class JacobiSVD - */ -template<typename Derived> -JacobiSVD<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::jacobiSvd(unsigned int computationOptions) const -{ - return JacobiSVD<PlainObject>(*this, computationOptions); -} - -} // end namespace Eigen - -#endif // EIGEN_JACOBISVD_H diff --git a/external/eigen/include/eigen3/Eigen/src/SVD/JacobiSVD_LAPACKE.h b/external/eigen/include/eigen3/Eigen/src/SVD/JacobiSVD_LAPACKE.h deleted file mode 100644 index ff0516f6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SVD/JacobiSVD_LAPACKE.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (c) 2011, Intel Corporation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ******************************************************************************** - * Content : Eigen bindings to LAPACKe - * Singular Value Decomposition - SVD. - ******************************************************************************** -*/ - -#ifndef EIGEN_JACOBISVD_LAPACKE_H -#define EIGEN_JACOBISVD_LAPACKE_H - -namespace Eigen { - -/** \internal Specialization for the data types supported by LAPACKe */ - -#define EIGEN_LAPACKE_SVD(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW) \ -template<> inline \ -JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>& \ -JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>::compute(const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>& matrix, unsigned int computationOptions) \ -{ \ - typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \ - /*typedef MatrixType::Scalar Scalar;*/ \ - /*typedef MatrixType::RealScalar RealScalar;*/ \ - allocate(matrix.rows(), matrix.cols(), computationOptions); \ -\ - /*const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();*/ \ - m_nonzeroSingularValues = m_diagSize; \ -\ - lapack_int lda = internal::convert_index<lapack_int>(matrix.outerStride()), ldu, ldvt; \ - lapack_int matrix_order = LAPACKE_COLROW; \ - char jobu, jobvt; \ - LAPACKE_TYPE *u, *vt, dummy; \ - jobu = (m_computeFullU) ? 'A' : (m_computeThinU) ? 'S' : 'N'; \ - jobvt = (m_computeFullV) ? 'A' : (m_computeThinV) ? 'S' : 'N'; \ - if (computeU()) { \ - ldu = internal::convert_index<lapack_int>(m_matrixU.outerStride()); \ - u = (LAPACKE_TYPE*)m_matrixU.data(); \ - } else { ldu=1; u=&dummy; }\ - MatrixType localV; \ - lapack_int vt_rows = (m_computeFullV) ? internal::convert_index<lapack_int>(m_cols) : (m_computeThinV) ? internal::convert_index<lapack_int>(m_diagSize) : 1; \ - if (computeV()) { \ - localV.resize(vt_rows, m_cols); \ - ldvt = internal::convert_index<lapack_int>(localV.outerStride()); \ - vt = (LAPACKE_TYPE*)localV.data(); \ - } else { ldvt=1; vt=&dummy; }\ - Matrix<LAPACKE_RTYPE, Dynamic, Dynamic> superb; superb.resize(m_diagSize, 1); \ - MatrixType m_temp; m_temp = matrix; \ - LAPACKE_##LAPACKE_PREFIX##gesvd( matrix_order, jobu, jobvt, internal::convert_index<lapack_int>(m_rows), internal::convert_index<lapack_int>(m_cols), (LAPACKE_TYPE*)m_temp.data(), lda, (LAPACKE_RTYPE*)m_singularValues.data(), u, ldu, vt, ldvt, superb.data()); \ - if (computeV()) m_matrixV = localV.adjoint(); \ - /* for(int i=0;i<m_diagSize;i++) if (m_singularValues.coeffRef(i) < precision) { m_nonzeroSingularValues--; m_singularValues.coeffRef(i)=RealScalar(0);}*/ \ - m_isInitialized = true; \ - return *this; \ -} - -EIGEN_LAPACKE_SVD(double, double, double, d, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_SVD(float, float, float , s, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, ColMajor, LAPACK_COL_MAJOR) -EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float, float , c, ColMajor, LAPACK_COL_MAJOR) - -EIGEN_LAPACKE_SVD(double, double, double, d, RowMajor, LAPACK_ROW_MAJOR) -EIGEN_LAPACKE_SVD(float, float, float , s, RowMajor, LAPACK_ROW_MAJOR) -EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, RowMajor, LAPACK_ROW_MAJOR) -EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float, float , c, RowMajor, LAPACK_ROW_MAJOR) - -} // end namespace Eigen - -#endif // EIGEN_JACOBISVD_LAPACKE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SVD/SVDBase.h b/external/eigen/include/eigen3/Eigen/src/SVD/SVDBase.h deleted file mode 100644 index 34d5c9dd..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SVD/SVDBase.h +++ /dev/null @@ -1,354 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// Copyright (C) 2013 Gauthier Brun <brun.gauthier@gmail.com> -// Copyright (C) 2013 Nicolas Carre <nicolas.carre@ensimag.fr> -// Copyright (C) 2013 Jean Ceccato <jean.ceccato@ensimag.fr> -// Copyright (C) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SVDBASE_H -#define EIGEN_SVDBASE_H - -namespace Eigen { - -namespace internal { -template<typename Derived> struct traits<SVDBase<Derived> > - : traits<Derived> -{ - typedef MatrixXpr XprKind; - typedef SolverStorage StorageKind; - typedef int StorageIndex; - enum { Flags = 0 }; -}; -} - -/** \ingroup SVD_Module - * - * - * \class SVDBase - * - * \brief Base class of SVD algorithms - * - * \tparam Derived the type of the actual SVD decomposition - * - * SVD decomposition consists in decomposing any n-by-p matrix \a A as a product - * \f[ A = U S V^* \f] - * where \a U is a n-by-n unitary, \a V is a p-by-p unitary, and \a S is a n-by-p real positive matrix which is zero outside of its main diagonal; - * the diagonal entries of S are known as the \em singular \em values of \a A and the columns of \a U and \a V are known as the left - * and right \em singular \em vectors of \a A respectively. - * - * Singular values are always sorted in decreasing order. - * - * - * You can ask for only \em thin \a U or \a V to be computed, meaning the following. In case of a rectangular n-by-p matrix, letting \a m be the - * smaller value among \a n and \a p, there are only \a m singular vectors; the remaining columns of \a U and \a V do not correspond to actual - * singular vectors. Asking for \em thin \a U or \a V means asking for only their \a m first columns to be formed. So \a U is then a n-by-m matrix, - * and \a V is then a p-by-m matrix. Notice that thin \a U and \a V are all you need for (least squares) solving. - * - * If the input matrix has inf or nan coefficients, the result of the computation is undefined, but the computation is guaranteed to - * terminate in finite (and reasonable) time. - * \sa class BDCSVD, class JacobiSVD - */ -template<typename Derived> class SVDBase - : public SolverBase<SVDBase<Derived> > -{ -public: - - template<typename Derived_> - friend struct internal::solve_assertion; - - typedef typename internal::traits<Derived>::MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; - typedef typename Eigen::internal::traits<SVDBase>::StorageIndex StorageIndex; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime), - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime,MaxColsAtCompileTime), - MatrixOptions = MatrixType::Options - }; - - typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime, MatrixOptions, MaxRowsAtCompileTime, MaxRowsAtCompileTime> MatrixUType; - typedef Matrix<Scalar, ColsAtCompileTime, ColsAtCompileTime, MatrixOptions, MaxColsAtCompileTime, MaxColsAtCompileTime> MatrixVType; - typedef typename internal::plain_diag_type<MatrixType, RealScalar>::type SingularValuesType; - - Derived& derived() { return *static_cast<Derived*>(this); } - const Derived& derived() const { return *static_cast<const Derived*>(this); } - - /** \returns the \a U matrix. - * - * For the SVD decomposition of a n-by-p matrix, letting \a m be the minimum of \a n and \a p, - * the U matrix is n-by-n if you asked for \link Eigen::ComputeFullU ComputeFullU \endlink, and is n-by-m if you asked for \link Eigen::ComputeThinU ComputeThinU \endlink. - * - * The \a m first columns of \a U are the left singular vectors of the matrix being decomposed. - * - * This method asserts that you asked for \a U to be computed. - */ - const MatrixUType& matrixU() const - { - eigen_assert(m_isInitialized && "SVD is not initialized."); - eigen_assert(computeU() && "This SVD decomposition didn't compute U. Did you ask for it?"); - return m_matrixU; - } - - /** \returns the \a V matrix. - * - * For the SVD decomposition of a n-by-p matrix, letting \a m be the minimum of \a n and \a p, - * the V matrix is p-by-p if you asked for \link Eigen::ComputeFullV ComputeFullV \endlink, and is p-by-m if you asked for \link Eigen::ComputeThinV ComputeThinV \endlink. - * - * The \a m first columns of \a V are the right singular vectors of the matrix being decomposed. - * - * This method asserts that you asked for \a V to be computed. - */ - const MatrixVType& matrixV() const - { - eigen_assert(m_isInitialized && "SVD is not initialized."); - eigen_assert(computeV() && "This SVD decomposition didn't compute V. Did you ask for it?"); - return m_matrixV; - } - - /** \returns the vector of singular values. - * - * For the SVD decomposition of a n-by-p matrix, letting \a m be the minimum of \a n and \a p, the - * returned vector has size \a m. Singular values are always sorted in decreasing order. - */ - const SingularValuesType& singularValues() const - { - eigen_assert(m_isInitialized && "SVD is not initialized."); - return m_singularValues; - } - - /** \returns the number of singular values that are not exactly 0 */ - Index nonzeroSingularValues() const - { - eigen_assert(m_isInitialized && "SVD is not initialized."); - return m_nonzeroSingularValues; - } - - /** \returns the rank of the matrix of which \c *this is the SVD. - * - * \note This method has to determine which singular values should be considered nonzero. - * For that, it uses the threshold value that you can control by calling - * setThreshold(const RealScalar&). - */ - inline Index rank() const - { - using std::abs; - eigen_assert(m_isInitialized && "JacobiSVD is not initialized."); - if(m_singularValues.size()==0) return 0; - RealScalar premultiplied_threshold = numext::maxi<RealScalar>(m_singularValues.coeff(0) * threshold(), (std::numeric_limits<RealScalar>::min)()); - Index i = m_nonzeroSingularValues-1; - while(i>=0 && m_singularValues.coeff(i) < premultiplied_threshold) --i; - return i+1; - } - - /** Allows to prescribe a threshold to be used by certain methods, such as rank() and solve(), - * which need to determine when singular values are to be considered nonzero. - * This is not used for the SVD decomposition itself. - * - * When it needs to get the threshold value, Eigen calls threshold(). - * The default is \c NumTraits<Scalar>::epsilon() - * - * \param threshold The new value to use as the threshold. - * - * A singular value will be considered nonzero if its value is strictly greater than - * \f$ \vert singular value \vert \leqslant threshold \times \vert max singular value \vert \f$. - * - * If you want to come back to the default behavior, call setThreshold(Default_t) - */ - Derived& setThreshold(const RealScalar& threshold) - { - m_usePrescribedThreshold = true; - m_prescribedThreshold = threshold; - return derived(); - } - - /** Allows to come back to the default behavior, letting Eigen use its default formula for - * determining the threshold. - * - * You should pass the special object Eigen::Default as parameter here. - * \code svd.setThreshold(Eigen::Default); \endcode - * - * See the documentation of setThreshold(const RealScalar&). - */ - Derived& setThreshold(Default_t) - { - m_usePrescribedThreshold = false; - return derived(); - } - - /** Returns the threshold that will be used by certain methods such as rank(). - * - * See the documentation of setThreshold(const RealScalar&). - */ - RealScalar threshold() const - { - eigen_assert(m_isInitialized || m_usePrescribedThreshold); - // this temporary is needed to workaround a MSVC issue - Index diagSize = (std::max<Index>)(1,m_diagSize); - return m_usePrescribedThreshold ? m_prescribedThreshold - : RealScalar(diagSize)*NumTraits<Scalar>::epsilon(); - } - - /** \returns true if \a U (full or thin) is asked for in this SVD decomposition */ - inline bool computeU() const { return m_computeFullU || m_computeThinU; } - /** \returns true if \a V (full or thin) is asked for in this SVD decomposition */ - inline bool computeV() const { return m_computeFullV || m_computeThinV; } - - inline Index rows() const { return m_rows; } - inline Index cols() const { return m_cols; } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** \returns a (least squares) solution of \f$ A x = b \f$ using the current SVD decomposition of A. - * - * \param b the right-hand-side of the equation to solve. - * - * \note Solving requires both U and V to be computed. Thin U and V are enough, there is no need for full U or V. - * - * \note SVD solving is implicitly least-squares. Thus, this method serves both purposes of exact solving and least-squares solving. - * In other words, the returned solution is guaranteed to minimize the Euclidean norm \f$ \Vert A x - b \Vert \f$. - */ - template<typename Rhs> - inline const Solve<Derived, Rhs> - solve(const MatrixBase<Rhs>& b) const; - #endif - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename RhsType, typename DstType> - void _solve_impl(const RhsType &rhs, DstType &dst) const; - - template<bool Conjugate, typename RhsType, typename DstType> - void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const; - #endif - -protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); - } - - template<bool Transpose_, typename Rhs> - void _check_solve_assertion(const Rhs& b) const { - EIGEN_ONLY_USED_FOR_DEBUG(b); - eigen_assert(m_isInitialized && "SVD is not initialized."); - eigen_assert(computeU() && computeV() && "SVDBase::solve(): Both unitaries U and V are required to be computed (thin unitaries suffice)."); - eigen_assert((Transpose_?cols():rows())==b.rows() && "SVDBase::solve(): invalid number of rows of the right hand side matrix b"); - } - - // return true if already allocated - bool allocate(Index rows, Index cols, unsigned int computationOptions) ; - - MatrixUType m_matrixU; - MatrixVType m_matrixV; - SingularValuesType m_singularValues; - bool m_isInitialized, m_isAllocated, m_usePrescribedThreshold; - bool m_computeFullU, m_computeThinU; - bool m_computeFullV, m_computeThinV; - unsigned int m_computationOptions; - Index m_nonzeroSingularValues, m_rows, m_cols, m_diagSize; - RealScalar m_prescribedThreshold; - - /** \brief Default Constructor. - * - * Default constructor of SVDBase - */ - SVDBase() - : m_isInitialized(false), - m_isAllocated(false), - m_usePrescribedThreshold(false), - m_computeFullU(false), - m_computeThinU(false), - m_computeFullV(false), - m_computeThinV(false), - m_computationOptions(0), - m_rows(-1), m_cols(-1), m_diagSize(0) - { - check_template_parameters(); - } - - -}; - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename Derived> -template<typename RhsType, typename DstType> -void SVDBase<Derived>::_solve_impl(const RhsType &rhs, DstType &dst) const -{ - // A = U S V^* - // So A^{-1} = V S^{-1} U^* - - Matrix<typename RhsType::Scalar, Dynamic, RhsType::ColsAtCompileTime, 0, MatrixType::MaxRowsAtCompileTime, RhsType::MaxColsAtCompileTime> tmp; - Index l_rank = rank(); - tmp.noalias() = m_matrixU.leftCols(l_rank).adjoint() * rhs; - tmp = m_singularValues.head(l_rank).asDiagonal().inverse() * tmp; - dst = m_matrixV.leftCols(l_rank) * tmp; -} - -template<typename Derived> -template<bool Conjugate, typename RhsType, typename DstType> -void SVDBase<Derived>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const -{ - // A = U S V^* - // So A^{-*} = U S^{-1} V^* - // And A^{-T} = U_conj S^{-1} V^T - Matrix<typename RhsType::Scalar, Dynamic, RhsType::ColsAtCompileTime, 0, MatrixType::MaxRowsAtCompileTime, RhsType::MaxColsAtCompileTime> tmp; - Index l_rank = rank(); - - tmp.noalias() = m_matrixV.leftCols(l_rank).transpose().template conjugateIf<Conjugate>() * rhs; - tmp = m_singularValues.head(l_rank).asDiagonal().inverse() * tmp; - dst = m_matrixU.template conjugateIf<!Conjugate>().leftCols(l_rank) * tmp; -} -#endif - -template<typename MatrixType> -bool SVDBase<MatrixType>::allocate(Index rows, Index cols, unsigned int computationOptions) -{ - eigen_assert(rows >= 0 && cols >= 0); - - if (m_isAllocated && - rows == m_rows && - cols == m_cols && - computationOptions == m_computationOptions) - { - return true; - } - - m_rows = rows; - m_cols = cols; - m_isInitialized = false; - m_isAllocated = true; - m_computationOptions = computationOptions; - m_computeFullU = (computationOptions & ComputeFullU) != 0; - m_computeThinU = (computationOptions & ComputeThinU) != 0; - m_computeFullV = (computationOptions & ComputeFullV) != 0; - m_computeThinV = (computationOptions & ComputeThinV) != 0; - eigen_assert(!(m_computeFullU && m_computeThinU) && "SVDBase: you can't ask for both full and thin U"); - eigen_assert(!(m_computeFullV && m_computeThinV) && "SVDBase: you can't ask for both full and thin V"); - eigen_assert(EIGEN_IMPLIES(m_computeThinU || m_computeThinV, MatrixType::ColsAtCompileTime==Dynamic) && - "SVDBase: thin U and V are only available when your matrix has a dynamic number of columns."); - - m_diagSize = (std::min)(m_rows, m_cols); - m_singularValues.resize(m_diagSize); - if(RowsAtCompileTime==Dynamic) - m_matrixU.resize(m_rows, m_computeFullU ? m_rows : m_computeThinU ? m_diagSize : 0); - if(ColsAtCompileTime==Dynamic) - m_matrixV.resize(m_cols, m_computeFullV ? m_cols : m_computeThinV ? m_diagSize : 0); - - return false; -} - -}// end namespace - -#endif // EIGEN_SVDBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SVD/UpperBidiagonalization.h b/external/eigen/include/eigen3/Eigen/src/SVD/UpperBidiagonalization.h deleted file mode 100644 index 997defc4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SVD/UpperBidiagonalization.h +++ /dev/null @@ -1,414 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2013-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BIDIAGONALIZATION_H -#define EIGEN_BIDIAGONALIZATION_H - -namespace Eigen { - -namespace internal { -// UpperBidiagonalization will probably be replaced by a Bidiagonalization class, don't want to make it stable API. -// At the same time, it's useful to keep for now as it's about the only thing that is testing the BandMatrix class. - -template<typename _MatrixType> class UpperBidiagonalization -{ - public: - - typedef _MatrixType MatrixType; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - ColsAtCompileTimeMinusOne = internal::decrement_size<ColsAtCompileTime>::ret - }; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 - typedef Matrix<Scalar, 1, ColsAtCompileTime> RowVectorType; - typedef Matrix<Scalar, RowsAtCompileTime, 1> ColVectorType; - typedef BandMatrix<RealScalar, ColsAtCompileTime, ColsAtCompileTime, 1, 0, RowMajor> BidiagonalType; - typedef Matrix<Scalar, ColsAtCompileTime, 1> DiagVectorType; - typedef Matrix<Scalar, ColsAtCompileTimeMinusOne, 1> SuperDiagVectorType; - typedef HouseholderSequence< - const MatrixType, - const typename internal::remove_all<typename Diagonal<const MatrixType,0>::ConjugateReturnType>::type - > HouseholderUSequenceType; - typedef HouseholderSequence< - const typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type, - Diagonal<const MatrixType,1>, - OnTheRight - > HouseholderVSequenceType; - - /** - * \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via Bidiagonalization::compute(const MatrixType&). - */ - UpperBidiagonalization() : m_householder(), m_bidiagonal(), m_isInitialized(false) {} - - explicit UpperBidiagonalization(const MatrixType& matrix) - : m_householder(matrix.rows(), matrix.cols()), - m_bidiagonal(matrix.cols(), matrix.cols()), - m_isInitialized(false) - { - compute(matrix); - } - - UpperBidiagonalization& compute(const MatrixType& matrix); - UpperBidiagonalization& computeUnblocked(const MatrixType& matrix); - - const MatrixType& householder() const { return m_householder; } - const BidiagonalType& bidiagonal() const { return m_bidiagonal; } - - const HouseholderUSequenceType householderU() const - { - eigen_assert(m_isInitialized && "UpperBidiagonalization is not initialized."); - return HouseholderUSequenceType(m_householder, m_householder.diagonal().conjugate()); - } - - const HouseholderVSequenceType householderV() // const here gives nasty errors and i'm lazy - { - eigen_assert(m_isInitialized && "UpperBidiagonalization is not initialized."); - return HouseholderVSequenceType(m_householder.conjugate(), m_householder.const_derived().template diagonal<1>()) - .setLength(m_householder.cols()-1) - .setShift(1); - } - - protected: - MatrixType m_householder; - BidiagonalType m_bidiagonal; - bool m_isInitialized; -}; - -// Standard upper bidiagonalization without fancy optimizations -// This version should be faster for small matrix size -template<typename MatrixType> -void upperbidiagonalization_inplace_unblocked(MatrixType& mat, - typename MatrixType::RealScalar *diagonal, - typename MatrixType::RealScalar *upper_diagonal, - typename MatrixType::Scalar* tempData = 0) -{ - typedef typename MatrixType::Scalar Scalar; - - Index rows = mat.rows(); - Index cols = mat.cols(); - - typedef Matrix<Scalar,Dynamic,1,ColMajor,MatrixType::MaxRowsAtCompileTime,1> TempType; - TempType tempVector; - if(tempData==0) - { - tempVector.resize(rows); - tempData = tempVector.data(); - } - - for (Index k = 0; /* breaks at k==cols-1 below */ ; ++k) - { - Index remainingRows = rows - k; - Index remainingCols = cols - k - 1; - - // construct left householder transform in-place in A - mat.col(k).tail(remainingRows) - .makeHouseholderInPlace(mat.coeffRef(k,k), diagonal[k]); - // apply householder transform to remaining part of A on the left - mat.bottomRightCorner(remainingRows, remainingCols) - .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows-1), mat.coeff(k,k), tempData); - - if(k == cols-1) break; - - // construct right householder transform in-place in mat - mat.row(k).tail(remainingCols) - .makeHouseholderInPlace(mat.coeffRef(k,k+1), upper_diagonal[k]); - // apply householder transform to remaining part of mat on the left - mat.bottomRightCorner(remainingRows-1, remainingCols) - .applyHouseholderOnTheRight(mat.row(k).tail(remainingCols-1).adjoint(), mat.coeff(k,k+1), tempData); - } -} - -/** \internal - * Helper routine for the block reduction to upper bidiagonal form. - * - * Let's partition the matrix A: - * - * | A00 A01 | - * A = | | - * | A10 A11 | - * - * This function reduces to bidiagonal form the left \c rows x \a blockSize vertical panel [A00/A10] - * and the \a blockSize x \c cols horizontal panel [A00 A01] of the matrix \a A. The bottom-right block A11 - * is updated using matrix-matrix products: - * A22 -= V * Y^T - X * U^T - * where V and U contains the left and right Householder vectors. U and V are stored in A10, and A01 - * respectively, and the update matrices X and Y are computed during the reduction. - * - */ -template<typename MatrixType> -void upperbidiagonalization_blocked_helper(MatrixType& A, - typename MatrixType::RealScalar *diagonal, - typename MatrixType::RealScalar *upper_diagonal, - Index bs, - Ref<Matrix<typename MatrixType::Scalar, Dynamic, Dynamic, - traits<MatrixType>::Flags & RowMajorBit> > X, - Ref<Matrix<typename MatrixType::Scalar, Dynamic, Dynamic, - traits<MatrixType>::Flags & RowMajorBit> > Y) -{ - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename NumTraits<RealScalar>::Literal Literal; - enum { StorageOrder = traits<MatrixType>::Flags & RowMajorBit }; - typedef InnerStride<int(StorageOrder) == int(ColMajor) ? 1 : Dynamic> ColInnerStride; - typedef InnerStride<int(StorageOrder) == int(ColMajor) ? Dynamic : 1> RowInnerStride; - typedef Ref<Matrix<Scalar, Dynamic, 1>, 0, ColInnerStride> SubColumnType; - typedef Ref<Matrix<Scalar, 1, Dynamic>, 0, RowInnerStride> SubRowType; - typedef Ref<Matrix<Scalar, Dynamic, Dynamic, StorageOrder > > SubMatType; - - Index brows = A.rows(); - Index bcols = A.cols(); - - Scalar tau_u, tau_u_prev(0), tau_v; - - for(Index k = 0; k < bs; ++k) - { - Index remainingRows = brows - k; - Index remainingCols = bcols - k - 1; - - SubMatType X_k1( X.block(k,0, remainingRows,k) ); - SubMatType V_k1( A.block(k,0, remainingRows,k) ); - - // 1 - update the k-th column of A - SubColumnType v_k = A.col(k).tail(remainingRows); - v_k -= V_k1 * Y.row(k).head(k).adjoint(); - if(k) v_k -= X_k1 * A.col(k).head(k); - - // 2 - construct left Householder transform in-place - v_k.makeHouseholderInPlace(tau_v, diagonal[k]); - - if(k+1<bcols) - { - SubMatType Y_k ( Y.block(k+1,0, remainingCols, k+1) ); - SubMatType U_k1 ( A.block(0,k+1, k,remainingCols) ); - - // this eases the application of Householder transforAions - // A(k,k) will store tau_v later - A(k,k) = Scalar(1); - - // 3 - Compute y_k^T = tau_v * ( A^T*v_k - Y_k-1*V_k-1^T*v_k - U_k-1*X_k-1^T*v_k ) - { - SubColumnType y_k( Y.col(k).tail(remainingCols) ); - - // let's use the beginning of column k of Y as a temporary vector - SubColumnType tmp( Y.col(k).head(k) ); - y_k.noalias() = A.block(k,k+1, remainingRows,remainingCols).adjoint() * v_k; // bottleneck - tmp.noalias() = V_k1.adjoint() * v_k; - y_k.noalias() -= Y_k.leftCols(k) * tmp; - tmp.noalias() = X_k1.adjoint() * v_k; - y_k.noalias() -= U_k1.adjoint() * tmp; - y_k *= numext::conj(tau_v); - } - - // 4 - update k-th row of A (it will become u_k) - SubRowType u_k( A.row(k).tail(remainingCols) ); - u_k = u_k.conjugate(); - { - u_k -= Y_k * A.row(k).head(k+1).adjoint(); - if(k) u_k -= U_k1.adjoint() * X.row(k).head(k).adjoint(); - } - - // 5 - construct right Householder transform in-place - u_k.makeHouseholderInPlace(tau_u, upper_diagonal[k]); - - // this eases the application of Householder transformations - // A(k,k+1) will store tau_u later - A(k,k+1) = Scalar(1); - - // 6 - Compute x_k = tau_u * ( A*u_k - X_k-1*U_k-1^T*u_k - V_k*Y_k^T*u_k ) - { - SubColumnType x_k ( X.col(k).tail(remainingRows-1) ); - - // let's use the beginning of column k of X as a temporary vectors - // note that tmp0 and tmp1 overlaps - SubColumnType tmp0 ( X.col(k).head(k) ), - tmp1 ( X.col(k).head(k+1) ); - - x_k.noalias() = A.block(k+1,k+1, remainingRows-1,remainingCols) * u_k.transpose(); // bottleneck - tmp0.noalias() = U_k1 * u_k.transpose(); - x_k.noalias() -= X_k1.bottomRows(remainingRows-1) * tmp0; - tmp1.noalias() = Y_k.adjoint() * u_k.transpose(); - x_k.noalias() -= A.block(k+1,0, remainingRows-1,k+1) * tmp1; - x_k *= numext::conj(tau_u); - tau_u = numext::conj(tau_u); - u_k = u_k.conjugate(); - } - - if(k>0) A.coeffRef(k-1,k) = tau_u_prev; - tau_u_prev = tau_u; - } - else - A.coeffRef(k-1,k) = tau_u_prev; - - A.coeffRef(k,k) = tau_v; - } - - if(bs<bcols) - A.coeffRef(bs-1,bs) = tau_u_prev; - - // update A22 - if(bcols>bs && brows>bs) - { - SubMatType A11( A.bottomRightCorner(brows-bs,bcols-bs) ); - SubMatType A10( A.block(bs,0, brows-bs,bs) ); - SubMatType A01( A.block(0,bs, bs,bcols-bs) ); - Scalar tmp = A01(bs-1,0); - A01(bs-1,0) = Literal(1); - A11.noalias() -= A10 * Y.topLeftCorner(bcols,bs).bottomRows(bcols-bs).adjoint(); - A11.noalias() -= X.topLeftCorner(brows,bs).bottomRows(brows-bs) * A01; - A01(bs-1,0) = tmp; - } -} - -/** \internal - * - * Implementation of a block-bidiagonal reduction. - * It is based on the following paper: - * The Design of a Parallel Dense Linear Algebra Software Library: Reduction to Hessenberg, Tridiagonal, and Bidiagonal Form. - * by Jaeyoung Choi, Jack J. Dongarra, David W. Walker. (1995) - * section 3.3 - */ -template<typename MatrixType, typename BidiagType> -void upperbidiagonalization_inplace_blocked(MatrixType& A, BidiagType& bidiagonal, - Index maxBlockSize=32, - typename MatrixType::Scalar* /*tempData*/ = 0) -{ - typedef typename MatrixType::Scalar Scalar; - typedef Block<MatrixType,Dynamic,Dynamic> BlockType; - - Index rows = A.rows(); - Index cols = A.cols(); - Index size = (std::min)(rows, cols); - - // X and Y are work space - enum { StorageOrder = traits<MatrixType>::Flags & RowMajorBit }; - Matrix<Scalar, - MatrixType::RowsAtCompileTime, - Dynamic, - StorageOrder, - MatrixType::MaxRowsAtCompileTime> X(rows,maxBlockSize); - Matrix<Scalar, - MatrixType::ColsAtCompileTime, - Dynamic, - StorageOrder, - MatrixType::MaxColsAtCompileTime> Y(cols,maxBlockSize); - Index blockSize = (std::min)(maxBlockSize,size); - - Index k = 0; - for(k = 0; k < size; k += blockSize) - { - Index bs = (std::min)(size-k,blockSize); // actual size of the block - Index brows = rows - k; // rows of the block - Index bcols = cols - k; // columns of the block - - // partition the matrix A: - // - // | A00 A01 A02 | - // | | - // A = | A10 A11 A12 | - // | | - // | A20 A21 A22 | - // - // where A11 is a bs x bs diagonal block, - // and let: - // | A11 A12 | - // B = | | - // | A21 A22 | - - BlockType B = A.block(k,k,brows,bcols); - - // This stage performs the bidiagonalization of A11, A21, A12, and updating of A22. - // Finally, the algorithm continue on the updated A22. - // - // However, if B is too small, or A22 empty, then let's use an unblocked strategy - if(k+bs==cols || bcols<48) // somewhat arbitrary threshold - { - upperbidiagonalization_inplace_unblocked(B, - &(bidiagonal.template diagonal<0>().coeffRef(k)), - &(bidiagonal.template diagonal<1>().coeffRef(k)), - X.data() - ); - break; // We're done - } - else - { - upperbidiagonalization_blocked_helper<BlockType>( B, - &(bidiagonal.template diagonal<0>().coeffRef(k)), - &(bidiagonal.template diagonal<1>().coeffRef(k)), - bs, - X.topLeftCorner(brows,bs), - Y.topLeftCorner(bcols,bs) - ); - } - } -} - -template<typename _MatrixType> -UpperBidiagonalization<_MatrixType>& UpperBidiagonalization<_MatrixType>::computeUnblocked(const _MatrixType& matrix) -{ - Index rows = matrix.rows(); - Index cols = matrix.cols(); - EIGEN_ONLY_USED_FOR_DEBUG(cols); - - eigen_assert(rows >= cols && "UpperBidiagonalization is only for Arices satisfying rows>=cols."); - - m_householder = matrix; - - ColVectorType temp(rows); - - upperbidiagonalization_inplace_unblocked(m_householder, - &(m_bidiagonal.template diagonal<0>().coeffRef(0)), - &(m_bidiagonal.template diagonal<1>().coeffRef(0)), - temp.data()); - - m_isInitialized = true; - return *this; -} - -template<typename _MatrixType> -UpperBidiagonalization<_MatrixType>& UpperBidiagonalization<_MatrixType>::compute(const _MatrixType& matrix) -{ - Index rows = matrix.rows(); - Index cols = matrix.cols(); - EIGEN_ONLY_USED_FOR_DEBUG(rows); - EIGEN_ONLY_USED_FOR_DEBUG(cols); - - eigen_assert(rows >= cols && "UpperBidiagonalization is only for Arices satisfying rows>=cols."); - - m_householder = matrix; - upperbidiagonalization_inplace_blocked(m_householder, m_bidiagonal); - - m_isInitialized = true; - return *this; -} - -#if 0 -/** \return the Householder QR decomposition of \c *this. - * - * \sa class Bidiagonalization - */ -template<typename Derived> -const UpperBidiagonalization<typename MatrixBase<Derived>::PlainObject> -MatrixBase<Derived>::bidiagonalization() const -{ - return UpperBidiagonalization<PlainObject>(eval()); -} -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_BIDIAGONALIZATION_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCholesky/SimplicialCholesky.h b/external/eigen/include/eigen3/Eigen/src/SparseCholesky/SimplicialCholesky.h deleted file mode 100644 index 06edb868..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCholesky/SimplicialCholesky.h +++ /dev/null @@ -1,697 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SIMPLICIAL_CHOLESKY_H -#define EIGEN_SIMPLICIAL_CHOLESKY_H - -namespace Eigen { - -enum SimplicialCholeskyMode { - SimplicialCholeskyLLT, - SimplicialCholeskyLDLT -}; - -namespace internal { - template<typename CholMatrixType, typename InputMatrixType> - struct simplicial_cholesky_grab_input { - typedef CholMatrixType const * ConstCholMatrixPtr; - static void run(const InputMatrixType& input, ConstCholMatrixPtr &pmat, CholMatrixType &tmp) - { - tmp = input; - pmat = &tmp; - } - }; - - template<typename MatrixType> - struct simplicial_cholesky_grab_input<MatrixType,MatrixType> { - typedef MatrixType const * ConstMatrixPtr; - static void run(const MatrixType& input, ConstMatrixPtr &pmat, MatrixType &/*tmp*/) - { - pmat = &input; - } - }; -} // end namespace internal - -/** \ingroup SparseCholesky_Module - * \brief A base class for direct sparse Cholesky factorizations - * - * This is a base class for LL^T and LDL^T Cholesky factorizations of sparse matrices that are - * selfadjoint and positive definite. These factorizations allow for solving A.X = B where - * X and B can be either dense or sparse. - * - * In order to reduce the fill-in, a symmetric permutation P is applied prior to the factorization - * such that the factorized matrix is P A P^-1. - * - * \tparam Derived the type of the derived class, that is the actual factorization type. - * - */ -template<typename Derived> -class SimplicialCholeskyBase : public SparseSolverBase<Derived> -{ - typedef SparseSolverBase<Derived> Base; - using Base::m_isInitialized; - - public: - typedef typename internal::traits<Derived>::MatrixType MatrixType; - typedef typename internal::traits<Derived>::OrderingType OrderingType; - enum { UpLo = internal::traits<Derived>::UpLo }; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar,ColMajor,StorageIndex> CholMatrixType; - typedef CholMatrixType const * ConstCholMatrixPtr; - typedef Matrix<Scalar,Dynamic,1> VectorType; - typedef Matrix<StorageIndex,Dynamic,1> VectorI; - - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - public: - - using Base::derived; - - /** Default constructor */ - SimplicialCholeskyBase() - : m_info(Success), - m_factorizationIsOk(false), - m_analysisIsOk(false), - m_shiftOffset(0), - m_shiftScale(1) - {} - - explicit SimplicialCholeskyBase(const MatrixType& matrix) - : m_info(Success), - m_factorizationIsOk(false), - m_analysisIsOk(false), - m_shiftOffset(0), - m_shiftScale(1) - { - derived().compute(matrix); - } - - ~SimplicialCholeskyBase() - { - } - - Derived& derived() { return *static_cast<Derived*>(this); } - const Derived& derived() const { return *static_cast<const Derived*>(this); } - - inline Index cols() const { return m_matrix.cols(); } - inline Index rows() const { return m_matrix.rows(); } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix.appears to be negative. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - - /** \returns the permutation P - * \sa permutationPinv() */ - const PermutationMatrix<Dynamic,Dynamic,StorageIndex>& permutationP() const - { return m_P; } - - /** \returns the inverse P^-1 of the permutation P - * \sa permutationP() */ - const PermutationMatrix<Dynamic,Dynamic,StorageIndex>& permutationPinv() const - { return m_Pinv; } - - /** Sets the shift parameters that will be used to adjust the diagonal coefficients during the numerical factorization. - * - * During the numerical factorization, the diagonal coefficients are transformed by the following linear model:\n - * \c d_ii = \a offset + \a scale * \c d_ii - * - * The default is the identity transformation with \a offset=0, and \a scale=1. - * - * \returns a reference to \c *this. - */ - Derived& setShift(const RealScalar& offset, const RealScalar& scale = 1) - { - m_shiftOffset = offset; - m_shiftScale = scale; - return derived(); - } - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal */ - template<typename Stream> - void dumpMemory(Stream& s) - { - int total = 0; - s << " L: " << ((total+=(m_matrix.cols()+1) * sizeof(int) + m_matrix.nonZeros()*(sizeof(int)+sizeof(Scalar))) >> 20) << "Mb" << "\n"; - s << " diag: " << ((total+=m_diag.size() * sizeof(Scalar)) >> 20) << "Mb" << "\n"; - s << " tree: " << ((total+=m_parent.size() * sizeof(int)) >> 20) << "Mb" << "\n"; - s << " nonzeros: " << ((total+=m_nonZerosPerCol.size() * sizeof(int)) >> 20) << "Mb" << "\n"; - s << " perm: " << ((total+=m_P.size() * sizeof(int)) >> 20) << "Mb" << "\n"; - s << " perm^-1: " << ((total+=m_Pinv.size() * sizeof(int)) >> 20) << "Mb" << "\n"; - s << " TOTAL: " << (total>> 20) << "Mb" << "\n"; - } - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &dest) const - { - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()"); - eigen_assert(m_matrix.rows()==b.rows()); - - if(m_info!=Success) - return; - - if(m_P.size()>0) - dest = m_P * b; - else - dest = b; - - if(m_matrix.nonZeros()>0) // otherwise L==I - derived().matrixL().solveInPlace(dest); - - if(m_diag.size()>0) - dest = m_diag.asDiagonal().inverse() * dest; - - if (m_matrix.nonZeros()>0) // otherwise U==I - derived().matrixU().solveInPlace(dest); - - if(m_P.size()>0) - dest = m_Pinv * dest; - } - - template<typename Rhs,typename Dest> - void _solve_impl(const SparseMatrixBase<Rhs> &b, SparseMatrixBase<Dest> &dest) const - { - internal::solve_sparse_through_dense_panels(derived(), b, dest); - } - -#endif // EIGEN_PARSED_BY_DOXYGEN - - protected: - - /** Computes the sparse Cholesky decomposition of \a matrix */ - template<bool DoLDLT> - void compute(const MatrixType& matrix) - { - eigen_assert(matrix.rows()==matrix.cols()); - Index size = matrix.cols(); - CholMatrixType tmp(size,size); - ConstCholMatrixPtr pmat; - ordering(matrix, pmat, tmp); - analyzePattern_preordered(*pmat, DoLDLT); - factorize_preordered<DoLDLT>(*pmat); - } - - template<bool DoLDLT> - void factorize(const MatrixType& a) - { - eigen_assert(a.rows()==a.cols()); - Index size = a.cols(); - CholMatrixType tmp(size,size); - ConstCholMatrixPtr pmat; - - if(m_P.size()==0 && (UpLo&Upper)==Upper) - { - // If there is no ordering, try to directly use the input matrix without any copy - internal::simplicial_cholesky_grab_input<CholMatrixType,MatrixType>::run(a, pmat, tmp); - } - else - { - tmp.template selfadjointView<Upper>() = a.template selfadjointView<UpLo>().twistedBy(m_P); - pmat = &tmp; - } - - factorize_preordered<DoLDLT>(*pmat); - } - - template<bool DoLDLT> - void factorize_preordered(const CholMatrixType& a); - - void analyzePattern(const MatrixType& a, bool doLDLT) - { - eigen_assert(a.rows()==a.cols()); - Index size = a.cols(); - CholMatrixType tmp(size,size); - ConstCholMatrixPtr pmat; - ordering(a, pmat, tmp); - analyzePattern_preordered(*pmat,doLDLT); - } - void analyzePattern_preordered(const CholMatrixType& a, bool doLDLT); - - void ordering(const MatrixType& a, ConstCholMatrixPtr &pmat, CholMatrixType& ap); - - /** keeps off-diagonal entries; drops diagonal entries */ - struct keep_diag { - inline bool operator() (const Index& row, const Index& col, const Scalar&) const - { - return row!=col; - } - }; - - mutable ComputationInfo m_info; - bool m_factorizationIsOk; - bool m_analysisIsOk; - - CholMatrixType m_matrix; - VectorType m_diag; // the diagonal coefficients (LDLT mode) - VectorI m_parent; // elimination tree - VectorI m_nonZerosPerCol; - PermutationMatrix<Dynamic,Dynamic,StorageIndex> m_P; // the permutation - PermutationMatrix<Dynamic,Dynamic,StorageIndex> m_Pinv; // the inverse permutation - - RealScalar m_shiftOffset; - RealScalar m_shiftScale; -}; - -template<typename _MatrixType, int _UpLo = Lower, typename _Ordering = AMDOrdering<typename _MatrixType::StorageIndex> > class SimplicialLLT; -template<typename _MatrixType, int _UpLo = Lower, typename _Ordering = AMDOrdering<typename _MatrixType::StorageIndex> > class SimplicialLDLT; -template<typename _MatrixType, int _UpLo = Lower, typename _Ordering = AMDOrdering<typename _MatrixType::StorageIndex> > class SimplicialCholesky; - -namespace internal { - -template<typename _MatrixType, int _UpLo, typename _Ordering> struct traits<SimplicialLLT<_MatrixType,_UpLo,_Ordering> > -{ - typedef _MatrixType MatrixType; - typedef _Ordering OrderingType; - enum { UpLo = _UpLo }; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar, ColMajor, StorageIndex> CholMatrixType; - typedef TriangularView<const CholMatrixType, Eigen::Lower> MatrixL; - typedef TriangularView<const typename CholMatrixType::AdjointReturnType, Eigen::Upper> MatrixU; - static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); } - static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); } -}; - -template<typename _MatrixType,int _UpLo, typename _Ordering> struct traits<SimplicialLDLT<_MatrixType,_UpLo,_Ordering> > -{ - typedef _MatrixType MatrixType; - typedef _Ordering OrderingType; - enum { UpLo = _UpLo }; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar, ColMajor, StorageIndex> CholMatrixType; - typedef TriangularView<const CholMatrixType, Eigen::UnitLower> MatrixL; - typedef TriangularView<const typename CholMatrixType::AdjointReturnType, Eigen::UnitUpper> MatrixU; - static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); } - static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); } -}; - -template<typename _MatrixType, int _UpLo, typename _Ordering> struct traits<SimplicialCholesky<_MatrixType,_UpLo,_Ordering> > -{ - typedef _MatrixType MatrixType; - typedef _Ordering OrderingType; - enum { UpLo = _UpLo }; -}; - -} - -/** \ingroup SparseCholesky_Module - * \class SimplicialLLT - * \brief A direct sparse LLT Cholesky factorizations - * - * This class provides a LL^T Cholesky factorizations of sparse matrices that are - * selfadjoint and positive definite. The factorization allows for solving A.X = B where - * X and B can be either dense or sparse. - * - * In order to reduce the fill-in, a symmetric permutation P is applied prior to the factorization - * such that the factorized matrix is P A P^-1. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam _UpLo the triangular part that will be used for the computations. It can be Lower - * or Upper. Default is Lower. - * \tparam _Ordering The ordering method to use, either AMDOrdering<> or NaturalOrdering<>. Default is AMDOrdering<> - * - * \implsparsesolverconcept - * - * \sa class SimplicialLDLT, class AMDOrdering, class NaturalOrdering - */ -template<typename _MatrixType, int _UpLo, typename _Ordering> - class SimplicialLLT : public SimplicialCholeskyBase<SimplicialLLT<_MatrixType,_UpLo,_Ordering> > -{ -public: - typedef _MatrixType MatrixType; - enum { UpLo = _UpLo }; - typedef SimplicialCholeskyBase<SimplicialLLT> Base; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar,ColMajor,Index> CholMatrixType; - typedef Matrix<Scalar,Dynamic,1> VectorType; - typedef internal::traits<SimplicialLLT> Traits; - typedef typename Traits::MatrixL MatrixL; - typedef typename Traits::MatrixU MatrixU; -public: - /** Default constructor */ - SimplicialLLT() : Base() {} - /** Constructs and performs the LLT factorization of \a matrix */ - explicit SimplicialLLT(const MatrixType& matrix) - : Base(matrix) {} - - /** \returns an expression of the factor L */ - inline const MatrixL matrixL() const { - eigen_assert(Base::m_factorizationIsOk && "Simplicial LLT not factorized"); - return Traits::getL(Base::m_matrix); - } - - /** \returns an expression of the factor U (= L^*) */ - inline const MatrixU matrixU() const { - eigen_assert(Base::m_factorizationIsOk && "Simplicial LLT not factorized"); - return Traits::getU(Base::m_matrix); - } - - /** Computes the sparse Cholesky decomposition of \a matrix */ - SimplicialLLT& compute(const MatrixType& matrix) - { - Base::template compute<false>(matrix); - return *this; - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize() - */ - void analyzePattern(const MatrixType& a) - { - Base::analyzePattern(a, false); - } - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must has the same sparcity than the matrix on which the symbolic decomposition has been performed. - * - * \sa analyzePattern() - */ - void factorize(const MatrixType& a) - { - Base::template factorize<false>(a); - } - - /** \returns the determinant of the underlying matrix from the current factorization */ - Scalar determinant() const - { - Scalar detL = Base::m_matrix.diagonal().prod(); - return numext::abs2(detL); - } -}; - -/** \ingroup SparseCholesky_Module - * \class SimplicialLDLT - * \brief A direct sparse LDLT Cholesky factorizations without square root. - * - * This class provides a LDL^T Cholesky factorizations without square root of sparse matrices that are - * selfadjoint and positive definite. The factorization allows for solving A.X = B where - * X and B can be either dense or sparse. - * - * In order to reduce the fill-in, a symmetric permutation P is applied prior to the factorization - * such that the factorized matrix is P A P^-1. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * \tparam _UpLo the triangular part that will be used for the computations. It can be Lower - * or Upper. Default is Lower. - * \tparam _Ordering The ordering method to use, either AMDOrdering<> or NaturalOrdering<>. Default is AMDOrdering<> - * - * \implsparsesolverconcept - * - * \sa class SimplicialLLT, class AMDOrdering, class NaturalOrdering - */ -template<typename _MatrixType, int _UpLo, typename _Ordering> - class SimplicialLDLT : public SimplicialCholeskyBase<SimplicialLDLT<_MatrixType,_UpLo,_Ordering> > -{ -public: - typedef _MatrixType MatrixType; - enum { UpLo = _UpLo }; - typedef SimplicialCholeskyBase<SimplicialLDLT> Base; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar,ColMajor,StorageIndex> CholMatrixType; - typedef Matrix<Scalar,Dynamic,1> VectorType; - typedef internal::traits<SimplicialLDLT> Traits; - typedef typename Traits::MatrixL MatrixL; - typedef typename Traits::MatrixU MatrixU; -public: - /** Default constructor */ - SimplicialLDLT() : Base() {} - - /** Constructs and performs the LLT factorization of \a matrix */ - explicit SimplicialLDLT(const MatrixType& matrix) - : Base(matrix) {} - - /** \returns a vector expression of the diagonal D */ - inline const VectorType vectorD() const { - eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized"); - return Base::m_diag; - } - /** \returns an expression of the factor L */ - inline const MatrixL matrixL() const { - eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized"); - return Traits::getL(Base::m_matrix); - } - - /** \returns an expression of the factor U (= L^*) */ - inline const MatrixU matrixU() const { - eigen_assert(Base::m_factorizationIsOk && "Simplicial LDLT not factorized"); - return Traits::getU(Base::m_matrix); - } - - /** Computes the sparse Cholesky decomposition of \a matrix */ - SimplicialLDLT& compute(const MatrixType& matrix) - { - Base::template compute<true>(matrix); - return *this; - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize() - */ - void analyzePattern(const MatrixType& a) - { - Base::analyzePattern(a, true); - } - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must has the same sparcity than the matrix on which the symbolic decomposition has been performed. - * - * \sa analyzePattern() - */ - void factorize(const MatrixType& a) - { - Base::template factorize<true>(a); - } - - /** \returns the determinant of the underlying matrix from the current factorization */ - Scalar determinant() const - { - return Base::m_diag.prod(); - } -}; - -/** \deprecated use SimplicialLDLT or class SimplicialLLT - * \ingroup SparseCholesky_Module - * \class SimplicialCholesky - * - * \sa class SimplicialLDLT, class SimplicialLLT - */ -template<typename _MatrixType, int _UpLo, typename _Ordering> - class SimplicialCholesky : public SimplicialCholeskyBase<SimplicialCholesky<_MatrixType,_UpLo,_Ordering> > -{ -public: - typedef _MatrixType MatrixType; - enum { UpLo = _UpLo }; - typedef SimplicialCholeskyBase<SimplicialCholesky> Base; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar,ColMajor,StorageIndex> CholMatrixType; - typedef Matrix<Scalar,Dynamic,1> VectorType; - typedef internal::traits<SimplicialCholesky> Traits; - typedef internal::traits<SimplicialLDLT<MatrixType,UpLo> > LDLTTraits; - typedef internal::traits<SimplicialLLT<MatrixType,UpLo> > LLTTraits; - public: - SimplicialCholesky() : Base(), m_LDLT(true) {} - - explicit SimplicialCholesky(const MatrixType& matrix) - : Base(), m_LDLT(true) - { - compute(matrix); - } - - SimplicialCholesky& setMode(SimplicialCholeskyMode mode) - { - switch(mode) - { - case SimplicialCholeskyLLT: - m_LDLT = false; - break; - case SimplicialCholeskyLDLT: - m_LDLT = true; - break; - default: - break; - } - - return *this; - } - - inline const VectorType vectorD() const { - eigen_assert(Base::m_factorizationIsOk && "Simplicial Cholesky not factorized"); - return Base::m_diag; - } - inline const CholMatrixType rawMatrix() const { - eigen_assert(Base::m_factorizationIsOk && "Simplicial Cholesky not factorized"); - return Base::m_matrix; - } - - /** Computes the sparse Cholesky decomposition of \a matrix */ - SimplicialCholesky& compute(const MatrixType& matrix) - { - if(m_LDLT) - Base::template compute<true>(matrix); - else - Base::template compute<false>(matrix); - return *this; - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize() - */ - void analyzePattern(const MatrixType& a) - { - Base::analyzePattern(a, m_LDLT); - } - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must has the same sparcity than the matrix on which the symbolic decomposition has been performed. - * - * \sa analyzePattern() - */ - void factorize(const MatrixType& a) - { - if(m_LDLT) - Base::template factorize<true>(a); - else - Base::template factorize<false>(a); - } - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &dest) const - { - eigen_assert(Base::m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()"); - eigen_assert(Base::m_matrix.rows()==b.rows()); - - if(Base::m_info!=Success) - return; - - if(Base::m_P.size()>0) - dest = Base::m_P * b; - else - dest = b; - - if(Base::m_matrix.nonZeros()>0) // otherwise L==I - { - if(m_LDLT) - LDLTTraits::getL(Base::m_matrix).solveInPlace(dest); - else - LLTTraits::getL(Base::m_matrix).solveInPlace(dest); - } - - if(Base::m_diag.size()>0) - dest = Base::m_diag.real().asDiagonal().inverse() * dest; - - if (Base::m_matrix.nonZeros()>0) // otherwise I==I - { - if(m_LDLT) - LDLTTraits::getU(Base::m_matrix).solveInPlace(dest); - else - LLTTraits::getU(Base::m_matrix).solveInPlace(dest); - } - - if(Base::m_P.size()>0) - dest = Base::m_Pinv * dest; - } - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_impl(const SparseMatrixBase<Rhs> &b, SparseMatrixBase<Dest> &dest) const - { - internal::solve_sparse_through_dense_panels(*this, b, dest); - } - - Scalar determinant() const - { - if(m_LDLT) - { - return Base::m_diag.prod(); - } - else - { - Scalar detL = Diagonal<const CholMatrixType>(Base::m_matrix).prod(); - return numext::abs2(detL); - } - } - - protected: - bool m_LDLT; -}; - -template<typename Derived> -void SimplicialCholeskyBase<Derived>::ordering(const MatrixType& a, ConstCholMatrixPtr &pmat, CholMatrixType& ap) -{ - eigen_assert(a.rows()==a.cols()); - const Index size = a.rows(); - pmat = ≈ - // Note that ordering methods compute the inverse permutation - if(!internal::is_same<OrderingType,NaturalOrdering<Index> >::value) - { - { - CholMatrixType C; - C = a.template selfadjointView<UpLo>(); - - OrderingType ordering; - ordering(C,m_Pinv); - } - - if(m_Pinv.size()>0) m_P = m_Pinv.inverse(); - else m_P.resize(0); - - ap.resize(size,size); - ap.template selfadjointView<Upper>() = a.template selfadjointView<UpLo>().twistedBy(m_P); - } - else - { - m_Pinv.resize(0); - m_P.resize(0); - if(int(UpLo)==int(Lower) || MatrixType::IsRowMajor) - { - // we have to transpose the lower part to to the upper one - ap.resize(size,size); - ap.template selfadjointView<Upper>() = a.template selfadjointView<UpLo>(); - } - else - internal::simplicial_cholesky_grab_input<CholMatrixType,MatrixType>::run(a, pmat, ap); - } -} - -} // end namespace Eigen - -#endif // EIGEN_SIMPLICIAL_CHOLESKY_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h b/external/eigen/include/eigen3/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h deleted file mode 100644 index 72e1740c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h +++ /dev/null @@ -1,174 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* -NOTE: these functions have been adapted from the LDL library: - -LDL Copyright (c) 2005 by Timothy A. Davis. All Rights Reserved. - -The author of LDL, Timothy A. Davis., has executed a license with Google LLC -to permit distribution of this code and derivative works as part of Eigen under -the Mozilla Public License v. 2.0, as stated at the top of this file. - */ - -#ifndef EIGEN_SIMPLICIAL_CHOLESKY_IMPL_H -#define EIGEN_SIMPLICIAL_CHOLESKY_IMPL_H - -namespace Eigen { - -template<typename Derived> -void SimplicialCholeskyBase<Derived>::analyzePattern_preordered(const CholMatrixType& ap, bool doLDLT) -{ - const StorageIndex size = StorageIndex(ap.rows()); - m_matrix.resize(size, size); - m_parent.resize(size); - m_nonZerosPerCol.resize(size); - - ei_declare_aligned_stack_constructed_variable(StorageIndex, tags, size, 0); - - for(StorageIndex k = 0; k < size; ++k) - { - /* L(k,:) pattern: all nodes reachable in etree from nz in A(0:k-1,k) */ - m_parent[k] = -1; /* parent of k is not yet known */ - tags[k] = k; /* mark node k as visited */ - m_nonZerosPerCol[k] = 0; /* count of nonzeros in column k of L */ - for(typename CholMatrixType::InnerIterator it(ap,k); it; ++it) - { - StorageIndex i = it.index(); - if(i < k) - { - /* follow path from i to root of etree, stop at flagged node */ - for(; tags[i] != k; i = m_parent[i]) - { - /* find parent of i if not yet determined */ - if (m_parent[i] == -1) - m_parent[i] = k; - m_nonZerosPerCol[i]++; /* L (k,i) is nonzero */ - tags[i] = k; /* mark i as visited */ - } - } - } - } - - /* construct Lp index array from m_nonZerosPerCol column counts */ - StorageIndex* Lp = m_matrix.outerIndexPtr(); - Lp[0] = 0; - for(StorageIndex k = 0; k < size; ++k) - Lp[k+1] = Lp[k] + m_nonZerosPerCol[k] + (doLDLT ? 0 : 1); - - m_matrix.resizeNonZeros(Lp[size]); - - m_isInitialized = true; - m_info = Success; - m_analysisIsOk = true; - m_factorizationIsOk = false; -} - - -template<typename Derived> -template<bool DoLDLT> -void SimplicialCholeskyBase<Derived>::factorize_preordered(const CholMatrixType& ap) -{ - using std::sqrt; - - eigen_assert(m_analysisIsOk && "You must first call analyzePattern()"); - eigen_assert(ap.rows()==ap.cols()); - eigen_assert(m_parent.size()==ap.rows()); - eigen_assert(m_nonZerosPerCol.size()==ap.rows()); - - const StorageIndex size = StorageIndex(ap.rows()); - const StorageIndex* Lp = m_matrix.outerIndexPtr(); - StorageIndex* Li = m_matrix.innerIndexPtr(); - Scalar* Lx = m_matrix.valuePtr(); - - ei_declare_aligned_stack_constructed_variable(Scalar, y, size, 0); - ei_declare_aligned_stack_constructed_variable(StorageIndex, pattern, size, 0); - ei_declare_aligned_stack_constructed_variable(StorageIndex, tags, size, 0); - - bool ok = true; - m_diag.resize(DoLDLT ? size : 0); - - for(StorageIndex k = 0; k < size; ++k) - { - // compute nonzero pattern of kth row of L, in topological order - y[k] = Scalar(0); // Y(0:k) is now all zero - StorageIndex top = size; // stack for pattern is empty - tags[k] = k; // mark node k as visited - m_nonZerosPerCol[k] = 0; // count of nonzeros in column k of L - for(typename CholMatrixType::InnerIterator it(ap,k); it; ++it) - { - StorageIndex i = it.index(); - if(i <= k) - { - y[i] += numext::conj(it.value()); /* scatter A(i,k) into Y (sum duplicates) */ - Index len; - for(len = 0; tags[i] != k; i = m_parent[i]) - { - pattern[len++] = i; /* L(k,i) is nonzero */ - tags[i] = k; /* mark i as visited */ - } - while(len > 0) - pattern[--top] = pattern[--len]; - } - } - - /* compute numerical values kth row of L (a sparse triangular solve) */ - - RealScalar d = numext::real(y[k]) * m_shiftScale + m_shiftOffset; // get D(k,k), apply the shift function, and clear Y(k) - y[k] = Scalar(0); - for(; top < size; ++top) - { - Index i = pattern[top]; /* pattern[top:n-1] is pattern of L(:,k) */ - Scalar yi = y[i]; /* get and clear Y(i) */ - y[i] = Scalar(0); - - /* the nonzero entry L(k,i) */ - Scalar l_ki; - if(DoLDLT) - l_ki = yi / numext::real(m_diag[i]); - else - yi = l_ki = yi / Lx[Lp[i]]; - - Index p2 = Lp[i] + m_nonZerosPerCol[i]; - Index p; - for(p = Lp[i] + (DoLDLT ? 0 : 1); p < p2; ++p) - y[Li[p]] -= numext::conj(Lx[p]) * yi; - d -= numext::real(l_ki * numext::conj(yi)); - Li[p] = k; /* store L(k,i) in column form of L */ - Lx[p] = l_ki; - ++m_nonZerosPerCol[i]; /* increment count of nonzeros in col i */ - } - if(DoLDLT) - { - m_diag[k] = d; - if(d == RealScalar(0)) - { - ok = false; /* failure, D(k,k) is zero */ - break; - } - } - else - { - Index p = Lp[k] + m_nonZerosPerCol[k]++; - Li[p] = k ; /* store L(k,k) = sqrt (d) in column k */ - if(d <= RealScalar(0)) { - ok = false; /* failure, matrix is not positive definite */ - break; - } - Lx[p] = sqrt(d) ; - } - } - - m_info = ok ? Success : NumericalIssue; - m_factorizationIsOk = true; -} - -} // end namespace Eigen - -#endif // EIGEN_SIMPLICIAL_CHOLESKY_IMPL_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/AmbiVector.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/AmbiVector.h deleted file mode 100644 index 2cb7747c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/AmbiVector.h +++ /dev/null @@ -1,378 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_AMBIVECTOR_H -#define EIGEN_AMBIVECTOR_H - -namespace Eigen { - -namespace internal { - -/** \internal - * Hybrid sparse/dense vector class designed for intensive read-write operations. - * - * See BasicSparseLLT and SparseProduct for usage examples. - */ -template<typename _Scalar, typename _StorageIndex> -class AmbiVector -{ - public: - typedef _Scalar Scalar; - typedef _StorageIndex StorageIndex; - typedef typename NumTraits<Scalar>::Real RealScalar; - - explicit AmbiVector(Index size) - : m_buffer(0), m_zero(0), m_size(0), m_end(0), m_allocatedSize(0), m_allocatedElements(0), m_mode(-1) - { - resize(size); - } - - void init(double estimatedDensity); - void init(int mode); - - Index nonZeros() const; - - /** Specifies a sub-vector to work on */ - void setBounds(Index start, Index end) { m_start = convert_index(start); m_end = convert_index(end); } - - void setZero(); - - void restart(); - Scalar& coeffRef(Index i); - Scalar& coeff(Index i); - - class Iterator; - - ~AmbiVector() { delete[] m_buffer; } - - void resize(Index size) - { - if (m_allocatedSize < size) - reallocate(size); - m_size = convert_index(size); - } - - StorageIndex size() const { return m_size; } - - protected: - StorageIndex convert_index(Index idx) - { - return internal::convert_index<StorageIndex>(idx); - } - - void reallocate(Index size) - { - // if the size of the matrix is not too large, let's allocate a bit more than needed such - // that we can handle dense vector even in sparse mode. - delete[] m_buffer; - if (size<1000) - { - Index allocSize = (size * sizeof(ListEl) + sizeof(Scalar) - 1)/sizeof(Scalar); - m_allocatedElements = convert_index((allocSize*sizeof(Scalar))/sizeof(ListEl)); - m_buffer = new Scalar[allocSize]; - } - else - { - m_allocatedElements = convert_index((size*sizeof(Scalar))/sizeof(ListEl)); - m_buffer = new Scalar[size]; - } - m_size = convert_index(size); - m_start = 0; - m_end = m_size; - } - - void reallocateSparse() - { - Index copyElements = m_allocatedElements; - m_allocatedElements = (std::min)(StorageIndex(m_allocatedElements*1.5),m_size); - Index allocSize = m_allocatedElements * sizeof(ListEl); - allocSize = (allocSize + sizeof(Scalar) - 1)/sizeof(Scalar); - Scalar* newBuffer = new Scalar[allocSize]; - std::memcpy(newBuffer, m_buffer, copyElements * sizeof(ListEl)); - delete[] m_buffer; - m_buffer = newBuffer; - } - - protected: - // element type of the linked list - struct ListEl - { - StorageIndex next; - StorageIndex index; - Scalar value; - }; - - // used to store data in both mode - Scalar* m_buffer; - Scalar m_zero; - StorageIndex m_size; - StorageIndex m_start; - StorageIndex m_end; - StorageIndex m_allocatedSize; - StorageIndex m_allocatedElements; - StorageIndex m_mode; - - // linked list mode - StorageIndex m_llStart; - StorageIndex m_llCurrent; - StorageIndex m_llSize; -}; - -/** \returns the number of non zeros in the current sub vector */ -template<typename _Scalar,typename _StorageIndex> -Index AmbiVector<_Scalar,_StorageIndex>::nonZeros() const -{ - if (m_mode==IsSparse) - return m_llSize; - else - return m_end - m_start; -} - -template<typename _Scalar,typename _StorageIndex> -void AmbiVector<_Scalar,_StorageIndex>::init(double estimatedDensity) -{ - if (estimatedDensity>0.1) - init(IsDense); - else - init(IsSparse); -} - -template<typename _Scalar,typename _StorageIndex> -void AmbiVector<_Scalar,_StorageIndex>::init(int mode) -{ - m_mode = mode; - // This is only necessary in sparse mode, but we set these unconditionally to avoid some maybe-uninitialized warnings - // if (m_mode==IsSparse) - { - m_llSize = 0; - m_llStart = -1; - } -} - -/** Must be called whenever we might perform a write access - * with an index smaller than the previous one. - * - * Don't worry, this function is extremely cheap. - */ -template<typename _Scalar,typename _StorageIndex> -void AmbiVector<_Scalar,_StorageIndex>::restart() -{ - m_llCurrent = m_llStart; -} - -/** Set all coefficients of current subvector to zero */ -template<typename _Scalar,typename _StorageIndex> -void AmbiVector<_Scalar,_StorageIndex>::setZero() -{ - if (m_mode==IsDense) - { - for (Index i=m_start; i<m_end; ++i) - m_buffer[i] = Scalar(0); - } - else - { - eigen_assert(m_mode==IsSparse); - m_llSize = 0; - m_llStart = -1; - } -} - -template<typename _Scalar,typename _StorageIndex> -_Scalar& AmbiVector<_Scalar,_StorageIndex>::coeffRef(Index i) -{ - if (m_mode==IsDense) - return m_buffer[i]; - else - { - ListEl* EIGEN_RESTRICT llElements = reinterpret_cast<ListEl*>(m_buffer); - // TODO factorize the following code to reduce code generation - eigen_assert(m_mode==IsSparse); - if (m_llSize==0) - { - // this is the first element - m_llStart = 0; - m_llCurrent = 0; - ++m_llSize; - llElements[0].value = Scalar(0); - llElements[0].index = convert_index(i); - llElements[0].next = -1; - return llElements[0].value; - } - else if (i<llElements[m_llStart].index) - { - // this is going to be the new first element of the list - ListEl& el = llElements[m_llSize]; - el.value = Scalar(0); - el.index = convert_index(i); - el.next = m_llStart; - m_llStart = m_llSize; - ++m_llSize; - m_llCurrent = m_llStart; - return el.value; - } - else - { - StorageIndex nextel = llElements[m_llCurrent].next; - eigen_assert(i>=llElements[m_llCurrent].index && "you must call restart() before inserting an element with lower or equal index"); - while (nextel >= 0 && llElements[nextel].index<=i) - { - m_llCurrent = nextel; - nextel = llElements[nextel].next; - } - - if (llElements[m_llCurrent].index==i) - { - // the coefficient already exists and we found it ! - return llElements[m_llCurrent].value; - } - else - { - if (m_llSize>=m_allocatedElements) - { - reallocateSparse(); - llElements = reinterpret_cast<ListEl*>(m_buffer); - } - eigen_internal_assert(m_llSize<m_allocatedElements && "internal error: overflow in sparse mode"); - // let's insert a new coefficient - ListEl& el = llElements[m_llSize]; - el.value = Scalar(0); - el.index = convert_index(i); - el.next = llElements[m_llCurrent].next; - llElements[m_llCurrent].next = m_llSize; - ++m_llSize; - return el.value; - } - } - } -} - -template<typename _Scalar,typename _StorageIndex> -_Scalar& AmbiVector<_Scalar,_StorageIndex>::coeff(Index i) -{ - if (m_mode==IsDense) - return m_buffer[i]; - else - { - ListEl* EIGEN_RESTRICT llElements = reinterpret_cast<ListEl*>(m_buffer); - eigen_assert(m_mode==IsSparse); - if ((m_llSize==0) || (i<llElements[m_llStart].index)) - { - return m_zero; - } - else - { - Index elid = m_llStart; - while (elid >= 0 && llElements[elid].index<i) - elid = llElements[elid].next; - - if (llElements[elid].index==i) - return llElements[m_llCurrent].value; - else - return m_zero; - } - } -} - -/** Iterator over the nonzero coefficients */ -template<typename _Scalar,typename _StorageIndex> -class AmbiVector<_Scalar,_StorageIndex>::Iterator -{ - public: - typedef _Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - - /** Default constructor - * \param vec the vector on which we iterate - * \param epsilon the minimal value used to prune zero coefficients. - * In practice, all coefficients having a magnitude smaller than \a epsilon - * are skipped. - */ - explicit Iterator(const AmbiVector& vec, const RealScalar& epsilon = 0) - : m_vector(vec) - { - using std::abs; - m_epsilon = epsilon; - m_isDense = m_vector.m_mode==IsDense; - if (m_isDense) - { - m_currentEl = 0; // this is to avoid a compilation warning - m_cachedValue = 0; // this is to avoid a compilation warning - m_cachedIndex = m_vector.m_start-1; - ++(*this); - } - else - { - ListEl* EIGEN_RESTRICT llElements = reinterpret_cast<ListEl*>(m_vector.m_buffer); - m_currentEl = m_vector.m_llStart; - while (m_currentEl>=0 && abs(llElements[m_currentEl].value)<=m_epsilon) - m_currentEl = llElements[m_currentEl].next; - if (m_currentEl<0) - { - m_cachedValue = 0; // this is to avoid a compilation warning - m_cachedIndex = -1; - } - else - { - m_cachedIndex = llElements[m_currentEl].index; - m_cachedValue = llElements[m_currentEl].value; - } - } - } - - StorageIndex index() const { return m_cachedIndex; } - Scalar value() const { return m_cachedValue; } - - operator bool() const { return m_cachedIndex>=0; } - - Iterator& operator++() - { - using std::abs; - if (m_isDense) - { - do { - ++m_cachedIndex; - } while (m_cachedIndex<m_vector.m_end && abs(m_vector.m_buffer[m_cachedIndex])<=m_epsilon); - if (m_cachedIndex<m_vector.m_end) - m_cachedValue = m_vector.m_buffer[m_cachedIndex]; - else - m_cachedIndex=-1; - } - else - { - ListEl* EIGEN_RESTRICT llElements = reinterpret_cast<ListEl*>(m_vector.m_buffer); - do { - m_currentEl = llElements[m_currentEl].next; - } while (m_currentEl>=0 && abs(llElements[m_currentEl].value)<=m_epsilon); - if (m_currentEl<0) - { - m_cachedIndex = -1; - } - else - { - m_cachedIndex = llElements[m_currentEl].index; - m_cachedValue = llElements[m_currentEl].value; - } - } - return *this; - } - - protected: - const AmbiVector& m_vector; // the target vector - StorageIndex m_currentEl; // the current element in sparse/linked-list mode - RealScalar m_epsilon; // epsilon used to prune zero coefficients - StorageIndex m_cachedIndex; // current coordinate - Scalar m_cachedValue; // current value - bool m_isDense; // mode of the vector -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_AMBIVECTOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/CompressedStorage.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/CompressedStorage.h deleted file mode 100644 index acd986fa..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/CompressedStorage.h +++ /dev/null @@ -1,274 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPRESSED_STORAGE_H -#define EIGEN_COMPRESSED_STORAGE_H - -namespace Eigen { - -namespace internal { - -/** \internal - * Stores a sparse set of values as a list of values and a list of indices. - * - */ -template<typename _Scalar,typename _StorageIndex> -class CompressedStorage -{ - public: - - typedef _Scalar Scalar; - typedef _StorageIndex StorageIndex; - - protected: - - typedef typename NumTraits<Scalar>::Real RealScalar; - - public: - - CompressedStorage() - : m_values(0), m_indices(0), m_size(0), m_allocatedSize(0) - {} - - explicit CompressedStorage(Index size) - : m_values(0), m_indices(0), m_size(0), m_allocatedSize(0) - { - resize(size); - } - - CompressedStorage(const CompressedStorage& other) - : m_values(0), m_indices(0), m_size(0), m_allocatedSize(0) - { - *this = other; - } - - CompressedStorage& operator=(const CompressedStorage& other) - { - resize(other.size()); - if(other.size()>0) - { - internal::smart_copy(other.m_values, other.m_values + m_size, m_values); - internal::smart_copy(other.m_indices, other.m_indices + m_size, m_indices); - } - return *this; - } - - void swap(CompressedStorage& other) - { - std::swap(m_values, other.m_values); - std::swap(m_indices, other.m_indices); - std::swap(m_size, other.m_size); - std::swap(m_allocatedSize, other.m_allocatedSize); - } - - ~CompressedStorage() - { - delete[] m_values; - delete[] m_indices; - } - - void reserve(Index size) - { - Index newAllocatedSize = m_size + size; - if (newAllocatedSize > m_allocatedSize) - reallocate(newAllocatedSize); - } - - void squeeze() - { - if (m_allocatedSize>m_size) - reallocate(m_size); - } - - void resize(Index size, double reserveSizeFactor = 0) - { - if (m_allocatedSize<size) - { - Index realloc_size = (std::min<Index>)(NumTraits<StorageIndex>::highest(), size + Index(reserveSizeFactor*double(size))); - if(realloc_size<size) - internal::throw_std_bad_alloc(); - reallocate(realloc_size); - } - m_size = size; - } - - void append(const Scalar& v, Index i) - { - Index id = m_size; - resize(m_size+1, 1); - m_values[id] = v; - m_indices[id] = internal::convert_index<StorageIndex>(i); - } - - inline Index size() const { return m_size; } - inline Index allocatedSize() const { return m_allocatedSize; } - inline void clear() { m_size = 0; } - - const Scalar* valuePtr() const { return m_values; } - Scalar* valuePtr() { return m_values; } - const StorageIndex* indexPtr() const { return m_indices; } - StorageIndex* indexPtr() { return m_indices; } - - inline Scalar& value(Index i) { eigen_internal_assert(m_values!=0); return m_values[i]; } - inline const Scalar& value(Index i) const { eigen_internal_assert(m_values!=0); return m_values[i]; } - - inline StorageIndex& index(Index i) { eigen_internal_assert(m_indices!=0); return m_indices[i]; } - inline const StorageIndex& index(Index i) const { eigen_internal_assert(m_indices!=0); return m_indices[i]; } - - /** \returns the largest \c k such that for all \c j in [0,k) index[\c j]\<\a key */ - inline Index searchLowerIndex(Index key) const - { - return searchLowerIndex(0, m_size, key); - } - - /** \returns the largest \c k in [start,end) such that for all \c j in [start,k) index[\c j]\<\a key */ - inline Index searchLowerIndex(Index start, Index end, Index key) const - { - while(end>start) - { - Index mid = (end+start)>>1; - if (m_indices[mid]<key) - start = mid+1; - else - end = mid; - } - return start; - } - - /** \returns the stored value at index \a key - * If the value does not exist, then the value \a defaultValue is returned without any insertion. */ - inline Scalar at(Index key, const Scalar& defaultValue = Scalar(0)) const - { - if (m_size==0) - return defaultValue; - else if (key==m_indices[m_size-1]) - return m_values[m_size-1]; - // ^^ optimization: let's first check if it is the last coefficient - // (very common in high level algorithms) - const Index id = searchLowerIndex(0,m_size-1,key); - return ((id<m_size) && (m_indices[id]==key)) ? m_values[id] : defaultValue; - } - - /** Like at(), but the search is performed in the range [start,end) */ - inline Scalar atInRange(Index start, Index end, Index key, const Scalar &defaultValue = Scalar(0)) const - { - if (start>=end) - return defaultValue; - else if (end>start && key==m_indices[end-1]) - return m_values[end-1]; - // ^^ optimization: let's first check if it is the last coefficient - // (very common in high level algorithms) - const Index id = searchLowerIndex(start,end-1,key); - return ((id<end) && (m_indices[id]==key)) ? m_values[id] : defaultValue; - } - - /** \returns a reference to the value at index \a key - * If the value does not exist, then the value \a defaultValue is inserted - * such that the keys are sorted. */ - inline Scalar& atWithInsertion(Index key, const Scalar& defaultValue = Scalar(0)) - { - Index id = searchLowerIndex(0,m_size,key); - if (id>=m_size || m_indices[id]!=key) - { - if (m_allocatedSize<m_size+1) - { - m_allocatedSize = 2*(m_size+1); - internal::scoped_array<Scalar> newValues(m_allocatedSize); - internal::scoped_array<StorageIndex> newIndices(m_allocatedSize); - - // copy first chunk - internal::smart_copy(m_values, m_values +id, newValues.ptr()); - internal::smart_copy(m_indices, m_indices+id, newIndices.ptr()); - - // copy the rest - if(m_size>id) - { - internal::smart_copy(m_values +id, m_values +m_size, newValues.ptr() +id+1); - internal::smart_copy(m_indices+id, m_indices+m_size, newIndices.ptr()+id+1); - } - std::swap(m_values,newValues.ptr()); - std::swap(m_indices,newIndices.ptr()); - } - else if(m_size>id) - { - internal::smart_memmove(m_values +id, m_values +m_size, m_values +id+1); - internal::smart_memmove(m_indices+id, m_indices+m_size, m_indices+id+1); - } - m_size++; - m_indices[id] = internal::convert_index<StorageIndex>(key); - m_values[id] = defaultValue; - } - return m_values[id]; - } - - void moveChunk(Index from, Index to, Index chunkSize) - { - eigen_internal_assert(to+chunkSize <= m_size); - if(to>from && from+chunkSize>to) - { - // move backward - internal::smart_memmove(m_values+from, m_values+from+chunkSize, m_values+to); - internal::smart_memmove(m_indices+from, m_indices+from+chunkSize, m_indices+to); - } - else - { - internal::smart_copy(m_values+from, m_values+from+chunkSize, m_values+to); - internal::smart_copy(m_indices+from, m_indices+from+chunkSize, m_indices+to); - } - } - - void prune(const Scalar& reference, const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision()) - { - Index k = 0; - Index n = size(); - for (Index i=0; i<n; ++i) - { - if (!internal::isMuchSmallerThan(value(i), reference, epsilon)) - { - value(k) = value(i); - index(k) = index(i); - ++k; - } - } - resize(k,0); - } - - protected: - - inline void reallocate(Index size) - { - #ifdef EIGEN_SPARSE_COMPRESSED_STORAGE_REALLOCATE_PLUGIN - EIGEN_SPARSE_COMPRESSED_STORAGE_REALLOCATE_PLUGIN - #endif - eigen_internal_assert(size!=m_allocatedSize); - internal::scoped_array<Scalar> newValues(size); - internal::scoped_array<StorageIndex> newIndices(size); - Index copySize = (std::min)(size, m_size); - if (copySize>0) { - internal::smart_copy(m_values, m_values+copySize, newValues.ptr()); - internal::smart_copy(m_indices, m_indices+copySize, newIndices.ptr()); - } - std::swap(m_values,newValues.ptr()); - std::swap(m_indices,newIndices.ptr()); - m_allocatedSize = size; - } - - protected: - Scalar* m_values; - StorageIndex* m_indices; - Index m_size; - Index m_allocatedSize; - -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPRESSED_STORAGE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h deleted file mode 100644 index 9db119b6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h +++ /dev/null @@ -1,352 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CONSERVATIVESPARSESPARSEPRODUCT_H -#define EIGEN_CONSERVATIVESPARSESPARSEPRODUCT_H - -namespace Eigen { - -namespace internal { - -template<typename Lhs, typename Rhs, typename ResultType> -static void conservative_sparse_sparse_product_impl(const Lhs& lhs, const Rhs& rhs, ResultType& res, bool sortedInsertion = false) -{ - typedef typename remove_all<Lhs>::type::Scalar LhsScalar; - typedef typename remove_all<Rhs>::type::Scalar RhsScalar; - typedef typename remove_all<ResultType>::type::Scalar ResScalar; - - // make sure to call innerSize/outerSize since we fake the storage order. - Index rows = lhs.innerSize(); - Index cols = rhs.outerSize(); - eigen_assert(lhs.outerSize() == rhs.innerSize()); - - ei_declare_aligned_stack_constructed_variable(bool, mask, rows, 0); - ei_declare_aligned_stack_constructed_variable(ResScalar, values, rows, 0); - ei_declare_aligned_stack_constructed_variable(Index, indices, rows, 0); - - std::memset(mask,0,sizeof(bool)*rows); - - evaluator<Lhs> lhsEval(lhs); - evaluator<Rhs> rhsEval(rhs); - - // estimate the number of non zero entries - // given a rhs column containing Y non zeros, we assume that the respective Y columns - // of the lhs differs in average of one non zeros, thus the number of non zeros for - // the product of a rhs column with the lhs is X+Y where X is the average number of non zero - // per column of the lhs. - // Therefore, we have nnz(lhs*rhs) = nnz(lhs) + nnz(rhs) - Index estimated_nnz_prod = lhsEval.nonZerosEstimate() + rhsEval.nonZerosEstimate(); - - res.setZero(); - res.reserve(Index(estimated_nnz_prod)); - // we compute each column of the result, one after the other - for (Index j=0; j<cols; ++j) - { - - res.startVec(j); - Index nnz = 0; - for (typename evaluator<Rhs>::InnerIterator rhsIt(rhsEval, j); rhsIt; ++rhsIt) - { - RhsScalar y = rhsIt.value(); - Index k = rhsIt.index(); - for (typename evaluator<Lhs>::InnerIterator lhsIt(lhsEval, k); lhsIt; ++lhsIt) - { - Index i = lhsIt.index(); - LhsScalar x = lhsIt.value(); - if(!mask[i]) - { - mask[i] = true; - values[i] = x * y; - indices[nnz] = i; - ++nnz; - } - else - values[i] += x * y; - } - } - if(!sortedInsertion) - { - // unordered insertion - for(Index k=0; k<nnz; ++k) - { - Index i = indices[k]; - res.insertBackByOuterInnerUnordered(j,i) = values[i]; - mask[i] = false; - } - } - else - { - // alternative ordered insertion code: - const Index t200 = rows/11; // 11 == (log2(200)*1.39) - const Index t = (rows*100)/139; - - // FIXME reserve nnz non zeros - // FIXME implement faster sorting algorithms for very small nnz - // if the result is sparse enough => use a quick sort - // otherwise => loop through the entire vector - // In order to avoid to perform an expensive log2 when the - // result is clearly very sparse we use a linear bound up to 200. - if((nnz<200 && nnz<t200) || nnz * numext::log2(int(nnz)) < t) - { - if(nnz>1) std::sort(indices,indices+nnz); - for(Index k=0; k<nnz; ++k) - { - Index i = indices[k]; - res.insertBackByOuterInner(j,i) = values[i]; - mask[i] = false; - } - } - else - { - // dense path - for(Index i=0; i<rows; ++i) - { - if(mask[i]) - { - mask[i] = false; - res.insertBackByOuterInner(j,i) = values[i]; - } - } - } - } - } - res.finalize(); -} - - -} // end namespace internal - -namespace internal { - -template<typename Lhs, typename Rhs, typename ResultType, - int LhsStorageOrder = (traits<Lhs>::Flags&RowMajorBit) ? RowMajor : ColMajor, - int RhsStorageOrder = (traits<Rhs>::Flags&RowMajorBit) ? RowMajor : ColMajor, - int ResStorageOrder = (traits<ResultType>::Flags&RowMajorBit) ? RowMajor : ColMajor> -struct conservative_sparse_sparse_product_selector; - -template<typename Lhs, typename Rhs, typename ResultType> -struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,ColMajor,ColMajor,ColMajor> -{ - typedef typename remove_all<Lhs>::type LhsCleaned; - typedef typename LhsCleaned::Scalar Scalar; - - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename ResultType::Scalar,RowMajor,typename ResultType::StorageIndex> RowMajorMatrix; - typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorMatrixAux; - typedef typename sparse_eval<ColMajorMatrixAux,ResultType::RowsAtCompileTime,ResultType::ColsAtCompileTime,ColMajorMatrixAux::Flags>::type ColMajorMatrix; - - // If the result is tall and thin (in the extreme case a column vector) - // then it is faster to sort the coefficients inplace instead of transposing twice. - // FIXME, the following heuristic is probably not very good. - if(lhs.rows()>rhs.cols()) - { - ColMajorMatrix resCol(lhs.rows(),rhs.cols()); - // perform sorted insertion - internal::conservative_sparse_sparse_product_impl<Lhs,Rhs,ColMajorMatrix>(lhs, rhs, resCol, true); - res = resCol.markAsRValue(); - } - else - { - ColMajorMatrixAux resCol(lhs.rows(),rhs.cols()); - // ressort to transpose to sort the entries - internal::conservative_sparse_sparse_product_impl<Lhs,Rhs,ColMajorMatrixAux>(lhs, rhs, resCol, false); - RowMajorMatrix resRow(resCol); - res = resRow.markAsRValue(); - } - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,RowMajor,ColMajor,ColMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename Rhs::Scalar,RowMajor,typename ResultType::StorageIndex> RowMajorRhs; - typedef SparseMatrix<typename ResultType::Scalar,RowMajor,typename ResultType::StorageIndex> RowMajorRes; - RowMajorRhs rhsRow = rhs; - RowMajorRes resRow(lhs.rows(), rhs.cols()); - internal::conservative_sparse_sparse_product_impl<RowMajorRhs,Lhs,RowMajorRes>(rhsRow, lhs, resRow); - res = resRow; - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,ColMajor,RowMajor,ColMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename Lhs::Scalar,RowMajor,typename ResultType::StorageIndex> RowMajorLhs; - typedef SparseMatrix<typename ResultType::Scalar,RowMajor,typename ResultType::StorageIndex> RowMajorRes; - RowMajorLhs lhsRow = lhs; - RowMajorRes resRow(lhs.rows(), rhs.cols()); - internal::conservative_sparse_sparse_product_impl<Rhs,RowMajorLhs,RowMajorRes>(rhs, lhsRow, resRow); - res = resRow; - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,RowMajor,RowMajor,ColMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename ResultType::Scalar,RowMajor,typename ResultType::StorageIndex> RowMajorMatrix; - RowMajorMatrix resRow(lhs.rows(), rhs.cols()); - internal::conservative_sparse_sparse_product_impl<Rhs,Lhs,RowMajorMatrix>(rhs, lhs, resRow); - res = resRow; - } -}; - - -template<typename Lhs, typename Rhs, typename ResultType> -struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,ColMajor,ColMajor,RowMajor> -{ - typedef typename traits<typename remove_all<Lhs>::type>::Scalar Scalar; - - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorMatrix; - ColMajorMatrix resCol(lhs.rows(), rhs.cols()); - internal::conservative_sparse_sparse_product_impl<Lhs,Rhs,ColMajorMatrix>(lhs, rhs, resCol); - res = resCol; - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,RowMajor,ColMajor,RowMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename Lhs::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorLhs; - typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorRes; - ColMajorLhs lhsCol = lhs; - ColMajorRes resCol(lhs.rows(), rhs.cols()); - internal::conservative_sparse_sparse_product_impl<ColMajorLhs,Rhs,ColMajorRes>(lhsCol, rhs, resCol); - res = resCol; - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,ColMajor,RowMajor,RowMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename Rhs::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorRhs; - typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorRes; - ColMajorRhs rhsCol = rhs; - ColMajorRes resCol(lhs.rows(), rhs.cols()); - internal::conservative_sparse_sparse_product_impl<Lhs,ColMajorRhs,ColMajorRes>(lhs, rhsCol, resCol); - res = resCol; - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct conservative_sparse_sparse_product_selector<Lhs,Rhs,ResultType,RowMajor,RowMajor,RowMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename ResultType::Scalar,RowMajor,typename ResultType::StorageIndex> RowMajorMatrix; - typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorMatrix; - RowMajorMatrix resRow(lhs.rows(),rhs.cols()); - internal::conservative_sparse_sparse_product_impl<Rhs,Lhs,RowMajorMatrix>(rhs, lhs, resRow); - // sort the non zeros: - ColMajorMatrix resCol(resRow); - res = resCol; - } -}; - -} // end namespace internal - - -namespace internal { - -template<typename Lhs, typename Rhs, typename ResultType> -static void sparse_sparse_to_dense_product_impl(const Lhs& lhs, const Rhs& rhs, ResultType& res) -{ - typedef typename remove_all<Lhs>::type::Scalar LhsScalar; - typedef typename remove_all<Rhs>::type::Scalar RhsScalar; - Index cols = rhs.outerSize(); - eigen_assert(lhs.outerSize() == rhs.innerSize()); - - evaluator<Lhs> lhsEval(lhs); - evaluator<Rhs> rhsEval(rhs); - - for (Index j=0; j<cols; ++j) - { - for (typename evaluator<Rhs>::InnerIterator rhsIt(rhsEval, j); rhsIt; ++rhsIt) - { - RhsScalar y = rhsIt.value(); - Index k = rhsIt.index(); - for (typename evaluator<Lhs>::InnerIterator lhsIt(lhsEval, k); lhsIt; ++lhsIt) - { - Index i = lhsIt.index(); - LhsScalar x = lhsIt.value(); - res.coeffRef(i,j) += x * y; - } - } - } -} - - -} // end namespace internal - -namespace internal { - -template<typename Lhs, typename Rhs, typename ResultType, - int LhsStorageOrder = (traits<Lhs>::Flags&RowMajorBit) ? RowMajor : ColMajor, - int RhsStorageOrder = (traits<Rhs>::Flags&RowMajorBit) ? RowMajor : ColMajor> -struct sparse_sparse_to_dense_product_selector; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_to_dense_product_selector<Lhs,Rhs,ResultType,ColMajor,ColMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - internal::sparse_sparse_to_dense_product_impl<Lhs,Rhs,ResultType>(lhs, rhs, res); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_to_dense_product_selector<Lhs,Rhs,ResultType,RowMajor,ColMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename Lhs::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorLhs; - ColMajorLhs lhsCol(lhs); - internal::sparse_sparse_to_dense_product_impl<ColMajorLhs,Rhs,ResultType>(lhsCol, rhs, res); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_to_dense_product_selector<Lhs,Rhs,ResultType,ColMajor,RowMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - typedef SparseMatrix<typename Rhs::Scalar,ColMajor,typename ResultType::StorageIndex> ColMajorRhs; - ColMajorRhs rhsCol(rhs); - internal::sparse_sparse_to_dense_product_impl<Lhs,ColMajorRhs,ResultType>(lhs, rhsCol, res); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_to_dense_product_selector<Lhs,Rhs,ResultType,RowMajor,RowMajor> -{ - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res) - { - Transpose<ResultType> trRes(res); - internal::sparse_sparse_to_dense_product_impl<Rhs,Lhs,Transpose<ResultType> >(rhs, lhs, trRes); - } -}; - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CONSERVATIVESPARSESPARSEPRODUCT_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/MappedSparseMatrix.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/MappedSparseMatrix.h deleted file mode 100644 index 67718c85..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/MappedSparseMatrix.h +++ /dev/null @@ -1,67 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MAPPED_SPARSEMATRIX_H -#define EIGEN_MAPPED_SPARSEMATRIX_H - -namespace Eigen { - -/** \deprecated Use Map<SparseMatrix<> > - * \class MappedSparseMatrix - * - * \brief Sparse matrix - * - * \param _Scalar the scalar type, i.e. the type of the coefficients - * - * See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme. - * - */ -namespace internal { -template<typename _Scalar, int _Flags, typename _StorageIndex> -struct traits<MappedSparseMatrix<_Scalar, _Flags, _StorageIndex> > : traits<SparseMatrix<_Scalar, _Flags, _StorageIndex> > -{}; -} // end namespace internal - -template<typename _Scalar, int _Flags, typename _StorageIndex> -class MappedSparseMatrix - : public Map<SparseMatrix<_Scalar, _Flags, _StorageIndex> > -{ - typedef Map<SparseMatrix<_Scalar, _Flags, _StorageIndex> > Base; - - public: - - typedef typename Base::StorageIndex StorageIndex; - typedef typename Base::Scalar Scalar; - - inline MappedSparseMatrix(Index rows, Index cols, Index nnz, StorageIndex* outerIndexPtr, StorageIndex* innerIndexPtr, Scalar* valuePtr, StorageIndex* innerNonZeroPtr = 0) - : Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZeroPtr) - {} - - /** Empty destructor */ - inline ~MappedSparseMatrix() {} -}; - -namespace internal { - -template<typename _Scalar, int _Options, typename _StorageIndex> -struct evaluator<MappedSparseMatrix<_Scalar,_Options,_StorageIndex> > - : evaluator<SparseCompressedBase<MappedSparseMatrix<_Scalar,_Options,_StorageIndex> > > -{ - typedef MappedSparseMatrix<_Scalar,_Options,_StorageIndex> XprType; - typedef evaluator<SparseCompressedBase<XprType> > Base; - - evaluator() : Base() {} - explicit evaluator(const XprType &mat) : Base(mat) {} -}; - -} - -} // end namespace Eigen - -#endif // EIGEN_MAPPED_SPARSEMATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseAssign.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseAssign.h deleted file mode 100644 index 905485c8..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseAssign.h +++ /dev/null @@ -1,270 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEASSIGN_H -#define EIGEN_SPARSEASSIGN_H - -namespace Eigen { - -template<typename Derived> -template<typename OtherDerived> -Derived& SparseMatrixBase<Derived>::operator=(const EigenBase<OtherDerived> &other) -{ - internal::call_assignment_no_alias(derived(), other.derived()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -Derived& SparseMatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other) -{ - // TODO use the evaluator mechanism - other.evalTo(derived()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -inline Derived& SparseMatrixBase<Derived>::operator=(const SparseMatrixBase<OtherDerived>& other) -{ - // by default sparse evaluation do not alias, so we can safely bypass the generic call_assignment routine - internal::Assignment<Derived,OtherDerived,internal::assign_op<Scalar,typename OtherDerived::Scalar> > - ::run(derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -template<typename Derived> -inline Derived& SparseMatrixBase<Derived>::operator=(const Derived& other) -{ - internal::call_assignment_no_alias(derived(), other.derived()); - return derived(); -} - -namespace internal { - -template<> -struct storage_kind_to_evaluator_kind<Sparse> { - typedef IteratorBased Kind; -}; - -template<> -struct storage_kind_to_shape<Sparse> { - typedef SparseShape Shape; -}; - -struct Sparse2Sparse {}; -struct Sparse2Dense {}; - -template<> struct AssignmentKind<SparseShape, SparseShape> { typedef Sparse2Sparse Kind; }; -template<> struct AssignmentKind<SparseShape, SparseTriangularShape> { typedef Sparse2Sparse Kind; }; -template<> struct AssignmentKind<DenseShape, SparseShape> { typedef Sparse2Dense Kind; }; -template<> struct AssignmentKind<DenseShape, SparseTriangularShape> { typedef Sparse2Dense Kind; }; - - -template<typename DstXprType, typename SrcXprType> -void assign_sparse_to_sparse(DstXprType &dst, const SrcXprType &src) -{ - typedef typename DstXprType::Scalar Scalar; - typedef internal::evaluator<DstXprType> DstEvaluatorType; - typedef internal::evaluator<SrcXprType> SrcEvaluatorType; - - SrcEvaluatorType srcEvaluator(src); - - const bool transpose = (DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit); - const Index outerEvaluationSize = (SrcEvaluatorType::Flags&RowMajorBit) ? src.rows() : src.cols(); - if ((!transpose) && src.isRValue()) - { - // eval without temporary - dst.resize(src.rows(), src.cols()); - dst.setZero(); - dst.reserve((std::min)(src.rows()*src.cols(), (std::max)(src.rows(),src.cols())*2)); - for (Index j=0; j<outerEvaluationSize; ++j) - { - dst.startVec(j); - for (typename SrcEvaluatorType::InnerIterator it(srcEvaluator, j); it; ++it) - { - Scalar v = it.value(); - dst.insertBackByOuterInner(j,it.index()) = v; - } - } - dst.finalize(); - } - else - { - // eval through a temporary - eigen_assert(( ((internal::traits<DstXprType>::SupportedAccessPatterns & OuterRandomAccessPattern)==OuterRandomAccessPattern) || - (!((DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit)))) && - "the transpose operation is supposed to be handled in SparseMatrix::operator="); - - enum { Flip = (DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit) }; - - - DstXprType temp(src.rows(), src.cols()); - - temp.reserve((std::min)(src.rows()*src.cols(), (std::max)(src.rows(),src.cols())*2)); - for (Index j=0; j<outerEvaluationSize; ++j) - { - temp.startVec(j); - for (typename SrcEvaluatorType::InnerIterator it(srcEvaluator, j); it; ++it) - { - Scalar v = it.value(); - temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v; - } - } - temp.finalize(); - - dst = temp.markAsRValue(); - } -} - -// Generic Sparse to Sparse assignment -template< typename DstXprType, typename SrcXprType, typename Functor> -struct Assignment<DstXprType, SrcXprType, Functor, Sparse2Sparse> -{ - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/) - { - assign_sparse_to_sparse(dst.derived(), src.derived()); - } -}; - -// Generic Sparse to Dense assignment -template< typename DstXprType, typename SrcXprType, typename Functor, typename Weak> -struct Assignment<DstXprType, SrcXprType, Functor, Sparse2Dense, Weak> -{ - static void run(DstXprType &dst, const SrcXprType &src, const Functor &func) - { - if(internal::is_same<Functor,internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> >::value) - dst.setZero(); - - internal::evaluator<SrcXprType> srcEval(src); - resize_if_allowed(dst, src, func); - internal::evaluator<DstXprType> dstEval(dst); - - const Index outerEvaluationSize = (internal::evaluator<SrcXprType>::Flags&RowMajorBit) ? src.rows() : src.cols(); - for (Index j=0; j<outerEvaluationSize; ++j) - for (typename internal::evaluator<SrcXprType>::InnerIterator i(srcEval,j); i; ++i) - func.assignCoeff(dstEval.coeffRef(i.row(),i.col()), i.value()); - } -}; - -// Specialization for dense ?= dense +/- sparse and dense ?= sparse +/- dense -template<typename DstXprType, typename Func1, typename Func2> -struct assignment_from_dense_op_sparse -{ - template<typename SrcXprType, typename InitialFunc> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void run(DstXprType &dst, const SrcXprType &src, const InitialFunc& /*func*/) - { - #ifdef EIGEN_SPARSE_ASSIGNMENT_FROM_DENSE_OP_SPARSE_PLUGIN - EIGEN_SPARSE_ASSIGNMENT_FROM_DENSE_OP_SPARSE_PLUGIN - #endif - - call_assignment_no_alias(dst, src.lhs(), Func1()); - call_assignment_no_alias(dst, src.rhs(), Func2()); - } - - // Specialization for dense1 = sparse + dense2; -> dense1 = dense2; dense1 += sparse; - template<typename Lhs, typename Rhs, typename Scalar> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename internal::enable_if<internal::is_same<typename internal::evaluator_traits<Rhs>::Shape,DenseShape>::value>::type - run(DstXprType &dst, const CwiseBinaryOp<internal::scalar_sum_op<Scalar,Scalar>, const Lhs, const Rhs> &src, - const internal::assign_op<typename DstXprType::Scalar,Scalar>& /*func*/) - { - #ifdef EIGEN_SPARSE_ASSIGNMENT_FROM_SPARSE_ADD_DENSE_PLUGIN - EIGEN_SPARSE_ASSIGNMENT_FROM_SPARSE_ADD_DENSE_PLUGIN - #endif - - // Apply the dense matrix first, then the sparse one. - call_assignment_no_alias(dst, src.rhs(), Func1()); - call_assignment_no_alias(dst, src.lhs(), Func2()); - } - - // Specialization for dense1 = sparse - dense2; -> dense1 = -dense2; dense1 += sparse; - template<typename Lhs, typename Rhs, typename Scalar> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename internal::enable_if<internal::is_same<typename internal::evaluator_traits<Rhs>::Shape,DenseShape>::value>::type - run(DstXprType &dst, const CwiseBinaryOp<internal::scalar_difference_op<Scalar,Scalar>, const Lhs, const Rhs> &src, - const internal::assign_op<typename DstXprType::Scalar,Scalar>& /*func*/) - { - #ifdef EIGEN_SPARSE_ASSIGNMENT_FROM_SPARSE_SUB_DENSE_PLUGIN - EIGEN_SPARSE_ASSIGNMENT_FROM_SPARSE_SUB_DENSE_PLUGIN - #endif - - // Apply the dense matrix first, then the sparse one. - call_assignment_no_alias(dst, -src.rhs(), Func1()); - call_assignment_no_alias(dst, src.lhs(), add_assign_op<typename DstXprType::Scalar,typename Lhs::Scalar>()); - } -}; - -#define EIGEN_CATCH_ASSIGN_DENSE_OP_SPARSE(ASSIGN_OP,BINOP,ASSIGN_OP2) \ - template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> \ - struct Assignment<DstXprType, CwiseBinaryOp<internal::BINOP<Scalar,Scalar>, const Lhs, const Rhs>, internal::ASSIGN_OP<typename DstXprType::Scalar,Scalar>, \ - Sparse2Dense, \ - typename internal::enable_if< internal::is_same<typename internal::evaluator_traits<Lhs>::Shape,DenseShape>::value \ - || internal::is_same<typename internal::evaluator_traits<Rhs>::Shape,DenseShape>::value>::type> \ - : assignment_from_dense_op_sparse<DstXprType, internal::ASSIGN_OP<typename DstXprType::Scalar,typename Lhs::Scalar>, internal::ASSIGN_OP2<typename DstXprType::Scalar,typename Rhs::Scalar> > \ - {} - -EIGEN_CATCH_ASSIGN_DENSE_OP_SPARSE(assign_op, scalar_sum_op,add_assign_op); -EIGEN_CATCH_ASSIGN_DENSE_OP_SPARSE(add_assign_op,scalar_sum_op,add_assign_op); -EIGEN_CATCH_ASSIGN_DENSE_OP_SPARSE(sub_assign_op,scalar_sum_op,sub_assign_op); - -EIGEN_CATCH_ASSIGN_DENSE_OP_SPARSE(assign_op, scalar_difference_op,sub_assign_op); -EIGEN_CATCH_ASSIGN_DENSE_OP_SPARSE(add_assign_op,scalar_difference_op,sub_assign_op); -EIGEN_CATCH_ASSIGN_DENSE_OP_SPARSE(sub_assign_op,scalar_difference_op,add_assign_op); - - -// Specialization for "dst = dec.solve(rhs)" -// NOTE we need to specialize it for Sparse2Sparse to avoid ambiguous specialization error -template<typename DstXprType, typename DecType, typename RhsType, typename Scalar> -struct Assignment<DstXprType, Solve<DecType,RhsType>, internal::assign_op<Scalar,Scalar>, Sparse2Sparse> -{ - typedef Solve<DecType,RhsType> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - src.dec()._solve_impl(src.rhs(), dst); - } -}; - -struct Diagonal2Sparse {}; - -template<> struct AssignmentKind<SparseShape,DiagonalShape> { typedef Diagonal2Sparse Kind; }; - -template< typename DstXprType, typename SrcXprType, typename Functor> -struct Assignment<DstXprType, SrcXprType, Functor, Diagonal2Sparse> -{ - typedef typename DstXprType::StorageIndex StorageIndex; - typedef typename DstXprType::Scalar Scalar; - - template<int Options, typename AssignFunc> - static void run(SparseMatrix<Scalar,Options,StorageIndex> &dst, const SrcXprType &src, const AssignFunc &func) - { dst.assignDiagonal(src.diagonal(), func); } - - template<typename DstDerived> - static void run(SparseMatrixBase<DstDerived> &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/) - { dst.derived().diagonal() = src.diagonal(); } - - template<typename DstDerived> - static void run(SparseMatrixBase<DstDerived> &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/) - { dst.derived().diagonal() += src.diagonal(); } - - template<typename DstDerived> - static void run(SparseMatrixBase<DstDerived> &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/) - { dst.derived().diagonal() -= src.diagonal(); } -}; -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSEASSIGN_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseBlock.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseBlock.h deleted file mode 100644 index db509025..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseBlock.h +++ /dev/null @@ -1,567 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_BLOCK_H -#define EIGEN_SPARSE_BLOCK_H - -namespace Eigen { - -// Subset of columns or rows -template<typename XprType, int BlockRows, int BlockCols> -class BlockImpl<XprType,BlockRows,BlockCols,true,Sparse> - : public SparseMatrixBase<Block<XprType,BlockRows,BlockCols,true> > -{ - typedef typename internal::remove_all<typename XprType::Nested>::type _MatrixTypeNested; - typedef Block<XprType, BlockRows, BlockCols, true> BlockType; -public: - enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor }; -protected: - enum { OuterSize = IsRowMajor ? BlockRows : BlockCols }; - typedef SparseMatrixBase<BlockType> Base; - using Base::convert_index; -public: - EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType) - - inline BlockImpl(XprType& xpr, Index i) - : m_matrix(xpr), m_outerStart(convert_index(i)), m_outerSize(OuterSize) - {} - - inline BlockImpl(XprType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols) - : m_matrix(xpr), m_outerStart(convert_index(IsRowMajor ? startRow : startCol)), m_outerSize(convert_index(IsRowMajor ? blockRows : blockCols)) - {} - - EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } - - Index nonZeros() const - { - typedef internal::evaluator<XprType> EvaluatorType; - EvaluatorType matEval(m_matrix); - Index nnz = 0; - Index end = m_outerStart + m_outerSize.value(); - for(Index j=m_outerStart; j<end; ++j) - for(typename EvaluatorType::InnerIterator it(matEval, j); it; ++it) - ++nnz; - return nnz; - } - - inline const Scalar coeff(Index row, Index col) const - { - return m_matrix.coeff(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 : m_outerStart)); - } - - inline const Scalar coeff(Index index) const - { - return m_matrix.coeff(IsRowMajor ? m_outerStart : index, IsRowMajor ? index : m_outerStart); - } - - inline const XprType& nestedExpression() const { return m_matrix; } - inline XprType& nestedExpression() { return m_matrix; } - Index startRow() const { return IsRowMajor ? m_outerStart : 0; } - Index startCol() const { return IsRowMajor ? 0 : m_outerStart; } - Index blockRows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - Index blockCols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } - - protected: - - typename internal::ref_selector<XprType>::non_const_type m_matrix; - Index m_outerStart; - const internal::variable_if_dynamic<Index, OuterSize> m_outerSize; - - protected: - // Disable assignment with clear error message. - // Note that simply removing operator= yields compilation errors with ICC+MSVC - template<typename T> - BlockImpl& operator=(const T&) - { - EIGEN_STATIC_ASSERT(sizeof(T)==0, THIS_SPARSE_BLOCK_SUBEXPRESSION_IS_READ_ONLY); - return *this; - } -}; - - -/*************************************************************************** -* specialization for SparseMatrix -***************************************************************************/ - -namespace internal { - -template<typename SparseMatrixType, int BlockRows, int BlockCols> -class sparse_matrix_block_impl - : public SparseCompressedBase<Block<SparseMatrixType,BlockRows,BlockCols,true> > -{ - typedef typename internal::remove_all<typename SparseMatrixType::Nested>::type _MatrixTypeNested; - typedef Block<SparseMatrixType, BlockRows, BlockCols, true> BlockType; - typedef SparseCompressedBase<Block<SparseMatrixType,BlockRows,BlockCols,true> > Base; - using Base::convert_index; -public: - enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor }; - EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType) -protected: - typedef typename Base::IndexVector IndexVector; - enum { OuterSize = IsRowMajor ? BlockRows : BlockCols }; -public: - - inline sparse_matrix_block_impl(SparseMatrixType& xpr, Index i) - : m_matrix(xpr), m_outerStart(convert_index(i)), m_outerSize(OuterSize) - {} - - inline sparse_matrix_block_impl(SparseMatrixType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols) - : m_matrix(xpr), m_outerStart(convert_index(IsRowMajor ? startRow : startCol)), m_outerSize(convert_index(IsRowMajor ? blockRows : blockCols)) - {} - - template<typename OtherDerived> - inline BlockType& operator=(const SparseMatrixBase<OtherDerived>& other) - { - typedef typename internal::remove_all<typename SparseMatrixType::Nested>::type _NestedMatrixType; - _NestedMatrixType& matrix = m_matrix; - // This assignment is slow if this vector set is not empty - // and/or it is not at the end of the nonzeros of the underlying matrix. - - // 1 - eval to a temporary to avoid transposition and/or aliasing issues - Ref<const SparseMatrix<Scalar, IsRowMajor ? RowMajor : ColMajor, StorageIndex> > tmp(other.derived()); - eigen_internal_assert(tmp.outerSize()==m_outerSize.value()); - - // 2 - let's check whether there is enough allocated memory - Index nnz = tmp.nonZeros(); - Index start = m_outerStart==0 ? 0 : m_matrix.outerIndexPtr()[m_outerStart]; // starting position of the current block - Index end = m_matrix.outerIndexPtr()[m_outerStart+m_outerSize.value()]; // ending position of the current block - Index block_size = end - start; // available room in the current block - Index tail_size = m_matrix.outerIndexPtr()[m_matrix.outerSize()] - end; - - Index free_size = m_matrix.isCompressed() - ? Index(matrix.data().allocatedSize()) + block_size - : block_size; - - Index tmp_start = tmp.outerIndexPtr()[0]; - - bool update_trailing_pointers = false; - if(nnz>free_size) - { - // realloc manually to reduce copies - typename SparseMatrixType::Storage newdata(m_matrix.data().allocatedSize() - block_size + nnz); - - internal::smart_copy(m_matrix.valuePtr(), m_matrix.valuePtr() + start, newdata.valuePtr()); - internal::smart_copy(m_matrix.innerIndexPtr(), m_matrix.innerIndexPtr() + start, newdata.indexPtr()); - - internal::smart_copy(tmp.valuePtr() + tmp_start, tmp.valuePtr() + tmp_start + nnz, newdata.valuePtr() + start); - internal::smart_copy(tmp.innerIndexPtr() + tmp_start, tmp.innerIndexPtr() + tmp_start + nnz, newdata.indexPtr() + start); - - internal::smart_copy(matrix.valuePtr()+end, matrix.valuePtr()+end + tail_size, newdata.valuePtr()+start+nnz); - internal::smart_copy(matrix.innerIndexPtr()+end, matrix.innerIndexPtr()+end + tail_size, newdata.indexPtr()+start+nnz); - - newdata.resize(m_matrix.outerIndexPtr()[m_matrix.outerSize()] - block_size + nnz); - - matrix.data().swap(newdata); - - update_trailing_pointers = true; - } - else - { - if(m_matrix.isCompressed() && nnz!=block_size) - { - // no need to realloc, simply copy the tail at its respective position and insert tmp - matrix.data().resize(start + nnz + tail_size); - - internal::smart_memmove(matrix.valuePtr()+end, matrix.valuePtr() + end+tail_size, matrix.valuePtr() + start+nnz); - internal::smart_memmove(matrix.innerIndexPtr()+end, matrix.innerIndexPtr() + end+tail_size, matrix.innerIndexPtr() + start+nnz); - - update_trailing_pointers = true; - } - - internal::smart_copy(tmp.valuePtr() + tmp_start, tmp.valuePtr() + tmp_start + nnz, matrix.valuePtr() + start); - internal::smart_copy(tmp.innerIndexPtr() + tmp_start, tmp.innerIndexPtr() + tmp_start + nnz, matrix.innerIndexPtr() + start); - } - - // update outer index pointers and innerNonZeros - if(IsVectorAtCompileTime) - { - if(!m_matrix.isCompressed()) - matrix.innerNonZeroPtr()[m_outerStart] = StorageIndex(nnz); - matrix.outerIndexPtr()[m_outerStart] = StorageIndex(start); - } - else - { - StorageIndex p = StorageIndex(start); - for(Index k=0; k<m_outerSize.value(); ++k) - { - StorageIndex nnz_k = internal::convert_index<StorageIndex>(tmp.innerVector(k).nonZeros()); - if(!m_matrix.isCompressed()) - matrix.innerNonZeroPtr()[m_outerStart+k] = nnz_k; - matrix.outerIndexPtr()[m_outerStart+k] = p; - p += nnz_k; - } - } - - if(update_trailing_pointers) - { - StorageIndex offset = internal::convert_index<StorageIndex>(nnz - block_size); - for(Index k = m_outerStart + m_outerSize.value(); k<=matrix.outerSize(); ++k) - { - matrix.outerIndexPtr()[k] += offset; - } - } - - return derived(); - } - - inline BlockType& operator=(const BlockType& other) - { - return operator=<BlockType>(other); - } - - inline const Scalar* valuePtr() const - { return m_matrix.valuePtr(); } - inline Scalar* valuePtr() - { return m_matrix.valuePtr(); } - - inline const StorageIndex* innerIndexPtr() const - { return m_matrix.innerIndexPtr(); } - inline StorageIndex* innerIndexPtr() - { return m_matrix.innerIndexPtr(); } - - inline const StorageIndex* outerIndexPtr() const - { return m_matrix.outerIndexPtr() + m_outerStart; } - inline StorageIndex* outerIndexPtr() - { return m_matrix.outerIndexPtr() + m_outerStart; } - - inline const StorageIndex* innerNonZeroPtr() const - { return isCompressed() ? 0 : (m_matrix.innerNonZeroPtr()+m_outerStart); } - inline StorageIndex* innerNonZeroPtr() - { return isCompressed() ? 0 : (m_matrix.innerNonZeroPtr()+m_outerStart); } - - bool isCompressed() const { return m_matrix.innerNonZeroPtr()==0; } - - inline Scalar& coeffRef(Index row, Index col) - { - return m_matrix.coeffRef(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 : m_outerStart)); - } - - inline const Scalar coeff(Index row, Index col) const - { - return m_matrix.coeff(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 : m_outerStart)); - } - - inline const Scalar coeff(Index index) const - { - return m_matrix.coeff(IsRowMajor ? m_outerStart : index, IsRowMajor ? index : m_outerStart); - } - - const Scalar& lastCoeff() const - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(sparse_matrix_block_impl); - eigen_assert(Base::nonZeros()>0); - if(m_matrix.isCompressed()) - return m_matrix.valuePtr()[m_matrix.outerIndexPtr()[m_outerStart+1]-1]; - else - return m_matrix.valuePtr()[m_matrix.outerIndexPtr()[m_outerStart]+m_matrix.innerNonZeroPtr()[m_outerStart]-1]; - } - - EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } - - inline const SparseMatrixType& nestedExpression() const { return m_matrix; } - inline SparseMatrixType& nestedExpression() { return m_matrix; } - Index startRow() const { return IsRowMajor ? m_outerStart : 0; } - Index startCol() const { return IsRowMajor ? 0 : m_outerStart; } - Index blockRows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - Index blockCols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } - - protected: - - typename internal::ref_selector<SparseMatrixType>::non_const_type m_matrix; - Index m_outerStart; - const internal::variable_if_dynamic<Index, OuterSize> m_outerSize; - -}; - -} // namespace internal - -template<typename _Scalar, int _Options, typename _StorageIndex, int BlockRows, int BlockCols> -class BlockImpl<SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true,Sparse> - : public internal::sparse_matrix_block_impl<SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols> -{ -public: - typedef _StorageIndex StorageIndex; - typedef SparseMatrix<_Scalar, _Options, _StorageIndex> SparseMatrixType; - typedef internal::sparse_matrix_block_impl<SparseMatrixType,BlockRows,BlockCols> Base; - inline BlockImpl(SparseMatrixType& xpr, Index i) - : Base(xpr, i) - {} - - inline BlockImpl(SparseMatrixType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols) - : Base(xpr, startRow, startCol, blockRows, blockCols) - {} - - using Base::operator=; -}; - -template<typename _Scalar, int _Options, typename _StorageIndex, int BlockRows, int BlockCols> -class BlockImpl<const SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true,Sparse> - : public internal::sparse_matrix_block_impl<const SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols> -{ -public: - typedef _StorageIndex StorageIndex; - typedef const SparseMatrix<_Scalar, _Options, _StorageIndex> SparseMatrixType; - typedef internal::sparse_matrix_block_impl<SparseMatrixType,BlockRows,BlockCols> Base; - inline BlockImpl(SparseMatrixType& xpr, Index i) - : Base(xpr, i) - {} - - inline BlockImpl(SparseMatrixType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols) - : Base(xpr, startRow, startCol, blockRows, blockCols) - {} - - using Base::operator=; -private: - template<typename Derived> BlockImpl(const SparseMatrixBase<Derived>& xpr, Index i); - template<typename Derived> BlockImpl(const SparseMatrixBase<Derived>& xpr); -}; - -//---------- - -/** Generic implementation of sparse Block expression. - * Real-only. - */ -template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> -class BlockImpl<XprType,BlockRows,BlockCols,InnerPanel,Sparse> - : public SparseMatrixBase<Block<XprType,BlockRows,BlockCols,InnerPanel> >, internal::no_assignment_operator -{ - typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType; - typedef SparseMatrixBase<BlockType> Base; - using Base::convert_index; -public: - enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor }; - EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType) - - typedef typename internal::remove_all<typename XprType::Nested>::type _MatrixTypeNested; - - /** Column or Row constructor - */ - inline BlockImpl(XprType& xpr, Index i) - : m_matrix(xpr), - m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? convert_index(i) : 0), - m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? convert_index(i) : 0), - m_blockRows(BlockRows==1 ? 1 : xpr.rows()), - m_blockCols(BlockCols==1 ? 1 : xpr.cols()) - {} - - /** Dynamic-size constructor - */ - inline BlockImpl(XprType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols) - : m_matrix(xpr), m_startRow(convert_index(startRow)), m_startCol(convert_index(startCol)), m_blockRows(convert_index(blockRows)), m_blockCols(convert_index(blockCols)) - {} - - inline Index rows() const { return m_blockRows.value(); } - inline Index cols() const { return m_blockCols.value(); } - - inline Scalar& coeffRef(Index row, Index col) - { - return m_matrix.coeffRef(row + m_startRow.value(), col + m_startCol.value()); - } - - inline const Scalar coeff(Index row, Index col) const - { - return m_matrix.coeff(row + m_startRow.value(), col + m_startCol.value()); - } - - inline Scalar& coeffRef(Index index) - { - return m_matrix.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), - m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); - } - - inline const Scalar coeff(Index index) const - { - return m_matrix.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), - m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); - } - - inline const XprType& nestedExpression() const { return m_matrix; } - inline XprType& nestedExpression() { return m_matrix; } - Index startRow() const { return m_startRow.value(); } - Index startCol() const { return m_startCol.value(); } - Index blockRows() const { return m_blockRows.value(); } - Index blockCols() const { return m_blockCols.value(); } - - protected: -// friend class internal::GenericSparseBlockInnerIteratorImpl<XprType,BlockRows,BlockCols,InnerPanel>; - friend struct internal::unary_evaluator<Block<XprType,BlockRows,BlockCols,InnerPanel>, internal::IteratorBased, Scalar >; - - Index nonZeros() const { return Dynamic; } - - typename internal::ref_selector<XprType>::non_const_type m_matrix; - const internal::variable_if_dynamic<Index, XprType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow; - const internal::variable_if_dynamic<Index, XprType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol; - const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_blockRows; - const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_blockCols; - - protected: - // Disable assignment with clear error message. - // Note that simply removing operator= yields compilation errors with ICC+MSVC - template<typename T> - BlockImpl& operator=(const T&) - { - EIGEN_STATIC_ASSERT(sizeof(T)==0, THIS_SPARSE_BLOCK_SUBEXPRESSION_IS_READ_ONLY); - return *this; - } - -}; - -namespace internal { - -template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> -struct unary_evaluator<Block<ArgType,BlockRows,BlockCols,InnerPanel>, IteratorBased > - : public evaluator_base<Block<ArgType,BlockRows,BlockCols,InnerPanel> > -{ - class InnerVectorInnerIterator; - class OuterVectorInnerIterator; - public: - typedef Block<ArgType,BlockRows,BlockCols,InnerPanel> XprType; - typedef typename XprType::StorageIndex StorageIndex; - typedef typename XprType::Scalar Scalar; - - enum { - IsRowMajor = XprType::IsRowMajor, - - OuterVector = (BlockCols==1 && ArgType::IsRowMajor) - | // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&". - // revert to || as soon as not needed anymore. - (BlockRows==1 && !ArgType::IsRowMajor), - - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - Flags = XprType::Flags - }; - - typedef typename internal::conditional<OuterVector,OuterVectorInnerIterator,InnerVectorInnerIterator>::type InnerIterator; - - explicit unary_evaluator(const XprType& op) - : m_argImpl(op.nestedExpression()), m_block(op) - {} - - inline Index nonZerosEstimate() const { - Index nnz = m_block.nonZeros(); - if(nnz<0) - return m_argImpl.nonZerosEstimate() * m_block.size() / m_block.nestedExpression().size(); - return nnz; - } - - protected: - typedef typename evaluator<ArgType>::InnerIterator EvalIterator; - - evaluator<ArgType> m_argImpl; - const XprType &m_block; -}; - -template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> -class unary_evaluator<Block<ArgType,BlockRows,BlockCols,InnerPanel>, IteratorBased>::InnerVectorInnerIterator - : public EvalIterator -{ - // NOTE MSVC fails to compile if we don't explicitely "import" IsRowMajor from unary_evaluator - // because the base class EvalIterator has a private IsRowMajor enum too. (bug #1786) - // NOTE We cannot call it IsRowMajor because it would shadow unary_evaluator::IsRowMajor - enum { XprIsRowMajor = unary_evaluator::IsRowMajor }; - const XprType& m_block; - Index m_end; -public: - - EIGEN_STRONG_INLINE InnerVectorInnerIterator(const unary_evaluator& aEval, Index outer) - : EvalIterator(aEval.m_argImpl, outer + (XprIsRowMajor ? aEval.m_block.startRow() : aEval.m_block.startCol())), - m_block(aEval.m_block), - m_end(XprIsRowMajor ? aEval.m_block.startCol()+aEval.m_block.blockCols() : aEval.m_block.startRow()+aEval.m_block.blockRows()) - { - while( (EvalIterator::operator bool()) && (EvalIterator::index() < (XprIsRowMajor ? m_block.startCol() : m_block.startRow())) ) - EvalIterator::operator++(); - } - - inline StorageIndex index() const { return EvalIterator::index() - convert_index<StorageIndex>(XprIsRowMajor ? m_block.startCol() : m_block.startRow()); } - inline Index outer() const { return EvalIterator::outer() - (XprIsRowMajor ? m_block.startRow() : m_block.startCol()); } - inline Index row() const { return EvalIterator::row() - m_block.startRow(); } - inline Index col() const { return EvalIterator::col() - m_block.startCol(); } - - inline operator bool() const { return EvalIterator::operator bool() && EvalIterator::index() < m_end; } -}; - -template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> -class unary_evaluator<Block<ArgType,BlockRows,BlockCols,InnerPanel>, IteratorBased>::OuterVectorInnerIterator -{ - // NOTE see above - enum { XprIsRowMajor = unary_evaluator::IsRowMajor }; - const unary_evaluator& m_eval; - Index m_outerPos; - const Index m_innerIndex; - Index m_end; - EvalIterator m_it; -public: - - EIGEN_STRONG_INLINE OuterVectorInnerIterator(const unary_evaluator& aEval, Index outer) - : m_eval(aEval), - m_outerPos( (XprIsRowMajor ? aEval.m_block.startCol() : aEval.m_block.startRow()) ), - m_innerIndex(XprIsRowMajor ? aEval.m_block.startRow() : aEval.m_block.startCol()), - m_end(XprIsRowMajor ? aEval.m_block.startCol()+aEval.m_block.blockCols() : aEval.m_block.startRow()+aEval.m_block.blockRows()), - m_it(m_eval.m_argImpl, m_outerPos) - { - EIGEN_UNUSED_VARIABLE(outer); - eigen_assert(outer==0); - - while(m_it && m_it.index() < m_innerIndex) ++m_it; - if((!m_it) || (m_it.index()!=m_innerIndex)) - ++(*this); - } - - inline StorageIndex index() const { return convert_index<StorageIndex>(m_outerPos - (XprIsRowMajor ? m_eval.m_block.startCol() : m_eval.m_block.startRow())); } - inline Index outer() const { return 0; } - inline Index row() const { return XprIsRowMajor ? 0 : index(); } - inline Index col() const { return XprIsRowMajor ? index() : 0; } - - inline Scalar value() const { return m_it.value(); } - inline Scalar& valueRef() { return m_it.valueRef(); } - - inline OuterVectorInnerIterator& operator++() - { - // search next non-zero entry - while(++m_outerPos<m_end) - { - // Restart iterator at the next inner-vector: - m_it.~EvalIterator(); - ::new (&m_it) EvalIterator(m_eval.m_argImpl, m_outerPos); - // search for the key m_innerIndex in the current outer-vector - while(m_it && m_it.index() < m_innerIndex) ++m_it; - if(m_it && m_it.index()==m_innerIndex) break; - } - return *this; - } - - inline operator bool() const { return m_outerPos < m_end; } -}; - -template<typename _Scalar, int _Options, typename _StorageIndex, int BlockRows, int BlockCols> -struct unary_evaluator<Block<SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true>, IteratorBased> - : evaluator<SparseCompressedBase<Block<SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true> > > -{ - typedef Block<SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true> XprType; - typedef evaluator<SparseCompressedBase<XprType> > Base; - explicit unary_evaluator(const XprType &xpr) : Base(xpr) {} -}; - -template<typename _Scalar, int _Options, typename _StorageIndex, int BlockRows, int BlockCols> -struct unary_evaluator<Block<const SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true>, IteratorBased> - : evaluator<SparseCompressedBase<Block<const SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true> > > -{ - typedef Block<const SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true> XprType; - typedef evaluator<SparseCompressedBase<XprType> > Base; - explicit unary_evaluator(const XprType &xpr) : Base(xpr) {} -}; - -} // end namespace internal - - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_BLOCK_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseColEtree.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseColEtree.h deleted file mode 100644 index ebe02d1a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseColEtree.h +++ /dev/null @@ -1,206 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -/* - - * NOTE: This file is the modified version of sp_coletree.c file in SuperLU - - * -- SuperLU routine (version 3.1) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * August 1, 2008 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ -#ifndef SPARSE_COLETREE_H -#define SPARSE_COLETREE_H - -namespace Eigen { - -namespace internal { - -/** Find the root of the tree/set containing the vertex i : Use Path halving */ -template<typename Index, typename IndexVector> -Index etree_find (Index i, IndexVector& pp) -{ - Index p = pp(i); // Parent - Index gp = pp(p); // Grand parent - while (gp != p) - { - pp(i) = gp; // Parent pointer on find path is changed to former grand parent - i = gp; - p = pp(i); - gp = pp(p); - } - return p; -} - -/** Compute the column elimination tree of a sparse matrix - * \param mat The matrix in column-major format. - * \param parent The elimination tree - * \param firstRowElt The column index of the first element in each row - * \param perm The permutation to apply to the column of \b mat - */ -template <typename MatrixType, typename IndexVector> -int coletree(const MatrixType& mat, IndexVector& parent, IndexVector& firstRowElt, typename MatrixType::StorageIndex *perm=0) -{ - typedef typename MatrixType::StorageIndex StorageIndex; - StorageIndex nc = convert_index<StorageIndex>(mat.cols()); // Number of columns - StorageIndex m = convert_index<StorageIndex>(mat.rows()); - StorageIndex diagSize = (std::min)(nc,m); - IndexVector root(nc); // root of subtree of etree - root.setZero(); - IndexVector pp(nc); // disjoint sets - pp.setZero(); // Initialize disjoint sets - parent.resize(mat.cols()); - //Compute first nonzero column in each row - firstRowElt.resize(m); - firstRowElt.setConstant(nc); - firstRowElt.segment(0, diagSize).setLinSpaced(diagSize, 0, diagSize-1); - bool found_diag; - for (StorageIndex col = 0; col < nc; col++) - { - StorageIndex pcol = col; - if(perm) pcol = perm[col]; - for (typename MatrixType::InnerIterator it(mat, pcol); it; ++it) - { - Index row = it.row(); - firstRowElt(row) = (std::min)(firstRowElt(row), col); - } - } - /* Compute etree by Liu's algorithm for symmetric matrices, - except use (firstRowElt[r],c) in place of an edge (r,c) of A. - Thus each row clique in A'*A is replaced by a star - centered at its first vertex, which has the same fill. */ - StorageIndex rset, cset, rroot; - for (StorageIndex col = 0; col < nc; col++) - { - found_diag = col>=m; - pp(col) = col; - cset = col; - root(cset) = col; - parent(col) = nc; - /* The diagonal element is treated here even if it does not exist in the matrix - * hence the loop is executed once more */ - StorageIndex pcol = col; - if(perm) pcol = perm[col]; - for (typename MatrixType::InnerIterator it(mat, pcol); it||!found_diag; ++it) - { // A sequence of interleaved find and union is performed - Index i = col; - if(it) i = it.index(); - if (i == col) found_diag = true; - - StorageIndex row = firstRowElt(i); - if (row >= col) continue; - rset = internal::etree_find(row, pp); // Find the name of the set containing row - rroot = root(rset); - if (rroot != col) - { - parent(rroot) = col; - pp(cset) = rset; - cset = rset; - root(cset) = col; - } - } - } - return 0; -} - -/** - * Depth-first search from vertex n. No recursion. - * This routine was contributed by Cédric Doucet, CEDRAT Group, Meylan, France. -*/ -template <typename IndexVector> -void nr_etdfs (typename IndexVector::Scalar n, IndexVector& parent, IndexVector& first_kid, IndexVector& next_kid, IndexVector& post, typename IndexVector::Scalar postnum) -{ - typedef typename IndexVector::Scalar StorageIndex; - StorageIndex current = n, first, next; - while (postnum != n) - { - // No kid for the current node - first = first_kid(current); - - // no kid for the current node - if (first == -1) - { - // Numbering this node because it has no kid - post(current) = postnum++; - - // looking for the next kid - next = next_kid(current); - while (next == -1) - { - // No more kids : back to the parent node - current = parent(current); - // numbering the parent node - post(current) = postnum++; - - // Get the next kid - next = next_kid(current); - } - // stopping criterion - if (postnum == n+1) return; - - // Updating current node - current = next; - } - else - { - current = first; - } - } -} - - -/** - * \brief Post order a tree - * \param n the number of nodes - * \param parent Input tree - * \param post postordered tree - */ -template <typename IndexVector> -void treePostorder(typename IndexVector::Scalar n, IndexVector& parent, IndexVector& post) -{ - typedef typename IndexVector::Scalar StorageIndex; - IndexVector first_kid, next_kid; // Linked list of children - StorageIndex postnum; - // Allocate storage for working arrays and results - first_kid.resize(n+1); - next_kid.setZero(n+1); - post.setZero(n+1); - - // Set up structure describing children - first_kid.setConstant(-1); - for (StorageIndex v = n-1; v >= 0; v--) - { - StorageIndex dad = parent(v); - next_kid(v) = first_kid(dad); - first_kid(dad) = v; - } - - // Depth-first search from dummy root vertex #n - postnum = 0; - internal::nr_etdfs(n, parent, first_kid, next_kid, post, postnum); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // SPARSE_COLETREE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCompressedBase.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCompressedBase.h deleted file mode 100644 index 6a2c7a8c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCompressedBase.h +++ /dev/null @@ -1,370 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_COMPRESSED_BASE_H -#define EIGEN_SPARSE_COMPRESSED_BASE_H - -namespace Eigen { - -template<typename Derived> class SparseCompressedBase; - -namespace internal { - -template<typename Derived> -struct traits<SparseCompressedBase<Derived> > : traits<Derived> -{}; - -} // end namespace internal - -/** \ingroup SparseCore_Module - * \class SparseCompressedBase - * \brief Common base class for sparse [compressed]-{row|column}-storage format. - * - * This class defines the common interface for all derived classes implementing the compressed sparse storage format, such as: - * - SparseMatrix - * - Ref<SparseMatrixType,Options> - * - Map<SparseMatrixType> - * - */ -template<typename Derived> -class SparseCompressedBase - : public SparseMatrixBase<Derived> -{ - public: - typedef SparseMatrixBase<Derived> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(SparseCompressedBase) - using Base::operator=; - using Base::IsRowMajor; - - class InnerIterator; - class ReverseInnerIterator; - - protected: - typedef typename Base::IndexVector IndexVector; - Eigen::Map<IndexVector> innerNonZeros() { return Eigen::Map<IndexVector>(innerNonZeroPtr(), isCompressed()?0:derived().outerSize()); } - const Eigen::Map<const IndexVector> innerNonZeros() const { return Eigen::Map<const IndexVector>(innerNonZeroPtr(), isCompressed()?0:derived().outerSize()); } - - public: - - /** \returns the number of non zero coefficients */ - inline Index nonZeros() const - { - if(Derived::IsVectorAtCompileTime && outerIndexPtr()==0) - return derived().nonZeros(); - else if(isCompressed()) - return outerIndexPtr()[derived().outerSize()]-outerIndexPtr()[0]; - else if(derived().outerSize()==0) - return 0; - else - return innerNonZeros().sum(); - } - - /** \returns a const pointer to the array of values. - * This function is aimed at interoperability with other libraries. - * \sa innerIndexPtr(), outerIndexPtr() */ - inline const Scalar* valuePtr() const { return derived().valuePtr(); } - /** \returns a non-const pointer to the array of values. - * This function is aimed at interoperability with other libraries. - * \sa innerIndexPtr(), outerIndexPtr() */ - inline Scalar* valuePtr() { return derived().valuePtr(); } - - /** \returns a const pointer to the array of inner indices. - * This function is aimed at interoperability with other libraries. - * \sa valuePtr(), outerIndexPtr() */ - inline const StorageIndex* innerIndexPtr() const { return derived().innerIndexPtr(); } - /** \returns a non-const pointer to the array of inner indices. - * This function is aimed at interoperability with other libraries. - * \sa valuePtr(), outerIndexPtr() */ - inline StorageIndex* innerIndexPtr() { return derived().innerIndexPtr(); } - - /** \returns a const pointer to the array of the starting positions of the inner vectors. - * This function is aimed at interoperability with other libraries. - * \warning it returns the null pointer 0 for SparseVector - * \sa valuePtr(), innerIndexPtr() */ - inline const StorageIndex* outerIndexPtr() const { return derived().outerIndexPtr(); } - /** \returns a non-const pointer to the array of the starting positions of the inner vectors. - * This function is aimed at interoperability with other libraries. - * \warning it returns the null pointer 0 for SparseVector - * \sa valuePtr(), innerIndexPtr() */ - inline StorageIndex* outerIndexPtr() { return derived().outerIndexPtr(); } - - /** \returns a const pointer to the array of the number of non zeros of the inner vectors. - * This function is aimed at interoperability with other libraries. - * \warning it returns the null pointer 0 in compressed mode */ - inline const StorageIndex* innerNonZeroPtr() const { return derived().innerNonZeroPtr(); } - /** \returns a non-const pointer to the array of the number of non zeros of the inner vectors. - * This function is aimed at interoperability with other libraries. - * \warning it returns the null pointer 0 in compressed mode */ - inline StorageIndex* innerNonZeroPtr() { return derived().innerNonZeroPtr(); } - - /** \returns whether \c *this is in compressed form. */ - inline bool isCompressed() const { return innerNonZeroPtr()==0; } - - /** \returns a read-only view of the stored coefficients as a 1D array expression. - * - * \warning this method is for \b compressed \b storage \b only, and it will trigger an assertion otherwise. - * - * \sa valuePtr(), isCompressed() */ - const Map<const Array<Scalar,Dynamic,1> > coeffs() const { eigen_assert(isCompressed()); return Array<Scalar,Dynamic,1>::Map(valuePtr(),nonZeros()); } - - /** \returns a read-write view of the stored coefficients as a 1D array expression - * - * \warning this method is for \b compressed \b storage \b only, and it will trigger an assertion otherwise. - * - * Here is an example: - * \include SparseMatrix_coeffs.cpp - * and the output is: - * \include SparseMatrix_coeffs.out - * - * \sa valuePtr(), isCompressed() */ - Map<Array<Scalar,Dynamic,1> > coeffs() { eigen_assert(isCompressed()); return Array<Scalar,Dynamic,1>::Map(valuePtr(),nonZeros()); } - - protected: - /** Default constructor. Do nothing. */ - SparseCompressedBase() {} - - /** \internal return the index of the coeff at (row,col) or just before if it does not exist. - * This is an analogue of std::lower_bound. - */ - internal::LowerBoundIndex lower_bound(Index row, Index col) const - { - eigen_internal_assert(row>=0 && row<this->rows() && col>=0 && col<this->cols()); - - const Index outer = Derived::IsRowMajor ? row : col; - const Index inner = Derived::IsRowMajor ? col : row; - - Index start = this->outerIndexPtr()[outer]; - Index end = this->isCompressed() ? this->outerIndexPtr()[outer+1] : this->outerIndexPtr()[outer] + this->innerNonZeroPtr()[outer]; - eigen_assert(end>=start && "you are using a non finalized sparse matrix or written coefficient does not exist"); - internal::LowerBoundIndex p; - p.value = std::lower_bound(this->innerIndexPtr()+start, this->innerIndexPtr()+end,inner) - this->innerIndexPtr(); - p.found = (p.value<end) && (this->innerIndexPtr()[p.value]==inner); - return p; - } - - friend struct internal::evaluator<SparseCompressedBase<Derived> >; - - private: - template<typename OtherDerived> explicit SparseCompressedBase(const SparseCompressedBase<OtherDerived>&); -}; - -template<typename Derived> -class SparseCompressedBase<Derived>::InnerIterator -{ - public: - InnerIterator() - : m_values(0), m_indices(0), m_outer(0), m_id(0), m_end(0) - {} - - InnerIterator(const InnerIterator& other) - : m_values(other.m_values), m_indices(other.m_indices), m_outer(other.m_outer), m_id(other.m_id), m_end(other.m_end) - {} - - InnerIterator& operator=(const InnerIterator& other) - { - m_values = other.m_values; - m_indices = other.m_indices; - const_cast<OuterType&>(m_outer).setValue(other.m_outer.value()); - m_id = other.m_id; - m_end = other.m_end; - return *this; - } - - InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) - { - if(Derived::IsVectorAtCompileTime && mat.outerIndexPtr()==0) - { - m_id = 0; - m_end = mat.nonZeros(); - } - else - { - m_id = mat.outerIndexPtr()[outer]; - if(mat.isCompressed()) - m_end = mat.outerIndexPtr()[outer+1]; - else - m_end = m_id + mat.innerNonZeroPtr()[outer]; - } - } - - explicit InnerIterator(const SparseCompressedBase& mat) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(0), m_id(0), m_end(mat.nonZeros()) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - } - - explicit InnerIterator(const internal::CompressedStorage<Scalar,StorageIndex>& data) - : m_values(data.valuePtr()), m_indices(data.indexPtr()), m_outer(0), m_id(0), m_end(data.size()) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - } - - inline InnerIterator& operator++() { m_id++; return *this; } - inline InnerIterator& operator+=(Index i) { m_id += i ; return *this; } - - inline InnerIterator operator+(Index i) - { - InnerIterator result = *this; - result += i; - return result; - } - - inline const Scalar& value() const { return m_values[m_id]; } - inline Scalar& valueRef() { return const_cast<Scalar&>(m_values[m_id]); } - - inline StorageIndex index() const { return m_indices[m_id]; } - inline Index outer() const { return m_outer.value(); } - inline Index row() const { return IsRowMajor ? m_outer.value() : index(); } - inline Index col() const { return IsRowMajor ? index() : m_outer.value(); } - - inline operator bool() const { return (m_id < m_end); } - - protected: - const Scalar* m_values; - const StorageIndex* m_indices; - typedef internal::variable_if_dynamic<Index,Derived::IsVectorAtCompileTime?0:Dynamic> OuterType; - const OuterType m_outer; - Index m_id; - Index m_end; - private: - // If you get here, then you're not using the right InnerIterator type, e.g.: - // SparseMatrix<double,RowMajor> A; - // SparseMatrix<double>::InnerIterator it(A,0); - template<typename T> InnerIterator(const SparseMatrixBase<T>&, Index outer); -}; - -template<typename Derived> -class SparseCompressedBase<Derived>::ReverseInnerIterator -{ - public: - ReverseInnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) - { - if(Derived::IsVectorAtCompileTime && mat.outerIndexPtr()==0) - { - m_start = 0; - m_id = mat.nonZeros(); - } - else - { - m_start = mat.outerIndexPtr()[outer]; - if(mat.isCompressed()) - m_id = mat.outerIndexPtr()[outer+1]; - else - m_id = m_start + mat.innerNonZeroPtr()[outer]; - } - } - - explicit ReverseInnerIterator(const SparseCompressedBase& mat) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(0), m_start(0), m_id(mat.nonZeros()) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - } - - explicit ReverseInnerIterator(const internal::CompressedStorage<Scalar,StorageIndex>& data) - : m_values(data.valuePtr()), m_indices(data.indexPtr()), m_outer(0), m_start(0), m_id(data.size()) - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - } - - inline ReverseInnerIterator& operator--() { --m_id; return *this; } - inline ReverseInnerIterator& operator-=(Index i) { m_id -= i; return *this; } - - inline ReverseInnerIterator operator-(Index i) - { - ReverseInnerIterator result = *this; - result -= i; - return result; - } - - inline const Scalar& value() const { return m_values[m_id-1]; } - inline Scalar& valueRef() { return const_cast<Scalar&>(m_values[m_id-1]); } - - inline StorageIndex index() const { return m_indices[m_id-1]; } - inline Index outer() const { return m_outer.value(); } - inline Index row() const { return IsRowMajor ? m_outer.value() : index(); } - inline Index col() const { return IsRowMajor ? index() : m_outer.value(); } - - inline operator bool() const { return (m_id > m_start); } - - protected: - const Scalar* m_values; - const StorageIndex* m_indices; - typedef internal::variable_if_dynamic<Index,Derived::IsVectorAtCompileTime?0:Dynamic> OuterType; - const OuterType m_outer; - Index m_start; - Index m_id; -}; - -namespace internal { - -template<typename Derived> -struct evaluator<SparseCompressedBase<Derived> > - : evaluator_base<Derived> -{ - typedef typename Derived::Scalar Scalar; - typedef typename Derived::InnerIterator InnerIterator; - - enum { - CoeffReadCost = NumTraits<Scalar>::ReadCost, - Flags = Derived::Flags - }; - - evaluator() : m_matrix(0), m_zero(0) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - explicit evaluator(const Derived &mat) : m_matrix(&mat), m_zero(0) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return m_matrix->nonZeros(); - } - - operator Derived&() { return m_matrix->const_cast_derived(); } - operator const Derived&() const { return *m_matrix; } - - typedef typename DenseCoeffsBase<Derived,ReadOnlyAccessors>::CoeffReturnType CoeffReturnType; - const Scalar& coeff(Index row, Index col) const - { - Index p = find(row,col); - - if(p==Dynamic) - return m_zero; - else - return m_matrix->const_cast_derived().valuePtr()[p]; - } - - Scalar& coeffRef(Index row, Index col) - { - Index p = find(row,col); - eigen_assert(p!=Dynamic && "written coefficient does not exist"); - return m_matrix->const_cast_derived().valuePtr()[p]; - } - -protected: - - Index find(Index row, Index col) const - { - internal::LowerBoundIndex p = m_matrix->lower_bound(row,col); - return p.found ? p.value : Dynamic; - } - - const Derived *m_matrix; - const Scalar m_zero; -}; - -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_COMPRESSED_BASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCwiseBinaryOp.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCwiseBinaryOp.h deleted file mode 100644 index 6130bab4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +++ /dev/null @@ -1,722 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_CWISE_BINARY_OP_H -#define EIGEN_SPARSE_CWISE_BINARY_OP_H - -namespace Eigen { - -// Here we have to handle 3 cases: -// 1 - sparse op dense -// 2 - dense op sparse -// 3 - sparse op sparse -// We also need to implement a 4th iterator for: -// 4 - dense op dense -// Finally, we also need to distinguish between the product and other operations : -// configuration returned mode -// 1 - sparse op dense product sparse -// generic dense -// 2 - dense op sparse product sparse -// generic dense -// 3 - sparse op sparse product sparse -// generic sparse -// 4 - dense op dense product dense -// generic dense -// -// TODO to ease compiler job, we could specialize product/quotient with a scalar -// and fallback to cwise-unary evaluator using bind1st_op and bind2nd_op. - -template<typename BinaryOp, typename Lhs, typename Rhs> -class CwiseBinaryOpImpl<BinaryOp, Lhs, Rhs, Sparse> - : public SparseMatrixBase<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > -{ - public: - typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> Derived; - typedef SparseMatrixBase<Derived> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) - CwiseBinaryOpImpl() - { - EIGEN_STATIC_ASSERT(( - (!internal::is_same<typename internal::traits<Lhs>::StorageKind, - typename internal::traits<Rhs>::StorageKind>::value) - || ((internal::evaluator<Lhs>::Flags&RowMajorBit) == (internal::evaluator<Rhs>::Flags&RowMajorBit))), - THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH); - } -}; - -namespace internal { - - -// Generic "sparse OP sparse" -template<typename XprType> struct binary_sparse_evaluator; - -template<typename BinaryOp, typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IteratorBased, IteratorBased> - : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > -{ -protected: - typedef typename evaluator<Lhs>::InnerIterator LhsIterator; - typedef typename evaluator<Rhs>::InnerIterator RhsIterator; - typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType; - typedef typename traits<XprType>::Scalar Scalar; - typedef typename XprType::StorageIndex StorageIndex; -public: - - class InnerIterator - { - public: - - EIGEN_STRONG_INLINE InnerIterator(const binary_evaluator& aEval, Index outer) - : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor) - { - this->operator++(); - } - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - if (m_lhsIter && m_rhsIter && (m_lhsIter.index() == m_rhsIter.index())) - { - m_id = m_lhsIter.index(); - m_value = m_functor(m_lhsIter.value(), m_rhsIter.value()); - ++m_lhsIter; - ++m_rhsIter; - } - else if (m_lhsIter && (!m_rhsIter || (m_lhsIter.index() < m_rhsIter.index()))) - { - m_id = m_lhsIter.index(); - m_value = m_functor(m_lhsIter.value(), Scalar(0)); - ++m_lhsIter; - } - else if (m_rhsIter && (!m_lhsIter || (m_lhsIter.index() > m_rhsIter.index()))) - { - m_id = m_rhsIter.index(); - m_value = m_functor(Scalar(0), m_rhsIter.value()); - ++m_rhsIter; - } - else - { - m_value = Scalar(0); // this is to avoid a compilation warning - m_id = -1; - } - return *this; - } - - EIGEN_STRONG_INLINE Scalar value() const { return m_value; } - - EIGEN_STRONG_INLINE StorageIndex index() const { return m_id; } - EIGEN_STRONG_INLINE Index outer() const { return m_lhsIter.outer(); } - EIGEN_STRONG_INLINE Index row() const { return Lhs::IsRowMajor ? m_lhsIter.row() : index(); } - EIGEN_STRONG_INLINE Index col() const { return Lhs::IsRowMajor ? index() : m_lhsIter.col(); } - - EIGEN_STRONG_INLINE operator bool() const { return m_id>=0; } - - protected: - LhsIterator m_lhsIter; - RhsIterator m_rhsIter; - const BinaryOp& m_functor; - Scalar m_value; - StorageIndex m_id; - }; - - - enum { - CoeffReadCost = evaluator<Lhs>::CoeffReadCost + evaluator<Rhs>::CoeffReadCost + functor_traits<BinaryOp>::Cost, - Flags = XprType::Flags - }; - - explicit binary_evaluator(const XprType& xpr) - : m_functor(xpr.functor()), - m_lhsImpl(xpr.lhs()), - m_rhsImpl(xpr.rhs()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return m_lhsImpl.nonZerosEstimate() + m_rhsImpl.nonZerosEstimate(); - } - -protected: - const BinaryOp m_functor; - evaluator<Lhs> m_lhsImpl; - evaluator<Rhs> m_rhsImpl; -}; - -// dense op sparse -template<typename BinaryOp, typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IteratorBased> - : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > -{ -protected: - typedef typename evaluator<Rhs>::InnerIterator RhsIterator; - typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType; - typedef typename traits<XprType>::Scalar Scalar; - typedef typename XprType::StorageIndex StorageIndex; -public: - - class InnerIterator - { - enum { IsRowMajor = (int(Rhs::Flags)&RowMajorBit)==RowMajorBit }; - public: - - EIGEN_STRONG_INLINE InnerIterator(const binary_evaluator& aEval, Index outer) - : m_lhsEval(aEval.m_lhsImpl), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor), m_value(0), m_id(-1), m_innerSize(aEval.m_expr.rhs().innerSize()) - { - this->operator++(); - } - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - ++m_id; - if(m_id<m_innerSize) - { - Scalar lhsVal = m_lhsEval.coeff(IsRowMajor?m_rhsIter.outer():m_id, - IsRowMajor?m_id:m_rhsIter.outer()); - if(m_rhsIter && m_rhsIter.index()==m_id) - { - m_value = m_functor(lhsVal, m_rhsIter.value()); - ++m_rhsIter; - } - else - m_value = m_functor(lhsVal, Scalar(0)); - } - - return *this; - } - - EIGEN_STRONG_INLINE Scalar value() const { eigen_internal_assert(m_id<m_innerSize); return m_value; } - - EIGEN_STRONG_INLINE StorageIndex index() const { return m_id; } - EIGEN_STRONG_INLINE Index outer() const { return m_rhsIter.outer(); } - EIGEN_STRONG_INLINE Index row() const { return IsRowMajor ? m_rhsIter.outer() : m_id; } - EIGEN_STRONG_INLINE Index col() const { return IsRowMajor ? m_id : m_rhsIter.outer(); } - - EIGEN_STRONG_INLINE operator bool() const { return m_id<m_innerSize; } - - protected: - const evaluator<Lhs> &m_lhsEval; - RhsIterator m_rhsIter; - const BinaryOp& m_functor; - Scalar m_value; - StorageIndex m_id; - StorageIndex m_innerSize; - }; - - - enum { - CoeffReadCost = evaluator<Lhs>::CoeffReadCost + evaluator<Rhs>::CoeffReadCost + functor_traits<BinaryOp>::Cost, - Flags = XprType::Flags - }; - - explicit binary_evaluator(const XprType& xpr) - : m_functor(xpr.functor()), - m_lhsImpl(xpr.lhs()), - m_rhsImpl(xpr.rhs()), - m_expr(xpr) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return m_expr.size(); - } - -protected: - const BinaryOp m_functor; - evaluator<Lhs> m_lhsImpl; - evaluator<Rhs> m_rhsImpl; - const XprType &m_expr; -}; - -// sparse op dense -template<typename BinaryOp, typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IteratorBased, IndexBased> - : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > -{ -protected: - typedef typename evaluator<Lhs>::InnerIterator LhsIterator; - typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType; - typedef typename traits<XprType>::Scalar Scalar; - typedef typename XprType::StorageIndex StorageIndex; -public: - - class InnerIterator - { - enum { IsRowMajor = (int(Lhs::Flags)&RowMajorBit)==RowMajorBit }; - public: - - EIGEN_STRONG_INLINE InnerIterator(const binary_evaluator& aEval, Index outer) - : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsEval(aEval.m_rhsImpl), m_functor(aEval.m_functor), m_value(0), m_id(-1), m_innerSize(aEval.m_expr.lhs().innerSize()) - { - this->operator++(); - } - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - ++m_id; - if(m_id<m_innerSize) - { - Scalar rhsVal = m_rhsEval.coeff(IsRowMajor?m_lhsIter.outer():m_id, - IsRowMajor?m_id:m_lhsIter.outer()); - if(m_lhsIter && m_lhsIter.index()==m_id) - { - m_value = m_functor(m_lhsIter.value(), rhsVal); - ++m_lhsIter; - } - else - m_value = m_functor(Scalar(0),rhsVal); - } - - return *this; - } - - EIGEN_STRONG_INLINE Scalar value() const { eigen_internal_assert(m_id<m_innerSize); return m_value; } - - EIGEN_STRONG_INLINE StorageIndex index() const { return m_id; } - EIGEN_STRONG_INLINE Index outer() const { return m_lhsIter.outer(); } - EIGEN_STRONG_INLINE Index row() const { return IsRowMajor ? m_lhsIter.outer() : m_id; } - EIGEN_STRONG_INLINE Index col() const { return IsRowMajor ? m_id : m_lhsIter.outer(); } - - EIGEN_STRONG_INLINE operator bool() const { return m_id<m_innerSize; } - - protected: - LhsIterator m_lhsIter; - const evaluator<Rhs> &m_rhsEval; - const BinaryOp& m_functor; - Scalar m_value; - StorageIndex m_id; - StorageIndex m_innerSize; - }; - - - enum { - CoeffReadCost = evaluator<Lhs>::CoeffReadCost + evaluator<Rhs>::CoeffReadCost + functor_traits<BinaryOp>::Cost, - Flags = XprType::Flags - }; - - explicit binary_evaluator(const XprType& xpr) - : m_functor(xpr.functor()), - m_lhsImpl(xpr.lhs()), - m_rhsImpl(xpr.rhs()), - m_expr(xpr) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return m_expr.size(); - } - -protected: - const BinaryOp m_functor; - evaluator<Lhs> m_lhsImpl; - evaluator<Rhs> m_rhsImpl; - const XprType &m_expr; -}; - -template<typename T, - typename LhsKind = typename evaluator_traits<typename T::Lhs>::Kind, - typename RhsKind = typename evaluator_traits<typename T::Rhs>::Kind, - typename LhsScalar = typename traits<typename T::Lhs>::Scalar, - typename RhsScalar = typename traits<typename T::Rhs>::Scalar> struct sparse_conjunction_evaluator; - -// "sparse .* sparse" -template<typename T1, typename T2, typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs>, IteratorBased, IteratorBased> - : sparse_conjunction_evaluator<CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs> XprType; - typedef sparse_conjunction_evaluator<XprType> Base; - explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} -}; -// "dense .* sparse" -template<typename T1, typename T2, typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs>, IndexBased, IteratorBased> - : sparse_conjunction_evaluator<CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs> XprType; - typedef sparse_conjunction_evaluator<XprType> Base; - explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} -}; -// "sparse .* dense" -template<typename T1, typename T2, typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs>, IteratorBased, IndexBased> - : sparse_conjunction_evaluator<CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs> XprType; - typedef sparse_conjunction_evaluator<XprType> Base; - explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} -}; - -// "sparse ./ dense" -template<typename T1, typename T2, typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<scalar_quotient_op<T1,T2>, Lhs, Rhs>, IteratorBased, IndexBased> - : sparse_conjunction_evaluator<CwiseBinaryOp<scalar_quotient_op<T1,T2>, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<scalar_quotient_op<T1,T2>, Lhs, Rhs> XprType; - typedef sparse_conjunction_evaluator<XprType> Base; - explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} -}; - -// "sparse && sparse" -template<typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs>, IteratorBased, IteratorBased> - : sparse_conjunction_evaluator<CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs> XprType; - typedef sparse_conjunction_evaluator<XprType> Base; - explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} -}; -// "dense && sparse" -template<typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs>, IndexBased, IteratorBased> - : sparse_conjunction_evaluator<CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs> XprType; - typedef sparse_conjunction_evaluator<XprType> Base; - explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} -}; -// "sparse && dense" -template<typename Lhs, typename Rhs> -struct binary_evaluator<CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs>, IteratorBased, IndexBased> - : sparse_conjunction_evaluator<CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs> > -{ - typedef CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs> XprType; - typedef sparse_conjunction_evaluator<XprType> Base; - explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} -}; - -// "sparse ^ sparse" -template<typename XprType> -struct sparse_conjunction_evaluator<XprType, IteratorBased, IteratorBased> - : evaluator_base<XprType> -{ -protected: - typedef typename XprType::Functor BinaryOp; - typedef typename XprType::Lhs LhsArg; - typedef typename XprType::Rhs RhsArg; - typedef typename evaluator<LhsArg>::InnerIterator LhsIterator; - typedef typename evaluator<RhsArg>::InnerIterator RhsIterator; - typedef typename XprType::StorageIndex StorageIndex; - typedef typename traits<XprType>::Scalar Scalar; -public: - - class InnerIterator - { - public: - - EIGEN_STRONG_INLINE InnerIterator(const sparse_conjunction_evaluator& aEval, Index outer) - : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor) - { - while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index())) - { - if (m_lhsIter.index() < m_rhsIter.index()) - ++m_lhsIter; - else - ++m_rhsIter; - } - } - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - ++m_lhsIter; - ++m_rhsIter; - while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index())) - { - if (m_lhsIter.index() < m_rhsIter.index()) - ++m_lhsIter; - else - ++m_rhsIter; - } - return *this; - } - - EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_lhsIter.value(), m_rhsIter.value()); } - - EIGEN_STRONG_INLINE StorageIndex index() const { return m_lhsIter.index(); } - EIGEN_STRONG_INLINE Index outer() const { return m_lhsIter.outer(); } - EIGEN_STRONG_INLINE Index row() const { return m_lhsIter.row(); } - EIGEN_STRONG_INLINE Index col() const { return m_lhsIter.col(); } - - EIGEN_STRONG_INLINE operator bool() const { return (m_lhsIter && m_rhsIter); } - - protected: - LhsIterator m_lhsIter; - RhsIterator m_rhsIter; - const BinaryOp& m_functor; - }; - - - enum { - CoeffReadCost = evaluator<LhsArg>::CoeffReadCost + evaluator<RhsArg>::CoeffReadCost + functor_traits<BinaryOp>::Cost, - Flags = XprType::Flags - }; - - explicit sparse_conjunction_evaluator(const XprType& xpr) - : m_functor(xpr.functor()), - m_lhsImpl(xpr.lhs()), - m_rhsImpl(xpr.rhs()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return (std::min)(m_lhsImpl.nonZerosEstimate(), m_rhsImpl.nonZerosEstimate()); - } - -protected: - const BinaryOp m_functor; - evaluator<LhsArg> m_lhsImpl; - evaluator<RhsArg> m_rhsImpl; -}; - -// "dense ^ sparse" -template<typename XprType> -struct sparse_conjunction_evaluator<XprType, IndexBased, IteratorBased> - : evaluator_base<XprType> -{ -protected: - typedef typename XprType::Functor BinaryOp; - typedef typename XprType::Lhs LhsArg; - typedef typename XprType::Rhs RhsArg; - typedef evaluator<LhsArg> LhsEvaluator; - typedef typename evaluator<RhsArg>::InnerIterator RhsIterator; - typedef typename XprType::StorageIndex StorageIndex; - typedef typename traits<XprType>::Scalar Scalar; -public: - - class InnerIterator - { - enum { IsRowMajor = (int(RhsArg::Flags)&RowMajorBit)==RowMajorBit }; - - public: - - EIGEN_STRONG_INLINE InnerIterator(const sparse_conjunction_evaluator& aEval, Index outer) - : m_lhsEval(aEval.m_lhsImpl), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor), m_outer(outer) - {} - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - ++m_rhsIter; - return *this; - } - - EIGEN_STRONG_INLINE Scalar value() const - { return m_functor(m_lhsEval.coeff(IsRowMajor?m_outer:m_rhsIter.index(),IsRowMajor?m_rhsIter.index():m_outer), m_rhsIter.value()); } - - EIGEN_STRONG_INLINE StorageIndex index() const { return m_rhsIter.index(); } - EIGEN_STRONG_INLINE Index outer() const { return m_rhsIter.outer(); } - EIGEN_STRONG_INLINE Index row() const { return m_rhsIter.row(); } - EIGEN_STRONG_INLINE Index col() const { return m_rhsIter.col(); } - - EIGEN_STRONG_INLINE operator bool() const { return m_rhsIter; } - - protected: - const LhsEvaluator &m_lhsEval; - RhsIterator m_rhsIter; - const BinaryOp& m_functor; - const Index m_outer; - }; - - - enum { - CoeffReadCost = evaluator<LhsArg>::CoeffReadCost + evaluator<RhsArg>::CoeffReadCost + functor_traits<BinaryOp>::Cost, - Flags = XprType::Flags - }; - - explicit sparse_conjunction_evaluator(const XprType& xpr) - : m_functor(xpr.functor()), - m_lhsImpl(xpr.lhs()), - m_rhsImpl(xpr.rhs()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return m_rhsImpl.nonZerosEstimate(); - } - -protected: - const BinaryOp m_functor; - evaluator<LhsArg> m_lhsImpl; - evaluator<RhsArg> m_rhsImpl; -}; - -// "sparse ^ dense" -template<typename XprType> -struct sparse_conjunction_evaluator<XprType, IteratorBased, IndexBased> - : evaluator_base<XprType> -{ -protected: - typedef typename XprType::Functor BinaryOp; - typedef typename XprType::Lhs LhsArg; - typedef typename XprType::Rhs RhsArg; - typedef typename evaluator<LhsArg>::InnerIterator LhsIterator; - typedef evaluator<RhsArg> RhsEvaluator; - typedef typename XprType::StorageIndex StorageIndex; - typedef typename traits<XprType>::Scalar Scalar; -public: - - class InnerIterator - { - enum { IsRowMajor = (int(LhsArg::Flags)&RowMajorBit)==RowMajorBit }; - - public: - - EIGEN_STRONG_INLINE InnerIterator(const sparse_conjunction_evaluator& aEval, Index outer) - : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsEval(aEval.m_rhsImpl), m_functor(aEval.m_functor), m_outer(outer) - {} - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - ++m_lhsIter; - return *this; - } - - EIGEN_STRONG_INLINE Scalar value() const - { return m_functor(m_lhsIter.value(), - m_rhsEval.coeff(IsRowMajor?m_outer:m_lhsIter.index(),IsRowMajor?m_lhsIter.index():m_outer)); } - - EIGEN_STRONG_INLINE StorageIndex index() const { return m_lhsIter.index(); } - EIGEN_STRONG_INLINE Index outer() const { return m_lhsIter.outer(); } - EIGEN_STRONG_INLINE Index row() const { return m_lhsIter.row(); } - EIGEN_STRONG_INLINE Index col() const { return m_lhsIter.col(); } - - EIGEN_STRONG_INLINE operator bool() const { return m_lhsIter; } - - protected: - LhsIterator m_lhsIter; - const evaluator<RhsArg> &m_rhsEval; - const BinaryOp& m_functor; - const Index m_outer; - }; - - - enum { - CoeffReadCost = evaluator<LhsArg>::CoeffReadCost + evaluator<RhsArg>::CoeffReadCost + functor_traits<BinaryOp>::Cost, - Flags = XprType::Flags - }; - - explicit sparse_conjunction_evaluator(const XprType& xpr) - : m_functor(xpr.functor()), - m_lhsImpl(xpr.lhs()), - m_rhsImpl(xpr.rhs()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return m_lhsImpl.nonZerosEstimate(); - } - -protected: - const BinaryOp m_functor; - evaluator<LhsArg> m_lhsImpl; - evaluator<RhsArg> m_rhsImpl; -}; - -} - -/*************************************************************************** -* Implementation of SparseMatrixBase and SparseCwise functions/operators -***************************************************************************/ - -template<typename Derived> -template<typename OtherDerived> -Derived& SparseMatrixBase<Derived>::operator+=(const EigenBase<OtherDerived> &other) -{ - call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -Derived& SparseMatrixBase<Derived>::operator-=(const EigenBase<OtherDerived> &other) -{ - call_assignment(derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -EIGEN_STRONG_INLINE Derived & -SparseMatrixBase<Derived>::operator-=(const SparseMatrixBase<OtherDerived> &other) -{ - return derived() = derived() - other.derived(); -} - -template<typename Derived> -template<typename OtherDerived> -EIGEN_STRONG_INLINE Derived & -SparseMatrixBase<Derived>::operator+=(const SparseMatrixBase<OtherDerived>& other) -{ - return derived() = derived() + other.derived(); -} - -template<typename Derived> -template<typename OtherDerived> -Derived& SparseMatrixBase<Derived>::operator+=(const DiagonalBase<OtherDerived>& other) -{ - call_assignment_no_alias(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -Derived& SparseMatrixBase<Derived>::operator-=(const DiagonalBase<OtherDerived>& other) -{ - call_assignment_no_alias(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>()); - return derived(); -} - -template<typename Derived> -template<typename OtherDerived> -EIGEN_STRONG_INLINE const typename SparseMatrixBase<Derived>::template CwiseProductDenseReturnType<OtherDerived>::Type -SparseMatrixBase<Derived>::cwiseProduct(const MatrixBase<OtherDerived> &other) const -{ - return typename CwiseProductDenseReturnType<OtherDerived>::Type(derived(), other.derived()); -} - -template<typename DenseDerived, typename SparseDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_sum_op<typename DenseDerived::Scalar,typename SparseDerived::Scalar>, const DenseDerived, const SparseDerived> -operator+(const MatrixBase<DenseDerived> &a, const SparseMatrixBase<SparseDerived> &b) -{ - return CwiseBinaryOp<internal::scalar_sum_op<typename DenseDerived::Scalar,typename SparseDerived::Scalar>, const DenseDerived, const SparseDerived>(a.derived(), b.derived()); -} - -template<typename SparseDerived, typename DenseDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_sum_op<typename SparseDerived::Scalar,typename DenseDerived::Scalar>, const SparseDerived, const DenseDerived> -operator+(const SparseMatrixBase<SparseDerived> &a, const MatrixBase<DenseDerived> &b) -{ - return CwiseBinaryOp<internal::scalar_sum_op<typename SparseDerived::Scalar,typename DenseDerived::Scalar>, const SparseDerived, const DenseDerived>(a.derived(), b.derived()); -} - -template<typename DenseDerived, typename SparseDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_difference_op<typename DenseDerived::Scalar,typename SparseDerived::Scalar>, const DenseDerived, const SparseDerived> -operator-(const MatrixBase<DenseDerived> &a, const SparseMatrixBase<SparseDerived> &b) -{ - return CwiseBinaryOp<internal::scalar_difference_op<typename DenseDerived::Scalar,typename SparseDerived::Scalar>, const DenseDerived, const SparseDerived>(a.derived(), b.derived()); -} - -template<typename SparseDerived, typename DenseDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_difference_op<typename SparseDerived::Scalar,typename DenseDerived::Scalar>, const SparseDerived, const DenseDerived> -operator-(const SparseMatrixBase<SparseDerived> &a, const MatrixBase<DenseDerived> &b) -{ - return CwiseBinaryOp<internal::scalar_difference_op<typename SparseDerived::Scalar,typename DenseDerived::Scalar>, const SparseDerived, const DenseDerived>(a.derived(), b.derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_CWISE_BINARY_OP_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCwiseUnaryOp.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCwiseUnaryOp.h deleted file mode 100644 index df6c28d2..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseCwiseUnaryOp.h +++ /dev/null @@ -1,150 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_CWISE_UNARY_OP_H -#define EIGEN_SPARSE_CWISE_UNARY_OP_H - -namespace Eigen { - -namespace internal { - -template<typename UnaryOp, typename ArgType> -struct unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased> - : public evaluator_base<CwiseUnaryOp<UnaryOp,ArgType> > -{ - public: - typedef CwiseUnaryOp<UnaryOp, ArgType> XprType; - - class InnerIterator; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost, - Flags = XprType::Flags - }; - - explicit unary_evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return m_argImpl.nonZerosEstimate(); - } - - protected: - typedef typename evaluator<ArgType>::InnerIterator EvalIterator; - - const UnaryOp m_functor; - evaluator<ArgType> m_argImpl; -}; - -template<typename UnaryOp, typename ArgType> -class unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::InnerIterator - : public unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::EvalIterator -{ - protected: - typedef typename XprType::Scalar Scalar; - typedef typename unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::EvalIterator Base; - public: - - EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& unaryOp, Index outer) - : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor) - {} - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { Base::operator++(); return *this; } - - EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); } - - protected: - const UnaryOp m_functor; - private: - Scalar& valueRef(); -}; - -template<typename ViewOp, typename ArgType> -struct unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased> - : public evaluator_base<CwiseUnaryView<ViewOp,ArgType> > -{ - public: - typedef CwiseUnaryView<ViewOp, ArgType> XprType; - - class InnerIterator; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<ViewOp>::Cost, - Flags = XprType::Flags - }; - - explicit unary_evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression()) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<ViewOp>::Cost); - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - protected: - typedef typename evaluator<ArgType>::InnerIterator EvalIterator; - - const ViewOp m_functor; - evaluator<ArgType> m_argImpl; -}; - -template<typename ViewOp, typename ArgType> -class unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::InnerIterator - : public unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator -{ - protected: - typedef typename XprType::Scalar Scalar; - typedef typename unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator Base; - public: - - EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& unaryOp, Index outer) - : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor) - {} - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { Base::operator++(); return *this; } - - EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); } - EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(Base::valueRef()); } - - protected: - const ViewOp m_functor; -}; - -} // end namespace internal - -template<typename Derived> -EIGEN_STRONG_INLINE Derived& -SparseMatrixBase<Derived>::operator*=(const Scalar& other) -{ - typedef typename internal::evaluator<Derived>::InnerIterator EvalIterator; - internal::evaluator<Derived> thisEval(derived()); - for (Index j=0; j<outerSize(); ++j) - for (EvalIterator i(thisEval,j); i; ++i) - i.valueRef() *= other; - return derived(); -} - -template<typename Derived> -EIGEN_STRONG_INLINE Derived& -SparseMatrixBase<Derived>::operator/=(const Scalar& other) -{ - typedef typename internal::evaluator<Derived>::InnerIterator EvalIterator; - internal::evaluator<Derived> thisEval(derived()); - for (Index j=0; j<outerSize(); ++j) - for (EvalIterator i(thisEval,j); i; ++i) - i.valueRef() /= other; - return derived(); -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_CWISE_UNARY_OP_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDenseProduct.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDenseProduct.h deleted file mode 100644 index f005a18a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDenseProduct.h +++ /dev/null @@ -1,342 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEDENSEPRODUCT_H -#define EIGEN_SPARSEDENSEPRODUCT_H - -namespace Eigen { - -namespace internal { - -template <> struct product_promote_storage_type<Sparse,Dense, OuterProduct> { typedef Sparse ret; }; -template <> struct product_promote_storage_type<Dense,Sparse, OuterProduct> { typedef Sparse ret; }; - -template<typename SparseLhsType, typename DenseRhsType, typename DenseResType, - typename AlphaType, - int LhsStorageOrder = ((SparseLhsType::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor, - bool ColPerCol = ((DenseRhsType::Flags&RowMajorBit)==0) || DenseRhsType::ColsAtCompileTime==1> -struct sparse_time_dense_product_impl; - -template<typename SparseLhsType, typename DenseRhsType, typename DenseResType> -struct sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType, typename DenseResType::Scalar, RowMajor, true> -{ - typedef typename internal::remove_all<SparseLhsType>::type Lhs; - typedef typename internal::remove_all<DenseRhsType>::type Rhs; - typedef typename internal::remove_all<DenseResType>::type Res; - typedef typename evaluator<Lhs>::InnerIterator LhsInnerIterator; - typedef evaluator<Lhs> LhsEval; - static void run(const SparseLhsType& lhs, const DenseRhsType& rhs, DenseResType& res, const typename Res::Scalar& alpha) - { - LhsEval lhsEval(lhs); - - Index n = lhs.outerSize(); -#ifdef EIGEN_HAS_OPENMP - Eigen::initParallel(); - Index threads = Eigen::nbThreads(); -#endif - - for(Index c=0; c<rhs.cols(); ++c) - { -#ifdef EIGEN_HAS_OPENMP - // This 20000 threshold has been found experimentally on 2D and 3D Poisson problems. - // It basically represents the minimal amount of work to be done to be worth it. - if(threads>1 && lhsEval.nonZerosEstimate() > 20000) - { - #pragma omp parallel for schedule(dynamic,(n+threads*4-1)/(threads*4)) num_threads(threads) - for(Index i=0; i<n; ++i) - processRow(lhsEval,rhs,res,alpha,i,c); - } - else -#endif - { - for(Index i=0; i<n; ++i) - processRow(lhsEval,rhs,res,alpha,i,c); - } - } - } - - static void processRow(const LhsEval& lhsEval, const DenseRhsType& rhs, DenseResType& res, const typename Res::Scalar& alpha, Index i, Index col) - { - typename Res::Scalar tmp(0); - for(LhsInnerIterator it(lhsEval,i); it ;++it) - tmp += it.value() * rhs.coeff(it.index(),col); - res.coeffRef(i,col) += alpha * tmp; - } - -}; - -// FIXME: what is the purpose of the following specialization? Is it for the BlockedSparse format? -// -> let's disable it for now as it is conflicting with generic scalar*matrix and matrix*scalar operators -// template<typename T1, typename T2/*, int _Options, typename _StrideType*/> -// struct ScalarBinaryOpTraits<T1, Ref<T2/*, _Options, _StrideType*/> > -// { -// enum { -// Defined = 1 -// }; -// typedef typename CwiseUnaryOp<scalar_multiple2_op<T1, typename T2::Scalar>, T2>::PlainObject ReturnType; -// }; - -template<typename SparseLhsType, typename DenseRhsType, typename DenseResType, typename AlphaType> -struct sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType, AlphaType, ColMajor, true> -{ - typedef typename internal::remove_all<SparseLhsType>::type Lhs; - typedef typename internal::remove_all<DenseRhsType>::type Rhs; - typedef typename internal::remove_all<DenseResType>::type Res; - typedef evaluator<Lhs> LhsEval; - typedef typename LhsEval::InnerIterator LhsInnerIterator; - static void run(const SparseLhsType& lhs, const DenseRhsType& rhs, DenseResType& res, const AlphaType& alpha) - { - LhsEval lhsEval(lhs); - for(Index c=0; c<rhs.cols(); ++c) - { - for(Index j=0; j<lhs.outerSize(); ++j) - { -// typename Res::Scalar rhs_j = alpha * rhs.coeff(j,c); - typename ScalarBinaryOpTraits<AlphaType, typename Rhs::Scalar>::ReturnType rhs_j(alpha * rhs.coeff(j,c)); - for(LhsInnerIterator it(lhsEval,j); it ;++it) - res.coeffRef(it.index(),c) += it.value() * rhs_j; - } - } - } -}; - -template<typename SparseLhsType, typename DenseRhsType, typename DenseResType> -struct sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType, typename DenseResType::Scalar, RowMajor, false> -{ - typedef typename internal::remove_all<SparseLhsType>::type Lhs; - typedef typename internal::remove_all<DenseRhsType>::type Rhs; - typedef typename internal::remove_all<DenseResType>::type Res; - typedef evaluator<Lhs> LhsEval; - typedef typename LhsEval::InnerIterator LhsInnerIterator; - static void run(const SparseLhsType& lhs, const DenseRhsType& rhs, DenseResType& res, const typename Res::Scalar& alpha) - { - Index n = lhs.rows(); - LhsEval lhsEval(lhs); - -#ifdef EIGEN_HAS_OPENMP - Eigen::initParallel(); - Index threads = Eigen::nbThreads(); - // This 20000 threshold has been found experimentally on 2D and 3D Poisson problems. - // It basically represents the minimal amount of work to be done to be worth it. - if(threads>1 && lhsEval.nonZerosEstimate()*rhs.cols() > 20000) - { - #pragma omp parallel for schedule(dynamic,(n+threads*4-1)/(threads*4)) num_threads(threads) - for(Index i=0; i<n; ++i) - processRow(lhsEval,rhs,res,alpha,i); - } - else -#endif - { - for(Index i=0; i<n; ++i) - processRow(lhsEval, rhs, res, alpha, i); - } - } - - static void processRow(const LhsEval& lhsEval, const DenseRhsType& rhs, Res& res, const typename Res::Scalar& alpha, Index i) - { - typename Res::RowXpr res_i(res.row(i)); - for(LhsInnerIterator it(lhsEval,i); it ;++it) - res_i += (alpha*it.value()) * rhs.row(it.index()); - } -}; - -template<typename SparseLhsType, typename DenseRhsType, typename DenseResType> -struct sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType, typename DenseResType::Scalar, ColMajor, false> -{ - typedef typename internal::remove_all<SparseLhsType>::type Lhs; - typedef typename internal::remove_all<DenseRhsType>::type Rhs; - typedef typename internal::remove_all<DenseResType>::type Res; - typedef typename evaluator<Lhs>::InnerIterator LhsInnerIterator; - static void run(const SparseLhsType& lhs, const DenseRhsType& rhs, DenseResType& res, const typename Res::Scalar& alpha) - { - evaluator<Lhs> lhsEval(lhs); - for(Index j=0; j<lhs.outerSize(); ++j) - { - typename Rhs::ConstRowXpr rhs_j(rhs.row(j)); - for(LhsInnerIterator it(lhsEval,j); it ;++it) - res.row(it.index()) += (alpha*it.value()) * rhs_j; - } - } -}; - -template<typename SparseLhsType, typename DenseRhsType, typename DenseResType,typename AlphaType> -inline void sparse_time_dense_product(const SparseLhsType& lhs, const DenseRhsType& rhs, DenseResType& res, const AlphaType& alpha) -{ - sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType, AlphaType>::run(lhs, rhs, res, alpha); -} - -} // end namespace internal - -namespace internal { - -template<typename Lhs, typename Rhs, int ProductType> -struct generic_product_impl<Lhs, Rhs, SparseShape, DenseShape, ProductType> - : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,SparseShape,DenseShape,ProductType> > -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - template<typename Dest> - static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { - typedef typename nested_eval<Lhs,((Rhs::Flags&RowMajorBit)==0) ? 1 : Rhs::ColsAtCompileTime>::type LhsNested; - typedef typename nested_eval<Rhs,((Lhs::Flags&RowMajorBit)==0) ? 1 : Dynamic>::type RhsNested; - LhsNested lhsNested(lhs); - RhsNested rhsNested(rhs); - internal::sparse_time_dense_product(lhsNested, rhsNested, dst, alpha); - } -}; - -template<typename Lhs, typename Rhs, int ProductType> -struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, DenseShape, ProductType> - : generic_product_impl<Lhs, Rhs, SparseShape, DenseShape, ProductType> -{}; - -template<typename Lhs, typename Rhs, int ProductType> -struct generic_product_impl<Lhs, Rhs, DenseShape, SparseShape, ProductType> - : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,SparseShape,ProductType> > -{ - typedef typename Product<Lhs,Rhs>::Scalar Scalar; - - template<typename Dst> - static void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) - { - typedef typename nested_eval<Lhs,((Rhs::Flags&RowMajorBit)==0) ? Dynamic : 1>::type LhsNested; - typedef typename nested_eval<Rhs,((Lhs::Flags&RowMajorBit)==RowMajorBit) ? 1 : Lhs::RowsAtCompileTime>::type RhsNested; - LhsNested lhsNested(lhs); - RhsNested rhsNested(rhs); - - // transpose everything - Transpose<Dst> dstT(dst); - internal::sparse_time_dense_product(rhsNested.transpose(), lhsNested.transpose(), dstT, alpha); - } -}; - -template<typename Lhs, typename Rhs, int ProductType> -struct generic_product_impl<Lhs, Rhs, DenseShape, SparseTriangularShape, ProductType> - : generic_product_impl<Lhs, Rhs, DenseShape, SparseShape, ProductType> -{}; - -template<typename LhsT, typename RhsT, bool NeedToTranspose> -struct sparse_dense_outer_product_evaluator -{ -protected: - typedef typename conditional<NeedToTranspose,RhsT,LhsT>::type Lhs1; - typedef typename conditional<NeedToTranspose,LhsT,RhsT>::type ActualRhs; - typedef Product<LhsT,RhsT,DefaultProduct> ProdXprType; - - // if the actual left-hand side is a dense vector, - // then build a sparse-view so that we can seamlessly iterate over it. - typedef typename conditional<is_same<typename internal::traits<Lhs1>::StorageKind,Sparse>::value, - Lhs1, SparseView<Lhs1> >::type ActualLhs; - typedef typename conditional<is_same<typename internal::traits<Lhs1>::StorageKind,Sparse>::value, - Lhs1 const&, SparseView<Lhs1> >::type LhsArg; - - typedef evaluator<ActualLhs> LhsEval; - typedef evaluator<ActualRhs> RhsEval; - typedef typename evaluator<ActualLhs>::InnerIterator LhsIterator; - typedef typename ProdXprType::Scalar Scalar; - -public: - enum { - Flags = NeedToTranspose ? RowMajorBit : 0, - CoeffReadCost = HugeCost - }; - - class InnerIterator : public LhsIterator - { - public: - InnerIterator(const sparse_dense_outer_product_evaluator &xprEval, Index outer) - : LhsIterator(xprEval.m_lhsXprImpl, 0), - m_outer(outer), - m_empty(false), - m_factor(get(xprEval.m_rhsXprImpl, outer, typename internal::traits<ActualRhs>::StorageKind() )) - {} - - EIGEN_STRONG_INLINE Index outer() const { return m_outer; } - EIGEN_STRONG_INLINE Index row() const { return NeedToTranspose ? m_outer : LhsIterator::index(); } - EIGEN_STRONG_INLINE Index col() const { return NeedToTranspose ? LhsIterator::index() : m_outer; } - - EIGEN_STRONG_INLINE Scalar value() const { return LhsIterator::value() * m_factor; } - EIGEN_STRONG_INLINE operator bool() const { return LhsIterator::operator bool() && (!m_empty); } - - protected: - Scalar get(const RhsEval &rhs, Index outer, Dense = Dense()) const - { - return rhs.coeff(outer); - } - - Scalar get(const RhsEval &rhs, Index outer, Sparse = Sparse()) - { - typename RhsEval::InnerIterator it(rhs, outer); - if (it && it.index()==0 && it.value()!=Scalar(0)) - return it.value(); - m_empty = true; - return Scalar(0); - } - - Index m_outer; - bool m_empty; - Scalar m_factor; - }; - - sparse_dense_outer_product_evaluator(const Lhs1 &lhs, const ActualRhs &rhs) - : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - // transpose case - sparse_dense_outer_product_evaluator(const ActualRhs &rhs, const Lhs1 &lhs) - : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - -protected: - const LhsArg m_lhs; - evaluator<ActualLhs> m_lhsXprImpl; - evaluator<ActualRhs> m_rhsXprImpl; -}; - -// sparse * dense outer product -template<typename Lhs, typename Rhs> -struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, OuterProduct, SparseShape, DenseShape> - : sparse_dense_outer_product_evaluator<Lhs,Rhs, Lhs::IsRowMajor> -{ - typedef sparse_dense_outer_product_evaluator<Lhs,Rhs, Lhs::IsRowMajor> Base; - - typedef Product<Lhs, Rhs> XprType; - typedef typename XprType::PlainObject PlainObject; - - explicit product_evaluator(const XprType& xpr) - : Base(xpr.lhs(), xpr.rhs()) - {} - -}; - -template<typename Lhs, typename Rhs> -struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, OuterProduct, DenseShape, SparseShape> - : sparse_dense_outer_product_evaluator<Lhs,Rhs, Rhs::IsRowMajor> -{ - typedef sparse_dense_outer_product_evaluator<Lhs,Rhs, Rhs::IsRowMajor> Base; - - typedef Product<Lhs, Rhs> XprType; - typedef typename XprType::PlainObject PlainObject; - - explicit product_evaluator(const XprType& xpr) - : Base(xpr.lhs(), xpr.rhs()) - {} - -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSEDENSEPRODUCT_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDiagonalProduct.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDiagonalProduct.h deleted file mode 100644 index 941c03be..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDiagonalProduct.h +++ /dev/null @@ -1,138 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_DIAGONAL_PRODUCT_H -#define EIGEN_SPARSE_DIAGONAL_PRODUCT_H - -namespace Eigen { - -// The product of a diagonal matrix with a sparse matrix can be easily -// implemented using expression template. -// We have two consider very different cases: -// 1 - diag * row-major sparse -// => each inner vector <=> scalar * sparse vector product -// => so we can reuse CwiseUnaryOp::InnerIterator -// 2 - diag * col-major sparse -// => each inner vector <=> densevector * sparse vector cwise product -// => again, we can reuse specialization of CwiseBinaryOp::InnerIterator -// for that particular case -// The two other cases are symmetric. - -namespace internal { - -enum { - SDP_AsScalarProduct, - SDP_AsCwiseProduct -}; - -template<typename SparseXprType, typename DiagonalCoeffType, int SDP_Tag> -struct sparse_diagonal_product_evaluator; - -template<typename Lhs, typename Rhs, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, ProductTag, DiagonalShape, SparseShape> - : public sparse_diagonal_product_evaluator<Rhs, typename Lhs::DiagonalVectorType, Rhs::Flags&RowMajorBit?SDP_AsScalarProduct:SDP_AsCwiseProduct> -{ - typedef Product<Lhs, Rhs, DefaultProduct> XprType; - enum { CoeffReadCost = HugeCost, Flags = Rhs::Flags&RowMajorBit, Alignment = 0 }; // FIXME CoeffReadCost & Flags - - typedef sparse_diagonal_product_evaluator<Rhs, typename Lhs::DiagonalVectorType, Rhs::Flags&RowMajorBit?SDP_AsScalarProduct:SDP_AsCwiseProduct> Base; - explicit product_evaluator(const XprType& xpr) : Base(xpr.rhs(), xpr.lhs().diagonal()) {} -}; - -template<typename Lhs, typename Rhs, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, ProductTag, SparseShape, DiagonalShape> - : public sparse_diagonal_product_evaluator<Lhs, Transpose<const typename Rhs::DiagonalVectorType>, Lhs::Flags&RowMajorBit?SDP_AsCwiseProduct:SDP_AsScalarProduct> -{ - typedef Product<Lhs, Rhs, DefaultProduct> XprType; - enum { CoeffReadCost = HugeCost, Flags = Lhs::Flags&RowMajorBit, Alignment = 0 }; // FIXME CoeffReadCost & Flags - - typedef sparse_diagonal_product_evaluator<Lhs, Transpose<const typename Rhs::DiagonalVectorType>, Lhs::Flags&RowMajorBit?SDP_AsCwiseProduct:SDP_AsScalarProduct> Base; - explicit product_evaluator(const XprType& xpr) : Base(xpr.lhs(), xpr.rhs().diagonal().transpose()) {} -}; - -template<typename SparseXprType, typename DiagonalCoeffType> -struct sparse_diagonal_product_evaluator<SparseXprType, DiagonalCoeffType, SDP_AsScalarProduct> -{ -protected: - typedef typename evaluator<SparseXprType>::InnerIterator SparseXprInnerIterator; - typedef typename SparseXprType::Scalar Scalar; - -public: - class InnerIterator : public SparseXprInnerIterator - { - public: - InnerIterator(const sparse_diagonal_product_evaluator &xprEval, Index outer) - : SparseXprInnerIterator(xprEval.m_sparseXprImpl, outer), - m_coeff(xprEval.m_diagCoeffImpl.coeff(outer)) - {} - - EIGEN_STRONG_INLINE Scalar value() const { return m_coeff * SparseXprInnerIterator::value(); } - protected: - typename DiagonalCoeffType::Scalar m_coeff; - }; - - sparse_diagonal_product_evaluator(const SparseXprType &sparseXpr, const DiagonalCoeffType &diagCoeff) - : m_sparseXprImpl(sparseXpr), m_diagCoeffImpl(diagCoeff) - {} - - Index nonZerosEstimate() const { return m_sparseXprImpl.nonZerosEstimate(); } - -protected: - evaluator<SparseXprType> m_sparseXprImpl; - evaluator<DiagonalCoeffType> m_diagCoeffImpl; -}; - - -template<typename SparseXprType, typename DiagCoeffType> -struct sparse_diagonal_product_evaluator<SparseXprType, DiagCoeffType, SDP_AsCwiseProduct> -{ - typedef typename SparseXprType::Scalar Scalar; - typedef typename SparseXprType::StorageIndex StorageIndex; - - typedef typename nested_eval<DiagCoeffType,SparseXprType::IsRowMajor ? SparseXprType::RowsAtCompileTime - : SparseXprType::ColsAtCompileTime>::type DiagCoeffNested; - - class InnerIterator - { - typedef typename evaluator<SparseXprType>::InnerIterator SparseXprIter; - public: - InnerIterator(const sparse_diagonal_product_evaluator &xprEval, Index outer) - : m_sparseIter(xprEval.m_sparseXprEval, outer), m_diagCoeffNested(xprEval.m_diagCoeffNested) - {} - - inline Scalar value() const { return m_sparseIter.value() * m_diagCoeffNested.coeff(index()); } - inline StorageIndex index() const { return m_sparseIter.index(); } - inline Index outer() const { return m_sparseIter.outer(); } - inline Index col() const { return SparseXprType::IsRowMajor ? m_sparseIter.index() : m_sparseIter.outer(); } - inline Index row() const { return SparseXprType::IsRowMajor ? m_sparseIter.outer() : m_sparseIter.index(); } - - EIGEN_STRONG_INLINE InnerIterator& operator++() { ++m_sparseIter; return *this; } - inline operator bool() const { return m_sparseIter; } - - protected: - SparseXprIter m_sparseIter; - DiagCoeffNested m_diagCoeffNested; - }; - - sparse_diagonal_product_evaluator(const SparseXprType &sparseXpr, const DiagCoeffType &diagCoeff) - : m_sparseXprEval(sparseXpr), m_diagCoeffNested(diagCoeff) - {} - - Index nonZerosEstimate() const { return m_sparseXprEval.nonZerosEstimate(); } - -protected: - evaluator<SparseXprType> m_sparseXprEval; - DiagCoeffNested m_diagCoeffNested; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_DIAGONAL_PRODUCT_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDot.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDot.h deleted file mode 100644 index 38bc4aa9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseDot.h +++ /dev/null @@ -1,98 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_DOT_H -#define EIGEN_SPARSE_DOT_H - -namespace Eigen { - -template<typename Derived> -template<typename OtherDerived> -typename internal::traits<Derived>::Scalar -SparseMatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived) - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - - eigen_assert(size() == other.size()); - eigen_assert(other.size()>0 && "you are using a non initialized vector"); - - internal::evaluator<Derived> thisEval(derived()); - typename internal::evaluator<Derived>::InnerIterator i(thisEval, 0); - Scalar res(0); - while (i) - { - res += numext::conj(i.value()) * other.coeff(i.index()); - ++i; - } - return res; -} - -template<typename Derived> -template<typename OtherDerived> -typename internal::traits<Derived>::Scalar -SparseMatrixBase<Derived>::dot(const SparseMatrixBase<OtherDerived>& other) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) - EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived) - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - - eigen_assert(size() == other.size()); - - internal::evaluator<Derived> thisEval(derived()); - typename internal::evaluator<Derived>::InnerIterator i(thisEval, 0); - - internal::evaluator<OtherDerived> otherEval(other.derived()); - typename internal::evaluator<OtherDerived>::InnerIterator j(otherEval, 0); - - Scalar res(0); - while (i && j) - { - if (i.index()==j.index()) - { - res += numext::conj(i.value()) * j.value(); - ++i; ++j; - } - else if (i.index()<j.index()) - ++i; - else - ++j; - } - return res; -} - -template<typename Derived> -inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real -SparseMatrixBase<Derived>::squaredNorm() const -{ - return numext::real((*this).cwiseAbs2().sum()); -} - -template<typename Derived> -inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real -SparseMatrixBase<Derived>::norm() const -{ - using std::sqrt; - return sqrt(squaredNorm()); -} - -template<typename Derived> -inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real -SparseMatrixBase<Derived>::blueNorm() const -{ - return internal::blueNorm_impl(*this); -} -} // end namespace Eigen - -#endif // EIGEN_SPARSE_DOT_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseFuzzy.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseFuzzy.h deleted file mode 100644 index 7d47eb94..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseFuzzy.h +++ /dev/null @@ -1,29 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_FUZZY_H -#define EIGEN_SPARSE_FUZZY_H - -namespace Eigen { - -template<typename Derived> -template<typename OtherDerived> -bool SparseMatrixBase<Derived>::isApprox(const SparseMatrixBase<OtherDerived>& other, const RealScalar &prec) const -{ - const typename internal::nested_eval<Derived,2,PlainObject>::type actualA(derived()); - typename internal::conditional<bool(IsRowMajor)==bool(OtherDerived::IsRowMajor), - const typename internal::nested_eval<OtherDerived,2,PlainObject>::type, - const PlainObject>::type actualB(other.derived()); - - return (actualA - actualB).squaredNorm() <= prec * prec * numext::mini(actualA.squaredNorm(), actualB.squaredNorm()); -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_FUZZY_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMap.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMap.h deleted file mode 100644 index f99be337..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMap.h +++ /dev/null @@ -1,305 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_MAP_H -#define EIGEN_SPARSE_MAP_H - -namespace Eigen { - -namespace internal { - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -struct traits<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > - : public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> > -{ - typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType; - typedef traits<PlainObjectType> TraitsBase; - enum { - Flags = TraitsBase::Flags & (~NestByRefBit) - }; -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -struct traits<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > - : public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> > -{ - typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType; - typedef traits<PlainObjectType> TraitsBase; - enum { - Flags = TraitsBase::Flags & (~ (NestByRefBit | LvalueBit)) - }; -}; - -} // end namespace internal - -template<typename Derived, - int Level = internal::accessors_level<Derived>::has_write_access ? WriteAccessors : ReadOnlyAccessors -> class SparseMapBase; - -/** \ingroup SparseCore_Module - * class SparseMapBase - * \brief Common base class for Map and Ref instance of sparse matrix and vector. - */ -template<typename Derived> -class SparseMapBase<Derived,ReadOnlyAccessors> - : public SparseCompressedBase<Derived> -{ - public: - typedef SparseCompressedBase<Derived> Base; - typedef typename Base::Scalar Scalar; - typedef typename Base::StorageIndex StorageIndex; - enum { IsRowMajor = Base::IsRowMajor }; - using Base::operator=; - protected: - - typedef typename internal::conditional< - bool(internal::is_lvalue<Derived>::value), - Scalar *, const Scalar *>::type ScalarPointer; - typedef typename internal::conditional< - bool(internal::is_lvalue<Derived>::value), - StorageIndex *, const StorageIndex *>::type IndexPointer; - - Index m_outerSize; - Index m_innerSize; - Array<StorageIndex,2,1> m_zero_nnz; - IndexPointer m_outerIndex; - IndexPointer m_innerIndices; - ScalarPointer m_values; - IndexPointer m_innerNonZeros; - - public: - - /** \copydoc SparseMatrixBase::rows() */ - inline Index rows() const { return IsRowMajor ? m_outerSize : m_innerSize; } - /** \copydoc SparseMatrixBase::cols() */ - inline Index cols() const { return IsRowMajor ? m_innerSize : m_outerSize; } - /** \copydoc SparseMatrixBase::innerSize() */ - inline Index innerSize() const { return m_innerSize; } - /** \copydoc SparseMatrixBase::outerSize() */ - inline Index outerSize() const { return m_outerSize; } - /** \copydoc SparseCompressedBase::nonZeros */ - inline Index nonZeros() const { return m_zero_nnz[1]; } - - /** \copydoc SparseCompressedBase::isCompressed */ - bool isCompressed() const { return m_innerNonZeros==0; } - - //---------------------------------------- - // direct access interface - /** \copydoc SparseMatrix::valuePtr */ - inline const Scalar* valuePtr() const { return m_values; } - /** \copydoc SparseMatrix::innerIndexPtr */ - inline const StorageIndex* innerIndexPtr() const { return m_innerIndices; } - /** \copydoc SparseMatrix::outerIndexPtr */ - inline const StorageIndex* outerIndexPtr() const { return m_outerIndex; } - /** \copydoc SparseMatrix::innerNonZeroPtr */ - inline const StorageIndex* innerNonZeroPtr() const { return m_innerNonZeros; } - //---------------------------------------- - - /** \copydoc SparseMatrix::coeff */ - inline Scalar coeff(Index row, Index col) const - { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - Index start = m_outerIndex[outer]; - Index end = isCompressed() ? m_outerIndex[outer+1] : start + m_innerNonZeros[outer]; - if (start==end) - return Scalar(0); - else if (end>0 && inner==m_innerIndices[end-1]) - return m_values[end-1]; - // ^^ optimization: let's first check if it is the last coefficient - // (very common in high level algorithms) - - const StorageIndex* r = std::lower_bound(&m_innerIndices[start],&m_innerIndices[end-1],inner); - const Index id = r-&m_innerIndices[0]; - return ((*r==inner) && (id<end)) ? m_values[id] : Scalar(0); - } - - inline SparseMapBase(Index rows, Index cols, Index nnz, IndexPointer outerIndexPtr, IndexPointer innerIndexPtr, - ScalarPointer valuePtr, IndexPointer innerNonZerosPtr = 0) - : m_outerSize(IsRowMajor?rows:cols), m_innerSize(IsRowMajor?cols:rows), m_zero_nnz(0,internal::convert_index<StorageIndex>(nnz)), m_outerIndex(outerIndexPtr), - m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(innerNonZerosPtr) - {} - - // for vectors - inline SparseMapBase(Index size, Index nnz, IndexPointer innerIndexPtr, ScalarPointer valuePtr) - : m_outerSize(1), m_innerSize(size), m_zero_nnz(0,internal::convert_index<StorageIndex>(nnz)), m_outerIndex(m_zero_nnz.data()), - m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(0) - {} - - /** Empty destructor */ - inline ~SparseMapBase() {} - - protected: - inline SparseMapBase() {} -}; - -/** \ingroup SparseCore_Module - * class SparseMapBase - * \brief Common base class for writable Map and Ref instance of sparse matrix and vector. - */ -template<typename Derived> -class SparseMapBase<Derived,WriteAccessors> - : public SparseMapBase<Derived,ReadOnlyAccessors> -{ - typedef MapBase<Derived, ReadOnlyAccessors> ReadOnlyMapBase; - - public: - typedef SparseMapBase<Derived, ReadOnlyAccessors> Base; - typedef typename Base::Scalar Scalar; - typedef typename Base::StorageIndex StorageIndex; - enum { IsRowMajor = Base::IsRowMajor }; - - using Base::operator=; - - public: - - //---------------------------------------- - // direct access interface - using Base::valuePtr; - using Base::innerIndexPtr; - using Base::outerIndexPtr; - using Base::innerNonZeroPtr; - /** \copydoc SparseMatrix::valuePtr */ - inline Scalar* valuePtr() { return Base::m_values; } - /** \copydoc SparseMatrix::innerIndexPtr */ - inline StorageIndex* innerIndexPtr() { return Base::m_innerIndices; } - /** \copydoc SparseMatrix::outerIndexPtr */ - inline StorageIndex* outerIndexPtr() { return Base::m_outerIndex; } - /** \copydoc SparseMatrix::innerNonZeroPtr */ - inline StorageIndex* innerNonZeroPtr() { return Base::m_innerNonZeros; } - //---------------------------------------- - - /** \copydoc SparseMatrix::coeffRef */ - inline Scalar& coeffRef(Index row, Index col) - { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - Index start = Base::m_outerIndex[outer]; - Index end = Base::isCompressed() ? Base::m_outerIndex[outer+1] : start + Base::m_innerNonZeros[outer]; - eigen_assert(end>=start && "you probably called coeffRef on a non finalized matrix"); - eigen_assert(end>start && "coeffRef cannot be called on a zero coefficient"); - StorageIndex* r = std::lower_bound(&Base::m_innerIndices[start],&Base::m_innerIndices[end],inner); - const Index id = r - &Base::m_innerIndices[0]; - eigen_assert((*r==inner) && (id<end) && "coeffRef cannot be called on a zero coefficient"); - return const_cast<Scalar*>(Base::m_values)[id]; - } - - inline SparseMapBase(Index rows, Index cols, Index nnz, StorageIndex* outerIndexPtr, StorageIndex* innerIndexPtr, - Scalar* valuePtr, StorageIndex* innerNonZerosPtr = 0) - : Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr) - {} - - // for vectors - inline SparseMapBase(Index size, Index nnz, StorageIndex* innerIndexPtr, Scalar* valuePtr) - : Base(size, nnz, innerIndexPtr, valuePtr) - {} - - /** Empty destructor */ - inline ~SparseMapBase() {} - - protected: - inline SparseMapBase() {} -}; - -/** \ingroup SparseCore_Module - * - * \brief Specialization of class Map for SparseMatrix-like storage. - * - * \tparam SparseMatrixType the equivalent sparse matrix type of the referenced data, it must be a template instance of class SparseMatrix. - * - * \sa class Map, class SparseMatrix, class Ref<SparseMatrixType,Options> - */ -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -class Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> - : public SparseMapBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > -#else -template<typename SparseMatrixType> -class Map<SparseMatrixType> - : public SparseMapBase<Derived,WriteAccessors> -#endif -{ - public: - typedef SparseMapBase<Map> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(Map) - enum { IsRowMajor = Base::IsRowMajor }; - - public: - - /** Constructs a read-write Map to a sparse matrix of size \a rows x \a cols, containing \a nnz non-zero coefficients, - * stored as a sparse format as defined by the pointers \a outerIndexPtr, \a innerIndexPtr, and \a valuePtr. - * If the optional parameter \a innerNonZerosPtr is the null pointer, then a standard compressed format is assumed. - * - * This constructor is available only if \c SparseMatrixType is non-const. - * - * More details on the expected storage schemes are given in the \ref TutorialSparse "manual pages". - */ - inline Map(Index rows, Index cols, Index nnz, StorageIndex* outerIndexPtr, - StorageIndex* innerIndexPtr, Scalar* valuePtr, StorageIndex* innerNonZerosPtr = 0) - : Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr) - {} -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** Empty destructor */ - inline ~Map() {} -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -class Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> - : public SparseMapBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > -{ - public: - typedef SparseMapBase<Map> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(Map) - enum { IsRowMajor = Base::IsRowMajor }; - - public: -#endif - /** This is the const version of the above constructor. - * - * This constructor is available only if \c SparseMatrixType is const, e.g.: - * \code Map<const SparseMatrix<double> > \endcode - */ - inline Map(Index rows, Index cols, Index nnz, const StorageIndex* outerIndexPtr, - const StorageIndex* innerIndexPtr, const Scalar* valuePtr, const StorageIndex* innerNonZerosPtr = 0) - : Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr) - {} - - /** Empty destructor */ - inline ~Map() {} -}; - -namespace internal { - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -struct evaluator<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > - : evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > -{ - typedef evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base; - typedef Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType; - evaluator() : Base() {} - explicit evaluator(const XprType &mat) : Base(mat) {} -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -struct evaluator<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > - : evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > -{ - typedef evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base; - typedef Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType; - evaluator() : Base() {} - explicit evaluator(const XprType &mat) : Base(mat) {} -}; - -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_MAP_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMatrix.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMatrix.h deleted file mode 100644 index e0910a2c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMatrix.h +++ /dev/null @@ -1,1512 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEMATRIX_H -#define EIGEN_SPARSEMATRIX_H - -namespace Eigen { - -/** \ingroup SparseCore_Module - * - * \class SparseMatrix - * - * \brief A versatible sparse matrix representation - * - * This class implements a more versatile variants of the common \em compressed row/column storage format. - * Each colmun's (resp. row) non zeros are stored as a pair of value with associated row (resp. colmiun) index. - * All the non zeros are stored in a single large buffer. Unlike the \em compressed format, there might be extra - * space in between the nonzeros of two successive colmuns (resp. rows) such that insertion of new non-zero - * can be done with limited memory reallocation and copies. - * - * A call to the function makeCompressed() turns the matrix into the standard \em compressed format - * compatible with many library. - * - * More details on this storage sceheme are given in the \ref TutorialSparse "manual pages". - * - * \tparam _Scalar the scalar type, i.e. the type of the coefficients - * \tparam _Options Union of bit flags controlling the storage scheme. Currently the only possibility - * is ColMajor or RowMajor. The default is 0 which means column-major. - * \tparam _StorageIndex the type of the indices. It has to be a \b signed type (e.g., short, int, std::ptrdiff_t). Default is \c int. - * - * \warning In %Eigen 3.2, the undocumented type \c SparseMatrix::Index was improperly defined as the storage index type (e.g., int), - * whereas it is now (starting from %Eigen 3.3) deprecated and always defined as Eigen::Index. - * Codes making use of \c SparseMatrix::Index, might thus likely have to be changed to use \c SparseMatrix::StorageIndex instead. - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_SPARSEMATRIX_PLUGIN. - */ - -namespace internal { -template<typename _Scalar, int _Options, typename _StorageIndex> -struct traits<SparseMatrix<_Scalar, _Options, _StorageIndex> > -{ - typedef _Scalar Scalar; - typedef _StorageIndex StorageIndex; - typedef Sparse StorageKind; - typedef MatrixXpr XprKind; - enum { - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = Dynamic, - MaxRowsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic, - Flags = _Options | NestByRefBit | LvalueBit | CompressedAccessBit, - SupportedAccessPatterns = InnerRandomAccessPattern - }; -}; - -template<typename _Scalar, int _Options, typename _StorageIndex, int DiagIndex> -struct traits<Diagonal<SparseMatrix<_Scalar, _Options, _StorageIndex>, DiagIndex> > -{ - typedef SparseMatrix<_Scalar, _Options, _StorageIndex> MatrixType; - typedef typename ref_selector<MatrixType>::type MatrixTypeNested; - typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested; - - typedef _Scalar Scalar; - typedef Dense StorageKind; - typedef _StorageIndex StorageIndex; - typedef MatrixXpr XprKind; - - enum { - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = 1, - MaxRowsAtCompileTime = Dynamic, - MaxColsAtCompileTime = 1, - Flags = LvalueBit - }; -}; - -template<typename _Scalar, int _Options, typename _StorageIndex, int DiagIndex> -struct traits<Diagonal<const SparseMatrix<_Scalar, _Options, _StorageIndex>, DiagIndex> > - : public traits<Diagonal<SparseMatrix<_Scalar, _Options, _StorageIndex>, DiagIndex> > -{ - enum { - Flags = 0 - }; -}; - -} // end namespace internal - -template<typename _Scalar, int _Options, typename _StorageIndex> -class SparseMatrix - : public SparseCompressedBase<SparseMatrix<_Scalar, _Options, _StorageIndex> > -{ - typedef SparseCompressedBase<SparseMatrix> Base; - using Base::convert_index; - friend class SparseVector<_Scalar,0,_StorageIndex>; - template<typename, typename, typename, typename, typename> - friend struct internal::Assignment; - public: - using Base::isCompressed; - using Base::nonZeros; - EIGEN_SPARSE_PUBLIC_INTERFACE(SparseMatrix) - using Base::operator+=; - using Base::operator-=; - - typedef MappedSparseMatrix<Scalar,Flags> Map; - typedef Diagonal<SparseMatrix> DiagonalReturnType; - typedef Diagonal<const SparseMatrix> ConstDiagonalReturnType; - typedef typename Base::InnerIterator InnerIterator; - typedef typename Base::ReverseInnerIterator ReverseInnerIterator; - - - using Base::IsRowMajor; - typedef internal::CompressedStorage<Scalar,StorageIndex> Storage; - enum { - Options = _Options - }; - - typedef typename Base::IndexVector IndexVector; - typedef typename Base::ScalarVector ScalarVector; - protected: - typedef SparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> TransposedSparseMatrix; - - Index m_outerSize; - Index m_innerSize; - StorageIndex* m_outerIndex; - StorageIndex* m_innerNonZeros; // optional, if null then the data is compressed - Storage m_data; - - public: - - /** \returns the number of rows of the matrix */ - inline Index rows() const { return IsRowMajor ? m_outerSize : m_innerSize; } - /** \returns the number of columns of the matrix */ - inline Index cols() const { return IsRowMajor ? m_innerSize : m_outerSize; } - - /** \returns the number of rows (resp. columns) of the matrix if the storage order column major (resp. row major) */ - inline Index innerSize() const { return m_innerSize; } - /** \returns the number of columns (resp. rows) of the matrix if the storage order column major (resp. row major) */ - inline Index outerSize() const { return m_outerSize; } - - /** \returns a const pointer to the array of values. - * This function is aimed at interoperability with other libraries. - * \sa innerIndexPtr(), outerIndexPtr() */ - inline const Scalar* valuePtr() const { return m_data.valuePtr(); } - /** \returns a non-const pointer to the array of values. - * This function is aimed at interoperability with other libraries. - * \sa innerIndexPtr(), outerIndexPtr() */ - inline Scalar* valuePtr() { return m_data.valuePtr(); } - - /** \returns a const pointer to the array of inner indices. - * This function is aimed at interoperability with other libraries. - * \sa valuePtr(), outerIndexPtr() */ - inline const StorageIndex* innerIndexPtr() const { return m_data.indexPtr(); } - /** \returns a non-const pointer to the array of inner indices. - * This function is aimed at interoperability with other libraries. - * \sa valuePtr(), outerIndexPtr() */ - inline StorageIndex* innerIndexPtr() { return m_data.indexPtr(); } - - /** \returns a const pointer to the array of the starting positions of the inner vectors. - * This function is aimed at interoperability with other libraries. - * \sa valuePtr(), innerIndexPtr() */ - inline const StorageIndex* outerIndexPtr() const { return m_outerIndex; } - /** \returns a non-const pointer to the array of the starting positions of the inner vectors. - * This function is aimed at interoperability with other libraries. - * \sa valuePtr(), innerIndexPtr() */ - inline StorageIndex* outerIndexPtr() { return m_outerIndex; } - - /** \returns a const pointer to the array of the number of non zeros of the inner vectors. - * This function is aimed at interoperability with other libraries. - * \warning it returns the null pointer 0 in compressed mode */ - inline const StorageIndex* innerNonZeroPtr() const { return m_innerNonZeros; } - /** \returns a non-const pointer to the array of the number of non zeros of the inner vectors. - * This function is aimed at interoperability with other libraries. - * \warning it returns the null pointer 0 in compressed mode */ - inline StorageIndex* innerNonZeroPtr() { return m_innerNonZeros; } - - /** \internal */ - inline Storage& data() { return m_data; } - /** \internal */ - inline const Storage& data() const { return m_data; } - - /** \returns the value of the matrix at position \a i, \a j - * This function returns Scalar(0) if the element is an explicit \em zero */ - inline Scalar coeff(Index row, Index col) const - { - eigen_assert(row>=0 && row<rows() && col>=0 && col<cols()); - - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - Index end = m_innerNonZeros ? m_outerIndex[outer] + m_innerNonZeros[outer] : m_outerIndex[outer+1]; - return m_data.atInRange(m_outerIndex[outer], end, StorageIndex(inner)); - } - - /** \returns a non-const reference to the value of the matrix at position \a i, \a j - * - * If the element does not exist then it is inserted via the insert(Index,Index) function - * which itself turns the matrix into a non compressed form if that was not the case. - * - * This is a O(log(nnz_j)) operation (binary search) plus the cost of insert(Index,Index) - * function if the element does not already exist. - */ - inline Scalar& coeffRef(Index row, Index col) - { - eigen_assert(row>=0 && row<rows() && col>=0 && col<cols()); - - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - Index start = m_outerIndex[outer]; - Index end = m_innerNonZeros ? m_outerIndex[outer] + m_innerNonZeros[outer] : m_outerIndex[outer+1]; - eigen_assert(end>=start && "you probably called coeffRef on a non finalized matrix"); - if(end<=start) - return insert(row,col); - const Index p = m_data.searchLowerIndex(start,end-1,StorageIndex(inner)); - if((p<end) && (m_data.index(p)==inner)) - return m_data.value(p); - else - return insert(row,col); - } - - /** \returns a reference to a novel non zero coefficient with coordinates \a row x \a col. - * The non zero coefficient must \b not already exist. - * - * If the matrix \c *this is in compressed mode, then \c *this is turned into uncompressed - * mode while reserving room for 2 x this->innerSize() non zeros if reserve(Index) has not been called earlier. - * In this case, the insertion procedure is optimized for a \e sequential insertion mode where elements are assumed to be - * inserted by increasing outer-indices. - * - * If that's not the case, then it is strongly recommended to either use a triplet-list to assemble the matrix, or to first - * call reserve(const SizesType &) to reserve the appropriate number of non-zero elements per inner vector. - * - * Assuming memory has been appropriately reserved, this function performs a sorted insertion in O(1) - * if the elements of each inner vector are inserted in increasing inner index order, and in O(nnz_j) for a random insertion. - * - */ - Scalar& insert(Index row, Index col); - - public: - - /** Removes all non zeros but keep allocated memory - * - * This function does not free the currently allocated memory. To release as much as memory as possible, - * call \code mat.data().squeeze(); \endcode after resizing it. - * - * \sa resize(Index,Index), data() - */ - inline void setZero() - { - m_data.clear(); - memset(m_outerIndex, 0, (m_outerSize+1)*sizeof(StorageIndex)); - if(m_innerNonZeros) - memset(m_innerNonZeros, 0, (m_outerSize)*sizeof(StorageIndex)); - } - - /** Preallocates \a reserveSize non zeros. - * - * Precondition: the matrix must be in compressed mode. */ - inline void reserve(Index reserveSize) - { - eigen_assert(isCompressed() && "This function does not make sense in non compressed mode."); - m_data.reserve(reserveSize); - } - - #ifdef EIGEN_PARSED_BY_DOXYGEN - /** Preallocates \a reserveSize[\c j] non zeros for each column (resp. row) \c j. - * - * This function turns the matrix in non-compressed mode. - * - * The type \c SizesType must expose the following interface: - \code - typedef value_type; - const value_type& operator[](i) const; - \endcode - * for \c i in the [0,this->outerSize()[ range. - * Typical choices include std::vector<int>, Eigen::VectorXi, Eigen::VectorXi::Constant, etc. - */ - template<class SizesType> - inline void reserve(const SizesType& reserveSizes); - #else - template<class SizesType> - inline void reserve(const SizesType& reserveSizes, const typename SizesType::value_type& enableif = - #if (!EIGEN_COMP_MSVC) || (EIGEN_COMP_MSVC>=1500) // MSVC 2005 fails to compile with this typename - typename - #endif - SizesType::value_type()) - { - EIGEN_UNUSED_VARIABLE(enableif); - reserveInnerVectors(reserveSizes); - } - #endif // EIGEN_PARSED_BY_DOXYGEN - protected: - template<class SizesType> - inline void reserveInnerVectors(const SizesType& reserveSizes) - { - if(isCompressed()) - { - Index totalReserveSize = 0; - // turn the matrix into non-compressed mode - m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex))); - if (!m_innerNonZeros) internal::throw_std_bad_alloc(); - - // temporarily use m_innerSizes to hold the new starting points. - StorageIndex* newOuterIndex = m_innerNonZeros; - - StorageIndex count = 0; - for(Index j=0; j<m_outerSize; ++j) - { - newOuterIndex[j] = count; - count += reserveSizes[j] + (m_outerIndex[j+1]-m_outerIndex[j]); - totalReserveSize += reserveSizes[j]; - } - m_data.reserve(totalReserveSize); - StorageIndex previousOuterIndex = m_outerIndex[m_outerSize]; - for(Index j=m_outerSize-1; j>=0; --j) - { - StorageIndex innerNNZ = previousOuterIndex - m_outerIndex[j]; - for(Index i=innerNNZ-1; i>=0; --i) - { - m_data.index(newOuterIndex[j]+i) = m_data.index(m_outerIndex[j]+i); - m_data.value(newOuterIndex[j]+i) = m_data.value(m_outerIndex[j]+i); - } - previousOuterIndex = m_outerIndex[j]; - m_outerIndex[j] = newOuterIndex[j]; - m_innerNonZeros[j] = innerNNZ; - } - m_outerIndex[m_outerSize] = m_outerIndex[m_outerSize-1] + m_innerNonZeros[m_outerSize-1] + reserveSizes[m_outerSize-1]; - - m_data.resize(m_outerIndex[m_outerSize]); - } - else - { - StorageIndex* newOuterIndex = static_cast<StorageIndex*>(std::malloc((m_outerSize+1)*sizeof(StorageIndex))); - if (!newOuterIndex) internal::throw_std_bad_alloc(); - - StorageIndex count = 0; - for(Index j=0; j<m_outerSize; ++j) - { - newOuterIndex[j] = count; - StorageIndex alreadyReserved = (m_outerIndex[j+1]-m_outerIndex[j]) - m_innerNonZeros[j]; - StorageIndex toReserve = std::max<StorageIndex>(reserveSizes[j], alreadyReserved); - count += toReserve + m_innerNonZeros[j]; - } - newOuterIndex[m_outerSize] = count; - - m_data.resize(count); - for(Index j=m_outerSize-1; j>=0; --j) - { - Index offset = newOuterIndex[j] - m_outerIndex[j]; - if(offset>0) - { - StorageIndex innerNNZ = m_innerNonZeros[j]; - for(Index i=innerNNZ-1; i>=0; --i) - { - m_data.index(newOuterIndex[j]+i) = m_data.index(m_outerIndex[j]+i); - m_data.value(newOuterIndex[j]+i) = m_data.value(m_outerIndex[j]+i); - } - } - } - - std::swap(m_outerIndex, newOuterIndex); - std::free(newOuterIndex); - } - - } - public: - - //--- low level purely coherent filling --- - - /** \internal - * \returns a reference to the non zero coefficient at position \a row, \a col assuming that: - * - the nonzero does not already exist - * - the new coefficient is the last one according to the storage order - * - * Before filling a given inner vector you must call the statVec(Index) function. - * - * After an insertion session, you should call the finalize() function. - * - * \sa insert, insertBackByOuterInner, startVec */ - inline Scalar& insertBack(Index row, Index col) - { - return insertBackByOuterInner(IsRowMajor?row:col, IsRowMajor?col:row); - } - - /** \internal - * \sa insertBack, startVec */ - inline Scalar& insertBackByOuterInner(Index outer, Index inner) - { - eigen_assert(Index(m_outerIndex[outer+1]) == m_data.size() && "Invalid ordered insertion (invalid outer index)"); - eigen_assert( (m_outerIndex[outer+1]-m_outerIndex[outer]==0 || m_data.index(m_data.size()-1)<inner) && "Invalid ordered insertion (invalid inner index)"); - Index p = m_outerIndex[outer+1]; - ++m_outerIndex[outer+1]; - m_data.append(Scalar(0), inner); - return m_data.value(p); - } - - /** \internal - * \warning use it only if you know what you are doing */ - inline Scalar& insertBackByOuterInnerUnordered(Index outer, Index inner) - { - Index p = m_outerIndex[outer+1]; - ++m_outerIndex[outer+1]; - m_data.append(Scalar(0), inner); - return m_data.value(p); - } - - /** \internal - * \sa insertBack, insertBackByOuterInner */ - inline void startVec(Index outer) - { - eigen_assert(m_outerIndex[outer]==Index(m_data.size()) && "You must call startVec for each inner vector sequentially"); - eigen_assert(m_outerIndex[outer+1]==0 && "You must call startVec for each inner vector sequentially"); - m_outerIndex[outer+1] = m_outerIndex[outer]; - } - - /** \internal - * Must be called after inserting a set of non zero entries using the low level compressed API. - */ - inline void finalize() - { - if(isCompressed()) - { - StorageIndex size = internal::convert_index<StorageIndex>(m_data.size()); - Index i = m_outerSize; - // find the last filled column - while (i>=0 && m_outerIndex[i]==0) - --i; - ++i; - while (i<=m_outerSize) - { - m_outerIndex[i] = size; - ++i; - } - } - } - - //--- - - template<typename InputIterators> - void setFromTriplets(const InputIterators& begin, const InputIterators& end); - - template<typename InputIterators,typename DupFunctor> - void setFromTriplets(const InputIterators& begin, const InputIterators& end, DupFunctor dup_func); - - void sumupDuplicates() { collapseDuplicates(internal::scalar_sum_op<Scalar,Scalar>()); } - - template<typename DupFunctor> - void collapseDuplicates(DupFunctor dup_func = DupFunctor()); - - //--- - - /** \internal - * same as insert(Index,Index) except that the indices are given relative to the storage order */ - Scalar& insertByOuterInner(Index j, Index i) - { - return insert(IsRowMajor ? j : i, IsRowMajor ? i : j); - } - - /** Turns the matrix into the \em compressed format. - */ - void makeCompressed() - { - if(isCompressed()) - return; - - eigen_internal_assert(m_outerIndex!=0 && m_outerSize>0); - - Index oldStart = m_outerIndex[1]; - m_outerIndex[1] = m_innerNonZeros[0]; - for(Index j=1; j<m_outerSize; ++j) - { - Index nextOldStart = m_outerIndex[j+1]; - Index offset = oldStart - m_outerIndex[j]; - if(offset>0) - { - for(Index k=0; k<m_innerNonZeros[j]; ++k) - { - m_data.index(m_outerIndex[j]+k) = m_data.index(oldStart+k); - m_data.value(m_outerIndex[j]+k) = m_data.value(oldStart+k); - } - } - m_outerIndex[j+1] = m_outerIndex[j] + m_innerNonZeros[j]; - oldStart = nextOldStart; - } - std::free(m_innerNonZeros); - m_innerNonZeros = 0; - m_data.resize(m_outerIndex[m_outerSize]); - m_data.squeeze(); - } - - /** Turns the matrix into the uncompressed mode */ - void uncompress() - { - if(m_innerNonZeros != 0) - return; - m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex))); - for (Index i = 0; i < m_outerSize; i++) - { - m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i]; - } - } - - /** Suppresses all nonzeros which are \b much \b smaller \b than \a reference under the tolerance \a epsilon */ - void prune(const Scalar& reference, const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision()) - { - prune(default_prunning_func(reference,epsilon)); - } - - /** Turns the matrix into compressed format, and suppresses all nonzeros which do not satisfy the predicate \a keep. - * The functor type \a KeepFunc must implement the following function: - * \code - * bool operator() (const Index& row, const Index& col, const Scalar& value) const; - * \endcode - * \sa prune(Scalar,RealScalar) - */ - template<typename KeepFunc> - void prune(const KeepFunc& keep = KeepFunc()) - { - // TODO optimize the uncompressed mode to avoid moving and allocating the data twice - makeCompressed(); - - StorageIndex k = 0; - for(Index j=0; j<m_outerSize; ++j) - { - Index previousStart = m_outerIndex[j]; - m_outerIndex[j] = k; - Index end = m_outerIndex[j+1]; - for(Index i=previousStart; i<end; ++i) - { - if(keep(IsRowMajor?j:m_data.index(i), IsRowMajor?m_data.index(i):j, m_data.value(i))) - { - m_data.value(k) = m_data.value(i); - m_data.index(k) = m_data.index(i); - ++k; - } - } - } - m_outerIndex[m_outerSize] = k; - m_data.resize(k,0); - } - - /** Resizes the matrix to a \a rows x \a cols matrix leaving old values untouched. - * - * If the sizes of the matrix are decreased, then the matrix is turned to \b uncompressed-mode - * and the storage of the out of bounds coefficients is kept and reserved. - * Call makeCompressed() to pack the entries and squeeze extra memory. - * - * \sa reserve(), setZero(), makeCompressed() - */ - void conservativeResize(Index rows, Index cols) - { - // No change - if (this->rows() == rows && this->cols() == cols) return; - - // If one dimension is null, then there is nothing to be preserved - if(rows==0 || cols==0) return resize(rows,cols); - - Index innerChange = IsRowMajor ? cols - this->cols() : rows - this->rows(); - Index outerChange = IsRowMajor ? rows - this->rows() : cols - this->cols(); - StorageIndex newInnerSize = convert_index(IsRowMajor ? cols : rows); - - // Deals with inner non zeros - if (m_innerNonZeros) - { - // Resize m_innerNonZeros - StorageIndex *newInnerNonZeros = static_cast<StorageIndex*>(std::realloc(m_innerNonZeros, (m_outerSize + outerChange) * sizeof(StorageIndex))); - if (!newInnerNonZeros) internal::throw_std_bad_alloc(); - m_innerNonZeros = newInnerNonZeros; - - for(Index i=m_outerSize; i<m_outerSize+outerChange; i++) - m_innerNonZeros[i] = 0; - } - else if (innerChange < 0) - { - // Inner size decreased: allocate a new m_innerNonZeros - m_innerNonZeros = static_cast<StorageIndex*>(std::malloc((m_outerSize+outerChange+1) * sizeof(StorageIndex))); - if (!m_innerNonZeros) internal::throw_std_bad_alloc(); - for(Index i = 0; i < m_outerSize; i++) - m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i]; - } - - // Change the m_innerNonZeros in case of a decrease of inner size - if (m_innerNonZeros && innerChange < 0) - { - for(Index i = 0; i < m_outerSize + (std::min)(outerChange, Index(0)); i++) - { - StorageIndex &n = m_innerNonZeros[i]; - StorageIndex start = m_outerIndex[i]; - while (n > 0 && m_data.index(start+n-1) >= newInnerSize) --n; - } - } - - m_innerSize = newInnerSize; - - // Re-allocate outer index structure if necessary - if (outerChange == 0) - return; - - StorageIndex *newOuterIndex = static_cast<StorageIndex*>(std::realloc(m_outerIndex, (m_outerSize + outerChange + 1) * sizeof(StorageIndex))); - if (!newOuterIndex) internal::throw_std_bad_alloc(); - m_outerIndex = newOuterIndex; - if (outerChange > 0) - { - StorageIndex lastIdx = m_outerSize == 0 ? 0 : m_outerIndex[m_outerSize]; - for(Index i=m_outerSize; i<m_outerSize+outerChange+1; i++) - m_outerIndex[i] = lastIdx; - } - m_outerSize += outerChange; - } - - /** Resizes the matrix to a \a rows x \a cols matrix and initializes it to zero. - * - * This function does not free the currently allocated memory. To release as much as memory as possible, - * call \code mat.data().squeeze(); \endcode after resizing it. - * - * \sa reserve(), setZero() - */ - void resize(Index rows, Index cols) - { - const Index outerSize = IsRowMajor ? rows : cols; - m_innerSize = IsRowMajor ? cols : rows; - m_data.clear(); - if (m_outerSize != outerSize || m_outerSize==0) - { - std::free(m_outerIndex); - m_outerIndex = static_cast<StorageIndex*>(std::malloc((outerSize + 1) * sizeof(StorageIndex))); - if (!m_outerIndex) internal::throw_std_bad_alloc(); - - m_outerSize = outerSize; - } - if(m_innerNonZeros) - { - std::free(m_innerNonZeros); - m_innerNonZeros = 0; - } - memset(m_outerIndex, 0, (m_outerSize+1)*sizeof(StorageIndex)); - } - - /** \internal - * Resize the nonzero vector to \a size */ - void resizeNonZeros(Index size) - { - m_data.resize(size); - } - - /** \returns a const expression of the diagonal coefficients. */ - const ConstDiagonalReturnType diagonal() const { return ConstDiagonalReturnType(*this); } - - /** \returns a read-write expression of the diagonal coefficients. - * \warning If the diagonal entries are written, then all diagonal - * entries \b must already exist, otherwise an assertion will be raised. - */ - DiagonalReturnType diagonal() { return DiagonalReturnType(*this); } - - /** Default constructor yielding an empty \c 0 \c x \c 0 matrix */ - inline SparseMatrix() - : m_outerSize(-1), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) - { - check_template_parameters(); - resize(0, 0); - } - - /** Constructs a \a rows \c x \a cols empty matrix */ - inline SparseMatrix(Index rows, Index cols) - : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) - { - check_template_parameters(); - resize(rows, cols); - } - - /** Constructs a sparse matrix from the sparse expression \a other */ - template<typename OtherDerived> - inline SparseMatrix(const SparseMatrixBase<OtherDerived>& other) - : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) - { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - check_template_parameters(); - const bool needToTranspose = (Flags & RowMajorBit) != (internal::evaluator<OtherDerived>::Flags & RowMajorBit); - if (needToTranspose) - *this = other.derived(); - else - { - #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - #endif - internal::call_assignment_no_alias(*this, other.derived()); - } - } - - /** Constructs a sparse matrix from the sparse selfadjoint view \a other */ - template<typename OtherDerived, unsigned int UpLo> - inline SparseMatrix(const SparseSelfAdjointView<OtherDerived, UpLo>& other) - : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) - { - check_template_parameters(); - Base::operator=(other); - } - - /** Copy constructor (it performs a deep copy) */ - inline SparseMatrix(const SparseMatrix& other) - : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) - { - check_template_parameters(); - *this = other.derived(); - } - - /** \brief Copy constructor with in-place evaluation */ - template<typename OtherDerived> - SparseMatrix(const ReturnByValue<OtherDerived>& other) - : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) - { - check_template_parameters(); - initAssignment(other); - other.evalTo(*this); - } - - /** \brief Copy constructor with in-place evaluation */ - template<typename OtherDerived> - explicit SparseMatrix(const DiagonalBase<OtherDerived>& other) - : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) - { - check_template_parameters(); - *this = other.derived(); - } - - /** Swaps the content of two sparse matrices of the same type. - * This is a fast operation that simply swaps the underlying pointers and parameters. */ - inline void swap(SparseMatrix& other) - { - //EIGEN_DBG_SPARSE(std::cout << "SparseMatrix:: swap\n"); - std::swap(m_outerIndex, other.m_outerIndex); - std::swap(m_innerSize, other.m_innerSize); - std::swap(m_outerSize, other.m_outerSize); - std::swap(m_innerNonZeros, other.m_innerNonZeros); - m_data.swap(other.m_data); - } - - /** Sets *this to the identity matrix. - * This function also turns the matrix into compressed mode, and drop any reserved memory. */ - inline void setIdentity() - { - eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES"); - this->m_data.resize(rows()); - Eigen::Map<IndexVector>(this->m_data.indexPtr(), rows()).setLinSpaced(0, StorageIndex(rows()-1)); - Eigen::Map<ScalarVector>(this->m_data.valuePtr(), rows()).setOnes(); - Eigen::Map<IndexVector>(this->m_outerIndex, rows()+1).setLinSpaced(0, StorageIndex(rows())); - std::free(m_innerNonZeros); - m_innerNonZeros = 0; - } - inline SparseMatrix& operator=(const SparseMatrix& other) - { - if (other.isRValue()) - { - swap(other.const_cast_derived()); - } - else if(this!=&other) - { - #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - #endif - initAssignment(other); - if(other.isCompressed()) - { - internal::smart_copy(other.m_outerIndex, other.m_outerIndex + m_outerSize + 1, m_outerIndex); - m_data = other.m_data; - } - else - { - Base::operator=(other); - } - } - return *this; - } - -#ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename OtherDerived> - inline SparseMatrix& operator=(const EigenBase<OtherDerived>& other) - { return Base::operator=(other.derived()); } -#endif // EIGEN_PARSED_BY_DOXYGEN - - template<typename OtherDerived> - EIGEN_DONT_INLINE SparseMatrix& operator=(const SparseMatrixBase<OtherDerived>& other); - - friend std::ostream & operator << (std::ostream & s, const SparseMatrix& m) - { - EIGEN_DBG_SPARSE( - s << "Nonzero entries:\n"; - if(m.isCompressed()) - { - for (Index i=0; i<m.nonZeros(); ++i) - s << "(" << m.m_data.value(i) << "," << m.m_data.index(i) << ") "; - } - else - { - for (Index i=0; i<m.outerSize(); ++i) - { - Index p = m.m_outerIndex[i]; - Index pe = m.m_outerIndex[i]+m.m_innerNonZeros[i]; - Index k=p; - for (; k<pe; ++k) { - s << "(" << m.m_data.value(k) << "," << m.m_data.index(k) << ") "; - } - for (; k<m.m_outerIndex[i+1]; ++k) { - s << "(_,_) "; - } - } - } - s << std::endl; - s << std::endl; - s << "Outer pointers:\n"; - for (Index i=0; i<m.outerSize(); ++i) { - s << m.m_outerIndex[i] << " "; - } - s << " $" << std::endl; - if(!m.isCompressed()) - { - s << "Inner non zeros:\n"; - for (Index i=0; i<m.outerSize(); ++i) { - s << m.m_innerNonZeros[i] << " "; - } - s << " $" << std::endl; - } - s << std::endl; - ); - s << static_cast<const SparseMatrixBase<SparseMatrix>&>(m); - return s; - } - - /** Destructor */ - inline ~SparseMatrix() - { - std::free(m_outerIndex); - std::free(m_innerNonZeros); - } - - /** Overloaded for performance */ - Scalar sum() const; - -# ifdef EIGEN_SPARSEMATRIX_PLUGIN -# include EIGEN_SPARSEMATRIX_PLUGIN -# endif - -protected: - - template<typename Other> - void initAssignment(const Other& other) - { - resize(other.rows(), other.cols()); - if(m_innerNonZeros) - { - std::free(m_innerNonZeros); - m_innerNonZeros = 0; - } - } - - /** \internal - * \sa insert(Index,Index) */ - EIGEN_DONT_INLINE Scalar& insertCompressed(Index row, Index col); - - /** \internal - * A vector object that is equal to 0 everywhere but v at the position i */ - class SingletonVector - { - StorageIndex m_index; - StorageIndex m_value; - public: - typedef StorageIndex value_type; - SingletonVector(Index i, Index v) - : m_index(convert_index(i)), m_value(convert_index(v)) - {} - - StorageIndex operator[](Index i) const { return i==m_index ? m_value : 0; } - }; - - /** \internal - * \sa insert(Index,Index) */ - EIGEN_DONT_INLINE Scalar& insertUncompressed(Index row, Index col); - -public: - /** \internal - * \sa insert(Index,Index) */ - EIGEN_STRONG_INLINE Scalar& insertBackUncompressed(Index row, Index col) - { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(!isCompressed()); - eigen_assert(m_innerNonZeros[outer]<=(m_outerIndex[outer+1] - m_outerIndex[outer])); - - Index p = m_outerIndex[outer] + m_innerNonZeros[outer]++; - m_data.index(p) = convert_index(inner); - return (m_data.value(p) = Scalar(0)); - } -protected: - struct IndexPosPair { - IndexPosPair(Index a_i, Index a_p) : i(a_i), p(a_p) {} - Index i; - Index p; - }; - - /** \internal assign \a diagXpr to the diagonal of \c *this - * There are different strategies: - * 1 - if *this is overwritten (Func==assign_op) or *this is empty, then we can work treat *this as a dense vector expression. - * 2 - otherwise, for each diagonal coeff, - * 2.a - if it already exists, then we update it, - * 2.b - otherwise, if *this is uncompressed and that the current inner-vector has empty room for at least 1 element, then we perform an in-place insertion. - * 2.c - otherwise, we'll have to reallocate and copy everything, so instead of doing so for each new element, it is recorded in a std::vector. - * 3 - at the end, if some entries failed to be inserted in-place, then we alloc a new buffer, copy each chunk at the right position, and insert the new elements. - * - * TODO: some piece of code could be isolated and reused for a general in-place update strategy. - * TODO: if we start to defer the insertion of some elements (i.e., case 2.c executed once), - * then it *might* be better to disable case 2.b since they will have to be copied anyway. - */ - template<typename DiagXpr, typename Func> - void assignDiagonal(const DiagXpr diagXpr, const Func& assignFunc) - { - Index n = diagXpr.size(); - - const bool overwrite = internal::is_same<Func, internal::assign_op<Scalar,Scalar> >::value; - if(overwrite) - { - if((this->rows()!=n) || (this->cols()!=n)) - this->resize(n, n); - } - - if(m_data.size()==0 || overwrite) - { - typedef Array<StorageIndex,Dynamic,1> ArrayXI; - this->makeCompressed(); - this->resizeNonZeros(n); - Eigen::Map<ArrayXI>(this->innerIndexPtr(), n).setLinSpaced(0,StorageIndex(n)-1); - Eigen::Map<ArrayXI>(this->outerIndexPtr(), n+1).setLinSpaced(0,StorageIndex(n)); - Eigen::Map<Array<Scalar,Dynamic,1> > values = this->coeffs(); - values.setZero(); - internal::call_assignment_no_alias(values, diagXpr, assignFunc); - } - else - { - bool isComp = isCompressed(); - internal::evaluator<DiagXpr> diaEval(diagXpr); - std::vector<IndexPosPair> newEntries; - - // 1 - try in-place update and record insertion failures - for(Index i = 0; i<n; ++i) - { - internal::LowerBoundIndex lb = this->lower_bound(i,i); - Index p = lb.value; - if(lb.found) - { - // the coeff already exists - assignFunc.assignCoeff(m_data.value(p), diaEval.coeff(i)); - } - else if((!isComp) && m_innerNonZeros[i] < (m_outerIndex[i+1]-m_outerIndex[i])) - { - // non compressed mode with local room for inserting one element - m_data.moveChunk(p, p+1, m_outerIndex[i]+m_innerNonZeros[i]-p); - m_innerNonZeros[i]++; - m_data.value(p) = Scalar(0); - m_data.index(p) = StorageIndex(i); - assignFunc.assignCoeff(m_data.value(p), diaEval.coeff(i)); - } - else - { - // defer insertion - newEntries.push_back(IndexPosPair(i,p)); - } - } - // 2 - insert deferred entries - Index n_entries = Index(newEntries.size()); - if(n_entries>0) - { - Storage newData(m_data.size()+n_entries); - Index prev_p = 0; - Index prev_i = 0; - for(Index k=0; k<n_entries;++k) - { - Index i = newEntries[k].i; - Index p = newEntries[k].p; - internal::smart_copy(m_data.valuePtr()+prev_p, m_data.valuePtr()+p, newData.valuePtr()+prev_p+k); - internal::smart_copy(m_data.indexPtr()+prev_p, m_data.indexPtr()+p, newData.indexPtr()+prev_p+k); - for(Index j=prev_i;j<i;++j) - m_outerIndex[j+1] += k; - if(!isComp) - m_innerNonZeros[i]++; - prev_p = p; - prev_i = i; - newData.value(p+k) = Scalar(0); - newData.index(p+k) = StorageIndex(i); - assignFunc.assignCoeff(newData.value(p+k), diaEval.coeff(i)); - } - { - internal::smart_copy(m_data.valuePtr()+prev_p, m_data.valuePtr()+m_data.size(), newData.valuePtr()+prev_p+n_entries); - internal::smart_copy(m_data.indexPtr()+prev_p, m_data.indexPtr()+m_data.size(), newData.indexPtr()+prev_p+n_entries); - for(Index j=prev_i+1;j<=m_outerSize;++j) - m_outerIndex[j] += n_entries; - } - m_data.swap(newData); - } - } - } - -private: - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT(NumTraits<StorageIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE); - EIGEN_STATIC_ASSERT((Options&(ColMajor|RowMajor))==Options,INVALID_MATRIX_TEMPLATE_PARAMETERS); - } - - struct default_prunning_func { - default_prunning_func(const Scalar& ref, const RealScalar& eps) : reference(ref), epsilon(eps) {} - inline bool operator() (const Index&, const Index&, const Scalar& value) const - { - return !internal::isMuchSmallerThan(value, reference, epsilon); - } - Scalar reference; - RealScalar epsilon; - }; -}; - -namespace internal { - -template<typename InputIterator, typename SparseMatrixType, typename DupFunctor> -void set_from_triplets(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat, DupFunctor dup_func) -{ - enum { IsRowMajor = SparseMatrixType::IsRowMajor }; - typedef typename SparseMatrixType::Scalar Scalar; - typedef typename SparseMatrixType::StorageIndex StorageIndex; - SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor,StorageIndex> trMat(mat.rows(),mat.cols()); - - if(begin!=end) - { - // pass 1: count the nnz per inner-vector - typename SparseMatrixType::IndexVector wi(trMat.outerSize()); - wi.setZero(); - for(InputIterator it(begin); it!=end; ++it) - { - eigen_assert(it->row()>=0 && it->row()<mat.rows() && it->col()>=0 && it->col()<mat.cols()); - wi(IsRowMajor ? it->col() : it->row())++; - } - - // pass 2: insert all the elements into trMat - trMat.reserve(wi); - for(InputIterator it(begin); it!=end; ++it) - trMat.insertBackUncompressed(it->row(),it->col()) = it->value(); - - // pass 3: - trMat.collapseDuplicates(dup_func); - } - - // pass 4: transposed copy -> implicit sorting - mat = trMat; -} - -} - - -/** Fill the matrix \c *this with the list of \em triplets defined by the iterator range \a begin - \a end. - * - * A \em triplet is a tuple (i,j,value) defining a non-zero element. - * The input list of triplets does not have to be sorted, and can contains duplicated elements. - * In any case, the result is a \b sorted and \b compressed sparse matrix where the duplicates have been summed up. - * This is a \em O(n) operation, with \em n the number of triplet elements. - * The initial contents of \c *this is destroyed. - * The matrix \c *this must be properly resized beforehand using the SparseMatrix(Index,Index) constructor, - * or the resize(Index,Index) method. The sizes are not extracted from the triplet list. - * - * The \a InputIterators value_type must provide the following interface: - * \code - * Scalar value() const; // the value - * Scalar row() const; // the row index i - * Scalar col() const; // the column index j - * \endcode - * See for instance the Eigen::Triplet template class. - * - * Here is a typical usage example: - * \code - typedef Triplet<double> T; - std::vector<T> tripletList; - triplets.reserve(estimation_of_entries); - for(...) - { - // ... - tripletList.push_back(T(i,j,v_ij)); - } - SparseMatrixType m(rows,cols); - m.setFromTriplets(tripletList.begin(), tripletList.end()); - // m is ready to go! - * \endcode - * - * \warning The list of triplets is read multiple times (at least twice). Therefore, it is not recommended to define - * an abstract iterator over a complex data-structure that would be expensive to evaluate. The triplets should rather - * be explicitly stored into a std::vector for instance. - */ -template<typename Scalar, int _Options, typename _StorageIndex> -template<typename InputIterators> -void SparseMatrix<Scalar,_Options,_StorageIndex>::setFromTriplets(const InputIterators& begin, const InputIterators& end) -{ - internal::set_from_triplets<InputIterators, SparseMatrix<Scalar,_Options,_StorageIndex> >(begin, end, *this, internal::scalar_sum_op<Scalar,Scalar>()); -} - -/** The same as setFromTriplets but when duplicates are met the functor \a dup_func is applied: - * \code - * value = dup_func(OldValue, NewValue) - * \endcode - * Here is a C++11 example keeping the latest entry only: - * \code - * mat.setFromTriplets(triplets.begin(), triplets.end(), [] (const Scalar&,const Scalar &b) { return b; }); - * \endcode - */ -template<typename Scalar, int _Options, typename _StorageIndex> -template<typename InputIterators,typename DupFunctor> -void SparseMatrix<Scalar,_Options,_StorageIndex>::setFromTriplets(const InputIterators& begin, const InputIterators& end, DupFunctor dup_func) -{ - internal::set_from_triplets<InputIterators, SparseMatrix<Scalar,_Options,_StorageIndex>, DupFunctor>(begin, end, *this, dup_func); -} - -/** \internal */ -template<typename Scalar, int _Options, typename _StorageIndex> -template<typename DupFunctor> -void SparseMatrix<Scalar,_Options,_StorageIndex>::collapseDuplicates(DupFunctor dup_func) -{ - eigen_assert(!isCompressed()); - // TODO, in practice we should be able to use m_innerNonZeros for that task - IndexVector wi(innerSize()); - wi.fill(-1); - StorageIndex count = 0; - // for each inner-vector, wi[inner_index] will hold the position of first element into the index/value buffers - for(Index j=0; j<outerSize(); ++j) - { - StorageIndex start = count; - Index oldEnd = m_outerIndex[j]+m_innerNonZeros[j]; - for(Index k=m_outerIndex[j]; k<oldEnd; ++k) - { - Index i = m_data.index(k); - if(wi(i)>=start) - { - // we already meet this entry => accumulate it - m_data.value(wi(i)) = dup_func(m_data.value(wi(i)), m_data.value(k)); - } - else - { - m_data.value(count) = m_data.value(k); - m_data.index(count) = m_data.index(k); - wi(i) = count; - ++count; - } - } - m_outerIndex[j] = start; - } - m_outerIndex[m_outerSize] = count; - - // turn the matrix into compressed form - std::free(m_innerNonZeros); - m_innerNonZeros = 0; - m_data.resize(m_outerIndex[m_outerSize]); -} - -template<typename Scalar, int _Options, typename _StorageIndex> -template<typename OtherDerived> -EIGEN_DONT_INLINE SparseMatrix<Scalar,_Options,_StorageIndex>& SparseMatrix<Scalar,_Options,_StorageIndex>::operator=(const SparseMatrixBase<OtherDerived>& other) -{ - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - - #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - #endif - - const bool needToTranspose = (Flags & RowMajorBit) != (internal::evaluator<OtherDerived>::Flags & RowMajorBit); - if (needToTranspose) - { - #ifdef EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN - EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN - #endif - // two passes algorithm: - // 1 - compute the number of coeffs per dest inner vector - // 2 - do the actual copy/eval - // Since each coeff of the rhs has to be evaluated twice, let's evaluate it if needed - typedef typename internal::nested_eval<OtherDerived,2,typename internal::plain_matrix_type<OtherDerived>::type >::type OtherCopy; - typedef typename internal::remove_all<OtherCopy>::type _OtherCopy; - typedef internal::evaluator<_OtherCopy> OtherCopyEval; - OtherCopy otherCopy(other.derived()); - OtherCopyEval otherCopyEval(otherCopy); - - SparseMatrix dest(other.rows(),other.cols()); - Eigen::Map<IndexVector> (dest.m_outerIndex,dest.outerSize()).setZero(); - - // pass 1 - // FIXME the above copy could be merged with that pass - for (Index j=0; j<otherCopy.outerSize(); ++j) - for (typename OtherCopyEval::InnerIterator it(otherCopyEval, j); it; ++it) - ++dest.m_outerIndex[it.index()]; - - // prefix sum - StorageIndex count = 0; - IndexVector positions(dest.outerSize()); - for (Index j=0; j<dest.outerSize(); ++j) - { - StorageIndex tmp = dest.m_outerIndex[j]; - dest.m_outerIndex[j] = count; - positions[j] = count; - count += tmp; - } - dest.m_outerIndex[dest.outerSize()] = count; - // alloc - dest.m_data.resize(count); - // pass 2 - for (StorageIndex j=0; j<otherCopy.outerSize(); ++j) - { - for (typename OtherCopyEval::InnerIterator it(otherCopyEval, j); it; ++it) - { - Index pos = positions[it.index()]++; - dest.m_data.index(pos) = j; - dest.m_data.value(pos) = it.value(); - } - } - this->swap(dest); - return *this; - } - else - { - if(other.isRValue()) - { - initAssignment(other.derived()); - } - // there is no special optimization - return Base::operator=(other.derived()); - } -} - -template<typename _Scalar, int _Options, typename _StorageIndex> -typename SparseMatrix<_Scalar,_Options,_StorageIndex>::Scalar& SparseMatrix<_Scalar,_Options,_StorageIndex>::insert(Index row, Index col) -{ - eigen_assert(row>=0 && row<rows() && col>=0 && col<cols()); - - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - if(isCompressed()) - { - if(nonZeros()==0) - { - // reserve space if not already done - if(m_data.allocatedSize()==0) - m_data.reserve(2*m_innerSize); - - // turn the matrix into non-compressed mode - m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex))); - if(!m_innerNonZeros) internal::throw_std_bad_alloc(); - - memset(m_innerNonZeros, 0, (m_outerSize)*sizeof(StorageIndex)); - - // pack all inner-vectors to the end of the pre-allocated space - // and allocate the entire free-space to the first inner-vector - StorageIndex end = convert_index(m_data.allocatedSize()); - for(Index j=1; j<=m_outerSize; ++j) - m_outerIndex[j] = end; - } - else - { - // turn the matrix into non-compressed mode - m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex))); - if(!m_innerNonZeros) internal::throw_std_bad_alloc(); - for(Index j=0; j<m_outerSize; ++j) - m_innerNonZeros[j] = m_outerIndex[j+1]-m_outerIndex[j]; - } - } - - // check whether we can do a fast "push back" insertion - Index data_end = m_data.allocatedSize(); - - // First case: we are filling a new inner vector which is packed at the end. - // We assume that all remaining inner-vectors are also empty and packed to the end. - if(m_outerIndex[outer]==data_end) - { - eigen_internal_assert(m_innerNonZeros[outer]==0); - - // pack previous empty inner-vectors to end of the used-space - // and allocate the entire free-space to the current inner-vector. - StorageIndex p = convert_index(m_data.size()); - Index j = outer; - while(j>=0 && m_innerNonZeros[j]==0) - m_outerIndex[j--] = p; - - // push back the new element - ++m_innerNonZeros[outer]; - m_data.append(Scalar(0), inner); - - // check for reallocation - if(data_end != m_data.allocatedSize()) - { - // m_data has been reallocated - // -> move remaining inner-vectors back to the end of the free-space - // so that the entire free-space is allocated to the current inner-vector. - eigen_internal_assert(data_end < m_data.allocatedSize()); - StorageIndex new_end = convert_index(m_data.allocatedSize()); - for(Index k=outer+1; k<=m_outerSize; ++k) - if(m_outerIndex[k]==data_end) - m_outerIndex[k] = new_end; - } - return m_data.value(p); - } - - // Second case: the next inner-vector is packed to the end - // and the current inner-vector end match the used-space. - if(m_outerIndex[outer+1]==data_end && m_outerIndex[outer]+m_innerNonZeros[outer]==m_data.size()) - { - eigen_internal_assert(outer+1==m_outerSize || m_innerNonZeros[outer+1]==0); - - // add space for the new element - ++m_innerNonZeros[outer]; - m_data.resize(m_data.size()+1); - - // check for reallocation - if(data_end != m_data.allocatedSize()) - { - // m_data has been reallocated - // -> move remaining inner-vectors back to the end of the free-space - // so that the entire free-space is allocated to the current inner-vector. - eigen_internal_assert(data_end < m_data.allocatedSize()); - StorageIndex new_end = convert_index(m_data.allocatedSize()); - for(Index k=outer+1; k<=m_outerSize; ++k) - if(m_outerIndex[k]==data_end) - m_outerIndex[k] = new_end; - } - - // and insert it at the right position (sorted insertion) - Index startId = m_outerIndex[outer]; - Index p = m_outerIndex[outer]+m_innerNonZeros[outer]-1; - while ( (p > startId) && (m_data.index(p-1) > inner) ) - { - m_data.index(p) = m_data.index(p-1); - m_data.value(p) = m_data.value(p-1); - --p; - } - - m_data.index(p) = convert_index(inner); - return (m_data.value(p) = Scalar(0)); - } - - if(m_data.size() != m_data.allocatedSize()) - { - // make sure the matrix is compatible to random un-compressed insertion: - m_data.resize(m_data.allocatedSize()); - this->reserveInnerVectors(Array<StorageIndex,Dynamic,1>::Constant(m_outerSize, 2)); - } - - return insertUncompressed(row,col); -} - -template<typename _Scalar, int _Options, typename _StorageIndex> -EIGEN_DONT_INLINE typename SparseMatrix<_Scalar,_Options,_StorageIndex>::Scalar& SparseMatrix<_Scalar,_Options,_StorageIndex>::insertUncompressed(Index row, Index col) -{ - eigen_assert(!isCompressed()); - - const Index outer = IsRowMajor ? row : col; - const StorageIndex inner = convert_index(IsRowMajor ? col : row); - - Index room = m_outerIndex[outer+1] - m_outerIndex[outer]; - StorageIndex innerNNZ = m_innerNonZeros[outer]; - if(innerNNZ>=room) - { - // this inner vector is full, we need to reallocate the whole buffer :( - reserve(SingletonVector(outer,std::max<StorageIndex>(2,innerNNZ))); - } - - Index startId = m_outerIndex[outer]; - Index p = startId + m_innerNonZeros[outer]; - while ( (p > startId) && (m_data.index(p-1) > inner) ) - { - m_data.index(p) = m_data.index(p-1); - m_data.value(p) = m_data.value(p-1); - --p; - } - eigen_assert((p<=startId || m_data.index(p-1)!=inner) && "you cannot insert an element that already exists, you must call coeffRef to this end"); - - m_innerNonZeros[outer]++; - - m_data.index(p) = inner; - return (m_data.value(p) = Scalar(0)); -} - -template<typename _Scalar, int _Options, typename _StorageIndex> -EIGEN_DONT_INLINE typename SparseMatrix<_Scalar,_Options,_StorageIndex>::Scalar& SparseMatrix<_Scalar,_Options,_StorageIndex>::insertCompressed(Index row, Index col) -{ - eigen_assert(isCompressed()); - - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - Index previousOuter = outer; - if (m_outerIndex[outer+1]==0) - { - // we start a new inner vector - while (previousOuter>=0 && m_outerIndex[previousOuter]==0) - { - m_outerIndex[previousOuter] = convert_index(m_data.size()); - --previousOuter; - } - m_outerIndex[outer+1] = m_outerIndex[outer]; - } - - // here we have to handle the tricky case where the outerIndex array - // starts with: [ 0 0 0 0 0 1 ...] and we are inserted in, e.g., - // the 2nd inner vector... - bool isLastVec = (!(previousOuter==-1 && m_data.size()!=0)) - && (std::size_t(m_outerIndex[outer+1]) == m_data.size()); - - std::size_t startId = m_outerIndex[outer]; - // FIXME let's make sure sizeof(long int) == sizeof(std::size_t) - std::size_t p = m_outerIndex[outer+1]; - ++m_outerIndex[outer+1]; - - double reallocRatio = 1; - if (m_data.allocatedSize()<=m_data.size()) - { - // if there is no preallocated memory, let's reserve a minimum of 32 elements - if (m_data.size()==0) - { - m_data.reserve(32); - } - else - { - // we need to reallocate the data, to reduce multiple reallocations - // we use a smart resize algorithm based on the current filling ratio - // in addition, we use double to avoid integers overflows - double nnzEstimate = double(m_outerIndex[outer])*double(m_outerSize)/double(outer+1); - reallocRatio = (nnzEstimate-double(m_data.size()))/double(m_data.size()); - // furthermore we bound the realloc ratio to: - // 1) reduce multiple minor realloc when the matrix is almost filled - // 2) avoid to allocate too much memory when the matrix is almost empty - reallocRatio = (std::min)((std::max)(reallocRatio,1.5),8.); - } - } - m_data.resize(m_data.size()+1,reallocRatio); - - if (!isLastVec) - { - if (previousOuter==-1) - { - // oops wrong guess. - // let's correct the outer offsets - for (Index k=0; k<=(outer+1); ++k) - m_outerIndex[k] = 0; - Index k=outer+1; - while(m_outerIndex[k]==0) - m_outerIndex[k++] = 1; - while (k<=m_outerSize && m_outerIndex[k]!=0) - m_outerIndex[k++]++; - p = 0; - --k; - k = m_outerIndex[k]-1; - while (k>0) - { - m_data.index(k) = m_data.index(k-1); - m_data.value(k) = m_data.value(k-1); - k--; - } - } - else - { - // we are not inserting into the last inner vec - // update outer indices: - Index j = outer+2; - while (j<=m_outerSize && m_outerIndex[j]!=0) - m_outerIndex[j++]++; - --j; - // shift data of last vecs: - Index k = m_outerIndex[j]-1; - while (k>=Index(p)) - { - m_data.index(k) = m_data.index(k-1); - m_data.value(k) = m_data.value(k-1); - k--; - } - } - } - - while ( (p > startId) && (m_data.index(p-1) > inner) ) - { - m_data.index(p) = m_data.index(p-1); - m_data.value(p) = m_data.value(p-1); - --p; - } - - m_data.index(p) = inner; - return (m_data.value(p) = Scalar(0)); -} - -namespace internal { - -template<typename _Scalar, int _Options, typename _StorageIndex> -struct evaluator<SparseMatrix<_Scalar,_Options,_StorageIndex> > - : evaluator<SparseCompressedBase<SparseMatrix<_Scalar,_Options,_StorageIndex> > > -{ - typedef evaluator<SparseCompressedBase<SparseMatrix<_Scalar,_Options,_StorageIndex> > > Base; - typedef SparseMatrix<_Scalar,_Options,_StorageIndex> SparseMatrixType; - evaluator() : Base() {} - explicit evaluator(const SparseMatrixType &mat) : Base(mat) {} -}; - -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSEMATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMatrixBase.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMatrixBase.h deleted file mode 100644 index 229449f0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseMatrixBase.h +++ /dev/null @@ -1,398 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEMATRIXBASE_H -#define EIGEN_SPARSEMATRIXBASE_H - -namespace Eigen { - -/** \ingroup SparseCore_Module - * - * \class SparseMatrixBase - * - * \brief Base class of any sparse matrices or sparse expressions - * - * \tparam Derived is the derived type, e.g. a sparse matrix type, or an expression, etc. - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_SPARSEMATRIXBASE_PLUGIN. - */ -template<typename Derived> class SparseMatrixBase - : public EigenBase<Derived> -{ - public: - - typedef typename internal::traits<Derived>::Scalar Scalar; - - /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc. - * - * It is an alias for the Scalar type */ - typedef Scalar value_type; - - typedef typename internal::packet_traits<Scalar>::type PacketScalar; - typedef typename internal::traits<Derived>::StorageKind StorageKind; - - /** The integer type used to \b store indices within a SparseMatrix. - * For a \c SparseMatrix<Scalar,Options,IndexType> it an alias of the third template parameter \c IndexType. */ - typedef typename internal::traits<Derived>::StorageIndex StorageIndex; - - typedef typename internal::add_const_on_value_type_if_arithmetic< - typename internal::packet_traits<Scalar>::type - >::type PacketReturnType; - - typedef SparseMatrixBase StorageBaseType; - - typedef Matrix<StorageIndex,Dynamic,1> IndexVector; - typedef Matrix<Scalar,Dynamic,1> ScalarVector; - - template<typename OtherDerived> - Derived& operator=(const EigenBase<OtherDerived> &other); - - enum { - - RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, - /**< The number of rows at compile-time. This is just a copy of the value provided - * by the \a Derived type. If a value is not known at compile-time, - * it is set to the \a Dynamic constant. - * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */ - - ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, - /**< The number of columns at compile-time. This is just a copy of the value provided - * by the \a Derived type. If a value is not known at compile-time, - * it is set to the \a Dynamic constant. - * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ - - - SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime, - internal::traits<Derived>::ColsAtCompileTime>::ret), - /**< This is equal to the number of coefficients, i.e. the number of - * rows times the number of columns, or to \a Dynamic if this is not - * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ - - MaxRowsAtCompileTime = RowsAtCompileTime, - MaxColsAtCompileTime = ColsAtCompileTime, - - MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime, - MaxColsAtCompileTime>::ret), - - IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1, - /**< This is set to true if either the number of rows or the number of - * columns is known at compile-time to be equal to 1. Indeed, in that case, - * we are dealing with a column-vector (if there is only one column) or with - * a row-vector (if there is only one row). */ - - NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2, - /**< This value is equal to Tensor::NumDimensions, i.e. 0 for scalars, 1 for vectors, - * and 2 for matrices. - */ - - Flags = internal::traits<Derived>::Flags, - /**< This stores expression \ref flags flags which may or may not be inherited by new expressions - * constructed from this one. See the \ref flags "list of flags". - */ - - IsRowMajor = Flags&RowMajorBit ? 1 : 0, - - InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime) - : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), - - #ifndef EIGEN_PARSED_BY_DOXYGEN - _HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC - #endif - }; - - /** \internal the return type of MatrixBase::adjoint() */ - typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Eigen::Transpose<const Derived> >, - Transpose<const Derived> - >::type AdjointReturnType; - typedef Transpose<Derived> TransposeReturnType; - typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType; - - // FIXME storage order do not match evaluator storage order - typedef SparseMatrix<Scalar, Flags&RowMajorBit ? RowMajor : ColMajor, StorageIndex> PlainObject; - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** This is the "real scalar" type; if the \a Scalar type is already real numbers - * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If - * \a Scalar is \a std::complex<T> then RealScalar is \a T. - * - * \sa class NumTraits - */ - typedef typename NumTraits<Scalar>::Real RealScalar; - - /** \internal the return type of coeff() - */ - typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType; - - /** \internal Represents a matrix with all coefficients equal to one another*/ - typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Matrix<Scalar,Dynamic,Dynamic> > ConstantReturnType; - - /** type of the equivalent dense matrix */ - typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> DenseMatrixType; - /** type of the equivalent square matrix */ - typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime), - EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType; - - inline const Derived& derived() const { return *static_cast<const Derived*>(this); } - inline Derived& derived() { return *static_cast<Derived*>(this); } - inline Derived& const_cast_derived() const - { return *static_cast<Derived*>(const_cast<SparseMatrixBase*>(this)); } - - typedef EigenBase<Derived> Base; - -#endif // not EIGEN_PARSED_BY_DOXYGEN - -#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase -#ifdef EIGEN_PARSED_BY_DOXYGEN -#define EIGEN_DOC_UNARY_ADDONS(METHOD,OP) /** <p>This method does not change the sparsity of \c *this: the OP is applied to explicitly stored coefficients only. \sa SparseCompressedBase::coeffs() </p> */ -#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL /** <p> \warning This method returns a read-only expression for any sparse matrices. \sa \ref TutorialSparse_SubMatrices "Sparse block operations" </p> */ -#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND) /** <p> \warning This method returns a read-write expression for COND sparse matrices only. Otherwise, the returned expression is read-only. \sa \ref TutorialSparse_SubMatrices "Sparse block operations" </p> */ -#else -#define EIGEN_DOC_UNARY_ADDONS(X,Y) -#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND) -#endif -# include "../plugins/CommonCwiseUnaryOps.h" -# include "../plugins/CommonCwiseBinaryOps.h" -# include "../plugins/MatrixCwiseUnaryOps.h" -# include "../plugins/MatrixCwiseBinaryOps.h" -# include "../plugins/BlockMethods.h" -# ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN -# include EIGEN_SPARSEMATRIXBASE_PLUGIN -# endif -#undef EIGEN_CURRENT_STORAGE_BASE_CLASS -#undef EIGEN_DOC_UNARY_ADDONS -#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF - - /** \returns the number of rows. \sa cols() */ - inline Index rows() const { return derived().rows(); } - /** \returns the number of columns. \sa rows() */ - inline Index cols() const { return derived().cols(); } - /** \returns the number of coefficients, which is \a rows()*cols(). - * \sa rows(), cols(). */ - inline Index size() const { return rows() * cols(); } - /** \returns true if either the number of rows or the number of columns is equal to 1. - * In other words, this function returns - * \code rows()==1 || cols()==1 \endcode - * \sa rows(), cols(), IsVectorAtCompileTime. */ - inline bool isVector() const { return rows()==1 || cols()==1; } - /** \returns the size of the storage major dimension, - * i.e., the number of columns for a columns major matrix, and the number of rows otherwise */ - Index outerSize() const { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); } - /** \returns the size of the inner dimension according to the storage order, - * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */ - Index innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); } - - bool isRValue() const { return m_isRValue; } - Derived& markAsRValue() { m_isRValue = true; return derived(); } - - SparseMatrixBase() : m_isRValue(false) { /* TODO check flags */ } - - - template<typename OtherDerived> - Derived& operator=(const ReturnByValue<OtherDerived>& other); - - template<typename OtherDerived> - inline Derived& operator=(const SparseMatrixBase<OtherDerived>& other); - - inline Derived& operator=(const Derived& other); - - protected: - - template<typename OtherDerived> - inline Derived& assign(const OtherDerived& other); - - template<typename OtherDerived> - inline void assignGeneric(const OtherDerived& other); - - public: - - friend std::ostream & operator << (std::ostream & s, const SparseMatrixBase& m) - { - typedef typename Derived::Nested Nested; - typedef typename internal::remove_all<Nested>::type NestedCleaned; - - if (Flags&RowMajorBit) - { - Nested nm(m.derived()); - internal::evaluator<NestedCleaned> thisEval(nm); - for (Index row=0; row<nm.outerSize(); ++row) - { - Index col = 0; - for (typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval, row); it; ++it) - { - for ( ; col<it.index(); ++col) - s << "0 "; - s << it.value() << " "; - ++col; - } - for ( ; col<m.cols(); ++col) - s << "0 "; - s << std::endl; - } - } - else - { - Nested nm(m.derived()); - internal::evaluator<NestedCleaned> thisEval(nm); - if (m.cols() == 1) { - Index row = 0; - for (typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval, 0); it; ++it) - { - for ( ; row<it.index(); ++row) - s << "0" << std::endl; - s << it.value() << std::endl; - ++row; - } - for ( ; row<m.rows(); ++row) - s << "0" << std::endl; - } - else - { - SparseMatrix<Scalar, RowMajorBit, StorageIndex> trans = m; - s << static_cast<const SparseMatrixBase<SparseMatrix<Scalar, RowMajorBit, StorageIndex> >&>(trans); - } - } - return s; - } - - template<typename OtherDerived> - Derived& operator+=(const SparseMatrixBase<OtherDerived>& other); - template<typename OtherDerived> - Derived& operator-=(const SparseMatrixBase<OtherDerived>& other); - - template<typename OtherDerived> - Derived& operator+=(const DiagonalBase<OtherDerived>& other); - template<typename OtherDerived> - Derived& operator-=(const DiagonalBase<OtherDerived>& other); - - template<typename OtherDerived> - Derived& operator+=(const EigenBase<OtherDerived> &other); - template<typename OtherDerived> - Derived& operator-=(const EigenBase<OtherDerived> &other); - - Derived& operator*=(const Scalar& other); - Derived& operator/=(const Scalar& other); - - template<typename OtherDerived> struct CwiseProductDenseReturnType { - typedef CwiseBinaryOp<internal::scalar_product_op<typename ScalarBinaryOpTraits< - typename internal::traits<Derived>::Scalar, - typename internal::traits<OtherDerived>::Scalar - >::ReturnType>, - const Derived, - const OtherDerived - > Type; - }; - - template<typename OtherDerived> - EIGEN_STRONG_INLINE const typename CwiseProductDenseReturnType<OtherDerived>::Type - cwiseProduct(const MatrixBase<OtherDerived> &other) const; - - // sparse * diagonal - template<typename OtherDerived> - const Product<Derived,OtherDerived> - operator*(const DiagonalBase<OtherDerived> &other) const - { return Product<Derived,OtherDerived>(derived(), other.derived()); } - - // diagonal * sparse - template<typename OtherDerived> friend - const Product<OtherDerived,Derived> - operator*(const DiagonalBase<OtherDerived> &lhs, const SparseMatrixBase& rhs) - { return Product<OtherDerived,Derived>(lhs.derived(), rhs.derived()); } - - // sparse * sparse - template<typename OtherDerived> - const Product<Derived,OtherDerived,AliasFreeProduct> - operator*(const SparseMatrixBase<OtherDerived> &other) const; - - // sparse * dense - template<typename OtherDerived> - const Product<Derived,OtherDerived> - operator*(const MatrixBase<OtherDerived> &other) const - { return Product<Derived,OtherDerived>(derived(), other.derived()); } - - // dense * sparse - template<typename OtherDerived> friend - const Product<OtherDerived,Derived> - operator*(const MatrixBase<OtherDerived> &lhs, const SparseMatrixBase& rhs) - { return Product<OtherDerived,Derived>(lhs.derived(), rhs.derived()); } - - /** \returns an expression of P H P^-1 where H is the matrix represented by \c *this */ - SparseSymmetricPermutationProduct<Derived,Upper|Lower> twistedBy(const PermutationMatrix<Dynamic,Dynamic,StorageIndex>& perm) const - { - return SparseSymmetricPermutationProduct<Derived,Upper|Lower>(derived(), perm); - } - - template<typename OtherDerived> - Derived& operator*=(const SparseMatrixBase<OtherDerived>& other); - - template<int Mode> - inline const TriangularView<const Derived, Mode> triangularView() const; - - template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SparseSelfAdjointView<Derived, UpLo> Type; }; - template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SparseSelfAdjointView<const Derived, UpLo> Type; }; - - template<unsigned int UpLo> inline - typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const; - template<unsigned int UpLo> inline - typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView(); - - template<typename OtherDerived> Scalar dot(const MatrixBase<OtherDerived>& other) const; - template<typename OtherDerived> Scalar dot(const SparseMatrixBase<OtherDerived>& other) const; - RealScalar squaredNorm() const; - RealScalar norm() const; - RealScalar blueNorm() const; - - TransposeReturnType transpose() { return TransposeReturnType(derived()); } - const ConstTransposeReturnType transpose() const { return ConstTransposeReturnType(derived()); } - const AdjointReturnType adjoint() const { return AdjointReturnType(transpose()); } - - DenseMatrixType toDense() const - { - return DenseMatrixType(derived()); - } - - template<typename OtherDerived> - bool isApprox(const SparseMatrixBase<OtherDerived>& other, - const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; - - template<typename OtherDerived> - bool isApprox(const MatrixBase<OtherDerived>& other, - const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const - { return toDense().isApprox(other,prec); } - - /** \returns the matrix or vector obtained by evaluating this expression. - * - * Notice that in the case of a plain matrix or vector (not an expression) this function just returns - * a const reference, in order to avoid a useless copy. - */ - inline const typename internal::eval<Derived>::type eval() const - { return typename internal::eval<Derived>::type(derived()); } - - Scalar sum() const; - - inline const SparseView<Derived> - pruned(const Scalar& reference = Scalar(0), const RealScalar& epsilon = NumTraits<Scalar>::dummy_precision()) const; - - protected: - - bool m_isRValue; - - static inline StorageIndex convert_index(const Index idx) { - return internal::convert_index<StorageIndex>(idx); - } - private: - template<typename Dest> void evalTo(Dest &) const; -}; - -} // end namespace Eigen - -#endif // EIGEN_SPARSEMATRIXBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparsePermutation.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparsePermutation.h deleted file mode 100644 index ef38357a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparsePermutation.h +++ /dev/null @@ -1,178 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_PERMUTATION_H -#define EIGEN_SPARSE_PERMUTATION_H - -// This file implements sparse * permutation products - -namespace Eigen { - -namespace internal { - -template<typename ExpressionType, int Side, bool Transposed> -struct permutation_matrix_product<ExpressionType, Side, Transposed, SparseShape> -{ - typedef typename nested_eval<ExpressionType, 1>::type MatrixType; - typedef typename remove_all<MatrixType>::type MatrixTypeCleaned; - - typedef typename MatrixTypeCleaned::Scalar Scalar; - typedef typename MatrixTypeCleaned::StorageIndex StorageIndex; - - enum { - SrcStorageOrder = MatrixTypeCleaned::Flags&RowMajorBit ? RowMajor : ColMajor, - MoveOuter = SrcStorageOrder==RowMajor ? Side==OnTheLeft : Side==OnTheRight - }; - - typedef typename internal::conditional<MoveOuter, - SparseMatrix<Scalar,SrcStorageOrder,StorageIndex>, - SparseMatrix<Scalar,int(SrcStorageOrder)==RowMajor?ColMajor:RowMajor,StorageIndex> >::type ReturnType; - - template<typename Dest,typename PermutationType> - static inline void run(Dest& dst, const PermutationType& perm, const ExpressionType& xpr) - { - MatrixType mat(xpr); - if(MoveOuter) - { - SparseMatrix<Scalar,SrcStorageOrder,StorageIndex> tmp(mat.rows(), mat.cols()); - Matrix<StorageIndex,Dynamic,1> sizes(mat.outerSize()); - for(Index j=0; j<mat.outerSize(); ++j) - { - Index jp = perm.indices().coeff(j); - sizes[((Side==OnTheLeft) ^ Transposed) ? jp : j] = StorageIndex(mat.innerVector(((Side==OnTheRight) ^ Transposed) ? jp : j).nonZeros()); - } - tmp.reserve(sizes); - for(Index j=0; j<mat.outerSize(); ++j) - { - Index jp = perm.indices().coeff(j); - Index jsrc = ((Side==OnTheRight) ^ Transposed) ? jp : j; - Index jdst = ((Side==OnTheLeft) ^ Transposed) ? jp : j; - for(typename MatrixTypeCleaned::InnerIterator it(mat,jsrc); it; ++it) - tmp.insertByOuterInner(jdst,it.index()) = it.value(); - } - dst = tmp; - } - else - { - SparseMatrix<Scalar,int(SrcStorageOrder)==RowMajor?ColMajor:RowMajor,StorageIndex> tmp(mat.rows(), mat.cols()); - Matrix<StorageIndex,Dynamic,1> sizes(tmp.outerSize()); - sizes.setZero(); - PermutationMatrix<Dynamic,Dynamic,StorageIndex> perm_cpy; - if((Side==OnTheLeft) ^ Transposed) - perm_cpy = perm; - else - perm_cpy = perm.transpose(); - - for(Index j=0; j<mat.outerSize(); ++j) - for(typename MatrixTypeCleaned::InnerIterator it(mat,j); it; ++it) - sizes[perm_cpy.indices().coeff(it.index())]++; - tmp.reserve(sizes); - for(Index j=0; j<mat.outerSize(); ++j) - for(typename MatrixTypeCleaned::InnerIterator it(mat,j); it; ++it) - tmp.insertByOuterInner(perm_cpy.indices().coeff(it.index()),j) = it.value(); - dst = tmp; - } - } -}; - -} - -namespace internal { - -template <int ProductTag> struct product_promote_storage_type<Sparse, PermutationStorage, ProductTag> { typedef Sparse ret; }; -template <int ProductTag> struct product_promote_storage_type<PermutationStorage, Sparse, ProductTag> { typedef Sparse ret; }; - -// TODO, the following two overloads are only needed to define the right temporary type through -// typename traits<permutation_sparse_matrix_product<Rhs,Lhs,OnTheRight,false> >::ReturnType -// whereas it should be correctly handled by traits<Product<> >::PlainObject - -template<typename Lhs, typename Rhs, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, AliasFreeProduct>, ProductTag, PermutationShape, SparseShape> - : public evaluator<typename permutation_matrix_product<Rhs,OnTheLeft,false,SparseShape>::ReturnType> -{ - typedef Product<Lhs, Rhs, AliasFreeProduct> XprType; - typedef typename permutation_matrix_product<Rhs,OnTheLeft,false,SparseShape>::ReturnType PlainObject; - typedef evaluator<PlainObject> Base; - - enum { - Flags = Base::Flags | EvalBeforeNestingBit - }; - - explicit product_evaluator(const XprType& xpr) - : m_result(xpr.rows(), xpr.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - generic_product_impl<Lhs, Rhs, PermutationShape, SparseShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs()); - } - -protected: - PlainObject m_result; -}; - -template<typename Lhs, typename Rhs, int ProductTag> -struct product_evaluator<Product<Lhs, Rhs, AliasFreeProduct>, ProductTag, SparseShape, PermutationShape > - : public evaluator<typename permutation_matrix_product<Lhs,OnTheRight,false,SparseShape>::ReturnType> -{ - typedef Product<Lhs, Rhs, AliasFreeProduct> XprType; - typedef typename permutation_matrix_product<Lhs,OnTheRight,false,SparseShape>::ReturnType PlainObject; - typedef evaluator<PlainObject> Base; - - enum { - Flags = Base::Flags | EvalBeforeNestingBit - }; - - explicit product_evaluator(const XprType& xpr) - : m_result(xpr.rows(), xpr.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - generic_product_impl<Lhs, Rhs, SparseShape, PermutationShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs()); - } - -protected: - PlainObject m_result; -}; - -} // end namespace internal - -/** \returns the matrix with the permutation applied to the columns - */ -template<typename SparseDerived, typename PermDerived> -inline const Product<SparseDerived, PermDerived, AliasFreeProduct> -operator*(const SparseMatrixBase<SparseDerived>& matrix, const PermutationBase<PermDerived>& perm) -{ return Product<SparseDerived, PermDerived, AliasFreeProduct>(matrix.derived(), perm.derived()); } - -/** \returns the matrix with the permutation applied to the rows - */ -template<typename SparseDerived, typename PermDerived> -inline const Product<PermDerived, SparseDerived, AliasFreeProduct> -operator*( const PermutationBase<PermDerived>& perm, const SparseMatrixBase<SparseDerived>& matrix) -{ return Product<PermDerived, SparseDerived, AliasFreeProduct>(perm.derived(), matrix.derived()); } - - -/** \returns the matrix with the inverse permutation applied to the columns. - */ -template<typename SparseDerived, typename PermutationType> -inline const Product<SparseDerived, Inverse<PermutationType>, AliasFreeProduct> -operator*(const SparseMatrixBase<SparseDerived>& matrix, const InverseImpl<PermutationType, PermutationStorage>& tperm) -{ - return Product<SparseDerived, Inverse<PermutationType>, AliasFreeProduct>(matrix.derived(), tperm.derived()); -} - -/** \returns the matrix with the inverse permutation applied to the rows. - */ -template<typename SparseDerived, typename PermutationType> -inline const Product<Inverse<PermutationType>, SparseDerived, AliasFreeProduct> -operator*(const InverseImpl<PermutationType,PermutationStorage>& tperm, const SparseMatrixBase<SparseDerived>& matrix) -{ - return Product<Inverse<PermutationType>, SparseDerived, AliasFreeProduct>(tperm.derived(), matrix.derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_SELFADJOINTVIEW_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseProduct.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseProduct.h deleted file mode 100644 index c495a739..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseProduct.h +++ /dev/null @@ -1,169 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEPRODUCT_H -#define EIGEN_SPARSEPRODUCT_H - -namespace Eigen { - -/** \returns an expression of the product of two sparse matrices. - * By default a conservative product preserving the symbolic non zeros is performed. - * The automatic pruning of the small values can be achieved by calling the pruned() function - * in which case a totally different product algorithm is employed: - * \code - * C = (A*B).pruned(); // suppress numerical zeros (exact) - * C = (A*B).pruned(ref); - * C = (A*B).pruned(ref,epsilon); - * \endcode - * where \c ref is a meaningful non zero reference value. - * */ -template<typename Derived> -template<typename OtherDerived> -inline const Product<Derived,OtherDerived,AliasFreeProduct> -SparseMatrixBase<Derived>::operator*(const SparseMatrixBase<OtherDerived> &other) const -{ - return Product<Derived,OtherDerived,AliasFreeProduct>(derived(), other.derived()); -} - -namespace internal { - -// sparse * sparse -template<typename Lhs, typename Rhs, int ProductType> -struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> -{ - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) - { - evalTo(dst, lhs, rhs, typename evaluator_traits<Dest>::Shape()); - } - - // dense += sparse * sparse - template<typename Dest,typename ActualLhs> - static void addTo(Dest& dst, const ActualLhs& lhs, const Rhs& rhs, typename enable_if<is_same<typename evaluator_traits<Dest>::Shape,DenseShape>::value,int*>::type* = 0) - { - typedef typename nested_eval<ActualLhs,Dynamic>::type LhsNested; - typedef typename nested_eval<Rhs,Dynamic>::type RhsNested; - LhsNested lhsNested(lhs); - RhsNested rhsNested(rhs); - internal::sparse_sparse_to_dense_product_selector<typename remove_all<LhsNested>::type, - typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst); - } - - // dense -= sparse * sparse - template<typename Dest> - static void subTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, typename enable_if<is_same<typename evaluator_traits<Dest>::Shape,DenseShape>::value,int*>::type* = 0) - { - addTo(dst, -lhs, rhs); - } - -protected: - - // sparse = sparse * sparse - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, SparseShape) - { - typedef typename nested_eval<Lhs,Dynamic>::type LhsNested; - typedef typename nested_eval<Rhs,Dynamic>::type RhsNested; - LhsNested lhsNested(lhs); - RhsNested rhsNested(rhs); - internal::conservative_sparse_sparse_product_selector<typename remove_all<LhsNested>::type, - typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst); - } - - // dense = sparse * sparse - template<typename Dest> - static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, DenseShape) - { - dst.setZero(); - addTo(dst, lhs, rhs); - } -}; - -// sparse * sparse-triangular -template<typename Lhs, typename Rhs, int ProductType> -struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType> - : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> -{}; - -// sparse-triangular * sparse -template<typename Lhs, typename Rhs, int ProductType> -struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType> - : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> -{}; - -// dense = sparse-product (can be sparse*sparse, sparse*perm, etc.) -template< typename DstXprType, typename Lhs, typename Rhs> -struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense> -{ - typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &) - { - Index dstRows = src.rows(); - Index dstCols = src.cols(); - if((dst.rows()!=dstRows) || (dst.cols()!=dstCols)) - dst.resize(dstRows, dstCols); - - generic_product_impl<Lhs, Rhs>::evalTo(dst,src.lhs(),src.rhs()); - } -}; - -// dense += sparse-product (can be sparse*sparse, sparse*perm, etc.) -template< typename DstXprType, typename Lhs, typename Rhs> -struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::add_assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense> -{ - typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &) - { - generic_product_impl<Lhs, Rhs>::addTo(dst,src.lhs(),src.rhs()); - } -}; - -// dense -= sparse-product (can be sparse*sparse, sparse*perm, etc.) -template< typename DstXprType, typename Lhs, typename Rhs> -struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::sub_assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense> -{ - typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType; - static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &) - { - generic_product_impl<Lhs, Rhs>::subTo(dst,src.lhs(),src.rhs()); - } -}; - -template<typename Lhs, typename Rhs, int Options> -struct unary_evaluator<SparseView<Product<Lhs, Rhs, Options> >, IteratorBased> - : public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject> -{ - typedef SparseView<Product<Lhs, Rhs, Options> > XprType; - typedef typename XprType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - - explicit unary_evaluator(const XprType& xpr) - : m_result(xpr.rows(), xpr.cols()) - { - using std::abs; - ::new (static_cast<Base*>(this)) Base(m_result); - typedef typename nested_eval<Lhs,Dynamic>::type LhsNested; - typedef typename nested_eval<Rhs,Dynamic>::type RhsNested; - LhsNested lhsNested(xpr.nestedExpression().lhs()); - RhsNested rhsNested(xpr.nestedExpression().rhs()); - - internal::sparse_sparse_product_with_pruning_selector<typename remove_all<LhsNested>::type, - typename remove_all<RhsNested>::type, PlainObject>::run(lhsNested,rhsNested,m_result, - abs(xpr.reference())*xpr.epsilon()); - } - -protected: - PlainObject m_result; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSEPRODUCT_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseRedux.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseRedux.h deleted file mode 100644 index 45877496..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseRedux.h +++ /dev/null @@ -1,49 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEREDUX_H -#define EIGEN_SPARSEREDUX_H - -namespace Eigen { - -template<typename Derived> -typename internal::traits<Derived>::Scalar -SparseMatrixBase<Derived>::sum() const -{ - eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); - Scalar res(0); - internal::evaluator<Derived> thisEval(derived()); - for (Index j=0; j<outerSize(); ++j) - for (typename internal::evaluator<Derived>::InnerIterator iter(thisEval,j); iter; ++iter) - res += iter.value(); - return res; -} - -template<typename _Scalar, int _Options, typename _Index> -typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar -SparseMatrix<_Scalar,_Options,_Index>::sum() const -{ - eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); - if(this->isCompressed()) - return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum(); - else - return Base::sum(); -} - -template<typename _Scalar, int _Options, typename _Index> -typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar -SparseVector<_Scalar,_Options,_Index>::sum() const -{ - eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); - return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum(); -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSEREDUX_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseRef.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseRef.h deleted file mode 100644 index 748f87d6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseRef.h +++ /dev/null @@ -1,397 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_REF_H -#define EIGEN_SPARSE_REF_H - -namespace Eigen { - -enum { - StandardCompressedFormat = 2 /**< used by Ref<SparseMatrix> to specify whether the input storage must be in standard compressed form */ -}; - -namespace internal { - -template<typename Derived> class SparseRefBase; - -template<typename MatScalar, int MatOptions, typename MatIndex, int _Options, typename _StrideType> -struct traits<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> > - : public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> > -{ - typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType; - enum { - Options = _Options, - Flags = traits<PlainObjectType>::Flags | CompressedAccessBit | NestByRefBit - }; - - template<typename Derived> struct match { - enum { - StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime || ((PlainObjectType::Flags&RowMajorBit)==(Derived::Flags&RowMajorBit)), - MatchAtCompileTime = (Derived::Flags&CompressedAccessBit) && StorageOrderMatch - }; - typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type; - }; - -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int _Options, typename _StrideType> -struct traits<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> > - : public traits<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> > -{ - enum { - Flags = (traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >::Flags | CompressedAccessBit | NestByRefBit) & ~LvalueBit - }; -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int _Options, typename _StrideType> -struct traits<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> > - : public traits<SparseVector<MatScalar,MatOptions,MatIndex> > -{ - typedef SparseVector<MatScalar,MatOptions,MatIndex> PlainObjectType; - enum { - Options = _Options, - Flags = traits<PlainObjectType>::Flags | CompressedAccessBit | NestByRefBit - }; - - template<typename Derived> struct match { - enum { - MatchAtCompileTime = (Derived::Flags&CompressedAccessBit) && Derived::IsVectorAtCompileTime - }; - typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type; - }; - -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int _Options, typename _StrideType> -struct traits<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> > - : public traits<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, _Options, _StrideType> > -{ - enum { - Flags = (traits<SparseVector<MatScalar,MatOptions,MatIndex> >::Flags | CompressedAccessBit | NestByRefBit) & ~LvalueBit - }; -}; - -template<typename Derived> -struct traits<SparseRefBase<Derived> > : public traits<Derived> {}; - -template<typename Derived> class SparseRefBase - : public SparseMapBase<Derived> -{ -public: - - typedef SparseMapBase<Derived> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(SparseRefBase) - - SparseRefBase() - : Base(RowsAtCompileTime==Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==Dynamic?0:ColsAtCompileTime, 0, 0, 0, 0, 0) - {} - -protected: - - template<typename Expression> - void construct(Expression& expr) - { - if(expr.outerIndexPtr()==0) - ::new (static_cast<Base*>(this)) Base(expr.size(), expr.nonZeros(), expr.innerIndexPtr(), expr.valuePtr()); - else - ::new (static_cast<Base*>(this)) Base(expr.rows(), expr.cols(), expr.nonZeros(), expr.outerIndexPtr(), expr.innerIndexPtr(), expr.valuePtr(), expr.innerNonZeroPtr()); - } -}; - -} // namespace internal - - -/** - * \ingroup SparseCore_Module - * - * \brief A sparse matrix expression referencing an existing sparse expression - * - * \tparam SparseMatrixType the equivalent sparse matrix type of the referenced data, it must be a template instance of class SparseMatrix. - * \tparam Options specifies whether the a standard compressed format is required \c Options is \c #StandardCompressedFormat, or \c 0. - * The default is \c 0. - * - * \sa class Ref - */ -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -class Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > - : public internal::SparseRefBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > > -#else -template<typename SparseMatrixType, int Options> -class Ref<SparseMatrixType, Options> - : public SparseMapBase<Derived,WriteAccessors> // yes, that's weird to use Derived here, but that works! -#endif -{ - typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType; - typedef internal::traits<Ref> Traits; - template<int OtherOptions> - inline Ref(const SparseMatrix<MatScalar,OtherOptions,MatIndex>& expr); - template<int OtherOptions> - inline Ref(const MappedSparseMatrix<MatScalar,OtherOptions,MatIndex>& expr); - public: - - typedef internal::SparseRefBase<Ref> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(Ref) - - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<int OtherOptions> - inline Ref(SparseMatrix<MatScalar,OtherOptions,MatIndex>& expr) - { - EIGEN_STATIC_ASSERT(bool(Traits::template match<SparseMatrix<MatScalar,OtherOptions,MatIndex> >::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); - eigen_assert( ((Options & int(StandardCompressedFormat))==0) || (expr.isCompressed()) ); - Base::construct(expr.derived()); - } - - template<int OtherOptions> - inline Ref(MappedSparseMatrix<MatScalar,OtherOptions,MatIndex>& expr) - { - EIGEN_STATIC_ASSERT(bool(Traits::template match<SparseMatrix<MatScalar,OtherOptions,MatIndex> >::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); - eigen_assert( ((Options & int(StandardCompressedFormat))==0) || (expr.isCompressed()) ); - Base::construct(expr.derived()); - } - - template<typename Derived> - inline Ref(const SparseCompressedBase<Derived>& expr) - #else - /** Implicit constructor from any sparse expression (2D matrix or 1D vector) */ - template<typename Derived> - inline Ref(SparseCompressedBase<Derived>& expr) - #endif - { - EIGEN_STATIC_ASSERT(bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); - EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); - eigen_assert( ((Options & int(StandardCompressedFormat))==0) || (expr.isCompressed()) ); - Base::construct(expr.const_cast_derived()); - } -}; - -// this is the const ref version -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -class Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> - : public internal::SparseRefBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > -{ - typedef SparseMatrix<MatScalar,MatOptions,MatIndex> TPlainObjectType; - typedef internal::traits<Ref> Traits; - public: - - typedef internal::SparseRefBase<Ref> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(Ref) - - template<typename Derived> - inline Ref(const SparseMatrixBase<Derived>& expr) : m_hasCopy(false) - { - construct(expr.derived(), typename Traits::template match<Derived>::type()); - } - - inline Ref(const Ref& other) : Base(other), m_hasCopy(false) { - // copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy - } - - template<typename OtherRef> - inline Ref(const RefBase<OtherRef>& other) : m_hasCopy(false) { - construct(other.derived(), typename Traits::template match<OtherRef>::type()); - } - - ~Ref() { - if(m_hasCopy) { - TPlainObjectType* obj = reinterpret_cast<TPlainObjectType*>(&m_storage); - obj->~TPlainObjectType(); - } - } - - protected: - - template<typename Expression> - void construct(const Expression& expr,internal::true_type) - { - if((Options & int(StandardCompressedFormat)) && (!expr.isCompressed())) - { - TPlainObjectType* obj = reinterpret_cast<TPlainObjectType*>(&m_storage); - ::new (obj) TPlainObjectType(expr); - m_hasCopy = true; - Base::construct(*obj); - } - else - { - Base::construct(expr); - } - } - - template<typename Expression> - void construct(const Expression& expr, internal::false_type) - { - TPlainObjectType* obj = reinterpret_cast<TPlainObjectType*>(&m_storage); - ::new (obj) TPlainObjectType(expr); - m_hasCopy = true; - Base::construct(*obj); - } - - protected: - typename internal::aligned_storage<sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage; - bool m_hasCopy; -}; - - - -/** - * \ingroup SparseCore_Module - * - * \brief A sparse vector expression referencing an existing sparse vector expression - * - * \tparam SparseVectorType the equivalent sparse vector type of the referenced data, it must be a template instance of class SparseVector. - * - * \sa class Ref - */ -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -class Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType > - : public internal::SparseRefBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType > > -#else -template<typename SparseVectorType> -class Ref<SparseVectorType> - : public SparseMapBase<Derived,WriteAccessors> -#endif -{ - typedef SparseVector<MatScalar,MatOptions,MatIndex> PlainObjectType; - typedef internal::traits<Ref> Traits; - template<int OtherOptions> - inline Ref(const SparseVector<MatScalar,OtherOptions,MatIndex>& expr); - public: - - typedef internal::SparseRefBase<Ref> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(Ref) - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<int OtherOptions> - inline Ref(SparseVector<MatScalar,OtherOptions,MatIndex>& expr) - { - EIGEN_STATIC_ASSERT(bool(Traits::template match<SparseVector<MatScalar,OtherOptions,MatIndex> >::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); - Base::construct(expr.derived()); - } - - template<typename Derived> - inline Ref(const SparseCompressedBase<Derived>& expr) - #else - /** Implicit constructor from any 1D sparse vector expression */ - template<typename Derived> - inline Ref(SparseCompressedBase<Derived>& expr) - #endif - { - EIGEN_STATIC_ASSERT(bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); - EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); - Base::construct(expr.const_cast_derived()); - } -}; - -// this is the const ref version -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -class Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> - : public internal::SparseRefBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > -{ - typedef SparseVector<MatScalar,MatOptions,MatIndex> TPlainObjectType; - typedef internal::traits<Ref> Traits; - public: - - typedef internal::SparseRefBase<Ref> Base; - EIGEN_SPARSE_PUBLIC_INTERFACE(Ref) - - template<typename Derived> - inline Ref(const SparseMatrixBase<Derived>& expr) : m_hasCopy(false) - { - construct(expr.derived(), typename Traits::template match<Derived>::type()); - } - - inline Ref(const Ref& other) : Base(other), m_hasCopy(false) { - // copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy - } - - template<typename OtherRef> - inline Ref(const RefBase<OtherRef>& other) : m_hasCopy(false) { - construct(other.derived(), typename Traits::template match<OtherRef>::type()); - } - - ~Ref() { - if(m_hasCopy) { - TPlainObjectType* obj = reinterpret_cast<TPlainObjectType*>(&m_storage); - obj->~TPlainObjectType(); - } - } - - protected: - - template<typename Expression> - void construct(const Expression& expr,internal::true_type) - { - Base::construct(expr); - } - - template<typename Expression> - void construct(const Expression& expr, internal::false_type) - { - TPlainObjectType* obj = reinterpret_cast<TPlainObjectType*>(&m_storage); - ::new (obj) TPlainObjectType(expr); - m_hasCopy = true; - Base::construct(*obj); - } - - protected: - typename internal::aligned_storage<sizeof(TPlainObjectType), EIGEN_ALIGNOF(TPlainObjectType)>::type m_storage; - bool m_hasCopy; -}; - -namespace internal { - -// FIXME shall we introduce a general evaluatior_ref that we can specialize for any sparse object once, and thus remove this copy-pasta thing... - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -struct evaluator<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > - : evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > -{ - typedef evaluator<SparseCompressedBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base; - typedef Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType; - evaluator() : Base() {} - explicit evaluator(const XprType &mat) : Base(mat) {} -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -struct evaluator<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > - : evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > -{ - typedef evaluator<SparseCompressedBase<Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base; - typedef Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType; - evaluator() : Base() {} - explicit evaluator(const XprType &mat) : Base(mat) {} -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -struct evaluator<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > - : evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > -{ - typedef evaluator<SparseCompressedBase<Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base; - typedef Ref<SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType; - evaluator() : Base() {} - explicit evaluator(const XprType &mat) : Base(mat) {} -}; - -template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> -struct evaluator<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > - : evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > -{ - typedef evaluator<SparseCompressedBase<Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base; - typedef Ref<const SparseVector<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType; - evaluator() : Base() {} - explicit evaluator(const XprType &mat) : Base(mat) {} -}; - -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_REF_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSelfAdjointView.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSelfAdjointView.h deleted file mode 100644 index 65611b3d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSelfAdjointView.h +++ /dev/null @@ -1,656 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_SELFADJOINTVIEW_H -#define EIGEN_SPARSE_SELFADJOINTVIEW_H - -namespace Eigen { - -/** \ingroup SparseCore_Module - * \class SparseSelfAdjointView - * - * \brief Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix. - * - * \param MatrixType the type of the dense matrix storing the coefficients - * \param Mode can be either \c #Lower or \c #Upper - * - * This class is an expression of a sefladjoint matrix from a triangular part of a matrix - * with given dense storage of the coefficients. It is the return type of MatrixBase::selfadjointView() - * and most of the time this is the only way that it is used. - * - * \sa SparseMatrixBase::selfadjointView() - */ -namespace internal { - -template<typename MatrixType, unsigned int Mode> -struct traits<SparseSelfAdjointView<MatrixType,Mode> > : traits<MatrixType> { -}; - -template<int SrcMode,int DstMode,typename MatrixType,int DestOrder> -void permute_symm_to_symm(const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DestOrder,typename MatrixType::StorageIndex>& _dest, const typename MatrixType::StorageIndex* perm = 0); - -template<int Mode,typename MatrixType,int DestOrder> -void permute_symm_to_fullsymm(const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DestOrder,typename MatrixType::StorageIndex>& _dest, const typename MatrixType::StorageIndex* perm = 0); - -} - -template<typename MatrixType, unsigned int _Mode> class SparseSelfAdjointView - : public EigenBase<SparseSelfAdjointView<MatrixType,_Mode> > -{ - public: - - enum { - Mode = _Mode, - TransposeMode = ((Mode & Upper) ? Lower : 0) | ((Mode & Lower) ? Upper : 0), - RowsAtCompileTime = internal::traits<SparseSelfAdjointView>::RowsAtCompileTime, - ColsAtCompileTime = internal::traits<SparseSelfAdjointView>::ColsAtCompileTime - }; - - typedef EigenBase<SparseSelfAdjointView> Base; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef Matrix<StorageIndex,Dynamic,1> VectorI; - typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested; - typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested; - - explicit inline SparseSelfAdjointView(MatrixType& matrix) : m_matrix(matrix) - { - eigen_assert(rows()==cols() && "SelfAdjointView is only for squared matrices"); - } - - inline Index rows() const { return m_matrix.rows(); } - inline Index cols() const { return m_matrix.cols(); } - - /** \internal \returns a reference to the nested matrix */ - const _MatrixTypeNested& matrix() const { return m_matrix; } - typename internal::remove_reference<MatrixTypeNested>::type& matrix() { return m_matrix; } - - /** \returns an expression of the matrix product between a sparse self-adjoint matrix \c *this and a sparse matrix \a rhs. - * - * Note that there is no algorithmic advantage of performing such a product compared to a general sparse-sparse matrix product. - * Indeed, the SparseSelfadjointView operand is first copied into a temporary SparseMatrix before computing the product. - */ - template<typename OtherDerived> - Product<SparseSelfAdjointView, OtherDerived> - operator*(const SparseMatrixBase<OtherDerived>& rhs) const - { - return Product<SparseSelfAdjointView, OtherDerived>(*this, rhs.derived()); - } - - /** \returns an expression of the matrix product between a sparse matrix \a lhs and a sparse self-adjoint matrix \a rhs. - * - * Note that there is no algorithmic advantage of performing such a product compared to a general sparse-sparse matrix product. - * Indeed, the SparseSelfadjointView operand is first copied into a temporary SparseMatrix before computing the product. - */ - template<typename OtherDerived> friend - Product<OtherDerived, SparseSelfAdjointView> - operator*(const SparseMatrixBase<OtherDerived>& lhs, const SparseSelfAdjointView& rhs) - { - return Product<OtherDerived, SparseSelfAdjointView>(lhs.derived(), rhs); - } - - /** Efficient sparse self-adjoint matrix times dense vector/matrix product */ - template<typename OtherDerived> - Product<SparseSelfAdjointView,OtherDerived> - operator*(const MatrixBase<OtherDerived>& rhs) const - { - return Product<SparseSelfAdjointView,OtherDerived>(*this, rhs.derived()); - } - - /** Efficient dense vector/matrix times sparse self-adjoint matrix product */ - template<typename OtherDerived> friend - Product<OtherDerived,SparseSelfAdjointView> - operator*(const MatrixBase<OtherDerived>& lhs, const SparseSelfAdjointView& rhs) - { - return Product<OtherDerived,SparseSelfAdjointView>(lhs.derived(), rhs); - } - - /** Perform a symmetric rank K update of the selfadjoint matrix \c *this: - * \f$ this = this + \alpha ( u u^* ) \f$ where \a u is a vector or matrix. - * - * \returns a reference to \c *this - * - * To perform \f$ this = this + \alpha ( u^* u ) \f$ you can simply - * call this function with u.adjoint(). - */ - template<typename DerivedU> - SparseSelfAdjointView& rankUpdate(const SparseMatrixBase<DerivedU>& u, const Scalar& alpha = Scalar(1)); - - /** \returns an expression of P H P^-1 */ - // TODO implement twists in a more evaluator friendly fashion - SparseSymmetricPermutationProduct<_MatrixTypeNested,Mode> twistedBy(const PermutationMatrix<Dynamic,Dynamic,StorageIndex>& perm) const - { - return SparseSymmetricPermutationProduct<_MatrixTypeNested,Mode>(m_matrix, perm); - } - - template<typename SrcMatrixType,int SrcMode> - SparseSelfAdjointView& operator=(const SparseSymmetricPermutationProduct<SrcMatrixType,SrcMode>& permutedMatrix) - { - internal::call_assignment_no_alias_no_transpose(*this, permutedMatrix); - return *this; - } - - SparseSelfAdjointView& operator=(const SparseSelfAdjointView& src) - { - PermutationMatrix<Dynamic,Dynamic,StorageIndex> pnull; - return *this = src.twistedBy(pnull); - } - - template<typename SrcMatrixType,unsigned int SrcMode> - SparseSelfAdjointView& operator=(const SparseSelfAdjointView<SrcMatrixType,SrcMode>& src) - { - PermutationMatrix<Dynamic,Dynamic,StorageIndex> pnull; - return *this = src.twistedBy(pnull); - } - - void resize(Index rows, Index cols) - { - EIGEN_ONLY_USED_FOR_DEBUG(rows); - EIGEN_ONLY_USED_FOR_DEBUG(cols); - eigen_assert(rows == this->rows() && cols == this->cols() - && "SparseSelfadjointView::resize() does not actually allow to resize."); - } - - protected: - - MatrixTypeNested m_matrix; - //mutable VectorI m_countPerRow; - //mutable VectorI m_countPerCol; - private: - template<typename Dest> void evalTo(Dest &) const; -}; - -/*************************************************************************** -* Implementation of SparseMatrixBase methods -***************************************************************************/ - -template<typename Derived> -template<unsigned int UpLo> -typename SparseMatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type SparseMatrixBase<Derived>::selfadjointView() const -{ - return SparseSelfAdjointView<const Derived, UpLo>(derived()); -} - -template<typename Derived> -template<unsigned int UpLo> -typename SparseMatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type SparseMatrixBase<Derived>::selfadjointView() -{ - return SparseSelfAdjointView<Derived, UpLo>(derived()); -} - -/*************************************************************************** -* Implementation of SparseSelfAdjointView methods -***************************************************************************/ - -template<typename MatrixType, unsigned int Mode> -template<typename DerivedU> -SparseSelfAdjointView<MatrixType,Mode>& -SparseSelfAdjointView<MatrixType,Mode>::rankUpdate(const SparseMatrixBase<DerivedU>& u, const Scalar& alpha) -{ - SparseMatrix<Scalar,(MatrixType::Flags&RowMajorBit)?RowMajor:ColMajor> tmp = u * u.adjoint(); - if(alpha==Scalar(0)) - m_matrix = tmp.template triangularView<Mode>(); - else - m_matrix += alpha * tmp.template triangularView<Mode>(); - - return *this; -} - -namespace internal { - -// TODO currently a selfadjoint expression has the form SelfAdjointView<.,.> -// in the future selfadjoint-ness should be defined by the expression traits -// such that Transpose<SelfAdjointView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work) -template<typename MatrixType, unsigned int Mode> -struct evaluator_traits<SparseSelfAdjointView<MatrixType,Mode> > -{ - typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind; - typedef SparseSelfAdjointShape Shape; -}; - -struct SparseSelfAdjoint2Sparse {}; - -template<> struct AssignmentKind<SparseShape,SparseSelfAdjointShape> { typedef SparseSelfAdjoint2Sparse Kind; }; -template<> struct AssignmentKind<SparseSelfAdjointShape,SparseShape> { typedef Sparse2Sparse Kind; }; - -template< typename DstXprType, typename SrcXprType, typename Functor> -struct Assignment<DstXprType, SrcXprType, Functor, SparseSelfAdjoint2Sparse> -{ - typedef typename DstXprType::StorageIndex StorageIndex; - typedef internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> AssignOpType; - - template<typename DestScalar,int StorageOrder> - static void run(SparseMatrix<DestScalar,StorageOrder,StorageIndex> &dst, const SrcXprType &src, const AssignOpType&/*func*/) - { - internal::permute_symm_to_fullsymm<SrcXprType::Mode>(src.matrix(), dst); - } - - // FIXME: the handling of += and -= in sparse matrices should be cleanup so that next two overloads could be reduced to: - template<typename DestScalar,int StorageOrder,typename AssignFunc> - static void run(SparseMatrix<DestScalar,StorageOrder,StorageIndex> &dst, const SrcXprType &src, const AssignFunc& func) - { - SparseMatrix<DestScalar,StorageOrder,StorageIndex> tmp(src.rows(),src.cols()); - run(tmp, src, AssignOpType()); - call_assignment_no_alias_no_transpose(dst, tmp, func); - } - - template<typename DestScalar,int StorageOrder> - static void run(SparseMatrix<DestScalar,StorageOrder,StorageIndex> &dst, const SrcXprType &src, - const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>& /* func */) - { - SparseMatrix<DestScalar,StorageOrder,StorageIndex> tmp(src.rows(),src.cols()); - run(tmp, src, AssignOpType()); - dst += tmp; - } - - template<typename DestScalar,int StorageOrder> - static void run(SparseMatrix<DestScalar,StorageOrder,StorageIndex> &dst, const SrcXprType &src, - const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>& /* func */) - { - SparseMatrix<DestScalar,StorageOrder,StorageIndex> tmp(src.rows(),src.cols()); - run(tmp, src, AssignOpType()); - dst -= tmp; - } - - template<typename DestScalar> - static void run(DynamicSparseMatrix<DestScalar,ColMajor,StorageIndex>& dst, const SrcXprType &src, const AssignOpType&/*func*/) - { - // TODO directly evaluate into dst; - SparseMatrix<DestScalar,ColMajor,StorageIndex> tmp(dst.rows(),dst.cols()); - internal::permute_symm_to_fullsymm<SrcXprType::Mode>(src.matrix(), tmp); - dst = tmp; - } -}; - -} // end namespace internal - -/*************************************************************************** -* Implementation of sparse self-adjoint time dense matrix -***************************************************************************/ - -namespace internal { - -template<int Mode, typename SparseLhsType, typename DenseRhsType, typename DenseResType, typename AlphaType> -inline void sparse_selfadjoint_time_dense_product(const SparseLhsType& lhs, const DenseRhsType& rhs, DenseResType& res, const AlphaType& alpha) -{ - EIGEN_ONLY_USED_FOR_DEBUG(alpha); - - typedef typename internal::nested_eval<SparseLhsType,DenseRhsType::MaxColsAtCompileTime>::type SparseLhsTypeNested; - typedef typename internal::remove_all<SparseLhsTypeNested>::type SparseLhsTypeNestedCleaned; - typedef evaluator<SparseLhsTypeNestedCleaned> LhsEval; - typedef typename LhsEval::InnerIterator LhsIterator; - typedef typename SparseLhsType::Scalar LhsScalar; - - enum { - LhsIsRowMajor = (LhsEval::Flags&RowMajorBit)==RowMajorBit, - ProcessFirstHalf = - ((Mode&(Upper|Lower))==(Upper|Lower)) - || ( (Mode&Upper) && !LhsIsRowMajor) - || ( (Mode&Lower) && LhsIsRowMajor), - ProcessSecondHalf = !ProcessFirstHalf - }; - - SparseLhsTypeNested lhs_nested(lhs); - LhsEval lhsEval(lhs_nested); - - // work on one column at once - for (Index k=0; k<rhs.cols(); ++k) - { - for (Index j=0; j<lhs.outerSize(); ++j) - { - LhsIterator i(lhsEval,j); - // handle diagonal coeff - if (ProcessSecondHalf) - { - while (i && i.index()<j) ++i; - if(i && i.index()==j) - { - res.coeffRef(j,k) += alpha * i.value() * rhs.coeff(j,k); - ++i; - } - } - - // premultiplied rhs for scatters - typename ScalarBinaryOpTraits<AlphaType, typename DenseRhsType::Scalar>::ReturnType rhs_j(alpha*rhs(j,k)); - // accumulator for partial scalar product - typename DenseResType::Scalar res_j(0); - for(; (ProcessFirstHalf ? i && i.index() < j : i) ; ++i) - { - LhsScalar lhs_ij = i.value(); - if(!LhsIsRowMajor) lhs_ij = numext::conj(lhs_ij); - res_j += lhs_ij * rhs.coeff(i.index(),k); - res(i.index(),k) += numext::conj(lhs_ij) * rhs_j; - } - res.coeffRef(j,k) += alpha * res_j; - - // handle diagonal coeff - if (ProcessFirstHalf && i && (i.index()==j)) - res.coeffRef(j,k) += alpha * i.value() * rhs.coeff(j,k); - } - } -} - - -template<typename LhsView, typename Rhs, int ProductType> -struct generic_product_impl<LhsView, Rhs, SparseSelfAdjointShape, DenseShape, ProductType> -: generic_product_impl_base<LhsView, Rhs, generic_product_impl<LhsView, Rhs, SparseSelfAdjointShape, DenseShape, ProductType> > -{ - template<typename Dest> - static void scaleAndAddTo(Dest& dst, const LhsView& lhsView, const Rhs& rhs, const typename Dest::Scalar& alpha) - { - typedef typename LhsView::_MatrixTypeNested Lhs; - typedef typename nested_eval<Lhs,Dynamic>::type LhsNested; - typedef typename nested_eval<Rhs,Dynamic>::type RhsNested; - LhsNested lhsNested(lhsView.matrix()); - RhsNested rhsNested(rhs); - - internal::sparse_selfadjoint_time_dense_product<LhsView::Mode>(lhsNested, rhsNested, dst, alpha); - } -}; - -template<typename Lhs, typename RhsView, int ProductType> -struct generic_product_impl<Lhs, RhsView, DenseShape, SparseSelfAdjointShape, ProductType> -: generic_product_impl_base<Lhs, RhsView, generic_product_impl<Lhs, RhsView, DenseShape, SparseSelfAdjointShape, ProductType> > -{ - template<typename Dest> - static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const RhsView& rhsView, const typename Dest::Scalar& alpha) - { - typedef typename RhsView::_MatrixTypeNested Rhs; - typedef typename nested_eval<Lhs,Dynamic>::type LhsNested; - typedef typename nested_eval<Rhs,Dynamic>::type RhsNested; - LhsNested lhsNested(lhs); - RhsNested rhsNested(rhsView.matrix()); - - // transpose everything - Transpose<Dest> dstT(dst); - internal::sparse_selfadjoint_time_dense_product<RhsView::TransposeMode>(rhsNested.transpose(), lhsNested.transpose(), dstT, alpha); - } -}; - -// NOTE: these two overloads are needed to evaluate the sparse selfadjoint view into a full sparse matrix -// TODO: maybe the copy could be handled by generic_product_impl so that these overloads would not be needed anymore - -template<typename LhsView, typename Rhs, int ProductTag> -struct product_evaluator<Product<LhsView, Rhs, DefaultProduct>, ProductTag, SparseSelfAdjointShape, SparseShape> - : public evaluator<typename Product<typename Rhs::PlainObject, Rhs, DefaultProduct>::PlainObject> -{ - typedef Product<LhsView, Rhs, DefaultProduct> XprType; - typedef typename XprType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - - product_evaluator(const XprType& xpr) - : m_lhs(xpr.lhs()), m_result(xpr.rows(), xpr.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - generic_product_impl<typename Rhs::PlainObject, Rhs, SparseShape, SparseShape, ProductTag>::evalTo(m_result, m_lhs, xpr.rhs()); - } - -protected: - typename Rhs::PlainObject m_lhs; - PlainObject m_result; -}; - -template<typename Lhs, typename RhsView, int ProductTag> -struct product_evaluator<Product<Lhs, RhsView, DefaultProduct>, ProductTag, SparseShape, SparseSelfAdjointShape> - : public evaluator<typename Product<Lhs, typename Lhs::PlainObject, DefaultProduct>::PlainObject> -{ - typedef Product<Lhs, RhsView, DefaultProduct> XprType; - typedef typename XprType::PlainObject PlainObject; - typedef evaluator<PlainObject> Base; - - product_evaluator(const XprType& xpr) - : m_rhs(xpr.rhs()), m_result(xpr.rows(), xpr.cols()) - { - ::new (static_cast<Base*>(this)) Base(m_result); - generic_product_impl<Lhs, typename Lhs::PlainObject, SparseShape, SparseShape, ProductTag>::evalTo(m_result, xpr.lhs(), m_rhs); - } - -protected: - typename Lhs::PlainObject m_rhs; - PlainObject m_result; -}; - -} // namespace internal - -/*************************************************************************** -* Implementation of symmetric copies and permutations -***************************************************************************/ -namespace internal { - -template<int Mode,typename MatrixType,int DestOrder> -void permute_symm_to_fullsymm(const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DestOrder,typename MatrixType::StorageIndex>& _dest, const typename MatrixType::StorageIndex* perm) -{ - typedef typename MatrixType::StorageIndex StorageIndex; - typedef typename MatrixType::Scalar Scalar; - typedef SparseMatrix<Scalar,DestOrder,StorageIndex> Dest; - typedef Matrix<StorageIndex,Dynamic,1> VectorI; - typedef evaluator<MatrixType> MatEval; - typedef typename evaluator<MatrixType>::InnerIterator MatIterator; - - MatEval matEval(mat); - Dest& dest(_dest.derived()); - enum { - StorageOrderMatch = int(Dest::IsRowMajor) == int(MatrixType::IsRowMajor) - }; - - Index size = mat.rows(); - VectorI count; - count.resize(size); - count.setZero(); - dest.resize(size,size); - for(Index j = 0; j<size; ++j) - { - Index jp = perm ? perm[j] : j; - for(MatIterator it(matEval,j); it; ++it) - { - Index i = it.index(); - Index r = it.row(); - Index c = it.col(); - Index ip = perm ? perm[i] : i; - if(Mode==(Upper|Lower)) - count[StorageOrderMatch ? jp : ip]++; - else if(r==c) - count[ip]++; - else if(( Mode==Lower && r>c) || ( Mode==Upper && r<c)) - { - count[ip]++; - count[jp]++; - } - } - } - Index nnz = count.sum(); - - // reserve space - dest.resizeNonZeros(nnz); - dest.outerIndexPtr()[0] = 0; - for(Index j=0; j<size; ++j) - dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j]; - for(Index j=0; j<size; ++j) - count[j] = dest.outerIndexPtr()[j]; - - // copy data - for(StorageIndex j = 0; j<size; ++j) - { - for(MatIterator it(matEval,j); it; ++it) - { - StorageIndex i = internal::convert_index<StorageIndex>(it.index()); - Index r = it.row(); - Index c = it.col(); - - StorageIndex jp = perm ? perm[j] : j; - StorageIndex ip = perm ? perm[i] : i; - - if(Mode==(Upper|Lower)) - { - Index k = count[StorageOrderMatch ? jp : ip]++; - dest.innerIndexPtr()[k] = StorageOrderMatch ? ip : jp; - dest.valuePtr()[k] = it.value(); - } - else if(r==c) - { - Index k = count[ip]++; - dest.innerIndexPtr()[k] = ip; - dest.valuePtr()[k] = it.value(); - } - else if(( (Mode&Lower)==Lower && r>c) || ( (Mode&Upper)==Upper && r<c)) - { - if(!StorageOrderMatch) - std::swap(ip,jp); - Index k = count[jp]++; - dest.innerIndexPtr()[k] = ip; - dest.valuePtr()[k] = it.value(); - k = count[ip]++; - dest.innerIndexPtr()[k] = jp; - dest.valuePtr()[k] = numext::conj(it.value()); - } - } - } -} - -template<int _SrcMode,int _DstMode,typename MatrixType,int DstOrder> -void permute_symm_to_symm(const MatrixType& mat, SparseMatrix<typename MatrixType::Scalar,DstOrder,typename MatrixType::StorageIndex>& _dest, const typename MatrixType::StorageIndex* perm) -{ - typedef typename MatrixType::StorageIndex StorageIndex; - typedef typename MatrixType::Scalar Scalar; - SparseMatrix<Scalar,DstOrder,StorageIndex>& dest(_dest.derived()); - typedef Matrix<StorageIndex,Dynamic,1> VectorI; - typedef evaluator<MatrixType> MatEval; - typedef typename evaluator<MatrixType>::InnerIterator MatIterator; - - enum { - SrcOrder = MatrixType::IsRowMajor ? RowMajor : ColMajor, - StorageOrderMatch = int(SrcOrder) == int(DstOrder), - DstMode = DstOrder==RowMajor ? (_DstMode==Upper ? Lower : Upper) : _DstMode, - SrcMode = SrcOrder==RowMajor ? (_SrcMode==Upper ? Lower : Upper) : _SrcMode - }; - - MatEval matEval(mat); - - Index size = mat.rows(); - VectorI count(size); - count.setZero(); - dest.resize(size,size); - for(StorageIndex j = 0; j<size; ++j) - { - StorageIndex jp = perm ? perm[j] : j; - for(MatIterator it(matEval,j); it; ++it) - { - StorageIndex i = it.index(); - if((int(SrcMode)==int(Lower) && i<j) || (int(SrcMode)==int(Upper) && i>j)) - continue; - - StorageIndex ip = perm ? perm[i] : i; - count[int(DstMode)==int(Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++; - } - } - dest.outerIndexPtr()[0] = 0; - for(Index j=0; j<size; ++j) - dest.outerIndexPtr()[j+1] = dest.outerIndexPtr()[j] + count[j]; - dest.resizeNonZeros(dest.outerIndexPtr()[size]); - for(Index j=0; j<size; ++j) - count[j] = dest.outerIndexPtr()[j]; - - for(StorageIndex j = 0; j<size; ++j) - { - - for(MatIterator it(matEval,j); it; ++it) - { - StorageIndex i = it.index(); - if((int(SrcMode)==int(Lower) && i<j) || (int(SrcMode)==int(Upper) && i>j)) - continue; - - StorageIndex jp = perm ? perm[j] : j; - StorageIndex ip = perm? perm[i] : i; - - Index k = count[int(DstMode)==int(Lower) ? (std::min)(ip,jp) : (std::max)(ip,jp)]++; - dest.innerIndexPtr()[k] = int(DstMode)==int(Lower) ? (std::max)(ip,jp) : (std::min)(ip,jp); - - if(!StorageOrderMatch) std::swap(ip,jp); - if( ((int(DstMode)==int(Lower) && ip<jp) || (int(DstMode)==int(Upper) && ip>jp))) - dest.valuePtr()[k] = numext::conj(it.value()); - else - dest.valuePtr()[k] = it.value(); - } - } -} - -} - -// TODO implement twists in a more evaluator friendly fashion - -namespace internal { - -template<typename MatrixType, int Mode> -struct traits<SparseSymmetricPermutationProduct<MatrixType,Mode> > : traits<MatrixType> { -}; - -} - -template<typename MatrixType,int Mode> -class SparseSymmetricPermutationProduct - : public EigenBase<SparseSymmetricPermutationProduct<MatrixType,Mode> > -{ - public: - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::StorageIndex StorageIndex; - enum { - RowsAtCompileTime = internal::traits<SparseSymmetricPermutationProduct>::RowsAtCompileTime, - ColsAtCompileTime = internal::traits<SparseSymmetricPermutationProduct>::ColsAtCompileTime - }; - protected: - typedef PermutationMatrix<Dynamic,Dynamic,StorageIndex> Perm; - public: - typedef Matrix<StorageIndex,Dynamic,1> VectorI; - typedef typename MatrixType::Nested MatrixTypeNested; - typedef typename internal::remove_all<MatrixTypeNested>::type NestedExpression; - - SparseSymmetricPermutationProduct(const MatrixType& mat, const Perm& perm) - : m_matrix(mat), m_perm(perm) - {} - - inline Index rows() const { return m_matrix.rows(); } - inline Index cols() const { return m_matrix.cols(); } - - const NestedExpression& matrix() const { return m_matrix; } - const Perm& perm() const { return m_perm; } - - protected: - MatrixTypeNested m_matrix; - const Perm& m_perm; - -}; - -namespace internal { - -template<typename DstXprType, typename MatrixType, int Mode, typename Scalar> -struct Assignment<DstXprType, SparseSymmetricPermutationProduct<MatrixType,Mode>, internal::assign_op<Scalar,typename MatrixType::Scalar>, Sparse2Sparse> -{ - typedef SparseSymmetricPermutationProduct<MatrixType,Mode> SrcXprType; - typedef typename DstXprType::StorageIndex DstIndex; - template<int Options> - static void run(SparseMatrix<Scalar,Options,DstIndex> &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename MatrixType::Scalar> &) - { - // internal::permute_symm_to_fullsymm<Mode>(m_matrix,_dest,m_perm.indices().data()); - SparseMatrix<Scalar,(Options&RowMajor)==RowMajor ? ColMajor : RowMajor, DstIndex> tmp; - internal::permute_symm_to_fullsymm<Mode>(src.matrix(),tmp,src.perm().indices().data()); - dst = tmp; - } - - template<typename DestType,unsigned int DestMode> - static void run(SparseSelfAdjointView<DestType,DestMode>& dst, const SrcXprType &src, const internal::assign_op<Scalar,typename MatrixType::Scalar> &) - { - internal::permute_symm_to_symm<Mode,DestMode>(src.matrix(),dst.matrix(),src.perm().indices().data()); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_SELFADJOINTVIEW_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSolverBase.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSolverBase.h deleted file mode 100644 index b4c9a422..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSolverBase.h +++ /dev/null @@ -1,124 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSESOLVERBASE_H -#define EIGEN_SPARSESOLVERBASE_H - -namespace Eigen { - -namespace internal { - - /** \internal - * Helper functions to solve with a sparse right-hand-side and result. - * The rhs is decomposed into small vertical panels which are solved through dense temporaries. - */ -template<typename Decomposition, typename Rhs, typename Dest> -typename enable_if<Rhs::ColsAtCompileTime!=1 && Dest::ColsAtCompileTime!=1>::type -solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs& rhs, Dest &dest) -{ - EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); - typedef typename Dest::Scalar DestScalar; - // we process the sparse rhs per block of NbColsAtOnce columns temporarily stored into a dense matrix. - static const Index NbColsAtOnce = 4; - Index rhsCols = rhs.cols(); - Index size = rhs.rows(); - // the temporary matrices do not need more columns than NbColsAtOnce: - Index tmpCols = (std::min)(rhsCols, NbColsAtOnce); - Eigen::Matrix<DestScalar,Dynamic,Dynamic> tmp(size,tmpCols); - Eigen::Matrix<DestScalar,Dynamic,Dynamic> tmpX(size,tmpCols); - for(Index k=0; k<rhsCols; k+=NbColsAtOnce) - { - Index actualCols = std::min<Index>(rhsCols-k, NbColsAtOnce); - tmp.leftCols(actualCols) = rhs.middleCols(k,actualCols); - tmpX.leftCols(actualCols) = dec.solve(tmp.leftCols(actualCols)); - dest.middleCols(k,actualCols) = tmpX.leftCols(actualCols).sparseView(); - } -} - -// Overload for vector as rhs -template<typename Decomposition, typename Rhs, typename Dest> -typename enable_if<Rhs::ColsAtCompileTime==1 || Dest::ColsAtCompileTime==1>::type -solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs& rhs, Dest &dest) -{ - typedef typename Dest::Scalar DestScalar; - Index size = rhs.rows(); - Eigen::Matrix<DestScalar,Dynamic,1> rhs_dense(rhs); - Eigen::Matrix<DestScalar,Dynamic,1> dest_dense(size); - dest_dense = dec.solve(rhs_dense); - dest = dest_dense.sparseView(); -} - -} // end namespace internal - -/** \class SparseSolverBase - * \ingroup SparseCore_Module - * \brief A base class for sparse solvers - * - * \tparam Derived the actual type of the solver. - * - */ -template<typename Derived> -class SparseSolverBase : internal::noncopyable -{ - public: - - /** Default constructor */ - SparseSolverBase() - : m_isInitialized(false) - {} - - ~SparseSolverBase() - {} - - Derived& derived() { return *static_cast<Derived*>(this); } - const Derived& derived() const { return *static_cast<const Derived*>(this); } - - /** \returns an expression of the solution x of \f$ A x = b \f$ using the current decomposition of A. - * - * \sa compute() - */ - template<typename Rhs> - inline const Solve<Derived, Rhs> - solve(const MatrixBase<Rhs>& b) const - { - eigen_assert(m_isInitialized && "Solver is not initialized."); - eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b"); - return Solve<Derived, Rhs>(derived(), b.derived()); - } - - /** \returns an expression of the solution x of \f$ A x = b \f$ using the current decomposition of A. - * - * \sa compute() - */ - template<typename Rhs> - inline const Solve<Derived, Rhs> - solve(const SparseMatrixBase<Rhs>& b) const - { - eigen_assert(m_isInitialized && "Solver is not initialized."); - eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b"); - return Solve<Derived, Rhs>(derived(), b.derived()); - } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal default implementation of solving with a sparse rhs */ - template<typename Rhs,typename Dest> - void _solve_impl(const SparseMatrixBase<Rhs> &b, SparseMatrixBase<Dest> &dest) const - { - internal::solve_sparse_through_dense_panels(derived(), b.derived(), dest.derived()); - } - #endif // EIGEN_PARSED_BY_DOXYGEN - - protected: - - mutable bool m_isInitialized; -}; - -} // end namespace Eigen - -#endif // EIGEN_SPARSESOLVERBASE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSparseProductWithPruning.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSparseProductWithPruning.h deleted file mode 100644 index 88820a48..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseSparseProductWithPruning.h +++ /dev/null @@ -1,198 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H -#define EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H - -namespace Eigen { - -namespace internal { - - -// perform a pseudo in-place sparse * sparse product assuming all matrices are col major -template<typename Lhs, typename Rhs, typename ResultType> -static void sparse_sparse_product_with_pruning_impl(const Lhs& lhs, const Rhs& rhs, ResultType& res, const typename ResultType::RealScalar& tolerance) -{ - // return sparse_sparse_product_with_pruning_impl2(lhs,rhs,res); - - typedef typename remove_all<Rhs>::type::Scalar RhsScalar; - typedef typename remove_all<ResultType>::type::Scalar ResScalar; - typedef typename remove_all<Lhs>::type::StorageIndex StorageIndex; - - // make sure to call innerSize/outerSize since we fake the storage order. - Index rows = lhs.innerSize(); - Index cols = rhs.outerSize(); - //Index size = lhs.outerSize(); - eigen_assert(lhs.outerSize() == rhs.innerSize()); - - // allocate a temporary buffer - AmbiVector<ResScalar,StorageIndex> tempVector(rows); - - // mimics a resizeByInnerOuter: - if(ResultType::IsRowMajor) - res.resize(cols, rows); - else - res.resize(rows, cols); - - evaluator<Lhs> lhsEval(lhs); - evaluator<Rhs> rhsEval(rhs); - - // estimate the number of non zero entries - // given a rhs column containing Y non zeros, we assume that the respective Y columns - // of the lhs differs in average of one non zeros, thus the number of non zeros for - // the product of a rhs column with the lhs is X+Y where X is the average number of non zero - // per column of the lhs. - // Therefore, we have nnz(lhs*rhs) = nnz(lhs) + nnz(rhs) - Index estimated_nnz_prod = lhsEval.nonZerosEstimate() + rhsEval.nonZerosEstimate(); - - res.reserve(estimated_nnz_prod); - double ratioColRes = double(estimated_nnz_prod)/(double(lhs.rows())*double(rhs.cols())); - for (Index j=0; j<cols; ++j) - { - // FIXME: - //double ratioColRes = (double(rhs.innerVector(j).nonZeros()) + double(lhs.nonZeros())/double(lhs.cols()))/double(lhs.rows()); - // let's do a more accurate determination of the nnz ratio for the current column j of res - tempVector.init(ratioColRes); - tempVector.setZero(); - for (typename evaluator<Rhs>::InnerIterator rhsIt(rhsEval, j); rhsIt; ++rhsIt) - { - // FIXME should be written like this: tmp += rhsIt.value() * lhs.col(rhsIt.index()) - tempVector.restart(); - RhsScalar x = rhsIt.value(); - for (typename evaluator<Lhs>::InnerIterator lhsIt(lhsEval, rhsIt.index()); lhsIt; ++lhsIt) - { - tempVector.coeffRef(lhsIt.index()) += lhsIt.value() * x; - } - } - res.startVec(j); - for (typename AmbiVector<ResScalar,StorageIndex>::Iterator it(tempVector,tolerance); it; ++it) - res.insertBackByOuterInner(j,it.index()) = it.value(); - } - res.finalize(); -} - -template<typename Lhs, typename Rhs, typename ResultType, - int LhsStorageOrder = traits<Lhs>::Flags&RowMajorBit, - int RhsStorageOrder = traits<Rhs>::Flags&RowMajorBit, - int ResStorageOrder = traits<ResultType>::Flags&RowMajorBit> -struct sparse_sparse_product_with_pruning_selector; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_product_with_pruning_selector<Lhs,Rhs,ResultType,ColMajor,ColMajor,ColMajor> -{ - typedef typename ResultType::RealScalar RealScalar; - - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res, const RealScalar& tolerance) - { - typename remove_all<ResultType>::type _res(res.rows(), res.cols()); - internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,ResultType>(lhs, rhs, _res, tolerance); - res.swap(_res); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_product_with_pruning_selector<Lhs,Rhs,ResultType,ColMajor,ColMajor,RowMajor> -{ - typedef typename ResultType::RealScalar RealScalar; - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res, const RealScalar& tolerance) - { - // we need a col-major matrix to hold the result - typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::StorageIndex> SparseTemporaryType; - SparseTemporaryType _res(res.rows(), res.cols()); - internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,SparseTemporaryType>(lhs, rhs, _res, tolerance); - res = _res; - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_product_with_pruning_selector<Lhs,Rhs,ResultType,RowMajor,RowMajor,RowMajor> -{ - typedef typename ResultType::RealScalar RealScalar; - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res, const RealScalar& tolerance) - { - // let's transpose the product to get a column x column product - typename remove_all<ResultType>::type _res(res.rows(), res.cols()); - internal::sparse_sparse_product_with_pruning_impl<Rhs,Lhs,ResultType>(rhs, lhs, _res, tolerance); - res.swap(_res); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_product_with_pruning_selector<Lhs,Rhs,ResultType,RowMajor,RowMajor,ColMajor> -{ - typedef typename ResultType::RealScalar RealScalar; - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res, const RealScalar& tolerance) - { - typedef SparseMatrix<typename Lhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixLhs; - typedef SparseMatrix<typename Rhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixRhs; - ColMajorMatrixLhs colLhs(lhs); - ColMajorMatrixRhs colRhs(rhs); - internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,ColMajorMatrixRhs,ResultType>(colLhs, colRhs, res, tolerance); - - // let's transpose the product to get a column x column product -// typedef SparseMatrix<typename ResultType::Scalar> SparseTemporaryType; -// SparseTemporaryType _res(res.cols(), res.rows()); -// sparse_sparse_product_with_pruning_impl<Rhs,Lhs,SparseTemporaryType>(rhs, lhs, _res); -// res = _res.transpose(); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_product_with_pruning_selector<Lhs,Rhs,ResultType,ColMajor,RowMajor,RowMajor> -{ - typedef typename ResultType::RealScalar RealScalar; - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res, const RealScalar& tolerance) - { - typedef SparseMatrix<typename Lhs::Scalar,RowMajor,typename Lhs::StorageIndex> RowMajorMatrixLhs; - RowMajorMatrixLhs rowLhs(lhs); - sparse_sparse_product_with_pruning_selector<RowMajorMatrixLhs,Rhs,ResultType,RowMajor,RowMajor>(rowLhs,rhs,res,tolerance); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_product_with_pruning_selector<Lhs,Rhs,ResultType,RowMajor,ColMajor,RowMajor> -{ - typedef typename ResultType::RealScalar RealScalar; - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res, const RealScalar& tolerance) - { - typedef SparseMatrix<typename Rhs::Scalar,RowMajor,typename Lhs::StorageIndex> RowMajorMatrixRhs; - RowMajorMatrixRhs rowRhs(rhs); - sparse_sparse_product_with_pruning_selector<Lhs,RowMajorMatrixRhs,ResultType,RowMajor,RowMajor,RowMajor>(lhs,rowRhs,res,tolerance); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_product_with_pruning_selector<Lhs,Rhs,ResultType,ColMajor,RowMajor,ColMajor> -{ - typedef typename ResultType::RealScalar RealScalar; - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res, const RealScalar& tolerance) - { - typedef SparseMatrix<typename Rhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixRhs; - ColMajorMatrixRhs colRhs(rhs); - internal::sparse_sparse_product_with_pruning_impl<Lhs,ColMajorMatrixRhs,ResultType>(lhs, colRhs, res, tolerance); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct sparse_sparse_product_with_pruning_selector<Lhs,Rhs,ResultType,RowMajor,ColMajor,ColMajor> -{ - typedef typename ResultType::RealScalar RealScalar; - static void run(const Lhs& lhs, const Rhs& rhs, ResultType& res, const RealScalar& tolerance) - { - typedef SparseMatrix<typename Lhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixLhs; - ColMajorMatrixLhs colLhs(lhs); - internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,Rhs,ResultType>(colLhs, rhs, res, tolerance); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseTranspose.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseTranspose.h deleted file mode 100644 index 3757d4c6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseTranspose.h +++ /dev/null @@ -1,92 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSETRANSPOSE_H -#define EIGEN_SPARSETRANSPOSE_H - -namespace Eigen { - -namespace internal { - template<typename MatrixType,int CompressedAccess=int(MatrixType::Flags&CompressedAccessBit)> - class SparseTransposeImpl - : public SparseMatrixBase<Transpose<MatrixType> > - {}; - - template<typename MatrixType> - class SparseTransposeImpl<MatrixType,CompressedAccessBit> - : public SparseCompressedBase<Transpose<MatrixType> > - { - typedef SparseCompressedBase<Transpose<MatrixType> > Base; - public: - using Base::derived; - typedef typename Base::Scalar Scalar; - typedef typename Base::StorageIndex StorageIndex; - - inline Index nonZeros() const { return derived().nestedExpression().nonZeros(); } - - inline const Scalar* valuePtr() const { return derived().nestedExpression().valuePtr(); } - inline const StorageIndex* innerIndexPtr() const { return derived().nestedExpression().innerIndexPtr(); } - inline const StorageIndex* outerIndexPtr() const { return derived().nestedExpression().outerIndexPtr(); } - inline const StorageIndex* innerNonZeroPtr() const { return derived().nestedExpression().innerNonZeroPtr(); } - - inline Scalar* valuePtr() { return derived().nestedExpression().valuePtr(); } - inline StorageIndex* innerIndexPtr() { return derived().nestedExpression().innerIndexPtr(); } - inline StorageIndex* outerIndexPtr() { return derived().nestedExpression().outerIndexPtr(); } - inline StorageIndex* innerNonZeroPtr() { return derived().nestedExpression().innerNonZeroPtr(); } - }; -} - -template<typename MatrixType> class TransposeImpl<MatrixType,Sparse> - : public internal::SparseTransposeImpl<MatrixType> -{ - protected: - typedef internal::SparseTransposeImpl<MatrixType> Base; -}; - -namespace internal { - -template<typename ArgType> -struct unary_evaluator<Transpose<ArgType>, IteratorBased> - : public evaluator_base<Transpose<ArgType> > -{ - typedef typename evaluator<ArgType>::InnerIterator EvalIterator; - public: - typedef Transpose<ArgType> XprType; - - inline Index nonZerosEstimate() const { - return m_argImpl.nonZerosEstimate(); - } - - class InnerIterator : public EvalIterator - { - public: - EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& unaryOp, Index outer) - : EvalIterator(unaryOp.m_argImpl,outer) - {} - - Index row() const { return EvalIterator::col(); } - Index col() const { return EvalIterator::row(); } - }; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - Flags = XprType::Flags - }; - - explicit unary_evaluator(const XprType& op) :m_argImpl(op.nestedExpression()) {} - - protected: - evaluator<ArgType> m_argImpl; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSETRANSPOSE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseTriangularView.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseTriangularView.h deleted file mode 100644 index 9ac12026..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseTriangularView.h +++ /dev/null @@ -1,189 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_TRIANGULARVIEW_H -#define EIGEN_SPARSE_TRIANGULARVIEW_H - -namespace Eigen { - -/** \ingroup SparseCore_Module - * - * \brief Base class for a triangular part in a \b sparse matrix - * - * This class is an abstract base class of class TriangularView, and objects of type TriangularViewImpl cannot be instantiated. - * It extends class TriangularView with additional methods which are available for sparse expressions only. - * - * \sa class TriangularView, SparseMatrixBase::triangularView() - */ -template<typename MatrixType, unsigned int Mode> class TriangularViewImpl<MatrixType,Mode,Sparse> - : public SparseMatrixBase<TriangularView<MatrixType,Mode> > -{ - enum { SkipFirst = ((Mode&Lower) && !(MatrixType::Flags&RowMajorBit)) - || ((Mode&Upper) && (MatrixType::Flags&RowMajorBit)), - SkipLast = !SkipFirst, - SkipDiag = (Mode&ZeroDiag) ? 1 : 0, - HasUnitDiag = (Mode&UnitDiag) ? 1 : 0 - }; - - typedef TriangularView<MatrixType,Mode> TriangularViewType; - - protected: - // dummy solve function to make TriangularView happy. - void solve() const; - - typedef SparseMatrixBase<TriangularViewType> Base; - public: - - EIGEN_SPARSE_PUBLIC_INTERFACE(TriangularViewType) - - typedef typename MatrixType::Nested MatrixTypeNested; - typedef typename internal::remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef; - typedef typename internal::remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned; - - template<typename RhsType, typename DstType> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void _solve_impl(const RhsType &rhs, DstType &dst) const { - if(!(internal::is_same<RhsType,DstType>::value && internal::extract_data(dst) == internal::extract_data(rhs))) - dst = rhs; - this->solveInPlace(dst); - } - - /** Applies the inverse of \c *this to the dense vector or matrix \a other, "in-place" */ - template<typename OtherDerived> void solveInPlace(MatrixBase<OtherDerived>& other) const; - - /** Applies the inverse of \c *this to the sparse vector or matrix \a other, "in-place" */ - template<typename OtherDerived> void solveInPlace(SparseMatrixBase<OtherDerived>& other) const; - -}; - -namespace internal { - -template<typename ArgType, unsigned int Mode> -struct unary_evaluator<TriangularView<ArgType,Mode>, IteratorBased> - : evaluator_base<TriangularView<ArgType,Mode> > -{ - typedef TriangularView<ArgType,Mode> XprType; - -protected: - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::StorageIndex StorageIndex; - typedef typename evaluator<ArgType>::InnerIterator EvalIterator; - - enum { SkipFirst = ((Mode&Lower) && !(ArgType::Flags&RowMajorBit)) - || ((Mode&Upper) && (ArgType::Flags&RowMajorBit)), - SkipLast = !SkipFirst, - SkipDiag = (Mode&ZeroDiag) ? 1 : 0, - HasUnitDiag = (Mode&UnitDiag) ? 1 : 0 - }; - -public: - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - Flags = XprType::Flags - }; - - explicit unary_evaluator(const XprType &xpr) : m_argImpl(xpr.nestedExpression()), m_arg(xpr.nestedExpression()) {} - - inline Index nonZerosEstimate() const { - return m_argImpl.nonZerosEstimate(); - } - - class InnerIterator : public EvalIterator - { - typedef EvalIterator Base; - public: - - EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& xprEval, Index outer) - : Base(xprEval.m_argImpl,outer), m_returnOne(false), m_containsDiag(Base::outer()<xprEval.m_arg.innerSize()) - { - if(SkipFirst) - { - while((*this) && ((HasUnitDiag||SkipDiag) ? this->index()<=outer : this->index()<outer)) - Base::operator++(); - if(HasUnitDiag) - m_returnOne = m_containsDiag; - } - else if(HasUnitDiag && ((!Base::operator bool()) || Base::index()>=Base::outer())) - { - if((!SkipFirst) && Base::operator bool()) - Base::operator++(); - m_returnOne = m_containsDiag; - } - } - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - if(HasUnitDiag && m_returnOne) - m_returnOne = false; - else - { - Base::operator++(); - if(HasUnitDiag && (!SkipFirst) && ((!Base::operator bool()) || Base::index()>=Base::outer())) - { - if((!SkipFirst) && Base::operator bool()) - Base::operator++(); - m_returnOne = m_containsDiag; - } - } - return *this; - } - - EIGEN_STRONG_INLINE operator bool() const - { - if(HasUnitDiag && m_returnOne) - return true; - if(SkipFirst) return Base::operator bool(); - else - { - if (SkipDiag) return (Base::operator bool() && this->index() < this->outer()); - else return (Base::operator bool() && this->index() <= this->outer()); - } - } - -// inline Index row() const { return (ArgType::Flags&RowMajorBit ? Base::outer() : this->index()); } -// inline Index col() const { return (ArgType::Flags&RowMajorBit ? this->index() : Base::outer()); } - inline StorageIndex index() const - { - if(HasUnitDiag && m_returnOne) return internal::convert_index<StorageIndex>(Base::outer()); - else return Base::index(); - } - inline Scalar value() const - { - if(HasUnitDiag && m_returnOne) return Scalar(1); - else return Base::value(); - } - - protected: - bool m_returnOne; - bool m_containsDiag; - private: - Scalar& valueRef(); - }; - -protected: - evaluator<ArgType> m_argImpl; - const ArgType& m_arg; -}; - -} // end namespace internal - -template<typename Derived> -template<int Mode> -inline const TriangularView<const Derived, Mode> -SparseMatrixBase<Derived>::triangularView() const -{ - return TriangularView<const Derived, Mode>(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_TRIANGULARVIEW_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseUtil.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseUtil.h deleted file mode 100644 index ceb93688..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseUtil.h +++ /dev/null @@ -1,186 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEUTIL_H -#define EIGEN_SPARSEUTIL_H - -namespace Eigen { - -#ifdef NDEBUG -#define EIGEN_DBG_SPARSE(X) -#else -#define EIGEN_DBG_SPARSE(X) X -#endif - -#define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \ -template<typename OtherDerived> \ -EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SparseMatrixBase<OtherDerived>& other) \ -{ \ - return Base::operator Op(other.derived()); \ -} \ -EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \ -{ \ - return Base::operator Op(other); \ -} - -#define EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ -template<typename Other> \ -EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \ -{ \ - return Base::operator Op(scalar); \ -} - -#define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ -EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) - - -#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \ - EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) - - -const int CoherentAccessPattern = 0x1; -const int InnerRandomAccessPattern = 0x2 | CoherentAccessPattern; -const int OuterRandomAccessPattern = 0x4 | CoherentAccessPattern; -const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern; - -template<typename _Scalar, int _Flags = 0, typename _StorageIndex = int> class SparseMatrix; -template<typename _Scalar, int _Flags = 0, typename _StorageIndex = int> class DynamicSparseMatrix; -template<typename _Scalar, int _Flags = 0, typename _StorageIndex = int> class SparseVector; -template<typename _Scalar, int _Flags = 0, typename _StorageIndex = int> class MappedSparseMatrix; - -template<typename MatrixType, unsigned int UpLo> class SparseSelfAdjointView; -template<typename Lhs, typename Rhs> class SparseDiagonalProduct; -template<typename MatrixType> class SparseView; - -template<typename Lhs, typename Rhs> class SparseSparseProduct; -template<typename Lhs, typename Rhs> class SparseTimeDenseProduct; -template<typename Lhs, typename Rhs> class DenseTimeSparseProduct; -template<typename Lhs, typename Rhs, bool Transpose> class SparseDenseOuterProduct; - -template<typename Lhs, typename Rhs> struct SparseSparseProductReturnType; -template<typename Lhs, typename Rhs, - int InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(internal::traits<Lhs>::ColsAtCompileTime,internal::traits<Rhs>::RowsAtCompileTime)> struct DenseSparseProductReturnType; - -template<typename Lhs, typename Rhs, - int InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(internal::traits<Lhs>::ColsAtCompileTime,internal::traits<Rhs>::RowsAtCompileTime)> struct SparseDenseProductReturnType; -template<typename MatrixType,int UpLo> class SparseSymmetricPermutationProduct; - -namespace internal { - -template<typename T,int Rows,int Cols,int Flags> struct sparse_eval; - -template<typename T> struct eval<T,Sparse> - : sparse_eval<T, traits<T>::RowsAtCompileTime,traits<T>::ColsAtCompileTime,traits<T>::Flags> -{}; - -template<typename T,int Cols,int Flags> struct sparse_eval<T,1,Cols,Flags> { - typedef typename traits<T>::Scalar _Scalar; - typedef typename traits<T>::StorageIndex _StorageIndex; - public: - typedef SparseVector<_Scalar, RowMajor, _StorageIndex> type; -}; - -template<typename T,int Rows,int Flags> struct sparse_eval<T,Rows,1,Flags> { - typedef typename traits<T>::Scalar _Scalar; - typedef typename traits<T>::StorageIndex _StorageIndex; - public: - typedef SparseVector<_Scalar, ColMajor, _StorageIndex> type; -}; - -// TODO this seems almost identical to plain_matrix_type<T, Sparse> -template<typename T,int Rows,int Cols,int Flags> struct sparse_eval { - typedef typename traits<T>::Scalar _Scalar; - typedef typename traits<T>::StorageIndex _StorageIndex; - enum { _Options = ((Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor }; - public: - typedef SparseMatrix<_Scalar, _Options, _StorageIndex> type; -}; - -template<typename T,int Flags> struct sparse_eval<T,1,1,Flags> { - typedef typename traits<T>::Scalar _Scalar; - public: - typedef Matrix<_Scalar, 1, 1> type; -}; - -template<typename T> struct plain_matrix_type<T,Sparse> -{ - typedef typename traits<T>::Scalar _Scalar; - typedef typename traits<T>::StorageIndex _StorageIndex; - enum { _Options = ((evaluator<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor }; - public: - typedef SparseMatrix<_Scalar, _Options, _StorageIndex> type; -}; - -template<typename T> -struct plain_object_eval<T,Sparse> - : sparse_eval<T, traits<T>::RowsAtCompileTime,traits<T>::ColsAtCompileTime, evaluator<T>::Flags> -{}; - -template<typename Decomposition, typename RhsType> -struct solve_traits<Decomposition,RhsType,Sparse> -{ - typedef typename sparse_eval<RhsType, RhsType::RowsAtCompileTime, RhsType::ColsAtCompileTime,traits<RhsType>::Flags>::type PlainObject; -}; - -template<typename Derived> -struct generic_xpr_base<Derived, MatrixXpr, Sparse> -{ - typedef SparseMatrixBase<Derived> type; -}; - -struct SparseTriangularShape { static std::string debugName() { return "SparseTriangularShape"; } }; -struct SparseSelfAdjointShape { static std::string debugName() { return "SparseSelfAdjointShape"; } }; - -template<> struct glue_shapes<SparseShape,SelfAdjointShape> { typedef SparseSelfAdjointShape type; }; -template<> struct glue_shapes<SparseShape,TriangularShape > { typedef SparseTriangularShape type; }; - -// return type of SparseCompressedBase::lower_bound; -struct LowerBoundIndex { - LowerBoundIndex() : value(-1), found(false) {} - LowerBoundIndex(Index val, bool ok) : value(val), found(ok) {} - Index value; - bool found; -}; - -} // end namespace internal - -/** \ingroup SparseCore_Module - * - * \class Triplet - * - * \brief A small structure to hold a non zero as a triplet (i,j,value). - * - * \sa SparseMatrix::setFromTriplets() - */ -template<typename Scalar, typename StorageIndex=typename SparseMatrix<Scalar>::StorageIndex > -class Triplet -{ -public: - Triplet() : m_row(0), m_col(0), m_value(0) {} - - Triplet(const StorageIndex& i, const StorageIndex& j, const Scalar& v = Scalar(0)) - : m_row(i), m_col(j), m_value(v) - {} - - /** \returns the row index of the element */ - const StorageIndex& row() const { return m_row; } - - /** \returns the column index of the element */ - const StorageIndex& col() const { return m_col; } - - /** \returns the value of the element */ - const Scalar& value() const { return m_value; } -protected: - StorageIndex m_row, m_col; - Scalar m_value; -}; - -} // end namespace Eigen - -#endif // EIGEN_SPARSEUTIL_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseVector.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseVector.h deleted file mode 100644 index 05779be6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseVector.h +++ /dev/null @@ -1,478 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEVECTOR_H -#define EIGEN_SPARSEVECTOR_H - -namespace Eigen { - -/** \ingroup SparseCore_Module - * \class SparseVector - * - * \brief a sparse vector class - * - * \tparam _Scalar the scalar type, i.e. the type of the coefficients - * - * See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme. - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_SPARSEVECTOR_PLUGIN. - */ - -namespace internal { -template<typename _Scalar, int _Options, typename _StorageIndex> -struct traits<SparseVector<_Scalar, _Options, _StorageIndex> > -{ - typedef _Scalar Scalar; - typedef _StorageIndex StorageIndex; - typedef Sparse StorageKind; - typedef MatrixXpr XprKind; - enum { - IsColVector = (_Options & RowMajorBit) ? 0 : 1, - - RowsAtCompileTime = IsColVector ? Dynamic : 1, - ColsAtCompileTime = IsColVector ? 1 : Dynamic, - MaxRowsAtCompileTime = RowsAtCompileTime, - MaxColsAtCompileTime = ColsAtCompileTime, - Flags = _Options | NestByRefBit | LvalueBit | (IsColVector ? 0 : RowMajorBit) | CompressedAccessBit, - SupportedAccessPatterns = InnerRandomAccessPattern - }; -}; - -// Sparse-Vector-Assignment kinds: -enum { - SVA_RuntimeSwitch, - SVA_Inner, - SVA_Outer -}; - -template< typename Dest, typename Src, - int AssignmentKind = !bool(Src::IsVectorAtCompileTime) ? SVA_RuntimeSwitch - : Src::InnerSizeAtCompileTime==1 ? SVA_Outer - : SVA_Inner> -struct sparse_vector_assign_selector; - -} - -template<typename _Scalar, int _Options, typename _StorageIndex> -class SparseVector - : public SparseCompressedBase<SparseVector<_Scalar, _Options, _StorageIndex> > -{ - typedef SparseCompressedBase<SparseVector> Base; - using Base::convert_index; - public: - EIGEN_SPARSE_PUBLIC_INTERFACE(SparseVector) - EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, +=) - EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, -=) - - typedef internal::CompressedStorage<Scalar,StorageIndex> Storage; - enum { IsColVector = internal::traits<SparseVector>::IsColVector }; - - enum { - Options = _Options - }; - - EIGEN_STRONG_INLINE Index rows() const { return IsColVector ? m_size : 1; } - EIGEN_STRONG_INLINE Index cols() const { return IsColVector ? 1 : m_size; } - EIGEN_STRONG_INLINE Index innerSize() const { return m_size; } - EIGEN_STRONG_INLINE Index outerSize() const { return 1; } - - EIGEN_STRONG_INLINE const Scalar* valuePtr() const { return m_data.valuePtr(); } - EIGEN_STRONG_INLINE Scalar* valuePtr() { return m_data.valuePtr(); } - - EIGEN_STRONG_INLINE const StorageIndex* innerIndexPtr() const { return m_data.indexPtr(); } - EIGEN_STRONG_INLINE StorageIndex* innerIndexPtr() { return m_data.indexPtr(); } - - inline const StorageIndex* outerIndexPtr() const { return 0; } - inline StorageIndex* outerIndexPtr() { return 0; } - inline const StorageIndex* innerNonZeroPtr() const { return 0; } - inline StorageIndex* innerNonZeroPtr() { return 0; } - - /** \internal */ - inline Storage& data() { return m_data; } - /** \internal */ - inline const Storage& data() const { return m_data; } - - inline Scalar coeff(Index row, Index col) const - { - eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size)); - return coeff(IsColVector ? row : col); - } - inline Scalar coeff(Index i) const - { - eigen_assert(i>=0 && i<m_size); - return m_data.at(StorageIndex(i)); - } - - inline Scalar& coeffRef(Index row, Index col) - { - eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size)); - return coeffRef(IsColVector ? row : col); - } - - /** \returns a reference to the coefficient value at given index \a i - * This operation involes a log(rho*size) binary search. If the coefficient does not - * exist yet, then a sorted insertion into a sequential buffer is performed. - * - * This insertion might be very costly if the number of nonzeros above \a i is large. - */ - inline Scalar& coeffRef(Index i) - { - eigen_assert(i>=0 && i<m_size); - - return m_data.atWithInsertion(StorageIndex(i)); - } - - public: - - typedef typename Base::InnerIterator InnerIterator; - typedef typename Base::ReverseInnerIterator ReverseInnerIterator; - - inline void setZero() { m_data.clear(); } - - /** \returns the number of non zero coefficients */ - inline Index nonZeros() const { return m_data.size(); } - - inline void startVec(Index outer) - { - EIGEN_UNUSED_VARIABLE(outer); - eigen_assert(outer==0); - } - - inline Scalar& insertBackByOuterInner(Index outer, Index inner) - { - EIGEN_UNUSED_VARIABLE(outer); - eigen_assert(outer==0); - return insertBack(inner); - } - inline Scalar& insertBack(Index i) - { - m_data.append(0, i); - return m_data.value(m_data.size()-1); - } - - Scalar& insertBackByOuterInnerUnordered(Index outer, Index inner) - { - EIGEN_UNUSED_VARIABLE(outer); - eigen_assert(outer==0); - return insertBackUnordered(inner); - } - inline Scalar& insertBackUnordered(Index i) - { - m_data.append(0, i); - return m_data.value(m_data.size()-1); - } - - inline Scalar& insert(Index row, Index col) - { - eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size)); - - Index inner = IsColVector ? row : col; - Index outer = IsColVector ? col : row; - EIGEN_ONLY_USED_FOR_DEBUG(outer); - eigen_assert(outer==0); - return insert(inner); - } - Scalar& insert(Index i) - { - eigen_assert(i>=0 && i<m_size); - - Index startId = 0; - Index p = Index(m_data.size()) - 1; - // TODO smart realloc - m_data.resize(p+2,1); - - while ( (p >= startId) && (m_data.index(p) > i) ) - { - m_data.index(p+1) = m_data.index(p); - m_data.value(p+1) = m_data.value(p); - --p; - } - m_data.index(p+1) = convert_index(i); - m_data.value(p+1) = 0; - return m_data.value(p+1); - } - - /** - */ - inline void reserve(Index reserveSize) { m_data.reserve(reserveSize); } - - - inline void finalize() {} - - /** \copydoc SparseMatrix::prune(const Scalar&,const RealScalar&) */ - void prune(const Scalar& reference, const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision()) - { - m_data.prune(reference,epsilon); - } - - /** Resizes the sparse vector to \a rows x \a cols - * - * This method is provided for compatibility with matrices. - * For a column vector, \a cols must be equal to 1. - * For a row vector, \a rows must be equal to 1. - * - * \sa resize(Index) - */ - void resize(Index rows, Index cols) - { - eigen_assert((IsColVector ? cols : rows)==1 && "Outer dimension must equal 1"); - resize(IsColVector ? rows : cols); - } - - /** Resizes the sparse vector to \a newSize - * This method deletes all entries, thus leaving an empty sparse vector - * - * \sa conservativeResize(), setZero() */ - void resize(Index newSize) - { - m_size = newSize; - m_data.clear(); - } - - /** Resizes the sparse vector to \a newSize, while leaving old values untouched. - * - * If the size of the vector is decreased, then the storage of the out-of bounds coefficients is kept and reserved. - * Call .data().squeeze() to free extra memory. - * - * \sa reserve(), setZero() - */ - void conservativeResize(Index newSize) - { - if (newSize < m_size) - { - Index i = 0; - while (i<m_data.size() && m_data.index(i)<newSize) ++i; - m_data.resize(i); - } - m_size = newSize; - } - - void resizeNonZeros(Index size) { m_data.resize(size); } - - inline SparseVector() : m_size(0) { check_template_parameters(); resize(0); } - - explicit inline SparseVector(Index size) : m_size(0) { check_template_parameters(); resize(size); } - - inline SparseVector(Index rows, Index cols) : m_size(0) { check_template_parameters(); resize(rows,cols); } - - template<typename OtherDerived> - inline SparseVector(const SparseMatrixBase<OtherDerived>& other) - : m_size(0) - { - #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - #endif - check_template_parameters(); - *this = other.derived(); - } - - inline SparseVector(const SparseVector& other) - : Base(other), m_size(0) - { - check_template_parameters(); - *this = other.derived(); - } - - /** Swaps the values of \c *this and \a other. - * Overloaded for performance: this version performs a \em shallow swap by swapping pointers and attributes only. - * \sa SparseMatrixBase::swap() - */ - inline void swap(SparseVector& other) - { - std::swap(m_size, other.m_size); - m_data.swap(other.m_data); - } - - template<int OtherOptions> - inline void swap(SparseMatrix<Scalar,OtherOptions,StorageIndex>& other) - { - eigen_assert(other.outerSize()==1); - std::swap(m_size, other.m_innerSize); - m_data.swap(other.m_data); - } - - inline SparseVector& operator=(const SparseVector& other) - { - if (other.isRValue()) - { - swap(other.const_cast_derived()); - } - else - { - resize(other.size()); - m_data = other.m_data; - } - return *this; - } - - template<typename OtherDerived> - inline SparseVector& operator=(const SparseMatrixBase<OtherDerived>& other) - { - SparseVector tmp(other.size()); - internal::sparse_vector_assign_selector<SparseVector,OtherDerived>::run(tmp,other.derived()); - this->swap(tmp); - return *this; - } - - #ifndef EIGEN_PARSED_BY_DOXYGEN - template<typename Lhs, typename Rhs> - inline SparseVector& operator=(const SparseSparseProduct<Lhs,Rhs>& product) - { - return Base::operator=(product); - } - #endif - - friend std::ostream & operator << (std::ostream & s, const SparseVector& m) - { - for (Index i=0; i<m.nonZeros(); ++i) - s << "(" << m.m_data.value(i) << "," << m.m_data.index(i) << ") "; - s << std::endl; - return s; - } - - /** Destructor */ - inline ~SparseVector() {} - - /** Overloaded for performance */ - Scalar sum() const; - - public: - - /** \internal \deprecated use setZero() and reserve() */ - EIGEN_DEPRECATED void startFill(Index reserve) - { - setZero(); - m_data.reserve(reserve); - } - - /** \internal \deprecated use insertBack(Index,Index) */ - EIGEN_DEPRECATED Scalar& fill(Index r, Index c) - { - eigen_assert(r==0 || c==0); - return fill(IsColVector ? r : c); - } - - /** \internal \deprecated use insertBack(Index) */ - EIGEN_DEPRECATED Scalar& fill(Index i) - { - m_data.append(0, i); - return m_data.value(m_data.size()-1); - } - - /** \internal \deprecated use insert(Index,Index) */ - EIGEN_DEPRECATED Scalar& fillrand(Index r, Index c) - { - eigen_assert(r==0 || c==0); - return fillrand(IsColVector ? r : c); - } - - /** \internal \deprecated use insert(Index) */ - EIGEN_DEPRECATED Scalar& fillrand(Index i) - { - return insert(i); - } - - /** \internal \deprecated use finalize() */ - EIGEN_DEPRECATED void endFill() {} - - // These two functions were here in the 3.1 release, so let's keep them in case some code rely on them. - /** \internal \deprecated use data() */ - EIGEN_DEPRECATED Storage& _data() { return m_data; } - /** \internal \deprecated use data() */ - EIGEN_DEPRECATED const Storage& _data() const { return m_data; } - -# ifdef EIGEN_SPARSEVECTOR_PLUGIN -# include EIGEN_SPARSEVECTOR_PLUGIN -# endif - -protected: - - static void check_template_parameters() - { - EIGEN_STATIC_ASSERT(NumTraits<StorageIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE); - EIGEN_STATIC_ASSERT((_Options&(ColMajor|RowMajor))==Options,INVALID_MATRIX_TEMPLATE_PARAMETERS); - } - - Storage m_data; - Index m_size; -}; - -namespace internal { - -template<typename _Scalar, int _Options, typename _Index> -struct evaluator<SparseVector<_Scalar,_Options,_Index> > - : evaluator_base<SparseVector<_Scalar,_Options,_Index> > -{ - typedef SparseVector<_Scalar,_Options,_Index> SparseVectorType; - typedef evaluator_base<SparseVectorType> Base; - typedef typename SparseVectorType::InnerIterator InnerIterator; - typedef typename SparseVectorType::ReverseInnerIterator ReverseInnerIterator; - - enum { - CoeffReadCost = NumTraits<_Scalar>::ReadCost, - Flags = SparseVectorType::Flags - }; - - evaluator() : Base() {} - - explicit evaluator(const SparseVectorType &mat) : m_matrix(&mat) - { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - inline Index nonZerosEstimate() const { - return m_matrix->nonZeros(); - } - - operator SparseVectorType&() { return m_matrix->const_cast_derived(); } - operator const SparseVectorType&() const { return *m_matrix; } - - const SparseVectorType *m_matrix; -}; - -template< typename Dest, typename Src> -struct sparse_vector_assign_selector<Dest,Src,SVA_Inner> { - static void run(Dest& dst, const Src& src) { - eigen_internal_assert(src.innerSize()==src.size()); - typedef internal::evaluator<Src> SrcEvaluatorType; - SrcEvaluatorType srcEval(src); - for(typename SrcEvaluatorType::InnerIterator it(srcEval, 0); it; ++it) - dst.insert(it.index()) = it.value(); - } -}; - -template< typename Dest, typename Src> -struct sparse_vector_assign_selector<Dest,Src,SVA_Outer> { - static void run(Dest& dst, const Src& src) { - eigen_internal_assert(src.outerSize()==src.size()); - typedef internal::evaluator<Src> SrcEvaluatorType; - SrcEvaluatorType srcEval(src); - for(Index i=0; i<src.size(); ++i) - { - typename SrcEvaluatorType::InnerIterator it(srcEval, i); - if(it) - dst.insert(i) = it.value(); - } - } -}; - -template< typename Dest, typename Src> -struct sparse_vector_assign_selector<Dest,Src,SVA_RuntimeSwitch> { - static void run(Dest& dst, const Src& src) { - if(src.outerSize()==1) sparse_vector_assign_selector<Dest,Src,SVA_Inner>::run(dst, src); - else sparse_vector_assign_selector<Dest,Src,SVA_Outer>::run(dst, src); - } -}; - -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSEVECTOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseView.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseView.h deleted file mode 100644 index 92b3d1f7..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/SparseView.h +++ /dev/null @@ -1,254 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Daniel Lowengrub <lowdanie@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEVIEW_H -#define EIGEN_SPARSEVIEW_H - -namespace Eigen { - -namespace internal { - -template<typename MatrixType> -struct traits<SparseView<MatrixType> > : traits<MatrixType> -{ - typedef typename MatrixType::StorageIndex StorageIndex; - typedef Sparse StorageKind; - enum { - Flags = int(traits<MatrixType>::Flags) & (RowMajorBit) - }; -}; - -} // end namespace internal - -/** \ingroup SparseCore_Module - * \class SparseView - * - * \brief Expression of a dense or sparse matrix with zero or too small values removed - * - * \tparam MatrixType the type of the object of which we are removing the small entries - * - * This class represents an expression of a given dense or sparse matrix with - * entries smaller than \c reference * \c epsilon are removed. - * It is the return type of MatrixBase::sparseView() and SparseMatrixBase::pruned() - * and most of the time this is the only way it is used. - * - * \sa MatrixBase::sparseView(), SparseMatrixBase::pruned() - */ -template<typename MatrixType> -class SparseView : public SparseMatrixBase<SparseView<MatrixType> > -{ - typedef typename MatrixType::Nested MatrixTypeNested; - typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested; - typedef SparseMatrixBase<SparseView > Base; -public: - EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView) - typedef typename internal::remove_all<MatrixType>::type NestedExpression; - - explicit SparseView(const MatrixType& mat, const Scalar& reference = Scalar(0), - const RealScalar &epsilon = NumTraits<Scalar>::dummy_precision()) - : m_matrix(mat), m_reference(reference), m_epsilon(epsilon) {} - - inline Index rows() const { return m_matrix.rows(); } - inline Index cols() const { return m_matrix.cols(); } - - inline Index innerSize() const { return m_matrix.innerSize(); } - inline Index outerSize() const { return m_matrix.outerSize(); } - - /** \returns the nested expression */ - const typename internal::remove_all<MatrixTypeNested>::type& - nestedExpression() const { return m_matrix; } - - Scalar reference() const { return m_reference; } - RealScalar epsilon() const { return m_epsilon; } - -protected: - MatrixTypeNested m_matrix; - Scalar m_reference; - RealScalar m_epsilon; -}; - -namespace internal { - -// TODO find a way to unify the two following variants -// This is tricky because implementing an inner iterator on top of an IndexBased evaluator is -// not easy because the evaluators do not expose the sizes of the underlying expression. - -template<typename ArgType> -struct unary_evaluator<SparseView<ArgType>, IteratorBased> - : public evaluator_base<SparseView<ArgType> > -{ - typedef typename evaluator<ArgType>::InnerIterator EvalIterator; - public: - typedef SparseView<ArgType> XprType; - - class InnerIterator : public EvalIterator - { - protected: - typedef typename XprType::Scalar Scalar; - public: - - EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& sve, Index outer) - : EvalIterator(sve.m_argImpl,outer), m_view(sve.m_view) - { - incrementToNonZero(); - } - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - EvalIterator::operator++(); - incrementToNonZero(); - return *this; - } - - using EvalIterator::value; - - protected: - const XprType &m_view; - - private: - void incrementToNonZero() - { - while((bool(*this)) && internal::isMuchSmallerThan(value(), m_view.reference(), m_view.epsilon())) - { - EvalIterator::operator++(); - } - } - }; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - Flags = XprType::Flags - }; - - explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {} - - protected: - evaluator<ArgType> m_argImpl; - const XprType &m_view; -}; - -template<typename ArgType> -struct unary_evaluator<SparseView<ArgType>, IndexBased> - : public evaluator_base<SparseView<ArgType> > -{ - public: - typedef SparseView<ArgType> XprType; - protected: - enum { IsRowMajor = (XprType::Flags&RowMajorBit)==RowMajorBit }; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::StorageIndex StorageIndex; - public: - - class InnerIterator - { - public: - - EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& sve, Index outer) - : m_sve(sve), m_inner(0), m_outer(outer), m_end(sve.m_view.innerSize()) - { - incrementToNonZero(); - } - - EIGEN_STRONG_INLINE InnerIterator& operator++() - { - m_inner++; - incrementToNonZero(); - return *this; - } - - EIGEN_STRONG_INLINE Scalar value() const - { - return (IsRowMajor) ? m_sve.m_argImpl.coeff(m_outer, m_inner) - : m_sve.m_argImpl.coeff(m_inner, m_outer); - } - - EIGEN_STRONG_INLINE StorageIndex index() const { return m_inner; } - inline Index row() const { return IsRowMajor ? m_outer : index(); } - inline Index col() const { return IsRowMajor ? index() : m_outer; } - - EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; } - - protected: - const unary_evaluator &m_sve; - Index m_inner; - const Index m_outer; - const Index m_end; - - private: - void incrementToNonZero() - { - while((bool(*this)) && internal::isMuchSmallerThan(value(), m_sve.m_view.reference(), m_sve.m_view.epsilon())) - { - m_inner++; - } - } - }; - - enum { - CoeffReadCost = evaluator<ArgType>::CoeffReadCost, - Flags = XprType::Flags - }; - - explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {} - - protected: - evaluator<ArgType> m_argImpl; - const XprType &m_view; -}; - -} // end namespace internal - -/** \ingroup SparseCore_Module - * - * \returns a sparse expression of the dense expression \c *this with values smaller than - * \a reference * \a epsilon removed. - * - * This method is typically used when prototyping to convert a quickly assembled dense Matrix \c D to a SparseMatrix \c S: - * \code - * MatrixXd D(n,m); - * SparseMatrix<double> S; - * S = D.sparseView(); // suppress numerical zeros (exact) - * S = D.sparseView(reference); - * S = D.sparseView(reference,epsilon); - * \endcode - * where \a reference is a meaningful non zero reference value, - * and \a epsilon is a tolerance factor defaulting to NumTraits<Scalar>::dummy_precision(). - * - * \sa SparseMatrixBase::pruned(), class SparseView */ -template<typename Derived> -const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar& reference, - const typename NumTraits<Scalar>::Real& epsilon) const -{ - return SparseView<Derived>(derived(), reference, epsilon); -} - -/** \returns an expression of \c *this with values smaller than - * \a reference * \a epsilon removed. - * - * This method is typically used in conjunction with the product of two sparse matrices - * to automatically prune the smallest values as follows: - * \code - * C = (A*B).pruned(); // suppress numerical zeros (exact) - * C = (A*B).pruned(ref); - * C = (A*B).pruned(ref,epsilon); - * \endcode - * where \c ref is a meaningful non zero reference value. - * */ -template<typename Derived> -const SparseView<Derived> -SparseMatrixBase<Derived>::pruned(const Scalar& reference, - const RealScalar& epsilon) const -{ - return SparseView<Derived>(derived(), reference, epsilon); -} - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/SparseCore/TriangularSolver.h b/external/eigen/include/eigen3/Eigen/src/SparseCore/TriangularSolver.h deleted file mode 100644 index f9c56ba7..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseCore/TriangularSolver.h +++ /dev/null @@ -1,315 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSETRIANGULARSOLVER_H -#define EIGEN_SPARSETRIANGULARSOLVER_H - -namespace Eigen { - -namespace internal { - -template<typename Lhs, typename Rhs, int Mode, - int UpLo = (Mode & Lower) - ? Lower - : (Mode & Upper) - ? Upper - : -1, - int StorageOrder = int(traits<Lhs>::Flags) & RowMajorBit> -struct sparse_solve_triangular_selector; - -// forward substitution, row-major -template<typename Lhs, typename Rhs, int Mode> -struct sparse_solve_triangular_selector<Lhs,Rhs,Mode,Lower,RowMajor> -{ - typedef typename Rhs::Scalar Scalar; - typedef evaluator<Lhs> LhsEval; - typedef typename evaluator<Lhs>::InnerIterator LhsIterator; - static void run(const Lhs& lhs, Rhs& other) - { - LhsEval lhsEval(lhs); - for(Index col=0 ; col<other.cols() ; ++col) - { - for(Index i=0; i<lhs.rows(); ++i) - { - Scalar tmp = other.coeff(i,col); - Scalar lastVal(0); - Index lastIndex = 0; - for(LhsIterator it(lhsEval, i); it; ++it) - { - lastVal = it.value(); - lastIndex = it.index(); - if(lastIndex==i) - break; - tmp -= lastVal * other.coeff(lastIndex,col); - } - if (Mode & UnitDiag) - other.coeffRef(i,col) = tmp; - else - { - eigen_assert(lastIndex==i); - other.coeffRef(i,col) = tmp/lastVal; - } - } - } - } -}; - -// backward substitution, row-major -template<typename Lhs, typename Rhs, int Mode> -struct sparse_solve_triangular_selector<Lhs,Rhs,Mode,Upper,RowMajor> -{ - typedef typename Rhs::Scalar Scalar; - typedef evaluator<Lhs> LhsEval; - typedef typename evaluator<Lhs>::InnerIterator LhsIterator; - static void run(const Lhs& lhs, Rhs& other) - { - LhsEval lhsEval(lhs); - for(Index col=0 ; col<other.cols() ; ++col) - { - for(Index i=lhs.rows()-1 ; i>=0 ; --i) - { - Scalar tmp = other.coeff(i,col); - Scalar l_ii(0); - LhsIterator it(lhsEval, i); - while(it && it.index()<i) - ++it; - if(!(Mode & UnitDiag)) - { - eigen_assert(it && it.index()==i); - l_ii = it.value(); - ++it; - } - else if (it && it.index() == i) - ++it; - for(; it; ++it) - { - tmp -= it.value() * other.coeff(it.index(),col); - } - - if (Mode & UnitDiag) other.coeffRef(i,col) = tmp; - else other.coeffRef(i,col) = tmp/l_ii; - } - } - } -}; - -// forward substitution, col-major -template<typename Lhs, typename Rhs, int Mode> -struct sparse_solve_triangular_selector<Lhs,Rhs,Mode,Lower,ColMajor> -{ - typedef typename Rhs::Scalar Scalar; - typedef evaluator<Lhs> LhsEval; - typedef typename evaluator<Lhs>::InnerIterator LhsIterator; - static void run(const Lhs& lhs, Rhs& other) - { - LhsEval lhsEval(lhs); - for(Index col=0 ; col<other.cols() ; ++col) - { - for(Index i=0; i<lhs.cols(); ++i) - { - Scalar& tmp = other.coeffRef(i,col); - if (tmp!=Scalar(0)) // optimization when other is actually sparse - { - LhsIterator it(lhsEval, i); - while(it && it.index()<i) - ++it; - if(!(Mode & UnitDiag)) - { - eigen_assert(it && it.index()==i); - tmp /= it.value(); - } - if (it && it.index()==i) - ++it; - for(; it; ++it) - other.coeffRef(it.index(), col) -= tmp * it.value(); - } - } - } - } -}; - -// backward substitution, col-major -template<typename Lhs, typename Rhs, int Mode> -struct sparse_solve_triangular_selector<Lhs,Rhs,Mode,Upper,ColMajor> -{ - typedef typename Rhs::Scalar Scalar; - typedef evaluator<Lhs> LhsEval; - typedef typename evaluator<Lhs>::InnerIterator LhsIterator; - static void run(const Lhs& lhs, Rhs& other) - { - LhsEval lhsEval(lhs); - for(Index col=0 ; col<other.cols() ; ++col) - { - for(Index i=lhs.cols()-1; i>=0; --i) - { - Scalar& tmp = other.coeffRef(i,col); - if (tmp!=Scalar(0)) // optimization when other is actually sparse - { - if(!(Mode & UnitDiag)) - { - // TODO replace this by a binary search. make sure the binary search is safe for partially sorted elements - LhsIterator it(lhsEval, i); - while(it && it.index()!=i) - ++it; - eigen_assert(it && it.index()==i); - other.coeffRef(i,col) /= it.value(); - } - LhsIterator it(lhsEval, i); - for(; it && it.index()<i; ++it) - other.coeffRef(it.index(), col) -= tmp * it.value(); - } - } - } - } -}; - -} // end namespace internal - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -template<typename ExpressionType,unsigned int Mode> -template<typename OtherDerived> -void TriangularViewImpl<ExpressionType,Mode,Sparse>::solveInPlace(MatrixBase<OtherDerived>& other) const -{ - eigen_assert(derived().cols() == derived().rows() && derived().cols() == other.rows()); - eigen_assert((!(Mode & ZeroDiag)) && bool(Mode & (Upper|Lower))); - - enum { copy = internal::traits<OtherDerived>::Flags & RowMajorBit }; - - typedef typename internal::conditional<copy, - typename internal::plain_matrix_type_column_major<OtherDerived>::type, OtherDerived&>::type OtherCopy; - OtherCopy otherCopy(other.derived()); - - internal::sparse_solve_triangular_selector<ExpressionType, typename internal::remove_reference<OtherCopy>::type, Mode>::run(derived().nestedExpression(), otherCopy); - - if (copy) - other = otherCopy; -} -#endif - -// pure sparse path - -namespace internal { - -template<typename Lhs, typename Rhs, int Mode, - int UpLo = (Mode & Lower) - ? Lower - : (Mode & Upper) - ? Upper - : -1, - int StorageOrder = int(Lhs::Flags) & (RowMajorBit)> -struct sparse_solve_triangular_sparse_selector; - -// forward substitution, col-major -template<typename Lhs, typename Rhs, int Mode, int UpLo> -struct sparse_solve_triangular_sparse_selector<Lhs,Rhs,Mode,UpLo,ColMajor> -{ - typedef typename Rhs::Scalar Scalar; - typedef typename promote_index_type<typename traits<Lhs>::StorageIndex, - typename traits<Rhs>::StorageIndex>::type StorageIndex; - static void run(const Lhs& lhs, Rhs& other) - { - const bool IsLower = (UpLo==Lower); - AmbiVector<Scalar,StorageIndex> tempVector(other.rows()*2); - tempVector.setBounds(0,other.rows()); - - Rhs res(other.rows(), other.cols()); - res.reserve(other.nonZeros()); - - for(Index col=0 ; col<other.cols() ; ++col) - { - // FIXME estimate number of non zeros - tempVector.init(.99/*float(other.col(col).nonZeros())/float(other.rows())*/); - tempVector.setZero(); - tempVector.restart(); - for (typename Rhs::InnerIterator rhsIt(other, col); rhsIt; ++rhsIt) - { - tempVector.coeffRef(rhsIt.index()) = rhsIt.value(); - } - - for(Index i=IsLower?0:lhs.cols()-1; - IsLower?i<lhs.cols():i>=0; - i+=IsLower?1:-1) - { - tempVector.restart(); - Scalar& ci = tempVector.coeffRef(i); - if (ci!=Scalar(0)) - { - // find - typename Lhs::InnerIterator it(lhs, i); - if(!(Mode & UnitDiag)) - { - if (IsLower) - { - eigen_assert(it.index()==i); - ci /= it.value(); - } - else - ci /= lhs.coeff(i,i); - } - tempVector.restart(); - if (IsLower) - { - if (it.index()==i) - ++it; - for(; it; ++it) - tempVector.coeffRef(it.index()) -= ci * it.value(); - } - else - { - for(; it && it.index()<i; ++it) - tempVector.coeffRef(it.index()) -= ci * it.value(); - } - } - } - - - Index count = 0; - // FIXME compute a reference value to filter zeros - for (typename AmbiVector<Scalar,StorageIndex>::Iterator it(tempVector/*,1e-12*/); it; ++it) - { - ++ count; -// std::cerr << "fill " << it.index() << ", " << col << "\n"; -// std::cout << it.value() << " "; - // FIXME use insertBack - res.insert(it.index(), col) = it.value(); - } -// std::cout << "tempVector.nonZeros() == " << int(count) << " / " << (other.rows()) << "\n"; - } - res.finalize(); - other = res.markAsRValue(); - } -}; - -} // end namespace internal - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename ExpressionType,unsigned int Mode> -template<typename OtherDerived> -void TriangularViewImpl<ExpressionType,Mode,Sparse>::solveInPlace(SparseMatrixBase<OtherDerived>& other) const -{ - eigen_assert(derived().cols() == derived().rows() && derived().cols() == other.rows()); - eigen_assert( (!(Mode & ZeroDiag)) && bool(Mode & (Upper|Lower))); - -// enum { copy = internal::traits<OtherDerived>::Flags & RowMajorBit }; - -// typedef typename internal::conditional<copy, -// typename internal::plain_matrix_type_column_major<OtherDerived>::type, OtherDerived&>::type OtherCopy; -// OtherCopy otherCopy(other.derived()); - - internal::sparse_solve_triangular_sparse_selector<ExpressionType, OtherDerived, Mode>::run(derived().nestedExpression(), other.derived()); - -// if (copy) -// other = otherCopy; -} -#endif - -} // end namespace Eigen - -#endif // EIGEN_SPARSETRIANGULARSOLVER_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU.h deleted file mode 100644 index 090993ad..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU.h +++ /dev/null @@ -1,773 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2012-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_SPARSE_LU_H -#define EIGEN_SPARSE_LU_H - -namespace Eigen { - -template <typename _MatrixType, typename _OrderingType = COLAMDOrdering<typename _MatrixType::StorageIndex> > class SparseLU; -template <typename MappedSparseMatrixType> struct SparseLUMatrixLReturnType; -template <typename MatrixLType, typename MatrixUType> struct SparseLUMatrixUReturnType; - -/** \ingroup SparseLU_Module - * \class SparseLU - * - * \brief Sparse supernodal LU factorization for general matrices - * - * This class implements the supernodal LU factorization for general matrices. - * It uses the main techniques from the sequential SuperLU package - * (http://crd-legacy.lbl.gov/~xiaoye/SuperLU/). It handles transparently real - * and complex arithmetic with single and double precision, depending on the - * scalar type of your input matrix. - * The code has been optimized to provide BLAS-3 operations during supernode-panel updates. - * It benefits directly from the built-in high-performant Eigen BLAS routines. - * Moreover, when the size of a supernode is very small, the BLAS calls are avoided to - * enable a better optimization from the compiler. For best performance, - * you should compile it with NDEBUG flag to avoid the numerous bounds checking on vectors. - * - * An important parameter of this class is the ordering method. It is used to reorder the columns - * (and eventually the rows) of the matrix to reduce the number of new elements that are created during - * numerical factorization. The cheapest method available is COLAMD. - * See \link OrderingMethods_Module the OrderingMethods module \endlink for the list of - * built-in and external ordering methods. - * - * Simple example with key steps - * \code - * VectorXd x(n), b(n); - * SparseMatrix<double> A; - * SparseLU<SparseMatrix<double>, COLAMDOrdering<int> > solver; - * // fill A and b; - * // Compute the ordering permutation vector from the structural pattern of A - * solver.analyzePattern(A); - * // Compute the numerical factorization - * solver.factorize(A); - * //Use the factors to solve the linear system - * x = solver.solve(b); - * \endcode - * - * \warning The input matrix A should be in a \b compressed and \b column-major form. - * Otherwise an expensive copy will be made. You can call the inexpensive makeCompressed() to get a compressed matrix. - * - * \note Unlike the initial SuperLU implementation, there is no step to equilibrate the matrix. - * For badly scaled matrices, this step can be useful to reduce the pivoting during factorization. - * If this is the case for your matrices, you can try the basic scaling method at - * "unsupported/Eigen/src/IterativeSolvers/Scaling.h" - * - * \tparam _MatrixType The type of the sparse matrix. It must be a column-major SparseMatrix<> - * \tparam _OrderingType The ordering method to use, either AMD, COLAMD or METIS. Default is COLMAD - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept - * \sa \ref OrderingMethods_Module - */ -template <typename _MatrixType, typename _OrderingType> -class SparseLU : public SparseSolverBase<SparseLU<_MatrixType,_OrderingType> >, public internal::SparseLUImpl<typename _MatrixType::Scalar, typename _MatrixType::StorageIndex> -{ - protected: - typedef SparseSolverBase<SparseLU<_MatrixType,_OrderingType> > APIBase; - using APIBase::m_isInitialized; - public: - using APIBase::_solve_impl; - - typedef _MatrixType MatrixType; - typedef _OrderingType OrderingType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar,ColMajor,StorageIndex> NCMatrix; - typedef internal::MappedSuperNodalMatrix<Scalar, StorageIndex> SCMatrix; - typedef Matrix<Scalar,Dynamic,1> ScalarVector; - typedef Matrix<StorageIndex,Dynamic,1> IndexVector; - typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType; - typedef internal::SparseLUImpl<Scalar, StorageIndex> Base; - - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - public: - SparseLU():m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0),m_detPermR(1) - { - initperfvalues(); - } - explicit SparseLU(const MatrixType& matrix) - : m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0),m_detPermR(1) - { - initperfvalues(); - compute(matrix); - } - - ~SparseLU() - { - // Free all explicit dynamic pointers - } - - void analyzePattern (const MatrixType& matrix); - void factorize (const MatrixType& matrix); - void simplicialfactorize(const MatrixType& matrix); - - /** - * Compute the symbolic and numeric factorization of the input sparse matrix. - * The input matrix should be in column-major storage. - */ - void compute (const MatrixType& matrix) - { - // Analyze - analyzePattern(matrix); - //Factorize - factorize(matrix); - } - - inline Index rows() const { return m_mat.rows(); } - inline Index cols() const { return m_mat.cols(); } - /** Indicate that the pattern of the input matrix is symmetric */ - void isSymmetric(bool sym) - { - m_symmetricmode = sym; - } - - /** \returns an expression of the matrix L, internally stored as supernodes - * The only operation available with this expression is the triangular solve - * \code - * y = b; matrixL().solveInPlace(y); - * \endcode - */ - SparseLUMatrixLReturnType<SCMatrix> matrixL() const - { - return SparseLUMatrixLReturnType<SCMatrix>(m_Lstore); - } - /** \returns an expression of the matrix U, - * The only operation available with this expression is the triangular solve - * \code - * y = b; matrixU().solveInPlace(y); - * \endcode - */ - SparseLUMatrixUReturnType<SCMatrix,MappedSparseMatrix<Scalar,ColMajor,StorageIndex> > matrixU() const - { - return SparseLUMatrixUReturnType<SCMatrix, MappedSparseMatrix<Scalar,ColMajor,StorageIndex> >(m_Lstore, m_Ustore); - } - - /** - * \returns a reference to the row matrix permutation \f$ P_r \f$ such that \f$P_r A P_c^T = L U\f$ - * \sa colsPermutation() - */ - inline const PermutationType& rowsPermutation() const - { - return m_perm_r; - } - /** - * \returns a reference to the column matrix permutation\f$ P_c^T \f$ such that \f$P_r A P_c^T = L U\f$ - * \sa rowsPermutation() - */ - inline const PermutationType& colsPermutation() const - { - return m_perm_c; - } - /** Set the threshold used for a diagonal entry to be an acceptable pivot. */ - void setPivotThreshold(const RealScalar& thresh) - { - m_diagpivotthresh = thresh; - } - -#ifdef EIGEN_PARSED_BY_DOXYGEN - /** \returns the solution X of \f$ A X = B \f$ using the current decomposition of A. - * - * \warning the destination matrix X in X = this->solve(B) must be colmun-major. - * - * \sa compute() - */ - template<typename Rhs> - inline const Solve<SparseLU, Rhs> solve(const MatrixBase<Rhs>& B) const; -#endif // EIGEN_PARSED_BY_DOXYGEN - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the LU factorization reports a problem, zero diagonal for instance - * \c InvalidInput if the input matrix is invalid - * - * \sa iparm() - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - - /** - * \returns A string describing the type of error - */ - std::string lastErrorMessage() const - { - return m_lastError; - } - - template<typename Rhs, typename Dest> - bool _solve_impl(const MatrixBase<Rhs> &B, MatrixBase<Dest> &X_base) const - { - Dest& X(X_base.derived()); - eigen_assert(m_factorizationIsOk && "The matrix should be factorized first"); - EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0, - THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); - - // Permute the right hand side to form X = Pr*B - // on return, X is overwritten by the computed solution - X.resize(B.rows(),B.cols()); - - // this ugly const_cast_derived() helps to detect aliasing when applying the permutations - for(Index j = 0; j < B.cols(); ++j) - X.col(j) = rowsPermutation() * B.const_cast_derived().col(j); - - //Forward substitution with L - this->matrixL().solveInPlace(X); - this->matrixU().solveInPlace(X); - - // Permute back the solution - for (Index j = 0; j < B.cols(); ++j) - X.col(j) = colsPermutation().inverse() * X.col(j); - - return true; - } - - /** - * \returns the absolute value of the determinant of the matrix of which - * *this is the QR decomposition. - * - * \warning a determinant can be very big or small, so for matrices - * of large enough dimension, there is a risk of overflow/underflow. - * One way to work around that is to use logAbsDeterminant() instead. - * - * \sa logAbsDeterminant(), signDeterminant() - */ - Scalar absDeterminant() - { - using std::abs; - eigen_assert(m_factorizationIsOk && "The matrix should be factorized first."); - // Initialize with the determinant of the row matrix - Scalar det = Scalar(1.); - // Note that the diagonal blocks of U are stored in supernodes, - // which are available in the L part :) - for (Index j = 0; j < this->cols(); ++j) - { - for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) - { - if(it.index() == j) - { - det *= abs(it.value()); - break; - } - } - } - return det; - } - - /** \returns the natural log of the absolute value of the determinant of the matrix - * of which **this is the QR decomposition - * - * \note This method is useful to work around the risk of overflow/underflow that's - * inherent to the determinant computation. - * - * \sa absDeterminant(), signDeterminant() - */ - Scalar logAbsDeterminant() const - { - using std::log; - using std::abs; - - eigen_assert(m_factorizationIsOk && "The matrix should be factorized first."); - Scalar det = Scalar(0.); - for (Index j = 0; j < this->cols(); ++j) - { - for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) - { - if(it.row() < j) continue; - if(it.row() == j) - { - det += log(abs(it.value())); - break; - } - } - } - return det; - } - - /** \returns A number representing the sign of the determinant - * - * \sa absDeterminant(), logAbsDeterminant() - */ - Scalar signDeterminant() - { - eigen_assert(m_factorizationIsOk && "The matrix should be factorized first."); - // Initialize with the determinant of the row matrix - Index det = 1; - // Note that the diagonal blocks of U are stored in supernodes, - // which are available in the L part :) - for (Index j = 0; j < this->cols(); ++j) - { - for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) - { - if(it.index() == j) - { - if(it.value()<0) - det = -det; - else if(it.value()==0) - return 0; - break; - } - } - } - return det * m_detPermR * m_detPermC; - } - - /** \returns The determinant of the matrix. - * - * \sa absDeterminant(), logAbsDeterminant() - */ - Scalar determinant() - { - eigen_assert(m_factorizationIsOk && "The matrix should be factorized first."); - // Initialize with the determinant of the row matrix - Scalar det = Scalar(1.); - // Note that the diagonal blocks of U are stored in supernodes, - // which are available in the L part :) - for (Index j = 0; j < this->cols(); ++j) - { - for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) - { - if(it.index() == j) - { - det *= it.value(); - break; - } - } - } - return (m_detPermR * m_detPermC) > 0 ? det : -det; - } - - protected: - // Functions - void initperfvalues() - { - m_perfv.panel_size = 16; - m_perfv.relax = 1; - m_perfv.maxsuper = 128; - m_perfv.rowblk = 16; - m_perfv.colblk = 8; - m_perfv.fillfactor = 20; - } - - // Variables - mutable ComputationInfo m_info; - bool m_factorizationIsOk; - bool m_analysisIsOk; - std::string m_lastError; - NCMatrix m_mat; // The input (permuted ) matrix - SCMatrix m_Lstore; // The lower triangular matrix (supernodal) - MappedSparseMatrix<Scalar,ColMajor,StorageIndex> m_Ustore; // The upper triangular matrix - PermutationType m_perm_c; // Column permutation - PermutationType m_perm_r ; // Row permutation - IndexVector m_etree; // Column elimination tree - - typename Base::GlobalLU_t m_glu; - - // SparseLU options - bool m_symmetricmode; - // values for performance - internal::perfvalues m_perfv; - RealScalar m_diagpivotthresh; // Specifies the threshold used for a diagonal entry to be an acceptable pivot - Index m_nnzL, m_nnzU; // Nonzeros in L and U factors - Index m_detPermR, m_detPermC; // Determinants of the permutation matrices - private: - // Disable copy constructor - SparseLU (const SparseLU& ); - -}; // End class SparseLU - - - -// Functions needed by the anaysis phase -/** - * Compute the column permutation to minimize the fill-in - * - * - Apply this permutation to the input matrix - - * - * - Compute the column elimination tree on the permuted matrix - * - * - Postorder the elimination tree and the column permutation - * - */ -template <typename MatrixType, typename OrderingType> -void SparseLU<MatrixType, OrderingType>::analyzePattern(const MatrixType& mat) -{ - - //TODO It is possible as in SuperLU to compute row and columns scaling vectors to equilibrate the matrix mat. - - // Firstly, copy the whole input matrix. - m_mat = mat; - - // Compute fill-in ordering - OrderingType ord; - ord(m_mat,m_perm_c); - - // Apply the permutation to the column of the input matrix - if (m_perm_c.size()) - { - m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. FIXME : This vector is filled but not subsequently used. - // Then, permute only the column pointers - ei_declare_aligned_stack_constructed_variable(StorageIndex,outerIndexPtr,mat.cols()+1,mat.isCompressed()?const_cast<StorageIndex*>(mat.outerIndexPtr()):0); - - // If the input matrix 'mat' is uncompressed, then the outer-indices do not match the ones of m_mat, and a copy is thus needed. - if(!mat.isCompressed()) - IndexVector::Map(outerIndexPtr, mat.cols()+1) = IndexVector::Map(m_mat.outerIndexPtr(),mat.cols()+1); - - // Apply the permutation and compute the nnz per column. - for (Index i = 0; i < mat.cols(); i++) - { - m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i]; - m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i]; - } - } - - // Compute the column elimination tree of the permuted matrix - IndexVector firstRowElt; - internal::coletree(m_mat, m_etree,firstRowElt); - - // In symmetric mode, do not do postorder here - if (!m_symmetricmode) { - IndexVector post, iwork; - // Post order etree - internal::treePostorder(StorageIndex(m_mat.cols()), m_etree, post); - - - // Renumber etree in postorder - Index m = m_mat.cols(); - iwork.resize(m+1); - for (Index i = 0; i < m; ++i) iwork(post(i)) = post(m_etree(i)); - m_etree = iwork; - - // Postmultiply A*Pc by post, i.e reorder the matrix according to the postorder of the etree - PermutationType post_perm(m); - for (Index i = 0; i < m; i++) - post_perm.indices()(i) = post(i); - - // Combine the two permutations : postorder the permutation for future use - if(m_perm_c.size()) { - m_perm_c = post_perm * m_perm_c; - } - - } // end postordering - - m_analysisIsOk = true; -} - -// Functions needed by the numerical factorization phase - - -/** - * - Numerical factorization - * - Interleaved with the symbolic factorization - * On exit, info is - * - * = 0: successful factorization - * - * > 0: if info = i, and i is - * - * <= A->ncol: U(i,i) is exactly zero. The factorization has - * been completed, but the factor U is exactly singular, - * and division by zero will occur if it is used to solve a - * system of equations. - * - * > A->ncol: number of bytes allocated when memory allocation - * failure occurred, plus A->ncol. If lwork = -1, it is - * the estimated amount of space needed, plus A->ncol. - */ -template <typename MatrixType, typename OrderingType> -void SparseLU<MatrixType, OrderingType>::factorize(const MatrixType& matrix) -{ - using internal::emptyIdxLU; - eigen_assert(m_analysisIsOk && "analyzePattern() should be called first"); - eigen_assert((matrix.rows() == matrix.cols()) && "Only for squared matrices"); - - m_isInitialized = true; - - // Apply the column permutation computed in analyzepattern() - // m_mat = matrix * m_perm_c.inverse(); - m_mat = matrix; - if (m_perm_c.size()) - { - m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. - //Then, permute only the column pointers - const StorageIndex * outerIndexPtr; - if (matrix.isCompressed()) outerIndexPtr = matrix.outerIndexPtr(); - else - { - StorageIndex* outerIndexPtr_t = new StorageIndex[matrix.cols()+1]; - for(Index i = 0; i <= matrix.cols(); i++) outerIndexPtr_t[i] = m_mat.outerIndexPtr()[i]; - outerIndexPtr = outerIndexPtr_t; - } - for (Index i = 0; i < matrix.cols(); i++) - { - m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i]; - m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i]; - } - if(!matrix.isCompressed()) delete[] outerIndexPtr; - } - else - { //FIXME This should not be needed if the empty permutation is handled transparently - m_perm_c.resize(matrix.cols()); - for(StorageIndex i = 0; i < matrix.cols(); ++i) m_perm_c.indices()(i) = i; - } - - Index m = m_mat.rows(); - Index n = m_mat.cols(); - Index nnz = m_mat.nonZeros(); - Index maxpanel = m_perfv.panel_size * m; - // Allocate working storage common to the factor routines - Index lwork = 0; - Index info = Base::memInit(m, n, nnz, lwork, m_perfv.fillfactor, m_perfv.panel_size, m_glu); - if (info) - { - m_lastError = "UNABLE TO ALLOCATE WORKING MEMORY\n\n" ; - m_factorizationIsOk = false; - return ; - } - - // Set up pointers for integer working arrays - IndexVector segrep(m); segrep.setZero(); - IndexVector parent(m); parent.setZero(); - IndexVector xplore(m); xplore.setZero(); - IndexVector repfnz(maxpanel); - IndexVector panel_lsub(maxpanel); - IndexVector xprune(n); xprune.setZero(); - IndexVector marker(m*internal::LUNoMarker); marker.setZero(); - - repfnz.setConstant(-1); - panel_lsub.setConstant(-1); - - // Set up pointers for scalar working arrays - ScalarVector dense; - dense.setZero(maxpanel); - ScalarVector tempv; - tempv.setZero(internal::LUnumTempV(m, m_perfv.panel_size, m_perfv.maxsuper, /*m_perfv.rowblk*/m) ); - - // Compute the inverse of perm_c - PermutationType iperm_c(m_perm_c.inverse()); - - // Identify initial relaxed snodes - IndexVector relax_end(n); - if ( m_symmetricmode == true ) - Base::heap_relax_snode(n, m_etree, m_perfv.relax, marker, relax_end); - else - Base::relax_snode(n, m_etree, m_perfv.relax, marker, relax_end); - - - m_perm_r.resize(m); - m_perm_r.indices().setConstant(-1); - marker.setConstant(-1); - m_detPermR = 1; // Record the determinant of the row permutation - - m_glu.supno(0) = emptyIdxLU; m_glu.xsup.setConstant(0); - m_glu.xsup(0) = m_glu.xlsub(0) = m_glu.xusub(0) = m_glu.xlusup(0) = Index(0); - - // Work on one 'panel' at a time. A panel is one of the following : - // (a) a relaxed supernode at the bottom of the etree, or - // (b) panel_size contiguous columns, <panel_size> defined by the user - Index jcol; - IndexVector panel_histo(n); - Index pivrow; // Pivotal row number in the original row matrix - Index nseg1; // Number of segments in U-column above panel row jcol - Index nseg; // Number of segments in each U-column - Index irep; - Index i, k, jj; - for (jcol = 0; jcol < n; ) - { - // Adjust panel size so that a panel won't overlap with the next relaxed snode. - Index panel_size = m_perfv.panel_size; // upper bound on panel width - for (k = jcol + 1; k < (std::min)(jcol+panel_size, n); k++) - { - if (relax_end(k) != emptyIdxLU) - { - panel_size = k - jcol; - break; - } - } - if (k == n) - panel_size = n - jcol; - - // Symbolic outer factorization on a panel of columns - Base::panel_dfs(m, panel_size, jcol, m_mat, m_perm_r.indices(), nseg1, dense, panel_lsub, segrep, repfnz, xprune, marker, parent, xplore, m_glu); - - // Numeric sup-panel updates in topological order - Base::panel_bmod(m, panel_size, jcol, nseg1, dense, tempv, segrep, repfnz, m_glu); - - // Sparse LU within the panel, and below the panel diagonal - for ( jj = jcol; jj< jcol + panel_size; jj++) - { - k = (jj - jcol) * m; // Column index for w-wide arrays - - nseg = nseg1; // begin after all the panel segments - //Depth-first-search for the current column - VectorBlock<IndexVector> panel_lsubk(panel_lsub, k, m); - VectorBlock<IndexVector> repfnz_k(repfnz, k, m); - info = Base::column_dfs(m, jj, m_perm_r.indices(), m_perfv.maxsuper, nseg, panel_lsubk, segrep, repfnz_k, xprune, marker, parent, xplore, m_glu); - if ( info ) - { - m_lastError = "UNABLE TO EXPAND MEMORY IN COLUMN_DFS() "; - m_info = NumericalIssue; - m_factorizationIsOk = false; - return; - } - // Numeric updates to this column - VectorBlock<ScalarVector> dense_k(dense, k, m); - VectorBlock<IndexVector> segrep_k(segrep, nseg1, m-nseg1); - info = Base::column_bmod(jj, (nseg - nseg1), dense_k, tempv, segrep_k, repfnz_k, jcol, m_glu); - if ( info ) - { - m_lastError = "UNABLE TO EXPAND MEMORY IN COLUMN_BMOD() "; - m_info = NumericalIssue; - m_factorizationIsOk = false; - return; - } - - // Copy the U-segments to ucol(*) - info = Base::copy_to_ucol(jj, nseg, segrep, repfnz_k ,m_perm_r.indices(), dense_k, m_glu); - if ( info ) - { - m_lastError = "UNABLE TO EXPAND MEMORY IN COPY_TO_UCOL() "; - m_info = NumericalIssue; - m_factorizationIsOk = false; - return; - } - - // Form the L-segment - info = Base::pivotL(jj, m_diagpivotthresh, m_perm_r.indices(), iperm_c.indices(), pivrow, m_glu); - if ( info ) - { - m_lastError = "THE MATRIX IS STRUCTURALLY SINGULAR ... ZERO COLUMN AT "; - std::ostringstream returnInfo; - returnInfo << info; - m_lastError += returnInfo.str(); - m_info = NumericalIssue; - m_factorizationIsOk = false; - return; - } - - // Update the determinant of the row permutation matrix - // FIXME: the following test is not correct, we should probably take iperm_c into account and pivrow is not directly the row pivot. - if (pivrow != jj) m_detPermR = -m_detPermR; - - // Prune columns (0:jj-1) using column jj - Base::pruneL(jj, m_perm_r.indices(), pivrow, nseg, segrep, repfnz_k, xprune, m_glu); - - // Reset repfnz for this column - for (i = 0; i < nseg; i++) - { - irep = segrep(i); - repfnz_k(irep) = emptyIdxLU; - } - } // end SparseLU within the panel - jcol += panel_size; // Move to the next panel - } // end for -- end elimination - - m_detPermR = m_perm_r.determinant(); - m_detPermC = m_perm_c.determinant(); - - // Count the number of nonzeros in factors - Base::countnz(n, m_nnzL, m_nnzU, m_glu); - // Apply permutation to the L subscripts - Base::fixupL(n, m_perm_r.indices(), m_glu); - - // Create supernode matrix L - m_Lstore.setInfos(m, n, m_glu.lusup, m_glu.xlusup, m_glu.lsub, m_glu.xlsub, m_glu.supno, m_glu.xsup); - // Create the column major upper sparse matrix U; - new (&m_Ustore) MappedSparseMatrix<Scalar, ColMajor, StorageIndex> ( m, n, m_nnzU, m_glu.xusub.data(), m_glu.usub.data(), m_glu.ucol.data() ); - - m_info = Success; - m_factorizationIsOk = true; -} - -template<typename MappedSupernodalType> -struct SparseLUMatrixLReturnType : internal::no_assignment_operator -{ - typedef typename MappedSupernodalType::Scalar Scalar; - explicit SparseLUMatrixLReturnType(const MappedSupernodalType& mapL) : m_mapL(mapL) - { } - Index rows() const { return m_mapL.rows(); } - Index cols() const { return m_mapL.cols(); } - template<typename Dest> - void solveInPlace( MatrixBase<Dest> &X) const - { - m_mapL.solveInPlace(X); - } - const MappedSupernodalType& m_mapL; -}; - -template<typename MatrixLType, typename MatrixUType> -struct SparseLUMatrixUReturnType : internal::no_assignment_operator -{ - typedef typename MatrixLType::Scalar Scalar; - SparseLUMatrixUReturnType(const MatrixLType& mapL, const MatrixUType& mapU) - : m_mapL(mapL),m_mapU(mapU) - { } - Index rows() const { return m_mapL.rows(); } - Index cols() const { return m_mapL.cols(); } - - template<typename Dest> void solveInPlace(MatrixBase<Dest> &X) const - { - Index nrhs = X.cols(); - Index n = X.rows(); - // Backward solve with U - for (Index k = m_mapL.nsuper(); k >= 0; k--) - { - Index fsupc = m_mapL.supToCol()[k]; - Index lda = m_mapL.colIndexPtr()[fsupc+1] - m_mapL.colIndexPtr()[fsupc]; // leading dimension - Index nsupc = m_mapL.supToCol()[k+1] - fsupc; - Index luptr = m_mapL.colIndexPtr()[fsupc]; - - if (nsupc == 1) - { - for (Index j = 0; j < nrhs; j++) - { - X(fsupc, j) /= m_mapL.valuePtr()[luptr]; - } - } - else - { - // FIXME: the following lines should use Block expressions and not Map! - Map<const Matrix<Scalar,Dynamic,Dynamic, ColMajor>, 0, OuterStride<> > A( &(m_mapL.valuePtr()[luptr]), nsupc, nsupc, OuterStride<>(lda) ); - Map< Matrix<Scalar,Dynamic,Dest::ColsAtCompileTime, ColMajor>, 0, OuterStride<> > U (&(X.coeffRef(fsupc,0)), nsupc, nrhs, OuterStride<>(n) ); - U = A.template triangularView<Upper>().solve(U); - } - - for (Index j = 0; j < nrhs; ++j) - { - for (Index jcol = fsupc; jcol < fsupc + nsupc; jcol++) - { - typename MatrixUType::InnerIterator it(m_mapU, jcol); - for ( ; it; ++it) - { - Index irow = it.index(); - X(irow, j) -= X(jcol, j) * it.value(); - } - } - } - } // End For U-solve - } - const MatrixLType& m_mapL; - const MatrixUType& m_mapU; -}; - -} // End namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLUImpl.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLUImpl.h deleted file mode 100644 index fc0cfc4d..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLUImpl.h +++ /dev/null @@ -1,66 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -#ifndef SPARSELU_IMPL_H -#define SPARSELU_IMPL_H - -namespace Eigen { -namespace internal { - -/** \ingroup SparseLU_Module - * \class SparseLUImpl - * Base class for sparseLU - */ -template <typename Scalar, typename StorageIndex> -class SparseLUImpl -{ - public: - typedef Matrix<Scalar,Dynamic,1> ScalarVector; - typedef Matrix<StorageIndex,Dynamic,1> IndexVector; - typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> ScalarMatrix; - typedef Map<ScalarMatrix, 0, OuterStride<> > MappedMatrixBlock; - typedef typename ScalarVector::RealScalar RealScalar; - typedef Ref<Matrix<Scalar,Dynamic,1> > BlockScalarVector; - typedef Ref<Matrix<StorageIndex,Dynamic,1> > BlockIndexVector; - typedef LU_GlobalLU_t<IndexVector, ScalarVector> GlobalLU_t; - typedef SparseMatrix<Scalar,ColMajor,StorageIndex> MatrixType; - - protected: - template <typename VectorType> - Index expand(VectorType& vec, Index& length, Index nbElts, Index keep_prev, Index& num_expansions); - Index memInit(Index m, Index n, Index annz, Index lwork, Index fillratio, Index panel_size, GlobalLU_t& glu); - template <typename VectorType> - Index memXpand(VectorType& vec, Index& maxlen, Index nbElts, MemType memtype, Index& num_expansions); - void heap_relax_snode (const Index n, IndexVector& et, const Index relax_columns, IndexVector& descendants, IndexVector& relax_end); - void relax_snode (const Index n, IndexVector& et, const Index relax_columns, IndexVector& descendants, IndexVector& relax_end); - Index snode_dfs(const Index jcol, const Index kcol,const MatrixType& mat, IndexVector& xprune, IndexVector& marker, GlobalLU_t& glu); - Index snode_bmod (const Index jcol, const Index fsupc, ScalarVector& dense, GlobalLU_t& glu); - Index pivotL(const Index jcol, const RealScalar& diagpivotthresh, IndexVector& perm_r, IndexVector& iperm_c, Index& pivrow, GlobalLU_t& glu); - template <typename Traits> - void dfs_kernel(const StorageIndex jj, IndexVector& perm_r, - Index& nseg, IndexVector& panel_lsub, IndexVector& segrep, - Ref<IndexVector> repfnz_col, IndexVector& xprune, Ref<IndexVector> marker, IndexVector& parent, - IndexVector& xplore, GlobalLU_t& glu, Index& nextl_col, Index krow, Traits& traits); - void panel_dfs(const Index m, const Index w, const Index jcol, MatrixType& A, IndexVector& perm_r, Index& nseg, ScalarVector& dense, IndexVector& panel_lsub, IndexVector& segrep, IndexVector& repfnz, IndexVector& xprune, IndexVector& marker, IndexVector& parent, IndexVector& xplore, GlobalLU_t& glu); - - void panel_bmod(const Index m, const Index w, const Index jcol, const Index nseg, ScalarVector& dense, ScalarVector& tempv, IndexVector& segrep, IndexVector& repfnz, GlobalLU_t& glu); - Index column_dfs(const Index m, const Index jcol, IndexVector& perm_r, Index maxsuper, Index& nseg, BlockIndexVector lsub_col, IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune, IndexVector& marker, IndexVector& parent, IndexVector& xplore, GlobalLU_t& glu); - Index column_bmod(const Index jcol, const Index nseg, BlockScalarVector dense, ScalarVector& tempv, BlockIndexVector segrep, BlockIndexVector repfnz, Index fpanelc, GlobalLU_t& glu); - Index copy_to_ucol(const Index jcol, const Index nseg, IndexVector& segrep, BlockIndexVector repfnz ,IndexVector& perm_r, BlockScalarVector dense, GlobalLU_t& glu); - void pruneL(const Index jcol, const IndexVector& perm_r, const Index pivrow, const Index nseg, const IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune, GlobalLU_t& glu); - void countnz(const Index n, Index& nnzL, Index& nnzU, GlobalLU_t& glu); - void fixupL(const Index n, const IndexVector& perm_r, GlobalLU_t& glu); - - template<typename , typename > - friend struct column_dfs_traits; -}; - -} // end namespace internal -} // namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Memory.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Memory.h deleted file mode 100644 index 349bfd58..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Memory.h +++ /dev/null @@ -1,226 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* - - * NOTE: This file is the modified version of [s,d,c,z]memory.c files in SuperLU - - * -- SuperLU routine (version 3.1) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * August 1, 2008 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ - -#ifndef EIGEN_SPARSELU_MEMORY -#define EIGEN_SPARSELU_MEMORY - -namespace Eigen { -namespace internal { - -enum { LUNoMarker = 3 }; -enum {emptyIdxLU = -1}; -inline Index LUnumTempV(Index& m, Index& w, Index& t, Index& b) -{ - return (std::max)(m, (t+b)*w); -} - -template< typename Scalar> -inline Index LUTempSpace(Index&m, Index& w) -{ - return (2*w + 4 + LUNoMarker) * m * sizeof(Index) + (w + 1) * m * sizeof(Scalar); -} - - - - -/** - * Expand the existing storage to accommodate more fill-ins - * \param vec Valid pointer to the vector to allocate or expand - * \param[in,out] length At input, contain the current length of the vector that is to be increased. At output, length of the newly allocated vector - * \param[in] nbElts Current number of elements in the factors - * \param keep_prev 1: use length and do not expand the vector; 0: compute new_len and expand - * \param[in,out] num_expansions Number of times the memory has been expanded - */ -template <typename Scalar, typename StorageIndex> -template <typename VectorType> -Index SparseLUImpl<Scalar,StorageIndex>::expand(VectorType& vec, Index& length, Index nbElts, Index keep_prev, Index& num_expansions) -{ - - float alpha = 1.5; // Ratio of the memory increase - Index new_len; // New size of the allocated memory - - if(num_expansions == 0 || keep_prev) - new_len = length ; // First time allocate requested - else - new_len = (std::max)(length+1,Index(alpha * length)); - - VectorType old_vec; // Temporary vector to hold the previous values - if (nbElts > 0 ) - old_vec = vec.segment(0,nbElts); - - //Allocate or expand the current vector -#ifdef EIGEN_EXCEPTIONS - try -#endif - { - vec.resize(new_len); - } -#ifdef EIGEN_EXCEPTIONS - catch(std::bad_alloc& ) -#else - if(!vec.size()) -#endif - { - if (!num_expansions) - { - // First time to allocate from LUMemInit() - // Let LUMemInit() deals with it. - return -1; - } - if (keep_prev) - { - // In this case, the memory length should not not be reduced - return new_len; - } - else - { - // Reduce the size and increase again - Index tries = 0; // Number of attempts - do - { - alpha = (alpha + 1)/2; - new_len = (std::max)(length+1,Index(alpha * length)); -#ifdef EIGEN_EXCEPTIONS - try -#endif - { - vec.resize(new_len); - } -#ifdef EIGEN_EXCEPTIONS - catch(std::bad_alloc& ) -#else - if (!vec.size()) -#endif - { - tries += 1; - if ( tries > 10) return new_len; - } - } while (!vec.size()); - } - } - //Copy the previous values to the newly allocated space - if (nbElts > 0) - vec.segment(0, nbElts) = old_vec; - - - length = new_len; - if(num_expansions) ++num_expansions; - return 0; -} - -/** - * \brief Allocate various working space for the numerical factorization phase. - * \param m number of rows of the input matrix - * \param n number of columns - * \param annz number of initial nonzeros in the matrix - * \param lwork if lwork=-1, this routine returns an estimated size of the required memory - * \param glu persistent data to facilitate multiple factors : will be deleted later ?? - * \param fillratio estimated ratio of fill in the factors - * \param panel_size Size of a panel - * \return an estimated size of the required memory if lwork = -1; otherwise, return the size of actually allocated memory when allocation failed, and 0 on success - * \note Unlike SuperLU, this routine does not support successive factorization with the same pattern and the same row permutation - */ -template <typename Scalar, typename StorageIndex> -Index SparseLUImpl<Scalar,StorageIndex>::memInit(Index m, Index n, Index annz, Index lwork, Index fillratio, Index panel_size, GlobalLU_t& glu) -{ - Index& num_expansions = glu.num_expansions; //No memory expansions so far - num_expansions = 0; - glu.nzumax = glu.nzlumax = (std::min)(fillratio * (annz+1) / n, m) * n; // estimated number of nonzeros in U - glu.nzlmax = (std::max)(Index(4), fillratio) * (annz+1) / 4; // estimated nnz in L factor - // Return the estimated size to the user if necessary - Index tempSpace; - tempSpace = (2*panel_size + 4 + LUNoMarker) * m * sizeof(Index) + (panel_size + 1) * m * sizeof(Scalar); - if (lwork == emptyIdxLU) - { - Index estimated_size; - estimated_size = (5 * n + 5) * sizeof(Index) + tempSpace - + (glu.nzlmax + glu.nzumax) * sizeof(Index) + (glu.nzlumax+glu.nzumax) * sizeof(Scalar) + n; - return estimated_size; - } - - // Setup the required space - - // First allocate Integer pointers for L\U factors - glu.xsup.resize(n+1); - glu.supno.resize(n+1); - glu.xlsub.resize(n+1); - glu.xlusup.resize(n+1); - glu.xusub.resize(n+1); - - // Reserve memory for L/U factors - do - { - if( (expand<ScalarVector>(glu.lusup, glu.nzlumax, 0, 0, num_expansions)<0) - || (expand<ScalarVector>(glu.ucol, glu.nzumax, 0, 0, num_expansions)<0) - || (expand<IndexVector> (glu.lsub, glu.nzlmax, 0, 0, num_expansions)<0) - || (expand<IndexVector> (glu.usub, glu.nzumax, 0, 1, num_expansions)<0) ) - { - //Reduce the estimated size and retry - glu.nzlumax /= 2; - glu.nzumax /= 2; - glu.nzlmax /= 2; - if (glu.nzlumax < annz ) return glu.nzlumax; - } - } while (!glu.lusup.size() || !glu.ucol.size() || !glu.lsub.size() || !glu.usub.size()); - - ++num_expansions; - return 0; - -} // end LuMemInit - -/** - * \brief Expand the existing storage - * \param vec vector to expand - * \param[in,out] maxlen On input, previous size of vec (Number of elements to copy ). on output, new size - * \param nbElts current number of elements in the vector. - * \param memtype Type of the element to expand - * \param num_expansions Number of expansions - * \return 0 on success, > 0 size of the memory allocated so far - */ -template <typename Scalar, typename StorageIndex> -template <typename VectorType> -Index SparseLUImpl<Scalar,StorageIndex>::memXpand(VectorType& vec, Index& maxlen, Index nbElts, MemType memtype, Index& num_expansions) -{ - Index failed_size; - if (memtype == USUB) - failed_size = this->expand<VectorType>(vec, maxlen, nbElts, 1, num_expansions); - else - failed_size = this->expand<VectorType>(vec, maxlen, nbElts, 0, num_expansions); - - if (failed_size) - return failed_size; - - return 0 ; -} - -} // end namespace internal - -} // end namespace Eigen -#endif // EIGEN_SPARSELU_MEMORY diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Structs.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Structs.h deleted file mode 100644 index cf5ec449..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Structs.h +++ /dev/null @@ -1,110 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* - * NOTE: This file comes from a partly modified version of files slu_[s,d,c,z]defs.h - * -- SuperLU routine (version 4.1) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * November, 2010 - * - * Global data structures used in LU factorization - - * - * nsuper: #supernodes = nsuper + 1, numbered [0, nsuper]. - * (xsup,supno): supno[i] is the supernode no to which i belongs; - * xsup(s) points to the beginning of the s-th supernode. - * e.g. supno 0 1 2 2 3 3 3 4 4 4 4 4 (n=12) - * xsup 0 1 2 4 7 12 - * Note: dfs will be performed on supernode rep. relative to the new - * row pivoting ordering - * - * (xlsub,lsub): lsub[*] contains the compressed subscript of - * rectangular supernodes; xlsub[j] points to the starting - * location of the j-th column in lsub[*]. Note that xlsub - * is indexed by column. - * Storage: original row subscripts - * - * During the course of sparse LU factorization, we also use - * (xlsub,lsub) for the purpose of symmetric pruning. For each - * supernode {s,s+1,...,t=s+r} with first column s and last - * column t, the subscript set - * lsub[j], j=xlsub[s], .., xlsub[s+1]-1 - * is the structure of column s (i.e. structure of this supernode). - * It is used for the storage of numerical values. - * Furthermore, - * lsub[j], j=xlsub[t], .., xlsub[t+1]-1 - * is the structure of the last column t of this supernode. - * It is for the purpose of symmetric pruning. Therefore, the - * structural subscripts can be rearranged without making physical - * interchanges among the numerical values. - * - * However, if the supernode has only one column, then we - * only keep one set of subscripts. For any subscript interchange - * performed, similar interchange must be done on the numerical - * values. - * - * The last column structures (for pruning) will be removed - * after the numercial LU factorization phase. - * - * (xlusup,lusup): lusup[*] contains the numerical values of the - * rectangular supernodes; xlusup[j] points to the starting - * location of the j-th column in storage vector lusup[*] - * Note: xlusup is indexed by column. - * Each rectangular supernode is stored by column-major - * scheme, consistent with Fortran 2-dim array storage. - * - * (xusub,ucol,usub): ucol[*] stores the numerical values of - * U-columns outside the rectangular supernodes. The row - * subscript of nonzero ucol[k] is stored in usub[k]. - * xusub[i] points to the starting location of column i in ucol. - * Storage: new row subscripts; that is subscripts of PA. - */ - -#ifndef EIGEN_LU_STRUCTS -#define EIGEN_LU_STRUCTS -namespace Eigen { -namespace internal { - -typedef enum {LUSUP, UCOL, LSUB, USUB, LLVL, ULVL} MemType; - -template <typename IndexVector, typename ScalarVector> -struct LU_GlobalLU_t { - typedef typename IndexVector::Scalar StorageIndex; - IndexVector xsup; //First supernode column ... xsup(s) points to the beginning of the s-th supernode - IndexVector supno; // Supernode number corresponding to this column (column to supernode mapping) - ScalarVector lusup; // nonzero values of L ordered by columns - IndexVector lsub; // Compressed row indices of L rectangular supernodes. - IndexVector xlusup; // pointers to the beginning of each column in lusup - IndexVector xlsub; // pointers to the beginning of each column in lsub - Index nzlmax; // Current max size of lsub - Index nzlumax; // Current max size of lusup - ScalarVector ucol; // nonzero values of U ordered by columns - IndexVector usub; // row indices of U columns in ucol - IndexVector xusub; // Pointers to the beginning of each column of U in ucol - Index nzumax; // Current max size of ucol - Index n; // Number of columns in the matrix - Index num_expansions; -}; - -// Values to set for performance -struct perfvalues { - Index panel_size; // a panel consists of at most <panel_size> consecutive columns - Index relax; // To control degree of relaxing supernodes. If the number of nodes (columns) - // in a subtree of the elimination tree is less than relax, this subtree is considered - // as one supernode regardless of the row structures of those columns - Index maxsuper; // The maximum size for a supernode in complete LU - Index rowblk; // The minimum row dimension for 2-D blocking to be used; - Index colblk; // The minimum column dimension for 2-D blocking to be used; - Index fillfactor; // The estimated fills factors for L and U, compared with A -}; - -} // end namespace internal - -} // end namespace Eigen -#endif // EIGEN_LU_STRUCTS diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h deleted file mode 100644 index 8583b1b6..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +++ /dev/null @@ -1,301 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSELU_SUPERNODAL_MATRIX_H -#define EIGEN_SPARSELU_SUPERNODAL_MATRIX_H - -namespace Eigen { -namespace internal { - -/** \ingroup SparseLU_Module - * \brief a class to manipulate the L supernodal factor from the SparseLU factorization - * - * This class contain the data to easily store - * and manipulate the supernodes during the factorization and solution phase of Sparse LU. - * Only the lower triangular matrix has supernodes. - * - * NOTE : This class corresponds to the SCformat structure in SuperLU - * - */ -/* TODO - * InnerIterator as for sparsematrix - * SuperInnerIterator to iterate through all supernodes - * Function for triangular solve - */ -template <typename _Scalar, typename _StorageIndex> -class MappedSuperNodalMatrix -{ - public: - typedef _Scalar Scalar; - typedef _StorageIndex StorageIndex; - typedef Matrix<StorageIndex,Dynamic,1> IndexVector; - typedef Matrix<Scalar,Dynamic,1> ScalarVector; - public: - MappedSuperNodalMatrix() - { - - } - MappedSuperNodalMatrix(Index m, Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind, - IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col ) - { - setInfos(m, n, nzval, nzval_colptr, rowind, rowind_colptr, col_to_sup, sup_to_col); - } - - ~MappedSuperNodalMatrix() - { - - } - /** - * Set appropriate pointers for the lower triangular supernodal matrix - * These infos are available at the end of the numerical factorization - * FIXME This class will be modified such that it can be use in the course - * of the factorization. - */ - void setInfos(Index m, Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind, - IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col ) - { - m_row = m; - m_col = n; - m_nzval = nzval.data(); - m_nzval_colptr = nzval_colptr.data(); - m_rowind = rowind.data(); - m_rowind_colptr = rowind_colptr.data(); - m_nsuper = col_to_sup(n); - m_col_to_sup = col_to_sup.data(); - m_sup_to_col = sup_to_col.data(); - } - - /** - * Number of rows - */ - Index rows() const { return m_row; } - - /** - * Number of columns - */ - Index cols() const { return m_col; } - - /** - * Return the array of nonzero values packed by column - * - * The size is nnz - */ - Scalar* valuePtr() { return m_nzval; } - - const Scalar* valuePtr() const - { - return m_nzval; - } - /** - * Return the pointers to the beginning of each column in \ref valuePtr() - */ - StorageIndex* colIndexPtr() - { - return m_nzval_colptr; - } - - const StorageIndex* colIndexPtr() const - { - return m_nzval_colptr; - } - - /** - * Return the array of compressed row indices of all supernodes - */ - StorageIndex* rowIndex() { return m_rowind; } - - const StorageIndex* rowIndex() const - { - return m_rowind; - } - - /** - * Return the location in \em rowvaluePtr() which starts each column - */ - StorageIndex* rowIndexPtr() { return m_rowind_colptr; } - - const StorageIndex* rowIndexPtr() const - { - return m_rowind_colptr; - } - - /** - * Return the array of column-to-supernode mapping - */ - StorageIndex* colToSup() { return m_col_to_sup; } - - const StorageIndex* colToSup() const - { - return m_col_to_sup; - } - /** - * Return the array of supernode-to-column mapping - */ - StorageIndex* supToCol() { return m_sup_to_col; } - - const StorageIndex* supToCol() const - { - return m_sup_to_col; - } - - /** - * Return the number of supernodes - */ - Index nsuper() const - { - return m_nsuper; - } - - class InnerIterator; - template<typename Dest> - void solveInPlace( MatrixBase<Dest>&X) const; - - - - - protected: - Index m_row; // Number of rows - Index m_col; // Number of columns - Index m_nsuper; // Number of supernodes - Scalar* m_nzval; //array of nonzero values packed by column - StorageIndex* m_nzval_colptr; //nzval_colptr[j] Stores the location in nzval[] which starts column j - StorageIndex* m_rowind; // Array of compressed row indices of rectangular supernodes - StorageIndex* m_rowind_colptr; //rowind_colptr[j] stores the location in rowind[] which starts column j - StorageIndex* m_col_to_sup; // col_to_sup[j] is the supernode number to which column j belongs - StorageIndex* m_sup_to_col; //sup_to_col[s] points to the starting column of the s-th supernode - - private : -}; - -/** - * \brief InnerIterator class to iterate over nonzero values of the current column in the supernodal matrix L - * - */ -template<typename Scalar, typename StorageIndex> -class MappedSuperNodalMatrix<Scalar,StorageIndex>::InnerIterator -{ - public: - InnerIterator(const MappedSuperNodalMatrix& mat, Index outer) - : m_matrix(mat), - m_outer(outer), - m_supno(mat.colToSup()[outer]), - m_idval(mat.colIndexPtr()[outer]), - m_startidval(m_idval), - m_endidval(mat.colIndexPtr()[outer+1]), - m_idrow(mat.rowIndexPtr()[mat.supToCol()[mat.colToSup()[outer]]]), - m_endidrow(mat.rowIndexPtr()[mat.supToCol()[mat.colToSup()[outer]]+1]) - {} - inline InnerIterator& operator++() - { - m_idval++; - m_idrow++; - return *this; - } - inline Scalar value() const { return m_matrix.valuePtr()[m_idval]; } - - inline Scalar& valueRef() { return const_cast<Scalar&>(m_matrix.valuePtr()[m_idval]); } - - inline Index index() const { return m_matrix.rowIndex()[m_idrow]; } - inline Index row() const { return index(); } - inline Index col() const { return m_outer; } - - inline Index supIndex() const { return m_supno; } - - inline operator bool() const - { - return ( (m_idval < m_endidval) && (m_idval >= m_startidval) - && (m_idrow < m_endidrow) ); - } - - protected: - const MappedSuperNodalMatrix& m_matrix; // Supernodal lower triangular matrix - const Index m_outer; // Current column - const Index m_supno; // Current SuperNode number - Index m_idval; // Index to browse the values in the current column - const Index m_startidval; // Start of the column value - const Index m_endidval; // End of the column value - Index m_idrow; // Index to browse the row indices - Index m_endidrow; // End index of row indices of the current column -}; - -/** - * \brief Solve with the supernode triangular matrix - * - */ -template<typename Scalar, typename Index_> -template<typename Dest> -void MappedSuperNodalMatrix<Scalar,Index_>::solveInPlace( MatrixBase<Dest>&X) const -{ - /* Explicit type conversion as the Index type of MatrixBase<Dest> may be wider than Index */ -// eigen_assert(X.rows() <= NumTraits<Index>::highest()); -// eigen_assert(X.cols() <= NumTraits<Index>::highest()); - Index n = int(X.rows()); - Index nrhs = Index(X.cols()); - const Scalar * Lval = valuePtr(); // Nonzero values - Matrix<Scalar,Dynamic,Dest::ColsAtCompileTime, ColMajor> work(n, nrhs); // working vector - work.setZero(); - for (Index k = 0; k <= nsuper(); k ++) - { - Index fsupc = supToCol()[k]; // First column of the current supernode - Index istart = rowIndexPtr()[fsupc]; // Pointer index to the subscript of the current column - Index nsupr = rowIndexPtr()[fsupc+1] - istart; // Number of rows in the current supernode - Index nsupc = supToCol()[k+1] - fsupc; // Number of columns in the current supernode - Index nrow = nsupr - nsupc; // Number of rows in the non-diagonal part of the supernode - Index irow; //Current index row - - if (nsupc == 1 ) - { - for (Index j = 0; j < nrhs; j++) - { - InnerIterator it(*this, fsupc); - ++it; // Skip the diagonal element - for (; it; ++it) - { - irow = it.row(); - X(irow, j) -= X(fsupc, j) * it.value(); - } - } - } - else - { - // The supernode has more than one column - Index luptr = colIndexPtr()[fsupc]; - Index lda = colIndexPtr()[fsupc+1] - luptr; - - // Triangular solve - Map<const Matrix<Scalar,Dynamic,Dynamic, ColMajor>, 0, OuterStride<> > A( &(Lval[luptr]), nsupc, nsupc, OuterStride<>(lda) ); - Map< Matrix<Scalar,Dynamic,Dest::ColsAtCompileTime, ColMajor>, 0, OuterStride<> > U (&(X(fsupc,0)), nsupc, nrhs, OuterStride<>(n) ); - U = A.template triangularView<UnitLower>().solve(U); - - // Matrix-vector product - new (&A) Map<const Matrix<Scalar,Dynamic,Dynamic, ColMajor>, 0, OuterStride<> > ( &(Lval[luptr+nsupc]), nrow, nsupc, OuterStride<>(lda) ); - work.topRows(nrow).noalias() = A * U; - - //Begin Scatter - for (Index j = 0; j < nrhs; j++) - { - Index iptr = istart + nsupc; - for (Index i = 0; i < nrow; i++) - { - irow = rowIndex()[iptr]; - X(irow, j) -= work(i, j); // Scatter operation - work(i, j) = Scalar(0); - iptr++; - } - } - } - } -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPARSELU_MATRIX_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Utils.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Utils.h deleted file mode 100644 index 9e3dab44..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_Utils.h +++ /dev/null @@ -1,80 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_SPARSELU_UTILS_H -#define EIGEN_SPARSELU_UTILS_H - -namespace Eigen { -namespace internal { - -/** - * \brief Count Nonzero elements in the factors - */ -template <typename Scalar, typename StorageIndex> -void SparseLUImpl<Scalar,StorageIndex>::countnz(const Index n, Index& nnzL, Index& nnzU, GlobalLU_t& glu) -{ - nnzL = 0; - nnzU = (glu.xusub)(n); - Index nsuper = (glu.supno)(n); - Index jlen; - Index i, j, fsupc; - if (n <= 0 ) return; - // For each supernode - for (i = 0; i <= nsuper; i++) - { - fsupc = glu.xsup(i); - jlen = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); - - for (j = fsupc; j < glu.xsup(i+1); j++) - { - nnzL += jlen; - nnzU += j - fsupc + 1; - jlen--; - } - } -} - -/** - * \brief Fix up the data storage lsub for L-subscripts. - * - * It removes the subscripts sets for structural pruning, - * and applies permutation to the remaining subscripts - * - */ -template <typename Scalar, typename StorageIndex> -void SparseLUImpl<Scalar,StorageIndex>::fixupL(const Index n, const IndexVector& perm_r, GlobalLU_t& glu) -{ - Index fsupc, i, j, k, jstart; - - StorageIndex nextl = 0; - Index nsuper = (glu.supno)(n); - - // For each supernode - for (i = 0; i <= nsuper; i++) - { - fsupc = glu.xsup(i); - jstart = glu.xlsub(fsupc); - glu.xlsub(fsupc) = nextl; - for (j = jstart; j < glu.xlsub(fsupc + 1); j++) - { - glu.lsub(nextl) = perm_r(glu.lsub(j)); // Now indexed into P*A - nextl++; - } - for (k = fsupc+1; k < glu.xsup(i+1); k++) - glu.xlsub(k) = nextl; // other columns in supernode i - } - - glu.xlsub(n) = nextl; -} - -} // end namespace internal - -} // end namespace Eigen -#endif // EIGEN_SPARSELU_UTILS_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_column_bmod.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_column_bmod.h deleted file mode 100644 index b57f0680..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_column_bmod.h +++ /dev/null @@ -1,181 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* - - * NOTE: This file is the modified version of xcolumn_bmod.c file in SuperLU - - * -- SuperLU routine (version 3.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * October 15, 2003 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ -#ifndef SPARSELU_COLUMN_BMOD_H -#define SPARSELU_COLUMN_BMOD_H - -namespace Eigen { - -namespace internal { -/** - * \brief Performs numeric block updates (sup-col) in topological order - * - * \param jcol current column to update - * \param nseg Number of segments in the U part - * \param dense Store the full representation of the column - * \param tempv working array - * \param segrep segment representative ... - * \param repfnz ??? First nonzero column in each row ??? ... - * \param fpanelc First column in the current panel - * \param glu Global LU data. - * \return 0 - successful return - * > 0 - number of bytes allocated when run out of space - * - */ -template <typename Scalar, typename StorageIndex> -Index SparseLUImpl<Scalar,StorageIndex>::column_bmod(const Index jcol, const Index nseg, BlockScalarVector dense, ScalarVector& tempv, - BlockIndexVector segrep, BlockIndexVector repfnz, Index fpanelc, GlobalLU_t& glu) -{ - Index jsupno, k, ksub, krep, ksupno; - Index lptr, nrow, isub, irow, nextlu, new_next, ufirst; - Index fsupc, nsupc, nsupr, luptr, kfnz, no_zeros; - /* krep = representative of current k-th supernode - * fsupc = first supernodal column - * nsupc = number of columns in a supernode - * nsupr = number of rows in a supernode - * luptr = location of supernodal LU-block in storage - * kfnz = first nonz in the k-th supernodal segment - * no_zeros = no lf leading zeros in a supernodal U-segment - */ - - jsupno = glu.supno(jcol); - // For each nonzero supernode segment of U[*,j] in topological order - k = nseg - 1; - Index d_fsupc; // distance between the first column of the current panel and the - // first column of the current snode - Index fst_col; // First column within small LU update - Index segsize; - for (ksub = 0; ksub < nseg; ksub++) - { - krep = segrep(k); k--; - ksupno = glu.supno(krep); - if (jsupno != ksupno ) - { - // outside the rectangular supernode - fsupc = glu.xsup(ksupno); - fst_col = (std::max)(fsupc, fpanelc); - - // Distance from the current supernode to the current panel; - // d_fsupc = 0 if fsupc > fpanelc - d_fsupc = fst_col - fsupc; - - luptr = glu.xlusup(fst_col) + d_fsupc; - lptr = glu.xlsub(fsupc) + d_fsupc; - - kfnz = repfnz(krep); - kfnz = (std::max)(kfnz, fpanelc); - - segsize = krep - kfnz + 1; - nsupc = krep - fst_col + 1; - nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); - nrow = nsupr - d_fsupc - nsupc; - Index lda = glu.xlusup(fst_col+1) - glu.xlusup(fst_col); - - - // Perform a triangular solver and block update, - // then scatter the result of sup-col update to dense - no_zeros = kfnz - fst_col; - if(segsize==1) - LU_kernel_bmod<1>::run(segsize, dense, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros); - else - LU_kernel_bmod<Dynamic>::run(segsize, dense, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros); - } // end if jsupno - } // end for each segment - - // Process the supernodal portion of L\U[*,j] - nextlu = glu.xlusup(jcol); - fsupc = glu.xsup(jsupno); - - // copy the SPA dense into L\U[*,j] - Index mem; - new_next = nextlu + glu.xlsub(fsupc + 1) - glu.xlsub(fsupc); - Index offset = internal::first_multiple<Index>(new_next, internal::packet_traits<Scalar>::size) - new_next; - if(offset) - new_next += offset; - while (new_next > glu.nzlumax ) - { - mem = memXpand<ScalarVector>(glu.lusup, glu.nzlumax, nextlu, LUSUP, glu.num_expansions); - if (mem) return mem; - } - - for (isub = glu.xlsub(fsupc); isub < glu.xlsub(fsupc+1); isub++) - { - irow = glu.lsub(isub); - glu.lusup(nextlu) = dense(irow); - dense(irow) = Scalar(0.0); - ++nextlu; - } - - if(offset) - { - glu.lusup.segment(nextlu,offset).setZero(); - nextlu += offset; - } - glu.xlusup(jcol + 1) = StorageIndex(nextlu); // close L\U(*,jcol); - - /* For more updates within the panel (also within the current supernode), - * should start from the first column of the panel, or the first column - * of the supernode, whichever is bigger. There are two cases: - * 1) fsupc < fpanelc, then fst_col <-- fpanelc - * 2) fsupc >= fpanelc, then fst_col <-- fsupc - */ - fst_col = (std::max)(fsupc, fpanelc); - - if (fst_col < jcol) - { - // Distance between the current supernode and the current panel - // d_fsupc = 0 if fsupc >= fpanelc - d_fsupc = fst_col - fsupc; - - lptr = glu.xlsub(fsupc) + d_fsupc; - luptr = glu.xlusup(fst_col) + d_fsupc; - nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); // leading dimension - nsupc = jcol - fst_col; // excluding jcol - nrow = nsupr - d_fsupc - nsupc; - - // points to the beginning of jcol in snode L\U(jsupno) - ufirst = glu.xlusup(jcol) + d_fsupc; - Index lda = glu.xlusup(jcol+1) - glu.xlusup(jcol); - MappedMatrixBlock A( &(glu.lusup.data()[luptr]), nsupc, nsupc, OuterStride<>(lda) ); - VectorBlock<ScalarVector> u(glu.lusup, ufirst, nsupc); - u = A.template triangularView<UnitLower>().solve(u); - - new (&A) MappedMatrixBlock ( &(glu.lusup.data()[luptr+nsupc]), nrow, nsupc, OuterStride<>(lda) ); - VectorBlock<ScalarVector> l(glu.lusup, ufirst+nsupc, nrow); - l.noalias() -= A * u; - - } // End if fst_col - return 0; -} - -} // end namespace internal -} // end namespace Eigen - -#endif // SPARSELU_COLUMN_BMOD_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_column_dfs.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_column_dfs.h deleted file mode 100644 index 5a2c941b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_column_dfs.h +++ /dev/null @@ -1,179 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* - - * NOTE: This file is the modified version of [s,d,c,z]column_dfs.c file in SuperLU - - * -- SuperLU routine (version 2.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * November 15, 1997 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ -#ifndef SPARSELU_COLUMN_DFS_H -#define SPARSELU_COLUMN_DFS_H - -template <typename Scalar, typename StorageIndex> class SparseLUImpl; -namespace Eigen { - -namespace internal { - -template<typename IndexVector, typename ScalarVector> -struct column_dfs_traits : no_assignment_operator -{ - typedef typename ScalarVector::Scalar Scalar; - typedef typename IndexVector::Scalar StorageIndex; - column_dfs_traits(Index jcol, Index& jsuper, typename SparseLUImpl<Scalar, StorageIndex>::GlobalLU_t& glu, SparseLUImpl<Scalar, StorageIndex>& luImpl) - : m_jcol(jcol), m_jsuper_ref(jsuper), m_glu(glu), m_luImpl(luImpl) - {} - bool update_segrep(Index /*krep*/, Index /*jj*/) - { - return true; - } - void mem_expand(IndexVector& lsub, Index& nextl, Index chmark) - { - if (nextl >= m_glu.nzlmax) - m_luImpl.memXpand(lsub, m_glu.nzlmax, nextl, LSUB, m_glu.num_expansions); - if (chmark != (m_jcol-1)) m_jsuper_ref = emptyIdxLU; - } - enum { ExpandMem = true }; - - Index m_jcol; - Index& m_jsuper_ref; - typename SparseLUImpl<Scalar, StorageIndex>::GlobalLU_t& m_glu; - SparseLUImpl<Scalar, StorageIndex>& m_luImpl; -}; - - -/** - * \brief Performs a symbolic factorization on column jcol and decide the supernode boundary - * - * A supernode representative is the last column of a supernode. - * The nonzeros in U[*,j] are segments that end at supernodes representatives. - * The routine returns a list of the supernodal representatives - * in topological order of the dfs that generates them. - * The location of the first nonzero in each supernodal segment - * (supernodal entry location) is also returned. - * - * \param m number of rows in the matrix - * \param jcol Current column - * \param perm_r Row permutation - * \param maxsuper Maximum number of column allowed in a supernode - * \param [in,out] nseg Number of segments in current U[*,j] - new segments appended - * \param lsub_col defines the rhs vector to start the dfs - * \param [in,out] segrep Segment representatives - new segments appended - * \param repfnz First nonzero location in each row - * \param xprune - * \param marker marker[i] == jj, if i was visited during dfs of current column jj; - * \param parent - * \param xplore working array - * \param glu global LU data - * \return 0 success - * > 0 number of bytes allocated when run out of space - * - */ -template <typename Scalar, typename StorageIndex> -Index SparseLUImpl<Scalar,StorageIndex>::column_dfs(const Index m, const Index jcol, IndexVector& perm_r, Index maxsuper, Index& nseg, - BlockIndexVector lsub_col, IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune, - IndexVector& marker, IndexVector& parent, IndexVector& xplore, GlobalLU_t& glu) -{ - - Index jsuper = glu.supno(jcol); - Index nextl = glu.xlsub(jcol); - VectorBlock<IndexVector> marker2(marker, 2*m, m); - - - column_dfs_traits<IndexVector, ScalarVector> traits(jcol, jsuper, glu, *this); - - // For each nonzero in A(*,jcol) do dfs - for (Index k = 0; ((k < m) ? lsub_col[k] != emptyIdxLU : false) ; k++) - { - Index krow = lsub_col(k); - lsub_col(k) = emptyIdxLU; - Index kmark = marker2(krow); - - // krow was visited before, go to the next nonz; - if (kmark == jcol) continue; - - dfs_kernel(StorageIndex(jcol), perm_r, nseg, glu.lsub, segrep, repfnz, xprune, marker2, parent, - xplore, glu, nextl, krow, traits); - } // for each nonzero ... - - Index fsupc; - StorageIndex nsuper = glu.supno(jcol); - StorageIndex jcolp1 = StorageIndex(jcol) + 1; - Index jcolm1 = jcol - 1; - - // check to see if j belongs in the same supernode as j-1 - if ( jcol == 0 ) - { // Do nothing for column 0 - nsuper = glu.supno(0) = 0 ; - } - else - { - fsupc = glu.xsup(nsuper); - StorageIndex jptr = glu.xlsub(jcol); // Not yet compressed - StorageIndex jm1ptr = glu.xlsub(jcolm1); - - // Use supernodes of type T2 : see SuperLU paper - if ( (nextl-jptr != jptr-jm1ptr-1) ) jsuper = emptyIdxLU; - - // Make sure the number of columns in a supernode doesn't - // exceed threshold - if ( (jcol - fsupc) >= maxsuper) jsuper = emptyIdxLU; - - /* If jcol starts a new supernode, reclaim storage space in - * glu.lsub from previous supernode. Note we only store - * the subscript set of the first and last columns of - * a supernode. (first for num values, last for pruning) - */ - if (jsuper == emptyIdxLU) - { // starts a new supernode - if ( (fsupc < jcolm1-1) ) - { // >= 3 columns in nsuper - StorageIndex ito = glu.xlsub(fsupc+1); - glu.xlsub(jcolm1) = ito; - StorageIndex istop = ito + jptr - jm1ptr; - xprune(jcolm1) = istop; // initialize xprune(jcol-1) - glu.xlsub(jcol) = istop; - - for (StorageIndex ifrom = jm1ptr; ifrom < nextl; ++ifrom, ++ito) - glu.lsub(ito) = glu.lsub(ifrom); - nextl = ito; // = istop + length(jcol) - } - nsuper++; - glu.supno(jcol) = nsuper; - } // if a new supernode - } // end else: jcol > 0 - - // Tidy up the pointers before exit - glu.xsup(nsuper+1) = jcolp1; - glu.supno(jcolp1) = nsuper; - xprune(jcol) = StorageIndex(nextl); // Initialize upper bound for pruning - glu.xlsub(jcolp1) = StorageIndex(nextl); - - return 0; -} - -} // end namespace internal - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h deleted file mode 100644 index c32d8d8b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h +++ /dev/null @@ -1,107 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -/* - - * NOTE: This file is the modified version of [s,d,c,z]copy_to_ucol.c file in SuperLU - - * -- SuperLU routine (version 2.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * November 15, 1997 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ -#ifndef SPARSELU_COPY_TO_UCOL_H -#define SPARSELU_COPY_TO_UCOL_H - -namespace Eigen { -namespace internal { - -/** - * \brief Performs numeric block updates (sup-col) in topological order - * - * \param jcol current column to update - * \param nseg Number of segments in the U part - * \param segrep segment representative ... - * \param repfnz First nonzero column in each row ... - * \param perm_r Row permutation - * \param dense Store the full representation of the column - * \param glu Global LU data. - * \return 0 - successful return - * > 0 - number of bytes allocated when run out of space - * - */ -template <typename Scalar, typename StorageIndex> -Index SparseLUImpl<Scalar,StorageIndex>::copy_to_ucol(const Index jcol, const Index nseg, IndexVector& segrep, - BlockIndexVector repfnz ,IndexVector& perm_r, BlockScalarVector dense, GlobalLU_t& glu) -{ - Index ksub, krep, ksupno; - - Index jsupno = glu.supno(jcol); - - // For each nonzero supernode segment of U[*,j] in topological order - Index k = nseg - 1, i; - StorageIndex nextu = glu.xusub(jcol); - Index kfnz, isub, segsize; - Index new_next,irow; - Index fsupc, mem; - for (ksub = 0; ksub < nseg; ksub++) - { - krep = segrep(k); k--; - ksupno = glu.supno(krep); - if (jsupno != ksupno ) // should go into ucol(); - { - kfnz = repfnz(krep); - if (kfnz != emptyIdxLU) - { // Nonzero U-segment - fsupc = glu.xsup(ksupno); - isub = glu.xlsub(fsupc) + kfnz - fsupc; - segsize = krep - kfnz + 1; - new_next = nextu + segsize; - while (new_next > glu.nzumax) - { - mem = memXpand<ScalarVector>(glu.ucol, glu.nzumax, nextu, UCOL, glu.num_expansions); - if (mem) return mem; - mem = memXpand<IndexVector>(glu.usub, glu.nzumax, nextu, USUB, glu.num_expansions); - if (mem) return mem; - - } - - for (i = 0; i < segsize; i++) - { - irow = glu.lsub(isub); - glu.usub(nextu) = perm_r(irow); // Unlike the L part, the U part is stored in its final order - glu.ucol(nextu) = dense(irow); - dense(irow) = Scalar(0.0); - nextu++; - isub++; - } - - } // end nonzero U-segment - - } // end if jsupno - - } // end for each segment - glu.xusub(jcol + 1) = nextu; // close U(*,jcol) - return 0; -} - -} // namespace internal -} // end namespace Eigen - -#endif // SPARSELU_COPY_TO_UCOL_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_gemm_kernel.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_gemm_kernel.h deleted file mode 100644 index e37c2fe0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_gemm_kernel.h +++ /dev/null @@ -1,280 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSELU_GEMM_KERNEL_H -#define EIGEN_SPARSELU_GEMM_KERNEL_H - -namespace Eigen { - -namespace internal { - - -/** \internal - * A general matrix-matrix product kernel optimized for the SparseLU factorization. - * - A, B, and C must be column major - * - lda and ldc must be multiples of the respective packet size - * - C must have the same alignment as A - */ -template<typename Scalar> -EIGEN_DONT_INLINE -void sparselu_gemm(Index m, Index n, Index d, const Scalar* A, Index lda, const Scalar* B, Index ldb, Scalar* C, Index ldc) -{ - using namespace Eigen::internal; - - typedef typename packet_traits<Scalar>::type Packet; - enum { - NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS, - PacketSize = packet_traits<Scalar>::size, - PM = 8, // peeling in M - RN = 2, // register blocking - RK = NumberOfRegisters>=16 ? 4 : 2, // register blocking - BM = 4096/sizeof(Scalar), // number of rows of A-C per chunk - SM = PM*PacketSize // step along M - }; - Index d_end = (d/RK)*RK; // number of columns of A (rows of B) suitable for full register blocking - Index n_end = (n/RN)*RN; // number of columns of B-C suitable for processing RN columns at once - Index i0 = internal::first_default_aligned(A,m); - - eigen_internal_assert(((lda%PacketSize)==0) && ((ldc%PacketSize)==0) && (i0==internal::first_default_aligned(C,m))); - - // handle the non aligned rows of A and C without any optimization: - for(Index i=0; i<i0; ++i) - { - for(Index j=0; j<n; ++j) - { - Scalar c = C[i+j*ldc]; - for(Index k=0; k<d; ++k) - c += B[k+j*ldb] * A[i+k*lda]; - C[i+j*ldc] = c; - } - } - // process the remaining rows per chunk of BM rows - for(Index ib=i0; ib<m; ib+=BM) - { - Index actual_b = std::min<Index>(BM, m-ib); // actual number of rows - Index actual_b_end1 = (actual_b/SM)*SM; // actual number of rows suitable for peeling - Index actual_b_end2 = (actual_b/PacketSize)*PacketSize; // actual number of rows suitable for vectorization - - // Let's process two columns of B-C at once - for(Index j=0; j<n_end; j+=RN) - { - const Scalar* Bc0 = B+(j+0)*ldb; - const Scalar* Bc1 = B+(j+1)*ldb; - - for(Index k=0; k<d_end; k+=RK) - { - - // load and expand a RN x RK block of B - Packet b00, b10, b20, b30, b01, b11, b21, b31; - { b00 = pset1<Packet>(Bc0[0]); } - { b10 = pset1<Packet>(Bc0[1]); } - if(RK==4) { b20 = pset1<Packet>(Bc0[2]); } - if(RK==4) { b30 = pset1<Packet>(Bc0[3]); } - { b01 = pset1<Packet>(Bc1[0]); } - { b11 = pset1<Packet>(Bc1[1]); } - if(RK==4) { b21 = pset1<Packet>(Bc1[2]); } - if(RK==4) { b31 = pset1<Packet>(Bc1[3]); } - - Packet a0, a1, a2, a3, c0, c1, t0, t1; - - const Scalar* A0 = A+ib+(k+0)*lda; - const Scalar* A1 = A+ib+(k+1)*lda; - const Scalar* A2 = A+ib+(k+2)*lda; - const Scalar* A3 = A+ib+(k+3)*lda; - - Scalar* C0 = C+ib+(j+0)*ldc; - Scalar* C1 = C+ib+(j+1)*ldc; - - a0 = pload<Packet>(A0); - a1 = pload<Packet>(A1); - if(RK==4) - { - a2 = pload<Packet>(A2); - a3 = pload<Packet>(A3); - } - else - { - // workaround "may be used uninitialized in this function" warning - a2 = a3 = a0; - } - -#define KMADD(c, a, b, tmp) {tmp = b; tmp = pmul(a,tmp); c = padd(c,tmp);} -#define WORK(I) \ - c0 = pload<Packet>(C0+i+(I)*PacketSize); \ - c1 = pload<Packet>(C1+i+(I)*PacketSize); \ - KMADD(c0, a0, b00, t0) \ - KMADD(c1, a0, b01, t1) \ - a0 = pload<Packet>(A0+i+(I+1)*PacketSize); \ - KMADD(c0, a1, b10, t0) \ - KMADD(c1, a1, b11, t1) \ - a1 = pload<Packet>(A1+i+(I+1)*PacketSize); \ - if(RK==4){ KMADD(c0, a2, b20, t0) }\ - if(RK==4){ KMADD(c1, a2, b21, t1) }\ - if(RK==4){ a2 = pload<Packet>(A2+i+(I+1)*PacketSize); }\ - if(RK==4){ KMADD(c0, a3, b30, t0) }\ - if(RK==4){ KMADD(c1, a3, b31, t1) }\ - if(RK==4){ a3 = pload<Packet>(A3+i+(I+1)*PacketSize); }\ - pstore(C0+i+(I)*PacketSize, c0); \ - pstore(C1+i+(I)*PacketSize, c1) - - // process rows of A' - C' with aggressive vectorization and peeling - for(Index i=0; i<actual_b_end1; i+=PacketSize*8) - { - EIGEN_ASM_COMMENT("SPARSELU_GEMML_KERNEL1"); - prefetch((A0+i+(5)*PacketSize)); - prefetch((A1+i+(5)*PacketSize)); - if(RK==4) prefetch((A2+i+(5)*PacketSize)); - if(RK==4) prefetch((A3+i+(5)*PacketSize)); - - WORK(0); - WORK(1); - WORK(2); - WORK(3); - WORK(4); - WORK(5); - WORK(6); - WORK(7); - } - // process the remaining rows with vectorization only - for(Index i=actual_b_end1; i<actual_b_end2; i+=PacketSize) - { - WORK(0); - } -#undef WORK - // process the remaining rows without vectorization - for(Index i=actual_b_end2; i<actual_b; ++i) - { - if(RK==4) - { - C0[i] += A0[i]*Bc0[0]+A1[i]*Bc0[1]+A2[i]*Bc0[2]+A3[i]*Bc0[3]; - C1[i] += A0[i]*Bc1[0]+A1[i]*Bc1[1]+A2[i]*Bc1[2]+A3[i]*Bc1[3]; - } - else - { - C0[i] += A0[i]*Bc0[0]+A1[i]*Bc0[1]; - C1[i] += A0[i]*Bc1[0]+A1[i]*Bc1[1]; - } - } - - Bc0 += RK; - Bc1 += RK; - } // peeled loop on k - } // peeled loop on the columns j - // process the last column (we now perform a matrix-vector product) - if((n-n_end)>0) - { - const Scalar* Bc0 = B+(n-1)*ldb; - - for(Index k=0; k<d_end; k+=RK) - { - - // load and expand a 1 x RK block of B - Packet b00, b10, b20, b30; - b00 = pset1<Packet>(Bc0[0]); - b10 = pset1<Packet>(Bc0[1]); - if(RK==4) b20 = pset1<Packet>(Bc0[2]); - if(RK==4) b30 = pset1<Packet>(Bc0[3]); - - Packet a0, a1, a2, a3, c0, t0/*, t1*/; - - const Scalar* A0 = A+ib+(k+0)*lda; - const Scalar* A1 = A+ib+(k+1)*lda; - const Scalar* A2 = A+ib+(k+2)*lda; - const Scalar* A3 = A+ib+(k+3)*lda; - - Scalar* C0 = C+ib+(n_end)*ldc; - - a0 = pload<Packet>(A0); - a1 = pload<Packet>(A1); - if(RK==4) - { - a2 = pload<Packet>(A2); - a3 = pload<Packet>(A3); - } - else - { - // workaround "may be used uninitialized in this function" warning - a2 = a3 = a0; - } - -#define WORK(I) \ - c0 = pload<Packet>(C0+i+(I)*PacketSize); \ - KMADD(c0, a0, b00, t0) \ - a0 = pload<Packet>(A0+i+(I+1)*PacketSize); \ - KMADD(c0, a1, b10, t0) \ - a1 = pload<Packet>(A1+i+(I+1)*PacketSize); \ - if(RK==4){ KMADD(c0, a2, b20, t0) }\ - if(RK==4){ a2 = pload<Packet>(A2+i+(I+1)*PacketSize); }\ - if(RK==4){ KMADD(c0, a3, b30, t0) }\ - if(RK==4){ a3 = pload<Packet>(A3+i+(I+1)*PacketSize); }\ - pstore(C0+i+(I)*PacketSize, c0); - - // aggressive vectorization and peeling - for(Index i=0; i<actual_b_end1; i+=PacketSize*8) - { - EIGEN_ASM_COMMENT("SPARSELU_GEMML_KERNEL2"); - WORK(0); - WORK(1); - WORK(2); - WORK(3); - WORK(4); - WORK(5); - WORK(6); - WORK(7); - } - // vectorization only - for(Index i=actual_b_end1; i<actual_b_end2; i+=PacketSize) - { - WORK(0); - } - // remaining scalars - for(Index i=actual_b_end2; i<actual_b; ++i) - { - if(RK==4) - C0[i] += A0[i]*Bc0[0]+A1[i]*Bc0[1]+A2[i]*Bc0[2]+A3[i]*Bc0[3]; - else - C0[i] += A0[i]*Bc0[0]+A1[i]*Bc0[1]; - } - - Bc0 += RK; -#undef WORK - } - } - - // process the last columns of A, corresponding to the last rows of B - Index rd = d-d_end; - if(rd>0) - { - for(Index j=0; j<n; ++j) - { - enum { - Alignment = PacketSize>1 ? Aligned : 0 - }; - typedef Map<Matrix<Scalar,Dynamic,1>, Alignment > MapVector; - typedef Map<const Matrix<Scalar,Dynamic,1>, Alignment > ConstMapVector; - if(rd==1) MapVector(C+j*ldc+ib,actual_b) += B[0+d_end+j*ldb] * ConstMapVector(A+(d_end+0)*lda+ib, actual_b); - - else if(rd==2) MapVector(C+j*ldc+ib,actual_b) += B[0+d_end+j*ldb] * ConstMapVector(A+(d_end+0)*lda+ib, actual_b) - + B[1+d_end+j*ldb] * ConstMapVector(A+(d_end+1)*lda+ib, actual_b); - - else MapVector(C+j*ldc+ib,actual_b) += B[0+d_end+j*ldb] * ConstMapVector(A+(d_end+0)*lda+ib, actual_b) - + B[1+d_end+j*ldb] * ConstMapVector(A+(d_end+1)*lda+ib, actual_b) - + B[2+d_end+j*ldb] * ConstMapVector(A+(d_end+2)*lda+ib, actual_b); - } - } - - } // blocking on the rows of A and C -} -#undef KMADD - -} // namespace internal - -} // namespace Eigen - -#endif // EIGEN_SPARSELU_GEMM_KERNEL_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h deleted file mode 100644 index 6f75d500..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h +++ /dev/null @@ -1,126 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* This file is a modified version of heap_relax_snode.c file in SuperLU - * -- SuperLU routine (version 3.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * October 15, 2003 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ - -#ifndef SPARSELU_HEAP_RELAX_SNODE_H -#define SPARSELU_HEAP_RELAX_SNODE_H - -namespace Eigen { -namespace internal { - -/** - * \brief Identify the initial relaxed supernodes - * - * This routine applied to a symmetric elimination tree. - * It assumes that the matrix has been reordered according to the postorder of the etree - * \param n The number of columns - * \param et elimination tree - * \param relax_columns Maximum number of columns allowed in a relaxed snode - * \param descendants Number of descendants of each node in the etree - * \param relax_end last column in a supernode - */ -template <typename Scalar, typename StorageIndex> -void SparseLUImpl<Scalar,StorageIndex>::heap_relax_snode (const Index n, IndexVector& et, const Index relax_columns, IndexVector& descendants, IndexVector& relax_end) -{ - - // The etree may not be postordered, but its heap ordered - IndexVector post; - internal::treePostorder(StorageIndex(n), et, post); // Post order etree - IndexVector inv_post(n+1); - for (StorageIndex i = 0; i < n+1; ++i) inv_post(post(i)) = i; // inv_post = post.inverse()??? - - // Renumber etree in postorder - IndexVector iwork(n); - IndexVector et_save(n+1); - for (Index i = 0; i < n; ++i) - { - iwork(post(i)) = post(et(i)); - } - et_save = et; // Save the original etree - et = iwork; - - // compute the number of descendants of each node in the etree - relax_end.setConstant(emptyIdxLU); - Index j, parent; - descendants.setZero(); - for (j = 0; j < n; j++) - { - parent = et(j); - if (parent != n) // not the dummy root - descendants(parent) += descendants(j) + 1; - } - // Identify the relaxed supernodes by postorder traversal of the etree - Index snode_start; // beginning of a snode - StorageIndex k; - Index nsuper_et_post = 0; // Number of relaxed snodes in postordered etree - Index nsuper_et = 0; // Number of relaxed snodes in the original etree - StorageIndex l; - for (j = 0; j < n; ) - { - parent = et(j); - snode_start = j; - while ( parent != n && descendants(parent) < relax_columns ) - { - j = parent; - parent = et(j); - } - // Found a supernode in postordered etree, j is the last column - ++nsuper_et_post; - k = StorageIndex(n); - for (Index i = snode_start; i <= j; ++i) - k = (std::min)(k, inv_post(i)); - l = inv_post(j); - if ( (l - k) == (j - snode_start) ) // Same number of columns in the snode - { - // This is also a supernode in the original etree - relax_end(k) = l; // Record last column - ++nsuper_et; - } - else - { - for (Index i = snode_start; i <= j; ++i) - { - l = inv_post(i); - if (descendants(i) == 0) - { - relax_end(l) = l; - ++nsuper_et; - } - } - } - j++; - // Search for a new leaf - while (descendants(j) != 0 && j < n) j++; - } // End postorder traversal of the etree - - // Recover the original etree - et = et_save; -} - -} // end namespace internal - -} // end namespace Eigen -#endif // SPARSELU_HEAP_RELAX_SNODE_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_kernel_bmod.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_kernel_bmod.h deleted file mode 100644 index 8c1b3e8b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_kernel_bmod.h +++ /dev/null @@ -1,130 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef SPARSELU_KERNEL_BMOD_H -#define SPARSELU_KERNEL_BMOD_H - -namespace Eigen { -namespace internal { - -template <int SegSizeAtCompileTime> struct LU_kernel_bmod -{ - /** \internal - * \brief Performs numeric block updates from a given supernode to a single column - * - * \param segsize Size of the segment (and blocks ) to use for updates - * \param[in,out] dense Packed values of the original matrix - * \param tempv temporary vector to use for updates - * \param lusup array containing the supernodes - * \param lda Leading dimension in the supernode - * \param nrow Number of rows in the rectangular part of the supernode - * \param lsub compressed row subscripts of supernodes - * \param lptr pointer to the first column of the current supernode in lsub - * \param no_zeros Number of nonzeros elements before the diagonal part of the supernode - */ - template <typename BlockScalarVector, typename ScalarVector, typename IndexVector> - static EIGEN_DONT_INLINE void run(const Index segsize, BlockScalarVector& dense, ScalarVector& tempv, ScalarVector& lusup, Index& luptr, const Index lda, - const Index nrow, IndexVector& lsub, const Index lptr, const Index no_zeros); -}; - -template <int SegSizeAtCompileTime> -template <typename BlockScalarVector, typename ScalarVector, typename IndexVector> -EIGEN_DONT_INLINE void LU_kernel_bmod<SegSizeAtCompileTime>::run(const Index segsize, BlockScalarVector& dense, ScalarVector& tempv, ScalarVector& lusup, Index& luptr, const Index lda, - const Index nrow, IndexVector& lsub, const Index lptr, const Index no_zeros) -{ - typedef typename ScalarVector::Scalar Scalar; - // First, copy U[*,j] segment from dense(*) to tempv(*) - // The result of triangular solve is in tempv[*]; - // The result of matric-vector update is in dense[*] - Index isub = lptr + no_zeros; - Index i; - Index irow; - for (i = 0; i < ((SegSizeAtCompileTime==Dynamic)?segsize:SegSizeAtCompileTime); i++) - { - irow = lsub(isub); - tempv(i) = dense(irow); - ++isub; - } - // Dense triangular solve -- start effective triangle - luptr += lda * no_zeros + no_zeros; - // Form Eigen matrix and vector - Map<Matrix<Scalar,SegSizeAtCompileTime,SegSizeAtCompileTime, ColMajor>, 0, OuterStride<> > A( &(lusup.data()[luptr]), segsize, segsize, OuterStride<>(lda) ); - Map<Matrix<Scalar,SegSizeAtCompileTime,1> > u(tempv.data(), segsize); - - u = A.template triangularView<UnitLower>().solve(u); - - // Dense matrix-vector product y <-- B*x - luptr += segsize; - const Index PacketSize = internal::packet_traits<Scalar>::size; - Index ldl = internal::first_multiple(nrow, PacketSize); - Map<Matrix<Scalar,Dynamic,SegSizeAtCompileTime, ColMajor>, 0, OuterStride<> > B( &(lusup.data()[luptr]), nrow, segsize, OuterStride<>(lda) ); - Index aligned_offset = internal::first_default_aligned(tempv.data()+segsize, PacketSize); - Index aligned_with_B_offset = (PacketSize-internal::first_default_aligned(B.data(), PacketSize))%PacketSize; - Map<Matrix<Scalar,Dynamic,1>, 0, OuterStride<> > l(tempv.data()+segsize+aligned_offset+aligned_with_B_offset, nrow, OuterStride<>(ldl) ); - - l.setZero(); - internal::sparselu_gemm<Scalar>(l.rows(), l.cols(), B.cols(), B.data(), B.outerStride(), u.data(), u.outerStride(), l.data(), l.outerStride()); - - // Scatter tempv[] into SPA dense[] as a temporary storage - isub = lptr + no_zeros; - for (i = 0; i < ((SegSizeAtCompileTime==Dynamic)?segsize:SegSizeAtCompileTime); i++) - { - irow = lsub(isub++); - dense(irow) = tempv(i); - } - - // Scatter l into SPA dense[] - for (i = 0; i < nrow; i++) - { - irow = lsub(isub++); - dense(irow) -= l(i); - } -} - -template <> struct LU_kernel_bmod<1> -{ - template <typename BlockScalarVector, typename ScalarVector, typename IndexVector> - static EIGEN_DONT_INLINE void run(const Index /*segsize*/, BlockScalarVector& dense, ScalarVector& /*tempv*/, ScalarVector& lusup, Index& luptr, - const Index lda, const Index nrow, IndexVector& lsub, const Index lptr, const Index no_zeros); -}; - - -template <typename BlockScalarVector, typename ScalarVector, typename IndexVector> -EIGEN_DONT_INLINE void LU_kernel_bmod<1>::run(const Index /*segsize*/, BlockScalarVector& dense, ScalarVector& /*tempv*/, ScalarVector& lusup, Index& luptr, - const Index lda, const Index nrow, IndexVector& lsub, const Index lptr, const Index no_zeros) -{ - typedef typename ScalarVector::Scalar Scalar; - typedef typename IndexVector::Scalar StorageIndex; - Scalar f = dense(lsub(lptr + no_zeros)); - luptr += lda * no_zeros + no_zeros + 1; - const Scalar* a(lusup.data() + luptr); - const StorageIndex* irow(lsub.data()+lptr + no_zeros + 1); - Index i = 0; - for (; i+1 < nrow; i+=2) - { - Index i0 = *(irow++); - Index i1 = *(irow++); - Scalar a0 = *(a++); - Scalar a1 = *(a++); - Scalar d0 = dense.coeff(i0); - Scalar d1 = dense.coeff(i1); - d0 -= f*a0; - d1 -= f*a1; - dense.coeffRef(i0) = d0; - dense.coeffRef(i1) = d1; - } - if(i<nrow) - dense.coeffRef(*(irow++)) -= f * *(a++); -} - -} // end namespace internal - -} // end namespace Eigen -#endif // SPARSELU_KERNEL_BMOD_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_panel_bmod.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_panel_bmod.h deleted file mode 100644 index f052001c..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_panel_bmod.h +++ /dev/null @@ -1,223 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* - - * NOTE: This file is the modified version of [s,d,c,z]panel_bmod.c file in SuperLU - - * -- SuperLU routine (version 3.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * October 15, 2003 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ -#ifndef SPARSELU_PANEL_BMOD_H -#define SPARSELU_PANEL_BMOD_H - -namespace Eigen { -namespace internal { - -/** - * \brief Performs numeric block updates (sup-panel) in topological order. - * - * Before entering this routine, the original nonzeros in the panel - * were already copied into the spa[m,w] - * - * \param m number of rows in the matrix - * \param w Panel size - * \param jcol Starting column of the panel - * \param nseg Number of segments in the U part - * \param dense Store the full representation of the panel - * \param tempv working array - * \param segrep segment representative... first row in the segment - * \param repfnz First nonzero rows - * \param glu Global LU data. - * - * - */ -template <typename Scalar, typename StorageIndex> -void SparseLUImpl<Scalar,StorageIndex>::panel_bmod(const Index m, const Index w, const Index jcol, - const Index nseg, ScalarVector& dense, ScalarVector& tempv, - IndexVector& segrep, IndexVector& repfnz, GlobalLU_t& glu) -{ - - Index ksub,jj,nextl_col; - Index fsupc, nsupc, nsupr, nrow; - Index krep, kfnz; - Index lptr; // points to the row subscripts of a supernode - Index luptr; // ... - Index segsize,no_zeros ; - // For each nonz supernode segment of U[*,j] in topological order - Index k = nseg - 1; - const Index PacketSize = internal::packet_traits<Scalar>::size; - - for (ksub = 0; ksub < nseg; ksub++) - { // For each updating supernode - /* krep = representative of current k-th supernode - * fsupc = first supernodal column - * nsupc = number of columns in a supernode - * nsupr = number of rows in a supernode - */ - krep = segrep(k); k--; - fsupc = glu.xsup(glu.supno(krep)); - nsupc = krep - fsupc + 1; - nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); - nrow = nsupr - nsupc; - lptr = glu.xlsub(fsupc); - - // loop over the panel columns to detect the actual number of columns and rows - Index u_rows = 0; - Index u_cols = 0; - for (jj = jcol; jj < jcol + w; jj++) - { - nextl_col = (jj-jcol) * m; - VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero column index for each row - - kfnz = repfnz_col(krep); - if ( kfnz == emptyIdxLU ) - continue; // skip any zero segment - - segsize = krep - kfnz + 1; - u_cols++; - u_rows = (std::max)(segsize,u_rows); - } - - if(nsupc >= 2) - { - Index ldu = internal::first_multiple<Index>(u_rows, PacketSize); - Map<ScalarMatrix, Aligned, OuterStride<> > U(tempv.data(), u_rows, u_cols, OuterStride<>(ldu)); - - // gather U - Index u_col = 0; - for (jj = jcol; jj < jcol + w; jj++) - { - nextl_col = (jj-jcol) * m; - VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero column index for each row - VectorBlock<ScalarVector> dense_col(dense, nextl_col, m); // Scatter/gather entire matrix column from/to here - - kfnz = repfnz_col(krep); - if ( kfnz == emptyIdxLU ) - continue; // skip any zero segment - - segsize = krep - kfnz + 1; - luptr = glu.xlusup(fsupc); - no_zeros = kfnz - fsupc; - - Index isub = lptr + no_zeros; - Index off = u_rows-segsize; - for (Index i = 0; i < off; i++) U(i,u_col) = 0; - for (Index i = 0; i < segsize; i++) - { - Index irow = glu.lsub(isub); - U(i+off,u_col) = dense_col(irow); - ++isub; - } - u_col++; - } - // solve U = A^-1 U - luptr = glu.xlusup(fsupc); - Index lda = glu.xlusup(fsupc+1) - glu.xlusup(fsupc); - no_zeros = (krep - u_rows + 1) - fsupc; - luptr += lda * no_zeros + no_zeros; - MappedMatrixBlock A(glu.lusup.data()+luptr, u_rows, u_rows, OuterStride<>(lda) ); - U = A.template triangularView<UnitLower>().solve(U); - - // update - luptr += u_rows; - MappedMatrixBlock B(glu.lusup.data()+luptr, nrow, u_rows, OuterStride<>(lda) ); - eigen_assert(tempv.size()>w*ldu + nrow*w + 1); - - Index ldl = internal::first_multiple<Index>(nrow, PacketSize); - Index offset = (PacketSize-internal::first_default_aligned(B.data(), PacketSize)) % PacketSize; - MappedMatrixBlock L(tempv.data()+w*ldu+offset, nrow, u_cols, OuterStride<>(ldl)); - - L.setZero(); - internal::sparselu_gemm<Scalar>(L.rows(), L.cols(), B.cols(), B.data(), B.outerStride(), U.data(), U.outerStride(), L.data(), L.outerStride()); - - // scatter U and L - u_col = 0; - for (jj = jcol; jj < jcol + w; jj++) - { - nextl_col = (jj-jcol) * m; - VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero column index for each row - VectorBlock<ScalarVector> dense_col(dense, nextl_col, m); // Scatter/gather entire matrix column from/to here - - kfnz = repfnz_col(krep); - if ( kfnz == emptyIdxLU ) - continue; // skip any zero segment - - segsize = krep - kfnz + 1; - no_zeros = kfnz - fsupc; - Index isub = lptr + no_zeros; - - Index off = u_rows-segsize; - for (Index i = 0; i < segsize; i++) - { - Index irow = glu.lsub(isub++); - dense_col(irow) = U.coeff(i+off,u_col); - U.coeffRef(i+off,u_col) = 0; - } - - // Scatter l into SPA dense[] - for (Index i = 0; i < nrow; i++) - { - Index irow = glu.lsub(isub++); - dense_col(irow) -= L.coeff(i,u_col); - L.coeffRef(i,u_col) = 0; - } - u_col++; - } - } - else // level 2 only - { - // Sequence through each column in the panel - for (jj = jcol; jj < jcol + w; jj++) - { - nextl_col = (jj-jcol) * m; - VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero column index for each row - VectorBlock<ScalarVector> dense_col(dense, nextl_col, m); // Scatter/gather entire matrix column from/to here - - kfnz = repfnz_col(krep); - if ( kfnz == emptyIdxLU ) - continue; // skip any zero segment - - segsize = krep - kfnz + 1; - luptr = glu.xlusup(fsupc); - - Index lda = glu.xlusup(fsupc+1)-glu.xlusup(fsupc);// nsupr - - // Perform a trianglar solve and block update, - // then scatter the result of sup-col update to dense[] - no_zeros = kfnz - fsupc; - if(segsize==1) LU_kernel_bmod<1>::run(segsize, dense_col, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros); - else if(segsize==2) LU_kernel_bmod<2>::run(segsize, dense_col, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros); - else if(segsize==3) LU_kernel_bmod<3>::run(segsize, dense_col, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros); - else LU_kernel_bmod<Dynamic>::run(segsize, dense_col, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros); - } // End for each column in the panel - } - - } // End for each updating supernode -} // end panel bmod - -} // end namespace internal - -} // end namespace Eigen - -#endif // SPARSELU_PANEL_BMOD_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_panel_dfs.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_panel_dfs.h deleted file mode 100644 index 155df733..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_panel_dfs.h +++ /dev/null @@ -1,258 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* - - * NOTE: This file is the modified version of [s,d,c,z]panel_dfs.c file in SuperLU - - * -- SuperLU routine (version 2.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * November 15, 1997 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ -#ifndef SPARSELU_PANEL_DFS_H -#define SPARSELU_PANEL_DFS_H - -namespace Eigen { - -namespace internal { - -template<typename IndexVector> -struct panel_dfs_traits -{ - typedef typename IndexVector::Scalar StorageIndex; - panel_dfs_traits(Index jcol, StorageIndex* marker) - : m_jcol(jcol), m_marker(marker) - {} - bool update_segrep(Index krep, StorageIndex jj) - { - if(m_marker[krep]<m_jcol) - { - m_marker[krep] = jj; - return true; - } - return false; - } - void mem_expand(IndexVector& /*glu.lsub*/, Index /*nextl*/, Index /*chmark*/) {} - enum { ExpandMem = false }; - Index m_jcol; - StorageIndex* m_marker; -}; - - -template <typename Scalar, typename StorageIndex> -template <typename Traits> -void SparseLUImpl<Scalar,StorageIndex>::dfs_kernel(const StorageIndex jj, IndexVector& perm_r, - Index& nseg, IndexVector& panel_lsub, IndexVector& segrep, - Ref<IndexVector> repfnz_col, IndexVector& xprune, Ref<IndexVector> marker, IndexVector& parent, - IndexVector& xplore, GlobalLU_t& glu, - Index& nextl_col, Index krow, Traits& traits - ) -{ - - StorageIndex kmark = marker(krow); - - // For each unmarked krow of jj - marker(krow) = jj; - StorageIndex kperm = perm_r(krow); - if (kperm == emptyIdxLU ) { - // krow is in L : place it in structure of L(*, jj) - panel_lsub(nextl_col++) = StorageIndex(krow); // krow is indexed into A - - traits.mem_expand(panel_lsub, nextl_col, kmark); - } - else - { - // krow is in U : if its supernode-representative krep - // has been explored, update repfnz(*) - // krep = supernode representative of the current row - StorageIndex krep = glu.xsup(glu.supno(kperm)+1) - 1; - // First nonzero element in the current column: - StorageIndex myfnz = repfnz_col(krep); - - if (myfnz != emptyIdxLU ) - { - // Representative visited before - if (myfnz > kperm ) repfnz_col(krep) = kperm; - - } - else - { - // Otherwise, perform dfs starting at krep - StorageIndex oldrep = emptyIdxLU; - parent(krep) = oldrep; - repfnz_col(krep) = kperm; - StorageIndex xdfs = glu.xlsub(krep); - Index maxdfs = xprune(krep); - - StorageIndex kpar; - do - { - // For each unmarked kchild of krep - while (xdfs < maxdfs) - { - StorageIndex kchild = glu.lsub(xdfs); - xdfs++; - StorageIndex chmark = marker(kchild); - - if (chmark != jj ) - { - marker(kchild) = jj; - StorageIndex chperm = perm_r(kchild); - - if (chperm == emptyIdxLU) - { - // case kchild is in L: place it in L(*, j) - panel_lsub(nextl_col++) = kchild; - traits.mem_expand(panel_lsub, nextl_col, chmark); - } - else - { - // case kchild is in U : - // chrep = its supernode-rep. If its rep has been explored, - // update its repfnz(*) - StorageIndex chrep = glu.xsup(glu.supno(chperm)+1) - 1; - myfnz = repfnz_col(chrep); - - if (myfnz != emptyIdxLU) - { // Visited before - if (myfnz > chperm) - repfnz_col(chrep) = chperm; - } - else - { // Cont. dfs at snode-rep of kchild - xplore(krep) = xdfs; - oldrep = krep; - krep = chrep; // Go deeper down G(L) - parent(krep) = oldrep; - repfnz_col(krep) = chperm; - xdfs = glu.xlsub(krep); - maxdfs = xprune(krep); - - } // end if myfnz != -1 - } // end if chperm == -1 - - } // end if chmark !=jj - } // end while xdfs < maxdfs - - // krow has no more unexplored nbrs : - // Place snode-rep krep in postorder DFS, if this - // segment is seen for the first time. (Note that - // "repfnz(krep)" may change later.) - // Baktrack dfs to its parent - if(traits.update_segrep(krep,jj)) - //if (marker1(krep) < jcol ) - { - segrep(nseg) = krep; - ++nseg; - //marker1(krep) = jj; - } - - kpar = parent(krep); // Pop recursion, mimic recursion - if (kpar == emptyIdxLU) - break; // dfs done - krep = kpar; - xdfs = xplore(krep); - maxdfs = xprune(krep); - - } while (kpar != emptyIdxLU); // Do until empty stack - - } // end if (myfnz = -1) - - } // end if (kperm == -1) -} - -/** - * \brief Performs a symbolic factorization on a panel of columns [jcol, jcol+w) - * - * A supernode representative is the last column of a supernode. - * The nonzeros in U[*,j] are segments that end at supernodes representatives - * - * The routine returns a list of the supernodal representatives - * in topological order of the dfs that generates them. This list is - * a superset of the topological order of each individual column within - * the panel. - * The location of the first nonzero in each supernodal segment - * (supernodal entry location) is also returned. Each column has - * a separate list for this purpose. - * - * Two markers arrays are used for dfs : - * marker[i] == jj, if i was visited during dfs of current column jj; - * marker1[i] >= jcol, if i was visited by earlier columns in this panel; - * - * \param[in] m number of rows in the matrix - * \param[in] w Panel size - * \param[in] jcol Starting column of the panel - * \param[in] A Input matrix in column-major storage - * \param[in] perm_r Row permutation - * \param[out] nseg Number of U segments - * \param[out] dense Accumulate the column vectors of the panel - * \param[out] panel_lsub Subscripts of the row in the panel - * \param[out] segrep Segment representative i.e first nonzero row of each segment - * \param[out] repfnz First nonzero location in each row - * \param[out] xprune The pruned elimination tree - * \param[out] marker work vector - * \param parent The elimination tree - * \param xplore work vector - * \param glu The global data structure - * - */ - -template <typename Scalar, typename StorageIndex> -void SparseLUImpl<Scalar,StorageIndex>::panel_dfs(const Index m, const Index w, const Index jcol, MatrixType& A, IndexVector& perm_r, Index& nseg, ScalarVector& dense, IndexVector& panel_lsub, IndexVector& segrep, IndexVector& repfnz, IndexVector& xprune, IndexVector& marker, IndexVector& parent, IndexVector& xplore, GlobalLU_t& glu) -{ - Index nextl_col; // Next available position in panel_lsub[*,jj] - - // Initialize pointers - VectorBlock<IndexVector> marker1(marker, m, m); - nseg = 0; - - panel_dfs_traits<IndexVector> traits(jcol, marker1.data()); - - // For each column in the panel - for (StorageIndex jj = StorageIndex(jcol); jj < jcol + w; jj++) - { - nextl_col = (jj - jcol) * m; - - VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero location in each row - VectorBlock<ScalarVector> dense_col(dense,nextl_col, m); // Accumulate a column vector here - - - // For each nnz in A[*, jj] do depth first search - for (typename MatrixType::InnerIterator it(A, jj); it; ++it) - { - Index krow = it.row(); - dense_col(krow) = it.value(); - - StorageIndex kmark = marker(krow); - if (kmark == jj) - continue; // krow visited before, go to the next nonzero - - dfs_kernel(jj, perm_r, nseg, panel_lsub, segrep, repfnz_col, xprune, marker, parent, - xplore, glu, nextl_col, krow, traits); - }// end for nonzeros in column jj - - } // end for column jj -} - -} // end namespace internal -} // end namespace Eigen - -#endif // SPARSELU_PANEL_DFS_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_pivotL.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_pivotL.h deleted file mode 100644 index a86dac93..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_pivotL.h +++ /dev/null @@ -1,137 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* - - * NOTE: This file is the modified version of xpivotL.c file in SuperLU - - * -- SuperLU routine (version 3.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * October 15, 2003 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ -#ifndef SPARSELU_PIVOTL_H -#define SPARSELU_PIVOTL_H - -namespace Eigen { -namespace internal { - -/** - * \brief Performs the numerical pivotin on the current column of L, and the CDIV operation. - * - * Pivot policy : - * (1) Compute thresh = u * max_(i>=j) abs(A_ij); - * (2) IF user specifies pivot row k and abs(A_kj) >= thresh THEN - * pivot row = k; - * ELSE IF abs(A_jj) >= thresh THEN - * pivot row = j; - * ELSE - * pivot row = m; - * - * Note: If you absolutely want to use a given pivot order, then set u=0.0. - * - * \param jcol The current column of L - * \param diagpivotthresh diagonal pivoting threshold - * \param[in,out] perm_r Row permutation (threshold pivoting) - * \param[in] iperm_c column permutation - used to finf diagonal of Pc*A*Pc' - * \param[out] pivrow The pivot row - * \param glu Global LU data - * \return 0 if success, i > 0 if U(i,i) is exactly zero - * - */ -template <typename Scalar, typename StorageIndex> -Index SparseLUImpl<Scalar,StorageIndex>::pivotL(const Index jcol, const RealScalar& diagpivotthresh, IndexVector& perm_r, IndexVector& iperm_c, Index& pivrow, GlobalLU_t& glu) -{ - - Index fsupc = (glu.xsup)((glu.supno)(jcol)); // First column in the supernode containing the column jcol - Index nsupc = jcol - fsupc; // Number of columns in the supernode portion, excluding jcol; nsupc >=0 - Index lptr = glu.xlsub(fsupc); // pointer to the starting location of the row subscripts for this supernode portion - Index nsupr = glu.xlsub(fsupc+1) - lptr; // Number of rows in the supernode - Index lda = glu.xlusup(fsupc+1) - glu.xlusup(fsupc); // leading dimension - Scalar* lu_sup_ptr = &(glu.lusup.data()[glu.xlusup(fsupc)]); // Start of the current supernode - Scalar* lu_col_ptr = &(glu.lusup.data()[glu.xlusup(jcol)]); // Start of jcol in the supernode - StorageIndex* lsub_ptr = &(glu.lsub.data()[lptr]); // Start of row indices of the supernode - - // Determine the largest abs numerical value for partial pivoting - Index diagind = iperm_c(jcol); // diagonal index - RealScalar pivmax(-1.0); - Index pivptr = nsupc; - Index diag = emptyIdxLU; - RealScalar rtemp; - Index isub, icol, itemp, k; - for (isub = nsupc; isub < nsupr; ++isub) { - using std::abs; - rtemp = abs(lu_col_ptr[isub]); - if (rtemp > pivmax) { - pivmax = rtemp; - pivptr = isub; - } - if (lsub_ptr[isub] == diagind) diag = isub; - } - - // Test for singularity - if ( pivmax <= RealScalar(0.0) ) { - // if pivmax == -1, the column is structurally empty, otherwise it is only numerically zero - pivrow = pivmax < RealScalar(0.0) ? diagind : lsub_ptr[pivptr]; - perm_r(pivrow) = StorageIndex(jcol); - return (jcol+1); - } - - RealScalar thresh = diagpivotthresh * pivmax; - - // Choose appropriate pivotal element - - { - // Test if the diagonal element can be used as a pivot (given the threshold value) - if (diag >= 0 ) - { - // Diagonal element exists - using std::abs; - rtemp = abs(lu_col_ptr[diag]); - if (rtemp != RealScalar(0.0) && rtemp >= thresh) pivptr = diag; - } - pivrow = lsub_ptr[pivptr]; - } - - // Record pivot row - perm_r(pivrow) = StorageIndex(jcol); - // Interchange row subscripts - if (pivptr != nsupc ) - { - std::swap( lsub_ptr[pivptr], lsub_ptr[nsupc] ); - // Interchange numerical values as well, for the two rows in the whole snode - // such that L is indexed the same way as A - for (icol = 0; icol <= nsupc; icol++) - { - itemp = pivptr + icol * lda; - std::swap(lu_sup_ptr[itemp], lu_sup_ptr[nsupc + icol * lda]); - } - } - // cdiv operations - Scalar temp = Scalar(1.0) / lu_col_ptr[nsupc]; - for (k = nsupc+1; k < nsupr; k++) - lu_col_ptr[k] *= temp; - return 0; -} - -} // end namespace internal -} // end namespace Eigen - -#endif // SPARSELU_PIVOTL_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_pruneL.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_pruneL.h deleted file mode 100644 index ad32fed5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_pruneL.h +++ /dev/null @@ -1,136 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* - - * NOTE: This file is the modified version of [s,d,c,z]pruneL.c file in SuperLU - - * -- SuperLU routine (version 2.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * November 15, 1997 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ -#ifndef SPARSELU_PRUNEL_H -#define SPARSELU_PRUNEL_H - -namespace Eigen { -namespace internal { - -/** - * \brief Prunes the L-structure. - * - * It prunes the L-structure of supernodes whose L-structure contains the current pivot row "pivrow" - * - * - * \param jcol The current column of L - * \param[in] perm_r Row permutation - * \param[out] pivrow The pivot row - * \param nseg Number of segments - * \param segrep - * \param repfnz - * \param[out] xprune - * \param glu Global LU data - * - */ -template <typename Scalar, typename StorageIndex> -void SparseLUImpl<Scalar,StorageIndex>::pruneL(const Index jcol, const IndexVector& perm_r, const Index pivrow, const Index nseg, - const IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune, GlobalLU_t& glu) -{ - // For each supernode-rep irep in U(*,j] - Index jsupno = glu.supno(jcol); - Index i,irep,irep1; - bool movnum, do_prune = false; - Index kmin = 0, kmax = 0, minloc, maxloc,krow; - for (i = 0; i < nseg; i++) - { - irep = segrep(i); - irep1 = irep + 1; - do_prune = false; - - // Don't prune with a zero U-segment - if (repfnz(irep) == emptyIdxLU) continue; - - // If a snode overlaps with the next panel, then the U-segment - // is fragmented into two parts -- irep and irep1. We should let - // pruning occur at the rep-column in irep1s snode. - if (glu.supno(irep) == glu.supno(irep1) ) continue; // don't prune - - // If it has not been pruned & it has a nonz in row L(pivrow,i) - if (glu.supno(irep) != jsupno ) - { - if ( xprune (irep) >= glu.xlsub(irep1) ) - { - kmin = glu.xlsub(irep); - kmax = glu.xlsub(irep1) - 1; - for (krow = kmin; krow <= kmax; krow++) - { - if (glu.lsub(krow) == pivrow) - { - do_prune = true; - break; - } - } - } - - if (do_prune) - { - // do a quicksort-type partition - // movnum=true means that the num values have to be exchanged - movnum = false; - if (irep == glu.xsup(glu.supno(irep)) ) // Snode of size 1 - movnum = true; - - while (kmin <= kmax) - { - if (perm_r(glu.lsub(kmax)) == emptyIdxLU) - kmax--; - else if ( perm_r(glu.lsub(kmin)) != emptyIdxLU) - kmin++; - else - { - // kmin below pivrow (not yet pivoted), and kmax - // above pivrow: interchange the two suscripts - std::swap(glu.lsub(kmin), glu.lsub(kmax)); - - // If the supernode has only one column, then we - // only keep one set of subscripts. For any subscript - // intercnahge performed, similar interchange must be - // done on the numerical values. - if (movnum) - { - minloc = glu.xlusup(irep) + ( kmin - glu.xlsub(irep) ); - maxloc = glu.xlusup(irep) + ( kmax - glu.xlsub(irep) ); - std::swap(glu.lusup(minloc), glu.lusup(maxloc)); - } - kmin++; - kmax--; - } - } // end while - - xprune(irep) = StorageIndex(kmin); //Pruning - } // end if do_prune - } // end pruning - } // End for each U-segment -} - -} // end namespace internal -} // end namespace Eigen - -#endif // SPARSELU_PRUNEL_H diff --git a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_relax_snode.h b/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_relax_snode.h deleted file mode 100644 index c408d01b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseLU/SparseLU_relax_snode.h +++ /dev/null @@ -1,83 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/* This file is a modified version of heap_relax_snode.c file in SuperLU - * -- SuperLU routine (version 3.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * October 15, 2003 - * - * Copyright (c) 1994 by Xerox Corporation. All rights reserved. - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - */ - -#ifndef SPARSELU_RELAX_SNODE_H -#define SPARSELU_RELAX_SNODE_H - -namespace Eigen { - -namespace internal { - -/** - * \brief Identify the initial relaxed supernodes - * - * This routine is applied to a column elimination tree. - * It assumes that the matrix has been reordered according to the postorder of the etree - * \param n the number of columns - * \param et elimination tree - * \param relax_columns Maximum number of columns allowed in a relaxed snode - * \param descendants Number of descendants of each node in the etree - * \param relax_end last column in a supernode - */ -template <typename Scalar, typename StorageIndex> -void SparseLUImpl<Scalar,StorageIndex>::relax_snode (const Index n, IndexVector& et, const Index relax_columns, IndexVector& descendants, IndexVector& relax_end) -{ - - // compute the number of descendants of each node in the etree - Index parent; - relax_end.setConstant(emptyIdxLU); - descendants.setZero(); - for (Index j = 0; j < n; j++) - { - parent = et(j); - if (parent != n) // not the dummy root - descendants(parent) += descendants(j) + 1; - } - // Identify the relaxed supernodes by postorder traversal of the etree - Index snode_start; // beginning of a snode - for (Index j = 0; j < n; ) - { - parent = et(j); - snode_start = j; - while ( parent != n && descendants(parent) < relax_columns ) - { - j = parent; - parent = et(j); - } - // Found a supernode in postordered etree, j is the last column - relax_end(snode_start) = StorageIndex(j); // Record last column - j++; - // Search for a new leaf - while (descendants(j) != 0 && j < n) j++; - } // End postorder traversal of the etree - -} - -} // end namespace internal - -} // end namespace Eigen -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/SparseQR/SparseQR.h b/external/eigen/include/eigen3/Eigen/src/SparseQR/SparseQR.h deleted file mode 100644 index d1fb96f5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SparseQR/SparseQR.h +++ /dev/null @@ -1,758 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012-2013 Desire Nuentsa <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2012-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_QR_H -#define EIGEN_SPARSE_QR_H - -namespace Eigen { - -template<typename MatrixType, typename OrderingType> class SparseQR; -template<typename SparseQRType> struct SparseQRMatrixQReturnType; -template<typename SparseQRType> struct SparseQRMatrixQTransposeReturnType; -template<typename SparseQRType, typename Derived> struct SparseQR_QProduct; -namespace internal { - template <typename SparseQRType> struct traits<SparseQRMatrixQReturnType<SparseQRType> > - { - typedef typename SparseQRType::MatrixType ReturnType; - typedef typename ReturnType::StorageIndex StorageIndex; - typedef typename ReturnType::StorageKind StorageKind; - enum { - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = Dynamic - }; - }; - template <typename SparseQRType> struct traits<SparseQRMatrixQTransposeReturnType<SparseQRType> > - { - typedef typename SparseQRType::MatrixType ReturnType; - }; - template <typename SparseQRType, typename Derived> struct traits<SparseQR_QProduct<SparseQRType, Derived> > - { - typedef typename Derived::PlainObject ReturnType; - }; -} // End namespace internal - -/** - * \ingroup SparseQR_Module - * \class SparseQR - * \brief Sparse left-looking QR factorization with numerical column pivoting - * - * This class implements a left-looking QR decomposition of sparse matrices - * with numerical column pivoting. - * When a column has a norm less than a given tolerance - * it is implicitly permuted to the end. The QR factorization thus obtained is - * given by A*P = Q*R where R is upper triangular or trapezoidal. - * - * P is the column permutation which is the product of the fill-reducing and the - * numerical permutations. Use colsPermutation() to get it. - * - * Q is the orthogonal matrix represented as products of Householder reflectors. - * Use matrixQ() to get an expression and matrixQ().adjoint() to get the adjoint. - * You can then apply it to a vector. - * - * R is the sparse triangular or trapezoidal matrix. The later occurs when A is rank-deficient. - * matrixR().topLeftCorner(rank(), rank()) always returns a triangular factor of full rank. - * - * \tparam _MatrixType The type of the sparse matrix A, must be a column-major SparseMatrix<> - * \tparam _OrderingType The fill-reducing ordering method. See the \link OrderingMethods_Module - * OrderingMethods \endlink module for the list of built-in and external ordering methods. - * - * \implsparsesolverconcept - * - * The numerical pivoting strategy and default threshold are the same as in SuiteSparse QR, and - * detailed in the following paper: - * <i> - * Tim Davis, "Algorithm 915, SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing - * Sparse QR Factorization, ACM Trans. on Math. Soft. 38(1), 2011. - * </i> - * Even though it is qualified as "rank-revealing", this strategy might fail for some - * rank deficient problems. When this class is used to solve linear or least-square problems - * it is thus strongly recommended to check the accuracy of the computed solution. If it - * failed, it usually helps to increase the threshold with setPivotThreshold. - * - * \warning The input sparse matrix A must be in compressed mode (see SparseMatrix::makeCompressed()). - * \warning For complex matrices matrixQ().transpose() will actually return the adjoint matrix. - * - */ -template<typename _MatrixType, typename _OrderingType> -class SparseQR : public SparseSolverBase<SparseQR<_MatrixType,_OrderingType> > -{ - protected: - typedef SparseSolverBase<SparseQR<_MatrixType,_OrderingType> > Base; - using Base::m_isInitialized; - public: - using Base::_solve_impl; - typedef _MatrixType MatrixType; - typedef _OrderingType OrderingType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef SparseMatrix<Scalar,ColMajor,StorageIndex> QRMatrixType; - typedef Matrix<StorageIndex, Dynamic, 1> IndexVector; - typedef Matrix<Scalar, Dynamic, 1> ScalarVector; - typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType; - - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - public: - SparseQR () : m_analysisIsok(false), m_lastError(""), m_useDefaultThreshold(true),m_isQSorted(false),m_isEtreeOk(false) - { } - - /** Construct a QR factorization of the matrix \a mat. - * - * \warning The matrix \a mat must be in compressed mode (see SparseMatrix::makeCompressed()). - * - * \sa compute() - */ - explicit SparseQR(const MatrixType& mat) : m_analysisIsok(false), m_lastError(""), m_useDefaultThreshold(true),m_isQSorted(false),m_isEtreeOk(false) - { - compute(mat); - } - - /** Computes the QR factorization of the sparse matrix \a mat. - * - * \warning The matrix \a mat must be in compressed mode (see SparseMatrix::makeCompressed()). - * - * \sa analyzePattern(), factorize() - */ - void compute(const MatrixType& mat) - { - analyzePattern(mat); - factorize(mat); - } - void analyzePattern(const MatrixType& mat); - void factorize(const MatrixType& mat); - - /** \returns the number of rows of the represented matrix. - */ - inline Index rows() const { return m_pmat.rows(); } - - /** \returns the number of columns of the represented matrix. - */ - inline Index cols() const { return m_pmat.cols();} - - /** \returns a const reference to the \b sparse upper triangular matrix R of the QR factorization. - * \warning The entries of the returned matrix are not sorted. This means that using it in algorithms - * expecting sorted entries will fail. This include random coefficient accesses (SpaseMatrix::coeff()), - * and coefficient-wise operations. Matrix products and triangular solves are fine though. - * - * To sort the entries, you can assign it to a row-major matrix, and if a column-major matrix - * is required, you can copy it again: - * \code - * SparseMatrix<double> R = qr.matrixR(); // column-major, not sorted! - * SparseMatrix<double,RowMajor> Rr = qr.matrixR(); // row-major, sorted - * SparseMatrix<double> Rc = Rr; // column-major, sorted - * \endcode - */ - const QRMatrixType& matrixR() const { return m_R; } - - /** \returns the number of non linearly dependent columns as determined by the pivoting threshold. - * - * \sa setPivotThreshold() - */ - Index rank() const - { - eigen_assert(m_isInitialized && "The factorization should be called first, use compute()"); - return m_nonzeropivots; - } - - /** \returns an expression of the matrix Q as products of sparse Householder reflectors. - * The common usage of this function is to apply it to a dense matrix or vector - * \code - * VectorXd B1, B2; - * // Initialize B1 - * B2 = matrixQ() * B1; - * \endcode - * - * To get a plain SparseMatrix representation of Q: - * \code - * SparseMatrix<double> Q; - * Q = SparseQR<SparseMatrix<double> >(A).matrixQ(); - * \endcode - * Internally, this call simply performs a sparse product between the matrix Q - * and a sparse identity matrix. However, due to the fact that the sparse - * reflectors are stored unsorted, two transpositions are needed to sort - * them before performing the product. - */ - SparseQRMatrixQReturnType<SparseQR> matrixQ() const - { return SparseQRMatrixQReturnType<SparseQR>(*this); } - - /** \returns a const reference to the column permutation P that was applied to A such that A*P = Q*R - * It is the combination of the fill-in reducing permutation and numerical column pivoting. - */ - const PermutationType& colsPermutation() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_outputPerm_c; - } - - /** \returns A string describing the type of error. - * This method is provided to ease debugging, not to handle errors. - */ - std::string lastErrorMessage() const { return m_lastError; } - - /** \internal */ - template<typename Rhs, typename Dest> - bool _solve_impl(const MatrixBase<Rhs> &B, MatrixBase<Dest> &dest) const - { - eigen_assert(m_isInitialized && "The factorization should be called first, use compute()"); - eigen_assert(this->rows() == B.rows() && "SparseQR::solve() : invalid number of rows in the right hand side matrix"); - - Index rank = this->rank(); - - // Compute Q^* * b; - typename Dest::PlainObject y, b; - y = this->matrixQ().adjoint() * B; - b = y; - - // Solve with the triangular matrix R - y.resize((std::max<Index>)(cols(),y.rows()),y.cols()); - y.topRows(rank) = this->matrixR().topLeftCorner(rank, rank).template triangularView<Upper>().solve(b.topRows(rank)); - y.bottomRows(y.rows()-rank).setZero(); - - // Apply the column permutation - if (m_perm_c.size()) dest = colsPermutation() * y.topRows(cols()); - else dest = y.topRows(cols()); - - m_info = Success; - return true; - } - - /** Sets the threshold that is used to determine linearly dependent columns during the factorization. - * - * In practice, if during the factorization the norm of the column that has to be eliminated is below - * this threshold, then the entire column is treated as zero, and it is moved at the end. - */ - void setPivotThreshold(const RealScalar& threshold) - { - m_useDefaultThreshold = false; - m_threshold = threshold; - } - - /** \returns the solution X of \f$ A X = B \f$ using the current decomposition of A. - * - * \sa compute() - */ - template<typename Rhs> - inline const Solve<SparseQR, Rhs> solve(const MatrixBase<Rhs>& B) const - { - eigen_assert(m_isInitialized && "The factorization should be called first, use compute()"); - eigen_assert(this->rows() == B.rows() && "SparseQR::solve() : invalid number of rows in the right hand side matrix"); - return Solve<SparseQR, Rhs>(*this, B.derived()); - } - template<typename Rhs> - inline const Solve<SparseQR, Rhs> solve(const SparseMatrixBase<Rhs>& B) const - { - eigen_assert(m_isInitialized && "The factorization should be called first, use compute()"); - eigen_assert(this->rows() == B.rows() && "SparseQR::solve() : invalid number of rows in the right hand side matrix"); - return Solve<SparseQR, Rhs>(*this, B.derived()); - } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the QR factorization reports a numerical problem - * \c InvalidInput if the input matrix is invalid - * - * \sa iparm() - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - - - /** \internal */ - inline void _sort_matrix_Q() - { - if(this->m_isQSorted) return; - // The matrix Q is sorted during the transposition - SparseMatrix<Scalar, RowMajor, Index> mQrm(this->m_Q); - this->m_Q = mQrm; - this->m_isQSorted = true; - } - - - protected: - bool m_analysisIsok; - bool m_factorizationIsok; - mutable ComputationInfo m_info; - std::string m_lastError; - QRMatrixType m_pmat; // Temporary matrix - QRMatrixType m_R; // The triangular factor matrix - QRMatrixType m_Q; // The orthogonal reflectors - ScalarVector m_hcoeffs; // The Householder coefficients - PermutationType m_perm_c; // Fill-reducing Column permutation - PermutationType m_pivotperm; // The permutation for rank revealing - PermutationType m_outputPerm_c; // The final column permutation - RealScalar m_threshold; // Threshold to determine null Householder reflections - bool m_useDefaultThreshold; // Use default threshold - Index m_nonzeropivots; // Number of non zero pivots found - IndexVector m_etree; // Column elimination tree - IndexVector m_firstRowElt; // First element in each row - bool m_isQSorted; // whether Q is sorted or not - bool m_isEtreeOk; // whether the elimination tree match the initial input matrix - - template <typename, typename > friend struct SparseQR_QProduct; - -}; - -/** \brief Preprocessing step of a QR factorization - * - * \warning The matrix \a mat must be in compressed mode (see SparseMatrix::makeCompressed()). - * - * In this step, the fill-reducing permutation is computed and applied to the columns of A - * and the column elimination tree is computed as well. Only the sparsity pattern of \a mat is exploited. - * - * \note In this step it is assumed that there is no empty row in the matrix \a mat. - */ -template <typename MatrixType, typename OrderingType> -void SparseQR<MatrixType,OrderingType>::analyzePattern(const MatrixType& mat) -{ - eigen_assert(mat.isCompressed() && "SparseQR requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it to SparseQR"); - // Copy to a column major matrix if the input is rowmajor - typename internal::conditional<MatrixType::IsRowMajor,QRMatrixType,const MatrixType&>::type matCpy(mat); - // Compute the column fill reducing ordering - OrderingType ord; - ord(matCpy, m_perm_c); - Index n = mat.cols(); - Index m = mat.rows(); - Index diagSize = (std::min)(m,n); - - if (!m_perm_c.size()) - { - m_perm_c.resize(n); - m_perm_c.indices().setLinSpaced(n, 0,StorageIndex(n-1)); - } - - // Compute the column elimination tree of the permuted matrix - m_outputPerm_c = m_perm_c.inverse(); - internal::coletree(matCpy, m_etree, m_firstRowElt, m_outputPerm_c.indices().data()); - m_isEtreeOk = true; - - m_R.resize(m, n); - m_Q.resize(m, diagSize); - - // Allocate space for nonzero elements: rough estimation - m_R.reserve(2*mat.nonZeros()); //FIXME Get a more accurate estimation through symbolic factorization with the etree - m_Q.reserve(2*mat.nonZeros()); - m_hcoeffs.resize(diagSize); - m_analysisIsok = true; -} - -/** \brief Performs the numerical QR factorization of the input matrix - * - * The function SparseQR::analyzePattern(const MatrixType&) must have been called beforehand with - * a matrix having the same sparsity pattern than \a mat. - * - * \param mat The sparse column-major matrix - */ -template <typename MatrixType, typename OrderingType> -void SparseQR<MatrixType,OrderingType>::factorize(const MatrixType& mat) -{ - using std::abs; - - eigen_assert(m_analysisIsok && "analyzePattern() should be called before this step"); - StorageIndex m = StorageIndex(mat.rows()); - StorageIndex n = StorageIndex(mat.cols()); - StorageIndex diagSize = (std::min)(m,n); - IndexVector mark((std::max)(m,n)); mark.setConstant(-1); // Record the visited nodes - IndexVector Ridx(n), Qidx(m); // Store temporarily the row indexes for the current column of R and Q - Index nzcolR, nzcolQ; // Number of nonzero for the current column of R and Q - ScalarVector tval(m); // The dense vector used to compute the current column - RealScalar pivotThreshold = m_threshold; - - m_R.setZero(); - m_Q.setZero(); - m_pmat = mat; - if(!m_isEtreeOk) - { - m_outputPerm_c = m_perm_c.inverse(); - internal::coletree(m_pmat, m_etree, m_firstRowElt, m_outputPerm_c.indices().data()); - m_isEtreeOk = true; - } - - m_pmat.uncompress(); // To have the innerNonZeroPtr allocated - - // Apply the fill-in reducing permutation lazily: - { - // If the input is row major, copy the original column indices, - // otherwise directly use the input matrix - // - IndexVector originalOuterIndicesCpy; - const StorageIndex *originalOuterIndices = mat.outerIndexPtr(); - if(MatrixType::IsRowMajor) - { - originalOuterIndicesCpy = IndexVector::Map(m_pmat.outerIndexPtr(),n+1); - originalOuterIndices = originalOuterIndicesCpy.data(); - } - - for (int i = 0; i < n; i++) - { - Index p = m_perm_c.size() ? m_perm_c.indices()(i) : i; - m_pmat.outerIndexPtr()[p] = originalOuterIndices[i]; - m_pmat.innerNonZeroPtr()[p] = originalOuterIndices[i+1] - originalOuterIndices[i]; - } - } - - /* Compute the default threshold as in MatLab, see: - * Tim Davis, "Algorithm 915, SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing - * Sparse QR Factorization, ACM Trans. on Math. Soft. 38(1), 2011, Page 8:3 - */ - if(m_useDefaultThreshold) - { - RealScalar max2Norm = 0.0; - for (int j = 0; j < n; j++) max2Norm = numext::maxi(max2Norm, m_pmat.col(j).norm()); - if(max2Norm==RealScalar(0)) - max2Norm = RealScalar(1); - pivotThreshold = 20 * (m + n) * max2Norm * NumTraits<RealScalar>::epsilon(); - } - - // Initialize the numerical permutation - m_pivotperm.setIdentity(n); - - StorageIndex nonzeroCol = 0; // Record the number of valid pivots - m_Q.startVec(0); - - // Left looking rank-revealing QR factorization: compute a column of R and Q at a time - for (StorageIndex col = 0; col < n; ++col) - { - mark.setConstant(-1); - m_R.startVec(col); - mark(nonzeroCol) = col; - Qidx(0) = nonzeroCol; - nzcolR = 0; nzcolQ = 1; - bool found_diag = nonzeroCol>=m; - tval.setZero(); - - // Symbolic factorization: find the nonzero locations of the column k of the factors R and Q, i.e., - // all the nodes (with indexes lower than rank) reachable through the column elimination tree (etree) rooted at node k. - // Note: if the diagonal entry does not exist, then its contribution must be explicitly added, - // thus the trick with found_diag that permits to do one more iteration on the diagonal element if this one has not been found. - for (typename QRMatrixType::InnerIterator itp(m_pmat, col); itp || !found_diag; ++itp) - { - StorageIndex curIdx = nonzeroCol; - if(itp) curIdx = StorageIndex(itp.row()); - if(curIdx == nonzeroCol) found_diag = true; - - // Get the nonzeros indexes of the current column of R - StorageIndex st = m_firstRowElt(curIdx); // The traversal of the etree starts here - if (st < 0 ) - { - m_lastError = "Empty row found during numerical factorization"; - m_info = InvalidInput; - return; - } - - // Traverse the etree - Index bi = nzcolR; - for (; mark(st) != col; st = m_etree(st)) - { - Ridx(nzcolR) = st; // Add this row to the list, - mark(st) = col; // and mark this row as visited - nzcolR++; - } - - // Reverse the list to get the topological ordering - Index nt = nzcolR-bi; - for(Index i = 0; i < nt/2; i++) std::swap(Ridx(bi+i), Ridx(nzcolR-i-1)); - - // Copy the current (curIdx,pcol) value of the input matrix - if(itp) tval(curIdx) = itp.value(); - else tval(curIdx) = Scalar(0); - - // Compute the pattern of Q(:,k) - if(curIdx > nonzeroCol && mark(curIdx) != col ) - { - Qidx(nzcolQ) = curIdx; // Add this row to the pattern of Q, - mark(curIdx) = col; // and mark it as visited - nzcolQ++; - } - } - - // Browse all the indexes of R(:,col) in reverse order - for (Index i = nzcolR-1; i >= 0; i--) - { - Index curIdx = Ridx(i); - - // Apply the curIdx-th householder vector to the current column (temporarily stored into tval) - Scalar tdot(0); - - // First compute q' * tval - tdot = m_Q.col(curIdx).dot(tval); - - tdot *= m_hcoeffs(curIdx); - - // Then update tval = tval - q * tau - // FIXME: tval -= tdot * m_Q.col(curIdx) should amount to the same (need to check/add support for efficient "dense ?= sparse") - for (typename QRMatrixType::InnerIterator itq(m_Q, curIdx); itq; ++itq) - tval(itq.row()) -= itq.value() * tdot; - - // Detect fill-in for the current column of Q - if(m_etree(Ridx(i)) == nonzeroCol) - { - for (typename QRMatrixType::InnerIterator itq(m_Q, curIdx); itq; ++itq) - { - StorageIndex iQ = StorageIndex(itq.row()); - if (mark(iQ) != col) - { - Qidx(nzcolQ++) = iQ; // Add this row to the pattern of Q, - mark(iQ) = col; // and mark it as visited - } - } - } - } // End update current column - - Scalar tau = RealScalar(0); - RealScalar beta = 0; - - if(nonzeroCol < diagSize) - { - // Compute the Householder reflection that eliminate the current column - // FIXME this step should call the Householder module. - Scalar c0 = nzcolQ ? tval(Qidx(0)) : Scalar(0); - - // First, the squared norm of Q((col+1):m, col) - RealScalar sqrNorm = 0.; - for (Index itq = 1; itq < nzcolQ; ++itq) sqrNorm += numext::abs2(tval(Qidx(itq))); - if(sqrNorm == RealScalar(0) && numext::imag(c0) == RealScalar(0)) - { - beta = numext::real(c0); - tval(Qidx(0)) = 1; - } - else - { - using std::sqrt; - beta = sqrt(numext::abs2(c0) + sqrNorm); - if(numext::real(c0) >= RealScalar(0)) - beta = -beta; - tval(Qidx(0)) = 1; - for (Index itq = 1; itq < nzcolQ; ++itq) - tval(Qidx(itq)) /= (c0 - beta); - tau = numext::conj((beta-c0) / beta); - - } - } - - // Insert values in R - for (Index i = nzcolR-1; i >= 0; i--) - { - Index curIdx = Ridx(i); - if(curIdx < nonzeroCol) - { - m_R.insertBackByOuterInnerUnordered(col, curIdx) = tval(curIdx); - tval(curIdx) = Scalar(0.); - } - } - - if(nonzeroCol < diagSize && abs(beta) >= pivotThreshold) - { - m_R.insertBackByOuterInner(col, nonzeroCol) = beta; - // The householder coefficient - m_hcoeffs(nonzeroCol) = tau; - // Record the householder reflections - for (Index itq = 0; itq < nzcolQ; ++itq) - { - Index iQ = Qidx(itq); - m_Q.insertBackByOuterInnerUnordered(nonzeroCol,iQ) = tval(iQ); - tval(iQ) = Scalar(0.); - } - nonzeroCol++; - if(nonzeroCol<diagSize) - m_Q.startVec(nonzeroCol); - } - else - { - // Zero pivot found: move implicitly this column to the end - for (Index j = nonzeroCol; j < n-1; j++) - std::swap(m_pivotperm.indices()(j), m_pivotperm.indices()[j+1]); - - // Recompute the column elimination tree - internal::coletree(m_pmat, m_etree, m_firstRowElt, m_pivotperm.indices().data()); - m_isEtreeOk = false; - } - } - - m_hcoeffs.tail(diagSize-nonzeroCol).setZero(); - - // Finalize the column pointers of the sparse matrices R and Q - m_Q.finalize(); - m_Q.makeCompressed(); - m_R.finalize(); - m_R.makeCompressed(); - m_isQSorted = false; - - m_nonzeropivots = nonzeroCol; - - if(nonzeroCol<n) - { - // Permute the triangular factor to put the 'dead' columns to the end - QRMatrixType tempR(m_R); - m_R = tempR * m_pivotperm; - - // Update the column permutation - m_outputPerm_c = m_outputPerm_c * m_pivotperm; - } - - m_isInitialized = true; - m_factorizationIsok = true; - m_info = Success; -} - -template <typename SparseQRType, typename Derived> -struct SparseQR_QProduct : ReturnByValue<SparseQR_QProduct<SparseQRType, Derived> > -{ - typedef typename SparseQRType::QRMatrixType MatrixType; - typedef typename SparseQRType::Scalar Scalar; - // Get the references - SparseQR_QProduct(const SparseQRType& qr, const Derived& other, bool transpose) : - m_qr(qr),m_other(other),m_transpose(transpose) {} - inline Index rows() const { return m_qr.matrixQ().rows(); } - inline Index cols() const { return m_other.cols(); } - - // Assign to a vector - template<typename DesType> - void evalTo(DesType& res) const - { - Index m = m_qr.rows(); - Index n = m_qr.cols(); - Index diagSize = (std::min)(m,n); - res = m_other; - if (m_transpose) - { - eigen_assert(m_qr.m_Q.rows() == m_other.rows() && "Non conforming object sizes"); - //Compute res = Q' * other column by column - for(Index j = 0; j < res.cols(); j++){ - for (Index k = 0; k < diagSize; k++) - { - Scalar tau = Scalar(0); - tau = m_qr.m_Q.col(k).dot(res.col(j)); - if(tau==Scalar(0)) continue; - tau = tau * m_qr.m_hcoeffs(k); - res.col(j) -= tau * m_qr.m_Q.col(k); - } - } - } - else - { - eigen_assert(m_qr.matrixQ().cols() == m_other.rows() && "Non conforming object sizes"); - - res.conservativeResize(rows(), cols()); - - // Compute res = Q * other column by column - for(Index j = 0; j < res.cols(); j++) - { - Index start_k = internal::is_identity<Derived>::value ? numext::mini(j,diagSize-1) : diagSize-1; - for (Index k = start_k; k >=0; k--) - { - Scalar tau = Scalar(0); - tau = m_qr.m_Q.col(k).dot(res.col(j)); - if(tau==Scalar(0)) continue; - tau = tau * numext::conj(m_qr.m_hcoeffs(k)); - res.col(j) -= tau * m_qr.m_Q.col(k); - } - } - } - } - - const SparseQRType& m_qr; - const Derived& m_other; - bool m_transpose; // TODO this actually means adjoint -}; - -template<typename SparseQRType> -struct SparseQRMatrixQReturnType : public EigenBase<SparseQRMatrixQReturnType<SparseQRType> > -{ - typedef typename SparseQRType::Scalar Scalar; - typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix; - enum { - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = Dynamic - }; - explicit SparseQRMatrixQReturnType(const SparseQRType& qr) : m_qr(qr) {} - template<typename Derived> - SparseQR_QProduct<SparseQRType, Derived> operator*(const MatrixBase<Derived>& other) - { - return SparseQR_QProduct<SparseQRType,Derived>(m_qr,other.derived(),false); - } - // To use for operations with the adjoint of Q - SparseQRMatrixQTransposeReturnType<SparseQRType> adjoint() const - { - return SparseQRMatrixQTransposeReturnType<SparseQRType>(m_qr); - } - inline Index rows() const { return m_qr.rows(); } - inline Index cols() const { return m_qr.rows(); } - // To use for operations with the transpose of Q FIXME this is the same as adjoint at the moment - SparseQRMatrixQTransposeReturnType<SparseQRType> transpose() const - { - return SparseQRMatrixQTransposeReturnType<SparseQRType>(m_qr); - } - const SparseQRType& m_qr; -}; - -// TODO this actually represents the adjoint of Q -template<typename SparseQRType> -struct SparseQRMatrixQTransposeReturnType -{ - explicit SparseQRMatrixQTransposeReturnType(const SparseQRType& qr) : m_qr(qr) {} - template<typename Derived> - SparseQR_QProduct<SparseQRType,Derived> operator*(const MatrixBase<Derived>& other) - { - return SparseQR_QProduct<SparseQRType,Derived>(m_qr,other.derived(), true); - } - const SparseQRType& m_qr; -}; - -namespace internal { - -template<typename SparseQRType> -struct evaluator_traits<SparseQRMatrixQReturnType<SparseQRType> > -{ - typedef typename SparseQRType::MatrixType MatrixType; - typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind; - typedef SparseShape Shape; -}; - -template< typename DstXprType, typename SparseQRType> -struct Assignment<DstXprType, SparseQRMatrixQReturnType<SparseQRType>, internal::assign_op<typename DstXprType::Scalar,typename DstXprType::Scalar>, Sparse2Sparse> -{ - typedef SparseQRMatrixQReturnType<SparseQRType> SrcXprType; - typedef typename DstXprType::Scalar Scalar; - typedef typename DstXprType::StorageIndex StorageIndex; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &/*func*/) - { - typename DstXprType::PlainObject idMat(src.rows(), src.cols()); - idMat.setIdentity(); - // Sort the sparse householder reflectors if needed - const_cast<SparseQRType *>(&src.m_qr)->_sort_matrix_Q(); - dst = SparseQR_QProduct<SparseQRType, DstXprType>(src.m_qr, idMat, false); - } -}; - -template< typename DstXprType, typename SparseQRType> -struct Assignment<DstXprType, SparseQRMatrixQReturnType<SparseQRType>, internal::assign_op<typename DstXprType::Scalar,typename DstXprType::Scalar>, Sparse2Dense> -{ - typedef SparseQRMatrixQReturnType<SparseQRType> SrcXprType; - typedef typename DstXprType::Scalar Scalar; - typedef typename DstXprType::StorageIndex StorageIndex; - static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &/*func*/) - { - dst = src.m_qr.matrixQ() * DstXprType::Identity(src.m_qr.rows(), src.m_qr.rows()); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/StlSupport/StdDeque.h b/external/eigen/include/eigen3/Eigen/src/StlSupport/StdDeque.h deleted file mode 100644 index 045da7b4..00000000 --- a/external/eigen/include/eigen3/Eigen/src/StlSupport/StdDeque.h +++ /dev/null @@ -1,126 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STDDEQUE_H -#define EIGEN_STDDEQUE_H - -#include "details.h" - -/** - * This section contains a convenience MACRO which allows an easy specialization of - * std::deque such that for data types with alignment issues the correct allocator - * is used automatically. - */ -#define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) \ -namespace std \ -{ \ - template<> \ - class deque<__VA_ARGS__, std::allocator<__VA_ARGS__> > \ - : public deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \ - { \ - typedef deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > deque_base; \ - public: \ - typedef __VA_ARGS__ value_type; \ - typedef deque_base::allocator_type allocator_type; \ - typedef deque_base::size_type size_type; \ - typedef deque_base::iterator iterator; \ - explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {} \ - template<typename InputIterator> \ - deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : deque_base(first, last, a) {} \ - deque(const deque& c) : deque_base(c) {} \ - explicit deque(size_type num, const value_type& val = value_type()) : deque_base(num, val) {} \ - deque(iterator start_, iterator end_) : deque_base(start_, end_) {} \ - deque& operator=(const deque& x) { \ - deque_base::operator=(x); \ - return *this; \ - } \ - }; \ -} - -// check whether we really need the std::deque specialization -#if !EIGEN_HAS_CXX11_CONTAINERS && !(defined(_GLIBCXX_DEQUE) && (!EIGEN_GNUC_AT_LEAST(4,1))) /* Note that before gcc-4.1 we already have: std::deque::resize(size_type,const T&). */ - -namespace std { - -#define EIGEN_STD_DEQUE_SPECIALIZATION_BODY \ - public: \ - typedef T value_type; \ - typedef typename deque_base::allocator_type allocator_type; \ - typedef typename deque_base::size_type size_type; \ - typedef typename deque_base::iterator iterator; \ - typedef typename deque_base::const_iterator const_iterator; \ - explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {} \ - template<typename InputIterator> \ - deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \ - : deque_base(first, last, a) {} \ - deque(const deque& c) : deque_base(c) {} \ - explicit deque(size_type num, const value_type& val = value_type()) : deque_base(num, val) {} \ - deque(iterator start_, iterator end_) : deque_base(start_, end_) {} \ - deque& operator=(const deque& x) { \ - deque_base::operator=(x); \ - return *this; \ - } - - template<typename T> - class deque<T,EIGEN_ALIGNED_ALLOCATOR<T> > - : public deque<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T), - Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > -{ - typedef deque<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T), - Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > deque_base; - EIGEN_STD_DEQUE_SPECIALIZATION_BODY - - void resize(size_type new_size) - { resize(new_size, T()); } - -#if defined(_DEQUE_) - // workaround MSVC std::deque implementation - void resize(size_type new_size, const value_type& x) - { - if (deque_base::size() < new_size) - deque_base::_Insert_n(deque_base::end(), new_size - deque_base::size(), x); - else if (new_size < deque_base::size()) - deque_base::erase(deque_base::begin() + new_size, deque_base::end()); - } - void push_back(const value_type& x) - { deque_base::push_back(x); } - void push_front(const value_type& x) - { deque_base::push_front(x); } - using deque_base::insert; - iterator insert(const_iterator position, const value_type& x) - { return deque_base::insert(position,x); } - void insert(const_iterator position, size_type new_size, const value_type& x) - { deque_base::insert(position, new_size, x); } -#elif defined(_GLIBCXX_DEQUE) && EIGEN_GNUC_AT_LEAST(4,2) - // workaround GCC std::deque implementation - void resize(size_type new_size, const value_type& x) - { - if (new_size < deque_base::size()) - deque_base::_M_erase_at_end(this->_M_impl._M_start + new_size); - else - deque_base::insert(deque_base::end(), new_size - deque_base::size(), x); - } -#else - // either GCC 4.1 or non-GCC - // default implementation which should always work. - void resize(size_type new_size, const value_type& x) - { - if (new_size < deque_base::size()) - deque_base::erase(deque_base::begin() + new_size, deque_base::end()); - else if (new_size > deque_base::size()) - deque_base::insert(deque_base::end(), new_size - deque_base::size(), x); - } -#endif - }; -} - -#endif // check whether specialization is actually required - -#endif // EIGEN_STDDEQUE_H diff --git a/external/eigen/include/eigen3/Eigen/src/StlSupport/StdList.h b/external/eigen/include/eigen3/Eigen/src/StlSupport/StdList.h deleted file mode 100644 index 8ba3fada..00000000 --- a/external/eigen/include/eigen3/Eigen/src/StlSupport/StdList.h +++ /dev/null @@ -1,106 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STDLIST_H -#define EIGEN_STDLIST_H - -#include "details.h" - -/** - * This section contains a convenience MACRO which allows an easy specialization of - * std::list such that for data types with alignment issues the correct allocator - * is used automatically. - */ -#define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) \ -namespace std \ -{ \ - template<> \ - class list<__VA_ARGS__, std::allocator<__VA_ARGS__> > \ - : public list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \ - { \ - typedef list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > list_base; \ - public: \ - typedef __VA_ARGS__ value_type; \ - typedef list_base::allocator_type allocator_type; \ - typedef list_base::size_type size_type; \ - typedef list_base::iterator iterator; \ - explicit list(const allocator_type& a = allocator_type()) : list_base(a) {} \ - template<typename InputIterator> \ - list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : list_base(first, last, a) {} \ - list(const list& c) : list_base(c) {} \ - explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \ - list(iterator start_, iterator end_) : list_base(start_, end_) {} \ - list& operator=(const list& x) { \ - list_base::operator=(x); \ - return *this; \ - } \ - }; \ -} - -// check whether we really need the std::list specialization -#if !EIGEN_HAS_CXX11_CONTAINERS && !(defined(_GLIBCXX_LIST) && (!EIGEN_GNUC_AT_LEAST(4,1))) /* Note that before gcc-4.1 we already have: std::list::resize(size_type,const T&). */ - -namespace std -{ - -#define EIGEN_STD_LIST_SPECIALIZATION_BODY \ - public: \ - typedef T value_type; \ - typedef typename list_base::allocator_type allocator_type; \ - typedef typename list_base::size_type size_type; \ - typedef typename list_base::iterator iterator; \ - typedef typename list_base::const_iterator const_iterator; \ - explicit list(const allocator_type& a = allocator_type()) : list_base(a) {} \ - template<typename InputIterator> \ - list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \ - : list_base(first, last, a) {} \ - list(const list& c) : list_base(c) {} \ - explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \ - list(iterator start_, iterator end_) : list_base(start_, end_) {} \ - list& operator=(const list& x) { \ - list_base::operator=(x); \ - return *this; \ - } - - template<typename T> - class list<T,EIGEN_ALIGNED_ALLOCATOR<T> > - : public list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T), - Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > - { - typedef list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T), - Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > list_base; - EIGEN_STD_LIST_SPECIALIZATION_BODY - - void resize(size_type new_size) - { resize(new_size, T()); } - - void resize(size_type new_size, const value_type& x) - { - if (list_base::size() < new_size) - list_base::insert(list_base::end(), new_size - list_base::size(), x); - else - while (new_size < list_base::size()) list_base::pop_back(); - } - -#if defined(_LIST_) - // workaround MSVC std::list implementation - void push_back(const value_type& x) - { list_base::push_back(x); } - using list_base::insert; - iterator insert(const_iterator position, const value_type& x) - { return list_base::insert(position,x); } - void insert(const_iterator position, size_type new_size, const value_type& x) - { list_base::insert(position, new_size, x); } -#endif - }; -} - -#endif // check whether specialization is actually required - -#endif // EIGEN_STDLIST_H diff --git a/external/eigen/include/eigen3/Eigen/src/StlSupport/StdVector.h b/external/eigen/include/eigen3/Eigen/src/StlSupport/StdVector.h deleted file mode 100644 index 9fcf19bc..00000000 --- a/external/eigen/include/eigen3/Eigen/src/StlSupport/StdVector.h +++ /dev/null @@ -1,131 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STDVECTOR_H -#define EIGEN_STDVECTOR_H - -#include "details.h" - -/** - * This section contains a convenience MACRO which allows an easy specialization of - * std::vector such that for data types with alignment issues the correct allocator - * is used automatically. - */ -#define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...) \ -namespace std \ -{ \ - template<> \ - class vector<__VA_ARGS__, std::allocator<__VA_ARGS__> > \ - : public vector<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \ - { \ - typedef vector<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > vector_base; \ - public: \ - typedef __VA_ARGS__ value_type; \ - typedef vector_base::allocator_type allocator_type; \ - typedef vector_base::size_type size_type; \ - typedef vector_base::iterator iterator; \ - explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {} \ - template<typename InputIterator> \ - vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : vector_base(first, last, a) {} \ - vector(const vector& c) : vector_base(c) {} \ - explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {} \ - vector(iterator start_, iterator end_) : vector_base(start_, end_) {} \ - vector& operator=(const vector& x) { \ - vector_base::operator=(x); \ - return *this; \ - } \ - }; \ -} - -// Don't specialize if containers are implemented according to C++11 -#if !EIGEN_HAS_CXX11_CONTAINERS - -namespace std { - -#define EIGEN_STD_VECTOR_SPECIALIZATION_BODY \ - public: \ - typedef T value_type; \ - typedef typename vector_base::allocator_type allocator_type; \ - typedef typename vector_base::size_type size_type; \ - typedef typename vector_base::iterator iterator; \ - typedef typename vector_base::const_iterator const_iterator; \ - explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {} \ - template<typename InputIterator> \ - vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \ - : vector_base(first, last, a) {} \ - vector(const vector& c) : vector_base(c) {} \ - explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {} \ - vector(iterator start_, iterator end_) : vector_base(start_, end_) {} \ - vector& operator=(const vector& x) { \ - vector_base::operator=(x); \ - return *this; \ - } - - template<typename T> - class vector<T,EIGEN_ALIGNED_ALLOCATOR<T> > - : public vector<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T), - Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > -{ - typedef vector<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T), - Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > vector_base; - EIGEN_STD_VECTOR_SPECIALIZATION_BODY - - void resize(size_type new_size) - { resize(new_size, T()); } - -#if defined(_VECTOR_) - // workaround MSVC std::vector implementation - void resize(size_type new_size, const value_type& x) - { - if (vector_base::size() < new_size) - vector_base::_Insert_n(vector_base::end(), new_size - vector_base::size(), x); - else if (new_size < vector_base::size()) - vector_base::erase(vector_base::begin() + new_size, vector_base::end()); - } - void push_back(const value_type& x) - { vector_base::push_back(x); } - using vector_base::insert; - iterator insert(const_iterator position, const value_type& x) - { return vector_base::insert(position,x); } - void insert(const_iterator position, size_type new_size, const value_type& x) - { vector_base::insert(position, new_size, x); } -#elif defined(_GLIBCXX_VECTOR) && (!(EIGEN_GNUC_AT_LEAST(4,1))) - /* Note that before gcc-4.1 we already have: std::vector::resize(size_type,const T&). - * However, this specialization is still needed to make the above EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION trick to work. */ - void resize(size_type new_size, const value_type& x) - { - vector_base::resize(new_size,x); - } -#elif defined(_GLIBCXX_VECTOR) && EIGEN_GNUC_AT_LEAST(4,2) - // workaround GCC std::vector implementation - void resize(size_type new_size, const value_type& x) - { - if (new_size < vector_base::size()) - vector_base::_M_erase_at_end(this->_M_impl._M_start + new_size); - else - vector_base::insert(vector_base::end(), new_size - vector_base::size(), x); - } -#else - // either GCC 4.1 or non-GCC - // default implementation which should always work. - void resize(size_type new_size, const value_type& x) - { - if (new_size < vector_base::size()) - vector_base::erase(vector_base::begin() + new_size, vector_base::end()); - else if (new_size > vector_base::size()) - vector_base::insert(vector_base::end(), new_size - vector_base::size(), x); - } -#endif - }; -} -#endif // !EIGEN_HAS_CXX11_CONTAINERS - - -#endif // EIGEN_STDVECTOR_H diff --git a/external/eigen/include/eigen3/Eigen/src/StlSupport/details.h b/external/eigen/include/eigen3/Eigen/src/StlSupport/details.h deleted file mode 100644 index 2cfd13e0..00000000 --- a/external/eigen/include/eigen3/Eigen/src/StlSupport/details.h +++ /dev/null @@ -1,84 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STL_DETAILS_H -#define EIGEN_STL_DETAILS_H - -#ifndef EIGEN_ALIGNED_ALLOCATOR - #define EIGEN_ALIGNED_ALLOCATOR Eigen::aligned_allocator -#endif - -namespace Eigen { - - // This one is needed to prevent reimplementing the whole std::vector. - template <class T> - class aligned_allocator_indirection : public EIGEN_ALIGNED_ALLOCATOR<T> - { - public: - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef T* pointer; - typedef const T* const_pointer; - typedef T& reference; - typedef const T& const_reference; - typedef T value_type; - - template<class U> - struct rebind - { - typedef aligned_allocator_indirection<U> other; - }; - - aligned_allocator_indirection() {} - aligned_allocator_indirection(const aligned_allocator_indirection& ) : EIGEN_ALIGNED_ALLOCATOR<T>() {} - aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<T>& ) {} - template<class U> - aligned_allocator_indirection(const aligned_allocator_indirection<U>& ) {} - template<class U> - aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<U>& ) {} - ~aligned_allocator_indirection() {} - }; - -#if EIGEN_COMP_MSVC - - // sometimes, MSVC detects, at compile time, that the argument x - // in std::vector::resize(size_t s,T x) won't be aligned and generate an error - // even if this function is never called. Whence this little wrapper. -#define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) \ - typename Eigen::internal::conditional< \ - Eigen::internal::is_arithmetic<T>::value, \ - T, \ - Eigen::internal::workaround_msvc_stl_support<T> \ - >::type - - namespace internal { - template<typename T> struct workaround_msvc_stl_support : public T - { - inline workaround_msvc_stl_support() : T() {} - inline workaround_msvc_stl_support(const T& other) : T(other) {} - inline operator T& () { return *static_cast<T*>(this); } - inline operator const T& () const { return *static_cast<const T*>(this); } - template<typename OtherT> - inline T& operator=(const OtherT& other) - { T::operator=(other); return *this; } - inline workaround_msvc_stl_support& operator=(const workaround_msvc_stl_support& other) - { T::operator=(other); return *this; } - }; - } - -#else - -#define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) T - -#endif - -} - -#endif // EIGEN_STL_DETAILS_H diff --git a/external/eigen/include/eigen3/Eigen/src/SuperLUSupport/SuperLUSupport.h b/external/eigen/include/eigen3/Eigen/src/SuperLUSupport/SuperLUSupport.h deleted file mode 100644 index 354e33de..00000000 --- a/external/eigen/include/eigen3/Eigen/src/SuperLUSupport/SuperLUSupport.h +++ /dev/null @@ -1,1027 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SUPERLUSUPPORT_H -#define EIGEN_SUPERLUSUPPORT_H - -namespace Eigen { - -#if defined(SUPERLU_MAJOR_VERSION) && (SUPERLU_MAJOR_VERSION >= 5) -#define DECL_GSSVX(PREFIX,FLOATTYPE,KEYTYPE) \ - extern "C" { \ - extern void PREFIX##gssvx(superlu_options_t *, SuperMatrix *, int *, int *, int *, \ - char *, FLOATTYPE *, FLOATTYPE *, SuperMatrix *, SuperMatrix *, \ - void *, int, SuperMatrix *, SuperMatrix *, \ - FLOATTYPE *, FLOATTYPE *, FLOATTYPE *, FLOATTYPE *, \ - GlobalLU_t *, mem_usage_t *, SuperLUStat_t *, int *); \ - } \ - inline float SuperLU_gssvx(superlu_options_t *options, SuperMatrix *A, \ - int *perm_c, int *perm_r, int *etree, char *equed, \ - FLOATTYPE *R, FLOATTYPE *C, SuperMatrix *L, \ - SuperMatrix *U, void *work, int lwork, \ - SuperMatrix *B, SuperMatrix *X, \ - FLOATTYPE *recip_pivot_growth, \ - FLOATTYPE *rcond, FLOATTYPE *ferr, FLOATTYPE *berr, \ - SuperLUStat_t *stats, int *info, KEYTYPE) { \ - mem_usage_t mem_usage; \ - GlobalLU_t gLU; \ - PREFIX##gssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, \ - U, work, lwork, B, X, recip_pivot_growth, rcond, \ - ferr, berr, &gLU, &mem_usage, stats, info); \ - return mem_usage.for_lu; /* bytes used by the factor storage */ \ - } -#else // version < 5.0 -#define DECL_GSSVX(PREFIX,FLOATTYPE,KEYTYPE) \ - extern "C" { \ - extern void PREFIX##gssvx(superlu_options_t *, SuperMatrix *, int *, int *, int *, \ - char *, FLOATTYPE *, FLOATTYPE *, SuperMatrix *, SuperMatrix *, \ - void *, int, SuperMatrix *, SuperMatrix *, \ - FLOATTYPE *, FLOATTYPE *, FLOATTYPE *, FLOATTYPE *, \ - mem_usage_t *, SuperLUStat_t *, int *); \ - } \ - inline float SuperLU_gssvx(superlu_options_t *options, SuperMatrix *A, \ - int *perm_c, int *perm_r, int *etree, char *equed, \ - FLOATTYPE *R, FLOATTYPE *C, SuperMatrix *L, \ - SuperMatrix *U, void *work, int lwork, \ - SuperMatrix *B, SuperMatrix *X, \ - FLOATTYPE *recip_pivot_growth, \ - FLOATTYPE *rcond, FLOATTYPE *ferr, FLOATTYPE *berr, \ - SuperLUStat_t *stats, int *info, KEYTYPE) { \ - mem_usage_t mem_usage; \ - PREFIX##gssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, \ - U, work, lwork, B, X, recip_pivot_growth, rcond, \ - ferr, berr, &mem_usage, stats, info); \ - return mem_usage.for_lu; /* bytes used by the factor storage */ \ - } -#endif - -DECL_GSSVX(s,float,float) -DECL_GSSVX(c,float,std::complex<float>) -DECL_GSSVX(d,double,double) -DECL_GSSVX(z,double,std::complex<double>) - -#ifdef MILU_ALPHA -#define EIGEN_SUPERLU_HAS_ILU -#endif - -#ifdef EIGEN_SUPERLU_HAS_ILU - -// similarly for the incomplete factorization using gsisx -#define DECL_GSISX(PREFIX,FLOATTYPE,KEYTYPE) \ - extern "C" { \ - extern void PREFIX##gsisx(superlu_options_t *, SuperMatrix *, int *, int *, int *, \ - char *, FLOATTYPE *, FLOATTYPE *, SuperMatrix *, SuperMatrix *, \ - void *, int, SuperMatrix *, SuperMatrix *, FLOATTYPE *, FLOATTYPE *, \ - mem_usage_t *, SuperLUStat_t *, int *); \ - } \ - inline float SuperLU_gsisx(superlu_options_t *options, SuperMatrix *A, \ - int *perm_c, int *perm_r, int *etree, char *equed, \ - FLOATTYPE *R, FLOATTYPE *C, SuperMatrix *L, \ - SuperMatrix *U, void *work, int lwork, \ - SuperMatrix *B, SuperMatrix *X, \ - FLOATTYPE *recip_pivot_growth, \ - FLOATTYPE *rcond, \ - SuperLUStat_t *stats, int *info, KEYTYPE) { \ - mem_usage_t mem_usage; \ - PREFIX##gsisx(options, A, perm_c, perm_r, etree, equed, R, C, L, \ - U, work, lwork, B, X, recip_pivot_growth, rcond, \ - &mem_usage, stats, info); \ - return mem_usage.for_lu; /* bytes used by the factor storage */ \ - } - -DECL_GSISX(s,float,float) -DECL_GSISX(c,float,std::complex<float>) -DECL_GSISX(d,double,double) -DECL_GSISX(z,double,std::complex<double>) - -#endif - -template<typename MatrixType> -struct SluMatrixMapHelper; - -/** \internal - * - * A wrapper class for SuperLU matrices. It supports only compressed sparse matrices - * and dense matrices. Supernodal and other fancy format are not supported by this wrapper. - * - * This wrapper class mainly aims to avoids the need of dynamic allocation of the storage structure. - */ -struct SluMatrix : SuperMatrix -{ - SluMatrix() - { - Store = &storage; - } - - SluMatrix(const SluMatrix& other) - : SuperMatrix(other) - { - Store = &storage; - storage = other.storage; - } - - SluMatrix& operator=(const SluMatrix& other) - { - SuperMatrix::operator=(static_cast<const SuperMatrix&>(other)); - Store = &storage; - storage = other.storage; - return *this; - } - - struct - { - union {int nnz;int lda;}; - void *values; - int *innerInd; - int *outerInd; - } storage; - - void setStorageType(Stype_t t) - { - Stype = t; - if (t==SLU_NC || t==SLU_NR || t==SLU_DN) - Store = &storage; - else - { - eigen_assert(false && "storage type not supported"); - Store = 0; - } - } - - template<typename Scalar> - void setScalarType() - { - if (internal::is_same<Scalar,float>::value) - Dtype = SLU_S; - else if (internal::is_same<Scalar,double>::value) - Dtype = SLU_D; - else if (internal::is_same<Scalar,std::complex<float> >::value) - Dtype = SLU_C; - else if (internal::is_same<Scalar,std::complex<double> >::value) - Dtype = SLU_Z; - else - { - eigen_assert(false && "Scalar type not supported by SuperLU"); - } - } - - template<typename MatrixType> - static SluMatrix Map(MatrixBase<MatrixType>& _mat) - { - MatrixType& mat(_mat.derived()); - eigen_assert( ((MatrixType::Flags&RowMajorBit)!=RowMajorBit) && "row-major dense matrices are not supported by SuperLU"); - SluMatrix res; - res.setStorageType(SLU_DN); - res.setScalarType<typename MatrixType::Scalar>(); - res.Mtype = SLU_GE; - - res.nrow = internal::convert_index<int>(mat.rows()); - res.ncol = internal::convert_index<int>(mat.cols()); - - res.storage.lda = internal::convert_index<int>(MatrixType::IsVectorAtCompileTime ? mat.size() : mat.outerStride()); - res.storage.values = (void*)(mat.data()); - return res; - } - - template<typename MatrixType> - static SluMatrix Map(SparseMatrixBase<MatrixType>& a_mat) - { - MatrixType &mat(a_mat.derived()); - SluMatrix res; - if ((MatrixType::Flags&RowMajorBit)==RowMajorBit) - { - res.setStorageType(SLU_NR); - res.nrow = internal::convert_index<int>(mat.cols()); - res.ncol = internal::convert_index<int>(mat.rows()); - } - else - { - res.setStorageType(SLU_NC); - res.nrow = internal::convert_index<int>(mat.rows()); - res.ncol = internal::convert_index<int>(mat.cols()); - } - - res.Mtype = SLU_GE; - - res.storage.nnz = internal::convert_index<int>(mat.nonZeros()); - res.storage.values = mat.valuePtr(); - res.storage.innerInd = mat.innerIndexPtr(); - res.storage.outerInd = mat.outerIndexPtr(); - - res.setScalarType<typename MatrixType::Scalar>(); - - // FIXME the following is not very accurate - if (MatrixType::Flags & Upper) - res.Mtype = SLU_TRU; - if (MatrixType::Flags & Lower) - res.Mtype = SLU_TRL; - - eigen_assert(((MatrixType::Flags & SelfAdjoint)==0) && "SelfAdjoint matrix shape not supported by SuperLU"); - - return res; - } -}; - -template<typename Scalar, int Rows, int Cols, int Options, int MRows, int MCols> -struct SluMatrixMapHelper<Matrix<Scalar,Rows,Cols,Options,MRows,MCols> > -{ - typedef Matrix<Scalar,Rows,Cols,Options,MRows,MCols> MatrixType; - static void run(MatrixType& mat, SluMatrix& res) - { - eigen_assert( ((Options&RowMajor)!=RowMajor) && "row-major dense matrices is not supported by SuperLU"); - res.setStorageType(SLU_DN); - res.setScalarType<Scalar>(); - res.Mtype = SLU_GE; - - res.nrow = mat.rows(); - res.ncol = mat.cols(); - - res.storage.lda = mat.outerStride(); - res.storage.values = mat.data(); - } -}; - -template<typename Derived> -struct SluMatrixMapHelper<SparseMatrixBase<Derived> > -{ - typedef Derived MatrixType; - static void run(MatrixType& mat, SluMatrix& res) - { - if ((MatrixType::Flags&RowMajorBit)==RowMajorBit) - { - res.setStorageType(SLU_NR); - res.nrow = mat.cols(); - res.ncol = mat.rows(); - } - else - { - res.setStorageType(SLU_NC); - res.nrow = mat.rows(); - res.ncol = mat.cols(); - } - - res.Mtype = SLU_GE; - - res.storage.nnz = mat.nonZeros(); - res.storage.values = mat.valuePtr(); - res.storage.innerInd = mat.innerIndexPtr(); - res.storage.outerInd = mat.outerIndexPtr(); - - res.setScalarType<typename MatrixType::Scalar>(); - - // FIXME the following is not very accurate - if (MatrixType::Flags & Upper) - res.Mtype = SLU_TRU; - if (MatrixType::Flags & Lower) - res.Mtype = SLU_TRL; - - eigen_assert(((MatrixType::Flags & SelfAdjoint)==0) && "SelfAdjoint matrix shape not supported by SuperLU"); - } -}; - -namespace internal { - -template<typename MatrixType> -SluMatrix asSluMatrix(MatrixType& mat) -{ - return SluMatrix::Map(mat); -} - -/** View a Super LU matrix as an Eigen expression */ -template<typename Scalar, int Flags, typename Index> -MappedSparseMatrix<Scalar,Flags,Index> map_superlu(SluMatrix& sluMat) -{ - eigen_assert(((Flags&RowMajor)==RowMajor && sluMat.Stype == SLU_NR) - || ((Flags&ColMajor)==ColMajor && sluMat.Stype == SLU_NC)); - - Index outerSize = (Flags&RowMajor)==RowMajor ? sluMat.ncol : sluMat.nrow; - - return MappedSparseMatrix<Scalar,Flags,Index>( - sluMat.nrow, sluMat.ncol, sluMat.storage.outerInd[outerSize], - sluMat.storage.outerInd, sluMat.storage.innerInd, reinterpret_cast<Scalar*>(sluMat.storage.values) ); -} - -} // end namespace internal - -/** \ingroup SuperLUSupport_Module - * \class SuperLUBase - * \brief The base class for the direct and incomplete LU factorization of SuperLU - */ -template<typename _MatrixType, typename Derived> -class SuperLUBase : public SparseSolverBase<Derived> -{ - protected: - typedef SparseSolverBase<Derived> Base; - using Base::derived; - using Base::m_isInitialized; - public: - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef Matrix<Scalar,Dynamic,1> Vector; - typedef Matrix<int, 1, MatrixType::ColsAtCompileTime> IntRowVectorType; - typedef Matrix<int, MatrixType::RowsAtCompileTime, 1> IntColVectorType; - typedef Map<PermutationMatrix<Dynamic,Dynamic,int> > PermutationMap; - typedef SparseMatrix<Scalar> LUMatrixType; - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - public: - - SuperLUBase() {} - - ~SuperLUBase() - { - clearFactors(); - } - - inline Index rows() const { return m_matrix.rows(); } - inline Index cols() const { return m_matrix.cols(); } - - /** \returns a reference to the Super LU option object to configure the Super LU algorithms. */ - inline superlu_options_t& options() { return m_sluOptions; } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix.appears to be negative. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - - /** Computes the sparse Cholesky decomposition of \a matrix */ - void compute(const MatrixType& matrix) - { - derived().analyzePattern(matrix); - derived().factorize(matrix); - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize() - */ - void analyzePattern(const MatrixType& /*matrix*/) - { - m_isInitialized = true; - m_info = Success; - m_analysisIsOk = true; - m_factorizationIsOk = false; - } - - template<typename Stream> - void dumpMemory(Stream& /*s*/) - {} - - protected: - - void initFactorization(const MatrixType& a) - { - set_default_options(&this->m_sluOptions); - - const Index size = a.rows(); - m_matrix = a; - - m_sluA = internal::asSluMatrix(m_matrix); - clearFactors(); - - m_p.resize(size); - m_q.resize(size); - m_sluRscale.resize(size); - m_sluCscale.resize(size); - m_sluEtree.resize(size); - - // set empty B and X - m_sluB.setStorageType(SLU_DN); - m_sluB.setScalarType<Scalar>(); - m_sluB.Mtype = SLU_GE; - m_sluB.storage.values = 0; - m_sluB.nrow = 0; - m_sluB.ncol = 0; - m_sluB.storage.lda = internal::convert_index<int>(size); - m_sluX = m_sluB; - - m_extractedDataAreDirty = true; - } - - void init() - { - m_info = InvalidInput; - m_isInitialized = false; - m_sluL.Store = 0; - m_sluU.Store = 0; - } - - void extractData() const; - - void clearFactors() - { - if(m_sluL.Store) - Destroy_SuperNode_Matrix(&m_sluL); - if(m_sluU.Store) - Destroy_CompCol_Matrix(&m_sluU); - - m_sluL.Store = 0; - m_sluU.Store = 0; - - memset(&m_sluL,0,sizeof m_sluL); - memset(&m_sluU,0,sizeof m_sluU); - } - - // cached data to reduce reallocation, etc. - mutable LUMatrixType m_l; - mutable LUMatrixType m_u; - mutable IntColVectorType m_p; - mutable IntRowVectorType m_q; - - mutable LUMatrixType m_matrix; // copy of the factorized matrix - mutable SluMatrix m_sluA; - mutable SuperMatrix m_sluL, m_sluU; - mutable SluMatrix m_sluB, m_sluX; - mutable SuperLUStat_t m_sluStat; - mutable superlu_options_t m_sluOptions; - mutable std::vector<int> m_sluEtree; - mutable Matrix<RealScalar,Dynamic,1> m_sluRscale, m_sluCscale; - mutable Matrix<RealScalar,Dynamic,1> m_sluFerr, m_sluBerr; - mutable char m_sluEqued; - - mutable ComputationInfo m_info; - int m_factorizationIsOk; - int m_analysisIsOk; - mutable bool m_extractedDataAreDirty; - - private: - SuperLUBase(SuperLUBase& ) { } -}; - - -/** \ingroup SuperLUSupport_Module - * \class SuperLU - * \brief A sparse direct LU factorization and solver based on the SuperLU library - * - * This class allows to solve for A.X = B sparse linear problems via a direct LU factorization - * using the SuperLU library. The sparse matrix A must be squared and invertible. The vectors or matrices - * X and B can be either dense or sparse. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * - * \warning This class is only for the 4.x versions of SuperLU. The 3.x and 5.x versions are not supported. - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class SparseLU - */ -template<typename _MatrixType> -class SuperLU : public SuperLUBase<_MatrixType,SuperLU<_MatrixType> > -{ - public: - typedef SuperLUBase<_MatrixType,SuperLU> Base; - typedef _MatrixType MatrixType; - typedef typename Base::Scalar Scalar; - typedef typename Base::RealScalar RealScalar; - typedef typename Base::StorageIndex StorageIndex; - typedef typename Base::IntRowVectorType IntRowVectorType; - typedef typename Base::IntColVectorType IntColVectorType; - typedef typename Base::PermutationMap PermutationMap; - typedef typename Base::LUMatrixType LUMatrixType; - typedef TriangularView<LUMatrixType, Lower|UnitDiag> LMatrixType; - typedef TriangularView<LUMatrixType, Upper> UMatrixType; - - public: - using Base::_solve_impl; - - SuperLU() : Base() { init(); } - - explicit SuperLU(const MatrixType& matrix) : Base() - { - init(); - Base::compute(matrix); - } - - ~SuperLU() - { - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize() - */ - void analyzePattern(const MatrixType& matrix) - { - m_info = InvalidInput; - m_isInitialized = false; - Base::analyzePattern(matrix); - } - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must has the same sparcity than the matrix on which the symbolic decomposition has been performed. - * - * \sa analyzePattern() - */ - void factorize(const MatrixType& matrix); - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &dest) const; - - inline const LMatrixType& matrixL() const - { - if (m_extractedDataAreDirty) this->extractData(); - return m_l; - } - - inline const UMatrixType& matrixU() const - { - if (m_extractedDataAreDirty) this->extractData(); - return m_u; - } - - inline const IntColVectorType& permutationP() const - { - if (m_extractedDataAreDirty) this->extractData(); - return m_p; - } - - inline const IntRowVectorType& permutationQ() const - { - if (m_extractedDataAreDirty) this->extractData(); - return m_q; - } - - Scalar determinant() const; - - protected: - - using Base::m_matrix; - using Base::m_sluOptions; - using Base::m_sluA; - using Base::m_sluB; - using Base::m_sluX; - using Base::m_p; - using Base::m_q; - using Base::m_sluEtree; - using Base::m_sluEqued; - using Base::m_sluRscale; - using Base::m_sluCscale; - using Base::m_sluL; - using Base::m_sluU; - using Base::m_sluStat; - using Base::m_sluFerr; - using Base::m_sluBerr; - using Base::m_l; - using Base::m_u; - - using Base::m_analysisIsOk; - using Base::m_factorizationIsOk; - using Base::m_extractedDataAreDirty; - using Base::m_isInitialized; - using Base::m_info; - - void init() - { - Base::init(); - - set_default_options(&this->m_sluOptions); - m_sluOptions.PrintStat = NO; - m_sluOptions.ConditionNumber = NO; - m_sluOptions.Trans = NOTRANS; - m_sluOptions.ColPerm = COLAMD; - } - - - private: - SuperLU(SuperLU& ) { } -}; - -template<typename MatrixType> -void SuperLU<MatrixType>::factorize(const MatrixType& a) -{ - eigen_assert(m_analysisIsOk && "You must first call analyzePattern()"); - if(!m_analysisIsOk) - { - m_info = InvalidInput; - return; - } - - this->initFactorization(a); - - m_sluOptions.ColPerm = COLAMD; - int info = 0; - RealScalar recip_pivot_growth, rcond; - RealScalar ferr, berr; - - StatInit(&m_sluStat); - SuperLU_gssvx(&m_sluOptions, &m_sluA, m_q.data(), m_p.data(), &m_sluEtree[0], - &m_sluEqued, &m_sluRscale[0], &m_sluCscale[0], - &m_sluL, &m_sluU, - NULL, 0, - &m_sluB, &m_sluX, - &recip_pivot_growth, &rcond, - &ferr, &berr, - &m_sluStat, &info, Scalar()); - StatFree(&m_sluStat); - - m_extractedDataAreDirty = true; - - // FIXME how to better check for errors ??? - m_info = info == 0 ? Success : NumericalIssue; - m_factorizationIsOk = true; -} - -template<typename MatrixType> -template<typename Rhs,typename Dest> -void SuperLU<MatrixType>::_solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest>& x) const -{ - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or analyzePattern()/factorize()"); - - const Index size = m_matrix.rows(); - const Index rhsCols = b.cols(); - eigen_assert(size==b.rows()); - - m_sluOptions.Trans = NOTRANS; - m_sluOptions.Fact = FACTORED; - m_sluOptions.IterRefine = NOREFINE; - - - m_sluFerr.resize(rhsCols); - m_sluBerr.resize(rhsCols); - - Ref<const Matrix<typename Rhs::Scalar,Dynamic,Dynamic,ColMajor> > b_ref(b); - Ref<const Matrix<typename Dest::Scalar,Dynamic,Dynamic,ColMajor> > x_ref(x); - - m_sluB = SluMatrix::Map(b_ref.const_cast_derived()); - m_sluX = SluMatrix::Map(x_ref.const_cast_derived()); - - typename Rhs::PlainObject b_cpy; - if(m_sluEqued!='N') - { - b_cpy = b; - m_sluB = SluMatrix::Map(b_cpy.const_cast_derived()); - } - - StatInit(&m_sluStat); - int info = 0; - RealScalar recip_pivot_growth, rcond; - SuperLU_gssvx(&m_sluOptions, &m_sluA, - m_q.data(), m_p.data(), - &m_sluEtree[0], &m_sluEqued, - &m_sluRscale[0], &m_sluCscale[0], - &m_sluL, &m_sluU, - NULL, 0, - &m_sluB, &m_sluX, - &recip_pivot_growth, &rcond, - &m_sluFerr[0], &m_sluBerr[0], - &m_sluStat, &info, Scalar()); - StatFree(&m_sluStat); - - if(x.derived().data() != x_ref.data()) - x = x_ref; - - m_info = info==0 ? Success : NumericalIssue; -} - -// the code of this extractData() function has been adapted from the SuperLU's Matlab support code, -// -// Copyright (c) 1994 by Xerox Corporation. All rights reserved. -// -// THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY -// EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. -// -template<typename MatrixType, typename Derived> -void SuperLUBase<MatrixType,Derived>::extractData() const -{ - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for extracting factors, you must first call either compute() or analyzePattern()/factorize()"); - if (m_extractedDataAreDirty) - { - int upper; - int fsupc, istart, nsupr; - int lastl = 0, lastu = 0; - SCformat *Lstore = static_cast<SCformat*>(m_sluL.Store); - NCformat *Ustore = static_cast<NCformat*>(m_sluU.Store); - Scalar *SNptr; - - const Index size = m_matrix.rows(); - m_l.resize(size,size); - m_l.resizeNonZeros(Lstore->nnz); - m_u.resize(size,size); - m_u.resizeNonZeros(Ustore->nnz); - - int* Lcol = m_l.outerIndexPtr(); - int* Lrow = m_l.innerIndexPtr(); - Scalar* Lval = m_l.valuePtr(); - - int* Ucol = m_u.outerIndexPtr(); - int* Urow = m_u.innerIndexPtr(); - Scalar* Uval = m_u.valuePtr(); - - Ucol[0] = 0; - Ucol[0] = 0; - - /* for each supernode */ - for (int k = 0; k <= Lstore->nsuper; ++k) - { - fsupc = L_FST_SUPC(k); - istart = L_SUB_START(fsupc); - nsupr = L_SUB_START(fsupc+1) - istart; - upper = 1; - - /* for each column in the supernode */ - for (int j = fsupc; j < L_FST_SUPC(k+1); ++j) - { - SNptr = &((Scalar*)Lstore->nzval)[L_NZ_START(j)]; - - /* Extract U */ - for (int i = U_NZ_START(j); i < U_NZ_START(j+1); ++i) - { - Uval[lastu] = ((Scalar*)Ustore->nzval)[i]; - /* Matlab doesn't like explicit zero. */ - if (Uval[lastu] != 0.0) - Urow[lastu++] = U_SUB(i); - } - for (int i = 0; i < upper; ++i) - { - /* upper triangle in the supernode */ - Uval[lastu] = SNptr[i]; - /* Matlab doesn't like explicit zero. */ - if (Uval[lastu] != 0.0) - Urow[lastu++] = L_SUB(istart+i); - } - Ucol[j+1] = lastu; - - /* Extract L */ - Lval[lastl] = 1.0; /* unit diagonal */ - Lrow[lastl++] = L_SUB(istart + upper - 1); - for (int i = upper; i < nsupr; ++i) - { - Lval[lastl] = SNptr[i]; - /* Matlab doesn't like explicit zero. */ - if (Lval[lastl] != 0.0) - Lrow[lastl++] = L_SUB(istart+i); - } - Lcol[j+1] = lastl; - - ++upper; - } /* for j ... */ - - } /* for k ... */ - - // squeeze the matrices : - m_l.resizeNonZeros(lastl); - m_u.resizeNonZeros(lastu); - - m_extractedDataAreDirty = false; - } -} - -template<typename MatrixType> -typename SuperLU<MatrixType>::Scalar SuperLU<MatrixType>::determinant() const -{ - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for computing the determinant, you must first call either compute() or analyzePattern()/factorize()"); - - if (m_extractedDataAreDirty) - this->extractData(); - - Scalar det = Scalar(1); - for (int j=0; j<m_u.cols(); ++j) - { - if (m_u.outerIndexPtr()[j+1]-m_u.outerIndexPtr()[j] > 0) - { - int lastId = m_u.outerIndexPtr()[j+1]-1; - eigen_assert(m_u.innerIndexPtr()[lastId]<=j); - if (m_u.innerIndexPtr()[lastId]==j) - det *= m_u.valuePtr()[lastId]; - } - } - if(PermutationMap(m_p.data(),m_p.size()).determinant()*PermutationMap(m_q.data(),m_q.size()).determinant()<0) - det = -det; - if(m_sluEqued!='N') - return det/m_sluRscale.prod()/m_sluCscale.prod(); - else - return det; -} - -#ifdef EIGEN_PARSED_BY_DOXYGEN -#define EIGEN_SUPERLU_HAS_ILU -#endif - -#ifdef EIGEN_SUPERLU_HAS_ILU - -/** \ingroup SuperLUSupport_Module - * \class SuperILU - * \brief A sparse direct \b incomplete LU factorization and solver based on the SuperLU library - * - * This class allows to solve for an approximate solution of A.X = B sparse linear problems via an incomplete LU factorization - * using the SuperLU library. This class is aimed to be used as a preconditioner of the iterative linear solvers. - * - * \warning This class is only for the 4.x versions of SuperLU. The 3.x and 5.x versions are not supported. - * - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class IncompleteLUT, class ConjugateGradient, class BiCGSTAB - */ - -template<typename _MatrixType> -class SuperILU : public SuperLUBase<_MatrixType,SuperILU<_MatrixType> > -{ - public: - typedef SuperLUBase<_MatrixType,SuperILU> Base; - typedef _MatrixType MatrixType; - typedef typename Base::Scalar Scalar; - typedef typename Base::RealScalar RealScalar; - - public: - using Base::_solve_impl; - - SuperILU() : Base() { init(); } - - SuperILU(const MatrixType& matrix) : Base() - { - init(); - Base::compute(matrix); - } - - ~SuperILU() - { - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize() - */ - void analyzePattern(const MatrixType& matrix) - { - Base::analyzePattern(matrix); - } - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must has the same sparcity than the matrix on which the symbolic decomposition has been performed. - * - * \sa analyzePattern() - */ - void factorize(const MatrixType& matrix); - - #ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &dest) const; - #endif // EIGEN_PARSED_BY_DOXYGEN - - protected: - - using Base::m_matrix; - using Base::m_sluOptions; - using Base::m_sluA; - using Base::m_sluB; - using Base::m_sluX; - using Base::m_p; - using Base::m_q; - using Base::m_sluEtree; - using Base::m_sluEqued; - using Base::m_sluRscale; - using Base::m_sluCscale; - using Base::m_sluL; - using Base::m_sluU; - using Base::m_sluStat; - using Base::m_sluFerr; - using Base::m_sluBerr; - using Base::m_l; - using Base::m_u; - - using Base::m_analysisIsOk; - using Base::m_factorizationIsOk; - using Base::m_extractedDataAreDirty; - using Base::m_isInitialized; - using Base::m_info; - - void init() - { - Base::init(); - - ilu_set_default_options(&m_sluOptions); - m_sluOptions.PrintStat = NO; - m_sluOptions.ConditionNumber = NO; - m_sluOptions.Trans = NOTRANS; - m_sluOptions.ColPerm = MMD_AT_PLUS_A; - - // no attempt to preserve column sum - m_sluOptions.ILU_MILU = SILU; - // only basic ILU(k) support -- no direct control over memory consumption - // better to use ILU_DropRule = DROP_BASIC | DROP_AREA - // and set ILU_FillFactor to max memory growth - m_sluOptions.ILU_DropRule = DROP_BASIC; - m_sluOptions.ILU_DropTol = NumTraits<Scalar>::dummy_precision()*10; - } - - private: - SuperILU(SuperILU& ) { } -}; - -template<typename MatrixType> -void SuperILU<MatrixType>::factorize(const MatrixType& a) -{ - eigen_assert(m_analysisIsOk && "You must first call analyzePattern()"); - if(!m_analysisIsOk) - { - m_info = InvalidInput; - return; - } - - this->initFactorization(a); - - int info = 0; - RealScalar recip_pivot_growth, rcond; - - StatInit(&m_sluStat); - SuperLU_gsisx(&m_sluOptions, &m_sluA, m_q.data(), m_p.data(), &m_sluEtree[0], - &m_sluEqued, &m_sluRscale[0], &m_sluCscale[0], - &m_sluL, &m_sluU, - NULL, 0, - &m_sluB, &m_sluX, - &recip_pivot_growth, &rcond, - &m_sluStat, &info, Scalar()); - StatFree(&m_sluStat); - - // FIXME how to better check for errors ??? - m_info = info == 0 ? Success : NumericalIssue; - m_factorizationIsOk = true; -} - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename MatrixType> -template<typename Rhs,typename Dest> -void SuperILU<MatrixType>::_solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest>& x) const -{ - eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or analyzePattern()/factorize()"); - - const int size = m_matrix.rows(); - const int rhsCols = b.cols(); - eigen_assert(size==b.rows()); - - m_sluOptions.Trans = NOTRANS; - m_sluOptions.Fact = FACTORED; - m_sluOptions.IterRefine = NOREFINE; - - m_sluFerr.resize(rhsCols); - m_sluBerr.resize(rhsCols); - - Ref<const Matrix<typename Rhs::Scalar,Dynamic,Dynamic,ColMajor> > b_ref(b); - Ref<const Matrix<typename Dest::Scalar,Dynamic,Dynamic,ColMajor> > x_ref(x); - - m_sluB = SluMatrix::Map(b_ref.const_cast_derived()); - m_sluX = SluMatrix::Map(x_ref.const_cast_derived()); - - typename Rhs::PlainObject b_cpy; - if(m_sluEqued!='N') - { - b_cpy = b; - m_sluB = SluMatrix::Map(b_cpy.const_cast_derived()); - } - - int info = 0; - RealScalar recip_pivot_growth, rcond; - - StatInit(&m_sluStat); - SuperLU_gsisx(&m_sluOptions, &m_sluA, - m_q.data(), m_p.data(), - &m_sluEtree[0], &m_sluEqued, - &m_sluRscale[0], &m_sluCscale[0], - &m_sluL, &m_sluU, - NULL, 0, - &m_sluB, &m_sluX, - &recip_pivot_growth, &rcond, - &m_sluStat, &info, Scalar()); - StatFree(&m_sluStat); - - if(x.derived().data() != x_ref.data()) - x = x_ref; - - m_info = info==0 ? Success : NumericalIssue; -} -#endif - -#endif - -} // end namespace Eigen - -#endif // EIGEN_SUPERLUSUPPORT_H diff --git a/external/eigen/include/eigen3/Eigen/src/UmfPackSupport/UmfPackSupport.h b/external/eigen/include/eigen3/Eigen/src/UmfPackSupport/UmfPackSupport.h deleted file mode 100644 index e3a333f8..00000000 --- a/external/eigen/include/eigen3/Eigen/src/UmfPackSupport/UmfPackSupport.h +++ /dev/null @@ -1,642 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_UMFPACKSUPPORT_H -#define EIGEN_UMFPACKSUPPORT_H - -// for compatibility with super old version of umfpack, -// not sure this is really needed, but this is harmless. -#ifndef SuiteSparse_long -#ifdef UF_long -#define SuiteSparse_long UF_long -#else -#error neither SuiteSparse_long nor UF_long are defined -#endif -#endif - -namespace Eigen { - -/* TODO extract L, extract U, compute det, etc... */ - -// generic double/complex<double> wrapper functions: - - - // Defaults -inline void umfpack_defaults(double control[UMFPACK_CONTROL], double, int) -{ umfpack_di_defaults(control); } - -inline void umfpack_defaults(double control[UMFPACK_CONTROL], std::complex<double>, int) -{ umfpack_zi_defaults(control); } - -inline void umfpack_defaults(double control[UMFPACK_CONTROL], double, SuiteSparse_long) -{ umfpack_dl_defaults(control); } - -inline void umfpack_defaults(double control[UMFPACK_CONTROL], std::complex<double>, SuiteSparse_long) -{ umfpack_zl_defaults(control); } - -// Report info -inline void umfpack_report_info(double control[UMFPACK_CONTROL], double info[UMFPACK_INFO], double, int) -{ umfpack_di_report_info(control, info);} - -inline void umfpack_report_info(double control[UMFPACK_CONTROL], double info[UMFPACK_INFO], std::complex<double>, int) -{ umfpack_zi_report_info(control, info);} - -inline void umfpack_report_info(double control[UMFPACK_CONTROL], double info[UMFPACK_INFO], double, SuiteSparse_long) -{ umfpack_dl_report_info(control, info);} - -inline void umfpack_report_info(double control[UMFPACK_CONTROL], double info[UMFPACK_INFO], std::complex<double>, SuiteSparse_long) -{ umfpack_zl_report_info(control, info);} - -// Report status -inline void umfpack_report_status(double control[UMFPACK_CONTROL], int status, double, int) -{ umfpack_di_report_status(control, status);} - -inline void umfpack_report_status(double control[UMFPACK_CONTROL], int status, std::complex<double>, int) -{ umfpack_zi_report_status(control, status);} - -inline void umfpack_report_status(double control[UMFPACK_CONTROL], int status, double, SuiteSparse_long) -{ umfpack_dl_report_status(control, status);} - -inline void umfpack_report_status(double control[UMFPACK_CONTROL], int status, std::complex<double>, SuiteSparse_long) -{ umfpack_zl_report_status(control, status);} - -// report control -inline void umfpack_report_control(double control[UMFPACK_CONTROL], double, int) -{ umfpack_di_report_control(control);} - -inline void umfpack_report_control(double control[UMFPACK_CONTROL], std::complex<double>, int) -{ umfpack_zi_report_control(control);} - -inline void umfpack_report_control(double control[UMFPACK_CONTROL], double, SuiteSparse_long) -{ umfpack_dl_report_control(control);} - -inline void umfpack_report_control(double control[UMFPACK_CONTROL], std::complex<double>, SuiteSparse_long) -{ umfpack_zl_report_control(control);} - -// Free numeric -inline void umfpack_free_numeric(void **Numeric, double, int) -{ umfpack_di_free_numeric(Numeric); *Numeric = 0; } - -inline void umfpack_free_numeric(void **Numeric, std::complex<double>, int) -{ umfpack_zi_free_numeric(Numeric); *Numeric = 0; } - -inline void umfpack_free_numeric(void **Numeric, double, SuiteSparse_long) -{ umfpack_dl_free_numeric(Numeric); *Numeric = 0; } - -inline void umfpack_free_numeric(void **Numeric, std::complex<double>, SuiteSparse_long) -{ umfpack_zl_free_numeric(Numeric); *Numeric = 0; } - -// Free symbolic -inline void umfpack_free_symbolic(void **Symbolic, double, int) -{ umfpack_di_free_symbolic(Symbolic); *Symbolic = 0; } - -inline void umfpack_free_symbolic(void **Symbolic, std::complex<double>, int) -{ umfpack_zi_free_symbolic(Symbolic); *Symbolic = 0; } - -inline void umfpack_free_symbolic(void **Symbolic, double, SuiteSparse_long) -{ umfpack_dl_free_symbolic(Symbolic); *Symbolic = 0; } - -inline void umfpack_free_symbolic(void **Symbolic, std::complex<double>, SuiteSparse_long) -{ umfpack_zl_free_symbolic(Symbolic); *Symbolic = 0; } - -// Symbolic -inline int umfpack_symbolic(int n_row,int n_col, - const int Ap[], const int Ai[], const double Ax[], void **Symbolic, - const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO]) -{ - return umfpack_di_symbolic(n_row,n_col,Ap,Ai,Ax,Symbolic,Control,Info); -} - -inline int umfpack_symbolic(int n_row,int n_col, - const int Ap[], const int Ai[], const std::complex<double> Ax[], void **Symbolic, - const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO]) -{ - return umfpack_zi_symbolic(n_row,n_col,Ap,Ai,&numext::real_ref(Ax[0]),0,Symbolic,Control,Info); -} -inline SuiteSparse_long umfpack_symbolic( SuiteSparse_long n_row,SuiteSparse_long n_col, - const SuiteSparse_long Ap[], const SuiteSparse_long Ai[], const double Ax[], void **Symbolic, - const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO]) -{ - return umfpack_dl_symbolic(n_row,n_col,Ap,Ai,Ax,Symbolic,Control,Info); -} - -inline SuiteSparse_long umfpack_symbolic( SuiteSparse_long n_row,SuiteSparse_long n_col, - const SuiteSparse_long Ap[], const SuiteSparse_long Ai[], const std::complex<double> Ax[], void **Symbolic, - const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO]) -{ - return umfpack_zl_symbolic(n_row,n_col,Ap,Ai,&numext::real_ref(Ax[0]),0,Symbolic,Control,Info); -} - -// Numeric -inline int umfpack_numeric( const int Ap[], const int Ai[], const double Ax[], - void *Symbolic, void **Numeric, - const double Control[UMFPACK_CONTROL],double Info [UMFPACK_INFO]) -{ - return umfpack_di_numeric(Ap,Ai,Ax,Symbolic,Numeric,Control,Info); -} - -inline int umfpack_numeric( const int Ap[], const int Ai[], const std::complex<double> Ax[], - void *Symbolic, void **Numeric, - const double Control[UMFPACK_CONTROL],double Info [UMFPACK_INFO]) -{ - return umfpack_zi_numeric(Ap,Ai,&numext::real_ref(Ax[0]),0,Symbolic,Numeric,Control,Info); -} -inline SuiteSparse_long umfpack_numeric(const SuiteSparse_long Ap[], const SuiteSparse_long Ai[], const double Ax[], - void *Symbolic, void **Numeric, - const double Control[UMFPACK_CONTROL],double Info [UMFPACK_INFO]) -{ - return umfpack_dl_numeric(Ap,Ai,Ax,Symbolic,Numeric,Control,Info); -} - -inline SuiteSparse_long umfpack_numeric(const SuiteSparse_long Ap[], const SuiteSparse_long Ai[], const std::complex<double> Ax[], - void *Symbolic, void **Numeric, - const double Control[UMFPACK_CONTROL],double Info [UMFPACK_INFO]) -{ - return umfpack_zl_numeric(Ap,Ai,&numext::real_ref(Ax[0]),0,Symbolic,Numeric,Control,Info); -} - -// solve -inline int umfpack_solve( int sys, const int Ap[], const int Ai[], const double Ax[], - double X[], const double B[], void *Numeric, - const double Control[UMFPACK_CONTROL], double Info[UMFPACK_INFO]) -{ - return umfpack_di_solve(sys,Ap,Ai,Ax,X,B,Numeric,Control,Info); -} - -inline int umfpack_solve( int sys, const int Ap[], const int Ai[], const std::complex<double> Ax[], - std::complex<double> X[], const std::complex<double> B[], void *Numeric, - const double Control[UMFPACK_CONTROL], double Info[UMFPACK_INFO]) -{ - return umfpack_zi_solve(sys,Ap,Ai,&numext::real_ref(Ax[0]),0,&numext::real_ref(X[0]),0,&numext::real_ref(B[0]),0,Numeric,Control,Info); -} - -inline SuiteSparse_long umfpack_solve(int sys, const SuiteSparse_long Ap[], const SuiteSparse_long Ai[], const double Ax[], - double X[], const double B[], void *Numeric, - const double Control[UMFPACK_CONTROL], double Info[UMFPACK_INFO]) -{ - return umfpack_dl_solve(sys,Ap,Ai,Ax,X,B,Numeric,Control,Info); -} - -inline SuiteSparse_long umfpack_solve(int sys, const SuiteSparse_long Ap[], const SuiteSparse_long Ai[], const std::complex<double> Ax[], - std::complex<double> X[], const std::complex<double> B[], void *Numeric, - const double Control[UMFPACK_CONTROL], double Info[UMFPACK_INFO]) -{ - return umfpack_zl_solve(sys,Ap,Ai,&numext::real_ref(Ax[0]),0,&numext::real_ref(X[0]),0,&numext::real_ref(B[0]),0,Numeric,Control,Info); -} - -// Get Lunz -inline int umfpack_get_lunz(int *lnz, int *unz, int *n_row, int *n_col, int *nz_udiag, void *Numeric, double) -{ - return umfpack_di_get_lunz(lnz,unz,n_row,n_col,nz_udiag,Numeric); -} - -inline int umfpack_get_lunz(int *lnz, int *unz, int *n_row, int *n_col, int *nz_udiag, void *Numeric, std::complex<double>) -{ - return umfpack_zi_get_lunz(lnz,unz,n_row,n_col,nz_udiag,Numeric); -} - -inline SuiteSparse_long umfpack_get_lunz( SuiteSparse_long *lnz, SuiteSparse_long *unz, SuiteSparse_long *n_row, SuiteSparse_long *n_col, - SuiteSparse_long *nz_udiag, void *Numeric, double) -{ - return umfpack_dl_get_lunz(lnz,unz,n_row,n_col,nz_udiag,Numeric); -} - -inline SuiteSparse_long umfpack_get_lunz( SuiteSparse_long *lnz, SuiteSparse_long *unz, SuiteSparse_long *n_row, SuiteSparse_long *n_col, - SuiteSparse_long *nz_udiag, void *Numeric, std::complex<double>) -{ - return umfpack_zl_get_lunz(lnz,unz,n_row,n_col,nz_udiag,Numeric); -} - -// Get Numeric -inline int umfpack_get_numeric(int Lp[], int Lj[], double Lx[], int Up[], int Ui[], double Ux[], - int P[], int Q[], double Dx[], int *do_recip, double Rs[], void *Numeric) -{ - return umfpack_di_get_numeric(Lp,Lj,Lx,Up,Ui,Ux,P,Q,Dx,do_recip,Rs,Numeric); -} - -inline int umfpack_get_numeric(int Lp[], int Lj[], std::complex<double> Lx[], int Up[], int Ui[], std::complex<double> Ux[], - int P[], int Q[], std::complex<double> Dx[], int *do_recip, double Rs[], void *Numeric) -{ - double& lx0_real = numext::real_ref(Lx[0]); - double& ux0_real = numext::real_ref(Ux[0]); - double& dx0_real = numext::real_ref(Dx[0]); - return umfpack_zi_get_numeric(Lp,Lj,Lx?&lx0_real:0,0,Up,Ui,Ux?&ux0_real:0,0,P,Q, - Dx?&dx0_real:0,0,do_recip,Rs,Numeric); -} -inline SuiteSparse_long umfpack_get_numeric(SuiteSparse_long Lp[], SuiteSparse_long Lj[], double Lx[], SuiteSparse_long Up[], SuiteSparse_long Ui[], double Ux[], - SuiteSparse_long P[], SuiteSparse_long Q[], double Dx[], SuiteSparse_long *do_recip, double Rs[], void *Numeric) -{ - return umfpack_dl_get_numeric(Lp,Lj,Lx,Up,Ui,Ux,P,Q,Dx,do_recip,Rs,Numeric); -} - -inline SuiteSparse_long umfpack_get_numeric(SuiteSparse_long Lp[], SuiteSparse_long Lj[], std::complex<double> Lx[], SuiteSparse_long Up[], SuiteSparse_long Ui[], std::complex<double> Ux[], - SuiteSparse_long P[], SuiteSparse_long Q[], std::complex<double> Dx[], SuiteSparse_long *do_recip, double Rs[], void *Numeric) -{ - double& lx0_real = numext::real_ref(Lx[0]); - double& ux0_real = numext::real_ref(Ux[0]); - double& dx0_real = numext::real_ref(Dx[0]); - return umfpack_zl_get_numeric(Lp,Lj,Lx?&lx0_real:0,0,Up,Ui,Ux?&ux0_real:0,0,P,Q, - Dx?&dx0_real:0,0,do_recip,Rs,Numeric); -} - -// Get Determinant -inline int umfpack_get_determinant(double *Mx, double *Ex, void *NumericHandle, double User_Info [UMFPACK_INFO], int) -{ - return umfpack_di_get_determinant(Mx,Ex,NumericHandle,User_Info); -} - -inline int umfpack_get_determinant(std::complex<double> *Mx, double *Ex, void *NumericHandle, double User_Info [UMFPACK_INFO], int) -{ - double& mx_real = numext::real_ref(*Mx); - return umfpack_zi_get_determinant(&mx_real,0,Ex,NumericHandle,User_Info); -} - -inline SuiteSparse_long umfpack_get_determinant(double *Mx, double *Ex, void *NumericHandle, double User_Info [UMFPACK_INFO], SuiteSparse_long) -{ - return umfpack_dl_get_determinant(Mx,Ex,NumericHandle,User_Info); -} - -inline SuiteSparse_long umfpack_get_determinant(std::complex<double> *Mx, double *Ex, void *NumericHandle, double User_Info [UMFPACK_INFO], SuiteSparse_long) -{ - double& mx_real = numext::real_ref(*Mx); - return umfpack_zl_get_determinant(&mx_real,0,Ex,NumericHandle,User_Info); -} - - -/** \ingroup UmfPackSupport_Module - * \brief A sparse LU factorization and solver based on UmfPack - * - * This class allows to solve for A.X = B sparse linear problems via a LU factorization - * using the UmfPack library. The sparse matrix A must be squared and full rank. - * The vectors or matrices X and B can be either dense or sparse. - * - * \warning The input matrix A should be in a \b compressed and \b column-major form. - * Otherwise an expensive copy will be made. You can call the inexpensive makeCompressed() to get a compressed matrix. - * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> - * - * \implsparsesolverconcept - * - * \sa \ref TutorialSparseSolverConcept, class SparseLU - */ -template<typename _MatrixType> -class UmfPackLU : public SparseSolverBase<UmfPackLU<_MatrixType> > -{ - protected: - typedef SparseSolverBase<UmfPackLU<_MatrixType> > Base; - using Base::m_isInitialized; - public: - using Base::_solve_impl; - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef Matrix<Scalar,Dynamic,1> Vector; - typedef Matrix<int, 1, MatrixType::ColsAtCompileTime> IntRowVectorType; - typedef Matrix<int, MatrixType::RowsAtCompileTime, 1> IntColVectorType; - typedef SparseMatrix<Scalar> LUMatrixType; - typedef SparseMatrix<Scalar,ColMajor,StorageIndex> UmfpackMatrixType; - typedef Ref<const UmfpackMatrixType, StandardCompressedFormat> UmfpackMatrixRef; - enum { - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; - - public: - - typedef Array<double, UMFPACK_CONTROL, 1> UmfpackControl; - typedef Array<double, UMFPACK_INFO, 1> UmfpackInfo; - - UmfPackLU() - : m_dummy(0,0), mp_matrix(m_dummy) - { - init(); - } - - template<typename InputMatrixType> - explicit UmfPackLU(const InputMatrixType& matrix) - : mp_matrix(matrix) - { - init(); - compute(matrix); - } - - ~UmfPackLU() - { - if(m_symbolic) umfpack_free_symbolic(&m_symbolic,Scalar(), StorageIndex()); - if(m_numeric) umfpack_free_numeric(&m_numeric,Scalar(), StorageIndex()); - } - - inline Index rows() const { return mp_matrix.rows(); } - inline Index cols() const { return mp_matrix.cols(); } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, - * \c NumericalIssue if the matrix.appears to be negative. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "Decomposition is not initialized."); - return m_info; - } - - inline const LUMatrixType& matrixL() const - { - if (m_extractedDataAreDirty) extractData(); - return m_l; - } - - inline const LUMatrixType& matrixU() const - { - if (m_extractedDataAreDirty) extractData(); - return m_u; - } - - inline const IntColVectorType& permutationP() const - { - if (m_extractedDataAreDirty) extractData(); - return m_p; - } - - inline const IntRowVectorType& permutationQ() const - { - if (m_extractedDataAreDirty) extractData(); - return m_q; - } - - /** Computes the sparse Cholesky decomposition of \a matrix - * Note that the matrix should be column-major, and in compressed format for best performance. - * \sa SparseMatrix::makeCompressed(). - */ - template<typename InputMatrixType> - void compute(const InputMatrixType& matrix) - { - if(m_symbolic) umfpack_free_symbolic(&m_symbolic,Scalar(),StorageIndex()); - if(m_numeric) umfpack_free_numeric(&m_numeric,Scalar(),StorageIndex()); - grab(matrix.derived()); - analyzePattern_impl(); - factorize_impl(); - } - - /** Performs a symbolic decomposition on the sparcity of \a matrix. - * - * This function is particularly useful when solving for several problems having the same structure. - * - * \sa factorize(), compute() - */ - template<typename InputMatrixType> - void analyzePattern(const InputMatrixType& matrix) - { - if(m_symbolic) umfpack_free_symbolic(&m_symbolic,Scalar(),StorageIndex()); - if(m_numeric) umfpack_free_numeric(&m_numeric,Scalar(),StorageIndex()); - - grab(matrix.derived()); - - analyzePattern_impl(); - } - - /** Provides the return status code returned by UmfPack during the numeric - * factorization. - * - * \sa factorize(), compute() - */ - inline int umfpackFactorizeReturncode() const - { - eigen_assert(m_numeric && "UmfPackLU: you must first call factorize()"); - return m_fact_errorCode; - } - - /** Provides access to the control settings array used by UmfPack. - * - * If this array contains NaN's, the default values are used. - * - * See UMFPACK documentation for details. - */ - inline const UmfpackControl& umfpackControl() const - { - return m_control; - } - - /** Provides access to the control settings array used by UmfPack. - * - * If this array contains NaN's, the default values are used. - * - * See UMFPACK documentation for details. - */ - inline UmfpackControl& umfpackControl() - { - return m_control; - } - - /** Performs a numeric decomposition of \a matrix - * - * The given matrix must has the same sparcity than the matrix on which the pattern anylysis has been performed. - * - * \sa analyzePattern(), compute() - */ - template<typename InputMatrixType> - void factorize(const InputMatrixType& matrix) - { - eigen_assert(m_analysisIsOk && "UmfPackLU: you must first call analyzePattern()"); - if(m_numeric) - umfpack_free_numeric(&m_numeric,Scalar(),StorageIndex()); - - grab(matrix.derived()); - - factorize_impl(); - } - - /** Prints the current UmfPack control settings. - * - * \sa umfpackControl() - */ - void printUmfpackControl() - { - umfpack_report_control(m_control.data(), Scalar(),StorageIndex()); - } - - /** Prints statistics collected by UmfPack. - * - * \sa analyzePattern(), compute() - */ - void printUmfpackInfo() - { - eigen_assert(m_analysisIsOk && "UmfPackLU: you must first call analyzePattern()"); - umfpack_report_info(m_control.data(), m_umfpackInfo.data(), Scalar(),StorageIndex()); - } - - /** Prints the status of the previous factorization operation performed by UmfPack (symbolic or numerical factorization). - * - * \sa analyzePattern(), compute() - */ - void printUmfpackStatus() { - eigen_assert(m_analysisIsOk && "UmfPackLU: you must first call analyzePattern()"); - umfpack_report_status(m_control.data(), m_fact_errorCode, Scalar(),StorageIndex()); - } - - /** \internal */ - template<typename BDerived,typename XDerived> - bool _solve_impl(const MatrixBase<BDerived> &b, MatrixBase<XDerived> &x) const; - - Scalar determinant() const; - - void extractData() const; - - protected: - - void init() - { - m_info = InvalidInput; - m_isInitialized = false; - m_numeric = 0; - m_symbolic = 0; - m_extractedDataAreDirty = true; - - umfpack_defaults(m_control.data(), Scalar(),StorageIndex()); - } - - void analyzePattern_impl() - { - m_fact_errorCode = umfpack_symbolic(internal::convert_index<StorageIndex>(mp_matrix.rows()), - internal::convert_index<StorageIndex>(mp_matrix.cols()), - mp_matrix.outerIndexPtr(), mp_matrix.innerIndexPtr(), mp_matrix.valuePtr(), - &m_symbolic, m_control.data(), m_umfpackInfo.data()); - - m_isInitialized = true; - m_info = m_fact_errorCode ? InvalidInput : Success; - m_analysisIsOk = true; - m_factorizationIsOk = false; - m_extractedDataAreDirty = true; - } - - void factorize_impl() - { - - m_fact_errorCode = umfpack_numeric(mp_matrix.outerIndexPtr(), mp_matrix.innerIndexPtr(), mp_matrix.valuePtr(), - m_symbolic, &m_numeric, m_control.data(), m_umfpackInfo.data()); - - m_info = m_fact_errorCode == UMFPACK_OK ? Success : NumericalIssue; - m_factorizationIsOk = true; - m_extractedDataAreDirty = true; - } - - template<typename MatrixDerived> - void grab(const EigenBase<MatrixDerived> &A) - { - mp_matrix.~UmfpackMatrixRef(); - ::new (&mp_matrix) UmfpackMatrixRef(A.derived()); - } - - void grab(const UmfpackMatrixRef &A) - { - if(&(A.derived()) != &mp_matrix) - { - mp_matrix.~UmfpackMatrixRef(); - ::new (&mp_matrix) UmfpackMatrixRef(A); - } - } - - // cached data to reduce reallocation, etc. - mutable LUMatrixType m_l; - StorageIndex m_fact_errorCode; - UmfpackControl m_control; - mutable UmfpackInfo m_umfpackInfo; - - mutable LUMatrixType m_u; - mutable IntColVectorType m_p; - mutable IntRowVectorType m_q; - - UmfpackMatrixType m_dummy; - UmfpackMatrixRef mp_matrix; - - void* m_numeric; - void* m_symbolic; - - mutable ComputationInfo m_info; - int m_factorizationIsOk; - int m_analysisIsOk; - mutable bool m_extractedDataAreDirty; - - private: - UmfPackLU(const UmfPackLU& ) { } -}; - - -template<typename MatrixType> -void UmfPackLU<MatrixType>::extractData() const -{ - if (m_extractedDataAreDirty) - { - // get size of the data - StorageIndex lnz, unz, rows, cols, nz_udiag; - umfpack_get_lunz(&lnz, &unz, &rows, &cols, &nz_udiag, m_numeric, Scalar()); - - // allocate data - m_l.resize(rows,(std::min)(rows,cols)); - m_l.resizeNonZeros(lnz); - - m_u.resize((std::min)(rows,cols),cols); - m_u.resizeNonZeros(unz); - - m_p.resize(rows); - m_q.resize(cols); - - // extract - umfpack_get_numeric(m_l.outerIndexPtr(), m_l.innerIndexPtr(), m_l.valuePtr(), - m_u.outerIndexPtr(), m_u.innerIndexPtr(), m_u.valuePtr(), - m_p.data(), m_q.data(), 0, 0, 0, m_numeric); - - m_extractedDataAreDirty = false; - } -} - -template<typename MatrixType> -typename UmfPackLU<MatrixType>::Scalar UmfPackLU<MatrixType>::determinant() const -{ - Scalar det; - umfpack_get_determinant(&det, 0, m_numeric, 0, StorageIndex()); - return det; -} - -template<typename MatrixType> -template<typename BDerived,typename XDerived> -bool UmfPackLU<MatrixType>::_solve_impl(const MatrixBase<BDerived> &b, MatrixBase<XDerived> &x) const -{ - Index rhsCols = b.cols(); - eigen_assert((BDerived::Flags&RowMajorBit)==0 && "UmfPackLU backend does not support non col-major rhs yet"); - eigen_assert((XDerived::Flags&RowMajorBit)==0 && "UmfPackLU backend does not support non col-major result yet"); - eigen_assert(b.derived().data() != x.derived().data() && " Umfpack does not support inplace solve"); - - Scalar* x_ptr = 0; - Matrix<Scalar,Dynamic,1> x_tmp; - if(x.innerStride()!=1) - { - x_tmp.resize(x.rows()); - x_ptr = x_tmp.data(); - } - for (int j=0; j<rhsCols; ++j) - { - if(x.innerStride()==1) - x_ptr = &x.col(j).coeffRef(0); - StorageIndex errorCode = umfpack_solve(UMFPACK_A, - mp_matrix.outerIndexPtr(), mp_matrix.innerIndexPtr(), mp_matrix.valuePtr(), - x_ptr, &b.const_cast_derived().col(j).coeffRef(0), - m_numeric, m_control.data(), m_umfpackInfo.data()); - if(x.innerStride()!=1) - x.col(j) = x_tmp; - if (errorCode!=0) - return false; - } - - return true; -} - -} // end namespace Eigen - -#endif // EIGEN_UMFPACKSUPPORT_H diff --git a/external/eigen/include/eigen3/Eigen/src/misc/Image.h b/external/eigen/include/eigen3/Eigen/src/misc/Image.h deleted file mode 100644 index b8b8a045..00000000 --- a/external/eigen/include/eigen3/Eigen/src/misc/Image.h +++ /dev/null @@ -1,82 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MISC_IMAGE_H -#define EIGEN_MISC_IMAGE_H - -namespace Eigen { - -namespace internal { - -/** \class image_retval_base - * - */ -template<typename DecompositionType> -struct traits<image_retval_base<DecompositionType> > -{ - typedef typename DecompositionType::MatrixType MatrixType; - typedef Matrix< - typename MatrixType::Scalar, - MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose - // dimension is the number of rows of the original matrix - Dynamic, // we don't know at compile time the dimension of the image (the rank) - MatrixType::Options, - MatrixType::MaxRowsAtCompileTime, // the image matrix will consist of columns from the original matrix, - MatrixType::MaxColsAtCompileTime // so it has the same number of rows and at most as many columns. - > ReturnType; -}; - -template<typename _DecompositionType> struct image_retval_base - : public ReturnByValue<image_retval_base<_DecompositionType> > -{ - typedef _DecompositionType DecompositionType; - typedef typename DecompositionType::MatrixType MatrixType; - typedef ReturnByValue<image_retval_base> Base; - - image_retval_base(const DecompositionType& dec, const MatrixType& originalMatrix) - : m_dec(dec), m_rank(dec.rank()), - m_cols(m_rank == 0 ? 1 : m_rank), - m_originalMatrix(originalMatrix) - {} - - inline Index rows() const { return m_dec.rows(); } - inline Index cols() const { return m_cols; } - inline Index rank() const { return m_rank; } - inline const DecompositionType& dec() const { return m_dec; } - inline const MatrixType& originalMatrix() const { return m_originalMatrix; } - - template<typename Dest> inline void evalTo(Dest& dst) const - { - static_cast<const image_retval<DecompositionType>*>(this)->evalTo(dst); - } - - protected: - const DecompositionType& m_dec; - Index m_rank, m_cols; - const MatrixType& m_originalMatrix; -}; - -} // end namespace internal - -#define EIGEN_MAKE_IMAGE_HELPERS(DecompositionType) \ - typedef typename DecompositionType::MatrixType MatrixType; \ - typedef typename MatrixType::Scalar Scalar; \ - typedef typename MatrixType::RealScalar RealScalar; \ - typedef Eigen::internal::image_retval_base<DecompositionType> Base; \ - using Base::dec; \ - using Base::originalMatrix; \ - using Base::rank; \ - using Base::rows; \ - using Base::cols; \ - image_retval(const DecompositionType& dec, const MatrixType& originalMatrix) \ - : Base(dec, originalMatrix) {} - -} // end namespace Eigen - -#endif // EIGEN_MISC_IMAGE_H diff --git a/external/eigen/include/eigen3/Eigen/src/misc/Kernel.h b/external/eigen/include/eigen3/Eigen/src/misc/Kernel.h deleted file mode 100644 index bef5d6ff..00000000 --- a/external/eigen/include/eigen3/Eigen/src/misc/Kernel.h +++ /dev/null @@ -1,79 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MISC_KERNEL_H -#define EIGEN_MISC_KERNEL_H - -namespace Eigen { - -namespace internal { - -/** \class kernel_retval_base - * - */ -template<typename DecompositionType> -struct traits<kernel_retval_base<DecompositionType> > -{ - typedef typename DecompositionType::MatrixType MatrixType; - typedef Matrix< - typename MatrixType::Scalar, - MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix" - // is the number of cols of the original matrix - // so that the product "matrix * kernel = zero" makes sense - Dynamic, // we don't know at compile-time the dimension of the kernel - MatrixType::Options, - MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter - MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space, - // whose dimension is the number of columns of the original matrix - > ReturnType; -}; - -template<typename _DecompositionType> struct kernel_retval_base - : public ReturnByValue<kernel_retval_base<_DecompositionType> > -{ - typedef _DecompositionType DecompositionType; - typedef ReturnByValue<kernel_retval_base> Base; - - explicit kernel_retval_base(const DecompositionType& dec) - : m_dec(dec), - m_rank(dec.rank()), - m_cols(m_rank==dec.cols() ? 1 : dec.cols() - m_rank) - {} - - inline Index rows() const { return m_dec.cols(); } - inline Index cols() const { return m_cols; } - inline Index rank() const { return m_rank; } - inline const DecompositionType& dec() const { return m_dec; } - - template<typename Dest> inline void evalTo(Dest& dst) const - { - static_cast<const kernel_retval<DecompositionType>*>(this)->evalTo(dst); - } - - protected: - const DecompositionType& m_dec; - Index m_rank, m_cols; -}; - -} // end namespace internal - -#define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) \ - typedef typename DecompositionType::MatrixType MatrixType; \ - typedef typename MatrixType::Scalar Scalar; \ - typedef typename MatrixType::RealScalar RealScalar; \ - typedef Eigen::internal::kernel_retval_base<DecompositionType> Base; \ - using Base::dec; \ - using Base::rank; \ - using Base::rows; \ - using Base::cols; \ - kernel_retval(const DecompositionType& dec) : Base(dec) {} - -} // end namespace Eigen - -#endif // EIGEN_MISC_KERNEL_H diff --git a/external/eigen/include/eigen3/Eigen/src/misc/RealSvd2x2.h b/external/eigen/include/eigen3/Eigen/src/misc/RealSvd2x2.h deleted file mode 100644 index abb4d3c2..00000000 --- a/external/eigen/include/eigen3/Eigen/src/misc/RealSvd2x2.h +++ /dev/null @@ -1,55 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// Copyright (C) 2013-2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_REALSVD2X2_H -#define EIGEN_REALSVD2X2_H - -namespace Eigen { - -namespace internal { - -template<typename MatrixType, typename RealScalar, typename Index> -void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q, - JacobiRotation<RealScalar> *j_left, - JacobiRotation<RealScalar> *j_right) -{ - using std::sqrt; - using std::abs; - Matrix<RealScalar,2,2> m; - m << numext::real(matrix.coeff(p,p)), numext::real(matrix.coeff(p,q)), - numext::real(matrix.coeff(q,p)), numext::real(matrix.coeff(q,q)); - JacobiRotation<RealScalar> rot1; - RealScalar t = m.coeff(0,0) + m.coeff(1,1); - RealScalar d = m.coeff(1,0) - m.coeff(0,1); - - if(abs(d) < (std::numeric_limits<RealScalar>::min)()) - { - rot1.s() = RealScalar(0); - rot1.c() = RealScalar(1); - } - else - { - // If d!=0, then t/d cannot overflow because the magnitude of the - // entries forming d are not too small compared to the ones forming t. - RealScalar u = t / d; - RealScalar tmp = sqrt(RealScalar(1) + numext::abs2(u)); - rot1.s() = RealScalar(1) / tmp; - rot1.c() = u / tmp; - } - m.applyOnTheLeft(0,1,rot1); - j_right->makeJacobi(m,0,1); - *j_left = rot1 * j_right->transpose(); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_REALSVD2X2_H diff --git a/external/eigen/include/eigen3/Eigen/src/misc/blas.h b/external/eigen/include/eigen3/Eigen/src/misc/blas.h deleted file mode 100644 index 25215b15..00000000 --- a/external/eigen/include/eigen3/Eigen/src/misc/blas.h +++ /dev/null @@ -1,440 +0,0 @@ -#ifndef BLAS_H -#define BLAS_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define BLASFUNC(FUNC) FUNC##_ - -#ifdef __WIN64__ -typedef long long BLASLONG; -typedef unsigned long long BLASULONG; -#else -typedef long BLASLONG; -typedef unsigned long BLASULONG; -#endif - -int BLASFUNC(xerbla)(const char *, int *info, int); - -float BLASFUNC(sdot) (int *, float *, int *, float *, int *); -float BLASFUNC(sdsdot)(int *, float *, float *, int *, float *, int *); - -double BLASFUNC(dsdot) (int *, float *, int *, float *, int *); -double BLASFUNC(ddot) (int *, double *, int *, double *, int *); -double BLASFUNC(qdot) (int *, double *, int *, double *, int *); - -int BLASFUNC(cdotuw) (int *, float *, int *, float *, int *, float*); -int BLASFUNC(cdotcw) (int *, float *, int *, float *, int *, float*); -int BLASFUNC(zdotuw) (int *, double *, int *, double *, int *, double*); -int BLASFUNC(zdotcw) (int *, double *, int *, double *, int *, double*); - -int BLASFUNC(saxpy) (const int *, const float *, const float *, const int *, float *, const int *); -int BLASFUNC(daxpy) (const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(qaxpy) (const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(caxpy) (const int *, const float *, const float *, const int *, float *, const int *); -int BLASFUNC(zaxpy) (const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(xaxpy) (const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(caxpyc)(const int *, const float *, const float *, const int *, float *, const int *); -int BLASFUNC(zaxpyc)(const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(xaxpyc)(const int *, const double *, const double *, const int *, double *, const int *); - -int BLASFUNC(scopy) (int *, float *, int *, float *, int *); -int BLASFUNC(dcopy) (int *, double *, int *, double *, int *); -int BLASFUNC(qcopy) (int *, double *, int *, double *, int *); -int BLASFUNC(ccopy) (int *, float *, int *, float *, int *); -int BLASFUNC(zcopy) (int *, double *, int *, double *, int *); -int BLASFUNC(xcopy) (int *, double *, int *, double *, int *); - -int BLASFUNC(sswap) (int *, float *, int *, float *, int *); -int BLASFUNC(dswap) (int *, double *, int *, double *, int *); -int BLASFUNC(qswap) (int *, double *, int *, double *, int *); -int BLASFUNC(cswap) (int *, float *, int *, float *, int *); -int BLASFUNC(zswap) (int *, double *, int *, double *, int *); -int BLASFUNC(xswap) (int *, double *, int *, double *, int *); - -float BLASFUNC(sasum) (int *, float *, int *); -float BLASFUNC(scasum)(int *, float *, int *); -double BLASFUNC(dasum) (int *, double *, int *); -double BLASFUNC(qasum) (int *, double *, int *); -double BLASFUNC(dzasum)(int *, double *, int *); -double BLASFUNC(qxasum)(int *, double *, int *); - -int BLASFUNC(isamax)(int *, float *, int *); -int BLASFUNC(idamax)(int *, double *, int *); -int BLASFUNC(iqamax)(int *, double *, int *); -int BLASFUNC(icamax)(int *, float *, int *); -int BLASFUNC(izamax)(int *, double *, int *); -int BLASFUNC(ixamax)(int *, double *, int *); - -int BLASFUNC(ismax) (int *, float *, int *); -int BLASFUNC(idmax) (int *, double *, int *); -int BLASFUNC(iqmax) (int *, double *, int *); -int BLASFUNC(icmax) (int *, float *, int *); -int BLASFUNC(izmax) (int *, double *, int *); -int BLASFUNC(ixmax) (int *, double *, int *); - -int BLASFUNC(isamin)(int *, float *, int *); -int BLASFUNC(idamin)(int *, double *, int *); -int BLASFUNC(iqamin)(int *, double *, int *); -int BLASFUNC(icamin)(int *, float *, int *); -int BLASFUNC(izamin)(int *, double *, int *); -int BLASFUNC(ixamin)(int *, double *, int *); - -int BLASFUNC(ismin)(int *, float *, int *); -int BLASFUNC(idmin)(int *, double *, int *); -int BLASFUNC(iqmin)(int *, double *, int *); -int BLASFUNC(icmin)(int *, float *, int *); -int BLASFUNC(izmin)(int *, double *, int *); -int BLASFUNC(ixmin)(int *, double *, int *); - -float BLASFUNC(samax) (int *, float *, int *); -double BLASFUNC(damax) (int *, double *, int *); -double BLASFUNC(qamax) (int *, double *, int *); -float BLASFUNC(scamax)(int *, float *, int *); -double BLASFUNC(dzamax)(int *, double *, int *); -double BLASFUNC(qxamax)(int *, double *, int *); - -float BLASFUNC(samin) (int *, float *, int *); -double BLASFUNC(damin) (int *, double *, int *); -double BLASFUNC(qamin) (int *, double *, int *); -float BLASFUNC(scamin)(int *, float *, int *); -double BLASFUNC(dzamin)(int *, double *, int *); -double BLASFUNC(qxamin)(int *, double *, int *); - -float BLASFUNC(smax) (int *, float *, int *); -double BLASFUNC(dmax) (int *, double *, int *); -double BLASFUNC(qmax) (int *, double *, int *); -float BLASFUNC(scmax) (int *, float *, int *); -double BLASFUNC(dzmax) (int *, double *, int *); -double BLASFUNC(qxmax) (int *, double *, int *); - -float BLASFUNC(smin) (int *, float *, int *); -double BLASFUNC(dmin) (int *, double *, int *); -double BLASFUNC(qmin) (int *, double *, int *); -float BLASFUNC(scmin) (int *, float *, int *); -double BLASFUNC(dzmin) (int *, double *, int *); -double BLASFUNC(qxmin) (int *, double *, int *); - -int BLASFUNC(sscal) (int *, float *, float *, int *); -int BLASFUNC(dscal) (int *, double *, double *, int *); -int BLASFUNC(qscal) (int *, double *, double *, int *); -int BLASFUNC(cscal) (int *, float *, float *, int *); -int BLASFUNC(zscal) (int *, double *, double *, int *); -int BLASFUNC(xscal) (int *, double *, double *, int *); -int BLASFUNC(csscal)(int *, float *, float *, int *); -int BLASFUNC(zdscal)(int *, double *, double *, int *); -int BLASFUNC(xqscal)(int *, double *, double *, int *); - -float BLASFUNC(snrm2) (int *, float *, int *); -float BLASFUNC(scnrm2)(int *, float *, int *); - -double BLASFUNC(dnrm2) (int *, double *, int *); -double BLASFUNC(qnrm2) (int *, double *, int *); -double BLASFUNC(dznrm2)(int *, double *, int *); -double BLASFUNC(qxnrm2)(int *, double *, int *); - -int BLASFUNC(srot) (int *, float *, int *, float *, int *, float *, float *); -int BLASFUNC(drot) (int *, double *, int *, double *, int *, double *, double *); -int BLASFUNC(qrot) (int *, double *, int *, double *, int *, double *, double *); -int BLASFUNC(csrot) (int *, float *, int *, float *, int *, float *, float *); -int BLASFUNC(zdrot) (int *, double *, int *, double *, int *, double *, double *); -int BLASFUNC(xqrot) (int *, double *, int *, double *, int *, double *, double *); - -int BLASFUNC(srotg) (float *, float *, float *, float *); -int BLASFUNC(drotg) (double *, double *, double *, double *); -int BLASFUNC(qrotg) (double *, double *, double *, double *); -int BLASFUNC(crotg) (float *, float *, float *, float *); -int BLASFUNC(zrotg) (double *, double *, double *, double *); -int BLASFUNC(xrotg) (double *, double *, double *, double *); - -int BLASFUNC(srotmg)(float *, float *, float *, float *, float *); -int BLASFUNC(drotmg)(double *, double *, double *, double *, double *); - -int BLASFUNC(srotm) (int *, float *, int *, float *, int *, float *); -int BLASFUNC(drotm) (int *, double *, int *, double *, int *, double *); -int BLASFUNC(qrotm) (int *, double *, int *, double *, int *, double *); - -/* Level 2 routines */ - -int BLASFUNC(sger)(int *, int *, float *, float *, int *, - float *, int *, float *, int *); -int BLASFUNC(dger)(int *, int *, double *, double *, int *, - double *, int *, double *, int *); -int BLASFUNC(qger)(int *, int *, double *, double *, int *, - double *, int *, double *, int *); -int BLASFUNC(cgeru)(int *, int *, float *, float *, int *, - float *, int *, float *, int *); -int BLASFUNC(cgerc)(int *, int *, float *, float *, int *, - float *, int *, float *, int *); -int BLASFUNC(zgeru)(int *, int *, double *, double *, int *, - double *, int *, double *, int *); -int BLASFUNC(zgerc)(int *, int *, double *, double *, int *, - double *, int *, double *, int *); -int BLASFUNC(xgeru)(int *, int *, double *, double *, int *, - double *, int *, double *, int *); -int BLASFUNC(xgerc)(int *, int *, double *, double *, int *, - double *, int *, double *, int *); - -int BLASFUNC(sgemv)(const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(dgemv)(const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(qgemv)(const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(cgemv)(const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zgemv)(const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xgemv)(const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); - -int BLASFUNC(strsv) (const char *, const char *, const char *, const int *, const float *, const int *, float *, const int *); -int BLASFUNC(dtrsv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(qtrsv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(ctrsv) (const char *, const char *, const char *, const int *, const float *, const int *, float *, const int *); -int BLASFUNC(ztrsv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(xtrsv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *); - -int BLASFUNC(stpsv) (char *, char *, char *, int *, float *, float *, int *); -int BLASFUNC(dtpsv) (char *, char *, char *, int *, double *, double *, int *); -int BLASFUNC(qtpsv) (char *, char *, char *, int *, double *, double *, int *); -int BLASFUNC(ctpsv) (char *, char *, char *, int *, float *, float *, int *); -int BLASFUNC(ztpsv) (char *, char *, char *, int *, double *, double *, int *); -int BLASFUNC(xtpsv) (char *, char *, char *, int *, double *, double *, int *); - -int BLASFUNC(strmv) (const char *, const char *, const char *, const int *, const float *, const int *, float *, const int *); -int BLASFUNC(dtrmv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(qtrmv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(ctrmv) (const char *, const char *, const char *, const int *, const float *, const int *, float *, const int *); -int BLASFUNC(ztrmv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(xtrmv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *); - -int BLASFUNC(stpmv) (char *, char *, char *, int *, float *, float *, int *); -int BLASFUNC(dtpmv) (char *, char *, char *, int *, double *, double *, int *); -int BLASFUNC(qtpmv) (char *, char *, char *, int *, double *, double *, int *); -int BLASFUNC(ctpmv) (char *, char *, char *, int *, float *, float *, int *); -int BLASFUNC(ztpmv) (char *, char *, char *, int *, double *, double *, int *); -int BLASFUNC(xtpmv) (char *, char *, char *, int *, double *, double *, int *); - -int BLASFUNC(stbmv) (char *, char *, char *, int *, int *, float *, int *, float *, int *); -int BLASFUNC(dtbmv) (char *, char *, char *, int *, int *, double *, int *, double *, int *); -int BLASFUNC(qtbmv) (char *, char *, char *, int *, int *, double *, int *, double *, int *); -int BLASFUNC(ctbmv) (char *, char *, char *, int *, int *, float *, int *, float *, int *); -int BLASFUNC(ztbmv) (char *, char *, char *, int *, int *, double *, int *, double *, int *); -int BLASFUNC(xtbmv) (char *, char *, char *, int *, int *, double *, int *, double *, int *); - -int BLASFUNC(stbsv) (char *, char *, char *, int *, int *, float *, int *, float *, int *); -int BLASFUNC(dtbsv) (char *, char *, char *, int *, int *, double *, int *, double *, int *); -int BLASFUNC(qtbsv) (char *, char *, char *, int *, int *, double *, int *, double *, int *); -int BLASFUNC(ctbsv) (char *, char *, char *, int *, int *, float *, int *, float *, int *); -int BLASFUNC(ztbsv) (char *, char *, char *, int *, int *, double *, int *, double *, int *); -int BLASFUNC(xtbsv) (char *, char *, char *, int *, int *, double *, int *, double *, int *); - -int BLASFUNC(ssymv) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(dsymv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(qsymv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); - -int BLASFUNC(sspmv) (char *, int *, float *, float *, - float *, int *, float *, float *, int *); -int BLASFUNC(dspmv) (char *, int *, double *, double *, - double *, int *, double *, double *, int *); -int BLASFUNC(qspmv) (char *, int *, double *, double *, - double *, int *, double *, double *, int *); - -int BLASFUNC(ssyr) (const char *, const int *, const float *, const float *, const int *, float *, const int *); -int BLASFUNC(dsyr) (const char *, const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(qsyr) (const char *, const int *, const double *, const double *, const int *, double *, const int *); - -int BLASFUNC(ssyr2) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, float *, const int *); -int BLASFUNC(dsyr2) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(qsyr2) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(csyr2) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, float *, const int *); -int BLASFUNC(zsyr2) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, double *, const int *); -int BLASFUNC(xsyr2) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, double *, const int *); - -int BLASFUNC(sspr) (char *, int *, float *, float *, int *, - float *); -int BLASFUNC(dspr) (char *, int *, double *, double *, int *, - double *); -int BLASFUNC(qspr) (char *, int *, double *, double *, int *, - double *); - -int BLASFUNC(sspr2) (char *, int *, float *, - float *, int *, float *, int *, float *); -int BLASFUNC(dspr2) (char *, int *, double *, - double *, int *, double *, int *, double *); -int BLASFUNC(qspr2) (char *, int *, double *, - double *, int *, double *, int *, double *); -int BLASFUNC(cspr2) (char *, int *, float *, - float *, int *, float *, int *, float *); -int BLASFUNC(zspr2) (char *, int *, double *, - double *, int *, double *, int *, double *); -int BLASFUNC(xspr2) (char *, int *, double *, - double *, int *, double *, int *, double *); - -int BLASFUNC(cher) (char *, int *, float *, float *, int *, - float *, int *); -int BLASFUNC(zher) (char *, int *, double *, double *, int *, - double *, int *); -int BLASFUNC(xher) (char *, int *, double *, double *, int *, - double *, int *); - -int BLASFUNC(chpr) (char *, int *, float *, float *, int *, float *); -int BLASFUNC(zhpr) (char *, int *, double *, double *, int *, double *); -int BLASFUNC(xhpr) (char *, int *, double *, double *, int *, double *); - -int BLASFUNC(cher2) (char *, int *, float *, - float *, int *, float *, int *, float *, int *); -int BLASFUNC(zher2) (char *, int *, double *, - double *, int *, double *, int *, double *, int *); -int BLASFUNC(xher2) (char *, int *, double *, - double *, int *, double *, int *, double *, int *); - -int BLASFUNC(chpr2) (char *, int *, float *, - float *, int *, float *, int *, float *); -int BLASFUNC(zhpr2) (char *, int *, double *, - double *, int *, double *, int *, double *); -int BLASFUNC(xhpr2) (char *, int *, double *, - double *, int *, double *, int *, double *); - -int BLASFUNC(chemv) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zhemv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xhemv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); - -int BLASFUNC(chpmv) (char *, int *, float *, float *, - float *, int *, float *, float *, int *); -int BLASFUNC(zhpmv) (char *, int *, double *, double *, - double *, int *, double *, double *, int *); -int BLASFUNC(xhpmv) (char *, int *, double *, double *, - double *, int *, double *, double *, int *); - -int BLASFUNC(snorm)(char *, int *, int *, float *, int *); -int BLASFUNC(dnorm)(char *, int *, int *, double *, int *); -int BLASFUNC(cnorm)(char *, int *, int *, float *, int *); -int BLASFUNC(znorm)(char *, int *, int *, double *, int *); - -int BLASFUNC(sgbmv)(char *, int *, int *, int *, int *, float *, float *, int *, - float *, int *, float *, float *, int *); -int BLASFUNC(dgbmv)(char *, int *, int *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); -int BLASFUNC(qgbmv)(char *, int *, int *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); -int BLASFUNC(cgbmv)(char *, int *, int *, int *, int *, float *, float *, int *, - float *, int *, float *, float *, int *); -int BLASFUNC(zgbmv)(char *, int *, int *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); -int BLASFUNC(xgbmv)(char *, int *, int *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); - -int BLASFUNC(ssbmv)(char *, int *, int *, float *, float *, int *, - float *, int *, float *, float *, int *); -int BLASFUNC(dsbmv)(char *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); -int BLASFUNC(qsbmv)(char *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); -int BLASFUNC(csbmv)(char *, int *, int *, float *, float *, int *, - float *, int *, float *, float *, int *); -int BLASFUNC(zsbmv)(char *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); -int BLASFUNC(xsbmv)(char *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); - -int BLASFUNC(chbmv)(char *, int *, int *, float *, float *, int *, - float *, int *, float *, float *, int *); -int BLASFUNC(zhbmv)(char *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); -int BLASFUNC(xhbmv)(char *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); - -/* Level 3 routines */ - -int BLASFUNC(sgemm)(const char *, const char *, const int *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(dgemm)(const char *, const char *, const int *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(qgemm)(const char *, const char *, const int *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(cgemm)(const char *, const char *, const int *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zgemm)(const char *, const char *, const int *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xgemm)(const char *, const char *, const int *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); - -int BLASFUNC(cgemm3m)(char *, char *, int *, int *, int *, float *, - float *, int *, float *, int *, float *, float *, int *); -int BLASFUNC(zgemm3m)(char *, char *, int *, int *, int *, double *, - double *, int *, double *, int *, double *, double *, int *); -int BLASFUNC(xgemm3m)(char *, char *, int *, int *, int *, double *, - double *, int *, double *, int *, double *, double *, int *); - -int BLASFUNC(sge2mm)(char *, char *, char *, int *, int *, - float *, float *, int *, float *, int *, - float *, float *, int *); -int BLASFUNC(dge2mm)(char *, char *, char *, int *, int *, - double *, double *, int *, double *, int *, - double *, double *, int *); -int BLASFUNC(cge2mm)(char *, char *, char *, int *, int *, - float *, float *, int *, float *, int *, - float *, float *, int *); -int BLASFUNC(zge2mm)(char *, char *, char *, int *, int *, - double *, double *, int *, double *, int *, - double *, double *, int *); - -int BLASFUNC(strsm)(const char *, const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, float *, const int *); -int BLASFUNC(dtrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(qtrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(ctrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, float *, const int *); -int BLASFUNC(ztrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(xtrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *); - -int BLASFUNC(strmm)(const char *, const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, float *, const int *); -int BLASFUNC(dtrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(qtrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(ctrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, float *, const int *); -int BLASFUNC(ztrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *); -int BLASFUNC(xtrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *); - -int BLASFUNC(ssymm)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(dsymm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(qsymm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(csymm)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zsymm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xsymm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); - -int BLASFUNC(csymm3m)(char *, char *, int *, int *, float *, float *, int *, float *, int *, float *, float *, int *); -int BLASFUNC(zsymm3m)(char *, char *, int *, int *, double *, double *, int *, double *, int *, double *, double *, int *); -int BLASFUNC(xsymm3m)(char *, char *, int *, int *, double *, double *, int *, double *, int *, double *, double *, int *); - -int BLASFUNC(ssyrk)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(dsyrk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(qsyrk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(csyrk)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zsyrk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xsyrk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *); - -int BLASFUNC(ssyr2k)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(dsyr2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *); -int BLASFUNC(qsyr2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *); -int BLASFUNC(csyr2k)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zsyr2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *); -int BLASFUNC(xsyr2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *); - -int BLASFUNC(chemm)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zhemm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xhemm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); - -int BLASFUNC(chemm3m)(char *, char *, int *, int *, float *, float *, int *, - float *, int *, float *, float *, int *); -int BLASFUNC(zhemm3m)(char *, char *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); -int BLASFUNC(xhemm3m)(char *, char *, int *, int *, double *, double *, int *, - double *, int *, double *, double *, int *); - -int BLASFUNC(cherk)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zherk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xherk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *); - -int BLASFUNC(cher2k)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zher2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xher2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(cher2m)(const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zher2m)(const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *); -int BLASFUNC(xher2m)(const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/misc/lapack.h b/external/eigen/include/eigen3/Eigen/src/misc/lapack.h deleted file mode 100644 index 249f3575..00000000 --- a/external/eigen/include/eigen3/Eigen/src/misc/lapack.h +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef LAPACK_H -#define LAPACK_H - -#include "blas.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -int BLASFUNC(csymv) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *); -int BLASFUNC(zsymv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); -int BLASFUNC(xsymv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *); - - -int BLASFUNC(cspmv) (char *, int *, float *, float *, - float *, int *, float *, float *, int *); -int BLASFUNC(zspmv) (char *, int *, double *, double *, - double *, int *, double *, double *, int *); -int BLASFUNC(xspmv) (char *, int *, double *, double *, - double *, int *, double *, double *, int *); - -int BLASFUNC(csyr) (char *, int *, float *, float *, int *, - float *, int *); -int BLASFUNC(zsyr) (char *, int *, double *, double *, int *, - double *, int *); -int BLASFUNC(xsyr) (char *, int *, double *, double *, int *, - double *, int *); - -int BLASFUNC(cspr) (char *, int *, float *, float *, int *, - float *); -int BLASFUNC(zspr) (char *, int *, double *, double *, int *, - double *); -int BLASFUNC(xspr) (char *, int *, double *, double *, int *, - double *); - -int BLASFUNC(sgemt)(char *, int *, int *, float *, float *, int *, - float *, int *); -int BLASFUNC(dgemt)(char *, int *, int *, double *, double *, int *, - double *, int *); -int BLASFUNC(cgemt)(char *, int *, int *, float *, float *, int *, - float *, int *); -int BLASFUNC(zgemt)(char *, int *, int *, double *, double *, int *, - double *, int *); - -int BLASFUNC(sgema)(char *, char *, int *, int *, float *, - float *, int *, float *, float *, int *, float *, int *); -int BLASFUNC(dgema)(char *, char *, int *, int *, double *, - double *, int *, double*, double *, int *, double*, int *); -int BLASFUNC(cgema)(char *, char *, int *, int *, float *, - float *, int *, float *, float *, int *, float *, int *); -int BLASFUNC(zgema)(char *, char *, int *, int *, double *, - double *, int *, double*, double *, int *, double*, int *); - -int BLASFUNC(sgems)(char *, char *, int *, int *, float *, - float *, int *, float *, float *, int *, float *, int *); -int BLASFUNC(dgems)(char *, char *, int *, int *, double *, - double *, int *, double*, double *, int *, double*, int *); -int BLASFUNC(cgems)(char *, char *, int *, int *, float *, - float *, int *, float *, float *, int *, float *, int *); -int BLASFUNC(zgems)(char *, char *, int *, int *, double *, - double *, int *, double*, double *, int *, double*, int *); - -int BLASFUNC(sgetf2)(int *, int *, float *, int *, int *, int *); -int BLASFUNC(dgetf2)(int *, int *, double *, int *, int *, int *); -int BLASFUNC(qgetf2)(int *, int *, double *, int *, int *, int *); -int BLASFUNC(cgetf2)(int *, int *, float *, int *, int *, int *); -int BLASFUNC(zgetf2)(int *, int *, double *, int *, int *, int *); -int BLASFUNC(xgetf2)(int *, int *, double *, int *, int *, int *); - -int BLASFUNC(sgetrf)(int *, int *, float *, int *, int *, int *); -int BLASFUNC(dgetrf)(int *, int *, double *, int *, int *, int *); -int BLASFUNC(qgetrf)(int *, int *, double *, int *, int *, int *); -int BLASFUNC(cgetrf)(int *, int *, float *, int *, int *, int *); -int BLASFUNC(zgetrf)(int *, int *, double *, int *, int *, int *); -int BLASFUNC(xgetrf)(int *, int *, double *, int *, int *, int *); - -int BLASFUNC(slaswp)(int *, float *, int *, int *, int *, int *, int *); -int BLASFUNC(dlaswp)(int *, double *, int *, int *, int *, int *, int *); -int BLASFUNC(qlaswp)(int *, double *, int *, int *, int *, int *, int *); -int BLASFUNC(claswp)(int *, float *, int *, int *, int *, int *, int *); -int BLASFUNC(zlaswp)(int *, double *, int *, int *, int *, int *, int *); -int BLASFUNC(xlaswp)(int *, double *, int *, int *, int *, int *, int *); - -int BLASFUNC(sgetrs)(char *, int *, int *, float *, int *, int *, float *, int *, int *); -int BLASFUNC(dgetrs)(char *, int *, int *, double *, int *, int *, double *, int *, int *); -int BLASFUNC(qgetrs)(char *, int *, int *, double *, int *, int *, double *, int *, int *); -int BLASFUNC(cgetrs)(char *, int *, int *, float *, int *, int *, float *, int *, int *); -int BLASFUNC(zgetrs)(char *, int *, int *, double *, int *, int *, double *, int *, int *); -int BLASFUNC(xgetrs)(char *, int *, int *, double *, int *, int *, double *, int *, int *); - -int BLASFUNC(sgesv)(int *, int *, float *, int *, int *, float *, int *, int *); -int BLASFUNC(dgesv)(int *, int *, double *, int *, int *, double*, int *, int *); -int BLASFUNC(qgesv)(int *, int *, double *, int *, int *, double*, int *, int *); -int BLASFUNC(cgesv)(int *, int *, float *, int *, int *, float *, int *, int *); -int BLASFUNC(zgesv)(int *, int *, double *, int *, int *, double*, int *, int *); -int BLASFUNC(xgesv)(int *, int *, double *, int *, int *, double*, int *, int *); - -int BLASFUNC(spotf2)(char *, int *, float *, int *, int *); -int BLASFUNC(dpotf2)(char *, int *, double *, int *, int *); -int BLASFUNC(qpotf2)(char *, int *, double *, int *, int *); -int BLASFUNC(cpotf2)(char *, int *, float *, int *, int *); -int BLASFUNC(zpotf2)(char *, int *, double *, int *, int *); -int BLASFUNC(xpotf2)(char *, int *, double *, int *, int *); - -int BLASFUNC(spotrf)(char *, int *, float *, int *, int *); -int BLASFUNC(dpotrf)(char *, int *, double *, int *, int *); -int BLASFUNC(qpotrf)(char *, int *, double *, int *, int *); -int BLASFUNC(cpotrf)(char *, int *, float *, int *, int *); -int BLASFUNC(zpotrf)(char *, int *, double *, int *, int *); -int BLASFUNC(xpotrf)(char *, int *, double *, int *, int *); - -int BLASFUNC(slauu2)(char *, int *, float *, int *, int *); -int BLASFUNC(dlauu2)(char *, int *, double *, int *, int *); -int BLASFUNC(qlauu2)(char *, int *, double *, int *, int *); -int BLASFUNC(clauu2)(char *, int *, float *, int *, int *); -int BLASFUNC(zlauu2)(char *, int *, double *, int *, int *); -int BLASFUNC(xlauu2)(char *, int *, double *, int *, int *); - -int BLASFUNC(slauum)(char *, int *, float *, int *, int *); -int BLASFUNC(dlauum)(char *, int *, double *, int *, int *); -int BLASFUNC(qlauum)(char *, int *, double *, int *, int *); -int BLASFUNC(clauum)(char *, int *, float *, int *, int *); -int BLASFUNC(zlauum)(char *, int *, double *, int *, int *); -int BLASFUNC(xlauum)(char *, int *, double *, int *, int *); - -int BLASFUNC(strti2)(char *, char *, int *, float *, int *, int *); -int BLASFUNC(dtrti2)(char *, char *, int *, double *, int *, int *); -int BLASFUNC(qtrti2)(char *, char *, int *, double *, int *, int *); -int BLASFUNC(ctrti2)(char *, char *, int *, float *, int *, int *); -int BLASFUNC(ztrti2)(char *, char *, int *, double *, int *, int *); -int BLASFUNC(xtrti2)(char *, char *, int *, double *, int *, int *); - -int BLASFUNC(strtri)(char *, char *, int *, float *, int *, int *); -int BLASFUNC(dtrtri)(char *, char *, int *, double *, int *, int *); -int BLASFUNC(qtrtri)(char *, char *, int *, double *, int *, int *); -int BLASFUNC(ctrtri)(char *, char *, int *, float *, int *, int *); -int BLASFUNC(ztrtri)(char *, char *, int *, double *, int *, int *); -int BLASFUNC(xtrtri)(char *, char *, int *, double *, int *, int *); - -int BLASFUNC(spotri)(char *, int *, float *, int *, int *); -int BLASFUNC(dpotri)(char *, int *, double *, int *, int *); -int BLASFUNC(qpotri)(char *, int *, double *, int *, int *); -int BLASFUNC(cpotri)(char *, int *, float *, int *, int *); -int BLASFUNC(zpotri)(char *, int *, double *, int *, int *); -int BLASFUNC(xpotri)(char *, int *, double *, int *, int *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/external/eigen/include/eigen3/Eigen/src/misc/lapacke.h b/external/eigen/include/eigen3/Eigen/src/misc/lapacke.h deleted file mode 100644 index 3d8e24f5..00000000 --- a/external/eigen/include/eigen3/Eigen/src/misc/lapacke.h +++ /dev/null @@ -1,16292 +0,0 @@ -/***************************************************************************** - Copyright (c) 2010, Intel Corp. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of Intel Corporation nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. -****************************************************************************** -* Contents: Native C interface to LAPACK -* Author: Intel Corporation -* Generated November, 2011 -*****************************************************************************/ - -#ifndef _MKL_LAPACKE_H_ - -#ifndef _LAPACKE_H_ -#define _LAPACKE_H_ - -/* -* Turn on HAVE_LAPACK_CONFIG_H to redefine C-LAPACK datatypes -*/ -#ifdef HAVE_LAPACK_CONFIG_H -#include "lapacke_config.h" -#endif - -#include <stdlib.h> - -#ifndef lapack_int -#define lapack_int int -#endif - -#ifndef lapack_logical -#define lapack_logical lapack_int -#endif - -/* Complex types are structures equivalent to the -* Fortran complex types COMPLEX(4) and COMPLEX(8). -* -* One can also redefine the types with his own types -* for example by including in the code definitions like -* -* #define lapack_complex_float std::complex<float> -* #define lapack_complex_double std::complex<double> -* -* or define these types in the command line: -* -* -Dlapack_complex_float="std::complex<float>" -* -Dlapack_complex_double="std::complex<double>" -*/ - -#ifndef LAPACK_COMPLEX_CUSTOM - -/* Complex type (single precision) */ -#ifndef lapack_complex_float -#include <complex.h> -#define lapack_complex_float float _Complex -#endif - -#ifndef lapack_complex_float_real -#define lapack_complex_float_real(z) (creal(z)) -#endif - -#ifndef lapack_complex_float_imag -#define lapack_complex_float_imag(z) (cimag(z)) -#endif - -lapack_complex_float lapack_make_complex_float( float re, float im ); - -/* Complex type (double precision) */ -#ifndef lapack_complex_double -#include <complex.h> -#define lapack_complex_double double _Complex -#endif - -#ifndef lapack_complex_double_real -#define lapack_complex_double_real(z) (creal(z)) -#endif - -#ifndef lapack_complex_double_imag -#define lapack_complex_double_imag(z) (cimag(z)) -#endif - -lapack_complex_double lapack_make_complex_double( double re, double im ); - -#endif - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef LAPACKE_malloc -#define LAPACKE_malloc( size ) malloc( size ) -#endif -#ifndef LAPACKE_free -#define LAPACKE_free( p ) free( p ) -#endif - -#define LAPACK_C2INT( x ) (lapack_int)(*((float*)&x )) -#define LAPACK_Z2INT( x ) (lapack_int)(*((double*)&x )) - -#define LAPACK_ROW_MAJOR 101 -#define LAPACK_COL_MAJOR 102 - -#define LAPACK_WORK_MEMORY_ERROR -1010 -#define LAPACK_TRANSPOSE_MEMORY_ERROR -1011 - -/* Callback logical functions of one, two, or three arguments are used -* to select eigenvalues to sort to the top left of the Schur form. -* The value is selected if function returns TRUE (non-zero). */ - -typedef lapack_logical (*LAPACK_S_SELECT2) ( const float*, const float* ); -typedef lapack_logical (*LAPACK_S_SELECT3) - ( const float*, const float*, const float* ); -typedef lapack_logical (*LAPACK_D_SELECT2) ( const double*, const double* ); -typedef lapack_logical (*LAPACK_D_SELECT3) - ( const double*, const double*, const double* ); - -typedef lapack_logical (*LAPACK_C_SELECT1) ( const lapack_complex_float* ); -typedef lapack_logical (*LAPACK_C_SELECT2) - ( const lapack_complex_float*, const lapack_complex_float* ); -typedef lapack_logical (*LAPACK_Z_SELECT1) ( const lapack_complex_double* ); -typedef lapack_logical (*LAPACK_Z_SELECT2) - ( const lapack_complex_double*, const lapack_complex_double* ); - -#include "lapacke_mangling.h" - -#define LAPACK_lsame LAPACK_GLOBAL(lsame,LSAME) -lapack_logical LAPACK_lsame( char* ca, char* cb, - lapack_int lca, lapack_int lcb ); - -/* C-LAPACK function prototypes */ - -lapack_int LAPACKE_sbdsdc( int matrix_order, char uplo, char compq, - lapack_int n, float* d, float* e, float* u, - lapack_int ldu, float* vt, lapack_int ldvt, float* q, - lapack_int* iq ); -lapack_int LAPACKE_dbdsdc( int matrix_order, char uplo, char compq, - lapack_int n, double* d, double* e, double* u, - lapack_int ldu, double* vt, lapack_int ldvt, - double* q, lapack_int* iq ); - -lapack_int LAPACKE_sbdsqr( int matrix_order, char uplo, lapack_int n, - lapack_int ncvt, lapack_int nru, lapack_int ncc, - float* d, float* e, float* vt, lapack_int ldvt, - float* u, lapack_int ldu, float* c, lapack_int ldc ); -lapack_int LAPACKE_dbdsqr( int matrix_order, char uplo, lapack_int n, - lapack_int ncvt, lapack_int nru, lapack_int ncc, - double* d, double* e, double* vt, lapack_int ldvt, - double* u, lapack_int ldu, double* c, - lapack_int ldc ); -lapack_int LAPACKE_cbdsqr( int matrix_order, char uplo, lapack_int n, - lapack_int ncvt, lapack_int nru, lapack_int ncc, - float* d, float* e, lapack_complex_float* vt, - lapack_int ldvt, lapack_complex_float* u, - lapack_int ldu, lapack_complex_float* c, - lapack_int ldc ); -lapack_int LAPACKE_zbdsqr( int matrix_order, char uplo, lapack_int n, - lapack_int ncvt, lapack_int nru, lapack_int ncc, - double* d, double* e, lapack_complex_double* vt, - lapack_int ldvt, lapack_complex_double* u, - lapack_int ldu, lapack_complex_double* c, - lapack_int ldc ); - -lapack_int LAPACKE_sdisna( char job, lapack_int m, lapack_int n, const float* d, - float* sep ); -lapack_int LAPACKE_ddisna( char job, lapack_int m, lapack_int n, - const double* d, double* sep ); - -lapack_int LAPACKE_sgbbrd( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int ncc, lapack_int kl, - lapack_int ku, float* ab, lapack_int ldab, float* d, - float* e, float* q, lapack_int ldq, float* pt, - lapack_int ldpt, float* c, lapack_int ldc ); -lapack_int LAPACKE_dgbbrd( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int ncc, lapack_int kl, - lapack_int ku, double* ab, lapack_int ldab, - double* d, double* e, double* q, lapack_int ldq, - double* pt, lapack_int ldpt, double* c, - lapack_int ldc ); -lapack_int LAPACKE_cgbbrd( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int ncc, lapack_int kl, - lapack_int ku, lapack_complex_float* ab, - lapack_int ldab, float* d, float* e, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* pt, lapack_int ldpt, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zgbbrd( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int ncc, lapack_int kl, - lapack_int ku, lapack_complex_double* ab, - lapack_int ldab, double* d, double* e, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* pt, lapack_int ldpt, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_sgbcon( int matrix_order, char norm, lapack_int n, - lapack_int kl, lapack_int ku, const float* ab, - lapack_int ldab, const lapack_int* ipiv, float anorm, - float* rcond ); -lapack_int LAPACKE_dgbcon( int matrix_order, char norm, lapack_int n, - lapack_int kl, lapack_int ku, const double* ab, - lapack_int ldab, const lapack_int* ipiv, - double anorm, double* rcond ); -lapack_int LAPACKE_cgbcon( int matrix_order, char norm, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_int* ipiv, float anorm, float* rcond ); -lapack_int LAPACKE_zgbcon( int matrix_order, char norm, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_double* ab, lapack_int ldab, - const lapack_int* ipiv, double anorm, - double* rcond ); - -lapack_int LAPACKE_sgbequ( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const float* ab, - lapack_int ldab, float* r, float* c, float* rowcnd, - float* colcnd, float* amax ); -lapack_int LAPACKE_dgbequ( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const double* ab, - lapack_int ldab, double* r, double* c, - double* rowcnd, double* colcnd, double* amax ); -lapack_int LAPACKE_cgbequ( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_float* ab, lapack_int ldab, - float* r, float* c, float* rowcnd, float* colcnd, - float* amax ); -lapack_int LAPACKE_zgbequ( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_double* ab, lapack_int ldab, - double* r, double* c, double* rowcnd, double* colcnd, - double* amax ); - -lapack_int LAPACKE_sgbequb( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const float* ab, - lapack_int ldab, float* r, float* c, float* rowcnd, - float* colcnd, float* amax ); -lapack_int LAPACKE_dgbequb( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const double* ab, - lapack_int ldab, double* r, double* c, - double* rowcnd, double* colcnd, double* amax ); -lapack_int LAPACKE_cgbequb( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_float* ab, lapack_int ldab, - float* r, float* c, float* rowcnd, float* colcnd, - float* amax ); -lapack_int LAPACKE_zgbequb( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_double* ab, lapack_int ldab, - double* r, double* c, double* rowcnd, - double* colcnd, double* amax ); - -lapack_int LAPACKE_sgbrfs( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const float* ab, lapack_int ldab, const float* afb, - lapack_int ldafb, const lapack_int* ipiv, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* ferr, float* berr ); -lapack_int LAPACKE_dgbrfs( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const double* ab, lapack_int ldab, const double* afb, - lapack_int ldafb, const lapack_int* ipiv, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr ); -lapack_int LAPACKE_cgbrfs( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_complex_float* afb, lapack_int ldafb, - const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zgbrfs( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const lapack_complex_double* ab, lapack_int ldab, - const lapack_complex_double* afb, lapack_int ldafb, - const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_sgbrfsx( int matrix_order, char trans, char equed, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, const float* ab, lapack_int ldab, - const float* afb, lapack_int ldafb, - const lapack_int* ipiv, const float* r, - const float* c, const float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_dgbrfsx( int matrix_order, char trans, char equed, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, const double* ab, lapack_int ldab, - const double* afb, lapack_int ldafb, - const lapack_int* ipiv, const double* r, - const double* c, const double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); -lapack_int LAPACKE_cgbrfsx( int matrix_order, char trans, char equed, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, const lapack_complex_float* ab, - lapack_int ldab, const lapack_complex_float* afb, - lapack_int ldafb, const lapack_int* ipiv, - const float* r, const float* c, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params ); -lapack_int LAPACKE_zgbrfsx( int matrix_order, char trans, char equed, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, const lapack_complex_double* ab, - lapack_int ldab, const lapack_complex_double* afb, - lapack_int ldafb, const lapack_int* ipiv, - const double* r, const double* c, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); - -lapack_int LAPACKE_sgbsv( int matrix_order, lapack_int n, lapack_int kl, - lapack_int ku, lapack_int nrhs, float* ab, - lapack_int ldab, lapack_int* ipiv, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dgbsv( int matrix_order, lapack_int n, lapack_int kl, - lapack_int ku, lapack_int nrhs, double* ab, - lapack_int ldab, lapack_int* ipiv, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cgbsv( int matrix_order, lapack_int n, lapack_int kl, - lapack_int ku, lapack_int nrhs, - lapack_complex_float* ab, lapack_int ldab, - lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgbsv( int matrix_order, lapack_int n, lapack_int kl, - lapack_int ku, lapack_int nrhs, - lapack_complex_double* ab, lapack_int ldab, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sgbsvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, float* ab, lapack_int ldab, - float* afb, lapack_int ldafb, lapack_int* ipiv, - char* equed, float* r, float* c, float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* rpivot ); -lapack_int LAPACKE_dgbsvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, double* ab, lapack_int ldab, - double* afb, lapack_int ldafb, lapack_int* ipiv, - char* equed, double* r, double* c, double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* rpivot ); -lapack_int LAPACKE_cgbsvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, lapack_complex_float* ab, - lapack_int ldab, lapack_complex_float* afb, - lapack_int ldafb, lapack_int* ipiv, char* equed, - float* r, float* c, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, float* rpivot ); -lapack_int LAPACKE_zgbsvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, lapack_complex_double* ab, - lapack_int ldab, lapack_complex_double* afb, - lapack_int ldafb, lapack_int* ipiv, char* equed, - double* r, double* c, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr, double* rpivot ); - -lapack_int LAPACKE_sgbsvxx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, float* ab, lapack_int ldab, - float* afb, lapack_int ldafb, lapack_int* ipiv, - char* equed, float* r, float* c, float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_dgbsvxx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, double* ab, lapack_int ldab, - double* afb, lapack_int ldafb, lapack_int* ipiv, - char* equed, double* r, double* c, double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params ); -lapack_int LAPACKE_cgbsvxx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, lapack_complex_float* ab, - lapack_int ldab, lapack_complex_float* afb, - lapack_int ldafb, lapack_int* ipiv, char* equed, - float* r, float* c, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* rpvgrw, - float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params ); -lapack_int LAPACKE_zgbsvxx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, lapack_complex_double* ab, - lapack_int ldab, lapack_complex_double* afb, - lapack_int ldafb, lapack_int* ipiv, char* equed, - double* r, double* c, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* rpvgrw, - double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); - -lapack_int LAPACKE_sgbtrf( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, float* ab, - lapack_int ldab, lapack_int* ipiv ); -lapack_int LAPACKE_dgbtrf( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, double* ab, - lapack_int ldab, lapack_int* ipiv ); -lapack_int LAPACKE_cgbtrf( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - lapack_complex_float* ab, lapack_int ldab, - lapack_int* ipiv ); -lapack_int LAPACKE_zgbtrf( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - lapack_complex_double* ab, lapack_int ldab, - lapack_int* ipiv ); - -lapack_int LAPACKE_sgbtrs( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const float* ab, lapack_int ldab, - const lapack_int* ipiv, float* b, lapack_int ldb ); -lapack_int LAPACKE_dgbtrs( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const double* ab, lapack_int ldab, - const lapack_int* ipiv, double* b, lapack_int ldb ); -lapack_int LAPACKE_cgbtrs( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgbtrs( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const lapack_complex_double* ab, lapack_int ldab, - const lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sgebak( int matrix_order, char job, char side, lapack_int n, - lapack_int ilo, lapack_int ihi, const float* scale, - lapack_int m, float* v, lapack_int ldv ); -lapack_int LAPACKE_dgebak( int matrix_order, char job, char side, lapack_int n, - lapack_int ilo, lapack_int ihi, const double* scale, - lapack_int m, double* v, lapack_int ldv ); -lapack_int LAPACKE_cgebak( int matrix_order, char job, char side, lapack_int n, - lapack_int ilo, lapack_int ihi, const float* scale, - lapack_int m, lapack_complex_float* v, - lapack_int ldv ); -lapack_int LAPACKE_zgebak( int matrix_order, char job, char side, lapack_int n, - lapack_int ilo, lapack_int ihi, const double* scale, - lapack_int m, lapack_complex_double* v, - lapack_int ldv ); - -lapack_int LAPACKE_sgebal( int matrix_order, char job, lapack_int n, float* a, - lapack_int lda, lapack_int* ilo, lapack_int* ihi, - float* scale ); -lapack_int LAPACKE_dgebal( int matrix_order, char job, lapack_int n, double* a, - lapack_int lda, lapack_int* ilo, lapack_int* ihi, - double* scale ); -lapack_int LAPACKE_cgebal( int matrix_order, char job, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ilo, lapack_int* ihi, float* scale ); -lapack_int LAPACKE_zgebal( int matrix_order, char job, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ilo, lapack_int* ihi, double* scale ); - -lapack_int LAPACKE_sgebrd( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* d, float* e, - float* tauq, float* taup ); -lapack_int LAPACKE_dgebrd( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* d, double* e, - double* tauq, double* taup ); -lapack_int LAPACKE_cgebrd( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, float* d, - float* e, lapack_complex_float* tauq, - lapack_complex_float* taup ); -lapack_int LAPACKE_zgebrd( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, double* d, - double* e, lapack_complex_double* tauq, - lapack_complex_double* taup ); - -lapack_int LAPACKE_sgecon( int matrix_order, char norm, lapack_int n, - const float* a, lapack_int lda, float anorm, - float* rcond ); -lapack_int LAPACKE_dgecon( int matrix_order, char norm, lapack_int n, - const double* a, lapack_int lda, double anorm, - double* rcond ); -lapack_int LAPACKE_cgecon( int matrix_order, char norm, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float anorm, float* rcond ); -lapack_int LAPACKE_zgecon( int matrix_order, char norm, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double anorm, double* rcond ); - -lapack_int LAPACKE_sgeequ( int matrix_order, lapack_int m, lapack_int n, - const float* a, lapack_int lda, float* r, float* c, - float* rowcnd, float* colcnd, float* amax ); -lapack_int LAPACKE_dgeequ( int matrix_order, lapack_int m, lapack_int n, - const double* a, lapack_int lda, double* r, - double* c, double* rowcnd, double* colcnd, - double* amax ); -lapack_int LAPACKE_cgeequ( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* r, float* c, float* rowcnd, float* colcnd, - float* amax ); -lapack_int LAPACKE_zgeequ( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* r, double* c, double* rowcnd, double* colcnd, - double* amax ); - -lapack_int LAPACKE_sgeequb( int matrix_order, lapack_int m, lapack_int n, - const float* a, lapack_int lda, float* r, float* c, - float* rowcnd, float* colcnd, float* amax ); -lapack_int LAPACKE_dgeequb( int matrix_order, lapack_int m, lapack_int n, - const double* a, lapack_int lda, double* r, - double* c, double* rowcnd, double* colcnd, - double* amax ); -lapack_int LAPACKE_cgeequb( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* r, float* c, float* rowcnd, float* colcnd, - float* amax ); -lapack_int LAPACKE_zgeequb( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* r, double* c, double* rowcnd, - double* colcnd, double* amax ); - -lapack_int LAPACKE_sgees( int matrix_order, char jobvs, char sort, - LAPACK_S_SELECT2 select, lapack_int n, float* a, - lapack_int lda, lapack_int* sdim, float* wr, - float* wi, float* vs, lapack_int ldvs ); -lapack_int LAPACKE_dgees( int matrix_order, char jobvs, char sort, - LAPACK_D_SELECT2 select, lapack_int n, double* a, - lapack_int lda, lapack_int* sdim, double* wr, - double* wi, double* vs, lapack_int ldvs ); -lapack_int LAPACKE_cgees( int matrix_order, char jobvs, char sort, - LAPACK_C_SELECT1 select, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* sdim, lapack_complex_float* w, - lapack_complex_float* vs, lapack_int ldvs ); -lapack_int LAPACKE_zgees( int matrix_order, char jobvs, char sort, - LAPACK_Z_SELECT1 select, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* sdim, lapack_complex_double* w, - lapack_complex_double* vs, lapack_int ldvs ); - -lapack_int LAPACKE_sgeesx( int matrix_order, char jobvs, char sort, - LAPACK_S_SELECT2 select, char sense, lapack_int n, - float* a, lapack_int lda, lapack_int* sdim, - float* wr, float* wi, float* vs, lapack_int ldvs, - float* rconde, float* rcondv ); -lapack_int LAPACKE_dgeesx( int matrix_order, char jobvs, char sort, - LAPACK_D_SELECT2 select, char sense, lapack_int n, - double* a, lapack_int lda, lapack_int* sdim, - double* wr, double* wi, double* vs, lapack_int ldvs, - double* rconde, double* rcondv ); -lapack_int LAPACKE_cgeesx( int matrix_order, char jobvs, char sort, - LAPACK_C_SELECT1 select, char sense, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* sdim, lapack_complex_float* w, - lapack_complex_float* vs, lapack_int ldvs, - float* rconde, float* rcondv ); -lapack_int LAPACKE_zgeesx( int matrix_order, char jobvs, char sort, - LAPACK_Z_SELECT1 select, char sense, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* sdim, lapack_complex_double* w, - lapack_complex_double* vs, lapack_int ldvs, - double* rconde, double* rcondv ); - -lapack_int LAPACKE_sgeev( int matrix_order, char jobvl, char jobvr, - lapack_int n, float* a, lapack_int lda, float* wr, - float* wi, float* vl, lapack_int ldvl, float* vr, - lapack_int ldvr ); -lapack_int LAPACKE_dgeev( int matrix_order, char jobvl, char jobvr, - lapack_int n, double* a, lapack_int lda, double* wr, - double* wi, double* vl, lapack_int ldvl, double* vr, - lapack_int ldvr ); -lapack_int LAPACKE_cgeev( int matrix_order, char jobvl, char jobvr, - lapack_int n, lapack_complex_float* a, lapack_int lda, - lapack_complex_float* w, lapack_complex_float* vl, - lapack_int ldvl, lapack_complex_float* vr, - lapack_int ldvr ); -lapack_int LAPACKE_zgeev( int matrix_order, char jobvl, char jobvr, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* w, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr ); - -lapack_int LAPACKE_sgeevx( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, float* a, - lapack_int lda, float* wr, float* wi, float* vl, - lapack_int ldvl, float* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, float* scale, - float* abnrm, float* rconde, float* rcondv ); -lapack_int LAPACKE_dgeevx( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, double* a, - lapack_int lda, double* wr, double* wi, double* vl, - lapack_int ldvl, double* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, double* scale, - double* abnrm, double* rconde, double* rcondv ); -lapack_int LAPACKE_cgeevx( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* w, lapack_complex_float* vl, - lapack_int ldvl, lapack_complex_float* vr, - lapack_int ldvr, lapack_int* ilo, lapack_int* ihi, - float* scale, float* abnrm, float* rconde, - float* rcondv ); -lapack_int LAPACKE_zgeevx( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* w, lapack_complex_double* vl, - lapack_int ldvl, lapack_complex_double* vr, - lapack_int ldvr, lapack_int* ilo, lapack_int* ihi, - double* scale, double* abnrm, double* rconde, - double* rcondv ); - -lapack_int LAPACKE_sgehrd( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, float* a, lapack_int lda, - float* tau ); -lapack_int LAPACKE_dgehrd( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, double* a, lapack_int lda, - double* tau ); -lapack_int LAPACKE_cgehrd( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* tau ); -lapack_int LAPACKE_zgehrd( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* tau ); - -lapack_int LAPACKE_sgejsv( int matrix_order, char joba, char jobu, char jobv, - char jobr, char jobt, char jobp, lapack_int m, - lapack_int n, float* a, lapack_int lda, float* sva, - float* u, lapack_int ldu, float* v, lapack_int ldv, - float* stat, lapack_int* istat ); -lapack_int LAPACKE_dgejsv( int matrix_order, char joba, char jobu, char jobv, - char jobr, char jobt, char jobp, lapack_int m, - lapack_int n, double* a, lapack_int lda, double* sva, - double* u, lapack_int ldu, double* v, lapack_int ldv, - double* stat, lapack_int* istat ); - -lapack_int LAPACKE_sgelq2( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau ); -lapack_int LAPACKE_dgelq2( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau ); -lapack_int LAPACKE_cgelq2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau ); -lapack_int LAPACKE_zgelq2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau ); - -lapack_int LAPACKE_sgelqf( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau ); -lapack_int LAPACKE_dgelqf( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau ); -lapack_int LAPACKE_cgelqf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau ); -lapack_int LAPACKE_zgelqf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau ); - -lapack_int LAPACKE_sgels( int matrix_order, char trans, lapack_int m, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* b, lapack_int ldb ); -lapack_int LAPACKE_dgels( int matrix_order, char trans, lapack_int m, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* b, lapack_int ldb ); -lapack_int LAPACKE_cgels( int matrix_order, char trans, lapack_int m, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zgels( int matrix_order, char trans, lapack_int m, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sgelsd( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, float* b, - lapack_int ldb, float* s, float rcond, - lapack_int* rank ); -lapack_int LAPACKE_dgelsd( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb, double* s, double rcond, - lapack_int* rank ); -lapack_int LAPACKE_cgelsd( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float* s, float rcond, - lapack_int* rank ); -lapack_int LAPACKE_zgelsd( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, double* s, double rcond, - lapack_int* rank ); - -lapack_int LAPACKE_sgelss( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, float* b, - lapack_int ldb, float* s, float rcond, - lapack_int* rank ); -lapack_int LAPACKE_dgelss( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb, double* s, double rcond, - lapack_int* rank ); -lapack_int LAPACKE_cgelss( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float* s, float rcond, - lapack_int* rank ); -lapack_int LAPACKE_zgelss( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, double* s, double rcond, - lapack_int* rank ); - -lapack_int LAPACKE_sgelsy( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, float* b, - lapack_int ldb, lapack_int* jpvt, float rcond, - lapack_int* rank ); -lapack_int LAPACKE_dgelsy( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb, lapack_int* jpvt, - double rcond, lapack_int* rank ); -lapack_int LAPACKE_cgelsy( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_int* jpvt, float rcond, - lapack_int* rank ); -lapack_int LAPACKE_zgelsy( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_int* jpvt, double rcond, - lapack_int* rank ); - -lapack_int LAPACKE_sgeqlf( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau ); -lapack_int LAPACKE_dgeqlf( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau ); -lapack_int LAPACKE_cgeqlf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau ); -lapack_int LAPACKE_zgeqlf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau ); - -lapack_int LAPACKE_sgeqp3( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, lapack_int* jpvt, - float* tau ); -lapack_int LAPACKE_dgeqp3( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, lapack_int* jpvt, - double* tau ); -lapack_int LAPACKE_cgeqp3( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* jpvt, lapack_complex_float* tau ); -lapack_int LAPACKE_zgeqp3( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* jpvt, lapack_complex_double* tau ); - -lapack_int LAPACKE_sgeqpf( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, lapack_int* jpvt, - float* tau ); -lapack_int LAPACKE_dgeqpf( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, lapack_int* jpvt, - double* tau ); -lapack_int LAPACKE_cgeqpf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* jpvt, lapack_complex_float* tau ); -lapack_int LAPACKE_zgeqpf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* jpvt, lapack_complex_double* tau ); - -lapack_int LAPACKE_sgeqr2( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau ); -lapack_int LAPACKE_dgeqr2( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau ); -lapack_int LAPACKE_cgeqr2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau ); -lapack_int LAPACKE_zgeqr2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau ); - -lapack_int LAPACKE_sgeqrf( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau ); -lapack_int LAPACKE_dgeqrf( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau ); -lapack_int LAPACKE_cgeqrf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau ); -lapack_int LAPACKE_zgeqrf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau ); - -lapack_int LAPACKE_sgeqrfp( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau ); -lapack_int LAPACKE_dgeqrfp( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau ); -lapack_int LAPACKE_cgeqrfp( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau ); -lapack_int LAPACKE_zgeqrfp( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau ); - -lapack_int LAPACKE_sgerfs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_dgerfs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const double* a, lapack_int lda, - const double* af, lapack_int ldaf, - const lapack_int* ipiv, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* ferr, double* berr ); -lapack_int LAPACKE_cgerfs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zgerfs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_sgerfsx( int matrix_order, char trans, char equed, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, const float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* r, - const float* c, const float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_dgerfsx( int matrix_order, char trans, char equed, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, const double* af, lapack_int ldaf, - const lapack_int* ipiv, const double* r, - const double* c, const double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); -lapack_int LAPACKE_cgerfsx( int matrix_order, char trans, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* r, - const float* c, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_zgerfsx( int matrix_order, char trans, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* af, lapack_int ldaf, - const lapack_int* ipiv, const double* r, - const double* c, const lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params ); - -lapack_int LAPACKE_sgerqf( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau ); -lapack_int LAPACKE_dgerqf( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau ); -lapack_int LAPACKE_cgerqf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau ); -lapack_int LAPACKE_zgerqf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau ); - -lapack_int LAPACKE_sgesdd( int matrix_order, char jobz, lapack_int m, - lapack_int n, float* a, lapack_int lda, float* s, - float* u, lapack_int ldu, float* vt, - lapack_int ldvt ); -lapack_int LAPACKE_dgesdd( int matrix_order, char jobz, lapack_int m, - lapack_int n, double* a, lapack_int lda, double* s, - double* u, lapack_int ldu, double* vt, - lapack_int ldvt ); -lapack_int LAPACKE_cgesdd( int matrix_order, char jobz, lapack_int m, - lapack_int n, lapack_complex_float* a, - lapack_int lda, float* s, lapack_complex_float* u, - lapack_int ldu, lapack_complex_float* vt, - lapack_int ldvt ); -lapack_int LAPACKE_zgesdd( int matrix_order, char jobz, lapack_int m, - lapack_int n, lapack_complex_double* a, - lapack_int lda, double* s, lapack_complex_double* u, - lapack_int ldu, lapack_complex_double* vt, - lapack_int ldvt ); - -lapack_int LAPACKE_sgesv( int matrix_order, lapack_int n, lapack_int nrhs, - float* a, lapack_int lda, lapack_int* ipiv, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dgesv( int matrix_order, lapack_int n, lapack_int nrhs, - double* a, lapack_int lda, lapack_int* ipiv, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cgesv( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgesv( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); -lapack_int LAPACKE_dsgesv( int matrix_order, lapack_int n, lapack_int nrhs, - double* a, lapack_int lda, lapack_int* ipiv, - double* b, lapack_int ldb, double* x, lapack_int ldx, - lapack_int* iter ); -lapack_int LAPACKE_zcgesv( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, lapack_int* iter ); - -lapack_int LAPACKE_sgesvd( int matrix_order, char jobu, char jobvt, - lapack_int m, lapack_int n, float* a, lapack_int lda, - float* s, float* u, lapack_int ldu, float* vt, - lapack_int ldvt, float* superb ); -lapack_int LAPACKE_dgesvd( int matrix_order, char jobu, char jobvt, - lapack_int m, lapack_int n, double* a, - lapack_int lda, double* s, double* u, lapack_int ldu, - double* vt, lapack_int ldvt, double* superb ); -lapack_int LAPACKE_cgesvd( int matrix_order, char jobu, char jobvt, - lapack_int m, lapack_int n, lapack_complex_float* a, - lapack_int lda, float* s, lapack_complex_float* u, - lapack_int ldu, lapack_complex_float* vt, - lapack_int ldvt, float* superb ); -lapack_int LAPACKE_zgesvd( int matrix_order, char jobu, char jobvt, - lapack_int m, lapack_int n, lapack_complex_double* a, - lapack_int lda, double* s, lapack_complex_double* u, - lapack_int ldu, lapack_complex_double* vt, - lapack_int ldvt, double* superb ); - -lapack_int LAPACKE_sgesvj( int matrix_order, char joba, char jobu, char jobv, - lapack_int m, lapack_int n, float* a, lapack_int lda, - float* sva, lapack_int mv, float* v, lapack_int ldv, - float* stat ); -lapack_int LAPACKE_dgesvj( int matrix_order, char joba, char jobu, char jobv, - lapack_int m, lapack_int n, double* a, - lapack_int lda, double* sva, lapack_int mv, - double* v, lapack_int ldv, double* stat ); - -lapack_int LAPACKE_sgesvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* r, float* c, - float* b, lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* rpivot ); -lapack_int LAPACKE_dgesvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* r, double* c, - double* b, lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* rpivot ); -lapack_int LAPACKE_cgesvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* r, float* c, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* rpivot ); -lapack_int LAPACKE_zgesvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* r, double* c, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* rpivot ); - -lapack_int LAPACKE_sgesvxx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* r, float* c, - float* b, lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_dgesvxx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* r, double* c, - double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* rpvgrw, - double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); -lapack_int LAPACKE_cgesvxx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* r, float* c, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_zgesvxx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* r, double* c, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params ); - -lapack_int LAPACKE_sgetf2( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_dgetf2( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_cgetf2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv ); -lapack_int LAPACKE_zgetf2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv ); - -lapack_int LAPACKE_sgetrf( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_dgetrf( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_cgetrf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv ); -lapack_int LAPACKE_zgetrf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv ); - -lapack_int LAPACKE_sgetri( int matrix_order, lapack_int n, float* a, - lapack_int lda, const lapack_int* ipiv ); -lapack_int LAPACKE_dgetri( int matrix_order, lapack_int n, double* a, - lapack_int lda, const lapack_int* ipiv ); -lapack_int LAPACKE_cgetri( int matrix_order, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_zgetri( int matrix_order, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv ); - -lapack_int LAPACKE_sgetrs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const lapack_int* ipiv, float* b, lapack_int ldb ); -lapack_int LAPACKE_dgetrs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const double* a, lapack_int lda, - const lapack_int* ipiv, double* b, lapack_int ldb ); -lapack_int LAPACKE_cgetrs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zgetrs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sggbak( int matrix_order, char job, char side, lapack_int n, - lapack_int ilo, lapack_int ihi, const float* lscale, - const float* rscale, lapack_int m, float* v, - lapack_int ldv ); -lapack_int LAPACKE_dggbak( int matrix_order, char job, char side, lapack_int n, - lapack_int ilo, lapack_int ihi, const double* lscale, - const double* rscale, lapack_int m, double* v, - lapack_int ldv ); -lapack_int LAPACKE_cggbak( int matrix_order, char job, char side, lapack_int n, - lapack_int ilo, lapack_int ihi, const float* lscale, - const float* rscale, lapack_int m, - lapack_complex_float* v, lapack_int ldv ); -lapack_int LAPACKE_zggbak( int matrix_order, char job, char side, lapack_int n, - lapack_int ilo, lapack_int ihi, const double* lscale, - const double* rscale, lapack_int m, - lapack_complex_double* v, lapack_int ldv ); - -lapack_int LAPACKE_sggbal( int matrix_order, char job, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - lapack_int* ilo, lapack_int* ihi, float* lscale, - float* rscale ); -lapack_int LAPACKE_dggbal( int matrix_order, char job, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - lapack_int* ilo, lapack_int* ihi, double* lscale, - double* rscale ); -lapack_int LAPACKE_cggbal( int matrix_order, char job, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_int* ilo, lapack_int* ihi, float* lscale, - float* rscale ); -lapack_int LAPACKE_zggbal( int matrix_order, char job, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_int* ilo, lapack_int* ihi, double* lscale, - double* rscale ); - -lapack_int LAPACKE_sgges( int matrix_order, char jobvsl, char jobvsr, char sort, - LAPACK_S_SELECT3 selctg, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - lapack_int* sdim, float* alphar, float* alphai, - float* beta, float* vsl, lapack_int ldvsl, float* vsr, - lapack_int ldvsr ); -lapack_int LAPACKE_dgges( int matrix_order, char jobvsl, char jobvsr, char sort, - LAPACK_D_SELECT3 selctg, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - lapack_int* sdim, double* alphar, double* alphai, - double* beta, double* vsl, lapack_int ldvsl, - double* vsr, lapack_int ldvsr ); -lapack_int LAPACKE_cgges( int matrix_order, char jobvsl, char jobvsr, char sort, - LAPACK_C_SELECT2 selctg, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_int* sdim, lapack_complex_float* alpha, - lapack_complex_float* beta, lapack_complex_float* vsl, - lapack_int ldvsl, lapack_complex_float* vsr, - lapack_int ldvsr ); -lapack_int LAPACKE_zgges( int matrix_order, char jobvsl, char jobvsr, char sort, - LAPACK_Z_SELECT2 selctg, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_int* sdim, lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* vsl, lapack_int ldvsl, - lapack_complex_double* vsr, lapack_int ldvsr ); - -lapack_int LAPACKE_sggesx( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_S_SELECT3 selctg, char sense, - lapack_int n, float* a, lapack_int lda, float* b, - lapack_int ldb, lapack_int* sdim, float* alphar, - float* alphai, float* beta, float* vsl, - lapack_int ldvsl, float* vsr, lapack_int ldvsr, - float* rconde, float* rcondv ); -lapack_int LAPACKE_dggesx( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_D_SELECT3 selctg, char sense, - lapack_int n, double* a, lapack_int lda, double* b, - lapack_int ldb, lapack_int* sdim, double* alphar, - double* alphai, double* beta, double* vsl, - lapack_int ldvsl, double* vsr, lapack_int ldvsr, - double* rconde, double* rcondv ); -lapack_int LAPACKE_cggesx( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_C_SELECT2 selctg, char sense, - lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_int* sdim, - lapack_complex_float* alpha, - lapack_complex_float* beta, - lapack_complex_float* vsl, lapack_int ldvsl, - lapack_complex_float* vsr, lapack_int ldvsr, - float* rconde, float* rcondv ); -lapack_int LAPACKE_zggesx( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_Z_SELECT2 selctg, char sense, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_int* sdim, - lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* vsl, lapack_int ldvsl, - lapack_complex_double* vsr, lapack_int ldvsr, - double* rconde, double* rcondv ); - -lapack_int LAPACKE_sggev( int matrix_order, char jobvl, char jobvr, - lapack_int n, float* a, lapack_int lda, float* b, - lapack_int ldb, float* alphar, float* alphai, - float* beta, float* vl, lapack_int ldvl, float* vr, - lapack_int ldvr ); -lapack_int LAPACKE_dggev( int matrix_order, char jobvl, char jobvr, - lapack_int n, double* a, lapack_int lda, double* b, - lapack_int ldb, double* alphar, double* alphai, - double* beta, double* vl, lapack_int ldvl, double* vr, - lapack_int ldvr ); -lapack_int LAPACKE_cggev( int matrix_order, char jobvl, char jobvr, - lapack_int n, lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* alpha, - lapack_complex_float* beta, lapack_complex_float* vl, - lapack_int ldvl, lapack_complex_float* vr, - lapack_int ldvr ); -lapack_int LAPACKE_zggev( int matrix_order, char jobvl, char jobvr, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr ); - -lapack_int LAPACKE_sggevx( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - float* alphar, float* alphai, float* beta, float* vl, - lapack_int ldvl, float* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, float* lscale, - float* rscale, float* abnrm, float* bbnrm, - float* rconde, float* rcondv ); -lapack_int LAPACKE_dggevx( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - double* alphar, double* alphai, double* beta, - double* vl, lapack_int ldvl, double* vr, - lapack_int ldvr, lapack_int* ilo, lapack_int* ihi, - double* lscale, double* rscale, double* abnrm, - double* bbnrm, double* rconde, double* rcondv ); -lapack_int LAPACKE_cggevx( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* alpha, - lapack_complex_float* beta, lapack_complex_float* vl, - lapack_int ldvl, lapack_complex_float* vr, - lapack_int ldvr, lapack_int* ilo, lapack_int* ihi, - float* lscale, float* rscale, float* abnrm, - float* bbnrm, float* rconde, float* rcondv ); -lapack_int LAPACKE_zggevx( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, double* lscale, - double* rscale, double* abnrm, double* bbnrm, - double* rconde, double* rcondv ); - -lapack_int LAPACKE_sggglm( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, float* a, lapack_int lda, float* b, - lapack_int ldb, float* d, float* x, float* y ); -lapack_int LAPACKE_dggglm( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, double* a, lapack_int lda, double* b, - lapack_int ldb, double* d, double* x, double* y ); -lapack_int LAPACKE_cggglm( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* d, - lapack_complex_float* x, lapack_complex_float* y ); -lapack_int LAPACKE_zggglm( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* d, - lapack_complex_double* x, lapack_complex_double* y ); - -lapack_int LAPACKE_sgghrd( int matrix_order, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - float* a, lapack_int lda, float* b, lapack_int ldb, - float* q, lapack_int ldq, float* z, lapack_int ldz ); -lapack_int LAPACKE_dgghrd( int matrix_order, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - double* a, lapack_int lda, double* b, lapack_int ldb, - double* q, lapack_int ldq, double* z, - lapack_int ldz ); -lapack_int LAPACKE_cgghrd( int matrix_order, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zgghrd( int matrix_order, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* z, lapack_int ldz ); - -lapack_int LAPACKE_sgglse( int matrix_order, lapack_int m, lapack_int n, - lapack_int p, float* a, lapack_int lda, float* b, - lapack_int ldb, float* c, float* d, float* x ); -lapack_int LAPACKE_dgglse( int matrix_order, lapack_int m, lapack_int n, - lapack_int p, double* a, lapack_int lda, double* b, - lapack_int ldb, double* c, double* d, double* x ); -lapack_int LAPACKE_cgglse( int matrix_order, lapack_int m, lapack_int n, - lapack_int p, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* c, - lapack_complex_float* d, lapack_complex_float* x ); -lapack_int LAPACKE_zgglse( int matrix_order, lapack_int m, lapack_int n, - lapack_int p, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* c, - lapack_complex_double* d, lapack_complex_double* x ); - -lapack_int LAPACKE_sggqrf( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, float* a, lapack_int lda, float* taua, - float* b, lapack_int ldb, float* taub ); -lapack_int LAPACKE_dggqrf( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, double* a, lapack_int lda, - double* taua, double* b, lapack_int ldb, - double* taub ); -lapack_int LAPACKE_cggqrf( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* taua, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* taub ); -lapack_int LAPACKE_zggqrf( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* taua, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* taub ); - -lapack_int LAPACKE_sggrqf( int matrix_order, lapack_int m, lapack_int p, - lapack_int n, float* a, lapack_int lda, float* taua, - float* b, lapack_int ldb, float* taub ); -lapack_int LAPACKE_dggrqf( int matrix_order, lapack_int m, lapack_int p, - lapack_int n, double* a, lapack_int lda, - double* taua, double* b, lapack_int ldb, - double* taub ); -lapack_int LAPACKE_cggrqf( int matrix_order, lapack_int m, lapack_int p, - lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* taua, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* taub ); -lapack_int LAPACKE_zggrqf( int matrix_order, lapack_int m, lapack_int p, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* taua, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* taub ); - -lapack_int LAPACKE_sggsvd( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int n, lapack_int p, - lapack_int* k, lapack_int* l, float* a, - lapack_int lda, float* b, lapack_int ldb, - float* alpha, float* beta, float* u, lapack_int ldu, - float* v, lapack_int ldv, float* q, lapack_int ldq, - lapack_int* iwork ); -lapack_int LAPACKE_dggsvd( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int n, lapack_int p, - lapack_int* k, lapack_int* l, double* a, - lapack_int lda, double* b, lapack_int ldb, - double* alpha, double* beta, double* u, - lapack_int ldu, double* v, lapack_int ldv, double* q, - lapack_int ldq, lapack_int* iwork ); -lapack_int LAPACKE_cggsvd( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int n, lapack_int p, - lapack_int* k, lapack_int* l, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - float* alpha, float* beta, lapack_complex_float* u, - lapack_int ldu, lapack_complex_float* v, - lapack_int ldv, lapack_complex_float* q, - lapack_int ldq, lapack_int* iwork ); -lapack_int LAPACKE_zggsvd( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int n, lapack_int p, - lapack_int* k, lapack_int* l, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - double* alpha, double* beta, - lapack_complex_double* u, lapack_int ldu, - lapack_complex_double* v, lapack_int ldv, - lapack_complex_double* q, lapack_int ldq, - lapack_int* iwork ); - -lapack_int LAPACKE_sggsvp( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int p, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, float tola, - float tolb, lapack_int* k, lapack_int* l, float* u, - lapack_int ldu, float* v, lapack_int ldv, float* q, - lapack_int ldq ); -lapack_int LAPACKE_dggsvp( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int p, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - double tola, double tolb, lapack_int* k, - lapack_int* l, double* u, lapack_int ldu, double* v, - lapack_int ldv, double* q, lapack_int ldq ); -lapack_int LAPACKE_cggsvp( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int p, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, float tola, - float tolb, lapack_int* k, lapack_int* l, - lapack_complex_float* u, lapack_int ldu, - lapack_complex_float* v, lapack_int ldv, - lapack_complex_float* q, lapack_int ldq ); -lapack_int LAPACKE_zggsvp( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int p, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - double tola, double tolb, lapack_int* k, - lapack_int* l, lapack_complex_double* u, - lapack_int ldu, lapack_complex_double* v, - lapack_int ldv, lapack_complex_double* q, - lapack_int ldq ); - -lapack_int LAPACKE_sgtcon( char norm, lapack_int n, const float* dl, - const float* d, const float* du, const float* du2, - const lapack_int* ipiv, float anorm, float* rcond ); -lapack_int LAPACKE_dgtcon( char norm, lapack_int n, const double* dl, - const double* d, const double* du, const double* du2, - const lapack_int* ipiv, double anorm, - double* rcond ); -lapack_int LAPACKE_cgtcon( char norm, lapack_int n, - const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* du2, - const lapack_int* ipiv, float anorm, float* rcond ); -lapack_int LAPACKE_zgtcon( char norm, lapack_int n, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* du2, - const lapack_int* ipiv, double anorm, - double* rcond ); - -lapack_int LAPACKE_sgtrfs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const float* dl, const float* d, - const float* du, const float* dlf, const float* df, - const float* duf, const float* du2, - const lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_dgtrfs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const double* dl, const double* d, - const double* du, const double* dlf, - const double* df, const double* duf, - const double* du2, const lapack_int* ipiv, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr ); -lapack_int LAPACKE_cgtrfs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* dlf, - const lapack_complex_float* df, - const lapack_complex_float* duf, - const lapack_complex_float* du2, - const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zgtrfs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* dlf, - const lapack_complex_double* df, - const lapack_complex_double* duf, - const lapack_complex_double* du2, - const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_sgtsv( int matrix_order, lapack_int n, lapack_int nrhs, - float* dl, float* d, float* du, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dgtsv( int matrix_order, lapack_int n, lapack_int nrhs, - double* dl, double* d, double* du, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cgtsv( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_float* dl, lapack_complex_float* d, - lapack_complex_float* du, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgtsv( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_double* dl, lapack_complex_double* d, - lapack_complex_double* du, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sgtsvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, const float* dl, - const float* d, const float* du, float* dlf, - float* df, float* duf, float* du2, lapack_int* ipiv, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr ); -lapack_int LAPACKE_dgtsvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, const double* dl, - const double* d, const double* du, double* dlf, - double* df, double* duf, double* du2, - lapack_int* ipiv, const double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* ferr, double* berr ); -lapack_int LAPACKE_cgtsvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - lapack_complex_float* dlf, lapack_complex_float* df, - lapack_complex_float* duf, lapack_complex_float* du2, - lapack_int* ipiv, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr ); -lapack_int LAPACKE_zgtsvx( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - lapack_complex_double* dlf, - lapack_complex_double* df, - lapack_complex_double* duf, - lapack_complex_double* du2, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); - -lapack_int LAPACKE_sgttrf( lapack_int n, float* dl, float* d, float* du, - float* du2, lapack_int* ipiv ); -lapack_int LAPACKE_dgttrf( lapack_int n, double* dl, double* d, double* du, - double* du2, lapack_int* ipiv ); -lapack_int LAPACKE_cgttrf( lapack_int n, lapack_complex_float* dl, - lapack_complex_float* d, lapack_complex_float* du, - lapack_complex_float* du2, lapack_int* ipiv ); -lapack_int LAPACKE_zgttrf( lapack_int n, lapack_complex_double* dl, - lapack_complex_double* d, lapack_complex_double* du, - lapack_complex_double* du2, lapack_int* ipiv ); - -lapack_int LAPACKE_sgttrs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const float* dl, const float* d, - const float* du, const float* du2, - const lapack_int* ipiv, float* b, lapack_int ldb ); -lapack_int LAPACKE_dgttrs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const double* dl, const double* d, - const double* du, const double* du2, - const lapack_int* ipiv, double* b, lapack_int ldb ); -lapack_int LAPACKE_cgttrs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* du2, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgttrs( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* du2, - const lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_chbev( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int kd, lapack_complex_float* ab, - lapack_int ldab, float* w, lapack_complex_float* z, - lapack_int ldz ); -lapack_int LAPACKE_zhbev( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int kd, lapack_complex_double* ab, - lapack_int ldab, double* w, lapack_complex_double* z, - lapack_int ldz ); - -lapack_int LAPACKE_chbevd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int kd, lapack_complex_float* ab, - lapack_int ldab, float* w, lapack_complex_float* z, - lapack_int ldz ); -lapack_int LAPACKE_zhbevd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int kd, lapack_complex_double* ab, - lapack_int ldab, double* w, lapack_complex_double* z, - lapack_int ldz ); - -lapack_int LAPACKE_chbevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_int kd, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* q, lapack_int ldq, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int ldz, lapack_int* ifail ); -lapack_int LAPACKE_zhbevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_int kd, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* q, lapack_int ldq, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_int* ifail ); - -lapack_int LAPACKE_chbgst( int matrix_order, char vect, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, - lapack_complex_float* ab, lapack_int ldab, - const lapack_complex_float* bb, lapack_int ldbb, - lapack_complex_float* x, lapack_int ldx ); -lapack_int LAPACKE_zhbgst( int matrix_order, char vect, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, - lapack_complex_double* ab, lapack_int ldab, - const lapack_complex_double* bb, lapack_int ldbb, - lapack_complex_double* x, lapack_int ldx ); - -lapack_int LAPACKE_chbgv( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* bb, lapack_int ldbb, float* w, - lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zhbgv( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* bb, lapack_int ldbb, double* w, - lapack_complex_double* z, lapack_int ldz ); - -lapack_int LAPACKE_chbgvd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* bb, lapack_int ldbb, float* w, - lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zhbgvd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* bb, lapack_int ldbb, - double* w, lapack_complex_double* z, - lapack_int ldz ); - -lapack_int LAPACKE_chbgvx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* bb, lapack_int ldbb, - lapack_complex_float* q, lapack_int ldq, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int ldz, lapack_int* ifail ); -lapack_int LAPACKE_zhbgvx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* bb, lapack_int ldbb, - lapack_complex_double* q, lapack_int ldq, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_int* ifail ); - -lapack_int LAPACKE_chbtrd( int matrix_order, char vect, char uplo, lapack_int n, - lapack_int kd, lapack_complex_float* ab, - lapack_int ldab, float* d, float* e, - lapack_complex_float* q, lapack_int ldq ); -lapack_int LAPACKE_zhbtrd( int matrix_order, char vect, char uplo, lapack_int n, - lapack_int kd, lapack_complex_double* ab, - lapack_int ldab, double* d, double* e, - lapack_complex_double* q, lapack_int ldq ); - -lapack_int LAPACKE_checon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, float anorm, float* rcond ); -lapack_int LAPACKE_zhecon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, double anorm, - double* rcond ); - -lapack_int LAPACKE_cheequb( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* s, float* scond, float* amax ); -lapack_int LAPACKE_zheequb( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* s, double* scond, double* amax ); - -lapack_int LAPACKE_cheev( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, float* w ); -lapack_int LAPACKE_zheev( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, double* w ); - -lapack_int LAPACKE_cheevd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, float* w ); -lapack_int LAPACKE_zheevd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - double* w ); - -lapack_int LAPACKE_cheevr( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_complex_float* a, - lapack_int lda, float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_int* isuppz ); -lapack_int LAPACKE_zheevr( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_complex_double* a, - lapack_int lda, double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, lapack_complex_double* z, lapack_int ldz, - lapack_int* isuppz ); - -lapack_int LAPACKE_cheevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_complex_float* a, - lapack_int lda, float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_int* ifail ); -lapack_int LAPACKE_zheevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_complex_double* a, - lapack_int lda, double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, lapack_complex_double* z, lapack_int ldz, - lapack_int* ifail ); - -lapack_int LAPACKE_chegst( int matrix_order, lapack_int itype, char uplo, - lapack_int n, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zhegst( int matrix_order, lapack_int itype, char uplo, - lapack_int n, lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_chegv( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float* w ); -lapack_int LAPACKE_zhegv( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, double* w ); - -lapack_int LAPACKE_chegvd( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float* w ); -lapack_int LAPACKE_zhegvd( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, double* w ); - -lapack_int LAPACKE_chegvx( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int ldz, lapack_int* ifail ); -lapack_int LAPACKE_zhegvx( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_int* ifail ); - -lapack_int LAPACKE_cherfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zherfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_cherfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* s, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params ); -lapack_int LAPACKE_zherfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* af, lapack_int ldaf, - const lapack_int* ipiv, const double* s, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); - -lapack_int LAPACKE_chesv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zhesv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_chesvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, lapack_complex_float* af, - lapack_int ldaf, lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr ); -lapack_int LAPACKE_zhesvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, lapack_complex_double* af, - lapack_int ldaf, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); - -lapack_int LAPACKE_chesvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* s, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_zhesvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params ); - -lapack_int LAPACKE_chetrd( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, float* d, - float* e, lapack_complex_float* tau ); -lapack_int LAPACKE_zhetrd( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, double* d, - double* e, lapack_complex_double* tau ); - -lapack_int LAPACKE_chetrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv ); -lapack_int LAPACKE_zhetrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv ); - -lapack_int LAPACKE_chetri( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_zhetri( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv ); - -lapack_int LAPACKE_chetrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zhetrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_chfrk( int matrix_order, char transr, char uplo, char trans, - lapack_int n, lapack_int k, float alpha, - const lapack_complex_float* a, lapack_int lda, - float beta, lapack_complex_float* c ); -lapack_int LAPACKE_zhfrk( int matrix_order, char transr, char uplo, char trans, - lapack_int n, lapack_int k, double alpha, - const lapack_complex_double* a, lapack_int lda, - double beta, lapack_complex_double* c ); - -lapack_int LAPACKE_shgeqz( int matrix_order, char job, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - float* h, lapack_int ldh, float* t, lapack_int ldt, - float* alphar, float* alphai, float* beta, float* q, - lapack_int ldq, float* z, lapack_int ldz ); -lapack_int LAPACKE_dhgeqz( int matrix_order, char job, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - double* h, lapack_int ldh, double* t, lapack_int ldt, - double* alphar, double* alphai, double* beta, - double* q, lapack_int ldq, double* z, - lapack_int ldz ); -lapack_int LAPACKE_chgeqz( int matrix_order, char job, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - lapack_complex_float* h, lapack_int ldh, - lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* alpha, - lapack_complex_float* beta, lapack_complex_float* q, - lapack_int ldq, lapack_complex_float* z, - lapack_int ldz ); -lapack_int LAPACKE_zhgeqz( int matrix_order, char job, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - lapack_complex_double* h, lapack_int ldh, - lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* z, lapack_int ldz ); - -lapack_int LAPACKE_chpcon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, - const lapack_int* ipiv, float anorm, float* rcond ); -lapack_int LAPACKE_zhpcon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, - const lapack_int* ipiv, double anorm, - double* rcond ); - -lapack_int LAPACKE_chpev( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_complex_float* ap, float* w, - lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zhpev( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_complex_double* ap, double* w, - lapack_complex_double* z, lapack_int ldz ); - -lapack_int LAPACKE_chpevd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_complex_float* ap, float* w, - lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zhpevd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_complex_double* ap, double* w, - lapack_complex_double* z, lapack_int ldz ); - -lapack_int LAPACKE_chpevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_complex_float* ap, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int ldz, lapack_int* ifail ); -lapack_int LAPACKE_zhpevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_complex_double* ap, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_int* ifail ); - -lapack_int LAPACKE_chpgst( int matrix_order, lapack_int itype, char uplo, - lapack_int n, lapack_complex_float* ap, - const lapack_complex_float* bp ); -lapack_int LAPACKE_zhpgst( int matrix_order, lapack_int itype, char uplo, - lapack_int n, lapack_complex_double* ap, - const lapack_complex_double* bp ); - -lapack_int LAPACKE_chpgv( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_float* ap, - lapack_complex_float* bp, float* w, - lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zhpgv( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_double* ap, - lapack_complex_double* bp, double* w, - lapack_complex_double* z, lapack_int ldz ); - -lapack_int LAPACKE_chpgvd( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_float* ap, - lapack_complex_float* bp, float* w, - lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zhpgvd( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_double* ap, - lapack_complex_double* bp, double* w, - lapack_complex_double* z, lapack_int ldz ); - -lapack_int LAPACKE_chpgvx( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, - lapack_complex_float* ap, lapack_complex_float* bp, - float vl, float vu, lapack_int il, lapack_int iu, - float abstol, lapack_int* m, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_int* ifail ); -lapack_int LAPACKE_zhpgvx( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, - lapack_complex_double* ap, lapack_complex_double* bp, - double vl, double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_int* ifail ); - -lapack_int LAPACKE_chprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_complex_float* afp, - const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zhprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* ap, - const lapack_complex_double* afp, - const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_chpsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* ap, - lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zhpsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* ap, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_chpsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - lapack_complex_float* afp, lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr ); -lapack_int LAPACKE_zhpsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* ap, - lapack_complex_double* afp, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); - -lapack_int LAPACKE_chptrd( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, float* d, float* e, - lapack_complex_float* tau ); -lapack_int LAPACKE_zhptrd( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, double* d, double* e, - lapack_complex_double* tau ); - -lapack_int LAPACKE_chptrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, lapack_int* ipiv ); -lapack_int LAPACKE_zhptrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, lapack_int* ipiv ); - -lapack_int LAPACKE_chptri( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, const lapack_int* ipiv ); -lapack_int LAPACKE_zhptri( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, const lapack_int* ipiv ); - -lapack_int LAPACKE_chptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zhptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* ap, - const lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_shsein( int matrix_order, char job, char eigsrc, char initv, - lapack_logical* select, lapack_int n, const float* h, - lapack_int ldh, float* wr, const float* wi, - float* vl, lapack_int ldvl, float* vr, - lapack_int ldvr, lapack_int mm, lapack_int* m, - lapack_int* ifaill, lapack_int* ifailr ); -lapack_int LAPACKE_dhsein( int matrix_order, char job, char eigsrc, char initv, - lapack_logical* select, lapack_int n, - const double* h, lapack_int ldh, double* wr, - const double* wi, double* vl, lapack_int ldvl, - double* vr, lapack_int ldvr, lapack_int mm, - lapack_int* m, lapack_int* ifaill, - lapack_int* ifailr ); -lapack_int LAPACKE_chsein( int matrix_order, char job, char eigsrc, char initv, - const lapack_logical* select, lapack_int n, - const lapack_complex_float* h, lapack_int ldh, - lapack_complex_float* w, lapack_complex_float* vl, - lapack_int ldvl, lapack_complex_float* vr, - lapack_int ldvr, lapack_int mm, lapack_int* m, - lapack_int* ifaill, lapack_int* ifailr ); -lapack_int LAPACKE_zhsein( int matrix_order, char job, char eigsrc, char initv, - const lapack_logical* select, lapack_int n, - const lapack_complex_double* h, lapack_int ldh, - lapack_complex_double* w, lapack_complex_double* vl, - lapack_int ldvl, lapack_complex_double* vr, - lapack_int ldvr, lapack_int mm, lapack_int* m, - lapack_int* ifaill, lapack_int* ifailr ); - -lapack_int LAPACKE_shseqr( int matrix_order, char job, char compz, lapack_int n, - lapack_int ilo, lapack_int ihi, float* h, - lapack_int ldh, float* wr, float* wi, float* z, - lapack_int ldz ); -lapack_int LAPACKE_dhseqr( int matrix_order, char job, char compz, lapack_int n, - lapack_int ilo, lapack_int ihi, double* h, - lapack_int ldh, double* wr, double* wi, double* z, - lapack_int ldz ); -lapack_int LAPACKE_chseqr( int matrix_order, char job, char compz, lapack_int n, - lapack_int ilo, lapack_int ihi, - lapack_complex_float* h, lapack_int ldh, - lapack_complex_float* w, lapack_complex_float* z, - lapack_int ldz ); -lapack_int LAPACKE_zhseqr( int matrix_order, char job, char compz, lapack_int n, - lapack_int ilo, lapack_int ihi, - lapack_complex_double* h, lapack_int ldh, - lapack_complex_double* w, lapack_complex_double* z, - lapack_int ldz ); - -lapack_int LAPACKE_clacgv( lapack_int n, lapack_complex_float* x, - lapack_int incx ); -lapack_int LAPACKE_zlacgv( lapack_int n, lapack_complex_double* x, - lapack_int incx ); - -lapack_int LAPACKE_slacpy( int matrix_order, char uplo, lapack_int m, - lapack_int n, const float* a, lapack_int lda, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dlacpy( int matrix_order, char uplo, lapack_int m, - lapack_int n, const double* a, lapack_int lda, double* b, - lapack_int ldb ); -lapack_int LAPACKE_clacpy( int matrix_order, char uplo, lapack_int m, - lapack_int n, const lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zlacpy( int matrix_order, char uplo, lapack_int m, - lapack_int n, const lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_zlag2c( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - lapack_complex_float* sa, lapack_int ldsa ); - -lapack_int LAPACKE_slag2d( int matrix_order, lapack_int m, lapack_int n, - const float* sa, lapack_int ldsa, double* a, - lapack_int lda ); - -lapack_int LAPACKE_dlag2s( int matrix_order, lapack_int m, lapack_int n, - const double* a, lapack_int lda, float* sa, - lapack_int ldsa ); - -lapack_int LAPACKE_clag2z( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_float* sa, lapack_int ldsa, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_slagge( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const float* d, - float* a, lapack_int lda, lapack_int* iseed ); -lapack_int LAPACKE_dlagge( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const double* d, - double* a, lapack_int lda, lapack_int* iseed ); -lapack_int LAPACKE_clagge( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const float* d, - lapack_complex_float* a, lapack_int lda, - lapack_int* iseed ); -lapack_int LAPACKE_zlagge( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const double* d, - lapack_complex_double* a, lapack_int lda, - lapack_int* iseed ); - -float LAPACKE_slamch( char cmach ); -double LAPACKE_dlamch( char cmach ); - -float LAPACKE_slange( int matrix_order, char norm, lapack_int m, - lapack_int n, const float* a, lapack_int lda ); -double LAPACKE_dlange( int matrix_order, char norm, lapack_int m, - lapack_int n, const double* a, lapack_int lda ); -float LAPACKE_clange( int matrix_order, char norm, lapack_int m, - lapack_int n, const lapack_complex_float* a, - lapack_int lda ); -double LAPACKE_zlange( int matrix_order, char norm, lapack_int m, - lapack_int n, const lapack_complex_double* a, - lapack_int lda ); - -float LAPACKE_clanhe( int matrix_order, char norm, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda ); -double LAPACKE_zlanhe( int matrix_order, char norm, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda ); - -float LAPACKE_slansy( int matrix_order, char norm, char uplo, lapack_int n, - const float* a, lapack_int lda ); -double LAPACKE_dlansy( int matrix_order, char norm, char uplo, lapack_int n, - const double* a, lapack_int lda ); -float LAPACKE_clansy( int matrix_order, char norm, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda ); -double LAPACKE_zlansy( int matrix_order, char norm, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda ); - -float LAPACKE_slantr( int matrix_order, char norm, char uplo, char diag, - lapack_int m, lapack_int n, const float* a, - lapack_int lda ); -double LAPACKE_dlantr( int matrix_order, char norm, char uplo, char diag, - lapack_int m, lapack_int n, const double* a, - lapack_int lda ); -float LAPACKE_clantr( int matrix_order, char norm, char uplo, char diag, - lapack_int m, lapack_int n, const lapack_complex_float* a, - lapack_int lda ); -double LAPACKE_zlantr( int matrix_order, char norm, char uplo, char diag, - lapack_int m, lapack_int n, const lapack_complex_double* a, - lapack_int lda ); - - -lapack_int LAPACKE_slarfb( int matrix_order, char side, char trans, char direct, - char storev, lapack_int m, lapack_int n, - lapack_int k, const float* v, lapack_int ldv, - const float* t, lapack_int ldt, float* c, - lapack_int ldc ); -lapack_int LAPACKE_dlarfb( int matrix_order, char side, char trans, char direct, - char storev, lapack_int m, lapack_int n, - lapack_int k, const double* v, lapack_int ldv, - const double* t, lapack_int ldt, double* c, - lapack_int ldc ); -lapack_int LAPACKE_clarfb( int matrix_order, char side, char trans, char direct, - char storev, lapack_int m, lapack_int n, - lapack_int k, const lapack_complex_float* v, - lapack_int ldv, const lapack_complex_float* t, - lapack_int ldt, lapack_complex_float* c, - lapack_int ldc ); -lapack_int LAPACKE_zlarfb( int matrix_order, char side, char trans, char direct, - char storev, lapack_int m, lapack_int n, - lapack_int k, const lapack_complex_double* v, - lapack_int ldv, const lapack_complex_double* t, - lapack_int ldt, lapack_complex_double* c, - lapack_int ldc ); - -lapack_int LAPACKE_slarfg( lapack_int n, float* alpha, float* x, - lapack_int incx, float* tau ); -lapack_int LAPACKE_dlarfg( lapack_int n, double* alpha, double* x, - lapack_int incx, double* tau ); -lapack_int LAPACKE_clarfg( lapack_int n, lapack_complex_float* alpha, - lapack_complex_float* x, lapack_int incx, - lapack_complex_float* tau ); -lapack_int LAPACKE_zlarfg( lapack_int n, lapack_complex_double* alpha, - lapack_complex_double* x, lapack_int incx, - lapack_complex_double* tau ); - -lapack_int LAPACKE_slarft( int matrix_order, char direct, char storev, - lapack_int n, lapack_int k, const float* v, - lapack_int ldv, const float* tau, float* t, - lapack_int ldt ); -lapack_int LAPACKE_dlarft( int matrix_order, char direct, char storev, - lapack_int n, lapack_int k, const double* v, - lapack_int ldv, const double* tau, double* t, - lapack_int ldt ); -lapack_int LAPACKE_clarft( int matrix_order, char direct, char storev, - lapack_int n, lapack_int k, - const lapack_complex_float* v, lapack_int ldv, - const lapack_complex_float* tau, - lapack_complex_float* t, lapack_int ldt ); -lapack_int LAPACKE_zlarft( int matrix_order, char direct, char storev, - lapack_int n, lapack_int k, - const lapack_complex_double* v, lapack_int ldv, - const lapack_complex_double* tau, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_slarfx( int matrix_order, char side, lapack_int m, - lapack_int n, const float* v, float tau, float* c, - lapack_int ldc, float* work ); -lapack_int LAPACKE_dlarfx( int matrix_order, char side, lapack_int m, - lapack_int n, const double* v, double tau, double* c, - lapack_int ldc, double* work ); -lapack_int LAPACKE_clarfx( int matrix_order, char side, lapack_int m, - lapack_int n, const lapack_complex_float* v, - lapack_complex_float tau, lapack_complex_float* c, - lapack_int ldc, lapack_complex_float* work ); -lapack_int LAPACKE_zlarfx( int matrix_order, char side, lapack_int m, - lapack_int n, const lapack_complex_double* v, - lapack_complex_double tau, lapack_complex_double* c, - lapack_int ldc, lapack_complex_double* work ); - -lapack_int LAPACKE_slarnv( lapack_int idist, lapack_int* iseed, lapack_int n, - float* x ); -lapack_int LAPACKE_dlarnv( lapack_int idist, lapack_int* iseed, lapack_int n, - double* x ); -lapack_int LAPACKE_clarnv( lapack_int idist, lapack_int* iseed, lapack_int n, - lapack_complex_float* x ); -lapack_int LAPACKE_zlarnv( lapack_int idist, lapack_int* iseed, lapack_int n, - lapack_complex_double* x ); - -lapack_int LAPACKE_slaset( int matrix_order, char uplo, lapack_int m, - lapack_int n, float alpha, float beta, float* a, - lapack_int lda ); -lapack_int LAPACKE_dlaset( int matrix_order, char uplo, lapack_int m, - lapack_int n, double alpha, double beta, double* a, - lapack_int lda ); -lapack_int LAPACKE_claset( int matrix_order, char uplo, lapack_int m, - lapack_int n, lapack_complex_float alpha, - lapack_complex_float beta, lapack_complex_float* a, - lapack_int lda ); -lapack_int LAPACKE_zlaset( int matrix_order, char uplo, lapack_int m, - lapack_int n, lapack_complex_double alpha, - lapack_complex_double beta, lapack_complex_double* a, - lapack_int lda ); - -lapack_int LAPACKE_slasrt( char id, lapack_int n, float* d ); -lapack_int LAPACKE_dlasrt( char id, lapack_int n, double* d ); - -lapack_int LAPACKE_slaswp( int matrix_order, lapack_int n, float* a, - lapack_int lda, lapack_int k1, lapack_int k2, - const lapack_int* ipiv, lapack_int incx ); -lapack_int LAPACKE_dlaswp( int matrix_order, lapack_int n, double* a, - lapack_int lda, lapack_int k1, lapack_int k2, - const lapack_int* ipiv, lapack_int incx ); -lapack_int LAPACKE_claswp( int matrix_order, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int k1, lapack_int k2, const lapack_int* ipiv, - lapack_int incx ); -lapack_int LAPACKE_zlaswp( int matrix_order, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int k1, lapack_int k2, const lapack_int* ipiv, - lapack_int incx ); - -lapack_int LAPACKE_slatms( int matrix_order, lapack_int m, lapack_int n, - char dist, lapack_int* iseed, char sym, float* d, - lapack_int mode, float cond, float dmax, - lapack_int kl, lapack_int ku, char pack, float* a, - lapack_int lda ); -lapack_int LAPACKE_dlatms( int matrix_order, lapack_int m, lapack_int n, - char dist, lapack_int* iseed, char sym, double* d, - lapack_int mode, double cond, double dmax, - lapack_int kl, lapack_int ku, char pack, double* a, - lapack_int lda ); -lapack_int LAPACKE_clatms( int matrix_order, lapack_int m, lapack_int n, - char dist, lapack_int* iseed, char sym, float* d, - lapack_int mode, float cond, float dmax, - lapack_int kl, lapack_int ku, char pack, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zlatms( int matrix_order, lapack_int m, lapack_int n, - char dist, lapack_int* iseed, char sym, double* d, - lapack_int mode, double cond, double dmax, - lapack_int kl, lapack_int ku, char pack, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_slauum( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda ); -lapack_int LAPACKE_dlauum( int matrix_order, char uplo, lapack_int n, double* a, - lapack_int lda ); -lapack_int LAPACKE_clauum( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zlauum( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_sopgtr( int matrix_order, char uplo, lapack_int n, - const float* ap, const float* tau, float* q, - lapack_int ldq ); -lapack_int LAPACKE_dopgtr( int matrix_order, char uplo, lapack_int n, - const double* ap, const double* tau, double* q, - lapack_int ldq ); - -lapack_int LAPACKE_sopmtr( int matrix_order, char side, char uplo, char trans, - lapack_int m, lapack_int n, const float* ap, - const float* tau, float* c, lapack_int ldc ); -lapack_int LAPACKE_dopmtr( int matrix_order, char side, char uplo, char trans, - lapack_int m, lapack_int n, const double* ap, - const double* tau, double* c, lapack_int ldc ); - -lapack_int LAPACKE_sorgbr( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int k, float* a, lapack_int lda, - const float* tau ); -lapack_int LAPACKE_dorgbr( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int k, double* a, - lapack_int lda, const double* tau ); - -lapack_int LAPACKE_sorghr( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, float* a, lapack_int lda, - const float* tau ); -lapack_int LAPACKE_dorghr( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, double* a, lapack_int lda, - const double* tau ); - -lapack_int LAPACKE_sorglq( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, float* a, lapack_int lda, - const float* tau ); -lapack_int LAPACKE_dorglq( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, double* a, lapack_int lda, - const double* tau ); - -lapack_int LAPACKE_sorgql( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, float* a, lapack_int lda, - const float* tau ); -lapack_int LAPACKE_dorgql( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, double* a, lapack_int lda, - const double* tau ); - -lapack_int LAPACKE_sorgqr( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, float* a, lapack_int lda, - const float* tau ); -lapack_int LAPACKE_dorgqr( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, double* a, lapack_int lda, - const double* tau ); - -lapack_int LAPACKE_sorgrq( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, float* a, lapack_int lda, - const float* tau ); -lapack_int LAPACKE_dorgrq( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, double* a, lapack_int lda, - const double* tau ); - -lapack_int LAPACKE_sorgtr( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda, const float* tau ); -lapack_int LAPACKE_dorgtr( int matrix_order, char uplo, lapack_int n, double* a, - lapack_int lda, const double* tau ); - -lapack_int LAPACKE_sormbr( int matrix_order, char vect, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, const float* tau, - float* c, lapack_int ldc ); -lapack_int LAPACKE_dormbr( int matrix_order, char vect, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, const double* tau, - double* c, lapack_int ldc ); - -lapack_int LAPACKE_sormhr( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int ilo, - lapack_int ihi, const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc ); -lapack_int LAPACKE_dormhr( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int ilo, - lapack_int ihi, const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc ); - -lapack_int LAPACKE_sormlq( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, const float* tau, - float* c, lapack_int ldc ); -lapack_int LAPACKE_dormlq( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, const double* tau, - double* c, lapack_int ldc ); - -lapack_int LAPACKE_sormql( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, const float* tau, - float* c, lapack_int ldc ); -lapack_int LAPACKE_dormql( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, const double* tau, - double* c, lapack_int ldc ); - -lapack_int LAPACKE_sormqr( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, const float* tau, - float* c, lapack_int ldc ); -lapack_int LAPACKE_dormqr( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, const double* tau, - double* c, lapack_int ldc ); - -lapack_int LAPACKE_sormrq( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, const float* tau, - float* c, lapack_int ldc ); -lapack_int LAPACKE_dormrq( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, const double* tau, - double* c, lapack_int ldc ); - -lapack_int LAPACKE_sormrz( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc ); -lapack_int LAPACKE_dormrz( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc ); - -lapack_int LAPACKE_sormtr( int matrix_order, char side, char uplo, char trans, - lapack_int m, lapack_int n, const float* a, - lapack_int lda, const float* tau, float* c, - lapack_int ldc ); -lapack_int LAPACKE_dormtr( int matrix_order, char side, char uplo, char trans, - lapack_int m, lapack_int n, const double* a, - lapack_int lda, const double* tau, double* c, - lapack_int ldc ); - -lapack_int LAPACKE_spbcon( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const float* ab, lapack_int ldab, - float anorm, float* rcond ); -lapack_int LAPACKE_dpbcon( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const double* ab, lapack_int ldab, - double anorm, double* rcond ); -lapack_int LAPACKE_cpbcon( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const lapack_complex_float* ab, - lapack_int ldab, float anorm, float* rcond ); -lapack_int LAPACKE_zpbcon( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const lapack_complex_double* ab, - lapack_int ldab, double anorm, double* rcond ); - -lapack_int LAPACKE_spbequ( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const float* ab, lapack_int ldab, - float* s, float* scond, float* amax ); -lapack_int LAPACKE_dpbequ( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const double* ab, lapack_int ldab, - double* s, double* scond, double* amax ); -lapack_int LAPACKE_cpbequ( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const lapack_complex_float* ab, - lapack_int ldab, float* s, float* scond, - float* amax ); -lapack_int LAPACKE_zpbequ( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const lapack_complex_double* ab, - lapack_int ldab, double* s, double* scond, - double* amax ); - -lapack_int LAPACKE_spbrfs( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, const float* ab, - lapack_int ldab, const float* afb, lapack_int ldafb, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* ferr, float* berr ); -lapack_int LAPACKE_dpbrfs( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, const double* ab, - lapack_int ldab, const double* afb, lapack_int ldafb, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr ); -lapack_int LAPACKE_cpbrfs( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_complex_float* afb, lapack_int ldafb, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zpbrfs( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const lapack_complex_double* ab, lapack_int ldab, - const lapack_complex_double* afb, lapack_int ldafb, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_spbstf( int matrix_order, char uplo, lapack_int n, - lapack_int kb, float* bb, lapack_int ldbb ); -lapack_int LAPACKE_dpbstf( int matrix_order, char uplo, lapack_int n, - lapack_int kb, double* bb, lapack_int ldbb ); -lapack_int LAPACKE_cpbstf( int matrix_order, char uplo, lapack_int n, - lapack_int kb, lapack_complex_float* bb, - lapack_int ldbb ); -lapack_int LAPACKE_zpbstf( int matrix_order, char uplo, lapack_int n, - lapack_int kb, lapack_complex_double* bb, - lapack_int ldbb ); - -lapack_int LAPACKE_spbsv( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, float* ab, - lapack_int ldab, float* b, lapack_int ldb ); -lapack_int LAPACKE_dpbsv( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, double* ab, - lapack_int ldab, double* b, lapack_int ldb ); -lapack_int LAPACKE_cpbsv( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpbsv( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_spbsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, float* ab, - lapack_int ldab, float* afb, lapack_int ldafb, - char* equed, float* s, float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, float* ferr, - float* berr ); -lapack_int LAPACKE_dpbsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, double* ab, - lapack_int ldab, double* afb, lapack_int ldafb, - char* equed, double* s, double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* ferr, double* berr ); -lapack_int LAPACKE_cpbsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* afb, lapack_int ldafb, - char* equed, float* s, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr ); -lapack_int LAPACKE_zpbsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* afb, lapack_int ldafb, - char* equed, double* s, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr ); - -lapack_int LAPACKE_spbtrf( int matrix_order, char uplo, lapack_int n, - lapack_int kd, float* ab, lapack_int ldab ); -lapack_int LAPACKE_dpbtrf( int matrix_order, char uplo, lapack_int n, - lapack_int kd, double* ab, lapack_int ldab ); -lapack_int LAPACKE_cpbtrf( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_complex_float* ab, - lapack_int ldab ); -lapack_int LAPACKE_zpbtrf( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_complex_double* ab, - lapack_int ldab ); - -lapack_int LAPACKE_spbtrs( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, const float* ab, - lapack_int ldab, float* b, lapack_int ldb ); -lapack_int LAPACKE_dpbtrs( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, const double* ab, - lapack_int ldab, double* b, lapack_int ldb ); -lapack_int LAPACKE_cpbtrs( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpbtrs( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_spftrf( int matrix_order, char transr, char uplo, - lapack_int n, float* a ); -lapack_int LAPACKE_dpftrf( int matrix_order, char transr, char uplo, - lapack_int n, double* a ); -lapack_int LAPACKE_cpftrf( int matrix_order, char transr, char uplo, - lapack_int n, lapack_complex_float* a ); -lapack_int LAPACKE_zpftrf( int matrix_order, char transr, char uplo, - lapack_int n, lapack_complex_double* a ); - -lapack_int LAPACKE_spftri( int matrix_order, char transr, char uplo, - lapack_int n, float* a ); -lapack_int LAPACKE_dpftri( int matrix_order, char transr, char uplo, - lapack_int n, double* a ); -lapack_int LAPACKE_cpftri( int matrix_order, char transr, char uplo, - lapack_int n, lapack_complex_float* a ); -lapack_int LAPACKE_zpftri( int matrix_order, char transr, char uplo, - lapack_int n, lapack_complex_double* a ); - -lapack_int LAPACKE_spftrs( int matrix_order, char transr, char uplo, - lapack_int n, lapack_int nrhs, const float* a, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dpftrs( int matrix_order, char transr, char uplo, - lapack_int n, lapack_int nrhs, const double* a, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cpftrs( int matrix_order, char transr, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpftrs( int matrix_order, char transr, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_spocon( int matrix_order, char uplo, lapack_int n, - const float* a, lapack_int lda, float anorm, - float* rcond ); -lapack_int LAPACKE_dpocon( int matrix_order, char uplo, lapack_int n, - const double* a, lapack_int lda, double anorm, - double* rcond ); -lapack_int LAPACKE_cpocon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float anorm, float* rcond ); -lapack_int LAPACKE_zpocon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double anorm, double* rcond ); - -lapack_int LAPACKE_spoequ( int matrix_order, lapack_int n, const float* a, - lapack_int lda, float* s, float* scond, - float* amax ); -lapack_int LAPACKE_dpoequ( int matrix_order, lapack_int n, const double* a, - lapack_int lda, double* s, double* scond, - double* amax ); -lapack_int LAPACKE_cpoequ( int matrix_order, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* s, float* scond, float* amax ); -lapack_int LAPACKE_zpoequ( int matrix_order, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* s, double* scond, double* amax ); - -lapack_int LAPACKE_spoequb( int matrix_order, lapack_int n, const float* a, - lapack_int lda, float* s, float* scond, - float* amax ); -lapack_int LAPACKE_dpoequb( int matrix_order, lapack_int n, const double* a, - lapack_int lda, double* s, double* scond, - double* amax ); -lapack_int LAPACKE_cpoequb( int matrix_order, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* s, float* scond, float* amax ); -lapack_int LAPACKE_zpoequb( int matrix_order, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* s, double* scond, double* amax ); - -lapack_int LAPACKE_sporfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const float* af, lapack_int ldaf, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_dporfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, lapack_int lda, - const double* af, lapack_int ldaf, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* ferr, double* berr ); -lapack_int LAPACKE_cporfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* af, - lapack_int ldaf, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* ferr, float* berr ); -lapack_int LAPACKE_zporfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* af, - lapack_int ldaf, const lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* ferr, double* berr ); - -lapack_int LAPACKE_sporfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, const float* af, lapack_int ldaf, - const float* s, const float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_dporfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, const double* af, lapack_int ldaf, - const double* s, const double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); -lapack_int LAPACKE_cporfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* af, lapack_int ldaf, - const float* s, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_zporfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* af, lapack_int ldaf, - const double* s, const lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params ); - -lapack_int LAPACKE_sposv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dposv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cposv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zposv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb ); -lapack_int LAPACKE_dsposv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb, double* x, lapack_int ldx, - lapack_int* iter ); -lapack_int LAPACKE_zcposv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, lapack_int* iter ); - -lapack_int LAPACKE_sposvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, float* af, - lapack_int ldaf, char* equed, float* s, float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr ); -lapack_int LAPACKE_dposvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* af, lapack_int ldaf, char* equed, double* s, - double* b, lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); -lapack_int LAPACKE_cposvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* af, - lapack_int ldaf, char* equed, float* s, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr ); -lapack_int LAPACKE_zposvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* af, - lapack_int ldaf, char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); - -lapack_int LAPACKE_sposvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - char* equed, float* s, float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, - float* rpvgrw, float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params ); -lapack_int LAPACKE_dposvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - char* equed, double* s, double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* rpvgrw, double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); -lapack_int LAPACKE_cposvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - char* equed, float* s, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* rpvgrw, - float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params ); -lapack_int LAPACKE_zposvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - char* equed, double* s, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* rpvgrw, - double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); - -lapack_int LAPACKE_spotrf( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda ); -lapack_int LAPACKE_dpotrf( int matrix_order, char uplo, lapack_int n, double* a, - lapack_int lda ); -lapack_int LAPACKE_cpotrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zpotrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_spotri( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda ); -lapack_int LAPACKE_dpotri( int matrix_order, char uplo, lapack_int n, double* a, - lapack_int lda ); -lapack_int LAPACKE_cpotri( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zpotri( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_spotrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dpotrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, lapack_int lda, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cpotrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zpotrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sppcon( int matrix_order, char uplo, lapack_int n, - const float* ap, float anorm, float* rcond ); -lapack_int LAPACKE_dppcon( int matrix_order, char uplo, lapack_int n, - const double* ap, double anorm, double* rcond ); -lapack_int LAPACKE_cppcon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, float anorm, - float* rcond ); -lapack_int LAPACKE_zppcon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, double anorm, - double* rcond ); - -lapack_int LAPACKE_sppequ( int matrix_order, char uplo, lapack_int n, - const float* ap, float* s, float* scond, - float* amax ); -lapack_int LAPACKE_dppequ( int matrix_order, char uplo, lapack_int n, - const double* ap, double* s, double* scond, - double* amax ); -lapack_int LAPACKE_cppequ( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, float* s, - float* scond, float* amax ); -lapack_int LAPACKE_zppequ( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, double* s, - double* scond, double* amax ); - -lapack_int LAPACKE_spprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, const float* afp, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* ferr, float* berr ); -lapack_int LAPACKE_dpprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, const double* afp, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr ); -lapack_int LAPACKE_cpprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_complex_float* afp, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zpprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* ap, - const lapack_complex_double* afp, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_sppsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, float* ap, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dppsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* ap, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cppsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* ap, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zppsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* ap, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sppsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, float* ap, float* afp, char* equed, - float* s, float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr ); -lapack_int LAPACKE_dppsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, double* ap, double* afp, - char* equed, double* s, double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* ferr, double* berr ); -lapack_int LAPACKE_cppsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* ap, - lapack_complex_float* afp, char* equed, float* s, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr ); -lapack_int LAPACKE_zppsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* ap, - lapack_complex_double* afp, char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); - -lapack_int LAPACKE_spptrf( int matrix_order, char uplo, lapack_int n, - float* ap ); -lapack_int LAPACKE_dpptrf( int matrix_order, char uplo, lapack_int n, - double* ap ); -lapack_int LAPACKE_cpptrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap ); -lapack_int LAPACKE_zpptrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap ); - -lapack_int LAPACKE_spptri( int matrix_order, char uplo, lapack_int n, - float* ap ); -lapack_int LAPACKE_dpptri( int matrix_order, char uplo, lapack_int n, - double* ap ); -lapack_int LAPACKE_cpptri( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap ); -lapack_int LAPACKE_zpptri( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap ); - -lapack_int LAPACKE_spptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dpptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cpptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* ap, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_spstrf( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda, lapack_int* piv, lapack_int* rank, - float tol ); -lapack_int LAPACKE_dpstrf( int matrix_order, char uplo, lapack_int n, double* a, - lapack_int lda, lapack_int* piv, lapack_int* rank, - double tol ); -lapack_int LAPACKE_cpstrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* piv, lapack_int* rank, float tol ); -lapack_int LAPACKE_zpstrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* piv, lapack_int* rank, double tol ); - -lapack_int LAPACKE_sptcon( lapack_int n, const float* d, const float* e, - float anorm, float* rcond ); -lapack_int LAPACKE_dptcon( lapack_int n, const double* d, const double* e, - double anorm, double* rcond ); -lapack_int LAPACKE_cptcon( lapack_int n, const float* d, - const lapack_complex_float* e, float anorm, - float* rcond ); -lapack_int LAPACKE_zptcon( lapack_int n, const double* d, - const lapack_complex_double* e, double anorm, - double* rcond ); - -lapack_int LAPACKE_spteqr( int matrix_order, char compz, lapack_int n, float* d, - float* e, float* z, lapack_int ldz ); -lapack_int LAPACKE_dpteqr( int matrix_order, char compz, lapack_int n, - double* d, double* e, double* z, lapack_int ldz ); -lapack_int LAPACKE_cpteqr( int matrix_order, char compz, lapack_int n, float* d, - float* e, lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zpteqr( int matrix_order, char compz, lapack_int n, - double* d, double* e, lapack_complex_double* z, - lapack_int ldz ); - -lapack_int LAPACKE_sptrfs( int matrix_order, lapack_int n, lapack_int nrhs, - const float* d, const float* e, const float* df, - const float* ef, const float* b, lapack_int ldb, - float* x, lapack_int ldx, float* ferr, float* berr ); -lapack_int LAPACKE_dptrfs( int matrix_order, lapack_int n, lapack_int nrhs, - const double* d, const double* e, const double* df, - const double* ef, const double* b, lapack_int ldb, - double* x, lapack_int ldx, double* ferr, - double* berr ); -lapack_int LAPACKE_cptrfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* d, - const lapack_complex_float* e, const float* df, - const lapack_complex_float* ef, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zptrfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* d, - const lapack_complex_double* e, const double* df, - const lapack_complex_double* ef, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_sptsv( int matrix_order, lapack_int n, lapack_int nrhs, - float* d, float* e, float* b, lapack_int ldb ); -lapack_int LAPACKE_dptsv( int matrix_order, lapack_int n, lapack_int nrhs, - double* d, double* e, double* b, lapack_int ldb ); -lapack_int LAPACKE_cptsv( int matrix_order, lapack_int n, lapack_int nrhs, - float* d, lapack_complex_float* e, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zptsv( int matrix_order, lapack_int n, lapack_int nrhs, - double* d, lapack_complex_double* e, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sptsvx( int matrix_order, char fact, lapack_int n, - lapack_int nrhs, const float* d, const float* e, - float* df, float* ef, const float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, float* ferr, - float* berr ); -lapack_int LAPACKE_dptsvx( int matrix_order, char fact, lapack_int n, - lapack_int nrhs, const double* d, const double* e, - double* df, double* ef, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); -lapack_int LAPACKE_cptsvx( int matrix_order, char fact, lapack_int n, - lapack_int nrhs, const float* d, - const lapack_complex_float* e, float* df, - lapack_complex_float* ef, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr ); -lapack_int LAPACKE_zptsvx( int matrix_order, char fact, lapack_int n, - lapack_int nrhs, const double* d, - const lapack_complex_double* e, double* df, - lapack_complex_double* ef, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); - -lapack_int LAPACKE_spttrf( lapack_int n, float* d, float* e ); -lapack_int LAPACKE_dpttrf( lapack_int n, double* d, double* e ); -lapack_int LAPACKE_cpttrf( lapack_int n, float* d, lapack_complex_float* e ); -lapack_int LAPACKE_zpttrf( lapack_int n, double* d, lapack_complex_double* e ); - -lapack_int LAPACKE_spttrs( int matrix_order, lapack_int n, lapack_int nrhs, - const float* d, const float* e, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dpttrs( int matrix_order, lapack_int n, lapack_int nrhs, - const double* d, const double* e, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cpttrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* d, - const lapack_complex_float* e, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpttrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* d, - const lapack_complex_double* e, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_ssbev( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int kd, float* ab, lapack_int ldab, float* w, - float* z, lapack_int ldz ); -lapack_int LAPACKE_dsbev( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int kd, double* ab, lapack_int ldab, double* w, - double* z, lapack_int ldz ); - -lapack_int LAPACKE_ssbevd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int kd, float* ab, lapack_int ldab, float* w, - float* z, lapack_int ldz ); -lapack_int LAPACKE_dsbevd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int kd, double* ab, lapack_int ldab, - double* w, double* z, lapack_int ldz ); - -lapack_int LAPACKE_ssbevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_int kd, float* ab, - lapack_int ldab, float* q, lapack_int ldq, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* ifail ); -lapack_int LAPACKE_dsbevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_int kd, double* ab, - lapack_int ldab, double* q, lapack_int ldq, - double vl, double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* ifail ); - -lapack_int LAPACKE_ssbgst( int matrix_order, char vect, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, float* ab, - lapack_int ldab, const float* bb, lapack_int ldbb, - float* x, lapack_int ldx ); -lapack_int LAPACKE_dsbgst( int matrix_order, char vect, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, double* ab, - lapack_int ldab, const double* bb, lapack_int ldbb, - double* x, lapack_int ldx ); - -lapack_int LAPACKE_ssbgv( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, float* ab, - lapack_int ldab, float* bb, lapack_int ldbb, float* w, - float* z, lapack_int ldz ); -lapack_int LAPACKE_dsbgv( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, double* ab, - lapack_int ldab, double* bb, lapack_int ldbb, - double* w, double* z, lapack_int ldz ); - -lapack_int LAPACKE_ssbgvd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, float* ab, - lapack_int ldab, float* bb, lapack_int ldbb, - float* w, float* z, lapack_int ldz ); -lapack_int LAPACKE_dsbgvd( int matrix_order, char jobz, char uplo, lapack_int n, - lapack_int ka, lapack_int kb, double* ab, - lapack_int ldab, double* bb, lapack_int ldbb, - double* w, double* z, lapack_int ldz ); - -lapack_int LAPACKE_ssbgvx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - float* ab, lapack_int ldab, float* bb, - lapack_int ldbb, float* q, lapack_int ldq, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* ifail ); -lapack_int LAPACKE_dsbgvx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - double* ab, lapack_int ldab, double* bb, - lapack_int ldbb, double* q, lapack_int ldq, - double vl, double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* ifail ); - -lapack_int LAPACKE_ssbtrd( int matrix_order, char vect, char uplo, lapack_int n, - lapack_int kd, float* ab, lapack_int ldab, float* d, - float* e, float* q, lapack_int ldq ); -lapack_int LAPACKE_dsbtrd( int matrix_order, char vect, char uplo, lapack_int n, - lapack_int kd, double* ab, lapack_int ldab, - double* d, double* e, double* q, lapack_int ldq ); - -lapack_int LAPACKE_ssfrk( int matrix_order, char transr, char uplo, char trans, - lapack_int n, lapack_int k, float alpha, - const float* a, lapack_int lda, float beta, - float* c ); -lapack_int LAPACKE_dsfrk( int matrix_order, char transr, char uplo, char trans, - lapack_int n, lapack_int k, double alpha, - const double* a, lapack_int lda, double beta, - double* c ); - -lapack_int LAPACKE_sspcon( int matrix_order, char uplo, lapack_int n, - const float* ap, const lapack_int* ipiv, float anorm, - float* rcond ); -lapack_int LAPACKE_dspcon( int matrix_order, char uplo, lapack_int n, - const double* ap, const lapack_int* ipiv, - double anorm, double* rcond ); -lapack_int LAPACKE_cspcon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, - const lapack_int* ipiv, float anorm, float* rcond ); -lapack_int LAPACKE_zspcon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, - const lapack_int* ipiv, double anorm, - double* rcond ); - -lapack_int LAPACKE_sspev( int matrix_order, char jobz, char uplo, lapack_int n, - float* ap, float* w, float* z, lapack_int ldz ); -lapack_int LAPACKE_dspev( int matrix_order, char jobz, char uplo, lapack_int n, - double* ap, double* w, double* z, lapack_int ldz ); - -lapack_int LAPACKE_sspevd( int matrix_order, char jobz, char uplo, lapack_int n, - float* ap, float* w, float* z, lapack_int ldz ); -lapack_int LAPACKE_dspevd( int matrix_order, char jobz, char uplo, lapack_int n, - double* ap, double* w, double* z, lapack_int ldz ); - -lapack_int LAPACKE_sspevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, float* ap, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* ifail ); -lapack_int LAPACKE_dspevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, double* ap, double vl, double vu, - lapack_int il, lapack_int iu, double abstol, - lapack_int* m, double* w, double* z, lapack_int ldz, - lapack_int* ifail ); - -lapack_int LAPACKE_sspgst( int matrix_order, lapack_int itype, char uplo, - lapack_int n, float* ap, const float* bp ); -lapack_int LAPACKE_dspgst( int matrix_order, lapack_int itype, char uplo, - lapack_int n, double* ap, const double* bp ); - -lapack_int LAPACKE_sspgv( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, float* ap, float* bp, - float* w, float* z, lapack_int ldz ); -lapack_int LAPACKE_dspgv( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, double* ap, double* bp, - double* w, double* z, lapack_int ldz ); - -lapack_int LAPACKE_sspgvd( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, float* ap, float* bp, - float* w, float* z, lapack_int ldz ); -lapack_int LAPACKE_dspgvd( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, double* ap, double* bp, - double* w, double* z, lapack_int ldz ); - -lapack_int LAPACKE_sspgvx( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, float* ap, - float* bp, float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, float* w, - float* z, lapack_int ldz, lapack_int* ifail ); -lapack_int LAPACKE_dspgvx( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, double* ap, - double* bp, double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, double* z, lapack_int ldz, - lapack_int* ifail ); - -lapack_int LAPACKE_ssprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, const float* afp, - const lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_dsprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, const double* afp, - const lapack_int* ipiv, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* ferr, double* berr ); -lapack_int LAPACKE_csprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_complex_float* afp, - const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zsprfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* ap, - const lapack_complex_double* afp, - const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_sspsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, float* ap, lapack_int* ipiv, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dspsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* ap, lapack_int* ipiv, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cspsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* ap, - lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zspsv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* ap, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sspsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, float* afp, - lapack_int* ipiv, const float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, float* ferr, - float* berr ); -lapack_int LAPACKE_dspsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, double* afp, - lapack_int* ipiv, const double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* ferr, double* berr ); -lapack_int LAPACKE_cspsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - lapack_complex_float* afp, lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr ); -lapack_int LAPACKE_zspsvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* ap, - lapack_complex_double* afp, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); - -lapack_int LAPACKE_ssptrd( int matrix_order, char uplo, lapack_int n, float* ap, - float* d, float* e, float* tau ); -lapack_int LAPACKE_dsptrd( int matrix_order, char uplo, lapack_int n, - double* ap, double* d, double* e, double* tau ); - -lapack_int LAPACKE_ssptrf( int matrix_order, char uplo, lapack_int n, float* ap, - lapack_int* ipiv ); -lapack_int LAPACKE_dsptrf( int matrix_order, char uplo, lapack_int n, - double* ap, lapack_int* ipiv ); -lapack_int LAPACKE_csptrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, lapack_int* ipiv ); -lapack_int LAPACKE_zsptrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, lapack_int* ipiv ); - -lapack_int LAPACKE_ssptri( int matrix_order, char uplo, lapack_int n, float* ap, - const lapack_int* ipiv ); -lapack_int LAPACKE_dsptri( int matrix_order, char uplo, lapack_int n, - double* ap, const lapack_int* ipiv ); -lapack_int LAPACKE_csptri( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, const lapack_int* ipiv ); -lapack_int LAPACKE_zsptri( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, const lapack_int* ipiv ); - -lapack_int LAPACKE_ssptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, - const lapack_int* ipiv, float* b, lapack_int ldb ); -lapack_int LAPACKE_dsptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, - const lapack_int* ipiv, double* b, lapack_int ldb ); -lapack_int LAPACKE_csptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zsptrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* ap, - const lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sstebz( char range, char order, lapack_int n, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - const float* d, const float* e, lapack_int* m, - lapack_int* nsplit, float* w, lapack_int* iblock, - lapack_int* isplit ); -lapack_int LAPACKE_dstebz( char range, char order, lapack_int n, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, const double* d, const double* e, - lapack_int* m, lapack_int* nsplit, double* w, - lapack_int* iblock, lapack_int* isplit ); - -lapack_int LAPACKE_sstedc( int matrix_order, char compz, lapack_int n, float* d, - float* e, float* z, lapack_int ldz ); -lapack_int LAPACKE_dstedc( int matrix_order, char compz, lapack_int n, - double* d, double* e, double* z, lapack_int ldz ); -lapack_int LAPACKE_cstedc( int matrix_order, char compz, lapack_int n, float* d, - float* e, lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zstedc( int matrix_order, char compz, lapack_int n, - double* d, double* e, lapack_complex_double* z, - lapack_int ldz ); - -lapack_int LAPACKE_sstegr( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* isuppz ); -lapack_int LAPACKE_dstegr( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* isuppz ); -lapack_int LAPACKE_cstegr( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int ldz, lapack_int* isuppz ); -lapack_int LAPACKE_zstegr( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_int* isuppz ); - -lapack_int LAPACKE_sstein( int matrix_order, lapack_int n, const float* d, - const float* e, lapack_int m, const float* w, - const lapack_int* iblock, const lapack_int* isplit, - float* z, lapack_int ldz, lapack_int* ifailv ); -lapack_int LAPACKE_dstein( int matrix_order, lapack_int n, const double* d, - const double* e, lapack_int m, const double* w, - const lapack_int* iblock, const lapack_int* isplit, - double* z, lapack_int ldz, lapack_int* ifailv ); -lapack_int LAPACKE_cstein( int matrix_order, lapack_int n, const float* d, - const float* e, lapack_int m, const float* w, - const lapack_int* iblock, const lapack_int* isplit, - lapack_complex_float* z, lapack_int ldz, - lapack_int* ifailv ); -lapack_int LAPACKE_zstein( int matrix_order, lapack_int n, const double* d, - const double* e, lapack_int m, const double* w, - const lapack_int* iblock, const lapack_int* isplit, - lapack_complex_double* z, lapack_int ldz, - lapack_int* ifailv ); - -lapack_int LAPACKE_sstemr( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, float vu, - lapack_int il, lapack_int iu, lapack_int* m, - float* w, float* z, lapack_int ldz, lapack_int nzc, - lapack_int* isuppz, lapack_logical* tryrac ); -lapack_int LAPACKE_dstemr( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - lapack_int* m, double* w, double* z, lapack_int ldz, - lapack_int nzc, lapack_int* isuppz, - lapack_logical* tryrac ); -lapack_int LAPACKE_cstemr( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, float vu, - lapack_int il, lapack_int iu, lapack_int* m, - float* w, lapack_complex_float* z, lapack_int ldz, - lapack_int nzc, lapack_int* isuppz, - lapack_logical* tryrac ); -lapack_int LAPACKE_zstemr( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - lapack_int* m, double* w, lapack_complex_double* z, - lapack_int ldz, lapack_int nzc, lapack_int* isuppz, - lapack_logical* tryrac ); - -lapack_int LAPACKE_ssteqr( int matrix_order, char compz, lapack_int n, float* d, - float* e, float* z, lapack_int ldz ); -lapack_int LAPACKE_dsteqr( int matrix_order, char compz, lapack_int n, - double* d, double* e, double* z, lapack_int ldz ); -lapack_int LAPACKE_csteqr( int matrix_order, char compz, lapack_int n, float* d, - float* e, lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zsteqr( int matrix_order, char compz, lapack_int n, - double* d, double* e, lapack_complex_double* z, - lapack_int ldz ); - -lapack_int LAPACKE_ssterf( lapack_int n, float* d, float* e ); -lapack_int LAPACKE_dsterf( lapack_int n, double* d, double* e ); - -lapack_int LAPACKE_sstev( int matrix_order, char jobz, lapack_int n, float* d, - float* e, float* z, lapack_int ldz ); -lapack_int LAPACKE_dstev( int matrix_order, char jobz, lapack_int n, double* d, - double* e, double* z, lapack_int ldz ); - -lapack_int LAPACKE_sstevd( int matrix_order, char jobz, lapack_int n, float* d, - float* e, float* z, lapack_int ldz ); -lapack_int LAPACKE_dstevd( int matrix_order, char jobz, lapack_int n, double* d, - double* e, double* z, lapack_int ldz ); - -lapack_int LAPACKE_sstevr( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* isuppz ); -lapack_int LAPACKE_dstevr( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* isuppz ); - -lapack_int LAPACKE_sstevx( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* ifail ); -lapack_int LAPACKE_dstevx( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* ifail ); - -lapack_int LAPACKE_ssycon( int matrix_order, char uplo, lapack_int n, - const float* a, lapack_int lda, - const lapack_int* ipiv, float anorm, float* rcond ); -lapack_int LAPACKE_dsycon( int matrix_order, char uplo, lapack_int n, - const double* a, lapack_int lda, - const lapack_int* ipiv, double anorm, - double* rcond ); -lapack_int LAPACKE_csycon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, float anorm, float* rcond ); -lapack_int LAPACKE_zsycon( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, double anorm, - double* rcond ); - -lapack_int LAPACKE_ssyequb( int matrix_order, char uplo, lapack_int n, - const float* a, lapack_int lda, float* s, - float* scond, float* amax ); -lapack_int LAPACKE_dsyequb( int matrix_order, char uplo, lapack_int n, - const double* a, lapack_int lda, double* s, - double* scond, double* amax ); -lapack_int LAPACKE_csyequb( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* s, float* scond, float* amax ); -lapack_int LAPACKE_zsyequb( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* s, double* scond, double* amax ); - -lapack_int LAPACKE_ssyev( int matrix_order, char jobz, char uplo, lapack_int n, - float* a, lapack_int lda, float* w ); -lapack_int LAPACKE_dsyev( int matrix_order, char jobz, char uplo, lapack_int n, - double* a, lapack_int lda, double* w ); - -lapack_int LAPACKE_ssyevd( int matrix_order, char jobz, char uplo, lapack_int n, - float* a, lapack_int lda, float* w ); -lapack_int LAPACKE_dsyevd( int matrix_order, char jobz, char uplo, lapack_int n, - double* a, lapack_int lda, double* w ); - -lapack_int LAPACKE_ssyevr( int matrix_order, char jobz, char range, char uplo, - lapack_int n, float* a, lapack_int lda, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* isuppz ); -lapack_int LAPACKE_dsyevr( int matrix_order, char jobz, char range, char uplo, - lapack_int n, double* a, lapack_int lda, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* isuppz ); - -lapack_int LAPACKE_ssyevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, float* a, lapack_int lda, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* ifail ); -lapack_int LAPACKE_dsyevx( int matrix_order, char jobz, char range, char uplo, - lapack_int n, double* a, lapack_int lda, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* ifail ); - -lapack_int LAPACKE_ssygst( int matrix_order, lapack_int itype, char uplo, - lapack_int n, float* a, lapack_int lda, - const float* b, lapack_int ldb ); -lapack_int LAPACKE_dsygst( int matrix_order, lapack_int itype, char uplo, - lapack_int n, double* a, lapack_int lda, - const double* b, lapack_int ldb ); - -lapack_int LAPACKE_ssygv( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, float* a, lapack_int lda, - float* b, lapack_int ldb, float* w ); -lapack_int LAPACKE_dsygv( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, double* a, lapack_int lda, - double* b, lapack_int ldb, double* w ); - -lapack_int LAPACKE_ssygvd( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, float* a, lapack_int lda, - float* b, lapack_int ldb, float* w ); -lapack_int LAPACKE_dsygvd( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, double* a, lapack_int lda, - double* b, lapack_int ldb, double* w ); - -lapack_int LAPACKE_ssygvx( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, float vl, - float vu, lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, lapack_int ldz, - lapack_int* ifail ); -lapack_int LAPACKE_dsygvx( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* ifail ); - -lapack_int LAPACKE_ssyrfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_dsyrfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, lapack_int lda, - const double* af, lapack_int ldaf, - const lapack_int* ipiv, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* ferr, double* berr ); -lapack_int LAPACKE_csyrfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_zsyrfs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_ssyrfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, const float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* s, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_dsyrfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, const double* af, lapack_int ldaf, - const lapack_int* ipiv, const double* s, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params ); -lapack_int LAPACKE_csyrfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* s, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params ); -lapack_int LAPACKE_zsyrfsx( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* af, lapack_int ldaf, - const lapack_int* ipiv, const double* s, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params ); - -lapack_int LAPACKE_ssysv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, - lapack_int* ipiv, float* b, lapack_int ldb ); -lapack_int LAPACKE_dsysv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - lapack_int* ipiv, double* b, lapack_int ldb ); -lapack_int LAPACKE_csysv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zsysv( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_ssysvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - float* af, lapack_int ldaf, lapack_int* ipiv, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr ); -lapack_int LAPACKE_dsysvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const double* a, lapack_int lda, - double* af, lapack_int ldaf, lapack_int* ipiv, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr ); -lapack_int LAPACKE_csysvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, lapack_complex_float* af, - lapack_int ldaf, lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr ); -lapack_int LAPACKE_zsysvx( int matrix_order, char fact, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, lapack_complex_double* af, - lapack_int ldaf, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr ); - -lapack_int LAPACKE_ssysvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* s, float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_dsysvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* s, double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params ); -lapack_int LAPACKE_csysvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* s, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params ); -lapack_int LAPACKE_zsysvxx( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params ); - -lapack_int LAPACKE_ssytrd( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda, float* d, float* e, float* tau ); -lapack_int LAPACKE_dsytrd( int matrix_order, char uplo, lapack_int n, double* a, - lapack_int lda, double* d, double* e, double* tau ); - -lapack_int LAPACKE_ssytrf( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_dsytrf( int matrix_order, char uplo, lapack_int n, double* a, - lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_csytrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv ); -lapack_int LAPACKE_zsytrf( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv ); - -lapack_int LAPACKE_ssytri( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda, const lapack_int* ipiv ); -lapack_int LAPACKE_dsytri( int matrix_order, char uplo, lapack_int n, double* a, - lapack_int lda, const lapack_int* ipiv ); -lapack_int LAPACKE_csytri( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_zsytri( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv ); - -lapack_int LAPACKE_ssytrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const lapack_int* ipiv, float* b, lapack_int ldb ); -lapack_int LAPACKE_dsytrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, lapack_int lda, - const lapack_int* ipiv, double* b, lapack_int ldb ); -lapack_int LAPACKE_csytrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zsytrs( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_stbcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, lapack_int kd, const float* ab, - lapack_int ldab, float* rcond ); -lapack_int LAPACKE_dtbcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, lapack_int kd, const double* ab, - lapack_int ldab, double* rcond ); -lapack_int LAPACKE_ctbcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, lapack_int kd, - const lapack_complex_float* ab, lapack_int ldab, - float* rcond ); -lapack_int LAPACKE_ztbcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, lapack_int kd, - const lapack_complex_double* ab, lapack_int ldab, - double* rcond ); - -lapack_int LAPACKE_stbrfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int kd, lapack_int nrhs, - const float* ab, lapack_int ldab, const float* b, - lapack_int ldb, const float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_dtbrfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int kd, lapack_int nrhs, - const double* ab, lapack_int ldab, const double* b, - lapack_int ldb, const double* x, lapack_int ldx, - double* ferr, double* berr ); -lapack_int LAPACKE_ctbrfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int kd, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_complex_float* b, lapack_int ldb, - const lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_ztbrfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int kd, lapack_int nrhs, - const lapack_complex_double* ab, lapack_int ldab, - const lapack_complex_double* b, lapack_int ldb, - const lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_stbtrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int kd, lapack_int nrhs, - const float* ab, lapack_int ldab, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dtbtrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int kd, lapack_int nrhs, - const double* ab, lapack_int ldab, double* b, - lapack_int ldb ); -lapack_int LAPACKE_ctbtrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int kd, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_ztbtrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int kd, lapack_int nrhs, - const lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_stfsm( int matrix_order, char transr, char side, char uplo, - char trans, char diag, lapack_int m, lapack_int n, - float alpha, const float* a, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dtfsm( int matrix_order, char transr, char side, char uplo, - char trans, char diag, lapack_int m, lapack_int n, - double alpha, const double* a, double* b, - lapack_int ldb ); -lapack_int LAPACKE_ctfsm( int matrix_order, char transr, char side, char uplo, - char trans, char diag, lapack_int m, lapack_int n, - lapack_complex_float alpha, - const lapack_complex_float* a, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_ztfsm( int matrix_order, char transr, char side, char uplo, - char trans, char diag, lapack_int m, lapack_int n, - lapack_complex_double alpha, - const lapack_complex_double* a, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_stftri( int matrix_order, char transr, char uplo, char diag, - lapack_int n, float* a ); -lapack_int LAPACKE_dtftri( int matrix_order, char transr, char uplo, char diag, - lapack_int n, double* a ); -lapack_int LAPACKE_ctftri( int matrix_order, char transr, char uplo, char diag, - lapack_int n, lapack_complex_float* a ); -lapack_int LAPACKE_ztftri( int matrix_order, char transr, char uplo, char diag, - lapack_int n, lapack_complex_double* a ); - -lapack_int LAPACKE_stfttp( int matrix_order, char transr, char uplo, - lapack_int n, const float* arf, float* ap ); -lapack_int LAPACKE_dtfttp( int matrix_order, char transr, char uplo, - lapack_int n, const double* arf, double* ap ); -lapack_int LAPACKE_ctfttp( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_float* arf, - lapack_complex_float* ap ); -lapack_int LAPACKE_ztfttp( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_double* arf, - lapack_complex_double* ap ); - -lapack_int LAPACKE_stfttr( int matrix_order, char transr, char uplo, - lapack_int n, const float* arf, float* a, - lapack_int lda ); -lapack_int LAPACKE_dtfttr( int matrix_order, char transr, char uplo, - lapack_int n, const double* arf, double* a, - lapack_int lda ); -lapack_int LAPACKE_ctfttr( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_float* arf, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_ztfttr( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_double* arf, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_stgevc( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - const float* s, lapack_int lds, const float* p, - lapack_int ldp, float* vl, lapack_int ldvl, - float* vr, lapack_int ldvr, lapack_int mm, - lapack_int* m ); -lapack_int LAPACKE_dtgevc( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - const double* s, lapack_int lds, const double* p, - lapack_int ldp, double* vl, lapack_int ldvl, - double* vr, lapack_int ldvr, lapack_int mm, - lapack_int* m ); -lapack_int LAPACKE_ctgevc( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_float* s, lapack_int lds, - const lapack_complex_float* p, lapack_int ldp, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m ); -lapack_int LAPACKE_ztgevc( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_double* s, lapack_int lds, - const lapack_complex_double* p, lapack_int ldp, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m ); - -lapack_int LAPACKE_stgexc( int matrix_order, lapack_logical wantq, - lapack_logical wantz, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, float* q, - lapack_int ldq, float* z, lapack_int ldz, - lapack_int* ifst, lapack_int* ilst ); -lapack_int LAPACKE_dtgexc( int matrix_order, lapack_logical wantq, - lapack_logical wantz, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, double* q, - lapack_int ldq, double* z, lapack_int ldz, - lapack_int* ifst, lapack_int* ilst ); -lapack_int LAPACKE_ctgexc( int matrix_order, lapack_logical wantq, - lapack_logical wantz, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* z, lapack_int ldz, - lapack_int ifst, lapack_int ilst ); -lapack_int LAPACKE_ztgexc( int matrix_order, lapack_logical wantq, - lapack_logical wantz, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* z, lapack_int ldz, - lapack_int ifst, lapack_int ilst ); - -lapack_int LAPACKE_stgsen( int matrix_order, lapack_int ijob, - lapack_logical wantq, lapack_logical wantz, - const lapack_logical* select, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - float* alphar, float* alphai, float* beta, float* q, - lapack_int ldq, float* z, lapack_int ldz, - lapack_int* m, float* pl, float* pr, float* dif ); -lapack_int LAPACKE_dtgsen( int matrix_order, lapack_int ijob, - lapack_logical wantq, lapack_logical wantz, - const lapack_logical* select, lapack_int n, - double* a, lapack_int lda, double* b, lapack_int ldb, - double* alphar, double* alphai, double* beta, - double* q, lapack_int ldq, double* z, lapack_int ldz, - lapack_int* m, double* pl, double* pr, double* dif ); -lapack_int LAPACKE_ctgsen( int matrix_order, lapack_int ijob, - lapack_logical wantq, lapack_logical wantz, - const lapack_logical* select, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* alpha, - lapack_complex_float* beta, lapack_complex_float* q, - lapack_int ldq, lapack_complex_float* z, - lapack_int ldz, lapack_int* m, float* pl, float* pr, - float* dif ); -lapack_int LAPACKE_ztgsen( int matrix_order, lapack_int ijob, - lapack_logical wantq, lapack_logical wantz, - const lapack_logical* select, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* z, lapack_int ldz, - lapack_int* m, double* pl, double* pr, double* dif ); - -lapack_int LAPACKE_stgsja( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int p, lapack_int n, - lapack_int k, lapack_int l, float* a, lapack_int lda, - float* b, lapack_int ldb, float tola, float tolb, - float* alpha, float* beta, float* u, lapack_int ldu, - float* v, lapack_int ldv, float* q, lapack_int ldq, - lapack_int* ncycle ); -lapack_int LAPACKE_dtgsja( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int p, lapack_int n, - lapack_int k, lapack_int l, double* a, - lapack_int lda, double* b, lapack_int ldb, - double tola, double tolb, double* alpha, - double* beta, double* u, lapack_int ldu, double* v, - lapack_int ldv, double* q, lapack_int ldq, - lapack_int* ncycle ); -lapack_int LAPACKE_ctgsja( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int p, lapack_int n, - lapack_int k, lapack_int l, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float tola, float tolb, float* alpha, - float* beta, lapack_complex_float* u, lapack_int ldu, - lapack_complex_float* v, lapack_int ldv, - lapack_complex_float* q, lapack_int ldq, - lapack_int* ncycle ); -lapack_int LAPACKE_ztgsja( int matrix_order, char jobu, char jobv, char jobq, - lapack_int m, lapack_int p, lapack_int n, - lapack_int k, lapack_int l, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, double tola, double tolb, - double* alpha, double* beta, - lapack_complex_double* u, lapack_int ldu, - lapack_complex_double* v, lapack_int ldv, - lapack_complex_double* q, lapack_int ldq, - lapack_int* ncycle ); - -lapack_int LAPACKE_stgsna( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const float* a, lapack_int lda, const float* b, - lapack_int ldb, const float* vl, lapack_int ldvl, - const float* vr, lapack_int ldvr, float* s, - float* dif, lapack_int mm, lapack_int* m ); -lapack_int LAPACKE_dtgsna( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const double* a, lapack_int lda, const double* b, - lapack_int ldb, const double* vl, lapack_int ldvl, - const double* vr, lapack_int ldvr, double* s, - double* dif, lapack_int mm, lapack_int* m ); -lapack_int LAPACKE_ctgsna( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* b, lapack_int ldb, - const lapack_complex_float* vl, lapack_int ldvl, - const lapack_complex_float* vr, lapack_int ldvr, - float* s, float* dif, lapack_int mm, lapack_int* m ); -lapack_int LAPACKE_ztgsna( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* b, lapack_int ldb, - const lapack_complex_double* vl, lapack_int ldvl, - const lapack_complex_double* vr, lapack_int ldvr, - double* s, double* dif, lapack_int mm, - lapack_int* m ); - -lapack_int LAPACKE_stgsyl( int matrix_order, char trans, lapack_int ijob, - lapack_int m, lapack_int n, const float* a, - lapack_int lda, const float* b, lapack_int ldb, - float* c, lapack_int ldc, const float* d, - lapack_int ldd, const float* e, lapack_int lde, - float* f, lapack_int ldf, float* scale, float* dif ); -lapack_int LAPACKE_dtgsyl( int matrix_order, char trans, lapack_int ijob, - lapack_int m, lapack_int n, const double* a, - lapack_int lda, const double* b, lapack_int ldb, - double* c, lapack_int ldc, const double* d, - lapack_int ldd, const double* e, lapack_int lde, - double* f, lapack_int ldf, double* scale, - double* dif ); -lapack_int LAPACKE_ctgsyl( int matrix_order, char trans, lapack_int ijob, - lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* c, lapack_int ldc, - const lapack_complex_float* d, lapack_int ldd, - const lapack_complex_float* e, lapack_int lde, - lapack_complex_float* f, lapack_int ldf, - float* scale, float* dif ); -lapack_int LAPACKE_ztgsyl( int matrix_order, char trans, lapack_int ijob, - lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* c, lapack_int ldc, - const lapack_complex_double* d, lapack_int ldd, - const lapack_complex_double* e, lapack_int lde, - lapack_complex_double* f, lapack_int ldf, - double* scale, double* dif ); - -lapack_int LAPACKE_stpcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, const float* ap, float* rcond ); -lapack_int LAPACKE_dtpcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, const double* ap, double* rcond ); -lapack_int LAPACKE_ctpcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, const lapack_complex_float* ap, - float* rcond ); -lapack_int LAPACKE_ztpcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, const lapack_complex_double* ap, - double* rcond ); - -lapack_int LAPACKE_stprfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, const float* ap, - const float* b, lapack_int ldb, const float* x, - lapack_int ldx, float* ferr, float* berr ); -lapack_int LAPACKE_dtprfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, const double* ap, - const double* b, lapack_int ldb, const double* x, - lapack_int ldx, double* ferr, double* berr ); -lapack_int LAPACKE_ctprfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* ap, - const lapack_complex_float* b, lapack_int ldb, - const lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_ztprfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* ap, - const lapack_complex_double* b, lapack_int ldb, - const lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_stptri( int matrix_order, char uplo, char diag, lapack_int n, - float* ap ); -lapack_int LAPACKE_dtptri( int matrix_order, char uplo, char diag, lapack_int n, - double* ap ); -lapack_int LAPACKE_ctptri( int matrix_order, char uplo, char diag, lapack_int n, - lapack_complex_float* ap ); -lapack_int LAPACKE_ztptri( int matrix_order, char uplo, char diag, lapack_int n, - lapack_complex_double* ap ); - -lapack_int LAPACKE_stptrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, const float* ap, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dtptrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, const double* ap, - double* b, lapack_int ldb ); -lapack_int LAPACKE_ctptrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* ap, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_ztptrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* ap, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_stpttf( int matrix_order, char transr, char uplo, - lapack_int n, const float* ap, float* arf ); -lapack_int LAPACKE_dtpttf( int matrix_order, char transr, char uplo, - lapack_int n, const double* ap, double* arf ); -lapack_int LAPACKE_ctpttf( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_float* ap, - lapack_complex_float* arf ); -lapack_int LAPACKE_ztpttf( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_double* ap, - lapack_complex_double* arf ); - -lapack_int LAPACKE_stpttr( int matrix_order, char uplo, lapack_int n, - const float* ap, float* a, lapack_int lda ); -lapack_int LAPACKE_dtpttr( int matrix_order, char uplo, lapack_int n, - const double* ap, double* a, lapack_int lda ); -lapack_int LAPACKE_ctpttr( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_ztpttr( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_strcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, const float* a, lapack_int lda, - float* rcond ); -lapack_int LAPACKE_dtrcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, const double* a, lapack_int lda, - double* rcond ); -lapack_int LAPACKE_ctrcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, const lapack_complex_float* a, - lapack_int lda, float* rcond ); -lapack_int LAPACKE_ztrcon( int matrix_order, char norm, char uplo, char diag, - lapack_int n, const lapack_complex_double* a, - lapack_int lda, double* rcond ); - -lapack_int LAPACKE_strevc( int matrix_order, char side, char howmny, - lapack_logical* select, lapack_int n, const float* t, - lapack_int ldt, float* vl, lapack_int ldvl, - float* vr, lapack_int ldvr, lapack_int mm, - lapack_int* m ); -lapack_int LAPACKE_dtrevc( int matrix_order, char side, char howmny, - lapack_logical* select, lapack_int n, - const double* t, lapack_int ldt, double* vl, - lapack_int ldvl, double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m ); -lapack_int LAPACKE_ctrevc( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m ); -lapack_int LAPACKE_ztrevc( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m ); - -lapack_int LAPACKE_strexc( int matrix_order, char compq, lapack_int n, float* t, - lapack_int ldt, float* q, lapack_int ldq, - lapack_int* ifst, lapack_int* ilst ); -lapack_int LAPACKE_dtrexc( int matrix_order, char compq, lapack_int n, - double* t, lapack_int ldt, double* q, lapack_int ldq, - lapack_int* ifst, lapack_int* ilst ); -lapack_int LAPACKE_ctrexc( int matrix_order, char compq, lapack_int n, - lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* q, lapack_int ldq, - lapack_int ifst, lapack_int ilst ); -lapack_int LAPACKE_ztrexc( int matrix_order, char compq, lapack_int n, - lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* q, lapack_int ldq, - lapack_int ifst, lapack_int ilst ); - -lapack_int LAPACKE_strrfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, const float* b, lapack_int ldb, - const float* x, lapack_int ldx, float* ferr, - float* berr ); -lapack_int LAPACKE_dtrrfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, const double* b, lapack_int ldb, - const double* x, lapack_int ldx, double* ferr, - double* berr ); -lapack_int LAPACKE_ctrrfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* b, lapack_int ldb, - const lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr ); -lapack_int LAPACKE_ztrrfs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* b, lapack_int ldb, - const lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr ); - -lapack_int LAPACKE_strsen( int matrix_order, char job, char compq, - const lapack_logical* select, lapack_int n, float* t, - lapack_int ldt, float* q, lapack_int ldq, float* wr, - float* wi, lapack_int* m, float* s, float* sep ); -lapack_int LAPACKE_dtrsen( int matrix_order, char job, char compq, - const lapack_logical* select, lapack_int n, - double* t, lapack_int ldt, double* q, lapack_int ldq, - double* wr, double* wi, lapack_int* m, double* s, - double* sep ); -lapack_int LAPACKE_ctrsen( int matrix_order, char job, char compq, - const lapack_logical* select, lapack_int n, - lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* w, lapack_int* m, float* s, - float* sep ); -lapack_int LAPACKE_ztrsen( int matrix_order, char job, char compq, - const lapack_logical* select, lapack_int n, - lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* w, lapack_int* m, double* s, - double* sep ); - -lapack_int LAPACKE_strsna( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const float* t, lapack_int ldt, const float* vl, - lapack_int ldvl, const float* vr, lapack_int ldvr, - float* s, float* sep, lapack_int mm, lapack_int* m ); -lapack_int LAPACKE_dtrsna( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const double* t, lapack_int ldt, const double* vl, - lapack_int ldvl, const double* vr, lapack_int ldvr, - double* s, double* sep, lapack_int mm, - lapack_int* m ); -lapack_int LAPACKE_ctrsna( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_float* t, lapack_int ldt, - const lapack_complex_float* vl, lapack_int ldvl, - const lapack_complex_float* vr, lapack_int ldvr, - float* s, float* sep, lapack_int mm, lapack_int* m ); -lapack_int LAPACKE_ztrsna( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_double* t, lapack_int ldt, - const lapack_complex_double* vl, lapack_int ldvl, - const lapack_complex_double* vr, lapack_int ldvr, - double* s, double* sep, lapack_int mm, - lapack_int* m ); - -lapack_int LAPACKE_strsyl( int matrix_order, char trana, char tranb, - lapack_int isgn, lapack_int m, lapack_int n, - const float* a, lapack_int lda, const float* b, - lapack_int ldb, float* c, lapack_int ldc, - float* scale ); -lapack_int LAPACKE_dtrsyl( int matrix_order, char trana, char tranb, - lapack_int isgn, lapack_int m, lapack_int n, - const double* a, lapack_int lda, const double* b, - lapack_int ldb, double* c, lapack_int ldc, - double* scale ); -lapack_int LAPACKE_ctrsyl( int matrix_order, char trana, char tranb, - lapack_int isgn, lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* c, lapack_int ldc, - float* scale ); -lapack_int LAPACKE_ztrsyl( int matrix_order, char trana, char tranb, - lapack_int isgn, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* c, lapack_int ldc, - double* scale ); - -lapack_int LAPACKE_strtri( int matrix_order, char uplo, char diag, lapack_int n, - float* a, lapack_int lda ); -lapack_int LAPACKE_dtrtri( int matrix_order, char uplo, char diag, lapack_int n, - double* a, lapack_int lda ); -lapack_int LAPACKE_ctrtri( int matrix_order, char uplo, char diag, lapack_int n, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_ztrtri( int matrix_order, char uplo, char diag, lapack_int n, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_strtrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, float* b, lapack_int ldb ); -lapack_int LAPACKE_dtrtrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, double* b, lapack_int ldb ); -lapack_int LAPACKE_ctrtrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_ztrtrs( int matrix_order, char uplo, char trans, char diag, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_strttf( int matrix_order, char transr, char uplo, - lapack_int n, const float* a, lapack_int lda, - float* arf ); -lapack_int LAPACKE_dtrttf( int matrix_order, char transr, char uplo, - lapack_int n, const double* a, lapack_int lda, - double* arf ); -lapack_int LAPACKE_ctrttf( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_float* a, - lapack_int lda, lapack_complex_float* arf ); -lapack_int LAPACKE_ztrttf( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_double* a, - lapack_int lda, lapack_complex_double* arf ); - -lapack_int LAPACKE_strttp( int matrix_order, char uplo, lapack_int n, - const float* a, lapack_int lda, float* ap ); -lapack_int LAPACKE_dtrttp( int matrix_order, char uplo, lapack_int n, - const double* a, lapack_int lda, double* ap ); -lapack_int LAPACKE_ctrttp( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - lapack_complex_float* ap ); -lapack_int LAPACKE_ztrttp( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - lapack_complex_double* ap ); - -lapack_int LAPACKE_stzrzf( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau ); -lapack_int LAPACKE_dtzrzf( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau ); -lapack_int LAPACKE_ctzrzf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau ); -lapack_int LAPACKE_ztzrzf( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau ); - -lapack_int LAPACKE_cungbr( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau ); -lapack_int LAPACKE_zungbr( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int k, lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* tau ); - -lapack_int LAPACKE_cunghr( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau ); -lapack_int LAPACKE_zunghr( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* tau ); - -lapack_int LAPACKE_cunglq( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau ); -lapack_int LAPACKE_zunglq( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* tau ); - -lapack_int LAPACKE_cungql( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau ); -lapack_int LAPACKE_zungql( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* tau ); - -lapack_int LAPACKE_cungqr( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau ); -lapack_int LAPACKE_zungqr( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* tau ); - -lapack_int LAPACKE_cungrq( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau ); -lapack_int LAPACKE_zungrq( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* tau ); - -lapack_int LAPACKE_cungtr( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau ); -lapack_int LAPACKE_zungtr( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau ); - -lapack_int LAPACKE_cunmbr( int matrix_order, char vect, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zunmbr( int matrix_order, char vect, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_cunmhr( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int ilo, - lapack_int ihi, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zunmhr( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int ilo, - lapack_int ihi, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_cunmlq( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zunmlq( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_cunmql( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zunmql( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_cunmqr( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zunmqr( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_cunmrq( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zunmrq( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_cunmrz( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zunmrz( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_cunmtr( int matrix_order, char side, char uplo, char trans, - lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zunmtr( int matrix_order, char side, char uplo, char trans, - lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_cupgtr( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, - const lapack_complex_float* tau, - lapack_complex_float* q, lapack_int ldq ); -lapack_int LAPACKE_zupgtr( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, - const lapack_complex_double* tau, - lapack_complex_double* q, lapack_int ldq ); - -lapack_int LAPACKE_cupmtr( int matrix_order, char side, char uplo, char trans, - lapack_int m, lapack_int n, - const lapack_complex_float* ap, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc ); -lapack_int LAPACKE_zupmtr( int matrix_order, char side, char uplo, char trans, - lapack_int m, lapack_int n, - const lapack_complex_double* ap, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc ); - -lapack_int LAPACKE_sbdsdc_work( int matrix_order, char uplo, char compq, - lapack_int n, float* d, float* e, float* u, - lapack_int ldu, float* vt, lapack_int ldvt, - float* q, lapack_int* iq, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dbdsdc_work( int matrix_order, char uplo, char compq, - lapack_int n, double* d, double* e, double* u, - lapack_int ldu, double* vt, lapack_int ldvt, - double* q, lapack_int* iq, double* work, - lapack_int* iwork ); - -lapack_int LAPACKE_sbdsqr_work( int matrix_order, char uplo, lapack_int n, - lapack_int ncvt, lapack_int nru, lapack_int ncc, - float* d, float* e, float* vt, lapack_int ldvt, - float* u, lapack_int ldu, float* c, - lapack_int ldc, float* work ); -lapack_int LAPACKE_dbdsqr_work( int matrix_order, char uplo, lapack_int n, - lapack_int ncvt, lapack_int nru, lapack_int ncc, - double* d, double* e, double* vt, - lapack_int ldvt, double* u, lapack_int ldu, - double* c, lapack_int ldc, double* work ); -lapack_int LAPACKE_cbdsqr_work( int matrix_order, char uplo, lapack_int n, - lapack_int ncvt, lapack_int nru, lapack_int ncc, - float* d, float* e, lapack_complex_float* vt, - lapack_int ldvt, lapack_complex_float* u, - lapack_int ldu, lapack_complex_float* c, - lapack_int ldc, float* work ); -lapack_int LAPACKE_zbdsqr_work( int matrix_order, char uplo, lapack_int n, - lapack_int ncvt, lapack_int nru, lapack_int ncc, - double* d, double* e, lapack_complex_double* vt, - lapack_int ldvt, lapack_complex_double* u, - lapack_int ldu, lapack_complex_double* c, - lapack_int ldc, double* work ); - -lapack_int LAPACKE_sdisna_work( char job, lapack_int m, lapack_int n, - const float* d, float* sep ); -lapack_int LAPACKE_ddisna_work( char job, lapack_int m, lapack_int n, - const double* d, double* sep ); - -lapack_int LAPACKE_sgbbrd_work( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int ncc, lapack_int kl, - lapack_int ku, float* ab, lapack_int ldab, - float* d, float* e, float* q, lapack_int ldq, - float* pt, lapack_int ldpt, float* c, - lapack_int ldc, float* work ); -lapack_int LAPACKE_dgbbrd_work( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int ncc, lapack_int kl, - lapack_int ku, double* ab, lapack_int ldab, - double* d, double* e, double* q, lapack_int ldq, - double* pt, lapack_int ldpt, double* c, - lapack_int ldc, double* work ); -lapack_int LAPACKE_cgbbrd_work( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int ncc, lapack_int kl, - lapack_int ku, lapack_complex_float* ab, - lapack_int ldab, float* d, float* e, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* pt, lapack_int ldpt, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zgbbrd_work( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int ncc, lapack_int kl, - lapack_int ku, lapack_complex_double* ab, - lapack_int ldab, double* d, double* e, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* pt, lapack_int ldpt, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgbcon_work( int matrix_order, char norm, lapack_int n, - lapack_int kl, lapack_int ku, const float* ab, - lapack_int ldab, const lapack_int* ipiv, - float anorm, float* rcond, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgbcon_work( int matrix_order, char norm, lapack_int n, - lapack_int kl, lapack_int ku, const double* ab, - lapack_int ldab, const lapack_int* ipiv, - double anorm, double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgbcon_work( int matrix_order, char norm, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_int* ipiv, float anorm, - float* rcond, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zgbcon_work( int matrix_order, char norm, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_double* ab, - lapack_int ldab, const lapack_int* ipiv, - double anorm, double* rcond, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgbequ_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const float* ab, - lapack_int ldab, float* r, float* c, - float* rowcnd, float* colcnd, float* amax ); -lapack_int LAPACKE_dgbequ_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const double* ab, - lapack_int ldab, double* r, double* c, - double* rowcnd, double* colcnd, double* amax ); -lapack_int LAPACKE_cgbequ_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_float* ab, lapack_int ldab, - float* r, float* c, float* rowcnd, - float* colcnd, float* amax ); -lapack_int LAPACKE_zgbequ_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_double* ab, - lapack_int ldab, double* r, double* c, - double* rowcnd, double* colcnd, double* amax ); - -lapack_int LAPACKE_sgbequb_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const float* ab, - lapack_int ldab, float* r, float* c, - float* rowcnd, float* colcnd, float* amax ); -lapack_int LAPACKE_dgbequb_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const double* ab, - lapack_int ldab, double* r, double* c, - double* rowcnd, double* colcnd, double* amax ); -lapack_int LAPACKE_cgbequb_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_float* ab, - lapack_int ldab, float* r, float* c, - float* rowcnd, float* colcnd, float* amax ); -lapack_int LAPACKE_zgbequb_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - const lapack_complex_double* ab, - lapack_int ldab, double* r, double* c, - double* rowcnd, double* colcnd, double* amax ); - -lapack_int LAPACKE_sgbrfs_work( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const float* ab, lapack_int ldab, - const float* afb, lapack_int ldafb, - const lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgbrfs_work( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const double* ab, lapack_int ldab, - const double* afb, lapack_int ldafb, - const lapack_int* ipiv, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* ferr, double* berr, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgbrfs_work( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_complex_float* afb, - lapack_int ldafb, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zgbrfs_work( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const lapack_complex_double* ab, - lapack_int ldab, - const lapack_complex_double* afb, - lapack_int ldafb, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgbrfsx_work( int matrix_order, char trans, char equed, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, const float* ab, - lapack_int ldab, const float* afb, - lapack_int ldafb, const lapack_int* ipiv, - const float* r, const float* c, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgbrfsx_work( int matrix_order, char trans, char equed, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, const double* ab, - lapack_int ldab, const double* afb, - lapack_int ldafb, const lapack_int* ipiv, - const double* r, const double* c, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgbrfsx_work( int matrix_order, char trans, char equed, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, - const lapack_complex_float* ab, - lapack_int ldab, - const lapack_complex_float* afb, - lapack_int ldafb, const lapack_int* ipiv, - const float* r, const float* c, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zgbrfsx_work( int matrix_order, char trans, char equed, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, - const lapack_complex_double* ab, - lapack_int ldab, - const lapack_complex_double* afb, - lapack_int ldafb, const lapack_int* ipiv, - const double* r, const double* c, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_sgbsv_work( int matrix_order, lapack_int n, lapack_int kl, - lapack_int ku, lapack_int nrhs, float* ab, - lapack_int ldab, lapack_int* ipiv, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dgbsv_work( int matrix_order, lapack_int n, lapack_int kl, - lapack_int ku, lapack_int nrhs, double* ab, - lapack_int ldab, lapack_int* ipiv, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cgbsv_work( int matrix_order, lapack_int n, lapack_int kl, - lapack_int ku, lapack_int nrhs, - lapack_complex_float* ab, lapack_int ldab, - lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgbsv_work( int matrix_order, lapack_int n, lapack_int kl, - lapack_int ku, lapack_int nrhs, - lapack_complex_double* ab, lapack_int ldab, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sgbsvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, float* ab, lapack_int ldab, - float* afb, lapack_int ldafb, lapack_int* ipiv, - char* equed, float* r, float* c, float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dgbsvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, double* ab, lapack_int ldab, - double* afb, lapack_int ldafb, lapack_int* ipiv, - char* equed, double* r, double* c, double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cgbsvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, lapack_complex_float* ab, - lapack_int ldab, lapack_complex_float* afb, - lapack_int ldafb, lapack_int* ipiv, char* equed, - float* r, float* c, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zgbsvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, lapack_complex_double* ab, - lapack_int ldab, lapack_complex_double* afb, - lapack_int ldafb, lapack_int* ipiv, char* equed, - double* r, double* c, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_sgbsvxx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, float* ab, lapack_int ldab, - float* afb, lapack_int ldafb, lapack_int* ipiv, - char* equed, float* r, float* c, float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgbsvxx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, double* ab, lapack_int ldab, - double* afb, lapack_int ldafb, - lapack_int* ipiv, char* equed, double* r, - double* c, double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgbsvxx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, lapack_complex_float* ab, - lapack_int ldab, lapack_complex_float* afb, - lapack_int ldafb, lapack_int* ipiv, - char* equed, float* r, float* c, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zgbsvxx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int kl, lapack_int ku, - lapack_int nrhs, lapack_complex_double* ab, - lapack_int ldab, lapack_complex_double* afb, - lapack_int ldafb, lapack_int* ipiv, - char* equed, double* r, double* c, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_sgbtrf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, float* ab, - lapack_int ldab, lapack_int* ipiv ); -lapack_int LAPACKE_dgbtrf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, double* ab, - lapack_int ldab, lapack_int* ipiv ); -lapack_int LAPACKE_cgbtrf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - lapack_complex_float* ab, lapack_int ldab, - lapack_int* ipiv ); -lapack_int LAPACKE_zgbtrf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, - lapack_complex_double* ab, lapack_int ldab, - lapack_int* ipiv ); - -lapack_int LAPACKE_sgbtrs_work( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const float* ab, lapack_int ldab, - const lapack_int* ipiv, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dgbtrs_work( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const double* ab, lapack_int ldab, - const lapack_int* ipiv, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cgbtrs_work( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgbtrs_work( int matrix_order, char trans, lapack_int n, - lapack_int kl, lapack_int ku, lapack_int nrhs, - const lapack_complex_double* ab, - lapack_int ldab, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sgebak_work( int matrix_order, char job, char side, - lapack_int n, lapack_int ilo, lapack_int ihi, - const float* scale, lapack_int m, float* v, - lapack_int ldv ); -lapack_int LAPACKE_dgebak_work( int matrix_order, char job, char side, - lapack_int n, lapack_int ilo, lapack_int ihi, - const double* scale, lapack_int m, double* v, - lapack_int ldv ); -lapack_int LAPACKE_cgebak_work( int matrix_order, char job, char side, - lapack_int n, lapack_int ilo, lapack_int ihi, - const float* scale, lapack_int m, - lapack_complex_float* v, lapack_int ldv ); -lapack_int LAPACKE_zgebak_work( int matrix_order, char job, char side, - lapack_int n, lapack_int ilo, lapack_int ihi, - const double* scale, lapack_int m, - lapack_complex_double* v, lapack_int ldv ); - -lapack_int LAPACKE_sgebal_work( int matrix_order, char job, lapack_int n, - float* a, lapack_int lda, lapack_int* ilo, - lapack_int* ihi, float* scale ); -lapack_int LAPACKE_dgebal_work( int matrix_order, char job, lapack_int n, - double* a, lapack_int lda, lapack_int* ilo, - lapack_int* ihi, double* scale ); -lapack_int LAPACKE_cgebal_work( int matrix_order, char job, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ilo, lapack_int* ihi, - float* scale ); -lapack_int LAPACKE_zgebal_work( int matrix_order, char job, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ilo, lapack_int* ihi, - double* scale ); - -lapack_int LAPACKE_sgebrd_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* d, float* e, - float* tauq, float* taup, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dgebrd_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* d, double* e, - double* tauq, double* taup, double* work, - lapack_int lwork ); -lapack_int LAPACKE_cgebrd_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - float* d, float* e, lapack_complex_float* tauq, - lapack_complex_float* taup, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgebrd_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - double* d, double* e, - lapack_complex_double* tauq, - lapack_complex_double* taup, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgecon_work( int matrix_order, char norm, lapack_int n, - const float* a, lapack_int lda, float anorm, - float* rcond, float* work, lapack_int* iwork ); -lapack_int LAPACKE_dgecon_work( int matrix_order, char norm, lapack_int n, - const double* a, lapack_int lda, double anorm, - double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgecon_work( int matrix_order, char norm, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float anorm, float* rcond, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zgecon_work( int matrix_order, char norm, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double anorm, double* rcond, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgeequ_work( int matrix_order, lapack_int m, lapack_int n, - const float* a, lapack_int lda, float* r, - float* c, float* rowcnd, float* colcnd, - float* amax ); -lapack_int LAPACKE_dgeequ_work( int matrix_order, lapack_int m, lapack_int n, - const double* a, lapack_int lda, double* r, - double* c, double* rowcnd, double* colcnd, - double* amax ); -lapack_int LAPACKE_cgeequ_work( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* r, float* c, float* rowcnd, - float* colcnd, float* amax ); -lapack_int LAPACKE_zgeequ_work( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* r, double* c, double* rowcnd, - double* colcnd, double* amax ); - -lapack_int LAPACKE_sgeequb_work( int matrix_order, lapack_int m, lapack_int n, - const float* a, lapack_int lda, float* r, - float* c, float* rowcnd, float* colcnd, - float* amax ); -lapack_int LAPACKE_dgeequb_work( int matrix_order, lapack_int m, lapack_int n, - const double* a, lapack_int lda, double* r, - double* c, double* rowcnd, double* colcnd, - double* amax ); -lapack_int LAPACKE_cgeequb_work( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* r, float* c, float* rowcnd, - float* colcnd, float* amax ); -lapack_int LAPACKE_zgeequb_work( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* r, double* c, double* rowcnd, - double* colcnd, double* amax ); - -lapack_int LAPACKE_sgees_work( int matrix_order, char jobvs, char sort, - LAPACK_S_SELECT2 select, lapack_int n, float* a, - lapack_int lda, lapack_int* sdim, float* wr, - float* wi, float* vs, lapack_int ldvs, - float* work, lapack_int lwork, - lapack_logical* bwork ); -lapack_int LAPACKE_dgees_work( int matrix_order, char jobvs, char sort, - LAPACK_D_SELECT2 select, lapack_int n, double* a, - lapack_int lda, lapack_int* sdim, double* wr, - double* wi, double* vs, lapack_int ldvs, - double* work, lapack_int lwork, - lapack_logical* bwork ); -lapack_int LAPACKE_cgees_work( int matrix_order, char jobvs, char sort, - LAPACK_C_SELECT1 select, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* sdim, lapack_complex_float* w, - lapack_complex_float* vs, lapack_int ldvs, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_logical* bwork ); -lapack_int LAPACKE_zgees_work( int matrix_order, char jobvs, char sort, - LAPACK_Z_SELECT1 select, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* sdim, lapack_complex_double* w, - lapack_complex_double* vs, lapack_int ldvs, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_logical* bwork ); - -lapack_int LAPACKE_sgeesx_work( int matrix_order, char jobvs, char sort, - LAPACK_S_SELECT2 select, char sense, - lapack_int n, float* a, lapack_int lda, - lapack_int* sdim, float* wr, float* wi, - float* vs, lapack_int ldvs, float* rconde, - float* rcondv, float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork, - lapack_logical* bwork ); -lapack_int LAPACKE_dgeesx_work( int matrix_order, char jobvs, char sort, - LAPACK_D_SELECT2 select, char sense, - lapack_int n, double* a, lapack_int lda, - lapack_int* sdim, double* wr, double* wi, - double* vs, lapack_int ldvs, double* rconde, - double* rcondv, double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork, - lapack_logical* bwork ); -lapack_int LAPACKE_cgeesx_work( int matrix_order, char jobvs, char sort, - LAPACK_C_SELECT1 select, char sense, - lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_int* sdim, - lapack_complex_float* w, - lapack_complex_float* vs, lapack_int ldvs, - float* rconde, float* rcondv, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_logical* bwork ); -lapack_int LAPACKE_zgeesx_work( int matrix_order, char jobvs, char sort, - LAPACK_Z_SELECT1 select, char sense, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_int* sdim, - lapack_complex_double* w, - lapack_complex_double* vs, lapack_int ldvs, - double* rconde, double* rcondv, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_logical* bwork ); - -lapack_int LAPACKE_sgeev_work( int matrix_order, char jobvl, char jobvr, - lapack_int n, float* a, lapack_int lda, - float* wr, float* wi, float* vl, lapack_int ldvl, - float* vr, lapack_int ldvr, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dgeev_work( int matrix_order, char jobvl, char jobvr, - lapack_int n, double* a, lapack_int lda, - double* wr, double* wi, double* vl, - lapack_int ldvl, double* vr, lapack_int ldvr, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgeev_work( int matrix_order, char jobvl, char jobvr, - lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* w, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_complex_float* work, lapack_int lwork, - float* rwork ); -lapack_int LAPACKE_zgeev_work( int matrix_order, char jobvl, char jobvr, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* w, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_complex_double* work, lapack_int lwork, - double* rwork ); - -lapack_int LAPACKE_sgeevx_work( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, float* a, - lapack_int lda, float* wr, float* wi, float* vl, - lapack_int ldvl, float* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, float* scale, - float* abnrm, float* rconde, float* rcondv, - float* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_dgeevx_work( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, double* a, - lapack_int lda, double* wr, double* wi, - double* vl, lapack_int ldvl, double* vr, - lapack_int ldvr, lapack_int* ilo, - lapack_int* ihi, double* scale, double* abnrm, - double* rconde, double* rcondv, double* work, - lapack_int lwork, lapack_int* iwork ); -lapack_int LAPACKE_cgeevx_work( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* w, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, float* scale, - float* abnrm, float* rconde, float* rcondv, - lapack_complex_float* work, lapack_int lwork, - float* rwork ); -lapack_int LAPACKE_zgeevx_work( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* w, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, double* scale, - double* abnrm, double* rconde, double* rcondv, - lapack_complex_double* work, lapack_int lwork, - double* rwork ); - -lapack_int LAPACKE_sgehrd_work( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, float* a, lapack_int lda, - float* tau, float* work, lapack_int lwork ); -lapack_int LAPACKE_dgehrd_work( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, double* a, lapack_int lda, - double* tau, double* work, lapack_int lwork ); -lapack_int LAPACKE_cgehrd_work( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgehrd_work( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgejsv_work( int matrix_order, char joba, char jobu, - char jobv, char jobr, char jobt, char jobp, - lapack_int m, lapack_int n, float* a, - lapack_int lda, float* sva, float* u, - lapack_int ldu, float* v, lapack_int ldv, - float* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_dgejsv_work( int matrix_order, char joba, char jobu, - char jobv, char jobr, char jobt, char jobp, - lapack_int m, lapack_int n, double* a, - lapack_int lda, double* sva, double* u, - lapack_int ldu, double* v, lapack_int ldv, - double* work, lapack_int lwork, - lapack_int* iwork ); - -lapack_int LAPACKE_sgelq2_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau, - float* work ); -lapack_int LAPACKE_dgelq2_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau, - double* work ); -lapack_int LAPACKE_cgelq2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau, - lapack_complex_float* work ); -lapack_int LAPACKE_zgelq2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau, - lapack_complex_double* work ); - -lapack_int LAPACKE_sgelqf_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dgelqf_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgelqf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgelqf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgels_work( int matrix_order, char trans, lapack_int m, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* b, lapack_int ldb, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dgels_work( int matrix_order, char trans, lapack_int m, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* b, lapack_int ldb, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgels_work( int matrix_order, char trans, lapack_int m, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgels_work( int matrix_order, char trans, lapack_int m, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgelsd_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, - float* b, lapack_int ldb, float* s, float rcond, - lapack_int* rank, float* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_dgelsd_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb, double* s, - double rcond, lapack_int* rank, double* work, - lapack_int lwork, lapack_int* iwork ); -lapack_int LAPACKE_cgelsd_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float* s, float rcond, - lapack_int* rank, lapack_complex_float* work, - lapack_int lwork, float* rwork, - lapack_int* iwork ); -lapack_int LAPACKE_zgelsd_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, double* s, double rcond, - lapack_int* rank, lapack_complex_double* work, - lapack_int lwork, double* rwork, - lapack_int* iwork ); - -lapack_int LAPACKE_sgelss_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, - float* b, lapack_int ldb, float* s, float rcond, - lapack_int* rank, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dgelss_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb, double* s, - double rcond, lapack_int* rank, double* work, - lapack_int lwork ); -lapack_int LAPACKE_cgelss_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float* s, float rcond, - lapack_int* rank, lapack_complex_float* work, - lapack_int lwork, float* rwork ); -lapack_int LAPACKE_zgelss_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, double* s, double rcond, - lapack_int* rank, lapack_complex_double* work, - lapack_int lwork, double* rwork ); - -lapack_int LAPACKE_sgelsy_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, - float* b, lapack_int ldb, lapack_int* jpvt, - float rcond, lapack_int* rank, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dgelsy_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb, lapack_int* jpvt, - double rcond, lapack_int* rank, double* work, - lapack_int lwork ); -lapack_int LAPACKE_cgelsy_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_int* jpvt, float rcond, - lapack_int* rank, lapack_complex_float* work, - lapack_int lwork, float* rwork ); -lapack_int LAPACKE_zgelsy_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_int* jpvt, double rcond, - lapack_int* rank, lapack_complex_double* work, - lapack_int lwork, double* rwork ); - -lapack_int LAPACKE_sgeqlf_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dgeqlf_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgeqlf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgeqlf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgeqp3_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, lapack_int* jpvt, - float* tau, float* work, lapack_int lwork ); -lapack_int LAPACKE_dgeqp3_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, lapack_int* jpvt, - double* tau, double* work, lapack_int lwork ); -lapack_int LAPACKE_cgeqp3_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* jpvt, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork, - float* rwork ); -lapack_int LAPACKE_zgeqp3_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* jpvt, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork, - double* rwork ); - -lapack_int LAPACKE_sgeqpf_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, lapack_int* jpvt, - float* tau, float* work ); -lapack_int LAPACKE_dgeqpf_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, lapack_int* jpvt, - double* tau, double* work ); -lapack_int LAPACKE_cgeqpf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* jpvt, lapack_complex_float* tau, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zgeqpf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* jpvt, lapack_complex_double* tau, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgeqr2_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau, - float* work ); -lapack_int LAPACKE_dgeqr2_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau, - double* work ); -lapack_int LAPACKE_cgeqr2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau, - lapack_complex_float* work ); -lapack_int LAPACKE_zgeqr2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau, - lapack_complex_double* work ); - -lapack_int LAPACKE_sgeqrf_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dgeqrf_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgeqrf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgeqrf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgeqrfp_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dgeqrfp_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgeqrfp_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgeqrfp_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau, - lapack_complex_double* work, - lapack_int lwork ); - -lapack_int LAPACKE_sgerfs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgerfs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const double* a, - lapack_int lda, const double* af, - lapack_int ldaf, const lapack_int* ipiv, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cgerfs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zgerfs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgerfsx_work( int matrix_order, char trans, char equed, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, const float* af, - lapack_int ldaf, const lapack_int* ipiv, - const float* r, const float* c, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgerfsx_work( int matrix_order, char trans, char equed, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, const double* af, - lapack_int ldaf, const lapack_int* ipiv, - const double* r, const double* c, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgerfsx_work( int matrix_order, char trans, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const float* r, const float* c, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zgerfsx_work( int matrix_order, char trans, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const double* r, const double* c, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_sgerqf_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dgerqf_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgerqf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgerqf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgesdd_work( int matrix_order, char jobz, lapack_int m, - lapack_int n, float* a, lapack_int lda, - float* s, float* u, lapack_int ldu, float* vt, - lapack_int ldvt, float* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_dgesdd_work( int matrix_order, char jobz, lapack_int m, - lapack_int n, double* a, lapack_int lda, - double* s, double* u, lapack_int ldu, - double* vt, lapack_int ldvt, double* work, - lapack_int lwork, lapack_int* iwork ); -lapack_int LAPACKE_cgesdd_work( int matrix_order, char jobz, lapack_int m, - lapack_int n, lapack_complex_float* a, - lapack_int lda, float* s, - lapack_complex_float* u, lapack_int ldu, - lapack_complex_float* vt, lapack_int ldvt, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_int* iwork ); -lapack_int LAPACKE_zgesdd_work( int matrix_order, char jobz, lapack_int m, - lapack_int n, lapack_complex_double* a, - lapack_int lda, double* s, - lapack_complex_double* u, lapack_int ldu, - lapack_complex_double* vt, lapack_int ldvt, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_int* iwork ); - -lapack_int LAPACKE_sgesv_work( int matrix_order, lapack_int n, lapack_int nrhs, - float* a, lapack_int lda, lapack_int* ipiv, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dgesv_work( int matrix_order, lapack_int n, lapack_int nrhs, - double* a, lapack_int lda, lapack_int* ipiv, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cgesv_work( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgesv_work( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); -lapack_int LAPACKE_dsgesv_work( int matrix_order, lapack_int n, lapack_int nrhs, - double* a, lapack_int lda, lapack_int* ipiv, - double* b, lapack_int ldb, double* x, - lapack_int ldx, double* work, float* swork, - lapack_int* iter ); -lapack_int LAPACKE_zcgesv_work( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, lapack_complex_double* work, - lapack_complex_float* swork, double* rwork, - lapack_int* iter ); - -lapack_int LAPACKE_sgesvd_work( int matrix_order, char jobu, char jobvt, - lapack_int m, lapack_int n, float* a, - lapack_int lda, float* s, float* u, - lapack_int ldu, float* vt, lapack_int ldvt, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dgesvd_work( int matrix_order, char jobu, char jobvt, - lapack_int m, lapack_int n, double* a, - lapack_int lda, double* s, double* u, - lapack_int ldu, double* vt, lapack_int ldvt, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgesvd_work( int matrix_order, char jobu, char jobvt, - lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - float* s, lapack_complex_float* u, - lapack_int ldu, lapack_complex_float* vt, - lapack_int ldvt, lapack_complex_float* work, - lapack_int lwork, float* rwork ); -lapack_int LAPACKE_zgesvd_work( int matrix_order, char jobu, char jobvt, - lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - double* s, lapack_complex_double* u, - lapack_int ldu, lapack_complex_double* vt, - lapack_int ldvt, lapack_complex_double* work, - lapack_int lwork, double* rwork ); - -lapack_int LAPACKE_sgesvj_work( int matrix_order, char joba, char jobu, - char jobv, lapack_int m, lapack_int n, float* a, - lapack_int lda, float* sva, lapack_int mv, - float* v, lapack_int ldv, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dgesvj_work( int matrix_order, char joba, char jobu, - char jobv, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* sva, - lapack_int mv, double* v, lapack_int ldv, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgesvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* r, - float* c, float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, float* work, lapack_int* iwork ); -lapack_int LAPACKE_dgesvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* r, - double* c, double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr, double* work, lapack_int* iwork ); -lapack_int LAPACKE_cgesvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* r, - float* c, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zgesvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* r, - double* c, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_sgesvxx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* r, - float* c, float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* rpvgrw, - float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgesvxx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* r, - double* c, double* b, lapack_int ldb, - double* x, lapack_int ldx, double* rcond, - double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgesvxx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* r, - float* c, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* rpvgrw, - float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zgesvxx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* r, - double* c, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* rpvgrw, - double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgetf2_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_dgetf2_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_cgetf2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv ); -lapack_int LAPACKE_zgetf2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv ); - -lapack_int LAPACKE_sgetrf_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_dgetrf_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, lapack_int* ipiv ); -lapack_int LAPACKE_cgetrf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv ); -lapack_int LAPACKE_zgetrf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv ); - -lapack_int LAPACKE_sgetri_work( int matrix_order, lapack_int n, float* a, - lapack_int lda, const lapack_int* ipiv, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dgetri_work( int matrix_order, lapack_int n, double* a, - lapack_int lda, const lapack_int* ipiv, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cgetri_work( int matrix_order, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgetri_work( int matrix_order, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgetrs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const lapack_int* ipiv, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dgetrs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const double* a, - lapack_int lda, const lapack_int* ipiv, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cgetrs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zgetrs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sggbak_work( int matrix_order, char job, char side, - lapack_int n, lapack_int ilo, lapack_int ihi, - const float* lscale, const float* rscale, - lapack_int m, float* v, lapack_int ldv ); -lapack_int LAPACKE_dggbak_work( int matrix_order, char job, char side, - lapack_int n, lapack_int ilo, lapack_int ihi, - const double* lscale, const double* rscale, - lapack_int m, double* v, lapack_int ldv ); -lapack_int LAPACKE_cggbak_work( int matrix_order, char job, char side, - lapack_int n, lapack_int ilo, lapack_int ihi, - const float* lscale, const float* rscale, - lapack_int m, lapack_complex_float* v, - lapack_int ldv ); -lapack_int LAPACKE_zggbak_work( int matrix_order, char job, char side, - lapack_int n, lapack_int ilo, lapack_int ihi, - const double* lscale, const double* rscale, - lapack_int m, lapack_complex_double* v, - lapack_int ldv ); - -lapack_int LAPACKE_sggbal_work( int matrix_order, char job, lapack_int n, - float* a, lapack_int lda, float* b, - lapack_int ldb, lapack_int* ilo, - lapack_int* ihi, float* lscale, float* rscale, - float* work ); -lapack_int LAPACKE_dggbal_work( int matrix_order, char job, lapack_int n, - double* a, lapack_int lda, double* b, - lapack_int ldb, lapack_int* ilo, - lapack_int* ihi, double* lscale, double* rscale, - double* work ); -lapack_int LAPACKE_cggbal_work( int matrix_order, char job, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_int* ilo, lapack_int* ihi, float* lscale, - float* rscale, float* work ); -lapack_int LAPACKE_zggbal_work( int matrix_order, char job, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_int* ilo, lapack_int* ihi, - double* lscale, double* rscale, double* work ); - -lapack_int LAPACKE_sgges_work( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_S_SELECT3 selctg, lapack_int n, - float* a, lapack_int lda, float* b, - lapack_int ldb, lapack_int* sdim, float* alphar, - float* alphai, float* beta, float* vsl, - lapack_int ldvsl, float* vsr, lapack_int ldvsr, - float* work, lapack_int lwork, - lapack_logical* bwork ); -lapack_int LAPACKE_dgges_work( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_D_SELECT3 selctg, lapack_int n, - double* a, lapack_int lda, double* b, - lapack_int ldb, lapack_int* sdim, double* alphar, - double* alphai, double* beta, double* vsl, - lapack_int ldvsl, double* vsr, lapack_int ldvsr, - double* work, lapack_int lwork, - lapack_logical* bwork ); -lapack_int LAPACKE_cgges_work( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_C_SELECT2 selctg, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_int* sdim, lapack_complex_float* alpha, - lapack_complex_float* beta, - lapack_complex_float* vsl, lapack_int ldvsl, - lapack_complex_float* vsr, lapack_int ldvsr, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_logical* bwork ); -lapack_int LAPACKE_zgges_work( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_Z_SELECT2 selctg, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_int* sdim, lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* vsl, lapack_int ldvsl, - lapack_complex_double* vsr, lapack_int ldvsr, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_logical* bwork ); - -lapack_int LAPACKE_sggesx_work( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_S_SELECT3 selctg, char sense, - lapack_int n, float* a, lapack_int lda, - float* b, lapack_int ldb, lapack_int* sdim, - float* alphar, float* alphai, float* beta, - float* vsl, lapack_int ldvsl, float* vsr, - lapack_int ldvsr, float* rconde, float* rcondv, - float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork, - lapack_logical* bwork ); -lapack_int LAPACKE_dggesx_work( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_D_SELECT3 selctg, char sense, - lapack_int n, double* a, lapack_int lda, - double* b, lapack_int ldb, lapack_int* sdim, - double* alphar, double* alphai, double* beta, - double* vsl, lapack_int ldvsl, double* vsr, - lapack_int ldvsr, double* rconde, - double* rcondv, double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork, - lapack_logical* bwork ); -lapack_int LAPACKE_cggesx_work( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_C_SELECT2 selctg, char sense, - lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_int* sdim, - lapack_complex_float* alpha, - lapack_complex_float* beta, - lapack_complex_float* vsl, lapack_int ldvsl, - lapack_complex_float* vsr, lapack_int ldvsr, - float* rconde, float* rcondv, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_int* iwork, - lapack_int liwork, lapack_logical* bwork ); -lapack_int LAPACKE_zggesx_work( int matrix_order, char jobvsl, char jobvsr, - char sort, LAPACK_Z_SELECT2 selctg, char sense, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_int* sdim, - lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* vsl, lapack_int ldvsl, - lapack_complex_double* vsr, lapack_int ldvsr, - double* rconde, double* rcondv, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_int* iwork, - lapack_int liwork, lapack_logical* bwork ); - -lapack_int LAPACKE_sggev_work( int matrix_order, char jobvl, char jobvr, - lapack_int n, float* a, lapack_int lda, float* b, - lapack_int ldb, float* alphar, float* alphai, - float* beta, float* vl, lapack_int ldvl, - float* vr, lapack_int ldvr, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dggev_work( int matrix_order, char jobvl, char jobvr, - lapack_int n, double* a, lapack_int lda, - double* b, lapack_int ldb, double* alphar, - double* alphai, double* beta, double* vl, - lapack_int ldvl, double* vr, lapack_int ldvr, - double* work, lapack_int lwork ); -lapack_int LAPACKE_cggev_work( int matrix_order, char jobvl, char jobvr, - lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* alpha, - lapack_complex_float* beta, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_complex_float* work, lapack_int lwork, - float* rwork ); -lapack_int LAPACKE_zggev_work( int matrix_order, char jobvl, char jobvr, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_complex_double* work, lapack_int lwork, - double* rwork ); - -lapack_int LAPACKE_sggevx_work( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - float* alphar, float* alphai, float* beta, - float* vl, lapack_int ldvl, float* vr, - lapack_int ldvr, lapack_int* ilo, - lapack_int* ihi, float* lscale, float* rscale, - float* abnrm, float* bbnrm, float* rconde, - float* rcondv, float* work, lapack_int lwork, - lapack_int* iwork, lapack_logical* bwork ); -lapack_int LAPACKE_dggevx_work( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - double* alphar, double* alphai, double* beta, - double* vl, lapack_int ldvl, double* vr, - lapack_int ldvr, lapack_int* ilo, - lapack_int* ihi, double* lscale, double* rscale, - double* abnrm, double* bbnrm, double* rconde, - double* rcondv, double* work, lapack_int lwork, - lapack_int* iwork, lapack_logical* bwork ); -lapack_int LAPACKE_cggevx_work( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* alpha, - lapack_complex_float* beta, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, float* lscale, - float* rscale, float* abnrm, float* bbnrm, - float* rconde, float* rcondv, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_int* iwork, - lapack_logical* bwork ); -lapack_int LAPACKE_zggevx_work( int matrix_order, char balanc, char jobvl, - char jobvr, char sense, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_int* ilo, lapack_int* ihi, - double* lscale, double* rscale, double* abnrm, - double* bbnrm, double* rconde, double* rcondv, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_int* iwork, - lapack_logical* bwork ); - -lapack_int LAPACKE_sggglm_work( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, float* a, lapack_int lda, - float* b, lapack_int ldb, float* d, float* x, - float* y, float* work, lapack_int lwork ); -lapack_int LAPACKE_dggglm_work( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, double* a, lapack_int lda, - double* b, lapack_int ldb, double* d, double* x, - double* y, double* work, lapack_int lwork ); -lapack_int LAPACKE_cggglm_work( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* d, - lapack_complex_float* x, - lapack_complex_float* y, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zggglm_work( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* d, - lapack_complex_double* x, - lapack_complex_double* y, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sgghrd_work( int matrix_order, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - float* a, lapack_int lda, float* b, - lapack_int ldb, float* q, lapack_int ldq, - float* z, lapack_int ldz ); -lapack_int LAPACKE_dgghrd_work( int matrix_order, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - double* a, lapack_int lda, double* b, - lapack_int ldb, double* q, lapack_int ldq, - double* z, lapack_int ldz ); -lapack_int LAPACKE_cgghrd_work( int matrix_order, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* z, lapack_int ldz ); -lapack_int LAPACKE_zgghrd_work( int matrix_order, char compq, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* z, lapack_int ldz ); - -lapack_int LAPACKE_sgglse_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int p, float* a, lapack_int lda, - float* b, lapack_int ldb, float* c, float* d, - float* x, float* work, lapack_int lwork ); -lapack_int LAPACKE_dgglse_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int p, double* a, lapack_int lda, - double* b, lapack_int ldb, double* c, double* d, - double* x, double* work, lapack_int lwork ); -lapack_int LAPACKE_cgglse_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int p, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* c, - lapack_complex_float* d, - lapack_complex_float* x, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zgglse_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int p, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* c, - lapack_complex_double* d, - lapack_complex_double* x, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sggqrf_work( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, float* a, lapack_int lda, - float* taua, float* b, lapack_int ldb, - float* taub, float* work, lapack_int lwork ); -lapack_int LAPACKE_dggqrf_work( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, double* a, lapack_int lda, - double* taua, double* b, lapack_int ldb, - double* taub, double* work, lapack_int lwork ); -lapack_int LAPACKE_cggqrf_work( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* taua, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* taub, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zggqrf_work( int matrix_order, lapack_int n, lapack_int m, - lapack_int p, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* taua, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* taub, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sggrqf_work( int matrix_order, lapack_int m, lapack_int p, - lapack_int n, float* a, lapack_int lda, - float* taua, float* b, lapack_int ldb, - float* taub, float* work, lapack_int lwork ); -lapack_int LAPACKE_dggrqf_work( int matrix_order, lapack_int m, lapack_int p, - lapack_int n, double* a, lapack_int lda, - double* taua, double* b, lapack_int ldb, - double* taub, double* work, lapack_int lwork ); -lapack_int LAPACKE_cggrqf_work( int matrix_order, lapack_int m, lapack_int p, - lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* taua, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* taub, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zggrqf_work( int matrix_order, lapack_int m, lapack_int p, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* taua, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* taub, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_sggsvd_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int n, - lapack_int p, lapack_int* k, lapack_int* l, - float* a, lapack_int lda, float* b, - lapack_int ldb, float* alpha, float* beta, - float* u, lapack_int ldu, float* v, - lapack_int ldv, float* q, lapack_int ldq, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dggsvd_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int n, - lapack_int p, lapack_int* k, lapack_int* l, - double* a, lapack_int lda, double* b, - lapack_int ldb, double* alpha, double* beta, - double* u, lapack_int ldu, double* v, - lapack_int ldv, double* q, lapack_int ldq, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cggsvd_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int n, - lapack_int p, lapack_int* k, lapack_int* l, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - float* alpha, float* beta, - lapack_complex_float* u, lapack_int ldu, - lapack_complex_float* v, lapack_int ldv, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* work, float* rwork, - lapack_int* iwork ); -lapack_int LAPACKE_zggsvd_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int n, - lapack_int p, lapack_int* k, lapack_int* l, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - double* alpha, double* beta, - lapack_complex_double* u, lapack_int ldu, - lapack_complex_double* v, lapack_int ldv, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* work, double* rwork, - lapack_int* iwork ); - -lapack_int LAPACKE_sggsvp_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int p, - lapack_int n, float* a, lapack_int lda, - float* b, lapack_int ldb, float tola, - float tolb, lapack_int* k, lapack_int* l, - float* u, lapack_int ldu, float* v, - lapack_int ldv, float* q, lapack_int ldq, - lapack_int* iwork, float* tau, float* work ); -lapack_int LAPACKE_dggsvp_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int p, - lapack_int n, double* a, lapack_int lda, - double* b, lapack_int ldb, double tola, - double tolb, lapack_int* k, lapack_int* l, - double* u, lapack_int ldu, double* v, - lapack_int ldv, double* q, lapack_int ldq, - lapack_int* iwork, double* tau, double* work ); -lapack_int LAPACKE_cggsvp_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int p, - lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float tola, float tolb, - lapack_int* k, lapack_int* l, - lapack_complex_float* u, lapack_int ldu, - lapack_complex_float* v, lapack_int ldv, - lapack_complex_float* q, lapack_int ldq, - lapack_int* iwork, float* rwork, - lapack_complex_float* tau, - lapack_complex_float* work ); -lapack_int LAPACKE_zggsvp_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int p, - lapack_int n, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, double tola, double tolb, - lapack_int* k, lapack_int* l, - lapack_complex_double* u, lapack_int ldu, - lapack_complex_double* v, lapack_int ldv, - lapack_complex_double* q, lapack_int ldq, - lapack_int* iwork, double* rwork, - lapack_complex_double* tau, - lapack_complex_double* work ); - -lapack_int LAPACKE_sgtcon_work( char norm, lapack_int n, const float* dl, - const float* d, const float* du, - const float* du2, const lapack_int* ipiv, - float anorm, float* rcond, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgtcon_work( char norm, lapack_int n, const double* dl, - const double* d, const double* du, - const double* du2, const lapack_int* ipiv, - double anorm, double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgtcon_work( char norm, lapack_int n, - const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* du2, - const lapack_int* ipiv, float anorm, - float* rcond, lapack_complex_float* work ); -lapack_int LAPACKE_zgtcon_work( char norm, lapack_int n, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* du2, - const lapack_int* ipiv, double anorm, - double* rcond, lapack_complex_double* work ); - -lapack_int LAPACKE_sgtrfs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const float* dl, - const float* d, const float* du, - const float* dlf, const float* df, - const float* duf, const float* du2, - const lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dgtrfs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const double* dl, - const double* d, const double* du, - const double* dlf, const double* df, - const double* duf, const double* du2, - const lapack_int* ipiv, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* ferr, double* berr, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cgtrfs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* dlf, - const lapack_complex_float* df, - const lapack_complex_float* duf, - const lapack_complex_float* du2, - const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zgtrfs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* dlf, - const lapack_complex_double* df, - const lapack_complex_double* duf, - const lapack_complex_double* du2, - const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgtsv_work( int matrix_order, lapack_int n, lapack_int nrhs, - float* dl, float* d, float* du, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dgtsv_work( int matrix_order, lapack_int n, lapack_int nrhs, - double* dl, double* d, double* du, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cgtsv_work( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_float* dl, - lapack_complex_float* d, - lapack_complex_float* du, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zgtsv_work( int matrix_order, lapack_int n, lapack_int nrhs, - lapack_complex_double* dl, - lapack_complex_double* d, - lapack_complex_double* du, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sgtsvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, const float* dl, - const float* d, const float* du, float* dlf, - float* df, float* duf, float* du2, - lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dgtsvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, const double* dl, - const double* d, const double* du, double* dlf, - double* df, double* duf, double* du2, - lapack_int* ipiv, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cgtsvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - lapack_complex_float* dlf, - lapack_complex_float* df, - lapack_complex_float* duf, - lapack_complex_float* du2, lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zgtsvx_work( int matrix_order, char fact, char trans, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - lapack_complex_double* dlf, - lapack_complex_double* df, - lapack_complex_double* duf, - lapack_complex_double* du2, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sgttrf_work( lapack_int n, float* dl, float* d, float* du, - float* du2, lapack_int* ipiv ); -lapack_int LAPACKE_dgttrf_work( lapack_int n, double* dl, double* d, double* du, - double* du2, lapack_int* ipiv ); -lapack_int LAPACKE_cgttrf_work( lapack_int n, lapack_complex_float* dl, - lapack_complex_float* d, - lapack_complex_float* du, - lapack_complex_float* du2, lapack_int* ipiv ); -lapack_int LAPACKE_zgttrf_work( lapack_int n, lapack_complex_double* dl, - lapack_complex_double* d, - lapack_complex_double* du, - lapack_complex_double* du2, lapack_int* ipiv ); - -lapack_int LAPACKE_sgttrs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const float* dl, - const float* d, const float* du, - const float* du2, const lapack_int* ipiv, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dgttrs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const double* dl, - const double* d, const double* du, - const double* du2, const lapack_int* ipiv, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cgttrs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* du2, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zgttrs_work( int matrix_order, char trans, lapack_int n, - lapack_int nrhs, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* du2, - const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_chbev_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int kd, - lapack_complex_float* ab, lapack_int ldab, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zhbev_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int kd, - lapack_complex_double* ab, lapack_int ldab, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_chbevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int kd, - lapack_complex_float* ab, lapack_int ldab, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - lapack_int lwork, float* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_zhbevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int kd, - lapack_complex_double* ab, lapack_int ldab, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - lapack_int lwork, double* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); - -lapack_int LAPACKE_chbevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, lapack_int kd, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* q, lapack_int ldq, - float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - float* rwork, lapack_int* iwork, - lapack_int* ifail ); -lapack_int LAPACKE_zhbevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, lapack_int kd, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* q, lapack_int ldq, - double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - double* rwork, lapack_int* iwork, - lapack_int* ifail ); - -lapack_int LAPACKE_chbgst_work( int matrix_order, char vect, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - lapack_complex_float* ab, lapack_int ldab, - const lapack_complex_float* bb, lapack_int ldbb, - lapack_complex_float* x, lapack_int ldx, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zhbgst_work( int matrix_order, char vect, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - lapack_complex_double* ab, lapack_int ldab, - const lapack_complex_double* bb, - lapack_int ldbb, lapack_complex_double* x, - lapack_int ldx, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_chbgv_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* bb, lapack_int ldbb, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zhbgv_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* bb, lapack_int ldbb, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_chbgvd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* bb, lapack_int ldbb, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - lapack_int lwork, float* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_zhbgvd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* bb, lapack_int ldbb, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - lapack_int lwork, double* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); - -lapack_int LAPACKE_chbgvx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, lapack_int ka, - lapack_int kb, lapack_complex_float* ab, - lapack_int ldab, lapack_complex_float* bb, - lapack_int ldbb, lapack_complex_float* q, - lapack_int ldq, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_complex_float* work, float* rwork, - lapack_int* iwork, lapack_int* ifail ); -lapack_int LAPACKE_zhbgvx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, lapack_int ka, - lapack_int kb, lapack_complex_double* ab, - lapack_int ldab, lapack_complex_double* bb, - lapack_int ldbb, lapack_complex_double* q, - lapack_int ldq, double vl, double vu, - lapack_int il, lapack_int iu, double abstol, - lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_complex_double* work, double* rwork, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_chbtrd_work( int matrix_order, char vect, char uplo, - lapack_int n, lapack_int kd, - lapack_complex_float* ab, lapack_int ldab, - float* d, float* e, lapack_complex_float* q, - lapack_int ldq, lapack_complex_float* work ); -lapack_int LAPACKE_zhbtrd_work( int matrix_order, char vect, char uplo, - lapack_int n, lapack_int kd, - lapack_complex_double* ab, lapack_int ldab, - double* d, double* e, lapack_complex_double* q, - lapack_int ldq, lapack_complex_double* work ); - -lapack_int LAPACKE_checon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, float anorm, - float* rcond, lapack_complex_float* work ); -lapack_int LAPACKE_zhecon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, double anorm, - double* rcond, lapack_complex_double* work ); - -lapack_int LAPACKE_cheequb_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* s, float* scond, float* amax, - lapack_complex_float* work ); -lapack_int LAPACKE_zheequb_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* s, double* scond, double* amax, - lapack_complex_double* work ); - -lapack_int LAPACKE_cheev_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_complex_float* a, - lapack_int lda, float* w, - lapack_complex_float* work, lapack_int lwork, - float* rwork ); -lapack_int LAPACKE_zheev_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_complex_double* a, - lapack_int lda, double* w, - lapack_complex_double* work, lapack_int lwork, - double* rwork ); - -lapack_int LAPACKE_cheevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_complex_float* a, - lapack_int lda, float* w, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_int lrwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_zheevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_complex_double* a, - lapack_int lda, double* w, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_int lrwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_cheevr_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_int* isuppz, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_int lrwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_zheevr_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_int* isuppz, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_int lrwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_cheevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - lapack_int lwork, float* rwork, - lapack_int* iwork, lapack_int* ifail ); -lapack_int LAPACKE_zheevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - lapack_int lwork, double* rwork, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_chegst_work( int matrix_order, lapack_int itype, char uplo, - lapack_int n, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zhegst_work( int matrix_order, lapack_int itype, char uplo, - lapack_int n, lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_chegv_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb, float* w, - lapack_complex_float* work, lapack_int lwork, - float* rwork ); -lapack_int LAPACKE_zhegv_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - double* w, lapack_complex_double* work, - lapack_int lwork, double* rwork ); - -lapack_int LAPACKE_chegvd_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - float* w, lapack_complex_float* work, - lapack_int lwork, float* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_zhegvd_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - double* w, lapack_complex_double* work, - lapack_int lwork, double* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); - -lapack_int LAPACKE_chegvx_work( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - lapack_int lwork, float* rwork, - lapack_int* iwork, lapack_int* ifail ); -lapack_int LAPACKE_zhegvx_work( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - lapack_int lwork, double* rwork, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_cherfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zherfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_cherfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const float* s, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zherfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const double* s, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_chesv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zhesv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_chesvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, lapack_complex_float* work, - lapack_int lwork, float* rwork ); -lapack_int LAPACKE_zhesvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, lapack_int lwork, - double* rwork ); - -lapack_int LAPACKE_chesvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* s, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zhesvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_chetrd_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - float* d, float* e, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zhetrd_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - double* d, double* e, - lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_chetrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_float* work, - lapack_int lwork ); -lapack_int LAPACKE_zhetrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_double* work, - lapack_int lwork ); - -lapack_int LAPACKE_chetri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_float* work ); -lapack_int LAPACKE_zhetri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_double* work ); - -lapack_int LAPACKE_chetrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zhetrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_chfrk_work( int matrix_order, char transr, char uplo, - char trans, lapack_int n, lapack_int k, - float alpha, const lapack_complex_float* a, - lapack_int lda, float beta, - lapack_complex_float* c ); -lapack_int LAPACKE_zhfrk_work( int matrix_order, char transr, char uplo, - char trans, lapack_int n, lapack_int k, - double alpha, const lapack_complex_double* a, - lapack_int lda, double beta, - lapack_complex_double* c ); - -lapack_int LAPACKE_shgeqz_work( int matrix_order, char job, char compq, - char compz, lapack_int n, lapack_int ilo, - lapack_int ihi, float* h, lapack_int ldh, - float* t, lapack_int ldt, float* alphar, - float* alphai, float* beta, float* q, - lapack_int ldq, float* z, lapack_int ldz, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dhgeqz_work( int matrix_order, char job, char compq, - char compz, lapack_int n, lapack_int ilo, - lapack_int ihi, double* h, lapack_int ldh, - double* t, lapack_int ldt, double* alphar, - double* alphai, double* beta, double* q, - lapack_int ldq, double* z, lapack_int ldz, - double* work, lapack_int lwork ); -lapack_int LAPACKE_chgeqz_work( int matrix_order, char job, char compq, - char compz, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_float* h, - lapack_int ldh, lapack_complex_float* t, - lapack_int ldt, lapack_complex_float* alpha, - lapack_complex_float* beta, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* z, lapack_int ldz, - lapack_complex_float* work, lapack_int lwork, - float* rwork ); -lapack_int LAPACKE_zhgeqz_work( int matrix_order, char job, char compq, - char compz, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_double* h, - lapack_int ldh, lapack_complex_double* t, - lapack_int ldt, lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* z, lapack_int ldz, - lapack_complex_double* work, lapack_int lwork, - double* rwork ); - -lapack_int LAPACKE_chpcon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, - const lapack_int* ipiv, float anorm, - float* rcond, lapack_complex_float* work ); -lapack_int LAPACKE_zhpcon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, - const lapack_int* ipiv, double anorm, - double* rcond, lapack_complex_double* work ); - -lapack_int LAPACKE_chpev_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_complex_float* ap, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zhpev_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_complex_double* ap, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_chpevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_complex_float* ap, - float* w, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - lapack_int lwork, float* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_zhpevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_complex_double* ap, - double* w, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - lapack_int lwork, double* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); - -lapack_int LAPACKE_chpevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, - lapack_complex_float* ap, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_complex_float* work, float* rwork, - lapack_int* iwork, lapack_int* ifail ); -lapack_int LAPACKE_zhpevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, - lapack_complex_double* ap, double vl, double vu, - lapack_int il, lapack_int iu, double abstol, - lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_complex_double* work, double* rwork, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_chpgst_work( int matrix_order, lapack_int itype, char uplo, - lapack_int n, lapack_complex_float* ap, - const lapack_complex_float* bp ); -lapack_int LAPACKE_zhpgst_work( int matrix_order, lapack_int itype, char uplo, - lapack_int n, lapack_complex_double* ap, - const lapack_complex_double* bp ); - -lapack_int LAPACKE_chpgv_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, - lapack_complex_float* ap, - lapack_complex_float* bp, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zhpgv_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, - lapack_complex_double* ap, - lapack_complex_double* bp, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_chpgvd_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, - lapack_complex_float* ap, - lapack_complex_float* bp, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_int lrwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_zhpgvd_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, - lapack_complex_double* ap, - lapack_complex_double* bp, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_int lrwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_chpgvx_work( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, - lapack_complex_float* ap, - lapack_complex_float* bp, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_complex_float* work, float* rwork, - lapack_int* iwork, lapack_int* ifail ); -lapack_int LAPACKE_zhpgvx_work( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, - lapack_complex_double* ap, - lapack_complex_double* bp, double vl, double vu, - lapack_int il, lapack_int iu, double abstol, - lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_complex_double* work, double* rwork, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_chprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_complex_float* afp, - const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zhprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, - const lapack_complex_double* ap, - const lapack_complex_double* afp, - const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_chpsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* ap, - lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zhpsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* ap, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_chpsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* ap, - lapack_complex_float* afp, lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zhpsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* ap, - lapack_complex_double* afp, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_chptrd_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, float* d, float* e, - lapack_complex_float* tau ); -lapack_int LAPACKE_zhptrd_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, double* d, double* e, - lapack_complex_double* tau ); - -lapack_int LAPACKE_chptrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, lapack_int* ipiv ); -lapack_int LAPACKE_zhptrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, lapack_int* ipiv ); - -lapack_int LAPACKE_chptri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, - const lapack_int* ipiv, - lapack_complex_float* work ); -lapack_int LAPACKE_zhptri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, - const lapack_int* ipiv, - lapack_complex_double* work ); - -lapack_int LAPACKE_chptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zhptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, - const lapack_complex_double* ap, - const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_shsein_work( int matrix_order, char job, char eigsrc, - char initv, lapack_logical* select, - lapack_int n, const float* h, lapack_int ldh, - float* wr, const float* wi, float* vl, - lapack_int ldvl, float* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, float* work, - lapack_int* ifaill, lapack_int* ifailr ); -lapack_int LAPACKE_dhsein_work( int matrix_order, char job, char eigsrc, - char initv, lapack_logical* select, - lapack_int n, const double* h, lapack_int ldh, - double* wr, const double* wi, double* vl, - lapack_int ldvl, double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, double* work, - lapack_int* ifaill, lapack_int* ifailr ); -lapack_int LAPACKE_chsein_work( int matrix_order, char job, char eigsrc, - char initv, const lapack_logical* select, - lapack_int n, const lapack_complex_float* h, - lapack_int ldh, lapack_complex_float* w, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, - lapack_complex_float* work, float* rwork, - lapack_int* ifaill, lapack_int* ifailr ); -lapack_int LAPACKE_zhsein_work( int matrix_order, char job, char eigsrc, - char initv, const lapack_logical* select, - lapack_int n, const lapack_complex_double* h, - lapack_int ldh, lapack_complex_double* w, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, - lapack_complex_double* work, double* rwork, - lapack_int* ifaill, lapack_int* ifailr ); - -lapack_int LAPACKE_shseqr_work( int matrix_order, char job, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - float* h, lapack_int ldh, float* wr, float* wi, - float* z, lapack_int ldz, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dhseqr_work( int matrix_order, char job, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - double* h, lapack_int ldh, double* wr, - double* wi, double* z, lapack_int ldz, - double* work, lapack_int lwork ); -lapack_int LAPACKE_chseqr_work( int matrix_order, char job, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - lapack_complex_float* h, lapack_int ldh, - lapack_complex_float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zhseqr_work( int matrix_order, char job, char compz, - lapack_int n, lapack_int ilo, lapack_int ihi, - lapack_complex_double* h, lapack_int ldh, - lapack_complex_double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_clacgv_work( lapack_int n, lapack_complex_float* x, - lapack_int incx ); -lapack_int LAPACKE_zlacgv_work( lapack_int n, lapack_complex_double* x, - lapack_int incx ); - -lapack_int LAPACKE_slacpy_work( int matrix_order, char uplo, lapack_int m, - lapack_int n, const float* a, lapack_int lda, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dlacpy_work( int matrix_order, char uplo, lapack_int m, - lapack_int n, const double* a, lapack_int lda, - double* b, lapack_int ldb ); -lapack_int LAPACKE_clacpy_work( int matrix_order, char uplo, lapack_int m, - lapack_int n, const lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zlacpy_work( int matrix_order, char uplo, lapack_int m, - lapack_int n, const lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_zlag2c_work( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - lapack_complex_float* sa, lapack_int ldsa ); - -lapack_int LAPACKE_slag2d_work( int matrix_order, lapack_int m, lapack_int n, - const float* sa, lapack_int ldsa, double* a, - lapack_int lda ); - -lapack_int LAPACKE_dlag2s_work( int matrix_order, lapack_int m, lapack_int n, - const double* a, lapack_int lda, float* sa, - lapack_int ldsa ); - -lapack_int LAPACKE_clag2z_work( int matrix_order, lapack_int m, lapack_int n, - const lapack_complex_float* sa, lapack_int ldsa, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_slagge_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const float* d, - float* a, lapack_int lda, lapack_int* iseed, - float* work ); -lapack_int LAPACKE_dlagge_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const double* d, - double* a, lapack_int lda, lapack_int* iseed, - double* work ); -lapack_int LAPACKE_clagge_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const float* d, - lapack_complex_float* a, lapack_int lda, - lapack_int* iseed, lapack_complex_float* work ); -lapack_int LAPACKE_zlagge_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int kl, lapack_int ku, const double* d, - lapack_complex_double* a, lapack_int lda, - lapack_int* iseed, - lapack_complex_double* work ); - -lapack_int LAPACKE_claghe_work( int matrix_order, lapack_int n, lapack_int k, - const float* d, lapack_complex_float* a, - lapack_int lda, lapack_int* iseed, - lapack_complex_float* work ); -lapack_int LAPACKE_zlaghe_work( int matrix_order, lapack_int n, lapack_int k, - const double* d, lapack_complex_double* a, - lapack_int lda, lapack_int* iseed, - lapack_complex_double* work ); - -lapack_int LAPACKE_slagsy_work( int matrix_order, lapack_int n, lapack_int k, - const float* d, float* a, lapack_int lda, - lapack_int* iseed, float* work ); -lapack_int LAPACKE_dlagsy_work( int matrix_order, lapack_int n, lapack_int k, - const double* d, double* a, lapack_int lda, - lapack_int* iseed, double* work ); -lapack_int LAPACKE_clagsy_work( int matrix_order, lapack_int n, lapack_int k, - const float* d, lapack_complex_float* a, - lapack_int lda, lapack_int* iseed, - lapack_complex_float* work ); -lapack_int LAPACKE_zlagsy_work( int matrix_order, lapack_int n, lapack_int k, - const double* d, lapack_complex_double* a, - lapack_int lda, lapack_int* iseed, - lapack_complex_double* work ); - -lapack_int LAPACKE_slapmr_work( int matrix_order, lapack_logical forwrd, - lapack_int m, lapack_int n, float* x, - lapack_int ldx, lapack_int* k ); -lapack_int LAPACKE_dlapmr_work( int matrix_order, lapack_logical forwrd, - lapack_int m, lapack_int n, double* x, - lapack_int ldx, lapack_int* k ); -lapack_int LAPACKE_clapmr_work( int matrix_order, lapack_logical forwrd, - lapack_int m, lapack_int n, - lapack_complex_float* x, lapack_int ldx, - lapack_int* k ); -lapack_int LAPACKE_zlapmr_work( int matrix_order, lapack_logical forwrd, - lapack_int m, lapack_int n, - lapack_complex_double* x, lapack_int ldx, - lapack_int* k ); - -lapack_int LAPACKE_slartgp_work( float f, float g, float* cs, float* sn, - float* r ); -lapack_int LAPACKE_dlartgp_work( double f, double g, double* cs, double* sn, - double* r ); - -lapack_int LAPACKE_slartgs_work( float x, float y, float sigma, float* cs, - float* sn ); -lapack_int LAPACKE_dlartgs_work( double x, double y, double sigma, double* cs, - double* sn ); - -float LAPACKE_slapy2_work( float x, float y ); -double LAPACKE_dlapy2_work( double x, double y ); - -float LAPACKE_slapy3_work( float x, float y, float z ); -double LAPACKE_dlapy3_work( double x, double y, double z ); - -float LAPACKE_slamch_work( char cmach ); -double LAPACKE_dlamch_work( char cmach ); - -float LAPACKE_slange_work( int matrix_order, char norm, lapack_int m, - lapack_int n, const float* a, lapack_int lda, - float* work ); -double LAPACKE_dlange_work( int matrix_order, char norm, lapack_int m, - lapack_int n, const double* a, lapack_int lda, - double* work ); -float LAPACKE_clange_work( int matrix_order, char norm, lapack_int m, - lapack_int n, const lapack_complex_float* a, - lapack_int lda, float* work ); -double LAPACKE_zlange_work( int matrix_order, char norm, lapack_int m, - lapack_int n, const lapack_complex_double* a, - lapack_int lda, double* work ); - -float LAPACKE_clanhe_work( int matrix_order, char norm, char uplo, - lapack_int n, const lapack_complex_float* a, - lapack_int lda, float* work ); -double LAPACKE_zlanhe_work( int matrix_order, char norm, char uplo, - lapack_int n, const lapack_complex_double* a, - lapack_int lda, double* work ); - -float LAPACKE_slansy_work( int matrix_order, char norm, char uplo, - lapack_int n, const float* a, lapack_int lda, - float* work ); -double LAPACKE_dlansy_work( int matrix_order, char norm, char uplo, - lapack_int n, const double* a, lapack_int lda, - double* work ); -float LAPACKE_clansy_work( int matrix_order, char norm, char uplo, - lapack_int n, const lapack_complex_float* a, - lapack_int lda, float* work ); -double LAPACKE_zlansy_work( int matrix_order, char norm, char uplo, - lapack_int n, const lapack_complex_double* a, - lapack_int lda, double* work ); - -float LAPACKE_slantr_work( int matrix_order, char norm, char uplo, - char diag, lapack_int m, lapack_int n, const float* a, - lapack_int lda, float* work ); -double LAPACKE_dlantr_work( int matrix_order, char norm, char uplo, - char diag, lapack_int m, lapack_int n, - const double* a, lapack_int lda, double* work ); -float LAPACKE_clantr_work( int matrix_order, char norm, char uplo, - char diag, lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* work ); -double LAPACKE_zlantr_work( int matrix_order, char norm, char uplo, - char diag, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* work ); - -lapack_int LAPACKE_slarfb_work( int matrix_order, char side, char trans, - char direct, char storev, lapack_int m, - lapack_int n, lapack_int k, const float* v, - lapack_int ldv, const float* t, lapack_int ldt, - float* c, lapack_int ldc, float* work, - lapack_int ldwork ); -lapack_int LAPACKE_dlarfb_work( int matrix_order, char side, char trans, - char direct, char storev, lapack_int m, - lapack_int n, lapack_int k, const double* v, - lapack_int ldv, const double* t, lapack_int ldt, - double* c, lapack_int ldc, double* work, - lapack_int ldwork ); -lapack_int LAPACKE_clarfb_work( int matrix_order, char side, char trans, - char direct, char storev, lapack_int m, - lapack_int n, lapack_int k, - const lapack_complex_float* v, lapack_int ldv, - const lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int ldwork ); -lapack_int LAPACKE_zlarfb_work( int matrix_order, char side, char trans, - char direct, char storev, lapack_int m, - lapack_int n, lapack_int k, - const lapack_complex_double* v, lapack_int ldv, - const lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, - lapack_int ldwork ); - -lapack_int LAPACKE_slarfg_work( lapack_int n, float* alpha, float* x, - lapack_int incx, float* tau ); -lapack_int LAPACKE_dlarfg_work( lapack_int n, double* alpha, double* x, - lapack_int incx, double* tau ); -lapack_int LAPACKE_clarfg_work( lapack_int n, lapack_complex_float* alpha, - lapack_complex_float* x, lapack_int incx, - lapack_complex_float* tau ); -lapack_int LAPACKE_zlarfg_work( lapack_int n, lapack_complex_double* alpha, - lapack_complex_double* x, lapack_int incx, - lapack_complex_double* tau ); - -lapack_int LAPACKE_slarft_work( int matrix_order, char direct, char storev, - lapack_int n, lapack_int k, const float* v, - lapack_int ldv, const float* tau, float* t, - lapack_int ldt ); -lapack_int LAPACKE_dlarft_work( int matrix_order, char direct, char storev, - lapack_int n, lapack_int k, const double* v, - lapack_int ldv, const double* tau, double* t, - lapack_int ldt ); -lapack_int LAPACKE_clarft_work( int matrix_order, char direct, char storev, - lapack_int n, lapack_int k, - const lapack_complex_float* v, lapack_int ldv, - const lapack_complex_float* tau, - lapack_complex_float* t, lapack_int ldt ); -lapack_int LAPACKE_zlarft_work( int matrix_order, char direct, char storev, - lapack_int n, lapack_int k, - const lapack_complex_double* v, lapack_int ldv, - const lapack_complex_double* tau, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_slarfx_work( int matrix_order, char side, lapack_int m, - lapack_int n, const float* v, float tau, - float* c, lapack_int ldc, float* work ); -lapack_int LAPACKE_dlarfx_work( int matrix_order, char side, lapack_int m, - lapack_int n, const double* v, double tau, - double* c, lapack_int ldc, double* work ); -lapack_int LAPACKE_clarfx_work( int matrix_order, char side, lapack_int m, - lapack_int n, const lapack_complex_float* v, - lapack_complex_float tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work ); -lapack_int LAPACKE_zlarfx_work( int matrix_order, char side, lapack_int m, - lapack_int n, const lapack_complex_double* v, - lapack_complex_double tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work ); - -lapack_int LAPACKE_slarnv_work( lapack_int idist, lapack_int* iseed, - lapack_int n, float* x ); -lapack_int LAPACKE_dlarnv_work( lapack_int idist, lapack_int* iseed, - lapack_int n, double* x ); -lapack_int LAPACKE_clarnv_work( lapack_int idist, lapack_int* iseed, - lapack_int n, lapack_complex_float* x ); -lapack_int LAPACKE_zlarnv_work( lapack_int idist, lapack_int* iseed, - lapack_int n, lapack_complex_double* x ); - -lapack_int LAPACKE_slaset_work( int matrix_order, char uplo, lapack_int m, - lapack_int n, float alpha, float beta, float* a, - lapack_int lda ); -lapack_int LAPACKE_dlaset_work( int matrix_order, char uplo, lapack_int m, - lapack_int n, double alpha, double beta, - double* a, lapack_int lda ); -lapack_int LAPACKE_claset_work( int matrix_order, char uplo, lapack_int m, - lapack_int n, lapack_complex_float alpha, - lapack_complex_float beta, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zlaset_work( int matrix_order, char uplo, lapack_int m, - lapack_int n, lapack_complex_double alpha, - lapack_complex_double beta, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_slasrt_work( char id, lapack_int n, float* d ); -lapack_int LAPACKE_dlasrt_work( char id, lapack_int n, double* d ); - -lapack_int LAPACKE_slaswp_work( int matrix_order, lapack_int n, float* a, - lapack_int lda, lapack_int k1, lapack_int k2, - const lapack_int* ipiv, lapack_int incx ); -lapack_int LAPACKE_dlaswp_work( int matrix_order, lapack_int n, double* a, - lapack_int lda, lapack_int k1, lapack_int k2, - const lapack_int* ipiv, lapack_int incx ); -lapack_int LAPACKE_claswp_work( int matrix_order, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int k1, lapack_int k2, - const lapack_int* ipiv, lapack_int incx ); -lapack_int LAPACKE_zlaswp_work( int matrix_order, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int k1, lapack_int k2, - const lapack_int* ipiv, lapack_int incx ); - -lapack_int LAPACKE_slatms_work( int matrix_order, lapack_int m, lapack_int n, - char dist, lapack_int* iseed, char sym, - float* d, lapack_int mode, float cond, - float dmax, lapack_int kl, lapack_int ku, - char pack, float* a, lapack_int lda, - float* work ); -lapack_int LAPACKE_dlatms_work( int matrix_order, lapack_int m, lapack_int n, - char dist, lapack_int* iseed, char sym, - double* d, lapack_int mode, double cond, - double dmax, lapack_int kl, lapack_int ku, - char pack, double* a, lapack_int lda, - double* work ); -lapack_int LAPACKE_clatms_work( int matrix_order, lapack_int m, lapack_int n, - char dist, lapack_int* iseed, char sym, - float* d, lapack_int mode, float cond, - float dmax, lapack_int kl, lapack_int ku, - char pack, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* work ); -lapack_int LAPACKE_zlatms_work( int matrix_order, lapack_int m, lapack_int n, - char dist, lapack_int* iseed, char sym, - double* d, lapack_int mode, double cond, - double dmax, lapack_int kl, lapack_int ku, - char pack, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* work ); - -lapack_int LAPACKE_slauum_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda ); -lapack_int LAPACKE_dlauum_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda ); -lapack_int LAPACKE_clauum_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zlauum_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_sopgtr_work( int matrix_order, char uplo, lapack_int n, - const float* ap, const float* tau, float* q, - lapack_int ldq, float* work ); -lapack_int LAPACKE_dopgtr_work( int matrix_order, char uplo, lapack_int n, - const double* ap, const double* tau, double* q, - lapack_int ldq, double* work ); - -lapack_int LAPACKE_sopmtr_work( int matrix_order, char side, char uplo, - char trans, lapack_int m, lapack_int n, - const float* ap, const float* tau, float* c, - lapack_int ldc, float* work ); -lapack_int LAPACKE_dopmtr_work( int matrix_order, char side, char uplo, - char trans, lapack_int m, lapack_int n, - const double* ap, const double* tau, double* c, - lapack_int ldc, double* work ); - -lapack_int LAPACKE_sorgbr_work( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int k, float* a, - lapack_int lda, const float* tau, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dorgbr_work( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int k, double* a, - lapack_int lda, const double* tau, double* work, - lapack_int lwork ); - -lapack_int LAPACKE_sorghr_work( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, float* a, lapack_int lda, - const float* tau, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dorghr_work( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, double* a, lapack_int lda, - const double* tau, double* work, - lapack_int lwork ); - -lapack_int LAPACKE_sorglq_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, float* a, lapack_int lda, - const float* tau, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dorglq_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, double* a, lapack_int lda, - const double* tau, double* work, - lapack_int lwork ); - -lapack_int LAPACKE_sorgql_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, float* a, lapack_int lda, - const float* tau, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dorgql_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, double* a, lapack_int lda, - const double* tau, double* work, - lapack_int lwork ); - -lapack_int LAPACKE_sorgqr_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, float* a, lapack_int lda, - const float* tau, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dorgqr_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, double* a, lapack_int lda, - const double* tau, double* work, - lapack_int lwork ); - -lapack_int LAPACKE_sorgrq_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, float* a, lapack_int lda, - const float* tau, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dorgrq_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, double* a, lapack_int lda, - const double* tau, double* work, - lapack_int lwork ); - -lapack_int LAPACKE_sorgtr_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda, const float* tau, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dorgtr_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, const double* tau, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sormbr_work( int matrix_order, char vect, char side, - char trans, lapack_int m, lapack_int n, - lapack_int k, const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dormbr_work( int matrix_order, char vect, char side, - char trans, lapack_int m, lapack_int n, - lapack_int k, const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sormhr_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int ilo, - lapack_int ihi, const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dormhr_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int ilo, - lapack_int ihi, const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sormlq_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dormlq_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sormql_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dormql_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sormqr_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dormqr_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sormrq_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dormrq_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sormrz_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dormrz_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_sormtr_work( int matrix_order, char side, char uplo, - char trans, lapack_int m, lapack_int n, - const float* a, lapack_int lda, - const float* tau, float* c, lapack_int ldc, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dormtr_work( int matrix_order, char side, char uplo, - char trans, lapack_int m, lapack_int n, - const double* a, lapack_int lda, - const double* tau, double* c, lapack_int ldc, - double* work, lapack_int lwork ); - -lapack_int LAPACKE_spbcon_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const float* ab, lapack_int ldab, - float anorm, float* rcond, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dpbcon_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const double* ab, - lapack_int ldab, double anorm, double* rcond, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cpbcon_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const lapack_complex_float* ab, - lapack_int ldab, float anorm, float* rcond, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zpbcon_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const lapack_complex_double* ab, - lapack_int ldab, double anorm, double* rcond, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_spbequ_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const float* ab, lapack_int ldab, - float* s, float* scond, float* amax ); -lapack_int LAPACKE_dpbequ_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const double* ab, - lapack_int ldab, double* s, double* scond, - double* amax ); -lapack_int LAPACKE_cpbequ_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const lapack_complex_float* ab, - lapack_int ldab, float* s, float* scond, - float* amax ); -lapack_int LAPACKE_zpbequ_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, const lapack_complex_double* ab, - lapack_int ldab, double* s, double* scond, - double* amax ); - -lapack_int LAPACKE_spbrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, const float* ab, - lapack_int ldab, const float* afb, - lapack_int ldafb, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dpbrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const double* ab, lapack_int ldab, - const double* afb, lapack_int ldafb, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cpbrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - const lapack_complex_float* afb, - lapack_int ldafb, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zpbrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const lapack_complex_double* ab, - lapack_int ldab, - const lapack_complex_double* afb, - lapack_int ldafb, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_spbstf_work( int matrix_order, char uplo, lapack_int n, - lapack_int kb, float* bb, lapack_int ldbb ); -lapack_int LAPACKE_dpbstf_work( int matrix_order, char uplo, lapack_int n, - lapack_int kb, double* bb, lapack_int ldbb ); -lapack_int LAPACKE_cpbstf_work( int matrix_order, char uplo, lapack_int n, - lapack_int kb, lapack_complex_float* bb, - lapack_int ldbb ); -lapack_int LAPACKE_zpbstf_work( int matrix_order, char uplo, lapack_int n, - lapack_int kb, lapack_complex_double* bb, - lapack_int ldbb ); - -lapack_int LAPACKE_spbsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, float* ab, - lapack_int ldab, float* b, lapack_int ldb ); -lapack_int LAPACKE_dpbsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, double* ab, - lapack_int ldab, double* b, lapack_int ldb ); -lapack_int LAPACKE_cpbsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpbsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_spbsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int kd, lapack_int nrhs, - float* ab, lapack_int ldab, float* afb, - lapack_int ldafb, char* equed, float* s, - float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, float* work, lapack_int* iwork ); -lapack_int LAPACKE_dpbsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int kd, lapack_int nrhs, - double* ab, lapack_int ldab, double* afb, - lapack_int ldafb, char* equed, double* s, - double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr, double* work, lapack_int* iwork ); -lapack_int LAPACKE_cpbsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int kd, lapack_int nrhs, - lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* afb, lapack_int ldafb, - char* equed, float* s, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zpbsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int kd, lapack_int nrhs, - lapack_complex_double* ab, lapack_int ldab, - lapack_complex_double* afb, lapack_int ldafb, - char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_spbtrf_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, float* ab, lapack_int ldab ); -lapack_int LAPACKE_dpbtrf_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, double* ab, lapack_int ldab ); -lapack_int LAPACKE_cpbtrf_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_complex_float* ab, - lapack_int ldab ); -lapack_int LAPACKE_zpbtrf_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_complex_double* ab, - lapack_int ldab ); - -lapack_int LAPACKE_spbtrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, const float* ab, - lapack_int ldab, float* b, lapack_int ldb ); -lapack_int LAPACKE_dpbtrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const double* ab, lapack_int ldab, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cpbtrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const lapack_complex_float* ab, lapack_int ldab, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpbtrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int kd, lapack_int nrhs, - const lapack_complex_double* ab, - lapack_int ldab, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_spftrf_work( int matrix_order, char transr, char uplo, - lapack_int n, float* a ); -lapack_int LAPACKE_dpftrf_work( int matrix_order, char transr, char uplo, - lapack_int n, double* a ); -lapack_int LAPACKE_cpftrf_work( int matrix_order, char transr, char uplo, - lapack_int n, lapack_complex_float* a ); -lapack_int LAPACKE_zpftrf_work( int matrix_order, char transr, char uplo, - lapack_int n, lapack_complex_double* a ); - -lapack_int LAPACKE_spftri_work( int matrix_order, char transr, char uplo, - lapack_int n, float* a ); -lapack_int LAPACKE_dpftri_work( int matrix_order, char transr, char uplo, - lapack_int n, double* a ); -lapack_int LAPACKE_cpftri_work( int matrix_order, char transr, char uplo, - lapack_int n, lapack_complex_float* a ); -lapack_int LAPACKE_zpftri_work( int matrix_order, char transr, char uplo, - lapack_int n, lapack_complex_double* a ); - -lapack_int LAPACKE_spftrs_work( int matrix_order, char transr, char uplo, - lapack_int n, lapack_int nrhs, const float* a, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dpftrs_work( int matrix_order, char transr, char uplo, - lapack_int n, lapack_int nrhs, const double* a, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cpftrs_work( int matrix_order, char transr, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpftrs_work( int matrix_order, char transr, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_spocon_work( int matrix_order, char uplo, lapack_int n, - const float* a, lapack_int lda, float anorm, - float* rcond, float* work, lapack_int* iwork ); -lapack_int LAPACKE_dpocon_work( int matrix_order, char uplo, lapack_int n, - const double* a, lapack_int lda, double anorm, - double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cpocon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float anorm, float* rcond, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zpocon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double anorm, double* rcond, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_spoequ_work( int matrix_order, lapack_int n, const float* a, - lapack_int lda, float* s, float* scond, - float* amax ); -lapack_int LAPACKE_dpoequ_work( int matrix_order, lapack_int n, const double* a, - lapack_int lda, double* s, double* scond, - double* amax ); -lapack_int LAPACKE_cpoequ_work( int matrix_order, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* s, float* scond, float* amax ); -lapack_int LAPACKE_zpoequ_work( int matrix_order, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* s, double* scond, double* amax ); - -lapack_int LAPACKE_spoequb_work( int matrix_order, lapack_int n, const float* a, - lapack_int lda, float* s, float* scond, - float* amax ); -lapack_int LAPACKE_dpoequb_work( int matrix_order, lapack_int n, - const double* a, lapack_int lda, double* s, - double* scond, double* amax ); -lapack_int LAPACKE_cpoequb_work( int matrix_order, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* s, float* scond, float* amax ); -lapack_int LAPACKE_zpoequb_work( int matrix_order, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* s, double* scond, double* amax ); - -lapack_int LAPACKE_sporfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const float* af, lapack_int ldaf, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* ferr, float* berr, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dporfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, - lapack_int lda, const double* af, - lapack_int ldaf, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* ferr, double* berr, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cporfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* af, - lapack_int ldaf, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zporfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* af, - lapack_int ldaf, const lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sporfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, const float* af, - lapack_int ldaf, const float* s, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dporfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, const double* af, - lapack_int ldaf, const double* s, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cporfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* af, - lapack_int ldaf, const float* s, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zporfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* af, - lapack_int ldaf, const double* s, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_sposv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dposv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cposv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zposv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb ); -lapack_int LAPACKE_dsposv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - double* b, lapack_int ldb, double* x, - lapack_int ldx, double* work, float* swork, - lapack_int* iter ); -lapack_int LAPACKE_zcposv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, lapack_complex_double* work, - lapack_complex_float* swork, double* rwork, - lapack_int* iter ); - -lapack_int LAPACKE_sposvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - char* equed, float* s, float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, - float* ferr, float* berr, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dposvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - char* equed, double* s, double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cposvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - char* equed, float* s, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zposvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sposvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - char* equed, float* s, float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dposvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - char* equed, double* s, double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cposvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - char* equed, float* s, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* rpvgrw, - float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zposvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_spotrf_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda ); -lapack_int LAPACKE_dpotrf_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda ); -lapack_int LAPACKE_cpotrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zpotrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_spotri_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda ); -lapack_int LAPACKE_dpotri_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda ); -lapack_int LAPACKE_cpotri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zpotri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_spotrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dpotrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, - lapack_int lda, double* b, lapack_int ldb ); -lapack_int LAPACKE_cpotrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zpotrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sppcon_work( int matrix_order, char uplo, lapack_int n, - const float* ap, float anorm, float* rcond, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dppcon_work( int matrix_order, char uplo, lapack_int n, - const double* ap, double anorm, double* rcond, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cppcon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, float anorm, - float* rcond, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zppcon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, double anorm, - double* rcond, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_sppequ_work( int matrix_order, char uplo, lapack_int n, - const float* ap, float* s, float* scond, - float* amax ); -lapack_int LAPACKE_dppequ_work( int matrix_order, char uplo, lapack_int n, - const double* ap, double* s, double* scond, - double* amax ); -lapack_int LAPACKE_cppequ_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, float* s, - float* scond, float* amax ); -lapack_int LAPACKE_zppequ_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, double* s, - double* scond, double* amax ); - -lapack_int LAPACKE_spprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, - const float* afp, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dpprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, - const double* afp, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* ferr, double* berr, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cpprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_complex_float* afp, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zpprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, - const lapack_complex_double* ap, - const lapack_complex_double* afp, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sppsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, float* ap, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dppsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* ap, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cppsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* ap, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zppsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* ap, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sppsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, float* ap, - float* afp, char* equed, float* s, float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dppsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, double* ap, - double* afp, char* equed, double* s, double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cppsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_float* ap, - lapack_complex_float* afp, char* equed, - float* s, lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zppsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_double* ap, - lapack_complex_double* afp, char* equed, - double* s, lapack_complex_double* b, - lapack_int ldb, lapack_complex_double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_spptrf_work( int matrix_order, char uplo, lapack_int n, - float* ap ); -lapack_int LAPACKE_dpptrf_work( int matrix_order, char uplo, lapack_int n, - double* ap ); -lapack_int LAPACKE_cpptrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap ); -lapack_int LAPACKE_zpptrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap ); - -lapack_int LAPACKE_spptri_work( int matrix_order, char uplo, lapack_int n, - float* ap ); -lapack_int LAPACKE_dpptri_work( int matrix_order, char uplo, lapack_int n, - double* ap ); -lapack_int LAPACKE_cpptri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap ); -lapack_int LAPACKE_zpptri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap ); - -lapack_int LAPACKE_spptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dpptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cpptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, - const lapack_complex_double* ap, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_spstrf_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda, lapack_int* piv, - lapack_int* rank, float tol, float* work ); -lapack_int LAPACKE_dpstrf_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, lapack_int* piv, - lapack_int* rank, double tol, double* work ); -lapack_int LAPACKE_cpstrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* piv, lapack_int* rank, float tol, - float* work ); -lapack_int LAPACKE_zpstrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* piv, lapack_int* rank, double tol, - double* work ); - -lapack_int LAPACKE_sptcon_work( lapack_int n, const float* d, const float* e, - float anorm, float* rcond, float* work ); -lapack_int LAPACKE_dptcon_work( lapack_int n, const double* d, const double* e, - double anorm, double* rcond, double* work ); -lapack_int LAPACKE_cptcon_work( lapack_int n, const float* d, - const lapack_complex_float* e, float anorm, - float* rcond, float* work ); -lapack_int LAPACKE_zptcon_work( lapack_int n, const double* d, - const lapack_complex_double* e, double anorm, - double* rcond, double* work ); - -lapack_int LAPACKE_spteqr_work( int matrix_order, char compz, lapack_int n, - float* d, float* e, float* z, lapack_int ldz, - float* work ); -lapack_int LAPACKE_dpteqr_work( int matrix_order, char compz, lapack_int n, - double* d, double* e, double* z, lapack_int ldz, - double* work ); -lapack_int LAPACKE_cpteqr_work( int matrix_order, char compz, lapack_int n, - float* d, float* e, lapack_complex_float* z, - lapack_int ldz, float* work ); -lapack_int LAPACKE_zpteqr_work( int matrix_order, char compz, lapack_int n, - double* d, double* e, lapack_complex_double* z, - lapack_int ldz, double* work ); - -lapack_int LAPACKE_sptrfs_work( int matrix_order, lapack_int n, lapack_int nrhs, - const float* d, const float* e, const float* df, - const float* ef, const float* b, lapack_int ldb, - float* x, lapack_int ldx, float* ferr, - float* berr, float* work ); -lapack_int LAPACKE_dptrfs_work( int matrix_order, lapack_int n, lapack_int nrhs, - const double* d, const double* e, - const double* df, const double* ef, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr, - double* work ); -lapack_int LAPACKE_cptrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* d, - const lapack_complex_float* e, const float* df, - const lapack_complex_float* ef, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zptrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* d, - const lapack_complex_double* e, - const double* df, - const lapack_complex_double* ef, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sptsv_work( int matrix_order, lapack_int n, lapack_int nrhs, - float* d, float* e, float* b, lapack_int ldb ); -lapack_int LAPACKE_dptsv_work( int matrix_order, lapack_int n, lapack_int nrhs, - double* d, double* e, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cptsv_work( int matrix_order, lapack_int n, lapack_int nrhs, - float* d, lapack_complex_float* e, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zptsv_work( int matrix_order, lapack_int n, lapack_int nrhs, - double* d, lapack_complex_double* e, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sptsvx_work( int matrix_order, char fact, lapack_int n, - lapack_int nrhs, const float* d, const float* e, - float* df, float* ef, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* work ); -lapack_int LAPACKE_dptsvx_work( int matrix_order, char fact, lapack_int n, - lapack_int nrhs, const double* d, - const double* e, double* df, double* ef, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* ferr, - double* berr, double* work ); -lapack_int LAPACKE_cptsvx_work( int matrix_order, char fact, lapack_int n, - lapack_int nrhs, const float* d, - const lapack_complex_float* e, float* df, - lapack_complex_float* ef, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zptsvx_work( int matrix_order, char fact, lapack_int n, - lapack_int nrhs, const double* d, - const lapack_complex_double* e, double* df, - lapack_complex_double* ef, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_spttrf_work( lapack_int n, float* d, float* e ); -lapack_int LAPACKE_dpttrf_work( lapack_int n, double* d, double* e ); -lapack_int LAPACKE_cpttrf_work( lapack_int n, float* d, - lapack_complex_float* e ); -lapack_int LAPACKE_zpttrf_work( lapack_int n, double* d, - lapack_complex_double* e ); - -lapack_int LAPACKE_spttrs_work( int matrix_order, lapack_int n, lapack_int nrhs, - const float* d, const float* e, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dpttrs_work( int matrix_order, lapack_int n, lapack_int nrhs, - const double* d, const double* e, double* b, - lapack_int ldb ); -lapack_int LAPACKE_cpttrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* d, - const lapack_complex_float* e, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zpttrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* d, - const lapack_complex_double* e, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_ssbev_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int kd, float* ab, - lapack_int ldab, float* w, float* z, - lapack_int ldz, float* work ); -lapack_int LAPACKE_dsbev_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int kd, double* ab, - lapack_int ldab, double* w, double* z, - lapack_int ldz, double* work ); - -lapack_int LAPACKE_ssbevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int kd, float* ab, - lapack_int ldab, float* w, float* z, - lapack_int ldz, float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dsbevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int kd, double* ab, - lapack_int ldab, double* w, double* z, - lapack_int ldz, double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_ssbevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, lapack_int kd, - float* ab, lapack_int ldab, float* q, - lapack_int ldq, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, - lapack_int ldz, float* work, lapack_int* iwork, - lapack_int* ifail ); -lapack_int LAPACKE_dsbevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, lapack_int kd, - double* ab, lapack_int ldab, double* q, - lapack_int ldq, double vl, double vu, - lapack_int il, lapack_int iu, double abstol, - lapack_int* m, double* w, double* z, - lapack_int ldz, double* work, lapack_int* iwork, - lapack_int* ifail ); - -lapack_int LAPACKE_ssbgst_work( int matrix_order, char vect, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - float* ab, lapack_int ldab, const float* bb, - lapack_int ldbb, float* x, lapack_int ldx, - float* work ); -lapack_int LAPACKE_dsbgst_work( int matrix_order, char vect, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - double* ab, lapack_int ldab, const double* bb, - lapack_int ldbb, double* x, lapack_int ldx, - double* work ); - -lapack_int LAPACKE_ssbgv_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - float* ab, lapack_int ldab, float* bb, - lapack_int ldbb, float* w, float* z, - lapack_int ldz, float* work ); -lapack_int LAPACKE_dsbgv_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - double* ab, lapack_int ldab, double* bb, - lapack_int ldbb, double* w, double* z, - lapack_int ldz, double* work ); - -lapack_int LAPACKE_ssbgvd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - float* ab, lapack_int ldab, float* bb, - lapack_int ldbb, float* w, float* z, - lapack_int ldz, float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dsbgvd_work( int matrix_order, char jobz, char uplo, - lapack_int n, lapack_int ka, lapack_int kb, - double* ab, lapack_int ldab, double* bb, - lapack_int ldbb, double* w, double* z, - lapack_int ldz, double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_ssbgvx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, lapack_int ka, - lapack_int kb, float* ab, lapack_int ldab, - float* bb, lapack_int ldbb, float* q, - lapack_int ldq, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, - lapack_int ldz, float* work, lapack_int* iwork, - lapack_int* ifail ); -lapack_int LAPACKE_dsbgvx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, lapack_int ka, - lapack_int kb, double* ab, lapack_int ldab, - double* bb, lapack_int ldbb, double* q, - lapack_int ldq, double vl, double vu, - lapack_int il, lapack_int iu, double abstol, - lapack_int* m, double* w, double* z, - lapack_int ldz, double* work, lapack_int* iwork, - lapack_int* ifail ); - -lapack_int LAPACKE_ssbtrd_work( int matrix_order, char vect, char uplo, - lapack_int n, lapack_int kd, float* ab, - lapack_int ldab, float* d, float* e, float* q, - lapack_int ldq, float* work ); -lapack_int LAPACKE_dsbtrd_work( int matrix_order, char vect, char uplo, - lapack_int n, lapack_int kd, double* ab, - lapack_int ldab, double* d, double* e, - double* q, lapack_int ldq, double* work ); - -lapack_int LAPACKE_ssfrk_work( int matrix_order, char transr, char uplo, - char trans, lapack_int n, lapack_int k, - float alpha, const float* a, lapack_int lda, - float beta, float* c ); -lapack_int LAPACKE_dsfrk_work( int matrix_order, char transr, char uplo, - char trans, lapack_int n, lapack_int k, - double alpha, const double* a, lapack_int lda, - double beta, double* c ); - -lapack_int LAPACKE_sspcon_work( int matrix_order, char uplo, lapack_int n, - const float* ap, const lapack_int* ipiv, - float anorm, float* rcond, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dspcon_work( int matrix_order, char uplo, lapack_int n, - const double* ap, const lapack_int* ipiv, - double anorm, double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_cspcon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, - const lapack_int* ipiv, float anorm, - float* rcond, lapack_complex_float* work ); -lapack_int LAPACKE_zspcon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, - const lapack_int* ipiv, double anorm, - double* rcond, lapack_complex_double* work ); - -lapack_int LAPACKE_sspev_work( int matrix_order, char jobz, char uplo, - lapack_int n, float* ap, float* w, float* z, - lapack_int ldz, float* work ); -lapack_int LAPACKE_dspev_work( int matrix_order, char jobz, char uplo, - lapack_int n, double* ap, double* w, double* z, - lapack_int ldz, double* work ); - -lapack_int LAPACKE_sspevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, float* ap, float* w, float* z, - lapack_int ldz, float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dspevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, double* ap, double* w, double* z, - lapack_int ldz, double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_sspevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, float* ap, float vl, - float vu, lapack_int il, lapack_int iu, - float abstol, lapack_int* m, float* w, float* z, - lapack_int ldz, float* work, lapack_int* iwork, - lapack_int* ifail ); -lapack_int LAPACKE_dspevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, double* ap, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - double* z, lapack_int ldz, double* work, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_sspgst_work( int matrix_order, lapack_int itype, char uplo, - lapack_int n, float* ap, const float* bp ); -lapack_int LAPACKE_dspgst_work( int matrix_order, lapack_int itype, char uplo, - lapack_int n, double* ap, const double* bp ); - -lapack_int LAPACKE_sspgv_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, float* ap, float* bp, - float* w, float* z, lapack_int ldz, - float* work ); -lapack_int LAPACKE_dspgv_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, double* ap, double* bp, - double* w, double* z, lapack_int ldz, - double* work ); - -lapack_int LAPACKE_sspgvd_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, float* ap, float* bp, - float* w, float* z, lapack_int ldz, float* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_dspgvd_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, double* ap, double* bp, - double* w, double* z, lapack_int ldz, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_sspgvx_work( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, float* ap, - float* bp, float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, - float* w, float* z, lapack_int ldz, float* work, - lapack_int* iwork, lapack_int* ifail ); -lapack_int LAPACKE_dspgvx_work( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, double* ap, - double* bp, double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, double* z, lapack_int ldz, - double* work, lapack_int* iwork, - lapack_int* ifail ); - -lapack_int LAPACKE_ssprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, - const float* afp, const lapack_int* ipiv, - const float* b, lapack_int ldb, float* x, - lapack_int ldx, float* ferr, float* berr, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dsprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, - const double* afp, const lapack_int* ipiv, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_csprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_complex_float* afp, - const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zsprfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, - const lapack_complex_double* ap, - const lapack_complex_double* afp, - const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_sspsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, float* ap, lapack_int* ipiv, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dspsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* ap, lapack_int* ipiv, - double* b, lapack_int ldb ); -lapack_int LAPACKE_cspsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* ap, - lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zspsv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* ap, - lapack_int* ipiv, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_sspsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, const float* ap, - float* afp, lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dspsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, const double* ap, - double* afp, lapack_int* ipiv, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_cspsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* ap, - lapack_complex_float* afp, lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zspsvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* ap, - lapack_complex_double* afp, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_ssptrd_work( int matrix_order, char uplo, lapack_int n, - float* ap, float* d, float* e, float* tau ); -lapack_int LAPACKE_dsptrd_work( int matrix_order, char uplo, lapack_int n, - double* ap, double* d, double* e, double* tau ); - -lapack_int LAPACKE_ssptrf_work( int matrix_order, char uplo, lapack_int n, - float* ap, lapack_int* ipiv ); -lapack_int LAPACKE_dsptrf_work( int matrix_order, char uplo, lapack_int n, - double* ap, lapack_int* ipiv ); -lapack_int LAPACKE_csptrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, lapack_int* ipiv ); -lapack_int LAPACKE_zsptrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, lapack_int* ipiv ); - -lapack_int LAPACKE_ssptri_work( int matrix_order, char uplo, lapack_int n, - float* ap, const lapack_int* ipiv, - float* work ); -lapack_int LAPACKE_dsptri_work( int matrix_order, char uplo, lapack_int n, - double* ap, const lapack_int* ipiv, - double* work ); -lapack_int LAPACKE_csptri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* ap, - const lapack_int* ipiv, - lapack_complex_float* work ); -lapack_int LAPACKE_zsptri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* ap, - const lapack_int* ipiv, - lapack_complex_double* work ); - -lapack_int LAPACKE_ssptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* ap, - const lapack_int* ipiv, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dsptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* ap, - const lapack_int* ipiv, double* b, - lapack_int ldb ); -lapack_int LAPACKE_csptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* ap, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_zsptrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, - const lapack_complex_double* ap, - const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_sstebz_work( char range, char order, lapack_int n, float vl, - float vu, lapack_int il, lapack_int iu, - float abstol, const float* d, const float* e, - lapack_int* m, lapack_int* nsplit, float* w, - lapack_int* iblock, lapack_int* isplit, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dstebz_work( char range, char order, lapack_int n, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, const double* d, const double* e, - lapack_int* m, lapack_int* nsplit, double* w, - lapack_int* iblock, lapack_int* isplit, - double* work, lapack_int* iwork ); - -lapack_int LAPACKE_sstedc_work( int matrix_order, char compz, lapack_int n, - float* d, float* e, float* z, lapack_int ldz, - float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dstedc_work( int matrix_order, char compz, lapack_int n, - double* d, double* e, double* z, lapack_int ldz, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_cstedc_work( int matrix_order, char compz, lapack_int n, - float* d, float* e, lapack_complex_float* z, - lapack_int ldz, lapack_complex_float* work, - lapack_int lwork, float* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_zstedc_work( int matrix_order, char compz, lapack_int n, - double* d, double* e, lapack_complex_double* z, - lapack_int ldz, lapack_complex_double* work, - lapack_int lwork, double* rwork, - lapack_int lrwork, lapack_int* iwork, - lapack_int liwork ); - -lapack_int LAPACKE_sstegr_work( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, - float vu, lapack_int il, lapack_int iu, - float abstol, lapack_int* m, float* w, float* z, - lapack_int ldz, lapack_int* isuppz, float* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_dstegr_work( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - double* z, lapack_int ldz, lapack_int* isuppz, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_cstegr_work( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, - float vu, lapack_int il, lapack_int iu, - float abstol, lapack_int* m, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_int* isuppz, float* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_zstegr_work( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_int* isuppz, double* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); - -lapack_int LAPACKE_sstein_work( int matrix_order, lapack_int n, const float* d, - const float* e, lapack_int m, const float* w, - const lapack_int* iblock, - const lapack_int* isplit, float* z, - lapack_int ldz, float* work, lapack_int* iwork, - lapack_int* ifailv ); -lapack_int LAPACKE_dstein_work( int matrix_order, lapack_int n, const double* d, - const double* e, lapack_int m, const double* w, - const lapack_int* iblock, - const lapack_int* isplit, double* z, - lapack_int ldz, double* work, lapack_int* iwork, - lapack_int* ifailv ); -lapack_int LAPACKE_cstein_work( int matrix_order, lapack_int n, const float* d, - const float* e, lapack_int m, const float* w, - const lapack_int* iblock, - const lapack_int* isplit, - lapack_complex_float* z, lapack_int ldz, - float* work, lapack_int* iwork, - lapack_int* ifailv ); -lapack_int LAPACKE_zstein_work( int matrix_order, lapack_int n, const double* d, - const double* e, lapack_int m, const double* w, - const lapack_int* iblock, - const lapack_int* isplit, - lapack_complex_double* z, lapack_int ldz, - double* work, lapack_int* iwork, - lapack_int* ifailv ); - -lapack_int LAPACKE_sstemr_work( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, - float vu, lapack_int il, lapack_int iu, - lapack_int* m, float* w, float* z, - lapack_int ldz, lapack_int nzc, - lapack_int* isuppz, lapack_logical* tryrac, - float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dstemr_work( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int nzc, - lapack_int* isuppz, lapack_logical* tryrac, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_cstemr_work( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, - float vu, lapack_int il, lapack_int iu, - lapack_int* m, float* w, - lapack_complex_float* z, lapack_int ldz, - lapack_int nzc, lapack_int* isuppz, - lapack_logical* tryrac, float* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_zstemr_work( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - lapack_int* m, double* w, - lapack_complex_double* z, lapack_int ldz, - lapack_int nzc, lapack_int* isuppz, - lapack_logical* tryrac, double* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); - -lapack_int LAPACKE_ssteqr_work( int matrix_order, char compz, lapack_int n, - float* d, float* e, float* z, lapack_int ldz, - float* work ); -lapack_int LAPACKE_dsteqr_work( int matrix_order, char compz, lapack_int n, - double* d, double* e, double* z, lapack_int ldz, - double* work ); -lapack_int LAPACKE_csteqr_work( int matrix_order, char compz, lapack_int n, - float* d, float* e, lapack_complex_float* z, - lapack_int ldz, float* work ); -lapack_int LAPACKE_zsteqr_work( int matrix_order, char compz, lapack_int n, - double* d, double* e, lapack_complex_double* z, - lapack_int ldz, double* work ); - -lapack_int LAPACKE_ssterf_work( lapack_int n, float* d, float* e ); -lapack_int LAPACKE_dsterf_work( lapack_int n, double* d, double* e ); - -lapack_int LAPACKE_sstev_work( int matrix_order, char jobz, lapack_int n, - float* d, float* e, float* z, lapack_int ldz, - float* work ); -lapack_int LAPACKE_dstev_work( int matrix_order, char jobz, lapack_int n, - double* d, double* e, double* z, lapack_int ldz, - double* work ); - -lapack_int LAPACKE_sstevd_work( int matrix_order, char jobz, lapack_int n, - float* d, float* e, float* z, lapack_int ldz, - float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dstevd_work( int matrix_order, char jobz, lapack_int n, - double* d, double* e, double* z, lapack_int ldz, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_sstevr_work( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, - float vu, lapack_int il, lapack_int iu, - float abstol, lapack_int* m, float* w, float* z, - lapack_int ldz, lapack_int* isuppz, float* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_dstevr_work( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - double* z, lapack_int ldz, lapack_int* isuppz, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_sstevx_work( int matrix_order, char jobz, char range, - lapack_int n, float* d, float* e, float vl, - float vu, lapack_int il, lapack_int iu, - float abstol, lapack_int* m, float* w, float* z, - lapack_int ldz, float* work, lapack_int* iwork, - lapack_int* ifail ); -lapack_int LAPACKE_dstevx_work( int matrix_order, char jobz, char range, - lapack_int n, double* d, double* e, double vl, - double vu, lapack_int il, lapack_int iu, - double abstol, lapack_int* m, double* w, - double* z, lapack_int ldz, double* work, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_ssycon_work( int matrix_order, char uplo, lapack_int n, - const float* a, lapack_int lda, - const lapack_int* ipiv, float anorm, - float* rcond, float* work, lapack_int* iwork ); -lapack_int LAPACKE_dsycon_work( int matrix_order, char uplo, lapack_int n, - const double* a, lapack_int lda, - const lapack_int* ipiv, double anorm, - double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_csycon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, float anorm, - float* rcond, lapack_complex_float* work ); -lapack_int LAPACKE_zsycon_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, double anorm, - double* rcond, lapack_complex_double* work ); - -lapack_int LAPACKE_ssyequb_work( int matrix_order, char uplo, lapack_int n, - const float* a, lapack_int lda, float* s, - float* scond, float* amax, float* work ); -lapack_int LAPACKE_dsyequb_work( int matrix_order, char uplo, lapack_int n, - const double* a, lapack_int lda, double* s, - double* scond, double* amax, double* work ); -lapack_int LAPACKE_csyequb_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* s, float* scond, float* amax, - lapack_complex_float* work ); -lapack_int LAPACKE_zsyequb_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* s, double* scond, double* amax, - lapack_complex_double* work ); - -lapack_int LAPACKE_ssyev_work( int matrix_order, char jobz, char uplo, - lapack_int n, float* a, lapack_int lda, float* w, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dsyev_work( int matrix_order, char jobz, char uplo, - lapack_int n, double* a, lapack_int lda, - double* w, double* work, lapack_int lwork ); - -lapack_int LAPACKE_ssyevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, float* a, lapack_int lda, - float* w, float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dsyevd_work( int matrix_order, char jobz, char uplo, - lapack_int n, double* a, lapack_int lda, - double* w, double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_ssyevr_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, float* a, - lapack_int lda, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, - lapack_int ldz, lapack_int* isuppz, float* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_dsyevr_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, double* a, - lapack_int lda, double vl, double vu, - lapack_int il, lapack_int iu, double abstol, - lapack_int* m, double* w, double* z, - lapack_int ldz, lapack_int* isuppz, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_ssyevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, float* a, - lapack_int lda, float vl, float vu, - lapack_int il, lapack_int iu, float abstol, - lapack_int* m, float* w, float* z, - lapack_int ldz, float* work, lapack_int lwork, - lapack_int* iwork, lapack_int* ifail ); -lapack_int LAPACKE_dsyevx_work( int matrix_order, char jobz, char range, - char uplo, lapack_int n, double* a, - lapack_int lda, double vl, double vu, - lapack_int il, lapack_int iu, double abstol, - lapack_int* m, double* w, double* z, - lapack_int ldz, double* work, lapack_int lwork, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_ssygst_work( int matrix_order, lapack_int itype, char uplo, - lapack_int n, float* a, lapack_int lda, - const float* b, lapack_int ldb ); -lapack_int LAPACKE_dsygst_work( int matrix_order, lapack_int itype, char uplo, - lapack_int n, double* a, lapack_int lda, - const double* b, lapack_int ldb ); - -lapack_int LAPACKE_ssygv_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - float* w, float* work, lapack_int lwork ); -lapack_int LAPACKE_dsygv_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - double* w, double* work, lapack_int lwork ); - -lapack_int LAPACKE_ssygvd_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - float* w, float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dsygvd_work( int matrix_order, lapack_int itype, char jobz, - char uplo, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - double* w, double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); - -lapack_int LAPACKE_ssygvx_work( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - float vl, float vu, lapack_int il, - lapack_int iu, float abstol, lapack_int* m, - float* w, float* z, lapack_int ldz, float* work, - lapack_int lwork, lapack_int* iwork, - lapack_int* ifail ); -lapack_int LAPACKE_dsygvx_work( int matrix_order, lapack_int itype, char jobz, - char range, char uplo, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - double vl, double vu, lapack_int il, - lapack_int iu, double abstol, lapack_int* m, - double* w, double* z, lapack_int ldz, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int* ifail ); - -lapack_int LAPACKE_ssyrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const float* af, lapack_int ldaf, - const lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* ferr, float* berr, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dsyrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, - lapack_int lda, const double* af, - lapack_int ldaf, const lapack_int* ipiv, - const double* b, lapack_int ldb, double* x, - lapack_int ldx, double* ferr, double* berr, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_csyrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_zsyrfs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_ssyrfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, const float* af, - lapack_int ldaf, const lapack_int* ipiv, - const float* s, const float* b, lapack_int ldb, - float* x, lapack_int ldx, float* rcond, - float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dsyrfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, const double* af, - lapack_int ldaf, const lapack_int* ipiv, - const double* s, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_csyrfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* af, - lapack_int ldaf, const lapack_int* ipiv, - const float* s, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zsyrfsx_work( int matrix_order, char uplo, char equed, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* af, - lapack_int ldaf, const lapack_int* ipiv, - const double* s, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_ssysv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, float* a, lapack_int lda, - lapack_int* ipiv, float* b, lapack_int ldb, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dsysv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, double* a, lapack_int lda, - lapack_int* ipiv, double* b, lapack_int ldb, - double* work, lapack_int lwork ); -lapack_int LAPACKE_csysv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_float* a, - lapack_int lda, lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zsysv_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, lapack_complex_double* a, - lapack_int lda, lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_ssysvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, const float* a, - lapack_int lda, float* af, lapack_int ldaf, - lapack_int* ipiv, const float* b, - lapack_int ldb, float* x, lapack_int ldx, - float* rcond, float* ferr, float* berr, - float* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_dsysvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, const double* a, - lapack_int lda, double* af, lapack_int ldaf, - lapack_int* ipiv, const double* b, - lapack_int ldb, double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - double* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_csysvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, const lapack_complex_float* b, - lapack_int ldb, lapack_complex_float* x, - lapack_int ldx, float* rcond, float* ferr, - float* berr, lapack_complex_float* work, - lapack_int lwork, float* rwork ); -lapack_int LAPACKE_zsysvx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, lapack_int lwork, - double* rwork ); - -lapack_int LAPACKE_ssysvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, float* a, - lapack_int lda, float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* s, - float* b, lapack_int ldb, float* x, - lapack_int ldx, float* rcond, float* rpvgrw, - float* berr, lapack_int n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int nparams, float* params, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dsysvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, double* a, - lapack_int lda, double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* s, - double* b, lapack_int ldb, double* x, - lapack_int ldx, double* rcond, double* rpvgrw, - double* berr, lapack_int n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int nparams, double* params, - double* work, lapack_int* iwork ); -lapack_int LAPACKE_csysvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, float* s, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* x, lapack_int ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int nparams, - float* params, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_zsysvxx_work( int matrix_order, char fact, char uplo, - lapack_int n, lapack_int nrhs, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* af, lapack_int ldaf, - lapack_int* ipiv, char* equed, double* s, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* x, lapack_int ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int nparams, - double* params, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_ssytrd_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda, float* d, float* e, - float* tau, float* work, lapack_int lwork ); -lapack_int LAPACKE_dsytrd_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, double* d, double* e, - double* tau, double* work, lapack_int lwork ); - -lapack_int LAPACKE_ssytrf_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda, lapack_int* ipiv, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dsytrf_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, lapack_int* ipiv, - double* work, lapack_int lwork ); -lapack_int LAPACKE_csytrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_float* work, - lapack_int lwork ); -lapack_int LAPACKE_zsytrf_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_int* ipiv, lapack_complex_double* work, - lapack_int lwork ); - -lapack_int LAPACKE_ssytri_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda, - const lapack_int* ipiv, float* work ); -lapack_int LAPACKE_dsytri_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, - const lapack_int* ipiv, double* work ); -lapack_int LAPACKE_csytri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_float* work ); -lapack_int LAPACKE_zsytri_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_double* work ); - -lapack_int LAPACKE_ssytrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const lapack_int* ipiv, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dsytrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, - lapack_int lda, const lapack_int* ipiv, - double* b, lapack_int ldb ); -lapack_int LAPACKE_csytrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_zsytrs_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_stbcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, lapack_int kd, - const float* ab, lapack_int ldab, float* rcond, - float* work, lapack_int* iwork ); -lapack_int LAPACKE_dtbcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, lapack_int kd, - const double* ab, lapack_int ldab, - double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_ctbcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, lapack_int kd, - const lapack_complex_float* ab, lapack_int ldab, - float* rcond, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_ztbcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, lapack_int kd, - const lapack_complex_double* ab, - lapack_int ldab, double* rcond, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_stbrfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int kd, - lapack_int nrhs, const float* ab, - lapack_int ldab, const float* b, lapack_int ldb, - const float* x, lapack_int ldx, float* ferr, - float* berr, float* work, lapack_int* iwork ); -lapack_int LAPACKE_dtbrfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int kd, - lapack_int nrhs, const double* ab, - lapack_int ldab, const double* b, - lapack_int ldb, const double* x, lapack_int ldx, - double* ferr, double* berr, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_ctbrfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int kd, - lapack_int nrhs, const lapack_complex_float* ab, - lapack_int ldab, const lapack_complex_float* b, - lapack_int ldb, const lapack_complex_float* x, - lapack_int ldx, float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_ztbrfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int kd, - lapack_int nrhs, - const lapack_complex_double* ab, - lapack_int ldab, const lapack_complex_double* b, - lapack_int ldb, const lapack_complex_double* x, - lapack_int ldx, double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_stbtrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int kd, - lapack_int nrhs, const float* ab, - lapack_int ldab, float* b, lapack_int ldb ); -lapack_int LAPACKE_dtbtrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int kd, - lapack_int nrhs, const double* ab, - lapack_int ldab, double* b, lapack_int ldb ); -lapack_int LAPACKE_ctbtrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int kd, - lapack_int nrhs, const lapack_complex_float* ab, - lapack_int ldab, lapack_complex_float* b, - lapack_int ldb ); -lapack_int LAPACKE_ztbtrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int kd, - lapack_int nrhs, - const lapack_complex_double* ab, - lapack_int ldab, lapack_complex_double* b, - lapack_int ldb ); - -lapack_int LAPACKE_stfsm_work( int matrix_order, char transr, char side, - char uplo, char trans, char diag, lapack_int m, - lapack_int n, float alpha, const float* a, - float* b, lapack_int ldb ); -lapack_int LAPACKE_dtfsm_work( int matrix_order, char transr, char side, - char uplo, char trans, char diag, lapack_int m, - lapack_int n, double alpha, const double* a, - double* b, lapack_int ldb ); -lapack_int LAPACKE_ctfsm_work( int matrix_order, char transr, char side, - char uplo, char trans, char diag, lapack_int m, - lapack_int n, lapack_complex_float alpha, - const lapack_complex_float* a, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_ztfsm_work( int matrix_order, char transr, char side, - char uplo, char trans, char diag, lapack_int m, - lapack_int n, lapack_complex_double alpha, - const lapack_complex_double* a, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_stftri_work( int matrix_order, char transr, char uplo, - char diag, lapack_int n, float* a ); -lapack_int LAPACKE_dtftri_work( int matrix_order, char transr, char uplo, - char diag, lapack_int n, double* a ); -lapack_int LAPACKE_ctftri_work( int matrix_order, char transr, char uplo, - char diag, lapack_int n, - lapack_complex_float* a ); -lapack_int LAPACKE_ztftri_work( int matrix_order, char transr, char uplo, - char diag, lapack_int n, - lapack_complex_double* a ); - -lapack_int LAPACKE_stfttp_work( int matrix_order, char transr, char uplo, - lapack_int n, const float* arf, float* ap ); -lapack_int LAPACKE_dtfttp_work( int matrix_order, char transr, char uplo, - lapack_int n, const double* arf, double* ap ); -lapack_int LAPACKE_ctfttp_work( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_float* arf, - lapack_complex_float* ap ); -lapack_int LAPACKE_ztfttp_work( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_double* arf, - lapack_complex_double* ap ); - -lapack_int LAPACKE_stfttr_work( int matrix_order, char transr, char uplo, - lapack_int n, const float* arf, float* a, - lapack_int lda ); -lapack_int LAPACKE_dtfttr_work( int matrix_order, char transr, char uplo, - lapack_int n, const double* arf, double* a, - lapack_int lda ); -lapack_int LAPACKE_ctfttr_work( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_float* arf, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_ztfttr_work( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_double* arf, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_stgevc_work( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - const float* s, lapack_int lds, const float* p, - lapack_int ldp, float* vl, lapack_int ldvl, - float* vr, lapack_int ldvr, lapack_int mm, - lapack_int* m, float* work ); -lapack_int LAPACKE_dtgevc_work( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - const double* s, lapack_int lds, - const double* p, lapack_int ldp, double* vl, - lapack_int ldvl, double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, double* work ); -lapack_int LAPACKE_ctgevc_work( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_float* s, lapack_int lds, - const lapack_complex_float* p, lapack_int ldp, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_ztgevc_work( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_double* s, lapack_int lds, - const lapack_complex_double* p, lapack_int ldp, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_stgexc_work( int matrix_order, lapack_logical wantq, - lapack_logical wantz, lapack_int n, float* a, - lapack_int lda, float* b, lapack_int ldb, - float* q, lapack_int ldq, float* z, - lapack_int ldz, lapack_int* ifst, - lapack_int* ilst, float* work, - lapack_int lwork ); -lapack_int LAPACKE_dtgexc_work( int matrix_order, lapack_logical wantq, - lapack_logical wantz, lapack_int n, double* a, - lapack_int lda, double* b, lapack_int ldb, - double* q, lapack_int ldq, double* z, - lapack_int ldz, lapack_int* ifst, - lapack_int* ilst, double* work, - lapack_int lwork ); -lapack_int LAPACKE_ctgexc_work( int matrix_order, lapack_logical wantq, - lapack_logical wantz, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* z, lapack_int ldz, - lapack_int ifst, lapack_int ilst ); -lapack_int LAPACKE_ztgexc_work( int matrix_order, lapack_logical wantq, - lapack_logical wantz, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* z, lapack_int ldz, - lapack_int ifst, lapack_int ilst ); - -lapack_int LAPACKE_stgsen_work( int matrix_order, lapack_int ijob, - lapack_logical wantq, lapack_logical wantz, - const lapack_logical* select, lapack_int n, - float* a, lapack_int lda, float* b, - lapack_int ldb, float* alphar, float* alphai, - float* beta, float* q, lapack_int ldq, float* z, - lapack_int ldz, lapack_int* m, float* pl, - float* pr, float* dif, float* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); -lapack_int LAPACKE_dtgsen_work( int matrix_order, lapack_int ijob, - lapack_logical wantq, lapack_logical wantz, - const lapack_logical* select, lapack_int n, - double* a, lapack_int lda, double* b, - lapack_int ldb, double* alphar, double* alphai, - double* beta, double* q, lapack_int ldq, - double* z, lapack_int ldz, lapack_int* m, - double* pl, double* pr, double* dif, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_ctgsen_work( int matrix_order, lapack_int ijob, - lapack_logical wantq, lapack_logical wantz, - const lapack_logical* select, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* alpha, - lapack_complex_float* beta, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* z, lapack_int ldz, - lapack_int* m, float* pl, float* pr, float* dif, - lapack_complex_float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_ztgsen_work( int matrix_order, lapack_int ijob, - lapack_logical wantq, lapack_logical wantz, - const lapack_logical* select, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* alpha, - lapack_complex_double* beta, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* z, lapack_int ldz, - lapack_int* m, double* pl, double* pr, - double* dif, lapack_complex_double* work, - lapack_int lwork, lapack_int* iwork, - lapack_int liwork ); - -lapack_int LAPACKE_stgsja_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int p, - lapack_int n, lapack_int k, lapack_int l, - float* a, lapack_int lda, float* b, - lapack_int ldb, float tola, float tolb, - float* alpha, float* beta, float* u, - lapack_int ldu, float* v, lapack_int ldv, - float* q, lapack_int ldq, float* work, - lapack_int* ncycle ); -lapack_int LAPACKE_dtgsja_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int p, - lapack_int n, lapack_int k, lapack_int l, - double* a, lapack_int lda, double* b, - lapack_int ldb, double tola, double tolb, - double* alpha, double* beta, double* u, - lapack_int ldu, double* v, lapack_int ldv, - double* q, lapack_int ldq, double* work, - lapack_int* ncycle ); -lapack_int LAPACKE_ctgsja_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int p, - lapack_int n, lapack_int k, lapack_int l, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - float tola, float tolb, float* alpha, - float* beta, lapack_complex_float* u, - lapack_int ldu, lapack_complex_float* v, - lapack_int ldv, lapack_complex_float* q, - lapack_int ldq, lapack_complex_float* work, - lapack_int* ncycle ); -lapack_int LAPACKE_ztgsja_work( int matrix_order, char jobu, char jobv, - char jobq, lapack_int m, lapack_int p, - lapack_int n, lapack_int k, lapack_int l, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - double tola, double tolb, double* alpha, - double* beta, lapack_complex_double* u, - lapack_int ldu, lapack_complex_double* v, - lapack_int ldv, lapack_complex_double* q, - lapack_int ldq, lapack_complex_double* work, - lapack_int* ncycle ); - -lapack_int LAPACKE_stgsna_work( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const float* a, lapack_int lda, const float* b, - lapack_int ldb, const float* vl, - lapack_int ldvl, const float* vr, - lapack_int ldvr, float* s, float* dif, - lapack_int mm, lapack_int* m, float* work, - lapack_int lwork, lapack_int* iwork ); -lapack_int LAPACKE_dtgsna_work( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const double* a, lapack_int lda, - const double* b, lapack_int ldb, - const double* vl, lapack_int ldvl, - const double* vr, lapack_int ldvr, double* s, - double* dif, lapack_int mm, lapack_int* m, - double* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_ctgsna_work( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* b, lapack_int ldb, - const lapack_complex_float* vl, lapack_int ldvl, - const lapack_complex_float* vr, lapack_int ldvr, - float* s, float* dif, lapack_int mm, - lapack_int* m, lapack_complex_float* work, - lapack_int lwork, lapack_int* iwork ); -lapack_int LAPACKE_ztgsna_work( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* b, lapack_int ldb, - const lapack_complex_double* vl, - lapack_int ldvl, - const lapack_complex_double* vr, - lapack_int ldvr, double* s, double* dif, - lapack_int mm, lapack_int* m, - lapack_complex_double* work, lapack_int lwork, - lapack_int* iwork ); - -lapack_int LAPACKE_stgsyl_work( int matrix_order, char trans, lapack_int ijob, - lapack_int m, lapack_int n, const float* a, - lapack_int lda, const float* b, lapack_int ldb, - float* c, lapack_int ldc, const float* d, - lapack_int ldd, const float* e, lapack_int lde, - float* f, lapack_int ldf, float* scale, - float* dif, float* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_dtgsyl_work( int matrix_order, char trans, lapack_int ijob, - lapack_int m, lapack_int n, const double* a, - lapack_int lda, const double* b, lapack_int ldb, - double* c, lapack_int ldc, const double* d, - lapack_int ldd, const double* e, lapack_int lde, - double* f, lapack_int ldf, double* scale, - double* dif, double* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_ctgsyl_work( int matrix_order, char trans, lapack_int ijob, - lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* c, lapack_int ldc, - const lapack_complex_float* d, lapack_int ldd, - const lapack_complex_float* e, lapack_int lde, - lapack_complex_float* f, lapack_int ldf, - float* scale, float* dif, - lapack_complex_float* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_ztgsyl_work( int matrix_order, char trans, lapack_int ijob, - lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* c, lapack_int ldc, - const lapack_complex_double* d, lapack_int ldd, - const lapack_complex_double* e, lapack_int lde, - lapack_complex_double* f, lapack_int ldf, - double* scale, double* dif, - lapack_complex_double* work, lapack_int lwork, - lapack_int* iwork ); - -lapack_int LAPACKE_stpcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, const float* ap, - float* rcond, float* work, lapack_int* iwork ); -lapack_int LAPACKE_dtpcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, const double* ap, - double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_ctpcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, - const lapack_complex_float* ap, float* rcond, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_ztpcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, - const lapack_complex_double* ap, double* rcond, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_stprfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const float* ap, const float* b, lapack_int ldb, - const float* x, lapack_int ldx, float* ferr, - float* berr, float* work, lapack_int* iwork ); -lapack_int LAPACKE_dtprfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const double* ap, const double* b, - lapack_int ldb, const double* x, lapack_int ldx, - double* ferr, double* berr, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_ctprfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const lapack_complex_float* ap, - const lapack_complex_float* b, lapack_int ldb, - const lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_ztprfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const lapack_complex_double* ap, - const lapack_complex_double* b, lapack_int ldb, - const lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_stptri_work( int matrix_order, char uplo, char diag, - lapack_int n, float* ap ); -lapack_int LAPACKE_dtptri_work( int matrix_order, char uplo, char diag, - lapack_int n, double* ap ); -lapack_int LAPACKE_ctptri_work( int matrix_order, char uplo, char diag, - lapack_int n, lapack_complex_float* ap ); -lapack_int LAPACKE_ztptri_work( int matrix_order, char uplo, char diag, - lapack_int n, lapack_complex_double* ap ); - -lapack_int LAPACKE_stptrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const float* ap, float* b, lapack_int ldb ); -lapack_int LAPACKE_dtptrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const double* ap, double* b, lapack_int ldb ); -lapack_int LAPACKE_ctptrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const lapack_complex_float* ap, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_ztptrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const lapack_complex_double* ap, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_stpttf_work( int matrix_order, char transr, char uplo, - lapack_int n, const float* ap, float* arf ); -lapack_int LAPACKE_dtpttf_work( int matrix_order, char transr, char uplo, - lapack_int n, const double* ap, double* arf ); -lapack_int LAPACKE_ctpttf_work( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_float* ap, - lapack_complex_float* arf ); -lapack_int LAPACKE_ztpttf_work( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_double* ap, - lapack_complex_double* arf ); - -lapack_int LAPACKE_stpttr_work( int matrix_order, char uplo, lapack_int n, - const float* ap, float* a, lapack_int lda ); -lapack_int LAPACKE_dtpttr_work( int matrix_order, char uplo, lapack_int n, - const double* ap, double* a, lapack_int lda ); -lapack_int LAPACKE_ctpttr_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_ztpttr_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_strcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, const float* a, - lapack_int lda, float* rcond, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dtrcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, const double* a, - lapack_int lda, double* rcond, double* work, - lapack_int* iwork ); -lapack_int LAPACKE_ctrcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - float* rcond, lapack_complex_float* work, - float* rwork ); -lapack_int LAPACKE_ztrcon_work( int matrix_order, char norm, char uplo, - char diag, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - double* rcond, lapack_complex_double* work, - double* rwork ); - -lapack_int LAPACKE_strevc_work( int matrix_order, char side, char howmny, - lapack_logical* select, lapack_int n, - const float* t, lapack_int ldt, float* vl, - lapack_int ldvl, float* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, float* work ); -lapack_int LAPACKE_dtrevc_work( int matrix_order, char side, char howmny, - lapack_logical* select, lapack_int n, - const double* t, lapack_int ldt, double* vl, - lapack_int ldvl, double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, double* work ); -lapack_int LAPACKE_ctrevc_work( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* vl, lapack_int ldvl, - lapack_complex_float* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_ztrevc_work( int matrix_order, char side, char howmny, - const lapack_logical* select, lapack_int n, - lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* vl, lapack_int ldvl, - lapack_complex_double* vr, lapack_int ldvr, - lapack_int mm, lapack_int* m, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_strexc_work( int matrix_order, char compq, lapack_int n, - float* t, lapack_int ldt, float* q, - lapack_int ldq, lapack_int* ifst, - lapack_int* ilst, float* work ); -lapack_int LAPACKE_dtrexc_work( int matrix_order, char compq, lapack_int n, - double* t, lapack_int ldt, double* q, - lapack_int ldq, lapack_int* ifst, - lapack_int* ilst, double* work ); -lapack_int LAPACKE_ctrexc_work( int matrix_order, char compq, lapack_int n, - lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* q, lapack_int ldq, - lapack_int ifst, lapack_int ilst ); -lapack_int LAPACKE_ztrexc_work( int matrix_order, char compq, lapack_int n, - lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* q, lapack_int ldq, - lapack_int ifst, lapack_int ilst ); - -lapack_int LAPACKE_strrfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const float* a, lapack_int lda, const float* b, - lapack_int ldb, const float* x, lapack_int ldx, - float* ferr, float* berr, float* work, - lapack_int* iwork ); -lapack_int LAPACKE_dtrrfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const double* a, lapack_int lda, - const double* b, lapack_int ldb, - const double* x, lapack_int ldx, double* ferr, - double* berr, double* work, lapack_int* iwork ); -lapack_int LAPACKE_ctrrfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* b, lapack_int ldb, - const lapack_complex_float* x, lapack_int ldx, - float* ferr, float* berr, - lapack_complex_float* work, float* rwork ); -lapack_int LAPACKE_ztrrfs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* b, lapack_int ldb, - const lapack_complex_double* x, lapack_int ldx, - double* ferr, double* berr, - lapack_complex_double* work, double* rwork ); - -lapack_int LAPACKE_strsen_work( int matrix_order, char job, char compq, - const lapack_logical* select, lapack_int n, - float* t, lapack_int ldt, float* q, - lapack_int ldq, float* wr, float* wi, - lapack_int* m, float* s, float* sep, - float* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_dtrsen_work( int matrix_order, char job, char compq, - const lapack_logical* select, lapack_int n, - double* t, lapack_int ldt, double* q, - lapack_int ldq, double* wr, double* wi, - lapack_int* m, double* s, double* sep, - double* work, lapack_int lwork, - lapack_int* iwork, lapack_int liwork ); -lapack_int LAPACKE_ctrsen_work( int matrix_order, char job, char compq, - const lapack_logical* select, lapack_int n, - lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* w, lapack_int* m, - float* s, float* sep, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_ztrsen_work( int matrix_order, char job, char compq, - const lapack_logical* select, lapack_int n, - lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* w, lapack_int* m, - double* s, double* sep, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_strsna_work( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const float* t, lapack_int ldt, const float* vl, - lapack_int ldvl, const float* vr, - lapack_int ldvr, float* s, float* sep, - lapack_int mm, lapack_int* m, float* work, - lapack_int ldwork, lapack_int* iwork ); -lapack_int LAPACKE_dtrsna_work( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const double* t, lapack_int ldt, - const double* vl, lapack_int ldvl, - const double* vr, lapack_int ldvr, double* s, - double* sep, lapack_int mm, lapack_int* m, - double* work, lapack_int ldwork, - lapack_int* iwork ); -lapack_int LAPACKE_ctrsna_work( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_float* t, lapack_int ldt, - const lapack_complex_float* vl, lapack_int ldvl, - const lapack_complex_float* vr, lapack_int ldvr, - float* s, float* sep, lapack_int mm, - lapack_int* m, lapack_complex_float* work, - lapack_int ldwork, float* rwork ); -lapack_int LAPACKE_ztrsna_work( int matrix_order, char job, char howmny, - const lapack_logical* select, lapack_int n, - const lapack_complex_double* t, lapack_int ldt, - const lapack_complex_double* vl, - lapack_int ldvl, - const lapack_complex_double* vr, - lapack_int ldvr, double* s, double* sep, - lapack_int mm, lapack_int* m, - lapack_complex_double* work, lapack_int ldwork, - double* rwork ); - -lapack_int LAPACKE_strsyl_work( int matrix_order, char trana, char tranb, - lapack_int isgn, lapack_int m, lapack_int n, - const float* a, lapack_int lda, const float* b, - lapack_int ldb, float* c, lapack_int ldc, - float* scale ); -lapack_int LAPACKE_dtrsyl_work( int matrix_order, char trana, char tranb, - lapack_int isgn, lapack_int m, lapack_int n, - const double* a, lapack_int lda, - const double* b, lapack_int ldb, double* c, - lapack_int ldc, double* scale ); -lapack_int LAPACKE_ctrsyl_work( int matrix_order, char trana, char tranb, - lapack_int isgn, lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* c, lapack_int ldc, - float* scale ); -lapack_int LAPACKE_ztrsyl_work( int matrix_order, char trana, char tranb, - lapack_int isgn, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* c, lapack_int ldc, - double* scale ); - -lapack_int LAPACKE_strtri_work( int matrix_order, char uplo, char diag, - lapack_int n, float* a, lapack_int lda ); -lapack_int LAPACKE_dtrtri_work( int matrix_order, char uplo, char diag, - lapack_int n, double* a, lapack_int lda ); -lapack_int LAPACKE_ctrtri_work( int matrix_order, char uplo, char diag, - lapack_int n, lapack_complex_float* a, - lapack_int lda ); -lapack_int LAPACKE_ztrtri_work( int matrix_order, char uplo, char diag, - lapack_int n, lapack_complex_double* a, - lapack_int lda ); - -lapack_int LAPACKE_strtrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const float* a, lapack_int lda, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dtrtrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const double* a, lapack_int lda, double* b, - lapack_int ldb ); -lapack_int LAPACKE_ctrtrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_ztrtrs_work( int matrix_order, char uplo, char trans, - char diag, lapack_int n, lapack_int nrhs, - const lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_strttf_work( int matrix_order, char transr, char uplo, - lapack_int n, const float* a, lapack_int lda, - float* arf ); -lapack_int LAPACKE_dtrttf_work( int matrix_order, char transr, char uplo, - lapack_int n, const double* a, lapack_int lda, - double* arf ); -lapack_int LAPACKE_ctrttf_work( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_float* a, - lapack_int lda, lapack_complex_float* arf ); -lapack_int LAPACKE_ztrttf_work( int matrix_order, char transr, char uplo, - lapack_int n, const lapack_complex_double* a, - lapack_int lda, lapack_complex_double* arf ); - -lapack_int LAPACKE_strttp_work( int matrix_order, char uplo, lapack_int n, - const float* a, lapack_int lda, float* ap ); -lapack_int LAPACKE_dtrttp_work( int matrix_order, char uplo, lapack_int n, - const double* a, lapack_int lda, double* ap ); -lapack_int LAPACKE_ctrttp_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - lapack_complex_float* ap ); -lapack_int LAPACKE_ztrttp_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - lapack_complex_double* ap ); - -lapack_int LAPACKE_stzrzf_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* tau, - float* work, lapack_int lwork ); -lapack_int LAPACKE_dtzrzf_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* tau, - double* work, lapack_int lwork ); -lapack_int LAPACKE_ctzrzf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_ztzrzf_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cungbr_work( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int k, - lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zungbr_work( int matrix_order, char vect, lapack_int m, - lapack_int n, lapack_int k, - lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunghr_work( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunghr_work( int matrix_order, lapack_int n, lapack_int ilo, - lapack_int ihi, lapack_complex_double* a, - lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunglq_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunglq_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_double* a, - lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cungql_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zungql_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_double* a, - lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cungqr_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zungqr_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_double* a, - lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cungrq_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zungrq_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int k, lapack_complex_double* a, - lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cungtr_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zungtr_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunmbr_work( int matrix_order, char vect, char side, - char trans, lapack_int m, lapack_int n, - lapack_int k, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunmbr_work( int matrix_order, char vect, char side, - char trans, lapack_int m, lapack_int n, - lapack_int k, const lapack_complex_double* a, - lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunmhr_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int ilo, - lapack_int ihi, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunmhr_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int ilo, - lapack_int ihi, const lapack_complex_double* a, - lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunmlq_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunmlq_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunmql_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunmql_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunmqr_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunmqr_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunmrq_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunmrq_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunmrz_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, const lapack_complex_float* a, - lapack_int lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunmrz_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, const lapack_complex_double* a, - lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cunmtr_work( int matrix_order, char side, char uplo, - char trans, lapack_int m, lapack_int n, - const lapack_complex_float* a, lapack_int lda, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_zunmtr_work( int matrix_order, char side, char uplo, - char trans, lapack_int m, lapack_int n, - const lapack_complex_double* a, lapack_int lda, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work, lapack_int lwork ); - -lapack_int LAPACKE_cupgtr_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_float* ap, - const lapack_complex_float* tau, - lapack_complex_float* q, lapack_int ldq, - lapack_complex_float* work ); -lapack_int LAPACKE_zupgtr_work( int matrix_order, char uplo, lapack_int n, - const lapack_complex_double* ap, - const lapack_complex_double* tau, - lapack_complex_double* q, lapack_int ldq, - lapack_complex_double* work ); - -lapack_int LAPACKE_cupmtr_work( int matrix_order, char side, char uplo, - char trans, lapack_int m, lapack_int n, - const lapack_complex_float* ap, - const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int ldc, - lapack_complex_float* work ); -lapack_int LAPACKE_zupmtr_work( int matrix_order, char side, char uplo, - char trans, lapack_int m, lapack_int n, - const lapack_complex_double* ap, - const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int ldc, - lapack_complex_double* work ); - -lapack_int LAPACKE_claghe( int matrix_order, lapack_int n, lapack_int k, - const float* d, lapack_complex_float* a, - lapack_int lda, lapack_int* iseed ); -lapack_int LAPACKE_zlaghe( int matrix_order, lapack_int n, lapack_int k, - const double* d, lapack_complex_double* a, - lapack_int lda, lapack_int* iseed ); - -lapack_int LAPACKE_slagsy( int matrix_order, lapack_int n, lapack_int k, - const float* d, float* a, lapack_int lda, - lapack_int* iseed ); -lapack_int LAPACKE_dlagsy( int matrix_order, lapack_int n, lapack_int k, - const double* d, double* a, lapack_int lda, - lapack_int* iseed ); -lapack_int LAPACKE_clagsy( int matrix_order, lapack_int n, lapack_int k, - const float* d, lapack_complex_float* a, - lapack_int lda, lapack_int* iseed ); -lapack_int LAPACKE_zlagsy( int matrix_order, lapack_int n, lapack_int k, - const double* d, lapack_complex_double* a, - lapack_int lda, lapack_int* iseed ); - -lapack_int LAPACKE_slapmr( int matrix_order, lapack_logical forwrd, - lapack_int m, lapack_int n, float* x, lapack_int ldx, - lapack_int* k ); -lapack_int LAPACKE_dlapmr( int matrix_order, lapack_logical forwrd, - lapack_int m, lapack_int n, double* x, - lapack_int ldx, lapack_int* k ); -lapack_int LAPACKE_clapmr( int matrix_order, lapack_logical forwrd, - lapack_int m, lapack_int n, lapack_complex_float* x, - lapack_int ldx, lapack_int* k ); -lapack_int LAPACKE_zlapmr( int matrix_order, lapack_logical forwrd, - lapack_int m, lapack_int n, lapack_complex_double* x, - lapack_int ldx, lapack_int* k ); - - -float LAPACKE_slapy2( float x, float y ); -double LAPACKE_dlapy2( double x, double y ); - -float LAPACKE_slapy3( float x, float y, float z ); -double LAPACKE_dlapy3( double x, double y, double z ); - -lapack_int LAPACKE_slartgp( float f, float g, float* cs, float* sn, float* r ); -lapack_int LAPACKE_dlartgp( double f, double g, double* cs, double* sn, - double* r ); - -lapack_int LAPACKE_slartgs( float x, float y, float sigma, float* cs, - float* sn ); -lapack_int LAPACKE_dlartgs( double x, double y, double sigma, double* cs, - double* sn ); - - -//LAPACK 3.3.0 -lapack_int LAPACKE_cbbcsd( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, lapack_int m, - lapack_int p, lapack_int q, float* theta, float* phi, - lapack_complex_float* u1, lapack_int ldu1, - lapack_complex_float* u2, lapack_int ldu2, - lapack_complex_float* v1t, lapack_int ldv1t, - lapack_complex_float* v2t, lapack_int ldv2t, - float* b11d, float* b11e, float* b12d, float* b12e, - float* b21d, float* b21e, float* b22d, float* b22e ); -lapack_int LAPACKE_cbbcsd_work( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, - lapack_int m, lapack_int p, lapack_int q, - float* theta, float* phi, - lapack_complex_float* u1, lapack_int ldu1, - lapack_complex_float* u2, lapack_int ldu2, - lapack_complex_float* v1t, lapack_int ldv1t, - lapack_complex_float* v2t, lapack_int ldv2t, - float* b11d, float* b11e, float* b12d, - float* b12e, float* b21d, float* b21e, - float* b22d, float* b22e, float* rwork, - lapack_int lrwork ); -lapack_int LAPACKE_cheswapr( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int i1, - lapack_int i2 ); -lapack_int LAPACKE_cheswapr_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int i1, - lapack_int i2 ); -lapack_int LAPACKE_chetri2( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_chetri2_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_chetri2x( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, lapack_int nb ); -lapack_int LAPACKE_chetri2x_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int nb ); -lapack_int LAPACKE_chetrs2( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_chetrs2_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* work ); -lapack_int LAPACKE_csyconv( int matrix_order, char uplo, char way, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_csyconv_work( int matrix_order, char uplo, char way, - lapack_int n, lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* work ); -lapack_int LAPACKE_csyswapr( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int i1, - lapack_int i2 ); -lapack_int LAPACKE_csyswapr_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int i1, - lapack_int i2 ); -lapack_int LAPACKE_csytri2( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_csytri2_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_csytri2x( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, lapack_int nb ); -lapack_int LAPACKE_csytri2x_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int nb ); -lapack_int LAPACKE_csytrs2( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_csytrs2_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_float* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* work ); -lapack_int LAPACKE_cunbdb( int matrix_order, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - lapack_complex_float* x11, lapack_int ldx11, - lapack_complex_float* x12, lapack_int ldx12, - lapack_complex_float* x21, lapack_int ldx21, - lapack_complex_float* x22, lapack_int ldx22, - float* theta, float* phi, - lapack_complex_float* taup1, - lapack_complex_float* taup2, - lapack_complex_float* tauq1, - lapack_complex_float* tauq2 ); -lapack_int LAPACKE_cunbdb_work( int matrix_order, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - lapack_complex_float* x11, lapack_int ldx11, - lapack_complex_float* x12, lapack_int ldx12, - lapack_complex_float* x21, lapack_int ldx21, - lapack_complex_float* x22, lapack_int ldx22, - float* theta, float* phi, - lapack_complex_float* taup1, - lapack_complex_float* taup2, - lapack_complex_float* tauq1, - lapack_complex_float* tauq2, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_cuncsd( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - lapack_complex_float* x11, lapack_int ldx11, - lapack_complex_float* x12, lapack_int ldx12, - lapack_complex_float* x21, lapack_int ldx21, - lapack_complex_float* x22, lapack_int ldx22, - float* theta, lapack_complex_float* u1, - lapack_int ldu1, lapack_complex_float* u2, - lapack_int ldu2, lapack_complex_float* v1t, - lapack_int ldv1t, lapack_complex_float* v2t, - lapack_int ldv2t ); -lapack_int LAPACKE_cuncsd_work( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, - char signs, lapack_int m, lapack_int p, - lapack_int q, lapack_complex_float* x11, - lapack_int ldx11, lapack_complex_float* x12, - lapack_int ldx12, lapack_complex_float* x21, - lapack_int ldx21, lapack_complex_float* x22, - lapack_int ldx22, float* theta, - lapack_complex_float* u1, lapack_int ldu1, - lapack_complex_float* u2, lapack_int ldu2, - lapack_complex_float* v1t, lapack_int ldv1t, - lapack_complex_float* v2t, lapack_int ldv2t, - lapack_complex_float* work, lapack_int lwork, - float* rwork, lapack_int lrwork, - lapack_int* iwork ); -lapack_int LAPACKE_dbbcsd( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, lapack_int m, - lapack_int p, lapack_int q, double* theta, - double* phi, double* u1, lapack_int ldu1, double* u2, - lapack_int ldu2, double* v1t, lapack_int ldv1t, - double* v2t, lapack_int ldv2t, double* b11d, - double* b11e, double* b12d, double* b12e, - double* b21d, double* b21e, double* b22d, - double* b22e ); -lapack_int LAPACKE_dbbcsd_work( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, - lapack_int m, lapack_int p, lapack_int q, - double* theta, double* phi, double* u1, - lapack_int ldu1, double* u2, lapack_int ldu2, - double* v1t, lapack_int ldv1t, double* v2t, - lapack_int ldv2t, double* b11d, double* b11e, - double* b12d, double* b12e, double* b21d, - double* b21e, double* b22d, double* b22e, - double* work, lapack_int lwork ); -lapack_int LAPACKE_dorbdb( int matrix_order, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - double* x11, lapack_int ldx11, double* x12, - lapack_int ldx12, double* x21, lapack_int ldx21, - double* x22, lapack_int ldx22, double* theta, - double* phi, double* taup1, double* taup2, - double* tauq1, double* tauq2 ); -lapack_int LAPACKE_dorbdb_work( int matrix_order, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - double* x11, lapack_int ldx11, double* x12, - lapack_int ldx12, double* x21, lapack_int ldx21, - double* x22, lapack_int ldx22, double* theta, - double* phi, double* taup1, double* taup2, - double* tauq1, double* tauq2, double* work, - lapack_int lwork ); -lapack_int LAPACKE_dorcsd( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - double* x11, lapack_int ldx11, double* x12, - lapack_int ldx12, double* x21, lapack_int ldx21, - double* x22, lapack_int ldx22, double* theta, - double* u1, lapack_int ldu1, double* u2, - lapack_int ldu2, double* v1t, lapack_int ldv1t, - double* v2t, lapack_int ldv2t ); -lapack_int LAPACKE_dorcsd_work( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, - char signs, lapack_int m, lapack_int p, - lapack_int q, double* x11, lapack_int ldx11, - double* x12, lapack_int ldx12, double* x21, - lapack_int ldx21, double* x22, lapack_int ldx22, - double* theta, double* u1, lapack_int ldu1, - double* u2, lapack_int ldu2, double* v1t, - lapack_int ldv1t, double* v2t, lapack_int ldv2t, - double* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_dsyconv( int matrix_order, char uplo, char way, lapack_int n, - double* a, lapack_int lda, const lapack_int* ipiv ); -lapack_int LAPACKE_dsyconv_work( int matrix_order, char uplo, char way, - lapack_int n, double* a, lapack_int lda, - const lapack_int* ipiv, double* work ); -lapack_int LAPACKE_dsyswapr( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int i1, lapack_int i2 ); -lapack_int LAPACKE_dsyswapr_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int i1, lapack_int i2 ); -lapack_int LAPACKE_dsytri2( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, const lapack_int* ipiv ); -lapack_int LAPACKE_dsytri2_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int lwork ); -lapack_int LAPACKE_dsytri2x( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, const lapack_int* ipiv, - lapack_int nb ); -lapack_int LAPACKE_dsytri2x_work( int matrix_order, char uplo, lapack_int n, - double* a, lapack_int lda, - const lapack_int* ipiv, double* work, - lapack_int nb ); -lapack_int LAPACKE_dsytrs2( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, lapack_int lda, - const lapack_int* ipiv, double* b, lapack_int ldb ); -lapack_int LAPACKE_dsytrs2_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const double* a, - lapack_int lda, const lapack_int* ipiv, - double* b, lapack_int ldb, double* work ); -lapack_int LAPACKE_sbbcsd( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, lapack_int m, - lapack_int p, lapack_int q, float* theta, float* phi, - float* u1, lapack_int ldu1, float* u2, - lapack_int ldu2, float* v1t, lapack_int ldv1t, - float* v2t, lapack_int ldv2t, float* b11d, - float* b11e, float* b12d, float* b12e, float* b21d, - float* b21e, float* b22d, float* b22e ); -lapack_int LAPACKE_sbbcsd_work( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, - lapack_int m, lapack_int p, lapack_int q, - float* theta, float* phi, float* u1, - lapack_int ldu1, float* u2, lapack_int ldu2, - float* v1t, lapack_int ldv1t, float* v2t, - lapack_int ldv2t, float* b11d, float* b11e, - float* b12d, float* b12e, float* b21d, - float* b21e, float* b22d, float* b22e, - float* work, lapack_int lwork ); -lapack_int LAPACKE_sorbdb( int matrix_order, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, float* x11, - lapack_int ldx11, float* x12, lapack_int ldx12, - float* x21, lapack_int ldx21, float* x22, - lapack_int ldx22, float* theta, float* phi, - float* taup1, float* taup2, float* tauq1, - float* tauq2 ); -lapack_int LAPACKE_sorbdb_work( int matrix_order, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - float* x11, lapack_int ldx11, float* x12, - lapack_int ldx12, float* x21, lapack_int ldx21, - float* x22, lapack_int ldx22, float* theta, - float* phi, float* taup1, float* taup2, - float* tauq1, float* tauq2, float* work, - lapack_int lwork ); -lapack_int LAPACKE_sorcsd( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, float* x11, - lapack_int ldx11, float* x12, lapack_int ldx12, - float* x21, lapack_int ldx21, float* x22, - lapack_int ldx22, float* theta, float* u1, - lapack_int ldu1, float* u2, lapack_int ldu2, - float* v1t, lapack_int ldv1t, float* v2t, - lapack_int ldv2t ); -lapack_int LAPACKE_sorcsd_work( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, - char signs, lapack_int m, lapack_int p, - lapack_int q, float* x11, lapack_int ldx11, - float* x12, lapack_int ldx12, float* x21, - lapack_int ldx21, float* x22, lapack_int ldx22, - float* theta, float* u1, lapack_int ldu1, - float* u2, lapack_int ldu2, float* v1t, - lapack_int ldv1t, float* v2t, lapack_int ldv2t, - float* work, lapack_int lwork, - lapack_int* iwork ); -lapack_int LAPACKE_ssyconv( int matrix_order, char uplo, char way, lapack_int n, - float* a, lapack_int lda, const lapack_int* ipiv ); -lapack_int LAPACKE_ssyconv_work( int matrix_order, char uplo, char way, - lapack_int n, float* a, lapack_int lda, - const lapack_int* ipiv, float* work ); -lapack_int LAPACKE_ssyswapr( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int i1, lapack_int i2 ); -lapack_int LAPACKE_ssyswapr_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int i1, lapack_int i2 ); -lapack_int LAPACKE_ssytri2( int matrix_order, char uplo, lapack_int n, float* a, - lapack_int lda, const lapack_int* ipiv ); -lapack_int LAPACKE_ssytri2_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int lwork ); -lapack_int LAPACKE_ssytri2x( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda, const lapack_int* ipiv, - lapack_int nb ); -lapack_int LAPACKE_ssytri2x_work( int matrix_order, char uplo, lapack_int n, - float* a, lapack_int lda, - const lapack_int* ipiv, float* work, - lapack_int nb ); -lapack_int LAPACKE_ssytrs2( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, lapack_int lda, - const lapack_int* ipiv, float* b, lapack_int ldb ); -lapack_int LAPACKE_ssytrs2_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const float* a, - lapack_int lda, const lapack_int* ipiv, - float* b, lapack_int ldb, float* work ); -lapack_int LAPACKE_zbbcsd( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, lapack_int m, - lapack_int p, lapack_int q, double* theta, - double* phi, lapack_complex_double* u1, - lapack_int ldu1, lapack_complex_double* u2, - lapack_int ldu2, lapack_complex_double* v1t, - lapack_int ldv1t, lapack_complex_double* v2t, - lapack_int ldv2t, double* b11d, double* b11e, - double* b12d, double* b12e, double* b21d, - double* b21e, double* b22d, double* b22e ); -lapack_int LAPACKE_zbbcsd_work( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, - lapack_int m, lapack_int p, lapack_int q, - double* theta, double* phi, - lapack_complex_double* u1, lapack_int ldu1, - lapack_complex_double* u2, lapack_int ldu2, - lapack_complex_double* v1t, lapack_int ldv1t, - lapack_complex_double* v2t, lapack_int ldv2t, - double* b11d, double* b11e, double* b12d, - double* b12e, double* b21d, double* b21e, - double* b22d, double* b22e, double* rwork, - lapack_int lrwork ); -lapack_int LAPACKE_zheswapr( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int i1, - lapack_int i2 ); -lapack_int LAPACKE_zheswapr_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int i1, - lapack_int i2 ); -lapack_int LAPACKE_zhetri2( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_zhetri2_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int lwork ); -lapack_int LAPACKE_zhetri2x( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, lapack_int nb ); -lapack_int LAPACKE_zhetri2x_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int nb ); -lapack_int LAPACKE_zhetrs2( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); -lapack_int LAPACKE_zhetrs2_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* work ); -lapack_int LAPACKE_zsyconv( int matrix_order, char uplo, char way, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_zsyconv_work( int matrix_order, char uplo, char way, - lapack_int n, lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* work ); -lapack_int LAPACKE_zsyswapr( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int i1, - lapack_int i2 ); -lapack_int LAPACKE_zsyswapr_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int i1, - lapack_int i2 ); -lapack_int LAPACKE_zsytri2( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv ); -lapack_int LAPACKE_zsytri2_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int lwork ); -lapack_int LAPACKE_zsytri2x( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, lapack_int nb ); -lapack_int LAPACKE_zsytri2x_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double* a, lapack_int lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int nb ); -lapack_int LAPACKE_zsytrs2( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb ); -lapack_int LAPACKE_zsytrs2_work( int matrix_order, char uplo, lapack_int n, - lapack_int nrhs, const lapack_complex_double* a, - lapack_int lda, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* work ); -lapack_int LAPACKE_zunbdb( int matrix_order, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - lapack_complex_double* x11, lapack_int ldx11, - lapack_complex_double* x12, lapack_int ldx12, - lapack_complex_double* x21, lapack_int ldx21, - lapack_complex_double* x22, lapack_int ldx22, - double* theta, double* phi, - lapack_complex_double* taup1, - lapack_complex_double* taup2, - lapack_complex_double* tauq1, - lapack_complex_double* tauq2 ); -lapack_int LAPACKE_zunbdb_work( int matrix_order, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - lapack_complex_double* x11, lapack_int ldx11, - lapack_complex_double* x12, lapack_int ldx12, - lapack_complex_double* x21, lapack_int ldx21, - lapack_complex_double* x22, lapack_int ldx22, - double* theta, double* phi, - lapack_complex_double* taup1, - lapack_complex_double* taup2, - lapack_complex_double* tauq1, - lapack_complex_double* tauq2, - lapack_complex_double* work, lapack_int lwork ); -lapack_int LAPACKE_zuncsd( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, char signs, - lapack_int m, lapack_int p, lapack_int q, - lapack_complex_double* x11, lapack_int ldx11, - lapack_complex_double* x12, lapack_int ldx12, - lapack_complex_double* x21, lapack_int ldx21, - lapack_complex_double* x22, lapack_int ldx22, - double* theta, lapack_complex_double* u1, - lapack_int ldu1, lapack_complex_double* u2, - lapack_int ldu2, lapack_complex_double* v1t, - lapack_int ldv1t, lapack_complex_double* v2t, - lapack_int ldv2t ); -lapack_int LAPACKE_zuncsd_work( int matrix_order, char jobu1, char jobu2, - char jobv1t, char jobv2t, char trans, - char signs, lapack_int m, lapack_int p, - lapack_int q, lapack_complex_double* x11, - lapack_int ldx11, lapack_complex_double* x12, - lapack_int ldx12, lapack_complex_double* x21, - lapack_int ldx21, lapack_complex_double* x22, - lapack_int ldx22, double* theta, - lapack_complex_double* u1, lapack_int ldu1, - lapack_complex_double* u2, lapack_int ldu2, - lapack_complex_double* v1t, lapack_int ldv1t, - lapack_complex_double* v2t, lapack_int ldv2t, - lapack_complex_double* work, lapack_int lwork, - double* rwork, lapack_int lrwork, - lapack_int* iwork ); -//LAPACK 3.4.0 -lapack_int LAPACKE_sgemqrt( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int nb, const float* v, lapack_int ldv, - const float* t, lapack_int ldt, float* c, - lapack_int ldc ); -lapack_int LAPACKE_dgemqrt( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int nb, const double* v, lapack_int ldv, - const double* t, lapack_int ldt, double* c, - lapack_int ldc ); -lapack_int LAPACKE_cgemqrt( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int nb, const lapack_complex_float* v, - lapack_int ldv, const lapack_complex_float* t, - lapack_int ldt, lapack_complex_float* c, - lapack_int ldc ); -lapack_int LAPACKE_zgemqrt( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int nb, const lapack_complex_double* v, - lapack_int ldv, const lapack_complex_double* t, - lapack_int ldt, lapack_complex_double* c, - lapack_int ldc ); - -lapack_int LAPACKE_sgeqrt( int matrix_order, lapack_int m, lapack_int n, - lapack_int nb, float* a, lapack_int lda, float* t, - lapack_int ldt ); -lapack_int LAPACKE_dgeqrt( int matrix_order, lapack_int m, lapack_int n, - lapack_int nb, double* a, lapack_int lda, double* t, - lapack_int ldt ); -lapack_int LAPACKE_cgeqrt( int matrix_order, lapack_int m, lapack_int n, - lapack_int nb, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* t, - lapack_int ldt ); -lapack_int LAPACKE_zgeqrt( int matrix_order, lapack_int m, lapack_int n, - lapack_int nb, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* t, - lapack_int ldt ); - -lapack_int LAPACKE_sgeqrt2( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* t, - lapack_int ldt ); -lapack_int LAPACKE_dgeqrt2( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* t, - lapack_int ldt ); -lapack_int LAPACKE_cgeqrt2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* t, lapack_int ldt ); -lapack_int LAPACKE_zgeqrt2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_sgeqrt3( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* t, - lapack_int ldt ); -lapack_int LAPACKE_dgeqrt3( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* t, - lapack_int ldt ); -lapack_int LAPACKE_cgeqrt3( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* t, lapack_int ldt ); -lapack_int LAPACKE_zgeqrt3( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_stpmqrt( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, lapack_int nb, const float* v, - lapack_int ldv, const float* t, lapack_int ldt, - float* a, lapack_int lda, float* b, - lapack_int ldb ); -lapack_int LAPACKE_dtpmqrt( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, lapack_int nb, const double* v, - lapack_int ldv, const double* t, lapack_int ldt, - double* a, lapack_int lda, double* b, - lapack_int ldb ); -lapack_int LAPACKE_ctpmqrt( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, lapack_int nb, - const lapack_complex_float* v, lapack_int ldv, - const lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb ); -lapack_int LAPACKE_ztpmqrt( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, lapack_int nb, - const lapack_complex_double* v, lapack_int ldv, - const lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb ); - -lapack_int LAPACKE_dtpqrt( int matrix_order, lapack_int m, lapack_int n, - lapack_int l, lapack_int nb, double* a, - lapack_int lda, double* b, lapack_int ldb, double* t, - lapack_int ldt ); -lapack_int LAPACKE_ctpqrt( int matrix_order, lapack_int m, lapack_int n, - lapack_int l, lapack_int nb, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* t, - lapack_complex_float* b, lapack_int ldb, - lapack_int ldt ); -lapack_int LAPACKE_ztpqrt( int matrix_order, lapack_int m, lapack_int n, - lapack_int l, lapack_int nb, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_stpqrt2( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* b, lapack_int ldb, - float* t, lapack_int ldt ); -lapack_int LAPACKE_dtpqrt2( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* b, - lapack_int ldb, double* t, lapack_int ldt ); -lapack_int LAPACKE_ctpqrt2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* t, lapack_int ldt ); -lapack_int LAPACKE_ztpqrt2( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_stprfb( int matrix_order, char side, char trans, char direct, - char storev, lapack_int m, lapack_int n, - lapack_int k, lapack_int l, const float* v, - lapack_int ldv, const float* t, lapack_int ldt, - float* a, lapack_int lda, float* b, lapack_int ldb, - lapack_int myldwork ); -lapack_int LAPACKE_dtprfb( int matrix_order, char side, char trans, char direct, - char storev, lapack_int m, lapack_int n, - lapack_int k, lapack_int l, const double* v, - lapack_int ldv, const double* t, lapack_int ldt, - double* a, lapack_int lda, double* b, lapack_int ldb, - lapack_int myldwork ); -lapack_int LAPACKE_ctprfb( int matrix_order, char side, char trans, char direct, - char storev, lapack_int m, lapack_int n, - lapack_int k, lapack_int l, - const lapack_complex_float* v, lapack_int ldv, - const lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_int myldwork ); -lapack_int LAPACKE_ztprfb( int matrix_order, char side, char trans, char direct, - char storev, lapack_int m, lapack_int n, - lapack_int k, lapack_int l, - const lapack_complex_double* v, lapack_int ldv, - const lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_int myldwork ); - -lapack_int LAPACKE_sgemqrt_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int nb, const float* v, lapack_int ldv, - const float* t, lapack_int ldt, float* c, - lapack_int ldc, float* work ); -lapack_int LAPACKE_dgemqrt_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int nb, const double* v, lapack_int ldv, - const double* t, lapack_int ldt, double* c, - lapack_int ldc, double* work ); -lapack_int LAPACKE_cgemqrt_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int nb, const lapack_complex_float* v, - lapack_int ldv, const lapack_complex_float* t, - lapack_int ldt, lapack_complex_float* c, - lapack_int ldc, lapack_complex_float* work ); -lapack_int LAPACKE_zgemqrt_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int nb, const lapack_complex_double* v, - lapack_int ldv, const lapack_complex_double* t, - lapack_int ldt, lapack_complex_double* c, - lapack_int ldc, lapack_complex_double* work ); - -lapack_int LAPACKE_sgeqrt_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nb, float* a, lapack_int lda, - float* t, lapack_int ldt, float* work ); -lapack_int LAPACKE_dgeqrt_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nb, double* a, lapack_int lda, - double* t, lapack_int ldt, double* work ); -lapack_int LAPACKE_cgeqrt_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nb, lapack_complex_float* a, - lapack_int lda, lapack_complex_float* t, - lapack_int ldt, lapack_complex_float* work ); -lapack_int LAPACKE_zgeqrt_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int nb, lapack_complex_double* a, - lapack_int lda, lapack_complex_double* t, - lapack_int ldt, lapack_complex_double* work ); - -lapack_int LAPACKE_sgeqrt2_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* t, - lapack_int ldt ); -lapack_int LAPACKE_dgeqrt2_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* t, - lapack_int ldt ); -lapack_int LAPACKE_cgeqrt2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* t, lapack_int ldt ); -lapack_int LAPACKE_zgeqrt2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_sgeqrt3_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* t, - lapack_int ldt ); -lapack_int LAPACKE_dgeqrt3_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* t, - lapack_int ldt ); -lapack_int LAPACKE_cgeqrt3_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* t, lapack_int ldt ); -lapack_int LAPACKE_zgeqrt3_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_stpmqrt_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, lapack_int nb, const float* v, - lapack_int ldv, const float* t, lapack_int ldt, - float* a, lapack_int lda, float* b, - lapack_int ldb, float* work ); -lapack_int LAPACKE_dtpmqrt_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, lapack_int nb, const double* v, - lapack_int ldv, const double* t, - lapack_int ldt, double* a, lapack_int lda, - double* b, lapack_int ldb, double* work ); -lapack_int LAPACKE_ctpmqrt_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, lapack_int nb, - const lapack_complex_float* v, lapack_int ldv, - const lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* work ); -lapack_int LAPACKE_ztpmqrt_work( int matrix_order, char side, char trans, - lapack_int m, lapack_int n, lapack_int k, - lapack_int l, lapack_int nb, - const lapack_complex_double* v, lapack_int ldv, - const lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* work ); - -lapack_int LAPACKE_dtpqrt_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int l, lapack_int nb, double* a, - lapack_int lda, double* b, lapack_int ldb, - double* t, lapack_int ldt, double* work ); -lapack_int LAPACKE_ctpqrt_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int l, lapack_int nb, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* t, - lapack_complex_float* b, lapack_int ldb, - lapack_int ldt, lapack_complex_float* work ); -lapack_int LAPACKE_ztpqrt_work( int matrix_order, lapack_int m, lapack_int n, - lapack_int l, lapack_int nb, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* work ); - -lapack_int LAPACKE_stpqrt2_work( int matrix_order, lapack_int m, lapack_int n, - float* a, lapack_int lda, float* b, - lapack_int ldb, float* t, lapack_int ldt ); -lapack_int LAPACKE_dtpqrt2_work( int matrix_order, lapack_int m, lapack_int n, - double* a, lapack_int lda, double* b, - lapack_int ldb, double* t, lapack_int ldt ); -lapack_int LAPACKE_ctpqrt2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - lapack_complex_float* t, lapack_int ldt ); -lapack_int LAPACKE_ztpqrt2_work( int matrix_order, lapack_int m, lapack_int n, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - lapack_complex_double* t, lapack_int ldt ); - -lapack_int LAPACKE_stprfb_work( int matrix_order, char side, char trans, - char direct, char storev, lapack_int m, - lapack_int n, lapack_int k, lapack_int l, - const float* v, lapack_int ldv, const float* t, - lapack_int ldt, float* a, lapack_int lda, - float* b, lapack_int ldb, const float* mywork, - lapack_int myldwork ); -lapack_int LAPACKE_dtprfb_work( int matrix_order, char side, char trans, - char direct, char storev, lapack_int m, - lapack_int n, lapack_int k, lapack_int l, - const double* v, lapack_int ldv, - const double* t, lapack_int ldt, double* a, - lapack_int lda, double* b, lapack_int ldb, - const double* mywork, lapack_int myldwork ); -lapack_int LAPACKE_ctprfb_work( int matrix_order, char side, char trans, - char direct, char storev, lapack_int m, - lapack_int n, lapack_int k, lapack_int l, - const lapack_complex_float* v, lapack_int ldv, - const lapack_complex_float* t, lapack_int ldt, - lapack_complex_float* a, lapack_int lda, - lapack_complex_float* b, lapack_int ldb, - const float* mywork, lapack_int myldwork ); -lapack_int LAPACKE_ztprfb_work( int matrix_order, char side, char trans, - char direct, char storev, lapack_int m, - lapack_int n, lapack_int k, lapack_int l, - const lapack_complex_double* v, lapack_int ldv, - const lapack_complex_double* t, lapack_int ldt, - lapack_complex_double* a, lapack_int lda, - lapack_complex_double* b, lapack_int ldb, - const double* mywork, lapack_int myldwork ); -//LAPACK 3.X.X -lapack_int LAPACKE_csyr( int matrix_order, char uplo, lapack_int n, - lapack_complex_float alpha, - const lapack_complex_float* x, lapack_int incx, - lapack_complex_float* a, lapack_int lda ); -lapack_int LAPACKE_zsyr( int matrix_order, char uplo, lapack_int n, - lapack_complex_double alpha, - const lapack_complex_double* x, lapack_int incx, - lapack_complex_double* a, lapack_int lda ); - -lapack_int LAPACKE_csyr_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_float alpha, - const lapack_complex_float* x, - lapack_int incx, lapack_complex_float* a, - lapack_int lda ); -lapack_int LAPACKE_zsyr_work( int matrix_order, char uplo, lapack_int n, - lapack_complex_double alpha, - const lapack_complex_double* x, - lapack_int incx, lapack_complex_double* a, - lapack_int lda ); - - - -#define LAPACK_sgetrf LAPACK_GLOBAL(sgetrf,SGETRF) -#define LAPACK_dgetrf LAPACK_GLOBAL(dgetrf,DGETRF) -#define LAPACK_cgetrf LAPACK_GLOBAL(cgetrf,CGETRF) -#define LAPACK_zgetrf LAPACK_GLOBAL(zgetrf,ZGETRF) -#define LAPACK_sgbtrf LAPACK_GLOBAL(sgbtrf,SGBTRF) -#define LAPACK_dgbtrf LAPACK_GLOBAL(dgbtrf,DGBTRF) -#define LAPACK_cgbtrf LAPACK_GLOBAL(cgbtrf,CGBTRF) -#define LAPACK_zgbtrf LAPACK_GLOBAL(zgbtrf,ZGBTRF) -#define LAPACK_sgttrf LAPACK_GLOBAL(sgttrf,SGTTRF) -#define LAPACK_dgttrf LAPACK_GLOBAL(dgttrf,DGTTRF) -#define LAPACK_cgttrf LAPACK_GLOBAL(cgttrf,CGTTRF) -#define LAPACK_zgttrf LAPACK_GLOBAL(zgttrf,ZGTTRF) -#define LAPACK_spotrf LAPACK_GLOBAL(spotrf,SPOTRF) -#define LAPACK_dpotrf LAPACK_GLOBAL(dpotrf,DPOTRF) -#define LAPACK_cpotrf LAPACK_GLOBAL(cpotrf,CPOTRF) -#define LAPACK_zpotrf LAPACK_GLOBAL(zpotrf,ZPOTRF) -#define LAPACK_dpstrf LAPACK_GLOBAL(dpstrf,DPSTRF) -#define LAPACK_spstrf LAPACK_GLOBAL(spstrf,SPSTRF) -#define LAPACK_zpstrf LAPACK_GLOBAL(zpstrf,ZPSTRF) -#define LAPACK_cpstrf LAPACK_GLOBAL(cpstrf,CPSTRF) -#define LAPACK_dpftrf LAPACK_GLOBAL(dpftrf,DPFTRF) -#define LAPACK_spftrf LAPACK_GLOBAL(spftrf,SPFTRF) -#define LAPACK_zpftrf LAPACK_GLOBAL(zpftrf,ZPFTRF) -#define LAPACK_cpftrf LAPACK_GLOBAL(cpftrf,CPFTRF) -#define LAPACK_spptrf LAPACK_GLOBAL(spptrf,SPPTRF) -#define LAPACK_dpptrf LAPACK_GLOBAL(dpptrf,DPPTRF) -#define LAPACK_cpptrf LAPACK_GLOBAL(cpptrf,CPPTRF) -#define LAPACK_zpptrf LAPACK_GLOBAL(zpptrf,ZPPTRF) -#define LAPACK_spbtrf LAPACK_GLOBAL(spbtrf,SPBTRF) -#define LAPACK_dpbtrf LAPACK_GLOBAL(dpbtrf,DPBTRF) -#define LAPACK_cpbtrf LAPACK_GLOBAL(cpbtrf,CPBTRF) -#define LAPACK_zpbtrf LAPACK_GLOBAL(zpbtrf,ZPBTRF) -#define LAPACK_spttrf LAPACK_GLOBAL(spttrf,SPTTRF) -#define LAPACK_dpttrf LAPACK_GLOBAL(dpttrf,DPTTRF) -#define LAPACK_cpttrf LAPACK_GLOBAL(cpttrf,CPTTRF) -#define LAPACK_zpttrf LAPACK_GLOBAL(zpttrf,ZPTTRF) -#define LAPACK_ssytrf LAPACK_GLOBAL(ssytrf,SSYTRF) -#define LAPACK_dsytrf LAPACK_GLOBAL(dsytrf,DSYTRF) -#define LAPACK_csytrf LAPACK_GLOBAL(csytrf,CSYTRF) -#define LAPACK_zsytrf LAPACK_GLOBAL(zsytrf,ZSYTRF) -#define LAPACK_chetrf LAPACK_GLOBAL(chetrf,CHETRF) -#define LAPACK_zhetrf LAPACK_GLOBAL(zhetrf,ZHETRF) -#define LAPACK_ssptrf LAPACK_GLOBAL(ssptrf,SSPTRF) -#define LAPACK_dsptrf LAPACK_GLOBAL(dsptrf,DSPTRF) -#define LAPACK_csptrf LAPACK_GLOBAL(csptrf,CSPTRF) -#define LAPACK_zsptrf LAPACK_GLOBAL(zsptrf,ZSPTRF) -#define LAPACK_chptrf LAPACK_GLOBAL(chptrf,CHPTRF) -#define LAPACK_zhptrf LAPACK_GLOBAL(zhptrf,ZHPTRF) -#define LAPACK_sgetrs LAPACK_GLOBAL(sgetrs,SGETRS) -#define LAPACK_dgetrs LAPACK_GLOBAL(dgetrs,DGETRS) -#define LAPACK_cgetrs LAPACK_GLOBAL(cgetrs,CGETRS) -#define LAPACK_zgetrs LAPACK_GLOBAL(zgetrs,ZGETRS) -#define LAPACK_sgbtrs LAPACK_GLOBAL(sgbtrs,SGBTRS) -#define LAPACK_dgbtrs LAPACK_GLOBAL(dgbtrs,DGBTRS) -#define LAPACK_cgbtrs LAPACK_GLOBAL(cgbtrs,CGBTRS) -#define LAPACK_zgbtrs LAPACK_GLOBAL(zgbtrs,ZGBTRS) -#define LAPACK_sgttrs LAPACK_GLOBAL(sgttrs,SGTTRS) -#define LAPACK_dgttrs LAPACK_GLOBAL(dgttrs,DGTTRS) -#define LAPACK_cgttrs LAPACK_GLOBAL(cgttrs,CGTTRS) -#define LAPACK_zgttrs LAPACK_GLOBAL(zgttrs,ZGTTRS) -#define LAPACK_spotrs LAPACK_GLOBAL(spotrs,SPOTRS) -#define LAPACK_dpotrs LAPACK_GLOBAL(dpotrs,DPOTRS) -#define LAPACK_cpotrs LAPACK_GLOBAL(cpotrs,CPOTRS) -#define LAPACK_zpotrs LAPACK_GLOBAL(zpotrs,ZPOTRS) -#define LAPACK_dpftrs LAPACK_GLOBAL(dpftrs,DPFTRS) -#define LAPACK_spftrs LAPACK_GLOBAL(spftrs,SPFTRS) -#define LAPACK_zpftrs LAPACK_GLOBAL(zpftrs,ZPFTRS) -#define LAPACK_cpftrs LAPACK_GLOBAL(cpftrs,CPFTRS) -#define LAPACK_spptrs LAPACK_GLOBAL(spptrs,SPPTRS) -#define LAPACK_dpptrs LAPACK_GLOBAL(dpptrs,DPPTRS) -#define LAPACK_cpptrs LAPACK_GLOBAL(cpptrs,CPPTRS) -#define LAPACK_zpptrs LAPACK_GLOBAL(zpptrs,ZPPTRS) -#define LAPACK_spbtrs LAPACK_GLOBAL(spbtrs,SPBTRS) -#define LAPACK_dpbtrs LAPACK_GLOBAL(dpbtrs,DPBTRS) -#define LAPACK_cpbtrs LAPACK_GLOBAL(cpbtrs,CPBTRS) -#define LAPACK_zpbtrs LAPACK_GLOBAL(zpbtrs,ZPBTRS) -#define LAPACK_spttrs LAPACK_GLOBAL(spttrs,SPTTRS) -#define LAPACK_dpttrs LAPACK_GLOBAL(dpttrs,DPTTRS) -#define LAPACK_cpttrs LAPACK_GLOBAL(cpttrs,CPTTRS) -#define LAPACK_zpttrs LAPACK_GLOBAL(zpttrs,ZPTTRS) -#define LAPACK_ssytrs LAPACK_GLOBAL(ssytrs,SSYTRS) -#define LAPACK_dsytrs LAPACK_GLOBAL(dsytrs,DSYTRS) -#define LAPACK_csytrs LAPACK_GLOBAL(csytrs,CSYTRS) -#define LAPACK_zsytrs LAPACK_GLOBAL(zsytrs,ZSYTRS) -#define LAPACK_chetrs LAPACK_GLOBAL(chetrs,CHETRS) -#define LAPACK_zhetrs LAPACK_GLOBAL(zhetrs,ZHETRS) -#define LAPACK_ssptrs LAPACK_GLOBAL(ssptrs,SSPTRS) -#define LAPACK_dsptrs LAPACK_GLOBAL(dsptrs,DSPTRS) -#define LAPACK_csptrs LAPACK_GLOBAL(csptrs,CSPTRS) -#define LAPACK_zsptrs LAPACK_GLOBAL(zsptrs,ZSPTRS) -#define LAPACK_chptrs LAPACK_GLOBAL(chptrs,CHPTRS) -#define LAPACK_zhptrs LAPACK_GLOBAL(zhptrs,ZHPTRS) -#define LAPACK_strtrs LAPACK_GLOBAL(strtrs,STRTRS) -#define LAPACK_dtrtrs LAPACK_GLOBAL(dtrtrs,DTRTRS) -#define LAPACK_ctrtrs LAPACK_GLOBAL(ctrtrs,CTRTRS) -#define LAPACK_ztrtrs LAPACK_GLOBAL(ztrtrs,ZTRTRS) -#define LAPACK_stptrs LAPACK_GLOBAL(stptrs,STPTRS) -#define LAPACK_dtptrs LAPACK_GLOBAL(dtptrs,DTPTRS) -#define LAPACK_ctptrs LAPACK_GLOBAL(ctptrs,CTPTRS) -#define LAPACK_ztptrs LAPACK_GLOBAL(ztptrs,ZTPTRS) -#define LAPACK_stbtrs LAPACK_GLOBAL(stbtrs,STBTRS) -#define LAPACK_dtbtrs LAPACK_GLOBAL(dtbtrs,DTBTRS) -#define LAPACK_ctbtrs LAPACK_GLOBAL(ctbtrs,CTBTRS) -#define LAPACK_ztbtrs LAPACK_GLOBAL(ztbtrs,ZTBTRS) -#define LAPACK_sgecon LAPACK_GLOBAL(sgecon,SGECON) -#define LAPACK_dgecon LAPACK_GLOBAL(dgecon,DGECON) -#define LAPACK_cgecon LAPACK_GLOBAL(cgecon,CGECON) -#define LAPACK_zgecon LAPACK_GLOBAL(zgecon,ZGECON) -#define LAPACK_sgbcon LAPACK_GLOBAL(sgbcon,SGBCON) -#define LAPACK_dgbcon LAPACK_GLOBAL(dgbcon,DGBCON) -#define LAPACK_cgbcon LAPACK_GLOBAL(cgbcon,CGBCON) -#define LAPACK_zgbcon LAPACK_GLOBAL(zgbcon,ZGBCON) -#define LAPACK_sgtcon LAPACK_GLOBAL(sgtcon,SGTCON) -#define LAPACK_dgtcon LAPACK_GLOBAL(dgtcon,DGTCON) -#define LAPACK_cgtcon LAPACK_GLOBAL(cgtcon,CGTCON) -#define LAPACK_zgtcon LAPACK_GLOBAL(zgtcon,ZGTCON) -#define LAPACK_spocon LAPACK_GLOBAL(spocon,SPOCON) -#define LAPACK_dpocon LAPACK_GLOBAL(dpocon,DPOCON) -#define LAPACK_cpocon LAPACK_GLOBAL(cpocon,CPOCON) -#define LAPACK_zpocon LAPACK_GLOBAL(zpocon,ZPOCON) -#define LAPACK_sppcon LAPACK_GLOBAL(sppcon,SPPCON) -#define LAPACK_dppcon LAPACK_GLOBAL(dppcon,DPPCON) -#define LAPACK_cppcon LAPACK_GLOBAL(cppcon,CPPCON) -#define LAPACK_zppcon LAPACK_GLOBAL(zppcon,ZPPCON) -#define LAPACK_spbcon LAPACK_GLOBAL(spbcon,SPBCON) -#define LAPACK_dpbcon LAPACK_GLOBAL(dpbcon,DPBCON) -#define LAPACK_cpbcon LAPACK_GLOBAL(cpbcon,CPBCON) -#define LAPACK_zpbcon LAPACK_GLOBAL(zpbcon,ZPBCON) -#define LAPACK_sptcon LAPACK_GLOBAL(sptcon,SPTCON) -#define LAPACK_dptcon LAPACK_GLOBAL(dptcon,DPTCON) -#define LAPACK_cptcon LAPACK_GLOBAL(cptcon,CPTCON) -#define LAPACK_zptcon LAPACK_GLOBAL(zptcon,ZPTCON) -#define LAPACK_ssycon LAPACK_GLOBAL(ssycon,SSYCON) -#define LAPACK_dsycon LAPACK_GLOBAL(dsycon,DSYCON) -#define LAPACK_csycon LAPACK_GLOBAL(csycon,CSYCON) -#define LAPACK_zsycon LAPACK_GLOBAL(zsycon,ZSYCON) -#define LAPACK_checon LAPACK_GLOBAL(checon,CHECON) -#define LAPACK_zhecon LAPACK_GLOBAL(zhecon,ZHECON) -#define LAPACK_sspcon LAPACK_GLOBAL(sspcon,SSPCON) -#define LAPACK_dspcon LAPACK_GLOBAL(dspcon,DSPCON) -#define LAPACK_cspcon LAPACK_GLOBAL(cspcon,CSPCON) -#define LAPACK_zspcon LAPACK_GLOBAL(zspcon,ZSPCON) -#define LAPACK_chpcon LAPACK_GLOBAL(chpcon,CHPCON) -#define LAPACK_zhpcon LAPACK_GLOBAL(zhpcon,ZHPCON) -#define LAPACK_strcon LAPACK_GLOBAL(strcon,STRCON) -#define LAPACK_dtrcon LAPACK_GLOBAL(dtrcon,DTRCON) -#define LAPACK_ctrcon LAPACK_GLOBAL(ctrcon,CTRCON) -#define LAPACK_ztrcon LAPACK_GLOBAL(ztrcon,ZTRCON) -#define LAPACK_stpcon LAPACK_GLOBAL(stpcon,STPCON) -#define LAPACK_dtpcon LAPACK_GLOBAL(dtpcon,DTPCON) -#define LAPACK_ctpcon LAPACK_GLOBAL(ctpcon,CTPCON) -#define LAPACK_ztpcon LAPACK_GLOBAL(ztpcon,ZTPCON) -#define LAPACK_stbcon LAPACK_GLOBAL(stbcon,STBCON) -#define LAPACK_dtbcon LAPACK_GLOBAL(dtbcon,DTBCON) -#define LAPACK_ctbcon LAPACK_GLOBAL(ctbcon,CTBCON) -#define LAPACK_ztbcon LAPACK_GLOBAL(ztbcon,ZTBCON) -#define LAPACK_sgerfs LAPACK_GLOBAL(sgerfs,SGERFS) -#define LAPACK_dgerfs LAPACK_GLOBAL(dgerfs,DGERFS) -#define LAPACK_cgerfs LAPACK_GLOBAL(cgerfs,CGERFS) -#define LAPACK_zgerfs LAPACK_GLOBAL(zgerfs,ZGERFS) -#define LAPACK_dgerfsx LAPACK_GLOBAL(dgerfsx,DGERFSX) -#define LAPACK_sgerfsx LAPACK_GLOBAL(sgerfsx,SGERFSX) -#define LAPACK_zgerfsx LAPACK_GLOBAL(zgerfsx,ZGERFSX) -#define LAPACK_cgerfsx LAPACK_GLOBAL(cgerfsx,CGERFSX) -#define LAPACK_sgbrfs LAPACK_GLOBAL(sgbrfs,SGBRFS) -#define LAPACK_dgbrfs LAPACK_GLOBAL(dgbrfs,DGBRFS) -#define LAPACK_cgbrfs LAPACK_GLOBAL(cgbrfs,CGBRFS) -#define LAPACK_zgbrfs LAPACK_GLOBAL(zgbrfs,ZGBRFS) -#define LAPACK_dgbrfsx LAPACK_GLOBAL(dgbrfsx,DGBRFSX) -#define LAPACK_sgbrfsx LAPACK_GLOBAL(sgbrfsx,SGBRFSX) -#define LAPACK_zgbrfsx LAPACK_GLOBAL(zgbrfsx,ZGBRFSX) -#define LAPACK_cgbrfsx LAPACK_GLOBAL(cgbrfsx,CGBRFSX) -#define LAPACK_sgtrfs LAPACK_GLOBAL(sgtrfs,SGTRFS) -#define LAPACK_dgtrfs LAPACK_GLOBAL(dgtrfs,DGTRFS) -#define LAPACK_cgtrfs LAPACK_GLOBAL(cgtrfs,CGTRFS) -#define LAPACK_zgtrfs LAPACK_GLOBAL(zgtrfs,ZGTRFS) -#define LAPACK_sporfs LAPACK_GLOBAL(sporfs,SPORFS) -#define LAPACK_dporfs LAPACK_GLOBAL(dporfs,DPORFS) -#define LAPACK_cporfs LAPACK_GLOBAL(cporfs,CPORFS) -#define LAPACK_zporfs LAPACK_GLOBAL(zporfs,ZPORFS) -#define LAPACK_dporfsx LAPACK_GLOBAL(dporfsx,DPORFSX) -#define LAPACK_sporfsx LAPACK_GLOBAL(sporfsx,SPORFSX) -#define LAPACK_zporfsx LAPACK_GLOBAL(zporfsx,ZPORFSX) -#define LAPACK_cporfsx LAPACK_GLOBAL(cporfsx,CPORFSX) -#define LAPACK_spprfs LAPACK_GLOBAL(spprfs,SPPRFS) -#define LAPACK_dpprfs LAPACK_GLOBAL(dpprfs,DPPRFS) -#define LAPACK_cpprfs LAPACK_GLOBAL(cpprfs,CPPRFS) -#define LAPACK_zpprfs LAPACK_GLOBAL(zpprfs,ZPPRFS) -#define LAPACK_spbrfs LAPACK_GLOBAL(spbrfs,SPBRFS) -#define LAPACK_dpbrfs LAPACK_GLOBAL(dpbrfs,DPBRFS) -#define LAPACK_cpbrfs LAPACK_GLOBAL(cpbrfs,CPBRFS) -#define LAPACK_zpbrfs LAPACK_GLOBAL(zpbrfs,ZPBRFS) -#define LAPACK_sptrfs LAPACK_GLOBAL(sptrfs,SPTRFS) -#define LAPACK_dptrfs LAPACK_GLOBAL(dptrfs,DPTRFS) -#define LAPACK_cptrfs LAPACK_GLOBAL(cptrfs,CPTRFS) -#define LAPACK_zptrfs LAPACK_GLOBAL(zptrfs,ZPTRFS) -#define LAPACK_ssyrfs LAPACK_GLOBAL(ssyrfs,SSYRFS) -#define LAPACK_dsyrfs LAPACK_GLOBAL(dsyrfs,DSYRFS) -#define LAPACK_csyrfs LAPACK_GLOBAL(csyrfs,CSYRFS) -#define LAPACK_zsyrfs LAPACK_GLOBAL(zsyrfs,ZSYRFS) -#define LAPACK_dsyrfsx LAPACK_GLOBAL(dsyrfsx,DSYRFSX) -#define LAPACK_ssyrfsx LAPACK_GLOBAL(ssyrfsx,SSYRFSX) -#define LAPACK_zsyrfsx LAPACK_GLOBAL(zsyrfsx,ZSYRFSX) -#define LAPACK_csyrfsx LAPACK_GLOBAL(csyrfsx,CSYRFSX) -#define LAPACK_cherfs LAPACK_GLOBAL(cherfs,CHERFS) -#define LAPACK_zherfs LAPACK_GLOBAL(zherfs,ZHERFS) -#define LAPACK_zherfsx LAPACK_GLOBAL(zherfsx,ZHERFSX) -#define LAPACK_cherfsx LAPACK_GLOBAL(cherfsx,CHERFSX) -#define LAPACK_ssprfs LAPACK_GLOBAL(ssprfs,SSPRFS) -#define LAPACK_dsprfs LAPACK_GLOBAL(dsprfs,DSPRFS) -#define LAPACK_csprfs LAPACK_GLOBAL(csprfs,CSPRFS) -#define LAPACK_zsprfs LAPACK_GLOBAL(zsprfs,ZSPRFS) -#define LAPACK_chprfs LAPACK_GLOBAL(chprfs,CHPRFS) -#define LAPACK_zhprfs LAPACK_GLOBAL(zhprfs,ZHPRFS) -#define LAPACK_strrfs LAPACK_GLOBAL(strrfs,STRRFS) -#define LAPACK_dtrrfs LAPACK_GLOBAL(dtrrfs,DTRRFS) -#define LAPACK_ctrrfs LAPACK_GLOBAL(ctrrfs,CTRRFS) -#define LAPACK_ztrrfs LAPACK_GLOBAL(ztrrfs,ZTRRFS) -#define LAPACK_stprfs LAPACK_GLOBAL(stprfs,STPRFS) -#define LAPACK_dtprfs LAPACK_GLOBAL(dtprfs,DTPRFS) -#define LAPACK_ctprfs LAPACK_GLOBAL(ctprfs,CTPRFS) -#define LAPACK_ztprfs LAPACK_GLOBAL(ztprfs,ZTPRFS) -#define LAPACK_stbrfs LAPACK_GLOBAL(stbrfs,STBRFS) -#define LAPACK_dtbrfs LAPACK_GLOBAL(dtbrfs,DTBRFS) -#define LAPACK_ctbrfs LAPACK_GLOBAL(ctbrfs,CTBRFS) -#define LAPACK_ztbrfs LAPACK_GLOBAL(ztbrfs,ZTBRFS) -#define LAPACK_sgetri LAPACK_GLOBAL(sgetri,SGETRI) -#define LAPACK_dgetri LAPACK_GLOBAL(dgetri,DGETRI) -#define LAPACK_cgetri LAPACK_GLOBAL(cgetri,CGETRI) -#define LAPACK_zgetri LAPACK_GLOBAL(zgetri,ZGETRI) -#define LAPACK_spotri LAPACK_GLOBAL(spotri,SPOTRI) -#define LAPACK_dpotri LAPACK_GLOBAL(dpotri,DPOTRI) -#define LAPACK_cpotri LAPACK_GLOBAL(cpotri,CPOTRI) -#define LAPACK_zpotri LAPACK_GLOBAL(zpotri,ZPOTRI) -#define LAPACK_dpftri LAPACK_GLOBAL(dpftri,DPFTRI) -#define LAPACK_spftri LAPACK_GLOBAL(spftri,SPFTRI) -#define LAPACK_zpftri LAPACK_GLOBAL(zpftri,ZPFTRI) -#define LAPACK_cpftri LAPACK_GLOBAL(cpftri,CPFTRI) -#define LAPACK_spptri LAPACK_GLOBAL(spptri,SPPTRI) -#define LAPACK_dpptri LAPACK_GLOBAL(dpptri,DPPTRI) -#define LAPACK_cpptri LAPACK_GLOBAL(cpptri,CPPTRI) -#define LAPACK_zpptri LAPACK_GLOBAL(zpptri,ZPPTRI) -#define LAPACK_ssytri LAPACK_GLOBAL(ssytri,SSYTRI) -#define LAPACK_dsytri LAPACK_GLOBAL(dsytri,DSYTRI) -#define LAPACK_csytri LAPACK_GLOBAL(csytri,CSYTRI) -#define LAPACK_zsytri LAPACK_GLOBAL(zsytri,ZSYTRI) -#define LAPACK_chetri LAPACK_GLOBAL(chetri,CHETRI) -#define LAPACK_zhetri LAPACK_GLOBAL(zhetri,ZHETRI) -#define LAPACK_ssptri LAPACK_GLOBAL(ssptri,SSPTRI) -#define LAPACK_dsptri LAPACK_GLOBAL(dsptri,DSPTRI) -#define LAPACK_csptri LAPACK_GLOBAL(csptri,CSPTRI) -#define LAPACK_zsptri LAPACK_GLOBAL(zsptri,ZSPTRI) -#define LAPACK_chptri LAPACK_GLOBAL(chptri,CHPTRI) -#define LAPACK_zhptri LAPACK_GLOBAL(zhptri,ZHPTRI) -#define LAPACK_strtri LAPACK_GLOBAL(strtri,STRTRI) -#define LAPACK_dtrtri LAPACK_GLOBAL(dtrtri,DTRTRI) -#define LAPACK_ctrtri LAPACK_GLOBAL(ctrtri,CTRTRI) -#define LAPACK_ztrtri LAPACK_GLOBAL(ztrtri,ZTRTRI) -#define LAPACK_dtftri LAPACK_GLOBAL(dtftri,DTFTRI) -#define LAPACK_stftri LAPACK_GLOBAL(stftri,STFTRI) -#define LAPACK_ztftri LAPACK_GLOBAL(ztftri,ZTFTRI) -#define LAPACK_ctftri LAPACK_GLOBAL(ctftri,CTFTRI) -#define LAPACK_stptri LAPACK_GLOBAL(stptri,STPTRI) -#define LAPACK_dtptri LAPACK_GLOBAL(dtptri,DTPTRI) -#define LAPACK_ctptri LAPACK_GLOBAL(ctptri,CTPTRI) -#define LAPACK_ztptri LAPACK_GLOBAL(ztptri,ZTPTRI) -#define LAPACK_sgeequ LAPACK_GLOBAL(sgeequ,SGEEQU) -#define LAPACK_dgeequ LAPACK_GLOBAL(dgeequ,DGEEQU) -#define LAPACK_cgeequ LAPACK_GLOBAL(cgeequ,CGEEQU) -#define LAPACK_zgeequ LAPACK_GLOBAL(zgeequ,ZGEEQU) -#define LAPACK_dgeequb LAPACK_GLOBAL(dgeequb,DGEEQUB) -#define LAPACK_sgeequb LAPACK_GLOBAL(sgeequb,SGEEQUB) -#define LAPACK_zgeequb LAPACK_GLOBAL(zgeequb,ZGEEQUB) -#define LAPACK_cgeequb LAPACK_GLOBAL(cgeequb,CGEEQUB) -#define LAPACK_sgbequ LAPACK_GLOBAL(sgbequ,SGBEQU) -#define LAPACK_dgbequ LAPACK_GLOBAL(dgbequ,DGBEQU) -#define LAPACK_cgbequ LAPACK_GLOBAL(cgbequ,CGBEQU) -#define LAPACK_zgbequ LAPACK_GLOBAL(zgbequ,ZGBEQU) -#define LAPACK_dgbequb LAPACK_GLOBAL(dgbequb,DGBEQUB) -#define LAPACK_sgbequb LAPACK_GLOBAL(sgbequb,SGBEQUB) -#define LAPACK_zgbequb LAPACK_GLOBAL(zgbequb,ZGBEQUB) -#define LAPACK_cgbequb LAPACK_GLOBAL(cgbequb,CGBEQUB) -#define LAPACK_spoequ LAPACK_GLOBAL(spoequ,SPOEQU) -#define LAPACK_dpoequ LAPACK_GLOBAL(dpoequ,DPOEQU) -#define LAPACK_cpoequ LAPACK_GLOBAL(cpoequ,CPOEQU) -#define LAPACK_zpoequ LAPACK_GLOBAL(zpoequ,ZPOEQU) -#define LAPACK_dpoequb LAPACK_GLOBAL(dpoequb,DPOEQUB) -#define LAPACK_spoequb LAPACK_GLOBAL(spoequb,SPOEQUB) -#define LAPACK_zpoequb LAPACK_GLOBAL(zpoequb,ZPOEQUB) -#define LAPACK_cpoequb LAPACK_GLOBAL(cpoequb,CPOEQUB) -#define LAPACK_sppequ LAPACK_GLOBAL(sppequ,SPPEQU) -#define LAPACK_dppequ LAPACK_GLOBAL(dppequ,DPPEQU) -#define LAPACK_cppequ LAPACK_GLOBAL(cppequ,CPPEQU) -#define LAPACK_zppequ LAPACK_GLOBAL(zppequ,ZPPEQU) -#define LAPACK_spbequ LAPACK_GLOBAL(spbequ,SPBEQU) -#define LAPACK_dpbequ LAPACK_GLOBAL(dpbequ,DPBEQU) -#define LAPACK_cpbequ LAPACK_GLOBAL(cpbequ,CPBEQU) -#define LAPACK_zpbequ LAPACK_GLOBAL(zpbequ,ZPBEQU) -#define LAPACK_dsyequb LAPACK_GLOBAL(dsyequb,DSYEQUB) -#define LAPACK_ssyequb LAPACK_GLOBAL(ssyequb,SSYEQUB) -#define LAPACK_zsyequb LAPACK_GLOBAL(zsyequb,ZSYEQUB) -#define LAPACK_csyequb LAPACK_GLOBAL(csyequb,CSYEQUB) -#define LAPACK_zheequb LAPACK_GLOBAL(zheequb,ZHEEQUB) -#define LAPACK_cheequb LAPACK_GLOBAL(cheequb,CHEEQUB) -#define LAPACK_sgesv LAPACK_GLOBAL(sgesv,SGESV) -#define LAPACK_dgesv LAPACK_GLOBAL(dgesv,DGESV) -#define LAPACK_cgesv LAPACK_GLOBAL(cgesv,CGESV) -#define LAPACK_zgesv LAPACK_GLOBAL(zgesv,ZGESV) -#define LAPACK_dsgesv LAPACK_GLOBAL(dsgesv,DSGESV) -#define LAPACK_zcgesv LAPACK_GLOBAL(zcgesv,ZCGESV) -#define LAPACK_sgesvx LAPACK_GLOBAL(sgesvx,SGESVX) -#define LAPACK_dgesvx LAPACK_GLOBAL(dgesvx,DGESVX) -#define LAPACK_cgesvx LAPACK_GLOBAL(cgesvx,CGESVX) -#define LAPACK_zgesvx LAPACK_GLOBAL(zgesvx,ZGESVX) -#define LAPACK_dgesvxx LAPACK_GLOBAL(dgesvxx,DGESVXX) -#define LAPACK_sgesvxx LAPACK_GLOBAL(sgesvxx,SGESVXX) -#define LAPACK_zgesvxx LAPACK_GLOBAL(zgesvxx,ZGESVXX) -#define LAPACK_cgesvxx LAPACK_GLOBAL(cgesvxx,CGESVXX) -#define LAPACK_sgbsv LAPACK_GLOBAL(sgbsv,SGBSV) -#define LAPACK_dgbsv LAPACK_GLOBAL(dgbsv,DGBSV) -#define LAPACK_cgbsv LAPACK_GLOBAL(cgbsv,CGBSV) -#define LAPACK_zgbsv LAPACK_GLOBAL(zgbsv,ZGBSV) -#define LAPACK_sgbsvx LAPACK_GLOBAL(sgbsvx,SGBSVX) -#define LAPACK_dgbsvx LAPACK_GLOBAL(dgbsvx,DGBSVX) -#define LAPACK_cgbsvx LAPACK_GLOBAL(cgbsvx,CGBSVX) -#define LAPACK_zgbsvx LAPACK_GLOBAL(zgbsvx,ZGBSVX) -#define LAPACK_dgbsvxx LAPACK_GLOBAL(dgbsvxx,DGBSVXX) -#define LAPACK_sgbsvxx LAPACK_GLOBAL(sgbsvxx,SGBSVXX) -#define LAPACK_zgbsvxx LAPACK_GLOBAL(zgbsvxx,ZGBSVXX) -#define LAPACK_cgbsvxx LAPACK_GLOBAL(cgbsvxx,CGBSVXX) -#define LAPACK_sgtsv LAPACK_GLOBAL(sgtsv,SGTSV) -#define LAPACK_dgtsv LAPACK_GLOBAL(dgtsv,DGTSV) -#define LAPACK_cgtsv LAPACK_GLOBAL(cgtsv,CGTSV) -#define LAPACK_zgtsv LAPACK_GLOBAL(zgtsv,ZGTSV) -#define LAPACK_sgtsvx LAPACK_GLOBAL(sgtsvx,SGTSVX) -#define LAPACK_dgtsvx LAPACK_GLOBAL(dgtsvx,DGTSVX) -#define LAPACK_cgtsvx LAPACK_GLOBAL(cgtsvx,CGTSVX) -#define LAPACK_zgtsvx LAPACK_GLOBAL(zgtsvx,ZGTSVX) -#define LAPACK_sposv LAPACK_GLOBAL(sposv,SPOSV) -#define LAPACK_dposv LAPACK_GLOBAL(dposv,DPOSV) -#define LAPACK_cposv LAPACK_GLOBAL(cposv,CPOSV) -#define LAPACK_zposv LAPACK_GLOBAL(zposv,ZPOSV) -#define LAPACK_dsposv LAPACK_GLOBAL(dsposv,DSPOSV) -#define LAPACK_zcposv LAPACK_GLOBAL(zcposv,ZCPOSV) -#define LAPACK_sposvx LAPACK_GLOBAL(sposvx,SPOSVX) -#define LAPACK_dposvx LAPACK_GLOBAL(dposvx,DPOSVX) -#define LAPACK_cposvx LAPACK_GLOBAL(cposvx,CPOSVX) -#define LAPACK_zposvx LAPACK_GLOBAL(zposvx,ZPOSVX) -#define LAPACK_dposvxx LAPACK_GLOBAL(dposvxx,DPOSVXX) -#define LAPACK_sposvxx LAPACK_GLOBAL(sposvxx,SPOSVXX) -#define LAPACK_zposvxx LAPACK_GLOBAL(zposvxx,ZPOSVXX) -#define LAPACK_cposvxx LAPACK_GLOBAL(cposvxx,CPOSVXX) -#define LAPACK_sppsv LAPACK_GLOBAL(sppsv,SPPSV) -#define LAPACK_dppsv LAPACK_GLOBAL(dppsv,DPPSV) -#define LAPACK_cppsv LAPACK_GLOBAL(cppsv,CPPSV) -#define LAPACK_zppsv LAPACK_GLOBAL(zppsv,ZPPSV) -#define LAPACK_sppsvx LAPACK_GLOBAL(sppsvx,SPPSVX) -#define LAPACK_dppsvx LAPACK_GLOBAL(dppsvx,DPPSVX) -#define LAPACK_cppsvx LAPACK_GLOBAL(cppsvx,CPPSVX) -#define LAPACK_zppsvx LAPACK_GLOBAL(zppsvx,ZPPSVX) -#define LAPACK_spbsv LAPACK_GLOBAL(spbsv,SPBSV) -#define LAPACK_dpbsv LAPACK_GLOBAL(dpbsv,DPBSV) -#define LAPACK_cpbsv LAPACK_GLOBAL(cpbsv,CPBSV) -#define LAPACK_zpbsv LAPACK_GLOBAL(zpbsv,ZPBSV) -#define LAPACK_spbsvx LAPACK_GLOBAL(spbsvx,SPBSVX) -#define LAPACK_dpbsvx LAPACK_GLOBAL(dpbsvx,DPBSVX) -#define LAPACK_cpbsvx LAPACK_GLOBAL(cpbsvx,CPBSVX) -#define LAPACK_zpbsvx LAPACK_GLOBAL(zpbsvx,ZPBSVX) -#define LAPACK_sptsv LAPACK_GLOBAL(sptsv,SPTSV) -#define LAPACK_dptsv LAPACK_GLOBAL(dptsv,DPTSV) -#define LAPACK_cptsv LAPACK_GLOBAL(cptsv,CPTSV) -#define LAPACK_zptsv LAPACK_GLOBAL(zptsv,ZPTSV) -#define LAPACK_sptsvx LAPACK_GLOBAL(sptsvx,SPTSVX) -#define LAPACK_dptsvx LAPACK_GLOBAL(dptsvx,DPTSVX) -#define LAPACK_cptsvx LAPACK_GLOBAL(cptsvx,CPTSVX) -#define LAPACK_zptsvx LAPACK_GLOBAL(zptsvx,ZPTSVX) -#define LAPACK_ssysv LAPACK_GLOBAL(ssysv,SSYSV) -#define LAPACK_dsysv LAPACK_GLOBAL(dsysv,DSYSV) -#define LAPACK_csysv LAPACK_GLOBAL(csysv,CSYSV) -#define LAPACK_zsysv LAPACK_GLOBAL(zsysv,ZSYSV) -#define LAPACK_ssysvx LAPACK_GLOBAL(ssysvx,SSYSVX) -#define LAPACK_dsysvx LAPACK_GLOBAL(dsysvx,DSYSVX) -#define LAPACK_csysvx LAPACK_GLOBAL(csysvx,CSYSVX) -#define LAPACK_zsysvx LAPACK_GLOBAL(zsysvx,ZSYSVX) -#define LAPACK_dsysvxx LAPACK_GLOBAL(dsysvxx,DSYSVXX) -#define LAPACK_ssysvxx LAPACK_GLOBAL(ssysvxx,SSYSVXX) -#define LAPACK_zsysvxx LAPACK_GLOBAL(zsysvxx,ZSYSVXX) -#define LAPACK_csysvxx LAPACK_GLOBAL(csysvxx,CSYSVXX) -#define LAPACK_chesv LAPACK_GLOBAL(chesv,CHESV) -#define LAPACK_zhesv LAPACK_GLOBAL(zhesv,ZHESV) -#define LAPACK_chesvx LAPACK_GLOBAL(chesvx,CHESVX) -#define LAPACK_zhesvx LAPACK_GLOBAL(zhesvx,ZHESVX) -#define LAPACK_zhesvxx LAPACK_GLOBAL(zhesvxx,ZHESVXX) -#define LAPACK_chesvxx LAPACK_GLOBAL(chesvxx,CHESVXX) -#define LAPACK_sspsv LAPACK_GLOBAL(sspsv,SSPSV) -#define LAPACK_dspsv LAPACK_GLOBAL(dspsv,DSPSV) -#define LAPACK_cspsv LAPACK_GLOBAL(cspsv,CSPSV) -#define LAPACK_zspsv LAPACK_GLOBAL(zspsv,ZSPSV) -#define LAPACK_sspsvx LAPACK_GLOBAL(sspsvx,SSPSVX) -#define LAPACK_dspsvx LAPACK_GLOBAL(dspsvx,DSPSVX) -#define LAPACK_cspsvx LAPACK_GLOBAL(cspsvx,CSPSVX) -#define LAPACK_zspsvx LAPACK_GLOBAL(zspsvx,ZSPSVX) -#define LAPACK_chpsv LAPACK_GLOBAL(chpsv,CHPSV) -#define LAPACK_zhpsv LAPACK_GLOBAL(zhpsv,ZHPSV) -#define LAPACK_chpsvx LAPACK_GLOBAL(chpsvx,CHPSVX) -#define LAPACK_zhpsvx LAPACK_GLOBAL(zhpsvx,ZHPSVX) -#define LAPACK_sgeqrf LAPACK_GLOBAL(sgeqrf,SGEQRF) -#define LAPACK_dgeqrf LAPACK_GLOBAL(dgeqrf,DGEQRF) -#define LAPACK_cgeqrf LAPACK_GLOBAL(cgeqrf,CGEQRF) -#define LAPACK_zgeqrf LAPACK_GLOBAL(zgeqrf,ZGEQRF) -#define LAPACK_sgeqpf LAPACK_GLOBAL(sgeqpf,SGEQPF) -#define LAPACK_dgeqpf LAPACK_GLOBAL(dgeqpf,DGEQPF) -#define LAPACK_cgeqpf LAPACK_GLOBAL(cgeqpf,CGEQPF) -#define LAPACK_zgeqpf LAPACK_GLOBAL(zgeqpf,ZGEQPF) -#define LAPACK_sgeqp3 LAPACK_GLOBAL(sgeqp3,SGEQP3) -#define LAPACK_dgeqp3 LAPACK_GLOBAL(dgeqp3,DGEQP3) -#define LAPACK_cgeqp3 LAPACK_GLOBAL(cgeqp3,CGEQP3) -#define LAPACK_zgeqp3 LAPACK_GLOBAL(zgeqp3,ZGEQP3) -#define LAPACK_sorgqr LAPACK_GLOBAL(sorgqr,SORGQR) -#define LAPACK_dorgqr LAPACK_GLOBAL(dorgqr,DORGQR) -#define LAPACK_sormqr LAPACK_GLOBAL(sormqr,SORMQR) -#define LAPACK_dormqr LAPACK_GLOBAL(dormqr,DORMQR) -#define LAPACK_cungqr LAPACK_GLOBAL(cungqr,CUNGQR) -#define LAPACK_zungqr LAPACK_GLOBAL(zungqr,ZUNGQR) -#define LAPACK_cunmqr LAPACK_GLOBAL(cunmqr,CUNMQR) -#define LAPACK_zunmqr LAPACK_GLOBAL(zunmqr,ZUNMQR) -#define LAPACK_sgelqf LAPACK_GLOBAL(sgelqf,SGELQF) -#define LAPACK_dgelqf LAPACK_GLOBAL(dgelqf,DGELQF) -#define LAPACK_cgelqf LAPACK_GLOBAL(cgelqf,CGELQF) -#define LAPACK_zgelqf LAPACK_GLOBAL(zgelqf,ZGELQF) -#define LAPACK_sorglq LAPACK_GLOBAL(sorglq,SORGLQ) -#define LAPACK_dorglq LAPACK_GLOBAL(dorglq,DORGLQ) -#define LAPACK_sormlq LAPACK_GLOBAL(sormlq,SORMLQ) -#define LAPACK_dormlq LAPACK_GLOBAL(dormlq,DORMLQ) -#define LAPACK_cunglq LAPACK_GLOBAL(cunglq,CUNGLQ) -#define LAPACK_zunglq LAPACK_GLOBAL(zunglq,ZUNGLQ) -#define LAPACK_cunmlq LAPACK_GLOBAL(cunmlq,CUNMLQ) -#define LAPACK_zunmlq LAPACK_GLOBAL(zunmlq,ZUNMLQ) -#define LAPACK_sgeqlf LAPACK_GLOBAL(sgeqlf,SGEQLF) -#define LAPACK_dgeqlf LAPACK_GLOBAL(dgeqlf,DGEQLF) -#define LAPACK_cgeqlf LAPACK_GLOBAL(cgeqlf,CGEQLF) -#define LAPACK_zgeqlf LAPACK_GLOBAL(zgeqlf,ZGEQLF) -#define LAPACK_sorgql LAPACK_GLOBAL(sorgql,SORGQL) -#define LAPACK_dorgql LAPACK_GLOBAL(dorgql,DORGQL) -#define LAPACK_cungql LAPACK_GLOBAL(cungql,CUNGQL) -#define LAPACK_zungql LAPACK_GLOBAL(zungql,ZUNGQL) -#define LAPACK_sormql LAPACK_GLOBAL(sormql,SORMQL) -#define LAPACK_dormql LAPACK_GLOBAL(dormql,DORMQL) -#define LAPACK_cunmql LAPACK_GLOBAL(cunmql,CUNMQL) -#define LAPACK_zunmql LAPACK_GLOBAL(zunmql,ZUNMQL) -#define LAPACK_sgerqf LAPACK_GLOBAL(sgerqf,SGERQF) -#define LAPACK_dgerqf LAPACK_GLOBAL(dgerqf,DGERQF) -#define LAPACK_cgerqf LAPACK_GLOBAL(cgerqf,CGERQF) -#define LAPACK_zgerqf LAPACK_GLOBAL(zgerqf,ZGERQF) -#define LAPACK_sorgrq LAPACK_GLOBAL(sorgrq,SORGRQ) -#define LAPACK_dorgrq LAPACK_GLOBAL(dorgrq,DORGRQ) -#define LAPACK_cungrq LAPACK_GLOBAL(cungrq,CUNGRQ) -#define LAPACK_zungrq LAPACK_GLOBAL(zungrq,ZUNGRQ) -#define LAPACK_sormrq LAPACK_GLOBAL(sormrq,SORMRQ) -#define LAPACK_dormrq LAPACK_GLOBAL(dormrq,DORMRQ) -#define LAPACK_cunmrq LAPACK_GLOBAL(cunmrq,CUNMRQ) -#define LAPACK_zunmrq LAPACK_GLOBAL(zunmrq,ZUNMRQ) -#define LAPACK_stzrzf LAPACK_GLOBAL(stzrzf,STZRZF) -#define LAPACK_dtzrzf LAPACK_GLOBAL(dtzrzf,DTZRZF) -#define LAPACK_ctzrzf LAPACK_GLOBAL(ctzrzf,CTZRZF) -#define LAPACK_ztzrzf LAPACK_GLOBAL(ztzrzf,ZTZRZF) -#define LAPACK_sormrz LAPACK_GLOBAL(sormrz,SORMRZ) -#define LAPACK_dormrz LAPACK_GLOBAL(dormrz,DORMRZ) -#define LAPACK_cunmrz LAPACK_GLOBAL(cunmrz,CUNMRZ) -#define LAPACK_zunmrz LAPACK_GLOBAL(zunmrz,ZUNMRZ) -#define LAPACK_sggqrf LAPACK_GLOBAL(sggqrf,SGGQRF) -#define LAPACK_dggqrf LAPACK_GLOBAL(dggqrf,DGGQRF) -#define LAPACK_cggqrf LAPACK_GLOBAL(cggqrf,CGGQRF) -#define LAPACK_zggqrf LAPACK_GLOBAL(zggqrf,ZGGQRF) -#define LAPACK_sggrqf LAPACK_GLOBAL(sggrqf,SGGRQF) -#define LAPACK_dggrqf LAPACK_GLOBAL(dggrqf,DGGRQF) -#define LAPACK_cggrqf LAPACK_GLOBAL(cggrqf,CGGRQF) -#define LAPACK_zggrqf LAPACK_GLOBAL(zggrqf,ZGGRQF) -#define LAPACK_sgebrd LAPACK_GLOBAL(sgebrd,SGEBRD) -#define LAPACK_dgebrd LAPACK_GLOBAL(dgebrd,DGEBRD) -#define LAPACK_cgebrd LAPACK_GLOBAL(cgebrd,CGEBRD) -#define LAPACK_zgebrd LAPACK_GLOBAL(zgebrd,ZGEBRD) -#define LAPACK_sgbbrd LAPACK_GLOBAL(sgbbrd,SGBBRD) -#define LAPACK_dgbbrd LAPACK_GLOBAL(dgbbrd,DGBBRD) -#define LAPACK_cgbbrd LAPACK_GLOBAL(cgbbrd,CGBBRD) -#define LAPACK_zgbbrd LAPACK_GLOBAL(zgbbrd,ZGBBRD) -#define LAPACK_sorgbr LAPACK_GLOBAL(sorgbr,SORGBR) -#define LAPACK_dorgbr LAPACK_GLOBAL(dorgbr,DORGBR) -#define LAPACK_sormbr LAPACK_GLOBAL(sormbr,SORMBR) -#define LAPACK_dormbr LAPACK_GLOBAL(dormbr,DORMBR) -#define LAPACK_cungbr LAPACK_GLOBAL(cungbr,CUNGBR) -#define LAPACK_zungbr LAPACK_GLOBAL(zungbr,ZUNGBR) -#define LAPACK_cunmbr LAPACK_GLOBAL(cunmbr,CUNMBR) -#define LAPACK_zunmbr LAPACK_GLOBAL(zunmbr,ZUNMBR) -#define LAPACK_sbdsqr LAPACK_GLOBAL(sbdsqr,SBDSQR) -#define LAPACK_dbdsqr LAPACK_GLOBAL(dbdsqr,DBDSQR) -#define LAPACK_cbdsqr LAPACK_GLOBAL(cbdsqr,CBDSQR) -#define LAPACK_zbdsqr LAPACK_GLOBAL(zbdsqr,ZBDSQR) -#define LAPACK_sbdsdc LAPACK_GLOBAL(sbdsdc,SBDSDC) -#define LAPACK_dbdsdc LAPACK_GLOBAL(dbdsdc,DBDSDC) -#define LAPACK_ssytrd LAPACK_GLOBAL(ssytrd,SSYTRD) -#define LAPACK_dsytrd LAPACK_GLOBAL(dsytrd,DSYTRD) -#define LAPACK_sorgtr LAPACK_GLOBAL(sorgtr,SORGTR) -#define LAPACK_dorgtr LAPACK_GLOBAL(dorgtr,DORGTR) -#define LAPACK_sormtr LAPACK_GLOBAL(sormtr,SORMTR) -#define LAPACK_dormtr LAPACK_GLOBAL(dormtr,DORMTR) -#define LAPACK_chetrd LAPACK_GLOBAL(chetrd,CHETRD) -#define LAPACK_zhetrd LAPACK_GLOBAL(zhetrd,ZHETRD) -#define LAPACK_cungtr LAPACK_GLOBAL(cungtr,CUNGTR) -#define LAPACK_zungtr LAPACK_GLOBAL(zungtr,ZUNGTR) -#define LAPACK_cunmtr LAPACK_GLOBAL(cunmtr,CUNMTR) -#define LAPACK_zunmtr LAPACK_GLOBAL(zunmtr,ZUNMTR) -#define LAPACK_ssptrd LAPACK_GLOBAL(ssptrd,SSPTRD) -#define LAPACK_dsptrd LAPACK_GLOBAL(dsptrd,DSPTRD) -#define LAPACK_sopgtr LAPACK_GLOBAL(sopgtr,SOPGTR) -#define LAPACK_dopgtr LAPACK_GLOBAL(dopgtr,DOPGTR) -#define LAPACK_sopmtr LAPACK_GLOBAL(sopmtr,SOPMTR) -#define LAPACK_dopmtr LAPACK_GLOBAL(dopmtr,DOPMTR) -#define LAPACK_chptrd LAPACK_GLOBAL(chptrd,CHPTRD) -#define LAPACK_zhptrd LAPACK_GLOBAL(zhptrd,ZHPTRD) -#define LAPACK_cupgtr LAPACK_GLOBAL(cupgtr,CUPGTR) -#define LAPACK_zupgtr LAPACK_GLOBAL(zupgtr,ZUPGTR) -#define LAPACK_cupmtr LAPACK_GLOBAL(cupmtr,CUPMTR) -#define LAPACK_zupmtr LAPACK_GLOBAL(zupmtr,ZUPMTR) -#define LAPACK_ssbtrd LAPACK_GLOBAL(ssbtrd,SSBTRD) -#define LAPACK_dsbtrd LAPACK_GLOBAL(dsbtrd,DSBTRD) -#define LAPACK_chbtrd LAPACK_GLOBAL(chbtrd,CHBTRD) -#define LAPACK_zhbtrd LAPACK_GLOBAL(zhbtrd,ZHBTRD) -#define LAPACK_ssterf LAPACK_GLOBAL(ssterf,SSTERF) -#define LAPACK_dsterf LAPACK_GLOBAL(dsterf,DSTERF) -#define LAPACK_ssteqr LAPACK_GLOBAL(ssteqr,SSTEQR) -#define LAPACK_dsteqr LAPACK_GLOBAL(dsteqr,DSTEQR) -#define LAPACK_csteqr LAPACK_GLOBAL(csteqr,CSTEQR) -#define LAPACK_zsteqr LAPACK_GLOBAL(zsteqr,ZSTEQR) -#define LAPACK_sstemr LAPACK_GLOBAL(sstemr,SSTEMR) -#define LAPACK_dstemr LAPACK_GLOBAL(dstemr,DSTEMR) -#define LAPACK_cstemr LAPACK_GLOBAL(cstemr,CSTEMR) -#define LAPACK_zstemr LAPACK_GLOBAL(zstemr,ZSTEMR) -#define LAPACK_sstedc LAPACK_GLOBAL(sstedc,SSTEDC) -#define LAPACK_dstedc LAPACK_GLOBAL(dstedc,DSTEDC) -#define LAPACK_cstedc LAPACK_GLOBAL(cstedc,CSTEDC) -#define LAPACK_zstedc LAPACK_GLOBAL(zstedc,ZSTEDC) -#define LAPACK_sstegr LAPACK_GLOBAL(sstegr,SSTEGR) -#define LAPACK_dstegr LAPACK_GLOBAL(dstegr,DSTEGR) -#define LAPACK_cstegr LAPACK_GLOBAL(cstegr,CSTEGR) -#define LAPACK_zstegr LAPACK_GLOBAL(zstegr,ZSTEGR) -#define LAPACK_spteqr LAPACK_GLOBAL(spteqr,SPTEQR) -#define LAPACK_dpteqr LAPACK_GLOBAL(dpteqr,DPTEQR) -#define LAPACK_cpteqr LAPACK_GLOBAL(cpteqr,CPTEQR) -#define LAPACK_zpteqr LAPACK_GLOBAL(zpteqr,ZPTEQR) -#define LAPACK_sstebz LAPACK_GLOBAL(sstebz,SSTEBZ) -#define LAPACK_dstebz LAPACK_GLOBAL(dstebz,DSTEBZ) -#define LAPACK_sstein LAPACK_GLOBAL(sstein,SSTEIN) -#define LAPACK_dstein LAPACK_GLOBAL(dstein,DSTEIN) -#define LAPACK_cstein LAPACK_GLOBAL(cstein,CSTEIN) -#define LAPACK_zstein LAPACK_GLOBAL(zstein,ZSTEIN) -#define LAPACK_sdisna LAPACK_GLOBAL(sdisna,SDISNA) -#define LAPACK_ddisna LAPACK_GLOBAL(ddisna,DDISNA) -#define LAPACK_ssygst LAPACK_GLOBAL(ssygst,SSYGST) -#define LAPACK_dsygst LAPACK_GLOBAL(dsygst,DSYGST) -#define LAPACK_chegst LAPACK_GLOBAL(chegst,CHEGST) -#define LAPACK_zhegst LAPACK_GLOBAL(zhegst,ZHEGST) -#define LAPACK_sspgst LAPACK_GLOBAL(sspgst,SSPGST) -#define LAPACK_dspgst LAPACK_GLOBAL(dspgst,DSPGST) -#define LAPACK_chpgst LAPACK_GLOBAL(chpgst,CHPGST) -#define LAPACK_zhpgst LAPACK_GLOBAL(zhpgst,ZHPGST) -#define LAPACK_ssbgst LAPACK_GLOBAL(ssbgst,SSBGST) -#define LAPACK_dsbgst LAPACK_GLOBAL(dsbgst,DSBGST) -#define LAPACK_chbgst LAPACK_GLOBAL(chbgst,CHBGST) -#define LAPACK_zhbgst LAPACK_GLOBAL(zhbgst,ZHBGST) -#define LAPACK_spbstf LAPACK_GLOBAL(spbstf,SPBSTF) -#define LAPACK_dpbstf LAPACK_GLOBAL(dpbstf,DPBSTF) -#define LAPACK_cpbstf LAPACK_GLOBAL(cpbstf,CPBSTF) -#define LAPACK_zpbstf LAPACK_GLOBAL(zpbstf,ZPBSTF) -#define LAPACK_sgehrd LAPACK_GLOBAL(sgehrd,SGEHRD) -#define LAPACK_dgehrd LAPACK_GLOBAL(dgehrd,DGEHRD) -#define LAPACK_cgehrd LAPACK_GLOBAL(cgehrd,CGEHRD) -#define LAPACK_zgehrd LAPACK_GLOBAL(zgehrd,ZGEHRD) -#define LAPACK_sorghr LAPACK_GLOBAL(sorghr,SORGHR) -#define LAPACK_dorghr LAPACK_GLOBAL(dorghr,DORGHR) -#define LAPACK_sormhr LAPACK_GLOBAL(sormhr,SORMHR) -#define LAPACK_dormhr LAPACK_GLOBAL(dormhr,DORMHR) -#define LAPACK_cunghr LAPACK_GLOBAL(cunghr,CUNGHR) -#define LAPACK_zunghr LAPACK_GLOBAL(zunghr,ZUNGHR) -#define LAPACK_cunmhr LAPACK_GLOBAL(cunmhr,CUNMHR) -#define LAPACK_zunmhr LAPACK_GLOBAL(zunmhr,ZUNMHR) -#define LAPACK_sgebal LAPACK_GLOBAL(sgebal,SGEBAL) -#define LAPACK_dgebal LAPACK_GLOBAL(dgebal,DGEBAL) -#define LAPACK_cgebal LAPACK_GLOBAL(cgebal,CGEBAL) -#define LAPACK_zgebal LAPACK_GLOBAL(zgebal,ZGEBAL) -#define LAPACK_sgebak LAPACK_GLOBAL(sgebak,SGEBAK) -#define LAPACK_dgebak LAPACK_GLOBAL(dgebak,DGEBAK) -#define LAPACK_cgebak LAPACK_GLOBAL(cgebak,CGEBAK) -#define LAPACK_zgebak LAPACK_GLOBAL(zgebak,ZGEBAK) -#define LAPACK_shseqr LAPACK_GLOBAL(shseqr,SHSEQR) -#define LAPACK_dhseqr LAPACK_GLOBAL(dhseqr,DHSEQR) -#define LAPACK_chseqr LAPACK_GLOBAL(chseqr,CHSEQR) -#define LAPACK_zhseqr LAPACK_GLOBAL(zhseqr,ZHSEQR) -#define LAPACK_shsein LAPACK_GLOBAL(shsein,SHSEIN) -#define LAPACK_dhsein LAPACK_GLOBAL(dhsein,DHSEIN) -#define LAPACK_chsein LAPACK_GLOBAL(chsein,CHSEIN) -#define LAPACK_zhsein LAPACK_GLOBAL(zhsein,ZHSEIN) -#define LAPACK_strevc LAPACK_GLOBAL(strevc,STREVC) -#define LAPACK_dtrevc LAPACK_GLOBAL(dtrevc,DTREVC) -#define LAPACK_ctrevc LAPACK_GLOBAL(ctrevc,CTREVC) -#define LAPACK_ztrevc LAPACK_GLOBAL(ztrevc,ZTREVC) -#define LAPACK_strsna LAPACK_GLOBAL(strsna,STRSNA) -#define LAPACK_dtrsna LAPACK_GLOBAL(dtrsna,DTRSNA) -#define LAPACK_ctrsna LAPACK_GLOBAL(ctrsna,CTRSNA) -#define LAPACK_ztrsna LAPACK_GLOBAL(ztrsna,ZTRSNA) -#define LAPACK_strexc LAPACK_GLOBAL(strexc,STREXC) -#define LAPACK_dtrexc LAPACK_GLOBAL(dtrexc,DTREXC) -#define LAPACK_ctrexc LAPACK_GLOBAL(ctrexc,CTREXC) -#define LAPACK_ztrexc LAPACK_GLOBAL(ztrexc,ZTREXC) -#define LAPACK_strsen LAPACK_GLOBAL(strsen,STRSEN) -#define LAPACK_dtrsen LAPACK_GLOBAL(dtrsen,DTRSEN) -#define LAPACK_ctrsen LAPACK_GLOBAL(ctrsen,CTRSEN) -#define LAPACK_ztrsen LAPACK_GLOBAL(ztrsen,ZTRSEN) -#define LAPACK_strsyl LAPACK_GLOBAL(strsyl,STRSYL) -#define LAPACK_dtrsyl LAPACK_GLOBAL(dtrsyl,DTRSYL) -#define LAPACK_ctrsyl LAPACK_GLOBAL(ctrsyl,CTRSYL) -#define LAPACK_ztrsyl LAPACK_GLOBAL(ztrsyl,ZTRSYL) -#define LAPACK_sgghrd LAPACK_GLOBAL(sgghrd,SGGHRD) -#define LAPACK_dgghrd LAPACK_GLOBAL(dgghrd,DGGHRD) -#define LAPACK_cgghrd LAPACK_GLOBAL(cgghrd,CGGHRD) -#define LAPACK_zgghrd LAPACK_GLOBAL(zgghrd,ZGGHRD) -#define LAPACK_sggbal LAPACK_GLOBAL(sggbal,SGGBAL) -#define LAPACK_dggbal LAPACK_GLOBAL(dggbal,DGGBAL) -#define LAPACK_cggbal LAPACK_GLOBAL(cggbal,CGGBAL) -#define LAPACK_zggbal LAPACK_GLOBAL(zggbal,ZGGBAL) -#define LAPACK_sggbak LAPACK_GLOBAL(sggbak,SGGBAK) -#define LAPACK_dggbak LAPACK_GLOBAL(dggbak,DGGBAK) -#define LAPACK_cggbak LAPACK_GLOBAL(cggbak,CGGBAK) -#define LAPACK_zggbak LAPACK_GLOBAL(zggbak,ZGGBAK) -#define LAPACK_shgeqz LAPACK_GLOBAL(shgeqz,SHGEQZ) -#define LAPACK_dhgeqz LAPACK_GLOBAL(dhgeqz,DHGEQZ) -#define LAPACK_chgeqz LAPACK_GLOBAL(chgeqz,CHGEQZ) -#define LAPACK_zhgeqz LAPACK_GLOBAL(zhgeqz,ZHGEQZ) -#define LAPACK_stgevc LAPACK_GLOBAL(stgevc,STGEVC) -#define LAPACK_dtgevc LAPACK_GLOBAL(dtgevc,DTGEVC) -#define LAPACK_ctgevc LAPACK_GLOBAL(ctgevc,CTGEVC) -#define LAPACK_ztgevc LAPACK_GLOBAL(ztgevc,ZTGEVC) -#define LAPACK_stgexc LAPACK_GLOBAL(stgexc,STGEXC) -#define LAPACK_dtgexc LAPACK_GLOBAL(dtgexc,DTGEXC) -#define LAPACK_ctgexc LAPACK_GLOBAL(ctgexc,CTGEXC) -#define LAPACK_ztgexc LAPACK_GLOBAL(ztgexc,ZTGEXC) -#define LAPACK_stgsen LAPACK_GLOBAL(stgsen,STGSEN) -#define LAPACK_dtgsen LAPACK_GLOBAL(dtgsen,DTGSEN) -#define LAPACK_ctgsen LAPACK_GLOBAL(ctgsen,CTGSEN) -#define LAPACK_ztgsen LAPACK_GLOBAL(ztgsen,ZTGSEN) -#define LAPACK_stgsyl LAPACK_GLOBAL(stgsyl,STGSYL) -#define LAPACK_dtgsyl LAPACK_GLOBAL(dtgsyl,DTGSYL) -#define LAPACK_ctgsyl LAPACK_GLOBAL(ctgsyl,CTGSYL) -#define LAPACK_ztgsyl LAPACK_GLOBAL(ztgsyl,ZTGSYL) -#define LAPACK_stgsna LAPACK_GLOBAL(stgsna,STGSNA) -#define LAPACK_dtgsna LAPACK_GLOBAL(dtgsna,DTGSNA) -#define LAPACK_ctgsna LAPACK_GLOBAL(ctgsna,CTGSNA) -#define LAPACK_ztgsna LAPACK_GLOBAL(ztgsna,ZTGSNA) -#define LAPACK_sggsvp LAPACK_GLOBAL(sggsvp,SGGSVP) -#define LAPACK_dggsvp LAPACK_GLOBAL(dggsvp,DGGSVP) -#define LAPACK_cggsvp LAPACK_GLOBAL(cggsvp,CGGSVP) -#define LAPACK_zggsvp LAPACK_GLOBAL(zggsvp,ZGGSVP) -#define LAPACK_stgsja LAPACK_GLOBAL(stgsja,STGSJA) -#define LAPACK_dtgsja LAPACK_GLOBAL(dtgsja,DTGSJA) -#define LAPACK_ctgsja LAPACK_GLOBAL(ctgsja,CTGSJA) -#define LAPACK_ztgsja LAPACK_GLOBAL(ztgsja,ZTGSJA) -#define LAPACK_sgels LAPACK_GLOBAL(sgels,SGELS) -#define LAPACK_dgels LAPACK_GLOBAL(dgels,DGELS) -#define LAPACK_cgels LAPACK_GLOBAL(cgels,CGELS) -#define LAPACK_zgels LAPACK_GLOBAL(zgels,ZGELS) -#define LAPACK_sgelsy LAPACK_GLOBAL(sgelsy,SGELSY) -#define LAPACK_dgelsy LAPACK_GLOBAL(dgelsy,DGELSY) -#define LAPACK_cgelsy LAPACK_GLOBAL(cgelsy,CGELSY) -#define LAPACK_zgelsy LAPACK_GLOBAL(zgelsy,ZGELSY) -#define LAPACK_sgelss LAPACK_GLOBAL(sgelss,SGELSS) -#define LAPACK_dgelss LAPACK_GLOBAL(dgelss,DGELSS) -#define LAPACK_cgelss LAPACK_GLOBAL(cgelss,CGELSS) -#define LAPACK_zgelss LAPACK_GLOBAL(zgelss,ZGELSS) -#define LAPACK_sgelsd LAPACK_GLOBAL(sgelsd,SGELSD) -#define LAPACK_dgelsd LAPACK_GLOBAL(dgelsd,DGELSD) -#define LAPACK_cgelsd LAPACK_GLOBAL(cgelsd,CGELSD) -#define LAPACK_zgelsd LAPACK_GLOBAL(zgelsd,ZGELSD) -#define LAPACK_sgglse LAPACK_GLOBAL(sgglse,SGGLSE) -#define LAPACK_dgglse LAPACK_GLOBAL(dgglse,DGGLSE) -#define LAPACK_cgglse LAPACK_GLOBAL(cgglse,CGGLSE) -#define LAPACK_zgglse LAPACK_GLOBAL(zgglse,ZGGLSE) -#define LAPACK_sggglm LAPACK_GLOBAL(sggglm,SGGGLM) -#define LAPACK_dggglm LAPACK_GLOBAL(dggglm,DGGGLM) -#define LAPACK_cggglm LAPACK_GLOBAL(cggglm,CGGGLM) -#define LAPACK_zggglm LAPACK_GLOBAL(zggglm,ZGGGLM) -#define LAPACK_ssyev LAPACK_GLOBAL(ssyev,SSYEV) -#define LAPACK_dsyev LAPACK_GLOBAL(dsyev,DSYEV) -#define LAPACK_cheev LAPACK_GLOBAL(cheev,CHEEV) -#define LAPACK_zheev LAPACK_GLOBAL(zheev,ZHEEV) -#define LAPACK_ssyevd LAPACK_GLOBAL(ssyevd,SSYEVD) -#define LAPACK_dsyevd LAPACK_GLOBAL(dsyevd,DSYEVD) -#define LAPACK_cheevd LAPACK_GLOBAL(cheevd,CHEEVD) -#define LAPACK_zheevd LAPACK_GLOBAL(zheevd,ZHEEVD) -#define LAPACK_ssyevx LAPACK_GLOBAL(ssyevx,SSYEVX) -#define LAPACK_dsyevx LAPACK_GLOBAL(dsyevx,DSYEVX) -#define LAPACK_cheevx LAPACK_GLOBAL(cheevx,CHEEVX) -#define LAPACK_zheevx LAPACK_GLOBAL(zheevx,ZHEEVX) -#define LAPACK_ssyevr LAPACK_GLOBAL(ssyevr,SSYEVR) -#define LAPACK_dsyevr LAPACK_GLOBAL(dsyevr,DSYEVR) -#define LAPACK_cheevr LAPACK_GLOBAL(cheevr,CHEEVR) -#define LAPACK_zheevr LAPACK_GLOBAL(zheevr,ZHEEVR) -#define LAPACK_sspev LAPACK_GLOBAL(sspev,SSPEV) -#define LAPACK_dspev LAPACK_GLOBAL(dspev,DSPEV) -#define LAPACK_chpev LAPACK_GLOBAL(chpev,CHPEV) -#define LAPACK_zhpev LAPACK_GLOBAL(zhpev,ZHPEV) -#define LAPACK_sspevd LAPACK_GLOBAL(sspevd,SSPEVD) -#define LAPACK_dspevd LAPACK_GLOBAL(dspevd,DSPEVD) -#define LAPACK_chpevd LAPACK_GLOBAL(chpevd,CHPEVD) -#define LAPACK_zhpevd LAPACK_GLOBAL(zhpevd,ZHPEVD) -#define LAPACK_sspevx LAPACK_GLOBAL(sspevx,SSPEVX) -#define LAPACK_dspevx LAPACK_GLOBAL(dspevx,DSPEVX) -#define LAPACK_chpevx LAPACK_GLOBAL(chpevx,CHPEVX) -#define LAPACK_zhpevx LAPACK_GLOBAL(zhpevx,ZHPEVX) -#define LAPACK_ssbev LAPACK_GLOBAL(ssbev,SSBEV) -#define LAPACK_dsbev LAPACK_GLOBAL(dsbev,DSBEV) -#define LAPACK_chbev LAPACK_GLOBAL(chbev,CHBEV) -#define LAPACK_zhbev LAPACK_GLOBAL(zhbev,ZHBEV) -#define LAPACK_ssbevd LAPACK_GLOBAL(ssbevd,SSBEVD) -#define LAPACK_dsbevd LAPACK_GLOBAL(dsbevd,DSBEVD) -#define LAPACK_chbevd LAPACK_GLOBAL(chbevd,CHBEVD) -#define LAPACK_zhbevd LAPACK_GLOBAL(zhbevd,ZHBEVD) -#define LAPACK_ssbevx LAPACK_GLOBAL(ssbevx,SSBEVX) -#define LAPACK_dsbevx LAPACK_GLOBAL(dsbevx,DSBEVX) -#define LAPACK_chbevx LAPACK_GLOBAL(chbevx,CHBEVX) -#define LAPACK_zhbevx LAPACK_GLOBAL(zhbevx,ZHBEVX) -#define LAPACK_sstev LAPACK_GLOBAL(sstev,SSTEV) -#define LAPACK_dstev LAPACK_GLOBAL(dstev,DSTEV) -#define LAPACK_sstevd LAPACK_GLOBAL(sstevd,SSTEVD) -#define LAPACK_dstevd LAPACK_GLOBAL(dstevd,DSTEVD) -#define LAPACK_sstevx LAPACK_GLOBAL(sstevx,SSTEVX) -#define LAPACK_dstevx LAPACK_GLOBAL(dstevx,DSTEVX) -#define LAPACK_sstevr LAPACK_GLOBAL(sstevr,SSTEVR) -#define LAPACK_dstevr LAPACK_GLOBAL(dstevr,DSTEVR) -#define LAPACK_sgees LAPACK_GLOBAL(sgees,SGEES) -#define LAPACK_dgees LAPACK_GLOBAL(dgees,DGEES) -#define LAPACK_cgees LAPACK_GLOBAL(cgees,CGEES) -#define LAPACK_zgees LAPACK_GLOBAL(zgees,ZGEES) -#define LAPACK_sgeesx LAPACK_GLOBAL(sgeesx,SGEESX) -#define LAPACK_dgeesx LAPACK_GLOBAL(dgeesx,DGEESX) -#define LAPACK_cgeesx LAPACK_GLOBAL(cgeesx,CGEESX) -#define LAPACK_zgeesx LAPACK_GLOBAL(zgeesx,ZGEESX) -#define LAPACK_sgeev LAPACK_GLOBAL(sgeev,SGEEV) -#define LAPACK_dgeev LAPACK_GLOBAL(dgeev,DGEEV) -#define LAPACK_cgeev LAPACK_GLOBAL(cgeev,CGEEV) -#define LAPACK_zgeev LAPACK_GLOBAL(zgeev,ZGEEV) -#define LAPACK_sgeevx LAPACK_GLOBAL(sgeevx,SGEEVX) -#define LAPACK_dgeevx LAPACK_GLOBAL(dgeevx,DGEEVX) -#define LAPACK_cgeevx LAPACK_GLOBAL(cgeevx,CGEEVX) -#define LAPACK_zgeevx LAPACK_GLOBAL(zgeevx,ZGEEVX) -#define LAPACK_sgesvd LAPACK_GLOBAL(sgesvd,SGESVD) -#define LAPACK_dgesvd LAPACK_GLOBAL(dgesvd,DGESVD) -#define LAPACK_cgesvd LAPACK_GLOBAL(cgesvd,CGESVD) -#define LAPACK_zgesvd LAPACK_GLOBAL(zgesvd,ZGESVD) -#define LAPACK_sgesdd LAPACK_GLOBAL(sgesdd,SGESDD) -#define LAPACK_dgesdd LAPACK_GLOBAL(dgesdd,DGESDD) -#define LAPACK_cgesdd LAPACK_GLOBAL(cgesdd,CGESDD) -#define LAPACK_zgesdd LAPACK_GLOBAL(zgesdd,ZGESDD) -#define LAPACK_dgejsv LAPACK_GLOBAL(dgejsv,DGEJSV) -#define LAPACK_sgejsv LAPACK_GLOBAL(sgejsv,SGEJSV) -#define LAPACK_dgesvj LAPACK_GLOBAL(dgesvj,DGESVJ) -#define LAPACK_sgesvj LAPACK_GLOBAL(sgesvj,SGESVJ) -#define LAPACK_sggsvd LAPACK_GLOBAL(sggsvd,SGGSVD) -#define LAPACK_dggsvd LAPACK_GLOBAL(dggsvd,DGGSVD) -#define LAPACK_cggsvd LAPACK_GLOBAL(cggsvd,CGGSVD) -#define LAPACK_zggsvd LAPACK_GLOBAL(zggsvd,ZGGSVD) -#define LAPACK_ssygv LAPACK_GLOBAL(ssygv,SSYGV) -#define LAPACK_dsygv LAPACK_GLOBAL(dsygv,DSYGV) -#define LAPACK_chegv LAPACK_GLOBAL(chegv,CHEGV) -#define LAPACK_zhegv LAPACK_GLOBAL(zhegv,ZHEGV) -#define LAPACK_ssygvd LAPACK_GLOBAL(ssygvd,SSYGVD) -#define LAPACK_dsygvd LAPACK_GLOBAL(dsygvd,DSYGVD) -#define LAPACK_chegvd LAPACK_GLOBAL(chegvd,CHEGVD) -#define LAPACK_zhegvd LAPACK_GLOBAL(zhegvd,ZHEGVD) -#define LAPACK_ssygvx LAPACK_GLOBAL(ssygvx,SSYGVX) -#define LAPACK_dsygvx LAPACK_GLOBAL(dsygvx,DSYGVX) -#define LAPACK_chegvx LAPACK_GLOBAL(chegvx,CHEGVX) -#define LAPACK_zhegvx LAPACK_GLOBAL(zhegvx,ZHEGVX) -#define LAPACK_sspgv LAPACK_GLOBAL(sspgv,SSPGV) -#define LAPACK_dspgv LAPACK_GLOBAL(dspgv,DSPGV) -#define LAPACK_chpgv LAPACK_GLOBAL(chpgv,CHPGV) -#define LAPACK_zhpgv LAPACK_GLOBAL(zhpgv,ZHPGV) -#define LAPACK_sspgvd LAPACK_GLOBAL(sspgvd,SSPGVD) -#define LAPACK_dspgvd LAPACK_GLOBAL(dspgvd,DSPGVD) -#define LAPACK_chpgvd LAPACK_GLOBAL(chpgvd,CHPGVD) -#define LAPACK_zhpgvd LAPACK_GLOBAL(zhpgvd,ZHPGVD) -#define LAPACK_sspgvx LAPACK_GLOBAL(sspgvx,SSPGVX) -#define LAPACK_dspgvx LAPACK_GLOBAL(dspgvx,DSPGVX) -#define LAPACK_chpgvx LAPACK_GLOBAL(chpgvx,CHPGVX) -#define LAPACK_zhpgvx LAPACK_GLOBAL(zhpgvx,ZHPGVX) -#define LAPACK_ssbgv LAPACK_GLOBAL(ssbgv,SSBGV) -#define LAPACK_dsbgv LAPACK_GLOBAL(dsbgv,DSBGV) -#define LAPACK_chbgv LAPACK_GLOBAL(chbgv,CHBGV) -#define LAPACK_zhbgv LAPACK_GLOBAL(zhbgv,ZHBGV) -#define LAPACK_ssbgvd LAPACK_GLOBAL(ssbgvd,SSBGVD) -#define LAPACK_dsbgvd LAPACK_GLOBAL(dsbgvd,DSBGVD) -#define LAPACK_chbgvd LAPACK_GLOBAL(chbgvd,CHBGVD) -#define LAPACK_zhbgvd LAPACK_GLOBAL(zhbgvd,ZHBGVD) -#define LAPACK_ssbgvx LAPACK_GLOBAL(ssbgvx,SSBGVX) -#define LAPACK_dsbgvx LAPACK_GLOBAL(dsbgvx,DSBGVX) -#define LAPACK_chbgvx LAPACK_GLOBAL(chbgvx,CHBGVX) -#define LAPACK_zhbgvx LAPACK_GLOBAL(zhbgvx,ZHBGVX) -#define LAPACK_sgges LAPACK_GLOBAL(sgges,SGGES) -#define LAPACK_dgges LAPACK_GLOBAL(dgges,DGGES) -#define LAPACK_cgges LAPACK_GLOBAL(cgges,CGGES) -#define LAPACK_zgges LAPACK_GLOBAL(zgges,ZGGES) -#define LAPACK_sggesx LAPACK_GLOBAL(sggesx,SGGESX) -#define LAPACK_dggesx LAPACK_GLOBAL(dggesx,DGGESX) -#define LAPACK_cggesx LAPACK_GLOBAL(cggesx,CGGESX) -#define LAPACK_zggesx LAPACK_GLOBAL(zggesx,ZGGESX) -#define LAPACK_sggev LAPACK_GLOBAL(sggev,SGGEV) -#define LAPACK_dggev LAPACK_GLOBAL(dggev,DGGEV) -#define LAPACK_cggev LAPACK_GLOBAL(cggev,CGGEV) -#define LAPACK_zggev LAPACK_GLOBAL(zggev,ZGGEV) -#define LAPACK_sggevx LAPACK_GLOBAL(sggevx,SGGEVX) -#define LAPACK_dggevx LAPACK_GLOBAL(dggevx,DGGEVX) -#define LAPACK_cggevx LAPACK_GLOBAL(cggevx,CGGEVX) -#define LAPACK_zggevx LAPACK_GLOBAL(zggevx,ZGGEVX) -#define LAPACK_dsfrk LAPACK_GLOBAL(dsfrk,DSFRK) -#define LAPACK_ssfrk LAPACK_GLOBAL(ssfrk,SSFRK) -#define LAPACK_zhfrk LAPACK_GLOBAL(zhfrk,ZHFRK) -#define LAPACK_chfrk LAPACK_GLOBAL(chfrk,CHFRK) -#define LAPACK_dtfsm LAPACK_GLOBAL(dtfsm,DTFSM) -#define LAPACK_stfsm LAPACK_GLOBAL(stfsm,STFSM) -#define LAPACK_ztfsm LAPACK_GLOBAL(ztfsm,ZTFSM) -#define LAPACK_ctfsm LAPACK_GLOBAL(ctfsm,CTFSM) -#define LAPACK_dtfttp LAPACK_GLOBAL(dtfttp,DTFTTP) -#define LAPACK_stfttp LAPACK_GLOBAL(stfttp,STFTTP) -#define LAPACK_ztfttp LAPACK_GLOBAL(ztfttp,ZTFTTP) -#define LAPACK_ctfttp LAPACK_GLOBAL(ctfttp,CTFTTP) -#define LAPACK_dtfttr LAPACK_GLOBAL(dtfttr,DTFTTR) -#define LAPACK_stfttr LAPACK_GLOBAL(stfttr,STFTTR) -#define LAPACK_ztfttr LAPACK_GLOBAL(ztfttr,ZTFTTR) -#define LAPACK_ctfttr LAPACK_GLOBAL(ctfttr,CTFTTR) -#define LAPACK_dtpttf LAPACK_GLOBAL(dtpttf,DTPTTF) -#define LAPACK_stpttf LAPACK_GLOBAL(stpttf,STPTTF) -#define LAPACK_ztpttf LAPACK_GLOBAL(ztpttf,ZTPTTF) -#define LAPACK_ctpttf LAPACK_GLOBAL(ctpttf,CTPTTF) -#define LAPACK_dtpttr LAPACK_GLOBAL(dtpttr,DTPTTR) -#define LAPACK_stpttr LAPACK_GLOBAL(stpttr,STPTTR) -#define LAPACK_ztpttr LAPACK_GLOBAL(ztpttr,ZTPTTR) -#define LAPACK_ctpttr LAPACK_GLOBAL(ctpttr,CTPTTR) -#define LAPACK_dtrttf LAPACK_GLOBAL(dtrttf,DTRTTF) -#define LAPACK_strttf LAPACK_GLOBAL(strttf,STRTTF) -#define LAPACK_ztrttf LAPACK_GLOBAL(ztrttf,ZTRTTF) -#define LAPACK_ctrttf LAPACK_GLOBAL(ctrttf,CTRTTF) -#define LAPACK_dtrttp LAPACK_GLOBAL(dtrttp,DTRTTP) -#define LAPACK_strttp LAPACK_GLOBAL(strttp,STRTTP) -#define LAPACK_ztrttp LAPACK_GLOBAL(ztrttp,ZTRTTP) -#define LAPACK_ctrttp LAPACK_GLOBAL(ctrttp,CTRTTP) -#define LAPACK_sgeqrfp LAPACK_GLOBAL(sgeqrfp,SGEQRFP) -#define LAPACK_dgeqrfp LAPACK_GLOBAL(dgeqrfp,DGEQRFP) -#define LAPACK_cgeqrfp LAPACK_GLOBAL(cgeqrfp,CGEQRFP) -#define LAPACK_zgeqrfp LAPACK_GLOBAL(zgeqrfp,ZGEQRFP) -#define LAPACK_clacgv LAPACK_GLOBAL(clacgv,CLACGV) -#define LAPACK_zlacgv LAPACK_GLOBAL(zlacgv,ZLACGV) -#define LAPACK_slarnv LAPACK_GLOBAL(slarnv,SLARNV) -#define LAPACK_dlarnv LAPACK_GLOBAL(dlarnv,DLARNV) -#define LAPACK_clarnv LAPACK_GLOBAL(clarnv,CLARNV) -#define LAPACK_zlarnv LAPACK_GLOBAL(zlarnv,ZLARNV) -#define LAPACK_sgeqr2 LAPACK_GLOBAL(sgeqr2,SGEQR2) -#define LAPACK_dgeqr2 LAPACK_GLOBAL(dgeqr2,DGEQR2) -#define LAPACK_cgeqr2 LAPACK_GLOBAL(cgeqr2,CGEQR2) -#define LAPACK_zgeqr2 LAPACK_GLOBAL(zgeqr2,ZGEQR2) -#define LAPACK_slacpy LAPACK_GLOBAL(slacpy,SLACPY) -#define LAPACK_dlacpy LAPACK_GLOBAL(dlacpy,DLACPY) -#define LAPACK_clacpy LAPACK_GLOBAL(clacpy,CLACPY) -#define LAPACK_zlacpy LAPACK_GLOBAL(zlacpy,ZLACPY) -#define LAPACK_sgetf2 LAPACK_GLOBAL(sgetf2,SGETF2) -#define LAPACK_dgetf2 LAPACK_GLOBAL(dgetf2,DGETF2) -#define LAPACK_cgetf2 LAPACK_GLOBAL(cgetf2,CGETF2) -#define LAPACK_zgetf2 LAPACK_GLOBAL(zgetf2,ZGETF2) -#define LAPACK_slaswp LAPACK_GLOBAL(slaswp,SLASWP) -#define LAPACK_dlaswp LAPACK_GLOBAL(dlaswp,DLASWP) -#define LAPACK_claswp LAPACK_GLOBAL(claswp,CLASWP) -#define LAPACK_zlaswp LAPACK_GLOBAL(zlaswp,ZLASWP) -#define LAPACK_slange LAPACK_GLOBAL(slange,SLANGE) -#define LAPACK_dlange LAPACK_GLOBAL(dlange,DLANGE) -#define LAPACK_clange LAPACK_GLOBAL(clange,CLANGE) -#define LAPACK_zlange LAPACK_GLOBAL(zlange,ZLANGE) -#define LAPACK_clanhe LAPACK_GLOBAL(clanhe,CLANHE) -#define LAPACK_zlanhe LAPACK_GLOBAL(zlanhe,ZLANHE) -#define LAPACK_slansy LAPACK_GLOBAL(slansy,SLANSY) -#define LAPACK_dlansy LAPACK_GLOBAL(dlansy,DLANSY) -#define LAPACK_clansy LAPACK_GLOBAL(clansy,CLANSY) -#define LAPACK_zlansy LAPACK_GLOBAL(zlansy,ZLANSY) -#define LAPACK_slantr LAPACK_GLOBAL(slantr,SLANTR) -#define LAPACK_dlantr LAPACK_GLOBAL(dlantr,DLANTR) -#define LAPACK_clantr LAPACK_GLOBAL(clantr,CLANTR) -#define LAPACK_zlantr LAPACK_GLOBAL(zlantr,ZLANTR) -#define LAPACK_slamch LAPACK_GLOBAL(slamch,SLAMCH) -#define LAPACK_dlamch LAPACK_GLOBAL(dlamch,DLAMCH) -#define LAPACK_sgelq2 LAPACK_GLOBAL(sgelq2,SGELQ2) -#define LAPACK_dgelq2 LAPACK_GLOBAL(dgelq2,DGELQ2) -#define LAPACK_cgelq2 LAPACK_GLOBAL(cgelq2,CGELQ2) -#define LAPACK_zgelq2 LAPACK_GLOBAL(zgelq2,ZGELQ2) -#define LAPACK_slarfb LAPACK_GLOBAL(slarfb,SLARFB) -#define LAPACK_dlarfb LAPACK_GLOBAL(dlarfb,DLARFB) -#define LAPACK_clarfb LAPACK_GLOBAL(clarfb,CLARFB) -#define LAPACK_zlarfb LAPACK_GLOBAL(zlarfb,ZLARFB) -#define LAPACK_slarfg LAPACK_GLOBAL(slarfg,SLARFG) -#define LAPACK_dlarfg LAPACK_GLOBAL(dlarfg,DLARFG) -#define LAPACK_clarfg LAPACK_GLOBAL(clarfg,CLARFG) -#define LAPACK_zlarfg LAPACK_GLOBAL(zlarfg,ZLARFG) -#define LAPACK_slarft LAPACK_GLOBAL(slarft,SLARFT) -#define LAPACK_dlarft LAPACK_GLOBAL(dlarft,DLARFT) -#define LAPACK_clarft LAPACK_GLOBAL(clarft,CLARFT) -#define LAPACK_zlarft LAPACK_GLOBAL(zlarft,ZLARFT) -#define LAPACK_slarfx LAPACK_GLOBAL(slarfx,SLARFX) -#define LAPACK_dlarfx LAPACK_GLOBAL(dlarfx,DLARFX) -#define LAPACK_clarfx LAPACK_GLOBAL(clarfx,CLARFX) -#define LAPACK_zlarfx LAPACK_GLOBAL(zlarfx,ZLARFX) -#define LAPACK_slatms LAPACK_GLOBAL(slatms,SLATMS) -#define LAPACK_dlatms LAPACK_GLOBAL(dlatms,DLATMS) -#define LAPACK_clatms LAPACK_GLOBAL(clatms,CLATMS) -#define LAPACK_zlatms LAPACK_GLOBAL(zlatms,ZLATMS) -#define LAPACK_slag2d LAPACK_GLOBAL(slag2d,SLAG2D) -#define LAPACK_dlag2s LAPACK_GLOBAL(dlag2s,DLAG2S) -#define LAPACK_clag2z LAPACK_GLOBAL(clag2z,CLAG2Z) -#define LAPACK_zlag2c LAPACK_GLOBAL(zlag2c,ZLAG2C) -#define LAPACK_slauum LAPACK_GLOBAL(slauum,SLAUUM) -#define LAPACK_dlauum LAPACK_GLOBAL(dlauum,DLAUUM) -#define LAPACK_clauum LAPACK_GLOBAL(clauum,CLAUUM) -#define LAPACK_zlauum LAPACK_GLOBAL(zlauum,ZLAUUM) -#define LAPACK_slagge LAPACK_GLOBAL(slagge,SLAGGE) -#define LAPACK_dlagge LAPACK_GLOBAL(dlagge,DLAGGE) -#define LAPACK_clagge LAPACK_GLOBAL(clagge,CLAGGE) -#define LAPACK_zlagge LAPACK_GLOBAL(zlagge,ZLAGGE) -#define LAPACK_slaset LAPACK_GLOBAL(slaset,SLASET) -#define LAPACK_dlaset LAPACK_GLOBAL(dlaset,DLASET) -#define LAPACK_claset LAPACK_GLOBAL(claset,CLASET) -#define LAPACK_zlaset LAPACK_GLOBAL(zlaset,ZLASET) -#define LAPACK_slasrt LAPACK_GLOBAL(slasrt,SLASRT) -#define LAPACK_dlasrt LAPACK_GLOBAL(dlasrt,DLASRT) -#define LAPACK_slagsy LAPACK_GLOBAL(slagsy,SLAGSY) -#define LAPACK_dlagsy LAPACK_GLOBAL(dlagsy,DLAGSY) -#define LAPACK_clagsy LAPACK_GLOBAL(clagsy,CLAGSY) -#define LAPACK_zlagsy LAPACK_GLOBAL(zlagsy,ZLAGSY) -#define LAPACK_claghe LAPACK_GLOBAL(claghe,CLAGHE) -#define LAPACK_zlaghe LAPACK_GLOBAL(zlaghe,ZLAGHE) -#define LAPACK_slapmr LAPACK_GLOBAL(slapmr,SLAPMR) -#define LAPACK_dlapmr LAPACK_GLOBAL(dlapmr,DLAPMR) -#define LAPACK_clapmr LAPACK_GLOBAL(clapmr,CLAPMR) -#define LAPACK_zlapmr LAPACK_GLOBAL(zlapmr,ZLAPMR) -#define LAPACK_slapy2 LAPACK_GLOBAL(slapy2,SLAPY2) -#define LAPACK_dlapy2 LAPACK_GLOBAL(dlapy2,DLAPY2) -#define LAPACK_slapy3 LAPACK_GLOBAL(slapy3,SLAPY3) -#define LAPACK_dlapy3 LAPACK_GLOBAL(dlapy3,DLAPY3) -#define LAPACK_slartgp LAPACK_GLOBAL(slartgp,SLARTGP) -#define LAPACK_dlartgp LAPACK_GLOBAL(dlartgp,DLARTGP) -#define LAPACK_slartgs LAPACK_GLOBAL(slartgs,SLARTGS) -#define LAPACK_dlartgs LAPACK_GLOBAL(dlartgs,DLARTGS) -// LAPACK 3.3.0 -#define LAPACK_cbbcsd LAPACK_GLOBAL(cbbcsd,CBBCSD) -#define LAPACK_cheswapr LAPACK_GLOBAL(cheswapr,CHESWAPR) -#define LAPACK_chetri2 LAPACK_GLOBAL(chetri2,CHETRI2) -#define LAPACK_chetri2x LAPACK_GLOBAL(chetri2x,CHETRI2X) -#define LAPACK_chetrs2 LAPACK_GLOBAL(chetrs2,CHETRS2) -#define LAPACK_csyconv LAPACK_GLOBAL(csyconv,CSYCONV) -#define LAPACK_csyswapr LAPACK_GLOBAL(csyswapr,CSYSWAPR) -#define LAPACK_csytri2 LAPACK_GLOBAL(csytri2,CSYTRI2) -#define LAPACK_csytri2x LAPACK_GLOBAL(csytri2x,CSYTRI2X) -#define LAPACK_csytrs2 LAPACK_GLOBAL(csytrs2,CSYTRS2) -#define LAPACK_cunbdb LAPACK_GLOBAL(cunbdb,CUNBDB) -#define LAPACK_cuncsd LAPACK_GLOBAL(cuncsd,CUNCSD) -#define LAPACK_dbbcsd LAPACK_GLOBAL(dbbcsd,DBBCSD) -#define LAPACK_dorbdb LAPACK_GLOBAL(dorbdb,DORBDB) -#define LAPACK_dorcsd LAPACK_GLOBAL(dorcsd,DORCSD) -#define LAPACK_dsyconv LAPACK_GLOBAL(dsyconv,DSYCONV) -#define LAPACK_dsyswapr LAPACK_GLOBAL(dsyswapr,DSYSWAPR) -#define LAPACK_dsytri2 LAPACK_GLOBAL(dsytri2,DSYTRI2) -#define LAPACK_dsytri2x LAPACK_GLOBAL(dsytri2x,DSYTRI2X) -#define LAPACK_dsytrs2 LAPACK_GLOBAL(dsytrs2,DSYTRS2) -#define LAPACK_sbbcsd LAPACK_GLOBAL(sbbcsd,SBBCSD) -#define LAPACK_sorbdb LAPACK_GLOBAL(sorbdb,SORBDB) -#define LAPACK_sorcsd LAPACK_GLOBAL(sorcsd,SORCSD) -#define LAPACK_ssyconv LAPACK_GLOBAL(ssyconv,SSYCONV) -#define LAPACK_ssyswapr LAPACK_GLOBAL(ssyswapr,SSYSWAPR) -#define LAPACK_ssytri2 LAPACK_GLOBAL(ssytri2,SSYTRI2) -#define LAPACK_ssytri2x LAPACK_GLOBAL(ssytri2x,SSYTRI2X) -#define LAPACK_ssytrs2 LAPACK_GLOBAL(ssytrs2,SSYTRS2) -#define LAPACK_zbbcsd LAPACK_GLOBAL(zbbcsd,ZBBCSD) -#define LAPACK_zheswapr LAPACK_GLOBAL(zheswapr,ZHESWAPR) -#define LAPACK_zhetri2 LAPACK_GLOBAL(zhetri2,ZHETRI2) -#define LAPACK_zhetri2x LAPACK_GLOBAL(zhetri2x,ZHETRI2X) -#define LAPACK_zhetrs2 LAPACK_GLOBAL(zhetrs2,ZHETRS2) -#define LAPACK_zsyconv LAPACK_GLOBAL(zsyconv,ZSYCONV) -#define LAPACK_zsyswapr LAPACK_GLOBAL(zsyswapr,ZSYSWAPR) -#define LAPACK_zsytri2 LAPACK_GLOBAL(zsytri2,ZSYTRI2) -#define LAPACK_zsytri2x LAPACK_GLOBAL(zsytri2x,ZSYTRI2X) -#define LAPACK_zsytrs2 LAPACK_GLOBAL(zsytrs2,ZSYTRS2) -#define LAPACK_zunbdb LAPACK_GLOBAL(zunbdb,ZUNBDB) -#define LAPACK_zuncsd LAPACK_GLOBAL(zuncsd,ZUNCSD) -// LAPACK 3.4.0 -#define LAPACK_sgemqrt LAPACK_GLOBAL(sgemqrt,SGEMQRT) -#define LAPACK_dgemqrt LAPACK_GLOBAL(dgemqrt,DGEMQRT) -#define LAPACK_cgemqrt LAPACK_GLOBAL(cgemqrt,CGEMQRT) -#define LAPACK_zgemqrt LAPACK_GLOBAL(zgemqrt,ZGEMQRT) -#define LAPACK_sgeqrt LAPACK_GLOBAL(sgeqrt,SGEQRT) -#define LAPACK_dgeqrt LAPACK_GLOBAL(dgeqrt,DGEQRT) -#define LAPACK_cgeqrt LAPACK_GLOBAL(cgeqrt,CGEQRT) -#define LAPACK_zgeqrt LAPACK_GLOBAL(zgeqrt,ZGEQRT) -#define LAPACK_sgeqrt2 LAPACK_GLOBAL(sgeqrt2,SGEQRT2) -#define LAPACK_dgeqrt2 LAPACK_GLOBAL(dgeqrt2,DGEQRT2) -#define LAPACK_cgeqrt2 LAPACK_GLOBAL(cgeqrt2,CGEQRT2) -#define LAPACK_zgeqrt2 LAPACK_GLOBAL(zgeqrt2,ZGEQRT2) -#define LAPACK_sgeqrt3 LAPACK_GLOBAL(sgeqrt3,SGEQRT3) -#define LAPACK_dgeqrt3 LAPACK_GLOBAL(dgeqrt3,DGEQRT3) -#define LAPACK_cgeqrt3 LAPACK_GLOBAL(cgeqrt3,CGEQRT3) -#define LAPACK_zgeqrt3 LAPACK_GLOBAL(zgeqrt3,ZGEQRT3) -#define LAPACK_stpmqrt LAPACK_GLOBAL(stpmqrt,STPMQRT) -#define LAPACK_dtpmqrt LAPACK_GLOBAL(dtpmqrt,DTPMQRT) -#define LAPACK_ctpmqrt LAPACK_GLOBAL(ctpmqrt,CTPMQRT) -#define LAPACK_ztpmqrt LAPACK_GLOBAL(ztpmqrt,ZTPMQRT) -#define LAPACK_dtpqrt LAPACK_GLOBAL(dtpqrt,DTPQRT) -#define LAPACK_ctpqrt LAPACK_GLOBAL(ctpqrt,CTPQRT) -#define LAPACK_ztpqrt LAPACK_GLOBAL(ztpqrt,ZTPQRT) -#define LAPACK_stpqrt2 LAPACK_GLOBAL(stpqrt2,STPQRT2) -#define LAPACK_dtpqrt2 LAPACK_GLOBAL(dtpqrt2,DTPQRT2) -#define LAPACK_ctpqrt2 LAPACK_GLOBAL(ctpqrt2,CTPQRT2) -#define LAPACK_ztpqrt2 LAPACK_GLOBAL(ztpqrt2,ZTPQRT2) -#define LAPACK_stprfb LAPACK_GLOBAL(stprfb,STPRFB) -#define LAPACK_dtprfb LAPACK_GLOBAL(dtprfb,DTPRFB) -#define LAPACK_ctprfb LAPACK_GLOBAL(ctprfb,CTPRFB) -#define LAPACK_ztprfb LAPACK_GLOBAL(ztprfb,ZTPRFB) -// LAPACK 3.X.X -#define LAPACK_csyr LAPACK_GLOBAL(csyr,CSYR) -#define LAPACK_zsyr LAPACK_GLOBAL(zsyr,ZSYR) - - -void LAPACK_sgetrf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_dgetrf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_cgetrf( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* ipiv, lapack_int *info ); -void LAPACK_zgetrf( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* ipiv, lapack_int *info ); -void LAPACK_sgbtrf( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, float* ab, lapack_int* ldab, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_dgbtrf( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, double* ab, lapack_int* ldab, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_cgbtrf( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_complex_float* ab, lapack_int* ldab, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_zgbtrf( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_complex_double* ab, lapack_int* ldab, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_sgttrf( lapack_int* n, float* dl, float* d, float* du, float* du2, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_dgttrf( lapack_int* n, double* dl, double* d, double* du, - double* du2, lapack_int* ipiv, lapack_int *info ); -void LAPACK_cgttrf( lapack_int* n, lapack_complex_float* dl, - lapack_complex_float* d, lapack_complex_float* du, - lapack_complex_float* du2, lapack_int* ipiv, - lapack_int *info ); -void LAPACK_zgttrf( lapack_int* n, lapack_complex_double* dl, - lapack_complex_double* d, lapack_complex_double* du, - lapack_complex_double* du2, lapack_int* ipiv, - lapack_int *info ); -void LAPACK_spotrf( char* uplo, lapack_int* n, float* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_dpotrf( char* uplo, lapack_int* n, double* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_cpotrf( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_zpotrf( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_dpstrf( char* uplo, lapack_int* n, double* a, lapack_int* lda, - lapack_int* piv, lapack_int* rank, double* tol, - double* work, lapack_int *info ); -void LAPACK_spstrf( char* uplo, lapack_int* n, float* a, lapack_int* lda, - lapack_int* piv, lapack_int* rank, float* tol, float* work, - lapack_int *info ); -void LAPACK_zpstrf( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* piv, lapack_int* rank, - double* tol, double* work, lapack_int *info ); -void LAPACK_cpstrf( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* piv, lapack_int* rank, - float* tol, float* work, lapack_int *info ); -void LAPACK_dpftrf( char* transr, char* uplo, lapack_int* n, double* a, - lapack_int *info ); -void LAPACK_spftrf( char* transr, char* uplo, lapack_int* n, float* a, - lapack_int *info ); -void LAPACK_zpftrf( char* transr, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int *info ); -void LAPACK_cpftrf( char* transr, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int *info ); -void LAPACK_spptrf( char* uplo, lapack_int* n, float* ap, lapack_int *info ); -void LAPACK_dpptrf( char* uplo, lapack_int* n, double* ap, lapack_int *info ); -void LAPACK_cpptrf( char* uplo, lapack_int* n, lapack_complex_float* ap, - lapack_int *info ); -void LAPACK_zpptrf( char* uplo, lapack_int* n, lapack_complex_double* ap, - lapack_int *info ); -void LAPACK_spbtrf( char* uplo, lapack_int* n, lapack_int* kd, float* ab, - lapack_int* ldab, lapack_int *info ); -void LAPACK_dpbtrf( char* uplo, lapack_int* n, lapack_int* kd, double* ab, - lapack_int* ldab, lapack_int *info ); -void LAPACK_cpbtrf( char* uplo, lapack_int* n, lapack_int* kd, - lapack_complex_float* ab, lapack_int* ldab, - lapack_int *info ); -void LAPACK_zpbtrf( char* uplo, lapack_int* n, lapack_int* kd, - lapack_complex_double* ab, lapack_int* ldab, - lapack_int *info ); -void LAPACK_spttrf( lapack_int* n, float* d, float* e, lapack_int *info ); -void LAPACK_dpttrf( lapack_int* n, double* d, double* e, lapack_int *info ); -void LAPACK_cpttrf( lapack_int* n, float* d, lapack_complex_float* e, - lapack_int *info ); -void LAPACK_zpttrf( lapack_int* n, double* d, lapack_complex_double* e, - lapack_int *info ); -void LAPACK_ssytrf( char* uplo, lapack_int* n, float* a, lapack_int* lda, - lapack_int* ipiv, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dsytrf( char* uplo, lapack_int* n, double* a, lapack_int* lda, - lapack_int* ipiv, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_csytrf( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* ipiv, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zsytrf( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* ipiv, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_chetrf( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* ipiv, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zhetrf( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* ipiv, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_ssptrf( char* uplo, lapack_int* n, float* ap, lapack_int* ipiv, - lapack_int *info ); -void LAPACK_dsptrf( char* uplo, lapack_int* n, double* ap, lapack_int* ipiv, - lapack_int *info ); -void LAPACK_csptrf( char* uplo, lapack_int* n, lapack_complex_float* ap, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_zsptrf( char* uplo, lapack_int* n, lapack_complex_double* ap, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_chptrf( char* uplo, lapack_int* n, lapack_complex_float* ap, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_zhptrf( char* uplo, lapack_int* n, lapack_complex_double* ap, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_sgetrs( char* trans, lapack_int* n, lapack_int* nrhs, - const float* a, lapack_int* lda, const lapack_int* ipiv, - float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_dgetrs( char* trans, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, const lapack_int* ipiv, - double* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_cgetrs( char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_zgetrs( char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_sgbtrs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, const float* ab, lapack_int* ldab, - const lapack_int* ipiv, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dgbtrs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, const double* ab, lapack_int* ldab, - const lapack_int* ipiv, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_cgbtrs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, const lapack_complex_float* ab, - lapack_int* ldab, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zgbtrs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, const lapack_complex_double* ab, - lapack_int* ldab, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_sgttrs( char* trans, lapack_int* n, lapack_int* nrhs, - const float* dl, const float* d, const float* du, - const float* du2, const lapack_int* ipiv, float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_dgttrs( char* trans, lapack_int* n, lapack_int* nrhs, - const double* dl, const double* d, const double* du, - const double* du2, const lapack_int* ipiv, double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_cgttrs( char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* du2, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zgttrs( char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* du2, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_spotrs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* a, - lapack_int* lda, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dpotrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_cpotrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zpotrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dpftrs( char* transr, char* uplo, lapack_int* n, lapack_int* nrhs, - const double* a, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_spftrs( char* transr, char* uplo, lapack_int* n, lapack_int* nrhs, - const float* a, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zpftrs( char* transr, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_cpftrs( char* transr, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_spptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const float* ap, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dpptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* ap, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_cpptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* ap, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_zpptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* ap, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_spbtrs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - const float* ab, lapack_int* ldab, float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_dpbtrs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - const double* ab, lapack_int* ldab, double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_cpbtrs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - const lapack_complex_float* ab, lapack_int* ldab, - lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zpbtrs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - const lapack_complex_double* ab, lapack_int* ldab, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_spttrs( lapack_int* n, lapack_int* nrhs, const float* d, - const float* e, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dpttrs( lapack_int* n, lapack_int* nrhs, const double* d, - const double* e, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_cpttrs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* d, - const lapack_complex_float* e, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_zpttrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* d, const lapack_complex_double* e, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_ssytrs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* a, - lapack_int* lda, const lapack_int* ipiv, float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_dsytrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, const lapack_int* ipiv, - double* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_csytrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_zsytrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_chetrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_int* ipiv, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_zhetrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_ssptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const float* ap, const lapack_int* ipiv, float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_dsptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* ap, const lapack_int* ipiv, double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_csptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* ap, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zsptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* ap, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_chptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* ap, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zhptrs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* ap, const lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_strtrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const float* a, lapack_int* lda, float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_dtrtrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const double* a, lapack_int* lda, - double* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_ctrtrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_ztrtrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_stptrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const float* ap, float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_dtptrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const double* ap, double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_ctptrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const lapack_complex_float* ap, - lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_ztptrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const lapack_complex_double* ap, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_stbtrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* kd, lapack_int* nrhs, const float* ab, - lapack_int* ldab, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dtbtrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* kd, lapack_int* nrhs, const double* ab, - lapack_int* ldab, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_ctbtrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* kd, lapack_int* nrhs, - const lapack_complex_float* ab, lapack_int* ldab, - lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_ztbtrs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* kd, lapack_int* nrhs, - const lapack_complex_double* ab, lapack_int* ldab, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_sgecon( char* norm, lapack_int* n, const float* a, lapack_int* lda, - float* anorm, float* rcond, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgecon( char* norm, lapack_int* n, const double* a, lapack_int* lda, - double* anorm, double* rcond, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_cgecon( char* norm, lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, float* anorm, float* rcond, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zgecon( char* norm, lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, double* anorm, double* rcond, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sgbcon( char* norm, lapack_int* n, lapack_int* kl, lapack_int* ku, - const float* ab, lapack_int* ldab, const lapack_int* ipiv, - float* anorm, float* rcond, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgbcon( char* norm, lapack_int* n, lapack_int* kl, lapack_int* ku, - const double* ab, lapack_int* ldab, const lapack_int* ipiv, - double* anorm, double* rcond, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_cgbcon( char* norm, lapack_int* n, lapack_int* kl, lapack_int* ku, - const lapack_complex_float* ab, lapack_int* ldab, - const lapack_int* ipiv, float* anorm, float* rcond, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zgbcon( char* norm, lapack_int* n, lapack_int* kl, lapack_int* ku, - const lapack_complex_double* ab, lapack_int* ldab, - const lapack_int* ipiv, double* anorm, double* rcond, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sgtcon( char* norm, lapack_int* n, const float* dl, const float* d, - const float* du, const float* du2, const lapack_int* ipiv, - float* anorm, float* rcond, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgtcon( char* norm, lapack_int* n, const double* dl, - const double* d, const double* du, const double* du2, - const lapack_int* ipiv, double* anorm, double* rcond, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_cgtcon( char* norm, lapack_int* n, const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* du2, const lapack_int* ipiv, - float* anorm, float* rcond, lapack_complex_float* work, - lapack_int *info ); -void LAPACK_zgtcon( char* norm, lapack_int* n, const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* du2, const lapack_int* ipiv, - double* anorm, double* rcond, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_spocon( char* uplo, lapack_int* n, const float* a, lapack_int* lda, - float* anorm, float* rcond, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dpocon( char* uplo, lapack_int* n, const double* a, lapack_int* lda, - double* anorm, double* rcond, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_cpocon( char* uplo, lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, float* anorm, float* rcond, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zpocon( char* uplo, lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, double* anorm, double* rcond, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sppcon( char* uplo, lapack_int* n, const float* ap, float* anorm, - float* rcond, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dppcon( char* uplo, lapack_int* n, const double* ap, double* anorm, - double* rcond, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_cppcon( char* uplo, lapack_int* n, const lapack_complex_float* ap, - float* anorm, float* rcond, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zppcon( char* uplo, lapack_int* n, const lapack_complex_double* ap, - double* anorm, double* rcond, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_spbcon( char* uplo, lapack_int* n, lapack_int* kd, const float* ab, - lapack_int* ldab, float* anorm, float* rcond, float* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dpbcon( char* uplo, lapack_int* n, lapack_int* kd, const double* ab, - lapack_int* ldab, double* anorm, double* rcond, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_cpbcon( char* uplo, lapack_int* n, lapack_int* kd, - const lapack_complex_float* ab, lapack_int* ldab, - float* anorm, float* rcond, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zpbcon( char* uplo, lapack_int* n, lapack_int* kd, - const lapack_complex_double* ab, lapack_int* ldab, - double* anorm, double* rcond, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_sptcon( lapack_int* n, const float* d, const float* e, float* anorm, - float* rcond, float* work, lapack_int *info ); -void LAPACK_dptcon( lapack_int* n, const double* d, const double* e, - double* anorm, double* rcond, double* work, - lapack_int *info ); -void LAPACK_cptcon( lapack_int* n, const float* d, - const lapack_complex_float* e, float* anorm, float* rcond, - float* work, lapack_int *info ); -void LAPACK_zptcon( lapack_int* n, const double* d, - const lapack_complex_double* e, double* anorm, - double* rcond, double* work, lapack_int *info ); -void LAPACK_ssycon( char* uplo, lapack_int* n, const float* a, lapack_int* lda, - const lapack_int* ipiv, float* anorm, float* rcond, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_dsycon( char* uplo, lapack_int* n, const double* a, lapack_int* lda, - const lapack_int* ipiv, double* anorm, double* rcond, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_csycon( char* uplo, lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, const lapack_int* ipiv, float* anorm, - float* rcond, lapack_complex_float* work, - lapack_int *info ); -void LAPACK_zsycon( char* uplo, lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, const lapack_int* ipiv, double* anorm, - double* rcond, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_checon( char* uplo, lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, const lapack_int* ipiv, float* anorm, - float* rcond, lapack_complex_float* work, - lapack_int *info ); -void LAPACK_zhecon( char* uplo, lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, const lapack_int* ipiv, double* anorm, - double* rcond, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_sspcon( char* uplo, lapack_int* n, const float* ap, - const lapack_int* ipiv, float* anorm, float* rcond, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_dspcon( char* uplo, lapack_int* n, const double* ap, - const lapack_int* ipiv, double* anorm, double* rcond, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_cspcon( char* uplo, lapack_int* n, const lapack_complex_float* ap, - const lapack_int* ipiv, float* anorm, float* rcond, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zspcon( char* uplo, lapack_int* n, const lapack_complex_double* ap, - const lapack_int* ipiv, double* anorm, double* rcond, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_chpcon( char* uplo, lapack_int* n, const lapack_complex_float* ap, - const lapack_int* ipiv, float* anorm, float* rcond, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zhpcon( char* uplo, lapack_int* n, const lapack_complex_double* ap, - const lapack_int* ipiv, double* anorm, double* rcond, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_strcon( char* norm, char* uplo, char* diag, lapack_int* n, - const float* a, lapack_int* lda, float* rcond, float* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dtrcon( char* norm, char* uplo, char* diag, lapack_int* n, - const double* a, lapack_int* lda, double* rcond, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_ctrcon( char* norm, char* uplo, char* diag, lapack_int* n, - const lapack_complex_float* a, lapack_int* lda, - float* rcond, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_ztrcon( char* norm, char* uplo, char* diag, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, - double* rcond, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_stpcon( char* norm, char* uplo, char* diag, lapack_int* n, - const float* ap, float* rcond, float* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dtpcon( char* norm, char* uplo, char* diag, lapack_int* n, - const double* ap, double* rcond, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_ctpcon( char* norm, char* uplo, char* diag, lapack_int* n, - const lapack_complex_float* ap, float* rcond, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_ztpcon( char* norm, char* uplo, char* diag, lapack_int* n, - const lapack_complex_double* ap, double* rcond, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_stbcon( char* norm, char* uplo, char* diag, lapack_int* n, - lapack_int* kd, const float* ab, lapack_int* ldab, - float* rcond, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dtbcon( char* norm, char* uplo, char* diag, lapack_int* n, - lapack_int* kd, const double* ab, lapack_int* ldab, - double* rcond, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_ctbcon( char* norm, char* uplo, char* diag, lapack_int* n, - lapack_int* kd, const lapack_complex_float* ab, - lapack_int* ldab, float* rcond, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_ztbcon( char* norm, char* uplo, char* diag, lapack_int* n, - lapack_int* kd, const lapack_complex_double* ab, - lapack_int* ldab, double* rcond, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sgerfs( char* trans, lapack_int* n, lapack_int* nrhs, - const float* a, lapack_int* lda, const float* af, - lapack_int* ldaf, const lapack_int* ipiv, const float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* ferr, - float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgerfs( char* trans, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, const double* af, - lapack_int* ldaf, const lapack_int* ipiv, const double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* ferr, - double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_cgerfs( char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* af, lapack_int* ldaf, - const lapack_int* ipiv, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* ferr, float* berr, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zgerfs( char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* af, lapack_int* ldaf, - const lapack_int* ipiv, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_dgerfsx( char* trans, char* equed, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, const double* af, - lapack_int* ldaf, const lapack_int* ipiv, const double* r, - const double* c, const double* b, lapack_int* ldb, - double* x, lapack_int* ldx, double* rcond, double* berr, - lapack_int* n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int* nparams, double* params, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_sgerfsx( char* trans, char* equed, lapack_int* n, lapack_int* nrhs, - const float* a, lapack_int* lda, const float* af, - lapack_int* ldaf, const lapack_int* ipiv, const float* r, - const float* c, const float* b, lapack_int* ldb, float* x, - lapack_int* ldx, float* rcond, float* berr, - lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_zgerfsx( char* trans, char* equed, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* af, lapack_int* ldaf, - const lapack_int* ipiv, const double* r, const double* c, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_cgerfsx( char* trans, char* equed, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* af, lapack_int* ldaf, - const lapack_int* ipiv, const float* r, const float* c, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* berr, lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_sgbrfs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, const float* ab, lapack_int* ldab, - const float* afb, lapack_int* ldafb, const lapack_int* ipiv, - const float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* ferr, float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgbrfs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, const double* ab, lapack_int* ldab, - const double* afb, lapack_int* ldafb, - const lapack_int* ipiv, const double* b, lapack_int* ldb, - double* x, lapack_int* ldx, double* ferr, double* berr, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_cgbrfs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, const lapack_complex_float* ab, - lapack_int* ldab, const lapack_complex_float* afb, - lapack_int* ldafb, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zgbrfs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, const lapack_complex_double* ab, - lapack_int* ldab, const lapack_complex_double* afb, - lapack_int* ldafb, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* ferr, - double* berr, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_dgbrfsx( char* trans, char* equed, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, const double* ab, - lapack_int* ldab, const double* afb, lapack_int* ldafb, - const lapack_int* ipiv, const double* r, const double* c, - const double* b, lapack_int* ldb, double* x, - lapack_int* ldx, double* rcond, double* berr, - lapack_int* n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int* nparams, double* params, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_sgbrfsx( char* trans, char* equed, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, const float* ab, - lapack_int* ldab, const float* afb, lapack_int* ldafb, - const lapack_int* ipiv, const float* r, const float* c, - const float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* rcond, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, float* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_zgbrfsx( char* trans, char* equed, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, - const lapack_complex_double* ab, lapack_int* ldab, - const lapack_complex_double* afb, lapack_int* ldafb, - const lapack_int* ipiv, const double* r, const double* c, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_cgbrfsx( char* trans, char* equed, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, - const lapack_complex_float* ab, lapack_int* ldab, - const lapack_complex_float* afb, lapack_int* ldafb, - const lapack_int* ipiv, const float* r, const float* c, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* berr, lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_sgtrfs( char* trans, lapack_int* n, lapack_int* nrhs, - const float* dl, const float* d, const float* du, - const float* dlf, const float* df, const float* duf, - const float* du2, const lapack_int* ipiv, const float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* ferr, - float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgtrfs( char* trans, lapack_int* n, lapack_int* nrhs, - const double* dl, const double* d, const double* du, - const double* dlf, const double* df, const double* duf, - const double* du2, const lapack_int* ipiv, const double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* ferr, - double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_cgtrfs( char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, - const lapack_complex_float* dlf, - const lapack_complex_float* df, - const lapack_complex_float* duf, - const lapack_complex_float* du2, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zgtrfs( char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, - const lapack_complex_double* dlf, - const lapack_complex_double* df, - const lapack_complex_double* duf, - const lapack_complex_double* du2, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* ferr, - double* berr, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sporfs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* a, - lapack_int* lda, const float* af, lapack_int* ldaf, - const float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* ferr, float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dporfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, const double* af, - lapack_int* ldaf, const double* b, lapack_int* ldb, - double* x, lapack_int* ldx, double* ferr, double* berr, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_cporfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* af, lapack_int* ldaf, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zporfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* af, lapack_int* ldaf, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* ferr, - double* berr, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_dporfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, const double* af, - lapack_int* ldaf, const double* s, const double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* rcond, - double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_sporfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const float* a, lapack_int* lda, const float* af, - lapack_int* ldaf, const float* s, const float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* rcond, - float* berr, lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_zporfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* af, lapack_int* ldaf, - const double* s, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* rcond, double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_cporfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* af, lapack_int* ldaf, - const float* s, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* rcond, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_spprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const float* ap, const float* afp, const float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* ferr, - float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dpprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* ap, const double* afp, const double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* ferr, - double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_cpprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* ap, - const lapack_complex_float* afp, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zpprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* ap, - const lapack_complex_double* afp, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* ferr, - double* berr, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_spbrfs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - const float* ab, lapack_int* ldab, const float* afb, - lapack_int* ldafb, const float* b, lapack_int* ldb, - float* x, lapack_int* ldx, float* ferr, float* berr, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_dpbrfs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - const double* ab, lapack_int* ldab, const double* afb, - lapack_int* ldafb, const double* b, lapack_int* ldb, - double* x, lapack_int* ldx, double* ferr, double* berr, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_cpbrfs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - const lapack_complex_float* ab, lapack_int* ldab, - const lapack_complex_float* afb, lapack_int* ldafb, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zpbrfs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - const lapack_complex_double* ab, lapack_int* ldab, - const lapack_complex_double* afb, lapack_int* ldafb, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* ferr, - double* berr, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sptrfs( lapack_int* n, lapack_int* nrhs, const float* d, - const float* e, const float* df, const float* ef, - const float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* ferr, float* berr, float* work, lapack_int *info ); -void LAPACK_dptrfs( lapack_int* n, lapack_int* nrhs, const double* d, - const double* e, const double* df, const double* ef, - const double* b, lapack_int* ldb, double* x, - lapack_int* ldx, double* ferr, double* berr, double* work, - lapack_int *info ); -void LAPACK_cptrfs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* d, - const lapack_complex_float* e, const float* df, - const lapack_complex_float* ef, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zptrfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* d, const lapack_complex_double* e, - const double* df, const lapack_complex_double* ef, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* ferr, - double* berr, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_ssyrfs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* a, - lapack_int* lda, const float* af, lapack_int* ldaf, - const lapack_int* ipiv, const float* b, lapack_int* ldb, - float* x, lapack_int* ldx, float* ferr, float* berr, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_dsyrfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, const double* af, - lapack_int* ldaf, const lapack_int* ipiv, const double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* ferr, - double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_csyrfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* af, lapack_int* ldaf, - const lapack_int* ipiv, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* ferr, float* berr, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zsyrfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* af, lapack_int* ldaf, - const lapack_int* ipiv, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_dsyrfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, const double* af, - lapack_int* ldaf, const lapack_int* ipiv, const double* s, - const double* b, lapack_int* ldb, double* x, - lapack_int* ldx, double* rcond, double* berr, - lapack_int* n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int* nparams, double* params, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_ssyrfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const float* a, lapack_int* lda, const float* af, - lapack_int* ldaf, const lapack_int* ipiv, const float* s, - const float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* rcond, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, float* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_zsyrfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* af, lapack_int* ldaf, - const lapack_int* ipiv, const double* s, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_csyrfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* af, lapack_int* ldaf, - const lapack_int* ipiv, const float* s, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* berr, lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_cherfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* af, lapack_int* ldaf, - const lapack_int* ipiv, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* ferr, float* berr, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zherfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* af, lapack_int* ldaf, - const lapack_int* ipiv, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_zherfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* af, lapack_int* ldaf, - const lapack_int* ipiv, const double* s, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_cherfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* af, lapack_int* ldaf, - const lapack_int* ipiv, const float* s, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* berr, lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_ssprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const float* ap, const float* afp, const lapack_int* ipiv, - const float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* ferr, float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dsprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const double* ap, const double* afp, const lapack_int* ipiv, - const double* b, lapack_int* ldb, double* x, - lapack_int* ldx, double* ferr, double* berr, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_csprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* ap, - const lapack_complex_float* afp, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zsprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* ap, - const lapack_complex_double* afp, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* ferr, - double* berr, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_chprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* ap, - const lapack_complex_float* afp, const lapack_int* ipiv, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zhprfs( char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* ap, - const lapack_complex_double* afp, const lapack_int* ipiv, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* ferr, - double* berr, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_strrfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const float* a, lapack_int* lda, - const float* b, lapack_int* ldb, const float* x, - lapack_int* ldx, float* ferr, float* berr, float* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dtrrfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const double* a, lapack_int* lda, - const double* b, lapack_int* ldb, const double* x, - lapack_int* ldx, double* ferr, double* berr, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_ctrrfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* b, - lapack_int* ldb, const lapack_complex_float* x, - lapack_int* ldx, float* ferr, float* berr, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_ztrrfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* b, - lapack_int* ldb, const lapack_complex_double* x, - lapack_int* ldx, double* ferr, double* berr, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_stprfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const float* ap, const float* b, - lapack_int* ldb, const float* x, lapack_int* ldx, - float* ferr, float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dtprfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const double* ap, const double* b, - lapack_int* ldb, const double* x, lapack_int* ldx, - double* ferr, double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_ctprfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const lapack_complex_float* ap, - const lapack_complex_float* b, lapack_int* ldb, - const lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_ztprfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* nrhs, const lapack_complex_double* ap, - const lapack_complex_double* b, lapack_int* ldb, - const lapack_complex_double* x, lapack_int* ldx, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_stbrfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* kd, lapack_int* nrhs, const float* ab, - lapack_int* ldab, const float* b, lapack_int* ldb, - const float* x, lapack_int* ldx, float* ferr, float* berr, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_dtbrfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* kd, lapack_int* nrhs, const double* ab, - lapack_int* ldab, const double* b, lapack_int* ldb, - const double* x, lapack_int* ldx, double* ferr, - double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_ctbrfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* kd, lapack_int* nrhs, - const lapack_complex_float* ab, lapack_int* ldab, - const lapack_complex_float* b, lapack_int* ldb, - const lapack_complex_float* x, lapack_int* ldx, float* ferr, - float* berr, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_ztbrfs( char* uplo, char* trans, char* diag, lapack_int* n, - lapack_int* kd, lapack_int* nrhs, - const lapack_complex_double* ab, lapack_int* ldab, - const lapack_complex_double* b, lapack_int* ldb, - const lapack_complex_double* x, lapack_int* ldx, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_sgetri( lapack_int* n, float* a, lapack_int* lda, - const lapack_int* ipiv, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dgetri( lapack_int* n, double* a, lapack_int* lda, - const lapack_int* ipiv, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cgetri( lapack_int* n, lapack_complex_float* a, lapack_int* lda, - const lapack_int* ipiv, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zgetri( lapack_int* n, lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_spotri( char* uplo, lapack_int* n, float* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_dpotri( char* uplo, lapack_int* n, double* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_cpotri( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_zpotri( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_dpftri( char* transr, char* uplo, lapack_int* n, double* a, - lapack_int *info ); -void LAPACK_spftri( char* transr, char* uplo, lapack_int* n, float* a, - lapack_int *info ); -void LAPACK_zpftri( char* transr, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int *info ); -void LAPACK_cpftri( char* transr, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int *info ); -void LAPACK_spptri( char* uplo, lapack_int* n, float* ap, lapack_int *info ); -void LAPACK_dpptri( char* uplo, lapack_int* n, double* ap, lapack_int *info ); -void LAPACK_cpptri( char* uplo, lapack_int* n, lapack_complex_float* ap, - lapack_int *info ); -void LAPACK_zpptri( char* uplo, lapack_int* n, lapack_complex_double* ap, - lapack_int *info ); -void LAPACK_ssytri( char* uplo, lapack_int* n, float* a, lapack_int* lda, - const lapack_int* ipiv, float* work, lapack_int *info ); -void LAPACK_dsytri( char* uplo, lapack_int* n, double* a, lapack_int* lda, - const lapack_int* ipiv, double* work, lapack_int *info ); -void LAPACK_csytri( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, const lapack_int* ipiv, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zsytri( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, const lapack_int* ipiv, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_chetri( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, const lapack_int* ipiv, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zhetri( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, const lapack_int* ipiv, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_ssptri( char* uplo, lapack_int* n, float* ap, - const lapack_int* ipiv, float* work, lapack_int *info ); -void LAPACK_dsptri( char* uplo, lapack_int* n, double* ap, - const lapack_int* ipiv, double* work, lapack_int *info ); -void LAPACK_csptri( char* uplo, lapack_int* n, lapack_complex_float* ap, - const lapack_int* ipiv, lapack_complex_float* work, - lapack_int *info ); -void LAPACK_zsptri( char* uplo, lapack_int* n, lapack_complex_double* ap, - const lapack_int* ipiv, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_chptri( char* uplo, lapack_int* n, lapack_complex_float* ap, - const lapack_int* ipiv, lapack_complex_float* work, - lapack_int *info ); -void LAPACK_zhptri( char* uplo, lapack_int* n, lapack_complex_double* ap, - const lapack_int* ipiv, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_strtri( char* uplo, char* diag, lapack_int* n, float* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_dtrtri( char* uplo, char* diag, lapack_int* n, double* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_ctrtri( char* uplo, char* diag, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_ztrtri( char* uplo, char* diag, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_dtftri( char* transr, char* uplo, char* diag, lapack_int* n, - double* a, lapack_int *info ); -void LAPACK_stftri( char* transr, char* uplo, char* diag, lapack_int* n, - float* a, lapack_int *info ); -void LAPACK_ztftri( char* transr, char* uplo, char* diag, lapack_int* n, - lapack_complex_double* a, lapack_int *info ); -void LAPACK_ctftri( char* transr, char* uplo, char* diag, lapack_int* n, - lapack_complex_float* a, lapack_int *info ); -void LAPACK_stptri( char* uplo, char* diag, lapack_int* n, float* ap, - lapack_int *info ); -void LAPACK_dtptri( char* uplo, char* diag, lapack_int* n, double* ap, - lapack_int *info ); -void LAPACK_ctptri( char* uplo, char* diag, lapack_int* n, - lapack_complex_float* ap, lapack_int *info ); -void LAPACK_ztptri( char* uplo, char* diag, lapack_int* n, - lapack_complex_double* ap, lapack_int *info ); -void LAPACK_sgeequ( lapack_int* m, lapack_int* n, const float* a, - lapack_int* lda, float* r, float* c, float* rowcnd, - float* colcnd, float* amax, lapack_int *info ); -void LAPACK_dgeequ( lapack_int* m, lapack_int* n, const double* a, - lapack_int* lda, double* r, double* c, double* rowcnd, - double* colcnd, double* amax, lapack_int *info ); -void LAPACK_cgeequ( lapack_int* m, lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, float* r, float* c, float* rowcnd, - float* colcnd, float* amax, lapack_int *info ); -void LAPACK_zgeequ( lapack_int* m, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, double* r, - double* c, double* rowcnd, double* colcnd, double* amax, - lapack_int *info ); -void LAPACK_dgeequb( lapack_int* m, lapack_int* n, const double* a, - lapack_int* lda, double* r, double* c, double* rowcnd, - double* colcnd, double* amax, lapack_int *info ); -void LAPACK_sgeequb( lapack_int* m, lapack_int* n, const float* a, - lapack_int* lda, float* r, float* c, float* rowcnd, - float* colcnd, float* amax, lapack_int *info ); -void LAPACK_zgeequb( lapack_int* m, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, double* r, - double* c, double* rowcnd, double* colcnd, double* amax, - lapack_int *info ); -void LAPACK_cgeequb( lapack_int* m, lapack_int* n, - const lapack_complex_float* a, lapack_int* lda, float* r, - float* c, float* rowcnd, float* colcnd, float* amax, - lapack_int *info ); -void LAPACK_sgbequ( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const float* ab, lapack_int* ldab, float* r, - float* c, float* rowcnd, float* colcnd, float* amax, - lapack_int *info ); -void LAPACK_dgbequ( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const double* ab, lapack_int* ldab, - double* r, double* c, double* rowcnd, double* colcnd, - double* amax, lapack_int *info ); -void LAPACK_cgbequ( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const lapack_complex_float* ab, - lapack_int* ldab, float* r, float* c, float* rowcnd, - float* colcnd, float* amax, lapack_int *info ); -void LAPACK_zgbequ( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const lapack_complex_double* ab, - lapack_int* ldab, double* r, double* c, double* rowcnd, - double* colcnd, double* amax, lapack_int *info ); -void LAPACK_dgbequb( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const double* ab, lapack_int* ldab, - double* r, double* c, double* rowcnd, double* colcnd, - double* amax, lapack_int *info ); -void LAPACK_sgbequb( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const float* ab, lapack_int* ldab, - float* r, float* c, float* rowcnd, float* colcnd, - float* amax, lapack_int *info ); -void LAPACK_zgbequb( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const lapack_complex_double* ab, - lapack_int* ldab, double* r, double* c, double* rowcnd, - double* colcnd, double* amax, lapack_int *info ); -void LAPACK_cgbequb( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const lapack_complex_float* ab, - lapack_int* ldab, float* r, float* c, float* rowcnd, - float* colcnd, float* amax, lapack_int *info ); -void LAPACK_spoequ( lapack_int* n, const float* a, lapack_int* lda, float* s, - float* scond, float* amax, lapack_int *info ); -void LAPACK_dpoequ( lapack_int* n, const double* a, lapack_int* lda, double* s, - double* scond, double* amax, lapack_int *info ); -void LAPACK_cpoequ( lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, float* s, float* scond, float* amax, - lapack_int *info ); -void LAPACK_zpoequ( lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, double* s, double* scond, double* amax, - lapack_int *info ); -void LAPACK_dpoequb( lapack_int* n, const double* a, lapack_int* lda, double* s, - double* scond, double* amax, lapack_int *info ); -void LAPACK_spoequb( lapack_int* n, const float* a, lapack_int* lda, float* s, - float* scond, float* amax, lapack_int *info ); -void LAPACK_zpoequb( lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, double* s, double* scond, double* amax, - lapack_int *info ); -void LAPACK_cpoequb( lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, float* s, float* scond, float* amax, - lapack_int *info ); -void LAPACK_sppequ( char* uplo, lapack_int* n, const float* ap, float* s, - float* scond, float* amax, lapack_int *info ); -void LAPACK_dppequ( char* uplo, lapack_int* n, const double* ap, double* s, - double* scond, double* amax, lapack_int *info ); -void LAPACK_cppequ( char* uplo, lapack_int* n, const lapack_complex_float* ap, - float* s, float* scond, float* amax, lapack_int *info ); -void LAPACK_zppequ( char* uplo, lapack_int* n, const lapack_complex_double* ap, - double* s, double* scond, double* amax, lapack_int *info ); -void LAPACK_spbequ( char* uplo, lapack_int* n, lapack_int* kd, const float* ab, - lapack_int* ldab, float* s, float* scond, float* amax, - lapack_int *info ); -void LAPACK_dpbequ( char* uplo, lapack_int* n, lapack_int* kd, const double* ab, - lapack_int* ldab, double* s, double* scond, double* amax, - lapack_int *info ); -void LAPACK_cpbequ( char* uplo, lapack_int* n, lapack_int* kd, - const lapack_complex_float* ab, lapack_int* ldab, float* s, - float* scond, float* amax, lapack_int *info ); -void LAPACK_zpbequ( char* uplo, lapack_int* n, lapack_int* kd, - const lapack_complex_double* ab, lapack_int* ldab, - double* s, double* scond, double* amax, lapack_int *info ); -void LAPACK_dsyequb( char* uplo, lapack_int* n, const double* a, - lapack_int* lda, double* s, double* scond, double* amax, - double* work, lapack_int *info ); -void LAPACK_ssyequb( char* uplo, lapack_int* n, const float* a, lapack_int* lda, - float* s, float* scond, float* amax, float* work, - lapack_int *info ); -void LAPACK_zsyequb( char* uplo, lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, double* s, double* scond, double* amax, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_csyequb( char* uplo, lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, float* s, float* scond, float* amax, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zheequb( char* uplo, lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, double* s, double* scond, double* amax, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_cheequb( char* uplo, lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, float* s, float* scond, float* amax, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_sgesv( lapack_int* n, lapack_int* nrhs, float* a, lapack_int* lda, - lapack_int* ipiv, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dgesv( lapack_int* n, lapack_int* nrhs, double* a, lapack_int* lda, - lapack_int* ipiv, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_cgesv( lapack_int* n, lapack_int* nrhs, lapack_complex_float* a, - lapack_int* lda, lapack_int* ipiv, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_zgesv( lapack_int* n, lapack_int* nrhs, lapack_complex_double* a, - lapack_int* lda, lapack_int* ipiv, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_dsgesv( lapack_int* n, lapack_int* nrhs, double* a, lapack_int* lda, - lapack_int* ipiv, double* b, lapack_int* ldb, double* x, - lapack_int* ldx, double* work, float* swork, - lapack_int* iter, lapack_int *info ); -void LAPACK_zcgesv( lapack_int* n, lapack_int* nrhs, lapack_complex_double* a, - lapack_int* lda, lapack_int* ipiv, lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - lapack_complex_double* work, lapack_complex_float* swork, - double* rwork, lapack_int* iter, lapack_int *info ); -void LAPACK_sgesvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - float* a, lapack_int* lda, float* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, float* r, float* c, float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgesvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - double* a, lapack_int* lda, double* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, double* r, double* c, - double* b, lapack_int* ldb, double* x, lapack_int* ldx, - double* rcond, double* ferr, double* berr, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_cgesvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, float* r, float* c, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zgesvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, double* r, double* c, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_dgesvxx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - double* a, lapack_int* lda, double* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, double* r, double* c, - double* b, lapack_int* ldb, double* x, lapack_int* ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int* n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int* nparams, double* params, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_sgesvxx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - float* a, lapack_int* lda, float* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, float* r, float* c, - float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_zgesvxx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, double* r, double* c, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* rpvgrw, double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_cgesvxx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, float* r, float* c, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* rpvgrw, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_sgbsv( lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, float* ab, lapack_int* ldab, - lapack_int* ipiv, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dgbsv( lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, double* ab, lapack_int* ldab, - lapack_int* ipiv, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_cgbsv( lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, lapack_complex_float* ab, lapack_int* ldab, - lapack_int* ipiv, lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zgbsv( lapack_int* n, lapack_int* kl, lapack_int* ku, - lapack_int* nrhs, lapack_complex_double* ab, - lapack_int* ldab, lapack_int* ipiv, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_sgbsvx( char* fact, char* trans, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, float* ab, - lapack_int* ldab, float* afb, lapack_int* ldafb, - lapack_int* ipiv, char* equed, float* r, float* c, float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgbsvx( char* fact, char* trans, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, double* ab, - lapack_int* ldab, double* afb, lapack_int* ldafb, - lapack_int* ipiv, char* equed, double* r, double* c, - double* b, lapack_int* ldb, double* x, lapack_int* ldx, - double* rcond, double* ferr, double* berr, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_cgbsvx( char* fact, char* trans, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, lapack_complex_float* ab, - lapack_int* ldab, lapack_complex_float* afb, - lapack_int* ldafb, lapack_int* ipiv, char* equed, float* r, - float* c, lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zgbsvx( char* fact, char* trans, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, lapack_complex_double* ab, - lapack_int* ldab, lapack_complex_double* afb, - lapack_int* ldafb, lapack_int* ipiv, char* equed, double* r, - double* c, lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_dgbsvxx( char* fact, char* trans, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, double* ab, - lapack_int* ldab, double* afb, lapack_int* ldafb, - lapack_int* ipiv, char* equed, double* r, double* c, - double* b, lapack_int* ldb, double* x, lapack_int* ldx, - double* rcond, double* rpvgrw, double* berr, - lapack_int* n_err_bnds, double* err_bnds_norm, - double* err_bnds_comp, lapack_int* nparams, double* params, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_sgbsvxx( char* fact, char* trans, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, float* ab, - lapack_int* ldab, float* afb, lapack_int* ldafb, - lapack_int* ipiv, char* equed, float* r, float* c, - float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* rcond, float* rpvgrw, float* berr, - lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_zgbsvxx( char* fact, char* trans, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, - lapack_complex_double* ab, lapack_int* ldab, - lapack_complex_double* afb, lapack_int* ldafb, - lapack_int* ipiv, char* equed, double* r, double* c, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* rpvgrw, double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_cgbsvxx( char* fact, char* trans, lapack_int* n, lapack_int* kl, - lapack_int* ku, lapack_int* nrhs, lapack_complex_float* ab, - lapack_int* ldab, lapack_complex_float* afb, - lapack_int* ldafb, lapack_int* ipiv, char* equed, float* r, - float* c, lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* rpvgrw, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_sgtsv( lapack_int* n, lapack_int* nrhs, float* dl, float* d, - float* du, float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_dgtsv( lapack_int* n, lapack_int* nrhs, double* dl, double* d, - double* du, double* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_cgtsv( lapack_int* n, lapack_int* nrhs, lapack_complex_float* dl, - lapack_complex_float* d, lapack_complex_float* du, - lapack_complex_float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_zgtsv( lapack_int* n, lapack_int* nrhs, lapack_complex_double* dl, - lapack_complex_double* d, lapack_complex_double* du, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_sgtsvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - const float* dl, const float* d, const float* du, - float* dlf, float* df, float* duf, float* du2, - lapack_int* ipiv, const float* b, lapack_int* ldb, float* x, - lapack_int* ldx, float* rcond, float* ferr, float* berr, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_dgtsvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - const double* dl, const double* d, const double* du, - double* dlf, double* df, double* duf, double* du2, - lapack_int* ipiv, const double* b, lapack_int* ldb, - double* x, lapack_int* ldx, double* rcond, double* ferr, - double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_cgtsvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* dl, - const lapack_complex_float* d, - const lapack_complex_float* du, lapack_complex_float* dlf, - lapack_complex_float* df, lapack_complex_float* duf, - lapack_complex_float* du2, lapack_int* ipiv, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zgtsvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* dl, - const lapack_complex_double* d, - const lapack_complex_double* du, lapack_complex_double* dlf, - lapack_complex_double* df, lapack_complex_double* duf, - lapack_complex_double* du2, lapack_int* ipiv, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_sposv( char* uplo, lapack_int* n, lapack_int* nrhs, float* a, - lapack_int* lda, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dposv( char* uplo, lapack_int* n, lapack_int* nrhs, double* a, - lapack_int* lda, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_cposv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_zposv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dsposv( char* uplo, lapack_int* n, lapack_int* nrhs, double* a, - lapack_int* lda, double* b, lapack_int* ldb, double* x, - lapack_int* ldx, double* work, float* swork, - lapack_int* iter, lapack_int *info ); -void LAPACK_zcposv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, - lapack_complex_double* work, lapack_complex_float* swork, - double* rwork, lapack_int* iter, lapack_int *info ); -void LAPACK_sposvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - float* a, lapack_int* lda, float* af, lapack_int* ldaf, - char* equed, float* s, float* b, lapack_int* ldb, float* x, - lapack_int* ldx, float* rcond, float* ferr, float* berr, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_dposvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - double* a, lapack_int* lda, double* af, lapack_int* ldaf, - char* equed, double* s, double* b, lapack_int* ldb, - double* x, lapack_int* ldx, double* rcond, double* ferr, - double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_cposvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* af, lapack_int* ldaf, char* equed, - float* s, lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zposvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* af, lapack_int* ldaf, char* equed, - double* s, lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_dposvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - double* a, lapack_int* lda, double* af, lapack_int* ldaf, - char* equed, double* s, double* b, lapack_int* ldb, - double* x, lapack_int* ldx, double* rcond, double* rpvgrw, - double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_sposvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - float* a, lapack_int* lda, float* af, lapack_int* ldaf, - char* equed, float* s, float* b, lapack_int* ldb, float* x, - lapack_int* ldx, float* rcond, float* rpvgrw, float* berr, - lapack_int* n_err_bnds, float* err_bnds_norm, - float* err_bnds_comp, lapack_int* nparams, float* params, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_zposvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* af, lapack_int* ldaf, char* equed, - double* s, lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* rpvgrw, double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_cposvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* af, lapack_int* ldaf, char* equed, - float* s, lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* rpvgrw, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_sppsv( char* uplo, lapack_int* n, lapack_int* nrhs, float* ap, - float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_dppsv( char* uplo, lapack_int* n, lapack_int* nrhs, double* ap, - double* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_cppsv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* ap, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_zppsv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* ap, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_sppsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - float* ap, float* afp, char* equed, float* s, float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dppsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - double* ap, double* afp, char* equed, double* s, double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* rcond, - double* ferr, double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_cppsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* ap, lapack_complex_float* afp, - char* equed, float* s, lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zppsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* ap, lapack_complex_double* afp, - char* equed, double* s, lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_spbsv( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - float* ab, lapack_int* ldab, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dpbsv( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - double* ab, lapack_int* ldab, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_cpbsv( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - lapack_complex_float* ab, lapack_int* ldab, - lapack_complex_float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_zpbsv( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs, - lapack_complex_double* ab, lapack_int* ldab, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_spbsvx( char* fact, char* uplo, lapack_int* n, lapack_int* kd, - lapack_int* nrhs, float* ab, lapack_int* ldab, float* afb, - lapack_int* ldafb, char* equed, float* s, float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dpbsvx( char* fact, char* uplo, lapack_int* n, lapack_int* kd, - lapack_int* nrhs, double* ab, lapack_int* ldab, double* afb, - lapack_int* ldafb, char* equed, double* s, double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* rcond, - double* ferr, double* berr, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_cpbsvx( char* fact, char* uplo, lapack_int* n, lapack_int* kd, - lapack_int* nrhs, lapack_complex_float* ab, - lapack_int* ldab, lapack_complex_float* afb, - lapack_int* ldafb, char* equed, float* s, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zpbsvx( char* fact, char* uplo, lapack_int* n, lapack_int* kd, - lapack_int* nrhs, lapack_complex_double* ab, - lapack_int* ldab, lapack_complex_double* afb, - lapack_int* ldafb, char* equed, double* s, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* ferr, double* berr, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_sptsv( lapack_int* n, lapack_int* nrhs, float* d, float* e, - float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_dptsv( lapack_int* n, lapack_int* nrhs, double* d, double* e, - double* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_cptsv( lapack_int* n, lapack_int* nrhs, float* d, - lapack_complex_float* e, lapack_complex_float* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_zptsv( lapack_int* n, lapack_int* nrhs, double* d, - lapack_complex_double* e, lapack_complex_double* b, - lapack_int* ldb, lapack_int *info ); -void LAPACK_sptsvx( char* fact, lapack_int* n, lapack_int* nrhs, const float* d, - const float* e, float* df, float* ef, const float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, float* work, lapack_int *info ); -void LAPACK_dptsvx( char* fact, lapack_int* n, lapack_int* nrhs, - const double* d, const double* e, double* df, double* ef, - const double* b, lapack_int* ldb, double* x, - lapack_int* ldx, double* rcond, double* ferr, double* berr, - double* work, lapack_int *info ); -void LAPACK_cptsvx( char* fact, lapack_int* n, lapack_int* nrhs, const float* d, - const lapack_complex_float* e, float* df, - lapack_complex_float* ef, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zptsvx( char* fact, lapack_int* n, lapack_int* nrhs, - const double* d, const lapack_complex_double* e, double* df, - lapack_complex_double* ef, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_ssysv( char* uplo, lapack_int* n, lapack_int* nrhs, float* a, - lapack_int* lda, lapack_int* ipiv, float* b, lapack_int* ldb, - float* work, lapack_int* lwork, lapack_int *info ); -void LAPACK_dsysv( char* uplo, lapack_int* n, lapack_int* nrhs, double* a, - lapack_int* lda, lapack_int* ipiv, double* b, - lapack_int* ldb, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_csysv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zsysv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_ssysvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const float* a, lapack_int* lda, float* af, - lapack_int* ldaf, lapack_int* ipiv, const float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* rcond, - float* ferr, float* berr, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dsysvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const double* a, lapack_int* lda, double* af, - lapack_int* ldaf, lapack_int* ipiv, const double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* rcond, - double* ferr, double* berr, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_csysvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* af, lapack_int* ldaf, - lapack_int* ipiv, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zsysvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* af, lapack_int* ldaf, - lapack_int* ipiv, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_dsysvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - double* a, lapack_int* lda, double* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, double* s, double* b, - lapack_int* ldb, double* x, lapack_int* ldx, double* rcond, - double* rpvgrw, double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_ssysvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - float* a, lapack_int* lda, float* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, float* s, float* b, - lapack_int* ldb, float* x, lapack_int* ldx, float* rcond, - float* rpvgrw, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, float* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_zsysvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, double* s, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* rpvgrw, double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_csysvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, float* s, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* rpvgrw, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_chesv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zhesv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_chesvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* af, lapack_int* ldaf, - lapack_int* ipiv, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zhesvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* af, lapack_int* ldaf, - lapack_int* ipiv, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_zhesvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, double* s, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* x, lapack_int* ldx, double* rcond, - double* rpvgrw, double* berr, lapack_int* n_err_bnds, - double* err_bnds_norm, double* err_bnds_comp, - lapack_int* nparams, double* params, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_chesvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* af, lapack_int* ldaf, - lapack_int* ipiv, char* equed, float* s, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* x, lapack_int* ldx, float* rcond, - float* rpvgrw, float* berr, lapack_int* n_err_bnds, - float* err_bnds_norm, float* err_bnds_comp, - lapack_int* nparams, float* params, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_sspsv( char* uplo, lapack_int* n, lapack_int* nrhs, float* ap, - lapack_int* ipiv, float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dspsv( char* uplo, lapack_int* n, lapack_int* nrhs, double* ap, - lapack_int* ipiv, double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_cspsv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* ap, lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_zspsv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* ap, lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_sspsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const float* ap, float* afp, lapack_int* ipiv, - const float* b, lapack_int* ldb, float* x, lapack_int* ldx, - float* rcond, float* ferr, float* berr, float* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dspsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const double* ap, double* afp, lapack_int* ipiv, - const double* b, lapack_int* ldb, double* x, - lapack_int* ldx, double* rcond, double* ferr, double* berr, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_cspsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* ap, lapack_complex_float* afp, - lapack_int* ipiv, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zspsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* ap, lapack_complex_double* afp, - lapack_int* ipiv, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_chpsv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* ap, lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, lapack_int *info ); -void LAPACK_zhpsv( char* uplo, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* ap, lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_chpsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_float* ap, lapack_complex_float* afp, - lapack_int* ipiv, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx, - float* rcond, float* ferr, float* berr, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zhpsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs, - const lapack_complex_double* ap, lapack_complex_double* afp, - lapack_int* ipiv, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx, - double* rcond, double* ferr, double* berr, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sgeqrf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* tau, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dgeqrf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* tau, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cgeqrf( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zgeqrf( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sgeqpf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - lapack_int* jpvt, float* tau, float* work, - lapack_int *info ); -void LAPACK_dgeqpf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - lapack_int* jpvt, double* tau, double* work, - lapack_int *info ); -void LAPACK_cgeqpf( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* jpvt, - lapack_complex_float* tau, lapack_complex_float* work, - float* rwork, lapack_int *info ); -void LAPACK_zgeqpf( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* jpvt, - lapack_complex_double* tau, lapack_complex_double* work, - double* rwork, lapack_int *info ); -void LAPACK_sgeqp3( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - lapack_int* jpvt, float* tau, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dgeqp3( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - lapack_int* jpvt, double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cgeqp3( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* jpvt, - lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_int *info ); -void LAPACK_zgeqp3( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* jpvt, - lapack_complex_double* tau, lapack_complex_double* work, - lapack_int* lwork, double* rwork, lapack_int *info ); -void LAPACK_sorgqr( lapack_int* m, lapack_int* n, lapack_int* k, float* a, - lapack_int* lda, const float* tau, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dorgqr( lapack_int* m, lapack_int* n, lapack_int* k, double* a, - lapack_int* lda, const double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sormqr( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const float* a, lapack_int* lda, - const float* tau, float* c, lapack_int* ldc, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dormqr( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const double* a, lapack_int* lda, - const double* tau, double* c, lapack_int* ldc, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cungqr( lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zungqr( lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cunmqr( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zunmqr( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sgelqf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* tau, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dgelqf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* tau, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cgelqf( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zgelqf( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sorglq( lapack_int* m, lapack_int* n, lapack_int* k, float* a, - lapack_int* lda, const float* tau, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dorglq( lapack_int* m, lapack_int* n, lapack_int* k, double* a, - lapack_int* lda, const double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sormlq( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const float* a, lapack_int* lda, - const float* tau, float* c, lapack_int* ldc, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dormlq( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const double* a, lapack_int* lda, - const double* tau, double* c, lapack_int* ldc, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cunglq( lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zunglq( lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cunmlq( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zunmlq( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sgeqlf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* tau, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dgeqlf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* tau, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cgeqlf( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zgeqlf( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sorgql( lapack_int* m, lapack_int* n, lapack_int* k, float* a, - lapack_int* lda, const float* tau, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dorgql( lapack_int* m, lapack_int* n, lapack_int* k, double* a, - lapack_int* lda, const double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cungql( lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zungql( lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sormql( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const float* a, lapack_int* lda, - const float* tau, float* c, lapack_int* ldc, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dormql( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const double* a, lapack_int* lda, - const double* tau, double* c, lapack_int* ldc, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cunmql( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zunmql( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sgerqf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* tau, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dgerqf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* tau, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cgerqf( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zgerqf( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sorgrq( lapack_int* m, lapack_int* n, lapack_int* k, float* a, - lapack_int* lda, const float* tau, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dorgrq( lapack_int* m, lapack_int* n, lapack_int* k, double* a, - lapack_int* lda, const double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cungrq( lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zungrq( lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sormrq( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const float* a, lapack_int* lda, - const float* tau, float* c, lapack_int* ldc, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dormrq( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const double* a, lapack_int* lda, - const double* tau, double* c, lapack_int* ldc, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cunmrq( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zunmrq( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, const lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_stzrzf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* tau, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dtzrzf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* tau, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_ctzrzf( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_ztzrzf( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sormrz( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* l, const float* a, - lapack_int* lda, const float* tau, float* c, - lapack_int* ldc, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dormrz( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* l, const double* a, - lapack_int* lda, const double* tau, double* c, - lapack_int* ldc, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cunmrz( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* l, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zunmrz( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* l, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, lapack_complex_double* c, - lapack_int* ldc, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sggqrf( lapack_int* n, lapack_int* m, lapack_int* p, float* a, - lapack_int* lda, float* taua, float* b, lapack_int* ldb, - float* taub, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dggqrf( lapack_int* n, lapack_int* m, lapack_int* p, double* a, - lapack_int* lda, double* taua, double* b, lapack_int* ldb, - double* taub, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cggqrf( lapack_int* n, lapack_int* m, lapack_int* p, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* taua, lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* taub, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zggqrf( lapack_int* n, lapack_int* m, lapack_int* p, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* taua, lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* taub, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sggrqf( lapack_int* m, lapack_int* p, lapack_int* n, float* a, - lapack_int* lda, float* taua, float* b, lapack_int* ldb, - float* taub, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dggrqf( lapack_int* m, lapack_int* p, lapack_int* n, double* a, - lapack_int* lda, double* taua, double* b, lapack_int* ldb, - double* taub, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cggrqf( lapack_int* m, lapack_int* p, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* taua, lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* taub, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zggrqf( lapack_int* m, lapack_int* p, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* taua, lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* taub, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sgebrd( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* d, float* e, float* tauq, float* taup, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dgebrd( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* d, double* e, double* tauq, double* taup, - double* work, lapack_int* lwork, lapack_int *info ); -void LAPACK_cgebrd( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, float* d, float* e, - lapack_complex_float* tauq, lapack_complex_float* taup, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zgebrd( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, double* d, double* e, - lapack_complex_double* tauq, lapack_complex_double* taup, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sgbbrd( char* vect, lapack_int* m, lapack_int* n, lapack_int* ncc, - lapack_int* kl, lapack_int* ku, float* ab, lapack_int* ldab, - float* d, float* e, float* q, lapack_int* ldq, float* pt, - lapack_int* ldpt, float* c, lapack_int* ldc, float* work, - lapack_int *info ); -void LAPACK_dgbbrd( char* vect, lapack_int* m, lapack_int* n, lapack_int* ncc, - lapack_int* kl, lapack_int* ku, double* ab, - lapack_int* ldab, double* d, double* e, double* q, - lapack_int* ldq, double* pt, lapack_int* ldpt, double* c, - lapack_int* ldc, double* work, lapack_int *info ); -void LAPACK_cgbbrd( char* vect, lapack_int* m, lapack_int* n, lapack_int* ncc, - lapack_int* kl, lapack_int* ku, lapack_complex_float* ab, - lapack_int* ldab, float* d, float* e, - lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* pt, lapack_int* ldpt, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zgbbrd( char* vect, lapack_int* m, lapack_int* n, lapack_int* ncc, - lapack_int* kl, lapack_int* ku, lapack_complex_double* ab, - lapack_int* ldab, double* d, double* e, - lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* pt, lapack_int* ldpt, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sorgbr( char* vect, lapack_int* m, lapack_int* n, lapack_int* k, - float* a, lapack_int* lda, const float* tau, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dorgbr( char* vect, lapack_int* m, lapack_int* n, lapack_int* k, - double* a, lapack_int* lda, const double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sormbr( char* vect, char* side, char* trans, lapack_int* m, - lapack_int* n, lapack_int* k, const float* a, - lapack_int* lda, const float* tau, float* c, - lapack_int* ldc, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dormbr( char* vect, char* side, char* trans, lapack_int* m, - lapack_int* n, lapack_int* k, const double* a, - lapack_int* lda, const double* tau, double* c, - lapack_int* ldc, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cungbr( char* vect, lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zungbr( char* vect, lapack_int* m, lapack_int* n, lapack_int* k, - lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cunmbr( char* vect, char* side, char* trans, lapack_int* m, - lapack_int* n, lapack_int* k, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zunmbr( char* vect, char* side, char* trans, lapack_int* m, - lapack_int* n, lapack_int* k, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, lapack_complex_double* c, - lapack_int* ldc, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sbdsqr( char* uplo, lapack_int* n, lapack_int* ncvt, - lapack_int* nru, lapack_int* ncc, float* d, float* e, - float* vt, lapack_int* ldvt, float* u, lapack_int* ldu, - float* c, lapack_int* ldc, float* work, lapack_int *info ); -void LAPACK_dbdsqr( char* uplo, lapack_int* n, lapack_int* ncvt, - lapack_int* nru, lapack_int* ncc, double* d, double* e, - double* vt, lapack_int* ldvt, double* u, lapack_int* ldu, - double* c, lapack_int* ldc, double* work, - lapack_int *info ); -void LAPACK_cbdsqr( char* uplo, lapack_int* n, lapack_int* ncvt, - lapack_int* nru, lapack_int* ncc, float* d, float* e, - lapack_complex_float* vt, lapack_int* ldvt, - lapack_complex_float* u, lapack_int* ldu, - lapack_complex_float* c, lapack_int* ldc, float* work, - lapack_int *info ); -void LAPACK_zbdsqr( char* uplo, lapack_int* n, lapack_int* ncvt, - lapack_int* nru, lapack_int* ncc, double* d, double* e, - lapack_complex_double* vt, lapack_int* ldvt, - lapack_complex_double* u, lapack_int* ldu, - lapack_complex_double* c, lapack_int* ldc, double* work, - lapack_int *info ); -void LAPACK_sbdsdc( char* uplo, char* compq, lapack_int* n, float* d, float* e, - float* u, lapack_int* ldu, float* vt, lapack_int* ldvt, - float* q, lapack_int* iq, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dbdsdc( char* uplo, char* compq, lapack_int* n, double* d, - double* e, double* u, lapack_int* ldu, double* vt, - lapack_int* ldvt, double* q, lapack_int* iq, double* work, - lapack_int* iwork, lapack_int *info ); -void LAPACK_ssytrd( char* uplo, lapack_int* n, float* a, lapack_int* lda, - float* d, float* e, float* tau, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dsytrd( char* uplo, lapack_int* n, double* a, lapack_int* lda, - double* d, double* e, double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sorgtr( char* uplo, lapack_int* n, float* a, lapack_int* lda, - const float* tau, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dorgtr( char* uplo, lapack_int* n, double* a, lapack_int* lda, - const double* tau, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sormtr( char* side, char* uplo, char* trans, lapack_int* m, - lapack_int* n, const float* a, lapack_int* lda, - const float* tau, float* c, lapack_int* ldc, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dormtr( char* side, char* uplo, char* trans, lapack_int* m, - lapack_int* n, const double* a, lapack_int* lda, - const double* tau, double* c, lapack_int* ldc, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_chetrd( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, float* d, float* e, - lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zhetrd( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, double* d, double* e, - lapack_complex_double* tau, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cungtr( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* tau, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zungtr( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cunmtr( char* side, char* uplo, char* trans, lapack_int* m, - lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* tau, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zunmtr( char* side, char* uplo, char* trans, lapack_int* m, - lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* tau, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_ssptrd( char* uplo, lapack_int* n, float* ap, float* d, float* e, - float* tau, lapack_int *info ); -void LAPACK_dsptrd( char* uplo, lapack_int* n, double* ap, double* d, double* e, - double* tau, lapack_int *info ); -void LAPACK_sopgtr( char* uplo, lapack_int* n, const float* ap, - const float* tau, float* q, lapack_int* ldq, float* work, - lapack_int *info ); -void LAPACK_dopgtr( char* uplo, lapack_int* n, const double* ap, - const double* tau, double* q, lapack_int* ldq, double* work, - lapack_int *info ); -void LAPACK_sopmtr( char* side, char* uplo, char* trans, lapack_int* m, - lapack_int* n, const float* ap, const float* tau, float* c, - lapack_int* ldc, float* work, lapack_int *info ); -void LAPACK_dopmtr( char* side, char* uplo, char* trans, lapack_int* m, - lapack_int* n, const double* ap, const double* tau, - double* c, lapack_int* ldc, double* work, - lapack_int *info ); -void LAPACK_chptrd( char* uplo, lapack_int* n, lapack_complex_float* ap, - float* d, float* e, lapack_complex_float* tau, - lapack_int *info ); -void LAPACK_zhptrd( char* uplo, lapack_int* n, lapack_complex_double* ap, - double* d, double* e, lapack_complex_double* tau, - lapack_int *info ); -void LAPACK_cupgtr( char* uplo, lapack_int* n, const lapack_complex_float* ap, - const lapack_complex_float* tau, lapack_complex_float* q, - lapack_int* ldq, lapack_complex_float* work, - lapack_int *info ); -void LAPACK_zupgtr( char* uplo, lapack_int* n, const lapack_complex_double* ap, - const lapack_complex_double* tau, lapack_complex_double* q, - lapack_int* ldq, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_cupmtr( char* side, char* uplo, char* trans, lapack_int* m, - lapack_int* n, const lapack_complex_float* ap, - const lapack_complex_float* tau, lapack_complex_float* c, - lapack_int* ldc, lapack_complex_float* work, - lapack_int *info ); -void LAPACK_zupmtr( char* side, char* uplo, char* trans, lapack_int* m, - lapack_int* n, const lapack_complex_double* ap, - const lapack_complex_double* tau, lapack_complex_double* c, - lapack_int* ldc, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_ssbtrd( char* vect, char* uplo, lapack_int* n, lapack_int* kd, - float* ab, lapack_int* ldab, float* d, float* e, float* q, - lapack_int* ldq, float* work, lapack_int *info ); -void LAPACK_dsbtrd( char* vect, char* uplo, lapack_int* n, lapack_int* kd, - double* ab, lapack_int* ldab, double* d, double* e, - double* q, lapack_int* ldq, double* work, - lapack_int *info ); -void LAPACK_chbtrd( char* vect, char* uplo, lapack_int* n, lapack_int* kd, - lapack_complex_float* ab, lapack_int* ldab, float* d, - float* e, lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zhbtrd( char* vect, char* uplo, lapack_int* n, lapack_int* kd, - lapack_complex_double* ab, lapack_int* ldab, double* d, - double* e, lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_ssterf( lapack_int* n, float* d, float* e, lapack_int *info ); -void LAPACK_dsterf( lapack_int* n, double* d, double* e, lapack_int *info ); -void LAPACK_ssteqr( char* compz, lapack_int* n, float* d, float* e, float* z, - lapack_int* ldz, float* work, lapack_int *info ); -void LAPACK_dsteqr( char* compz, lapack_int* n, double* d, double* e, double* z, - lapack_int* ldz, double* work, lapack_int *info ); -void LAPACK_csteqr( char* compz, lapack_int* n, float* d, float* e, - lapack_complex_float* z, lapack_int* ldz, float* work, - lapack_int *info ); -void LAPACK_zsteqr( char* compz, lapack_int* n, double* d, double* e, - lapack_complex_double* z, lapack_int* ldz, double* work, - lapack_int *info ); -void LAPACK_sstemr( char* jobz, char* range, lapack_int* n, float* d, float* e, - float* vl, float* vu, lapack_int* il, lapack_int* iu, - lapack_int* m, float* w, float* z, lapack_int* ldz, - lapack_int* nzc, lapack_int* isuppz, lapack_logical* tryrac, - float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_dstemr( char* jobz, char* range, lapack_int* n, double* d, - double* e, double* vl, double* vu, lapack_int* il, - lapack_int* iu, lapack_int* m, double* w, double* z, - lapack_int* ldz, lapack_int* nzc, lapack_int* isuppz, - lapack_logical* tryrac, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_cstemr( char* jobz, char* range, lapack_int* n, float* d, float* e, - float* vl, float* vu, lapack_int* il, lapack_int* iu, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_int* nzc, lapack_int* isuppz, - lapack_logical* tryrac, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_zstemr( char* jobz, char* range, lapack_int* n, double* d, - double* e, double* vl, double* vu, lapack_int* il, - lapack_int* iu, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int* ldz, lapack_int* nzc, - lapack_int* isuppz, lapack_logical* tryrac, double* work, - lapack_int* lwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_sstedc( char* compz, lapack_int* n, float* d, float* e, float* z, - lapack_int* ldz, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_dstedc( char* compz, lapack_int* n, double* d, double* e, double* z, - lapack_int* ldz, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_cstedc( char* compz, lapack_int* n, float* d, float* e, - lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_zstedc( char* compz, lapack_int* n, double* d, double* e, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_sstegr( char* jobz, char* range, lapack_int* n, float* d, float* e, - float* vl, float* vu, lapack_int* il, lapack_int* iu, - float* abstol, lapack_int* m, float* w, float* z, - lapack_int* ldz, lapack_int* isuppz, float* work, - lapack_int* lwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_dstegr( char* jobz, char* range, lapack_int* n, double* d, - double* e, double* vl, double* vu, lapack_int* il, - lapack_int* iu, double* abstol, lapack_int* m, double* w, - double* z, lapack_int* ldz, lapack_int* isuppz, - double* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_cstegr( char* jobz, char* range, lapack_int* n, float* d, float* e, - float* vl, float* vu, lapack_int* il, lapack_int* iu, - float* abstol, lapack_int* m, float* w, - lapack_complex_float* z, lapack_int* ldz, - lapack_int* isuppz, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_zstegr( char* jobz, char* range, lapack_int* n, double* d, - double* e, double* vl, double* vu, lapack_int* il, - lapack_int* iu, double* abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int* ldz, - lapack_int* isuppz, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_spteqr( char* compz, lapack_int* n, float* d, float* e, float* z, - lapack_int* ldz, float* work, lapack_int *info ); -void LAPACK_dpteqr( char* compz, lapack_int* n, double* d, double* e, double* z, - lapack_int* ldz, double* work, lapack_int *info ); -void LAPACK_cpteqr( char* compz, lapack_int* n, float* d, float* e, - lapack_complex_float* z, lapack_int* ldz, float* work, - lapack_int *info ); -void LAPACK_zpteqr( char* compz, lapack_int* n, double* d, double* e, - lapack_complex_double* z, lapack_int* ldz, double* work, - lapack_int *info ); -void LAPACK_sstebz( char* range, char* order, lapack_int* n, float* vl, - float* vu, lapack_int* il, lapack_int* iu, float* abstol, - const float* d, const float* e, lapack_int* m, - lapack_int* nsplit, float* w, lapack_int* iblock, - lapack_int* isplit, float* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dstebz( char* range, char* order, lapack_int* n, double* vl, - double* vu, lapack_int* il, lapack_int* iu, double* abstol, - const double* d, const double* e, lapack_int* m, - lapack_int* nsplit, double* w, lapack_int* iblock, - lapack_int* isplit, double* work, lapack_int* iwork, - lapack_int *info ); -void LAPACK_sstein( lapack_int* n, const float* d, const float* e, - lapack_int* m, const float* w, const lapack_int* iblock, - const lapack_int* isplit, float* z, lapack_int* ldz, - float* work, lapack_int* iwork, lapack_int* ifailv, - lapack_int *info ); -void LAPACK_dstein( lapack_int* n, const double* d, const double* e, - lapack_int* m, const double* w, const lapack_int* iblock, - const lapack_int* isplit, double* z, lapack_int* ldz, - double* work, lapack_int* iwork, lapack_int* ifailv, - lapack_int *info ); -void LAPACK_cstein( lapack_int* n, const float* d, const float* e, - lapack_int* m, const float* w, const lapack_int* iblock, - const lapack_int* isplit, lapack_complex_float* z, - lapack_int* ldz, float* work, lapack_int* iwork, - lapack_int* ifailv, lapack_int *info ); -void LAPACK_zstein( lapack_int* n, const double* d, const double* e, - lapack_int* m, const double* w, const lapack_int* iblock, - const lapack_int* isplit, lapack_complex_double* z, - lapack_int* ldz, double* work, lapack_int* iwork, - lapack_int* ifailv, lapack_int *info ); -void LAPACK_sdisna( char* job, lapack_int* m, lapack_int* n, const float* d, - float* sep, lapack_int *info ); -void LAPACK_ddisna( char* job, lapack_int* m, lapack_int* n, const double* d, - double* sep, lapack_int *info ); -void LAPACK_ssygst( lapack_int* itype, char* uplo, lapack_int* n, float* a, - lapack_int* lda, const float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_dsygst( lapack_int* itype, char* uplo, lapack_int* n, double* a, - lapack_int* lda, const double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_chegst( lapack_int* itype, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_zhegst( lapack_int* itype, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* b, lapack_int* ldb, - lapack_int *info ); -void LAPACK_sspgst( lapack_int* itype, char* uplo, lapack_int* n, float* ap, - const float* bp, lapack_int *info ); -void LAPACK_dspgst( lapack_int* itype, char* uplo, lapack_int* n, double* ap, - const double* bp, lapack_int *info ); -void LAPACK_chpgst( lapack_int* itype, char* uplo, lapack_int* n, - lapack_complex_float* ap, const lapack_complex_float* bp, - lapack_int *info ); -void LAPACK_zhpgst( lapack_int* itype, char* uplo, lapack_int* n, - lapack_complex_double* ap, const lapack_complex_double* bp, - lapack_int *info ); -void LAPACK_ssbgst( char* vect, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, float* ab, lapack_int* ldab, - const float* bb, lapack_int* ldbb, float* x, - lapack_int* ldx, float* work, lapack_int *info ); -void LAPACK_dsbgst( char* vect, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, double* ab, lapack_int* ldab, - const double* bb, lapack_int* ldbb, double* x, - lapack_int* ldx, double* work, lapack_int *info ); -void LAPACK_chbgst( char* vect, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, lapack_complex_float* ab, lapack_int* ldab, - const lapack_complex_float* bb, lapack_int* ldbb, - lapack_complex_float* x, lapack_int* ldx, - lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zhbgst( char* vect, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, lapack_complex_double* ab, lapack_int* ldab, - const lapack_complex_double* bb, lapack_int* ldbb, - lapack_complex_double* x, lapack_int* ldx, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_spbstf( char* uplo, lapack_int* n, lapack_int* kb, float* bb, - lapack_int* ldbb, lapack_int *info ); -void LAPACK_dpbstf( char* uplo, lapack_int* n, lapack_int* kb, double* bb, - lapack_int* ldbb, lapack_int *info ); -void LAPACK_cpbstf( char* uplo, lapack_int* n, lapack_int* kb, - lapack_complex_float* bb, lapack_int* ldbb, - lapack_int *info ); -void LAPACK_zpbstf( char* uplo, lapack_int* n, lapack_int* kb, - lapack_complex_double* bb, lapack_int* ldbb, - lapack_int *info ); -void LAPACK_sgehrd( lapack_int* n, lapack_int* ilo, lapack_int* ihi, float* a, - lapack_int* lda, float* tau, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dgehrd( lapack_int* n, lapack_int* ilo, lapack_int* ihi, double* a, - lapack_int* lda, double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cgehrd( lapack_int* n, lapack_int* ilo, lapack_int* ihi, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zgehrd( lapack_int* n, lapack_int* ilo, lapack_int* ihi, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* tau, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sorghr( lapack_int* n, lapack_int* ilo, lapack_int* ihi, float* a, - lapack_int* lda, const float* tau, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dorghr( lapack_int* n, lapack_int* ilo, lapack_int* ihi, double* a, - lapack_int* lda, const double* tau, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sormhr( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* ilo, lapack_int* ihi, const float* a, - lapack_int* lda, const float* tau, float* c, - lapack_int* ldc, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dormhr( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* ilo, lapack_int* ihi, const double* a, - lapack_int* lda, const double* tau, double* c, - lapack_int* ldc, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cunghr( lapack_int* n, lapack_int* ilo, lapack_int* ihi, - lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* tau, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zunghr( lapack_int* n, lapack_int* ilo, lapack_int* ihi, - lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cunmhr( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* ilo, lapack_int* ihi, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* tau, lapack_complex_float* c, - lapack_int* ldc, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zunmhr( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* ilo, lapack_int* ihi, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* tau, lapack_complex_double* c, - lapack_int* ldc, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sgebal( char* job, lapack_int* n, float* a, lapack_int* lda, - lapack_int* ilo, lapack_int* ihi, float* scale, - lapack_int *info ); -void LAPACK_dgebal( char* job, lapack_int* n, double* a, lapack_int* lda, - lapack_int* ilo, lapack_int* ihi, double* scale, - lapack_int *info ); -void LAPACK_cgebal( char* job, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* ilo, lapack_int* ihi, - float* scale, lapack_int *info ); -void LAPACK_zgebal( char* job, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* ilo, lapack_int* ihi, - double* scale, lapack_int *info ); -void LAPACK_sgebak( char* job, char* side, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, const float* scale, lapack_int* m, - float* v, lapack_int* ldv, lapack_int *info ); -void LAPACK_dgebak( char* job, char* side, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, const double* scale, lapack_int* m, - double* v, lapack_int* ldv, lapack_int *info ); -void LAPACK_cgebak( char* job, char* side, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, const float* scale, lapack_int* m, - lapack_complex_float* v, lapack_int* ldv, - lapack_int *info ); -void LAPACK_zgebak( char* job, char* side, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, const double* scale, lapack_int* m, - lapack_complex_double* v, lapack_int* ldv, - lapack_int *info ); -void LAPACK_shseqr( char* job, char* compz, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, float* h, lapack_int* ldh, float* wr, - float* wi, float* z, lapack_int* ldz, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dhseqr( char* job, char* compz, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, double* h, lapack_int* ldh, double* wr, - double* wi, double* z, lapack_int* ldz, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_chseqr( char* job, char* compz, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, lapack_complex_float* h, lapack_int* ldh, - lapack_complex_float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zhseqr( char* job, char* compz, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, lapack_complex_double* h, lapack_int* ldh, - lapack_complex_double* w, lapack_complex_double* z, - lapack_int* ldz, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_shsein( char* job, char* eigsrc, char* initv, - lapack_logical* select, lapack_int* n, const float* h, - lapack_int* ldh, float* wr, const float* wi, float* vl, - lapack_int* ldvl, float* vr, lapack_int* ldvr, - lapack_int* mm, lapack_int* m, float* work, - lapack_int* ifaill, lapack_int* ifailr, lapack_int *info ); -void LAPACK_dhsein( char* job, char* eigsrc, char* initv, - lapack_logical* select, lapack_int* n, const double* h, - lapack_int* ldh, double* wr, const double* wi, double* vl, - lapack_int* ldvl, double* vr, lapack_int* ldvr, - lapack_int* mm, lapack_int* m, double* work, - lapack_int* ifaill, lapack_int* ifailr, lapack_int *info ); -void LAPACK_chsein( char* job, char* eigsrc, char* initv, - const lapack_logical* select, lapack_int* n, - const lapack_complex_float* h, lapack_int* ldh, - lapack_complex_float* w, lapack_complex_float* vl, - lapack_int* ldvl, lapack_complex_float* vr, - lapack_int* ldvr, lapack_int* mm, lapack_int* m, - lapack_complex_float* work, float* rwork, - lapack_int* ifaill, lapack_int* ifailr, lapack_int *info ); -void LAPACK_zhsein( char* job, char* eigsrc, char* initv, - const lapack_logical* select, lapack_int* n, - const lapack_complex_double* h, lapack_int* ldh, - lapack_complex_double* w, lapack_complex_double* vl, - lapack_int* ldvl, lapack_complex_double* vr, - lapack_int* ldvr, lapack_int* mm, lapack_int* m, - lapack_complex_double* work, double* rwork, - lapack_int* ifaill, lapack_int* ifailr, lapack_int *info ); -void LAPACK_strevc( char* side, char* howmny, lapack_logical* select, - lapack_int* n, const float* t, lapack_int* ldt, float* vl, - lapack_int* ldvl, float* vr, lapack_int* ldvr, - lapack_int* mm, lapack_int* m, float* work, - lapack_int *info ); -void LAPACK_dtrevc( char* side, char* howmny, lapack_logical* select, - lapack_int* n, const double* t, lapack_int* ldt, double* vl, - lapack_int* ldvl, double* vr, lapack_int* ldvr, - lapack_int* mm, lapack_int* m, double* work, - lapack_int *info ); -void LAPACK_ctrevc( char* side, char* howmny, const lapack_logical* select, - lapack_int* n, lapack_complex_float* t, lapack_int* ldt, - lapack_complex_float* vl, lapack_int* ldvl, - lapack_complex_float* vr, lapack_int* ldvr, lapack_int* mm, - lapack_int* m, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_ztrevc( char* side, char* howmny, const lapack_logical* select, - lapack_int* n, lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* vl, lapack_int* ldvl, - lapack_complex_double* vr, lapack_int* ldvr, lapack_int* mm, - lapack_int* m, lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_strsna( char* job, char* howmny, const lapack_logical* select, - lapack_int* n, const float* t, lapack_int* ldt, - const float* vl, lapack_int* ldvl, const float* vr, - lapack_int* ldvr, float* s, float* sep, lapack_int* mm, - lapack_int* m, float* work, lapack_int* ldwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dtrsna( char* job, char* howmny, const lapack_logical* select, - lapack_int* n, const double* t, lapack_int* ldt, - const double* vl, lapack_int* ldvl, const double* vr, - lapack_int* ldvr, double* s, double* sep, lapack_int* mm, - lapack_int* m, double* work, lapack_int* ldwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_ctrsna( char* job, char* howmny, const lapack_logical* select, - lapack_int* n, const lapack_complex_float* t, - lapack_int* ldt, const lapack_complex_float* vl, - lapack_int* ldvl, const lapack_complex_float* vr, - lapack_int* ldvr, float* s, float* sep, lapack_int* mm, - lapack_int* m, lapack_complex_float* work, - lapack_int* ldwork, float* rwork, lapack_int *info ); -void LAPACK_ztrsna( char* job, char* howmny, const lapack_logical* select, - lapack_int* n, const lapack_complex_double* t, - lapack_int* ldt, const lapack_complex_double* vl, - lapack_int* ldvl, const lapack_complex_double* vr, - lapack_int* ldvr, double* s, double* sep, lapack_int* mm, - lapack_int* m, lapack_complex_double* work, - lapack_int* ldwork, double* rwork, lapack_int *info ); -void LAPACK_strexc( char* compq, lapack_int* n, float* t, lapack_int* ldt, - float* q, lapack_int* ldq, lapack_int* ifst, - lapack_int* ilst, float* work, lapack_int *info ); -void LAPACK_dtrexc( char* compq, lapack_int* n, double* t, lapack_int* ldt, - double* q, lapack_int* ldq, lapack_int* ifst, - lapack_int* ilst, double* work, lapack_int *info ); -void LAPACK_ctrexc( char* compq, lapack_int* n, lapack_complex_float* t, - lapack_int* ldt, lapack_complex_float* q, lapack_int* ldq, - lapack_int* ifst, lapack_int* ilst, lapack_int *info ); -void LAPACK_ztrexc( char* compq, lapack_int* n, lapack_complex_double* t, - lapack_int* ldt, lapack_complex_double* q, lapack_int* ldq, - lapack_int* ifst, lapack_int* ilst, lapack_int *info ); -void LAPACK_strsen( char* job, char* compq, const lapack_logical* select, - lapack_int* n, float* t, lapack_int* ldt, float* q, - lapack_int* ldq, float* wr, float* wi, lapack_int* m, - float* s, float* sep, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_dtrsen( char* job, char* compq, const lapack_logical* select, - lapack_int* n, double* t, lapack_int* ldt, double* q, - lapack_int* ldq, double* wr, double* wi, lapack_int* m, - double* s, double* sep, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_ctrsen( char* job, char* compq, const lapack_logical* select, - lapack_int* n, lapack_complex_float* t, lapack_int* ldt, - lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* w, lapack_int* m, float* s, - float* sep, lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_ztrsen( char* job, char* compq, const lapack_logical* select, - lapack_int* n, lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* w, lapack_int* m, double* s, - double* sep, lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_strsyl( char* trana, char* tranb, lapack_int* isgn, lapack_int* m, - lapack_int* n, const float* a, lapack_int* lda, - const float* b, lapack_int* ldb, float* c, lapack_int* ldc, - float* scale, lapack_int *info ); -void LAPACK_dtrsyl( char* trana, char* tranb, lapack_int* isgn, lapack_int* m, - lapack_int* n, const double* a, lapack_int* lda, - const double* b, lapack_int* ldb, double* c, - lapack_int* ldc, double* scale, lapack_int *info ); -void LAPACK_ctrsyl( char* trana, char* tranb, lapack_int* isgn, lapack_int* m, - lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* b, - lapack_int* ldb, lapack_complex_float* c, lapack_int* ldc, - float* scale, lapack_int *info ); -void LAPACK_ztrsyl( char* trana, char* tranb, lapack_int* isgn, lapack_int* m, - lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* b, - lapack_int* ldb, lapack_complex_double* c, lapack_int* ldc, - double* scale, lapack_int *info ); -void LAPACK_sgghrd( char* compq, char* compz, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, float* a, lapack_int* lda, float* b, - lapack_int* ldb, float* q, lapack_int* ldq, float* z, - lapack_int* ldz, lapack_int *info ); -void LAPACK_dgghrd( char* compq, char* compz, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, double* a, lapack_int* lda, double* b, - lapack_int* ldb, double* q, lapack_int* ldq, double* z, - lapack_int* ldz, lapack_int *info ); -void LAPACK_cgghrd( char* compq, char* compz, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* z, lapack_int* ldz, - lapack_int *info ); -void LAPACK_zgghrd( char* compq, char* compz, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* z, lapack_int* ldz, - lapack_int *info ); -void LAPACK_sggbal( char* job, lapack_int* n, float* a, lapack_int* lda, - float* b, lapack_int* ldb, lapack_int* ilo, lapack_int* ihi, - float* lscale, float* rscale, float* work, - lapack_int *info ); -void LAPACK_dggbal( char* job, lapack_int* n, double* a, lapack_int* lda, - double* b, lapack_int* ldb, lapack_int* ilo, - lapack_int* ihi, double* lscale, double* rscale, - double* work, lapack_int *info ); -void LAPACK_cggbal( char* job, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* b, lapack_int* ldb, - lapack_int* ilo, lapack_int* ihi, float* lscale, - float* rscale, float* work, lapack_int *info ); -void LAPACK_zggbal( char* job, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* b, lapack_int* ldb, - lapack_int* ilo, lapack_int* ihi, double* lscale, - double* rscale, double* work, lapack_int *info ); -void LAPACK_sggbak( char* job, char* side, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, const float* lscale, const float* rscale, - lapack_int* m, float* v, lapack_int* ldv, - lapack_int *info ); -void LAPACK_dggbak( char* job, char* side, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, const double* lscale, const double* rscale, - lapack_int* m, double* v, lapack_int* ldv, - lapack_int *info ); -void LAPACK_cggbak( char* job, char* side, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, const float* lscale, const float* rscale, - lapack_int* m, lapack_complex_float* v, lapack_int* ldv, - lapack_int *info ); -void LAPACK_zggbak( char* job, char* side, lapack_int* n, lapack_int* ilo, - lapack_int* ihi, const double* lscale, const double* rscale, - lapack_int* m, lapack_complex_double* v, lapack_int* ldv, - lapack_int *info ); -void LAPACK_shgeqz( char* job, char* compq, char* compz, lapack_int* n, - lapack_int* ilo, lapack_int* ihi, float* h, lapack_int* ldh, - float* t, lapack_int* ldt, float* alphar, float* alphai, - float* beta, float* q, lapack_int* ldq, float* z, - lapack_int* ldz, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dhgeqz( char* job, char* compq, char* compz, lapack_int* n, - lapack_int* ilo, lapack_int* ihi, double* h, - lapack_int* ldh, double* t, lapack_int* ldt, double* alphar, - double* alphai, double* beta, double* q, lapack_int* ldq, - double* z, lapack_int* ldz, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_chgeqz( char* job, char* compq, char* compz, lapack_int* n, - lapack_int* ilo, lapack_int* ihi, lapack_complex_float* h, - lapack_int* ldh, lapack_complex_float* t, lapack_int* ldt, - lapack_complex_float* alpha, lapack_complex_float* beta, - lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zhgeqz( char* job, char* compq, char* compz, lapack_int* n, - lapack_int* ilo, lapack_int* ihi, lapack_complex_double* h, - lapack_int* ldh, lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* alpha, lapack_complex_double* beta, - lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_stgevc( char* side, char* howmny, const lapack_logical* select, - lapack_int* n, const float* s, lapack_int* lds, - const float* p, lapack_int* ldp, float* vl, - lapack_int* ldvl, float* vr, lapack_int* ldvr, - lapack_int* mm, lapack_int* m, float* work, - lapack_int *info ); -void LAPACK_dtgevc( char* side, char* howmny, const lapack_logical* select, - lapack_int* n, const double* s, lapack_int* lds, - const double* p, lapack_int* ldp, double* vl, - lapack_int* ldvl, double* vr, lapack_int* ldvr, - lapack_int* mm, lapack_int* m, double* work, - lapack_int *info ); -void LAPACK_ctgevc( char* side, char* howmny, const lapack_logical* select, - lapack_int* n, const lapack_complex_float* s, - lapack_int* lds, const lapack_complex_float* p, - lapack_int* ldp, lapack_complex_float* vl, lapack_int* ldvl, - lapack_complex_float* vr, lapack_int* ldvr, lapack_int* mm, - lapack_int* m, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_ztgevc( char* side, char* howmny, const lapack_logical* select, - lapack_int* n, const lapack_complex_double* s, - lapack_int* lds, const lapack_complex_double* p, - lapack_int* ldp, lapack_complex_double* vl, - lapack_int* ldvl, lapack_complex_double* vr, - lapack_int* ldvr, lapack_int* mm, lapack_int* m, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_stgexc( lapack_logical* wantq, lapack_logical* wantz, lapack_int* n, - float* a, lapack_int* lda, float* b, lapack_int* ldb, - float* q, lapack_int* ldq, float* z, lapack_int* ldz, - lapack_int* ifst, lapack_int* ilst, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dtgexc( lapack_logical* wantq, lapack_logical* wantz, lapack_int* n, - double* a, lapack_int* lda, double* b, lapack_int* ldb, - double* q, lapack_int* ldq, double* z, lapack_int* ldz, - lapack_int* ifst, lapack_int* ilst, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_ctgexc( lapack_logical* wantq, lapack_logical* wantz, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* z, lapack_int* ldz, lapack_int* ifst, - lapack_int* ilst, lapack_int *info ); -void LAPACK_ztgexc( lapack_logical* wantq, lapack_logical* wantz, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* z, lapack_int* ldz, lapack_int* ifst, - lapack_int* ilst, lapack_int *info ); -void LAPACK_stgsen( lapack_int* ijob, lapack_logical* wantq, - lapack_logical* wantz, const lapack_logical* select, - lapack_int* n, float* a, lapack_int* lda, float* b, - lapack_int* ldb, float* alphar, float* alphai, float* beta, - float* q, lapack_int* ldq, float* z, lapack_int* ldz, - lapack_int* m, float* pl, float* pr, float* dif, - float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_dtgsen( lapack_int* ijob, lapack_logical* wantq, - lapack_logical* wantz, const lapack_logical* select, - lapack_int* n, double* a, lapack_int* lda, double* b, - lapack_int* ldb, double* alphar, double* alphai, - double* beta, double* q, lapack_int* ldq, double* z, - lapack_int* ldz, lapack_int* m, double* pl, double* pr, - double* dif, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_ctgsen( lapack_int* ijob, lapack_logical* wantq, - lapack_logical* wantz, const lapack_logical* select, - lapack_int* n, lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* alpha, lapack_complex_float* beta, - lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* z, lapack_int* ldz, lapack_int* m, - float* pl, float* pr, float* dif, - lapack_complex_float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_ztgsen( lapack_int* ijob, lapack_logical* wantq, - lapack_logical* wantz, const lapack_logical* select, - lapack_int* n, lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* alpha, lapack_complex_double* beta, - lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* z, lapack_int* ldz, lapack_int* m, - double* pl, double* pr, double* dif, - lapack_complex_double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_stgsyl( char* trans, lapack_int* ijob, lapack_int* m, lapack_int* n, - const float* a, lapack_int* lda, const float* b, - lapack_int* ldb, float* c, lapack_int* ldc, const float* d, - lapack_int* ldd, const float* e, lapack_int* lde, float* f, - lapack_int* ldf, float* scale, float* dif, float* work, - lapack_int* lwork, lapack_int* iwork, lapack_int *info ); -void LAPACK_dtgsyl( char* trans, lapack_int* ijob, lapack_int* m, lapack_int* n, - const double* a, lapack_int* lda, const double* b, - lapack_int* ldb, double* c, lapack_int* ldc, - const double* d, lapack_int* ldd, const double* e, - lapack_int* lde, double* f, lapack_int* ldf, double* scale, - double* dif, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_ctgsyl( char* trans, lapack_int* ijob, lapack_int* m, lapack_int* n, - const lapack_complex_float* a, lapack_int* lda, - const lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* c, lapack_int* ldc, - const lapack_complex_float* d, lapack_int* ldd, - const lapack_complex_float* e, lapack_int* lde, - lapack_complex_float* f, lapack_int* ldf, float* scale, - float* dif, lapack_complex_float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_ztgsyl( char* trans, lapack_int* ijob, lapack_int* m, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, - const lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* c, lapack_int* ldc, - const lapack_complex_double* d, lapack_int* ldd, - const lapack_complex_double* e, lapack_int* lde, - lapack_complex_double* f, lapack_int* ldf, double* scale, - double* dif, lapack_complex_double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_stgsna( char* job, char* howmny, const lapack_logical* select, - lapack_int* n, const float* a, lapack_int* lda, - const float* b, lapack_int* ldb, const float* vl, - lapack_int* ldvl, const float* vr, lapack_int* ldvr, - float* s, float* dif, lapack_int* mm, lapack_int* m, - float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dtgsna( char* job, char* howmny, const lapack_logical* select, - lapack_int* n, const double* a, lapack_int* lda, - const double* b, lapack_int* ldb, const double* vl, - lapack_int* ldvl, const double* vr, lapack_int* ldvr, - double* s, double* dif, lapack_int* mm, lapack_int* m, - double* work, lapack_int* lwork, lapack_int* iwork, - lapack_int *info ); -void LAPACK_ctgsna( char* job, char* howmny, const lapack_logical* select, - lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, const lapack_complex_float* b, - lapack_int* ldb, const lapack_complex_float* vl, - lapack_int* ldvl, const lapack_complex_float* vr, - lapack_int* ldvr, float* s, float* dif, lapack_int* mm, - lapack_int* m, lapack_complex_float* work, - lapack_int* lwork, lapack_int* iwork, lapack_int *info ); -void LAPACK_ztgsna( char* job, char* howmny, const lapack_logical* select, - lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, const lapack_complex_double* b, - lapack_int* ldb, const lapack_complex_double* vl, - lapack_int* ldvl, const lapack_complex_double* vr, - lapack_int* ldvr, double* s, double* dif, lapack_int* mm, - lapack_int* m, lapack_complex_double* work, - lapack_int* lwork, lapack_int* iwork, lapack_int *info ); -void LAPACK_sggsvp( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* p, lapack_int* n, float* a, lapack_int* lda, - float* b, lapack_int* ldb, float* tola, float* tolb, - lapack_int* k, lapack_int* l, float* u, lapack_int* ldu, - float* v, lapack_int* ldv, float* q, lapack_int* ldq, - lapack_int* iwork, float* tau, float* work, - lapack_int *info ); -void LAPACK_dggsvp( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* p, lapack_int* n, double* a, lapack_int* lda, - double* b, lapack_int* ldb, double* tola, double* tolb, - lapack_int* k, lapack_int* l, double* u, lapack_int* ldu, - double* v, lapack_int* ldv, double* q, lapack_int* ldq, - lapack_int* iwork, double* tau, double* work, - lapack_int *info ); -void LAPACK_cggsvp( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* p, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* b, lapack_int* ldb, - float* tola, float* tolb, lapack_int* k, lapack_int* l, - lapack_complex_float* u, lapack_int* ldu, - lapack_complex_float* v, lapack_int* ldv, - lapack_complex_float* q, lapack_int* ldq, lapack_int* iwork, - float* rwork, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zggsvp( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* p, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* b, lapack_int* ldb, - double* tola, double* tolb, lapack_int* k, lapack_int* l, - lapack_complex_double* u, lapack_int* ldu, - lapack_complex_double* v, lapack_int* ldv, - lapack_complex_double* q, lapack_int* ldq, - lapack_int* iwork, double* rwork, - lapack_complex_double* tau, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_stgsja( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* p, lapack_int* n, lapack_int* k, lapack_int* l, - float* a, lapack_int* lda, float* b, lapack_int* ldb, - float* tola, float* tolb, float* alpha, float* beta, - float* u, lapack_int* ldu, float* v, lapack_int* ldv, - float* q, lapack_int* ldq, float* work, lapack_int* ncycle, - lapack_int *info ); -void LAPACK_dtgsja( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* p, lapack_int* n, lapack_int* k, lapack_int* l, - double* a, lapack_int* lda, double* b, lapack_int* ldb, - double* tola, double* tolb, double* alpha, double* beta, - double* u, lapack_int* ldu, double* v, lapack_int* ldv, - double* q, lapack_int* ldq, double* work, - lapack_int* ncycle, lapack_int *info ); -void LAPACK_ctgsja( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* p, lapack_int* n, lapack_int* k, lapack_int* l, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, float* tola, - float* tolb, float* alpha, float* beta, - lapack_complex_float* u, lapack_int* ldu, - lapack_complex_float* v, lapack_int* ldv, - lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* work, lapack_int* ncycle, - lapack_int *info ); -void LAPACK_ztgsja( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* p, lapack_int* n, lapack_int* k, lapack_int* l, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, double* tola, - double* tolb, double* alpha, double* beta, - lapack_complex_double* u, lapack_int* ldu, - lapack_complex_double* v, lapack_int* ldv, - lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* work, lapack_int* ncycle, - lapack_int *info ); -void LAPACK_sgels( char* trans, lapack_int* m, lapack_int* n, lapack_int* nrhs, - float* a, lapack_int* lda, float* b, lapack_int* ldb, - float* work, lapack_int* lwork, lapack_int *info ); -void LAPACK_dgels( char* trans, lapack_int* m, lapack_int* n, lapack_int* nrhs, - double* a, lapack_int* lda, double* b, lapack_int* ldb, - double* work, lapack_int* lwork, lapack_int *info ); -void LAPACK_cgels( char* trans, lapack_int* m, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zgels( char* trans, lapack_int* m, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_sgelsy( lapack_int* m, lapack_int* n, lapack_int* nrhs, float* a, - lapack_int* lda, float* b, lapack_int* ldb, - lapack_int* jpvt, float* rcond, lapack_int* rank, - float* work, lapack_int* lwork, lapack_int *info ); -void LAPACK_dgelsy( lapack_int* m, lapack_int* n, lapack_int* nrhs, double* a, - lapack_int* lda, double* b, lapack_int* ldb, - lapack_int* jpvt, double* rcond, lapack_int* rank, - double* work, lapack_int* lwork, lapack_int *info ); -void LAPACK_cgelsy( lapack_int* m, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, lapack_int* jpvt, - float* rcond, lapack_int* rank, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_int *info ); -void LAPACK_zgelsy( lapack_int* m, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, lapack_int* jpvt, - double* rcond, lapack_int* rank, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_sgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs, float* a, - lapack_int* lda, float* b, lapack_int* ldb, float* s, - float* rcond, lapack_int* rank, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs, double* a, - lapack_int* lda, double* b, lapack_int* ldb, double* s, - double* rcond, lapack_int* rank, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, float* s, - float* rcond, lapack_int* rank, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_int *info ); -void LAPACK_zgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, double* s, - double* rcond, lapack_int* rank, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_sgelsd( lapack_int* m, lapack_int* n, lapack_int* nrhs, float* a, - lapack_int* lda, float* b, lapack_int* ldb, float* s, - float* rcond, lapack_int* rank, float* work, - lapack_int* lwork, lapack_int* iwork, lapack_int *info ); -void LAPACK_dgelsd( lapack_int* m, lapack_int* n, lapack_int* nrhs, double* a, - lapack_int* lda, double* b, lapack_int* ldb, double* s, - double* rcond, lapack_int* rank, double* work, - lapack_int* lwork, lapack_int* iwork, lapack_int *info ); -void LAPACK_cgelsd( lapack_int* m, lapack_int* n, lapack_int* nrhs, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, float* s, - float* rcond, lapack_int* rank, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_int* iwork, - lapack_int *info ); -void LAPACK_zgelsd( lapack_int* m, lapack_int* n, lapack_int* nrhs, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, double* s, - double* rcond, lapack_int* rank, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* iwork, lapack_int *info ); -void LAPACK_sgglse( lapack_int* m, lapack_int* n, lapack_int* p, float* a, - lapack_int* lda, float* b, lapack_int* ldb, float* c, - float* d, float* x, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dgglse( lapack_int* m, lapack_int* n, lapack_int* p, double* a, - lapack_int* lda, double* b, lapack_int* ldb, double* c, - double* d, double* x, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cgglse( lapack_int* m, lapack_int* n, lapack_int* p, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* c, lapack_complex_float* d, - lapack_complex_float* x, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zgglse( lapack_int* m, lapack_int* n, lapack_int* p, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* c, lapack_complex_double* d, - lapack_complex_double* x, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sggglm( lapack_int* n, lapack_int* m, lapack_int* p, float* a, - lapack_int* lda, float* b, lapack_int* ldb, float* d, - float* x, float* y, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dggglm( lapack_int* n, lapack_int* m, lapack_int* p, double* a, - lapack_int* lda, double* b, lapack_int* ldb, double* d, - double* x, double* y, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cggglm( lapack_int* n, lapack_int* m, lapack_int* p, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* d, lapack_complex_float* x, - lapack_complex_float* y, lapack_complex_float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_zggglm( lapack_int* n, lapack_int* m, lapack_int* p, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* d, lapack_complex_double* x, - lapack_complex_double* y, lapack_complex_double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_ssyev( char* jobz, char* uplo, lapack_int* n, float* a, - lapack_int* lda, float* w, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dsyev( char* jobz, char* uplo, lapack_int* n, double* a, - lapack_int* lda, double* w, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cheev( char* jobz, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, float* w, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zheev( char* jobz, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, double* w, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_ssyevd( char* jobz, char* uplo, lapack_int* n, float* a, - lapack_int* lda, float* w, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_dsyevd( char* jobz, char* uplo, lapack_int* n, double* a, - lapack_int* lda, double* w, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_cheevd( char* jobz, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, float* w, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_zheevd( char* jobz, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, double* w, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_ssyevx( char* jobz, char* range, char* uplo, lapack_int* n, - float* a, lapack_int* lda, float* vl, float* vu, - lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, float* z, lapack_int* ldz, - float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_dsyevx( char* jobz, char* range, char* uplo, lapack_int* n, - double* a, lapack_int* lda, double* vl, double* vu, - lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, double* z, lapack_int* ldz, - double* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_cheevx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, float* vl, - float* vu, lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_zheevx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, double* vl, - double* vu, lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, lapack_complex_double* z, - lapack_int* ldz, lapack_complex_double* work, - lapack_int* lwork, double* rwork, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_ssyevr( char* jobz, char* range, char* uplo, lapack_int* n, - float* a, lapack_int* lda, float* vl, float* vu, - lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, float* z, lapack_int* ldz, - lapack_int* isuppz, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_dsyevr( char* jobz, char* range, char* uplo, lapack_int* n, - double* a, lapack_int* lda, double* vl, double* vu, - lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, double* z, lapack_int* ldz, - lapack_int* isuppz, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_cheevr( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, float* vl, - float* vu, lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_int* isuppz, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_zheevr( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, double* vl, - double* vu, lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, lapack_complex_double* z, - lapack_int* ldz, lapack_int* isuppz, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_sspev( char* jobz, char* uplo, lapack_int* n, float* ap, float* w, - float* z, lapack_int* ldz, float* work, lapack_int *info ); -void LAPACK_dspev( char* jobz, char* uplo, lapack_int* n, double* ap, double* w, - double* z, lapack_int* ldz, double* work, lapack_int *info ); -void LAPACK_chpev( char* jobz, char* uplo, lapack_int* n, - lapack_complex_float* ap, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_complex_float* work, float* rwork, - lapack_int *info ); -void LAPACK_zhpev( char* jobz, char* uplo, lapack_int* n, - lapack_complex_double* ap, double* w, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sspevd( char* jobz, char* uplo, lapack_int* n, float* ap, float* w, - float* z, lapack_int* ldz, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_dspevd( char* jobz, char* uplo, lapack_int* n, double* ap, - double* w, double* z, lapack_int* ldz, double* work, - lapack_int* lwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_chpevd( char* jobz, char* uplo, lapack_int* n, - lapack_complex_float* ap, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_int* lrwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_zhpevd( char* jobz, char* uplo, lapack_int* n, - lapack_complex_double* ap, double* w, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_sspevx( char* jobz, char* range, char* uplo, lapack_int* n, - float* ap, float* vl, float* vu, lapack_int* il, - lapack_int* iu, float* abstol, lapack_int* m, float* w, - float* z, lapack_int* ldz, float* work, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_dspevx( char* jobz, char* range, char* uplo, lapack_int* n, - double* ap, double* vl, double* vu, lapack_int* il, - lapack_int* iu, double* abstol, lapack_int* m, double* w, - double* z, lapack_int* ldz, double* work, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_chpevx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_complex_float* ap, float* vl, float* vu, - lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_complex_float* work, float* rwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_zhpevx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_complex_double* ap, double* vl, double* vu, - lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, lapack_complex_double* z, - lapack_int* ldz, lapack_complex_double* work, double* rwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_ssbev( char* jobz, char* uplo, lapack_int* n, lapack_int* kd, - float* ab, lapack_int* ldab, float* w, float* z, - lapack_int* ldz, float* work, lapack_int *info ); -void LAPACK_dsbev( char* jobz, char* uplo, lapack_int* n, lapack_int* kd, - double* ab, lapack_int* ldab, double* w, double* z, - lapack_int* ldz, double* work, lapack_int *info ); -void LAPACK_chbev( char* jobz, char* uplo, lapack_int* n, lapack_int* kd, - lapack_complex_float* ab, lapack_int* ldab, float* w, - lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, float* rwork, lapack_int *info ); -void LAPACK_zhbev( char* jobz, char* uplo, lapack_int* n, lapack_int* kd, - lapack_complex_double* ab, lapack_int* ldab, double* w, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_ssbevd( char* jobz, char* uplo, lapack_int* n, lapack_int* kd, - float* ab, lapack_int* ldab, float* w, float* z, - lapack_int* ldz, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_dsbevd( char* jobz, char* uplo, lapack_int* n, lapack_int* kd, - double* ab, lapack_int* ldab, double* w, double* z, - lapack_int* ldz, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_chbevd( char* jobz, char* uplo, lapack_int* n, lapack_int* kd, - lapack_complex_float* ab, lapack_int* ldab, float* w, - lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_zhbevd( char* jobz, char* uplo, lapack_int* n, lapack_int* kd, - lapack_complex_double* ab, lapack_int* ldab, double* w, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_ssbevx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_int* kd, float* ab, lapack_int* ldab, float* q, - lapack_int* ldq, float* vl, float* vu, lapack_int* il, - lapack_int* iu, float* abstol, lapack_int* m, float* w, - float* z, lapack_int* ldz, float* work, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_dsbevx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_int* kd, double* ab, lapack_int* ldab, double* q, - lapack_int* ldq, double* vl, double* vu, lapack_int* il, - lapack_int* iu, double* abstol, lapack_int* m, double* w, - double* z, lapack_int* ldz, double* work, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_chbevx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_int* kd, lapack_complex_float* ab, lapack_int* ldab, - lapack_complex_float* q, lapack_int* ldq, float* vl, - float* vu, lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_complex_float* work, float* rwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_zhbevx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_int* kd, lapack_complex_double* ab, lapack_int* ldab, - lapack_complex_double* q, lapack_int* ldq, double* vl, - double* vu, lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, lapack_complex_double* z, - lapack_int* ldz, lapack_complex_double* work, double* rwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_sstev( char* jobz, lapack_int* n, float* d, float* e, float* z, - lapack_int* ldz, float* work, lapack_int *info ); -void LAPACK_dstev( char* jobz, lapack_int* n, double* d, double* e, double* z, - lapack_int* ldz, double* work, lapack_int *info ); -void LAPACK_sstevd( char* jobz, lapack_int* n, float* d, float* e, float* z, - lapack_int* ldz, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_dstevd( char* jobz, lapack_int* n, double* d, double* e, double* z, - lapack_int* ldz, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_sstevx( char* jobz, char* range, lapack_int* n, float* d, float* e, - float* vl, float* vu, lapack_int* il, lapack_int* iu, - float* abstol, lapack_int* m, float* w, float* z, - lapack_int* ldz, float* work, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_dstevx( char* jobz, char* range, lapack_int* n, double* d, - double* e, double* vl, double* vu, lapack_int* il, - lapack_int* iu, double* abstol, lapack_int* m, double* w, - double* z, lapack_int* ldz, double* work, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_sstevr( char* jobz, char* range, lapack_int* n, float* d, float* e, - float* vl, float* vu, lapack_int* il, lapack_int* iu, - float* abstol, lapack_int* m, float* w, float* z, - lapack_int* ldz, lapack_int* isuppz, float* work, - lapack_int* lwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_dstevr( char* jobz, char* range, lapack_int* n, double* d, - double* e, double* vl, double* vu, lapack_int* il, - lapack_int* iu, double* abstol, lapack_int* m, double* w, - double* z, lapack_int* ldz, lapack_int* isuppz, - double* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_sgees( char* jobvs, char* sort, LAPACK_S_SELECT2 select, - lapack_int* n, float* a, lapack_int* lda, lapack_int* sdim, - float* wr, float* wi, float* vs, lapack_int* ldvs, - float* work, lapack_int* lwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_dgees( char* jobvs, char* sort, LAPACK_D_SELECT2 select, - lapack_int* n, double* a, lapack_int* lda, lapack_int* sdim, - double* wr, double* wi, double* vs, lapack_int* ldvs, - double* work, lapack_int* lwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_cgees( char* jobvs, char* sort, LAPACK_C_SELECT1 select, - lapack_int* n, lapack_complex_float* a, lapack_int* lda, - lapack_int* sdim, lapack_complex_float* w, - lapack_complex_float* vs, lapack_int* ldvs, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_logical* bwork, lapack_int *info ); -void LAPACK_zgees( char* jobvs, char* sort, LAPACK_Z_SELECT1 select, - lapack_int* n, lapack_complex_double* a, lapack_int* lda, - lapack_int* sdim, lapack_complex_double* w, - lapack_complex_double* vs, lapack_int* ldvs, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_logical* bwork, lapack_int *info ); -void LAPACK_sgeesx( char* jobvs, char* sort, LAPACK_S_SELECT2 select, - char* sense, lapack_int* n, float* a, lapack_int* lda, - lapack_int* sdim, float* wr, float* wi, float* vs, - lapack_int* ldvs, float* rconde, float* rcondv, float* work, - lapack_int* lwork, lapack_int* iwork, lapack_int* liwork, - lapack_logical* bwork, lapack_int *info ); -void LAPACK_dgeesx( char* jobvs, char* sort, LAPACK_D_SELECT2 select, - char* sense, lapack_int* n, double* a, lapack_int* lda, - lapack_int* sdim, double* wr, double* wi, double* vs, - lapack_int* ldvs, double* rconde, double* rcondv, - double* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_cgeesx( char* jobvs, char* sort, LAPACK_C_SELECT1 select, - char* sense, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* sdim, lapack_complex_float* w, - lapack_complex_float* vs, lapack_int* ldvs, float* rconde, - float* rcondv, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_zgeesx( char* jobvs, char* sort, LAPACK_Z_SELECT1 select, - char* sense, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* sdim, lapack_complex_double* w, - lapack_complex_double* vs, lapack_int* ldvs, double* rconde, - double* rcondv, lapack_complex_double* work, - lapack_int* lwork, double* rwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_sgeev( char* jobvl, char* jobvr, lapack_int* n, float* a, - lapack_int* lda, float* wr, float* wi, float* vl, - lapack_int* ldvl, float* vr, lapack_int* ldvr, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dgeev( char* jobvl, char* jobvr, lapack_int* n, double* a, - lapack_int* lda, double* wr, double* wi, double* vl, - lapack_int* ldvl, double* vr, lapack_int* ldvr, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cgeev( char* jobvl, char* jobvr, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* w, lapack_complex_float* vl, - lapack_int* ldvl, lapack_complex_float* vr, lapack_int* ldvr, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zgeev( char* jobvl, char* jobvr, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* w, lapack_complex_double* vl, - lapack_int* ldvl, lapack_complex_double* vr, - lapack_int* ldvr, lapack_complex_double* work, - lapack_int* lwork, double* rwork, lapack_int *info ); -void LAPACK_sgeevx( char* balanc, char* jobvl, char* jobvr, char* sense, - lapack_int* n, float* a, lapack_int* lda, float* wr, - float* wi, float* vl, lapack_int* ldvl, float* vr, - lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi, - float* scale, float* abnrm, float* rconde, float* rcondv, - float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int *info ); -void LAPACK_dgeevx( char* balanc, char* jobvl, char* jobvr, char* sense, - lapack_int* n, double* a, lapack_int* lda, double* wr, - double* wi, double* vl, lapack_int* ldvl, double* vr, - lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi, - double* scale, double* abnrm, double* rconde, - double* rcondv, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_cgeevx( char* balanc, char* jobvl, char* jobvr, char* sense, - lapack_int* n, lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* w, lapack_complex_float* vl, - lapack_int* ldvl, lapack_complex_float* vr, - lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi, - float* scale, float* abnrm, float* rconde, float* rcondv, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zgeevx( char* balanc, char* jobvl, char* jobvr, char* sense, - lapack_int* n, lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* w, lapack_complex_double* vl, - lapack_int* ldvl, lapack_complex_double* vr, - lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi, - double* scale, double* abnrm, double* rconde, - double* rcondv, lapack_complex_double* work, - lapack_int* lwork, double* rwork, lapack_int *info ); -void LAPACK_sgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n, - float* a, lapack_int* lda, float* s, float* u, - lapack_int* ldu, float* vt, lapack_int* ldvt, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_dgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n, - double* a, lapack_int* lda, double* s, double* u, - lapack_int* ldu, double* vt, lapack_int* ldvt, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, float* s, - lapack_complex_float* u, lapack_int* ldu, - lapack_complex_float* vt, lapack_int* ldvt, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, double* s, - lapack_complex_double* u, lapack_int* ldu, - lapack_complex_double* vt, lapack_int* ldvt, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_sgesdd( char* jobz, lapack_int* m, lapack_int* n, float* a, - lapack_int* lda, float* s, float* u, lapack_int* ldu, - float* vt, lapack_int* ldvt, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dgesdd( char* jobz, lapack_int* m, lapack_int* n, double* a, - lapack_int* lda, double* s, double* u, lapack_int* ldu, - double* vt, lapack_int* ldvt, double* work, - lapack_int* lwork, lapack_int* iwork, lapack_int *info ); -void LAPACK_cgesdd( char* jobz, lapack_int* m, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, float* s, - lapack_complex_float* u, lapack_int* ldu, - lapack_complex_float* vt, lapack_int* ldvt, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_zgesdd( char* jobz, lapack_int* m, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, double* s, - lapack_complex_double* u, lapack_int* ldu, - lapack_complex_double* vt, lapack_int* ldvt, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* iwork, lapack_int *info ); -void LAPACK_dgejsv( char* joba, char* jobu, char* jobv, char* jobr, char* jobt, - char* jobp, lapack_int* m, lapack_int* n, double* a, - lapack_int* lda, double* sva, double* u, lapack_int* ldu, - double* v, lapack_int* ldv, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_sgejsv( char* joba, char* jobu, char* jobv, char* jobr, char* jobt, - char* jobp, lapack_int* m, lapack_int* n, float* a, - lapack_int* lda, float* sva, float* u, lapack_int* ldu, - float* v, lapack_int* ldv, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_dgesvj( char* joba, char* jobu, char* jobv, lapack_int* m, - lapack_int* n, double* a, lapack_int* lda, double* sva, - lapack_int* mv, double* v, lapack_int* ldv, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sgesvj( char* joba, char* jobu, char* jobv, lapack_int* m, - lapack_int* n, float* a, lapack_int* lda, float* sva, - lapack_int* mv, float* v, lapack_int* ldv, float* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_sggsvd( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* n, lapack_int* p, lapack_int* k, lapack_int* l, - float* a, lapack_int* lda, float* b, lapack_int* ldb, - float* alpha, float* beta, float* u, lapack_int* ldu, - float* v, lapack_int* ldv, float* q, lapack_int* ldq, - float* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_dggsvd( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* n, lapack_int* p, lapack_int* k, lapack_int* l, - double* a, lapack_int* lda, double* b, lapack_int* ldb, - double* alpha, double* beta, double* u, lapack_int* ldu, - double* v, lapack_int* ldv, double* q, lapack_int* ldq, - double* work, lapack_int* iwork, lapack_int *info ); -void LAPACK_cggsvd( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* n, lapack_int* p, lapack_int* k, lapack_int* l, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, float* alpha, - float* beta, lapack_complex_float* u, lapack_int* ldu, - lapack_complex_float* v, lapack_int* ldv, - lapack_complex_float* q, lapack_int* ldq, - lapack_complex_float* work, float* rwork, lapack_int* iwork, - lapack_int *info ); -void LAPACK_zggsvd( char* jobu, char* jobv, char* jobq, lapack_int* m, - lapack_int* n, lapack_int* p, lapack_int* k, lapack_int* l, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, double* alpha, - double* beta, lapack_complex_double* u, lapack_int* ldu, - lapack_complex_double* v, lapack_int* ldv, - lapack_complex_double* q, lapack_int* ldq, - lapack_complex_double* work, double* rwork, - lapack_int* iwork, lapack_int *info ); -void LAPACK_ssygv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - float* a, lapack_int* lda, float* b, lapack_int* ldb, - float* w, float* work, lapack_int* lwork, lapack_int *info ); -void LAPACK_dsygv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - double* a, lapack_int* lda, double* b, lapack_int* ldb, - double* w, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_chegv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, float* w, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zhegv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, double* w, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_ssygvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - float* a, lapack_int* lda, float* b, lapack_int* ldb, - float* w, float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_dsygvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - double* a, lapack_int* lda, double* b, lapack_int* ldb, - double* w, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_chegvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, float* w, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_zhegvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, double* w, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_ssygvx( lapack_int* itype, char* jobz, char* range, char* uplo, - lapack_int* n, float* a, lapack_int* lda, float* b, - lapack_int* ldb, float* vl, float* vu, lapack_int* il, - lapack_int* iu, float* abstol, lapack_int* m, float* w, - float* z, lapack_int* ldz, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_dsygvx( lapack_int* itype, char* jobz, char* range, char* uplo, - lapack_int* n, double* a, lapack_int* lda, double* b, - lapack_int* ldb, double* vl, double* vu, lapack_int* il, - lapack_int* iu, double* abstol, lapack_int* m, double* w, - double* z, lapack_int* ldz, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_chegvx( lapack_int* itype, char* jobz, char* range, char* uplo, - lapack_int* n, lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, float* vl, - float* vu, lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_zhegvx( lapack_int* itype, char* jobz, char* range, char* uplo, - lapack_int* n, lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, double* vl, - double* vu, lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, lapack_complex_double* z, - lapack_int* ldz, lapack_complex_double* work, - lapack_int* lwork, double* rwork, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_sspgv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - float* ap, float* bp, float* w, float* z, lapack_int* ldz, - float* work, lapack_int *info ); -void LAPACK_dspgv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - double* ap, double* bp, double* w, double* z, - lapack_int* ldz, double* work, lapack_int *info ); -void LAPACK_chpgv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - lapack_complex_float* ap, lapack_complex_float* bp, float* w, - lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, float* rwork, lapack_int *info ); -void LAPACK_zhpgv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - lapack_complex_double* ap, lapack_complex_double* bp, - double* w, lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_sspgvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - float* ap, float* bp, float* w, float* z, lapack_int* ldz, - float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_dspgvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - double* ap, double* bp, double* w, double* z, - lapack_int* ldz, double* work, lapack_int* lwork, - lapack_int* iwork, lapack_int* liwork, lapack_int *info ); -void LAPACK_chpgvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - lapack_complex_float* ap, lapack_complex_float* bp, - float* w, lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_zhpgvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n, - lapack_complex_double* ap, lapack_complex_double* bp, - double* w, lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_sspgvx( lapack_int* itype, char* jobz, char* range, char* uplo, - lapack_int* n, float* ap, float* bp, float* vl, float* vu, - lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, float* z, lapack_int* ldz, - float* work, lapack_int* iwork, lapack_int* ifail, - lapack_int *info ); -void LAPACK_dspgvx( lapack_int* itype, char* jobz, char* range, char* uplo, - lapack_int* n, double* ap, double* bp, double* vl, - double* vu, lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, double* z, lapack_int* ldz, - double* work, lapack_int* iwork, lapack_int* ifail, - lapack_int *info ); -void LAPACK_chpgvx( lapack_int* itype, char* jobz, char* range, char* uplo, - lapack_int* n, lapack_complex_float* ap, - lapack_complex_float* bp, float* vl, float* vu, - lapack_int* il, lapack_int* iu, float* abstol, - lapack_int* m, float* w, lapack_complex_float* z, - lapack_int* ldz, lapack_complex_float* work, float* rwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_zhpgvx( lapack_int* itype, char* jobz, char* range, char* uplo, - lapack_int* n, lapack_complex_double* ap, - lapack_complex_double* bp, double* vl, double* vu, - lapack_int* il, lapack_int* iu, double* abstol, - lapack_int* m, double* w, lapack_complex_double* z, - lapack_int* ldz, lapack_complex_double* work, double* rwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_ssbgv( char* jobz, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, float* ab, lapack_int* ldab, float* bb, - lapack_int* ldbb, float* w, float* z, lapack_int* ldz, - float* work, lapack_int *info ); -void LAPACK_dsbgv( char* jobz, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, double* ab, lapack_int* ldab, double* bb, - lapack_int* ldbb, double* w, double* z, lapack_int* ldz, - double* work, lapack_int *info ); -void LAPACK_chbgv( char* jobz, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, lapack_complex_float* ab, lapack_int* ldab, - lapack_complex_float* bb, lapack_int* ldbb, float* w, - lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, float* rwork, lapack_int *info ); -void LAPACK_zhbgv( char* jobz, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, lapack_complex_double* ab, lapack_int* ldab, - lapack_complex_double* bb, lapack_int* ldbb, double* w, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, double* rwork, - lapack_int *info ); -void LAPACK_ssbgvd( char* jobz, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, float* ab, lapack_int* ldab, float* bb, - lapack_int* ldbb, float* w, float* z, lapack_int* ldz, - float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_dsbgvd( char* jobz, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, double* ab, lapack_int* ldab, double* bb, - lapack_int* ldbb, double* w, double* z, lapack_int* ldz, - double* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_chbgvd( char* jobz, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, lapack_complex_float* ab, lapack_int* ldab, - lapack_complex_float* bb, lapack_int* ldbb, float* w, - lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, - lapack_int *info ); -void LAPACK_zhbgvd( char* jobz, char* uplo, lapack_int* n, lapack_int* ka, - lapack_int* kb, lapack_complex_double* ab, lapack_int* ldab, - lapack_complex_double* bb, lapack_int* ldbb, double* w, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, lapack_int* iwork, - lapack_int* liwork, lapack_int *info ); -void LAPACK_ssbgvx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_int* ka, lapack_int* kb, float* ab, lapack_int* ldab, - float* bb, lapack_int* ldbb, float* q, lapack_int* ldq, - float* vl, float* vu, lapack_int* il, lapack_int* iu, - float* abstol, lapack_int* m, float* w, float* z, - lapack_int* ldz, float* work, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_dsbgvx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_int* ka, lapack_int* kb, double* ab, - lapack_int* ldab, double* bb, lapack_int* ldbb, double* q, - lapack_int* ldq, double* vl, double* vu, lapack_int* il, - lapack_int* iu, double* abstol, lapack_int* m, double* w, - double* z, lapack_int* ldz, double* work, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_chbgvx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_int* ka, lapack_int* kb, lapack_complex_float* ab, - lapack_int* ldab, lapack_complex_float* bb, - lapack_int* ldbb, lapack_complex_float* q, lapack_int* ldq, - float* vl, float* vu, lapack_int* il, lapack_int* iu, - float* abstol, lapack_int* m, float* w, - lapack_complex_float* z, lapack_int* ldz, - lapack_complex_float* work, float* rwork, lapack_int* iwork, - lapack_int* ifail, lapack_int *info ); -void LAPACK_zhbgvx( char* jobz, char* range, char* uplo, lapack_int* n, - lapack_int* ka, lapack_int* kb, lapack_complex_double* ab, - lapack_int* ldab, lapack_complex_double* bb, - lapack_int* ldbb, lapack_complex_double* q, lapack_int* ldq, - double* vl, double* vu, lapack_int* il, lapack_int* iu, - double* abstol, lapack_int* m, double* w, - lapack_complex_double* z, lapack_int* ldz, - lapack_complex_double* work, double* rwork, - lapack_int* iwork, lapack_int* ifail, lapack_int *info ); -void LAPACK_sgges( char* jobvsl, char* jobvsr, char* sort, - LAPACK_S_SELECT3 selctg, lapack_int* n, float* a, - lapack_int* lda, float* b, lapack_int* ldb, lapack_int* sdim, - float* alphar, float* alphai, float* beta, float* vsl, - lapack_int* ldvsl, float* vsr, lapack_int* ldvsr, - float* work, lapack_int* lwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_dgges( char* jobvsl, char* jobvsr, char* sort, - LAPACK_D_SELECT3 selctg, lapack_int* n, double* a, - lapack_int* lda, double* b, lapack_int* ldb, - lapack_int* sdim, double* alphar, double* alphai, - double* beta, double* vsl, lapack_int* ldvsl, double* vsr, - lapack_int* ldvsr, double* work, lapack_int* lwork, - lapack_logical* bwork, lapack_int *info ); -void LAPACK_cgges( char* jobvsl, char* jobvsr, char* sort, - LAPACK_C_SELECT2 selctg, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, lapack_int* sdim, - lapack_complex_float* alpha, lapack_complex_float* beta, - lapack_complex_float* vsl, lapack_int* ldvsl, - lapack_complex_float* vsr, lapack_int* ldvsr, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_logical* bwork, lapack_int *info ); -void LAPACK_zgges( char* jobvsl, char* jobvsr, char* sort, - LAPACK_Z_SELECT2 selctg, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, lapack_int* sdim, - lapack_complex_double* alpha, lapack_complex_double* beta, - lapack_complex_double* vsl, lapack_int* ldvsl, - lapack_complex_double* vsr, lapack_int* ldvsr, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_logical* bwork, lapack_int *info ); -void LAPACK_sggesx( char* jobvsl, char* jobvsr, char* sort, - LAPACK_S_SELECT3 selctg, char* sense, lapack_int* n, - float* a, lapack_int* lda, float* b, lapack_int* ldb, - lapack_int* sdim, float* alphar, float* alphai, float* beta, - float* vsl, lapack_int* ldvsl, float* vsr, - lapack_int* ldvsr, float* rconde, float* rcondv, - float* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_dggesx( char* jobvsl, char* jobvsr, char* sort, - LAPACK_D_SELECT3 selctg, char* sense, lapack_int* n, - double* a, lapack_int* lda, double* b, lapack_int* ldb, - lapack_int* sdim, double* alphar, double* alphai, - double* beta, double* vsl, lapack_int* ldvsl, double* vsr, - lapack_int* ldvsr, double* rconde, double* rcondv, - double* work, lapack_int* lwork, lapack_int* iwork, - lapack_int* liwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_cggesx( char* jobvsl, char* jobvsr, char* sort, - LAPACK_C_SELECT2 selctg, char* sense, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, lapack_int* sdim, - lapack_complex_float* alpha, lapack_complex_float* beta, - lapack_complex_float* vsl, lapack_int* ldvsl, - lapack_complex_float* vsr, lapack_int* ldvsr, float* rconde, - float* rcondv, lapack_complex_float* work, - lapack_int* lwork, float* rwork, lapack_int* iwork, - lapack_int* liwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_zggesx( char* jobvsl, char* jobvsr, char* sort, - LAPACK_Z_SELECT2 selctg, char* sense, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, lapack_int* sdim, - lapack_complex_double* alpha, lapack_complex_double* beta, - lapack_complex_double* vsl, lapack_int* ldvsl, - lapack_complex_double* vsr, lapack_int* ldvsr, - double* rconde, double* rcondv, lapack_complex_double* work, - lapack_int* lwork, double* rwork, lapack_int* iwork, - lapack_int* liwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_sggev( char* jobvl, char* jobvr, lapack_int* n, float* a, - lapack_int* lda, float* b, lapack_int* ldb, float* alphar, - float* alphai, float* beta, float* vl, lapack_int* ldvl, - float* vr, lapack_int* ldvr, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dggev( char* jobvl, char* jobvr, lapack_int* n, double* a, - lapack_int* lda, double* b, lapack_int* ldb, double* alphar, - double* alphai, double* beta, double* vl, lapack_int* ldvl, - double* vr, lapack_int* ldvr, double* work, - lapack_int* lwork, lapack_int *info ); -void LAPACK_cggev( char* jobvl, char* jobvr, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* alpha, lapack_complex_float* beta, - lapack_complex_float* vl, lapack_int* ldvl, - lapack_complex_float* vr, lapack_int* ldvr, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int *info ); -void LAPACK_zggev( char* jobvl, char* jobvr, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* alpha, lapack_complex_double* beta, - lapack_complex_double* vl, lapack_int* ldvl, - lapack_complex_double* vr, lapack_int* ldvr, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int *info ); -void LAPACK_sggevx( char* balanc, char* jobvl, char* jobvr, char* sense, - lapack_int* n, float* a, lapack_int* lda, float* b, - lapack_int* ldb, float* alphar, float* alphai, float* beta, - float* vl, lapack_int* ldvl, float* vr, lapack_int* ldvr, - lapack_int* ilo, lapack_int* ihi, float* lscale, - float* rscale, float* abnrm, float* bbnrm, float* rconde, - float* rcondv, float* work, lapack_int* lwork, - lapack_int* iwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_dggevx( char* balanc, char* jobvl, char* jobvr, char* sense, - lapack_int* n, double* a, lapack_int* lda, double* b, - lapack_int* ldb, double* alphar, double* alphai, - double* beta, double* vl, lapack_int* ldvl, double* vr, - lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi, - double* lscale, double* rscale, double* abnrm, - double* bbnrm, double* rconde, double* rcondv, double* work, - lapack_int* lwork, lapack_int* iwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_cggevx( char* balanc, char* jobvl, char* jobvr, char* sense, - lapack_int* n, lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* alpha, lapack_complex_float* beta, - lapack_complex_float* vl, lapack_int* ldvl, - lapack_complex_float* vr, lapack_int* ldvr, lapack_int* ilo, - lapack_int* ihi, float* lscale, float* rscale, float* abnrm, - float* bbnrm, float* rconde, float* rcondv, - lapack_complex_float* work, lapack_int* lwork, float* rwork, - lapack_int* iwork, lapack_logical* bwork, - lapack_int *info ); -void LAPACK_zggevx( char* balanc, char* jobvl, char* jobvr, char* sense, - lapack_int* n, lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* alpha, lapack_complex_double* beta, - lapack_complex_double* vl, lapack_int* ldvl, - lapack_complex_double* vr, lapack_int* ldvr, - lapack_int* ilo, lapack_int* ihi, double* lscale, - double* rscale, double* abnrm, double* bbnrm, - double* rconde, double* rcondv, lapack_complex_double* work, - lapack_int* lwork, double* rwork, lapack_int* iwork, - lapack_logical* bwork, lapack_int *info ); -void LAPACK_dsfrk( char* transr, char* uplo, char* trans, lapack_int* n, - lapack_int* k, double* alpha, const double* a, - lapack_int* lda, double* beta, double* c ); -void LAPACK_ssfrk( char* transr, char* uplo, char* trans, lapack_int* n, - lapack_int* k, float* alpha, const float* a, lapack_int* lda, - float* beta, float* c ); -void LAPACK_zhfrk( char* transr, char* uplo, char* trans, lapack_int* n, - lapack_int* k, double* alpha, const lapack_complex_double* a, - lapack_int* lda, double* beta, lapack_complex_double* c ); -void LAPACK_chfrk( char* transr, char* uplo, char* trans, lapack_int* n, - lapack_int* k, float* alpha, const lapack_complex_float* a, - lapack_int* lda, float* beta, lapack_complex_float* c ); -void LAPACK_dtfsm( char* transr, char* side, char* uplo, char* trans, - char* diag, lapack_int* m, lapack_int* n, double* alpha, - const double* a, double* b, lapack_int* ldb ); -void LAPACK_stfsm( char* transr, char* side, char* uplo, char* trans, - char* diag, lapack_int* m, lapack_int* n, float* alpha, - const float* a, float* b, lapack_int* ldb ); -void LAPACK_ztfsm( char* transr, char* side, char* uplo, char* trans, - char* diag, lapack_int* m, lapack_int* n, - lapack_complex_double* alpha, const lapack_complex_double* a, - lapack_complex_double* b, lapack_int* ldb ); -void LAPACK_ctfsm( char* transr, char* side, char* uplo, char* trans, - char* diag, lapack_int* m, lapack_int* n, - lapack_complex_float* alpha, const lapack_complex_float* a, - lapack_complex_float* b, lapack_int* ldb ); -void LAPACK_dtfttp( char* transr, char* uplo, lapack_int* n, const double* arf, - double* ap, lapack_int *info ); -void LAPACK_stfttp( char* transr, char* uplo, lapack_int* n, const float* arf, - float* ap, lapack_int *info ); -void LAPACK_ztfttp( char* transr, char* uplo, lapack_int* n, - const lapack_complex_double* arf, lapack_complex_double* ap, - lapack_int *info ); -void LAPACK_ctfttp( char* transr, char* uplo, lapack_int* n, - const lapack_complex_float* arf, lapack_complex_float* ap, - lapack_int *info ); -void LAPACK_dtfttr( char* transr, char* uplo, lapack_int* n, const double* arf, - double* a, lapack_int* lda, lapack_int *info ); -void LAPACK_stfttr( char* transr, char* uplo, lapack_int* n, const float* arf, - float* a, lapack_int* lda, lapack_int *info ); -void LAPACK_ztfttr( char* transr, char* uplo, lapack_int* n, - const lapack_complex_double* arf, lapack_complex_double* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_ctfttr( char* transr, char* uplo, lapack_int* n, - const lapack_complex_float* arf, lapack_complex_float* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_dtpttf( char* transr, char* uplo, lapack_int* n, const double* ap, - double* arf, lapack_int *info ); -void LAPACK_stpttf( char* transr, char* uplo, lapack_int* n, const float* ap, - float* arf, lapack_int *info ); -void LAPACK_ztpttf( char* transr, char* uplo, lapack_int* n, - const lapack_complex_double* ap, lapack_complex_double* arf, - lapack_int *info ); -void LAPACK_ctpttf( char* transr, char* uplo, lapack_int* n, - const lapack_complex_float* ap, lapack_complex_float* arf, - lapack_int *info ); -void LAPACK_dtpttr( char* uplo, lapack_int* n, const double* ap, double* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_stpttr( char* uplo, lapack_int* n, const float* ap, float* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_ztpttr( char* uplo, lapack_int* n, const lapack_complex_double* ap, - lapack_complex_double* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_ctpttr( char* uplo, lapack_int* n, const lapack_complex_float* ap, - lapack_complex_float* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_dtrttf( char* transr, char* uplo, lapack_int* n, const double* a, - lapack_int* lda, double* arf, lapack_int *info ); -void LAPACK_strttf( char* transr, char* uplo, lapack_int* n, const float* a, - lapack_int* lda, float* arf, lapack_int *info ); -void LAPACK_ztrttf( char* transr, char* uplo, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* arf, lapack_int *info ); -void LAPACK_ctrttf( char* transr, char* uplo, lapack_int* n, - const lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* arf, lapack_int *info ); -void LAPACK_dtrttp( char* uplo, lapack_int* n, const double* a, lapack_int* lda, - double* ap, lapack_int *info ); -void LAPACK_strttp( char* uplo, lapack_int* n, const float* a, lapack_int* lda, - float* ap, lapack_int *info ); -void LAPACK_ztrttp( char* uplo, lapack_int* n, const lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* ap, - lapack_int *info ); -void LAPACK_ctrttp( char* uplo, lapack_int* n, const lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* ap, - lapack_int *info ); -void LAPACK_sgeqrfp( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* tau, float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_dgeqrfp( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* tau, double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_cgeqrfp( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_zgeqrfp( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int* lwork, - lapack_int *info ); -void LAPACK_clacgv( lapack_int* n, lapack_complex_float* x, lapack_int* incx ); -void LAPACK_zlacgv( lapack_int* n, lapack_complex_double* x, lapack_int* incx ); -void LAPACK_slarnv( lapack_int* idist, lapack_int* iseed, lapack_int* n, - float* x ); -void LAPACK_dlarnv( lapack_int* idist, lapack_int* iseed, lapack_int* n, - double* x ); -void LAPACK_clarnv( lapack_int* idist, lapack_int* iseed, lapack_int* n, - lapack_complex_float* x ); -void LAPACK_zlarnv( lapack_int* idist, lapack_int* iseed, lapack_int* n, - lapack_complex_double* x ); -void LAPACK_sgeqr2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* tau, float* work, lapack_int *info ); -void LAPACK_dgeqr2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* tau, double* work, lapack_int *info ); -void LAPACK_cgeqr2( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zgeqr2( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_slacpy( char* uplo, lapack_int* m, lapack_int* n, const float* a, - lapack_int* lda, float* b, lapack_int* ldb ); -void LAPACK_dlacpy( char* uplo, lapack_int* m, lapack_int* n, const double* a, - lapack_int* lda, double* b, lapack_int* ldb ); -void LAPACK_clacpy( char* uplo, lapack_int* m, lapack_int* n, - const lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb ); -void LAPACK_zlacpy( char* uplo, lapack_int* m, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb ); -void LAPACK_sgetf2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_dgetf2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - lapack_int* ipiv, lapack_int *info ); -void LAPACK_cgetf2( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int* ipiv, lapack_int *info ); -void LAPACK_zgetf2( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int* ipiv, lapack_int *info ); -void LAPACK_slaswp( lapack_int* n, float* a, lapack_int* lda, lapack_int* k1, - lapack_int* k2, const lapack_int* ipiv, lapack_int* incx ); -void LAPACK_dlaswp( lapack_int* n, double* a, lapack_int* lda, lapack_int* k1, - lapack_int* k2, const lapack_int* ipiv, lapack_int* incx ); -void LAPACK_claswp( lapack_int* n, lapack_complex_float* a, lapack_int* lda, - lapack_int* k1, lapack_int* k2, const lapack_int* ipiv, - lapack_int* incx ); -void LAPACK_zlaswp( lapack_int* n, lapack_complex_double* a, lapack_int* lda, - lapack_int* k1, lapack_int* k2, const lapack_int* ipiv, - lapack_int* incx ); -float LAPACK_slange( char* norm, lapack_int* m, lapack_int* n, const float* a, - lapack_int* lda, float* work ); -double LAPACK_dlange( char* norm, lapack_int* m, lapack_int* n, const double* a, - lapack_int* lda, double* work ); -float LAPACK_clange( char* norm, lapack_int* m, lapack_int* n, - const lapack_complex_float* a, lapack_int* lda, float* work ); -double LAPACK_zlange( char* norm, lapack_int* m, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, double* work ); -float LAPACK_clanhe( char* norm, char* uplo, lapack_int* n, - const lapack_complex_float* a, lapack_int* lda, float* work ); -double LAPACK_zlanhe( char* norm, char* uplo, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, double* work ); -float LAPACK_slansy( char* norm, char* uplo, lapack_int* n, const float* a, - lapack_int* lda, float* work ); -double LAPACK_dlansy( char* norm, char* uplo, lapack_int* n, const double* a, - lapack_int* lda, double* work ); -float LAPACK_clansy( char* norm, char* uplo, lapack_int* n, - const lapack_complex_float* a, lapack_int* lda, float* work ); -double LAPACK_zlansy( char* norm, char* uplo, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, double* work ); -float LAPACK_slantr( char* norm, char* uplo, char* diag, lapack_int* m, - lapack_int* n, const float* a, lapack_int* lda, float* work ); -double LAPACK_dlantr( char* norm, char* uplo, char* diag, lapack_int* m, - lapack_int* n, const double* a, lapack_int* lda, double* work ); -float LAPACK_clantr( char* norm, char* uplo, char* diag, lapack_int* m, - lapack_int* n, const lapack_complex_float* a, lapack_int* lda, - float* work ); -double LAPACK_zlantr( char* norm, char* uplo, char* diag, lapack_int* m, - lapack_int* n, const lapack_complex_double* a, lapack_int* lda, - double* work ); -float LAPACK_slamch( char* cmach ); -double LAPACK_dlamch( char* cmach ); -void LAPACK_sgelq2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* tau, float* work, lapack_int *info ); -void LAPACK_dgelq2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* tau, double* work, lapack_int *info ); -void LAPACK_cgelq2( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* tau, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zgelq2( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* tau, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_slarfb( char* side, char* trans, char* direct, char* storev, - lapack_int* m, lapack_int* n, lapack_int* k, const float* v, - lapack_int* ldv, const float* t, lapack_int* ldt, float* c, - lapack_int* ldc, float* work, lapack_int* ldwork ); -void LAPACK_dlarfb( char* side, char* trans, char* direct, char* storev, - lapack_int* m, lapack_int* n, lapack_int* k, - const double* v, lapack_int* ldv, const double* t, - lapack_int* ldt, double* c, lapack_int* ldc, double* work, - lapack_int* ldwork ); -void LAPACK_clarfb( char* side, char* trans, char* direct, char* storev, - lapack_int* m, lapack_int* n, lapack_int* k, - const lapack_complex_float* v, lapack_int* ldv, - const lapack_complex_float* t, lapack_int* ldt, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int* ldwork ); -void LAPACK_zlarfb( char* side, char* trans, char* direct, char* storev, - lapack_int* m, lapack_int* n, lapack_int* k, - const lapack_complex_double* v, lapack_int* ldv, - const lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work, lapack_int* ldwork ); -void LAPACK_slarfg( lapack_int* n, float* alpha, float* x, lapack_int* incx, - float* tau ); -void LAPACK_dlarfg( lapack_int* n, double* alpha, double* x, lapack_int* incx, - double* tau ); -void LAPACK_clarfg( lapack_int* n, lapack_complex_float* alpha, - lapack_complex_float* x, lapack_int* incx, - lapack_complex_float* tau ); -void LAPACK_zlarfg( lapack_int* n, lapack_complex_double* alpha, - lapack_complex_double* x, lapack_int* incx, - lapack_complex_double* tau ); -void LAPACK_slarft( char* direct, char* storev, lapack_int* n, lapack_int* k, - const float* v, lapack_int* ldv, const float* tau, float* t, - lapack_int* ldt ); -void LAPACK_dlarft( char* direct, char* storev, lapack_int* n, lapack_int* k, - const double* v, lapack_int* ldv, const double* tau, - double* t, lapack_int* ldt ); -void LAPACK_clarft( char* direct, char* storev, lapack_int* n, lapack_int* k, - const lapack_complex_float* v, lapack_int* ldv, - const lapack_complex_float* tau, lapack_complex_float* t, - lapack_int* ldt ); -void LAPACK_zlarft( char* direct, char* storev, lapack_int* n, lapack_int* k, - const lapack_complex_double* v, lapack_int* ldv, - const lapack_complex_double* tau, lapack_complex_double* t, - lapack_int* ldt ); -void LAPACK_slarfx( char* side, lapack_int* m, lapack_int* n, const float* v, - float* tau, float* c, lapack_int* ldc, float* work ); -void LAPACK_dlarfx( char* side, lapack_int* m, lapack_int* n, const double* v, - double* tau, double* c, lapack_int* ldc, double* work ); -void LAPACK_clarfx( char* side, lapack_int* m, lapack_int* n, - const lapack_complex_float* v, lapack_complex_float* tau, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work ); -void LAPACK_zlarfx( char* side, lapack_int* m, lapack_int* n, - const lapack_complex_double* v, lapack_complex_double* tau, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work ); -void LAPACK_slatms( lapack_int* m, lapack_int* n, char* dist, lapack_int* iseed, - char* sym, float* d, lapack_int* mode, float* cond, - float* dmax, lapack_int* kl, lapack_int* ku, char* pack, - float* a, lapack_int* lda, float* work, lapack_int *info ); -void LAPACK_dlatms( lapack_int* m, lapack_int* n, char* dist, lapack_int* iseed, - char* sym, double* d, lapack_int* mode, double* cond, - double* dmax, lapack_int* kl, lapack_int* ku, char* pack, - double* a, lapack_int* lda, double* work, - lapack_int *info ); -void LAPACK_clatms( lapack_int* m, lapack_int* n, char* dist, lapack_int* iseed, - char* sym, float* d, lapack_int* mode, float* cond, - float* dmax, lapack_int* kl, lapack_int* ku, char* pack, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zlatms( lapack_int* m, lapack_int* n, char* dist, lapack_int* iseed, - char* sym, double* d, lapack_int* mode, double* cond, - double* dmax, lapack_int* kl, lapack_int* ku, char* pack, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_slag2d( lapack_int* m, lapack_int* n, const float* sa, - lapack_int* ldsa, double* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_dlag2s( lapack_int* m, lapack_int* n, const double* a, - lapack_int* lda, float* sa, lapack_int* ldsa, - lapack_int *info ); -void LAPACK_clag2z( lapack_int* m, lapack_int* n, - const lapack_complex_float* sa, lapack_int* ldsa, - lapack_complex_double* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_zlag2c( lapack_int* m, lapack_int* n, - const lapack_complex_double* a, lapack_int* lda, - lapack_complex_float* sa, lapack_int* ldsa, - lapack_int *info ); -void LAPACK_slauum( char* uplo, lapack_int* n, float* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_dlauum( char* uplo, lapack_int* n, double* a, lapack_int* lda, - lapack_int *info ); -void LAPACK_clauum( char* uplo, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_zlauum( char* uplo, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_int *info ); -void LAPACK_slagge( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const float* d, float* a, lapack_int* lda, - lapack_int* iseed, float* work, lapack_int *info ); -void LAPACK_dlagge( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const double* d, double* a, lapack_int* lda, - lapack_int* iseed, double* work, lapack_int *info ); -void LAPACK_clagge( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const float* d, lapack_complex_float* a, - lapack_int* lda, lapack_int* iseed, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zlagge( lapack_int* m, lapack_int* n, lapack_int* kl, - lapack_int* ku, const double* d, lapack_complex_double* a, - lapack_int* lda, lapack_int* iseed, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_slaset( char* uplo, lapack_int* m, lapack_int* n, float* alpha, - float* beta, float* a, lapack_int* lda ); -void LAPACK_dlaset( char* uplo, lapack_int* m, lapack_int* n, double* alpha, - double* beta, double* a, lapack_int* lda ); -void LAPACK_claset( char* uplo, lapack_int* m, lapack_int* n, - lapack_complex_float* alpha, lapack_complex_float* beta, - lapack_complex_float* a, lapack_int* lda ); -void LAPACK_zlaset( char* uplo, lapack_int* m, lapack_int* n, - lapack_complex_double* alpha, lapack_complex_double* beta, - lapack_complex_double* a, lapack_int* lda ); -void LAPACK_slasrt( char* id, lapack_int* n, float* d, lapack_int *info ); -void LAPACK_dlasrt( char* id, lapack_int* n, double* d, lapack_int *info ); -void LAPACK_claghe( lapack_int* n, lapack_int* k, const float* d, - lapack_complex_float* a, lapack_int* lda, lapack_int* iseed, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zlaghe( lapack_int* n, lapack_int* k, const double* d, - lapack_complex_double* a, lapack_int* lda, - lapack_int* iseed, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_slagsy( lapack_int* n, lapack_int* k, const float* d, float* a, - lapack_int* lda, lapack_int* iseed, float* work, - lapack_int *info ); -void LAPACK_dlagsy( lapack_int* n, lapack_int* k, const double* d, double* a, - lapack_int* lda, lapack_int* iseed, double* work, - lapack_int *info ); -void LAPACK_clagsy( lapack_int* n, lapack_int* k, const float* d, - lapack_complex_float* a, lapack_int* lda, lapack_int* iseed, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zlagsy( lapack_int* n, lapack_int* k, const double* d, - lapack_complex_double* a, lapack_int* lda, - lapack_int* iseed, lapack_complex_double* work, - lapack_int *info ); -void LAPACK_slapmr( lapack_logical* forwrd, lapack_int* m, lapack_int* n, - float* x, lapack_int* ldx, lapack_int* k ); -void LAPACK_dlapmr( lapack_logical* forwrd, lapack_int* m, lapack_int* n, - double* x, lapack_int* ldx, lapack_int* k ); -void LAPACK_clapmr( lapack_logical* forwrd, lapack_int* m, lapack_int* n, - lapack_complex_float* x, lapack_int* ldx, lapack_int* k ); -void LAPACK_zlapmr( lapack_logical* forwrd, lapack_int* m, lapack_int* n, - lapack_complex_double* x, lapack_int* ldx, lapack_int* k ); -float LAPACK_slapy2( float* x, float* y ); -double LAPACK_dlapy2( double* x, double* y ); -float LAPACK_slapy3( float* x, float* y, float* z ); -double LAPACK_dlapy3( double* x, double* y, double* z ); -void LAPACK_slartgp( float* f, float* g, float* cs, float* sn, float* r ); -void LAPACK_dlartgp( double* f, double* g, double* cs, double* sn, double* r ); -void LAPACK_slartgs( float* x, float* y, float* sigma, float* cs, float* sn ); -void LAPACK_dlartgs( double* x, double* y, double* sigma, double* cs, - double* sn ); -// LAPACK 3.3.0 -void LAPACK_cbbcsd( char* jobu1, char* jobu2, - char* jobv1t, char* jobv2t, char* trans, - lapack_int* m, lapack_int* p, lapack_int* q, - float* theta, float* phi, - lapack_complex_float* u1, lapack_int* ldu1, - lapack_complex_float* u2, lapack_int* ldu2, - lapack_complex_float* v1t, lapack_int* ldv1t, - lapack_complex_float* v2t, lapack_int* ldv2t, - float* b11d, float* b11e, float* b12d, - float* b12e, float* b21d, float* b21e, - float* b22d, float* b22e, float* rwork, - lapack_int* lrwork , lapack_int *info ); -void LAPACK_cheswapr( char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* i1, - lapack_int* i2 ); -void LAPACK_chetri2( char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_chetri2x( char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int* nb , lapack_int *info ); -void LAPACK_chetrs2( char* uplo, lapack_int* n, - lapack_int* nrhs, const lapack_complex_float* a, - lapack_int* lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* work , lapack_int *info ); -void LAPACK_csyconv( char* uplo, char* way, - lapack_int* n, lapack_complex_float* a, - lapack_int* lda, const lapack_int* ipiv, - lapack_complex_float* work , lapack_int *info ); -void LAPACK_csyswapr( char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* i1, - lapack_int* i2 ); -void LAPACK_csytri2( char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_csytri2x( char* uplo, lapack_int* n, - lapack_complex_float* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int* nb , lapack_int *info ); -void LAPACK_csytrs2( char* uplo, lapack_int* n, - lapack_int* nrhs, const lapack_complex_float* a, - lapack_int* lda, const lapack_int* ipiv, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* work , lapack_int *info ); -void LAPACK_cunbdb( char* trans, char* signs, - lapack_int* m, lapack_int* p, lapack_int* q, - lapack_complex_float* x11, lapack_int* ldx11, - lapack_complex_float* x12, lapack_int* ldx12, - lapack_complex_float* x21, lapack_int* ldx21, - lapack_complex_float* x22, lapack_int* ldx22, - float* theta, float* phi, - lapack_complex_float* taup1, - lapack_complex_float* taup2, - lapack_complex_float* tauq1, - lapack_complex_float* tauq2, - lapack_complex_float* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_cuncsd( char* jobu1, char* jobu2, - char* jobv1t, char* jobv2t, char* trans, - char* signs, lapack_int* m, lapack_int* p, - lapack_int* q, lapack_complex_float* x11, - lapack_int* ldx11, lapack_complex_float* x12, - lapack_int* ldx12, lapack_complex_float* x21, - lapack_int* ldx21, lapack_complex_float* x22, - lapack_int* ldx22, float* theta, - lapack_complex_float* u1, lapack_int* ldu1, - lapack_complex_float* u2, lapack_int* ldu2, - lapack_complex_float* v1t, lapack_int* ldv1t, - lapack_complex_float* v2t, lapack_int* ldv2t, - lapack_complex_float* work, lapack_int* lwork, - float* rwork, lapack_int* lrwork, - lapack_int* iwork , lapack_int *info ); -void LAPACK_dbbcsd( char* jobu1, char* jobu2, - char* jobv1t, char* jobv2t, char* trans, - lapack_int* m, lapack_int* p, lapack_int* q, - double* theta, double* phi, double* u1, - lapack_int* ldu1, double* u2, lapack_int* ldu2, - double* v1t, lapack_int* ldv1t, double* v2t, - lapack_int* ldv2t, double* b11d, double* b11e, - double* b12d, double* b12e, double* b21d, - double* b21e, double* b22d, double* b22e, - double* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_dorbdb( char* trans, char* signs, - lapack_int* m, lapack_int* p, lapack_int* q, - double* x11, lapack_int* ldx11, double* x12, - lapack_int* ldx12, double* x21, lapack_int* ldx21, - double* x22, lapack_int* ldx22, double* theta, - double* phi, double* taup1, double* taup2, - double* tauq1, double* tauq2, double* work, - lapack_int* lwork , lapack_int *info ); -void LAPACK_dorcsd( char* jobu1, char* jobu2, - char* jobv1t, char* jobv2t, char* trans, - char* signs, lapack_int* m, lapack_int* p, - lapack_int* q, double* x11, lapack_int* ldx11, - double* x12, lapack_int* ldx12, double* x21, - lapack_int* ldx21, double* x22, lapack_int* ldx22, - double* theta, double* u1, lapack_int* ldu1, - double* u2, lapack_int* ldu2, double* v1t, - lapack_int* ldv1t, double* v2t, lapack_int* ldv2t, - double* work, lapack_int* lwork, - lapack_int* iwork , lapack_int *info ); -void LAPACK_dsyconv( char* uplo, char* way, - lapack_int* n, double* a, lapack_int* lda, - const lapack_int* ipiv, double* work , lapack_int *info ); -void LAPACK_dsyswapr( char* uplo, lapack_int* n, - double* a, lapack_int* i1, lapack_int* i2 ); -void LAPACK_dsytri2( char* uplo, lapack_int* n, - double* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_dsytri2x( char* uplo, lapack_int* n, - double* a, lapack_int* lda, - const lapack_int* ipiv, double* work, - lapack_int* nb , lapack_int *info ); -void LAPACK_dsytrs2( char* uplo, lapack_int* n, - lapack_int* nrhs, const double* a, - lapack_int* lda, const lapack_int* ipiv, - double* b, lapack_int* ldb, double* work , lapack_int *info ); -void LAPACK_sbbcsd( char* jobu1, char* jobu2, - char* jobv1t, char* jobv2t, char* trans, - lapack_int* m, lapack_int* p, lapack_int* q, - float* theta, float* phi, float* u1, - lapack_int* ldu1, float* u2, lapack_int* ldu2, - float* v1t, lapack_int* ldv1t, float* v2t, - lapack_int* ldv2t, float* b11d, float* b11e, - float* b12d, float* b12e, float* b21d, - float* b21e, float* b22d, float* b22e, - float* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_sorbdb( char* trans, char* signs, - lapack_int* m, lapack_int* p, lapack_int* q, - float* x11, lapack_int* ldx11, float* x12, - lapack_int* ldx12, float* x21, lapack_int* ldx21, - float* x22, lapack_int* ldx22, float* theta, - float* phi, float* taup1, float* taup2, - float* tauq1, float* tauq2, float* work, - lapack_int* lwork , lapack_int *info ); -void LAPACK_sorcsd( char* jobu1, char* jobu2, - char* jobv1t, char* jobv2t, char* trans, - char* signs, lapack_int* m, lapack_int* p, - lapack_int* q, float* x11, lapack_int* ldx11, - float* x12, lapack_int* ldx12, float* x21, - lapack_int* ldx21, float* x22, lapack_int* ldx22, - float* theta, float* u1, lapack_int* ldu1, - float* u2, lapack_int* ldu2, float* v1t, - lapack_int* ldv1t, float* v2t, lapack_int* ldv2t, - float* work, lapack_int* lwork, - lapack_int* iwork , lapack_int *info ); -void LAPACK_ssyconv( char* uplo, char* way, - lapack_int* n, float* a, lapack_int* lda, - const lapack_int* ipiv, float* work , lapack_int *info ); -void LAPACK_ssyswapr( char* uplo, lapack_int* n, - float* a, lapack_int* i1, lapack_int* i2 ); -void LAPACK_ssytri2( char* uplo, lapack_int* n, - float* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_float* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_ssytri2x( char* uplo, lapack_int* n, - float* a, lapack_int* lda, - const lapack_int* ipiv, float* work, - lapack_int* nb , lapack_int *info ); -void LAPACK_ssytrs2( char* uplo, lapack_int* n, - lapack_int* nrhs, const float* a, - lapack_int* lda, const lapack_int* ipiv, - float* b, lapack_int* ldb, float* work , lapack_int *info ); -void LAPACK_zbbcsd( char* jobu1, char* jobu2, - char* jobv1t, char* jobv2t, char* trans, - lapack_int* m, lapack_int* p, lapack_int* q, - double* theta, double* phi, - lapack_complex_double* u1, lapack_int* ldu1, - lapack_complex_double* u2, lapack_int* ldu2, - lapack_complex_double* v1t, lapack_int* ldv1t, - lapack_complex_double* v2t, lapack_int* ldv2t, - double* b11d, double* b11e, double* b12d, - double* b12e, double* b21d, double* b21e, - double* b22d, double* b22e, double* rwork, - lapack_int* lrwork , lapack_int *info ); -void LAPACK_zheswapr( char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* i1, - lapack_int* i2 ); -void LAPACK_zhetri2( char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_zhetri2x( char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int* nb , lapack_int *info ); -void LAPACK_zhetrs2( char* uplo, lapack_int* n, - lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* work , lapack_int *info ); -void LAPACK_zsyconv( char* uplo, char* way, - lapack_int* n, lapack_complex_double* a, - lapack_int* lda, const lapack_int* ipiv, - lapack_complex_double* work , lapack_int *info ); -void LAPACK_zsyswapr( char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* i1, - lapack_int* i2 ); -void LAPACK_zsytri2( char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_zsytri2x( char* uplo, lapack_int* n, - lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_double* work, lapack_int* nb , lapack_int *info ); -void LAPACK_zsytrs2( char* uplo, lapack_int* n, - lapack_int* nrhs, - const lapack_complex_double* a, lapack_int* lda, - const lapack_int* ipiv, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* work , lapack_int *info ); -void LAPACK_zunbdb( char* trans, char* signs, - lapack_int* m, lapack_int* p, lapack_int* q, - lapack_complex_double* x11, lapack_int* ldx11, - lapack_complex_double* x12, lapack_int* ldx12, - lapack_complex_double* x21, lapack_int* ldx21, - lapack_complex_double* x22, lapack_int* ldx22, - double* theta, double* phi, - lapack_complex_double* taup1, - lapack_complex_double* taup2, - lapack_complex_double* tauq1, - lapack_complex_double* tauq2, - lapack_complex_double* work, lapack_int* lwork , lapack_int *info ); -void LAPACK_zuncsd( char* jobu1, char* jobu2, - char* jobv1t, char* jobv2t, char* trans, - char* signs, lapack_int* m, lapack_int* p, - lapack_int* q, lapack_complex_double* x11, - lapack_int* ldx11, lapack_complex_double* x12, - lapack_int* ldx12, lapack_complex_double* x21, - lapack_int* ldx21, lapack_complex_double* x22, - lapack_int* ldx22, double* theta, - lapack_complex_double* u1, lapack_int* ldu1, - lapack_complex_double* u2, lapack_int* ldu2, - lapack_complex_double* v1t, lapack_int* ldv1t, - lapack_complex_double* v2t, lapack_int* ldv2t, - lapack_complex_double* work, lapack_int* lwork, - double* rwork, lapack_int* lrwork, - lapack_int* iwork , lapack_int *info ); -// LAPACK 3.4.0 -void LAPACK_sgemqrt( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* nb, const float* v, - lapack_int* ldv, const float* t, lapack_int* ldt, float* c, - lapack_int* ldc, float* work, lapack_int *info ); -void LAPACK_dgemqrt( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* nb, const double* v, - lapack_int* ldv, const double* t, lapack_int* ldt, - double* c, lapack_int* ldc, double* work, - lapack_int *info ); -void LAPACK_cgemqrt( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* nb, - const lapack_complex_float* v, lapack_int* ldv, - const lapack_complex_float* t, lapack_int* ldt, - lapack_complex_float* c, lapack_int* ldc, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zgemqrt( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* nb, - const lapack_complex_double* v, lapack_int* ldv, - const lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* c, lapack_int* ldc, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_sgeqrt( lapack_int* m, lapack_int* n, lapack_int* nb, float* a, - lapack_int* lda, float* t, lapack_int* ldt, float* work, - lapack_int *info ); -void LAPACK_dgeqrt( lapack_int* m, lapack_int* n, lapack_int* nb, double* a, - lapack_int* lda, double* t, lapack_int* ldt, double* work, - lapack_int *info ); -void LAPACK_cgeqrt( lapack_int* m, lapack_int* n, lapack_int* nb, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* t, lapack_int* ldt, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_zgeqrt( lapack_int* m, lapack_int* n, lapack_int* nb, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_sgeqrt2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* t, lapack_int* ldt, lapack_int *info ); -void LAPACK_dgeqrt2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* t, lapack_int* ldt, lapack_int *info ); -void LAPACK_cgeqrt2( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* t, lapack_int* ldt, - lapack_int *info ); -void LAPACK_zgeqrt2( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* t, lapack_int* ldt, - lapack_int *info ); -void LAPACK_sgeqrt3( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* t, lapack_int* ldt, lapack_int *info ); -void LAPACK_dgeqrt3( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* t, lapack_int* ldt, lapack_int *info ); -void LAPACK_cgeqrt3( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* t, lapack_int* ldt, - lapack_int *info ); -void LAPACK_zgeqrt3( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* t, lapack_int* ldt, - lapack_int *info ); -void LAPACK_stpmqrt( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* l, lapack_int* nb, - const float* v, lapack_int* ldv, const float* t, - lapack_int* ldt, float* a, lapack_int* lda, float* b, - lapack_int* ldb, float* work, lapack_int *info ); -void LAPACK_dtpmqrt( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* l, lapack_int* nb, - const double* v, lapack_int* ldv, const double* t, - lapack_int* ldt, double* a, lapack_int* lda, double* b, - lapack_int* ldb, double* work, lapack_int *info ); -void LAPACK_ctpmqrt( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* l, lapack_int* nb, - const lapack_complex_float* v, lapack_int* ldv, - const lapack_complex_float* t, lapack_int* ldt, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_ztpmqrt( char* side, char* trans, lapack_int* m, lapack_int* n, - lapack_int* k, lapack_int* l, lapack_int* nb, - const lapack_complex_double* v, lapack_int* ldv, - const lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_dtpqrt( lapack_int* m, lapack_int* n, lapack_int* l, lapack_int* nb, - double* a, lapack_int* lda, double* b, lapack_int* ldb, - double* t, lapack_int* ldt, double* work, - lapack_int *info ); -void LAPACK_ctpqrt( lapack_int* m, lapack_int* n, lapack_int* l, lapack_int* nb, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* t, lapack_complex_float* b, - lapack_int* ldb, lapack_int* ldt, - lapack_complex_float* work, lapack_int *info ); -void LAPACK_ztpqrt( lapack_int* m, lapack_int* n, lapack_int* l, lapack_int* nb, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* work, lapack_int *info ); -void LAPACK_stpqrt2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, - float* b, lapack_int* ldb, float* t, lapack_int* ldt, - lapack_int *info ); -void LAPACK_dtpqrt2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, - double* b, lapack_int* ldb, double* t, lapack_int* ldt, - lapack_int *info ); -void LAPACK_ctpqrt2( lapack_int* m, lapack_int* n, lapack_complex_float* a, - lapack_int* lda, lapack_complex_float* b, lapack_int* ldb, - lapack_complex_float* t, lapack_int* ldt, - lapack_int *info ); -void LAPACK_ztpqrt2( lapack_int* m, lapack_int* n, lapack_complex_double* a, - lapack_int* lda, lapack_complex_double* b, lapack_int* ldb, - lapack_complex_double* t, lapack_int* ldt, - lapack_int *info ); -void LAPACK_stprfb( char* side, char* trans, char* direct, char* storev, - lapack_int* m, lapack_int* n, lapack_int* k, lapack_int* l, - const float* v, lapack_int* ldv, const float* t, - lapack_int* ldt, float* a, lapack_int* lda, float* b, - lapack_int* ldb, const float* mywork, - lapack_int* myldwork ); -void LAPACK_dtprfb( char* side, char* trans, char* direct, char* storev, - lapack_int* m, lapack_int* n, lapack_int* k, lapack_int* l, - const double* v, lapack_int* ldv, const double* t, - lapack_int* ldt, double* a, lapack_int* lda, double* b, - lapack_int* ldb, const double* mywork, - lapack_int* myldwork ); -void LAPACK_ctprfb( char* side, char* trans, char* direct, char* storev, - lapack_int* m, lapack_int* n, lapack_int* k, lapack_int* l, - const lapack_complex_float* v, lapack_int* ldv, - const lapack_complex_float* t, lapack_int* ldt, - lapack_complex_float* a, lapack_int* lda, - lapack_complex_float* b, lapack_int* ldb, - const float* mywork, lapack_int* myldwork ); -void LAPACK_ztprfb( char* side, char* trans, char* direct, char* storev, - lapack_int* m, lapack_int* n, lapack_int* k, lapack_int* l, - const lapack_complex_double* v, lapack_int* ldv, - const lapack_complex_double* t, lapack_int* ldt, - lapack_complex_double* a, lapack_int* lda, - lapack_complex_double* b, lapack_int* ldb, - const double* mywork, lapack_int* myldwork ); -// LAPACK 3.X.X -void LAPACK_csyr( char* uplo, lapack_int* n, lapack_complex_float* alpha, - const lapack_complex_float* x, lapack_int* incx, - lapack_complex_float* a, lapack_int* lda ); -void LAPACK_zsyr( char* uplo, lapack_int* n, lapack_complex_double* alpha, - const lapack_complex_double* x, lapack_int* incx, - lapack_complex_double* a, lapack_int* lda ); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _LAPACKE_H_ */ - -#endif /* _MKL_LAPACKE_H_ */ diff --git a/external/eigen/include/eigen3/Eigen/src/misc/lapacke_mangling.h b/external/eigen/include/eigen3/Eigen/src/misc/lapacke_mangling.h deleted file mode 100644 index 6211fd14..00000000 --- a/external/eigen/include/eigen3/Eigen/src/misc/lapacke_mangling.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef LAPACK_HEADER_INCLUDED -#define LAPACK_HEADER_INCLUDED - -#ifndef LAPACK_GLOBAL -#if defined(LAPACK_GLOBAL_PATTERN_LC) || defined(ADD_) -#define LAPACK_GLOBAL(lcname,UCNAME) lcname##_ -#elif defined(LAPACK_GLOBAL_PATTERN_UC) || defined(UPPER) -#define LAPACK_GLOBAL(lcname,UCNAME) UCNAME -#elif defined(LAPACK_GLOBAL_PATTERN_MC) || defined(NOCHANGE) -#define LAPACK_GLOBAL(lcname,UCNAME) lcname -#else -#define LAPACK_GLOBAL(lcname,UCNAME) lcname##_ -#endif -#endif - -#endif - diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/ArrayCwiseBinaryOps.h b/external/eigen/include/eigen3/Eigen/src/plugins/ArrayCwiseBinaryOps.h deleted file mode 100644 index 8dce1ba9..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/ArrayCwiseBinaryOps.h +++ /dev/null @@ -1,332 +0,0 @@ - -/** \returns an expression of the coefficient wise product of \c *this and \a other - * - * \sa MatrixBase::cwiseProduct - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product) -operator*(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)(derived(), other.derived()); -} - -/** \returns an expression of the coefficient wise quotient of \c *this and \a other - * - * \sa MatrixBase::cwiseQuotient - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar,typename OtherDerived::Scalar>, const Derived, const OtherDerived> -operator/(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<internal::scalar_quotient_op<Scalar,typename OtherDerived::Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise min of \c *this and \a other - * - * Example: \include Cwise_min.cpp - * Output: \verbinclude Cwise_min.out - * - * \sa max() - */ -EIGEN_MAKE_CWISE_BINARY_OP(min,min) - -/** \returns an expression of the coefficient-wise min of \c *this and scalar \a other - * - * \sa max() - */ -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, - const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > -#ifdef EIGEN_PARSED_BY_DOXYGEN -min -#else -(min) -#endif -(const Scalar &other) const -{ - return (min)(Derived::PlainObject::Constant(rows(), cols(), other)); -} - -/** \returns an expression of the coefficient-wise max of \c *this and \a other - * - * Example: \include Cwise_max.cpp - * Output: \verbinclude Cwise_max.out - * - * \sa min() - */ -EIGEN_MAKE_CWISE_BINARY_OP(max,max) - -/** \returns an expression of the coefficient-wise max of \c *this and scalar \a other - * - * \sa min() - */ -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, - const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > -#ifdef EIGEN_PARSED_BY_DOXYGEN -max -#else -(max) -#endif -(const Scalar &other) const -{ - return (max)(Derived::PlainObject::Constant(rows(), cols(), other)); -} - -/** \returns an expression of the coefficient-wise power of \c *this to the given array of \a exponents. - * - * This function computes the coefficient-wise power. - * - * Example: \include Cwise_array_power_array.cpp - * Output: \verbinclude Cwise_array_power_array.out - */ -EIGEN_MAKE_CWISE_BINARY_OP(pow,pow) - -#ifndef EIGEN_PARSED_BY_DOXYGEN -EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(pow,pow) -#else -/** \returns an expression of the coefficients of \c *this rasied to the constant power \a exponent - * - * \tparam T is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression. - * - * This function computes the coefficient-wise power. The function MatrixBase::pow() in the - * unsupported module MatrixFunctions computes the matrix power. - * - * Example: \include Cwise_pow.cpp - * Output: \verbinclude Cwise_pow.out - * - * \sa ArrayBase::pow(ArrayBase), square(), cube(), exp(), log() - */ -template<typename T> -const CwiseBinaryOp<internal::scalar_pow_op<Scalar,T>,Derived,Constant<T> > pow(const T& exponent) const; -#endif - - -// TODO code generating macros could be moved to Macros.h and could include generation of documentation -#define EIGEN_MAKE_CWISE_COMP_OP(OP, COMPARATOR) \ -template<typename OtherDerived> \ -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, typename OtherDerived::Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived> \ -OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \ -{ \ - return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, typename OtherDerived::Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived>(derived(), other.derived()); \ -}\ -typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > Cmp ## COMPARATOR ## ReturnType; \ -typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar, internal::cmp_ ## COMPARATOR>, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject>, const Derived > RCmp ## COMPARATOR ## ReturnType; \ -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Cmp ## COMPARATOR ## ReturnType \ -OP(const Scalar& s) const { \ - return this->OP(Derived::PlainObject::Constant(rows(), cols(), s)); \ -} \ -EIGEN_DEVICE_FUNC friend EIGEN_STRONG_INLINE const RCmp ## COMPARATOR ## ReturnType \ -OP(const Scalar& s, const Derived& d) { \ - return Derived::PlainObject::Constant(d.rows(), d.cols(), s).OP(d); \ -} - -#define EIGEN_MAKE_CWISE_COMP_R_OP(OP, R_OP, RCOMPARATOR) \ -template<typename OtherDerived> \ -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<typename OtherDerived::Scalar, Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived> \ -OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \ -{ \ - return CwiseBinaryOp<internal::scalar_cmp_op<typename OtherDerived::Scalar, Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived>(other.derived(), derived()); \ -} \ -EIGEN_DEVICE_FUNC \ -inline const RCmp ## RCOMPARATOR ## ReturnType \ -OP(const Scalar& s) const { \ - return Derived::PlainObject::Constant(rows(), cols(), s).R_OP(*this); \ -} \ -friend inline const Cmp ## RCOMPARATOR ## ReturnType \ -OP(const Scalar& s, const Derived& d) { \ - return d.R_OP(Derived::PlainObject::Constant(d.rows(), d.cols(), s)); \ -} - - - -/** \returns an expression of the coefficient-wise \< operator of *this and \a other - * - * Example: \include Cwise_less.cpp - * Output: \verbinclude Cwise_less.out - * - * \sa all(), any(), operator>(), operator<=() - */ -EIGEN_MAKE_CWISE_COMP_OP(operator<, LT) - -/** \returns an expression of the coefficient-wise \<= operator of *this and \a other - * - * Example: \include Cwise_less_equal.cpp - * Output: \verbinclude Cwise_less_equal.out - * - * \sa all(), any(), operator>=(), operator<() - */ -EIGEN_MAKE_CWISE_COMP_OP(operator<=, LE) - -/** \returns an expression of the coefficient-wise \> operator of *this and \a other - * - * Example: \include Cwise_greater.cpp - * Output: \verbinclude Cwise_greater.out - * - * \sa all(), any(), operator>=(), operator<() - */ -EIGEN_MAKE_CWISE_COMP_R_OP(operator>, operator<, LT) - -/** \returns an expression of the coefficient-wise \>= operator of *this and \a other - * - * Example: \include Cwise_greater_equal.cpp - * Output: \verbinclude Cwise_greater_equal.out - * - * \sa all(), any(), operator>(), operator<=() - */ -EIGEN_MAKE_CWISE_COMP_R_OP(operator>=, operator<=, LE) - -/** \returns an expression of the coefficient-wise == operator of *this and \a other - * - * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. - * In order to check for equality between two vectors or matrices with floating-point coefficients, it is - * generally a far better idea to use a fuzzy comparison as provided by isApprox() and - * isMuchSmallerThan(). - * - * Example: \include Cwise_equal_equal.cpp - * Output: \verbinclude Cwise_equal_equal.out - * - * \sa all(), any(), isApprox(), isMuchSmallerThan() - */ -EIGEN_MAKE_CWISE_COMP_OP(operator==, EQ) - -/** \returns an expression of the coefficient-wise != operator of *this and \a other - * - * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. - * In order to check for equality between two vectors or matrices with floating-point coefficients, it is - * generally a far better idea to use a fuzzy comparison as provided by isApprox() and - * isMuchSmallerThan(). - * - * Example: \include Cwise_not_equal.cpp - * Output: \verbinclude Cwise_not_equal.out - * - * \sa all(), any(), isApprox(), isMuchSmallerThan() - */ -EIGEN_MAKE_CWISE_COMP_OP(operator!=, NEQ) - - -#undef EIGEN_MAKE_CWISE_COMP_OP -#undef EIGEN_MAKE_CWISE_COMP_R_OP - -// scalar addition -#ifndef EIGEN_PARSED_BY_DOXYGEN -EIGEN_MAKE_SCALAR_BINARY_OP(operator+,sum) -#else -/** \returns an expression of \c *this with each coeff incremented by the constant \a scalar - * - * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. - * - * Example: \include Cwise_plus.cpp - * Output: \verbinclude Cwise_plus.out - * - * \sa operator+=(), operator-() - */ -template<typename T> -const CwiseBinaryOp<internal::scalar_sum_op<Scalar,T>,Derived,Constant<T> > operator+(const T& scalar) const; -/** \returns an expression of \a expr with each coeff incremented by the constant \a scalar - * - * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. - */ -template<typename T> friend -const CwiseBinaryOp<internal::scalar_sum_op<T,Scalar>,Constant<T>,Derived> operator+(const T& scalar, const StorageBaseType& expr); -#endif - -#ifndef EIGEN_PARSED_BY_DOXYGEN -EIGEN_MAKE_SCALAR_BINARY_OP(operator-,difference) -#else -/** \returns an expression of \c *this with each coeff decremented by the constant \a scalar - * - * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. - * - * Example: \include Cwise_minus.cpp - * Output: \verbinclude Cwise_minus.out - * - * \sa operator+=(), operator-() - */ -template<typename T> -const CwiseBinaryOp<internal::scalar_difference_op<Scalar,T>,Derived,Constant<T> > operator-(const T& scalar) const; -/** \returns an expression of the constant matrix of value \a scalar decremented by the coefficients of \a expr - * - * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. - */ -template<typename T> friend -const CwiseBinaryOp<internal::scalar_difference_op<T,Scalar>,Constant<T>,Derived> operator-(const T& scalar, const StorageBaseType& expr); -#endif - - -#ifndef EIGEN_PARSED_BY_DOXYGEN - EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(operator/,quotient) -#else - /** - * \brief Component-wise division of the scalar \a s by array elements of \a a. - * - * \tparam Scalar is the scalar type of \a x. It must be compatible with the scalar type of the given array expression (\c Derived::Scalar). - */ - template<typename T> friend - inline const CwiseBinaryOp<internal::scalar_quotient_op<T,Scalar>,Constant<T>,Derived> - operator/(const T& s,const StorageBaseType& a); -#endif - -/** \returns an expression of the coefficient-wise ^ operator of *this and \a other - * - * \warning this operator is for expression of bool only. - * - * Example: \include Cwise_boolean_xor.cpp - * Output: \verbinclude Cwise_boolean_xor.out - * - * \sa operator&&(), select() - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -inline const CwiseBinaryOp<internal::scalar_boolean_xor_op, const Derived, const OtherDerived> -operator^(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value), - THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); - return CwiseBinaryOp<internal::scalar_boolean_xor_op, const Derived, const OtherDerived>(derived(),other.derived()); -} - -// NOTE disabled until we agree on argument order -#if 0 -/** \cpp11 \returns an expression of the coefficient-wise polygamma function. - * - * \specialfunctions_module - * - * It returns the \a n -th derivative of the digamma(psi) evaluated at \c *this. - * - * \warning Be careful with the order of the parameters: x.polygamma(n) is equivalent to polygamma(n,x) - * - * \sa Eigen::polygamma() - */ -template<typename DerivedN> -inline const CwiseBinaryOp<internal::scalar_polygamma_op<Scalar>, const DerivedN, const Derived> -polygamma(const EIGEN_CURRENT_STORAGE_BASE_CLASS<DerivedN> &n) const -{ - return CwiseBinaryOp<internal::scalar_polygamma_op<Scalar>, const DerivedN, const Derived>(n.derived(), this->derived()); -} -#endif - -/** \returns an expression of the coefficient-wise zeta function. - * - * \specialfunctions_module - * - * It returns the Riemann zeta function of two arguments \c *this and \a q: - * - * \param q is the shift, it must be > 0 - * - * \note *this is the exponent, it must be > 1. - * \note This function supports only float and double scalar types. To support other scalar types, the user has - * to provide implementations of zeta(T,T) for any scalar type T to be supported. - * - * This method is an alias for zeta(*this,q); - * - * \sa Eigen::zeta() - */ -template<typename DerivedQ> -inline const CwiseBinaryOp<internal::scalar_zeta_op<Scalar>, const Derived, const DerivedQ> -zeta(const EIGEN_CURRENT_STORAGE_BASE_CLASS<DerivedQ> &q) const -{ - return CwiseBinaryOp<internal::scalar_zeta_op<Scalar>, const Derived, const DerivedQ>(this->derived(), q.derived()); -} diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/ArrayCwiseUnaryOps.h b/external/eigen/include/eigen3/Eigen/src/plugins/ArrayCwiseUnaryOps.h deleted file mode 100644 index 59a4ee6a..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/ArrayCwiseUnaryOps.h +++ /dev/null @@ -1,644 +0,0 @@ - - -typedef CwiseUnaryOp<internal::scalar_abs_op<Scalar>, const Derived> AbsReturnType; -typedef CwiseUnaryOp<internal::scalar_arg_op<Scalar>, const Derived> ArgReturnType; -typedef CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const Derived> Abs2ReturnType; -typedef CwiseUnaryOp<internal::scalar_sqrt_op<Scalar>, const Derived> SqrtReturnType; -typedef CwiseUnaryOp<internal::scalar_rsqrt_op<Scalar>, const Derived> RsqrtReturnType; -typedef CwiseUnaryOp<internal::scalar_sign_op<Scalar>, const Derived> SignReturnType; -typedef CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived> InverseReturnType; -typedef CwiseUnaryOp<internal::scalar_boolean_not_op<Scalar>, const Derived> BooleanNotReturnType; - -typedef CwiseUnaryOp<internal::scalar_exp_op<Scalar>, const Derived> ExpReturnType; -typedef CwiseUnaryOp<internal::scalar_expm1_op<Scalar>, const Derived> Expm1ReturnType; -typedef CwiseUnaryOp<internal::scalar_log_op<Scalar>, const Derived> LogReturnType; -typedef CwiseUnaryOp<internal::scalar_log1p_op<Scalar>, const Derived> Log1pReturnType; -typedef CwiseUnaryOp<internal::scalar_log10_op<Scalar>, const Derived> Log10ReturnType; -typedef CwiseUnaryOp<internal::scalar_cos_op<Scalar>, const Derived> CosReturnType; -typedef CwiseUnaryOp<internal::scalar_sin_op<Scalar>, const Derived> SinReturnType; -typedef CwiseUnaryOp<internal::scalar_tan_op<Scalar>, const Derived> TanReturnType; -typedef CwiseUnaryOp<internal::scalar_acos_op<Scalar>, const Derived> AcosReturnType; -typedef CwiseUnaryOp<internal::scalar_asin_op<Scalar>, const Derived> AsinReturnType; -typedef CwiseUnaryOp<internal::scalar_atan_op<Scalar>, const Derived> AtanReturnType; -typedef CwiseUnaryOp<internal::scalar_tanh_op<Scalar>, const Derived> TanhReturnType; -typedef CwiseUnaryOp<internal::scalar_logistic_op<Scalar>, const Derived> LogisticReturnType; -typedef CwiseUnaryOp<internal::scalar_sinh_op<Scalar>, const Derived> SinhReturnType; -#if EIGEN_HAS_CXX11_MATH -typedef CwiseUnaryOp<internal::scalar_atanh_op<Scalar>, const Derived> AtanhReturnType; -typedef CwiseUnaryOp<internal::scalar_asinh_op<Scalar>, const Derived> AsinhReturnType; -typedef CwiseUnaryOp<internal::scalar_acosh_op<Scalar>, const Derived> AcoshReturnType; -#endif -typedef CwiseUnaryOp<internal::scalar_cosh_op<Scalar>, const Derived> CoshReturnType; -typedef CwiseUnaryOp<internal::scalar_square_op<Scalar>, const Derived> SquareReturnType; -typedef CwiseUnaryOp<internal::scalar_cube_op<Scalar>, const Derived> CubeReturnType; -typedef CwiseUnaryOp<internal::scalar_round_op<Scalar>, const Derived> RoundReturnType; -typedef CwiseUnaryOp<internal::scalar_rint_op<Scalar>, const Derived> RintReturnType; -typedef CwiseUnaryOp<internal::scalar_floor_op<Scalar>, const Derived> FloorReturnType; -typedef CwiseUnaryOp<internal::scalar_ceil_op<Scalar>, const Derived> CeilReturnType; -typedef CwiseUnaryOp<internal::scalar_isnan_op<Scalar>, const Derived> IsNaNReturnType; -typedef CwiseUnaryOp<internal::scalar_isinf_op<Scalar>, const Derived> IsInfReturnType; -typedef CwiseUnaryOp<internal::scalar_isfinite_op<Scalar>, const Derived> IsFiniteReturnType; - -/** \returns an expression of the coefficient-wise absolute value of \c *this - * - * Example: \include Cwise_abs.cpp - * Output: \verbinclude Cwise_abs.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_abs">Math functions</a>, abs2() - */ -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const AbsReturnType -abs() const -{ - return AbsReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise phase angle of \c *this - * - * Example: \include Cwise_arg.cpp - * Output: \verbinclude Cwise_arg.out - * - * \sa abs() - */ -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const ArgReturnType -arg() const -{ - return ArgReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise squared absolute value of \c *this - * - * Example: \include Cwise_abs2.cpp - * Output: \verbinclude Cwise_abs2.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_abs2">Math functions</a>, abs(), square() - */ -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const Abs2ReturnType -abs2() const -{ - return Abs2ReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise exponential of *this. - * - * This function computes the coefficient-wise exponential. The function MatrixBase::exp() in the - * unsupported module MatrixFunctions computes the matrix exponential. - * - * Example: \include Cwise_exp.cpp - * Output: \verbinclude Cwise_exp.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_exp">Math functions</a>, pow(), log(), sin(), cos() - */ -EIGEN_DEVICE_FUNC -inline const ExpReturnType -exp() const -{ - return ExpReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise exponential of *this minus 1. - * - * In exact arithmetic, \c x.expm1() is equivalent to \c x.exp() - 1, - * however, with finite precision, this function is much more accurate when \c x is close to zero. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_expm1">Math functions</a>, exp() - */ -EIGEN_DEVICE_FUNC -inline const Expm1ReturnType -expm1() const -{ - return Expm1ReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise logarithm of *this. - * - * This function computes the coefficient-wise logarithm. The function MatrixBase::log() in the - * unsupported module MatrixFunctions computes the matrix logarithm. - * - * Example: \include Cwise_log.cpp - * Output: \verbinclude Cwise_log.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log">Math functions</a>, log() - */ -EIGEN_DEVICE_FUNC -inline const LogReturnType -log() const -{ - return LogReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise logarithm of 1 plus \c *this. - * - * In exact arithmetic, \c x.log() is equivalent to \c (x+1).log(), - * however, with finite precision, this function is much more accurate when \c x is close to zero. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log1p">Math functions</a>, log() - */ -EIGEN_DEVICE_FUNC -inline const Log1pReturnType -log1p() const -{ - return Log1pReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise base-10 logarithm of *this. - * - * This function computes the coefficient-wise base-10 logarithm. - * - * Example: \include Cwise_log10.cpp - * Output: \verbinclude Cwise_log10.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log10">Math functions</a>, log() - */ -EIGEN_DEVICE_FUNC -inline const Log10ReturnType -log10() const -{ - return Log10ReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise square root of *this. - * - * This function computes the coefficient-wise square root. The function MatrixBase::sqrt() in the - * unsupported module MatrixFunctions computes the matrix square root. - * - * Example: \include Cwise_sqrt.cpp - * Output: \verbinclude Cwise_sqrt.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sqrt">Math functions</a>, pow(), square() - */ -EIGEN_DEVICE_FUNC -inline const SqrtReturnType -sqrt() const -{ - return SqrtReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise inverse square root of *this. - * - * This function computes the coefficient-wise inverse square root. - * - * Example: \include Cwise_sqrt.cpp - * Output: \verbinclude Cwise_sqrt.out - * - * \sa pow(), square() - */ -EIGEN_DEVICE_FUNC -inline const RsqrtReturnType -rsqrt() const -{ - return RsqrtReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise signum of *this. - * - * This function computes the coefficient-wise signum. - * - * Example: \include Cwise_sign.cpp - * Output: \verbinclude Cwise_sign.out - * - * \sa pow(), square() - */ -EIGEN_DEVICE_FUNC -inline const SignReturnType -sign() const -{ - return SignReturnType(derived()); -} - - -/** \returns an expression of the coefficient-wise cosine of *this. - * - * This function computes the coefficient-wise cosine. The function MatrixBase::cos() in the - * unsupported module MatrixFunctions computes the matrix cosine. - * - * Example: \include Cwise_cos.cpp - * Output: \verbinclude Cwise_cos.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cos">Math functions</a>, sin(), acos() - */ -EIGEN_DEVICE_FUNC -inline const CosReturnType -cos() const -{ - return CosReturnType(derived()); -} - - -/** \returns an expression of the coefficient-wise sine of *this. - * - * This function computes the coefficient-wise sine. The function MatrixBase::sin() in the - * unsupported module MatrixFunctions computes the matrix sine. - * - * Example: \include Cwise_sin.cpp - * Output: \verbinclude Cwise_sin.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sin">Math functions</a>, cos(), asin() - */ -EIGEN_DEVICE_FUNC -inline const SinReturnType -sin() const -{ - return SinReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise tan of *this. - * - * Example: \include Cwise_tan.cpp - * Output: \verbinclude Cwise_tan.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_tan">Math functions</a>, cos(), sin() - */ -EIGEN_DEVICE_FUNC -inline const TanReturnType -tan() const -{ - return TanReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise arc tan of *this. - * - * Example: \include Cwise_atan.cpp - * Output: \verbinclude Cwise_atan.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_atan">Math functions</a>, tan(), asin(), acos() - */ -EIGEN_DEVICE_FUNC -inline const AtanReturnType -atan() const -{ - return AtanReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise arc cosine of *this. - * - * Example: \include Cwise_acos.cpp - * Output: \verbinclude Cwise_acos.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_acos">Math functions</a>, cos(), asin() - */ -EIGEN_DEVICE_FUNC -inline const AcosReturnType -acos() const -{ - return AcosReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise arc sine of *this. - * - * Example: \include Cwise_asin.cpp - * Output: \verbinclude Cwise_asin.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_asin">Math functions</a>, sin(), acos() - */ -EIGEN_DEVICE_FUNC -inline const AsinReturnType -asin() const -{ - return AsinReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise hyperbolic tan of *this. - * - * Example: \include Cwise_tanh.cpp - * Output: \verbinclude Cwise_tanh.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_tanh">Math functions</a>, tan(), sinh(), cosh() - */ -EIGEN_DEVICE_FUNC -inline const TanhReturnType -tanh() const -{ - return TanhReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise hyperbolic sin of *this. - * - * Example: \include Cwise_sinh.cpp - * Output: \verbinclude Cwise_sinh.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sinh">Math functions</a>, sin(), tanh(), cosh() - */ -EIGEN_DEVICE_FUNC -inline const SinhReturnType -sinh() const -{ - return SinhReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise hyperbolic cos of *this. - * - * Example: \include Cwise_cosh.cpp - * Output: \verbinclude Cwise_cosh.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cosh">Math functions</a>, tanh(), sinh(), cosh() - */ -EIGEN_DEVICE_FUNC -inline const CoshReturnType -cosh() const -{ - return CoshReturnType(derived()); -} - -#if EIGEN_HAS_CXX11_MATH -/** \returns an expression of the coefficient-wise inverse hyperbolic tan of *this. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_atanh">Math functions</a>, atanh(), asinh(), acosh() - */ -EIGEN_DEVICE_FUNC -inline const AtanhReturnType -atanh() const -{ - return AtanhReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise inverse hyperbolic sin of *this. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_asinh">Math functions</a>, atanh(), asinh(), acosh() - */ -EIGEN_DEVICE_FUNC -inline const AsinhReturnType -asinh() const -{ - return AsinhReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise inverse hyperbolic cos of *this. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_acosh">Math functions</a>, atanh(), asinh(), acosh() - */ -EIGEN_DEVICE_FUNC -inline const AcoshReturnType -acosh() const -{ - return AcoshReturnType(derived()); -} -#endif - -/** \returns an expression of the coefficient-wise logistic of *this. - */ -EIGEN_DEVICE_FUNC -inline const LogisticReturnType -logistic() const -{ - return LogisticReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise inverse of *this. - * - * Example: \include Cwise_inverse.cpp - * Output: \verbinclude Cwise_inverse.out - * - * \sa operator/(), operator*() - */ -EIGEN_DEVICE_FUNC -inline const InverseReturnType -inverse() const -{ - return InverseReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise square of *this. - * - * Example: \include Cwise_square.cpp - * Output: \verbinclude Cwise_square.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_squareE">Math functions</a>, abs2(), cube(), pow() - */ -EIGEN_DEVICE_FUNC -inline const SquareReturnType -square() const -{ - return SquareReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise cube of *this. - * - * Example: \include Cwise_cube.cpp - * Output: \verbinclude Cwise_cube.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cube">Math functions</a>, square(), pow() - */ -EIGEN_DEVICE_FUNC -inline const CubeReturnType -cube() const -{ - return CubeReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise rint of *this. - * - * Example: \include Cwise_rint.cpp - * Output: \verbinclude Cwise_rint.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_rint">Math functions</a>, ceil(), floor() - */ -EIGEN_DEVICE_FUNC -inline const RintReturnType -rint() const -{ - return RintReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise round of *this. - * - * Example: \include Cwise_round.cpp - * Output: \verbinclude Cwise_round.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_round">Math functions</a>, ceil(), floor() - */ -EIGEN_DEVICE_FUNC -inline const RoundReturnType -round() const -{ - return RoundReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise floor of *this. - * - * Example: \include Cwise_floor.cpp - * Output: \verbinclude Cwise_floor.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_floor">Math functions</a>, ceil(), round() - */ -EIGEN_DEVICE_FUNC -inline const FloorReturnType -floor() const -{ - return FloorReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise ceil of *this. - * - * Example: \include Cwise_ceil.cpp - * Output: \verbinclude Cwise_ceil.out - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_ceil">Math functions</a>, floor(), round() - */ -EIGEN_DEVICE_FUNC -inline const CeilReturnType -ceil() const -{ - return CeilReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise isnan of *this. - * - * Example: \include Cwise_isNaN.cpp - * Output: \verbinclude Cwise_isNaN.out - * - * \sa isfinite(), isinf() - */ -EIGEN_DEVICE_FUNC -inline const IsNaNReturnType -isNaN() const -{ - return IsNaNReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise isinf of *this. - * - * Example: \include Cwise_isInf.cpp - * Output: \verbinclude Cwise_isInf.out - * - * \sa isnan(), isfinite() - */ -EIGEN_DEVICE_FUNC -inline const IsInfReturnType -isInf() const -{ - return IsInfReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise isfinite of *this. - * - * Example: \include Cwise_isFinite.cpp - * Output: \verbinclude Cwise_isFinite.out - * - * \sa isnan(), isinf() - */ -EIGEN_DEVICE_FUNC -inline const IsFiniteReturnType -isFinite() const -{ - return IsFiniteReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise ! operator of *this - * - * \warning this operator is for expression of bool only. - * - * Example: \include Cwise_boolean_not.cpp - * Output: \verbinclude Cwise_boolean_not.out - * - * \sa operator!=() - */ -EIGEN_DEVICE_FUNC -inline const BooleanNotReturnType -operator!() const -{ - EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value), - THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); - return BooleanNotReturnType(derived()); -} - - -// --- SpecialFunctions module --- - -typedef CwiseUnaryOp<internal::scalar_lgamma_op<Scalar>, const Derived> LgammaReturnType; -typedef CwiseUnaryOp<internal::scalar_digamma_op<Scalar>, const Derived> DigammaReturnType; -typedef CwiseUnaryOp<internal::scalar_erf_op<Scalar>, const Derived> ErfReturnType; -typedef CwiseUnaryOp<internal::scalar_erfc_op<Scalar>, const Derived> ErfcReturnType; -typedef CwiseUnaryOp<internal::scalar_ndtri_op<Scalar>, const Derived> NdtriReturnType; - -/** \cpp11 \returns an expression of the coefficient-wise ln(|gamma(*this)|). - * - * \specialfunctions_module - * - * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations of lgamma(T) for any scalar - * type T to be supported. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_lgamma">Math functions</a>, digamma() - */ -EIGEN_DEVICE_FUNC -inline const LgammaReturnType -lgamma() const -{ - return LgammaReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise digamma (psi, derivative of lgamma). - * - * \specialfunctions_module - * - * \note This function supports only float and double scalar types. To support other scalar types, - * the user has to provide implementations of digamma(T) for any scalar - * type T to be supported. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_digamma">Math functions</a>, Eigen::digamma(), Eigen::polygamma(), lgamma() - */ -EIGEN_DEVICE_FUNC -inline const DigammaReturnType -digamma() const -{ - return DigammaReturnType(derived()); -} - -/** \cpp11 \returns an expression of the coefficient-wise Gauss error - * function of *this. - * - * \specialfunctions_module - * - * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations of erf(T) for any scalar - * type T to be supported. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_erf">Math functions</a>, erfc() - */ -EIGEN_DEVICE_FUNC -inline const ErfReturnType -erf() const -{ - return ErfReturnType(derived()); -} - -/** \cpp11 \returns an expression of the coefficient-wise Complementary error - * function of *this. - * - * \specialfunctions_module - * - * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations of erfc(T) for any scalar - * type T to be supported. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_erfc">Math functions</a>, erf() - */ -EIGEN_DEVICE_FUNC -inline const ErfcReturnType -erfc() const -{ - return ErfcReturnType(derived()); -} - -/** \returns an expression of the coefficient-wise inverse of the CDF of the Normal distribution function - * function of *this. - * - * \specialfunctions_module - * - * In other words, considering `x = ndtri(y)`, it returns the argument, x, for which the area under the - * Gaussian probability density function (integrated from minus infinity to x) is equal to y. - * - * \note This function supports only float and double scalar types. To support other scalar types, - * the user has to provide implementations of ndtri(T) for any scalar type T to be supported. - * - * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_ndtri">Math functions</a> - */ -EIGEN_DEVICE_FUNC -inline const NdtriReturnType -ndtri() const -{ - return NdtriReturnType(derived()); -} diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/BlockMethods.h b/external/eigen/include/eigen3/Eigen/src/plugins/BlockMethods.h deleted file mode 100644 index 935a604b..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/BlockMethods.h +++ /dev/null @@ -1,1443 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -/// \internal expression type of a column */ -typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ColXpr; -typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ConstColXpr; -/// \internal expression type of a row */ -typedef Block<Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowXpr; -typedef const Block<const Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowXpr; -/// \internal expression type of a block of whole columns */ -typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ColsBlockXpr; -typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ConstColsBlockXpr; -/// \internal expression type of a block of whole rows */ -typedef Block<Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowsBlockXpr; -typedef const Block<const Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowsBlockXpr; -/// \internal expression type of a block of whole columns */ -template<int N> struct NColsBlockXpr { typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; }; -template<int N> struct ConstNColsBlockXpr { typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; }; -/// \internal expression type of a block of whole rows */ -template<int N> struct NRowsBlockXpr { typedef Block<Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; }; -template<int N> struct ConstNRowsBlockXpr { typedef const Block<const Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; }; -/// \internal expression of a block */ -typedef Block<Derived> BlockXpr; -typedef const Block<const Derived> ConstBlockXpr; -/// \internal expression of a block of fixed sizes */ -template<int Rows, int Cols> struct FixedBlockXpr { typedef Block<Derived,Rows,Cols> Type; }; -template<int Rows, int Cols> struct ConstFixedBlockXpr { typedef Block<const Derived,Rows,Cols> Type; }; - -typedef VectorBlock<Derived> SegmentReturnType; -typedef const VectorBlock<const Derived> ConstSegmentReturnType; -template<int Size> struct FixedSegmentReturnType { typedef VectorBlock<Derived, Size> Type; }; -template<int Size> struct ConstFixedSegmentReturnType { typedef const VectorBlock<const Derived, Size> Type; }; - -/// \internal inner-vector -typedef Block<Derived,IsRowMajor?1:Dynamic,IsRowMajor?Dynamic:1,true> InnerVectorReturnType; -typedef Block<const Derived,IsRowMajor?1:Dynamic,IsRowMajor?Dynamic:1,true> ConstInnerVectorReturnType; - -/// \internal set of inner-vectors -typedef Block<Derived,Dynamic,Dynamic,true> InnerVectorsReturnType; -typedef Block<const Derived,Dynamic,Dynamic,true> ConstInnerVectorsReturnType; - -#endif // not EIGEN_PARSED_BY_DOXYGEN - -/// \returns an expression of a block in \c *this with either dynamic or fixed sizes. -/// -/// \param startRow the first row in the block -/// \param startCol the first column in the block -/// \param blockRows number of rows in the block, specified at either run-time or compile-time -/// \param blockCols number of columns in the block, specified at either run-time or compile-time -/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index. -/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index. -/// -/// Example using runtime (aka dynamic) sizes: \include MatrixBase_block_int_int_int_int.cpp -/// Output: \verbinclude MatrixBase_block_int_int_int_int.out -/// -/// \newin{3.4}: -/// -/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. In the later case, \c n plays the role of a runtime fallback value in case \c N equals Eigen::Dynamic. -/// Here is an example with a fixed number of rows \c NRows and dynamic number of columns \c cols: -/// \code -/// mat.block(i,j,fix<NRows>,cols) -/// \endcode -/// -/// This function thus fully covers the features offered by the following overloads block<NRows,NCols>(Index, Index), -/// and block<NRows,NCols>(Index, Index, Index, Index) that are thus obsolete. Indeed, this generic version avoids -/// redundancy, it preserves the argument order, and prevents the need to rely on the template keyword in templated code. -/// -/// but with less redundancy and more consistency as it does not modify the argument order -/// and seamlessly enable hybrid fixed/dynamic sizes. -/// -/// \note Even in the case that the returned expression has dynamic size, in the case -/// when it is applied to a fixed-size matrix, it inherits a fixed maximal size, -/// which means that evaluating it does not cause a dynamic memory allocation. -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa class Block, fix, fix<N>(int) -/// -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -typename FixedBlockXpr<...,...>::Type -#endif -block(Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols) -{ - return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type( - derived(), startRow, startCol, internal::get_runtime_value(blockRows), internal::get_runtime_value(blockCols)); -} - -/// This is the const version of block(Index,Index,NRowsType,NColsType) -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -const typename ConstFixedBlockXpr<...,...>::Type -#endif -block(Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols) const -{ - return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type( - derived(), startRow, startCol, internal::get_runtime_value(blockRows), internal::get_runtime_value(blockCols)); -} - - - -/// \returns a expression of a top-right corner of \c *this with either dynamic or fixed sizes. -/// -/// \param cRows the number of rows in the corner -/// \param cCols the number of columns in the corner -/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index. -/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index. -/// -/// Example with dynamic sizes: \include MatrixBase_topRightCorner_int_int.cpp -/// Output: \verbinclude MatrixBase_topRightCorner_int_int.out -/// -/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -typename FixedBlockXpr<...,...>::Type -#endif -topRightCorner(NRowsType cRows, NColsType cCols) -{ - return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, cols() - internal::get_runtime_value(cCols), internal::get_runtime_value(cRows), internal::get_runtime_value(cCols)); -} - -/// This is the const version of topRightCorner(NRowsType, NColsType). -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -const typename ConstFixedBlockXpr<...,...>::Type -#endif -topRightCorner(NRowsType cRows, NColsType cCols) const -{ - return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, cols() - internal::get_runtime_value(cCols), internal::get_runtime_value(cRows), internal::get_runtime_value(cCols)); -} - -/// \returns an expression of a fixed-size top-right corner of \c *this. -/// -/// \tparam CRows the number of rows in the corner -/// \tparam CCols the number of columns in the corner -/// -/// Example: \include MatrixBase_template_int_int_topRightCorner.cpp -/// Output: \verbinclude MatrixBase_template_int_int_topRightCorner.out -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa class Block, block<int,int>(Index,Index) -/// -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<CRows,CCols>::Type topRightCorner() -{ - return typename FixedBlockXpr<CRows,CCols>::Type(derived(), 0, cols() - CCols); -} - -/// This is the const version of topRightCorner<int, int>(). -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<CRows,CCols>::Type topRightCorner() const -{ - return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), 0, cols() - CCols); -} - -/// \returns an expression of a top-right corner of \c *this. -/// -/// \tparam CRows number of rows in corner as specified at compile-time -/// \tparam CCols number of columns in corner as specified at compile-time -/// \param cRows number of rows in corner as specified at run-time -/// \param cCols number of columns in corner as specified at run-time -/// -/// This function is mainly useful for corners where the number of rows is specified at compile-time -/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time -/// information should not contradict. In other words, \a cRows should equal \a CRows unless -/// \a CRows is \a Dynamic, and the same for the number of columns. -/// -/// Example: \include MatrixBase_template_int_int_topRightCorner_int_int.cpp -/// Output: \verbinclude MatrixBase_template_int_int_topRightCorner_int_int.out -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa class Block -/// -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<CRows,CCols>::Type topRightCorner(Index cRows, Index cCols) -{ - return typename FixedBlockXpr<CRows,CCols>::Type(derived(), 0, cols() - cCols, cRows, cCols); -} - -/// This is the const version of topRightCorner<int, int>(Index, Index). -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<CRows,CCols>::Type topRightCorner(Index cRows, Index cCols) const -{ - return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), 0, cols() - cCols, cRows, cCols); -} - - - -/// \returns an expression of a top-left corner of \c *this with either dynamic or fixed sizes. -/// -/// \param cRows the number of rows in the corner -/// \param cCols the number of columns in the corner -/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index. -/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index. -/// -/// Example: \include MatrixBase_topLeftCorner_int_int.cpp -/// Output: \verbinclude MatrixBase_topLeftCorner_int_int.out -/// -/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -typename FixedBlockXpr<...,...>::Type -#endif -topLeftCorner(NRowsType cRows, NColsType cCols) -{ - return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, 0, internal::get_runtime_value(cRows), internal::get_runtime_value(cCols)); -} - -/// This is the const version of topLeftCorner(Index, Index). -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -const typename ConstFixedBlockXpr<...,...>::Type -#endif -topLeftCorner(NRowsType cRows, NColsType cCols) const -{ - return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, 0, internal::get_runtime_value(cRows), internal::get_runtime_value(cCols)); -} - -/// \returns an expression of a fixed-size top-left corner of \c *this. -/// -/// The template parameters CRows and CCols are the number of rows and columns in the corner. -/// -/// Example: \include MatrixBase_template_int_int_topLeftCorner.cpp -/// Output: \verbinclude MatrixBase_template_int_int_topLeftCorner.out -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<CRows,CCols>::Type topLeftCorner() -{ - return typename FixedBlockXpr<CRows,CCols>::Type(derived(), 0, 0); -} - -/// This is the const version of topLeftCorner<int, int>(). -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<CRows,CCols>::Type topLeftCorner() const -{ - return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), 0, 0); -} - -/// \returns an expression of a top-left corner of \c *this. -/// -/// \tparam CRows number of rows in corner as specified at compile-time -/// \tparam CCols number of columns in corner as specified at compile-time -/// \param cRows number of rows in corner as specified at run-time -/// \param cCols number of columns in corner as specified at run-time -/// -/// This function is mainly useful for corners where the number of rows is specified at compile-time -/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time -/// information should not contradict. In other words, \a cRows should equal \a CRows unless -/// \a CRows is \a Dynamic, and the same for the number of columns. -/// -/// Example: \include MatrixBase_template_int_int_topLeftCorner_int_int.cpp -/// Output: \verbinclude MatrixBase_template_int_int_topLeftCorner_int_int.out -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa class Block -/// -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<CRows,CCols>::Type topLeftCorner(Index cRows, Index cCols) -{ - return typename FixedBlockXpr<CRows,CCols>::Type(derived(), 0, 0, cRows, cCols); -} - -/// This is the const version of topLeftCorner<int, int>(Index, Index). -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<CRows,CCols>::Type topLeftCorner(Index cRows, Index cCols) const -{ - return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), 0, 0, cRows, cCols); -} - - - -/// \returns an expression of a bottom-right corner of \c *this with either dynamic or fixed sizes. -/// -/// \param cRows the number of rows in the corner -/// \param cCols the number of columns in the corner -/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index. -/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index. -/// -/// Example: \include MatrixBase_bottomRightCorner_int_int.cpp -/// Output: \verbinclude MatrixBase_bottomRightCorner_int_int.out -/// -/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -typename FixedBlockXpr<...,...>::Type -#endif -bottomRightCorner(NRowsType cRows, NColsType cCols) -{ - return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type - (derived(), rows() - internal::get_runtime_value(cRows), cols() - internal::get_runtime_value(cCols), - internal::get_runtime_value(cRows), internal::get_runtime_value(cCols)); -} - -/// This is the const version of bottomRightCorner(NRowsType, NColsType). -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -const typename ConstFixedBlockXpr<...,...>::Type -#endif -bottomRightCorner(NRowsType cRows, NColsType cCols) const -{ - return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type - (derived(), rows() - internal::get_runtime_value(cRows), cols() - internal::get_runtime_value(cCols), - internal::get_runtime_value(cRows), internal::get_runtime_value(cCols)); -} - -/// \returns an expression of a fixed-size bottom-right corner of \c *this. -/// -/// The template parameters CRows and CCols are the number of rows and columns in the corner. -/// -/// Example: \include MatrixBase_template_int_int_bottomRightCorner.cpp -/// Output: \verbinclude MatrixBase_template_int_int_bottomRightCorner.out -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<CRows,CCols>::Type bottomRightCorner() -{ - return typename FixedBlockXpr<CRows,CCols>::Type(derived(), rows() - CRows, cols() - CCols); -} - -/// This is the const version of bottomRightCorner<int, int>(). -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<CRows,CCols>::Type bottomRightCorner() const -{ - return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), rows() - CRows, cols() - CCols); -} - -/// \returns an expression of a bottom-right corner of \c *this. -/// -/// \tparam CRows number of rows in corner as specified at compile-time -/// \tparam CCols number of columns in corner as specified at compile-time -/// \param cRows number of rows in corner as specified at run-time -/// \param cCols number of columns in corner as specified at run-time -/// -/// This function is mainly useful for corners where the number of rows is specified at compile-time -/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time -/// information should not contradict. In other words, \a cRows should equal \a CRows unless -/// \a CRows is \a Dynamic, and the same for the number of columns. -/// -/// Example: \include MatrixBase_template_int_int_bottomRightCorner_int_int.cpp -/// Output: \verbinclude MatrixBase_template_int_int_bottomRightCorner_int_int.out -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa class Block -/// -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<CRows,CCols>::Type bottomRightCorner(Index cRows, Index cCols) -{ - return typename FixedBlockXpr<CRows,CCols>::Type(derived(), rows() - cRows, cols() - cCols, cRows, cCols); -} - -/// This is the const version of bottomRightCorner<int, int>(Index, Index). -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<CRows,CCols>::Type bottomRightCorner(Index cRows, Index cCols) const -{ - return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), rows() - cRows, cols() - cCols, cRows, cCols); -} - - - -/// \returns an expression of a bottom-left corner of \c *this with either dynamic or fixed sizes. -/// -/// \param cRows the number of rows in the corner -/// \param cCols the number of columns in the corner -/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index. -/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index. -/// -/// Example: \include MatrixBase_bottomLeftCorner_int_int.cpp -/// Output: \verbinclude MatrixBase_bottomLeftCorner_int_int.out -/// -/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -typename FixedBlockXpr<...,...>::Type -#endif -bottomLeftCorner(NRowsType cRows, NColsType cCols) -{ - return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type - (derived(), rows() - internal::get_runtime_value(cRows), 0, - internal::get_runtime_value(cRows), internal::get_runtime_value(cCols)); -} - -/// This is the const version of bottomLeftCorner(NRowsType, NColsType). -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type -#else -typename ConstFixedBlockXpr<...,...>::Type -#endif -bottomLeftCorner(NRowsType cRows, NColsType cCols) const -{ - return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type - (derived(), rows() - internal::get_runtime_value(cRows), 0, - internal::get_runtime_value(cRows), internal::get_runtime_value(cCols)); -} - -/// \returns an expression of a fixed-size bottom-left corner of \c *this. -/// -/// The template parameters CRows and CCols are the number of rows and columns in the corner. -/// -/// Example: \include MatrixBase_template_int_int_bottomLeftCorner.cpp -/// Output: \verbinclude MatrixBase_template_int_int_bottomLeftCorner.out -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<CRows,CCols>::Type bottomLeftCorner() -{ - return typename FixedBlockXpr<CRows,CCols>::Type(derived(), rows() - CRows, 0); -} - -/// This is the const version of bottomLeftCorner<int, int>(). -template<int CRows, int CCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<CRows,CCols>::Type bottomLeftCorner() const -{ - return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), rows() - CRows, 0); -} - -/// \returns an expression of a bottom-left corner of \c *this. -/// -/// \tparam CRows number of rows in corner as specified at compile-time -/// \tparam CCols number of columns in corner as specified at compile-time -/// \param cRows number of rows in corner as specified at run-time -/// \param cCols number of columns in corner as specified at run-time -/// -/// This function is mainly useful for corners where the number of rows is specified at compile-time -/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time -/// information should not contradict. In other words, \a cRows should equal \a CRows unless -/// \a CRows is \a Dynamic, and the same for the number of columns. -/// -/// Example: \include MatrixBase_template_int_int_bottomLeftCorner_int_int.cpp -/// Output: \verbinclude MatrixBase_template_int_int_bottomLeftCorner_int_int.out -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa class Block -/// -template<int CRows, int CCols> -EIGEN_STRONG_INLINE -typename FixedBlockXpr<CRows,CCols>::Type bottomLeftCorner(Index cRows, Index cCols) -{ - return typename FixedBlockXpr<CRows,CCols>::Type(derived(), rows() - cRows, 0, cRows, cCols); -} - -/// This is the const version of bottomLeftCorner<int, int>(Index, Index). -template<int CRows, int CCols> -EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<CRows,CCols>::Type bottomLeftCorner(Index cRows, Index cCols) const -{ - return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), rows() - cRows, 0, cRows, cCols); -} - - - -/// \returns a block consisting of the top rows of \c *this. -/// -/// \param n the number of rows in the block -/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index. -/// -/// Example: \include MatrixBase_topRows_int.cpp -/// Output: \verbinclude MatrixBase_topRows_int.out -/// -/// The number of rows \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NRowsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type -#else -typename NRowsBlockXpr<...>::Type -#endif -topRows(NRowsType n) -{ - return typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type - (derived(), 0, 0, internal::get_runtime_value(n), cols()); -} - -/// This is the const version of topRows(NRowsType). -template<typename NRowsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type -#else -const typename ConstNRowsBlockXpr<...>::Type -#endif -topRows(NRowsType n) const -{ - return typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type - (derived(), 0, 0, internal::get_runtime_value(n), cols()); -} - -/// \returns a block consisting of the top rows of \c *this. -/// -/// \tparam N the number of rows in the block as specified at compile-time -/// \param n the number of rows in the block as specified at run-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include MatrixBase_template_int_topRows.cpp -/// Output: \verbinclude MatrixBase_template_int_topRows.out -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename NRowsBlockXpr<N>::Type topRows(Index n = N) -{ - return typename NRowsBlockXpr<N>::Type(derived(), 0, 0, n, cols()); -} - -/// This is the const version of topRows<int>(). -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstNRowsBlockXpr<N>::Type topRows(Index n = N) const -{ - return typename ConstNRowsBlockXpr<N>::Type(derived(), 0, 0, n, cols()); -} - - - -/// \returns a block consisting of the bottom rows of \c *this. -/// -/// \param n the number of rows in the block -/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index. -/// -/// Example: \include MatrixBase_bottomRows_int.cpp -/// Output: \verbinclude MatrixBase_bottomRows_int.out -/// -/// The number of rows \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NRowsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type -#else -typename NRowsBlockXpr<...>::Type -#endif -bottomRows(NRowsType n) -{ - return typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type - (derived(), rows() - internal::get_runtime_value(n), 0, internal::get_runtime_value(n), cols()); -} - -/// This is the const version of bottomRows(NRowsType). -template<typename NRowsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type -#else -const typename ConstNRowsBlockXpr<...>::Type -#endif -bottomRows(NRowsType n) const -{ - return typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type - (derived(), rows() - internal::get_runtime_value(n), 0, internal::get_runtime_value(n), cols()); -} - -/// \returns a block consisting of the bottom rows of \c *this. -/// -/// \tparam N the number of rows in the block as specified at compile-time -/// \param n the number of rows in the block as specified at run-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include MatrixBase_template_int_bottomRows.cpp -/// Output: \verbinclude MatrixBase_template_int_bottomRows.out -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename NRowsBlockXpr<N>::Type bottomRows(Index n = N) -{ - return typename NRowsBlockXpr<N>::Type(derived(), rows() - n, 0, n, cols()); -} - -/// This is the const version of bottomRows<int>(). -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstNRowsBlockXpr<N>::Type bottomRows(Index n = N) const -{ - return typename ConstNRowsBlockXpr<N>::Type(derived(), rows() - n, 0, n, cols()); -} - - - -/// \returns a block consisting of a range of rows of \c *this. -/// -/// \param startRow the index of the first row in the block -/// \param n the number of rows in the block -/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index. -/// -/// Example: \include DenseBase_middleRows_int.cpp -/// Output: \verbinclude DenseBase_middleRows_int.out -/// -/// The number of rows \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NRowsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type -#else -typename NRowsBlockXpr<...>::Type -#endif -middleRows(Index startRow, NRowsType n) -{ - return typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type - (derived(), startRow, 0, internal::get_runtime_value(n), cols()); -} - -/// This is the const version of middleRows(Index,NRowsType). -template<typename NRowsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type -#else -const typename ConstNRowsBlockXpr<...>::Type -#endif -middleRows(Index startRow, NRowsType n) const -{ - return typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type - (derived(), startRow, 0, internal::get_runtime_value(n), cols()); -} - -/// \returns a block consisting of a range of rows of \c *this. -/// -/// \tparam N the number of rows in the block as specified at compile-time -/// \param startRow the index of the first row in the block -/// \param n the number of rows in the block as specified at run-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include DenseBase_template_int_middleRows.cpp -/// Output: \verbinclude DenseBase_template_int_middleRows.out -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename NRowsBlockXpr<N>::Type middleRows(Index startRow, Index n = N) -{ - return typename NRowsBlockXpr<N>::Type(derived(), startRow, 0, n, cols()); -} - -/// This is the const version of middleRows<int>(). -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstNRowsBlockXpr<N>::Type middleRows(Index startRow, Index n = N) const -{ - return typename ConstNRowsBlockXpr<N>::Type(derived(), startRow, 0, n, cols()); -} - - - -/// \returns a block consisting of the left columns of \c *this. -/// -/// \param n the number of columns in the block -/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index. -/// -/// Example: \include MatrixBase_leftCols_int.cpp -/// Output: \verbinclude MatrixBase_leftCols_int.out -/// -/// The number of columns \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type -#else -typename NColsBlockXpr<...>::Type -#endif -leftCols(NColsType n) -{ - return typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, 0, rows(), internal::get_runtime_value(n)); -} - -/// This is the const version of leftCols(NColsType). -template<typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type -#else -const typename ConstNColsBlockXpr<...>::Type -#endif -leftCols(NColsType n) const -{ - return typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, 0, rows(), internal::get_runtime_value(n)); -} - -/// \returns a block consisting of the left columns of \c *this. -/// -/// \tparam N the number of columns in the block as specified at compile-time -/// \param n the number of columns in the block as specified at run-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include MatrixBase_template_int_leftCols.cpp -/// Output: \verbinclude MatrixBase_template_int_leftCols.out -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename NColsBlockXpr<N>::Type leftCols(Index n = N) -{ - return typename NColsBlockXpr<N>::Type(derived(), 0, 0, rows(), n); -} - -/// This is the const version of leftCols<int>(). -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstNColsBlockXpr<N>::Type leftCols(Index n = N) const -{ - return typename ConstNColsBlockXpr<N>::Type(derived(), 0, 0, rows(), n); -} - - - -/// \returns a block consisting of the right columns of \c *this. -/// -/// \param n the number of columns in the block -/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index. -/// -/// Example: \include MatrixBase_rightCols_int.cpp -/// Output: \verbinclude MatrixBase_rightCols_int.out -/// -/// The number of columns \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type -#else -typename NColsBlockXpr<...>::Type -#endif -rightCols(NColsType n) -{ - return typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, cols() - internal::get_runtime_value(n), rows(), internal::get_runtime_value(n)); -} - -/// This is the const version of rightCols(NColsType). -template<typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type -#else -const typename ConstNColsBlockXpr<...>::Type -#endif -rightCols(NColsType n) const -{ - return typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, cols() - internal::get_runtime_value(n), rows(), internal::get_runtime_value(n)); -} - -/// \returns a block consisting of the right columns of \c *this. -/// -/// \tparam N the number of columns in the block as specified at compile-time -/// \param n the number of columns in the block as specified at run-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include MatrixBase_template_int_rightCols.cpp -/// Output: \verbinclude MatrixBase_template_int_rightCols.out -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename NColsBlockXpr<N>::Type rightCols(Index n = N) -{ - return typename NColsBlockXpr<N>::Type(derived(), 0, cols() - n, rows(), n); -} - -/// This is the const version of rightCols<int>(). -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstNColsBlockXpr<N>::Type rightCols(Index n = N) const -{ - return typename ConstNColsBlockXpr<N>::Type(derived(), 0, cols() - n, rows(), n); -} - - - -/// \returns a block consisting of a range of columns of \c *this. -/// -/// \param startCol the index of the first column in the block -/// \param numCols the number of columns in the block -/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index. -/// -/// Example: \include DenseBase_middleCols_int.cpp -/// Output: \verbinclude DenseBase_middleCols_int.out -/// -/// The number of columns \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type -#else -typename NColsBlockXpr<...>::Type -#endif -middleCols(Index startCol, NColsType numCols) -{ - return typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, startCol, rows(), internal::get_runtime_value(numCols)); -} - -/// This is the const version of middleCols(Index,NColsType). -template<typename NColsType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type -#else -const typename ConstNColsBlockXpr<...>::Type -#endif -middleCols(Index startCol, NColsType numCols) const -{ - return typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type - (derived(), 0, startCol, rows(), internal::get_runtime_value(numCols)); -} - -/// \returns a block consisting of a range of columns of \c *this. -/// -/// \tparam N the number of columns in the block as specified at compile-time -/// \param startCol the index of the first column in the block -/// \param n the number of columns in the block as specified at run-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include DenseBase_template_int_middleCols.cpp -/// Output: \verbinclude DenseBase_template_int_middleCols.out -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename NColsBlockXpr<N>::Type middleCols(Index startCol, Index n = N) -{ - return typename NColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), n); -} - -/// This is the const version of middleCols<int>(). -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstNColsBlockXpr<N>::Type middleCols(Index startCol, Index n = N) const -{ - return typename ConstNColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), n); -} - - - -/// \returns a fixed-size expression of a block of \c *this. -/// -/// The template parameters \a NRows and \a NCols are the number of -/// rows and columns in the block. -/// -/// \param startRow the first row in the block -/// \param startCol the first column in the block -/// -/// Example: \include MatrixBase_block_int_int.cpp -/// Output: \verbinclude MatrixBase_block_int_int.out -/// -/// \note The usage of of this overload is discouraged from %Eigen 3.4, better used the generic -/// block(Index,Index,NRowsType,NColsType), here is the one-to-one equivalence: -/// \code -/// mat.template block<NRows,NCols>(i,j) <--> mat.block(i,j,fix<NRows>,fix<NCols>) -/// \endcode -/// -/// \note since block is a templated member, the keyword template has to be used -/// if the matrix type is also a template parameter: \code m.template block<3,3>(1,1); \endcode -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int NRows, int NCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol) -{ - return typename FixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol); -} - -/// This is the const version of block<>(Index, Index). */ -template<int NRows, int NCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol) const -{ - return typename ConstFixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol); -} - -/// \returns an expression of a block of \c *this. -/// -/// \tparam NRows number of rows in block as specified at compile-time -/// \tparam NCols number of columns in block as specified at compile-time -/// \param startRow the first row in the block -/// \param startCol the first column in the block -/// \param blockRows number of rows in block as specified at run-time -/// \param blockCols number of columns in block as specified at run-time -/// -/// This function is mainly useful for blocks where the number of rows is specified at compile-time -/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time -/// information should not contradict. In other words, \a blockRows should equal \a NRows unless -/// \a NRows is \a Dynamic, and the same for the number of columns. -/// -/// Example: \include MatrixBase_template_int_int_block_int_int_int_int.cpp -/// Output: \verbinclude MatrixBase_template_int_int_block_int_int_int_int.out -/// -/// \note The usage of of this overload is discouraged from %Eigen 3.4, better used the generic -/// block(Index,Index,NRowsType,NColsType), here is the one-to-one complete equivalence: -/// \code -/// mat.template block<NRows,NCols>(i,j,rows,cols) <--> mat.block(i,j,fix<NRows>(rows),fix<NCols>(cols)) -/// \endcode -/// If we known that, e.g., NRows==Dynamic and NCols!=Dynamic, then the equivalence becomes: -/// \code -/// mat.template block<Dynamic,NCols>(i,j,rows,NCols) <--> mat.block(i,j,rows,fix<NCols>) -/// \endcode -/// -EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL -/// -/// \sa block(Index,Index,NRowsType,NColsType), class Block -/// -template<int NRows, int NCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol, - Index blockRows, Index blockCols) -{ - return typename FixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol, blockRows, blockCols); -} - -/// This is the const version of block<>(Index, Index, Index, Index). -template<int NRows, int NCols> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const typename ConstFixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol, - Index blockRows, Index blockCols) const -{ - return typename ConstFixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol, blockRows, blockCols); -} - -/// \returns an expression of the \a i-th column of \c *this. Note that the numbering starts at 0. -/// -/// Example: \include MatrixBase_col.cpp -/// Output: \verbinclude MatrixBase_col.out -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) -/** - * \sa row(), class Block */ -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -ColXpr col(Index i) -{ - return ColXpr(derived(), i); -} - -/// This is the const version of col(). -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -ConstColXpr col(Index i) const -{ - return ConstColXpr(derived(), i); -} - -/// \returns an expression of the \a i-th row of \c *this. Note that the numbering starts at 0. -/// -/// Example: \include MatrixBase_row.cpp -/// Output: \verbinclude MatrixBase_row.out -/// -EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) -/** - * \sa col(), class Block */ -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -RowXpr row(Index i) -{ - return RowXpr(derived(), i); -} - -/// This is the const version of row(). */ -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -ConstRowXpr row(Index i) const -{ - return ConstRowXpr(derived(), i); -} - -/// \returns an expression of a segment (i.e. a vector block) in \c *this with either dynamic or fixed sizes. -/// -/// \only_for_vectors -/// -/// \param start the first coefficient in the segment -/// \param n the number of coefficients in the segment -/// \tparam NType the type of the value handling the number of coefficients in the segment, typically Index. -/// -/// Example: \include MatrixBase_segment_int_int.cpp -/// Output: \verbinclude MatrixBase_segment_int_int.out -/// -/// The number of coefficients \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -/// \note Even in the case that the returned expression has dynamic size, in the case -/// when it is applied to a fixed-size vector, it inherits a fixed maximal size, -/// which means that evaluating it does not cause a dynamic memory allocation. -/// -/// \sa block(Index,Index,NRowsType,NColsType), fix<N>, fix<N>(int), class Block -/// -template<typename NType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type -#else -typename FixedSegmentReturnType<...>::Type -#endif -segment(Index start, NType n) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type - (derived(), start, internal::get_runtime_value(n)); -} - - -/// This is the const version of segment(Index,NType). -template<typename NType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type -#else -const typename ConstFixedSegmentReturnType<...>::Type -#endif -segment(Index start, NType n) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type - (derived(), start, internal::get_runtime_value(n)); -} - -/// \returns an expression of the first coefficients of \c *this with either dynamic or fixed sizes. -/// -/// \only_for_vectors -/// -/// \param n the number of coefficients in the segment -/// \tparam NType the type of the value handling the number of coefficients in the segment, typically Index. -/// -/// Example: \include MatrixBase_start_int.cpp -/// Output: \verbinclude MatrixBase_start_int.out -/// -/// The number of coefficients \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -/// \note Even in the case that the returned expression has dynamic size, in the case -/// when it is applied to a fixed-size vector, it inherits a fixed maximal size, -/// which means that evaluating it does not cause a dynamic memory allocation. -/// -/// \sa class Block, block(Index,Index) -/// -template<typename NType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type -#else -typename FixedSegmentReturnType<...>::Type -#endif -head(NType n) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type - (derived(), 0, internal::get_runtime_value(n)); -} - -/// This is the const version of head(NType). -template<typename NType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type -#else -const typename ConstFixedSegmentReturnType<...>::Type -#endif -head(NType n) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type - (derived(), 0, internal::get_runtime_value(n)); -} - -/// \returns an expression of a last coefficients of \c *this with either dynamic or fixed sizes. -/// -/// \only_for_vectors -/// -/// \param n the number of coefficients in the segment -/// \tparam NType the type of the value handling the number of coefficients in the segment, typically Index. -/// -/// Example: \include MatrixBase_end_int.cpp -/// Output: \verbinclude MatrixBase_end_int.out -/// -/// The number of coefficients \a n can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. -/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details. -/// -/// \note Even in the case that the returned expression has dynamic size, in the case -/// when it is applied to a fixed-size vector, it inherits a fixed maximal size, -/// which means that evaluating it does not cause a dynamic memory allocation. -/// -/// \sa class Block, block(Index,Index) -/// -template<typename NType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type -#else -typename FixedSegmentReturnType<...>::Type -#endif -tail(NType n) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type - (derived(), this->size() - internal::get_runtime_value(n), internal::get_runtime_value(n)); -} - -/// This is the const version of tail(Index). -template<typename NType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -#ifndef EIGEN_PARSED_BY_DOXYGEN -const typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type -#else -const typename ConstFixedSegmentReturnType<...>::Type -#endif -tail(NType n) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type - (derived(), this->size() - internal::get_runtime_value(n), internal::get_runtime_value(n)); -} - -/// \returns a fixed-size expression of a segment (i.e. a vector block) in \c *this -/// -/// \only_for_vectors -/// -/// \tparam N the number of coefficients in the segment as specified at compile-time -/// \param start the index of the first element in the segment -/// \param n the number of coefficients in the segment as specified at compile-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include MatrixBase_template_int_segment.cpp -/// Output: \verbinclude MatrixBase_template_int_segment.out -/// -/// \sa segment(Index,NType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedSegmentReturnType<N>::Type segment(Index start, Index n = N) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename FixedSegmentReturnType<N>::Type(derived(), start, n); -} - -/// This is the const version of segment<int>(Index). -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstFixedSegmentReturnType<N>::Type segment(Index start, Index n = N) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename ConstFixedSegmentReturnType<N>::Type(derived(), start, n); -} - -/// \returns a fixed-size expression of the first coefficients of \c *this. -/// -/// \only_for_vectors -/// -/// \tparam N the number of coefficients in the segment as specified at compile-time -/// \param n the number of coefficients in the segment as specified at run-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include MatrixBase_template_int_start.cpp -/// Output: \verbinclude MatrixBase_template_int_start.out -/// -/// \sa head(NType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedSegmentReturnType<N>::Type head(Index n = N) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename FixedSegmentReturnType<N>::Type(derived(), 0, n); -} - -/// This is the const version of head<int>(). -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstFixedSegmentReturnType<N>::Type head(Index n = N) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename ConstFixedSegmentReturnType<N>::Type(derived(), 0, n); -} - -/// \returns a fixed-size expression of the last coefficients of \c *this. -/// -/// \only_for_vectors -/// -/// \tparam N the number of coefficients in the segment as specified at compile-time -/// \param n the number of coefficients in the segment as specified at run-time -/// -/// The compile-time and run-time information should not contradict. In other words, -/// \a n should equal \a N unless \a N is \a Dynamic. -/// -/// Example: \include MatrixBase_template_int_end.cpp -/// Output: \verbinclude MatrixBase_template_int_end.out -/// -/// \sa tail(NType), class Block -/// -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename FixedSegmentReturnType<N>::Type tail(Index n = N) -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename FixedSegmentReturnType<N>::Type(derived(), size() - n); -} - -/// This is the const version of tail<int>. -template<int N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename ConstFixedSegmentReturnType<N>::Type tail(Index n = N) const -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return typename ConstFixedSegmentReturnType<N>::Type(derived(), size() - n); -} - -/// \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this -/// is col-major (resp. row-major). -/// -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -InnerVectorReturnType innerVector(Index outer) -{ return InnerVectorReturnType(derived(), outer); } - -/// \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this -/// is col-major (resp. row-major). Read-only. -/// -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const ConstInnerVectorReturnType innerVector(Index outer) const -{ return ConstInnerVectorReturnType(derived(), outer); } - -/// \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this -/// is col-major (resp. row-major). -/// -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -InnerVectorsReturnType -innerVectors(Index outerStart, Index outerSize) -{ - return Block<Derived,Dynamic,Dynamic,true>(derived(), - IsRowMajor ? outerStart : 0, IsRowMajor ? 0 : outerStart, - IsRowMajor ? outerSize : rows(), IsRowMajor ? cols() : outerSize); - -} - -/// \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this -/// is col-major (resp. row-major). Read-only. -/// -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -const ConstInnerVectorsReturnType -innerVectors(Index outerStart, Index outerSize) const -{ - return Block<const Derived,Dynamic,Dynamic,true>(derived(), - IsRowMajor ? outerStart : 0, IsRowMajor ? 0 : outerStart, - IsRowMajor ? outerSize : rows(), IsRowMajor ? cols() : outerSize); - -} - -/** \returns the i-th subvector (column or vector) according to the \c Direction - * \sa subVectors() - */ -template<DirectionType Direction> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename internal::conditional<Direction==Vertical,ColXpr,RowXpr>::type -subVector(Index i) -{ - return typename internal::conditional<Direction==Vertical,ColXpr,RowXpr>::type(derived(),i); -} - -/** This is the const version of subVector(Index) */ -template<DirectionType Direction> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -typename internal::conditional<Direction==Vertical,ConstColXpr,ConstRowXpr>::type -subVector(Index i) const -{ - return typename internal::conditional<Direction==Vertical,ConstColXpr,ConstRowXpr>::type(derived(),i); -} - -/** \returns the number of subvectors (rows or columns) in the direction \c Direction - * \sa subVector(Index) - */ -template<DirectionType Direction> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -Index subVectors() const -{ return (Direction==Vertical)?cols():rows(); } - diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h b/external/eigen/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h deleted file mode 100644 index 8b6730ed..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h +++ /dev/null @@ -1,115 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// This file is a base class plugin containing common coefficient wise functions. - -/** \returns an expression of the difference of \c *this and \a other - * - * \note If you want to substract a given scalar from all coefficients, see Cwise::operator-(). - * - * \sa class CwiseBinaryOp, operator-=() - */ -EIGEN_MAKE_CWISE_BINARY_OP(operator-,difference) - -/** \returns an expression of the sum of \c *this and \a other - * - * \note If you want to add a given scalar to all coefficients, see Cwise::operator+(). - * - * \sa class CwiseBinaryOp, operator+=() - */ -EIGEN_MAKE_CWISE_BINARY_OP(operator+,sum) - -/** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other - * - * The template parameter \a CustomBinaryOp is the type of the functor - * of the custom operator (see class CwiseBinaryOp for an example) - * - * Here is an example illustrating the use of custom functors: - * \include class_CwiseBinaryOp.cpp - * Output: \verbinclude class_CwiseBinaryOp.out - * - * \sa class CwiseBinaryOp, operator+(), operator-(), cwiseProduct() - */ -template<typename CustomBinaryOp, typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived> -binaryExpr(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const -{ - return CwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived>(derived(), other.derived(), func); -} - - -#ifndef EIGEN_PARSED_BY_DOXYGEN -EIGEN_MAKE_SCALAR_BINARY_OP(operator*,product) -#else -/** \returns an expression of \c *this scaled by the scalar factor \a scalar - * - * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. - */ -template<typename T> -const CwiseBinaryOp<internal::scalar_product_op<Scalar,T>,Derived,Constant<T> > operator*(const T& scalar) const; -/** \returns an expression of \a expr scaled by the scalar factor \a scalar - * - * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. - */ -template<typename T> friend -const CwiseBinaryOp<internal::scalar_product_op<T,Scalar>,Constant<T>,Derived> operator*(const T& scalar, const StorageBaseType& expr); -#endif - - - -#ifndef EIGEN_PARSED_BY_DOXYGEN -EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(operator/,quotient) -#else -/** \returns an expression of \c *this divided by the scalar value \a scalar - * - * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. - */ -template<typename T> -const CwiseBinaryOp<internal::scalar_quotient_op<Scalar,T>,Derived,Constant<T> > operator/(const T& scalar) const; -#endif - -/** \returns an expression of the coefficient-wise boolean \b and operator of \c *this and \a other - * - * \warning this operator is for expression of bool only. - * - * Example: \include Cwise_boolean_and.cpp - * Output: \verbinclude Cwise_boolean_and.out - * - * \sa operator||(), select() - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -inline const CwiseBinaryOp<internal::scalar_boolean_and_op, const Derived, const OtherDerived> -operator&&(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value), - THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); - return CwiseBinaryOp<internal::scalar_boolean_and_op, const Derived, const OtherDerived>(derived(),other.derived()); -} - -/** \returns an expression of the coefficient-wise boolean \b or operator of \c *this and \a other - * - * \warning this operator is for expression of bool only. - * - * Example: \include Cwise_boolean_or.cpp - * Output: \verbinclude Cwise_boolean_or.out - * - * \sa operator&&(), select() - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -inline const CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived> -operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value), - THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); - return CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>(derived(),other.derived()); -} diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/CommonCwiseUnaryOps.h b/external/eigen/include/eigen3/Eigen/src/plugins/CommonCwiseUnaryOps.h deleted file mode 100644 index 5418dc41..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/CommonCwiseUnaryOps.h +++ /dev/null @@ -1,177 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// This file is a base class plugin containing common coefficient wise functions. - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -/** \internal the return type of conjugate() */ -typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>, - const Derived& - >::type ConjugateReturnType; -/** \internal the return type of real() const */ -typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - const CwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived>, - const Derived& - >::type RealReturnType; -/** \internal the return type of real() */ -typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>, - Derived& - >::type NonConstRealReturnType; -/** \internal the return type of imag() const */ -typedef CwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived> ImagReturnType; -/** \internal the return type of imag() */ -typedef CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType; - -typedef CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived> NegativeReturnType; - -#endif // not EIGEN_PARSED_BY_DOXYGEN - -/// \returns an expression of the opposite of \c *this -/// -EIGEN_DOC_UNARY_ADDONS(operator-,opposite) -/// -EIGEN_DEVICE_FUNC -inline const NegativeReturnType -operator-() const { return NegativeReturnType(derived()); } - - -template<class NewType> struct CastXpr { typedef typename internal::cast_return_type<Derived,const CwiseUnaryOp<internal::scalar_cast_op<Scalar, NewType>, const Derived> >::type Type; }; - -/// \returns an expression of \c *this with the \a Scalar type casted to -/// \a NewScalar. -/// -/// The template parameter \a NewScalar is the type we are casting the scalars to. -/// -EIGEN_DOC_UNARY_ADDONS(cast,conversion function) -/// -/// \sa class CwiseUnaryOp -/// -template<typename NewType> -EIGEN_DEVICE_FUNC -typename CastXpr<NewType>::Type -cast() const -{ - return typename CastXpr<NewType>::Type(derived()); -} - -/// \returns an expression of the complex conjugate of \c *this. -/// -EIGEN_DOC_UNARY_ADDONS(conjugate,complex conjugate) -/// -/// \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_conj">Math functions</a>, MatrixBase::adjoint() -EIGEN_DEVICE_FUNC -inline ConjugateReturnType -conjugate() const -{ - return ConjugateReturnType(derived()); -} - -/// \returns an expression of the complex conjugate of \c *this if Cond==true, returns derived() otherwise. -/// -EIGEN_DOC_UNARY_ADDONS(conjugate,complex conjugate) -/// -/// \sa conjugate() -template<bool Cond> -EIGEN_DEVICE_FUNC -inline typename internal::conditional<Cond,ConjugateReturnType,const Derived&>::type -conjugateIf() const -{ - typedef typename internal::conditional<Cond,ConjugateReturnType,const Derived&>::type ReturnType; - return ReturnType(derived()); -} - -/// \returns a read-only expression of the real part of \c *this. -/// -EIGEN_DOC_UNARY_ADDONS(real,real part function) -/// -/// \sa imag() -EIGEN_DEVICE_FUNC -inline RealReturnType -real() const { return RealReturnType(derived()); } - -/// \returns an read-only expression of the imaginary part of \c *this. -/// -EIGEN_DOC_UNARY_ADDONS(imag,imaginary part function) -/// -/// \sa real() -EIGEN_DEVICE_FUNC -inline const ImagReturnType -imag() const { return ImagReturnType(derived()); } - -/// \brief Apply a unary operator coefficient-wise -/// \param[in] func Functor implementing the unary operator -/// \tparam CustomUnaryOp Type of \a func -/// \returns An expression of a custom coefficient-wise unary operator \a func of *this -/// -/// The function \c ptr_fun() from the C++ standard library can be used to make functors out of normal functions. -/// -/// Example: -/// \include class_CwiseUnaryOp_ptrfun.cpp -/// Output: \verbinclude class_CwiseUnaryOp_ptrfun.out -/// -/// Genuine functors allow for more possibilities, for instance it may contain a state. -/// -/// Example: -/// \include class_CwiseUnaryOp.cpp -/// Output: \verbinclude class_CwiseUnaryOp.out -/// -EIGEN_DOC_UNARY_ADDONS(unaryExpr,unary function) -/// -/// \sa unaryViewExpr, binaryExpr, class CwiseUnaryOp -/// -template<typename CustomUnaryOp> -EIGEN_DEVICE_FUNC -inline const CwiseUnaryOp<CustomUnaryOp, const Derived> -unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const -{ - return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func); -} - -/// \returns an expression of a custom coefficient-wise unary operator \a func of *this -/// -/// The template parameter \a CustomUnaryOp is the type of the functor -/// of the custom unary operator. -/// -/// Example: -/// \include class_CwiseUnaryOp.cpp -/// Output: \verbinclude class_CwiseUnaryOp.out -/// -EIGEN_DOC_UNARY_ADDONS(unaryViewExpr,unary function) -/// -/// \sa unaryExpr, binaryExpr class CwiseUnaryOp -/// -template<typename CustomViewOp> -EIGEN_DEVICE_FUNC -inline const CwiseUnaryView<CustomViewOp, const Derived> -unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const -{ - return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func); -} - -/// \returns a non const expression of the real part of \c *this. -/// -EIGEN_DOC_UNARY_ADDONS(real,real part function) -/// -/// \sa imag() -EIGEN_DEVICE_FUNC -inline NonConstRealReturnType -real() { return NonConstRealReturnType(derived()); } - -/// \returns a non const expression of the imaginary part of \c *this. -/// -EIGEN_DOC_UNARY_ADDONS(imag,imaginary part function) -/// -/// \sa real() -EIGEN_DEVICE_FUNC -inline NonConstImagReturnType -imag() { return NonConstImagReturnType(derived()); } diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/IndexedViewMethods.h b/external/eigen/include/eigen3/Eigen/src/plugins/IndexedViewMethods.h deleted file mode 100644 index 5bfb19ac..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/IndexedViewMethods.h +++ /dev/null @@ -1,262 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#if !defined(EIGEN_PARSED_BY_DOXYGEN) - -// This file is automatically included twice to generate const and non-const versions - -#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS -#define EIGEN_INDEXED_VIEW_METHOD_CONST const -#define EIGEN_INDEXED_VIEW_METHOD_TYPE ConstIndexedViewType -#else -#define EIGEN_INDEXED_VIEW_METHOD_CONST -#define EIGEN_INDEXED_VIEW_METHOD_TYPE IndexedViewType -#endif - -#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS -protected: - -// define some aliases to ease readability - -template<typename Indices> -struct IvcRowType : public internal::IndexedViewCompatibleType<Indices,RowsAtCompileTime> {}; - -template<typename Indices> -struct IvcColType : public internal::IndexedViewCompatibleType<Indices,ColsAtCompileTime> {}; - -template<typename Indices> -struct IvcType : public internal::IndexedViewCompatibleType<Indices,SizeAtCompileTime> {}; - -typedef typename internal::IndexedViewCompatibleType<Index,1>::type IvcIndex; - -template<typename Indices> -typename IvcRowType<Indices>::type -ivcRow(const Indices& indices) const { - return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,RowsAtCompileTime>(derived().rows()),Specialized); -} - -template<typename Indices> -typename IvcColType<Indices>::type -ivcCol(const Indices& indices) const { - return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,ColsAtCompileTime>(derived().cols()),Specialized); -} - -template<typename Indices> -typename IvcColType<Indices>::type -ivcSize(const Indices& indices) const { - return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,SizeAtCompileTime>(derived().size()),Specialized); -} - -public: - -#endif - -template<typename RowIndices, typename ColIndices> -struct EIGEN_INDEXED_VIEW_METHOD_TYPE { - typedef IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived, - typename IvcRowType<RowIndices>::type, - typename IvcColType<ColIndices>::type> type; -}; - -// This is the generic version - -template<typename RowIndices, typename ColIndices> -typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value - && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsIndexedView, - typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type >::type -operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - return typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type - (derived(), ivcRow(rowIndices), ivcCol(colIndices)); -} - -// The following overload returns a Block<> object - -template<typename RowIndices, typename ColIndices> -typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value - && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsBlock, - typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType>::type -operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - typedef typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType BlockType; - typename IvcRowType<RowIndices>::type actualRowIndices = ivcRow(rowIndices); - typename IvcColType<ColIndices>::type actualColIndices = ivcCol(colIndices); - return BlockType(derived(), - internal::first(actualRowIndices), - internal::first(actualColIndices), - internal::size(actualRowIndices), - internal::size(actualColIndices)); -} - -// The following overload returns a Scalar - -template<typename RowIndices, typename ColIndices> -typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value - && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsScalar, - CoeffReturnType >::type -operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - return Base::operator()(internal::eval_expr_given_size(rowIndices,rows()),internal::eval_expr_given_size(colIndices,cols())); -} - -#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE - -// The following three overloads are needed to handle raw Index[N] arrays. - -template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices> -IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type> -operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type> - (derived(), rowIndices, ivcCol(colIndices)); -} - -template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN> -IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcRowType<RowIndices>::type, const ColIndicesT (&)[ColIndicesN]> -operator()(const RowIndices& rowIndices, const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcRowType<RowIndices>::type,const ColIndicesT (&)[ColIndicesN]> - (derived(), ivcRow(rowIndices), colIndices); -} - -template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndicesT, std::size_t ColIndicesN> -IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN], const ColIndicesT (&)[ColIndicesN]> -operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],const ColIndicesT (&)[ColIndicesN]> - (derived(), rowIndices, colIndices); -} - -#endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE - -// Overloads for 1D vectors/arrays - -template<typename Indices> -typename internal::enable_if< - IsRowMajor && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)), - IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,typename IvcType<Indices>::type> >::type -operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,typename IvcType<Indices>::type> - (derived(), IvcIndex(0), ivcCol(indices)); -} - -template<typename Indices> -typename internal::enable_if< - (!IsRowMajor) && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)), - IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcType<Indices>::type,IvcIndex> >::type -operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcType<Indices>::type,IvcIndex> - (derived(), ivcRow(indices), IvcIndex(0)); -} - -template<typename Indices> -typename internal::enable_if< - (internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1) && (!internal::is_valid_index_type<Indices>::value) && (!symbolic::is_symbolic<Indices>::value), - VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value> >::type -operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - typename IvcType<Indices>::type actualIndices = ivcSize(indices); - return VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value> - (derived(), internal::first(actualIndices), internal::size(actualIndices)); -} - -template<typename IndexType> -typename internal::enable_if<symbolic::is_symbolic<IndexType>::value, CoeffReturnType >::type -operator()(const IndexType& id) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - return Base::operator()(internal::eval_expr_given_size(id,size())); -} - -#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE - -template<typename IndicesT, std::size_t IndicesN> -typename internal::enable_if<IsRowMajor, - IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]> >::type -operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]> - (derived(), IvcIndex(0), indices); -} - -template<typename IndicesT, std::size_t IndicesN> -typename internal::enable_if<!IsRowMajor, - IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex> >::type -operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST -{ - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) - return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex> - (derived(), indices, IvcIndex(0)); -} - -#endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE - -#undef EIGEN_INDEXED_VIEW_METHOD_CONST -#undef EIGEN_INDEXED_VIEW_METHOD_TYPE - -#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS -#define EIGEN_INDEXED_VIEW_METHOD_2ND_PASS -#include "IndexedViewMethods.h" -#undef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS -#endif - -#else // EIGEN_PARSED_BY_DOXYGEN - -/** - * \returns a generic submatrix view defined by the rows and columns indexed \a rowIndices and \a colIndices respectively. - * - * Each parameter must either be: - * - An integer indexing a single row or column - * - Eigen::all indexing the full set of respective rows or columns in increasing order - * - An ArithmeticSequence as returned by the Eigen::seq and Eigen::seqN functions - * - Any %Eigen's vector/array of integers or expressions - * - Plain C arrays: \c int[N] - * - And more generally any type exposing the following two member functions: - * \code - * <integral type> operator[](<integral type>) const; - * <integral type> size() const; - * \endcode - * where \c <integral \c type> stands for any integer type compatible with Eigen::Index (i.e. \c std::ptrdiff_t). - * - * The last statement implies compatibility with \c std::vector, \c std::valarray, \c std::array, many of the Range-v3's ranges, etc. - * - * If the submatrix can be represented using a starting position \c (i,j) and positive sizes \c (rows,columns), then this - * method will returns a Block object after extraction of the relevant information from the passed arguments. This is the case - * when all arguments are either: - * - An integer - * - Eigen::all - * - An ArithmeticSequence with compile-time increment strictly equal to 1, as returned by Eigen::seq(a,b), and Eigen::seqN(a,N). - * - * Otherwise a more general IndexedView<Derived,RowIndices',ColIndices'> object will be returned, after conversion of the inputs - * to more suitable types \c RowIndices' and \c ColIndices'. - * - * For 1D vectors and arrays, you better use the operator()(const Indices&) overload, which behave the same way but taking a single parameter. - * - * See also this <a href="https://stackoverflow.com/questions/46110917/eigen-replicate-items-along-one-dimension-without-useless-allocations">question</a> and its answer for an example of how to duplicate coefficients. - * - * \sa operator()(const Indices&), class Block, class IndexedView, DenseBase::block(Index,Index,Index,Index) - */ -template<typename RowIndices, typename ColIndices> -IndexedView_or_Block -operator()(const RowIndices& rowIndices, const ColIndices& colIndices); - -/** This is an overload of operator()(const RowIndices&, const ColIndices&) for 1D vectors or arrays - * - * \only_for_vectors - */ -template<typename Indices> -IndexedView_or_VectorBlock -operator()(const Indices& indices); - -#endif // EIGEN_PARSED_BY_DOXYGEN diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/MatrixCwiseBinaryOps.h b/external/eigen/include/eigen3/Eigen/src/plugins/MatrixCwiseBinaryOps.h deleted file mode 100644 index f1084abe..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/MatrixCwiseBinaryOps.h +++ /dev/null @@ -1,152 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// This file is a base class plugin containing matrix specifics coefficient wise functions. - -/** \returns an expression of the Schur product (coefficient wise product) of *this and \a other - * - * Example: \include MatrixBase_cwiseProduct.cpp - * Output: \verbinclude MatrixBase_cwiseProduct.out - * - * \sa class CwiseBinaryOp, cwiseAbs2 - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product) -cwiseProduct(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise == operator of *this and \a other - * - * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. - * In order to check for equality between two vectors or matrices with floating-point coefficients, it is - * generally a far better idea to use a fuzzy comparison as provided by isApprox() and - * isMuchSmallerThan(). - * - * Example: \include MatrixBase_cwiseEqual.cpp - * Output: \verbinclude MatrixBase_cwiseEqual.out - * - * \sa cwiseNotEqual(), isApprox(), isMuchSmallerThan() - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -inline const CwiseBinaryOp<std::equal_to<Scalar>, const Derived, const OtherDerived> -cwiseEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<std::equal_to<Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise != operator of *this and \a other - * - * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. - * In order to check for equality between two vectors or matrices with floating-point coefficients, it is - * generally a far better idea to use a fuzzy comparison as provided by isApprox() and - * isMuchSmallerThan(). - * - * Example: \include MatrixBase_cwiseNotEqual.cpp - * Output: \verbinclude MatrixBase_cwiseNotEqual.out - * - * \sa cwiseEqual(), isApprox(), isMuchSmallerThan() - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -inline const CwiseBinaryOp<std::not_equal_to<Scalar>, const Derived, const OtherDerived> -cwiseNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<std::not_equal_to<Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise min of *this and \a other - * - * Example: \include MatrixBase_cwiseMin.cpp - * Output: \verbinclude MatrixBase_cwiseMin.out - * - * \sa class CwiseBinaryOp, max() - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const OtherDerived> -cwiseMin(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise min of *this and scalar \a other - * - * \sa class CwiseBinaryOp, min() - */ -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const ConstantReturnType> -cwiseMin(const Scalar &other) const -{ - return cwiseMin(Derived::Constant(rows(), cols(), other)); -} - -/** \returns an expression of the coefficient-wise max of *this and \a other - * - * Example: \include MatrixBase_cwiseMax.cpp - * Output: \verbinclude MatrixBase_cwiseMax.out - * - * \sa class CwiseBinaryOp, min() - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const OtherDerived> -cwiseMax(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise max of *this and scalar \a other - * - * \sa class CwiseBinaryOp, min() - */ -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const ConstantReturnType> -cwiseMax(const Scalar &other) const -{ - return cwiseMax(Derived::Constant(rows(), cols(), other)); -} - - -/** \returns an expression of the coefficient-wise quotient of *this and \a other - * - * Example: \include MatrixBase_cwiseQuotient.cpp - * Output: \verbinclude MatrixBase_cwiseQuotient.out - * - * \sa class CwiseBinaryOp, cwiseProduct(), cwiseInverse() - */ -template<typename OtherDerived> -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived> -cwiseQuotient(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); -} - -typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar,internal::cmp_EQ>, const Derived, const ConstantReturnType> CwiseScalarEqualReturnType; - -/** \returns an expression of the coefficient-wise == operator of \c *this and a scalar \a s - * - * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. - * In order to check for equality between two vectors or matrices with floating-point coefficients, it is - * generally a far better idea to use a fuzzy comparison as provided by isApprox() and - * isMuchSmallerThan(). - * - * \sa cwiseEqual(const MatrixBase<OtherDerived> &) const - */ -EIGEN_DEVICE_FUNC -inline const CwiseScalarEqualReturnType -cwiseEqual(const Scalar& s) const -{ - return CwiseScalarEqualReturnType(derived(), Derived::Constant(rows(), cols(), s), internal::scalar_cmp_op<Scalar,Scalar,internal::cmp_EQ>()); -} diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/MatrixCwiseUnaryOps.h b/external/eigen/include/eigen3/Eigen/src/plugins/MatrixCwiseUnaryOps.h deleted file mode 100644 index b1be3d56..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/MatrixCwiseUnaryOps.h +++ /dev/null @@ -1,85 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// This file is included into the body of the base classes supporting matrix specific coefficient-wise functions. -// This include MatrixBase and SparseMatrixBase. - - -typedef CwiseUnaryOp<internal::scalar_abs_op<Scalar>, const Derived> CwiseAbsReturnType; -typedef CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const Derived> CwiseAbs2ReturnType; -typedef CwiseUnaryOp<internal::scalar_sqrt_op<Scalar>, const Derived> CwiseSqrtReturnType; -typedef CwiseUnaryOp<internal::scalar_sign_op<Scalar>, const Derived> CwiseSignReturnType; -typedef CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived> CwiseInverseReturnType; - -/// \returns an expression of the coefficient-wise absolute value of \c *this -/// -/// Example: \include MatrixBase_cwiseAbs.cpp -/// Output: \verbinclude MatrixBase_cwiseAbs.out -/// -EIGEN_DOC_UNARY_ADDONS(cwiseAbs,absolute value) -/// -/// \sa cwiseAbs2() -/// -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseAbsReturnType -cwiseAbs() const { return CwiseAbsReturnType(derived()); } - -/// \returns an expression of the coefficient-wise squared absolute value of \c *this -/// -/// Example: \include MatrixBase_cwiseAbs2.cpp -/// Output: \verbinclude MatrixBase_cwiseAbs2.out -/// -EIGEN_DOC_UNARY_ADDONS(cwiseAbs2,squared absolute value) -/// -/// \sa cwiseAbs() -/// -EIGEN_DEVICE_FUNC -EIGEN_STRONG_INLINE const CwiseAbs2ReturnType -cwiseAbs2() const { return CwiseAbs2ReturnType(derived()); } - -/// \returns an expression of the coefficient-wise square root of *this. -/// -/// Example: \include MatrixBase_cwiseSqrt.cpp -/// Output: \verbinclude MatrixBase_cwiseSqrt.out -/// -EIGEN_DOC_UNARY_ADDONS(cwiseSqrt,square-root) -/// -/// \sa cwisePow(), cwiseSquare() -/// -EIGEN_DEVICE_FUNC -inline const CwiseSqrtReturnType -cwiseSqrt() const { return CwiseSqrtReturnType(derived()); } - -/// \returns an expression of the coefficient-wise signum of *this. -/// -/// Example: \include MatrixBase_cwiseSign.cpp -/// Output: \verbinclude MatrixBase_cwiseSign.out -/// -EIGEN_DOC_UNARY_ADDONS(cwiseSign,sign function) -/// -EIGEN_DEVICE_FUNC -inline const CwiseSignReturnType -cwiseSign() const { return CwiseSignReturnType(derived()); } - - -/// \returns an expression of the coefficient-wise inverse of *this. -/// -/// Example: \include MatrixBase_cwiseInverse.cpp -/// Output: \verbinclude MatrixBase_cwiseInverse.out -/// -EIGEN_DOC_UNARY_ADDONS(cwiseInverse,inverse) -/// -/// \sa cwiseProduct() -/// -EIGEN_DEVICE_FUNC -inline const CwiseInverseReturnType -cwiseInverse() const { return CwiseInverseReturnType(derived()); } - - diff --git a/external/eigen/include/eigen3/Eigen/src/plugins/ReshapedMethods.h b/external/eigen/include/eigen3/Eigen/src/plugins/ReshapedMethods.h deleted file mode 100644 index 482a6b04..00000000 --- a/external/eigen/include/eigen3/Eigen/src/plugins/ReshapedMethods.h +++ /dev/null @@ -1,149 +0,0 @@ - -#ifdef EIGEN_PARSED_BY_DOXYGEN - -/// \returns an expression of \c *this with reshaped sizes. -/// -/// \param nRows the number of rows in the reshaped expression, specified at either run-time or compile-time, or AutoSize -/// \param nCols the number of columns in the reshaped expression, specified at either run-time or compile-time, or AutoSize -/// \tparam Order specifies whether the coefficients should be processed in column-major-order (ColMajor), in row-major-order (RowMajor), -/// or follows the \em natural order of the nested expression (AutoOrder). The default is ColMajor. -/// \tparam NRowsType the type of the value handling the number of rows, typically Index. -/// \tparam NColsType the type of the value handling the number of columns, typically Index. -/// -/// Dynamic size example: \include MatrixBase_reshaped_int_int.cpp -/// Output: \verbinclude MatrixBase_reshaped_int_int.out -/// -/// The number of rows \a nRows and columns \a nCols can also be specified at compile-time by passing Eigen::fix<N>, -/// or Eigen::fix<N>(n) as arguments. In the later case, \c n plays the role of a runtime fallback value in case \c N equals Eigen::Dynamic. -/// Here is an example with a fixed number of rows and columns: -/// \include MatrixBase_reshaped_fixed.cpp -/// Output: \verbinclude MatrixBase_reshaped_fixed.out -/// -/// Finally, one of the sizes parameter can be automatically deduced from the other one by passing AutoSize as in the following example: -/// \include MatrixBase_reshaped_auto.cpp -/// Output: \verbinclude MatrixBase_reshaped_auto.out -/// AutoSize does preserve compile-time sizes when possible, i.e., when the sizes of the input are known at compile time \b and -/// that the other size is passed at compile-time using Eigen::fix<N> as above. -/// -/// \sa class Reshaped, fix, fix<N>(int) -/// -template<int Order = ColMajor, typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC -inline Reshaped<Derived,...> -reshaped(NRowsType nRows, NColsType nCols); - -/// This is the const version of reshaped(NRowsType,NColsType). -template<int Order = ColMajor, typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC -inline const Reshaped<const Derived,...> -reshaped(NRowsType nRows, NColsType nCols) const; - -/// \returns an expression of \c *this with columns (or rows) stacked to a linear column vector -/// -/// \tparam Order specifies whether the coefficients should be processed in column-major-order (ColMajor), in row-major-order (RowMajor), -/// or follows the \em natural order of the nested expression (AutoOrder). The default is ColMajor. -/// -/// This overloads is essentially a shortcut for `A.reshaped<Order>(AutoSize,fix<1>)`. -/// -/// - If `Order==ColMajor` (the default), then it returns a column-vector from the stacked columns of \c *this. -/// - If `Order==RowMajor`, then it returns a column-vector from the stacked rows of \c *this. -/// - If `Order==AutoOrder`, then it returns a column-vector with elements stacked following the storage order of \c *this. -/// This mode is the recommended one when the particular ordering of the element is not relevant. -/// -/// Example: -/// \include MatrixBase_reshaped_to_vector.cpp -/// Output: \verbinclude MatrixBase_reshaped_to_vector.out -/// -/// If you want more control, you can still fall back to reshaped(NRowsType,NColsType). -/// -/// \sa reshaped(NRowsType,NColsType), class Reshaped -/// -template<int Order = ColMajor> -EIGEN_DEVICE_FUNC -inline Reshaped<Derived,...> -reshaped(); - -/// This is the const version of reshaped(). -template<int Order = ColMajor> -EIGEN_DEVICE_FUNC -inline const Reshaped<const Derived,...> -reshaped() const; - -#else - -// This file is automatically included twice to generate const and non-const versions - -#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS -#define EIGEN_RESHAPED_METHOD_CONST const -#else -#define EIGEN_RESHAPED_METHOD_CONST -#endif - -#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS - -// This part is included once - -#endif - -template<typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC -inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, - internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value, - internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value> -reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST -{ - return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, - internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value, - internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value> - (derived(), - internal::get_runtime_reshape_size(nRows,internal::get_runtime_value(nCols),size()), - internal::get_runtime_reshape_size(nCols,internal::get_runtime_value(nRows),size())); -} - -template<int Order, typename NRowsType, typename NColsType> -EIGEN_DEVICE_FUNC -inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, - internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value, - internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value, - internal::get_compiletime_reshape_order<Flags,Order>::value> -reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST -{ - return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, - internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value, - internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value, - internal::get_compiletime_reshape_order<Flags,Order>::value> - (derived(), - internal::get_runtime_reshape_size(nRows,internal::get_runtime_value(nCols),size()), - internal::get_runtime_reshape_size(nCols,internal::get_runtime_value(nRows),size())); -} - -// Views as linear vectors - -EIGEN_DEVICE_FUNC -inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,SizeAtCompileTime,1> -reshaped() EIGEN_RESHAPED_METHOD_CONST -{ - return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,SizeAtCompileTime,1>(derived(),size(),1); -} - -template<int Order> -EIGEN_DEVICE_FUNC -inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, SizeAtCompileTime, 1, - internal::get_compiletime_reshape_order<Flags,Order>::value> -reshaped() EIGEN_RESHAPED_METHOD_CONST -{ - EIGEN_STATIC_ASSERT(Order==RowMajor || Order==ColMajor || Order==AutoOrder, INVALID_TEMPLATE_PARAMETER); - return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, SizeAtCompileTime, 1, - internal::get_compiletime_reshape_order<Flags,Order>::value> - (derived(), size(), 1); -} - -#undef EIGEN_RESHAPED_METHOD_CONST - -#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS -#define EIGEN_RESHAPED_METHOD_2ND_PASS -#include "ReshapedMethods.h" -#undef EIGEN_RESHAPED_METHOD_2ND_PASS -#endif - -#endif // EIGEN_PARSED_BY_DOXYGEN diff --git a/external/eigen/include/eigen3/signature_of_eigen3_matrix_library b/external/eigen/include/eigen3/signature_of_eigen3_matrix_library deleted file mode 100644 index 80aaf462..00000000 --- a/external/eigen/include/eigen3/signature_of_eigen3_matrix_library +++ /dev/null @@ -1 +0,0 @@ -This file is just there as a signature to help identify directories containing Eigen3. When writing a script looking for Eigen3, just look for this file. This is especially useful to help disambiguate with Eigen2... diff --git a/external/eigen/include/eigen3/unsupported/Eigen/AdolcForward b/external/eigen/include/eigen3/unsupported/Eigen/AdolcForward deleted file mode 100644 index 9b8d3cd1..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/AdolcForward +++ /dev/null @@ -1,156 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <g.gael@free.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ADLOC_FORWARD -#define EIGEN_ADLOC_FORWARD - -//-------------------------------------------------------------------------------- -// -// This file provides support for adolc's adouble type in forward mode. -// ADOL-C is a C++ automatic differentiation library, -// see https://projects.coin-or.org/ADOL-C for more information. -// -// Note that the maximal number of directions is controlled by -// the preprocessor token NUMBER_DIRECTIONS. The default is 2. -// -//-------------------------------------------------------------------------------- - -#define ADOLC_TAPELESS -#ifndef NUMBER_DIRECTIONS -# define NUMBER_DIRECTIONS 2 -#endif -#include <adolc/adtl.h> - -// adolc defines some very stupid macros: -#if defined(malloc) -# undef malloc -#endif - -#if defined(calloc) -# undef calloc -#endif - -#if defined(realloc) -# undef realloc -#endif - -#include "../../Eigen/Core" - -namespace Eigen { - -/** - * \defgroup AdolcForward_Module Adolc forward module - * This module provides support for adolc's adouble type in forward mode. - * ADOL-C is a C++ automatic differentiation library, - * see https://projects.coin-or.org/ADOL-C for more information. - * It mainly consists in: - * - a struct Eigen::NumTraits<adtl::adouble> specialization - * - overloads of internal::* math function for adtl::adouble type. - * - * Note that the maximal number of directions is controlled by - * the preprocessor token NUMBER_DIRECTIONS. The default is 2. - * - * \code - * #include <unsupported/Eigen/AdolcSupport> - * \endcode - */ - //@{ - -} // namespace Eigen - -// Eigen's require a few additional functions which must be defined in the same namespace -// than the custom scalar type own namespace -namespace adtl { - -inline const adouble& conj(const adouble& x) { return x; } -inline const adouble& real(const adouble& x) { return x; } -inline adouble imag(const adouble&) { return 0.; } -inline adouble abs(const adouble& x) { return fabs(x); } -inline adouble abs2(const adouble& x) { return x*x; } - -} - -namespace Eigen { - -template<> struct NumTraits<adtl::adouble> - : NumTraits<double> -{ - typedef adtl::adouble Real; - typedef adtl::adouble NonInteger; - typedef adtl::adouble Nested; - enum { - IsComplex = 0, - IsInteger = 0, - IsSigned = 1, - RequireInitialization = 1, - ReadCost = 1, - AddCost = 1, - MulCost = 1 - }; -}; - -template<typename Functor> class AdolcForwardJacobian : public Functor -{ - typedef adtl::adouble ActiveScalar; -public: - - AdolcForwardJacobian() : Functor() {} - AdolcForwardJacobian(const Functor& f) : Functor(f) {} - - // forward constructors - template<typename T0> - AdolcForwardJacobian(const T0& a0) : Functor(a0) {} - template<typename T0, typename T1> - AdolcForwardJacobian(const T0& a0, const T1& a1) : Functor(a0, a1) {} - template<typename T0, typename T1, typename T2> - AdolcForwardJacobian(const T0& a0, const T1& a1, const T1& a2) : Functor(a0, a1, a2) {} - - typedef typename Functor::InputType InputType; - typedef typename Functor::ValueType ValueType; - typedef typename Functor::JacobianType JacobianType; - - typedef Matrix<ActiveScalar, InputType::SizeAtCompileTime, 1> ActiveInput; - typedef Matrix<ActiveScalar, ValueType::SizeAtCompileTime, 1> ActiveValue; - - void operator() (const InputType& x, ValueType* v, JacobianType* _jac) const - { - eigen_assert(v!=0); - if (!_jac) - { - Functor::operator()(x, v); - return; - } - - JacobianType& jac = *_jac; - - ActiveInput ax = x.template cast<ActiveScalar>(); - ActiveValue av(jac.rows()); - - for (int j=0; j<jac.cols(); j++) - for (int i=0; i<jac.cols(); i++) - ax[i].setADValue(j, i==j ? 1 : 0); - - Functor::operator()(ax, &av); - - for (int i=0; i<jac.rows(); i++) - { - (*v)[i] = av[i].getValue(); - for (int j=0; j<jac.cols(); j++) - jac.coeffRef(i,j) = av[i].getADValue(j); - } - } -protected: - -}; - -//@} - -} - -#endif // EIGEN_ADLOC_FORWARD diff --git a/external/eigen/include/eigen3/unsupported/Eigen/AlignedVector3 b/external/eigen/include/eigen3/unsupported/Eigen/AlignedVector3 deleted file mode 100644 index 4fa1842a..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/AlignedVector3 +++ /dev/null @@ -1,234 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <g.gael@free.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ALIGNED_VECTOR3 -#define EIGEN_ALIGNED_VECTOR3 - -#include "../../Eigen/Geometry" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -namespace Eigen { - -/** - * \defgroup AlignedVector3_Module Aligned vector3 module - * - * \code - * #include <unsupported/Eigen/AlignedVector3> - * \endcode - */ - //@{ - - -/** \class AlignedVector3 - * - * \brief A vectorization friendly 3D vector - * - * This class represents a 3D vector internally using a 4D vector - * such that vectorization can be seamlessly enabled. Of course, - * the same result can be achieved by directly using a 4D vector. - * This class makes this process simpler. - * - */ -// TODO specialize Cwise -template<typename _Scalar> class AlignedVector3; - -namespace internal { -template<typename _Scalar> struct traits<AlignedVector3<_Scalar> > - : traits<Matrix<_Scalar,3,1,0,4,1> > -{ -}; -} - -template<typename _Scalar> class AlignedVector3 - : public MatrixBase<AlignedVector3<_Scalar> > -{ - typedef Matrix<_Scalar,4,1> CoeffType; - CoeffType m_coeffs; - public: - - typedef MatrixBase<AlignedVector3<_Scalar> > Base; - EIGEN_DENSE_PUBLIC_INTERFACE(AlignedVector3) - using Base::operator*; - - inline Index rows() const { return 3; } - inline Index cols() const { return 1; } - - Scalar* data() { return m_coeffs.data(); } - const Scalar* data() const { return m_coeffs.data(); } - Index innerStride() const { return 1; } - Index outerStride() const { return 3; } - - inline const Scalar& coeff(Index row, Index col) const - { return m_coeffs.coeff(row, col); } - - inline Scalar& coeffRef(Index row, Index col) - { return m_coeffs.coeffRef(row, col); } - - inline const Scalar& coeff(Index index) const - { return m_coeffs.coeff(index); } - - inline Scalar& coeffRef(Index index) - { return m_coeffs.coeffRef(index);} - - - inline AlignedVector3() - {} - - inline AlignedVector3(const Scalar& x, const Scalar& y, const Scalar& z) - : m_coeffs(x, y, z, Scalar(0)) - {} - - inline AlignedVector3(const AlignedVector3& other) - : Base(), m_coeffs(other.m_coeffs) - {} - - template<typename XprType, int Size=XprType::SizeAtCompileTime> - struct generic_assign_selector {}; - - template<typename XprType> struct generic_assign_selector<XprType,4> - { - inline static void run(AlignedVector3& dest, const XprType& src) - { - dest.m_coeffs = src; - } - }; - - template<typename XprType> struct generic_assign_selector<XprType,3> - { - inline static void run(AlignedVector3& dest, const XprType& src) - { - dest.m_coeffs.template head<3>() = src; - dest.m_coeffs.w() = Scalar(0); - } - }; - - template<typename Derived> - inline AlignedVector3(const MatrixBase<Derived>& other) - { - generic_assign_selector<Derived>::run(*this,other.derived()); - } - - inline AlignedVector3& operator=(const AlignedVector3& other) - { m_coeffs = other.m_coeffs; return *this; } - - template <typename Derived> - inline AlignedVector3& operator=(const MatrixBase<Derived>& other) - { - generic_assign_selector<Derived>::run(*this,other.derived()); - return *this; - } - - inline AlignedVector3 operator+(const AlignedVector3& other) const - { return AlignedVector3(m_coeffs + other.m_coeffs); } - - inline AlignedVector3& operator+=(const AlignedVector3& other) - { m_coeffs += other.m_coeffs; return *this; } - - inline AlignedVector3 operator-(const AlignedVector3& other) const - { return AlignedVector3(m_coeffs - other.m_coeffs); } - - inline AlignedVector3 operator-() const - { return AlignedVector3(-m_coeffs); } - - inline AlignedVector3 operator-=(const AlignedVector3& other) - { m_coeffs -= other.m_coeffs; return *this; } - - inline AlignedVector3 operator*(const Scalar& s) const - { return AlignedVector3(m_coeffs * s); } - - inline friend AlignedVector3 operator*(const Scalar& s,const AlignedVector3& vec) - { return AlignedVector3(s * vec.m_coeffs); } - - inline AlignedVector3& operator*=(const Scalar& s) - { m_coeffs *= s; return *this; } - - inline AlignedVector3 operator/(const Scalar& s) const - { return AlignedVector3(m_coeffs / s); } - - inline AlignedVector3& operator/=(const Scalar& s) - { m_coeffs /= s; return *this; } - - inline Scalar dot(const AlignedVector3& other) const - { - eigen_assert(m_coeffs.w()==Scalar(0)); - eigen_assert(other.m_coeffs.w()==Scalar(0)); - return m_coeffs.dot(other.m_coeffs); - } - - inline void normalize() - { - m_coeffs /= norm(); - } - - inline AlignedVector3 normalized() const - { - return AlignedVector3(m_coeffs / norm()); - } - - inline Scalar sum() const - { - eigen_assert(m_coeffs.w()==Scalar(0)); - return m_coeffs.sum(); - } - - inline Scalar squaredNorm() const - { - eigen_assert(m_coeffs.w()==Scalar(0)); - return m_coeffs.squaredNorm(); - } - - inline Scalar norm() const - { - using std::sqrt; - return sqrt(squaredNorm()); - } - - inline AlignedVector3 cross(const AlignedVector3& other) const - { - return AlignedVector3(m_coeffs.cross3(other.m_coeffs)); - } - - template<typename Derived> - inline bool isApprox(const MatrixBase<Derived>& other, const RealScalar& eps=NumTraits<Scalar>::dummy_precision()) const - { - return m_coeffs.template head<3>().isApprox(other,eps); - } - - CoeffType& coeffs() { return m_coeffs; } - const CoeffType& coeffs() const { return m_coeffs; } -}; - -namespace internal { - -template<typename _Scalar> -struct eval<AlignedVector3<_Scalar>, Dense> -{ - typedef const AlignedVector3<_Scalar>& type; -}; - -template<typename Scalar> -struct evaluator<AlignedVector3<Scalar> > - : evaluator<Matrix<Scalar,4,1> > -{ - typedef AlignedVector3<Scalar> XprType; - typedef evaluator<Matrix<Scalar,4,1> > Base; - - evaluator(const XprType &m) : Base(m.coeffs()) {} -}; - -} - -//@} - -} - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_ALIGNED_VECTOR3 diff --git a/external/eigen/include/eigen3/unsupported/Eigen/ArpackSupport b/external/eigen/include/eigen3/unsupported/Eigen/ArpackSupport deleted file mode 100644 index 28c95ffa..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/ArpackSupport +++ /dev/null @@ -1,31 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ARPACKSUPPORT_MODULE_H -#define EIGEN_ARPACKSUPPORT_MODULE_H - -#include "../../Eigen/Core" - -/** \defgroup ArpackSupport_Module Arpack support module - * - * This module provides a wrapper to Arpack, a library for sparse eigenvalue decomposition. - * - * \code - * #include <Eigen/ArpackSupport> - * \endcode - */ - -#include "../../Eigen/SparseCholesky" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" -#include "src/Eigenvalues/ArpackSelfAdjointEigenSolver.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_ARPACKSUPPORT_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/AutoDiff b/external/eigen/include/eigen3/unsupported/Eigen/AutoDiff deleted file mode 100644 index 7a4ff460..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/AutoDiff +++ /dev/null @@ -1,46 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <g.gael@free.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_AUTODIFF_MODULE -#define EIGEN_AUTODIFF_MODULE - -namespace Eigen { - -/** - * \defgroup AutoDiff_Module Auto Diff module - * - * This module features forward automatic differentation via a simple - * templated scalar type wrapper AutoDiffScalar. - * - * Warning : this should NOT be confused with numerical differentiation, which - * is a different method and has its own module in Eigen : \ref NumericalDiff_Module. - * - * \code - * #include <unsupported/Eigen/AutoDiff> - * \endcode - */ -//@{ - -} -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - - -#include "src/AutoDiff/AutoDiffScalar.h" -// #include "src/AutoDiff/AutoDiffVector.h" -#include "src/AutoDiff/AutoDiffJacobian.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - - - -namespace Eigen { -//@} -} - -#endif // EIGEN_AUTODIFF_MODULE diff --git a/external/eigen/include/eigen3/unsupported/Eigen/BVH b/external/eigen/include/eigen3/unsupported/Eigen/BVH deleted file mode 100644 index 666c9835..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/BVH +++ /dev/null @@ -1,95 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Ilya Baran <ibaran@mit.edu> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BVH_MODULE_H -#define EIGEN_BVH_MODULE_H - -#include "../../Eigen/Core" -#include "../../Eigen/Geometry" -#include "../../Eigen/StdVector" -#include <algorithm> -#include <queue> - -namespace Eigen { - -/** - * \defgroup BVH_Module BVH module - * \brief This module provides generic bounding volume hierarchy algorithms - * and reference tree implementations. - * - * - * \code - * #include <unsupported/Eigen/BVH> - * \endcode - * - * A bounding volume hierarchy (BVH) can accelerate many geometric queries. This module provides a generic implementation - * of the two basic algorithms over a BVH: intersection of a query object against all objects in the hierarchy and minimization - * of a function over the objects in the hierarchy. It also provides intersection and minimization over a cartesian product of - * two BVH's. A BVH accelerates intersection by using the fact that if a query object does not intersect a volume, then it cannot - * intersect any object contained in that volume. Similarly, a BVH accelerates minimization because the minimum of a function - * over a volume is no greater than the minimum of a function over any object contained in it. - * - * Some sample queries that can be written in terms of intersection are: - * - Determine all points where a ray intersects a triangle mesh - * - Given a set of points, determine which are contained in a query sphere - * - Given a set of spheres, determine which contain the query point - * - Given a set of disks, determine if any is completely contained in a query rectangle (represent each 2D disk as a point \f$(x,y,r)\f$ - * in 3D and represent the rectangle as a pyramid based on the original rectangle and shrinking in the \f$r\f$ direction) - * - Given a set of points, count how many pairs are \f$d\pm\epsilon\f$ apart (done by looking at the cartesian product of the set - * of points with itself) - * - * Some sample queries that can be written in terms of function minimization over a set of objects are: - * - Find the intersection between a ray and a triangle mesh closest to the ray origin (function is infinite off the ray) - * - Given a polyline and a query point, determine the closest point on the polyline to the query - * - Find the diameter of a point cloud (done by looking at the cartesian product and using negative distance as the function) - * - Determine how far two meshes are from colliding (this is also a cartesian product query) - * - * This implementation decouples the basic algorithms both from the type of hierarchy (and the types of the bounding volumes) and - * from the particulars of the query. To enable abstraction from the BVH, the BVH is required to implement a generic mechanism - * for traversal. To abstract from the query, the query is responsible for keeping track of results. - * - * To be used in the algorithms, a hierarchy must implement the following traversal mechanism (see KdBVH for a sample implementation): \code - typedef Volume //the type of bounding volume - typedef Object //the type of object in the hierarchy - typedef Index //a reference to a node in the hierarchy--typically an int or a pointer - typedef VolumeIterator //an iterator type over node children--returns Index - typedef ObjectIterator //an iterator over object (leaf) children--returns const Object & - Index getRootIndex() const //returns the index of the hierarchy root - const Volume &getVolume(Index index) const //returns the bounding volume of the node at given index - void getChildren(Index index, VolumeIterator &outVBegin, VolumeIterator &outVEnd, - ObjectIterator &outOBegin, ObjectIterator &outOEnd) const - //getChildren takes a node index and makes [outVBegin, outVEnd) range over its node children - //and [outOBegin, outOEnd) range over its object children - \endcode - * - * To use the hierarchy, call BVIntersect or BVMinimize, passing it a BVH (or two, for cartesian product) and a minimizer or intersector. - * For an intersection query on a single BVH, the intersector encapsulates the query and must provide two functions: - * \code - bool intersectVolume(const Volume &volume) //returns true if the query intersects the volume - bool intersectObject(const Object &object) //returns true if the intersection search should terminate immediately - \endcode - * The guarantee that BVIntersect provides is that intersectObject will be called on every object whose bounding volume - * intersects the query (but possibly on other objects too) unless the search is terminated prematurely. It is the - * responsibility of the intersectObject function to keep track of the results in whatever manner is appropriate. - * The cartesian product intersection and the BVMinimize queries are similar--see their individual documentation. - * - * The following is a simple but complete example for how to use the BVH to accelerate the search for a closest red-blue point pair: - * \include BVH_Example.cpp - * Output: \verbinclude BVH_Example.out - */ -} - -//@{ - -#include "src/BVH/BVAlgorithms.h" -#include "src/BVH/KdBVH.h" - -//@} - -#endif // EIGEN_BVH_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/Tensor b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/Tensor deleted file mode 100644 index 2640f956..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/Tensor +++ /dev/null @@ -1,157 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -//#ifndef EIGEN_CXX11_TENSOR_MODULE -//#define EIGEN_CXX11_TENSOR_MODULE - -#include "../../../Eigen/Core" - -#if EIGEN_HAS_CXX11 - -#include "../SpecialFunctions" - -#include "../../../Eigen/src/Core/util/DisableStupidWarnings.h" -#include "src/util/CXX11Meta.h" -#include "src/util/MaxSizeVector.h" - -/** \defgroup CXX11_Tensor_Module Tensor Module - * - * This module provides a Tensor class for storing arbitrarily indexed - * objects. - * - * \code - * #include <Eigen/CXX11/Tensor> - * \endcode - * - * Much of the documentation can be found \ref eigen_tensors "here". - */ - -#include <cmath> -#include <cstddef> -#include <cstring> -#include <random> - -#ifdef _WIN32 -typedef __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -#include <windows.h> -#else -#include <stdint.h> -#include <unistd.h> -#endif - -#ifdef _WIN32 -#include <windows.h> -#elif defined(__APPLE__) -#include <mach/mach_time.h> -#else -#include <time.h> -#endif - -#if defined(EIGEN_USE_THREADS) || defined(EIGEN_USE_SYCL) -#include "ThreadPool" -#endif - -#ifdef EIGEN_USE_GPU - #include <iostream> - #if defined(EIGEN_USE_HIP) - #include <hip/hip_runtime.h> - #else - #include <cuda_runtime.h> - #endif - #include <atomic> - #include <unistd.h> -#endif - -#include "src/Tensor/TensorMacros.h" -#include "src/Tensor/TensorForwardDeclarations.h" -#include "src/Tensor/TensorMeta.h" -#include "src/Tensor/TensorFunctors.h" -#include "src/Tensor/TensorCostModel.h" -#include "src/Tensor/TensorDeviceDefault.h" -#include "src/Tensor/TensorDeviceThreadPool.h" -#include "src/Tensor/TensorDeviceGpu.h" -#ifndef gpu_assert -#define gpu_assert(x) -#endif -#include "src/Tensor/TensorDeviceSycl.h" -#include "src/Tensor/TensorIndexList.h" -#include "src/Tensor/TensorDimensionList.h" -#include "src/Tensor/TensorDimensions.h" -#include "src/Tensor/TensorInitializer.h" -#include "src/Tensor/TensorTraits.h" -#include "src/Tensor/TensorRandom.h" -#include "src/Tensor/TensorUInt128.h" -#include "src/Tensor/TensorIntDiv.h" -#include "src/Tensor/TensorGlobalFunctions.h" - -#include "src/Tensor/TensorBase.h" -#include "src/Tensor/TensorBlock.h" - -#include "src/Tensor/TensorEvaluator.h" -#include "src/Tensor/TensorExpr.h" -#include "src/Tensor/TensorReduction.h" -#include "src/Tensor/TensorReductionGpu.h" -#include "src/Tensor/TensorArgMax.h" -#include "src/Tensor/TensorConcatenation.h" -#include "src/Tensor/TensorContractionMapper.h" -#include "src/Tensor/TensorContractionBlocking.h" -#include "src/Tensor/TensorContraction.h" -#include "src/Tensor/TensorContractionThreadPool.h" -#include "src/Tensor/TensorContractionGpu.h" -#include "src/Tensor/TensorConversion.h" -#include "src/Tensor/TensorConvolution.h" -#include "src/Tensor/TensorFFT.h" -#include "src/Tensor/TensorPatch.h" -#include "src/Tensor/TensorImagePatch.h" -#include "src/Tensor/TensorVolumePatch.h" -#include "src/Tensor/TensorBroadcasting.h" -#include "src/Tensor/TensorChipping.h" -#include "src/Tensor/TensorInflation.h" -#include "src/Tensor/TensorLayoutSwap.h" -#include "src/Tensor/TensorMorphing.h" -#include "src/Tensor/TensorPadding.h" -#include "src/Tensor/TensorReverse.h" -#include "src/Tensor/TensorShuffling.h" -#include "src/Tensor/TensorStriding.h" -#include "src/Tensor/TensorCustomOp.h" -#include "src/Tensor/TensorEvalTo.h" -#include "src/Tensor/TensorForcedEval.h" -#include "src/Tensor/TensorGenerator.h" -#include "src/Tensor/TensorAssign.h" -#include "src/Tensor/TensorScan.h" -#include "src/Tensor/TensorTrace.h" - -#ifdef EIGEN_USE_SYCL -#include "src/Tensor/TensorReductionSycl.h" -#include "src/Tensor/TensorConvolutionSycl.h" -#include "src/Tensor/TensorContractionSycl.h" -#include "src/Tensor/TensorScanSycl.h" -#endif - -#include "src/Tensor/TensorExecutor.h" -#include "src/Tensor/TensorDevice.h" - -#include "src/Tensor/TensorStorage.h" -#include "src/Tensor/Tensor.h" -#include "src/Tensor/TensorFixedSize.h" -#include "src/Tensor/TensorMap.h" -#include "src/Tensor/TensorRef.h" - -#include "src/Tensor/TensorIO.h" - -#include "../../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_HAS_CXX11 -//#endif // EIGEN_CXX11_TENSOR_MODULE diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/TensorSymmetry b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/TensorSymmetry deleted file mode 100644 index b09c5e47..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/TensorSymmetry +++ /dev/null @@ -1,42 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSORSYMMETRY_MODULE -#define EIGEN_CXX11_TENSORSYMMETRY_MODULE - -#include "Tensor" - -#include "../../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#include "src/util/CXX11Meta.h" - -/** \defgroup CXX11_TensorSymmetry_Module Tensor Symmetry Module - * - * This module provides a classes that allow for the definition of - * symmetries w.r.t. tensor indices. - * - * Including this module will implicitly include the Tensor module. - * - * \code - * #include <Eigen/TensorSymmetry> - * \endcode - */ - -#include "src/TensorSymmetry/util/TemplateGroupTheory.h" -#include "src/TensorSymmetry/Symmetry.h" -#include "src/TensorSymmetry/StaticSymmetry.h" -#include "src/TensorSymmetry/DynamicSymmetry.h" - -#include "../../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_CXX11_TENSORSYMMETRY_MODULE - -/* - * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; - */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/ThreadPool b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/ThreadPool deleted file mode 100644 index 71a6afe3..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/ThreadPool +++ /dev/null @@ -1,75 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_MODULE -#define EIGEN_CXX11_THREADPOOL_MODULE - -#include "../../../Eigen/Core" - -#include "../../../Eigen/src/Core/util/DisableStupidWarnings.h" - -/** \defgroup CXX11_ThreadPool_Module C++11 ThreadPool Module - * - * This module provides 2 threadpool implementations - * - a simple reference implementation - * - a faster non blocking implementation - * - * This module requires C++11. - * - * \code - * #include <Eigen/CXX11/ThreadPool> - * \endcode - */ - - -// The code depends on CXX11, so only include the module if the -// compiler supports it. -#if __cplusplus > 199711L || EIGEN_COMP_MSVC >= 1900 -#include <cstddef> -#include <cstring> -#include <stdint.h> -#include <time.h> - -#include <vector> -#include <atomic> -#include <condition_variable> -#include <deque> -#include <mutex> -#include <thread> -#include <functional> -#include <memory> -#include <utility> - -// There are non-parenthesized calls to "max" in the <unordered_map> header, -// which trigger a check in test/main.h causing compilation to fail. -// We work around the check here by removing the check for max in -// the case where we have to emulate thread_local. -#ifdef max -#undef max -#endif -#include <unordered_map> - -#include "src/util/CXX11Meta.h" -#include "src/util/MaxSizeVector.h" - -#include "src/ThreadPool/ThreadLocal.h" -#include "src/ThreadPool/ThreadYield.h" -#include "src/ThreadPool/ThreadCancel.h" -#include "src/ThreadPool/EventCount.h" -#include "src/ThreadPool/RunQueue.h" -#include "src/ThreadPool/ThreadPoolInterface.h" -#include "src/ThreadPool/ThreadEnvironment.h" -#include "src/ThreadPool/Barrier.h" -#include "src/ThreadPool/NonBlockingThreadPool.h" - -#endif - -#include "../../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_CXX11_THREADPOOL_MODULE diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/Tensor.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/Tensor.h deleted file mode 100644 index 17cee495..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/Tensor.h +++ /dev/null @@ -1,554 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_H -#define EIGEN_CXX11_TENSOR_TENSOR_H - -namespace Eigen { - -/** \class Tensor - * \ingroup CXX11_Tensor_Module - * - * \brief The tensor class. - * - * The %Tensor class is the work-horse for all \em dense tensors within Eigen. - * - * The %Tensor class encompasses only dynamic-size objects so far. - * - * The first two template parameters are required: - * \tparam Scalar_ Numeric type, e.g. float, double, int or `std::complex<float>`. - * User defined scalar types are supported as well (see \ref user_defined_scalars "here"). - * \tparam NumIndices_ Number of indices (i.e. rank of the tensor) - * - * The remaining template parameters are optional -- in most cases you don't have to worry about them. - * \tparam Options_ A combination of either \b #RowMajor or \b #ColMajor, and of either - * \b #AutoAlign or \b #DontAlign. - * The former controls \ref TopicStorageOrders "storage order", and defaults to column-major. The latter controls alignment, which is required - * for vectorization. It defaults to aligning tensors. Note that tensors currently do not support any operations that profit from vectorization. - * Support for such operations (i.e. adding two tensors etc.) is planned. - * - * You can access elements of tensors using normal subscripting: - * - * \code - * Eigen::Tensor<double, 4> t(10, 10, 10, 10); - * t(0, 1, 2, 3) = 42.0; - * \endcode - * - * This class can be extended with the help of the plugin mechanism described on the page - * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_TENSOR_PLUGIN. - * - * <i><b>Some notes:</b></i> - * - * <dl> - * <dt><b>Relation to other parts of Eigen:</b></dt> - * <dd>The midterm development goal for this class is to have a similar hierarchy as Eigen uses for matrices, so that - * taking blocks or using tensors in expressions is easily possible, including an interface with the vector/matrix code - * by providing .asMatrix() and .asVector() (or similar) methods for rank 2 and 1 tensors. However, currently, the %Tensor - * class does not provide any of these features and is only available as a stand-alone class that just allows for - * coefficient access. Also, when fixed-size tensors are implemented, the number of template arguments is likely to - * change dramatically.</dd> - * </dl> - * - * \ref TopicStorageOrders - */ - -template<typename Scalar_, int NumIndices_, int Options_, typename IndexType_> -class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexType_> > -{ - public: - typedef Tensor<Scalar_, NumIndices_, Options_, IndexType_> Self; - typedef TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexType_> > Base; - typedef typename Eigen::internal::nested<Self>::type Nested; - typedef typename internal::traits<Self>::StorageKind StorageKind; - typedef typename internal::traits<Self>::Index Index; - typedef Scalar_ Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef typename Base::CoeffReturnType CoeffReturnType; - - enum { - IsAligned = bool(EIGEN_MAX_ALIGN_BYTES>0) & !(Options_&DontAlign), - Layout = Options_ & RowMajor ? RowMajor : ColMajor, - CoordAccess = true, - RawAccess = true - }; - - static const int Options = Options_; - static const int NumIndices = NumIndices_; - typedef DSizes<Index, NumIndices_> Dimensions; - - protected: - TensorStorage<Scalar, Dimensions, Options> m_storage; - -#ifdef EIGEN_HAS_SFINAE - template<typename CustomIndices> - struct isOfNormalIndex{ - static const bool is_array = internal::is_base_of<array<Index, NumIndices>, CustomIndices>::value; - static const bool is_int = NumTraits<CustomIndices>::IsInteger; - static const bool value = is_array | is_int; - }; -#endif - - public: - // Metadata - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { return NumIndices; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const { return m_storage.dimensions()[n]; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_storage.dimensions(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_storage.size(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() { return m_storage.data(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar *data() const { return m_storage.data(); } - - // This makes EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - // work, because that uses base().coeffRef() - and we don't yet - // implement a similar class hierarchy - inline Self& base() { return *this; } - inline const Self& base() const { return *this; } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) const - { - // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - return coeff(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}}); - } -#endif - - // normal indices - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(const array<Index, NumIndices>& indices) const - { - eigen_internal_assert(checkIndexRange(indices)); - return m_storage.data()[linearizedIndex(indices)]; - } - - // custom indices -#ifdef EIGEN_HAS_SFINAE - template<typename CustomIndices, - EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomIndices>::value) ) - > - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(CustomIndices& indices) const - { - return coeff(internal::customIndices2Array<Index,NumIndices>(indices)); - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff() const - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - return m_storage.data()[0]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const - { - eigen_internal_assert(index >= 0 && index < size()); - return m_storage.data()[index]; - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - inline Scalar& coeffRef(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) - { - // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - return coeffRef(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}}); - } -#endif - - // normal indices - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(const array<Index, NumIndices>& indices) - { - eigen_internal_assert(checkIndexRange(indices)); - return m_storage.data()[linearizedIndex(indices)]; - } - - // custom indices -#ifdef EIGEN_HAS_SFINAE - template<typename CustomIndices, - EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomIndices>::value) ) - > - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(CustomIndices& indices) - { - return coeffRef(internal::customIndices2Array<Index,NumIndices>(indices)); - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef() - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - return m_storage.data()[0]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) - { - eigen_internal_assert(index >= 0 && index < size()); - return m_storage.data()[index]; - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - inline const Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) const - { - // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - return this->operator()(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}}); - } -#else - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index i0, Index i1) const - { - return coeff(array<Index, 2>(i0, i1)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index i0, Index i1, Index i2) const - { - return coeff(array<Index, 3>(i0, i1, i2)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index i0, Index i1, Index i2, Index i3) const - { - return coeff(array<Index, 4>(i0, i1, i2, i3)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4) const - { - return coeff(array<Index, 5>(i0, i1, i2, i3, i4)); - } -#endif - - // custom indices -#ifdef EIGEN_HAS_SFINAE - template<typename CustomIndices, - EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomIndices>::value) ) - > - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator()(CustomIndices& indices) const - { - return coeff(internal::customIndices2Array<Index,NumIndices>(indices)); - } -#endif - - // normal indices - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator()(const array<Index, NumIndices>& indices) const - { - return coeff(indices); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator()(Index index) const - { - eigen_internal_assert(index >= 0 && index < size()); - return coeff(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator()() const - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - return coeff(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator[](Index index) const - { - // The bracket operator is only for vectors, use the parenthesis operator instead. - EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE); - return coeff(index); - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - inline Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) - { - // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - return operator()(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}}); - } -#else - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1) - { - return coeffRef(array<Index, 2>(i0, i1)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2) - { - return coeffRef(array<Index, 3>(i0, i1, i2)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3) - { - return coeffRef(array<Index, 4>(i0, i1, i2, i3)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4) - { - return coeffRef(array<Index, 5>(i0, i1, i2, i3, i4)); - } -#endif - - // normal indices - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(const array<Index, NumIndices>& indices) - { - return coeffRef(indices); - } - - // custom indices -#ifdef EIGEN_HAS_SFINAE - template<typename CustomIndices, - EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomIndices>::value) ) - > - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(CustomIndices& indices) - { - return coeffRef(internal::customIndices2Array<Index,NumIndices>(indices)); - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index index) - { - eigen_assert(index >= 0 && index < size()); - return coeffRef(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()() - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - return coeffRef(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator[](Index index) - { - // The bracket operator is only for vectors, use the parenthesis operator instead - EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE) - return coeffRef(index); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Tensor() - : m_storage() - { - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Tensor(const Self& other) - : m_storage(other.m_storage) - { - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index firstDimension, IndexTypes... otherDimensions) - : m_storage(firstDimension, otherDimensions...) - { - // The number of dimensions used to construct a tensor must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherDimensions) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - } -#else - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Tensor(Index dim1) - : m_storage(dim1, array<Index, 1>(dim1)) - { - EIGEN_STATIC_ASSERT(1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index dim1, Index dim2) - : m_storage(dim1*dim2, array<Index, 2>(dim1, dim2)) - { - EIGEN_STATIC_ASSERT(2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index dim1, Index dim2, Index dim3) - : m_storage(dim1*dim2*dim3, array<Index, 3>(dim1, dim2, dim3)) - { - EIGEN_STATIC_ASSERT(3 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index dim1, Index dim2, Index dim3, Index dim4) - : m_storage(dim1*dim2*dim3*dim4, array<Index, 4>(dim1, dim2, dim3, dim4)) - { - EIGEN_STATIC_ASSERT(4 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index dim1, Index dim2, Index dim3, Index dim4, Index dim5) - : m_storage(dim1*dim2*dim3*dim4*dim5, array<Index, 5>(dim1, dim2, dim3, dim4, dim5)) - { - EIGEN_STATIC_ASSERT(5 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - } -#endif - - /** Normal Dimension */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Tensor(const array<Index, NumIndices>& dimensions) - : m_storage(internal::array_prod(dimensions), dimensions) - { - EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Tensor(const TensorBase<OtherDerived, ReadOnlyAccessors>& other) - { - typedef TensorAssignOp<Tensor, const OtherDerived> Assign; - Assign assign(*this, other.derived()); - resize(TensorEvaluator<const Assign, DefaultDevice>(assign, DefaultDevice()).dimensions()); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - } - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Tensor(const TensorBase<OtherDerived, WriteAccessors>& other) - { - typedef TensorAssignOp<Tensor, const OtherDerived> Assign; - Assign assign(*this, other.derived()); - resize(TensorEvaluator<const Assign, DefaultDevice>(assign, DefaultDevice()).dimensions()); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - } - - #if EIGEN_HAS_RVALUE_REFERENCES - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Tensor(Self&& other) - : Tensor() - { - m_storage.swap(other.m_storage); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Tensor& operator=(Self&& other) - { - m_storage.swap(other.m_storage); - return *this; - } - #endif - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Tensor& operator=(const Tensor& other) - { - typedef TensorAssignOp<Tensor, const Tensor> Assign; - Assign assign(*this, other); - resize(TensorEvaluator<const Assign, DefaultDevice>(assign, DefaultDevice()).dimensions()); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Tensor& operator=(const OtherDerived& other) - { - typedef TensorAssignOp<Tensor, const OtherDerived> Assign; - Assign assign(*this, other); - resize(TensorEvaluator<const Assign, DefaultDevice>(assign, DefaultDevice()).dimensions()); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> EIGEN_DEVICE_FUNC - void resize(Index firstDimension, IndexTypes... otherDimensions) - { - // The number of dimensions used to resize a tensor must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherDimensions) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - resize(array<Index, NumIndices>{{firstDimension, otherDimensions...}}); - } -#endif - - /** Normal Dimension */ - EIGEN_DEVICE_FUNC void resize(const array<Index, NumIndices>& dimensions) - { - int i; - Index size = Index(1); - for (i = 0; i < NumIndices; i++) { - internal::check_rows_cols_for_overflow<Dynamic>::run(size, dimensions[i]); - size *= dimensions[i]; - } - #ifdef EIGEN_INITIALIZE_COEFFS - bool size_changed = size != this->size(); - m_storage.resize(size, dimensions); - if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - #else - m_storage.resize(size, dimensions); - #endif - } - - // Why this overload, DSizes is derived from array ??? // - EIGEN_DEVICE_FUNC void resize(const DSizes<Index, NumIndices>& dimensions) { - array<Index, NumIndices> dims; - for (int i = 0; i < NumIndices; ++i) { - dims[i] = dimensions[i]; - } - resize(dims); - } - - EIGEN_DEVICE_FUNC - void resize() - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - // Nothing to do: rank 0 tensors have fixed size - } - -#ifdef EIGEN_HAS_INDEX_LIST - template <typename FirstType, typename... OtherTypes> - EIGEN_DEVICE_FUNC - void resize(const Eigen::IndexList<FirstType, OtherTypes...>& dimensions) { - array<Index, NumIndices> dims; - for (int i = 0; i < NumIndices; ++i) { - dims[i] = static_cast<Index>(dimensions[i]); - } - resize(dims); - } -#endif - - /** Custom Dimension */ -#ifdef EIGEN_HAS_SFINAE - template<typename CustomDimension, - EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomDimension>::value) ) - > - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(CustomDimension& dimensions) - { - resize(internal::customIndices2Array<Index,NumIndices>(dimensions)); - } -#endif - -#ifndef EIGEN_EMULATE_CXX11_META_H - template <typename std::ptrdiff_t... Indices> - EIGEN_DEVICE_FUNC - void resize(const Sizes<Indices...>& dimensions) { - array<Index, NumIndices> dims; - for (int i = 0; i < NumIndices; ++i) { - dims[i] = static_cast<Index>(dimensions[i]); - } - resize(dims); - } -#else - template <std::size_t V1, std::size_t V2, std::size_t V3, std::size_t V4, std::size_t V5> - EIGEN_DEVICE_FUNC - void resize(const Sizes<V1, V2, V3, V4, V5>& dimensions) { - array<Index, NumIndices> dims; - for (int i = 0; i < NumIndices; ++i) { - dims[i] = static_cast<Index>(dimensions[i]); - } - resize(dims); - } -#endif - - protected: - - bool checkIndexRange(const array<Index, NumIndices>& indices) const - { - using internal::array_apply_and_reduce; - using internal::array_zip_and_reduce; - using internal::greater_equal_zero_op; - using internal::logical_and_op; - using internal::lesser_op; - - return - // check whether the indices are all >= 0 - array_apply_and_reduce<logical_and_op, greater_equal_zero_op>(indices) && - // check whether the indices fit in the dimensions - array_zip_and_reduce<logical_and_op, lesser_op>(indices, m_storage.dimensions()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index linearizedIndex(const array<Index, NumIndices>& indices) const - { - if (Options&RowMajor) { - return m_storage.dimensions().IndexOfRowMajor(indices); - } else { - return m_storage.dimensions().IndexOfColMajor(indices); - } - } -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorArgMax.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorArgMax.h deleted file mode 100644 index 91a6f8d6..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorArgMax.h +++ /dev/null @@ -1,329 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Eugene Brevdo <ebrevdo@gmail.com> -// Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_ARG_MAX_H -#define EIGEN_CXX11_TENSOR_TENSOR_ARG_MAX_H - -namespace Eigen { -namespace internal { - -/** \class TensorIndexTuple - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor + Index Tuple class. - * - * - */ -template<typename XprType> -struct traits<TensorIndexTupleOp<XprType> > : public traits<XprType> -{ - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef Tuple<Index, typename XprTraits::Scalar> Scalar; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; -}; - -template<typename XprType> -struct eval<TensorIndexTupleOp<XprType>, Eigen::Dense> -{ - typedef const TensorIndexTupleOp<XprType>EIGEN_DEVICE_REF type; -}; - -template<typename XprType> -struct nested<TensorIndexTupleOp<XprType>, 1, - typename eval<TensorIndexTupleOp<XprType> >::type> -{ - typedef TensorIndexTupleOp<XprType> type; -}; - -} // end namespace internal - -template<typename XprType> -class TensorIndexTupleOp : public TensorBase<TensorIndexTupleOp<XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorIndexTupleOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename Eigen::internal::nested<TensorIndexTupleOp>::type Nested; - typedef typename Eigen::internal::traits<TensorIndexTupleOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorIndexTupleOp>::Index Index; - typedef Tuple<Index, typename XprType::CoeffReturnType> CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorIndexTupleOp(const XprType& expr) - : m_xpr(expr) {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; -}; - -// Eval as rvalue -template<typename ArgType, typename Device> -struct TensorEvaluator<const TensorIndexTupleOp<ArgType>, Device> -{ - typedef TensorIndexTupleOp<ArgType> XprType; - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - - typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions; - static const int NumDims = internal::array_size<Dimensions>::value; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = /*TensorEvaluator<ArgType, Device>::IsAligned*/ false, - PacketAccess = /*TensorEvaluator<ArgType, Device>::PacketAccess*/ false, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device) { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { - return m_impl.dimensions(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return CoeffReturnType(index, m_impl.coeff(index)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - return m_impl.costPerCoeff(vectorized) + TensorOpCost(0, 0, 1); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - protected: - TensorEvaluator<ArgType, Device> m_impl; -}; - -namespace internal { - -/** \class TensorTupleIndex - * \ingroup CXX11_Tensor_Module - * - * \brief Converts to Tensor<Tuple<Index, Scalar> > and reduces to Tensor<Index>. - * - */ -template<typename ReduceOp, typename Dims, typename XprType> -struct traits<TensorTupleReducerOp<ReduceOp, Dims, XprType> > : public traits<XprType> -{ - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef Index Scalar; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions - array_size<Dims>::value; - static const int Layout = XprTraits::Layout; -}; - -template<typename ReduceOp, typename Dims, typename XprType> -struct eval<TensorTupleReducerOp<ReduceOp, Dims, XprType>, Eigen::Dense> -{ - typedef const TensorTupleReducerOp<ReduceOp, Dims, XprType>EIGEN_DEVICE_REF type; -}; - -template<typename ReduceOp, typename Dims, typename XprType> -struct nested<TensorTupleReducerOp<ReduceOp, Dims, XprType>, 1, - typename eval<TensorTupleReducerOp<ReduceOp, Dims, XprType> >::type> -{ - typedef TensorTupleReducerOp<ReduceOp, Dims, XprType> type; -}; - -} // end namespace internal - -template<typename ReduceOp, typename Dims, typename XprType> -class TensorTupleReducerOp : public TensorBase<TensorTupleReducerOp<ReduceOp, Dims, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorTupleReducerOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename Eigen::internal::nested<TensorTupleReducerOp>::type Nested; - typedef typename Eigen::internal::traits<TensorTupleReducerOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorTupleReducerOp>::Index Index; - typedef Index CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorTupleReducerOp(const XprType& expr, - const ReduceOp& reduce_op, - const Index return_dim, - const Dims& reduce_dims) - : m_xpr(expr), m_reduce_op(reduce_op), m_return_dim(return_dim), m_reduce_dims(reduce_dims) {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - const ReduceOp& reduce_op() const { return m_reduce_op; } - - EIGEN_DEVICE_FUNC - const Dims& reduce_dims() const { return m_reduce_dims; } - - EIGEN_DEVICE_FUNC - Index return_dim() const { return m_return_dim; } - - protected: - typename XprType::Nested m_xpr; - const ReduceOp m_reduce_op; - const Index m_return_dim; - const Dims m_reduce_dims; -}; - -// Eval as rvalue -template<typename ReduceOp, typename Dims, typename ArgType, typename Device> -struct TensorEvaluator<const TensorTupleReducerOp<ReduceOp, Dims, ArgType>, Device> -{ - typedef TensorTupleReducerOp<ReduceOp, Dims, ArgType> XprType; - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename TensorIndexTupleOp<ArgType>::CoeffReturnType TupleType; - typedef typename TensorEvaluator<const TensorReductionOp<ReduceOp, Dims, const TensorIndexTupleOp<ArgType> >, Device>::Dimensions Dimensions; - typedef typename TensorEvaluator<const TensorIndexTupleOp<ArgType> , Device>::Dimensions InputDimensions; - static const int NumDims = internal::array_size<InputDimensions>::value; - typedef array<Index, NumDims> StrideDims; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - typedef StorageMemory<TupleType, Device> TupleStorageMem; - - enum { - IsAligned = /*TensorEvaluator<ArgType, Device>::IsAligned*/ false, - PacketAccess = /*TensorEvaluator<ArgType, Device>::PacketAccess*/ false, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<const TensorReductionOp<ReduceOp, Dims, const TensorIndexTupleOp<ArgType> >, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_orig_impl(op.expression(), device), - m_impl(op.expression().index_tuples().reduce(op.reduce_dims(), op.reduce_op()), device), - m_return_dim(op.return_dim()) - { - gen_strides(m_orig_impl.dimensions(), m_strides); - if (Layout == static_cast<int>(ColMajor)) { - const Index total_size = internal::array_prod(m_orig_impl.dimensions()); - m_stride_mod = (m_return_dim < NumDims - 1) ? m_strides[m_return_dim + 1] : total_size; - } else { - const Index total_size = internal::array_prod(m_orig_impl.dimensions()); - m_stride_mod = (m_return_dim > 0) ? m_strides[m_return_dim - 1] : total_size; - } - // If m_return_dim is not a valid index, returns 1 or this can crash on Windows. - m_stride_div = ((m_return_dim >= 0) && - (m_return_dim < static_cast<Index>(m_strides.size()))) - ? m_strides[m_return_dim] : 1; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { - return m_impl.dimensions(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - const TupleType v = m_impl.coeff(index); - return (m_return_dim < 0) ? v.first : (v.first % m_stride_mod) / m_stride_div; - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } -#ifdef EIGEN_USE_SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - m_orig_impl.bind(cgh); - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - const double compute_cost = 1.0 + - (m_return_dim < 0 ? 0.0 : (TensorOpCost::ModCost<Index>() + TensorOpCost::DivCost<Index>())); - return m_orig_impl.costPerCoeff(vectorized) + - m_impl.costPerCoeff(vectorized) + TensorOpCost(0, 0, compute_cost); - } - - private: - EIGEN_DEVICE_FUNC void gen_strides(const InputDimensions& dims, StrideDims& strides) { - if (m_return_dim < 0) { - return; // Won't be using the strides. - } - eigen_assert(m_return_dim < NumDims && - "Asking to convert index to a dimension outside of the rank"); - - // Calculate m_stride_div and m_stride_mod, which are used to - // calculate the value of an index w.r.t. the m_return_dim. - if (Layout == static_cast<int>(ColMajor)) { - strides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - strides[i] = strides[i-1] * dims[i-1]; - } - } else { - strides[NumDims-1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - strides[i] = strides[i+1] * dims[i+1]; - } - } - } - - protected: - TensorEvaluator<const TensorIndexTupleOp<ArgType>, Device> m_orig_impl; - TensorEvaluator<const TensorReductionOp<ReduceOp, Dims, const TensorIndexTupleOp<ArgType> >, Device> m_impl; - const Index m_return_dim; - StrideDims m_strides; - Index m_stride_mod; - Index m_stride_div; -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_ARG_MAX_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h deleted file mode 100644 index 72f072cf..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h +++ /dev/null @@ -1,247 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H -#define EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H - -namespace Eigen { - -/** \class TensorAssign - * \ingroup CXX11_Tensor_Module - * - * \brief The tensor assignment class. - * - * This class is represents the assignment of the values resulting from the evaluation of - * the rhs expression to the memory locations denoted by the lhs expression. - */ -namespace internal { -template<typename LhsXprType, typename RhsXprType> -struct traits<TensorAssignOp<LhsXprType, RhsXprType> > -{ - typedef typename LhsXprType::Scalar Scalar; - typedef typename traits<LhsXprType>::StorageKind StorageKind; - typedef typename promote_index_type<typename traits<LhsXprType>::Index, - typename traits<RhsXprType>::Index>::type Index; - typedef typename LhsXprType::Nested LhsNested; - typedef typename RhsXprType::Nested RhsNested; - typedef typename remove_reference<LhsNested>::type _LhsNested; - typedef typename remove_reference<RhsNested>::type _RhsNested; - static const std::size_t NumDimensions = internal::traits<LhsXprType>::NumDimensions; - static const int Layout = internal::traits<LhsXprType>::Layout; - typedef typename traits<LhsXprType>::PointerType PointerType; - - enum { - Flags = 0 - }; -}; - -template<typename LhsXprType, typename RhsXprType> -struct eval<TensorAssignOp<LhsXprType, RhsXprType>, Eigen::Dense> -{ - typedef const TensorAssignOp<LhsXprType, RhsXprType>& type; -}; - -template<typename LhsXprType, typename RhsXprType> -struct nested<TensorAssignOp<LhsXprType, RhsXprType>, 1, typename eval<TensorAssignOp<LhsXprType, RhsXprType> >::type> -{ - typedef TensorAssignOp<LhsXprType, RhsXprType> type; -}; - -} // end namespace internal - - - -template<typename LhsXprType, typename RhsXprType> -class TensorAssignOp : public TensorBase<TensorAssignOp<LhsXprType, RhsXprType> > -{ - public: - typedef typename Eigen::internal::traits<TensorAssignOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename LhsXprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorAssignOp>::type Nested; - typedef typename Eigen::internal::traits<TensorAssignOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorAssignOp>::Index Index; - - static const int NumDims = Eigen::internal::traits<TensorAssignOp>::NumDimensions; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorAssignOp(LhsXprType& lhs, const RhsXprType& rhs) - : m_lhs_xpr(lhs), m_rhs_xpr(rhs) {} - - /** \returns the nested expressions */ - EIGEN_DEVICE_FUNC - typename internal::remove_all<typename LhsXprType::Nested>::type& - lhsExpression() const { return *((typename internal::remove_all<typename LhsXprType::Nested>::type*)&m_lhs_xpr); } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename RhsXprType::Nested>::type& - rhsExpression() const { return m_rhs_xpr; } - - protected: - typename internal::remove_all<typename LhsXprType::Nested>::type& m_lhs_xpr; - const typename internal::remove_all<typename RhsXprType::Nested>::type& m_rhs_xpr; -}; - - -template<typename LeftArgType, typename RightArgType, typename Device> -struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device> -{ - typedef TensorAssignOp<LeftArgType, RightArgType> XprType; - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef typename TensorEvaluator<RightArgType, Device>::Dimensions Dimensions; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - static const int NumDims = XprType::NumDims; - - enum { - IsAligned = TensorEvaluator<LeftArgType, Device>::IsAligned & - TensorEvaluator<RightArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<LeftArgType, Device>::PacketAccess & - TensorEvaluator<RightArgType, Device>::PacketAccess, - BlockAccess = TensorEvaluator<LeftArgType, Device>::BlockAccess & - TensorEvaluator<RightArgType, Device>::BlockAccess, - PreferBlockAccess = TensorEvaluator<LeftArgType, Device>::PreferBlockAccess | - TensorEvaluator<RightArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<LeftArgType, Device>::Layout, - RawAccess = TensorEvaluator<LeftArgType, Device>::RawAccess - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename TensorEvaluator<const RightArgType, Device>::TensorBlock - RightTensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) : - m_leftImpl(op.lhsExpression(), device), - m_rightImpl(op.rhsExpression(), device) - { - EIGEN_STATIC_ASSERT( - (static_cast<int>(TensorEvaluator<LeftArgType, Device>::Layout) == - static_cast<int>(TensorEvaluator<RightArgType, Device>::Layout)), - YOU_MADE_A_PROGRAMMING_MISTAKE); - } - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const - { - // The dimensions of the lhs and the rhs tensors should be equal to prevent - // overflows and ensure the result is fully initialized. - // TODO: use left impl instead if right impl dimensions are known at compile time. - return m_rightImpl.dimensions(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - eigen_assert(dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions())); - m_leftImpl.evalSubExprsIfNeeded(NULL); - // If the lhs provides raw access to its storage area (i.e. if m_leftImpl.data() returns a non - // null value), attempt to evaluate the rhs expression in place. Returns true iff in place - // evaluation isn't supported and the caller still needs to manually assign the values generated - // by the rhs to the lhs. - return m_rightImpl.evalSubExprsIfNeeded(m_leftImpl.data()); - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - m_leftImpl.evalSubExprsIfNeededAsync(nullptr, [this, done](bool) { - m_rightImpl.evalSubExprsIfNeededAsync( - m_leftImpl.data(), [done](bool need_assign) { done(need_assign); }); - }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_leftImpl.cleanup(); - m_rightImpl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i) { - m_leftImpl.coeffRef(i) = m_rightImpl.coeff(i); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i) { - - const int LhsStoreMode = TensorEvaluator<LeftArgType, Device>::IsAligned ? Aligned : Unaligned; - const int RhsLoadMode = TensorEvaluator<RightArgType, Device>::IsAligned ? Aligned : Unaligned; - m_leftImpl.template writePacket<LhsStoreMode>(i, m_rightImpl.template packet<RhsLoadMode>(i)); - } - EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const - { - return m_leftImpl.coeff(index); - } - template<int LoadMode> - EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const - { - return m_leftImpl.template packet<LoadMode>(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - // We assume that evalPacket or evalScalar is called to perform the - // assignment and account for the cost of the write here, but reduce left - // cost by one load because we are using m_leftImpl.coeffRef. - TensorOpCost left = m_leftImpl.costPerCoeff(vectorized); - return m_rightImpl.costPerCoeff(vectorized) + - TensorOpCost( - numext::maxi(0.0, left.bytes_loaded() - sizeof(CoeffReturnType)), - left.bytes_stored(), left.compute_cycles()) + - TensorOpCost(0, sizeof(CoeffReturnType), 0, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - return internal::TensorBlockResourceRequirements::merge( - m_leftImpl.getResourceRequirements(), - m_rightImpl.getResourceRequirements()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock( - TensorBlockDesc& desc, TensorBlockScratch& scratch) { - if (TensorEvaluator<LeftArgType, Device>::RawAccess && - m_leftImpl.data() != NULL) { - // If destination has raw data access, we pass it as a potential - // destination for a block descriptor evaluation. - desc.template AddDestinationBuffer<Layout>( - /*dst_base=*/m_leftImpl.data() + desc.offset(), - /*dst_strides=*/internal::strides<Layout>(m_leftImpl.dimensions())); - } - - RightTensorBlock block = m_rightImpl.block(desc, scratch, /*root_of_expr_ast=*/true); - // If block was evaluated into a destination, there is no need to do assignment. - if (block.kind() != internal::TensorBlockKind::kMaterializedInOutput) { - m_leftImpl.writeBlock(desc, block); - } - block.cleanup(); - } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_leftImpl.bind(cgh); - m_rightImpl.bind(cgh); - } -#endif - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_leftImpl.data(); } - - private: - TensorEvaluator<LeftArgType, Device> m_leftImpl; - TensorEvaluator<RightArgType, Device> m_rightImpl; -}; - -} - - -#endif // EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h deleted file mode 100644 index bb0969f4..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h +++ /dev/null @@ -1,1153 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_BASE_H -#define EIGEN_CXX11_TENSOR_TENSOR_BASE_H - -// clang-format off - -namespace Eigen { - -/** \class TensorBase - * \ingroup CXX11_Tensor_Module - * - * \brief The tensor base class. - * - * This class is the common parent of the Tensor and TensorMap class, thus - * making it possible to use either class interchangeably in expressions. - */ -#ifndef EIGEN_PARSED_BY_DOXYGEN -// FIXME Doxygen does not like the inheritance with different template parameters -// Since there is no doxygen documentation inside, we disable it for now -template<typename Derived> -class TensorBase<Derived, ReadOnlyAccessors> -{ - public: - typedef internal::traits<Derived> DerivedTraits; - typedef typename DerivedTraits::Scalar Scalar; - typedef typename DerivedTraits::Index Index; - typedef typename internal::remove_const<Scalar>::type CoeffReturnType; - static const int NumDimensions = DerivedTraits::NumDimensions; - - // Generic nullary operation support. - template <typename CustomNullaryOp> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseNullaryOp<CustomNullaryOp, const Derived> - nullaryExpr(const CustomNullaryOp& func) const { - return TensorCwiseNullaryOp<CustomNullaryOp, const Derived>(derived(), func); - } - - // Coefficient-wise nullary operators - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> - constant(const Scalar& value) const { - return nullaryExpr(internal::scalar_constant_op<Scalar>(value)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseNullaryOp<internal::UniformRandomGenerator<Scalar>, const Derived> - random() const { - return nullaryExpr(internal::UniformRandomGenerator<Scalar>()); - } - template <typename RandomGenerator> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseNullaryOp<RandomGenerator, const Derived> - random(const RandomGenerator& gen = RandomGenerator()) const { - return nullaryExpr(gen); - } - - // Tensor generation - template <typename Generator> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorGeneratorOp<Generator, const Derived> - generate(const Generator& generator) const { - return TensorGeneratorOp<Generator, const Derived>(derived(), generator); - } - - // Generic unary operation support. - template <typename CustomUnaryOp> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<CustomUnaryOp, const Derived> - unaryExpr(const CustomUnaryOp& func) const { - return TensorCwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func); - } - - // Coefficient-wise unary operators - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived> - operator-() const { - return unaryExpr(internal::scalar_opposite_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_sqrt_op<Scalar>, const Derived> - sqrt() const { - return unaryExpr(internal::scalar_sqrt_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_sign_op<Scalar>, const Derived> - sign() const { - return unaryExpr(internal::scalar_sign_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_rsqrt_op<Scalar>, const Derived> - rsqrt() const { - return unaryExpr(internal::scalar_rsqrt_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_square_op<Scalar>, const Derived> - square() const { - return unaryExpr(internal::scalar_square_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_cube_op<Scalar>, const Derived> - cube() const { - return unaryExpr(internal::scalar_cube_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived> - inverse() const { - return unaryExpr(internal::scalar_inverse_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_tanh_op<Scalar>, const Derived> - tanh() const { - return unaryExpr(internal::scalar_tanh_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_lgamma_op<Scalar>, const Derived> - lgamma() const { - return unaryExpr(internal::scalar_lgamma_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_digamma_op<Scalar>, const Derived> - digamma() const { - return unaryExpr(internal::scalar_digamma_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_i0_op<Scalar>, const Derived> - bessel_i0() const { - return unaryExpr(internal::scalar_bessel_i0_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_i0e_op<Scalar>, const Derived> - bessel_i0e() const { - return unaryExpr(internal::scalar_bessel_i0e_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_i1_op<Scalar>, const Derived> - bessel_i1() const { - return unaryExpr(internal::scalar_bessel_i1_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_i1e_op<Scalar>, const Derived> - bessel_i1e() const { - return unaryExpr(internal::scalar_bessel_i1e_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_j0_op<Scalar>, const Derived> - bessel_j0() const { - return unaryExpr(internal::scalar_bessel_j0_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_y0_op<Scalar>, const Derived> - bessel_y0() const { - return unaryExpr(internal::scalar_bessel_y0_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_j1_op<Scalar>, const Derived> - bessel_j1() const { - return unaryExpr(internal::scalar_bessel_j1_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_y1_op<Scalar>, const Derived> - bessel_y1() const { - return unaryExpr(internal::scalar_bessel_y1_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_k0_op<Scalar>, const Derived> - bessel_k0() const { - return unaryExpr(internal::scalar_bessel_k0_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_k0e_op<Scalar>, const Derived> - bessel_k0e() const { - return unaryExpr(internal::scalar_bessel_k0e_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_k1_op<Scalar>, const Derived> - bessel_k1() const { - return unaryExpr(internal::scalar_bessel_k1_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_k1e_op<Scalar>, const Derived> - bessel_k1e() const { - return unaryExpr(internal::scalar_bessel_k1e_op<Scalar>()); - } - - // igamma(a = this, x = other) - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_igamma_op<Scalar>, const Derived, const OtherDerived> - igamma(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_igamma_op<Scalar>()); - } - - // igamma_der_a(a = this, x = other) - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_igamma_der_a_op<Scalar>, const Derived, const OtherDerived> - igamma_der_a(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_igamma_der_a_op<Scalar>()); - } - - // gamma_sample_der_alpha(alpha = this, sample = other) - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_gamma_sample_der_alpha_op<Scalar>, const Derived, const OtherDerived> - gamma_sample_der_alpha(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_gamma_sample_der_alpha_op<Scalar>()); - } - - // igammac(a = this, x = other) - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_igammac_op<Scalar>, const Derived, const OtherDerived> - igammac(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_igammac_op<Scalar>()); - } - - // zeta(x = this, q = other) - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_zeta_op<Scalar>, const Derived, const OtherDerived> - zeta(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_zeta_op<Scalar>()); - } - - // polygamma(n = this, x = other) - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_polygamma_op<Scalar>, const Derived, const OtherDerived> - polygamma(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_polygamma_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_erf_op<Scalar>, const Derived> - erf() const { - return unaryExpr(internal::scalar_erf_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_erfc_op<Scalar>, const Derived> - erfc() const { - return unaryExpr(internal::scalar_erfc_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_ndtri_op<Scalar>, const Derived> - ndtri() const { - return unaryExpr(internal::scalar_ndtri_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_logistic_op<Scalar>, const Derived> - sigmoid() const { - return unaryExpr(internal::scalar_logistic_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_exp_op<Scalar>, const Derived> - exp() const { - return unaryExpr(internal::scalar_exp_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_expm1_op<Scalar>, const Derived> - expm1() const { - return unaryExpr(internal::scalar_expm1_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_log_op<Scalar>, const Derived> - log() const { - return unaryExpr(internal::scalar_log_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_log1p_op<Scalar>, const Derived> - log1p() const { - return unaryExpr(internal::scalar_log1p_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_abs_op<Scalar>, const Derived> - abs() const { - return unaryExpr(internal::scalar_abs_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_clamp_op<Scalar>, const Derived> - clip(Scalar min, Scalar max) const { - return unaryExpr(internal::scalar_clamp_op<Scalar>(min, max)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const typename internal::conditional<NumTraits<CoeffReturnType>::IsComplex, - TensorCwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>, - Derived>::type - conjugate() const { - return choose(Cond<NumTraits<CoeffReturnType>::IsComplex>(), unaryExpr(internal::scalar_conjugate_op<Scalar>()), derived()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::bind2nd_op<internal::scalar_pow_op<Scalar,Scalar> >, const Derived> - pow(Scalar exponent) const { - return unaryExpr(internal::bind2nd_op<internal::scalar_pow_op<Scalar,Scalar> >(exponent)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived> - real() const { - return unaryExpr(internal::scalar_real_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived> - imag() const { - return unaryExpr(internal::scalar_imag_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::bind2nd_op<internal::scalar_sum_op<Scalar,Scalar> >, const Derived> - operator+ (Scalar rhs) const { - return unaryExpr(internal::bind2nd_op<internal::scalar_sum_op<Scalar,Scalar> >(rhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE friend - const TensorCwiseUnaryOp<internal::bind1st_op<internal::scalar_sum_op<Scalar> >, const Derived> - operator+ (Scalar lhs, const Derived& rhs) { - return rhs.unaryExpr(internal::bind1st_op<internal::scalar_sum_op<Scalar> >(lhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::bind2nd_op<internal::scalar_difference_op<Scalar,Scalar> >, const Derived> - operator- (Scalar rhs) const { - EIGEN_STATIC_ASSERT((NumTraits<Scalar>::IsSigned || internal::is_same<Scalar, const std::complex<float> >::value), YOU_MADE_A_PROGRAMMING_MISTAKE); - return unaryExpr(internal::bind2nd_op<internal::scalar_difference_op<Scalar,Scalar> >(rhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE friend - const TensorCwiseUnaryOp<internal::bind1st_op<internal::scalar_difference_op<Scalar> >, const Derived> - operator- (Scalar lhs, const Derived& rhs) { - return rhs.unaryExpr(internal::bind1st_op<internal::scalar_difference_op<Scalar> >(lhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::bind2nd_op<internal::scalar_product_op<Scalar,Scalar> >, const Derived> - operator* (Scalar rhs) const { - return unaryExpr(internal::bind2nd_op<internal::scalar_product_op<Scalar,Scalar> >(rhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE friend - const TensorCwiseUnaryOp<internal::bind1st_op<internal::scalar_product_op<Scalar> >, const Derived> - operator* (Scalar lhs, const Derived& rhs) { - return rhs.unaryExpr(internal::bind1st_op<internal::scalar_product_op<Scalar> >(lhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::bind2nd_op<internal::scalar_quotient_op<Scalar,Scalar> >, const Derived> - operator/ (Scalar rhs) const { - return unaryExpr(internal::bind2nd_op<internal::scalar_quotient_op<Scalar,Scalar> >(rhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE friend - const TensorCwiseUnaryOp<internal::bind1st_op<internal::scalar_quotient_op<Scalar> >, const Derived> - operator/ (Scalar lhs, const Derived& rhs) { - return rhs.unaryExpr(internal::bind1st_op<internal::scalar_quotient_op<Scalar> >(lhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_mod_op<Scalar>, const Derived> - operator% (Scalar rhs) const { - EIGEN_STATIC_ASSERT(NumTraits<Scalar>::IsInteger, YOU_MADE_A_PROGRAMMING_MISTAKE_TRY_MOD); - return unaryExpr(internal::scalar_mod_op<Scalar>(rhs)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_max_op<Scalar>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> > - cwiseMax(Scalar threshold) const { - return cwiseMax(constant(threshold)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_min_op<Scalar>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> > - cwiseMin(Scalar threshold) const { - return cwiseMin(constant(threshold)); - } - - template<typename NewType> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const typename internal::conditional<internal::is_same<NewType, CoeffReturnType>::value, - Derived, - TensorConversionOp<NewType, const Derived> >::type - cast() const { - return choose(Cond<internal::is_same<NewType, CoeffReturnType>::value>(), derived(), TensorConversionOp<NewType, const Derived>(derived())); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_round_op<Scalar>, const Derived> - round() const { - return unaryExpr(internal::scalar_round_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_rint_op<Scalar>, const Derived> - rint() const { - return unaryExpr(internal::scalar_rint_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_ceil_op<Scalar>, const Derived> - ceil() const { - return unaryExpr(internal::scalar_ceil_op<Scalar>()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_floor_op<Scalar>, const Derived> - floor() const { - return unaryExpr(internal::scalar_floor_op<Scalar>()); - } - - // Generic binary operation support. - template <typename CustomBinaryOp, typename OtherDerived> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived> - binaryExpr(const OtherDerived& other, const CustomBinaryOp& func) const { - return TensorCwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived>(derived(), other, func); - } - - // Coefficient-wise binary operators. - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_sum_op<Scalar>, const Derived, const OtherDerived> - operator+(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_sum_op<Scalar>()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_difference_op<Scalar>, const Derived, const OtherDerived> - operator-(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_difference_op<Scalar>()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_product_op<Scalar>, const Derived, const OtherDerived> - operator*(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_product_op<Scalar>()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived> - operator/(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_quotient_op<Scalar>()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_max_op<Scalar>, const Derived, const OtherDerived> - cwiseMax(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_max_op<Scalar>()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_min_op<Scalar>, const Derived, const OtherDerived> - cwiseMin(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_min_op<Scalar>()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_boolean_and_op, const Derived, const OtherDerived> - operator&&(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_boolean_and_op()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived> - operator||(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_boolean_or_op()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_boolean_xor_op, const Derived, const OtherDerived> - operator^(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_boolean_xor_op()); - } - - // Comparisons and tests. - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT>, const Derived, const OtherDerived> - operator<(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT>()); - } - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE>, const Derived, const OtherDerived> - operator<=(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE>()); - } - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT>, const Derived, const OtherDerived> - operator>(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT>()); - } - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE>, const Derived, const OtherDerived> - operator>=(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE>()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ>, const Derived, const OtherDerived> - operator==(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ>()); - } - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ>, const Derived, const OtherDerived> - operator!=(const OtherDerived& other) const { - return binaryExpr(other.derived(), internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ>()); - } - - // comparisons and tests for Scalars - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> > - operator<(Scalar threshold) const { - return operator<(constant(threshold)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> > - operator<=(Scalar threshold) const { - return operator<=(constant(threshold)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> > - operator>(Scalar threshold) const { - return operator>(constant(threshold)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> > - operator>=(Scalar threshold) const { - return operator>=(constant(threshold)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> > - operator==(Scalar threshold) const { - return operator==(constant(threshold)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> > - operator!=(Scalar threshold) const { - return operator!=(constant(threshold)); - } - - // Checks - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_isnan_op<Scalar>, const Derived> - (isnan)() const { - return unaryExpr(internal::scalar_isnan_op<Scalar>()); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_isinf_op<Scalar>, const Derived> - (isinf)() const { - return unaryExpr(internal::scalar_isinf_op<Scalar>()); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_isfinite_op<Scalar>, const Derived> - (isfinite)() const { - return unaryExpr(internal::scalar_isfinite_op<Scalar>()); - } - - // Coefficient-wise ternary operators. - template<typename ThenDerived, typename ElseDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorSelectOp<const Derived, const ThenDerived, const ElseDerived> - select(const ThenDerived& thenTensor, const ElseDerived& elseTensor) const { - return TensorSelectOp<const Derived, const ThenDerived, const ElseDerived>(derived(), thenTensor.derived(), elseTensor.derived()); - } - - // Contractions. - typedef Eigen::IndexPair<Index> DimensionPair; - - template<typename OtherDerived, typename Dimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorContractionOp<const Dimensions, const Derived, const OtherDerived, const NoOpOutputKernel> - contract(const OtherDerived& other, const Dimensions& dims) const { - return TensorContractionOp<const Dimensions, const Derived, const OtherDerived, const NoOpOutputKernel>(derived(), other.derived(), dims); - } - - template<typename OtherDerived, typename Dimensions, typename OutputKernel> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorContractionOp<const Dimensions, const Derived, const OtherDerived, const OutputKernel> - contract(const OtherDerived& other, const Dimensions& dims, const OutputKernel& output_kernel) const { - return TensorContractionOp<const Dimensions, const Derived, const OtherDerived, const OutputKernel>(derived(), other.derived(), dims, output_kernel); - } - - // Convolutions. - template<typename KernelDerived, typename Dimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorConvolutionOp<const Dimensions, const Derived, const KernelDerived> - convolve(const KernelDerived& kernel, const Dimensions& dims) const { - return TensorConvolutionOp<const Dimensions, const Derived, const KernelDerived>(derived(), kernel.derived(), dims); - } - - // Fourier transforms - template <int FFTDataType, int FFTDirection, typename FFT> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorFFTOp<const FFT, const Derived, FFTDataType, FFTDirection> - fft(const FFT& dims) const { - return TensorFFTOp<const FFT, const Derived, FFTDataType, FFTDirection>(derived(), dims); - } - - // Scan. - typedef TensorScanOp<internal::SumReducer<CoeffReturnType>, const Derived> TensorScanSumOp; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorScanSumOp - cumsum(const Index& axis, bool exclusive = false) const { - return TensorScanSumOp(derived(), axis, exclusive); - } - - typedef TensorScanOp<internal::ProdReducer<CoeffReturnType>, const Derived> TensorScanProdOp; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorScanProdOp - cumprod(const Index& axis, bool exclusive = false) const { - return TensorScanProdOp(derived(), axis, exclusive); - } - - template <typename Reducer> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorScanOp<Reducer, const Derived> - scan(const Index& axis, const Reducer& reducer, bool exclusive = false) const { - return TensorScanOp<Reducer, const Derived>(derived(), axis, exclusive, reducer); - } - - // Reductions. - template <typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::SumReducer<CoeffReturnType>, const Dims, const Derived> - sum(const Dims& dims) const { - return TensorReductionOp<internal::SumReducer<CoeffReturnType>, const Dims, const Derived>(derived(), dims, internal::SumReducer<CoeffReturnType>()); - } - - const TensorReductionOp<internal::SumReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived> - sum() const { - DimensionList<Index, NumDimensions> in_dims; - return TensorReductionOp<internal::SumReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived>(derived(), in_dims, internal::SumReducer<CoeffReturnType>()); - } - - template <typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::MeanReducer<CoeffReturnType>, const Dims, const Derived> - mean(const Dims& dims) const { - return TensorReductionOp<internal::MeanReducer<CoeffReturnType>, const Dims, const Derived>(derived(), dims, internal::MeanReducer<CoeffReturnType>()); - } - - const TensorReductionOp<internal::MeanReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived> - mean() const { - DimensionList<Index, NumDimensions> in_dims; - return TensorReductionOp<internal::MeanReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived>(derived(), in_dims, internal::MeanReducer<CoeffReturnType>()); - } - - template <typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::ProdReducer<CoeffReturnType>, const Dims, const Derived> - prod(const Dims& dims) const { - return TensorReductionOp<internal::ProdReducer<CoeffReturnType>, const Dims, const Derived>(derived(), dims, internal::ProdReducer<CoeffReturnType>()); - } - - const TensorReductionOp<internal::ProdReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived> - prod() const { - DimensionList<Index, NumDimensions> in_dims; - return TensorReductionOp<internal::ProdReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived>(derived(), in_dims, internal::ProdReducer<CoeffReturnType>()); - } - - template <typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::MaxReducer<CoeffReturnType>, const Dims, const Derived> - maximum(const Dims& dims) const { - return TensorReductionOp<internal::MaxReducer<CoeffReturnType>, const Dims, const Derived>(derived(), dims, internal::MaxReducer<CoeffReturnType>()); - } - - const TensorReductionOp<internal::MaxReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived> - maximum() const { - DimensionList<Index, NumDimensions> in_dims; - return TensorReductionOp<internal::MaxReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived>(derived(), in_dims, internal::MaxReducer<CoeffReturnType>()); - } - - template <typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::MinReducer<CoeffReturnType>, const Dims, const Derived> - minimum(const Dims& dims) const { - return TensorReductionOp<internal::MinReducer<CoeffReturnType>, const Dims, const Derived>(derived(), dims, internal::MinReducer<CoeffReturnType>()); - } - - const TensorReductionOp<internal::MinReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived> - minimum() const { - DimensionList<Index, NumDimensions> in_dims; - return TensorReductionOp<internal::MinReducer<CoeffReturnType>, const DimensionList<Index, NumDimensions>, const Derived>(derived(), in_dims, internal::MinReducer<CoeffReturnType>()); - } - - template <typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::AndReducer, const Dims, const typename internal::conditional<internal::is_same<bool, CoeffReturnType>::value, Derived, TensorConversionOp<bool, const Derived> >::type > - all(const Dims& dims) const { - return cast<bool>().reduce(dims, internal::AndReducer()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::AndReducer, const DimensionList<Index, NumDimensions>, const typename internal::conditional<internal::is_same<bool, CoeffReturnType>::value, Derived, TensorConversionOp<bool, const Derived> >::type > - all() const { - DimensionList<Index, NumDimensions> in_dims; - return cast<bool>().reduce(in_dims, internal::AndReducer()); - } - - template <typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::OrReducer, const Dims, const typename internal::conditional<internal::is_same<bool, CoeffReturnType>::value, Derived, TensorConversionOp<bool, const Derived> >::type > - any(const Dims& dims) const { - return cast<bool>().reduce(dims, internal::OrReducer()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<internal::OrReducer, const DimensionList<Index, NumDimensions>, const typename internal::conditional<internal::is_same<bool, CoeffReturnType>::value, Derived, TensorConversionOp<bool, const Derived> >::type > - any() const { - DimensionList<Index, NumDimensions> in_dims; - return cast<bool>().reduce(in_dims, internal::OrReducer()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorTupleReducerOp< - internal::ArgMaxTupleReducer<Tuple<Index, CoeffReturnType> >, - const array<Index, NumDimensions>, const Derived> - argmax() const { - array<Index, NumDimensions> in_dims; - for (Index d = 0; d < NumDimensions; ++d) in_dims[d] = d; - return TensorTupleReducerOp< - internal::ArgMaxTupleReducer<Tuple<Index, CoeffReturnType> >, - const array<Index, NumDimensions>, - const Derived>(derived(), internal::ArgMaxTupleReducer<Tuple<Index, CoeffReturnType> >(), -1, in_dims); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorTupleReducerOp< - internal::ArgMinTupleReducer<Tuple<Index, CoeffReturnType> >, - const array<Index, NumDimensions>, const Derived> - argmin() const { - array<Index, NumDimensions> in_dims; - for (Index d = 0; d < NumDimensions; ++d) in_dims[d] = d; - return TensorTupleReducerOp< - internal::ArgMinTupleReducer<Tuple<Index, CoeffReturnType> >, - const array<Index, NumDimensions>, - const Derived>(derived(), internal::ArgMinTupleReducer<Tuple<Index, CoeffReturnType> >(), -1, in_dims); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorTupleReducerOp< - internal::ArgMaxTupleReducer<Tuple<Index, CoeffReturnType> >, - const array<Index, 1>, const Derived> - argmax(const Index return_dim) const { - array<Index, 1> in_dims; - in_dims[0] = return_dim; - return TensorTupleReducerOp< - internal::ArgMaxTupleReducer<Tuple<Index, CoeffReturnType> >, - const array<Index, 1>, - const Derived>(derived(), internal::ArgMaxTupleReducer<Tuple<Index, CoeffReturnType> >(), return_dim, in_dims); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorTupleReducerOp< - internal::ArgMinTupleReducer<Tuple<Index, CoeffReturnType> >, - const array<Index, 1>, const Derived> - argmin(const Index return_dim) const { - array<Index, 1> in_dims; - in_dims[0] = return_dim; - return TensorTupleReducerOp< - internal::ArgMinTupleReducer<Tuple<Index, CoeffReturnType> >, - const array<Index, 1>, - const Derived>(derived(), internal::ArgMinTupleReducer<Tuple<Index, CoeffReturnType> >(), return_dim, in_dims); - } - - template <typename Reducer, typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReductionOp<Reducer, const Dims, const Derived> - reduce(const Dims& dims, const Reducer& reducer) const { - return TensorReductionOp<Reducer, const Dims, const Derived>(derived(), dims, reducer); - } - - template <typename Dims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorTraceOp<const Dims, const Derived> - trace(const Dims& dims) const { - return TensorTraceOp<const Dims, const Derived>(derived(), dims); - } - - const TensorTraceOp<const DimensionList<Index, NumDimensions>, const Derived> - trace() const { - DimensionList<Index, NumDimensions> in_dims; - return TensorTraceOp<const DimensionList<Index, NumDimensions>, const Derived>(derived(), in_dims); - } - - template <typename Broadcast> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorBroadcastingOp<const Broadcast, const Derived> - broadcast(const Broadcast& bcast) const { - return TensorBroadcastingOp<const Broadcast, const Derived>(derived(), bcast); - } - - template <typename Axis, typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorConcatenationOp<Axis, const Derived, const OtherDerived> - concatenate(const OtherDerived& other, Axis axis) const { - return TensorConcatenationOp<Axis, const Derived, const OtherDerived>(derived(), other.derived(), axis); - } - - template <typename PatchDims> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorPatchOp<const PatchDims, const Derived> - extract_patches(const PatchDims& patch_dims) const { - return TensorPatchOp<const PatchDims, const Derived>(derived(), patch_dims); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorImagePatchOp<Dynamic, Dynamic, const Derived> - extract_image_patches(const Index patch_rows = 1, const Index patch_cols = 1, - const Index row_stride = 1, const Index col_stride = 1, - const Index in_row_stride = 1, const Index in_col_stride = 1, - const PaddingType padding_type = PADDING_SAME, const Scalar padding_value = Scalar(0)) const { - return TensorImagePatchOp<Dynamic, Dynamic, const Derived>(derived(), patch_rows, patch_cols, row_stride, col_stride, - in_row_stride, in_col_stride, 1, 1, padding_type, padding_value); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorImagePatchOp<Dynamic, Dynamic, const Derived> - extract_image_patches(const Index patch_rows, const Index patch_cols, - const Index row_stride, const Index col_stride, - const Index in_row_stride, const Index in_col_stride, - const Index row_inflate_stride, const Index col_inflate_stride, - const Index padding_top, const Index padding_bottom, - const Index padding_left,const Index padding_right, - const Scalar padding_value) const { - return TensorImagePatchOp<Dynamic, Dynamic, const Derived>(derived(), patch_rows, patch_cols, row_stride, col_stride, - in_row_stride, in_col_stride, row_inflate_stride, col_inflate_stride, - padding_top, padding_bottom, padding_left, padding_right, padding_value); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorVolumePatchOp<Dynamic, Dynamic, Dynamic, const Derived> - extract_volume_patches(const Index patch_planes, const Index patch_rows, const Index patch_cols, - const Index plane_stride = 1, const Index row_stride = 1, const Index col_stride = 1, - const PaddingType padding_type = PADDING_SAME, const Scalar padding_value = Scalar(0)) const { - return TensorVolumePatchOp<Dynamic, Dynamic, Dynamic, const Derived>(derived(), patch_planes, patch_rows, patch_cols, plane_stride, row_stride, col_stride, 1, 1, 1, 1, 1, 1, padding_type, padding_value); - } - - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorVolumePatchOp<Dynamic, Dynamic, Dynamic, const Derived> - extract_volume_patches(const Index patch_planes, const Index patch_rows, const Index patch_cols, - const Index plane_stride, const Index row_stride, const Index col_stride, - const Index plane_inflate_stride, const Index row_inflate_stride, const Index col_inflate_stride, - const Index padding_top_z, const Index padding_bottom_z, - const Index padding_top, const Index padding_bottom, - const Index padding_left, const Index padding_right, const Scalar padding_value = Scalar(0)) const { - return TensorVolumePatchOp<Dynamic, Dynamic, Dynamic, const Derived>(derived(), patch_planes, patch_rows, patch_cols, plane_stride, row_stride, col_stride, 1, 1, 1, plane_inflate_stride, row_inflate_stride, col_inflate_stride, padding_top_z, padding_bottom_z, padding_top, padding_bottom, padding_left, padding_right, padding_value); - } - - // Morphing operators. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorLayoutSwapOp<const Derived> - swap_layout() const { - return TensorLayoutSwapOp<const Derived>(derived()); - } - template <typename NewDimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReshapingOp<const NewDimensions, const Derived> - reshape(const NewDimensions& newDimensions) const { - return TensorReshapingOp<const NewDimensions, const Derived>(derived(), newDimensions); - } - template <typename StartIndices, typename Sizes> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorSlicingOp<const StartIndices, const Sizes, const Derived> - slice(const StartIndices& startIndices, const Sizes& sizes) const { - return TensorSlicingOp<const StartIndices, const Sizes, const Derived>(derived(), startIndices, sizes); - } - template <typename StartIndices, typename StopIndices, typename Strides> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorStridingSlicingOp<const StartIndices, const StopIndices, const Strides, const Derived> - stridedSlice(const StartIndices& startIndices, const StopIndices& stopIndices, const Strides& strides) const { - return TensorStridingSlicingOp<const StartIndices, const StopIndices, const Strides, - const Derived>(derived(), startIndices, stopIndices, strides); - } - template <Index DimId> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorChippingOp<DimId, const Derived> - chip(const Index offset) const { - return TensorChippingOp<DimId, const Derived>(derived(), offset, DimId); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorChippingOp<Dynamic, const Derived> - chip(const Index offset, const Index dim) const { - return TensorChippingOp<Dynamic, const Derived>(derived(), offset, dim); - } - template <typename ReverseDimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReverseOp<const ReverseDimensions, const Derived> - reverse(const ReverseDimensions& rev) const { - return TensorReverseOp<const ReverseDimensions, const Derived>(derived(), rev); - } - template <typename PaddingDimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorPaddingOp<const PaddingDimensions, const Derived> - pad(const PaddingDimensions& padding) const { - return TensorPaddingOp<const PaddingDimensions, const Derived>(derived(), padding, internal::scalar_cast_op<int, Scalar>()(0)); - } - template <typename PaddingDimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorPaddingOp<const PaddingDimensions, const Derived> - pad(const PaddingDimensions& padding, const Scalar padding_value) const { - return TensorPaddingOp<const PaddingDimensions, const Derived>(derived(), padding, padding_value); - } - template <typename Shuffle> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorShufflingOp<const Shuffle, const Derived> - shuffle(const Shuffle& shfl) const { - return TensorShufflingOp<const Shuffle, const Derived>(derived(), shfl); - } - template <typename Strides> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorStridingOp<const Strides, const Derived> - stride(const Strides& strides) const { - return TensorStridingOp<const Strides, const Derived>(derived(), strides); - } - template <typename Strides> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorInflationOp<const Strides, const Derived> - inflate(const Strides& strides) const { - return TensorInflationOp<const Strides, const Derived>(derived(), strides); - } - - // Returns a tensor containing index/value tuples - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorIndexTupleOp<const Derived> - index_tuples() const { - return TensorIndexTupleOp<const Derived>(derived()); - } - - // Support for custom unary and binary operations - template <typename CustomUnaryFunc> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCustomUnaryOp<const CustomUnaryFunc, const Derived> customOp(const CustomUnaryFunc& op) const { - return TensorCustomUnaryOp<const CustomUnaryFunc, const Derived>(derived(), op); - } - template <typename OtherDerived, typename CustomBinaryFunc> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorCustomBinaryOp<const CustomBinaryFunc, const Derived, const OtherDerived> customOp(const OtherDerived& other, const CustomBinaryFunc& op) const { - return TensorCustomBinaryOp<const CustomBinaryFunc, const Derived, const OtherDerived>(derived(), other, op); - } - - // Force the evaluation of the expression. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorForcedEvalOp<const Derived> eval() const { - return TensorForcedEvalOp<const Derived>(derived()); - } - - protected: - template <typename Scalar, int NumIndices, int Options, typename IndexType> friend class Tensor; - template <typename Scalar, typename Dimensions, int Option, typename IndexTypes> friend class TensorFixedSize; - // the Eigen:: prefix is required to workaround a compilation issue with nvcc 9.0 - template <typename OtherDerived, int AccessLevel> friend class Eigen::TensorBase; - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast<const Derived*>(this); } -}; - -template<typename Derived, int AccessLevel = internal::accessors_level<Derived>::value> -class TensorBase : public TensorBase<Derived, ReadOnlyAccessors> { - public: - typedef internal::traits<Derived> DerivedTraits; - typedef typename DerivedTraits::Scalar Scalar; - typedef typename DerivedTraits::Index Index; - typedef Scalar CoeffReturnType; - static const int NumDimensions = DerivedTraits::NumDimensions; - - template <typename Scalar, int NumIndices, int Options, typename IndexType> friend class Tensor; - template <typename Scalar, typename Dimensions, int Option, typename IndexTypes> friend class TensorFixedSize; - // the Eigen:: prefix is required to workaround a compilation issue with nvcc 9.0 - template <typename OtherDerived, int OtherAccessLevel> friend class Eigen::TensorBase; - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& setZero() { - return setConstant(Scalar(0)); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& setConstant(const Scalar& val) { - return derived() = this->constant(val); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& setRandom() { - return derived() = this->random(); - } - template <typename RandomGenerator> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& setRandom() { - return derived() = this->template random<RandomGenerator>(); - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& setValues( - const typename internal::Initializer<Derived, NumDimensions>::InitList& vals) { - TensorEvaluator<Derived, DefaultDevice> eval(derived(), DefaultDevice()); - internal::initialize_tensor<Derived, NumDimensions>(eval, vals); - return derived(); - } -#endif // EIGEN_HAS_VARIADIC_TEMPLATES - - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator+=(const OtherDerived& other) { - return derived() = derived() + other.derived(); - } - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator-=(const OtherDerived& other) { - return derived() = derived() - other.derived(); - } - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator*=(const OtherDerived& other) { - return derived() = derived() * other.derived(); - } - template<typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Derived& operator/=(const OtherDerived& other) { - return derived() = derived() / other.derived(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorLayoutSwapOp<const Derived> - swap_layout() const { - return TensorLayoutSwapOp<const Derived>(derived()); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorLayoutSwapOp<Derived> - swap_layout() { - return TensorLayoutSwapOp<Derived>(derived()); - } - - template <typename Axis, typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorConcatenationOp<const Axis, const Derived, const OtherDerived> - concatenate(const OtherDerived& other, const Axis& axis) const { - return TensorConcatenationOp<const Axis, const Derived, const OtherDerived>(derived(), other, axis); - } - template <typename Axis, typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorConcatenationOp<const Axis, Derived, OtherDerived> - concatenate(const OtherDerived& other, const Axis& axis) { - return TensorConcatenationOp<const Axis, Derived, OtherDerived>(derived(), other, axis); - } - - template <typename NewDimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReshapingOp<const NewDimensions, const Derived> - reshape(const NewDimensions& newDimensions) const { - return TensorReshapingOp<const NewDimensions, const Derived>(derived(), newDimensions); - } - template <typename NewDimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorReshapingOp<const NewDimensions, Derived> - reshape(const NewDimensions& newDimensions) { - return TensorReshapingOp<const NewDimensions, Derived>(derived(), newDimensions); - } - - template <typename StartIndices, typename Sizes> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorSlicingOp<const StartIndices, const Sizes, const Derived> - slice(const StartIndices& startIndices, const Sizes& sizes) const { - return TensorSlicingOp<const StartIndices, const Sizes, const Derived>(derived(), startIndices, sizes); - } - template <typename StartIndices, typename Sizes> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorSlicingOp<const StartIndices, const Sizes, Derived> - slice(const StartIndices& startIndices, const Sizes& sizes) { - return TensorSlicingOp<const StartIndices, const Sizes, Derived>(derived(), startIndices, sizes); - } - - template <typename StartIndices, typename StopIndices, typename Strides> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorStridingSlicingOp<const StartIndices, const StopIndices, const Strides, const Derived> - stridedSlice(const StartIndices& startIndices, const StopIndices& stopIndices, const Strides& strides) const { - return TensorStridingSlicingOp<const StartIndices, const StopIndices, const Strides, - const Derived>(derived(), startIndices, stopIndices, strides); - } - template <typename StartIndices, typename StopIndices, typename Strides> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorStridingSlicingOp<const StartIndices, const StopIndices, const Strides, Derived> - stridedSlice(const StartIndices& startIndices, const StopIndices& stopIndices, const Strides& strides) { - return TensorStridingSlicingOp<const StartIndices, const StopIndices, const Strides, - Derived>(derived(), startIndices, stopIndices, strides); - } - - template <DenseIndex DimId> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorChippingOp<DimId, const Derived> - chip(const Index offset) const { - return TensorChippingOp<DimId, const Derived>(derived(), offset, DimId); - } - template <Index DimId> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorChippingOp<DimId, Derived> - chip(const Index offset) { - return TensorChippingOp<DimId, Derived>(derived(), offset, DimId); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorChippingOp<Dynamic, const Derived> - chip(const Index offset, const Index dim) const { - return TensorChippingOp<Dynamic, const Derived>(derived(), offset, dim); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorChippingOp<Dynamic, Derived> - chip(const Index offset, const Index dim) { - return TensorChippingOp<Dynamic, Derived>(derived(), offset, dim); - } - - template <typename ReverseDimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorReverseOp<const ReverseDimensions, const Derived> - reverse(const ReverseDimensions& rev) const { - return TensorReverseOp<const ReverseDimensions, const Derived>(derived(), rev); - } - template <typename ReverseDimensions> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorReverseOp<const ReverseDimensions, Derived> - reverse(const ReverseDimensions& rev) { - return TensorReverseOp<const ReverseDimensions, Derived>(derived(), rev); - } - - template <typename Shuffle> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorShufflingOp<const Shuffle, const Derived> - shuffle(const Shuffle& shfl) const { - return TensorShufflingOp<const Shuffle, const Derived>(derived(), shfl); - } - template <typename Shuffle> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorShufflingOp<const Shuffle, Derived> - shuffle(const Shuffle& shfl) { - return TensorShufflingOp<const Shuffle, Derived>(derived(), shfl); - } - - template <typename Strides> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const TensorStridingOp<const Strides, const Derived> - stride(const Strides& strides) const { - return TensorStridingOp<const Strides, const Derived>(derived(), strides); - } - template <typename Strides> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorStridingOp<const Strides, Derived> - stride(const Strides& strides) { - return TensorStridingOp<const Strides, Derived>(derived(), strides); - } - - // Select the device on which to evaluate the expression. - template <typename DeviceType> - TensorDevice<Derived, DeviceType> device(const DeviceType& dev) { - return TensorDevice<Derived, DeviceType>(dev, derived()); - } - - // Select the async device on which to evaluate the expression. - template <typename DeviceType, typename DoneCallback> - TensorAsyncDevice<Derived, DeviceType, DoneCallback> device(const DeviceType& dev, DoneCallback done) { - return TensorAsyncDevice<Derived, DeviceType, DoneCallback>(dev, derived(), std::move(done)); - } - - protected: - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Derived& derived() { return *static_cast<Derived*>(this); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Derived& derived() const { return *static_cast<const Derived*>(this); } -}; -#endif // EIGEN_PARSED_BY_DOXYGEN -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_BASE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h deleted file mode 100644 index af30ea3d..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h +++ /dev/null @@ -1,1559 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_BLOCK_H -#define EIGEN_CXX11_TENSOR_TENSOR_BLOCK_H - -namespace Eigen { -namespace internal { - -// -------------------------------------------------------------------------- // -// Forward declarations for templates defined below. -template <typename Scalar, typename IndexType, int NumDims, int Layout> -class TensorBlockIO; - -// -------------------------------------------------------------------------- // -// Helper function to compute strides for densely stored buffer of given -// dimensions. - -// TODO(ezhulenev): We compute strides 1000 times in different evaluators, use -// this function instead everywhere. -template <int Layout, typename IndexType, int NumDims> -EIGEN_ALWAYS_INLINE DSizes<IndexType, NumDims> strides( - const DSizes<IndexType, NumDims>& dimensions) { - DSizes<IndexType, NumDims> strides; - if (NumDims == 0) return strides; - - // TODO(ezhulenev): Use templates to unroll this loop (similar to - // h_array_reduce in CXX11meta.h)? Benchmark it. - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - strides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - strides[i] = strides[i - 1] * dimensions[i - 1]; - } - } else { - strides[NumDims - 1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - strides[i] = strides[i + 1] * dimensions[i + 1]; - } - } - - return strides; -} - -template <int Layout, typename IndexType, size_t NumDims> -EIGEN_ALWAYS_INLINE DSizes<IndexType, NumDims> strides( - const Eigen::array<IndexType, NumDims>& dimensions) { - return strides<Layout>(DSizes<IndexType, NumDims>(dimensions)); -} - -template <int Layout, std::ptrdiff_t... Indices> -EIGEN_STRONG_INLINE DSizes<std::ptrdiff_t, sizeof...(Indices)> strides( - const Sizes<Indices...>& sizes) { - return strides<Layout>(DSizes<std::ptrdiff_t, sizeof...(Indices)>(sizes)); -} - -// -------------------------------------------------------------------------- // - -// Tensor block shape type defines what are the shape preference for the blocks -// extracted from the larger tensor. -// -// Example: blocks of 100 elements from the large 100x100 tensor: -// - tensor: 100x100 -// - target_block_size: 100 -// -// TensorBlockShapeType: -// - kUniformAllDims: 100 blocks of size 10x10 -// - kSkewedInnerDims: 100 blocks of size 100x1 (or 1x100 depending on a column -// or row major layout) -enum class TensorBlockShapeType { kUniformAllDims, kSkewedInnerDims }; - -struct TensorBlockResourceRequirements { - TensorBlockShapeType shape_type; // target block shape - size_t size; // target block size - TensorOpCost cost_per_coeff; // cost of computing a single block element - -#ifdef EIGEN_HIPCC - // For HIPCC, we need to explicitly declare as a "device fun", the constructor - // which is implicitly invoked in the "merge" / "any" routines. else HIPCC - // errors out complaining about the lack of a matching constructor - EIGEN_DEVICE_FUNC - TensorBlockResourceRequirements(TensorBlockShapeType shape_type_, size_t size_, - TensorOpCost cost_) - : shape_type(shape_type_), size(size_), cost_per_coeff(cost_) - {} -#endif - - template <typename Scalar> - EIGEN_DEVICE_FUNC static TensorBlockResourceRequirements withShapeAndSize( - TensorBlockShapeType shape_type, size_t size_in_bytes, - TensorOpCost cost) { - const size_t size = numext::maxi(size_t(1), size_in_bytes / sizeof(Scalar)); - return {shape_type, size, cost}; - } - - template <typename Scalar> - EIGEN_DEVICE_FUNC static TensorBlockResourceRequirements withShapeAndSize( - TensorBlockShapeType shape_type, size_t size_in_bytes) { - // This default cost per coefficient is valid for most materialized tensor - // block evaluation implementations, because they typically just read - // coefficients from the underlying tensor storage, and write to the tensor - // block buffer (scratch or destination memory, reads and writes have linear - // access pattern). We ignore the fixed cost of block evaluation, because in - // practice it should negligible. - // - // Lazy block evaluation adds the cost of calling a functor for each - // coefficient. - // - // All non-trivial block evaluation implementations must provide their own - // cost approximation (e.g. shuffling inner dimension has a much higher cost - // because it reads memory randomly, although the total number of moved - // bytes is the same). - return withShapeAndSize<Scalar>(shape_type, size_in_bytes, - {/*bytes_loaded=*/sizeof(Scalar), - /*bytes_stored=*/sizeof(Scalar), - /*compute_cycles=*/0}); - } - - template <typename Scalar> - EIGEN_DEVICE_FUNC static TensorBlockResourceRequirements skewed( - size_t size_in_bytes) { - return withShapeAndSize<Scalar>(TensorBlockShapeType::kSkewedInnerDims, - size_in_bytes); - } - - template <typename Scalar> - EIGEN_DEVICE_FUNC static TensorBlockResourceRequirements uniform( - size_t size_in_bytes) { - return withShapeAndSize<Scalar>(TensorBlockShapeType::kUniformAllDims, - size_in_bytes); - } - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE TensorBlockResourceRequirements - merge(const TensorBlockResourceRequirements& lhs, - const TensorBlockResourceRequirements& rhs) { - return {merge(lhs.shape_type, rhs.shape_type), // shape_type - merge(lhs.size, rhs.size), // size - merge(lhs.cost_per_coeff, rhs.cost_per_coeff)}; // cost_per_coeff - } - - EIGEN_DEVICE_FUNC TensorBlockResourceRequirements& addCostPerCoeff( - TensorOpCost cost) { - cost_per_coeff += cost; - return *this; - } - - // This is a resource requirement that should be returned from expressions - // that do not have any block evaluation preference (e.g. default tensor - // expression with raw buffer access). - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE TensorBlockResourceRequirements any() { - return {TensorBlockShapeType::kUniformAllDims, 1, {0, 0, 0}}; - } - - private: - using Requirements = TensorBlockResourceRequirements; - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE size_t merge(size_t lhs_size, size_t rhs_size) { - return numext::maxi(lhs_size, rhs_size); - } - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE TensorBlockShapeType - merge(TensorBlockShapeType lhs, TensorBlockShapeType rhs) { - return (lhs == TensorBlockShapeType::kSkewedInnerDims || - rhs == TensorBlockShapeType::kSkewedInnerDims) - ? TensorBlockShapeType::kSkewedInnerDims - : TensorBlockShapeType::kUniformAllDims; - } - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE TensorOpCost merge(TensorOpCost lhs_cost, - TensorOpCost rhs_cost) { - return lhs_cost + rhs_cost; - } -}; - -// -------------------------------------------------------------------------- // -// TensorBlockDescriptor specifies a block offset within a tensor and the block -// sizes along each of the tensor dimensions. - -template <int NumDims, typename IndexType = Eigen::Index> -class TensorBlockDescriptor { - public: - typedef DSizes<IndexType, NumDims> Dimensions; - - // If we evaluate a Tensor assignment, and expression on the left, already has - // a memory buffer, then we might do performance optimization, and evaluate - // the root expression directly into the final output memory. Some time it's - // possible to reuse it for materializing subexpressions inside an expression - // tree, to to avoid dynamic memory allocation. - // - // The pointer type of the underlying storage is erased, because passing - // Scalar type through all the expression evaluation layers is way too many - // templates. In practice destination buffer type should always match the - // evaluated expression scalar type. - class DestinationBuffer { - public: - enum DestinationBufferKind : int { - // The above explicit specification of "int" as the enum basetype is - // needed to get around a HIPCC link error ("the field type is not - // amp-compatible") - // which is issued for class members with the enum type. - // TODO(rocm): - // remove the "int" basetype once HIPCC has been fixed to not error out - // in the above scenario. - - // Destination buffer is not defined (`m_data` == nullptr). - kEmpty, - - // Tensor block defined by an owning tensor block descriptor can fit - // contiguously into the destination buffer. In this case it's safe to - // materialize tensor block in the destination buffer, wrap it in a - // TensorMap, and use to build Eigen expression on top of it. - kContiguous, - - // Destination buffer strides do not match strides of the contiguously - // stored block, and it's impossible to define a TensorMap over this - // buffer. However if we are evaluating a root of an expression tree, we - // still can materialize an output into this destination, because we can - // guarantee that no one will ever access it through block API. - // - // In theory it is possible to build valid TensorStriding<TensorMap> - // expression on top of this destination buffer, however it has - // inefficient coeff/packet access, and defeats the purpose of fast block - // evaluation API. - kStrided - }; - - template <typename Scalar> - Scalar* data() const { - eigen_assert(m_data_type_size == sizeof(Scalar)); - return static_cast<Scalar*>(m_data); - } - - const Dimensions& strides() const { return m_strides; } - const DestinationBufferKind& kind() const { return m_kind; } - - private: - friend class TensorBlockDescriptor; - - DestinationBuffer() : m_data(NULL), m_data_type_size(0), m_kind(kEmpty) {} - - template <typename Scalar> - DestinationBuffer(Scalar* data, const Dimensions& strides, - DestinationBufferKind kind) - : m_data(static_cast<void*>(data)), - m_data_type_size(sizeof(Scalar)), - m_strides(strides), - m_kind(kind) {} - - template <int Layout, typename Scalar> - static DestinationBuffer make(const TensorBlockDescriptor& desc, - Scalar* data, const Dimensions& strides) { - return DestinationBuffer(data, strides, kind<Layout>(desc, strides)); - } - - template <int Layout> - static DestinationBufferKind kind(const TensorBlockDescriptor& desc, - const Dimensions& strides) { - const Dimensions& desc_dims = desc.dimensions(); - const Dimensions& desc_strides = internal::strides<Layout>(desc_dims); - for (int i = 0; i < NumDims; ++i) { - if (desc_dims[i] == 1) continue; - if (desc_strides[i] != strides[i]) return kStrided; - } - return kContiguous; - } - - // Storage pointer is type erased, to reduce template bloat, but we still - // keep the size of the underlying element type for error checking. - void* m_data; - size_t m_data_type_size; - - // Destination buffer dimensions always match the dimensions of a tensor - // block descriptor it belongs to, however strides might be different. - Dimensions m_strides; - - DestinationBufferKind m_kind; - }; - - TensorBlockDescriptor(const IndexType offset, const Dimensions& dimensions, - const DestinationBuffer& destination) - : m_offset(offset), - m_dimensions(dimensions), - m_destination(destination) {} - - TensorBlockDescriptor(const IndexType offset, const Dimensions& dimensions) - : m_offset(offset), - m_dimensions(dimensions), - m_destination(DestinationBuffer()) {} - - IndexType offset() const { return m_offset; } - const Dimensions& dimensions() const { return m_dimensions; } - IndexType dimension(int index) const { return m_dimensions[index]; } - IndexType size() const { return array_prod<IndexType>(m_dimensions); } - - const DestinationBuffer& destination() const { return m_destination; } - - template <int Layout, typename Scalar> - void AddDestinationBuffer(Scalar* dst_base, const Dimensions& dst_strides) { - eigen_assert(dst_base != NULL); - m_destination = - DestinationBuffer::template make<Layout>(*this, dst_base, dst_strides); - } - - template <int Layout, typename Scalar, typename DstStridesIndexType> - void AddDestinationBuffer( - Scalar* dst_base, - const DSizes<DstStridesIndexType, NumDims>& dst_strides) { - // DSizes constructor will do index type promotion if it's safe. - AddDestinationBuffer<Layout>(dst_base, Dimensions(dst_strides)); - } - - TensorBlockDescriptor& DropDestinationBuffer() { - m_destination.m_data = NULL; - m_destination.m_kind = DestinationBuffer::kEmpty; - return *this; - } - - bool HasDestinationBuffer() const { - return m_destination.kind() != DestinationBuffer::kEmpty; - } - - // Returns a copy of `*this` with updated offset. - TensorBlockDescriptor WithOffset(IndexType offset) const { - return TensorBlockDescriptor(offset, m_dimensions, m_destination); - } - - private: - // Offset and dimensions are immutable after construction. Block descriptor - // can only be mutated by adding or dropping destination. - const IndexType m_offset; - const Dimensions m_dimensions; - DestinationBuffer m_destination; -}; - -// -------------------------------------------------------------------------- // -// TensorBlockMapper is responsible for iterating over the blocks of a tensor. - -template <int NumDims, int Layout, typename IndexType = Eigen::Index> -class TensorBlockMapper { - typedef TensorBlockDescriptor<NumDims, IndexType> BlockDescriptor; - - public: - typedef DSizes<IndexType, NumDims> Dimensions; - - TensorBlockMapper() = default; - TensorBlockMapper(const DSizes<IndexType, NumDims>& dimensions, - const TensorBlockResourceRequirements& requirements) - : m_tensor_dimensions(dimensions), m_requirements(requirements) { - // Compute block dimensions and the total number of blocks. - InitializeBlockDimensions(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE IndexType blockCount() const { - return m_total_block_count; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE IndexType blockTotalSize() const { - return m_block_dimensions.TotalSize(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const DSizes<IndexType, NumDims>& - blockDimensions() const { - return m_block_dimensions; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockDescriptor - blockDescriptor(IndexType block_index) const { - static const bool isColMajor = Layout == static_cast<int>(ColMajor); - - IndexType offset = 0; - DSizes<IndexType, NumDims> dimensions; - - if (NumDims == 0) return BlockDescriptor(offset, dimensions); - - // Iterate outer -> inner dimensions. - for (int i = NumDims - 1; i >= 0; --i) { - const int dim = isColMajor ? i : NumDims - i - 1; - - const IndexType idx = block_index / m_block_strides[dim]; - block_index -= idx * m_block_strides[dim]; - - const IndexType coord = idx * m_block_dimensions[dim]; - dimensions[dim] = numext::mini(m_tensor_dimensions[dim] - coord, - m_block_dimensions[dim]); - offset += coord * m_tensor_strides[dim]; - } - - return {offset, dimensions}; - } - - private: - void InitializeBlockDimensions() { - // Requested block shape and size. - const TensorBlockShapeType shape_type = m_requirements.shape_type; - IndexType target_block_size = - numext::maxi<IndexType>(1, static_cast<IndexType>(m_requirements.size)); - - IndexType tensor_size = m_tensor_dimensions.TotalSize(); - - // Corner case: one of the dimensions is zero. Logic below is too complex - // to handle this case on a general basis, just use unit block size. - // Note: we must not yield blocks with zero dimensions (recipe for - // overflows/underflows, divisions by zero and NaNs later). - if (tensor_size == 0) { - for (int i = 0; i < NumDims; ++i) { - m_block_dimensions[i] = 1; - } - m_total_block_count = 0; - return; - } - - // If tensor fits into a target block size, evaluate it as a single block. - if (tensor_size <= target_block_size) { - m_block_dimensions = m_tensor_dimensions; - m_total_block_count = 1; - // The only valid block index is `0`, and in this case we do not need - // to compute real strides for tensor or blocks (see blockDescriptor). - for (int i = 0; i < NumDims; ++i) { - m_tensor_strides[i] = 0; - m_block_strides[i] = 1; - } - return; - } - - static const bool isColMajor = Layout == static_cast<int>(ColMajor); - - // Block shape skewed towards inner dimension. - if (shape_type == TensorBlockShapeType::kSkewedInnerDims) { - IndexType coeff_to_allocate = target_block_size; - - for (int i = 0; i < NumDims; ++i) { - const int dim = isColMajor ? i : NumDims - i - 1; - m_block_dimensions[dim] = - numext::mini(coeff_to_allocate, m_tensor_dimensions[dim]); - coeff_to_allocate = divup( - coeff_to_allocate, - numext::maxi(static_cast<IndexType>(1), m_block_dimensions[dim])); - } - eigen_assert(coeff_to_allocate == 1); - - } else if (shape_type == TensorBlockShapeType::kUniformAllDims) { - // Tensor will not fit within 'target_block_size' budget: calculate tensor - // block dimension sizes based on "square" dimension size target. - const IndexType dim_size_target = convert_index<IndexType>( - std::pow(static_cast<float>(target_block_size), - 1.0f / static_cast<float>(m_block_dimensions.rank()))); - - for (int i = 0; i < NumDims; ++i) { - // TODO(andydavis) Adjust the inner most 'block_dim_size' to make it - // a multiple of the packet size. Note that reducing - // 'block_dim_size' in this manner can increase the number of - // blocks, and so will amplify any per-block overhead. - m_block_dimensions[i] = - numext::mini(dim_size_target, m_tensor_dimensions[i]); - } - - // Add any un-allocated coefficients to inner dimension(s). - IndexType total_size = m_block_dimensions.TotalSize(); - for (int i = 0; i < NumDims; ++i) { - const int dim = isColMajor ? i : NumDims - i - 1; - - if (m_block_dimensions[dim] < m_tensor_dimensions[dim]) { - const IndexType total_size_other_dims = - total_size / m_block_dimensions[dim]; - const IndexType alloc_avail = - divup<IndexType>(target_block_size, total_size_other_dims); - if (alloc_avail == m_block_dimensions[dim]) { - // Insufficient excess coefficients to allocate. - break; - } - m_block_dimensions[dim] = - numext::mini(m_tensor_dimensions[dim], alloc_avail); - total_size = total_size_other_dims * m_block_dimensions[dim]; - } - } - - } else { - eigen_assert(false); // unknown block shape - } - - eigen_assert(m_block_dimensions.TotalSize() >= - numext::mini<IndexType>(target_block_size, - m_tensor_dimensions.TotalSize())); - - // Calculate block counts by dimension and total block count. - DSizes<IndexType, NumDims> block_count; - for (int i = 0; i < NumDims; ++i) { - block_count[i] = divup(m_tensor_dimensions[i], m_block_dimensions[i]); - } - m_total_block_count = array_prod(block_count); - - // Calculate block strides (used for enumerating blocks). - m_tensor_strides = strides<Layout>(m_tensor_dimensions); - m_block_strides = strides<Layout>(block_count); - } - - DSizes<IndexType, NumDims> m_tensor_dimensions; - TensorBlockResourceRequirements m_requirements; - - DSizes<IndexType, NumDims> m_block_dimensions; - IndexType m_total_block_count; - - DSizes<IndexType, NumDims> m_tensor_strides; - DSizes<IndexType, NumDims> m_block_strides; -}; - -// -------------------------------------------------------------------------- // -// TensorBlockScratchAllocator is responsible for allocating temporary buffers -// for block evaluation (output or input block materialization). Given that -// Eigen expression traversal order is deterministic, all temporary allocations -// are happening in the same order, and usually have exactly the same size. -// Scratch allocator keeps a trace of all dynamic allocations, and after the -// first block evaluation is completed, we should be able to reuse all the -// temporary buffers for the next block evaluation. - -template <typename Device> -class TensorBlockScratchAllocator { - public: - explicit TensorBlockScratchAllocator(const Device& device) - : m_device(device), m_allocation_index(0) {} - - ~TensorBlockScratchAllocator() { - for (size_t i = 0; i < m_allocations.size(); ++i) { - m_device.deallocate(m_allocations[i].ptr); - } - } - - void* allocate(size_t size) { - // TODO(ezhulenev): Remove when replaced with inlined vector. - if (m_allocations.capacity() == 0) m_allocations.reserve(8); - - // Check if we already have an existing allocation att current index. - const int num_allocations = static_cast<int>(m_allocations.size()); - const bool has_allocation = m_allocation_index < num_allocations; - - // Allocation index can't be larger than the number of allocations. - eigen_assert(m_allocation_index <= num_allocations); - - // If we have existing allocation, and its size is larger or equal to - // requested size, we do nothing. - - // If current allocation can't fit requested size, we deallocate it, and - // replace with a larger allocation. - if (has_allocation && m_allocations[m_allocation_index].size < size) { - m_device.deallocate(m_allocations[m_allocation_index].ptr); - m_allocations[m_allocation_index].ptr = m_device.allocate(size); - m_allocations[m_allocation_index].size = size; - } - - // Make a new allocation if we don't have and existing one. - if (!has_allocation) { - Allocation allocation; - allocation.ptr = m_device.allocate(size); - allocation.size = size; - m_allocations.push_back(allocation); - } - - eigen_assert(m_allocations[m_allocation_index].ptr != NULL); - eigen_assert(m_allocations[m_allocation_index].size >= size); - - return m_allocations[m_allocation_index++].ptr; - } - - void reset() { m_allocation_index = 0; } - - private: - struct Allocation { - void* ptr; - size_t size; - }; - - const Device& m_device; - int m_allocation_index; - // TODO(ezhulenev): This should be an inlined vector. - std::vector<Allocation> m_allocations; -}; - -// -------------------------------------------------------------------------- // -// TensorBlockKind represents all possible block kinds, that can be produced by -// TensorEvaluator::evalBlock function. -enum TensorBlockKind { - // Tensor block that is a lazy expression that must be assigned to a - // destination using TensorBlockAssign. - kExpr, - - // Tensor block that is a view into a memory buffer owned by an underlying - // Tensor expression (e.g. it can be a view into a Tensor buffer). - kView, - - // Tensor block that was materialized in a scratch memory buffer, allocated - // with TensorBlockScratchAllocator. This block must be copied to a - // destination, similar to a block of `kExpr` type. - kMaterializedInScratch, - - // Tensor block that was materialized directly into the final output memory - // buffer. For example if the left side of an assignment is a Tensor, we can - // directly materialize the block in the destination memory. - // - // If strides in the output buffer do not match tensor block strides, the - // Tensor expression will be invalid, and should not be used by - // TensorBlockAssign or for constructing another block expression. - kMaterializedInOutput -}; - -// -------------------------------------------------------------------------- // -// TensorBlockNotImplemented should be used to defined TensorBlock typedef in -// TensorEvaluators that do not support block evaluation. - -class TensorBlockNotImplemented { - public: - typedef void XprType; -}; - -// -------------------------------------------------------------------------- // -// XprScalar extracts Scalar type from the Eigen expressions (if expression type -// is not void). It's required to be able to define lazy block expression for -// argument types, that do not support block evaluation. - -template <typename XprType> -struct XprScalar { - typedef typename XprType::Scalar type; -}; -template <> -struct XprScalar<void> { - typedef void type; -}; - -// -------------------------------------------------------------------------- // -// TensorMaterializedBlock is a fully evaluated block of the original tensor, -// and XprType is just a TensorMap over the data. This block type is typically -// used to materialize blocks of tensor expressions, that can't be efficiently -// represented as lazy Tensor expressions with fast coeff/packet operations, -// e.g. we materialize all broadcasts into evaluated blocks. -// -// TensorMaterializedBlock does not own its memory buffer, it's either a memory -// buffer that backs the original expression (e.g. block is just a view into a -// Tensor), or a memory buffer allocated with scratch allocator, and in this -// case the scratch allocator will deallocate it at the end of block based -// expression execution. -// -// If the block was evaluated directly into the output buffer, and strides in -// the output buffer do not match block strides, the TensorMap expression will -// be invalid, and should never be used in block assignment or any other tensor -// expression. - -template <typename Scalar, int NumDims, int Layout, - typename IndexType = Eigen::Index> -class TensorMaterializedBlock { - public: - typedef DSizes<IndexType, NumDims> Dimensions; - typedef TensorMap<const Tensor<Scalar, NumDims, Layout> > XprType; - - TensorMaterializedBlock(TensorBlockKind kind, const Scalar* data, - const Dimensions& dimensions, bool valid_expr = true) - : m_kind(kind), - m_data(data), - m_dimensions(dimensions), - m_expr(m_data, m_dimensions), - m_valid_expr(valid_expr) { - eigen_assert(m_kind == internal::TensorBlockKind::kView || - m_kind == internal::TensorBlockKind::kMaterializedInScratch || - m_kind == internal::TensorBlockKind::kMaterializedInOutput); - } - - TensorBlockKind kind() const { return m_kind; } - // NOTE(ezhulenev): Returning XprType by value like in other block types - // causes asan failures. The theory is that XprType::Nested doesn't work - // properly for TensorMap. - const XprType& expr() const { - eigen_assert(m_valid_expr); - return m_expr; - } - const Scalar* data() const { return m_data; } - void cleanup() {} - - typedef internal::TensorBlockDescriptor<NumDims, IndexType> TensorBlockDesc; - - // TensorMaterializedBlock can be backed by different types of storage: - // - // (1) Contiguous block of memory allocated with scratch allocator. - // (2) Contiguous block of memory reused from tensor block descriptor - // destination buffer. - // (3) Strided block of memory reused from tensor block descriptor - // destination buffer. - // - class Storage { - public: - Scalar* data() const { return m_data; } - const Dimensions& dimensions() const { return m_dimensions; } - const Dimensions& strides() const { return m_strides; } - - TensorMaterializedBlock AsTensorMaterializedBlock() const { - return TensorMaterializedBlock( - m_materialized_in_output - ? internal::TensorBlockKind::kMaterializedInOutput - : internal::TensorBlockKind::kMaterializedInScratch, - m_data, m_dimensions, !m_strided_storage); - } - - private: - friend class TensorMaterializedBlock; - - Storage(Scalar* data, const Dimensions& dimensions, - const Dimensions& strides, bool materialized_in_output, - bool strided_storage) - : m_data(data), - m_dimensions(dimensions), - m_strides(strides), - m_materialized_in_output(materialized_in_output), - m_strided_storage(strided_storage) {} - - Scalar* m_data; - Dimensions m_dimensions; - Dimensions m_strides; - bool m_materialized_in_output; - bool m_strided_storage; - }; - - // Creates a storage for materialized block either from the block descriptor - // destination buffer, or allocates a new buffer with scratch allocator. - template <typename TensorBlockScratch> - EIGEN_STRONG_INLINE static Storage prepareStorage( - TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool allow_strided_storage = false) { - // Try to reuse destination as an output block buffer. - typedef typename TensorBlockDesc::DestinationBuffer DestinationBuffer; - - if (desc.destination().kind() == DestinationBuffer::kContiguous) { - Scalar* buffer = desc.destination().template data<Scalar>(); - desc.DropDestinationBuffer(); - return Storage(buffer, desc.dimensions(), - internal::strides<Layout>(desc.dimensions()), - /*materialized_in_output=*/true, - /*strided_storage=*/false); - - } else if (desc.destination().kind() == DestinationBuffer::kStrided && - allow_strided_storage) { - Scalar* buffer = desc.destination().template data<Scalar>(); - desc.DropDestinationBuffer(); - return Storage(buffer, desc.dimensions(), desc.destination().strides(), - /*materialized_in_output=*/true, /*strided_storage=*/true); - - } else { - void* mem = scratch.allocate(desc.size() * sizeof(Scalar)); - return Storage(static_cast<Scalar*>(mem), desc.dimensions(), - internal::strides<Layout>(desc.dimensions()), - /*materialized_in_output=*/false, - /*strided_storage=*/false); - } - } - - // Creates a materialized block for the given descriptor from a memory buffer. - template <typename DataDimensions, typename TensorBlockScratch> - EIGEN_STRONG_INLINE static TensorMaterializedBlock materialize( - const Scalar* data, const DataDimensions& data_dims, - TensorBlockDesc& desc, TensorBlockScratch& scratch) { - eigen_assert(array_size<DataDimensions>::value == desc.dimensions().size()); - - // If a tensor block dimensions covers a contiguous block of the underlying - // memory, we can skip block buffer memory allocation, and construct a block - // from existing `data` memory buffer. - // - // Example: (RowMajor layout) - // data_dims: [11, 12, 13, 14] - // desc.dimensions(): [1, 1, 3, 14] - // - // In this case we can construct a TensorBlock starting at - // `data + desc.offset()`, with a `desc.dimensions()` block sizes. - static const bool is_col_major = Layout == ColMajor; - - // Find out how many inner dimensions have a matching size. - int num_matching_inner_dims = 0; - for (int i = 0; i < NumDims; ++i) { - int dim = is_col_major ? i : NumDims - i - 1; - if (data_dims[dim] != desc.dimensions()[dim]) break; - ++num_matching_inner_dims; - } - - // All the outer dimensions must be of size `1`, except a single dimension - // before the matching inner dimension (`3` in the example above). - bool can_use_direct_access = true; - for (int i = num_matching_inner_dims + 1; i < NumDims; ++i) { - int dim = is_col_major ? i : NumDims - i - 1; - if (desc.dimension(dim) != 1) { - can_use_direct_access = false; - break; - } - } - - if (can_use_direct_access) { - const Scalar* block_start = data + desc.offset(); - return TensorMaterializedBlock(internal::TensorBlockKind::kView, - block_start, desc.dimensions()); - - } else { - // Reuse destination buffer or allocate new buffer with scratch allocator. - const Storage storage = prepareStorage(desc, scratch); - - typedef internal::TensorBlockIO<Scalar, IndexType, NumDims, Layout> - TensorBlockIO; - typedef typename TensorBlockIO::Dst TensorBlockIODst; - typedef typename TensorBlockIO::Src TensorBlockIOSrc; - - TensorBlockIOSrc src(internal::strides<Layout>(Dimensions(data_dims)), - data, desc.offset()); - TensorBlockIODst dst(storage.dimensions(), storage.strides(), - storage.data()); - - TensorBlockIO::Copy(dst, src); - return storage.AsTensorMaterializedBlock(); - } - } - - private: - TensorBlockKind m_kind; - const Scalar* m_data; - Dimensions m_dimensions; - XprType m_expr; - bool m_valid_expr; -}; - -// -------------------------------------------------------------------------- // -// TensorCwiseUnaryBlock is a lazy tensor expression block that applies UnaryOp -// functor to the blocks produced by the underlying Tensor expression. - -template <typename UnaryOp, typename ArgTensorBlock> -class TensorCwiseUnaryBlock { - static const bool NoArgBlockAccess = - internal::is_void<typename ArgTensorBlock::XprType>::value; - - public: - typedef typename conditional< - NoArgBlockAccess, void, - TensorCwiseUnaryOp<UnaryOp, const typename ArgTensorBlock::XprType> >:: - type XprType; - - typedef typename XprScalar<XprType>::type Scalar; - - TensorCwiseUnaryBlock(const ArgTensorBlock& arg_block, const UnaryOp& functor) - : m_arg_block(arg_block), m_functor(functor) {} - - TensorBlockKind kind() const { return internal::TensorBlockKind::kExpr; } - - XprType expr() const { return XprType(m_arg_block.expr(), m_functor); } - const Scalar* data() const { return NULL; } - void cleanup() { m_arg_block.cleanup(); } - - private: - ArgTensorBlock m_arg_block; - UnaryOp m_functor; -}; - -// -------------------------------------------------------------------------- // -// TensorCwiseUnaryBlock is a lazy tensor expression block that applies BinaryOp -// functor to the blocks produced by the underlying Tensor expression. - -template <typename BinaryOp, typename LhsTensorBlock, typename RhsTensorBlock> -class TensorCwiseBinaryBlock { - static const bool NoArgBlockAccess = - internal::is_void<typename LhsTensorBlock::XprType>::value || - internal::is_void<typename RhsTensorBlock::XprType>::value; - - public: - typedef typename conditional< - NoArgBlockAccess, void, - TensorCwiseBinaryOp<BinaryOp, const typename LhsTensorBlock::XprType, - const typename RhsTensorBlock::XprType> >::type - XprType; - - typedef typename XprScalar<XprType>::type Scalar; - - TensorCwiseBinaryBlock(const LhsTensorBlock& left_block, - const RhsTensorBlock& right_block, - const BinaryOp& functor) - : m_left_block(left_block), - m_right_block(right_block), - m_functor(functor) {} - - TensorBlockKind kind() const { return internal::TensorBlockKind::kExpr; } - - XprType expr() const { - return XprType(m_left_block.expr(), m_right_block.expr(), m_functor); - } - - const Scalar* data() const { return NULL; } - - void cleanup() { - m_left_block.cleanup(); - m_right_block.cleanup(); - } - - private: - LhsTensorBlock m_left_block; - RhsTensorBlock m_right_block; - BinaryOp m_functor; -}; - -// -------------------------------------------------------------------------- // -// TensorUnaryExprBlock is a lazy tensor expression block that can construct -// an arbitrary tensor expression from a block of the underlying type (this is a -// generalization of the TensorCwiseUnaryBlock for arbitrary expressions). - -template <typename BlockFactory, typename ArgTensorBlock> -class TensorUnaryExprBlock { - typedef typename ArgTensorBlock::XprType ArgXprType; - static const bool NoArgBlockAccess = internal::is_void<ArgXprType>::value; - - public: - typedef typename conditional< - NoArgBlockAccess, void, - typename BlockFactory::template XprType<ArgXprType>::type>::type XprType; - - typedef typename XprScalar<XprType>::type Scalar; - - TensorUnaryExprBlock(const ArgTensorBlock& arg_block, - const BlockFactory& factory) - : m_arg_block(arg_block), m_factory(factory) {} - - TensorBlockKind kind() const { return internal::TensorBlockKind::kExpr; } - XprType expr() const { return m_factory.expr(m_arg_block.expr()); } - const Scalar* data() const { return NULL; } - void cleanup() { m_arg_block.cleanup(); } - - private: - ArgTensorBlock m_arg_block; - BlockFactory m_factory; -}; - -// -------------------------------------------------------------------------- // -// TensorTernaryExprBlock is a lazy tensor expression block that can construct -// an arbitrary tensor expression from three blocks of the underlying type. - -template <typename BlockFactory, typename Arg1TensorBlock, - typename Arg2TensorBlock, typename Arg3TensorBlock> -class TensorTernaryExprBlock { - typedef typename Arg1TensorBlock::XprType Arg1XprType; - typedef typename Arg2TensorBlock::XprType Arg2XprType; - typedef typename Arg3TensorBlock::XprType Arg3XprType; - - static const bool NoArgBlockAccess = internal::is_void<Arg1XprType>::value || - internal::is_void<Arg2XprType>::value || - internal::is_void<Arg3XprType>::value; - - public: - typedef typename conditional< - NoArgBlockAccess, void, - typename BlockFactory::template XprType<Arg1XprType, Arg2XprType, - Arg3XprType>::type>::type XprType; - - typedef typename XprScalar<XprType>::type Scalar; - - TensorTernaryExprBlock(const Arg1TensorBlock& arg1_block, - const Arg2TensorBlock& arg2_block, - const Arg3TensorBlock& arg3_block, - const BlockFactory& factory) - : m_arg1_block(arg1_block), - m_arg2_block(arg2_block), - m_arg3_block(arg3_block), - m_factory(factory) {} - - TensorBlockKind kind() const { return internal::TensorBlockKind::kExpr; } - XprType expr() const { - return m_factory.expr(m_arg1_block.expr(), m_arg2_block.expr(), - m_arg3_block.expr()); - } - const Scalar* data() const { return NULL; } - void cleanup() { - m_arg1_block.cleanup(); - m_arg2_block.cleanup(); - m_arg3_block.cleanup(); - } - - private: - Arg1TensorBlock m_arg1_block; - Arg2TensorBlock m_arg2_block; - Arg3TensorBlock m_arg3_block; - BlockFactory m_factory; -}; - -// -------------------------------------------------------------------------- // -// StridedLinearBufferCopy provides a method to copy data between two linear -// buffers with different strides, with optimized paths for scatter/gather. - -template <typename Scalar, typename IndexType> -class StridedLinearBufferCopy { - typedef typename packet_traits<Scalar>::type Packet; - enum { - Vectorizable = packet_traits<Scalar>::Vectorizable, - PacketSize = packet_traits<Scalar>::size - }; - - public: - // Specifying linear copy kind statically gives ~30% speedup for small sizes. - enum class Kind { - Linear = 0, // src_stride == 1 && dst_stride == 1 - Scatter = 1, // src_stride == 1 && dst_stride != 1 - FillLinear = 2, // src_stride == 0 && dst_stride == 1 - FillScatter = 3, // src_stride == 0 && dst_stride != 1 - Gather = 4, // dst_stride == 1 - Random = 5 // everything else - }; - - struct Dst { - Dst(IndexType o, IndexType s, Scalar* d) : offset(o), stride(s), data(d) {} - - IndexType offset; - IndexType stride; - Scalar* data; - }; - - struct Src { - Src(IndexType o, IndexType s, const Scalar* d) - : offset(o), stride(s), data(d) {} - - IndexType offset; - IndexType stride; - const Scalar* data; - }; - - template <StridedLinearBufferCopy::Kind kind> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(const Dst& dst, - const Src& src, - const size_t count) { - Run<kind>(count, dst.offset, dst.stride, dst.data, src.offset, src.stride, - src.data); - } - - private: - template <StridedLinearBufferCopy::Kind kind> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run( - const IndexType count, const IndexType dst_offset, - const IndexType dst_stride, Scalar* EIGEN_RESTRICT dst_data, - const IndexType src_offset, const IndexType src_stride, - const Scalar* EIGEN_RESTRICT src_data) { - const Scalar* src = &src_data[src_offset]; - Scalar* dst = &dst_data[dst_offset]; - - if (!Vectorizable) { - for (Index i = 0; i < count; ++i) { - dst[i * dst_stride] = src[i * src_stride]; - } - return; - } - - const IndexType vectorized_size = count - PacketSize; - IndexType i = 0; - - if (kind == StridedLinearBufferCopy::Kind::Linear) { - // ******************************************************************** // - // Linear copy from `src` to `dst`. - const IndexType unrolled_size = count - 4 * PacketSize; - eigen_assert(src_stride == 1 && dst_stride == 1); - for (; i <= unrolled_size; i += 4 * PacketSize) { - for (int j = 0; j < 4; ++j) { - Packet p = ploadu<Packet>(src + i + j * PacketSize); - pstoreu<Scalar, Packet>(dst + i + j * PacketSize, p); - } - } - for (; i <= vectorized_size; i += PacketSize) { - Packet p = ploadu<Packet>(src + i); - pstoreu<Scalar, Packet>(dst + i, p); - } - for (; i < count; ++i) { - dst[i] = src[i]; - } - // ******************************************************************** // - } else if (kind == StridedLinearBufferCopy::Kind::Scatter) { - // Scatter from `src` to `dst`. - eigen_assert(src_stride == 1 && dst_stride != 1); - for (; i <= vectorized_size; i += PacketSize) { - Packet p = ploadu<Packet>(src + i); - pscatter<Scalar, Packet>(dst + i * dst_stride, p, dst_stride); - } - for (; i < count; ++i) { - dst[i * dst_stride] = src[i]; - } - // ******************************************************************** // - } else if (kind == StridedLinearBufferCopy::Kind::FillLinear) { - // Fill `dst` with value at `*src`. - eigen_assert(src_stride == 0 && dst_stride == 1); - const IndexType unrolled_size = count - 4 * PacketSize; - Packet p = pload1<Packet>(src); - for (; i <= unrolled_size; i += 4 * PacketSize) { - for (int j = 0; j < 4; ++j) { - pstoreu<Scalar, Packet>(dst + i + j * PacketSize, p); - } - } - for (; i <= vectorized_size; i += PacketSize) { - pstoreu<Scalar, Packet>(dst + i, p); - } - for (; i < count; ++i) { - dst[i] = *src; - } - // ******************************************************************** // - } else if (kind == StridedLinearBufferCopy::Kind::FillScatter) { - // Scatter `*src` into `dst`. - eigen_assert(src_stride == 0 && dst_stride != 1); - Packet p = pload1<Packet>(src); - for (; i <= vectorized_size; i += PacketSize) { - pscatter<Scalar, Packet>(dst + i * dst_stride, p, dst_stride); - } - for (; i < count; ++i) { - dst[i * dst_stride] = *src; - } - // ******************************************************************** // - } else if (kind == StridedLinearBufferCopy::Kind::Gather) { - // Gather from `src` into `dst`. - eigen_assert(dst_stride == 1); - for (; i <= vectorized_size; i += PacketSize) { - Packet p = pgather<Scalar, Packet>(src + i * src_stride, src_stride); - pstoreu<Scalar, Packet>(dst + i, p); - } - for (; i < count; ++i) { - dst[i] = src[i * src_stride]; - } - // ******************************************************************** // - } else if (kind == StridedLinearBufferCopy::Kind::Random) { - // Random. - for (; i < count; ++i) { - dst[i * dst_stride] = src[i * src_stride]; - } - } else { - eigen_assert(false); - } - } -}; - -// -------------------------------------------------------------------------- // -// TensorBlockIO copies data from `src` tensor block, to the `dst` tensor block. -// It's possible to specify src->dst dimension mapping for the copy operation. -// Dimensions of `dst` specify how many elements have to be copied, for the -// `src` we need to know only stride to navigate through source memory buffer. - -template <typename Scalar, typename IndexType, int NumDims, int Layout> -class TensorBlockIO { - static const bool IsColMajor = (Layout == ColMajor); - - typedef StridedLinearBufferCopy<Scalar, IndexType> LinCopy; - - public: - typedef DSizes<IndexType, NumDims> Dimensions; - typedef DSizes<int, NumDims> DimensionsMap; - - struct Dst { - Dst(const Dimensions& dst_dims, const Dimensions& dst_strides, Scalar* dst, - IndexType dst_offset = 0) - : dims(dst_dims), strides(dst_strides), data(dst), offset(dst_offset) {} - - Dimensions dims; - Dimensions strides; - Scalar* data; - IndexType offset; - }; - - struct Src { - Src(const Dimensions& src_strides, const Scalar* src, - IndexType src_offset = 0) - : strides(src_strides), data(src), offset(src_offset) {} - - Dimensions strides; - const Scalar* data; - IndexType offset; - }; - - // Copies data to `dst` from `src`, using provided dimensions mapping: - // - // src_dimension_index = dst_to_src_dim_map[dst_dimension_index] - // - // Returns the number of copied elements. - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE IndexType Copy( - const Dst& dst, const Src& src, const DimensionsMap& dst_to_src_dim_map) { - // Copy single scalar value from `src` to `dst`. - if (NumDims == 0) { - *(dst.data + dst.offset) = *(src.data + src.offset); - return 1; - } - - // Both `dst` and `src` must have contiguous innermost dimension. We also - // accept the special case with stride '0', because it's used as a trick to - // implement broadcasting. - { - int inner_dim = IsColMajor ? 0 : NumDims - 1; - EIGEN_UNUSED_VARIABLE(inner_dim); - eigen_assert(dst.strides[inner_dim] == 1 || dst.strides[inner_dim] == 0); - eigen_assert(src.strides[inner_dim] == 1 || src.strides[inner_dim] == 0); - } - - // Give a shorter name to `dst_to_src_dim_map`. - const DimensionsMap& dim_map = dst_to_src_dim_map; - - // Do not squeeze reordered inner dimensions. - int num_squeezable_dims = NumSqueezableInnerDims(dim_map); - - // NOTE: We find the innermost dimension (contiguous in memory) in the dst - // block, and we write data linearly into that dimension, reading it from - // the src. If dimensions are reordered, we might end up reading data from - // the src with `stride != 1`. - // - // NOTE: Random-Read/Linear-Write can be up to ~2X faster than - // Linear-Read/Random-Write: https://stackoverflow.com/a/54935680 - - // Find the innermost dimension in the dst whose size is not 1. This is the - // effective inner dim. - int num_size_one_inner_dims = 0; - for (int i = 0; i < num_squeezable_dims; ++i) { - const int dst_dim = IsColMajor ? i : NumDims - i - 1; - if (dst.dims[dst_dim] != 1) break; - num_size_one_inner_dims++; - } - - // If all dimensions are of size 1, just copy a scalar from `src` to `dst`. - if (num_size_one_inner_dims == NumDims) { - *(dst.data + dst.offset) = *(src.data + src.offset); - return 1; - } - - // Outermost dimension in the dst with `stride == 1` (contiguous in memory). - const int dst_stride1_dim = IsColMajor - ? num_size_one_inner_dims - : NumDims - num_size_one_inner_dims - 1; - - // Dimension in the src that corresponds to the dst innermost dimension. - const int src_dim_for_dst_stride1_dim = - NumDims == 0 ? 1 : dim_map[dst_stride1_dim]; - - // Size of the innermost dimension (length of contiguous blocks of memory). - IndexType dst_inner_dim_size = NumDims == 0 ? 1 : dst.dims[dst_stride1_dim]; - - // Squeeze multiple inner dims into one if they are contiguous in `dst` and - // `src` memory, so we can do less linear copy calls. - for (int i = num_size_one_inner_dims + 1; i < num_squeezable_dims; ++i) { - const int dst_dim = IsColMajor ? i : NumDims - i - 1; - const IndexType dst_stride = dst.strides[dst_dim]; - const IndexType src_stride = src.strides[dim_map[dst_dim]]; - if (dst_inner_dim_size == dst_stride && dst_stride == src_stride) { - dst_inner_dim_size *= dst.dims[dst_dim]; - ++num_size_one_inner_dims; - } else { - break; - } - } - - // Setup strides to read data from `src` and write to `dst`. - IndexType input_offset = src.offset; - IndexType output_offset = dst.offset; - IndexType input_stride = - NumDims == 0 ? 1 : src.strides[src_dim_for_dst_stride1_dim]; - IndexType output_stride = NumDims == 0 ? 1 : dst.strides[dst_stride1_dim]; - - const int at_least_1_dim = NumDims <= 1 ? 1 : NumDims - 1; - array<BlockIteratorState, at_least_1_dim> it; - - // Initialize block iterator state. Squeeze away any dimension of size 1. - int idx = 0; // currently initialized iterator state index - for (int i = num_size_one_inner_dims; i < NumDims - 1; ++i) { - const int dst_dim = IsColMajor ? i + 1 : NumDims - i - 2; - if (dst.dims[dst_dim] == 1) continue; - - it[idx].size = dst.dims[dst_dim]; - it[idx].input_stride = src.strides[dim_map[dst_dim]]; - it[idx].output_stride = dst.strides[dst_dim]; - - it[idx].input_span = it[idx].input_stride * (it[idx].size - 1); - it[idx].output_span = it[idx].output_stride * (it[idx].size - 1); - - idx++; - } - - // Iterate copying data from src to dst. - const IndexType block_total_size = NumDims == 0 ? 1 : dst.dims.TotalSize(); - -#define COPY_INNER_DIM(KIND) \ - IndexType num_copied = 0; \ - for (num_copied = 0; num_copied < block_total_size; \ - num_copied += dst_inner_dim_size) { \ - LinCopy::template Run<KIND>( \ - typename LinCopy::Dst(output_offset, output_stride, dst.data), \ - typename LinCopy::Src(input_offset, input_stride, src.data), \ - dst_inner_dim_size); \ - \ - for (int j = 0; j < idx; ++j) { \ - if (++it[j].count < it[j].size) { \ - input_offset += it[j].input_stride; \ - output_offset += it[j].output_stride; \ - break; \ - } \ - it[j].count = 0; \ - input_offset -= it[j].input_span; \ - output_offset -= it[j].output_span; \ - } \ - } \ - return num_copied; - - if (input_stride == 1 && output_stride == 1) { - COPY_INNER_DIM(LinCopy::Kind::Linear); - } else if (input_stride == 1 && output_stride != 1) { - COPY_INNER_DIM(LinCopy::Kind::Scatter); - } else if (input_stride == 0 && output_stride == 1) { - COPY_INNER_DIM(LinCopy::Kind::FillLinear); - } else if (input_stride == 0 && output_stride != 1) { - COPY_INNER_DIM(LinCopy::Kind::FillScatter); - } else if (output_stride == 1) { - COPY_INNER_DIM(LinCopy::Kind::Gather); - } else { - COPY_INNER_DIM(LinCopy::Kind::Random); - } - -#undef COPY_INNER_DIM - } - - // Copy from `src` to `dst` with an identity src->dst dimension map. Returns - // the number of copied elements. - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexType Copy(const Dst& dst, - const Src& src) { - DimensionsMap dst_to_src_map; - for (int i = 0; i < NumDims; ++i) dst_to_src_map[i] = i; - return Copy(dst, src, dst_to_src_map); - } - - private: - struct BlockIteratorState { - BlockIteratorState() - : size(0), - count(0), - input_stride(0), - output_stride(0), - input_span(0), - output_span(0) {} - - IndexType size; - IndexType count; - IndexType input_stride; - IndexType output_stride; - IndexType input_span; - IndexType output_span; - }; - - // Compute how many inner dimensions it's allowed to squeeze when doing IO - // between two tensor blocks. It's safe to squeeze inner dimensions, only - // if they are not reordered. - static int NumSqueezableInnerDims(const DimensionsMap& dim_map) { - int num_squeezable_dims = 0; - for (int i = 0; i < NumDims; ++i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - if (dim_map[dim] != dim) break; - num_squeezable_dims++; - } - return num_squeezable_dims; - } -}; - -// -------------------------------------------------------------------------- // -// TensorBlockAssignment assigns a block expression of type `TensorBlockExpr` to -// a Tensor block defined by `desc`, backed by a memory buffer at `target`. -// -// Currently there is no way to write from a Tensor expression to a block of -// memory, if dimensions are reordered. If you need to do that, you should -// materialize a Tensor block expression into a memory buffer, and then use -// TensorBlockIO to copy data between two memory buffers with a custom -// `target->src` dimension map (see definition above). -// -// Also currently the innermost dimension of `target` must have a stride '1' -// (contiguous in memory). This restriction could be lifted with a `pscatter`, -// but in practice it's never needed, and there is a similar TensorBlockIO -// workaround for that. -// -// TODO(ezhulenev): TensorBlockAssignment is a special case of TensorBlockIO -// where `src` is a tensor expression. Explore if it is possible to rewrite IO -// to use expressions instead of pointers, and after that TensorBlockAssignment -// will become an alias to IO. -template <typename Scalar, int NumDims, typename TensorBlockExpr, - typename IndexType = Eigen::Index> -class TensorBlockAssignment { - // We will use coeff/packet path to evaluate block expressions. - typedef TensorEvaluator<const TensorBlockExpr, DefaultDevice> - TensorBlockEvaluator; - - typedef DSizes<IndexType, NumDims> Dimensions; - - enum { - Vectorizable = packet_traits<Scalar>::Vectorizable, - PacketSize = packet_traits<Scalar>::size - }; - - template <bool Vectorizable, typename Evaluator> - struct InnerDimAssign { - EIGEN_ALWAYS_INLINE static void Run(Scalar* target, IndexType count, - const Evaluator& eval, - IndexType eval_offset) { - for (IndexType i = 0; i < count; ++i) { - target[i] = eval.coeff(eval_offset + i); - } - } - }; - - template <typename Evaluator> - struct InnerDimAssign<true, Evaluator> { - EIGEN_ALWAYS_INLINE static void Run(Scalar* target, IndexType count, - const Evaluator& eval, - IndexType eval_offset) { - typedef typename packet_traits<Scalar>::type Packet; - - const IndexType unrolled_size = count - 4 * PacketSize; - const IndexType vectorized_size = count - PacketSize; - IndexType i = 0; - - for (; i <= unrolled_size; i += 4 * PacketSize) { - for (int j = 0; j < 4; ++j) { - const IndexType idx = eval_offset + i + j * PacketSize; - Packet p = eval.template packet<Unaligned>(idx); - pstoreu<Scalar>(target + i + j * PacketSize, p); - } - } - - for (; i <= vectorized_size; i += PacketSize) { - Packet p = eval.template packet<Unaligned>(eval_offset + i); - pstoreu<Scalar>(target + i, p); - } - - for (; i < count; ++i) { - target[i] = eval.coeff(eval_offset + i); - } - } - }; - - public: - struct Target { - Target(const Dimensions& target_dims, const Dimensions& target_strides, - Scalar* target_data, IndexType target_offset = 0) - : dims(target_dims), - strides(target_strides), - data(target_data), - offset(target_offset) {} - - Dimensions dims; - Dimensions strides; - Scalar* data; - IndexType offset; - }; - - static Target target(const Dimensions& target_dims, - const Dimensions& target_strides, Scalar* target_data, - IndexType target_offset = 0) { - return Target(target_dims, target_strides, target_data, target_offset); - } - - template <typename TargetDimsIndexType, typename TargetStridesIndexType> - static Target target( - const DSizes<TargetDimsIndexType, NumDims>& target_dims, - const DSizes<TargetStridesIndexType, NumDims>& target_strides, - Scalar* target_data, IndexType target_offset = 0) { - // DSizes constructor will do index type promotion if it's safe. - return Target(Dimensions(target_dims), Dimensions(target_strides), - target_data, target_offset); - } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run( - const Target& target, const TensorBlockExpr& expr) { - // Prepare evaluator for block expression. - DefaultDevice default_device; - TensorBlockEvaluator eval(expr, default_device); - - // Tensor block expression dimension should match destination dimensions. - eigen_assert(dimensions_match(target.dims, eval.dimensions())); - - static const int Layout = TensorBlockEvaluator::Layout; - static const bool is_col_major = Layout == ColMajor; - - // Initialize output inner dimension size based on a layout. - const IndexType output_size = NumDims == 0 ? 1 : target.dims.TotalSize(); - const int inner_dim_idx = is_col_major ? 0 : NumDims - 1; - IndexType output_inner_dim_size = target.dims[inner_dim_idx]; - - // Target inner dimension stride must be '1'. - eigen_assert(target.strides[inner_dim_idx] == 1); - - // Squeeze multiple inner dims into one if they are contiguous in `target`. - IndexType num_squeezed_dims = 0; - for (Index i = 1; i < NumDims; ++i) { - const Index dim = is_col_major ? i : NumDims - i - 1; - const IndexType target_stride = target.strides[dim]; - - if (output_inner_dim_size == target_stride) { - output_inner_dim_size *= target.dims[dim]; - num_squeezed_dims++; - } else { - break; - } - } - - // Initialize output block iterator state. Dimension in this array are - // always in inner_most -> outer_most order (col major layout). - array<BlockIteratorState, NumDims> it; - - int idx = 0; // currently initialized iterator state index - for (Index i = num_squeezed_dims; i < NumDims - 1; ++i) { - const Index dim = is_col_major ? i + 1 : NumDims - i - 2; - - it[idx].count = 0; - it[idx].size = target.dims[dim]; - it[idx].output_stride = target.strides[dim]; - it[idx].output_span = it[idx].output_stride * (it[idx].size - 1); - idx++; - } - - // We read block expression from the beginning, and start writing data to - // `target` at given offset. - IndexType input_offset = 0; - IndexType output_offset = target.offset; - - // Iterate copying data from `eval` to `target`. - for (IndexType i = 0; i < output_size; i += output_inner_dim_size) { - // Assign to `target` at current offset. - InnerDimAssign<Vectorizable && TensorBlockEvaluator::PacketAccess, - TensorBlockEvaluator>::Run(target.data + output_offset, - output_inner_dim_size, eval, - input_offset); - - // Move input offset forward by the number of assigned coefficients. - input_offset += output_inner_dim_size; - - // Update index. - for (int j = 0; j < idx; ++j) { - if (++it[j].count < it[j].size) { - output_offset += it[j].output_stride; - break; - } - it[j].count = 0; - output_offset -= it[j].output_span; - } - } - } - - private: - struct BlockIteratorState { - BlockIteratorState() - : count(0), size(0), output_stride(0), output_span(0) {} - - IndexType count; - IndexType size; - IndexType output_stride; - IndexType output_span; - }; -}; - -// -------------------------------------------------------------------------- // - -} // namespace internal -} // namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_BLOCK_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBroadcasting.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBroadcasting.h deleted file mode 100644 index 3408f90d..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorBroadcasting.h +++ /dev/null @@ -1,1094 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_BROADCASTING_H -#define EIGEN_CXX11_TENSOR_TENSOR_BROADCASTING_H - -namespace Eigen { - -/** \class TensorBroadcasting - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor broadcasting class. - * - * - */ -namespace internal { -template<typename Broadcast, typename XprType> -struct traits<TensorBroadcastingOp<Broadcast, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename Broadcast, typename XprType> -struct eval<TensorBroadcastingOp<Broadcast, XprType>, Eigen::Dense> -{ - typedef const TensorBroadcastingOp<Broadcast, XprType> EIGEN_DEVICE_REF type; -}; - -template<typename Broadcast, typename XprType> -struct nested<TensorBroadcastingOp<Broadcast, XprType>, 1, typename eval<TensorBroadcastingOp<Broadcast, XprType> >::type> -{ - typedef TensorBroadcastingOp<Broadcast, XprType> type; -}; - -template <typename Dims> -struct is_input_scalar { - static const bool value = false; -}; -template <> -struct is_input_scalar<Sizes<> > { - static const bool value = true; -}; -#ifndef EIGEN_EMULATE_CXX11_META_H -template <typename std::ptrdiff_t... Indices> -struct is_input_scalar<Sizes<Indices...> > { - static const bool value = (Sizes<Indices...>::total_size == 1); -}; -#endif - -} // end namespace internal - - - -template<typename Broadcast, typename XprType> -class TensorBroadcastingOp : public TensorBase<TensorBroadcastingOp<Broadcast, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorBroadcastingOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorBroadcastingOp>::type Nested; - typedef typename Eigen::internal::traits<TensorBroadcastingOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorBroadcastingOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBroadcastingOp(const XprType& expr, const Broadcast& broadcast) - : m_xpr(expr), m_broadcast(broadcast) {} - - EIGEN_DEVICE_FUNC - const Broadcast& broadcast() const { return m_broadcast; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const Broadcast m_broadcast; -}; - - -// Eval as rvalue -template<typename Broadcast, typename ArgType, typename Device> -struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> -{ - typedef TensorBroadcastingOp<Broadcast, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions InputDimensions; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - protected: // all the non-static fields must have the same access control, otherwise the TensorEvaluator wont be standard layout; - bool isCopy, nByOne, oneByN; - public: - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = true, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = TensorEvaluator<ArgType, Device>::BlockAccess, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - RawAccess = false - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - // We do block based broadcasting using a trick with 2x tensor rank and 0 - // strides. See block method implementation for details. - typedef DSizes<Index, 2 * NumDims> BroadcastDimensions; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename TensorEvaluator<const ArgType, Device>::TensorBlock - ArgTensorBlock; - - typedef typename internal::TensorMaterializedBlock<ScalarNoConst, NumDims, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, - const Device& device) - : isCopy(false), nByOne(false), oneByN(false), - m_device(device), m_broadcast(op.broadcast()), m_impl(op.expression(), device) - { - - // The broadcasting op doesn't change the rank of the tensor. One can't broadcast a scalar - // and store the result in a scalar. Instead one should reshape the scalar into a a N-D - // tensor with N >= 1 of 1 element first and then broadcast. - EIGEN_STATIC_ASSERT((NumDims > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - const InputDimensions& input_dims = m_impl.dimensions(); - isCopy = true; - for (int i = 0; i < NumDims; ++i) { - eigen_assert(input_dims[i] > 0); - m_dimensions[i] = input_dims[i] * m_broadcast[i]; - if (m_broadcast[i] != 1) { - isCopy = false; - } - } - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_inputStrides[0] = 1; - m_outputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1]; - m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1]; - } - } else { - m_inputStrides[NumDims-1] = 1; - m_outputStrides[NumDims-1] = 1; - for (int i = NumDims-2; i >= 0; --i) { - m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1]; - m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1]; - } - } - - if (input_dims[0] == 1) { - oneByN = true; - for (int i = 1; i < NumDims; ++i) { - if (m_broadcast[i] != 1) { - oneByN = false; - break; - } - } - } else if (input_dims[NumDims-1] == 1) { - nByOne = true; - for (int i = 0; i < NumDims-1; ++i) { - if (m_broadcast[i] != 1) { - nByOne = false; - break; - } - } - } - - // Handle special format like NCHW, its input shape is '[1, N..., 1]' and - // broadcast shape is '[N, 1..., N]' - if (!oneByN && !nByOne) { - if (input_dims[0] == 1 && input_dims[NumDims-1] == 1 && NumDims > 2) { - nByOne = true; - oneByN = true; - for (int i = 1; i < NumDims-1; ++i) { - if (m_broadcast[i] != 1) { - nByOne = false; - oneByN = false; - break; - } - } - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - m_impl.evalSubExprsIfNeededAsync(nullptr, [done](bool) { done(true); }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE CoeffReturnType coeff(Index index) const - { - if (internal::is_input_scalar<typename internal::remove_all<InputDimensions>::type>::value) { - return m_impl.coeff(0); - } - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - if (isCopy) { - return m_impl.coeff(index); - } else { - return coeffColMajor(index); - } - } else { - if (isCopy) { - return m_impl.coeff(index); - } else { - return coeffRowMajor(index); - } - } - } - - // TODO: attempt to speed this up. The integer divisions and modulo are slow - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index indexColMajor(Index index) const { - Index inputIndex = 0; - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_outputStrides[i]; - if (internal::index_statically_eq<Broadcast>(i, 1)) { - eigen_assert(idx < m_impl.dimensions()[i]); - inputIndex += idx * m_inputStrides[i]; - } else { - if (internal::index_statically_eq<InputDimensions>(i, 1)) { - eigen_assert(idx % m_impl.dimensions()[i] == 0); - } else { - inputIndex += (idx % m_impl.dimensions()[i]) * m_inputStrides[i]; - } - } - index -= idx * m_outputStrides[i]; - } - if (internal::index_statically_eq<Broadcast>(0, 1)) { - eigen_assert(index < m_impl.dimensions()[0]); - inputIndex += index; - } else { - if (internal::index_statically_eq<InputDimensions>(0, 1)) { - eigen_assert(index % m_impl.dimensions()[0] == 0); - } else { - inputIndex += (index % m_impl.dimensions()[0]); - } - } - return inputIndex; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeffColMajor(Index index) const - { - return m_impl.coeff(indexColMajor(index)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index indexRowMajor(Index index) const { - Index inputIndex = 0; - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_outputStrides[i]; - if (internal::index_statically_eq<Broadcast>(i, 1)) { - eigen_assert(idx < m_impl.dimensions()[i]); - inputIndex += idx * m_inputStrides[i]; - } else { - if (internal::index_statically_eq<InputDimensions>(i, 1)) { - eigen_assert(idx % m_impl.dimensions()[i] == 0); - } else { - inputIndex += (idx % m_impl.dimensions()[i]) * m_inputStrides[i]; - } - } - index -= idx * m_outputStrides[i]; - } - if (internal::index_statically_eq<Broadcast>(NumDims - 1, 1)) { - eigen_assert(index < m_impl.dimensions()[NumDims - 1]); - inputIndex += index; - } else { - if (internal::index_statically_eq<InputDimensions>(NumDims - 1, 1)) { - eigen_assert(index % m_impl.dimensions()[NumDims - 1] == 0); - } else { - inputIndex += (index % m_impl.dimensions()[NumDims - 1]); - } - } - return inputIndex; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeffRowMajor(Index index) const - { - return m_impl.coeff(indexRowMajor(index)); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketReturnType packet(Index index) const - { - if (internal::is_input_scalar<typename internal::remove_all<InputDimensions>::type>::value) { - return internal::pset1<PacketReturnType>(m_impl.coeff(0)); - } - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - if (isCopy) { - #ifdef EIGEN_GPU_COMPILE_PHASE - // See PR 437: on NVIDIA P100 and K20m we observed a x3-4 speed up by enforcing - // unaligned loads here. The reason is unclear though. - return m_impl.template packet<Unaligned>(index); - #else - return m_impl.template packet<LoadMode>(index); - #endif - } else if (oneByN && !nByOne) { - return packetNByOne<LoadMode>(index); - } else if (!oneByN && nByOne) { - return packetOneByN<LoadMode>(index); - } else if (oneByN && nByOne) { - return packetOneByNByOne<LoadMode>(index); - } else { - return packetColMajor<LoadMode>(index); - } - } else { - if (isCopy) { - #ifdef EIGEN_GPU_COMPILE_PHASE - // See above. - return m_impl.template packet<Unaligned>(index); - #else - return m_impl.template packet<LoadMode>(index); - #endif - } else if (oneByN && !nByOne) { - return packetOneByN<LoadMode>(index); - } else if (!oneByN && nByOne) { - return packetNByOne<LoadMode>(index); - } else if (oneByN && nByOne) { - return packetOneByNByOne<LoadMode>(index); - } else { - return packetRowMajor<LoadMode>(index); - } - } - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetOneByNByOne - (Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - Index startDim, endDim; - Index inputIndex, outputOffset, batchedIndex; - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - startDim = NumDims - 1; - endDim = 1; - } else { - startDim = 0; - endDim = NumDims - 2; - } - - batchedIndex = index % m_outputStrides[startDim]; - inputIndex = batchedIndex / m_outputStrides[endDim]; - outputOffset = batchedIndex % m_outputStrides[endDim]; - - if (outputOffset + PacketSize <= m_outputStrides[endDim]) { - values[0] = m_impl.coeff(inputIndex); - return internal::pload1<PacketReturnType>(values); - } else { - EIGEN_UNROLL_LOOP - for (int i = 0, cur = 0; i < PacketSize; ++i, ++cur) { - if (outputOffset + cur < m_outputStrides[endDim]) { - values[i] = m_impl.coeff(inputIndex); - } else { - ++inputIndex; - inputIndex = (inputIndex == m_inputStrides[startDim] ? 0 : inputIndex); - values[i] = m_impl.coeff(inputIndex); - outputOffset = 0; - cur = 0; - } - } - return internal::pload<PacketReturnType>(values); - } - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetOneByN(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - Index dim, inputIndex; - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - dim = NumDims - 1; - } else { - dim = 0; - } - - inputIndex = index % m_inputStrides[dim]; - if (inputIndex + PacketSize <= m_inputStrides[dim]) { - return m_impl.template packet<Unaligned>(inputIndex); - } else { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - if (inputIndex > m_inputStrides[dim]-1) { - inputIndex = 0; - } - values[i] = m_impl.coeff(inputIndex++); - } - return internal::pload<PacketReturnType>(values); - } - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetNByOne(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - Index dim, inputIndex, outputOffset; - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - dim = 1; - } else { - dim = NumDims - 2; - } - - inputIndex = index / m_outputStrides[dim]; - outputOffset = index % m_outputStrides[dim]; - if (outputOffset + PacketSize <= m_outputStrides[dim]) { - values[0] = m_impl.coeff(inputIndex); - return internal::pload1<PacketReturnType>(values); - } else { - EIGEN_UNROLL_LOOP - for (int i = 0, cur = 0; i < PacketSize; ++i, ++cur) { - if (outputOffset + cur < m_outputStrides[dim]) { - values[i] = m_impl.coeff(inputIndex); - } else { - values[i] = m_impl.coeff(++inputIndex); - outputOffset = 0; - cur = 0; - } - } - return internal::pload<PacketReturnType>(values); - } - } - - // Ignore the LoadMode and always use unaligned loads since we can't guarantee - // the alignment at compile time. - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetColMajor(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - const Index originalIndex = index; - - Index inputIndex = 0; - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_outputStrides[i]; - if (internal::index_statically_eq<Broadcast>(i, 1)) { - eigen_assert(idx < m_impl.dimensions()[i]); - inputIndex += idx * m_inputStrides[i]; - } else { - if (internal::index_statically_eq<InputDimensions>(i, 1)) { - eigen_assert(idx % m_impl.dimensions()[i] == 0); - } else { - inputIndex += (idx % m_impl.dimensions()[i]) * m_inputStrides[i]; - } - } - index -= idx * m_outputStrides[i]; - } - Index innermostLoc; - if (internal::index_statically_eq<Broadcast>(0, 1)) { - eigen_assert(index < m_impl.dimensions()[0]); - innermostLoc = index; - } else { - if (internal::index_statically_eq<InputDimensions>(0, 1)) { - eigen_assert(index % m_impl.dimensions()[0] == 0); - innermostLoc = 0; - } else { - innermostLoc = index % m_impl.dimensions()[0]; - } - } - inputIndex += innermostLoc; - - // Todo: this could be extended to the second dimension if we're not - // broadcasting alongside the first dimension, and so on. - if (innermostLoc + PacketSize <= m_impl.dimensions()[0]) { - return m_impl.template packet<Unaligned>(inputIndex); - } else { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - values[0] = m_impl.coeff(inputIndex); - EIGEN_UNROLL_LOOP - for (int i = 1; i < PacketSize; ++i) { - if (innermostLoc + i < m_impl.dimensions()[0]) { - values[i] = m_impl.coeff(inputIndex+i); - } else { - values[i] = coeffColMajor(originalIndex+i); - } - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetRowMajor(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - const Index originalIndex = index; - - Index inputIndex = 0; - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_outputStrides[i]; - if (internal::index_statically_eq<Broadcast>(i, 1)) { - eigen_assert(idx < m_impl.dimensions()[i]); - inputIndex += idx * m_inputStrides[i]; - } else { - if (internal::index_statically_eq<InputDimensions>(i, 1)) { - eigen_assert(idx % m_impl.dimensions()[i] == 0); - } else { - inputIndex += (idx % m_impl.dimensions()[i]) * m_inputStrides[i]; - } - } - index -= idx * m_outputStrides[i]; - } - Index innermostLoc; - if (internal::index_statically_eq<Broadcast>(NumDims-1, 1)) { - eigen_assert(index < m_impl.dimensions()[NumDims-1]); - innermostLoc = index; - } else { - if (internal::index_statically_eq<InputDimensions>(NumDims-1, 1)) { - eigen_assert(index % m_impl.dimensions()[NumDims-1] == 0); - innermostLoc = 0; - } else { - innermostLoc = index % m_impl.dimensions()[NumDims-1]; - } - } - inputIndex += innermostLoc; - - // Todo: this could be extended to the second dimension if we're not - // broadcasting alongside the first dimension, and so on. - if (innermostLoc + PacketSize <= m_impl.dimensions()[NumDims-1]) { - return m_impl.template packet<Unaligned>(inputIndex); - } else { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - values[0] = m_impl.coeff(inputIndex); - EIGEN_UNROLL_LOOP - for (int i = 1; i < PacketSize; ++i) { - if (innermostLoc + i < m_impl.dimensions()[NumDims-1]) { - values[i] = m_impl.coeff(inputIndex+i); - } else { - values[i] = coeffRowMajor(originalIndex+i); - } - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - double compute_cost = TensorOpCost::AddCost<Index>(); - if (!isCopy && NumDims > 0) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - compute_cost += TensorOpCost::DivCost<Index>(); - if (internal::index_statically_eq<Broadcast>(i, 1)) { - compute_cost += - TensorOpCost::MulCost<Index>() + TensorOpCost::AddCost<Index>(); - } else { - if (!internal::index_statically_eq<InputDimensions>(i, 1)) { - compute_cost += TensorOpCost::MulCost<Index>() + - TensorOpCost::ModCost<Index>() + - TensorOpCost::AddCost<Index>(); - } - } - compute_cost += - TensorOpCost::MulCost<Index>() + TensorOpCost::AddCost<Index>(); - } - } - return m_impl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, compute_cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - // TODO(wuke): Targeting L1 size is 30% faster than targeting L{-1} on large - // tensors. But this might need further tuning. - const size_t target_size = m_device.firstLevelCacheSize(); - return internal::TensorBlockResourceRequirements::merge( - m_impl.getResourceRequirements(), - internal::TensorBlockResourceRequirements::skewed<Scalar>(target_size)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - BlockBroadcastingParams params = blockBroadcastingParams(desc); - - if (params.inner_dim_size == 0 || params.bcast_dim_size == 0) { - return emptyBlock(); - } - - // Prepare storage for the materialized broadcasting result. - const typename TensorBlock::Storage block_storage = - TensorBlock::prepareStorage(desc, scratch); - ScalarNoConst* materialized_output = block_storage.data(); - - // We potentially will need to materialize input blocks. - size_t materialized_input_size = 0; - ScalarNoConst* materialized_input = NULL; - - // Initialize block broadcating iterator state for outer dimensions (outer - // with regard to bcast dimension). Dimension in this array are always in - // inner_most -> outer_most order (col major layout). - array<BlockBroadcastingIteratorState, NumDims> it; - int idx = 0; - - for (int i = params.inner_dim_count + 1; i < NumDims; ++i) { - const Index dim = IsColMajor ? i : NumDims - 1 - i; - it[idx].size = params.output_dims[dim]; - it[idx].count = 0; - it[idx].output_stride = m_outputStrides[dim]; - it[idx].output_span = it[idx].output_stride * (it[idx].size - 1); - idx++; - } - - // Write output into the beginning of `materialized_output`. - Index output_offset = 0; - - // We will fill output block by broadcasting along the bcast dim, and - // iterating over outer dimension. - const Index output_size = NumDims == 0 ? 1 : params.output_dims.TotalSize(); - - for (Index num_output_coeffs = 0; num_output_coeffs < output_size;) { - ScalarNoConst* bcast_output = materialized_output + num_output_coeffs; - Index bcast_offset = desc.offset() + output_offset; - - // Broadcast along the bcast dimension. - num_output_coeffs += BroadcastBlockAlongBcastDim( - params, bcast_offset, scratch, bcast_output, &materialized_input, - &materialized_input_size); - - // Switch to the next outer dimension. - for (int j = 0; j < idx; ++j) { - if (++it[j].count < it[j].size) { - output_offset += it[j].output_stride; - break; - } - it[j].count = 0; - output_offset -= it[j].output_span; - } - } - - return block_storage.AsTensorMaterializedBlock(); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - - const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; } - - Broadcast functor() const { return m_broadcast; } -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind( - cl::sycl::handler& cgh) const { - m_impl.bind(cgh); - } -#endif - private: - static const bool IsColMajor = - static_cast<int>(Layout) == static_cast<int>(ColMajor); - - // We will build a general case block broadcasting on top of broadcasting - // primitive that will do broadcasting only for the inner dimension(s) along - // the first dimension smaller than the input size (it's called `bcast_dim`). - // - // Example: - // dim: 0 1 2 (ColMajor) - // input size: [9, 3, 6] - // block size: [9, 2, 6] - // - // We will compute broadcasted block by iterating over the outer dimensions - // before `bcast_dim` (only dimension `2` in this example) and computing - // broadcasts along the `bcast_dim` (dimension `1` in this example). - - // BlockBroadcastingParams holds precomputed parameters for broadcasting a - // single block along the broadcasting dimension. Sizes and strides along the - // `bcast_dim` might be invalid, they will be adjusted later in - // `BroadcastBlockAlongBcastDim`. - struct BlockBroadcastingParams { - Dimensions input_dims; // input expression dimensions - Dimensions output_dims; // output block sizes - Dimensions output_strides; // output block strides - - int inner_dim_count; // count inner dimensions matching in size - int bcast_dim; // broadcasting dimension index - Index bcast_dim_size; // broadcasting dimension size - Index inner_dim_size; // inner dimensions size - - // Block sizes and strides for the input block where all dimensions before - // `bcast_dim` are equal to `1`. - Dimensions input_block_sizes; - Dimensions input_block_strides; - - // Block sizes and strides for blocks with extra dimensions and strides `0`. - BroadcastDimensions bcast_block_sizes; - BroadcastDimensions bcast_block_strides; - BroadcastDimensions bcast_input_strides; - }; - - struct BlockBroadcastingIteratorState { - Index size; - Index count; - Index output_stride; - Index output_span; - }; - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BlockBroadcastingParams - blockBroadcastingParams(TensorBlockDesc& desc) const { - BlockBroadcastingParams params; - - params.input_dims = Dimensions(m_impl.dimensions()); - - // Output block sizes and strides. - params.output_dims = desc.dimensions(); - params.output_strides = internal::strides<Layout>(params.output_dims); - - // Find the broadcasting dimension (first dimension with output size smaller - // that the input size). - params.bcast_dim = 0; - params.bcast_dim_size = 1; - params.inner_dim_size = 1; - - // Count the number of inner dimensions that have the same size in the block - // and in the broadcast expression. - params.inner_dim_count = 0; - - for (int i = 0; i < NumDims; ++i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - - if (params.output_dims[dim] == m_dimensions[dim]) { - params.inner_dim_size *= params.output_dims[dim]; - ++params.inner_dim_count; - continue; - } - - // First non-matching dimension is the broadcasting dimension. - eigen_assert(params.output_dims[dim] < m_dimensions[dim]); - params.bcast_dim = dim; - params.bcast_dim_size = params.output_dims[dim]; - break; - } - - // Calculate the input block size for looking into the input. - for (int i = 0; i < params.inner_dim_count; ++i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - params.input_block_sizes[dim] = params.input_dims[dim]; - } - for (int i = params.inner_dim_count; i < NumDims; ++i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - params.input_block_sizes[dim] = 1; - } - params.input_block_strides = - internal::strides<Layout>(params.input_block_sizes); - - // Broadcast with the 0-stride trick: Create 1 extra dim for each - // broadcast, set the input stride to 0. - // - // When ColMajor: - // - // - bcast_block_sizes: - // [d_0, b_0, d_1, b_1, ...] - // - // - bcast_block_strides: - // [output_block_strides[0], output_block_strides[0] * d_0, - // output_block_strides[1], output_block_strides[1] * d_1, - // ...] - // - // - bcast_input_strides: - // [input_block_strides[0], 0, - // input_block_strides[1], 0, - // ...]. - // - for (int i = 0; i < params.inner_dim_count; ++i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - - const int copy_dim = IsColMajor ? 2 * i : 2 * NumDims - 2 * i - 1; - const int broadcast_dim = IsColMajor ? copy_dim + 1 : copy_dim - 1; - - params.bcast_block_sizes[copy_dim] = params.input_dims[dim]; - params.bcast_block_sizes[broadcast_dim] = m_broadcast[dim]; - params.bcast_block_strides[copy_dim] = params.output_strides[dim]; - params.bcast_block_strides[broadcast_dim] = - params.output_strides[dim] * params.input_dims[dim]; - params.bcast_input_strides[copy_dim] = params.input_block_strides[dim]; - params.bcast_input_strides[broadcast_dim] = 0; - } - - for (int i = 2 * params.inner_dim_count; i < 2 * NumDims; ++i) { - const int dim = IsColMajor ? i : 2 * NumDims - i - 1; - params.bcast_block_sizes[dim] = 1; - params.bcast_block_strides[dim] = 0; - params.bcast_input_strides[dim] = 0; - } - - return params; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock emptyBlock() const { - DSizes<Index, NumDims> dimensions; - for (int i = 0; i < NumDims; ++i) dimensions[i] = 0; - return TensorBlock(internal::TensorBlockKind::kView, NULL, dimensions); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index BroadcastBlockAlongBcastDim( - BlockBroadcastingParams params, Index bcast_offset, - TensorBlockScratch& scratch, ScalarNoConst* materialized_output, - ScalarNoConst** materialized_input, - size_t* materialized_input_size) const { - if (params.bcast_dim_size == 1) { - // We just need one block read using the ready-set values above. - return BroadcastBlock( - params.input_block_sizes, params.input_block_strides, - params.bcast_block_sizes, params.bcast_block_strides, - params.bcast_input_strides, bcast_offset, 0, scratch, - materialized_output, materialized_input, materialized_input_size); - - } else if (params.input_dims[params.bcast_dim] == 1) { - // Broadcast bcast dimension (< NumDims) by bcast_dim_size. - const int broadcast_bcast_dim = - IsColMajor ? 2 * params.inner_dim_count + 1 - : 2 * NumDims - 2 * params.inner_dim_count - 2; - - params.bcast_block_sizes[broadcast_bcast_dim] = params.bcast_dim_size; - params.bcast_input_strides[broadcast_bcast_dim] = 0; - params.bcast_block_strides[broadcast_bcast_dim] = - params.output_strides[params.bcast_dim]; - - return BroadcastBlock( - params.input_block_sizes, params.input_block_strides, - params.bcast_block_sizes, params.bcast_block_strides, - params.bcast_input_strides, bcast_offset, 0, scratch, - materialized_output, materialized_input, materialized_input_size); - - } else { - // Keep track of the total number of the coefficients written to the - // output block. - Index num_output_coeffs = 0; - - // The general case. Let's denote the output block as - // - // x[..., a:a+bcast_dim_size, :, ..., :] - // - // where a:a+bcast_dim_size is a slice on the bcast_dim dimension - // (< NumDims). We need to split the a:a+bcast_dim_size into possibly 3 - // sub-blocks: - // - // (1) a:b, where b is the smallest multiple of - // input_dims[bcast_dim_start] in [a, a+bcast_dim_size]. - // - // (2) b:c, where c is the largest multiple of input_dims[bcast_dim_start] - // in [a, a+bcast_dim_size]. - // - // (3) c:a+bcast_dim_size . - // - // Or, when b and c do not exist, we just need to process the whole block - // together. - - // Find a. - const Index bcast_dim_left_index = - bcast_offset / m_outputStrides[params.bcast_dim]; - - // Find b and c. - const Index input_bcast_dim_size = params.input_dims[params.bcast_dim]; - - // First multiple after a. This is b when <= bcast_dim_left_index + - // bcast_dim_size. - const Index first_multiple = - divup<Index>(bcast_dim_left_index, input_bcast_dim_size) * - input_bcast_dim_size; - - if (first_multiple <= bcast_dim_left_index + params.bcast_dim_size) { - // b exists, so does c. Find it. - const Index last_multiple = - (bcast_dim_left_index + params.bcast_dim_size) / - input_bcast_dim_size * input_bcast_dim_size; - const int copy_bcast_dim = - IsColMajor ? 2 * params.inner_dim_count - : 2 * NumDims - 2 * params.inner_dim_count - 1; - const int broadcast_bcast_dim = - IsColMajor ? 2 * params.inner_dim_count + 1 - : 2 * NumDims - 2 * params.inner_dim_count - 2; - - if (first_multiple > bcast_dim_left_index) { - const Index head_size = first_multiple - bcast_dim_left_index; - params.input_block_sizes[params.bcast_dim] = head_size; - params.bcast_block_sizes[copy_bcast_dim] = head_size; - params.bcast_input_strides[copy_bcast_dim] = - params.input_block_strides[params.bcast_dim]; - params.bcast_block_strides[copy_bcast_dim] = - params.output_strides[params.bcast_dim]; - params.bcast_block_sizes[broadcast_bcast_dim] = 1; - params.bcast_input_strides[broadcast_bcast_dim] = 0; - params.bcast_block_strides[broadcast_bcast_dim] = - params.output_strides[params.bcast_dim] * - params.input_dims[params.bcast_dim]; - - num_output_coeffs += BroadcastBlock( - params.input_block_sizes, params.input_block_strides, - params.bcast_block_sizes, params.bcast_block_strides, - params.bcast_input_strides, bcast_offset, 0, scratch, - materialized_output, materialized_input, materialized_input_size); - } - if (first_multiple < last_multiple) { - params.input_block_sizes[params.bcast_dim] = input_bcast_dim_size; - params.bcast_block_sizes[copy_bcast_dim] = input_bcast_dim_size; - params.bcast_input_strides[copy_bcast_dim] = - params.input_block_strides[params.bcast_dim]; - params.bcast_block_strides[copy_bcast_dim] = - params.output_strides[params.bcast_dim]; - params.bcast_block_sizes[broadcast_bcast_dim] = - (last_multiple - first_multiple) / input_bcast_dim_size; - params.bcast_input_strides[broadcast_bcast_dim] = 0; - params.bcast_block_strides[broadcast_bcast_dim] = - params.output_strides[params.bcast_dim] * - params.input_dims[params.bcast_dim]; - const Index offset = (first_multiple - bcast_dim_left_index) * - m_outputStrides[params.bcast_dim]; - - num_output_coeffs += BroadcastBlock( - params.input_block_sizes, params.input_block_strides, - params.bcast_block_sizes, params.bcast_block_strides, - params.bcast_input_strides, bcast_offset, offset, scratch, - materialized_output, materialized_input, materialized_input_size); - } - if (last_multiple < bcast_dim_left_index + params.bcast_dim_size) { - const Index tail_size = - bcast_dim_left_index + params.bcast_dim_size - last_multiple; - params.input_block_sizes[params.bcast_dim] = tail_size; - params.bcast_block_sizes[copy_bcast_dim] = tail_size; - params.bcast_input_strides[copy_bcast_dim] = - params.input_block_strides[params.bcast_dim]; - params.bcast_block_strides[copy_bcast_dim] = - params.output_strides[params.bcast_dim]; - params.bcast_block_sizes[broadcast_bcast_dim] = 1; - params.bcast_input_strides[broadcast_bcast_dim] = 0; - params.bcast_block_strides[broadcast_bcast_dim] = - params.output_strides[params.bcast_dim] * - params.input_dims[params.bcast_dim]; - const Index offset = (last_multiple - bcast_dim_left_index) * - m_outputStrides[params.bcast_dim]; - - num_output_coeffs += BroadcastBlock( - params.input_block_sizes, params.input_block_strides, - params.bcast_block_sizes, params.bcast_block_strides, - params.bcast_input_strides, bcast_offset, offset, scratch, - materialized_output, materialized_input, materialized_input_size); - } - } else { - // b and c do not exist. - const int copy_bcast_dim = - IsColMajor ? 2 * params.inner_dim_count - : 2 * NumDims - 2 * params.inner_dim_count - 1; - params.input_block_sizes[params.bcast_dim] = params.bcast_dim_size; - params.bcast_block_sizes[copy_bcast_dim] = params.bcast_dim_size; - params.bcast_input_strides[copy_bcast_dim] = - params.input_block_strides[params.bcast_dim]; - params.bcast_block_strides[copy_bcast_dim] = - params.output_strides[params.bcast_dim]; - - num_output_coeffs += BroadcastBlock( - params.input_block_sizes, params.input_block_strides, - params.bcast_block_sizes, params.bcast_block_strides, - params.bcast_input_strides, bcast_offset, 0, scratch, - materialized_output, materialized_input, materialized_input_size); - } - - return num_output_coeffs; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index BroadcastBlock( - const Dimensions& input_block_sizes, - const Dimensions& input_block_strides, - const BroadcastDimensions& bcast_block_sizes, - const BroadcastDimensions& bcast_block_strides, - const BroadcastDimensions& bcast_input_strides, Index bcast_offset, - Index offset, TensorBlockScratch& scratch, - ScalarNoConst* materialized_output, ScalarNoConst** materialized_input, - size_t* materialized_input_size) const { - // ---------------------------------------------------------------------- // - // Tensor block descriptor for reading block from the input. - const Index input_offset = bcast_offset + offset; - TensorBlockDesc input_desc( - IsColMajor ? indexColMajor(input_offset) : indexRowMajor(input_offset), - input_block_sizes); - - ArgTensorBlock input_block = m_impl.block(input_desc, scratch); - - // ---------------------------------------------------------------------- // - // Materialize input block into a temporary memory buffer only if it's not - // already available in the arg block. - const ScalarNoConst* input_buffer = NULL; - - if (input_block.data() != NULL) { - // Input block already has raw data, there is no need to materialize it. - input_buffer = input_block.data(); - - } else { - // Otherwise we have to do block assignment into a temporary buffer. - - // Maybe reuse previously allocated buffer, or allocate a new one with a - // scratch allocator. - const size_t input_total_size = input_block_sizes.TotalSize(); - if (*materialized_input == NULL || - *materialized_input_size < input_total_size) { - *materialized_input_size = input_total_size; - void* mem = scratch.allocate(*materialized_input_size * sizeof(Scalar)); - *materialized_input = static_cast<ScalarNoConst*>(mem); - } - - typedef internal::TensorBlockAssignment< - ScalarNoConst, NumDims, typename ArgTensorBlock::XprType, Index> - TensorBlockAssignment; - - TensorBlockAssignment::Run( - TensorBlockAssignment::target(input_block_sizes, input_block_strides, - *materialized_input), - input_block.expr()); - - input_buffer = *materialized_input; - } - - // ---------------------------------------------------------------------- // - // Copy data from materialized input block to the materialized output, using - // given broadcast strides (strides with zeroes). - typedef internal::TensorBlockIO<ScalarNoConst, Index, 2 * NumDims, Layout> - TensorBlockIO; - - typename TensorBlockIO::Src src(bcast_input_strides, input_buffer); - typename TensorBlockIO::Dst dst(bcast_block_sizes, bcast_block_strides, - materialized_output + offset); - - return TensorBlockIO::Copy(dst, src); - } - -protected: - const Device EIGEN_DEVICE_REF m_device; - const typename internal::remove_reference<Broadcast>::type m_broadcast; - Dimensions m_dimensions; - array<Index, NumDims> m_outputStrides; - array<Index, NumDims> m_inputStrides; - TensorEvaluator<ArgType, Device> m_impl; -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_BROADCASTING_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorChipping.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorChipping.h deleted file mode 100644 index 5b28e706..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorChipping.h +++ /dev/null @@ -1,534 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H -#define EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H - -namespace Eigen { - -/** \class TensorKChippingReshaping - * \ingroup CXX11_Tensor_Module - * - * \brief A chip is a thin slice, corresponding to a column or a row in a 2-d tensor. - * - * - */ - -namespace internal { -template<DenseIndex DimId, typename XprType> -struct traits<TensorChippingOp<DimId, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions - 1; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<DenseIndex DimId, typename XprType> -struct eval<TensorChippingOp<DimId, XprType>, Eigen::Dense> -{ - typedef const TensorChippingOp<DimId, XprType> EIGEN_DEVICE_REF type; -}; - -template<DenseIndex DimId, typename XprType> -struct nested<TensorChippingOp<DimId, XprType>, 1, typename eval<TensorChippingOp<DimId, XprType> >::type> -{ - typedef TensorChippingOp<DimId, XprType> type; -}; - -template <DenseIndex DimId> -struct DimensionId -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DimensionId(DenseIndex dim) { - EIGEN_UNUSED_VARIABLE(dim); - eigen_assert(dim == DimId); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex actualDim() const { - return DimId; - } -}; -template <> -struct DimensionId<Dynamic> -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DimensionId(DenseIndex dim) : actual_dim(dim) { - eigen_assert(dim >= 0); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex actualDim() const { - return actual_dim; - } - private: - const DenseIndex actual_dim; -}; - - -} // end namespace internal - - - -template<DenseIndex DimId, typename XprType> -class TensorChippingOp : public TensorBase<TensorChippingOp<DimId, XprType> > -{ - public: - typedef typename Eigen::internal::traits<TensorChippingOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorChippingOp>::type Nested; - typedef typename Eigen::internal::traits<TensorChippingOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorChippingOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorChippingOp(const XprType& expr, const Index offset, const Index dim) - : m_xpr(expr), m_offset(offset), m_dim(dim) { - } - - EIGEN_DEVICE_FUNC - const Index offset() const { return m_offset; } - EIGEN_DEVICE_FUNC - const Index dim() const { return m_dim.actualDim(); } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorChippingOp& operator = (const TensorChippingOp& other) - { - typedef TensorAssignOp<TensorChippingOp, const TensorChippingOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorChippingOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorChippingOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - protected: - typename XprType::Nested m_xpr; - const Index m_offset; - const internal::DimensionId<DimId> m_dim; -}; - - -// Eval as rvalue -template<DenseIndex DimId, typename ArgType, typename Device> -struct TensorEvaluator<const TensorChippingOp<DimId, ArgType>, Device> -{ - typedef TensorChippingOp<DimId, ArgType> XprType; - static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - static const int NumDims = NumInputDims-1; - typedef typename XprType::Index Index; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - // Alignment can't be guaranteed at compile time since it depends on the - // slice offsets. - IsAligned = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = TensorEvaluator<ArgType, Device>::BlockAccess, - // Chipping of outer-most dimension is a trivial operation, because we can - // read and write directly from the underlying tensor using single offset. - IsOuterChipping = (static_cast<int>(Layout) == ColMajor && DimId == NumInputDims - 1) || - (static_cast<int>(Layout) == RowMajor && DimId == 0), - // Chipping inner-most dimension. - IsInnerChipping = (static_cast<int>(Layout) == ColMajor && DimId == 0) || - (static_cast<int>(Layout) == RowMajor && DimId == NumInputDims - 1), - // Prefer block access if the underlying expression prefers it, otherwise - // only if chipping is not trivial. - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess || - !IsOuterChipping, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef internal::TensorBlockDescriptor<NumInputDims, Index> - ArgTensorBlockDesc; - typedef typename TensorEvaluator<const ArgType, Device>::TensorBlock - ArgTensorBlock; - - typedef typename internal::TensorMaterializedBlock<ScalarNoConst, NumDims, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_dim(op.dim()), m_device(device) - { - EIGEN_STATIC_ASSERT((NumInputDims >= 1), YOU_MADE_A_PROGRAMMING_MISTAKE); - eigen_assert(NumInputDims > m_dim.actualDim()); - - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - eigen_assert(op.offset() < input_dims[m_dim.actualDim()]); - - int j = 0; - for (int i = 0; i < NumInputDims; ++i) { - if (i != m_dim.actualDim()) { - m_dimensions[j] = input_dims[i]; - ++j; - } - } - - m_stride = 1; - m_inputStride = 1; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = 0; i < m_dim.actualDim(); ++i) { - m_stride *= input_dims[i]; - m_inputStride *= input_dims[i]; - } - } else { - for (int i = NumInputDims-1; i > m_dim.actualDim(); --i) { - m_stride *= input_dims[i]; - m_inputStride *= input_dims[i]; - } - } - m_inputStride *= input_dims[m_dim.actualDim()]; - m_inputOffset = m_stride * op.offset(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return m_impl.coeff(srcCoeff(index)); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - if (isInnerChipping()) { - // m_stride is equal to 1, so let's avoid the integer division. - eigen_assert(m_stride == 1); - Index inputIndex = index * m_inputStride + m_inputOffset; - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = m_impl.coeff(inputIndex); - inputIndex += m_inputStride; - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } else if (isOuterChipping()) { - // m_stride is always greater than index, so let's avoid the integer division. - eigen_assert(m_stride > index); - return m_impl.template packet<LoadMode>(index + m_inputOffset); - } else { - const Index idx = index / m_stride; - const Index rem = index - idx * m_stride; - if (rem + PacketSize <= m_stride) { - Index inputIndex = idx * m_inputStride + m_inputOffset + rem; - return m_impl.template packet<LoadMode>(inputIndex); - } else { - // Cross the stride boundary. Fallback to slow path. - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index); - ++index; - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - double cost = 0; - if ((static_cast<int>(Layout) == static_cast<int>(ColMajor) && - m_dim.actualDim() == 0) || - (static_cast<int>(Layout) == static_cast<int>(RowMajor) && - m_dim.actualDim() == NumInputDims - 1)) { - cost += TensorOpCost::MulCost<Index>() + TensorOpCost::AddCost<Index>(); - } else if ((static_cast<int>(Layout) == static_cast<int>(ColMajor) && - m_dim.actualDim() == NumInputDims - 1) || - (static_cast<int>(Layout) == static_cast<int>(RowMajor) && - m_dim.actualDim() == 0)) { - cost += TensorOpCost::AddCost<Index>(); - } else { - cost += 3 * TensorOpCost::MulCost<Index>() + TensorOpCost::DivCost<Index>() + - 3 * TensorOpCost::AddCost<Index>(); - } - - return m_impl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - const size_t target_size = m_device.lastLevelCacheSize(); - return internal::TensorBlockResourceRequirements::merge( - internal::TensorBlockResourceRequirements::skewed<Scalar>(target_size), - m_impl.getResourceRequirements()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool root_of_expr_ast = false) const { - const Index chip_dim = m_dim.actualDim(); - - DSizes<Index, NumInputDims> input_block_dims; - for (int i = 0; i < NumInputDims; ++i) { - input_block_dims[i] - = i < chip_dim ? desc.dimension(i) - : i > chip_dim ? desc.dimension(i - 1) - : 1; - } - - ArgTensorBlockDesc arg_desc(srcCoeff(desc.offset()), input_block_dims); - - // Try to reuse destination buffer for materializing argument block. - if (desc.HasDestinationBuffer()) { - DSizes<Index, NumInputDims> arg_destination_strides; - for (int i = 0; i < NumInputDims; ++i) { - arg_destination_strides[i] - = i < chip_dim ? desc.destination().strides()[i] - : i > chip_dim ? desc.destination().strides()[i - 1] - : 0; // for dimensions of size `1` stride should never be used. - } - - arg_desc.template AddDestinationBuffer<Layout>( - desc.destination().template data<ScalarNoConst>(), - arg_destination_strides); - } - - ArgTensorBlock arg_block = m_impl.block(arg_desc, scratch, root_of_expr_ast); - if (!arg_desc.HasDestinationBuffer()) desc.DropDestinationBuffer(); - - if (arg_block.data() != NULL) { - // Forward argument block buffer if possible. - return TensorBlock(arg_block.kind(), arg_block.data(), - desc.dimensions()); - - } else { - // Assign argument block expression to a buffer. - - // Prepare storage for the materialized chipping result. - const typename TensorBlock::Storage block_storage = - TensorBlock::prepareStorage(desc, scratch); - - typedef internal::TensorBlockAssignment< - ScalarNoConst, NumInputDims, typename ArgTensorBlock::XprType, Index> - TensorBlockAssignment; - - TensorBlockAssignment::Run( - TensorBlockAssignment::target( - arg_desc.dimensions(), - internal::strides<Layout>(arg_desc.dimensions()), - block_storage.data()), - arg_block.expr()); - - return block_storage.AsTensorMaterializedBlock(); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Storage::Type data() const { - typename Storage::Type result = constCast(m_impl.data()); - if (isOuterChipping() && result) { - return result + m_inputOffset; - } else { - return NULL; - } - } -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index srcCoeff(Index index) const - { - Index inputIndex; - if (isInnerChipping()) { - // m_stride is equal to 1, so let's avoid the integer division. - eigen_assert(m_stride == 1); - inputIndex = index * m_inputStride + m_inputOffset; - } else if (isOuterChipping()) { - // m_stride is always greater than index, so let's avoid the integer - // division. - eigen_assert(m_stride > index); - inputIndex = index + m_inputOffset; - } else { - const Index idx = index / m_stride; - inputIndex = idx * m_inputStride + m_inputOffset; - index -= idx * m_stride; - inputIndex += index; - } - return inputIndex; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool isInnerChipping() const { - return IsInnerChipping || - (static_cast<int>(Layout) == ColMajor && m_dim.actualDim() == 0) || - (static_cast<int>(Layout) == RowMajor && m_dim.actualDim() == NumInputDims - 1); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool isOuterChipping() const { - return IsOuterChipping || - (static_cast<int>(Layout) == ColMajor && m_dim.actualDim() == NumInputDims-1) || - (static_cast<int>(Layout) == RowMajor && m_dim.actualDim() == 0); - } - - Dimensions m_dimensions; - Index m_stride; - Index m_inputOffset; - Index m_inputStride; - TensorEvaluator<ArgType, Device> m_impl; - const internal::DimensionId<DimId> m_dim; - const Device EIGEN_DEVICE_REF m_device; -}; - - -// Eval as lvalue -template<DenseIndex DimId, typename ArgType, typename Device> -struct TensorEvaluator<TensorChippingOp<DimId, ArgType>, Device> - : public TensorEvaluator<const TensorChippingOp<DimId, ArgType>, Device> -{ - typedef TensorEvaluator<const TensorChippingOp<DimId, ArgType>, Device> Base; - typedef TensorChippingOp<DimId, ArgType> XprType; - static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - static const int NumDims = NumInputDims-1; - typedef typename XprType::Index Index; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = TensorEvaluator<ArgType, Device>::RawAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : Base(op, device) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index) - { - return this->m_impl.coeffRef(this->srcCoeff(index)); - } - - template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - - if (this->isInnerChipping()) { - // m_stride is equal to 1, so let's avoid the integer division. - eigen_assert(this->m_stride == 1); - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - internal::pstore<CoeffReturnType, PacketReturnType>(values, x); - Index inputIndex = index * this->m_inputStride + this->m_inputOffset; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - this->m_impl.coeffRef(inputIndex) = values[i]; - inputIndex += this->m_inputStride; - } - } else if (this->isOuterChipping()) { - // m_stride is always greater than index, so let's avoid the integer division. - eigen_assert(this->m_stride > index); - this->m_impl.template writePacket<StoreMode>(index + this->m_inputOffset, x); - } else { - const Index idx = index / this->m_stride; - const Index rem = index - idx * this->m_stride; - if (rem + PacketSize <= this->m_stride) { - const Index inputIndex = idx * this->m_inputStride + this->m_inputOffset + rem; - this->m_impl.template writePacket<StoreMode>(inputIndex, x); - } else { - // Cross stride boundary. Fallback to slow path. - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - internal::pstore<CoeffReturnType, PacketReturnType>(values, x); - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - this->coeffRef(index) = values[i]; - ++index; - } - } - } - } - - template <typename TensorBlock> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writeBlock( - const TensorBlockDesc& desc, const TensorBlock& block) { - assert(this->m_impl.data() != NULL); - - const Index chip_dim = this->m_dim.actualDim(); - - DSizes<Index, NumInputDims> input_block_dims; - for (int i = 0; i < NumInputDims; ++i) { - input_block_dims[i] = i < chip_dim ? desc.dimension(i) - : i > chip_dim ? desc.dimension(i - 1) - : 1; - } - - typedef TensorReshapingOp<const DSizes<Index, NumInputDims>, - const typename TensorBlock::XprType> - TensorBlockExpr; - - typedef internal::TensorBlockAssignment<Scalar, NumInputDims, - TensorBlockExpr, Index> - TensorBlockAssign; - - TensorBlockAssign::Run( - TensorBlockAssign::target( - input_block_dims, - internal::strides<Layout>(this->m_impl.dimensions()), - this->m_impl.data(), this->srcCoeff(desc.offset())), - block.expr().reshape(input_block_dims)); - } -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConcatenation.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConcatenation.h deleted file mode 100644 index 5968ff4b..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConcatenation.h +++ /dev/null @@ -1,394 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H - -namespace Eigen { - -/** \class TensorConcatenationOp - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor concatenation class. - * - * - */ -namespace internal { -template<typename Axis, typename LhsXprType, typename RhsXprType> -struct traits<TensorConcatenationOp<Axis, LhsXprType, RhsXprType> > -{ - // Type promotion to handle the case where the types of the lhs and the rhs are different. - typedef typename promote_storage_type<typename LhsXprType::Scalar, - typename RhsXprType::Scalar>::ret Scalar; - typedef typename promote_storage_type<typename traits<LhsXprType>::StorageKind, - typename traits<RhsXprType>::StorageKind>::ret StorageKind; - typedef typename promote_index_type<typename traits<LhsXprType>::Index, - typename traits<RhsXprType>::Index>::type Index; - typedef typename LhsXprType::Nested LhsNested; - typedef typename RhsXprType::Nested RhsNested; - typedef typename remove_reference<LhsNested>::type _LhsNested; - typedef typename remove_reference<RhsNested>::type _RhsNested; - static const int NumDimensions = traits<LhsXprType>::NumDimensions; - static const int Layout = traits<LhsXprType>::Layout; - enum { Flags = 0 }; - typedef typename conditional<Pointer_type_promotion<typename LhsXprType::Scalar, Scalar>::val, - typename traits<LhsXprType>::PointerType, typename traits<RhsXprType>::PointerType>::type PointerType; -}; - -template<typename Axis, typename LhsXprType, typename RhsXprType> -struct eval<TensorConcatenationOp<Axis, LhsXprType, RhsXprType>, Eigen::Dense> -{ - typedef const TensorConcatenationOp<Axis, LhsXprType, RhsXprType>& type; -}; - -template<typename Axis, typename LhsXprType, typename RhsXprType> -struct nested<TensorConcatenationOp<Axis, LhsXprType, RhsXprType>, 1, typename eval<TensorConcatenationOp<Axis, LhsXprType, RhsXprType> >::type> -{ - typedef TensorConcatenationOp<Axis, LhsXprType, RhsXprType> type; -}; - -} // end namespace internal - - -template<typename Axis, typename LhsXprType, typename RhsXprType> -class TensorConcatenationOp : public TensorBase<TensorConcatenationOp<Axis, LhsXprType, RhsXprType>, WriteAccessors> -{ - public: - typedef typename internal::traits<TensorConcatenationOp>::Scalar Scalar; - typedef typename internal::traits<TensorConcatenationOp>::StorageKind StorageKind; - typedef typename internal::traits<TensorConcatenationOp>::Index Index; - typedef typename internal::nested<TensorConcatenationOp>::type Nested; - typedef typename internal::promote_storage_type<typename LhsXprType::CoeffReturnType, - typename RhsXprType::CoeffReturnType>::ret CoeffReturnType; - typedef typename NumTraits<Scalar>::Real RealScalar; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConcatenationOp(const LhsXprType& lhs, const RhsXprType& rhs, Axis axis) - : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_axis(axis) {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename LhsXprType::Nested>::type& - lhsExpression() const { return m_lhs_xpr; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename RhsXprType::Nested>::type& - rhsExpression() const { return m_rhs_xpr; } - - EIGEN_DEVICE_FUNC const Axis& axis() const { return m_axis; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorConcatenationOp& operator = (const TensorConcatenationOp& other) - { - typedef TensorAssignOp<TensorConcatenationOp, const TensorConcatenationOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorConcatenationOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorConcatenationOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - protected: - typename LhsXprType::Nested m_lhs_xpr; - typename RhsXprType::Nested m_rhs_xpr; - const Axis m_axis; -}; - - -// Eval as rvalue -template<typename Axis, typename LeftArgType, typename RightArgType, typename Device> -struct TensorEvaluator<const TensorConcatenationOp<Axis, LeftArgType, RightArgType>, Device> -{ - typedef TensorConcatenationOp<Axis, LeftArgType, RightArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<LeftArgType, Device>::Dimensions>::value; - static const int RightNumDims = internal::array_size<typename TensorEvaluator<RightArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<LeftArgType, Device>::PacketAccess && - TensorEvaluator<RightArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<LeftArgType, Device>::PreferBlockAccess || - TensorEvaluator<RightArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<LeftArgType, Device>::Layout, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_leftImpl(op.lhsExpression(), device), m_rightImpl(op.rhsExpression(), device), m_axis(op.axis()) - { - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<LeftArgType, Device>::Layout) == static_cast<int>(TensorEvaluator<RightArgType, Device>::Layout) || NumDims == 1), YOU_MADE_A_PROGRAMMING_MISTAKE); - EIGEN_STATIC_ASSERT((NumDims == RightNumDims), YOU_MADE_A_PROGRAMMING_MISTAKE); - EIGEN_STATIC_ASSERT((NumDims > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - - eigen_assert(0 <= m_axis && m_axis < NumDims); - const Dimensions& lhs_dims = m_leftImpl.dimensions(); - const Dimensions& rhs_dims = m_rightImpl.dimensions(); - { - int i = 0; - for (; i < m_axis; ++i) { - eigen_assert(lhs_dims[i] > 0); - eigen_assert(lhs_dims[i] == rhs_dims[i]); - m_dimensions[i] = lhs_dims[i]; - } - eigen_assert(lhs_dims[i] > 0); // Now i == m_axis. - eigen_assert(rhs_dims[i] > 0); - m_dimensions[i] = lhs_dims[i] + rhs_dims[i]; - for (++i; i < NumDims; ++i) { - eigen_assert(lhs_dims[i] > 0); - eigen_assert(lhs_dims[i] == rhs_dims[i]); - m_dimensions[i] = lhs_dims[i]; - } - } - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_leftStrides[0] = 1; - m_rightStrides[0] = 1; - m_outputStrides[0] = 1; - - for (int j = 1; j < NumDims; ++j) { - m_leftStrides[j] = m_leftStrides[j-1] * lhs_dims[j-1]; - m_rightStrides[j] = m_rightStrides[j-1] * rhs_dims[j-1]; - m_outputStrides[j] = m_outputStrides[j-1] * m_dimensions[j-1]; - } - } else { - m_leftStrides[NumDims - 1] = 1; - m_rightStrides[NumDims - 1] = 1; - m_outputStrides[NumDims - 1] = 1; - - for (int j = NumDims - 2; j >= 0; --j) { - m_leftStrides[j] = m_leftStrides[j+1] * lhs_dims[j+1]; - m_rightStrides[j] = m_rightStrides[j+1] * rhs_dims[j+1]; - m_outputStrides[j] = m_outputStrides[j+1] * m_dimensions[j+1]; - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - // TODO(phli): Add short-circuit memcpy evaluation if underlying data are linear? - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) - { - m_leftImpl.evalSubExprsIfNeeded(NULL); - m_rightImpl.evalSubExprsIfNeeded(NULL); - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() - { - m_leftImpl.cleanup(); - m_rightImpl.cleanup(); - } - - // TODO(phli): attempt to speed this up. The integer divisions and modulo are slow. - // See CL/76180724 comments for more ideas. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - // Collect dimension-wise indices (subs). - array<Index, NumDims> subs; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumDims - 1; i > 0; --i) { - subs[i] = index / m_outputStrides[i]; - index -= subs[i] * m_outputStrides[i]; - } - subs[0] = index; - } else { - for (int i = 0; i < NumDims - 1; ++i) { - subs[i] = index / m_outputStrides[i]; - index -= subs[i] * m_outputStrides[i]; - } - subs[NumDims - 1] = index; - } - - const Dimensions& left_dims = m_leftImpl.dimensions(); - if (subs[m_axis] < left_dims[m_axis]) { - Index left_index; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - left_index = subs[0]; - EIGEN_UNROLL_LOOP - for (int i = 1; i < NumDims; ++i) { - left_index += (subs[i] % left_dims[i]) * m_leftStrides[i]; - } - } else { - left_index = subs[NumDims - 1]; - EIGEN_UNROLL_LOOP - for (int i = NumDims - 2; i >= 0; --i) { - left_index += (subs[i] % left_dims[i]) * m_leftStrides[i]; - } - } - return m_leftImpl.coeff(left_index); - } else { - subs[m_axis] -= left_dims[m_axis]; - const Dimensions& right_dims = m_rightImpl.dimensions(); - Index right_index; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - right_index = subs[0]; - EIGEN_UNROLL_LOOP - for (int i = 1; i < NumDims; ++i) { - right_index += (subs[i] % right_dims[i]) * m_rightStrides[i]; - } - } else { - right_index = subs[NumDims - 1]; - EIGEN_UNROLL_LOOP - for (int i = NumDims - 2; i >= 0; --i) { - right_index += (subs[i] % right_dims[i]) * m_rightStrides[i]; - } - } - return m_rightImpl.coeff(right_index); - } - } - - // TODO(phli): Add a real vectorization. - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - const int packetSize = PacketType<CoeffReturnType, Device>::size; - EIGEN_STATIC_ASSERT((packetSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index + packetSize - 1 < dimensions().TotalSize()); - - EIGEN_ALIGN_MAX CoeffReturnType values[packetSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < packetSize; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - const double compute_cost = NumDims * (2 * TensorOpCost::AddCost<Index>() + - 2 * TensorOpCost::MulCost<Index>() + - TensorOpCost::DivCost<Index>() + - TensorOpCost::ModCost<Index>()); - const double lhs_size = m_leftImpl.dimensions().TotalSize(); - const double rhs_size = m_rightImpl.dimensions().TotalSize(); - return (lhs_size / (lhs_size + rhs_size)) * - m_leftImpl.costPerCoeff(vectorized) + - (rhs_size / (lhs_size + rhs_size)) * - m_rightImpl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, compute_cost); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - - #ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_leftImpl.bind(cgh); - m_rightImpl.bind(cgh); - } - #endif - - protected: - Dimensions m_dimensions; - array<Index, NumDims> m_outputStrides; - array<Index, NumDims> m_leftStrides; - array<Index, NumDims> m_rightStrides; - TensorEvaluator<LeftArgType, Device> m_leftImpl; - TensorEvaluator<RightArgType, Device> m_rightImpl; - const Axis m_axis; -}; - -// Eval as lvalue -template<typename Axis, typename LeftArgType, typename RightArgType, typename Device> - struct TensorEvaluator<TensorConcatenationOp<Axis, LeftArgType, RightArgType>, Device> - : public TensorEvaluator<const TensorConcatenationOp<Axis, LeftArgType, RightArgType>, Device> -{ - typedef TensorEvaluator<const TensorConcatenationOp<Axis, LeftArgType, RightArgType>, Device> Base; - typedef TensorConcatenationOp<Axis, LeftArgType, RightArgType> XprType; - typedef typename Base::Dimensions Dimensions; - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<LeftArgType, Device>::PacketAccess && - TensorEvaluator<RightArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<LeftArgType, Device>::PreferBlockAccess || - TensorEvaluator<RightArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<LeftArgType, Device>::Layout, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(XprType& op, const Device& device) - : Base(op, device) - { - EIGEN_STATIC_ASSERT((static_cast<int>(Layout) == static_cast<int>(ColMajor)), YOU_MADE_A_PROGRAMMING_MISTAKE); - } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index) - { - // Collect dimension-wise indices (subs). - array<Index, Base::NumDims> subs; - for (int i = Base::NumDims - 1; i > 0; --i) { - subs[i] = index / this->m_outputStrides[i]; - index -= subs[i] * this->m_outputStrides[i]; - } - subs[0] = index; - - const Dimensions& left_dims = this->m_leftImpl.dimensions(); - if (subs[this->m_axis] < left_dims[this->m_axis]) { - Index left_index = subs[0]; - for (int i = 1; i < Base::NumDims; ++i) { - left_index += (subs[i] % left_dims[i]) * this->m_leftStrides[i]; - } - return this->m_leftImpl.coeffRef(left_index); - } else { - subs[this->m_axis] -= left_dims[this->m_axis]; - const Dimensions& right_dims = this->m_rightImpl.dimensions(); - Index right_index = subs[0]; - for (int i = 1; i < Base::NumDims; ++i) { - right_index += (subs[i] % right_dims[i]) * this->m_rightStrides[i]; - } - return this->m_rightImpl.coeffRef(right_index); - } - } - - template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) - { - const int packetSize = PacketType<CoeffReturnType, Device>::size; - EIGEN_STATIC_ASSERT((packetSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index + packetSize - 1 < this->dimensions().TotalSize()); - - EIGEN_ALIGN_MAX CoeffReturnType values[packetSize]; - internal::pstore<CoeffReturnType, PacketReturnType>(values, x); - for (int i = 0; i < packetSize; ++i) { - coeffRef(index+i) = values[i]; - } - } -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONCATENATION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h deleted file mode 100644 index 605d72c8..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h +++ /dev/null @@ -1,1021 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_H - -namespace Eigen { - -/** \class TensorContraction - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor contraction class. - * - * - */ -namespace internal { - -template<typename Dimensions, typename LhsXprType, typename RhsXprType, typename OutputKernelType> -struct traits<TensorContractionOp<Dimensions, LhsXprType, RhsXprType, OutputKernelType> > -{ - // Type promotion to handle the case where the types of the lhs and the rhs are different. - typedef typename gebp_traits<typename remove_const<typename LhsXprType::Scalar>::type, - typename remove_const<typename RhsXprType::Scalar>::type>::ResScalar Scalar; - - typedef typename promote_storage_type<typename traits<LhsXprType>::StorageKind, - typename traits<RhsXprType>::StorageKind>::ret StorageKind; - typedef typename promote_index_type<typename traits<LhsXprType>::Index, - typename traits<RhsXprType>::Index>::type Index; - typedef typename LhsXprType::Nested LhsNested; - typedef typename RhsXprType::Nested RhsNested; - typedef typename remove_reference<LhsNested>::type _LhsNested; - typedef typename remove_reference<RhsNested>::type _RhsNested; - - // From NumDims below. - static const int NumDimensions = traits<LhsXprType>::NumDimensions + traits<RhsXprType>::NumDimensions - 2 * array_size<Dimensions>::value; - static const int Layout = traits<LhsXprType>::Layout; - typedef typename conditional<Pointer_type_promotion<typename LhsXprType::Scalar, Scalar>::val, - typename traits<LhsXprType>::PointerType, - typename traits<RhsXprType>::PointerType>::type - PointerType; - - enum { - Flags = 0 - }; -}; - -template<typename Dimensions, typename LhsXprType, typename RhsXprType, typename OutputKernelType> -struct eval<TensorContractionOp<Dimensions, LhsXprType, RhsXprType, OutputKernelType>, Eigen::Dense> -{ - typedef const TensorContractionOp<Dimensions, LhsXprType, RhsXprType, OutputKernelType>& type; -}; - -template<typename Dimensions, typename LhsXprType, typename RhsXprType, typename OutputKernelType> -struct nested<TensorContractionOp<Dimensions, LhsXprType, RhsXprType, OutputKernelType>, 1, typename eval<TensorContractionOp<Dimensions, LhsXprType, RhsXprType, OutputKernelType> >::type> -{ - typedef TensorContractionOp<Dimensions, LhsXprType, RhsXprType, OutputKernelType> type; -}; - -template<typename Indices_, typename LeftArgType_, typename RightArgType_, typename OutputKernelType_, typename Device_> -struct traits<TensorEvaluator<const TensorContractionOp<Indices_, LeftArgType_, RightArgType_, OutputKernelType_>, Device_> > { - typedef Indices_ Indices; - typedef LeftArgType_ LeftArgType; - typedef RightArgType_ RightArgType; - typedef OutputKernelType_ OutputKernelType; - typedef Device_ Device; - - // From NumDims below. - static const int NumDimensions = traits<LeftArgType_>::NumDimensions + traits<RightArgType_>::NumDimensions - 2 * array_size<Indices_>::value; -}; - -// Helper class to allocate and deallocate temporary memory for packed buffers. -template <typename LhsScalar, typename RhsScalar> -struct TensorContractionBlockMemAllocator { - typedef void* BlockMemHandle; - - template <typename Device> - EIGEN_DEVICE_FUNC static BlockMemHandle allocate(Device& d, const Index bm, - const Index bk, - const Index bn, - LhsScalar** lhs_block, - RhsScalar** rhs_block) { - eigen_assert(lhs_block); - eigen_assert(rhs_block); - BlockSizes sz = ComputeLhsRhsBlockSizes(bm, bk, bn); - char* block_mem = static_cast<char*>(d.allocate(sz.lhs_size + sz.rhs_size)); - eigen_assert(block_mem); - *lhs_block = reinterpret_cast<LhsScalar*>(block_mem); - *rhs_block = reinterpret_cast<RhsScalar*>(block_mem + sz.lhs_size); - return block_mem; - } - - template <typename Device> - EIGEN_DEVICE_FUNC static BlockMemHandle allocateSlices( - Device& d, const Index bm, const Index bk, const Index bn, - const Index num_lhs, const Index num_rhs, const Index num_slices, - std::vector<LhsScalar*>* lhs_blocks, - std::vector<RhsScalar*>* rhs_blocks) { - eigen_assert(num_slices > 0); - eigen_assert(num_lhs >= 0 && num_rhs >= 0); - eigen_assert(num_lhs == 0 || lhs_blocks); - eigen_assert(num_rhs == 0 || rhs_blocks); - BlockSizes sz = ComputeLhsRhsBlockSizes(bm, bk, bn); - void* block_mem = d.allocate( - (num_lhs * sz.lhs_size + num_rhs * sz.rhs_size) * num_slices); - eigen_assert(block_mem); - char* mem = static_cast<char*>(block_mem); - - for (Index x = 0; x < num_slices; x++) { - if (num_lhs > 0) lhs_blocks[x].resize(num_lhs); - for (Index m = 0; m < num_lhs; m++) { - lhs_blocks[x][m] = reinterpret_cast<LhsScalar*>(mem); - mem += sz.lhs_size; - } - if (num_rhs > 0) rhs_blocks[x].resize(num_rhs); - for (Index n = 0; n < num_rhs; n++) { - rhs_blocks[x][n] = reinterpret_cast<RhsScalar*>(mem); - mem += sz.rhs_size; - } - } - - return block_mem; - } - - template <typename Device> - EIGEN_DEVICE_FUNC static void deallocate(Device& d, BlockMemHandle handle) { - d.deallocate(handle); - } - - private: - struct BlockSizes { - Index lhs_size; - Index rhs_size; - }; - EIGEN_DEVICE_FUNC static BlockSizes ComputeLhsRhsBlockSizes(const Index bm, - const Index bk, - const Index bn) { - Index align = numext::maxi(EIGEN_MAX_ALIGN_BYTES, 1); - BlockSizes sz; - sz.lhs_size = divup<Index>(bm * bk * sizeof(LhsScalar), align) * align; - sz.rhs_size = divup<Index>(bn * bk * sizeof(RhsScalar), align) * align; - return sz; - } -}; - -// WARNING: In this code we assume that Lhs and Rhs tensor expressions are in -// ColMajor storage order. This property is guaranteed by the -// TensorContractionOp evaluator. TensorContractionKernel specifies how we pack -// blocks of Lhs and Rhs tensor expressions, and how we invoke matrix -// multiplication for these blocks. Default tensor contraction uses -// gemm_pack_rhs, gemm_pack_lhs and gebp_kernel from Eigen Core (see -// GeneralBlocPanelKernel.h for details). -// -// By specializing contraction kernels we can use other low level libraries to -// perform matrix multiplication, and still rely on Eigen contraction evaluator. -// This also includes full support in TensorContractionThreadPool, assuming that -// underlying gemm do not use it's own threading. -// -// - ResScalar/LhsScalar/RhsScalar - scalar type for the result of -// multiplication, lhs tensor and rhs tensor respectively. -// -// - StorageIndex - index type for the tensor expressions. In practice almost -// always is Eigen::Index. -// -// - OutputMapper provides access to the memory of the output matrix. In -// practice it's always column major blas_data_mapper (it must be of ResScalar -// type). -// -// - LhsMapper/RhsMapper similarly to blas_data_mapper provide a two dimensional -// view into the Lhs/Rhs tensor expressions. In practice it's -// TensorContractionInputMapper, or some specialization of it based on the -// type of tensor expression (e.g. TensorImagePatchOp has optimized input -// mapper). -template <typename ResScalar, typename LhsScalar, typename RhsScalar, - typename StorageIndex, typename OutputMapper, typename LhsMapper, - typename RhsMapper> -struct TensorContractionKernel { - // True if `invoke()` supports `beta` in `C <- alpha * A * B + beta * C` - // (otherwise beta should be always equal to 1). - enum { HasBeta = false }; - - EIGEN_DEVICE_FUNC - TensorContractionKernel(StorageIndex m_, StorageIndex k_, StorageIndex n_, - StorageIndex bm_, StorageIndex bk_, StorageIndex bn_) - : m(m_), k(k_), n(n_), bm(bm_), bk(bk_), bn(bn_) {} - - // Pack blocks of Lhs and Rhs into contiguous blocks in memory. - typedef LhsScalar* LhsBlock; - typedef RhsScalar* RhsBlock; - - // Packed Lhs/Rhs block memory allocator. - typedef TensorContractionBlockMemAllocator<LhsScalar, RhsScalar> - BlockMemAllocator; - typedef typename BlockMemAllocator::BlockMemHandle BlockMemHandle; - - typedef typename internal::gebp_traits<LhsScalar, RhsScalar> Traits; - - typedef internal::gemm_pack_lhs< - LhsScalar, StorageIndex, typename LhsMapper::SubMapper, Traits::mr, - Traits::LhsProgress, typename Traits::LhsPacket4Packing, ColMajor> - LhsPacker; - - typedef internal::gemm_pack_rhs<RhsScalar, StorageIndex, - typename RhsMapper::SubMapper, Traits::nr, - ColMajor> - RhsPacker; - - typedef internal::gebp_kernel<LhsScalar, RhsScalar, StorageIndex, - OutputMapper, Traits::mr, Traits::nr, - /*ConjugateLhs*/ false, /*ConjugateRhs*/ false> - GebpKernel; - - template <typename Device> - EIGEN_DEVICE_FUNC BlockMemHandle allocate(Device& d, LhsBlock* lhs_block, - RhsBlock* rhs_block) { - return BlockMemAllocator::allocate(d, bm, bk, bn, lhs_block, rhs_block); - } - - template <typename Device> - EIGEN_DEVICE_FUNC BlockMemHandle allocateSlices( - Device& d, const StorageIndex num_lhs, const StorageIndex num_rhs, - const StorageIndex num_slices, std::vector<LhsBlock>* lhs_blocks, - std::vector<RhsBlock>* rhs_blocks) { - return BlockMemAllocator::allocateSlices( - d, bm, bk, bn, num_lhs, num_rhs, num_slices, lhs_blocks, rhs_blocks); - } - - template <typename Device> - EIGEN_DEVICE_FUNC static void deallocate(Device& d, BlockMemHandle handle) { - BlockMemAllocator::deallocate(d, handle); - } - - EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE void packLhs( - LhsBlock* lhsBlock, const typename LhsMapper::SubMapper& data_mapper, - const StorageIndex depth, const StorageIndex rows) { - LhsPacker()(*lhsBlock, data_mapper, depth, rows, /*stride*/ 0, - /*offset*/ 0); - } - - EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE void packRhs( - RhsBlock* rhsBlock, const typename RhsMapper::SubMapper& data_mapper, - const StorageIndex depth, const StorageIndex cols) { - RhsPacker()(*rhsBlock, data_mapper, depth, cols); - } - - EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE void invoke( - const OutputMapper& output_mapper, const LhsBlock& lhsBlock, - const RhsBlock& rhsBlock, const StorageIndex rows, - const StorageIndex depth, const StorageIndex cols, - const ResScalar alpha, const ResScalar beta) { - // Default GEBP kernel does not support beta. - eigen_assert(beta == ResScalar(1)); - static const int kComputeStrideFromBlockDimensions = -1; - GebpKernel()(output_mapper, lhsBlock, rhsBlock, rows, depth, cols, alpha, - /*strideA*/ kComputeStrideFromBlockDimensions, - /*strideB*/ kComputeStrideFromBlockDimensions, - /*offsetA*/ 0, /*offsetB*/ 0); - } - - private: - // These are dimensions of the original Tensors, and selected block sizes. The - // actual block sizes passed to all function above might be smaller because of - // the partial blocks at the end. - const StorageIndex m; - const StorageIndex k; - const StorageIndex n; - const StorageIndex bm; - const StorageIndex bk; - const StorageIndex bn; -}; - -} // end namespace internal - -// Tensor contraction params that should enable to get from output matrix -// 2-dimensional coordinates to the output tensor dimensions. -struct TensorContractionParams { - // TensorContraction evaluator assumes that both tensors are in ColMajor - // layout, if tensors are in RowMajor evaluator swap lhs with rhs. - bool swapped_arguments; -}; - -// Output kernel allows to fuse operations into the tensor contraction. -// -// Examples: -// 1. Elementwise Relu transformation following Conv2D. -// 2. AddBias to the Conv2D output channels dimension. -// -// The NoOpOutputKernel implements an output kernel that does absolutely nothing. -struct NoOpOutputKernel { - /** - * Tensor contraction evaluator calls this kernel after finishing each block - * of output matrix. Output blocks belong to the 2-dimensional output tensor. - * - * TensorContractionParams contains contraction dimensions information - * required to map output 2-d space into the expected output tensor space - * (potentially higher dimensional). - * - * \param[in] output_mapper Access to output tensor memory - * \param[in] params Tensor contraction parameters - * \param[in] i Index of a first row available through output_mapper - * \param[in] j Index of a first column available through output_mapper - * \param[in] num_rows Number of available rows - * \param[in] num_cols Number of available columns - */ - template <typename Index, typename Scalar> - EIGEN_ALWAYS_INLINE void operator()( - const internal::blas_data_mapper<Scalar, Index, ColMajor>& output_mapper, - const TensorContractionParams& params, Index i, - Index j, Index num_rows, Index num_cols) const { - EIGEN_UNUSED_VARIABLE(output_mapper); - EIGEN_UNUSED_VARIABLE(params); - EIGEN_UNUSED_VARIABLE(i); - EIGEN_UNUSED_VARIABLE(j); - EIGEN_UNUSED_VARIABLE(num_rows); - EIGEN_UNUSED_VARIABLE(num_cols); - } -}; - -template<typename Indices, typename LhsXprType, typename RhsXprType, typename OutputKernelType = const NoOpOutputKernel> -class TensorContractionOp : public TensorBase<TensorContractionOp<Indices, LhsXprType, RhsXprType, OutputKernelType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorContractionOp>::Scalar Scalar; - typedef typename internal::gebp_traits<typename LhsXprType::CoeffReturnType, - typename RhsXprType::CoeffReturnType>::ResScalar CoeffReturnType; - typedef typename Eigen::internal::nested<TensorContractionOp>::type Nested; - typedef typename Eigen::internal::traits<TensorContractionOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorContractionOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorContractionOp( - const LhsXprType& lhs, const RhsXprType& rhs, const Indices& dims, - const OutputKernelType& output_kernel = OutputKernelType()) - : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_indices(dims), - m_output_kernel(output_kernel) {} - - EIGEN_DEVICE_FUNC - const Indices& indices() const { return m_indices; } - - /** \returns the nested expressions */ - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename LhsXprType::Nested>::type& - lhsExpression() const { return m_lhs_xpr; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename RhsXprType::Nested>::type& - rhsExpression() const { return m_rhs_xpr; } - - EIGEN_DEVICE_FUNC - const OutputKernelType& outputKernel() const { return m_output_kernel; } - - protected: - typename LhsXprType::Nested m_lhs_xpr; - typename RhsXprType::Nested m_rhs_xpr; - const Indices m_indices; - const OutputKernelType m_output_kernel; -}; - - -template<typename Derived> -struct TensorContractionEvaluatorBase -{ - typedef typename internal::traits<Derived>::Indices Indices; - typedef typename internal::traits<Derived>::LeftArgType LeftArgType; - typedef typename internal::traits<Derived>::RightArgType RightArgType; - typedef typename internal::traits<Derived>::OutputKernelType OutputKernelType; - typedef typename internal::traits<Derived>::Device Device; - - typedef TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType> XprType; - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef typename XprType::Index Index; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef StorageMemory<Scalar, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = true, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<LeftArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = true - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - // Most of the code is assuming that both input tensors are ColMajor. If the - // inputs are RowMajor, we will "cheat" by swapping the LHS and RHS: - // If we want to compute A * B = C, where A is LHS and B is RHS, the code - // will pretend B is LHS and A is RHS. - typedef typename internal::conditional< - static_cast<int>(Layout) == static_cast<int>(ColMajor), LeftArgType, RightArgType>::type EvalLeftArgType; - typedef typename internal::conditional< - static_cast<int>(Layout) == static_cast<int>(ColMajor), RightArgType, LeftArgType>::type EvalRightArgType; - - typedef TensorEvaluator<EvalLeftArgType, Device> LeftEvaluatorType; - typedef TensorEvaluator<EvalRightArgType, Device> RightEvaluatorType; - - static const int LDims = - internal::array_size<typename TensorEvaluator<EvalLeftArgType, Device>::Dimensions>::value; - static const int RDims = - internal::array_size<typename TensorEvaluator<EvalRightArgType, Device>::Dimensions>::value; - static const int ContractDims = internal::array_size<Indices>::value; - static const int NumDims = LDims + RDims - 2 * ContractDims; - - typedef array<Index, ContractDims> contract_t; - typedef array<Index, LDims - ContractDims> left_nocontract_t; - typedef array<Index, RDims - ContractDims> right_nocontract_t; - - typedef DSizes<Index, NumDims> Dimensions; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorContractionEvaluatorBase(const XprType& op, const Device& device) - : m_leftImpl(choose(Cond<static_cast<int>(Layout) == static_cast<int>(ColMajor)>(), - op.lhsExpression(), op.rhsExpression()), device), - m_rightImpl(choose(Cond<static_cast<int>(Layout) == static_cast<int>(ColMajor)>(), - op.rhsExpression(), op.lhsExpression()), device), - m_device(device), - m_output_kernel(op.outputKernel()), - m_result(NULL) { - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<LeftArgType, Device>::Layout) == - static_cast<int>(TensorEvaluator<RightArgType, Device>::Layout)), - YOU_MADE_A_PROGRAMMING_MISTAKE); - - - DSizes<Index, LDims> eval_left_dims; - DSizes<Index, RDims> eval_right_dims; - array<IndexPair<Index>, ContractDims> eval_op_indices; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - // For ColMajor, we keep using the existing dimensions - for (int i = 0; i < LDims; i++) { - eval_left_dims[i] = m_leftImpl.dimensions()[i]; - } - for (int i = 0; i < RDims; i++) { - eval_right_dims[i] = m_rightImpl.dimensions()[i]; - } - // We keep the pairs of contracting indices. - for (int i = 0; i < ContractDims; i++) { - eval_op_indices[i].first = op.indices()[i].first; - eval_op_indices[i].second = op.indices()[i].second; - } - } else { - // For RowMajor, we need to reverse the existing dimensions - for (int i = 0; i < LDims; i++) { - eval_left_dims[i] = m_leftImpl.dimensions()[LDims - i - 1]; - } - for (int i = 0; i < RDims; i++) { - eval_right_dims[i] = m_rightImpl.dimensions()[RDims - i - 1]; - } - // We need to flip all the pairs of contracting indices as well as - // reversing the dimensions. - for (int i = 0; i < ContractDims; i++) { - eval_op_indices[i].first = LDims - 1 - op.indices()[ContractDims - 1 - i].second; - eval_op_indices[i].second = RDims - 1 - op.indices()[ContractDims - 1 - i].first; - } - } - - // Check for duplicate axes and make sure the first index in eval_op_indices - // is increasing. Using O(n^2) sorting is OK since ContractDims is small - for (int i = 0; i < ContractDims; i++) { - for (int j = i + 1; j < ContractDims; j++) { - eigen_assert(eval_op_indices[j].first != eval_op_indices[i].first && - eval_op_indices[j].second != eval_op_indices[i].second && - "contraction axes should be unique"); - if (eval_op_indices[j].first < eval_op_indices[i].first) { - numext::swap(eval_op_indices[j], eval_op_indices[i]); - } - } - } - - array<Index, LDims> lhs_strides; - lhs_strides[0] = 1; - for (int i = 0; i < LDims-1; ++i) { - lhs_strides[i+1] = lhs_strides[i] * eval_left_dims[i]; - } - - array<Index, RDims> rhs_strides; - rhs_strides[0] = 1; - for (int i = 0; i < RDims-1; ++i) { - rhs_strides[i+1] = rhs_strides[i] * eval_right_dims[i]; - } - - if (m_i_strides.size() > 0) m_i_strides[0] = 1; - if (m_j_strides.size() > 0) m_j_strides[0] = 1; - if (m_k_strides.size() > 0) m_k_strides[0] = 1; - - m_i_size = 1; - m_j_size = 1; - m_k_size = 1; - - // To compute the dimension, we simply concatenate the non-contracting - // dimensions of the left and then the right tensor. Additionally, we also - // compute the strides corresponding to the left non-contracting - // dimensions and right non-contracting dimensions. - m_lhs_inner_dim_contiguous = true; - int dim_idx = 0; - Index nocontract_idx = 0; - - for (int i = 0; i < LDims; i++) { - // find if we are contracting on index i of left tensor - bool contracting = false; - for (int j = 0; j < ContractDims; j++) { - if (eval_op_indices[j].first == i) { - contracting = true; - break; - } - } - if (!contracting) { - // add dimension size to output dimensions - m_dimensions[dim_idx] = eval_left_dims[i]; - m_left_nocontract_strides[nocontract_idx] = lhs_strides[i]; - if (dim_idx != i) { - m_lhs_inner_dim_contiguous = false; - } - if (nocontract_idx+1 < internal::array_size<left_nocontract_t>::value) { - m_i_strides[nocontract_idx+1] = - m_i_strides[nocontract_idx] * eval_left_dims[i]; - } else { - m_i_size = m_i_strides[nocontract_idx] * eval_left_dims[i]; - } - dim_idx++; - nocontract_idx++; - } - } - - nocontract_idx = 0; - for (int i = 0; i < RDims; i++) { - bool contracting = false; - // find if we are contracting on index i of right tensor - for (int j = 0; j < ContractDims; j++) { - if (eval_op_indices[j].second == i) { - contracting = true; - break; - } - } - if (!contracting) { - m_dimensions[dim_idx] = eval_right_dims[i]; - if (nocontract_idx+1 < internal::array_size<right_nocontract_t>::value) { - m_j_strides[nocontract_idx+1] = - m_j_strides[nocontract_idx] * eval_right_dims[i]; - } else { - m_j_size = m_j_strides[nocontract_idx] * eval_right_dims[i]; - } - m_right_nocontract_strides[nocontract_idx] = rhs_strides[i]; - dim_idx++; - nocontract_idx++; - } - } - - // Now compute the strides corresponding to the contracting dimensions. We - // assumed above that non-contracting axes are represented in the same order - // in the matrix as they are in the tensor. This is not the case for - // contracting axes. As the contracting axes must be of the same size in - // each tensor, we'll only look at the first tensor here. - m_rhs_inner_dim_contiguous = true; - m_rhs_inner_dim_reordered = false; - for (int i = 0; i < ContractDims; i++) { - Index left = eval_op_indices[i].first; - Index right = eval_op_indices[i].second; - - Index size = eval_left_dims[left]; - eigen_assert(size == eval_right_dims[right] && - "Contraction axes must be same size"); - - if (i+1 < static_cast<int>(internal::array_size<contract_t>::value)) { - m_k_strides[i+1] = m_k_strides[i] * size; - } else { - m_k_size = m_k_strides[i] * size; - } - m_left_contracting_strides[i] = lhs_strides[left]; - m_right_contracting_strides[i] = rhs_strides[right]; - - if (i > 0 && right < eval_op_indices[i-1].second) { - m_rhs_inner_dim_reordered = true; - } - if (right != i) { - m_rhs_inner_dim_contiguous = false; - } - } - - // If the layout is RowMajor, we need to reverse the m_dimensions - if (static_cast<int>(Layout) == static_cast<int>(RowMajor)) { - for (int i = 0, j = NumDims - 1; i < j; i++, j--) { - numext::swap(m_dimensions[i], m_dimensions[j]); - } - } - - // A set of parameters that will allow output kernel to get from output - // tensor dimensions (i, j) into the original tensor dimensions. - // TODO(ezhulenev): Add parameters required to infer output tensor index for - // more complex contractions than 2x2 on internal dimension. - m_tensor_contraction_params.swapped_arguments = static_cast<int>(Layout) == RowMajor; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - m_leftImpl.evalSubExprsIfNeeded(NULL); - m_rightImpl.evalSubExprsIfNeeded(NULL); - if (data) { - evalTo(data); - return false; - } else { - m_result = static_cast<EvaluatorPointerType>(m_device.allocate(dimensions().TotalSize() * sizeof(Scalar))); - evalTo(m_result); - return true; - } - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType dest, EvalSubExprsCallback done) { - m_leftImpl.evalSubExprsIfNeededAsync(nullptr, [this, done, dest](bool) { - m_rightImpl.evalSubExprsIfNeededAsync(nullptr, [this, done, dest](bool) { - if (dest) { - evalToAsync(dest, [done]() { done(false); }); - } else { - m_result = static_cast<EvaluatorPointerType>( - m_device.allocate(dimensions().TotalSize() * sizeof(Scalar))); - evalToAsync(m_result, [done]() { done(true); }); - } - }); - }); - } -#endif // EIGEN_USE_THREADS - -#define TENSOR_CONTRACTION_DISPATCH(METHOD, ALIGNMENT, ARGS) \ - if (this->m_lhs_inner_dim_contiguous) { \ - if (this->m_rhs_inner_dim_contiguous) { \ - if (this->m_rhs_inner_dim_reordered) { \ - METHOD<true, true, true, ALIGNMENT> ARGS; \ - } else { \ - METHOD<true, true, false, ALIGNMENT> ARGS; \ - } \ - } else { \ - if (this->m_rhs_inner_dim_reordered) { \ - METHOD<true, false, true, ALIGNMENT> ARGS; \ - } else { \ - METHOD<true, false, false, ALIGNMENT> ARGS; \ - } \ - } \ - } else { \ - if (this->m_rhs_inner_dim_contiguous) { \ - if (this->m_rhs_inner_dim_reordered) { \ - METHOD<false, true, true, ALIGNMENT> ARGS; \ - } else { \ - METHOD<false, true, false, ALIGNMENT> ARGS; \ - } \ - } else { \ - if (this->m_rhs_inner_dim_reordered) { \ - METHOD<false, false, true, ALIGNMENT> ARGS; \ - } else { \ - METHOD<false, false, false, ALIGNMENT> ARGS; \ - } \ - } \ - } - -#define TENSOR_CONTRACTION_ASYNC_DISPATCH(METHOD, DONE, ALIGNMENT, ARGS, FN) \ - if (this->m_lhs_inner_dim_contiguous) { \ - if (this->m_rhs_inner_dim_contiguous) { \ - if (this->m_rhs_inner_dim_reordered) { \ - (new METHOD<DONE, true, true, true, ALIGNMENT> ARGS)->FN; \ - } else { \ - (new METHOD<DONE, true, true, false, ALIGNMENT> ARGS)->FN; \ - } \ - } else { \ - if (this->m_rhs_inner_dim_reordered) { \ - (new METHOD<DONE, true, false, true, ALIGNMENT> ARGS)->FN; \ - } else { \ - (new METHOD<DONE, true, false, false, ALIGNMENT> ARGS)->FN; \ - } \ - } \ - } else { \ - if (this->m_rhs_inner_dim_contiguous) { \ - if (this->m_rhs_inner_dim_reordered) { \ - (new METHOD<DONE, false, true, true, ALIGNMENT> ARGS)->FN; \ - } else { \ - (new METHOD<DONE, false, true, false, ALIGNMENT> ARGS)->FN; \ - } \ - } else { \ - if (this->m_rhs_inner_dim_reordered) { \ - (new METHOD<DONE, false, false, true, ALIGNMENT> ARGS)->FN; \ - } else { \ - (new METHOD<DONE, false, false, false, ALIGNMENT> ARGS)->FN; \ - } \ - } \ - } - - EIGEN_DEVICE_FUNC void evalTo(Scalar* buffer) const { - static_cast<const Derived*>(this)->template evalProduct<Unaligned>(buffer); - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalToCallback> - void evalToAsync(Scalar* buffer, EvalToCallback done) const { - static_cast<const Derived*>(this) - ->template evalProductAsync<EvalToCallback, Unaligned>(buffer, - std::move(done)); - } -#endif // EIGEN_USE_THREADS - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, - bool rhs_inner_dim_reordered, int Alignment> - void evalProductSequential(Scalar* buffer) const { - if (this->m_j_size == 1) { - this->template evalGemv<lhs_inner_dim_contiguous, - rhs_inner_dim_contiguous, rhs_inner_dim_reordered, - Alignment>(buffer); - } else { - this->template evalGemm<lhs_inner_dim_contiguous, rhs_inner_dim_contiguous, - rhs_inner_dim_reordered, Alignment>(buffer); - } - } - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment> - #if !defined(EIGEN_HIPCC) - EIGEN_DEVICE_FUNC - #endif - void evalGemv(Scalar* buffer) const { - const Index rows = m_i_size; - const Index cols = m_k_size; - - typedef typename internal::remove_const<typename EvalLeftArgType::Scalar>::type LhsScalar; - typedef typename internal::remove_const<typename EvalRightArgType::Scalar>::type RhsScalar; - typedef TensorEvaluator<EvalLeftArgType, Device> LeftEvaluator; - typedef TensorEvaluator<EvalRightArgType, Device> RightEvaluator; - const Index lhs_packet_size = internal::unpacket_traits<typename LeftEvaluator::PacketReturnType>::size; - const Index rhs_packet_size = internal::unpacket_traits<typename RightEvaluator::PacketReturnType>::size; - const int lhs_alignment = LeftEvaluator::IsAligned ? Aligned : Unaligned; - const int rhs_alignment = RightEvaluator::IsAligned ? Aligned : Unaligned; - typedef internal::TensorContractionInputMapper<LhsScalar, Index, internal::Lhs, - LeftEvaluator, left_nocontract_t, - contract_t, lhs_packet_size, - lhs_inner_dim_contiguous, - false, lhs_alignment> LhsMapper; - - typedef internal::TensorContractionInputMapper<RhsScalar, Index, internal::Rhs, - RightEvaluator, right_nocontract_t, - contract_t, rhs_packet_size, - rhs_inner_dim_contiguous, - rhs_inner_dim_reordered, rhs_alignment> RhsMapper; - - LhsMapper lhs(m_leftImpl, m_left_nocontract_strides, m_i_strides, - m_left_contracting_strides, m_k_strides); - RhsMapper rhs(m_rightImpl, m_right_nocontract_strides, m_j_strides, - m_right_contracting_strides, m_k_strides); - - const Scalar alpha(1); - const Index resIncr(1); - - // zero out the result buffer (which must be of size at least rows * sizeof(Scalar) - m_device.memset(buffer, 0, rows * sizeof(Scalar)); - - internal::general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,false,RhsScalar,RhsMapper,false>::run( - rows, cols, lhs, rhs, - buffer, resIncr, alpha); - - typedef internal::blas_data_mapper<Scalar, Index, ColMajor> OutputMapper; - m_output_kernel(OutputMapper(buffer, rows), m_tensor_contraction_params, - static_cast<Index>(0), static_cast<Index>(0), rows, - static_cast<Index>(1)); - } - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment> - #if !defined(EIGEN_HIPCC) - EIGEN_DEVICE_FUNC - #endif - void evalGemm(Scalar* buffer) const { - // columns in left side, rows in right side - const Index k = this->m_k_size; - this->template evalGemmPartial<lhs_inner_dim_contiguous, - rhs_inner_dim_contiguous, - rhs_inner_dim_reordered, - Alignment, true>(buffer, 0, k, 1); - } - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, - bool rhs_inner_dim_reordered, int Alignment> - EIGEN_DEVICE_FUNC void evalGemmPartialWithoutOutputKernel( - Scalar* buffer, Index k_start, Index k_end, int num_threads) const { - evalGemmPartial<lhs_inner_dim_contiguous, rhs_inner_dim_contiguous, - rhs_inner_dim_reordered, Alignment, - /*use_output_kernel*/ false>(buffer, k_start, k_end, - num_threads); - } - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment, bool use_output_kernel> - EIGEN_DEVICE_FUNC void evalGemmPartial(Scalar* buffer, Index k_start, Index k_end, int num_threads) const { - eigen_assert(k_end >= k_start && k_start >= 0 && k_end <= this->m_k_size); - // columns in slice on left side, rows on right side - const Index k_slice = k_end - k_start; - - // rows in left side - const Index m = this->m_i_size; - - // columns in right side - const Index n = this->m_j_size; - - // define data mappers for Lhs and Rhs - typedef typename internal::remove_const<typename EvalLeftArgType::Scalar>::type LhsScalar; - typedef typename internal::remove_const<typename EvalRightArgType::Scalar>::type RhsScalar; - - typedef TensorEvaluator<EvalLeftArgType, Device> LeftEvaluator; - typedef TensorEvaluator<EvalRightArgType, Device> RightEvaluator; - - const Index lhs_packet_size = internal::unpacket_traits<typename LeftEvaluator::PacketReturnType>::size; - const Index rhs_packet_size = internal::unpacket_traits<typename RightEvaluator::PacketReturnType>::size; - - typedef internal::TensorContractionInputMapper<LhsScalar, Index, internal::Lhs, - LeftEvaluator, left_nocontract_t, - contract_t, lhs_packet_size, - lhs_inner_dim_contiguous, - false, Unaligned> LhsMapper; - - typedef internal::TensorContractionInputMapper<RhsScalar, Index, internal::Rhs, - RightEvaluator, right_nocontract_t, - contract_t, rhs_packet_size, - rhs_inner_dim_contiguous, - rhs_inner_dim_reordered, Unaligned> RhsMapper; - - typedef internal::blas_data_mapper<Scalar, Index, ColMajor> OutputMapper; - - typedef internal::TensorContractionKernel< - Scalar, LhsScalar, RhsScalar, Index, OutputMapper, LhsMapper, RhsMapper> - TensorContractionKernel; - - // initialize data mappers - LhsMapper lhs(this->m_leftImpl, this->m_left_nocontract_strides, this->m_i_strides, - this->m_left_contracting_strides, this->m_k_strides); - - RhsMapper rhs(this->m_rightImpl, this->m_right_nocontract_strides, this->m_j_strides, - this->m_right_contracting_strides, this->m_k_strides); - - OutputMapper output(buffer, m); - - // Sizes of the blocks to load in cache. See the Goto paper for details. - internal::TensorContractionBlocking<Scalar, LhsScalar, RhsScalar, - Index, internal::ShardByCol> - blocking(k_slice, m, n, num_threads); - const Index kc = blocking.kc(); - const Index mc = numext::mini(m, blocking.mc()); - const Index nc = numext::mini(n, blocking.nc()); - - typedef typename TensorContractionKernel::LhsBlock LhsBlock; - typedef typename TensorContractionKernel::RhsBlock RhsBlock; - - LhsBlock blockA; - RhsBlock blockB; - - TensorContractionKernel kernel(m, k_slice, n, mc, kc, nc); - - typedef typename TensorContractionKernel::BlockMemHandle BlockMemHandle; - const BlockMemHandle packed_mem = - kernel.allocate(this->m_device, &blockA, &blockB); - - // If a contraction kernel does not support beta, explicitly initialize - // output buffer with zeroes. - if (!TensorContractionKernel::HasBeta) { - this->m_device.memset(buffer, 0, m * n * sizeof(Scalar)); - } - - for(Index i2=0; i2<m; i2+=mc) - { - const Index actual_mc = numext::mini(i2+mc,m)-i2; - for (Index k2 = k_start; k2 < k_end; k2 += kc) { - // make sure we don't overshoot right edge of left matrix, then pack vertical panel - const Index actual_kc = numext::mini(k2 + kc, k_end) - k2; - kernel.packLhs(&blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc); - - // If kernel supports beta, there is no need to initialize output - // buffer with zeroes. - const Scalar alpha = Scalar(1); - const Scalar beta = (TensorContractionKernel::HasBeta && k2 == k_start) - ? Scalar(0) - : Scalar(1); - - // series of horizontal blocks - for (Index j2 = 0; j2 < n; j2 += nc) { - // make sure we don't overshoot right edge of right matrix, then pack block - const Index actual_nc = numext::mini(j2 + nc, n) - j2; - kernel.packRhs(&blockB, rhs.getSubMapper(k2, j2), actual_kc, - actual_nc); - - // call gebp (matrix kernel) - // The parameters here are copied from Eigen's GEMM implementation - const OutputMapper output_mapper = output.getSubMapper(i2, j2); - kernel.invoke(output_mapper, blockA, blockB, actual_mc, actual_kc, - actual_nc, alpha, beta); - - // We are done with this [i2, j2] output block. - if (use_output_kernel && k2 + kc >= k_end) { - m_output_kernel(output_mapper, m_tensor_contraction_params, i2, j2, - actual_mc, actual_nc); - } - } - } - } - - kernel.deallocate(this->m_device, packed_mem); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_leftImpl.cleanup(); - m_rightImpl.cleanup(); - - if (m_result != NULL) { - m_device.deallocate(m_result); - m_result = NULL; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - return m_result[index]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool) const { - return TensorOpCost(sizeof(CoeffReturnType), 0, 0); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const { - return internal::ploadt<PacketReturnType, LoadMode>(m_result + index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data() const { return m_result; } - -protected: - // Prevent assignment - TensorContractionEvaluatorBase& operator = (const TensorContractionEvaluatorBase&); - Dimensions m_dimensions; - - contract_t m_k_strides; - contract_t m_left_contracting_strides; - contract_t m_right_contracting_strides; - - bool m_lhs_inner_dim_contiguous; - bool m_rhs_inner_dim_contiguous; - bool m_rhs_inner_dim_reordered; - - left_nocontract_t m_i_strides; - right_nocontract_t m_j_strides; - left_nocontract_t m_left_nocontract_strides; - right_nocontract_t m_right_nocontract_strides; - - Index m_i_size; - Index m_j_size; - Index m_k_size; - - TensorContractionParams m_tensor_contraction_params; - - TensorEvaluator<EvalLeftArgType, Device> m_leftImpl; - TensorEvaluator<EvalRightArgType, Device> m_rightImpl; - const Device EIGEN_DEVICE_REF m_device; - OutputKernelType m_output_kernel; - EvaluatorPointerType m_result; -}; - - -// evaluator for default device -template<typename Indices, typename LeftArgType, typename RightArgType, typename OutputKernelType, typename Device> -struct TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, Device> : - public TensorContractionEvaluatorBase< - TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, Device> > { - typedef TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, Device> Self; - typedef TensorContractionEvaluatorBase<Self> Base; - - typedef TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType> XprType; - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef typename XprType::Index Index; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - - enum { - Layout = TensorEvaluator<LeftArgType, Device>::Layout - }; - - // Most of the code is assuming that both input tensors are ColMajor. If the - // inputs are RowMajor, we will "cheat" by swapping the LHS and RHS: - // If we want to compute A * B = C, where A is LHS and B is RHS, the code - // will pretend B is LHS and A is RHS. - typedef typename internal::conditional< - static_cast<int>(Layout) == static_cast<int>(ColMajor), LeftArgType, RightArgType>::type EvalLeftArgType; - typedef typename internal::conditional< - static_cast<int>(Layout) == static_cast<int>(ColMajor), RightArgType, LeftArgType>::type EvalRightArgType; - - static const int LDims = - internal::array_size<typename TensorEvaluator<EvalLeftArgType, Device>::Dimensions>::value; - static const int RDims = - internal::array_size<typename TensorEvaluator<EvalRightArgType, Device>::Dimensions>::value; - static const int ContractDims = internal::array_size<Indices>::value; - - typedef array<Index, ContractDims> contract_t; - typedef array<Index, LDims - ContractDims> left_nocontract_t; - typedef array<Index, RDims - ContractDims> right_nocontract_t; - - static const int NumDims = LDims + RDims - 2 * ContractDims; - - // Could we use NumDimensions here? - typedef DSizes<Index, NumDims> Dimensions; - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) : - Base(op, device) { } - - template <int Alignment> - void evalProduct(Scalar* buffer) const { - TENSOR_CONTRACTION_DISPATCH(this->template evalProductSequential, Alignment, (buffer)); - } -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionBlocking.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionBlocking.h deleted file mode 100644 index 974feb0a..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionBlocking.h +++ /dev/null @@ -1,73 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_BLOCKING_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_BLOCKING_H - - -namespace Eigen { -namespace internal { - -enum { - ShardByRow = 0, - ShardByCol = 1 -}; - - -// Default Blocking Strategy -template<typename ResScalar, typename LhsScalar, typename RhsScalar, typename StorageIndex, int ShardingType = ShardByCol> -class TensorContractionBlocking { - public: - - /* - adding EIGEN_DEVICE_FUNC unconditionally to 'TensorContractionBlocking' constructor in `TensorContractionBlocking.h` - requires adding EIGEN_DEVICE_FUNC to `computeProductBlockingSizes` in `GeneralBlockPanelKernel.h` - which in turn, requires adding EIGEN_DEVICE_FUNC to `evaluateProductBlockingSizesHeuristic` in `GeneralBlockPanelKernel.h` - which in turn, requires adding EIGEN_DEVICE_FUNC to `manage_caching_sizes` in `GeneralBlockPanelKernel.h` - (else HIPCC will error out) - - However adding EIGEN_DEVICE_FUNC to `manage_caching_sizes` in `GeneralBlockPanelKernel.h` - results in NVCC erroring out with the following error - - ../Eigen/src/Core/products/GeneralBlockPanelKernel.h(57): error #2901: - dynamic initialization is not supported for function-scope static variables within a __device__/__global__ function - */ - - #if !defined(EIGEN_HIPCC) - EIGEN_DEVICE_FUNC - #endif - TensorContractionBlocking(StorageIndex k, StorageIndex m, StorageIndex n, StorageIndex num_threads = 1) : - kc_(k), mc_(m), nc_(n) - { - if (ShardingType == ShardByCol) { - computeProductBlockingSizes<LhsScalar, RhsScalar, 1>(kc_, mc_, nc_, num_threads); - } - else { - computeProductBlockingSizes<LhsScalar, RhsScalar, 1>(kc_, nc_, mc_, num_threads); - } - - const int rhs_packet_size = internal::packet_traits<RhsScalar>::size; - kc_ = (rhs_packet_size <= 8 || kc_ <= rhs_packet_size) ? - kc_ : (kc_ / rhs_packet_size) * rhs_packet_size; - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE StorageIndex kc() const { return kc_; } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE StorageIndex mc() const { return mc_; } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE StorageIndex nc() const { return nc_; } - - private: - StorageIndex kc_; - StorageIndex mc_; - StorageIndex nc_; -}; - -} // end namespace internal -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_BLOCKING_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionCuda.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionCuda.h deleted file mode 100644 index 3f315fed..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionCuda.h +++ /dev/null @@ -1,6 +0,0 @@ - -#if defined(__clang__) || defined(__GNUC__) -#warning "Deprecated header file, please either include the main Eigen/CXX11/Tensor header or the respective TensorContractionGpu.h file" -#endif - -#include "TensorContractionGpu.h" diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionGpu.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionGpu.h deleted file mode 100644 index bb990b37..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionGpu.h +++ /dev/null @@ -1,1413 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014-2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// Copyright (C) 2015 Navdeep Jaitly <ndjaitly@google.com> -// Copyright (C) 2014 Eric Martin <eric@ericmart.in> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_GPU_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_GPU_H - -#if defined(EIGEN_USE_GPU) && defined(EIGEN_GPUCC) - -namespace Eigen { - -template<typename Scalar, typename Index, typename LhsMapper, - typename RhsMapper, typename OutputMapper, bool needs_edge_check> -__device__ EIGEN_STRONG_INLINE void -EigenContractionKernelInternal(const LhsMapper lhs, const RhsMapper rhs, - const OutputMapper output, Scalar* lhs_shmem, Scalar* rhs_shmem, - const Index m_size, const Index n_size, const Index k_size) { - - const Index m_block_idx = blockIdx.x; - const Index n_block_idx = blockIdx.y; - - const Index base_m = 64 * m_block_idx; - const Index base_n = 64 * n_block_idx; - - // declare and initialize 64 registers for output 8x8 block - - // prefetch registers - Scalar lhs_pf0; - Scalar lhs_pf1; - Scalar lhs_pf2; - Scalar lhs_pf3; - Scalar lhs_pf4; - Scalar lhs_pf5; - Scalar lhs_pf6; - Scalar lhs_pf7; - - Scalar rhs_pf0; - Scalar rhs_pf1; - Scalar rhs_pf2; - Scalar rhs_pf3; - Scalar rhs_pf4; - Scalar rhs_pf5; - Scalar rhs_pf6; - Scalar rhs_pf7; - - // shared memory is formatted - // (contract idx in block, nocontract idx in block, block idx) - // where block idx is column major. This transposition limits the number of - // bank conflicts when reading the LHS. The core idea is that since the contracting - // index is shared by both sides, then the contracting index should be in threadIdx.x. - - // On the LHS, we pad each row inside of each block with an extra element. This makes - // each block 8 rows of 9 elements, which is 72 elements. This gives no bank conflicts - // on writes and very few 2-way conflicts on reads. There is an 8x8 grid of these blocks. - - // On the RHS we just add 8 padding elements to the end of each block. This gives no bank - // conflicts on writes and also none on reads. - - // storage indices - const Index lhs_store_idx_base = threadIdx.y * 72 + threadIdx.x * 9 + threadIdx.z; - const Index rhs_store_idx_base = threadIdx.y * 72 + threadIdx.z * 8 + threadIdx.x; - - const Index lhs_store_idx_0 = lhs_store_idx_base + 576 * 0; - const Index lhs_store_idx_1 = lhs_store_idx_base + 576 * 1; - const Index lhs_store_idx_2 = lhs_store_idx_base + 576 * 2; - const Index lhs_store_idx_3 = lhs_store_idx_base + 576 * 3; - const Index lhs_store_idx_4 = lhs_store_idx_base + 576 * 4; - const Index lhs_store_idx_5 = lhs_store_idx_base + 576 * 5; - const Index lhs_store_idx_6 = lhs_store_idx_base + 576 * 6; - const Index lhs_store_idx_7 = lhs_store_idx_base + 576 * 7; - - const Index rhs_store_idx_0 = rhs_store_idx_base + 576 * 0; - const Index rhs_store_idx_1 = rhs_store_idx_base + 576 * 1; - const Index rhs_store_idx_2 = rhs_store_idx_base + 576 * 2; - const Index rhs_store_idx_3 = rhs_store_idx_base + 576 * 3; - const Index rhs_store_idx_4 = rhs_store_idx_base + 576 * 4; - const Index rhs_store_idx_5 = rhs_store_idx_base + 576 * 5; - const Index rhs_store_idx_6 = rhs_store_idx_base + 576 * 6; - const Index rhs_store_idx_7 = rhs_store_idx_base + 576 * 7; - - // in the loading code, the following variables are important: - // threadIdx.x: the vertical position in an 8x8 block - // threadIdx.y: the vertical index of the 8x8 block in the grid - // threadIdx.z: the horizontal position in an 8x8 block - // k: the horizontal index of the 8x8 block in the grid - // - // The k parameter is implicit (it was the loop counter for a loop that went - // from 0 to <8, but now that loop is unrolled in the below code. - - const Index load_idx_vert = threadIdx.x + 8 * threadIdx.y; - const Index lhs_vert = base_m + load_idx_vert; - -#define prefetchIntoRegisters(base_k) \ - { \ - lhs_pf0 = conv(0); \ - lhs_pf1 = conv(0); \ - lhs_pf2 = conv(0); \ - lhs_pf3 = conv(0); \ - lhs_pf4 = conv(0); \ - lhs_pf5 = conv(0); \ - lhs_pf6 = conv(0); \ - lhs_pf7 = conv(0); \ - \ - rhs_pf0 = conv(0); \ - rhs_pf1 = conv(0); \ - rhs_pf2 = conv(0); \ - rhs_pf3 = conv(0); \ - rhs_pf4 = conv(0); \ - rhs_pf5 = conv(0); \ - rhs_pf6 = conv(0); \ - rhs_pf7 = conv(0); \ - \ - if (!needs_edge_check || lhs_vert < m_size) { \ - const Index lhs_horiz_0 = base_k + threadIdx.z + 0 * 8; \ - const Index lhs_horiz_1 = base_k + threadIdx.z + 1 * 8; \ - const Index lhs_horiz_2 = base_k + threadIdx.z + 2 * 8; \ - const Index lhs_horiz_3 = base_k + threadIdx.z + 3 * 8; \ - const Index lhs_horiz_4 = base_k + threadIdx.z + 4 * 8; \ - const Index lhs_horiz_5 = base_k + threadIdx.z + 5 * 8; \ - const Index lhs_horiz_6 = base_k + threadIdx.z + 6 * 8; \ - const Index lhs_horiz_7 = base_k + threadIdx.z + 7 * 8; \ - \ - if (!needs_edge_check || lhs_horiz_7 < k_size) { \ - lhs_pf0 = lhs(lhs_vert, lhs_horiz_0); \ - lhs_pf1 = lhs(lhs_vert, lhs_horiz_1); \ - lhs_pf2 = lhs(lhs_vert, lhs_horiz_2); \ - lhs_pf3 = lhs(lhs_vert, lhs_horiz_3); \ - lhs_pf4 = lhs(lhs_vert, lhs_horiz_4); \ - lhs_pf5 = lhs(lhs_vert, lhs_horiz_5); \ - lhs_pf6 = lhs(lhs_vert, lhs_horiz_6); \ - lhs_pf7 = lhs(lhs_vert, lhs_horiz_7); \ - } else if (lhs_horiz_6 < k_size) { \ - lhs_pf0 = lhs(lhs_vert, lhs_horiz_0); \ - lhs_pf1 = lhs(lhs_vert, lhs_horiz_1); \ - lhs_pf2 = lhs(lhs_vert, lhs_horiz_2); \ - lhs_pf3 = lhs(lhs_vert, lhs_horiz_3); \ - lhs_pf4 = lhs(lhs_vert, lhs_horiz_4); \ - lhs_pf5 = lhs(lhs_vert, lhs_horiz_5); \ - lhs_pf6 = lhs(lhs_vert, lhs_horiz_6); \ - } else if (lhs_horiz_5 < k_size) { \ - lhs_pf0 = lhs(lhs_vert, lhs_horiz_0); \ - lhs_pf1 = lhs(lhs_vert, lhs_horiz_1); \ - lhs_pf2 = lhs(lhs_vert, lhs_horiz_2); \ - lhs_pf3 = lhs(lhs_vert, lhs_horiz_3); \ - lhs_pf4 = lhs(lhs_vert, lhs_horiz_4); \ - lhs_pf5 = lhs(lhs_vert, lhs_horiz_5); \ - } else if (lhs_horiz_4 < k_size) { \ - lhs_pf0 = lhs(lhs_vert, lhs_horiz_0); \ - lhs_pf1 = lhs(lhs_vert, lhs_horiz_1); \ - lhs_pf2 = lhs(lhs_vert, lhs_horiz_2); \ - lhs_pf3 = lhs(lhs_vert, lhs_horiz_3); \ - lhs_pf4 = lhs(lhs_vert, lhs_horiz_4); \ - } else if (lhs_horiz_3 < k_size) { \ - lhs_pf0 = lhs(lhs_vert, lhs_horiz_0); \ - lhs_pf1 = lhs(lhs_vert, lhs_horiz_1); \ - lhs_pf2 = lhs(lhs_vert, lhs_horiz_2); \ - lhs_pf3 = lhs(lhs_vert, lhs_horiz_3); \ - } else if (lhs_horiz_2 < k_size) { \ - lhs_pf0 = lhs(lhs_vert, lhs_horiz_0); \ - lhs_pf1 = lhs(lhs_vert, lhs_horiz_1); \ - lhs_pf2 = lhs(lhs_vert, lhs_horiz_2); \ - } else if (lhs_horiz_1 < k_size) { \ - lhs_pf0 = lhs(lhs_vert, lhs_horiz_0); \ - lhs_pf1 = lhs(lhs_vert, lhs_horiz_1); \ - } else if (lhs_horiz_0 < k_size) { \ - lhs_pf0 = lhs(lhs_vert, lhs_horiz_0); \ - } \ - } \ - \ - const Index rhs_vert = base_k + load_idx_vert; \ - if (!needs_edge_check || rhs_vert < k_size) { \ - const Index rhs_horiz_0 = base_n + threadIdx.z + 0 * 8; \ - const Index rhs_horiz_1 = base_n + threadIdx.z + 1 * 8; \ - const Index rhs_horiz_2 = base_n + threadIdx.z + 2 * 8; \ - const Index rhs_horiz_3 = base_n + threadIdx.z + 3 * 8; \ - const Index rhs_horiz_4 = base_n + threadIdx.z + 4 * 8; \ - const Index rhs_horiz_5 = base_n + threadIdx.z + 5 * 8; \ - const Index rhs_horiz_6 = base_n + threadIdx.z + 6 * 8; \ - const Index rhs_horiz_7 = base_n + threadIdx.z + 7 * 8; \ - \ - if (rhs_horiz_7 < n_size) { \ - rhs_pf0 = rhs(rhs_vert, rhs_horiz_0); \ - rhs_pf1 = rhs(rhs_vert, rhs_horiz_1); \ - rhs_pf2 = rhs(rhs_vert, rhs_horiz_2); \ - rhs_pf3 = rhs(rhs_vert, rhs_horiz_3); \ - rhs_pf4 = rhs(rhs_vert, rhs_horiz_4); \ - rhs_pf5 = rhs(rhs_vert, rhs_horiz_5); \ - rhs_pf6 = rhs(rhs_vert, rhs_horiz_6); \ - rhs_pf7 = rhs(rhs_vert, rhs_horiz_7); \ - } else if (rhs_horiz_6 < n_size) { \ - rhs_pf0 = rhs(rhs_vert, rhs_horiz_0); \ - rhs_pf1 = rhs(rhs_vert, rhs_horiz_1); \ - rhs_pf2 = rhs(rhs_vert, rhs_horiz_2); \ - rhs_pf3 = rhs(rhs_vert, rhs_horiz_3); \ - rhs_pf4 = rhs(rhs_vert, rhs_horiz_4); \ - rhs_pf5 = rhs(rhs_vert, rhs_horiz_5); \ - rhs_pf6 = rhs(rhs_vert, rhs_horiz_6); \ - } else if (rhs_horiz_5 < n_size) { \ - rhs_pf0 = rhs(rhs_vert, rhs_horiz_0); \ - rhs_pf1 = rhs(rhs_vert, rhs_horiz_1); \ - rhs_pf2 = rhs(rhs_vert, rhs_horiz_2); \ - rhs_pf3 = rhs(rhs_vert, rhs_horiz_3); \ - rhs_pf4 = rhs(rhs_vert, rhs_horiz_4); \ - rhs_pf5 = rhs(rhs_vert, rhs_horiz_5); \ - } else if (rhs_horiz_4 < n_size) { \ - rhs_pf0 = rhs(rhs_vert, rhs_horiz_0); \ - rhs_pf1 = rhs(rhs_vert, rhs_horiz_1); \ - rhs_pf2 = rhs(rhs_vert, rhs_horiz_2); \ - rhs_pf3 = rhs(rhs_vert, rhs_horiz_3); \ - rhs_pf4 = rhs(rhs_vert, rhs_horiz_4); \ - } else if (rhs_horiz_3 < n_size) { \ - rhs_pf0 = rhs(rhs_vert, rhs_horiz_0); \ - rhs_pf1 = rhs(rhs_vert, rhs_horiz_1); \ - rhs_pf2 = rhs(rhs_vert, rhs_horiz_2); \ - rhs_pf3 = rhs(rhs_vert, rhs_horiz_3); \ - } else if (rhs_horiz_2 < n_size) { \ - rhs_pf0 = rhs(rhs_vert, rhs_horiz_0); \ - rhs_pf1 = rhs(rhs_vert, rhs_horiz_1); \ - rhs_pf2 = rhs(rhs_vert, rhs_horiz_2); \ - } else if (rhs_horiz_1 < n_size) { \ - rhs_pf0 = rhs(rhs_vert, rhs_horiz_0); \ - rhs_pf1 = rhs(rhs_vert, rhs_horiz_1); \ - } else if (rhs_horiz_0 < n_size) { \ - rhs_pf0 = rhs(rhs_vert, rhs_horiz_0); \ - } \ - } \ - } \ - -#define writeRegToShmem(_) \ - lhs_shmem[lhs_store_idx_0] = lhs_pf0; \ - rhs_shmem[rhs_store_idx_0] = rhs_pf0; \ - \ - lhs_shmem[lhs_store_idx_1] = lhs_pf1; \ - rhs_shmem[rhs_store_idx_1] = rhs_pf1; \ - \ - lhs_shmem[lhs_store_idx_2] = lhs_pf2; \ - rhs_shmem[rhs_store_idx_2] = rhs_pf2; \ - \ - lhs_shmem[lhs_store_idx_3] = lhs_pf3; \ - rhs_shmem[rhs_store_idx_3] = rhs_pf3; \ - \ - lhs_shmem[lhs_store_idx_4] = lhs_pf4; \ - rhs_shmem[rhs_store_idx_4] = rhs_pf4; \ - \ - lhs_shmem[lhs_store_idx_5] = lhs_pf5; \ - rhs_shmem[rhs_store_idx_5] = rhs_pf5; \ - \ - lhs_shmem[lhs_store_idx_6] = lhs_pf6; \ - rhs_shmem[rhs_store_idx_6] = rhs_pf6; \ - \ - lhs_shmem[lhs_store_idx_7] = lhs_pf7; \ - rhs_shmem[rhs_store_idx_7] = rhs_pf7; \ - - // declare and initialize result array -#define res(i, j) _res_##i##j -#define initResultRow(i) \ - Scalar res(i, 0) = conv(0); \ - Scalar res(i, 1) = conv(0); \ - Scalar res(i, 2) = conv(0); \ - Scalar res(i, 3) = conv(0); \ - Scalar res(i, 4) = conv(0); \ - Scalar res(i, 5) = conv(0); \ - Scalar res(i, 6) = conv(0); \ - Scalar res(i, 7) = conv(0); \ - - internal::scalar_cast_op<int, Scalar> conv; - initResultRow(0); - initResultRow(1); - initResultRow(2); - initResultRow(3); - initResultRow(4); - initResultRow(5); - initResultRow(6); - initResultRow(7); -#undef initResultRow - - for (Index base_k = 0; base_k < k_size; base_k += 64) { - // wait for previous iteration to finish with shmem. Despite common sense, - // the code is a bit faster with this here then at bottom of loop - __syncthreads(); - - prefetchIntoRegisters(base_k); - writeRegToShmem(); - - #undef prefetchIntoRegisters - #undef writeRegToShmem - - // wait for shared mem packing to be done before starting computation - __syncthreads(); - - // compute 8x8 matrix product by outer product. This involves packing one column - // of LHS and one row of RHS into registers (takes 16 registers). - -#define lcol(i) _lcol##i - Scalar lcol(0); - Scalar lcol(1); - Scalar lcol(2); - Scalar lcol(3); - Scalar lcol(4); - Scalar lcol(5); - Scalar lcol(6); - Scalar lcol(7); - -#define rrow(j) _rrow##j - Scalar rrow(0); - Scalar rrow(1); - Scalar rrow(2); - Scalar rrow(3); - Scalar rrow(4); - Scalar rrow(5); - Scalar rrow(6); - Scalar rrow(7); - - // Now x corresponds to k, y to m, and z to n - const Scalar* lhs_block = &lhs_shmem[threadIdx.x + 9 * threadIdx.y]; - const Scalar* rhs_block = &rhs_shmem[threadIdx.x + 8 * threadIdx.z]; - -#define lhs_element(i, j) lhs_block[72 * ((i) + 8 * (j))] -#define rhs_element(i, j) rhs_block[72 * ((i) + 8 * (j))] - -#define loadData(i, j) \ - lcol(0) = lhs_element(0, j); \ - rrow(0) = rhs_element(i, 0); \ - lcol(1) = lhs_element(1, j); \ - rrow(1) = rhs_element(i, 1); \ - lcol(2) = lhs_element(2, j); \ - rrow(2) = rhs_element(i, 2); \ - lcol(3) = lhs_element(3, j); \ - rrow(3) = rhs_element(i, 3); \ - lcol(4) = lhs_element(4, j); \ - rrow(4) = rhs_element(i, 4); \ - lcol(5) = lhs_element(5, j); \ - rrow(5) = rhs_element(i, 5); \ - lcol(6) = lhs_element(6, j); \ - rrow(6) = rhs_element(i, 6); \ - lcol(7) = lhs_element(7, j); \ - rrow(7) = rhs_element(i, 7); \ - -#define computeCol(j) \ - res(0, j) += lcol(0) * rrow(j); \ - res(1, j) += lcol(1) * rrow(j); \ - res(2, j) += lcol(2) * rrow(j); \ - res(3, j) += lcol(3) * rrow(j); \ - res(4, j) += lcol(4) * rrow(j); \ - res(5, j) += lcol(5) * rrow(j); \ - res(6, j) += lcol(6) * rrow(j); \ - res(7, j) += lcol(7) * rrow(j); \ - -#define computePass(i) \ - loadData(i, i); \ - \ - computeCol(0); \ - computeCol(1); \ - computeCol(2); \ - computeCol(3); \ - computeCol(4); \ - computeCol(5); \ - computeCol(6); \ - computeCol(7); \ - - computePass(0); - computePass(1); - computePass(2); - computePass(3); - computePass(4); - computePass(5); - computePass(6); - computePass(7); - -#undef lcol -#undef rrow -#undef lhs_element -#undef rhs_element -#undef loadData -#undef computeCol -#undef computePass - } // end loop over k - - // we've now iterated over all of the large (ie width 64) k blocks and - // accumulated results in registers. At this point thread (x, y, z) contains - // the sum across all big k blocks of the product of little k block of index (x, y) - // with block of index (y, z). To compute the final output, we need to reduce - // the 8 threads over y by summation. -#if defined(EIGEN_HIPCC) || (defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000) -#define shuffleInc(i, j, mask) res(i, j) += __shfl_xor(res(i, j), mask) -#else -#define shuffleInc(i, j, mask) res(i, j) += __shfl_xor_sync(0xFFFFFFFF, res(i, j), mask) -#endif - -#define reduceRow(i, mask) \ - shuffleInc(i, 0, mask); \ - shuffleInc(i, 1, mask); \ - shuffleInc(i, 2, mask); \ - shuffleInc(i, 3, mask); \ - shuffleInc(i, 4, mask); \ - shuffleInc(i, 5, mask); \ - shuffleInc(i, 6, mask); \ - shuffleInc(i, 7, mask); \ - -#define reduceMatrix(mask) \ - reduceRow(0, mask); \ - reduceRow(1, mask); \ - reduceRow(2, mask); \ - reduceRow(3, mask); \ - reduceRow(4, mask); \ - reduceRow(5, mask); \ - reduceRow(6, mask); \ - reduceRow(7, mask); \ - - // actually perform the reduction, now each thread of index (_, y, z) - // contains the correct values in its registers that belong in the output - // block - reduceMatrix(1); - reduceMatrix(2); - reduceMatrix(4); - -#undef shuffleInc -#undef reduceRow -#undef reduceMatrix - - // now we need to copy the 64 values into main memory. We can't split work - // among threads because all variables are in registers. There's 2 ways - // to do this: - // (1) have 1 thread do 64 writes from registers into global memory - // (2) have 1 thread do 64 writes into shared memory, and then 8 threads - // each do 8 writes into global memory. We can just overwrite the shared - // memory from the problem we just solved. - // (2) is slightly faster than (1) due to less branching and more ILP - - // TODO: won't yield much gain, but could just use currently unused shared mem - // and then we won't have to sync - // wait for shared mem to be out of use - __syncthreads(); - -#define writeResultShmem(i, j) \ - lhs_shmem[i + 8 * threadIdx.y + 64 * threadIdx.z + 512 * j] = res(i, j); \ - -#define writeRow(i) \ - writeResultShmem(i, 0); \ - writeResultShmem(i, 1); \ - writeResultShmem(i, 2); \ - writeResultShmem(i, 3); \ - writeResultShmem(i, 4); \ - writeResultShmem(i, 5); \ - writeResultShmem(i, 6); \ - writeResultShmem(i, 7); \ - - if (threadIdx.x == 0) { - writeRow(0); - writeRow(1); - writeRow(2); - writeRow(3); - writeRow(4); - writeRow(5); - writeRow(6); - writeRow(7); - } -#undef writeResultShmem -#undef writeRow - - const int max_i_write = numext::mini((int)((m_size - base_m - threadIdx.y + 7) / 8), 8); - const int max_j_write = numext::mini((int)((n_size - base_n - threadIdx.z + 7) / 8), 8); - - if (threadIdx.x < max_i_write) { - if (max_j_write == 8) { - // TODO: can i trade bank conflicts for coalesced writes? - Scalar val0 = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * 0]; - Scalar val1 = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * 1]; - Scalar val2 = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * 2]; - Scalar val3 = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * 3]; - Scalar val4 = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * 4]; - Scalar val5 = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * 5]; - Scalar val6 = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * 6]; - Scalar val7 = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * 7]; - - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * 0) = val0; - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * 1) = val1; - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * 2) = val2; - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * 3) = val3; - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * 4) = val4; - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * 5) = val5; - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * 6) = val6; - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * 7) = val7; - } else { -#pragma unroll 7 - for (int j = 0; j < max_j_write; j++) { - Scalar val = lhs_shmem[threadIdx.x + 8 * threadIdx.y + 64 * threadIdx.z + 512 * j]; - output(base_m + threadIdx.y + 8 * threadIdx.x, base_n + threadIdx.z + 8 * j) = val; - } - } - } -#undef res -} - - -template<typename Scalar, typename Index, typename LhsMapper, - typename RhsMapper, typename OutputMapper> -__global__ void -#if defined(EIGEN_HIPCC) -__launch_bounds__(512, 1) -#else -__launch_bounds__(512) -#endif -EigenContractionKernel(const LhsMapper lhs, const RhsMapper rhs, - const OutputMapper output, - const Index m_size, const Index n_size, const Index k_size) { - __shared__ Scalar lhs_shmem[72 * 64]; - __shared__ Scalar rhs_shmem[72 * 64]; - - const Index m_block_idx = blockIdx.x; - const Index n_block_idx = blockIdx.y; - - const Index base_m = 64 * m_block_idx; - const Index base_n = 64 * n_block_idx; - - if (base_m + 63 < m_size && base_n + 63 < n_size) { - EigenContractionKernelInternal<Scalar, Index, LhsMapper, RhsMapper, OutputMapper, false>(lhs, rhs, output, lhs_shmem, rhs_shmem, m_size, n_size, k_size); - } else { - EigenContractionKernelInternal<Scalar, Index, LhsMapper, RhsMapper, OutputMapper, true>(lhs, rhs, output, lhs_shmem, rhs_shmem, m_size, n_size, k_size); - } -} - - -template<typename Index, typename LhsMapper, - typename RhsMapper, typename OutputMapper, bool CHECK_LHS_BOUNDARY, - bool CHECK_RHS_BOUNDARY> -__device__ __forceinline__ void -EigenFloatContractionKernelInternal16x16(const LhsMapper lhs, const RhsMapper rhs, - const OutputMapper output, float2 lhs_shmem2[][16], - float2 rhs_shmem2[][8], const Index m_size, - const Index n_size, const Index k_size, - const Index base_m, const Index base_n) { - - // prefetch registers - float4 lhs_pf0, rhs_pf0; - - float4 results[4]; - for (int i=0; i < 4; i++) { - results[i].x = results[i].y = results[i].z = results[i].w = 0; - } - -#define prefetch_lhs(reg, row, col) \ - if (!CHECK_LHS_BOUNDARY) { \ - if (col < k_size) { \ - reg =lhs.template loadPacket<float4,Unaligned>(row, col); \ - } \ - } else { \ - if (col < k_size) { \ - if (row + 3 < m_size) { \ - reg =lhs.template loadPacket<float4,Unaligned>(row, col); \ - } else if (row + 2 < m_size) { \ - reg.x =lhs(row + 0, col); \ - reg.y =lhs(row + 1, col); \ - reg.z =lhs(row + 2, col); \ - } else if (row + 1 < m_size) { \ - reg.x =lhs(row + 0, col); \ - reg.y =lhs(row + 1, col); \ - } else if (row < m_size) { \ - reg.x =lhs(row + 0, col); \ - } \ - } \ - } \ - - Index lhs_vert = base_m+threadIdx.x*4; - - for (Index k = 0; k < k_size; k += 16) { - - lhs_pf0 = internal::pset1<float4>(0); - rhs_pf0 = internal::pset1<float4>(0); - - Index lhs_horiz = threadIdx.y+k; - prefetch_lhs(lhs_pf0, lhs_vert, lhs_horiz) - - Index rhs_vert = k+(threadIdx.x%4)*4; - Index rhs_horiz0 = (threadIdx.x>>2)+threadIdx.y*4+base_n; - - if (!CHECK_RHS_BOUNDARY) { - if ((rhs_vert + 3) < k_size) { - // just CHECK_RHS_BOUNDARY - rhs_pf0 = rhs.template loadPacket<float4,Unaligned>(rhs_vert, rhs_horiz0); - } else if (rhs_vert + 2 < k_size) { - // just CHECK_RHS_BOUNDARY - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - rhs_pf0.z = rhs(rhs_vert + 2, rhs_horiz0); - } else if (rhs_vert + 1 < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - } else if (rhs_vert < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - } - } else { - if (rhs_horiz0 < n_size) { - if ((rhs_vert + 3) < k_size) { - rhs_pf0 = rhs.template loadPacket<float4,Unaligned>(rhs_vert, rhs_horiz0); - } else if ((rhs_vert + 2) < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - rhs_pf0.z = rhs(rhs_vert + 2, rhs_horiz0); - } else if ((rhs_vert + 1) < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - } else if (rhs_vert < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - } - } - } - float x1, x2 ; - // the following can be a bitwise operation..... some day. - if((threadIdx.x%8) < 4) { - x1 = rhs_pf0.y; - x2 = rhs_pf0.w; - } else { - x1 = rhs_pf0.x; - x2 = rhs_pf0.z; - } - #if defined(EIGEN_HIPCC) || (defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000) - x1 = __shfl_xor(x1, 4); - x2 = __shfl_xor(x2, 4); - #else - x1 = __shfl_xor_sync(0xFFFFFFFF, x1, 4); - x2 = __shfl_xor_sync(0xFFFFFFFF, x2, 4); - #endif - if((threadIdx.x%8) < 4) { - rhs_pf0.y = x1; - rhs_pf0.w = x2; - } else { - rhs_pf0.x = x1; - rhs_pf0.z = x2; - } - - // We have 64 features. - // Row 0 -> times (0, 4, 8, 12, 1, 5, 9, 13) for features 0, 1. - // Row 1 -> times (0, 4, 8, 12, 1, 5, 9, 13) for features 2, 3. - // ... - // Row 31 -> times (0, 4, 8, 12, 1, 5, 9, 13) for features 62, 63 - // Row 32 -> times (2, 6, 10, 14, 3, 7, 11, 15) for features 0, 1 - // ... - rhs_shmem2[(threadIdx.x>>3)+ threadIdx.y*2][threadIdx.x%8] = make_float2(rhs_pf0.x, rhs_pf0.y); - rhs_shmem2[(threadIdx.x>>3)+ threadIdx.y*2+32][threadIdx.x%8] = make_float2(rhs_pf0.z, rhs_pf0.w); - - // Row 0 (time 0) -> features (0, 1), (4, 5), .. (28, 29), (32, 33), .. (60, 61) - // Row 1 (time 1) -> features (0, 1), (4, 5), .. (28, 29), (32, 33), .. (60, 61) - // ... - // Row 15 (time 15) -> features (0, 1), (4, 5), .. (28, 29), (32, 33), .. (60, 61) - // Row 16 (time 0) -> features (2, 3), (6, 7), .. (30, 31), (34, 35), .. (62, 63) - // ... - - lhs_shmem2[threadIdx.y][threadIdx.x] = make_float2(lhs_pf0.x, lhs_pf0.y); - lhs_shmem2[threadIdx.y+16][threadIdx.x] = make_float2(lhs_pf0.z, lhs_pf0.w); - - -#define add_vals(fl1, fl2, fr1, fr2)\ - results[0].x += fl1.x * fr1.x;\ - results[0].y += fl1.y * fr1.x;\ - results[0].z += fl2.x * fr1.x;\ - results[0].w += fl2.y * fr1.x;\ -\ - results[1].x += fl1.x * fr1.y;\ - results[1].y += fl1.y * fr1.y;\ - results[1].z += fl2.x * fr1.y;\ - results[1].w += fl2.y * fr1.y;\ -\ - results[2].x += fl1.x * fr2.x;\ - results[2].y += fl1.y * fr2.x;\ - results[2].z += fl2.x * fr2.x;\ - results[2].w += fl2.y * fr2.x;\ -\ - results[3].x += fl1.x * fr2.y;\ - results[3].y += fl1.y * fr2.y;\ - results[3].z += fl2.x * fr2.y;\ - results[3].w += fl2.y * fr2.y;\ - - __syncthreads(); - - // Do the multiplies. - #pragma unroll - for (int koff = 0; koff < 16; koff ++) { - // 32 x threads. - float2 fl1 = lhs_shmem2[koff][threadIdx.x]; - float2 fl2 = lhs_shmem2[koff + 16][threadIdx.x]; - - int start_feature = threadIdx.y * 4; - float2 fr1 = rhs_shmem2[(start_feature>>1) + 32*((koff%4)/2)][koff/4 + (koff%2)*4]; - float2 fr2 = rhs_shmem2[(start_feature>>1) + 1 + 32*((koff%4)/2)][koff/4 + (koff%2)*4]; - - add_vals(fl1, fl2, fr1, fr2) - } - __syncthreads(); - } - -#undef prefetch_lhs -#undef add_vals - - Index horiz_base = threadIdx.y*4+base_n; - if (!CHECK_LHS_BOUNDARY && !CHECK_RHS_BOUNDARY) { - for (int i = 0; i < 4; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - output(lhs_vert + 3, horiz_base + i) = results[i].w; - } - } else if (!CHECK_RHS_BOUNDARY) { - // CHECK LHS - if (lhs_vert + 3 < m_size) { - for (int i = 0; i < 4; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - output(lhs_vert + 3, horiz_base + i) = results[i].w; - } - } else if (lhs_vert + 2 < m_size) { - for (int i = 0; i < 4; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - } - } else if (lhs_vert + 1 < m_size) { - for (int i = 0; i < 4; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - } - } else if (lhs_vert < m_size) { - for (int i = 0; i < 4; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - } - } - } else if (!CHECK_LHS_BOUNDARY) { - // CHECK RHS - /* - int ncols_rem = fminf(n_size- horiz_base, 4); - for (int i = 0; i < ncols_rem; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - output(lhs_vert + 3, horiz_base + i) = results[i].w; - }*/ - for (int i = 0; i < 4; i++) { - if (horiz_base+i < n_size) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - output(lhs_vert + 3, horiz_base + i) = results[i].w; - } - } - } else { - // CHECK both boundaries. - for (int i = 0; i < 4; i++) { - if (horiz_base+i < n_size) { - if (lhs_vert < m_size) - output(lhs_vert, horiz_base + i) = results[i].x; - if (lhs_vert + 1 < m_size) - output(lhs_vert + 1, horiz_base + i) = results[i].y; - if (lhs_vert + 2 < m_size) - output(lhs_vert + 2, horiz_base + i) = results[i].z; - if (lhs_vert + 3 < m_size) - output(lhs_vert + 3, horiz_base + i) = results[i].w; - } - } - } -} - - -template<typename Index, typename LhsMapper, - typename RhsMapper, typename OutputMapper, bool CHECK_LHS_BOUNDARY, - bool CHECK_RHS_BOUNDARY> -__device__ __forceinline__ void -EigenFloatContractionKernelInternal(const LhsMapper lhs, const RhsMapper rhs, - const OutputMapper output, float2 lhs_shmem2[][32], - float2 rhs_shmem2[][8], const Index m_size, - const Index n_size, const Index k_size, - const Index base_m, const Index base_n) { - - // prefetch registers - float4 lhs_pf0, lhs_pf1, lhs_pf2, lhs_pf3; - float4 rhs_pf0, rhs_pf1; - - float4 results[8]; - for (int i=0; i < 8; i++) { - results[i].x = results[i].y = results[i].z = results[i].w = 0; - } - - Index lhs_vert = base_m+threadIdx.x*4+(threadIdx.y%4)*32; - for (Index k = 0; k < k_size; k += 32) { - lhs_pf0 = internal::pset1<float4>(0); - lhs_pf1 = internal::pset1<float4>(0); - lhs_pf2 = internal::pset1<float4>(0); - lhs_pf3 = internal::pset1<float4>(0); - - rhs_pf0 = internal::pset1<float4>(0); - rhs_pf1 = internal::pset1<float4>(0); - - if (!CHECK_LHS_BOUNDARY) { - if ((threadIdx.y/4+k+24) < k_size) { - lhs_pf0 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k)); - lhs_pf1 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+8)); - lhs_pf2 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+16)); - lhs_pf3 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+24)); - } else if ((threadIdx.y/4+k+16) < k_size) { - lhs_pf0 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k)); - lhs_pf1 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+8)); - lhs_pf2 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+16)); - } else if ((threadIdx.y/4+k+8) < k_size) { - lhs_pf0 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k)); - lhs_pf1 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+8)); - } else if ((threadIdx.y/4+k) < k_size) { - lhs_pf0 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k)); - } - } else { - // just CHECK_LHS_BOUNDARY - if (lhs_vert + 3 < m_size) { - if ((threadIdx.y/4+k+24) < k_size) { - lhs_pf0 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k)); - lhs_pf1 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+8)); - lhs_pf2 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+16)); - lhs_pf3 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+24)); - } else if ((threadIdx.y/4+k+16) < k_size) { - lhs_pf0 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k)); - lhs_pf1 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+8)); - lhs_pf2 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+16)); - } else if ((threadIdx.y/4+k+8) < k_size) { - lhs_pf0 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k)); - lhs_pf1 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k+8)); - } else if ((threadIdx.y/4+k) < k_size) { - lhs_pf0 =lhs.template loadPacket<float4,Unaligned>(lhs_vert, (threadIdx.y/4+k)); - } - } else if (lhs_vert + 2 < m_size) { - if ((threadIdx.y/4+k+24) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf0.y =lhs(lhs_vert + 1, (threadIdx.y/4+k)); - lhs_pf0.z =lhs(lhs_vert + 2, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - lhs_pf1.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+8)); - lhs_pf1.z =lhs(lhs_vert + 2, (threadIdx.y/4+k+8)); - lhs_pf2.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+16)); - lhs_pf2.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+16)); - lhs_pf2.z =lhs(lhs_vert + 2, (threadIdx.y/4+k+16)); - lhs_pf3.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+24)); - lhs_pf3.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+24)); - lhs_pf3.z =lhs(lhs_vert + 2, (threadIdx.y/4+k+24)); - } else if ((threadIdx.y/4+k+16) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf0.y =lhs(lhs_vert + 1, (threadIdx.y/4+k)); - lhs_pf0.z =lhs(lhs_vert + 2, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - lhs_pf1.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+8)); - lhs_pf1.z =lhs(lhs_vert + 2, (threadIdx.y/4+k+8)); - lhs_pf2.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+16)); - lhs_pf2.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+16)); - lhs_pf2.z =lhs(lhs_vert + 2, (threadIdx.y/4+k+16)); - } else if ((threadIdx.y/4+k+8) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf0.y =lhs(lhs_vert + 1, (threadIdx.y/4+k)); - lhs_pf0.z =lhs(lhs_vert + 2, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - lhs_pf1.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+8)); - lhs_pf1.z =lhs(lhs_vert + 2, (threadIdx.y/4+k+8)); - } else if ((threadIdx.y/4+k) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf0.y =lhs(lhs_vert + 1, (threadIdx.y/4+k)); - lhs_pf0.z =lhs(lhs_vert + 2, (threadIdx.y/4+k)); - } - } else if (lhs_vert + 1 < m_size) { - if ((threadIdx.y/4+k+24) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf0.y =lhs(lhs_vert + 1, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - lhs_pf1.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+8)); - lhs_pf2.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+16)); - lhs_pf2.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+16)); - lhs_pf3.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+24)); - lhs_pf3.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+24)); - } else if ((threadIdx.y/4+k+16) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf0.y =lhs(lhs_vert + 1, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - lhs_pf1.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+8)); - lhs_pf2.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+16)); - lhs_pf2.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+16)); - } else if ((threadIdx.y/4+k+8) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf0.y =lhs(lhs_vert + 1, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - lhs_pf1.y =lhs(lhs_vert + 1, (threadIdx.y/4+k+8)); - } else if ((threadIdx.y/4+k) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf0.y =lhs(lhs_vert + 1, (threadIdx.y/4+k)); - } - } else if (lhs_vert < m_size) { - if ((threadIdx.y/4+k+24) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - lhs_pf2.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+16)); - lhs_pf3.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+24)); - } else if ((threadIdx.y/4+k+16) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - lhs_pf2.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+16)); - } else if ((threadIdx.y/4+k+8) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - lhs_pf1.x =lhs(lhs_vert + 0, (threadIdx.y/4+k+8)); - } else if ((threadIdx.y/4+k) < k_size) { - lhs_pf0.x =lhs(lhs_vert + 0, (threadIdx.y/4+k)); - } - } - } - __syncthreads(); - Index rhs_vert = k+threadIdx.x*4; - Index rhs_horiz0 = threadIdx.y*2+base_n; - Index rhs_horiz1 = threadIdx.y*2+1+base_n; - if (!CHECK_RHS_BOUNDARY) { - if ((rhs_vert + 3) < k_size) { - // just CHECK_RHS_BOUNDARY - rhs_pf0 = rhs.template loadPacket<float4,Unaligned>(rhs_vert, rhs_horiz0); - rhs_pf1 = rhs.template loadPacket<float4,Unaligned>(rhs_vert, rhs_horiz1); - } else if (rhs_vert + 2 < k_size) { - // just CHECK_RHS_BOUNDARY - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - rhs_pf0.z = rhs(rhs_vert + 2, rhs_horiz0); - rhs_pf1.x = rhs(rhs_vert, rhs_horiz1); - rhs_pf1.y = rhs(rhs_vert + 1, rhs_horiz1); - rhs_pf1.z = rhs(rhs_vert + 2, rhs_horiz1); - } else if (rhs_vert + 1 < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - rhs_pf1.x = rhs(rhs_vert, rhs_horiz1); - rhs_pf1.y = rhs(rhs_vert + 1, rhs_horiz1); - } else if (rhs_vert < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf1.x = rhs(rhs_vert, rhs_horiz1); - } - } else { - if (rhs_horiz1 < n_size) { - if ((rhs_vert + 3) < k_size) { - // just CHECK_RHS_BOUNDARY - rhs_pf0 = rhs.template loadPacket<float4,Unaligned>(rhs_vert, rhs_horiz0); - rhs_pf1 = rhs.template loadPacket<float4,Unaligned>(rhs_vert, rhs_horiz1); - } else if (rhs_vert + 2 < k_size) { - // just CHECK_RHS_BOUNDARY - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - rhs_pf0.z = rhs(rhs_vert + 2, rhs_horiz0); - rhs_pf1.x = rhs(rhs_vert, rhs_horiz1); - rhs_pf1.y = rhs(rhs_vert + 1, rhs_horiz1); - rhs_pf1.z = rhs(rhs_vert + 2, rhs_horiz1); - } else if (k+threadIdx.x*4 + 1 < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - rhs_pf1.x = rhs(rhs_vert, rhs_horiz1); - rhs_pf1.y = rhs(rhs_vert + 1, rhs_horiz1); - } else if (k+threadIdx.x*4 < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf1.x = rhs(rhs_vert, rhs_horiz1); - } - } else if (rhs_horiz0 < n_size) { - if ((rhs_vert + 3) < k_size) { - // just CHECK_RHS_BOUNDARY - rhs_pf0 = rhs.template loadPacket<float4,Unaligned>(rhs_vert, rhs_horiz0); - } else if ((rhs_vert + 2) < k_size) { - // just CHECK_RHS_BOUNDARY - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - rhs_pf0.z = rhs(rhs_vert + 2, rhs_horiz0); - } else if ((rhs_vert + 1) < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - rhs_pf0.y = rhs(rhs_vert + 1, rhs_horiz0); - } else if (rhs_vert < k_size) { - rhs_pf0.x = rhs(rhs_vert, rhs_horiz0); - } - } - } - __syncthreads(); - // Loaded. Do computation - // Row 0 -> times (0, 4, 8, .. 28) for features 0, 1. - // Row 1 -> times (0, 4, 8, .. 28) for features 2, 3. - // .. - // Row 31 -> times (0, 4, 8, .. 28) for features 62, 63 - rhs_shmem2[threadIdx.y][threadIdx.x] = make_float2(rhs_pf0.x, rhs_pf1.x); - // Row 32 -> times (1, 5, 9, .. 29) for features 0, 1. - // Row 33 -> times (1, 5, 9, .. 29) for features 2, 3. - // .. - rhs_shmem2[threadIdx.y+32][threadIdx.x] = make_float2(rhs_pf0.y, rhs_pf1.y); - // Row 64 -> times (2, 6, 10, .. 30) for features 0, 1. - // Row 65 -> times (2, 6, 10, .. 30) for features 2, 3. - rhs_shmem2[threadIdx.y+64][threadIdx.x] = make_float2(rhs_pf0.z, rhs_pf1.z); - // Row 96 -> times (3, 7, 11, .. 31) for features 0, 1. - // Row 97 -> times (3, 7, 11, .. 31) for features 2, 3. - rhs_shmem2[threadIdx.y+96][threadIdx.x] = make_float2(rhs_pf0.w, rhs_pf1.w); - - // LHS. - // Row 0 (time 0) -> features (0, 1), (4, 5), .. (28, 29), (32, 33), .. (60, 61) .. (124, 125) - // Row 1 (time 1) -> features (0, 1), (4, 5), .. (28, 29), (32, 33), .. (60, 61) .. (124, 125) - // ... - // Row 8 (time 0) -> features (2, 3), (6, 7), .. (30, 31), (34, 35), .. (62, 63) .. (126, 127) - // Row 15 (time 7) -> features (2, 3), (6, 7), .. (30, 31), (34, 35), .. (62, 63) .. (126, 127) - - -#define add_vals(a_feat1, a_feat2, f1, f2, f3, f4)\ - results[0].x += a_feat1.x * f1.x;\ - results[1].x += a_feat1.x * f1.y;\ - results[2].x += a_feat1.x * f2.x;\ - results[3].x += a_feat1.x * f2.y;\ - results[4].x += a_feat1.x * f3.x;\ - results[5].x += a_feat1.x * f3.y;\ - results[6].x += a_feat1.x * f4.x;\ - results[7].x += a_feat1.x * f4.y;\ -\ - results[0].y += a_feat1.y * f1.x;\ - results[1].y += a_feat1.y * f1.y;\ - results[2].y += a_feat1.y * f2.x;\ - results[3].y += a_feat1.y * f2.y;\ - results[4].y += a_feat1.y * f3.x;\ - results[5].y += a_feat1.y * f3.y;\ - results[6].y += a_feat1.y * f4.x;\ - results[7].y += a_feat1.y * f4.y;\ -\ - results[0].z += a_feat2.x * f1.x;\ - results[1].z += a_feat2.x * f1.y;\ - results[2].z += a_feat2.x * f2.x;\ - results[3].z += a_feat2.x * f2.y;\ - results[4].z += a_feat2.x * f3.x;\ - results[5].z += a_feat2.x * f3.y;\ - results[6].z += a_feat2.x * f4.x;\ - results[7].z += a_feat2.x * f4.y;\ -\ - results[0].w += a_feat2.y * f1.x;\ - results[1].w += a_feat2.y * f1.y;\ - results[2].w += a_feat2.y * f2.x;\ - results[3].w += a_feat2.y * f2.y;\ - results[4].w += a_feat2.y * f3.x;\ - results[5].w += a_feat2.y * f3.y;\ - results[6].w += a_feat2.y * f4.x;\ - results[7].w += a_feat2.y * f4.y;\ - - lhs_shmem2[threadIdx.y/4][threadIdx.x+(threadIdx.y%4)*8] = make_float2(lhs_pf0.x, lhs_pf0.y); - lhs_shmem2[threadIdx.y/4+8][threadIdx.x+(threadIdx.y%4)*8] = make_float2(lhs_pf1.x, lhs_pf1.y); - lhs_shmem2[threadIdx.y/4+16][threadIdx.x+(threadIdx.y%4)*8] = make_float2(lhs_pf2.x, lhs_pf2.y); - lhs_shmem2[threadIdx.y/4+24][threadIdx.x+(threadIdx.y%4)*8] = make_float2(lhs_pf3.x, lhs_pf3.y); - - lhs_shmem2[threadIdx.y/4 + 32][threadIdx.x+(threadIdx.y%4)*8] = make_float2(lhs_pf0.z, lhs_pf0.w); - lhs_shmem2[threadIdx.y/4 + 40][threadIdx.x+(threadIdx.y%4)*8] = make_float2(lhs_pf1.z, lhs_pf1.w); - lhs_shmem2[threadIdx.y/4 + 48][threadIdx.x+(threadIdx.y%4)*8] = make_float2(lhs_pf2.z, lhs_pf2.w); - lhs_shmem2[threadIdx.y/4 + 56][threadIdx.x+(threadIdx.y%4)*8] = make_float2(lhs_pf3.z, lhs_pf3.w); - - __syncthreads(); - - // Do the multiplies. - #pragma unroll - for (int koff = 0; koff < 32; koff ++) { - float2 a3 = lhs_shmem2[koff][threadIdx.x + (threadIdx.y % 4) * 8]; - float2 a4 = lhs_shmem2[koff + 32][threadIdx.x + (threadIdx.y % 4) * 8]; - - // first feature is at (threadIdx.y/4) * 8 last is at start + 8. - int start_feature = (threadIdx.y / 4) * 8; - - float2 br1 = rhs_shmem2[start_feature/2 + (koff % 4) * 32][koff/4]; - float2 br2 = rhs_shmem2[start_feature/2 + 1 + (koff % 4) * 32][koff/4]; - float2 br3 = rhs_shmem2[start_feature/2 + 2 + (koff % 4) * 32][koff/4]; - float2 br4 = rhs_shmem2[start_feature/2 + 3 + (koff % 4) * 32][koff/4]; - - add_vals(a3, a4, br1, br2, br3, br4) - } - __syncthreads(); - } // end loop over k - - __syncthreads(); - Index horiz_base = (threadIdx.y/4)*8+base_n; - if (!CHECK_LHS_BOUNDARY && !CHECK_RHS_BOUNDARY) { - for (int i = 0; i < 8; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - output(lhs_vert + 3, horiz_base + i) = results[i].w; - } - } else if (!CHECK_RHS_BOUNDARY) { - if (lhs_vert + 3 < m_size) { - for (int i = 0; i < 8; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - output(lhs_vert + 3, horiz_base + i) = results[i].w; - } - } else if (lhs_vert + 2 < m_size) { - for (int i = 0; i < 8; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - } - } else if (lhs_vert + 1 < m_size) { - for (int i = 0; i < 8; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - } - } else if (lhs_vert < m_size) { - for (int i = 0; i < 8; i++) { - output(lhs_vert, horiz_base + i) = results[i].x; - } - } - } else if (!CHECK_LHS_BOUNDARY) { - // CHECK BOUNDARY_B - for (int i = 0; i < 8; i++) { - if (horiz_base + i < n_size) { - output(lhs_vert, horiz_base + i) = results[i].x; - output(lhs_vert + 1, horiz_base + i) = results[i].y; - output(lhs_vert + 2, horiz_base + i) = results[i].z; - output(lhs_vert + 3, horiz_base + i) = results[i].w; - } - } - } else { - // CHECK both boundaries. - for (int i = 0; i < 8; i++) { - if (horiz_base + i < n_size) { - if (lhs_vert < m_size) - output(lhs_vert, horiz_base + i) = results[i].x; - if (lhs_vert + 1 < m_size) - output(lhs_vert + 1, horiz_base + i) = results[i].y; - if (lhs_vert + 2 < m_size) - output(lhs_vert + 2, horiz_base + i) = results[i].z; - if (lhs_vert + 3 < m_size) - output(lhs_vert + 3, horiz_base + i) = results[i].w; - } - } - } -} - - -template<typename Index, typename LhsMapper, - typename RhsMapper, typename OutputMapper> -__global__ void -#if defined(EIGEN_HIPCC) -__launch_bounds__(256, 1) -#else -__launch_bounds__(256) -#endif -EigenFloatContractionKernel(const LhsMapper lhs, const RhsMapper rhs, - const OutputMapper output, - const Index m_size, const Index n_size, const Index k_size) { - __shared__ float2 lhs_shmem[64*32]; - __shared__ float2 rhs_shmem[128*8]; - - typedef float2 LHS_MEM[64][32]; - typedef float2 RHS_MEM[128][8]; - - const Index m_block_idx = blockIdx.x; - const Index n_block_idx = blockIdx.y; - - const Index base_m = 128 * m_block_idx; - const Index base_n = 64 * n_block_idx; - - bool check_rhs = (base_n + 63) >= n_size; - bool check_lhs128 = (base_m + 127) >= m_size; - - if (!check_rhs) { - if (!check_lhs128) { - // >= 128 rows left - EigenFloatContractionKernelInternal<Index, LhsMapper, RhsMapper, OutputMapper, false, false>( - lhs, rhs, output, *((LHS_MEM *) lhs_shmem), *((RHS_MEM *) rhs_shmem), m_size, n_size, k_size, base_m, base_n); - } else { - EigenFloatContractionKernelInternal<Index, LhsMapper, RhsMapper, OutputMapper, true, false>( - lhs, rhs, output, *((LHS_MEM *) lhs_shmem), *((RHS_MEM *) rhs_shmem), m_size, n_size, k_size, base_m, base_n); - } - } else { - if (!check_lhs128) { - // >= 128 rows left - EigenFloatContractionKernelInternal<Index, LhsMapper, RhsMapper, OutputMapper, false, true>( - lhs, rhs, output, *((LHS_MEM *) lhs_shmem), *((RHS_MEM *) rhs_shmem), m_size, n_size, k_size, base_m, base_n); - } else { - EigenFloatContractionKernelInternal<Index, LhsMapper, RhsMapper, OutputMapper, true, true>( - lhs, rhs, output, *((LHS_MEM *) lhs_shmem), *((RHS_MEM *) rhs_shmem), m_size, n_size, k_size, base_m, base_n); - } - } -} - -template<typename Index, typename LhsMapper, - typename RhsMapper, typename OutputMapper> -__global__ void -#if defined(EIGEN_HIPCC) -__launch_bounds__(256, 1) -#else -__launch_bounds__(256) -#endif -EigenFloatContractionKernel16x16(const LhsMapper lhs, const RhsMapper rhs, - const OutputMapper output, - const Index m_size, const Index n_size, const Index k_size) { - __shared__ float2 lhs_shmem[32][16]; - __shared__ float2 rhs_shmem[64][8]; - - const Index m_block_idx = blockIdx.x; - const Index n_block_idx = blockIdx.y; - - const Index base_m = 64 * m_block_idx; - const Index base_n = 64 * n_block_idx; - - if (base_m + 63 < m_size) { - if (base_n + 63 < n_size) { - EigenFloatContractionKernelInternal16x16<Index, LhsMapper, RhsMapper, OutputMapper, false, false>(lhs, rhs, output, lhs_shmem, rhs_shmem, m_size, n_size, k_size, base_m, base_n); - } else { - EigenFloatContractionKernelInternal16x16<Index, LhsMapper, RhsMapper, OutputMapper, false, true>(lhs, rhs, output, lhs_shmem, rhs_shmem, m_size, n_size, k_size, base_m, base_n); - } - } else { - if (base_n + 63 < n_size) { - EigenFloatContractionKernelInternal16x16<Index, LhsMapper, RhsMapper, OutputMapper, true, false>(lhs, rhs, output, lhs_shmem, rhs_shmem, m_size, n_size, k_size, base_m, base_n); - } else { - EigenFloatContractionKernelInternal16x16<Index, LhsMapper, RhsMapper, OutputMapper, true, true>(lhs, rhs, output, lhs_shmem, rhs_shmem, m_size, n_size, k_size, base_m, base_n); - } - } -} - - -template<typename Indices, typename LeftArgType, typename RightArgType, typename OutputKernelType> -struct TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, GpuDevice> : - public TensorContractionEvaluatorBase<TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, GpuDevice> > { - - typedef GpuDevice Device; - - typedef TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, Device> Self; - typedef TensorContractionEvaluatorBase<Self> Base; - - typedef TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType> XprType; - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef typename XprType::Index Index; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, GpuDevice>::type PacketReturnType; - - enum { - Layout = TensorEvaluator<LeftArgType, Device>::Layout, - }; - - // Most of the code is assuming that both input tensors are ColMajor. If the - // inputs are RowMajor, we will "cheat" by swapping the LHS and RHS: - // If we want to compute A * B = C, where A is LHS and B is RHS, the code - // will pretend B is LHS and A is RHS. - typedef typename internal::conditional< - static_cast<int>(Layout) == static_cast<int>(ColMajor), LeftArgType, RightArgType>::type EvalLeftArgType; - typedef typename internal::conditional< - static_cast<int>(Layout) == static_cast<int>(ColMajor), RightArgType, LeftArgType>::type EvalRightArgType; - - static const int LDims = - internal::array_size<typename TensorEvaluator<EvalLeftArgType, Device>::Dimensions>::value; - static const int RDims = - internal::array_size<typename TensorEvaluator<EvalRightArgType, Device>::Dimensions>::value; - static const int ContractDims = internal::array_size<Indices>::value; - - typedef array<Index, LDims> left_dim_mapper_t; - typedef array<Index, RDims> right_dim_mapper_t; - - typedef array<Index, ContractDims> contract_t; - typedef array<Index, LDims - ContractDims> left_nocontract_t; - typedef array<Index, RDims - ContractDims> right_nocontract_t; - - static const int NumDims = LDims + RDims - 2 * ContractDims; - - typedef DSizes<Index, NumDims> Dimensions; - - // typedefs needed in evalTo - typedef typename internal::remove_const<typename EvalLeftArgType::Scalar>::type LhsScalar; - typedef typename internal::remove_const<typename EvalRightArgType::Scalar>::type RhsScalar; - - typedef TensorEvaluator<EvalLeftArgType, Device> LeftEvaluator; - typedef TensorEvaluator<EvalRightArgType, Device> RightEvaluator; - - typedef typename LeftEvaluator::Dimensions LeftDimensions; - typedef typename RightEvaluator::Dimensions RightDimensions; - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) : - Base(op, device) - { - EIGEN_STATIC_ASSERT( (internal::is_same<OutputKernelType, const NoOpOutputKernel>::value), - GPU_TENSOR_CONTRACTION_DOES_NOT_SUPPORT_OUTPUT_KERNELS); - } - - // We need to redefine this method to make nvcc happy - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(Scalar* data) { - this->m_leftImpl.evalSubExprsIfNeeded(NULL); - this->m_rightImpl.evalSubExprsIfNeeded(NULL); - if (data) { - evalTo(data); - return false; - } else { - this->m_result = static_cast<Scalar *>(this->m_device.allocate(this->dimensions().TotalSize() * sizeof(Scalar))); - evalTo(this->m_result); - return true; - } - } - - void evalTo(Scalar* buffer) const { - if (this->m_lhs_inner_dim_contiguous) { - if (this->m_rhs_inner_dim_contiguous) { - if (this->m_rhs_inner_dim_reordered) { - evalTyped<true, true, true, Unaligned>(buffer); - } - else { - evalTyped<true, true, false, Unaligned>(buffer); - } - } - else { - if (this->m_rhs_inner_dim_reordered) { - evalTyped<true, false, true, Unaligned>(buffer); - } - else { - evalTyped<true, false, false, Unaligned>(buffer); - } - } - } - else { - if (this->m_rhs_inner_dim_contiguous) { - if (this->m_rhs_inner_dim_reordered) { - evalTyped<false, true, true, Unaligned>(buffer); - } - else { - evalTyped<false, true, false, Unaligned>(buffer); - } - } - else { - if (this->m_rhs_inner_dim_reordered) { - evalTyped<false, false, true, Unaligned>(buffer); - } - else { - evalTyped<false, false, false, Unaligned>(buffer); - } - } - } - } - - template <typename LhsScalar, typename RhsScalar, typename Index, typename LhsMapper, typename RhsMapper, typename OutputMapper> struct LaunchKernels { - static void Run(const LhsMapper& lhs, const RhsMapper& rhs, const OutputMapper& output, Index m, Index n, Index k, const GpuDevice& device) { - const Index m_blocks = (m + 63) / 64; - const Index n_blocks = (n + 63) / 64; - const dim3 num_blocks(m_blocks, n_blocks, 1); - const dim3 block_size(8, 8, 8); - LAUNCH_GPU_KERNEL((EigenContractionKernel<Scalar, Index, LhsMapper, RhsMapper, OutputMapper>), num_blocks, block_size, 0, device, lhs, rhs, output, m, n, k); - } - }; - - template <typename Index, typename LhsMapper, typename RhsMapper, typename OutputMapper> struct LaunchKernels<float, float, Index, LhsMapper, RhsMapper, OutputMapper> { - static void Run(const LhsMapper& lhs, const RhsMapper& rhs, const OutputMapper& output, Index m, Index n, Index k, const GpuDevice& device) { - if (m < 768 || n < 768) { - const Index m_blocks = (m + 63) / 64; - const Index n_blocks = (n + 63) / 64; - const dim3 num_blocks(m_blocks, n_blocks, 1); - const dim3 block_size(16, 16, 1); - LAUNCH_GPU_KERNEL((EigenFloatContractionKernel16x16<Index, LhsMapper, RhsMapper, OutputMapper>), num_blocks, block_size, 0, device, lhs, rhs, output, m, n, k); - } else { - const Index m_blocks = (m + 127) / 128; - const Index n_blocks = (n + 63) / 64; - const dim3 num_blocks(m_blocks, n_blocks, 1); - const dim3 block_size(8, 32, 1); - LAUNCH_GPU_KERNEL((EigenFloatContractionKernel<Index, LhsMapper, RhsMapper, OutputMapper>), num_blocks, block_size, 0, device, lhs, rhs, output, m, n, k); - } - } - }; - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment> - void evalTyped(Scalar* buffer) const { - // columns in left side, rows in right side - const Index k = this->m_k_size; - EIGEN_UNUSED_VARIABLE(k) - - // rows in left side - const Index m = this->m_i_size; - - // columns in right side - const Index n = this->m_j_size; - - // zero out the result buffer (which must be of size at least m * n * sizeof(Scalar) - this->m_device.memset(buffer, 0, m * n * sizeof(Scalar)); - - typedef internal::TensorContractionInputMapper<LhsScalar, Index, internal::Lhs, - LeftEvaluator, left_nocontract_t, - contract_t, 4, - lhs_inner_dim_contiguous, - false, Unaligned> LhsMapper; - - typedef internal::TensorContractionInputMapper<RhsScalar, Index, internal::Rhs, - RightEvaluator, right_nocontract_t, - contract_t, 4, - rhs_inner_dim_contiguous, - rhs_inner_dim_reordered, Unaligned> RhsMapper; - - typedef internal::blas_data_mapper<Scalar, Index, ColMajor> OutputMapper; - - - // initialize data mappers - LhsMapper lhs(this->m_leftImpl, this->m_left_nocontract_strides, this->m_i_strides, - this->m_left_contracting_strides, this->m_k_strides); - - RhsMapper rhs(this->m_rightImpl, this->m_right_nocontract_strides, this->m_j_strides, - this->m_right_contracting_strides, this->m_k_strides); - - OutputMapper output(buffer, m); - -#if defined(EIGEN_USE_HIP) - setGpuSharedMemConfig(hipSharedMemBankSizeEightByte); -#else - setGpuSharedMemConfig(cudaSharedMemBankSizeEightByte); -#endif - - LaunchKernels<LhsScalar, RhsScalar, Index, LhsMapper, RhsMapper, OutputMapper>::Run(lhs, rhs, output, m, n, k, this->m_device); - } -}; - -} // end namespace Eigen - -#endif // EIGEN_USE_GPU and EIGEN_GPUCC -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_GPU_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h deleted file mode 100644 index 9ab900b4..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h +++ /dev/null @@ -1,575 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_MAPPER_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_MAPPER_H - -namespace Eigen { - -namespace internal { - -enum { - Rhs = 0, - Lhs = 1 -}; - -/* - * Implementation of the Eigen blas_data_mapper class for tensors. - */ -/// The make pointer class is used by sycl in order to build the mapper class on the device. For other platform the default make pointer is used which -/// is scalar * for CoeffLoader. -template <typename Tensor, bool HasRawAccess, template <class> class MakePointer_ = MakePointer> -struct CoeffLoader; - -template <typename Scalar, typename Index, int side, typename Tensor, - typename nocontract_t, typename contract_t, int packet_size, - bool inner_dim_contiguous, bool inner_dim_reordered, int Alignment, - template <class> class MakePointer_ = MakePointer> -class BaseTensorContractionMapper; - -template <typename Tensor, bool HasRawAccess, template <class> class MakePointer_> -struct CoeffLoader { - enum { - DirectOffsets = false - }; - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE CoeffLoader(const Tensor& tensor) : m_tensor(tensor) { } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void offsetBuffer(typename Tensor::Index) { - eigen_assert(false && "unsupported"); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const typename MakePointer_<const typename Tensor::Scalar>::Type - data() const { - eigen_assert(false && "unsupported"); - return NULL; - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE typename Tensor::Scalar coeff(typename Tensor::Index index) const { return m_tensor.coeff(index); } - - template<int LoadMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename Tensor::PacketReturnType packet(typename Tensor::Index index) const - { - return m_tensor.template packet<LoadMode>(index); - } - - #ifdef EIGEN_USE_SYCL - // The placeholder accessors require to be bound to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_tensor.bind(cgh); - } - #endif - - private: - const Tensor m_tensor; -}; - -template <typename Tensor, template <class> class MakePointer_> -struct CoeffLoader<Tensor, true, MakePointer_> { - enum { - DirectOffsets = true - }; - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE CoeffLoader(const Tensor& tensor) : m_data(tensor.data()) {} - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void offsetBuffer(typename Tensor::Index offset) { - m_data += offset; - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const typename MakePointer_<const typename Tensor::Scalar>::Type - data() const { - return m_data; - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE typename Tensor::Scalar coeff(typename Tensor::Index index) const { return loadConstant(m_data+index); } - - template<int LoadMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename Tensor::PacketReturnType packet(typename Tensor::Index index) const - { - return internal::ploadt_ro<typename Tensor::PacketReturnType, LoadMode>(m_data + index); - } - - #ifdef EIGEN_USE_SYCL - // The placeholder accessors require to be bound to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_data.bind(cgh); - } - #endif - private: - typedef typename Tensor::Scalar Scalar; - - typename MakePointer_<const Scalar>::Type m_data; -}; - -template<typename Scalar, typename Index, int side, - typename Tensor, - typename nocontract_t, typename contract_t, - int packet_size, bool inner_dim_contiguous, int Alignment, template <class> class MakePointer_ = MakePointer> -class SimpleTensorContractionMapper { - public: - EIGEN_DEVICE_FUNC - SimpleTensorContractionMapper(const Tensor& tensor, - const nocontract_t& nocontract_strides, - const nocontract_t& ij_strides, - const contract_t& contract_strides, - const contract_t& k_strides) : - m_tensor(tensor), - m_nocontract_strides(nocontract_strides), - m_ij_strides(ij_strides), - m_contract_strides(contract_strides), - m_k_strides(k_strides) { } - - enum { - DirectOffsets = CoeffLoader<Tensor, Tensor::RawAccess, MakePointer_>::DirectOffsets - }; - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void offsetBuffer(typename Tensor::Index offset) { - m_tensor.offsetBuffer(offset); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE void prefetch(Index /*i*/) { } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar operator()(Index row) const { - // column major assumption - return operator()(row, 0); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar operator()(Index row, Index col) const { - return m_tensor.coeff(computeIndex(row, col)); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index computeIndex(Index row, Index col) const { - const bool left = (side == Lhs); - EIGEN_UNUSED_VARIABLE(left); // annoying bug in g++8.1: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85963 - Index nocontract_val = left ? row : col; - Index linidx = 0; - EIGEN_UNROLL_LOOP - for (int i = static_cast<int>(array_size<nocontract_t>::value) - 1; i > 0; i--) { - const Index idx = nocontract_val / m_ij_strides[i]; - linidx += idx * m_nocontract_strides[i]; - nocontract_val -= idx * m_ij_strides[i]; - } - if (array_size<typename Tensor::Dimensions>::value > array_size<contract_t>::value) { - if (side == Lhs && inner_dim_contiguous) { - eigen_assert(m_nocontract_strides[0] == 1); - linidx += nocontract_val; - } else { - linidx += nocontract_val * m_nocontract_strides[0]; - } - } - - Index contract_val = left ? col : row; - if(array_size<contract_t>::value > 0) { - EIGEN_UNROLL_LOOP - for (int i = static_cast<int>(array_size<contract_t>::value) - 1; i > 0; i--) { - const Index idx = contract_val / m_k_strides[i]; - linidx += idx * m_contract_strides[i]; - contract_val -= idx * m_k_strides[i]; - } - - if (side == Rhs && inner_dim_contiguous) { - eigen_assert(m_contract_strides[0] == 1); - linidx += contract_val; - } else { - linidx += contract_val * m_contract_strides[0]; - } - } - - return linidx; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE IndexPair<Index> computeIndexPair(Index row, Index col, const Index distance) const { - const bool left = (side == Lhs); - EIGEN_UNUSED_VARIABLE(left); // annoying bug in g++8.1: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85963 - Index nocontract_val[2] = {left ? row : col, left ? row + distance : col}; - Index linidx[2] = {0, 0}; - if (array_size<typename Tensor::Dimensions>::value > array_size<contract_t>::value) { - EIGEN_UNROLL_LOOP - for (int i = static_cast<int>(array_size<nocontract_t>::value) - 1; i > 0; i--) { - const Index idx0 = nocontract_val[0] / m_ij_strides[i]; - const Index idx1 = nocontract_val[1] / m_ij_strides[i]; - linidx[0] += idx0 * m_nocontract_strides[i]; - linidx[1] += idx1 * m_nocontract_strides[i]; - nocontract_val[0] -= idx0 * m_ij_strides[i]; - nocontract_val[1] -= idx1 * m_ij_strides[i]; - } - if (side == Lhs && inner_dim_contiguous) { - eigen_assert(m_nocontract_strides[0] == 1); - linidx[0] += nocontract_val[0]; - linidx[1] += nocontract_val[1]; - } else { - linidx[0] += nocontract_val[0] * m_nocontract_strides[0]; - linidx[1] += nocontract_val[1] * m_nocontract_strides[0]; - } - } - - Index contract_val[2] = {left ? col : row, left ? col : row + distance}; - if (array_size<contract_t>::value> 0) { - EIGEN_UNROLL_LOOP - for (int i = static_cast<int>(array_size<contract_t>::value) - 1; i > 0; i--) { - const Index idx0 = contract_val[0] / m_k_strides[i]; - const Index idx1 = contract_val[1] / m_k_strides[i]; - linidx[0] += idx0 * m_contract_strides[i]; - linidx[1] += idx1 * m_contract_strides[i]; - contract_val[0] -= idx0 * m_k_strides[i]; - contract_val[1] -= idx1 * m_k_strides[i]; - } - - if (side == Rhs && inner_dim_contiguous) { - eigen_assert(m_contract_strides[0] == 1); - linidx[0] += contract_val[0]; - linidx[1] += contract_val[1]; - } else { - linidx[0] += contract_val[0] * m_contract_strides[0]; - linidx[1] += contract_val[1] * m_contract_strides[0]; - } - } - return IndexPair<Index>(linidx[0], linidx[1]); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Index firstAligned(Index size) const { - // Only claim alignment when we can compute the actual stride (ie when we're - // dealing with the lhs with inner_dim_contiguous. This is because the - // matrix-vector product relies on the stride when dealing with aligned inputs. - return (Alignment == Aligned) && (side == Lhs) && inner_dim_contiguous ? 0 : size; - } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Index stride() const { - return ((side == Lhs) && inner_dim_contiguous && array_size<contract_t>::value > 0) ? m_contract_strides[0] : 1; - } - - #ifdef EIGEN_USE_SYCL - // The placeholder accessors require to be bound to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_tensor.bind(cgh); - } - #endif - - const CoeffLoader<Tensor, Tensor::RawAccess, MakePointer_>& tensor() const { - return m_tensor; - } - - const nocontract_t& nocontract_strides() const { - return m_nocontract_strides; - } - const nocontract_t& ij_strides() const { return m_ij_strides; } - const contract_t& contract_strides() const { return m_contract_strides; } - const contract_t& k_strides() const { return m_k_strides; } - - protected: - CoeffLoader<Tensor, Tensor::RawAccess, MakePointer_> m_tensor; - const nocontract_t m_nocontract_strides; - const nocontract_t m_ij_strides; - const contract_t m_contract_strides; - const contract_t m_k_strides; -}; - -template<typename Scalar, typename Index, int side, - typename Tensor, - typename nocontract_t, typename contract_t, - int packet_size, bool inner_dim_contiguous, - bool inner_dim_reordered, int Alignment, template <class> class MakePointer_> -class BaseTensorContractionMapper : public SimpleTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, Alignment, MakePointer_> -{ - public: - typedef SimpleTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, Alignment, MakePointer_> ParentMapper; - - EIGEN_DEVICE_FUNC - BaseTensorContractionMapper(const Tensor& tensor, - const nocontract_t& nocontract_strides, - const nocontract_t& ij_strides, - const contract_t& contract_strides, - const contract_t& k_strides) : - ParentMapper(tensor, nocontract_strides, ij_strides, contract_strides, k_strides) { } - - template <typename PacketT,int AlignmentType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename internal::enable_if<internal::unpacket_traits<PacketT>::size==packet_size,PacketT>::type - load(Index i, Index j) const - { - // whole method makes column major assumption - - // don't need to add offsets for now (because operator handles that) - // current code assumes packet size must be a multiple of 2 - EIGEN_STATIC_ASSERT(packet_size % 2 == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - - if (Tensor::PacketAccess && inner_dim_contiguous && !inner_dim_reordered) { - const Index index = this->computeIndex(i, j); - eigen_assert(this->computeIndex(i+packet_size-1, j) == index + packet_size-1); - return this->m_tensor.template packet<AlignmentType>(index); - } - - const IndexPair<Index> indexPair = this->computeIndexPair(i, j, packet_size - 1); - const Index first = indexPair.first; - const Index lastIdx = indexPair.second; - - // We can always do optimized packet reads from left hand side right now, because - // the vertical matrix dimension on the left hand side is never contracting. - // On the right hand side we need to check if the contracting dimensions may have - // been shuffled first. - if (Tensor::PacketAccess && - (side == Lhs || internal::array_size<contract_t>::value <= 1 || !inner_dim_reordered) && - (lastIdx - first) == (packet_size - 1)) { - - return this->m_tensor.template packet<AlignmentType>(first); - } - - EIGEN_ALIGN_MAX Scalar data[packet_size]; - - data[0] = this->m_tensor.coeff(first); - EIGEN_UNROLL_LOOP - for (Index k = 1; k < packet_size - 1; k += 2) { - const IndexPair<Index> internal_pair = this->computeIndexPair(i + k, j, 1); - data[k] = this->m_tensor.coeff(internal_pair.first); - data[k + 1] = this->m_tensor.coeff(internal_pair.second); - } - data[packet_size - 1] = this->m_tensor.coeff(lastIdx); - - return pload<PacketT>(data); - } - - template <typename PacketT,int AlignmentType> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename internal::enable_if<internal::unpacket_traits<PacketT>::size!=packet_size,PacketT>::type - load(Index i, Index j) const - { - const Index requested_packet_size = internal::unpacket_traits<PacketT>::size; - EIGEN_ALIGN_MAX Scalar data[requested_packet_size]; - - const IndexPair<Index> indexPair = this->computeIndexPair(i, j, requested_packet_size - 1); - const Index first = indexPair.first; - const Index lastIdx = indexPair.second; - - data[0] = this->m_tensor.coeff(first); - for (Index k = 1; k < requested_packet_size - 1; k += 2) { - const IndexPair<Index> internal_pair = this->computeIndexPair(i + k, j, 1); - data[k] = this->m_tensor.coeff(internal_pair.first); - data[k + 1] = this->m_tensor.coeff(internal_pair.second); - } - data[requested_packet_size - 1] = this->m_tensor.coeff(lastIdx); - - return pload<PacketT>(data); - } - - template <typename PacketT,int AlignmentType> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PacketT loadPacket(Index i, Index j) const { - return this->load<PacketT,AlignmentType>(i,j); - } -}; - - -template<typename Scalar, typename Index, int side, - typename Tensor, - typename nocontract_t, typename contract_t, - bool inner_dim_contiguous, - bool inner_dim_reordered, int Alignment, template <class> class MakePointer_> -class BaseTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> - : public SimpleTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, Alignment, MakePointer_> -{ - public: - typedef SimpleTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, Alignment, MakePointer_> ParentMapper; - - EIGEN_DEVICE_FUNC - BaseTensorContractionMapper(const Tensor& tensor, - const nocontract_t& nocontract_strides, - const nocontract_t& ij_strides, - const contract_t& contract_strides, - const contract_t& k_strides) : - ParentMapper(tensor, nocontract_strides, ij_strides, contract_strides, k_strides) { } - - template <typename PacketT,int> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PacketT loadPacket(Index i, Index j) const { - EIGEN_ALIGN_MAX Scalar data[1]; - data[0] = this->m_tensor.coeff(this->computeIndex(i, j)); - return pload<PacketT>(data); - } - template <typename PacketT,int> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE PacketT load(Index i, Index j) const { - EIGEN_ALIGN_MAX Scalar data[1]; - data[0] = this->m_tensor.coeff(this->computeIndex(i, j)); - return pload<PacketT>(data); - } -}; - - -template<typename Scalar, typename Index, int side, - typename Tensor, - typename nocontract_t, typename contract_t, - int packet_size, - bool inner_dim_contiguous, bool inner_dim_reordered, int Alignment, template <class> class MakePointer_=MakePointer> -class TensorContractionSubMapper { - public: - - typedef BaseTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> ParentMapper; - typedef TensorContractionSubMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> Self; - typedef Self LinearMapper; - - enum { - // We can use direct offsets iff the parent mapper supports then and we can compute the strides. - // TODO: we should also enable direct offsets for the Rhs case. - UseDirectOffsets = ParentMapper::DirectOffsets && (side == Lhs) && inner_dim_contiguous && (array_size<contract_t>::value > 0) - }; - - EIGEN_DEVICE_FUNC TensorContractionSubMapper(const ParentMapper& base_mapper, Index vert_offset, Index horiz_offset) - : m_base_mapper(base_mapper), m_vert_offset(vert_offset), m_horiz_offset(horiz_offset) { - // Bake the offsets into the buffer used by the base mapper whenever possible. This avoids the need to recompute - // this offset every time we attempt to access a coefficient. - if (UseDirectOffsets) { - Index stride = m_base_mapper.stride(); - m_base_mapper.offsetBuffer(vert_offset + horiz_offset * stride); - } - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar operator()(Index i) const { - if (UseDirectOffsets) { - return m_base_mapper(i, 0); - } - return m_base_mapper(i + m_vert_offset, m_horiz_offset); - } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar operator()(Index i, Index j) const { - if (UseDirectOffsets) { - return m_base_mapper(i, j); - } - return m_base_mapper(i + m_vert_offset, j + m_horiz_offset); - } - - template <typename PacketT> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT loadPacket(Index i) const { - if (UseDirectOffsets) { - return m_base_mapper.template loadPacket<PacketT,Alignment>(i, 0); - } - return m_base_mapper.template loadPacket<PacketT,Alignment>(i + m_vert_offset, m_horiz_offset); - } - - template <typename PacketT> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT loadPacket(Index i, Index j) const { - if (UseDirectOffsets) { - return m_base_mapper.template loadPacket<PacketT,Alignment>(i, j); - } - return m_base_mapper.template loadPacket<PacketT,Alignment>(i + m_vert_offset, j + m_horiz_offset); - } - - template <typename PacketT, int AlignmentType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT loadPacket(Index i, Index j) const { - if (UseDirectOffsets) { - return m_base_mapper.template load<PacketT,AlignmentType>(i, j); - } - return m_base_mapper.template loadPacket<PacketT,AlignmentType>(i + m_vert_offset, j + m_horiz_offset); - } - - template <typename PacketT> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void storePacket(Index i, const PacketT& p) const { - if (UseDirectOffsets) { - m_base_mapper.storePacket(i, 0, p); - } - m_base_mapper.storePacket(i + m_vert_offset, m_horiz_offset, p); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LinearMapper getLinearMapper(Index i, Index j) const { - if (UseDirectOffsets) { - return LinearMapper(m_base_mapper, i, j); - } - return LinearMapper(m_base_mapper, i + m_vert_offset, j + m_horiz_offset); - } - - template <typename PacketT, int AlignmentType> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT load(Index i) const { - EIGEN_STATIC_ASSERT((internal::is_same<PacketT, PacketT>::value), YOU_MADE_A_PROGRAMMING_MISTAKE); - const int ActualAlignment = (AlignmentType == Aligned) && (Alignment == Aligned) ? Aligned : Unaligned; - if (UseDirectOffsets) { - return m_base_mapper.template loadPacket<PacketT,ActualAlignment>(i, 0); - } - return m_base_mapper.template loadPacket<PacketT,ActualAlignment>(i + m_vert_offset, m_horiz_offset); - } - - template <typename PacketT> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool aligned(Index) const { - return false; - } - - #ifdef EIGEN_USE_SYCL - // The placeholder accessors require to be bound to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_base_mapper.bind(cgh); - } - #endif - - const ParentMapper& base_mapper() const { return m_base_mapper; } - Index vert_offset() const { return m_vert_offset; } - Index horiz_offset() const { return m_horiz_offset; } - - private: - ParentMapper m_base_mapper; - const Index m_vert_offset; - const Index m_horiz_offset; -}; - - -template<typename Scalar_, typename Index, int side, - typename Tensor, - typename nocontract_t, typename contract_t, - int packet_size, - bool inner_dim_contiguous, bool inner_dim_reordered, int Alignment, template <class> class MakePointer_=MakePointer> -class TensorContractionInputMapper - : public BaseTensorContractionMapper<Scalar_, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> { - - public: - typedef Scalar_ Scalar; - typedef BaseTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> Base; - typedef TensorContractionSubMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> SubMapper; - typedef SubMapper VectorMapper; - - EIGEN_DEVICE_FUNC TensorContractionInputMapper(const Tensor& tensor, - const nocontract_t& nocontract_strides, - const nocontract_t& ij_strides, - const contract_t& contract_strides, - const contract_t& k_strides) - : Base(tensor, nocontract_strides, ij_strides, contract_strides, k_strides) { } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE SubMapper getSubMapper(Index i, Index j) const { - return SubMapper(*this, i, j); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE VectorMapper getVectorMapper(Index i, Index j) const { - return VectorMapper(*this, i, j); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const CoeffLoader<Tensor, Tensor::RawAccess, MakePointer_>& get_tensor() const { - return Base::m_tensor; - } -}; - - -template <typename T> struct TensorContractionInputMapperTrait; - -template<typename Scalar_, typename Index_, int side_, - typename Tensor_, - typename nocontract_t_, typename contract_t_, - int packet_size_, - bool inner_dim_contiguous_, bool inner_dim_reordered_, int Alignment_, template <class> class MakePointer_> -struct TensorContractionInputMapperTrait<TensorContractionInputMapper<Scalar_, Index_, side_, Tensor_, - nocontract_t_, contract_t_, packet_size_, inner_dim_contiguous_, - inner_dim_reordered_, Alignment_, MakePointer_> > { - - typedef Tensor_ XprType; - static const bool inner_dim_contiguous = inner_dim_contiguous_; - static const bool inner_dim_reordered = inner_dim_reordered_; - }; - - -} // end namespace internal -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_MAPPER_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionSycl.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionSycl.h deleted file mode 100644 index a6ca1777..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionSycl.h +++ /dev/null @@ -1,1650 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License v. 2.0. If a copy of the MPL was not -// distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/***************************************************************** - * TensorContractionSycl.h - * - * \brief: - * TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend - * - *****************************************************************/ - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_SYCL_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_SYCL_H - -namespace Eigen { - -namespace TensorSycl { -namespace internal { - -#ifndef EIGEN_SYCL_DISABLE_GEMV -/*! - * \brief TVPanelSize, a template class used for setting the panel size required for launching General TensorVector - * contraction kernel on various hardware devices. - * - * \tparam Scalar: determines the element type of the tensor/vector - * - * \tparam StorageIndex determines the Index type. - * - * \tparam NCWindow: determines the number of non-contracting element to be process by each work-group - * - * \tparam CFactor: determines the number of contracting element to be process by each thread - * - * \tparam NCFactor: determines the number of non-contracting element to be process by each thread - */ -template <typename Scalar, typename StorageIndex, StorageIndex NCWindow, StorageIndex CFactor, StorageIndex NCFactor> -struct TVPanelSize { - // LocalThreadSizeC: determines total number of thread per workgroup for the contracting dimension - static EIGEN_CONSTEXPR StorageIndex LocalThreadSizeC = EIGEN_SYCL_LOCAL_THREAD_DIM0; - // LocalThreadSizeNC: determines total number of thread per workgroup for the non-contracting dimension - static EIGEN_CONSTEXPR StorageIndex LocalThreadSizeNC = EIGEN_SYCL_LOCAL_THREAD_DIM1; - // TileSizeDimNC: determines the tile size for the non-contracting dimension - static EIGEN_CONSTEXPR StorageIndex TileSizeDimNC = NCWindow / NCFactor; - // TileSizeDimC: determines the tile size for the contracting dimension - static EIGEN_CONSTEXPR StorageIndex TileSizeDimC = CFactor * LocalThreadSizeNC * LocalThreadSizeC; - // WorkLoadPerThreadNC : determines workload per thread for loading the non-contracting dimension - static EIGEN_CONSTEXPR StorageIndex WorkLoadPerThreadNC = TileSizeDimNC / LocalThreadSizeNC; - // WorkLoadPerThreadC: determines workload per thread for loading the non-contracting dimension - static EIGEN_CONSTEXPR StorageIndex WorkLoadPerThreadC = TileSizeDimC / LocalThreadSizeC; - // BC : determines if supporting bank conflict is required - static EIGEN_CONSTEXPR bool BC = false; -}; -#endif - -/*! - * \brief TTPanelSize, a template class used for setting the panel size required for launching General Tensor Tensor - contraction kernel on various hardware devices. - * - * \tparam Scalar: determines the element type of the tensor - * - * \tparam StorageIndex: determines the Index type. - * - * \tparam REG_SIZE_M: determines workload per thread for loading the M dimension This can be varied based on the - available register on a chosen device(can be controlled by EIGEN_SYCL_REG_M macro). - * - * \tparam REG_SIZE_N: determines workload per thread for loading the N dimension This can be varied based on the - available register on a chosen device(can be controlled by EIGEN_SYCL_REG_N macro). - * - * \tparam TSDK: determines Tile size for dimension K. The packet size is assumed to be considered - */ - -template <typename Scalar, typename StorageIndex, StorageIndex REG_SIZE_M, StorageIndex REG_SIZE_N, StorageIndex TSDK> -struct TTPanelSize { - // TileSizeDimK: determines Tile size for dimension K. The packet size is assumed to be considered - static EIGEN_CONSTEXPR StorageIndex TileSizeDimK = TSDK; - // WorkLoadPerThreadM : determines workload per thread for loading the M dimension This can be varied based on the - // available register on a chosen device(can be controlled by EIGEN_SYCL_REG_M macro// -#ifndef EIGEN_SYCL_REG_M - static EIGEN_CONSTEXPR StorageIndex WorkLoadPerThreadM = REG_SIZE_M; -#else - static EIGEN_CONSTEXPR StorageIndex WorkLoadPerThreadM = EIGEN_SYCL_REG_M; -#endif -// WorkLoadPerThreadN : determines workload per thread for loading the N dimension This can be varied based on the -// available register on a chosen device(can be controlled by EIGEN_SYCL_REG_N macro -#ifndef EIGEN_SYCL_REG_N - static EIGEN_CONSTEXPR StorageIndex WorkLoadPerThreadN = REG_SIZE_N; -#else - static EIGEN_CONSTEXPR StorageIndex WorkLoadPerThreadN = EIGEN_SYCL_REG_N; -#endif - // LocalThreadSizeM: determines total number of thread per workgroup for the m dimension - static EIGEN_CONSTEXPR StorageIndex LocalThreadSizeM = EIGEN_SYCL_LOCAL_THREAD_DIM0; - // LocalThreadSizeN: determines total number of thread per workgroup for the n dimension - static EIGEN_CONSTEXPR StorageIndex LocalThreadSizeN = EIGEN_SYCL_LOCAL_THREAD_DIM1; - // TileSizeDimM: determines the tile size for the m dimension - static EIGEN_CONSTEXPR StorageIndex TileSizeDimM = LocalThreadSizeM * WorkLoadPerThreadM; - // TileSizeDimN: determines the tile size for the n dimension - static EIGEN_CONSTEXPR StorageIndex TileSizeDimN = LocalThreadSizeN * WorkLoadPerThreadN; - // LoadPerThreadLhs: determines workload per thread for loading Lhs Tensor. This must be divisable by packetsize - static EIGEN_CONSTEXPR StorageIndex LoadPerThreadLhs = - ((TileSizeDimK * WorkLoadPerThreadM * WorkLoadPerThreadN) / (TileSizeDimN)); - // LoadPerThreadRhs: determines workload per thread for loading Rhs Tensor. This must be divisable by packetsize - static EIGEN_CONSTEXPR StorageIndex LoadPerThreadRhs = - ((TileSizeDimK * WorkLoadPerThreadM * WorkLoadPerThreadN) / (TileSizeDimM)); - // BC : determines if supporting bank conflict is required - static EIGEN_CONSTEXPR bool BC = true; - // DoubleBuffer: determines if double buffering technique should be used (This can be disabled by - // EIGEN_SYCL_DISABLE_DOUBLE_BUFFER macro when the device doesnot have sufficient local memory) - static EIGEN_CONSTEXPR bool DoubleBuffer = -#ifdef EIGEN_SYCL_DISABLE_DOUBLE_BUFFER - false; -#else - true; -#endif -}; - -/* ! - * \brief contraction_type: an enum class representing the Tensor Contraction implementation algorithm. This is used to - * specialize the contraction algorithm based on device support for dedicated local memory. - */ -enum class contraction_type { local, no_local }; -/* ! - * \brief data_source an enum class determining the location of the data in a memory hierarchy (global, local, private). - */ -enum class data_source { global_mem, local_mem, private_mem }; - -/*! - * \brief read, a template function used for loading the data from global - memory. This function is used to guarantee coalesced and vectorized load whenever possible - * - * \tparam PacketLoad: determines if the each element of this tensor block should be loaded in a packet mode - * - * \param is_coalesced_layout: determines whether or not the Tensor data in a memory can be access coalesced and - vectorized when possible. Coalesced memory access is a key factor in Kernel performance. When a tensor is 2d and the - contracting dimension is 1, it is always possible to accessed tensor data coalesced and vectorized. This is the case - when RHS(right hand side) Tensor is transposed or when LHS(left hand side) Tensor is not transposed. - * - * \tparam PacketType: determines the type of packet - * - * \tparam TensorMapper: determines the input tensor mapper type - * - * \tparam StorageIndex: determines the Index type - - * \param tensorMapper: is the input tensor - * - * \param NCIndex: is the non-contracting dim index - * - * \param CIndex is the contracting dim index - * - * \param ld: is the leading dimension of the flattened tensor - */ -template <bool PacketLoad, bool is_coalesced_layout, bool, typename PacketType, typename TensorMapper, - typename StorageIndex> -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename ::Eigen::internal::enable_if<PacketLoad, PacketType>::type read( - const TensorMapper &tensorMapper, const StorageIndex &NCIndex, const StorageIndex &CIndex, const StorageIndex &ld) { - const StorageIndex row = (is_coalesced_layout) ? NCIndex : CIndex; - const StorageIndex col = (is_coalesced_layout) ? CIndex : NCIndex; - return tensorMapper.get_tensor().template packet<Unaligned>(row + (col * ld)); -} - -/*! - * \brief read, special overload of read function, when the read access is not vectorized - * - * \tparam PacketLoad: determines if the each element of this tensor block should be loaded in a packet mode - * - * \param is_coalesced_layout: determines whether or not the Tensor data in a memory can be access coalesced and - vectorized when possible. Coalesced memory access is a key factor in Kernel performance. When a tensor is 2d and the - contracting dimension is 1, it is always possible to accessed tensor data coalesced and vectorized. This is the case - when RHS(right hand side) Tensor is transposed or when LHS(left hand side) Tensor is not transposed. - * - * \tparam PacketType: determines the type of packet - * - * \tparam TensorMapper: determines the input tensor mapper type - * - * \tparam StorageIndex: determines the Index type - - * \param tensorMapper: is the input tensor - * - * \param NCIndex: is the non-contracting dim index - * - * \param CIndex: is the contracting dim index - */ -template <bool PacketLoad, bool, bool IsRhs, typename PacketType, typename TensorMapper, typename StorageIndex> -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename ::Eigen::internal::enable_if<!PacketLoad, PacketType>::type read( - const TensorMapper &tensorMapper, const StorageIndex &NCIndex, const StorageIndex &CIndex, const StorageIndex &) { - const StorageIndex row = (IsRhs) ? CIndex : NCIndex; - const StorageIndex col = (IsRhs) ? NCIndex : CIndex; - return tensorMapper(row, col); -} - -/*! - * \brief write, a template function used for storing the data to local memory. This function is used to guarantee - * coalesced and vectorized store whenever possible. - * - * \tparam StorageIndex: determines the Index type - * - * \param ld is the leading dimension of the local memory. ld is a compile time value for the local memory - * - * \tparam data_source: an enum value representing if the location of the data in a memory hierarchy. - * - * \tparam PacketType: determines the type of packet - * - * \tparam DataScalar: determines the output data type - * - * \param packet_data: the data to be written in the local memory - * - * \param ptr: a pointer to the local memory - * - * \param CIndex is the contracting dim index - */ - -template <typename StorageIndex, StorageIndex ld, data_source dt, typename PacketType, typename DataScalar> -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename ::Eigen::internal::enable_if<dt != data_source::global_mem, void>::type - write(PacketType &packet_data, DataScalar ptr) { - EIGEN_CONSTEXPR int PacketSize = Eigen::internal::unpacket_traits<PacketType>::size; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; i++) { - *ptr = PacketWrapper<PacketType, PacketSize>::scalarize(i, packet_data); - ptr += ld; - } -} - -/*! - * \brief Overloading the write function for storing the data to global memory, when vectorization enabled This function - * is used to guarantee coalesced and vectorized store whenever possible. - * - * \tparam data_source: an enum value representing if the location of the data in a memory hierarchy. - * - * \tparam PacketType: determines the type of packet - * - * \tparam DataScalar: determines the output data type - * - * \param packet_data: the data to be written in the local memory - * - * \param ptr: a pointer to the local memory - */ - -template <data_source dt, typename PacketType, typename DataScalar> -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename ::Eigen::internal::enable_if< - Eigen::internal::unpacket_traits<PacketType>::size != 1 && dt == data_source::global_mem, void>::type -write(PacketType &packet_data, DataScalar *ptr) { - ::Eigen::internal::pstoreu<DataScalar, PacketType>(ptr, packet_data); -} - -/*! - * \brief Overloading the write function for storing the data to global memory, when vectorization is disabled. - * - * \tparam data_source: an enum value representing if the location of the data in a memory hierarchy. - * - * \tparam PacketType: determines the type of packet - * - * \tparam DataScalar: determines the output data type - * - * \param packet_data: the data to be written in the local memory - * - * \param ptr: a pointer to the local memory - */ -template <data_source dt, typename PacketType, typename DataScalar> -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename ::Eigen::internal::enable_if< - Eigen::internal::unpacket_traits<PacketType>::size == 1 && dt == data_source::global_mem, void>::type -write(PacketType &packet_data, DataScalar *ptr) { - *ptr = packet_data; -} - -/*! - * \brief check_boundary: is used to check the edge condition for non-internal blocks. - * - * \tparam is_internal: determines if the block is internal - */ -template <bool is_internal> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool check_boundary(bool) { - return true; -} - -/*! - * \brief check_boundary: specialization of the check_boundary for non-internal blocks. - * - * \param cond: true when the data is in range. Otherwise false - */ -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool check_boundary<false>(bool cond) { - return cond; -} - -/*! - * \brief BlockProperties is a template class that provides different characteristic of a block of each Tensor processed - * by each workgroup. - * - * \tparam is_transposed: iff true, determines whether or not the block of the Tensor is transposed - * - * \tparam packet_load_: determines if the each element of this tensor block should be loaded in a packet mode - * - * \tparam PacketType: determines the type of packet - * - * \tparam OutType: determines the type of each element for this block of tensor. If packet load is true, it will be - * packetType; Otherwise it will be scalar Type - * - * \param elements_per_access determines the size of each element based on OutType - * - * \param is_coalesced_layout determines whether or not the Tensor data in a memory can be access coalesced and - * vectorized when possible. Coalesced memory access is a key factor in Kernel performance. When a tensor is 2d and the - * contracting dimension is 1, it is always possible to accessed tensor data coalesced and vectorized. This is the case - * when RHS(right hand side) Tensor is transposed or when LHS(left hand side) Tensor is not transposed. - * - * \param nc_stride determines the stride of non-contracting dimension to access the next adjustment element within the - * Tensor Block for each workgroup - * - * \param c_stride determines the stride of contracting dimension to access the next adjustment element within the - * Tensor Block for each workgroup - */ -template <bool is_transposed, bool is_rhs_, bool packet_load_, typename PacketType> -struct BlockProperties { - static EIGEN_CONSTEXPR bool packet_load = packet_load_; - typedef typename Eigen::internal::unpacket_traits<PacketType>::type OutScalar; - static EIGEN_CONSTEXPR bool is_rhs = is_rhs_; - typedef typename Eigen::internal::conditional<packet_load, PacketType, OutScalar>::type OutType; - static EIGEN_CONSTEXPR int elements_per_access = Eigen::internal::unpacket_traits<OutType>::size; - static EIGEN_CONSTEXPR bool is_coalesced_layout = !(is_transposed ^ is_rhs); - static EIGEN_CONSTEXPR int nc_stride = (is_coalesced_layout ? elements_per_access : 1); - static EIGEN_CONSTEXPR int c_stride = (is_coalesced_layout ? 1 : elements_per_access); -}; - -/*! - * \brief ThreadProperties is a template class that provides each thread's properties within a workgroup. Please see - * the sycl-1.2.1 specification (https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf) for the workgroup, - * work-items - * - * \tparam StorageIndex: determines the StorageIndex Type - * - * \param linearLocalThreadId: determines the linearized location of a thread within a work-group - * - * \param kGroupId: determines the logical group id in a k dimension of the flattened tensor. It will be > 1 when - * tall/skinny algorithm is used - * - * \param mGroupOffset: determines the logical start position of all thread within a workgroup for the m dimension of - * the flattened tensor. - * - * \param kGroupOffset determines the logical start position of all thread within a workgroup for the k dimension of the - * flattened tensor. It will be > 1 when tall/skinny algorithm is used. - * - * \param mLocalOffset: determines the logical start position of each thread within a workgroup for the m dimension of a - * flattened tensor. The position determines the distance of each thread within the workgroup from each other - * independent from their global position. - * - * \param nLocalOffset: determines the logical start position of each thread within a workgroup for the n dimension of a - * flattened tensor. The position determines the distance of each thread within the workgroup from each other - * independent from their global position. - * - * \param mGlobalOffset: determines the logical start position of each thread a thread for the m dimension on a - * flattened tensor - * - * \param nGlobalOffset: determines the logical start position of each thread a thread for the n dimension on a - * flattened tensor - * - * \param kSize : determine the number of the k elements of the flattened Tensor to be processed by each thread for the - * given tensor block. This is !=K dimension of Flattened Tensor when Tall/Skinny matrix is used. - * - * \param is_internal : this will determined if the thread within the work-group computes an internal block of tensor or - * the edge blocks. When it is internal, there is no need to check the boundaries and all the if stantement can be - * resolve by compiler. - */ -template <typename StorageIndex> -struct ThreadProperties { - const StorageIndex linearLocalThreadId; - const StorageIndex kGroupId; - const StorageIndex mGroupOffset; - const StorageIndex nGroupOffset; - const StorageIndex kGroupOffset; - const StorageIndex mLocalOffset; - const StorageIndex nLocalOffset; - const StorageIndex mGlobalOffset; - const StorageIndex nGlobalOffset; - StorageIndex kSize; - const bool is_internal; - // this is used to adjust the last block - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ThreadProperties( - const StorageIndex linearLocalThreadId_, const StorageIndex kGroupId_, const StorageIndex mGroupOffset_, - const StorageIndex nGroupOffset_, const StorageIndex kGroupOffset_, const StorageIndex mLocalOffset_, - const StorageIndex nLocalOffset_, const StorageIndex mGlobalOffset_, const StorageIndex nGlobalOffset_, - StorageIndex kSize_, const bool is_internal_) - : linearLocalThreadId(linearLocalThreadId_), - kGroupId(kGroupId_), - mGroupOffset(mGroupOffset_), - nGroupOffset(nGroupOffset_), - kGroupOffset(kGroupOffset_), - mLocalOffset(mLocalOffset_), - nLocalOffset(nLocalOffset_), - mGlobalOffset(mGlobalOffset_), - nGlobalOffset(nGlobalOffset_), - kSize(kSize_), - is_internal(is_internal_) {} -}; - -/*! - * \brief TensorContractionKernel is a template class that provides Tensor -Tensor contraction operation. - * - * \tparam OutScalar: determines the output scalar type - * - * \tparam LhsScalar: determines the left-hand-side scalar type - * - * \tparam RhsScalar: determines the right-hand-side scalar type - * - * \tparam OutAccessor: determines the sycl accessor type for out put (please see the sycl-1.2.1 specification - (https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf) for accessor definition) - * - * \tparam LhsMapper determines the tensor contraction mapper type for left-hand-side matrix - * - * \tparam RhsMapper determines the tensor contraction mapper type for right-hand-side matrix - * - * \tparam StorageIndex: determines the StorageIndex Type - * - * \tparam Properties: determines the Contraction Panel properties - * - * \tparam TripleDim: determines the M, K, N dimensions for the flatten tensors in order to treat them as a matrix - * - * \tparam Vectorizable: determines whether or not the vectorization is enabled for the Eigen expression. - * - * \tparam input_mapper_properties : determine if the input tensors are matrix. If they are matrix, special memory - access is used to guarantee that always the memory access are coalesced. - * - * \tptaram IsFinal : determine if this is the final kernel. If so, the result will be written in a final output. - Otherwise, the result of contraction will be written iin a temporary buffer. This is the case when Tall/Skinny - contraction is used. So in this case, a final reduction step is required to compute final output. - - * \tparam contraction_tp: it is an enum value representing whether the local memroy/no local memory implementation of - the algorithm to be used - * - * \param scratch: local memory containing tiles of LHS and RHS tensors for each work-group - * - * \param lhs: determines the left-hand-side flattened tensor (tensor mapper) - * - * \param rhs: determines the right-hand-side flattened tensor (tensor mapper) - * - * \param out_res: determines the output tensor containing the contraction result - * - * \param groupSizeM: a logical number determining the number of work-group for m dimension - * - * \param groupSizeN: a logical number determining the number of work-group for n dimension - * - * \param numTiles: determines total number of tiles on the k dimension - * - * \param TripleDim: determines the M, K, N dimensions for the flatten tensors in order to treat them as a matrix - */ -template <typename OutScalar, typename LhsScalar, typename RhsScalar, typename OutAccessor, typename LhsMapper, - typename RhsMapper, typename StorageIndex, typename Properties, typename TripleDim, bool Vectorizable, - typename input_mapper_properties, bool IsFinal, contraction_type contraction_tp> -class TensorContractionKernel { - public: - typedef typename Eigen::TensorSycl::internal::Vectorise<OutScalar, Eigen::SyclDevice, Vectorizable>::PacketReturnType - PacketReturnType; - static EIGEN_CONSTEXPR int PacketSize = - Eigen::TensorSycl::internal::Vectorise<OutScalar, Eigen::SyclDevice, Vectorizable>::PacketSize; - static EIGEN_CONSTEXPR bool is_lhs_transposed = - !::Eigen::internal::TensorContractionInputMapperTrait<LhsMapper>::inner_dim_contiguous; - static EIGEN_CONSTEXPR bool is_rhs_transposed = - !::Eigen::internal::TensorContractionInputMapperTrait<RhsMapper>::inner_dim_contiguous; - - typedef BlockProperties<is_lhs_transposed, false, input_mapper_properties::is_lhs_matrix && Vectorizable, - PacketReturnType> - LHSBlockProperties; - - typedef BlockProperties<is_rhs_transposed, true, input_mapper_properties::is_rhs_matrix && Vectorizable, - PacketReturnType> - RHSBlockProperties; - - static EIGEN_CONSTEXPR StorageIndex NStride = - contraction_tp == contraction_type::local ? Properties::WorkLoadPerThreadN : RHSBlockProperties::nc_stride; - - typedef cl::sycl::accessor<OutScalar, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> Scratch; - typedef cl::sycl::multi_ptr<OutScalar, cl::sycl::access::address_space::local_space> local_ptr; - typedef OutScalar * /*cl::sycl::multi_ptr<OutScalar, cl::sycl::access::address_space::private_space>*/ private_ptr; - typedef - typename ::Eigen::internal::conditional<contraction_tp == contraction_type::local, local_ptr, private_ptr>::type - tile_ptr; - static EIGEN_CONSTEXPR StorageIndex LSDL = contraction_tp == contraction_type::local - ? Properties::TileSizeDimM + Properties::BC - : Properties::WorkLoadPerThreadM; - static EIGEN_CONSTEXPR StorageIndex LSDR = contraction_tp == contraction_type::local - ? Properties::TileSizeDimN + Properties::BC - : Properties::WorkLoadPerThreadN; - static EIGEN_CONSTEXPR StorageIndex LocalOffset = Properties::LocalThreadSizeM * Properties::LocalThreadSizeN; - - /** - * \brief MemHolder this is a place holder struct for creating memory hierarchy in SYCL. Inside SYCL kernel it is not - * allowed to have dynamic memory allocation. While the local memory is created outside of the kernel and passed to - * the kernel as an accessor, the private memory can only allowed to be allocated statically. Since we are abstracting - * the TiledMemory for both local and private memory, the MemHolder structs is used as a helper to abstract out - * different type of memory needed when local/no_local memory computation is called. - * - * \tparam contraction_type: it is an enum value representing whether the local memroy/no local memory implementation - of the algorithm to be used - * \tparam the private memory size - * \param ptr the tile memory pointer type - */ - template <contraction_type, StorageIndex> - struct MemHolder { - tile_ptr ptr; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE MemHolder(local_ptr block_start_ptr) : ptr(block_start_ptr) {} - }; - /** - * \brief specialization of memHolder class when no local memory kernel is used. - */ - template <StorageIndex MemSize> - struct MemHolder<contraction_type::no_local, MemSize> { - OutScalar ptr[MemSize] = {OutScalar{0}}; - }; - /** - * \brief TiledMemory: contains required memory pointer for loading each tile of the TensorContraction panel from - * global memory to local/private memory when local/no_local algorithm used. - * - * \param lhs_scratch_extract : determines the LHS tile memory. It is either private or local memory based on the - * selected contraction_type. - * - * \param rhs_scratch_extract : determines the RHS tile memory. It is either private or local memory based on the - * selected contraction_type. - * - * \param lhs_extract_index: determins the position of each thread on a local memory for lhs input. When private - * memory is used this is set to zero as this is not applicable in case of private memory. - * - * \param rhs_extract_index: determins the position of each thread on a local memory for rhs input. When private - * memory is used this is set to zero as this is not applicable in case of private memory. - * - * \param lhs_scratch_compute : determines the location to load for computation for lhs_local memory. This is the - * same as lhs_scratch_extract for private memory. - * - * \param rhs_scratch_compute : determines the location to load for computation for rhs_local memory. This is the - * same as rhs_scratch_extract for private memory. - */ - struct TiledMemory { - MemHolder<contraction_tp, Properties::WorkLoadPerThreadM * Properties::TileSizeDimK> lhs_scratch_extract; - MemHolder<contraction_tp, Properties::WorkLoadPerThreadN * Properties::TileSizeDimK> rhs_scratch_extract; - tile_ptr lhs_scratch_ptr_compute; - tile_ptr rhs_scratch_ptr_compute; - const std::pair<StorageIndex, StorageIndex> lhs_extract_index; - const std::pair<StorageIndex, StorageIndex> rhs_extract_index; - template <contraction_type tp = contraction_tp> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TiledMemory(const ThreadProperties<StorageIndex> &, local_ptr, - typename ::Eigen::internal::enable_if<tp == contraction_type::no_local>::type * = 0) - : lhs_scratch_extract{}, - rhs_scratch_extract{}, - lhs_scratch_ptr_compute(lhs_scratch_extract.ptr), - rhs_scratch_ptr_compute(rhs_scratch_extract.ptr), - lhs_extract_index(std::pair<StorageIndex, StorageIndex>(StorageIndex{0}, StorageIndex{0})), - rhs_extract_index(std::pair<StorageIndex, StorageIndex>(StorageIndex{0}, StorageIndex{0})) {} - - template <contraction_type tp = contraction_tp> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TiledMemory(const ThreadProperties<StorageIndex> &thread_properties, local_ptr block_start_ptr, - typename ::Eigen::internal::enable_if<tp == contraction_type::local>::type * = 0) - : lhs_scratch_extract{block_start_ptr}, - rhs_scratch_extract{lhs_scratch_extract.ptr + - ((Properties::DoubleBuffer + 1) * LSDL * Properties::TileSizeDimK)}, - lhs_scratch_ptr_compute(lhs_scratch_extract.ptr + thread_properties.mLocalOffset), - rhs_scratch_ptr_compute(rhs_scratch_extract.ptr + thread_properties.nLocalOffset), - lhs_extract_index( - local_id_extract<LHSBlockProperties, Properties::TileSizeDimM>(thread_properties.linearLocalThreadId)), - rhs_extract_index( - local_id_extract<RHSBlockProperties, Properties::TileSizeDimN>(thread_properties.linearLocalThreadId)) {} - }; - - Scratch scratch; - const LhsMapper lhs; - const RhsMapper rhs; - OutAccessor out_res; - const StorageIndex groupSizeM; - const StorageIndex groupSizeN; - const StorageIndex numTiles; - const TripleDim triple_dim; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorContractionKernel(Scratch scratch_, const LhsMapper lhs_, - const RhsMapper rhs_, OutAccessor out_res_, - const StorageIndex groupSizeM_, - const StorageIndex groupSizeN_, - const StorageIndex numTiles_, - const TripleDim triple_dim_) - : scratch(scratch_), - lhs(lhs_), - rhs(rhs_), - out_res(out_res_), - groupSizeM(groupSizeM_), - groupSizeN(groupSizeN_), - numTiles(numTiles_), - triple_dim(triple_dim_) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorContractionKernel(Scratch scratch_, const LhsMapper lhs_, - const RhsMapper rhs_, OutAccessor out_res_, - const StorageIndex groupSizeM_, - const StorageIndex numTiles_, - const TripleDim triple_dim_) - : TensorContractionKernel(scratch_, lhs_, rhs_, out_res_, groupSizeM_, 1, numTiles_, triple_dim_) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(cl::sycl::nd_item<1> itemID) { - const StorageIndex linearLocalThreadId = itemID.get_local_id(0); - const StorageIndex nLocalThreadId = linearLocalThreadId / Properties::LocalThreadSizeM; - const StorageIndex mLocalThreadId = linearLocalThreadId % Properties::LocalThreadSizeM; - const StorageIndex mGroupId = itemID.get_group(0) % groupSizeM; - const StorageIndex tmp = itemID.get_group(0) / groupSizeM; - const StorageIndex nGroupId = IsFinal ? tmp : tmp % groupSizeN; - const StorageIndex kGroupId = IsFinal ? 0 : tmp / groupSizeN; - const StorageIndex mGroupOffset = mGroupId * Properties::TileSizeDimM; - const StorageIndex nGroupOffset = nGroupId * Properties::TileSizeDimN; - const StorageIndex mLocalOffset = PacketSize * mLocalThreadId; - const StorageIndex nLocalOffset = NStride * nLocalThreadId; - const StorageIndex mGlobalOffset = mGroupOffset + mLocalOffset; - const StorageIndex nGlobalOffset = nGroupOffset + nLocalOffset; - - const StorageIndex kSizePerWG = IsFinal ? triple_dim.K : numTiles * Properties::TileSizeDimK; - StorageIndex kGroupOffset = kGroupId * kSizePerWG; - const bool is_internal = triple_dim.M - mGroupOffset >= Properties::TileSizeDimM && - triple_dim.N - nGroupOffset >= Properties::TileSizeDimN && - triple_dim.K - kGroupOffset >= kSizePerWG; - // this is used to adjust the last block - StorageIndex kSize = IsFinal ? triple_dim.K : std::min(kSizePerWG, triple_dim.K - kGroupOffset); - // This is used to find out the lats K offset so that kGroupOffset -kSize can compute the coffset for loading to - // tile - kGroupOffset += kSize; - - auto thread_properties = - ThreadProperties<StorageIndex>(linearLocalThreadId, kGroupId, mGroupOffset, nGroupOffset, kGroupOffset, - mLocalOffset, nLocalOffset, mGlobalOffset, nGlobalOffset, kSize, is_internal); - - auto out_ptr = out_res.get_pointer() + (IsFinal ? 0 : thread_properties.kGroupId * triple_dim.M * triple_dim.N); - - (thread_properties.is_internal) ? compute_panel<true>(itemID, thread_properties, out_ptr) - : compute_panel<false>(itemID, thread_properties, out_ptr); - } - // The compute block computes the contraction operation private block for each thread and store the resutl in the - // privateRes memory of Each computation the compute block function is independent of local and no local concepts as - // it only compute the block on each thread's private memory space - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void compute_block_per_tile(OutScalar *lhs_block_ptr, OutScalar *rhs_block_ptr, - PacketReturnType *privateRes) { - StorageIndex idx = 0; - EIGEN_CONSTEXPR StorageIndex lhs_stride = - contraction_tp == contraction_type::local ? (PacketSize * Properties::LocalThreadSizeM) : 1; - EIGEN_UNROLL_LOOP - for (StorageIndex wLPTN = 0; wLPTN < Properties::WorkLoadPerThreadN; wLPTN++) { - auto rhsPacket = PacketReturnType{*(rhs_block_ptr + wLPTN)}; - StorageIndex lhs_index = 0; - EIGEN_UNROLL_LOOP - for (StorageIndex wLPTM = 0; wLPTM < Properties::WorkLoadPerThreadM / PacketSize; wLPTM++) { - PacketReturnType lhsPack{}; - Eigen::TensorSycl::internal::PacketWrapper<PacketReturnType, PacketSize>::set_packet(lhsPack, - lhs_block_ptr + lhs_index); - privateRes[idx] = ::Eigen::internal::pmadd(lhsPack, rhsPacket, privateRes[idx]); - - lhs_index += lhs_stride; - idx++; - } - } - } - // The store function write the computed contraction operation in the private memory of each thread to the global - // memory. The store function is independent of local and no local concepts s that it can be abstract out in the base - // class. - template <bool is_internal_block, StorageIndex PrivateNStride, typename OutPtr> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void store(OutPtr *out_ptr, PacketReturnType *privateRes, - StorageIndex mGlobalOffset, StorageIndex nGlobalOffset) { - auto chk_bound = [&](const StorageIndex &mIndex, const StorageIndex &nIndex) EIGEN_DEVICE_FUNC { - return (mIndex + PacketSize - 1 < triple_dim.M && nGlobalOffset + nIndex < triple_dim.N); - }; - // when local memory is not used M and N are both accessed in a coalesced way. However, when local memory is - // available the k*N is transposed in the local to N*K therefore, each blocks operates on blockId* - // WorkLoadPerThreadN slice of N - EIGEN_CONSTEXPR StorageIndex GlobalNStride = - contraction_tp == contraction_type::local ? 1 : Properties::LocalThreadSizeN; - EIGEN_UNROLL_LOOP - for (StorageIndex wLPTN = 0; wLPTN < Properties::WorkLoadPerThreadN / PrivateNStride; wLPTN++) { - // output leading dimension - StorageIndex outputLD = 0; - // When local memory is used the PrivateNstride is always 1 because the coalesed access on N is loaded into Local - // memory and extracting from local to global is the same as no transposed version. However, when local memory is - // not used and RHS is transposed we packetize the load for RHS. - EIGEN_UNROLL_LOOP - for (StorageIndex nId = 0; nId < PrivateNStride; nId++) { - StorageIndex globalRow = mGlobalOffset; - EIGEN_UNROLL_LOOP - for (StorageIndex wLPTM = 0; wLPTM < Properties::WorkLoadPerThreadM / PacketSize; wLPTM++) { - PacketReturnType privetOut = privateRes[wLPTM]; - if (check_boundary<is_internal_block>(chk_bound(globalRow, nId))) { - // Store the final results in C. The C matrix has always M as a first StorageIndex and N as a second - // StorageIndex Therefore it is always coalesced layout - write<data_source::global_mem>(privetOut, out_ptr + outputLD + globalRow); - } else { - EIGEN_UNROLL_LOOP - for (StorageIndex mId = 0; mId < PacketSize; mId++) { - StorageIndex mOffset = globalRow + mId; - if (mOffset < triple_dim.M && (nGlobalOffset + nId < triple_dim.N)) { - out_ptr[mOffset + outputLD] = - Eigen::TensorSycl::internal::PacketWrapper<PacketReturnType, PacketSize>::scalarize(mId, privetOut); - } - } - } - globalRow += (PacketSize * Properties::LocalThreadSizeM); - } - outputLD += triple_dim.M; - privateRes += Properties::WorkLoadPerThreadM / PacketSize; - } - out_ptr += (GlobalNStride * outputLD); - - nGlobalOffset += (PrivateNStride * GlobalNStride); - } - } - // when no local memory is used the following extract_block will be enabled - template <typename InputBlockProperties, bool is_internal_block, typename Input, typename PrivateReg, - contraction_type contract_tp = contraction_tp> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename ::Eigen::internal::enable_if<contract_tp == contraction_type::no_local>::type - extract_block(const Input &inpt, PrivateReg private_ptr, const std::pair<StorageIndex, StorageIndex> &, - const StorageIndex &ncOffset, const StorageIndex cOffset) { - EIGEN_CONSTEXPR StorageIndex LocalThreadSizeNC = - InputBlockProperties::is_rhs ? Properties::LocalThreadSizeN : Properties::LocalThreadSizeM; - EIGEN_CONSTEXPR StorageIndex WorkLoadPerThreadNC = - InputBlockProperties::is_rhs ? Properties::WorkLoadPerThreadN : Properties::WorkLoadPerThreadM; - const StorageIndex &NC = InputBlockProperties::is_rhs ? triple_dim.N : triple_dim.M; - - auto chk_bound = [&](const StorageIndex &CIndex, const StorageIndex &NCIndex) EIGEN_DEVICE_FUNC { - return ((CIndex + InputBlockProperties::c_stride - 1 < triple_dim.K) && - (NCIndex + InputBlockProperties::nc_stride - 1 < NC)); - }; - const StorageIndex ld = InputBlockProperties::is_coalesced_layout ? NC : triple_dim.K; - StorageIndex cIndex = cOffset; - - EIGEN_UNROLL_LOOP - for (StorageIndex cId = 0; cId < Properties::TileSizeDimK / InputBlockProperties::c_stride; cId++) { - StorageIndex ncIndex = ncOffset; - EIGEN_UNROLL_LOOP - for (StorageIndex ncId = 0; ncId < WorkLoadPerThreadNC / InputBlockProperties::nc_stride; ncId++) { - if (check_boundary<is_internal_block>(chk_bound(cIndex, ncIndex))) { - auto val = - read<InputBlockProperties::packet_load, InputBlockProperties::is_coalesced_layout, - InputBlockProperties::is_rhs, typename InputBlockProperties::OutType>(inpt, ncIndex, cIndex, ld); - - write<StorageIndex, (InputBlockProperties::is_coalesced_layout ? 1 : WorkLoadPerThreadNC), - data_source::private_mem>(val, private_ptr); - } else { - EIGEN_UNROLL_LOOP - for (StorageIndex i = 0; i < InputBlockProperties::elements_per_access; i++) { - const StorageIndex ncInd = ncIndex + (InputBlockProperties::is_coalesced_layout ? i : 0); - const StorageIndex cInd = cIndex + (InputBlockProperties::is_coalesced_layout ? 0 : i); - OutScalar val = - (ncInd < NC && cInd < triple_dim.K) - ? read<false, InputBlockProperties::is_coalesced_layout, InputBlockProperties::is_rhs, OutScalar>( - inpt, ncInd, cInd, ld) - : OutScalar(0); - write<StorageIndex, (InputBlockProperties::is_coalesced_layout ? 1 : WorkLoadPerThreadNC), - data_source::private_mem>( - val, private_ptr + (InputBlockProperties::is_coalesced_layout ? i : 0) + - ((InputBlockProperties::is_coalesced_layout ? 0 : i) * WorkLoadPerThreadNC)); - } - } - - // if it is lhs we have to load it packetised when the packet size is > 1, because the output is coalesced. So - // even if M is not accessed in a coalesced mode, we have to load packet_size number of m per thread. - ncIndex = (!InputBlockProperties::is_rhs && InputBlockProperties::nc_stride == 1 && PacketSize != 1) - ? ncOffset + (ncId + 1) % PacketSize + ((ncId + 1) / PacketSize) * LocalThreadSizeNC - : (ncIndex + InputBlockProperties::nc_stride * LocalThreadSizeNC); - private_ptr += InputBlockProperties::nc_stride; - } - // the previous for loop ( private_ptr += (ncId * nc_stride)) has already moved ptr with one WorkLoadPerThreadNC - private_ptr += (InputBlockProperties::c_stride - 1) * WorkLoadPerThreadNC; - cIndex += InputBlockProperties::c_stride; - } - } - template <typename InputBlockProperties, StorageIndex TileSizeDimNC> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::pair<StorageIndex, StorageIndex> local_id_extract( - const StorageIndex &linearLocalThreadId) { - const StorageIndex localThreadNC = - (InputBlockProperties::is_coalesced_layout) - ? linearLocalThreadId % (TileSizeDimNC / InputBlockProperties::nc_stride) - : linearLocalThreadId / (Properties::TileSizeDimK / InputBlockProperties::c_stride); - const StorageIndex localThreadC = - (InputBlockProperties::is_coalesced_layout) - ? linearLocalThreadId / (TileSizeDimNC / InputBlockProperties::nc_stride) - : linearLocalThreadId % (Properties::TileSizeDimK / InputBlockProperties::c_stride); - return std::pair<StorageIndex, StorageIndex>(localThreadNC, localThreadC); - } - - template <bool db = Properties::DoubleBuffer, contraction_type ctp = contraction_tp> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename ::Eigen::internal::enable_if<db && ctp == contraction_type::local>::type - sync_mem(const cl::sycl::nd_item<1> &, bool &db_offset) noexcept { - db_offset = !db_offset; - } - - template <bool db = Properties::DoubleBuffer, contraction_type ctp = contraction_tp> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename ::Eigen::internal::enable_if<!db && ctp == contraction_type::local>::type - sync_mem(const cl::sycl::nd_item<1> &itemID, bool &) noexcept { - itemID.barrier(cl::sycl::access::fence_space::local_space); - } - - template <contraction_type ctp = contraction_tp> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename ::Eigen::internal::enable_if<ctp == contraction_type::no_local>::type - sync_mem(const cl::sycl::nd_item<1> &, bool &) noexcept { - return; - } - - template <bool need_sync, contraction_type ctp = contraction_tp> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename ::Eigen::internal::enable_if<need_sync && ctp == contraction_type::no_local>::type - sync_thread(const cl::sycl::nd_item<1> & -#ifdef EIGEN_SYCL_ARM_GPU_CACHE_OPTIMISATION - itemID -#endif - ) noexcept { -#ifdef EIGEN_SYCL_ARM_GPU_CACHE_OPTIMISATION - itemID.barrier(cl::sycl::access::fence_spacce::local_space); -#else - return; -#endif - } - template <bool need_sync, contraction_type ctp = contraction_tp> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename ::Eigen::internal::enable_if<need_sync && ctp == contraction_type::local>::type - sync_thread(const cl::sycl::nd_item<1> &itemID) { - itemID.barrier(cl::sycl::access::fence_space::local_space); - } - template <bool need_sync> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename ::Eigen::internal::enable_if<!need_sync>::type sync_thread( - const cl::sycl::nd_item<1> &) { - return; - } - - template <bool is_internal_block> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void compute_tile_per_panel(const cl::sycl::nd_item<1> &itemID, - ThreadProperties<StorageIndex> &thread_properties, - TiledMemory &tiled_input_block, - PacketReturnType *privateRes, bool &db_offset) { - // Tiling the Rhs block from global to local memory - extract_block<RHSBlockProperties, is_internal_block>( - rhs, tiled_input_block.rhs_scratch_extract.ptr + (db_offset * Properties::TileSizeDimK * LSDR), - tiled_input_block.rhs_extract_index, - contraction_tp == contraction_type::local ? thread_properties.nGroupOffset : thread_properties.nGlobalOffset, - thread_properties.kGroupOffset - thread_properties.kSize); - - sync_thread<contraction_tp == contraction_type::no_local>(itemID); - - // Tiling the Lhs block from global to local memory - extract_block<LHSBlockProperties, is_internal_block>( - lhs, tiled_input_block.lhs_scratch_extract.ptr + (db_offset * LSDL * Properties::TileSizeDimK), - tiled_input_block.lhs_extract_index, - contraction_tp == contraction_type::local ? thread_properties.mGroupOffset : thread_properties.mGlobalOffset, - thread_properties.kGroupOffset - thread_properties.kSize); - - // itemID.barrier(cl::sycl::access::fence_space::local_space); - sync_thread<contraction_tp == contraction_type::local>(itemID); - // switch to compute mede - StorageIndex lhs_offset = (db_offset * LSDL * Properties::TileSizeDimK); - StorageIndex rhs_offset = (db_offset * Properties::TileSizeDimK * LSDR); - // Loop over the values of a single tile - for (StorageIndex k = 0; k < Properties::TileSizeDimK; k++) { - compute_block_per_tile(tiled_input_block.lhs_scratch_ptr_compute + lhs_offset, - tiled_input_block.rhs_scratch_ptr_compute + rhs_offset, privateRes); - lhs_offset += LSDL; - rhs_offset += LSDR; - } - // computing the K index for the next tile - thread_properties.kSize -= Properties::TileSizeDimK; - sync_mem(itemID, db_offset); - } - - // when local memory is available the following compute_panel will be enabled - template <bool is_internal_block, typename OutPtr> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void compute_panel(const cl::sycl::nd_item<1> &itemID, - ThreadProperties<StorageIndex> &thread_properties, - OutPtr out_ptr) { - auto tiled_input_block = TiledMemory{thread_properties, scratch.get_pointer()}; - // Allocate register space - PacketReturnType privateRes[Properties::WorkLoadPerThreadM * Properties::WorkLoadPerThreadN / PacketSize] = { - PacketReturnType{0}}; - bool db_offset = 0; - - while (thread_properties.kSize >= Properties::TileSizeDimK) { - compute_tile_per_panel<is_internal_block>(itemID, thread_properties, tiled_input_block, privateRes, db_offset); - } - if (thread_properties.kSize > 0) { - compute_tile_per_panel<false>(itemID, thread_properties, tiled_input_block, privateRes, db_offset); - } - - // Storing the final results in the output - store<is_internal_block, - contraction_tp == contraction_type::local ? static_cast<StorageIndex>(1) : RHSBlockProperties::nc_stride>( - out_ptr + thread_properties.nGlobalOffset * triple_dim.M, privateRes, thread_properties.mGlobalOffset, - thread_properties.nGlobalOffset); - } - // When local memory is available the following extract_block will be enabled - template <typename InputBlockProperties, bool is_internal_block, typename Input, typename Local, - contraction_type contract_tp = contraction_tp> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename ::Eigen::internal::enable_if<contract_tp == contraction_type::local>::type - extract_block(const Input &inpt, Local local_ptr, const std::pair<StorageIndex, StorageIndex>& local_index, - const StorageIndex &ncOffset, const StorageIndex cOffset) { - EIGEN_CONSTEXPR StorageIndex TileSizeDimNC = - InputBlockProperties::is_rhs ? Properties::TileSizeDimN : Properties::TileSizeDimM; - EIGEN_CONSTEXPR StorageIndex LoadPerThread = - InputBlockProperties::is_rhs ? Properties::LoadPerThreadRhs : Properties::LoadPerThreadLhs; - EIGEN_CONSTEXPR StorageIndex LSD = InputBlockProperties::is_rhs ? LSDR : LSDL; - static_assert(((LocalOffset % (TileSizeDimNC / InputBlockProperties::nc_stride) == 0) && - (LocalOffset % (Properties::TileSizeDimK / InputBlockProperties::c_stride) == 0)), - " LocalOffset must be divisable by stride"); - const StorageIndex &NC = InputBlockProperties::is_rhs ? triple_dim.N : triple_dim.M; - StorageIndex localThreadNC = local_index.first; - StorageIndex localThreadC = local_index.second; - auto chk_bound = [&](const StorageIndex &CIndex, const StorageIndex &NCIndex) EIGEN_DEVICE_FUNC { - return ((CIndex + InputBlockProperties::c_stride - 1 < triple_dim.K) && - (NCIndex + InputBlockProperties::nc_stride - 1 < NC)); - }; - EIGEN_UNROLL_LOOP - for (StorageIndex lPT = 0; lPT < LoadPerThread / InputBlockProperties::elements_per_access; lPT++) { - const StorageIndex CIndex = cOffset + (InputBlockProperties::c_stride * localThreadC); - const StorageIndex NCIndex = ncOffset + (InputBlockProperties::nc_stride * localThreadNC); - const StorageIndex ld = InputBlockProperties::is_coalesced_layout ? NC : triple_dim.K; - if (check_boundary<is_internal_block>(chk_bound(CIndex, NCIndex))) { - auto val = - read<InputBlockProperties::packet_load, InputBlockProperties::is_coalesced_layout, - InputBlockProperties::is_rhs, typename InputBlockProperties::OutType>(inpt, NCIndex, CIndex, ld); - write<StorageIndex, (InputBlockProperties::is_coalesced_layout ? 1 : LSD), data_source::local_mem>( - val, local_ptr + (InputBlockProperties::nc_stride * localThreadNC) + - (InputBlockProperties::c_stride * localThreadC * LSD)); - } else { - EIGEN_UNROLL_LOOP - for (StorageIndex i = 0; i < InputBlockProperties::elements_per_access; i++) { - const StorageIndex nCInd = NCIndex + (InputBlockProperties::is_coalesced_layout ? i : 0); - const StorageIndex cInd = CIndex + (InputBlockProperties::is_coalesced_layout ? 0 : i); - OutScalar val = - (nCInd < NC && cInd < triple_dim.K) - ? read<false, InputBlockProperties::is_coalesced_layout, InputBlockProperties::is_rhs, OutScalar>( - inpt, nCInd, cInd, ld) - : OutScalar(0); - - write<StorageIndex, (InputBlockProperties::is_coalesced_layout ? 1 : LSD), data_source::local_mem>( - val, local_ptr + (InputBlockProperties::nc_stride * localThreadNC) + - (InputBlockProperties::is_coalesced_layout ? i : 0) + - ((InputBlockProperties::c_stride * localThreadC + - (InputBlockProperties::is_coalesced_layout ? 0 : i)) * - LSD)); - } - } - localThreadNC += (InputBlockProperties::is_coalesced_layout) - ? LocalOffset % (TileSizeDimNC / InputBlockProperties::nc_stride) - : LocalOffset / (Properties::TileSizeDimK / InputBlockProperties::c_stride); - localThreadC += (InputBlockProperties::is_coalesced_layout) - ? LocalOffset / (TileSizeDimNC / InputBlockProperties::nc_stride) - : LocalOffset % (Properties::TileSizeDimK / InputBlockProperties::c_stride); - } - } -}; - -#ifndef EIGEN_SYCL_DISABLE_GEMV - -/*! - * \brief GeneralVectorTensor is a template class that provides Tensor -vector contraction operation, which is a special - * case of Tensor Tensor contraction. - * - * \tparam OutScalar: determines the output scalar type - * - * \tparam OutAccessor: determines the sycl accessor type for out put (please see the sycl-1.2.1 specification - * (https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf) for accessor definition) - * - * \tparam VectorMapper: determines the tensor contraction mapper for the vector input (can be lhs or rhs) - * - * \tparam TensorMapper: determines the tensor contraction mapper for the tensor input (can be lhs or rhs) - * - * \tparam StorageIndex: determines the StorageIndex Type - * - * \tparam Properties: determines the Contraction Panel properties - * - * \tparam KFactor: determines the number of elements in K dimension in a Tile - * - * \tparam Vectorizable: determines whether or not the vectorization is enabled for the Eigen expression. - * - * \tparam is_lhs_vec: determines whether lhs is a vector or rhs is a vector - * - * \tparam IsFinal: determine if this is the final kernel. If so, the result will be written in a final output. - * Otherwise, the result of contraction will be written iin a temporary buffer. - * - * \param scratch: determines the local memory containing the vector block for each work-group - * - * \param vec: determines the vector input (tensor mapper) - * - * \param mat: determines the tensor input (tensor mapper) - * - * \param out_res: determines the output vector containing the contraction result - * - * \param nonContractGroupSize: a logical number determining the number of work-group for non-contracting dimension - * - * \param nonContractDim: determines the size of non contracting dimension for the flattened tensor - * - * \param contractDim: determines the size of non contracting dimension for the flattened tensor - * - */ -template <typename OutScalar, typename OutAccessor, typename VectorMapper, typename TensorMapper, typename StorageIndex, - typename Properties, StorageIndex KFactor, bool Vectorizable, bool is_lhs_vec, bool IsFinal> -struct GeneralVectorTensor { - typedef typename Eigen::TensorSycl::internal::Vectorise<OutScalar, Eigen::SyclDevice, Vectorizable>::PacketReturnType - PacketReturnType; - static EIGEN_CONSTEXPR int PacketSize = - Eigen::TensorSycl::internal::Vectorise<OutScalar, Eigen::SyclDevice, Vectorizable>::PacketSize; - typedef cl::sycl::accessor<OutScalar, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> Scratch; - - static EIGEN_CONSTEXPR StorageIndex OutScratchOffset = - KFactor * Properties::LocalThreadSizeC * Properties::LocalThreadSizeNC; - - // Since the access layout for a vector can always be coalesced, when LHS is a vector, we pass false and false to make - // sure that the !^ is true When RHS is a vector, we pass true and true to make sure that the !^ is true. - typedef BlockProperties<is_lhs_vec ? false : true, is_lhs_vec ? false : true, Vectorizable, PacketReturnType> - VecBlockProperties; - - Scratch scratch; - const VectorMapper vec; - const TensorMapper mat; - OutAccessor out_res; - const StorageIndex nonContractGroupSize; - const StorageIndex nonContractDim; - const StorageIndex contractDim; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE GeneralVectorTensor(Scratch scratch_, const VectorMapper vec_, - const TensorMapper mat_, OutAccessor out_res_, - const StorageIndex nonContractGroupSize_, - const StorageIndex nonContractDim_, - const StorageIndex contractDim_) - : scratch(scratch_), - vec(vec_), - mat(mat_), - out_res(out_res_), - nonContractGroupSize(nonContractGroupSize_), - nonContractDim(nonContractDim_), - contractDim(contractDim_) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(cl::sycl::nd_item<1> itemID) { - auto scratch_ptr = scratch.get_pointer(); - const StorageIndex linearLocalThreadId = itemID.get_local_id(0); - StorageIndex nonContractId = is_lhs_vec ? linearLocalThreadId / Properties::LocalThreadSizeC - : linearLocalThreadId % Properties::LocalThreadSizeNC; - StorageIndex contractId = is_lhs_vec ? linearLocalThreadId % Properties::LocalThreadSizeC - : linearLocalThreadId / Properties::LocalThreadSizeNC; - const StorageIndex cGroupSize = itemID.get_group_range(0) / nonContractGroupSize; - const StorageIndex nonContractGroupId = - is_lhs_vec ? itemID.get_group(0) / cGroupSize : itemID.get_group(0) % nonContractGroupSize; - const StorageIndex contractGroupId = - is_lhs_vec ? itemID.get_group(0) % cGroupSize : itemID.get_group(0) / nonContractGroupSize; - auto out_ptr = out_res.get_pointer() + (IsFinal ? 0 : contractGroupId * nonContractDim); - - const StorageIndex nonContractGroupOffset = nonContractGroupId * Properties::TileSizeDimNC; - const StorageIndex contractGroupOffset = contractGroupId * Properties::TileSizeDimC; - auto outScratchIndex = nonContractId + contractId * Properties::LocalThreadSizeNC; - const StorageIndex globalNonContractDimOffset = nonContractGroupOffset + nonContractId; - const StorageIndex globalContractDimOffset = contractGroupOffset + contractId; - auto local_output = scratch_ptr + OutScratchOffset; - const bool is_internal = nonContractDim - nonContractGroupOffset >= Properties::TileSizeDimNC && - contractDim - contractGroupOffset >= Properties::TileSizeDimC; - is_internal - ? compute_panel<true>(itemID, vec, mat, local_output, out_ptr, -#ifdef EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON - scratch_ptr, contractGroupOffset, -#endif - nonContractGroupOffset, linearLocalThreadId, contractDim, nonContractDim, contractId, - nonContractId, globalContractDimOffset, globalNonContractDimOffset, outScratchIndex) - : compute_panel<false>(itemID, vec, mat, local_output, out_ptr, -#ifdef EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON - scratch_ptr, contractGroupOffset, -#endif - nonContractGroupOffset, linearLocalThreadId, contractDim, nonContractDim, contractId, - nonContractId, globalContractDimOffset, globalNonContractDimOffset, outScratchIndex); - } - template <bool is_internal_block, typename OutPtr> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void compute_panel( - const cl::sycl::nd_item<1> &itemID, const VectorMapper &vec, const TensorMapper &mat, OutScalar *local_output, - OutPtr out_ptr, -#ifdef EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON - OutScalar *scratch_ptr, const StorageIndex contractGroupOffset, -#endif - const StorageIndex nonContractGroupOffset, const StorageIndex linearLocalThreadId, StorageIndex contractDim, - StorageIndex nonContractDim, StorageIndex contractId, StorageIndex nonContractId, - StorageIndex globalContractDimOffset, StorageIndex globalNonContractDimOffset, StorageIndex outScratchIndex) { - OutScalar outScalar[Properties::WorkLoadPerThreadNC] = {OutScalar(0)}; - // Reading the vector -#ifdef EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON - const StorageIndex vectorOffset = contractGroupOffset + linearLocalThreadId; - extract_block<VecBlockProperties, is_internal_block, KFactor, - Properties::LocalThreadSizeNC * Properties::LocalThreadSizeC>(vec, scratch_ptr, linearLocalThreadId, - vectorOffset, contractDim); - - itemID.barrier(cl::sycl::access::fence_space::local_space); - auto in_scratch_ptr = scratch_ptr + contractId; -#endif - - StorageIndex privateOffsetC = 0; - EIGEN_UNROLL_LOOP - for (StorageIndex i = 0; i < Properties::WorkLoadPerThreadC; i++) { - StorageIndex privateOffsetNC = 0; - bool contract_conds = ((globalContractDimOffset + privateOffsetC) < contractDim); -#ifdef EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON - auto vecScalar = *in_scratch_ptr; -#else - auto vecScalar = (check_boundary<is_internal_block>(contract_conds)) - ? vec(is_lhs_vec ? StorageIndex(0) : globalContractDimOffset + privateOffsetC, - is_lhs_vec ? globalContractDimOffset + privateOffsetC : StorageIndex(0)) - : OutScalar(0); -#endif - EIGEN_UNROLL_LOOP - for (StorageIndex j = 0; j < Properties::WorkLoadPerThreadNC; j++) { - auto matScalar = (check_boundary<is_internal_block>( - contract_conds && ((globalNonContractDimOffset + privateOffsetNC) < nonContractDim))) - ? mat(is_lhs_vec ? globalContractDimOffset + privateOffsetC - : globalNonContractDimOffset + privateOffsetNC, - is_lhs_vec ? globalNonContractDimOffset + privateOffsetNC - : globalContractDimOffset + privateOffsetC) - : OutScalar(0); - - outScalar[j] = cl::sycl::mad(matScalar, vecScalar, outScalar[j]); - privateOffsetNC += Properties::LocalThreadSizeNC; - } - privateOffsetC += Properties::LocalThreadSizeC; -#ifdef EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON - in_scratch_ptr += Properties::LocalThreadSizeC; -#endif - } - - auto out_scratch_ptr = local_output + outScratchIndex; - // Each block of 16*16 element in shared memory should reduce to 16*1 - EIGEN_UNROLL_LOOP - for (StorageIndex j = 0; j < Properties::WorkLoadPerThreadNC; j++) { - *out_scratch_ptr = outScalar[j]; - - out_scratch_ptr += (Properties::LocalThreadSizeNC * Properties::LocalThreadSizeC); - } - if (is_lhs_vec) { - nonContractId = linearLocalThreadId % Properties::LocalThreadSizeNC; - contractId = linearLocalThreadId / Properties::LocalThreadSizeNC; - outScratchIndex = nonContractId + contractId * Properties::LocalThreadSizeNC; - } - - out_scratch_ptr = local_output + outScratchIndex; - EIGEN_UNROLL_LOOP - for (StorageIndex j = 0; j < Properties::WorkLoadPerThreadNC; j++) { - EIGEN_UNROLL_LOOP - for (StorageIndex offset = Properties::LocalThreadSizeC >> 1; offset > 0; offset >>= 1) { - itemID.barrier(cl::sycl::access::fence_space::local_space); - if (contractId < offset) { - StorageIndex myNeigbourId = (Properties::LocalThreadSizeNC * offset); - *out_scratch_ptr += out_scratch_ptr[myNeigbourId]; - } - } - // moving to next 16 by 16 block - out_scratch_ptr += (Properties::LocalThreadSizeNC * Properties::LocalThreadSizeC); - } - - if (contractId == 0) { - out_scratch_ptr = local_output + nonContractId; - StorageIndex global_final_offset = nonContractGroupOffset + nonContractId; - out_ptr += global_final_offset; - EIGEN_UNROLL_LOOP - for (StorageIndex j = 0; j < Properties::WorkLoadPerThreadNC; j++) { - if (check_boundary<is_internal_block>(global_final_offset < nonContractDim)) { - auto res = *out_scratch_ptr; - - *out_ptr = res; - out_ptr += Properties::LocalThreadSizeNC; - } - // moving to next 16 by 16 block to ge the next 16 reduced elements - out_scratch_ptr += (Properties::LocalThreadSizeNC * Properties::LocalThreadSizeC); - if (!(is_internal_block)) global_final_offset += Properties::LocalThreadSizeNC; - } - } - } - - template <typename InputBlockProperties, bool is_internal_block, int CFactor, int GroupSize, typename Input, - typename Local> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void extract_block(const Input &inpt, Local *local_ptr, - const StorageIndex &linearLocalThreadId, - const StorageIndex &cOffset, const StorageIndex &C) { - local_ptr += InputBlockProperties::c_stride * linearLocalThreadId; - StorageIndex cIndex = cOffset; - for (StorageIndex cId = 0; cId < CFactor / InputBlockProperties::c_stride; cId++) { - if (check_boundary<is_internal_block>(cIndex + InputBlockProperties::c_stride - 1 < C)) { - auto val = read<InputBlockProperties::packet_load, InputBlockProperties::is_coalesced_layout, - InputBlockProperties::is_rhs, typename InputBlockProperties::OutType>(inpt, StorageIndex(0), - cIndex, StorageIndex(1)); - write<StorageIndex, 1, data_source::local_mem>(val, local_ptr); - } else { - EIGEN_UNROLL_LOOP - for (StorageIndex i = 0; i < InputBlockProperties::elements_per_access; i++) { - OutScalar val = - (cIndex + i < C) - ? read<false, InputBlockProperties::is_coalesced_layout, InputBlockProperties::is_rhs, OutScalar>( - inpt, StorageIndex(0), cIndex + i, StorageIndex(1)) - : OutScalar(0); - write<StorageIndex, 1, data_source::local_mem>(val, local_ptr + i); - } - } - local_ptr += InputBlockProperties::c_stride * GroupSize; - cIndex += InputBlockProperties::c_stride * GroupSize; - } - } -}; -#endif - -#ifndef EIGEN_SYCL_DISABLE_SCALAR - -/*! - * \brief GeneralScalarContraction is a template class that provides the scalar value of Tensor -Tensor contraction - * operation, when all the dimensions are contracting dimensions. This Kernel reduces two tensors to an scalar - * - * \tparam OutScalar: determines the output scalar type - * - * \tparam LhsScalar: determines the left-hand-side scalar type - * - * \tparam RhsScalar: determines the right-hand-side scalar type - * - * \tparam OutAccessor: determines the sycl accessor type for out put (please see the sycl-1.2.1 specification - * (https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf) for accessor definition) - * - * \tparam LhsMapper: determines the tensor contraction mapper type for left-hand-side matrix - * - * \tparam RhsMapper: determines the tensor contraction mapper type for right-hand-side matrix - * - * \tparam StorageIndex: determines the StorageIndex Type - * - * \tparam Vectorizable: determines whether or not the vectorization is enabled for the Eigen expression. - * - * \param scratch: local memory containing tiles of LHS and RHS tensors for each work-group - * - * \param lhs: determines the left-hand-side flattened tensor (tensor mapper) - * - * \param rhs: determines the right-hand-side flattened tensor (tensor mapper) - * - * \param out_res: determines the output tensor containing the contraction result - * - * \param rng: determins the total input data size - */ -template <typename OutScalar, typename LhsScalar, typename RhsScalar, typename OutAccessor, typename LhsMapper, - typename RhsMapper, typename StorageIndex, bool Vectorizable> -struct GeneralScalarContraction { - typedef cl::sycl::accessor<OutScalar, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> Scratch; - Scratch scratch; - const LhsMapper lhs; - const RhsMapper rhs; - OutAccessor out_res; - const StorageIndex rng; - - EIGEN_DEVICE_FUNC - GeneralScalarContraction(Scratch scratch_, const LhsMapper lhs_, const RhsMapper rhs_, OutAccessor out_res_, - const StorageIndex rng_) - : scratch(scratch_), lhs(lhs_), rhs(rhs_), out_res(out_res_), rng(rng_) {} - - EIGEN_DEVICE_FUNC void operator()(cl::sycl::nd_item<1> itemID) { - auto out_ptr = out_res.get_pointer(); - auto scratch_ptr = scratch.get_pointer().get(); - - StorageIndex globalid = itemID.get_global_id(0); - StorageIndex localid = itemID.get_local_id(0); - OutScalar accumulator = OutScalar(0); - for (StorageIndex i = globalid; i < rng; i += itemID.get_global_range(0)) { - accumulator = cl::sycl::mad(lhs(0, i), rhs(i, 0), accumulator); - } - auto out_scratch_ptr = scratch_ptr + localid; - *out_scratch_ptr = accumulator; - for (StorageIndex offset = itemID.get_local_range(0) >> 1; offset > 0; offset >>= 1) { - itemID.barrier(cl::sycl::access::fence_space::local_space); - if (localid < offset) { - *out_scratch_ptr = (accumulator += out_scratch_ptr[offset]); - } - } - if (localid == 0) { - out_ptr[itemID.get_group(0)] = accumulator; - } - } -}; -#endif - -} // namespace internal -} // namespace TensorSycl - -template <typename Indices, typename LeftArgType, typename RightArgType, typename OutputKernelType> -struct TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, - Eigen::SyclDevice> - : public TensorContractionEvaluatorBase<TensorEvaluator< - const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, Eigen::SyclDevice>> { - static_assert(std::is_same<OutputKernelType, const NoOpOutputKernel>::value, - "SYCL tensor contraction does not support output kernels."); - - typedef Eigen::SyclDevice Device; - - typedef TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, Device> Self; - typedef TensorContractionEvaluatorBase<Self> Base; - typedef TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType> XprType; - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef typename XprType::Index StorageIndex; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef typename Base::Storage Storage; - typedef typename Base::EvaluatorPointerType EvaluatorPointerType; - struct TripleDim { - const StorageIndex M; - const StorageIndex N; - const StorageIndex K; - TripleDim(const StorageIndex M_, const StorageIndex N_, const StorageIndex K_) : M(M_), N(N_), K(K_) {} - }; - enum { - Layout = TensorEvaluator<LeftArgType, Device>::Layout, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = false, - }; - - static EIGEN_CONSTEXPR int LDims = Base::LDims; - static EIGEN_CONSTEXPR int RDims = Base::RDims; - static EIGEN_CONSTEXPR int ContractDims = Base::ContractDims; - - typedef array<StorageIndex, LDims> left_dim_mapper_t; - typedef array<StorageIndex, RDims> right_dim_mapper_t; - - typedef array<StorageIndex, ContractDims> contract_t; - typedef array<StorageIndex, LDims - ContractDims> left_nocontract_t; - typedef array<StorageIndex, RDims - ContractDims> right_nocontract_t; - - static const int NumDims = LDims + RDims - 2 * ContractDims; - - typedef DSizes<StorageIndex, NumDims> Dimensions; - - typedef TensorEvaluator<typename Base::EvalLeftArgType, Device> LeftEvaluator; - typedef TensorEvaluator<typename Base::EvalRightArgType, Device> RightEvaluator; - typedef typename Eigen::internal::remove_const<typename LeftEvaluator::CoeffReturnType>::type LhsScalar; - typedef typename Eigen::internal::remove_const<typename RightEvaluator::CoeffReturnType>::type RhsScalar; - - typedef typename LeftEvaluator::Dimensions LeftDimensions; - typedef typename RightEvaluator::Dimensions RightDimensions; - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered> - struct input_mapper_propertis { - static EIGEN_CONSTEXPR bool is_lhs_matrix = (LDims == 2 && ContractDims == 1) || lhs_inner_dim_contiguous; - static EIGEN_CONSTEXPR bool is_rhs_matrix = - (RDims == 2 && ContractDims == 1) || (rhs_inner_dim_contiguous && !rhs_inner_dim_reordered); - }; - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType &op, const Device &device) : Base(op, device) {} - - // We need to redefine this method to make nvcc happy - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(typename Base::EvaluatorPointerType data) { - this->m_leftImpl.evalSubExprsIfNeeded(NULL); - this->m_rightImpl.evalSubExprsIfNeeded(NULL); - if (!data) { - this->m_result = this->m_device.get( - static_cast<Scalar *>(this->m_device.allocate_temp(this->dimensions().TotalSize() * sizeof(Scalar)))); - data = this->m_result; - } - evalToSycl(data); - return (this->m_result != NULL); - } - const Eigen::SyclDevice &device() const { return this->m_device; } - void evalToSycl(typename Base::EvaluatorPointerType buffer) const { - if (this->m_lhs_inner_dim_contiguous) { - if (this->m_rhs_inner_dim_contiguous) { - if (this->m_rhs_inner_dim_reordered) { - evalTyped<true, true, true, Unaligned>(buffer); - } else { - evalTyped<true, true, false, Unaligned>(buffer); - } - } else { - if (this->m_rhs_inner_dim_reordered) { - evalTyped<true, false, true, Unaligned>(buffer); - } else { - evalTyped<true, false, false, Unaligned>(buffer); - } - } - } else { - if (this->m_rhs_inner_dim_contiguous) { - if (this->m_rhs_inner_dim_reordered) { - evalTyped<false, true, true, Unaligned>(buffer); - } else { - evalTyped<false, true, false, Unaligned>(buffer); - } - } else { - if (this->m_rhs_inner_dim_reordered) { - evalTyped<false, false, true, Unaligned>(buffer); - } else { - evalTyped<false, false, false, Unaligned>(buffer); - } - } - } - } - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment> - void evalTyped(typename Base::EvaluatorPointerType buffer) const { - const auto triple_dim = TripleDim{this->m_i_size, this->m_j_size, this->m_k_size}; - typedef internal::TensorContractionInputMapper< - LhsScalar, StorageIndex, internal::Lhs, LeftEvaluator, left_nocontract_t, contract_t, - PacketType<CoeffReturnType, Device>::size, lhs_inner_dim_contiguous, false, Unaligned, MakeSYCLPointer> - LhsMapper; - - typedef internal::TensorContractionInputMapper<RhsScalar, StorageIndex, internal::Rhs, RightEvaluator, - right_nocontract_t, contract_t, - PacketType<CoeffReturnType, Device>::size, rhs_inner_dim_contiguous, - rhs_inner_dim_reordered, Unaligned, MakeSYCLPointer> - RhsMapper; - - // initialize data mappers - LhsMapper lhs(this->m_leftImpl, this->m_left_nocontract_strides, this->m_i_strides, - this->m_left_contracting_strides, this->m_k_strides); - - RhsMapper rhs(this->m_rightImpl, this->m_right_nocontract_strides, this->m_j_strides, - this->m_right_contracting_strides, this->m_k_strides); - -#ifndef EIGEN_SYCL_DISABLE_SCALAR - if (triple_dim.M == 1 && triple_dim.N == 1) { - launchSC(buffer, lhs, rhs, triple_dim.K); - } else -#endif -#ifndef EIGEN_SYCL_DISABLE_GEMV - if (triple_dim.M != 1 && triple_dim.N == 1) { - LaunchVT<false>(buffer, rhs, lhs, triple_dim.M, triple_dim.K); - } else if (triple_dim.M == 1 && triple_dim.N != 1) { - LaunchVT<true>(buffer, lhs, rhs, triple_dim.N, triple_dim.K); - } else // This is equivalent of if (m!=1 && n!=1) -#endif - { - typedef input_mapper_propertis<lhs_inner_dim_contiguous, rhs_inner_dim_contiguous, rhs_inner_dim_reordered> - inpt_mapper_properties; -#ifndef EIGEN_SYCL_DISABLE_SKINNY - bool skinny = false; - auto platform_name = this->device().getPlatformName(); - // This is based on empirical calculation for AMD r9-nano and Fiji - if (platform_name.find("AMD") == 0) { - skinny = (triple_dim.M < triple_dim.K || triple_dim.N < triple_dim.K) && - ((triple_dim.M < 1024 && triple_dim.N < 1024) || - (uint64_t(triple_dim.M * triple_dim.N) < uint64_t(triple_dim.K))); - } else { - skinny = (((std::max(triple_dim.K, triple_dim.N) / std::min(triple_dim.K, triple_dim.N)) > 100) || - ((std::max(triple_dim.K, triple_dim.M) / std::min(triple_dim.K, triple_dim.M)) > 100) || - ((std::max(triple_dim.N, triple_dim.M) / std::min(triple_dim.N, triple_dim.M)) > 100)); - } - if (skinny) - adjustTT<true, inpt_mapper_properties>(buffer, lhs, rhs, triple_dim); - else -#endif // EIGEN_SYCL_DISABLE_SKINNY - adjustTT<false, inpt_mapper_properties>(buffer, lhs, rhs, triple_dim); - } - } - - template <bool skinny, typename input_mapper_properties, typename LhsMapper, typename RhsMapper> - void EIGEN_ALWAYS_INLINE adjustTT(EvaluatorPointerType buffer, const LhsMapper &lhs, const RhsMapper &rhs, - const TripleDim &triple_dim) const { -#ifdef EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON - if (device().has_local_memory()) { - typedef TensorSycl::internal::TTPanelSize<CoeffReturnType, StorageIndex, 4, 4, 16> PanelParameters; - launchTT<TensorSycl::internal::contraction_type::local, skinny, input_mapper_properties, PanelParameters>( - buffer, lhs, rhs, triple_dim); - } -#endif -#ifdef EIGEN_SYCL_LOCAL_MEM_UNSET_OR_OFF - if (!(device().has_local_memory())) { - typedef TensorSycl::internal::TTPanelSize<CoeffReturnType, StorageIndex, 4, 4, 4> PanelParameters; - launchTT<TensorSycl::internal::contraction_type::no_local, skinny, input_mapper_properties, PanelParameters>( - buffer, lhs, rhs, triple_dim); - } -#endif - } - - template <TensorSycl::internal::contraction_type ct, bool skinny, typename input_mapper_properties, - typename Properties, typename LhsMapper, typename RhsMapper> - void launchTT(EvaluatorPointerType buffer, const LhsMapper &lhs, const RhsMapper &rhs, - const TripleDim &triple_dim) const { - const StorageIndex roundUpM = Eigen::TensorSycl::internal::roundUp(triple_dim.M, Properties::TileSizeDimM); - const StorageIndex roundUpN = Eigen::TensorSycl::internal::roundUp(triple_dim.N, Properties::TileSizeDimN); - const StorageIndex groupSizeM = roundUpM / Properties::TileSizeDimM; - const StorageIndex groupSizeN = roundUpN / Properties::TileSizeDimN; - - const StorageIndex roundUpK = Eigen::TensorSycl::internal::roundUp(triple_dim.K, Properties::TileSizeDimK); - StorageIndex totalTilesK = roundUpK / Properties::TileSizeDimK; - StorageIndex groupSizeK = - skinny - ? std::max(std::min(totalTilesK, - (StorageIndex)(device().getPowerOfTwo(device().getNumSyclMultiProcessors(), true) * 4) / - (groupSizeM * groupSizeN)), - StorageIndex(1)) - : StorageIndex(1); - - const StorageIndex numTilesPerGroup = Eigen::TensorSycl::internal::roundUp(totalTilesK, groupSizeK) / groupSizeK; - - const StorageIndex totalGroupSize = groupSizeM * groupSizeN * groupSizeK; - - const StorageIndex localRange = Properties::LocalThreadSizeM * Properties::LocalThreadSizeN; - const StorageIndex globalRange = totalGroupSize * localRange; - - const StorageIndex scratchSize = (ct == TensorSycl::internal::contraction_type::local) - ? ((Properties::DoubleBuffer + 1) * - (Properties::TileSizeDimM + Properties::BC) * (Properties::TileSizeDimK)) + - ((Properties::DoubleBuffer + 1) * (Properties::TileSizeDimK) * - (Properties::TileSizeDimN + Properties::BC)) - : StorageIndex(1); - - auto thread_range = cl::sycl::nd_range<1>(cl::sycl::range<1>(globalRange), cl::sycl::range<1>(localRange)); - if (groupSizeK == 1) { - typedef TensorSycl::internal::TensorContractionKernel<CoeffReturnType, LhsScalar, RhsScalar, EvaluatorPointerType, - LhsMapper, RhsMapper, StorageIndex, Properties, TripleDim, - PacketAccess, input_mapper_properties, true, ct> - ContractKernelName; - device().template binary_kernel_launcher<CoeffReturnType, ContractKernelName>( - lhs, rhs, buffer, thread_range, scratchSize, groupSizeM, groupSizeN, numTilesPerGroup, triple_dim); - } else { - typedef TensorSycl::internal::TensorContractionKernel<CoeffReturnType, LhsScalar, RhsScalar, EvaluatorPointerType, - LhsMapper, RhsMapper, StorageIndex, Properties, TripleDim, - PacketAccess, input_mapper_properties, false, ct> - ContractKernelName; - CoeffReturnType *temp_pointer = static_cast<CoeffReturnType *>( - device().allocate_temp(triple_dim.M * triple_dim.N * groupSizeK * sizeof(CoeffReturnType))); - EvaluatorPointerType tmp_global_accessor = device().get(temp_pointer); - - device().template binary_kernel_launcher<CoeffReturnType, ContractKernelName>( - lhs, rhs, tmp_global_accessor, thread_range, scratchSize, groupSizeM, groupSizeN, numTilesPerGroup, - triple_dim); - - typedef Eigen::internal::SumReducer<CoeffReturnType> Op; - auto op = Op(); - typedef TensorSycl::internal::SecondStepPartialReduction<CoeffReturnType, StorageIndex, EvaluatorPointerType, - EvaluatorPointerType, Op> - ReductionKernel; - - device().template unary_kernel_launcher<CoeffReturnType, ReductionKernel>( - tmp_global_accessor, buffer, - cl::sycl::nd_range<1>(cl::sycl::range<1>(StorageIndex( - Eigen::TensorSycl::internal::roundUp(triple_dim.M * triple_dim.N, localRange))), - cl::sycl::range<1>(localRange)), - StorageIndex(1), op, StorageIndex(triple_dim.M * triple_dim.N), groupSizeK); - - device().deallocate_temp(temp_pointer); - } - } - -#ifndef EIGEN_SYCL_DISABLE_GEMV - template <bool is_lhs_vec, typename VectorMapper, typename TensorMapper, typename StorageIndex> - void EIGEN_ALWAYS_INLINE LaunchVT(EvaluatorPointerType buffer, const VectorMapper &vec, const TensorMapper &mat, - StorageIndex NC, StorageIndex C) const { - const StorageIndex nonContractDim = NC; - EIGEN_CONSTEXPR StorageIndex NCFactor = 1; - EIGEN_CONSTEXPR StorageIndex CFactor = 1; - EIGEN_CONSTEXPR StorageIndex NCWindow = 16; - typedef Eigen::TensorSycl::internal::TVPanelSize<CoeffReturnType, StorageIndex, NCWindow, CFactor, NCFactor> - Properties; - const StorageIndex roundUpC = Eigen::TensorSycl::internal::roundUp(C, Properties::TileSizeDimC); - const StorageIndex cNumGroups = roundUpC / (Properties::LocalThreadSizeC * Properties::WorkLoadPerThreadC); - const StorageIndex roundUpNC = Eigen::TensorSycl::internal::roundUp(nonContractDim, Properties::TileSizeDimNC); - const StorageIndex nCNumGroups = roundUpNC / (Properties::LocalThreadSizeNC * Properties::WorkLoadPerThreadNC); - const StorageIndex globalRange = - (roundUpNC / (Properties::WorkLoadPerThreadNC)) * (roundUpC / (Properties::WorkLoadPerThreadC)); - const StorageIndex localRange = Properties::LocalThreadSizeNC * Properties::LocalThreadSizeC; - const StorageIndex scratchSize = - (Properties::WorkLoadPerThreadNC + CFactor) * Properties::LocalThreadSizeC * Properties::LocalThreadSizeNC; - auto thread_range = cl::sycl::nd_range<1>(cl::sycl::range<1>(globalRange), cl::sycl::range<1>(localRange)); - if (cNumGroups > 1) { - typedef Eigen::TensorSycl::internal::GeneralVectorTensor<CoeffReturnType, EvaluatorPointerType, VectorMapper, - TensorMapper, StorageIndex, Properties, CFactor, false, - is_lhs_vec, false> - ContractKernelName; - CoeffReturnType *temp_pointer = - static_cast<CoeffReturnType *>(device().allocate_temp(nonContractDim * cNumGroups * sizeof(CoeffReturnType))); - EvaluatorPointerType tmp_global_accessor = device().get(temp_pointer); - - device().template binary_kernel_launcher<CoeffReturnType, ContractKernelName>( - vec, mat, tmp_global_accessor, thread_range, scratchSize, nCNumGroups, nonContractDim, C); - - typedef Eigen::internal::SumReducer<CoeffReturnType> Op; - typedef TensorSycl::internal::SecondStepPartialReduction<CoeffReturnType, StorageIndex, EvaluatorPointerType, - EvaluatorPointerType, Op> - ReductionKernel; - - device().template unary_kernel_launcher<CoeffReturnType, ReductionKernel>( - tmp_global_accessor, buffer, - cl::sycl::nd_range<1>(cl::sycl::range<1>(Eigen::TensorSycl::internal::roundUp(nonContractDim, localRange)), - cl::sycl::range<1>(localRange)), - StorageIndex(1), Op(), nonContractDim, cNumGroups); - - device().deallocate_temp(temp_pointer); - } else { - typedef Eigen::TensorSycl::internal::GeneralVectorTensor<CoeffReturnType, EvaluatorPointerType, VectorMapper, - TensorMapper, StorageIndex, Properties, CFactor, false, - is_lhs_vec, true> - ContractKernelName; - device().template binary_kernel_launcher<CoeffReturnType, ContractKernelName>( - vec, mat, buffer, thread_range, scratchSize, nCNumGroups, nonContractDim, C); - } - } -#endif - -#ifndef EIGEN_SYCL_DISABLE_SCALAR - template <typename LhsMapper, typename RhsMapper> - EIGEN_ALWAYS_INLINE void launchSC(EvaluatorPointerType buffer, const LhsMapper &lhs, const RhsMapper &rhs, - StorageIndex K) const { - EIGEN_STATIC_ASSERT(!((EIGEN_SYCL_LOCAL_THREAD_DIM0 * EIGEN_SYCL_LOCAL_THREAD_DIM1) & - (EIGEN_SYCL_LOCAL_THREAD_DIM0 * EIGEN_SYCL_LOCAL_THREAD_DIM1 - 1)), - "The Local thread size must be a power of 2 for the reduction " - "operation"); - EIGEN_CONSTEXPR StorageIndex local_range = EIGEN_SYCL_LOCAL_THREAD_DIM0 * EIGEN_SYCL_LOCAL_THREAD_DIM1; - - // Here we force the code not to be more than 2-step reduction: Our empirical research shows that if each thread - // reduces at least 512 elementss individually, we get better performance. - const StorageIndex num_work_group = ((K + (512 * local_range - 1)) / (512 * local_range) > 1 ? local_range : 1); - const StorageIndex global_range = num_work_group * local_range; - - typedef Eigen::TensorSycl::internal::GeneralScalarContraction< - CoeffReturnType, LhsScalar, RhsScalar, EvaluatorPointerType, LhsMapper, RhsMapper, StorageIndex, false> - ContractKernelName; - auto thread_range = cl::sycl::nd_range<1>(cl::sycl::range<1>(global_range), cl::sycl::range<1>(local_range)); - if (num_work_group > 1) { - CoeffReturnType *temp_pointer = - static_cast<CoeffReturnType *>(device().allocate_temp(num_work_group * sizeof(CoeffReturnType))); - EvaluatorPointerType tmp_global_accessor = device().get(temp_pointer); - device().template binary_kernel_launcher<CoeffReturnType, ContractKernelName>(lhs, rhs, tmp_global_accessor, - thread_range, local_range, K); - typedef Eigen::internal::SumReducer<CoeffReturnType> Op; - typedef TensorSycl::internal::SecondStepFullReducer<CoeffReturnType, Op, EvaluatorPointerType, - EvaluatorPointerType, StorageIndex, local_range> - GenericRKernel; - device().template unary_kernel_launcher<CoeffReturnType, GenericRKernel>( - tmp_global_accessor, buffer, - cl::sycl::nd_range<1>(cl::sycl::range<1>(local_range), cl::sycl::range<1>(local_range)), local_range, Op()); - - device().deallocate_temp(temp_pointer); - } else { - device().template binary_kernel_launcher<CoeffReturnType, ContractKernelName>(lhs, rhs, buffer, thread_range, - local_range, K); - } - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - this->m_leftImpl.cleanup(); - this->m_rightImpl.cleanup(); - - if (this->m_result) { - this->m_device.deallocate_temp(this->m_result); - this->m_result = NULL; - } - } - // The placeholder accessors must bound to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - this->m_leftImpl.bind(cgh); - this->m_rightImpl.bind(cgh); - this->m_result.bind(cgh); - } -}; -} // namespace Eigen -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_SYCL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionThreadPool.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionThreadPool.h deleted file mode 100644 index 21be6ea4..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContractionThreadPool.h +++ /dev/null @@ -1,1679 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_THREAD_POOL_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_THREAD_POOL_H - -// evaluator for thread pool device -#ifdef EIGEN_USE_THREADS - -namespace Eigen { - -template<typename Indices, typename LeftArgType, typename RightArgType, typename OutputKernelType> -struct TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, ThreadPoolDevice> : - public TensorContractionEvaluatorBase<TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, ThreadPoolDevice> > { - - typedef ThreadPoolDevice Device; - - typedef TensorEvaluator<const TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType>, Device> Self; - typedef TensorContractionEvaluatorBase<Self> Base; - - typedef TensorContractionOp<Indices, LeftArgType, RightArgType, OutputKernelType> XprType; - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef typename XprType::Index Index; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - - enum { - Layout = TensorEvaluator<LeftArgType, Device>::Layout, - }; - - // Most of the code is assuming that both input tensors are ColMajor. If the - // inputs are RowMajor, we will "cheat" by swapping the LHS and RHS: - // If we want to compute A * B = C, where A is LHS and B is RHS, the code - // will pretend B is LHS and A is RHS. - typedef typename internal::conditional< - static_cast<int>(Layout) == static_cast<int>(ColMajor), LeftArgType, RightArgType>::type EvalLeftArgType; - typedef typename internal::conditional< - static_cast<int>(Layout) == static_cast<int>(ColMajor), RightArgType, LeftArgType>::type EvalRightArgType; - - static const int LDims = - internal::array_size<typename TensorEvaluator<EvalLeftArgType, Device>::Dimensions>::value; - static const int RDims = - internal::array_size<typename TensorEvaluator<EvalRightArgType, Device>::Dimensions>::value; - static const int ContractDims = internal::array_size<Indices>::value; - - typedef array<Index, LDims> left_dim_mapper_t; - typedef array<Index, RDims> right_dim_mapper_t; - - typedef array<Index, ContractDims> contract_t; - typedef array<Index, LDims - ContractDims> left_nocontract_t; - typedef array<Index, RDims - ContractDims> right_nocontract_t; - - static const int NumDims = LDims + RDims - 2 * ContractDims; - - typedef DSizes<Index, NumDims> Dimensions; - - // typedefs needed in evalTo - typedef typename internal::remove_const<typename EvalLeftArgType::Scalar>::type LhsScalar; - typedef typename internal::remove_const<typename EvalRightArgType::Scalar>::type RhsScalar; - typedef typename internal::gebp_traits<LhsScalar, RhsScalar> Traits; - - typedef TensorEvaluator<EvalLeftArgType, Device> LeftEvaluator; - typedef TensorEvaluator<EvalRightArgType, Device> RightEvaluator; - - TensorEvaluator(const XprType& op, const Device& device) : - Base(op, device) {} - - template <int Alignment> - void evalProduct(Scalar* buffer) const { - evalProductImpl<NoCallback, Alignment>(buffer, NoCallback()); - } - - template <typename EvalToCallback, int Alignment> - void evalProductAsync(Scalar* buffer, EvalToCallback done) const { - evalProductImpl<EvalToCallback, Alignment>(buffer, std::move(done)); - } - - template <typename DoneCallback, int Alignment> - void evalProductImpl(Scalar* buffer, DoneCallback done) const { - // This function computes a lot of heuristics in multiple steps, and it - // also has multiple exit points. To keep it sane, readable and all in one - // place, sync/async execution decision is made at runtime at the very end. - // - // (1) In sync mode we allocate Context on the stack, submit computations - // to the device thread pool, and block on a barrier until it is - // completed. - // - // (2) In async mode we allocate Context on the heap, and after all tasks - // are finished, we call provided the done callback, and delete a - // context from the heap. - // - // (*) EvalParallelContext & EvalShardedByInnerDimContext owns all the state - // and temporary buffers, requried for executing the tensor contraction. - // They are responsible for cleaning it up after contraction is done. - static const bool IsEvalInSyncMode = - std::is_same<DoneCallback, NoCallback>::value; - - const Index m = this->m_i_size; - const Index n = this->m_j_size; - const Index k = this->m_k_size; - if (m == 0 || n == 0 || k == 0) return; - - // Compute a set of algorithm parameters: - // - kernel block sizes (bm, bn, bk) - // - task grain sizes (number of kernels executed per task: gm, gn) - // - number of threads - // - sharding by row/column - // - parallel packing or first lhs then rhs - // and some derived parameters: - // - number of tasks (nm, nn, nk) - // - number of kernels (nm0, nn0) - // Unfortunately, all these parameters are tightly interdependent. - // So in some cases we first compute approximate values, then compute other - // values based on these approximations and then refine the approximations. - - // There are lots of heuristics here. There is some reasoning behind them, - // but ultimately they are just tuned on contraction benchmarks for - // different input configurations, thread counts and instruction sets. - // So feel free to question any of them. - - // Compute whether we want to shard by row or by column. - // This is a first approximation, it will be refined later. Since we don't - // know number of threads yet we use 2, because what's we are most - // interested in at this point is whether it makes sense to use - // parallelization at all or not. - bool shard_by_col = shardByCol(m, n, 2); - - // First approximation of kernel blocking sizes. - // Again, we don't know number of threads yet, so we use 2. - Index bm, bn, bk; - if (shard_by_col) { - internal::TensorContractionBlocking<Scalar, LhsScalar, RhsScalar, Index, - internal::ShardByCol> - blocking(k, m, n, 2); - bm = blocking.mc(); - bn = blocking.nc(); - bk = blocking.kc(); - } else { - internal::TensorContractionBlocking<Scalar, LhsScalar, RhsScalar, Index, - internal::ShardByRow> - blocking(k, m, n, 2); - bm = blocking.mc(); - bn = blocking.nc(); - bk = blocking.kc(); - } - - // Compute optimal number of threads. - // Note: we use bk instead of k here because we are interested in amount of - // _parallelizable_ computations, and computations are not parallelizable - // across k dimension. - const TensorOpCost cost = - contractionCost(m, n, bm, bn, bk, shard_by_col, false); - int num_threads = TensorCostModel<ThreadPoolDevice>::numThreads( - static_cast<double>(n) * m, cost, this->m_device.numThreads()); - int num_threads_by_k = numThreadsInnerDim(m, n, k); - if (shardByInnerDim(m, n, k, num_threads, num_threads_by_k)) { - // We are in the scenario where it is more effective to shard by the - // inner dimension. - if (IsEvalInSyncMode) { - EvalShardedByInnerDimContext<DoneCallback> ctx( - this, num_threads_by_k, buffer, m, n, k, std::move(done)); - ctx.template run<Alignment>(); - } else { - auto* ctx = new EvalShardedByInnerDimContext<DoneCallback>( - this, num_threads_by_k, buffer, m, n, k, std::move(done)); - ctx->template runAsync<Alignment>(); - } - - return; - } - - // TODO(dvyukov): this is a stop-gap to prevent regressions while the cost - // model is not tuned. Remove this when the cost model is tuned. - if (n == 1) num_threads = 1; - - if (num_threads == 1) { - TENSOR_CONTRACTION_DISPATCH(this->template evalProductSequential, - Unaligned, (buffer)); - if (!IsEvalInSyncMode) done(); - return; - } - - // Now that we know number of threads, recalculate sharding and blocking. - shard_by_col = shardByCol(m, n, num_threads); - if (shard_by_col) { - internal::TensorContractionBlocking<Scalar, LhsScalar, RhsScalar, Index, - internal::ShardByCol> - blocking(k, m, n, num_threads); - bm = blocking.mc(); - bn = blocking.nc(); - bk = blocking.kc(); - } else { - internal::TensorContractionBlocking<Scalar, LhsScalar, RhsScalar, Index, - internal::ShardByRow> - blocking(k, m, n, num_threads); - bm = blocking.mc(); - bn = blocking.nc(); - bk = blocking.kc(); - } - - // Number of kernels for each dimension. - Index nm0 = divup(m, bm); - Index nn0 = divup(n, bn); - Index nk = divup(k, bk); - - // Calculate task grain size (number of kernels executed per task). - // This task size coarsening serves two purposes: - // 1. It reduces per-task overheads including synchronization overheads. - // 2. It allows to use caches better (reuse the same packed rhs in several - // consecutive kernels). - Index gm = 1; - Index gn = 1; - // If we are sharding by column, then we prefer to reduce rows first. - if (shard_by_col) { - gm = coarsenM(m, n, bm, bn, bk, gn, num_threads, shard_by_col); - gn = coarsenN(m, n, bm, bn, bk, gm, num_threads, shard_by_col); - } else { - gn = coarsenN(m, n, bm, bn, bk, gm, num_threads, shard_by_col); - gm = coarsenM(m, n, bm, bn, bk, gn, num_threads, shard_by_col); - } - // Number of tasks in each dimension. - Index nm = divup(nm0, gm); - Index nn = divup(nn0, gn); - - // If there is enough concurrency in the sharding dimension, we choose not - // to paralellize by the other dimension, and execute all kernels in sync - // mode. This reduces parallelism from the nm x nn down to nn - // (shard_by_col==true) or nm (shard_by_col==false). - const Index sharding_dim_tasks = shard_by_col ? nn : nm; - const int num_worker_threads = this->m_device.numThreadsInPool(); - - // With small number of threads we want to make sure that we do not reduce - // parallelism too much. With large number of threads we trade maximum - // parallelism for better memory locality. - const float oversharding_factor = - num_worker_threads <= 4 ? 8.0 : - num_worker_threads <= 8 ? 4.0 : - num_worker_threads <= 16 ? 2.0 : - num_worker_threads <= 32 ? 1.0 : - num_worker_threads <= 64 ? 0.8 : /* num_worker_threads > 64 */ 0.6; - - const bool parallelize_by_sharding_dim_only = - sharding_dim_tasks >= oversharding_factor * num_worker_threads; - - // Last by not least, decide whether we want to issue both lhs and rhs - // packing in parallel; or issue lhs packing first, and then issue rhs - // packing when lhs packing completes (for !shard_by_col lhs and rhs are - // swapped). Parallel packing allows more parallelism (for both packing and - // kernels), while sequential packing provides better locality (once - // a thread finishes rhs packing it proceed to kernels with that rhs). - // First, we are interested in parallel packing if there are few tasks. - bool parallel_pack = num_threads >= nm * nn; - // Also do parallel packing if all data fits into L2$. - if (m * bk * Index(sizeof(LhsScalar)) + n * bk * Index(sizeof(RhsScalar)) <= - l2CacheSize() * num_threads) - parallel_pack = true; - // But don't do it if we will use each rhs only once. Locality seems to be - // more important in this case. - if ((shard_by_col ? nm : nn) == 1) parallel_pack = false; - // Also don't get in the way of parallelize_by_sharding_dim_only - // optimization. - if (parallelize_by_sharding_dim_only) parallel_pack = false; - - // TODO(ezhulnev): With if contexpr we don't need SyncEvalParallelContext. - if (IsEvalInSyncMode) { -#define CONTEXT_ARGS \ - (this, num_threads, buffer, m, n, k, bm, bn, bk, nm, nn, nk, gm, gn, nm0, \ - nn0, shard_by_col, parallel_pack, parallelize_by_sharding_dim_only, \ - NoCallback()) \ - .run() - TENSOR_CONTRACTION_DISPATCH(SyncEvalParallelContext, Alignment, - CONTEXT_ARGS); -#undef CONTEXT_ARGS - - } else { -#define CONTEXT_ARGS \ - (this, num_threads, buffer, m, n, k, bm, bn, bk, nm, nn, nk, gm, gn, nm0, \ - nn0, shard_by_col, parallel_pack, parallelize_by_sharding_dim_only, \ - std::move(done)) - TENSOR_CONTRACTION_ASYNC_DISPATCH(EvalParallelContext, DoneCallback, - Alignment, CONTEXT_ARGS, run()); -#undef CONTEXT_ARGS - } - } - - // ------------------------------------------------------------------------ // - - // Dummy struct to represent an empty DoneCallback. - - struct NoCallback { - void operator()() { - eigen_assert(false && "NoCallback should never be called"); - } - }; - - // ------------------------------------------------------------------------ // - - template <typename DoneCallback, typename Context> - class EvalParallelNotification; - - // Synchronous evaluation notification that blocks caller thread in Wait(). - template <typename Context> - class EvalParallelNotification<NoCallback, Context> { - public: - EvalParallelNotification(Context*, NoCallback) {} - void Notify() { done_.Notify(); } - void Wait() { done_.Wait(); } - private: - Eigen::Notification done_; - }; - - // Asynchronous evaluation notification that does not block in Wait(). - template <typename DoneCallback, typename Context> - class EvalParallelNotification { - public: - EvalParallelNotification(Context* ctx, DoneCallback done) - : ctx_(ctx), done_(std::move(done)) {} - - void Notify() { - // Make a copy of done callback, because it will be destructed when we - // will delete context in the next line (EvalParallelNotification is a - // data member of EvalParallelContext class). - DoneCallback done_copy = std::move(done_); - - // Delete parallel evaluation context. - delete ctx_; - - // Now safely call the done callback. - done_copy(); - } - - void Wait() {} - - private: - Context* ctx_; - DoneCallback done_; - }; - - // Context orchestrates sync/async parallel contraction evaluation. When it is - // executed in asynchronous mode, it owns all the shared state that might be - // accessible by block packing and kernel tasks. - - template <typename DoneCallback, bool lhs_inner_dim_contiguous, - bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, - int Alignment> - class EvalParallelContext { - public: - typedef internal::TensorContractionInputMapper< - LhsScalar, Index, internal::Lhs, LeftEvaluator, left_nocontract_t, - contract_t, internal::packet_traits<LhsScalar>::size, - lhs_inner_dim_contiguous, false, Unaligned> - LhsMapper; - typedef internal::TensorContractionInputMapper< - RhsScalar, Index, internal::Rhs, RightEvaluator, right_nocontract_t, - contract_t, internal::packet_traits<RhsScalar>::size, - rhs_inner_dim_contiguous, rhs_inner_dim_reordered, Unaligned> - RhsMapper; - - typedef internal::blas_data_mapper<Scalar, Index, ColMajor> OutputMapper; - - typedef internal::TensorContractionKernel< - Scalar, LhsScalar, RhsScalar, Index, OutputMapper, LhsMapper, RhsMapper> - TensorContractionKernel; - - typedef typename TensorContractionKernel::LhsBlock LhsBlock; - typedef typename TensorContractionKernel::RhsBlock RhsBlock; - typedef typename TensorContractionKernel::BlockMemHandle BlockMemHandle; - - EvalParallelContext(const Self* self, int num_threads, Scalar* buffer, - Index tm, Index tn, Index tk, Index bm, Index bn, - Index bk, Index nm, Index nn, Index nk, Index gm, - Index gn, Index nm0, Index nn0, bool shard_by_col, - bool parallel_pack, - bool parallelize_by_sharding_dim_only, - DoneCallback done) - : created_by_thread_id_(std::this_thread::get_id()), - done_(this, std::move(done)), - device_(self->m_device), - lhs_(self->m_leftImpl, self->m_left_nocontract_strides, - self->m_i_strides, self->m_left_contracting_strides, - self->m_k_strides), - rhs_(self->m_rightImpl, self->m_right_nocontract_strides, - self->m_j_strides, self->m_right_contracting_strides, - self->m_k_strides), - buffer_(buffer), - output_(buffer, tm), - output_kernel_(self->m_output_kernel), - tensor_contraction_params_(self->m_tensor_contraction_params), - num_threads_(num_threads), - shard_by_col_(shard_by_col), - parallel_pack_(parallel_pack), - parallelize_by_sharding_dim_only_(parallelize_by_sharding_dim_only), - m_(tm), - n_(tn), - k_(tk), - bm_(bm), - bn_(bn), - bk_(bk), - nm_(nm), - nn_(nn), - nk_(nk), - gm_(gm), - gn_(gn), - nm0_(nm0), - nn0_(nn0), - kernel_(m_, k_, n_, bm_, bk_, bn_), - num_thread_local_allocations_(0), - // We reserve 2X more capacity for a thread local values, than the - // number of threads in the pool to efficiently handle task stealing - // by threads that are not managed by the pool. - thread_local_capacity(2 * (parallelize_by_sharding_dim_only_ - ? device_.numThreadsInPool() - : 0)), - // We will use only one of the Lhs/Rhs thread local storage depending - // on the shard_by_col value and we parallelize by sharding dim ONLY. - lhs_thread_local_blocks_(shard_by_col_ ? 0 : thread_local_capacity, - {*this}, {*this}), - rhs_thread_local_blocks_(shard_by_col_ ? thread_local_capacity : 0, - {*this}, {*this}) { - // These two options are mutually exclusive. - eigen_assert(!(parallel_pack && parallelize_by_sharding_dim_only)); - - for (Index x = 0; x < P; x++) { - // Normal number of notifications for k slice switch is - // nm_ + nn_ + nm_ * nn_. However, first P - 1 slices will receive only - // nm_ + nn_ notifications, because they will not receive notifications - // from preceding kernels. - state_switch_[x] = - x == 0 - ? 1 - : (parallel_pack_ ? nn_ + nm_ : (shard_by_col_ ? nn_ : nm_)) + - (x == P - 1 ? nm_ * nn_ : 0); - state_packing_ready_[x] = - parallel_pack_ ? 0 : (shard_by_col_ ? nm_ : nn_); - state_kernel_[x] = new std::atomic<uint8_t>*[nm_]; - for (Index m = 0; m < nm_; m++) { - state_kernel_[x][m] = new std::atomic<uint8_t>[nn_]; - // Kernels generally receive 3 notifications (previous kernel + 2 - // packing), but the first slice won't get notifications from previous - // kernels. - for (Index n = 0; n < nn_; n++) - state_kernel_[x][m][n].store( - (x == 0 ? 0 : 1) + (parallel_pack_ ? 2 : 1), - std::memory_order_relaxed); - } - } - - // Allocate memory for packed rhs/lhs matrices. - packed_mem_ = kernel_.allocateSlices( // - device_, // - /*num_lhs=*/nm0_, // - /*num_rhs=*/nn0_, // - /*num_slices=*/std::min<Index>(nk_, P - 1), // - packed_lhs_, packed_rhs_); - - if (parallelize_by_sharding_dim_only_) { - const int num_worker_threads = device_.numThreadsInPool(); - - if (shard_by_col) { - can_use_thread_local_packed_ = new std::atomic<bool>[nn_]; - for (int i = 0; i < nn_; ++i) - can_use_thread_local_packed_[i].store(true, - std::memory_order_relaxed); - - Index num_blocks = num_worker_threads * gn_; - thread_local_pre_alocated_mem_ = kernel_.allocateSlices( // - device_, // - /*num_lhs=*/0, // - /*num_rhs=*/num_blocks, // - /*num_slices=*/1, // - /*lhs_blocks=*/nullptr, &rhs_thread_local_pre_allocated_); - - } else { - can_use_thread_local_packed_ = new std::atomic<bool>[nm_]; - for (int i = 0; i < nm_; ++i) - can_use_thread_local_packed_[i].store(true, - std::memory_order_relaxed); - - Index num_blocks = num_worker_threads * gm_; - thread_local_pre_alocated_mem_ = kernel_.allocateSlices( // - device_, // - /*num_lhs=*/num_blocks, // - /*num_rhs=*/0, // - /*num_slices=*/1, &lhs_thread_local_pre_allocated_, // - /*rhs_blocks=*/nullptr); - } - } - } - - ~EvalParallelContext() { - for (Index x = 0; x < P; x++) { - for (Index m = 0; m < nm_; m++) delete[] state_kernel_[x][m]; - delete[] state_kernel_[x]; - } - kernel_.deallocate(device_, packed_mem_); - if (parallelize_by_sharding_dim_only_) { - kernel_.deallocate(device_, thread_local_pre_alocated_mem_); - delete[] can_use_thread_local_packed_; - } - } - - void run() { - // Kick off packing of the first slice. - signal_switch(0, 1); - - // Wait for overall completion. - // - // If parallel evaluation is executed in async mode, this is a no-op, and - // Wait() will return immediately. In synchronous mode it will block the - // caller thread until it will receive notification from last task. - // - // In async mode, last task when completed will call done callback from - // the same thread, and will delete this context. - // - // TODO(dvyukov): This wait can lead to deadlock if contraction is - // evaluated in synchronous mode. If nthreads contractions are - // concurrently submitted from worker threads, this wait will block all - // worker threads and the system will deadlock. - done_.Wait(); - } - - private: - std::thread::id created_by_thread_id_; - - // This notification is specialized on the type of DoneCallback and can be - // blocking or non-blocking. - EvalParallelNotification<DoneCallback, EvalParallelContext> done_; - - const Device& device_; - LhsMapper lhs_; - RhsMapper rhs_; - Scalar* const buffer_; - OutputMapper output_; - OutputKernelType output_kernel_; - TensorContractionParams tensor_contraction_params_; - const int num_threads_; - const bool shard_by_col_; - const bool parallel_pack_; - const bool parallelize_by_sharding_dim_only_; - // Matrix sizes. - const Index m_; - const Index n_; - const Index k_; - // Block sizes. - const Index bm_; - const Index bn_; - const Index bk_; - // Number of tasks. - const Index nm_; - const Index nn_; - const Index nk_; - // Task grain sizes (number of kernels executed per task). - const Index gm_; - const Index gn_; - // Number of blocks (this is different from ni_/nn_ because of task size - // coarsening). - const Index nm0_; - const Index nn0_; - // Tensor contraction kernel. - TensorContractionKernel kernel_; - - // Parallelization strategy. - // - // Blocks related to the same k block can run in parallel because they write - // to different output blocks. So we parallelize within k slices, this - // gives us parallelism level of m x n. Before we can start any kernels - // related to k-th slice, we need to issue m lhs packing tasks and n rhs - // packing tasks. - // - // However, there is a bottleneck when we are finishing kernels for k-th - // slice (at the very end there is only 1 runnable kernel). To mitigate this - // bottleneck we allow kernels from k-th and k+1-th slices to run in - // parallel. Note that (m, n, k) and (m, n, k+1) kernels write to the same - // output block, so they must not run in parallel. - // - // This gives us the following dependency graph. - // On each k slice we have m x n kernel tasks, m lhs paking tasks and n rhs - // packing tasks. - // Kernel (m, n, k) can start when: - // - kernel (m, n, k-1) has finished - // - lhs packing (m, k) has finished - // - rhs packing (n, k) has finished - // Lhs/rhs packing can start when: - // - all k-1 packing has finished (artificially imposed to limit amount of - // parallel packing) - // - // On top of that we limit runnable tasks to two consecutive k slices. - // This is done to limit amount of memory we need for packed lhs/rhs - // (for each k slice we need m*bk + n*bk memory in packed_lhs_/packed_rhs_). - // - // state_switch_ tracks when we are ready to switch to the next k slice. - // state_kernel_[m][n] tracks when we are ready to kick off kernel (m, n). - // These variable are rolling over 3 consecutive k slices: first two we are - // actively executing + one to track completion of kernels in the second - // slice. - static const Index P = 3; - - // Handle to the allocated temporary storage for Lhs/Rhs blocks. - BlockMemHandle packed_mem_; - std::vector<LhsBlock> packed_lhs_[P - 1]; - std::vector<RhsBlock> packed_rhs_[P - 1]; - - // If we choose to parallelize only by the sharding dimension, each thread - // will have it's own "thead local" (not a c++ thread local storage) memory - // for packed_lhs or packed_rhs (shard_by_col = false of true). This memory - // can't be passed to a kernel that might execute on a different thread. - // - // In practice when we are ready to pack memory for the sharding dimension - // (rhs if shard_by_col==true) of the K-th slice, all kernels for K-1 slice - // already computed (99% of the time), and we can pack data into the thread - // local storage, and guarantee that all the kernels will be executed - // immediately in the same thread. This significantly increases L1 cache hit - // ratio and reduces pressure on the memory bus. - // - // It's still possible that kernel for the K-th slice will be ready before - // completion of the K-1 kernel, so we have to allocate "global" packed_lhs_ - // and packed_rhs_ to allow kernels to be executed later on a thread - // different from the thread that was used for packing. - - // Handle for pre-allocated thread local memory buffers. - BlockMemHandle thread_local_pre_alocated_mem_; - - // Only one of these will be initialized depending on shard_by_col value - // (the size will be `num_worker_threads * num_grains_in_the_sharding_dim`). - std::vector<LhsBlock> lhs_thread_local_pre_allocated_; - std::vector<RhsBlock> rhs_thread_local_pre_allocated_; - - // How many thread local blocks were already allocated. - std::atomic<int> num_thread_local_allocations_; - const int thread_local_capacity; - - // We will use pre-allocated Lhs/Rhs blocks defined above, if the number of - // unique threads in a system is below or equal to the number of threads in - // a thread pool. We will fallback on dynamic memory allocation after that. - - // ThreadLocalBlocks is a container for Lhs or Rhs thread local buffers. Its - // size is equal to the grain size in Lhs/Rhs sharding dimension. - template <typename BlockType> - class ThreadLocalBlocks { - public: - ThreadLocalBlocks() = default; - - ThreadLocalBlocks(BlockType* base, size_t grain_size) - : is_pre_allocated_(true), - thread_local_pre_allocated_base_(base), - grain_size_(grain_size) {} - - ThreadLocalBlocks(BlockMemHandle mem_handle, - std::vector<BlockType> blocks) - : is_pre_allocated_(false), - mem_handle_(std::move(mem_handle)), - blocks_(std::move(blocks)) {} - - BlockType& block(int grain_index) { - eigen_assert(grain_index >= 0); - eigen_assert(static_cast<size_t>(grain_index) < size()); - return is_pre_allocated_ ? thread_local_pre_allocated_base_[grain_index] - : blocks_[grain_index]; - } - - void Release(EvalParallelContext& ctx) const { - if (!is_pre_allocated_) { - ctx.kernel_.deallocate(ctx.device_, mem_handle_); - } - } - - size_t size() const { - return is_pre_allocated_ ? grain_size_ : blocks_.size(); - } - - private: - bool is_pre_allocated_; - - // Reuse pre-allocated thread local buffers. - BlockType* thread_local_pre_allocated_base_ = nullptr; - size_t grain_size_ = 0; - - // These will be initialized only if `is_pre_allocated == false`. - BlockMemHandle mem_handle_{}; - std::vector<BlockType> blocks_; - }; - - // ThreadLocalBlocksInitialize callable does custom thread local blocks - // initialization, and will reuse pre-allocated buffers if possible, or will - // dynamically allocate new memory. - // - // Lhs/Rhs blocks might be of the same type, so we have to pass explicitly - // for what side do we plan to do block allocation. - template <typename BlockType, bool is_rhs> - class ThreadLocalBlocksInitialize { - static constexpr bool kIsLhs = - !is_rhs && std::is_same<BlockType, LhsBlock>::value; - static const bool kIsRhs = - is_rhs && std::is_same<BlockType, RhsBlock>::value; - static_assert(kIsLhs || kIsRhs, "Unkown block type"); - - using Blocks = ThreadLocalBlocks<BlockType>; - - public: - ThreadLocalBlocksInitialize(EvalParallelContext& ctx) - : ctx_(ctx), - num_worker_threads_(ctx_.device_.numThreadsInPool()) {} - - void operator()(Blocks& blocks) { - const int n = ctx_.num_thread_local_allocations_.fetch_add( - 1, std::memory_order_relaxed); - - if (n >= num_worker_threads_) { - ThreadLocalBlocksAllocator<is_rhs>::allocate(ctx_, blocks); - } else { - ThreadLocalBlocksAllocator<is_rhs>::reuse(ctx_, n, blocks); - } - } - - private: - // NOTE(ezhulenev): Without 'if constexpr' we have to put calls to - // TensorContractionKernel::allocateSlices into template specializations. - // Also explicit specializations are not allowed at class scope in C++03, - // EvalCtx type parameter is just a workaround for that limitation. - template <bool pack_rhs, typename EvalCtx = EvalParallelContext> - struct ThreadLocalBlocksAllocator; - - template <typename EvalCtx> - struct ThreadLocalBlocksAllocator</*pack_rhs=*/true, EvalCtx> { - static void allocate(EvalCtx& ctx, Blocks& blocks) { - std::vector<RhsBlock> rhs_blocks; - BlockMemHandle mem_handle = ctx.kernel_.allocateSlices( - ctx.device_, - /*num_lhs=*/0, - /*num_rhs=*/ctx.gn_, - /*num_slices=*/1, - /*lhs_blocks=*/nullptr, /*rhs_blocks=*/&rhs_blocks); - - blocks = ThreadLocalBlocks<RhsBlock>(std::move(mem_handle), - std::move(rhs_blocks)); - } - - static void reuse(EvalCtx& ctx, int index, Blocks& blocks) { - RhsBlock* ptr = &ctx.rhs_thread_local_pre_allocated_[ctx.gn_ * index]; - blocks = ThreadLocalBlocks<RhsBlock>(ptr, ctx.gn_); - } - }; - - template <typename EvalCtx> - struct ThreadLocalBlocksAllocator</*pack_rhs=*/false, EvalCtx> { - static void allocate(EvalCtx& ctx, Blocks& blocks) { - std::vector<LhsBlock> lhs_blocks; - BlockMemHandle mem_handle = ctx.kernel_.allocateSlices( - ctx.device_, - /*num_lhs=*/ctx.gm_, - /*num_rhs=*/0, - /*num_slices=*/1, - /*lhs_blocks=*/&lhs_blocks, /*rhs_blocks=*/nullptr); - - blocks = ThreadLocalBlocks<LhsBlock>(std::move(mem_handle), - std::move(lhs_blocks)); - } - - static void reuse(EvalCtx& ctx, int index, Blocks& blocks) { - LhsBlock* ptr = &ctx.lhs_thread_local_pre_allocated_[ctx.gm_ * index]; - blocks = ThreadLocalBlocks<LhsBlock>(ptr, ctx.gm_); - } - }; - - EvalParallelContext& ctx_; - const int num_worker_threads_; - }; - - template <typename BlockType> - class ThreadLocalBlocksRelease { - public: - using Blocks = ThreadLocalBlocks<BlockType>; - ThreadLocalBlocksRelease(EvalParallelContext& ctx) : ctx_(ctx) {} - void operator()(Blocks& blocks) { blocks.Release(ctx_); } - - private: - EvalParallelContext& ctx_; - }; - - // ThreadLocalBlocks initialization callables. - using ThreadLocalLhsInit = - ThreadLocalBlocksInitialize<LhsBlock, /*is_rhs=*/false>; - using ThreadLocalRhsInit = - ThreadLocalBlocksInitialize<RhsBlock, /*is_rhs=*/true>; - - // ThreadLocalBlocks release callables. - using ThreadLocalLhsRelease = ThreadLocalBlocksRelease<LhsBlock>; - using ThreadLocalRhsRelease = ThreadLocalBlocksRelease<RhsBlock>; - - // Thread local containers for Lhs/Rhs block packs. In practice only one of - // them will be used, depending on the shard_by_col value. - Eigen::ThreadLocal<ThreadLocalBlocks<LhsBlock>, ThreadLocalLhsInit, - ThreadLocalLhsRelease> - lhs_thread_local_blocks_; - Eigen::ThreadLocal<ThreadLocalBlocks<RhsBlock>, ThreadLocalRhsInit, - ThreadLocalRhsRelease> - rhs_thread_local_blocks_; - - // After a particular shard for Kth slice missed thread local execution - // opportunity (K-1 slice didn't complete kernels execution), we can no - // longer schedule K+1 and following slices in thread local mode, because - // there is no more guarantee that previous kernels were executed - // sequentially in the same thread (size is nn_ or nm_). - std::atomic<bool>* can_use_thread_local_packed_; - - std::atomic<uint8_t>** state_kernel_[P]; - // state_switch_ is frequently modified by worker threads, while other - // fields are read-only after constructor. Let's move it to a separate cache - // line to reduce cache-coherency traffic. - char pad_[128]; - std::atomic<Index> state_packing_ready_[P]; - std::atomic<Index> state_switch_[P]; - - LhsBlock& packed_lhs(Index m, Index k, Index m1, bool use_thread_local) { - if (use_thread_local) { - eigen_assert(!shard_by_col_); - ThreadLocalBlocks<LhsBlock>& blocks = lhs_thread_local_blocks_.local(); - - Index grain_index = m1 - m * gm_; - return blocks.block(internal::convert_index<int>(grain_index)); // FIXME better make ThreadLocalBlocks use Eigen::Index? - } else { - return packed_lhs_[k % (P - 1)][m1]; - } - } - - RhsBlock& packed_rhs(Index n, Index k, Index n1, bool use_thread_local) { - if (use_thread_local) { - eigen_assert(shard_by_col_); - ThreadLocalBlocks<RhsBlock>& blocks = rhs_thread_local_blocks_.local(); - - Index grain_index = n1 - n * gn_; - return blocks.block(internal::convert_index<int>(grain_index)); // FIXME better make ThreadLocalBlocks use Eigen::Index? - } else { - return packed_rhs_[k % (P - 1)][n1]; - } - } - - // In following two methods (pack_lhs and pack_rhs), if we know for sure - // that we'll be able to immediately call a kernel with packed data, and do - // not submit it to the thread pool, we can use thread local memory for - // packed data. - // - // We can only reliably check it if we are running all kernels in sync mode - // (parallelize only by sharding dim). If kernel for m==0 (n==0) is ready to - // run, it's guaranteed that all kernels with larger values of m (n) are - // also ready, because we execute them in the same order for all K slices. - - void pack_lhs(Index m, Index k) { - bool use_thread_local = false; - - if (parallelize_by_sharding_dim_only_ && !shard_by_col_ && - can_use_thread_local_packed_[m].load(std::memory_order_relaxed)) { - if (state_kernel_[k % P][m][0].load(std::memory_order_relaxed) == 1) { - use_thread_local = true; - } else { - // If we can't guarantee that all kernels in `k` slice will be - // executed sequentially in current thread, it's no longer safe to use - // thread local memory in following slices along the k dimensions. - eigen_assert(k > 0); - can_use_thread_local_packed_[m].store(false, - std::memory_order_relaxed); - } - } - - const Index mend = m * gm_ + gm(m); - for (Index m1 = m * gm_; m1 < mend; m1++) - kernel_.packLhs(&packed_lhs(m, k, m1, use_thread_local), - lhs_.getSubMapper(m1 * bm_, k * bk_), bk(k), bm(m1)); - - if (!parallel_pack_ && shard_by_col_) { - assert(!use_thread_local); - signal_packing(k); - } else { - signal_switch(k + 1); - for (Index n = nn_ - 1; n >= 0; n--) { - bool sync = parallelize_by_sharding_dim_only_ || n == 0; - signal_kernel(m, n, k, sync, use_thread_local); - } - } - } - - void pack_rhs(Index n, Index k) { - bool use_thread_local = false; - - if (parallelize_by_sharding_dim_only_ && shard_by_col_ && - can_use_thread_local_packed_[n].load(std::memory_order_relaxed)) { - if (state_kernel_[k % P][0][n].load(std::memory_order_relaxed) == 1) { - use_thread_local = true; - } else { - // If we can't guarantee that all kernels in `k` slice will be - // executed sequentially in current thread, it's no longer safe to use - // thread local memory in followig slices along the k dimensions. - eigen_assert(k > 0); - can_use_thread_local_packed_[n].store(false, - std::memory_order_relaxed); - } - } - - const Index nend = n * gn_ + gn(n); - for (Index n1 = n * gn_; n1 < nend; n1++) { - if (!TensorContractionKernel::HasBeta && k == 0) { - // Zero the output memory in parallel, only if contraction kernel does - // not support `beta`. Otherwise we will pass beta 0.0 to the first - // call to the `TensorContractionKernel::invoke()`. - // - // On 10000x2x10000 mm zeroing can easily take half of time. Zero (bn - // x m) row. Safe to do here because all kernels that will write to - // this memory depend on completion of this task. Note: don't call - // device_.memset() here. device_.memset() blocks on thread pool - // worker thread, which can lead to underutilization and deadlocks. - memset(buffer_ + n1 * bn_ * m_, 0, bn(n1) * m_ * sizeof(Scalar)); - } - kernel_.packRhs(&packed_rhs(n, k, n1, use_thread_local), - rhs_.getSubMapper(k * bk_, n1 * bn_), bk(k), bn(n1)); - } - - if (parallel_pack_ || shard_by_col_) { - signal_switch(k + 1); - for (Index m = nm_ - 1; m >= 0; m--) { - bool sync = parallelize_by_sharding_dim_only_ || m == 0; - signal_kernel(m, n, k, sync, use_thread_local); - } - } else { - assert(!use_thread_local); - signal_packing(k); - } - } - - void kernel(Index m, Index n, Index k, bool use_thread_local) { - // Note: order of iteration matters here. Iteration over m is innermost - // because we want to reuse the same packed rhs in consecutive tasks - // (rhs fits into L2$ while lhs only into L3$). - const Index nend = n * gn_ + gn(n); - const Index mend = m * gm_ + gm(m); - - // NOTE: output = alpha * LHS * RHS + beta * output. - const Scalar alpha = Scalar(1); - const Scalar beta = - (TensorContractionKernel::HasBeta && k == 0) ? Scalar(0) : Scalar(1); - - if (shard_by_col_) { - for (Index n1 = n * gn_; n1 < nend; n1++) { - for (Index m1 = m * gm_; m1 < mend; m1++) { - const auto output_mapper = output_.getSubMapper(m1 * bm_, n1 * bn_); - kernel_.invoke( - output_mapper, - packed_lhs(m, k, m1, !shard_by_col_ && use_thread_local), - packed_rhs(n, k, n1, shard_by_col_ && use_thread_local), bm(m1), - bk(k), bn(n1), alpha, beta); - - // We are done with the last task for the [m1, n1] block. - if (k + 1 == nk_) { - output_kernel_(output_mapper, tensor_contraction_params_, - m1 * bm_, n1 * bn_, bm(m1), bn(n1)); - } - } - } - } else { - for (Index m1 = m * gm_; m1 < mend; m1++) - for (Index n1 = n * gn_; n1 < nend; n1++) { - const auto output_mapper = output_.getSubMapper(m1 * bm_, n1 * bn_); - kernel_.invoke( - output_mapper, - packed_lhs(m, k, m1, !shard_by_col_ && use_thread_local), - packed_rhs(n, k, n1, shard_by_col_ && use_thread_local), bm(m1), - bk(k), bn(n1), alpha, beta); - - // We are done with the last task for the [m1, n1] block. - if (k + 1 == nk_) { - output_kernel_(output_mapper, tensor_contraction_params_, - m1 * bm_, n1 * bn_, bm(m1), bn(n1)); - } - } - } - signal_kernel(m, n, k + 1, /*sync=*/false, /*use_thread_local=*/false); - signal_switch(k + 2); - } - - void signal_packing(Index k) { - eigen_assert(!parallel_pack_); - Index s = state_packing_ready_[k % P].fetch_sub(1); - eigen_assert(s > 0); - if (s != 1) return; - state_packing_ready_[k % P] = shard_by_col_ ? nm_ : nn_; - enqueue_packing(k, shard_by_col_); - } - - void signal_kernel(Index m, Index n, Index k, bool sync, - bool use_thread_local) { - std::atomic<uint8_t>* state = &state_kernel_[k % P][m][n]; - Index s = state->load(); - eigen_assert(s > 0); - if (s != 1 && state->fetch_sub(1) != 1) { - eigen_assert(!use_thread_local); - return; - } - state->store(parallel_pack_ ? 3 : 2, std::memory_order_relaxed); - if (sync) { - kernel(m, n, k, use_thread_local); - } else { - eigen_assert(!use_thread_local); - device_.enqueueNoNotification( - [=]() { kernel(m, n, k, use_thread_local); }); - } - } - - void signal_switch(Index k, Index v = 1) { - Index s = state_switch_[k % P].fetch_sub(v); - eigen_assert(s >= v); - if (s != v) return; - - // Ready to switch to the next k slice. - // Reset counter for the next iteration. - state_switch_[k % P] = - (parallel_pack_ ? nm_ + nn_ : (shard_by_col_ ? nn_ : nm_)) + - nm_ * nn_; - if (k < nk_) { - // Issue lhs/rhs packing. Their completion will in turn kick off - // kernels. - if (parallel_pack_) { - enqueue_packing(k, !shard_by_col_); - enqueue_packing(k, shard_by_col_); - } else if (shard_by_col_) { - enqueue_packing(k, false); - } else { - enqueue_packing(k, true); - } - - // Termination handling. - // Because kernel completion signals k + 2 switch, we need to finish nk - // + 2 slices without issuing any tasks on nk + 1 slice. So here we - // pretend that all nk + 1 packing tasks just finish instantly; so that - // nk + 2 switch only waits for completion of nk kernels. - } else if (k == nk_) { - signal_switch(k + 1, - parallel_pack_ ? nm_ + nn_ : (shard_by_col_ ? nn_ : nm_)); - } else { - done_.Notify(); - } - } - - // Enqueue all rhs/lhs packing for k-th slice. - void enqueue_packing(Index k, bool rhs) { - enqueue_packing_helper(0, rhs ? nn_ : nm_, k, rhs); - } - - void enqueue_packing_helper(Index start, Index end, Index k, bool rhs) { - if (end - start == 1) { - if (rhs) - pack_rhs(start, k); - else - pack_lhs(start, k); - } else { - while (end - start > 1) { - Index mid = (start + end) / 2; - device_.enqueueNoNotification( - [=]() { enqueue_packing_helper(mid, end, k, rhs); }); - end = mid; - } - - // Decide if we want to run first packing task (start == 0) in - // async mode if we parallelize only by sharding dim: - // (1) pack_lhs and pack_rhs call signal_switch before completing - // all calls to signal_kernel, which in sync mode might lead - // to the execution of the first kernel of the k+1 slice, before - // completing a call to the last kernel of the k slice. - // (2) all pack tasks for sharded dim must be executed in a thread - // pool to get pre-allocated thead local buffers. - bool pack_async = - (start == 0) && - (parallelize_by_sharding_dim_only_&& shard_by_col_ == rhs) && - (k > 0 || std::this_thread::get_id() == created_by_thread_id_); - - if (pack_async) { - device_.enqueueNoNotification( - [=]() { enqueue_packing_helper(start, end, k, rhs); }); - } else { - enqueue_packing_helper(start, end, k, rhs); - } - } - } - - // Block sizes with accounting for potentially incomplete last block. - Index bm(Index m) const { return m + 1 < nm0_ ? bm_ : m_ + bm_ - bm_ * nm0_; } - Index bn(Index n) const { return n + 1 < nn0_ ? bn_ : n_ + bn_ - bn_ * nn0_; } - Index bk(Index k) const { return k + 1 < nk_ ? bk_ : k_ + bk_ - bk_ * nk_; } - // Task grain sizes accounting for potentially incomplete last task. - Index gm(Index m) const { return m + 1 < nm_ ? gm_ : nm0_ + gm_ - gm_ * nm_; } - Index gn(Index n) const { return n + 1 < nn_ ? gn_ : nn0_ + gn_ - gn_ * nn_; } - - EvalParallelContext(const EvalParallelContext&) = delete; - void operator=(const EvalParallelContext&) = delete; - }; - - template <bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, - bool rhs_inner_dim_reordered, int Alignment> - using SyncEvalParallelContext = - EvalParallelContext<NoCallback, lhs_inner_dim_contiguous, - rhs_inner_dim_contiguous, rhs_inner_dim_reordered, - Alignment>; - - // ------------------------------------------------------------------------ // - - // EvalShardedByInnerDimContext orchestrates sync/async contraction - // evaluation, when we shard by inner dimension. When it is executed in - // asynchronous mode, it owns all the shared state that might be accessible by - // block processing tasks. - - template <typename DoneCallback> - struct EvalShardedByInnerDimContext { - EvalShardedByInnerDimContext(const Self* self, int num_threads, - Scalar* result_buffer, - Index m_size, Index n_size, Index k_size, - DoneCallback done_callback) - : evaluator(self), - m_lhs_inner_dim_contiguous(evaluator->m_lhs_inner_dim_contiguous), - m_rhs_inner_dim_contiguous(evaluator->m_rhs_inner_dim_contiguous), - m_rhs_inner_dim_reordered(evaluator->m_rhs_inner_dim_reordered), - result(result_buffer), - m(m_size), - n(n_size), - k(k_size), - done(std::move(done_callback)), - buffer_size_bytes(m * n * sizeof(Scalar)), - block_size(blockSize(k, num_threads)), - num_blocks(divup<Index>(k, block_size)), - num_pending_blocks(internal::convert_index<int>(num_blocks)), - l0_ranges(divup<Index>(num_blocks, l0_size)), - l0_state(l0_ranges), - block_buffers(num_blocks) { - // Keep count of pending gemm tasks for each l0 range. - for (int i = 0; i < l0_ranges; ++i) { - const Index num_pending_tasks = actualRangeSize(l0_ranges, l0_size, i); - l0_state.emplace_back(internal::convert_index<int>(num_pending_tasks)); - } - - // Allocate temporary buffers for each block. - for (Index block_idx = 0; block_idx < num_blocks; ++block_idx) { - Scalar* buf = block_idx == 0 - ? result - : static_cast<Scalar*>(evaluator->m_device.allocate( - buffer_size_bytes)); - block_buffers.emplace_back(buf); - } - } - - ~EvalShardedByInnerDimContext() { - for (Index i = 1; i < num_blocks; ++i) { - evaluator->m_device.deallocate(block_buffers[i]); - } - } - - template <int Alignment> - void run() { - Barrier barrier(internal::convert_index<int>(num_blocks)); - eval<Alignment>(barrier, 0, num_blocks); - barrier.Wait(); - - // Aggregate partial sums from l0 ranges. - aggregateL0Blocks<Alignment>(); - - // Apply output kernel. - applyOutputKernel(); - } - - template <int Alignment> - void runAsync() { - evalAsync<Alignment>(0, num_blocks); - } - - private: - // The underlying GEMM kernel assumes that k is a multiple of - // the packet size and subtle breakage occurs if this is violated. - static const Index packet_size = internal::packet_traits<RhsScalar>::size; - - const Self* evaluator; // TensorContraction evaluator - - // These fields required fromTENSOR_CONTRACTION_DISPATCH macro. - bool m_lhs_inner_dim_contiguous; - bool m_rhs_inner_dim_contiguous; - bool m_rhs_inner_dim_reordered; - - Scalar* result; - - Index m; - Index n; - Index k; - - DoneCallback done; - - // ----------------------------------------------------------------------// - // Algorithm parameters. - - // We will compute partial results into the buffers of this size. - Index buffer_size_bytes; - - Index block_size; - Index num_blocks; - - // Keep track of pending tasks when evaluate in async mode. - std::atomic<int> num_pending_blocks; - - // We compute partial gemm results in parallel, and to get the final result - // we need to add them all together. For the large number of threads (>= 48) - // this adds a very expensive sequential step at the end. - // - // We split the [0, num_blocks) into small ranges, and when a task for the - // block finishes its partial gemm computation, it checks if it was the last - // gemm in the range, and if so, it will add all blocks of the range. - // - // After all tasks done, we need to add only these pre-aggregated blocks. - - // For now we use just a single level of ranges to compute pre-aggregated - // partial sums, but in general we can use more layers to compute tree - // aggregation in parallel and reduce the size of the sequential step. - // - // TODO(ezhulenev): Add multilevel tree aggregation? Probably will make - // sense only if number of threads >= ~128? - static const Index l0_size = 4; - Index l0_ranges; - - // Keep count of pending gemm tasks for each l0 range. - MaxSizeVector<std::atomic<int>> l0_state; // [0, l0_ranges) - - // Buffers allocated for each temporary block computation. - MaxSizeVector<Scalar*> block_buffers; // [0, num_blocks) - - template <int Alignment> - void processBlock(Index block_idx, Index begin, Index end) { - Scalar* buf = block_buffers[block_idx]; - - TENSOR_CONTRACTION_DISPATCH( - evaluator->template evalGemmPartialWithoutOutputKernel, Alignment, - (buf, begin, end, - /*num_threads=*/internal::convert_index<int>(num_blocks))); - - // Check if it was the last task in l0 range. - const Index l0_index = block_idx / l0_size; - const int v = l0_state[l0_index].fetch_sub(1); - eigen_assert(v >= 1); - - // If we processed the last block of the range, we can aggregate all - // partial results into the first block of the range. - if (v == 1) { - const Index rng_size = actualRangeSize(l0_ranges, l0_size, l0_index); - const Index dst_block_idx = l0_index * l0_size; - - if (rng_size == l0_size) { - addAllToBuffer<Alignment>( - m * n, - /*src_buf0=*/block_buffers[dst_block_idx + 1], - /*src_buf1=*/block_buffers[dst_block_idx + 2], - /*src_buf2=*/block_buffers[dst_block_idx + 3], - /*dst_buf= */ block_buffers[dst_block_idx]); - } else { - // Aggregate blocks of potentially incomplete last range. - for (int i = 1; i < rng_size; ++i) { - addToBuffer<Alignment>(m * n, - /*src_buf=*/block_buffers[dst_block_idx + i], - /*dst_buf=*/block_buffers[dst_block_idx]); - } - } - } - } - - // Aggregate partial sums from l0 ranges. - template <int Alignment> - void aggregateL0Blocks() const { - Index l0_index = 1; - - for (; l0_index + 2 < l0_ranges; l0_index += 3) { - addAllToBuffer<Alignment>( - m * n, - /*src_buf0=*/block_buffers[(l0_index + 0) * l0_size], - /*src_buf1=*/block_buffers[(l0_index + 1) * l0_size], - /*src_buf2=*/block_buffers[(l0_index + 2) * l0_size], - /*dst_buf= */ block_buffers[0]); - } - - for (; l0_index < l0_ranges; ++l0_index) { - addToBuffer<Alignment>(m * n, block_buffers[l0_index * l0_size], - block_buffers[0]); - } - } - - void applyOutputKernel() const { - typedef internal::blas_data_mapper<Scalar, Index, ColMajor> OutputMapper; - evaluator->m_output_kernel( - OutputMapper(result, m), evaluator->m_tensor_contraction_params, - static_cast<Eigen::Index>(0), static_cast<Eigen::Index>(0), m, n); - } - - // Compute block size with accounting for potentially incomplete last block. - Index actualBlockSize(Index block_idx) const { - return block_idx + 1 < num_blocks - ? block_size - : k + block_size - block_size * num_blocks; - }; - - // Compute range size with accounting for potentially incomplete last range. - Index actualRangeSize(Index num_ranges, Index range_size, - Index range_idx) const { - eigen_assert(range_idx < num_ranges); - return range_idx + 1 < num_ranges - ? range_size - : num_blocks + range_size - range_size * num_ranges; - }; - - template <int Alignment> - EIGEN_STRONG_INLINE static void addToBuffer(size_t n, const Scalar* src_buf, - Scalar* tgt_buf) { - const int output_packet_size = - internal::unpacket_traits<PacketReturnType>::size; - size_t i = 0; - const size_t num_packets = n / output_packet_size; - for (; i < output_packet_size * num_packets; i += output_packet_size) { - const PacketReturnType src_val = - internal::pload<PacketReturnType>(src_buf + i); - const PacketReturnType tgt_val = - internal::ploadt<PacketReturnType, Alignment>(tgt_buf + i); - const PacketReturnType sum = internal::padd(src_val, tgt_val); - internal::pstoret<Scalar, PacketReturnType, Alignment>(tgt_buf + i, - sum); - } - for (; i < n; ++i) { - tgt_buf[i] += src_buf[i]; - } - } - - template <int Alignment> - EIGEN_STRONG_INLINE static void addAllToBuffer(size_t n, - const Scalar* src_buf0, - const Scalar* src_buf1, - const Scalar* src_buf2, - Scalar* dst_buf) { - using ::Eigen::internal::padd; - using ::Eigen::internal::pload; - using ::Eigen::internal::ploadt; - using ::Eigen::internal::pstoret; - - const int output_packet_size = - internal::unpacket_traits<PacketReturnType>::size; - - size_t i = 0; - const size_t num_packets = n / output_packet_size; - for (; i < output_packet_size * num_packets; i += output_packet_size) { - const auto src_val0 = pload<PacketReturnType>(src_buf0 + i); - const auto src_val1 = pload<PacketReturnType>(src_buf1 + i); - const auto src_val2 = pload<PacketReturnType>(src_buf2 + i); - - const auto dst_val = ploadt<PacketReturnType, Alignment>(dst_buf + i); - const auto sum = - padd(padd(dst_val, src_val0), padd(src_val1, src_val2)); - - pstoret<Scalar, PacketReturnType, Alignment>(dst_buf + i, sum); - } - for (; i < n; ++i) { - dst_buf[i] += src_buf0[i] + src_buf1[i] + src_buf2[i]; - } - } - - template <int Alignment> - void eval(Barrier& barrier, Index start_block_idx, Index end_block_idx) { - while (end_block_idx - start_block_idx > 1) { - Index mid_block_idx = (start_block_idx + end_block_idx) / 2; - evaluator->m_device.enqueueNoNotification( - [this, &barrier, mid_block_idx, end_block_idx]() { - eval<Alignment>(barrier, mid_block_idx, end_block_idx); - }); - end_block_idx = mid_block_idx; - } - - Index block_idx = start_block_idx; - Index block_start = block_idx * block_size; - Index block_end = block_start + actualBlockSize(block_idx); - - processBlock<Alignment>(block_idx, block_start, block_end); - barrier.Notify(); - } - - template <int Alignment> - void evalAsync(Index start_block_idx, Index end_block_idx) { - while (end_block_idx - start_block_idx > 1) { - Index mid_block_idx = (start_block_idx + end_block_idx) / 2; - evaluator->m_device.enqueueNoNotification( - [this, mid_block_idx, end_block_idx]() { - evalAsync<Alignment>(mid_block_idx, end_block_idx); - }); - end_block_idx = mid_block_idx; - } - - Index block_idx = start_block_idx; - - Index block_start = block_idx * block_size; - Index block_end = block_start + actualBlockSize(block_idx); - - processBlock<Alignment>(block_idx, block_start, block_end); - - int v = num_pending_blocks.fetch_sub(1); - eigen_assert(v >= 1); - - if (v == 1) { - // Aggregate partial sums from l0 ranges. - aggregateL0Blocks<Alignment>(); - - // Apply output kernel. - applyOutputKernel(); - - // NOTE: If we call `done` callback before deleting this (context), - // it might deallocate Self* pointer captured by context, and we'll - // fail in destructor trying to deallocate temporary buffers. - - // Move done call back from context before it will be destructed. - DoneCallback done_copy = std::move(done); - - // We are confident that we are the last one who touches context. - delete this; - - // Now safely call the done callback. - done_copy(); - } - } - - // Cost model doesn't capture well the cost associated with constructing - // tensor contraction mappers and computing loop bounds in gemm_pack_lhs - // and gemm_pack_rhs, so we specify minimum desired block size. - static Index blockSize(Index k, int num_threads) { - const auto round_up = [=](Index index) -> Index { - const Index kmultiple = packet_size <= 8 ? 8 : packet_size; - return divup<Index>(index, kmultiple) * kmultiple; - }; - - const Index target_block_size = round_up(divup<Index>(k, num_threads)); - const Index desired_min_block_size = 12 * packet_size; - - return numext::mini<Index>( - k, numext::maxi<Index>(desired_min_block_size, target_block_size)); - } - - EvalShardedByInnerDimContext(const EvalShardedByInnerDimContext&) = delete; - void operator=(const EvalShardedByInnerDimContext&) = delete; - }; - - // ------------------------------------------------------------------------ // - - // Below are the function used by evalProductImpl heuristics, trying to select - // optimcal parameters for parallelization algorithm. - - // Decide whether we want to shard m x n contraction by columns or by rows. - static bool shardByCol(Index m, Index n, Index num_threads) { - // Note: we are comparing both n and m against Traits::nr, it is not - // a mistake. We are trying to figure out how both n and m will fit into - // the main sharding dimension. - - // Sharding by column is the default - // ... unless there is enough data for vectorization over rows - if (m / num_threads >= Traits::nr && - // and not enough data for vectorization over columns - (n / num_threads < Traits::nr || - // ... or barely enough data for vectorization over columns, - // but it is not evenly dividable across threads - (n / num_threads < 4 * Traits::nr && - (n % (num_threads * Traits::nr)) != 0 && - // ... and it is evenly dividable across threads for rows - ((m % (num_threads * Traits::nr)) == 0 || - // .. or it is not evenly dividable for both dimensions but - // there is much more data over rows so that corner effects are - // mitigated. - (m / n >= 6))))) - return false; - // Wait, or if matrices are just substantially prolonged over the other - // dimension. - if (n / num_threads < 16 * Traits::nr && m > n * 32) return false; - return true; - } - - Index coarsenM(Index m, Index n, Index bm, Index bn, Index bk, Index gn, - int num_threads, bool shard_by_col) const { - Index gm = 1; - Index gm1 = 1; - Index nm0 = divup(m, bm); - Index nm1 = nm0; - for (;;) { - // Find the next candidate for m grain size. It needs to result in - // different number of blocks. E.g. if we have 10 kernels, we want to try - // 5 and 10, but not 6, 7, 8 and 9. - while (gm1 <= nm0 && nm1 == divup(nm0, gm1)) gm1++; - if (gm1 > nm0) break; - // Check the candidate. - int res = checkGrain(m, n, bm, bn, bk, gm1, gn, gm, gn, num_threads, - shard_by_col); - if (res < 0) break; - nm1 = divup(nm0, gm1); - if (res == 0) continue; - // Commit new grain size. - gm = gm1; - } - return gm; - } - - Index coarsenN(Index m, Index n, Index bm, Index bn, Index bk, Index gm, - int num_threads, bool shard_by_col) const { - Index gn = 1; - Index gn1 = 1; - Index nn0 = divup(n, bn); - Index nn1 = nn0; - for (;;) { - while (gn1 <= nn0 && nn1 == divup(nn0, gn1)) gn1++; - if (gn1 > nn0) break; - int res = checkGrain(m, n, bm, bn, bk, gm, gn1, gm, gn, num_threads, - shard_by_col); - if (res < 0) break; - nn1 = divup(nn0, gn1); - if (res == 0) continue; - gn = gn1; - } - return gn; - } - - // checkGrain checks whether grain (gm, gn) is suitable and is better than - // (oldgm, oldgn). - int checkGrain(Index m, Index n, Index bm, Index bn, Index bk, Index gm, - Index gn, Index oldgm, Index oldgn, int num_threads, - bool shard_by_col) const { - const TensorOpCost cost = - contractionCost(bm * gm, bn * gn, bm, bn, bk, shard_by_col, true); - double taskSize = TensorCostModel<ThreadPoolDevice>::taskSize( - static_cast<double>(bm) * gm * bn * gn, cost); - // If the task is too small, then we agree on it regardless of anything - // else. Otherwise synchronization overheads will dominate. - if (taskSize < 1) return 1; - // If it is too large, then we reject it and all larger tasks. - if (taskSize > 2) return -1; - // Now we are in presumably good task size range. - // The main deciding factor here is parallelism. Consider that we have 12 - // kernels and 4 threads. Grains of 2, 3 and 4 all yield good task sizes. - // But 2/4 yield 6/3 tasks, which gives us parallelism of 0.75 (at most 3/4 - // of cores will be busy). While grain size 3 gives us 4 tasks, which gives - // us parallelism of 1 (we can load all cores). - Index nm0 = divup(m, bm); - Index nn0 = divup(n, bn); - Index new_tasks = divup(nm0, gm) * divup(nn0, gn); - double new_parallelism = static_cast<double>(new_tasks) / - (divup<int>(new_tasks, num_threads) * num_threads); - Index old_tasks = divup(nm0, oldgm) * divup(nn0, oldgn); - double old_parallelism = static_cast<double>(old_tasks) / - (divup<int>(old_tasks, num_threads) * num_threads); - if (new_parallelism > old_parallelism || new_parallelism == 1) return 1; - return 0; - } - - TensorOpCost contractionCost(Index m, Index n, Index bm, Index bn, Index bk, - bool shard_by_col, bool prepacked) const { - const int packed_size = std::min<int>(PacketType<LhsScalar, Device>::size, - PacketType<RhsScalar, Device>::size); - const int output_packet_size = internal::unpacket_traits<PacketReturnType>::size; - const double kd = static_cast<double>(bk); - double compute_bandwidth = computeBandwidth(false, bm, bn, bk); - // Computations. - TensorOpCost cost = TensorOpCost(0, 0, kd * compute_bandwidth, true, packed_size); - // Output stores. - cost += TensorOpCost(0, sizeof(CoeffReturnType), 0, true, output_packet_size); - if (prepacked) { - // Packing and kernels are executed in different tasks. When we calculate - // task grain size we look only at kernel cost assuming that kernel - // is more expensive than packing. - return cost; - } - // Lhs/rhs loads + computations. - TensorOpCost lhsCost = this->m_leftImpl.costPerCoeff(true) * (kd / n); - TensorOpCost rhsCost = this->m_rightImpl.costPerCoeff(true) * (kd / m); - // Lhs packing memory cost does not contribute considerably to overall - // execution time because lhs is prefetched early and accessed sequentially. - if (shard_by_col) - lhsCost.dropMemoryCost(); - else - rhsCost.dropMemoryCost(); - return cost + lhsCost + rhsCost; - } - - // Decide whether we want to shard m x k x n contraction over the inner - // (contraction) dimension (k). - static bool shardByInnerDim(Index m, Index n, Index k, int num_threads, - int num_threads_by_k) { - std::ptrdiff_t bufsize = m * n * sizeof(Scalar); - bool shard_by_k = false; - if (n == 1 || // If mat*vec or... - num_threads_by_k < 2 || // running single threaded or... - num_threads_by_k < - num_threads || // sharding by k gives less parallelism or... - bufsize > l3CacheSize() / num_threads_by_k || // need more buffer space - // than L3 cache or... - k / num_threads_by_k < 2 * Traits::nr) { // k per thread is tiny. - shard_by_k = false; - } else if (numext::maxi(m, n) / num_threads < - Traits::nr || // both other dimensions are tiny or... - // k per thread is not small and... - (k / num_threads_by_k > 8 * Traits::nr && - // one of the outer dimensions is tiny or sharding by k offers - // more parallelism. - (numext::mini(m, n) < 2 * Traits::nr || - num_threads_by_k > num_threads))) { - shard_by_k = true; - } - return shard_by_k; - } - - TensorOpCost contractionCostPerInnerDim(Index m, Index n, Index k) const { - // Compute cost. - const int output_packet_size = internal::unpacket_traits<PacketReturnType>::size; - TensorOpCost cost(0, 0, (computeBandwidth(true, m, n, k) * m) * n, true, output_packet_size); - // Output stores. - cost += TensorOpCost(0, sizeof(CoeffReturnType), 0, true, output_packet_size); - TensorOpCost lhsCost = this->m_leftImpl.costPerCoeff(true) * m; - TensorOpCost rhsCost = this->m_rightImpl.costPerCoeff(true) * n; - // Since the inner gemm kernel is always sharded by column, the lhs - // load cost is negligible. - lhsCost.dropMemoryCost(); - return cost + lhsCost + rhsCost; - } - - int numThreadsInnerDim(Index m, Index n, Index k) const { - const int output_packet_size = internal::unpacket_traits<PacketReturnType>::size; - TensorOpCost cost = contractionCostPerInnerDim(m, n, k); - double total_parallel_cost = - TensorCostModel<ThreadPoolDevice>::totalCost(k, cost); - // Cost of reduction step accumulating the m*n per-thread buffers into the - // result. - double reduction_cost = TensorCostModel<ThreadPoolDevice>::totalCost( - m * n, TensorOpCost(2, 1, 1, true, output_packet_size)); - int num_threads = 1; - double min_cost = total_parallel_cost; - double kPerThreadOverHead = 3000; - double kFixedOverHead = 100000; - for (int nt = 2; nt <= this->m_device.numThreads(); nt += 2) { - double sequential_cost = - kFixedOverHead + nt * (reduction_cost + kPerThreadOverHead); - double parallel_cost = total_parallel_cost / nt + sequential_cost; - if (parallel_cost < min_cost) { - num_threads = nt; - min_cost = parallel_cost; - } - } - return num_threads; - } - - double computeBandwidth(bool shard_by_col, Index bm, Index bn, - Index bk) const { - // Peak VFMA bandwidth is 0.5. However if we have not enough data for - // vectorization bandwidth drops. The 4.0 and 2.0 bandwidth is determined - // experimentally. - double computeBandwidth = - bk == 1 ? 4.0 - : (shard_by_col ? bn : bm) < Traits::nr || - (shard_by_col ? bm : bn) < Traits::mr - ? 2.0 - : 0.5; -#ifndef EIGEN_VECTORIZE_FMA - // Bandwidth of all of VFMA/MULPS/ADDPS is 0.5 on latest Intel processors. - // However for MULPS/ADDPS we have dependent sequence of 2 such - // instructions, - // so overall bandwidth is 1.0. - if (computeBandwidth == 0.5) computeBandwidth = 1.0; -#endif - return computeBandwidth; - } - -}; - -} // end namespace Eigen - -#endif // EIGEN_USE_THREADS -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_THREAD_POOL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConversion.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConversion.h deleted file mode 100644 index cdbafbbb..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConversion.h +++ /dev/null @@ -1,429 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H - -namespace Eigen { - -/** \class TensorConversionOp - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor conversion class. This class makes it possible to vectorize - * type casting operations when the number of scalars per packet in the source - * and the destination type differ - */ -namespace internal { -template<typename TargetType, typename XprType> -struct traits<TensorConversionOp<TargetType, XprType> > -{ - // Type promotion to handle the case where the types of the lhs and the rhs are different. - typedef TargetType Scalar; - typedef typename traits<XprType>::StorageKind StorageKind; - typedef typename traits<XprType>::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = traits<XprType>::NumDimensions; - static const int Layout = traits<XprType>::Layout; - enum { Flags = 0 }; - typedef typename TypeConversion<Scalar, typename traits<XprType>::PointerType>::type PointerType; -}; - -template<typename TargetType, typename XprType> -struct eval<TensorConversionOp<TargetType, XprType>, Eigen::Dense> -{ - typedef const TensorConversionOp<TargetType, XprType>& type; -}; - -template<typename TargetType, typename XprType> -struct nested<TensorConversionOp<TargetType, XprType>, 1, typename eval<TensorConversionOp<TargetType, XprType> >::type> -{ - typedef TensorConversionOp<TargetType, XprType> type; -}; - -} // end namespace internal - - -template <typename TensorEvaluator, typename SrcPacket, typename TgtPacket, int SrcCoeffRatio, int TgtCoeffRatio> -struct PacketConverter { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketConverter(const TensorEvaluator& impl) - : m_impl(impl) {} - - template<int LoadMode, typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const { - return internal::pcast<SrcPacket, TgtPacket>(m_impl.template packet<LoadMode>(index)); - } - - private: - const TensorEvaluator& m_impl; -}; - - -template <typename TensorEvaluator, typename SrcPacket, typename TgtPacket> -struct PacketConverter<TensorEvaluator, SrcPacket, TgtPacket, 2, 1> { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketConverter(const TensorEvaluator& impl) - : m_impl(impl) {} - - template<int LoadMode, typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const { - const int SrcPacketSize = internal::unpacket_traits<SrcPacket>::size; - - SrcPacket src1 = m_impl.template packet<LoadMode>(index); - SrcPacket src2 = m_impl.template packet<LoadMode>(index + SrcPacketSize); - TgtPacket result = internal::pcast<SrcPacket, TgtPacket>(src1, src2); - return result; - } - - private: - const TensorEvaluator& m_impl; -}; - -template <typename TensorEvaluator, typename SrcPacket, typename TgtPacket> -struct PacketConverter<TensorEvaluator, SrcPacket, TgtPacket, 4, 1> { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketConverter(const TensorEvaluator& impl) - : m_impl(impl) {} - - template<int LoadMode, typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const { - const int SrcPacketSize = internal::unpacket_traits<SrcPacket>::size; - - SrcPacket src1 = m_impl.template packet<LoadMode>(index); - SrcPacket src2 = m_impl.template packet<LoadMode>(index + SrcPacketSize); - SrcPacket src3 = m_impl.template packet<LoadMode>(index + 2 * SrcPacketSize); - SrcPacket src4 = m_impl.template packet<LoadMode>(index + 3 * SrcPacketSize); - TgtPacket result = internal::pcast<SrcPacket, TgtPacket>(src1, src2, src3, src4); - return result; - } - - private: - const TensorEvaluator& m_impl; -}; - -template <typename TensorEvaluator, typename SrcPacket, typename TgtPacket> -struct PacketConverter<TensorEvaluator, SrcPacket, TgtPacket, 1, 2> { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketConverter(const TensorEvaluator& impl) - : m_impl(impl), m_maxIndex(impl.dimensions().TotalSize()) {} - - template<int LoadMode, typename Index> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const { - const int SrcPacketSize = internal::unpacket_traits<SrcPacket>::size; - // Only call m_impl.packet() when we have direct access to the underlying data. This - // ensures that we don't compute the subexpression twice. We may however load some - // coefficients twice, but in practice this doesn't negatively impact performance. - if (m_impl.data() && (index + SrcPacketSize < m_maxIndex)) { - // Force unaligned memory loads since we can't ensure alignment anymore - return internal::pcast<SrcPacket, TgtPacket>(m_impl.template packet<Unaligned>(index)); - } else { - const int TgtPacketSize = internal::unpacket_traits<TgtPacket>::size; - typedef typename internal::unpacket_traits<SrcPacket>::type SrcType; - typedef typename internal::unpacket_traits<TgtPacket>::type TgtType; - internal::scalar_cast_op<SrcType, TgtType> converter; - EIGEN_ALIGN_MAX typename internal::unpacket_traits<TgtPacket>::type values[TgtPacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < TgtPacketSize; ++i) { - values[i] = converter(m_impl.coeff(index+i)); - } - TgtPacket rslt = internal::pload<TgtPacket>(values); - return rslt; - } - } - - private: - const TensorEvaluator& m_impl; - const typename TensorEvaluator::Index m_maxIndex; -}; - -template<typename TargetType, typename XprType> -class TensorConversionOp : public TensorBase<TensorConversionOp<TargetType, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename internal::traits<TensorConversionOp>::Scalar Scalar; - typedef typename internal::traits<TensorConversionOp>::StorageKind StorageKind; - typedef typename internal::traits<TensorConversionOp>::Index Index; - typedef typename internal::nested<TensorConversionOp>::type Nested; - typedef Scalar CoeffReturnType; - typedef typename NumTraits<Scalar>::Real RealScalar; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConversionOp(const XprType& xpr) - : m_xpr(xpr) {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; -}; - -template <bool SameType, typename Eval, typename EvalPointerType> struct ConversionSubExprEval { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Eval& impl, EvalPointerType) { - impl.evalSubExprsIfNeeded(NULL); - return true; - } -}; - -template <typename Eval, typename EvalPointerType> struct ConversionSubExprEval<true, Eval, EvalPointerType> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Eval& impl, EvalPointerType data) { - return impl.evalSubExprsIfNeeded(data); - } -}; - -#ifdef EIGEN_USE_THREADS -template <bool SameType, typename Eval, typename EvalPointerType, - typename EvalSubExprsCallback> -struct ConversionSubExprEvalAsync { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run( - Eval& impl, EvalPointerType, EvalSubExprsCallback done) { - impl.evalSubExprsIfNeededAsync(nullptr, std::move(done)); - } -}; - -template <typename Eval, typename EvalPointerType, - typename EvalSubExprsCallback> -struct ConversionSubExprEvalAsync<true, Eval, EvalPointerType, - EvalSubExprsCallback> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run( - Eval& impl, EvalPointerType data, EvalSubExprsCallback done) { - impl.evalSubExprsIfNeededAsync(data, std::move(done)); - } -}; -#endif - -namespace internal { - -template <typename SrcType, typename TargetType, bool IsSameT> -struct CoeffConv { - template <typename ArgType, typename Device> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetType run(const TensorEvaluator<ArgType, Device>& impl, Index index) { - internal::scalar_cast_op<SrcType, TargetType> converter; - return converter(impl.coeff(index)); - } -}; - -template <typename SrcType, typename TargetType> -struct CoeffConv<SrcType, TargetType, true> { - template <typename ArgType, typename Device> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetType run(const TensorEvaluator<ArgType, Device>& impl, Index index) { - return impl.coeff(index); - } -}; - -template <typename SrcPacket, typename TargetPacket, int LoadMode, bool ActuallyVectorize, bool IsSameT> -struct PacketConv { - typedef typename internal::unpacket_traits<SrcPacket>::type SrcType; - typedef typename internal::unpacket_traits<TargetPacket>::type TargetType; - - static const int PacketSize = internal::unpacket_traits<TargetPacket>::size; - - template <typename ArgType, typename Device> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator<ArgType, Device>& impl, Index index) { - internal::scalar_cast_op<SrcType, TargetType> converter; - EIGEN_ALIGN_MAX typename internal::remove_const<TargetType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = converter(impl.coeff(index+i)); - } - TargetPacket rslt = internal::pload<TargetPacket>(values); - return rslt; - } -}; - -template <typename SrcPacket, typename TargetPacket, int LoadMode, bool IsSameT> -struct PacketConv<SrcPacket, TargetPacket, LoadMode, true, IsSameT> { - typedef typename internal::unpacket_traits<SrcPacket>::type SrcType; - typedef typename internal::unpacket_traits<TargetPacket>::type TargetType; - - template <typename ArgType, typename Device> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator<ArgType, Device>& impl, Index index) { - const int SrcCoeffRatio = internal::type_casting_traits<SrcType, TargetType>::SrcCoeffRatio; - const int TgtCoeffRatio = internal::type_casting_traits<SrcType, TargetType>::TgtCoeffRatio; - PacketConverter<TensorEvaluator<ArgType, Device>, SrcPacket, TargetPacket, - SrcCoeffRatio, TgtCoeffRatio> converter(impl); - return converter.template packet<LoadMode>(index); - } -}; - -template <typename SrcPacket, typename TargetPacket, int LoadMode> -struct PacketConv<SrcPacket, TargetPacket, LoadMode, /*ActuallyVectorize=*/false, /*IsSameT=*/true> { - typedef typename internal::unpacket_traits<TargetPacket>::type TargetType; - static const int PacketSize = internal::unpacket_traits<TargetPacket>::size; - - template <typename ArgType, typename Device> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator<ArgType, Device>& impl, Index index) { - EIGEN_ALIGN_MAX typename internal::remove_const<TargetType>::type values[PacketSize]; - for (int i = 0; i < PacketSize; ++i) values[i] = impl.coeff(index+i); - return internal::pload<TargetPacket>(values); - } -}; - -template <typename SrcPacket, typename TargetPacket, int LoadMode> -struct PacketConv<SrcPacket, TargetPacket, LoadMode, /*ActuallyVectorize=*/true, /*IsSameT=*/true> { - template <typename ArgType, typename Device> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator<ArgType, Device>& impl, Index index) { - return impl.template packet<LoadMode>(index); - } -}; - -} // namespace internal - -// Eval as rvalue -template<typename TargetType, typename ArgType, typename Device> -struct TensorEvaluator<const TensorConversionOp<TargetType, ArgType>, Device> -{ - typedef TensorConversionOp<TargetType, ArgType> XprType; - typedef typename XprType::Index Index; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions; - typedef TargetType Scalar; - typedef TargetType CoeffReturnType; - typedef typename internal::remove_all<typename internal::traits<ArgType>::Scalar>::type SrcType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef typename PacketType<SrcType, Device>::type PacketSourceType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - static const bool IsSameType = internal::is_same<TargetType, SrcType>::value; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = - #ifndef EIGEN_USE_SYCL - true, - #else - TensorEvaluator<ArgType, Device>::PacketAccess & - internal::type_casting_traits<SrcType, TargetType>::VectorizedCast, - #endif - BlockAccess = TensorEvaluator<ArgType, Device>::BlockAccess, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - RawAccess = false - }; - - static const int NumDims = internal::array_size<Dimensions>::value; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename TensorEvaluator<const ArgType, Device>::TensorBlock - ArgTensorBlock; - - struct TensorConversionOpBlockFactory { - template <typename ArgXprType> - struct XprType { - typedef TensorConversionOp<TargetType, const ArgXprType> type; - }; - - template <typename ArgXprType> - typename XprType<ArgXprType>::type expr(const ArgXprType& expr) const { - return typename XprType<ArgXprType>::type(expr); - } - }; - - typedef internal::TensorUnaryExprBlock<TensorConversionOpBlockFactory, - ArgTensorBlock> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device) - { - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_impl.dimensions(); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) - { - return ConversionSubExprEval<IsSameType, TensorEvaluator<ArgType, Device>, EvaluatorPointerType>::run(m_impl, data); - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType data, EvalSubExprsCallback done) { - ConversionSubExprEvalAsync<IsSameType, TensorEvaluator<ArgType, Device>, - EvaluatorPointerType, - EvalSubExprsCallback>::run(m_impl, data, std::move(done)); - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() - { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return internal::CoeffConv<SrcType, TargetType, IsSameType>::run(m_impl,index); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType - packet(Index index) const { - // If we are not going to do the cast, we just need to check that base - // TensorEvaluator has packet access. Otherwise we also need to make sure, - // that we have an implementation of vectorized cast. - const bool Vectorizable = - IsSameType - ? TensorEvaluator<ArgType, Device>::PacketAccess - : TensorEvaluator<ArgType, Device>::PacketAccess & - internal::type_casting_traits<SrcType, TargetType>::VectorizedCast; - - return internal::PacketConv<PacketSourceType, PacketReturnType, LoadMode, - Vectorizable, IsSameType>::run(m_impl, index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - const double cast_cost = TensorOpCost::CastCost<SrcType, TargetType>(); - if (vectorized) { - const double SrcCoeffRatio = - internal::type_casting_traits<SrcType, TargetType>::SrcCoeffRatio; - const double TgtCoeffRatio = - internal::type_casting_traits<SrcType, TargetType>::TgtCoeffRatio; - return m_impl.costPerCoeff(vectorized) * (SrcCoeffRatio / PacketSize) + - TensorOpCost(0, 0, TgtCoeffRatio * (cast_cost / PacketSize)); - } else { - return m_impl.costPerCoeff(vectorized) + TensorOpCost(0, 0, cast_cost); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - return m_impl.getResourceRequirements(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - return TensorBlock(m_impl.block(desc, scratch), - TensorConversionOpBlockFactory()); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - - /// required by sycl in order to extract the sycl accessor - const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; } -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - protected: - TensorEvaluator<ArgType, Device> m_impl; -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConvolution.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConvolution.h deleted file mode 100644 index 27ad9f14..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConvolution.h +++ /dev/null @@ -1,1132 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONVOLUTION_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONVOLUTION_H - -namespace Eigen { - -/** \class TensorConvolution - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor convolution class. - * - * - */ -namespace internal { - -template <typename Index, typename InputDims, int NumKernelDims, int Layout> -class IndexMapper { - public: - IndexMapper(const InputDims& input_dims, const array<Index, NumKernelDims>& kernel_dims, - const array<Index, NumKernelDims>& indices) { - - array<Index, NumDims> dimensions = input_dims; - for (int i = 0; i < NumKernelDims; ++i) { - const Index index = indices[i]; - const Index input_dim = input_dims[index]; - const Index kernel_dim = kernel_dims[i]; - const Index result_dim = input_dim - kernel_dim + 1; - dimensions[index] = result_dim; - } - - array<Index, NumDims> inputStrides; - array<Index, NumDims> outputStrides; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - inputStrides[0] = 1; - outputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - inputStrides[i] = inputStrides[i-1] * input_dims[i-1]; - outputStrides[i] = outputStrides[i-1] * dimensions[i-1]; - } - } else { - inputStrides[NumDims - 1] = 1; - outputStrides[NumDims - 1] = 1; - for (int i = static_cast<int>(NumDims) - 2; i >= 0; --i) { - inputStrides[i] = inputStrides[i + 1] * input_dims[i + 1]; - outputStrides[i] = outputStrides[i + 1] * dimensions[i + 1]; - } - } - - array<Index, NumDims> gpuInputDimensions; - array<Index, NumDims> gpuOutputDimensions; - array<Index, NumDims> tmp = dimensions; - array<Index, NumDims> ordering; - const size_t offset = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? 0 - : NumDims - NumKernelDims; - for (int i = 0; i < NumKernelDims; ++i) { - const Index index = i + offset; - ordering[index] = indices[i]; - tmp[indices[i]] = -1; - gpuInputDimensions[index] = input_dims[indices[i]]; - gpuOutputDimensions[index] = dimensions[indices[i]]; - } - - int written = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? NumKernelDims - : 0; - for (int i = 0; i < NumDims; ++i) { - if (tmp[i] >= 0) { - ordering[written] = i; - gpuInputDimensions[written] = input_dims[i]; - gpuOutputDimensions[written] = dimensions[i]; - ++written; - } - } - - for (int i = 0; i < NumDims; ++i) { - m_inputStrides[i] = inputStrides[ordering[i]]; - m_outputStrides[i] = outputStrides[ordering[i]]; - } - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = 0; i < NumDims; ++i) { - if (i > NumKernelDims) { - m_gpuInputStrides[i] = - m_gpuInputStrides[i - 1] * gpuInputDimensions[i - 1]; - m_gpuOutputStrides[i] = - m_gpuOutputStrides[i - 1] * gpuOutputDimensions[i - 1]; - } else { - m_gpuInputStrides[i] = 1; - m_gpuOutputStrides[i] = 1; - } - } - } else { - for (int i = NumDims - 1; i >= 0; --i) { - if (static_cast<size_t>(i + 1) < offset) { - m_gpuInputStrides[i] = - m_gpuInputStrides[i + 1] * gpuInputDimensions[i + 1]; - m_gpuOutputStrides[i] = - m_gpuOutputStrides[i + 1] * gpuOutputDimensions[i + 1]; - } else { - m_gpuInputStrides[i] = 1; - m_gpuOutputStrides[i] = 1; - } - } - } - } - - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Index mapGpuInputPlaneToTensorInputOffset(Index p) const { - Index inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int d = NumDims - 1; d > NumKernelDims; --d) { - const Index idx = p / m_gpuInputStrides[d]; - inputIndex += idx * m_inputStrides[d]; - p -= idx * m_gpuInputStrides[d]; - } - inputIndex += p * m_inputStrides[NumKernelDims]; - } else { - std::ptrdiff_t limit = 0; - if (NumKernelDims < NumDims) { - limit = NumDims - NumKernelDims - 1; - } - for (int d = 0; d < limit; ++d) { - const Index idx = p / m_gpuInputStrides[d]; - inputIndex += idx * m_inputStrides[d]; - p -= idx * m_gpuInputStrides[d]; - } - inputIndex += p * m_inputStrides[limit]; - } - return inputIndex; - } - - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Index mapGpuOutputPlaneToTensorOutputOffset(Index p) const { - Index outputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int d = NumDims - 1; d > NumKernelDims; --d) { - const Index idx = p / m_gpuOutputStrides[d]; - outputIndex += idx * m_outputStrides[d]; - p -= idx * m_gpuOutputStrides[d]; - } - outputIndex += p * m_outputStrides[NumKernelDims]; - } else { - std::ptrdiff_t limit = 0; - if (NumKernelDims < NumDims) { - limit = NumDims - NumKernelDims - 1; - } - for (int d = 0; d < limit; ++d) { - const Index idx = p / m_gpuOutputStrides[d]; - outputIndex += idx * m_outputStrides[d]; - p -= idx * m_gpuOutputStrides[d]; - } - outputIndex += p * m_outputStrides[limit]; - } - return outputIndex; - } - - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Index mapGpuInputKernelToTensorInputOffset(Index i) const { - const size_t offset = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? 0 - : NumDims - NumKernelDims; - return i * m_inputStrides[offset]; - } - - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Index mapGpuOutputKernelToTensorOutputOffset(Index i) const { - const size_t offset = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? 0 - : NumDims - NumKernelDims; - return i * m_outputStrides[offset]; - } - - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Index mapGpuInputKernelToTensorInputOffset(Index i, Index j) const { - const size_t offset = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? 0 - : NumDims - NumKernelDims; - return i * m_inputStrides[offset] + j * m_inputStrides[offset + 1]; - } - - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Index mapGpuOutputKernelToTensorOutputOffset(Index i, Index j) const { - const size_t offset = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? 0 - : NumDims - NumKernelDims; - return i * m_outputStrides[offset] + j * m_outputStrides[offset + 1]; - } - - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Index mapGpuInputKernelToTensorInputOffset(Index i, Index j, Index k) const { - const size_t offset = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? 0 - : NumDims - NumKernelDims; - return i * m_inputStrides[offset] + j * m_inputStrides[offset + 1] + - k * m_inputStrides[offset + 2]; - } - - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Index mapGpuOutputKernelToTensorOutputOffset(Index i, Index j, Index k) const { - const size_t offset = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? 0 - : NumDims - NumKernelDims; - return i * m_outputStrides[offset] + j * m_outputStrides[offset + 1] + - k * m_outputStrides[offset + 2]; - } - - private: - static const int NumDims = internal::array_size<InputDims>::value; - array<Index, NumDims> m_inputStrides; - array<Index, NumDims> m_outputStrides; - array<Index, NumDims> m_gpuInputStrides; - array<Index, NumDims> m_gpuOutputStrides; -}; - - - -template<typename Dimensions, typename InputXprType, typename KernelXprType> -struct traits<TensorConvolutionOp<Dimensions, InputXprType, KernelXprType> > -{ - // Type promotion to handle the case where the types of the lhs and the rhs are different. - typedef typename promote_storage_type<typename InputXprType::Scalar, - typename KernelXprType::Scalar>::ret Scalar; - typedef typename promote_storage_type<typename traits<InputXprType>::StorageKind, - typename traits<KernelXprType>::StorageKind>::ret StorageKind; - typedef typename promote_index_type<typename traits<InputXprType>::Index, - typename traits<KernelXprType>::Index>::type Index; - typedef typename InputXprType::Nested LhsNested; - typedef typename KernelXprType::Nested RhsNested; - typedef typename remove_reference<LhsNested>::type _LhsNested; - typedef typename remove_reference<RhsNested>::type _RhsNested; - static const int NumDimensions = traits<InputXprType>::NumDimensions; - static const int Layout = traits<InputXprType>::Layout; - typedef typename conditional<Pointer_type_promotion<typename InputXprType::Scalar, Scalar>::val, - typename traits<InputXprType>::PointerType, typename traits<KernelXprType>::PointerType>::type PointerType; - - enum { - Flags = 0 - }; -}; - -template<typename Dimensions, typename InputXprType, typename KernelXprType> -struct eval<TensorConvolutionOp<Dimensions, InputXprType, KernelXprType>, Eigen::Dense> -{ - typedef const TensorConvolutionOp<Dimensions, InputXprType, KernelXprType>& type; -}; - -template<typename Dimensions, typename InputXprType, typename KernelXprType> -struct nested<TensorConvolutionOp<Dimensions, InputXprType, KernelXprType>, 1, typename eval<TensorConvolutionOp<Dimensions, InputXprType, KernelXprType> >::type> -{ - typedef TensorConvolutionOp<Dimensions, InputXprType, KernelXprType> type; -}; - -} // end namespace internal - - - -template<typename Indices, typename InputXprType, typename KernelXprType> -class TensorConvolutionOp : public TensorBase<TensorConvolutionOp<Indices, InputXprType, KernelXprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorConvolutionOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename internal::promote_storage_type<typename InputXprType::CoeffReturnType, - typename KernelXprType::CoeffReturnType>::ret CoeffReturnType; - typedef typename Eigen::internal::nested<TensorConvolutionOp>::type Nested; - typedef typename Eigen::internal::traits<TensorConvolutionOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorConvolutionOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConvolutionOp(const InputXprType& input, const KernelXprType& kernel, const Indices& dims) - : m_input_xpr(input), m_kernel_xpr(kernel), m_indices(dims) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Indices& indices() const { return m_indices; } - - /** \returns the nested expressions */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const typename internal::remove_all<typename InputXprType::Nested>::type& - inputExpression() const { return m_input_xpr; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const typename internal::remove_all<typename KernelXprType::Nested>::type& - kernelExpression() const { return m_kernel_xpr; } - - protected: - typename InputXprType::Nested m_input_xpr; - typename KernelXprType::Nested m_kernel_xpr; - const Indices m_indices; -}; - - -template<typename Indices, typename InputArgType, typename KernelArgType, typename Device> -struct TensorEvaluator<const TensorConvolutionOp<Indices, InputArgType, KernelArgType>, Device> -{ - typedef TensorConvolutionOp<Indices, InputArgType, KernelArgType> XprType; - - static const int NumDims = internal::array_size<typename TensorEvaluator<InputArgType, Device>::Dimensions>::value; - static const int NumKernelDims = internal::array_size<Indices>::value; - typedef typename XprType::Index Index; - typedef DSizes<Index, NumDims> Dimensions; - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<Scalar, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = TensorEvaluator<InputArgType, Device>::IsAligned & TensorEvaluator<KernelArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<InputArgType, Device>::PacketAccess & TensorEvaluator<KernelArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<InputArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_inputImpl(op.inputExpression(), device), m_kernelImpl(op.kernelExpression(), device), m_kernelArg(op.kernelExpression()), m_kernel(NULL), m_local_kernel(false), m_device(device) - { - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<InputArgType, Device>::Layout) == static_cast<int>(TensorEvaluator<KernelArgType, Device>::Layout)), YOU_MADE_A_PROGRAMMING_MISTAKE); - - const typename TensorEvaluator<InputArgType, Device>::Dimensions& input_dims = m_inputImpl.dimensions(); - const typename TensorEvaluator<KernelArgType, Device>::Dimensions& kernel_dims = m_kernelImpl.dimensions(); - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_inputStride[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_inputStride[i] = m_inputStride[i - 1] * input_dims[i - 1]; - } - } else { - m_inputStride[NumDims - 1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_inputStride[i] = m_inputStride[i + 1] * input_dims[i + 1]; - } - } - - m_dimensions = m_inputImpl.dimensions(); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = 0; i < NumKernelDims; ++i) { - const Index index = op.indices()[i]; - const Index input_dim = input_dims[index]; - const Index kernel_dim = kernel_dims[i]; - const Index result_dim = input_dim - kernel_dim + 1; - m_dimensions[index] = result_dim; - if (i > 0) { - m_kernelStride[i] = m_kernelStride[i - 1] * kernel_dims[i - 1]; - } else { - m_kernelStride[0] = 1; - } - m_indexStride[i] = m_inputStride[index]; - } - - m_outputStride[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_outputStride[i] = m_outputStride[i - 1] * m_dimensions[i - 1]; - } - } else { - for (int i = NumKernelDims - 1; i >= 0; --i) { - const Index index = op.indices()[i]; - const Index input_dim = input_dims[index]; - const Index kernel_dim = kernel_dims[i]; - const Index result_dim = input_dim - kernel_dim + 1; - m_dimensions[index] = result_dim; - if (i < NumKernelDims - 1) { - m_kernelStride[i] = m_kernelStride[i + 1] * kernel_dims[i + 1]; - } else { - m_kernelStride[NumKernelDims - 1] = 1; - } - m_indexStride[i] = m_inputStride[index]; - } - - m_outputStride[NumDims - 1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_outputStride[i] = m_outputStride[i + 1] * m_dimensions[i + 1]; - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(Scalar*) { - m_inputImpl.evalSubExprsIfNeeded(NULL); - preloadKernel(); - return true; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_inputImpl.cleanup(); - if (m_local_kernel) { - m_device.deallocate((void*)m_kernel); - m_local_kernel = false; - } - m_kernel = NULL; - } - - void evalTo(typename XprType::Scalar* buffer) { - evalSubExprsIfNeeded(NULL); - for (int i = 0; i < dimensions().TotalSize(); ++i) { - buffer[i] += coeff(i); - } - cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - CoeffReturnType result = CoeffReturnType(0); - convolve(firstInput(index), 0, NumKernelDims-1, result); - return result; - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC PacketReturnType packet(const Index index) const - { - Index indices[2] = {index, index+PacketSize-1}; - Index startInputs[2] = {0, 0}; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumDims - 1; i > 0; --i) { - const Index idx0 = indices[0] / m_outputStride[i]; - const Index idx1 = indices[1] / m_outputStride[i]; - startInputs[0] += idx0 * m_inputStride[i]; - startInputs[1] += idx1 * m_inputStride[i]; - indices[0] -= idx0 * m_outputStride[i]; - indices[1] -= idx1 * m_outputStride[i]; - } - } else { - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx0 = indices[0] / m_outputStride[i]; - const Index idx1 = indices[1] / m_outputStride[i]; - startInputs[0] += idx0 * m_inputStride[i]; - startInputs[1] += idx1 * m_inputStride[i]; - indices[0] -= idx0 * m_outputStride[i]; - indices[1] -= idx1 * m_outputStride[i]; - } - } - startInputs[0] += indices[0]; - startInputs[1] += indices[1]; - - if (startInputs[1]-startInputs[0] == PacketSize-1) { - PacketReturnType result = internal::pset1<PacketReturnType>(0); - convolvePacket(startInputs[0], 0, NumKernelDims-1, result); - return result; - } else { - EIGEN_ALIGN_MAX Scalar data[PacketSize]; - data[0] = Scalar(0); - convolve(startInputs[0], 0, NumKernelDims-1, data[0]); - for (int i = 1; i < PacketSize-1; ++i) { - data[i] = Scalar(0); - convolve(firstInput(index+i), 0, NumKernelDims-1, data[i]); - } - data[PacketSize-1] = Scalar(0); - convolve(startInputs[1], 0, NumKernelDims-1, data[PacketSize-1]); - return internal::pload<PacketReturnType>(data); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - const double kernel_size = m_kernelImpl.dimensions().TotalSize(); - // We ignore the use of fused multiply-add. - const double convolve_compute_cost = - TensorOpCost::AddCost<Scalar>() + TensorOpCost::MulCost<Scalar>(); - const double firstIndex_compute_cost = - NumDims * - (2 * TensorOpCost::AddCost<Index>() + 2 * TensorOpCost::MulCost<Index>() + - TensorOpCost::DivCost<Index>()); - return TensorOpCost(0, 0, firstIndex_compute_cost, vectorized, PacketSize) + - kernel_size * (m_inputImpl.costPerCoeff(vectorized) + - m_kernelImpl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, convolve_compute_cost, vectorized, - PacketSize)); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - - private: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index firstInput(Index index) const { - Index startInput = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_outputStride[i]; - startInput += idx * m_inputStride[i]; - index -= idx * m_outputStride[i]; - } - } else { - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_outputStride[i]; - startInput += idx * m_inputStride[i]; - index -= idx * m_outputStride[i]; - } - } - startInput += index; - return startInput; - } - - EIGEN_DEVICE_FUNC void convolve(Index firstIndex, Index firstKernel, int DimIndex, CoeffReturnType& accum) const { - for (int j = 0; j < m_kernelImpl.dimensions()[DimIndex]; ++j) { - const Index input = firstIndex + j * m_indexStride[DimIndex]; - const Index kernel = firstKernel + j * m_kernelStride[DimIndex]; - if (DimIndex > 0) { - convolve(input, kernel, DimIndex-1, accum); - } else { - accum += m_inputImpl.coeff(input) * m_kernel[kernel]; - } - } - } - - template <typename Packet> - EIGEN_DEVICE_FUNC void convolvePacket(Index firstIndex, Index firstKernel, int DimIndex, Packet& accum) const { - for (int j = 0; j < m_kernelImpl.dimensions()[DimIndex]; ++j) { - const Index input = firstIndex + j * m_indexStride[DimIndex]; - const Index kernel = firstKernel + j * m_kernelStride[DimIndex]; - if (DimIndex > 0) { - convolvePacket(input, kernel, DimIndex-1, accum); - } else { - accum = internal::pmadd<Packet>(m_inputImpl.template packet<Unaligned>(input), internal::pset1<Packet>(m_kernel[kernel]), accum); - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void preloadKernel() { - // Don't make a local copy of the kernel unless we have to (i.e. it's an - // expression that needs to be evaluated) - const Scalar* in_place = m_kernelImpl.data(); - if (in_place) { - m_kernel = in_place; - m_local_kernel = false; - } else { - size_t kernel_sz = m_kernelImpl.dimensions().TotalSize() * sizeof(Scalar); - Scalar* local = (Scalar*)m_device.allocate_temp(kernel_sz); - typedef TensorEvalToOp<const KernelArgType> EvalTo; - EvalTo evalToTmp(local, m_kernelArg); - const bool Vectorize = internal::IsVectorizable<Device, KernelArgType>::value; - internal::TensorExecutor<const EvalTo, Device, Vectorize>::run(evalToTmp, m_device); - - m_kernel = local; - m_local_kernel = true; - } - } - - array<Index, NumDims> m_inputStride; - array<Index, NumDims> m_outputStride; - - array<Index, NumKernelDims> m_indexStride; - array<Index, NumKernelDims> m_kernelStride; - TensorEvaluator<InputArgType, Device> m_inputImpl; - TensorEvaluator<KernelArgType, Device> m_kernelImpl; - Dimensions m_dimensions; - - KernelArgType m_kernelArg; - const Scalar* m_kernel; - bool m_local_kernel; - const Device EIGEN_DEVICE_REF m_device; -}; - - - - -// Use an optimized implementation of the evaluation code for GPUs whenever possible. -#if defined(EIGEN_USE_GPU) && defined(EIGEN_GPUCC) - -template <int StaticKernelSize> -struct GetKernelSize { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int operator() (const int /*kernelSize*/) const { - return StaticKernelSize; - } -}; -template <> -struct GetKernelSize<Dynamic> { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int operator() (const int kernelSize) const { - return kernelSize; - } -}; - -template <typename InputEvaluator, typename Index, typename InputDims, - int StaticKernelSize> -__global__ void EigenConvolutionKernel1D( - InputEvaluator eval, - const internal::IndexMapper<Index, InputDims, 1, InputEvaluator::Layout> - indexMapper, - const float* __restrict kernel, const int numPlanes, const int numX, - const int maxX, const int kernelSize, float* buffer) { -#if defined(EIGEN_HIPCC) - HIP_DYNAMIC_SHARED(float, s) -#else - extern __shared__ float s[]; -#endif - - const int first_x = blockIdx.x * maxX; - const int last_x = (first_x + maxX < numX ? first_x + maxX : numX) - 1; - const int num_x_input = last_x - first_x + GetKernelSize<StaticKernelSize>()(kernelSize); - const int num_x_output = last_x - first_x + 1; - - const int first_plane = blockIdx.y * blockDim.y; - const int plane_stride = blockDim.y * gridDim.y; - - for (int p = first_plane + threadIdx.y; p < numPlanes; p += plane_stride) { - // Load inputs to shared memory - const int plane_input_offset = indexMapper.mapGpuInputPlaneToTensorInputOffset(p); - const int plane_kernel_offset = threadIdx.y * num_x_input; - #pragma unroll - for (int i = threadIdx.x; i < num_x_input; i += blockDim.x) { - const int tensor_index = plane_input_offset + indexMapper.mapGpuInputKernelToTensorInputOffset(i+first_x); - s[i + plane_kernel_offset] = eval.coeff(tensor_index); - } - - __syncthreads(); - - // Compute the convolution - const int plane_output_offset = indexMapper.mapGpuOutputPlaneToTensorOutputOffset(p); - - #pragma unroll - for (int i = threadIdx.x; i < num_x_output; i += blockDim.x) { - const int kernel_offset = plane_kernel_offset + i; - float result = 0.0f; - #pragma unroll - for (int k = 0; k < GetKernelSize<StaticKernelSize>()(kernelSize); ++k) { - result += s[k + kernel_offset] * kernel[k]; - } - const int tensor_index = plane_output_offset + indexMapper.mapGpuOutputKernelToTensorOutputOffset(i+first_x); - buffer[tensor_index] = result; - } - __syncthreads(); - } -}; - -template <typename InputEvaluator, typename Index, typename InputDims, - int StaticKernelSizeX, int StaticKernelSizeY> -__global__ void EigenConvolutionKernel2D( - InputEvaluator eval, - const internal::IndexMapper<Index, InputDims, 2, InputEvaluator::Layout> - indexMapper, - const float* __restrict kernel, const int numPlanes, const int numX, - const int maxX, const int numY, const int maxY, const int kernelSizeX, - const int kernelSizeY, float* buffer) { -#if defined(EIGEN_HIPCC) - HIP_DYNAMIC_SHARED(float, s) -#else - extern __shared__ float s[]; -#endif - - const int first_x = blockIdx.x * maxX; - const int last_x = (first_x + maxX < numX ? first_x + maxX : numX) - 1; - const int num_x_input = last_x - first_x + GetKernelSize<StaticKernelSizeX>()(kernelSizeX); - const int num_x_output = last_x - first_x + 1; - - const int first_y = blockIdx.y * maxY; - const int last_y = (first_y + maxY < numY ? first_y + maxY : numY) - 1; - const int num_y_input = last_y - first_y + GetKernelSize<StaticKernelSizeY>()(kernelSizeY); - const int num_y_output = last_y - first_y + 1; - - const int first_plane = blockIdx.z * blockDim.z; - const int plane_stride = blockDim.z * gridDim.z; - - for (int p = first_plane + threadIdx.z; p < numPlanes; p += plane_stride) { - - const int plane_input_offset = indexMapper.mapGpuInputPlaneToTensorInputOffset(p); - const int plane_kernel_offset = threadIdx.z * num_y_input; - - // Load inputs to shared memory - #pragma unroll - for (int j = threadIdx.y; j < num_y_input; j += blockDim.y) { - const int input_offset = num_x_input * (j + plane_kernel_offset); - #pragma unroll - for (int i = threadIdx.x; i < num_x_input; i += blockDim.x) { - const int tensor_index = plane_input_offset + indexMapper.mapGpuInputKernelToTensorInputOffset(i+first_x, j+first_y); - s[i + input_offset] = eval.coeff(tensor_index); - } - } - - __syncthreads(); - - // Convolution - const int plane_output_offset = indexMapper.mapGpuOutputPlaneToTensorOutputOffset(p); - - #pragma unroll - for (int j = threadIdx.y; j < num_y_output; j += blockDim.y) { - #pragma unroll - for (int i = threadIdx.x; i < num_x_output; i += blockDim.x) { - float result = 0.0f; - #pragma unroll - for (int l = 0; l < GetKernelSize<StaticKernelSizeY>()(kernelSizeY); ++l) { - const int kernel_offset = kernelSizeX * l; - const int input_offset = i + num_x_input * (j + l + plane_kernel_offset); - #pragma unroll - for (int k = 0; k < GetKernelSize<StaticKernelSizeX>()(kernelSizeX); ++k) { - result += s[k + input_offset] * kernel[k + kernel_offset]; - } - } - const int tensor_index = plane_output_offset + indexMapper.mapGpuOutputKernelToTensorOutputOffset(i+first_x, j+first_y); - buffer[tensor_index] = result; - } - } - - __syncthreads(); - } -}; - -template <typename InputEvaluator, typename Index, typename InputDims> -__global__ void EigenConvolutionKernel3D( - InputEvaluator eval, - const internal::IndexMapper<Index, InputDims, 3, InputEvaluator::Layout> - indexMapper, - const float* __restrict kernel, const size_t numPlanes, const size_t numX, - const size_t maxX, const size_t numY, const size_t maxY, const size_t numZ, - const size_t maxZ, const size_t kernelSizeX, const size_t kernelSizeY, - const size_t kernelSizeZ, float* buffer) { -#if defined(EIGEN_HIPCC) - HIP_DYNAMIC_SHARED(float, s) -#else - extern __shared__ float s[]; -#endif - - // Load inputs to shared memory - const int first_x = blockIdx.x * maxX; - const int last_x = (first_x + maxX < numX ? first_x + maxX : numX) - 1; - const int num_x_input = last_x - first_x + kernelSizeX; - - const int first_y = blockIdx.y * maxY; - const int last_y = (first_y + maxY < numY ? first_y + maxY : numY) - 1; - const int num_y_input = last_y - first_y + kernelSizeY; - - const int first_z = blockIdx.z * maxZ; - const int last_z = (first_z + maxZ < numZ ? first_z + maxZ : numZ) - 1; - const int num_z_input = last_z - first_z + kernelSizeZ; - - for (int p = 0; p < numPlanes; ++p) { - - const int plane_input_offset = indexMapper.mapGpuInputPlaneToTensorInputOffset(p); - const int plane_kernel_offset = 0; - - for (int k = threadIdx.z; k < num_z_input; k += blockDim.z) { - for (int j = threadIdx.y; j < num_y_input; j += blockDim.y) { - for (int i = threadIdx.x; i < num_x_input; i += blockDim.x) { - const int tensor_index = plane_input_offset + indexMapper.mapGpuInputKernelToTensorInputOffset(i+first_x, j+first_y, k+first_z); - s[i + num_x_input * (j + num_y_input * (k + plane_kernel_offset))] = eval.coeff(tensor_index); - } - } - } - - __syncthreads(); - - // Convolution - const int num_z_output = last_z - first_z + 1; - const int num_y_output = last_y - first_y + 1; - const int num_x_output = last_x - first_x + 1; - const int plane_output_offset = indexMapper.mapGpuOutputPlaneToTensorOutputOffset(p); - - for (int k = threadIdx.z; k < num_z_output; k += blockDim.z) { - for (int j = threadIdx.y; j < num_y_output; j += blockDim.y) { - for (int i = threadIdx.x; i < num_x_output; i += blockDim.x) { - float result = 0.0f; - for (int n = 0; n < kernelSizeZ; ++n) { - for (int m = 0; m < kernelSizeY; ++m) { - for (int l = 0; l < kernelSizeX; ++l) { - result += s[i + l + num_x_input * (j + m + num_y_input * (k + n + plane_kernel_offset))] * kernel[l + kernelSizeX * (m + kernelSizeY * n)]; - } - } - } - const int tensor_index = plane_output_offset + indexMapper.mapGpuOutputKernelToTensorOutputOffset(i+first_x, j+first_y, k+first_z); - buffer[tensor_index] = result; - } - } - } - __syncthreads(); - } -}; - - - -template<typename Indices, typename InputArgType, typename KernelArgType> -struct TensorEvaluator<const TensorConvolutionOp<Indices, InputArgType, KernelArgType>, GpuDevice> -{ - typedef TensorConvolutionOp<Indices, InputArgType, KernelArgType> XprType; - - static const int NumDims = internal::array_size<typename TensorEvaluator<InputArgType, GpuDevice>::Dimensions>::value; - static const int NumKernelDims = internal::array_size<Indices>::value; - typedef typename XprType::Index Index; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename TensorEvaluator<KernelArgType, GpuDevice>::Dimensions KernelDimensions; - - enum { - IsAligned = TensorEvaluator<InputArgType, GpuDevice>::IsAligned & TensorEvaluator<KernelArgType, GpuDevice>::IsAligned, - PacketAccess = false, - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<InputArgType, GpuDevice>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const GpuDevice& device) - : m_inputImpl(op.inputExpression(), device), m_kernelImpl(op.kernelExpression(), device), m_kernelArg(op.kernelExpression()), m_indices(op.indices()), m_buf(NULL), m_kernel(NULL), m_local_kernel(false), m_device(device) - { - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<InputArgType, GpuDevice>::Layout) == static_cast<int>(TensorEvaluator<KernelArgType, GpuDevice>::Layout)), YOU_MADE_A_PROGRAMMING_MISTAKE); - - const typename TensorEvaluator<InputArgType, GpuDevice>::Dimensions& input_dims = m_inputImpl.dimensions(); - const typename TensorEvaluator<KernelArgType, GpuDevice>::Dimensions& kernel_dims = m_kernelImpl.dimensions(); - - m_dimensions = m_inputImpl.dimensions(); - for (int i = 0; i < NumKernelDims; ++i) { - const Index index = op.indices()[i]; - const Index input_dim = input_dims[index]; - const Index kernel_dim = kernel_dims[i]; - const Index result_dim = input_dim - kernel_dim + 1; - m_dimensions[index] = result_dim; - } - } - - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, GpuDevice>::type PacketReturnType; - typedef typename InputArgType::Scalar Scalar; - static const int PacketSize = internal::unpacket_traits<PacketReturnType>::size; - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(Scalar* data) { - preloadKernel(); - m_inputImpl.evalSubExprsIfNeeded(NULL); - if (data) { - executeEval(data); - return false; - } else { - m_buf = (Scalar*)m_device.allocate(dimensions().TotalSize() * sizeof(Scalar)); - executeEval(m_buf); - return true; - } - } - - EIGEN_STRONG_INLINE void cleanup() { - m_inputImpl.cleanup(); - if (m_buf) { - m_device.deallocate(m_buf); - m_buf = NULL; - } - if (m_local_kernel) { - m_device.deallocate((void*)m_kernel); - m_local_kernel = false; - } - m_kernel = NULL; - } - - EIGEN_STRONG_INLINE void preloadKernel() { - // Don't make a local copy of the kernel unless we have to (i.e. it's an - // expression that needs to be evaluated) - const Scalar* in_place = m_kernelImpl.data(); - if (in_place) { - m_kernel = in_place; - m_local_kernel = false; - } else { - size_t kernel_sz = m_kernelImpl.dimensions().TotalSize() * sizeof(Scalar); - Scalar* local = (Scalar*)m_device.allocate(kernel_sz); - typedef TensorEvalToOp<const KernelArgType> EvalTo; - EvalTo evalToTmp(local, m_kernelArg); - const bool PacketAccess = internal::IsVectorizable<GpuDevice, KernelArgType>::value; - internal::TensorExecutor<const EvalTo, GpuDevice, PacketAccess>::run(evalToTmp, m_device); - - m_kernel = local; - m_local_kernel = true; - } - } - - static unsigned int ceil(unsigned int num, unsigned int denom) { - const unsigned int rounded_toward_zero = num / denom; - if (num > rounded_toward_zero * denom) { - return rounded_toward_zero + 1; - } - return rounded_toward_zero; - } - - void executeEval(Scalar* data) const { - typedef typename TensorEvaluator<InputArgType, GpuDevice>::Dimensions InputDims; - - const int maxSharedMem = m_device.sharedMemPerBlock(); - const int maxThreadsPerBlock = m_device.maxGpuThreadsPerBlock(); - const int maxBlocksPerProcessor = m_device.maxGpuThreadsPerMultiProcessor() / maxThreadsPerBlock; - const int numMultiProcessors = m_device.getNumGpuMultiProcessors(); - const int warpSize = 32; - - switch (NumKernelDims) { - case 1: { - const int kernel_size = m_kernelImpl.dimensions().TotalSize(); - - const int numX = dimensions()[m_indices[0]]; - const int numP = dimensions().TotalSize() / numX; - int maxX; - dim3 block_size; - - const int single_stride_dim = - static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? 0 - : m_inputImpl.dimensions().rank() - 1; - if (m_indices[0] == single_stride_dim) { - // Maximum the reuse - const int inner_dim = ((maxSharedMem / (sizeof(Scalar)) - kernel_size + 1 + 31) / 32) * 32; - maxX = numext::mini<int>(inner_dim, numX); - const int maxP = numext::mini<int>(maxSharedMem / ((kernel_size - 1 + maxX) * sizeof(Scalar)), numP); - block_size.x = numext::mini(maxThreadsPerBlock, maxX); - block_size.y = numext::mini<int>(maxThreadsPerBlock / block_size.x, maxP); - } - else { - // Read as much as possible alongside the inner most dimension, that is the plane - const int inner_dim = maxSharedMem / ((warpSize + kernel_size) * sizeof(Scalar)); - const int maxP = numext::mini<int>(inner_dim, numP); - maxX = numext::mini<int>(maxSharedMem / (inner_dim * sizeof(Scalar)) - kernel_size + 1, numX); - - block_size.x = numext::mini(warpSize, maxX); - block_size.y = numext::mini<int>(maxThreadsPerBlock/block_size.x, maxP); - } - - const int shared_mem = block_size.y * (maxX + kernel_size - 1) * sizeof(Scalar); - gpu_assert(shared_mem <= maxSharedMem); - - const int num_x_blocks = ceil(numX, maxX); - const int blocksPerProcessor = numext::mini(maxBlocksPerProcessor, maxSharedMem / shared_mem); - const int num_y_blocks = ceil(numMultiProcessors * blocksPerProcessor, num_x_blocks); - - dim3 num_blocks(num_x_blocks, numext::mini<int>(num_y_blocks, ceil(numP, block_size.y))); - - - //cout << "launching 1D kernel with block_size.x: " << block_size.x << " block_size.y: " << block_size.y << " num_blocks.x: " << num_blocks.x << " num_blocks.y: " << num_blocks.y << " maxX: " << maxX << " shared_mem: " << shared_mem << " in stream " << m_device.stream() << endl; - - const array<Index, 1> indices(m_indices[0]); - const array<Index, 1> kernel_dims(m_kernelImpl.dimensions()[0]); - internal::IndexMapper<Index, InputDims, 1, Layout> indexMapper( - m_inputImpl.dimensions(), kernel_dims, indices); - switch(kernel_size) { - case 4: { - LAUNCH_GPU_KERNEL((EigenConvolutionKernel1D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims, 4>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, 4, data); - break; - } - case 7: { - LAUNCH_GPU_KERNEL((EigenConvolutionKernel1D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims, 7>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, 7, data); - break; - } - default: { - LAUNCH_GPU_KERNEL((EigenConvolutionKernel1D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims, Dynamic>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, kernel_size, data); - } - } - break; - } - - case 2: { - const int idxX = - static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : 1; - const int idxY = - static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 1 : 0; - const int kernel_size_x = m_kernelImpl.dimensions()[idxX]; - const int kernel_size_y = m_kernelImpl.dimensions()[idxY]; - - const int numX = dimensions()[m_indices[idxX]]; - const int numY = dimensions()[m_indices[idxY]]; - const int numP = dimensions().TotalSize() / (numX*numY); - - const float scaling_factor = sqrtf(static_cast<float>(maxSharedMem) / (sizeof(Scalar) * kernel_size_y * kernel_size_x)); - - // Snap maxX to warp size - int inner_dim = ((static_cast<int>(scaling_factor * kernel_size_x) - kernel_size_x + 1 + 32) / 32) * 32; - const int maxX = numext::mini<int>(inner_dim, numX); - const int maxY = numext::mini<int>(maxSharedMem / (sizeof(Scalar) * (maxX + kernel_size_x - 1)) - kernel_size_y + 1, numY); - const int maxP = numext::mini<int>(maxSharedMem / ((kernel_size_x - 1 + maxX) * (kernel_size_y - 1 + maxY) * sizeof(Scalar)), numP); - - dim3 block_size; - block_size.x = numext::mini(1024, maxX); - block_size.y = numext::mini<int>(1024/block_size.x, maxY); - block_size.z = numext::mini<int>(1024/(block_size.x*block_size.y), maxP); - - const int shared_mem = block_size.z * (maxX + kernel_size_x - 1) * (maxY + kernel_size_y - 1) * sizeof(Scalar); - gpu_assert(shared_mem <= maxSharedMem); - - const int num_x_blocks = ceil(numX, maxX); - const int num_y_blocks = ceil(numY, maxY); - const int blocksPerProcessor = numext::mini(maxBlocksPerProcessor, maxSharedMem / shared_mem); - const int num_z_blocks = ceil(numMultiProcessors * blocksPerProcessor, num_x_blocks * num_y_blocks); - - dim3 num_blocks(num_x_blocks, num_y_blocks, numext::mini<int>(num_z_blocks, ceil(numP, block_size.z))); - - - //cout << "launching 2D kernel with block_size.x: " << block_size.x << " block_size.y: " << block_size.y << " block_size.z: " << block_size.z << " num_blocks.x: " << num_blocks.x << " num_blocks.y: " << num_blocks.y << " num_blocks.z: " << num_blocks.z << " maxX: " << maxX << " maxY: " << maxY << " maxP: " << maxP << " shared_mem: " << shared_mem << " in stream " << m_device.stream() << endl; - - const array<Index, 2> indices(m_indices[idxX], m_indices[idxY]); - const array<Index, 2> kernel_dims(m_kernelImpl.dimensions()[idxX], - m_kernelImpl.dimensions()[idxY]); - internal::IndexMapper<Index, InputDims, 2, Layout> indexMapper( - m_inputImpl.dimensions(), kernel_dims, indices); - switch (kernel_size_x) { - case 4: { - switch (kernel_size_y) { - case 7: { - LAUNCH_GPU_KERNEL((EigenConvolutionKernel2D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims, 4, 7>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, numY, maxY, 4, 7, data); - break; - } - default: { - LAUNCH_GPU_KERNEL((EigenConvolutionKernel2D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims, 4, Dynamic>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, numY, maxY, 4, kernel_size_y, data); - break; - } - } - break; - } - case 7: { - switch (kernel_size_y) { - case 4: { - LAUNCH_GPU_KERNEL((EigenConvolutionKernel2D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims, 7, 4>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, numY, maxY, 7, 4, data); - break; - } - default: { - LAUNCH_GPU_KERNEL((EigenConvolutionKernel2D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims, 7, Dynamic>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, numY, maxY, 7, kernel_size_y, data); - break; - } - } - break; - } - default: { - LAUNCH_GPU_KERNEL((EigenConvolutionKernel2D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims, Dynamic, Dynamic>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, numY, maxY, kernel_size_x, kernel_size_y, data); - break; - } - } - break; - } - - case 3: { - const int idxX = - static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : 2; - const int idxY = - static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 1 : 1; - const int idxZ = - static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 2 : 0; - - const int kernel_size_x = m_kernelImpl.dimensions()[idxX]; - const int kernel_size_y = m_kernelImpl.dimensions()[idxY]; - const int kernel_size_z = m_kernelImpl.dimensions()[idxZ]; - - const int numX = dimensions()[m_indices[idxX]]; - const int numY = dimensions()[m_indices[idxY]]; - const int numZ = dimensions()[m_indices[idxZ]]; - const int numP = dimensions().TotalSize() / (numX*numY*numZ); - - const int maxX = numext::mini<int>(128, numext::mini<int>(maxSharedMem / (sizeof(Scalar) * kernel_size_y * kernel_size_z) - kernel_size_x + 1, numX)); - const int maxY = numext::mini<int>(128, numext::mini<int>(maxSharedMem / (sizeof(Scalar) * (maxX + kernel_size_x - 1) * kernel_size_z) - kernel_size_y + 1, numY)); - const int maxZ = numext::mini<int>(128, numext::mini<int>(maxSharedMem / (sizeof(Scalar) * (maxX + kernel_size_x - 1) * (maxY + kernel_size_y - 1)) - kernel_size_z + 1, numZ)); - - dim3 block_size; - block_size.x = numext::mini(32, maxX); - block_size.y = numext::mini(32, maxY); - block_size.z = numext::mini<int>(1024/(block_size.x*block_size.y), maxZ); - dim3 num_blocks(ceil(numX, maxX), ceil(numY, maxY), ceil(numZ, maxZ)); - - const int shared_mem = (maxX + kernel_size_x - 1) * (maxY + kernel_size_y - 1) * (maxZ + kernel_size_z - 1) * sizeof(Scalar); - gpu_assert(shared_mem <= maxSharedMem); - - //cout << "launching 3D kernel with block_size.x: " << block_size.x << " block_size.y: " << block_size.y << " block_size.z: " << block_size.z << " num_blocks.x: " << num_blocks.x << " num_blocks.y: " << num_blocks.y << " num_blocks.z: " << num_blocks.z << " shared_mem: " << shared_mem << " in stream " << m_device.stream() << endl; - const array<Index, 3> indices(m_indices[idxX], m_indices[idxY], - m_indices[idxZ]); - const array<Index, 3> kernel_dims(m_kernelImpl.dimensions()[idxX], - m_kernelImpl.dimensions()[idxY], - m_kernelImpl.dimensions()[idxZ]); - internal::IndexMapper<Index, InputDims, 3, Layout> indexMapper( - m_inputImpl.dimensions(), kernel_dims, indices); - - LAUNCH_GPU_KERNEL((EigenConvolutionKernel3D<TensorEvaluator<InputArgType, GpuDevice>, Index, InputDims>), num_blocks, block_size, shared_mem, m_device, m_inputImpl, indexMapper, m_kernel, numP, numX, maxX, numY, maxY, numZ, maxZ, kernel_size_x, kernel_size_y, kernel_size_z, data); - break; - } - - default: { - EIGEN_STATIC_ASSERT((NumKernelDims >= 1 && NumKernelDims <= 3), THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE); - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - eigen_assert(m_buf); - eigen_assert(index < m_dimensions.TotalSize()); - return m_buf[index]; - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(const Index index) const - { - eigen_assert(m_buf); - eigen_assert(index < m_dimensions.TotalSize()); - return internal::ploadt<PacketReturnType, LoadMode>(m_buf+index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - // TODO(rmlarsen): FIXME: For now, this is just a copy of the CPU cost - // model. - const double kernel_size = m_kernelImpl.dimensions().TotalSize(); - // We ignore the use of fused multiply-add. - const double convolve_compute_cost = - TensorOpCost::AddCost<Scalar>() + TensorOpCost::MulCost<Scalar>(); - const double firstIndex_compute_cost = - NumDims * - (2 * TensorOpCost::AddCost<Index>() + 2 * TensorOpCost::MulCost<Index>() + - TensorOpCost::DivCost<Index>()); - return TensorOpCost(0, 0, firstIndex_compute_cost, vectorized, PacketSize) + - kernel_size * (m_inputImpl.costPerCoeff(vectorized) + - m_kernelImpl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, convolve_compute_cost, vectorized, - PacketSize)); - } - - private: - // No assignment (copies are needed by the kernels) - TensorEvaluator& operator = (const TensorEvaluator&); - - TensorEvaluator<InputArgType, GpuDevice> m_inputImpl; - TensorEvaluator<KernelArgType, GpuDevice> m_kernelImpl; - KernelArgType m_kernelArg; - Indices m_indices; - Dimensions m_dimensions; - Scalar* m_buf; - const Scalar* m_kernel; - bool m_local_kernel; - - const GpuDevice& m_device; -}; -#endif - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONVOLUTION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConvolutionSycl.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConvolutionSycl.h deleted file mode 100644 index 92003c76..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorConvolutionSycl.h +++ /dev/null @@ -1,544 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> - -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONVOLUTION_SYCL_H -#define EIGEN_CXX11_TENSOR_TENSOR_CONVOLUTION_SYCL_H - -namespace Eigen { - -/** \class TensorConvolution - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor convolution class. - * - * - */ - -enum class convolution_type { CONV1D, CONV2D, CONV3D }; -template <typename Evaluator, typename CoeffReturnType, typename KernelType, typename Index, typename InputDims, - typename Kernel_accessor, typename Buffer_accessor, convolution_type Conv_Dim> -struct EigenConvolutionKernel; -template <typename Evaluator, typename CoeffReturnType, typename KernelType, typename Index, typename InputDims, - typename Kernel_accessor, typename Buffer_accessor> -struct EigenConvolutionKernel<Evaluator, CoeffReturnType, KernelType, Index, InputDims, Kernel_accessor, - Buffer_accessor, convolution_type::CONV1D> { - typedef cl::sycl::accessor<CoeffReturnType, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - Local_accessor; - Local_accessor local_acc; - Evaluator device_evaluator; - Kernel_accessor kernel_filter; - Buffer_accessor buffer_acc; - internal::IndexMapper<Index, InputDims, 1, Evaluator::Layout> indexMapper; - const size_t kernelSize; - const cl::sycl::range<2> input_range; - EigenConvolutionKernel(Local_accessor local_acc_, Evaluator device_evaluator_, Kernel_accessor kernel_filter_, - Buffer_accessor buffer_acc_, - internal::IndexMapper<Index, InputDims, 1, Evaluator::Layout> indexMapper_, - const size_t kernelSize_, const cl::sycl::range<2> input_range_) - : local_acc(local_acc_), - device_evaluator(device_evaluator_), - kernel_filter(kernel_filter_), - buffer_acc(buffer_acc_), - indexMapper(indexMapper_), - kernelSize(kernelSize_), - input_range(input_range_) {} - - template <typename BooleanDim2> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool boundary_check(const BooleanDim2 boolean_check) { - return (boolean_check[0] && boolean_check[1]); - } - void operator()(cl::sycl::nd_item<2> itemID) { - auto buffer_ptr = buffer_acc.get_pointer(); - auto kernel_ptr = kernel_filter.get_pointer(); - // the required row to be calculated for the for each plane in shered memory - const size_t num_input = (itemID.get_local_range()[0] + kernelSize - 1); - const size_t plane_kernel_offset = itemID.get_local_id(1) * num_input; - const size_t input_offset = itemID.get_group(0) * itemID.get_local_range()[0]; - const size_t plane_tensor_offset = indexMapper.mapGpuInputPlaneToTensorInputOffset(itemID.get_global_id(1)); - /// fill the shared memory - for (size_t i = itemID.get_local_id(0); i < num_input; i += itemID.get_local_range()[0]) { - const size_t local_index = i + plane_kernel_offset; - const size_t tensor_index = - plane_tensor_offset + indexMapper.mapGpuInputKernelToTensorInputOffset(i + input_offset); - - local_acc[local_index] = - (((i + input_offset) < (input_range[0] + kernelSize - 1)) && itemID.get_global_id(1) < input_range[1]) - ? device_evaluator.coeff(tensor_index) - : CoeffReturnType(0); - } - - itemID.barrier(cl::sycl::access::fence_space::local_space); - - // calculate the convolution // output start x - const size_t first_output_start = itemID.get_group(0) * (itemID.get_local_range()[0]); - if (boundary_check(itemID.get_global_id() < input_range)) { - CoeffReturnType result = static_cast<CoeffReturnType>(0); - const size_t index = plane_kernel_offset + itemID.get_local_id(0); - for (size_t k = 0; k < kernelSize; ++k) { - result += (local_acc[k + index] * kernel_ptr[k]); - } - const size_t tensor_index = - indexMapper.mapGpuOutputPlaneToTensorOutputOffset(itemID.get_global_id(1)) + - indexMapper.mapGpuOutputKernelToTensorOutputOffset(itemID.get_local_id(0) + first_output_start); - buffer_ptr[tensor_index] = result; - } - } -}; - -template <typename Evaluator, typename CoeffReturnType, typename KernelType, typename Index, typename InputDims, - typename Kernel_accessor, typename Buffer_accessor> -struct EigenConvolutionKernel<Evaluator, CoeffReturnType, KernelType, Index, InputDims, Kernel_accessor, - Buffer_accessor, convolution_type::CONV2D> { - typedef cl::sycl::accessor<CoeffReturnType, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - Local_accessor; - Local_accessor local_acc; - Evaluator device_evaluator; - Kernel_accessor kernel_filter; - Buffer_accessor buffer_acc; - internal::IndexMapper<Index, InputDims, 2, Evaluator::Layout> indexMapper; - const cl::sycl::range<2> kernel_size; - const cl::sycl::range<3> input_range; - EigenConvolutionKernel(Local_accessor local_acc_, Evaluator device_evaluator_, Kernel_accessor kernel_filter_, - Buffer_accessor buffer_acc_, - internal::IndexMapper<Index, InputDims, 2, Evaluator::Layout> indexMapper_, - const cl::sycl::range<2> kernel_size_, const cl::sycl::range<3> input_range_) - : local_acc(local_acc_), - device_evaluator(device_evaluator_), - kernel_filter(kernel_filter_), - buffer_acc(buffer_acc_), - indexMapper(indexMapper_), - kernel_size(kernel_size_), - input_range(input_range_) {} - template <typename BooleanDim3> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool boundary_check(const BooleanDim3 boolean_check) { - return (boolean_check[0] && boolean_check[1] && boolean_check[2]); - } - - void operator()(cl::sycl::nd_item<3> itemID) { - auto buffer_ptr = buffer_acc.get_pointer(); - auto kernel_ptr = kernel_filter.get_pointer(); - // the required row to be calculated for the for each plane in shered memory - const auto num_input = cl::sycl::range<2>{ - (cl::sycl::range<2>(itemID.get_local_range()[0], itemID.get_local_range()[1]) + kernel_size - 1)}; - - const size_t plane_input_offset = indexMapper.mapGpuInputPlaneToTensorInputOffset(itemID.get_global_id(2)); - const size_t plane_kernel_offset = itemID.get_local_id(2) * num_input[1]; - - const auto input_offset = cl::sycl::range<2>{itemID.get_group(0) * itemID.get_local_range()[0], - itemID.get_group(1) * itemID.get_local_range()[1]}; - - // fill the local memory - bool in_range_dim2 = itemID.get_global_id(2) < input_range[2]; - for (size_t j = itemID.get_local_id(1); j < num_input[1]; j += itemID.get_local_range()[1]) { - const size_t local_input_offset = num_input[0] * (j + plane_kernel_offset); - bool in_range_dim1 = ((j + input_offset[1]) < (input_range[1] + kernel_size[1] - 1)); - for (size_t i = itemID.get_local_id(0); i < num_input[0]; i += itemID.get_local_range()[0]) { - const size_t local_index = i + local_input_offset; - const size_t tensor_index = plane_input_offset + indexMapper.mapGpuInputKernelToTensorInputOffset( - i + input_offset[0], j + input_offset[1]); - local_acc[local_index] = (((i + input_offset[0]) < (input_range[0] + kernel_size[0] - 1)) && - in_range_dim1 && in_range_dim2) - ? device_evaluator.coeff(tensor_index) - : CoeffReturnType(0); - } - } - - itemID.barrier(cl::sycl::access::fence_space::local_space); - - // output offset start for each thread - const auto output_offset = cl::sycl::range<2>{itemID.get_group(0) * itemID.get_local_range()[0], - itemID.get_group(1) * itemID.get_local_range()[1]}; - - if (boundary_check(itemID.get_global_id() < input_range)) { - CoeffReturnType result = static_cast<CoeffReturnType>(0); - - for (size_t j = 0; j < kernel_size[1]; j++) { - size_t kernel_offset = kernel_size[0] * j; - const size_t index = - (num_input[0] * (plane_kernel_offset + j + itemID.get_local_id(1))) + itemID.get_local_id(0); - for (size_t i = 0; i < kernel_size[0]; i++) { - result += (local_acc[i + index] * kernel_ptr[i + kernel_offset]); - } - } - const size_t tensor_index = - indexMapper.mapGpuOutputPlaneToTensorOutputOffset(itemID.get_global_id(2)) + - indexMapper.mapGpuOutputKernelToTensorOutputOffset(itemID.get_local_id(0) + output_offset[0], - itemID.get_local_id(1) + output_offset[1]); - - buffer_ptr[tensor_index] = result; - } - } -}; - -template <typename Evaluator, typename CoeffReturnType, typename KernelType, typename Index, typename InputDims, - typename Kernel_accessor, typename Buffer_accessor> -struct EigenConvolutionKernel<Evaluator, CoeffReturnType, KernelType, Index, InputDims, Kernel_accessor, - Buffer_accessor, convolution_type::CONV3D> { - typedef cl::sycl::accessor<CoeffReturnType, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - Local_accessor; - Local_accessor local_acc; - Evaluator device_evaluator; - Kernel_accessor kernel_filter; - Buffer_accessor buffer_acc; - internal::IndexMapper<Index, InputDims, 3, Evaluator::Layout> indexMapper; - const cl::sycl::range<3> kernel_size; - const cl::sycl::range<3> input_range; - const size_t numP; - - EigenConvolutionKernel(Local_accessor local_acc_, Evaluator device_evaluator_, Kernel_accessor kernel_filter_, - Buffer_accessor buffer_acc_, - internal::IndexMapper<Index, InputDims, 3, Evaluator::Layout> indexMapper_, - const cl::sycl::range<3> kernel_size_, const cl::sycl::range<3> input_range_, - const size_t numP_) - : local_acc(local_acc_), - device_evaluator(device_evaluator_), - kernel_filter(kernel_filter_), - buffer_acc(buffer_acc_), - indexMapper(indexMapper_), - kernel_size(kernel_size_), - input_range(input_range_), - numP(numP_) {} - template <typename BooleanDim3> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool boundary_check(const BooleanDim3 boolean_check) { - return (boolean_check[0] && boolean_check[1] && boolean_check[2]); - } - void operator()(cl::sycl::nd_item<3> itemID) { - auto buffer_ptr = buffer_acc.get_pointer(); - auto kernel_ptr = kernel_filter.get_pointer(); - const auto num_input = cl::sycl::range<3>{itemID.get_local_range() + kernel_size - 1}; - - const auto input_offset = cl::sycl::range<3>{itemID.get_group().get_id() * itemID.get_local_range()}; - - const auto output_offset = - cl::sycl::range<3>{itemID.get_group().get_id() * itemID.get_local_range() + itemID.get_local_id()}; - - for (size_t p = 0; p < numP; p++) { - /// fill the shared memory - const size_t plane_input_offset = indexMapper.mapGpuInputPlaneToTensorInputOffset(p); - for (size_t k = itemID.get_local_id(2); k < num_input[2]; k += itemID.get_local_range()[2]) { - size_t local_index_dim2 = num_input[0] * num_input[1] * k; - bool cond_k_dim = (k + input_offset[2] < (input_range[2] + kernel_size[2] - 1)); - for (size_t j = itemID.get_local_id(1); j < num_input[1]; j += itemID.get_local_range()[1]) { - bool cond_j_dim = cond_k_dim && (j + input_offset[1] < (input_range[1] + kernel_size[1] - 1)); - size_t local_index_dim1 = (num_input[0] * j) + local_index_dim2; - for (size_t i = itemID.get_local_id(0); i < num_input[0]; i += itemID.get_local_range()[0]) { - bool conds = cond_j_dim && (i + input_offset[0] < (input_range[0] + kernel_size[0] - 1)); - const size_t local_index = local_index_dim1 + i; - const size_t tensor_index = - plane_input_offset + indexMapper.mapGpuInputKernelToTensorInputOffset( - i + input_offset[0], j + input_offset[1], k + input_offset[2]); - local_acc[local_index] = conds ? device_evaluator.coeff(tensor_index) : CoeffReturnType(0); - } - } - } - itemID.barrier(cl::sycl::access::fence_space::local_space); - - // calculate the convolution - - if (boundary_check(itemID.get_global_id() < input_range)) { - CoeffReturnType result = static_cast<CoeffReturnType>(0); - for (size_t k = 0; k < kernel_size[2]; k++) { - for (size_t j = 0; j < kernel_size[1]; j++) { - for (size_t i = 0; i < kernel_size[0]; i++) { - const size_t kernel_index = i + kernel_size[0] * (j + kernel_size[1] * k); - const size_t local_index = - ((i + itemID.get_local_id(0)) + - num_input[0] * ((j + itemID.get_local_id(1)) + num_input[1] * (k + itemID.get_local_id(2)))); - - result += (local_acc[local_index] * kernel_ptr[kernel_index]); - } - } - } - const size_t tensor_index = - indexMapper.mapGpuOutputPlaneToTensorOutputOffset(p) + - indexMapper.mapGpuOutputKernelToTensorOutputOffset(output_offset[0], output_offset[1], output_offset[2]); - buffer_ptr[tensor_index] = result; - } - - itemID.barrier(cl::sycl::access::fence_space::local_space); - } - } -}; - -template <typename Indices, typename InputArgType, typename KernelArgType> -struct TensorEvaluator<const TensorConvolutionOp<Indices, InputArgType, KernelArgType>, Eigen::SyclDevice> { - typedef TensorConvolutionOp<Indices, InputArgType, KernelArgType> XprType; - - static const int NumDims = - internal::array_size<typename TensorEvaluator<InputArgType, Eigen::SyclDevice>::Dimensions>::value; - static const int NumKernelDims = internal::array_size<Indices>::value; - typedef typename XprType::Index Index; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename TensorEvaluator<KernelArgType, Eigen::SyclDevice>::Dimensions KernelDimensions; - typedef const Eigen::SyclDevice Device; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Eigen::SyclDevice>::type PacketReturnType; - typedef typename InputArgType::Scalar Scalar; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Eigen::SyclDevice> Storage; - typedef typename Storage::Type EvaluatorPointerType; - typedef StorageMemory<const CoeffReturnType, Eigen::SyclDevice> KernelStorage; - - enum { - IsAligned = TensorEvaluator<InputArgType, Eigen::SyclDevice>::IsAligned & - TensorEvaluator<KernelArgType, Eigen::SyclDevice>::IsAligned, - PacketAccess = false, - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<InputArgType, Eigen::SyclDevice>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType &op, const Eigen::SyclDevice &device) - : m_inputImpl(op.inputExpression(), device), - m_kernelArg(op.kernelExpression()), - m_kernelImpl(op.kernelExpression(), device), - m_indices(op.indices()), - m_buf(NULL), - m_kernel(NULL), - m_local_kernel(false), - m_device(device) { - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<InputArgType, Eigen::SyclDevice>::Layout) == - static_cast<int>(TensorEvaluator<KernelArgType, Eigen::SyclDevice>::Layout)), - YOU_MADE_A_PROGRAMMING_MISTAKE); - - const typename TensorEvaluator<InputArgType, Eigen::SyclDevice>::Dimensions &input_dims = m_inputImpl.dimensions(); - const typename TensorEvaluator<KernelArgType, Eigen::SyclDevice>::Dimensions &kernel_dims = - m_kernelImpl.dimensions(); - - m_dimensions = m_inputImpl.dimensions(); - for (int i = 0; i < NumKernelDims; ++i) { - const Index index = op.indices()[i]; - const Index input_dim = input_dims[index]; - const Index kernel_dim = kernel_dims[i]; - const Index result_dim = input_dim - kernel_dim + 1; - m_dimensions[index] = result_dim; - } - } - - EIGEN_DEVICE_FUNC const Dimensions &dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - preloadKernel(); - m_inputImpl.evalSubExprsIfNeeded(NULL); - if (data) { - executeEval(data); - return false; - } else { - m_buf = (EvaluatorPointerType)m_device.get( - (Scalar *)m_device.allocate_temp(dimensions().TotalSize() * sizeof(Scalar))); - executeEval(m_buf); - return true; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_inputImpl.cleanup(); - if (m_buf) { - m_device.deallocate_temp(m_buf); - m_buf = NULL; - } - if (m_local_kernel) { - m_device.deallocate_temp(m_kernel); - m_local_kernel = false; - } - m_kernel = NULL; - } - /// used by sycl in order to build the sycl buffer - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Device &device() const { return m_device; } - /// used by sycl in order to build the sycl buffer - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data() const { return m_buf; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void preloadKernel() { - // Don't make a local copy of the kernel unless we have to (i.e. it's an - // expression that needs to be evaluated) - typename KernelStorage::Type in_place = m_kernelImpl.data(); - if (in_place) { - m_kernel = in_place; - m_local_kernel = false; - } else { - ptrdiff_t kernel_sz = m_kernelImpl.dimensions().TotalSize() * sizeof(Scalar); - EvaluatorPointerType local = (EvaluatorPointerType)m_device.get((Scalar *)m_device.allocate_temp(kernel_sz)); - typedef TensorEvalToOp<const KernelArgType> EvalTo; - EvalTo evalToTmp(m_device.get(local), m_kernelArg); - const bool PacketAccess = internal::IsVectorizable<Eigen::SyclDevice, KernelArgType>::value; - internal::TensorExecutor<const EvalTo, Eigen::SyclDevice, PacketAccess>::run(evalToTmp, m_device); - m_kernel = local; - m_local_kernel = true; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void executeEval(EvaluatorPointerType data) const { - typedef TensorEvaluator<InputArgType, Eigen::SyclDevice> InputEvaluator; - typedef typename InputEvaluator::Dimensions InputDims; - switch (NumKernelDims) { - case 1: { - const size_t numX = dimensions()[m_indices[0]]; - const size_t numP = dimensions().TotalSize() / numX; - const auto input_dim = std::array<size_t, 2>{numX, numP}; - auto global_range = cl::sycl::range<2>{}; - auto local_range = cl::sycl::range<2>{}; - const size_t kernel_size = m_kernelImpl.dimensions().TotalSize(); - - m_device.parallel_for_setup(input_dim, global_range, local_range); - const size_t local_memory_size = (local_range[0] + kernel_size - 1) * (local_range[1]); - gpu_assert(static_cast<unsigned long>(local_memory_size) <= m_device.sharedMemPerBlock()); - const array<Index, 1> indices{{m_indices[0]}}; - const array<Index, 1> kernel_dims{{m_kernelImpl.dimensions()[0]}}; - internal::IndexMapper<Index, InputDims, 1, Layout> indexMapper(m_inputImpl.dimensions(), kernel_dims, indices); - - typedef EigenConvolutionKernel<InputEvaluator, CoeffReturnType, Scalar, Index, InputDims, - typename KernelStorage::Type, EvaluatorPointerType, convolution_type::CONV1D> - ConvKernel; - - m_device.template binary_kernel_launcher<CoeffReturnType, ConvKernel>( - m_inputImpl, m_kernel, data, cl::sycl::nd_range<2>(global_range, local_range), local_memory_size, - indexMapper, kernel_size, cl::sycl::range<2>(input_dim[0], input_dim[1])); - break; - } - - case 2: { - auto kernel_index = std::array<size_t, 2>{static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : 1, - static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 1 : 0}; - auto kernel_size = cl::sycl::range<2>{(size_t)m_kernelImpl.dimensions()[kernel_index[0]], - (size_t)m_kernelImpl.dimensions()[kernel_index[1]]}; - const size_t numX = dimensions()[m_indices[kernel_index[0]]]; - const size_t numY = dimensions()[m_indices[kernel_index[1]]]; - const size_t numP = dimensions().TotalSize() / (numX * numY); - auto input_dim = std::array<size_t, 3>{numX, numY, numP}; - - auto global_range = cl::sycl::range<3>{}; - auto local_range = cl::sycl::range<3>{}; - - m_device.parallel_for_setup(input_dim, global_range, local_range); - - const size_t local_memory_size = - (local_range[0] + kernel_size[0] - 1) * (local_range[1] + kernel_size[1] - 1) * local_range[2]; - gpu_assert(static_cast<unsigned long>(local_memory_size) <= m_device.sharedMemPerBlock()); - const array<Index, 2> indices{{m_indices[kernel_index[0]], m_indices[kernel_index[1]]}}; - const array<Index, 2> kernel_dims{ - {m_kernelImpl.dimensions()[kernel_index[0]], m_kernelImpl.dimensions()[kernel_index[1]]}}; - internal::IndexMapper<Index, InputDims, 2, Layout> indexMapper(m_inputImpl.dimensions(), kernel_dims, indices); - typedef EigenConvolutionKernel<InputEvaluator, CoeffReturnType, Scalar, Index, InputDims, - typename KernelStorage::Type, EvaluatorPointerType, convolution_type::CONV2D> - ConvKernel; - m_device.template binary_kernel_launcher<CoeffReturnType, ConvKernel>( - m_inputImpl, m_kernel, data, cl::sycl::nd_range<3>(global_range, local_range), local_memory_size, - indexMapper, kernel_size, cl::sycl::range<3>{input_dim[0], input_dim[1], input_dim[2]}); - break; - } - - case 3: { - auto kernel_index = std::array<size_t, 3>{static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : 2, - static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 1 : 1, - static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 2 : 0}; - - auto kernel_size = cl::sycl::range<3>{(size_t)m_kernelImpl.dimensions()[kernel_index[0]], - (size_t)m_kernelImpl.dimensions()[kernel_index[1]], - (size_t)m_kernelImpl.dimensions()[kernel_index[2]]}; - - const size_t numX = dimensions()[m_indices[kernel_index[0]]]; - const size_t numY = dimensions()[m_indices[kernel_index[1]]]; - const size_t numZ = dimensions()[m_indices[kernel_index[2]]]; - auto input_dim = std::array<size_t, 3>{numX, numY, numZ}; - const size_t numP = dimensions().TotalSize() / (numX * numY * numZ); - - const array<Index, 3> indices{ - {m_indices[kernel_index[0]], m_indices[kernel_index[1]], m_indices[kernel_index[2]]}}; - const array<Index, 3> kernel_dims{{m_kernelImpl.dimensions()[kernel_index[0]], - m_kernelImpl.dimensions()[kernel_index[1]], - m_kernelImpl.dimensions()[kernel_index[2]]}}; - - internal::IndexMapper<Index, InputDims, 3, Layout> indexMapper(m_inputImpl.dimensions(), kernel_dims, indices); - - auto global_range = cl::sycl::range<3>{}; - auto local_range = cl::sycl::range<3>{}; - - m_device.parallel_for_setup(input_dim, global_range, local_range); - auto local_memory_range = (local_range + kernel_size - 1); - const size_t local_memory_size = local_memory_range[0] * local_memory_range[1] * local_memory_range[2]; - - gpu_assert(static_cast<unsigned long>(local_memory_size) <= m_device.sharedMemPerBlock()); - typedef EigenConvolutionKernel<InputEvaluator, CoeffReturnType, Scalar, Index, InputDims, - typename KernelStorage::Type, EvaluatorPointerType, convolution_type::CONV3D> - ConvKernel; - m_device.template binary_kernel_launcher<CoeffReturnType, ConvKernel>( - m_inputImpl, m_kernel, data, cl::sycl::nd_range<3>(global_range, local_range), local_memory_size, - indexMapper, kernel_size, cl::sycl::range<3>(input_dim[0], input_dim[1], input_dim[2]), numP); - break; - } - - default: { - EIGEN_STATIC_ASSERT((NumKernelDims >= 1 && NumKernelDims <= 3), - THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE); - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - eigen_assert(m_buf != NULL); - eigen_assert(index < m_dimensions.TotalSize()); - return m_buf[index]; - } - - template <int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(const Index index) const { - eigen_assert(m_buf != NULL); - eigen_assert(index < m_dimensions.TotalSize()); - return internal::ploadt<PacketReturnType, LoadMode>(m_buf + index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - // TODO(rmlarsen): FIXME: For now, this is just a copy of the CPU cost - // model. - const double kernel_size = m_kernelImpl.dimensions().TotalSize(); - // We ignore the use of fused multiply-add. - const double convolve_compute_cost = TensorOpCost::AddCost<Scalar>() + TensorOpCost::MulCost<Scalar>(); - const double firstIndex_compute_cost = - NumDims * - (2 * TensorOpCost::AddCost<Index>() + 2 * TensorOpCost::MulCost<Index>() + TensorOpCost::DivCost<Index>()); - return TensorOpCost(0, 0, firstIndex_compute_cost, vectorized, PacketSize) + - kernel_size * (m_inputImpl.costPerCoeff(vectorized) + m_kernelImpl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, convolve_compute_cost, vectorized, PacketSize)); - } - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_kernelImpl.bind(cgh); - m_inputImpl.bind(cgh); - m_buf.bind(cgh); - m_kernel.bind(cgh); - } - - private: - // No assignment (copies are needed by the kernels) - TensorEvaluator &operator=(const TensorEvaluator &); - TensorEvaluator<InputArgType, Eigen::SyclDevice> m_inputImpl; - KernelArgType m_kernelArg; - TensorEvaluator<KernelArgType, Eigen::SyclDevice> m_kernelImpl; - Indices m_indices; - Dimensions m_dimensions; - EvaluatorPointerType m_buf; - typename KernelStorage::Type m_kernel; - bool m_local_kernel; - const Eigen::SyclDevice EIGEN_DEVICE_REF m_device; -}; // namespace Eigen - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CONVOLUTION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorCostModel.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorCostModel.h deleted file mode 100644 index 195267ce..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorCostModel.h +++ /dev/null @@ -1,214 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Rasmus Munk Larsen <rmlarsen@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_COST_MODEL_H -#define EIGEN_CXX11_TENSOR_TENSOR_COST_MODEL_H - -namespace Eigen { - -/** \class TensorEvaluator - * \ingroup CXX11_Tensor_Module - * - * \brief A cost model used to limit the number of threads used for evaluating - * tensor expression. - * - */ - -// Class storing the cost of evaluating a tensor expression in terms of the -// estimated number of operand bytes loads, bytes stored, and compute cycles. -class TensorOpCost { - public: - // TODO(rmlarsen): Fix the scalar op costs in Eigen proper. Even a simple - // model based on minimal reciprocal throughput numbers from Intel or - // Agner Fog's tables would be better than what is there now. - template <typename ArgType> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int MulCost() { - return internal::functor_traits< - internal::scalar_product_op<ArgType, ArgType> >::Cost; - } - template <typename ArgType> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int AddCost() { - return internal::functor_traits<internal::scalar_sum_op<ArgType> >::Cost; - } - template <typename ArgType> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int DivCost() { - return internal::functor_traits< - internal::scalar_quotient_op<ArgType, ArgType> >::Cost; - } - template <typename ArgType> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int ModCost() { - return internal::functor_traits<internal::scalar_mod_op<ArgType> >::Cost; - } - template <typename SrcType, typename TargetType> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int CastCost() { - return internal::functor_traits< - internal::scalar_cast_op<SrcType, TargetType> >::Cost; - } - - EIGEN_DEVICE_FUNC - TensorOpCost() : bytes_loaded_(0), bytes_stored_(0), compute_cycles_(0) {} - EIGEN_DEVICE_FUNC - TensorOpCost(double bytes_loaded, double bytes_stored, double compute_cycles) - : bytes_loaded_(bytes_loaded), - bytes_stored_(bytes_stored), - compute_cycles_(compute_cycles) {} - - EIGEN_DEVICE_FUNC - TensorOpCost(double bytes_loaded, double bytes_stored, double compute_cycles, - bool vectorized, double packet_size) - : bytes_loaded_(bytes_loaded), - bytes_stored_(bytes_stored), - compute_cycles_(vectorized ? compute_cycles / packet_size - : compute_cycles) { - eigen_assert(bytes_loaded >= 0 && (numext::isfinite)(bytes_loaded)); - eigen_assert(bytes_stored >= 0 && (numext::isfinite)(bytes_stored)); - eigen_assert(compute_cycles >= 0 && (numext::isfinite)(compute_cycles)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bytes_loaded() const { - return bytes_loaded_; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bytes_stored() const { - return bytes_stored_; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double compute_cycles() const { - return compute_cycles_; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double total_cost( - double load_cost, double store_cost, double compute_cost) const { - return load_cost * bytes_loaded_ + store_cost * bytes_stored_ + - compute_cost * compute_cycles_; - } - - // Drop memory access component. Intended for cases when memory accesses are - // sequential or are completely masked by computations. - EIGEN_DEVICE_FUNC void dropMemoryCost() { - bytes_loaded_ = 0; - bytes_stored_ = 0; - } - - // TODO(rmlarsen): Define min in terms of total cost, not elementwise. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost cwiseMin( - const TensorOpCost& rhs) const { - double bytes_loaded = numext::mini(bytes_loaded_, rhs.bytes_loaded()); - double bytes_stored = numext::mini(bytes_stored_, rhs.bytes_stored()); - double compute_cycles = numext::mini(compute_cycles_, rhs.compute_cycles()); - return TensorOpCost(bytes_loaded, bytes_stored, compute_cycles); - } - - // TODO(rmlarsen): Define max in terms of total cost, not elementwise. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost cwiseMax( - const TensorOpCost& rhs) const { - double bytes_loaded = numext::maxi(bytes_loaded_, rhs.bytes_loaded()); - double bytes_stored = numext::maxi(bytes_stored_, rhs.bytes_stored()); - double compute_cycles = numext::maxi(compute_cycles_, rhs.compute_cycles()); - return TensorOpCost(bytes_loaded, bytes_stored, compute_cycles); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost& operator+=( - const TensorOpCost& rhs) { - bytes_loaded_ += rhs.bytes_loaded(); - bytes_stored_ += rhs.bytes_stored(); - compute_cycles_ += rhs.compute_cycles(); - return *this; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost& operator*=(double rhs) { - bytes_loaded_ *= rhs; - bytes_stored_ *= rhs; - compute_cycles_ *= rhs; - return *this; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend TensorOpCost operator+( - TensorOpCost lhs, const TensorOpCost& rhs) { - lhs += rhs; - return lhs; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend TensorOpCost operator*( - TensorOpCost lhs, double rhs) { - lhs *= rhs; - return lhs; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend TensorOpCost operator*( - double lhs, TensorOpCost rhs) { - rhs *= lhs; - return rhs; - } - - friend std::ostream& operator<<(std::ostream& os, const TensorOpCost& tc) { - return os << "[bytes_loaded = " << tc.bytes_loaded() - << ", bytes_stored = " << tc.bytes_stored() - << ", compute_cycles = " << tc.compute_cycles() << "]"; - } - - private: - double bytes_loaded_; - double bytes_stored_; - double compute_cycles_; -}; - -// TODO(rmlarsen): Implement a policy that chooses an "optimal" number of theads -// in [1:max_threads] instead of just switching multi-threading off for small -// work units. -template <typename Device> -class TensorCostModel { - public: - // Scaling from Eigen compute cost to device cycles. - static const int kDeviceCyclesPerComputeCycle = 1; - - // Costs in device cycles. - static const int kStartupCycles = 100000; - static const int kPerThreadCycles = 100000; - static const int kTaskSize = 40000; - - // Returns the number of threads in [1:max_threads] to use for - // evaluating an expression with the given output size and cost per - // coefficient. - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int numThreads( - double output_size, const TensorOpCost& cost_per_coeff, int max_threads) { - double cost = totalCost(output_size, cost_per_coeff); - double threads = (cost - kStartupCycles) / kPerThreadCycles + 0.9; - // Make sure we don't invoke undefined behavior when we convert to an int. - threads = numext::mini<double>(threads, GenericNumTraits<int>::highest()); - return numext::mini(max_threads, - numext::maxi<int>(1, static_cast<int>(threads))); - } - - // taskSize assesses parallel task size. - // Value of 1.0 means ideal parallel task size. Values < 1.0 mean that task - // granularity needs to be increased to mitigate parallelization overheads. - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double taskSize( - double output_size, const TensorOpCost& cost_per_coeff) { - return totalCost(output_size, cost_per_coeff) / kTaskSize; - } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double totalCost( - double output_size, const TensorOpCost& cost_per_coeff) { - // Cost of memory fetches from L2 cache. 64 is typical cache line size. - // 11 is L2 cache latency on Haswell. - // We don't know whether data is in L1, L2 or L3. But we are most interested - // in single-threaded computational time around 100us-10ms (smaller time - // is too small for parallelization, larger time is not interesting - // either because we are probably using all available threads already). - // And for the target time range, L2 seems to be what matters. Data set - // fitting into L1 is too small to take noticeable time. Data set fitting - // only into L3 presumably will take more than 10ms to load and process. - const double kLoadCycles = 1.0 / 64 * 11; - const double kStoreCycles = 1.0 / 64 * 11; - // Scaling from Eigen compute cost to device cycles. - return output_size * - cost_per_coeff.total_cost(kLoadCycles, kStoreCycles, - kDeviceCyclesPerComputeCycle); - } -}; - -} // namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_COST_MODEL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h deleted file mode 100644 index 476b2282..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ /dev/null @@ -1,347 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H -#define EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H - -namespace Eigen { - -/** \class TensorCustomUnaryOp - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor custom class. - * - * - */ -namespace internal { -template<typename CustomUnaryFunc, typename XprType> -struct traits<TensorCustomUnaryOp<CustomUnaryFunc, XprType> > -{ - typedef typename XprType::Scalar Scalar; - typedef typename XprType::StorageKind StorageKind; - typedef typename XprType::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = traits<XprType>::NumDimensions; - static const int Layout = traits<XprType>::Layout; - typedef typename traits<XprType>::PointerType PointerType; -}; - -template<typename CustomUnaryFunc, typename XprType> -struct eval<TensorCustomUnaryOp<CustomUnaryFunc, XprType>, Eigen::Dense> -{ - typedef const TensorCustomUnaryOp<CustomUnaryFunc, XprType>EIGEN_DEVICE_REF type; -}; - -template<typename CustomUnaryFunc, typename XprType> -struct nested<TensorCustomUnaryOp<CustomUnaryFunc, XprType> > -{ - typedef TensorCustomUnaryOp<CustomUnaryFunc, XprType> type; -}; - -} // end namespace internal - - - -template<typename CustomUnaryFunc, typename XprType> -class TensorCustomUnaryOp : public TensorBase<TensorCustomUnaryOp<CustomUnaryFunc, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename internal::traits<TensorCustomUnaryOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename internal::nested<TensorCustomUnaryOp>::type Nested; - typedef typename internal::traits<TensorCustomUnaryOp>::StorageKind StorageKind; - typedef typename internal::traits<TensorCustomUnaryOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCustomUnaryOp(const XprType& expr, const CustomUnaryFunc& func) - : m_expr(expr), m_func(func) {} - - EIGEN_DEVICE_FUNC - const CustomUnaryFunc& func() const { return m_func; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_expr; } - - protected: - typename XprType::Nested m_expr; - const CustomUnaryFunc m_func; -}; - - -// Eval as rvalue -template<typename CustomUnaryFunc, typename XprType, typename Device> -struct TensorEvaluator<const TensorCustomUnaryOp<CustomUnaryFunc, XprType>, Device> -{ - typedef TensorCustomUnaryOp<CustomUnaryFunc, XprType> ArgType; - typedef typename internal::traits<ArgType>::Index Index; - static const int NumDims = internal::traits<ArgType>::NumDimensions; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename internal::remove_const<typename ArgType::Scalar>::type Scalar; - typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<XprType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const ArgType& op, const Device& device) - : m_op(op), m_device(device), m_result(NULL) - { - m_dimensions = op.func().dimensions(op.expression()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - if (data) { - evalTo(data); - return false; - } else { - m_result = static_cast<EvaluatorPointerType>(m_device.get( (CoeffReturnType*) - m_device.allocate_temp(dimensions().TotalSize() * sizeof(Scalar)))); - evalTo(m_result); - return true; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - if (m_result) { - m_device.deallocate_temp(m_result); - m_result = NULL; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - return m_result[index]; - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const { - return internal::ploadt<PacketReturnType, LoadMode>(m_result + index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - // TODO(rmlarsen): Extend CustomOp API to return its cost estimate. - return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_result; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_result.bind(cgh); - } -#endif - - protected: - EIGEN_DEVICE_FUNC void evalTo(EvaluatorPointerType data) { - TensorMap<Tensor<CoeffReturnType, NumDims, Layout, Index> > result(m_device.get(data), m_dimensions); - m_op.func().eval(m_op.expression(), result, m_device); - } - - Dimensions m_dimensions; - const ArgType m_op; - const Device EIGEN_DEVICE_REF m_device; - EvaluatorPointerType m_result; -}; - - - -/** \class TensorCustomBinaryOp - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor custom class. - * - * - */ -namespace internal { -template<typename CustomBinaryFunc, typename LhsXprType, typename RhsXprType> -struct traits<TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType> > -{ - typedef typename internal::promote_storage_type<typename LhsXprType::Scalar, - typename RhsXprType::Scalar>::ret Scalar; - typedef typename internal::promote_storage_type<typename LhsXprType::CoeffReturnType, - typename RhsXprType::CoeffReturnType>::ret CoeffReturnType; - typedef typename promote_storage_type<typename traits<LhsXprType>::StorageKind, - typename traits<RhsXprType>::StorageKind>::ret StorageKind; - typedef typename promote_index_type<typename traits<LhsXprType>::Index, - typename traits<RhsXprType>::Index>::type Index; - typedef typename LhsXprType::Nested LhsNested; - typedef typename RhsXprType::Nested RhsNested; - typedef typename remove_reference<LhsNested>::type _LhsNested; - typedef typename remove_reference<RhsNested>::type _RhsNested; - static const int NumDimensions = traits<LhsXprType>::NumDimensions; - static const int Layout = traits<LhsXprType>::Layout; - typedef typename conditional<Pointer_type_promotion<typename LhsXprType::Scalar, Scalar>::val, - typename traits<LhsXprType>::PointerType, typename traits<RhsXprType>::PointerType>::type PointerType; -}; - -template<typename CustomBinaryFunc, typename LhsXprType, typename RhsXprType> -struct eval<TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType>, Eigen::Dense> -{ - typedef const TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType>& type; -}; - -template<typename CustomBinaryFunc, typename LhsXprType, typename RhsXprType> -struct nested<TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType> > -{ - typedef TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType> type; -}; - -} // end namespace internal - - - -template<typename CustomBinaryFunc, typename LhsXprType, typename RhsXprType> -class TensorCustomBinaryOp : public TensorBase<TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType>, ReadOnlyAccessors> -{ - public: - typedef typename internal::traits<TensorCustomBinaryOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename internal::traits<TensorCustomBinaryOp>::CoeffReturnType CoeffReturnType; - typedef typename internal::nested<TensorCustomBinaryOp>::type Nested; - typedef typename internal::traits<TensorCustomBinaryOp>::StorageKind StorageKind; - typedef typename internal::traits<TensorCustomBinaryOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCustomBinaryOp(const LhsXprType& lhs, const RhsXprType& rhs, const CustomBinaryFunc& func) - - : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_func(func) {} - - EIGEN_DEVICE_FUNC - const CustomBinaryFunc& func() const { return m_func; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename LhsXprType::Nested>::type& - lhsExpression() const { return m_lhs_xpr; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename RhsXprType::Nested>::type& - rhsExpression() const { return m_rhs_xpr; } - - protected: - typename LhsXprType::Nested m_lhs_xpr; - typename RhsXprType::Nested m_rhs_xpr; - const CustomBinaryFunc m_func; -}; - - -// Eval as rvalue -template<typename CustomBinaryFunc, typename LhsXprType, typename RhsXprType, typename Device> -struct TensorEvaluator<const TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType>, Device> -{ - typedef TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType> XprType; - typedef typename internal::traits<XprType>::Index Index; - static const int NumDims = internal::traits<XprType>::NumDimensions; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - - typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<LhsXprType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_op(op), m_device(device), m_result(NULL) - { - m_dimensions = op.func().dimensions(op.lhsExpression(), op.rhsExpression()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - if (data) { - evalTo(data); - return false; - } else { - m_result = static_cast<EvaluatorPointerType>(m_device.get( (CoeffReturnType*) - m_device.allocate_temp(dimensions().TotalSize() * sizeof(CoeffReturnType)))); - evalTo(m_result); - return true; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - if (m_result != NULL) { - m_device.deallocate_temp(m_result); - m_result = NULL; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - return m_result[index]; - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const { - return internal::ploadt<PacketReturnType, LoadMode>(m_result + index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - // TODO(rmlarsen): Extend CustomOp API to return its cost estimate. - return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_result; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_result.bind(cgh); - } -#endif - - protected: - EIGEN_DEVICE_FUNC void evalTo(EvaluatorPointerType data) { - TensorMap<Tensor<CoeffReturnType, NumDims, Layout> > result(m_device.get(data), m_dimensions); - m_op.func().eval(m_op.lhsExpression(), m_op.rhsExpression(), result, m_device); - } - - Dimensions m_dimensions; - const XprType m_op; - const Device EIGEN_DEVICE_REF m_device; - EvaluatorPointerType m_result; -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h deleted file mode 100644 index 804a16cc..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h +++ /dev/null @@ -1,135 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H -#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H - -namespace Eigen { - -/** \class TensorDevice - * \ingroup CXX11_Tensor_Module - * - * \brief Pseudo expression providing an operator = that will evaluate its argument - * on the specified computing 'device' (GPU, thread pool, ...) - * - * Example: - * C.device(EIGEN_GPU) = A + B; - * - * Todo: operator *= and /=. - */ - -template <typename ExpressionType, typename DeviceType> class TensorDevice { - public: - TensorDevice(const DeviceType& device, ExpressionType& expression) : m_device(device), m_expression(expression) {} - - template<typename OtherDerived> - EIGEN_STRONG_INLINE TensorDevice& operator=(const OtherDerived& other) { - typedef TensorAssignOp<ExpressionType, const OtherDerived> Assign; - Assign assign(m_expression, other); - internal::TensorExecutor<const Assign, DeviceType>::run(assign, m_device); - return *this; - } - - template<typename OtherDerived> - EIGEN_STRONG_INLINE TensorDevice& operator+=(const OtherDerived& other) { - typedef typename OtherDerived::Scalar Scalar; - typedef TensorCwiseBinaryOp<internal::scalar_sum_op<Scalar>, const ExpressionType, const OtherDerived> Sum; - Sum sum(m_expression, other); - typedef TensorAssignOp<ExpressionType, const Sum> Assign; - Assign assign(m_expression, sum); - internal::TensorExecutor<const Assign, DeviceType>::run(assign, m_device); - return *this; - } - - template<typename OtherDerived> - EIGEN_STRONG_INLINE TensorDevice& operator-=(const OtherDerived& other) { - typedef typename OtherDerived::Scalar Scalar; - typedef TensorCwiseBinaryOp<internal::scalar_difference_op<Scalar>, const ExpressionType, const OtherDerived> Difference; - Difference difference(m_expression, other); - typedef TensorAssignOp<ExpressionType, const Difference> Assign; - Assign assign(m_expression, difference); - internal::TensorExecutor<const Assign, DeviceType>::run(assign, m_device); - return *this; - } - - protected: - const DeviceType& m_device; - ExpressionType& m_expression; -}; - -/** \class TensorAsyncDevice - * \ingroup CXX11_Tensor_Module - * - * \brief Pseudo expression providing an operator = that will evaluate its - * argument asynchronously on the specified device. Currently only - * ThreadPoolDevice implements proper asynchronous execution, while the default - * and GPU devices just run the expression synchronously and call m_done() on - * completion.. - * - * Example: - * auto done = []() { ... expression evaluation done ... }; - * C.device(thread_pool_device, std::move(done)) = A + B; - */ - -template <typename ExpressionType, typename DeviceType, typename DoneCallback> -class TensorAsyncDevice { - public: - TensorAsyncDevice(const DeviceType& device, ExpressionType& expression, - DoneCallback done) - : m_device(device), m_expression(expression), m_done(std::move(done)) {} - - template <typename OtherDerived> - EIGEN_STRONG_INLINE TensorAsyncDevice& operator=(const OtherDerived& other) { - typedef TensorAssignOp<ExpressionType, const OtherDerived> Assign; - typedef internal::TensorExecutor<const Assign, DeviceType> Executor; - - Assign assign(m_expression, other); - Executor::run(assign, m_device); - m_done(); - - return *this; - } - - protected: - const DeviceType& m_device; - ExpressionType& m_expression; - DoneCallback m_done; -}; - - -#ifdef EIGEN_USE_THREADS -template <typename ExpressionType, typename DoneCallback> -class TensorAsyncDevice<ExpressionType, ThreadPoolDevice, DoneCallback> { - public: - TensorAsyncDevice(const ThreadPoolDevice& device, ExpressionType& expression, - DoneCallback done) - : m_device(device), m_expression(expression), m_done(std::move(done)) {} - - template <typename OtherDerived> - EIGEN_STRONG_INLINE TensorAsyncDevice& operator=(const OtherDerived& other) { - typedef TensorAssignOp<ExpressionType, const OtherDerived> Assign; - typedef internal::TensorAsyncExecutor<const Assign, ThreadPoolDevice, DoneCallback> Executor; - - // WARNING: After assignment 'm_done' callback will be in undefined state. - Assign assign(m_expression, other); - Executor::runAsync(assign, m_device, std::move(m_done)); - - return *this; - } - - protected: - const ThreadPoolDevice& m_device; - ExpressionType& m_expression; - DoneCallback m_done; -}; -#endif - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h deleted file mode 100644 index f7792393..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h +++ /dev/null @@ -1,6 +0,0 @@ - -#if defined(__clang__) || defined(__GNUC__) -#warning "Deprecated header file, please either include the main Eigen/CXX11/Tensor header or the respective TensorDeviceGpu.h file" -#endif - -#include "TensorDeviceGpu.h" diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceDefault.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceDefault.h deleted file mode 100644 index 46b9d3ab..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceDefault.h +++ /dev/null @@ -1,104 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H -#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H - - -namespace Eigen { - -// Default device for the machine (typically a single cpu core) -struct DefaultDevice { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const { - return internal::aligned_malloc(num_bytes); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate(void* buffer) const { - internal::aligned_free(buffer); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* allocate_temp(size_t num_bytes) const { - return allocate(num_bytes); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate_temp(void* buffer) const { - deallocate(buffer); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpy(void* dst, const void* src, size_t n) const { - ::memcpy(dst, src, n); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyHostToDevice(void* dst, const void* src, size_t n) const { - memcpy(dst, src, n); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyDeviceToHost(void* dst, const void* src, size_t n) const { - memcpy(dst, src, n); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memset(void* buffer, int c, size_t n) const { - ::memset(buffer, c, n); - } - template<typename Type> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Type get(Type data) const { - return data; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t numThreads() const { -#if !defined(EIGEN_GPU_COMPILE_PHASE) - // Running on the host CPU - return 1; -#elif defined(EIGEN_HIP_DEVICE_COMPILE) - // Running on a HIP device - return 64; -#else - // Running on a CUDA device - return 32; -#endif - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const { -#if !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(SYCL_DEVICE_ONLY) - // Running on the host CPU - return l1CacheSize(); -#elif defined(EIGEN_HIP_DEVICE_COMPILE) - // Running on a HIP device - return 48*1024; // FIXME : update this number for HIP -#else - // Running on a CUDA device, return the amount of shared memory available. - return 48*1024; -#endif - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const { -#if !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(SYCL_DEVICE_ONLY) - // Running single threaded on the host CPU - return l3CacheSize(); -#elif defined(EIGEN_HIP_DEVICE_COMPILE) - // Running on a HIP device - return firstLevelCacheSize(); // FIXME : update this number for HIP -#else - // Running on a CUDA device - return firstLevelCacheSize(); -#endif - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const { -#if !defined(EIGEN_GPU_COMPILE_PHASE) - // Running single threaded on the host CPU - // Should return an enum that encodes the ISA supported by the CPU - return 1; -#elif defined(EIGEN_HIP_DEVICE_COMPILE) - // Running on a HIP device - // return 1 as major for HIP - return 1; -#else - // Running on a CUDA device - return EIGEN_CUDA_ARCH / 100; -#endif - } -}; - -} // namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceGpu.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceGpu.h deleted file mode 100644 index 7f339443..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceGpu.h +++ /dev/null @@ -1,360 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#if defined(EIGEN_USE_GPU) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_GPU_H) -#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_GPU_H - -// This header file container defines fo gpu* macros which will resolve to -// their equivalent hip* or cuda* versions depending on the compiler in use -// A separate header (included at the end of this file) will undefine all -#include "TensorGpuHipCudaDefines.h" - -namespace Eigen { - -static const int kGpuScratchSize = 1024; - -// This defines an interface that GPUDevice can take to use -// HIP / CUDA streams underneath. -class StreamInterface { - public: - virtual ~StreamInterface() {} - - virtual const gpuStream_t& stream() const = 0; - virtual const gpuDeviceProp_t& deviceProperties() const = 0; - - // Allocate memory on the actual device where the computation will run - virtual void* allocate(size_t num_bytes) const = 0; - virtual void deallocate(void* buffer) const = 0; - - // Return a scratchpad buffer of size 1k - virtual void* scratchpad() const = 0; - - // Return a semaphore. The semaphore is initially initialized to 0, and - // each kernel using it is responsible for resetting to 0 upon completion - // to maintain the invariant that the semaphore is always equal to 0 upon - // each kernel start. - virtual unsigned int* semaphore() const = 0; -}; - -static gpuDeviceProp_t* m_deviceProperties; -static bool m_devicePropInitialized = false; - -static void initializeDeviceProp() { - if (!m_devicePropInitialized) { - // Attempts to ensure proper behavior in the case of multiple threads - // calling this function simultaneously. This would be trivial to - // implement if we could use std::mutex, but unfortunately mutex don't - // compile with nvcc, so we resort to atomics and thread fences instead. - // Note that if the caller uses a compiler that doesn't support c++11 we - // can't ensure that the initialization is thread safe. - static std::atomic<bool> first(true); - if (first.exchange(false)) { - // We're the first thread to reach this point. - int num_devices; - gpuError_t status = gpuGetDeviceCount(&num_devices); - if (status != gpuSuccess) { - std::cerr << "Failed to get the number of GPU devices: " - << gpuGetErrorString(status) - << std::endl; - gpu_assert(status == gpuSuccess); - } - m_deviceProperties = new gpuDeviceProp_t[num_devices]; - for (int i = 0; i < num_devices; ++i) { - status = gpuGetDeviceProperties(&m_deviceProperties[i], i); - if (status != gpuSuccess) { - std::cerr << "Failed to initialize GPU device #" - << i - << ": " - << gpuGetErrorString(status) - << std::endl; - gpu_assert(status == gpuSuccess); - } - } - - std::atomic_thread_fence(std::memory_order_release); - m_devicePropInitialized = true; - } else { - // Wait for the other thread to inititialize the properties. - while (!m_devicePropInitialized) { - std::atomic_thread_fence(std::memory_order_acquire); - EIGEN_SLEEP(1000); - } - } - } -} - -static const gpuStream_t default_stream = gpuStreamDefault; - -class GpuStreamDevice : public StreamInterface { - public: - // Use the default stream on the current device - GpuStreamDevice() : stream_(&default_stream), scratch_(NULL), semaphore_(NULL) { - gpuGetDevice(&device_); - initializeDeviceProp(); - } - // Use the default stream on the specified device - GpuStreamDevice(int device) : stream_(&default_stream), device_(device), scratch_(NULL), semaphore_(NULL) { - initializeDeviceProp(); - } - // Use the specified stream. Note that it's the - // caller responsibility to ensure that the stream can run on - // the specified device. If no device is specified the code - // assumes that the stream is associated to the current gpu device. - GpuStreamDevice(const gpuStream_t* stream, int device = -1) - : stream_(stream), device_(device), scratch_(NULL), semaphore_(NULL) { - if (device < 0) { - gpuGetDevice(&device_); - } else { - int num_devices; - gpuError_t err = gpuGetDeviceCount(&num_devices); - EIGEN_UNUSED_VARIABLE(err) - gpu_assert(err == gpuSuccess); - gpu_assert(device < num_devices); - device_ = device; - } - initializeDeviceProp(); - } - - virtual ~GpuStreamDevice() { - if (scratch_) { - deallocate(scratch_); - } - } - - const gpuStream_t& stream() const { return *stream_; } - const gpuDeviceProp_t& deviceProperties() const { - return m_deviceProperties[device_]; - } - virtual void* allocate(size_t num_bytes) const { - gpuError_t err = gpuSetDevice(device_); - EIGEN_UNUSED_VARIABLE(err) - gpu_assert(err == gpuSuccess); - void* result; - err = gpuMalloc(&result, num_bytes); - gpu_assert(err == gpuSuccess); - gpu_assert(result != NULL); - return result; - } - virtual void deallocate(void* buffer) const { - gpuError_t err = gpuSetDevice(device_); - EIGEN_UNUSED_VARIABLE(err) - gpu_assert(err == gpuSuccess); - gpu_assert(buffer != NULL); - err = gpuFree(buffer); - gpu_assert(err == gpuSuccess); - } - - virtual void* scratchpad() const { - if (scratch_ == NULL) { - scratch_ = allocate(kGpuScratchSize + sizeof(unsigned int)); - } - return scratch_; - } - - virtual unsigned int* semaphore() const { - if (semaphore_ == NULL) { - char* scratch = static_cast<char*>(scratchpad()) + kGpuScratchSize; - semaphore_ = reinterpret_cast<unsigned int*>(scratch); - gpuError_t err = gpuMemsetAsync(semaphore_, 0, sizeof(unsigned int), *stream_); - EIGEN_UNUSED_VARIABLE(err) - gpu_assert(err == gpuSuccess); - } - return semaphore_; - } - - private: - const gpuStream_t* stream_; - int device_; - mutable void* scratch_; - mutable unsigned int* semaphore_; -}; - -struct GpuDevice { - // The StreamInterface is not owned: the caller is - // responsible for its initialization and eventual destruction. - explicit GpuDevice(const StreamInterface* stream) : stream_(stream), max_blocks_(INT_MAX) { - eigen_assert(stream); - } - explicit GpuDevice(const StreamInterface* stream, int num_blocks) : stream_(stream), max_blocks_(num_blocks) { - eigen_assert(stream); - } - // TODO(bsteiner): This is an internal API, we should not expose it. - EIGEN_STRONG_INLINE const gpuStream_t& stream() const { - return stream_->stream(); - } - - EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const { - return stream_->allocate(num_bytes); - } - - EIGEN_STRONG_INLINE void deallocate(void* buffer) const { - stream_->deallocate(buffer); - } - - EIGEN_STRONG_INLINE void* allocate_temp(size_t num_bytes) const { - return stream_->allocate(num_bytes); - } - - EIGEN_STRONG_INLINE void deallocate_temp(void* buffer) const { - stream_->deallocate(buffer); - } - - template<typename Type> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Type get(Type data) const { - return data; - } - - EIGEN_STRONG_INLINE void* scratchpad() const { - return stream_->scratchpad(); - } - - EIGEN_STRONG_INLINE unsigned int* semaphore() const { - return stream_->semaphore(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpy(void* dst, const void* src, size_t n) const { -#ifndef EIGEN_GPU_COMPILE_PHASE - gpuError_t err = gpuMemcpyAsync(dst, src, n, gpuMemcpyDeviceToDevice, - stream_->stream()); - EIGEN_UNUSED_VARIABLE(err) - gpu_assert(err == gpuSuccess); -#else - EIGEN_UNUSED_VARIABLE(dst); - EIGEN_UNUSED_VARIABLE(src); - EIGEN_UNUSED_VARIABLE(n); - eigen_assert(false && "The default device should be used instead to generate kernel code"); -#endif - } - - EIGEN_STRONG_INLINE void memcpyHostToDevice(void* dst, const void* src, size_t n) const { - gpuError_t err = - gpuMemcpyAsync(dst, src, n, gpuMemcpyHostToDevice, stream_->stream()); - EIGEN_UNUSED_VARIABLE(err) - gpu_assert(err == gpuSuccess); - } - - EIGEN_STRONG_INLINE void memcpyDeviceToHost(void* dst, const void* src, size_t n) const { - gpuError_t err = - gpuMemcpyAsync(dst, src, n, gpuMemcpyDeviceToHost, stream_->stream()); - EIGEN_UNUSED_VARIABLE(err) - gpu_assert(err == gpuSuccess); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memset(void* buffer, int c, size_t n) const { -#ifndef EIGEN_GPU_COMPILE_PHASE - gpuError_t err = gpuMemsetAsync(buffer, c, n, stream_->stream()); - EIGEN_UNUSED_VARIABLE(err) - gpu_assert(err == gpuSuccess); -#else - eigen_assert(false && "The default device should be used instead to generate kernel code"); -#endif - } - - EIGEN_STRONG_INLINE size_t numThreads() const { - // FIXME - return 32; - } - - EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const { - // FIXME - return 48*1024; - } - - EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const { - // We won't try to take advantage of the l2 cache for the time being, and - // there is no l3 cache on hip/cuda devices. - return firstLevelCacheSize(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void synchronize() const { -#ifndef EIGEN_GPU_COMPILE_PHASE - gpuError_t err = gpuStreamSynchronize(stream_->stream()); - if (err != gpuSuccess) { - std::cerr << "Error detected in GPU stream: " - << gpuGetErrorString(err) - << std::endl; - gpu_assert(err == gpuSuccess); - } -#else - gpu_assert(false && "The default device should be used instead to generate kernel code"); -#endif - } - - EIGEN_STRONG_INLINE int getNumGpuMultiProcessors() const { - return stream_->deviceProperties().multiProcessorCount; - } - EIGEN_STRONG_INLINE int maxGpuThreadsPerBlock() const { - return stream_->deviceProperties().maxThreadsPerBlock; - } - EIGEN_STRONG_INLINE int maxGpuThreadsPerMultiProcessor() const { - return stream_->deviceProperties().maxThreadsPerMultiProcessor; - } - EIGEN_STRONG_INLINE int sharedMemPerBlock() const { - return stream_->deviceProperties().sharedMemPerBlock; - } - EIGEN_STRONG_INLINE int majorDeviceVersion() const { - return stream_->deviceProperties().major; - } - EIGEN_STRONG_INLINE int minorDeviceVersion() const { - return stream_->deviceProperties().minor; - } - - EIGEN_STRONG_INLINE int maxBlocks() const { - return max_blocks_; - } - - // This function checks if the GPU runtime recorded an error for the - // underlying stream device. - inline bool ok() const { -#ifdef EIGEN_GPUCC - gpuError_t error = gpuStreamQuery(stream_->stream()); - return (error == gpuSuccess) || (error == gpuErrorNotReady); -#else - return false; -#endif - } - - private: - const StreamInterface* stream_; - int max_blocks_; -}; - -#if defined(EIGEN_HIPCC) - -#define LAUNCH_GPU_KERNEL(kernel, gridsize, blocksize, sharedmem, device, ...) \ - hipLaunchKernelGGL(kernel, dim3(gridsize), dim3(blocksize), (sharedmem), (device).stream(), __VA_ARGS__); \ - gpu_assert(hipGetLastError() == hipSuccess); - -#else - -#define LAUNCH_GPU_KERNEL(kernel, gridsize, blocksize, sharedmem, device, ...) \ - (kernel) <<< (gridsize), (blocksize), (sharedmem), (device).stream() >>> (__VA_ARGS__); \ - gpu_assert(cudaGetLastError() == cudaSuccess); - -#endif - -// FIXME: Should be device and kernel specific. -#ifdef EIGEN_GPUCC -static EIGEN_DEVICE_FUNC inline void setGpuSharedMemConfig(gpuSharedMemConfig config) { -#ifndef EIGEN_GPU_COMPILE_PHASE - gpuError_t status = gpuDeviceSetSharedMemConfig(config); - EIGEN_UNUSED_VARIABLE(status) - gpu_assert(status == gpuSuccess); -#else - EIGEN_UNUSED_VARIABLE(config) -#endif -} -#endif - -} // end namespace Eigen - -// undefine all the gpu* macros we defined at the beginning of the file -#include "TensorGpuHipCudaUndefines.h" - -#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_GPU_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h deleted file mode 100644 index df591c21..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h +++ /dev/null @@ -1,1048 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> - -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#if defined(EIGEN_USE_SYCL) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H) -#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H -#include <unordered_set> - -namespace Eigen { - -namespace TensorSycl { -namespace internal { - -/// Cache all the device information needed -struct SyclDeviceInfo { - SyclDeviceInfo(cl::sycl::queue queue) - : local_mem_type( - queue.get_device() - .template get_info<cl::sycl::info::device::local_mem_type>()), - max_work_item_sizes( - queue.get_device() - .template get_info< - cl::sycl::info::device::max_work_item_sizes>()), - max_mem_alloc_size( - queue.get_device() - .template get_info< - cl::sycl::info::device::max_mem_alloc_size>()), - max_compute_units(queue.get_device() - .template get_info< - cl::sycl::info::device::max_compute_units>()), - max_work_group_size( - queue.get_device() - .template get_info< - cl::sycl::info::device::max_work_group_size>()), - local_mem_size( - queue.get_device() - .template get_info<cl::sycl::info::device::local_mem_size>()), - platform_name(queue.get_device() - .get_platform() - .template get_info<cl::sycl::info::platform::name>()), - device_name(queue.get_device() - .template get_info<cl::sycl::info::device::name>()), - device_vendor( - queue.get_device() - .template get_info<cl::sycl::info::device::vendor>()) {} - - cl::sycl::info::local_mem_type local_mem_type; - cl::sycl::id<3> max_work_item_sizes; - unsigned long max_mem_alloc_size; - unsigned long max_compute_units; - unsigned long max_work_group_size; - size_t local_mem_size; - std::string platform_name; - std::string device_name; - std::string device_vendor; -}; - -} // end namespace internal -} // end namespace TensorSycl - -typedef TensorSycl::internal::buffer_data_type_t buffer_scalar_t; -// All devices (even AMD CPU with intel OpenCL runtime) that support OpenCL and -// can consume SPIR or SPIRV can use the Eigen SYCL backend and consequently -// TensorFlow via the Eigen SYCL Backend. -EIGEN_STRONG_INLINE auto get_sycl_supported_devices() - -> decltype(cl::sycl::device::get_devices()) { -#ifdef EIGEN_SYCL_USE_DEFAULT_SELECTOR - return {cl::sycl::device(cl::sycl::default_selector())}; -#else - std::vector<cl::sycl::device> supported_devices; - auto platform_list = cl::sycl::platform::get_platforms(); - for (const auto &platform : platform_list) { - auto device_list = platform.get_devices(); - auto platform_name = - platform.template get_info<cl::sycl::info::platform::name>(); - std::transform(platform_name.begin(), platform_name.end(), - platform_name.begin(), ::tolower); - for (const auto &device : device_list) { - auto vendor = device.template get_info<cl::sycl::info::device::vendor>(); - std::transform(vendor.begin(), vendor.end(), vendor.begin(), ::tolower); - bool unsupported_condition = - (device.is_cpu() && platform_name.find("amd") != std::string::npos && - vendor.find("apu") == std::string::npos) || - (platform_name.find("experimental") != std::string::npos) || - device.is_host(); - if (!unsupported_condition) { - supported_devices.push_back(device); - } - } - } - return supported_devices; -#endif -} - -class QueueInterface { - public: - /// Creating device by using cl::sycl::selector or cl::sycl::device. - template <typename DeviceOrSelector> - explicit QueueInterface( - const DeviceOrSelector &dev_or_sel, cl::sycl::async_handler handler, - unsigned num_threads = std::thread::hardware_concurrency()) - : m_queue(dev_or_sel, handler), -#ifdef EIGEN_SYCL_USE_PROGRAM_CLASS - m_prog(m_queue.get_context(), get_sycl_supported_devices()), -#endif - m_thread_pool(num_threads), - m_device_info(m_queue) { -#ifdef EIGEN_SYCL_USE_PROGRAM_CLASS - m_prog.build_with_kernel_type<DeviceOrSelector>(); - auto f = [&](cl::sycl::handler &cgh) { - cgh.single_task<DeviceOrSelector>(m_prog.get_kernel<DeviceOrSelector>(), - [=]() {}) - }; - EIGEN_SYCL_TRY_CATCH(m_queue.submit(f)); -#endif - } - - template <typename DeviceOrSelector> - explicit QueueInterface( - const DeviceOrSelector &dev_or_sel, - unsigned num_threads = std::thread::hardware_concurrency()) - : QueueInterface(dev_or_sel, - [this](cl::sycl::exception_list l) { - this->exception_caught_ = this->sycl_async_handler(l); - }, - num_threads) {} - -#ifdef EIGEN_SYCL_USE_PROGRAM_CLASS - EIGEN_STRONG_INLINE cl::sycl::program &program() const { return m_prog; } -#endif - - /// Attach an existing buffer to the pointer map, Eigen will not reuse it - EIGEN_STRONG_INLINE void *attach_buffer( - cl::sycl::buffer<buffer_scalar_t, 1> &buf) const { - std::lock_guard<std::mutex> lock(pmapper_mutex_); - return static_cast<void *>(pMapper.add_pointer(buf)); - } - - /// Detach previously attached buffer - EIGEN_STRONG_INLINE void detach_buffer(void *p) const { - std::lock_guard<std::mutex> lock(pmapper_mutex_); - TensorSycl::internal::SYCLfree<false>(p, pMapper); - } - - /// Allocating device pointer. This pointer is actually an 8 bytes host - /// pointer used as key to access the sycl device buffer. The reason is that - /// we cannot use device buffer as a pointer as a m_data in Eigen leafNode - /// expressions. So we create a key pointer to be used in Eigen expression - /// construction. When we convert the Eigen construction into the sycl - /// construction we use this pointer as a key in our buffer_map and we make - /// sure that we dedicate only one buffer only for this pointer. The device - /// pointer would be deleted by calling deallocate function. - EIGEN_STRONG_INLINE void *allocate(size_t num_bytes) const { -#if EIGEN_MAX_ALIGN_BYTES > 0 - size_t align = num_bytes % EIGEN_MAX_ALIGN_BYTES; - if (align > 0) { - num_bytes += EIGEN_MAX_ALIGN_BYTES - align; - } -#endif - std::lock_guard<std::mutex> lock(pmapper_mutex_); - return TensorSycl::internal::SYCLmalloc(num_bytes, pMapper); - } - - EIGEN_STRONG_INLINE void *allocate_temp(size_t num_bytes) const { -#if EIGEN_MAX_ALIGN_BYTES > 0 - size_t align = num_bytes % EIGEN_MAX_ALIGN_BYTES; - if (align > 0) { - num_bytes += EIGEN_MAX_ALIGN_BYTES - align; - } -#endif - std::lock_guard<std::mutex> lock(pmapper_mutex_); -#ifndef EIGEN_SYCL_NO_REUSE_BUFFERS - if (scratch_buffers.empty()) { - return TensorSycl::internal::SYCLmalloc(num_bytes, pMapper); - ; - } else { - for (auto it = scratch_buffers.begin(); it != scratch_buffers.end();) { - auto buff = pMapper.get_buffer(*it); - if (buff.get_size() >= num_bytes) { - auto ptr = *it; - scratch_buffers.erase(it); - return ptr; - } else { - ++it; - } - } - return TensorSycl::internal::SYCLmalloc(num_bytes, pMapper); - } -#else - return TensorSycl::internal::SYCLmalloc(num_bytes, pMapper); -#endif - } - template <typename data_t> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorSycl::internal::RangeAccess< - cl::sycl::access::mode::read_write, data_t> - get(data_t *data) const { - return get_range_accessor<cl::sycl::access::mode::read_write, data_t>(data); - } - template <typename data_t> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE data_t *get( - TensorSycl::internal::RangeAccess<cl::sycl::access::mode::read_write, - data_t> - data) const { - return static_cast<data_t *>(data.get_virtual_pointer()); - } - - EIGEN_STRONG_INLINE void deallocate_temp(void *p) const { - std::lock_guard<std::mutex> lock(pmapper_mutex_); -#ifndef EIGEN_SYCL_NO_REUSE_BUFFERS - scratch_buffers.insert(p); -#else - TensorSycl::internal::SYCLfree(p, pMapper); -#endif - } - template <cl::sycl::access::mode AcMd, typename T> - EIGEN_STRONG_INLINE void deallocate_temp( - const TensorSycl::internal::RangeAccess<AcMd, T> &p) const { - deallocate_temp(p.get_virtual_pointer()); - } - - /// This is used to deallocate the device pointer. p is used as a key inside - /// the map to find the device buffer and delete it. - EIGEN_STRONG_INLINE void deallocate(void *p) const { - std::lock_guard<std::mutex> lock(pmapper_mutex_); - TensorSycl::internal::SYCLfree(p, pMapper); - } - - EIGEN_STRONG_INLINE void deallocate_all() const { - std::lock_guard<std::mutex> lock(pmapper_mutex_); - TensorSycl::internal::SYCLfreeAll(pMapper); -#ifndef EIGEN_SYCL_NO_REUSE_BUFFERS - scratch_buffers.clear(); -#endif - } - - /// The memcpyHostToDevice is used to copy the data from host to device - /// The destination pointer could be deleted before the copy happend which is - /// why a callback function is needed. By default if none is provided, the - /// function is blocking. - EIGEN_STRONG_INLINE void memcpyHostToDevice( - void *dst, const void *src, size_t n, - std::function<void()> callback) const { - static const auto write_mode = cl::sycl::access::mode::discard_write; - static const auto global_access = cl::sycl::access::target::global_buffer; - typedef cl::sycl::accessor<buffer_scalar_t, 1, write_mode, global_access> - write_accessor; - if (n == 0) { - if (callback) callback(); - return; - } - n /= sizeof(buffer_scalar_t); - auto f = [&](cl::sycl::handler &cgh) { - write_accessor dst_acc = get_range_accessor<write_mode>(cgh, dst, n); - buffer_scalar_t const *ptr = static_cast<buffer_scalar_t const *>(src); - auto non_deleter = [](buffer_scalar_t const *) {}; - std::shared_ptr<const buffer_scalar_t> s_ptr(ptr, non_deleter); - cgh.copy(s_ptr, dst_acc); - }; - cl::sycl::event e; - EIGEN_SYCL_TRY_CATCH(e = m_queue.submit(f)); - synchronize_and_callback(e, callback); - } - - /// The memcpyDeviceToHost is used to copy the data from device to host. - /// The source pointer could be deleted before the copy happend which is - /// why a callback function is needed. By default if none is provided, the - /// function is blocking. - EIGEN_STRONG_INLINE void memcpyDeviceToHost( - void *dst, const void *src, size_t n, - std::function<void()> callback) const { - static const auto read_mode = cl::sycl::access::mode::read; - static const auto global_access = cl::sycl::access::target::global_buffer; - typedef cl::sycl::accessor<buffer_scalar_t, 1, read_mode, global_access> - read_accessor; - if (n == 0) { - if (callback) callback(); - return; - } - n /= sizeof(buffer_scalar_t); - auto f = [&](cl::sycl::handler &cgh) { - read_accessor src_acc = get_range_accessor<read_mode>(cgh, src, n); - buffer_scalar_t *ptr = static_cast<buffer_scalar_t *>(dst); - auto non_deleter = [](buffer_scalar_t *) {}; - std::shared_ptr<buffer_scalar_t> s_ptr(ptr, non_deleter); - cgh.copy(src_acc, s_ptr); - }; - cl::sycl::event e; - EIGEN_SYCL_TRY_CATCH(e = m_queue.submit(f)); - synchronize_and_callback(e, callback); - } - - /// The memcpy function. - /// No callback is required here as both arguments are on the device - /// and SYCL can handle the dependency. - EIGEN_STRONG_INLINE void memcpy(void *dst, const void *src, size_t n) const { - static const auto read_mode = cl::sycl::access::mode::read; - static const auto write_mode = cl::sycl::access::mode::discard_write; - if (n == 0) { - return; - } - n /= sizeof(buffer_scalar_t); - auto f = [&](cl::sycl::handler &cgh) { - auto src_acc = get_range_accessor<read_mode>(cgh, src, n); - auto dst_acc = get_range_accessor<write_mode>(cgh, dst, n); - cgh.copy(src_acc, dst_acc); - }; - cl::sycl::event e; - EIGEN_SYCL_TRY_CATCH(e = m_queue.submit(f)); - async_synchronize(e); - } - - /// the memset function. - /// No callback is required here as both arguments are on the device - /// and SYCL can handle the dependency. - EIGEN_STRONG_INLINE void memset(void *data, int c, size_t n) const { - static const auto write_mode = cl::sycl::access::mode::discard_write; - if (n == 0) { - return; - } - n /= sizeof(buffer_scalar_t); - auto f = [&](cl::sycl::handler &cgh) { - auto dst_acc = get_range_accessor<write_mode>(cgh, data, n); - // The cast to uint8_t is here to match the behaviour of the standard - // memset. The cast to buffer_scalar_t is needed to match the type of the - // accessor (in case buffer_scalar_t is not uint8_t) - cgh.fill(dst_acc, static_cast<buffer_scalar_t>(static_cast<uint8_t>(c))); - }; - cl::sycl::event e; - EIGEN_SYCL_TRY_CATCH(e = m_queue.submit(f)); - async_synchronize(e); - } - - /// Get a range accessor to the virtual pointer's device memory. This range - /// accessor will allow access to the memory from the pointer to the end of - /// the buffer. - /// - /// NOTE: Inside a kernel the range accessor will always be indexed from the - /// start of the buffer, so the offset in the accessor is only used by - /// methods like handler::copy and will not be available inside a kernel. - template <cl::sycl::access::mode AcMd, typename T> - EIGEN_STRONG_INLINE TensorSycl::internal::RangeAccess<AcMd, T> - get_range_accessor(const void *ptr) const { - static const auto global_access = cl::sycl::access::target::global_buffer; - static const auto is_place_holder = cl::sycl::access::placeholder::true_t; - typedef TensorSycl::internal::RangeAccess<AcMd, T> ret_type; - typedef const TensorSycl::internal::buffer_data_type_t *internal_ptr_t; - - std::lock_guard<std::mutex> lock(pmapper_mutex_); - - auto original_buffer = pMapper.get_buffer(ptr); - const ptrdiff_t offset = pMapper.get_offset(ptr); - const ptrdiff_t typed_offset = offset / sizeof(T); - eigen_assert(typed_offset >= 0); - const auto typed_size = original_buffer.get_size() / sizeof(T); - auto buffer = original_buffer.template reinterpret< - typename Eigen::internal::remove_const<T>::type>( - cl::sycl::range<1>(typed_size)); - const ptrdiff_t size = buffer.get_count() - typed_offset; - eigen_assert(size >= 0); - typedef cl::sycl::accessor<typename Eigen::internal::remove_const<T>::type, - 1, AcMd, global_access, is_place_holder> - placeholder_accessor_t; - const auto start_ptr = static_cast<internal_ptr_t>(ptr) - offset; - return ret_type(placeholder_accessor_t(buffer, cl::sycl::range<1>(size), - cl::sycl::id<1>(typed_offset)), - static_cast<size_t>(typed_offset), - reinterpret_cast<std::intptr_t>(start_ptr)); - } - - /// Get a range accessor to the virtual pointer's device memory with a - /// specified size. - template <cl::sycl::access::mode AcMd, typename Index> - EIGEN_STRONG_INLINE cl::sycl::accessor< - buffer_scalar_t, 1, AcMd, cl::sycl::access::target::global_buffer> - get_range_accessor(cl::sycl::handler &cgh, const void *ptr, - const Index n_bytes) const { - static const auto global_access = cl::sycl::access::target::global_buffer; - eigen_assert(n_bytes >= 0); - std::lock_guard<std::mutex> lock(pmapper_mutex_); - auto buffer = pMapper.get_buffer(ptr); - const ptrdiff_t offset = pMapper.get_offset(ptr); - eigen_assert(offset >= 0); - eigen_assert(offset + n_bytes <= buffer.get_size()); - return buffer.template get_access<AcMd, global_access>( - cgh, cl::sycl::range<1>(n_bytes), cl::sycl::id<1>(offset)); - } - - /// Creation of sycl accessor for a buffer. This function first tries to find - /// the buffer in the buffer_map. If found it gets the accessor from it, if - /// not, the function then adds an entry by creating a sycl buffer for that - /// particular pointer. - template <cl::sycl::access::mode AcMd> - EIGEN_STRONG_INLINE cl::sycl::accessor< - buffer_scalar_t, 1, AcMd, cl::sycl::access::target::global_buffer> - get_sycl_accessor(cl::sycl::handler &cgh, const void *ptr) const { - std::lock_guard<std::mutex> lock(pmapper_mutex_); - return pMapper.get_buffer(ptr) - .template get_access<AcMd, cl::sycl::access::target::global_buffer>( - cgh); - } - - EIGEN_STRONG_INLINE cl::sycl::buffer<buffer_scalar_t, 1> get_sycl_buffer( - const void *ptr) const { - std::lock_guard<std::mutex> lock(pmapper_mutex_); - return pMapper.get_buffer(ptr); - } - - EIGEN_STRONG_INLINE ptrdiff_t get_offset(const void *ptr) const { - std::lock_guard<std::mutex> lock(pmapper_mutex_); - return pMapper.get_offset(ptr); - } - - template <typename OutScalar, typename sycl_kernel, typename Lhs, - typename Rhs, typename OutPtr, typename Range, typename Index, - typename... T> - EIGEN_ALWAYS_INLINE void binary_kernel_launcher(const Lhs &lhs, - const Rhs &rhs, OutPtr outptr, - Range thread_range, - Index scratchSize, - T... var) const { - auto kernel_functor = [=](cl::sycl::handler &cgh) { - // binding the placeholder accessors to a commandgroup handler - lhs.bind(cgh); - rhs.bind(cgh); - outptr.bind(cgh); - typedef cl::sycl::accessor<OutScalar, 1, - cl::sycl::access::mode::read_write, - cl::sycl::access::target::local> - LocalAccessor; - - LocalAccessor scratch(cl::sycl::range<1>(scratchSize), cgh); - cgh.parallel_for( -#ifdef EIGEN_SYCL_USE_PROGRAM_CLASS - program().template get_kernel<sycl_kernel>(), -#endif - thread_range, sycl_kernel(scratch, lhs, rhs, outptr, var...)); - }; - cl::sycl::event e; - EIGEN_SYCL_TRY_CATCH(e = m_queue.submit(kernel_functor)); - async_synchronize(e); - } - - template <typename OutScalar, typename sycl_kernel, typename InPtr, - typename OutPtr, typename Range, typename Index, typename... T> - EIGEN_ALWAYS_INLINE void unary_kernel_launcher(const InPtr &inptr, - OutPtr &outptr, - Range thread_range, - Index scratchSize, - T... var) const { - auto kernel_functor = [=](cl::sycl::handler &cgh) { - // binding the placeholder accessors to a commandgroup handler - inptr.bind(cgh); - outptr.bind(cgh); - typedef cl::sycl::accessor<OutScalar, 1, - cl::sycl::access::mode::read_write, - cl::sycl::access::target::local> - LocalAccessor; - - LocalAccessor scratch(cl::sycl::range<1>(scratchSize), cgh); - cgh.parallel_for( -#ifdef EIGEN_SYCL_USE_PROGRAM_CLASS - program().template get_kernel<sycl_kernel>(), -#endif - thread_range, sycl_kernel(scratch, inptr, outptr, var...)); - }; - cl::sycl::event e; - EIGEN_SYCL_TRY_CATCH(e = m_queue.submit(kernel_functor)); - async_synchronize(e); - } - - template <typename OutScalar, typename sycl_kernel, typename InPtr, - typename Range, typename Index, typename... T> - EIGEN_ALWAYS_INLINE void nullary_kernel_launcher(const InPtr &inptr, - Range thread_range, - Index scratchSize, - T... var) const { - auto kernel_functor = [=](cl::sycl::handler &cgh) { - // binding the placeholder accessors to a commandgroup handler - inptr.bind(cgh); - typedef cl::sycl::accessor<OutScalar, 1, - cl::sycl::access::mode::read_write, - cl::sycl::access::target::local> - LocalAccessor; - - LocalAccessor scratch(cl::sycl::range<1>(scratchSize), cgh); - cgh.parallel_for( -#ifdef EIGEN_SYCL_USE_PROGRAM_CLASS - program().template get_kernel<sycl_kernel>(), -#endif - thread_range, sycl_kernel(scratch, inptr, var...)); - }; - cl::sycl::event e; - EIGEN_SYCL_TRY_CATCH(e = m_queue.submit(kernel_functor)); - async_synchronize(e); - } - - - EIGEN_STRONG_INLINE void synchronize() const { -#ifdef EIGEN_EXCEPTIONS - m_queue.wait_and_throw(); -#else - m_queue.wait(); -#endif - } - - - EIGEN_STRONG_INLINE void async_synchronize(cl::sycl::event e) const { - set_latest_event(e); -#ifndef EIGEN_SYCL_ASYNC_EXECUTION - synchronize(); -#endif - } - - template <typename Index> - EIGEN_STRONG_INLINE void parallel_for_setup(Index n, Index &tileSize, - Index &rng, Index &GRange) const { - tileSize = static_cast<Index>(getNearestPowerOfTwoWorkGroupSize()); - tileSize = std::min(static_cast<Index>(EIGEN_SYCL_LOCAL_THREAD_DIM0 * - EIGEN_SYCL_LOCAL_THREAD_DIM1), - static_cast<Index>(tileSize)); - rng = n; - if (rng == 0) rng = static_cast<Index>(1); - GRange = rng; - if (tileSize > GRange) - tileSize = GRange; - else if (GRange > tileSize) { - Index xMode = static_cast<Index>(GRange % tileSize); - if (xMode != 0) GRange += static_cast<Index>(tileSize - xMode); - } - } - - /// This is used to prepare the number of threads and also the number of - /// threads per block for sycl kernels - template <typename Index> - EIGEN_STRONG_INLINE void parallel_for_setup( - const std::array<Index, 2> &input_dim, cl::sycl::range<2> &global_range, - cl::sycl::range<2> &local_range) const { - std::array<Index, 2> input_range = input_dim; - Index max_workgroup_Size = - static_cast<Index>(getNearestPowerOfTwoWorkGroupSize()); - max_workgroup_Size = - std::min(static_cast<Index>(EIGEN_SYCL_LOCAL_THREAD_DIM0 * - EIGEN_SYCL_LOCAL_THREAD_DIM1), - static_cast<Index>(max_workgroup_Size)); - Index pow_of_2 = static_cast<Index>(std::log2(max_workgroup_Size)); - local_range[1] = - static_cast<Index>(std::pow(2, static_cast<Index>(pow_of_2 / 2))); - input_range[1] = input_dim[1]; - if (input_range[1] == 0) input_range[1] = static_cast<Index>(1); - global_range[1] = input_range[1]; - if (local_range[1] > global_range[1]) - local_range[1] = global_range[1]; - else if (global_range[1] > local_range[1]) { - Index xMode = static_cast<Index>(global_range[1] % local_range[1]); - if (xMode != 0) - global_range[1] += static_cast<Index>(local_range[1] - xMode); - } - local_range[0] = static_cast<Index>(max_workgroup_Size / local_range[1]); - input_range[0] = input_dim[0]; - if (input_range[0] == 0) input_range[0] = static_cast<Index>(1); - global_range[0] = input_range[0]; - if (local_range[0] > global_range[0]) - local_range[0] = global_range[0]; - else if (global_range[0] > local_range[0]) { - Index xMode = static_cast<Index>(global_range[0] % local_range[0]); - if (xMode != 0) - global_range[0] += static_cast<Index>(local_range[0] - xMode); - } - } - - /// This is used to prepare the number of threads and also the number of - /// threads per block for sycl kernels - template <typename Index> - EIGEN_STRONG_INLINE void parallel_for_setup( - const std::array<Index, 3> &input_dim, cl::sycl::range<3> &global_range, - cl::sycl::range<3> &local_range) const { - std::array<Index, 3> input_range = input_dim; - Index max_workgroup_Size = - static_cast<Index>(getNearestPowerOfTwoWorkGroupSize()); - max_workgroup_Size = - std::min(static_cast<Index>(EIGEN_SYCL_LOCAL_THREAD_DIM0 * - EIGEN_SYCL_LOCAL_THREAD_DIM1), - static_cast<Index>(max_workgroup_Size)); - Index pow_of_2 = static_cast<Index>(std::log2(max_workgroup_Size)); - local_range[2] = - static_cast<Index>(std::pow(2, static_cast<Index>(pow_of_2 / 3))); - input_range[2] = input_dim[2]; - if (input_range[2] == 0) input_range[1] = static_cast<Index>(1); - global_range[2] = input_range[2]; - if (local_range[2] > global_range[2]) - local_range[2] = global_range[2]; - else if (global_range[2] > local_range[2]) { - Index xMode = static_cast<Index>(global_range[2] % local_range[2]); - if (xMode != 0) - global_range[2] += static_cast<Index>(local_range[2] - xMode); - } - pow_of_2 = static_cast<Index>( - std::log2(static_cast<Index>(max_workgroup_Size / local_range[2]))); - local_range[1] = - static_cast<Index>(std::pow(2, static_cast<Index>(pow_of_2 / 2))); - input_range[1] = input_dim[1]; - if (input_range[1] == 0) input_range[1] = static_cast<Index>(1); - global_range[1] = input_range[1]; - if (local_range[1] > global_range[1]) - local_range[1] = global_range[1]; - else if (global_range[1] > local_range[1]) { - Index xMode = static_cast<Index>(global_range[1] % local_range[1]); - if (xMode != 0) - global_range[1] += static_cast<Index>(local_range[1] - xMode); - } - local_range[0] = static_cast<Index>(max_workgroup_Size / - (local_range[1] * local_range[2])); - input_range[0] = input_dim[0]; - if (input_range[0] == 0) input_range[0] = static_cast<Index>(1); - global_range[0] = input_range[0]; - if (local_range[0] > global_range[0]) - local_range[0] = global_range[0]; - else if (global_range[0] > local_range[0]) { - Index xMode = static_cast<Index>(global_range[0] % local_range[0]); - if (xMode != 0) - global_range[0] += static_cast<Index>(local_range[0] - xMode); - } - } - - EIGEN_STRONG_INLINE bool has_local_memory() const { -#if !defined(EIGEN_SYCL_LOCAL_MEM) && defined(EIGEN_SYCL_NO_LOCAL_MEM) - return false; -#elif defined(EIGEN_SYCL_LOCAL_MEM) && !defined(EIGEN_SYCL_NO_LOCAL_MEM) - return true; -#else - return m_device_info.local_mem_type == - cl::sycl::info::local_mem_type::local; -#endif - } - - EIGEN_STRONG_INLINE unsigned long max_buffer_size() const { - return m_device_info.max_mem_alloc_size; - } - - EIGEN_STRONG_INLINE unsigned long getNumSyclMultiProcessors() const { - return m_device_info.max_compute_units; - } - - EIGEN_STRONG_INLINE unsigned long maxSyclThreadsPerBlock() const { - return m_device_info.max_work_group_size; - } - - EIGEN_STRONG_INLINE cl::sycl::id<3> maxWorkItemSizes() const { - return m_device_info.max_work_item_sizes; - } - - /// No need for sycl it should act the same as CPU version - EIGEN_STRONG_INLINE int majorDeviceVersion() const { return 1; } - - EIGEN_STRONG_INLINE unsigned long maxSyclThreadsPerMultiProcessor() const { - // OpenCL doesnot have such concept - return 2; - } - - EIGEN_STRONG_INLINE size_t sharedMemPerBlock() const { - return m_device_info.local_mem_size; - } - - // This function returns the nearest power of 2 Work-group size which is <= - // maximum device workgroup size. - EIGEN_STRONG_INLINE size_t getNearestPowerOfTwoWorkGroupSize() const { - return getPowerOfTwo(m_device_info.max_work_group_size, false); - } - - EIGEN_STRONG_INLINE std::string getPlatformName() const { - return m_device_info.platform_name; - } - - EIGEN_STRONG_INLINE std::string getDeviceName() const { - return m_device_info.device_name; - } - - EIGEN_STRONG_INLINE std::string getDeviceVendor() const { - return m_device_info.device_vendor; - } - - // This function returns the nearest power of 2 - // if roundup is true returns result>=wgsize - // else it return result <= wgsize - EIGEN_STRONG_INLINE size_t getPowerOfTwo(size_t wGSize, bool roundUp) const { - if (roundUp) --wGSize; - wGSize |= (wGSize >> 1); - wGSize |= (wGSize >> 2); - wGSize |= (wGSize >> 4); - wGSize |= (wGSize >> 8); - wGSize |= (wGSize >> 16); -#if EIGEN_ARCH_x86_64 || EIGEN_ARCH_ARM64 || EIGEN_OS_WIN64 - wGSize |= (wGSize >> 32); -#endif - return ((!roundUp) ? (wGSize - (wGSize >> 1)) : ++wGSize); - } - - EIGEN_STRONG_INLINE cl::sycl::queue &sycl_queue() const { return m_queue; } - - // This function checks if the runtime recorded an error for the - // underlying stream device. - EIGEN_STRONG_INLINE bool ok() const { - if (!exception_caught_) { - synchronize(); - } - return !exception_caught_; - } - - EIGEN_STRONG_INLINE cl::sycl::event get_latest_event() const { -#ifdef EIGEN_SYCL_STORE_LATEST_EVENT - std::lock_guard<std::mutex> lock(event_mutex_); - return latest_events_[std::this_thread::get_id()]; -#else - eigen_assert(false); - return cl::sycl::event(); -#endif - } - - // destructor - ~QueueInterface() { - pMapper.clear(); -#ifndef EIGEN_SYCL_NO_REUSE_BUFFERS - scratch_buffers.clear(); -#endif - } - - protected: - EIGEN_STRONG_INLINE void set_latest_event(cl::sycl::event e) const { -#ifdef EIGEN_SYCL_STORE_LATEST_EVENT - std::lock_guard<std::mutex> lock(event_mutex_); - latest_events_[std::this_thread::get_id()] = e; -#else - EIGEN_UNUSED_VARIABLE(e); -#endif - } - - void synchronize_and_callback(cl::sycl::event e, - const std::function<void()> &callback) const { - set_latest_event(e); - if (callback) { - auto callback_ = [=]() { -#ifdef EIGEN_EXCEPTIONS - cl::sycl::event(e).wait_and_throw(); -#else - cl::sycl::event(e).wait(); -#endif - callback(); - }; - m_thread_pool.Schedule(std::move(callback_)); - } else { -#ifdef EIGEN_EXCEPTIONS - m_queue.wait_and_throw(); -#else - m_queue.wait(); -#endif - } - } - - bool sycl_async_handler(cl::sycl::exception_list exceptions) const { - bool exception_caught = false; - for (const auto &e : exceptions) { - if (e) { - exception_caught = true; - EIGEN_THROW_X(e); - } - } - return exception_caught; - } - - /// class members: - bool exception_caught_ = false; - - mutable std::mutex pmapper_mutex_; - -#ifdef EIGEN_SYCL_STORE_LATEST_EVENT - mutable std::mutex event_mutex_; - mutable std::unordered_map<std::thread::id, cl::sycl::event> latest_events_; -#endif - - /// std::map is the container used to make sure that we create only one buffer - /// per pointer. The lifespan of the buffer now depends on the lifespan of - /// SyclDevice. If a non-read-only pointer is needed to be accessed on the - /// host we should manually deallocate it. - mutable TensorSycl::internal::PointerMapper pMapper; -#ifndef EIGEN_SYCL_NO_REUSE_BUFFERS - mutable std::unordered_set<void *> scratch_buffers; -#endif - /// sycl queue - mutable cl::sycl::queue m_queue; -#ifdef EIGEN_SYCL_USE_PROGRAM_CLASS - mutable cl::sycl::program m_prog; -#endif - - /// The thread pool is used to wait on events and call callbacks - /// asynchronously - mutable Eigen::ThreadPool m_thread_pool; - - const TensorSycl::internal::SyclDeviceInfo m_device_info; -}; - -struct SyclDeviceBase { - /// QueueInterface is not owned. it is the caller's responsibility to destroy - /// it - const QueueInterface *m_queue_stream; - explicit SyclDeviceBase(const QueueInterface *queue_stream) - : m_queue_stream(queue_stream) {} - EIGEN_STRONG_INLINE const QueueInterface *queue_stream() const { - return m_queue_stream; - } -}; - -// Here is a sycl device struct which accept the sycl queue interface -// as an input -struct SyclDevice : public SyclDeviceBase { - explicit SyclDevice(const QueueInterface *queue_stream) - : SyclDeviceBase(queue_stream) {} - - // this is the accessor used to construct the evaluator - template <cl::sycl::access::mode AcMd, typename T> - EIGEN_STRONG_INLINE TensorSycl::internal::RangeAccess<AcMd, T> - get_range_accessor(const void *ptr) const { - return queue_stream()->template get_range_accessor<AcMd, T>(ptr); - } - - // get sycl accessor - template <cl::sycl::access::mode AcMd> - EIGEN_STRONG_INLINE cl::sycl::accessor< - buffer_scalar_t, 1, AcMd, cl::sycl::access::target::global_buffer> - get_sycl_accessor(cl::sycl::handler &cgh, const void *ptr) const { - return queue_stream()->template get_sycl_accessor<AcMd>(cgh, ptr); - } - - /// Accessing the created sycl device buffer for the device pointer - EIGEN_STRONG_INLINE cl::sycl::buffer<buffer_scalar_t, 1> get_sycl_buffer( - const void *ptr) const { - return queue_stream()->get_sycl_buffer(ptr); - } - - /// This is used to prepare the number of threads and also the number of - /// threads per block for sycl kernels - template <typename Index> - EIGEN_STRONG_INLINE void parallel_for_setup(Index n, Index &tileSize, - Index &rng, Index &GRange) const { - queue_stream()->parallel_for_setup(n, tileSize, rng, GRange); - } - - /// This is used to prepare the number of threads and also the number of - /// threads per block for sycl kernels - template <typename Index> - EIGEN_STRONG_INLINE void parallel_for_setup( - const std::array<Index, 2> &input_dim, cl::sycl::range<2> &global_range, - cl::sycl::range<2> &local_range) const { - queue_stream()->parallel_for_setup(input_dim, global_range, local_range); - } - - /// This is used to prepare the number of threads and also the number of - /// threads per block for sycl kernels - template <typename Index> - EIGEN_STRONG_INLINE void parallel_for_setup( - const std::array<Index, 3> &input_dim, cl::sycl::range<3> &global_range, - cl::sycl::range<3> &local_range) const { - queue_stream()->parallel_for_setup(input_dim, global_range, local_range); - } - - /// allocate device memory - EIGEN_STRONG_INLINE void *allocate(size_t num_bytes) const { - return queue_stream()->allocate(num_bytes); - } - - EIGEN_STRONG_INLINE void *allocate_temp(size_t num_bytes) const { - return queue_stream()->allocate_temp(num_bytes); - } - - /// deallocate device memory - EIGEN_STRONG_INLINE void deallocate(void *p) const { - queue_stream()->deallocate(p); - } - - EIGEN_STRONG_INLINE void deallocate_temp(void *buffer) const { - queue_stream()->deallocate_temp(buffer); - } - template <cl::sycl::access::mode AcMd, typename T> - EIGEN_STRONG_INLINE void deallocate_temp( - const TensorSycl::internal::RangeAccess<AcMd, T> &buffer) const { - queue_stream()->deallocate_temp(buffer); - } - EIGEN_STRONG_INLINE void deallocate_all() const { - queue_stream()->deallocate_all(); - } - - template <typename data_t> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorSycl::internal::RangeAccess< - cl::sycl::access::mode::read_write, data_t> - get(data_t *data) const { - return queue_stream()->get(data); - } - template <typename data_t> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE data_t *get( - TensorSycl::internal::RangeAccess<cl::sycl::access::mode::read_write, - data_t> - data) const { - return queue_stream()->get(data); - } - - /// attach existing buffer - EIGEN_STRONG_INLINE void *attach_buffer( - cl::sycl::buffer<buffer_scalar_t, 1> &buf) const { - return queue_stream()->attach_buffer(buf); - } - /// detach buffer - EIGEN_STRONG_INLINE void detach_buffer(void *p) const { - queue_stream()->detach_buffer(p); - } - EIGEN_STRONG_INLINE ptrdiff_t get_offset(const void *ptr) const { - return queue_stream()->get_offset(ptr); - } - - // some runtime conditions that can be applied here - EIGEN_STRONG_INLINE bool isDeviceSuitable() const { return true; } - - /// memcpyHostToDevice - template <typename Index> - EIGEN_STRONG_INLINE void memcpyHostToDevice( - Index *dst, const Index *src, size_t n, - std::function<void()> callback = {}) const { - queue_stream()->memcpyHostToDevice(dst, src, n, callback); - } - /// memcpyDeviceToHost - template <typename Index> - EIGEN_STRONG_INLINE void memcpyDeviceToHost( - void *dst, const Index *src, size_t n, - std::function<void()> callback = {}) const { - queue_stream()->memcpyDeviceToHost(dst, src, n, callback); - } - /// the memcpy function - template <typename Index> - EIGEN_STRONG_INLINE void memcpy(void *dst, const Index *src, size_t n) const { - queue_stream()->memcpy(dst, src, n); - } - /// the memset function - EIGEN_STRONG_INLINE void memset(void *data, int c, size_t n) const { - queue_stream()->memset(data, c, n); - } - /// returning the sycl queue - EIGEN_STRONG_INLINE cl::sycl::queue &sycl_queue() const { - return queue_stream()->sycl_queue(); - } -#ifdef EIGEN_SYCL_USE_PROGRAM_CLASS - EIGEN_STRONG_INLINE cl::sycl::program &program() const { - return queue_stream()->program(); - } -#endif - - EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const { return 48 * 1024; } - - EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const { - // We won't try to take advantage of the l2 cache for the time being, and - // there is no l3 cache on sycl devices. - return firstLevelCacheSize(); - } - EIGEN_STRONG_INLINE unsigned long getNumSyclMultiProcessors() const { - return queue_stream()->getNumSyclMultiProcessors(); - } - EIGEN_STRONG_INLINE unsigned long maxSyclThreadsPerBlock() const { - return queue_stream()->maxSyclThreadsPerBlock(); - } - EIGEN_STRONG_INLINE cl::sycl::id<3> maxWorkItemSizes() const { - return queue_stream()->maxWorkItemSizes(); - } - EIGEN_STRONG_INLINE unsigned long maxSyclThreadsPerMultiProcessor() const { - // OpenCL doesnot have such concept - return queue_stream()->maxSyclThreadsPerMultiProcessor(); - } - EIGEN_STRONG_INLINE size_t sharedMemPerBlock() const { - return queue_stream()->sharedMemPerBlock(); - } - EIGEN_STRONG_INLINE size_t getNearestPowerOfTwoWorkGroupSize() const { - return queue_stream()->getNearestPowerOfTwoWorkGroupSize(); - } - - EIGEN_STRONG_INLINE size_t getPowerOfTwo(size_t val, bool roundUp) const { - return queue_stream()->getPowerOfTwo(val, roundUp); - } - /// No need for sycl it should act the same as CPU version - EIGEN_STRONG_INLINE int majorDeviceVersion() const { - return queue_stream()->majorDeviceVersion(); - } - - EIGEN_STRONG_INLINE void synchronize() const { - queue_stream()->synchronize(); - } - EIGEN_STRONG_INLINE void async_synchronize( - cl::sycl::event e = cl::sycl::event()) const { - queue_stream()->async_synchronize(e); - } - EIGEN_STRONG_INLINE cl::sycl::event get_latest_event() const { - return queue_stream()->get_latest_event(); - } - - // This function checks if the runtime recorded an error for the - // underlying stream device. - EIGEN_STRONG_INLINE bool ok() const { return queue_stream()->ok(); } - - EIGEN_STRONG_INLINE bool has_local_memory() const { - return queue_stream()->has_local_memory(); - } - EIGEN_STRONG_INLINE long max_buffer_size() const { - return queue_stream()->max_buffer_size(); - } - EIGEN_STRONG_INLINE std::string getPlatformName() const { - return queue_stream()->getPlatformName(); - } - EIGEN_STRONG_INLINE std::string getDeviceName() const { - return queue_stream()->getDeviceName(); - } - EIGEN_STRONG_INLINE std::string getDeviceVendor() const { - return queue_stream()->getDeviceVendor(); - } - template <typename OutScalar, typename KernelType, typename... T> - EIGEN_ALWAYS_INLINE void binary_kernel_launcher(T... var) const { - queue_stream()->template binary_kernel_launcher<OutScalar, KernelType>( - var...); - } - template <typename OutScalar, typename KernelType, typename... T> - EIGEN_ALWAYS_INLINE void unary_kernel_launcher(T... var) const { - queue_stream()->template unary_kernel_launcher<OutScalar, KernelType>( - var...); - } - - template <typename OutScalar, typename KernelType, typename... T> - EIGEN_ALWAYS_INLINE void nullary_kernel_launcher(T... var) const { - queue_stream()->template nullary_kernel_launcher<OutScalar, KernelType>( - var...); - } -}; -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h deleted file mode 100644 index cee46634..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h +++ /dev/null @@ -1,407 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#if defined(EIGEN_USE_THREADS) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_THREAD_POOL_H) -#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_THREAD_POOL_H - -namespace Eigen { - -// Runs an arbitrary function and then calls Notify() on the passed in -// Notification. -template <typename Function, typename... Args> struct FunctionWrapperWithNotification -{ - static void run(Notification* n, Function f, Args... args) { - f(args...); - if (n) { - n->Notify(); - } - } -}; - -template <typename Function, typename... Args> struct FunctionWrapperWithBarrier -{ - static void run(Barrier* b, Function f, Args... args) { - f(args...); - if (b) { - b->Notify(); - } - } -}; - -template <typename SyncType> -static EIGEN_STRONG_INLINE void wait_until_ready(SyncType* n) { - if (n) { - n->Wait(); - } -} - -// An abstract interface to a device specific memory allocator. -class Allocator { - public: - virtual ~Allocator() {} - virtual void* allocate(size_t num_bytes) const = 0; - virtual void deallocate(void* buffer) const = 0; -}; - -// Build a thread pool device on top the an existing pool of threads. -struct ThreadPoolDevice { - // The ownership of the thread pool remains with the caller. - ThreadPoolDevice(ThreadPoolInterface* pool, int num_cores, Allocator* allocator = nullptr) - : pool_(pool), num_threads_(num_cores), allocator_(allocator) { } - - EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const { - return allocator_ ? allocator_->allocate(num_bytes) - : internal::aligned_malloc(num_bytes); - } - - EIGEN_STRONG_INLINE void deallocate(void* buffer) const { - if (allocator_) { - allocator_->deallocate(buffer); - } else { - internal::aligned_free(buffer); - } - } - - EIGEN_STRONG_INLINE void* allocate_temp(size_t num_bytes) const { - return allocate(num_bytes); - } - - EIGEN_STRONG_INLINE void deallocate_temp(void* buffer) const { - deallocate(buffer); - } - - template<typename Type> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Type get(Type data) const { - return data; - } - - EIGEN_STRONG_INLINE void memcpy(void* dst, const void* src, size_t n) const { -#ifdef __ANDROID__ - ::memcpy(dst, src, n); -#else - // TODO(rmlarsen): Align blocks on cache lines. - // We have observed that going beyond 4 threads usually just wastes - // CPU cycles due to the threads competing for memory bandwidth, so we - // statically schedule at most 4 block copies here. - const size_t kMinBlockSize = 32768; - const size_t num_threads = CostModel::numThreads(n, TensorOpCost(1.0, 1.0, 0), 4); - if (n <= kMinBlockSize || num_threads < 2) { - ::memcpy(dst, src, n); - } else { - const char* src_ptr = static_cast<const char*>(src); - char* dst_ptr = static_cast<char*>(dst); - const size_t blocksize = (n + (num_threads - 1)) / num_threads; - Barrier barrier(static_cast<int>(num_threads - 1)); - // Launch the last 3 blocks on worker threads. - for (size_t i = 1; i < num_threads; ++i) { - enqueue_with_barrier(&barrier, [n, i, src_ptr, dst_ptr, blocksize] { - ::memcpy(dst_ptr + i * blocksize, src_ptr + i * blocksize, - numext::mini(blocksize, n - (i * blocksize))); - }); - } - // Launch the first block on the main thread. - ::memcpy(dst_ptr, src_ptr, blocksize); - barrier.Wait(); - } -#endif - } - EIGEN_STRONG_INLINE void memcpyHostToDevice(void* dst, const void* src, size_t n) const { - memcpy(dst, src, n); - } - EIGEN_STRONG_INLINE void memcpyDeviceToHost(void* dst, const void* src, size_t n) const { - memcpy(dst, src, n); - } - - EIGEN_STRONG_INLINE void memset(void* buffer, int c, size_t n) const { - ::memset(buffer, c, n); - } - - EIGEN_STRONG_INLINE int numThreads() const { - return num_threads_; - } - - // Number of theads available in the underlying thread pool. This number can - // be different from the value returned by numThreads(). - EIGEN_STRONG_INLINE int numThreadsInPool() const { - return pool_->NumThreads(); - } - - EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const { - return l1CacheSize(); - } - - EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const { - // The l3 cache size is shared between all the cores. - return l3CacheSize() / num_threads_; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const { - // Should return an enum that encodes the ISA supported by the CPU - return 1; - } - - template <class Function, class... Args> - EIGEN_STRONG_INLINE Notification* enqueue(Function&& f, - Args&&... args) const { - Notification* n = new Notification(); - pool_->Schedule( - std::bind(&FunctionWrapperWithNotification<Function, Args...>::run, n, - std::move(f), args...)); - return n; - } - - template <class Function, class... Args> - EIGEN_STRONG_INLINE void enqueue_with_barrier(Barrier* b, Function&& f, - Args&&... args) const { - pool_->Schedule( - std::bind(&FunctionWrapperWithBarrier<Function, Args...>::run, b, - std::move(f), args...)); - } - - template <class Function, class... Args> - EIGEN_STRONG_INLINE void enqueueNoNotification(Function&& f, - Args&&... args) const { - if (sizeof...(args) > 0) { - pool_->Schedule(std::bind(std::move(f), args...)); - } else { - pool_->Schedule(std::move(f)); - } - } - - // Returns a logical thread index between 0 and pool_->NumThreads() - 1 if - // called from one of the threads in pool_. Returns -1 otherwise. - EIGEN_STRONG_INLINE int currentThreadId() const { - return pool_->CurrentThreadId(); - } - - // WARNING: This function is synchronous and will block the calling thread. - // - // Synchronous parallelFor executes f with [0, n) arguments in parallel and - // waits for completion. F accepts a half-open interval [first, last). Block - // size is chosen based on the iteration cost and resulting parallel - // efficiency. If block_align is not nullptr, it is called to round up the - // block size. - void parallelFor(Index n, const TensorOpCost& cost, - std::function<Index(Index)> block_align, - std::function<void(Index, Index)> f) const { - // Compute small problems directly in the caller thread. - if (n <= 1 || numThreads() == 1 || - CostModel::numThreads(n, cost, static_cast<int>(numThreads())) == 1) { - f(0, n); - return; - } - - // Compute block size and total count of blocks. - ParallelForBlock block = CalculateParallelForBlock(n, cost, block_align); - - // Recursively divide size into halves until we reach block_size. - // Division code rounds mid to block_size, so we are guaranteed to get - // block_count leaves that do actual computations. - Barrier barrier(static_cast<unsigned int>(block.count)); - std::function<void(Index, Index)> handleRange; - handleRange = [=, &handleRange, &barrier, &f](Index firstIdx, - Index lastIdx) { - while (lastIdx - firstIdx > block.size) { - // Split into halves and schedule the second half on a different thread. - const Index midIdx = firstIdx + divup((lastIdx - firstIdx) / 2, block.size) * block.size; - pool_->Schedule([=, &handleRange]() { handleRange(midIdx, lastIdx); }); - lastIdx = midIdx; - } - // Single block or less, execute directly. - f(firstIdx, lastIdx); - barrier.Notify(); - }; - - if (block.count <= numThreads()) { - // Avoid a thread hop by running the root of the tree and one block on the - // main thread. - handleRange(0, n); - } else { - // Execute the root in the thread pool to avoid running work on more than - // numThreads() threads. - pool_->Schedule([=, &handleRange]() { handleRange(0, n); }); - } - - barrier.Wait(); - } - - // Convenience wrapper for parallelFor that does not align blocks. - void parallelFor(Index n, const TensorOpCost& cost, - std::function<void(Index, Index)> f) const { - parallelFor(n, cost, nullptr, std::move(f)); - } - - // WARNING: This function is asynchronous and will not block the calling thread. - // - // Asynchronous parallelFor executes f with [0, n) arguments in parallel - // without waiting for completion. When the last block finished, it will call - // 'done' callback. F accepts a half-open interval [first, last). Block size - // is chosen based on the iteration cost and resulting parallel efficiency. If - // block_align is not nullptr, it is called to round up the block size. - void parallelForAsync(Index n, const TensorOpCost& cost, - std::function<Index(Index)> block_align, - std::function<void(Index, Index)> f, - std::function<void()> done) const { - // Compute small problems directly in the caller thread. - if (n <= 1 || numThreads() == 1 || - CostModel::numThreads(n, cost, static_cast<int>(numThreads())) == 1) { - f(0, n); - done(); - return; - } - - // Compute block size and total count of blocks. - ParallelForBlock block = CalculateParallelForBlock(n, cost, block_align); - - ParallelForAsyncContext* const ctx = - new ParallelForAsyncContext(block.count, std::move(f), std::move(done)); - - // Recursively divide size into halves until we reach block_size. - // Division code rounds mid to block_size, so we are guaranteed to get - // block_count leaves that do actual computations. - ctx->handle_range = [this, ctx, block](Index firstIdx, Index lastIdx) { - while (lastIdx - firstIdx > block.size) { - // Split into halves and schedule the second half on a different thread. - const Index midIdx = firstIdx + divup((lastIdx - firstIdx) / 2, block.size) * block.size; - pool_->Schedule( - [ctx, midIdx, lastIdx]() { ctx->handle_range(midIdx, lastIdx); }); - lastIdx = midIdx; - } - - // Single block or less, execute directly. - ctx->f(firstIdx, lastIdx); - - // Delete async context if it was the last block. - if (ctx->count.fetch_sub(1) == 1) delete ctx; - }; - - if (block.count <= numThreads()) { - // Avoid a thread hop by running the root of the tree and one block on the - // main thread. - ctx->handle_range(0, n); - } else { - // Execute the root in the thread pool to avoid running work on more than - // numThreads() threads. - pool_->Schedule([ctx, n]() { ctx->handle_range(0, n); }); - } - } - - // Convenience wrapper for parallelForAsync that does not align blocks. - void parallelForAsync(Index n, const TensorOpCost& cost, - std::function<void(Index, Index)> f, - std::function<void()> done) const { - parallelForAsync(n, cost, nullptr, std::move(f), std::move(done)); - } - - // Thread pool accessor. - ThreadPoolInterface* getPool() const { return pool_; } - - // Allocator accessor. - Allocator* allocator() const { return allocator_; } - - private: - typedef TensorCostModel<ThreadPoolDevice> CostModel; - - // For parallelForAsync we must keep passed in closures on the heap, and - // delete them only after `done` callback finished. - struct ParallelForAsyncContext { - ParallelForAsyncContext(Index block_count, - std::function<void(Index, Index)> block_f, - std::function<void()> done_callback) - : count(block_count), - f(std::move(block_f)), - done(std::move(done_callback)) {} - ~ParallelForAsyncContext() { done(); } - - std::atomic<Index> count; - std::function<void(Index, Index)> f; - std::function<void()> done; - - std::function<void(Index, Index)> handle_range; - }; - - struct ParallelForBlock { - Index size; // block size - Index count; // number of blocks - }; - - // Calculates block size based on (1) the iteration cost and (2) parallel - // efficiency. We want blocks to be not too small to mitigate parallelization - // overheads; not too large to mitigate tail effect and potential load - // imbalance and we also want number of blocks to be evenly dividable across - // threads. - ParallelForBlock CalculateParallelForBlock( - const Index n, const TensorOpCost& cost, - std::function<Index(Index)> block_align) const { - const double block_size_f = 1.0 / CostModel::taskSize(1, cost); - const Index max_oversharding_factor = 4; - Index block_size = numext::mini( - n, numext::maxi<Index>( - divup<Index>(n, max_oversharding_factor * numThreads()), - block_size_f)); - const Index max_block_size = numext::mini(n, 2 * block_size); - - if (block_align) { - Index new_block_size = block_align(block_size); - eigen_assert(new_block_size >= block_size); - block_size = numext::mini(n, new_block_size); - } - - Index block_count = divup(n, block_size); - - // Calculate parallel efficiency as fraction of total CPU time used for - // computations: - double max_efficiency = - static_cast<double>(block_count) / - (divup<int>(block_count, numThreads()) * numThreads()); - - // Now try to increase block size up to max_block_size as long as it - // doesn't decrease parallel efficiency. - for (Index prev_block_count = block_count; - max_efficiency < 1.0 && prev_block_count > 1;) { - // This is the next block size that divides size into a smaller number - // of blocks than the current block_size. - Index coarser_block_size = divup(n, prev_block_count - 1); - if (block_align) { - Index new_block_size = block_align(coarser_block_size); - eigen_assert(new_block_size >= coarser_block_size); - coarser_block_size = numext::mini(n, new_block_size); - } - if (coarser_block_size > max_block_size) { - break; // Reached max block size. Stop. - } - // Recalculate parallel efficiency. - const Index coarser_block_count = divup(n, coarser_block_size); - eigen_assert(coarser_block_count < prev_block_count); - prev_block_count = coarser_block_count; - const double coarser_efficiency = - static_cast<double>(coarser_block_count) / - (divup<int>(coarser_block_count, numThreads()) * numThreads()); - if (coarser_efficiency + 0.01 >= max_efficiency) { - // Taking it. - block_size = coarser_block_size; - block_count = coarser_block_count; - if (max_efficiency < coarser_efficiency) { - max_efficiency = coarser_efficiency; - } - } - } - - return {block_size, block_count}; - } - - ThreadPoolInterface* pool_; - int num_threads_; - Allocator* allocator_; -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_THREAD_POOL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h deleted file mode 100644 index 1a30e45f..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h +++ /dev/null @@ -1,236 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H -#define EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H - -namespace Eigen { - -/** \internal - * - * \class TensorDimensionList - * \ingroup CXX11_Tensor_Module - * - * \brief Special case of tensor index list used to list all the dimensions of a tensor of rank n. - * - * \sa Tensor - */ - -template <typename Index, std::size_t Rank> struct DimensionList { - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - const Index operator[] (const Index i) const { return i; } -}; - -namespace internal { - -template<typename Index, std::size_t Rank> struct array_size<DimensionList<Index, Rank> > { - static const size_t value = Rank; -}; -template<typename Index, std::size_t Rank> struct array_size<const DimensionList<Index, Rank> > { - static const size_t value = Rank; -}; - -template<DenseIndex n, typename Index, std::size_t Rank> const Index array_get(DimensionList<Index, Rank>&) { - return n; -} -template<DenseIndex n, typename Index, std::size_t Rank> const Index array_get(const DimensionList<Index, Rank>&) { - return n; -} - - -#if EIGEN_HAS_CONSTEXPR -template <typename Index, std::size_t Rank> -struct index_known_statically_impl<DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex) { - return true; - } -}; -template <typename Index, std::size_t Rank> -struct index_known_statically_impl<const DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex) { - return true; - } -}; - -template <typename Index, std::size_t Rank> -struct all_indices_known_statically_impl<DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return true; - } -}; -template <typename Index, std::size_t Rank> -struct all_indices_known_statically_impl<const DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return true; - } -}; - -template <typename Index, std::size_t Rank> -struct indices_statically_known_to_increase_impl<DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return true; - } -}; -template <typename Index, std::size_t Rank> -struct indices_statically_known_to_increase_impl<const DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return true; - } -}; - -template <typename Index, std::size_t Rank> -struct index_statically_eq_impl<DimensionList<Index, Rank> > { - static constexpr bool run(const DenseIndex i, const DenseIndex value) { - return i == value; - } -}; -template <typename Index, std::size_t Rank> -struct index_statically_eq_impl<const DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) { - return i == value; - } -}; - -template <typename Index, std::size_t Rank> -struct index_statically_ne_impl<DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) { - return i != value; - } -}; -template <typename Index, std::size_t Rank> -struct index_statically_ne_impl<const DimensionList<Index, Rank> > { - static constexpr bool run(const DenseIndex i, const DenseIndex value) { - return i != value; - } -}; - -template <typename Index, std::size_t Rank> -struct index_statically_gt_impl<DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) { - return i > value; - } -}; -template <typename Index, std::size_t Rank> -struct index_statically_gt_impl<const DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) { - return i > value; - } -}; - -template <typename Index, std::size_t Rank> -struct index_statically_lt_impl<DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) { - return i < value; - } -}; -template <typename Index, std::size_t Rank> -struct index_statically_lt_impl<const DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const DenseIndex i, const DenseIndex value) { - return i < value; - } -}; - -#else -template <typename Index, std::size_t Rank> -struct index_known_statically_impl<DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE bool run(const DenseIndex) { - return true; - } -}; -template <typename Index, std::size_t Rank> -struct index_known_statically_impl<const DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE bool run(const DenseIndex) { - return true; - } -}; - -template <typename Index, std::size_t Rank> -struct all_indices_known_statically_impl<DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE bool run() { - return true; - } -}; -template <typename Index, std::size_t Rank> -struct all_indices_known_statically_impl<const DimensionList<Index, Rank> > { - EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE bool run() { - return true; - } -}; - -template <typename Index, std::size_t Rank> -struct indices_statically_known_to_increase_impl<DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() { - return true; - } -}; -template <typename Index, std::size_t Rank> -struct indices_statically_known_to_increase_impl<const DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() { - return true; - } -}; - -template <typename Index, std::size_t Rank> -struct index_statically_eq_impl<DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) { - return false; - } -}; -template <typename Index, std::size_t Rank> -struct index_statically_eq_impl<const DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) { - return false; - } -}; - -template <typename Index, std::size_t Rank> -struct index_statically_ne_impl<DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex){ - return false; - } -}; -template <typename Index, std::size_t Rank> -struct index_statically_ne_impl<const DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) { - return false; - } -}; - -template <typename Index, std::size_t Rank> -struct index_statically_gt_impl<DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) { - return false; - } -}; -template <typename Index, std::size_t Rank> -struct index_statically_gt_impl<const DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) { - return false; - } -}; - -template <typename Index, std::size_t Rank> -struct index_statically_lt_impl<DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) { - return false; - } -}; -template <typename Index, std::size_t Rank> -struct index_statically_lt_impl<const DimensionList<Index, Rank> > { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) { - return false; - } -}; -#endif - -} // end namespace internal -} // end namespace Eigen - - -#endif // EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h deleted file mode 100644 index 132458a2..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h +++ /dev/null @@ -1,490 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H -#define EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H - - -namespace Eigen { - -/** \internal - * - * \class TensorDimensions - * \ingroup CXX11_Tensor_Module - * - * \brief Set of classes used to encode and store the dimensions of a Tensor. - * - * The Sizes class encodes as part of the type the number of dimensions and the - * sizes corresponding to each dimension. It uses no storage space since it is - * entirely known at compile time. - * The DSizes class is its dynamic sibling: the number of dimensions is known - * at compile time but the sizes are set during execution. - * - * \sa Tensor - */ - -// Boilerplate code -namespace internal { - -template<std::ptrdiff_t n, typename Dimension> struct dget { - static const std::ptrdiff_t value = get<n, Dimension>::value; -}; - - -template<typename Index, std::ptrdiff_t NumIndices, std::ptrdiff_t n, bool RowMajor> -struct fixed_size_tensor_index_linearization_helper -{ - template <typename Dimensions> EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const& indices, - const Dimensions& dimensions) - { - return array_get<RowMajor ? n - 1 : (NumIndices - n)>(indices) + - dget<RowMajor ? n - 1 : (NumIndices - n), Dimensions>::value * - fixed_size_tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions); - } -}; - -template<typename Index, std::ptrdiff_t NumIndices, bool RowMajor> -struct fixed_size_tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor> -{ - template <typename Dimensions> EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const&, const Dimensions&) - { - return 0; - } -}; - -template<typename Index, std::ptrdiff_t n> -struct fixed_size_tensor_index_extraction_helper -{ - template <typename Dimensions> EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Index run(const Index index, - const Dimensions& dimensions) - { - const Index mult = (index == n-1) ? 1 : 0; - return array_get<n-1>(dimensions) * mult + - fixed_size_tensor_index_extraction_helper<Index, n - 1>::run(index, dimensions); - } -}; - -template<typename Index> -struct fixed_size_tensor_index_extraction_helper<Index, 0> -{ - template <typename Dimensions> EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Index run(const Index, - const Dimensions&) - { - return 0; - } - }; - -} // end namespace internal - - -// Fixed size -#ifndef EIGEN_EMULATE_CXX11_META_H -template <typename std::ptrdiff_t... Indices> -struct Sizes { - typedef internal::numeric_list<std::ptrdiff_t, Indices...> Base; - const Base t = Base(); - static const std::ptrdiff_t total_size = internal::arg_prod(Indices...); - static const ptrdiff_t count = Base::count; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t rank() const { - return Base::count; - } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t TotalSize() { - return internal::arg_prod(Indices...); - } - - EIGEN_DEVICE_FUNC Sizes() { } - template <typename DenseIndex> - explicit EIGEN_DEVICE_FUNC Sizes(const array<DenseIndex, Base::count>& /*indices*/) { - // todo: add assertion - } -#if EIGEN_HAS_VARIADIC_TEMPLATES - template <typename... DenseIndex> EIGEN_DEVICE_FUNC Sizes(DenseIndex...) { } - explicit EIGEN_DEVICE_FUNC Sizes(std::initializer_list<std::ptrdiff_t> /*l*/) { - // todo: add assertion - } -#endif - - template <typename T> Sizes& operator = (const T& /*other*/) { - // add assertion failure if the size of other is different - return *this; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t operator[] (const std::ptrdiff_t index) const { - return internal::fixed_size_tensor_index_extraction_helper<std::ptrdiff_t, Base::count>::run(index, t); - } - - template <typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - ptrdiff_t IndexOfColMajor(const array<DenseIndex, Base::count>& indices) const { - return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, t); - } - template <typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - ptrdiff_t IndexOfRowMajor(const array<DenseIndex, Base::count>& indices) const { - return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, t); - } -}; - -namespace internal { -template <typename std::ptrdiff_t... Indices> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes<Indices...>&) { - return Sizes<Indices...>::total_size; -} -} - -#else - -template <std::ptrdiff_t n> -struct non_zero_size { - typedef internal::type2val<std::ptrdiff_t, n> type; -}; -template <> -struct non_zero_size<0> { - typedef internal::null_type type; -}; - -template <std::ptrdiff_t V1=0, std::ptrdiff_t V2=0, std::ptrdiff_t V3=0, std::ptrdiff_t V4=0, std::ptrdiff_t V5=0> struct Sizes { - typedef typename internal::make_type_list<typename non_zero_size<V1>::type, typename non_zero_size<V2>::type, typename non_zero_size<V3>::type, typename non_zero_size<V4>::type, typename non_zero_size<V5>::type >::type Base; - static const std::ptrdiff_t count = Base::count; - static const std::ptrdiff_t total_size = internal::arg_prod<Base>::value; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptrdiff_t rank() const { - return count; - } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptrdiff_t TotalSize() { - return internal::arg_prod<Base>::value; - } - - Sizes() { } - template <typename DenseIndex> - explicit Sizes(const array<DenseIndex, Base::count>& /*indices*/) { - // todo: add assertion - } - template <typename T> Sizes& operator = (const T& /*other*/) { - // add assertion failure if the size of other is different - return *this; - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template <typename... DenseIndex> Sizes(DenseIndex... /*indices*/) { } - explicit Sizes(std::initializer_list<std::ptrdiff_t>) { - // todo: add assertion - } -#else - EIGEN_DEVICE_FUNC explicit Sizes(const DenseIndex) { - } - EIGEN_DEVICE_FUNC Sizes(const DenseIndex, const DenseIndex) { - } - EIGEN_DEVICE_FUNC Sizes(const DenseIndex, const DenseIndex, const DenseIndex) { - } - EIGEN_DEVICE_FUNC Sizes(const DenseIndex, const DenseIndex, const DenseIndex, const DenseIndex) { - } - EIGEN_DEVICE_FUNC Sizes(const DenseIndex, const DenseIndex, const DenseIndex, const DenseIndex, const DenseIndex) { - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index operator[] (const Index index) const { - switch (index) { - case 0: - return internal::get<0, Base>::value; - case 1: - return internal::get<1, Base>::value; - case 2: - return internal::get<2, Base>::value; - case 3: - return internal::get<3, Base>::value; - case 4: - return internal::get<4, Base>::value; - default: - eigen_assert(false && "index overflow"); - return static_cast<Index>(-1); - } - } - - template <typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - ptrdiff_t IndexOfColMajor(const array<DenseIndex, Base::count>& indices) const { - return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, *reinterpret_cast<const Base*>(this)); - } - template <typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - ptrdiff_t IndexOfRowMajor(const array<DenseIndex, Base::count>& indices) const { - return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, *reinterpret_cast<const Base*>(this)); - } -}; - -namespace internal { -template <std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes<V1, V2, V3, V4, V5>&) { - return Sizes<V1, V2, V3, V4, V5>::total_size; -} -} - -#endif - -// Boilerplate -namespace internal { -template<typename Index, std::ptrdiff_t NumIndices, std::ptrdiff_t n, bool RowMajor> -struct tensor_index_linearization_helper -{ - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index run(array<Index, NumIndices> const& indices, array<Index, NumIndices> const& dimensions) - { - return array_get<RowMajor ? n : (NumIndices - n - 1)>(indices) + - array_get<RowMajor ? n : (NumIndices - n - 1)>(dimensions) * - tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions); - } -}; - -template<typename Index, std::ptrdiff_t NumIndices, bool RowMajor> -struct tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor> -{ - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index run(array<Index, NumIndices> const& indices, array<Index, NumIndices> const&) - { - return array_get<RowMajor ? 0 : NumIndices - 1>(indices); - } -}; -} // end namespace internal - - - -// Dynamic size -template <typename DenseIndex, int NumDims> -struct DSizes : array<DenseIndex, NumDims> { - typedef array<DenseIndex, NumDims> Base; - static const int count = NumDims; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { - return NumDims; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const { - return (NumDims == 0) ? 1 : internal::array_prod(*static_cast<const Base*>(this)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DSizes() { - for (int i = 0 ; i < NumDims; ++i) { - (*this)[i] = 0; - } - } - EIGEN_DEVICE_FUNC explicit DSizes(const array<DenseIndex, NumDims>& a) : Base(a) { } - - EIGEN_DEVICE_FUNC explicit DSizes(const DenseIndex i0) { - eigen_assert(NumDims == 1); - (*this)[0] = i0; - } - - EIGEN_DEVICE_FUNC DSizes(const DimensionList<DenseIndex, NumDims>& a) { - for (int i = 0 ; i < NumDims; ++i) { - (*this)[i] = a[i]; - } - } - - // Enable DSizes index type promotion only if we are promoting to the - // larger type, e.g. allow to promote dimensions of type int to long. - template<typename OtherIndex> - EIGEN_DEVICE_FUNC - explicit DSizes(const array<OtherIndex, NumDims>& other, - // Default template parameters require c++11. - typename internal::enable_if< - internal::is_same< - DenseIndex, - typename internal::promote_index_type< - DenseIndex, - OtherIndex - >::type - >::value, void*>::type = 0) { - for (int i = 0; i < NumDims; ++i) { - (*this)[i] = static_cast<DenseIndex>(other[i]); - } - } - -#ifdef EIGEN_HAS_INDEX_LIST - template <typename FirstType, typename... OtherTypes> - EIGEN_DEVICE_FUNC - explicit DSizes(const Eigen::IndexList<FirstType, OtherTypes...>& dimensions) { - for (int i = 0; i < dimensions.count; ++i) { - (*this)[i] = dimensions[i]; - } - } -#endif - -#ifndef EIGEN_EMULATE_CXX11_META_H - template <typename std::ptrdiff_t... Indices> - EIGEN_DEVICE_FUNC DSizes(const Sizes<Indices...>& a) { - for (int i = 0 ; i < NumDims; ++i) { - (*this)[i] = a[i]; - } - } -#else - template <std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5> - EIGEN_DEVICE_FUNC DSizes(const Sizes<V1, V2, V3, V4, V5>& a) { - for (int i = 0 ; i < NumDims; ++i) { - (*this)[i] = a[i]; - } - } -#endif - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE explicit DSizes(DenseIndex firstDimension, DenseIndex secondDimension, IndexTypes... otherDimensions) : Base({{firstDimension, secondDimension, otherDimensions...}}) { - EIGEN_STATIC_ASSERT(sizeof...(otherDimensions) + 2 == NumDims, YOU_MADE_A_PROGRAMMING_MISTAKE) - } -#else - EIGEN_DEVICE_FUNC DSizes(const DenseIndex i0, const DenseIndex i1) { - eigen_assert(NumDims == 2); - (*this)[0] = i0; - (*this)[1] = i1; - } - EIGEN_DEVICE_FUNC DSizes(const DenseIndex i0, const DenseIndex i1, const DenseIndex i2) { - eigen_assert(NumDims == 3); - (*this)[0] = i0; - (*this)[1] = i1; - (*this)[2] = i2; - } - EIGEN_DEVICE_FUNC DSizes(const DenseIndex i0, const DenseIndex i1, const DenseIndex i2, const DenseIndex i3) { - eigen_assert(NumDims == 4); - (*this)[0] = i0; - (*this)[1] = i1; - (*this)[2] = i2; - (*this)[3] = i3; - } - EIGEN_DEVICE_FUNC DSizes(const DenseIndex i0, const DenseIndex i1, const DenseIndex i2, const DenseIndex i3, const DenseIndex i4) { - eigen_assert(NumDims == 5); - (*this)[0] = i0; - (*this)[1] = i1; - (*this)[2] = i2; - (*this)[3] = i3; - (*this)[4] = i4; - } -#endif - - EIGEN_DEVICE_FUNC DSizes& operator = (const array<DenseIndex, NumDims>& other) { - *static_cast<Base*>(this) = other; - return *this; - } - - // A constexpr would be so much better here - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfColMajor(const array<DenseIndex, NumDims>& indices) const { - return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, false>::run(indices, *static_cast<const Base*>(this)); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfRowMajor(const array<DenseIndex, NumDims>& indices) const { - return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, true>::run(indices, *static_cast<const Base*>(this)); - } -}; - -template <typename IndexType, int NumDims> -std::ostream& operator<<(std::ostream& os, - const DSizes<IndexType, NumDims>& dims) { - os << "["; - for (int i = 0; i < NumDims; ++i) { - if (i > 0) os << ", "; - os << dims[i]; - } - os << "]"; - return os; -} - -// Boilerplate -namespace internal { -template<typename Index, std::ptrdiff_t NumIndices, std::ptrdiff_t n, bool RowMajor> -struct tensor_vsize_index_linearization_helper -{ - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index run(array<Index, NumIndices> const& indices, std::vector<DenseIndex> const& dimensions) - { - return array_get<RowMajor ? n : (NumIndices - n - 1)>(indices) + - array_get<RowMajor ? n : (NumIndices - n - 1)>(dimensions) * - tensor_vsize_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions); - } -}; - -template<typename Index, std::ptrdiff_t NumIndices, bool RowMajor> -struct tensor_vsize_index_linearization_helper<Index, NumIndices, 0, RowMajor> -{ - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Index run(array<Index, NumIndices> const& indices, std::vector<DenseIndex> const&) - { - return array_get<RowMajor ? 0 : NumIndices - 1>(indices); - } -}; -} // end namespace internal - - -namespace internal { - -template <typename DenseIndex, int NumDims> struct array_size<const DSizes<DenseIndex, NumDims> > { - static const ptrdiff_t value = NumDims; -}; -template <typename DenseIndex, int NumDims> struct array_size<DSizes<DenseIndex, NumDims> > { - static const ptrdiff_t value = NumDims; -}; -#ifndef EIGEN_EMULATE_CXX11_META_H -template <typename std::ptrdiff_t... Indices> struct array_size<const Sizes<Indices...> > { -static const std::ptrdiff_t value = Sizes<Indices...>::count; -}; -template <typename std::ptrdiff_t... Indices> struct array_size<Sizes<Indices...> > { -static const std::ptrdiff_t value = Sizes<Indices...>::count; -}; -template <std::ptrdiff_t n, typename std::ptrdiff_t... Indices> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes<Indices...>&) { - return get<n, internal::numeric_list<std::ptrdiff_t, Indices...> >::value; -} -template <std::ptrdiff_t n> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes<>&) { - eigen_assert(false && "should never be called"); - return -1; -} -#else -template <std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5> struct array_size<const Sizes<V1,V2,V3,V4,V5> > { - static const ptrdiff_t value = Sizes<V1,V2,V3,V4,V5>::count; -}; -template <std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5> struct array_size<Sizes<V1,V2,V3,V4,V5> > { - static const ptrdiff_t value = Sizes<V1,V2,V3,V4,V5>::count; -}; -template <std::ptrdiff_t n, std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes<V1,V2,V3,V4,V5>&) { - return get<n, typename Sizes<V1,V2,V3,V4,V5>::Base>::value; -} - -#endif - - -template <typename Dims1, typename Dims2, ptrdiff_t n, ptrdiff_t m> -struct sizes_match_below_dim { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Dims1&, Dims2&) { - return false; - } -}; -template <typename Dims1, typename Dims2, ptrdiff_t n> -struct sizes_match_below_dim<Dims1, Dims2, n, n> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Dims1& dims1, Dims2& dims2) { - return (array_get<n-1>(dims1) == array_get<n-1>(dims2)) & - sizes_match_below_dim<Dims1, Dims2, n-1, n-1>::run(dims1, dims2); - } -}; -template <typename Dims1, typename Dims2> -struct sizes_match_below_dim<Dims1, Dims2, 0, 0> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Dims1&, Dims2&) { - return true; - } -}; - -} // end namespace internal - - -template <typename Dims1, typename Dims2> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool dimensions_match(Dims1 dims1, Dims2 dims2) { - return internal::sizes_match_below_dim<Dims1, Dims2, internal::array_size<Dims1>::value, internal::array_size<Dims2>::value>::run(dims1, dims2); -} - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvalTo.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvalTo.h deleted file mode 100644 index 4689b023..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvalTo.h +++ /dev/null @@ -1,236 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H -#define EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H - -namespace Eigen { - -/** \class TensorForcedEval - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor reshaping class. - * - * - */ -namespace internal { -template<typename XprType, template <class> class MakePointer_> -struct traits<TensorEvalToOp<XprType, MakePointer_> > -{ - // Type promotion to handle the case where the types of the lhs and the rhs are different. - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename MakePointer_<Scalar>::Type PointerType; - - enum { - Flags = 0 - }; - template <class T> - struct MakePointer { - // Intermediate typedef to workaround MSVC issue. - typedef MakePointer_<T> MakePointerT; - typedef typename MakePointerT::Type Type; - - - }; -}; - -template<typename XprType, template <class> class MakePointer_> -struct eval<TensorEvalToOp<XprType, MakePointer_>, Eigen::Dense> -{ - typedef const TensorEvalToOp<XprType, MakePointer_>& type; -}; - -template<typename XprType, template <class> class MakePointer_> -struct nested<TensorEvalToOp<XprType, MakePointer_>, 1, typename eval<TensorEvalToOp<XprType, MakePointer_> >::type> -{ - typedef TensorEvalToOp<XprType, MakePointer_> type; -}; - -} // end namespace internal - - - - -template<typename XprType, template <class> class MakePointer_> -class TensorEvalToOp : public TensorBase<TensorEvalToOp<XprType, MakePointer_>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorEvalToOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename MakePointer_<CoeffReturnType>::Type PointerType; - typedef typename Eigen::internal::nested<TensorEvalToOp>::type Nested; - typedef typename Eigen::internal::traits<TensorEvalToOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorEvalToOp>::Index Index; - - static const int NumDims = Eigen::internal::traits<TensorEvalToOp>::NumDimensions; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvalToOp(PointerType buffer, const XprType& expr) - : m_xpr(expr), m_buffer(buffer) {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC PointerType buffer() const { return m_buffer; } - - protected: - typename XprType::Nested m_xpr; - PointerType m_buffer; -}; - - - -template<typename ArgType, typename Device, template <class> class MakePointer_> -struct TensorEvaluator<const TensorEvalToOp<ArgType, MakePointer_>, Device> -{ - typedef TensorEvalToOp<ArgType, MakePointer_> XprType; - typedef typename ArgType::Scalar Scalar; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions; - typedef typename XprType::Index Index; - typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - enum { - IsAligned = TensorEvaluator<ArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = true, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = true - }; - - static const int NumDims = internal::traits<ArgType>::NumDimensions; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename TensorEvaluator<const ArgType, Device>::TensorBlock - ArgTensorBlock; - - typedef internal::TensorBlockAssignment< - CoeffReturnType, NumDims, typename ArgTensorBlock::XprType, Index> - TensorBlockAssignment; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_buffer(device.get(op.buffer())), m_expression(op.expression()){} - - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~TensorEvaluator() { - } - - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType scalar) { - EIGEN_UNUSED_VARIABLE(scalar); - eigen_assert(scalar == NULL); - return m_impl.evalSubExprsIfNeeded(m_buffer); - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType scalar, EvalSubExprsCallback done) { - EIGEN_UNUSED_VARIABLE(scalar); - eigen_assert(scalar == NULL); - m_impl.evalSubExprsIfNeededAsync(m_buffer, std::move(done)); - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i) { - m_buffer[i] = m_impl.coeff(i); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i) { - internal::pstoret<CoeffReturnType, PacketReturnType, Aligned>(m_buffer + i, m_impl.template packet<TensorEvaluator<ArgType, Device>::IsAligned ? Aligned : Unaligned>(i)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - return m_impl.getResourceRequirements(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock( - TensorBlockDesc& desc, TensorBlockScratch& scratch) { - // Add `m_buffer` as destination buffer to the block descriptor. - desc.template AddDestinationBuffer<Layout>( - /*dst_base=*/m_buffer + desc.offset(), - /*dst_strides=*/internal::strides<Layout>(m_impl.dimensions())); - - ArgTensorBlock block = - m_impl.block(desc, scratch, /*root_of_expr_ast=*/true); - - // If block was evaluated into a destination buffer, there is no need to do - // an assignment. - if (block.kind() != internal::TensorBlockKind::kMaterializedInOutput) { - TensorBlockAssignment::Run( - TensorBlockAssignment::target( - desc.dimensions(), internal::strides<Layout>(m_impl.dimensions()), - m_buffer, desc.offset()), - block.expr()); - } - block.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return m_buffer[index]; - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - // We assume that evalPacket or evalScalar is called to perform the - // assignment and account for the cost of the write here. - return m_impl.costPerCoeff(vectorized) + - TensorOpCost(0, sizeof(CoeffReturnType), 0, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_buffer; } - ArgType expression() const { return m_expression; } - #ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - m_buffer.bind(cgh); - } - #endif - - - private: - TensorEvaluator<ArgType, Device> m_impl; - EvaluatorPointerType m_buffer; - const ArgType m_expression; -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h deleted file mode 100644 index d4532b72..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h +++ /dev/null @@ -1,984 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_EVALUATOR_H -#define EIGEN_CXX11_TENSOR_TENSOR_EVALUATOR_H - -namespace Eigen { - -/** \class TensorEvaluator - * \ingroup CXX11_Tensor_Module - * - * \brief The tensor evaluator classes. - * - * These classes are responsible for the evaluation of the tensor expression. - * - * TODO: add support for more types of expressions, in particular expressions - * leading to lvalues (slicing, reshaping, etc...) - */ - -// Generic evaluator -template<typename Derived, typename Device> -struct TensorEvaluator -{ - typedef typename Derived::Index Index; - typedef typename Derived::Scalar Scalar; - typedef typename Derived::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef typename Derived::Dimensions Dimensions; - typedef Derived XprType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename internal::traits<Derived>::template MakePointer<Scalar>::Type TensorPointerType; - typedef StorageMemory<Scalar, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - // NumDimensions is -1 for variable dim tensors - static const int NumCoords = internal::traits<Derived>::NumDimensions > 0 ? - internal::traits<Derived>::NumDimensions : 0; - - enum { - IsAligned = Derived::IsAligned, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = internal::is_arithmetic<typename internal::remove_const<Scalar>::type>::value, - PreferBlockAccess = false, - Layout = Derived::Layout, - CoordAccess = NumCoords > 0, - RawAccess = true - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumCoords, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename internal::TensorMaterializedBlock<ScalarNoConst, NumCoords, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const Derived& m, const Device& device) - : m_data(device.get((const_cast<TensorPointerType>(m.data())))), - m_dims(m.dimensions()), - m_device(device) - { } - - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dims; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType dest) { - if (!NumTraits<typename internal::remove_const<Scalar>::type>::RequireInitialization && dest) { - m_device.memcpy((void*)(m_device.get(dest)), m_device.get(m_data), m_dims.TotalSize() * sizeof(Scalar)); - return false; - } - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType dest, EvalSubExprsCallback done) { - // TODO(ezhulenev): ThreadPoolDevice memcpy is blockign operation. - done(evalSubExprsIfNeeded(dest)); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - eigen_assert(m_data != NULL); - return m_data[index]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index) { - eigen_assert(m_data != NULL); - return m_data[index]; - } - - template<int LoadMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketReturnType packet(Index index) const - { - return internal::ploadt<PacketReturnType, LoadMode>(m_data + index); - } - - // Return a packet starting at `index` where `umask` specifies which elements - // have to be loaded. Type/size of mask depends on PacketReturnType, e.g. for - // Packet16f, `umask` is of type uint16_t and if a bit is 1, corresponding - // float element will be loaded, otherwise 0 will be loaded. - // Function has been templatized to enable Sfinae. - template <typename PacketReturnTypeT> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename internal::enable_if<internal::unpacket_traits<PacketReturnTypeT>::masked_load_available, PacketReturnTypeT>::type - partialPacket(Index index, typename internal::unpacket_traits<PacketReturnTypeT>::mask_t umask) const - { - return internal::ploadu<PacketReturnTypeT>(m_data + index, umask); - } - - template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) - { - return internal::pstoret<Scalar, PacketReturnType, StoreMode>(m_data + index, x); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(const array<DenseIndex, NumCoords>& coords) const { - eigen_assert(m_data != NULL); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - return m_data[m_dims.IndexOfColMajor(coords)]; - } else { - return m_data[m_dims.IndexOfRowMajor(coords)]; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& - coeffRef(const array<DenseIndex, NumCoords>& coords) { - eigen_assert(m_data != NULL); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - return m_data[m_dims.IndexOfColMajor(coords)]; - } else { - return m_data[m_dims.IndexOfRowMajor(coords)]; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, - PacketType<CoeffReturnType, Device>::size); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - return internal::TensorBlockResourceRequirements::any(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - assert(m_data != NULL); - return TensorBlock::materialize(m_data, m_dims, desc, scratch); - } - - template<typename TensorBlock> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writeBlock( - const TensorBlockDesc& desc, const TensorBlock& block) { - assert(m_data != NULL); - - typedef typename TensorBlock::XprType TensorBlockExpr; - typedef internal::TensorBlockAssignment<Scalar, NumCoords, TensorBlockExpr, - Index> - TensorBlockAssign; - - TensorBlockAssign::Run( - TensorBlockAssign::target(desc.dimensions(), - internal::strides<Layout>(m_dims), m_data, - desc.offset()), - block.expr()); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_data; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_data.bind(cgh); - } -#endif - protected: - EvaluatorPointerType m_data; - Dimensions m_dims; - const Device EIGEN_DEVICE_REF m_device; -}; - -namespace { -template <typename T> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T loadConstant(const T* address) { - return *address; -} -// Use the texture cache on CUDA devices whenever possible -#if defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350 -template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -float loadConstant(const float* address) { - return __ldg(address); -} -template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -double loadConstant(const double* address) { - return __ldg(address); -} -template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -Eigen::half loadConstant(const Eigen::half* address) { - return Eigen::half(half_impl::raw_uint16_to_half(__ldg(&address->x))); -} -#endif -#ifdef EIGEN_USE_SYCL -// overload of load constant should be implemented here based on range access -template <cl::sycl::access::mode AcMd, typename T> -T &loadConstant(const Eigen::TensorSycl::internal::RangeAccess<AcMd, T> &address) { - return *address; -} -#endif -} - - -// Default evaluator for rvalues -template<typename Derived, typename Device> -struct TensorEvaluator<const Derived, Device> -{ - typedef typename Derived::Index Index; - typedef typename Derived::Scalar Scalar; - typedef typename Derived::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef typename Derived::Dimensions Dimensions; - typedef const Derived XprType; - typedef typename internal::traits<Derived>::template MakePointer<const Scalar>::Type TensorPointerType; - typedef StorageMemory<const Scalar, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - // NumDimensions is -1 for variable dim tensors - static const int NumCoords = internal::traits<Derived>::NumDimensions > 0 ? - internal::traits<Derived>::NumDimensions : 0; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - - enum { - IsAligned = Derived::IsAligned, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = internal::is_arithmetic<ScalarNoConst>::value, - PreferBlockAccess = false, - Layout = Derived::Layout, - CoordAccess = NumCoords > 0, - RawAccess = true - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumCoords, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename internal::TensorMaterializedBlock<ScalarNoConst, NumCoords, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const Derived& m, const Device& device) - : m_data(device.get(m.data())), m_dims(m.dimensions()), m_device(device) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dims; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - if (!NumTraits<typename internal::remove_const<Scalar>::type>::RequireInitialization && data) { - m_device.memcpy((void*)(m_device.get(data)),m_device.get(m_data), m_dims.TotalSize() * sizeof(Scalar)); - return false; - } - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType dest, EvalSubExprsCallback done) { - // TODO(ezhulenev): ThreadPoolDevice memcpy is a blockign operation. - done(evalSubExprsIfNeeded(dest)); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - eigen_assert(m_data != NULL); - return loadConstant(m_data+index); - } - - template<int LoadMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketReturnType packet(Index index) const - { - return internal::ploadt_ro<PacketReturnType, LoadMode>(m_data + index); - } - - // Return a packet starting at `index` where `umask` specifies which elements - // have to be loaded. Type/size of mask depends on PacketReturnType, e.g. for - // Packet16f, `umask` is of type uint16_t and if a bit is 1, corresponding - // float element will be loaded, otherwise 0 will be loaded. - // Function has been templatized to enable Sfinae. - template <typename PacketReturnTypeT> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - typename internal::enable_if<internal::unpacket_traits<PacketReturnTypeT>::masked_load_available, PacketReturnTypeT>::type - partialPacket(Index index, typename internal::unpacket_traits<PacketReturnTypeT>::mask_t umask) const - { - return internal::ploadu<PacketReturnTypeT>(m_data + index, umask); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(const array<DenseIndex, NumCoords>& coords) const { - eigen_assert(m_data != NULL); - const Index index = (static_cast<int>(Layout) == static_cast<int>(ColMajor)) ? m_dims.IndexOfColMajor(coords) - : m_dims.IndexOfRowMajor(coords); - return loadConstant(m_data+index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, - PacketType<CoeffReturnType, Device>::size); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - return internal::TensorBlockResourceRequirements::any(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - assert(m_data != NULL); - return TensorBlock::materialize(m_data, m_dims, desc, scratch); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_data; } -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_data.bind(cgh); - } -#endif - protected: - EvaluatorPointerType m_data; - Dimensions m_dims; - const Device EIGEN_DEVICE_REF m_device; -}; - - - - -// -------------------- CwiseNullaryOp -------------------- - -template<typename NullaryOp, typename ArgType, typename Device> -struct TensorEvaluator<const TensorCwiseNullaryOp<NullaryOp, ArgType>, Device> -{ - typedef TensorCwiseNullaryOp<NullaryOp, ArgType> XprType; - - EIGEN_DEVICE_FUNC - TensorEvaluator(const XprType& op, const Device& device) - : m_functor(op.functor()), m_argImpl(op.nestedExpression(), device), m_wrapper() - { } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename internal::traits<XprType>::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = true, - PacketAccess = internal::functor_traits<NullaryOp>::PacketAccess - #ifdef EIGEN_USE_SYCL - && (PacketType<CoeffReturnType, Device>::size >1) - #endif - , - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_argImpl.dimensions(); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { return true; } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - done(true); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { } - - EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const - { - return m_wrapper(m_functor, index); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - return m_wrapper.template packetOp<PacketReturnType, Index>(m_functor, index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, - PacketType<CoeffReturnType, Device>::size); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_argImpl.bind(cgh); - } -#endif - - private: - const NullaryOp m_functor; - TensorEvaluator<ArgType, Device> m_argImpl; - const internal::nullary_wrapper<CoeffReturnType,NullaryOp> m_wrapper; -}; - - - -// -------------------- CwiseUnaryOp -------------------- - -template<typename UnaryOp, typename ArgType, typename Device> -struct TensorEvaluator<const TensorCwiseUnaryOp<UnaryOp, ArgType>, Device> -{ - typedef TensorCwiseUnaryOp<UnaryOp, ArgType> XprType; - - enum { - IsAligned = TensorEvaluator<ArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess & - internal::functor_traits<UnaryOp>::PacketAccess, - BlockAccess = TensorEvaluator<ArgType, Device>::BlockAccess, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) - : m_device(device), - m_functor(op.functor()), - m_argImpl(op.nestedExpression(), device) - { } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - typedef typename internal::traits<XprType>::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - static const int NumDims = internal::array_size<Dimensions>::value; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename TensorEvaluator<const ArgType, Device>::TensorBlock - ArgTensorBlock; - - typedef internal::TensorCwiseUnaryBlock<UnaryOp, ArgTensorBlock> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_argImpl.dimensions(); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_argImpl.evalSubExprsIfNeeded(NULL); - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - m_argImpl.evalSubExprsIfNeededAsync(nullptr, [done](bool) { done(true); }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_argImpl.cleanup(); - } - - EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const - { - return m_functor(m_argImpl.coeff(index)); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - return m_functor.packetOp(m_argImpl.template packet<LoadMode>(index)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - const double functor_cost = internal::functor_traits<UnaryOp>::Cost; - return m_argImpl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, functor_cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - static const double functor_cost = internal::functor_traits<UnaryOp>::Cost; - return m_argImpl.getResourceRequirements().addCostPerCoeff( - {0, 0, functor_cost / PacketSize}); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - return TensorBlock(m_argImpl.block(desc, scratch), m_functor); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const{ - m_argImpl.bind(cgh); - } -#endif - - - private: - const Device EIGEN_DEVICE_REF m_device; - const UnaryOp m_functor; - TensorEvaluator<ArgType, Device> m_argImpl; -}; - - -// -------------------- CwiseBinaryOp -------------------- - -template<typename BinaryOp, typename LeftArgType, typename RightArgType, typename Device> -struct TensorEvaluator<const TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device> -{ - typedef TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType> XprType; - - enum { - IsAligned = TensorEvaluator<LeftArgType, Device>::IsAligned & - TensorEvaluator<RightArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<LeftArgType, Device>::PacketAccess & - TensorEvaluator<RightArgType, Device>::PacketAccess & - internal::functor_traits<BinaryOp>::PacketAccess, - BlockAccess = TensorEvaluator<LeftArgType, Device>::BlockAccess & - TensorEvaluator<RightArgType, Device>::BlockAccess, - PreferBlockAccess = TensorEvaluator<LeftArgType, Device>::PreferBlockAccess | - TensorEvaluator<RightArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<LeftArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) - : m_device(device), - m_functor(op.functor()), - m_leftImpl(op.lhsExpression(), device), - m_rightImpl(op.rhsExpression(), device) - { - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<LeftArgType, Device>::Layout) == static_cast<int>(TensorEvaluator<RightArgType, Device>::Layout) || internal::traits<XprType>::NumDimensions <= 1), YOU_MADE_A_PROGRAMMING_MISTAKE); - eigen_assert(dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions())); - } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename internal::traits<XprType>::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename TensorEvaluator<LeftArgType, Device>::Dimensions Dimensions; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - static const int NumDims = internal::array_size< - typename TensorEvaluator<LeftArgType, Device>::Dimensions>::value; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename TensorEvaluator<const LeftArgType, Device>::TensorBlock - LeftTensorBlock; - typedef typename TensorEvaluator<const RightArgType, Device>::TensorBlock - RightTensorBlock; - - typedef internal::TensorCwiseBinaryBlock<BinaryOp, LeftTensorBlock, - RightTensorBlock> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const - { - // TODO: use right impl instead if right impl dimensions are known at compile time. - return m_leftImpl.dimensions(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_leftImpl.evalSubExprsIfNeeded(NULL); - m_rightImpl.evalSubExprsIfNeeded(NULL); - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - // TODO(ezhulenev): Evaluate two expression in parallel? - m_leftImpl.evalSubExprsIfNeededAsync(nullptr, [this, done](bool) { - m_rightImpl.evalSubExprsIfNeededAsync(nullptr, - [done](bool) { done(true); }); - }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_leftImpl.cleanup(); - m_rightImpl.cleanup(); - } - - EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const - { - return m_functor(m_leftImpl.coeff(index), m_rightImpl.coeff(index)); - } - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - return m_functor.packetOp(m_leftImpl.template packet<LoadMode>(index), m_rightImpl.template packet<LoadMode>(index)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - const double functor_cost = internal::functor_traits<BinaryOp>::Cost; - return m_leftImpl.costPerCoeff(vectorized) + - m_rightImpl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, functor_cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - static const double functor_cost = internal::functor_traits<BinaryOp>::Cost; - return internal::TensorBlockResourceRequirements::merge( - m_leftImpl.getResourceRequirements(), - m_rightImpl.getResourceRequirements()) - .addCostPerCoeff({0, 0, functor_cost / PacketSize}); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - desc.DropDestinationBuffer(); - return TensorBlock(m_leftImpl.block(desc, scratch), - m_rightImpl.block(desc, scratch), m_functor); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - - #ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_leftImpl.bind(cgh); - m_rightImpl.bind(cgh); - } - #endif - private: - const Device EIGEN_DEVICE_REF m_device; - const BinaryOp m_functor; - TensorEvaluator<LeftArgType, Device> m_leftImpl; - TensorEvaluator<RightArgType, Device> m_rightImpl; -}; - -// -------------------- CwiseTernaryOp -------------------- - -template<typename TernaryOp, typename Arg1Type, typename Arg2Type, typename Arg3Type, typename Device> -struct TensorEvaluator<const TensorCwiseTernaryOp<TernaryOp, Arg1Type, Arg2Type, Arg3Type>, Device> -{ - typedef TensorCwiseTernaryOp<TernaryOp, Arg1Type, Arg2Type, Arg3Type> XprType; - - enum { - IsAligned = TensorEvaluator<Arg1Type, Device>::IsAligned & TensorEvaluator<Arg2Type, Device>::IsAligned & TensorEvaluator<Arg3Type, Device>::IsAligned, - PacketAccess = TensorEvaluator<Arg1Type, Device>::PacketAccess && - TensorEvaluator<Arg2Type, Device>::PacketAccess && - TensorEvaluator<Arg3Type, Device>::PacketAccess && - internal::functor_traits<TernaryOp>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<Arg1Type, Device>::PreferBlockAccess || - TensorEvaluator<Arg2Type, Device>::PreferBlockAccess || - TensorEvaluator<Arg3Type, Device>::PreferBlockAccess, - Layout = TensorEvaluator<Arg1Type, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) - : m_functor(op.functor()), - m_arg1Impl(op.arg1Expression(), device), - m_arg2Impl(op.arg2Expression(), device), - m_arg3Impl(op.arg3Expression(), device) - { - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<Arg1Type, Device>::Layout) == static_cast<int>(TensorEvaluator<Arg3Type, Device>::Layout) || internal::traits<XprType>::NumDimensions <= 1), YOU_MADE_A_PROGRAMMING_MISTAKE); - - EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Arg1Type>::StorageKind, - typename internal::traits<Arg2Type>::StorageKind>::value), - STORAGE_KIND_MUST_MATCH) - EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Arg1Type>::StorageKind, - typename internal::traits<Arg3Type>::StorageKind>::value), - STORAGE_KIND_MUST_MATCH) - EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Arg1Type>::Index, - typename internal::traits<Arg2Type>::Index>::value), - STORAGE_INDEX_MUST_MATCH) - EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Arg1Type>::Index, - typename internal::traits<Arg3Type>::Index>::value), - STORAGE_INDEX_MUST_MATCH) - - eigen_assert(dimensions_match(m_arg1Impl.dimensions(), m_arg2Impl.dimensions()) && dimensions_match(m_arg1Impl.dimensions(), m_arg3Impl.dimensions())); - } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename internal::traits<XprType>::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename TensorEvaluator<Arg1Type, Device>::Dimensions Dimensions; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const - { - // TODO: use arg2 or arg3 dimensions if they are known at compile time. - return m_arg1Impl.dimensions(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_arg1Impl.evalSubExprsIfNeeded(NULL); - m_arg2Impl.evalSubExprsIfNeeded(NULL); - m_arg3Impl.evalSubExprsIfNeeded(NULL); - return true; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_arg1Impl.cleanup(); - m_arg2Impl.cleanup(); - m_arg3Impl.cleanup(); - } - - EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const - { - return m_functor(m_arg1Impl.coeff(index), m_arg2Impl.coeff(index), m_arg3Impl.coeff(index)); - } - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - return m_functor.packetOp(m_arg1Impl.template packet<LoadMode>(index), - m_arg2Impl.template packet<LoadMode>(index), - m_arg3Impl.template packet<LoadMode>(index)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - const double functor_cost = internal::functor_traits<TernaryOp>::Cost; - return m_arg1Impl.costPerCoeff(vectorized) + - m_arg2Impl.costPerCoeff(vectorized) + - m_arg3Impl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, functor_cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_arg1Impl.bind(cgh); - m_arg2Impl.bind(cgh); - m_arg3Impl.bind(cgh); - } -#endif - - private: - const TernaryOp m_functor; - TensorEvaluator<Arg1Type, Device> m_arg1Impl; - TensorEvaluator<Arg2Type, Device> m_arg2Impl; - TensorEvaluator<Arg3Type, Device> m_arg3Impl; -}; - - -// -------------------- SelectOp -------------------- - -template<typename IfArgType, typename ThenArgType, typename ElseArgType, typename Device> -struct TensorEvaluator<const TensorSelectOp<IfArgType, ThenArgType, ElseArgType>, Device> -{ - typedef TensorSelectOp<IfArgType, ThenArgType, ElseArgType> XprType; - typedef typename XprType::Scalar Scalar; - - enum { - IsAligned = TensorEvaluator<ThenArgType, Device>::IsAligned & - TensorEvaluator<ElseArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<ThenArgType, Device>::PacketAccess & - TensorEvaluator<ElseArgType, Device>::PacketAccess & - PacketType<Scalar, Device>::HasBlend, - BlockAccess = TensorEvaluator<IfArgType, Device>::BlockAccess && - TensorEvaluator<ThenArgType, Device>::BlockAccess && - TensorEvaluator<ElseArgType, Device>::BlockAccess, - PreferBlockAccess = TensorEvaluator<IfArgType, Device>::PreferBlockAccess || - TensorEvaluator<ThenArgType, Device>::PreferBlockAccess || - TensorEvaluator<ElseArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<IfArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) - : m_condImpl(op.ifExpression(), device), - m_thenImpl(op.thenExpression(), device), - m_elseImpl(op.elseExpression(), device) - { - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<IfArgType, Device>::Layout) == static_cast<int>(TensorEvaluator<ThenArgType, Device>::Layout)), YOU_MADE_A_PROGRAMMING_MISTAKE); - EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<IfArgType, Device>::Layout) == static_cast<int>(TensorEvaluator<ElseArgType, Device>::Layout)), YOU_MADE_A_PROGRAMMING_MISTAKE); - eigen_assert(dimensions_match(m_condImpl.dimensions(), m_thenImpl.dimensions())); - eigen_assert(dimensions_match(m_thenImpl.dimensions(), m_elseImpl.dimensions())); - } - - typedef typename XprType::Index Index; - typedef typename internal::traits<XprType>::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename TensorEvaluator<IfArgType, Device>::Dimensions Dimensions; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - static const int NumDims = internal::array_size<Dimensions>::value; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename TensorEvaluator<const IfArgType, Device>::TensorBlock - IfArgTensorBlock; - typedef typename TensorEvaluator<const ThenArgType, Device>::TensorBlock - ThenArgTensorBlock; - typedef typename TensorEvaluator<const ElseArgType, Device>::TensorBlock - ElseArgTensorBlock; - - struct TensorSelectOpBlockFactory { - template <typename IfArgXprType, typename ThenArgXprType, typename ElseArgXprType> - struct XprType { - typedef TensorSelectOp<const IfArgXprType, const ThenArgXprType, const ElseArgXprType> type; - }; - - template <typename IfArgXprType, typename ThenArgXprType, typename ElseArgXprType> - typename XprType<IfArgXprType, ThenArgXprType, ElseArgXprType>::type expr( - const IfArgXprType& if_expr, const ThenArgXprType& then_expr, const ElseArgXprType& else_expr) const { - return typename XprType<IfArgXprType, ThenArgXprType, ElseArgXprType>::type(if_expr, then_expr, else_expr); - } - }; - - typedef internal::TensorTernaryExprBlock<TensorSelectOpBlockFactory, - IfArgTensorBlock, ThenArgTensorBlock, - ElseArgTensorBlock> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const - { - // TODO: use then or else impl instead if they happen to be known at compile time. - return m_condImpl.dimensions(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_condImpl.evalSubExprsIfNeeded(NULL); - m_thenImpl.evalSubExprsIfNeeded(NULL); - m_elseImpl.evalSubExprsIfNeeded(NULL); - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - m_condImpl.evalSubExprsIfNeeded(nullptr, [this, done](bool) { - m_thenImpl.evalSubExprsIfNeeded(nullptr, [this, done](bool) { - m_elseImpl.evalSubExprsIfNeeded(nullptr, [done](bool) { done(true); }); - }); - }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_condImpl.cleanup(); - m_thenImpl.cleanup(); - m_elseImpl.cleanup(); - } - - EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const - { - return m_condImpl.coeff(index) ? m_thenImpl.coeff(index) : m_elseImpl.coeff(index); - } - template<int LoadMode> - EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const - { - internal::Selector<PacketSize> select; - EIGEN_UNROLL_LOOP - for (Index i = 0; i < PacketSize; ++i) { - select.select[i] = m_condImpl.coeff(index+i); - } - return internal::pblend(select, - m_thenImpl.template packet<LoadMode>(index), - m_elseImpl.template packet<LoadMode>(index)); - - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - return m_condImpl.costPerCoeff(vectorized) + - m_thenImpl.costPerCoeff(vectorized) - .cwiseMax(m_elseImpl.costPerCoeff(vectorized)); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - auto then_req = m_thenImpl.getResourceRequirements(); - auto else_req = m_elseImpl.getResourceRequirements(); - - auto merged_req = - internal::TensorBlockResourceRequirements::merge(then_req, else_req); - merged_req.cost_per_coeff = - then_req.cost_per_coeff.cwiseMax(else_req.cost_per_coeff); - - return internal::TensorBlockResourceRequirements::merge( - m_condImpl.getResourceRequirements(), merged_req); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - // It's unsafe to pass destination buffer to underlying expressions, because - // output might be aliased with one of the inputs. - desc.DropDestinationBuffer(); - - return TensorBlock( - m_condImpl.block(desc, scratch), m_thenImpl.block(desc, scratch), - m_elseImpl.block(desc, scratch), TensorSelectOpBlockFactory()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_condImpl.bind(cgh); - m_thenImpl.bind(cgh); - m_elseImpl.bind(cgh); - } -#endif - private: - TensorEvaluator<IfArgType, Device> m_condImpl; - TensorEvaluator<ThenArgType, Device> m_thenImpl; - TensorEvaluator<ElseArgType, Device> m_elseImpl; -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_EVALUATOR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h deleted file mode 100644 index 93bab11b..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h +++ /dev/null @@ -1,700 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_EXECUTOR_H -#define EIGEN_CXX11_TENSOR_TENSOR_EXECUTOR_H - -namespace Eigen { - -/** - * \class TensorExecutor - * \ingroup CXX11_Tensor_Module - * - * \brief The tensor executor class. - * - * This class is responsible for launch the evaluation of the expression on - * the specified computing device. - * - * @tparam Vectorizable can use packet math (SSE/AVX/etc... registers and - * instructions) - * @tparam Tiling can use block based tensor evaluation - * (see TensorBlock.h) - */ -namespace internal { - -/** - * Evaluating TensorBroadcastingOp via coefficient of packet path is extremely - * expensive. If expression has at least one broadcast op in it, and it supports - * block based evaluation, we always prefer it, even for the small tensors. For - * all other tileable ops, block evaluation overhead for small tensors (fits - * into L1) is too large, and we fallback on vectorized evaluation. - */ - -// TODO(ezhulenev): Add specializations for all other types of Tensor ops. - -template<typename Expression> -struct ExpressionHasTensorBroadcastingOp { - enum { value = false }; -}; - -template<typename LhsXprType, typename RhsXprType> -struct ExpressionHasTensorBroadcastingOp< - const TensorAssignOp<LhsXprType, RhsXprType> > { - enum { value = ExpressionHasTensorBroadcastingOp<RhsXprType>::value }; -}; - -template<typename UnaryOp, typename XprType> -struct ExpressionHasTensorBroadcastingOp< - const TensorCwiseUnaryOp<UnaryOp, XprType> > { - enum { value = ExpressionHasTensorBroadcastingOp<XprType>::value }; -}; - -template<typename BinaryOp, typename LhsXprType, typename RhsXprType> -struct ExpressionHasTensorBroadcastingOp< - const TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> > { - enum { - value = ExpressionHasTensorBroadcastingOp<LhsXprType>::value || - ExpressionHasTensorBroadcastingOp<RhsXprType>::value - }; -}; - -template<typename Broadcast, typename XprType> -struct ExpressionHasTensorBroadcastingOp< - const TensorBroadcastingOp<Broadcast, XprType> > { - enum { value = true }; -}; - -// -------------------------------------------------------------------------- // - -/** - * Default strategy: the expression is evaluated sequentially with a single cpu - * thread, without vectorization and block evaluation. - */ -template <typename Expression, typename Device, bool Vectorizable, - TiledEvaluation Tiling> -class TensorExecutor { - public: - typedef typename Expression::Index StorageIndex; - - // Including `unsupported/Eigen/CXX11/Tensor` in different translation units - // with/without `EIGEN_USE_THREADS` is an ODR violation. If this template - // is instantiated with a thread pool device, it means that this header - // file was included without defining `EIGEN_USE_THREADS`. - static_assert(!std::is_same<Device, ThreadPoolDevice>::value, - "You are missing `#define EIGEN_USE_THREADS`"); - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void run(const Expression& expr, - const Device& device = Device()) { - TensorEvaluator<Expression, Device> evaluator(expr, device); - const bool needs_assign = evaluator.evalSubExprsIfNeeded(NULL); - if (needs_assign) { - const StorageIndex size = array_prod(evaluator.dimensions()); - for (StorageIndex i = 0; i < size; ++i) { - evaluator.evalScalar(i); - } - } - evaluator.cleanup(); - } -}; - -/** - * Default async execution strategy is not implemented. Currently it's only - * available for ThreadPoolDevice (see definition below). - */ -template <typename Expression, typename Device, typename DoneCallback, - bool Vectorizable, TiledEvaluation Tiling> -class TensorAsyncExecutor {}; - -/** - * Process all the data with a single cpu thread, using vectorized instructions. - */ -template <typename Expression> -class TensorExecutor<Expression, DefaultDevice, /*Vectorizable=*/true, - /*Tiling=*/TiledEvaluation::Off> { - public: - typedef typename Expression::Index StorageIndex; - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void run( - const Expression& expr, const DefaultDevice& device = DefaultDevice()) { - TensorEvaluator<Expression, DefaultDevice> evaluator(expr, device); - const bool needs_assign = evaluator.evalSubExprsIfNeeded(NULL); - if (needs_assign) { - const StorageIndex size = array_prod(evaluator.dimensions()); - const int PacketSize = unpacket_traits<typename TensorEvaluator< - Expression, DefaultDevice>::PacketReturnType>::size; - - // Give compiler a strong possibility to unroll the loop. But don't insist - // on unrolling, because if the function is expensive compiler should not - // unroll the loop at the expense of inlining. - const StorageIndex UnrolledSize = - (size / (4 * PacketSize)) * 4 * PacketSize; - for (StorageIndex i = 0; i < UnrolledSize; i += 4 * PacketSize) { - for (StorageIndex j = 0; j < 4; j++) { - evaluator.evalPacket(i + j * PacketSize); - } - } - const StorageIndex VectorizedSize = (size / PacketSize) * PacketSize; - for (StorageIndex i = UnrolledSize; i < VectorizedSize; i += PacketSize) { - evaluator.evalPacket(i); - } - for (StorageIndex i = VectorizedSize; i < size; ++i) { - evaluator.evalScalar(i); - } - } - evaluator.cleanup(); - } -}; - -/** - * Process all the data with a single cpu thread, using blocks of data. By - * sizing a block to fit L1 cache we get better cache performance. - */ -template <typename Expression, bool Vectorizable> -class TensorExecutor<Expression, DefaultDevice, Vectorizable, - /*Tiling=*/TiledEvaluation::On> { - public: - typedef typename traits<Expression>::Scalar Scalar; - typedef typename remove_const<Scalar>::type ScalarNoConst; - - typedef TensorEvaluator<Expression, DefaultDevice> Evaluator; - typedef typename traits<Expression>::Index StorageIndex; - - static const int NumDims = traits<Expression>::NumDimensions; - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE void run(const Expression& expr, - const DefaultDevice& device = DefaultDevice()) { - typedef TensorBlockMapper<NumDims, Evaluator::Layout, StorageIndex> - TensorBlockMapper; - - typedef internal::TensorBlockDescriptor<NumDims, StorageIndex> - TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<DefaultDevice> - TensorBlockScratch; - - Evaluator evaluator(expr, device); - - // TODO(ezhulenev): Do not use tiling for small tensors? - const bool needs_assign = evaluator.evalSubExprsIfNeeded(NULL); - - if (needs_assign) { - // Query expression tree for desired block size/shape. - const TensorBlockResourceRequirements requirements = - evaluator.getResourceRequirements(); - - const TensorBlockMapper block_mapper( - typename TensorBlockDesc::Dimensions(evaluator.dimensions()), - requirements); - - // Share scratch memory allocator between all blocks. - TensorBlockScratch scratch(device); - - const StorageIndex total_block_count = block_mapper.blockCount(); - for (StorageIndex i = 0; i < total_block_count; ++i) { - TensorBlockDesc desc = block_mapper.blockDescriptor(i); - evaluator.evalBlock(desc, scratch); - scratch.reset(); - } - } - evaluator.cleanup(); - } -}; - -/** - * Multicore strategy: the index space is partitioned and each partition is - * executed on a single core. - * - * (1) TensorExecutor will submit work to the ThreadPoolDevice managed thread - * pool, and will block the caller thread until all tasks are finished. - * - * (2) TensorAsyncExecutor is a non-blocking version, that will submit work to - * the ThreadPoolDevice managed thread pool, and will return immediately. - * It will call 'done' callback after all tasks are finished. - */ -#ifdef EIGEN_USE_THREADS - -template <typename TensorBlockMapper> -struct TensorExecutorTilingContext { - TensorExecutorTilingContext() = default; - TensorExecutorTilingContext(const TensorBlockMapper& b_mapper, - const TensorOpCost& b_cost, size_t b_aligned_size) - : block_mapper(b_mapper), - cost(b_cost), - aligned_blocksize(b_aligned_size) {} - - TensorBlockMapper block_mapper; // navigate through blocks - TensorOpCost cost; // cost of computing a single block - size_t aligned_blocksize; // block size after memory alignment -}; - -// Computes a block evaluation parameters, and allocates temporary memory buffer -// for blocks. See TensorExecutor/TensorAsyncExecutor (Tiling=On) below. -template <typename Evaluator, typename TensorBlockMapper, bool Vectorizable> -TensorExecutorTilingContext<TensorBlockMapper> GetTensorExecutorTilingContext( - const Evaluator& evaluator) { - // Query expression tree for desired block size/shape. - TensorBlockResourceRequirements requirements = - evaluator.getResourceRequirements(); - - // Update target block size based on cost model. - double taskSize = TensorCostModel<ThreadPoolDevice>::taskSize( - 1, requirements.cost_per_coeff); - requirements.size = static_cast<size_t>(1.0 / taskSize); - - TensorBlockMapper block_mapper( - typename TensorBlockMapper::Dimensions(evaluator.dimensions()), - requirements); - - size_t block_size = block_mapper.blockTotalSize(); - const size_t align = numext::maxi(EIGEN_MAX_ALIGN_BYTES, 1); - const size_t aligned_blocksize = - align * - divup<size_t>(block_size * sizeof(typename Evaluator::Scalar), align); - - return {block_mapper, requirements.cost_per_coeff * block_size, - aligned_blocksize}; -} - -template <typename Evaluator, typename StorageIndex, bool Vectorizable> -struct EvalRange { - static void run(Evaluator* evaluator_in, const StorageIndex firstIdx, - const StorageIndex lastIdx) { - Evaluator evaluator = *evaluator_in; - eigen_assert(lastIdx >= firstIdx); - for (StorageIndex i = firstIdx; i < lastIdx; ++i) { - evaluator.evalScalar(i); - } - } - - static StorageIndex alignBlockSize(StorageIndex size) { return size; } -}; - -template <typename Evaluator, typename StorageIndex> -struct EvalRange<Evaluator, StorageIndex, /*Vectorizable*/ true> { - static const int PacketSize = - unpacket_traits<typename Evaluator::PacketReturnType>::size; - - static void run(Evaluator* evaluator_in, const StorageIndex firstIdx, - const StorageIndex lastIdx) { - Evaluator evaluator = *evaluator_in; - eigen_assert(lastIdx >= firstIdx); - StorageIndex i = firstIdx; - if (lastIdx - firstIdx >= PacketSize) { - eigen_assert(firstIdx % PacketSize == 0); - StorageIndex last_chunk_offset = lastIdx - 4 * PacketSize; - // Give compiler a strong possibility to unroll the loop. But don't insist - // on unrolling, because if the function is expensive compiler should not - // unroll the loop at the expense of inlining. - for (; i <= last_chunk_offset; i += 4 * PacketSize) { - for (StorageIndex j = 0; j < 4; j++) { - evaluator.evalPacket(i + j * PacketSize); - } - } - last_chunk_offset = lastIdx - PacketSize; - for (; i <= last_chunk_offset; i += PacketSize) { - evaluator.evalPacket(i); - } - } - for (; i < lastIdx; ++i) { - evaluator.evalScalar(i); - } - } - - static StorageIndex alignBlockSize(StorageIndex size) { - // Align block size to packet size and account for unrolling in run above. - if (size >= 16 * PacketSize) { - return (size + 4 * PacketSize - 1) & ~(4 * PacketSize - 1); - } - // Aligning to 4 * PacketSize would increase block size by more than 25%. - return (size + PacketSize - 1) & ~(PacketSize - 1); - } -}; - -template <typename Expression, bool Vectorizable, TiledEvaluation Tiling> -class TensorExecutor<Expression, ThreadPoolDevice, Vectorizable, Tiling> { - public: - typedef typename Expression::Index StorageIndex; - - static EIGEN_STRONG_INLINE void run(const Expression& expr, - const ThreadPoolDevice& device) { - typedef TensorEvaluator<Expression, ThreadPoolDevice> Evaluator; - typedef EvalRange<Evaluator, StorageIndex, Vectorizable> EvalRange; - - Evaluator evaluator(expr, device); - const bool needs_assign = evaluator.evalSubExprsIfNeeded(nullptr); - if (needs_assign) { - const StorageIndex size = array_prod(evaluator.dimensions()); - device.parallelFor(size, evaluator.costPerCoeff(Vectorizable), - EvalRange::alignBlockSize, - [&evaluator](StorageIndex firstIdx, StorageIndex lastIdx) { - EvalRange::run(&evaluator, firstIdx, lastIdx); - }); - } - evaluator.cleanup(); - } -}; - -template <typename Expression, bool Vectorizable> -class TensorExecutor<Expression, ThreadPoolDevice, Vectorizable, - /*Tiling=*/TiledEvaluation::On> { - public: - typedef typename traits<Expression>::Index IndexType; - typedef typename traits<Expression>::Scalar Scalar; - typedef typename remove_const<Scalar>::type ScalarNoConst; - - static const int NumDims = traits<Expression>::NumDimensions; - - typedef TensorEvaluator<Expression, ThreadPoolDevice> Evaluator; - typedef TensorBlockMapper<NumDims, Evaluator::Layout, IndexType> BlockMapper; - typedef TensorExecutorTilingContext<BlockMapper> TilingContext; - - typedef internal::TensorBlockDescriptor<NumDims, IndexType> - TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<ThreadPoolDevice> - TensorBlockScratch; - - static EIGEN_STRONG_INLINE void run(const Expression& expr, - const ThreadPoolDevice& device) { - Evaluator evaluator(expr, device); - - const bool needs_assign = evaluator.evalSubExprsIfNeeded(nullptr); - if (needs_assign) { - const TilingContext tiling = - internal::GetTensorExecutorTilingContext<Evaluator, BlockMapper, - Vectorizable>(evaluator); - - auto eval_block = [&device, &evaluator, &tiling](IndexType firstBlockIdx, - IndexType lastBlockIdx) { - TensorBlockScratch scratch(device); - - for (IndexType block_idx = firstBlockIdx; block_idx < lastBlockIdx; - ++block_idx) { - TensorBlockDesc desc = tiling.block_mapper.blockDescriptor(block_idx); - evaluator.evalBlock(desc, scratch); - scratch.reset(); - } - }; - - // Evaluate small expressions directly as a single block. - if (tiling.block_mapper.blockCount() == 1) { - TensorBlockScratch scratch(device); - TensorBlockDesc desc(0, tiling.block_mapper.blockDimensions()); - evaluator.evalBlock(desc, scratch); - } else { - device.parallelFor(tiling.block_mapper.blockCount(), tiling.cost, - eval_block); - } - } - evaluator.cleanup(); - } -}; - -template <typename Expression, typename DoneCallback, bool Vectorizable, - TiledEvaluation Tiling> -class TensorAsyncExecutor<Expression, ThreadPoolDevice, DoneCallback, - Vectorizable, Tiling> { - public: - typedef typename Expression::Index StorageIndex; - typedef TensorEvaluator<Expression, ThreadPoolDevice> Evaluator; - - static EIGEN_STRONG_INLINE void runAsync(const Expression& expr, - const ThreadPoolDevice& device, - DoneCallback done) { - TensorAsyncExecutorContext* const ctx = - new TensorAsyncExecutorContext(expr, device, std::move(done)); - - const auto on_eval_subexprs = [ctx, &device](bool need_assign) -> void { - if (!need_assign) { - delete ctx; - return; - } - - typedef EvalRange<Evaluator, StorageIndex, Vectorizable> EvalRange; - const StorageIndex size = array_prod(ctx->evaluator.dimensions()); - device.parallelForAsync( - size, ctx->evaluator.costPerCoeff(Vectorizable), - EvalRange::alignBlockSize, - [ctx](StorageIndex firstIdx, StorageIndex lastIdx) { - EvalRange::run(&ctx->evaluator, firstIdx, lastIdx); - }, - [ctx]() { delete ctx; }); - }; - - ctx->evaluator.evalSubExprsIfNeededAsync(nullptr, on_eval_subexprs); - } - - private: - struct TensorAsyncExecutorContext { - TensorAsyncExecutorContext(const Expression& expr, - const ThreadPoolDevice& thread_pool, - DoneCallback done) - : evaluator(expr, thread_pool), on_done(std::move(done)) {} - - ~TensorAsyncExecutorContext() { - evaluator.cleanup(); - on_done(); - } - - Evaluator evaluator; - - private: - DoneCallback on_done; - }; -}; - -template <typename Expression, typename DoneCallback, bool Vectorizable> -class TensorAsyncExecutor<Expression, ThreadPoolDevice, DoneCallback, - Vectorizable, /*Tileable*/ TiledEvaluation::On> { - public: - typedef typename traits<Expression>::Index IndexType; - typedef typename traits<Expression>::Scalar Scalar; - typedef typename remove_const<Scalar>::type ScalarNoConst; - - static const int NumDims = traits<Expression>::NumDimensions; - - typedef TensorEvaluator<Expression, ThreadPoolDevice> Evaluator; - typedef TensorBlockMapper<NumDims, Evaluator::Layout, IndexType> BlockMapper; - typedef TensorExecutorTilingContext<BlockMapper> TilingContext; - - typedef internal::TensorBlockDescriptor<NumDims, IndexType> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<ThreadPoolDevice> - TensorBlockScratch; - - static EIGEN_STRONG_INLINE void runAsync(const Expression& expr, - const ThreadPoolDevice& device, - DoneCallback done) { - - TensorAsyncExecutorContext* const ctx = - new TensorAsyncExecutorContext(expr, device, std::move(done)); - - const auto on_eval_subexprs = [ctx](bool need_assign) -> void { - if (!need_assign) { - delete ctx; - return; - } - - ctx->tiling = internal::GetTensorExecutorTilingContext< - Evaluator, BlockMapper, Vectorizable>(ctx->evaluator); - - auto eval_block = [ctx](IndexType firstBlockIdx, IndexType lastBlockIdx) { - TensorBlockScratch scratch(ctx->device); - - for (IndexType block_idx = firstBlockIdx; block_idx < lastBlockIdx; - ++block_idx) { - TensorBlockDesc desc = - ctx->tiling.block_mapper.blockDescriptor(block_idx); - ctx->evaluator.evalBlock(desc, scratch); - scratch.reset(); - } - }; - - // Evaluate small expressions directly as a single block. - if (ctx->tiling.block_mapper.blockCount() == 1) { - TensorBlockScratch scratch(ctx->device); - TensorBlockDesc desc(0, ctx->tiling.block_mapper.blockDimensions()); - ctx->evaluator.evalBlock(desc, scratch); - delete ctx; - } else { - ctx->device.parallelForAsync(ctx->tiling.block_mapper.blockCount(), - ctx->tiling.cost, eval_block, - [ctx]() { delete ctx; }); - } - }; - - ctx->evaluator.evalSubExprsIfNeededAsync(nullptr, on_eval_subexprs); - } - - private: - struct TensorAsyncExecutorContext { - TensorAsyncExecutorContext(const Expression& expr, - const ThreadPoolDevice& thread_pool, - DoneCallback done) - : device(thread_pool), - evaluator(expr, thread_pool), - on_done(std::move(done)) {} - - ~TensorAsyncExecutorContext() { - evaluator.cleanup(); - on_done(); - } - - const ThreadPoolDevice& device; - Evaluator evaluator; - TilingContext tiling; - - private: - DoneCallback on_done; - }; -}; - -#endif // EIGEN_USE_THREADS - -// GPU: the evaluation of the expression is offloaded to a GPU. -#if defined(EIGEN_USE_GPU) - -template <typename Expression, bool Vectorizable, TiledEvaluation Tiling> -class TensorExecutor<Expression, GpuDevice, Vectorizable, Tiling> { - public: - typedef typename Expression::Index StorageIndex; - static void run(const Expression& expr, const GpuDevice& device); -}; - -#if defined(EIGEN_GPUCC) -template <typename Evaluator, typename StorageIndex, bool Vectorizable> -struct EigenMetaKernelEval { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - void run(Evaluator& eval, StorageIndex firstIdx, StorageIndex lastIdx, StorageIndex step_size) { - for (StorageIndex i = firstIdx; i < lastIdx; i += step_size) { - eval.evalScalar(i); - } - } -}; - -template <typename Evaluator, typename StorageIndex> -struct EigenMetaKernelEval<Evaluator, StorageIndex, true> { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - void run(Evaluator& eval, StorageIndex firstIdx, StorageIndex lastIdx, StorageIndex step_size) { - const StorageIndex PacketSize = unpacket_traits<typename Evaluator::PacketReturnType>::size; - const StorageIndex vectorized_size = (lastIdx / PacketSize) * PacketSize; - const StorageIndex vectorized_step_size = step_size * PacketSize; - - // Use the vector path - for (StorageIndex i = firstIdx * PacketSize; i < vectorized_size; - i += vectorized_step_size) { - eval.evalPacket(i); - } - for (StorageIndex i = vectorized_size + firstIdx; i < lastIdx; i += step_size) { - eval.evalScalar(i); - } - } -}; - -template <typename Evaluator, typename StorageIndex> -__global__ void -__launch_bounds__(1024) -EigenMetaKernel(Evaluator eval, StorageIndex size) { - - const StorageIndex first_index = blockIdx.x * blockDim.x + threadIdx.x; - const StorageIndex step_size = blockDim.x * gridDim.x; - - const bool vectorizable = Evaluator::PacketAccess & Evaluator::IsAligned; - EigenMetaKernelEval<Evaluator, StorageIndex, vectorizable>::run(eval, first_index, size, step_size); -} - -/*static*/ -template <typename Expression, bool Vectorizable, TiledEvaluation Tiling> -EIGEN_STRONG_INLINE void TensorExecutor<Expression, GpuDevice, Vectorizable, Tiling>::run( - const Expression& expr, const GpuDevice& device) { - TensorEvaluator<Expression, GpuDevice> evaluator(expr, device); - const bool needs_assign = evaluator.evalSubExprsIfNeeded(nullptr); - if (needs_assign) { - - const int block_size = device.maxGpuThreadsPerBlock(); - const int max_blocks = device.getNumGpuMultiProcessors() * - device.maxGpuThreadsPerMultiProcessor() / block_size; - const StorageIndex size = array_prod(evaluator.dimensions()); - // Create a least one block to ensure we won't crash when tensorflow calls with tensors of size 0. - const int num_blocks = numext::maxi<int>(numext::mini<int>(max_blocks, divup<int>(size, block_size)), 1); - - LAUNCH_GPU_KERNEL( - (EigenMetaKernel<TensorEvaluator<Expression, GpuDevice>, StorageIndex>), - num_blocks, block_size, 0, device, evaluator, size); - } - evaluator.cleanup(); -} - -#endif // EIGEN_GPUCC -#endif // EIGEN_USE_GPU - -// SYCL Executor policy -#ifdef EIGEN_USE_SYCL - -template <typename Evaluator> -struct ExecExprFunctorKernel { - typedef typename Evaluator::Index Index; - Evaluator evaluator; - const Index range; - template <typename Scratch> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ExecExprFunctorKernel( - const Scratch, Evaluator evaluator_, const Index range_) - : evaluator(evaluator_), range(range_) {} - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void operator()( - cl::sycl::nd_item<1> itemID) { - compute(itemID); - } - template <bool is_vec = Evaluator::PacketAccess> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE typename std::enable_if<!is_vec>::type - compute(const cl::sycl::nd_item<1>& itemID) { - Index gId = static_cast<Index>(itemID.get_global_linear_id()); - Index total_threads = itemID.get_global_range(0); - - for (Index i = gId; i < range; i += total_threads) { - evaluator.evalScalar(i); - } - } - template <bool is_vec = Evaluator::PacketAccess> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE typename std::enable_if<is_vec>::type - compute(const cl::sycl::nd_item<1>& itemID) { - const Index vectorizedRange = - (range / Evaluator::PacketSize) * Evaluator::PacketSize; - Index gId = static_cast<Index>(itemID.get_global_linear_id()); - const Index step = Evaluator::PacketSize * itemID.get_global_range(0); - const Index start = Evaluator::PacketSize * gId; - for (Index i = start; i < vectorizedRange; i += step) { - evaluator.evalPacket(i); - } - gId += vectorizedRange; - for (Index i = gId; i < range; i += itemID.get_global_range(0)) { - evaluator.evalScalar(i); - } - } -}; - -template <typename Expression, bool Vectorizable, TiledEvaluation Tiling> -class TensorExecutor<Expression, Eigen::SyclDevice, Vectorizable, Tiling> { - public: - typedef typename Expression::Index Index; - static EIGEN_STRONG_INLINE void run(const Expression& expr, - const Eigen::SyclDevice& dev) { - typedef Eigen::TensorEvaluator<Expression, Eigen::SyclDevice> Evaluator; - Evaluator evaluator(expr, dev); - const bool needs_assign = evaluator.evalSubExprsIfNeeded(NULL); - if (needs_assign) { - Index range, GRange, tileSize; - Index total_size = ::Eigen::internal::array_prod(evaluator.dimensions()); - total_size = (total_size == 0) ? 1 : total_size; - const int PacketSize = - Eigen::PacketType<typename Evaluator::CoeffReturnType, - Eigen::SyclDevice>::size; - Index vectorizable_threads = static_cast<Index>(total_size / PacketSize); - dev.parallel_for_setup(vectorizable_threads, tileSize, range, GRange); - range = total_size; - - dev.template nullary_kernel_launcher< - typename Evaluator::CoeffReturnType, - ExecExprFunctorKernel<Evaluator> >( - evaluator, - cl::sycl::nd_range<1>(cl::sycl::range<1>(GRange), - cl::sycl::range<1>(tileSize)), - Index(1), range); - } - evaluator.cleanup(); - } -}; - -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_EXECUTOR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h deleted file mode 100644 index c9bccfc6..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h +++ /dev/null @@ -1,388 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_EXPR_H -#define EIGEN_CXX11_TENSOR_TENSOR_EXPR_H - -namespace Eigen { - -/** \class TensorExpr - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor expression classes. - * - * The TensorCwiseNullaryOp class applies a nullary operators to an expression. - * This is typically used to generate constants. - * - * The TensorCwiseUnaryOp class represents an expression where a unary operator - * (e.g. cwiseSqrt) is applied to an expression. - * - * The TensorCwiseBinaryOp class represents an expression where a binary - * operator (e.g. addition) is applied to a lhs and a rhs expression. - * - */ -namespace internal { -template<typename NullaryOp, typename XprType> -struct traits<TensorCwiseNullaryOp<NullaryOp, XprType> > - : traits<XprType> -{ - typedef traits<XprType> XprTraits; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::Nested XprTypeNested; - typedef typename remove_reference<XprTypeNested>::type _XprTypeNested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; - enum { - Flags = 0 - }; -}; - -} // end namespace internal - - - -template<typename NullaryOp, typename XprType> -class TensorCwiseNullaryOp : public TensorBase<TensorCwiseNullaryOp<NullaryOp, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorCwiseNullaryOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef TensorCwiseNullaryOp<NullaryOp, XprType> Nested; - typedef typename Eigen::internal::traits<TensorCwiseNullaryOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorCwiseNullaryOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseNullaryOp(const XprType& xpr, const NullaryOp& func = NullaryOp()) - : m_xpr(xpr), m_functor(func) {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - nestedExpression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - const NullaryOp& functor() const { return m_functor; } - - protected: - typename XprType::Nested m_xpr; - const NullaryOp m_functor; -}; - - - -namespace internal { -template<typename UnaryOp, typename XprType> -struct traits<TensorCwiseUnaryOp<UnaryOp, XprType> > - : traits<XprType> -{ - // TODO(phli): Add InputScalar, InputPacket. Check references to - // current Scalar/Packet to see if the intent is Input or Output. - typedef typename result_of<UnaryOp(typename XprType::Scalar)>::type Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprType::Nested XprTypeNested; - typedef typename remove_reference<XprTypeNested>::type _XprTypeNested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename TypeConversion<Scalar, - typename XprTraits::PointerType - >::type - PointerType; -}; - -template<typename UnaryOp, typename XprType> -struct eval<TensorCwiseUnaryOp<UnaryOp, XprType>, Eigen::Dense> -{ - typedef const TensorCwiseUnaryOp<UnaryOp, XprType>& type; -}; - -template<typename UnaryOp, typename XprType> -struct nested<TensorCwiseUnaryOp<UnaryOp, XprType>, 1, typename eval<TensorCwiseUnaryOp<UnaryOp, XprType> >::type> -{ - typedef TensorCwiseUnaryOp<UnaryOp, XprType> type; -}; - -} // end namespace internal - - - -template<typename UnaryOp, typename XprType> -class TensorCwiseUnaryOp : public TensorBase<TensorCwiseUnaryOp<UnaryOp, XprType>, ReadOnlyAccessors> -{ - public: - // TODO(phli): Add InputScalar, InputPacket. Check references to - // current Scalar/Packet to see if the intent is Input or Output. - typedef typename Eigen::internal::traits<TensorCwiseUnaryOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef Scalar CoeffReturnType; - typedef typename Eigen::internal::nested<TensorCwiseUnaryOp>::type Nested; - typedef typename Eigen::internal::traits<TensorCwiseUnaryOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorCwiseUnaryOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) - : m_xpr(xpr), m_functor(func) {} - - EIGEN_DEVICE_FUNC - const UnaryOp& functor() const { return m_functor; } - - /** \returns the nested expression */ - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - nestedExpression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const UnaryOp m_functor; -}; - - -namespace internal { -template<typename BinaryOp, typename LhsXprType, typename RhsXprType> -struct traits<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> > -{ - // Type promotion to handle the case where the types of the lhs and the rhs - // are different. - // TODO(phli): Add Lhs/RhsScalar, Lhs/RhsPacket. Check references to - // current Scalar/Packet to see if the intent is Inputs or Output. - typedef typename result_of< - BinaryOp(typename LhsXprType::Scalar, - typename RhsXprType::Scalar)>::type Scalar; - typedef traits<LhsXprType> XprTraits; - typedef typename promote_storage_type< - typename traits<LhsXprType>::StorageKind, - typename traits<RhsXprType>::StorageKind>::ret StorageKind; - typedef typename promote_index_type< - typename traits<LhsXprType>::Index, - typename traits<RhsXprType>::Index>::type Index; - typedef typename LhsXprType::Nested LhsNested; - typedef typename RhsXprType::Nested RhsNested; - typedef typename remove_reference<LhsNested>::type _LhsNested; - typedef typename remove_reference<RhsNested>::type _RhsNested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename TypeConversion<Scalar, - typename conditional<Pointer_type_promotion<typename LhsXprType::Scalar, Scalar>::val, - typename traits<LhsXprType>::PointerType, - typename traits<RhsXprType>::PointerType>::type - >::type - PointerType; - enum { - Flags = 0 - }; -}; - -template<typename BinaryOp, typename LhsXprType, typename RhsXprType> -struct eval<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, Eigen::Dense> -{ - typedef const TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>& type; -}; - -template<typename BinaryOp, typename LhsXprType, typename RhsXprType> -struct nested<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, 1, typename eval<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> >::type> -{ - typedef TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> type; -}; - -} // end namespace internal - - - -template<typename BinaryOp, typename LhsXprType, typename RhsXprType> -class TensorCwiseBinaryOp : public TensorBase<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, ReadOnlyAccessors> -{ - public: - // TODO(phli): Add Lhs/RhsScalar, Lhs/RhsPacket. Check references to - // current Scalar/Packet to see if the intent is Inputs or Output. - typedef typename Eigen::internal::traits<TensorCwiseBinaryOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef Scalar CoeffReturnType; - typedef typename Eigen::internal::nested<TensorCwiseBinaryOp>::type Nested; - typedef typename Eigen::internal::traits<TensorCwiseBinaryOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorCwiseBinaryOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseBinaryOp(const LhsXprType& lhs, const RhsXprType& rhs, const BinaryOp& func = BinaryOp()) - : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_functor(func) {} - - EIGEN_DEVICE_FUNC - const BinaryOp& functor() const { return m_functor; } - - /** \returns the nested expressions */ - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename LhsXprType::Nested>::type& - lhsExpression() const { return m_lhs_xpr; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename RhsXprType::Nested>::type& - rhsExpression() const { return m_rhs_xpr; } - - protected: - typename LhsXprType::Nested m_lhs_xpr; - typename RhsXprType::Nested m_rhs_xpr; - const BinaryOp m_functor; -}; - - -namespace internal { -template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType> -struct traits<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType> > -{ - // Type promotion to handle the case where the types of the args are different. - typedef typename result_of< - TernaryOp(typename Arg1XprType::Scalar, - typename Arg2XprType::Scalar, - typename Arg3XprType::Scalar)>::type Scalar; - typedef traits<Arg1XprType> XprTraits; - typedef typename traits<Arg1XprType>::StorageKind StorageKind; - typedef typename traits<Arg1XprType>::Index Index; - typedef typename Arg1XprType::Nested Arg1Nested; - typedef typename Arg2XprType::Nested Arg2Nested; - typedef typename Arg3XprType::Nested Arg3Nested; - typedef typename remove_reference<Arg1Nested>::type _Arg1Nested; - typedef typename remove_reference<Arg2Nested>::type _Arg2Nested; - typedef typename remove_reference<Arg3Nested>::type _Arg3Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename TypeConversion<Scalar, - typename conditional<Pointer_type_promotion<typename Arg2XprType::Scalar, Scalar>::val, - typename traits<Arg2XprType>::PointerType, - typename traits<Arg3XprType>::PointerType>::type - >::type - PointerType; - enum { - Flags = 0 - }; -}; - -template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType> -struct eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, Eigen::Dense> -{ - typedef const TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>& type; -}; - -template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType> -struct nested<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, 1, typename eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType> >::type> -{ - typedef TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType> type; -}; - -} // end namespace internal - - - -template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType> -class TensorCwiseTernaryOp : public TensorBase<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorCwiseTernaryOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef Scalar CoeffReturnType; - typedef typename Eigen::internal::nested<TensorCwiseTernaryOp>::type Nested; - typedef typename Eigen::internal::traits<TensorCwiseTernaryOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorCwiseTernaryOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseTernaryOp(const Arg1XprType& arg1, const Arg2XprType& arg2, const Arg3XprType& arg3, const TernaryOp& func = TernaryOp()) - : m_arg1_xpr(arg1), m_arg2_xpr(arg2), m_arg3_xpr(arg3), m_functor(func) {} - - EIGEN_DEVICE_FUNC - const TernaryOp& functor() const { return m_functor; } - - /** \returns the nested expressions */ - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename Arg1XprType::Nested>::type& - arg1Expression() const { return m_arg1_xpr; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename Arg2XprType::Nested>::type& - arg2Expression() const { return m_arg2_xpr; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename Arg3XprType::Nested>::type& - arg3Expression() const { return m_arg3_xpr; } - - protected: - typename Arg1XprType::Nested m_arg1_xpr; - typename Arg2XprType::Nested m_arg2_xpr; - typename Arg3XprType::Nested m_arg3_xpr; - const TernaryOp m_functor; -}; - - -namespace internal { -template<typename IfXprType, typename ThenXprType, typename ElseXprType> -struct traits<TensorSelectOp<IfXprType, ThenXprType, ElseXprType> > - : traits<ThenXprType> -{ - typedef typename traits<ThenXprType>::Scalar Scalar; - typedef traits<ThenXprType> XprTraits; - typedef typename promote_storage_type<typename traits<ThenXprType>::StorageKind, - typename traits<ElseXprType>::StorageKind>::ret StorageKind; - typedef typename promote_index_type<typename traits<ElseXprType>::Index, - typename traits<ThenXprType>::Index>::type Index; - typedef typename IfXprType::Nested IfNested; - typedef typename ThenXprType::Nested ThenNested; - typedef typename ElseXprType::Nested ElseNested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename conditional<Pointer_type_promotion<typename ThenXprType::Scalar, Scalar>::val, - typename traits<ThenXprType>::PointerType, - typename traits<ElseXprType>::PointerType>::type PointerType; -}; - -template<typename IfXprType, typename ThenXprType, typename ElseXprType> -struct eval<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, Eigen::Dense> -{ - typedef const TensorSelectOp<IfXprType, ThenXprType, ElseXprType>& type; -}; - -template<typename IfXprType, typename ThenXprType, typename ElseXprType> -struct nested<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, 1, typename eval<TensorSelectOp<IfXprType, ThenXprType, ElseXprType> >::type> -{ - typedef TensorSelectOp<IfXprType, ThenXprType, ElseXprType> type; -}; - -} // end namespace internal - - -template<typename IfXprType, typename ThenXprType, typename ElseXprType> -class TensorSelectOp : public TensorBase<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorSelectOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename internal::promote_storage_type<typename ThenXprType::CoeffReturnType, - typename ElseXprType::CoeffReturnType>::ret CoeffReturnType; - typedef typename Eigen::internal::nested<TensorSelectOp>::type Nested; - typedef typename Eigen::internal::traits<TensorSelectOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorSelectOp>::Index Index; - - EIGEN_DEVICE_FUNC - TensorSelectOp(const IfXprType& a_condition, - const ThenXprType& a_then, - const ElseXprType& a_else) - : m_condition(a_condition), m_then(a_then), m_else(a_else) - { } - - EIGEN_DEVICE_FUNC - const IfXprType& ifExpression() const { return m_condition; } - - EIGEN_DEVICE_FUNC - const ThenXprType& thenExpression() const { return m_then; } - - EIGEN_DEVICE_FUNC - const ElseXprType& elseExpression() const { return m_else; } - - protected: - typename IfXprType::Nested m_condition; - typename ThenXprType::Nested m_then; - typename ElseXprType::Nested m_else; -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_EXPR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFFT.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFFT.h deleted file mode 100644 index c62bc5fa..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFFT.h +++ /dev/null @@ -1,669 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Jianwei Cui <thucjw@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_FFT_H -#define EIGEN_CXX11_TENSOR_TENSOR_FFT_H - -namespace Eigen { - -/** \class TensorFFT - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor FFT class. - * - * TODO: - * Vectorize the Cooley Tukey and the Bluestein algorithm - * Add support for multithreaded evaluation - * Improve the performance on GPU - */ - -template <bool NeedUprade> struct MakeComplex { - template <typename T> - EIGEN_DEVICE_FUNC - T operator() (const T& val) const { return val; } -}; - -template <> struct MakeComplex<true> { - template <typename T> - EIGEN_DEVICE_FUNC - std::complex<T> operator() (const T& val) const { return std::complex<T>(val, 0); } -}; - -template <> struct MakeComplex<false> { - template <typename T> - EIGEN_DEVICE_FUNC - std::complex<T> operator() (const std::complex<T>& val) const { return val; } -}; - -template <int ResultType> struct PartOf { - template <typename T> T operator() (const T& val) const { return val; } -}; - -template <> struct PartOf<RealPart> { - template <typename T> T operator() (const std::complex<T>& val) const { return val.real(); } -}; - -template <> struct PartOf<ImagPart> { - template <typename T> T operator() (const std::complex<T>& val) const { return val.imag(); } -}; - -namespace internal { -template <typename FFT, typename XprType, int FFTResultType, int FFTDir> -struct traits<TensorFFTOp<FFT, XprType, FFTResultType, FFTDir> > : public traits<XprType> { - typedef traits<XprType> XprTraits; - typedef typename NumTraits<typename XprTraits::Scalar>::Real RealScalar; - typedef typename std::complex<RealScalar> ComplexScalar; - typedef typename XprTraits::Scalar InputScalar; - typedef typename conditional<FFTResultType == RealPart || FFTResultType == ImagPart, RealScalar, ComplexScalar>::type OutputScalar; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename traits<XprType>::PointerType PointerType; -}; - -template <typename FFT, typename XprType, int FFTResultType, int FFTDirection> -struct eval<TensorFFTOp<FFT, XprType, FFTResultType, FFTDirection>, Eigen::Dense> { - typedef const TensorFFTOp<FFT, XprType, FFTResultType, FFTDirection>& type; -}; - -template <typename FFT, typename XprType, int FFTResultType, int FFTDirection> -struct nested<TensorFFTOp<FFT, XprType, FFTResultType, FFTDirection>, 1, typename eval<TensorFFTOp<FFT, XprType, FFTResultType, FFTDirection> >::type> { - typedef TensorFFTOp<FFT, XprType, FFTResultType, FFTDirection> type; -}; - -} // end namespace internal - -template <typename FFT, typename XprType, int FFTResultType, int FFTDir> -class TensorFFTOp : public TensorBase<TensorFFTOp<FFT, XprType, FFTResultType, FFTDir>, ReadOnlyAccessors> { - public: - typedef typename Eigen::internal::traits<TensorFFTOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename std::complex<RealScalar> ComplexScalar; - typedef typename internal::conditional<FFTResultType == RealPart || FFTResultType == ImagPart, RealScalar, ComplexScalar>::type OutputScalar; - typedef OutputScalar CoeffReturnType; - typedef typename Eigen::internal::nested<TensorFFTOp>::type Nested; - typedef typename Eigen::internal::traits<TensorFFTOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorFFTOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFFTOp(const XprType& expr, const FFT& fft) - : m_xpr(expr), m_fft(fft) {} - - EIGEN_DEVICE_FUNC - const FFT& fft() const { return m_fft; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& expression() const { - return m_xpr; - } - - protected: - typename XprType::Nested m_xpr; - const FFT m_fft; -}; - -// Eval as rvalue -template <typename FFT, typename ArgType, typename Device, int FFTResultType, int FFTDir> -struct TensorEvaluator<const TensorFFTOp<FFT, ArgType, FFTResultType, FFTDir>, Device> { - typedef TensorFFTOp<FFT, ArgType, FFTResultType, FFTDir> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename std::complex<RealScalar> ComplexScalar; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions InputDimensions; - typedef internal::traits<XprType> XprTraits; - typedef typename XprTraits::Scalar InputScalar; - typedef typename internal::conditional<FFTResultType == RealPart || FFTResultType == ImagPart, RealScalar, ComplexScalar>::type OutputScalar; - typedef OutputScalar CoeffReturnType; - typedef typename PacketType<OutputScalar, Device>::type PacketReturnType; - static const int PacketSize = internal::unpacket_traits<PacketReturnType>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = true, - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) : m_fft(op.fft()), m_impl(op.expression(), device), m_data(NULL), m_device(device) { - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - for (int i = 0; i < NumDims; ++i) { - eigen_assert(input_dims[i] > 0); - m_dimensions[i] = input_dims[i]; - } - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_strides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_strides[i] = m_strides[i - 1] * m_dimensions[i - 1]; - } - } else { - m_strides[NumDims - 1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_strides[i] = m_strides[i + 1] * m_dimensions[i + 1]; - } - } - m_size = m_dimensions.TotalSize(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { - return m_dimensions; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - m_impl.evalSubExprsIfNeeded(NULL); - if (data) { - evalToBuf(data); - return false; - } else { - m_data = (EvaluatorPointerType)m_device.get((CoeffReturnType*)(m_device.allocate_temp(sizeof(CoeffReturnType) * m_size))); - evalToBuf(m_data); - return true; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - if (m_data) { - m_device.deallocate(m_data); - m_data = NULL; - } - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE CoeffReturnType coeff(Index index) const { - return m_data[index]; - } - - template <int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketReturnType - packet(Index index) const { - return internal::ploadt<PacketReturnType, LoadMode>(m_data + index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_data; } -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_data.bind(cgh); - } -#endif - - private: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalToBuf(EvaluatorPointerType data) { - const bool write_to_out = internal::is_same<OutputScalar, ComplexScalar>::value; - ComplexScalar* buf = write_to_out ? (ComplexScalar*)data : (ComplexScalar*)m_device.allocate(sizeof(ComplexScalar) * m_size); - - for (Index i = 0; i < m_size; ++i) { - buf[i] = MakeComplex<internal::is_same<InputScalar, RealScalar>::value>()(m_impl.coeff(i)); - } - - for (size_t i = 0; i < m_fft.size(); ++i) { - Index dim = m_fft[i]; - eigen_assert(dim >= 0 && dim < NumDims); - Index line_len = m_dimensions[dim]; - eigen_assert(line_len >= 1); - ComplexScalar* line_buf = (ComplexScalar*)m_device.allocate(sizeof(ComplexScalar) * line_len); - const bool is_power_of_two = isPowerOfTwo(line_len); - const Index good_composite = is_power_of_two ? 0 : findGoodComposite(line_len); - const Index log_len = is_power_of_two ? getLog2(line_len) : getLog2(good_composite); - - ComplexScalar* a = is_power_of_two ? NULL : (ComplexScalar*)m_device.allocate(sizeof(ComplexScalar) * good_composite); - ComplexScalar* b = is_power_of_two ? NULL : (ComplexScalar*)m_device.allocate(sizeof(ComplexScalar) * good_composite); - ComplexScalar* pos_j_base_powered = is_power_of_two ? NULL : (ComplexScalar*)m_device.allocate(sizeof(ComplexScalar) * (line_len + 1)); - if (!is_power_of_two) { - // Compute twiddle factors - // t_n = exp(sqrt(-1) * pi * n^2 / line_len) - // for n = 0, 1,..., line_len-1. - // For n > 2 we use the recurrence t_n = t_{n-1}^2 / t_{n-2} * t_1^2 - - // The recurrence is correct in exact arithmetic, but causes - // numerical issues for large transforms, especially in - // single-precision floating point. - // - // pos_j_base_powered[0] = ComplexScalar(1, 0); - // if (line_len > 1) { - // const ComplexScalar pos_j_base = ComplexScalar( - // numext::cos(M_PI / line_len), numext::sin(M_PI / line_len)); - // pos_j_base_powered[1] = pos_j_base; - // if (line_len > 2) { - // const ComplexScalar pos_j_base_sq = pos_j_base * pos_j_base; - // for (int i = 2; i < line_len + 1; ++i) { - // pos_j_base_powered[i] = pos_j_base_powered[i - 1] * - // pos_j_base_powered[i - 1] / - // pos_j_base_powered[i - 2] * - // pos_j_base_sq; - // } - // } - // } - // TODO(rmlarsen): Find a way to use Eigen's vectorized sin - // and cosine functions here. - for (int j = 0; j < line_len + 1; ++j) { - double arg = ((EIGEN_PI * j) * j) / line_len; - std::complex<double> tmp(numext::cos(arg), numext::sin(arg)); - pos_j_base_powered[j] = static_cast<ComplexScalar>(tmp); - } - } - - for (Index partial_index = 0; partial_index < m_size / line_len; ++partial_index) { - const Index base_offset = getBaseOffsetFromIndex(partial_index, dim); - - // get data into line_buf - const Index stride = m_strides[dim]; - if (stride == 1) { - m_device.memcpy(line_buf, &buf[base_offset], line_len*sizeof(ComplexScalar)); - } else { - Index offset = base_offset; - for (int j = 0; j < line_len; ++j, offset += stride) { - line_buf[j] = buf[offset]; - } - } - - // process the line - if (is_power_of_two) { - processDataLineCooleyTukey(line_buf, line_len, log_len); - } - else { - processDataLineBluestein(line_buf, line_len, good_composite, log_len, a, b, pos_j_base_powered); - } - - // write back - if (FFTDir == FFT_FORWARD && stride == 1) { - m_device.memcpy(&buf[base_offset], line_buf, line_len*sizeof(ComplexScalar)); - } else { - Index offset = base_offset; - const ComplexScalar div_factor = ComplexScalar(1.0 / line_len, 0); - for (int j = 0; j < line_len; ++j, offset += stride) { - buf[offset] = (FFTDir == FFT_FORWARD) ? line_buf[j] : line_buf[j] * div_factor; - } - } - } - m_device.deallocate(line_buf); - if (!is_power_of_two) { - m_device.deallocate(a); - m_device.deallocate(b); - m_device.deallocate(pos_j_base_powered); - } - } - - if(!write_to_out) { - for (Index i = 0; i < m_size; ++i) { - data[i] = PartOf<FFTResultType>()(buf[i]); - } - m_device.deallocate(buf); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static bool isPowerOfTwo(Index x) { - eigen_assert(x > 0); - return !(x & (x - 1)); - } - - // The composite number for padding, used in Bluestein's FFT algorithm - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Index findGoodComposite(Index n) { - Index i = 2; - while (i < 2 * n - 1) i *= 2; - return i; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Index getLog2(Index m) { - Index log2m = 0; - while (m >>= 1) log2m++; - return log2m; - } - - // Call Cooley Tukey algorithm directly, data length must be power of 2 - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void processDataLineCooleyTukey(ComplexScalar* line_buf, Index line_len, Index log_len) { - eigen_assert(isPowerOfTwo(line_len)); - scramble_FFT(line_buf, line_len); - compute_1D_Butterfly<FFTDir>(line_buf, line_len, log_len); - } - - // Call Bluestein's FFT algorithm, m is a good composite number greater than (2 * n - 1), used as the padding length - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void processDataLineBluestein(ComplexScalar* line_buf, Index line_len, Index good_composite, Index log_len, ComplexScalar* a, ComplexScalar* b, const ComplexScalar* pos_j_base_powered) { - Index n = line_len; - Index m = good_composite; - ComplexScalar* data = line_buf; - - for (Index i = 0; i < n; ++i) { - if(FFTDir == FFT_FORWARD) { - a[i] = data[i] * numext::conj(pos_j_base_powered[i]); - } - else { - a[i] = data[i] * pos_j_base_powered[i]; - } - } - for (Index i = n; i < m; ++i) { - a[i] = ComplexScalar(0, 0); - } - - for (Index i = 0; i < n; ++i) { - if(FFTDir == FFT_FORWARD) { - b[i] = pos_j_base_powered[i]; - } - else { - b[i] = numext::conj(pos_j_base_powered[i]); - } - } - for (Index i = n; i < m - n; ++i) { - b[i] = ComplexScalar(0, 0); - } - for (Index i = m - n; i < m; ++i) { - if(FFTDir == FFT_FORWARD) { - b[i] = pos_j_base_powered[m-i]; - } - else { - b[i] = numext::conj(pos_j_base_powered[m-i]); - } - } - - scramble_FFT(a, m); - compute_1D_Butterfly<FFT_FORWARD>(a, m, log_len); - - scramble_FFT(b, m); - compute_1D_Butterfly<FFT_FORWARD>(b, m, log_len); - - for (Index i = 0; i < m; ++i) { - a[i] *= b[i]; - } - - scramble_FFT(a, m); - compute_1D_Butterfly<FFT_REVERSE>(a, m, log_len); - - //Do the scaling after ifft - for (Index i = 0; i < m; ++i) { - a[i] /= m; - } - - for (Index i = 0; i < n; ++i) { - if(FFTDir == FFT_FORWARD) { - data[i] = a[i] * numext::conj(pos_j_base_powered[i]); - } - else { - data[i] = a[i] * pos_j_base_powered[i]; - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void scramble_FFT(ComplexScalar* data, Index n) { - eigen_assert(isPowerOfTwo(n)); - Index j = 1; - for (Index i = 1; i < n; ++i){ - if (j > i) { - std::swap(data[j-1], data[i-1]); - } - Index m = n >> 1; - while (m >= 2 && j > m) { - j -= m; - m >>= 1; - } - j += m; - } - } - - template <int Dir> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void butterfly_2(ComplexScalar* data) { - ComplexScalar tmp = data[1]; - data[1] = data[0] - data[1]; - data[0] += tmp; - } - - template <int Dir> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void butterfly_4(ComplexScalar* data) { - ComplexScalar tmp[4]; - tmp[0] = data[0] + data[1]; - tmp[1] = data[0] - data[1]; - tmp[2] = data[2] + data[3]; - if (Dir == FFT_FORWARD) { - tmp[3] = ComplexScalar(0.0, -1.0) * (data[2] - data[3]); - } else { - tmp[3] = ComplexScalar(0.0, 1.0) * (data[2] - data[3]); - } - data[0] = tmp[0] + tmp[2]; - data[1] = tmp[1] + tmp[3]; - data[2] = tmp[0] - tmp[2]; - data[3] = tmp[1] - tmp[3]; - } - - template <int Dir> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void butterfly_8(ComplexScalar* data) { - ComplexScalar tmp_1[8]; - ComplexScalar tmp_2[8]; - - tmp_1[0] = data[0] + data[1]; - tmp_1[1] = data[0] - data[1]; - tmp_1[2] = data[2] + data[3]; - if (Dir == FFT_FORWARD) { - tmp_1[3] = (data[2] - data[3]) * ComplexScalar(0, -1); - } else { - tmp_1[3] = (data[2] - data[3]) * ComplexScalar(0, 1); - } - tmp_1[4] = data[4] + data[5]; - tmp_1[5] = data[4] - data[5]; - tmp_1[6] = data[6] + data[7]; - if (Dir == FFT_FORWARD) { - tmp_1[7] = (data[6] - data[7]) * ComplexScalar(0, -1); - } else { - tmp_1[7] = (data[6] - data[7]) * ComplexScalar(0, 1); - } - tmp_2[0] = tmp_1[0] + tmp_1[2]; - tmp_2[1] = tmp_1[1] + tmp_1[3]; - tmp_2[2] = tmp_1[0] - tmp_1[2]; - tmp_2[3] = tmp_1[1] - tmp_1[3]; - tmp_2[4] = tmp_1[4] + tmp_1[6]; -// SQRT2DIV2 = sqrt(2)/2 -#define SQRT2DIV2 0.7071067811865476 - if (Dir == FFT_FORWARD) { - tmp_2[5] = (tmp_1[5] + tmp_1[7]) * ComplexScalar(SQRT2DIV2, -SQRT2DIV2); - tmp_2[6] = (tmp_1[4] - tmp_1[6]) * ComplexScalar(0, -1); - tmp_2[7] = (tmp_1[5] - tmp_1[7]) * ComplexScalar(-SQRT2DIV2, -SQRT2DIV2); - } else { - tmp_2[5] = (tmp_1[5] + tmp_1[7]) * ComplexScalar(SQRT2DIV2, SQRT2DIV2); - tmp_2[6] = (tmp_1[4] - tmp_1[6]) * ComplexScalar(0, 1); - tmp_2[7] = (tmp_1[5] - tmp_1[7]) * ComplexScalar(-SQRT2DIV2, SQRT2DIV2); - } - data[0] = tmp_2[0] + tmp_2[4]; - data[1] = tmp_2[1] + tmp_2[5]; - data[2] = tmp_2[2] + tmp_2[6]; - data[3] = tmp_2[3] + tmp_2[7]; - data[4] = tmp_2[0] - tmp_2[4]; - data[5] = tmp_2[1] - tmp_2[5]; - data[6] = tmp_2[2] - tmp_2[6]; - data[7] = tmp_2[3] - tmp_2[7]; - } - - template <int Dir> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void butterfly_1D_merge( - ComplexScalar* data, Index n, Index n_power_of_2) { - // Original code: - // RealScalar wtemp = std::sin(M_PI/n); - // RealScalar wpi = -std::sin(2 * M_PI/n); - const RealScalar wtemp = m_sin_PI_div_n_LUT[n_power_of_2]; - const RealScalar wpi = (Dir == FFT_FORWARD) - ? m_minus_sin_2_PI_div_n_LUT[n_power_of_2] - : -m_minus_sin_2_PI_div_n_LUT[n_power_of_2]; - - const ComplexScalar wp(wtemp, wpi); - const ComplexScalar wp_one = wp + ComplexScalar(1, 0); - const ComplexScalar wp_one_2 = wp_one * wp_one; - const ComplexScalar wp_one_3 = wp_one_2 * wp_one; - const ComplexScalar wp_one_4 = wp_one_3 * wp_one; - const Index n2 = n / 2; - ComplexScalar w(1.0, 0.0); - for (Index i = 0; i < n2; i += 4) { - ComplexScalar temp0(data[i + n2] * w); - ComplexScalar temp1(data[i + 1 + n2] * w * wp_one); - ComplexScalar temp2(data[i + 2 + n2] * w * wp_one_2); - ComplexScalar temp3(data[i + 3 + n2] * w * wp_one_3); - w = w * wp_one_4; - - data[i + n2] = data[i] - temp0; - data[i] += temp0; - - data[i + 1 + n2] = data[i + 1] - temp1; - data[i + 1] += temp1; - - data[i + 2 + n2] = data[i + 2] - temp2; - data[i + 2] += temp2; - - data[i + 3 + n2] = data[i + 3] - temp3; - data[i + 3] += temp3; - } - } - - template <int Dir> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void compute_1D_Butterfly( - ComplexScalar* data, Index n, Index n_power_of_2) { - eigen_assert(isPowerOfTwo(n)); - if (n > 8) { - compute_1D_Butterfly<Dir>(data, n / 2, n_power_of_2 - 1); - compute_1D_Butterfly<Dir>(data + n / 2, n / 2, n_power_of_2 - 1); - butterfly_1D_merge<Dir>(data, n, n_power_of_2); - } else if (n == 8) { - butterfly_8<Dir>(data); - } else if (n == 4) { - butterfly_4<Dir>(data); - } else if (n == 2) { - butterfly_2<Dir>(data); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index getBaseOffsetFromIndex(Index index, Index omitted_dim) const { - Index result = 0; - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumDims - 1; i > omitted_dim; --i) { - const Index partial_m_stride = m_strides[i] / m_dimensions[omitted_dim]; - const Index idx = index / partial_m_stride; - index -= idx * partial_m_stride; - result += idx * m_strides[i]; - } - result += index; - } - else { - for (Index i = 0; i < omitted_dim; ++i) { - const Index partial_m_stride = m_strides[i] / m_dimensions[omitted_dim]; - const Index idx = index / partial_m_stride; - index -= idx * partial_m_stride; - result += idx * m_strides[i]; - } - result += index; - } - // Value of index_coords[omitted_dim] is not determined to this step - return result; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index getIndexFromOffset(Index base, Index omitted_dim, Index offset) const { - Index result = base + offset * m_strides[omitted_dim] ; - return result; - } - - protected: - Index m_size; - const FFT EIGEN_DEVICE_REF m_fft; - Dimensions m_dimensions; - array<Index, NumDims> m_strides; - TensorEvaluator<ArgType, Device> m_impl; - EvaluatorPointerType m_data; - const Device EIGEN_DEVICE_REF m_device; - - // This will support a maximum FFT size of 2^32 for each dimension - // m_sin_PI_div_n_LUT[i] = (-2) * std::sin(M_PI / std::pow(2,i)) ^ 2; - const RealScalar m_sin_PI_div_n_LUT[32] = { - RealScalar(0.0), - RealScalar(-2), - RealScalar(-0.999999999999999), - RealScalar(-0.292893218813453), - RealScalar(-0.0761204674887130), - RealScalar(-0.0192147195967696), - RealScalar(-0.00481527332780311), - RealScalar(-0.00120454379482761), - RealScalar(-3.01181303795779e-04), - RealScalar(-7.52981608554592e-05), - RealScalar(-1.88247173988574e-05), - RealScalar(-4.70619042382852e-06), - RealScalar(-1.17654829809007e-06), - RealScalar(-2.94137117780840e-07), - RealScalar(-7.35342821488550e-08), - RealScalar(-1.83835707061916e-08), - RealScalar(-4.59589268710903e-09), - RealScalar(-1.14897317243732e-09), - RealScalar(-2.87243293150586e-10), - RealScalar( -7.18108232902250e-11), - RealScalar(-1.79527058227174e-11), - RealScalar(-4.48817645568941e-12), - RealScalar(-1.12204411392298e-12), - RealScalar(-2.80511028480785e-13), - RealScalar(-7.01277571201985e-14), - RealScalar(-1.75319392800498e-14), - RealScalar(-4.38298482001247e-15), - RealScalar(-1.09574620500312e-15), - RealScalar(-2.73936551250781e-16), - RealScalar(-6.84841378126949e-17), - RealScalar(-1.71210344531737e-17), - RealScalar(-4.28025861329343e-18) - }; - - // m_minus_sin_2_PI_div_n_LUT[i] = -std::sin(2 * M_PI / std::pow(2,i)); - const RealScalar m_minus_sin_2_PI_div_n_LUT[32] = { - RealScalar(0.0), - RealScalar(0.0), - RealScalar(-1.00000000000000e+00), - RealScalar(-7.07106781186547e-01), - RealScalar(-3.82683432365090e-01), - RealScalar(-1.95090322016128e-01), - RealScalar(-9.80171403295606e-02), - RealScalar(-4.90676743274180e-02), - RealScalar(-2.45412285229123e-02), - RealScalar(-1.22715382857199e-02), - RealScalar(-6.13588464915448e-03), - RealScalar(-3.06795676296598e-03), - RealScalar(-1.53398018628477e-03), - RealScalar(-7.66990318742704e-04), - RealScalar(-3.83495187571396e-04), - RealScalar(-1.91747597310703e-04), - RealScalar(-9.58737990959773e-05), - RealScalar(-4.79368996030669e-05), - RealScalar(-2.39684498084182e-05), - RealScalar(-1.19842249050697e-05), - RealScalar(-5.99211245264243e-06), - RealScalar(-2.99605622633466e-06), - RealScalar(-1.49802811316901e-06), - RealScalar(-7.49014056584716e-07), - RealScalar(-3.74507028292384e-07), - RealScalar(-1.87253514146195e-07), - RealScalar(-9.36267570730981e-08), - RealScalar(-4.68133785365491e-08), - RealScalar(-2.34066892682746e-08), - RealScalar(-1.17033446341373e-08), - RealScalar(-5.85167231706864e-09), - RealScalar(-2.92583615853432e-09) - }; -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_FFT_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFixedSize.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFixedSize.h deleted file mode 100644 index a5be54bc..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFixedSize.h +++ /dev/null @@ -1,396 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H -#define EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H - -namespace Eigen { - -/** \class TensorFixedSize - * \ingroup CXX11_Tensor_Module - * - * \brief The fixed sized version of the tensor class. - * - * The fixed sized equivalent of - * Eigen::Tensor<float, 3> t(3, 5, 7); - * is - * Eigen::TensorFixedSize<float, Sizes<3,5,7>> t; - */ - -template<typename Scalar_, typename Dimensions_, int Options_, typename IndexType> -class TensorFixedSize : public TensorBase<TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> > -{ - public: - typedef TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> Self; - typedef TensorBase<TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> > Base; - typedef typename Eigen::internal::nested<Self>::type Nested; - typedef typename internal::traits<Self>::StorageKind StorageKind; - typedef typename internal::traits<Self>::Index Index; - typedef Scalar_ Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef typename Base::CoeffReturnType CoeffReturnType; - - static const int Options = Options_; - - enum { - IsAligned = bool(EIGEN_MAX_ALIGN_BYTES>0), - PacketAccess = (internal::packet_traits<Scalar>::size > 1), - BlockAccess = false, - PreferBlockAccess = false, - Layout = Options_ & RowMajor ? RowMajor : ColMajor, - CoordAccess = true, - RawAccess = true - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - typedef Dimensions_ Dimensions; - static const std::size_t NumIndices = Dimensions::count; - - protected: - TensorStorage<Scalar, Dimensions, Options> m_storage; - - public: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { return NumIndices; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const { return m_storage.dimensions()[n]; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_storage.dimensions(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_storage.size(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() { return m_storage.data(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar *data() const { return m_storage.data(); } - - // This makes EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED - // work, because that uses base().coeffRef() - and we don't yet - // implement a similar class hierarchy - inline Self& base() { return *this; } - inline const Self& base() const { return *this; } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices) const - { - // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - return coeff(array<Index, NumIndices>{{firstIndex, otherIndices...}}); - } -#endif - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& coeff(const array<Index, NumIndices>& indices) const - { - eigen_internal_assert(checkIndexRange(indices)); - return m_storage.data()[linearizedIndex(indices)]; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const - { - eigen_internal_assert(index >= 0 && index < size()); - return m_storage.data()[index]; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& coeff() const - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - return m_storage.data()[0]; - } - - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices) - { - // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}}); - } -#endif - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(const array<Index, NumIndices>& indices) - { - eigen_internal_assert(checkIndexRange(indices)); - return m_storage.data()[linearizedIndex(indices)]; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) - { - eigen_internal_assert(index >= 0 && index < size()); - return m_storage.data()[index]; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef() - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - return m_storage.data()[0]; - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices) const - { - // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}}); - } -#else - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index i0, Index i1) const - { - if (Options&RowMajor) { - const Index index = i1 + i0 * m_storage.dimensions()[1]; - return m_storage.data()[index]; - } else { - const Index index = i0 + i1 * m_storage.dimensions()[0]; - return m_storage.data()[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index i0, Index i1, Index i2) const - { - if (Options&RowMajor) { - const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0); - return m_storage.data()[index]; - } else { - const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2); - return m_storage.data()[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index i0, Index i1, Index i2, Index i3) const - { - if (Options&RowMajor) { - const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)); - return m_storage.data()[index]; - } else { - const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3)); - return m_storage.data()[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4) const - { - if (Options&RowMajor) { - const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0))); - return m_storage.data()[index]; - } else { - const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4))); - return m_storage.data()[index]; - } - } -#endif - - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(const array<Index, NumIndices>& indices) const - { - eigen_assert(checkIndexRange(indices)); - return coeff(indices); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()(Index index) const - { - eigen_internal_assert(index >= 0 && index < size()); - return coeff(index); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator()() const - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - return coeff(); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar& operator[](Index index) const - { - // The bracket operator is only for vectors, use the parenthesis operator instead. - EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE); - return coeff(index); - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices) - { - // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}}); - } -#else - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1) - { - if (Options&RowMajor) { - const Index index = i1 + i0 * m_storage.dimensions()[1]; - return m_storage.data()[index]; - } else { - const Index index = i0 + i1 * m_storage.dimensions()[0]; - return m_storage.data()[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2) - { - if (Options&RowMajor) { - const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0); - return m_storage.data()[index]; - } else { - const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2); - return m_storage.data()[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3) - { - if (Options&RowMajor) { - const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)); - return m_storage.data()[index]; - } else { - const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3)); - return m_storage.data()[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4) - { - if (Options&RowMajor) { - const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0))); - return m_storage.data()[index]; - } else { - const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4))); - return m_storage.data()[index]; - } - } -#endif - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(const array<Index, NumIndices>& indices) - { - eigen_assert(checkIndexRange(indices)); - return coeffRef(indices); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index index) - { - eigen_assert(index >= 0 && index < size()); - return coeffRef(index); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()() - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE); - return coeffRef(); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator[](Index index) - { - // The bracket operator is only for vectors, use the parenthesis operator instead - EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE) - return coeffRef(index); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorFixedSize() - : m_storage() - { - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorFixedSize(const Self& other) - : m_storage(other.m_storage) - { - } - -#if EIGEN_HAS_RVALUE_REFERENCES - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(Self&& other) - : m_storage(other.m_storage) - { - } -#endif - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorFixedSize(const TensorBase<OtherDerived, ReadOnlyAccessors>& other) - { - typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign; - Assign assign(*this, other.derived()); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - } - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorFixedSize(const TensorBase<OtherDerived, WriteAccessors>& other) - { - typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign; - Assign assign(*this, other.derived()); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorFixedSize& operator=(const TensorFixedSize& other) - { - // FIXME: check that the dimensions of other match the dimensions of *this. - // Unfortunately this isn't possible yet when the rhs is an expression. - typedef TensorAssignOp<Self, const TensorFixedSize> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorFixedSize& operator=(const OtherDerived& other) - { - // FIXME: check that the dimensions of other match the dimensions of *this. - // Unfortunately this isn't possible yet when the rhs is an expression. - typedef TensorAssignOp<Self, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - protected: - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE bool checkIndexRange(const array<Index, NumIndices>& /*indices*/) const - { - using internal::array_apply_and_reduce; - using internal::array_zip_and_reduce; - using internal::greater_equal_zero_op; - using internal::logical_and_op; - using internal::lesser_op; - - return true; - // check whether the indices are all >= 0 - /* array_apply_and_reduce<logical_and_op, greater_equal_zero_op>(indices) && - // check whether the indices fit in the dimensions - array_zip_and_reduce<logical_and_op, lesser_op>(indices, m_storage.dimensions());*/ - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index linearizedIndex(const array<Index, NumIndices>& indices) const - { - if (Options&RowMajor) { - return m_storage.dimensions().IndexOfRowMajor(indices); - } else { - return m_storage.dimensions().IndexOfColMajor(indices); - } - } -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.h deleted file mode 100644 index 14020aa6..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.h +++ /dev/null @@ -1,240 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H -#define EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H - -namespace Eigen { - -/** \class TensorForcedEval - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor reshaping class. - * - * - */ -namespace internal { -template<typename XprType> -struct traits<TensorForcedEvalOp<XprType> > -{ - // Type promotion to handle the case where the types of the lhs and the rhs are different. - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename traits<XprType>::StorageKind StorageKind; - typedef typename traits<XprType>::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; - - enum { - Flags = 0 - }; -}; - -template<typename XprType> -struct eval<TensorForcedEvalOp<XprType>, Eigen::Dense> -{ - typedef const TensorForcedEvalOp<XprType>& type; -}; - -template<typename XprType> -struct nested<TensorForcedEvalOp<XprType>, 1, typename eval<TensorForcedEvalOp<XprType> >::type> -{ - typedef TensorForcedEvalOp<XprType> type; -}; - -} // end namespace internal - - - -template<typename XprType> -class TensorForcedEvalOp : public TensorBase<TensorForcedEvalOp<XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename Eigen::internal::nested<TensorForcedEvalOp>::type Nested; - typedef typename Eigen::internal::traits<TensorForcedEvalOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(const XprType& expr) - : m_xpr(expr) {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; -}; - -namespace internal { -template <typename Device, typename CoeffReturnType> -struct non_integral_type_placement_new{ - template <typename StorageType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index numValues, StorageType m_buffer) { - // Initialize non-trivially constructible types. - if (!internal::is_arithmetic<CoeffReturnType>::value) { - for (Index i = 0; i < numValues; ++i) new (m_buffer + i) CoeffReturnType(); - } -} -}; - -// SYCL does not support non-integral types -// having new (m_buffer + i) CoeffReturnType() causes the following compiler error for SYCL Devices -// no matching function for call to 'operator new' -template <typename CoeffReturnType> -struct non_integral_type_placement_new<Eigen::SyclDevice, CoeffReturnType> { - template <typename StorageType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index, StorageType) { -} -}; -} // end namespace internal - -template<typename ArgType_, typename Device> -struct TensorEvaluator<const TensorForcedEvalOp<ArgType_>, Device> -{ - typedef const typename internal::remove_all<ArgType_>::type ArgType; - typedef TensorForcedEvalOp<ArgType> XprType; - typedef typename ArgType::Scalar Scalar; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions; - typedef typename XprType::Index Index; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = true, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = internal::is_arithmetic<CoeffReturnType>::value, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - RawAccess = true - }; - - static const int NumDims = internal::traits<ArgType>::NumDimensions; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename internal::TensorMaterializedBlock<CoeffReturnType, NumDims, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_op(op.expression()), - m_device(device), m_buffer(NULL) - { } - - EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); } - - #if !defined(EIGEN_HIPCC) - EIGEN_DEVICE_FUNC - #endif - EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - const Index numValues = internal::array_prod(m_impl.dimensions()); - m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(numValues * sizeof(CoeffReturnType))); - - internal::non_integral_type_placement_new<Device, CoeffReturnType>()(numValues, m_buffer); - - typedef TensorEvalToOp< const typename internal::remove_const<ArgType>::type > EvalTo; - EvalTo evalToTmp(m_device.get(m_buffer), m_op); - - internal::TensorExecutor< - const EvalTo, typename internal::remove_const<Device>::type, - /*Vectorizable=*/internal::IsVectorizable<Device, const ArgType>::value, - /*Tiling=*/internal::IsTileable<Device, const ArgType>::value>:: - run(evalToTmp, m_device); - - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - const Index numValues = internal::array_prod(m_impl.dimensions()); - m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp( - numValues * sizeof(CoeffReturnType))); - typedef TensorEvalToOp<const typename internal::remove_const<ArgType>::type> - EvalTo; - EvalTo evalToTmp(m_device.get(m_buffer), m_op); - - auto on_done = std::bind([](EvalSubExprsCallback done_) { done_(true); }, - std::move(done)); - internal::TensorAsyncExecutor< - const EvalTo, typename internal::remove_const<Device>::type, - decltype(on_done), - /*Vectorizable=*/internal::IsVectorizable<Device, const ArgType>::value, - /*Tiling=*/internal::IsTileable<Device, const ArgType>::value>:: - runAsync(evalToTmp, m_device, std::move(on_done)); - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_device.deallocate_temp(m_buffer); - m_buffer = NULL; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return m_buffer[index]; - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - return internal::TensorBlockResourceRequirements::any(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - assert(m_buffer != NULL); - return TensorBlock::materialize(m_buffer, m_impl.dimensions(), desc, scratch); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - EvaluatorPointerType data() const { return m_buffer; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_buffer.bind(cgh); - m_impl.bind(cgh); - } -#endif - private: - TensorEvaluator<ArgType, Device> m_impl; - const ArgType m_op; - const Device EIGEN_DEVICE_REF m_device; - EvaluatorPointerType m_buffer; -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h deleted file mode 100644 index 246ebe44..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h +++ /dev/null @@ -1,191 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_FORWARD_DECLARATIONS_H -#define EIGEN_CXX11_TENSOR_TENSOR_FORWARD_DECLARATIONS_H - -namespace Eigen { - -// MakePointer class is used as a container of the address space of the pointer -// on the host and on the device. From the host side it generates the T* pointer -// and when EIGEN_USE_SYCL is used it construct a buffer with a map_allocator to -// T* m_data on the host. It is always called on the device. -// Specialisation of MakePointer class for creating the sycl buffer with -// map_allocator. -template<typename T> struct MakePointer { - typedef T* Type; - typedef const T* ConstType; -}; - -template <typename T> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* constCast(const T* data) { - return const_cast<T*>(data); -} - -// The StorageMemory class is a container of the device specific pointer -// used for refering to a Pointer on TensorEvaluator class. While the TensorExpression -// is a device-agnostic type and need MakePointer class for type conversion, -// the TensorEvaluator class can be specialized for a device, hence it is possible -// to construct different types of temproray storage memory in TensorEvaluator -// for different devices by specializing the following StorageMemory class. -template<typename T, typename device> struct StorageMemory: MakePointer <T> {}; - -namespace internal{ -template<typename A, typename B> struct Pointer_type_promotion { - static const bool val=false; -}; -template<typename A> struct Pointer_type_promotion<A, A> { - static const bool val = true; -}; -template<typename A, typename B> struct TypeConversion { - typedef A* type; -}; -} - - -template<typename PlainObjectType, int Options_ = Unaligned, template <class> class MakePointer_ = MakePointer> class TensorMap; -template<typename Scalar_, int NumIndices_, int Options_ = 0, typename IndexType = DenseIndex> class Tensor; -template<typename Scalar_, typename Dimensions, int Options_ = 0, typename IndexType = DenseIndex> class TensorFixedSize; -template<typename PlainObjectType> class TensorRef; -template<typename Derived, int AccessLevel> class TensorBase; - -template<typename NullaryOp, typename PlainObjectType> class TensorCwiseNullaryOp; -template<typename UnaryOp, typename XprType> class TensorCwiseUnaryOp; -template<typename BinaryOp, typename LeftXprType, typename RightXprType> class TensorCwiseBinaryOp; -template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType> class TensorCwiseTernaryOp; -template<typename IfXprType, typename ThenXprType, typename ElseXprType> class TensorSelectOp; -template<typename Op, typename Dims, typename XprType, template <class> class MakePointer_ = MakePointer > class TensorReductionOp; -template<typename XprType> class TensorIndexTupleOp; -template<typename ReduceOp, typename Dims, typename XprType> class TensorTupleReducerOp; -template<typename Axis, typename LeftXprType, typename RightXprType> class TensorConcatenationOp; -template<typename Dimensions, typename LeftXprType, typename RightXprType, typename OutputKernelType> class TensorContractionOp; -template<typename TargetType, typename XprType> class TensorConversionOp; -template<typename Dimensions, typename InputXprType, typename KernelXprType> class TensorConvolutionOp; -template<typename FFT, typename XprType, int FFTDataType, int FFTDirection> class TensorFFTOp; -template<typename PatchDim, typename XprType> class TensorPatchOp; -template<DenseIndex Rows, DenseIndex Cols, typename XprType> class TensorImagePatchOp; -template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType> class TensorVolumePatchOp; -template<typename Broadcast, typename XprType> class TensorBroadcastingOp; -template<DenseIndex DimId, typename XprType> class TensorChippingOp; -template<typename NewDimensions, typename XprType> class TensorReshapingOp; -template<typename XprType> class TensorLayoutSwapOp; -template<typename StartIndices, typename Sizes, typename XprType> class TensorSlicingOp; -template<typename ReverseDimensions, typename XprType> class TensorReverseOp; -template<typename PaddingDimensions, typename XprType> class TensorPaddingOp; -template<typename Shuffle, typename XprType> class TensorShufflingOp; -template<typename Strides, typename XprType> class TensorStridingOp; -template<typename StartIndices, typename StopIndices, typename Strides, typename XprType> class TensorStridingSlicingOp; -template<typename Strides, typename XprType> class TensorInflationOp; -template<typename Generator, typename XprType> class TensorGeneratorOp; -template<typename LeftXprType, typename RightXprType> class TensorAssignOp; -template<typename Op, typename XprType> class TensorScanOp; -template<typename Dims, typename XprType> class TensorTraceOp; - -template<typename CustomUnaryFunc, typename XprType> class TensorCustomUnaryOp; -template<typename CustomBinaryFunc, typename LhsXprType, typename RhsXprType> class TensorCustomBinaryOp; - -template<typename XprType, template <class> class MakePointer_ = MakePointer> class TensorEvalToOp; -template<typename XprType> class TensorForcedEvalOp; - -template<typename ExpressionType, typename DeviceType> class TensorDevice; -template<typename ExpressionType, typename DeviceType, typename DoneCallback> class TensorAsyncDevice; -template<typename Derived, typename Device> struct TensorEvaluator; - -struct NoOpOutputKernel; - -struct DefaultDevice; -struct ThreadPoolDevice; -struct GpuDevice; -struct SyclDevice; - -#ifdef EIGEN_USE_SYCL - -template <typename T> struct MakeSYCLPointer { - typedef Eigen::TensorSycl::internal::RangeAccess<cl::sycl::access::mode::read_write, T> Type; -}; - -template <typename T> -EIGEN_STRONG_INLINE const Eigen::TensorSycl::internal::RangeAccess<cl::sycl::access::mode::read_write, T>& -constCast(const Eigen::TensorSycl::internal::RangeAccess<cl::sycl::access::mode::read_write, T>& data) { - return data; -} - -template <typename T> -struct StorageMemory<T, SyclDevice> : MakeSYCLPointer<T> {}; -template <typename T> -struct StorageMemory<T, const SyclDevice> : StorageMemory<T, SyclDevice> {}; - -namespace TensorSycl { -namespace internal{ -template <typename Evaluator, typename Op> class GenericNondeterministicReducer; -} -} -#endif - - -enum FFTResultType { - RealPart = 0, - ImagPart = 1, - BothParts = 2 -}; - -enum FFTDirection { - FFT_FORWARD = 0, - FFT_REVERSE = 1 -}; - - -namespace internal { - -template <typename Device, typename Expression> -struct IsVectorizable { - static const bool value = TensorEvaluator<Expression, Device>::PacketAccess; -}; - -template <typename Expression> -struct IsVectorizable<GpuDevice, Expression> { - static const bool value = TensorEvaluator<Expression, GpuDevice>::PacketAccess && - TensorEvaluator<Expression, GpuDevice>::IsAligned; -}; - -// Tiled evaluation strategy. -enum TiledEvaluation { - Off = 0, // tiled evaluation is not supported - On = 1, // still work in progress (see TensorBlock.h) -}; - -template <typename Device, typename Expression> -struct IsTileable { - // Check that block evaluation is supported and it's a preferred option (at - // least one sub-expression has much faster block evaluation, e.g. - // broadcasting). - static const bool BlockAccess = - TensorEvaluator<Expression, Device>::BlockAccess && - TensorEvaluator<Expression, Device>::PreferBlockAccess; - - static const TiledEvaluation value = - BlockAccess ? TiledEvaluation::On : TiledEvaluation::Off; -}; - -template <typename Expression, typename Device, - bool Vectorizable = IsVectorizable<Device, Expression>::value, - TiledEvaluation Tiling = IsTileable<Device, Expression>::value> -class TensorExecutor; - -template <typename Expression, typename Device, typename DoneCallback, - bool Vectorizable = IsVectorizable<Device, Expression>::value, - TiledEvaluation Tiling = IsTileable<Device, Expression>::value> -class TensorAsyncExecutor; - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_FORWARD_DECLARATIONS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h deleted file mode 100644 index 2edc45f1..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h +++ /dev/null @@ -1,477 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_FUNCTORS_H -#define EIGEN_CXX11_TENSOR_TENSOR_FUNCTORS_H - -namespace Eigen { -namespace internal { - - -/** \internal - * \brief Template functor to compute the modulo between an array and a scalar. - */ -template <typename Scalar> -struct scalar_mod_op { - EIGEN_DEVICE_FUNC scalar_mod_op(const Scalar& divisor) : m_divisor(divisor) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a) const { return a % m_divisor; } - const Scalar m_divisor; -}; -template <typename Scalar> -struct functor_traits<scalar_mod_op<Scalar> > -{ enum { Cost = scalar_div_cost<Scalar,false>::value, PacketAccess = false }; }; - - -/** \internal - * \brief Template functor to compute the modulo between 2 arrays. - */ -template <typename Scalar> -struct scalar_mod2_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_mod2_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a, const Scalar& b) const { return a % b; } -}; -template <typename Scalar> -struct functor_traits<scalar_mod2_op<Scalar> > -{ enum { Cost = scalar_div_cost<Scalar,false>::value, PacketAccess = false }; }; - -template <typename Scalar> -struct scalar_fmod_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_fmod_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar - operator()(const Scalar& a, const Scalar& b) const { - return numext::fmod(a, b); - } -}; -template <typename Scalar> -struct functor_traits<scalar_fmod_op<Scalar> > { - enum { Cost = 13, // Reciprocal throughput of FPREM on Haswell. - PacketAccess = false }; -}; - -template<typename Reducer, typename Device> -struct reducer_traits { - enum { - Cost = 1, - PacketAccess = false, - IsStateful = false, - IsExactlyAssociative = true - }; -}; - -// Standard reduction functors -template <typename T> struct SumReducer -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) const { - internal::scalar_sum_op<T> sum_op; - *accum = sum_op(*accum, t); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) const { - (*accum) = padd<Packet>(*accum, p); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T initialize() const { - internal::scalar_cast_op<int, T> conv; - return conv(0); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet initializePacket() const { - return pset1<Packet>(initialize()); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalize(const T accum) const { - return accum; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const { - return vaccum; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const { - internal::scalar_sum_op<T> sum_op; - return sum_op(saccum, predux(vaccum)); - } -}; - -template <typename T, typename Device> -struct reducer_traits<SumReducer<T>, Device> { - enum { - Cost = NumTraits<T>::AddCost, - PacketAccess = PacketType<T, Device>::HasAdd, - IsStateful = false, - IsExactlyAssociative = NumTraits<T>::IsInteger - }; -}; - -template <typename T> struct MeanReducer -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - MeanReducer() : scalarCount_(0), packetCount_(0) { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) { - internal::scalar_sum_op<T> sum_op; - *accum = sum_op(*accum, t); - scalarCount_++; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) { - (*accum) = padd<Packet>(*accum, p); - packetCount_++; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T initialize() const { - internal::scalar_cast_op<int, T> conv; - return conv(0); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet initializePacket() const { - return pset1<Packet>(initialize()); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalize(const T accum) const { - internal::scalar_quotient_op<T> quotient_op; - return quotient_op(accum, T(scalarCount_)); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const { - return pdiv(vaccum, pset1<Packet>(T(packetCount_))); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const { - internal::scalar_sum_op<T> sum_op; - internal::scalar_quotient_op<T> quotient_op; - return quotient_op( - sum_op(saccum, predux(vaccum)), - T(scalarCount_ + packetCount_ * unpacket_traits<Packet>::size)); - } - - protected: - DenseIndex scalarCount_; - DenseIndex packetCount_; -}; - -template <typename T, typename Device> -struct reducer_traits<MeanReducer<T>, Device> { - enum { - Cost = NumTraits<T>::AddCost, - PacketAccess = PacketType<T, Device>::HasAdd && - PacketType<T, Device>::HasDiv && !NumTraits<T>::IsInteger, - IsStateful = true, - IsExactlyAssociative = NumTraits<T>::IsInteger - }; -}; - - -template <typename T, bool IsMax = true, bool IsInteger = true> -struct MinMaxBottomValue { - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T bottom_value() { - return Eigen::NumTraits<T>::lowest(); - } -}; -template <typename T> -struct MinMaxBottomValue<T, true, false> { - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T bottom_value() { - return -Eigen::NumTraits<T>::infinity(); - } -}; -template <typename T> -struct MinMaxBottomValue<T, false, true> { - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T bottom_value() { - return Eigen::NumTraits<T>::highest(); - } -}; -template <typename T> -struct MinMaxBottomValue<T, false, false> { - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T bottom_value() { - return Eigen::NumTraits<T>::infinity(); - } -}; - - -template <typename T> struct MaxReducer -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) const { - if (t > *accum) { *accum = t; } - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) const { - (*accum) = pmax<Packet>(*accum, p); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T initialize() const { - return MinMaxBottomValue<T, true, Eigen::NumTraits<T>::IsInteger>::bottom_value(); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet initializePacket() const { - return pset1<Packet>(initialize()); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalize(const T accum) const { - return accum; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const { - return vaccum; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const { - return numext::maxi(saccum, predux_max(vaccum)); - } -}; - -template <typename T, typename Device> -struct reducer_traits<MaxReducer<T>, Device> { - enum { - Cost = NumTraits<T>::AddCost, - PacketAccess = PacketType<T, Device>::HasMax, - IsStateful = false, - IsExactlyAssociative = true - }; -}; - - -template <typename T> struct MinReducer -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) const { - if (t < *accum) { *accum = t; } - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) const { - (*accum) = pmin<Packet>(*accum, p); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T initialize() const { - return MinMaxBottomValue<T, false, Eigen::NumTraits<T>::IsInteger>::bottom_value(); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet initializePacket() const { - return pset1<Packet>(initialize()); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalize(const T accum) const { - return accum; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const { - return vaccum; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const { - return numext::mini(saccum, predux_min(vaccum)); - } -}; - -template <typename T, typename Device> -struct reducer_traits<MinReducer<T>, Device> { - enum { - Cost = NumTraits<T>::AddCost, - PacketAccess = PacketType<T, Device>::HasMin, - IsStateful = false, - IsExactlyAssociative = true - }; -}; - - -template <typename T> struct ProdReducer -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) const { - internal::scalar_product_op<T> prod_op; - (*accum) = prod_op(*accum, t); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) const { - (*accum) = pmul<Packet>(*accum, p); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T initialize() const { - internal::scalar_cast_op<int, T> conv; - return conv(1); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet initializePacket() const { - return pset1<Packet>(initialize()); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalize(const T accum) const { - return accum; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const { - return vaccum; - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const { - internal::scalar_product_op<T> prod_op; - return prod_op(saccum, predux_mul(vaccum)); - } -}; - -template <typename T, typename Device> -struct reducer_traits<ProdReducer<T>, Device> { - enum { - Cost = NumTraits<T>::MulCost, - PacketAccess = PacketType<T, Device>::HasMul, - IsStateful = false, - IsExactlyAssociative = true - }; -}; - - -struct AndReducer -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(bool t, bool* accum) const { - *accum = *accum && t; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool initialize() const { - return true; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool finalize(bool accum) const { - return accum; - } -}; - -template <typename Device> -struct reducer_traits<AndReducer, Device> { - enum { - Cost = 1, - PacketAccess = false, - IsStateful = false, - IsExactlyAssociative = true - }; -}; - - -struct OrReducer { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(bool t, bool* accum) const { - *accum = *accum || t; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool initialize() const { - return false; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool finalize(bool accum) const { - return accum; - } -}; - -template <typename Device> -struct reducer_traits<OrReducer, Device> { - enum { - Cost = 1, - PacketAccess = false, - IsStateful = false, - IsExactlyAssociative = true - }; -}; - - -// Argmin/Argmax reducers -template <typename T> struct ArgMaxTupleReducer -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) const { - if (t.second > accum->second) { *accum = t; } - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T initialize() const { - return T(0, NumTraits<typename T::second_type>::lowest()); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalize(const T& accum) const { - return accum; - } -}; - -template <typename T, typename Device> -struct reducer_traits<ArgMaxTupleReducer<T>, Device> { - enum { - Cost = NumTraits<T>::AddCost, - PacketAccess = false, - IsStateful = false, - IsExactlyAssociative = true - }; -}; - - -template <typename T> struct ArgMinTupleReducer -{ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T& t, T* accum) const { - if (t.second < accum->second) { *accum = t; } - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T initialize() const { - return T(0, NumTraits<typename T::second_type>::highest()); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalize(const T& accum) const { - return accum; - } -}; - -template <typename T, typename Device> -struct reducer_traits<ArgMinTupleReducer<T>, Device> { - enum { - Cost = NumTraits<T>::AddCost, - PacketAccess = false, - IsStateful = false, - IsExactlyAssociative = true - }; -}; - - -template <typename T, typename Index, size_t NumDims> -class GaussianGenerator { - public: - static const bool PacketAccess = false; - - EIGEN_DEVICE_FUNC GaussianGenerator(const array<T, NumDims>& means, - const array<T, NumDims>& std_devs) - : m_means(means) - { - EIGEN_UNROLL_LOOP - for (size_t i = 0; i < NumDims; ++i) { - m_two_sigmas[i] = std_devs[i] * std_devs[i] * 2; - } - } - - EIGEN_DEVICE_FUNC T operator()(const array<Index, NumDims>& coordinates) const { - T tmp = T(0); - EIGEN_UNROLL_LOOP - for (size_t i = 0; i < NumDims; ++i) { - T offset = coordinates[i] - m_means[i]; - tmp += offset * offset / m_two_sigmas[i]; - } - return numext::exp(-tmp); - } - - private: - array<T, NumDims> m_means; - array<T, NumDims> m_two_sigmas; -}; - -template <typename T, typename Index, size_t NumDims> -struct functor_traits<GaussianGenerator<T, Index, NumDims> > { - enum { - Cost = NumDims * (2 * NumTraits<T>::AddCost + NumTraits<T>::MulCost + - functor_traits<scalar_quotient_op<T, T> >::Cost) + - functor_traits<scalar_exp_op<T> >::Cost, - PacketAccess = GaussianGenerator<T, Index, NumDims>::PacketAccess - }; -}; - -template <typename Scalar> -struct scalar_clamp_op { - EIGEN_DEVICE_FUNC inline scalar_clamp_op(const Scalar& _min, const Scalar& _max) : m_min(_min), m_max(_max) {} - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar - operator()(const Scalar& x) const { - return numext::mini(numext::maxi(x, m_min), m_max); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet - packetOp(const Packet& x) const { - return internal::pmin(internal::pmax(x, pset1<Packet>(m_min)), pset1<Packet>(m_max)); - } - const Scalar m_min; - const Scalar m_max; -}; -template<typename Scalar> -struct functor_traits<scalar_clamp_op<Scalar> > -{ enum { Cost = 2 * NumTraits<Scalar>::AddCost, PacketAccess = (packet_traits<Scalar>::HasMin && packet_traits<Scalar>::HasMax)}; }; - -} // end namespace internal -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_FUNCTORS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGenerator.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGenerator.h deleted file mode 100644 index b1ff1d8b..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGenerator.h +++ /dev/null @@ -1,302 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_GENERATOR_H -#define EIGEN_CXX11_TENSOR_TENSOR_GENERATOR_H - -namespace Eigen { - -/** \class TensorGeneratorOp - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor generator class. - * - * - */ -namespace internal { -template<typename Generator, typename XprType> -struct traits<TensorGeneratorOp<Generator, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename Generator, typename XprType> -struct eval<TensorGeneratorOp<Generator, XprType>, Eigen::Dense> -{ - typedef const TensorGeneratorOp<Generator, XprType>& type; -}; - -template<typename Generator, typename XprType> -struct nested<TensorGeneratorOp<Generator, XprType>, 1, typename eval<TensorGeneratorOp<Generator, XprType> >::type> -{ - typedef TensorGeneratorOp<Generator, XprType> type; -}; - -} // end namespace internal - - - -template<typename Generator, typename XprType> -class TensorGeneratorOp : public TensorBase<TensorGeneratorOp<Generator, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorGeneratorOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorGeneratorOp>::type Nested; - typedef typename Eigen::internal::traits<TensorGeneratorOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorGeneratorOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorGeneratorOp(const XprType& expr, const Generator& generator) - : m_xpr(expr), m_generator(generator) {} - - EIGEN_DEVICE_FUNC - const Generator& generator() const { return m_generator; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const Generator m_generator; -}; - - -// Eval as rvalue -template<typename Generator, typename ArgType, typename Device> -struct TensorEvaluator<const TensorGeneratorOp<Generator, ArgType>, Device> -{ - typedef TensorGeneratorOp<Generator, ArgType> XprType; - typedef typename XprType::Index Index; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions; - static const int NumDims = internal::array_size<Dimensions>::value; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - enum { - IsAligned = false, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = true, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - typedef internal::TensorIntDivisor<Index> IndexDivisor; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename internal::TensorMaterializedBlock<CoeffReturnType, NumDims, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_device(device), m_generator(op.generator()) - { - TensorEvaluator<ArgType, Device> argImpl(op.expression(), device); - m_dimensions = argImpl.dimensions(); - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_strides[0] = 1; - EIGEN_UNROLL_LOOP - for (int i = 1; i < NumDims; ++i) { - m_strides[i] = m_strides[i - 1] * m_dimensions[i - 1]; - if (m_strides[i] != 0) m_fast_strides[i] = IndexDivisor(m_strides[i]); - } - } else { - m_strides[NumDims - 1] = 1; - EIGEN_UNROLL_LOOP - for (int i = NumDims - 2; i >= 0; --i) { - m_strides[i] = m_strides[i + 1] * m_dimensions[i + 1]; - if (m_strides[i] != 0) m_fast_strides[i] = IndexDivisor(m_strides[i]); - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - return true; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - array<Index, NumDims> coords; - extract_coordinates(index, coords); - return m_generator(coords); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - const int packetSize = PacketType<CoeffReturnType, Device>::size; - EIGEN_STATIC_ASSERT((packetSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+packetSize-1 < dimensions().TotalSize()); - - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[packetSize]; - for (int i = 0; i < packetSize; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - const size_t target_size = m_device.firstLevelCacheSize(); - // TODO(ezhulenev): Generator should have a cost. - return internal::TensorBlockResourceRequirements::skewed<Scalar>( - target_size); - } - - struct BlockIteratorState { - Index stride; - Index span; - Index size; - Index count; - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - static const bool is_col_major = - static_cast<int>(Layout) == static_cast<int>(ColMajor); - - // Compute spatial coordinates for the first block element. - array<Index, NumDims> coords; - extract_coordinates(desc.offset(), coords); - array<Index, NumDims> initial_coords = coords; - - // Offset in the output block buffer. - Index offset = 0; - - // Initialize output block iterator state. Dimension in this array are - // always in inner_most -> outer_most order (col major layout). - array<BlockIteratorState, NumDims> it; - for (int i = 0; i < NumDims; ++i) { - const int dim = is_col_major ? i : NumDims - 1 - i; - it[i].size = desc.dimension(dim); - it[i].stride = i == 0 ? 1 : (it[i - 1].size * it[i - 1].stride); - it[i].span = it[i].stride * (it[i].size - 1); - it[i].count = 0; - } - eigen_assert(it[0].stride == 1); - - // Prepare storage for the materialized generator result. - const typename TensorBlock::Storage block_storage = - TensorBlock::prepareStorage(desc, scratch); - - CoeffReturnType* block_buffer = block_storage.data(); - - static const int packet_size = PacketType<CoeffReturnType, Device>::size; - - static const int inner_dim = is_col_major ? 0 : NumDims - 1; - const Index inner_dim_size = it[0].size; - const Index inner_dim_vectorized = inner_dim_size - packet_size; - - while (it[NumDims - 1].count < it[NumDims - 1].size) { - Index i = 0; - // Generate data for the vectorized part of the inner-most dimension. - for (; i <= inner_dim_vectorized; i += packet_size) { - for (Index j = 0; j < packet_size; ++j) { - array<Index, NumDims> j_coords = coords; // Break loop dependence. - j_coords[inner_dim] += j; - *(block_buffer + offset + i + j) = m_generator(j_coords); - } - coords[inner_dim] += packet_size; - } - // Finalize non-vectorized part of the inner-most dimension. - for (; i < inner_dim_size; ++i) { - *(block_buffer + offset + i) = m_generator(coords); - coords[inner_dim]++; - } - coords[inner_dim] = initial_coords[inner_dim]; - - // For the 1d tensor we need to generate only one inner-most dimension. - if (NumDims == 1) break; - - // Update offset. - for (i = 1; i < NumDims; ++i) { - if (++it[i].count < it[i].size) { - offset += it[i].stride; - coords[is_col_major ? i : NumDims - 1 - i]++; - break; - } - if (i != NumDims - 1) it[i].count = 0; - coords[is_col_major ? i : NumDims - 1 - i] = - initial_coords[is_col_major ? i : NumDims - 1 - i]; - offset -= it[i].span; - } - } - - return block_storage.AsTensorMaterializedBlock(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool) const { - // TODO(rmlarsen): This is just a placeholder. Define interface to make - // generators return their cost. - return TensorOpCost(0, 0, TensorOpCost::AddCost<Scalar>() + - TensorOpCost::MulCost<Scalar>()); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler&) const {} -#endif - - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void extract_coordinates(Index index, array<Index, NumDims>& coords) const { - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_fast_strides[i]; - index -= idx * m_strides[i]; - coords[i] = idx; - } - coords[0] = index; - } else { - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_fast_strides[i]; - index -= idx * m_strides[i]; - coords[i] = idx; - } - coords[NumDims-1] = index; - } - } - - const Device EIGEN_DEVICE_REF m_device; - Dimensions m_dimensions; - array<Index, NumDims> m_strides; - array<IndexDivisor, NumDims> m_fast_strides; - Generator m_generator; -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_GENERATOR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGlobalFunctions.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGlobalFunctions.h deleted file mode 100644 index 665b861c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGlobalFunctions.h +++ /dev/null @@ -1,33 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_GLOBAL_FUNCTIONS_H -#define EIGEN_CXX11_TENSOR_TENSOR_GLOBAL_FUNCTIONS_H - -namespace Eigen { - -/** \cpp11 \returns an expression of the coefficient-wise betainc(\a x, \a a, \a b) to the given tensors. - * - * This function computes the regularized incomplete beta function (integral). - * - */ -template <typename ADerived, typename BDerived, typename XDerived> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const - TensorCwiseTernaryOp<internal::scalar_betainc_op<typename XDerived::Scalar>, - const ADerived, const BDerived, const XDerived> - betainc(const ADerived& a, const BDerived& b, const XDerived& x) { - return TensorCwiseTernaryOp< - internal::scalar_betainc_op<typename XDerived::Scalar>, const ADerived, - const BDerived, const XDerived>( - a, b, x, internal::scalar_betainc_op<typename XDerived::Scalar>()); -} - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_GLOBAL_FUNCTIONS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h deleted file mode 100644 index f32ce27e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h +++ /dev/null @@ -1,93 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// Copyright (C) 2018 Deven Desai <deven.desai.amd@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#if defined(EIGEN_USE_GPU) && !defined(EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H) -#define EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H - -// Note that we are using EIGEN_USE_HIP here instead of EIGEN_HIPCC...this is by design -// There is code in the Tensorflow codebase that will define EIGEN_USE_GPU, but -// for some reason gets sent to the gcc/host compiler instead of the gpu/nvcc/hipcc compiler -// When compiling such files, gcc will end up trying to pick up the CUDA headers by -// default (see the code within "unsupported/Eigen/CXX11/Tensor" that is guarded by EIGEN_USE_GPU) -// This will obsviously not work when trying to compile tensorflow on a system with no CUDA -// To work around this issue for HIP systems (and leave the default behaviour intact), the -// HIP tensorflow build defines EIGEN_USE_HIP when compiling all source files, and -// "unsupported/Eigen/CXX11/Tensor" has been updated to use HIP header when EIGEN_USE_HIP is -// defined. In continuation of that requirement, the guard here needs to be EIGEN_USE_HIP as well - -#if defined(EIGEN_USE_HIP) - -#define gpuStream_t hipStream_t -#define gpuDeviceProp_t hipDeviceProp_t -#define gpuError_t hipError_t -#define gpuSuccess hipSuccess -#define gpuErrorNotReady hipErrorNotReady -#define gpuGetDeviceCount hipGetDeviceCount -#define gpuGetErrorString hipGetErrorString -#define gpuGetDeviceProperties hipGetDeviceProperties -#define gpuStreamDefault hipStreamDefault -#define gpuGetDevice hipGetDevice -#define gpuSetDevice hipSetDevice -#define gpuMalloc hipMalloc -#define gpuFree hipFree -#define gpuMemsetAsync hipMemsetAsync -#define gpuMemcpyAsync hipMemcpyAsync -#define gpuMemcpyDeviceToDevice hipMemcpyDeviceToDevice -#define gpuMemcpyDeviceToHost hipMemcpyDeviceToHost -#define gpuMemcpyHostToDevice hipMemcpyHostToDevice -#define gpuStreamQuery hipStreamQuery -#define gpuSharedMemConfig hipSharedMemConfig -#define gpuDeviceSetSharedMemConfig hipDeviceSetSharedMemConfig -#define gpuStreamSynchronize hipStreamSynchronize -#define gpuDeviceSynchronize hipDeviceSynchronize -#define gpuMemcpy hipMemcpy - -#else - -#define gpuStream_t cudaStream_t -#define gpuDeviceProp_t cudaDeviceProp -#define gpuError_t cudaError_t -#define gpuSuccess cudaSuccess -#define gpuErrorNotReady cudaErrorNotReady -#define gpuGetDeviceCount cudaGetDeviceCount -#define gpuGetErrorString cudaGetErrorString -#define gpuGetDeviceProperties cudaGetDeviceProperties -#define gpuStreamDefault cudaStreamDefault -#define gpuGetDevice cudaGetDevice -#define gpuSetDevice cudaSetDevice -#define gpuMalloc cudaMalloc -#define gpuFree cudaFree -#define gpuMemsetAsync cudaMemsetAsync -#define gpuMemcpyAsync cudaMemcpyAsync -#define gpuMemcpyDeviceToDevice cudaMemcpyDeviceToDevice -#define gpuMemcpyDeviceToHost cudaMemcpyDeviceToHost -#define gpuMemcpyHostToDevice cudaMemcpyHostToDevice -#define gpuStreamQuery cudaStreamQuery -#define gpuSharedMemConfig cudaSharedMemConfig -#define gpuDeviceSetSharedMemConfig cudaDeviceSetSharedMemConfig -#define gpuStreamSynchronize cudaStreamSynchronize -#define gpuDeviceSynchronize cudaDeviceSynchronize -#define gpuMemcpy cudaMemcpy - -#endif - -// gpu_assert can be overridden -#ifndef gpu_assert - -#if defined(EIGEN_HIP_DEVICE_COMPILE) -// HIPCC do not support the use of assert on the GPU side. -#define gpu_assert(COND) -#else -#define gpu_assert(COND) assert(COND) -#endif - -#endif // gpu_assert - -#endif // EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaUndefines.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaUndefines.h deleted file mode 100644 index db394bcb..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaUndefines.h +++ /dev/null @@ -1,40 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// Copyright (C) 2018 Deven Desai <deven.desai.amd@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#if defined(EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H) - -#undef gpuStream_t -#undef gpuDeviceProp_t -#undef gpuError_t -#undef gpuSuccess -#undef gpuErrorNotReady -#undef gpuGetDeviceCount -#undef gpuGetErrorString -#undef gpuGetDeviceProperties -#undef gpuStreamDefault -#undef gpuGetDevice -#undef gpuSetDevice -#undef gpuMalloc -#undef gpuFree -#undef gpuMemsetAsync -#undef gpuMemcpyAsync -#undef gpuMemcpyDeviceToDevice -#undef gpuMemcpyDeviceToHost -#undef gpuMemcpyHostToDevice -#undef gpuStreamQuery -#undef gpuSharedMemConfig -#undef gpuDeviceSetSharedMemConfig -#undef gpuStreamSynchronize -#undef gpuDeviceSynchronize -#undef gpuMemcpy - -#undef EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H - -#endif // EIGEN_CXX11_TENSOR_GPU_HIP_CUDA_DEFINES_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIO.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIO.h deleted file mode 100644 index a901c5dd..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIO.h +++ /dev/null @@ -1,79 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_IO_H -#define EIGEN_CXX11_TENSOR_TENSOR_IO_H - -namespace Eigen { - -namespace internal { - -// Print the tensor as a 2d matrix -template <typename Tensor, int Rank> -struct TensorPrinter { - static void run (std::ostream& os, const Tensor& tensor) { - typedef typename internal::remove_const<typename Tensor::Scalar>::type Scalar; - typedef typename Tensor::Index Index; - const Index total_size = internal::array_prod(tensor.dimensions()); - if (total_size > 0) { - const Index first_dim = Eigen::internal::array_get<0>(tensor.dimensions()); - static const int layout = Tensor::Layout; - Map<const Array<Scalar, Dynamic, Dynamic, layout> > matrix(const_cast<Scalar*>(tensor.data()), first_dim, total_size/first_dim); - os << matrix; - } - } -}; - - -// Print the tensor as a vector -template <typename Tensor> -struct TensorPrinter<Tensor, 1> { - static void run (std::ostream& os, const Tensor& tensor) { - typedef typename internal::remove_const<typename Tensor::Scalar>::type Scalar; - typedef typename Tensor::Index Index; - const Index total_size = internal::array_prod(tensor.dimensions()); - if (total_size > 0) { - Map<const Array<Scalar, Dynamic, 1> > array(const_cast<Scalar*>(tensor.data()), total_size); - os << array; - } - } -}; - - -// Print the tensor as a scalar -template <typename Tensor> -struct TensorPrinter<Tensor, 0> { - static void run (std::ostream& os, const Tensor& tensor) { - os << tensor.coeff(0); - } -}; -} - -template <typename T> -std::ostream& operator << (std::ostream& os, const TensorBase<T, ReadOnlyAccessors>& expr) { - typedef TensorEvaluator<const TensorForcedEvalOp<const T>, DefaultDevice> Evaluator; - typedef typename Evaluator::Dimensions Dimensions; - - // Evaluate the expression if needed - TensorForcedEvalOp<const T> eval = expr.eval(); - Evaluator tensor(eval, DefaultDevice()); - tensor.evalSubExprsIfNeeded(NULL); - - // Print the result - static const int rank = internal::array_size<Dimensions>::value; - internal::TensorPrinter<Evaluator, rank>::run(os, tensor); - - // Cleanup. - tensor.cleanup(); - return os; -} - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_IO_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorImagePatch.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorImagePatch.h deleted file mode 100644 index 49d1004f..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorImagePatch.h +++ /dev/null @@ -1,603 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_IMAGE_PATCH_H -#define EIGEN_CXX11_TENSOR_TENSOR_IMAGE_PATCH_H - -namespace Eigen { - -/** \class TensorImagePatch - * \ingroup CXX11_Tensor_Module - * - * \brief Patch extraction specialized for image processing. - * This assumes that the input has a least 3 dimensions ordered as follow: - * 1st dimension: channels (of size d) - * 2nd dimension: rows (of size r) - * 3rd dimension: columns (of size c) - * There can be additional dimensions such as time (for video) or batch (for - * bulk processing after the first 3. - * Calling the image patch code with patch_rows and patch_cols is equivalent - * to calling the regular patch extraction code with parameters d, patch_rows, - * patch_cols, and 1 for all the additional dimensions. - */ -namespace internal { - -template<DenseIndex Rows, DenseIndex Cols, typename XprType> -struct traits<TensorImagePatchOp<Rows, Cols, XprType> > : public traits<XprType> -{ - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions + 1; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<DenseIndex Rows, DenseIndex Cols, typename XprType> -struct eval<TensorImagePatchOp<Rows, Cols, XprType>, Eigen::Dense> -{ - typedef const TensorImagePatchOp<Rows, Cols, XprType>& type; -}; - -template<DenseIndex Rows, DenseIndex Cols, typename XprType> -struct nested<TensorImagePatchOp<Rows, Cols, XprType>, 1, typename eval<TensorImagePatchOp<Rows, Cols, XprType> >::type> -{ - typedef TensorImagePatchOp<Rows, Cols, XprType> type; -}; - -template <typename Self, bool Vectorizable> -struct ImagePatchCopyOp { - typedef typename Self::Index Index; - typedef typename Self::Scalar Scalar; - typedef typename Self::Impl Impl; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run( - const Self& self, const Index num_coeff_to_copy, const Index dst_index, - Scalar* dst_data, const Index src_index) { - const Impl& impl = self.impl(); - for (Index i = 0; i < num_coeff_to_copy; ++i) { - dst_data[dst_index + i] = impl.coeff(src_index + i); - } - } -}; - -template <typename Self> -struct ImagePatchCopyOp<Self, true> { - typedef typename Self::Index Index; - typedef typename Self::Scalar Scalar; - typedef typename Self::Impl Impl; - typedef typename packet_traits<Scalar>::type Packet; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run( - const Self& self, const Index num_coeff_to_copy, const Index dst_index, - Scalar* dst_data, const Index src_index) { - const Impl& impl = self.impl(); - const Index packet_size = internal::unpacket_traits<Packet>::size; - const Index vectorized_size = - (num_coeff_to_copy / packet_size) * packet_size; - for (Index i = 0; i < vectorized_size; i += packet_size) { - Packet p = impl.template packet<Unaligned>(src_index + i); - internal::pstoret<Scalar, Packet, Unaligned>(dst_data + dst_index + i, p); - } - for (Index i = vectorized_size; i < num_coeff_to_copy; ++i) { - dst_data[dst_index + i] = impl.coeff(src_index + i); - } - } -}; - -template <typename Self> -struct ImagePatchPaddingOp { - typedef typename Self::Index Index; - typedef typename Self::Scalar Scalar; - typedef typename packet_traits<Scalar>::type Packet; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run( - const Index num_coeff_to_pad, const Scalar padding_value, - const Index dst_index, Scalar* dst_data) { - const Index packet_size = internal::unpacket_traits<Packet>::size; - const Packet padded_packet = internal::pset1<Packet>(padding_value); - const Index vectorized_size = - (num_coeff_to_pad / packet_size) * packet_size; - for (Index i = 0; i < vectorized_size; i += packet_size) { - internal::pstoret<Scalar, Packet, Unaligned>(dst_data + dst_index + i, - padded_packet); - } - for (Index i = vectorized_size; i < num_coeff_to_pad; ++i) { - dst_data[dst_index + i] = padding_value; - } - } -}; - -} // end namespace internal - -template<DenseIndex Rows, DenseIndex Cols, typename XprType> -class TensorImagePatchOp : public TensorBase<TensorImagePatchOp<Rows, Cols, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorImagePatchOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorImagePatchOp>::type Nested; - typedef typename Eigen::internal::traits<TensorImagePatchOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorImagePatchOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorImagePatchOp(const XprType& expr, DenseIndex patch_rows, DenseIndex patch_cols, - DenseIndex row_strides, DenseIndex col_strides, - DenseIndex in_row_strides, DenseIndex in_col_strides, - DenseIndex row_inflate_strides, DenseIndex col_inflate_strides, - PaddingType padding_type, Scalar padding_value) - : m_xpr(expr), m_patch_rows(patch_rows), m_patch_cols(patch_cols), - m_row_strides(row_strides), m_col_strides(col_strides), - m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides), - m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides), - m_padding_explicit(false), m_padding_top(0), m_padding_bottom(0), m_padding_left(0), m_padding_right(0), - m_padding_type(padding_type), m_padding_value(padding_value) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorImagePatchOp(const XprType& expr, DenseIndex patch_rows, DenseIndex patch_cols, - DenseIndex row_strides, DenseIndex col_strides, - DenseIndex in_row_strides, DenseIndex in_col_strides, - DenseIndex row_inflate_strides, DenseIndex col_inflate_strides, - DenseIndex padding_top, DenseIndex padding_bottom, - DenseIndex padding_left, DenseIndex padding_right, - Scalar padding_value) - : m_xpr(expr), m_patch_rows(patch_rows), m_patch_cols(patch_cols), - m_row_strides(row_strides), m_col_strides(col_strides), - m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides), - m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides), - m_padding_explicit(true), m_padding_top(padding_top), m_padding_bottom(padding_bottom), - m_padding_left(padding_left), m_padding_right(padding_right), - m_padding_type(PADDING_VALID), m_padding_value(padding_value) {} - - - EIGEN_DEVICE_FUNC - DenseIndex patch_rows() const { return m_patch_rows; } - EIGEN_DEVICE_FUNC - DenseIndex patch_cols() const { return m_patch_cols; } - EIGEN_DEVICE_FUNC - DenseIndex row_strides() const { return m_row_strides; } - EIGEN_DEVICE_FUNC - DenseIndex col_strides() const { return m_col_strides; } - EIGEN_DEVICE_FUNC - DenseIndex in_row_strides() const { return m_in_row_strides; } - EIGEN_DEVICE_FUNC - DenseIndex in_col_strides() const { return m_in_col_strides; } - EIGEN_DEVICE_FUNC - DenseIndex row_inflate_strides() const { return m_row_inflate_strides; } - EIGEN_DEVICE_FUNC - DenseIndex col_inflate_strides() const { return m_col_inflate_strides; } - EIGEN_DEVICE_FUNC - bool padding_explicit() const { return m_padding_explicit; } - EIGEN_DEVICE_FUNC - DenseIndex padding_top() const { return m_padding_top; } - EIGEN_DEVICE_FUNC - DenseIndex padding_bottom() const { return m_padding_bottom; } - EIGEN_DEVICE_FUNC - DenseIndex padding_left() const { return m_padding_left; } - EIGEN_DEVICE_FUNC - DenseIndex padding_right() const { return m_padding_right; } - EIGEN_DEVICE_FUNC - PaddingType padding_type() const { return m_padding_type; } - EIGEN_DEVICE_FUNC - Scalar padding_value() const { return m_padding_value; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const DenseIndex m_patch_rows; - const DenseIndex m_patch_cols; - const DenseIndex m_row_strides; - const DenseIndex m_col_strides; - const DenseIndex m_in_row_strides; - const DenseIndex m_in_col_strides; - const DenseIndex m_row_inflate_strides; - const DenseIndex m_col_inflate_strides; - const bool m_padding_explicit; - const DenseIndex m_padding_top; - const DenseIndex m_padding_bottom; - const DenseIndex m_padding_left; - const DenseIndex m_padding_right; - const PaddingType m_padding_type; - const Scalar m_padding_value; -}; - -// Eval as rvalue -template<DenseIndex Rows, DenseIndex Cols, typename ArgType, typename Device> -struct TensorEvaluator<const TensorImagePatchOp<Rows, Cols, ArgType>, Device> -{ - typedef TensorImagePatchOp<Rows, Cols, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - static const int NumDims = NumInputDims + 1; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef TensorEvaluator<const TensorImagePatchOp<Rows, Cols, ArgType>, - Device> Self; - typedef TensorEvaluator<ArgType, Device> Impl; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator( const XprType& op, const Device& device) - : m_device(device), m_impl(op.expression(), device) - { - EIGEN_STATIC_ASSERT((NumDims >= 4), YOU_MADE_A_PROGRAMMING_MISTAKE); - - m_paddingValue = op.padding_value(); - - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - - // Caches a few variables. - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_inputDepth = input_dims[0]; - m_inputRows = input_dims[1]; - m_inputCols = input_dims[2]; - } else { - m_inputDepth = input_dims[NumInputDims-1]; - m_inputRows = input_dims[NumInputDims-2]; - m_inputCols = input_dims[NumInputDims-3]; - } - - m_row_strides = op.row_strides(); - m_col_strides = op.col_strides(); - - // Input strides and effective input/patch size - m_in_row_strides = op.in_row_strides(); - m_in_col_strides = op.in_col_strides(); - m_row_inflate_strides = op.row_inflate_strides(); - m_col_inflate_strides = op.col_inflate_strides(); - // The "effective" input rows and input cols are the input rows and cols - // after inflating them with zeros. - // For examples, a 2x3 matrix with row_inflate_strides and - // col_inflate_strides of 2 comes from: - // A B C - // D E F - // - // to a matrix is 3 x 5: - // - // A . B . C - // . . . . . - // D . E . F - - m_input_rows_eff = (m_inputRows - 1) * m_row_inflate_strides + 1; - m_input_cols_eff = (m_inputCols - 1) * m_col_inflate_strides + 1; - m_patch_rows_eff = op.patch_rows() + (op.patch_rows() - 1) * (m_in_row_strides - 1); - m_patch_cols_eff = op.patch_cols() + (op.patch_cols() - 1) * (m_in_col_strides - 1); - - if (op.padding_explicit()) { - m_outputRows = numext::ceil((m_input_rows_eff + op.padding_top() + op.padding_bottom() - m_patch_rows_eff + 1.f) / static_cast<float>(m_row_strides)); - m_outputCols = numext::ceil((m_input_cols_eff + op.padding_left() + op.padding_right() - m_patch_cols_eff + 1.f) / static_cast<float>(m_col_strides)); - m_rowPaddingTop = op.padding_top(); - m_colPaddingLeft = op.padding_left(); - } else { - // Computing padding from the type - switch (op.padding_type()) { - case PADDING_VALID: - m_outputRows = numext::ceil((m_input_rows_eff - m_patch_rows_eff + 1.f) / static_cast<float>(m_row_strides)); - m_outputCols = numext::ceil((m_input_cols_eff - m_patch_cols_eff + 1.f) / static_cast<float>(m_col_strides)); - // Calculate the padding - m_rowPaddingTop = numext::maxi<Index>(0, ((m_outputRows - 1) * m_row_strides + m_patch_rows_eff - m_input_rows_eff) / 2); - m_colPaddingLeft = numext::maxi<Index>(0, ((m_outputCols - 1) * m_col_strides + m_patch_cols_eff - m_input_cols_eff) / 2); - break; - case PADDING_SAME: - m_outputRows = numext::ceil(m_input_rows_eff / static_cast<float>(m_row_strides)); - m_outputCols = numext::ceil(m_input_cols_eff / static_cast<float>(m_col_strides)); - // Calculate the padding - m_rowPaddingTop = ((m_outputRows - 1) * m_row_strides + m_patch_rows_eff - m_input_rows_eff) / 2; - m_colPaddingLeft = ((m_outputCols - 1) * m_col_strides + m_patch_cols_eff - m_input_cols_eff) / 2; - // The padding size calculation for PADDING_SAME has been updated to - // be consistent with how TensorFlow extracts its paddings. - m_rowPaddingTop = numext::maxi<Index>(0, m_rowPaddingTop); - m_colPaddingLeft = numext::maxi<Index>(0, m_colPaddingLeft); - break; - default: - eigen_assert(false && "unexpected padding"); - m_outputCols=0; // silence the uninitialised warning; - m_outputRows=0; //// silence the uninitialised warning; - } - } - eigen_assert(m_outputRows > 0); - eigen_assert(m_outputCols > 0); - - // Dimensions for result of extraction. - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - // ColMajor - // 0: depth - // 1: patch_rows - // 2: patch_cols - // 3: number of patches - // 4 and beyond: anything else (such as batch). - m_dimensions[0] = input_dims[0]; - m_dimensions[1] = op.patch_rows(); - m_dimensions[2] = op.patch_cols(); - m_dimensions[3] = m_outputRows * m_outputCols; - for (int i = 4; i < NumDims; ++i) { - m_dimensions[i] = input_dims[i-1]; - } - } else { - // RowMajor - // NumDims-1: depth - // NumDims-2: patch_rows - // NumDims-3: patch_cols - // NumDims-4: number of patches - // NumDims-5 and beyond: anything else (such as batch). - m_dimensions[NumDims-1] = input_dims[NumInputDims-1]; - m_dimensions[NumDims-2] = op.patch_rows(); - m_dimensions[NumDims-3] = op.patch_cols(); - m_dimensions[NumDims-4] = m_outputRows * m_outputCols; - for (int i = NumDims-5; i >= 0; --i) { - m_dimensions[i] = input_dims[i]; - } - } - - // Strides for moving the patch in various dimensions. - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_colStride = m_dimensions[1]; - m_patchStride = m_colStride * m_dimensions[2] * m_dimensions[0]; - m_otherStride = m_patchStride * m_dimensions[3]; - } else { - m_colStride = m_dimensions[NumDims-2]; - m_patchStride = m_colStride * m_dimensions[NumDims-3] * m_dimensions[NumDims-1]; - m_otherStride = m_patchStride * m_dimensions[NumDims-4]; - } - - // Strides for navigating through the input tensor. - m_rowInputStride = m_inputDepth; - m_colInputStride = m_inputDepth * m_inputRows; - m_patchInputStride = m_inputDepth * m_inputRows * m_inputCols; - - // Fast representations of different variables. - m_fastOtherStride = internal::TensorIntDivisor<Index>(m_otherStride); - m_fastPatchStride = internal::TensorIntDivisor<Index>(m_patchStride); - m_fastColStride = internal::TensorIntDivisor<Index>(m_colStride); - m_fastInflateRowStride = internal::TensorIntDivisor<Index>(m_row_inflate_strides); - m_fastInflateColStride = internal::TensorIntDivisor<Index>(m_col_inflate_strides); - m_fastInputColsEff = internal::TensorIntDivisor<Index>(m_input_cols_eff); - - // Number of patches in the width dimension. - m_fastOutputRows = internal::TensorIntDivisor<Index>(m_outputRows); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[0]); - } else { - m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[NumDims-1]); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - m_impl.evalSubExprsIfNeededAsync(nullptr, [done](bool) { done(true); }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - // Patch index corresponding to the passed in index. - const Index patchIndex = index / m_fastPatchStride; - // Find the offset of the element wrt the location of the first element. - const Index patchOffset = (index - patchIndex * m_patchStride) / m_fastOutputDepth; - - // Other ways to index this element. - const Index otherIndex = (NumDims == 4) ? 0 : index / m_fastOtherStride; - const Index patch2DIndex = (NumDims == 4) ? patchIndex : (index - otherIndex * m_otherStride) / m_fastPatchStride; - - // Calculate col index in the input original tensor. - const Index colIndex = patch2DIndex / m_fastOutputRows; - const Index colOffset = patchOffset / m_fastColStride; - const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft; - const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInflateColStride) : 0); - if (inputCol < 0 || inputCol >= m_input_cols_eff || - ((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) { - return Scalar(m_paddingValue); - } - - // Calculate row index in the original input tensor. - const Index rowIndex = patch2DIndex - colIndex * m_outputRows; - const Index rowOffset = patchOffset - colOffset * m_colStride; - const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop; - const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInflateRowStride) : 0); - if (inputRow < 0 || inputRow >= m_input_rows_eff || - ((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) { - return Scalar(m_paddingValue); - } - - const int depth_index = static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1; - const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index]; - - const Index inputIndex = depth + origInputRow * m_rowInputStride + origInputCol * m_colInputStride + otherIndex * m_patchInputStride; - return m_impl.coeff(inputIndex); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - if (m_in_row_strides != 1 || m_in_col_strides != 1 || m_row_inflate_strides != 1 || m_col_inflate_strides != 1) { - return packetWithPossibleZero(index); - } - - const Index indices[2] = {index, index + PacketSize - 1}; - const Index patchIndex = indices[0] / m_fastPatchStride; - if (patchIndex != indices[1] / m_fastPatchStride) { - return packetWithPossibleZero(index); - } - const Index otherIndex = (NumDims == 4) ? 0 : indices[0] / m_fastOtherStride; - eigen_assert(otherIndex == indices[1] / m_fastOtherStride); - - // Find the offset of the element wrt the location of the first element. - const Index patchOffsets[2] = {(indices[0] - patchIndex * m_patchStride) / m_fastOutputDepth, - (indices[1] - patchIndex * m_patchStride) / m_fastOutputDepth}; - - const Index patch2DIndex = (NumDims == 4) ? patchIndex : (indices[0] - otherIndex * m_otherStride) / m_fastPatchStride; - eigen_assert(patch2DIndex == (indices[1] - otherIndex * m_otherStride) / m_fastPatchStride); - - const Index colIndex = patch2DIndex / m_fastOutputRows; - const Index colOffsets[2] = {patchOffsets[0] / m_fastColStride, patchOffsets[1] / m_fastColStride}; - - // Calculate col indices in the original input tensor. - const Index inputCols[2] = {colIndex * m_col_strides + colOffsets[0] - - m_colPaddingLeft, colIndex * m_col_strides + colOffsets[1] - m_colPaddingLeft}; - if (inputCols[1] < 0 || inputCols[0] >= m_inputCols) { - return internal::pset1<PacketReturnType>(Scalar(m_paddingValue)); - } - - if (inputCols[0] == inputCols[1]) { - const Index rowIndex = patch2DIndex - colIndex * m_outputRows; - const Index rowOffsets[2] = {patchOffsets[0] - colOffsets[0]*m_colStride, patchOffsets[1] - colOffsets[1]*m_colStride}; - eigen_assert(rowOffsets[0] <= rowOffsets[1]); - // Calculate col indices in the original input tensor. - const Index inputRows[2] = {rowIndex * m_row_strides + rowOffsets[0] - - m_rowPaddingTop, rowIndex * m_row_strides + rowOffsets[1] - m_rowPaddingTop}; - - if (inputRows[1] < 0 || inputRows[0] >= m_inputRows) { - return internal::pset1<PacketReturnType>(Scalar(m_paddingValue)); - } - - if (inputRows[0] >= 0 && inputRows[1] < m_inputRows) { - // no padding - const int depth_index = static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1; - const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index]; - const Index inputIndex = depth + inputRows[0] * m_rowInputStride + inputCols[0] * m_colInputStride + otherIndex * m_patchInputStride; - return m_impl.template packet<Unaligned>(inputIndex); - } - } - - return packetWithPossibleZero(index); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - Index rowPaddingTop() const { return m_rowPaddingTop; } - Index colPaddingLeft() const { return m_colPaddingLeft; } - Index outputRows() const { return m_outputRows; } - Index outputCols() const { return m_outputCols; } - Index userRowStride() const { return m_row_strides; } - Index userColStride() const { return m_col_strides; } - Index userInRowStride() const { return m_in_row_strides; } - Index userInColStride() const { return m_in_col_strides; } - Index rowInflateStride() const { return m_row_inflate_strides; } - Index colInflateStride() const { return m_col_inflate_strides; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - // We conservatively estimate the cost for the code path where the computed - // index is inside the original image and - // TensorEvaluator<ArgType, Device>::CoordAccess is false. - const double compute_cost = 3 * TensorOpCost::DivCost<Index>() + - 6 * TensorOpCost::MulCost<Index>() + - 8 * TensorOpCost::MulCost<Index>(); - return m_impl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, compute_cost, vectorized, PacketSize); - } - - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index) const - { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - - Dimensions m_dimensions; - - Index m_otherStride; - Index m_patchStride; - Index m_colStride; - Index m_row_strides; - Index m_col_strides; - - Index m_in_row_strides; - Index m_in_col_strides; - Index m_row_inflate_strides; - Index m_col_inflate_strides; - - Index m_input_rows_eff; - Index m_input_cols_eff; - Index m_patch_rows_eff; - Index m_patch_cols_eff; - - internal::TensorIntDivisor<Index> m_fastOtherStride; - internal::TensorIntDivisor<Index> m_fastPatchStride; - internal::TensorIntDivisor<Index> m_fastColStride; - internal::TensorIntDivisor<Index> m_fastInflateRowStride; - internal::TensorIntDivisor<Index> m_fastInflateColStride; - internal::TensorIntDivisor<Index> m_fastInputColsEff; - - Index m_rowInputStride; - Index m_colInputStride; - Index m_patchInputStride; - - Index m_inputDepth; - Index m_inputRows; - Index m_inputCols; - - Index m_outputRows; - Index m_outputCols; - - Index m_rowPaddingTop; - Index m_colPaddingLeft; - - internal::TensorIntDivisor<Index> m_fastOutputRows; - internal::TensorIntDivisor<Index> m_fastOutputDepth; - - Scalar m_paddingValue; - - const Device EIGEN_DEVICE_REF m_device; - TensorEvaluator<ArgType, Device> m_impl; -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_IMAGE_PATCH_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h deleted file mode 100644 index 2a3398d6..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h +++ /dev/null @@ -1,738 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H -#define EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H - - -#if EIGEN_HAS_CONSTEXPR && EIGEN_HAS_VARIADIC_TEMPLATES - -#define EIGEN_HAS_INDEX_LIST - -namespace Eigen { - -/** \internal - * - * \class TensorIndexList - * \ingroup CXX11_Tensor_Module - * - * \brief Set of classes used to encode a set of Tensor dimensions/indices. - * - * The indices in the list can be known at compile time or at runtime. A mix - * of static and dynamic indices can also be provided if needed. The tensor - * code will attempt to take advantage of the indices that are known at - * compile time to optimize the code it generates. - * - * This functionality requires a c++11 compliant compiler. If your compiler - * is older you need to use arrays of indices instead. - * - * Several examples are provided in the cxx11_tensor_index_list.cpp file. - * - * \sa Tensor - */ - -template <Index n> -struct type2index { - static const Index value = n; - EIGEN_DEVICE_FUNC constexpr operator Index() const { return n; } - EIGEN_DEVICE_FUNC void set(Index val) { - eigen_assert(val == n); - } -}; - -// This can be used with IndexPairList to get compile-time constant pairs, -// such as IndexPairList<type2indexpair<1,2>, type2indexpair<3,4>>(). -template <Index f, Index s> -struct type2indexpair { - static const Index first = f; - static const Index second = s; - - constexpr EIGEN_DEVICE_FUNC operator IndexPair<Index>() const { - return IndexPair<Index>(f, s); - } - - EIGEN_DEVICE_FUNC void set(const IndexPair<Index>& val) { - eigen_assert(val.first == f); - eigen_assert(val.second == s); - } -}; - - -template<Index n> struct NumTraits<type2index<n> > -{ - typedef Index Real; - enum { - IsComplex = 0, - RequireInitialization = false, - ReadCost = 1, - AddCost = 1, - MulCost = 1 - }; - - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Real epsilon() { return 0; } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Real dummy_precision() { return 0; } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Real highest() { return n; } - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Real lowest() { return n; } -}; - -namespace internal { -template <typename T> -EIGEN_DEVICE_FUNC void update_value(T& val, Index new_val) { - val = internal::convert_index<T>(new_val); -} -template <Index n> -EIGEN_DEVICE_FUNC void update_value(type2index<n>& val, Index new_val) { - val.set(new_val); -} - -template <typename T> -EIGEN_DEVICE_FUNC void update_value(T& val, IndexPair<Index> new_val) { - val = new_val; -} -template <Index f, Index s> -EIGEN_DEVICE_FUNC void update_value(type2indexpair<f, s>& val, IndexPair<Index> new_val) { - val.set(new_val); -} - - -template <typename T> -struct is_compile_time_constant { - static constexpr bool value = false; -}; - -template <Index idx> -struct is_compile_time_constant<type2index<idx> > { - static constexpr bool value = true; -}; -template <Index idx> -struct is_compile_time_constant<const type2index<idx> > { - static constexpr bool value = true; -}; -template <Index idx> -struct is_compile_time_constant<type2index<idx>& > { - static constexpr bool value = true; -}; -template <Index idx> -struct is_compile_time_constant<const type2index<idx>& > { - static constexpr bool value = true; -}; - -template <Index f, Index s> -struct is_compile_time_constant<type2indexpair<f, s> > { - static constexpr bool value = true; -}; -template <Index f, Index s> -struct is_compile_time_constant<const type2indexpair<f, s> > { - static constexpr bool value = true; -}; -template <Index f, Index s> -struct is_compile_time_constant<type2indexpair<f, s>& > { - static constexpr bool value = true; -}; -template <Index f, Index s> -struct is_compile_time_constant<const type2indexpair<f, s>& > { - static constexpr bool value = true; -}; - - -template<typename... T> -struct IndexTuple; - -template<typename T, typename... O> -struct IndexTuple<T, O...> { - EIGEN_DEVICE_FUNC constexpr IndexTuple() : head(), others() { } - EIGEN_DEVICE_FUNC constexpr IndexTuple(const T& v, const O... o) : head(v), others(o...) { } - - constexpr static int count = 1 + sizeof...(O); - T head; - IndexTuple<O...> others; - typedef T Head; - typedef IndexTuple<O...> Other; -}; - -template<typename T> - struct IndexTuple<T> { - EIGEN_DEVICE_FUNC constexpr IndexTuple() : head() { } - EIGEN_DEVICE_FUNC constexpr IndexTuple(const T& v) : head(v) { } - - constexpr static int count = 1; - T head; - typedef T Head; -}; - - -template<int N, typename... T> -struct IndexTupleExtractor; - -template<int N, typename T, typename... O> -struct IndexTupleExtractor<N, T, O...> { - - typedef typename IndexTupleExtractor<N-1, O...>::ValType ValType; - - EIGEN_DEVICE_FUNC static constexpr ValType& get_val(IndexTuple<T, O...>& val) { - return IndexTupleExtractor<N-1, O...>::get_val(val.others); - } - - EIGEN_DEVICE_FUNC static constexpr const ValType& get_val(const IndexTuple<T, O...>& val) { - return IndexTupleExtractor<N-1, O...>::get_val(val.others); - } - template <typename V> - EIGEN_DEVICE_FUNC static void set_val(IndexTuple<T, O...>& val, V& new_val) { - IndexTupleExtractor<N-1, O...>::set_val(val.others, new_val); - } - -}; - -template<typename T, typename... O> - struct IndexTupleExtractor<0, T, O...> { - - typedef T ValType; - - EIGEN_DEVICE_FUNC static constexpr ValType& get_val(IndexTuple<T, O...>& val) { - return val.head; - } - EIGEN_DEVICE_FUNC static constexpr const ValType& get_val(const IndexTuple<T, O...>& val) { - return val.head; - } - template <typename V> - EIGEN_DEVICE_FUNC static void set_val(IndexTuple<T, O...>& val, V& new_val) { - val.head = new_val; - } -}; - - - -template <int N, typename T, typename... O> -EIGEN_DEVICE_FUNC constexpr typename IndexTupleExtractor<N, T, O...>::ValType& array_get(IndexTuple<T, O...>& tuple) { - return IndexTupleExtractor<N, T, O...>::get_val(tuple); -} -template <int N, typename T, typename... O> -EIGEN_DEVICE_FUNC constexpr const typename IndexTupleExtractor<N, T, O...>::ValType& array_get(const IndexTuple<T, O...>& tuple) { - return IndexTupleExtractor<N, T, O...>::get_val(tuple); -} -template <typename T, typename... O> - struct array_size<IndexTuple<T, O...> > { - static const size_t value = IndexTuple<T, O...>::count; -}; -template <typename T, typename... O> - struct array_size<const IndexTuple<T, O...> > { - static const size_t value = IndexTuple<T, O...>::count; -}; - - - - -template <Index Idx, typename ValueT> -struct tuple_coeff { - template <typename... T> - EIGEN_DEVICE_FUNC static constexpr ValueT get(const Index i, const IndexTuple<T...>& t) { - // return array_get<Idx>(t) * (i == Idx) + tuple_coeff<Idx-1>::get(i, t) * (i != Idx); - return (i == Idx ? array_get<Idx>(t) : tuple_coeff<Idx-1, ValueT>::get(i, t)); - } - template <typename... T> - EIGEN_DEVICE_FUNC static void set(const Index i, IndexTuple<T...>& t, const ValueT& value) { - if (i == Idx) { - update_value(array_get<Idx>(t), value); - } else { - tuple_coeff<Idx-1, ValueT>::set(i, t, value); - } - } - - template <typename... T> - EIGEN_DEVICE_FUNC static constexpr bool value_known_statically(const Index i, const IndexTuple<T...>& t) { - return ((i == Idx) & is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value) || - tuple_coeff<Idx-1, ValueT>::value_known_statically(i, t); - } - - template <typename... T> - EIGEN_DEVICE_FUNC static constexpr bool values_up_to_known_statically(const IndexTuple<T...>& t) { - return is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value && - tuple_coeff<Idx-1, ValueT>::values_up_to_known_statically(t); - } - - template <typename... T> - EIGEN_DEVICE_FUNC static constexpr bool values_up_to_statically_known_to_increase(const IndexTuple<T...>& t) { - return is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value && - is_compile_time_constant<typename IndexTupleExtractor<Idx, T...>::ValType>::value && - array_get<Idx>(t) > array_get<Idx-1>(t) && - tuple_coeff<Idx-1, ValueT>::values_up_to_statically_known_to_increase(t); - } -}; - -template <typename ValueT> -struct tuple_coeff<0, ValueT> { - template <typename... T> - EIGEN_DEVICE_FUNC static constexpr ValueT get(const Index /*i*/, const IndexTuple<T...>& t) { - // eigen_assert (i == 0); // gcc fails to compile assertions in constexpr - return array_get<0>(t)/* * (i == 0)*/; - } - template <typename... T> - EIGEN_DEVICE_FUNC static void set(const Index i, IndexTuple<T...>& t, const ValueT value) { - eigen_assert (i == 0); - update_value(array_get<0>(t), value); - } - template <typename... T> - EIGEN_DEVICE_FUNC static constexpr bool value_known_statically(const Index i, const IndexTuple<T...>&) { - return is_compile_time_constant<typename IndexTupleExtractor<0, T...>::ValType>::value & (i == 0); - } - - template <typename... T> - EIGEN_DEVICE_FUNC static constexpr bool values_up_to_known_statically(const IndexTuple<T...>&) { - return is_compile_time_constant<typename IndexTupleExtractor<0, T...>::ValType>::value; - } - - template <typename... T> - EIGEN_DEVICE_FUNC static constexpr bool values_up_to_statically_known_to_increase(const IndexTuple<T...>&) { - return true; - } -}; -} // namespace internal - - - -template<typename FirstType, typename... OtherTypes> -struct IndexList : internal::IndexTuple<FirstType, OtherTypes...> { - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr Index operator[] (const Index i) const { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, Index>::get(i, *this); - } - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr Index get(const Index i) const { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, Index>::get(i, *this); - } - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC void set(const Index i, const Index value) { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, Index>::set(i, *this, value); - } - - EIGEN_DEVICE_FUNC constexpr IndexList(const internal::IndexTuple<FirstType, OtherTypes...>& other) : internal::IndexTuple<FirstType, OtherTypes...>(other) { } - EIGEN_DEVICE_FUNC constexpr IndexList(FirstType& first, OtherTypes... other) : internal::IndexTuple<FirstType, OtherTypes...>(first, other...) { } - EIGEN_DEVICE_FUNC constexpr IndexList() : internal::IndexTuple<FirstType, OtherTypes...>() { } - - EIGEN_DEVICE_FUNC constexpr bool value_known_statically(const Index i) const { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, Index>::value_known_statically(i, *this); - } - EIGEN_DEVICE_FUNC constexpr bool all_values_known_statically() const { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, Index>::values_up_to_known_statically(*this); - } - - EIGEN_DEVICE_FUNC constexpr bool values_statically_known_to_increase() const { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, Index>::values_up_to_statically_known_to_increase(*this); - } -}; - -template <typename FirstType, typename... OtherTypes> -std::ostream& operator<<(std::ostream& os, - const IndexList<FirstType, OtherTypes...>& dims) { - os << "["; - for (size_t i = 0; i < 1 + sizeof...(OtherTypes); ++i) { - if (i > 0) os << ", "; - os << dims[i]; - } - os << "]"; - return os; -} - -template<typename FirstType, typename... OtherTypes> -constexpr IndexList<FirstType, OtherTypes...> make_index_list(FirstType val1, OtherTypes... other_vals) { - return IndexList<FirstType, OtherTypes...>(val1, other_vals...); -} - - -template<typename FirstType, typename... OtherTypes> -struct IndexPairList : internal::IndexTuple<FirstType, OtherTypes...> { - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr IndexPair<Index> operator[] (const Index i) const { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, IndexPair<Index>>::get(i, *this); - } - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC void set(const Index i, const IndexPair<Index> value) { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...>>::value-1, IndexPair<Index> >::set(i, *this, value); - } - - EIGEN_DEVICE_FUNC constexpr IndexPairList(const internal::IndexTuple<FirstType, OtherTypes...>& other) : internal::IndexTuple<FirstType, OtherTypes...>(other) { } - EIGEN_DEVICE_FUNC constexpr IndexPairList() : internal::IndexTuple<FirstType, OtherTypes...>() { } - - EIGEN_DEVICE_FUNC constexpr bool value_known_statically(const Index i) const { - return internal::tuple_coeff<internal::array_size<internal::IndexTuple<FirstType, OtherTypes...> >::value-1, Index>::value_known_statically(i, *this); - } -}; - -namespace internal { - -template<typename FirstType, typename... OtherTypes> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index array_prod(const IndexList<FirstType, OtherTypes...>& sizes) { - Index result = 1; - EIGEN_UNROLL_LOOP - for (size_t i = 0; i < array_size<IndexList<FirstType, OtherTypes...> >::value; ++i) { - result *= sizes[i]; - } - return result; -} - -template<typename FirstType, typename... OtherTypes> struct array_size<IndexList<FirstType, OtherTypes...> > { - static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >::value; -}; -template<typename FirstType, typename... OtherTypes> struct array_size<const IndexList<FirstType, OtherTypes...> > { - static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...> >::value; -}; - -template<typename FirstType, typename... OtherTypes> struct array_size<IndexPairList<FirstType, OtherTypes...> > { - static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value; -}; -template<typename FirstType, typename... OtherTypes> struct array_size<const IndexPairList<FirstType, OtherTypes...> > { - static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value; -}; - -template<Index N, typename FirstType, typename... OtherTypes> EIGEN_DEVICE_FUNC constexpr Index array_get(IndexList<FirstType, OtherTypes...>& a) { - return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(a); -} -template<Index N, typename FirstType, typename... OtherTypes> EIGEN_DEVICE_FUNC constexpr Index array_get(const IndexList<FirstType, OtherTypes...>& a) { - return IndexTupleExtractor<N, FirstType, OtherTypes...>::get_val(a); -} - -template <typename T> -struct index_known_statically_impl { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index) { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_known_statically_impl<IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i); - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_known_statically_impl<const IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i); - } -}; - - -template <typename T> -struct all_indices_known_statically_impl { - static constexpr bool run() { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> -struct all_indices_known_statically_impl<IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return IndexList<FirstType, OtherTypes...>().all_values_known_statically(); - } -}; - -template <typename FirstType, typename... OtherTypes> -struct all_indices_known_statically_impl<const IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return IndexList<FirstType, OtherTypes...>().all_values_known_statically(); - } -}; - - -template <typename T> -struct indices_statically_known_to_increase_impl { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> - struct indices_statically_known_to_increase_impl<IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase(); - } -}; - -template <typename FirstType, typename... OtherTypes> - struct indices_statically_known_to_increase_impl<const IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run() { - return Eigen::IndexList<FirstType, OtherTypes...>().values_statically_known_to_increase(); - } -}; - - -template <typename Tx> -struct index_statically_eq_impl { - EIGEN_DEVICE_FUNC static constexpr bool run(Index, Index) { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_statically_eq_impl<IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexList<FirstType, OtherTypes...>().get(i) == value); - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_statically_eq_impl<const IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexList<FirstType, OtherTypes...>().get(i) == value); - } -}; - - -template <typename T> -struct index_statically_ne_impl { - EIGEN_DEVICE_FUNC static constexpr bool run(Index, Index) { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_statically_ne_impl<IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexList<FirstType, OtherTypes...>().get(i) != value); - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_statically_ne_impl<const IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexList<FirstType, OtherTypes...>().get(i) != value); - } -}; - - -template <typename T> -struct index_statically_gt_impl { - EIGEN_DEVICE_FUNC static constexpr bool run(Index, Index) { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_statically_gt_impl<IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexList<FirstType, OtherTypes...>().get(i) > value); - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_statically_gt_impl<const IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexList<FirstType, OtherTypes...>().get(i) > value); - } -}; - - - -template <typename T> -struct index_statically_lt_impl { - EIGEN_DEVICE_FUNC static constexpr bool run(Index, Index) { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_statically_lt_impl<IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexList<FirstType, OtherTypes...>().get(i) < value); - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_statically_lt_impl<const IndexList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexList<FirstType, OtherTypes...>().get(i) < value); - } -}; - - - -template <typename Tx> -struct index_pair_first_statically_eq_impl { - EIGEN_DEVICE_FUNC static constexpr bool run(Index, Index) { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_pair_first_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexPairList<FirstType, OtherTypes...>().operator[](i).first == value); - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_pair_first_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexPairList<FirstType, OtherTypes...>().operator[](i).first == value); - } -}; - - - -template <typename Tx> -struct index_pair_second_statically_eq_impl { - EIGEN_DEVICE_FUNC static constexpr bool run(Index, Index) { - return false; - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_pair_second_statically_eq_impl<IndexPairList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexPairList<FirstType, OtherTypes...>().operator[](i).second == value); - } -}; - -template <typename FirstType, typename... OtherTypes> -struct index_pair_second_statically_eq_impl<const IndexPairList<FirstType, OtherTypes...> > { - EIGEN_DEVICE_FUNC static constexpr bool run(const Index i, const Index value) { - return IndexPairList<FirstType, OtherTypes...>().value_known_statically(i) & - (IndexPairList<FirstType, OtherTypes...>().operator[](i).second == value); - } -}; - - -} // end namespace internal -} // end namespace Eigen - -#else - -namespace Eigen { -namespace internal { - -template <typename T> -struct index_known_statically_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const Index) { - return false; - } -}; - -template <typename T> -struct all_indices_known_statically_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() { - return false; - } -}; - -template <typename T> -struct indices_statically_known_to_increase_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() { - return false; - } -}; - -template <typename T> -struct index_statically_eq_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(Index, Index) { - return false; - } -}; - -template <typename T> -struct index_statically_ne_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(Index, Index) { - return false; - } -}; - -template <typename T> -struct index_statically_gt_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(Index, Index) { - return false; - } -}; - -template <typename T> -struct index_statically_lt_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(Index, Index) { - return false; - } -}; - -template <typename Tx> -struct index_pair_first_statically_eq_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(Index, Index) { - return false; - } -}; - -template <typename Tx> -struct index_pair_second_statically_eq_impl { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(Index, Index) { - return false; - } -}; - - - -} // end namespace internal -} // end namespace Eigen - -#endif - - -namespace Eigen { -namespace internal { -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_known_statically(Index i) { - return index_known_statically_impl<T>::run(i); -} - -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool all_indices_known_statically() { - return all_indices_known_statically_impl<T>::run(); -} - -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool indices_statically_known_to_increase() { - return indices_statically_known_to_increase_impl<T>::run(); -} - -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_eq(Index i, Index value) { - return index_statically_eq_impl<T>::run(i, value); -} - -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_ne(Index i, Index value) { - return index_statically_ne_impl<T>::run(i, value); -} - -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_gt(Index i, Index value) { - return index_statically_gt_impl<T>::run(i, value); -} - -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_statically_lt(Index i, Index value) { - return index_statically_lt_impl<T>::run(i, value); -} - -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_pair_first_statically_eq(Index i, Index value) { - return index_pair_first_statically_eq_impl<T>::run(i, value); -} - -template <typename T> -static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bool index_pair_second_statically_eq(Index i, Index value) { - return index_pair_second_statically_eq_impl<T>::run(i, value); -} - -} // end namespace internal -} // end namespace Eigen - - -#endif // EIGEN_CXX11_TENSOR_TENSOR_INDEX_LIST_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorInflation.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorInflation.h deleted file mode 100644 index 7dadec7f..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorInflation.h +++ /dev/null @@ -1,247 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Ke Yang <yangke@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H -#define EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H - -namespace Eigen { - -/** \class TensorInflation - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor inflation class. - * - * - */ -namespace internal { -template<typename Strides, typename XprType> -struct traits<TensorInflationOp<Strides, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename Strides, typename XprType> -struct eval<TensorInflationOp<Strides, XprType>, Eigen::Dense> -{ - typedef const TensorInflationOp<Strides, XprType>& type; -}; - -template<typename Strides, typename XprType> -struct nested<TensorInflationOp<Strides, XprType>, 1, typename eval<TensorInflationOp<Strides, XprType> >::type> -{ - typedef TensorInflationOp<Strides, XprType> type; -}; - -} // end namespace internal - -template<typename Strides, typename XprType> -class TensorInflationOp : public TensorBase<TensorInflationOp<Strides, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorInflationOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorInflationOp>::type Nested; - typedef typename Eigen::internal::traits<TensorInflationOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorInflationOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorInflationOp(const XprType& expr, const Strides& strides) - : m_xpr(expr), m_strides(strides) {} - - EIGEN_DEVICE_FUNC - const Strides& strides() const { return m_strides; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const Strides m_strides; -}; - -// Eval as rvalue -template<typename Strides, typename ArgType, typename Device> -struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device> -{ - typedef TensorInflationOp<Strides, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = /*TensorEvaluator<ArgType, Device>::IsAligned*/ false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_strides(op.strides()) - { - m_dimensions = m_impl.dimensions(); - // Expand each dimension to the inflated dimension. - for (int i = 0; i < NumDims; ++i) { - m_dimensions[i] = (m_dimensions[i] - 1) * op.strides()[i] + 1; - } - - // Remember the strides for fast division. - for (int i = 0; i < NumDims; ++i) { - m_fastStrides[i] = internal::TensorIntDivisor<Index>(m_strides[i]); - } - - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_outputStrides[0] = 1; - m_inputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1]; - m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1]; - } - } else { // RowMajor - m_outputStrides[NumDims-1] = 1; - m_inputStrides[NumDims-1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1]; - m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1]; - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - // Computes the input index given the output index. Returns true if the output - // index doesn't fall into a hole. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool getInputIndex(Index index, Index* inputIndex) const - { - eigen_assert(index < dimensions().TotalSize()); - *inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_outputStrides[i]; - if (idx != idx / m_fastStrides[i] * m_strides[i]) { - return false; - } - *inputIndex += idx / m_strides[i] * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - if (index != index / m_fastStrides[0] * m_strides[0]) { - return false; - } - *inputIndex += index / m_strides[0]; - return true; - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_outputStrides[i]; - if (idx != idx / m_fastStrides[i] * m_strides[i]) { - return false; - } - *inputIndex += idx / m_strides[i] * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - if (index != index / m_fastStrides[NumDims-1] * m_strides[NumDims-1]) { - return false; - } - *inputIndex += index / m_strides[NumDims - 1]; - } - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - Index inputIndex = 0; - if (getInputIndex(index, &inputIndex)) { - return m_impl.coeff(inputIndex); - } else { - return Scalar(0); - } - } - - // TODO(yangke): optimize this function so that we can detect and produce - // all-zero packets - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - const double compute_cost = NumDims * (3 * TensorOpCost::DivCost<Index>() + - 3 * TensorOpCost::MulCost<Index>() + - 2 * TensorOpCost::AddCost<Index>()); - const double input_size = m_impl.dimensions().TotalSize(); - const double output_size = m_dimensions.TotalSize(); - if (output_size == 0) - return TensorOpCost(); - return m_impl.costPerCoeff(vectorized) + - TensorOpCost(sizeof(CoeffReturnType) * input_size / output_size, 0, - compute_cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - protected: - Dimensions m_dimensions; - array<Index, NumDims> m_outputStrides; - array<Index, NumDims> m_inputStrides; - TensorEvaluator<ArgType, Device> m_impl; - const Strides m_strides; - array<internal::TensorIntDivisor<Index>, NumDims> m_fastStrides; -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorInitializer.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorInitializer.h deleted file mode 100644 index 33edc49e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorInitializer.h +++ /dev/null @@ -1,82 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_INITIALIZER_H -#define EIGEN_CXX11_TENSOR_TENSOR_INITIALIZER_H - -#if EIGEN_HAS_VARIADIC_TEMPLATES - -#include <initializer_list> - -namespace Eigen { - -/** \class TensorInitializer - * \ingroup CXX11_Tensor_Module - * - * \brief Helper template to initialize Tensors from std::initializer_lists. - */ -namespace internal { - -template <typename Derived, int N> -struct Initializer { - typedef std::initializer_list< - typename Initializer<Derived, N - 1>::InitList> InitList; - - static void run(TensorEvaluator<Derived, DefaultDevice>& tensor, - Eigen::array<typename traits<Derived>::Index, traits<Derived>::NumDimensions>* indices, - const InitList& vals) { - int i = 0; - for (auto v : vals) { - (*indices)[traits<Derived>::NumDimensions - N] = i++; - Initializer<Derived, N - 1>::run(tensor, indices, v); - } - } -}; - -template <typename Derived> -struct Initializer<Derived, 1> { - typedef std::initializer_list<typename traits<Derived>::Scalar> InitList; - - static void run(TensorEvaluator<Derived, DefaultDevice>& tensor, - Eigen::array<typename traits<Derived>::Index, traits<Derived>::NumDimensions>* indices, - const InitList& vals) { - int i = 0; - // There is likely a faster way to do that than iterating. - for (auto v : vals) { - (*indices)[traits<Derived>::NumDimensions - 1] = i++; - tensor.coeffRef(*indices) = v; - } - } -}; - -template <typename Derived> -struct Initializer<Derived, 0> { - typedef typename traits<Derived>::Scalar InitList; - - static void run(TensorEvaluator<Derived, DefaultDevice>& tensor, - Eigen::array<typename traits<Derived>::Index, traits<Derived>::NumDimensions>*, - const InitList& v) { - tensor.coeffRef(0) = v; - } -}; - - -template <typename Derived, int N> -void initialize_tensor(TensorEvaluator<Derived, DefaultDevice>& tensor, - const typename Initializer<Derived, traits<Derived>::NumDimensions>::InitList& vals) { - Eigen::array<typename traits<Derived>::Index, traits<Derived>::NumDimensions> indices; - Initializer<Derived, traits<Derived>::NumDimensions>::run(tensor, &indices, vals); -} - -} // namespace internal -} // namespace Eigen - -#endif // EIGEN_HAS_VARIADIC_TEMPLATES - -#endif // EIGEN_CXX11_TENSOR_TENSOR_INITIALIZER_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h deleted file mode 100644 index 6d5cce4a..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h +++ /dev/null @@ -1,263 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_INTDIV_H -#define EIGEN_CXX11_TENSOR_TENSOR_INTDIV_H - - -namespace Eigen { - -/** \internal - * - * \class TensorIntDiv - * \ingroup CXX11_Tensor_Module - * - * \brief Fast integer division by a constant. - * - * See the paper from Granlund and Montgomery for explanation. - * (at https://doi.org/10.1145/773473.178249) - * - * \sa Tensor - */ - -namespace internal { - -namespace { - - // Note: result is undefined if val == 0 - template <typename T> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - typename internal::enable_if<sizeof(T)==4,int>::type count_leading_zeros(const T val) - { -#ifdef EIGEN_GPU_COMPILE_PHASE - return __clz(val); -#elif defined(SYCL_DEVICE_ONLY) - return cl::sycl::clz(val); -#elif EIGEN_COMP_MSVC - unsigned long index; - _BitScanReverse(&index, val); - return 31 - index; -#else - EIGEN_STATIC_ASSERT(sizeof(unsigned long long) == 8, YOU_MADE_A_PROGRAMMING_MISTAKE); - return __builtin_clz(static_cast<uint32_t>(val)); -#endif - } - - template <typename T> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - typename internal::enable_if<sizeof(T)==8,int>::type count_leading_zeros(const T val) - { -#ifdef EIGEN_GPU_COMPILE_PHASE - return __clzll(val); -#elif defined(SYCL_DEVICE_ONLY) - return static_cast<int>(cl::sycl::clz(val)); -#elif EIGEN_COMP_MSVC && EIGEN_ARCH_x86_64 - unsigned long index; - _BitScanReverse64(&index, val); - return 63 - index; -#elif EIGEN_COMP_MSVC - // MSVC's _BitScanReverse64 is not available for 32bits builds. - unsigned int lo = (unsigned int)(val&0xffffffff); - unsigned int hi = (unsigned int)((val>>32)&0xffffffff); - int n; - if(hi==0) - n = 32 + count_leading_zeros<unsigned int>(lo); - else - n = count_leading_zeros<unsigned int>(hi); - return n; -#else - EIGEN_STATIC_ASSERT(sizeof(unsigned long long) == 8, YOU_MADE_A_PROGRAMMING_MISTAKE); - return __builtin_clzll(static_cast<uint64_t>(val)); -#endif - } - - template <typename T> - struct UnsignedTraits { - typedef typename conditional<sizeof(T) == 8, uint64_t, uint32_t>::type type; - }; - - template <typename T> - struct DividerTraits { - typedef typename UnsignedTraits<T>::type type; - static const int N = sizeof(T) * 8; - }; - - template <typename T> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE uint32_t muluh(const uint32_t a, const T b) { -#if defined(EIGEN_GPU_COMPILE_PHASE) - return __umulhi(a, b); -#elif defined(SYCL_DEVICE_ONLY) - return cl::sycl::mul_hi(a, static_cast<uint32_t>(b)); -#else - return (static_cast<uint64_t>(a) * b) >> 32; -#endif - } - - template <typename T> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE uint64_t muluh(const uint64_t a, const T b) { -#if defined(EIGEN_GPU_COMPILE_PHASE) - return __umul64hi(a, b); -#elif defined(SYCL_DEVICE_ONLY) - return cl::sycl::mul_hi(a, static_cast<uint64_t>(b)); -#elif EIGEN_HAS_BUILTIN_INT128 - __uint128_t v = static_cast<__uint128_t>(a) * static_cast<__uint128_t>(b); - return static_cast<uint64_t>(v >> 64); -#else - return (TensorUInt128<static_val<0>, uint64_t>(a) * TensorUInt128<static_val<0>, uint64_t>(b)).upper(); -#endif - } - - template <int N, typename T> - struct DividerHelper { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE uint32_t computeMultiplier(const int log_div, const T divider) { - EIGEN_STATIC_ASSERT(N == 32, YOU_MADE_A_PROGRAMMING_MISTAKE); - return static_cast<uint32_t>((static_cast<uint64_t>(1) << (N+log_div)) / divider - (static_cast<uint64_t>(1) << N) + 1); - } - }; - - template <typename T> - struct DividerHelper<64, T> { - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE uint64_t computeMultiplier(const int log_div, const T divider) { -#if EIGEN_HAS_BUILTIN_INT128 && !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(SYCL_DEVICE_ONLY) - return static_cast<uint64_t>((static_cast<__uint128_t>(1) << (64+log_div)) / static_cast<__uint128_t>(divider) - (static_cast<__uint128_t>(1) << 64) + 1); -#else - const uint64_t shift = 1ULL << log_div; - TensorUInt128<uint64_t, uint64_t> result = TensorUInt128<uint64_t, static_val<0> >(shift, 0) / TensorUInt128<static_val<0>, uint64_t>(divider) - - TensorUInt128<static_val<1>, static_val<0> >(1, 0) - + TensorUInt128<static_val<0>, static_val<1> >(1); - return static_cast<uint64_t>(result); -#endif - } - }; -} - - -template <typename T, bool div_gt_one = false> -struct TensorIntDivisor { - public: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorIntDivisor() { - multiplier = 0; - shift1 = 0; - shift2 = 0; - } - - // Must have 0 < divider < 2^31. This is relaxed to - // 0 < divider < 2^63 when using 64-bit indices on platforms that support - // the __uint128_t type. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorIntDivisor(const T divider) { - const int N = DividerTraits<T>::N; - eigen_assert(static_cast<typename UnsignedTraits<T>::type>(divider) < NumTraits<UnsignedType>::highest()/2); - eigen_assert(divider > 0); - - // fast ln2 - const int leading_zeros = count_leading_zeros(static_cast<UnsignedType>(divider)); - int log_div = N - leading_zeros; - // if divider is a power of two then log_div is 1 more than it should be. - if ((static_cast<typename UnsignedTraits<T>::type>(1) << (log_div-1)) == static_cast<typename UnsignedTraits<T>::type>(divider)) - log_div--; - - multiplier = DividerHelper<N, T>::computeMultiplier(log_div, divider); - shift1 = log_div > 1 ? 1 : log_div; - shift2 = log_div > 1 ? log_div-1 : 0; - } - - // Must have 0 <= numerator. On platforms that don't support the __uint128_t - // type numerator should also be less than 2^32-1. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T divide(const T numerator) const { - eigen_assert(static_cast<typename UnsignedTraits<T>::type>(numerator) < NumTraits<UnsignedType>::highest()/2); - //eigen_assert(numerator >= 0); // this is implicitly asserted by the line above - - UnsignedType t1 = muluh(multiplier, numerator); - UnsignedType t = (static_cast<UnsignedType>(numerator) - t1) >> shift1; - return (t1 + t) >> shift2; - } - - private: - typedef typename DividerTraits<T>::type UnsignedType; - UnsignedType multiplier; - int32_t shift1; - int32_t shift2; -}; - - -// Optimized version for signed 32 bit integers. -// Derived from Hacker's Delight. -// Only works for divisors strictly greater than one -template <> -class TensorIntDivisor<int32_t, true> { - public: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorIntDivisor() { - magic = 0; - shift = 0; - } - // Must have 2 <= divider - EIGEN_DEVICE_FUNC TensorIntDivisor(int32_t divider) { - eigen_assert(divider >= 2); - calcMagic(divider); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE int divide(const int32_t n) const { -#ifdef EIGEN_GPU_COMPILE_PHASE - return (__umulhi(magic, n) >> shift); -#elif defined(SYCL_DEVICE_ONLY) - return (cl::sycl::mul_hi(magic, static_cast<uint32_t>(n)) >> shift); -#else - uint64_t v = static_cast<uint64_t>(magic) * static_cast<uint64_t>(n); - return (static_cast<uint32_t>(v >> 32) >> shift); -#endif - } - -private: - // Compute the magic numbers. See Hacker's Delight section 10 for an in - // depth explanation. - EIGEN_DEVICE_FUNC void calcMagic(int32_t d) { - const unsigned two31 = 0x80000000; // 2**31. - unsigned ad = d; - unsigned t = two31 + (ad >> 31); - unsigned anc = t - 1 - t%ad; // Absolute value of nc. - int p = 31; // Init. p. - unsigned q1 = two31/anc; // Init. q1 = 2**p/|nc|. - unsigned r1 = two31 - q1*anc; // Init. r1 = rem(2**p, |nc|). - unsigned q2 = two31/ad; // Init. q2 = 2**p/|d|. - unsigned r2 = two31 - q2*ad; // Init. r2 = rem(2**p, |d|). - unsigned delta = 0; - do { - p = p + 1; - q1 = 2*q1; // Update q1 = 2**p/|nc|. - r1 = 2*r1; // Update r1 = rem(2**p, |nc|). - if (r1 >= anc) { // (Must be an unsigned - q1 = q1 + 1; // comparison here). - r1 = r1 - anc;} - q2 = 2*q2; // Update q2 = 2**p/|d|. - r2 = 2*r2; // Update r2 = rem(2**p, |d|). - if (r2 >= ad) { // (Must be an unsigned - q2 = q2 + 1; // comparison here). - r2 = r2 - ad;} - delta = ad - r2; - } while (q1 < delta || (q1 == delta && r1 == 0)); - - magic = (unsigned)(q2 + 1); - shift = p - 32; - } - - uint32_t magic; - int32_t shift; -}; - - -template <typename T, bool div_gt_one> -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator / (const T& numerator, const TensorIntDivisor<T, div_gt_one>& divisor) { - return divisor.divide(numerator); -} - - -} // end namespace internal -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_INTDIV_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorLayoutSwap.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorLayoutSwap.h deleted file mode 100644 index 05fa80e5..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorLayoutSwap.h +++ /dev/null @@ -1,233 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_LAYOUT_SWAP_H -#define EIGEN_CXX11_TENSOR_TENSOR_LAYOUT_SWAP_H - -namespace Eigen { - -/** \class TensorLayoutSwap - * \ingroup CXX11_Tensor_Module - * - * \brief Swap the layout from col-major to row-major, or row-major - * to col-major, and invert the order of the dimensions. - * - * Beware: the dimensions are reversed by this operation. If you want to - * preserve the ordering of the dimensions, you need to combine this - * operation with a shuffle. - * - * \example: - * Tensor<float, 2, ColMajor> input(2, 4); - * Tensor<float, 2, RowMajor> output = input.swap_layout(); - * eigen_assert(output.dimension(0) == 4); - * eigen_assert(output.dimension(1) == 2); - * - * array<int, 2> shuffle(1, 0); - * output = input.swap_layout().shuffle(shuffle); - * eigen_assert(output.dimension(0) == 2); - * eigen_assert(output.dimension(1) == 4); - * - */ -namespace internal { -template<typename XprType> -struct traits<TensorLayoutSwapOp<XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = traits<XprType>::NumDimensions; - static const int Layout = (traits<XprType>::Layout == ColMajor) ? RowMajor : ColMajor; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename XprType> -struct eval<TensorLayoutSwapOp<XprType>, Eigen::Dense> -{ - typedef const TensorLayoutSwapOp<XprType>& type; -}; - -template<typename XprType> -struct nested<TensorLayoutSwapOp<XprType>, 1, typename eval<TensorLayoutSwapOp<XprType> >::type> -{ - typedef TensorLayoutSwapOp<XprType> type; -}; - -} // end namespace internal - - - -template<typename XprType> -class TensorLayoutSwapOp : public TensorBase<TensorLayoutSwapOp<XprType>, WriteAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorLayoutSwapOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename Eigen::internal::nested<TensorLayoutSwapOp>::type Nested; - typedef typename Eigen::internal::traits<TensorLayoutSwapOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorLayoutSwapOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorLayoutSwapOp(const XprType& expr) - : m_xpr(expr) {} - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorLayoutSwapOp& operator = (const TensorLayoutSwapOp& other) - { - typedef TensorAssignOp<TensorLayoutSwapOp, const TensorLayoutSwapOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorLayoutSwapOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorLayoutSwapOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - protected: - typename XprType::Nested m_xpr; -}; - - -// Eval as rvalue -template<typename ArgType, typename Device> -struct TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device> -{ - typedef TensorLayoutSwapOp<ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - - enum { - IsAligned = TensorEvaluator<ArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = (static_cast<int>(TensorEvaluator<ArgType, Device>::Layout) == static_cast<int>(ColMajor)) ? RowMajor : ColMajor, - CoordAccess = false, // to be implemented - RawAccess = TensorEvaluator<ArgType, Device>::RawAccess - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device) - { - for(int i = 0; i < NumDims; ++i) { - m_dimensions[i] = m_impl.dimensions()[NumDims-1-i]; - } - } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - return m_impl.evalSubExprsIfNeeded(data); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return m_impl.coeff(index); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - return m_impl.template packet<LoadMode>(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - return m_impl.costPerCoeff(vectorized); - } - - EIGEN_DEVICE_FUNC typename Storage::Type data() const { - return constCast(m_impl.data()); - } - - const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; } - - protected: - TensorEvaluator<ArgType, Device> m_impl; - Dimensions m_dimensions; -}; - - -// Eval as lvalue -template<typename ArgType, typename Device> - struct TensorEvaluator<TensorLayoutSwapOp<ArgType>, Device> - : public TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device> -{ - typedef TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device> Base; - typedef TensorLayoutSwapOp<ArgType> XprType; - - enum { - IsAligned = TensorEvaluator<ArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = (static_cast<int>(TensorEvaluator<ArgType, Device>::Layout) == static_cast<int>(ColMajor)) ? RowMajor : ColMajor, - CoordAccess = false // to be implemented - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : Base(op, device) - { } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index) - { - return this->m_impl.coeffRef(index); - } - template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) - { - this->m_impl.template writePacket<StoreMode>(index, x); - } -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_LAYOUT_SWAP_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h deleted file mode 100644 index af9e5db7..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h +++ /dev/null @@ -1,93 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_META_MACROS_H -#define EIGEN_CXX11_TENSOR_TENSOR_META_MACROS_H - - -/** use this macro in sfinae selection in templated functions - * - * template<typename T, - * typename std::enable_if< isBanana<T>::value , int >::type = 0 - * > - * void foo(){} - * - * becomes => - * - * template<typename TopoType, - * SFINAE_ENABLE_IF( isBanana<T>::value ) - * > - * void foo(){} - */ - -// SFINAE requires variadic templates -#if !defined(EIGEN_GPUCC) -#if EIGEN_HAS_VARIADIC_TEMPLATES - // SFINAE doesn't work for gcc <= 4.7 - #ifdef EIGEN_COMP_GNUC - #if EIGEN_GNUC_AT_LEAST(4,8) - #define EIGEN_HAS_SFINAE - #endif - #else - #define EIGEN_HAS_SFINAE - #endif -#endif -#endif - -#define EIGEN_SFINAE_ENABLE_IF( __condition__ ) \ - typename internal::enable_if< ( __condition__ ) , int >::type = 0 - - -#if EIGEN_HAS_CONSTEXPR -#define EIGEN_CONSTEXPR constexpr -#else -#define EIGEN_CONSTEXPR -#endif - - -#if EIGEN_OS_WIN || EIGEN_OS_WIN64 -#define EIGEN_SLEEP(n) Sleep(n) -#elif EIGEN_OS_GNULINUX -#define EIGEN_SLEEP(n) usleep(n * 1000); -#else -#define EIGEN_SLEEP(n) sleep(std::max<unsigned>(1, n/1000)) -#endif - -// Define a macro to use a reference on the host but a value on the device -#if defined(SYCL_DEVICE_ONLY) - #define EIGEN_DEVICE_REF -#else - #define EIGEN_DEVICE_REF & -#endif - -// Define a macro for catching SYCL exceptions if exceptions are enabled -#define EIGEN_SYCL_TRY_CATCH(X) \ - do { \ - EIGEN_TRY {X;} \ - EIGEN_CATCH(const cl::sycl::exception& e) { \ - EIGEN_THROW_X(std::runtime_error("SYCL exception at " + \ - std::string(__FILE__) + ":" + \ - std::to_string(__LINE__) + "\n" + \ - e.what())); \ - } \ - } while (false) - -// Define a macro if local memory flags are unset or one of them is set -// Setting both flags is the same as unsetting them -#if (!defined(EIGEN_SYCL_LOCAL_MEM) && !defined(EIGEN_SYCL_NO_LOCAL_MEM)) || \ - (defined(EIGEN_SYCL_LOCAL_MEM) && defined(EIGEN_SYCL_NO_LOCAL_MEM)) - #define EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON 1 - #define EIGEN_SYCL_LOCAL_MEM_UNSET_OR_OFF 1 -#elif defined(EIGEN_SYCL_LOCAL_MEM) && !defined(EIGEN_SYCL_NO_LOCAL_MEM) - #define EIGEN_SYCL_LOCAL_MEM_UNSET_OR_ON 1 -#elif !defined(EIGEN_SYCL_LOCAL_MEM) && defined(EIGEN_SYCL_NO_LOCAL_MEM) - #define EIGEN_SYCL_LOCAL_MEM_UNSET_OR_OFF 1 -#endif - -#endif diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMap.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMap.h deleted file mode 100644 index 172a6bab..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMap.h +++ /dev/null @@ -1,343 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_MAP_H -#define EIGEN_CXX11_TENSOR_TENSOR_MAP_H - -namespace Eigen { - -// FIXME use proper doxygen documentation (e.g. \tparam MakePointer_) - -/** \class TensorMap - * \ingroup CXX11_Tensor_Module - * - * \brief A tensor expression mapping an existing array of data. - * - */ -/// `template <class> class MakePointer_` is added to convert the host pointer to the device pointer. -/// It is added due to the fact that for our device compiler `T*` is not allowed. -/// If we wanted to use the same Evaluator functions we have to convert that type to our pointer `T`. -/// This is done through our `MakePointer_` class. By default the Type in the `MakePointer_<T>` is `T*` . -/// Therefore, by adding the default value, we managed to convert the type and it does not break any -/// existing code as its default value is `T*`. -template<typename PlainObjectType, int Options_, template <class> class MakePointer_> class TensorMap : public TensorBase<TensorMap<PlainObjectType, Options_, MakePointer_> > -{ - public: - typedef TensorMap<PlainObjectType, Options_, MakePointer_> Self; - typedef typename PlainObjectType::Base Base; - #ifdef EIGEN_USE_SYCL - typedef typename Eigen::internal::remove_reference<typename Eigen::internal::nested<Self>::type>::type Nested; - #else - typedef typename Eigen::internal::nested<Self>::type Nested; - #endif - typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind; - typedef typename internal::traits<PlainObjectType>::Index Index; - typedef typename internal::traits<PlainObjectType>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef typename Base::CoeffReturnType CoeffReturnType; - - typedef typename MakePointer_<Scalar>::Type PointerType; - typedef typename MakePointer_<Scalar>::ConstType PointerConstType; - - // WARN: PointerType still can be a pointer to const (const Scalar*), for - // example in TensorMap<Tensor<const Scalar, ...>> expression. This type of - // expression should be illegal, but adding this restriction is not possible - // in practice (see https://bitbucket.org/eigen/eigen/pull-requests/488). - typedef typename internal::conditional< - bool(internal::is_lvalue<PlainObjectType>::value), - PointerType, // use simple pointer in lvalue expressions - PointerConstType // use const pointer in rvalue expressions - >::type StoragePointerType; - - // If TensorMap was constructed over rvalue expression (e.g. const Tensor), - // we should return a reference to const from operator() (and others), even - // if TensorMap itself is not const. - typedef typename internal::conditional< - bool(internal::is_lvalue<PlainObjectType>::value), - Scalar&, - const Scalar& - >::type StorageRefType; - - static const int Options = Options_; - - static const Index NumIndices = PlainObjectType::NumIndices; - typedef typename PlainObjectType::Dimensions Dimensions; - - enum { - IsAligned = ((int(Options_)&Aligned)==Aligned), - Layout = PlainObjectType::Layout, - CoordAccess = true, - RawAccess = true - }; - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr) : m_data(dataPtr), m_dimensions() { - // The number of dimensions used to construct a tensor must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE) - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index firstDimension, IndexTypes... otherDimensions) : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) { - // The number of dimensions used to construct a tensor must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT((sizeof...(otherDimensions) + 1 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE) - } -#else - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index firstDimension) : m_data(dataPtr), m_dimensions(firstDimension) { - // The number of dimensions used to construct a tensor must be equal to the rank of the tensor. - EIGEN_STATIC_ASSERT((1 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE) - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index dim1, Index dim2) : m_data(dataPtr), m_dimensions(dim1, dim2) { - EIGEN_STATIC_ASSERT(2 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE) - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index dim1, Index dim2, Index dim3) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3) { - EIGEN_STATIC_ASSERT(3 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE) - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index dim1, Index dim2, Index dim3, Index dim4) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3, dim4) { - EIGEN_STATIC_ASSERT(4 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE) - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index dim1, Index dim2, Index dim3, Index dim4, Index dim5) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3, dim4, dim5) { - EIGEN_STATIC_ASSERT(5 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE) - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, const array<Index, NumIndices>& dimensions) - : m_data(dataPtr), m_dimensions(dimensions) - { } - - template <typename Dimensions> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, const Dimensions& dimensions) - : m_data(dataPtr), m_dimensions(dimensions) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PlainObjectType& tensor) - : m_data(tensor.data()), m_dimensions(tensor.dimensions()) - { } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index rank() const { return m_dimensions.rank(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index dimension(Index n) const { return m_dimensions[n]; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index size() const { return m_dimensions.TotalSize(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StoragePointerType data() { return m_data; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StoragePointerType data() const { return m_data; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(const array<Index, NumIndices>& indices) const - { - // eigen_assert(checkIndexRange(indices)); - if (PlainObjectType::Options&RowMajor) { - const Index index = m_dimensions.IndexOfRowMajor(indices); - return m_data[index]; - } else { - const Index index = m_dimensions.IndexOfColMajor(indices); - return m_data[index]; - } - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()() const - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE) - return m_data[0]; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index index) const - { - eigen_internal_assert(index >= 0 && index < size()); - return m_data[index]; - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) const - { - EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(internal::all((Eigen::NumTraits<Index>::highest() >= otherIndices)...)); - if (PlainObjectType::Options&RowMajor) { - const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}}); - return m_data[index]; - } else { - const Index index = m_dimensions.IndexOfColMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}}); - return m_data[index]; - } - } -#else - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1) const - { - if (PlainObjectType::Options&RowMajor) { - const Index index = i1 + i0 * m_dimensions[1]; - return m_data[index]; - } else { - const Index index = i0 + i1 * m_dimensions[0]; - return m_data[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2) const - { - if (PlainObjectType::Options&RowMajor) { - const Index index = i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0); - return m_data[index]; - } else { - const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * i2); - return m_data[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2, Index i3) const - { - if (PlainObjectType::Options&RowMajor) { - const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)); - return m_data[index]; - } else { - const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3)); - return m_data[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2, Index i3, Index i4) const - { - if (PlainObjectType::Options&RowMajor) { - const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0))); - return m_data[index]; - } else { - const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4))); - return m_data[index]; - } - } -#endif - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(const array<Index, NumIndices>& indices) - { - // eigen_assert(checkIndexRange(indices)); - if (PlainObjectType::Options&RowMajor) { - const Index index = m_dimensions.IndexOfRowMajor(indices); - return m_data[index]; - } else { - const Index index = m_dimensions.IndexOfColMajor(indices); - return m_data[index]; - } - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()() - { - EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE) - return m_data[0]; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index index) - { - eigen_internal_assert(index >= 0 && index < size()); - return m_data[index]; - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) - { - static_assert(sizeof...(otherIndices) + 2 == NumIndices || NumIndices == Dynamic, "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor."); - eigen_assert(internal::all((Eigen::NumTraits<Index>::highest() >= otherIndices)...)); - const std::size_t NumDims = sizeof...(otherIndices) + 2; - if (PlainObjectType::Options&RowMajor) { - const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}}); - return m_data[index]; - } else { - const Index index = m_dimensions.IndexOfColMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}}); - return m_data[index]; - } - } -#else - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1) - { - if (PlainObjectType::Options&RowMajor) { - const Index index = i1 + i0 * m_dimensions[1]; - return m_data[index]; - } else { - const Index index = i0 + i1 * m_dimensions[0]; - return m_data[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2) - { - if (PlainObjectType::Options&RowMajor) { - const Index index = i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0); - return m_data[index]; - } else { - const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * i2); - return m_data[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2, Index i3) - { - if (PlainObjectType::Options&RowMajor) { - const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)); - return m_data[index]; - } else { - const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3)); - return m_data[index]; - } - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2, Index i3, Index i4) - { - if (PlainObjectType::Options&RowMajor) { - const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0))); - return m_data[index]; - } else { - const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4))); - return m_data[index]; - } - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Self& operator=(const Self& other) - { - typedef TensorAssignOp<Self, const Self> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Self& operator=(const OtherDerived& other) - { - typedef TensorAssignOp<Self, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - private: - StoragePointerType m_data; - Dimensions m_dimensions; -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_MAP_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h deleted file mode 100644 index 6afc9887..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h +++ /dev/null @@ -1,319 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_META_H -#define EIGEN_CXX11_TENSOR_TENSOR_META_H - -namespace Eigen { - -template<bool cond> struct Cond {}; - -template<typename T1, typename T2> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -const T1& choose(Cond<true>, const T1& first, const T2&) { - return first; -} - -template<typename T1, typename T2> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -const T2& choose(Cond<false>, const T1&, const T2& second) { - return second; -} - - -template <typename T, typename X, typename Y> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T divup(const X x, const Y y) { - return static_cast<T>((x + y - 1) / y); -} - -template <typename T> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T divup(const T x, const T y) { - return static_cast<T>((x + y - 1) / y); -} - -template <size_t n> struct max_n_1 { - static const size_t size = n; -}; -template <> struct max_n_1<0> { - static const size_t size = 1; -}; - - -// Default packet types -template <typename Scalar, typename Device> -struct PacketType : internal::packet_traits<Scalar> { - typedef typename internal::packet_traits<Scalar>::type type; -}; - -// For CUDA packet types when using a GpuDevice -#if defined(EIGEN_USE_GPU) && defined(EIGEN_HAS_GPU_FP16) -template <> -struct PacketType<half, GpuDevice> { - typedef half2 type; - static const int size = 2; - enum { - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasNegate = 1, - HasAbs = 1, - HasArg = 0, - HasAbs2 = 0, - HasMin = 1, - HasMax = 1, - HasConj = 0, - HasSetLinear = 0, - HasBlend = 0, - - HasDiv = 1, - HasSqrt = 1, - HasRsqrt = 1, - HasExp = 1, - HasExpm1 = 0, - HasLog = 1, - HasLog1p = 0, - HasLog10 = 0, - HasPow = 1, - }; -}; -#endif - -#if defined(EIGEN_USE_SYCL) - -namespace TensorSycl { -namespace internal { - -template <typename Index, Index A, Index B> struct PlusOp { - static constexpr Index Value = A + B; -}; - -template <typename Index, Index A, Index B> struct DivOp { - static constexpr Index Value = A / B; -}; - -template <typename Index, Index start, Index end, Index step, - template <class Indx, Indx...> class StepOp> -struct static_for { - template <typename UnaryOperator> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void loop(UnaryOperator op) { - op(start); - static_for<Index, StepOp<Index, start, step>::Value, end, step, - StepOp>::loop(op); - } -}; -template <typename Index, Index end, Index step, - template <class Indx, Indx...> class StepOp> -struct static_for<Index, end, end, step, StepOp> { - template <typename UnaryOperator> - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void loop(UnaryOperator) {} -}; - -template <typename OutScalar, typename Device, bool Vectorizable> -struct Vectorise { - static const int PacketSize = 1; - typedef OutScalar PacketReturnType; -}; - -template <typename OutScalar, typename Device> -struct Vectorise<OutScalar, Device, true> { - static const int PacketSize = Eigen::PacketType<OutScalar, Device>::size; - typedef typename Eigen::PacketType<OutScalar, Device>::type PacketReturnType; -}; - -static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Index roundUp(Index x, Index y) { - return ((((x) + (y)-1) / (y)) * (y)); -} - -} // namespace internal -} // namespace TensorSycl - -template <> - struct PacketType<half, SyclDevice> { - typedef half type; - static const int size = 1; - enum { - HasAdd = 0, - HasSub = 0, - HasMul = 0, - HasNegate = 0, - HasAbs = 0, - HasArg = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasConj = 0, - HasSetLinear = 0, - HasBlend = 0 - }; -}; -template <typename Scalar> -struct PacketType<Scalar, SyclDevice> : internal::default_packet_traits { - typedef Scalar type; - typedef Scalar half; - enum { - Vectorizable = 0, - size = 1, - AlignedOnScalar = 0, - HasHalfPacket = 0 - }; - enum { - HasAdd = 0, - HasSub = 0, - HasMul = 0, - HasNegate = 0, - HasAbs = 0, - HasAbs2 = 0, - HasMin = 0, - HasMax = 0, - HasConj = 0, - HasSetLinear = 0 - }; - -}; - -template <typename Scalar> -struct PacketType<Scalar, const SyclDevice> : PacketType<Scalar, SyclDevice>{}; - -#ifndef EIGEN_DONT_VECTORIZE_SYCL -#define PACKET_TYPE(CVQual, Type, val, lengths, DEV)\ -template<> struct PacketType<CVQual Type, DEV> : internal::sycl_packet_traits<val, lengths> \ -{\ - typedef typename internal::packet_traits<Type>::type type;\ - typedef typename internal::packet_traits<Type>::half half;\ -}; - - -PACKET_TYPE(const, float, 1, 4, SyclDevice) -PACKET_TYPE(, float, 1, 4, SyclDevice) -PACKET_TYPE(const, float, 1, 4, const SyclDevice) -PACKET_TYPE(, float, 1, 4, const SyclDevice) - -PACKET_TYPE(const, double, 0, 2, SyclDevice) -PACKET_TYPE(, double, 0, 2, SyclDevice) -PACKET_TYPE(const, double, 0, 2, const SyclDevice) -PACKET_TYPE(, double, 0, 2, const SyclDevice) -#undef PACKET_TYPE - -template<> struct PacketType<half, const SyclDevice>: PacketType<half, SyclDevice>{}; -template<> struct PacketType<const half, const SyclDevice>: PacketType<half, SyclDevice>{}; -#endif -#endif - -// Tuple mimics std::pair but works on e.g. nvcc. -template <typename U, typename V> struct Tuple { - public: - U first; - V second; - - typedef U first_type; - typedef V second_type; - - EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Tuple() : first(), second() {} - - EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Tuple(const U& f, const V& s) : first(f), second(s) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Tuple& operator= (const Tuple& rhs) { - #ifndef SYCL_DEVICE_ONLY - if (&rhs == this) return *this; - #endif - first = rhs.first; - second = rhs.second; - return *this; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void swap(Tuple& rhs) { - using numext::swap; - swap(first, rhs.first); - swap(second, rhs.second); - } -}; - -template <typename U, typename V> -EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -bool operator==(const Tuple<U, V>& x, const Tuple<U, V>& y) { - return (x.first == y.first && x.second == y.second); -} - -template <typename U, typename V> -EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -bool operator!=(const Tuple<U, V>& x, const Tuple<U, V>& y) { - return !(x == y); -} - - -// Can't use std::pairs on cuda devices -template <typename Idx> struct IndexPair { - EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair() : first(0), second(0) {} - EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair(Idx f, Idx s) : first(f), second(s) {} - - EIGEN_DEVICE_FUNC void set(IndexPair<Idx> val) { - first = val.first; - second = val.second; - } - - Idx first; - Idx second; -}; - - -#ifdef EIGEN_HAS_SFINAE -namespace internal { - - template<typename IndexType, typename Index, Index... Is> - EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - array<Index, sizeof...(Is)> customIndices2Array(IndexType& idx, numeric_list<Index, Is...>) { - return { idx[Is]... }; - } - template<typename IndexType, typename Index> - EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - array<Index, 0> customIndices2Array(IndexType&, numeric_list<Index>) { - return array<Index, 0>(); - } - - /** Make an array (for index/dimensions) out of a custom index */ - template<typename Index, std::size_t NumIndices, typename IndexType> - EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - array<Index, NumIndices> customIndices2Array(IndexType& idx) { - return customIndices2Array(idx, typename gen_numeric_list<Index, NumIndices>::type{}); - } - - - template <typename B, typename D> - struct is_base_of - { - - typedef char (&yes)[1]; - typedef char (&no)[2]; - - template <typename BB, typename DD> - struct Host - { - operator BB*() const; - operator DD*(); - }; - - template<typename T> - static yes check(D*, T); - static no check(B*, int); - - static const bool value = sizeof(check(Host<B,D>(), int())) == sizeof(yes); - }; - -} -#endif - - - -} // namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_META_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h deleted file mode 100644 index 879a67ea..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h +++ /dev/null @@ -1,1152 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_MORPHING_H -#define EIGEN_CXX11_TENSOR_TENSOR_MORPHING_H - -namespace Eigen { - -/** \class TensorReshaping - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor reshaping class. - * - * - */ -namespace internal { -template<typename NewDimensions, typename XprType> -struct traits<TensorReshapingOp<NewDimensions, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = array_size<NewDimensions>::value; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename NewDimensions, typename XprType> -struct eval<TensorReshapingOp<NewDimensions, XprType>, Eigen::Dense> -{ - typedef const TensorReshapingOp<NewDimensions, XprType>EIGEN_DEVICE_REF type; -}; - -template<typename NewDimensions, typename XprType> -struct nested<TensorReshapingOp<NewDimensions, XprType>, 1, typename eval<TensorReshapingOp<NewDimensions, XprType> >::type> -{ - typedef TensorReshapingOp<NewDimensions, XprType> type; -}; - -} // end namespace internal - - - -template<typename NewDimensions, typename XprType> -class TensorReshapingOp : public TensorBase<TensorReshapingOp<NewDimensions, XprType>, WriteAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorReshapingOp>::Scalar Scalar; - typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename Eigen::internal::nested<TensorReshapingOp>::type Nested; - typedef typename Eigen::internal::traits<TensorReshapingOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorReshapingOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorReshapingOp(const XprType& expr, const NewDimensions& dims) - : m_xpr(expr), m_dims(dims) {} - - EIGEN_DEVICE_FUNC - const NewDimensions& dimensions() const { return m_dims; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorReshapingOp& operator = (const TensorReshapingOp& other) - { - typedef TensorAssignOp<TensorReshapingOp, const TensorReshapingOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorReshapingOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorReshapingOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - protected: - typename XprType::Nested m_xpr; - const NewDimensions m_dims; -}; - - -// Eval as rvalue -template<typename NewDimensions, typename ArgType, typename Device> -struct TensorEvaluator<const TensorReshapingOp<NewDimensions, ArgType>, Device> -{ - typedef TensorReshapingOp<NewDimensions, ArgType> XprType; - typedef NewDimensions Dimensions; - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - typedef StorageMemory<typename internal::remove_const<CoeffReturnType>::type, Device> ConstCastStorage; - - static const int NumOutputDims = internal::array_size<Dimensions>::value; - static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - - enum ReshapingKind { - // We do not use layout information to determine reshaping kind. - // Depending on the layout `N` can be inner or outer dimension. - OneByN = 0, // expr.reshape(1, N) - NByOne = 1, // expr.reshape(N, 1) - Runtime = 2 // Reshape dimensions are dynamic (specified at runtime). - }; - - // clang-format off - static const ReshapingKind kind = -#if defined(EIGEN_HAS_INDEX_LIST) - (NumOutputDims == 2 && internal::index_statically_eq<NewDimensions>(/*index=*/0, /*value=*/1)) ? OneByN - : (NumOutputDims == 2 && internal::index_statically_eq<NewDimensions>(/*index=*/1, /*value=*/1)) ? NByOne - : Runtime; -#else - Runtime; -#endif - // clang-format on - - enum { - IsAligned = TensorEvaluator<ArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - // For trivial reshapes with raw access to underlying data we will provide - // zero overhead block access. - // TODO(ezhulenev): Consider adding block access without raw access? - BlockAccess = TensorEvaluator<ArgType, Device>::RawAccess && - NumInputDims > 0 && NumOutputDims > 0, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = TensorEvaluator<ArgType, Device>::RawAccess - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumOutputDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef - typename internal::TensorMaterializedBlock<ScalarNoConst, NumOutputDims, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_dimensions(op.dimensions()) - { - // The total size of the reshaped tensor must be equal to the total size - // of the input tensor. - eigen_assert(internal::array_prod(m_impl.dimensions()) == internal::array_prod(op.dimensions())); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType data, EvalSubExprsCallback done) { - m_impl.evalSubExprsIfNeededAsync(data, std::move(done)); - } -#endif - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - return m_impl.evalSubExprsIfNeeded(data); - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return m_impl.coeff(index); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - return m_impl.template packet<LoadMode>(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - return m_impl.costPerCoeff(vectorized); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - return internal::TensorBlockResourceRequirements::any(); - } - - // required in block(OutputTensorBlock* output_block) const - // For C++03 compatibility this must be defined outside the method - struct BlockIteratorState { - Index stride; - Index span; - Index size; - Index count; - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - eigen_assert(m_impl.data() != NULL); - eigen_assert((kind == Runtime) || - (kind == OneByN && desc.dimensions()[0] == 1) || - (kind == NByOne && desc.dimensions()[1] == 1)); - - if (kind == OneByN || kind == NByOne) { - // We can guarantee at compile time that block is just a contiguous slice - // of the underlying expression memory buffer. - return TensorBlock(internal::TensorBlockKind::kView, - m_impl.data() + desc.offset(), desc.dimensions()); - } else { - // This will do additional runtime checks, and in the end it might be also - // a view, or it might be a block materialized in the temporary buffer. - return TensorBlock::materialize(m_impl.data(), m_dimensions, desc, - scratch); - } - } - - EIGEN_DEVICE_FUNC typename Storage::Type data() const { - return constCast(m_impl.data()); - } - - EIGEN_DEVICE_FUNC const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; } - - #ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } - #endif - protected: - TensorEvaluator<ArgType, Device> m_impl; - NewDimensions m_dimensions; -}; - - -// Eval as lvalue -template<typename NewDimensions, typename ArgType, typename Device> - struct TensorEvaluator<TensorReshapingOp<NewDimensions, ArgType>, Device> - : public TensorEvaluator<const TensorReshapingOp<NewDimensions, ArgType>, Device> - -{ - typedef TensorEvaluator<const TensorReshapingOp<NewDimensions, ArgType>, Device> Base; - typedef TensorReshapingOp<NewDimensions, ArgType> XprType; - typedef NewDimensions Dimensions; - - enum { - IsAligned = TensorEvaluator<ArgType, Device>::IsAligned, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = TensorEvaluator<ArgType, Device>::RawAccess, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = TensorEvaluator<ArgType, Device>::RawAccess - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : Base(op, device) - { } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<TensorEvaluator::NumOutputDims, Index> - TensorBlockDesc; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index) - { - return this->m_impl.coeffRef(index); - } - - template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) - { - this->m_impl.template writePacket<StoreMode>(index, x); - } - - template <typename TensorBlock> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writeBlock( - const TensorBlockDesc& desc, const TensorBlock& block) { - assert(this->m_impl.data() != NULL); - - typedef typename TensorBlock::XprType TensorBlockExpr; - typedef internal::TensorBlockAssignment< - Scalar, TensorEvaluator::NumOutputDims, TensorBlockExpr, Index> - TensorBlockAssign; - - TensorBlockAssign::Run( - TensorBlockAssign::target(desc.dimensions(), - internal::strides<Layout>(this->dimensions()), - this->m_impl.data(), desc.offset()), - block.expr()); - } -}; - - -/** \class TensorSlicing - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor slicing class. - * - * - */ -namespace internal { -template<typename StartIndices, typename Sizes, typename XprType> -struct traits<TensorSlicingOp<StartIndices, Sizes, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = array_size<StartIndices>::value; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename StartIndices, typename Sizes, typename XprType> -struct eval<TensorSlicingOp<StartIndices, Sizes, XprType>, Eigen::Dense> -{ - typedef const TensorSlicingOp<StartIndices, Sizes, XprType>EIGEN_DEVICE_REF type; -}; - -template<typename StartIndices, typename Sizes, typename XprType> -struct nested<TensorSlicingOp<StartIndices, Sizes, XprType>, 1, typename eval<TensorSlicingOp<StartIndices, Sizes, XprType> >::type> -{ - typedef TensorSlicingOp<StartIndices, Sizes, XprType> type; -}; - -} // end namespace internal - - - -template<typename StartIndices, typename Sizes, typename XprType> -class TensorSlicingOp : public TensorBase<TensorSlicingOp<StartIndices, Sizes, XprType> > -{ - public: - typedef typename Eigen::internal::traits<TensorSlicingOp>::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorSlicingOp>::type Nested; - typedef typename Eigen::internal::traits<TensorSlicingOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorSlicingOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorSlicingOp(const XprType& expr, const StartIndices& indices, const Sizes& sizes) - : m_xpr(expr), m_indices(indices), m_sizes(sizes) {} - - EIGEN_DEVICE_FUNC - const StartIndices& startIndices() const { return m_indices; } - EIGEN_DEVICE_FUNC - const Sizes& sizes() const { return m_sizes; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorSlicingOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorSlicingOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorSlicingOp& operator = (const TensorSlicingOp& other) - { - typedef TensorAssignOp<TensorSlicingOp, const TensorSlicingOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - - protected: - typename XprType::Nested m_xpr; - const StartIndices m_indices; - const Sizes m_sizes; -}; - - -// Fixme: figure out the exact threshold -namespace { -template <typename Index, typename Device, bool BlockAccess> struct MemcpyTriggerForSlicing { - EIGEN_DEVICE_FUNC MemcpyTriggerForSlicing(const Device& device) : threshold_(2 * device.numThreads()) { } - EIGEN_DEVICE_FUNC bool operator ()(Index total, Index contiguous) const { - const bool prefer_block_evaluation = BlockAccess && total > 32*1024; - return !prefer_block_evaluation && contiguous > threshold_; - } - - private: - Index threshold_; -}; - -// It is very expensive to start the memcpy kernel on GPU: we therefore only -// use it for large copies. -#ifdef EIGEN_USE_GPU -template <typename Index, bool BlockAccess> struct MemcpyTriggerForSlicing<Index, GpuDevice, BlockAccess> { - EIGEN_DEVICE_FUNC MemcpyTriggerForSlicing(const GpuDevice&) { } - EIGEN_DEVICE_FUNC bool operator ()(Index, Index contiguous) const { return contiguous > 4*1024*1024; } -}; -#endif - -// It is very expensive to start the memcpy kernel on GPU: we therefore only -// use it for large copies. -#ifdef EIGEN_USE_SYCL -template <typename Index, bool BlockAccess> struct MemcpyTriggerForSlicing<Index, Eigen::SyclDevice, BlockAccess> { - EIGEN_DEVICE_FUNC MemcpyTriggerForSlicing(const SyclDevice&) { } - EIGEN_DEVICE_FUNC bool operator ()(Index, Index contiguous) const { return contiguous > 4*1024*1024; } -}; -#endif - -} - -// Eval as rvalue -template<typename StartIndices, typename Sizes, typename ArgType, typename Device> -struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Device> -{ - typedef TensorSlicingOp<StartIndices, Sizes, ArgType> XprType; - static const int NumDims = internal::array_size<Sizes>::value; - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef Sizes Dimensions; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef StorageMemory<typename internal::remove_const<CoeffReturnType>::type, Device> ConstCastStorage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - // Alignment can't be guaranteed at compile time since it depends on the - // slice offsets and sizes. - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = TensorEvaluator<ArgType, Device>::BlockAccess, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, - RawAccess = false - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - // Tensor slicing does not change the block type. - typedef typename TensorEvaluator<const ArgType, Device>::TensorBlock - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_device(device), m_dimensions(op.sizes()), m_offsets(op.startIndices()) - { - for (Index i = 0; i < internal::array_size<Dimensions>::value; ++i) { - eigen_assert(m_impl.dimensions()[i] >= op.sizes()[i] + op.startIndices()[i]); - } - - m_is_identity = true; - for (int i = 0; i < internal::array_size<Dimensions>::value; ++i) { - eigen_assert(m_impl.dimensions()[i] >= - op.sizes()[i] + op.startIndices()[i]); - if (m_impl.dimensions()[i] != op.sizes()[i] || - op.startIndices()[i] != 0) { - m_is_identity = false; - } - } - - // No strides for scalars. - if (NumDims == 0) return; - - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - const Sizes& output_dims = op.sizes(); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_inputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1]; - } - - // Don't initialize m_fastOutputStrides[0] since it won't ever be accessed. - m_outputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_outputStrides[i] = m_outputStrides[i-1] * output_dims[i-1]; - m_fastOutputStrides[i] = internal::TensorIntDivisor<Index>(m_outputStrides[i]); - } - } else { - m_inputStrides[NumDims-1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1]; - } - - // Don't initialize m_fastOutputStrides[NumDims-1] since it won't ever be accessed. - m_outputStrides[NumDims-1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_outputStrides[i] = m_outputStrides[i+1] * output_dims[i+1]; - m_fastOutputStrides[i] = internal::TensorIntDivisor<Index>(m_outputStrides[i]); - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - m_impl.evalSubExprsIfNeeded(NULL); - if (!NumTraits<typename internal::remove_const<Scalar>::type>::RequireInitialization - && data && m_impl.data()) { - Index contiguous_values = 1; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = 0; i < NumDims; ++i) { - contiguous_values *= dimensions()[i]; - if (dimensions()[i] != m_impl.dimensions()[i]) { - break; - } - } - } else { - for (int i = NumDims-1; i >= 0; --i) { - contiguous_values *= dimensions()[i]; - if (dimensions()[i] != m_impl.dimensions()[i]) { - break; - } - } - } - // Use memcpy if it's going to be faster than using the regular evaluation. - const MemcpyTriggerForSlicing<Index, Device, BlockAccess> trigger(m_device); - if (trigger(internal::array_prod(dimensions()), contiguous_values)) { - EvaluatorPointerType src = (EvaluatorPointerType)m_impl.data(); - for (Index i = 0; i < internal::array_prod(dimensions()); i += contiguous_values) { - Index offset = srcCoeff(i); - m_device.memcpy((void*)(m_device.get(data + i)), m_device.get(src+offset), contiguous_values * sizeof(Scalar)); - } - return false; - } - } - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - if (m_is_identity) { - return m_impl.coeff(index); - } else { - return m_impl.coeff(srcCoeff(index)); - } - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - const int packetSize = PacketType<CoeffReturnType, Device>::size; - EIGEN_STATIC_ASSERT((packetSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+packetSize-1 < internal::array_prod(dimensions())); - - if (m_is_identity) { - return m_impl.template packet<LoadMode>(index); - } - - Index inputIndices[] = {0, 0}; - Index indices[] = {index, index + packetSize - 1}; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx0 = indices[0] / m_fastOutputStrides[i]; - const Index idx1 = indices[1] / m_fastOutputStrides[i]; - inputIndices[0] += (idx0 + m_offsets[i]) * m_inputStrides[i]; - inputIndices[1] += (idx1 + m_offsets[i]) * m_inputStrides[i]; - indices[0] -= idx0 * m_outputStrides[i]; - indices[1] -= idx1 * m_outputStrides[i]; - } - inputIndices[0] += (indices[0] + m_offsets[0]); - inputIndices[1] += (indices[1] + m_offsets[0]); - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx0 = indices[0] / m_fastOutputStrides[i]; - const Index idx1 = indices[1] / m_fastOutputStrides[i]; - inputIndices[0] += (idx0 + m_offsets[i]) * m_inputStrides[i]; - inputIndices[1] += (idx1 + m_offsets[i]) * m_inputStrides[i]; - indices[0] -= idx0 * m_outputStrides[i]; - indices[1] -= idx1 * m_outputStrides[i]; - } - inputIndices[0] += (indices[0] + m_offsets[NumDims-1]); - inputIndices[1] += (indices[1] + m_offsets[NumDims-1]); - } - if (inputIndices[1] - inputIndices[0] == packetSize - 1) { - PacketReturnType rslt = m_impl.template packet<Unaligned>(inputIndices[0]); - return rslt; - } - else { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[packetSize]; - values[0] = m_impl.coeff(inputIndices[0]); - values[packetSize-1] = m_impl.coeff(inputIndices[1]); - EIGEN_UNROLL_LOOP - for (int i = 1; i < packetSize-1; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - return m_impl.costPerCoeff(vectorized) + TensorOpCost(0, 0, m_is_identity ? 1 : NumDims); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - const size_t target_size = m_device.lastLevelCacheSize(); - return internal::TensorBlockResourceRequirements::merge( - internal::TensorBlockResourceRequirements::skewed<Scalar>(target_size), - m_impl.getResourceRequirements()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - TensorBlockDesc arg_desc = desc.WithOffset(srcCoeff(desc.offset())); - TensorBlock block = m_impl.block(arg_desc, scratch); - if (!arg_desc.HasDestinationBuffer()) desc.DropDestinationBuffer(); - return block; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Storage::Type data() const { - typename Storage::Type result = constCast(m_impl.data()); - if (result) { - Index offset = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = 0; i < NumDims; ++i) { - if (m_dimensions[i] != m_impl.dimensions()[i]) { - offset += m_offsets[i] * m_inputStrides[i]; - for (int j = i+1; j < NumDims; ++j) { - if (m_dimensions[j] > 1) { - return NULL; - } - offset += m_offsets[j] * m_inputStrides[j]; - } - break; - } - } - } else { - for (int i = NumDims - 1; i >= 0; --i) { - if (m_dimensions[i] != m_impl.dimensions()[i]) { - offset += m_offsets[i] * m_inputStrides[i]; - for (int j = i-1; j >= 0; --j) { - if (m_dimensions[j] > 1) { - return NULL; - } - offset += m_offsets[j] * m_inputStrides[j]; - } - break; - } - } - } - return result + offset; - } - return NULL; - } -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index srcCoeff(Index index) const - { - Index inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_fastOutputStrides[i]; - inputIndex += (idx + m_offsets[i]) * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - inputIndex += (index + m_offsets[0]); - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_fastOutputStrides[i]; - inputIndex += (idx + m_offsets[i]) * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - inputIndex += (index + m_offsets[NumDims-1]); - } - return inputIndex; - } - - array<Index, NumDims> m_outputStrides; - array<internal::TensorIntDivisor<Index>, NumDims> m_fastOutputStrides; - array<Index, NumDims> m_inputStrides; - TensorEvaluator<ArgType, Device> m_impl; - const Device EIGEN_DEVICE_REF m_device; - Dimensions m_dimensions; - bool m_is_identity; - const StartIndices m_offsets; -}; - - -// Eval as lvalue -template<typename StartIndices, typename Sizes, typename ArgType, typename Device> -struct TensorEvaluator<TensorSlicingOp<StartIndices, Sizes, ArgType>, Device> - : public TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Device> -{ - typedef TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Device> Base; - typedef TensorSlicingOp<StartIndices, Sizes, ArgType> XprType; - static const int NumDims = internal::array_size<Sizes>::value; - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef Sizes Dimensions; - - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = TensorEvaluator<ArgType, Device>::BlockAccess, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, - RawAccess = (NumDims == 1) & TensorEvaluator<ArgType, Device>::RawAccess - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : Base(op, device) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index) - { - if (this->m_is_identity) { - return this->m_impl.coeffRef(index); - } else { - return this->m_impl.coeffRef(this->srcCoeff(index)); - } - } - - template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) - { - if (this->m_is_identity) { - this->m_impl.template writePacket<StoreMode>(index, x); - return; - } - - const int packetSize = PacketType<CoeffReturnType, Device>::size; - Index inputIndices[] = {0, 0}; - Index indices[] = {index, index + packetSize - 1}; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx0 = indices[0] / this->m_fastOutputStrides[i]; - const Index idx1 = indices[1] / this->m_fastOutputStrides[i]; - inputIndices[0] += (idx0 + this->m_offsets[i]) * this->m_inputStrides[i]; - inputIndices[1] += (idx1 + this->m_offsets[i]) * this->m_inputStrides[i]; - indices[0] -= idx0 * this->m_outputStrides[i]; - indices[1] -= idx1 * this->m_outputStrides[i]; - } - inputIndices[0] += (indices[0] + this->m_offsets[0]); - inputIndices[1] += (indices[1] + this->m_offsets[0]); - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx0 = indices[0] / this->m_fastOutputStrides[i]; - const Index idx1 = indices[1] / this->m_fastOutputStrides[i]; - inputIndices[0] += (idx0 + this->m_offsets[i]) * this->m_inputStrides[i]; - inputIndices[1] += (idx1 + this->m_offsets[i]) * this->m_inputStrides[i]; - indices[0] -= idx0 * this->m_outputStrides[i]; - indices[1] -= idx1 * this->m_outputStrides[i]; - } - inputIndices[0] += (indices[0] + this->m_offsets[NumDims-1]); - inputIndices[1] += (indices[1] + this->m_offsets[NumDims-1]); - } - if (inputIndices[1] - inputIndices[0] == packetSize - 1) { - this->m_impl.template writePacket<StoreMode>(inputIndices[0], x); - } - else { - EIGEN_ALIGN_MAX CoeffReturnType values[packetSize]; - internal::pstore<CoeffReturnType, PacketReturnType>(values, x); - this->m_impl.coeffRef(inputIndices[0]) = values[0]; - this->m_impl.coeffRef(inputIndices[1]) = values[packetSize-1]; - EIGEN_UNROLL_LOOP - for (int i = 1; i < packetSize-1; ++i) { - this->coeffRef(index+i) = values[i]; - } - } - } - - template<typename TensorBlock> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writeBlock( - const TensorBlockDesc& desc, const TensorBlock& block) { - TensorBlockDesc arg_desc = desc.WithOffset(this->srcCoeff(desc.offset())); - this->m_impl.writeBlock(arg_desc, block); - } -}; - -namespace internal { -template<typename StartIndices, typename StopIndices, typename Strides, typename XprType> -struct traits<TensorStridingSlicingOp<StartIndices, StopIndices, Strides, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = array_size<StartIndices>::value; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename StartIndices, typename StopIndices, typename Strides, typename XprType> -struct eval<TensorStridingSlicingOp<StartIndices, StopIndices, Strides, XprType>, Eigen::Dense> -{ - typedef const TensorStridingSlicingOp<StartIndices, StopIndices, Strides, XprType>EIGEN_DEVICE_REF type; -}; - -template<typename StartIndices, typename StopIndices, typename Strides, typename XprType> -struct nested<TensorStridingSlicingOp<StartIndices, StopIndices, Strides, XprType>, 1, typename eval<TensorStridingSlicingOp<StartIndices, StopIndices, Strides, XprType> >::type> -{ - typedef TensorStridingSlicingOp<StartIndices, StopIndices, Strides, XprType> type; -}; - -} // end namespace internal - - -template<typename StartIndices, typename StopIndices, typename Strides, typename XprType> -class TensorStridingSlicingOp : public TensorBase<TensorStridingSlicingOp<StartIndices, StopIndices, Strides, XprType> > -{ - public: - typedef typename internal::traits<TensorStridingSlicingOp>::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename internal::nested<TensorStridingSlicingOp>::type Nested; - typedef typename internal::traits<TensorStridingSlicingOp>::StorageKind StorageKind; - typedef typename internal::traits<TensorStridingSlicingOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorStridingSlicingOp( - const XprType& expr, const StartIndices& startIndices, - const StopIndices& stopIndices, const Strides& strides) - : m_xpr(expr), m_startIndices(startIndices), m_stopIndices(stopIndices), - m_strides(strides) {} - - EIGEN_DEVICE_FUNC - const StartIndices& startIndices() const { return m_startIndices; } - EIGEN_DEVICE_FUNC - const StartIndices& stopIndices() const { return m_stopIndices; } - EIGEN_DEVICE_FUNC - const StartIndices& strides() const { return m_strides; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorStridingSlicingOp& operator = (const TensorStridingSlicingOp& other) - { - typedef TensorAssignOp<TensorStridingSlicingOp, const TensorStridingSlicingOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run( - assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorStridingSlicingOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorStridingSlicingOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run( - assign, DefaultDevice()); - return *this; - } - - protected: - typename XprType::Nested m_xpr; - const StartIndices m_startIndices; - const StopIndices m_stopIndices; - const Strides m_strides; -}; - -// Eval as rvalue -template<typename StartIndices, typename StopIndices, typename Strides, typename ArgType, typename Device> -struct TensorEvaluator<const TensorStridingSlicingOp<StartIndices, StopIndices, Strides, ArgType>, Device> -{ - typedef TensorStridingSlicingOp<StartIndices, StopIndices, Strides, ArgType> XprType; - static const int NumDims = internal::array_size<Strides>::value; - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - typedef Strides Dimensions; - - enum { - // Alignment can't be guaranteed at compile time since it depends on the - // slice offsets and sizes. - IsAligned = false, - PacketAccess = false, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), - m_device(device), - m_strides(op.strides()) - { - // Handle degenerate intervals by gracefully clamping and allowing m_dimensions to be zero - DSizes<Index, NumDims> startIndicesClamped, stopIndicesClamped; - for (ptrdiff_t i = 0; i < internal::array_size<Dimensions>::value; ++i) { - eigen_assert(m_strides[i] != 0 && "0 stride is invalid"); - if (m_strides[i] > 0) { - startIndicesClamped[i] = - clamp(op.startIndices()[i], 0, m_impl.dimensions()[i]); - stopIndicesClamped[i] = - clamp(op.stopIndices()[i], 0, m_impl.dimensions()[i]); - } else { - /* implies m_strides[i] < 0 by assert */ - startIndicesClamped[i] = - clamp(op.startIndices()[i], -1, m_impl.dimensions()[i] - 1); - stopIndicesClamped[i] = - clamp(op.stopIndices()[i], -1, m_impl.dimensions()[i] - 1); - } - m_startIndices[i] = startIndicesClamped[i]; - } - - typedef typename TensorEvaluator<ArgType, Device>::Dimensions InputDimensions; - const InputDimensions& input_dims = m_impl.dimensions(); - - // check for degenerate intervals and compute output tensor shape - bool degenerate = false; - m_is_identity = true; - for (int i = 0; i < NumDims; i++) { - Index interval = stopIndicesClamped[i] - startIndicesClamped[i]; - if (interval == 0 || ((interval < 0) != (m_strides[i] < 0))) { - m_dimensions[i] = 0; - degenerate = true; - } else { - m_dimensions[i] = - (interval / m_strides[i]) + (interval % m_strides[i] != 0 ? 1 : 0); - eigen_assert(m_dimensions[i] >= 0); - } - if (m_strides[i] != 1 || interval != m_impl.dimensions()[i]) { - m_is_identity = false; - } - } - - Strides output_dims = m_dimensions; - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_inputStrides[0] = m_strides[0]; - m_offsets[0] = startIndicesClamped[0]; - Index previousDimProduct = 1; - for (int i = 1; i < NumDims; ++i) { - previousDimProduct *= input_dims[i-1]; - m_inputStrides[i] = previousDimProduct * m_strides[i]; - m_offsets[i] = startIndicesClamped[i] * previousDimProduct; - } - - // Don't initialize m_fastOutputStrides[0] since it won't ever be accessed. - m_outputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_outputStrides[i] = m_outputStrides[i-1] * output_dims[i-1]; - // NOTE: if tensor is degenerate, we send 1 to prevent TensorIntDivisor constructor crash - m_fastOutputStrides[i] = internal::TensorIntDivisor<Index>(degenerate ? 1 : m_outputStrides[i]); - } - } else { - m_inputStrides[NumDims-1] = m_strides[NumDims-1]; - m_offsets[NumDims-1] = startIndicesClamped[NumDims-1]; - Index previousDimProduct = 1; - for (int i = NumDims - 2; i >= 0; --i) { - previousDimProduct *= input_dims[i+1]; - m_inputStrides[i] = previousDimProduct * m_strides[i]; - m_offsets[i] = startIndicesClamped[i] * previousDimProduct; - } - - m_outputStrides[NumDims-1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_outputStrides[i] = m_outputStrides[i+1] * output_dims[i+1]; - // NOTE: if tensor is degenerate, we send 1 to prevent TensorIntDivisor constructor crash - m_fastOutputStrides[i] = internal::TensorIntDivisor<Index>(degenerate ? 1 : m_outputStrides[i]); - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - if (m_is_identity) { - return m_impl.coeff(index); - } else { - return m_impl.coeff(srcCoeff(index)); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - return m_impl.costPerCoeff(vectorized) + TensorOpCost(0, 0, m_is_identity ? 1 : NumDims); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Storage::Type data() const { - return NULL; - } -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index srcCoeff(Index index) const - { - Index inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i >= 0; --i) { - const Index idx = index / m_fastOutputStrides[i]; - inputIndex += idx * m_inputStrides[i] + m_offsets[i]; - index -= idx * m_outputStrides[i]; - } - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims; ++i) { - const Index idx = index / m_fastOutputStrides[i]; - inputIndex += idx * m_inputStrides[i] + m_offsets[i]; - index -= idx * m_outputStrides[i]; - } - } - return inputIndex; - } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index clamp(Index value, Index min, Index max) { -#ifndef SYCL_DEVICE_ONLY - return numext::maxi(min, numext::mini(max,value)); -#else - return cl::sycl::clamp(value, min, max); -#endif - } - - array<Index, NumDims> m_outputStrides; - array<internal::TensorIntDivisor<Index>, NumDims> m_fastOutputStrides; - array<Index, NumDims> m_inputStrides; - bool m_is_identity; - TensorEvaluator<ArgType, Device> m_impl; - const Device EIGEN_DEVICE_REF m_device; - DSizes<Index, NumDims> m_startIndices; // clamped startIndices - DSizes<Index, NumDims> m_dimensions; - DSizes<Index, NumDims> m_offsets; // offset in a flattened shape - const Strides m_strides; -}; - -// Eval as lvalue -template<typename StartIndices, typename StopIndices, typename Strides, typename ArgType, typename Device> -struct TensorEvaluator<TensorStridingSlicingOp<StartIndices, StopIndices, Strides, ArgType>, Device> - : public TensorEvaluator<const TensorStridingSlicingOp<StartIndices, StopIndices, Strides, ArgType>, Device> -{ - typedef TensorEvaluator<const TensorStridingSlicingOp<StartIndices, StopIndices, Strides, ArgType>, Device> Base; - typedef TensorStridingSlicingOp<StartIndices, StopIndices, Strides, ArgType> XprType; - static const int NumDims = internal::array_size<Strides>::value; - - enum { - IsAligned = false, - PacketAccess = false, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = TensorEvaluator<ArgType, Device>::CoordAccess, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : Base(op, device) - { } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef Strides Dimensions; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index) - { - if (this->m_is_identity) { - return this->m_impl.coeffRef(index); - } else { - return this->m_impl.coeffRef(this->srcCoeff(index)); - } - } -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_MORPHING_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h deleted file mode 100644 index 561666c6..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h +++ /dev/null @@ -1,708 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_PADDING_H -#define EIGEN_CXX11_TENSOR_TENSOR_PADDING_H - -namespace Eigen { - -/** \class TensorPadding - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor padding class. - * At the moment only padding with a constant value is supported. - * - */ -namespace internal { -template<typename PaddingDimensions, typename XprType> -struct traits<TensorPaddingOp<PaddingDimensions, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename PaddingDimensions, typename XprType> -struct eval<TensorPaddingOp<PaddingDimensions, XprType>, Eigen::Dense> -{ - typedef const TensorPaddingOp<PaddingDimensions, XprType>& type; -}; - -template<typename PaddingDimensions, typename XprType> -struct nested<TensorPaddingOp<PaddingDimensions, XprType>, 1, typename eval<TensorPaddingOp<PaddingDimensions, XprType> >::type> -{ - typedef TensorPaddingOp<PaddingDimensions, XprType> type; -}; - -} // end namespace internal - - - -template<typename PaddingDimensions, typename XprType> -class TensorPaddingOp : public TensorBase<TensorPaddingOp<PaddingDimensions, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorPaddingOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorPaddingOp>::type Nested; - typedef typename Eigen::internal::traits<TensorPaddingOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorPaddingOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorPaddingOp(const XprType& expr, const PaddingDimensions& padding_dims, const Scalar padding_value) - : m_xpr(expr), m_padding_dims(padding_dims), m_padding_value(padding_value) {} - - EIGEN_DEVICE_FUNC - const PaddingDimensions& padding() const { return m_padding_dims; } - EIGEN_DEVICE_FUNC - Scalar padding_value() const { return m_padding_value; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const PaddingDimensions m_padding_dims; - const Scalar m_padding_value; -}; - - -// Eval as rvalue -template<typename PaddingDimensions, typename ArgType, typename Device> -struct TensorEvaluator<const TensorPaddingOp<PaddingDimensions, ArgType>, Device> -{ - typedef TensorPaddingOp<PaddingDimensions, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<PaddingDimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = true, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = TensorEvaluator<ArgType, Device>::RawAccess, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = true, - RawAccess = false - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename internal::TensorMaterializedBlock<ScalarNoConst, NumDims, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_padding(op.padding()), m_paddingValue(op.padding_value()), m_device(device) - { - // The padding op doesn't change the rank of the tensor. Directly padding a scalar would lead - // to a vector, which doesn't make sense. Instead one should reshape the scalar into a vector - // of 1 element first and then pad. - EIGEN_STATIC_ASSERT((NumDims > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - - // Compute dimensions - m_dimensions = m_impl.dimensions(); - for (int i = 0; i < NumDims; ++i) { - m_dimensions[i] += m_padding[i].first + m_padding[i].second; - } - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_inputStrides[0] = 1; - m_outputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1]; - m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1]; - } - m_outputStrides[NumDims] = m_outputStrides[NumDims-1] * m_dimensions[NumDims-1]; - } else { - m_inputStrides[NumDims - 1] = 1; - m_outputStrides[NumDims] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1]; - m_outputStrides[i+1] = m_outputStrides[i+2] * m_dimensions[i+1]; - } - m_outputStrides[0] = m_outputStrides[1] * m_dimensions[0]; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - m_impl.evalSubExprsIfNeededAsync(nullptr, [done](bool) { done(true); }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - eigen_assert(index < dimensions().TotalSize()); - Index inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_outputStrides[i]; - if (isPaddingAtIndexForDim(idx, i)) { - return m_paddingValue; - } - inputIndex += (idx - m_padding[i].first) * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - if (isPaddingAtIndexForDim(index, 0)) { - return m_paddingValue; - } - inputIndex += (index - m_padding[0].first); - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_outputStrides[i+1]; - if (isPaddingAtIndexForDim(idx, i)) { - return m_paddingValue; - } - inputIndex += (idx - m_padding[i].first) * m_inputStrides[i]; - index -= idx * m_outputStrides[i+1]; - } - if (isPaddingAtIndexForDim(index, NumDims-1)) { - return m_paddingValue; - } - inputIndex += (index - m_padding[NumDims-1].first); - } - return m_impl.coeff(inputIndex); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - return packetColMajor(index); - } - return packetRowMajor(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - TensorOpCost cost = m_impl.costPerCoeff(vectorized); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims; ++i) - updateCostPerDimension(cost, i, i == 0); - } else { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i >= 0; --i) - updateCostPerDimension(cost, i, i == NumDims - 1); - } - return cost; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - const size_t target_size = m_device.lastLevelCacheSize(); - return internal::TensorBlockResourceRequirements::merge( - internal::TensorBlockResourceRequirements::skewed<Scalar>(target_size), - m_impl.getResourceRequirements()); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - // If one of the dimensions is zero, return empty block view. - if (desc.size() == 0) { - return TensorBlock(internal::TensorBlockKind::kView, NULL, - desc.dimensions()); - } - - static const bool IsColMajor = Layout == static_cast<int>(ColMajor); - const int inner_dim_idx = IsColMajor ? 0 : NumDims - 1; - - Index offset = desc.offset(); - - // Compute offsets in the output tensor corresponding to the desc.offset(). - DSizes<Index, NumDims> output_offsets; - for (int i = NumDims - 1; i > 0; --i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - const int stride_dim = IsColMajor ? dim : dim + 1; - output_offsets[dim] = offset / m_outputStrides[stride_dim]; - offset -= output_offsets[dim] * m_outputStrides[stride_dim]; - } - output_offsets[inner_dim_idx] = offset; - - // Offsets in the input corresponding to output offsets. - DSizes<Index, NumDims> input_offsets = output_offsets; - for (int i = 0; i < NumDims; ++i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - input_offsets[dim] = input_offsets[dim] - m_padding[dim].first; - } - - // Compute offset in the input buffer (at this point it might be illegal and - // point outside of the input buffer, because we don't check for negative - // offsets, it will be autocorrected in the block iteration loop below). - Index input_offset = 0; - for (int i = 0; i < NumDims; ++i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - input_offset += input_offsets[dim] * m_inputStrides[dim]; - } - - // Destination buffer and scratch buffer both indexed from 0 and have the - // same dimensions as the requested block (for destination buffer this - // property is guaranteed by `desc.destination()`). - Index output_offset = 0; - const DSizes<Index, NumDims> output_strides = - internal::strides<Layout>(desc.dimensions()); - - // NOTE(ezhulenev): We initialize bock iteration state for `NumDims - 1` - // dimensions, skipping innermost dimension. In theory it should be possible - // to squeeze matching innermost dimensions, however in practice that did - // not show any improvements in benchmarks. Also in practice first outer - // dimension usually has padding, and will prevent squeezing. - - // Initialize output block iterator state. Dimension in this array are - // always in inner_most -> outer_most order (col major layout). - array<BlockIteratorState, NumDims - 1> it; - for (int i = 0; i < NumDims - 1; ++i) { - const int dim = IsColMajor ? i + 1 : NumDims - i - 2; - it[i].count = 0; - it[i].size = desc.dimension(dim); - - it[i].input_stride = m_inputStrides[dim]; - it[i].input_span = it[i].input_stride * (it[i].size - 1); - - it[i].output_stride = output_strides[dim]; - it[i].output_span = it[i].output_stride * (it[i].size - 1); - } - - const Index input_inner_dim_size = - static_cast<Index>(m_impl.dimensions()[inner_dim_idx]); - - // Total output size. - const Index output_size = desc.size(); - - // We will fill inner dimension of this size in the output. It might be - // larger than the inner dimension in the input, so we might have to pad - // before/after we copy values from the input inner dimension. - const Index output_inner_dim_size = desc.dimension(inner_dim_idx); - - // How many values to fill with padding BEFORE reading from the input inner - // dimension. - const Index output_inner_pad_before_size = - input_offsets[inner_dim_idx] < 0 - ? numext::mini(numext::abs(input_offsets[inner_dim_idx]), - output_inner_dim_size) - : 0; - - // How many values we can actually copy from the input inner dimension. - const Index output_inner_copy_size = numext::mini( - // Want to copy from input. - (output_inner_dim_size - output_inner_pad_before_size), - // Can copy from input. - numext::maxi(input_inner_dim_size - (input_offsets[inner_dim_idx] + - output_inner_pad_before_size), - Index(0))); - - eigen_assert(output_inner_copy_size >= 0); - - // How many values to fill with padding AFTER reading from the input inner - // dimension. - const Index output_inner_pad_after_size = - (output_inner_dim_size - output_inner_copy_size - - output_inner_pad_before_size); - - // Sanity check, sum of all sizes must be equal to the output size. - eigen_assert(output_inner_dim_size == - (output_inner_pad_before_size + output_inner_copy_size + - output_inner_pad_after_size)); - - // Keep track of current coordinates and padding in the output. - DSizes<Index, NumDims> output_coord = output_offsets; - DSizes<Index, NumDims> output_padded; - for (int i = 0; i < NumDims; ++i) { - const int dim = IsColMajor ? i : NumDims - i - 1; - output_padded[dim] = isPaddingAtIndexForDim(output_coord[dim], dim); - } - - typedef internal::StridedLinearBufferCopy<ScalarNoConst, Index> LinCopy; - - // Prepare storage for the materialized padding result. - const typename TensorBlock::Storage block_storage = - TensorBlock::prepareStorage(desc, scratch); - - // TODO(ezhulenev): Squeeze multiple non-padded inner dimensions into a - // single logical inner dimension. - - // When possible we squeeze writes for the innermost (only if non-padded) - // dimension with the first padded dimension. This allows to reduce the - // number of calls to LinCopy and better utilize vector instructions. - const bool squeeze_writes = - NumDims > 1 && - // inner dimension is not padded - (input_inner_dim_size == m_dimensions[inner_dim_idx]) && - // and equal to the block inner dimension - (input_inner_dim_size == output_inner_dim_size); - - const int squeeze_dim = IsColMajor ? inner_dim_idx + 1 : inner_dim_idx - 1; - - // Maximum coordinate on a squeeze dimension that we can write to. - const Index squeeze_max_coord = - squeeze_writes ? numext::mini( - // max non-padded element in the input - static_cast<Index>(m_dimensions[squeeze_dim] - - m_padding[squeeze_dim].second), - // max element in the output buffer - static_cast<Index>(output_offsets[squeeze_dim] + - desc.dimension(squeeze_dim))) - : static_cast<Index>(0); - - // Iterate copying data from `m_impl.data()` to the output buffer. - for (Index size = 0; size < output_size;) { - // Detect if we are in the padded region (exclude innermost dimension). - bool is_padded = false; - for (int j = 1; j < NumDims; ++j) { - const int dim = IsColMajor ? j : NumDims - j - 1; - is_padded = output_padded[dim]; - if (is_padded) break; - } - - if (is_padded) { - // Fill single innermost dimension with padding value. - size += output_inner_dim_size; - - LinCopy::template Run<LinCopy::Kind::FillLinear>( - typename LinCopy::Dst(output_offset, 1, block_storage.data()), - typename LinCopy::Src(0, 0, &m_paddingValue), - output_inner_dim_size); - - - } else if (squeeze_writes) { - // Squeeze multiple reads from innermost dimensions. - const Index squeeze_num = squeeze_max_coord - output_coord[squeeze_dim]; - size += output_inner_dim_size * squeeze_num; - - // Copy `squeeze_num` inner dimensions from input to output. - LinCopy::template Run<LinCopy::Kind::Linear>( - typename LinCopy::Dst(output_offset, 1, block_storage.data()), - typename LinCopy::Src(input_offset, 1, m_impl.data()), - output_inner_dim_size * squeeze_num); - - // Update iteration state for only `squeeze_num - 1` processed inner - // dimensions, because we have another iteration state update at the end - // of the loop that will update iteration state for the last inner - // processed dimension. - it[0].count += (squeeze_num - 1); - input_offset += it[0].input_stride * (squeeze_num - 1); - output_offset += it[0].output_stride * (squeeze_num - 1); - output_coord[squeeze_dim] += (squeeze_num - 1); - - } else { - // Single read from innermost dimension. - size += output_inner_dim_size; - - { // Fill with padding before copying from input inner dimension. - const Index out = output_offset; - - LinCopy::template Run<LinCopy::Kind::FillLinear>( - typename LinCopy::Dst(out, 1, block_storage.data()), - typename LinCopy::Src(0, 0, &m_paddingValue), - output_inner_pad_before_size); - } - - { // Copy data from input inner dimension. - const Index out = output_offset + output_inner_pad_before_size; - const Index in = input_offset + output_inner_pad_before_size; - - eigen_assert(output_inner_copy_size == 0 || m_impl.data() != NULL); - - LinCopy::template Run<LinCopy::Kind::Linear>( - typename LinCopy::Dst(out, 1, block_storage.data()), - typename LinCopy::Src(in, 1, m_impl.data()), - output_inner_copy_size); - } - - { // Fill with padding after copying from input inner dimension. - const Index out = output_offset + output_inner_pad_before_size + - output_inner_copy_size; - - LinCopy::template Run<LinCopy::Kind::FillLinear>( - typename LinCopy::Dst(out, 1, block_storage.data()), - typename LinCopy::Src(0, 0, &m_paddingValue), - output_inner_pad_after_size); - } - } - - for (int j = 0; j < NumDims - 1; ++j) { - const int dim = IsColMajor ? j + 1 : NumDims - j - 2; - - if (++it[j].count < it[j].size) { - input_offset += it[j].input_stride; - output_offset += it[j].output_stride; - output_coord[dim] += 1; - output_padded[dim] = isPaddingAtIndexForDim(output_coord[dim], dim); - break; - } - it[j].count = 0; - input_offset -= it[j].input_span; - output_offset -= it[j].output_span; - output_coord[dim] -= it[j].size - 1; - output_padded[dim] = isPaddingAtIndexForDim(output_coord[dim], dim); - } - } - - return block_storage.AsTensorMaterializedBlock(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - private: - struct BlockIteratorState { - BlockIteratorState() - : count(0), - size(0), - input_stride(0), - input_span(0), - output_stride(0), - output_span(0) {} - - Index count; - Index size; - Index input_stride; - Index input_span; - Index output_stride; - Index output_span; - }; - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool isPaddingAtIndexForDim( - Index index, int dim_index) const { -#if defined(EIGEN_HAS_INDEX_LIST) - return (!internal::index_pair_first_statically_eq<PaddingDimensions>(dim_index, 0) && - index < m_padding[dim_index].first) || - (!internal::index_pair_second_statically_eq<PaddingDimensions>(dim_index, 0) && - index >= m_dimensions[dim_index] - m_padding[dim_index].second); -#else - return (index < m_padding[dim_index].first) || - (index >= m_dimensions[dim_index] - m_padding[dim_index].second); -#endif - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool isLeftPaddingCompileTimeZero( - int dim_index) const { -#if defined(EIGEN_HAS_INDEX_LIST) - return internal::index_pair_first_statically_eq<PaddingDimensions>(dim_index, 0); -#else - EIGEN_UNUSED_VARIABLE(dim_index); - return false; -#endif - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool isRightPaddingCompileTimeZero( - int dim_index) const { -#if defined(EIGEN_HAS_INDEX_LIST) - return internal::index_pair_second_statically_eq<PaddingDimensions>(dim_index, 0); -#else - EIGEN_UNUSED_VARIABLE(dim_index); - return false; -#endif - } - - - void updateCostPerDimension(TensorOpCost& cost, int i, bool first) const { - const double in = static_cast<double>(m_impl.dimensions()[i]); - const double out = in + m_padding[i].first + m_padding[i].second; - if (out == 0) - return; - const double reduction = in / out; - cost *= reduction; - if (first) { - cost += TensorOpCost(0, 0, 2 * TensorOpCost::AddCost<Index>() + - reduction * (1 * TensorOpCost::AddCost<Index>())); - } else { - cost += TensorOpCost(0, 0, 2 * TensorOpCost::AddCost<Index>() + - 2 * TensorOpCost::MulCost<Index>() + - reduction * (2 * TensorOpCost::MulCost<Index>() + - 1 * TensorOpCost::DivCost<Index>())); - } - } - - protected: - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetColMajor(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - const Index initialIndex = index; - Index inputIndex = 0; - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index firstIdx = index; - const Index lastIdx = index + PacketSize - 1; - const Index lastPaddedLeft = m_padding[i].first * m_outputStrides[i]; - const Index firstPaddedRight = (m_dimensions[i] - m_padding[i].second) * m_outputStrides[i]; - const Index lastPaddedRight = m_outputStrides[i+1]; - - if (!isLeftPaddingCompileTimeZero(i) && lastIdx < lastPaddedLeft) { - // all the coefficient are in the padding zone. - return internal::pset1<PacketReturnType>(m_paddingValue); - } - else if (!isRightPaddingCompileTimeZero(i) && firstIdx >= firstPaddedRight && lastIdx < lastPaddedRight) { - // all the coefficient are in the padding zone. - return internal::pset1<PacketReturnType>(m_paddingValue); - } - else if ((isLeftPaddingCompileTimeZero(i) && isRightPaddingCompileTimeZero(i)) || (firstIdx >= lastPaddedLeft && lastIdx < firstPaddedRight)) { - // all the coefficient are between the 2 padding zones. - const Index idx = index / m_outputStrides[i]; - inputIndex += (idx - m_padding[i].first) * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - else { - // Every other case - return packetWithPossibleZero(initialIndex); - } - } - - const Index lastIdx = index + PacketSize - 1; - const Index firstIdx = index; - const Index lastPaddedLeft = m_padding[0].first; - const Index firstPaddedRight = (m_dimensions[0] - m_padding[0].second); - const Index lastPaddedRight = m_outputStrides[1]; - - if (!isLeftPaddingCompileTimeZero(0) && lastIdx < lastPaddedLeft) { - // all the coefficient are in the padding zone. - return internal::pset1<PacketReturnType>(m_paddingValue); - } - else if (!isRightPaddingCompileTimeZero(0) && firstIdx >= firstPaddedRight && lastIdx < lastPaddedRight) { - // all the coefficient are in the padding zone. - return internal::pset1<PacketReturnType>(m_paddingValue); - } - else if ((isLeftPaddingCompileTimeZero(0) && isRightPaddingCompileTimeZero(0)) || (firstIdx >= lastPaddedLeft && lastIdx < firstPaddedRight)) { - // all the coefficient are between the 2 padding zones. - inputIndex += (index - m_padding[0].first); - return m_impl.template packet<Unaligned>(inputIndex); - } - // Every other case - return packetWithPossibleZero(initialIndex); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetRowMajor(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - const Index initialIndex = index; - Index inputIndex = 0; - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index firstIdx = index; - const Index lastIdx = index + PacketSize - 1; - const Index lastPaddedLeft = m_padding[i].first * m_outputStrides[i+1]; - const Index firstPaddedRight = (m_dimensions[i] - m_padding[i].second) * m_outputStrides[i+1]; - const Index lastPaddedRight = m_outputStrides[i]; - - if (!isLeftPaddingCompileTimeZero(i) && lastIdx < lastPaddedLeft) { - // all the coefficient are in the padding zone. - return internal::pset1<PacketReturnType>(m_paddingValue); - } - else if (!isRightPaddingCompileTimeZero(i) && firstIdx >= firstPaddedRight && lastIdx < lastPaddedRight) { - // all the coefficient are in the padding zone. - return internal::pset1<PacketReturnType>(m_paddingValue); - } - else if ((isLeftPaddingCompileTimeZero(i) && isRightPaddingCompileTimeZero(i)) || (firstIdx >= lastPaddedLeft && lastIdx < firstPaddedRight)) { - // all the coefficient are between the 2 padding zones. - const Index idx = index / m_outputStrides[i+1]; - inputIndex += (idx - m_padding[i].first) * m_inputStrides[i]; - index -= idx * m_outputStrides[i+1]; - } - else { - // Every other case - return packetWithPossibleZero(initialIndex); - } - } - - const Index lastIdx = index + PacketSize - 1; - const Index firstIdx = index; - const Index lastPaddedLeft = m_padding[NumDims-1].first; - const Index firstPaddedRight = (m_dimensions[NumDims-1] - m_padding[NumDims-1].second); - const Index lastPaddedRight = m_outputStrides[NumDims-1]; - - if (!isLeftPaddingCompileTimeZero(NumDims-1) && lastIdx < lastPaddedLeft) { - // all the coefficient are in the padding zone. - return internal::pset1<PacketReturnType>(m_paddingValue); - } - else if (!isRightPaddingCompileTimeZero(NumDims-1) && firstIdx >= firstPaddedRight && lastIdx < lastPaddedRight) { - // all the coefficient are in the padding zone. - return internal::pset1<PacketReturnType>(m_paddingValue); - } - else if ((isLeftPaddingCompileTimeZero(NumDims-1) && isRightPaddingCompileTimeZero(NumDims-1)) || (firstIdx >= lastPaddedLeft && lastIdx < firstPaddedRight)) { - // all the coefficient are between the 2 padding zones. - inputIndex += (index - m_padding[NumDims-1].first); - return m_impl.template packet<Unaligned>(inputIndex); - } - // Every other case - return packetWithPossibleZero(initialIndex); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index) const - { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - - Dimensions m_dimensions; - array<Index, NumDims+1> m_outputStrides; - array<Index, NumDims> m_inputStrides; - TensorEvaluator<ArgType, Device> m_impl; - PaddingDimensions m_padding; - - Scalar m_paddingValue; - - const Device EIGEN_DEVICE_REF m_device; -}; - - - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_PADDING_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorPatch.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorPatch.h deleted file mode 100644 index 64a436e5..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorPatch.h +++ /dev/null @@ -1,291 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_PATCH_H -#define EIGEN_CXX11_TENSOR_TENSOR_PATCH_H - -namespace Eigen { - -/** \class TensorPatch - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor patch class. - * - * - */ -namespace internal { -template<typename PatchDim, typename XprType> -struct traits<TensorPatchOp<PatchDim, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions + 1; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename PatchDim, typename XprType> -struct eval<TensorPatchOp<PatchDim, XprType>, Eigen::Dense> -{ - typedef const TensorPatchOp<PatchDim, XprType>& type; -}; - -template<typename PatchDim, typename XprType> -struct nested<TensorPatchOp<PatchDim, XprType>, 1, typename eval<TensorPatchOp<PatchDim, XprType> >::type> -{ - typedef TensorPatchOp<PatchDim, XprType> type; -}; - -} // end namespace internal - - - -template<typename PatchDim, typename XprType> -class TensorPatchOp : public TensorBase<TensorPatchOp<PatchDim, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorPatchOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorPatchOp>::type Nested; - typedef typename Eigen::internal::traits<TensorPatchOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorPatchOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorPatchOp(const XprType& expr, const PatchDim& patch_dims) - : m_xpr(expr), m_patch_dims(patch_dims) {} - - EIGEN_DEVICE_FUNC - const PatchDim& patch_dims() const { return m_patch_dims; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const PatchDim m_patch_dims; -}; - - -// Eval as rvalue -template<typename PatchDim, typename ArgType, typename Device> -struct TensorEvaluator<const TensorPatchOp<PatchDim, ArgType>, Device> -{ - typedef TensorPatchOp<PatchDim, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value + 1; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device) - { - Index num_patches = 1; - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - const PatchDim& patch_dims = op.patch_dims(); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = 0; i < NumDims-1; ++i) { - m_dimensions[i] = patch_dims[i]; - num_patches *= (input_dims[i] - patch_dims[i] + 1); - } - m_dimensions[NumDims-1] = num_patches; - - m_inputStrides[0] = 1; - m_patchStrides[0] = 1; - for (int i = 1; i < NumDims-1; ++i) { - m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1]; - m_patchStrides[i] = m_patchStrides[i-1] * (input_dims[i-1] - patch_dims[i-1] + 1); - } - m_outputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1]; - } - } else { - for (int i = 0; i < NumDims-1; ++i) { - m_dimensions[i+1] = patch_dims[i]; - num_patches *= (input_dims[i] - patch_dims[i] + 1); - } - m_dimensions[0] = num_patches; - - m_inputStrides[NumDims-2] = 1; - m_patchStrides[NumDims-2] = 1; - for (int i = NumDims-3; i >= 0; --i) { - m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1]; - m_patchStrides[i] = m_patchStrides[i+1] * (input_dims[i+1] - patch_dims[i+1] + 1); - } - m_outputStrides[NumDims-1] = 1; - for (int i = NumDims-2; i >= 0; --i) { - m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1]; - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - Index output_stride_index = (static_cast<int>(Layout) == static_cast<int>(ColMajor)) ? NumDims - 1 : 0; - // Find the location of the first element of the patch. - Index patchIndex = index / m_outputStrides[output_stride_index]; - // Find the offset of the element wrt the location of the first element. - Index patchOffset = index - patchIndex * m_outputStrides[output_stride_index]; - Index inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 2; i > 0; --i) { - const Index patchIdx = patchIndex / m_patchStrides[i]; - patchIndex -= patchIdx * m_patchStrides[i]; - const Index offsetIdx = patchOffset / m_outputStrides[i]; - patchOffset -= offsetIdx * m_outputStrides[i]; - inputIndex += (patchIdx + offsetIdx) * m_inputStrides[i]; - } - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 2; ++i) { - const Index patchIdx = patchIndex / m_patchStrides[i]; - patchIndex -= patchIdx * m_patchStrides[i]; - const Index offsetIdx = patchOffset / m_outputStrides[i+1]; - patchOffset -= offsetIdx * m_outputStrides[i+1]; - inputIndex += (patchIdx + offsetIdx) * m_inputStrides[i]; - } - } - inputIndex += (patchIndex + patchOffset); - return m_impl.coeff(inputIndex); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - Index output_stride_index = (static_cast<int>(Layout) == static_cast<int>(ColMajor)) ? NumDims - 1 : 0; - Index indices[2] = {index, index + PacketSize - 1}; - Index patchIndices[2] = {indices[0] / m_outputStrides[output_stride_index], - indices[1] / m_outputStrides[output_stride_index]}; - Index patchOffsets[2] = {indices[0] - patchIndices[0] * m_outputStrides[output_stride_index], - indices[1] - patchIndices[1] * m_outputStrides[output_stride_index]}; - - Index inputIndices[2] = {0, 0}; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 2; i > 0; --i) { - const Index patchIdx[2] = {patchIndices[0] / m_patchStrides[i], - patchIndices[1] / m_patchStrides[i]}; - patchIndices[0] -= patchIdx[0] * m_patchStrides[i]; - patchIndices[1] -= patchIdx[1] * m_patchStrides[i]; - - const Index offsetIdx[2] = {patchOffsets[0] / m_outputStrides[i], - patchOffsets[1] / m_outputStrides[i]}; - patchOffsets[0] -= offsetIdx[0] * m_outputStrides[i]; - patchOffsets[1] -= offsetIdx[1] * m_outputStrides[i]; - - inputIndices[0] += (patchIdx[0] + offsetIdx[0]) * m_inputStrides[i]; - inputIndices[1] += (patchIdx[1] + offsetIdx[1]) * m_inputStrides[i]; - } - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 2; ++i) { - const Index patchIdx[2] = {patchIndices[0] / m_patchStrides[i], - patchIndices[1] / m_patchStrides[i]}; - patchIndices[0] -= patchIdx[0] * m_patchStrides[i]; - patchIndices[1] -= patchIdx[1] * m_patchStrides[i]; - - const Index offsetIdx[2] = {patchOffsets[0] / m_outputStrides[i+1], - patchOffsets[1] / m_outputStrides[i+1]}; - patchOffsets[0] -= offsetIdx[0] * m_outputStrides[i+1]; - patchOffsets[1] -= offsetIdx[1] * m_outputStrides[i+1]; - - inputIndices[0] += (patchIdx[0] + offsetIdx[0]) * m_inputStrides[i]; - inputIndices[1] += (patchIdx[1] + offsetIdx[1]) * m_inputStrides[i]; - } - } - inputIndices[0] += (patchIndices[0] + patchOffsets[0]); - inputIndices[1] += (patchIndices[1] + patchOffsets[1]); - - if (inputIndices[1] - inputIndices[0] == PacketSize - 1) { - PacketReturnType rslt = m_impl.template packet<Unaligned>(inputIndices[0]); - return rslt; - } - else { - EIGEN_ALIGN_MAX CoeffReturnType values[PacketSize]; - values[0] = m_impl.coeff(inputIndices[0]); - values[PacketSize-1] = m_impl.coeff(inputIndices[1]); - EIGEN_UNROLL_LOOP - for (int i = 1; i < PacketSize-1; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - const double compute_cost = NumDims * (TensorOpCost::DivCost<Index>() + - TensorOpCost::MulCost<Index>() + - 2 * TensorOpCost::AddCost<Index>()); - return m_impl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, compute_cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - protected: - Dimensions m_dimensions; - array<Index, NumDims> m_outputStrides; - array<Index, NumDims-1> m_inputStrides; - array<Index, NumDims-1> m_patchStrides; - - TensorEvaluator<ArgType, Device> m_impl; - -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_PATCH_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h deleted file mode 100644 index 44524816..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h +++ /dev/null @@ -1,350 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> -// Copyright (C) 2018 Mehdi Goli <eigen@codeplay.com> Codeplay Software Ltd. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_RANDOM_H -#define EIGEN_CXX11_TENSOR_TENSOR_RANDOM_H - -namespace Eigen { -namespace internal { - -namespace { - -EIGEN_DEVICE_FUNC uint64_t get_random_seed() { -#if defined(EIGEN_GPU_COMPILE_PHASE) - // We don't support 3d kernels since we currently only use 1 and - // 2d kernels. - gpu_assert(threadIdx.z == 0); - return clock64() + - blockIdx.x * blockDim.x + threadIdx.x + - gridDim.x * blockDim.x * (blockIdx.y * blockDim.y + threadIdx.y); - -#elif defined _WIN32 - // Use the current time as a baseline. - SYSTEMTIME st; - GetSystemTime(&st); - int time = st.wSecond + 1000 * st.wMilliseconds; - // Mix in a random number to make sure that we get different seeds if - // we try to generate seeds faster than the clock resolution. - // We need 2 random values since the generator only generate 16 bits at - // a time (https://msdn.microsoft.com/en-us/library/398ax69y.aspx) - int rnd1 = ::rand(); - int rnd2 = ::rand(); - uint64_t rnd = (rnd1 | rnd2 << 16) ^ time; - return rnd; - -#elif defined __APPLE__ - // Same approach as for win32, except that the random number generator - // is better (// https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/random.3.html#//apple_ref/doc/man/3/random). - uint64_t rnd = ::random() ^ mach_absolute_time(); - return rnd; - -#elif defined __native_client__ - // Same approach as for win32, except using clock_gettime - timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - int rnd1 = ::rand(); - int rnd2 = ::rand(); - uint64_t rnd = (rnd1 | rnd2 << 16) ^ ts.tv_nsec; - return rnd; - -#else - // Augment the current time with pseudo random number generation - // to ensure that we get different seeds if we try to generate seeds - // faster than the clock resolution. - timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - uint64_t rnd = ::random() ^ ts.tv_nsec; - return rnd; -#endif -} - -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE unsigned PCG_XSH_RS_generator(uint64_t* state, uint64_t stream) { - // TODO: Unify with the implementation in the non blocking thread pool. - uint64_t current = *state; - // Update the internal state - *state = current * 6364136223846793005ULL + (stream << 1 | 1); - // Generate the random output (using the PCG-XSH-RS scheme) - return static_cast<unsigned>((current ^ (current >> 22)) >> (22 + (current >> 61))); -} - -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE uint64_t PCG_XSH_RS_state(uint64_t seed) { - seed = seed ? seed : get_random_seed(); - return seed * 6364136223846793005ULL + 0xda3e39cb94b95bdbULL; -} - -} // namespace - - -template <typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -T RandomToTypeUniform(uint64_t* state, uint64_t stream) { - unsigned rnd = PCG_XSH_RS_generator(state, stream); - return static_cast<T>(rnd); -} - - -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -Eigen::half RandomToTypeUniform<Eigen::half>(uint64_t* state, uint64_t stream) { - Eigen::half result; - // Generate 10 random bits for the mantissa - unsigned rnd = PCG_XSH_RS_generator(state, stream); - result.x = static_cast<uint16_t>(rnd & 0x3ffu); - // Set the exponent - result.x |= (static_cast<uint16_t>(15) << 10); - // Return the final result - return result - Eigen::half(1.0f); -} - - -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float RandomToTypeUniform<float>(uint64_t* state, uint64_t stream) { - typedef union { - uint32_t raw; - float fp; - } internal; - internal result; - // Generate 23 random bits for the mantissa mantissa - const unsigned rnd = PCG_XSH_RS_generator(state, stream); - result.raw = rnd & 0x7fffffu; - // Set the exponent - result.raw |= (static_cast<uint32_t>(127) << 23); - // Return the final result - return result.fp - 1.0f; -} - -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double RandomToTypeUniform<double>(uint64_t* state, uint64_t stream) { - typedef union { - uint64_t raw; - double dp; - } internal; - internal result; - result.raw = 0; - // Generate 52 random bits for the mantissa - // First generate the upper 20 bits - unsigned rnd1 = PCG_XSH_RS_generator(state, stream) & 0xfffffu; - // The generate the lower 32 bits - unsigned rnd2 = PCG_XSH_RS_generator(state, stream); - result.raw = (static_cast<uint64_t>(rnd1) << 32) | rnd2; - // Set the exponent - result.raw |= (static_cast<uint64_t>(1023) << 52); - // Return the final result - return result.dp - 1.0; -} - -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -std::complex<float> RandomToTypeUniform<std::complex<float> >(uint64_t* state, uint64_t stream) { - return std::complex<float>(RandomToTypeUniform<float>(state, stream), - RandomToTypeUniform<float>(state, stream)); -} -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -std::complex<double> RandomToTypeUniform<std::complex<double> >(uint64_t* state, uint64_t stream) { - return std::complex<double>(RandomToTypeUniform<double>(state, stream), - RandomToTypeUniform<double>(state, stream)); -} - -template <typename T> class UniformRandomGenerator { - public: - static const bool PacketAccess = true; - - // Uses the given "seed" if non-zero, otherwise uses a random seed. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UniformRandomGenerator( - uint64_t seed = 0) { - m_state = PCG_XSH_RS_state(seed); - #ifdef EIGEN_USE_SYCL - // In SYCL it is not possible to build PCG_XSH_RS_state in one step. - // Therefor, we need two step to initializate the m_state. - // IN SYCL, the constructor of the functor is s called on the CPU - // and we get the clock seed here from the CPU. However, This seed is - //the same for all the thread. As unlike CUDA, the thread.ID, BlockID, etc is not a global function. - // and only available on the Operator() function (which is called on the GPU). - // Thus for CUDA (((CLOCK + global_thread_id)* 6364136223846793005ULL) + 0xda3e39cb94b95bdbULL) is passed to each thread - // but for SYCL ((CLOCK * 6364136223846793005ULL) + 0xda3e39cb94b95bdbULL) is passed to each thread and each thread adds - // the (global_thread_id* 6364136223846793005ULL) for itself only once, in order to complete the construction - // similar to CUDA Therefore, the thread Id injection is not available at this stage. - //However when the operator() is called the thread ID will be avilable. So inside the opeator, - // we add the thrreadID, BlockId,... (which is equivalent of i) - //to the seed and construct the unique m_state per thead similar to cuda. - m_exec_once =false; - #endif - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UniformRandomGenerator( - const UniformRandomGenerator& other) { - m_state = other.m_state; - #ifdef EIGEN_USE_SYCL - m_exec_once =other.m_exec_once; - #endif - } - - template<typename Index> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - T operator()(Index i) const { - #ifdef EIGEN_USE_SYCL - if(!m_exec_once) { - // This is the second stage of adding thread Id to the CPU clock seed and build unique seed per thread - // The (i * 6364136223846793005ULL) is the remaining part of the PCG_XSH_RS_state on the GPU side - m_state += (i * 6364136223846793005ULL); - m_exec_once =true; - } - #endif - T result = RandomToTypeUniform<T>(&m_state, i); - return result; - } - - template<typename Packet, typename Index> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Packet packetOp(Index i) const { - const int packetSize = internal::unpacket_traits<Packet>::size; - EIGEN_ALIGN_MAX T values[packetSize]; - #ifdef EIGEN_USE_SYCL - if(!m_exec_once) { - // This is the second stage of adding thread Id to the CPU clock seed and build unique seed per thread - m_state += (i * 6364136223846793005ULL); - m_exec_once =true; - } - #endif - EIGEN_UNROLL_LOOP - for (int j = 0; j < packetSize; ++j) { - values[j] = RandomToTypeUniform<T>(&m_state, i); - } - return internal::pload<Packet>(values); - } - - private: - mutable uint64_t m_state; - #ifdef EIGEN_USE_SYCL - mutable bool m_exec_once; - #endif -}; - -template <typename Scalar> -struct functor_traits<UniformRandomGenerator<Scalar> > { - enum { - // Rough estimate for floating point, multiplied by ceil(sizeof(T) / sizeof(float)). - Cost = 12 * NumTraits<Scalar>::AddCost * - ((sizeof(Scalar) + sizeof(float) - 1) / sizeof(float)), - PacketAccess = UniformRandomGenerator<Scalar>::PacketAccess - }; -}; - - - -template <typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -T RandomToTypeNormal(uint64_t* state, uint64_t stream) { - // Use the ratio of uniform method to generate numbers following a normal - // distribution. See for example Numerical Recipes chapter 7.3.9 for the - // details. - T u, v, q; - do { - u = RandomToTypeUniform<T>(state, stream); - v = T(1.7156) * (RandomToTypeUniform<T>(state, stream) - T(0.5)); - const T x = u - T(0.449871); - const T y = numext::abs(v) + T(0.386595); - q = x*x + y * (T(0.196)*y - T(0.25472)*x); - } while (q > T(0.27597) && - (q > T(0.27846) || v*v > T(-4) * numext::log(u) * u*u)); - - return v/u; -} - -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -std::complex<float> RandomToTypeNormal<std::complex<float> >(uint64_t* state, uint64_t stream) { - return std::complex<float>(RandomToTypeNormal<float>(state, stream), - RandomToTypeNormal<float>(state, stream)); -} -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -std::complex<double> RandomToTypeNormal<std::complex<double> >(uint64_t* state, uint64_t stream) { - return std::complex<double>(RandomToTypeNormal<double>(state, stream), - RandomToTypeNormal<double>(state, stream)); -} - - -template <typename T> class NormalRandomGenerator { - public: - static const bool PacketAccess = true; - - // Uses the given "seed" if non-zero, otherwise uses a random seed. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NormalRandomGenerator(uint64_t seed = 0) { - m_state = PCG_XSH_RS_state(seed); - #ifdef EIGEN_USE_SYCL - // In SYCL it is not possible to build PCG_XSH_RS_state in one step. - // Therefor, we need two steps to initializate the m_state. - // IN SYCL, the constructor of the functor is s called on the CPU - // and we get the clock seed here from the CPU. However, This seed is - //the same for all the thread. As unlike CUDA, the thread.ID, BlockID, etc is not a global function. - // and only available on the Operator() function (which is called on the GPU). - // Therefore, the thread Id injection is not available at this stage. However when the operator() - //is called the thread ID will be avilable. So inside the opeator, - // we add the thrreadID, BlockId,... (which is equivalent of i) - //to the seed and construct the unique m_state per thead similar to cuda. - m_exec_once =false; - #endif - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NormalRandomGenerator( - const NormalRandomGenerator& other) { - m_state = other.m_state; -#ifdef EIGEN_USE_SYCL - m_exec_once=other.m_exec_once; -#endif - } - - template<typename Index> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - T operator()(Index i) const { - #ifdef EIGEN_USE_SYCL - if(!m_exec_once) { - // This is the second stage of adding thread Id to the CPU clock seed and build unique seed per thread - m_state += (i * 6364136223846793005ULL); - m_exec_once =true; - } - #endif - T result = RandomToTypeNormal<T>(&m_state, i); - return result; - } - - template<typename Packet, typename Index> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Packet packetOp(Index i) const { - const int packetSize = internal::unpacket_traits<Packet>::size; - EIGEN_ALIGN_MAX T values[packetSize]; - #ifdef EIGEN_USE_SYCL - if(!m_exec_once) { - // This is the second stage of adding thread Id to the CPU clock seed and build unique seed per thread - m_state += (i * 6364136223846793005ULL); - m_exec_once =true; - } - #endif - EIGEN_UNROLL_LOOP - for (int j = 0; j < packetSize; ++j) { - values[j] = RandomToTypeNormal<T>(&m_state, i); - } - return internal::pload<Packet>(values); - } - - private: - mutable uint64_t m_state; - #ifdef EIGEN_USE_SYCL - mutable bool m_exec_once; - #endif -}; - - -template <typename Scalar> -struct functor_traits<NormalRandomGenerator<Scalar> > { - enum { - // On average, we need to generate about 3 random numbers - // 15 mul, 8 add, 1.5 logs - Cost = 3 * functor_traits<UniformRandomGenerator<Scalar> >::Cost + - 15 * NumTraits<Scalar>::AddCost + 8 * NumTraits<Scalar>::AddCost + - 3 * functor_traits<scalar_log_op<Scalar> >::Cost / 2, - PacketAccess = NormalRandomGenerator<Scalar>::PacketAccess - }; -}; - - -} // end namespace internal -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_RANDOM_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h deleted file mode 100644 index ad14d82f..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h +++ /dev/null @@ -1,1134 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// Copyright (C) 2016 Mehdi Goli, Codeplay Software Ltd <eigen@codeplay.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_REDUCTION_H -#define EIGEN_CXX11_TENSOR_TENSOR_REDUCTION_H - -// clang is incompatible with the CUDA syntax wrt making a kernel a class friend, -// so we'll use a macro to make clang happy. -#ifndef KERNEL_FRIEND -#if defined(__clang__) && (defined(__CUDA__) || defined(__HIP__)) -#define KERNEL_FRIEND friend __global__ -#else -#define KERNEL_FRIEND friend -#endif -#endif - - -namespace Eigen { - - -/** \class TensorReduction - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor reduction class. - * - */ - -namespace internal { - template<typename Op, typename Dims, typename XprType,template <class> class MakePointer_ > - struct traits<TensorReductionOp<Op, Dims, XprType, MakePointer_> > - : traits<XprType> -{ - typedef traits<XprType> XprTraits; - typedef typename XprTraits::Scalar Scalar; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - static const int NumDimensions = XprTraits::NumDimensions - array_size<Dims>::value; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; - - template <class T> struct MakePointer { - // Intermediate typedef to workaround MSVC issue. - typedef MakePointer_<T> MakePointerT; - typedef typename MakePointerT::Type Type; - }; -}; - -template<typename Op, typename Dims, typename XprType, template <class> class MakePointer_> -struct eval<TensorReductionOp<Op, Dims, XprType, MakePointer_>, Eigen::Dense> -{ - typedef const TensorReductionOp<Op, Dims, XprType, MakePointer_>& type; -}; - -template<typename Op, typename Dims, typename XprType, template <class> class MakePointer_> -struct nested<TensorReductionOp<Op, Dims, XprType, MakePointer_>, 1, typename eval<TensorReductionOp<Op, Dims, XprType, MakePointer_> >::type> -{ - typedef TensorReductionOp<Op, Dims, XprType, MakePointer_> type; -}; - - -template <typename OutputDims> struct DimInitializer { - template <typename InputDims, typename ReducedDims> EIGEN_DEVICE_FUNC - static void run(const InputDims& input_dims, - const array<bool, internal::array_size<InputDims>::value>& reduced, - OutputDims* output_dims, ReducedDims* reduced_dims) { - const int NumInputDims = internal::array_size<InputDims>::value; - int outputIndex = 0; - int reduceIndex = 0; - for (int i = 0; i < NumInputDims; ++i) { - if (reduced[i]) { - (*reduced_dims)[reduceIndex] = input_dims[i]; - ++reduceIndex; - } else { - (*output_dims)[outputIndex] = input_dims[i]; - ++outputIndex; - } - } - } -}; - -template <> struct DimInitializer<Sizes<> > { - template <typename InputDims, typename Index, size_t Rank> EIGEN_DEVICE_FUNC - static void run(const InputDims& input_dims, const array<bool, Rank>&, - Sizes<>*, array<Index, Rank>* reduced_dims) { - const int NumInputDims = internal::array_size<InputDims>::value; - for (int i = 0; i < NumInputDims; ++i) { - (*reduced_dims)[i] = input_dims[i]; - } - } -}; - - -template <typename ReducedDims, int NumTensorDims, int Layout> -struct are_inner_most_dims { - static const bool value = false; -}; -template <typename ReducedDims, int NumTensorDims, int Layout> -struct preserve_inner_most_dims { - static const bool value = false; -}; - -#if EIGEN_HAS_CONSTEXPR && EIGEN_HAS_VARIADIC_TEMPLATES -template <typename ReducedDims, int NumTensorDims> -struct are_inner_most_dims<ReducedDims, NumTensorDims, ColMajor>{ - static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>(); - static const bool tmp2 = index_statically_eq<ReducedDims>(0, 0); - static const bool tmp3 = index_statically_eq<ReducedDims>(array_size<ReducedDims>::value-1, array_size<ReducedDims>::value-1); - static const bool value = tmp1 & tmp2 & tmp3; -}; -template <typename ReducedDims, int NumTensorDims> -struct are_inner_most_dims<ReducedDims, NumTensorDims, RowMajor>{ - static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>(); - static const bool tmp2 = index_statically_eq<ReducedDims>(0, NumTensorDims - array_size<ReducedDims>::value); - static const bool tmp3 = index_statically_eq<ReducedDims>(array_size<ReducedDims>::value - 1, NumTensorDims - 1); - static const bool value = tmp1 & tmp2 & tmp3; - -}; -template <typename ReducedDims, int NumTensorDims> -struct preserve_inner_most_dims<ReducedDims, NumTensorDims, ColMajor>{ - static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>(); - static const bool tmp2 = index_statically_gt<ReducedDims>(0, 0); - static const bool value = tmp1 & tmp2; - -}; -template <typename ReducedDims, int NumTensorDims> -struct preserve_inner_most_dims<ReducedDims, NumTensorDims, RowMajor>{ - static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>(); - static const bool tmp2 = index_statically_lt<ReducedDims>(array_size<ReducedDims>::value - 1, NumTensorDims - 1); - static const bool value = tmp1 & tmp2; -}; -#endif - - -template <int DimIndex, typename Self, typename Op> -struct GenericDimReducer { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const Self& self, typename Self::Index firstIndex, Op& reducer, typename Self::CoeffReturnType* accum) { - EIGEN_STATIC_ASSERT((DimIndex > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - for (int j = 0; j < self.m_reducedDims[DimIndex]; ++j) { - const typename Self::Index input = firstIndex + j * self.m_reducedStrides[DimIndex]; - GenericDimReducer<DimIndex-1, Self, Op>::reduce(self, input, reducer, accum); - } - } -}; -template <typename Self, typename Op> -struct GenericDimReducer<0, Self, Op> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const Self& self, typename Self::Index firstIndex, Op& reducer, typename Self::CoeffReturnType* accum) { - for (int j = 0; j < self.m_reducedDims[0]; ++j) { - const typename Self::Index input = firstIndex + j * self.m_reducedStrides[0]; - reducer.reduce(self.m_impl.coeff(input), accum); - } - } -}; -template <typename Self, typename Op> -struct GenericDimReducer<-1, Self, Op> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const Self& self, typename Self::Index index, Op& reducer, typename Self::CoeffReturnType* accum) { - reducer.reduce(self.m_impl.coeff(index), accum); - } -}; - -template <typename Self, typename Op, bool Vectorizable = (Self::InputPacketAccess && Self::ReducerTraits::PacketAccess), - bool UseTreeReduction = (!Self::ReducerTraits::IsStateful && - !Self::ReducerTraits::IsExactlyAssociative)> -struct InnerMostDimReducer { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Self::CoeffReturnType reduce(const Self& self, typename Self::Index firstIndex, typename Self::Index numValuesToReduce, Op& reducer) { - typename Self::CoeffReturnType accum = reducer.initialize(); - for (typename Self::Index j = 0; j < numValuesToReduce; ++j) { - reducer.reduce(self.m_impl.coeff(firstIndex + j), &accum); - } - return reducer.finalize(accum); - } -}; - -template <typename Self, typename Op> -struct InnerMostDimReducer<Self, Op, true, false> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Self::CoeffReturnType reduce(const Self& self, typename Self::Index firstIndex, typename Self::Index numValuesToReduce, Op& reducer) { - const typename Self::Index packetSize = internal::unpacket_traits<typename Self::PacketReturnType>::size; - const typename Self::Index VectorizedSize = (numValuesToReduce / packetSize) * packetSize; - typename Self::PacketReturnType paccum = reducer.template initializePacket<typename Self::PacketReturnType>(); - for (typename Self::Index j = 0; j < VectorizedSize; j += packetSize) { - reducer.reducePacket(self.m_impl.template packet<Unaligned>(firstIndex + j), &paccum); - } - typename Self::CoeffReturnType accum = reducer.initialize(); - for (typename Self::Index j = VectorizedSize; j < numValuesToReduce; ++j) { - reducer.reduce(self.m_impl.coeff(firstIndex + j), &accum); - } - return reducer.finalizeBoth(accum, paccum); - } -}; - -#if !defined(EIGEN_HIPCC) -static const int kLeafSize = 1024; - -template <typename Self, typename Op> -struct InnerMostDimReducer<Self, Op, false, true> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Self::CoeffReturnType - reduce(const Self& self, typename Self::Index firstIndex, - typename Self::Index numValuesToReduce, Op& reducer) { - typename Self::CoeffReturnType accum = reducer.initialize(); - if (numValuesToReduce > kLeafSize) { - const typename Self::Index half = numValuesToReduce / 2; - reducer.reduce(reduce(self, firstIndex, half, reducer), &accum); - reducer.reduce( - reduce(self, firstIndex + half, numValuesToReduce - half, reducer), - &accum); - } else { - for (typename Self::Index j = 0; j < numValuesToReduce; ++j) { - reducer.reduce(self.m_impl.coeff(firstIndex + j), &accum); - } - } - return reducer.finalize(accum); - } -}; - -template <typename Self, typename Op> -struct InnerMostDimReducer<Self, Op, true, true> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Self::CoeffReturnType - reduce(const Self& self, typename Self::Index firstIndex, - typename Self::Index numValuesToReduce, Op& reducer) { - const typename Self::Index packetSize = - internal::unpacket_traits<typename Self::PacketReturnType>::size; - typename Self::CoeffReturnType accum = reducer.initialize(); - if (numValuesToReduce > packetSize * kLeafSize) { - // Make sure the split point is aligned on a packet boundary. - const typename Self::Index split = - packetSize * - divup(firstIndex + divup(numValuesToReduce, typename Self::Index(2)), - packetSize); - const typename Self::Index num_left = - numext::mini(split - firstIndex, numValuesToReduce); - reducer.reduce(reduce(self, firstIndex, num_left, reducer), &accum); - if (num_left < numValuesToReduce) { - reducer.reduce( - reduce(self, split, numValuesToReduce - num_left, reducer), &accum); - } - return reducer.finalize(accum); - } else { - const typename Self::Index VectorizedSize = - (numValuesToReduce / packetSize) * packetSize; - typename Self::PacketReturnType paccum = - reducer.template initializePacket<typename Self::PacketReturnType>(); - for (typename Self::Index j = 0; j < VectorizedSize; j += packetSize) { - reducer.reducePacket( - self.m_impl.template packet<Unaligned>(firstIndex + j), &paccum); - } - for (typename Self::Index j = VectorizedSize; j < numValuesToReduce; - ++j) { - reducer.reduce(self.m_impl.coeff(firstIndex + j), &accum); - } - return reducer.finalizeBoth(accum, paccum); - } - } -}; -#endif - -template <int DimIndex, typename Self, typename Op, bool vectorizable = (Self::InputPacketAccess && Self::ReducerTraits::PacketAccess)> -struct InnerMostDimPreserver { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const Self&, typename Self::Index, Op&, typename Self::PacketReturnType*) { - eigen_assert(false && "should never be called"); - } -}; - -template <int DimIndex, typename Self, typename Op> -struct InnerMostDimPreserver<DimIndex, Self, Op, true> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const Self& self, typename Self::Index firstIndex, Op& reducer, typename Self::PacketReturnType* accum) { - EIGEN_STATIC_ASSERT((DimIndex > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - for (typename Self::Index j = 0; j < self.m_reducedDims[DimIndex]; ++j) { - const typename Self::Index input = firstIndex + j * self.m_reducedStrides[DimIndex]; - InnerMostDimPreserver<DimIndex-1, Self, Op>::reduce(self, input, reducer, accum); - } - } -}; - -template <typename Self, typename Op> -struct InnerMostDimPreserver<0, Self, Op, true> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const Self& self, typename Self::Index firstIndex, Op& reducer, typename Self::PacketReturnType* accum) { - for (typename Self::Index j = 0; j < self.m_reducedDims[0]; ++j) { - const typename Self::Index input = firstIndex + j * self.m_reducedStrides[0]; - reducer.reducePacket(self.m_impl.template packet<Unaligned>(input), accum); - } - } -}; -template <typename Self, typename Op> -struct InnerMostDimPreserver<-1, Self, Op, true> { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const Self&, typename Self::Index, Op&, typename Self::PacketReturnType*) { - eigen_assert(false && "should never be called"); - } -}; - -// Default full reducer -template <typename Self, typename Op, typename Device, bool Vectorizable = (Self::InputPacketAccess && Self::ReducerTraits::PacketAccess)> -struct FullReducer { - static const bool HasOptimizedImplementation = false; - - static EIGEN_DEVICE_FUNC void run(const Self& self, Op& reducer, const Device&, typename Self::EvaluatorPointerType output) { - const typename Self::Index num_coeffs = array_prod(self.m_impl.dimensions()); - *output = InnerMostDimReducer<Self, Op, Vectorizable>::reduce(self, 0, num_coeffs, reducer); - } -}; - - -#ifdef EIGEN_USE_THREADS -// Multithreaded full reducers -template <typename Self, typename Op, - bool Vectorizable = (Self::InputPacketAccess && Self::ReducerTraits::PacketAccess)> -struct FullReducerShard { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Self& self, typename Self::Index firstIndex, - typename Self::Index numValuesToReduce, Op& reducer, - typename Self::CoeffReturnType* output) { - *output = InnerMostDimReducer<Self, Op, Vectorizable>::reduce( - self, firstIndex, numValuesToReduce, reducer); - } -}; - -// Multithreaded full reducer -template <typename Self, typename Op, bool Vectorizable> -struct FullReducer<Self, Op, ThreadPoolDevice, Vectorizable> { - static const bool HasOptimizedImplementation = !Self::ReducerTraits::IsStateful; - static const Index PacketSize = - unpacket_traits<typename Self::PacketReturnType>::size; - - // launch one reducer per thread and accumulate the result. - static void run(const Self& self, Op& reducer, const ThreadPoolDevice& device, - typename Self::CoeffReturnType* output) { - typedef typename Self::Index Index; - const Index num_coeffs = array_prod(self.m_impl.dimensions()); - if (num_coeffs == 0) { - *output = reducer.finalize(reducer.initialize()); - return; - } - const TensorOpCost cost = - self.m_impl.costPerCoeff(Vectorizable) + - TensorOpCost(0, 0, internal::functor_traits<Op>::Cost, Vectorizable, - PacketSize); - const int num_threads = TensorCostModel<ThreadPoolDevice>::numThreads( - num_coeffs, cost, device.numThreads()); - if (num_threads == 1) { - *output = - InnerMostDimReducer<Self, Op, Vectorizable>::reduce(self, 0, num_coeffs, reducer); - return; - } - const Index blocksize = - std::floor<Index>(static_cast<float>(num_coeffs) / num_threads); - const Index numblocks = blocksize > 0 ? num_coeffs / blocksize : 0; - eigen_assert(num_coeffs >= numblocks * blocksize); - - Barrier barrier(internal::convert_index<unsigned int>(numblocks)); - MaxSizeVector<typename Self::CoeffReturnType> shards(numblocks, reducer.initialize()); - for (Index i = 0; i < numblocks; ++i) { - device.enqueue_with_barrier(&barrier, &FullReducerShard<Self, Op, Vectorizable>::run, - self, i * blocksize, blocksize, reducer, - &shards[i]); - } - typename Self::CoeffReturnType finalShard; - if (numblocks * blocksize < num_coeffs) { - finalShard = InnerMostDimReducer<Self, Op, Vectorizable>::reduce( - self, numblocks * blocksize, num_coeffs - numblocks * blocksize, - reducer); - } else { - finalShard = reducer.initialize(); - } - barrier.Wait(); - - for (Index i = 0; i < numblocks; ++i) { - reducer.reduce(shards[i], &finalShard); - } - *output = reducer.finalize(finalShard); - } -}; - -#endif - - -// Default inner reducer -template <typename Self, typename Op, typename Device> -struct InnerReducer { - static const bool HasOptimizedImplementation = false; - - EIGEN_DEVICE_FUNC static bool run(const Self&, Op&, const Device&, typename Self::CoeffReturnType*, typename Self::Index, typename Self::Index) { - eigen_assert(false && "Not implemented"); - return true; - } -}; - -// Default outer reducer -template <typename Self, typename Op, typename Device> -struct OuterReducer { - static const bool HasOptimizedImplementation = false; - - EIGEN_DEVICE_FUNC static bool run(const Self&, Op&, const Device&, typename Self::CoeffReturnType*, typename Self::Index, typename Self::Index) { - eigen_assert(false && "Not implemented"); - return true; - } -}; - -#ifdef EIGEN_USE_SYCL -// Default Generic reducer -template <typename Self, typename Op, typename Device> -struct GenericReducer { - static const bool HasOptimizedImplementation = false; - - EIGEN_DEVICE_FUNC static bool run(const Self&, Op&, const Device&, typename Self::CoeffReturnType*, typename Self::Index, typename Self::Index) { - eigen_assert(false && "Not implemented"); - return true; - } -}; -#endif - -#if defined(EIGEN_USE_GPU) && (defined(EIGEN_GPUCC)) -template <int B, int N, typename S, typename R, typename I_> -__global__ void FullReductionKernel(R, const S, I_, typename S::CoeffReturnType*, unsigned int*); - - -#if defined(EIGEN_HAS_GPU_FP16) -template <typename S, typename R, typename I_> -__global__ void ReductionInitFullReduxKernelHalfFloat(R, const S, I_, half2*); -template <int B, int N, typename S, typename R, typename I_> -__global__ void FullReductionKernelHalfFloat(R, const S, I_, half*, half2*); -template <int NPT, typename S, typename R, typename I_> -__global__ void InnerReductionKernelHalfFloat(R, const S, I_, I_, half*); - -#endif - -template <int NPT, typename S, typename R, typename I_> -__global__ void InnerReductionKernel(R, const S, I_, I_, typename S::CoeffReturnType*); - -template <int NPT, typename S, typename R, typename I_> -__global__ void OuterReductionKernel(R, const S, I_, I_, typename S::CoeffReturnType*); -#endif - -/** - * For SYCL, the return type of the reduction is deduced from the initialize method of the given Op. - * This allows the reduction to have a different type for the accumulator than the input data type. - * If this is the case, the functor needs to have two reduce method: one for reducing an element of the input - * with the accumulator and the other for reducing two accumulators. - * Such a reducer can be useful for instance when the accumulator is a boolean or a bitset that checks for - * some properties of the input. - */ -template <typename Op, typename CoeffReturnType> -struct ReductionReturnType { -#if defined(EIGEN_USE_SYCL) - typedef typename remove_const<decltype(std::declval<Op>().initialize())>::type type; -#else - typedef typename remove_const<CoeffReturnType>::type type; -#endif -}; - -template <typename Self, typename Op, - bool Vectorizable = - (Self::InputPacketAccess & Self::ReducerTraits::PacketAccess)> -class BlockReducer { - public: - typedef typename Self::Index Index; - typedef typename Self::Scalar Scalar; - typedef typename Self::CoeffReturnType CoeffReturnType; - typedef typename Self::PacketReturnType PacketReturnType; - explicit BlockReducer(const Op& reducer) : op_(reducer) { - accum_ = op_.initialize(); - } - void Reduce(Index index, Index num_values_to_reduce, Scalar* data) { - for (Index i = 0; i < num_values_to_reduce; ++i) { - op_.reduce(data[index + i], &accum_); - } - } - CoeffReturnType Finalize() { return op_.finalize(accum_); } - PacketReturnType FinalizePacket() { - // TODO(andydavis) This function should not be called for Scalar - // reductions: clean this up or add an assert here. - return PacketReturnType(); - } - - private: - CoeffReturnType accum_; - Op op_; -}; - -template <typename Self, typename Op> -class BlockReducer<Self, Op, true> { - public: - typedef typename Self::Index Index; - typedef typename Self::Scalar Scalar; - typedef typename Self::CoeffReturnType CoeffReturnType; - typedef typename Self::PacketReturnType PacketReturnType; - static const Index PacketSize = - internal::unpacket_traits<PacketReturnType>::size; - - explicit BlockReducer(const Op& reducer) : op_(reducer) { - vaccum_ = op_.template initializePacket<PacketReturnType>(); - accum_ = op_.initialize(); - } - void Reduce(Index index, Index num_values_to_reduce, Scalar* data) { - const Index vectorized_size = - (num_values_to_reduce / PacketSize) * PacketSize; - for (Index i = 0; i < vectorized_size; i += PacketSize) { - op_.reducePacket( - internal::ploadt<PacketReturnType, Unaligned>(&data[index + i]), - &vaccum_); - } - for (Index i = vectorized_size; i < num_values_to_reduce; ++i) { - op_.reduce(data[index + i], &accum_); - } - } - CoeffReturnType Finalize() { return op_.finalizeBoth(accum_, vaccum_); } - PacketReturnType FinalizePacket() { return op_.finalizePacket(vaccum_); } - - private: - PacketReturnType vaccum_; - CoeffReturnType accum_; - Op op_; -}; - -} // end namespace internal - - -template <typename Op, typename Dims, typename XprType, template <class> class MakePointer_> -class TensorReductionOp : public TensorBase<TensorReductionOp<Op, Dims, XprType, MakePointer_>, ReadOnlyAccessors> { - public: - typedef typename Eigen::internal::traits<TensorReductionOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename Eigen::internal::nested<TensorReductionOp>::type Nested; - typedef typename Eigen::internal::traits<TensorReductionOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorReductionOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorReductionOp(const XprType& expr, const Dims& dims) : m_expr(expr), m_dims(dims) - { } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorReductionOp(const XprType& expr, const Dims& dims, const Op& reducer) : m_expr(expr), m_dims(dims), m_reducer(reducer) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const XprType& expression() const { return m_expr; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Dims& dims() const { return m_dims; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Op& reducer() const { return m_reducer; } - - protected: - typename XprType::Nested m_expr; - const Dims m_dims; - const Op m_reducer; -}; - -template<typename ArgType, typename Device> -struct TensorReductionEvaluatorBase; - -// Eval as rvalue -template<typename Op, typename Dims, typename ArgType, template <class> class MakePointer_, typename Device> -struct TensorReductionEvaluatorBase<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device> -{ - typedef internal::reducer_traits<Op, Device> ReducerTraits; - typedef Dims ReducedDims; - typedef TensorReductionOp<Op, Dims, ArgType, MakePointer_> XprType; - typedef typename XprType::Index Index; - typedef ArgType ChildType; - typedef typename TensorEvaluator<ArgType, Device>::Dimensions InputDimensions; - static const int NumInputDims = internal::array_size<InputDimensions>::value; - static const int NumReducedDims = internal::array_size<Dims>::value; - static const int NumOutputDims = NumInputDims - NumReducedDims; - typedef typename internal::conditional<NumOutputDims==0, Sizes<>, DSizes<Index, NumOutputDims> >::type Dimensions; - typedef typename XprType::Scalar Scalar; - typedef TensorReductionEvaluatorBase<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device> Self; - static const bool InputPacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess; - typedef typename internal::ReductionReturnType<Op, typename XprType::CoeffReturnType>::type CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const Index PacketSize = PacketType<CoeffReturnType, Device>::size; - - typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - // Subset of strides of the input tensor for the non-reduced dimensions. - // Indexed by output dimensions. - static const int NumPreservedStrides = max_n_1<NumOutputDims>::size; - - enum { - IsAligned = false, - PacketAccess = Self::InputPacketAccess && ReducerTraits::PacketAccess, - BlockAccess = false, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - static const bool ReducingInnerMostDims = internal::are_inner_most_dims<Dims, NumInputDims, Layout>::value; - static const bool PreservingInnerMostDims = internal::preserve_inner_most_dims<Dims, NumInputDims, Layout>::value; - static const bool RunningFullReduction = (NumOutputDims==0); - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorReductionEvaluatorBase(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_reducer(op.reducer()), m_result(NULL), m_device(device) - { - EIGEN_STATIC_ASSERT((NumInputDims >= NumReducedDims), YOU_MADE_A_PROGRAMMING_MISTAKE); - EIGEN_STATIC_ASSERT((!ReducingInnerMostDims | !PreservingInnerMostDims | (NumReducedDims == NumInputDims)), - YOU_MADE_A_PROGRAMMING_MISTAKE); - - // Build the bitmap indicating if an input dimension is reduced or not. - for (int i = 0; i < NumInputDims; ++i) { - m_reduced[i] = false; - } - for (int i = 0; i < NumReducedDims; ++i) { - eigen_assert(op.dims()[i] >= 0); - eigen_assert(op.dims()[i] < NumInputDims); - m_reduced[op.dims()[i]] = true; - } - - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - internal::DimInitializer<Dimensions>::run(input_dims, m_reduced, &m_dimensions, &m_reducedDims); - - // Precompute output strides. - if (NumOutputDims > 0) { - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_outputStrides[0] = 1; - for (int i = 1; i < NumOutputDims; ++i) { - m_outputStrides[i] = m_outputStrides[i - 1] * m_dimensions[i - 1]; - m_fastOutputStrides[i] = internal::TensorIntDivisor<Index>(m_outputStrides[i]); - } - } else { - m_outputStrides[NumOutputDims - 1] = 1; - for (int i = NumOutputDims - 2; i >= 0; --i) { - m_outputStrides[i] = m_outputStrides[i + 1] * m_dimensions[i + 1]; - m_fastOutputStrides[i] = internal::TensorIntDivisor<Index>(m_outputStrides[i]); - } - } - } - - // Precompute input strides. - if (NumInputDims > 0) { - array<Index, NumInputDims> input_strides; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - input_strides[0] = 1; - for (int i = 1; i < NumInputDims; ++i) { - input_strides[i] = input_strides[i-1] * input_dims[i-1]; - } - } else { - input_strides.back() = 1; - for (int i = NumInputDims - 2; i >= 0; --i) { - input_strides[i] = input_strides[i + 1] * input_dims[i + 1]; - } - } - - int outputIndex = 0; - int reduceIndex = 0; - for (int i = 0; i < NumInputDims; ++i) { - if (m_reduced[i]) { - m_reducedStrides[reduceIndex] = input_strides[i]; - ++reduceIndex; - } else { - m_preservedStrides[outputIndex] = input_strides[i]; - m_output_to_input_dim_map[outputIndex] = i; - ++outputIndex; - } - } - } - - // Special case for full reductions - if (NumOutputDims == 0) { - m_preservedStrides[0] = internal::array_prod(input_dims); - } - - m_numValuesToReduce = - NumOutputDims == 0 - ? internal::array_prod(input_dims) - : (static_cast<int>(Layout) == static_cast<int>(ColMajor)) - ? m_preservedStrides[0] - : m_preservedStrides[NumOutputDims - 1]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_STRONG_INLINE -#if !defined(EIGEN_HIPCC) - // Marking this as EIGEN_DEVICE_FUNC for HIPCC requires also doing the same - // for all the functions being called within here, which then leads to - // proliferation of EIGEN_DEVICE_FUNC markings, one of which will eventually - // result in an NVCC error - EIGEN_DEVICE_FUNC -#endif - bool evalSubExprsIfNeededCommon(EvaluatorPointerType data) { - // Use the FullReducer if possible. - if ((RunningFullReduction && RunningOnSycl) ||(RunningFullReduction && - internal::FullReducer<Self, Op, Device>::HasOptimizedImplementation && - ((RunningOnGPU && (m_device.majorDeviceVersion() >= 3)) || - !RunningOnGPU))) { - bool need_assign = false; - if (!data) { - m_result = static_cast<EvaluatorPointerType>(m_device.get((CoeffReturnType*)m_device.allocate_temp(sizeof(CoeffReturnType)))); - data = m_result; - need_assign = true; - } - Op reducer(m_reducer); - internal::FullReducer<Self, Op, Device>::run(*this, reducer, m_device, data); - return need_assign; - } - - // Attempt to use an optimized reduction. - else if ((RunningOnGPU && (m_device.majorDeviceVersion() >= 3)) || (RunningOnSycl)) { - bool reducing_inner_dims = true; - for (int i = 0; i < NumReducedDims; ++i) { - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - reducing_inner_dims &= m_reduced[i]; - } else { - reducing_inner_dims &= m_reduced[NumInputDims - 1 - i]; - } - } - if (internal::InnerReducer<Self, Op, Device>::HasOptimizedImplementation && - (reducing_inner_dims || ReducingInnerMostDims)) { - const Index num_values_to_reduce = internal::array_prod(m_reducedDims); - const Index num_coeffs_to_preserve = internal::array_prod(m_dimensions); - if (!data) { - if ((num_coeffs_to_preserve < 1024 && num_values_to_reduce > num_coeffs_to_preserve && num_values_to_reduce > 128) || (RunningOnSycl)) { - data = static_cast<EvaluatorPointerType>(m_device.get((CoeffReturnType*)m_device.allocate_temp(sizeof(CoeffReturnType) * num_coeffs_to_preserve))); - m_result = data; - } - else { - return true; - } - } - Op reducer(m_reducer); - // For SYCL this if always return false - if (internal::InnerReducer<Self, Op, Device>::run(*this, reducer, m_device, data, num_values_to_reduce, num_coeffs_to_preserve)) { - if (m_result) { - m_device.deallocate_temp(m_result); - m_result = NULL; - } - return true; - } else { - return (m_result != NULL); - } - } - - bool preserving_inner_dims = true; - for (int i = 0; i < NumReducedDims; ++i) { - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - preserving_inner_dims &= m_reduced[NumInputDims - 1 - i]; - } else { - preserving_inner_dims &= m_reduced[i]; - } - } - if (internal::OuterReducer<Self, Op, Device>::HasOptimizedImplementation && - preserving_inner_dims) { - const Index num_values_to_reduce = internal::array_prod(m_reducedDims); - const Index num_coeffs_to_preserve = internal::array_prod(m_dimensions); - if (!data) { - if ((num_coeffs_to_preserve < 1024 && num_values_to_reduce > num_coeffs_to_preserve && num_values_to_reduce > 32) || (RunningOnSycl)) { - data = static_cast<EvaluatorPointerType>(m_device.get((CoeffReturnType*)m_device.allocate_temp(sizeof(CoeffReturnType) * num_coeffs_to_preserve))); - m_result = data; - } - else { - return true; - } - } - Op reducer(m_reducer); - // For SYCL this if always return false - if (internal::OuterReducer<Self, Op, Device>::run(*this, reducer, m_device, data, num_values_to_reduce, num_coeffs_to_preserve)) { - if (m_result) { - m_device.deallocate_temp(m_result); - m_result = NULL; - } - return true; - } else { - return (m_result != NULL); - } - } - #if defined(EIGEN_USE_SYCL) - // If there is no Optimised version for SYCL, the reduction expression - // must break into two subexpression and use the SYCL generic Reducer on the device. - if(RunningOnSycl) { - const Index num_values_to_reduce = internal::array_prod(m_reducedDims); - const Index num_coeffs_to_preserve = internal::array_prod(m_dimensions); - if (!data) { - data = static_cast<EvaluatorPointerType>(m_device.get((CoeffReturnType*)m_device.allocate_temp(sizeof(CoeffReturnType) * num_coeffs_to_preserve))); - m_result = data; - } - Op reducer(m_reducer); - internal::GenericReducer<Self, Op, Device>::run(*this, reducer, m_device, data, num_values_to_reduce, num_coeffs_to_preserve); - return (m_result != NULL); - } - #endif - } - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_STRONG_INLINE -#if !defined(EIGEN_HIPCC) - EIGEN_DEVICE_FUNC -#endif - void - evalSubExprsIfNeededAsync(EvaluatorPointerType data, - EvalSubExprsCallback done) { - m_impl.evalSubExprsIfNeededAsync(NULL, [this, data, done](bool) { - done(evalSubExprsIfNeededCommon(data)); - }); - } -#endif - - EIGEN_STRONG_INLINE -#if !defined(EIGEN_HIPCC) - // Marking this as EIGEN_DEVICE_FUNC for HIPCC requires also doing the same - // for all the functions being called within here, which then leads to - // proliferation of EIGEN_DEVICE_FUNC markings, one of which will eventually - // result in an NVCC error - EIGEN_DEVICE_FUNC -#endif - bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - m_impl.evalSubExprsIfNeeded(NULL); - return evalSubExprsIfNeededCommon(data); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - if (m_result) { - m_device.deallocate_temp(m_result); - m_result = NULL; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - if (( RunningFullReduction || RunningOnGPU) && m_result ) { - return *(m_result + index); - } - Op reducer(m_reducer); - if (ReducingInnerMostDims || RunningFullReduction) { - const Index num_values_to_reduce = - (static_cast<int>(Layout) == static_cast<int>(ColMajor)) ? m_preservedStrides[0] : m_preservedStrides[NumPreservedStrides - 1]; - return internal::InnerMostDimReducer<Self, Op>::reduce(*this, firstInput(index), - num_values_to_reduce, reducer); - } else { - typename Self::CoeffReturnType accum = reducer.initialize(); - internal::GenericDimReducer<NumReducedDims-1, Self, Op>::reduce(*this, firstInput(index), reducer, &accum); - return reducer.finalize(accum); - } - } - - // TODO(bsteiner): provide a more efficient implementation. - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index + PacketSize - 1 < Index(internal::array_prod(dimensions()))); - - if (RunningOnGPU && m_result) { - return internal::pload<PacketReturnType>(m_result + index); - } - - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - if (ReducingInnerMostDims) { - const Index num_values_to_reduce = - (static_cast<int>(Layout) == static_cast<int>(ColMajor)) ? m_preservedStrides[0] : m_preservedStrides[NumPreservedStrides - 1]; - const Index firstIndex = firstInput(index); - for (Index i = 0; i < PacketSize; ++i) { - Op reducer(m_reducer); - values[i] = internal::InnerMostDimReducer<Self, Op>::reduce(*this, firstIndex + i * num_values_to_reduce, - num_values_to_reduce, reducer); - } - } else if (PreservingInnerMostDims) { - const Index firstIndex = firstInput(index); - const int innermost_dim = (static_cast<int>(Layout) == static_cast<int>(ColMajor)) ? 0 : NumOutputDims - 1; - // TBD: extend this the the n innermost dimensions that we preserve. - if (((firstIndex % m_dimensions[innermost_dim]) + PacketSize - 1) < m_dimensions[innermost_dim]) { - Op reducer(m_reducer); - typename Self::PacketReturnType accum = reducer.template initializePacket<typename Self::PacketReturnType>(); - internal::InnerMostDimPreserver<NumReducedDims-1, Self, Op>::reduce(*this, firstIndex, reducer, &accum); - return reducer.finalizePacket(accum); - } else { - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index + i); - } - } - } else { - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index + i); - } - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - - // Must be called after evalSubExprsIfNeeded(). - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - if (RunningFullReduction && m_result) { - return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize); - } else { - const Index num_values_to_reduce = internal::array_prod(m_reducedDims); - const double compute_cost = num_values_to_reduce * internal::functor_traits<Op>::Cost; - return m_impl.costPerCoeff(vectorized) * num_values_to_reduce + - TensorOpCost(0, 0, compute_cost, vectorized, PacketSize); - } - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_result; } - EIGEN_DEVICE_FUNC const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; } - EIGEN_DEVICE_FUNC const Device& device() const { return m_device; } -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - m_result.bind(cgh); - } -#endif - - private: - template <int, typename, typename> friend struct internal::GenericDimReducer; - template <typename, typename, bool, bool> friend struct internal::InnerMostDimReducer; - template <int, typename, typename, bool> friend struct internal::InnerMostDimPreserver; - template <typename S, typename O, typename D, bool V> friend struct internal::FullReducer; -#ifdef EIGEN_USE_THREADS - template <typename S, typename O, bool V> friend struct internal::FullReducerShard; -#endif -#if defined(EIGEN_USE_GPU) && (defined(EIGEN_GPUCC)) - template <int B, int N, typename S, typename R, typename I_> KERNEL_FRIEND void internal::FullReductionKernel(R, const S, I_, typename S::CoeffReturnType*, unsigned int*); -#if defined(EIGEN_HAS_GPU_FP16) - template <typename S, typename R, typename I_> KERNEL_FRIEND void internal::ReductionInitFullReduxKernelHalfFloat(R, const S, I_, half2*); - template <int B, int N, typename S, typename R, typename I_> KERNEL_FRIEND void internal::FullReductionKernelHalfFloat(R, const S, I_, half*, half2*); - template <int NPT, typename S, typename R, typename I_> KERNEL_FRIEND void internal::InnerReductionKernelHalfFloat(R, const S, I_, I_, half*); -#endif - template <int NPT, typename S, typename R, typename I_> KERNEL_FRIEND void internal::InnerReductionKernel(R, const S, I_, I_, typename S::CoeffReturnType*); - - template <int NPT, typename S, typename R, typename I_> KERNEL_FRIEND void internal::OuterReductionKernel(R, const S, I_, I_, typename S::CoeffReturnType*); -#endif - -#if defined(EIGEN_USE_SYCL) - template < typename Evaluator_, typename Op__> friend class TensorSycl::internal::GenericNondeterministicReducer; - // SYCL need the Generic reducer for the case the recution algorithm is neither inner, outer, and full reducer - template <typename, typename, typename> friend struct internal::GenericReducer; -#endif - - - template <typename S, typename O, typename D> friend struct internal::InnerReducer; - - struct BlockIteratorState { - Index input_dim; - Index output_size; - Index output_count; - }; - - // Returns the Index in the input tensor of the first value that needs to be - // used to compute the reduction at output index "index". - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index firstInput(Index index) const { - if (ReducingInnerMostDims) { - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - return index * m_preservedStrides[0]; - } else { - return index * m_preservedStrides[NumPreservedStrides - 1]; - } - } - // TBD: optimize the case where we preserve the innermost dimensions. - Index startInput = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumOutputDims - 1; i > 0; --i) { - // This is index_i in the output tensor. - const Index idx = index / m_outputStrides[i]; - startInput += idx * m_preservedStrides[i]; - index -= idx * m_outputStrides[i]; - } - if (PreservingInnerMostDims) { - eigen_assert(m_preservedStrides[0] == 1); - startInput += index; - } else { - startInput += index * m_preservedStrides[0]; - } - } else { - for (int i = 0; i < NumOutputDims - 1; ++i) { - // This is index_i in the output tensor. - const Index idx = index / m_outputStrides[i]; - startInput += idx * m_preservedStrides[i]; - index -= idx * m_outputStrides[i]; - } - if (PreservingInnerMostDims) { - eigen_assert(m_preservedStrides[NumPreservedStrides - 1] == 1); - startInput += index; - } else { - startInput += index * m_preservedStrides[NumPreservedStrides - 1]; - } - } - return startInput; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void GetInputCoordsForOutputIndex( - Index index, - DSizes<Index, NumInputDims>* coords) const { - for (int i = 0; i < NumInputDims; ++i) { - (*coords)[i] = 0; - } - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumOutputDims - 1; i > 0; --i) { - const Index idx = index / m_fastOutputStrides[i]; - (*coords)[m_output_to_input_dim_map[i]] = idx; - index -= idx * m_outputStrides[i]; - } - (*coords)[m_output_to_input_dim_map[0]] = index; - } else { - for (int i = 0; i < NumOutputDims - 1; ++i) { - const Index idx = index / m_fastOutputStrides[i]; - (*coords)[m_output_to_input_dim_map[i]] = idx; - index -= idx * m_outputStrides[i]; - } - (*coords)[m_output_to_input_dim_map[NumOutputDims-1]] = index; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void CalculateTargetInputBlockShape( - const Index max_coeff_count, - const DSizes<Index, NumInputDims>& input_slice_sizes, - DSizes<Index, NumInputDims>* target_input_block_sizes) const { - typedef internal::BlockReducer<Self, Op> BlockReducer; - // TODO(andydavis) Compute reducer overhead correctly for the case where - // we are preserving the inner most dimension, and a single reducer - // reduces a packet's worth of output coefficients. - const Index reducer_overhead = sizeof(BlockReducer) / sizeof(Scalar); - - Index coeff_to_allocate = max_coeff_count; - bool first_preserved_dim_allocated = false; - bool first_reduced_dim_allocated = false; - for (int i = 0; i < NumInputDims; ++i) { - const int dim = static_cast<int>(Layout) == static_cast<int>(ColMajor) - ? i - : NumInputDims - i - 1; - (*target_input_block_sizes)[dim] = 1; - if (m_reduced[dim]) { - // TODO(andydavis) Consider allocating to multiple reduced dimensions. - // Watch out for cases where reduced dimensions are not contiguous, - // which induces scattered reads. - if (!first_reduced_dim_allocated) { - (*target_input_block_sizes)[dim] = - numext::mini(input_slice_sizes[dim], coeff_to_allocate); - coeff_to_allocate /= (*target_input_block_sizes)[dim]; - first_reduced_dim_allocated = true; - } - } else if (!first_preserved_dim_allocated) { - // TODO(andydavis) Include output block size in this L1 working set - // calculation. - const Index alloc_size = numext::maxi( - static_cast<Index>(1), coeff_to_allocate / reducer_overhead); - (*target_input_block_sizes)[dim] = - numext::mini(input_slice_sizes[dim], alloc_size); - coeff_to_allocate = numext::maxi( - static_cast<Index>(1), - coeff_to_allocate / - ((*target_input_block_sizes)[dim] * reducer_overhead)); - first_preserved_dim_allocated = true; - } - } - } - - // Bitmap indicating if an input dimension is reduced or not. - array<bool, NumInputDims> m_reduced; - // Dimensions of the output of the operation. - Dimensions m_dimensions; - // Precomputed strides for the output tensor. - array<Index, NumOutputDims> m_outputStrides; - array<internal::TensorIntDivisor<Index>, NumOutputDims> m_fastOutputStrides; - array<Index, NumPreservedStrides> m_preservedStrides; - // Map from output to input dimension index. - array<Index, NumOutputDims> m_output_to_input_dim_map; - // How many values go into each reduction - Index m_numValuesToReduce; - - // Subset of strides of the input tensor for the reduced dimensions. - // Indexed by reduced dimensions. - array<Index, NumReducedDims> m_reducedStrides; - // Size of the input dimensions that are reduced. - // Indexed by reduced dimensions. - array<Index, NumReducedDims> m_reducedDims; - - // Evaluator for the input expression. - TensorEvaluator<ArgType, Device> m_impl; - - // Operation to apply for computing the reduction. - Op m_reducer; - - // For full reductions -#if defined(EIGEN_USE_GPU) && (defined(EIGEN_GPUCC)) - static const bool RunningOnGPU = internal::is_same<Device, Eigen::GpuDevice>::value; - static const bool RunningOnSycl = false; -#elif defined(EIGEN_USE_SYCL) -static const bool RunningOnSycl = internal::is_same<typename internal::remove_all<Device>::type, Eigen::SyclDevice>::value; -static const bool RunningOnGPU = false; -#else - static const bool RunningOnGPU = false; - static const bool RunningOnSycl = false; -#endif - EvaluatorPointerType m_result; - - const Device EIGEN_DEVICE_REF m_device; -}; - -template<typename Op, typename Dims, typename ArgType, template <class> class MakePointer_, typename Device> -struct TensorEvaluator<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device> -: public TensorReductionEvaluatorBase<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device> { - typedef TensorReductionEvaluatorBase<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device> Base; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const typename Base::XprType& op, const Device& device) : Base(op, device){} -}; - - -template<typename Op, typename Dims, typename ArgType, template <class> class MakePointer_> -struct TensorEvaluator<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Eigen::SyclDevice> -: public TensorReductionEvaluatorBase<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Eigen::SyclDevice> { - - typedef TensorReductionEvaluatorBase<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Eigen::SyclDevice> Base; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const typename Base::XprType& op, const Eigen::SyclDevice& device) : Base(op, device){} - // The coeff function in the base the recursive method which is not an standard layout and cannot be used in the SYCL kernel - //Therefore the coeff function should be overridden by for SYCL kernel - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Base::CoeffReturnType coeff(typename Base::Index index) const { - return *(this->data() + index); - } - // The packet function in the base the recursive method which is not an standard layout and cannot be used in the SYCL kernel - //Therefore the packet function should be overridden by for SYCL kernel - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename Base::PacketReturnType packet(typename Base::Index index) const { - return internal::pload<typename Base::PacketReturnType>(this->data() + index); - } -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_REDUCTION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h deleted file mode 100644 index 68780cd3..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionCuda.h +++ /dev/null @@ -1,6 +0,0 @@ - -#if defined(__clang__) || defined(__GNUC__) -#warning "Deprecated header file, please either include the main Eigen/CXX11/Tensor header or the respective TensorReductionGpu.h file" -#endif - -#include "TensorReductionGpu.h" diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionGpu.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionGpu.h deleted file mode 100644 index 095bb54c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionGpu.h +++ /dev/null @@ -1,821 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_REDUCTION_GPU_H -#define EIGEN_CXX11_TENSOR_TENSOR_REDUCTION_GPU_H - -namespace Eigen { -namespace internal { - - -#if defined(EIGEN_USE_GPU) && defined(EIGEN_GPUCC) -// Full reducers for GPU, don't vectorize for now - -// Reducer function that enables multiple gpu thread to safely accumulate at the same -// output address. It basically reads the current value of the output variable, and -// attempts to update it with the new value. If in the meantime another gpu thread -// updated the content of the output address it will try again. -template <typename T, typename R> -__device__ EIGEN_ALWAYS_INLINE void atomicReduce(T* output, T accum, R& reducer) { -#if (defined(EIGEN_HIP_DEVICE_COMPILE) && defined(__HIP_ARCH_HAS_WARP_SHUFFLE__)) || (EIGEN_CUDA_ARCH >= 300) - if (sizeof(T) == 4) - { - unsigned int oldval = *reinterpret_cast<unsigned int*>(output); - unsigned int newval = oldval; - reducer.reduce(accum, reinterpret_cast<T*>(&newval)); - if (newval == oldval) { - return; - } - unsigned int readback; - while ((readback = atomicCAS((unsigned int*)output, oldval, newval)) != oldval) { - oldval = readback; - newval = oldval; - reducer.reduce(accum, reinterpret_cast<T*>(&newval)); - if (newval == oldval) { - return; - } - } - } - else if (sizeof(T) == 8) { - unsigned long long oldval = *reinterpret_cast<unsigned long long*>(output); - unsigned long long newval = oldval; - reducer.reduce(accum, reinterpret_cast<T*>(&newval)); - if (newval == oldval) { - return; - } - unsigned long long readback; - while ((readback = atomicCAS((unsigned long long*)output, oldval, newval)) != oldval) { - oldval = readback; - newval = oldval; - reducer.reduce(accum, reinterpret_cast<T*>(&newval)); - if (newval == oldval) { - return; - } - } - } - else { - gpu_assert(0 && "Wordsize not supported"); - } -#else // EIGEN_CUDA_ARCH >= 300 - gpu_assert(0 && "Shouldn't be called on unsupported device"); -#endif // EIGEN_CUDA_ARCH >= 300 -} - -// We extend atomicExch to support extra data types -template <typename Type> -__device__ inline Type atomicExchCustom(Type* address, Type val) { - return atomicExch(address, val); -} - -template <> -__device__ inline double atomicExchCustom(double* address, double val) { - unsigned long long int* address_as_ull = reinterpret_cast<unsigned long long int*>(address); - return __longlong_as_double(atomicExch(address_as_ull, __double_as_longlong(val))); -} - -#ifdef EIGEN_HAS_GPU_FP16 -template <template <typename T> class R> -__device__ inline void atomicReduce(half2* output, half2 accum, R<half>& reducer) { - unsigned int oldval = *reinterpret_cast<unsigned int*>(output); - unsigned int newval = oldval; - reducer.reducePacket(accum, reinterpret_cast<half2*>(&newval)); - if (newval == oldval) { - return; - } - unsigned int readback; - while ((readback = atomicCAS((unsigned int*)output, oldval, newval)) != oldval) { - oldval = readback; - newval = oldval; - reducer.reducePacket(accum, reinterpret_cast<half2*>(&newval)); - if (newval == oldval) { - return; - } - } -} -#endif // EIGEN_HAS_GPU_FP16 - -template <> -__device__ inline void atomicReduce(float* output, float accum, SumReducer<float>&) { -#if (defined(EIGEN_HIP_DEVICE_COMPILE) && defined(__HIP_ARCH_HAS_WARP_SHUFFLE__)) || (EIGEN_CUDA_ARCH >= 300) - atomicAdd(output, accum); -#else // EIGEN_CUDA_ARCH >= 300 - gpu_assert(0 && "Shouldn't be called on unsupported device"); -#endif // EIGEN_CUDA_ARCH >= 300 -} - - -template <typename CoeffType, typename Index> -__global__ void ReductionInitKernel(const CoeffType val, Index num_preserved_coeffs, CoeffType* output) { - const Index thread_id = blockIdx.x * blockDim.x + threadIdx.x; - const Index num_threads = blockDim.x * gridDim.x; - for (Index i = thread_id; i < num_preserved_coeffs; i += num_threads) { - output[i] = val; - } -} - - -template <int BlockSize, int NumPerThread, typename Self, - typename Reducer, typename Index> -__global__ void FullReductionKernel(Reducer reducer, const Self input, Index num_coeffs, - typename Self::CoeffReturnType* output, unsigned int* semaphore) { -#if (defined(EIGEN_HIP_DEVICE_COMPILE) && defined(__HIP_ARCH_HAS_WARP_SHUFFLE__)) || (EIGEN_CUDA_ARCH >= 300) - // Initialize the output value - const Index first_index = blockIdx.x * BlockSize * NumPerThread + threadIdx.x; - if (gridDim.x == 1) { - if (first_index == 0) { - *output = reducer.initialize(); - } - } - else { - if (threadIdx.x == 0) { - unsigned int block = atomicCAS(semaphore, 0u, 1u); - if (block == 0) { - // We're the first block to run, initialize the output value - atomicExchCustom(output, reducer.initialize()); - __threadfence(); - atomicExch(semaphore, 2u); - } - else { - // Wait for the first block to initialize the output value. - // Use atomicCAS here to ensure that the reads aren't cached - unsigned int val; - do { - val = atomicCAS(semaphore, 2u, 2u); - } - while (val < 2u); - } - } - } - - __syncthreads(); - - eigen_assert(gridDim.x == 1 || *semaphore >= 2u); - - typename Self::CoeffReturnType accum = reducer.initialize(); - Index max_iter = numext::mini<Index>(num_coeffs - first_index, NumPerThread*BlockSize); - for (Index i = 0; i < max_iter; i+=BlockSize) { - const Index index = first_index + i; - eigen_assert(index < num_coeffs); - typename Self::CoeffReturnType val = input.m_impl.coeff(index); - reducer.reduce(val, &accum); - } - -#pragma unroll - for (int offset = warpSize/2; offset > 0; offset /= 2) { - #if defined(EIGEN_HIPCC) - // use std::is_floating_point to determine the type of reduced_val - // This is needed because when Type == double, hipcc will give a "call to __shfl_down is ambguous" error - // and list the float and int versions of __shfl_down as the candidate functions. - if (std::is_floating_point<typename Self::CoeffReturnType>::value) { - reducer.reduce(__shfl_down(static_cast<float>(accum), offset, warpSize), &accum); - } else { - reducer.reduce(__shfl_down(static_cast<int>(accum), offset, warpSize), &accum); - } - #elif defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000 - reducer.reduce(__shfl_down(accum, offset, warpSize), &accum); - #else - reducer.reduce(__shfl_down_sync(0xFFFFFFFF, accum, offset, warpSize), &accum); - #endif - } - - if ((threadIdx.x & (warpSize - 1)) == 0) { - atomicReduce(output, accum, reducer); - } - - if (gridDim.x > 1 && threadIdx.x == 0) { - // Let the last block reset the semaphore - atomicInc(semaphore, gridDim.x + 1); -#if defined(EIGEN_HIPCC) - __threadfence_system(); -#endif - } -#else // EIGEN_CUDA_ARCH >= 300 - gpu_assert(0 && "Shouldn't be called on unsupported device"); -#endif // EIGEN_CUDA_ARCH >= 300 -} - - -#ifdef EIGEN_HAS_GPU_FP16 -template <typename Self, - typename Reducer, typename Index> -__global__ void ReductionInitFullReduxKernelHalfFloat(Reducer reducer, const Self input, Index num_coeffs, half2* scratch) { - eigen_assert(blockDim.x == 1); - eigen_assert(gridDim.x == 1); - if (num_coeffs % 2 != 0) { - half lastCoeff = input.m_impl.coeff(num_coeffs-1); - *scratch = __halves2half2(lastCoeff, reducer.initialize()); - } else { - *scratch = reducer.template initializePacket<half2>(); - } -} - -template <typename Self, - typename Reducer, typename Index> -__global__ void ReductionInitKernelHalfFloat(Reducer reducer, const Self input, Index num_coeffs, half* output) { - const Index thread_id = blockIdx.x * blockDim.x + threadIdx.x; - const Index num_threads = blockDim.x * gridDim.x; - const Index num_packets = num_coeffs / 2; - for (Index i = thread_id; i < num_packets; i += num_threads) { - ((half2*)output)[i] = reducer.template initializePacket<half2>(); - } - - if (thread_id == 0 && num_coeffs % 2 != 0) { - output[num_coeffs-1] = reducer.initialize(); - } -} - -template <int BlockSize, int NumPerThread, typename Self, - typename Reducer, typename Index> -__global__ void FullReductionKernelHalfFloat(Reducer reducer, const Self input, Index num_coeffs, - half* output, half2* scratch) { - eigen_assert(NumPerThread % 2 == 0); - - const Index first_index = blockIdx.x * BlockSize * NumPerThread + 2*threadIdx.x; - - // Initialize the output value if it wasn't initialized by the ReductionInitKernel - - if (gridDim.x == 1) { - if (first_index == 0) { - if (num_coeffs % 2 != 0) { - half last = input.m_impl.coeff(num_coeffs-1); - *scratch = __halves2half2(last, reducer.initialize()); - } else { - *scratch = reducer.template initializePacket<half2>(); - } - } - __syncthreads(); - } - - half2 accum = reducer.template initializePacket<half2>(); - const Index max_iter = numext::mini<Index>((num_coeffs - first_index) / 2, NumPerThread*BlockSize / 2); - for (Index i = 0; i < max_iter; i += BlockSize) { - const Index index = first_index + 2*i; - eigen_assert(index + 1 < num_coeffs); - half2 val = input.m_impl.template packet<Unaligned>(index); - reducer.reducePacket(val, &accum); - } - -#pragma unroll - for (int offset = warpSize/2; offset > 0; offset /= 2) { - #if defined(EIGEN_HIPCC) - // FIXME : remove this workaround once we have native half/half2 support for __shfl_down - union { int i; half2 h; } wka_in, wka_out; - wka_in.h = accum; - wka_out.i = __shfl_down(wka_in.i, offset, warpSize); - reducer.reducePacket(wka_out.h, &accum); - #elif defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000 - reducer.reducePacket(__shfl_down(accum, offset, warpSize), &accum); - #else - int temp = __shfl_down_sync(0xFFFFFFFF, *(int*)(&accum), (unsigned)offset, warpSize); - reducer.reducePacket(*(half2*)(&temp), &accum); - #endif - } - - if ((threadIdx.x & (warpSize - 1)) == 0) { - atomicReduce(scratch, accum, reducer); - } - - if (gridDim.x == 1) { - __syncthreads(); - if (first_index == 0) { - half tmp = __low2half(*scratch); - reducer.reduce(__high2half(*scratch), &tmp); - *output = tmp; - } - } -} - -template <typename Op> -__global__ void ReductionCleanupKernelHalfFloat(Op reducer, half* output, half2* scratch) { - eigen_assert(threadIdx.x == 1); - half tmp = __low2half(*scratch); - reducer.reduce(__high2half(*scratch), &tmp); - *output = tmp; -} - -#endif // EIGEN_HAS_GPU_FP16 - -template <typename Self, typename Op, typename OutputType, bool PacketAccess, typename Enabled = void> -struct FullReductionLauncher { - static void run(const Self&, Op&, const GpuDevice&, OutputType*, typename Self::Index) { - gpu_assert(false && "Should only be called on doubles, floats and half floats"); - } -}; - -// Specialization for float and double -template <typename Self, typename Op, typename OutputType, bool PacketAccess> -struct FullReductionLauncher< - Self, Op, OutputType, PacketAccess, - typename internal::enable_if< - internal::is_same<float, OutputType>::value || - internal::is_same<double, OutputType>::value, - void>::type> { - static void run(const Self& self, Op& reducer, const GpuDevice& device, OutputType* output, typename Self::Index num_coeffs) { - - typedef typename Self::Index Index; - const int block_size = 256; - const int num_per_thread = 128; - const int num_blocks = divup<int>(num_coeffs, block_size * num_per_thread); - - unsigned int* semaphore = NULL; - if (num_blocks > 1) { - semaphore = device.semaphore(); - } - - LAUNCH_GPU_KERNEL((FullReductionKernel<block_size, num_per_thread, Self, Op, Index>), - num_blocks, block_size, 0, device, reducer, self, num_coeffs, output, semaphore); - } -}; - -#ifdef EIGEN_HAS_GPU_FP16 -template <typename Self, typename Op> -struct FullReductionLauncher<Self, Op, Eigen::half, false> { - static void run(const Self&, Op&, const GpuDevice&, half*, typename Self::Index) { - gpu_assert(false && "Should not be called since there is no packet accessor"); - } -}; - -template <typename Self, typename Op> -struct FullReductionLauncher<Self, Op, Eigen::half, true> { - static void run(const Self& self, Op& reducer, const GpuDevice& device, half* output, typename Self::Index num_coeffs) { - typedef typename Self::Index Index; - - const int block_size = 256; - const int num_per_thread = 128; - const int num_blocks = divup<int>(num_coeffs, block_size * num_per_thread); - half2* scratch = static_cast<half2*>(device.scratchpad()); - - if (num_blocks > 1) { - // We initialize the output and the scrathpad outside the reduction kernel when we can't be sure that there - // won't be a race conditions between multiple thread blocks. - LAUNCH_GPU_KERNEL((ReductionInitFullReduxKernelHalfFloat<Self, Op, Index>), - 1, 1, 0, device, reducer, self, num_coeffs, scratch); - } - - LAUNCH_GPU_KERNEL((FullReductionKernelHalfFloat<block_size, num_per_thread, Self, Op, Index>), - num_blocks, block_size, 0, device, reducer, self, num_coeffs, output, scratch); - - if (num_blocks > 1) { - LAUNCH_GPU_KERNEL((ReductionCleanupKernelHalfFloat<Op>), - 1, 1, 0, device, reducer, output, scratch); - } - } -}; -#endif // EIGEN_HAS_GPU_FP16 - - -template <typename Self, typename Op, bool Vectorizable> -struct FullReducer<Self, Op, GpuDevice, Vectorizable> { - // Unfortunately nvidia doesn't support well exotic types such as complex, - // so reduce the scope of the optimized version of the code to the simple cases - // of doubles, floats and half floats -#ifdef EIGEN_HAS_GPU_FP16 - static const bool HasOptimizedImplementation = !Self::ReducerTraits::IsStateful && - (internal::is_same<typename Self::CoeffReturnType, float>::value || - internal::is_same<typename Self::CoeffReturnType, double>::value || - (internal::is_same<typename Self::CoeffReturnType, Eigen::half>::value && reducer_traits<Op, GpuDevice>::PacketAccess)); -#else // EIGEN_HAS_GPU_FP16 - static const bool HasOptimizedImplementation = !Self::ReducerTraits::IsStateful && - (internal::is_same<typename Self::CoeffReturnType, float>::value || - internal::is_same<typename Self::CoeffReturnType, double>::value); -#endif // EIGEN_HAS_GPU_FP16 - - template <typename OutputType> - static void run(const Self& self, Op& reducer, const GpuDevice& device, OutputType* output) { - gpu_assert(HasOptimizedImplementation && "Should only be called on doubles, floats or half floats"); - const Index num_coeffs = array_prod(self.m_impl.dimensions()); - // Don't crash when we're called with an input tensor of size 0. - if (num_coeffs == 0) { - return; - } - - FullReductionLauncher<Self, Op, OutputType, reducer_traits<Op, GpuDevice>::PacketAccess>::run(self, reducer, device, output, num_coeffs); - } -}; - - -template <int NumPerThread, typename Self, - typename Reducer, typename Index> -__global__ void InnerReductionKernel(Reducer reducer, const Self input, Index num_coeffs_to_reduce, Index num_preserved_coeffs, - typename Self::CoeffReturnType* output) { -#if (defined(EIGEN_HIP_DEVICE_COMPILE) && defined(__HIP_ARCH_HAS_WARP_SHUFFLE__)) || (EIGEN_CUDA_ARCH >= 300) - typedef typename Self::CoeffReturnType Type; - eigen_assert(blockDim.y == 1); - eigen_assert(blockDim.z == 1); - eigen_assert(gridDim.y == 1); - eigen_assert(gridDim.z == 1); - - const int unroll_times = 16; - eigen_assert(NumPerThread % unroll_times == 0); - - const Index input_col_blocks = divup<Index>(num_coeffs_to_reduce, blockDim.x * NumPerThread); - const Index num_input_blocks = input_col_blocks * num_preserved_coeffs; - - const Index num_threads = blockDim.x * gridDim.x; - const Index thread_id = blockIdx.x * blockDim.x + threadIdx.x; - - // Initialize the output values if they weren't initialized by the ReductionInitKernel - if (gridDim.x == 1) { - for (Index i = thread_id; i < num_preserved_coeffs; i += num_threads) { - output[i] = reducer.initialize(); - } - __syncthreads(); - } - - for (Index i = blockIdx.x; i < num_input_blocks; i += gridDim.x) { - const Index row = i / input_col_blocks; - - if (row < num_preserved_coeffs) { - const Index col_block = i % input_col_blocks; - const Index col_begin = col_block * blockDim.x * NumPerThread + threadIdx.x; - - Type reduced_val = reducer.initialize(); - - for (Index j = 0; j < NumPerThread; j += unroll_times) { - const Index last_col = col_begin + blockDim.x * (j + unroll_times - 1); - if (last_col >= num_coeffs_to_reduce) { - for (Index col = col_begin + blockDim.x * j; col < num_coeffs_to_reduce; col += blockDim.x) { - const Type val = input.m_impl.coeff(row * num_coeffs_to_reduce + col); - reducer.reduce(val, &reduced_val); - } - break; - } else { - // Faster version of the loop with no branches after unrolling. -#pragma unroll - for (int k = 0; k < unroll_times; ++k) { - const Index col = col_begin + blockDim.x * (j + k); - reducer.reduce(input.m_impl.coeff(row * num_coeffs_to_reduce + col), &reduced_val); - } - } - } - -#pragma unroll - for (int offset = warpSize/2; offset > 0; offset /= 2) { - #if defined(EIGEN_HIPCC) - // use std::is_floating_point to determine the type of reduced_val - // This is needed because when Type == double, hipcc will give a "call to __shfl_down is ambguous" error - // and list the float and int versions of __shfl_down as the candidate functions. - if (std::is_floating_point<Type>::value) { - reducer.reduce(__shfl_down(static_cast<float>(reduced_val), offset), &reduced_val); - } else { - reducer.reduce(__shfl_down(static_cast<int>(reduced_val), offset), &reduced_val); - } - #elif defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000 - reducer.reduce(__shfl_down(reduced_val, offset), &reduced_val); - #else - reducer.reduce(__shfl_down_sync(0xFFFFFFFF, reduced_val, offset), &reduced_val); - #endif - } - - if ((threadIdx.x & (warpSize - 1)) == 0) { - atomicReduce(&(output[row]), reduced_val, reducer); - } - } - } -#else // EIGEN_CUDA_ARCH >= 300 - gpu_assert(0 && "Shouldn't be called on unsupported device"); -#endif // EIGEN_CUDA_ARCH >= 300 -} - -#ifdef EIGEN_HAS_GPU_FP16 - -template <int NumPerThread, typename Self, - typename Reducer, typename Index> -__global__ void InnerReductionKernelHalfFloat(Reducer reducer, const Self input, Index num_coeffs_to_reduce, Index num_preserved_coeffs, - half* output) { - eigen_assert(blockDim.y == 1); - eigen_assert(blockDim.z == 1); - eigen_assert(gridDim.y == 1); - eigen_assert(gridDim.z == 1); - - const int unroll_times = 16; - eigen_assert(NumPerThread % unroll_times == 0); - eigen_assert(unroll_times % 2 == 0); - - const Index input_col_blocks = divup<Index>(num_coeffs_to_reduce, blockDim.x * NumPerThread * 2); - const Index num_input_blocks = divup<Index>(input_col_blocks * num_preserved_coeffs, 2); - - const Index num_threads = blockDim.x * gridDim.x; - const Index thread_id = blockIdx.x * blockDim.x + threadIdx.x; - - // Initialize the output values if they weren't initialized by the ReductionInitKernel - if (gridDim.x == 1) { - Index i = 2*thread_id; - for (; i + 1 < num_preserved_coeffs; i += 2*num_threads) { - half* loc = output + i; - *((half2*)loc) = reducer.template initializePacket<half2>(); - } - if (i < num_preserved_coeffs) { - output[i] = reducer.initialize(); - } - __syncthreads(); - } - - for (Index i = blockIdx.x; i < num_input_blocks; i += gridDim.x) { - const Index row = 2 * (i / input_col_blocks); - - if (row + 1 < num_preserved_coeffs) { - const Index col_block = i % input_col_blocks; - const Index col_begin = 2 * (col_block * blockDim.x * NumPerThread + threadIdx.x); - - half2 reduced_val1 = reducer.template initializePacket<half2>(); - half2 reduced_val2 = reducer.template initializePacket<half2>(); - - for (Index j = 0; j < NumPerThread; j += unroll_times) { - const Index last_col = col_begin + blockDim.x * (j + unroll_times - 1) * 2; - if (last_col >= num_coeffs_to_reduce) { - Index col = col_begin + blockDim.x * j; - for (; col + 1 < num_coeffs_to_reduce; col += blockDim.x) { - const half2 val1 = input.m_impl.template packet<Unaligned>(row * num_coeffs_to_reduce + col); - reducer.reducePacket(val1, &reduced_val1); - const half2 val2 = input.m_impl.template packet<Unaligned>((row+1) * num_coeffs_to_reduce + col); - reducer.reducePacket(val2, &reduced_val2); - } - if (col < num_coeffs_to_reduce) { - // Peel; - const half last1 = input.m_impl.coeff(row * num_coeffs_to_reduce + col); - const half2 val1 = __halves2half2(last1, reducer.initialize()); - reducer.reducePacket(val1, &reduced_val1); - const half last2 = input.m_impl.coeff((row+1) * num_coeffs_to_reduce + col); - const half2 val2 = __halves2half2(last2, reducer.initialize()); - reducer.reducePacket(val2, &reduced_val2); - } - break; - } else { - // Faster version of the loop with no branches after unrolling. -#pragma unroll - for (int k = 0; k < unroll_times; ++k) { - const Index col = col_begin + blockDim.x * (j + k) * 2; - reducer.reducePacket(input.m_impl.template packet<Unaligned>(row * num_coeffs_to_reduce + col), &reduced_val1); - reducer.reducePacket(input.m_impl.template packet<Unaligned>((row + 1)* num_coeffs_to_reduce + col), &reduced_val2); - } - } - } - -#pragma unroll - for (int offset = warpSize/2; offset > 0; offset /= 2) { - #if defined(EIGEN_HIPCC) - // FIXME : remove this workaround once we have native half/half2 support for __shfl_down - union { int i; half2 h; } wka_in, wka_out; - - wka_in.h = reduced_val1; - wka_out.i = __shfl_down(wka_in.i, offset, warpSize); - reducer.reducePacket(wka_out.h, &reduced_val1); - - wka_in.h = reduced_val2; - wka_out.i = __shfl_down(wka_in.i, offset, warpSize); - reducer.reducePacket(wka_out.h, &reduced_val2); - #elif defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000 - reducer.reducePacket(__shfl_down(reduced_val1, offset, warpSize), &reduced_val1); - reducer.reducePacket(__shfl_down(reduced_val2, offset, warpSize), &reduced_val2); - #else - int temp1 = __shfl_down_sync(0xFFFFFFFF, *(int*)(&reduced_val1), (unsigned)offset, warpSize); - int temp2 = __shfl_down_sync(0xFFFFFFFF, *(int*)(&reduced_val2), (unsigned)offset, warpSize); - reducer.reducePacket(*(half2*)(&temp1), &reduced_val1); - reducer.reducePacket(*(half2*)(&temp2), &reduced_val2); - #endif - } - - half val1 = __low2half(reduced_val1); - reducer.reduce(__high2half(reduced_val1), &val1); - half val2 = __low2half(reduced_val2); - reducer.reduce(__high2half(reduced_val2), &val2); - half2 val = __halves2half2(val1, val2); - - if ((threadIdx.x & (warpSize - 1)) == 0) { - half* loc = output + row; - atomicReduce((half2*)loc, val, reducer); - } - } - } -} - -#endif // EIGEN_HAS_GPU_FP16 - -template <typename Self, typename Op, typename OutputType, bool PacketAccess, typename Enabled = void> -struct InnerReductionLauncher { - static EIGEN_DEVICE_FUNC bool run(const Self&, Op&, const GpuDevice&, OutputType*, typename Self::Index, typename Self::Index) { - gpu_assert(false && "Should only be called to reduce doubles, floats and half floats on a gpu device"); - return true; - } -}; - -// Specialization for float and double -template <typename Self, typename Op, typename OutputType, bool PacketAccess> -struct InnerReductionLauncher< - Self, Op, OutputType, PacketAccess, - typename internal::enable_if< - internal::is_same<float, OutputType>::value || - internal::is_same<double, OutputType>::value, - void>::type> { - static bool run(const Self& self, Op& reducer, const GpuDevice& device, OutputType* output, typename Self::Index num_coeffs_to_reduce, typename Self::Index num_preserved_vals) { - typedef typename Self::Index Index; - - const Index num_coeffs = num_coeffs_to_reduce * num_preserved_vals; - const int block_size = 256; - const int num_per_thread = 128; - const int dyn_blocks = divup<int>(num_coeffs, block_size * num_per_thread); - const int max_blocks = device.getNumGpuMultiProcessors() * - device.maxGpuThreadsPerMultiProcessor() / block_size; - const int num_blocks = numext::mini<int>(max_blocks, dyn_blocks); - - if (num_blocks > 1) { - // We initialize the outputs outside the reduction kernel when we can't be sure that there - // won't be a race conditions between multiple thread blocks. - const int dyn_blocks = divup<int>(num_preserved_vals, 1024); - const int max_blocks = device.getNumGpuMultiProcessors() * - device.maxGpuThreadsPerMultiProcessor() / 1024; - const int num_blocks = numext::mini<int>(max_blocks, dyn_blocks); - LAUNCH_GPU_KERNEL((ReductionInitKernel<OutputType, Index>), - num_blocks, 1024, 0, device, reducer.initialize(), - num_preserved_vals, output); - } - - LAUNCH_GPU_KERNEL((InnerReductionKernel<num_per_thread, Self, Op, Index>), - num_blocks, block_size, 0, device, reducer, self, num_coeffs_to_reduce, num_preserved_vals, output); - - return false; - } -}; - -#ifdef EIGEN_HAS_GPU_FP16 -template <typename Self, typename Op> -struct InnerReductionLauncher<Self, Op, Eigen::half, false> { - static bool run(const Self&, Op&, const GpuDevice&, half*, typename Self::Index, typename Self::Index) { - gpu_assert(false && "Should not be called since there is no packet accessor"); - return true; - } -}; - -template <typename Self, typename Op> -struct InnerReductionLauncher<Self, Op, Eigen::half, true> { - static bool run(const Self& self, Op& reducer, const GpuDevice& device, half* output, typename Self::Index num_coeffs_to_reduce, typename Self::Index num_preserved_vals) { - typedef typename Self::Index Index; - - if (num_preserved_vals % 2 != 0) { - // Not supported yet, revert to the slower code path - return true; - } - - const Index num_coeffs = num_coeffs_to_reduce * num_preserved_vals; - const int block_size = /*256*/128; - const int num_per_thread = /*128*/64; - const int dyn_blocks = divup<int>(num_coeffs, block_size * num_per_thread); - const int max_blocks = device.getNumGpuMultiProcessors() * - device.maxGpuThreadsPerMultiProcessor() / block_size; - const int num_blocks = numext::mini<int>(max_blocks, dyn_blocks); - - if (num_blocks > 1) { - // We initialize the outputs outside the reduction kernel when we can't be sure that there - // won't be a race conditions between multiple thread blocks. - LAUNCH_GPU_KERNEL((ReductionInitKernelHalfFloat<Self, Op, Index>), - 1, 1, 0, device, reducer, self, num_preserved_vals, output); - } - - LAUNCH_GPU_KERNEL((InnerReductionKernelHalfFloat<num_per_thread, Self, Op, Index>), - num_blocks, block_size, 0, device, reducer, self, num_coeffs_to_reduce, num_preserved_vals, output); - - return false; - } -}; -#endif // EIGEN_HAS_GPU_FP16 - - -template <typename Self, typename Op> -struct InnerReducer<Self, Op, GpuDevice> { - // Unfortunately nvidia doesn't support well exotic types such as complex, - // so reduce the scope of the optimized version of the code to the simple case - // of floats and half floats. -#ifdef EIGEN_HAS_GPU_FP16 - static const bool HasOptimizedImplementation = !Self::ReducerTraits::IsStateful && - (internal::is_same<typename Self::CoeffReturnType, float>::value || - internal::is_same<typename Self::CoeffReturnType, double>::value || - (internal::is_same<typename Self::CoeffReturnType, Eigen::half>::value && reducer_traits<Op, GpuDevice>::PacketAccess)); -#else // EIGEN_HAS_GPU_FP16 - static const bool HasOptimizedImplementation = !Self::ReducerTraits::IsStateful && - (internal::is_same<typename Self::CoeffReturnType, float>::value || - internal::is_same<typename Self::CoeffReturnType, double>::value); -#endif // EIGEN_HAS_GPU_FP16 - - template <typename OutputType> - static bool run(const Self& self, Op& reducer, const GpuDevice& device, OutputType* output, typename Self::Index num_coeffs_to_reduce, typename Self::Index num_preserved_vals) { - gpu_assert(HasOptimizedImplementation && "Should only be called on doubles, floats or half floats"); - const Index num_coeffs = array_prod(self.m_impl.dimensions()); - // Don't crash when we're called with an input tensor of size 0. - if (num_coeffs == 0) { - return true; - } - // It's faster to use the usual code. - if (num_coeffs_to_reduce <= 128) { - return true; - } - - return InnerReductionLauncher<Self, Op, OutputType, reducer_traits<Op, GpuDevice>::PacketAccess>::run(self, reducer, device, output, num_coeffs_to_reduce, num_preserved_vals); - } -}; - -template <int NumPerThread, typename Self, - typename Reducer, typename Index> -__global__ void OuterReductionKernel(Reducer reducer, const Self input, Index num_coeffs_to_reduce, Index num_preserved_coeffs, - typename Self::CoeffReturnType* output) { - const Index num_threads = blockDim.x * gridDim.x; - const Index thread_id = blockIdx.x * blockDim.x + threadIdx.x; - // Initialize the output values if they weren't initialized by the ReductionInitKernel - if (gridDim.x == 1) { - for (Index i = thread_id; i < num_preserved_coeffs; i += num_threads) { - output[i] = reducer.initialize(); - } - __syncthreads(); - } - - // Do the reduction. - const Index max_iter = num_preserved_coeffs * divup<Index>(num_coeffs_to_reduce, NumPerThread); - for (Index i = thread_id; i < max_iter; i += num_threads) { - const Index input_col = i % num_preserved_coeffs; - const Index input_row = (i / num_preserved_coeffs) * NumPerThread; - typename Self::CoeffReturnType reduced_val = reducer.initialize(); - const Index max_row = numext::mini(input_row + NumPerThread, num_coeffs_to_reduce); - for (Index j = input_row; j < max_row; j++) { - typename Self::CoeffReturnType val = input.m_impl.coeff(j * num_preserved_coeffs + input_col); - reducer.reduce(val, &reduced_val); - } - atomicReduce(&(output[input_col]), reduced_val, reducer); - } -} - - -template <typename Self, typename Op> -struct OuterReducer<Self, Op, GpuDevice> { - // Unfortunately nvidia doesn't support well exotic types such as complex, - // so reduce the scope of the optimized version of the code to the simple case - // of floats. - static const bool HasOptimizedImplementation = !Self::ReducerTraits::IsStateful && - (internal::is_same<typename Self::CoeffReturnType, float>::value || - internal::is_same<typename Self::CoeffReturnType, double>::value); - template <typename Device, typename OutputType> - static - #if !defined(EIGEN_HIPCC) - // FIXME : leaving this EIGEN_DEVICE_FUNC in, results in the following runtime error - // (in the cxx11_tensor_reduction_gpu test) - // - // terminate called after throwing an instance of 'std::runtime_error' - // what(): No device code available for function: _ZN5Eigen8internal20OuterReductionKernelIL... - // - // don't know why this happens (and why is it a runtime error instead of a compile time error) - // - // this will be fixed by HIP PR#457 - EIGEN_DEVICE_FUNC - #endif - bool run(const Self&, Op&, const Device&, OutputType*, typename Self::Index, typename Self::Index) { - gpu_assert(false && "Should only be called to reduce doubles or floats on a gpu device"); - return true; - } - - static bool run(const Self& self, Op& reducer, const GpuDevice& device, float* output, typename Self::Index num_coeffs_to_reduce, typename Self::Index num_preserved_vals) { - typedef typename Self::Index Index; - - // It's faster to use the usual code. - if (num_coeffs_to_reduce <= 32) { - return true; - } - - const Index num_coeffs = num_coeffs_to_reduce * num_preserved_vals; - const int block_size = 256; - const int num_per_thread = 16; - const int dyn_blocks = divup<int>(num_coeffs, block_size * num_per_thread); - const int max_blocks = device.getNumGpuMultiProcessors() * - device.maxGpuThreadsPerMultiProcessor() / block_size; - const int num_blocks = numext::mini<int>(max_blocks, dyn_blocks); - - if (num_blocks > 1) { - // We initialize the outputs in the reduction kernel itself when we don't have to worry - // about race conditions between multiple thread blocks. - const int dyn_blocks = divup<int>(num_preserved_vals, 1024); - const int max_blocks = device.getNumGpuMultiProcessors() * - device.maxGpuThreadsPerMultiProcessor() / 1024; - const int num_blocks = numext::mini<int>(max_blocks, dyn_blocks); - LAUNCH_GPU_KERNEL((ReductionInitKernel<float, Index>), - num_blocks, 1024, 0, device, reducer.initialize(), - num_preserved_vals, output); - } - - LAUNCH_GPU_KERNEL((OuterReductionKernel<num_per_thread, Self, Op, Index>), - num_blocks, block_size, 0, device, reducer, self, num_coeffs_to_reduce, num_preserved_vals, output); - - return false; - } -}; - -#endif // defined(EIGEN_USE_GPU) && defined(EIGEN_GPUCC) - - -} // end namespace internal -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_REDUCTION_GPU_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h deleted file mode 100644 index 387c3edf..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h +++ /dev/null @@ -1,586 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/***************************************************************** - * TensorReductionSycl.h - * - * \brief: - * This is the specialization of the reduction operation. Two phase reduction approach - * is used since the GPU does not have Global Synchronization for global memory among - * different work-group/thread block. To solve the problem, we need to create two kernels - * to reduce the data, where the first kernel reduce the data locally and each local - * workgroup/thread-block save the input data into global memory. In the second phase (global reduction) - * one work-group uses one work-group/thread-block to reduces the intermediate data into one single element. - * Here is an NVIDIA presentation explaining the optimized two phase reduction algorithm on GPU: - * https://developer.download.nvidia.com/assets/cuda/files/reduction.pdf - * - *****************************************************************/ - -#ifndef UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSOR_REDUCTION_SYCL_HPP -#define UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSOR_REDUCTION_SYCL_HPP -namespace Eigen { -namespace TensorSycl { -namespace internal { - -template <typename Op, typename CoeffReturnType, typename Index, bool Vectorizable> -struct OpDefiner { - typedef typename Vectorise<CoeffReturnType, Eigen::SyclDevice, Vectorizable>::PacketReturnType PacketReturnType; - typedef Op type; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE type get_op(Op &op) { return op; } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType finalise_op(const PacketReturnType &accumulator, - const Index &) { - return accumulator; - } -}; - -template <typename CoeffReturnType, typename Index> -struct OpDefiner<Eigen::internal::MeanReducer<CoeffReturnType>, CoeffReturnType, Index, false> { - typedef Eigen::internal::SumReducer<CoeffReturnType> type; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE type get_op(Eigen::internal::MeanReducer<CoeffReturnType> &) { - return type(); - } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType finalise_op(const CoeffReturnType &accumulator, - const Index &scale) { - ::Eigen::internal::scalar_quotient_op<CoeffReturnType> quotient_op; - return quotient_op(accumulator, CoeffReturnType(scale)); - } -}; - -template <typename CoeffReturnType, typename Index> -struct OpDefiner<Eigen::internal::MeanReducer<CoeffReturnType>, CoeffReturnType, Index, true> { - typedef typename Vectorise<CoeffReturnType, Eigen::SyclDevice, true>::PacketReturnType PacketReturnType; - typedef Eigen::internal::SumReducer<CoeffReturnType> type; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE type get_op(Eigen::internal::MeanReducer<CoeffReturnType> &) { - return type(); - } - - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType finalise_op(const PacketReturnType &accumulator, - const Index &scale) { - return ::Eigen::internal::pdiv(accumulator, ::Eigen::internal::pset1<PacketReturnType>(CoeffReturnType(scale))); - } -}; - -template <typename CoeffReturnType, typename OpType, typename InputAccessor, typename OutputAccessor, typename Index, - Index local_range> -struct SecondStepFullReducer { - typedef cl::sycl::accessor<CoeffReturnType, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - LocalAccessor; - typedef OpDefiner<OpType, CoeffReturnType, Index, true> OpDef; - typedef typename OpDef::type Op; - LocalAccessor scratch; - InputAccessor aI; - OutputAccessor outAcc; - Op op; - SecondStepFullReducer(LocalAccessor scratch_, InputAccessor aI_, OutputAccessor outAcc_, OpType op_) - : scratch(scratch_), aI(aI_), outAcc(outAcc_), op(OpDef::get_op(op_)) {} - - void operator()(cl::sycl::nd_item<1> itemID) { - // Our empirical research shows that the best performance will be achieved - // when there is only one element per thread to reduce in the second step. - // in this step the second step reduction time is almost negligible. - // Hence, in the second step of reduction the input size is fixed to the - // local size, thus, there is only one element read per thread. The - // algorithm must be changed if the number of reduce per thread in the - // second step is greater than 1. Otherwise, the result will be wrong. - const Index localid = itemID.get_local_id(0); - auto aInPtr = aI.get_pointer() + localid; - auto aOutPtr = outAcc.get_pointer(); - CoeffReturnType *scratchptr = scratch.get_pointer(); - CoeffReturnType accumulator = *aInPtr; - - scratchptr[localid] = op.finalize(accumulator); -#pragma unroll 8 - for (Index offset = itemID.get_local_range(0) / 2; offset > 0; offset /= 2) { - itemID.barrier(cl::sycl::access::fence_space::local_space); - if (localid < offset) { - op.reduce(scratchptr[localid + offset], &accumulator); - scratchptr[localid] = op.finalize(accumulator); - } - } - if (localid == 0) *aOutPtr = op.finalize(accumulator); - } -}; - -// Full reduction first phase. In this version the vectorization is true and the reduction accept -// any generic reducerOp e.g( max, min, sum, mean, iamax, iamin, etc ). -template <typename Evaluator, typename OpType, typename Evaluator::Index local_range> -class FullReductionKernelFunctor { - public: - typedef typename Evaluator::CoeffReturnType CoeffReturnType; - typedef typename Evaluator::Index Index; - typedef OpDefiner<OpType, typename Evaluator::CoeffReturnType, Index, - (Evaluator::ReducerTraits::PacketAccess & Evaluator::InputPacketAccess)> - OpDef; - - typedef typename OpDef::type Op; - typedef typename Evaluator::EvaluatorPointerType EvaluatorPointerType; - typedef typename Evaluator::PacketReturnType PacketReturnType; - typedef - typename ::Eigen::internal::conditional<(Evaluator::ReducerTraits::PacketAccess & Evaluator::InputPacketAccess), - PacketReturnType, CoeffReturnType>::type OutType; - typedef cl::sycl::accessor<OutType, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - LocalAccessor; - LocalAccessor scratch; - Evaluator evaluator; - EvaluatorPointerType final_output; - Index rng; - Op op; - - FullReductionKernelFunctor(LocalAccessor scratch_, Evaluator evaluator_, EvaluatorPointerType final_output_, - Index rng_, OpType op_) - : scratch(scratch_), evaluator(evaluator_), final_output(final_output_), rng(rng_), op(OpDef::get_op(op_)) {} - - void operator()(cl::sycl::nd_item<1> itemID) { compute_reduction(itemID); } - - template <bool Vect = (Evaluator::ReducerTraits::PacketAccess & Evaluator::InputPacketAccess)> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename ::Eigen::internal::enable_if<Vect>::type compute_reduction( - const cl::sycl::nd_item<1> &itemID) { - auto output_ptr = final_output.get_pointer(); - Index VectorizedRange = (rng / Evaluator::PacketSize) * Evaluator::PacketSize; - Index globalid = itemID.get_global_id(0); - Index localid = itemID.get_local_id(0); - Index step = Evaluator::PacketSize * itemID.get_global_range(0); - Index start = Evaluator::PacketSize * globalid; - // vectorizable parts - PacketReturnType packetAccumulator = op.template initializePacket<PacketReturnType>(); -#pragma unroll(8 / Evaluator::PacketSize) - for (Index i = start; i < VectorizedRange; i += step) { - op.template reducePacket<PacketReturnType>(evaluator.impl().template packet<Unaligned>(i), &packetAccumulator); - } - globalid += VectorizedRange; - // non vectorizable parts - for (Index i = globalid; i < rng; i += itemID.get_global_range(0)) { - op.template reducePacket<PacketReturnType>( - ::Eigen::TensorSycl::internal::PacketWrapper<PacketReturnType, Evaluator::PacketSize>::convert_to_packet_type( - evaluator.impl().coeff(i), op.initialize()), - &packetAccumulator); - } - scratch[localid] = packetAccumulator = - OpDef::finalise_op(op.template finalizePacket<PacketReturnType>(packetAccumulator), rng); - // reduction parts // Local size is always power of 2 - EIGEN_UNROLL_LOOP - for (Index offset = local_range / 2; offset > 0; offset /= 2) { - itemID.barrier(cl::sycl::access::fence_space::local_space); - if (localid < offset) { - op.template reducePacket<PacketReturnType>(scratch[localid + offset], &packetAccumulator); - scratch[localid] = op.template finalizePacket<PacketReturnType>(packetAccumulator); - } - } - if (localid == 0) { - output_ptr[itemID.get_group(0)] = - op.finalizeBoth(op.initialize(), op.template finalizePacket<PacketReturnType>(packetAccumulator)); - } - } - - template <bool Vect = (Evaluator::ReducerTraits::PacketAccess & Evaluator::InputPacketAccess)> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename ::Eigen::internal::enable_if<!Vect>::type compute_reduction( - const cl::sycl::nd_item<1> &itemID) { - auto output_ptr = final_output.get_pointer(); - Index globalid = itemID.get_global_id(0); - Index localid = itemID.get_local_id(0); - // vectorizable parts - CoeffReturnType accumulator = op.initialize(); - // non vectorizable parts - for (Index i = globalid; i < rng; i += itemID.get_global_range(0)) { - op.reduce(evaluator.impl().coeff(i), &accumulator); - } - scratch[localid] = accumulator = OpDef::finalise_op(op.finalize(accumulator), rng); - - // reduction parts. the local size is always power of 2 - EIGEN_UNROLL_LOOP - for (Index offset = local_range / 2; offset > 0; offset /= 2) { - itemID.barrier(cl::sycl::access::fence_space::local_space); - if (localid < offset) { - op.reduce(scratch[localid + offset], &accumulator); - scratch[localid] = op.finalize(accumulator); - } - } - if (localid == 0) { - output_ptr[itemID.get_group(0)] = op.finalize(accumulator); - } - } -}; - -template <typename Evaluator, typename OpType> -class GenericNondeterministicReducer { - public: - typedef typename Evaluator::CoeffReturnType CoeffReturnType; - typedef typename Evaluator::EvaluatorPointerType EvaluatorPointerType; - typedef typename Evaluator::Index Index; - typedef OpDefiner<OpType, CoeffReturnType, Index, false> OpDef; - typedef typename OpDef::type Op; - template <typename Scratch> - GenericNondeterministicReducer(Scratch, Evaluator evaluator_, EvaluatorPointerType output_accessor_, OpType functor_, - Index range_, Index num_values_to_reduce_) - : evaluator(evaluator_), - output_accessor(output_accessor_), - functor(OpDef::get_op(functor_)), - range(range_), - num_values_to_reduce(num_values_to_reduce_) {} - - void operator()(cl::sycl::nd_item<1> itemID) { - auto output_accessor_ptr = output_accessor.get_pointer(); - /// const cast added as a naive solution to solve the qualifier drop error - Index globalid = static_cast<Index>(itemID.get_global_linear_id()); - if (globalid < range) { - CoeffReturnType accum = functor.initialize(); - Eigen::internal::GenericDimReducer<Evaluator::NumReducedDims - 1, Evaluator, Op>::reduce( - evaluator, evaluator.firstInput(globalid), functor, &accum); - output_accessor_ptr[globalid] = OpDef::finalise_op(functor.finalize(accum), num_values_to_reduce); - } - } - - private: - Evaluator evaluator; - EvaluatorPointerType output_accessor; - Op functor; - Index range; - Index num_values_to_reduce; -}; - -enum class reduction_dim { inner_most, outer_most }; -// default is preserver -template <typename Evaluator, typename OpType, typename PannelParameters, reduction_dim rt> -struct PartialReductionKernel { - typedef typename Evaluator::CoeffReturnType CoeffReturnType; - typedef typename Evaluator::EvaluatorPointerType EvaluatorPointerType; - typedef typename Evaluator::Index Index; - typedef OpDefiner<OpType, CoeffReturnType, Index, false> OpDef; - typedef typename OpDef::type Op; - typedef cl::sycl::accessor<CoeffReturnType, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - ScratchAcc; - ScratchAcc scratch; - Evaluator evaluator; - EvaluatorPointerType output_accessor; - Op op; - const Index preserve_elements_num_groups; - const Index reduce_elements_num_groups; - const Index num_coeffs_to_preserve; - const Index num_coeffs_to_reduce; - - PartialReductionKernel(ScratchAcc scratch_, Evaluator evaluator_, EvaluatorPointerType output_accessor_, OpType op_, - const Index preserve_elements_num_groups_, const Index reduce_elements_num_groups_, - const Index num_coeffs_to_preserve_, const Index num_coeffs_to_reduce_) - : scratch(scratch_), - evaluator(evaluator_), - output_accessor(output_accessor_), - op(OpDef::get_op(op_)), - preserve_elements_num_groups(preserve_elements_num_groups_), - reduce_elements_num_groups(reduce_elements_num_groups_), - num_coeffs_to_preserve(num_coeffs_to_preserve_), - num_coeffs_to_reduce(num_coeffs_to_reduce_) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void element_wise_reduce(Index globalRId, Index globalPId, - CoeffReturnType &accumulator) { - if (globalPId >= num_coeffs_to_preserve) { - return; - } - Index global_offset = rt == reduction_dim::outer_most ? globalPId + (globalRId * num_coeffs_to_preserve) - : globalRId + (globalPId * num_coeffs_to_reduce); - Index localOffset = globalRId; - - const Index per_thread_local_stride = PannelParameters::LocalThreadSizeR * reduce_elements_num_groups; - const Index per_thread_global_stride = - rt == reduction_dim::outer_most ? num_coeffs_to_preserve * per_thread_local_stride : per_thread_local_stride; -#pragma unroll 8 - for (Index i = globalRId; i < num_coeffs_to_reduce; i += per_thread_local_stride) { - op.reduce(evaluator.impl().coeff(global_offset), &accumulator); - localOffset += per_thread_local_stride; - global_offset += per_thread_global_stride; - } - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(cl::sycl::nd_item<1> itemID) { - const Index linearLocalThreadId = itemID.get_local_id(0); - Index pLocalThreadId = rt == reduction_dim::outer_most ? linearLocalThreadId % PannelParameters::LocalThreadSizeP - : linearLocalThreadId / PannelParameters::LocalThreadSizeR; - Index rLocalThreadId = rt == reduction_dim::outer_most ? linearLocalThreadId / PannelParameters::LocalThreadSizeP - : linearLocalThreadId % PannelParameters::LocalThreadSizeR; - const Index pGroupId = rt == reduction_dim::outer_most ? itemID.get_group(0) % preserve_elements_num_groups - : itemID.get_group(0) / reduce_elements_num_groups; - const Index rGroupId = rt == reduction_dim::outer_most ? itemID.get_group(0) / preserve_elements_num_groups - : itemID.get_group(0) % reduce_elements_num_groups; - - Index globalPId = pGroupId * PannelParameters::LocalThreadSizeP + pLocalThreadId; - const Index globalRId = rGroupId * PannelParameters::LocalThreadSizeR + rLocalThreadId; - auto scratchPtr = scratch.get_pointer().get(); - auto outPtr = - output_accessor.get_pointer() + (reduce_elements_num_groups > 1 ? rGroupId * num_coeffs_to_preserve : 0); - CoeffReturnType accumulator = op.initialize(); - - element_wise_reduce(globalRId, globalPId, accumulator); - - accumulator = OpDef::finalise_op(op.finalize(accumulator), num_coeffs_to_reduce); - scratchPtr[pLocalThreadId + rLocalThreadId * (PannelParameters::LocalThreadSizeP + PannelParameters::BC)] = - accumulator; - if (rt == reduction_dim::inner_most) { - pLocalThreadId = linearLocalThreadId % PannelParameters::LocalThreadSizeP; - rLocalThreadId = linearLocalThreadId / PannelParameters::LocalThreadSizeP; - globalPId = pGroupId * PannelParameters::LocalThreadSizeP + pLocalThreadId; - } - - /* Apply the reduction operation between the current local - * id and the one on the other half of the vector. */ - auto out_scratch_ptr = - scratchPtr + (pLocalThreadId + (rLocalThreadId * (PannelParameters::LocalThreadSizeP + PannelParameters::BC))); - itemID.barrier(cl::sycl::access::fence_space::local_space); - if (rt == reduction_dim::inner_most) { - accumulator = *out_scratch_ptr; - } - // The Local LocalThreadSizeR is always power of 2 - EIGEN_UNROLL_LOOP - for (Index offset = PannelParameters::LocalThreadSizeR >> 1; offset > 0; offset >>= 1) { - if (rLocalThreadId < offset) { - op.reduce(out_scratch_ptr[(PannelParameters::LocalThreadSizeP + PannelParameters::BC) * offset], &accumulator); - // The result has already been divided for mean reducer in the - // previous reduction so no need to divide furthermore - *out_scratch_ptr = op.finalize(accumulator); - } - /* All threads collectively read from global memory into local. - * The barrier ensures all threads' IO is resolved before - * execution continues (strictly speaking, all threads within - * a single work-group - there is no co-ordination between - * work-groups, only work-items). */ - itemID.barrier(cl::sycl::access::fence_space::local_space); - } - - if (rLocalThreadId == 0 && (globalPId < num_coeffs_to_preserve)) { - outPtr[globalPId] = op.finalize(accumulator); - } - } -}; - -template <typename OutScalar, typename Index, typename InputAccessor, typename OutputAccessor, typename OpType> -struct SecondStepPartialReduction { - typedef OpDefiner<OpType, OutScalar, Index, false> OpDef; - typedef typename OpDef::type Op; - typedef cl::sycl::accessor<OutScalar, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - ScratchAccessor; - InputAccessor input_accessor; - OutputAccessor output_accessor; - Op op; - const Index num_coeffs_to_preserve; - const Index num_coeffs_to_reduce; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE SecondStepPartialReduction(ScratchAccessor, InputAccessor input_accessor_, - OutputAccessor output_accessor_, OpType op_, - const Index num_coeffs_to_preserve_, - const Index num_coeffs_to_reduce_) - : input_accessor(input_accessor_), - output_accessor(output_accessor_), - op(OpDef::get_op(op_)), - num_coeffs_to_preserve(num_coeffs_to_preserve_), - num_coeffs_to_reduce(num_coeffs_to_reduce_) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(cl::sycl::nd_item<1> itemID) { - const Index globalId = itemID.get_global_id(0); - - if (globalId >= num_coeffs_to_preserve) return; - - auto in_ptr = input_accessor.get_pointer() + globalId; - - OutScalar accumulator = op.initialize(); -// num_coeffs_to_reduce is not bigger that 256 -#pragma unroll 8 - for (Index i = 0; i < num_coeffs_to_reduce; i++) { - op.reduce(*in_ptr, &accumulator); - in_ptr += num_coeffs_to_preserve; - } - output_accessor.get_pointer()[globalId] = op.finalize(accumulator); - } -}; // namespace internal - -template <typename Index, Index LTP, Index LTR, bool BC_> -struct ReductionPannel { - static EIGEN_CONSTEXPR Index LocalThreadSizeP = LTP; - static EIGEN_CONSTEXPR Index LocalThreadSizeR = LTR; - static EIGEN_CONSTEXPR bool BC = BC_; -}; - -template <typename Self, typename Op, TensorSycl::internal::reduction_dim rt> -struct PartialReducerLauncher { - typedef typename Self::EvaluatorPointerType EvaluatorPointerType; - typedef typename Self::CoeffReturnType CoeffReturnType; - typedef typename Self::Storage Storage; - typedef typename Self::Index Index; - typedef ReductionPannel<typename Self::Index, EIGEN_SYCL_LOCAL_THREAD_DIM0, EIGEN_SYCL_LOCAL_THREAD_DIM1, true> - PannelParameters; - - typedef PartialReductionKernel<Self, Op, PannelParameters, rt> SyclReducerKerneType; - - static bool run(const Self &self, const Op &reducer, const Eigen::SyclDevice &dev, EvaluatorPointerType output, - Index num_coeffs_to_reduce, Index num_coeffs_to_preserve) { - Index roundUpP = roundUp(num_coeffs_to_preserve, PannelParameters::LocalThreadSizeP); - - // getPowerOfTwo makes sure local range is power of 2 and <= - // maxSyclThreadPerBlock this will help us to avoid extra check on the - // kernel - static_assert(!((PannelParameters::LocalThreadSizeP * PannelParameters::LocalThreadSizeR) & - (PannelParameters::LocalThreadSizeP * PannelParameters::LocalThreadSizeR - 1)), - "The Local thread size must be a power of 2 for the reduction " - "operation"); - - EIGEN_CONSTEXPR Index localRange = PannelParameters::LocalThreadSizeP * PannelParameters::LocalThreadSizeR; - // In this step, we force the code not to be more than 2-step reduction: - // Our empirical research shows that if each thread reduces at least 64 - // elemnts individually, we get better performance. However, this can change - // on different platforms. In this step we force the code not to be - // morthan step reduction: Our empirical research shows that for inner_most - // dim reducer, it is better to have 8 group in a reduce dimension for sizes - // > 1024 to achieve the best performance. - const Index reductionPerThread = 64; - Index cu = dev.getPowerOfTwo(dev.getNumSyclMultiProcessors(), true); - const Index pNumGroups = roundUpP / PannelParameters::LocalThreadSizeP; - Index rGroups = (cu + pNumGroups - 1) / pNumGroups; - const Index rNumGroups = num_coeffs_to_reduce > reductionPerThread * localRange ? std::min(rGroups, localRange) : 1; - const Index globalRange = pNumGroups * rNumGroups * localRange; - - EIGEN_CONSTEXPR Index scratchSize = - PannelParameters::LocalThreadSizeR * (PannelParameters::LocalThreadSizeP + PannelParameters::BC); - auto thread_range = cl::sycl::nd_range<1>(cl::sycl::range<1>(globalRange), cl::sycl::range<1>(localRange)); - if (rNumGroups > 1) { - CoeffReturnType *temp_pointer = static_cast<CoeffReturnType *>( - dev.allocate_temp(num_coeffs_to_preserve * rNumGroups * sizeof(CoeffReturnType))); - EvaluatorPointerType temp_accessor = dev.get(temp_pointer); - dev.template unary_kernel_launcher<CoeffReturnType, SyclReducerKerneType>( - self, temp_accessor, thread_range, scratchSize, reducer, pNumGroups, rNumGroups, num_coeffs_to_preserve, - num_coeffs_to_reduce); - - typedef SecondStepPartialReduction<CoeffReturnType, Index, EvaluatorPointerType, EvaluatorPointerType, Op> - SecondStepPartialReductionKernel; - - dev.template unary_kernel_launcher<CoeffReturnType, SecondStepPartialReductionKernel>( - temp_accessor, output, - cl::sycl::nd_range<1>(cl::sycl::range<1>(pNumGroups * localRange), cl::sycl::range<1>(localRange)), Index(1), - reducer, num_coeffs_to_preserve, rNumGroups); - - self.device().deallocate_temp(temp_pointer); - } else { - dev.template unary_kernel_launcher<CoeffReturnType, SyclReducerKerneType>( - self, output, thread_range, scratchSize, reducer, pNumGroups, rNumGroups, num_coeffs_to_preserve, - num_coeffs_to_reduce); - } - return false; - } -}; -} // namespace internal -} // namespace TensorSycl - -namespace internal { - -template <typename Self, typename Op, bool Vectorizable> -struct FullReducer<Self, Op, Eigen::SyclDevice, Vectorizable> { - typedef typename Self::CoeffReturnType CoeffReturnType; - typedef typename Self::EvaluatorPointerType EvaluatorPointerType; - static EIGEN_CONSTEXPR bool HasOptimizedImplementation = true; - static EIGEN_CONSTEXPR int PacketSize = Self::PacketAccess ? Self::PacketSize : 1; - static void run(const Self &self, Op &reducer, const Eigen::SyclDevice &dev, EvaluatorPointerType data) { - typedef typename conditional<Self::PacketAccess, typename Self::PacketReturnType, CoeffReturnType>::type OutType; - static_assert(!((EIGEN_SYCL_LOCAL_THREAD_DIM0 * EIGEN_SYCL_LOCAL_THREAD_DIM1) & - (EIGEN_SYCL_LOCAL_THREAD_DIM0 * EIGEN_SYCL_LOCAL_THREAD_DIM1 - 1)), - "The Local thread size must be a power of 2 for the reduction " - "operation"); - EIGEN_CONSTEXPR Index local_range = EIGEN_SYCL_LOCAL_THREAD_DIM0 * EIGEN_SYCL_LOCAL_THREAD_DIM1; - - typename Self::Index inputSize = self.impl().dimensions().TotalSize(); - // In this step we force the code not to be more than 2-step reduction: - // Our empirical research shows that if each thread reduces at least 512 - // elemnts individually, we get better performance. - const Index reductionPerThread = 2048; - // const Index num_work_group = - Index reductionGroup = dev.getPowerOfTwo( - (inputSize + (reductionPerThread * local_range - 1)) / (reductionPerThread * local_range), true); - const Index num_work_group = std::min(reductionGroup, local_range); - // 1 - // ? local_range - // : 1); - const Index global_range = num_work_group * local_range; - - auto thread_range = cl::sycl::nd_range<1>(cl::sycl::range<1>(global_range), cl::sycl::range<1>(local_range)); - typedef TensorSycl::internal::FullReductionKernelFunctor<Self, Op, local_range> reduction_kernel_t; - if (num_work_group > 1) { - CoeffReturnType *temp_pointer = - static_cast<CoeffReturnType *>(dev.allocate_temp(num_work_group * sizeof(CoeffReturnType))); - typename Self::EvaluatorPointerType tmp_global_accessor = dev.get(temp_pointer); - dev.template unary_kernel_launcher<OutType, reduction_kernel_t>(self, tmp_global_accessor, thread_range, - local_range, inputSize, reducer); - - typedef TensorSycl::internal::SecondStepFullReducer<CoeffReturnType, Op, EvaluatorPointerType, - EvaluatorPointerType, Index, local_range> - GenericRKernel; - dev.template unary_kernel_launcher<CoeffReturnType, GenericRKernel>( - tmp_global_accessor, data, - cl::sycl::nd_range<1>(cl::sycl::range<1>(num_work_group), cl::sycl::range<1>(num_work_group)), num_work_group, - reducer); - - dev.deallocate_temp(temp_pointer); - } else { - dev.template unary_kernel_launcher<OutType, reduction_kernel_t>(self, data, thread_range, local_range, inputSize, - reducer); - } - } -}; -// vectorizable inner_most most dim preserver -// col reduction -template <typename Self, typename Op> -struct OuterReducer<Self, Op, Eigen::SyclDevice> { - static EIGEN_CONSTEXPR bool HasOptimizedImplementation = true; - - static bool run(const Self &self, const Op &reducer, const Eigen::SyclDevice &dev, - typename Self::EvaluatorPointerType output, typename Self::Index num_coeffs_to_reduce, - typename Self::Index num_coeffs_to_preserve) { - return ::Eigen::TensorSycl::internal::PartialReducerLauncher< - Self, Op, ::Eigen::TensorSycl::internal::reduction_dim::outer_most>::run(self, reducer, dev, output, - num_coeffs_to_reduce, - num_coeffs_to_preserve); - } -}; -// row reduction -template <typename Self, typename Op> -struct InnerReducer<Self, Op, Eigen::SyclDevice> { - static EIGEN_CONSTEXPR bool HasOptimizedImplementation = true; - - static bool run(const Self &self, const Op &reducer, const Eigen::SyclDevice &dev, - typename Self::EvaluatorPointerType output, typename Self::Index num_coeffs_to_reduce, - typename Self::Index num_coeffs_to_preserve) { - return ::Eigen::TensorSycl::internal::PartialReducerLauncher< - Self, Op, ::Eigen::TensorSycl::internal::reduction_dim::inner_most>::run(self, reducer, dev, output, - num_coeffs_to_reduce, - num_coeffs_to_preserve); - } -}; - -// ArmgMax uses this kernel for partial reduction// -// TODO(@mehdi.goli) come up with a better kernel -// generic partial reduction -template <typename Self, typename Op> -struct GenericReducer<Self, Op, Eigen::SyclDevice> { - static EIGEN_CONSTEXPR bool HasOptimizedImplementation = false; - static bool run(const Self &self, const Op &reducer, const Eigen::SyclDevice &dev, - typename Self::EvaluatorPointerType output, typename Self::Index num_values_to_reduce, - typename Self::Index num_coeffs_to_preserve) { - typename Self::Index range, GRange, tileSize; - dev.parallel_for_setup(num_coeffs_to_preserve, tileSize, range, GRange); - - dev.template unary_kernel_launcher<typename Self::CoeffReturnType, - TensorSycl::internal::GenericNondeterministicReducer<Self, Op>>( - self, output, cl::sycl::nd_range<1>(cl::sycl::range<1>(GRange), cl::sycl::range<1>(tileSize)), Index(1), - reducer, range, (num_values_to_reduce != 0) ? num_values_to_reduce : static_cast<Index>(1)); - return false; - } -}; - -} // namespace internal -} // namespace Eigen - -#endif // UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSOR_REDUCTION_SYCL_HPP diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorRef.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorRef.h deleted file mode 100644 index 030d1984..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorRef.h +++ /dev/null @@ -1,454 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_REF_H -#define EIGEN_CXX11_TENSOR_TENSOR_REF_H - -namespace Eigen { - -namespace internal { - -template <typename Dimensions, typename Scalar> -class TensorLazyBaseEvaluator { - public: - TensorLazyBaseEvaluator() : m_refcount(0) { } - virtual ~TensorLazyBaseEvaluator() { } - - EIGEN_DEVICE_FUNC virtual const Dimensions& dimensions() const = 0; - EIGEN_DEVICE_FUNC virtual const Scalar* data() const = 0; - - EIGEN_DEVICE_FUNC virtual const Scalar coeff(DenseIndex index) const = 0; - EIGEN_DEVICE_FUNC virtual Scalar& coeffRef(DenseIndex index) = 0; - - void incrRefCount() { ++m_refcount; } - void decrRefCount() { --m_refcount; } - int refCount() const { return m_refcount; } - - private: - // No copy, no assignment; - TensorLazyBaseEvaluator(const TensorLazyBaseEvaluator& other); - TensorLazyBaseEvaluator& operator = (const TensorLazyBaseEvaluator& other); - - int m_refcount; -}; - - -template <typename Dimensions, typename Expr, typename Device> -class TensorLazyEvaluatorReadOnly : public TensorLazyBaseEvaluator<Dimensions, typename TensorEvaluator<Expr, Device>::Scalar> { - public: - // typedef typename TensorEvaluator<Expr, Device>::Dimensions Dimensions; - typedef typename TensorEvaluator<Expr, Device>::Scalar Scalar; - typedef StorageMemory<Scalar, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - typedef TensorEvaluator<Expr, Device> EvalType; - - TensorLazyEvaluatorReadOnly(const Expr& expr, const Device& device) : m_impl(expr, device), m_dummy(Scalar(0)) { - m_dims = m_impl.dimensions(); - m_impl.evalSubExprsIfNeeded(NULL); - } - virtual ~TensorLazyEvaluatorReadOnly() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC virtual const Dimensions& dimensions() const { - return m_dims; - } - EIGEN_DEVICE_FUNC virtual const Scalar* data() const { - return m_impl.data(); - } - - EIGEN_DEVICE_FUNC virtual const Scalar coeff(DenseIndex index) const { - return m_impl.coeff(index); - } - EIGEN_DEVICE_FUNC virtual Scalar& coeffRef(DenseIndex /*index*/) { - eigen_assert(false && "can't reference the coefficient of a rvalue"); - return m_dummy; - }; - - protected: - TensorEvaluator<Expr, Device> m_impl; - Dimensions m_dims; - Scalar m_dummy; -}; - -template <typename Dimensions, typename Expr, typename Device> -class TensorLazyEvaluatorWritable : public TensorLazyEvaluatorReadOnly<Dimensions, Expr, Device> { - public: - typedef TensorLazyEvaluatorReadOnly<Dimensions, Expr, Device> Base; - typedef typename Base::Scalar Scalar; - typedef StorageMemory<Scalar, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - TensorLazyEvaluatorWritable(const Expr& expr, const Device& device) : Base(expr, device) { - } - virtual ~TensorLazyEvaluatorWritable() { - } - - EIGEN_DEVICE_FUNC virtual Scalar& coeffRef(DenseIndex index) { - return this->m_impl.coeffRef(index); - } -}; - -template <typename Dimensions, typename Expr, typename Device> -class TensorLazyEvaluator : public internal::conditional<bool(internal::is_lvalue<Expr>::value), - TensorLazyEvaluatorWritable<Dimensions, Expr, Device>, - TensorLazyEvaluatorReadOnly<Dimensions, const Expr, Device> >::type { - public: - typedef typename internal::conditional<bool(internal::is_lvalue<Expr>::value), - TensorLazyEvaluatorWritable<Dimensions, Expr, Device>, - TensorLazyEvaluatorReadOnly<Dimensions, const Expr, Device> >::type Base; - typedef typename Base::Scalar Scalar; - - TensorLazyEvaluator(const Expr& expr, const Device& device) : Base(expr, device) { - } - virtual ~TensorLazyEvaluator() { - } -}; - -} // namespace internal - - -/** \class TensorRef - * \ingroup CXX11_Tensor_Module - * - * \brief A reference to a tensor expression - * The expression will be evaluated lazily (as much as possible). - * - */ -template<typename PlainObjectType> class TensorRef : public TensorBase<TensorRef<PlainObjectType> > -{ - public: - typedef TensorRef<PlainObjectType> Self; - typedef typename PlainObjectType::Base Base; - typedef typename Eigen::internal::nested<Self>::type Nested; - typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind; - typedef typename internal::traits<PlainObjectType>::Index Index; - typedef typename internal::traits<PlainObjectType>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef typename Base::CoeffReturnType CoeffReturnType; - typedef Scalar* PointerType; - typedef PointerType PointerArgType; - - static const Index NumIndices = PlainObjectType::NumIndices; - typedef typename PlainObjectType::Dimensions Dimensions; - - enum { - IsAligned = false, - PacketAccess = false, - BlockAccess = false, - PreferBlockAccess = false, - Layout = PlainObjectType::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -----------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===------------------------------------------------------------------===// - - EIGEN_STRONG_INLINE TensorRef() : m_evaluator(NULL) { - } - - template <typename Expression> - EIGEN_STRONG_INLINE TensorRef(const Expression& expr) : m_evaluator(new internal::TensorLazyEvaluator<Dimensions, Expression, DefaultDevice>(expr, DefaultDevice())) { - m_evaluator->incrRefCount(); - } - - template <typename Expression> - EIGEN_STRONG_INLINE TensorRef& operator = (const Expression& expr) { - unrefEvaluator(); - m_evaluator = new internal::TensorLazyEvaluator<Dimensions, Expression, DefaultDevice>(expr, DefaultDevice()); - m_evaluator->incrRefCount(); - return *this; - } - - ~TensorRef() { - unrefEvaluator(); - } - - TensorRef(const TensorRef& other) : m_evaluator(other.m_evaluator) { - eigen_assert(m_evaluator->refCount() > 0); - m_evaluator->incrRefCount(); - } - - TensorRef& operator = (const TensorRef& other) { - if (this != &other) { - unrefEvaluator(); - m_evaluator = other.m_evaluator; - eigen_assert(m_evaluator->refCount() > 0); - m_evaluator->incrRefCount(); - } - return *this; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index rank() const { return m_evaluator->dimensions().size(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index dimension(Index n) const { return m_evaluator->dimensions()[n]; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_evaluator->dimensions(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Index size() const { return m_evaluator->dimensions().TotalSize(); } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar* data() const { return m_evaluator->data(); } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar operator()(Index index) const - { - return m_evaluator->coeff(index); - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... IndexTypes> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar operator()(Index firstIndex, IndexTypes... otherIndices) const - { - const std::size_t num_indices = (sizeof...(otherIndices) + 1); - const array<Index, num_indices> indices{{firstIndex, otherIndices...}}; - return coeff(indices); - } - template<typename... IndexTypes> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices) - { - const std::size_t num_indices = (sizeof...(otherIndices) + 1); - const array<Index, num_indices> indices{{firstIndex, otherIndices...}}; - return coeffRef(indices); - } -#else - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar operator()(Index i0, Index i1) const - { - array<Index, 2> indices; - indices[0] = i0; - indices[1] = i1; - return coeff(indices); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar operator()(Index i0, Index i1, Index i2) const - { - array<Index, 3> indices; - indices[0] = i0; - indices[1] = i1; - indices[2] = i2; - return coeff(indices); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar operator()(Index i0, Index i1, Index i2, Index i3) const - { - array<Index, 4> indices; - indices[0] = i0; - indices[1] = i1; - indices[2] = i2; - indices[3] = i3; - return coeff(indices); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar operator()(Index i0, Index i1, Index i2, Index i3, Index i4) const - { - array<Index, 5> indices; - indices[0] = i0; - indices[1] = i1; - indices[2] = i2; - indices[3] = i3; - indices[4] = i4; - return coeff(indices); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1) - { - array<Index, 2> indices; - indices[0] = i0; - indices[1] = i1; - return coeffRef(indices); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1, Index i2) - { - array<Index, 3> indices; - indices[0] = i0; - indices[1] = i1; - indices[2] = i2; - return coeffRef(indices); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3) - { - array<Index, 4> indices; - indices[0] = i0; - indices[1] = i1; - indices[2] = i2; - indices[3] = i3; - return coeffRef(indices); - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1, Index i2, Index i3, Index i4) - { - array<Index, 5> indices; - indices[0] = i0; - indices[1] = i1; - indices[2] = i2; - indices[3] = i3; - indices[4] = i4; - return coeffRef(indices); - } -#endif - - template <std::size_t NumIndices> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar coeff(const array<Index, NumIndices>& indices) const - { - const Dimensions& dims = this->dimensions(); - Index index = 0; - if (PlainObjectType::Options & RowMajor) { - index += indices[0]; - for (size_t i = 1; i < NumIndices; ++i) { - index = index * dims[i] + indices[i]; - } - } else { - index += indices[NumIndices-1]; - for (int i = NumIndices-2; i >= 0; --i) { - index = index * dims[i] + indices[i]; - } - } - return m_evaluator->coeff(index); - } - template <std::size_t NumIndices> EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(const array<Index, NumIndices>& indices) - { - const Dimensions& dims = this->dimensions(); - Index index = 0; - if (PlainObjectType::Options & RowMajor) { - index += indices[0]; - for (size_t i = 1; i < NumIndices; ++i) { - index = index * dims[i] + indices[i]; - } - } else { - index += indices[NumIndices-1]; - for (int i = NumIndices-2; i >= 0; --i) { - index = index * dims[i] + indices[i]; - } - } - return m_evaluator->coeffRef(index); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const Scalar coeff(Index index) const - { - return m_evaluator->coeff(index); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) - { - return m_evaluator->coeffRef(index); - } - - private: - EIGEN_STRONG_INLINE void unrefEvaluator() { - if (m_evaluator) { - m_evaluator->decrRefCount(); - if (m_evaluator->refCount() == 0) { - delete m_evaluator; - } - } - } - - internal::TensorLazyBaseEvaluator<Dimensions, Scalar>* m_evaluator; -}; - - -// evaluator for rvalues -template<typename Derived, typename Device> -struct TensorEvaluator<const TensorRef<Derived>, Device> -{ - typedef typename Derived::Index Index; - typedef typename Derived::Scalar Scalar; - typedef typename Derived::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef typename Derived::Dimensions Dimensions; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = false, - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorRef<Derived>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const TensorRef<Derived>& m, const Device&) - : m_ref(m) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_ref.dimensions(); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - return m_ref.coeff(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { - return m_ref.coeffRef(index); - } - - EIGEN_DEVICE_FUNC const Scalar* data() const { return m_ref.data(); } - - protected: - TensorRef<Derived> m_ref; -}; - - -// evaluator for lvalues -template<typename Derived, typename Device> -struct TensorEvaluator<TensorRef<Derived>, Device> : public TensorEvaluator<const TensorRef<Derived>, Device> -{ - typedef typename Derived::Index Index; - typedef typename Derived::Scalar Scalar; - typedef typename Derived::Scalar CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef typename Derived::Dimensions Dimensions; - - typedef TensorEvaluator<const TensorRef<Derived>, Device> Base; - - enum { - IsAligned = false, - PacketAccess = false, - BlockAccess = false, - PreferBlockAccess = false, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(TensorRef<Derived>& m, const Device& d) : Base(m, d) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { - return this->m_ref.coeffRef(index); - } -}; - - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_REF_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReverse.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReverse.h deleted file mode 100644 index 2fc85c13..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorReverse.h +++ /dev/null @@ -1,482 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Navdeep Jaitly <ndjaitly@google.com> -// Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_REVERSE_H -#define EIGEN_CXX11_TENSOR_TENSOR_REVERSE_H -namespace Eigen { - -/** \class TensorReverse - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor reverse elements class. - * - */ -namespace internal { -template<typename ReverseDimensions, typename XprType> -struct traits<TensorReverseOp<ReverseDimensions, - XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename ReverseDimensions, typename XprType> -struct eval<TensorReverseOp<ReverseDimensions, XprType>, Eigen::Dense> -{ - typedef const TensorReverseOp<ReverseDimensions, XprType>& type; -}; - -template<typename ReverseDimensions, typename XprType> -struct nested<TensorReverseOp<ReverseDimensions, XprType>, 1, - typename eval<TensorReverseOp<ReverseDimensions, XprType> >::type> -{ - typedef TensorReverseOp<ReverseDimensions, XprType> type; -}; - -} // end namespace internal - -template<typename ReverseDimensions, typename XprType> -class TensorReverseOp : public TensorBase<TensorReverseOp<ReverseDimensions, - XprType>, WriteAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorReverseOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorReverseOp>::type Nested; - typedef typename Eigen::internal::traits<TensorReverseOp>::StorageKind - StorageKind; - typedef typename Eigen::internal::traits<TensorReverseOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorReverseOp( - const XprType& expr, const ReverseDimensions& reverse_dims) - : m_xpr(expr), m_reverse_dims(reverse_dims) { } - - EIGEN_DEVICE_FUNC - const ReverseDimensions& reverse() const { return m_reverse_dims; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorReverseOp& operator = (const TensorReverseOp& other) - { - typedef TensorAssignOp<TensorReverseOp, const TensorReverseOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorReverseOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorReverseOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - protected: - typename XprType::Nested m_xpr; - const ReverseDimensions m_reverse_dims; -}; - -// Eval as rvalue -template<typename ReverseDimensions, typename ArgType, typename Device> -struct TensorEvaluator<const TensorReverseOp<ReverseDimensions, ArgType>, Device> -{ - typedef TensorReverseOp<ReverseDimensions, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<ReverseDimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = NumDims > 0, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - typedef internal::TensorIntDivisor<Index> IndexDivisor; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename TensorEvaluator<const ArgType, Device>::TensorBlock - ArgTensorBlock; - - typedef typename internal::TensorMaterializedBlock<CoeffReturnType, NumDims, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, - const Device& device) - : m_impl(op.expression(), device), - m_reverse(op.reverse()), - m_device(device) - { - // Reversing a scalar isn't supported yet. It would be a no-op anyway. - EIGEN_STATIC_ASSERT((NumDims > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - - // Compute strides - m_dimensions = m_impl.dimensions(); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_strides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_strides[i] = m_strides[i-1] * m_dimensions[i-1]; - if (m_strides[i] > 0) m_fastStrides[i] = IndexDivisor(m_strides[i]); - } - } else { - m_strides[NumDims-1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_strides[i] = m_strides[i+1] * m_dimensions[i+1]; - if (m_strides[i] > 0) m_fastStrides[i] = IndexDivisor(m_strides[i]); - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - m_impl.evalSubExprsIfNeededAsync(nullptr, [done](bool) { done(true); }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index reverseIndex( - Index index) const { - eigen_assert(index < dimensions().TotalSize()); - Index inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - Index idx = index / m_fastStrides[i]; - index -= idx * m_strides[i]; - if (m_reverse[i]) { - idx = m_dimensions[i] - idx - 1; - } - inputIndex += idx * m_strides[i] ; - } - if (m_reverse[0]) { - inputIndex += (m_dimensions[0] - index - 1); - } else { - inputIndex += index; - } - } else { - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - Index idx = index / m_fastStrides[i]; - index -= idx * m_strides[i]; - if (m_reverse[i]) { - idx = m_dimensions[i] - idx - 1; - } - inputIndex += idx * m_strides[i] ; - } - if (m_reverse[NumDims-1]) { - inputIndex += (m_dimensions[NumDims-1] - index - 1); - } else { - inputIndex += index; - } - } - return inputIndex; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff( - Index index) const { - return m_impl.coeff(reverseIndex(index)); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - // TODO(ndjaitly): write a better packing routine that uses - // local structure. - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type - values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - const size_t target_size = m_device.lastLevelCacheSize(); - // Block evaluation reads underlying memory in reverse order, and default - // cost model does not properly catch this in bytes stored/loaded. - return internal::TensorBlockResourceRequirements::skewed<Scalar>( - target_size) - .addCostPerCoeff({0, 0, 24}); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool /*root_of_expr_ast*/ = false) const { - // TODO(ezhulenev): If underlying tensor expression supports and prefers - // block evaluation we must use it. Currently we use coeff and packet - // access into the underlying tensor expression. - // static const bool useBlockAccessForArgType = - // TensorEvaluator<ArgType, Device>::BlockAccess && - // TensorEvaluator<ArgType, Device>::PreferBlockAccess; - - static const bool isColMajor = - static_cast<int>(Layout) == static_cast<int>(ColMajor); - - static const Index inner_dim_idx = isColMajor ? 0 : NumDims - 1; - const bool inner_dim_reversed = m_reverse[inner_dim_idx]; - - // Offset in the output block. - Index block_offset = 0; - - // Offset in the input Tensor. - Index input_offset = reverseIndex(desc.offset()); - - // Initialize output block iterator state. Dimension in this array are - // always in inner_most -> outer_most order (col major layout). - array<BlockIteratorState, NumDims> it; - for (int i = 0; i < NumDims; ++i) { - const int dim = isColMajor ? i : NumDims - 1 - i; - it[i].size = desc.dimension(dim); - it[i].count = 0; - it[i].reverse = m_reverse[dim]; - - it[i].block_stride = - i == 0 ? 1 : (it[i - 1].size * it[i - 1].block_stride); - it[i].block_span = it[i].block_stride * (it[i].size - 1); - - it[i].input_stride = m_strides[dim]; - it[i].input_span = it[i].input_stride * (it[i].size - 1); - - if (it[i].reverse) { - it[i].input_stride = -1 * it[i].input_stride; - it[i].input_span = -1 * it[i].input_span; - } - } - - // If multiple inner dimensions have the same reverse flag, check if we can - // merge them into a single virtual inner dimension. - int effective_inner_dim = 0; - for (int i = 1; i < NumDims; ++i) { - if (it[i].reverse != it[effective_inner_dim].reverse) break; - if (it[i].block_stride != it[effective_inner_dim].size) break; - if (it[i].block_stride != numext::abs(it[i].input_stride)) break; - - it[i].size = it[effective_inner_dim].size * it[i].size; - - it[i].block_stride = 1; - it[i].input_stride = (inner_dim_reversed ? -1 : 1); - - it[i].block_span = it[i].block_stride * (it[i].size - 1); - it[i].input_span = it[i].input_stride * (it[i].size - 1); - - effective_inner_dim = i; - } - - eigen_assert(it[effective_inner_dim].block_stride == 1); - eigen_assert(it[effective_inner_dim].input_stride == - (inner_dim_reversed ? -1 : 1)); - - const Index inner_dim_size = it[effective_inner_dim].size; - - // Prepare storage for the materialized reverse result. - const typename TensorBlock::Storage block_storage = - TensorBlock::prepareStorage(desc, scratch); - CoeffReturnType* block_buffer = block_storage.data(); - - while (it[NumDims - 1].count < it[NumDims - 1].size) { - // Copy inner-most dimension data from reversed location in input. - Index dst = block_offset; - Index src = input_offset; - - // NOTE(ezhulenev): Adding vectorized path with internal::preverse showed - // worse results in benchmarks than a simple coefficient loop. - if (inner_dim_reversed) { - for (Index i = 0; i < inner_dim_size; ++i) { - block_buffer[dst] = m_impl.coeff(src); - ++dst; - --src; - } - } else { - for (Index i = 0; i < inner_dim_size; ++i) { - block_buffer[dst] = m_impl.coeff(src); - ++dst; - ++src; - } - } - - // For the 1d tensor we need to generate only one inner-most dimension. - if ((NumDims - effective_inner_dim) == 1) break; - - // Update offset. - for (Index i = effective_inner_dim + 1; i < NumDims; ++i) { - if (++it[i].count < it[i].size) { - block_offset += it[i].block_stride; - input_offset += it[i].input_stride; - break; - } - if (i != NumDims - 1) it[i].count = 0; - block_offset -= it[i].block_span; - input_offset -= it[i].input_span; - } - } - - return block_storage.AsTensorMaterializedBlock(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - double compute_cost = NumDims * (2 * TensorOpCost::AddCost<Index>() + - 2 * TensorOpCost::MulCost<Index>() + - TensorOpCost::DivCost<Index>()); - for (int i = 0; i < NumDims; ++i) { - if (m_reverse[i]) { - compute_cost += 2 * TensorOpCost::AddCost<Index>(); - } - } - return m_impl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, compute_cost, false /* vectorized */, PacketSize); - } - - EIGEN_DEVICE_FUNC typename Storage::Type data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - protected: - Dimensions m_dimensions; - array<Index, NumDims> m_strides; - array<IndexDivisor, NumDims> m_fastStrides; - TensorEvaluator<ArgType, Device> m_impl; - ReverseDimensions m_reverse; - const Device EIGEN_DEVICE_REF m_device; - - private: - struct BlockIteratorState { - BlockIteratorState() - : size(0), - count(0), - reverse(false), - block_stride(0), - block_span(0), - input_stride(0), - input_span(0) {} - - Index size; - Index count; - bool reverse; - Index block_stride; - Index block_span; - Index input_stride; - Index input_span; - }; -}; - -// Eval as lvalue - -template <typename ReverseDimensions, typename ArgType, typename Device> -struct TensorEvaluator<TensorReverseOp<ReverseDimensions, ArgType>, Device> - : public TensorEvaluator<const TensorReverseOp<ReverseDimensions, ArgType>, - Device> { - typedef TensorEvaluator<const TensorReverseOp<ReverseDimensions, ArgType>, - Device> Base; - typedef TensorReverseOp<ReverseDimensions, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<ReverseDimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, - const Device& device) - : Base(op, device) {} - - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Dimensions& dimensions() const { return this->m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { - return this->m_impl.coeffRef(this->reverseIndex(index)); - } - - template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - // This code is pilfered from TensorMorphing.h - EIGEN_ALIGN_MAX CoeffReturnType values[PacketSize]; - internal::pstore<CoeffReturnType, PacketReturnType>(values, x); - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - this->coeffRef(index+i) = values[i]; - } - } -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_REVERSE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorScan.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorScan.h deleted file mode 100644 index ee465dd0..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorScan.h +++ /dev/null @@ -1,313 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Igor Babuschkin <igor@babuschk.in> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_SCAN_H -#define EIGEN_CXX11_TENSOR_TENSOR_SCAN_H - -namespace Eigen { - -namespace internal { - -template <typename Op, typename XprType> -struct traits<TensorScanOp<Op, XprType> > - : public traits<XprType> { - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename Op, typename XprType> -struct eval<TensorScanOp<Op, XprType>, Eigen::Dense> -{ - typedef const TensorScanOp<Op, XprType>& type; -}; - -template<typename Op, typename XprType> -struct nested<TensorScanOp<Op, XprType>, 1, - typename eval<TensorScanOp<Op, XprType> >::type> -{ - typedef TensorScanOp<Op, XprType> type; -}; -} // end namespace internal - -/** \class TensorScan - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor scan class. - */ -template <typename Op, typename XprType> -class TensorScanOp - : public TensorBase<TensorScanOp<Op, XprType>, ReadOnlyAccessors> { -public: - typedef typename Eigen::internal::traits<TensorScanOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorScanOp>::type Nested; - typedef typename Eigen::internal::traits<TensorScanOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorScanOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorScanOp( - const XprType& expr, const Index& axis, bool exclusive = false, const Op& op = Op()) - : m_expr(expr), m_axis(axis), m_accumulator(op), m_exclusive(exclusive) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Index axis() const { return m_axis; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const XprType& expression() const { return m_expr; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Op accumulator() const { return m_accumulator; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - bool exclusive() const { return m_exclusive; } - -protected: - typename XprType::Nested m_expr; - const Index m_axis; - const Op m_accumulator; - const bool m_exclusive; -}; - -template <typename Self, typename Reducer, typename Device> -struct ScanLauncher; - -// Eval as rvalue -template <typename Op, typename ArgType, typename Device> -struct TensorEvaluator<const TensorScanOp<Op, ArgType>, Device> { - - typedef TensorScanOp<Op, ArgType> XprType; - typedef typename XprType::Index Index; - typedef const ArgType ChildType; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - typedef TensorEvaluator<const TensorScanOp<Op, ArgType>, Device> Self; - typedef StorageMemory<Scalar, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = false, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, - RawAccess = true - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, - const Device& device) - : m_impl(op.expression(), device), - m_device(device), - m_exclusive(op.exclusive()), - m_accumulator(op.accumulator()), - m_size(m_impl.dimensions()[op.axis()]), - m_stride(1), m_consume_dim(op.axis()), - m_output(NULL) { - - // Accumulating a scalar isn't supported. - EIGEN_STATIC_ASSERT((NumDims > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - eigen_assert(op.axis() >= 0 && op.axis() < NumDims); - - // Compute stride of scan axis - const Dimensions& dims = m_impl.dimensions(); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = 0; i < op.axis(); ++i) { - m_stride = m_stride * dims[i]; - } - } else { - // dims can only be indexed through unsigned integers, - // so let's use an unsigned type to let the compiler knows. - // This prevents stupid warnings: ""'*((void*)(& evaluator)+64)[18446744073709551615]' may be used uninitialized in this function" - unsigned int axis = internal::convert_index<unsigned int>(op.axis()); - for (unsigned int i = NumDims - 1; i > axis; --i) { - m_stride = m_stride * dims[i]; - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { - return m_impl.dimensions(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Index& stride() const { - return m_stride; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Index& consume_dim() const { - return m_consume_dim; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Index& size() const { - return m_size; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Op& accumulator() const { - return m_accumulator; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool exclusive() const { - return m_exclusive; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorEvaluator<ArgType, Device>& inner() const { - return m_impl; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Device& device() const { - return m_device; - } - - EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { - m_impl.evalSubExprsIfNeeded(NULL); - ScanLauncher<Self, Op, Device> launcher; - if (data) { - launcher(*this, data); - return false; - } - - const Index total_size = internal::array_prod(dimensions()); - m_output = static_cast<EvaluatorPointerType>(m_device.get((Scalar*) m_device.allocate_temp(total_size * sizeof(Scalar)))); - launcher(*this, m_output); - return true; - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const { - return internal::ploadt<PacketReturnType, LoadMode>(m_output + index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data() const - { - return m_output; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return m_output[index]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool) const { - return TensorOpCost(sizeof(CoeffReturnType), 0, 0); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - if (m_output) { - m_device.deallocate_temp(m_output); - m_output = NULL; - } - m_impl.cleanup(); - } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - m_output.bind(cgh); - } -#endif -protected: - TensorEvaluator<ArgType, Device> m_impl; - const Device EIGEN_DEVICE_REF m_device; - const bool m_exclusive; - Op m_accumulator; - const Index m_size; - Index m_stride; - Index m_consume_dim; - EvaluatorPointerType m_output; -}; - -// CPU implementation of scan -// TODO(ibab) This single-threaded implementation should be parallelized, -// at least by running multiple scans at the same time. -template <typename Self, typename Reducer, typename Device> -struct ScanLauncher { - void operator()(Self& self, typename Self::CoeffReturnType *data) { - Index total_size = internal::array_prod(self.dimensions()); - - // We fix the index along the scan axis to 0 and perform a - // scan per remaining entry. The iteration is split into two nested - // loops to avoid an integer division by keeping track of each idx1 and idx2. - for (Index idx1 = 0; idx1 < total_size; idx1 += self.stride() * self.size()) { - for (Index idx2 = 0; idx2 < self.stride(); idx2++) { - // Calculate the starting offset for the scan - Index offset = idx1 + idx2; - - // Compute the scan along the axis, starting at the calculated offset - typename Self::CoeffReturnType accum = self.accumulator().initialize(); - for (Index idx3 = 0; idx3 < self.size(); idx3++) { - Index curr = offset + idx3 * self.stride(); - - if (self.exclusive()) { - data[curr] = self.accumulator().finalize(accum); - self.accumulator().reduce(self.inner().coeff(curr), &accum); - } else { - self.accumulator().reduce(self.inner().coeff(curr), &accum); - data[curr] = self.accumulator().finalize(accum); - } - } - } - } - } -}; - -#if defined(EIGEN_USE_GPU) && (defined(EIGEN_GPUCC)) - -// GPU implementation of scan -// TODO(ibab) This placeholder implementation performs multiple scans in -// parallel, but it would be better to use a parallel scan algorithm and -// optimize memory access. -template <typename Self, typename Reducer> -__global__ void ScanKernel(Self self, Index total_size, typename Self::CoeffReturnType* data) { - // Compute offset as in the CPU version - Index val = threadIdx.x + blockIdx.x * blockDim.x; - Index offset = (val / self.stride()) * self.stride() * self.size() + val % self.stride(); - - if (offset + (self.size() - 1) * self.stride() < total_size) { - // Compute the scan along the axis, starting at the calculated offset - typename Self::CoeffReturnType accum = self.accumulator().initialize(); - for (Index idx = 0; idx < self.size(); idx++) { - Index curr = offset + idx * self.stride(); - if (self.exclusive()) { - data[curr] = self.accumulator().finalize(accum); - self.accumulator().reduce(self.inner().coeff(curr), &accum); - } else { - self.accumulator().reduce(self.inner().coeff(curr), &accum); - data[curr] = self.accumulator().finalize(accum); - } - } - } - __syncthreads(); - -} - -template <typename Self, typename Reducer> -struct ScanLauncher<Self, Reducer, GpuDevice> { - void operator()(const Self& self, typename Self::CoeffReturnType* data) { - Index total_size = internal::array_prod(self.dimensions()); - Index num_blocks = (total_size / self.size() + 63) / 64; - Index block_size = 64; - - LAUNCH_GPU_KERNEL((ScanKernel<Self, Reducer>), num_blocks, block_size, 0, self.device(), self, total_size, data); - } -}; -#endif // EIGEN_USE_GPU && (EIGEN_GPUCC) - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_SCAN_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorScanSycl.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorScanSycl.h deleted file mode 100644 index 0078692c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorScanSycl.h +++ /dev/null @@ -1,512 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Mehdi Goli Codeplay Software Ltd. -// Ralph Potter Codeplay Software Ltd. -// Luke Iwanski Codeplay Software Ltd. -// Contact: <eigen@codeplay.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/***************************************************************** - * TensorScanSycl.h - * - * \brief: - * Tensor Scan Sycl implement the extend version of - * "Efficient parallel scan algorithms for GPUs." .for Tensor operations. - * The algorithm requires up to 3 stage (consequently 3 kernels) depending on - * the size of the tensor. In the first kernel (ScanKernelFunctor), each - * threads within the work-group individually reduces the allocated elements per - * thread in order to reduces the total number of blocks. In the next step all - * thread within the work-group will reduce the associated blocks into the - * temporary buffers. In the next kernel(ScanBlockKernelFunctor), the temporary - * buffer is given as an input and all the threads within a work-group scan and - * reduces the boundaries between the blocks (generated from the previous - * kernel). and write the data on the temporary buffer. If the second kernel is - * required, the third and final kerenl (ScanAdjustmentKernelFunctor) will - * adjust the final result into the output buffer. - * The original algorithm for the parallel prefix sum can be found here: - * - * Sengupta, Shubhabrata, Mark Harris, and Michael Garland. "Efficient parallel - * scan algorithms for GPUs." NVIDIA, Santa Clara, CA, Tech. Rep. NVR-2008-003 - *1, no. 1 (2008): 1-17. - *****************************************************************/ - -#ifndef UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSOR_SYCL_SYCL_HPP -#define UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSOR_SYCL_SYCL_HPP - -namespace Eigen { -namespace TensorSycl { -namespace internal { - -#ifndef EIGEN_SYCL_MAX_GLOBAL_RANGE -#define EIGEN_SYCL_MAX_GLOBAL_RANGE (EIGEN_SYCL_LOCAL_THREAD_DIM0 * EIGEN_SYCL_LOCAL_THREAD_DIM1 * 4) -#endif - -template <typename index_t> -struct ScanParameters { - // must be power of 2 - static EIGEN_CONSTEXPR index_t ScanPerThread = 8; - const index_t total_size; - const index_t non_scan_size; - const index_t scan_size; - const index_t non_scan_stride; - const index_t scan_stride; - const index_t panel_threads; - const index_t group_threads; - const index_t block_threads; - const index_t elements_per_group; - const index_t elements_per_block; - const index_t loop_range; - - ScanParameters(index_t total_size_, index_t non_scan_size_, index_t scan_size_, index_t non_scan_stride_, - index_t scan_stride_, index_t panel_threads_, index_t group_threads_, index_t block_threads_, - index_t elements_per_group_, index_t elements_per_block_, index_t loop_range_) - : total_size(total_size_), - non_scan_size(non_scan_size_), - scan_size(scan_size_), - non_scan_stride(non_scan_stride_), - scan_stride(scan_stride_), - panel_threads(panel_threads_), - group_threads(group_threads_), - block_threads(block_threads_), - elements_per_group(elements_per_group_), - elements_per_block(elements_per_block_), - loop_range(loop_range_) {} -}; - -enum class scan_step { first, second }; -template <typename Evaluator, typename CoeffReturnType, typename OutAccessor, typename Op, typename Index, - scan_step stp> -struct ScanKernelFunctor { - typedef cl::sycl::accessor<CoeffReturnType, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - LocalAccessor; - static EIGEN_CONSTEXPR int PacketSize = ScanParameters<Index>::ScanPerThread / 2; - - LocalAccessor scratch; - Evaluator dev_eval; - OutAccessor out_accessor; - OutAccessor temp_accessor; - const ScanParameters<Index> scanParameters; - Op accumulator; - const bool inclusive; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ScanKernelFunctor(LocalAccessor scratch_, const Evaluator dev_eval_, - OutAccessor out_accessor_, OutAccessor temp_accessor_, - const ScanParameters<Index> scanParameters_, Op accumulator_, - const bool inclusive_) - : scratch(scratch_), - dev_eval(dev_eval_), - out_accessor(out_accessor_), - temp_accessor(temp_accessor_), - scanParameters(scanParameters_), - accumulator(accumulator_), - inclusive(inclusive_) {} - - template <scan_step sst = stp, typename Input> - typename ::Eigen::internal::enable_if<sst == scan_step::first, CoeffReturnType>::type EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE - read(const Input &inpt, Index global_id) { - return inpt.coeff(global_id); - } - - template <scan_step sst = stp, typename Input> - typename ::Eigen::internal::enable_if<sst != scan_step::first, CoeffReturnType>::type EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE - read(const Input &inpt, Index global_id) { - return inpt[global_id]; - } - - template <scan_step sst = stp, typename InclusiveOp> - typename ::Eigen::internal::enable_if<sst == scan_step::first>::type EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - first_step_inclusive_Operation(InclusiveOp inclusive_op) { - inclusive_op(); - } - - template <scan_step sst = stp, typename InclusiveOp> - typename ::Eigen::internal::enable_if<sst != scan_step::first>::type EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - first_step_inclusive_Operation(InclusiveOp) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(cl::sycl::nd_item<1> itemID) { - auto out_ptr = out_accessor.get_pointer(); - auto tmp_ptr = temp_accessor.get_pointer(); - auto scratch_ptr = scratch.get_pointer().get(); - - for (Index loop_offset = 0; loop_offset < scanParameters.loop_range; loop_offset++) { - Index data_offset = (itemID.get_global_id(0) + (itemID.get_global_range(0) * loop_offset)); - Index tmp = data_offset % scanParameters.panel_threads; - const Index panel_id = data_offset / scanParameters.panel_threads; - const Index group_id = tmp / scanParameters.group_threads; - tmp = tmp % scanParameters.group_threads; - const Index block_id = tmp / scanParameters.block_threads; - const Index local_id = tmp % scanParameters.block_threads; - // we put one element per packet in scratch_mem - const Index scratch_stride = scanParameters.elements_per_block / PacketSize; - const Index scratch_offset = (itemID.get_local_id(0) / scanParameters.block_threads) * scratch_stride; - CoeffReturnType private_scan[ScanParameters<Index>::ScanPerThread]; - CoeffReturnType inclusive_scan; - // the actual panel size is scan_size * non_scan_size. - // elements_per_panel is roundup to power of 2 for binary tree - const Index panel_offset = panel_id * scanParameters.scan_size * scanParameters.non_scan_size; - const Index group_offset = group_id * scanParameters.non_scan_stride; - // This will be effective when the size is bigger than elements_per_block - const Index block_offset = block_id * scanParameters.elements_per_block * scanParameters.scan_stride; - const Index thread_offset = (ScanParameters<Index>::ScanPerThread * local_id * scanParameters.scan_stride); - const Index global_offset = panel_offset + group_offset + block_offset + thread_offset; - Index next_elements = 0; - EIGEN_UNROLL_LOOP - for (int i = 0; i < ScanParameters<Index>::ScanPerThread; i++) { - Index global_id = global_offset + next_elements; - private_scan[i] = ((((block_id * scanParameters.elements_per_block) + - (ScanParameters<Index>::ScanPerThread * local_id) + i) < scanParameters.scan_size) && - (global_id < scanParameters.total_size)) - ? read(dev_eval, global_id) - : accumulator.initialize(); - next_elements += scanParameters.scan_stride; - } - first_step_inclusive_Operation([&]() EIGEN_DEVICE_FUNC { - if (inclusive) { - inclusive_scan = private_scan[ScanParameters<Index>::ScanPerThread - 1]; - } - }); - // This for loop must be 2 - EIGEN_UNROLL_LOOP - for (int packetIndex = 0; packetIndex < ScanParameters<Index>::ScanPerThread; packetIndex += PacketSize) { - Index private_offset = 1; - // build sum in place up the tree - EIGEN_UNROLL_LOOP - for (Index d = PacketSize >> 1; d > 0; d >>= 1) { - EIGEN_UNROLL_LOOP - for (Index l = 0; l < d; l++) { - Index ai = private_offset * (2 * l + 1) - 1 + packetIndex; - Index bi = private_offset * (2 * l + 2) - 1 + packetIndex; - CoeffReturnType accum = accumulator.initialize(); - accumulator.reduce(private_scan[ai], &accum); - accumulator.reduce(private_scan[bi], &accum); - private_scan[bi] = accumulator.finalize(accum); - } - private_offset *= 2; - } - scratch_ptr[2 * local_id + (packetIndex / PacketSize) + scratch_offset] = - private_scan[PacketSize - 1 + packetIndex]; - private_scan[PacketSize - 1 + packetIndex] = accumulator.initialize(); - // traverse down tree & build scan - EIGEN_UNROLL_LOOP - for (Index d = 1; d < PacketSize; d *= 2) { - private_offset >>= 1; - EIGEN_UNROLL_LOOP - for (Index l = 0; l < d; l++) { - Index ai = private_offset * (2 * l + 1) - 1 + packetIndex; - Index bi = private_offset * (2 * l + 2) - 1 + packetIndex; - CoeffReturnType accum = accumulator.initialize(); - accumulator.reduce(private_scan[ai], &accum); - accumulator.reduce(private_scan[bi], &accum); - private_scan[ai] = private_scan[bi]; - private_scan[bi] = accumulator.finalize(accum); - } - } - } - - Index offset = 1; - // build sum in place up the tree - for (Index d = scratch_stride >> 1; d > 0; d >>= 1) { - // Synchronise - itemID.barrier(cl::sycl::access::fence_space::local_space); - if (local_id < d) { - Index ai = offset * (2 * local_id + 1) - 1 + scratch_offset; - Index bi = offset * (2 * local_id + 2) - 1 + scratch_offset; - CoeffReturnType accum = accumulator.initialize(); - accumulator.reduce(scratch_ptr[ai], &accum); - accumulator.reduce(scratch_ptr[bi], &accum); - scratch_ptr[bi] = accumulator.finalize(accum); - } - offset *= 2; - } - // Synchronise - itemID.barrier(cl::sycl::access::fence_space::local_space); - // next step optimisation - if (local_id == 0) { - if (((scanParameters.elements_per_group / scanParameters.elements_per_block) > 1)) { - const Index temp_id = panel_id * (scanParameters.elements_per_group / scanParameters.elements_per_block) * - scanParameters.non_scan_size + - group_id * (scanParameters.elements_per_group / scanParameters.elements_per_block) + - block_id; - tmp_ptr[temp_id] = scratch_ptr[scratch_stride - 1 + scratch_offset]; - } - // clear the last element - scratch_ptr[scratch_stride - 1 + scratch_offset] = accumulator.initialize(); - } - // traverse down tree & build scan - for (Index d = 1; d < scratch_stride; d *= 2) { - offset >>= 1; - // Synchronise - itemID.barrier(cl::sycl::access::fence_space::local_space); - if (local_id < d) { - Index ai = offset * (2 * local_id + 1) - 1 + scratch_offset; - Index bi = offset * (2 * local_id + 2) - 1 + scratch_offset; - CoeffReturnType accum = accumulator.initialize(); - accumulator.reduce(scratch_ptr[ai], &accum); - accumulator.reduce(scratch_ptr[bi], &accum); - scratch_ptr[ai] = scratch_ptr[bi]; - scratch_ptr[bi] = accumulator.finalize(accum); - } - } - // Synchronise - itemID.barrier(cl::sycl::access::fence_space::local_space); - // This for loop must be 2 - EIGEN_UNROLL_LOOP - for (int packetIndex = 0; packetIndex < ScanParameters<Index>::ScanPerThread; packetIndex += PacketSize) { - EIGEN_UNROLL_LOOP - for (Index i = 0; i < PacketSize; i++) { - CoeffReturnType accum = private_scan[packetIndex + i]; - accumulator.reduce(scratch_ptr[2 * local_id + (packetIndex / PacketSize) + scratch_offset], &accum); - private_scan[packetIndex + i] = accumulator.finalize(accum); - } - } - first_step_inclusive_Operation([&]() EIGEN_DEVICE_FUNC { - if (inclusive) { - accumulator.reduce(private_scan[ScanParameters<Index>::ScanPerThread - 1], &inclusive_scan); - private_scan[0] = accumulator.finalize(inclusive_scan); - } - }); - next_elements = 0; - // right the first set of private param - EIGEN_UNROLL_LOOP - for (Index i = 0; i < ScanParameters<Index>::ScanPerThread; i++) { - Index global_id = global_offset + next_elements; - if ((((block_id * scanParameters.elements_per_block) + (ScanParameters<Index>::ScanPerThread * local_id) + i) < - scanParameters.scan_size) && - (global_id < scanParameters.total_size)) { - Index private_id = (i * !inclusive) + (((i + 1) % ScanParameters<Index>::ScanPerThread) * (inclusive)); - out_ptr[global_id] = private_scan[private_id]; - } - next_elements += scanParameters.scan_stride; - } - } // end for loop - } -}; - -template <typename CoeffReturnType, typename InAccessor, typename OutAccessor, typename Op, typename Index> -struct ScanAdjustmentKernelFunctor { - typedef cl::sycl::accessor<CoeffReturnType, 1, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> - LocalAccessor; - static EIGEN_CONSTEXPR int PacketSize = ScanParameters<Index>::ScanPerThread / 2; - InAccessor in_accessor; - OutAccessor out_accessor; - const ScanParameters<Index> scanParameters; - Op accumulator; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ScanAdjustmentKernelFunctor(LocalAccessor, InAccessor in_accessor_, - OutAccessor out_accessor_, - const ScanParameters<Index> scanParameters_, - Op accumulator_) - : in_accessor(in_accessor_), - out_accessor(out_accessor_), - scanParameters(scanParameters_), - accumulator(accumulator_) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(cl::sycl::nd_item<1> itemID) { - auto in_ptr = in_accessor.get_pointer(); - auto out_ptr = out_accessor.get_pointer(); - - for (Index loop_offset = 0; loop_offset < scanParameters.loop_range; loop_offset++) { - Index data_offset = (itemID.get_global_id(0) + (itemID.get_global_range(0) * loop_offset)); - Index tmp = data_offset % scanParameters.panel_threads; - const Index panel_id = data_offset / scanParameters.panel_threads; - const Index group_id = tmp / scanParameters.group_threads; - tmp = tmp % scanParameters.group_threads; - const Index block_id = tmp / scanParameters.block_threads; - const Index local_id = tmp % scanParameters.block_threads; - - // the actual panel size is scan_size * non_scan_size. - // elements_per_panel is roundup to power of 2 for binary tree - const Index panel_offset = panel_id * scanParameters.scan_size * scanParameters.non_scan_size; - const Index group_offset = group_id * scanParameters.non_scan_stride; - // This will be effective when the size is bigger than elements_per_block - const Index block_offset = block_id * scanParameters.elements_per_block * scanParameters.scan_stride; - const Index thread_offset = ScanParameters<Index>::ScanPerThread * local_id * scanParameters.scan_stride; - - const Index global_offset = panel_offset + group_offset + block_offset + thread_offset; - const Index block_size = scanParameters.elements_per_group / scanParameters.elements_per_block; - const Index in_id = (panel_id * block_size * scanParameters.non_scan_size) + (group_id * block_size) + block_id; - CoeffReturnType adjust_val = in_ptr[in_id]; - - Index next_elements = 0; - EIGEN_UNROLL_LOOP - for (Index i = 0; i < ScanParameters<Index>::ScanPerThread; i++) { - Index global_id = global_offset + next_elements; - if ((((block_id * scanParameters.elements_per_block) + (ScanParameters<Index>::ScanPerThread * local_id) + i) < - scanParameters.scan_size) && - (global_id < scanParameters.total_size)) { - CoeffReturnType accum = adjust_val; - accumulator.reduce(out_ptr[global_id], &accum); - out_ptr[global_id] = accumulator.finalize(accum); - } - next_elements += scanParameters.scan_stride; - } - } - } -}; - -template <typename Index> -struct ScanInfo { - const Index &total_size; - const Index &scan_size; - const Index &panel_size; - const Index &non_scan_size; - const Index &scan_stride; - const Index &non_scan_stride; - - Index max_elements_per_block; - Index block_size; - Index panel_threads; - Index group_threads; - Index block_threads; - Index elements_per_group; - Index elements_per_block; - Index loop_range; - Index global_range; - Index local_range; - const Eigen::SyclDevice &dev; - EIGEN_STRONG_INLINE ScanInfo(const Index &total_size_, const Index &scan_size_, const Index &panel_size_, - const Index &non_scan_size_, const Index &scan_stride_, const Index &non_scan_stride_, - const Eigen::SyclDevice &dev_) - : total_size(total_size_), - scan_size(scan_size_), - panel_size(panel_size_), - non_scan_size(non_scan_size_), - scan_stride(scan_stride_), - non_scan_stride(non_scan_stride_), - dev(dev_) { - // must be power of 2 - local_range = std::min(Index(dev.getNearestPowerOfTwoWorkGroupSize()), - Index(EIGEN_SYCL_LOCAL_THREAD_DIM0 * EIGEN_SYCL_LOCAL_THREAD_DIM1)); - - max_elements_per_block = local_range * ScanParameters<Index>::ScanPerThread; - - elements_per_group = - dev.getPowerOfTwo(Index(roundUp(Index(scan_size), ScanParameters<Index>::ScanPerThread)), true); - const Index elements_per_panel = elements_per_group * non_scan_size; - elements_per_block = std::min(Index(elements_per_group), Index(max_elements_per_block)); - panel_threads = elements_per_panel / ScanParameters<Index>::ScanPerThread; - group_threads = elements_per_group / ScanParameters<Index>::ScanPerThread; - block_threads = elements_per_block / ScanParameters<Index>::ScanPerThread; - block_size = elements_per_group / elements_per_block; -#ifdef EIGEN_SYCL_MAX_GLOBAL_RANGE - const Index max_threads = std::min(Index(panel_threads * panel_size), Index(EIGEN_SYCL_MAX_GLOBAL_RANGE)); -#else - const Index max_threads = panel_threads * panel_size; -#endif - global_range = roundUp(max_threads, local_range); - loop_range = Index( - std::ceil(double(elements_per_panel * panel_size) / (global_range * ScanParameters<Index>::ScanPerThread))); - } - inline ScanParameters<Index> get_scan_parameter() { - return ScanParameters<Index>(total_size, non_scan_size, scan_size, non_scan_stride, scan_stride, panel_threads, - group_threads, block_threads, elements_per_group, elements_per_block, loop_range); - } - inline cl::sycl::nd_range<1> get_thread_range() { - return cl::sycl::nd_range<1>(cl::sycl::range<1>(global_range), cl::sycl::range<1>(local_range)); - } -}; - -template <typename EvaluatorPointerType, typename CoeffReturnType, typename Reducer, typename Index> -struct SYCLAdjustBlockOffset { - EIGEN_STRONG_INLINE static void adjust_scan_block_offset(EvaluatorPointerType in_ptr, EvaluatorPointerType out_ptr, - Reducer &accumulator, const Index total_size, - const Index scan_size, const Index panel_size, - const Index non_scan_size, const Index scan_stride, - const Index non_scan_stride, const Eigen::SyclDevice &dev) { - auto scan_info = - ScanInfo<Index>(total_size, scan_size, panel_size, non_scan_size, scan_stride, non_scan_stride, dev); - - typedef ScanAdjustmentKernelFunctor<CoeffReturnType, EvaluatorPointerType, EvaluatorPointerType, Reducer, Index> - AdjustFuctor; - dev.template unary_kernel_launcher<CoeffReturnType, AdjustFuctor>(in_ptr, out_ptr, scan_info.get_thread_range(), - scan_info.max_elements_per_block, - scan_info.get_scan_parameter(), accumulator); - } -}; - -template <typename CoeffReturnType, scan_step stp> -struct ScanLauncher_impl { - template <typename Input, typename EvaluatorPointerType, typename Reducer, typename Index> - EIGEN_STRONG_INLINE static void scan_block(Input in_ptr, EvaluatorPointerType out_ptr, Reducer &accumulator, - const Index total_size, const Index scan_size, const Index panel_size, - const Index non_scan_size, const Index scan_stride, - const Index non_scan_stride, const bool inclusive, - const Eigen::SyclDevice &dev) { - auto scan_info = - ScanInfo<Index>(total_size, scan_size, panel_size, non_scan_size, scan_stride, non_scan_stride, dev); - const Index temp_pointer_size = scan_info.block_size * non_scan_size * panel_size; - const Index scratch_size = scan_info.max_elements_per_block / (ScanParameters<Index>::ScanPerThread / 2); - CoeffReturnType *temp_pointer = - static_cast<CoeffReturnType *>(dev.allocate_temp(temp_pointer_size * sizeof(CoeffReturnType))); - EvaluatorPointerType tmp_global_accessor = dev.get(temp_pointer); - - typedef ScanKernelFunctor<Input, CoeffReturnType, EvaluatorPointerType, Reducer, Index, stp> ScanFunctor; - dev.template binary_kernel_launcher<CoeffReturnType, ScanFunctor>( - in_ptr, out_ptr, tmp_global_accessor, scan_info.get_thread_range(), scratch_size, - scan_info.get_scan_parameter(), accumulator, inclusive); - - if (scan_info.block_size > 1) { - ScanLauncher_impl<CoeffReturnType, scan_step::second>::scan_block( - tmp_global_accessor, tmp_global_accessor, accumulator, temp_pointer_size, scan_info.block_size, panel_size, - non_scan_size, Index(1), scan_info.block_size, false, dev); - - SYCLAdjustBlockOffset<EvaluatorPointerType, CoeffReturnType, Reducer, Index>::adjust_scan_block_offset( - tmp_global_accessor, out_ptr, accumulator, total_size, scan_size, panel_size, non_scan_size, scan_stride, - non_scan_stride, dev); - } - dev.deallocate_temp(temp_pointer); - } -}; - -} // namespace internal -} // namespace TensorSycl - -template <typename Self, typename Reducer> -struct ScanLauncher<Self, Reducer, Eigen::SyclDevice> { - typedef typename Self::Index Index; - typedef typename Self::CoeffReturnType CoeffReturnType; - typedef typename Self::Storage Storage; - typedef typename Self::EvaluatorPointerType EvaluatorPointerType; - void operator()(Self &self, EvaluatorPointerType data) { - const Index total_size = internal::array_prod(self.dimensions()); - const Index scan_size = self.size(); - const Index scan_stride = self.stride(); - // this is the scan op (can be sum or ...) - auto accumulator = self.accumulator(); - auto inclusive = !self.exclusive(); - auto consume_dim = self.consume_dim(); - auto dev = self.device(); - - auto dims = self.inner().dimensions(); - - Index non_scan_size = 1; - Index panel_size = 1; - if (static_cast<int>(Self::Layout) == static_cast<int>(ColMajor)) { - for (int i = 0; i < consume_dim; i++) { - non_scan_size *= dims[i]; - } - for (int i = consume_dim + 1; i < Self::NumDims; i++) { - panel_size *= dims[i]; - } - } else { - for (int i = Self::NumDims - 1; i > consume_dim; i--) { - non_scan_size *= dims[i]; - } - for (int i = consume_dim - 1; i >= 0; i--) { - panel_size *= dims[i]; - } - } - const Index non_scan_stride = (scan_stride > 1) ? 1 : scan_size; - auto eval_impl = self.inner(); - TensorSycl::internal::ScanLauncher_impl<CoeffReturnType, TensorSycl::internal::scan_step::first>::scan_block( - eval_impl, data, accumulator, total_size, scan_size, panel_size, non_scan_size, scan_stride, non_scan_stride, - inclusive, dev); - } -}; -} // namespace Eigen - -#endif // UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSOR_SYCL_SYCL_HPP diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorShuffling.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorShuffling.h deleted file mode 100644 index 597ca64c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorShuffling.h +++ /dev/null @@ -1,485 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_SHUFFLING_H -#define EIGEN_CXX11_TENSOR_TENSOR_SHUFFLING_H - -namespace Eigen { - -/** \class TensorShuffling - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor shuffling class. - * - * - */ -namespace internal { -template<typename Shuffle, typename XprType> -struct traits<TensorShufflingOp<Shuffle, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename Shuffle, typename XprType> -struct eval<TensorShufflingOp<Shuffle, XprType>, Eigen::Dense> -{ - typedef const TensorShufflingOp<Shuffle, XprType>& type; -}; - -template<typename Shuffle, typename XprType> -struct nested<TensorShufflingOp<Shuffle, XprType>, 1, typename eval<TensorShufflingOp<Shuffle, XprType> >::type> -{ - typedef TensorShufflingOp<Shuffle, XprType> type; -}; - -} // end namespace internal - - - -template<typename Shuffle, typename XprType> -class TensorShufflingOp : public TensorBase<TensorShufflingOp<Shuffle, XprType> > -{ - public: - typedef typename Eigen::internal::traits<TensorShufflingOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorShufflingOp>::type Nested; - typedef typename Eigen::internal::traits<TensorShufflingOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorShufflingOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorShufflingOp(const XprType& expr, const Shuffle& shfl) - : m_xpr(expr), m_shuffle(shfl) {} - - EIGEN_DEVICE_FUNC - const Shuffle& shufflePermutation() const { return m_shuffle; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorShufflingOp& operator = (const TensorShufflingOp& other) - { - typedef TensorAssignOp<TensorShufflingOp, const TensorShufflingOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorShufflingOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorShufflingOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - protected: - typename XprType::Nested m_xpr; - const Shuffle m_shuffle; -}; - - -// Eval as rvalue -template<typename Shuffle, typename ArgType, typename Device> -struct TensorEvaluator<const TensorShufflingOp<Shuffle, ArgType>, Device> -{ - typedef TensorEvaluator<const TensorShufflingOp<Shuffle, ArgType>, Device> Self; - typedef TensorShufflingOp<Shuffle, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = TensorEvaluator<ArgType, Device>::RawAccess, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch; - - typedef typename internal::TensorMaterializedBlock<ScalarNoConst, NumDims, - Layout, Index> - TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, - const Device& device) - : m_device(device), - m_impl(op.expression(), device) - { - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - const Shuffle& shuffle = op.shufflePermutation(); - m_is_identity = true; - for (int i = 0; i < NumDims; ++i) { - m_shuffle[i] = static_cast<int>(shuffle[i]); - m_dimensions[i] = input_dims[shuffle[i]]; - m_inverseShuffle[shuffle[i]] = i; - if (m_is_identity && shuffle[i] != i) { - m_is_identity = false; - } - } - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_unshuffledInputStrides[0] = 1; - m_outputStrides[0] = 1; - - for (int i = 1; i < NumDims; ++i) { - m_unshuffledInputStrides[i] = - m_unshuffledInputStrides[i - 1] * input_dims[i - 1]; - m_outputStrides[i] = m_outputStrides[i - 1] * m_dimensions[i - 1]; - m_fastOutputStrides[i] = internal::TensorIntDivisor<Index>(m_outputStrides[i]); - } - } else { - m_unshuffledInputStrides[NumDims - 1] = 1; - m_outputStrides[NumDims - 1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_unshuffledInputStrides[i] = - m_unshuffledInputStrides[i + 1] * input_dims[i + 1]; - m_outputStrides[i] = m_outputStrides[i + 1] * m_dimensions[i + 1]; - m_fastOutputStrides[i] = internal::TensorIntDivisor<Index>(m_outputStrides[i]); - } - } - - for (int i = 0; i < NumDims; ++i) { - m_inputStrides[i] = m_unshuffledInputStrides[shuffle[i]]; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - -#ifdef EIGEN_USE_THREADS - template <typename EvalSubExprsCallback> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync( - EvaluatorPointerType, EvalSubExprsCallback done) { - m_impl.evalSubExprsIfNeededAsync(nullptr, [done](bool) { done(true); }); - } -#endif // EIGEN_USE_THREADS - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - if (m_is_identity) { - return m_impl.coeff(index); - } else { - return m_impl.coeff(srcCoeff(index)); - } - } - - template <int LoadMode, typename Self, bool ImplPacketAccess> - struct PacketLoader { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - static PacketReturnType Run(const Self& self, Index index) { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = self.coeff(index + i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - }; - - template<int LoadMode, typename Self> - struct PacketLoader<LoadMode, Self, true> { - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - static PacketReturnType Run(const Self& self, Index index) { - if (self.m_is_identity) { - return self.m_impl.template packet<LoadMode>(index); - } else { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = self.coeff(index + i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - } - }; - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index + PacketSize - 1 < dimensions().TotalSize()); - return PacketLoader<LoadMode, Self, TensorEvaluator<ArgType, Device>::PacketAccess>::Run(*this, index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - internal::TensorBlockResourceRequirements getResourceRequirements() const { - static const int inner_dim = - Layout == static_cast<int>(ColMajor) ? 0 : NumDims - 1; - - const size_t target_size = m_device.firstLevelCacheSize(); - const bool inner_dim_shuffled = m_shuffle[inner_dim] != inner_dim; - - // Shuffled inner dimensions leads to a random memory access, which is not - // captured by default cost model bytes loaded/stored. We add this cost - // explicitly. The number of cycles picked based on the benchmarks. - // TODO(ezhulenev): This number was picked based on a very questionable - // benchmarks, add benchmarks that are representative of real workloads. - using BlockRequirements = internal::TensorBlockResourceRequirements; - if (inner_dim_shuffled) { - return BlockRequirements::uniform<Scalar>(target_size) - .addCostPerCoeff({0, 0, NumDims * 28}); - } else { - return BlockRequirements::skewed<Scalar>(target_size); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock - block(TensorBlockDesc& desc, TensorBlockScratch& scratch, - bool root_of_expr_ast = false) const { - assert(m_impl.data() != NULL); - - typedef internal::TensorBlockIO<ScalarNoConst, Index, NumDims, Layout> - TensorBlockIO; - typedef typename TensorBlockIO::Dst TensorBlockIODst; - typedef typename TensorBlockIO::Src TensorBlockIOSrc; - - const typename TensorBlock::Storage block_storage = - TensorBlock::prepareStorage( - desc, scratch, /*allow_strided_storage=*/root_of_expr_ast); - - typename TensorBlockIO::Dimensions input_strides(m_unshuffledInputStrides); - TensorBlockIOSrc src(input_strides, m_impl.data(), srcCoeff(desc.offset())); - - TensorBlockIODst dst(block_storage.dimensions(), block_storage.strides(), - block_storage.data()); - - typename TensorBlockIO::DimensionsMap dst_to_src_dim_map(m_shuffle); - TensorBlockIO::Copy(dst, src, dst_to_src_dim_map); - - return block_storage.AsTensorMaterializedBlock(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - const double compute_cost = m_is_identity ? TensorOpCost::AddCost<Index>() : - NumDims * (2 * TensorOpCost::AddCost<Index>() + - 2 * TensorOpCost::MulCost<Index>() + - TensorOpCost::DivCost<Index>()); - return m_impl.costPerCoeff(vectorized) + - TensorOpCost(0, 0, compute_cost, m_is_identity /* vectorized */, PacketSize); - } - - EIGEN_DEVICE_FUNC typename Storage::Type data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index GetBlockOutputIndex( - Index input_index, - const DSizes<Index, NumDims>& input_block_strides, - const DSizes<Index, NumDims>& output_block_strides, - const DSizes<internal::TensorIntDivisor<Index>, NumDims>& fast_input_block_strides) const { - Index output_index = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = input_index / fast_input_block_strides[i]; - output_index += idx * output_block_strides[m_inverseShuffle[i]]; - input_index -= idx * input_block_strides[i]; - } - return output_index + input_index * - output_block_strides[m_inverseShuffle[0]]; - } else { - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = input_index / fast_input_block_strides[i]; - output_index += idx * output_block_strides[m_inverseShuffle[i]]; - input_index -= idx * input_block_strides[i]; - } - return output_index + input_index * - output_block_strides[m_inverseShuffle[NumDims - 1]]; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index srcCoeff(Index index) const { - Index inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_fastOutputStrides[i]; - inputIndex += idx * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - return inputIndex + index * m_inputStrides[0]; - } else { - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_fastOutputStrides[i]; - inputIndex += idx * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - return inputIndex + index * m_inputStrides[NumDims - 1]; - } - } - - Dimensions m_dimensions; - bool m_is_identity; - array<int, NumDims> m_shuffle; - array<Index, NumDims> m_inverseShuffle; // TODO(ezhulenev): Make it int type. - array<Index, NumDims> m_outputStrides; - array<internal::TensorIntDivisor<Index>, NumDims> m_fastOutputStrides; - array<Index, NumDims> m_inputStrides; - array<Index, NumDims> m_unshuffledInputStrides; - - const Device EIGEN_DEVICE_REF m_device; - TensorEvaluator<ArgType, Device> m_impl; -}; - - -// Eval as lvalue -template<typename Shuffle, typename ArgType, typename Device> -struct TensorEvaluator<TensorShufflingOp<Shuffle, ArgType>, Device> - : public TensorEvaluator<const TensorShufflingOp<Shuffle, ArgType>, Device> -{ - typedef TensorEvaluator<const TensorShufflingOp<Shuffle, ArgType>, Device> Base; - - typedef TensorShufflingOp<Shuffle, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - - enum { - IsAligned = false, - PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1), - BlockAccess = TensorEvaluator<ArgType, Device>::RawAccess, - PreferBlockAccess = true, - Layout = TensorEvaluator<ArgType, Device>::Layout, - RawAccess = false - }; - - typedef typename internal::remove_const<Scalar>::type ScalarNoConst; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : Base(op, device) - { } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index) - { - return this->m_impl.coeffRef(this->srcCoeff(index)); - } - - template <int StoreMode> EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - internal::pstore<CoeffReturnType, PacketReturnType>(values, x); - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - this->coeffRef(index+i) = values[i]; - } - } - - template <typename TensorBlock> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writeBlock( - const TensorBlockDesc& desc, const TensorBlock& block) { - eigen_assert(this->m_impl.data() != NULL); - - typedef internal::TensorBlockIO<ScalarNoConst, Index, NumDims, Layout> - TensorBlockIO; - typedef typename TensorBlockIO::Dst TensorBlockIODst; - typedef typename TensorBlockIO::Src TensorBlockIOSrc; - - const Scalar* block_buffer = block.data(); - - // TODO(ezhulenev): TensorBlockIO should be able to read from any Eigen - // expression with coefficient and packet access as `src`. - void* mem = NULL; - if (block_buffer == NULL) { - mem = this->m_device.allocate(desc.size() * sizeof(Scalar)); - ScalarNoConst* buf = static_cast<ScalarNoConst*>(mem); - - typedef internal::TensorBlockAssignment< - ScalarNoConst, NumDims, typename TensorBlock::XprType, Index> - TensorBlockAssignment; - - TensorBlockAssignment::Run( - TensorBlockAssignment::target( - desc.dimensions(), internal::strides<Layout>(desc.dimensions()), - buf), - block.expr()); - - block_buffer = buf; - } - - // Read from block. - TensorBlockIOSrc src(internal::strides<Layout>(desc.dimensions()), - block_buffer); - - // Write to the output buffer. - typename TensorBlockIO::Dimensions output_strides( - this->m_unshuffledInputStrides); - typename TensorBlockIO::Dimensions output_dimensions; - for (int i = 0; i < NumDims; ++i) { - output_dimensions[this->m_shuffle[i]] = desc.dimension(i); - } - TensorBlockIODst dst(output_dimensions, output_strides, this->m_impl.data(), - this->srcCoeff(desc.offset())); - - // Reorder dimensions according to the shuffle. - typename TensorBlockIO::DimensionsMap dst_to_src_dim_map; - for (int i = 0; i < NumDims; ++i) { - dst_to_src_dim_map[i] = static_cast<int>(this->m_inverseShuffle[i]); - } - TensorBlockIO::Copy(dst, src, dst_to_src_dim_map); - - // Deallocate temporary buffer used for the block materialization. - if (mem != NULL) this->m_device.deallocate(mem); - } -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_SHUFFLING_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h deleted file mode 100644 index e6a666f7..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h +++ /dev/null @@ -1,146 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// Copyright (C) 2014-2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSORSTORAGE_H -#define EIGEN_CXX11_TENSOR_TENSORSTORAGE_H - -#ifdef EIGEN_TENSOR_STORAGE_CTOR_PLUGIN - #define EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN EIGEN_TENSOR_STORAGE_CTOR_PLUGIN; -#else - #define EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN -#endif - -namespace Eigen { - -/** \internal - * - * \class TensorStorage - * \ingroup CXX11_Tensor_Module - * - * \brief Stores the data of a tensor - * - * This class stores the data of fixed-size, dynamic-size or mixed tensors - * in a way as compact as possible. - * - * \sa Tensor - */ -template<typename T, typename Dimensions, int Options> class TensorStorage; - - -// Pure fixed-size storage -template<typename T, typename FixedDimensions, int Options_> -class TensorStorage -{ - private: - static const std::size_t Size = FixedDimensions::total_size; - - // Allocate an array of size at least one to prevent compiler warnings. - static const std::size_t MinSize = max_n_1<Size>::size; - EIGEN_ALIGN_MAX T m_data[MinSize]; - - FixedDimensions m_dimensions; - - public: - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorStorage() { - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE T *data() { return m_data; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const T *data() const { return m_data; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const FixedDimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE DenseIndex size() const { return m_dimensions.TotalSize(); } -}; - - -// pure dynamic -template<typename T, typename IndexType, int NumIndices_, int Options_> -class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_> -{ - public: - typedef IndexType Index; - typedef DSizes<IndexType, NumIndices_> Dimensions; - typedef TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_> Self; - - EIGEN_DEVICE_FUNC TensorStorage() : m_data(0), m_dimensions() { - if (NumIndices_ == 0) { - m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(1); - } - } - EIGEN_DEVICE_FUNC TensorStorage(internal::constructor_without_unaligned_array_assert) - : m_data(0), m_dimensions(internal::template repeat<NumIndices_, Index>(0)) {} - EIGEN_DEVICE_FUNC TensorStorage(Index size, const array<Index, NumIndices_>& dimensions) - : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size)), m_dimensions(dimensions) - { EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - template <typename... DenseIndex> - EIGEN_DEVICE_FUNC TensorStorage(DenseIndex... indices) : m_dimensions(indices...) { - m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(internal::array_prod(m_dimensions)); - } -#endif - - EIGEN_DEVICE_FUNC TensorStorage(const Self& other) - : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(internal::array_prod(other.m_dimensions))) - , m_dimensions(other.m_dimensions) - { - internal::smart_copy(other.m_data, other.m_data+internal::array_prod(other.m_dimensions), m_data); - } - EIGEN_DEVICE_FUNC Self& operator=(const Self& other) - { - if (this != &other) { - Self tmp(other); - this->swap(tmp); - } - return *this; - } - - EIGEN_DEVICE_FUNC ~TensorStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, internal::array_prod(m_dimensions)); } - EIGEN_DEVICE_FUNC void swap(Self& other) - { numext::swap(m_data,other.m_data); numext::swap(m_dimensions,other.m_dimensions); } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const {return m_dimensions;} - - EIGEN_DEVICE_FUNC void resize(Index size, const array<Index, NumIndices_>& nbDimensions) - { - const Index currentSz = internal::array_prod(m_dimensions); - if(size != currentSz) - { - internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, currentSz); - if (size) - m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size); - else if (NumIndices_ == 0) { - m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(1); - } - else - m_data = 0; - EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) - } - m_dimensions = nbDimensions; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T *data() { return m_data; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T *data() const { return m_data; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_dimensions.TotalSize(); } - - private: - T *m_data; - Dimensions m_dimensions; -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSORSTORAGE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStriding.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStriding.h deleted file mode 100644 index d05f3753..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorStriding.h +++ /dev/null @@ -1,362 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_STRIDING_H -#define EIGEN_CXX11_TENSOR_TENSOR_STRIDING_H - -namespace Eigen { - -/** \class TensorStriding - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor striding class. - * - * - */ -namespace internal { -template<typename Strides, typename XprType> -struct traits<TensorStridingOp<Strides, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; -}; - -template<typename Strides, typename XprType> -struct eval<TensorStridingOp<Strides, XprType>, Eigen::Dense> -{ - typedef const TensorStridingOp<Strides, XprType>EIGEN_DEVICE_REF type; -}; - -template<typename Strides, typename XprType> -struct nested<TensorStridingOp<Strides, XprType>, 1, typename eval<TensorStridingOp<Strides, XprType> >::type> -{ - typedef TensorStridingOp<Strides, XprType> type; -}; - -} // end namespace internal - - - -template<typename Strides, typename XprType> -class TensorStridingOp : public TensorBase<TensorStridingOp<Strides, XprType> > -{ - public: - typedef typename Eigen::internal::traits<TensorStridingOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorStridingOp>::type Nested; - typedef typename Eigen::internal::traits<TensorStridingOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorStridingOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorStridingOp(const XprType& expr, const Strides& dims) - : m_xpr(expr), m_dims(dims) {} - - EIGEN_DEVICE_FUNC - const Strides& strides() const { return m_dims; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorStridingOp& operator = (const TensorStridingOp& other) - { - typedef TensorAssignOp<TensorStridingOp, const TensorStridingOp> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - template<typename OtherDerived> - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE TensorStridingOp& operator = (const OtherDerived& other) - { - typedef TensorAssignOp<TensorStridingOp, const OtherDerived> Assign; - Assign assign(*this, other); - internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice()); - return *this; - } - - protected: - typename XprType::Nested m_xpr; - const Strides m_dims; -}; - - -// Eval as rvalue -template<typename Strides, typename ArgType, typename Device> -struct TensorEvaluator<const TensorStridingOp<Strides, ArgType>, Device> -{ - typedef TensorStridingOp<Strides, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = /*TensorEvaluator<ArgType, Device>::IsAligned*/false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device) - { - m_dimensions = m_impl.dimensions(); - for (int i = 0; i < NumDims; ++i) { - m_dimensions[i] =Eigen::numext::ceil(static_cast<float>(m_dimensions[i]) / op.strides()[i]); - } - - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_outputStrides[0] = 1; - m_inputStrides[0] = 1; - for (int i = 1; i < NumDims; ++i) { - m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1]; - m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1]; - m_inputStrides[i-1] *= op.strides()[i-1]; - } - m_inputStrides[NumDims-1] *= op.strides()[NumDims-1]; - } else { // RowMajor - m_outputStrides[NumDims-1] = 1; - m_inputStrides[NumDims-1] = 1; - for (int i = NumDims - 2; i >= 0; --i) { - m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1]; - m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1]; - m_inputStrides[i+1] *= op.strides()[i+1]; - } - m_inputStrides[0] *= op.strides()[0]; - } - } - - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType/*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - return m_impl.coeff(srcCoeff(index)); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - Index inputIndices[] = {0, 0}; - Index indices[] = {index, index + PacketSize - 1}; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx0 = indices[0] / m_outputStrides[i]; - const Index idx1 = indices[1] / m_outputStrides[i]; - inputIndices[0] += idx0 * m_inputStrides[i]; - inputIndices[1] += idx1 * m_inputStrides[i]; - indices[0] -= idx0 * m_outputStrides[i]; - indices[1] -= idx1 * m_outputStrides[i]; - } - inputIndices[0] += indices[0] * m_inputStrides[0]; - inputIndices[1] += indices[1] * m_inputStrides[0]; - } else { // RowMajor - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx0 = indices[0] / m_outputStrides[i]; - const Index idx1 = indices[1] / m_outputStrides[i]; - inputIndices[0] += idx0 * m_inputStrides[i]; - inputIndices[1] += idx1 * m_inputStrides[i]; - indices[0] -= idx0 * m_outputStrides[i]; - indices[1] -= idx1 * m_outputStrides[i]; - } - inputIndices[0] += indices[0] * m_inputStrides[NumDims-1]; - inputIndices[1] += indices[1] * m_inputStrides[NumDims-1]; - } - if (inputIndices[1] - inputIndices[0] == PacketSize - 1) { - PacketReturnType rslt = m_impl.template packet<Unaligned>(inputIndices[0]); - return rslt; - } - else { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - values[0] = m_impl.coeff(inputIndices[0]); - values[PacketSize-1] = m_impl.coeff(inputIndices[1]); - EIGEN_UNROLL_LOOP - for (int i = 1; i < PacketSize-1; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const { - double compute_cost = (NumDims - 1) * (TensorOpCost::AddCost<Index>() + - TensorOpCost::MulCost<Index>() + - TensorOpCost::DivCost<Index>()) + - TensorOpCost::MulCost<Index>(); - if (vectorized) { - compute_cost *= 2; // packet() computes two indices - } - const int innerDim = (static_cast<int>(Layout) == static_cast<int>(ColMajor)) ? 0 : (NumDims - 1); - return m_impl.costPerCoeff(vectorized && m_inputStrides[innerDim] == 1) + - // Computation is not vectorized per se, but it is done once per packet. - TensorOpCost(0, 0, compute_cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC typename Storage::Type data() const { return NULL; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index srcCoeff(Index index) const - { - Index inputIndex = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx = index / m_outputStrides[i]; - inputIndex += idx * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - inputIndex += index * m_inputStrides[0]; - } else { // RowMajor - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx = index / m_outputStrides[i]; - inputIndex += idx * m_inputStrides[i]; - index -= idx * m_outputStrides[i]; - } - inputIndex += index * m_inputStrides[NumDims-1]; - } - return inputIndex; - } - - Dimensions m_dimensions; - array<Index, NumDims> m_outputStrides; - array<Index, NumDims> m_inputStrides; - TensorEvaluator<ArgType, Device> m_impl; -}; - -// Eval as lvalue -template<typename Strides, typename ArgType, typename Device> -struct TensorEvaluator<TensorStridingOp<Strides, ArgType>, Device> - : public TensorEvaluator<const TensorStridingOp<Strides, ArgType>, Device> -{ - typedef TensorStridingOp<Strides, ArgType> XprType; - typedef TensorEvaluator<const XprType, Device> Base; - // typedef typename XprType::Index Index; - static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - // typedef DSizes<Index, NumDims> Dimensions; - - enum { - IsAligned = /*TensorEvaluator<ArgType, Device>::IsAligned*/false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - PreferBlockAccess = false, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, // to be implemented - RawAccess = false - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : Base(op, device) { } - - typedef typename XprType::Index Index; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) - { - return this->m_impl.coeffRef(this->srcCoeff(index)); - } - - template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void writePacket(Index index, const PacketReturnType& x) - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < this->dimensions().TotalSize()); - - Index inputIndices[] = {0, 0}; - Index indices[] = {index, index + PacketSize - 1}; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - EIGEN_UNROLL_LOOP - for (int i = NumDims - 1; i > 0; --i) { - const Index idx0 = indices[0] / this->m_outputStrides[i]; - const Index idx1 = indices[1] / this->m_outputStrides[i]; - inputIndices[0] += idx0 * this->m_inputStrides[i]; - inputIndices[1] += idx1 * this->m_inputStrides[i]; - indices[0] -= idx0 * this->m_outputStrides[i]; - indices[1] -= idx1 * this->m_outputStrides[i]; - } - inputIndices[0] += indices[0] * this->m_inputStrides[0]; - inputIndices[1] += indices[1] * this->m_inputStrides[0]; - } else { // RowMajor - EIGEN_UNROLL_LOOP - for (int i = 0; i < NumDims - 1; ++i) { - const Index idx0 = indices[0] / this->m_outputStrides[i]; - const Index idx1 = indices[1] / this->m_outputStrides[i]; - inputIndices[0] += idx0 * this->m_inputStrides[i]; - inputIndices[1] += idx1 * this->m_inputStrides[i]; - indices[0] -= idx0 * this->m_outputStrides[i]; - indices[1] -= idx1 * this->m_outputStrides[i]; - } - inputIndices[0] += indices[0] * this->m_inputStrides[NumDims-1]; - inputIndices[1] += indices[1] * this->m_inputStrides[NumDims-1]; - } - if (inputIndices[1] - inputIndices[0] == PacketSize - 1) { - this->m_impl.template writePacket<Unaligned>(inputIndices[0], x); - } - else { - EIGEN_ALIGN_MAX Scalar values[PacketSize]; - internal::pstore<Scalar, PacketReturnType>(values, x); - this->m_impl.coeffRef(inputIndices[0]) = values[0]; - this->m_impl.coeffRef(inputIndices[1]) = values[PacketSize-1]; - EIGEN_UNROLL_LOOP - for (int i = 1; i < PacketSize-1; ++i) { - this->coeffRef(index+i) = values[i]; - } - } - } -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_STRIDING_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h deleted file mode 100644 index 24d22c18..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h +++ /dev/null @@ -1,303 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2017 Gagan Goel <gagan.nith@gmail.com> -// Copyright (C) 2017 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_TRACE_H -#define EIGEN_CXX11_TENSOR_TENSOR_TRACE_H - -namespace Eigen { - -/** \class TensorTrace - * \ingroup CXX11_Tensor_Module - * - * \brief Tensor Trace class. - * - * - */ - -namespace internal { -template<typename Dims, typename XprType> -struct traits<TensorTraceOp<Dims, XprType> > : public traits<XprType> -{ - typedef typename XprType::Scalar Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions - array_size<Dims>::value; - static const int Layout = XprTraits::Layout; -}; - -template<typename Dims, typename XprType> -struct eval<TensorTraceOp<Dims, XprType>, Eigen::Dense> -{ - typedef const TensorTraceOp<Dims, XprType>& type; -}; - -template<typename Dims, typename XprType> -struct nested<TensorTraceOp<Dims, XprType>, 1, typename eval<TensorTraceOp<Dims, XprType> >::type> -{ - typedef TensorTraceOp<Dims, XprType> type; -}; - -} // end namespace internal - - -template<typename Dims, typename XprType> -class TensorTraceOp : public TensorBase<TensorTraceOp<Dims, XprType> > -{ - public: - typedef typename Eigen::internal::traits<TensorTraceOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorTraceOp>::type Nested; - typedef typename Eigen::internal::traits<TensorTraceOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorTraceOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorTraceOp(const XprType& expr, const Dims& dims) - : m_xpr(expr), m_dims(dims) { - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const Dims& dims() const { return m_dims; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const typename internal::remove_all<typename XprType::Nested>::type& expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const Dims m_dims; -}; - - -// Eval as rvalue -template<typename Dims, typename ArgType, typename Device> -struct TensorEvaluator<const TensorTraceOp<Dims, ArgType>, Device> -{ - typedef TensorTraceOp<Dims, ArgType> XprType; - static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - static const int NumReducedDims = internal::array_size<Dims>::value; - static const int NumOutputDims = NumInputDims - NumReducedDims; - typedef typename XprType::Index Index; - typedef DSizes<Index, NumOutputDims> Dimensions; - typedef typename XprType::Scalar Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = internal::unpacket_traits<PacketReturnType>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) - : m_impl(op.expression(), device), m_traceDim(1), m_device(device) - { - - EIGEN_STATIC_ASSERT((NumOutputDims >= 0), YOU_MADE_A_PROGRAMMING_MISTAKE); - EIGEN_STATIC_ASSERT((NumReducedDims >= 2) || ((NumReducedDims == 0) && (NumInputDims == 0)), YOU_MADE_A_PROGRAMMING_MISTAKE); - - for (int i = 0; i < NumInputDims; ++i) { - m_reduced[i] = false; - } - - const Dims& op_dims = op.dims(); - for (int i = 0; i < NumReducedDims; ++i) { - eigen_assert(op_dims[i] >= 0); - eigen_assert(op_dims[i] < NumInputDims); - m_reduced[op_dims[i]] = true; - } - - // All the dimensions should be distinct to compute the trace - int num_distinct_reduce_dims = 0; - for (int i = 0; i < NumInputDims; ++i) { - if (m_reduced[i]) { - ++num_distinct_reduce_dims; - } - } - - eigen_assert(num_distinct_reduce_dims == NumReducedDims); - - // Compute the dimensions of the result. - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - - int output_index = 0; - int reduced_index = 0; - for (int i = 0; i < NumInputDims; ++i) { - if (m_reduced[i]) { - m_reducedDims[reduced_index] = input_dims[i]; - if (reduced_index > 0) { - // All the trace dimensions must have the same size - eigen_assert(m_reducedDims[0] == m_reducedDims[reduced_index]); - } - ++reduced_index; - } - else { - m_dimensions[output_index] = input_dims[i]; - ++output_index; - } - } - - if (NumReducedDims != 0) { - m_traceDim = m_reducedDims[0]; - } - - // Compute the output strides - if (NumOutputDims > 0) { - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_outputStrides[0] = 1; - for (int i = 1; i < NumOutputDims; ++i) { - m_outputStrides[i] = m_outputStrides[i - 1] * m_dimensions[i - 1]; - } - } - else { - m_outputStrides.back() = 1; - for (int i = NumOutputDims - 2; i >= 0; --i) { - m_outputStrides[i] = m_outputStrides[i + 1] * m_dimensions[i + 1]; - } - } - } - - // Compute the input strides - if (NumInputDims > 0) { - array<Index, NumInputDims> input_strides; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - input_strides[0] = 1; - for (int i = 1; i < NumInputDims; ++i) { - input_strides[i] = input_strides[i - 1] * input_dims[i - 1]; - } - } - else { - input_strides.back() = 1; - for (int i = NumInputDims - 2; i >= 0; --i) { - input_strides[i] = input_strides[i + 1] * input_dims[i + 1]; - } - } - - output_index = 0; - reduced_index = 0; - for (int i = 0; i < NumInputDims; ++i) { - if(m_reduced[i]) { - m_reducedStrides[reduced_index] = input_strides[i]; - ++reduced_index; - } - else { - m_preservedStrides[output_index] = input_strides[i]; - ++output_index; - } - } - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { - return m_dimensions; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - // Initialize the result - CoeffReturnType result = internal::cast<int, CoeffReturnType>(0); - Index index_stride = 0; - for (int i = 0; i < NumReducedDims; ++i) { - index_stride += m_reducedStrides[i]; - } - - // If trace is requested along all dimensions, starting index would be 0 - Index cur_index = 0; - if (NumOutputDims != 0) - cur_index = firstInput(index); - for (Index i = 0; i < m_traceDim; ++i) { - result += m_impl.coeff(cur_index); - cur_index += index_stride; - } - - return result; - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const { - - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE); - eigen_assert(index + PacketSize - 1 < dimensions().TotalSize()); - - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index + i); - } - PacketReturnType result = internal::ploadt<PacketReturnType, LoadMode>(values); - return result; - } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - - protected: - // Given the output index, finds the first index in the input tensor used to compute the trace - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index firstInput(Index index) const { - Index startInput = 0; - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - for (int i = NumOutputDims - 1; i > 0; --i) { - const Index idx = index / m_outputStrides[i]; - startInput += idx * m_preservedStrides[i]; - index -= idx * m_outputStrides[i]; - } - startInput += index * m_preservedStrides[0]; - } - else { - for (int i = 0; i < NumOutputDims - 1; ++i) { - const Index idx = index / m_outputStrides[i]; - startInput += idx * m_preservedStrides[i]; - index -= idx * m_outputStrides[i]; - } - startInput += index * m_preservedStrides[NumOutputDims - 1]; - } - return startInput; - } - - Dimensions m_dimensions; - TensorEvaluator<ArgType, Device> m_impl; - // Initialize the size of the trace dimension - Index m_traceDim; - const Device EIGEN_DEVICE_REF m_device; - array<bool, NumInputDims> m_reduced; - array<Index, NumReducedDims> m_reducedDims; - array<Index, NumOutputDims> m_outputStrides; - array<Index, NumReducedDims> m_reducedStrides; - array<Index, NumOutputDims> m_preservedStrides; -}; - - -} // End namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_TRACE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h deleted file mode 100644 index 4f7fd340..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h +++ /dev/null @@ -1,264 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H -#define EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H - -namespace Eigen { -namespace internal { - - -template<typename Scalar, int Options> -class compute_tensor_flags -{ - enum { - is_dynamic_size_storage = 1, - - is_aligned = - ( - ((Options&DontAlign)==0) && ( -#if EIGEN_MAX_STATIC_ALIGN_BYTES>0 - (!is_dynamic_size_storage) -#else - 0 -#endif - | -#if EIGEN_MAX_ALIGN_BYTES>0 - is_dynamic_size_storage -#else - 0 -#endif - ) - ), - packet_access_bit = packet_traits<Scalar>::Vectorizable && is_aligned ? PacketAccessBit : 0 - }; - - public: - enum { ret = packet_access_bit }; -}; - - -template<typename Scalar_, int NumIndices_, int Options_, typename IndexType_> -struct traits<Tensor<Scalar_, NumIndices_, Options_, IndexType_> > -{ - typedef Scalar_ Scalar; - typedef Dense StorageKind; - typedef IndexType_ Index; - static const int NumDimensions = NumIndices_; - static const int Layout = Options_ & RowMajor ? RowMajor : ColMajor; - enum { - Options = Options_, - Flags = compute_tensor_flags<Scalar_, Options_>::ret | (is_const<Scalar_>::value ? 0 : LvalueBit) - }; - template <typename T> struct MakePointer { - typedef T* Type; - }; - typedef typename MakePointer<Scalar>::Type PointerType; -}; - - -template<typename Scalar_, typename Dimensions, int Options_, typename IndexType_> -struct traits<TensorFixedSize<Scalar_, Dimensions, Options_, IndexType_> > -{ - typedef Scalar_ Scalar; - typedef Dense StorageKind; - typedef IndexType_ Index; - static const int NumDimensions = array_size<Dimensions>::value; - static const int Layout = Options_ & RowMajor ? RowMajor : ColMajor; - enum { - Options = Options_, - Flags = compute_tensor_flags<Scalar_, Options_>::ret | (is_const<Scalar_>::value ? 0: LvalueBit) - }; - template <typename T> struct MakePointer { - typedef T* Type; - }; - typedef typename MakePointer<Scalar>::Type PointerType; -}; - - -template<typename PlainObjectType, int Options_, template <class> class MakePointer_> -struct traits<TensorMap<PlainObjectType, Options_, MakePointer_> > - : public traits<PlainObjectType> -{ - typedef traits<PlainObjectType> BaseTraits; - typedef typename BaseTraits::Scalar Scalar; - typedef typename BaseTraits::StorageKind StorageKind; - typedef typename BaseTraits::Index Index; - static const int NumDimensions = BaseTraits::NumDimensions; - static const int Layout = BaseTraits::Layout; - enum { - Options = Options_, - Flags = BaseTraits::Flags - }; - template <class T> struct MakePointer { - // Intermediate typedef to workaround MSVC issue. - typedef MakePointer_<T> MakePointerT; - typedef typename MakePointerT::Type Type; - }; - typedef typename MakePointer<Scalar>::Type PointerType; -}; - -template<typename PlainObjectType> -struct traits<TensorRef<PlainObjectType> > - : public traits<PlainObjectType> -{ - typedef traits<PlainObjectType> BaseTraits; - typedef typename BaseTraits::Scalar Scalar; - typedef typename BaseTraits::StorageKind StorageKind; - typedef typename BaseTraits::Index Index; - static const int NumDimensions = BaseTraits::NumDimensions; - static const int Layout = BaseTraits::Layout; - enum { - Options = BaseTraits::Options, - Flags = BaseTraits::Flags - }; - typedef typename BaseTraits::PointerType PointerType; -}; - - -template<typename _Scalar, int NumIndices_, int Options, typename IndexType_> -struct eval<Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense> -{ - typedef const Tensor<_Scalar, NumIndices_, Options, IndexType_>EIGEN_DEVICE_REF type; -}; - -template<typename _Scalar, int NumIndices_, int Options, typename IndexType_> -struct eval<const Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense> -{ - typedef const Tensor<_Scalar, NumIndices_, Options, IndexType_>EIGEN_DEVICE_REF type; -}; - -template<typename Scalar_, typename Dimensions, int Options, typename IndexType_> -struct eval<TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>, Eigen::Dense> -{ - typedef const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>EIGEN_DEVICE_REF type; -}; - -template<typename Scalar_, typename Dimensions, int Options, typename IndexType_> -struct eval<const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>, Eigen::Dense> -{ - typedef const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>EIGEN_DEVICE_REF type; -}; - -template<typename PlainObjectType, int Options, template <class> class MakePointer> -struct eval<TensorMap<PlainObjectType, Options, MakePointer>, Eigen::Dense> -{ - typedef const TensorMap<PlainObjectType, Options, MakePointer>EIGEN_DEVICE_REF type; -}; - -template<typename PlainObjectType, int Options, template <class> class MakePointer> -struct eval<const TensorMap<PlainObjectType, Options, MakePointer>, Eigen::Dense> -{ - typedef const TensorMap<PlainObjectType, Options, MakePointer>EIGEN_DEVICE_REF type; -}; - -template<typename PlainObjectType> -struct eval<TensorRef<PlainObjectType>, Eigen::Dense> -{ - typedef const TensorRef<PlainObjectType>EIGEN_DEVICE_REF type; -}; - -template<typename PlainObjectType> -struct eval<const TensorRef<PlainObjectType>, Eigen::Dense> -{ - typedef const TensorRef<PlainObjectType>EIGEN_DEVICE_REF type; -}; - -// TODO nested<> does not exist anymore in Eigen/Core, and it thus has to be removed in favor of ref_selector. -template<typename T, int n=1, typename PlainObject = void> struct nested -{ - typedef typename ref_selector<T>::type type; -}; - -template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_> -struct nested<Tensor<Scalar_, NumIndices_, Options_, IndexType_> > -{ - typedef const Tensor<Scalar_, NumIndices_, Options_, IndexType_>EIGEN_DEVICE_REF type; -}; - -template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_> -struct nested<const Tensor<Scalar_, NumIndices_, Options_, IndexType_> > -{ - typedef const Tensor<Scalar_, NumIndices_, Options_, IndexType_>EIGEN_DEVICE_REF type; -}; - -template <typename Scalar_, typename Dimensions, int Options, typename IndexType_> -struct nested<TensorFixedSize<Scalar_, Dimensions, Options, IndexType_> > -{ - typedef const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>EIGEN_DEVICE_REF type; -}; - -template <typename Scalar_, typename Dimensions, int Options, typename IndexType_> -struct nested<const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_> > -{ - typedef const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>EIGEN_DEVICE_REF type; -}; - - -template <typename PlainObjectType> -struct nested<TensorRef<PlainObjectType> > -{ - typedef const TensorRef<PlainObjectType>EIGEN_DEVICE_REF type; -}; - -template <typename PlainObjectType> -struct nested<const TensorRef<PlainObjectType> > -{ - typedef const TensorRef<PlainObjectType>EIGEN_DEVICE_REF type; -}; - -} // end namespace internal - -// Convolutional layers take in an input tensor of shape (D, R, C, B), or (D, C, -// R, B), and convolve it with a set of filters, which can also be presented as -// a tensor (D, K, K, M), where M is the number of filters, K is the filter -// size, and each 3-dimensional tensor of size (D, K, K) is a filter. For -// simplicity we assume that we always use square filters (which is usually the -// case in images), hence the two Ks in the tensor dimension. It also takes in -// a few additional parameters: -// Stride (S): The convolution stride is the offset between locations where we -// apply the filters. A larger stride means that the output will be -// spatially smaller. -// Padding (P): The padding we apply to the input tensor along the R and C -// dimensions. This is usually used to make sure that the spatial -// dimensions of the output matches our intention. -// -// Two types of padding are often used: -// SAME: The pad value is computed so that the output will have size -// R/S and C/S. -// VALID: no padding is carried out. -// When we do padding, the padded values at the padded locations are usually -// zero. -// -// The output dimensions for convolution, when given all the parameters above, -// are as follows: -// When Padding = SAME: the output size is (B, R', C', M), where -// R' = ceil(float(R) / float(S)) -// C' = ceil(float(C) / float(S)) -// where ceil is the ceiling function. The input tensor is padded with 0 as -// needed. The number of padded rows and columns are computed as: -// Pr = ((R' - 1) * S + K - R) / 2 -// Pc = ((C' - 1) * S + K - C) / 2 -// when the stride is 1, we have the simplified case R'=R, C'=C, Pr=Pc=(K-1)/2. -// This is where SAME comes from - the output has the same size as the input has. -// When Padding = VALID: the output size is computed as -// R' = ceil(float(R - K + 1) / float(S)) -// C' = ceil(float(C - K + 1) / float(S)) -// and the number of padded rows and columns are computed in the same way as in -// the SAME case. -// When the stride is 1, we have the simplified case R'=R-K+1, C'=C-K+1, Pr=0, -// Pc=0. -typedef enum { - PADDING_VALID = 1, - PADDING_SAME = 2 -} PaddingType; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h deleted file mode 100644 index d23f2e4c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h +++ /dev/null @@ -1,249 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_UINT128_H -#define EIGEN_CXX11_TENSOR_TENSOR_UINT128_H - -namespace Eigen { -namespace internal { - - -template <uint64_t n> -struct static_val { - static const uint64_t value = n; - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE operator uint64_t() const { return n; } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static_val() { } - - template <typename T> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static_val(const T& v) { - EIGEN_UNUSED_VARIABLE(v); - eigen_assert(v == n); - } -}; - - -template <typename HIGH = uint64_t, typename LOW = uint64_t> -struct TensorUInt128 -{ - HIGH high; - LOW low; - - template<typename OTHER_HIGH, typename OTHER_LOW> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128(const TensorUInt128<OTHER_HIGH, OTHER_LOW>& other) : high(other.high), low(other.low) { - EIGEN_STATIC_ASSERT(sizeof(OTHER_HIGH) <= sizeof(HIGH), YOU_MADE_A_PROGRAMMING_MISTAKE); - EIGEN_STATIC_ASSERT(sizeof(OTHER_LOW) <= sizeof(LOW), YOU_MADE_A_PROGRAMMING_MISTAKE); - } - - template<typename OTHER_HIGH, typename OTHER_LOW> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128& operator = (const TensorUInt128<OTHER_HIGH, OTHER_LOW>& other) { - EIGEN_STATIC_ASSERT(sizeof(OTHER_HIGH) <= sizeof(HIGH), YOU_MADE_A_PROGRAMMING_MISTAKE); - EIGEN_STATIC_ASSERT(sizeof(OTHER_LOW) <= sizeof(LOW), YOU_MADE_A_PROGRAMMING_MISTAKE); - high = other.high; - low = other.low; - return *this; - } - - template<typename T> - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - explicit TensorUInt128(const T& x) : high(0), low(x) { - eigen_assert((static_cast<typename conditional<sizeof(T) == 8, uint64_t, uint32_t>::type>(x) <= NumTraits<uint64_t>::highest())); - eigen_assert(x >= 0); - } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128(HIGH y, LOW x) : high(y), low(x) { } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE operator LOW() const { - return low; - } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LOW lower() const { - return low; - } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE HIGH upper() const { - return high; - } -}; - - -template <typename HL, typename LL, typename HR, typename LR> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -bool operator == (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) -{ - return (lhs.high == rhs.high) & (lhs.low == rhs.low); -} - -template <typename HL, typename LL, typename HR, typename LR> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -bool operator != (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) -{ - return (lhs.high != rhs.high) | (lhs.low != rhs.low); -} - -template <typename HL, typename LL, typename HR, typename LR> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -bool operator >= (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) -{ - if (lhs.high != rhs.high) { - return lhs.high > rhs.high; - } - return lhs.low >= rhs.low; -} - -template <typename HL, typename LL, typename HR, typename LR> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -bool operator < (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) -{ - if (lhs.high != rhs.high) { - return lhs.high < rhs.high; - } - return lhs.low < rhs.low; -} - -template <typename HL, typename LL, typename HR, typename LR> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -TensorUInt128<uint64_t, uint64_t> operator + (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) -{ - TensorUInt128<uint64_t, uint64_t> result(lhs.high + rhs.high, lhs.low + rhs.low); - if (result.low < rhs.low) { - result.high += 1; - } - return result; -} - -template <typename HL, typename LL, typename HR, typename LR> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -TensorUInt128<uint64_t, uint64_t> operator - (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) -{ - TensorUInt128<uint64_t, uint64_t> result(lhs.high - rhs.high, lhs.low - rhs.low); - if (result.low > lhs.low) { - result.high -= 1; - } - return result; -} - - -template <typename HL, typename LL, typename HR, typename LR> -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -TensorUInt128<uint64_t, uint64_t> operator * (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) -{ - // Split each 128-bit integer into 4 32-bit integers, and then do the - // multiplications by hand as follow: - // lhs a b c d - // rhs e f g h - // ----------- - // ah bh ch dh - // bg cg dg - // cf df - // de - // The result is stored in 2 64bit integers, high and low. - - const uint64_t LOW = 0x00000000FFFFFFFFLL; - const uint64_t HIGH = 0xFFFFFFFF00000000LL; - - uint64_t d = lhs.low & LOW; - uint64_t c = (lhs.low & HIGH) >> 32LL; - uint64_t b = lhs.high & LOW; - uint64_t a = (lhs.high & HIGH) >> 32LL; - - uint64_t h = rhs.low & LOW; - uint64_t g = (rhs.low & HIGH) >> 32LL; - uint64_t f = rhs.high & LOW; - uint64_t e = (rhs.high & HIGH) >> 32LL; - - // Compute the low 32 bits of low - uint64_t acc = d * h; - uint64_t low = acc & LOW; - // Compute the high 32 bits of low. Add a carry every time we wrap around - acc >>= 32LL; - uint64_t carry = 0; - uint64_t acc2 = acc + c * h; - if (acc2 < acc) { - carry++; - } - acc = acc2 + d * g; - if (acc < acc2) { - carry++; - } - low |= (acc << 32LL); - - // Carry forward the high bits of acc to initiate the computation of the - // low 32 bits of high - acc2 = (acc >> 32LL) | (carry << 32LL); - carry = 0; - - acc = acc2 + b * h; - if (acc < acc2) { - carry++; - } - acc2 = acc + c * g; - if (acc2 < acc) { - carry++; - } - acc = acc2 + d * f; - if (acc < acc2) { - carry++; - } - uint64_t high = acc & LOW; - - // Start to compute the high 32 bits of high. - acc2 = (acc >> 32LL) | (carry << 32LL); - - acc = acc2 + a * h; - acc2 = acc + b * g; - acc = acc2 + c * f; - acc2 = acc + d * e; - high |= (acc2 << 32LL); - - return TensorUInt128<uint64_t, uint64_t>(high, low); -} - -template <typename HL, typename LL, typename HR, typename LR> -static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -TensorUInt128<uint64_t, uint64_t> operator / (const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) -{ - if (rhs == TensorUInt128<static_val<0>, static_val<1> >(1)) { - return TensorUInt128<uint64_t, uint64_t>(lhs.high, lhs.low); - } else if (lhs < rhs) { - return TensorUInt128<uint64_t, uint64_t>(0); - } else { - // calculate the biggest power of 2 times rhs that's less than or equal to lhs - TensorUInt128<uint64_t, uint64_t> power2(1); - TensorUInt128<uint64_t, uint64_t> d(rhs); - TensorUInt128<uint64_t, uint64_t> tmp(lhs - d); - while (lhs >= d) { - tmp = tmp - d; - d = d + d; - power2 = power2 + power2; - } - - tmp = TensorUInt128<uint64_t, uint64_t>(lhs.high, lhs.low); - TensorUInt128<uint64_t, uint64_t> result(0); - while (power2 != TensorUInt128<static_val<0>, static_val<0> >(0)) { - if (tmp >= d) { - tmp = tmp - d; - result = result + power2; - } - // Shift right - power2 = TensorUInt128<uint64_t, uint64_t>(power2.high >> 1, (power2.low >> 1) | (power2.high << 63)); - d = TensorUInt128<uint64_t, uint64_t>(d.high >> 1, (d.low >> 1) | (d.high << 63)); - } - - return result; - } -} - - -} // namespace internal -} // namespace Eigen - - -#endif // EIGEN_CXX11_TENSOR_TENSOR_UINT128_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorVolumePatch.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorVolumePatch.h deleted file mode 100644 index 000ed5b4..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorVolumePatch.h +++ /dev/null @@ -1,629 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. - -#ifndef EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H -#define EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H - -namespace Eigen { - -/** \class TensorVolumePatch - * \ingroup CXX11_Tensor_Module - * - * \brief Patch extraction specialized for processing of volumetric data. - * This assumes that the input has a least 4 dimensions ordered as follows: - * - channels - * - planes - * - rows - * - columns - * - (optional) additional dimensions such as time or batch size. - * Calling the volume patch code with patch_planes, patch_rows, and patch_cols - * is equivalent to calling the regular patch extraction code with parameters - * d, patch_planes, patch_rows, patch_cols, and 1 for all the additional - * dimensions. - */ -namespace internal { - -template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType> -struct traits<TensorVolumePatchOp<Planes, Rows, Cols, XprType> > : public traits<XprType> -{ - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef traits<XprType> XprTraits; - typedef typename XprTraits::StorageKind StorageKind; - typedef typename XprTraits::Index Index; - typedef typename XprType::Nested Nested; - typedef typename remove_reference<Nested>::type _Nested; - static const int NumDimensions = XprTraits::NumDimensions + 1; - static const int Layout = XprTraits::Layout; - typedef typename XprTraits::PointerType PointerType; - -}; - -template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType> -struct eval<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, Eigen::Dense> -{ - typedef const TensorVolumePatchOp<Planes, Rows, Cols, XprType>& type; -}; - -template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType> -struct nested<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, 1, typename eval<TensorVolumePatchOp<Planes, Rows, Cols, XprType> >::type> -{ - typedef TensorVolumePatchOp<Planes, Rows, Cols, XprType> type; -}; - -} // end namespace internal - -template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType> -class TensorVolumePatchOp : public TensorBase<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, ReadOnlyAccessors> -{ - public: - typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Scalar Scalar; - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename Eigen::internal::nested<TensorVolumePatchOp>::type Nested; - typedef typename Eigen::internal::traits<TensorVolumePatchOp>::StorageKind StorageKind; - typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Index Index; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(const XprType& expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols, - DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides, - DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides, - DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides, - PaddingType padding_type, Scalar padding_value) - : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols), - m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides), - m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides), - m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides), - m_padding_explicit(false), m_padding_top_z(0), m_padding_bottom_z(0), m_padding_top(0), m_padding_bottom(0), m_padding_left(0), m_padding_right(0), - m_padding_type(padding_type), m_padding_value(padding_value) {} - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(const XprType& expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols, - DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides, - DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides, - DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides, - DenseIndex padding_top_z, DenseIndex padding_bottom_z, - DenseIndex padding_top, DenseIndex padding_bottom, - DenseIndex padding_left, DenseIndex padding_right, - Scalar padding_value) - : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols), - m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides), - m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides), - m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides), - m_padding_explicit(true), m_padding_top_z(padding_top_z), m_padding_bottom_z(padding_bottom_z), m_padding_top(padding_top), m_padding_bottom(padding_bottom), - m_padding_left(padding_left), m_padding_right(padding_right), - m_padding_type(PADDING_VALID), m_padding_value(padding_value) {} - - EIGEN_DEVICE_FUNC - DenseIndex patch_planes() const { return m_patch_planes; } - EIGEN_DEVICE_FUNC - DenseIndex patch_rows() const { return m_patch_rows; } - EIGEN_DEVICE_FUNC - DenseIndex patch_cols() const { return m_patch_cols; } - EIGEN_DEVICE_FUNC - DenseIndex plane_strides() const { return m_plane_strides; } - EIGEN_DEVICE_FUNC - DenseIndex row_strides() const { return m_row_strides; } - EIGEN_DEVICE_FUNC - DenseIndex col_strides() const { return m_col_strides; } - EIGEN_DEVICE_FUNC - DenseIndex in_plane_strides() const { return m_in_plane_strides; } - EIGEN_DEVICE_FUNC - DenseIndex in_row_strides() const { return m_in_row_strides; } - EIGEN_DEVICE_FUNC - DenseIndex in_col_strides() const { return m_in_col_strides; } - EIGEN_DEVICE_FUNC - DenseIndex plane_inflate_strides() const { return m_plane_inflate_strides; } - EIGEN_DEVICE_FUNC - DenseIndex row_inflate_strides() const { return m_row_inflate_strides; } - EIGEN_DEVICE_FUNC - DenseIndex col_inflate_strides() const { return m_col_inflate_strides; } - EIGEN_DEVICE_FUNC - bool padding_explicit() const { return m_padding_explicit; } - EIGEN_DEVICE_FUNC - DenseIndex padding_top_z() const { return m_padding_top_z; } - EIGEN_DEVICE_FUNC - DenseIndex padding_bottom_z() const { return m_padding_bottom_z; } - EIGEN_DEVICE_FUNC - DenseIndex padding_top() const { return m_padding_top; } - EIGEN_DEVICE_FUNC - DenseIndex padding_bottom() const { return m_padding_bottom; } - EIGEN_DEVICE_FUNC - DenseIndex padding_left() const { return m_padding_left; } - EIGEN_DEVICE_FUNC - DenseIndex padding_right() const { return m_padding_right; } - EIGEN_DEVICE_FUNC - PaddingType padding_type() const { return m_padding_type; } - EIGEN_DEVICE_FUNC - Scalar padding_value() const { return m_padding_value; } - - EIGEN_DEVICE_FUNC - const typename internal::remove_all<typename XprType::Nested>::type& - expression() const { return m_xpr; } - - protected: - typename XprType::Nested m_xpr; - const DenseIndex m_patch_planes; - const DenseIndex m_patch_rows; - const DenseIndex m_patch_cols; - const DenseIndex m_plane_strides; - const DenseIndex m_row_strides; - const DenseIndex m_col_strides; - const DenseIndex m_in_plane_strides; - const DenseIndex m_in_row_strides; - const DenseIndex m_in_col_strides; - const DenseIndex m_plane_inflate_strides; - const DenseIndex m_row_inflate_strides; - const DenseIndex m_col_inflate_strides; - const bool m_padding_explicit; - const DenseIndex m_padding_top_z; - const DenseIndex m_padding_bottom_z; - const DenseIndex m_padding_top; - const DenseIndex m_padding_bottom; - const DenseIndex m_padding_left; - const DenseIndex m_padding_right; - const PaddingType m_padding_type; - const Scalar m_padding_value; -}; - - -// Eval as rvalue -template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename ArgType, typename Device> -struct TensorEvaluator<const TensorVolumePatchOp<Planes, Rows, Cols, ArgType>, Device> -{ - typedef TensorVolumePatchOp<Planes, Rows, Cols, ArgType> XprType; - typedef typename XprType::Index Index; - static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value; - static const int NumDims = NumInputDims + 1; - typedef DSizes<Index, NumDims> Dimensions; - typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar; - typedef typename XprType::CoeffReturnType CoeffReturnType; - typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType; - static const int PacketSize = PacketType<CoeffReturnType, Device>::size; - typedef StorageMemory<CoeffReturnType, Device> Storage; - typedef typename Storage::Type EvaluatorPointerType; - - enum { - IsAligned = false, - PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess, - BlockAccess = false, - PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess, - Layout = TensorEvaluator<ArgType, Device>::Layout, - CoordAccess = false, - RawAccess = false - }; - - //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===// - typedef internal::TensorBlockNotImplemented TensorBlock; - //===--------------------------------------------------------------------===// - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) : - m_impl(op.expression(), device) - { - EIGEN_STATIC_ASSERT((NumDims >= 5), YOU_MADE_A_PROGRAMMING_MISTAKE); - - m_paddingValue = op.padding_value(); - - const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions(); - - // Cache a few variables. - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_inputDepth = input_dims[0]; - m_inputPlanes = input_dims[1]; - m_inputRows = input_dims[2]; - m_inputCols = input_dims[3]; - } else { - m_inputDepth = input_dims[NumInputDims-1]; - m_inputPlanes = input_dims[NumInputDims-2]; - m_inputRows = input_dims[NumInputDims-3]; - m_inputCols = input_dims[NumInputDims-4]; - } - - m_plane_strides = op.plane_strides(); - m_row_strides = op.row_strides(); - m_col_strides = op.col_strides(); - - // Input strides and effective input/patch size - m_in_plane_strides = op.in_plane_strides(); - m_in_row_strides = op.in_row_strides(); - m_in_col_strides = op.in_col_strides(); - m_plane_inflate_strides = op.plane_inflate_strides(); - m_row_inflate_strides = op.row_inflate_strides(); - m_col_inflate_strides = op.col_inflate_strides(); - - // The "effective" spatial size after inflating data with zeros. - m_input_planes_eff = (m_inputPlanes - 1) * m_plane_inflate_strides + 1; - m_input_rows_eff = (m_inputRows - 1) * m_row_inflate_strides + 1; - m_input_cols_eff = (m_inputCols - 1) * m_col_inflate_strides + 1; - m_patch_planes_eff = op.patch_planes() + (op.patch_planes() - 1) * (m_in_plane_strides - 1); - m_patch_rows_eff = op.patch_rows() + (op.patch_rows() - 1) * (m_in_row_strides - 1); - m_patch_cols_eff = op.patch_cols() + (op.patch_cols() - 1) * (m_in_col_strides - 1); - - if (op.padding_explicit()) { - m_outputPlanes = numext::ceil((m_input_planes_eff + op.padding_top_z() + op.padding_bottom_z() - m_patch_planes_eff + 1.f) / static_cast<float>(m_plane_strides)); - m_outputRows = numext::ceil((m_input_rows_eff + op.padding_top() + op.padding_bottom() - m_patch_rows_eff + 1.f) / static_cast<float>(m_row_strides)); - m_outputCols = numext::ceil((m_input_cols_eff + op.padding_left() + op.padding_right() - m_patch_cols_eff + 1.f) / static_cast<float>(m_col_strides)); - m_planePaddingTop = op.padding_top_z(); - m_rowPaddingTop = op.padding_top(); - m_colPaddingLeft = op.padding_left(); - } else { - // Computing padding from the type - switch (op.padding_type()) { - case PADDING_VALID: - m_outputPlanes = numext::ceil((m_input_planes_eff - m_patch_planes_eff + 1.f) / static_cast<float>(m_plane_strides)); - m_outputRows = numext::ceil((m_input_rows_eff - m_patch_rows_eff + 1.f) / static_cast<float>(m_row_strides)); - m_outputCols = numext::ceil((m_input_cols_eff - m_patch_cols_eff + 1.f) / static_cast<float>(m_col_strides)); - m_planePaddingTop = 0; - m_rowPaddingTop = 0; - m_colPaddingLeft = 0; - break; - case PADDING_SAME: { - m_outputPlanes = numext::ceil(m_input_planes_eff / static_cast<float>(m_plane_strides)); - m_outputRows = numext::ceil(m_input_rows_eff / static_cast<float>(m_row_strides)); - m_outputCols = numext::ceil(m_input_cols_eff / static_cast<float>(m_col_strides)); - const Index dz = m_outputPlanes * m_plane_strides + m_patch_planes_eff - 1 - m_input_planes_eff; - const Index dy = m_outputRows * m_row_strides + m_patch_rows_eff - 1 - m_input_rows_eff; - const Index dx = m_outputCols * m_col_strides + m_patch_cols_eff - 1 - m_input_cols_eff; - m_planePaddingTop = dz - dz / 2; - m_rowPaddingTop = dy - dy / 2; - m_colPaddingLeft = dx - dx / 2; - break; - } - default: - eigen_assert(false && "unexpected padding"); - } - } - eigen_assert(m_outputRows > 0); - eigen_assert(m_outputCols > 0); - eigen_assert(m_outputPlanes > 0); - - // Dimensions for result of extraction. - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - // ColMajor - // 0: depth - // 1: patch_planes - // 2: patch_rows - // 3: patch_cols - // 4: number of patches - // 5 and beyond: anything else (such as batch). - m_dimensions[0] = input_dims[0]; - m_dimensions[1] = op.patch_planes(); - m_dimensions[2] = op.patch_rows(); - m_dimensions[3] = op.patch_cols(); - m_dimensions[4] = m_outputPlanes * m_outputRows * m_outputCols; - for (int i = 5; i < NumDims; ++i) { - m_dimensions[i] = input_dims[i-1]; - } - } else { - // RowMajor - // NumDims-1: depth - // NumDims-2: patch_planes - // NumDims-3: patch_rows - // NumDims-4: patch_cols - // NumDims-5: number of patches - // NumDims-6 and beyond: anything else (such as batch). - m_dimensions[NumDims-1] = input_dims[NumInputDims-1]; - m_dimensions[NumDims-2] = op.patch_planes(); - m_dimensions[NumDims-3] = op.patch_rows(); - m_dimensions[NumDims-4] = op.patch_cols(); - m_dimensions[NumDims-5] = m_outputPlanes * m_outputRows * m_outputCols; - for (int i = NumDims-6; i >= 0; --i) { - m_dimensions[i] = input_dims[i]; - } - } - - // Strides for the output tensor. - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_rowStride = m_dimensions[1]; - m_colStride = m_dimensions[2] * m_rowStride; - m_patchStride = m_colStride * m_dimensions[3] * m_dimensions[0]; - m_otherStride = m_patchStride * m_dimensions[4]; - } else { - m_rowStride = m_dimensions[NumDims-2]; - m_colStride = m_dimensions[NumDims-3] * m_rowStride; - m_patchStride = m_colStride * m_dimensions[NumDims-4] * m_dimensions[NumDims-1]; - m_otherStride = m_patchStride * m_dimensions[NumDims-5]; - } - - // Strides for navigating through the input tensor. - m_planeInputStride = m_inputDepth; - m_rowInputStride = m_inputDepth * m_inputPlanes; - m_colInputStride = m_inputDepth * m_inputRows * m_inputPlanes; - m_otherInputStride = m_inputDepth * m_inputRows * m_inputCols * m_inputPlanes; - - m_outputPlanesRows = m_outputPlanes * m_outputRows; - - // Fast representations of different variables. - m_fastOtherStride = internal::TensorIntDivisor<Index>(m_otherStride); - - m_fastPatchStride = internal::TensorIntDivisor<Index>(m_patchStride); - m_fastColStride = internal::TensorIntDivisor<Index>(m_colStride); - m_fastRowStride = internal::TensorIntDivisor<Index>(m_rowStride); - m_fastInputRowStride = internal::TensorIntDivisor<Index>(m_row_inflate_strides); - m_fastInputColStride = internal::TensorIntDivisor<Index>(m_col_inflate_strides); - m_fastInputPlaneStride = internal::TensorIntDivisor<Index>(m_plane_inflate_strides); - m_fastInputColsEff = internal::TensorIntDivisor<Index>(m_input_cols_eff); - m_fastOutputPlanes = internal::TensorIntDivisor<Index>(m_outputPlanes); - m_fastOutputPlanesRows = internal::TensorIntDivisor<Index>(m_outputPlanesRows); - - if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) { - m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[0]); - } else { - m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[NumDims-1]); - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) { - m_impl.evalSubExprsIfNeeded(NULL); - return true; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { - m_impl.cleanup(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const - { - // Patch index corresponding to the passed in index. - const Index patchIndex = index / m_fastPatchStride; - - // Spatial offset within the patch. This has to be translated into 3D - // coordinates within the patch. - const Index patchOffset = (index - patchIndex * m_patchStride) / m_fastOutputDepth; - - // Batch, etc. - const Index otherIndex = (NumDims == 5) ? 0 : index / m_fastOtherStride; - const Index patch3DIndex = (NumDims == 5) ? patchIndex : (index - otherIndex * m_otherStride) / m_fastPatchStride; - - // Calculate column index in the input original tensor. - const Index colIndex = patch3DIndex / m_fastOutputPlanesRows; - const Index colOffset = patchOffset / m_fastColStride; - const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft; - const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0); - if (inputCol < 0 || inputCol >= m_input_cols_eff || - ((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) { - return Scalar(m_paddingValue); - } - - // Calculate row index in the original input tensor. - const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes; - const Index rowOffset = (patchOffset - colOffset * m_colStride) / m_fastRowStride; - const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop; - const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0); - if (inputRow < 0 || inputRow >= m_input_rows_eff || - ((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) { - return Scalar(m_paddingValue); - } - - // Calculate plane index in the original input tensor. - const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex)); - const Index planeOffset = patchOffset - colOffset * m_colStride - rowOffset * m_rowStride; - const Index inputPlane = planeIndex * m_plane_strides + planeOffset * m_in_plane_strides - m_planePaddingTop; - const Index origInputPlane = (m_plane_inflate_strides == 1) ? inputPlane : ((inputPlane >= 0) ? (inputPlane / m_fastInputPlaneStride) : 0); - if (inputPlane < 0 || inputPlane >= m_input_planes_eff || - ((m_plane_inflate_strides != 1) && (inputPlane != origInputPlane * m_plane_inflate_strides))) { - return Scalar(m_paddingValue); - } - - const int depth_index = static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1; - const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index]; - - const Index inputIndex = depth + - origInputRow * m_rowInputStride + - origInputCol * m_colInputStride + - origInputPlane * m_planeInputStride + - otherIndex * m_otherInputStride; - - return m_impl.coeff(inputIndex); - } - - template<int LoadMode> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const - { - EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE) - eigen_assert(index+PacketSize-1 < dimensions().TotalSize()); - - if (m_in_row_strides != 1 || m_in_col_strides != 1 || m_row_inflate_strides != 1 || m_col_inflate_strides != 1 || - m_in_plane_strides != 1 || m_plane_inflate_strides != 1) { - return packetWithPossibleZero(index); - } - - const Index indices[2] = {index, index + PacketSize - 1}; - const Index patchIndex = indices[0] / m_fastPatchStride; - if (patchIndex != indices[1] / m_fastPatchStride) { - return packetWithPossibleZero(index); - } - const Index otherIndex = (NumDims == 5) ? 0 : indices[0] / m_fastOtherStride; - eigen_assert(otherIndex == indices[1] / m_fastOtherStride); - - // Find the offset of the element wrt the location of the first element. - const Index patchOffsets[2] = {(indices[0] - patchIndex * m_patchStride) / m_fastOutputDepth, - (indices[1] - patchIndex * m_patchStride) / m_fastOutputDepth}; - - const Index patch3DIndex = (NumDims == 5) ? patchIndex : (indices[0] - otherIndex * m_otherStride) / m_fastPatchStride; - eigen_assert(patch3DIndex == (indices[1] - otherIndex * m_otherStride) / m_fastPatchStride); - - const Index colIndex = patch3DIndex / m_fastOutputPlanesRows; - const Index colOffsets[2] = { - patchOffsets[0] / m_fastColStride, - patchOffsets[1] / m_fastColStride}; - - // Calculate col indices in the original input tensor. - const Index inputCols[2] = { - colIndex * m_col_strides + colOffsets[0] - m_colPaddingLeft, - colIndex * m_col_strides + colOffsets[1] - m_colPaddingLeft}; - if (inputCols[1] < 0 || inputCols[0] >= m_inputCols) { - return internal::pset1<PacketReturnType>(Scalar(m_paddingValue)); - } - - if (inputCols[0] != inputCols[1]) { - return packetWithPossibleZero(index); - } - - const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes; - const Index rowOffsets[2] = { - (patchOffsets[0] - colOffsets[0] * m_colStride) / m_fastRowStride, - (patchOffsets[1] - colOffsets[1] * m_colStride) / m_fastRowStride}; - eigen_assert(rowOffsets[0] <= rowOffsets[1]); - // Calculate col indices in the original input tensor. - const Index inputRows[2] = { - rowIndex * m_row_strides + rowOffsets[0] - m_rowPaddingTop, - rowIndex * m_row_strides + rowOffsets[1] - m_rowPaddingTop}; - - if (inputRows[1] < 0 || inputRows[0] >= m_inputRows) { - return internal::pset1<PacketReturnType>(Scalar(m_paddingValue)); - } - - if (inputRows[0] != inputRows[1]) { - return packetWithPossibleZero(index); - } - - const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex)); - const Index planeOffsets[2] = { - patchOffsets[0] - colOffsets[0] * m_colStride - rowOffsets[0] * m_rowStride, - patchOffsets[1] - colOffsets[1] * m_colStride - rowOffsets[1] * m_rowStride}; - eigen_assert(planeOffsets[0] <= planeOffsets[1]); - const Index inputPlanes[2] = { - planeIndex * m_plane_strides + planeOffsets[0] - m_planePaddingTop, - planeIndex * m_plane_strides + planeOffsets[1] - m_planePaddingTop}; - - if (inputPlanes[1] < 0 || inputPlanes[0] >= m_inputPlanes) { - return internal::pset1<PacketReturnType>(Scalar(m_paddingValue)); - } - - if (inputPlanes[0] >= 0 && inputPlanes[1] < m_inputPlanes) { - // no padding - const int depth_index = static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1; - const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index]; - const Index inputIndex = depth + - inputRows[0] * m_rowInputStride + - inputCols[0] * m_colInputStride + - m_planeInputStride * inputPlanes[0] + - otherIndex * m_otherInputStride; - return m_impl.template packet<Unaligned>(inputIndex); - } - - return packetWithPossibleZero(index); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost - costPerCoeff(bool vectorized) const { - const double compute_cost = - 10 * TensorOpCost::DivCost<Index>() + 21 * TensorOpCost::MulCost<Index>() + - 8 * TensorOpCost::AddCost<Index>(); - return TensorOpCost(0, 0, compute_cost, vectorized, PacketSize); - } - - EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; } - - const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; } - - - Index planePaddingTop() const { return m_planePaddingTop; } - Index rowPaddingTop() const { return m_rowPaddingTop; } - Index colPaddingLeft() const { return m_colPaddingLeft; } - Index outputPlanes() const { return m_outputPlanes; } - Index outputRows() const { return m_outputRows; } - Index outputCols() const { return m_outputCols; } - Index userPlaneStride() const { return m_plane_strides; } - Index userRowStride() const { return m_row_strides; } - Index userColStride() const { return m_col_strides; } - Index userInPlaneStride() const { return m_in_plane_strides; } - Index userInRowStride() const { return m_in_row_strides; } - Index userInColStride() const { return m_in_col_strides; } - Index planeInflateStride() const { return m_plane_inflate_strides; } - Index rowInflateStride() const { return m_row_inflate_strides; } - Index colInflateStride() const { return m_col_inflate_strides; } - -#ifdef EIGEN_USE_SYCL - // binding placeholder accessors to a command group handler for SYCL - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const { - m_impl.bind(cgh); - } -#endif - protected: - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index) const - { - EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize]; - EIGEN_UNROLL_LOOP - for (int i = 0; i < PacketSize; ++i) { - values[i] = coeff(index+i); - } - PacketReturnType rslt = internal::pload<PacketReturnType>(values); - return rslt; - } - - Dimensions m_dimensions; - - // Parameters passed to the constructor. - Index m_plane_strides; - Index m_row_strides; - Index m_col_strides; - - Index m_outputPlanes; - Index m_outputRows; - Index m_outputCols; - - Index m_planePaddingTop; - Index m_rowPaddingTop; - Index m_colPaddingLeft; - - Index m_in_plane_strides; - Index m_in_row_strides; - Index m_in_col_strides; - - Index m_plane_inflate_strides; - Index m_row_inflate_strides; - Index m_col_inflate_strides; - - // Cached input size. - Index m_inputDepth; - Index m_inputPlanes; - Index m_inputRows; - Index m_inputCols; - - // Other cached variables. - Index m_outputPlanesRows; - - // Effective input/patch post-inflation size. - Index m_input_planes_eff; - Index m_input_rows_eff; - Index m_input_cols_eff; - Index m_patch_planes_eff; - Index m_patch_rows_eff; - Index m_patch_cols_eff; - - // Strides for the output tensor. - Index m_otherStride; - Index m_patchStride; - Index m_rowStride; - Index m_colStride; - - // Strides for the input tensor. - Index m_planeInputStride; - Index m_rowInputStride; - Index m_colInputStride; - Index m_otherInputStride; - - internal::TensorIntDivisor<Index> m_fastOtherStride; - internal::TensorIntDivisor<Index> m_fastPatchStride; - internal::TensorIntDivisor<Index> m_fastColStride; - internal::TensorIntDivisor<Index> m_fastRowStride; - internal::TensorIntDivisor<Index> m_fastInputPlaneStride; - internal::TensorIntDivisor<Index> m_fastInputRowStride; - internal::TensorIntDivisor<Index> m_fastInputColStride; - internal::TensorIntDivisor<Index> m_fastInputColsEff; - internal::TensorIntDivisor<Index> m_fastOutputPlanesRows; - internal::TensorIntDivisor<Index> m_fastOutputPlanes; - internal::TensorIntDivisor<Index> m_fastOutputDepth; - - Scalar m_paddingValue; - - TensorEvaluator<ArgType, Device> m_impl; - - -}; - - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/DynamicSymmetry.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/DynamicSymmetry.h deleted file mode 100644 index bc4f2025..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/DynamicSymmetry.h +++ /dev/null @@ -1,293 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSORSYMMETRY_DYNAMICSYMMETRY_H -#define EIGEN_CXX11_TENSORSYMMETRY_DYNAMICSYMMETRY_H - -namespace Eigen { - -class DynamicSGroup -{ - public: - inline explicit DynamicSGroup() : m_numIndices(1), m_elements(), m_generators(), m_globalFlags(0) { m_elements.push_back(ge(Generator(0, 0, 0))); } - inline DynamicSGroup(const DynamicSGroup& o) : m_numIndices(o.m_numIndices), m_elements(o.m_elements), m_generators(o.m_generators), m_globalFlags(o.m_globalFlags) { } - inline DynamicSGroup(DynamicSGroup&& o) : m_numIndices(o.m_numIndices), m_elements(), m_generators(o.m_generators), m_globalFlags(o.m_globalFlags) { std::swap(m_elements, o.m_elements); } - inline DynamicSGroup& operator=(const DynamicSGroup& o) { m_numIndices = o.m_numIndices; m_elements = o.m_elements; m_generators = o.m_generators; m_globalFlags = o.m_globalFlags; return *this; } - inline DynamicSGroup& operator=(DynamicSGroup&& o) { m_numIndices = o.m_numIndices; std::swap(m_elements, o.m_elements); m_generators = o.m_generators; m_globalFlags = o.m_globalFlags; return *this; } - - void add(int one, int two, int flags = 0); - - template<typename Gen_> - inline void add(Gen_) { add(Gen_::One, Gen_::Two, Gen_::Flags); } - inline void addSymmetry(int one, int two) { add(one, two, 0); } - inline void addAntiSymmetry(int one, int two) { add(one, two, NegationFlag); } - inline void addHermiticity(int one, int two) { add(one, two, ConjugationFlag); } - inline void addAntiHermiticity(int one, int two) { add(one, two, NegationFlag | ConjugationFlag); } - - template<typename Op, typename RV, typename Index, std::size_t N, typename... Args> - inline RV apply(const std::array<Index, N>& idx, RV initial, Args&&... args) const - { - eigen_assert(N >= m_numIndices && "Can only apply symmetry group to objects that have at least the required amount of indices."); - for (std::size_t i = 0; i < size(); i++) - initial = Op::run(h_permute(i, idx, typename internal::gen_numeric_list<int, N>::type()), m_elements[i].flags, initial, std::forward<Args>(args)...); - return initial; - } - - template<typename Op, typename RV, typename Index, typename... Args> - inline RV apply(const std::vector<Index>& idx, RV initial, Args&&... args) const - { - eigen_assert(idx.size() >= m_numIndices && "Can only apply symmetry group to objects that have at least the required amount of indices."); - for (std::size_t i = 0; i < size(); i++) - initial = Op::run(h_permute(i, idx), m_elements[i].flags, initial, std::forward<Args>(args)...); - return initial; - } - - inline int globalFlags() const { return m_globalFlags; } - inline std::size_t size() const { return m_elements.size(); } - - template<typename Tensor_, typename... IndexTypes> - inline internal::tensor_symmetry_value_setter<Tensor_, DynamicSGroup> operator()(Tensor_& tensor, typename Tensor_::Index firstIndex, IndexTypes... otherIndices) const - { - static_assert(sizeof...(otherIndices) + 1 == Tensor_::NumIndices, "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor."); - return operator()(tensor, std::array<typename Tensor_::Index, Tensor_::NumIndices>{{firstIndex, otherIndices...}}); - } - - template<typename Tensor_> - inline internal::tensor_symmetry_value_setter<Tensor_, DynamicSGroup> operator()(Tensor_& tensor, std::array<typename Tensor_::Index, Tensor_::NumIndices> const& indices) const - { - return internal::tensor_symmetry_value_setter<Tensor_, DynamicSGroup>(tensor, *this, indices); - } - private: - struct GroupElement { - std::vector<int> representation; - int flags; - bool isId() const - { - for (std::size_t i = 0; i < representation.size(); i++) - if (i != (size_t)representation[i]) - return false; - return true; - } - }; - struct Generator { - int one; - int two; - int flags; - constexpr inline Generator(int one_, int two_, int flags_) : one(one_), two(two_), flags(flags_) {} - }; - - std::size_t m_numIndices; - std::vector<GroupElement> m_elements; - std::vector<Generator> m_generators; - int m_globalFlags; - - template<typename Index, std::size_t N, int... n> - inline std::array<Index, N> h_permute(std::size_t which, const std::array<Index, N>& idx, internal::numeric_list<int, n...>) const - { - return std::array<Index, N>{{ idx[n >= m_numIndices ? n : m_elements[which].representation[n]]... }}; - } - - template<typename Index> - inline std::vector<Index> h_permute(std::size_t which, std::vector<Index> idx) const - { - std::vector<Index> result; - result.reserve(idx.size()); - for (auto k : m_elements[which].representation) - result.push_back(idx[k]); - for (std::size_t i = m_numIndices; i < idx.size(); i++) - result.push_back(idx[i]); - return result; - } - - inline GroupElement ge(Generator const& g) const - { - GroupElement result; - result.representation.reserve(m_numIndices); - result.flags = g.flags; - for (std::size_t k = 0; k < m_numIndices; k++) { - if (k == (std::size_t)g.one) - result.representation.push_back(g.two); - else if (k == (std::size_t)g.two) - result.representation.push_back(g.one); - else - result.representation.push_back(int(k)); - } - return result; - } - - GroupElement mul(GroupElement, GroupElement) const; - inline GroupElement mul(Generator g1, GroupElement g2) const - { - return mul(ge(g1), g2); - } - - inline GroupElement mul(GroupElement g1, Generator g2) const - { - return mul(g1, ge(g2)); - } - - inline GroupElement mul(Generator g1, Generator g2) const - { - return mul(ge(g1), ge(g2)); - } - - inline int findElement(GroupElement e) const - { - for (auto ee : m_elements) { - if (ee.representation == e.representation) - return ee.flags ^ e.flags; - } - return -1; - } - - void updateGlobalFlags(int flagDiffOfSameGenerator); -}; - -// dynamic symmetry group that auto-adds the template parameters in the constructor -template<typename... Gen> -class DynamicSGroupFromTemplateArgs : public DynamicSGroup -{ - public: - inline DynamicSGroupFromTemplateArgs() : DynamicSGroup() - { - add_all(internal::type_list<Gen...>()); - } - inline DynamicSGroupFromTemplateArgs(DynamicSGroupFromTemplateArgs const& other) : DynamicSGroup(other) { } - inline DynamicSGroupFromTemplateArgs(DynamicSGroupFromTemplateArgs&& other) : DynamicSGroup(other) { } - inline DynamicSGroupFromTemplateArgs<Gen...>& operator=(const DynamicSGroupFromTemplateArgs<Gen...>& o) { DynamicSGroup::operator=(o); return *this; } - inline DynamicSGroupFromTemplateArgs<Gen...>& operator=(DynamicSGroupFromTemplateArgs<Gen...>&& o) { DynamicSGroup::operator=(o); return *this; } - - private: - template<typename Gen1, typename... GenNext> - inline void add_all(internal::type_list<Gen1, GenNext...>) - { - add(Gen1()); - add_all(internal::type_list<GenNext...>()); - } - - inline void add_all(internal::type_list<>) - { - } -}; - -inline DynamicSGroup::GroupElement DynamicSGroup::mul(GroupElement g1, GroupElement g2) const -{ - eigen_internal_assert(g1.representation.size() == m_numIndices); - eigen_internal_assert(g2.representation.size() == m_numIndices); - - GroupElement result; - result.representation.reserve(m_numIndices); - for (std::size_t i = 0; i < m_numIndices; i++) { - int v = g2.representation[g1.representation[i]]; - eigen_assert(v >= 0); - result.representation.push_back(v); - } - result.flags = g1.flags ^ g2.flags; - return result; -} - -inline void DynamicSGroup::add(int one, int two, int flags) -{ - eigen_assert(one >= 0); - eigen_assert(two >= 0); - eigen_assert(one != two); - - if ((std::size_t)one >= m_numIndices || (std::size_t)two >= m_numIndices) { - std::size_t newNumIndices = (one > two) ? one : two + 1; - for (auto& gelem : m_elements) { - gelem.representation.reserve(newNumIndices); - for (std::size_t i = m_numIndices; i < newNumIndices; i++) - gelem.representation.push_back(i); - } - m_numIndices = newNumIndices; - } - - Generator g{one, two, flags}; - GroupElement e = ge(g); - - /* special case for first generator */ - if (m_elements.size() == 1) { - while (!e.isId()) { - m_elements.push_back(e); - e = mul(e, g); - } - - if (e.flags > 0) - updateGlobalFlags(e.flags); - - // only add in case we didn't have identity - if (m_elements.size() > 1) - m_generators.push_back(g); - return; - } - - int p = findElement(e); - if (p >= 0) { - updateGlobalFlags(p); - return; - } - - std::size_t coset_order = m_elements.size(); - m_elements.push_back(e); - for (std::size_t i = 1; i < coset_order; i++) - m_elements.push_back(mul(m_elements[i], e)); - m_generators.push_back(g); - - std::size_t coset_rep = coset_order; - do { - for (auto g : m_generators) { - e = mul(m_elements[coset_rep], g); - p = findElement(e); - if (p < 0) { - // element not yet in group - m_elements.push_back(e); - for (std::size_t i = 1; i < coset_order; i++) - m_elements.push_back(mul(m_elements[i], e)); - } else if (p > 0) { - updateGlobalFlags(p); - } - } - coset_rep += coset_order; - } while (coset_rep < m_elements.size()); -} - -inline void DynamicSGroup::updateGlobalFlags(int flagDiffOfSameGenerator) -{ - switch (flagDiffOfSameGenerator) { - case 0: - default: - // nothing happened - break; - case NegationFlag: - // every element is it's own negative => whole tensor is zero - m_globalFlags |= GlobalZeroFlag; - break; - case ConjugationFlag: - // every element is it's own conjugate => whole tensor is real - m_globalFlags |= GlobalRealFlag; - break; - case (NegationFlag | ConjugationFlag): - // every element is it's own negative conjugate => whole tensor is imaginary - m_globalFlags |= GlobalImagFlag; - break; - /* NOTE: - * since GlobalZeroFlag == GlobalRealFlag | GlobalImagFlag, if one generator - * causes the tensor to be real and the next one to be imaginary, this will - * trivially give the correct result - */ - } -} - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSORSYMMETRY_DYNAMICSYMMETRY_H - -/* - * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; - */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/StaticSymmetry.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/StaticSymmetry.h deleted file mode 100644 index 942293bd..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/StaticSymmetry.h +++ /dev/null @@ -1,236 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSORSYMMETRY_STATICSYMMETRY_H -#define EIGEN_CXX11_TENSORSYMMETRY_STATICSYMMETRY_H - -namespace Eigen { - -namespace internal { - -template<typename list> struct tensor_static_symgroup_permutate; - -template<int... nn> -struct tensor_static_symgroup_permutate<numeric_list<int, nn...>> -{ - constexpr static std::size_t N = sizeof...(nn); - - template<typename T> - constexpr static inline std::array<T, N> run(const std::array<T, N>& indices) - { - return {{indices[nn]...}}; - } -}; - -template<typename indices_, int flags_> -struct tensor_static_symgroup_element -{ - typedef indices_ indices; - constexpr static int flags = flags_; -}; - -template<typename Gen, int N> -struct tensor_static_symgroup_element_ctor -{ - typedef tensor_static_symgroup_element< - typename gen_numeric_list_swapped_pair<int, N, Gen::One, Gen::Two>::type, - Gen::Flags - > type; -}; - -template<int N> -struct tensor_static_symgroup_identity_ctor -{ - typedef tensor_static_symgroup_element< - typename gen_numeric_list<int, N>::type, - 0 - > type; -}; - -template<typename iib> -struct tensor_static_symgroup_multiply_helper -{ - template<int... iia> - constexpr static inline numeric_list<int, get<iia, iib>::value...> helper(numeric_list<int, iia...>) { - return numeric_list<int, get<iia, iib>::value...>(); - } -}; - -template<typename A, typename B> -struct tensor_static_symgroup_multiply -{ - private: - typedef typename A::indices iia; - typedef typename B::indices iib; - constexpr static int ffa = A::flags; - constexpr static int ffb = B::flags; - - public: - static_assert(iia::count == iib::count, "Cannot multiply symmetry elements with different number of indices."); - - typedef tensor_static_symgroup_element< - decltype(tensor_static_symgroup_multiply_helper<iib>::helper(iia())), - ffa ^ ffb - > type; -}; - -template<typename A, typename B> -struct tensor_static_symgroup_equality -{ - typedef typename A::indices iia; - typedef typename B::indices iib; - constexpr static int ffa = A::flags; - constexpr static int ffb = B::flags; - static_assert(iia::count == iib::count, "Cannot compare symmetry elements with different number of indices."); - - constexpr static bool value = is_same<iia, iib>::value; - - private: - /* this should be zero if they are identical, or else the tensor - * will be forced to be pure real, pure imaginary or even pure zero - */ - constexpr static int flags_cmp_ = ffa ^ ffb; - - /* either they are not equal, then we don't care whether the flags - * match, or they are equal, and then we have to check - */ - constexpr static bool is_zero = value && flags_cmp_ == NegationFlag; - constexpr static bool is_real = value && flags_cmp_ == ConjugationFlag; - constexpr static bool is_imag = value && flags_cmp_ == (NegationFlag | ConjugationFlag); - - public: - constexpr static int global_flags = - (is_real ? GlobalRealFlag : 0) | - (is_imag ? GlobalImagFlag : 0) | - (is_zero ? GlobalZeroFlag : 0); -}; - -template<std::size_t NumIndices, typename... Gen> -struct tensor_static_symgroup -{ - typedef StaticSGroup<Gen...> type; - constexpr static std::size_t size = type::static_size; -}; - -template<typename Index, std::size_t N, int... ii, int... jj> -constexpr static inline std::array<Index, N> tensor_static_symgroup_index_permute(std::array<Index, N> idx, internal::numeric_list<int, ii...>, internal::numeric_list<int, jj...>) -{ - return {{ idx[ii]..., idx[jj]... }}; -} - -template<typename Index, int... ii> -static inline std::vector<Index> tensor_static_symgroup_index_permute(std::vector<Index> idx, internal::numeric_list<int, ii...>) -{ - std::vector<Index> result{{ idx[ii]... }}; - std::size_t target_size = idx.size(); - for (std::size_t i = result.size(); i < target_size; i++) - result.push_back(idx[i]); - return result; -} - -template<typename T> struct tensor_static_symgroup_do_apply; - -template<typename first, typename... next> -struct tensor_static_symgroup_do_apply<internal::type_list<first, next...>> -{ - template<typename Op, typename RV, std::size_t SGNumIndices, typename Index, std::size_t NumIndices, typename... Args> - static inline RV run(const std::array<Index, NumIndices>& idx, RV initial, Args&&... args) - { - static_assert(NumIndices >= SGNumIndices, "Can only apply symmetry group to objects that have at least the required amount of indices."); - typedef typename internal::gen_numeric_list<int, NumIndices - SGNumIndices, SGNumIndices>::type remaining_indices; - initial = Op::run(tensor_static_symgroup_index_permute(idx, typename first::indices(), remaining_indices()), first::flags, initial, std::forward<Args>(args)...); - return tensor_static_symgroup_do_apply<internal::type_list<next...>>::template run<Op, RV, SGNumIndices>(idx, initial, args...); - } - - template<typename Op, typename RV, std::size_t SGNumIndices, typename Index, typename... Args> - static inline RV run(const std::vector<Index>& idx, RV initial, Args&&... args) - { - eigen_assert(idx.size() >= SGNumIndices && "Can only apply symmetry group to objects that have at least the required amount of indices."); - initial = Op::run(tensor_static_symgroup_index_permute(idx, typename first::indices()), first::flags, initial, std::forward<Args>(args)...); - return tensor_static_symgroup_do_apply<internal::type_list<next...>>::template run<Op, RV, SGNumIndices>(idx, initial, args...); - } -}; - -template<EIGEN_TPL_PP_SPEC_HACK_DEF(typename, empty)> -struct tensor_static_symgroup_do_apply<internal::type_list<EIGEN_TPL_PP_SPEC_HACK_USE(empty)>> -{ - template<typename Op, typename RV, std::size_t SGNumIndices, typename Index, std::size_t NumIndices, typename... Args> - static inline RV run(const std::array<Index, NumIndices>&, RV initial, Args&&...) - { - // do nothing - return initial; - } - - template<typename Op, typename RV, std::size_t SGNumIndices, typename Index, typename... Args> - static inline RV run(const std::vector<Index>&, RV initial, Args&&...) - { - // do nothing - return initial; - } -}; - -} // end namespace internal - -template<typename... Gen> -class StaticSGroup -{ - constexpr static std::size_t NumIndices = internal::tensor_symmetry_num_indices<Gen...>::value; - typedef internal::group_theory::enumerate_group_elements< - internal::tensor_static_symgroup_multiply, - internal::tensor_static_symgroup_equality, - typename internal::tensor_static_symgroup_identity_ctor<NumIndices>::type, - internal::type_list<typename internal::tensor_static_symgroup_element_ctor<Gen, NumIndices>::type...> - > group_elements; - typedef typename group_elements::type ge; - public: - constexpr inline StaticSGroup() {} - constexpr inline StaticSGroup(const StaticSGroup<Gen...>&) {} - constexpr inline StaticSGroup(StaticSGroup<Gen...>&&) {} - - template<typename Op, typename RV, typename Index, std::size_t N, typename... Args> - static inline RV apply(const std::array<Index, N>& idx, RV initial, Args&&... args) - { - return internal::tensor_static_symgroup_do_apply<ge>::template run<Op, RV, NumIndices>(idx, initial, args...); - } - - template<typename Op, typename RV, typename Index, typename... Args> - static inline RV apply(const std::vector<Index>& idx, RV initial, Args&&... args) - { - eigen_assert(idx.size() == NumIndices); - return internal::tensor_static_symgroup_do_apply<ge>::template run<Op, RV, NumIndices>(idx, initial, args...); - } - - constexpr static std::size_t static_size = ge::count; - - constexpr static inline std::size_t size() { - return ge::count; - } - constexpr static inline int globalFlags() { return group_elements::global_flags; } - - template<typename Tensor_, typename... IndexTypes> - inline internal::tensor_symmetry_value_setter<Tensor_, StaticSGroup<Gen...>> operator()(Tensor_& tensor, typename Tensor_::Index firstIndex, IndexTypes... otherIndices) const - { - static_assert(sizeof...(otherIndices) + 1 == Tensor_::NumIndices, "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor."); - return operator()(tensor, std::array<typename Tensor_::Index, Tensor_::NumIndices>{{firstIndex, otherIndices...}}); - } - - template<typename Tensor_> - inline internal::tensor_symmetry_value_setter<Tensor_, StaticSGroup<Gen...>> operator()(Tensor_& tensor, std::array<typename Tensor_::Index, Tensor_::NumIndices> const& indices) const - { - return internal::tensor_symmetry_value_setter<Tensor_, StaticSGroup<Gen...>>(tensor, *this, indices); - } -}; - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSORSYMMETRY_STATICSYMMETRY_H - -/* - * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; - */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/Symmetry.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/Symmetry.h deleted file mode 100644 index 879d6cd7..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/Symmetry.h +++ /dev/null @@ -1,338 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSORSYMMETRY_SYMMETRY_H -#define EIGEN_CXX11_TENSORSYMMETRY_SYMMETRY_H - -namespace Eigen { - -enum { - NegationFlag = 0x01, - ConjugationFlag = 0x02 -}; - -enum { - GlobalRealFlag = 0x01, - GlobalImagFlag = 0x02, - GlobalZeroFlag = 0x03 -}; - -namespace internal { - -template<std::size_t NumIndices, typename... Sym> struct tensor_symmetry_pre_analysis; -template<std::size_t NumIndices, typename... Sym> struct tensor_static_symgroup; -template<bool instantiate, std::size_t NumIndices, typename... Sym> struct tensor_static_symgroup_if; -template<typename Tensor_> struct tensor_symmetry_calculate_flags; -template<typename Tensor_> struct tensor_symmetry_assign_value; -template<typename... Sym> struct tensor_symmetry_num_indices; - -} // end namespace internal - -template<int One_, int Two_> -struct Symmetry -{ - static_assert(One_ != Two_, "Symmetries must cover distinct indices."); - constexpr static int One = One_; - constexpr static int Two = Two_; - constexpr static int Flags = 0; -}; - -template<int One_, int Two_> -struct AntiSymmetry -{ - static_assert(One_ != Two_, "Symmetries must cover distinct indices."); - constexpr static int One = One_; - constexpr static int Two = Two_; - constexpr static int Flags = NegationFlag; -}; - -template<int One_, int Two_> -struct Hermiticity -{ - static_assert(One_ != Two_, "Symmetries must cover distinct indices."); - constexpr static int One = One_; - constexpr static int Two = Two_; - constexpr static int Flags = ConjugationFlag; -}; - -template<int One_, int Two_> -struct AntiHermiticity -{ - static_assert(One_ != Two_, "Symmetries must cover distinct indices."); - constexpr static int One = One_; - constexpr static int Two = Two_; - constexpr static int Flags = ConjugationFlag | NegationFlag; -}; - -/** \class DynamicSGroup - * \ingroup TensorSymmetry_Module - * - * \brief Dynamic symmetry group - * - * The %DynamicSGroup class represents a symmetry group that need not be known at - * compile time. It is useful if one wants to support arbitrary run-time defineable - * symmetries for tensors, but it is also instantiated if a symmetry group is defined - * at compile time that would be either too large for the compiler to reasonably - * generate (using templates to calculate this at compile time is very inefficient) - * or that the compiler could generate the group but that it wouldn't make sense to - * unroll the loop for setting coefficients anymore. - */ -class DynamicSGroup; - -/** \internal - * - * \class DynamicSGroupFromTemplateArgs - * \ingroup TensorSymmetry_Module - * - * \brief Dynamic symmetry group, initialized from template arguments - * - * This class is a child class of DynamicSGroup. It uses the template arguments - * specified to initialize itself. - */ -template<typename... Gen> -class DynamicSGroupFromTemplateArgs; - -/** \class StaticSGroup - * \ingroup TensorSymmetry_Module - * - * \brief Static symmetry group - * - * This class represents a symmetry group that is known and resolved completely - * at compile time. Ideally, no run-time penalty is incurred compared to the - * manual unrolling of the symmetry. - * - * <b><i>CAUTION:</i></b> - * - * Do not use this class directly for large symmetry groups. The compiler - * may run into a limit, or segfault or in the very least will take a very, - * very, very long time to compile the code. Use the SGroup class instead - * if you want a static group. That class contains logic that will - * automatically select the DynamicSGroup class instead if the symmetry - * group becomes too large. (In that case, unrolling may not even be - * beneficial.) - */ -template<typename... Gen> -class StaticSGroup; - -/** \class SGroup - * \ingroup TensorSymmetry_Module - * - * \brief Symmetry group, initialized from template arguments - * - * This class represents a symmetry group whose generators are already - * known at compile time. It may or may not be resolved at compile time, - * depending on the estimated size of the group. - * - * \sa StaticSGroup - * \sa DynamicSGroup - */ -template<typename... Gen> -class SGroup : public internal::tensor_symmetry_pre_analysis<internal::tensor_symmetry_num_indices<Gen...>::value, Gen...>::root_type -{ - public: - constexpr static std::size_t NumIndices = internal::tensor_symmetry_num_indices<Gen...>::value; - typedef typename internal::tensor_symmetry_pre_analysis<NumIndices, Gen...>::root_type Base; - - // make standard constructors + assignment operators public - inline SGroup() : Base() { } - inline SGroup(const SGroup<Gen...>& other) : Base(other) { } - inline SGroup(SGroup<Gen...>&& other) : Base(other) { } - inline SGroup<Gen...>& operator=(const SGroup<Gen...>& other) { Base::operator=(other); return *this; } - inline SGroup<Gen...>& operator=(SGroup<Gen...>&& other) { Base::operator=(other); return *this; } - - // all else is defined in the base class -}; - -namespace internal { - -template<typename... Sym> struct tensor_symmetry_num_indices -{ - constexpr static std::size_t value = 1; -}; - -template<int One_, int Two_, typename... Sym> struct tensor_symmetry_num_indices<Symmetry<One_, Two_>, Sym...> -{ -private: - constexpr static std::size_t One = static_cast<std::size_t>(One_); - constexpr static std::size_t Two = static_cast<std::size_t>(Two_); - constexpr static std::size_t Three = tensor_symmetry_num_indices<Sym...>::value; - - // don't use std::max, since it's not constexpr until C++14... - constexpr static std::size_t maxOneTwoPlusOne = ((One > Two) ? One : Two) + 1; -public: - constexpr static std::size_t value = (maxOneTwoPlusOne > Three) ? maxOneTwoPlusOne : Three; -}; - -template<int One_, int Two_, typename... Sym> struct tensor_symmetry_num_indices<AntiSymmetry<One_, Two_>, Sym...> - : public tensor_symmetry_num_indices<Symmetry<One_, Two_>, Sym...> {}; -template<int One_, int Two_, typename... Sym> struct tensor_symmetry_num_indices<Hermiticity<One_, Two_>, Sym...> - : public tensor_symmetry_num_indices<Symmetry<One_, Two_>, Sym...> {}; -template<int One_, int Two_, typename... Sym> struct tensor_symmetry_num_indices<AntiHermiticity<One_, Two_>, Sym...> - : public tensor_symmetry_num_indices<Symmetry<One_, Two_>, Sym...> {}; - -/** \internal - * - * \class tensor_symmetry_pre_analysis - * \ingroup TensorSymmetry_Module - * - * \brief Pre-select whether to use a static or dynamic symmetry group - * - * When a symmetry group could in principle be determined at compile time, - * this template implements the logic whether to actually do that or whether - * to rather defer that to runtime. - * - * The logic is as follows: - * <dl> - * <dt><b>No generators (trivial symmetry):</b></dt> - * <dd>Use a trivial static group. Ideally, this has no performance impact - * compared to not using symmetry at all. In practice, this might not - * be the case.</dd> - * <dt><b>More than 4 generators:</b></dt> - * <dd>Calculate the group at run time, it is likely far too large for the - * compiler to be able to properly generate it in a realistic time.</dd> - * <dt><b>Up to and including 4 generators:</b></dt> - * <dd>Actually enumerate all group elements, but then check how many there - * are. If there are more than 16, it is unlikely that unrolling the - * loop (as is done in the static compile-time case) is sensible, so - * use a dynamic group instead. If there are at most 16 elements, actually - * use that static group. Note that the largest group with 4 generators - * still compiles with reasonable resources.</dd> - * </dl> - * - * Note: Example compile time performance with g++-4.6 on an Intenl Core i5-3470 - * with 16 GiB RAM (all generators non-redundant and the subgroups don't - * factorize): - * - * # Generators -O0 -ggdb -O2 - * ------------------------------------------------------------------- - * 1 0.5 s / 250 MiB 0.45s / 230 MiB - * 2 0.5 s / 260 MiB 0.5 s / 250 MiB - * 3 0.65s / 310 MiB 0.62s / 310 MiB - * 4 2.2 s / 860 MiB 1.7 s / 770 MiB - * 5 130 s / 13000 MiB 120 s / 11000 MiB - * - * It is clear that everything is still very efficient up to 4 generators, then - * the memory and CPU requirements become unreasonable. Thus we only instantiate - * the template group theory logic if the number of generators supplied is 4 or - * lower, otherwise this will be forced to be done during runtime, where the - * algorithm is reasonably fast. - */ -template<std::size_t NumIndices> -struct tensor_symmetry_pre_analysis<NumIndices> -{ - typedef StaticSGroup<> root_type; -}; - -template<std::size_t NumIndices, typename Gen_, typename... Gens_> -struct tensor_symmetry_pre_analysis<NumIndices, Gen_, Gens_...> -{ - constexpr static std::size_t max_static_generators = 4; - constexpr static std::size_t max_static_elements = 16; - typedef tensor_static_symgroup_if<(sizeof...(Gens_) + 1 <= max_static_generators), NumIndices, Gen_, Gens_...> helper; - constexpr static std::size_t possible_size = helper::size; - - typedef typename conditional< - possible_size == 0 || possible_size >= max_static_elements, - DynamicSGroupFromTemplateArgs<Gen_, Gens_...>, - typename helper::type - >::type root_type; -}; - -template<bool instantiate, std::size_t NumIndices, typename... Gens> -struct tensor_static_symgroup_if -{ - constexpr static std::size_t size = 0; - typedef void type; -}; - -template<std::size_t NumIndices, typename... Gens> -struct tensor_static_symgroup_if<true, NumIndices, Gens...> : tensor_static_symgroup<NumIndices, Gens...> {}; - -template<typename Tensor_> -struct tensor_symmetry_assign_value -{ - typedef typename Tensor_::Index Index; - typedef typename Tensor_::Scalar Scalar; - constexpr static std::size_t NumIndices = Tensor_::NumIndices; - - static inline int run(const std::array<Index, NumIndices>& transformed_indices, int transformation_flags, int dummy, Tensor_& tensor, const Scalar& value_) - { - Scalar value(value_); - if (transformation_flags & ConjugationFlag) - value = numext::conj(value); - if (transformation_flags & NegationFlag) - value = -value; - tensor.coeffRef(transformed_indices) = value; - return dummy; - } -}; - -template<typename Tensor_> -struct tensor_symmetry_calculate_flags -{ - typedef typename Tensor_::Index Index; - constexpr static std::size_t NumIndices = Tensor_::NumIndices; - - static inline int run(const std::array<Index, NumIndices>& transformed_indices, int transform_flags, int current_flags, const std::array<Index, NumIndices>& orig_indices) - { - if (transformed_indices == orig_indices) { - if (transform_flags & (ConjugationFlag | NegationFlag)) - return current_flags | GlobalImagFlag; // anti-hermitian diagonal - else if (transform_flags & ConjugationFlag) - return current_flags | GlobalRealFlag; // hermitian diagonal - else if (transform_flags & NegationFlag) - return current_flags | GlobalZeroFlag; // anti-symmetric diagonal - } - return current_flags; - } -}; - -template<typename Tensor_, typename Symmetry_, int Flags = 0> -class tensor_symmetry_value_setter -{ - public: - typedef typename Tensor_::Index Index; - typedef typename Tensor_::Scalar Scalar; - constexpr static std::size_t NumIndices = Tensor_::NumIndices; - - inline tensor_symmetry_value_setter(Tensor_& tensor, Symmetry_ const& symmetry, std::array<Index, NumIndices> const& indices) - : m_tensor(tensor), m_symmetry(symmetry), m_indices(indices) { } - - inline tensor_symmetry_value_setter<Tensor_, Symmetry_, Flags>& operator=(Scalar const& value) - { - doAssign(value); - return *this; - } - private: - Tensor_& m_tensor; - Symmetry_ m_symmetry; - std::array<Index, NumIndices> m_indices; - - inline void doAssign(Scalar const& value) - { - #ifdef EIGEN_TENSOR_SYMMETRY_CHECK_VALUES - int value_flags = m_symmetry.template apply<internal::tensor_symmetry_calculate_flags<Tensor_>, int>(m_indices, m_symmetry.globalFlags(), m_indices); - if (value_flags & GlobalRealFlag) - eigen_assert(numext::imag(value) == 0); - if (value_flags & GlobalImagFlag) - eigen_assert(numext::real(value) == 0); - #endif - m_symmetry.template apply<internal::tensor_symmetry_assign_value<Tensor_>, int>(m_indices, 0, m_tensor, value); - } -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSORSYMMETRY_SYMMETRY_H - -/* - * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; - */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/util/TemplateGroupTheory.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/util/TemplateGroupTheory.h deleted file mode 100644 index 54bf9dbb..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/TensorSymmetry/util/TemplateGroupTheory.h +++ /dev/null @@ -1,669 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_TENSORSYMMETRY_TEMPLATEGROUPTHEORY_H -#define EIGEN_CXX11_TENSORSYMMETRY_TEMPLATEGROUPTHEORY_H - -namespace Eigen { - -namespace internal { - -namespace group_theory { - -/** \internal - * \file CXX11/src/TensorSymmetry/util/TemplateGroupTheory.h - * This file contains C++ templates that implement group theory algorithms. - * - * The algorithms allow for a compile-time analysis of finite groups. - * - * Currently only Dimino's algorithm is implemented, which returns a list - * of all elements in a group given a set of (possibly redundant) generators. - * (One could also do that with the so-called orbital algorithm, but that - * is much more expensive and usually has no advantages.) - */ - -/********************************************************************** - * "Ok kid, here is where it gets complicated." - * - Amelia Pond in the "Doctor Who" episode - * "The Big Bang" - * - * Dimino's algorithm - * ================== - * - * The following is Dimino's algorithm in sequential form: - * - * Input: identity element, list of generators, equality check, - * multiplication operation - * Output: list of group elements - * - * 1. add identity element - * 2. remove identities from list of generators - * 3. add all powers of first generator that aren't the - * identity element - * 4. go through all remaining generators: - * a. if generator is already in the list of elements - * -> do nothing - * b. otherwise - * i. remember current # of elements - * (i.e. the size of the current subgroup) - * ii. add all current elements (which includes - * the identity) each multiplied from right - * with the current generator to the group - * iii. add all remaining cosets that are generated - * by products of the new generator with itself - * and all other generators seen so far - * - * In functional form, this is implemented as a long set of recursive - * templates that have a complicated relationship. - * - * The main interface for Dimino's algorithm is the template - * enumerate_group_elements. All lists are implemented as variadic - * type_list<typename...> and numeric_list<typename = int, int...> - * templates. - * - * 'Calling' templates is usually done via typedefs. - * - * This algorithm is an extended version of the basic version. The - * extension consists in the fact that each group element has a set - * of flags associated with it. Multiplication of two group elements - * with each other results in a group element whose flags are the - * XOR of the flags of the previous elements. Each time the algorithm - * notices that a group element it just calculated is already in the - * list of current elements, the flags of both will be compared and - * added to the so-called 'global flags' of the group. - * - * The rationale behind this extension is that this allows not only - * for the description of symmetries between tensor indices, but - * also allows for the description of hermiticity, antisymmetry and - * antihermiticity. Negation and conjugation each are specific bit - * in the flags value and if two different ways to reach a group - * element lead to two different flags, this poses a constraint on - * the allowed values of the resulting tensor. For example, if a - * group element is reach both with and without the conjugation - * flags, it is clear that the resulting tensor has to be real. - * - * Note that this flag mechanism is quite generic and may have other - * uses beyond tensor properties. - * - * IMPORTANT: - * This algorithm assumes the group to be finite. If you try to - * run it with a group that's infinite, the algorithm will only - * terminate once you hit a compiler limit (max template depth). - * Also note that trying to use this implementation to create a - * very large group will probably either make you hit the same - * limit, cause the compiler to segfault or at the very least - * take a *really* long time (hours, days, weeks - sic!) to - * compile. It is not recommended to plug in more than 4 - * generators, unless they are independent of each other. - */ - -/** \internal - * - * \class strip_identities - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Cleanse a list of group elements of the identity element - * - * This template is used to make a first pass through all initial - * generators of Dimino's algorithm and remove the identity - * elements. - * - * \sa enumerate_group_elements - */ -template<template<typename, typename> class Equality, typename id, typename L> struct strip_identities; - -template< - template<typename, typename> class Equality, - typename id, - typename t, - typename... ts -> -struct strip_identities<Equality, id, type_list<t, ts...>> -{ - typedef typename conditional< - Equality<id, t>::value, - typename strip_identities<Equality, id, type_list<ts...>>::type, - typename concat<type_list<t>, typename strip_identities<Equality, id, type_list<ts...>>::type>::type - >::type type; - constexpr static int global_flags = Equality<id, t>::global_flags | strip_identities<Equality, id, type_list<ts...>>::global_flags; -}; - -template< - template<typename, typename> class Equality, - typename id - EIGEN_TPL_PP_SPEC_HACK_DEFC(typename, ts) -> -struct strip_identities<Equality, id, type_list<EIGEN_TPL_PP_SPEC_HACK_USE(ts)>> -{ - typedef type_list<> type; - constexpr static int global_flags = 0; -}; - -/** \internal - * - * \class dimino_first_step_elements_helper - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Recursive template that adds powers of the first generator to the list of group elements - * - * This template calls itself recursively to add powers of the first - * generator to the list of group elements. It stops if it reaches - * the identity element again. - * - * \sa enumerate_group_elements, dimino_first_step_elements - */ -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename g, - typename current_element, - typename elements, - bool dont_add_current_element // = false -> -struct dimino_first_step_elements_helper -#ifndef EIGEN_PARSED_BY_DOXYGEN - : // recursive inheritance is too difficult for Doxygen - public dimino_first_step_elements_helper< - Multiply, - Equality, - id, - g, - typename Multiply<current_element, g>::type, - typename concat<elements, type_list<current_element>>::type, - Equality<typename Multiply<current_element, g>::type, id>::value - > {}; - -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename g, - typename current_element, - typename elements -> -struct dimino_first_step_elements_helper<Multiply, Equality, id, g, current_element, elements, true> -#endif // EIGEN_PARSED_BY_DOXYGEN -{ - typedef elements type; - constexpr static int global_flags = Equality<current_element, id>::global_flags; -}; - -/** \internal - * - * \class dimino_first_step_elements - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Add all powers of the first generator to the list of group elements - * - * This template takes the first non-identity generator and generates the initial - * list of elements which consists of all powers of that generator. For a group - * with just one generated, it would be enumerated after this. - * - * \sa enumerate_group_elements - */ -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename generators -> -struct dimino_first_step_elements -{ - typedef typename get<0, generators>::type first_generator; - typedef typename skip<1, generators>::type next_generators; - typedef type_list<first_generator> generators_done; - - typedef dimino_first_step_elements_helper< - Multiply, - Equality, - id, - first_generator, - first_generator, - type_list<id>, - false - > helper; - typedef typename helper::type type; - constexpr static int global_flags = helper::global_flags; -}; - -/** \internal - * - * \class dimino_get_coset_elements - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Generate all elements of a specific coset - * - * This template generates all the elements of a specific coset by - * multiplying all elements in the given subgroup with the new - * coset representative. Note that the first element of the - * subgroup is always the identity element, so the first element of - * the result of this template is going to be the coset - * representative itself. - * - * Note that this template accepts an additional boolean parameter - * that specifies whether to actually generate the coset (true) or - * just return an empty list (false). - * - * \sa enumerate_group_elements, dimino_add_cosets_for_rep - */ -template< - template<typename, typename> class Multiply, - typename sub_group_elements, - typename new_coset_rep, - bool generate_coset // = true -> -struct dimino_get_coset_elements -{ - typedef typename apply_op_from_right<Multiply, new_coset_rep, sub_group_elements>::type type; -}; - -template< - template<typename, typename> class Multiply, - typename sub_group_elements, - typename new_coset_rep -> -struct dimino_get_coset_elements<Multiply, sub_group_elements, new_coset_rep, false> -{ - typedef type_list<> type; -}; - -/** \internal - * - * \class dimino_add_cosets_for_rep - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Recursive template for adding coset spaces - * - * This template multiplies the coset representative with a generator - * from the list of previous generators. If the new element is not in - * the group already, it adds the corresponding coset. Finally it - * proceeds to call itself with the next generator from the list. - * - * \sa enumerate_group_elements, dimino_add_all_coset_spaces - */ -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename sub_group_elements, - typename elements, - typename generators, - typename rep_element, - int sub_group_size -> -struct dimino_add_cosets_for_rep; - -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename sub_group_elements, - typename elements, - typename g, - typename... gs, - typename rep_element, - int sub_group_size -> -struct dimino_add_cosets_for_rep<Multiply, Equality, id, sub_group_elements, elements, type_list<g, gs...>, rep_element, sub_group_size> -{ - typedef typename Multiply<rep_element, g>::type new_coset_rep; - typedef contained_in_list_gf<Equality, new_coset_rep, elements> _cil; - constexpr static bool add_coset = !_cil::value; - - typedef typename dimino_get_coset_elements< - Multiply, - sub_group_elements, - new_coset_rep, - add_coset - >::type coset_elements; - - typedef dimino_add_cosets_for_rep< - Multiply, - Equality, - id, - sub_group_elements, - typename concat<elements, coset_elements>::type, - type_list<gs...>, - rep_element, - sub_group_size - > _helper; - - typedef typename _helper::type type; - constexpr static int global_flags = _cil::global_flags | _helper::global_flags; - - /* Note that we don't have to update global flags here, since - * we will only add these elements if they are not part of - * the group already. But that only happens if the coset rep - * is not already in the group, so the check for the coset rep - * will catch this. - */ -}; - -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename sub_group_elements, - typename elements - EIGEN_TPL_PP_SPEC_HACK_DEFC(typename, empty), - typename rep_element, - int sub_group_size -> -struct dimino_add_cosets_for_rep<Multiply, Equality, id, sub_group_elements, elements, type_list<EIGEN_TPL_PP_SPEC_HACK_USE(empty)>, rep_element, sub_group_size> -{ - typedef elements type; - constexpr static int global_flags = 0; -}; - -/** \internal - * - * \class dimino_add_all_coset_spaces - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Recursive template for adding all coset spaces for a new generator - * - * This template tries to go through the list of generators (with - * the help of the dimino_add_cosets_for_rep template) as long as - * it still finds elements that are not part of the group and add - * the corresponding cosets. - * - * \sa enumerate_group_elements, dimino_add_cosets_for_rep - */ -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename sub_group_elements, - typename elements, - typename generators, - int sub_group_size, - int rep_pos, - bool stop_condition // = false -> -struct dimino_add_all_coset_spaces -{ - typedef typename get<rep_pos, elements>::type rep_element; - typedef dimino_add_cosets_for_rep< - Multiply, - Equality, - id, - sub_group_elements, - elements, - generators, - rep_element, - sub_group_elements::count - > _ac4r; - typedef typename _ac4r::type new_elements; - - constexpr static int new_rep_pos = rep_pos + sub_group_elements::count; - constexpr static bool new_stop_condition = new_rep_pos >= new_elements::count; - - typedef dimino_add_all_coset_spaces< - Multiply, - Equality, - id, - sub_group_elements, - new_elements, - generators, - sub_group_size, - new_rep_pos, - new_stop_condition - > _helper; - - typedef typename _helper::type type; - constexpr static int global_flags = _helper::global_flags | _ac4r::global_flags; -}; - -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename sub_group_elements, - typename elements, - typename generators, - int sub_group_size, - int rep_pos -> -struct dimino_add_all_coset_spaces<Multiply, Equality, id, sub_group_elements, elements, generators, sub_group_size, rep_pos, true> -{ - typedef elements type; - constexpr static int global_flags = 0; -}; - -/** \internal - * - * \class dimino_add_generator - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Enlarge the group by adding a new generator. - * - * It accepts a boolean parameter that determines if the generator is redundant, - * i.e. was already seen in the group. In that case, it reduces to a no-op. - * - * \sa enumerate_group_elements, dimino_add_all_coset_spaces - */ -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename elements, - typename generators_done, - typename current_generator, - bool redundant // = false -> -struct dimino_add_generator -{ - /* this template is only called if the generator is not redundant - * => all elements of the group multiplied with the new generator - * are going to be new elements of the most trivial coset space - */ - typedef typename apply_op_from_right<Multiply, current_generator, elements>::type multiplied_elements; - typedef typename concat<elements, multiplied_elements>::type new_elements; - - constexpr static int rep_pos = elements::count; - - typedef dimino_add_all_coset_spaces< - Multiply, - Equality, - id, - elements, // elements of previous subgroup - new_elements, - typename concat<generators_done, type_list<current_generator>>::type, - elements::count, // size of previous subgroup - rep_pos, - false // don't stop (because rep_pos >= new_elements::count is always false at this point) - > _helper; - typedef typename _helper::type type; - constexpr static int global_flags = _helper::global_flags; -}; - -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename elements, - typename generators_done, - typename current_generator -> -struct dimino_add_generator<Multiply, Equality, id, elements, generators_done, current_generator, true> -{ - // redundant case - typedef elements type; - constexpr static int global_flags = 0; -}; - -/** \internal - * - * \class dimino_add_remaining_generators - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Recursive template that adds all remaining generators to a group - * - * Loop through the list of generators that remain and successively - * add them to the group. - * - * \sa enumerate_group_elements, dimino_add_generator - */ -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename generators_done, - typename remaining_generators, - typename elements -> -struct dimino_add_remaining_generators -{ - typedef typename get<0, remaining_generators>::type first_generator; - typedef typename skip<1, remaining_generators>::type next_generators; - - typedef contained_in_list_gf<Equality, first_generator, elements> _cil; - - typedef dimino_add_generator< - Multiply, - Equality, - id, - elements, - generators_done, - first_generator, - _cil::value - > _helper; - - typedef typename _helper::type new_elements; - - typedef dimino_add_remaining_generators< - Multiply, - Equality, - id, - typename concat<generators_done, type_list<first_generator>>::type, - next_generators, - new_elements - > _next_iter; - - typedef typename _next_iter::type type; - constexpr static int global_flags = - _cil::global_flags | - _helper::global_flags | - _next_iter::global_flags; -}; - -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename generators_done, - typename elements -> -struct dimino_add_remaining_generators<Multiply, Equality, id, generators_done, type_list<>, elements> -{ - typedef elements type; - constexpr static int global_flags = 0; -}; - -/** \internal - * - * \class enumerate_group_elements_noid - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Helper template that implements group element enumeration - * - * This is a helper template that implements the actual enumeration - * of group elements. This has been split so that the list of - * generators can be cleansed of the identity element before - * performing the actual operation. - * - * \sa enumerate_group_elements - */ -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename generators, - int initial_global_flags = 0 -> -struct enumerate_group_elements_noid -{ - typedef dimino_first_step_elements<Multiply, Equality, id, generators> first_step; - typedef typename first_step::type first_step_elements; - - typedef dimino_add_remaining_generators< - Multiply, - Equality, - id, - typename first_step::generators_done, - typename first_step::next_generators, // remaining_generators - typename first_step::type // first_step elements - > _helper; - - typedef typename _helper::type type; - constexpr static int global_flags = - initial_global_flags | - first_step::global_flags | - _helper::global_flags; -}; - -// in case when no generators are specified -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - int initial_global_flags -> -struct enumerate_group_elements_noid<Multiply, Equality, id, type_list<>, initial_global_flags> -{ - typedef type_list<id> type; - constexpr static int global_flags = initial_global_flags; -}; - -/** \internal - * - * \class enumerate_group_elements - * \ingroup CXX11_TensorSymmetry_Module - * - * \brief Enumerate all elements in a finite group - * - * This template enumerates all elements in a finite group. It accepts - * the following template parameters: - * - * \tparam Multiply The multiplication operation that multiplies two group elements - * with each other. - * \tparam Equality The equality check operation that checks if two group elements - * are equal to another. - * \tparam id The identity element - * \tparam _generators A list of (possibly redundant) generators of the group - */ -template< - template<typename, typename> class Multiply, - template<typename, typename> class Equality, - typename id, - typename _generators -> -struct enumerate_group_elements - : public enumerate_group_elements_noid< - Multiply, - Equality, - id, - typename strip_identities<Equality, id, _generators>::type, - strip_identities<Equality, id, _generators>::global_flags - > -{ -}; - -} // end namespace group_theory - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CXX11_TENSORSYMMETRY_TEMPLATEGROUPTHEORY_H - -/* - * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; - */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/Barrier.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/Barrier.h deleted file mode 100644 index e4c59dc3..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/Barrier.h +++ /dev/null @@ -1,67 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2018 Rasmus Munk Larsen <rmlarsen@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// Barrier is an object that allows one or more threads to wait until -// Notify has been called a specified number of times. - -#ifndef EIGEN_CXX11_THREADPOOL_BARRIER_H -#define EIGEN_CXX11_THREADPOOL_BARRIER_H - -namespace Eigen { - -class Barrier { - public: - Barrier(unsigned int count) : state_(count << 1), notified_(false) { - eigen_plain_assert(((count << 1) >> 1) == count); - } - ~Barrier() { eigen_plain_assert((state_ >> 1) == 0); } - - void Notify() { - unsigned int v = state_.fetch_sub(2, std::memory_order_acq_rel) - 2; - if (v != 1) { - // Clear the lowest bit (waiter flag) and check that the original state - // value was not zero. If it was zero, it means that notify was called - // more times than the original count. - eigen_plain_assert(((v + 2) & ~1) != 0); - return; // either count has not dropped to 0, or waiter is not waiting - } - std::unique_lock<std::mutex> l(mu_); - eigen_plain_assert(!notified_); - notified_ = true; - cv_.notify_all(); - } - - void Wait() { - unsigned int v = state_.fetch_or(1, std::memory_order_acq_rel); - if ((v >> 1) == 0) return; - std::unique_lock<std::mutex> l(mu_); - while (!notified_) { - cv_.wait(l); - } - } - - private: - std::mutex mu_; - std::condition_variable cv_; - std::atomic<unsigned int> state_; // low bit is waiter flag - bool notified_; -}; - -// Notification is an object that allows a user to to wait for another -// thread to signal a notification that an event has occurred. -// -// Multiple threads can wait on the same Notification object, -// but only one caller must call Notify() on the object. -struct Notification : Barrier { - Notification() : Barrier(1){}; -}; - -} // namespace Eigen - -#endif // EIGEN_CXX11_THREADPOOL_BARRIER_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/EventCount.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/EventCount.h deleted file mode 100644 index 4549aa06..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/EventCount.h +++ /dev/null @@ -1,249 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Dmitry Vyukov <dvyukov@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_EVENTCOUNT_H_ -#define EIGEN_CXX11_THREADPOOL_EVENTCOUNT_H_ - -namespace Eigen { - -// EventCount allows to wait for arbitrary predicates in non-blocking -// algorithms. Think of condition variable, but wait predicate does not need to -// be protected by a mutex. Usage: -// Waiting thread does: -// -// if (predicate) -// return act(); -// EventCount::Waiter& w = waiters[my_index]; -// ec.Prewait(&w); -// if (predicate) { -// ec.CancelWait(&w); -// return act(); -// } -// ec.CommitWait(&w); -// -// Notifying thread does: -// -// predicate = true; -// ec.Notify(true); -// -// Notify is cheap if there are no waiting threads. Prewait/CommitWait are not -// cheap, but they are executed only if the preceding predicate check has -// failed. -// -// Algorithm outline: -// There are two main variables: predicate (managed by user) and state_. -// Operation closely resembles Dekker mutual algorithm: -// https://en.wikipedia.org/wiki/Dekker%27s_algorithm -// Waiting thread sets state_ then checks predicate, Notifying thread sets -// predicate then checks state_. Due to seq_cst fences in between these -// operations it is guaranteed than either waiter will see predicate change -// and won't block, or notifying thread will see state_ change and will unblock -// the waiter, or both. But it can't happen that both threads don't see each -// other changes, which would lead to deadlock. -class EventCount { - public: - class Waiter; - - EventCount(MaxSizeVector<Waiter>& waiters) - : state_(kStackMask), waiters_(waiters) { - eigen_plain_assert(waiters.size() < (1 << kWaiterBits) - 1); - } - - ~EventCount() { - // Ensure there are no waiters. - eigen_plain_assert(state_.load() == kStackMask); - } - - // Prewait prepares for waiting. - // After calling Prewait, the thread must re-check the wait predicate - // and then call either CancelWait or CommitWait. - void Prewait() { - uint64_t state = state_.load(std::memory_order_relaxed); - for (;;) { - CheckState(state); - uint64_t newstate = state + kWaiterInc; - CheckState(newstate); - if (state_.compare_exchange_weak(state, newstate, - std::memory_order_seq_cst)) - return; - } - } - - // CommitWait commits waiting after Prewait. - void CommitWait(Waiter* w) { - eigen_plain_assert((w->epoch & ~kEpochMask) == 0); - w->state = Waiter::kNotSignaled; - const uint64_t me = (w - &waiters_[0]) | w->epoch; - uint64_t state = state_.load(std::memory_order_seq_cst); - for (;;) { - CheckState(state, true); - uint64_t newstate; - if ((state & kSignalMask) != 0) { - // Consume the signal and return immidiately. - newstate = state - kWaiterInc - kSignalInc; - } else { - // Remove this thread from pre-wait counter and add to the waiter stack. - newstate = ((state & kWaiterMask) - kWaiterInc) | me; - w->next.store(state & (kStackMask | kEpochMask), - std::memory_order_relaxed); - } - CheckState(newstate); - if (state_.compare_exchange_weak(state, newstate, - std::memory_order_acq_rel)) { - if ((state & kSignalMask) == 0) { - w->epoch += kEpochInc; - Park(w); - } - return; - } - } - } - - // CancelWait cancels effects of the previous Prewait call. - void CancelWait() { - uint64_t state = state_.load(std::memory_order_relaxed); - for (;;) { - CheckState(state, true); - uint64_t newstate = state - kWaiterInc; - // We don't know if the thread was also notified or not, - // so we should not consume a signal unconditionaly. - // Only if number of waiters is equal to number of signals, - // we know that the thread was notified and we must take away the signal. - if (((state & kWaiterMask) >> kWaiterShift) == - ((state & kSignalMask) >> kSignalShift)) - newstate -= kSignalInc; - CheckState(newstate); - if (state_.compare_exchange_weak(state, newstate, - std::memory_order_acq_rel)) - return; - } - } - - // Notify wakes one or all waiting threads. - // Must be called after changing the associated wait predicate. - void Notify(bool notifyAll) { - std::atomic_thread_fence(std::memory_order_seq_cst); - uint64_t state = state_.load(std::memory_order_acquire); - for (;;) { - CheckState(state); - const uint64_t waiters = (state & kWaiterMask) >> kWaiterShift; - const uint64_t signals = (state & kSignalMask) >> kSignalShift; - // Easy case: no waiters. - if ((state & kStackMask) == kStackMask && waiters == signals) return; - uint64_t newstate; - if (notifyAll) { - // Empty wait stack and set signal to number of pre-wait threads. - newstate = - (state & kWaiterMask) | (waiters << kSignalShift) | kStackMask; - } else if (signals < waiters) { - // There is a thread in pre-wait state, unblock it. - newstate = state + kSignalInc; - } else { - // Pop a waiter from list and unpark it. - Waiter* w = &waiters_[state & kStackMask]; - uint64_t next = w->next.load(std::memory_order_relaxed); - newstate = (state & (kWaiterMask | kSignalMask)) | next; - } - CheckState(newstate); - if (state_.compare_exchange_weak(state, newstate, - std::memory_order_acq_rel)) { - if (!notifyAll && (signals < waiters)) - return; // unblocked pre-wait thread - if ((state & kStackMask) == kStackMask) return; - Waiter* w = &waiters_[state & kStackMask]; - if (!notifyAll) w->next.store(kStackMask, std::memory_order_relaxed); - Unpark(w); - return; - } - } - } - - class Waiter { - friend class EventCount; - // Align to 128 byte boundary to prevent false sharing with other Waiter - // objects in the same vector. - EIGEN_ALIGN_TO_BOUNDARY(128) std::atomic<uint64_t> next; - std::mutex mu; - std::condition_variable cv; - uint64_t epoch = 0; - unsigned state = kNotSignaled; - enum { - kNotSignaled, - kWaiting, - kSignaled, - }; - }; - - private: - // State_ layout: - // - low kWaiterBits is a stack of waiters committed wait - // (indexes in waiters_ array are used as stack elements, - // kStackMask means empty stack). - // - next kWaiterBits is count of waiters in prewait state. - // - next kWaiterBits is count of pending signals. - // - remaining bits are ABA counter for the stack. - // (stored in Waiter node and incremented on push). - static const uint64_t kWaiterBits = 14; - static const uint64_t kStackMask = (1ull << kWaiterBits) - 1; - static const uint64_t kWaiterShift = kWaiterBits; - static const uint64_t kWaiterMask = ((1ull << kWaiterBits) - 1) - << kWaiterShift; - static const uint64_t kWaiterInc = 1ull << kWaiterShift; - static const uint64_t kSignalShift = 2 * kWaiterBits; - static const uint64_t kSignalMask = ((1ull << kWaiterBits) - 1) - << kSignalShift; - static const uint64_t kSignalInc = 1ull << kSignalShift; - static const uint64_t kEpochShift = 3 * kWaiterBits; - static const uint64_t kEpochBits = 64 - kEpochShift; - static const uint64_t kEpochMask = ((1ull << kEpochBits) - 1) << kEpochShift; - static const uint64_t kEpochInc = 1ull << kEpochShift; - std::atomic<uint64_t> state_; - MaxSizeVector<Waiter>& waiters_; - - static void CheckState(uint64_t state, bool waiter = false) { - static_assert(kEpochBits >= 20, "not enough bits to prevent ABA problem"); - const uint64_t waiters = (state & kWaiterMask) >> kWaiterShift; - const uint64_t signals = (state & kSignalMask) >> kSignalShift; - eigen_plain_assert(waiters >= signals); - eigen_plain_assert(waiters < (1 << kWaiterBits) - 1); - eigen_plain_assert(!waiter || waiters > 0); - (void)waiters; - (void)signals; - } - - void Park(Waiter* w) { - std::unique_lock<std::mutex> lock(w->mu); - while (w->state != Waiter::kSignaled) { - w->state = Waiter::kWaiting; - w->cv.wait(lock); - } - } - - void Unpark(Waiter* w) { - for (Waiter* next; w; w = next) { - uint64_t wnext = w->next.load(std::memory_order_relaxed) & kStackMask; - next = wnext == kStackMask ? nullptr : &waiters_[wnext]; - unsigned state; - { - std::unique_lock<std::mutex> lock(w->mu); - state = w->state; - w->state = Waiter::kSignaled; - } - // Avoid notifying if it wasn't waiting. - if (state == Waiter::kWaiting) w->cv.notify_one(); - } - } - - EventCount(const EventCount&) = delete; - void operator=(const EventCount&) = delete; -}; - -} // namespace Eigen - -#endif // EIGEN_CXX11_THREADPOOL_EVENTCOUNT_H_ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h deleted file mode 100644 index 9353f41e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h +++ /dev/null @@ -1,480 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Dmitry Vyukov <dvyukov@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_NONBLOCKING_THREAD_POOL_H -#define EIGEN_CXX11_THREADPOOL_NONBLOCKING_THREAD_POOL_H - -namespace Eigen { - -template <typename Environment> -class ThreadPoolTempl : public Eigen::ThreadPoolInterface { - public: - typedef typename Environment::Task Task; - typedef RunQueue<Task, 1024> Queue; - - ThreadPoolTempl(int num_threads, Environment env = Environment()) - : ThreadPoolTempl(num_threads, true, env) {} - - ThreadPoolTempl(int num_threads, bool allow_spinning, - Environment env = Environment()) - : env_(env), - num_threads_(num_threads), - allow_spinning_(allow_spinning), - thread_data_(num_threads), - all_coprimes_(num_threads), - waiters_(num_threads), - global_steal_partition_(EncodePartition(0, num_threads_)), - blocked_(0), - spinning_(0), - done_(false), - cancelled_(false), - ec_(waiters_) { - waiters_.resize(num_threads_); - // Calculate coprimes of all numbers [1, num_threads]. - // Coprimes are used for random walks over all threads in Steal - // and NonEmptyQueueIndex. Iteration is based on the fact that if we take - // a random starting thread index t and calculate num_threads - 1 subsequent - // indices as (t + coprime) % num_threads, we will cover all threads without - // repetitions (effectively getting a presudo-random permutation of thread - // indices). - eigen_plain_assert(num_threads_ < kMaxThreads); - for (int i = 1; i <= num_threads_; ++i) { - all_coprimes_.emplace_back(i); - ComputeCoprimes(i, &all_coprimes_.back()); - } -#ifndef EIGEN_THREAD_LOCAL - init_barrier_.reset(new Barrier(num_threads_)); -#endif - thread_data_.resize(num_threads_); - for (int i = 0; i < num_threads_; i++) { - SetStealPartition(i, EncodePartition(0, num_threads_)); - thread_data_[i].thread.reset( - env_.CreateThread([this, i]() { WorkerLoop(i); })); - } -#ifndef EIGEN_THREAD_LOCAL - // Wait for workers to initialize per_thread_map_. Otherwise we might race - // with them in Schedule or CurrentThreadId. - init_barrier_->Wait(); -#endif - } - - ~ThreadPoolTempl() { - done_ = true; - - // Now if all threads block without work, they will start exiting. - // But note that threads can continue to work arbitrary long, - // block, submit new work, unblock and otherwise live full life. - if (!cancelled_) { - ec_.Notify(true); - } else { - // Since we were cancelled, there might be entries in the queues. - // Empty them to prevent their destructor from asserting. - for (size_t i = 0; i < thread_data_.size(); i++) { - thread_data_[i].queue.Flush(); - } - } - // Join threads explicitly (by destroying) to avoid destruction order within - // this class. - for (size_t i = 0; i < thread_data_.size(); ++i) - thread_data_[i].thread.reset(); - } - - void SetStealPartitions(const std::vector<std::pair<unsigned, unsigned>>& partitions) { - eigen_plain_assert(partitions.size() == static_cast<std::size_t>(num_threads_)); - - // Pass this information to each thread queue. - for (int i = 0; i < num_threads_; i++) { - const auto& pair = partitions[i]; - unsigned start = pair.first, end = pair.second; - AssertBounds(start, end); - unsigned val = EncodePartition(start, end); - SetStealPartition(i, val); - } - } - - void Schedule(std::function<void()> fn) EIGEN_OVERRIDE { - ScheduleWithHint(std::move(fn), 0, num_threads_); - } - - void ScheduleWithHint(std::function<void()> fn, int start, - int limit) override { - Task t = env_.CreateTask(std::move(fn)); - PerThread* pt = GetPerThread(); - if (pt->pool == this) { - // Worker thread of this pool, push onto the thread's queue. - Queue& q = thread_data_[pt->thread_id].queue; - t = q.PushFront(std::move(t)); - } else { - // A free-standing thread (or worker of another pool), push onto a random - // queue. - eigen_plain_assert(start < limit); - eigen_plain_assert(limit <= num_threads_); - int num_queues = limit - start; - int rnd = Rand(&pt->rand) % num_queues; - eigen_plain_assert(start + rnd < limit); - Queue& q = thread_data_[start + rnd].queue; - t = q.PushBack(std::move(t)); - } - // Note: below we touch this after making w available to worker threads. - // Strictly speaking, this can lead to a racy-use-after-free. Consider that - // Schedule is called from a thread that is neither main thread nor a worker - // thread of this pool. Then, execution of w directly or indirectly - // completes overall computations, which in turn leads to destruction of - // this. We expect that such scenario is prevented by program, that is, - // this is kept alive while any threads can potentially be in Schedule. - if (!t.f) { - ec_.Notify(false); - } else { - env_.ExecuteTask(t); // Push failed, execute directly. - } - } - - void Cancel() EIGEN_OVERRIDE { - cancelled_ = true; - done_ = true; - - // Let each thread know it's been cancelled. -#ifdef EIGEN_THREAD_ENV_SUPPORTS_CANCELLATION - for (size_t i = 0; i < thread_data_.size(); i++) { - thread_data_[i].thread->OnCancel(); - } -#endif - - // Wake up the threads without work to let them exit on their own. - ec_.Notify(true); - } - - int NumThreads() const EIGEN_FINAL { return num_threads_; } - - int CurrentThreadId() const EIGEN_FINAL { - const PerThread* pt = const_cast<ThreadPoolTempl*>(this)->GetPerThread(); - if (pt->pool == this) { - return pt->thread_id; - } else { - return -1; - } - } - - private: - // Create a single atomic<int> that encodes start and limit information for - // each thread. - // We expect num_threads_ < 65536, so we can store them in a single - // std::atomic<unsigned>. - // Exposed publicly as static functions so that external callers can reuse - // this encode/decode logic for maintaining their own thread-safe copies of - // scheduling and steal domain(s). - static const int kMaxPartitionBits = 16; - static const int kMaxThreads = 1 << kMaxPartitionBits; - - inline unsigned EncodePartition(unsigned start, unsigned limit) { - return (start << kMaxPartitionBits) | limit; - } - - inline void DecodePartition(unsigned val, unsigned* start, unsigned* limit) { - *limit = val & (kMaxThreads - 1); - val >>= kMaxPartitionBits; - *start = val; - } - - void AssertBounds(int start, int end) { - eigen_plain_assert(start >= 0); - eigen_plain_assert(start < end); // non-zero sized partition - eigen_plain_assert(end <= num_threads_); - } - - inline void SetStealPartition(size_t i, unsigned val) { - thread_data_[i].steal_partition.store(val, std::memory_order_relaxed); - } - - inline unsigned GetStealPartition(int i) { - return thread_data_[i].steal_partition.load(std::memory_order_relaxed); - } - - void ComputeCoprimes(int N, MaxSizeVector<unsigned>* coprimes) { - for (int i = 1; i <= N; i++) { - unsigned a = i; - unsigned b = N; - // If GCD(a, b) == 1, then a and b are coprimes. - while (b != 0) { - unsigned tmp = a; - a = b; - b = tmp % b; - } - if (a == 1) { - coprimes->push_back(i); - } - } - } - - typedef typename Environment::EnvThread Thread; - - struct PerThread { - constexpr PerThread() : pool(NULL), rand(0), thread_id(-1) {} - ThreadPoolTempl* pool; // Parent pool, or null for normal threads. - uint64_t rand; // Random generator state. - int thread_id; // Worker thread index in pool. -#ifndef EIGEN_THREAD_LOCAL - // Prevent false sharing. - char pad_[128]; -#endif - }; - - struct ThreadData { - constexpr ThreadData() : thread(), steal_partition(0), queue() {} - std::unique_ptr<Thread> thread; - std::atomic<unsigned> steal_partition; - Queue queue; - }; - - Environment env_; - const int num_threads_; - const bool allow_spinning_; - MaxSizeVector<ThreadData> thread_data_; - MaxSizeVector<MaxSizeVector<unsigned>> all_coprimes_; - MaxSizeVector<EventCount::Waiter> waiters_; - unsigned global_steal_partition_; - std::atomic<unsigned> blocked_; - std::atomic<bool> spinning_; - std::atomic<bool> done_; - std::atomic<bool> cancelled_; - EventCount ec_; -#ifndef EIGEN_THREAD_LOCAL - std::unique_ptr<Barrier> init_barrier_; - std::mutex per_thread_map_mutex_; // Protects per_thread_map_. - std::unordered_map<uint64_t, std::unique_ptr<PerThread>> per_thread_map_; -#endif - - // Main worker thread loop. - void WorkerLoop(int thread_id) { -#ifndef EIGEN_THREAD_LOCAL - std::unique_ptr<PerThread> new_pt(new PerThread()); - per_thread_map_mutex_.lock(); - eigen_plain_assert(per_thread_map_.emplace(GlobalThreadIdHash(), std::move(new_pt)).second); - per_thread_map_mutex_.unlock(); - init_barrier_->Notify(); - init_barrier_->Wait(); -#endif - PerThread* pt = GetPerThread(); - pt->pool = this; - pt->rand = GlobalThreadIdHash(); - pt->thread_id = thread_id; - Queue& q = thread_data_[thread_id].queue; - EventCount::Waiter* waiter = &waiters_[thread_id]; - // TODO(dvyukov,rmlarsen): The time spent in NonEmptyQueueIndex() is - // proportional to num_threads_ and we assume that new work is scheduled at - // a constant rate, so we set spin_count to 5000 / num_threads_. The - // constant was picked based on a fair dice roll, tune it. - const int spin_count = - allow_spinning_ && num_threads_ > 0 ? 5000 / num_threads_ : 0; - if (num_threads_ == 1) { - // For num_threads_ == 1 there is no point in going through the expensive - // steal loop. Moreover, since NonEmptyQueueIndex() calls PopBack() on the - // victim queues it might reverse the order in which ops are executed - // compared to the order in which they are scheduled, which tends to be - // counter-productive for the types of I/O workloads the single thread - // pools tend to be used for. - while (!cancelled_) { - Task t = q.PopFront(); - for (int i = 0; i < spin_count && !t.f; i++) { - if (!cancelled_.load(std::memory_order_relaxed)) { - t = q.PopFront(); - } - } - if (!t.f) { - if (!WaitForWork(waiter, &t)) { - return; - } - } - if (t.f) { - env_.ExecuteTask(t); - } - } - } else { - while (!cancelled_) { - Task t = q.PopFront(); - if (!t.f) { - t = LocalSteal(); - if (!t.f) { - t = GlobalSteal(); - if (!t.f) { - // Leave one thread spinning. This reduces latency. - if (allow_spinning_ && !spinning_ && !spinning_.exchange(true)) { - for (int i = 0; i < spin_count && !t.f; i++) { - if (!cancelled_.load(std::memory_order_relaxed)) { - t = GlobalSteal(); - } else { - return; - } - } - spinning_ = false; - } - if (!t.f) { - if (!WaitForWork(waiter, &t)) { - return; - } - } - } - } - } - if (t.f) { - env_.ExecuteTask(t); - } - } - } - } - - // Steal tries to steal work from other worker threads in the range [start, - // limit) in best-effort manner. - Task Steal(unsigned start, unsigned limit) { - PerThread* pt = GetPerThread(); - const size_t size = limit - start; - unsigned r = Rand(&pt->rand); - unsigned victim = r % size; - unsigned inc = all_coprimes_[size - 1][r % all_coprimes_[size - 1].size()]; - - for (unsigned i = 0; i < size; i++) { - eigen_plain_assert(start + victim < limit); - Task t = thread_data_[start + victim].queue.PopBack(); - if (t.f) { - return t; - } - victim += inc; - if (victim >= size) { - victim -= size; - } - } - return Task(); - } - - // Steals work within threads belonging to the partition. - Task LocalSteal() { - PerThread* pt = GetPerThread(); - unsigned partition = GetStealPartition(pt->thread_id); - // If thread steal partition is the same as global partition, there is no - // need to go through the steal loop twice. - if (global_steal_partition_ == partition) return Task(); - unsigned start, limit; - DecodePartition(partition, &start, &limit); - AssertBounds(start, limit); - - return Steal(start, limit); - } - - // Steals work from any other thread in the pool. - Task GlobalSteal() { - return Steal(0, num_threads_); - } - - - // WaitForWork blocks until new work is available (returns true), or if it is - // time to exit (returns false). Can optionally return a task to execute in t - // (in such case t.f != nullptr on return). - bool WaitForWork(EventCount::Waiter* waiter, Task* t) { - eigen_plain_assert(!t->f); - // We already did best-effort emptiness check in Steal, so prepare for - // blocking. - ec_.Prewait(); - // Now do a reliable emptiness check. - int victim = NonEmptyQueueIndex(); - if (victim != -1) { - ec_.CancelWait(); - if (cancelled_) { - return false; - } else { - *t = thread_data_[victim].queue.PopBack(); - return true; - } - } - // Number of blocked threads is used as termination condition. - // If we are shutting down and all worker threads blocked without work, - // that's we are done. - blocked_++; - // TODO is blocked_ required to be unsigned? - if (done_ && blocked_ == static_cast<unsigned>(num_threads_)) { - ec_.CancelWait(); - // Almost done, but need to re-check queues. - // Consider that all queues are empty and all worker threads are preempted - // right after incrementing blocked_ above. Now a free-standing thread - // submits work and calls destructor (which sets done_). If we don't - // re-check queues, we will exit leaving the work unexecuted. - if (NonEmptyQueueIndex() != -1) { - // Note: we must not pop from queues before we decrement blocked_, - // otherwise the following scenario is possible. Consider that instead - // of checking for emptiness we popped the only element from queues. - // Now other worker threads can start exiting, which is bad if the - // work item submits other work. So we just check emptiness here, - // which ensures that all worker threads exit at the same time. - blocked_--; - return true; - } - // Reached stable termination state. - ec_.Notify(true); - return false; - } - ec_.CommitWait(waiter); - blocked_--; - return true; - } - - int NonEmptyQueueIndex() { - PerThread* pt = GetPerThread(); - // We intentionally design NonEmptyQueueIndex to steal work from - // anywhere in the queue so threads don't block in WaitForWork() forever - // when all threads in their partition go to sleep. Steal is still local. - const size_t size = thread_data_.size(); - unsigned r = Rand(&pt->rand); - unsigned inc = all_coprimes_[size - 1][r % all_coprimes_[size - 1].size()]; - unsigned victim = r % size; - for (unsigned i = 0; i < size; i++) { - if (!thread_data_[victim].queue.Empty()) { - return victim; - } - victim += inc; - if (victim >= size) { - victim -= size; - } - } - return -1; - } - - static EIGEN_STRONG_INLINE uint64_t GlobalThreadIdHash() { - return std::hash<std::thread::id>()(std::this_thread::get_id()); - } - - EIGEN_STRONG_INLINE PerThread* GetPerThread() { -#ifndef EIGEN_THREAD_LOCAL - static PerThread dummy; - auto it = per_thread_map_.find(GlobalThreadIdHash()); - if (it == per_thread_map_.end()) { - return &dummy; - } else { - return it->second.get(); - } -#else - EIGEN_THREAD_LOCAL PerThread per_thread_; - PerThread* pt = &per_thread_; - return pt; -#endif - } - - static EIGEN_STRONG_INLINE unsigned Rand(uint64_t* state) { - uint64_t current = *state; - // Update the internal state - *state = current * 6364136223846793005ULL + 0xda3e39cb94b95bdbULL; - // Generate the random output (using the PCG-XSH-RS scheme) - return static_cast<unsigned>((current ^ (current >> 22)) >> - (22 + (current >> 61))); - } -}; - -typedef ThreadPoolTempl<StlThreadEnvironment> ThreadPool; - -} // namespace Eigen - -#endif // EIGEN_CXX11_THREADPOOL_NONBLOCKING_THREAD_POOL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/RunQueue.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/RunQueue.h deleted file mode 100644 index b572ebcd..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/RunQueue.h +++ /dev/null @@ -1,236 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Dmitry Vyukov <dvyukov@google.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_RUNQUEUE_H_ -#define EIGEN_CXX11_THREADPOOL_RUNQUEUE_H_ - -namespace Eigen { - -// RunQueue is a fixed-size, partially non-blocking deque or Work items. -// Operations on front of the queue must be done by a single thread (owner), -// operations on back of the queue can be done by multiple threads concurrently. -// -// Algorithm outline: -// All remote threads operating on the queue back are serialized by a mutex. -// This ensures that at most two threads access state: owner and one remote -// thread (Size aside). The algorithm ensures that the occupied region of the -// underlying array is logically continuous (can wraparound, but no stray -// occupied elements). Owner operates on one end of this region, remote thread -// operates on the other end. Synchronization between these threads -// (potential consumption of the last element and take up of the last empty -// element) happens by means of state variable in each element. States are: -// empty, busy (in process of insertion of removal) and ready. Threads claim -// elements (empty->busy and ready->busy transitions) by means of a CAS -// operation. The finishing transition (busy->empty and busy->ready) are done -// with plain store as the element is exclusively owned by the current thread. -// -// Note: we could permit only pointers as elements, then we would not need -// separate state variable as null/non-null pointer value would serve as state, -// but that would require malloc/free per operation for large, complex values -// (and this is designed to store std::function<()>). -template <typename Work, unsigned kSize> -class RunQueue { - public: - RunQueue() : front_(0), back_(0) { - // require power-of-two for fast masking - eigen_plain_assert((kSize & (kSize - 1)) == 0); - eigen_plain_assert(kSize > 2); // why would you do this? - eigen_plain_assert(kSize <= (64 << 10)); // leave enough space for counter - for (unsigned i = 0; i < kSize; i++) - array_[i].state.store(kEmpty, std::memory_order_relaxed); - } - - ~RunQueue() { eigen_plain_assert(Size() == 0); } - - // PushFront inserts w at the beginning of the queue. - // If queue is full returns w, otherwise returns default-constructed Work. - Work PushFront(Work w) { - unsigned front = front_.load(std::memory_order_relaxed); - Elem* e = &array_[front & kMask]; - uint8_t s = e->state.load(std::memory_order_relaxed); - if (s != kEmpty || - !e->state.compare_exchange_strong(s, kBusy, std::memory_order_acquire)) - return w; - front_.store(front + 1 + (kSize << 1), std::memory_order_relaxed); - e->w = std::move(w); - e->state.store(kReady, std::memory_order_release); - return Work(); - } - - // PopFront removes and returns the first element in the queue. - // If the queue was empty returns default-constructed Work. - Work PopFront() { - unsigned front = front_.load(std::memory_order_relaxed); - Elem* e = &array_[(front - 1) & kMask]; - uint8_t s = e->state.load(std::memory_order_relaxed); - if (s != kReady || - !e->state.compare_exchange_strong(s, kBusy, std::memory_order_acquire)) - return Work(); - Work w = std::move(e->w); - e->state.store(kEmpty, std::memory_order_release); - front = ((front - 1) & kMask2) | (front & ~kMask2); - front_.store(front, std::memory_order_relaxed); - return w; - } - - // PushBack adds w at the end of the queue. - // If queue is full returns w, otherwise returns default-constructed Work. - Work PushBack(Work w) { - std::unique_lock<std::mutex> lock(mutex_); - unsigned back = back_.load(std::memory_order_relaxed); - Elem* e = &array_[(back - 1) & kMask]; - uint8_t s = e->state.load(std::memory_order_relaxed); - if (s != kEmpty || - !e->state.compare_exchange_strong(s, kBusy, std::memory_order_acquire)) - return w; - back = ((back - 1) & kMask2) | (back & ~kMask2); - back_.store(back, std::memory_order_relaxed); - e->w = std::move(w); - e->state.store(kReady, std::memory_order_release); - return Work(); - } - - // PopBack removes and returns the last elements in the queue. - Work PopBack() { - if (Empty()) return Work(); - std::unique_lock<std::mutex> lock(mutex_); - unsigned back = back_.load(std::memory_order_relaxed); - Elem* e = &array_[back & kMask]; - uint8_t s = e->state.load(std::memory_order_relaxed); - if (s != kReady || - !e->state.compare_exchange_strong(s, kBusy, std::memory_order_acquire)) - return Work(); - Work w = std::move(e->w); - e->state.store(kEmpty, std::memory_order_release); - back_.store(back + 1 + (kSize << 1), std::memory_order_relaxed); - return w; - } - - // PopBackHalf removes and returns half last elements in the queue. - // Returns number of elements removed. - unsigned PopBackHalf(std::vector<Work>* result) { - if (Empty()) return 0; - std::unique_lock<std::mutex> lock(mutex_); - unsigned back = back_.load(std::memory_order_relaxed); - unsigned size = Size(); - unsigned mid = back; - if (size > 1) mid = back + (size - 1) / 2; - unsigned n = 0; - unsigned start = 0; - for (; static_cast<int>(mid - back) >= 0; mid--) { - Elem* e = &array_[mid & kMask]; - uint8_t s = e->state.load(std::memory_order_relaxed); - if (n == 0) { - if (s != kReady || !e->state.compare_exchange_strong( - s, kBusy, std::memory_order_acquire)) - continue; - start = mid; - } else { - // Note: no need to store temporal kBusy, we exclusively own these - // elements. - eigen_plain_assert(s == kReady); - } - result->push_back(std::move(e->w)); - e->state.store(kEmpty, std::memory_order_release); - n++; - } - if (n != 0) - back_.store(start + 1 + (kSize << 1), std::memory_order_relaxed); - return n; - } - - // Size returns current queue size. - // Can be called by any thread at any time. - unsigned Size() const { return SizeOrNotEmpty<true>(); } - - // Empty tests whether container is empty. - // Can be called by any thread at any time. - bool Empty() const { return SizeOrNotEmpty<false>() == 0; } - - // Delete all the elements from the queue. - void Flush() { - while (!Empty()) { - PopFront(); - } - } - - private: - static const unsigned kMask = kSize - 1; - static const unsigned kMask2 = (kSize << 1) - 1; - struct Elem { - std::atomic<uint8_t> state; - Work w; - }; - enum { - kEmpty, - kBusy, - kReady, - }; - std::mutex mutex_; - // Low log(kSize) + 1 bits in front_ and back_ contain rolling index of - // front/back, respectively. The remaining bits contain modification counters - // that are incremented on Push operations. This allows us to (1) distinguish - // between empty and full conditions (if we would use log(kSize) bits for - // position, these conditions would be indistinguishable); (2) obtain - // consistent snapshot of front_/back_ for Size operation using the - // modification counters. - std::atomic<unsigned> front_; - std::atomic<unsigned> back_; - Elem array_[kSize]; - - // SizeOrNotEmpty returns current queue size; if NeedSizeEstimate is false, - // only whether the size is 0 is guaranteed to be correct. - // Can be called by any thread at any time. - template<bool NeedSizeEstimate> - unsigned SizeOrNotEmpty() const { - // Emptiness plays critical role in thread pool blocking. So we go to great - // effort to not produce false positives (claim non-empty queue as empty). - unsigned front = front_.load(std::memory_order_acquire); - for (;;) { - // Capture a consistent snapshot of front/tail. - unsigned back = back_.load(std::memory_order_acquire); - unsigned front1 = front_.load(std::memory_order_relaxed); - if (front != front1) { - front = front1; - std::atomic_thread_fence(std::memory_order_acquire); - continue; - } - if (NeedSizeEstimate) { - return CalculateSize(front, back); - } else { - // This value will be 0 if the queue is empty, and undefined otherwise. - unsigned maybe_zero = ((front ^ back) & kMask2); - // Queue size estimate must agree with maybe zero check on the queue - // empty/non-empty state. - eigen_assert((CalculateSize(front, back) == 0) == (maybe_zero == 0)); - return maybe_zero; - } - } - } - - EIGEN_ALWAYS_INLINE - unsigned CalculateSize(unsigned front, unsigned back) const { - int size = (front & kMask2) - (back & kMask2); - // Fix overflow. - if (size < 0) size += 2 * kSize; - // Order of modification in push/pop is crafted to make the queue look - // larger than it is during concurrent modifications. E.g. push can - // increment size before the corresponding pop has decremented it. - // So the computed size can be up to kSize + 1, fix it. - if (size > static_cast<int>(kSize)) size = kSize; - return static_cast<unsigned>(size); - } - - RunQueue(const RunQueue&) = delete; - void operator=(const RunQueue&) = delete; -}; - -} // namespace Eigen - -#endif // EIGEN_CXX11_THREADPOOL_RUNQUEUE_H_ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadCancel.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadCancel.h deleted file mode 100644 index a05685f1..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadCancel.h +++ /dev/null @@ -1,23 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_THREAD_CANCEL_H -#define EIGEN_CXX11_THREADPOOL_THREAD_CANCEL_H - -// Try to come up with a portable way to cancel a thread -#if EIGEN_OS_GNULINUX - #define EIGEN_THREAD_CANCEL(t) \ - pthread_cancel(t.native_handle()); - #define EIGEN_SUPPORTS_THREAD_CANCELLATION 1 -#else -#define EIGEN_THREAD_CANCEL(t) -#endif - - -#endif // EIGEN_CXX11_THREADPOOL_THREAD_CANCEL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadEnvironment.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadEnvironment.h deleted file mode 100644 index d94a0641..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadEnvironment.h +++ /dev/null @@ -1,40 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H -#define EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H - -namespace Eigen { - -struct StlThreadEnvironment { - struct Task { - std::function<void()> f; - }; - - // EnvThread constructor must start the thread, - // destructor must join the thread. - class EnvThread { - public: - EnvThread(std::function<void()> f) : thr_(std::move(f)) {} - ~EnvThread() { thr_.join(); } - // This function is called when the threadpool is cancelled. - void OnCancel() { } - - private: - std::thread thr_; - }; - - EnvThread* CreateThread(std::function<void()> f) { return new EnvThread(std::move(f)); } - Task CreateTask(std::function<void()> f) { return Task{std::move(f)}; } - void ExecuteTask(const Task& t) { t.f(); } -}; - -} // namespace Eigen - -#endif // EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h deleted file mode 100644 index 4e684740..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h +++ /dev/null @@ -1,301 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_THREAD_LOCAL_H -#define EIGEN_CXX11_THREADPOOL_THREAD_LOCAL_H - -#ifdef EIGEN_AVOID_THREAD_LOCAL - -#ifdef EIGEN_THREAD_LOCAL -#undef EIGEN_THREAD_LOCAL -#endif - -#else - -#if EIGEN_MAX_CPP_VER >= 11 && \ - ((EIGEN_COMP_GNUC && EIGEN_GNUC_AT_LEAST(4, 8)) || \ - __has_feature(cxx_thread_local) || \ - (EIGEN_COMP_MSVC >= 1900) ) -#define EIGEN_THREAD_LOCAL static thread_local -#endif - -// Disable TLS for Apple and Android builds with older toolchains. -#if defined(__APPLE__) -// Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED, -// __IPHONE_8_0. -#include <Availability.h> -#include <TargetConditionals.h> -#endif -// Checks whether C++11's `thread_local` storage duration specifier is -// supported. -#if defined(__apple_build_version__) && \ - ((__apple_build_version__ < 8000042) || \ - (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)) -// Notes: Xcode's clang did not support `thread_local` until version -// 8, and even then not for all iOS < 9.0. -#undef EIGEN_THREAD_LOCAL - -#elif defined(__ANDROID__) && EIGEN_COMP_CLANG -// There are platforms for which TLS should not be used even though the compiler -// makes it seem like it's supported (Android NDK < r12b for example). -// This is primarily because of linker problems and toolchain misconfiguration: -// TLS isn't supported until NDK r12b per -// https://developer.android.com/ndk/downloads/revision_history.html -// Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in -// <android/ndk-version.h>. For NDK < r16, users should define these macros, -// e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11. -#if __has_include(<android/ndk-version.h>) -#include <android/ndk-version.h> -#endif // __has_include(<android/ndk-version.h>) -#if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \ - defined(__NDK_MINOR__) && \ - ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1))) -#undef EIGEN_THREAD_LOCAL -#endif -#endif // defined(__ANDROID__) && defined(__clang__) - -#endif // EIGEN_AVOID_THREAD_LOCAL - -namespace Eigen { - -namespace internal { -template <typename T> -struct ThreadLocalNoOpInitialize { - void operator()(T&) const {} -}; - -template <typename T> -struct ThreadLocalNoOpRelease { - void operator()(T&) const {} -}; - -} // namespace internal - -// Thread local container for elements of type T, that does not use thread local -// storage. As long as the number of unique threads accessing this storage -// is smaller than `capacity_`, it is lock-free and wait-free. Otherwise it will -// use a mutex for synchronization. -// -// Type `T` has to be default constructible, and by default each thread will get -// a default constructed value. It is possible to specify custom `initialize` -// callable, that will be called lazily from each thread accessing this object, -// and will be passed a default initialized object of type `T`. Also it's -// possible to pass a custom `release` callable, that will be invoked before -// calling ~T(). -// -// Example: -// -// struct Counter { -// int value = 0; -// } -// -// Eigen::ThreadLocal<Counter> counter(10); -// -// // Each thread will have access to it's own counter object. -// Counter& cnt = counter.local(); -// cnt++; -// -// WARNING: Eigen::ThreadLocal uses the OS-specific value returned by -// std::this_thread::get_id() to identify threads. This value is not guaranteed -// to be unique except for the life of the thread. A newly created thread may -// get an OS-specific ID equal to that of an already destroyed thread. -// -// Somewhat similar to TBB thread local storage, with similar restrictions: -// https://www.threadingbuildingblocks.org/docs/help/reference/thread_local_storage/enumerable_thread_specific_cls.html -// -template <typename T, - typename Initialize = internal::ThreadLocalNoOpInitialize<T>, - typename Release = internal::ThreadLocalNoOpRelease<T>> -class ThreadLocal { - // We preallocate default constructed elements in MaxSizedVector. - static_assert(std::is_default_constructible<T>::value, - "ThreadLocal data type must be default constructible"); - - public: - explicit ThreadLocal(int capacity) - : ThreadLocal(capacity, internal::ThreadLocalNoOpInitialize<T>(), - internal::ThreadLocalNoOpRelease<T>()) {} - - ThreadLocal(int capacity, Initialize initialize) - : ThreadLocal(capacity, std::move(initialize), - internal::ThreadLocalNoOpRelease<T>()) {} - - ThreadLocal(int capacity, Initialize initialize, Release release) - : initialize_(std::move(initialize)), - release_(std::move(release)), - capacity_(capacity), - data_(capacity_), - ptr_(capacity_), - filled_records_(0) { - eigen_assert(capacity_ >= 0); - data_.resize(capacity_); - for (int i = 0; i < capacity_; ++i) { - ptr_.emplace_back(nullptr); - } - } - - T& local() { - std::thread::id this_thread = std::this_thread::get_id(); - if (capacity_ == 0) return SpilledLocal(this_thread); - - std::size_t h = std::hash<std::thread::id>()(this_thread); - const int start_idx = h % capacity_; - - // NOTE: From the definition of `std::this_thread::get_id()` it is - // guaranteed that we never can have concurrent insertions with the same key - // to our hash-map like data structure. If we didn't find an element during - // the initial traversal, it's guaranteed that no one else could have - // inserted it while we are in this function. This allows to massively - // simplify out lock-free insert-only hash map. - - // Check if we already have an element for `this_thread`. - int idx = start_idx; - while (ptr_[idx].load() != nullptr) { - ThreadIdAndValue& record = *(ptr_[idx].load()); - if (record.thread_id == this_thread) return record.value; - - idx += 1; - if (idx >= capacity_) idx -= capacity_; - if (idx == start_idx) break; - } - - // If we are here, it means that we found an insertion point in lookup - // table at `idx`, or we did a full traversal and table is full. - - // If lock-free storage is full, fallback on mutex. - if (filled_records_.load() >= capacity_) return SpilledLocal(this_thread); - - // We double check that we still have space to insert an element into a lock - // free storage. If old value in `filled_records_` is larger than the - // records capacity, it means that some other thread added an element while - // we were traversing lookup table. - int insertion_index = - filled_records_.fetch_add(1, std::memory_order_relaxed); - if (insertion_index >= capacity_) return SpilledLocal(this_thread); - - // At this point it's guaranteed that we can access to - // data_[insertion_index_] without a data race. - data_[insertion_index].thread_id = this_thread; - initialize_(data_[insertion_index].value); - - // That's the pointer we'll put into the lookup table. - ThreadIdAndValue* inserted = &data_[insertion_index]; - - // We'll use nullptr pointer to ThreadIdAndValue in a compare-and-swap loop. - ThreadIdAndValue* empty = nullptr; - - // Now we have to find an insertion point into the lookup table. We start - // from the `idx` that was identified as an insertion point above, it's - // guaranteed that we will have an empty record somewhere in a lookup table - // (because we created a record in the `data_`). - const int insertion_idx = idx; - - do { - // Always start search from the original insertion candidate. - idx = insertion_idx; - while (ptr_[idx].load() != nullptr) { - idx += 1; - if (idx >= capacity_) idx -= capacity_; - // If we did a full loop, it means that we don't have any free entries - // in the lookup table, and this means that something is terribly wrong. - eigen_assert(idx != insertion_idx); - } - // Atomic CAS of the pointer guarantees that any other thread, that will - // follow this pointer will see all the mutations in the `data_`. - } while (!ptr_[idx].compare_exchange_weak(empty, inserted)); - - return inserted->value; - } - - // WARN: It's not thread safe to call it concurrently with `local()`. - void ForEach(std::function<void(std::thread::id, T&)> f) { - // Reading directly from `data_` is unsafe, because only CAS to the - // record in `ptr_` makes all changes visible to other threads. - for (auto& ptr : ptr_) { - ThreadIdAndValue* record = ptr.load(); - if (record == nullptr) continue; - f(record->thread_id, record->value); - } - - // We did not spill into the map based storage. - if (filled_records_.load(std::memory_order_relaxed) < capacity_) return; - - // Adds a happens before edge from the last call to SpilledLocal(). - std::unique_lock<std::mutex> lock(mu_); - for (auto& kv : per_thread_map_) { - f(kv.first, kv.second); - } - } - - // WARN: It's not thread safe to call it concurrently with `local()`. - ~ThreadLocal() { - // Reading directly from `data_` is unsafe, because only CAS to the record - // in `ptr_` makes all changes visible to other threads. - for (auto& ptr : ptr_) { - ThreadIdAndValue* record = ptr.load(); - if (record == nullptr) continue; - release_(record->value); - } - - // We did not spill into the map based storage. - if (filled_records_.load(std::memory_order_relaxed) < capacity_) return; - - // Adds a happens before edge from the last call to SpilledLocal(). - std::unique_lock<std::mutex> lock(mu_); - for (auto& kv : per_thread_map_) { - release_(kv.second); - } - } - - private: - struct ThreadIdAndValue { - std::thread::id thread_id; - T value; - }; - - // Use unordered map guarded by a mutex when lock free storage is full. - T& SpilledLocal(std::thread::id this_thread) { - std::unique_lock<std::mutex> lock(mu_); - - auto it = per_thread_map_.find(this_thread); - if (it == per_thread_map_.end()) { - auto result = per_thread_map_.emplace(this_thread, T()); - eigen_assert(result.second); - initialize_((*result.first).second); - return (*result.first).second; - } else { - return it->second; - } - } - - Initialize initialize_; - Release release_; - const int capacity_; - - // Storage that backs lock-free lookup table `ptr_`. Records stored in this - // storage contiguously starting from index 0. - MaxSizeVector<ThreadIdAndValue> data_; - - // Atomic pointers to the data stored in `data_`. Used as a lookup table for - // linear probing hash map (https://en.wikipedia.org/wiki/Linear_probing). - MaxSizeVector<std::atomic<ThreadIdAndValue*>> ptr_; - - // Number of records stored in the `data_`. - std::atomic<int> filled_records_; - - // We fallback on per thread map if lock-free storage is full. In practice - // this should never happen, if `capacity_` is a reasonable estimate of the - // number of threads running in a system. - std::mutex mu_; // Protects per_thread_map_. - std::unordered_map<std::thread::id, T> per_thread_map_; -}; - -} // namespace Eigen - -#endif // EIGEN_CXX11_THREADPOOL_THREAD_LOCAL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadPoolInterface.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadPoolInterface.h deleted file mode 100644 index 25030dc0..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadPoolInterface.h +++ /dev/null @@ -1,48 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_THREAD_POOL_INTERFACE_H -#define EIGEN_CXX11_THREADPOOL_THREAD_POOL_INTERFACE_H - -namespace Eigen { - -// This defines an interface that ThreadPoolDevice can take to use -// custom thread pools underneath. -class ThreadPoolInterface { - public: - // Submits a closure to be run by a thread in the pool. - virtual void Schedule(std::function<void()> fn) = 0; - - // Submits a closure to be run by threads in the range [start, end) in the - // pool. - virtual void ScheduleWithHint(std::function<void()> fn, int /*start*/, - int /*end*/) { - // Just defer to Schedule in case sub-classes aren't interested in - // overriding this functionality. - Schedule(fn); - } - - // If implemented, stop processing the closures that have been enqueued. - // Currently running closures may still be processed. - // If not implemented, does nothing. - virtual void Cancel() {} - - // Returns the number of threads in the pool. - virtual int NumThreads() const = 0; - - // Returns a logical thread index between 0 and NumThreads() - 1 if called - // from one of the threads in the pool. Returns -1 otherwise. - virtual int CurrentThreadId() const = 0; - - virtual ~ThreadPoolInterface() {} -}; - -} // namespace Eigen - -#endif // EIGEN_CXX11_THREADPOOL_THREAD_POOL_INTERFACE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadYield.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadYield.h deleted file mode 100644 index a859c7ba..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/ThreadPool/ThreadYield.h +++ /dev/null @@ -1,20 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11_THREADPOOL_THREAD_YIELD_H -#define EIGEN_CXX11_THREADPOOL_THREAD_YIELD_H - -// Try to come up with a portable way to yield -#if EIGEN_COMP_GNUC && EIGEN_GNUC_AT_MOST(4, 7) -#define EIGEN_THREAD_YIELD() sched_yield() -#else -#define EIGEN_THREAD_YIELD() std::this_thread::yield() -#endif - -#endif // EIGEN_CXX11_THREADPOOL_THREAD_YIELD_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/CXX11Meta.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/CXX11Meta.h deleted file mode 100644 index 149ceaff..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/CXX11Meta.h +++ /dev/null @@ -1,537 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11META_H -#define EIGEN_CXX11META_H - -#include <vector> -#include "EmulateArray.h" - -#include "CXX11Workarounds.h" - -namespace Eigen { - -namespace internal { - -/** \internal - * \file CXX11/util/CXX11Meta.h - * This file contains generic metaprogramming classes which are not specifically related to Eigen. - * This file expands upon Core/util/Meta.h and adds support for C++11 specific features. - */ - -template<typename... tt> -struct type_list { constexpr static int count = sizeof...(tt); }; - -template<typename t, typename... tt> -struct type_list<t, tt...> { constexpr static int count = sizeof...(tt) + 1; typedef t first_type; }; - -template<typename T, T... nn> -struct numeric_list { constexpr static std::size_t count = sizeof...(nn); }; - -template<typename T, T n, T... nn> -struct numeric_list<T, n, nn...> { static const std::size_t count = sizeof...(nn) + 1; const static T first_value = n; }; - -#ifndef EIGEN_PARSED_BY_DOXYGEN -/* numeric list constructors - * - * equivalencies: - * constructor result - * typename gen_numeric_list<int, 5>::type numeric_list<int, 0,1,2,3,4> - * typename gen_numeric_list_reversed<int, 5>::type numeric_list<int, 4,3,2,1,0> - * typename gen_numeric_list_swapped_pair<int, 5,1,2>::type numeric_list<int, 0,2,1,3,4> - * typename gen_numeric_list_repeated<int, 0, 5>::type numeric_list<int, 0,0,0,0,0> - */ - -template<typename T, std::size_t n, T start = 0, T... ii> struct gen_numeric_list : gen_numeric_list<T, n-1, start, start + n-1, ii...> {}; -template<typename T, T start, T... ii> struct gen_numeric_list<T, 0, start, ii...> { typedef numeric_list<T, ii...> type; }; - -template<typename T, std::size_t n, T start = 0, T... ii> struct gen_numeric_list_reversed : gen_numeric_list_reversed<T, n-1, start, ii..., start + n-1> {}; -template<typename T, T start, T... ii> struct gen_numeric_list_reversed<T, 0, start, ii...> { typedef numeric_list<T, ii...> type; }; - -template<typename T, std::size_t n, T a, T b, T start = 0, T... ii> struct gen_numeric_list_swapped_pair : gen_numeric_list_swapped_pair<T, n-1, a, b, start, (start + n-1) == a ? b : ((start + n-1) == b ? a : (start + n-1)), ii...> {}; -template<typename T, T a, T b, T start, T... ii> struct gen_numeric_list_swapped_pair<T, 0, a, b, start, ii...> { typedef numeric_list<T, ii...> type; }; - -template<typename T, std::size_t n, T V, T... nn> struct gen_numeric_list_repeated : gen_numeric_list_repeated<T, n-1, V, V, nn...> {}; -template<typename T, T V, T... nn> struct gen_numeric_list_repeated<T, 0, V, nn...> { typedef numeric_list<T, nn...> type; }; - -/* list manipulation: concatenate */ - -template<class a, class b> struct concat; - -template<typename... as, typename... bs> struct concat<type_list<as...>, type_list<bs...>> { typedef type_list<as..., bs...> type; }; -template<typename T, T... as, T... bs> struct concat<numeric_list<T, as...>, numeric_list<T, bs...> > { typedef numeric_list<T, as..., bs...> type; }; - -template<typename... p> struct mconcat; -template<typename a> struct mconcat<a> { typedef a type; }; -template<typename a, typename b> struct mconcat<a, b> : concat<a, b> {}; -template<typename a, typename b, typename... cs> struct mconcat<a, b, cs...> : concat<a, typename mconcat<b, cs...>::type> {}; - -/* list manipulation: extract slices */ - -template<int n, typename x> struct take; -template<int n, typename a, typename... as> struct take<n, type_list<a, as...>> : concat<type_list<a>, typename take<n-1, type_list<as...>>::type> {}; -template<int n> struct take<n, type_list<>> { typedef type_list<> type; }; -template<typename a, typename... as> struct take<0, type_list<a, as...>> { typedef type_list<> type; }; -template<> struct take<0, type_list<>> { typedef type_list<> type; }; - -template<typename T, int n, T a, T... as> struct take<n, numeric_list<T, a, as...>> : concat<numeric_list<T, a>, typename take<n-1, numeric_list<T, as...>>::type> {}; -template<typename T, int n> struct take<n, numeric_list<T>> { typedef numeric_list<T> type; }; -template<typename T, T a, T... as> struct take<0, numeric_list<T, a, as...>> { typedef numeric_list<T> type; }; -template<typename T> struct take<0, numeric_list<T>> { typedef numeric_list<T> type; }; - -template<typename T, int n, T... ii> struct h_skip_helper_numeric; -template<typename T, int n, T i, T... ii> struct h_skip_helper_numeric<T, n, i, ii...> : h_skip_helper_numeric<T, n-1, ii...> {}; -template<typename T, T i, T... ii> struct h_skip_helper_numeric<T, 0, i, ii...> { typedef numeric_list<T, i, ii...> type; }; -template<typename T, int n> struct h_skip_helper_numeric<T, n> { typedef numeric_list<T> type; }; -template<typename T> struct h_skip_helper_numeric<T, 0> { typedef numeric_list<T> type; }; - -template<int n, typename... tt> struct h_skip_helper_type; -template<int n, typename t, typename... tt> struct h_skip_helper_type<n, t, tt...> : h_skip_helper_type<n-1, tt...> {}; -template<typename t, typename... tt> struct h_skip_helper_type<0, t, tt...> { typedef type_list<t, tt...> type; }; -template<int n> struct h_skip_helper_type<n> { typedef type_list<> type; }; -template<> struct h_skip_helper_type<0> { typedef type_list<> type; }; -#endif //not EIGEN_PARSED_BY_DOXYGEN - -template<int n> -struct h_skip { - template<typename T, T... ii> - constexpr static EIGEN_STRONG_INLINE typename h_skip_helper_numeric<T, n, ii...>::type helper(numeric_list<T, ii...>) { return typename h_skip_helper_numeric<T, n, ii...>::type(); } - template<typename... tt> - constexpr static EIGEN_STRONG_INLINE typename h_skip_helper_type<n, tt...>::type helper(type_list<tt...>) { return typename h_skip_helper_type<n, tt...>::type(); } -}; - -template<int n, typename a> struct skip { typedef decltype(h_skip<n>::helper(a())) type; }; - -template<int start, int count, typename a> struct slice : take<count, typename skip<start, a>::type> {}; - -/* list manipulation: retrieve single element from list */ - -template<int n, typename x> struct get; - -template<int n, typename a, typename... as> struct get<n, type_list<a, as...>> : get<n-1, type_list<as...>> {}; -template<typename a, typename... as> struct get<0, type_list<a, as...>> { typedef a type; }; - -template<typename T, int n, T a, T... as> struct get<n, numeric_list<T, a, as...>> : get<n-1, numeric_list<T, as...>> {}; -template<typename T, T a, T... as> struct get<0, numeric_list<T, a, as...>> { constexpr static T value = a; }; - -template<std::size_t n, typename T, T a, T... as> constexpr T array_get(const numeric_list<T, a, as...>&) { - return get<(int)n, numeric_list<T, a, as...>>::value; -} - -/* always get type, regardless of dummy; good for parameter pack expansion */ - -template<typename T, T dummy, typename t> struct id_numeric { typedef t type; }; -template<typename dummy, typename t> struct id_type { typedef t type; }; - -/* equality checking, flagged version */ - -template<typename a, typename b> struct is_same_gf : is_same<a, b> { constexpr static int global_flags = 0; }; - -/* apply_op to list */ - -template< - bool from_left, // false - template<typename, typename> class op, - typename additional_param, - typename... values -> -struct h_apply_op_helper { typedef type_list<typename op<values, additional_param>::type...> type; }; -template< - template<typename, typename> class op, - typename additional_param, - typename... values -> -struct h_apply_op_helper<true, op, additional_param, values...> { typedef type_list<typename op<additional_param, values>::type...> type; }; - -template< - bool from_left, - template<typename, typename> class op, - typename additional_param -> -struct h_apply_op -{ - template<typename... values> - constexpr static typename h_apply_op_helper<from_left, op, additional_param, values...>::type helper(type_list<values...>) - { return typename h_apply_op_helper<from_left, op, additional_param, values...>::type(); } -}; - -template< - template<typename, typename> class op, - typename additional_param, - typename a -> -struct apply_op_from_left { typedef decltype(h_apply_op<true, op, additional_param>::helper(a())) type; }; - -template< - template<typename, typename> class op, - typename additional_param, - typename a -> -struct apply_op_from_right { typedef decltype(h_apply_op<false, op, additional_param>::helper(a())) type; }; - -/* see if an element is in a list */ - -template< - template<typename, typename> class test, - typename check_against, - typename h_list, - bool last_check_positive = false -> -struct contained_in_list; - -template< - template<typename, typename> class test, - typename check_against, - typename h_list -> -struct contained_in_list<test, check_against, h_list, true> -{ - constexpr static bool value = true; -}; - -template< - template<typename, typename> class test, - typename check_against, - typename a, - typename... as -> -struct contained_in_list<test, check_against, type_list<a, as...>, false> : contained_in_list<test, check_against, type_list<as...>, test<check_against, a>::value> {}; - -template< - template<typename, typename> class test, - typename check_against - EIGEN_TPL_PP_SPEC_HACK_DEFC(typename, empty) -> -struct contained_in_list<test, check_against, type_list<EIGEN_TPL_PP_SPEC_HACK_USE(empty)>, false> { constexpr static bool value = false; }; - -/* see if an element is in a list and check for global flags */ - -template< - template<typename, typename> class test, - typename check_against, - typename h_list, - int default_flags = 0, - bool last_check_positive = false, - int last_check_flags = default_flags -> -struct contained_in_list_gf; - -template< - template<typename, typename> class test, - typename check_against, - typename h_list, - int default_flags, - int last_check_flags -> -struct contained_in_list_gf<test, check_against, h_list, default_flags, true, last_check_flags> -{ - constexpr static bool value = true; - constexpr static int global_flags = last_check_flags; -}; - -template< - template<typename, typename> class test, - typename check_against, - typename a, - typename... as, - int default_flags, - int last_check_flags -> -struct contained_in_list_gf<test, check_against, type_list<a, as...>, default_flags, false, last_check_flags> : contained_in_list_gf<test, check_against, type_list<as...>, default_flags, test<check_against, a>::value, test<check_against, a>::global_flags> {}; - -template< - template<typename, typename> class test, - typename check_against - EIGEN_TPL_PP_SPEC_HACK_DEFC(typename, empty), - int default_flags, - int last_check_flags -> -struct contained_in_list_gf<test, check_against, type_list<EIGEN_TPL_PP_SPEC_HACK_USE(empty)>, default_flags, false, last_check_flags> { constexpr static bool value = false; constexpr static int global_flags = default_flags; }; - -/* generic reductions */ - -template< - typename Reducer, - typename... Ts -> struct reduce; - -template< - typename Reducer -> struct reduce<Reducer> -{ - EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE int run() { return Reducer::Identity; } -}; - -template< - typename Reducer, - typename A -> struct reduce<Reducer, A> -{ - EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE A run(A a) { return a; } -}; - -template< - typename Reducer, - typename A, - typename... Ts -> struct reduce<Reducer, A, Ts...> -{ - EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, Ts... ts) -> decltype(Reducer::run(a, reduce<Reducer, Ts...>::run(ts...))) { - return Reducer::run(a, reduce<Reducer, Ts...>::run(ts...)); - } -}; - -/* generic binary operations */ - -struct sum_op { - template<typename A, typename B> EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a + b) { return a + b; } - static constexpr int Identity = 0; -}; -struct product_op { - template<typename A, typename B> EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a * b) { return a * b; } - static constexpr int Identity = 1; -}; - -struct logical_and_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a && b) { return a && b; } }; -struct logical_or_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a || b) { return a || b; } }; - -struct equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a == b) { return a == b; } }; -struct not_equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a != b) { return a != b; } }; -struct lesser_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a < b) { return a < b; } }; -struct lesser_equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a <= b) { return a <= b; } }; -struct greater_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a > b) { return a > b; } }; -struct greater_equal_op { template<typename A, typename B> constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a >= b) { return a >= b; } }; - -/* generic unary operations */ - -struct not_op { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(!a) { return !a; } }; -struct negation_op { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(-a) { return -a; } }; -struct greater_equal_zero_op { template<typename A> constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(a >= 0) { return a >= 0; } }; - - -/* reductions for lists */ - -// using auto -> return value spec makes ICC 13.0 and 13.1 crash here, so we have to hack it -// together in front... (13.0 doesn't work with array_prod/array_reduce/... anyway, but 13.1 -// does... -template<typename... Ts> -EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE decltype(reduce<product_op, Ts...>::run((*((Ts*)0))...)) arg_prod(Ts... ts) -{ - return reduce<product_op, Ts...>::run(ts...); -} - -template<typename... Ts> -constexpr EIGEN_STRONG_INLINE decltype(reduce<sum_op, Ts...>::run((*((Ts*)0))...)) arg_sum(Ts... ts) -{ - return reduce<sum_op, Ts...>::run(ts...); -} - -/* reverse arrays */ - -template<typename Array, int... n> -constexpr EIGEN_STRONG_INLINE Array h_array_reverse(Array arr, numeric_list<int, n...>) -{ - return {{array_get<sizeof...(n) - n - 1>(arr)...}}; -} - -template<typename T, std::size_t N> -constexpr EIGEN_STRONG_INLINE array<T, N> array_reverse(array<T, N> arr) -{ - return h_array_reverse(arr, typename gen_numeric_list<int, N>::type()); -} - - -/* generic array reductions */ - -// can't reuse standard reduce() interface above because Intel's Compiler -// *really* doesn't like it, so we just reimplement the stuff -// (start from N - 1 and work down to 0 because specialization for -// n == N - 1 also doesn't work in Intel's compiler, so it goes into -// an infinite loop) -template<typename Reducer, typename T, std::size_t N, std::size_t n = N - 1> -struct h_array_reduce { - EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(array<T, N> arr, T identity) -> decltype(Reducer::run(h_array_reduce<Reducer, T, N, n - 1>::run(arr, identity), array_get<n>(arr))) - { - return Reducer::run(h_array_reduce<Reducer, T, N, n - 1>::run(arr, identity), array_get<n>(arr)); - } -}; - -template<typename Reducer, typename T, std::size_t N> -struct h_array_reduce<Reducer, T, N, 0> -{ - EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE T run(const array<T, N>& arr, T) - { - return array_get<0>(arr); - } -}; - -template<typename Reducer, typename T> -struct h_array_reduce<Reducer, T, 0> -{ - EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE T run(const array<T, 0>&, T identity) - { - return identity; - } -}; - -template<typename Reducer, typename T, std::size_t N> -EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_reduce(const array<T, N>& arr, T identity) -> decltype(h_array_reduce<Reducer, T, N>::run(arr, identity)) -{ - return h_array_reduce<Reducer, T, N>::run(arr, identity); -} - -/* standard array reductions */ - -template<typename T, std::size_t N> -EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_sum(const array<T, N>& arr) -> decltype(array_reduce<sum_op, T, N>(arr, static_cast<T>(0))) -{ - return array_reduce<sum_op, T, N>(arr, static_cast<T>(0)); -} - -template<typename T, std::size_t N> -EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_prod(const array<T, N>& arr) -> decltype(array_reduce<product_op, T, N>(arr, static_cast<T>(1))) -{ - return array_reduce<product_op, T, N>(arr, static_cast<T>(1)); -} - -template<typename t> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE t array_prod(const std::vector<t>& a) { - eigen_assert(a.size() > 0); - t prod = 1; - for (size_t i = 0; i < a.size(); ++i) { prod *= a[i]; } - return prod; -} - -/* zip an array */ - -template<typename Op, typename A, typename B, std::size_t N, int... n> -constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A(), B())),N> h_array_zip(array<A, N> a, array<B, N> b, numeric_list<int, n...>) -{ - return array<decltype(Op::run(A(), B())),N>{{ Op::run(array_get<n>(a), array_get<n>(b))... }}; -} - -template<typename Op, typename A, typename B, std::size_t N> -constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A(), B())),N> array_zip(array<A, N> a, array<B, N> b) -{ - return h_array_zip<Op>(a, b, typename gen_numeric_list<int, N>::type()); -} - -/* zip an array and reduce the result */ - -template<typename Reducer, typename Op, typename A, typename B, std::size_t N, int... n> -constexpr EIGEN_STRONG_INLINE auto h_array_zip_and_reduce(array<A, N> a, array<B, N> b, numeric_list<int, n...>) -> decltype(reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A(), B()))>::type...>::run(Op::run(array_get<n>(a), array_get<n>(b))...)) -{ - return reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A(), B()))>::type...>::run(Op::run(array_get<n>(a), array_get<n>(b))...); -} - -template<typename Reducer, typename Op, typename A, typename B, std::size_t N> -constexpr EIGEN_STRONG_INLINE auto array_zip_and_reduce(array<A, N> a, array<B, N> b) -> decltype(h_array_zip_and_reduce<Reducer, Op, A, B, N>(a, b, typename gen_numeric_list<int, N>::type())) -{ - return h_array_zip_and_reduce<Reducer, Op, A, B, N>(a, b, typename gen_numeric_list<int, N>::type()); -} - -/* apply stuff to an array */ - -template<typename Op, typename A, std::size_t N, int... n> -constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A())),N> h_array_apply(array<A, N> a, numeric_list<int, n...>) -{ - return array<decltype(Op::run(A())),N>{{ Op::run(array_get<n>(a))... }}; -} - -template<typename Op, typename A, std::size_t N> -constexpr EIGEN_STRONG_INLINE array<decltype(Op::run(A())),N> array_apply(array<A, N> a) -{ - return h_array_apply<Op>(a, typename gen_numeric_list<int, N>::type()); -} - -/* apply stuff to an array and reduce */ - -template<typename Reducer, typename Op, typename A, std::size_t N, int... n> -constexpr EIGEN_STRONG_INLINE auto h_array_apply_and_reduce(array<A, N> arr, numeric_list<int, n...>) -> decltype(reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A()))>::type...>::run(Op::run(array_get<n>(arr))...)) -{ - return reduce<Reducer, typename id_numeric<int,n,decltype(Op::run(A()))>::type...>::run(Op::run(array_get<n>(arr))...); -} - -template<typename Reducer, typename Op, typename A, std::size_t N> -constexpr EIGEN_STRONG_INLINE auto array_apply_and_reduce(array<A, N> a) -> decltype(h_array_apply_and_reduce<Reducer, Op, A, N>(a, typename gen_numeric_list<int, N>::type())) -{ - return h_array_apply_and_reduce<Reducer, Op, A, N>(a, typename gen_numeric_list<int, N>::type()); -} - -/* repeat a value n times (and make an array out of it - * usage: - * array<int, 16> = repeat<16>(42); - */ - -template<int n> -struct h_repeat -{ - template<typename t, int... ii> - constexpr static EIGEN_STRONG_INLINE array<t, n> run(t v, numeric_list<int, ii...>) - { - return {{ typename id_numeric<int, ii, t>::type(v)... }}; - } -}; - -template<int n, typename t> -constexpr array<t, n> repeat(t v) { return h_repeat<n>::run(v, typename gen_numeric_list<int, n>::type()); } - -/* instantiate a class by a C-style array */ -template<class InstType, typename ArrType, std::size_t N, bool Reverse, typename... Ps> -struct h_instantiate_by_c_array; - -template<class InstType, typename ArrType, std::size_t N, typename... Ps> -struct h_instantiate_by_c_array<InstType, ArrType, N, false, Ps...> -{ - static InstType run(ArrType* arr, Ps... args) - { - return h_instantiate_by_c_array<InstType, ArrType, N - 1, false, Ps..., ArrType>::run(arr + 1, args..., arr[0]); - } -}; - -template<class InstType, typename ArrType, std::size_t N, typename... Ps> -struct h_instantiate_by_c_array<InstType, ArrType, N, true, Ps...> -{ - static InstType run(ArrType* arr, Ps... args) - { - return h_instantiate_by_c_array<InstType, ArrType, N - 1, false, ArrType, Ps...>::run(arr + 1, arr[0], args...); - } -}; - -template<class InstType, typename ArrType, typename... Ps> -struct h_instantiate_by_c_array<InstType, ArrType, 0, false, Ps...> -{ - static InstType run(ArrType* arr, Ps... args) - { - (void)arr; - return InstType(args...); - } -}; - -template<class InstType, typename ArrType, typename... Ps> -struct h_instantiate_by_c_array<InstType, ArrType, 0, true, Ps...> -{ - static InstType run(ArrType* arr, Ps... args) - { - (void)arr; - return InstType(args...); - } -}; - -template<class InstType, typename ArrType, std::size_t N, bool Reverse = false> -InstType instantiate_by_c_array(ArrType* arr) -{ - return h_instantiate_by_c_array<InstType, ArrType, N, Reverse>::run(arr); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CXX11META_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/CXX11Workarounds.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/CXX11Workarounds.h deleted file mode 100644 index f1c0284e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/CXX11Workarounds.h +++ /dev/null @@ -1,88 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler <christian@iwakd.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_CXX11WORKAROUNDS_H -#define EIGEN_CXX11WORKAROUNDS_H - -/* COMPATIBILITY CHECKS - * (so users of compilers that are too old get some realistic error messages) - */ -#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1310) -#error Intel Compiler only supports required C++ features since version 13.1. -// note that most stuff in principle works with 13.0 but when combining -// some features, at some point 13.0 will just fail with an internal assertion -#elif defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) -// G++ < 4.6 by default will continue processing the source files - even if we use #error to make -// it error out. For this reason, we use the pragma to make sure G++ aborts at the first error -// it sees. Unfortunately, that is still not our #error directive, but at least the output is -// short enough the user has a chance to see that the compiler version is not sufficient for -// the funky template mojo we use. -#pragma GCC diagnostic error "-Wfatal-errors" -#error GNU C++ Compiler (g++) only supports required C++ features since version 4.6. -#endif - -/* Check that the compiler at least claims to support C++11. It might not be sufficient - * because the compiler may not implement it correctly, but at least we'll know. - * On the other hand, visual studio still doesn't claim to support C++11 although it's - * compliant enugh for our purpose. - */ -#if (__cplusplus <= 199711L) && (EIGEN_COMP_MSVC < 1900) -#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) -#pragma GCC diagnostic error "-Wfatal-errors" -#endif -#error This library needs at least a C++11 compliant compiler. If you use g++/clang, please enable the -std=c++11 compiler flag. (-std=c++0x on older versions.) -#endif - -namespace Eigen { - -namespace internal { - -/* std::get is only constexpr in C++14, not yet in C++11 - */ - - -template<std::size_t I_, class T> constexpr inline T& array_get(std::vector<T>& a) { return a[I_]; } -template<std::size_t I_, class T> constexpr inline T&& array_get(std::vector<T>&& a) { return a[I_]; } -template<std::size_t I_, class T> constexpr inline T const& array_get(std::vector<T> const& a) { return a[I_]; } - -/* Suppose you have a template of the form - * template<typename T> struct X; - * And you want to specialize it in such a way: - * template<typename S1, typename... SN> struct X<Foo<S1, SN...>> { ::: }; - * template<> struct X<Foo<>> { ::: }; - * This will work in Intel's compiler 13.0, but only to some extent in g++ 4.6, since - * g++ can only match templates called with parameter packs if the number of template - * arguments is not a fixed size (so inside the first specialization, referencing - * X<Foo<Sn...>> will fail in g++). On the other hand, g++ will accept the following: - * template<typename S...> struct X<Foo<S...>> { ::: }: - * as an additional (!) specialization, which will then only match the empty case. - * But Intel's compiler 13.0 won't accept that, it will only accept the empty syntax, - * so we have to create a workaround for this. - */ -#if defined(__GNUC__) && !defined(__INTEL_COMPILER) -#define EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n) mt... n -#define EIGEN_TPL_PP_SPEC_HACK_DEFC(mt, n) , EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n) -#define EIGEN_TPL_PP_SPEC_HACK_USE(n) n... -#define EIGEN_TPL_PP_SPEC_HACK_USEC(n) , n... -#else -#define EIGEN_TPL_PP_SPEC_HACK_DEF(mt, n) -#define EIGEN_TPL_PP_SPEC_HACK_DEFC(mt, n) -#define EIGEN_TPL_PP_SPEC_HACK_USE(n) -#define EIGEN_TPL_PP_SPEC_HACK_USEC(n) -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CXX11WORKAROUNDS_H - -/* - * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; - */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/EmulateArray.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/EmulateArray.h deleted file mode 100644 index 834b20b5..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/EmulateArray.h +++ /dev/null @@ -1,261 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_EMULATE_ARRAY_H -#define EIGEN_EMULATE_ARRAY_H - - - -// The array class is only available starting with cxx11. Emulate our own here -// if needed. Beware, msvc still doesn't advertise itself as a c++11 compiler! -// Moreover, CUDA doesn't support the STL containers, so we use our own instead. -#if (__cplusplus <= 199711L && EIGEN_COMP_MSVC < 1900) || defined(EIGEN_GPUCC) || defined(EIGEN_AVOID_STL_ARRAY) - -namespace Eigen { -template <typename T, size_t n> class array { - public: - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE T& operator[] (size_t index) { eigen_internal_assert(index < size()); return values[index]; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const T& operator[] (size_t index) const { eigen_internal_assert(index < size()); return values[index]; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE T& at(size_t index) { eigen_assert(index < size()); return values[index]; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const T& at(size_t index) const { eigen_assert(index < size()); return values[index]; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE T& front() { return values[0]; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const T& front() const { return values[0]; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE T& back() { return values[n-1]; } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const T& back() const { return values[n-1]; } - - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - static std::size_t size() { return n; } - - T values[n]; - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array() { } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array(const T& v) { - EIGEN_STATIC_ASSERT(n==1, YOU_MADE_A_PROGRAMMING_MISTAKE) - values[0] = v; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array(const T& v1, const T& v2) { - EIGEN_STATIC_ASSERT(n==2, YOU_MADE_A_PROGRAMMING_MISTAKE) - values[0] = v1; - values[1] = v2; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3) { - EIGEN_STATIC_ASSERT(n==3, YOU_MADE_A_PROGRAMMING_MISTAKE) - values[0] = v1; - values[1] = v2; - values[2] = v3; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, - const T& v4) { - EIGEN_STATIC_ASSERT(n==4, YOU_MADE_A_PROGRAMMING_MISTAKE) - values[0] = v1; - values[1] = v2; - values[2] = v3; - values[3] = v4; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5) { - EIGEN_STATIC_ASSERT(n==5, YOU_MADE_A_PROGRAMMING_MISTAKE) - values[0] = v1; - values[1] = v2; - values[2] = v3; - values[3] = v4; - values[4] = v5; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5, const T& v6) { - EIGEN_STATIC_ASSERT(n==6, YOU_MADE_A_PROGRAMMING_MISTAKE) - values[0] = v1; - values[1] = v2; - values[2] = v3; - values[3] = v4; - values[4] = v5; - values[5] = v6; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array(const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5, const T& v6, const T& v7) { - EIGEN_STATIC_ASSERT(n==7, YOU_MADE_A_PROGRAMMING_MISTAKE) - values[0] = v1; - values[1] = v2; - values[2] = v3; - values[3] = v4; - values[4] = v5; - values[5] = v6; - values[6] = v7; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array( - const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5, const T& v6, const T& v7, const T& v8) { - EIGEN_STATIC_ASSERT(n==8, YOU_MADE_A_PROGRAMMING_MISTAKE) - values[0] = v1; - values[1] = v2; - values[2] = v3; - values[3] = v4; - values[4] = v5; - values[5] = v6; - values[6] = v7; - values[7] = v8; - } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array(std::initializer_list<T> l) { - eigen_assert(l.size() == n); - internal::smart_copy(l.begin(), l.end(), values); - } -#endif -}; - - -// Specialize array for zero size -template <typename T> class array<T, 0> { - public: - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE T& operator[] (size_t) { - eigen_assert(false && "Can't index a zero size array"); - return dummy; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const T& operator[] (size_t) const { - eigen_assert(false && "Can't index a zero size array"); - return dummy; - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE T& front() { - eigen_assert(false && "Can't index a zero size array"); - return dummy; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const T& front() const { - eigen_assert(false && "Can't index a zero size array"); - return dummy; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE T& back() { - eigen_assert(false && "Can't index a zero size array"); - return dummy; - } - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const T& back() const { - eigen_assert(false && "Can't index a zero size array"); - return dummy; - } - - static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE std::size_t size() { return 0; } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE array() : dummy() { } - -#if EIGEN_HAS_VARIADIC_TEMPLATES - EIGEN_DEVICE_FUNC array(std::initializer_list<T> l) : dummy() { - EIGEN_UNUSED_VARIABLE(l); - eigen_assert(l.size() == 0); - } -#endif - - private: - T dummy; -}; - -// Comparison operator -// Todo: implement !=, <, <=, >, and >= -template<class T, std::size_t N> -EIGEN_DEVICE_FUNC bool operator==(const array<T,N>& lhs, const array<T,N>& rhs) { - for (std::size_t i = 0; i < N; ++i) { - if (lhs[i] != rhs[i]) { - return false; - } - } - return true; -} - - -namespace internal { -template<std::size_t I_, class T, std::size_t N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& array_get(array<T,N>& a) { - return a[I_]; -} -template<std::size_t I_, class T, std::size_t N> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& array_get(const array<T,N>& a) { - return a[I_]; -} - -template<class T, std::size_t N> struct array_size<array<T,N> > { - enum { value = N }; -}; -template<class T, std::size_t N> struct array_size<array<T,N>& > { - enum { value = N }; -}; -template<class T, std::size_t N> struct array_size<const array<T,N> > { - enum { value = N }; -}; -template<class T, std::size_t N> struct array_size<const array<T,N>& > { - enum { value = N }; -}; - -} // end namespace internal -} // end namespace Eigen - -#else - -// The compiler supports c++11, and we're not targeting cuda: use std::array as Eigen::array -#include <array> -namespace Eigen { - -template <typename T, std::size_t N> using array = std::array<T, N>; - -namespace internal { -/* std::get is only constexpr in C++14, not yet in C++11 - * - libstdc++ from version 4.7 onwards has it nevertheless, - * so use that - * - libstdc++ older versions: use _M_instance directly - * - libc++ all versions so far: use __elems_ directly - * - all other libs: use std::get to be portable, but - * this may not be constexpr - */ -#if defined(__GLIBCXX__) && __GLIBCXX__ < 20120322 -#define STD_GET_ARR_HACK a._M_instance[I_] -#elif defined(_LIBCPP_VERSION) -#define STD_GET_ARR_HACK a.__elems_[I_] -#else -#define STD_GET_ARR_HACK std::template get<I_, T, N>(a) -#endif - -template<std::size_t I_, class T, std::size_t N> constexpr inline T& array_get(std::array<T,N>& a) { return (T&) STD_GET_ARR_HACK; } -template<std::size_t I_, class T, std::size_t N> constexpr inline T&& array_get(std::array<T,N>&& a) { return (T&&) STD_GET_ARR_HACK; } -template<std::size_t I_, class T, std::size_t N> constexpr inline T const& array_get(std::array<T,N> const& a) { return (T const&) STD_GET_ARR_HACK; } - -#undef STD_GET_ARR_HACK - -} // end namespace internal -} // end namespace Eigen - -#endif - -#endif // EIGEN_EMULATE_ARRAY_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h b/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h deleted file mode 100644 index 277ab149..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h +++ /dev/null @@ -1,158 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_FIXEDSIZEVECTOR_H -#define EIGEN_FIXEDSIZEVECTOR_H - -namespace Eigen { - -/** \class MaxSizeVector - * \ingroup Core - * - * \brief The MaxSizeVector class. - * - * The %MaxSizeVector provides a subset of std::vector functionality. - * - * The goal is to provide basic std::vector operations when using - * std::vector is not an option (e.g. on GPU or when compiling using - * FMA/AVX, as this can cause either compilation failures or illegal - * instruction failures). - * - * Beware: The constructors are not API compatible with these of - * std::vector. - */ -template <typename T> -class MaxSizeVector { - static const size_t alignment = EIGEN_PLAIN_ENUM_MAX(EIGEN_ALIGNOF(T), sizeof(void*)); - public: - // Construct a new MaxSizeVector, reserve n elements. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - explicit MaxSizeVector(size_t n) - : reserve_(n), size_(0), - data_(static_cast<T*>(internal::handmade_aligned_malloc(n * sizeof(T), alignment))) { - } - - // Construct a new MaxSizeVector, reserve and resize to n. - // Copy the init value to all elements. - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - MaxSizeVector(size_t n, const T& init) - : reserve_(n), size_(n), - data_(static_cast<T*>(internal::handmade_aligned_malloc(n * sizeof(T), alignment))) { - size_t i = 0; - EIGEN_TRY - { - for(; i < size_; ++i) { new (&data_[i]) T(init); } - } - EIGEN_CATCH(...) - { - // Construction failed, destruct in reverse order: - for(; (i+1) > 0; --i) { data_[i-1].~T(); } - internal::handmade_aligned_free(data_); - EIGEN_THROW; - } - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - ~MaxSizeVector() { - for (size_t i = size_; i > 0; --i) { - data_[i-1].~T(); - } - internal::handmade_aligned_free(data_); - } - - void resize(size_t n) { - eigen_assert(n <= reserve_); - for (; size_ < n; ++size_) { - new (&data_[size_]) T; - } - for (; size_ > n; --size_) { - data_[size_-1].~T(); - } - eigen_assert(size_ == n); - } - - // Append new elements (up to reserved size). - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void push_back(const T& t) { - eigen_assert(size_ < reserve_); - new (&data_[size_++]) T(t); - } - - // For C++03 compatibility this only takes one argument - template<class X> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void emplace_back(const X& x) { - eigen_assert(size_ < reserve_); - new (&data_[size_++]) T(x); - } - - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const T& operator[] (size_t i) const { - eigen_assert(i < size_); - return data_[i]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - T& operator[] (size_t i) { - eigen_assert(i < size_); - return data_[i]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - T& back() { - eigen_assert(size_ > 0); - return data_[size_ - 1]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const T& back() const { - eigen_assert(size_ > 0); - return data_[size_ - 1]; - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - void pop_back() { - eigen_assert(size_ > 0); - data_[--size_].~T(); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - size_t size() const { return size_; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - bool empty() const { return size_ == 0; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - T* data() { return data_; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const T* data() const { return data_; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - T* begin() { return data_; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - T* end() { return data_ + size_; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const T* begin() const { return data_; } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - const T* end() const { return data_ + size_; } - - private: - size_t reserve_; - size_t size_; - T* data_; -}; - -} // namespace Eigen - -#endif // EIGEN_FIXEDSIZEVECTOR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/EulerAngles b/external/eigen/include/eigen3/unsupported/Eigen/EulerAngles deleted file mode 100644 index f8f1c5d0..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/EulerAngles +++ /dev/null @@ -1,43 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Tal Hadad <tal_hd@hotmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_EULERANGLES_MODULE_H -#define EIGEN_EULERANGLES_MODULE_H - - -#include "../../Eigen/Core" -#include "../../Eigen/Geometry" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -namespace Eigen { - -/** - * \defgroup EulerAngles_Module EulerAngles module - * \brief This module provides generic euler angles rotation. - * - * Euler angles are a way to represent 3D rotation. - * - * In order to use this module in your code, include this header: - * \code - * #include <unsupported/Eigen/EulerAngles> - * \endcode - * - * See \ref EulerAngles for more information. - * - */ - -} - -#include "src/EulerAngles/EulerSystem.h" -#include "src/EulerAngles/EulerAngles.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_EULERANGLES_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/FFT b/external/eigen/include/eigen3/unsupported/Eigen/FFT deleted file mode 100644 index d9ad21a5..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/FFT +++ /dev/null @@ -1,424 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Mark Borgerding mark a borgerding net -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_FFT_H -#define EIGEN_FFT_H - -#include <complex> -#include <vector> -#include <map> -#include "../../Eigen/Core" - - -/** - * \defgroup FFT_Module Fast Fourier Transform module - * - * \code - * #include <unsupported/Eigen/FFT> - * \endcode - * - * This module provides Fast Fourier transformation, with a configurable backend - * implementation. - * - * The default implementation is based on kissfft. It is a small, free, and - * reasonably efficient default. - * - * There are currently two implementation backend: - * - * - fftw (http://www.fftw.org) : faster, GPL -- incompatible with Eigen in LGPL form, bigger code size. - * - MKL (http://en.wikipedia.org/wiki/Math_Kernel_Library) : fastest, commercial -- may be incompatible with Eigen in GPL form. - * - * \section FFTDesign Design - * - * The following design decisions were made concerning scaling and - * half-spectrum for real FFT. - * - * The intent is to facilitate generic programming and ease migrating code - * from Matlab/octave. - * We think the default behavior of Eigen/FFT should favor correctness and - * generality over speed. Of course, the caller should be able to "opt-out" from this - * behavior and get the speed increase if they want it. - * - * 1) %Scaling: - * Other libraries (FFTW,IMKL,KISSFFT) do not perform scaling, so there - * is a constant gain incurred after the forward&inverse transforms , so - * IFFT(FFT(x)) = Kx; this is done to avoid a vector-by-value multiply. - * The downside is that algorithms that worked correctly in Matlab/octave - * don't behave the same way once implemented in C++. - * - * How Eigen/FFT differs: invertible scaling is performed so IFFT( FFT(x) ) = x. - * - * 2) Real FFT half-spectrum - * Other libraries use only half the frequency spectrum (plus one extra - * sample for the Nyquist bin) for a real FFT, the other half is the - * conjugate-symmetric of the first half. This saves them a copy and some - * memory. The downside is the caller needs to have special logic for the - * number of bins in complex vs real. - * - * How Eigen/FFT differs: The full spectrum is returned from the forward - * transform. This facilitates generic template programming by obviating - * separate specializations for real vs complex. On the inverse - * transform, only half the spectrum is actually used if the output type is real. - */ - - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#ifdef EIGEN_FFTW_DEFAULT -// FFTW: faster, GPL -- incompatible with Eigen in LGPL form, bigger code size -# include <fftw3.h> -# include "src/FFT/ei_fftw_impl.h" - namespace Eigen { - //template <typename T> typedef struct internal::fftw_impl default_fft_impl; this does not work - template <typename T> struct default_fft_impl : public internal::fftw_impl<T> {}; - } -#elif defined EIGEN_MKL_DEFAULT -// TODO -// intel Math Kernel Library: fastest, commercial -- may be incompatible with Eigen in GPL form -# include "src/FFT/ei_imklfft_impl.h" - namespace Eigen { - template <typename T> struct default_fft_impl : public internal::imklfft_impl {}; - } -#else -// internal::kissfft_impl: small, free, reasonably efficient default, derived from kissfft -// -# include "src/FFT/ei_kissfft_impl.h" - namespace Eigen { - template <typename T> - struct default_fft_impl : public internal::kissfft_impl<T> {}; - } -#endif - -namespace Eigen { - - -// -template<typename T_SrcMat,typename T_FftIfc> struct fft_fwd_proxy; -template<typename T_SrcMat,typename T_FftIfc> struct fft_inv_proxy; - -namespace internal { -template<typename T_SrcMat,typename T_FftIfc> -struct traits< fft_fwd_proxy<T_SrcMat,T_FftIfc> > -{ - typedef typename T_SrcMat::PlainObject ReturnType; -}; -template<typename T_SrcMat,typename T_FftIfc> -struct traits< fft_inv_proxy<T_SrcMat,T_FftIfc> > -{ - typedef typename T_SrcMat::PlainObject ReturnType; -}; -} - -template<typename T_SrcMat,typename T_FftIfc> -struct fft_fwd_proxy - : public ReturnByValue<fft_fwd_proxy<T_SrcMat,T_FftIfc> > -{ - typedef DenseIndex Index; - - fft_fwd_proxy(const T_SrcMat& src,T_FftIfc & fft, Index nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {} - - template<typename T_DestMat> void evalTo(T_DestMat& dst) const; - - Index rows() const { return m_src.rows(); } - Index cols() const { return m_src.cols(); } -protected: - const T_SrcMat & m_src; - T_FftIfc & m_ifc; - Index m_nfft; -private: - fft_fwd_proxy& operator=(const fft_fwd_proxy&); -}; - -template<typename T_SrcMat,typename T_FftIfc> -struct fft_inv_proxy - : public ReturnByValue<fft_inv_proxy<T_SrcMat,T_FftIfc> > -{ - typedef DenseIndex Index; - - fft_inv_proxy(const T_SrcMat& src,T_FftIfc & fft, Index nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {} - - template<typename T_DestMat> void evalTo(T_DestMat& dst) const; - - Index rows() const { return m_src.rows(); } - Index cols() const { return m_src.cols(); } -protected: - const T_SrcMat & m_src; - T_FftIfc & m_ifc; - Index m_nfft; -private: - fft_inv_proxy& operator=(const fft_inv_proxy&); -}; - - -template <typename T_Scalar, - typename T_Impl=default_fft_impl<T_Scalar> > -class FFT -{ - public: - typedef T_Impl impl_type; - typedef DenseIndex Index; - typedef typename impl_type::Scalar Scalar; - typedef typename impl_type::Complex Complex; - - enum Flag { - Default=0, // goof proof - Unscaled=1, - HalfSpectrum=2, - // SomeOtherSpeedOptimization=4 - Speedy=32767 - }; - - FFT( const impl_type & impl=impl_type() , Flag flags=Default ) :m_impl(impl),m_flag(flags) { } - - inline - bool HasFlag(Flag f) const { return (m_flag & (int)f) == f;} - - inline - void SetFlag(Flag f) { m_flag |= (int)f;} - - inline - void ClearFlag(Flag f) { m_flag &= (~(int)f);} - - inline - void fwd( Complex * dst, const Scalar * src, Index nfft) - { - m_impl.fwd(dst,src,static_cast<int>(nfft)); - if ( HasFlag(HalfSpectrum) == false) - ReflectSpectrum(dst,nfft); - } - - inline - void fwd( Complex * dst, const Complex * src, Index nfft) - { - m_impl.fwd(dst,src,static_cast<int>(nfft)); - } - - /* - inline - void fwd2(Complex * dst, const Complex * src, int n0,int n1) - { - m_impl.fwd2(dst,src,n0,n1); - } - */ - - template <typename _Input> - inline - void fwd( std::vector<Complex> & dst, const std::vector<_Input> & src) - { - if ( NumTraits<_Input>::IsComplex == 0 && HasFlag(HalfSpectrum) ) - dst.resize( (src.size()>>1)+1); // half the bins + Nyquist bin - else - dst.resize(src.size()); - fwd(&dst[0],&src[0],src.size()); - } - - template<typename InputDerived, typename ComplexDerived> - inline - void fwd( MatrixBase<ComplexDerived> & dst, const MatrixBase<InputDerived> & src, Index nfft=-1) - { - typedef typename ComplexDerived::Scalar dst_type; - typedef typename InputDerived::Scalar src_type; - EIGEN_STATIC_ASSERT_VECTOR_ONLY(InputDerived) - EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived) - EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ComplexDerived,InputDerived) // size at compile-time - EIGEN_STATIC_ASSERT((internal::is_same<dst_type, Complex>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - EIGEN_STATIC_ASSERT(int(InputDerived::Flags)&int(ComplexDerived::Flags)&DirectAccessBit, - THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES) - - if (nfft<1) - nfft = src.size(); - - if ( NumTraits< src_type >::IsComplex == 0 && HasFlag(HalfSpectrum) ) - dst.derived().resize( (nfft>>1)+1); - else - dst.derived().resize(nfft); - - if ( src.innerStride() != 1 || src.size() < nfft ) { - Matrix<src_type,1,Dynamic> tmp; - if (src.size()<nfft) { - tmp.setZero(nfft); - tmp.block(0,0,src.size(),1 ) = src; - }else{ - tmp = src; - } - fwd( &dst[0],&tmp[0],nfft ); - }else{ - fwd( &dst[0],&src[0],nfft ); - } - } - - template<typename InputDerived> - inline - fft_fwd_proxy< MatrixBase<InputDerived>, FFT<T_Scalar,T_Impl> > - fwd( const MatrixBase<InputDerived> & src, Index nfft=-1) - { - return fft_fwd_proxy< MatrixBase<InputDerived> ,FFT<T_Scalar,T_Impl> >( src, *this,nfft ); - } - - template<typename InputDerived> - inline - fft_inv_proxy< MatrixBase<InputDerived>, FFT<T_Scalar,T_Impl> > - inv( const MatrixBase<InputDerived> & src, Index nfft=-1) - { - return fft_inv_proxy< MatrixBase<InputDerived> ,FFT<T_Scalar,T_Impl> >( src, *this,nfft ); - } - - inline - void inv( Complex * dst, const Complex * src, Index nfft) - { - m_impl.inv( dst,src,static_cast<int>(nfft) ); - if ( HasFlag( Unscaled ) == false) - scale(dst,Scalar(1./nfft),nfft); // scale the time series - } - - inline - void inv( Scalar * dst, const Complex * src, Index nfft) - { - m_impl.inv( dst,src,static_cast<int>(nfft) ); - if ( HasFlag( Unscaled ) == false) - scale(dst,Scalar(1./nfft),nfft); // scale the time series - } - - template<typename OutputDerived, typename ComplexDerived> - inline - void inv( MatrixBase<OutputDerived> & dst, const MatrixBase<ComplexDerived> & src, Index nfft=-1) - { - typedef typename ComplexDerived::Scalar src_type; - typedef typename ComplexDerived::RealScalar real_type; - typedef typename OutputDerived::Scalar dst_type; - const bool realfft= (NumTraits<dst_type>::IsComplex == 0); - EIGEN_STATIC_ASSERT_VECTOR_ONLY(OutputDerived) - EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived) - EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ComplexDerived,OutputDerived) // size at compile-time - EIGEN_STATIC_ASSERT((internal::is_same<src_type, Complex>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - EIGEN_STATIC_ASSERT(int(OutputDerived::Flags)&int(ComplexDerived::Flags)&DirectAccessBit, - THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES) - - if (nfft<1) { //automatic FFT size determination - if ( realfft && HasFlag(HalfSpectrum) ) - nfft = 2*(src.size()-1); //assume even fft size - else - nfft = src.size(); - } - dst.derived().resize( nfft ); - - // check for nfft that does not fit the input data size - Index resize_input= ( realfft && HasFlag(HalfSpectrum) ) - ? ( (nfft/2+1) - src.size() ) - : ( nfft - src.size() ); - - if ( src.innerStride() != 1 || resize_input ) { - // if the vector is strided, then we need to copy it to a packed temporary - Matrix<src_type,1,Dynamic> tmp; - if ( resize_input ) { - size_t ncopy = (std::min)(src.size(),src.size() + resize_input); - tmp.setZero(src.size() + resize_input); - if ( realfft && HasFlag(HalfSpectrum) ) { - // pad at the Nyquist bin - tmp.head(ncopy) = src.head(ncopy); - tmp(ncopy-1) = real(tmp(ncopy-1)); // enforce real-only Nyquist bin - }else{ - size_t nhead,ntail; - nhead = 1+ncopy/2-1; // range [0:pi) - ntail = ncopy/2-1; // range (-pi:0) - tmp.head(nhead) = src.head(nhead); - tmp.tail(ntail) = src.tail(ntail); - if (resize_input<0) { //shrinking -- create the Nyquist bin as the average of the two bins that fold into it - tmp(nhead) = ( src(nfft/2) + src( src.size() - nfft/2 ) )*real_type(.5); - }else{ // expanding -- split the old Nyquist bin into two halves - tmp(nhead) = src(nhead) * real_type(.5); - tmp(tmp.size()-nhead) = tmp(nhead); - } - } - }else{ - tmp = src; - } - inv( &dst[0],&tmp[0], nfft); - }else{ - inv( &dst[0],&src[0], nfft); - } - } - - template <typename _Output> - inline - void inv( std::vector<_Output> & dst, const std::vector<Complex> & src,Index nfft=-1) - { - if (nfft<1) - nfft = ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) ) ? 2*(src.size()-1) : src.size(); - dst.resize( nfft ); - inv( &dst[0],&src[0],nfft); - } - - - /* - // TODO: multi-dimensional FFTs - inline - void inv2(Complex * dst, const Complex * src, int n0,int n1) - { - m_impl.inv2(dst,src,n0,n1); - if ( HasFlag( Unscaled ) == false) - scale(dst,1./(n0*n1),n0*n1); - } - */ - - inline - impl_type & impl() {return m_impl;} - private: - - template <typename T_Data> - inline - void scale(T_Data * x,Scalar s,Index nx) - { -#if 1 - for (int k=0;k<nx;++k) - *x++ *= s; -#else - if ( ((ptrdiff_t)x) & 15 ) - Matrix<T_Data, Dynamic, 1>::Map(x,nx) *= s; - else - Matrix<T_Data, Dynamic, 1>::MapAligned(x,nx) *= s; - //Matrix<T_Data, Dynamic, Dynamic>::Map(x,nx) * s; -#endif - } - - inline - void ReflectSpectrum(Complex * freq, Index nfft) - { - // create the implicit right-half spectrum (conjugate-mirror of the left-half) - Index nhbins=(nfft>>1)+1; - for (Index k=nhbins;k < nfft; ++k ) - freq[k] = conj(freq[nfft-k]); - } - - impl_type m_impl; - int m_flag; -}; - -template<typename T_SrcMat,typename T_FftIfc> -template<typename T_DestMat> inline -void fft_fwd_proxy<T_SrcMat,T_FftIfc>::evalTo(T_DestMat& dst) const -{ - m_ifc.fwd( dst, m_src, m_nfft); -} - -template<typename T_SrcMat,typename T_FftIfc> -template<typename T_DestMat> inline -void fft_inv_proxy<T_SrcMat,T_FftIfc>::evalTo(T_DestMat& dst) const -{ - m_ifc.inv( dst, m_src, m_nfft); -} - -} - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/IterativeSolvers b/external/eigen/include/eigen3/unsupported/Eigen/IterativeSolvers deleted file mode 100644 index 0fa129a7..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/IterativeSolvers +++ /dev/null @@ -1,46 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <g.gael@free.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ITERATIVE_SOLVERS_MODULE_H -#define EIGEN_ITERATIVE_SOLVERS_MODULE_H - -#include "../../Eigen/Sparse" -#include "../../Eigen/Jacobi" -#include "../../Eigen/Householder" - -/** - * \defgroup IterativeSolvers_Module Iterative solvers module - * This module aims to provide various iterative linear and non linear solver algorithms. - * It currently provides: - * - a constrained conjugate gradient - * - a Householder GMRES implementation - * \code - * #include <unsupported/Eigen/IterativeSolvers> - * \endcode - */ -//@{ - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#ifndef EIGEN_MPL2_ONLY -#include "src/IterativeSolvers/IterationController.h" -#include "src/IterativeSolvers/ConstrainedConjGrad.h" -#endif - -#include "src/IterativeSolvers/IncompleteLU.h" -#include "src/IterativeSolvers/GMRES.h" -#include "src/IterativeSolvers/DGMRES.h" -//#include "src/IterativeSolvers/SSORPreconditioner.h" -#include "src/IterativeSolvers/MINRES.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -//@} - -#endif // EIGEN_ITERATIVE_SOLVERS_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/KroneckerProduct b/external/eigen/include/eigen3/unsupported/Eigen/KroneckerProduct deleted file mode 100644 index 5f5afb8c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/KroneckerProduct +++ /dev/null @@ -1,36 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_KRONECKER_PRODUCT_MODULE_H -#define EIGEN_KRONECKER_PRODUCT_MODULE_H - -#include "../../Eigen/Core" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#include "../../Eigen/src/SparseCore/SparseUtil.h" - -namespace Eigen { - -/** - * \defgroup KroneckerProduct_Module KroneckerProduct module - * - * This module contains an experimental Kronecker product implementation. - * - * \code - * #include <Eigen/KroneckerProduct> - * \endcode - */ - -} // namespace Eigen - -#include "src/KroneckerProduct/KroneckerTensorProduct.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_KRONECKER_PRODUCT_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/LevenbergMarquardt b/external/eigen/include/eigen3/unsupported/Eigen/LevenbergMarquardt deleted file mode 100644 index 10905050..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/LevenbergMarquardt +++ /dev/null @@ -1,49 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_LEVENBERGMARQUARDT_MODULE -#define EIGEN_LEVENBERGMARQUARDT_MODULE - -// #include <vector> - -#include "../../Eigen/Core" -#include "../../Eigen/Jacobi" -#include "../../Eigen/QR" -#include "NumericalDiff" - -#include "../../Eigen/SparseQR" - -/** - * \defgroup LevenbergMarquardt_Module Levenberg-Marquardt module - * - * \code - * #include </Eigen/LevenbergMarquardt> - * \endcode - * - * - */ - -#include "../../Eigen/SparseCore" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -#include "src/LevenbergMarquardt/LMqrsolv.h" -#include "src/LevenbergMarquardt/LMcovar.h" -#include "src/LevenbergMarquardt/LMpar.h" - -#endif - -#include "src/LevenbergMarquardt/LevenbergMarquardt.h" -#include "src/LevenbergMarquardt/LMonestep.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_LEVENBERGMARQUARDT_MODULE diff --git a/external/eigen/include/eigen3/unsupported/Eigen/MPRealSupport b/external/eigen/include/eigen3/unsupported/Eigen/MPRealSupport deleted file mode 100644 index c4ea4ec5..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/MPRealSupport +++ /dev/null @@ -1,213 +0,0 @@ -// This file is part of a joint effort between Eigen, a lightweight C++ template library -// for linear algebra, and MPFR C++, a C++ interface to MPFR library (http://www.holoborodko.com/pavel/) -// -// Copyright (C) 2010-2012 Pavel Holoborodko <pavel@holoborodko.com> -// Copyright (C) 2010 Konstantin Holoborodko <konstantin@holoborodko.com> -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MPREALSUPPORT_MODULE_H -#define EIGEN_MPREALSUPPORT_MODULE_H - -#include "../../Eigen/Core" -#include <mpreal.h> - -namespace Eigen { - -/** - * \defgroup MPRealSupport_Module MPFRC++ Support module - * \code - * #include <Eigen/MPRealSupport> - * \endcode - * - * This module provides support for multi precision floating point numbers - * via the <a href="http://www.holoborodko.com/pavel/mpfr">MPFR C++</a> - * library which itself is built upon <a href="http://www.mpfr.org/">MPFR</a>/<a href="http://gmplib.org/">GMP</a>. - * - * \warning MPFR C++ is licensed under the GPL. - * - * You can find a copy of MPFR C++ that is known to be compatible in the unsupported/test/mpreal folder. - * - * Here is an example: - * -\code -#include <iostream> -#include <Eigen/MPRealSupport> -#include <Eigen/LU> -using namespace mpfr; -using namespace Eigen; -int main() -{ - // set precision to 256 bits (double has only 53 bits) - mpreal::set_default_prec(256); - // Declare matrix and vector types with multi-precision scalar type - typedef Matrix<mpreal,Dynamic,Dynamic> MatrixXmp; - typedef Matrix<mpreal,Dynamic,1> VectorXmp; - - MatrixXmp A = MatrixXmp::Random(100,100); - VectorXmp b = VectorXmp::Random(100); - - // Solve Ax=b using LU - VectorXmp x = A.lu().solve(b); - std::cout << "relative error: " << (A*x - b).norm() / b.norm() << std::endl; - return 0; -} -\endcode - * - */ - - template<> struct NumTraits<mpfr::mpreal> - : GenericNumTraits<mpfr::mpreal> - { - enum { - IsInteger = 0, - IsSigned = 1, - IsComplex = 0, - RequireInitialization = 1, - ReadCost = HugeCost, - AddCost = HugeCost, - MulCost = HugeCost - }; - - typedef mpfr::mpreal Real; - typedef mpfr::mpreal NonInteger; - - static inline Real highest (long Precision = mpfr::mpreal::get_default_prec()) { return mpfr::maxval(Precision); } - static inline Real lowest (long Precision = mpfr::mpreal::get_default_prec()) { return -mpfr::maxval(Precision); } - - // Constants - static inline Real Pi (long Precision = mpfr::mpreal::get_default_prec()) { return mpfr::const_pi(Precision); } - static inline Real Euler (long Precision = mpfr::mpreal::get_default_prec()) { return mpfr::const_euler(Precision); } - static inline Real Log2 (long Precision = mpfr::mpreal::get_default_prec()) { return mpfr::const_log2(Precision); } - static inline Real Catalan (long Precision = mpfr::mpreal::get_default_prec()) { return mpfr::const_catalan(Precision); } - - static inline Real epsilon (long Precision = mpfr::mpreal::get_default_prec()) { return mpfr::machine_epsilon(Precision); } - static inline Real epsilon (const Real& x) { return mpfr::machine_epsilon(x); } - -#ifdef MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS - static inline int digits10 (long Precision = mpfr::mpreal::get_default_prec()) { return std::numeric_limits<Real>::digits10(Precision); } - static inline int digits10 (const Real& x) { return std::numeric_limits<Real>::digits10(x); } - - static inline int digits () { return std::numeric_limits<Real>::digits(); } - static inline int digits (const Real& x) { return std::numeric_limits<Real>::digits(x); } -#endif - - static inline Real dummy_precision() - { - mpfr_prec_t weak_prec = ((mpfr::mpreal::get_default_prec()-1) * 90) / 100; - return mpfr::machine_epsilon(weak_prec); - } - }; - - namespace internal { - - template<> inline mpfr::mpreal random<mpfr::mpreal>() - { - return mpfr::random(); - } - - template<> inline mpfr::mpreal random<mpfr::mpreal>(const mpfr::mpreal& a, const mpfr::mpreal& b) - { - return a + (b-a) * random<mpfr::mpreal>(); - } - - inline bool isMuchSmallerThan(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& eps) - { - return mpfr::abs(a) <= mpfr::abs(b) * eps; - } - - inline bool isApprox(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& eps) - { - return mpfr::isEqualFuzzy(a,b,eps); - } - - inline bool isApproxOrLessThan(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& eps) - { - return a <= b || mpfr::isEqualFuzzy(a,b,eps); - } - - template<> inline long double cast<mpfr::mpreal,long double>(const mpfr::mpreal& x) - { return x.toLDouble(); } - - template<> inline double cast<mpfr::mpreal,double>(const mpfr::mpreal& x) - { return x.toDouble(); } - - template<> inline long cast<mpfr::mpreal,long>(const mpfr::mpreal& x) - { return x.toLong(); } - - template<> inline int cast<mpfr::mpreal,int>(const mpfr::mpreal& x) - { return int(x.toLong()); } - - // Specialize GEBP kernel and traits for mpreal (no need for peeling, nor complicated stuff) - // This also permits to directly call mpfr's routines and avoid many temporaries produced by mpreal - template<> - class gebp_traits<mpfr::mpreal, mpfr::mpreal, false, false> - { - public: - typedef mpfr::mpreal ResScalar; - enum { - Vectorizable = false, - LhsPacketSize = 1, - RhsPacketSize = 1, - ResPacketSize = 1, - NumberOfRegisters = 1, - nr = 1, - mr = 1, - LhsProgress = 1, - RhsProgress = 1 - }; - typedef ResScalar LhsPacket; - typedef ResScalar RhsPacket; - typedef ResScalar ResPacket; - typedef LhsPacket LhsPacket4Packing; - - }; - - - - template<typename Index, typename DataMapper, bool ConjugateLhs, bool ConjugateRhs> - struct gebp_kernel<mpfr::mpreal,mpfr::mpreal,Index,DataMapper,1,1,ConjugateLhs,ConjugateRhs> - { - typedef mpfr::mpreal mpreal; - - EIGEN_DONT_INLINE - void operator()(const DataMapper& res, const mpreal* blockA, const mpreal* blockB, - Index rows, Index depth, Index cols, const mpreal& alpha, - Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0) - { - if(rows==0 || cols==0 || depth==0) - return; - - mpreal acc1(0,mpfr_get_prec(blockA[0].mpfr_srcptr())), - tmp (0,mpfr_get_prec(blockA[0].mpfr_srcptr())); - - if(strideA==-1) strideA = depth; - if(strideB==-1) strideB = depth; - - for(Index i=0; i<rows; ++i) - { - for(Index j=0; j<cols; ++j) - { - const mpreal *A = blockA + i*strideA + offsetA; - const mpreal *B = blockB + j*strideB + offsetB; - - acc1 = 0; - for(Index k=0; k<depth; k++) - { - mpfr_mul(tmp.mpfr_ptr(), A[k].mpfr_srcptr(), B[k].mpfr_srcptr(), mpreal::get_default_rnd()); - mpfr_add(acc1.mpfr_ptr(), acc1.mpfr_ptr(), tmp.mpfr_ptr(), mpreal::get_default_rnd()); - } - - mpfr_mul(acc1.mpfr_ptr(), acc1.mpfr_srcptr(), alpha.mpfr_srcptr(), mpreal::get_default_rnd()); - mpfr_add(res(i,j).mpfr_ptr(), res(i,j).mpfr_srcptr(), acc1.mpfr_srcptr(), mpreal::get_default_rnd()); - } - } - } - }; - } // end namespace internal -} - -#endif // EIGEN_MPREALSUPPORT_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/MatrixFunctions b/external/eigen/include/eigen3/unsupported/Eigen/MatrixFunctions deleted file mode 100644 index 20c23d1c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/MatrixFunctions +++ /dev/null @@ -1,504 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Jitse Niesen <jitse@maths.leeds.ac.uk> -// Copyright (C) 2012 Chen-Pang He <jdh8@ms63.hinet.net> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIX_FUNCTIONS -#define EIGEN_MATRIX_FUNCTIONS - -#include <cfloat> -#include <list> - -#include "../../Eigen/Core" -#include "../../Eigen/LU" -#include "../../Eigen/Eigenvalues" - -/** - * \defgroup MatrixFunctions_Module Matrix functions module - * \brief This module aims to provide various methods for the computation of - * matrix functions. - * - * To use this module, add - * \code - * #include <unsupported/Eigen/MatrixFunctions> - * \endcode - * at the start of your source file. - * - * This module defines the following MatrixBase methods. - * - \ref matrixbase_cos "MatrixBase::cos()", for computing the matrix cosine - * - \ref matrixbase_cosh "MatrixBase::cosh()", for computing the matrix hyperbolic cosine - * - \ref matrixbase_exp "MatrixBase::exp()", for computing the matrix exponential - * - \ref matrixbase_log "MatrixBase::log()", for computing the matrix logarithm - * - \ref matrixbase_pow "MatrixBase::pow()", for computing the matrix power - * - \ref matrixbase_matrixfunction "MatrixBase::matrixFunction()", for computing general matrix functions - * - \ref matrixbase_sin "MatrixBase::sin()", for computing the matrix sine - * - \ref matrixbase_sinh "MatrixBase::sinh()", for computing the matrix hyperbolic sine - * - \ref matrixbase_sqrt "MatrixBase::sqrt()", for computing the matrix square root - * - * These methods are the main entry points to this module. - * - * %Matrix functions are defined as follows. Suppose that \f$ f \f$ - * is an entire function (that is, a function on the complex plane - * that is everywhere complex differentiable). Then its Taylor - * series - * \f[ f(0) + f'(0) x + \frac{f''(0)}{2} x^2 + \frac{f'''(0)}{3!} x^3 + \cdots \f] - * converges to \f$ f(x) \f$. In this case, we can define the matrix - * function by the same series: - * \f[ f(M) = f(0) + f'(0) M + \frac{f''(0)}{2} M^2 + \frac{f'''(0)}{3!} M^3 + \cdots \f] - * - */ - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#include "src/MatrixFunctions/MatrixExponential.h" -#include "src/MatrixFunctions/MatrixFunction.h" -#include "src/MatrixFunctions/MatrixSquareRoot.h" -#include "src/MatrixFunctions/MatrixLogarithm.h" -#include "src/MatrixFunctions/MatrixPower.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - - -/** -\page matrixbaseextra_page -\ingroup MatrixFunctions_Module - -\section matrixbaseextra MatrixBase methods defined in the MatrixFunctions module - -The remainder of the page documents the following MatrixBase methods -which are defined in the MatrixFunctions module. - - - -\subsection matrixbase_cos MatrixBase::cos() - -Compute the matrix cosine. - -\code -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::cos() const -\endcode - -\param[in] M a square matrix. -\returns expression representing \f$ \cos(M) \f$. - -This function computes the matrix cosine. Use ArrayBase::cos() for computing the entry-wise cosine. - -The implementation calls \ref matrixbase_matrixfunction "matrixFunction()" with StdStemFunctions::cos(). - -\sa \ref matrixbase_sin "sin()" for an example. - - - -\subsection matrixbase_cosh MatrixBase::cosh() - -Compute the matrix hyberbolic cosine. - -\code -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::cosh() const -\endcode - -\param[in] M a square matrix. -\returns expression representing \f$ \cosh(M) \f$ - -This function calls \ref matrixbase_matrixfunction "matrixFunction()" with StdStemFunctions::cosh(). - -\sa \ref matrixbase_sinh "sinh()" for an example. - - - -\subsection matrixbase_exp MatrixBase::exp() - -Compute the matrix exponential. - -\code -const MatrixExponentialReturnValue<Derived> MatrixBase<Derived>::exp() const -\endcode - -\param[in] M matrix whose exponential is to be computed. -\returns expression representing the matrix exponential of \p M. - -The matrix exponential of \f$ M \f$ is defined by -\f[ \exp(M) = \sum_{k=0}^\infty \frac{M^k}{k!}. \f] -The matrix exponential can be used to solve linear ordinary -differential equations: the solution of \f$ y' = My \f$ with the -initial condition \f$ y(0) = y_0 \f$ is given by -\f$ y(t) = \exp(M) y_0 \f$. - -The matrix exponential is different from applying the exp function to all the entries in the matrix. -Use ArrayBase::exp() if you want to do the latter. - -The cost of the computation is approximately \f$ 20 n^3 \f$ for -matrices of size \f$ n \f$. The number 20 depends weakly on the -norm of the matrix. - -The matrix exponential is computed using the scaling-and-squaring -method combined with Padé approximation. The matrix is first -rescaled, then the exponential of the reduced matrix is computed -approximant, and then the rescaling is undone by repeated -squaring. The degree of the Padé approximant is chosen such -that the approximation error is less than the round-off -error. However, errors may accumulate during the squaring phase. - -Details of the algorithm can be found in: Nicholas J. Higham, "The -scaling and squaring method for the matrix exponential revisited," -<em>SIAM J. %Matrix Anal. Applic.</em>, <b>26</b>:1179–1193, -2005. - -Example: The following program checks that -\f[ \exp \left[ \begin{array}{ccc} - 0 & \frac14\pi & 0 \\ - -\frac14\pi & 0 & 0 \\ - 0 & 0 & 0 - \end{array} \right] = \left[ \begin{array}{ccc} - \frac12\sqrt2 & -\frac12\sqrt2 & 0 \\ - \frac12\sqrt2 & \frac12\sqrt2 & 0 \\ - 0 & 0 & 1 - \end{array} \right]. \f] -This corresponds to a rotation of \f$ \frac14\pi \f$ radians around -the z-axis. - -\include MatrixExponential.cpp -Output: \verbinclude MatrixExponential.out - -\note \p M has to be a matrix of \c float, \c double, `long double` -\c complex<float>, \c complex<double>, or `complex<long double>` . - - -\subsection matrixbase_log MatrixBase::log() - -Compute the matrix logarithm. - -\code -const MatrixLogarithmReturnValue<Derived> MatrixBase<Derived>::log() const -\endcode - -\param[in] M invertible matrix whose logarithm is to be computed. -\returns expression representing the matrix logarithm root of \p M. - -The matrix logarithm of \f$ M \f$ is a matrix \f$ X \f$ such that -\f$ \exp(X) = M \f$ where exp denotes the matrix exponential. As for -the scalar logarithm, the equation \f$ \exp(X) = M \f$ may have -multiple solutions; this function returns a matrix whose eigenvalues -have imaginary part in the interval \f$ (-\pi,\pi] \f$. - -The matrix logarithm is different from applying the log function to all the entries in the matrix. -Use ArrayBase::log() if you want to do the latter. - -In the real case, the matrix \f$ M \f$ should be invertible and -it should have no eigenvalues which are real and negative (pairs of -complex conjugate eigenvalues are allowed). In the complex case, it -only needs to be invertible. - -This function computes the matrix logarithm using the Schur-Parlett -algorithm as implemented by MatrixBase::matrixFunction(). The -logarithm of an atomic block is computed by MatrixLogarithmAtomic, -which uses direct computation for 1-by-1 and 2-by-2 blocks and an -inverse scaling-and-squaring algorithm for bigger blocks, with the -square roots computed by MatrixBase::sqrt(). - -Details of the algorithm can be found in Section 11.6.2 of: -Nicholas J. Higham, -<em>Functions of Matrices: Theory and Computation</em>, -SIAM 2008. ISBN 978-0-898716-46-7. - -Example: The following program checks that -\f[ \log \left[ \begin{array}{ccc} - \frac12\sqrt2 & -\frac12\sqrt2 & 0 \\ - \frac12\sqrt2 & \frac12\sqrt2 & 0 \\ - 0 & 0 & 1 - \end{array} \right] = \left[ \begin{array}{ccc} - 0 & \frac14\pi & 0 \\ - -\frac14\pi & 0 & 0 \\ - 0 & 0 & 0 - \end{array} \right]. \f] -This corresponds to a rotation of \f$ \frac14\pi \f$ radians around -the z-axis. This is the inverse of the example used in the -documentation of \ref matrixbase_exp "exp()". - -\include MatrixLogarithm.cpp -Output: \verbinclude MatrixLogarithm.out - -\note \p M has to be a matrix of \c float, \c double, `long -double`, \c complex<float>, \c complex<double>, or `complex<long double>`. - -\sa MatrixBase::exp(), MatrixBase::matrixFunction(), - class MatrixLogarithmAtomic, MatrixBase::sqrt(). - - -\subsection matrixbase_pow MatrixBase::pow() - -Compute the matrix raised to arbitrary real power. - -\code -const MatrixPowerReturnValue<Derived> MatrixBase<Derived>::pow(RealScalar p) const -\endcode - -\param[in] M base of the matrix power, should be a square matrix. -\param[in] p exponent of the matrix power. - -The matrix power \f$ M^p \f$ is defined as \f$ \exp(p \log(M)) \f$, -where exp denotes the matrix exponential, and log denotes the matrix -logarithm. This is different from raising all the entries in the matrix -to the p-th power. Use ArrayBase::pow() if you want to do the latter. - -If \p p is complex, the scalar type of \p M should be the type of \p -p . \f$ M^p \f$ simply evaluates into \f$ \exp(p \log(M)) \f$. -Therefore, the matrix \f$ M \f$ should meet the conditions to be an -argument of matrix logarithm. - -If \p p is real, it is casted into the real scalar type of \p M. Then -this function computes the matrix power using the Schur-Padé -algorithm as implemented by class MatrixPower. The exponent is split -into integral part and fractional part, where the fractional part is -in the interval \f$ (-1, 1) \f$. The main diagonal and the first -super-diagonal is directly computed. - -If \p M is singular with a semisimple zero eigenvalue and \p p is -positive, the Schur factor \f$ T \f$ is reordered with Givens -rotations, i.e. - -\f[ T = \left[ \begin{array}{cc} - T_1 & T_2 \\ - 0 & 0 - \end{array} \right] \f] - -where \f$ T_1 \f$ is invertible. Then \f$ T^p \f$ is given by - -\f[ T^p = \left[ \begin{array}{cc} - T_1^p & T_1^{-1} T_1^p T_2 \\ - 0 & 0 - \end{array}. \right] \f] - -\warning Fractional power of a matrix with a non-semisimple zero -eigenvalue is not well-defined. We introduce an assertion failure -against inaccurate result, e.g. \code -#include <unsupported/Eigen/MatrixFunctions> -#include <iostream> - -int main() -{ - Eigen::Matrix4d A; - A << 0, 0, 2, 3, - 0, 0, 4, 5, - 0, 0, 6, 7, - 0, 0, 8, 9; - std::cout << A.pow(0.37) << std::endl; - - // The 1 makes eigenvalue 0 non-semisimple. - A.coeffRef(0, 1) = 1; - - // This fails if EIGEN_NO_DEBUG is undefined. - std::cout << A.pow(0.37) << std::endl; - - return 0; -} -\endcode - -Details of the algorithm can be found in: Nicholas J. Higham and -Lijing Lin, "A Schur-Padé algorithm for fractional powers of a -matrix," <em>SIAM J. %Matrix Anal. Applic.</em>, -<b>32(3)</b>:1056–1078, 2011. - -Example: The following program checks that -\f[ \left[ \begin{array}{ccc} - \cos1 & -\sin1 & 0 \\ - \sin1 & \cos1 & 0 \\ - 0 & 0 & 1 - \end{array} \right]^{\frac14\pi} = \left[ \begin{array}{ccc} - \frac12\sqrt2 & -\frac12\sqrt2 & 0 \\ - \frac12\sqrt2 & \frac12\sqrt2 & 0 \\ - 0 & 0 & 1 - \end{array} \right]. \f] -This corresponds to \f$ \frac14\pi \f$ rotations of 1 radian around -the z-axis. - -\include MatrixPower.cpp -Output: \verbinclude MatrixPower.out - -MatrixBase::pow() is user-friendly. However, there are some -circumstances under which you should use class MatrixPower directly. -MatrixPower can save the result of Schur decomposition, so it's -better for computing various powers for the same matrix. - -Example: -\include MatrixPower_optimal.cpp -Output: \verbinclude MatrixPower_optimal.out - -\note \p M has to be a matrix of \c float, \c double, `long -double`, \c complex<float>, \c complex<double>, or -\c complex<long double> . - -\sa MatrixBase::exp(), MatrixBase::log(), class MatrixPower. - - -\subsection matrixbase_matrixfunction MatrixBase::matrixFunction() - -Compute a matrix function. - -\code -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::matrixFunction(typename internal::stem_function<typename internal::traits<Derived>::Scalar>::type f) const -\endcode - -\param[in] M argument of matrix function, should be a square matrix. -\param[in] f an entire function; \c f(x,n) should compute the n-th -derivative of f at x. -\returns expression representing \p f applied to \p M. - -Suppose that \p M is a matrix whose entries have type \c Scalar. -Then, the second argument, \p f, should be a function with prototype -\code -ComplexScalar f(ComplexScalar, int) -\endcode -where \c ComplexScalar = \c std::complex<Scalar> if \c Scalar is -real (e.g., \c float or \c double) and \c ComplexScalar = -\c Scalar if \c Scalar is complex. The return value of \c f(x,n) -should be \f$ f^{(n)}(x) \f$, the n-th derivative of f at x. - -This routine uses the algorithm described in: -Philip Davies and Nicholas J. Higham, -"A Schur-Parlett algorithm for computing matrix functions", -<em>SIAM J. %Matrix Anal. Applic.</em>, <b>25</b>:464–485, 2003. - -The actual work is done by the MatrixFunction class. - -Example: The following program checks that -\f[ \exp \left[ \begin{array}{ccc} - 0 & \frac14\pi & 0 \\ - -\frac14\pi & 0 & 0 \\ - 0 & 0 & 0 - \end{array} \right] = \left[ \begin{array}{ccc} - \frac12\sqrt2 & -\frac12\sqrt2 & 0 \\ - \frac12\sqrt2 & \frac12\sqrt2 & 0 \\ - 0 & 0 & 1 - \end{array} \right]. \f] -This corresponds to a rotation of \f$ \frac14\pi \f$ radians around -the z-axis. This is the same example as used in the documentation -of \ref matrixbase_exp "exp()". - -\include MatrixFunction.cpp -Output: \verbinclude MatrixFunction.out - -Note that the function \c expfn is defined for complex numbers -\c x, even though the matrix \c A is over the reals. Instead of -\c expfn, we could also have used StdStemFunctions::exp: -\code -A.matrixFunction(StdStemFunctions<std::complex<double> >::exp, &B); -\endcode - - - -\subsection matrixbase_sin MatrixBase::sin() - -Compute the matrix sine. - -\code -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::sin() const -\endcode - -\param[in] M a square matrix. -\returns expression representing \f$ \sin(M) \f$. - -This function computes the matrix sine. Use ArrayBase::sin() for computing the entry-wise sine. - -The implementation calls \ref matrixbase_matrixfunction "matrixFunction()" with StdStemFunctions::sin(). - -Example: \include MatrixSine.cpp -Output: \verbinclude MatrixSine.out - - - -\subsection matrixbase_sinh MatrixBase::sinh() - -Compute the matrix hyperbolic sine. - -\code -MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::sinh() const -\endcode - -\param[in] M a square matrix. -\returns expression representing \f$ \sinh(M) \f$ - -This function calls \ref matrixbase_matrixfunction "matrixFunction()" with StdStemFunctions::sinh(). - -Example: \include MatrixSinh.cpp -Output: \verbinclude MatrixSinh.out - - -\subsection matrixbase_sqrt MatrixBase::sqrt() - -Compute the matrix square root. - -\code -const MatrixSquareRootReturnValue<Derived> MatrixBase<Derived>::sqrt() const -\endcode - -\param[in] M invertible matrix whose square root is to be computed. -\returns expression representing the matrix square root of \p M. - -The matrix square root of \f$ M \f$ is the matrix \f$ M^{1/2} \f$ -whose square is the original matrix; so if \f$ S = M^{1/2} \f$ then -\f$ S^2 = M \f$. This is different from taking the square root of all -the entries in the matrix; use ArrayBase::sqrt() if you want to do the -latter. - -In the <b>real case</b>, the matrix \f$ M \f$ should be invertible and -it should have no eigenvalues which are real and negative (pairs of -complex conjugate eigenvalues are allowed). In that case, the matrix -has a square root which is also real, and this is the square root -computed by this function. - -The matrix square root is computed by first reducing the matrix to -quasi-triangular form with the real Schur decomposition. The square -root of the quasi-triangular matrix can then be computed directly. The -cost is approximately \f$ 25 n^3 \f$ real flops for the real Schur -decomposition and \f$ 3\frac13 n^3 \f$ real flops for the remainder -(though the computation time in practice is likely more than this -indicates). - -Details of the algorithm can be found in: Nicholas J. Highan, -"Computing real square roots of a real matrix", <em>Linear Algebra -Appl.</em>, 88/89:405–430, 1987. - -If the matrix is <b>positive-definite symmetric</b>, then the square -root is also positive-definite symmetric. In this case, it is best to -use SelfAdjointEigenSolver::operatorSqrt() to compute it. - -In the <b>complex case</b>, the matrix \f$ M \f$ should be invertible; -this is a restriction of the algorithm. The square root computed by -this algorithm is the one whose eigenvalues have an argument in the -interval \f$ (-\frac12\pi, \frac12\pi] \f$. This is the usual branch -cut. - -The computation is the same as in the real case, except that the -complex Schur decomposition is used to reduce the matrix to a -triangular matrix. The theoretical cost is the same. Details are in: -Åke Björck and Sven Hammarling, "A Schur method for the -square root of a matrix", <em>Linear Algebra Appl.</em>, -52/53:127–140, 1983. - -Example: The following program checks that the square root of -\f[ \left[ \begin{array}{cc} - \cos(\frac13\pi) & -\sin(\frac13\pi) \\ - \sin(\frac13\pi) & \cos(\frac13\pi) - \end{array} \right], \f] -corresponding to a rotation over 60 degrees, is a rotation over 30 degrees: -\f[ \left[ \begin{array}{cc} - \cos(\frac16\pi) & -\sin(\frac16\pi) \\ - \sin(\frac16\pi) & \cos(\frac16\pi) - \end{array} \right]. \f] - -\include MatrixSquareRoot.cpp -Output: \verbinclude MatrixSquareRoot.out - -\sa class RealSchur, class ComplexSchur, class MatrixSquareRoot, - SelfAdjointEigenSolver::operatorSqrt(). - -*/ - -#endif // EIGEN_MATRIX_FUNCTIONS - diff --git a/external/eigen/include/eigen3/unsupported/Eigen/MoreVectorization b/external/eigen/include/eigen3/unsupported/Eigen/MoreVectorization deleted file mode 100644 index 7662b478..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/MoreVectorization +++ /dev/null @@ -1,24 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MOREVECTORIZATION_MODULE_H -#define EIGEN_MOREVECTORIZATION_MODULE_H - -#include "../../Eigen/Core" - -namespace Eigen { - -/** - * \defgroup MoreVectorization More vectorization module - */ - -} - -#include "src/MoreVectorization/MathFunctions.h" - -#endif // EIGEN_MOREVECTORIZATION_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/NonLinearOptimization b/external/eigen/include/eigen3/unsupported/Eigen/NonLinearOptimization deleted file mode 100644 index 961f192b..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/NonLinearOptimization +++ /dev/null @@ -1,140 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_NONLINEAROPTIMIZATION_MODULE -#define EIGEN_NONLINEAROPTIMIZATION_MODULE - -#include <vector> - -#include "../../Eigen/Core" -#include "../../Eigen/Jacobi" -#include "../../Eigen/QR" -#include "NumericalDiff" - -/** - * \defgroup NonLinearOptimization_Module Non linear optimization module - * - * \code - * #include <unsupported/Eigen/NonLinearOptimization> - * \endcode - * - * This module provides implementation of two important algorithms in non linear - * optimization. In both cases, we consider a system of non linear functions. Of - * course, this should work, and even work very well if those functions are - * actually linear. But if this is so, you should probably better use other - * methods more fitted to this special case. - * - * One algorithm allows to find a least-squares solution of such a system - * (Levenberg-Marquardt algorithm) and the second one is used to find - * a zero for the system (Powell hybrid "dogleg" method). - * - * This code is a port of minpack (http://en.wikipedia.org/wiki/MINPACK). - * Minpack is a very famous, old, robust and well renowned package, written in - * fortran. Those implementations have been carefully tuned, tested, and used - * for several decades. - * - * The original fortran code was automatically translated using f2c (http://en.wikipedia.org/wiki/F2c) in C, - * then c++, and then cleaned by several different authors. - * The last one of those cleanings being our starting point : - * http://devernay.free.fr/hacks/cminpack.html - * - * Finally, we ported this code to Eigen, creating classes and API - * coherent with Eigen. When possible, we switched to Eigen - * implementation, such as most linear algebra (vectors, matrices, stable norms). - * - * Doing so, we were very careful to check the tests we setup at the very - * beginning, which ensure that the same results are found. - * - * \section Tests Tests - * - * The tests are placed in the file unsupported/test/NonLinear.cpp. - * - * There are two kinds of tests : those that come from examples bundled with cminpack. - * They guaranty we get the same results as the original algorithms (value for 'x', - * for the number of evaluations of the function, and for the number of evaluations - * of the Jacobian if ever). - * - * Other tests were added by myself at the very beginning of the - * process and check the results for Levenberg-Marquardt using the reference data - * on http://www.itl.nist.gov/div898/strd/nls/nls_main.shtml. Since then i've - * carefully checked that the same results were obtained when modifying the - * code. Please note that we do not always get the exact same decimals as they do, - * but this is ok : they use 128bits float, and we do the tests using the C type 'double', - * which is 64 bits on most platforms (x86 and amd64, at least). - * I've performed those tests on several other implementations of Levenberg-Marquardt, and - * (c)minpack performs VERY well compared to those, both in accuracy and speed. - * - * The documentation for running the tests is on the wiki - * http://eigen.tuxfamily.org/index.php?title=Tests - * - * \section API API: overview of methods - * - * Both algorithms needs a functor computing the Jacobian. It can be computed by - * hand, using auto-differentiation (see \ref AutoDiff_Module), or using numerical - * differences (see \ref NumericalDiff_Module). For instance: - *\code - * MyFunc func; - * NumericalDiff<MyFunc> func_with_num_diff(func); - * LevenbergMarquardt<NumericalDiff<MyFunc> > lm(func_with_num_diff); - * \endcode - * For HybridNonLinearSolver, the method solveNumericalDiff() does the above wrapping for - * you. - * - * The methods LevenbergMarquardt.lmder1()/lmdif1()/lmstr1() and - * HybridNonLinearSolver.hybrj1()/hybrd1() are specific methods from the original - * minpack package that you probably should NOT use until you are porting a code that - * was previously using minpack. They just define a 'simple' API with default values - * for some parameters. - * - * All algorithms are provided using two APIs : - * - one where the user inits the algorithm, and uses '*OneStep()' as much as he wants : - * this way the caller have control over the steps - * - one where the user just calls a method (optimize() or solve()) which will - * handle the loop: init + loop until a stop condition is met. Those are provided for - * convenience. - * - * As an example, the method LevenbergMarquardt::minimize() is - * implemented as follow: - * \code - * Status LevenbergMarquardt<FunctorType,Scalar>::minimize(FVectorType &x, const int mode) - * { - * Status status = minimizeInit(x, mode); - * do { - * status = minimizeOneStep(x, mode); - * } while (status==Running); - * return status; - * } - * \endcode - * - * \section examples Examples - * - * The easiest way to understand how to use this module is by looking at the many examples in the file - * unsupported/test/NonLinearOptimization.cpp. - */ - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -#include "src/NonLinearOptimization/qrsolv.h" -#include "src/NonLinearOptimization/r1updt.h" -#include "src/NonLinearOptimization/r1mpyq.h" -#include "src/NonLinearOptimization/rwupdt.h" -#include "src/NonLinearOptimization/fdjac1.h" -#include "src/NonLinearOptimization/lmpar.h" -#include "src/NonLinearOptimization/dogleg.h" -#include "src/NonLinearOptimization/covar.h" - -#include "src/NonLinearOptimization/chkder.h" - -#endif - -#include "src/NonLinearOptimization/HybridNonLinearSolver.h" -#include "src/NonLinearOptimization/LevenbergMarquardt.h" - - -#endif // EIGEN_NONLINEAROPTIMIZATION_MODULE diff --git a/external/eigen/include/eigen3/unsupported/Eigen/NumericalDiff b/external/eigen/include/eigen3/unsupported/Eigen/NumericalDiff deleted file mode 100644 index 0668f960..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/NumericalDiff +++ /dev/null @@ -1,56 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_NUMERICALDIFF_MODULE -#define EIGEN_NUMERICALDIFF_MODULE - -#include "../../Eigen/Core" - -namespace Eigen { - -/** - * \defgroup NumericalDiff_Module Numerical differentiation module - * - * \code - * #include <unsupported/Eigen/NumericalDiff> - * \endcode - * - * See http://en.wikipedia.org/wiki/Numerical_differentiation - * - * Warning : this should NOT be confused with automatic differentiation, which - * is a different method and has its own module in Eigen : \ref - * AutoDiff_Module. - * - * Currently only "Forward" and "Central" schemes are implemented. Those - * are basic methods, and there exist some more elaborated way of - * computing such approximates. They are implemented using both - * proprietary and free software, and usually requires linking to an - * external library. It is very easy for you to write a functor - * using such software, and the purpose is quite orthogonal to what we - * want to achieve with Eigen. - * - * This is why we will not provide wrappers for every great numerical - * differentiation software that exist, but should rather stick with those - * basic ones, that still are useful for testing. - * - * Also, the \ref NonLinearOptimization_Module needs this in order to - * provide full features compatibility with the original (c)minpack - * package. - * - */ -} - -//@{ - -#include "src/NumericalDiff/NumericalDiff.h" - -//@} - - -#endif // EIGEN_NUMERICALDIFF_MODULE diff --git a/external/eigen/include/eigen3/unsupported/Eigen/OpenGLSupport b/external/eigen/include/eigen3/unsupported/Eigen/OpenGLSupport deleted file mode 100644 index f8c21300..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/OpenGLSupport +++ /dev/null @@ -1,322 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_OPENGL_MODULE -#define EIGEN_OPENGL_MODULE - -#include "../../Eigen/Geometry" - -#if defined(__APPLE_CC__) - #include <OpenGL/gl.h> -#else - #include <GL/gl.h> -#endif - -namespace Eigen { - -/** - * \defgroup OpenGLSUpport_Module OpenGL Support module - * - * This module provides wrapper functions for a couple of OpenGL functions - * which simplify the way to pass Eigen's object to openGL. - * Here is an example: - * - * \code - * // You need to add path_to_eigen/unsupported to your include path. - * #include <Eigen/OpenGLSupport> - * // ... - * Vector3f x, y; - * Matrix3f rot; - * - * glVertex(y + x * rot); - * - * Quaternion q; - * glRotate(q); - * - * // ... - * \endcode - * - */ -//@{ - -#define EIGEN_GL_FUNC_DECLARATION(FUNC) \ -namespace internal { \ - template< typename XprType, \ - typename Scalar = typename XprType::Scalar, \ - int Rows = XprType::RowsAtCompileTime, \ - int Cols = XprType::ColsAtCompileTime, \ - bool IsGLCompatible = bool(internal::evaluator<XprType>::Flags&LinearAccessBit) \ - && bool(XprType::Flags&DirectAccessBit) \ - && (XprType::IsVectorAtCompileTime || (XprType::Flags&RowMajorBit)==0)> \ - struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl); \ - \ - template<typename XprType, typename Scalar, int Rows, int Cols> \ - struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<XprType,Scalar,Rows,Cols,false> { \ - inline static void run(const XprType& p) { \ - EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<typename plain_matrix_type_column_major<XprType>::type>::run(p); } \ - }; \ -} \ - \ -template<typename Derived> inline void FUNC(const Eigen::DenseBase<Derived>& p) { \ - EIGEN_CAT(EIGEN_CAT(internal::gl_,FUNC),_impl)<Derived>::run(p.derived()); \ -} - - -#define EIGEN_GL_FUNC_SPECIALIZATION_MAT(FUNC,SCALAR,ROWS,COLS,SUFFIX) \ -namespace internal { \ - template< typename XprType> struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<XprType, SCALAR, ROWS, COLS, true> { \ - inline static void run(const XprType& p) { FUNC##SUFFIX(p.data()); } \ - }; \ -} - - -#define EIGEN_GL_FUNC_SPECIALIZATION_VEC(FUNC,SCALAR,SIZE,SUFFIX) \ -namespace internal { \ - template< typename XprType> struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<XprType, SCALAR, SIZE, 1, true> { \ - inline static void run(const XprType& p) { FUNC##SUFFIX(p.data()); } \ - }; \ - template< typename XprType> struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<XprType, SCALAR, 1, SIZE, true> { \ - inline static void run(const XprType& p) { FUNC##SUFFIX(p.data()); } \ - }; \ -} - - -EIGEN_GL_FUNC_DECLARATION (glVertex) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,int, 2,2iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,short, 2,2sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,float, 2,2fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,double, 2,2dv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,int, 3,3iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,short, 3,3sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,float, 3,3fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,double, 3,3dv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,int, 4,4iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,short, 4,4sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,float, 4,4fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glVertex,double, 4,4dv) - -EIGEN_GL_FUNC_DECLARATION (glTexCoord) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,int, 2,2iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,short, 2,2sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,float, 2,2fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,double, 2,2dv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,int, 3,3iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,short, 3,3sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,float, 3,3fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,double, 3,3dv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,int, 4,4iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,short, 4,4sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,float, 4,4fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTexCoord,double, 4,4dv) - -EIGEN_GL_FUNC_DECLARATION (glColor) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,int, 2,2iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,short, 2,2sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,float, 2,2fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,double, 2,2dv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,int, 3,3iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,short, 3,3sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,float, 3,3fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,double, 3,3dv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,int, 4,4iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,short, 4,4sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,float, 4,4fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glColor,double, 4,4dv) - -EIGEN_GL_FUNC_DECLARATION (glNormal) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glNormal,int, 3,3iv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glNormal,short, 3,3sv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glNormal,float, 3,3fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glNormal,double, 3,3dv) - -inline void glScale2fv(const float* v) { glScalef(v[0], v[1], 1.f); } -inline void glScale2dv(const double* v) { glScaled(v[0], v[1], 1.0); } -inline void glScale3fv(const float* v) { glScalef(v[0], v[1], v[2]); } -inline void glScale3dv(const double* v) { glScaled(v[0], v[1], v[2]); } - -EIGEN_GL_FUNC_DECLARATION (glScale) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glScale,float, 2,2fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glScale,double, 2,2dv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glScale,float, 3,3fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glScale,double, 3,3dv) - -template<typename Scalar> void glScale(const UniformScaling<Scalar>& s) { glScale(Matrix<Scalar,3,1>::Constant(s.factor())); } - -inline void glTranslate2fv(const float* v) { glTranslatef(v[0], v[1], 0.f); } -inline void glTranslate2dv(const double* v) { glTranslated(v[0], v[1], 0.0); } -inline void glTranslate3fv(const float* v) { glTranslatef(v[0], v[1], v[2]); } -inline void glTranslate3dv(const double* v) { glTranslated(v[0], v[1], v[2]); } - -EIGEN_GL_FUNC_DECLARATION (glTranslate) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTranslate,float, 2,2fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTranslate,double, 2,2dv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTranslate,float, 3,3fv) -EIGEN_GL_FUNC_SPECIALIZATION_VEC(glTranslate,double, 3,3dv) - -template<typename Scalar> void glTranslate(const Translation<Scalar,2>& t) { glTranslate(t.vector()); } -template<typename Scalar> void glTranslate(const Translation<Scalar,3>& t) { glTranslate(t.vector()); } - -EIGEN_GL_FUNC_DECLARATION (glMultMatrix) -EIGEN_GL_FUNC_SPECIALIZATION_MAT(glMultMatrix,float, 4,4,f) -EIGEN_GL_FUNC_SPECIALIZATION_MAT(glMultMatrix,double, 4,4,d) - -template<typename Scalar> void glMultMatrix(const Transform<Scalar,3,Affine>& t) { glMultMatrix(t.matrix()); } -template<typename Scalar> void glMultMatrix(const Transform<Scalar,3,Projective>& t) { glMultMatrix(t.matrix()); } -template<typename Scalar> void glMultMatrix(const Transform<Scalar,3,AffineCompact>& t) { glMultMatrix(Transform<Scalar,3,Affine>(t).matrix()); } - -EIGEN_GL_FUNC_DECLARATION (glLoadMatrix) -EIGEN_GL_FUNC_SPECIALIZATION_MAT(glLoadMatrix,float, 4,4,f) -EIGEN_GL_FUNC_SPECIALIZATION_MAT(glLoadMatrix,double, 4,4,d) - -template<typename Scalar> void glLoadMatrix(const Transform<Scalar,3,Affine>& t) { glLoadMatrix(t.matrix()); } -template<typename Scalar> void glLoadMatrix(const Transform<Scalar,3,Projective>& t) { glLoadMatrix(t.matrix()); } -template<typename Scalar> void glLoadMatrix(const Transform<Scalar,3,AffineCompact>& t) { glLoadMatrix(Transform<Scalar,3,Affine>(t).matrix()); } - -inline void glRotate(const Rotation2D<float>& rot) -{ - glRotatef(rot.angle()*180.f/float(EIGEN_PI), 0.f, 0.f, 1.f); -} -inline void glRotate(const Rotation2D<double>& rot) -{ - glRotated(rot.angle()*180.0/double(EIGEN_PI), 0.0, 0.0, 1.0); -} - -template<typename Derived> void glRotate(const RotationBase<Derived,3>& rot) -{ - Transform<typename Derived::Scalar,3,Projective> tr(rot); - glMultMatrix(tr.matrix()); -} - -#define EIGEN_GL_MAKE_CONST_const const -#define EIGEN_GL_MAKE_CONST__ -#define EIGEN_GL_EVAL(X) X - -#define EIGEN_GL_FUNC1_DECLARATION(FUNC,ARG1,CONST) \ -namespace internal { \ - template< typename XprType, \ - typename Scalar = typename XprType::Scalar, \ - int Rows = XprType::RowsAtCompileTime, \ - int Cols = XprType::ColsAtCompileTime, \ - bool IsGLCompatible = bool(internal::evaluator<XprType>::Flags&LinearAccessBit) \ - && bool(XprType::Flags&DirectAccessBit) \ - && (XprType::IsVectorAtCompileTime || (XprType::Flags&RowMajorBit)==0)> \ - struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl); \ - \ - template<typename XprType, typename Scalar, int Rows, int Cols> \ - struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<XprType,Scalar,Rows,Cols,false> { \ - inline static void run(ARG1 a,EIGEN_GL_EVAL(EIGEN_GL_MAKE_CONST_##CONST) XprType& p) { \ - EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<typename plain_matrix_type_column_major<XprType>::type>::run(a,p); } \ - }; \ -} \ - \ -template<typename Derived> inline void FUNC(ARG1 a,EIGEN_GL_EVAL(EIGEN_GL_MAKE_CONST_##CONST) Eigen::DenseBase<Derived>& p) { \ - EIGEN_CAT(EIGEN_CAT(internal::gl_,FUNC),_impl)<Derived>::run(a,p.derived()); \ -} - - -#define EIGEN_GL_FUNC1_SPECIALIZATION_MAT(FUNC,ARG1,CONST,SCALAR,ROWS,COLS,SUFFIX) \ -namespace internal { \ - template< typename XprType> struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<XprType, SCALAR, ROWS, COLS, true> { \ - inline static void run(ARG1 a, EIGEN_GL_EVAL(EIGEN_GL_MAKE_CONST_##CONST) XprType& p) { FUNC##SUFFIX(a,p.data()); } \ - }; \ -} - - -#define EIGEN_GL_FUNC1_SPECIALIZATION_VEC(FUNC,ARG1,CONST,SCALAR,SIZE,SUFFIX) \ -namespace internal { \ - template< typename XprType> struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<XprType, SCALAR, SIZE, 1, true> { \ - inline static void run(ARG1 a, EIGEN_GL_EVAL(EIGEN_GL_MAKE_CONST_##CONST) XprType& p) { FUNC##SUFFIX(a,p.data()); } \ - }; \ - template< typename XprType> struct EIGEN_CAT(EIGEN_CAT(gl_,FUNC),_impl)<XprType, SCALAR, 1, SIZE, true> { \ - inline static void run(ARG1 a, EIGEN_GL_EVAL(EIGEN_GL_MAKE_CONST_##CONST) XprType& p) { FUNC##SUFFIX(a,p.data()); } \ - }; \ -} - -EIGEN_GL_FUNC1_DECLARATION (glGet,GLenum,_) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glGet,GLenum,_,float, 4,4,Floatv) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glGet,GLenum,_,double, 4,4,Doublev) - -// glUniform API - -#ifdef GL_VERSION_2_0 - -inline void glUniform2fv_ei (GLint loc, const float* v) { glUniform2fv(loc,1,v); } -inline void glUniform2iv_ei (GLint loc, const int* v) { glUniform2iv(loc,1,v); } - -inline void glUniform3fv_ei (GLint loc, const float* v) { glUniform3fv(loc,1,v); } -inline void glUniform3iv_ei (GLint loc, const int* v) { glUniform3iv(loc,1,v); } - -inline void glUniform4fv_ei (GLint loc, const float* v) { glUniform4fv(loc,1,v); } -inline void glUniform4iv_ei (GLint loc, const int* v) { glUniform4iv(loc,1,v); } - -inline void glUniformMatrix2fv_ei (GLint loc, const float* v) { glUniformMatrix2fv(loc,1,false,v); } -inline void glUniformMatrix3fv_ei (GLint loc, const float* v) { glUniformMatrix3fv(loc,1,false,v); } -inline void glUniformMatrix4fv_ei (GLint loc, const float* v) { glUniformMatrix4fv(loc,1,false,v); } - - -EIGEN_GL_FUNC1_DECLARATION (glUniform,GLint,const) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,float, 2,2fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,int, 2,2iv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,float, 3,3fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,int, 3,3iv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,float, 4,4fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,int, 4,4iv_ei) - -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 2,2,Matrix2fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 3,3,Matrix3fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 4,4,Matrix4fv_ei) - -#endif - -#ifdef GL_VERSION_2_1 - -inline void glUniformMatrix2x3fv_ei(GLint loc, const float* v) { glUniformMatrix2x3fv(loc,1,false,v); } -inline void glUniformMatrix3x2fv_ei(GLint loc, const float* v) { glUniformMatrix3x2fv(loc,1,false,v); } -inline void glUniformMatrix2x4fv_ei(GLint loc, const float* v) { glUniformMatrix2x4fv(loc,1,false,v); } -inline void glUniformMatrix4x2fv_ei(GLint loc, const float* v) { glUniformMatrix4x2fv(loc,1,false,v); } -inline void glUniformMatrix3x4fv_ei(GLint loc, const float* v) { glUniformMatrix3x4fv(loc,1,false,v); } -inline void glUniformMatrix4x3fv_ei(GLint loc, const float* v) { glUniformMatrix4x3fv(loc,1,false,v); } - -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 2,3,Matrix2x3fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 3,2,Matrix3x2fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 2,4,Matrix2x4fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 4,2,Matrix4x2fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 3,4,Matrix3x4fv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_MAT(glUniform,GLint,const,float, 4,3,Matrix4x3fv_ei) - -#endif - -#ifdef GL_VERSION_3_0 - -inline void glUniform2uiv_ei (GLint loc, const unsigned int* v) { glUniform2uiv(loc,1,v); } -inline void glUniform3uiv_ei (GLint loc, const unsigned int* v) { glUniform3uiv(loc,1,v); } -inline void glUniform4uiv_ei (GLint loc, const unsigned int* v) { glUniform4uiv(loc,1,v); } - -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,unsigned int, 2,2uiv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,unsigned int, 3,3uiv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,unsigned int, 4,4uiv_ei) - -#endif - -#ifdef GL_ARB_gpu_shader_fp64 -inline void glUniform2dv_ei (GLint loc, const double* v) { glUniform2dv(loc,1,v); } -inline void glUniform3dv_ei (GLint loc, const double* v) { glUniform3dv(loc,1,v); } -inline void glUniform4dv_ei (GLint loc, const double* v) { glUniform4dv(loc,1,v); } - -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,double, 2,2dv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,double, 3,3dv_ei) -EIGEN_GL_FUNC1_SPECIALIZATION_VEC(glUniform,GLint,const,double, 4,4dv_ei) -#endif - - -//@} - -} - -#endif // EIGEN_OPENGL_MODULE diff --git a/external/eigen/include/eigen3/unsupported/Eigen/Polynomials b/external/eigen/include/eigen3/unsupported/Eigen/Polynomials deleted file mode 100644 index 146e5c40..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/Polynomials +++ /dev/null @@ -1,138 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_POLYNOMIALS_MODULE_H -#define EIGEN_POLYNOMIALS_MODULE_H - -#include "../../Eigen/Core" - -#include "../../Eigen/Eigenvalues" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -// Note that EIGEN_HIDE_HEAVY_CODE has to be defined per module -#if (defined EIGEN_EXTERN_INSTANTIATIONS) && (EIGEN_EXTERN_INSTANTIATIONS>=2) - #ifndef EIGEN_HIDE_HEAVY_CODE - #define EIGEN_HIDE_HEAVY_CODE - #endif -#elif defined EIGEN_HIDE_HEAVY_CODE - #undef EIGEN_HIDE_HEAVY_CODE -#endif - -/** - * \defgroup Polynomials_Module Polynomials module - * \brief This module provides a QR based polynomial solver. - * - * To use this module, add - * \code - * #include <unsupported/Eigen/Polynomials> - * \endcode - * at the start of your source file. - */ - -#include "src/Polynomials/PolynomialUtils.h" -#include "src/Polynomials/Companion.h" -#include "src/Polynomials/PolynomialSolver.h" - -/** - \page polynomials Polynomials defines functions for dealing with polynomials - and a QR based polynomial solver. - \ingroup Polynomials_Module - - The remainder of the page documents first the functions for evaluating, computing - polynomials, computing estimates about polynomials and next the QR based polynomial - solver. - - \section polynomialUtils convenient functions to deal with polynomials - \subsection roots_to_monicPolynomial - The function - \code - void roots_to_monicPolynomial( const RootVector& rv, Polynomial& poly ) - \endcode - computes the coefficients \f$ a_i \f$ of - - \f$ p(x) = a_0 + a_{1}x + ... + a_{n-1}x^{n-1} + x^n \f$ - - where \f$ p \f$ is known through its roots i.e. \f$ p(x) = (x-r_1)(x-r_2)...(x-r_n) \f$. - - \subsection poly_eval - The function - \code - T poly_eval( const Polynomials& poly, const T& x ) - \endcode - evaluates a polynomial at a given point using stabilized Hörner method. - - The following code: first computes the coefficients in the monomial basis of the monic polynomial that has the provided roots; - then, it evaluates the computed polynomial, using a stabilized Hörner method. - - \include PolynomialUtils1.cpp - Output: \verbinclude PolynomialUtils1.out - - \subsection Cauchy bounds - The function - \code - Real cauchy_max_bound( const Polynomial& poly ) - \endcode - provides a maximum bound (the Cauchy one: \f$C(p)\f$) for the absolute value of a root of the given polynomial i.e. - \f$ \forall r_i \f$ root of \f$ p(x) = \sum_{k=0}^d a_k x^k \f$, - \f$ |r_i| \le C(p) = \sum_{k=0}^{d} \left | \frac{a_k}{a_d} \right | \f$ - The leading coefficient \f$ p \f$: should be non zero \f$a_d \neq 0\f$. - - - The function - \code - Real cauchy_min_bound( const Polynomial& poly ) - \endcode - provides a minimum bound (the Cauchy one: \f$c(p)\f$) for the absolute value of a non zero root of the given polynomial i.e. - \f$ \forall r_i \neq 0 \f$ root of \f$ p(x) = \sum_{k=0}^d a_k x^k \f$, - \f$ |r_i| \ge c(p) = \left( \sum_{k=0}^{d} \left | \frac{a_k}{a_0} \right | \right)^{-1} \f$ - - - - - \section QR polynomial solver class - Computes the complex roots of a polynomial by computing the eigenvalues of the associated companion matrix with the QR algorithm. - - The roots of \f$ p(x) = a_0 + a_1 x + a_2 x^2 + a_{3} x^3 + x^4 \f$ are the eigenvalues of - \f$ - \left [ - \begin{array}{cccc} - 0 & 0 & 0 & a_0 \\ - 1 & 0 & 0 & a_1 \\ - 0 & 1 & 0 & a_2 \\ - 0 & 0 & 1 & a_3 - \end{array} \right ] - \f$ - - However, the QR algorithm is not guaranteed to converge when there are several eigenvalues with same modulus. - - Therefore the current polynomial solver is guaranteed to provide a correct result only when the complex roots \f$r_1,r_2,...,r_d\f$ have distinct moduli i.e. - - \f$ \forall i,j \in [1;d],~ \| r_i \| \neq \| r_j \| \f$. - - With 32bit (float) floating types this problem shows up frequently. - However, almost always, correct accuracy is reached even in these cases for 64bit - (double) floating types and small polynomial degree (<20). - - \include PolynomialSolver1.cpp - - In the above example: - - -# a simple use of the polynomial solver is shown; - -# the accuracy problem with the QR algorithm is presented: a polynomial with almost conjugate roots is provided to the solver. - Those roots have almost same module therefore the QR algorithm failed to converge: the accuracy - of the last root is bad; - -# a simple way to circumvent the problem is shown: use doubles instead of floats. - - Output: \verbinclude PolynomialSolver1.out -*/ - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_POLYNOMIALS_MODULE_H -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/Skyline b/external/eigen/include/eigen3/unsupported/Eigen/Skyline deleted file mode 100644 index ebdf143f..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/Skyline +++ /dev/null @@ -1,39 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SKYLINE_MODULE_H -#define EIGEN_SKYLINE_MODULE_H - - -#include "../../Eigen/Core" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#include <map> -#include <cstdlib> -#include <cstring> -#include <algorithm> - -/** - * \defgroup Skyline_Module Skyline module - * - * - * - * - */ - -#include "src/Skyline/SkylineUtil.h" -#include "src/Skyline/SkylineMatrixBase.h" -#include "src/Skyline/SkylineStorage.h" -#include "src/Skyline/SkylineMatrix.h" -#include "src/Skyline/SkylineInplaceLU.h" -#include "src/Skyline/SkylineProduct.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SKYLINE_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/SparseExtra b/external/eigen/include/eigen3/unsupported/Eigen/SparseExtra deleted file mode 100644 index 819cffa2..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/SparseExtra +++ /dev/null @@ -1,53 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <g.gael@free.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_EXTRA_MODULE_H -#define EIGEN_SPARSE_EXTRA_MODULE_H - -#include "../../Eigen/Sparse" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#include <vector> -#include <map> -#include <cstdlib> -#include <cstring> -#include <algorithm> -#include <fstream> -#include <sstream> - -#ifdef EIGEN_GOOGLEHASH_SUPPORT - #include <google/dense_hash_map> -#endif - -/** - * \defgroup SparseExtra_Module SparseExtra module - * - * This module contains some experimental features extending the sparse module. - * - * \code - * #include <Eigen/SparseExtra> - * \endcode - */ - - -#include "src/SparseExtra/DynamicSparseMatrix.h" -#include "src/SparseExtra/BlockOfDynamicSparseMatrix.h" -#include "src/SparseExtra/RandomSetter.h" - -#include "src/SparseExtra/MarketIO.h" - -#if !defined(_WIN32) -#include <dirent.h> -#include "src/SparseExtra/MatrixMarketIterator.h" -#endif - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SPARSE_EXTRA_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/SpecialFunctions b/external/eigen/include/eigen3/unsupported/Eigen/SpecialFunctions deleted file mode 100644 index a098ce87..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/SpecialFunctions +++ /dev/null @@ -1,88 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Gael Guennebaud <g.gael@free.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPECIALFUNCTIONS_MODULE -#define EIGEN_SPECIALFUNCTIONS_MODULE - -#include <math.h> - -#include "../../Eigen/Core" - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -namespace Eigen { - -/** - * \defgroup SpecialFunctions_Module Special math functions module - * - * This module features additional coefficient-wise math functions available - * within the numext:: namespace for the scalar version, and as method and/or free - * functions of Array. Those include: - * - * - erf - * - erfc - * - lgamma - * - igamma - * - igamma_der_a - * - gamma_sample_der_alpha - * - igammac - * - digamma - * - ndtri - * - polygamma - * - zeta - * - betainc - * - * Bessel Functions - * - bessel_i0 - * - bessel_i0e - * - bessel_i1 - * - bessel_i1e - * - bessel_j0 - * - bessel_j1 - * - bessel_k0 - * - bessel_k0e - * - bessel_k1 - * - bessel_k1e - * - bessel_y0 - * - bessel_y1 - * - * \code - * #include <unsupported/Eigen/SpecialFunctions> - * \endcode - */ -//@{ - -} - -#include "src/SpecialFunctions/BesselFunctionsImpl.h" -#include "src/SpecialFunctions/BesselFunctionsPacketMath.h" -#include "src/SpecialFunctions/BesselFunctionsHalf.h" -#include "src/SpecialFunctions/BesselFunctionsFunctors.h" -#include "src/SpecialFunctions/BesselFunctionsArrayAPI.h" -#include "src/SpecialFunctions/SpecialFunctionsImpl.h" -#if defined(EIGEN_HIPCC) -#include "src/SpecialFunctions/HipVectorCompatibility.h" -#endif -#include "src/SpecialFunctions/SpecialFunctionsPacketMath.h" -#include "src/SpecialFunctions/SpecialFunctionsHalf.h" -#include "src/SpecialFunctions/SpecialFunctionsFunctors.h" -#include "src/SpecialFunctions/SpecialFunctionsArrayAPI.h" - -#if defined EIGEN_VECTORIZE_GPU - #include "src/SpecialFunctions/arch/GPU/GpuSpecialFunctions.h" -#endif - -namespace Eigen { -//@} -} - - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SPECIALFUNCTIONS_MODULE diff --git a/external/eigen/include/eigen3/unsupported/Eigen/Splines b/external/eigen/include/eigen3/unsupported/Eigen/Splines deleted file mode 100644 index 2ca58136..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/Splines +++ /dev/null @@ -1,35 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 20010-2011 Hauke Heibel <hauke.heibel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPLINES_MODULE_H -#define EIGEN_SPLINES_MODULE_H - -namespace Eigen -{ -/** - * \defgroup Splines_Module Spline and spline fitting module - * - * This module provides a simple multi-dimensional spline class while - * offering most basic functionality to fit a spline to point sets. - * - * \code - * #include <unsupported/Eigen/Splines> - * \endcode - */ -} - -#include "../../Eigen/src/Core/util/DisableStupidWarnings.h" - -#include "src/Splines/SplineFwd.h" -#include "src/Splines/Spline.h" -#include "src/Splines/SplineFitting.h" - -#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_SPLINES_MODULE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffJacobian.h b/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffJacobian.h deleted file mode 100644 index 33b6c393..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffJacobian.h +++ /dev/null @@ -1,108 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_AUTODIFF_JACOBIAN_H -#define EIGEN_AUTODIFF_JACOBIAN_H - -namespace Eigen -{ - -template<typename Functor> class AutoDiffJacobian : public Functor -{ -public: - AutoDiffJacobian() : Functor() {} - AutoDiffJacobian(const Functor& f) : Functor(f) {} - - // forward constructors -#if EIGEN_HAS_VARIADIC_TEMPLATES - template<typename... T> - AutoDiffJacobian(const T& ...Values) : Functor(Values...) {} -#else - template<typename T0> - AutoDiffJacobian(const T0& a0) : Functor(a0) {} - template<typename T0, typename T1> - AutoDiffJacobian(const T0& a0, const T1& a1) : Functor(a0, a1) {} - template<typename T0, typename T1, typename T2> - AutoDiffJacobian(const T0& a0, const T1& a1, const T2& a2) : Functor(a0, a1, a2) {} -#endif - - typedef typename Functor::InputType InputType; - typedef typename Functor::ValueType ValueType; - typedef typename ValueType::Scalar Scalar; - - enum { - InputsAtCompileTime = InputType::RowsAtCompileTime, - ValuesAtCompileTime = ValueType::RowsAtCompileTime - }; - - typedef Matrix<Scalar, ValuesAtCompileTime, InputsAtCompileTime> JacobianType; - typedef typename JacobianType::Index Index; - - typedef Matrix<Scalar, InputsAtCompileTime, 1> DerivativeType; - typedef AutoDiffScalar<DerivativeType> ActiveScalar; - - typedef Matrix<ActiveScalar, InputsAtCompileTime, 1> ActiveInput; - typedef Matrix<ActiveScalar, ValuesAtCompileTime, 1> ActiveValue; - -#if EIGEN_HAS_VARIADIC_TEMPLATES - // Some compilers don't accept variadic parameters after a default parameter, - // i.e., we can't just write _jac=0 but we need to overload operator(): - EIGEN_STRONG_INLINE - void operator() (const InputType& x, ValueType* v) const - { - this->operator()(x, v, 0); - } - template<typename... ParamsType> - void operator() (const InputType& x, ValueType* v, JacobianType* _jac, - const ParamsType&... Params) const -#else - void operator() (const InputType& x, ValueType* v, JacobianType* _jac=0) const -#endif - { - eigen_assert(v!=0); - - if (!_jac) - { -#if EIGEN_HAS_VARIADIC_TEMPLATES - Functor::operator()(x, v, Params...); -#else - Functor::operator()(x, v); -#endif - return; - } - - JacobianType& jac = *_jac; - - ActiveInput ax = x.template cast<ActiveScalar>(); - ActiveValue av(jac.rows()); - - if(InputsAtCompileTime==Dynamic) - for (Index j=0; j<jac.rows(); j++) - av[j].derivatives().resize(x.rows()); - - for (Index i=0; i<jac.cols(); i++) - ax[i].derivatives() = DerivativeType::Unit(x.rows(),i); - -#if EIGEN_HAS_VARIADIC_TEMPLATES - Functor::operator()(ax, &av, Params...); -#else - Functor::operator()(ax, &av); -#endif - - for (Index i=0; i<jac.rows(); i++) - { - (*v)[i] = av[i].value(); - jac.row(i) = av[i].derivatives(); - } - } -}; - -} - -#endif // EIGEN_AUTODIFF_JACOBIAN_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h b/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h deleted file mode 100644 index 0ef159e3..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h +++ /dev/null @@ -1,730 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_AUTODIFF_SCALAR_H -#define EIGEN_AUTODIFF_SCALAR_H - -namespace Eigen { - -namespace internal { - -template<typename A, typename B> -struct make_coherent_impl { - static void run(A&, B&) {} -}; - -// resize a to match b is a.size()==0, and conversely. -template<typename A, typename B> -void make_coherent(const A& a, const B&b) -{ - make_coherent_impl<A,B>::run(a.const_cast_derived(), b.const_cast_derived()); -} - -template<typename _DerType, bool Enable> struct auto_diff_special_op; - -} // end namespace internal - -template<typename _DerType> class AutoDiffScalar; - -template<typename NewDerType> -inline AutoDiffScalar<NewDerType> MakeAutoDiffScalar(const typename NewDerType::Scalar& value, const NewDerType &der) { - return AutoDiffScalar<NewDerType>(value,der); -} - -/** \class AutoDiffScalar - * \brief A scalar type replacement with automatic differentation capability - * - * \param _DerType the vector type used to store/represent the derivatives. The base scalar type - * as well as the number of derivatives to compute are determined from this type. - * Typical choices include, e.g., \c Vector4f for 4 derivatives, or \c VectorXf - * if the number of derivatives is not known at compile time, and/or, the number - * of derivatives is large. - * Note that _DerType can also be a reference (e.g., \c VectorXf&) to wrap a - * existing vector into an AutoDiffScalar. - * Finally, _DerType can also be any Eigen compatible expression. - * - * This class represents a scalar value while tracking its respective derivatives using Eigen's expression - * template mechanism. - * - * It supports the following list of global math function: - * - std::abs, std::sqrt, std::pow, std::exp, std::log, std::sin, std::cos, - * - internal::abs, internal::sqrt, numext::pow, internal::exp, internal::log, internal::sin, internal::cos, - * - internal::conj, internal::real, internal::imag, numext::abs2. - * - * AutoDiffScalar can be used as the scalar type of an Eigen::Matrix object. However, - * in that case, the expression template mechanism only occurs at the top Matrix level, - * while derivatives are computed right away. - * - */ - -template<typename _DerType> -class AutoDiffScalar - : public internal::auto_diff_special_op - <_DerType, !internal::is_same<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar, - typename NumTraits<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar>::Real>::value> -{ - public: - typedef internal::auto_diff_special_op - <_DerType, !internal::is_same<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar, - typename NumTraits<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar>::Real>::value> Base; - typedef typename internal::remove_all<_DerType>::type DerType; - typedef typename internal::traits<DerType>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real Real; - - using Base::operator+; - using Base::operator*; - - /** Default constructor without any initialization. */ - AutoDiffScalar() {} - - /** Constructs an active scalar from its \a value, - and initializes the \a nbDer derivatives such that it corresponds to the \a derNumber -th variable */ - AutoDiffScalar(const Scalar& value, int nbDer, int derNumber) - : m_value(value), m_derivatives(DerType::Zero(nbDer)) - { - m_derivatives.coeffRef(derNumber) = Scalar(1); - } - - /** Conversion from a scalar constant to an active scalar. - * The derivatives are set to zero. */ - /*explicit*/ AutoDiffScalar(const Real& value) - : m_value(value) - { - if(m_derivatives.size()>0) - m_derivatives.setZero(); - } - - /** Constructs an active scalar from its \a value and derivatives \a der */ - AutoDiffScalar(const Scalar& value, const DerType& der) - : m_value(value), m_derivatives(der) - {} - - template<typename OtherDerType> - AutoDiffScalar(const AutoDiffScalar<OtherDerType>& other -#ifndef EIGEN_PARSED_BY_DOXYGEN - , typename internal::enable_if< - internal::is_same<Scalar, typename internal::traits<typename internal::remove_all<OtherDerType>::type>::Scalar>::value - && internal::is_convertible<OtherDerType,DerType>::value , void*>::type = 0 -#endif - ) - : m_value(other.value()), m_derivatives(other.derivatives()) - {} - - friend std::ostream & operator << (std::ostream & s, const AutoDiffScalar& a) - { - return s << a.value(); - } - - AutoDiffScalar(const AutoDiffScalar& other) - : m_value(other.value()), m_derivatives(other.derivatives()) - {} - - template<typename OtherDerType> - inline AutoDiffScalar& operator=(const AutoDiffScalar<OtherDerType>& other) - { - m_value = other.value(); - m_derivatives = other.derivatives(); - return *this; - } - - inline AutoDiffScalar& operator=(const AutoDiffScalar& other) - { - m_value = other.value(); - m_derivatives = other.derivatives(); - return *this; - } - - inline AutoDiffScalar& operator=(const Scalar& other) - { - m_value = other; - if(m_derivatives.size()>0) - m_derivatives.setZero(); - return *this; - } - -// inline operator const Scalar& () const { return m_value; } -// inline operator Scalar& () { return m_value; } - - inline const Scalar& value() const { return m_value; } - inline Scalar& value() { return m_value; } - - inline const DerType& derivatives() const { return m_derivatives; } - inline DerType& derivatives() { return m_derivatives; } - - inline bool operator< (const Scalar& other) const { return m_value < other; } - inline bool operator<=(const Scalar& other) const { return m_value <= other; } - inline bool operator> (const Scalar& other) const { return m_value > other; } - inline bool operator>=(const Scalar& other) const { return m_value >= other; } - inline bool operator==(const Scalar& other) const { return m_value == other; } - inline bool operator!=(const Scalar& other) const { return m_value != other; } - - friend inline bool operator< (const Scalar& a, const AutoDiffScalar& b) { return a < b.value(); } - friend inline bool operator<=(const Scalar& a, const AutoDiffScalar& b) { return a <= b.value(); } - friend inline bool operator> (const Scalar& a, const AutoDiffScalar& b) { return a > b.value(); } - friend inline bool operator>=(const Scalar& a, const AutoDiffScalar& b) { return a >= b.value(); } - friend inline bool operator==(const Scalar& a, const AutoDiffScalar& b) { return a == b.value(); } - friend inline bool operator!=(const Scalar& a, const AutoDiffScalar& b) { return a != b.value(); } - - template<typename OtherDerType> inline bool operator< (const AutoDiffScalar<OtherDerType>& b) const { return m_value < b.value(); } - template<typename OtherDerType> inline bool operator<=(const AutoDiffScalar<OtherDerType>& b) const { return m_value <= b.value(); } - template<typename OtherDerType> inline bool operator> (const AutoDiffScalar<OtherDerType>& b) const { return m_value > b.value(); } - template<typename OtherDerType> inline bool operator>=(const AutoDiffScalar<OtherDerType>& b) const { return m_value >= b.value(); } - template<typename OtherDerType> inline bool operator==(const AutoDiffScalar<OtherDerType>& b) const { return m_value == b.value(); } - template<typename OtherDerType> inline bool operator!=(const AutoDiffScalar<OtherDerType>& b) const { return m_value != b.value(); } - - inline const AutoDiffScalar<DerType&> operator+(const Scalar& other) const - { - return AutoDiffScalar<DerType&>(m_value + other, m_derivatives); - } - - friend inline const AutoDiffScalar<DerType&> operator+(const Scalar& a, const AutoDiffScalar& b) - { - return AutoDiffScalar<DerType&>(a + b.value(), b.derivatives()); - } - -// inline const AutoDiffScalar<DerType&> operator+(const Real& other) const -// { -// return AutoDiffScalar<DerType&>(m_value + other, m_derivatives); -// } - -// friend inline const AutoDiffScalar<DerType&> operator+(const Real& a, const AutoDiffScalar& b) -// { -// return AutoDiffScalar<DerType&>(a + b.value(), b.derivatives()); -// } - - inline AutoDiffScalar& operator+=(const Scalar& other) - { - value() += other; - return *this; - } - - template<typename OtherDerType> - inline const AutoDiffScalar<CwiseBinaryOp<internal::scalar_sum_op<Scalar>,const DerType,const typename internal::remove_all<OtherDerType>::type> > - operator+(const AutoDiffScalar<OtherDerType>& other) const - { - internal::make_coherent(m_derivatives, other.derivatives()); - return AutoDiffScalar<CwiseBinaryOp<internal::scalar_sum_op<Scalar>,const DerType,const typename internal::remove_all<OtherDerType>::type> >( - m_value + other.value(), - m_derivatives + other.derivatives()); - } - - template<typename OtherDerType> - inline AutoDiffScalar& - operator+=(const AutoDiffScalar<OtherDerType>& other) - { - (*this) = (*this) + other; - return *this; - } - - inline const AutoDiffScalar<DerType&> operator-(const Scalar& b) const - { - return AutoDiffScalar<DerType&>(m_value - b, m_derivatives); - } - - friend inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType> > - operator-(const Scalar& a, const AutoDiffScalar& b) - { - return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType> > - (a - b.value(), -b.derivatives()); - } - - inline AutoDiffScalar& operator-=(const Scalar& other) - { - value() -= other; - return *this; - } - - template<typename OtherDerType> - inline const AutoDiffScalar<CwiseBinaryOp<internal::scalar_difference_op<Scalar>, const DerType,const typename internal::remove_all<OtherDerType>::type> > - operator-(const AutoDiffScalar<OtherDerType>& other) const - { - internal::make_coherent(m_derivatives, other.derivatives()); - return AutoDiffScalar<CwiseBinaryOp<internal::scalar_difference_op<Scalar>, const DerType,const typename internal::remove_all<OtherDerType>::type> >( - m_value - other.value(), - m_derivatives - other.derivatives()); - } - - template<typename OtherDerType> - inline AutoDiffScalar& - operator-=(const AutoDiffScalar<OtherDerType>& other) - { - *this = *this - other; - return *this; - } - - inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType> > - operator-() const - { - return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType> >( - -m_value, - -m_derivatives); - } - - inline const AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product) > - operator*(const Scalar& other) const - { - return MakeAutoDiffScalar(m_value * other, m_derivatives * other); - } - - friend inline const AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product) > - operator*(const Scalar& other, const AutoDiffScalar& a) - { - return MakeAutoDiffScalar(a.value() * other, a.derivatives() * other); - } - -// inline const AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type > -// operator*(const Real& other) const -// { -// return AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type >( -// m_value * other, -// (m_derivatives * other)); -// } -// -// friend inline const AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type > -// operator*(const Real& other, const AutoDiffScalar& a) -// { -// return AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type >( -// a.value() * other, -// a.derivatives() * other); -// } - - inline const AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product) > - operator/(const Scalar& other) const - { - return MakeAutoDiffScalar(m_value / other, (m_derivatives * (Scalar(1)/other))); - } - - friend inline const AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product) > - operator/(const Scalar& other, const AutoDiffScalar& a) - { - return MakeAutoDiffScalar(other / a.value(), a.derivatives() * (Scalar(-other) / (a.value()*a.value()))); - } - -// inline const AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type > -// operator/(const Real& other) const -// { -// return AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type >( -// m_value / other, -// (m_derivatives * (Real(1)/other))); -// } -// -// friend inline const AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type > -// operator/(const Real& other, const AutoDiffScalar& a) -// { -// return AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type >( -// other / a.value(), -// a.derivatives() * (-Real(1)/other)); -// } - - template<typename OtherDerType> - inline const AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE( - CwiseBinaryOp<internal::scalar_difference_op<Scalar> EIGEN_COMMA - const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product) EIGEN_COMMA - const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(typename internal::remove_all<OtherDerType>::type,Scalar,product) >,Scalar,product) > - operator/(const AutoDiffScalar<OtherDerType>& other) const - { - internal::make_coherent(m_derivatives, other.derivatives()); - return MakeAutoDiffScalar( - m_value / other.value(), - ((m_derivatives * other.value()) - (other.derivatives() * m_value)) - * (Scalar(1)/(other.value()*other.value()))); - } - - template<typename OtherDerType> - inline const AutoDiffScalar<CwiseBinaryOp<internal::scalar_sum_op<Scalar>, - const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product), - const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(typename internal::remove_all<OtherDerType>::type,Scalar,product) > > - operator*(const AutoDiffScalar<OtherDerType>& other) const - { - internal::make_coherent(m_derivatives, other.derivatives()); - return MakeAutoDiffScalar( - m_value * other.value(), - (m_derivatives * other.value()) + (other.derivatives() * m_value)); - } - - inline AutoDiffScalar& operator*=(const Scalar& other) - { - *this = *this * other; - return *this; - } - - template<typename OtherDerType> - inline AutoDiffScalar& operator*=(const AutoDiffScalar<OtherDerType>& other) - { - *this = *this * other; - return *this; - } - - inline AutoDiffScalar& operator/=(const Scalar& other) - { - *this = *this / other; - return *this; - } - - template<typename OtherDerType> - inline AutoDiffScalar& operator/=(const AutoDiffScalar<OtherDerType>& other) - { - *this = *this / other; - return *this; - } - - protected: - Scalar m_value; - DerType m_derivatives; - -}; - -namespace internal { - -template<typename _DerType> -struct auto_diff_special_op<_DerType, true> -// : auto_diff_scalar_op<_DerType, typename NumTraits<Scalar>::Real, -// is_same<Scalar,typename NumTraits<Scalar>::Real>::value> -{ - typedef typename remove_all<_DerType>::type DerType; - typedef typename traits<DerType>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real Real; - -// typedef auto_diff_scalar_op<_DerType, typename NumTraits<Scalar>::Real, -// is_same<Scalar,typename NumTraits<Scalar>::Real>::value> Base; - -// using Base::operator+; -// using Base::operator+=; -// using Base::operator-; -// using Base::operator-=; -// using Base::operator*; -// using Base::operator*=; - - const AutoDiffScalar<_DerType>& derived() const { return *static_cast<const AutoDiffScalar<_DerType>*>(this); } - AutoDiffScalar<_DerType>& derived() { return *static_cast<AutoDiffScalar<_DerType>*>(this); } - - - inline const AutoDiffScalar<DerType&> operator+(const Real& other) const - { - return AutoDiffScalar<DerType&>(derived().value() + other, derived().derivatives()); - } - - friend inline const AutoDiffScalar<DerType&> operator+(const Real& a, const AutoDiffScalar<_DerType>& b) - { - return AutoDiffScalar<DerType&>(a + b.value(), b.derivatives()); - } - - inline AutoDiffScalar<_DerType>& operator+=(const Real& other) - { - derived().value() += other; - return derived(); - } - - - inline const AutoDiffScalar<typename CwiseUnaryOp<bind2nd_op<scalar_product_op<Scalar,Real> >, DerType>::Type > - operator*(const Real& other) const - { - return AutoDiffScalar<typename CwiseUnaryOp<bind2nd_op<scalar_product_op<Scalar,Real> >, DerType>::Type >( - derived().value() * other, - derived().derivatives() * other); - } - - friend inline const AutoDiffScalar<typename CwiseUnaryOp<bind1st_op<scalar_product_op<Real,Scalar> >, DerType>::Type > - operator*(const Real& other, const AutoDiffScalar<_DerType>& a) - { - return AutoDiffScalar<typename CwiseUnaryOp<bind1st_op<scalar_product_op<Real,Scalar> >, DerType>::Type >( - a.value() * other, - a.derivatives() * other); - } - - inline AutoDiffScalar<_DerType>& operator*=(const Scalar& other) - { - *this = *this * other; - return derived(); - } -}; - -template<typename _DerType> -struct auto_diff_special_op<_DerType, false> -{ - void operator*() const; - void operator-() const; - void operator+() const; -}; - -template<typename BinOp, typename A, typename B, typename RefType> -void make_coherent_expression(CwiseBinaryOp<BinOp,A,B> xpr, const RefType &ref) -{ - make_coherent(xpr.const_cast_derived().lhs(), ref); - make_coherent(xpr.const_cast_derived().rhs(), ref); -} - -template<typename UnaryOp, typename A, typename RefType> -void make_coherent_expression(const CwiseUnaryOp<UnaryOp,A> &xpr, const RefType &ref) -{ - make_coherent(xpr.nestedExpression().const_cast_derived(), ref); -} - -// needed for compilation only -template<typename UnaryOp, typename A, typename RefType> -void make_coherent_expression(const CwiseNullaryOp<UnaryOp,A> &, const RefType &) -{} - -template<typename A_Scalar, int A_Rows, int A_Cols, int A_Options, int A_MaxRows, int A_MaxCols, typename B> -struct make_coherent_impl<Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols>, B> { - typedef Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols> A; - static void run(A& a, B& b) { - if((A_Rows==Dynamic || A_Cols==Dynamic) && (a.size()==0)) - { - a.resize(b.size()); - a.setZero(); - } - else if (B::SizeAtCompileTime==Dynamic && a.size()!=0 && b.size()==0) - { - make_coherent_expression(b,a); - } - } -}; - -template<typename A, typename B_Scalar, int B_Rows, int B_Cols, int B_Options, int B_MaxRows, int B_MaxCols> -struct make_coherent_impl<A, Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols> > { - typedef Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols> B; - static void run(A& a, B& b) { - if((B_Rows==Dynamic || B_Cols==Dynamic) && (b.size()==0)) - { - b.resize(a.size()); - b.setZero(); - } - else if (A::SizeAtCompileTime==Dynamic && b.size()!=0 && a.size()==0) - { - make_coherent_expression(a,b); - } - } -}; - -template<typename A_Scalar, int A_Rows, int A_Cols, int A_Options, int A_MaxRows, int A_MaxCols, - typename B_Scalar, int B_Rows, int B_Cols, int B_Options, int B_MaxRows, int B_MaxCols> -struct make_coherent_impl<Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols>, - Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols> > { - typedef Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols> A; - typedef Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols> B; - static void run(A& a, B& b) { - if((A_Rows==Dynamic || A_Cols==Dynamic) && (a.size()==0)) - { - a.resize(b.size()); - a.setZero(); - } - else if((B_Rows==Dynamic || B_Cols==Dynamic) && (b.size()==0)) - { - b.resize(a.size()); - b.setZero(); - } - } -}; - -} // end namespace internal - -template<typename DerType, typename BinOp> -struct ScalarBinaryOpTraits<AutoDiffScalar<DerType>,typename DerType::Scalar,BinOp> -{ - typedef AutoDiffScalar<DerType> ReturnType; -}; - -template<typename DerType, typename BinOp> -struct ScalarBinaryOpTraits<typename DerType::Scalar,AutoDiffScalar<DerType>, BinOp> -{ - typedef AutoDiffScalar<DerType> ReturnType; -}; - - -// The following is an attempt to let Eigen's known about expression template, but that's more tricky! - -// template<typename DerType, typename BinOp> -// struct ScalarBinaryOpTraits<AutoDiffScalar<DerType>,AutoDiffScalar<DerType>, BinOp> -// { -// enum { Defined = 1 }; -// typedef AutoDiffScalar<typename DerType::PlainObject> ReturnType; -// }; -// -// template<typename DerType1,typename DerType2, typename BinOp> -// struct ScalarBinaryOpTraits<AutoDiffScalar<DerType1>,AutoDiffScalar<DerType2>, BinOp> -// { -// enum { Defined = 1 };//internal::is_same<typename DerType1::Scalar,typename DerType2::Scalar>::value }; -// typedef AutoDiffScalar<typename DerType1::PlainObject> ReturnType; -// }; - -#define EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(FUNC,CODE) \ - template<typename DerType> \ - inline const Eigen::AutoDiffScalar< \ - EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(typename Eigen::internal::remove_all<DerType>::type, typename Eigen::internal::traits<typename Eigen::internal::remove_all<DerType>::type>::Scalar, product) > \ - FUNC(const Eigen::AutoDiffScalar<DerType>& x) { \ - using namespace Eigen; \ - typedef typename Eigen::internal::traits<typename Eigen::internal::remove_all<DerType>::type>::Scalar Scalar; \ - EIGEN_UNUSED_VARIABLE(sizeof(Scalar)); \ - CODE; \ - } - -template<typename DerType> -struct CleanedUpDerType { - typedef AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> type; -}; - -template<typename DerType> -inline const AutoDiffScalar<DerType>& conj(const AutoDiffScalar<DerType>& x) { return x; } -template<typename DerType> -inline const AutoDiffScalar<DerType>& real(const AutoDiffScalar<DerType>& x) { return x; } -template<typename DerType> -inline typename DerType::Scalar imag(const AutoDiffScalar<DerType>&) { return 0.; } -template<typename DerType, typename T> -inline typename CleanedUpDerType<DerType>::type (min)(const AutoDiffScalar<DerType>& x, const T& y) { - typedef typename CleanedUpDerType<DerType>::type ADS; - return (x <= y ? ADS(x) : ADS(y)); -} -template<typename DerType, typename T> -inline typename CleanedUpDerType<DerType>::type (max)(const AutoDiffScalar<DerType>& x, const T& y) { - typedef typename CleanedUpDerType<DerType>::type ADS; - return (x >= y ? ADS(x) : ADS(y)); -} -template<typename DerType, typename T> -inline typename CleanedUpDerType<DerType>::type (min)(const T& x, const AutoDiffScalar<DerType>& y) { - typedef typename CleanedUpDerType<DerType>::type ADS; - return (x < y ? ADS(x) : ADS(y)); -} -template<typename DerType, typename T> -inline typename CleanedUpDerType<DerType>::type (max)(const T& x, const AutoDiffScalar<DerType>& y) { - typedef typename CleanedUpDerType<DerType>::type ADS; - return (x > y ? ADS(x) : ADS(y)); -} -template<typename DerType> -inline typename CleanedUpDerType<DerType>::type (min)(const AutoDiffScalar<DerType>& x, const AutoDiffScalar<DerType>& y) { - return (x.value() < y.value() ? x : y); -} -template<typename DerType> -inline typename CleanedUpDerType<DerType>::type (max)(const AutoDiffScalar<DerType>& x, const AutoDiffScalar<DerType>& y) { - return (x.value() >= y.value() ? x : y); -} - - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs, - using std::abs; - return Eigen::MakeAutoDiffScalar(abs(x.value()), x.derivatives() * (x.value()<0 ? -1 : 1) );) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs2, - using numext::abs2; - return Eigen::MakeAutoDiffScalar(abs2(x.value()), x.derivatives() * (Scalar(2)*x.value()));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sqrt, - using std::sqrt; - Scalar sqrtx = sqrt(x.value()); - return Eigen::MakeAutoDiffScalar(sqrtx,x.derivatives() * (Scalar(0.5) / sqrtx));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(cos, - using std::cos; - using std::sin; - return Eigen::MakeAutoDiffScalar(cos(x.value()), x.derivatives() * (-sin(x.value())));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sin, - using std::sin; - using std::cos; - return Eigen::MakeAutoDiffScalar(sin(x.value()),x.derivatives() * cos(x.value()));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(exp, - using std::exp; - Scalar expx = exp(x.value()); - return Eigen::MakeAutoDiffScalar(expx,x.derivatives() * expx);) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(log, - using std::log; - return Eigen::MakeAutoDiffScalar(log(x.value()),x.derivatives() * (Scalar(1)/x.value()));) - -template<typename DerType> -inline const Eigen::AutoDiffScalar< -EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(typename internal::remove_all<DerType>::type,typename internal::traits<typename internal::remove_all<DerType>::type>::Scalar,product) > -pow(const Eigen::AutoDiffScalar<DerType> &x, const typename internal::traits<typename internal::remove_all<DerType>::type>::Scalar &y) -{ - using namespace Eigen; - using std::pow; - return Eigen::MakeAutoDiffScalar(pow(x.value(),y), x.derivatives() * (y * pow(x.value(),y-1))); -} - - -template<typename DerTypeA,typename DerTypeB> -inline const AutoDiffScalar<Matrix<typename internal::traits<typename internal::remove_all<DerTypeA>::type>::Scalar,Dynamic,1> > -atan2(const AutoDiffScalar<DerTypeA>& a, const AutoDiffScalar<DerTypeB>& b) -{ - using std::atan2; - typedef typename internal::traits<typename internal::remove_all<DerTypeA>::type>::Scalar Scalar; - typedef AutoDiffScalar<Matrix<Scalar,Dynamic,1> > PlainADS; - PlainADS ret; - ret.value() = atan2(a.value(), b.value()); - - Scalar squared_hypot = a.value() * a.value() + b.value() * b.value(); - - // if (squared_hypot==0) the derivation is undefined and the following results in a NaN: - ret.derivatives() = (a.derivatives() * b.value() - a.value() * b.derivatives()) / squared_hypot; - - return ret; -} - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(tan, - using std::tan; - using std::cos; - return Eigen::MakeAutoDiffScalar(tan(x.value()),x.derivatives() * (Scalar(1)/numext::abs2(cos(x.value()))));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(asin, - using std::sqrt; - using std::asin; - return Eigen::MakeAutoDiffScalar(asin(x.value()),x.derivatives() * (Scalar(1)/sqrt(1-numext::abs2(x.value()))));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(acos, - using std::sqrt; - using std::acos; - return Eigen::MakeAutoDiffScalar(acos(x.value()),x.derivatives() * (Scalar(-1)/sqrt(1-numext::abs2(x.value()))));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(tanh, - using std::cosh; - using std::tanh; - return Eigen::MakeAutoDiffScalar(tanh(x.value()),x.derivatives() * (Scalar(1)/numext::abs2(cosh(x.value()))));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sinh, - using std::sinh; - using std::cosh; - return Eigen::MakeAutoDiffScalar(sinh(x.value()),x.derivatives() * cosh(x.value()));) - -EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(cosh, - using std::sinh; - using std::cosh; - return Eigen::MakeAutoDiffScalar(cosh(x.value()),x.derivatives() * sinh(x.value()));) - -#undef EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY - -template<typename DerType> struct NumTraits<AutoDiffScalar<DerType> > - : NumTraits< typename NumTraits<typename internal::remove_all<DerType>::type::Scalar>::Real > -{ - typedef typename internal::remove_all<DerType>::type DerTypeCleaned; - typedef AutoDiffScalar<Matrix<typename NumTraits<typename DerTypeCleaned::Scalar>::Real,DerTypeCleaned::RowsAtCompileTime,DerTypeCleaned::ColsAtCompileTime, - 0, DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime> > Real; - typedef AutoDiffScalar<DerType> NonInteger; - typedef AutoDiffScalar<DerType> Nested; - typedef typename NumTraits<typename DerTypeCleaned::Scalar>::Literal Literal; - enum{ - RequireInitialization = 1 - }; -}; - -} - -namespace std { - -template <typename T> -class numeric_limits<Eigen::AutoDiffScalar<T> > - : public numeric_limits<typename T::Scalar> {}; - -template <typename T> -class numeric_limits<Eigen::AutoDiffScalar<T&> > - : public numeric_limits<typename T::Scalar> {}; - -} // namespace std - -#endif // EIGEN_AUTODIFF_SCALAR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffVector.h b/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffVector.h deleted file mode 100644 index 8c2d0483..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/AutoDiff/AutoDiffVector.h +++ /dev/null @@ -1,220 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_AUTODIFF_VECTOR_H -#define EIGEN_AUTODIFF_VECTOR_H - -namespace Eigen { - -/* \class AutoDiffScalar - * \brief A scalar type replacement with automatic differentation capability - * - * \param DerType the vector type used to store/represent the derivatives (e.g. Vector3f) - * - * This class represents a scalar value while tracking its respective derivatives. - * - * It supports the following list of global math function: - * - std::abs, std::sqrt, std::pow, std::exp, std::log, std::sin, std::cos, - * - internal::abs, internal::sqrt, numext::pow, internal::exp, internal::log, internal::sin, internal::cos, - * - internal::conj, internal::real, internal::imag, numext::abs2. - * - * AutoDiffScalar can be used as the scalar type of an Eigen::Matrix object. However, - * in that case, the expression template mechanism only occurs at the top Matrix level, - * while derivatives are computed right away. - * - */ -template<typename ValueType, typename JacobianType> -class AutoDiffVector -{ - public: - //typedef typename internal::traits<ValueType>::Scalar Scalar; - typedef typename internal::traits<ValueType>::Scalar BaseScalar; - typedef AutoDiffScalar<Matrix<BaseScalar,JacobianType::RowsAtCompileTime,1> > ActiveScalar; - typedef ActiveScalar Scalar; - typedef AutoDiffScalar<typename JacobianType::ColXpr> CoeffType; - typedef typename JacobianType::Index Index; - - inline AutoDiffVector() {} - - inline AutoDiffVector(const ValueType& values) - : m_values(values) - { - m_jacobian.setZero(); - } - - - CoeffType operator[] (Index i) { return CoeffType(m_values[i], m_jacobian.col(i)); } - const CoeffType operator[] (Index i) const { return CoeffType(m_values[i], m_jacobian.col(i)); } - - CoeffType operator() (Index i) { return CoeffType(m_values[i], m_jacobian.col(i)); } - const CoeffType operator() (Index i) const { return CoeffType(m_values[i], m_jacobian.col(i)); } - - CoeffType coeffRef(Index i) { return CoeffType(m_values[i], m_jacobian.col(i)); } - const CoeffType coeffRef(Index i) const { return CoeffType(m_values[i], m_jacobian.col(i)); } - - Index size() const { return m_values.size(); } - - // FIXME here we could return an expression of the sum - Scalar sum() const { /*std::cerr << "sum \n\n";*/ /*std::cerr << m_jacobian.rowwise().sum() << "\n\n";*/ return Scalar(m_values.sum(), m_jacobian.rowwise().sum()); } - - - inline AutoDiffVector(const ValueType& values, const JacobianType& jac) - : m_values(values), m_jacobian(jac) - {} - - template<typename OtherValueType, typename OtherJacobianType> - inline AutoDiffVector(const AutoDiffVector<OtherValueType, OtherJacobianType>& other) - : m_values(other.values()), m_jacobian(other.jacobian()) - {} - - inline AutoDiffVector(const AutoDiffVector& other) - : m_values(other.values()), m_jacobian(other.jacobian()) - {} - - template<typename OtherValueType, typename OtherJacobianType> - inline AutoDiffVector& operator=(const AutoDiffVector<OtherValueType, OtherJacobianType>& other) - { - m_values = other.values(); - m_jacobian = other.jacobian(); - return *this; - } - - inline AutoDiffVector& operator=(const AutoDiffVector& other) - { - m_values = other.values(); - m_jacobian = other.jacobian(); - return *this; - } - - inline const ValueType& values() const { return m_values; } - inline ValueType& values() { return m_values; } - - inline const JacobianType& jacobian() const { return m_jacobian; } - inline JacobianType& jacobian() { return m_jacobian; } - - template<typename OtherValueType,typename OtherJacobianType> - inline const AutoDiffVector< - typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>,ValueType,OtherValueType>::Type, - typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>,JacobianType,OtherJacobianType>::Type > - operator+(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) const - { - return AutoDiffVector< - typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>,ValueType,OtherValueType>::Type, - typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>,JacobianType,OtherJacobianType>::Type >( - m_values + other.values(), - m_jacobian + other.jacobian()); - } - - template<typename OtherValueType, typename OtherJacobianType> - inline AutoDiffVector& - operator+=(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) - { - m_values += other.values(); - m_jacobian += other.jacobian(); - return *this; - } - - template<typename OtherValueType,typename OtherJacobianType> - inline const AutoDiffVector< - typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>,ValueType,OtherValueType>::Type, - typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>,JacobianType,OtherJacobianType>::Type > - operator-(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) const - { - return AutoDiffVector< - typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>,ValueType,OtherValueType>::Type, - typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>,JacobianType,OtherJacobianType>::Type >( - m_values - other.values(), - m_jacobian - other.jacobian()); - } - - template<typename OtherValueType, typename OtherJacobianType> - inline AutoDiffVector& - operator-=(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) - { - m_values -= other.values(); - m_jacobian -= other.jacobian(); - return *this; - } - - inline const AutoDiffVector< - typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, ValueType>::Type, - typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, JacobianType>::Type > - operator-() const - { - return AutoDiffVector< - typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, ValueType>::Type, - typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, JacobianType>::Type >( - -m_values, - -m_jacobian); - } - - inline const AutoDiffVector< - typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type, - typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type> - operator*(const BaseScalar& other) const - { - return AutoDiffVector< - typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type, - typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type >( - m_values * other, - m_jacobian * other); - } - - friend inline const AutoDiffVector< - typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type, - typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type > - operator*(const Scalar& other, const AutoDiffVector& v) - { - return AutoDiffVector< - typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type, - typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type >( - v.values() * other, - v.jacobian() * other); - } - -// template<typename OtherValueType,typename OtherJacobianType> -// inline const AutoDiffVector< -// CwiseBinaryOp<internal::scalar_multiple_op<Scalar>, ValueType, OtherValueType> -// CwiseBinaryOp<internal::scalar_sum_op<Scalar>, -// CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>, -// CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, OtherJacobianType> > > -// operator*(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) const -// { -// return AutoDiffVector< -// CwiseBinaryOp<internal::scalar_multiple_op<Scalar>, ValueType, OtherValueType> -// CwiseBinaryOp<internal::scalar_sum_op<Scalar>, -// CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>, -// CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, OtherJacobianType> > >( -// m_values.cwise() * other.values(), -// (m_jacobian * other.values()) + (m_values * other.jacobian())); -// } - - inline AutoDiffVector& operator*=(const Scalar& other) - { - m_values *= other; - m_jacobian *= other; - return *this; - } - - template<typename OtherValueType,typename OtherJacobianType> - inline AutoDiffVector& operator*=(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) - { - *this = *this * other; - return *this; - } - - protected: - ValueType m_values; - JacobianType m_jacobian; - -}; - -} - -#endif // EIGEN_AUTODIFF_VECTOR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/BVH/BVAlgorithms.h b/external/eigen/include/eigen3/unsupported/Eigen/src/BVH/BVAlgorithms.h deleted file mode 100644 index 994c8af5..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/BVH/BVAlgorithms.h +++ /dev/null @@ -1,293 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Ilya Baran <ibaran@mit.edu> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BVALGORITHMS_H -#define EIGEN_BVALGORITHMS_H - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename BVH, typename Intersector> -bool intersect_helper(const BVH &tree, Intersector &intersector, typename BVH::Index root) -{ - typedef typename BVH::Index Index; - typedef typename BVH::VolumeIterator VolIter; - typedef typename BVH::ObjectIterator ObjIter; - - VolIter vBegin = VolIter(), vEnd = VolIter(); - ObjIter oBegin = ObjIter(), oEnd = ObjIter(); - - std::vector<Index> todo(1, root); - - while(!todo.empty()) { - tree.getChildren(todo.back(), vBegin, vEnd, oBegin, oEnd); - todo.pop_back(); - - for(; vBegin != vEnd; ++vBegin) //go through child volumes - if(intersector.intersectVolume(tree.getVolume(*vBegin))) - todo.push_back(*vBegin); - - for(; oBegin != oEnd; ++oBegin) //go through child objects - if(intersector.intersectObject(*oBegin)) - return true; //intersector said to stop query - } - return false; -} -#endif //not EIGEN_PARSED_BY_DOXYGEN - -template<typename Volume1, typename Object1, typename Object2, typename Intersector> -struct intersector_helper1 -{ - intersector_helper1(const Object2 &inStored, Intersector &in) : stored(inStored), intersector(in) {} - bool intersectVolume(const Volume1 &vol) { return intersector.intersectVolumeObject(vol, stored); } - bool intersectObject(const Object1 &obj) { return intersector.intersectObjectObject(obj, stored); } - Object2 stored; - Intersector &intersector; -private: - intersector_helper1& operator=(const intersector_helper1&); -}; - -template<typename Volume2, typename Object2, typename Object1, typename Intersector> -struct intersector_helper2 -{ - intersector_helper2(const Object1 &inStored, Intersector &in) : stored(inStored), intersector(in) {} - bool intersectVolume(const Volume2 &vol) { return intersector.intersectObjectVolume(stored, vol); } - bool intersectObject(const Object2 &obj) { return intersector.intersectObjectObject(stored, obj); } - Object1 stored; - Intersector &intersector; -private: - intersector_helper2& operator=(const intersector_helper2&); -}; - -} // end namespace internal - -/** Given a BVH, runs the query encapsulated by \a intersector. - * The Intersector type must provide the following members: \code - bool intersectVolume(const BVH::Volume &volume) //returns true if volume intersects the query - bool intersectObject(const BVH::Object &object) //returns true if the search should terminate immediately - \endcode - */ -template<typename BVH, typename Intersector> -void BVIntersect(const BVH &tree, Intersector &intersector) -{ - internal::intersect_helper(tree, intersector, tree.getRootIndex()); -} - -/** Given two BVH's, runs the query on their Cartesian product encapsulated by \a intersector. - * The Intersector type must provide the following members: \code - bool intersectVolumeVolume(const BVH1::Volume &v1, const BVH2::Volume &v2) //returns true if product of volumes intersects the query - bool intersectVolumeObject(const BVH1::Volume &v1, const BVH2::Object &o2) //returns true if the volume-object product intersects the query - bool intersectObjectVolume(const BVH1::Object &o1, const BVH2::Volume &v2) //returns true if the volume-object product intersects the query - bool intersectObjectObject(const BVH1::Object &o1, const BVH2::Object &o2) //returns true if the search should terminate immediately - \endcode - */ -template<typename BVH1, typename BVH2, typename Intersector> -void BVIntersect(const BVH1 &tree1, const BVH2 &tree2, Intersector &intersector) //TODO: tandem descent when it makes sense -{ - typedef typename BVH1::Index Index1; - typedef typename BVH2::Index Index2; - typedef internal::intersector_helper1<typename BVH1::Volume, typename BVH1::Object, typename BVH2::Object, Intersector> Helper1; - typedef internal::intersector_helper2<typename BVH2::Volume, typename BVH2::Object, typename BVH1::Object, Intersector> Helper2; - typedef typename BVH1::VolumeIterator VolIter1; - typedef typename BVH1::ObjectIterator ObjIter1; - typedef typename BVH2::VolumeIterator VolIter2; - typedef typename BVH2::ObjectIterator ObjIter2; - - VolIter1 vBegin1 = VolIter1(), vEnd1 = VolIter1(); - ObjIter1 oBegin1 = ObjIter1(), oEnd1 = ObjIter1(); - VolIter2 vBegin2 = VolIter2(), vEnd2 = VolIter2(), vCur2 = VolIter2(); - ObjIter2 oBegin2 = ObjIter2(), oEnd2 = ObjIter2(), oCur2 = ObjIter2(); - - std::vector<std::pair<Index1, Index2> > todo(1, std::make_pair(tree1.getRootIndex(), tree2.getRootIndex())); - - while(!todo.empty()) { - tree1.getChildren(todo.back().first, vBegin1, vEnd1, oBegin1, oEnd1); - tree2.getChildren(todo.back().second, vBegin2, vEnd2, oBegin2, oEnd2); - todo.pop_back(); - - for(; vBegin1 != vEnd1; ++vBegin1) { //go through child volumes of first tree - const typename BVH1::Volume &vol1 = tree1.getVolume(*vBegin1); - for(vCur2 = vBegin2; vCur2 != vEnd2; ++vCur2) { //go through child volumes of second tree - if(intersector.intersectVolumeVolume(vol1, tree2.getVolume(*vCur2))) - todo.push_back(std::make_pair(*vBegin1, *vCur2)); - } - - for(oCur2 = oBegin2; oCur2 != oEnd2; ++oCur2) {//go through child objects of second tree - Helper1 helper(*oCur2, intersector); - if(internal::intersect_helper(tree1, helper, *vBegin1)) - return; //intersector said to stop query - } - } - - for(; oBegin1 != oEnd1; ++oBegin1) { //go through child objects of first tree - for(vCur2 = vBegin2; vCur2 != vEnd2; ++vCur2) { //go through child volumes of second tree - Helper2 helper(*oBegin1, intersector); - if(internal::intersect_helper(tree2, helper, *vCur2)) - return; //intersector said to stop query - } - - for(oCur2 = oBegin2; oCur2 != oEnd2; ++oCur2) {//go through child objects of second tree - if(intersector.intersectObjectObject(*oBegin1, *oCur2)) - return; //intersector said to stop query - } - } - } -} - -namespace internal { - -#ifndef EIGEN_PARSED_BY_DOXYGEN -template<typename BVH, typename Minimizer> -typename Minimizer::Scalar minimize_helper(const BVH &tree, Minimizer &minimizer, typename BVH::Index root, typename Minimizer::Scalar minimum) -{ - typedef typename Minimizer::Scalar Scalar; - typedef typename BVH::Index Index; - typedef std::pair<Scalar, Index> QueueElement; //first element is priority - typedef typename BVH::VolumeIterator VolIter; - typedef typename BVH::ObjectIterator ObjIter; - - VolIter vBegin = VolIter(), vEnd = VolIter(); - ObjIter oBegin = ObjIter(), oEnd = ObjIter(); - std::priority_queue<QueueElement, std::vector<QueueElement>, std::greater<QueueElement> > todo; //smallest is at the top - - todo.push(std::make_pair(Scalar(), root)); - - while(!todo.empty()) { - tree.getChildren(todo.top().second, vBegin, vEnd, oBegin, oEnd); - todo.pop(); - - for(; oBegin != oEnd; ++oBegin) //go through child objects - minimum = (std::min)(minimum, minimizer.minimumOnObject(*oBegin)); - - for(; vBegin != vEnd; ++vBegin) { //go through child volumes - Scalar val = minimizer.minimumOnVolume(tree.getVolume(*vBegin)); - if(val < minimum) - todo.push(std::make_pair(val, *vBegin)); - } - } - - return minimum; -} -#endif //not EIGEN_PARSED_BY_DOXYGEN - - -template<typename Volume1, typename Object1, typename Object2, typename Minimizer> -struct minimizer_helper1 -{ - typedef typename Minimizer::Scalar Scalar; - minimizer_helper1(const Object2 &inStored, Minimizer &m) : stored(inStored), minimizer(m) {} - Scalar minimumOnVolume(const Volume1 &vol) { return minimizer.minimumOnVolumeObject(vol, stored); } - Scalar minimumOnObject(const Object1 &obj) { return minimizer.minimumOnObjectObject(obj, stored); } - Object2 stored; - Minimizer &minimizer; -private: - minimizer_helper1& operator=(const minimizer_helper1&); -}; - -template<typename Volume2, typename Object2, typename Object1, typename Minimizer> -struct minimizer_helper2 -{ - typedef typename Minimizer::Scalar Scalar; - minimizer_helper2(const Object1 &inStored, Minimizer &m) : stored(inStored), minimizer(m) {} - Scalar minimumOnVolume(const Volume2 &vol) { return minimizer.minimumOnObjectVolume(stored, vol); } - Scalar minimumOnObject(const Object2 &obj) { return minimizer.minimumOnObjectObject(stored, obj); } - Object1 stored; - Minimizer &minimizer; -private: - minimizer_helper2& operator=(const minimizer_helper2&); -}; - -} // end namespace internal - -/** Given a BVH, runs the query encapsulated by \a minimizer. - * \returns the minimum value. - * The Minimizer type must provide the following members: \code - typedef Scalar //the numeric type of what is being minimized--not necessarily the Scalar type of the BVH (if it has one) - Scalar minimumOnVolume(const BVH::Volume &volume) - Scalar minimumOnObject(const BVH::Object &object) - \endcode - */ -template<typename BVH, typename Minimizer> -typename Minimizer::Scalar BVMinimize(const BVH &tree, Minimizer &minimizer) -{ - return internal::minimize_helper(tree, minimizer, tree.getRootIndex(), (std::numeric_limits<typename Minimizer::Scalar>::max)()); -} - -/** Given two BVH's, runs the query on their cartesian product encapsulated by \a minimizer. - * \returns the minimum value. - * The Minimizer type must provide the following members: \code - typedef Scalar //the numeric type of what is being minimized--not necessarily the Scalar type of the BVH (if it has one) - Scalar minimumOnVolumeVolume(const BVH1::Volume &v1, const BVH2::Volume &v2) - Scalar minimumOnVolumeObject(const BVH1::Volume &v1, const BVH2::Object &o2) - Scalar minimumOnObjectVolume(const BVH1::Object &o1, const BVH2::Volume &v2) - Scalar minimumOnObjectObject(const BVH1::Object &o1, const BVH2::Object &o2) - \endcode - */ -template<typename BVH1, typename BVH2, typename Minimizer> -typename Minimizer::Scalar BVMinimize(const BVH1 &tree1, const BVH2 &tree2, Minimizer &minimizer) -{ - typedef typename Minimizer::Scalar Scalar; - typedef typename BVH1::Index Index1; - typedef typename BVH2::Index Index2; - typedef internal::minimizer_helper1<typename BVH1::Volume, typename BVH1::Object, typename BVH2::Object, Minimizer> Helper1; - typedef internal::minimizer_helper2<typename BVH2::Volume, typename BVH2::Object, typename BVH1::Object, Minimizer> Helper2; - typedef std::pair<Scalar, std::pair<Index1, Index2> > QueueElement; //first element is priority - typedef typename BVH1::VolumeIterator VolIter1; - typedef typename BVH1::ObjectIterator ObjIter1; - typedef typename BVH2::VolumeIterator VolIter2; - typedef typename BVH2::ObjectIterator ObjIter2; - - VolIter1 vBegin1 = VolIter1(), vEnd1 = VolIter1(); - ObjIter1 oBegin1 = ObjIter1(), oEnd1 = ObjIter1(); - VolIter2 vBegin2 = VolIter2(), vEnd2 = VolIter2(), vCur2 = VolIter2(); - ObjIter2 oBegin2 = ObjIter2(), oEnd2 = ObjIter2(), oCur2 = ObjIter2(); - std::priority_queue<QueueElement, std::vector<QueueElement>, std::greater<QueueElement> > todo; //smallest is at the top - - Scalar minimum = (std::numeric_limits<Scalar>::max)(); - todo.push(std::make_pair(Scalar(), std::make_pair(tree1.getRootIndex(), tree2.getRootIndex()))); - - while(!todo.empty()) { - tree1.getChildren(todo.top().second.first, vBegin1, vEnd1, oBegin1, oEnd1); - tree2.getChildren(todo.top().second.second, vBegin2, vEnd2, oBegin2, oEnd2); - todo.pop(); - - for(; oBegin1 != oEnd1; ++oBegin1) { //go through child objects of first tree - for(oCur2 = oBegin2; oCur2 != oEnd2; ++oCur2) {//go through child objects of second tree - minimum = (std::min)(minimum, minimizer.minimumOnObjectObject(*oBegin1, *oCur2)); - } - - for(vCur2 = vBegin2; vCur2 != vEnd2; ++vCur2) { //go through child volumes of second tree - Helper2 helper(*oBegin1, minimizer); - minimum = (std::min)(minimum, internal::minimize_helper(tree2, helper, *vCur2, minimum)); - } - } - - for(; vBegin1 != vEnd1; ++vBegin1) { //go through child volumes of first tree - const typename BVH1::Volume &vol1 = tree1.getVolume(*vBegin1); - - for(oCur2 = oBegin2; oCur2 != oEnd2; ++oCur2) {//go through child objects of second tree - Helper1 helper(*oCur2, minimizer); - minimum = (std::min)(minimum, internal::minimize_helper(tree1, helper, *vBegin1, minimum)); - } - - for(vCur2 = vBegin2; vCur2 != vEnd2; ++vCur2) { //go through child volumes of second tree - Scalar val = minimizer.minimumOnVolumeVolume(vol1, tree2.getVolume(*vCur2)); - if(val < minimum) - todo.push(std::make_pair(val, std::make_pair(*vBegin1, *vCur2))); - } - } - } - return minimum; -} - -} // end namespace Eigen - -#endif // EIGEN_BVALGORITHMS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/BVH/KdBVH.h b/external/eigen/include/eigen3/unsupported/Eigen/src/BVH/KdBVH.h deleted file mode 100644 index 2d5b76ad..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/BVH/KdBVH.h +++ /dev/null @@ -1,223 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Ilya Baran <ibaran@mit.edu> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef KDBVH_H_INCLUDED -#define KDBVH_H_INCLUDED - -namespace Eigen { - -namespace internal { - -//internal pair class for the BVH--used instead of std::pair because of alignment -template<typename Scalar, int Dim> -struct vector_int_pair -{ -EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Dim) - typedef Matrix<Scalar, Dim, 1> VectorType; - - vector_int_pair(const VectorType &v, int i) : first(v), second(i) {} - - VectorType first; - int second; -}; - -//these templates help the tree initializer get the bounding boxes either from a provided -//iterator range or using bounding_box in a unified way -template<typename ObjectList, typename VolumeList, typename BoxIter> -struct get_boxes_helper { - void operator()(const ObjectList &objects, BoxIter boxBegin, BoxIter boxEnd, VolumeList &outBoxes) - { - outBoxes.insert(outBoxes.end(), boxBegin, boxEnd); - eigen_assert(outBoxes.size() == objects.size()); - EIGEN_ONLY_USED_FOR_DEBUG(objects); - } -}; - -template<typename ObjectList, typename VolumeList> -struct get_boxes_helper<ObjectList, VolumeList, int> { - void operator()(const ObjectList &objects, int, int, VolumeList &outBoxes) - { - outBoxes.reserve(objects.size()); - for(int i = 0; i < (int)objects.size(); ++i) - outBoxes.push_back(bounding_box(objects[i])); - } -}; - -} // end namespace internal - - -/** \class KdBVH - * \brief A simple bounding volume hierarchy based on AlignedBox - * - * \param _Scalar The underlying scalar type of the bounding boxes - * \param _Dim The dimension of the space in which the hierarchy lives - * \param _Object The object type that lives in the hierarchy. It must have value semantics. Either bounding_box(_Object) must - * be defined and return an AlignedBox<_Scalar, _Dim> or bounding boxes must be provided to the tree initializer. - * - * This class provides a simple (as opposed to optimized) implementation of a bounding volume hierarchy analogous to a Kd-tree. - * Given a sequence of objects, it computes their bounding boxes, constructs a Kd-tree of their centers - * and builds a BVH with the structure of that Kd-tree. When the elements of the tree are too expensive to be copied around, - * it is useful for _Object to be a pointer. - */ -template<typename _Scalar, int _Dim, typename _Object> class KdBVH -{ -public: - enum { Dim = _Dim }; - typedef _Object Object; - typedef std::vector<Object, aligned_allocator<Object> > ObjectList; - typedef _Scalar Scalar; - typedef AlignedBox<Scalar, Dim> Volume; - typedef std::vector<Volume, aligned_allocator<Volume> > VolumeList; - typedef int Index; - typedef const int *VolumeIterator; //the iterators are just pointers into the tree's vectors - typedef const Object *ObjectIterator; - - KdBVH() {} - - /** Given an iterator range over \a Object references, constructs the BVH. Requires that bounding_box(Object) return a Volume. */ - template<typename Iter> KdBVH(Iter begin, Iter end) { init(begin, end, 0, 0); } //int is recognized by init as not being an iterator type - - /** Given an iterator range over \a Object references and an iterator range over their bounding boxes, constructs the BVH */ - template<typename OIter, typename BIter> KdBVH(OIter begin, OIter end, BIter boxBegin, BIter boxEnd) { init(begin, end, boxBegin, boxEnd); } - - /** Given an iterator range over \a Object references, constructs the BVH, overwriting whatever is in there currently. - * Requires that bounding_box(Object) return a Volume. */ - template<typename Iter> void init(Iter begin, Iter end) { init(begin, end, 0, 0); } - - /** Given an iterator range over \a Object references and an iterator range over their bounding boxes, - * constructs the BVH, overwriting whatever is in there currently. */ - template<typename OIter, typename BIter> void init(OIter begin, OIter end, BIter boxBegin, BIter boxEnd) - { - objects.clear(); - boxes.clear(); - children.clear(); - - objects.insert(objects.end(), begin, end); - int n = static_cast<int>(objects.size()); - - if(n < 2) - return; //if we have at most one object, we don't need any internal nodes - - VolumeList objBoxes; - VIPairList objCenters; - - //compute the bounding boxes depending on BIter type - internal::get_boxes_helper<ObjectList, VolumeList, BIter>()(objects, boxBegin, boxEnd, objBoxes); - - objCenters.reserve(n); - boxes.reserve(n - 1); - children.reserve(2 * n - 2); - - for(int i = 0; i < n; ++i) - objCenters.push_back(VIPair(objBoxes[i].center(), i)); - - build(objCenters, 0, n, objBoxes, 0); //the recursive part of the algorithm - - ObjectList tmp(n); - tmp.swap(objects); - for(int i = 0; i < n; ++i) - objects[i] = tmp[objCenters[i].second]; - } - - /** \returns the index of the root of the hierarchy */ - inline Index getRootIndex() const { return (int)boxes.size() - 1; } - - /** Given an \a index of a node, on exit, \a outVBegin and \a outVEnd range over the indices of the volume children of the node - * and \a outOBegin and \a outOEnd range over the object children of the node */ - EIGEN_STRONG_INLINE void getChildren(Index index, VolumeIterator &outVBegin, VolumeIterator &outVEnd, - ObjectIterator &outOBegin, ObjectIterator &outOEnd) const - { //inlining this function should open lots of optimization opportunities to the compiler - if(index < 0) { - outVBegin = outVEnd; - if(!objects.empty()) - outOBegin = &(objects[0]); - outOEnd = outOBegin + objects.size(); //output all objects--necessary when the tree has only one object - return; - } - - int numBoxes = static_cast<int>(boxes.size()); - - int idx = index * 2; - if(children[idx + 1] < numBoxes) { //second index is always bigger - outVBegin = &(children[idx]); - outVEnd = outVBegin + 2; - outOBegin = outOEnd; - } - else if(children[idx] >= numBoxes) { //if both children are objects - outVBegin = outVEnd; - outOBegin = &(objects[children[idx] - numBoxes]); - outOEnd = outOBegin + 2; - } else { //if the first child is a volume and the second is an object - outVBegin = &(children[idx]); - outVEnd = outVBegin + 1; - outOBegin = &(objects[children[idx + 1] - numBoxes]); - outOEnd = outOBegin + 1; - } - } - - /** \returns the bounding box of the node at \a index */ - inline const Volume &getVolume(Index index) const - { - return boxes[index]; - } - -private: - typedef internal::vector_int_pair<Scalar, Dim> VIPair; - typedef std::vector<VIPair, aligned_allocator<VIPair> > VIPairList; - typedef Matrix<Scalar, Dim, 1> VectorType; - struct VectorComparator //compares vectors, or more specifically, VIPairs along a particular dimension - { - VectorComparator(int inDim) : dim(inDim) {} - inline bool operator()(const VIPair &v1, const VIPair &v2) const { return v1.first[dim] < v2.first[dim]; } - int dim; - }; - - //Build the part of the tree between objects[from] and objects[to] (not including objects[to]). - //This routine partitions the objCenters in [from, to) along the dimension dim, recursively constructs - //the two halves, and adds their parent node. TODO: a cache-friendlier layout - void build(VIPairList &objCenters, int from, int to, const VolumeList &objBoxes, int dim) - { - eigen_assert(to - from > 1); - if(to - from == 2) { - boxes.push_back(objBoxes[objCenters[from].second].merged(objBoxes[objCenters[from + 1].second])); - children.push_back(from + (int)objects.size() - 1); //there are objects.size() - 1 tree nodes - children.push_back(from + (int)objects.size()); - } - else if(to - from == 3) { - int mid = from + 2; - std::nth_element(objCenters.begin() + from, objCenters.begin() + mid, - objCenters.begin() + to, VectorComparator(dim)); //partition - build(objCenters, from, mid, objBoxes, (dim + 1) % Dim); - int idx1 = (int)boxes.size() - 1; - boxes.push_back(boxes[idx1].merged(objBoxes[objCenters[mid].second])); - children.push_back(idx1); - children.push_back(mid + (int)objects.size() - 1); - } - else { - int mid = from + (to - from) / 2; - nth_element(objCenters.begin() + from, objCenters.begin() + mid, - objCenters.begin() + to, VectorComparator(dim)); //partition - build(objCenters, from, mid, objBoxes, (dim + 1) % Dim); - int idx1 = (int)boxes.size() - 1; - build(objCenters, mid, to, objBoxes, (dim + 1) % Dim); - int idx2 = (int)boxes.size() - 1; - boxes.push_back(boxes[idx1].merged(boxes[idx2])); - children.push_back(idx1); - children.push_back(idx2); - } - } - - std::vector<int> children; //children of x are children[2x] and children[2x+1], indices bigger than boxes.size() index into objects. - VolumeList boxes; - ObjectList objects; -}; - -} // end namespace Eigen - -#endif //KDBVH_H_INCLUDED diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Eigenvalues/ArpackSelfAdjointEigenSolver.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Eigenvalues/ArpackSelfAdjointEigenSolver.h deleted file mode 100644 index 0fbd8477..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Eigenvalues/ArpackSelfAdjointEigenSolver.h +++ /dev/null @@ -1,790 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 David Harmon <dharmon@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ARPACKGENERALIZEDSELFADJOINTEIGENSOLVER_H -#define EIGEN_ARPACKGENERALIZEDSELFADJOINTEIGENSOLVER_H - -#include "../../../../Eigen/Dense" - -namespace Eigen { - -namespace internal { - template<typename Scalar, typename RealScalar> struct arpack_wrapper; - template<typename MatrixSolver, typename MatrixType, typename Scalar, bool BisSPD> struct OP; -} - - - -template<typename MatrixType, typename MatrixSolver=SimplicialLLT<MatrixType>, bool BisSPD=false> -class ArpackGeneralizedSelfAdjointEigenSolver -{ -public: - //typedef typename MatrixSolver::MatrixType MatrixType; - - /** \brief Scalar type for matrices of type \p MatrixType. */ - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::Index Index; - - /** \brief Real scalar type for \p MatrixType. - * - * This is just \c Scalar if #Scalar is real (e.g., \c float or - * \c Scalar), and the type of the real part of \c Scalar if #Scalar is - * complex. - */ - typedef typename NumTraits<Scalar>::Real RealScalar; - - /** \brief Type for vector of eigenvalues as returned by eigenvalues(). - * - * This is a column vector with entries of type #RealScalar. - * The length of the vector is the size of \p nbrEigenvalues. - */ - typedef typename internal::plain_col_type<MatrixType, RealScalar>::type RealVectorType; - - /** \brief Default constructor. - * - * The default constructor is for cases in which the user intends to - * perform decompositions via compute(). - * - */ - ArpackGeneralizedSelfAdjointEigenSolver() - : m_eivec(), - m_eivalues(), - m_isInitialized(false), - m_eigenvectorsOk(false), - m_nbrConverged(0), - m_nbrIterations(0) - { } - - /** \brief Constructor; computes generalized eigenvalues of given matrix with respect to another matrix. - * - * \param[in] A Self-adjoint matrix whose eigenvalues / eigenvectors will - * computed. By default, the upper triangular part is used, but can be changed - * through the template parameter. - * \param[in] B Self-adjoint matrix for the generalized eigenvalue problem. - * \param[in] nbrEigenvalues The number of eigenvalues / eigenvectors to compute. - * Must be less than the size of the input matrix, or an error is returned. - * \param[in] eigs_sigma String containing either "LM", "SM", "LA", or "SA", with - * respective meanings to find the largest magnitude , smallest magnitude, - * largest algebraic, or smallest algebraic eigenvalues. Alternatively, this - * value can contain floating point value in string form, in which case the - * eigenvalues closest to this value will be found. - * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly. - * \param[in] tol What tolerance to find the eigenvalues to. Default is 0, which - * means machine precision. - * - * This constructor calls compute(const MatrixType&, const MatrixType&, Index, string, int, RealScalar) - * to compute the eigenvalues of the matrix \p A with respect to \p B. The eigenvectors are computed if - * \p options equals #ComputeEigenvectors. - * - */ - ArpackGeneralizedSelfAdjointEigenSolver(const MatrixType& A, const MatrixType& B, - Index nbrEigenvalues, std::string eigs_sigma="LM", - int options=ComputeEigenvectors, RealScalar tol=0.0) - : m_eivec(), - m_eivalues(), - m_isInitialized(false), - m_eigenvectorsOk(false), - m_nbrConverged(0), - m_nbrIterations(0) - { - compute(A, B, nbrEigenvalues, eigs_sigma, options, tol); - } - - /** \brief Constructor; computes eigenvalues of given matrix. - * - * \param[in] A Self-adjoint matrix whose eigenvalues / eigenvectors will - * computed. By default, the upper triangular part is used, but can be changed - * through the template parameter. - * \param[in] nbrEigenvalues The number of eigenvalues / eigenvectors to compute. - * Must be less than the size of the input matrix, or an error is returned. - * \param[in] eigs_sigma String containing either "LM", "SM", "LA", or "SA", with - * respective meanings to find the largest magnitude , smallest magnitude, - * largest algebraic, or smallest algebraic eigenvalues. Alternatively, this - * value can contain floating point value in string form, in which case the - * eigenvalues closest to this value will be found. - * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly. - * \param[in] tol What tolerance to find the eigenvalues to. Default is 0, which - * means machine precision. - * - * This constructor calls compute(const MatrixType&, Index, string, int, RealScalar) - * to compute the eigenvalues of the matrix \p A. The eigenvectors are computed if - * \p options equals #ComputeEigenvectors. - * - */ - - ArpackGeneralizedSelfAdjointEigenSolver(const MatrixType& A, - Index nbrEigenvalues, std::string eigs_sigma="LM", - int options=ComputeEigenvectors, RealScalar tol=0.0) - : m_eivec(), - m_eivalues(), - m_isInitialized(false), - m_eigenvectorsOk(false), - m_nbrConverged(0), - m_nbrIterations(0) - { - compute(A, nbrEigenvalues, eigs_sigma, options, tol); - } - - - /** \brief Computes generalized eigenvalues / eigenvectors of given matrix using the external ARPACK library. - * - * \param[in] A Selfadjoint matrix whose eigendecomposition is to be computed. - * \param[in] B Selfadjoint matrix for generalized eigenvalues. - * \param[in] nbrEigenvalues The number of eigenvalues / eigenvectors to compute. - * Must be less than the size of the input matrix, or an error is returned. - * \param[in] eigs_sigma String containing either "LM", "SM", "LA", or "SA", with - * respective meanings to find the largest magnitude , smallest magnitude, - * largest algebraic, or smallest algebraic eigenvalues. Alternatively, this - * value can contain floating point value in string form, in which case the - * eigenvalues closest to this value will be found. - * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly. - * \param[in] tol What tolerance to find the eigenvalues to. Default is 0, which - * means machine precision. - * - * \returns Reference to \c *this - * - * This function computes the generalized eigenvalues of \p A with respect to \p B using ARPACK. The eigenvalues() - * function can be used to retrieve them. If \p options equals #ComputeEigenvectors, - * then the eigenvectors are also computed and can be retrieved by - * calling eigenvectors(). - * - */ - ArpackGeneralizedSelfAdjointEigenSolver& compute(const MatrixType& A, const MatrixType& B, - Index nbrEigenvalues, std::string eigs_sigma="LM", - int options=ComputeEigenvectors, RealScalar tol=0.0); - - /** \brief Computes eigenvalues / eigenvectors of given matrix using the external ARPACK library. - * - * \param[in] A Selfadjoint matrix whose eigendecomposition is to be computed. - * \param[in] nbrEigenvalues The number of eigenvalues / eigenvectors to compute. - * Must be less than the size of the input matrix, or an error is returned. - * \param[in] eigs_sigma String containing either "LM", "SM", "LA", or "SA", with - * respective meanings to find the largest magnitude , smallest magnitude, - * largest algebraic, or smallest algebraic eigenvalues. Alternatively, this - * value can contain floating point value in string form, in which case the - * eigenvalues closest to this value will be found. - * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly. - * \param[in] tol What tolerance to find the eigenvalues to. Default is 0, which - * means machine precision. - * - * \returns Reference to \c *this - * - * This function computes the eigenvalues of \p A using ARPACK. The eigenvalues() - * function can be used to retrieve them. If \p options equals #ComputeEigenvectors, - * then the eigenvectors are also computed and can be retrieved by - * calling eigenvectors(). - * - */ - ArpackGeneralizedSelfAdjointEigenSolver& compute(const MatrixType& A, - Index nbrEigenvalues, std::string eigs_sigma="LM", - int options=ComputeEigenvectors, RealScalar tol=0.0); - - - /** \brief Returns the eigenvectors of given matrix. - * - * \returns A const reference to the matrix whose columns are the eigenvectors. - * - * \pre The eigenvectors have been computed before. - * - * Column \f$ k \f$ of the returned matrix is an eigenvector corresponding - * to eigenvalue number \f$ k \f$ as returned by eigenvalues(). The - * eigenvectors are normalized to have (Euclidean) norm equal to one. If - * this object was used to solve the eigenproblem for the selfadjoint - * matrix \f$ A \f$, then the matrix returned by this function is the - * matrix \f$ V \f$ in the eigendecomposition \f$ A V = D V \f$. - * For the generalized eigenproblem, the matrix returned is the solution \f$ A V = D B V \f$ - * - * Example: \include SelfAdjointEigenSolver_eigenvectors.cpp - * Output: \verbinclude SelfAdjointEigenSolver_eigenvectors.out - * - * \sa eigenvalues() - */ - const Matrix<Scalar, Dynamic, Dynamic>& eigenvectors() const - { - eigen_assert(m_isInitialized && "ArpackGeneralizedSelfAdjointEigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - return m_eivec; - } - - /** \brief Returns the eigenvalues of given matrix. - * - * \returns A const reference to the column vector containing the eigenvalues. - * - * \pre The eigenvalues have been computed before. - * - * The eigenvalues are repeated according to their algebraic multiplicity, - * so there are as many eigenvalues as rows in the matrix. The eigenvalues - * are sorted in increasing order. - * - * Example: \include SelfAdjointEigenSolver_eigenvalues.cpp - * Output: \verbinclude SelfAdjointEigenSolver_eigenvalues.out - * - * \sa eigenvectors(), MatrixBase::eigenvalues() - */ - const Matrix<Scalar, Dynamic, 1>& eigenvalues() const - { - eigen_assert(m_isInitialized && "ArpackGeneralizedSelfAdjointEigenSolver is not initialized."); - return m_eivalues; - } - - /** \brief Computes the positive-definite square root of the matrix. - * - * \returns the positive-definite square root of the matrix - * - * \pre The eigenvalues and eigenvectors of a positive-definite matrix - * have been computed before. - * - * The square root of a positive-definite matrix \f$ A \f$ is the - * positive-definite matrix whose square equals \f$ A \f$. This function - * uses the eigendecomposition \f$ A = V D V^{-1} \f$ to compute the - * square root as \f$ A^{1/2} = V D^{1/2} V^{-1} \f$. - * - * Example: \include SelfAdjointEigenSolver_operatorSqrt.cpp - * Output: \verbinclude SelfAdjointEigenSolver_operatorSqrt.out - * - * \sa operatorInverseSqrt(), - * \ref MatrixFunctions_Module "MatrixFunctions Module" - */ - Matrix<Scalar, Dynamic, Dynamic> operatorSqrt() const - { - eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - return m_eivec * m_eivalues.cwiseSqrt().asDiagonal() * m_eivec.adjoint(); - } - - /** \brief Computes the inverse square root of the matrix. - * - * \returns the inverse positive-definite square root of the matrix - * - * \pre The eigenvalues and eigenvectors of a positive-definite matrix - * have been computed before. - * - * This function uses the eigendecomposition \f$ A = V D V^{-1} \f$ to - * compute the inverse square root as \f$ V D^{-1/2} V^{-1} \f$. This is - * cheaper than first computing the square root with operatorSqrt() and - * then its inverse with MatrixBase::inverse(). - * - * Example: \include SelfAdjointEigenSolver_operatorInverseSqrt.cpp - * Output: \verbinclude SelfAdjointEigenSolver_operatorInverseSqrt.out - * - * \sa operatorSqrt(), MatrixBase::inverse(), - * \ref MatrixFunctions_Module "MatrixFunctions Module" - */ - Matrix<Scalar, Dynamic, Dynamic> operatorInverseSqrt() const - { - eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized."); - eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues."); - return m_eivec * m_eivalues.cwiseInverse().cwiseSqrt().asDiagonal() * m_eivec.adjoint(); - } - - /** \brief Reports whether previous computation was successful. - * - * \returns \c Success if computation was successful, \c NoConvergence otherwise. - */ - ComputationInfo info() const - { - eigen_assert(m_isInitialized && "ArpackGeneralizedSelfAdjointEigenSolver is not initialized."); - return m_info; - } - - size_t getNbrConvergedEigenValues() const - { return m_nbrConverged; } - - size_t getNbrIterations() const - { return m_nbrIterations; } - -protected: - Matrix<Scalar, Dynamic, Dynamic> m_eivec; - Matrix<Scalar, Dynamic, 1> m_eivalues; - ComputationInfo m_info; - bool m_isInitialized; - bool m_eigenvectorsOk; - - size_t m_nbrConverged; - size_t m_nbrIterations; -}; - - - - - -template<typename MatrixType, typename MatrixSolver, bool BisSPD> -ArpackGeneralizedSelfAdjointEigenSolver<MatrixType, MatrixSolver, BisSPD>& - ArpackGeneralizedSelfAdjointEigenSolver<MatrixType, MatrixSolver, BisSPD> -::compute(const MatrixType& A, Index nbrEigenvalues, - std::string eigs_sigma, int options, RealScalar tol) -{ - MatrixType B(0,0); - compute(A, B, nbrEigenvalues, eigs_sigma, options, tol); - - return *this; -} - - -template<typename MatrixType, typename MatrixSolver, bool BisSPD> -ArpackGeneralizedSelfAdjointEigenSolver<MatrixType, MatrixSolver, BisSPD>& - ArpackGeneralizedSelfAdjointEigenSolver<MatrixType, MatrixSolver, BisSPD> -::compute(const MatrixType& A, const MatrixType& B, Index nbrEigenvalues, - std::string eigs_sigma, int options, RealScalar tol) -{ - eigen_assert(A.cols() == A.rows()); - eigen_assert(B.cols() == B.rows()); - eigen_assert(B.rows() == 0 || A.cols() == B.rows()); - eigen_assert((options &~ (EigVecMask | GenEigMask)) == 0 - && (options & EigVecMask) != EigVecMask - && "invalid option parameter"); - - bool isBempty = (B.rows() == 0) || (B.cols() == 0); - - // For clarity, all parameters match their ARPACK name - // - // Always 0 on the first call - // - int ido = 0; - - int n = (int)A.cols(); - - // User options: "LA", "SA", "SM", "LM", "BE" - // - char whch[3] = "LM"; - - // Specifies the shift if iparam[6] = { 3, 4, 5 }, not used if iparam[6] = { 1, 2 } - // - RealScalar sigma = 0.0; - - if (eigs_sigma.length() >= 2 && isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])) - { - eigs_sigma[0] = toupper(eigs_sigma[0]); - eigs_sigma[1] = toupper(eigs_sigma[1]); - - // In the following special case we're going to invert the problem, since solving - // for larger magnitude is much much faster - // i.e., if 'SM' is specified, we're going to really use 'LM', the default - // - if (eigs_sigma.substr(0,2) != "SM") - { - whch[0] = eigs_sigma[0]; - whch[1] = eigs_sigma[1]; - } - } - else - { - eigen_assert(false && "Specifying clustered eigenvalues is not yet supported!"); - - // If it's not scalar values, then the user may be explicitly - // specifying the sigma value to cluster the evs around - // - sigma = atof(eigs_sigma.c_str()); - - // If atof fails, it returns 0.0, which is a fine default - // - } - - // "I" means normal eigenvalue problem, "G" means generalized - // - char bmat[2] = "I"; - if (eigs_sigma.substr(0,2) == "SM" || !(isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])) || (!isBempty && !BisSPD)) - bmat[0] = 'G'; - - // Now we determine the mode to use - // - int mode = (bmat[0] == 'G') + 1; - if (eigs_sigma.substr(0,2) == "SM" || !(isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1]))) - { - // We're going to use shift-and-invert mode, and basically find - // the largest eigenvalues of the inverse operator - // - mode = 3; - } - - // The user-specified number of eigenvalues/vectors to compute - // - int nev = (int)nbrEigenvalues; - - // Allocate space for ARPACK to store the residual - // - Scalar *resid = new Scalar[n]; - - // Number of Lanczos vectors, must satisfy nev < ncv <= n - // Note that this indicates that nev != n, and we cannot compute - // all eigenvalues of a mtrix - // - int ncv = std::min(std::max(2*nev, 20), n); - - // The working n x ncv matrix, also store the final eigenvectors (if computed) - // - Scalar *v = new Scalar[n*ncv]; - int ldv = n; - - // Working space - // - Scalar *workd = new Scalar[3*n]; - int lworkl = ncv*ncv+8*ncv; // Must be at least this length - Scalar *workl = new Scalar[lworkl]; - - int *iparam= new int[11]; - iparam[0] = 1; // 1 means we let ARPACK perform the shifts, 0 means we'd have to do it - iparam[2] = std::max(300, (int)std::ceil(2*n/std::max(ncv,1))); - iparam[6] = mode; // The mode, 1 is standard ev problem, 2 for generalized ev, 3 for shift-and-invert - - // Used during reverse communicate to notify where arrays start - // - int *ipntr = new int[11]; - - // Error codes are returned in here, initial value of 0 indicates a random initial - // residual vector is used, any other values means resid contains the initial residual - // vector, possibly from a previous run - // - int info = 0; - - Scalar scale = 1.0; - //if (!isBempty) - //{ - //Scalar scale = B.norm() / std::sqrt(n); - //scale = std::pow(2, std::floor(std::log(scale+1))); - ////M /= scale; - //for (size_t i=0; i<(size_t)B.outerSize(); i++) - // for (typename MatrixType::InnerIterator it(B, i); it; ++it) - // it.valueRef() /= scale; - //} - - MatrixSolver OP; - if (mode == 1 || mode == 2) - { - if (!isBempty) - OP.compute(B); - } - else if (mode == 3) - { - if (sigma == 0.0) - { - OP.compute(A); - } - else - { - // Note: We will never enter here because sigma must be 0.0 - // - if (isBempty) - { - MatrixType AminusSigmaB(A); - for (Index i=0; i<A.rows(); ++i) - AminusSigmaB.coeffRef(i,i) -= sigma; - - OP.compute(AminusSigmaB); - } - else - { - MatrixType AminusSigmaB = A - sigma * B; - OP.compute(AminusSigmaB); - } - } - } - - if (!(mode == 1 && isBempty) && !(mode == 2 && isBempty) && OP.info() != Success) - std::cout << "Error factoring matrix" << std::endl; - - do - { - internal::arpack_wrapper<Scalar, RealScalar>::saupd(&ido, bmat, &n, whch, &nev, &tol, resid, - &ncv, v, &ldv, iparam, ipntr, workd, workl, - &lworkl, &info); - - if (ido == -1 || ido == 1) - { - Scalar *in = workd + ipntr[0] - 1; - Scalar *out = workd + ipntr[1] - 1; - - if (ido == 1 && mode != 2) - { - Scalar *out2 = workd + ipntr[2] - 1; - if (isBempty || mode == 1) - Matrix<Scalar, Dynamic, 1>::Map(out2, n) = Matrix<Scalar, Dynamic, 1>::Map(in, n); - else - Matrix<Scalar, Dynamic, 1>::Map(out2, n) = B * Matrix<Scalar, Dynamic, 1>::Map(in, n); - - in = workd + ipntr[2] - 1; - } - - if (mode == 1) - { - if (isBempty) - { - // OP = A - // - Matrix<Scalar, Dynamic, 1>::Map(out, n) = A * Matrix<Scalar, Dynamic, 1>::Map(in, n); - } - else - { - // OP = L^{-1}AL^{-T} - // - internal::OP<MatrixSolver, MatrixType, Scalar, BisSPD>::applyOP(OP, A, n, in, out); - } - } - else if (mode == 2) - { - if (ido == 1) - Matrix<Scalar, Dynamic, 1>::Map(in, n) = A * Matrix<Scalar, Dynamic, 1>::Map(in, n); - - // OP = B^{-1} A - // - Matrix<Scalar, Dynamic, 1>::Map(out, n) = OP.solve(Matrix<Scalar, Dynamic, 1>::Map(in, n)); - } - else if (mode == 3) - { - // OP = (A-\sigmaB)B (\sigma could be 0, and B could be I) - // The B * in is already computed and stored at in if ido == 1 - // - if (ido == 1 || isBempty) - Matrix<Scalar, Dynamic, 1>::Map(out, n) = OP.solve(Matrix<Scalar, Dynamic, 1>::Map(in, n)); - else - Matrix<Scalar, Dynamic, 1>::Map(out, n) = OP.solve(B * Matrix<Scalar, Dynamic, 1>::Map(in, n)); - } - } - else if (ido == 2) - { - Scalar *in = workd + ipntr[0] - 1; - Scalar *out = workd + ipntr[1] - 1; - - if (isBempty || mode == 1) - Matrix<Scalar, Dynamic, 1>::Map(out, n) = Matrix<Scalar, Dynamic, 1>::Map(in, n); - else - Matrix<Scalar, Dynamic, 1>::Map(out, n) = B * Matrix<Scalar, Dynamic, 1>::Map(in, n); - } - } while (ido != 99); - - if (info == 1) - m_info = NoConvergence; - else if (info == 3) - m_info = NumericalIssue; - else if (info < 0) - m_info = InvalidInput; - else if (info != 0) - eigen_assert(false && "Unknown ARPACK return value!"); - else - { - // Do we compute eigenvectors or not? - // - int rvec = (options & ComputeEigenvectors) == ComputeEigenvectors; - - // "A" means "All", use "S" to choose specific eigenvalues (not yet supported in ARPACK)) - // - char howmny[2] = "A"; - - // if howmny == "S", specifies the eigenvalues to compute (not implemented in ARPACK) - // - int *select = new int[ncv]; - - // Final eigenvalues - // - m_eivalues.resize(nev, 1); - - internal::arpack_wrapper<Scalar, RealScalar>::seupd(&rvec, howmny, select, m_eivalues.data(), v, &ldv, - &sigma, bmat, &n, whch, &nev, &tol, resid, &ncv, - v, &ldv, iparam, ipntr, workd, workl, &lworkl, &info); - - if (info == -14) - m_info = NoConvergence; - else if (info != 0) - m_info = InvalidInput; - else - { - if (rvec) - { - m_eivec.resize(A.rows(), nev); - for (int i=0; i<nev; i++) - for (int j=0; j<n; j++) - m_eivec(j,i) = v[i*n+j] / scale; - - if (mode == 1 && !isBempty && BisSPD) - internal::OP<MatrixSolver, MatrixType, Scalar, BisSPD>::project(OP, n, nev, m_eivec.data()); - - m_eigenvectorsOk = true; - } - - m_nbrIterations = iparam[2]; - m_nbrConverged = iparam[4]; - - m_info = Success; - } - - delete[] select; - } - - delete[] v; - delete[] iparam; - delete[] ipntr; - delete[] workd; - delete[] workl; - delete[] resid; - - m_isInitialized = true; - - return *this; -} - - -// Single precision -// -extern "C" void ssaupd_(int *ido, char *bmat, int *n, char *which, - int *nev, float *tol, float *resid, int *ncv, - float *v, int *ldv, int *iparam, int *ipntr, - float *workd, float *workl, int *lworkl, - int *info); - -extern "C" void sseupd_(int *rvec, char *All, int *select, float *d, - float *z, int *ldz, float *sigma, - char *bmat, int *n, char *which, int *nev, - float *tol, float *resid, int *ncv, float *v, - int *ldv, int *iparam, int *ipntr, float *workd, - float *workl, int *lworkl, int *ierr); - -// Double precision -// -extern "C" void dsaupd_(int *ido, char *bmat, int *n, char *which, - int *nev, double *tol, double *resid, int *ncv, - double *v, int *ldv, int *iparam, int *ipntr, - double *workd, double *workl, int *lworkl, - int *info); - -extern "C" void dseupd_(int *rvec, char *All, int *select, double *d, - double *z, int *ldz, double *sigma, - char *bmat, int *n, char *which, int *nev, - double *tol, double *resid, int *ncv, double *v, - int *ldv, int *iparam, int *ipntr, double *workd, - double *workl, int *lworkl, int *ierr); - - -namespace internal { - -template<typename Scalar, typename RealScalar> struct arpack_wrapper -{ - static inline void saupd(int *ido, char *bmat, int *n, char *which, - int *nev, RealScalar *tol, Scalar *resid, int *ncv, - Scalar *v, int *ldv, int *iparam, int *ipntr, - Scalar *workd, Scalar *workl, int *lworkl, int *info) - { - EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL) - } - - static inline void seupd(int *rvec, char *All, int *select, Scalar *d, - Scalar *z, int *ldz, RealScalar *sigma, - char *bmat, int *n, char *which, int *nev, - RealScalar *tol, Scalar *resid, int *ncv, Scalar *v, - int *ldv, int *iparam, int *ipntr, Scalar *workd, - Scalar *workl, int *lworkl, int *ierr) - { - EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL) - } -}; - -template <> struct arpack_wrapper<float, float> -{ - static inline void saupd(int *ido, char *bmat, int *n, char *which, - int *nev, float *tol, float *resid, int *ncv, - float *v, int *ldv, int *iparam, int *ipntr, - float *workd, float *workl, int *lworkl, int *info) - { - ssaupd_(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); - } - - static inline void seupd(int *rvec, char *All, int *select, float *d, - float *z, int *ldz, float *sigma, - char *bmat, int *n, char *which, int *nev, - float *tol, float *resid, int *ncv, float *v, - int *ldv, int *iparam, int *ipntr, float *workd, - float *workl, int *lworkl, int *ierr) - { - sseupd_(rvec, All, select, d, z, ldz, sigma, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, - workd, workl, lworkl, ierr); - } -}; - -template <> struct arpack_wrapper<double, double> -{ - static inline void saupd(int *ido, char *bmat, int *n, char *which, - int *nev, double *tol, double *resid, int *ncv, - double *v, int *ldv, int *iparam, int *ipntr, - double *workd, double *workl, int *lworkl, int *info) - { - dsaupd_(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); - } - - static inline void seupd(int *rvec, char *All, int *select, double *d, - double *z, int *ldz, double *sigma, - char *bmat, int *n, char *which, int *nev, - double *tol, double *resid, int *ncv, double *v, - int *ldv, int *iparam, int *ipntr, double *workd, - double *workl, int *lworkl, int *ierr) - { - dseupd_(rvec, All, select, d, v, ldv, sigma, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, - workd, workl, lworkl, ierr); - } -}; - - -template<typename MatrixSolver, typename MatrixType, typename Scalar, bool BisSPD> -struct OP -{ - static inline void applyOP(MatrixSolver &OP, const MatrixType &A, int n, Scalar *in, Scalar *out); - static inline void project(MatrixSolver &OP, int n, int k, Scalar *vecs); -}; - -template<typename MatrixSolver, typename MatrixType, typename Scalar> -struct OP<MatrixSolver, MatrixType, Scalar, true> -{ - static inline void applyOP(MatrixSolver &OP, const MatrixType &A, int n, Scalar *in, Scalar *out) -{ - // OP = L^{-1} A L^{-T} (B = LL^T) - // - // First solve L^T out = in - // - Matrix<Scalar, Dynamic, 1>::Map(out, n) = OP.matrixU().solve(Matrix<Scalar, Dynamic, 1>::Map(in, n)); - Matrix<Scalar, Dynamic, 1>::Map(out, n) = OP.permutationPinv() * Matrix<Scalar, Dynamic, 1>::Map(out, n); - - // Then compute out = A out - // - Matrix<Scalar, Dynamic, 1>::Map(out, n) = A * Matrix<Scalar, Dynamic, 1>::Map(out, n); - - // Then solve L out = out - // - Matrix<Scalar, Dynamic, 1>::Map(out, n) = OP.permutationP() * Matrix<Scalar, Dynamic, 1>::Map(out, n); - Matrix<Scalar, Dynamic, 1>::Map(out, n) = OP.matrixL().solve(Matrix<Scalar, Dynamic, 1>::Map(out, n)); -} - - static inline void project(MatrixSolver &OP, int n, int k, Scalar *vecs) -{ - // Solve L^T out = in - // - Matrix<Scalar, Dynamic, Dynamic>::Map(vecs, n, k) = OP.matrixU().solve(Matrix<Scalar, Dynamic, Dynamic>::Map(vecs, n, k)); - Matrix<Scalar, Dynamic, Dynamic>::Map(vecs, n, k) = OP.permutationPinv() * Matrix<Scalar, Dynamic, Dynamic>::Map(vecs, n, k); -} - -}; - -template<typename MatrixSolver, typename MatrixType, typename Scalar> -struct OP<MatrixSolver, MatrixType, Scalar, false> -{ - static inline void applyOP(MatrixSolver &OP, const MatrixType &A, int n, Scalar *in, Scalar *out) -{ - eigen_assert(false && "Should never be in here..."); -} - - static inline void project(MatrixSolver &OP, int n, int k, Scalar *vecs) -{ - eigen_assert(false && "Should never be in here..."); -} - -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_ARPACKSELFADJOINTEIGENSOLVER_H - diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/EulerAngles/EulerAngles.h b/external/eigen/include/eigen3/unsupported/Eigen/src/EulerAngles/EulerAngles.h deleted file mode 100644 index e43cdb7f..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/EulerAngles/EulerAngles.h +++ /dev/null @@ -1,355 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Tal Hadad <tal_hd@hotmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_EULERANGLESCLASS_H// TODO: Fix previous "EIGEN_EULERANGLES_H" definition? -#define EIGEN_EULERANGLESCLASS_H - -namespace Eigen -{ - /** \class EulerAngles - * - * \ingroup EulerAngles_Module - * - * \brief Represents a rotation in a 3 dimensional space as three Euler angles. - * - * Euler rotation is a set of three rotation of three angles over three fixed axes, defined by the EulerSystem given as a template parameter. - * - * Here is how intrinsic Euler angles works: - * - first, rotate the axes system over the alpha axis in angle alpha - * - then, rotate the axes system over the beta axis(which was rotated in the first stage) in angle beta - * - then, rotate the axes system over the gamma axis(which was rotated in the two stages above) in angle gamma - * - * \note This class support only intrinsic Euler angles for simplicity, - * see EulerSystem how to easily overcome this for extrinsic systems. - * - * ### Rotation representation and conversions ### - * - * It has been proved(see Wikipedia link below) that every rotation can be represented - * by Euler angles, but there is no single representation (e.g. unlike rotation matrices). - * Therefore, you can convert from Eigen rotation and to them - * (including rotation matrices, which is not called "rotations" by Eigen design). - * - * Euler angles usually used for: - * - convenient human representation of rotation, especially in interactive GUI. - * - gimbal systems and robotics - * - efficient encoding(i.e. 3 floats only) of rotation for network protocols. - * - * However, Euler angles are slow comparing to quaternion or matrices, - * because their unnatural math definition, although it's simple for human. - * To overcome this, this class provide easy movement from the math friendly representation - * to the human friendly representation, and vise-versa. - * - * All the user need to do is a safe simple C++ type conversion, - * and this class take care for the math. - * Additionally, some axes related computation is done in compile time. - * - * #### Euler angles ranges in conversions #### - * Rotations representation as EulerAngles are not single (unlike matrices), - * and even have infinite EulerAngles representations.<BR> - * For example, add or subtract 2*PI from either angle of EulerAngles - * and you'll get the same rotation. - * This is the general reason for infinite representation, - * but it's not the only general reason for not having a single representation. - * - * When converting rotation to EulerAngles, this class convert it to specific ranges - * When converting some rotation to EulerAngles, the rules for ranges are as follow: - * - If the rotation we converting from is an EulerAngles - * (even when it represented as RotationBase explicitly), angles ranges are __undefined__. - * - otherwise, alpha and gamma angles will be in the range [-PI, PI].<BR> - * As for Beta angle: - * - If the system is Tait-Bryan, the beta angle will be in the range [-PI/2, PI/2]. - * - otherwise: - * - If the beta axis is positive, the beta angle will be in the range [0, PI] - * - If the beta axis is negative, the beta angle will be in the range [-PI, 0] - * - * \sa EulerAngles(const MatrixBase<Derived>&) - * \sa EulerAngles(const RotationBase<Derived, 3>&) - * - * ### Convenient user typedefs ### - * - * Convenient typedefs for EulerAngles exist for float and double scalar, - * in a form of EulerAngles{A}{B}{C}{scalar}, - * e.g. \ref EulerAnglesXYZd, \ref EulerAnglesZYZf. - * - * Only for positive axes{+x,+y,+z} Euler systems are have convenient typedef. - * If you need negative axes{-x,-y,-z}, it is recommended to create you own typedef with - * a word that represent what you need. - * - * ### Example ### - * - * \include EulerAngles.cpp - * Output: \verbinclude EulerAngles.out - * - * ### Additional reading ### - * - * If you're want to get more idea about how Euler system work in Eigen see EulerSystem. - * - * More information about Euler angles: https://en.wikipedia.org/wiki/Euler_angles - * - * \tparam _Scalar the scalar type, i.e. the type of the angles. - * - * \tparam _System the EulerSystem to use, which represents the axes of rotation. - */ - template <typename _Scalar, class _System> - class EulerAngles : public RotationBase<EulerAngles<_Scalar, _System>, 3> - { - public: - typedef RotationBase<EulerAngles<_Scalar, _System>, 3> Base; - - /** the scalar type of the angles */ - typedef _Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - - /** the EulerSystem to use, which represents the axes of rotation. */ - typedef _System System; - - typedef Matrix<Scalar,3,3> Matrix3; /*!< the equivalent rotation matrix type */ - typedef Matrix<Scalar,3,1> Vector3; /*!< the equivalent 3 dimension vector type */ - typedef Quaternion<Scalar> QuaternionType; /*!< the equivalent quaternion type */ - typedef AngleAxis<Scalar> AngleAxisType; /*!< the equivalent angle-axis type */ - - /** \returns the axis vector of the first (alpha) rotation */ - static Vector3 AlphaAxisVector() { - const Vector3& u = Vector3::Unit(System::AlphaAxisAbs - 1); - return System::IsAlphaOpposite ? -u : u; - } - - /** \returns the axis vector of the second (beta) rotation */ - static Vector3 BetaAxisVector() { - const Vector3& u = Vector3::Unit(System::BetaAxisAbs - 1); - return System::IsBetaOpposite ? -u : u; - } - - /** \returns the axis vector of the third (gamma) rotation */ - static Vector3 GammaAxisVector() { - const Vector3& u = Vector3::Unit(System::GammaAxisAbs - 1); - return System::IsGammaOpposite ? -u : u; - } - - private: - Vector3 m_angles; - - public: - /** Default constructor without initialization. */ - EulerAngles() {} - /** Constructs and initialize an EulerAngles (\p alpha, \p beta, \p gamma). */ - EulerAngles(const Scalar& alpha, const Scalar& beta, const Scalar& gamma) : - m_angles(alpha, beta, gamma) {} - - // TODO: Test this constructor - /** Constructs and initialize an EulerAngles from the array data {alpha, beta, gamma} */ - explicit EulerAngles(const Scalar* data) : m_angles(data) {} - - /** Constructs and initializes an EulerAngles from either: - * - a 3x3 rotation matrix expression(i.e. pure orthogonal matrix with determinant of +1), - * - a 3D vector expression representing Euler angles. - * - * \note If \p other is a 3x3 rotation matrix, the angles range rules will be as follow:<BR> - * Alpha and gamma angles will be in the range [-PI, PI].<BR> - * As for Beta angle: - * - If the system is Tait-Bryan, the beta angle will be in the range [-PI/2, PI/2]. - * - otherwise: - * - If the beta axis is positive, the beta angle will be in the range [0, PI] - * - If the beta axis is negative, the beta angle will be in the range [-PI, 0] - */ - template<typename Derived> - explicit EulerAngles(const MatrixBase<Derived>& other) { *this = other; } - - /** Constructs and initialize Euler angles from a rotation \p rot. - * - * \note If \p rot is an EulerAngles (even when it represented as RotationBase explicitly), - * angles ranges are __undefined__. - * Otherwise, alpha and gamma angles will be in the range [-PI, PI].<BR> - * As for Beta angle: - * - If the system is Tait-Bryan, the beta angle will be in the range [-PI/2, PI/2]. - * - otherwise: - * - If the beta axis is positive, the beta angle will be in the range [0, PI] - * - If the beta axis is negative, the beta angle will be in the range [-PI, 0] - */ - template<typename Derived> - EulerAngles(const RotationBase<Derived, 3>& rot) { System::CalcEulerAngles(*this, rot.toRotationMatrix()); } - - /*EulerAngles(const QuaternionType& q) - { - // TODO: Implement it in a faster way for quaternions - // According to http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/ - // we can compute only the needed matrix cells and then convert to euler angles. (see ZYX example below) - // Currently we compute all matrix cells from quaternion. - - // Special case only for ZYX - //Scalar y2 = q.y() * q.y(); - //m_angles[0] = std::atan2(2*(q.w()*q.z() + q.x()*q.y()), (1 - 2*(y2 + q.z()*q.z()))); - //m_angles[1] = std::asin( 2*(q.w()*q.y() - q.z()*q.x())); - //m_angles[2] = std::atan2(2*(q.w()*q.x() + q.y()*q.z()), (1 - 2*(q.x()*q.x() + y2))); - }*/ - - /** \returns The angle values stored in a vector (alpha, beta, gamma). */ - const Vector3& angles() const { return m_angles; } - /** \returns A read-write reference to the angle values stored in a vector (alpha, beta, gamma). */ - Vector3& angles() { return m_angles; } - - /** \returns The value of the first angle. */ - Scalar alpha() const { return m_angles[0]; } - /** \returns A read-write reference to the angle of the first angle. */ - Scalar& alpha() { return m_angles[0]; } - - /** \returns The value of the second angle. */ - Scalar beta() const { return m_angles[1]; } - /** \returns A read-write reference to the angle of the second angle. */ - Scalar& beta() { return m_angles[1]; } - - /** \returns The value of the third angle. */ - Scalar gamma() const { return m_angles[2]; } - /** \returns A read-write reference to the angle of the third angle. */ - Scalar& gamma() { return m_angles[2]; } - - /** \returns The Euler angles rotation inverse (which is as same as the negative), - * (-alpha, -beta, -gamma). - */ - EulerAngles inverse() const - { - EulerAngles res; - res.m_angles = -m_angles; - return res; - } - - /** \returns The Euler angles rotation negative (which is as same as the inverse), - * (-alpha, -beta, -gamma). - */ - EulerAngles operator -() const - { - return inverse(); - } - - /** Set \c *this from either: - * - a 3x3 rotation matrix expression(i.e. pure orthogonal matrix with determinant of +1), - * - a 3D vector expression representing Euler angles. - * - * See EulerAngles(const MatrixBase<Derived, 3>&) for more information about - * angles ranges output. - */ - template<class Derived> - EulerAngles& operator=(const MatrixBase<Derived>& other) - { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename Derived::Scalar>::value), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - - internal::eulerangles_assign_impl<System, Derived>::run(*this, other.derived()); - return *this; - } - - // TODO: Assign and construct from another EulerAngles (with different system) - - /** Set \c *this from a rotation. - * - * See EulerAngles(const RotationBase<Derived, 3>&) for more information about - * angles ranges output. - */ - template<typename Derived> - EulerAngles& operator=(const RotationBase<Derived, 3>& rot) { - System::CalcEulerAngles(*this, rot.toRotationMatrix()); - return *this; - } - - /** \returns \c true if \c *this is approximately equal to \a other, within the precision - * determined by \a prec. - * - * \sa MatrixBase::isApprox() */ - bool isApprox(const EulerAngles& other, - const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const - { return angles().isApprox(other.angles(), prec); } - - /** \returns an equivalent 3x3 rotation matrix. */ - Matrix3 toRotationMatrix() const - { - // TODO: Calc it faster - return static_cast<QuaternionType>(*this).toRotationMatrix(); - } - - /** Convert the Euler angles to quaternion. */ - operator QuaternionType() const - { - return - AngleAxisType(alpha(), AlphaAxisVector()) * - AngleAxisType(beta(), BetaAxisVector()) * - AngleAxisType(gamma(), GammaAxisVector()); - } - - friend std::ostream& operator<<(std::ostream& s, const EulerAngles<Scalar, System>& eulerAngles) - { - s << eulerAngles.angles().transpose(); - return s; - } - - /** \returns \c *this with scalar type casted to \a NewScalarType */ - template <typename NewScalarType> - EulerAngles<NewScalarType, System> cast() const - { - EulerAngles<NewScalarType, System> e; - e.angles() = angles().template cast<NewScalarType>(); - return e; - } - }; - -#define EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(AXES, SCALAR_TYPE, SCALAR_POSTFIX) \ - /** \ingroup EulerAngles_Module */ \ - typedef EulerAngles<SCALAR_TYPE, EulerSystem##AXES> EulerAngles##AXES##SCALAR_POSTFIX; - -#define EIGEN_EULER_ANGLES_TYPEDEFS(SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XYZ, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XYX, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XZY, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XZX, SCALAR_TYPE, SCALAR_POSTFIX) \ - \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YZX, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YZY, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YXZ, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YXY, SCALAR_TYPE, SCALAR_POSTFIX) \ - \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZXY, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZXZ, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZYX, SCALAR_TYPE, SCALAR_POSTFIX) \ - EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZYZ, SCALAR_TYPE, SCALAR_POSTFIX) - -EIGEN_EULER_ANGLES_TYPEDEFS(float, f) -EIGEN_EULER_ANGLES_TYPEDEFS(double, d) - - namespace internal - { - template<typename _Scalar, class _System> - struct traits<EulerAngles<_Scalar, _System> > - { - typedef _Scalar Scalar; - }; - - // set from a rotation matrix - template<class System, class Other> - struct eulerangles_assign_impl<System,Other,3,3> - { - typedef typename Other::Scalar Scalar; - static void run(EulerAngles<Scalar, System>& e, const Other& m) - { - System::CalcEulerAngles(e, m); - } - }; - - // set from a vector of Euler angles - template<class System, class Other> - struct eulerangles_assign_impl<System,Other,3,1> - { - typedef typename Other::Scalar Scalar; - static void run(EulerAngles<Scalar, System>& e, const Other& vec) - { - e.angles() = vec; - } - }; - } -} - -#endif // EIGEN_EULERANGLESCLASS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/EulerAngles/EulerSystem.h b/external/eigen/include/eigen3/unsupported/Eigen/src/EulerAngles/EulerSystem.h deleted file mode 100644 index 2a833b0a..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/EulerAngles/EulerSystem.h +++ /dev/null @@ -1,305 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Tal Hadad <tal_hd@hotmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_EULERSYSTEM_H -#define EIGEN_EULERSYSTEM_H - -namespace Eigen -{ - // Forward declarations - template <typename _Scalar, class _System> - class EulerAngles; - - namespace internal - { - // TODO: Add this trait to the Eigen internal API? - template <int Num, bool IsPositive = (Num > 0)> - struct Abs - { - enum { value = Num }; - }; - - template <int Num> - struct Abs<Num, false> - { - enum { value = -Num }; - }; - - template <int Axis> - struct IsValidAxis - { - enum { value = Axis != 0 && Abs<Axis>::value <= 3 }; - }; - - template<typename System, - typename Other, - int OtherRows=Other::RowsAtCompileTime, - int OtherCols=Other::ColsAtCompileTime> - struct eulerangles_assign_impl; - } - - #define EIGEN_EULER_ANGLES_CLASS_STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1] - - /** \brief Representation of a fixed signed rotation axis for EulerSystem. - * - * \ingroup EulerAngles_Module - * - * Values here represent: - * - The axis of the rotation: X, Y or Z. - * - The sign (i.e. direction of the rotation along the axis): positive(+) or negative(-) - * - * Therefore, this could express all the axes {+X,+Y,+Z,-X,-Y,-Z} - * - * For positive axis, use +EULER_{axis}, and for negative axis use -EULER_{axis}. - */ - enum EulerAxis - { - EULER_X = 1, /*!< the X axis */ - EULER_Y = 2, /*!< the Y axis */ - EULER_Z = 3 /*!< the Z axis */ - }; - - /** \class EulerSystem - * - * \ingroup EulerAngles_Module - * - * \brief Represents a fixed Euler rotation system. - * - * This meta-class goal is to represent the Euler system in compilation time, for EulerAngles. - * - * You can use this class to get two things: - * - Build an Euler system, and then pass it as a template parameter to EulerAngles. - * - Query some compile time data about an Euler system. (e.g. Whether it's Tait-Bryan) - * - * Euler rotation is a set of three rotation on fixed axes. (see \ref EulerAngles) - * This meta-class store constantly those signed axes. (see \ref EulerAxis) - * - * ### Types of Euler systems ### - * - * All and only valid 3 dimension Euler rotation over standard - * signed axes{+X,+Y,+Z,-X,-Y,-Z} are supported: - * - all axes X, Y, Z in each valid order (see below what order is valid) - * - rotation over the axis is supported both over the positive and negative directions. - * - both Tait-Bryan and proper/classic Euler angles (i.e. the opposite). - * - * Since EulerSystem support both positive and negative directions, - * you may call this rotation distinction in other names: - * - _right handed_ or _left handed_ - * - _counterclockwise_ or _clockwise_ - * - * Notice all axed combination are valid, and would trigger a static assertion. - * Same unsigned axes can't be neighbors, e.g. {X,X,Y} is invalid. - * This yield two and only two classes: - * - _Tait-Bryan_ - all unsigned axes are distinct, e.g. {X,Y,Z} - * - _proper/classic Euler angles_ - The first and the third unsigned axes is equal, - * and the second is different, e.g. {X,Y,X} - * - * ### Intrinsic vs extrinsic Euler systems ### - * - * Only intrinsic Euler systems are supported for simplicity. - * If you want to use extrinsic Euler systems, - * just use the equal intrinsic opposite order for axes and angles. - * I.e axes (A,B,C) becomes (C,B,A), and angles (a,b,c) becomes (c,b,a). - * - * ### Convenient user typedefs ### - * - * Convenient typedefs for EulerSystem exist (only for positive axes Euler systems), - * in a form of EulerSystem{A}{B}{C}, e.g. \ref EulerSystemXYZ. - * - * ### Additional reading ### - * - * More information about Euler angles: https://en.wikipedia.org/wiki/Euler_angles - * - * \tparam _AlphaAxis the first fixed EulerAxis - * - * \tparam _BetaAxis the second fixed EulerAxis - * - * \tparam _GammaAxis the third fixed EulerAxis - */ - template <int _AlphaAxis, int _BetaAxis, int _GammaAxis> - class EulerSystem - { - public: - // It's defined this way and not as enum, because I think - // that enum is not guerantee to support negative numbers - - /** The first rotation axis */ - static const int AlphaAxis = _AlphaAxis; - - /** The second rotation axis */ - static const int BetaAxis = _BetaAxis; - - /** The third rotation axis */ - static const int GammaAxis = _GammaAxis; - - enum - { - AlphaAxisAbs = internal::Abs<AlphaAxis>::value, /*!< the first rotation axis unsigned */ - BetaAxisAbs = internal::Abs<BetaAxis>::value, /*!< the second rotation axis unsigned */ - GammaAxisAbs = internal::Abs<GammaAxis>::value, /*!< the third rotation axis unsigned */ - - IsAlphaOpposite = (AlphaAxis < 0) ? 1 : 0, /*!< whether alpha axis is negative */ - IsBetaOpposite = (BetaAxis < 0) ? 1 : 0, /*!< whether beta axis is negative */ - IsGammaOpposite = (GammaAxis < 0) ? 1 : 0, /*!< whether gamma axis is negative */ - - // Parity is even if alpha axis X is followed by beta axis Y, or Y is followed - // by Z, or Z is followed by X; otherwise it is odd. - IsOdd = ((AlphaAxisAbs)%3 == (BetaAxisAbs - 1)%3) ? 0 : 1, /*!< whether the Euler system is odd */ - IsEven = IsOdd ? 0 : 1, /*!< whether the Euler system is even */ - - IsTaitBryan = ((unsigned)AlphaAxisAbs != (unsigned)GammaAxisAbs) ? 1 : 0 /*!< whether the Euler system is Tait-Bryan */ - }; - - private: - - EIGEN_EULER_ANGLES_CLASS_STATIC_ASSERT(internal::IsValidAxis<AlphaAxis>::value, - ALPHA_AXIS_IS_INVALID); - - EIGEN_EULER_ANGLES_CLASS_STATIC_ASSERT(internal::IsValidAxis<BetaAxis>::value, - BETA_AXIS_IS_INVALID); - - EIGEN_EULER_ANGLES_CLASS_STATIC_ASSERT(internal::IsValidAxis<GammaAxis>::value, - GAMMA_AXIS_IS_INVALID); - - EIGEN_EULER_ANGLES_CLASS_STATIC_ASSERT((unsigned)AlphaAxisAbs != (unsigned)BetaAxisAbs, - ALPHA_AXIS_CANT_BE_EQUAL_TO_BETA_AXIS); - - EIGEN_EULER_ANGLES_CLASS_STATIC_ASSERT((unsigned)BetaAxisAbs != (unsigned)GammaAxisAbs, - BETA_AXIS_CANT_BE_EQUAL_TO_GAMMA_AXIS); - - static const int - // I, J, K are the pivot indexes permutation for the rotation matrix, that match this Euler system. - // They are used in this class converters. - // They are always different from each other, and their possible values are: 0, 1, or 2. - I_ = AlphaAxisAbs - 1, - J_ = (AlphaAxisAbs - 1 + 1 + IsOdd)%3, - K_ = (AlphaAxisAbs - 1 + 2 - IsOdd)%3 - ; - - // TODO: Get @mat parameter in form that avoids double evaluation. - template <typename Derived> - static void CalcEulerAngles_imp(Matrix<typename MatrixBase<Derived>::Scalar, 3, 1>& res, const MatrixBase<Derived>& mat, internal::true_type /*isTaitBryan*/) - { - using std::atan2; - using std::sqrt; - - typedef typename Derived::Scalar Scalar; - - const Scalar plusMinus = IsEven? 1 : -1; - const Scalar minusPlus = IsOdd? 1 : -1; - - const Scalar Rsum = sqrt((mat(I_,I_) * mat(I_,I_) + mat(I_,J_) * mat(I_,J_) + mat(J_,K_) * mat(J_,K_) + mat(K_,K_) * mat(K_,K_))/2); - res[1] = atan2(plusMinus * mat(I_,K_), Rsum); - - // There is a singularity when cos(beta) == 0 - if(Rsum > 4 * NumTraits<Scalar>::epsilon()) {// cos(beta) != 0 - res[0] = atan2(minusPlus * mat(J_, K_), mat(K_, K_)); - res[2] = atan2(minusPlus * mat(I_, J_), mat(I_, I_)); - } - else if(plusMinus * mat(I_, K_) > 0) {// cos(beta) == 0 and sin(beta) == 1 - Scalar spos = mat(J_, I_) + plusMinus * mat(K_, J_); // 2*sin(alpha + plusMinus * gamma - Scalar cpos = mat(J_, J_) + minusPlus * mat(K_, I_); // 2*cos(alpha + plusMinus * gamma) - Scalar alphaPlusMinusGamma = atan2(spos, cpos); - res[0] = alphaPlusMinusGamma; - res[2] = 0; - } - else {// cos(beta) == 0 and sin(beta) == -1 - Scalar sneg = plusMinus * (mat(K_, J_) + minusPlus * mat(J_, I_)); // 2*sin(alpha + minusPlus*gamma) - Scalar cneg = mat(J_, J_) + plusMinus * mat(K_, I_); // 2*cos(alpha + minusPlus*gamma) - Scalar alphaMinusPlusBeta = atan2(sneg, cneg); - res[0] = alphaMinusPlusBeta; - res[2] = 0; - } - } - - template <typename Derived> - static void CalcEulerAngles_imp(Matrix<typename MatrixBase<Derived>::Scalar,3,1>& res, - const MatrixBase<Derived>& mat, internal::false_type /*isTaitBryan*/) - { - using std::atan2; - using std::sqrt; - - typedef typename Derived::Scalar Scalar; - - const Scalar plusMinus = IsEven? 1 : -1; - const Scalar minusPlus = IsOdd? 1 : -1; - - const Scalar Rsum = sqrt((mat(I_, J_) * mat(I_, J_) + mat(I_, K_) * mat(I_, K_) + mat(J_, I_) * mat(J_, I_) + mat(K_, I_) * mat(K_, I_)) / 2); - - res[1] = atan2(Rsum, mat(I_, I_)); - - // There is a singularity when sin(beta) == 0 - if(Rsum > 4 * NumTraits<Scalar>::epsilon()) {// sin(beta) != 0 - res[0] = atan2(mat(J_, I_), minusPlus * mat(K_, I_)); - res[2] = atan2(mat(I_, J_), plusMinus * mat(I_, K_)); - } - else if(mat(I_, I_) > 0) {// sin(beta) == 0 and cos(beta) == 1 - Scalar spos = plusMinus * mat(K_, J_) + minusPlus * mat(J_, K_); // 2*sin(alpha + gamma) - Scalar cpos = mat(J_, J_) + mat(K_, K_); // 2*cos(alpha + gamma) - res[0] = atan2(spos, cpos); - res[2] = 0; - } - else {// sin(beta) == 0 and cos(beta) == -1 - Scalar sneg = plusMinus * mat(K_, J_) + plusMinus * mat(J_, K_); // 2*sin(alpha - gamma) - Scalar cneg = mat(J_, J_) - mat(K_, K_); // 2*cos(alpha - gamma) - res[0] = atan2(sneg, cneg); - res[2] = 0; - } - } - - template<typename Scalar> - static void CalcEulerAngles( - EulerAngles<Scalar, EulerSystem>& res, - const typename EulerAngles<Scalar, EulerSystem>::Matrix3& mat) - { - CalcEulerAngles_imp( - res.angles(), mat, - typename internal::conditional<IsTaitBryan, internal::true_type, internal::false_type>::type()); - - if (IsAlphaOpposite) - res.alpha() = -res.alpha(); - - if (IsBetaOpposite) - res.beta() = -res.beta(); - - if (IsGammaOpposite) - res.gamma() = -res.gamma(); - } - - template <typename _Scalar, class _System> - friend class Eigen::EulerAngles; - - template<typename System, - typename Other, - int OtherRows, - int OtherCols> - friend struct internal::eulerangles_assign_impl; - }; - -#define EIGEN_EULER_SYSTEM_TYPEDEF(A, B, C) \ - /** \ingroup EulerAngles_Module */ \ - typedef EulerSystem<EULER_##A, EULER_##B, EULER_##C> EulerSystem##A##B##C; - - EIGEN_EULER_SYSTEM_TYPEDEF(X,Y,Z) - EIGEN_EULER_SYSTEM_TYPEDEF(X,Y,X) - EIGEN_EULER_SYSTEM_TYPEDEF(X,Z,Y) - EIGEN_EULER_SYSTEM_TYPEDEF(X,Z,X) - - EIGEN_EULER_SYSTEM_TYPEDEF(Y,Z,X) - EIGEN_EULER_SYSTEM_TYPEDEF(Y,Z,Y) - EIGEN_EULER_SYSTEM_TYPEDEF(Y,X,Z) - EIGEN_EULER_SYSTEM_TYPEDEF(Y,X,Y) - - EIGEN_EULER_SYSTEM_TYPEDEF(Z,X,Y) - EIGEN_EULER_SYSTEM_TYPEDEF(Z,X,Z) - EIGEN_EULER_SYSTEM_TYPEDEF(Z,Y,X) - EIGEN_EULER_SYSTEM_TYPEDEF(Z,Y,Z) -} - -#endif // EIGEN_EULERSYSTEM_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/FFT/ei_fftw_impl.h b/external/eigen/include/eigen3/unsupported/Eigen/src/FFT/ei_fftw_impl.h deleted file mode 100644 index 7c1f716e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/FFT/ei_fftw_impl.h +++ /dev/null @@ -1,263 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Mark Borgerding mark a borgerding net -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -namespace Eigen { - -namespace internal { - - // FFTW uses non-const arguments - // so we must use ugly const_cast calls for all the args it uses - // - // This should be safe as long as - // 1. we use FFTW_ESTIMATE for all our planning - // see the FFTW docs section 4.3.2 "Planner Flags" - // 2. fftw_complex is compatible with std::complex - // This assumes std::complex<T> layout is array of size 2 with real,imag - template <typename T> - inline - T * fftw_cast(const T* p) - { - return const_cast<T*>( p); - } - - inline - fftw_complex * fftw_cast( const std::complex<double> * p) - { - return const_cast<fftw_complex*>( reinterpret_cast<const fftw_complex*>(p) ); - } - - inline - fftwf_complex * fftw_cast( const std::complex<float> * p) - { - return const_cast<fftwf_complex*>( reinterpret_cast<const fftwf_complex*>(p) ); - } - - inline - fftwl_complex * fftw_cast( const std::complex<long double> * p) - { - return const_cast<fftwl_complex*>( reinterpret_cast<const fftwl_complex*>(p) ); - } - - template <typename T> - struct fftw_plan {}; - - template <> - struct fftw_plan<float> - { - typedef float scalar_type; - typedef fftwf_complex complex_type; - fftwf_plan m_plan; - fftw_plan() :m_plan(NULL) {} - ~fftw_plan() {if (m_plan) fftwf_destroy_plan(m_plan);} - - inline - void fwd(complex_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftwf_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwf_execute_dft( m_plan, src,dst); - } - inline - void inv(complex_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftwf_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwf_execute_dft( m_plan, src,dst); - } - inline - void fwd(complex_type * dst,scalar_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftwf_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwf_execute_dft_r2c( m_plan,src,dst); - } - inline - void inv(scalar_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) - m_plan = fftwf_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwf_execute_dft_c2r( m_plan, src,dst); - } - - inline - void fwd2( complex_type * dst,complex_type * src,int n0,int n1) { - if (m_plan==NULL) m_plan = fftwf_plan_dft_2d(n0,n1,src,dst,FFTW_FORWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwf_execute_dft( m_plan, src,dst); - } - inline - void inv2( complex_type * dst,complex_type * src,int n0,int n1) { - if (m_plan==NULL) m_plan = fftwf_plan_dft_2d(n0,n1,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwf_execute_dft( m_plan, src,dst); - } - - }; - template <> - struct fftw_plan<double> - { - typedef double scalar_type; - typedef fftw_complex complex_type; - ::fftw_plan m_plan; - fftw_plan() :m_plan(NULL) {} - ~fftw_plan() {if (m_plan) fftw_destroy_plan(m_plan);} - - inline - void fwd(complex_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftw_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftw_execute_dft( m_plan, src,dst); - } - inline - void inv(complex_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftw_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftw_execute_dft( m_plan, src,dst); - } - inline - void fwd(complex_type * dst,scalar_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftw_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftw_execute_dft_r2c( m_plan,src,dst); - } - inline - void inv(scalar_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) - m_plan = fftw_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftw_execute_dft_c2r( m_plan, src,dst); - } - inline - void fwd2( complex_type * dst,complex_type * src,int n0,int n1) { - if (m_plan==NULL) m_plan = fftw_plan_dft_2d(n0,n1,src,dst,FFTW_FORWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftw_execute_dft( m_plan, src,dst); - } - inline - void inv2( complex_type * dst,complex_type * src,int n0,int n1) { - if (m_plan==NULL) m_plan = fftw_plan_dft_2d(n0,n1,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftw_execute_dft( m_plan, src,dst); - } - }; - template <> - struct fftw_plan<long double> - { - typedef long double scalar_type; - typedef fftwl_complex complex_type; - fftwl_plan m_plan; - fftw_plan() :m_plan(NULL) {} - ~fftw_plan() {if (m_plan) fftwl_destroy_plan(m_plan);} - - inline - void fwd(complex_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftwl_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwl_execute_dft( m_plan, src,dst); - } - inline - void inv(complex_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftwl_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwl_execute_dft( m_plan, src,dst); - } - inline - void fwd(complex_type * dst,scalar_type * src,int nfft) { - if (m_plan==NULL) m_plan = fftwl_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwl_execute_dft_r2c( m_plan,src,dst); - } - inline - void inv(scalar_type * dst,complex_type * src,int nfft) { - if (m_plan==NULL) - m_plan = fftwl_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwl_execute_dft_c2r( m_plan, src,dst); - } - inline - void fwd2( complex_type * dst,complex_type * src,int n0,int n1) { - if (m_plan==NULL) m_plan = fftwl_plan_dft_2d(n0,n1,src,dst,FFTW_FORWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwl_execute_dft( m_plan, src,dst); - } - inline - void inv2( complex_type * dst,complex_type * src,int n0,int n1) { - if (m_plan==NULL) m_plan = fftwl_plan_dft_2d(n0,n1,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); - fftwl_execute_dft( m_plan, src,dst); - } - }; - - template <typename _Scalar> - struct fftw_impl - { - typedef _Scalar Scalar; - typedef std::complex<Scalar> Complex; - - inline - void clear() - { - m_plans.clear(); - } - - // complex-to-complex forward FFT - inline - void fwd( Complex * dst,const Complex *src,int nfft) - { - get_plan(nfft,false,dst,src).fwd(fftw_cast(dst), fftw_cast(src),nfft ); - } - - // real-to-complex forward FFT - inline - void fwd( Complex * dst,const Scalar * src,int nfft) - { - get_plan(nfft,false,dst,src).fwd(fftw_cast(dst), fftw_cast(src) ,nfft); - } - - // 2-d complex-to-complex - inline - void fwd2(Complex * dst, const Complex * src, int n0,int n1) - { - get_plan(n0,n1,false,dst,src).fwd2(fftw_cast(dst), fftw_cast(src) ,n0,n1); - } - - // inverse complex-to-complex - inline - void inv(Complex * dst,const Complex *src,int nfft) - { - get_plan(nfft,true,dst,src).inv(fftw_cast(dst), fftw_cast(src),nfft ); - } - - // half-complex to scalar - inline - void inv( Scalar * dst,const Complex * src,int nfft) - { - get_plan(nfft,true,dst,src).inv(fftw_cast(dst), fftw_cast(src),nfft ); - } - - // 2-d complex-to-complex - inline - void inv2(Complex * dst, const Complex * src, int n0,int n1) - { - get_plan(n0,n1,true,dst,src).inv2(fftw_cast(dst), fftw_cast(src) ,n0,n1); - } - - - protected: - typedef fftw_plan<Scalar> PlanData; - - typedef Eigen::numext::int64_t int64_t; - - typedef std::map<int64_t,PlanData> PlanMap; - - PlanMap m_plans; - - inline - PlanData & get_plan(int nfft,bool inverse,void * dst,const void * src) - { - bool inplace = (dst==src); - bool aligned = ( (reinterpret_cast<size_t>(src)&15) | (reinterpret_cast<size_t>(dst)&15) ) == 0; - int64_t key = ( (nfft<<3 ) | (inverse<<2) | (inplace<<1) | aligned ) << 1; - return m_plans[key]; - } - - inline - PlanData & get_plan(int n0,int n1,bool inverse,void * dst,const void * src) - { - bool inplace = (dst==src); - bool aligned = ( (reinterpret_cast<size_t>(src)&15) | (reinterpret_cast<size_t>(dst)&15) ) == 0; - int64_t key = ( ( (((int64_t)n0) << 30)|(n1<<3 ) | (inverse<<2) | (inplace<<1) | aligned ) << 1 ) + 1; - return m_plans[key]; - } - }; - -} // end namespace internal - -} // end namespace Eigen - -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/FFT/ei_kissfft_impl.h b/external/eigen/include/eigen3/unsupported/Eigen/src/FFT/ei_kissfft_impl.h deleted file mode 100644 index 079e8860..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/FFT/ei_kissfft_impl.h +++ /dev/null @@ -1,420 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Mark Borgerding mark a borgerding net -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -namespace Eigen { - -namespace internal { - - // This FFT implementation was derived from kissfft http:sourceforge.net/projects/kissfft - // Copyright 2003-2009 Mark Borgerding - -template <typename _Scalar> -struct kiss_cpx_fft -{ - typedef _Scalar Scalar; - typedef std::complex<Scalar> Complex; - std::vector<Complex> m_twiddles; - std::vector<int> m_stageRadix; - std::vector<int> m_stageRemainder; - std::vector<Complex> m_scratchBuf; - bool m_inverse; - - inline - void make_twiddles(int nfft,bool inverse) - { - using std::acos; - m_inverse = inverse; - m_twiddles.resize(nfft); - Scalar phinc = (inverse?2:-2)* acos( (Scalar) -1) / nfft; - for (int i=0;i<nfft;++i) - m_twiddles[i] = exp( Complex(0,i*phinc) ); - } - - void factorize(int nfft) - { - //start factoring out 4's, then 2's, then 3,5,7,9,... - int n= nfft; - int p=4; - do { - while (n % p) { - switch (p) { - case 4: p = 2; break; - case 2: p = 3; break; - default: p += 2; break; - } - if (p*p>n) - p=n;// impossible to have a factor > sqrt(n) - } - n /= p; - m_stageRadix.push_back(p); - m_stageRemainder.push_back(n); - if ( p > 5 ) - m_scratchBuf.resize(p); // scratchbuf will be needed in bfly_generic - }while(n>1); - } - - template <typename _Src> - inline - void work( int stage,Complex * xout, const _Src * xin, size_t fstride,size_t in_stride) - { - int p = m_stageRadix[stage]; - int m = m_stageRemainder[stage]; - Complex * Fout_beg = xout; - Complex * Fout_end = xout + p*m; - - if (m>1) { - do{ - // recursive call: - // DFT of size m*p performed by doing - // p instances of smaller DFTs of size m, - // each one takes a decimated version of the input - work(stage+1, xout , xin, fstride*p,in_stride); - xin += fstride*in_stride; - }while( (xout += m) != Fout_end ); - }else{ - do{ - *xout = *xin; - xin += fstride*in_stride; - }while(++xout != Fout_end ); - } - xout=Fout_beg; - - // recombine the p smaller DFTs - switch (p) { - case 2: bfly2(xout,fstride,m); break; - case 3: bfly3(xout,fstride,m); break; - case 4: bfly4(xout,fstride,m); break; - case 5: bfly5(xout,fstride,m); break; - default: bfly_generic(xout,fstride,m,p); break; - } - } - - inline - void bfly2( Complex * Fout, const size_t fstride, int m) - { - for (int k=0;k<m;++k) { - Complex t = Fout[m+k] * m_twiddles[k*fstride]; - Fout[m+k] = Fout[k] - t; - Fout[k] += t; - } - } - - inline - void bfly4( Complex * Fout, const size_t fstride, const size_t m) - { - Complex scratch[6]; - int negative_if_inverse = m_inverse * -2 +1; - for (size_t k=0;k<m;++k) { - scratch[0] = Fout[k+m] * m_twiddles[k*fstride]; - scratch[1] = Fout[k+2*m] * m_twiddles[k*fstride*2]; - scratch[2] = Fout[k+3*m] * m_twiddles[k*fstride*3]; - scratch[5] = Fout[k] - scratch[1]; - - Fout[k] += scratch[1]; - scratch[3] = scratch[0] + scratch[2]; - scratch[4] = scratch[0] - scratch[2]; - scratch[4] = Complex( scratch[4].imag()*negative_if_inverse , -scratch[4].real()* negative_if_inverse ); - - Fout[k+2*m] = Fout[k] - scratch[3]; - Fout[k] += scratch[3]; - Fout[k+m] = scratch[5] + scratch[4]; - Fout[k+3*m] = scratch[5] - scratch[4]; - } - } - - inline - void bfly3( Complex * Fout, const size_t fstride, const size_t m) - { - size_t k=m; - const size_t m2 = 2*m; - Complex *tw1,*tw2; - Complex scratch[5]; - Complex epi3; - epi3 = m_twiddles[fstride*m]; - - tw1=tw2=&m_twiddles[0]; - - do{ - scratch[1]=Fout[m] * *tw1; - scratch[2]=Fout[m2] * *tw2; - - scratch[3]=scratch[1]+scratch[2]; - scratch[0]=scratch[1]-scratch[2]; - tw1 += fstride; - tw2 += fstride*2; - Fout[m] = Complex( Fout->real() - Scalar(.5)*scratch[3].real() , Fout->imag() - Scalar(.5)*scratch[3].imag() ); - scratch[0] *= epi3.imag(); - *Fout += scratch[3]; - Fout[m2] = Complex( Fout[m].real() + scratch[0].imag() , Fout[m].imag() - scratch[0].real() ); - Fout[m] += Complex( -scratch[0].imag(),scratch[0].real() ); - ++Fout; - }while(--k); - } - - inline - void bfly5( Complex * Fout, const size_t fstride, const size_t m) - { - Complex *Fout0,*Fout1,*Fout2,*Fout3,*Fout4; - size_t u; - Complex scratch[13]; - Complex * twiddles = &m_twiddles[0]; - Complex *tw; - Complex ya,yb; - ya = twiddles[fstride*m]; - yb = twiddles[fstride*2*m]; - - Fout0=Fout; - Fout1=Fout0+m; - Fout2=Fout0+2*m; - Fout3=Fout0+3*m; - Fout4=Fout0+4*m; - - tw=twiddles; - for ( u=0; u<m; ++u ) { - scratch[0] = *Fout0; - - scratch[1] = *Fout1 * tw[u*fstride]; - scratch[2] = *Fout2 * tw[2*u*fstride]; - scratch[3] = *Fout3 * tw[3*u*fstride]; - scratch[4] = *Fout4 * tw[4*u*fstride]; - - scratch[7] = scratch[1] + scratch[4]; - scratch[10] = scratch[1] - scratch[4]; - scratch[8] = scratch[2] + scratch[3]; - scratch[9] = scratch[2] - scratch[3]; - - *Fout0 += scratch[7]; - *Fout0 += scratch[8]; - - scratch[5] = scratch[0] + Complex( - (scratch[7].real()*ya.real() ) + (scratch[8].real() *yb.real() ), - (scratch[7].imag()*ya.real()) + (scratch[8].imag()*yb.real()) - ); - - scratch[6] = Complex( - (scratch[10].imag()*ya.imag()) + (scratch[9].imag()*yb.imag()), - -(scratch[10].real()*ya.imag()) - (scratch[9].real()*yb.imag()) - ); - - *Fout1 = scratch[5] - scratch[6]; - *Fout4 = scratch[5] + scratch[6]; - - scratch[11] = scratch[0] + - Complex( - (scratch[7].real()*yb.real()) + (scratch[8].real()*ya.real()), - (scratch[7].imag()*yb.real()) + (scratch[8].imag()*ya.real()) - ); - - scratch[12] = Complex( - -(scratch[10].imag()*yb.imag()) + (scratch[9].imag()*ya.imag()), - (scratch[10].real()*yb.imag()) - (scratch[9].real()*ya.imag()) - ); - - *Fout2=scratch[11]+scratch[12]; - *Fout3=scratch[11]-scratch[12]; - - ++Fout0;++Fout1;++Fout2;++Fout3;++Fout4; - } - } - - /* perform the butterfly for one stage of a mixed radix FFT */ - inline - void bfly_generic( - Complex * Fout, - const size_t fstride, - int m, - int p - ) - { - int u,k,q1,q; - Complex * twiddles = &m_twiddles[0]; - Complex t; - int Norig = static_cast<int>(m_twiddles.size()); - Complex * scratchbuf = &m_scratchBuf[0]; - - for ( u=0; u<m; ++u ) { - k=u; - for ( q1=0 ; q1<p ; ++q1 ) { - scratchbuf[q1] = Fout[ k ]; - k += m; - } - - k=u; - for ( q1=0 ; q1<p ; ++q1 ) { - int twidx=0; - Fout[ k ] = scratchbuf[0]; - for (q=1;q<p;++q ) { - twidx += static_cast<int>(fstride) * k; - if (twidx>=Norig) twidx-=Norig; - t=scratchbuf[q] * twiddles[twidx]; - Fout[ k ] += t; - } - k += m; - } - } - } -}; - -template <typename _Scalar> -struct kissfft_impl -{ - typedef _Scalar Scalar; - typedef std::complex<Scalar> Complex; - - void clear() - { - m_plans.clear(); - m_realTwiddles.clear(); - } - - inline - void fwd( Complex * dst,const Complex *src,int nfft) - { - get_plan(nfft,false).work(0, dst, src, 1,1); - } - - inline - void fwd2( Complex * dst,const Complex *src,int n0,int n1) - { - EIGEN_UNUSED_VARIABLE(dst); - EIGEN_UNUSED_VARIABLE(src); - EIGEN_UNUSED_VARIABLE(n0); - EIGEN_UNUSED_VARIABLE(n1); - } - - inline - void inv2( Complex * dst,const Complex *src,int n0,int n1) - { - EIGEN_UNUSED_VARIABLE(dst); - EIGEN_UNUSED_VARIABLE(src); - EIGEN_UNUSED_VARIABLE(n0); - EIGEN_UNUSED_VARIABLE(n1); - } - - // real-to-complex forward FFT - // perform two FFTs of src even and src odd - // then twiddle to recombine them into the half-spectrum format - // then fill in the conjugate symmetric half - inline - void fwd( Complex * dst,const Scalar * src,int nfft) - { - if ( nfft&3 ) { - // use generic mode for odd - m_tmpBuf1.resize(nfft); - get_plan(nfft,false).work(0, &m_tmpBuf1[0], src, 1,1); - std::copy(m_tmpBuf1.begin(),m_tmpBuf1.begin()+(nfft>>1)+1,dst ); - }else{ - int ncfft = nfft>>1; - int ncfft2 = nfft>>2; - Complex * rtw = real_twiddles(ncfft2); - - // use optimized mode for even real - fwd( dst, reinterpret_cast<const Complex*> (src), ncfft); - Complex dc(dst[0].real() + dst[0].imag()); - Complex nyquist(dst[0].real() - dst[0].imag()); - int k; - for ( k=1;k <= ncfft2 ; ++k ) { - Complex fpk = dst[k]; - Complex fpnk = conj(dst[ncfft-k]); - Complex f1k = fpk + fpnk; - Complex f2k = fpk - fpnk; - Complex tw= f2k * rtw[k-1]; - dst[k] = (f1k + tw) * Scalar(.5); - dst[ncfft-k] = conj(f1k -tw)*Scalar(.5); - } - dst[0] = dc; - dst[ncfft] = nyquist; - } - } - - // inverse complex-to-complex - inline - void inv(Complex * dst,const Complex *src,int nfft) - { - get_plan(nfft,true).work(0, dst, src, 1,1); - } - - // half-complex to scalar - inline - void inv( Scalar * dst,const Complex * src,int nfft) - { - if (nfft&3) { - m_tmpBuf1.resize(nfft); - m_tmpBuf2.resize(nfft); - std::copy(src,src+(nfft>>1)+1,m_tmpBuf1.begin() ); - for (int k=1;k<(nfft>>1)+1;++k) - m_tmpBuf1[nfft-k] = conj(m_tmpBuf1[k]); - inv(&m_tmpBuf2[0],&m_tmpBuf1[0],nfft); - for (int k=0;k<nfft;++k) - dst[k] = m_tmpBuf2[k].real(); - }else{ - // optimized version for multiple of 4 - int ncfft = nfft>>1; - int ncfft2 = nfft>>2; - Complex * rtw = real_twiddles(ncfft2); - m_tmpBuf1.resize(ncfft); - m_tmpBuf1[0] = Complex( src[0].real() + src[ncfft].real(), src[0].real() - src[ncfft].real() ); - for (int k = 1; k <= ncfft / 2; ++k) { - Complex fk = src[k]; - Complex fnkc = conj(src[ncfft-k]); - Complex fek = fk + fnkc; - Complex tmp = fk - fnkc; - Complex fok = tmp * conj(rtw[k-1]); - m_tmpBuf1[k] = fek + fok; - m_tmpBuf1[ncfft-k] = conj(fek - fok); - } - get_plan(ncfft,true).work(0, reinterpret_cast<Complex*>(dst), &m_tmpBuf1[0], 1,1); - } - } - - protected: - typedef kiss_cpx_fft<Scalar> PlanData; - typedef std::map<int,PlanData> PlanMap; - - PlanMap m_plans; - std::map<int, std::vector<Complex> > m_realTwiddles; - std::vector<Complex> m_tmpBuf1; - std::vector<Complex> m_tmpBuf2; - - inline - int PlanKey(int nfft, bool isinverse) const { return (nfft<<1) | int(isinverse); } - - inline - PlanData & get_plan(int nfft, bool inverse) - { - // TODO look for PlanKey(nfft, ! inverse) and conjugate the twiddles - PlanData & pd = m_plans[ PlanKey(nfft,inverse) ]; - if ( pd.m_twiddles.size() == 0 ) { - pd.make_twiddles(nfft,inverse); - pd.factorize(nfft); - } - return pd; - } - - inline - Complex * real_twiddles(int ncfft2) - { - using std::acos; - std::vector<Complex> & twidref = m_realTwiddles[ncfft2];// creates new if not there - if ( (int)twidref.size() != ncfft2 ) { - twidref.resize(ncfft2); - int ncfft= ncfft2<<1; - Scalar pi = acos( Scalar(-1) ); - for (int k=1;k<=ncfft2;++k) - twidref[k-1] = exp( Complex(0,-pi * (Scalar(k) / ncfft + Scalar(.5)) ) ); - } - return &twidref[0]; - } -}; - -} // end namespace internal - -} // end namespace Eigen - -/* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/ConstrainedConjGrad.h b/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/ConstrainedConjGrad.h deleted file mode 100644 index 5f7cdf29..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/ConstrainedConjGrad.h +++ /dev/null @@ -1,189 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> - -/* NOTE The functions of this file have been adapted from the GMM++ library */ - -//======================================================================== -// -// Copyright (C) 2002-2007 Yves Renard -// -// This file is a part of GETFEM++ -// -// Getfem++ is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; version 2.1 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// You should have received a copy of the GNU Lesser General Public -// License along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, -// USA. -// -//======================================================================== - -#include "../../../../Eigen/src/Core/util/NonMPL2.h" - -#ifndef EIGEN_CONSTRAINEDCG_H -#define EIGEN_CONSTRAINEDCG_H - -#include "../../../../Eigen/Core" - -namespace Eigen { - -namespace internal { - -/** \ingroup IterativeSolvers_Module - * Compute the pseudo inverse of the non-square matrix C such that - * \f$ CINV = (C * C^T)^{-1} * C \f$ based on a conjugate gradient method. - * - * This function is internally used by constrained_cg. - */ -template <typename CMatrix, typename CINVMatrix> -void pseudo_inverse(const CMatrix &C, CINVMatrix &CINV) -{ - // optimisable : copie de la ligne, precalcul de C * trans(C). - typedef typename CMatrix::Scalar Scalar; - typedef typename CMatrix::Index Index; - // FIXME use sparse vectors ? - typedef Matrix<Scalar,Dynamic,1> TmpVec; - - Index rows = C.rows(), cols = C.cols(); - - TmpVec d(rows), e(rows), l(cols), p(rows), q(rows), r(rows); - Scalar rho, rho_1, alpha; - d.setZero(); - - typedef Triplet<double> T; - std::vector<T> tripletList; - - for (Index i = 0; i < rows; ++i) - { - d[i] = 1.0; - rho = 1.0; - e.setZero(); - r = d; - p = d; - - while (rho >= 1e-38) - { /* conjugate gradient to compute e */ - /* which is the i-th row of inv(C * trans(C)) */ - l = C.transpose() * p; - q = C * l; - alpha = rho / p.dot(q); - e += alpha * p; - r += -alpha * q; - rho_1 = rho; - rho = r.dot(r); - p = (rho/rho_1) * p + r; - } - - l = C.transpose() * e; // l is the i-th row of CINV - // FIXME add a generic "prune/filter" expression for both dense and sparse object to sparse - for (Index j=0; j<l.size(); ++j) - if (l[j]<1e-15) - tripletList.push_back(T(i,j,l(j))); - - - d[i] = 0.0; - } - CINV.setFromTriplets(tripletList.begin(), tripletList.end()); -} - - - -/** \ingroup IterativeSolvers_Module - * Constrained conjugate gradient - * - * Computes the minimum of \f$ 1/2((Ax).x) - bx \f$ under the constraint \f$ Cx \le f \f$ - */ -template<typename TMatrix, typename CMatrix, - typename VectorX, typename VectorB, typename VectorF> -void constrained_cg(const TMatrix& A, const CMatrix& C, VectorX& x, - const VectorB& b, const VectorF& f, IterationController &iter) -{ - using std::sqrt; - typedef typename TMatrix::Scalar Scalar; - typedef typename TMatrix::Index Index; - typedef Matrix<Scalar,Dynamic,1> TmpVec; - - Scalar rho = 1.0, rho_1, lambda, gamma; - Index xSize = x.size(); - TmpVec p(xSize), q(xSize), q2(xSize), - r(xSize), old_z(xSize), z(xSize), - memox(xSize); - std::vector<bool> satured(C.rows()); - p.setZero(); - iter.setRhsNorm(sqrt(b.dot(b))); // gael vect_sp(PS, b, b) - if (iter.rhsNorm() == 0.0) iter.setRhsNorm(1.0); - - SparseMatrix<Scalar,RowMajor> CINV(C.rows(), C.cols()); - pseudo_inverse(C, CINV); - - while(true) - { - // computation of residual - old_z = z; - memox = x; - r = b; - r += A * -x; - z = r; - bool transition = false; - for (Index i = 0; i < C.rows(); ++i) - { - Scalar al = C.row(i).dot(x) - f.coeff(i); - if (al >= -1.0E-15) - { - if (!satured[i]) - { - satured[i] = true; - transition = true; - } - Scalar bb = CINV.row(i).dot(z); - if (bb > 0.0) - // FIXME: we should allow that: z += -bb * C.row(i); - for (typename CMatrix::InnerIterator it(C,i); it; ++it) - z.coeffRef(it.index()) -= bb*it.value(); - } - else - satured[i] = false; - } - - // descent direction - rho_1 = rho; - rho = r.dot(z); - - if (iter.finished(rho)) break; - - if (iter.noiseLevel() > 0 && transition) std::cerr << "CCG: transition\n"; - if (transition || iter.first()) gamma = 0.0; - else gamma = (std::max)(0.0, (rho - old_z.dot(z)) / rho_1); - p = z + gamma*p; - - ++iter; - // one dimensionnal optimization - q = A * p; - lambda = rho / q.dot(p); - for (Index i = 0; i < C.rows(); ++i) - { - if (!satured[i]) - { - Scalar bb = C.row(i).dot(p) - f[i]; - if (bb > 0.0) - lambda = (std::min)(lambda, (f.coeff(i)-C.row(i).dot(x)) / bb); - } - } - x += lambda * p; - memox -= x; - } -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_CONSTRAINEDCG_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/DGMRES.h b/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/DGMRES.h deleted file mode 100644 index 2ab56b5e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/DGMRES.h +++ /dev/null @@ -1,511 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DGMRES_H -#define EIGEN_DGMRES_H - -#include "../../../../Eigen/Eigenvalues" - -namespace Eigen { - -template< typename _MatrixType, - typename _Preconditioner = DiagonalPreconditioner<typename _MatrixType::Scalar> > -class DGMRES; - -namespace internal { - -template< typename _MatrixType, typename _Preconditioner> -struct traits<DGMRES<_MatrixType,_Preconditioner> > -{ - typedef _MatrixType MatrixType; - typedef _Preconditioner Preconditioner; -}; - -/** \brief Computes a permutation vector to have a sorted sequence - * \param vec The vector to reorder. - * \param perm gives the sorted sequence on output. Must be initialized with 0..n-1 - * \param ncut Put the ncut smallest elements at the end of the vector - * WARNING This is an expensive sort, so should be used only - * for small size vectors - * TODO Use modified QuickSplit or std::nth_element to get the smallest values - */ -template <typename VectorType, typename IndexType> -void sortWithPermutation (VectorType& vec, IndexType& perm, typename IndexType::Scalar& ncut) -{ - eigen_assert(vec.size() == perm.size()); - bool flag; - for (Index k = 0; k < ncut; k++) - { - flag = false; - for (Index j = 0; j < vec.size()-1; j++) - { - if ( vec(perm(j)) < vec(perm(j+1)) ) - { - std::swap(perm(j),perm(j+1)); - flag = true; - } - if (!flag) break; // The vector is in sorted order - } - } -} - -} -/** - * \ingroup IterativeLInearSolvers_Module - * \brief A Restarted GMRES with deflation. - * This class implements a modification of the GMRES solver for - * sparse linear systems. The basis is built with modified - * Gram-Schmidt. At each restart, a few approximated eigenvectors - * corresponding to the smallest eigenvalues are used to build a - * preconditioner for the next cycle. This preconditioner - * for deflation can be combined with any other preconditioner, - * the IncompleteLUT for instance. The preconditioner is applied - * at right of the matrix and the combination is multiplicative. - * - * \tparam _MatrixType the type of the sparse matrix A, can be a dense or a sparse matrix. - * \tparam _Preconditioner the type of the preconditioner. Default is DiagonalPreconditioner - * Typical usage : - * \code - * SparseMatrix<double> A; - * VectorXd x, b; - * //Fill A and b ... - * DGMRES<SparseMatrix<double> > solver; - * solver.set_restart(30); // Set restarting value - * solver.setEigenv(1); // Set the number of eigenvalues to deflate - * solver.compute(A); - * x = solver.solve(b); - * \endcode - * - * DGMRES can also be used in a matrix-free context, see the following \link MatrixfreeSolverExample example \endlink. - * - * References : - * [1] D. NUENTSA WAKAM and F. PACULL, Memory Efficient Hybrid - * Algebraic Solvers for Linear Systems Arising from Compressible - * Flows, Computers and Fluids, In Press, - * https://doi.org/10.1016/j.compfluid.2012.03.023 - * [2] K. Burrage and J. Erhel, On the performance of various - * adaptive preconditioned GMRES strategies, 5(1998), 101-121. - * [3] J. Erhel, K. Burrage and B. Pohl, Restarted GMRES - * preconditioned by deflation,J. Computational and Applied - * Mathematics, 69(1996), 303-318. - - * - */ -template< typename _MatrixType, typename _Preconditioner> -class DGMRES : public IterativeSolverBase<DGMRES<_MatrixType,_Preconditioner> > -{ - typedef IterativeSolverBase<DGMRES> Base; - using Base::matrix; - using Base::m_error; - using Base::m_iterations; - using Base::m_info; - using Base::m_isInitialized; - using Base::m_tolerance; - public: - using Base::_solve_impl; - using Base::_solve_with_guess_impl; - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::StorageIndex StorageIndex; - typedef typename MatrixType::RealScalar RealScalar; - typedef _Preconditioner Preconditioner; - typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix; - typedef Matrix<RealScalar,Dynamic,Dynamic> DenseRealMatrix; - typedef Matrix<Scalar,Dynamic,1> DenseVector; - typedef Matrix<RealScalar,Dynamic,1> DenseRealVector; - typedef Matrix<std::complex<RealScalar>, Dynamic, 1> ComplexVector; - - - /** Default constructor. */ - DGMRES() : Base(),m_restart(30),m_neig(0),m_r(0),m_maxNeig(5),m_isDeflAllocated(false),m_isDeflInitialized(false) {} - - /** Initialize the solver with matrix \a A for further \c Ax=b solving. - * - * This constructor is a shortcut for the default constructor followed - * by a call to compute(). - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - explicit DGMRES(const EigenBase<MatrixDerived>& A) : Base(A.derived()), m_restart(30),m_neig(0),m_r(0),m_maxNeig(5),m_isDeflAllocated(false),m_isDeflInitialized(false) {} - - ~DGMRES() {} - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_vector_with_guess_impl(const Rhs& b, Dest& x) const - { - EIGEN_STATIC_ASSERT(Rhs::ColsAtCompileTime==1 || Dest::ColsAtCompileTime==1, YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX); - - m_iterations = Base::maxIterations(); - m_error = Base::m_tolerance; - - dgmres(matrix(), b, x, Base::m_preconditioner); - } - - /** - * Get the restart value - */ - Index restart() { return m_restart; } - - /** - * Set the restart value (default is 30) - */ - void set_restart(const Index restart) { m_restart=restart; } - - /** - * Set the number of eigenvalues to deflate at each restart - */ - void setEigenv(const Index neig) - { - m_neig = neig; - if (neig+1 > m_maxNeig) m_maxNeig = neig+1; // To allow for complex conjugates - } - - /** - * Get the size of the deflation subspace size - */ - Index deflSize() {return m_r; } - - /** - * Set the maximum size of the deflation subspace - */ - void setMaxEigenv(const Index maxNeig) { m_maxNeig = maxNeig; } - - protected: - // DGMRES algorithm - template<typename Rhs, typename Dest> - void dgmres(const MatrixType& mat,const Rhs& rhs, Dest& x, const Preconditioner& precond) const; - // Perform one cycle of GMRES - template<typename Dest> - Index dgmresCycle(const MatrixType& mat, const Preconditioner& precond, Dest& x, DenseVector& r0, RealScalar& beta, const RealScalar& normRhs, Index& nbIts) const; - // Compute data to use for deflation - Index dgmresComputeDeflationData(const MatrixType& mat, const Preconditioner& precond, const Index& it, StorageIndex& neig) const; - // Apply deflation to a vector - template<typename RhsType, typename DestType> - Index dgmresApplyDeflation(const RhsType& In, DestType& Out) const; - ComplexVector schurValues(const ComplexSchur<DenseMatrix>& schurofH) const; - ComplexVector schurValues(const RealSchur<DenseMatrix>& schurofH) const; - // Init data for deflation - void dgmresInitDeflation(Index& rows) const; - mutable DenseMatrix m_V; // Krylov basis vectors - mutable DenseMatrix m_H; // Hessenberg matrix - mutable DenseMatrix m_Hes; // Initial hessenberg matrix without Givens rotations applied - mutable Index m_restart; // Maximum size of the Krylov subspace - mutable DenseMatrix m_U; // Vectors that form the basis of the invariant subspace - mutable DenseMatrix m_MU; // matrix operator applied to m_U (for next cycles) - mutable DenseMatrix m_T; /* T=U^T*M^{-1}*A*U */ - mutable PartialPivLU<DenseMatrix> m_luT; // LU factorization of m_T - mutable StorageIndex m_neig; //Number of eigenvalues to extract at each restart - mutable Index m_r; // Current number of deflated eigenvalues, size of m_U - mutable Index m_maxNeig; // Maximum number of eigenvalues to deflate - mutable RealScalar m_lambdaN; //Modulus of the largest eigenvalue of A - mutable bool m_isDeflAllocated; - mutable bool m_isDeflInitialized; - - //Adaptive strategy - mutable RealScalar m_smv; // Smaller multiple of the remaining number of steps allowed - mutable bool m_force; // Force the use of deflation at each restart - -}; -/** - * \brief Perform several cycles of restarted GMRES with modified Gram Schmidt, - * - * A right preconditioner is used combined with deflation. - * - */ -template< typename _MatrixType, typename _Preconditioner> -template<typename Rhs, typename Dest> -void DGMRES<_MatrixType, _Preconditioner>::dgmres(const MatrixType& mat,const Rhs& rhs, Dest& x, - const Preconditioner& precond) const -{ - const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)(); - - RealScalar normRhs = rhs.norm(); - if(normRhs <= considerAsZero) - { - x.setZero(); - m_error = 0; - return; - } - - //Initialization - m_isDeflInitialized = false; - Index n = mat.rows(); - DenseVector r0(n); - Index nbIts = 0; - m_H.resize(m_restart+1, m_restart); - m_Hes.resize(m_restart, m_restart); - m_V.resize(n,m_restart+1); - //Initial residual vector and initial norm - if(x.squaredNorm()==0) - x = precond.solve(rhs); - r0 = rhs - mat * x; - RealScalar beta = r0.norm(); - - m_error = beta/normRhs; - if(m_error < m_tolerance) - m_info = Success; - else - m_info = NoConvergence; - - // Iterative process - while (nbIts < m_iterations && m_info == NoConvergence) - { - dgmresCycle(mat, precond, x, r0, beta, normRhs, nbIts); - - // Compute the new residual vector for the restart - if (nbIts < m_iterations && m_info == NoConvergence) { - r0 = rhs - mat * x; - beta = r0.norm(); - } - } -} - -/** - * \brief Perform one restart cycle of DGMRES - * \param mat The coefficient matrix - * \param precond The preconditioner - * \param x the new approximated solution - * \param r0 The initial residual vector - * \param beta The norm of the residual computed so far - * \param normRhs The norm of the right hand side vector - * \param nbIts The number of iterations - */ -template< typename _MatrixType, typename _Preconditioner> -template<typename Dest> -Index DGMRES<_MatrixType, _Preconditioner>::dgmresCycle(const MatrixType& mat, const Preconditioner& precond, Dest& x, DenseVector& r0, RealScalar& beta, const RealScalar& normRhs, Index& nbIts) const -{ - //Initialization - DenseVector g(m_restart+1); // Right hand side of the least square problem - g.setZero(); - g(0) = Scalar(beta); - m_V.col(0) = r0/beta; - m_info = NoConvergence; - std::vector<JacobiRotation<Scalar> >gr(m_restart); // Givens rotations - Index it = 0; // Number of inner iterations - Index n = mat.rows(); - DenseVector tv1(n), tv2(n); //Temporary vectors - while (m_info == NoConvergence && it < m_restart && nbIts < m_iterations) - { - // Apply preconditioner(s) at right - if (m_isDeflInitialized ) - { - dgmresApplyDeflation(m_V.col(it), tv1); // Deflation - tv2 = precond.solve(tv1); - } - else - { - tv2 = precond.solve(m_V.col(it)); // User's selected preconditioner - } - tv1 = mat * tv2; - - // Orthogonalize it with the previous basis in the basis using modified Gram-Schmidt - Scalar coef; - for (Index i = 0; i <= it; ++i) - { - coef = tv1.dot(m_V.col(i)); - tv1 = tv1 - coef * m_V.col(i); - m_H(i,it) = coef; - m_Hes(i,it) = coef; - } - // Normalize the vector - coef = tv1.norm(); - m_V.col(it+1) = tv1/coef; - m_H(it+1, it) = coef; -// m_Hes(it+1,it) = coef; - - // FIXME Check for happy breakdown - - // Update Hessenberg matrix with Givens rotations - for (Index i = 1; i <= it; ++i) - { - m_H.col(it).applyOnTheLeft(i-1,i,gr[i-1].adjoint()); - } - // Compute the new plane rotation - gr[it].makeGivens(m_H(it, it), m_H(it+1,it)); - // Apply the new rotation - m_H.col(it).applyOnTheLeft(it,it+1,gr[it].adjoint()); - g.applyOnTheLeft(it,it+1, gr[it].adjoint()); - - beta = std::abs(g(it+1)); - m_error = beta/normRhs; - // std::cerr << nbIts << " Relative Residual Norm " << m_error << std::endl; - it++; nbIts++; - - if (m_error < m_tolerance) - { - // The method has converged - m_info = Success; - break; - } - } - - // Compute the new coefficients by solving the least square problem -// it++; - //FIXME Check first if the matrix is singular ... zero diagonal - DenseVector nrs(m_restart); - nrs = m_H.topLeftCorner(it,it).template triangularView<Upper>().solve(g.head(it)); - - // Form the new solution - if (m_isDeflInitialized) - { - tv1 = m_V.leftCols(it) * nrs; - dgmresApplyDeflation(tv1, tv2); - x = x + precond.solve(tv2); - } - else - x = x + precond.solve(m_V.leftCols(it) * nrs); - - // Go for a new cycle and compute data for deflation - if(nbIts < m_iterations && m_info == NoConvergence && m_neig > 0 && (m_r+m_neig) < m_maxNeig) - dgmresComputeDeflationData(mat, precond, it, m_neig); - return 0; - -} - - -template< typename _MatrixType, typename _Preconditioner> -void DGMRES<_MatrixType, _Preconditioner>::dgmresInitDeflation(Index& rows) const -{ - m_U.resize(rows, m_maxNeig); - m_MU.resize(rows, m_maxNeig); - m_T.resize(m_maxNeig, m_maxNeig); - m_lambdaN = 0.0; - m_isDeflAllocated = true; -} - -template< typename _MatrixType, typename _Preconditioner> -inline typename DGMRES<_MatrixType, _Preconditioner>::ComplexVector DGMRES<_MatrixType, _Preconditioner>::schurValues(const ComplexSchur<DenseMatrix>& schurofH) const -{ - return schurofH.matrixT().diagonal(); -} - -template< typename _MatrixType, typename _Preconditioner> -inline typename DGMRES<_MatrixType, _Preconditioner>::ComplexVector DGMRES<_MatrixType, _Preconditioner>::schurValues(const RealSchur<DenseMatrix>& schurofH) const -{ - const DenseMatrix& T = schurofH.matrixT(); - Index it = T.rows(); - ComplexVector eig(it); - Index j = 0; - while (j < it-1) - { - if (T(j+1,j) ==Scalar(0)) - { - eig(j) = std::complex<RealScalar>(T(j,j),RealScalar(0)); - j++; - } - else - { - eig(j) = std::complex<RealScalar>(T(j,j),T(j+1,j)); - eig(j+1) = std::complex<RealScalar>(T(j,j+1),T(j+1,j+1)); - j++; - } - } - if (j < it-1) eig(j) = std::complex<RealScalar>(T(j,j),RealScalar(0)); - return eig; -} - -template< typename _MatrixType, typename _Preconditioner> -Index DGMRES<_MatrixType, _Preconditioner>::dgmresComputeDeflationData(const MatrixType& mat, const Preconditioner& precond, const Index& it, StorageIndex& neig) const -{ - // First, find the Schur form of the Hessenberg matrix H - typename internal::conditional<NumTraits<Scalar>::IsComplex, ComplexSchur<DenseMatrix>, RealSchur<DenseMatrix> >::type schurofH; - bool computeU = true; - DenseMatrix matrixQ(it,it); - matrixQ.setIdentity(); - schurofH.computeFromHessenberg(m_Hes.topLeftCorner(it,it), matrixQ, computeU); - - ComplexVector eig(it); - Matrix<StorageIndex,Dynamic,1>perm(it); - eig = this->schurValues(schurofH); - - // Reorder the absolute values of Schur values - DenseRealVector modulEig(it); - for (Index j=0; j<it; ++j) modulEig(j) = std::abs(eig(j)); - perm.setLinSpaced(it,0,internal::convert_index<StorageIndex>(it-1)); - internal::sortWithPermutation(modulEig, perm, neig); - - if (!m_lambdaN) - { - m_lambdaN = (std::max)(modulEig.maxCoeff(), m_lambdaN); - } - //Count the real number of extracted eigenvalues (with complex conjugates) - Index nbrEig = 0; - while (nbrEig < neig) - { - if(eig(perm(it-nbrEig-1)).imag() == RealScalar(0)) nbrEig++; - else nbrEig += 2; - } - // Extract the Schur vectors corresponding to the smallest Ritz values - DenseMatrix Sr(it, nbrEig); - Sr.setZero(); - for (Index j = 0; j < nbrEig; j++) - { - Sr.col(j) = schurofH.matrixU().col(perm(it-j-1)); - } - - // Form the Schur vectors of the initial matrix using the Krylov basis - DenseMatrix X; - X = m_V.leftCols(it) * Sr; - if (m_r) - { - // Orthogonalize X against m_U using modified Gram-Schmidt - for (Index j = 0; j < nbrEig; j++) - for (Index k =0; k < m_r; k++) - X.col(j) = X.col(j) - (m_U.col(k).dot(X.col(j)))*m_U.col(k); - } - - // Compute m_MX = A * M^-1 * X - Index m = m_V.rows(); - if (!m_isDeflAllocated) - dgmresInitDeflation(m); - DenseMatrix MX(m, nbrEig); - DenseVector tv1(m); - for (Index j = 0; j < nbrEig; j++) - { - tv1 = mat * X.col(j); - MX.col(j) = precond.solve(tv1); - } - - //Update m_T = [U'MU U'MX; X'MU X'MX] - m_T.block(m_r, m_r, nbrEig, nbrEig) = X.transpose() * MX; - if(m_r) - { - m_T.block(0, m_r, m_r, nbrEig) = m_U.leftCols(m_r).transpose() * MX; - m_T.block(m_r, 0, nbrEig, m_r) = X.transpose() * m_MU.leftCols(m_r); - } - - // Save X into m_U and m_MX in m_MU - for (Index j = 0; j < nbrEig; j++) m_U.col(m_r+j) = X.col(j); - for (Index j = 0; j < nbrEig; j++) m_MU.col(m_r+j) = MX.col(j); - // Increase the size of the invariant subspace - m_r += nbrEig; - - // Factorize m_T into m_luT - m_luT.compute(m_T.topLeftCorner(m_r, m_r)); - - //FIXME CHeck if the factorization was correctly done (nonsingular matrix) - m_isDeflInitialized = true; - return 0; -} -template<typename _MatrixType, typename _Preconditioner> -template<typename RhsType, typename DestType> -Index DGMRES<_MatrixType, _Preconditioner>::dgmresApplyDeflation(const RhsType &x, DestType &y) const -{ - DenseVector x1 = m_U.leftCols(m_r).transpose() * x; - y = x + m_U.leftCols(m_r) * ( m_lambdaN * m_luT.solve(x1) - x1); - return 0; -} - -} // end namespace Eigen -#endif diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/GMRES.h b/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/GMRES.h deleted file mode 100644 index ff912094..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/GMRES.h +++ /dev/null @@ -1,335 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2012, 2014 Kolja Brix <brix@igpm.rwth-aaachen.de> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GMRES_H -#define EIGEN_GMRES_H - -namespace Eigen { - -namespace internal { - -/** -* Generalized Minimal Residual Algorithm based on the -* Arnoldi algorithm implemented with Householder reflections. -* -* Parameters: -* \param mat matrix of linear system of equations -* \param rhs right hand side vector of linear system of equations -* \param x on input: initial guess, on output: solution -* \param precond preconditioner used -* \param iters on input: maximum number of iterations to perform -* on output: number of iterations performed -* \param restart number of iterations for a restart -* \param tol_error on input: relative residual tolerance -* on output: residuum achieved -* -* \sa IterativeMethods::bicgstab() -* -* -* For references, please see: -* -* Saad, Y. and Schultz, M. H. -* GMRES: A Generalized Minimal Residual Algorithm for Solving Nonsymmetric Linear Systems. -* SIAM J.Sci.Stat.Comp. 7, 1986, pp. 856 - 869. -* -* Saad, Y. -* Iterative Methods for Sparse Linear Systems. -* Society for Industrial and Applied Mathematics, Philadelphia, 2003. -* -* Walker, H. F. -* Implementations of the GMRES method. -* Comput.Phys.Comm. 53, 1989, pp. 311 - 320. -* -* Walker, H. F. -* Implementation of the GMRES Method using Householder Transformations. -* SIAM J.Sci.Stat.Comp. 9, 1988, pp. 152 - 163. -* -*/ -template<typename MatrixType, typename Rhs, typename Dest, typename Preconditioner> -bool gmres(const MatrixType & mat, const Rhs & rhs, Dest & x, const Preconditioner & precond, - Index &iters, const Index &restart, typename Dest::RealScalar & tol_error) { - - using std::sqrt; - using std::abs; - - typedef typename Dest::RealScalar RealScalar; - typedef typename Dest::Scalar Scalar; - typedef Matrix < Scalar, Dynamic, 1 > VectorType; - typedef Matrix < Scalar, Dynamic, Dynamic, ColMajor> FMatrixType; - - const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)(); - - if(rhs.norm() <= considerAsZero) - { - x.setZero(); - tol_error = 0; - return true; - } - - RealScalar tol = tol_error; - const Index maxIters = iters; - iters = 0; - - const Index m = mat.rows(); - - // residual and preconditioned residual - VectorType p0 = rhs - mat*x; - VectorType r0 = precond.solve(p0); - - const RealScalar r0Norm = r0.norm(); - - // is initial guess already good enough? - if(r0Norm == 0) - { - tol_error = 0; - return true; - } - - // storage for Hessenberg matrix and Householder data - FMatrixType H = FMatrixType::Zero(m, restart + 1); - VectorType w = VectorType::Zero(restart + 1); - VectorType tau = VectorType::Zero(restart + 1); - - // storage for Jacobi rotations - std::vector < JacobiRotation < Scalar > > G(restart); - - // storage for temporaries - VectorType t(m), v(m), workspace(m), x_new(m); - - // generate first Householder vector - Ref<VectorType> H0_tail = H.col(0).tail(m - 1); - RealScalar beta; - r0.makeHouseholder(H0_tail, tau.coeffRef(0), beta); - w(0) = Scalar(beta); - - for (Index k = 1; k <= restart; ++k) - { - ++iters; - - v = VectorType::Unit(m, k - 1); - - // apply Householder reflections H_{1} ... H_{k-1} to v - // TODO: use a HouseholderSequence - for (Index i = k - 1; i >= 0; --i) { - v.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data()); - } - - // apply matrix M to v: v = mat * v; - t.noalias() = mat * v; - v = precond.solve(t); - - // apply Householder reflections H_{k-1} ... H_{1} to v - // TODO: use a HouseholderSequence - for (Index i = 0; i < k; ++i) { - v.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data()); - } - - if (v.tail(m - k).norm() != 0.0) - { - if (k <= restart) - { - // generate new Householder vector - Ref<VectorType> Hk_tail = H.col(k).tail(m - k - 1); - v.tail(m - k).makeHouseholder(Hk_tail, tau.coeffRef(k), beta); - - // apply Householder reflection H_{k} to v - v.tail(m - k).applyHouseholderOnTheLeft(Hk_tail, tau.coeffRef(k), workspace.data()); - } - } - - if (k > 1) - { - for (Index i = 0; i < k - 1; ++i) - { - // apply old Givens rotations to v - v.applyOnTheLeft(i, i + 1, G[i].adjoint()); - } - } - - if (k<m && v(k) != (Scalar) 0) - { - // determine next Givens rotation - G[k - 1].makeGivens(v(k - 1), v(k)); - - // apply Givens rotation to v and w - v.applyOnTheLeft(k - 1, k, G[k - 1].adjoint()); - w.applyOnTheLeft(k - 1, k, G[k - 1].adjoint()); - } - - // insert coefficients into upper matrix triangle - H.col(k-1).head(k) = v.head(k); - - tol_error = abs(w(k)) / r0Norm; - bool stop = (k==m || tol_error < tol || iters == maxIters); - - if (stop || k == restart) - { - // solve upper triangular system - Ref<VectorType> y = w.head(k); - H.topLeftCorner(k, k).template triangularView <Upper>().solveInPlace(y); - - // use Horner-like scheme to calculate solution vector - x_new.setZero(); - for (Index i = k - 1; i >= 0; --i) - { - x_new(i) += y(i); - // apply Householder reflection H_{i} to x_new - x_new.tail(m - i).applyHouseholderOnTheLeft(H.col(i).tail(m - i - 1), tau.coeffRef(i), workspace.data()); - } - - x += x_new; - - if(stop) - { - return true; - } - else - { - k=0; - - // reset data for restart - p0.noalias() = rhs - mat*x; - r0 = precond.solve(p0); - - // clear Hessenberg matrix and Householder data - H.setZero(); - w.setZero(); - tau.setZero(); - - // generate first Householder vector - r0.makeHouseholder(H0_tail, tau.coeffRef(0), beta); - w(0) = Scalar(beta); - } - } - } - - return false; - -} - -} - -template< typename _MatrixType, - typename _Preconditioner = DiagonalPreconditioner<typename _MatrixType::Scalar> > -class GMRES; - -namespace internal { - -template< typename _MatrixType, typename _Preconditioner> -struct traits<GMRES<_MatrixType,_Preconditioner> > -{ - typedef _MatrixType MatrixType; - typedef _Preconditioner Preconditioner; -}; - -} - -/** \ingroup IterativeLinearSolvers_Module - * \brief A GMRES solver for sparse square problems - * - * This class allows to solve for A.x = b sparse linear problems using a generalized minimal - * residual method. The vectors x and b can be either dense or sparse. - * - * \tparam _MatrixType the type of the sparse matrix A, can be a dense or a sparse matrix. - * \tparam _Preconditioner the type of the preconditioner. Default is DiagonalPreconditioner - * - * The maximal number of iterations and tolerance value can be controlled via the setMaxIterations() - * and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations - * and NumTraits<Scalar>::epsilon() for the tolerance. - * - * This class can be used as the direct solver classes. Here is a typical usage example: - * \code - * int n = 10000; - * VectorXd x(n), b(n); - * SparseMatrix<double> A(n,n); - * // fill A and b - * GMRES<SparseMatrix<double> > solver(A); - * x = solver.solve(b); - * std::cout << "#iterations: " << solver.iterations() << std::endl; - * std::cout << "estimated error: " << solver.error() << std::endl; - * // update b, and solve again - * x = solver.solve(b); - * \endcode - * - * By default the iterations start with x=0 as an initial guess of the solution. - * One can control the start using the solveWithGuess() method. - * - * GMRES can also be used in a matrix-free context, see the following \link MatrixfreeSolverExample example \endlink. - * - * \sa class SimplicialCholesky, DiagonalPreconditioner, IdentityPreconditioner - */ -template< typename _MatrixType, typename _Preconditioner> -class GMRES : public IterativeSolverBase<GMRES<_MatrixType,_Preconditioner> > -{ - typedef IterativeSolverBase<GMRES> Base; - using Base::matrix; - using Base::m_error; - using Base::m_iterations; - using Base::m_info; - using Base::m_isInitialized; - -private: - Index m_restart; - -public: - using Base::_solve_impl; - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef _Preconditioner Preconditioner; - -public: - - /** Default constructor. */ - GMRES() : Base(), m_restart(30) {} - - /** Initialize the solver with matrix \a A for further \c Ax=b solving. - * - * This constructor is a shortcut for the default constructor followed - * by a call to compute(). - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - explicit GMRES(const EigenBase<MatrixDerived>& A) : Base(A.derived()), m_restart(30) {} - - ~GMRES() {} - - /** Get the number of iterations after that a restart is performed. - */ - Index get_restart() { return m_restart; } - - /** Set the number of iterations after that a restart is performed. - * \param restart number of iterations for a restarti, default is 30. - */ - void set_restart(const Index restart) { m_restart=restart; } - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_vector_with_guess_impl(const Rhs& b, Dest& x) const - { - m_iterations = Base::maxIterations(); - m_error = Base::m_tolerance; - bool ret = internal::gmres(matrix(), b, x, Base::m_preconditioner, m_iterations, m_restart, m_error); - m_info = (!ret) ? NumericalIssue - : m_error <= Base::m_tolerance ? Success - : NoConvergence; - } - -protected: - -}; - -} // end namespace Eigen - -#endif // EIGEN_GMRES_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/IncompleteLU.h b/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/IncompleteLU.h deleted file mode 100644 index 7d08c351..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/IncompleteLU.h +++ /dev/null @@ -1,90 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_INCOMPLETE_LU_H -#define EIGEN_INCOMPLETE_LU_H - -namespace Eigen { - -template <typename _Scalar> -class IncompleteLU : public SparseSolverBase<IncompleteLU<_Scalar> > -{ - protected: - typedef SparseSolverBase<IncompleteLU<_Scalar> > Base; - using Base::m_isInitialized; - - typedef _Scalar Scalar; - typedef Matrix<Scalar,Dynamic,1> Vector; - typedef typename Vector::Index Index; - typedef SparseMatrix<Scalar,RowMajor> FactorType; - - public: - typedef Matrix<Scalar,Dynamic,Dynamic> MatrixType; - - IncompleteLU() {} - - template<typename MatrixType> - IncompleteLU(const MatrixType& mat) - { - compute(mat); - } - - Index rows() const { return m_lu.rows(); } - Index cols() const { return m_lu.cols(); } - - template<typename MatrixType> - IncompleteLU& compute(const MatrixType& mat) - { - m_lu = mat; - int size = mat.cols(); - Vector diag(size); - for(int i=0; i<size; ++i) - { - typename FactorType::InnerIterator k_it(m_lu,i); - for(; k_it && k_it.index()<i; ++k_it) - { - int k = k_it.index(); - k_it.valueRef() /= diag(k); - - typename FactorType::InnerIterator j_it(k_it); - typename FactorType::InnerIterator kj_it(m_lu, k); - while(kj_it && kj_it.index()<=k) ++kj_it; - for(++j_it; j_it; ) - { - if(kj_it.index()==j_it.index()) - { - j_it.valueRef() -= k_it.value() * kj_it.value(); - ++j_it; - ++kj_it; - } - else if(kj_it.index()<j_it.index()) ++kj_it; - else ++j_it; - } - } - if(k_it && k_it.index()==i) diag(i) = k_it.value(); - else diag(i) = 1; - } - m_isInitialized = true; - return *this; - } - - template<typename Rhs, typename Dest> - void _solve_impl(const Rhs& b, Dest& x) const - { - x = m_lu.template triangularView<UnitLower>().solve(b); - x = m_lu.template triangularView<Upper>().solve(x); - } - - protected: - FactorType m_lu; -}; - -} // end namespace Eigen - -#endif // EIGEN_INCOMPLETE_LU_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/IterationController.h b/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/IterationController.h deleted file mode 100644 index c9c1a4be..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/IterationController.h +++ /dev/null @@ -1,154 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> - -/* NOTE The class IterationController has been adapted from the iteration - * class of the GMM++ and ITL libraries. - */ - -//======================================================================= -// Copyright (C) 1997-2001 -// Authors: Andrew Lumsdaine <lums@osl.iu.edu> -// Lie-Quan Lee <llee@osl.iu.edu> -// -// This file is part of the Iterative Template Library -// -// You should have received a copy of the License Agreement for the -// Iterative Template Library along with the software; see the -// file LICENSE. -// -// Permission to modify the code and to distribute modified code is -// granted, provided the text of this NOTICE is retained, a notice that -// the code was modified is included with the above COPYRIGHT NOTICE and -// with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE -// file is distributed with the modified code. -// -// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. -// By way of example, but not limitation, Licensor MAKES NO -// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY -// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS -// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS -// OR OTHER RIGHTS. -//======================================================================= - -//======================================================================== -// -// Copyright (C) 2002-2007 Yves Renard -// -// This file is a part of GETFEM++ -// -// Getfem++ is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; version 2.1 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// You should have received a copy of the GNU Lesser General Public -// License along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, -// USA. -// -//======================================================================== - -#include "../../../../Eigen/src/Core/util/NonMPL2.h" - -#ifndef EIGEN_ITERATION_CONTROLLER_H -#define EIGEN_ITERATION_CONTROLLER_H - -namespace Eigen { - -/** \ingroup IterativeSolvers_Module - * \class IterationController - * - * \brief Controls the iterations of the iterative solvers - * - * This class has been adapted from the iteration class of GMM++ and ITL libraries. - * - */ -class IterationController -{ - protected : - double m_rhsn; ///< Right hand side norm - size_t m_maxiter; ///< Max. number of iterations - int m_noise; ///< if noise > 0 iterations are printed - double m_resmax; ///< maximum residual - double m_resminreach, m_resadd; - size_t m_nit; ///< iteration number - double m_res; ///< last computed residual - bool m_written; - void (*m_callback)(const IterationController&); - public : - - void init() - { - m_nit = 0; m_res = 0.0; m_written = false; - m_resminreach = 1E50; m_resadd = 0.0; - m_callback = 0; - } - - IterationController(double r = 1.0E-8, int noi = 0, size_t mit = size_t(-1)) - : m_rhsn(1.0), m_maxiter(mit), m_noise(noi), m_resmax(r) { init(); } - - void operator ++(int) { m_nit++; m_written = false; m_resadd += m_res; } - void operator ++() { (*this)++; } - - bool first() { return m_nit == 0; } - - /* get/set the "noisyness" (verbosity) of the solvers */ - int noiseLevel() const { return m_noise; } - void setNoiseLevel(int n) { m_noise = n; } - void reduceNoiseLevel() { if (m_noise > 0) m_noise--; } - - double maxResidual() const { return m_resmax; } - void setMaxResidual(double r) { m_resmax = r; } - - double residual() const { return m_res; } - - /* change the user-definable callback, called after each iteration */ - void setCallback(void (*t)(const IterationController&)) - { - m_callback = t; - } - - size_t iteration() const { return m_nit; } - void setIteration(size_t i) { m_nit = i; } - - size_t maxIterarions() const { return m_maxiter; } - void setMaxIterations(size_t i) { m_maxiter = i; } - - double rhsNorm() const { return m_rhsn; } - void setRhsNorm(double r) { m_rhsn = r; } - - bool converged() const { return m_res <= m_rhsn * m_resmax; } - bool converged(double nr) - { - using std::abs; - m_res = abs(nr); - m_resminreach = (std::min)(m_resminreach, m_res); - return converged(); - } - template<typename VectorType> bool converged(const VectorType &v) - { return converged(v.squaredNorm()); } - - bool finished(double nr) - { - if (m_callback) m_callback(*this); - if (m_noise > 0 && !m_written) - { - converged(nr); - m_written = true; - } - return (m_nit >= m_maxiter || converged(nr)); - } - template <typename VectorType> - bool finished(const MatrixBase<VectorType> &v) - { return finished(double(v.squaredNorm())); } - -}; - -} // end namespace Eigen - -#endif // EIGEN_ITERATION_CONTROLLER_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/MINRES.h b/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/MINRES.h deleted file mode 100644 index 5db454d2..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/MINRES.h +++ /dev/null @@ -1,267 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Giacomo Po <gpo@ucla.edu> -// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2018 David Hyde <dabh@stanford.edu> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_MINRES_H_ -#define EIGEN_MINRES_H_ - - -namespace Eigen { - - namespace internal { - - /** \internal Low-level MINRES algorithm - * \param mat The matrix A - * \param rhs The right hand side vector b - * \param x On input and initial solution, on output the computed solution. - * \param precond A right preconditioner being able to efficiently solve for an - * approximation of Ax=b (regardless of b) - * \param iters On input the max number of iteration, on output the number of performed iterations. - * \param tol_error On input the tolerance error, on output an estimation of the relative error. - */ - template<typename MatrixType, typename Rhs, typename Dest, typename Preconditioner> - EIGEN_DONT_INLINE - void minres(const MatrixType& mat, const Rhs& rhs, Dest& x, - const Preconditioner& precond, Index& iters, - typename Dest::RealScalar& tol_error) - { - using std::sqrt; - typedef typename Dest::RealScalar RealScalar; - typedef typename Dest::Scalar Scalar; - typedef Matrix<Scalar,Dynamic,1> VectorType; - - // Check for zero rhs - const RealScalar rhsNorm2(rhs.squaredNorm()); - if(rhsNorm2 == 0) - { - x.setZero(); - iters = 0; - tol_error = 0; - return; - } - - // initialize - const Index maxIters(iters); // initialize maxIters to iters - const Index N(mat.cols()); // the size of the matrix - const RealScalar threshold2(tol_error*tol_error*rhsNorm2); // convergence threshold (compared to residualNorm2) - - // Initialize preconditioned Lanczos - VectorType v_old(N); // will be initialized inside loop - VectorType v( VectorType::Zero(N) ); //initialize v - VectorType v_new(rhs-mat*x); //initialize v_new - RealScalar residualNorm2(v_new.squaredNorm()); - VectorType w(N); // will be initialized inside loop - VectorType w_new(precond.solve(v_new)); // initialize w_new -// RealScalar beta; // will be initialized inside loop - RealScalar beta_new2(v_new.dot(w_new)); - eigen_assert(beta_new2 >= 0.0 && "PRECONDITIONER IS NOT POSITIVE DEFINITE"); - RealScalar beta_new(sqrt(beta_new2)); - const RealScalar beta_one(beta_new); - // Initialize other variables - RealScalar c(1.0); // the cosine of the Givens rotation - RealScalar c_old(1.0); - RealScalar s(0.0); // the sine of the Givens rotation - RealScalar s_old(0.0); // the sine of the Givens rotation - VectorType p_oold(N); // will be initialized in loop - VectorType p_old(VectorType::Zero(N)); // initialize p_old=0 - VectorType p(p_old); // initialize p=0 - RealScalar eta(1.0); - - iters = 0; // reset iters - while ( iters < maxIters ) - { - // Preconditioned Lanczos - /* Note that there are 4 variants on the Lanczos algorithm. These are - * described in Paige, C. C. (1972). Computational variants of - * the Lanczos method for the eigenproblem. IMA Journal of Applied - * Mathematics, 10(3), 373-381. The current implementation corresponds - * to the case A(2,7) in the paper. It also corresponds to - * algorithm 6.14 in Y. Saad, Iterative Methods for Sparse Linear - * Systems, 2003 p.173. For the preconditioned version see - * A. Greenbaum, Iterative Methods for Solving Linear Systems, SIAM (1987). - */ - const RealScalar beta(beta_new); - v_old = v; // update: at first time step, this makes v_old = 0 so value of beta doesn't matter - v_new /= beta_new; // overwrite v_new for next iteration - w_new /= beta_new; // overwrite w_new for next iteration - v = v_new; // update - w = w_new; // update - v_new.noalias() = mat*w - beta*v_old; // compute v_new - const RealScalar alpha = v_new.dot(w); - v_new -= alpha*v; // overwrite v_new - w_new = precond.solve(v_new); // overwrite w_new - beta_new2 = v_new.dot(w_new); // compute beta_new - eigen_assert(beta_new2 >= 0.0 && "PRECONDITIONER IS NOT POSITIVE DEFINITE"); - beta_new = sqrt(beta_new2); // compute beta_new - - // Givens rotation - const RealScalar r2 =s*alpha+c*c_old*beta; // s, s_old, c and c_old are still from previous iteration - const RealScalar r3 =s_old*beta; // s, s_old, c and c_old are still from previous iteration - const RealScalar r1_hat=c*alpha-c_old*s*beta; - const RealScalar r1 =sqrt( std::pow(r1_hat,2) + std::pow(beta_new,2) ); - c_old = c; // store for next iteration - s_old = s; // store for next iteration - c=r1_hat/r1; // new cosine - s=beta_new/r1; // new sine - - // Update solution - p_oold = p_old; - p_old = p; - p.noalias()=(w-r2*p_old-r3*p_oold) /r1; // IS NOALIAS REQUIRED? - x += beta_one*c*eta*p; - - /* Update the squared residual. Note that this is the estimated residual. - The real residual |Ax-b|^2 may be slightly larger */ - residualNorm2 *= s*s; - - if ( residualNorm2 < threshold2) - { - break; - } - - eta=-s*eta; // update eta - iters++; // increment iteration number (for output purposes) - } - - /* Compute error. Note that this is the estimated error. The real - error |Ax-b|/|b| may be slightly larger */ - tol_error = std::sqrt(residualNorm2 / rhsNorm2); - } - - } - - template< typename _MatrixType, int _UpLo=Lower, - typename _Preconditioner = IdentityPreconditioner> - class MINRES; - - namespace internal { - - template< typename _MatrixType, int _UpLo, typename _Preconditioner> - struct traits<MINRES<_MatrixType,_UpLo,_Preconditioner> > - { - typedef _MatrixType MatrixType; - typedef _Preconditioner Preconditioner; - }; - - } - - /** \ingroup IterativeLinearSolvers_Module - * \brief A minimal residual solver for sparse symmetric problems - * - * This class allows to solve for A.x = b sparse linear problems using the MINRES algorithm - * of Paige and Saunders (1975). The sparse matrix A must be symmetric (possibly indefinite). - * The vectors x and b can be either dense or sparse. - * - * \tparam _MatrixType the type of the sparse matrix A, can be a dense or a sparse matrix. - * \tparam _UpLo the triangular part that will be used for the computations. It can be Lower, - * Upper, or Lower|Upper in which the full matrix entries will be considered. Default is Lower. - * \tparam _Preconditioner the type of the preconditioner. Default is DiagonalPreconditioner - * - * The maximal number of iterations and tolerance value can be controlled via the setMaxIterations() - * and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations - * and NumTraits<Scalar>::epsilon() for the tolerance. - * - * This class can be used as the direct solver classes. Here is a typical usage example: - * \code - * int n = 10000; - * VectorXd x(n), b(n); - * SparseMatrix<double> A(n,n); - * // fill A and b - * MINRES<SparseMatrix<double> > mr; - * mr.compute(A); - * x = mr.solve(b); - * std::cout << "#iterations: " << mr.iterations() << std::endl; - * std::cout << "estimated error: " << mr.error() << std::endl; - * // update b, and solve again - * x = mr.solve(b); - * \endcode - * - * By default the iterations start with x=0 as an initial guess of the solution. - * One can control the start using the solveWithGuess() method. - * - * MINRES can also be used in a matrix-free context, see the following \link MatrixfreeSolverExample example \endlink. - * - * \sa class ConjugateGradient, BiCGSTAB, SimplicialCholesky, DiagonalPreconditioner, IdentityPreconditioner - */ - template< typename _MatrixType, int _UpLo, typename _Preconditioner> - class MINRES : public IterativeSolverBase<MINRES<_MatrixType,_UpLo,_Preconditioner> > - { - - typedef IterativeSolverBase<MINRES> Base; - using Base::matrix; - using Base::m_error; - using Base::m_iterations; - using Base::m_info; - using Base::m_isInitialized; - public: - using Base::_solve_impl; - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef _Preconditioner Preconditioner; - - enum {UpLo = _UpLo}; - - public: - - /** Default constructor. */ - MINRES() : Base() {} - - /** Initialize the solver with matrix \a A for further \c Ax=b solving. - * - * This constructor is a shortcut for the default constructor followed - * by a call to compute(). - * - * \warning this class stores a reference to the matrix A as well as some - * precomputed values that depend on it. Therefore, if \a A is changed - * this class becomes invalid. Call compute() to update it with the new - * matrix A, or modify a copy of A. - */ - template<typename MatrixDerived> - explicit MINRES(const EigenBase<MatrixDerived>& A) : Base(A.derived()) {} - - /** Destructor. */ - ~MINRES(){} - - /** \internal */ - template<typename Rhs,typename Dest> - void _solve_vector_with_guess_impl(const Rhs& b, Dest& x) const - { - typedef typename Base::MatrixWrapper MatrixWrapper; - typedef typename Base::ActualMatrixType ActualMatrixType; - enum { - TransposeInput = (!MatrixWrapper::MatrixFree) - && (UpLo==(Lower|Upper)) - && (!MatrixType::IsRowMajor) - && (!NumTraits<Scalar>::IsComplex) - }; - typedef typename internal::conditional<TransposeInput,Transpose<const ActualMatrixType>, ActualMatrixType const&>::type RowMajorWrapper; - EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(MatrixWrapper::MatrixFree,UpLo==(Lower|Upper)),MATRIX_FREE_CONJUGATE_GRADIENT_IS_COMPATIBLE_WITH_UPPER_UNION_LOWER_MODE_ONLY); - typedef typename internal::conditional<UpLo==(Lower|Upper), - RowMajorWrapper, - typename MatrixWrapper::template ConstSelfAdjointViewReturnType<UpLo>::Type - >::type SelfAdjointWrapper; - - m_iterations = Base::maxIterations(); - m_error = Base::m_tolerance; - RowMajorWrapper row_mat(matrix()); - internal::minres(SelfAdjointWrapper(row_mat), b, x, - Base::m_preconditioner, m_iterations, m_error); - m_info = m_error <= Base::m_tolerance ? Success : NoConvergence; - } - - protected: - - }; - -} // end namespace Eigen - -#endif // EIGEN_MINRES_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/Scaling.h b/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/Scaling.h deleted file mode 100644 index 9b3eb53e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/IterativeSolvers/Scaling.h +++ /dev/null @@ -1,193 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Desire NUENTSA WAKAM <desire.nuentsa_wakam@inria.fr -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_ITERSCALING_H -#define EIGEN_ITERSCALING_H - -namespace Eigen { - -/** - * \ingroup IterativeSolvers_Module - * \brief iterative scaling algorithm to equilibrate rows and column norms in matrices - * - * This class can be used as a preprocessing tool to accelerate the convergence of iterative methods - * - * This feature is useful to limit the pivoting amount during LU/ILU factorization - * The scaling strategy as presented here preserves the symmetry of the problem - * NOTE It is assumed that the matrix does not have empty row or column, - * - * Example with key steps - * \code - * VectorXd x(n), b(n); - * SparseMatrix<double> A; - * // fill A and b; - * IterScaling<SparseMatrix<double> > scal; - * // Compute the left and right scaling vectors. The matrix is equilibrated at output - * scal.computeRef(A); - * // Scale the right hand side - * b = scal.LeftScaling().cwiseProduct(b); - * // Now, solve the equilibrated linear system with any available solver - * - * // Scale back the computed solution - * x = scal.RightScaling().cwiseProduct(x); - * \endcode - * - * \tparam _MatrixType the type of the matrix. It should be a real square sparsematrix - * - * References : D. Ruiz and B. Ucar, A Symmetry Preserving Algorithm for Matrix Scaling, INRIA Research report RR-7552 - * - * \sa \ref IncompleteLUT - */ -template<typename _MatrixType> -class IterScaling -{ - public: - typedef _MatrixType MatrixType; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::Index Index; - - public: - IterScaling() { init(); } - - IterScaling(const MatrixType& matrix) - { - init(); - compute(matrix); - } - - ~IterScaling() { } - - /** - * Compute the left and right diagonal matrices to scale the input matrix @p mat - * - * FIXME This algorithm will be modified such that the diagonal elements are permuted on the diagonal. - * - * \sa LeftScaling() RightScaling() - */ - void compute (const MatrixType& mat) - { - using std::abs; - int m = mat.rows(); - int n = mat.cols(); - eigen_assert((m>0 && m == n) && "Please give a non - empty matrix"); - m_left.resize(m); - m_right.resize(n); - m_left.setOnes(); - m_right.setOnes(); - m_matrix = mat; - VectorXd Dr, Dc, DrRes, DcRes; // Temporary Left and right scaling vectors - Dr.resize(m); Dc.resize(n); - DrRes.resize(m); DcRes.resize(n); - double EpsRow = 1.0, EpsCol = 1.0; - int its = 0; - do - { // Iterate until the infinite norm of each row and column is approximately 1 - // Get the maximum value in each row and column - Dr.setZero(); Dc.setZero(); - for (int k=0; k<m_matrix.outerSize(); ++k) - { - for (typename MatrixType::InnerIterator it(m_matrix, k); it; ++it) - { - if ( Dr(it.row()) < abs(it.value()) ) - Dr(it.row()) = abs(it.value()); - - if ( Dc(it.col()) < abs(it.value()) ) - Dc(it.col()) = abs(it.value()); - } - } - for (int i = 0; i < m; ++i) - { - Dr(i) = std::sqrt(Dr(i)); - } - for (int i = 0; i < n; ++i) - { - Dc(i) = std::sqrt(Dc(i)); - } - // Save the scaling factors - for (int i = 0; i < m; ++i) - { - m_left(i) /= Dr(i); - } - for (int i = 0; i < n; ++i) - { - m_right(i) /= Dc(i); - } - // Scale the rows and the columns of the matrix - DrRes.setZero(); DcRes.setZero(); - for (int k=0; k<m_matrix.outerSize(); ++k) - { - for (typename MatrixType::InnerIterator it(m_matrix, k); it; ++it) - { - it.valueRef() = it.value()/( Dr(it.row()) * Dc(it.col()) ); - // Accumulate the norms of the row and column vectors - if ( DrRes(it.row()) < abs(it.value()) ) - DrRes(it.row()) = abs(it.value()); - - if ( DcRes(it.col()) < abs(it.value()) ) - DcRes(it.col()) = abs(it.value()); - } - } - DrRes.array() = (1-DrRes.array()).abs(); - EpsRow = DrRes.maxCoeff(); - DcRes.array() = (1-DcRes.array()).abs(); - EpsCol = DcRes.maxCoeff(); - its++; - }while ( (EpsRow >m_tol || EpsCol > m_tol) && (its < m_maxits) ); - m_isInitialized = true; - } - /** Compute the left and right vectors to scale the vectors - * the input matrix is scaled with the computed vectors at output - * - * \sa compute() - */ - void computeRef (MatrixType& mat) - { - compute (mat); - mat = m_matrix; - } - /** Get the vector to scale the rows of the matrix - */ - VectorXd& LeftScaling() - { - return m_left; - } - - /** Get the vector to scale the columns of the matrix - */ - VectorXd& RightScaling() - { - return m_right; - } - - /** Set the tolerance for the convergence of the iterative scaling algorithm - */ - void setTolerance(double tol) - { - m_tol = tol; - } - - protected: - - void init() - { - m_tol = 1e-10; - m_maxits = 5; - m_isInitialized = false; - } - - MatrixType m_matrix; - mutable ComputationInfo m_info; - bool m_isInitialized; - VectorXd m_left; // Left scaling vector - VectorXd m_right; // m_right scaling vector - double m_tol; - int m_maxits; // Maximum number of iterations allowed -}; -} -#endif diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h b/external/eigen/include/eigen3/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h deleted file mode 100644 index 582fa851..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h +++ /dev/null @@ -1,305 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011 Kolja Brix <brix@igpm.rwth-aachen.de> -// Copyright (C) 2011 Andreas Platen <andiplaten@gmx.de> -// Copyright (C) 2012 Chen-Pang He <jdh8@ms63.hinet.net> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef KRONECKER_TENSOR_PRODUCT_H -#define KRONECKER_TENSOR_PRODUCT_H - -namespace Eigen { - -/*! - * \ingroup KroneckerProduct_Module - * - * \brief The base class of dense and sparse Kronecker product. - * - * \tparam Derived is the derived type. - */ -template<typename Derived> -class KroneckerProductBase : public ReturnByValue<Derived> -{ - private: - typedef typename internal::traits<Derived> Traits; - typedef typename Traits::Scalar Scalar; - - protected: - typedef typename Traits::Lhs Lhs; - typedef typename Traits::Rhs Rhs; - - public: - /*! \brief Constructor. */ - KroneckerProductBase(const Lhs& A, const Rhs& B) - : m_A(A), m_B(B) - {} - - inline Index rows() const { return m_A.rows() * m_B.rows(); } - inline Index cols() const { return m_A.cols() * m_B.cols(); } - - /*! - * This overrides ReturnByValue::coeff because this function is - * efficient enough. - */ - Scalar coeff(Index row, Index col) const - { - return m_A.coeff(row / m_B.rows(), col / m_B.cols()) * - m_B.coeff(row % m_B.rows(), col % m_B.cols()); - } - - /*! - * This overrides ReturnByValue::coeff because this function is - * efficient enough. - */ - Scalar coeff(Index i) const - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); - return m_A.coeff(i / m_A.size()) * m_B.coeff(i % m_A.size()); - } - - protected: - typename Lhs::Nested m_A; - typename Rhs::Nested m_B; -}; - -/*! - * \ingroup KroneckerProduct_Module - * - * \brief Kronecker tensor product helper class for dense matrices - * - * This class is the return value of kroneckerProduct(MatrixBase, - * MatrixBase). Use the function rather than construct this class - * directly to avoid specifying template prarameters. - * - * \tparam Lhs Type of the left-hand side, a matrix expression. - * \tparam Rhs Type of the rignt-hand side, a matrix expression. - */ -template<typename Lhs, typename Rhs> -class KroneckerProduct : public KroneckerProductBase<KroneckerProduct<Lhs,Rhs> > -{ - private: - typedef KroneckerProductBase<KroneckerProduct> Base; - using Base::m_A; - using Base::m_B; - - public: - /*! \brief Constructor. */ - KroneckerProduct(const Lhs& A, const Rhs& B) - : Base(A, B) - {} - - /*! \brief Evaluate the Kronecker tensor product. */ - template<typename Dest> void evalTo(Dest& dst) const; -}; - -/*! - * \ingroup KroneckerProduct_Module - * - * \brief Kronecker tensor product helper class for sparse matrices - * - * If at least one of the operands is a sparse matrix expression, - * then this class is returned and evaluates into a sparse matrix. - * - * This class is the return value of kroneckerProduct(EigenBase, - * EigenBase). Use the function rather than construct this class - * directly to avoid specifying template prarameters. - * - * \tparam Lhs Type of the left-hand side, a matrix expression. - * \tparam Rhs Type of the rignt-hand side, a matrix expression. - */ -template<typename Lhs, typename Rhs> -class KroneckerProductSparse : public KroneckerProductBase<KroneckerProductSparse<Lhs,Rhs> > -{ - private: - typedef KroneckerProductBase<KroneckerProductSparse> Base; - using Base::m_A; - using Base::m_B; - - public: - /*! \brief Constructor. */ - KroneckerProductSparse(const Lhs& A, const Rhs& B) - : Base(A, B) - {} - - /*! \brief Evaluate the Kronecker tensor product. */ - template<typename Dest> void evalTo(Dest& dst) const; -}; - -template<typename Lhs, typename Rhs> -template<typename Dest> -void KroneckerProduct<Lhs,Rhs>::evalTo(Dest& dst) const -{ - const int BlockRows = Rhs::RowsAtCompileTime, - BlockCols = Rhs::ColsAtCompileTime; - const Index Br = m_B.rows(), - Bc = m_B.cols(); - for (Index i=0; i < m_A.rows(); ++i) - for (Index j=0; j < m_A.cols(); ++j) - Block<Dest,BlockRows,BlockCols>(dst,i*Br,j*Bc,Br,Bc) = m_A.coeff(i,j) * m_B; -} - -template<typename Lhs, typename Rhs> -template<typename Dest> -void KroneckerProductSparse<Lhs,Rhs>::evalTo(Dest& dst) const -{ - Index Br = m_B.rows(), Bc = m_B.cols(); - dst.resize(this->rows(), this->cols()); - dst.resizeNonZeros(0); - - // 1 - evaluate the operands if needed: - typedef typename internal::nested_eval<Lhs,Dynamic>::type Lhs1; - typedef typename internal::remove_all<Lhs1>::type Lhs1Cleaned; - const Lhs1 lhs1(m_A); - typedef typename internal::nested_eval<Rhs,Dynamic>::type Rhs1; - typedef typename internal::remove_all<Rhs1>::type Rhs1Cleaned; - const Rhs1 rhs1(m_B); - - // 2 - construct respective iterators - typedef Eigen::InnerIterator<Lhs1Cleaned> LhsInnerIterator; - typedef Eigen::InnerIterator<Rhs1Cleaned> RhsInnerIterator; - - // compute number of non-zeros per innervectors of dst - { - // TODO VectorXi is not necessarily big enough! - VectorXi nnzA = VectorXi::Zero(Dest::IsRowMajor ? m_A.rows() : m_A.cols()); - for (Index kA=0; kA < m_A.outerSize(); ++kA) - for (LhsInnerIterator itA(lhs1,kA); itA; ++itA) - nnzA(Dest::IsRowMajor ? itA.row() : itA.col())++; - - VectorXi nnzB = VectorXi::Zero(Dest::IsRowMajor ? m_B.rows() : m_B.cols()); - for (Index kB=0; kB < m_B.outerSize(); ++kB) - for (RhsInnerIterator itB(rhs1,kB); itB; ++itB) - nnzB(Dest::IsRowMajor ? itB.row() : itB.col())++; - - Matrix<int,Dynamic,Dynamic,ColMajor> nnzAB = nnzB * nnzA.transpose(); - dst.reserve(VectorXi::Map(nnzAB.data(), nnzAB.size())); - } - - for (Index kA=0; kA < m_A.outerSize(); ++kA) - { - for (Index kB=0; kB < m_B.outerSize(); ++kB) - { - for (LhsInnerIterator itA(lhs1,kA); itA; ++itA) - { - for (RhsInnerIterator itB(rhs1,kB); itB; ++itB) - { - Index i = itA.row() * Br + itB.row(), - j = itA.col() * Bc + itB.col(); - dst.insert(i,j) = itA.value() * itB.value(); - } - } - } - } -} - -namespace internal { - -template<typename _Lhs, typename _Rhs> -struct traits<KroneckerProduct<_Lhs,_Rhs> > -{ - typedef typename remove_all<_Lhs>::type Lhs; - typedef typename remove_all<_Rhs>::type Rhs; - typedef typename ScalarBinaryOpTraits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar; - typedef typename promote_index_type<typename Lhs::StorageIndex, typename Rhs::StorageIndex>::type StorageIndex; - - enum { - Rows = size_at_compile_time<traits<Lhs>::RowsAtCompileTime, traits<Rhs>::RowsAtCompileTime>::ret, - Cols = size_at_compile_time<traits<Lhs>::ColsAtCompileTime, traits<Rhs>::ColsAtCompileTime>::ret, - MaxRows = size_at_compile_time<traits<Lhs>::MaxRowsAtCompileTime, traits<Rhs>::MaxRowsAtCompileTime>::ret, - MaxCols = size_at_compile_time<traits<Lhs>::MaxColsAtCompileTime, traits<Rhs>::MaxColsAtCompileTime>::ret - }; - - typedef Matrix<Scalar,Rows,Cols> ReturnType; -}; - -template<typename _Lhs, typename _Rhs> -struct traits<KroneckerProductSparse<_Lhs,_Rhs> > -{ - typedef MatrixXpr XprKind; - typedef typename remove_all<_Lhs>::type Lhs; - typedef typename remove_all<_Rhs>::type Rhs; - typedef typename ScalarBinaryOpTraits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar; - typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind, typename traits<Rhs>::StorageKind, scalar_product_op<typename Lhs::Scalar, typename Rhs::Scalar> >::ret StorageKind; - typedef typename promote_index_type<typename Lhs::StorageIndex, typename Rhs::StorageIndex>::type StorageIndex; - - enum { - LhsFlags = Lhs::Flags, - RhsFlags = Rhs::Flags, - - RowsAtCompileTime = size_at_compile_time<traits<Lhs>::RowsAtCompileTime, traits<Rhs>::RowsAtCompileTime>::ret, - ColsAtCompileTime = size_at_compile_time<traits<Lhs>::ColsAtCompileTime, traits<Rhs>::ColsAtCompileTime>::ret, - MaxRowsAtCompileTime = size_at_compile_time<traits<Lhs>::MaxRowsAtCompileTime, traits<Rhs>::MaxRowsAtCompileTime>::ret, - MaxColsAtCompileTime = size_at_compile_time<traits<Lhs>::MaxColsAtCompileTime, traits<Rhs>::MaxColsAtCompileTime>::ret, - - EvalToRowMajor = (LhsFlags & RhsFlags & RowMajorBit), - RemovedBits = ~(EvalToRowMajor ? 0 : RowMajorBit), - - Flags = ((LhsFlags | RhsFlags) & HereditaryBits & RemovedBits) - | EvalBeforeNestingBit, - CoeffReadCost = HugeCost - }; - - typedef SparseMatrix<Scalar, 0, StorageIndex> ReturnType; -}; - -} // end namespace internal - -/*! - * \ingroup KroneckerProduct_Module - * - * Computes Kronecker tensor product of two dense matrices - * - * \warning If you want to replace a matrix by its Kronecker product - * with some matrix, do \b NOT do this: - * \code - * A = kroneckerProduct(A,B); // bug!!! caused by aliasing effect - * \endcode - * instead, use eval() to work around this: - * \code - * A = kroneckerProduct(A,B).eval(); - * \endcode - * - * \param a Dense matrix a - * \param b Dense matrix b - * \return Kronecker tensor product of a and b - */ -template<typename A, typename B> -KroneckerProduct<A,B> kroneckerProduct(const MatrixBase<A>& a, const MatrixBase<B>& b) -{ - return KroneckerProduct<A, B>(a.derived(), b.derived()); -} - -/*! - * \ingroup KroneckerProduct_Module - * - * Computes Kronecker tensor product of two matrices, at least one of - * which is sparse - * - * \warning If you want to replace a matrix by its Kronecker product - * with some matrix, do \b NOT do this: - * \code - * A = kroneckerProduct(A,B); // bug!!! caused by aliasing effect - * \endcode - * instead, use eval() to work around this: - * \code - * A = kroneckerProduct(A,B).eval(); - * \endcode - * - * \param a Dense/sparse matrix a - * \param b Dense/sparse matrix b - * \return Kronecker tensor product of a and b, stored in a sparse - * matrix - */ -template<typename A, typename B> -KroneckerProductSparse<A,B> kroneckerProduct(const EigenBase<A>& a, const EigenBase<B>& b) -{ - return KroneckerProductSparse<A,B>(a.derived(), b.derived()); -} - -} // end namespace Eigen - -#endif // KRONECKER_TENSOR_PRODUCT_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMcovar.h b/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMcovar.h deleted file mode 100644 index b75bea25..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMcovar.h +++ /dev/null @@ -1,84 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This code initially comes from MINPACK whose original authors are: -// Copyright Jorge More - Argonne National Laboratory -// Copyright Burt Garbow - Argonne National Laboratory -// Copyright Ken Hillstrom - Argonne National Laboratory -// -// This Source Code Form is subject to the terms of the Minpack license -// (a BSD-like license) described in the campaigned CopyrightMINPACK.txt file. - -#ifndef EIGEN_LMCOVAR_H -#define EIGEN_LMCOVAR_H - -namespace Eigen { - -namespace internal { - -template <typename Scalar> -void covar( - Matrix< Scalar, Dynamic, Dynamic > &r, - const VectorXi& ipvt, - Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) ) -{ - using std::abs; - /* Local variables */ - Index i, j, k, l, ii, jj; - bool sing; - Scalar temp; - - /* Function Body */ - const Index n = r.cols(); - const Scalar tolr = tol * abs(r(0,0)); - Matrix< Scalar, Dynamic, 1 > wa(n); - eigen_assert(ipvt.size()==n); - - /* form the inverse of r in the full upper triangle of r. */ - l = -1; - for (k = 0; k < n; ++k) - if (abs(r(k,k)) > tolr) { - r(k,k) = 1. / r(k,k); - for (j = 0; j <= k-1; ++j) { - temp = r(k,k) * r(j,k); - r(j,k) = 0.; - r.col(k).head(j+1) -= r.col(j).head(j+1) * temp; - } - l = k; - } - - /* form the full upper triangle of the inverse of (r transpose)*r */ - /* in the full upper triangle of r. */ - for (k = 0; k <= l; ++k) { - for (j = 0; j <= k-1; ++j) - r.col(j).head(j+1) += r.col(k).head(j+1) * r(j,k); - r.col(k).head(k+1) *= r(k,k); - } - - /* form the full lower triangle of the covariance matrix */ - /* in the strict lower triangle of r and in wa. */ - for (j = 0; j < n; ++j) { - jj = ipvt[j]; - sing = j > l; - for (i = 0; i <= j; ++i) { - if (sing) - r(i,j) = 0.; - ii = ipvt[i]; - if (ii > jj) - r(ii,jj) = r(i,j); - if (ii < jj) - r(jj,ii) = r(i,j); - } - wa[jj] = r(j,j); - } - - /* symmetrize the covariance matrix in r. */ - r.topLeftCorner(n,n).template triangularView<StrictlyUpper>() = r.topLeftCorner(n,n).transpose(); - r.diagonal() = wa; -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_LMCOVAR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMonestep.h b/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMonestep.h deleted file mode 100644 index 25b32ec5..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMonestep.h +++ /dev/null @@ -1,202 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// -// This code initially comes from MINPACK whose original authors are: -// Copyright Jorge More - Argonne National Laboratory -// Copyright Burt Garbow - Argonne National Laboratory -// Copyright Ken Hillstrom - Argonne National Laboratory -// -// This Source Code Form is subject to the terms of the Minpack license -// (a BSD-like license) described in the campaigned CopyrightMINPACK.txt file. - -#ifndef EIGEN_LMONESTEP_H -#define EIGEN_LMONESTEP_H - -namespace Eigen { - -template<typename FunctorType> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType>::minimizeOneStep(FVectorType &x) -{ - using std::abs; - using std::sqrt; - RealScalar temp, temp1,temp2; - RealScalar ratio; - RealScalar pnorm, xnorm, fnorm1, actred, dirder, prered; - eigen_assert(x.size()==n); // check the caller is not cheating us - - temp = 0.0; xnorm = 0.0; - /* calculate the jacobian matrix. */ - Index df_ret = m_functor.df(x, m_fjac); - if (df_ret<0) - return LevenbergMarquardtSpace::UserAsked; - if (df_ret>0) - // numerical diff, we evaluated the function df_ret times - m_nfev += df_ret; - else m_njev++; - - /* compute the qr factorization of the jacobian. */ - for (int j = 0; j < x.size(); ++j) - m_wa2(j) = m_fjac.col(j).blueNorm(); - QRSolver qrfac(m_fjac); - if(qrfac.info() != Success) { - m_info = NumericalIssue; - return LevenbergMarquardtSpace::ImproperInputParameters; - } - // Make a copy of the first factor with the associated permutation - m_rfactor = qrfac.matrixR(); - m_permutation = (qrfac.colsPermutation()); - - /* on the first iteration and if external scaling is not used, scale according */ - /* to the norms of the columns of the initial jacobian. */ - if (m_iter == 1) { - if (!m_useExternalScaling) - for (Index j = 0; j < n; ++j) - m_diag[j] = (m_wa2[j]==0.)? 1. : m_wa2[j]; - - /* on the first iteration, calculate the norm of the scaled x */ - /* and initialize the step bound m_delta. */ - xnorm = m_diag.cwiseProduct(x).stableNorm(); - m_delta = m_factor * xnorm; - if (m_delta == 0.) - m_delta = m_factor; - } - - /* form (q transpose)*m_fvec and store the first n components in */ - /* m_qtf. */ - m_wa4 = m_fvec; - m_wa4 = qrfac.matrixQ().adjoint() * m_fvec; - m_qtf = m_wa4.head(n); - - /* compute the norm of the scaled gradient. */ - m_gnorm = 0.; - if (m_fnorm != 0.) - for (Index j = 0; j < n; ++j) - if (m_wa2[m_permutation.indices()[j]] != 0.) - m_gnorm = (std::max)(m_gnorm, abs( m_rfactor.col(j).head(j+1).dot(m_qtf.head(j+1)/m_fnorm) / m_wa2[m_permutation.indices()[j]])); - - /* test for convergence of the gradient norm. */ - if (m_gnorm <= m_gtol) { - m_info = Success; - return LevenbergMarquardtSpace::CosinusTooSmall; - } - - /* rescale if necessary. */ - if (!m_useExternalScaling) - m_diag = m_diag.cwiseMax(m_wa2); - - do { - /* determine the levenberg-marquardt parameter. */ - internal::lmpar2(qrfac, m_diag, m_qtf, m_delta, m_par, m_wa1); - - /* store the direction p and x + p. calculate the norm of p. */ - m_wa1 = -m_wa1; - m_wa2 = x + m_wa1; - pnorm = m_diag.cwiseProduct(m_wa1).stableNorm(); - - /* on the first iteration, adjust the initial step bound. */ - if (m_iter == 1) - m_delta = (std::min)(m_delta,pnorm); - - /* evaluate the function at x + p and calculate its norm. */ - if ( m_functor(m_wa2, m_wa4) < 0) - return LevenbergMarquardtSpace::UserAsked; - ++m_nfev; - fnorm1 = m_wa4.stableNorm(); - - /* compute the scaled actual reduction. */ - actred = -1.; - if (Scalar(.1) * fnorm1 < m_fnorm) - actred = 1. - numext::abs2(fnorm1 / m_fnorm); - - /* compute the scaled predicted reduction and */ - /* the scaled directional derivative. */ - m_wa3 = m_rfactor.template triangularView<Upper>() * (m_permutation.inverse() *m_wa1); - temp1 = numext::abs2(m_wa3.stableNorm() / m_fnorm); - temp2 = numext::abs2(sqrt(m_par) * pnorm / m_fnorm); - prered = temp1 + temp2 / Scalar(.5); - dirder = -(temp1 + temp2); - - /* compute the ratio of the actual to the predicted */ - /* reduction. */ - ratio = 0.; - if (prered != 0.) - ratio = actred / prered; - - /* update the step bound. */ - if (ratio <= Scalar(.25)) { - if (actred >= 0.) - temp = RealScalar(.5); - if (actred < 0.) - temp = RealScalar(.5) * dirder / (dirder + RealScalar(.5) * actred); - if (RealScalar(.1) * fnorm1 >= m_fnorm || temp < RealScalar(.1)) - temp = Scalar(.1); - /* Computing MIN */ - m_delta = temp * (std::min)(m_delta, pnorm / RealScalar(.1)); - m_par /= temp; - } else if (!(m_par != 0. && ratio < RealScalar(.75))) { - m_delta = pnorm / RealScalar(.5); - m_par = RealScalar(.5) * m_par; - } - - /* test for successful iteration. */ - if (ratio >= RealScalar(1e-4)) { - /* successful iteration. update x, m_fvec, and their norms. */ - x = m_wa2; - m_wa2 = m_diag.cwiseProduct(x); - m_fvec = m_wa4; - xnorm = m_wa2.stableNorm(); - m_fnorm = fnorm1; - ++m_iter; - } - - /* tests for convergence. */ - if (abs(actred) <= m_ftol && prered <= m_ftol && Scalar(.5) * ratio <= 1. && m_delta <= m_xtol * xnorm) - { - m_info = Success; - return LevenbergMarquardtSpace::RelativeErrorAndReductionTooSmall; - } - if (abs(actred) <= m_ftol && prered <= m_ftol && Scalar(.5) * ratio <= 1.) - { - m_info = Success; - return LevenbergMarquardtSpace::RelativeReductionTooSmall; - } - if (m_delta <= m_xtol * xnorm) - { - m_info = Success; - return LevenbergMarquardtSpace::RelativeErrorTooSmall; - } - - /* tests for termination and stringent tolerances. */ - if (m_nfev >= m_maxfev) - { - m_info = NoConvergence; - return LevenbergMarquardtSpace::TooManyFunctionEvaluation; - } - if (abs(actred) <= NumTraits<Scalar>::epsilon() && prered <= NumTraits<Scalar>::epsilon() && Scalar(.5) * ratio <= 1.) - { - m_info = Success; - return LevenbergMarquardtSpace::FtolTooSmall; - } - if (m_delta <= NumTraits<Scalar>::epsilon() * xnorm) - { - m_info = Success; - return LevenbergMarquardtSpace::XtolTooSmall; - } - if (m_gnorm <= NumTraits<Scalar>::epsilon()) - { - m_info = Success; - return LevenbergMarquardtSpace::GtolTooSmall; - } - - } while (ratio < Scalar(1e-4)); - - return LevenbergMarquardtSpace::Running; -} - - -} // end namespace Eigen - -#endif // EIGEN_LMONESTEP_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMpar.h b/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMpar.h deleted file mode 100644 index 9a483654..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMpar.h +++ /dev/null @@ -1,160 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This code initially comes from MINPACK whose original authors are: -// Copyright Jorge More - Argonne National Laboratory -// Copyright Burt Garbow - Argonne National Laboratory -// Copyright Ken Hillstrom - Argonne National Laboratory -// -// This Source Code Form is subject to the terms of the Minpack license -// (a BSD-like license) described in the campaigned CopyrightMINPACK.txt file. - -#ifndef EIGEN_LMPAR_H -#define EIGEN_LMPAR_H - -namespace Eigen { - -namespace internal { - - template <typename QRSolver, typename VectorType> - void lmpar2( - const QRSolver &qr, - const VectorType &diag, - const VectorType &qtb, - typename VectorType::Scalar m_delta, - typename VectorType::Scalar &par, - VectorType &x) - - { - using std::sqrt; - using std::abs; - typedef typename QRSolver::MatrixType MatrixType; - typedef typename QRSolver::Scalar Scalar; -// typedef typename QRSolver::StorageIndex StorageIndex; - - /* Local variables */ - Index j; - Scalar fp; - Scalar parc, parl; - Index iter; - Scalar temp, paru; - Scalar gnorm; - Scalar dxnorm; - - // Make a copy of the triangular factor. - // This copy is modified during call the qrsolv - MatrixType s; - s = qr.matrixR(); - - /* Function Body */ - const Scalar dwarf = (std::numeric_limits<Scalar>::min)(); - const Index n = qr.matrixR().cols(); - eigen_assert(n==diag.size()); - eigen_assert(n==qtb.size()); - - VectorType wa1, wa2; - - /* compute and store in x the gauss-newton direction. if the */ - /* jacobian is rank-deficient, obtain a least squares solution. */ - - // const Index rank = qr.nonzeroPivots(); // exactly double(0.) - const Index rank = qr.rank(); // use a threshold - wa1 = qtb; - wa1.tail(n-rank).setZero(); - //FIXME There is no solve in place for sparse triangularView - wa1.head(rank) = s.topLeftCorner(rank,rank).template triangularView<Upper>().solve(qtb.head(rank)); - - x = qr.colsPermutation()*wa1; - - /* initialize the iteration counter. */ - /* evaluate the function at the origin, and test */ - /* for acceptance of the gauss-newton direction. */ - iter = 0; - wa2 = diag.cwiseProduct(x); - dxnorm = wa2.blueNorm(); - fp = dxnorm - m_delta; - if (fp <= Scalar(0.1) * m_delta) { - par = 0; - return; - } - - /* if the jacobian is not rank deficient, the newton */ - /* step provides a lower bound, parl, for the zero of */ - /* the function. otherwise set this bound to zero. */ - parl = 0.; - if (rank==n) { - wa1 = qr.colsPermutation().inverse() * diag.cwiseProduct(wa2)/dxnorm; - s.topLeftCorner(n,n).transpose().template triangularView<Lower>().solveInPlace(wa1); - temp = wa1.blueNorm(); - parl = fp / m_delta / temp / temp; - } - - /* calculate an upper bound, paru, for the zero of the function. */ - for (j = 0; j < n; ++j) - wa1[j] = s.col(j).head(j+1).dot(qtb.head(j+1)) / diag[qr.colsPermutation().indices()(j)]; - - gnorm = wa1.stableNorm(); - paru = gnorm / m_delta; - if (paru == 0.) - paru = dwarf / (std::min)(m_delta,Scalar(0.1)); - - /* if the input par lies outside of the interval (parl,paru), */ - /* set par to the closer endpoint. */ - par = (std::max)(par,parl); - par = (std::min)(par,paru); - if (par == 0.) - par = gnorm / dxnorm; - - /* beginning of an iteration. */ - while (true) { - ++iter; - - /* evaluate the function at the current value of par. */ - if (par == 0.) - par = (std::max)(dwarf,Scalar(.001) * paru); /* Computing MAX */ - wa1 = sqrt(par)* diag; - - VectorType sdiag(n); - lmqrsolv(s, qr.colsPermutation(), wa1, qtb, x, sdiag); - - wa2 = diag.cwiseProduct(x); - dxnorm = wa2.blueNorm(); - temp = fp; - fp = dxnorm - m_delta; - - /* if the function is small enough, accept the current value */ - /* of par. also test for the exceptional cases where parl */ - /* is zero or the number of iterations has reached 10. */ - if (abs(fp) <= Scalar(0.1) * m_delta || (parl == 0. && fp <= temp && temp < 0.) || iter == 10) - break; - - /* compute the newton correction. */ - wa1 = qr.colsPermutation().inverse() * diag.cwiseProduct(wa2/dxnorm); - // we could almost use this here, but the diagonal is outside qr, in sdiag[] - for (j = 0; j < n; ++j) { - wa1[j] /= sdiag[j]; - temp = wa1[j]; - for (Index i = j+1; i < n; ++i) - wa1[i] -= s.coeff(i,j) * temp; - } - temp = wa1.blueNorm(); - parc = fp / m_delta / temp / temp; - - /* depending on the sign of the function, update parl or paru. */ - if (fp > 0.) - parl = (std::max)(parl,par); - if (fp < 0.) - paru = (std::min)(paru,par); - - /* compute an improved estimate for par. */ - par = (std::max)(parl,par+parc); - } - if (iter == 0) - par = 0.; - return; - } -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_LMPAR_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMqrsolv.h b/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMqrsolv.h deleted file mode 100644 index 12348581..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LMqrsolv.h +++ /dev/null @@ -1,188 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// Copyright (C) 2012 Desire Nuentsa <desire.nuentsa_wakam@inria.fr> -// -// This code initially comes from MINPACK whose original authors are: -// Copyright Jorge More - Argonne National Laboratory -// Copyright Burt Garbow - Argonne National Laboratory -// Copyright Ken Hillstrom - Argonne National Laboratory -// -// This Source Code Form is subject to the terms of the Minpack license -// (a BSD-like license) described in the campaigned CopyrightMINPACK.txt file. - -#ifndef EIGEN_LMQRSOLV_H -#define EIGEN_LMQRSOLV_H - -namespace Eigen { - -namespace internal { - -template <typename Scalar,int Rows, int Cols, typename PermIndex> -void lmqrsolv( - Matrix<Scalar,Rows,Cols> &s, - const PermutationMatrix<Dynamic,Dynamic,PermIndex> &iPerm, - const Matrix<Scalar,Dynamic,1> &diag, - const Matrix<Scalar,Dynamic,1> &qtb, - Matrix<Scalar,Dynamic,1> &x, - Matrix<Scalar,Dynamic,1> &sdiag) -{ - /* Local variables */ - Index i, j, k; - Scalar temp; - Index n = s.cols(); - Matrix<Scalar,Dynamic,1> wa(n); - JacobiRotation<Scalar> givens; - - /* Function Body */ - // the following will only change the lower triangular part of s, including - // the diagonal, though the diagonal is restored afterward - - /* copy r and (q transpose)*b to preserve input and initialize s. */ - /* in particular, save the diagonal elements of r in x. */ - x = s.diagonal(); - wa = qtb; - - - s.topLeftCorner(n,n).template triangularView<StrictlyLower>() = s.topLeftCorner(n,n).transpose(); - /* eliminate the diagonal matrix d using a givens rotation. */ - for (j = 0; j < n; ++j) { - - /* prepare the row of d to be eliminated, locating the */ - /* diagonal element using p from the qr factorization. */ - const PermIndex l = iPerm.indices()(j); - if (diag[l] == 0.) - break; - sdiag.tail(n-j).setZero(); - sdiag[j] = diag[l]; - - /* the transformations to eliminate the row of d */ - /* modify only a single element of (q transpose)*b */ - /* beyond the first n, which is initially zero. */ - Scalar qtbpj = 0.; - for (k = j; k < n; ++k) { - /* determine a givens rotation which eliminates the */ - /* appropriate element in the current row of d. */ - givens.makeGivens(-s(k,k), sdiag[k]); - - /* compute the modified diagonal element of r and */ - /* the modified element of ((q transpose)*b,0). */ - s(k,k) = givens.c() * s(k,k) + givens.s() * sdiag[k]; - temp = givens.c() * wa[k] + givens.s() * qtbpj; - qtbpj = -givens.s() * wa[k] + givens.c() * qtbpj; - wa[k] = temp; - - /* accumulate the transformation in the row of s. */ - for (i = k+1; i<n; ++i) { - temp = givens.c() * s(i,k) + givens.s() * sdiag[i]; - sdiag[i] = -givens.s() * s(i,k) + givens.c() * sdiag[i]; - s(i,k) = temp; - } - } - } - - /* solve the triangular system for z. if the system is */ - /* singular, then obtain a least squares solution. */ - Index nsing; - for(nsing=0; nsing<n && sdiag[nsing]!=0; nsing++) {} - - wa.tail(n-nsing).setZero(); - s.topLeftCorner(nsing, nsing).transpose().template triangularView<Upper>().solveInPlace(wa.head(nsing)); - - // restore - sdiag = s.diagonal(); - s.diagonal() = x; - - /* permute the components of z back to components of x. */ - x = iPerm * wa; -} - -template <typename Scalar, int _Options, typename Index> -void lmqrsolv( - SparseMatrix<Scalar,_Options,Index> &s, - const PermutationMatrix<Dynamic,Dynamic> &iPerm, - const Matrix<Scalar,Dynamic,1> &diag, - const Matrix<Scalar,Dynamic,1> &qtb, - Matrix<Scalar,Dynamic,1> &x, - Matrix<Scalar,Dynamic,1> &sdiag) -{ - /* Local variables */ - typedef SparseMatrix<Scalar,RowMajor,Index> FactorType; - Index i, j, k, l; - Scalar temp; - Index n = s.cols(); - Matrix<Scalar,Dynamic,1> wa(n); - JacobiRotation<Scalar> givens; - - /* Function Body */ - // the following will only change the lower triangular part of s, including - // the diagonal, though the diagonal is restored afterward - - /* copy r and (q transpose)*b to preserve input and initialize R. */ - wa = qtb; - FactorType R(s); - // Eliminate the diagonal matrix d using a givens rotation - for (j = 0; j < n; ++j) - { - // Prepare the row of d to be eliminated, locating the - // diagonal element using p from the qr factorization - l = iPerm.indices()(j); - if (diag(l) == Scalar(0)) - break; - sdiag.tail(n-j).setZero(); - sdiag[j] = diag[l]; - // the transformations to eliminate the row of d - // modify only a single element of (q transpose)*b - // beyond the first n, which is initially zero. - - Scalar qtbpj = 0; - // Browse the nonzero elements of row j of the upper triangular s - for (k = j; k < n; ++k) - { - typename FactorType::InnerIterator itk(R,k); - for (; itk; ++itk){ - if (itk.index() < k) continue; - else break; - } - //At this point, we have the diagonal element R(k,k) - // Determine a givens rotation which eliminates - // the appropriate element in the current row of d - givens.makeGivens(-itk.value(), sdiag(k)); - - // Compute the modified diagonal element of r and - // the modified element of ((q transpose)*b,0). - itk.valueRef() = givens.c() * itk.value() + givens.s() * sdiag(k); - temp = givens.c() * wa(k) + givens.s() * qtbpj; - qtbpj = -givens.s() * wa(k) + givens.c() * qtbpj; - wa(k) = temp; - - // Accumulate the transformation in the remaining k row/column of R - for (++itk; itk; ++itk) - { - i = itk.index(); - temp = givens.c() * itk.value() + givens.s() * sdiag(i); - sdiag(i) = -givens.s() * itk.value() + givens.c() * sdiag(i); - itk.valueRef() = temp; - } - } - } - - // Solve the triangular system for z. If the system is - // singular, then obtain a least squares solution - Index nsing; - for(nsing = 0; nsing<n && sdiag(nsing) !=0; nsing++) {} - - wa.tail(n-nsing).setZero(); -// x = wa; - wa.head(nsing) = R.topLeftCorner(nsing,nsing).template triangularView<Upper>().solve/*InPlace*/(wa.head(nsing)); - - sdiag = R.diagonal(); - // Permute the components of z back to components of x - x = iPerm * wa; -} -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_LMQRSOLV_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h b/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h deleted file mode 100644 index 62561da1..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h +++ /dev/null @@ -1,396 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// Copyright (C) 2012 Desire Nuentsa <desire.nuentsa_wakam@inria.fr> -// -// The algorithm of this class initially comes from MINPACK whose original authors are: -// Copyright Jorge More - Argonne National Laboratory -// Copyright Burt Garbow - Argonne National Laboratory -// Copyright Ken Hillstrom - Argonne National Laboratory -// -// This Source Code Form is subject to the terms of the Minpack license -// (a BSD-like license) described in the campaigned CopyrightMINPACK.txt file. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_LEVENBERGMARQUARDT_H -#define EIGEN_LEVENBERGMARQUARDT_H - - -namespace Eigen { -namespace LevenbergMarquardtSpace { - enum Status { - NotStarted = -2, - Running = -1, - ImproperInputParameters = 0, - RelativeReductionTooSmall = 1, - RelativeErrorTooSmall = 2, - RelativeErrorAndReductionTooSmall = 3, - CosinusTooSmall = 4, - TooManyFunctionEvaluation = 5, - FtolTooSmall = 6, - XtolTooSmall = 7, - GtolTooSmall = 8, - UserAsked = 9 - }; -} - -template <typename _Scalar, int NX=Dynamic, int NY=Dynamic> -struct DenseFunctor -{ - typedef _Scalar Scalar; - enum { - InputsAtCompileTime = NX, - ValuesAtCompileTime = NY - }; - typedef Matrix<Scalar,InputsAtCompileTime,1> InputType; - typedef Matrix<Scalar,ValuesAtCompileTime,1> ValueType; - typedef Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime> JacobianType; - typedef ColPivHouseholderQR<JacobianType> QRSolver; - const int m_inputs, m_values; - - DenseFunctor() : m_inputs(InputsAtCompileTime), m_values(ValuesAtCompileTime) {} - DenseFunctor(int inputs, int values) : m_inputs(inputs), m_values(values) {} - - int inputs() const { return m_inputs; } - int values() const { return m_values; } - - //int operator()(const InputType &x, ValueType& fvec) { } - // should be defined in derived classes - - //int df(const InputType &x, JacobianType& fjac) { } - // should be defined in derived classes -}; - -template <typename _Scalar, typename _Index> -struct SparseFunctor -{ - typedef _Scalar Scalar; - typedef _Index Index; - typedef Matrix<Scalar,Dynamic,1> InputType; - typedef Matrix<Scalar,Dynamic,1> ValueType; - typedef SparseMatrix<Scalar, ColMajor, Index> JacobianType; - typedef SparseQR<JacobianType, COLAMDOrdering<int> > QRSolver; - enum { - InputsAtCompileTime = Dynamic, - ValuesAtCompileTime = Dynamic - }; - - SparseFunctor(int inputs, int values) : m_inputs(inputs), m_values(values) {} - - int inputs() const { return m_inputs; } - int values() const { return m_values; } - - const int m_inputs, m_values; - //int operator()(const InputType &x, ValueType& fvec) { } - // to be defined in the functor - - //int df(const InputType &x, JacobianType& fjac) { } - // to be defined in the functor if no automatic differentiation - -}; -namespace internal { -template <typename QRSolver, typename VectorType> -void lmpar2(const QRSolver &qr, const VectorType &diag, const VectorType &qtb, - typename VectorType::Scalar m_delta, typename VectorType::Scalar &par, - VectorType &x); - } -/** - * \ingroup NonLinearOptimization_Module - * \brief Performs non linear optimization over a non-linear function, - * using a variant of the Levenberg Marquardt algorithm. - * - * Check wikipedia for more information. - * http://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm - */ -template<typename _FunctorType> -class LevenbergMarquardt : internal::no_assignment_operator -{ - public: - typedef _FunctorType FunctorType; - typedef typename FunctorType::QRSolver QRSolver; - typedef typename FunctorType::JacobianType JacobianType; - typedef typename JacobianType::Scalar Scalar; - typedef typename JacobianType::RealScalar RealScalar; - typedef typename QRSolver::StorageIndex PermIndex; - typedef Matrix<Scalar,Dynamic,1> FVectorType; - typedef PermutationMatrix<Dynamic,Dynamic,int> PermutationType; - public: - LevenbergMarquardt(FunctorType& functor) - : m_functor(functor),m_nfev(0),m_njev(0),m_fnorm(0.0),m_gnorm(0), - m_isInitialized(false),m_info(InvalidInput) - { - resetParameters(); - m_useExternalScaling=false; - } - - LevenbergMarquardtSpace::Status minimize(FVectorType &x); - LevenbergMarquardtSpace::Status minimizeInit(FVectorType &x); - LevenbergMarquardtSpace::Status minimizeOneStep(FVectorType &x); - LevenbergMarquardtSpace::Status lmder1( - FVectorType &x, - const Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) - ); - static LevenbergMarquardtSpace::Status lmdif1( - FunctorType &functor, - FVectorType &x, - Index *nfev, - const Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) - ); - - /** Sets the default parameters */ - void resetParameters() - { - using std::sqrt; - - m_factor = 100.; - m_maxfev = 400; - m_ftol = sqrt(NumTraits<RealScalar>::epsilon()); - m_xtol = sqrt(NumTraits<RealScalar>::epsilon()); - m_gtol = 0. ; - m_epsfcn = 0. ; - } - - /** Sets the tolerance for the norm of the solution vector*/ - void setXtol(RealScalar xtol) { m_xtol = xtol; } - - /** Sets the tolerance for the norm of the vector function*/ - void setFtol(RealScalar ftol) { m_ftol = ftol; } - - /** Sets the tolerance for the norm of the gradient of the error vector*/ - void setGtol(RealScalar gtol) { m_gtol = gtol; } - - /** Sets the step bound for the diagonal shift */ - void setFactor(RealScalar factor) { m_factor = factor; } - - /** Sets the error precision */ - void setEpsilon (RealScalar epsfcn) { m_epsfcn = epsfcn; } - - /** Sets the maximum number of function evaluation */ - void setMaxfev(Index maxfev) {m_maxfev = maxfev; } - - /** Use an external Scaling. If set to true, pass a nonzero diagonal to diag() */ - void setExternalScaling(bool value) {m_useExternalScaling = value; } - - /** \returns the tolerance for the norm of the solution vector */ - RealScalar xtol() const {return m_xtol; } - - /** \returns the tolerance for the norm of the vector function */ - RealScalar ftol() const {return m_ftol; } - - /** \returns the tolerance for the norm of the gradient of the error vector */ - RealScalar gtol() const {return m_gtol; } - - /** \returns the step bound for the diagonal shift */ - RealScalar factor() const {return m_factor; } - - /** \returns the error precision */ - RealScalar epsilon() const {return m_epsfcn; } - - /** \returns the maximum number of function evaluation */ - Index maxfev() const {return m_maxfev; } - - /** \returns a reference to the diagonal of the jacobian */ - FVectorType& diag() {return m_diag; } - - /** \returns the number of iterations performed */ - Index iterations() { return m_iter; } - - /** \returns the number of functions evaluation */ - Index nfev() { return m_nfev; } - - /** \returns the number of jacobian evaluation */ - Index njev() { return m_njev; } - - /** \returns the norm of current vector function */ - RealScalar fnorm() {return m_fnorm; } - - /** \returns the norm of the gradient of the error */ - RealScalar gnorm() {return m_gnorm; } - - /** \returns the LevenbergMarquardt parameter */ - RealScalar lm_param(void) { return m_par; } - - /** \returns a reference to the current vector function - */ - FVectorType& fvec() {return m_fvec; } - - /** \returns a reference to the matrix where the current Jacobian matrix is stored - */ - JacobianType& jacobian() {return m_fjac; } - - /** \returns a reference to the triangular matrix R from the QR of the jacobian matrix. - * \sa jacobian() - */ - JacobianType& matrixR() {return m_rfactor; } - - /** the permutation used in the QR factorization - */ - PermutationType permutation() {return m_permutation; } - - /** - * \brief Reports whether the minimization was successful - * \returns \c Success if the minimization was successful, - * \c NumericalIssue if a numerical problem arises during the - * minimization process, for example during the QR factorization - * \c NoConvergence if the minimization did not converge after - * the maximum number of function evaluation allowed - * \c InvalidInput if the input matrix is invalid - */ - ComputationInfo info() const - { - - return m_info; - } - private: - JacobianType m_fjac; - JacobianType m_rfactor; // The triangular matrix R from the QR of the jacobian matrix m_fjac - FunctorType &m_functor; - FVectorType m_fvec, m_qtf, m_diag; - Index n; - Index m; - Index m_nfev; - Index m_njev; - RealScalar m_fnorm; // Norm of the current vector function - RealScalar m_gnorm; //Norm of the gradient of the error - RealScalar m_factor; // - Index m_maxfev; // Maximum number of function evaluation - RealScalar m_ftol; //Tolerance in the norm of the vector function - RealScalar m_xtol; // - RealScalar m_gtol; //tolerance of the norm of the error gradient - RealScalar m_epsfcn; // - Index m_iter; // Number of iterations performed - RealScalar m_delta; - bool m_useExternalScaling; - PermutationType m_permutation; - FVectorType m_wa1, m_wa2, m_wa3, m_wa4; //Temporary vectors - RealScalar m_par; - bool m_isInitialized; // Check whether the minimization step has been called - ComputationInfo m_info; -}; - -template<typename FunctorType> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType>::minimize(FVectorType &x) -{ - LevenbergMarquardtSpace::Status status = minimizeInit(x); - if (status==LevenbergMarquardtSpace::ImproperInputParameters) { - m_isInitialized = true; - return status; - } - do { -// std::cout << " uv " << x.transpose() << "\n"; - status = minimizeOneStep(x); - } while (status==LevenbergMarquardtSpace::Running); - m_isInitialized = true; - return status; -} - -template<typename FunctorType> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType>::minimizeInit(FVectorType &x) -{ - n = x.size(); - m = m_functor.values(); - - m_wa1.resize(n); m_wa2.resize(n); m_wa3.resize(n); - m_wa4.resize(m); - m_fvec.resize(m); - //FIXME Sparse Case : Allocate space for the jacobian - m_fjac.resize(m, n); -// m_fjac.reserve(VectorXi::Constant(n,5)); // FIXME Find a better alternative - if (!m_useExternalScaling) - m_diag.resize(n); - eigen_assert( (!m_useExternalScaling || m_diag.size()==n) && "When m_useExternalScaling is set, the caller must provide a valid 'm_diag'"); - m_qtf.resize(n); - - /* Function Body */ - m_nfev = 0; - m_njev = 0; - - /* check the input parameters for errors. */ - if (n <= 0 || m < n || m_ftol < 0. || m_xtol < 0. || m_gtol < 0. || m_maxfev <= 0 || m_factor <= 0.){ - m_info = InvalidInput; - return LevenbergMarquardtSpace::ImproperInputParameters; - } - - if (m_useExternalScaling) - for (Index j = 0; j < n; ++j) - if (m_diag[j] <= 0.) - { - m_info = InvalidInput; - return LevenbergMarquardtSpace::ImproperInputParameters; - } - - /* evaluate the function at the starting point */ - /* and calculate its norm. */ - m_nfev = 1; - if ( m_functor(x, m_fvec) < 0) - return LevenbergMarquardtSpace::UserAsked; - m_fnorm = m_fvec.stableNorm(); - - /* initialize levenberg-marquardt parameter and iteration counter. */ - m_par = 0.; - m_iter = 1; - - return LevenbergMarquardtSpace::NotStarted; -} - -template<typename FunctorType> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType>::lmder1( - FVectorType &x, - const Scalar tol - ) -{ - n = x.size(); - m = m_functor.values(); - - /* check the input parameters for errors. */ - if (n <= 0 || m < n || tol < 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - resetParameters(); - m_ftol = tol; - m_xtol = tol; - m_maxfev = 100*(n+1); - - return minimize(x); -} - - -template<typename FunctorType> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType>::lmdif1( - FunctorType &functor, - FVectorType &x, - Index *nfev, - const Scalar tol - ) -{ - Index n = x.size(); - Index m = functor.values(); - - /* check the input parameters for errors. */ - if (n <= 0 || m < n || tol < 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - NumericalDiff<FunctorType> numDiff(functor); - // embedded LevenbergMarquardt - LevenbergMarquardt<NumericalDiff<FunctorType> > lm(numDiff); - lm.setFtol(tol); - lm.setXtol(tol); - lm.setMaxfev(200*(n+1)); - - LevenbergMarquardtSpace::Status info = LevenbergMarquardtSpace::Status(lm.minimize(x)); - if (nfev) - * nfev = lm.nfev(); - return info; -} - -} // end namespace Eigen - -#endif // EIGEN_LEVENBERGMARQUARDT_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h b/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h deleted file mode 100644 index 02284b0d..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h +++ /dev/null @@ -1,441 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009, 2010, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk> -// Copyright (C) 2011, 2013 Chen-Pang He <jdh8@ms63.hinet.net> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIX_EXPONENTIAL -#define EIGEN_MATRIX_EXPONENTIAL - -#include "StemFunction.h" - -namespace Eigen { -namespace internal { - -/** \brief Scaling operator. - * - * This struct is used by CwiseUnaryOp to scale a matrix by \f$ 2^{-s} \f$. - */ -template <typename RealScalar> -struct MatrixExponentialScalingOp -{ - /** \brief Constructor. - * - * \param[in] squarings The integer \f$ s \f$ in this document. - */ - MatrixExponentialScalingOp(int squarings) : m_squarings(squarings) { } - - - /** \brief Scale a matrix coefficient. - * - * \param[in,out] x The scalar to be scaled, becoming \f$ 2^{-s} x \f$. - */ - inline const RealScalar operator() (const RealScalar& x) const - { - using std::ldexp; - return ldexp(x, -m_squarings); - } - - typedef std::complex<RealScalar> ComplexScalar; - - /** \brief Scale a matrix coefficient. - * - * \param[in,out] x The scalar to be scaled, becoming \f$ 2^{-s} x \f$. - */ - inline const ComplexScalar operator() (const ComplexScalar& x) const - { - using std::ldexp; - return ComplexScalar(ldexp(x.real(), -m_squarings), ldexp(x.imag(), -m_squarings)); - } - - private: - int m_squarings; -}; - -/** \brief Compute the (3,3)-Padé approximant to the exponential. - * - * After exit, \f$ (V+U)(V-U)^{-1} \f$ is the Padé - * approximant of \f$ \exp(A) \f$ around \f$ A = 0 \f$. - */ -template <typename MatA, typename MatU, typename MatV> -void matrix_exp_pade3(const MatA& A, MatU& U, MatV& V) -{ - typedef typename MatA::PlainObject MatrixType; - typedef typename NumTraits<typename traits<MatA>::Scalar>::Real RealScalar; - const RealScalar b[] = {120.L, 60.L, 12.L, 1.L}; - const MatrixType A2 = A * A; - const MatrixType tmp = b[3] * A2 + b[1] * MatrixType::Identity(A.rows(), A.cols()); - U.noalias() = A * tmp; - V = b[2] * A2 + b[0] * MatrixType::Identity(A.rows(), A.cols()); -} - -/** \brief Compute the (5,5)-Padé approximant to the exponential. - * - * After exit, \f$ (V+U)(V-U)^{-1} \f$ is the Padé - * approximant of \f$ \exp(A) \f$ around \f$ A = 0 \f$. - */ -template <typename MatA, typename MatU, typename MatV> -void matrix_exp_pade5(const MatA& A, MatU& U, MatV& V) -{ - typedef typename MatA::PlainObject MatrixType; - typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar; - const RealScalar b[] = {30240.L, 15120.L, 3360.L, 420.L, 30.L, 1.L}; - const MatrixType A2 = A * A; - const MatrixType A4 = A2 * A2; - const MatrixType tmp = b[5] * A4 + b[3] * A2 + b[1] * MatrixType::Identity(A.rows(), A.cols()); - U.noalias() = A * tmp; - V = b[4] * A4 + b[2] * A2 + b[0] * MatrixType::Identity(A.rows(), A.cols()); -} - -/** \brief Compute the (7,7)-Padé approximant to the exponential. - * - * After exit, \f$ (V+U)(V-U)^{-1} \f$ is the Padé - * approximant of \f$ \exp(A) \f$ around \f$ A = 0 \f$. - */ -template <typename MatA, typename MatU, typename MatV> -void matrix_exp_pade7(const MatA& A, MatU& U, MatV& V) -{ - typedef typename MatA::PlainObject MatrixType; - typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar; - const RealScalar b[] = {17297280.L, 8648640.L, 1995840.L, 277200.L, 25200.L, 1512.L, 56.L, 1.L}; - const MatrixType A2 = A * A; - const MatrixType A4 = A2 * A2; - const MatrixType A6 = A4 * A2; - const MatrixType tmp = b[7] * A6 + b[5] * A4 + b[3] * A2 - + b[1] * MatrixType::Identity(A.rows(), A.cols()); - U.noalias() = A * tmp; - V = b[6] * A6 + b[4] * A4 + b[2] * A2 + b[0] * MatrixType::Identity(A.rows(), A.cols()); - -} - -/** \brief Compute the (9,9)-Padé approximant to the exponential. - * - * After exit, \f$ (V+U)(V-U)^{-1} \f$ is the Padé - * approximant of \f$ \exp(A) \f$ around \f$ A = 0 \f$. - */ -template <typename MatA, typename MatU, typename MatV> -void matrix_exp_pade9(const MatA& A, MatU& U, MatV& V) -{ - typedef typename MatA::PlainObject MatrixType; - typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar; - const RealScalar b[] = {17643225600.L, 8821612800.L, 2075673600.L, 302702400.L, 30270240.L, - 2162160.L, 110880.L, 3960.L, 90.L, 1.L}; - const MatrixType A2 = A * A; - const MatrixType A4 = A2 * A2; - const MatrixType A6 = A4 * A2; - const MatrixType A8 = A6 * A2; - const MatrixType tmp = b[9] * A8 + b[7] * A6 + b[5] * A4 + b[3] * A2 - + b[1] * MatrixType::Identity(A.rows(), A.cols()); - U.noalias() = A * tmp; - V = b[8] * A8 + b[6] * A6 + b[4] * A4 + b[2] * A2 + b[0] * MatrixType::Identity(A.rows(), A.cols()); -} - -/** \brief Compute the (13,13)-Padé approximant to the exponential. - * - * After exit, \f$ (V+U)(V-U)^{-1} \f$ is the Padé - * approximant of \f$ \exp(A) \f$ around \f$ A = 0 \f$. - */ -template <typename MatA, typename MatU, typename MatV> -void matrix_exp_pade13(const MatA& A, MatU& U, MatV& V) -{ - typedef typename MatA::PlainObject MatrixType; - typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar; - const RealScalar b[] = {64764752532480000.L, 32382376266240000.L, 7771770303897600.L, - 1187353796428800.L, 129060195264000.L, 10559470521600.L, 670442572800.L, - 33522128640.L, 1323241920.L, 40840800.L, 960960.L, 16380.L, 182.L, 1.L}; - const MatrixType A2 = A * A; - const MatrixType A4 = A2 * A2; - const MatrixType A6 = A4 * A2; - V = b[13] * A6 + b[11] * A4 + b[9] * A2; // used for temporary storage - MatrixType tmp = A6 * V; - tmp += b[7] * A6 + b[5] * A4 + b[3] * A2 + b[1] * MatrixType::Identity(A.rows(), A.cols()); - U.noalias() = A * tmp; - tmp = b[12] * A6 + b[10] * A4 + b[8] * A2; - V.noalias() = A6 * tmp; - V += b[6] * A6 + b[4] * A4 + b[2] * A2 + b[0] * MatrixType::Identity(A.rows(), A.cols()); -} - -/** \brief Compute the (17,17)-Padé approximant to the exponential. - * - * After exit, \f$ (V+U)(V-U)^{-1} \f$ is the Padé - * approximant of \f$ \exp(A) \f$ around \f$ A = 0 \f$. - * - * This function activates only if your long double is double-double or quadruple. - */ -#if LDBL_MANT_DIG > 64 -template <typename MatA, typename MatU, typename MatV> -void matrix_exp_pade17(const MatA& A, MatU& U, MatV& V) -{ - typedef typename MatA::PlainObject MatrixType; - typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar; - const RealScalar b[] = {830034394580628357120000.L, 415017197290314178560000.L, - 100610229646136770560000.L, 15720348382208870400000.L, - 1774878043152614400000.L, 153822763739893248000.L, 10608466464820224000.L, - 595373117923584000.L, 27563570274240000.L, 1060137318240000.L, - 33924394183680.L, 899510451840.L, 19554575040.L, 341863200.L, 4651200.L, - 46512.L, 306.L, 1.L}; - const MatrixType A2 = A * A; - const MatrixType A4 = A2 * A2; - const MatrixType A6 = A4 * A2; - const MatrixType A8 = A4 * A4; - V = b[17] * A8 + b[15] * A6 + b[13] * A4 + b[11] * A2; // used for temporary storage - MatrixType tmp = A8 * V; - tmp += b[9] * A8 + b[7] * A6 + b[5] * A4 + b[3] * A2 - + b[1] * MatrixType::Identity(A.rows(), A.cols()); - U.noalias() = A * tmp; - tmp = b[16] * A8 + b[14] * A6 + b[12] * A4 + b[10] * A2; - V.noalias() = tmp * A8; - V += b[8] * A8 + b[6] * A6 + b[4] * A4 + b[2] * A2 - + b[0] * MatrixType::Identity(A.rows(), A.cols()); -} -#endif - -template <typename MatrixType, typename RealScalar = typename NumTraits<typename traits<MatrixType>::Scalar>::Real> -struct matrix_exp_computeUV -{ - /** \brief Compute Padé approximant to the exponential. - * - * Computes \c U, \c V and \c squarings such that \f$ (V+U)(V-U)^{-1} \f$ is a Padé - * approximant of \f$ \exp(2^{-\mbox{squarings}}M) \f$ around \f$ M = 0 \f$, where \f$ M \f$ - * denotes the matrix \c arg. The degree of the Padé approximant and the value of squarings - * are chosen such that the approximation error is no more than the round-off error. - */ - static void run(const MatrixType& arg, MatrixType& U, MatrixType& V, int& squarings); -}; - -template <typename MatrixType> -struct matrix_exp_computeUV<MatrixType, float> -{ - template <typename ArgType> - static void run(const ArgType& arg, MatrixType& U, MatrixType& V, int& squarings) - { - using std::frexp; - using std::pow; - const float l1norm = arg.cwiseAbs().colwise().sum().maxCoeff(); - squarings = 0; - if (l1norm < 4.258730016922831e-001f) { - matrix_exp_pade3(arg, U, V); - } else if (l1norm < 1.880152677804762e+000f) { - matrix_exp_pade5(arg, U, V); - } else { - const float maxnorm = 3.925724783138660f; - frexp(l1norm / maxnorm, &squarings); - if (squarings < 0) squarings = 0; - MatrixType A = arg.unaryExpr(MatrixExponentialScalingOp<float>(squarings)); - matrix_exp_pade7(A, U, V); - } - } -}; - -template <typename MatrixType> -struct matrix_exp_computeUV<MatrixType, double> -{ - typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar; - template <typename ArgType> - static void run(const ArgType& arg, MatrixType& U, MatrixType& V, int& squarings) - { - using std::frexp; - using std::pow; - const RealScalar l1norm = arg.cwiseAbs().colwise().sum().maxCoeff(); - squarings = 0; - if (l1norm < 1.495585217958292e-002) { - matrix_exp_pade3(arg, U, V); - } else if (l1norm < 2.539398330063230e-001) { - matrix_exp_pade5(arg, U, V); - } else if (l1norm < 9.504178996162932e-001) { - matrix_exp_pade7(arg, U, V); - } else if (l1norm < 2.097847961257068e+000) { - matrix_exp_pade9(arg, U, V); - } else { - const RealScalar maxnorm = 5.371920351148152; - frexp(l1norm / maxnorm, &squarings); - if (squarings < 0) squarings = 0; - MatrixType A = arg.unaryExpr(MatrixExponentialScalingOp<RealScalar>(squarings)); - matrix_exp_pade13(A, U, V); - } - } -}; - -template <typename MatrixType> -struct matrix_exp_computeUV<MatrixType, long double> -{ - template <typename ArgType> - static void run(const ArgType& arg, MatrixType& U, MatrixType& V, int& squarings) - { -#if LDBL_MANT_DIG == 53 // double precision - matrix_exp_computeUV<MatrixType, double>::run(arg, U, V, squarings); - -#else - - using std::frexp; - using std::pow; - const long double l1norm = arg.cwiseAbs().colwise().sum().maxCoeff(); - squarings = 0; - -#if LDBL_MANT_DIG <= 64 // extended precision - - if (l1norm < 4.1968497232266989671e-003L) { - matrix_exp_pade3(arg, U, V); - } else if (l1norm < 1.1848116734693823091e-001L) { - matrix_exp_pade5(arg, U, V); - } else if (l1norm < 5.5170388480686700274e-001L) { - matrix_exp_pade7(arg, U, V); - } else if (l1norm < 1.3759868875587845383e+000L) { - matrix_exp_pade9(arg, U, V); - } else { - const long double maxnorm = 4.0246098906697353063L; - frexp(l1norm / maxnorm, &squarings); - if (squarings < 0) squarings = 0; - MatrixType A = arg.unaryExpr(MatrixExponentialScalingOp<long double>(squarings)); - matrix_exp_pade13(A, U, V); - } - -#elif LDBL_MANT_DIG <= 106 // double-double - - if (l1norm < 3.2787892205607026992947488108213e-005L) { - matrix_exp_pade3(arg, U, V); - } else if (l1norm < 6.4467025060072760084130906076332e-003L) { - matrix_exp_pade5(arg, U, V); - } else if (l1norm < 6.8988028496595374751374122881143e-002L) { - matrix_exp_pade7(arg, U, V); - } else if (l1norm < 2.7339737518502231741495857201670e-001L) { - matrix_exp_pade9(arg, U, V); - } else if (l1norm < 1.3203382096514474905666448850278e+000L) { - matrix_exp_pade13(arg, U, V); - } else { - const long double maxnorm = 3.2579440895405400856599663723517L; - frexp(l1norm / maxnorm, &squarings); - if (squarings < 0) squarings = 0; - MatrixType A = arg.unaryExpr(MatrixExponentialScalingOp<long double>(squarings)); - matrix_exp_pade17(A, U, V); - } - -#elif LDBL_MANT_DIG <= 113 // quadruple precision - - if (l1norm < 1.639394610288918690547467954466970e-005L) { - matrix_exp_pade3(arg, U, V); - } else if (l1norm < 4.253237712165275566025884344433009e-003L) { - matrix_exp_pade5(arg, U, V); - } else if (l1norm < 5.125804063165764409885122032933142e-002L) { - matrix_exp_pade7(arg, U, V); - } else if (l1norm < 2.170000765161155195453205651889853e-001L) { - matrix_exp_pade9(arg, U, V); - } else if (l1norm < 1.125358383453143065081397882891878e+000L) { - matrix_exp_pade13(arg, U, V); - } else { - const long double maxnorm = 2.884233277829519311757165057717815L; - frexp(l1norm / maxnorm, &squarings); - if (squarings < 0) squarings = 0; - MatrixType A = arg.unaryExpr(MatrixExponentialScalingOp<long double>(squarings)); - matrix_exp_pade17(A, U, V); - } - -#else - - // this case should be handled in compute() - eigen_assert(false && "Bug in MatrixExponential"); - -#endif -#endif // LDBL_MANT_DIG - } -}; - -template<typename T> struct is_exp_known_type : false_type {}; -template<> struct is_exp_known_type<float> : true_type {}; -template<> struct is_exp_known_type<double> : true_type {}; -#if LDBL_MANT_DIG <= 113 -template<> struct is_exp_known_type<long double> : true_type {}; -#endif - -template <typename ArgType, typename ResultType> -void matrix_exp_compute(const ArgType& arg, ResultType &result, true_type) // natively supported scalar type -{ - typedef typename ArgType::PlainObject MatrixType; - MatrixType U, V; - int squarings; - matrix_exp_computeUV<MatrixType>::run(arg, U, V, squarings); // Pade approximant is (U+V) / (-U+V) - MatrixType numer = U + V; - MatrixType denom = -U + V; - result = denom.partialPivLu().solve(numer); - for (int i=0; i<squarings; i++) - result *= result; // undo scaling by repeated squaring -} - - -/* Computes the matrix exponential - * - * \param arg argument of matrix exponential (should be plain object) - * \param result variable in which result will be stored - */ -template <typename ArgType, typename ResultType> -void matrix_exp_compute(const ArgType& arg, ResultType &result, false_type) // default -{ - typedef typename ArgType::PlainObject MatrixType; - typedef typename traits<MatrixType>::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef typename std::complex<RealScalar> ComplexScalar; - result = arg.matrixFunction(internal::stem_function_exp<ComplexScalar>); -} - -} // end namespace Eigen::internal - -/** \ingroup MatrixFunctions_Module - * - * \brief Proxy for the matrix exponential of some matrix (expression). - * - * \tparam Derived Type of the argument to the matrix exponential. - * - * This class holds the argument to the matrix exponential until it is assigned or evaluated for - * some other reason (so the argument should not be changed in the meantime). It is the return type - * of MatrixBase::exp() and most of the time this is the only way it is used. - */ -template<typename Derived> struct MatrixExponentialReturnValue -: public ReturnByValue<MatrixExponentialReturnValue<Derived> > -{ - public: - /** \brief Constructor. - * - * \param src %Matrix (expression) forming the argument of the matrix exponential. - */ - MatrixExponentialReturnValue(const Derived& src) : m_src(src) { } - - /** \brief Compute the matrix exponential. - * - * \param result the matrix exponential of \p src in the constructor. - */ - template <typename ResultType> - inline void evalTo(ResultType& result) const - { - const typename internal::nested_eval<Derived, 10>::type tmp(m_src); - internal::matrix_exp_compute(tmp, result, internal::is_exp_known_type<typename Derived::RealScalar>()); - } - - Index rows() const { return m_src.rows(); } - Index cols() const { return m_src.cols(); } - - protected: - const typename internal::ref_selector<Derived>::type m_src; -}; - -namespace internal { -template<typename Derived> -struct traits<MatrixExponentialReturnValue<Derived> > -{ - typedef typename Derived::PlainObject ReturnType; -}; -} - -template <typename Derived> -const MatrixExponentialReturnValue<Derived> MatrixBase<Derived>::exp() const -{ - eigen_assert(rows() == cols()); - return MatrixExponentialReturnValue<Derived>(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_MATRIX_EXPONENTIAL diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h b/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h deleted file mode 100644 index cc12ab62..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h +++ /dev/null @@ -1,569 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009-2011, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIX_FUNCTION_H -#define EIGEN_MATRIX_FUNCTION_H - -#include "StemFunction.h" - - -namespace Eigen { - -namespace internal { - -/** \brief Maximum distance allowed between eigenvalues to be considered "close". */ -static const float matrix_function_separation = 0.1f; - -/** \ingroup MatrixFunctions_Module - * \class MatrixFunctionAtomic - * \brief Helper class for computing matrix functions of atomic matrices. - * - * Here, an atomic matrix is a triangular matrix whose diagonal entries are close to each other. - */ -template <typename MatrixType> -class MatrixFunctionAtomic -{ - public: - - typedef typename MatrixType::Scalar Scalar; - typedef typename stem_function<Scalar>::type StemFunction; - - /** \brief Constructor - * \param[in] f matrix function to compute. - */ - MatrixFunctionAtomic(StemFunction f) : m_f(f) { } - - /** \brief Compute matrix function of atomic matrix - * \param[in] A argument of matrix function, should be upper triangular and atomic - * \returns f(A), the matrix function evaluated at the given matrix - */ - MatrixType compute(const MatrixType& A); - - private: - StemFunction* m_f; -}; - -template <typename MatrixType> -typename NumTraits<typename MatrixType::Scalar>::Real matrix_function_compute_mu(const MatrixType& A) -{ - typedef typename plain_col_type<MatrixType>::type VectorType; - Index rows = A.rows(); - const MatrixType N = MatrixType::Identity(rows, rows) - A; - VectorType e = VectorType::Ones(rows); - N.template triangularView<Upper>().solveInPlace(e); - return e.cwiseAbs().maxCoeff(); -} - -template <typename MatrixType> -MatrixType MatrixFunctionAtomic<MatrixType>::compute(const MatrixType& A) -{ - // TODO: Use that A is upper triangular - typedef typename NumTraits<Scalar>::Real RealScalar; - Index rows = A.rows(); - Scalar avgEival = A.trace() / Scalar(RealScalar(rows)); - MatrixType Ashifted = A - avgEival * MatrixType::Identity(rows, rows); - RealScalar mu = matrix_function_compute_mu(Ashifted); - MatrixType F = m_f(avgEival, 0) * MatrixType::Identity(rows, rows); - MatrixType P = Ashifted; - MatrixType Fincr; - for (Index s = 1; double(s) < 1.1 * double(rows) + 10.0; s++) { // upper limit is fairly arbitrary - Fincr = m_f(avgEival, static_cast<int>(s)) * P; - F += Fincr; - P = Scalar(RealScalar(1)/RealScalar(s + 1)) * P * Ashifted; - - // test whether Taylor series converged - const RealScalar F_norm = F.cwiseAbs().rowwise().sum().maxCoeff(); - const RealScalar Fincr_norm = Fincr.cwiseAbs().rowwise().sum().maxCoeff(); - if (Fincr_norm < NumTraits<Scalar>::epsilon() * F_norm) { - RealScalar delta = 0; - RealScalar rfactorial = 1; - for (Index r = 0; r < rows; r++) { - RealScalar mx = 0; - for (Index i = 0; i < rows; i++) - mx = (std::max)(mx, std::abs(m_f(Ashifted(i, i) + avgEival, static_cast<int>(s+r)))); - if (r != 0) - rfactorial *= RealScalar(r); - delta = (std::max)(delta, mx / rfactorial); - } - const RealScalar P_norm = P.cwiseAbs().rowwise().sum().maxCoeff(); - if (mu * delta * P_norm < NumTraits<Scalar>::epsilon() * F_norm) // series converged - break; - } - } - return F; -} - -/** \brief Find cluster in \p clusters containing some value - * \param[in] key Value to find - * \returns Iterator to cluster containing \p key, or \c clusters.end() if no cluster in \p m_clusters - * contains \p key. - */ -template <typename Index, typename ListOfClusters> -typename ListOfClusters::iterator matrix_function_find_cluster(Index key, ListOfClusters& clusters) -{ - typename std::list<Index>::iterator j; - for (typename ListOfClusters::iterator i = clusters.begin(); i != clusters.end(); ++i) { - j = std::find(i->begin(), i->end(), key); - if (j != i->end()) - return i; - } - return clusters.end(); -} - -/** \brief Partition eigenvalues in clusters of ei'vals close to each other - * - * \param[in] eivals Eigenvalues - * \param[out] clusters Resulting partition of eigenvalues - * - * The partition satisfies the following two properties: - * # Any eigenvalue in a certain cluster is at most matrix_function_separation() away from another eigenvalue - * in the same cluster. - * # The distance between two eigenvalues in different clusters is more than matrix_function_separation(). - * The implementation follows Algorithm 4.1 in the paper of Davies and Higham. - */ -template <typename EivalsType, typename Cluster> -void matrix_function_partition_eigenvalues(const EivalsType& eivals, std::list<Cluster>& clusters) -{ - typedef typename EivalsType::RealScalar RealScalar; - for (Index i=0; i<eivals.rows(); ++i) { - // Find cluster containing i-th ei'val, adding a new cluster if necessary - typename std::list<Cluster>::iterator qi = matrix_function_find_cluster(i, clusters); - if (qi == clusters.end()) { - Cluster l; - l.push_back(i); - clusters.push_back(l); - qi = clusters.end(); - --qi; - } - - // Look for other element to add to the set - for (Index j=i+1; j<eivals.rows(); ++j) { - if (abs(eivals(j) - eivals(i)) <= RealScalar(matrix_function_separation) - && std::find(qi->begin(), qi->end(), j) == qi->end()) { - typename std::list<Cluster>::iterator qj = matrix_function_find_cluster(j, clusters); - if (qj == clusters.end()) { - qi->push_back(j); - } else { - qi->insert(qi->end(), qj->begin(), qj->end()); - clusters.erase(qj); - } - } - } - } -} - -/** \brief Compute size of each cluster given a partitioning */ -template <typename ListOfClusters, typename Index> -void matrix_function_compute_cluster_size(const ListOfClusters& clusters, Matrix<Index, Dynamic, 1>& clusterSize) -{ - const Index numClusters = static_cast<Index>(clusters.size()); - clusterSize.setZero(numClusters); - Index clusterIndex = 0; - for (typename ListOfClusters::const_iterator cluster = clusters.begin(); cluster != clusters.end(); ++cluster) { - clusterSize[clusterIndex] = cluster->size(); - ++clusterIndex; - } -} - -/** \brief Compute start of each block using clusterSize */ -template <typename VectorType> -void matrix_function_compute_block_start(const VectorType& clusterSize, VectorType& blockStart) -{ - blockStart.resize(clusterSize.rows()); - blockStart(0) = 0; - for (Index i = 1; i < clusterSize.rows(); i++) { - blockStart(i) = blockStart(i-1) + clusterSize(i-1); - } -} - -/** \brief Compute mapping of eigenvalue indices to cluster indices */ -template <typename EivalsType, typename ListOfClusters, typename VectorType> -void matrix_function_compute_map(const EivalsType& eivals, const ListOfClusters& clusters, VectorType& eivalToCluster) -{ - eivalToCluster.resize(eivals.rows()); - Index clusterIndex = 0; - for (typename ListOfClusters::const_iterator cluster = clusters.begin(); cluster != clusters.end(); ++cluster) { - for (Index i = 0; i < eivals.rows(); ++i) { - if (std::find(cluster->begin(), cluster->end(), i) != cluster->end()) { - eivalToCluster[i] = clusterIndex; - } - } - ++clusterIndex; - } -} - -/** \brief Compute permutation which groups ei'vals in same cluster together */ -template <typename DynVectorType, typename VectorType> -void matrix_function_compute_permutation(const DynVectorType& blockStart, const DynVectorType& eivalToCluster, VectorType& permutation) -{ - DynVectorType indexNextEntry = blockStart; - permutation.resize(eivalToCluster.rows()); - for (Index i = 0; i < eivalToCluster.rows(); i++) { - Index cluster = eivalToCluster[i]; - permutation[i] = indexNextEntry[cluster]; - ++indexNextEntry[cluster]; - } -} - -/** \brief Permute Schur decomposition in U and T according to permutation */ -template <typename VectorType, typename MatrixType> -void matrix_function_permute_schur(VectorType& permutation, MatrixType& U, MatrixType& T) -{ - for (Index i = 0; i < permutation.rows() - 1; i++) { - Index j; - for (j = i; j < permutation.rows(); j++) { - if (permutation(j) == i) break; - } - eigen_assert(permutation(j) == i); - for (Index k = j-1; k >= i; k--) { - JacobiRotation<typename MatrixType::Scalar> rotation; - rotation.makeGivens(T(k, k+1), T(k+1, k+1) - T(k, k)); - T.applyOnTheLeft(k, k+1, rotation.adjoint()); - T.applyOnTheRight(k, k+1, rotation); - U.applyOnTheRight(k, k+1, rotation); - std::swap(permutation.coeffRef(k), permutation.coeffRef(k+1)); - } - } -} - -/** \brief Compute block diagonal part of matrix function. - * - * This routine computes the matrix function applied to the block diagonal part of \p T (which should be - * upper triangular), with the blocking given by \p blockStart and \p clusterSize. The matrix function of - * each diagonal block is computed by \p atomic. The off-diagonal parts of \p fT are set to zero. - */ -template <typename MatrixType, typename AtomicType, typename VectorType> -void matrix_function_compute_block_atomic(const MatrixType& T, AtomicType& atomic, const VectorType& blockStart, const VectorType& clusterSize, MatrixType& fT) -{ - fT.setZero(T.rows(), T.cols()); - for (Index i = 0; i < clusterSize.rows(); ++i) { - fT.block(blockStart(i), blockStart(i), clusterSize(i), clusterSize(i)) - = atomic.compute(T.block(blockStart(i), blockStart(i), clusterSize(i), clusterSize(i))); - } -} - -/** \brief Solve a triangular Sylvester equation AX + XB = C - * - * \param[in] A the matrix A; should be square and upper triangular - * \param[in] B the matrix B; should be square and upper triangular - * \param[in] C the matrix C; should have correct size. - * - * \returns the solution X. - * - * If A is m-by-m and B is n-by-n, then both C and X are m-by-n. The (i,j)-th component of the Sylvester - * equation is - * \f[ - * \sum_{k=i}^m A_{ik} X_{kj} + \sum_{k=1}^j X_{ik} B_{kj} = C_{ij}. - * \f] - * This can be re-arranged to yield: - * \f[ - * X_{ij} = \frac{1}{A_{ii} + B_{jj}} \Bigl( C_{ij} - * - \sum_{k=i+1}^m A_{ik} X_{kj} - \sum_{k=1}^{j-1} X_{ik} B_{kj} \Bigr). - * \f] - * It is assumed that A and B are such that the numerator is never zero (otherwise the Sylvester equation - * does not have a unique solution). In that case, these equations can be evaluated in the order - * \f$ i=m,\ldots,1 \f$ and \f$ j=1,\ldots,n \f$. - */ -template <typename MatrixType> -MatrixType matrix_function_solve_triangular_sylvester(const MatrixType& A, const MatrixType& B, const MatrixType& C) -{ - eigen_assert(A.rows() == A.cols()); - eigen_assert(A.isUpperTriangular()); - eigen_assert(B.rows() == B.cols()); - eigen_assert(B.isUpperTriangular()); - eigen_assert(C.rows() == A.rows()); - eigen_assert(C.cols() == B.rows()); - - typedef typename MatrixType::Scalar Scalar; - - Index m = A.rows(); - Index n = B.rows(); - MatrixType X(m, n); - - for (Index i = m - 1; i >= 0; --i) { - for (Index j = 0; j < n; ++j) { - - // Compute AX = \sum_{k=i+1}^m A_{ik} X_{kj} - Scalar AX; - if (i == m - 1) { - AX = 0; - } else { - Matrix<Scalar,1,1> AXmatrix = A.row(i).tail(m-1-i) * X.col(j).tail(m-1-i); - AX = AXmatrix(0,0); - } - - // Compute XB = \sum_{k=1}^{j-1} X_{ik} B_{kj} - Scalar XB; - if (j == 0) { - XB = 0; - } else { - Matrix<Scalar,1,1> XBmatrix = X.row(i).head(j) * B.col(j).head(j); - XB = XBmatrix(0,0); - } - - X(i,j) = (C(i,j) - AX - XB) / (A(i,i) + B(j,j)); - } - } - return X; -} - -/** \brief Compute part of matrix function above block diagonal. - * - * This routine completes the computation of \p fT, denoting a matrix function applied to the triangular - * matrix \p T. It assumes that the block diagonal part of \p fT has already been computed. The part below - * the diagonal is zero, because \p T is upper triangular. - */ -template <typename MatrixType, typename VectorType> -void matrix_function_compute_above_diagonal(const MatrixType& T, const VectorType& blockStart, const VectorType& clusterSize, MatrixType& fT) -{ - typedef internal::traits<MatrixType> Traits; - typedef typename MatrixType::Scalar Scalar; - static const int Options = MatrixType::Options; - typedef Matrix<Scalar, Dynamic, Dynamic, Options, Traits::RowsAtCompileTime, Traits::ColsAtCompileTime> DynMatrixType; - - for (Index k = 1; k < clusterSize.rows(); k++) { - for (Index i = 0; i < clusterSize.rows() - k; i++) { - // compute (i, i+k) block - DynMatrixType A = T.block(blockStart(i), blockStart(i), clusterSize(i), clusterSize(i)); - DynMatrixType B = -T.block(blockStart(i+k), blockStart(i+k), clusterSize(i+k), clusterSize(i+k)); - DynMatrixType C = fT.block(blockStart(i), blockStart(i), clusterSize(i), clusterSize(i)) - * T.block(blockStart(i), blockStart(i+k), clusterSize(i), clusterSize(i+k)); - C -= T.block(blockStart(i), blockStart(i+k), clusterSize(i), clusterSize(i+k)) - * fT.block(blockStart(i+k), blockStart(i+k), clusterSize(i+k), clusterSize(i+k)); - for (Index m = i + 1; m < i + k; m++) { - C += fT.block(blockStart(i), blockStart(m), clusterSize(i), clusterSize(m)) - * T.block(blockStart(m), blockStart(i+k), clusterSize(m), clusterSize(i+k)); - C -= T.block(blockStart(i), blockStart(m), clusterSize(i), clusterSize(m)) - * fT.block(blockStart(m), blockStart(i+k), clusterSize(m), clusterSize(i+k)); - } - fT.block(blockStart(i), blockStart(i+k), clusterSize(i), clusterSize(i+k)) - = matrix_function_solve_triangular_sylvester(A, B, C); - } - } -} - -/** \ingroup MatrixFunctions_Module - * \brief Class for computing matrix functions. - * \tparam MatrixType type of the argument of the matrix function, - * expected to be an instantiation of the Matrix class template. - * \tparam AtomicType type for computing matrix function of atomic blocks. - * \tparam IsComplex used internally to select correct specialization. - * - * This class implements the Schur-Parlett algorithm for computing matrix functions. The spectrum of the - * matrix is divided in clustered of eigenvalues that lies close together. This class delegates the - * computation of the matrix function on every block corresponding to these clusters to an object of type - * \p AtomicType and uses these results to compute the matrix function of the whole matrix. The class - * \p AtomicType should have a \p compute() member function for computing the matrix function of a block. - * - * \sa class MatrixFunctionAtomic, class MatrixLogarithmAtomic - */ -template <typename MatrixType, int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex> -struct matrix_function_compute -{ - /** \brief Compute the matrix function. - * - * \param[in] A argument of matrix function, should be a square matrix. - * \param[in] atomic class for computing matrix function of atomic blocks. - * \param[out] result the function \p f applied to \p A, as - * specified in the constructor. - * - * See MatrixBase::matrixFunction() for details on how this computation - * is implemented. - */ - template <typename AtomicType, typename ResultType> - static void run(const MatrixType& A, AtomicType& atomic, ResultType &result); -}; - -/** \internal \ingroup MatrixFunctions_Module - * \brief Partial specialization of MatrixFunction for real matrices - * - * This converts the real matrix to a complex matrix, compute the matrix function of that matrix, and then - * converts the result back to a real matrix. - */ -template <typename MatrixType> -struct matrix_function_compute<MatrixType, 0> -{ - template <typename MatA, typename AtomicType, typename ResultType> - static void run(const MatA& A, AtomicType& atomic, ResultType &result) - { - typedef internal::traits<MatrixType> Traits; - typedef typename Traits::Scalar Scalar; - static const int Rows = Traits::RowsAtCompileTime, Cols = Traits::ColsAtCompileTime; - static const int MaxRows = Traits::MaxRowsAtCompileTime, MaxCols = Traits::MaxColsAtCompileTime; - - typedef std::complex<Scalar> ComplexScalar; - typedef Matrix<ComplexScalar, Rows, Cols, 0, MaxRows, MaxCols> ComplexMatrix; - - ComplexMatrix CA = A.template cast<ComplexScalar>(); - ComplexMatrix Cresult; - matrix_function_compute<ComplexMatrix>::run(CA, atomic, Cresult); - result = Cresult.real(); - } -}; - -/** \internal \ingroup MatrixFunctions_Module - * \brief Partial specialization of MatrixFunction for complex matrices - */ -template <typename MatrixType> -struct matrix_function_compute<MatrixType, 1> -{ - template <typename MatA, typename AtomicType, typename ResultType> - static void run(const MatA& A, AtomicType& atomic, ResultType &result) - { - typedef internal::traits<MatrixType> Traits; - - // compute Schur decomposition of A - const ComplexSchur<MatrixType> schurOfA(A); - eigen_assert(schurOfA.info()==Success); - MatrixType T = schurOfA.matrixT(); - MatrixType U = schurOfA.matrixU(); - - // partition eigenvalues into clusters of ei'vals "close" to each other - std::list<std::list<Index> > clusters; - matrix_function_partition_eigenvalues(T.diagonal(), clusters); - - // compute size of each cluster - Matrix<Index, Dynamic, 1> clusterSize; - matrix_function_compute_cluster_size(clusters, clusterSize); - - // blockStart[i] is row index at which block corresponding to i-th cluster starts - Matrix<Index, Dynamic, 1> blockStart; - matrix_function_compute_block_start(clusterSize, blockStart); - - // compute map so that eivalToCluster[i] = j means that i-th ei'val is in j-th cluster - Matrix<Index, Dynamic, 1> eivalToCluster; - matrix_function_compute_map(T.diagonal(), clusters, eivalToCluster); - - // compute permutation which groups ei'vals in same cluster together - Matrix<Index, Traits::RowsAtCompileTime, 1> permutation; - matrix_function_compute_permutation(blockStart, eivalToCluster, permutation); - - // permute Schur decomposition - matrix_function_permute_schur(permutation, U, T); - - // compute result - MatrixType fT; // matrix function applied to T - matrix_function_compute_block_atomic(T, atomic, blockStart, clusterSize, fT); - matrix_function_compute_above_diagonal(T, blockStart, clusterSize, fT); - result = U * (fT.template triangularView<Upper>() * U.adjoint()); - } -}; - -} // end of namespace internal - -/** \ingroup MatrixFunctions_Module - * - * \brief Proxy for the matrix function of some matrix (expression). - * - * \tparam Derived Type of the argument to the matrix function. - * - * This class holds the argument to the matrix function until it is assigned or evaluated for some other - * reason (so the argument should not be changed in the meantime). It is the return type of - * matrixBase::matrixFunction() and related functions and most of the time this is the only way it is used. - */ -template<typename Derived> class MatrixFunctionReturnValue -: public ReturnByValue<MatrixFunctionReturnValue<Derived> > -{ - public: - typedef typename Derived::Scalar Scalar; - typedef typename internal::stem_function<Scalar>::type StemFunction; - - protected: - typedef typename internal::ref_selector<Derived>::type DerivedNested; - - public: - - /** \brief Constructor. - * - * \param[in] A %Matrix (expression) forming the argument of the matrix function. - * \param[in] f Stem function for matrix function under consideration. - */ - MatrixFunctionReturnValue(const Derived& A, StemFunction f) : m_A(A), m_f(f) { } - - /** \brief Compute the matrix function. - * - * \param[out] result \p f applied to \p A, where \p f and \p A are as in the constructor. - */ - template <typename ResultType> - inline void evalTo(ResultType& result) const - { - typedef typename internal::nested_eval<Derived, 10>::type NestedEvalType; - typedef typename internal::remove_all<NestedEvalType>::type NestedEvalTypeClean; - typedef internal::traits<NestedEvalTypeClean> Traits; - typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar; - typedef Matrix<ComplexScalar, Dynamic, Dynamic, 0, Traits::RowsAtCompileTime, Traits::ColsAtCompileTime> DynMatrixType; - - typedef internal::MatrixFunctionAtomic<DynMatrixType> AtomicType; - AtomicType atomic(m_f); - - internal::matrix_function_compute<typename NestedEvalTypeClean::PlainObject>::run(m_A, atomic, result); - } - - Index rows() const { return m_A.rows(); } - Index cols() const { return m_A.cols(); } - - private: - const DerivedNested m_A; - StemFunction *m_f; -}; - -namespace internal { -template<typename Derived> -struct traits<MatrixFunctionReturnValue<Derived> > -{ - typedef typename Derived::PlainObject ReturnType; -}; -} - - -/********** MatrixBase methods **********/ - - -template <typename Derived> -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::matrixFunction(typename internal::stem_function<typename internal::traits<Derived>::Scalar>::type f) const -{ - eigen_assert(rows() == cols()); - return MatrixFunctionReturnValue<Derived>(derived(), f); -} - -template <typename Derived> -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::sin() const -{ - eigen_assert(rows() == cols()); - typedef typename internal::stem_function<Scalar>::ComplexScalar ComplexScalar; - return MatrixFunctionReturnValue<Derived>(derived(), internal::stem_function_sin<ComplexScalar>); -} - -template <typename Derived> -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::cos() const -{ - eigen_assert(rows() == cols()); - typedef typename internal::stem_function<Scalar>::ComplexScalar ComplexScalar; - return MatrixFunctionReturnValue<Derived>(derived(), internal::stem_function_cos<ComplexScalar>); -} - -template <typename Derived> -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::sinh() const -{ - eigen_assert(rows() == cols()); - typedef typename internal::stem_function<Scalar>::ComplexScalar ComplexScalar; - return MatrixFunctionReturnValue<Derived>(derived(), internal::stem_function_sinh<ComplexScalar>); -} - -template <typename Derived> -const MatrixFunctionReturnValue<Derived> MatrixBase<Derived>::cosh() const -{ - eigen_assert(rows() == cols()); - typedef typename internal::stem_function<Scalar>::ComplexScalar ComplexScalar; - return MatrixFunctionReturnValue<Derived>(derived(), internal::stem_function_cosh<ComplexScalar>); -} - -} // end namespace Eigen - -#endif // EIGEN_MATRIX_FUNCTION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h b/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h deleted file mode 100644 index e917013e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h +++ /dev/null @@ -1,373 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk> -// Copyright (C) 2011 Chen-Pang He <jdh8@ms63.hinet.net> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIX_LOGARITHM -#define EIGEN_MATRIX_LOGARITHM - -namespace Eigen { - -namespace internal { - -template <typename Scalar> -struct matrix_log_min_pade_degree -{ - static const int value = 3; -}; - -template <typename Scalar> -struct matrix_log_max_pade_degree -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - static const int value = std::numeric_limits<RealScalar>::digits<= 24? 5: // single precision - std::numeric_limits<RealScalar>::digits<= 53? 7: // double precision - std::numeric_limits<RealScalar>::digits<= 64? 8: // extended precision - std::numeric_limits<RealScalar>::digits<=106? 10: // double-double - 11; // quadruple precision -}; - -/** \brief Compute logarithm of 2x2 triangular matrix. */ -template <typename MatrixType> -void matrix_log_compute_2x2(const MatrixType& A, MatrixType& result) -{ - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - using std::abs; - using std::ceil; - using std::imag; - using std::log; - - Scalar logA00 = log(A(0,0)); - Scalar logA11 = log(A(1,1)); - - result(0,0) = logA00; - result(1,0) = Scalar(0); - result(1,1) = logA11; - - Scalar y = A(1,1) - A(0,0); - if (y==Scalar(0)) - { - result(0,1) = A(0,1) / A(0,0); - } - else if ((abs(A(0,0)) < RealScalar(0.5)*abs(A(1,1))) || (abs(A(0,0)) > 2*abs(A(1,1)))) - { - result(0,1) = A(0,1) * (logA11 - logA00) / y; - } - else - { - // computation in previous branch is inaccurate if A(1,1) \approx A(0,0) - RealScalar unwindingNumber = ceil((imag(logA11 - logA00) - RealScalar(EIGEN_PI)) / RealScalar(2*EIGEN_PI)); - result(0,1) = A(0,1) * (numext::log1p(y/A(0,0)) + Scalar(0,RealScalar(2*EIGEN_PI)*unwindingNumber)) / y; - } -} - -/* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = float) */ -inline int matrix_log_get_pade_degree(float normTminusI) -{ - const float maxNormForPade[] = { 2.5111573934555054e-1 /* degree = 3 */ , 4.0535837411880493e-1, - 5.3149729967117310e-1 }; - const int minPadeDegree = matrix_log_min_pade_degree<float>::value; - const int maxPadeDegree = matrix_log_max_pade_degree<float>::value; - int degree = minPadeDegree; - for (; degree <= maxPadeDegree; ++degree) - if (normTminusI <= maxNormForPade[degree - minPadeDegree]) - break; - return degree; -} - -/* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = double) */ -inline int matrix_log_get_pade_degree(double normTminusI) -{ - const double maxNormForPade[] = { 1.6206284795015624e-2 /* degree = 3 */ , 5.3873532631381171e-2, - 1.1352802267628681e-1, 1.8662860613541288e-1, 2.642960831111435e-1 }; - const int minPadeDegree = matrix_log_min_pade_degree<double>::value; - const int maxPadeDegree = matrix_log_max_pade_degree<double>::value; - int degree = minPadeDegree; - for (; degree <= maxPadeDegree; ++degree) - if (normTminusI <= maxNormForPade[degree - minPadeDegree]) - break; - return degree; -} - -/* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = long double) */ -inline int matrix_log_get_pade_degree(long double normTminusI) -{ -#if LDBL_MANT_DIG == 53 // double precision - const long double maxNormForPade[] = { 1.6206284795015624e-2L /* degree = 3 */ , 5.3873532631381171e-2L, - 1.1352802267628681e-1L, 1.8662860613541288e-1L, 2.642960831111435e-1L }; -#elif LDBL_MANT_DIG <= 64 // extended precision - const long double maxNormForPade[] = { 5.48256690357782863103e-3L /* degree = 3 */, 2.34559162387971167321e-2L, - 5.84603923897347449857e-2L, 1.08486423756725170223e-1L, 1.68385767881294446649e-1L, - 2.32777776523703892094e-1L }; -#elif LDBL_MANT_DIG <= 106 // double-double - const long double maxNormForPade[] = { 8.58970550342939562202529664318890e-5L /* degree = 3 */, - 9.34074328446359654039446552677759e-4L, 4.26117194647672175773064114582860e-3L, - 1.21546224740281848743149666560464e-2L, 2.61100544998339436713088248557444e-2L, - 4.66170074627052749243018566390567e-2L, 7.32585144444135027565872014932387e-2L, - 1.05026503471351080481093652651105e-1L }; -#else // quadruple precision - const long double maxNormForPade[] = { 4.7419931187193005048501568167858103e-5L /* degree = 3 */, - 5.8853168473544560470387769480192666e-4L, 2.9216120366601315391789493628113520e-3L, - 8.8415758124319434347116734705174308e-3L, 1.9850836029449446668518049562565291e-2L, - 3.6688019729653446926585242192447447e-2L, 5.9290962294020186998954055264528393e-2L, - 8.6998436081634343903250580992127677e-2L, 1.1880960220216759245467951592883642e-1L }; -#endif - const int minPadeDegree = matrix_log_min_pade_degree<long double>::value; - const int maxPadeDegree = matrix_log_max_pade_degree<long double>::value; - int degree = minPadeDegree; - for (; degree <= maxPadeDegree; ++degree) - if (normTminusI <= maxNormForPade[degree - minPadeDegree]) - break; - return degree; -} - -/* \brief Compute Pade approximation to matrix logarithm */ -template <typename MatrixType> -void matrix_log_compute_pade(MatrixType& result, const MatrixType& T, int degree) -{ - typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; - const int minPadeDegree = 3; - const int maxPadeDegree = 11; - assert(degree >= minPadeDegree && degree <= maxPadeDegree); - // FIXME this creates float-conversion-warnings if these are enabled. - // Either manually convert each value, or disable the warning locally - const RealScalar nodes[][maxPadeDegree] = { - { 0.1127016653792583114820734600217600L, 0.5000000000000000000000000000000000L, // degree 3 - 0.8872983346207416885179265399782400L }, - { 0.0694318442029737123880267555535953L, 0.3300094782075718675986671204483777L, // degree 4 - 0.6699905217924281324013328795516223L, 0.9305681557970262876119732444464048L }, - { 0.0469100770306680036011865608503035L, 0.2307653449471584544818427896498956L, // degree 5 - 0.5000000000000000000000000000000000L, 0.7692346550528415455181572103501044L, - 0.9530899229693319963988134391496965L }, - { 0.0337652428984239860938492227530027L, 0.1693953067668677431693002024900473L, // degree 6 - 0.3806904069584015456847491391596440L, 0.6193095930415984543152508608403560L, - 0.8306046932331322568306997975099527L, 0.9662347571015760139061507772469973L }, - { 0.0254460438286207377369051579760744L, 0.1292344072003027800680676133596058L, // degree 7 - 0.2970774243113014165466967939615193L, 0.5000000000000000000000000000000000L, - 0.7029225756886985834533032060384807L, 0.8707655927996972199319323866403942L, - 0.9745539561713792622630948420239256L }, - { 0.0198550717512318841582195657152635L, 0.1016667612931866302042230317620848L, // degree 8 - 0.2372337950418355070911304754053768L, 0.4082826787521750975302619288199080L, - 0.5917173212478249024697380711800920L, 0.7627662049581644929088695245946232L, - 0.8983332387068133697957769682379152L, 0.9801449282487681158417804342847365L }, - { 0.0159198802461869550822118985481636L, 0.0819844463366821028502851059651326L, // degree 9 - 0.1933142836497048013456489803292629L, 0.3378732882980955354807309926783317L, - 0.5000000000000000000000000000000000L, 0.6621267117019044645192690073216683L, - 0.8066857163502951986543510196707371L, 0.9180155536633178971497148940348674L, - 0.9840801197538130449177881014518364L }, - { 0.0130467357414141399610179939577740L, 0.0674683166555077446339516557882535L, // degree 10 - 0.1602952158504877968828363174425632L, 0.2833023029353764046003670284171079L, - 0.4255628305091843945575869994351400L, 0.5744371694908156054424130005648600L, - 0.7166976970646235953996329715828921L, 0.8397047841495122031171636825574368L, - 0.9325316833444922553660483442117465L, 0.9869532642585858600389820060422260L }, - { 0.0108856709269715035980309994385713L, 0.0564687001159523504624211153480364L, // degree 11 - 0.1349239972129753379532918739844233L, 0.2404519353965940920371371652706952L, - 0.3652284220238275138342340072995692L, 0.5000000000000000000000000000000000L, - 0.6347715779761724861657659927004308L, 0.7595480646034059079628628347293048L, - 0.8650760027870246620467081260155767L, 0.9435312998840476495375788846519636L, - 0.9891143290730284964019690005614287L } }; - - const RealScalar weights[][maxPadeDegree] = { - { 0.2777777777777777777777777777777778L, 0.4444444444444444444444444444444444L, // degree 3 - 0.2777777777777777777777777777777778L }, - { 0.1739274225687269286865319746109997L, 0.3260725774312730713134680253890003L, // degree 4 - 0.3260725774312730713134680253890003L, 0.1739274225687269286865319746109997L }, - { 0.1184634425280945437571320203599587L, 0.2393143352496832340206457574178191L, // degree 5 - 0.2844444444444444444444444444444444L, 0.2393143352496832340206457574178191L, - 0.1184634425280945437571320203599587L }, - { 0.0856622461895851725201480710863665L, 0.1803807865240693037849167569188581L, // degree 6 - 0.2339569672863455236949351719947755L, 0.2339569672863455236949351719947755L, - 0.1803807865240693037849167569188581L, 0.0856622461895851725201480710863665L }, - { 0.0647424830844348466353057163395410L, 0.1398526957446383339507338857118898L, // degree 7 - 0.1909150252525594724751848877444876L, 0.2089795918367346938775510204081633L, - 0.1909150252525594724751848877444876L, 0.1398526957446383339507338857118898L, - 0.0647424830844348466353057163395410L }, - { 0.0506142681451881295762656771549811L, 0.1111905172266872352721779972131204L, // degree 8 - 0.1568533229389436436689811009933007L, 0.1813418916891809914825752246385978L, - 0.1813418916891809914825752246385978L, 0.1568533229389436436689811009933007L, - 0.1111905172266872352721779972131204L, 0.0506142681451881295762656771549811L }, - { 0.0406371941807872059859460790552618L, 0.0903240803474287020292360156214564L, // degree 9 - 0.1303053482014677311593714347093164L, 0.1561735385200014200343152032922218L, - 0.1651196775006298815822625346434870L, 0.1561735385200014200343152032922218L, - 0.1303053482014677311593714347093164L, 0.0903240803474287020292360156214564L, - 0.0406371941807872059859460790552618L }, - { 0.0333356721543440687967844049466659L, 0.0747256745752902965728881698288487L, // degree 10 - 0.1095431812579910219977674671140816L, 0.1346333596549981775456134607847347L, - 0.1477621123573764350869464973256692L, 0.1477621123573764350869464973256692L, - 0.1346333596549981775456134607847347L, 0.1095431812579910219977674671140816L, - 0.0747256745752902965728881698288487L, 0.0333356721543440687967844049466659L }, - { 0.0278342835580868332413768602212743L, 0.0627901847324523123173471496119701L, // degree 11 - 0.0931451054638671257130488207158280L, 0.1165968822959952399592618524215876L, - 0.1314022722551233310903444349452546L, 0.1364625433889503153572417641681711L, - 0.1314022722551233310903444349452546L, 0.1165968822959952399592618524215876L, - 0.0931451054638671257130488207158280L, 0.0627901847324523123173471496119701L, - 0.0278342835580868332413768602212743L } }; - - MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); - result.setZero(T.rows(), T.rows()); - for (int k = 0; k < degree; ++k) { - RealScalar weight = weights[degree-minPadeDegree][k]; - RealScalar node = nodes[degree-minPadeDegree][k]; - result += weight * (MatrixType::Identity(T.rows(), T.rows()) + node * TminusI) - .template triangularView<Upper>().solve(TminusI); - } -} - -/** \brief Compute logarithm of triangular matrices with size > 2. - * \details This uses a inverse scale-and-square algorithm. */ -template <typename MatrixType> -void matrix_log_compute_big(const MatrixType& A, MatrixType& result) -{ - typedef typename MatrixType::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - using std::pow; - - int numberOfSquareRoots = 0; - int numberOfExtraSquareRoots = 0; - int degree; - MatrixType T = A, sqrtT; - - const int maxPadeDegree = matrix_log_max_pade_degree<Scalar>::value; - const RealScalar maxNormForPade = RealScalar( - maxPadeDegree<= 5? 5.3149729967117310e-1L: // single precision - maxPadeDegree<= 7? 2.6429608311114350e-1L: // double precision - maxPadeDegree<= 8? 2.32777776523703892094e-1L: // extended precision - maxPadeDegree<=10? 1.05026503471351080481093652651105e-1L: // double-double - 1.1880960220216759245467951592883642e-1L); // quadruple precision - - while (true) { - RealScalar normTminusI = (T - MatrixType::Identity(T.rows(), T.rows())).cwiseAbs().colwise().sum().maxCoeff(); - if (normTminusI < maxNormForPade) { - degree = matrix_log_get_pade_degree(normTminusI); - int degree2 = matrix_log_get_pade_degree(normTminusI / RealScalar(2)); - if ((degree - degree2 <= 1) || (numberOfExtraSquareRoots == 1)) - break; - ++numberOfExtraSquareRoots; - } - matrix_sqrt_triangular(T, sqrtT); - T = sqrtT.template triangularView<Upper>(); - ++numberOfSquareRoots; - } - - matrix_log_compute_pade(result, T, degree); - result *= pow(RealScalar(2), RealScalar(numberOfSquareRoots)); // TODO replace by bitshift if possible -} - -/** \ingroup MatrixFunctions_Module - * \class MatrixLogarithmAtomic - * \brief Helper class for computing matrix logarithm of atomic matrices. - * - * Here, an atomic matrix is a triangular matrix whose diagonal entries are close to each other. - * - * \sa class MatrixFunctionAtomic, MatrixBase::log() - */ -template <typename MatrixType> -class MatrixLogarithmAtomic -{ -public: - /** \brief Compute matrix logarithm of atomic matrix - * \param[in] A argument of matrix logarithm, should be upper triangular and atomic - * \returns The logarithm of \p A. - */ - MatrixType compute(const MatrixType& A); -}; - -template <typename MatrixType> -MatrixType MatrixLogarithmAtomic<MatrixType>::compute(const MatrixType& A) -{ - using std::log; - MatrixType result(A.rows(), A.rows()); - if (A.rows() == 1) - result(0,0) = log(A(0,0)); - else if (A.rows() == 2) - matrix_log_compute_2x2(A, result); - else - matrix_log_compute_big(A, result); - return result; -} - -} // end of namespace internal - -/** \ingroup MatrixFunctions_Module - * - * \brief Proxy for the matrix logarithm of some matrix (expression). - * - * \tparam Derived Type of the argument to the matrix function. - * - * This class holds the argument to the matrix function until it is - * assigned or evaluated for some other reason (so the argument - * should not be changed in the meantime). It is the return type of - * MatrixBase::log() and most of the time this is the only way it - * is used. - */ -template<typename Derived> class MatrixLogarithmReturnValue -: public ReturnByValue<MatrixLogarithmReturnValue<Derived> > -{ -public: - typedef typename Derived::Scalar Scalar; - typedef typename Derived::Index Index; - -protected: - typedef typename internal::ref_selector<Derived>::type DerivedNested; - -public: - - /** \brief Constructor. - * - * \param[in] A %Matrix (expression) forming the argument of the matrix logarithm. - */ - explicit MatrixLogarithmReturnValue(const Derived& A) : m_A(A) { } - - /** \brief Compute the matrix logarithm. - * - * \param[out] result Logarithm of \c A, where \c A is as specified in the constructor. - */ - template <typename ResultType> - inline void evalTo(ResultType& result) const - { - typedef typename internal::nested_eval<Derived, 10>::type DerivedEvalType; - typedef typename internal::remove_all<DerivedEvalType>::type DerivedEvalTypeClean; - typedef internal::traits<DerivedEvalTypeClean> Traits; - typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar; - typedef Matrix<ComplexScalar, Dynamic, Dynamic, 0, Traits::RowsAtCompileTime, Traits::ColsAtCompileTime> DynMatrixType; - typedef internal::MatrixLogarithmAtomic<DynMatrixType> AtomicType; - AtomicType atomic; - - internal::matrix_function_compute<typename DerivedEvalTypeClean::PlainObject>::run(m_A, atomic, result); - } - - Index rows() const { return m_A.rows(); } - Index cols() const { return m_A.cols(); } - -private: - const DerivedNested m_A; -}; - -namespace internal { - template<typename Derived> - struct traits<MatrixLogarithmReturnValue<Derived> > - { - typedef typename Derived::PlainObject ReturnType; - }; -} - - -/********** MatrixBase method **********/ - - -template <typename Derived> -const MatrixLogarithmReturnValue<Derived> MatrixBase<Derived>::log() const -{ - eigen_assert(rows() == cols()); - return MatrixLogarithmReturnValue<Derived>(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_MATRIX_LOGARITHM diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h b/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h deleted file mode 100644 index d7672d7c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h +++ /dev/null @@ -1,705 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012, 2013 Chen-Pang He <jdh8@ms63.hinet.net> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIX_POWER -#define EIGEN_MATRIX_POWER - -namespace Eigen { - -template<typename MatrixType> class MatrixPower; - -/** - * \ingroup MatrixFunctions_Module - * - * \brief Proxy for the matrix power of some matrix. - * - * \tparam MatrixType type of the base, a matrix. - * - * This class holds the arguments to the matrix power until it is - * assigned or evaluated for some other reason (so the argument - * should not be changed in the meantime). It is the return type of - * MatrixPower::operator() and related functions and most of the - * time this is the only way it is used. - */ -/* TODO This class is only used by MatrixPower, so it should be nested - * into MatrixPower, like MatrixPower::ReturnValue. However, my - * compiler complained about unused template parameter in the - * following declaration in namespace internal. - * - * template<typename MatrixType> - * struct traits<MatrixPower<MatrixType>::ReturnValue>; - */ -template<typename MatrixType> -class MatrixPowerParenthesesReturnValue : public ReturnByValue< MatrixPowerParenthesesReturnValue<MatrixType> > -{ - public: - typedef typename MatrixType::RealScalar RealScalar; - - /** - * \brief Constructor. - * - * \param[in] pow %MatrixPower storing the base. - * \param[in] p scalar, the exponent of the matrix power. - */ - MatrixPowerParenthesesReturnValue(MatrixPower<MatrixType>& pow, RealScalar p) : m_pow(pow), m_p(p) - { } - - /** - * \brief Compute the matrix power. - * - * \param[out] result - */ - template<typename ResultType> - inline void evalTo(ResultType& result) const - { m_pow.compute(result, m_p); } - - Index rows() const { return m_pow.rows(); } - Index cols() const { return m_pow.cols(); } - - private: - MatrixPower<MatrixType>& m_pow; - const RealScalar m_p; -}; - -/** - * \ingroup MatrixFunctions_Module - * - * \brief Class for computing matrix powers. - * - * \tparam MatrixType type of the base, expected to be an instantiation - * of the Matrix class template. - * - * This class is capable of computing triangular real/complex matrices - * raised to a power in the interval \f$ (-1, 1) \f$. - * - * \note Currently this class is only used by MatrixPower. One may - * insist that this be nested into MatrixPower. This class is here to - * facilitate future development of triangular matrix functions. - */ -template<typename MatrixType> -class MatrixPowerAtomic : internal::noncopyable -{ - private: - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime - }; - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - typedef std::complex<RealScalar> ComplexScalar; - typedef Block<MatrixType,Dynamic,Dynamic> ResultType; - - const MatrixType& m_A; - RealScalar m_p; - - void computePade(int degree, const MatrixType& IminusT, ResultType& res) const; - void compute2x2(ResultType& res, RealScalar p) const; - void computeBig(ResultType& res) const; - static int getPadeDegree(float normIminusT); - static int getPadeDegree(double normIminusT); - static int getPadeDegree(long double normIminusT); - static ComplexScalar computeSuperDiag(const ComplexScalar&, const ComplexScalar&, RealScalar p); - static RealScalar computeSuperDiag(RealScalar, RealScalar, RealScalar p); - - public: - /** - * \brief Constructor. - * - * \param[in] T the base of the matrix power. - * \param[in] p the exponent of the matrix power, should be in - * \f$ (-1, 1) \f$. - * - * The class stores a reference to T, so it should not be changed - * (or destroyed) before evaluation. Only the upper triangular - * part of T is read. - */ - MatrixPowerAtomic(const MatrixType& T, RealScalar p); - - /** - * \brief Compute the matrix power. - * - * \param[out] res \f$ A^p \f$ where A and p are specified in the - * constructor. - */ - void compute(ResultType& res) const; -}; - -template<typename MatrixType> -MatrixPowerAtomic<MatrixType>::MatrixPowerAtomic(const MatrixType& T, RealScalar p) : - m_A(T), m_p(p) -{ - eigen_assert(T.rows() == T.cols()); - eigen_assert(p > -1 && p < 1); -} - -template<typename MatrixType> -void MatrixPowerAtomic<MatrixType>::compute(ResultType& res) const -{ - using std::pow; - switch (m_A.rows()) { - case 0: - break; - case 1: - res(0,0) = pow(m_A(0,0), m_p); - break; - case 2: - compute2x2(res, m_p); - break; - default: - computeBig(res); - } -} - -template<typename MatrixType> -void MatrixPowerAtomic<MatrixType>::computePade(int degree, const MatrixType& IminusT, ResultType& res) const -{ - int i = 2*degree; - res = (m_p-RealScalar(degree)) / RealScalar(2*i-2) * IminusT; - - for (--i; i; --i) { - res = (MatrixType::Identity(IminusT.rows(), IminusT.cols()) + res).template triangularView<Upper>() - .solve((i==1 ? -m_p : i&1 ? (-m_p-RealScalar(i/2))/RealScalar(2*i) : (m_p-RealScalar(i/2))/RealScalar(2*i-2)) * IminusT).eval(); - } - res += MatrixType::Identity(IminusT.rows(), IminusT.cols()); -} - -// This function assumes that res has the correct size (see bug 614) -template<typename MatrixType> -void MatrixPowerAtomic<MatrixType>::compute2x2(ResultType& res, RealScalar p) const -{ - using std::abs; - using std::pow; - res.coeffRef(0,0) = pow(m_A.coeff(0,0), p); - - for (Index i=1; i < m_A.cols(); ++i) { - res.coeffRef(i,i) = pow(m_A.coeff(i,i), p); - if (m_A.coeff(i-1,i-1) == m_A.coeff(i,i)) - res.coeffRef(i-1,i) = p * pow(m_A.coeff(i,i), p-1); - else if (2*abs(m_A.coeff(i-1,i-1)) < abs(m_A.coeff(i,i)) || 2*abs(m_A.coeff(i,i)) < abs(m_A.coeff(i-1,i-1))) - res.coeffRef(i-1,i) = (res.coeff(i,i)-res.coeff(i-1,i-1)) / (m_A.coeff(i,i)-m_A.coeff(i-1,i-1)); - else - res.coeffRef(i-1,i) = computeSuperDiag(m_A.coeff(i,i), m_A.coeff(i-1,i-1), p); - res.coeffRef(i-1,i) *= m_A.coeff(i-1,i); - } -} - -template<typename MatrixType> -void MatrixPowerAtomic<MatrixType>::computeBig(ResultType& res) const -{ - using std::ldexp; - const int digits = std::numeric_limits<RealScalar>::digits; - const RealScalar maxNormForPade = RealScalar( - digits <= 24? 4.3386528e-1L // single precision - : digits <= 53? 2.789358995219730e-1L // double precision - : digits <= 64? 2.4471944416607995472e-1L // extended precision - : digits <= 106? 1.1016843812851143391275867258512e-1L // double-double - : 9.134603732914548552537150753385375e-2L); // quadruple precision - MatrixType IminusT, sqrtT, T = m_A.template triangularView<Upper>(); - RealScalar normIminusT; - int degree, degree2, numberOfSquareRoots = 0; - bool hasExtraSquareRoot = false; - - for (Index i=0; i < m_A.cols(); ++i) - eigen_assert(m_A(i,i) != RealScalar(0)); - - while (true) { - IminusT = MatrixType::Identity(m_A.rows(), m_A.cols()) - T; - normIminusT = IminusT.cwiseAbs().colwise().sum().maxCoeff(); - if (normIminusT < maxNormForPade) { - degree = getPadeDegree(normIminusT); - degree2 = getPadeDegree(normIminusT/2); - if (degree - degree2 <= 1 || hasExtraSquareRoot) - break; - hasExtraSquareRoot = true; - } - matrix_sqrt_triangular(T, sqrtT); - T = sqrtT.template triangularView<Upper>(); - ++numberOfSquareRoots; - } - computePade(degree, IminusT, res); - - for (; numberOfSquareRoots; --numberOfSquareRoots) { - compute2x2(res, ldexp(m_p, -numberOfSquareRoots)); - res = res.template triangularView<Upper>() * res; - } - compute2x2(res, m_p); -} - -template<typename MatrixType> -inline int MatrixPowerAtomic<MatrixType>::getPadeDegree(float normIminusT) -{ - const float maxNormForPade[] = { 2.8064004e-1f /* degree = 3 */ , 4.3386528e-1f }; - int degree = 3; - for (; degree <= 4; ++degree) - if (normIminusT <= maxNormForPade[degree - 3]) - break; - return degree; -} - -template<typename MatrixType> -inline int MatrixPowerAtomic<MatrixType>::getPadeDegree(double normIminusT) -{ - const double maxNormForPade[] = { 1.884160592658218e-2 /* degree = 3 */ , 6.038881904059573e-2, 1.239917516308172e-1, - 1.999045567181744e-1, 2.789358995219730e-1 }; - int degree = 3; - for (; degree <= 7; ++degree) - if (normIminusT <= maxNormForPade[degree - 3]) - break; - return degree; -} - -template<typename MatrixType> -inline int MatrixPowerAtomic<MatrixType>::getPadeDegree(long double normIminusT) -{ -#if LDBL_MANT_DIG == 53 - const int maxPadeDegree = 7; - const double maxNormForPade[] = { 1.884160592658218e-2L /* degree = 3 */ , 6.038881904059573e-2L, 1.239917516308172e-1L, - 1.999045567181744e-1L, 2.789358995219730e-1L }; -#elif LDBL_MANT_DIG <= 64 - const int maxPadeDegree = 8; - const long double maxNormForPade[] = { 6.3854693117491799460e-3L /* degree = 3 */ , 2.6394893435456973676e-2L, - 6.4216043030404063729e-2L, 1.1701165502926694307e-1L, 1.7904284231268670284e-1L, 2.4471944416607995472e-1L }; -#elif LDBL_MANT_DIG <= 106 - const int maxPadeDegree = 10; - const double maxNormForPade[] = { 1.0007161601787493236741409687186e-4L /* degree = 3 */ , - 1.0007161601787493236741409687186e-3L, 4.7069769360887572939882574746264e-3L, 1.3220386624169159689406653101695e-2L, - 2.8063482381631737920612944054906e-2L, 4.9625993951953473052385361085058e-2L, 7.7367040706027886224557538328171e-2L, - 1.1016843812851143391275867258512e-1L }; -#else - const int maxPadeDegree = 10; - const double maxNormForPade[] = { 5.524506147036624377378713555116378e-5L /* degree = 3 */ , - 6.640600568157479679823602193345995e-4L, 3.227716520106894279249709728084626e-3L, - 9.619593944683432960546978734646284e-3L, 2.134595382433742403911124458161147e-2L, - 3.908166513900489428442993794761185e-2L, 6.266780814639442865832535460550138e-2L, - 9.134603732914548552537150753385375e-2L }; -#endif - int degree = 3; - for (; degree <= maxPadeDegree; ++degree) - if (normIminusT <= maxNormForPade[degree - 3]) - break; - return degree; -} - -template<typename MatrixType> -inline typename MatrixPowerAtomic<MatrixType>::ComplexScalar -MatrixPowerAtomic<MatrixType>::computeSuperDiag(const ComplexScalar& curr, const ComplexScalar& prev, RealScalar p) -{ - using std::ceil; - using std::exp; - using std::log; - using std::sinh; - - ComplexScalar logCurr = log(curr); - ComplexScalar logPrev = log(prev); - RealScalar unwindingNumber = ceil((numext::imag(logCurr - logPrev) - RealScalar(EIGEN_PI)) / RealScalar(2*EIGEN_PI)); - ComplexScalar w = numext::log1p((curr-prev)/prev)/RealScalar(2) + ComplexScalar(0, RealScalar(EIGEN_PI)*unwindingNumber); - return RealScalar(2) * exp(RealScalar(0.5) * p * (logCurr + logPrev)) * sinh(p * w) / (curr - prev); -} - -template<typename MatrixType> -inline typename MatrixPowerAtomic<MatrixType>::RealScalar -MatrixPowerAtomic<MatrixType>::computeSuperDiag(RealScalar curr, RealScalar prev, RealScalar p) -{ - using std::exp; - using std::log; - using std::sinh; - - RealScalar w = numext::log1p((curr-prev)/prev)/RealScalar(2); - return 2 * exp(p * (log(curr) + log(prev)) / 2) * sinh(p * w) / (curr - prev); -} - -/** - * \ingroup MatrixFunctions_Module - * - * \brief Class for computing matrix powers. - * - * \tparam MatrixType type of the base, expected to be an instantiation - * of the Matrix class template. - * - * This class is capable of computing real/complex matrices raised to - * an arbitrary real power. Meanwhile, it saves the result of Schur - * decomposition if an non-integral power has even been calculated. - * Therefore, if you want to compute multiple (>= 2) matrix powers - * for the same matrix, using the class directly is more efficient than - * calling MatrixBase::pow(). - * - * Example: - * \include MatrixPower_optimal.cpp - * Output: \verbinclude MatrixPower_optimal.out - */ -template<typename MatrixType> -class MatrixPower : internal::noncopyable -{ - private: - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::RealScalar RealScalar; - - public: - /** - * \brief Constructor. - * - * \param[in] A the base of the matrix power. - * - * The class stores a reference to A, so it should not be changed - * (or destroyed) before evaluation. - */ - explicit MatrixPower(const MatrixType& A) : - m_A(A), - m_conditionNumber(0), - m_rank(A.cols()), - m_nulls(0) - { eigen_assert(A.rows() == A.cols()); } - - /** - * \brief Returns the matrix power. - * - * \param[in] p exponent, a real scalar. - * \return The expression \f$ A^p \f$, where A is specified in the - * constructor. - */ - const MatrixPowerParenthesesReturnValue<MatrixType> operator()(RealScalar p) - { return MatrixPowerParenthesesReturnValue<MatrixType>(*this, p); } - - /** - * \brief Compute the matrix power. - * - * \param[in] p exponent, a real scalar. - * \param[out] res \f$ A^p \f$ where A is specified in the - * constructor. - */ - template<typename ResultType> - void compute(ResultType& res, RealScalar p); - - Index rows() const { return m_A.rows(); } - Index cols() const { return m_A.cols(); } - - private: - typedef std::complex<RealScalar> ComplexScalar; - typedef Matrix<ComplexScalar, Dynamic, Dynamic, 0, - MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime> ComplexMatrix; - - /** \brief Reference to the base of matrix power. */ - typename MatrixType::Nested m_A; - - /** \brief Temporary storage. */ - MatrixType m_tmp; - - /** \brief Store the result of Schur decomposition. */ - ComplexMatrix m_T, m_U; - - /** \brief Store fractional power of m_T. */ - ComplexMatrix m_fT; - - /** - * \brief Condition number of m_A. - * - * It is initialized as 0 to avoid performing unnecessary Schur - * decomposition, which is the bottleneck. - */ - RealScalar m_conditionNumber; - - /** \brief Rank of m_A. */ - Index m_rank; - - /** \brief Rank deficiency of m_A. */ - Index m_nulls; - - /** - * \brief Split p into integral part and fractional part. - * - * \param[in] p The exponent. - * \param[out] p The fractional part ranging in \f$ (-1, 1) \f$. - * \param[out] intpart The integral part. - * - * Only if the fractional part is nonzero, it calls initialize(). - */ - void split(RealScalar& p, RealScalar& intpart); - - /** \brief Perform Schur decomposition for fractional power. */ - void initialize(); - - template<typename ResultType> - void computeIntPower(ResultType& res, RealScalar p); - - template<typename ResultType> - void computeFracPower(ResultType& res, RealScalar p); - - template<int Rows, int Cols, int Options, int MaxRows, int MaxCols> - static void revertSchur( - Matrix<ComplexScalar, Rows, Cols, Options, MaxRows, MaxCols>& res, - const ComplexMatrix& T, - const ComplexMatrix& U); - - template<int Rows, int Cols, int Options, int MaxRows, int MaxCols> - static void revertSchur( - Matrix<RealScalar, Rows, Cols, Options, MaxRows, MaxCols>& res, - const ComplexMatrix& T, - const ComplexMatrix& U); -}; - -template<typename MatrixType> -template<typename ResultType> -void MatrixPower<MatrixType>::compute(ResultType& res, RealScalar p) -{ - using std::pow; - switch (cols()) { - case 0: - break; - case 1: - res(0,0) = pow(m_A.coeff(0,0), p); - break; - default: - RealScalar intpart; - split(p, intpart); - - res = MatrixType::Identity(rows(), cols()); - computeIntPower(res, intpart); - if (p) computeFracPower(res, p); - } -} - -template<typename MatrixType> -void MatrixPower<MatrixType>::split(RealScalar& p, RealScalar& intpart) -{ - using std::floor; - using std::pow; - - intpart = floor(p); - p -= intpart; - - // Perform Schur decomposition if it is not yet performed and the power is - // not an integer. - if (!m_conditionNumber && p) - initialize(); - - // Choose the more stable of intpart = floor(p) and intpart = ceil(p). - if (p > RealScalar(0.5) && p > (1-p) * pow(m_conditionNumber, p)) { - --p; - ++intpart; - } -} - -template<typename MatrixType> -void MatrixPower<MatrixType>::initialize() -{ - const ComplexSchur<MatrixType> schurOfA(m_A); - JacobiRotation<ComplexScalar> rot; - ComplexScalar eigenvalue; - - m_fT.resizeLike(m_A); - m_T = schurOfA.matrixT(); - m_U = schurOfA.matrixU(); - m_conditionNumber = m_T.diagonal().array().abs().maxCoeff() / m_T.diagonal().array().abs().minCoeff(); - - // Move zero eigenvalues to the bottom right corner. - for (Index i = cols()-1; i>=0; --i) { - if (m_rank <= 2) - return; - if (m_T.coeff(i,i) == RealScalar(0)) { - for (Index j=i+1; j < m_rank; ++j) { - eigenvalue = m_T.coeff(j,j); - rot.makeGivens(m_T.coeff(j-1,j), eigenvalue); - m_T.applyOnTheRight(j-1, j, rot); - m_T.applyOnTheLeft(j-1, j, rot.adjoint()); - m_T.coeffRef(j-1,j-1) = eigenvalue; - m_T.coeffRef(j,j) = RealScalar(0); - m_U.applyOnTheRight(j-1, j, rot); - } - --m_rank; - } - } - - m_nulls = rows() - m_rank; - if (m_nulls) { - eigen_assert(m_T.bottomRightCorner(m_nulls, m_nulls).isZero() - && "Base of matrix power should be invertible or with a semisimple zero eigenvalue."); - m_fT.bottomRows(m_nulls).fill(RealScalar(0)); - } -} - -template<typename MatrixType> -template<typename ResultType> -void MatrixPower<MatrixType>::computeIntPower(ResultType& res, RealScalar p) -{ - using std::abs; - using std::fmod; - RealScalar pp = abs(p); - - if (p<0) - m_tmp = m_A.inverse(); - else - m_tmp = m_A; - - while (true) { - if (fmod(pp, 2) >= 1) - res = m_tmp * res; - pp /= 2; - if (pp < 1) - break; - m_tmp *= m_tmp; - } -} - -template<typename MatrixType> -template<typename ResultType> -void MatrixPower<MatrixType>::computeFracPower(ResultType& res, RealScalar p) -{ - Block<ComplexMatrix,Dynamic,Dynamic> blockTp(m_fT, 0, 0, m_rank, m_rank); - eigen_assert(m_conditionNumber); - eigen_assert(m_rank + m_nulls == rows()); - - MatrixPowerAtomic<ComplexMatrix>(m_T.topLeftCorner(m_rank, m_rank), p).compute(blockTp); - if (m_nulls) { - m_fT.topRightCorner(m_rank, m_nulls) = m_T.topLeftCorner(m_rank, m_rank).template triangularView<Upper>() - .solve(blockTp * m_T.topRightCorner(m_rank, m_nulls)); - } - revertSchur(m_tmp, m_fT, m_U); - res = m_tmp * res; -} - -template<typename MatrixType> -template<int Rows, int Cols, int Options, int MaxRows, int MaxCols> -inline void MatrixPower<MatrixType>::revertSchur( - Matrix<ComplexScalar, Rows, Cols, Options, MaxRows, MaxCols>& res, - const ComplexMatrix& T, - const ComplexMatrix& U) -{ res.noalias() = U * (T.template triangularView<Upper>() * U.adjoint()); } - -template<typename MatrixType> -template<int Rows, int Cols, int Options, int MaxRows, int MaxCols> -inline void MatrixPower<MatrixType>::revertSchur( - Matrix<RealScalar, Rows, Cols, Options, MaxRows, MaxCols>& res, - const ComplexMatrix& T, - const ComplexMatrix& U) -{ res.noalias() = (U * (T.template triangularView<Upper>() * U.adjoint())).real(); } - -/** - * \ingroup MatrixFunctions_Module - * - * \brief Proxy for the matrix power of some matrix (expression). - * - * \tparam Derived type of the base, a matrix (expression). - * - * This class holds the arguments to the matrix power until it is - * assigned or evaluated for some other reason (so the argument - * should not be changed in the meantime). It is the return type of - * MatrixBase::pow() and related functions and most of the - * time this is the only way it is used. - */ -template<typename Derived> -class MatrixPowerReturnValue : public ReturnByValue< MatrixPowerReturnValue<Derived> > -{ - public: - typedef typename Derived::PlainObject PlainObject; - typedef typename Derived::RealScalar RealScalar; - - /** - * \brief Constructor. - * - * \param[in] A %Matrix (expression), the base of the matrix power. - * \param[in] p real scalar, the exponent of the matrix power. - */ - MatrixPowerReturnValue(const Derived& A, RealScalar p) : m_A(A), m_p(p) - { } - - /** - * \brief Compute the matrix power. - * - * \param[out] result \f$ A^p \f$ where \p A and \p p are as in the - * constructor. - */ - template<typename ResultType> - inline void evalTo(ResultType& result) const - { MatrixPower<PlainObject>(m_A.eval()).compute(result, m_p); } - - Index rows() const { return m_A.rows(); } - Index cols() const { return m_A.cols(); } - - private: - const Derived& m_A; - const RealScalar m_p; -}; - -/** - * \ingroup MatrixFunctions_Module - * - * \brief Proxy for the matrix power of some matrix (expression). - * - * \tparam Derived type of the base, a matrix (expression). - * - * This class holds the arguments to the matrix power until it is - * assigned or evaluated for some other reason (so the argument - * should not be changed in the meantime). It is the return type of - * MatrixBase::pow() and related functions and most of the - * time this is the only way it is used. - */ -template<typename Derived> -class MatrixComplexPowerReturnValue : public ReturnByValue< MatrixComplexPowerReturnValue<Derived> > -{ - public: - typedef typename Derived::PlainObject PlainObject; - typedef typename std::complex<typename Derived::RealScalar> ComplexScalar; - - /** - * \brief Constructor. - * - * \param[in] A %Matrix (expression), the base of the matrix power. - * \param[in] p complex scalar, the exponent of the matrix power. - */ - MatrixComplexPowerReturnValue(const Derived& A, const ComplexScalar& p) : m_A(A), m_p(p) - { } - - /** - * \brief Compute the matrix power. - * - * Because \p p is complex, \f$ A^p \f$ is simply evaluated as \f$ - * \exp(p \log(A)) \f$. - * - * \param[out] result \f$ A^p \f$ where \p A and \p p are as in the - * constructor. - */ - template<typename ResultType> - inline void evalTo(ResultType& result) const - { result = (m_p * m_A.log()).exp(); } - - Index rows() const { return m_A.rows(); } - Index cols() const { return m_A.cols(); } - - private: - const Derived& m_A; - const ComplexScalar m_p; -}; - -namespace internal { - -template<typename MatrixPowerType> -struct traits< MatrixPowerParenthesesReturnValue<MatrixPowerType> > -{ typedef typename MatrixPowerType::PlainObject ReturnType; }; - -template<typename Derived> -struct traits< MatrixPowerReturnValue<Derived> > -{ typedef typename Derived::PlainObject ReturnType; }; - -template<typename Derived> -struct traits< MatrixComplexPowerReturnValue<Derived> > -{ typedef typename Derived::PlainObject ReturnType; }; - -} - -template<typename Derived> -const MatrixPowerReturnValue<Derived> MatrixBase<Derived>::pow(const RealScalar& p) const -{ return MatrixPowerReturnValue<Derived>(derived(), p); } - -template<typename Derived> -const MatrixComplexPowerReturnValue<Derived> MatrixBase<Derived>::pow(const std::complex<RealScalar>& p) const -{ return MatrixComplexPowerReturnValue<Derived>(derived(), p); } - -} // namespace Eigen - -#endif // EIGEN_MATRIX_POWER diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h b/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h deleted file mode 100644 index e363e779..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h +++ /dev/null @@ -1,368 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MATRIX_SQUARE_ROOT -#define EIGEN_MATRIX_SQUARE_ROOT - -namespace Eigen { - -namespace internal { - -// pre: T.block(i,i,2,2) has complex conjugate eigenvalues -// post: sqrtT.block(i,i,2,2) is square root of T.block(i,i,2,2) -template <typename MatrixType, typename ResultType> -void matrix_sqrt_quasi_triangular_2x2_diagonal_block(const MatrixType& T, Index i, ResultType& sqrtT) -{ - // TODO: This case (2-by-2 blocks with complex conjugate eigenvalues) is probably hidden somewhere - // in EigenSolver. If we expose it, we could call it directly from here. - typedef typename traits<MatrixType>::Scalar Scalar; - Matrix<Scalar,2,2> block = T.template block<2,2>(i,i); - EigenSolver<Matrix<Scalar,2,2> > es(block); - sqrtT.template block<2,2>(i,i) - = (es.eigenvectors() * es.eigenvalues().cwiseSqrt().asDiagonal() * es.eigenvectors().inverse()).real(); -} - -// pre: block structure of T is such that (i,j) is a 1x1 block, -// all blocks of sqrtT to left of and below (i,j) are correct -// post: sqrtT(i,j) has the correct value -template <typename MatrixType, typename ResultType> -void matrix_sqrt_quasi_triangular_1x1_off_diagonal_block(const MatrixType& T, Index i, Index j, ResultType& sqrtT) -{ - typedef typename traits<MatrixType>::Scalar Scalar; - Scalar tmp = (sqrtT.row(i).segment(i+1,j-i-1) * sqrtT.col(j).segment(i+1,j-i-1)).value(); - sqrtT.coeffRef(i,j) = (T.coeff(i,j) - tmp) / (sqrtT.coeff(i,i) + sqrtT.coeff(j,j)); -} - -// similar to compute1x1offDiagonalBlock() -template <typename MatrixType, typename ResultType> -void matrix_sqrt_quasi_triangular_1x2_off_diagonal_block(const MatrixType& T, Index i, Index j, ResultType& sqrtT) -{ - typedef typename traits<MatrixType>::Scalar Scalar; - Matrix<Scalar,1,2> rhs = T.template block<1,2>(i,j); - if (j-i > 1) - rhs -= sqrtT.block(i, i+1, 1, j-i-1) * sqrtT.block(i+1, j, j-i-1, 2); - Matrix<Scalar,2,2> A = sqrtT.coeff(i,i) * Matrix<Scalar,2,2>::Identity(); - A += sqrtT.template block<2,2>(j,j).transpose(); - sqrtT.template block<1,2>(i,j).transpose() = A.fullPivLu().solve(rhs.transpose()); -} - -// similar to compute1x1offDiagonalBlock() -template <typename MatrixType, typename ResultType> -void matrix_sqrt_quasi_triangular_2x1_off_diagonal_block(const MatrixType& T, Index i, Index j, ResultType& sqrtT) -{ - typedef typename traits<MatrixType>::Scalar Scalar; - Matrix<Scalar,2,1> rhs = T.template block<2,1>(i,j); - if (j-i > 2) - rhs -= sqrtT.block(i, i+2, 2, j-i-2) * sqrtT.block(i+2, j, j-i-2, 1); - Matrix<Scalar,2,2> A = sqrtT.coeff(j,j) * Matrix<Scalar,2,2>::Identity(); - A += sqrtT.template block<2,2>(i,i); - sqrtT.template block<2,1>(i,j) = A.fullPivLu().solve(rhs); -} - -// solves the equation A X + X B = C where all matrices are 2-by-2 -template <typename MatrixType> -void matrix_sqrt_quasi_triangular_solve_auxiliary_equation(MatrixType& X, const MatrixType& A, const MatrixType& B, const MatrixType& C) -{ - typedef typename traits<MatrixType>::Scalar Scalar; - Matrix<Scalar,4,4> coeffMatrix = Matrix<Scalar,4,4>::Zero(); - coeffMatrix.coeffRef(0,0) = A.coeff(0,0) + B.coeff(0,0); - coeffMatrix.coeffRef(1,1) = A.coeff(0,0) + B.coeff(1,1); - coeffMatrix.coeffRef(2,2) = A.coeff(1,1) + B.coeff(0,0); - coeffMatrix.coeffRef(3,3) = A.coeff(1,1) + B.coeff(1,1); - coeffMatrix.coeffRef(0,1) = B.coeff(1,0); - coeffMatrix.coeffRef(0,2) = A.coeff(0,1); - coeffMatrix.coeffRef(1,0) = B.coeff(0,1); - coeffMatrix.coeffRef(1,3) = A.coeff(0,1); - coeffMatrix.coeffRef(2,0) = A.coeff(1,0); - coeffMatrix.coeffRef(2,3) = B.coeff(1,0); - coeffMatrix.coeffRef(3,1) = A.coeff(1,0); - coeffMatrix.coeffRef(3,2) = B.coeff(0,1); - - Matrix<Scalar,4,1> rhs; - rhs.coeffRef(0) = C.coeff(0,0); - rhs.coeffRef(1) = C.coeff(0,1); - rhs.coeffRef(2) = C.coeff(1,0); - rhs.coeffRef(3) = C.coeff(1,1); - - Matrix<Scalar,4,1> result; - result = coeffMatrix.fullPivLu().solve(rhs); - - X.coeffRef(0,0) = result.coeff(0); - X.coeffRef(0,1) = result.coeff(1); - X.coeffRef(1,0) = result.coeff(2); - X.coeffRef(1,1) = result.coeff(3); -} - -// similar to compute1x1offDiagonalBlock() -template <typename MatrixType, typename ResultType> -void matrix_sqrt_quasi_triangular_2x2_off_diagonal_block(const MatrixType& T, Index i, Index j, ResultType& sqrtT) -{ - typedef typename traits<MatrixType>::Scalar Scalar; - Matrix<Scalar,2,2> A = sqrtT.template block<2,2>(i,i); - Matrix<Scalar,2,2> B = sqrtT.template block<2,2>(j,j); - Matrix<Scalar,2,2> C = T.template block<2,2>(i,j); - if (j-i > 2) - C -= sqrtT.block(i, i+2, 2, j-i-2) * sqrtT.block(i+2, j, j-i-2, 2); - Matrix<Scalar,2,2> X; - matrix_sqrt_quasi_triangular_solve_auxiliary_equation(X, A, B, C); - sqrtT.template block<2,2>(i,j) = X; -} - -// pre: T is quasi-upper-triangular and sqrtT is a zero matrix of the same size -// post: the diagonal blocks of sqrtT are the square roots of the diagonal blocks of T -template <typename MatrixType, typename ResultType> -void matrix_sqrt_quasi_triangular_diagonal(const MatrixType& T, ResultType& sqrtT) -{ - using std::sqrt; - const Index size = T.rows(); - for (Index i = 0; i < size; i++) { - if (i == size - 1 || T.coeff(i+1, i) == 0) { - eigen_assert(T(i,i) >= 0); - sqrtT.coeffRef(i,i) = sqrt(T.coeff(i,i)); - } - else { - matrix_sqrt_quasi_triangular_2x2_diagonal_block(T, i, sqrtT); - ++i; - } - } -} - -// pre: T is quasi-upper-triangular and diagonal blocks of sqrtT are square root of diagonal blocks of T. -// post: sqrtT is the square root of T. -template <typename MatrixType, typename ResultType> -void matrix_sqrt_quasi_triangular_off_diagonal(const MatrixType& T, ResultType& sqrtT) -{ - const Index size = T.rows(); - for (Index j = 1; j < size; j++) { - if (T.coeff(j, j-1) != 0) // if T(j-1:j, j-1:j) is a 2-by-2 block - continue; - for (Index i = j-1; i >= 0; i--) { - if (i > 0 && T.coeff(i, i-1) != 0) // if T(i-1:i, i-1:i) is a 2-by-2 block - continue; - bool iBlockIs2x2 = (i < size - 1) && (T.coeff(i+1, i) != 0); - bool jBlockIs2x2 = (j < size - 1) && (T.coeff(j+1, j) != 0); - if (iBlockIs2x2 && jBlockIs2x2) - matrix_sqrt_quasi_triangular_2x2_off_diagonal_block(T, i, j, sqrtT); - else if (iBlockIs2x2 && !jBlockIs2x2) - matrix_sqrt_quasi_triangular_2x1_off_diagonal_block(T, i, j, sqrtT); - else if (!iBlockIs2x2 && jBlockIs2x2) - matrix_sqrt_quasi_triangular_1x2_off_diagonal_block(T, i, j, sqrtT); - else if (!iBlockIs2x2 && !jBlockIs2x2) - matrix_sqrt_quasi_triangular_1x1_off_diagonal_block(T, i, j, sqrtT); - } - } -} - -} // end of namespace internal - -/** \ingroup MatrixFunctions_Module - * \brief Compute matrix square root of quasi-triangular matrix. - * - * \tparam MatrixType type of \p arg, the argument of matrix square root, - * expected to be an instantiation of the Matrix class template. - * \tparam ResultType type of \p result, where result is to be stored. - * \param[in] arg argument of matrix square root. - * \param[out] result matrix square root of upper Hessenberg part of \p arg. - * - * This function computes the square root of the upper quasi-triangular matrix stored in the upper - * Hessenberg part of \p arg. Only the upper Hessenberg part of \p result is updated, the rest is - * not touched. See MatrixBase::sqrt() for details on how this computation is implemented. - * - * \sa MatrixSquareRoot, MatrixSquareRootQuasiTriangular - */ -template <typename MatrixType, typename ResultType> -void matrix_sqrt_quasi_triangular(const MatrixType &arg, ResultType &result) -{ - eigen_assert(arg.rows() == arg.cols()); - result.resize(arg.rows(), arg.cols()); - internal::matrix_sqrt_quasi_triangular_diagonal(arg, result); - internal::matrix_sqrt_quasi_triangular_off_diagonal(arg, result); -} - - -/** \ingroup MatrixFunctions_Module - * \brief Compute matrix square root of triangular matrix. - * - * \tparam MatrixType type of \p arg, the argument of matrix square root, - * expected to be an instantiation of the Matrix class template. - * \tparam ResultType type of \p result, where result is to be stored. - * \param[in] arg argument of matrix square root. - * \param[out] result matrix square root of upper triangular part of \p arg. - * - * Only the upper triangular part (including the diagonal) of \p result is updated, the rest is not - * touched. See MatrixBase::sqrt() for details on how this computation is implemented. - * - * \sa MatrixSquareRoot, MatrixSquareRootQuasiTriangular - */ -template <typename MatrixType, typename ResultType> -void matrix_sqrt_triangular(const MatrixType &arg, ResultType &result) -{ - using std::sqrt; - typedef typename MatrixType::Scalar Scalar; - - eigen_assert(arg.rows() == arg.cols()); - - // Compute square root of arg and store it in upper triangular part of result - // This uses that the square root of triangular matrices can be computed directly. - result.resize(arg.rows(), arg.cols()); - for (Index i = 0; i < arg.rows(); i++) { - result.coeffRef(i,i) = sqrt(arg.coeff(i,i)); - } - for (Index j = 1; j < arg.cols(); j++) { - for (Index i = j-1; i >= 0; i--) { - // if i = j-1, then segment has length 0 so tmp = 0 - Scalar tmp = (result.row(i).segment(i+1,j-i-1) * result.col(j).segment(i+1,j-i-1)).value(); - // denominator may be zero if original matrix is singular - result.coeffRef(i,j) = (arg.coeff(i,j) - tmp) / (result.coeff(i,i) + result.coeff(j,j)); - } - } -} - - -namespace internal { - -/** \ingroup MatrixFunctions_Module - * \brief Helper struct for computing matrix square roots of general matrices. - * \tparam MatrixType type of the argument of the matrix square root, - * expected to be an instantiation of the Matrix class template. - * - * \sa MatrixSquareRootTriangular, MatrixSquareRootQuasiTriangular, MatrixBase::sqrt() - */ -template <typename MatrixType, int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex> -struct matrix_sqrt_compute -{ - /** \brief Compute the matrix square root - * - * \param[in] arg matrix whose square root is to be computed. - * \param[out] result square root of \p arg. - * - * See MatrixBase::sqrt() for details on how this computation is implemented. - */ - template <typename ResultType> static void run(const MatrixType &arg, ResultType &result); -}; - - -// ********** Partial specialization for real matrices ********** - -template <typename MatrixType> -struct matrix_sqrt_compute<MatrixType, 0> -{ - typedef typename MatrixType::PlainObject PlainType; - template <typename ResultType> - static void run(const MatrixType &arg, ResultType &result) - { - eigen_assert(arg.rows() == arg.cols()); - - // Compute Schur decomposition of arg - const RealSchur<PlainType> schurOfA(arg); - const PlainType& T = schurOfA.matrixT(); - const PlainType& U = schurOfA.matrixU(); - - // Compute square root of T - PlainType sqrtT = PlainType::Zero(arg.rows(), arg.cols()); - matrix_sqrt_quasi_triangular(T, sqrtT); - - // Compute square root of arg - result = U * sqrtT * U.adjoint(); - } -}; - - -// ********** Partial specialization for complex matrices ********** - -template <typename MatrixType> -struct matrix_sqrt_compute<MatrixType, 1> -{ - typedef typename MatrixType::PlainObject PlainType; - template <typename ResultType> - static void run(const MatrixType &arg, ResultType &result) - { - eigen_assert(arg.rows() == arg.cols()); - - // Compute Schur decomposition of arg - const ComplexSchur<PlainType> schurOfA(arg); - const PlainType& T = schurOfA.matrixT(); - const PlainType& U = schurOfA.matrixU(); - - // Compute square root of T - PlainType sqrtT; - matrix_sqrt_triangular(T, sqrtT); - - // Compute square root of arg - result = U * (sqrtT.template triangularView<Upper>() * U.adjoint()); - } -}; - -} // end namespace internal - -/** \ingroup MatrixFunctions_Module - * - * \brief Proxy for the matrix square root of some matrix (expression). - * - * \tparam Derived Type of the argument to the matrix square root. - * - * This class holds the argument to the matrix square root until it - * is assigned or evaluated for some other reason (so the argument - * should not be changed in the meantime). It is the return type of - * MatrixBase::sqrt() and most of the time this is the only way it is - * used. - */ -template<typename Derived> class MatrixSquareRootReturnValue -: public ReturnByValue<MatrixSquareRootReturnValue<Derived> > -{ - protected: - typedef typename internal::ref_selector<Derived>::type DerivedNested; - - public: - /** \brief Constructor. - * - * \param[in] src %Matrix (expression) forming the argument of the - * matrix square root. - */ - explicit MatrixSquareRootReturnValue(const Derived& src) : m_src(src) { } - - /** \brief Compute the matrix square root. - * - * \param[out] result the matrix square root of \p src in the - * constructor. - */ - template <typename ResultType> - inline void evalTo(ResultType& result) const - { - typedef typename internal::nested_eval<Derived, 10>::type DerivedEvalType; - typedef typename internal::remove_all<DerivedEvalType>::type DerivedEvalTypeClean; - DerivedEvalType tmp(m_src); - internal::matrix_sqrt_compute<DerivedEvalTypeClean>::run(tmp, result); - } - - Index rows() const { return m_src.rows(); } - Index cols() const { return m_src.cols(); } - - protected: - const DerivedNested m_src; -}; - -namespace internal { -template<typename Derived> -struct traits<MatrixSquareRootReturnValue<Derived> > -{ - typedef typename Derived::PlainObject ReturnType; -}; -} - -template <typename Derived> -const MatrixSquareRootReturnValue<Derived> MatrixBase<Derived>::sqrt() const -{ - eigen_assert(rows() == cols()); - return MatrixSquareRootReturnValue<Derived>(derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_MATRIX_FUNCTION diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/StemFunction.h b/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/StemFunction.h deleted file mode 100644 index 7604df90..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/MatrixFunctions/StemFunction.h +++ /dev/null @@ -1,117 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_STEM_FUNCTION -#define EIGEN_STEM_FUNCTION - -namespace Eigen { - -namespace internal { - -/** \brief The exponential function (and its derivatives). */ -template <typename Scalar> -Scalar stem_function_exp(Scalar x, int) -{ - using std::exp; - return exp(x); -} - -/** \brief Cosine (and its derivatives). */ -template <typename Scalar> -Scalar stem_function_cos(Scalar x, int n) -{ - using std::cos; - using std::sin; - Scalar res; - - switch (n % 4) { - case 0: - res = std::cos(x); - break; - case 1: - res = -std::sin(x); - break; - case 2: - res = -std::cos(x); - break; - case 3: - res = std::sin(x); - break; - } - return res; -} - -/** \brief Sine (and its derivatives). */ -template <typename Scalar> -Scalar stem_function_sin(Scalar x, int n) -{ - using std::cos; - using std::sin; - Scalar res; - - switch (n % 4) { - case 0: - res = std::sin(x); - break; - case 1: - res = std::cos(x); - break; - case 2: - res = -std::sin(x); - break; - case 3: - res = -std::cos(x); - break; - } - return res; -} - -/** \brief Hyperbolic cosine (and its derivatives). */ -template <typename Scalar> -Scalar stem_function_cosh(Scalar x, int n) -{ - using std::cosh; - using std::sinh; - Scalar res; - - switch (n % 2) { - case 0: - res = std::cosh(x); - break; - case 1: - res = std::sinh(x); - break; - } - return res; -} - -/** \brief Hyperbolic sine (and its derivatives). */ -template <typename Scalar> -Scalar stem_function_sinh(Scalar x, int n) -{ - using std::cosh; - using std::sinh; - Scalar res; - - switch (n % 2) { - case 0: - res = std::sinh(x); - break; - case 1: - res = std::cosh(x); - break; - } - return res; -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_STEM_FUNCTION diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/MoreVectorization/MathFunctions.h b/external/eigen/include/eigen3/unsupported/Eigen/src/MoreVectorization/MathFunctions.h deleted file mode 100644 index 63cb28de..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/MoreVectorization/MathFunctions.h +++ /dev/null @@ -1,95 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Rohit Garg <rpg.314@gmail.com> -// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_MOREVECTORIZATION_MATHFUNCTIONS_H -#define EIGEN_MOREVECTORIZATION_MATHFUNCTIONS_H - -namespace Eigen { - -namespace internal { - -/** \internal \returns the arcsin of \a a (coeff-wise) */ -template<typename Packet> inline static Packet pasin(Packet a) { return std::asin(a); } - -#ifdef EIGEN_VECTORIZE_SSE - -template<> EIGEN_DONT_INLINE Packet4f pasin(Packet4f x) -{ - _EIGEN_DECLARE_CONST_Packet4f(half, 0.5); - _EIGEN_DECLARE_CONST_Packet4f(minus_half, -0.5); - _EIGEN_DECLARE_CONST_Packet4f(3half, 1.5); - - _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(sign_mask, 0x80000000); - - _EIGEN_DECLARE_CONST_Packet4f(pi, 3.141592654); - _EIGEN_DECLARE_CONST_Packet4f(pi_over_2, 3.141592654*0.5); - - _EIGEN_DECLARE_CONST_Packet4f(asin1, 4.2163199048E-2); - _EIGEN_DECLARE_CONST_Packet4f(asin2, 2.4181311049E-2); - _EIGEN_DECLARE_CONST_Packet4f(asin3, 4.5470025998E-2); - _EIGEN_DECLARE_CONST_Packet4f(asin4, 7.4953002686E-2); - _EIGEN_DECLARE_CONST_Packet4f(asin5, 1.6666752422E-1); - - Packet4f a = pabs(x);//got the absolute value - - Packet4f sign_bit= _mm_and_ps(x, p4f_sign_mask);//extracted the sign bit - - Packet4f z1,z2;//will need them during computation - - -//will compute the two branches for asin -//so first compare with half - - Packet4f branch_mask= _mm_cmpgt_ps(a, p4f_half);//this is to select which branch to take -//both will be taken, and finally results will be merged -//the branch for values >0.5 - - { -//the core series expansion - z1=pmadd(p4f_minus_half,a,p4f_half); - Packet4f x1=psqrt(z1); - Packet4f s1=pmadd(p4f_asin1, z1, p4f_asin2); - Packet4f s2=pmadd(s1, z1, p4f_asin3); - Packet4f s3=pmadd(s2,z1, p4f_asin4); - Packet4f s4=pmadd(s3,z1, p4f_asin5); - Packet4f temp=pmul(s4,z1);//not really a madd but a mul by z so that the next term can be a madd - z1=pmadd(temp,x1,x1); - z1=padd(z1,z1); - z1=psub(p4f_pi_over_2,z1); - } - - { -//the core series expansion - Packet4f x2=a; - z2=pmul(x2,x2); - Packet4f s1=pmadd(p4f_asin1, z2, p4f_asin2); - Packet4f s2=pmadd(s1, z2, p4f_asin3); - Packet4f s3=pmadd(s2,z2, p4f_asin4); - Packet4f s4=pmadd(s3,z2, p4f_asin5); - Packet4f temp=pmul(s4,z2);//not really a madd but a mul by z so that the next term can be a madd - z2=pmadd(temp,x2,x2); - } - -/* select the correct result from the two branch evaluations */ - z1 = _mm_and_ps(branch_mask, z1); - z2 = _mm_andnot_ps(branch_mask, z2); - Packet4f z = _mm_or_ps(z1,z2); - -/* update the sign */ - return _mm_xor_ps(z, sign_bit); -} - -#endif // EIGEN_VECTORIZE_SSE - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_MOREVECTORIZATION_MATHFUNCTIONS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h deleted file mode 100644 index 8fe3ed86..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h +++ /dev/null @@ -1,601 +0,0 @@ -// -*- coding: utf-8 -// vim: set fileencoding=utf-8 - -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_HYBRIDNONLINEARSOLVER_H -#define EIGEN_HYBRIDNONLINEARSOLVER_H - -namespace Eigen { - -namespace HybridNonLinearSolverSpace { - enum Status { - Running = -1, - ImproperInputParameters = 0, - RelativeErrorTooSmall = 1, - TooManyFunctionEvaluation = 2, - TolTooSmall = 3, - NotMakingProgressJacobian = 4, - NotMakingProgressIterations = 5, - UserAsked = 6 - }; -} - -/** - * \ingroup NonLinearOptimization_Module - * \brief Finds a zero of a system of n - * nonlinear functions in n variables by a modification of the Powell - * hybrid method ("dogleg"). - * - * The user must provide a subroutine which calculates the - * functions. The Jacobian is either provided by the user, or approximated - * using a forward-difference method. - * - */ -template<typename FunctorType, typename Scalar=double> -class HybridNonLinearSolver -{ -public: - typedef DenseIndex Index; - - HybridNonLinearSolver(FunctorType &_functor) - : functor(_functor) { nfev=njev=iter = 0; fnorm= 0.; useExternalScaling=false;} - - struct Parameters { - Parameters() - : factor(Scalar(100.)) - , maxfev(1000) - , xtol(std::sqrt(NumTraits<Scalar>::epsilon())) - , nb_of_subdiagonals(-1) - , nb_of_superdiagonals(-1) - , epsfcn(Scalar(0.)) {} - Scalar factor; - Index maxfev; // maximum number of function evaluation - Scalar xtol; - Index nb_of_subdiagonals; - Index nb_of_superdiagonals; - Scalar epsfcn; - }; - typedef Matrix< Scalar, Dynamic, 1 > FVectorType; - typedef Matrix< Scalar, Dynamic, Dynamic > JacobianType; - /* TODO: if eigen provides a triangular storage, use it here */ - typedef Matrix< Scalar, Dynamic, Dynamic > UpperTriangularType; - - HybridNonLinearSolverSpace::Status hybrj1( - FVectorType &x, - const Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) - ); - - HybridNonLinearSolverSpace::Status solveInit(FVectorType &x); - HybridNonLinearSolverSpace::Status solveOneStep(FVectorType &x); - HybridNonLinearSolverSpace::Status solve(FVectorType &x); - - HybridNonLinearSolverSpace::Status hybrd1( - FVectorType &x, - const Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) - ); - - HybridNonLinearSolverSpace::Status solveNumericalDiffInit(FVectorType &x); - HybridNonLinearSolverSpace::Status solveNumericalDiffOneStep(FVectorType &x); - HybridNonLinearSolverSpace::Status solveNumericalDiff(FVectorType &x); - - void resetParameters(void) { parameters = Parameters(); } - Parameters parameters; - FVectorType fvec, qtf, diag; - JacobianType fjac; - UpperTriangularType R; - Index nfev; - Index njev; - Index iter; - Scalar fnorm; - bool useExternalScaling; -private: - FunctorType &functor; - Index n; - Scalar sum; - bool sing; - Scalar temp; - Scalar delta; - bool jeval; - Index ncsuc; - Scalar ratio; - Scalar pnorm, xnorm, fnorm1; - Index nslow1, nslow2; - Index ncfail; - Scalar actred, prered; - FVectorType wa1, wa2, wa3, wa4; - - HybridNonLinearSolver& operator=(const HybridNonLinearSolver&); -}; - - - -template<typename FunctorType, typename Scalar> -HybridNonLinearSolverSpace::Status -HybridNonLinearSolver<FunctorType,Scalar>::hybrj1( - FVectorType &x, - const Scalar tol - ) -{ - n = x.size(); - - /* check the input parameters for errors. */ - if (n <= 0 || tol < 0.) - return HybridNonLinearSolverSpace::ImproperInputParameters; - - resetParameters(); - parameters.maxfev = 100*(n+1); - parameters.xtol = tol; - diag.setConstant(n, 1.); - useExternalScaling = true; - return solve(x); -} - -template<typename FunctorType, typename Scalar> -HybridNonLinearSolverSpace::Status -HybridNonLinearSolver<FunctorType,Scalar>::solveInit(FVectorType &x) -{ - n = x.size(); - - wa1.resize(n); wa2.resize(n); wa3.resize(n); wa4.resize(n); - fvec.resize(n); - qtf.resize(n); - fjac.resize(n, n); - if (!useExternalScaling) - diag.resize(n); - eigen_assert( (!useExternalScaling || diag.size()==n) && "When useExternalScaling is set, the caller must provide a valid 'diag'"); - - /* Function Body */ - nfev = 0; - njev = 0; - - /* check the input parameters for errors. */ - if (n <= 0 || parameters.xtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0. ) - return HybridNonLinearSolverSpace::ImproperInputParameters; - if (useExternalScaling) - for (Index j = 0; j < n; ++j) - if (diag[j] <= 0.) - return HybridNonLinearSolverSpace::ImproperInputParameters; - - /* evaluate the function at the starting point */ - /* and calculate its norm. */ - nfev = 1; - if ( functor(x, fvec) < 0) - return HybridNonLinearSolverSpace::UserAsked; - fnorm = fvec.stableNorm(); - - /* initialize iteration counter and monitors. */ - iter = 1; - ncsuc = 0; - ncfail = 0; - nslow1 = 0; - nslow2 = 0; - - return HybridNonLinearSolverSpace::Running; -} - -template<typename FunctorType, typename Scalar> -HybridNonLinearSolverSpace::Status -HybridNonLinearSolver<FunctorType,Scalar>::solveOneStep(FVectorType &x) -{ - using std::abs; - - eigen_assert(x.size()==n); // check the caller is not cheating us - - Index j; - std::vector<JacobiRotation<Scalar> > v_givens(n), w_givens(n); - - jeval = true; - - /* calculate the jacobian matrix. */ - if ( functor.df(x, fjac) < 0) - return HybridNonLinearSolverSpace::UserAsked; - ++njev; - - wa2 = fjac.colwise().blueNorm(); - - /* on the first iteration and if external scaling is not used, scale according */ - /* to the norms of the columns of the initial jacobian. */ - if (iter == 1) { - if (!useExternalScaling) - for (j = 0; j < n; ++j) - diag[j] = (wa2[j]==0.) ? 1. : wa2[j]; - - /* on the first iteration, calculate the norm of the scaled x */ - /* and initialize the step bound delta. */ - xnorm = diag.cwiseProduct(x).stableNorm(); - delta = parameters.factor * xnorm; - if (delta == 0.) - delta = parameters.factor; - } - - /* compute the qr factorization of the jacobian. */ - HouseholderQR<JacobianType> qrfac(fjac); // no pivoting: - - /* copy the triangular factor of the qr factorization into r. */ - R = qrfac.matrixQR(); - - /* accumulate the orthogonal factor in fjac. */ - fjac = qrfac.householderQ(); - - /* form (q transpose)*fvec and store in qtf. */ - qtf = fjac.transpose() * fvec; - - /* rescale if necessary. */ - if (!useExternalScaling) - diag = diag.cwiseMax(wa2); - - while (true) { - /* determine the direction p. */ - internal::dogleg<Scalar>(R, diag, qtf, delta, wa1); - - /* store the direction p and x + p. calculate the norm of p. */ - wa1 = -wa1; - wa2 = x + wa1; - pnorm = diag.cwiseProduct(wa1).stableNorm(); - - /* on the first iteration, adjust the initial step bound. */ - if (iter == 1) - delta = (std::min)(delta,pnorm); - - /* evaluate the function at x + p and calculate its norm. */ - if ( functor(wa2, wa4) < 0) - return HybridNonLinearSolverSpace::UserAsked; - ++nfev; - fnorm1 = wa4.stableNorm(); - - /* compute the scaled actual reduction. */ - actred = -1.; - if (fnorm1 < fnorm) /* Computing 2nd power */ - actred = 1. - numext::abs2(fnorm1 / fnorm); - - /* compute the scaled predicted reduction. */ - wa3 = R.template triangularView<Upper>()*wa1 + qtf; - temp = wa3.stableNorm(); - prered = 0.; - if (temp < fnorm) /* Computing 2nd power */ - prered = 1. - numext::abs2(temp / fnorm); - - /* compute the ratio of the actual to the predicted reduction. */ - ratio = 0.; - if (prered > 0.) - ratio = actred / prered; - - /* update the step bound. */ - if (ratio < Scalar(.1)) { - ncsuc = 0; - ++ncfail; - delta = Scalar(.5) * delta; - } else { - ncfail = 0; - ++ncsuc; - if (ratio >= Scalar(.5) || ncsuc > 1) - delta = (std::max)(delta, pnorm / Scalar(.5)); - if (abs(ratio - 1.) <= Scalar(.1)) { - delta = pnorm / Scalar(.5); - } - } - - /* test for successful iteration. */ - if (ratio >= Scalar(1e-4)) { - /* successful iteration. update x, fvec, and their norms. */ - x = wa2; - wa2 = diag.cwiseProduct(x); - fvec = wa4; - xnorm = wa2.stableNorm(); - fnorm = fnorm1; - ++iter; - } - - /* determine the progress of the iteration. */ - ++nslow1; - if (actred >= Scalar(.001)) - nslow1 = 0; - if (jeval) - ++nslow2; - if (actred >= Scalar(.1)) - nslow2 = 0; - - /* test for convergence. */ - if (delta <= parameters.xtol * xnorm || fnorm == 0.) - return HybridNonLinearSolverSpace::RelativeErrorTooSmall; - - /* tests for termination and stringent tolerances. */ - if (nfev >= parameters.maxfev) - return HybridNonLinearSolverSpace::TooManyFunctionEvaluation; - if (Scalar(.1) * (std::max)(Scalar(.1) * delta, pnorm) <= NumTraits<Scalar>::epsilon() * xnorm) - return HybridNonLinearSolverSpace::TolTooSmall; - if (nslow2 == 5) - return HybridNonLinearSolverSpace::NotMakingProgressJacobian; - if (nslow1 == 10) - return HybridNonLinearSolverSpace::NotMakingProgressIterations; - - /* criterion for recalculating jacobian. */ - if (ncfail == 2) - break; // leave inner loop and go for the next outer loop iteration - - /* calculate the rank one modification to the jacobian */ - /* and update qtf if necessary. */ - wa1 = diag.cwiseProduct( diag.cwiseProduct(wa1)/pnorm ); - wa2 = fjac.transpose() * wa4; - if (ratio >= Scalar(1e-4)) - qtf = wa2; - wa2 = (wa2-wa3)/pnorm; - - /* compute the qr factorization of the updated jacobian. */ - internal::r1updt<Scalar>(R, wa1, v_givens, w_givens, wa2, wa3, &sing); - internal::r1mpyq<Scalar>(n, n, fjac.data(), v_givens, w_givens); - internal::r1mpyq<Scalar>(1, n, qtf.data(), v_givens, w_givens); - - jeval = false; - } - return HybridNonLinearSolverSpace::Running; -} - -template<typename FunctorType, typename Scalar> -HybridNonLinearSolverSpace::Status -HybridNonLinearSolver<FunctorType,Scalar>::solve(FVectorType &x) -{ - HybridNonLinearSolverSpace::Status status = solveInit(x); - if (status==HybridNonLinearSolverSpace::ImproperInputParameters) - return status; - while (status==HybridNonLinearSolverSpace::Running) - status = solveOneStep(x); - return status; -} - - - -template<typename FunctorType, typename Scalar> -HybridNonLinearSolverSpace::Status -HybridNonLinearSolver<FunctorType,Scalar>::hybrd1( - FVectorType &x, - const Scalar tol - ) -{ - n = x.size(); - - /* check the input parameters for errors. */ - if (n <= 0 || tol < 0.) - return HybridNonLinearSolverSpace::ImproperInputParameters; - - resetParameters(); - parameters.maxfev = 200*(n+1); - parameters.xtol = tol; - - diag.setConstant(n, 1.); - useExternalScaling = true; - return solveNumericalDiff(x); -} - -template<typename FunctorType, typename Scalar> -HybridNonLinearSolverSpace::Status -HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffInit(FVectorType &x) -{ - n = x.size(); - - if (parameters.nb_of_subdiagonals<0) parameters.nb_of_subdiagonals= n-1; - if (parameters.nb_of_superdiagonals<0) parameters.nb_of_superdiagonals= n-1; - - wa1.resize(n); wa2.resize(n); wa3.resize(n); wa4.resize(n); - qtf.resize(n); - fjac.resize(n, n); - fvec.resize(n); - if (!useExternalScaling) - diag.resize(n); - eigen_assert( (!useExternalScaling || diag.size()==n) && "When useExternalScaling is set, the caller must provide a valid 'diag'"); - - /* Function Body */ - nfev = 0; - njev = 0; - - /* check the input parameters for errors. */ - if (n <= 0 || parameters.xtol < 0. || parameters.maxfev <= 0 || parameters.nb_of_subdiagonals< 0 || parameters.nb_of_superdiagonals< 0 || parameters.factor <= 0. ) - return HybridNonLinearSolverSpace::ImproperInputParameters; - if (useExternalScaling) - for (Index j = 0; j < n; ++j) - if (diag[j] <= 0.) - return HybridNonLinearSolverSpace::ImproperInputParameters; - - /* evaluate the function at the starting point */ - /* and calculate its norm. */ - nfev = 1; - if ( functor(x, fvec) < 0) - return HybridNonLinearSolverSpace::UserAsked; - fnorm = fvec.stableNorm(); - - /* initialize iteration counter and monitors. */ - iter = 1; - ncsuc = 0; - ncfail = 0; - nslow1 = 0; - nslow2 = 0; - - return HybridNonLinearSolverSpace::Running; -} - -template<typename FunctorType, typename Scalar> -HybridNonLinearSolverSpace::Status -HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiffOneStep(FVectorType &x) -{ - using std::sqrt; - using std::abs; - - assert(x.size()==n); // check the caller is not cheating us - - Index j; - std::vector<JacobiRotation<Scalar> > v_givens(n), w_givens(n); - - jeval = true; - if (parameters.nb_of_subdiagonals<0) parameters.nb_of_subdiagonals= n-1; - if (parameters.nb_of_superdiagonals<0) parameters.nb_of_superdiagonals= n-1; - - /* calculate the jacobian matrix. */ - if (internal::fdjac1(functor, x, fvec, fjac, parameters.nb_of_subdiagonals, parameters.nb_of_superdiagonals, parameters.epsfcn) <0) - return HybridNonLinearSolverSpace::UserAsked; - nfev += (std::min)(parameters.nb_of_subdiagonals+parameters.nb_of_superdiagonals+ 1, n); - - wa2 = fjac.colwise().blueNorm(); - - /* on the first iteration and if external scaling is not used, scale according */ - /* to the norms of the columns of the initial jacobian. */ - if (iter == 1) { - if (!useExternalScaling) - for (j = 0; j < n; ++j) - diag[j] = (wa2[j]==0.) ? 1. : wa2[j]; - - /* on the first iteration, calculate the norm of the scaled x */ - /* and initialize the step bound delta. */ - xnorm = diag.cwiseProduct(x).stableNorm(); - delta = parameters.factor * xnorm; - if (delta == 0.) - delta = parameters.factor; - } - - /* compute the qr factorization of the jacobian. */ - HouseholderQR<JacobianType> qrfac(fjac); // no pivoting: - - /* copy the triangular factor of the qr factorization into r. */ - R = qrfac.matrixQR(); - - /* accumulate the orthogonal factor in fjac. */ - fjac = qrfac.householderQ(); - - /* form (q transpose)*fvec and store in qtf. */ - qtf = fjac.transpose() * fvec; - - /* rescale if necessary. */ - if (!useExternalScaling) - diag = diag.cwiseMax(wa2); - - while (true) { - /* determine the direction p. */ - internal::dogleg<Scalar>(R, diag, qtf, delta, wa1); - - /* store the direction p and x + p. calculate the norm of p. */ - wa1 = -wa1; - wa2 = x + wa1; - pnorm = diag.cwiseProduct(wa1).stableNorm(); - - /* on the first iteration, adjust the initial step bound. */ - if (iter == 1) - delta = (std::min)(delta,pnorm); - - /* evaluate the function at x + p and calculate its norm. */ - if ( functor(wa2, wa4) < 0) - return HybridNonLinearSolverSpace::UserAsked; - ++nfev; - fnorm1 = wa4.stableNorm(); - - /* compute the scaled actual reduction. */ - actred = -1.; - if (fnorm1 < fnorm) /* Computing 2nd power */ - actred = 1. - numext::abs2(fnorm1 / fnorm); - - /* compute the scaled predicted reduction. */ - wa3 = R.template triangularView<Upper>()*wa1 + qtf; - temp = wa3.stableNorm(); - prered = 0.; - if (temp < fnorm) /* Computing 2nd power */ - prered = 1. - numext::abs2(temp / fnorm); - - /* compute the ratio of the actual to the predicted reduction. */ - ratio = 0.; - if (prered > 0.) - ratio = actred / prered; - - /* update the step bound. */ - if (ratio < Scalar(.1)) { - ncsuc = 0; - ++ncfail; - delta = Scalar(.5) * delta; - } else { - ncfail = 0; - ++ncsuc; - if (ratio >= Scalar(.5) || ncsuc > 1) - delta = (std::max)(delta, pnorm / Scalar(.5)); - if (abs(ratio - 1.) <= Scalar(.1)) { - delta = pnorm / Scalar(.5); - } - } - - /* test for successful iteration. */ - if (ratio >= Scalar(1e-4)) { - /* successful iteration. update x, fvec, and their norms. */ - x = wa2; - wa2 = diag.cwiseProduct(x); - fvec = wa4; - xnorm = wa2.stableNorm(); - fnorm = fnorm1; - ++iter; - } - - /* determine the progress of the iteration. */ - ++nslow1; - if (actred >= Scalar(.001)) - nslow1 = 0; - if (jeval) - ++nslow2; - if (actred >= Scalar(.1)) - nslow2 = 0; - - /* test for convergence. */ - if (delta <= parameters.xtol * xnorm || fnorm == 0.) - return HybridNonLinearSolverSpace::RelativeErrorTooSmall; - - /* tests for termination and stringent tolerances. */ - if (nfev >= parameters.maxfev) - return HybridNonLinearSolverSpace::TooManyFunctionEvaluation; - if (Scalar(.1) * (std::max)(Scalar(.1) * delta, pnorm) <= NumTraits<Scalar>::epsilon() * xnorm) - return HybridNonLinearSolverSpace::TolTooSmall; - if (nslow2 == 5) - return HybridNonLinearSolverSpace::NotMakingProgressJacobian; - if (nslow1 == 10) - return HybridNonLinearSolverSpace::NotMakingProgressIterations; - - /* criterion for recalculating jacobian. */ - if (ncfail == 2) - break; // leave inner loop and go for the next outer loop iteration - - /* calculate the rank one modification to the jacobian */ - /* and update qtf if necessary. */ - wa1 = diag.cwiseProduct( diag.cwiseProduct(wa1)/pnorm ); - wa2 = fjac.transpose() * wa4; - if (ratio >= Scalar(1e-4)) - qtf = wa2; - wa2 = (wa2-wa3)/pnorm; - - /* compute the qr factorization of the updated jacobian. */ - internal::r1updt<Scalar>(R, wa1, v_givens, w_givens, wa2, wa3, &sing); - internal::r1mpyq<Scalar>(n, n, fjac.data(), v_givens, w_givens); - internal::r1mpyq<Scalar>(1, n, qtf.data(), v_givens, w_givens); - - jeval = false; - } - return HybridNonLinearSolverSpace::Running; -} - -template<typename FunctorType, typename Scalar> -HybridNonLinearSolverSpace::Status -HybridNonLinearSolver<FunctorType,Scalar>::solveNumericalDiff(FVectorType &x) -{ - HybridNonLinearSolverSpace::Status status = solveNumericalDiffInit(x); - if (status==HybridNonLinearSolverSpace::ImproperInputParameters) - return status; - while (status==HybridNonLinearSolverSpace::Running) - status = solveNumericalDiffOneStep(x); - return status; -} - -} // end namespace Eigen - -#endif // EIGEN_HYBRIDNONLINEARSOLVER_H - -//vim: ai ts=4 sts=4 et sw=4 diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h deleted file mode 100644 index fe3b79ca..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h +++ /dev/null @@ -1,657 +0,0 @@ -// -*- coding: utf-8 -// vim: set fileencoding=utf-8 - -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_LEVENBERGMARQUARDT__H -#define EIGEN_LEVENBERGMARQUARDT__H - -namespace Eigen { - -namespace LevenbergMarquardtSpace { - enum Status { - NotStarted = -2, - Running = -1, - ImproperInputParameters = 0, - RelativeReductionTooSmall = 1, - RelativeErrorTooSmall = 2, - RelativeErrorAndReductionTooSmall = 3, - CosinusTooSmall = 4, - TooManyFunctionEvaluation = 5, - FtolTooSmall = 6, - XtolTooSmall = 7, - GtolTooSmall = 8, - UserAsked = 9 - }; -} - - - -/** - * \ingroup NonLinearOptimization_Module - * \brief Performs non linear optimization over a non-linear function, - * using a variant of the Levenberg Marquardt algorithm. - * - * Check wikipedia for more information. - * http://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm - */ -template<typename FunctorType, typename Scalar=double> -class LevenbergMarquardt -{ - static Scalar sqrt_epsilon() - { - using std::sqrt; - return sqrt(NumTraits<Scalar>::epsilon()); - } - -public: - LevenbergMarquardt(FunctorType &_functor) - : functor(_functor) { nfev = njev = iter = 0; fnorm = gnorm = 0.; useExternalScaling=false; } - - typedef DenseIndex Index; - - struct Parameters { - Parameters() - : factor(Scalar(100.)) - , maxfev(400) - , ftol(sqrt_epsilon()) - , xtol(sqrt_epsilon()) - , gtol(Scalar(0.)) - , epsfcn(Scalar(0.)) {} - Scalar factor; - Index maxfev; // maximum number of function evaluation - Scalar ftol; - Scalar xtol; - Scalar gtol; - Scalar epsfcn; - }; - - typedef Matrix< Scalar, Dynamic, 1 > FVectorType; - typedef Matrix< Scalar, Dynamic, Dynamic > JacobianType; - - LevenbergMarquardtSpace::Status lmder1( - FVectorType &x, - const Scalar tol = sqrt_epsilon() - ); - - LevenbergMarquardtSpace::Status minimize(FVectorType &x); - LevenbergMarquardtSpace::Status minimizeInit(FVectorType &x); - LevenbergMarquardtSpace::Status minimizeOneStep(FVectorType &x); - - static LevenbergMarquardtSpace::Status lmdif1( - FunctorType &functor, - FVectorType &x, - Index *nfev, - const Scalar tol = sqrt_epsilon() - ); - - LevenbergMarquardtSpace::Status lmstr1( - FVectorType &x, - const Scalar tol = sqrt_epsilon() - ); - - LevenbergMarquardtSpace::Status minimizeOptimumStorage(FVectorType &x); - LevenbergMarquardtSpace::Status minimizeOptimumStorageInit(FVectorType &x); - LevenbergMarquardtSpace::Status minimizeOptimumStorageOneStep(FVectorType &x); - - void resetParameters(void) { parameters = Parameters(); } - - Parameters parameters; - FVectorType fvec, qtf, diag; - JacobianType fjac; - PermutationMatrix<Dynamic,Dynamic> permutation; - Index nfev; - Index njev; - Index iter; - Scalar fnorm, gnorm; - bool useExternalScaling; - - Scalar lm_param(void) { return par; } -private: - - FunctorType &functor; - Index n; - Index m; - FVectorType wa1, wa2, wa3, wa4; - - Scalar par, sum; - Scalar temp, temp1, temp2; - Scalar delta; - Scalar ratio; - Scalar pnorm, xnorm, fnorm1, actred, dirder, prered; - - LevenbergMarquardt& operator=(const LevenbergMarquardt&); -}; - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::lmder1( - FVectorType &x, - const Scalar tol - ) -{ - n = x.size(); - m = functor.values(); - - /* check the input parameters for errors. */ - if (n <= 0 || m < n || tol < 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - resetParameters(); - parameters.ftol = tol; - parameters.xtol = tol; - parameters.maxfev = 100*(n+1); - - return minimize(x); -} - - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::minimize(FVectorType &x) -{ - LevenbergMarquardtSpace::Status status = minimizeInit(x); - if (status==LevenbergMarquardtSpace::ImproperInputParameters) - return status; - do { - status = minimizeOneStep(x); - } while (status==LevenbergMarquardtSpace::Running); - return status; -} - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::minimizeInit(FVectorType &x) -{ - n = x.size(); - m = functor.values(); - - wa1.resize(n); wa2.resize(n); wa3.resize(n); - wa4.resize(m); - fvec.resize(m); - fjac.resize(m, n); - if (!useExternalScaling) - diag.resize(n); - eigen_assert( (!useExternalScaling || diag.size()==n) && "When useExternalScaling is set, the caller must provide a valid 'diag'"); - qtf.resize(n); - - /* Function Body */ - nfev = 0; - njev = 0; - - /* check the input parameters for errors. */ - if (n <= 0 || m < n || parameters.ftol < 0. || parameters.xtol < 0. || parameters.gtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - if (useExternalScaling) - for (Index j = 0; j < n; ++j) - if (diag[j] <= 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - /* evaluate the function at the starting point */ - /* and calculate its norm. */ - nfev = 1; - if ( functor(x, fvec) < 0) - return LevenbergMarquardtSpace::UserAsked; - fnorm = fvec.stableNorm(); - - /* initialize levenberg-marquardt parameter and iteration counter. */ - par = 0.; - iter = 1; - - return LevenbergMarquardtSpace::NotStarted; -} - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::minimizeOneStep(FVectorType &x) -{ - using std::abs; - using std::sqrt; - - eigen_assert(x.size()==n); // check the caller is not cheating us - - /* calculate the jacobian matrix. */ - Index df_ret = functor.df(x, fjac); - if (df_ret<0) - return LevenbergMarquardtSpace::UserAsked; - if (df_ret>0) - // numerical diff, we evaluated the function df_ret times - nfev += df_ret; - else njev++; - - /* compute the qr factorization of the jacobian. */ - wa2 = fjac.colwise().blueNorm(); - ColPivHouseholderQR<JacobianType> qrfac(fjac); - fjac = qrfac.matrixQR(); - permutation = qrfac.colsPermutation(); - - /* on the first iteration and if external scaling is not used, scale according */ - /* to the norms of the columns of the initial jacobian. */ - if (iter == 1) { - if (!useExternalScaling) - for (Index j = 0; j < n; ++j) - diag[j] = (wa2[j]==0.)? 1. : wa2[j]; - - /* on the first iteration, calculate the norm of the scaled x */ - /* and initialize the step bound delta. */ - xnorm = diag.cwiseProduct(x).stableNorm(); - delta = parameters.factor * xnorm; - if (delta == 0.) - delta = parameters.factor; - } - - /* form (q transpose)*fvec and store the first n components in */ - /* qtf. */ - wa4 = fvec; - wa4.applyOnTheLeft(qrfac.householderQ().adjoint()); - qtf = wa4.head(n); - - /* compute the norm of the scaled gradient. */ - gnorm = 0.; - if (fnorm != 0.) - for (Index j = 0; j < n; ++j) - if (wa2[permutation.indices()[j]] != 0.) - gnorm = (std::max)(gnorm, abs( fjac.col(j).head(j+1).dot(qtf.head(j+1)/fnorm) / wa2[permutation.indices()[j]])); - - /* test for convergence of the gradient norm. */ - if (gnorm <= parameters.gtol) - return LevenbergMarquardtSpace::CosinusTooSmall; - - /* rescale if necessary. */ - if (!useExternalScaling) - diag = diag.cwiseMax(wa2); - - do { - - /* determine the levenberg-marquardt parameter. */ - internal::lmpar2<Scalar>(qrfac, diag, qtf, delta, par, wa1); - - /* store the direction p and x + p. calculate the norm of p. */ - wa1 = -wa1; - wa2 = x + wa1; - pnorm = diag.cwiseProduct(wa1).stableNorm(); - - /* on the first iteration, adjust the initial step bound. */ - if (iter == 1) - delta = (std::min)(delta,pnorm); - - /* evaluate the function at x + p and calculate its norm. */ - if ( functor(wa2, wa4) < 0) - return LevenbergMarquardtSpace::UserAsked; - ++nfev; - fnorm1 = wa4.stableNorm(); - - /* compute the scaled actual reduction. */ - actred = -1.; - if (Scalar(.1) * fnorm1 < fnorm) - actred = 1. - numext::abs2(fnorm1 / fnorm); - - /* compute the scaled predicted reduction and */ - /* the scaled directional derivative. */ - wa3 = fjac.template triangularView<Upper>() * (qrfac.colsPermutation().inverse() *wa1); - temp1 = numext::abs2(wa3.stableNorm() / fnorm); - temp2 = numext::abs2(sqrt(par) * pnorm / fnorm); - prered = temp1 + temp2 / Scalar(.5); - dirder = -(temp1 + temp2); - - /* compute the ratio of the actual to the predicted */ - /* reduction. */ - ratio = 0.; - if (prered != 0.) - ratio = actred / prered; - - /* update the step bound. */ - if (ratio <= Scalar(.25)) { - if (actred >= 0.) - temp = Scalar(.5); - if (actred < 0.) - temp = Scalar(.5) * dirder / (dirder + Scalar(.5) * actred); - if (Scalar(.1) * fnorm1 >= fnorm || temp < Scalar(.1)) - temp = Scalar(.1); - /* Computing MIN */ - delta = temp * (std::min)(delta, pnorm / Scalar(.1)); - par /= temp; - } else if (!(par != 0. && ratio < Scalar(.75))) { - delta = pnorm / Scalar(.5); - par = Scalar(.5) * par; - } - - /* test for successful iteration. */ - if (ratio >= Scalar(1e-4)) { - /* successful iteration. update x, fvec, and their norms. */ - x = wa2; - wa2 = diag.cwiseProduct(x); - fvec = wa4; - xnorm = wa2.stableNorm(); - fnorm = fnorm1; - ++iter; - } - - /* tests for convergence. */ - if (abs(actred) <= parameters.ftol && prered <= parameters.ftol && Scalar(.5) * ratio <= 1. && delta <= parameters.xtol * xnorm) - return LevenbergMarquardtSpace::RelativeErrorAndReductionTooSmall; - if (abs(actred) <= parameters.ftol && prered <= parameters.ftol && Scalar(.5) * ratio <= 1.) - return LevenbergMarquardtSpace::RelativeReductionTooSmall; - if (delta <= parameters.xtol * xnorm) - return LevenbergMarquardtSpace::RelativeErrorTooSmall; - - /* tests for termination and stringent tolerances. */ - if (nfev >= parameters.maxfev) - return LevenbergMarquardtSpace::TooManyFunctionEvaluation; - if (abs(actred) <= NumTraits<Scalar>::epsilon() && prered <= NumTraits<Scalar>::epsilon() && Scalar(.5) * ratio <= 1.) - return LevenbergMarquardtSpace::FtolTooSmall; - if (delta <= NumTraits<Scalar>::epsilon() * xnorm) - return LevenbergMarquardtSpace::XtolTooSmall; - if (gnorm <= NumTraits<Scalar>::epsilon()) - return LevenbergMarquardtSpace::GtolTooSmall; - - } while (ratio < Scalar(1e-4)); - - return LevenbergMarquardtSpace::Running; -} - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::lmstr1( - FVectorType &x, - const Scalar tol - ) -{ - n = x.size(); - m = functor.values(); - - /* check the input parameters for errors. */ - if (n <= 0 || m < n || tol < 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - resetParameters(); - parameters.ftol = tol; - parameters.xtol = tol; - parameters.maxfev = 100*(n+1); - - return minimizeOptimumStorage(x); -} - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageInit(FVectorType &x) -{ - n = x.size(); - m = functor.values(); - - wa1.resize(n); wa2.resize(n); wa3.resize(n); - wa4.resize(m); - fvec.resize(m); - // Only R is stored in fjac. Q is only used to compute 'qtf', which is - // Q.transpose()*rhs. qtf will be updated using givens rotation, - // instead of storing them in Q. - // The purpose it to only use a nxn matrix, instead of mxn here, so - // that we can handle cases where m>>n : - fjac.resize(n, n); - if (!useExternalScaling) - diag.resize(n); - eigen_assert( (!useExternalScaling || diag.size()==n) && "When useExternalScaling is set, the caller must provide a valid 'diag'"); - qtf.resize(n); - - /* Function Body */ - nfev = 0; - njev = 0; - - /* check the input parameters for errors. */ - if (n <= 0 || m < n || parameters.ftol < 0. || parameters.xtol < 0. || parameters.gtol < 0. || parameters.maxfev <= 0 || parameters.factor <= 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - if (useExternalScaling) - for (Index j = 0; j < n; ++j) - if (diag[j] <= 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - /* evaluate the function at the starting point */ - /* and calculate its norm. */ - nfev = 1; - if ( functor(x, fvec) < 0) - return LevenbergMarquardtSpace::UserAsked; - fnorm = fvec.stableNorm(); - - /* initialize levenberg-marquardt parameter and iteration counter. */ - par = 0.; - iter = 1; - - return LevenbergMarquardtSpace::NotStarted; -} - - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorageOneStep(FVectorType &x) -{ - using std::abs; - using std::sqrt; - - eigen_assert(x.size()==n); // check the caller is not cheating us - - Index i, j; - bool sing; - - /* compute the qr factorization of the jacobian matrix */ - /* calculated one row at a time, while simultaneously */ - /* forming (q transpose)*fvec and storing the first */ - /* n components in qtf. */ - qtf.fill(0.); - fjac.fill(0.); - Index rownb = 2; - for (i = 0; i < m; ++i) { - if (functor.df(x, wa3, rownb) < 0) return LevenbergMarquardtSpace::UserAsked; - internal::rwupdt<Scalar>(fjac, wa3, qtf, fvec[i]); - ++rownb; - } - ++njev; - - /* if the jacobian is rank deficient, call qrfac to */ - /* reorder its columns and update the components of qtf. */ - sing = false; - for (j = 0; j < n; ++j) { - if (fjac(j,j) == 0.) - sing = true; - wa2[j] = fjac.col(j).head(j).stableNorm(); - } - permutation.setIdentity(n); - if (sing) { - wa2 = fjac.colwise().blueNorm(); - // TODO We have no unit test covering this code path, do not modify - // until it is carefully tested - ColPivHouseholderQR<JacobianType> qrfac(fjac); - fjac = qrfac.matrixQR(); - wa1 = fjac.diagonal(); - fjac.diagonal() = qrfac.hCoeffs(); - permutation = qrfac.colsPermutation(); - // TODO : avoid this: - for(Index ii=0; ii< fjac.cols(); ii++) fjac.col(ii).segment(ii+1, fjac.rows()-ii-1) *= fjac(ii,ii); // rescale vectors - - for (j = 0; j < n; ++j) { - if (fjac(j,j) != 0.) { - sum = 0.; - for (i = j; i < n; ++i) - sum += fjac(i,j) * qtf[i]; - temp = -sum / fjac(j,j); - for (i = j; i < n; ++i) - qtf[i] += fjac(i,j) * temp; - } - fjac(j,j) = wa1[j]; - } - } - - /* on the first iteration and if external scaling is not used, scale according */ - /* to the norms of the columns of the initial jacobian. */ - if (iter == 1) { - if (!useExternalScaling) - for (j = 0; j < n; ++j) - diag[j] = (wa2[j]==0.)? 1. : wa2[j]; - - /* on the first iteration, calculate the norm of the scaled x */ - /* and initialize the step bound delta. */ - xnorm = diag.cwiseProduct(x).stableNorm(); - delta = parameters.factor * xnorm; - if (delta == 0.) - delta = parameters.factor; - } - - /* compute the norm of the scaled gradient. */ - gnorm = 0.; - if (fnorm != 0.) - for (j = 0; j < n; ++j) - if (wa2[permutation.indices()[j]] != 0.) - gnorm = (std::max)(gnorm, abs( fjac.col(j).head(j+1).dot(qtf.head(j+1)/fnorm) / wa2[permutation.indices()[j]])); - - /* test for convergence of the gradient norm. */ - if (gnorm <= parameters.gtol) - return LevenbergMarquardtSpace::CosinusTooSmall; - - /* rescale if necessary. */ - if (!useExternalScaling) - diag = diag.cwiseMax(wa2); - - do { - - /* determine the levenberg-marquardt parameter. */ - internal::lmpar<Scalar>(fjac, permutation.indices(), diag, qtf, delta, par, wa1); - - /* store the direction p and x + p. calculate the norm of p. */ - wa1 = -wa1; - wa2 = x + wa1; - pnorm = diag.cwiseProduct(wa1).stableNorm(); - - /* on the first iteration, adjust the initial step bound. */ - if (iter == 1) - delta = (std::min)(delta,pnorm); - - /* evaluate the function at x + p and calculate its norm. */ - if ( functor(wa2, wa4) < 0) - return LevenbergMarquardtSpace::UserAsked; - ++nfev; - fnorm1 = wa4.stableNorm(); - - /* compute the scaled actual reduction. */ - actred = -1.; - if (Scalar(.1) * fnorm1 < fnorm) - actred = 1. - numext::abs2(fnorm1 / fnorm); - - /* compute the scaled predicted reduction and */ - /* the scaled directional derivative. */ - wa3 = fjac.topLeftCorner(n,n).template triangularView<Upper>() * (permutation.inverse() * wa1); - temp1 = numext::abs2(wa3.stableNorm() / fnorm); - temp2 = numext::abs2(sqrt(par) * pnorm / fnorm); - prered = temp1 + temp2 / Scalar(.5); - dirder = -(temp1 + temp2); - - /* compute the ratio of the actual to the predicted */ - /* reduction. */ - ratio = 0.; - if (prered != 0.) - ratio = actred / prered; - - /* update the step bound. */ - if (ratio <= Scalar(.25)) { - if (actred >= 0.) - temp = Scalar(.5); - if (actred < 0.) - temp = Scalar(.5) * dirder / (dirder + Scalar(.5) * actred); - if (Scalar(.1) * fnorm1 >= fnorm || temp < Scalar(.1)) - temp = Scalar(.1); - /* Computing MIN */ - delta = temp * (std::min)(delta, pnorm / Scalar(.1)); - par /= temp; - } else if (!(par != 0. && ratio < Scalar(.75))) { - delta = pnorm / Scalar(.5); - par = Scalar(.5) * par; - } - - /* test for successful iteration. */ - if (ratio >= Scalar(1e-4)) { - /* successful iteration. update x, fvec, and their norms. */ - x = wa2; - wa2 = diag.cwiseProduct(x); - fvec = wa4; - xnorm = wa2.stableNorm(); - fnorm = fnorm1; - ++iter; - } - - /* tests for convergence. */ - if (abs(actred) <= parameters.ftol && prered <= parameters.ftol && Scalar(.5) * ratio <= 1. && delta <= parameters.xtol * xnorm) - return LevenbergMarquardtSpace::RelativeErrorAndReductionTooSmall; - if (abs(actred) <= parameters.ftol && prered <= parameters.ftol && Scalar(.5) * ratio <= 1.) - return LevenbergMarquardtSpace::RelativeReductionTooSmall; - if (delta <= parameters.xtol * xnorm) - return LevenbergMarquardtSpace::RelativeErrorTooSmall; - - /* tests for termination and stringent tolerances. */ - if (nfev >= parameters.maxfev) - return LevenbergMarquardtSpace::TooManyFunctionEvaluation; - if (abs(actred) <= NumTraits<Scalar>::epsilon() && prered <= NumTraits<Scalar>::epsilon() && Scalar(.5) * ratio <= 1.) - return LevenbergMarquardtSpace::FtolTooSmall; - if (delta <= NumTraits<Scalar>::epsilon() * xnorm) - return LevenbergMarquardtSpace::XtolTooSmall; - if (gnorm <= NumTraits<Scalar>::epsilon()) - return LevenbergMarquardtSpace::GtolTooSmall; - - } while (ratio < Scalar(1e-4)); - - return LevenbergMarquardtSpace::Running; -} - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::minimizeOptimumStorage(FVectorType &x) -{ - LevenbergMarquardtSpace::Status status = minimizeOptimumStorageInit(x); - if (status==LevenbergMarquardtSpace::ImproperInputParameters) - return status; - do { - status = minimizeOptimumStorageOneStep(x); - } while (status==LevenbergMarquardtSpace::Running); - return status; -} - -template<typename FunctorType, typename Scalar> -LevenbergMarquardtSpace::Status -LevenbergMarquardt<FunctorType,Scalar>::lmdif1( - FunctorType &functor, - FVectorType &x, - Index *nfev, - const Scalar tol - ) -{ - Index n = x.size(); - Index m = functor.values(); - - /* check the input parameters for errors. */ - if (n <= 0 || m < n || tol < 0.) - return LevenbergMarquardtSpace::ImproperInputParameters; - - NumericalDiff<FunctorType> numDiff(functor); - // embedded LevenbergMarquardt - LevenbergMarquardt<NumericalDiff<FunctorType>, Scalar > lm(numDiff); - lm.parameters.ftol = tol; - lm.parameters.xtol = tol; - lm.parameters.maxfev = 200*(n+1); - - LevenbergMarquardtSpace::Status info = LevenbergMarquardtSpace::Status(lm.minimize(x)); - if (nfev) - * nfev = lm.nfev; - return info; -} - -} // end namespace Eigen - -#endif // EIGEN_LEVENBERGMARQUARDT__H - -//vim: ai ts=4 sts=4 et sw=4 diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/chkder.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/chkder.h deleted file mode 100644 index db8ff7d6..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/chkder.h +++ /dev/null @@ -1,66 +0,0 @@ -#define chkder_log10e 0.43429448190325182765 -#define chkder_factor 100. - -namespace Eigen { - -namespace internal { - -template<typename Scalar> -void chkder( - const Matrix< Scalar, Dynamic, 1 > &x, - const Matrix< Scalar, Dynamic, 1 > &fvec, - const Matrix< Scalar, Dynamic, Dynamic > &fjac, - Matrix< Scalar, Dynamic, 1 > &xp, - const Matrix< Scalar, Dynamic, 1 > &fvecp, - int mode, - Matrix< Scalar, Dynamic, 1 > &err - ) -{ - using std::sqrt; - using std::abs; - using std::log; - - typedef DenseIndex Index; - - const Scalar eps = sqrt(NumTraits<Scalar>::epsilon()); - const Scalar epsf = chkder_factor * NumTraits<Scalar>::epsilon(); - const Scalar epslog = chkder_log10e * log(eps); - Scalar temp; - - const Index m = fvec.size(), n = x.size(); - - if (mode != 2) { - /* mode = 1. */ - xp.resize(n); - for (Index j = 0; j < n; ++j) { - temp = eps * abs(x[j]); - if (temp == 0.) - temp = eps; - xp[j] = x[j] + temp; - } - } - else { - /* mode = 2. */ - err.setZero(m); - for (Index j = 0; j < n; ++j) { - temp = abs(x[j]); - if (temp == 0.) - temp = 1.; - err += temp * fjac.col(j); - } - for (Index i = 0; i < m; ++i) { - temp = 1.; - if (fvec[i] != 0. && fvecp[i] != 0. && abs(fvecp[i] - fvec[i]) >= epsf * abs(fvec[i])) - temp = eps * abs((fvecp[i] - fvec[i]) / eps - err[i]) / (abs(fvec[i]) + abs(fvecp[i])); - err[i] = 1.; - if (temp > NumTraits<Scalar>::epsilon() && temp < eps) - err[i] = (chkder_log10e * log(temp) - epslog) / epslog; - if (temp >= eps) - err[i] = 0.; - } - } -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/covar.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/covar.h deleted file mode 100644 index 68260d19..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/covar.h +++ /dev/null @@ -1,70 +0,0 @@ -namespace Eigen { - -namespace internal { - -template <typename Scalar> -void covar( - Matrix< Scalar, Dynamic, Dynamic > &r, - const VectorXi &ipvt, - Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) ) -{ - using std::abs; - typedef DenseIndex Index; - - /* Local variables */ - Index i, j, k, l, ii, jj; - bool sing; - Scalar temp; - - /* Function Body */ - const Index n = r.cols(); - const Scalar tolr = tol * abs(r(0,0)); - Matrix< Scalar, Dynamic, 1 > wa(n); - eigen_assert(ipvt.size()==n); - - /* form the inverse of r in the full upper triangle of r. */ - l = -1; - for (k = 0; k < n; ++k) - if (abs(r(k,k)) > tolr) { - r(k,k) = 1. / r(k,k); - for (j = 0; j <= k-1; ++j) { - temp = r(k,k) * r(j,k); - r(j,k) = 0.; - r.col(k).head(j+1) -= r.col(j).head(j+1) * temp; - } - l = k; - } - - /* form the full upper triangle of the inverse of (r transpose)*r */ - /* in the full upper triangle of r. */ - for (k = 0; k <= l; ++k) { - for (j = 0; j <= k-1; ++j) - r.col(j).head(j+1) += r.col(k).head(j+1) * r(j,k); - r.col(k).head(k+1) *= r(k,k); - } - - /* form the full lower triangle of the covariance matrix */ - /* in the strict lower triangle of r and in wa. */ - for (j = 0; j < n; ++j) { - jj = ipvt[j]; - sing = j > l; - for (i = 0; i <= j; ++i) { - if (sing) - r(i,j) = 0.; - ii = ipvt[i]; - if (ii > jj) - r(ii,jj) = r(i,j); - if (ii < jj) - r(jj,ii) = r(i,j); - } - wa[jj] = r(j,j); - } - - /* symmetrize the covariance matrix in r. */ - r.topLeftCorner(n,n).template triangularView<StrictlyUpper>() = r.topLeftCorner(n,n).transpose(); - r.diagonal() = wa; -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/dogleg.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/dogleg.h deleted file mode 100644 index 80c5d277..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/dogleg.h +++ /dev/null @@ -1,107 +0,0 @@ -namespace Eigen { - -namespace internal { - -template <typename Scalar> -void dogleg( - const Matrix< Scalar, Dynamic, Dynamic > &qrfac, - const Matrix< Scalar, Dynamic, 1 > &diag, - const Matrix< Scalar, Dynamic, 1 > &qtb, - Scalar delta, - Matrix< Scalar, Dynamic, 1 > &x) -{ - using std::abs; - using std::sqrt; - - typedef DenseIndex Index; - - /* Local variables */ - Index i, j; - Scalar sum, temp, alpha, bnorm; - Scalar gnorm, qnorm; - Scalar sgnorm; - - /* Function Body */ - const Scalar epsmch = NumTraits<Scalar>::epsilon(); - const Index n = qrfac.cols(); - eigen_assert(n==qtb.size()); - eigen_assert(n==x.size()); - eigen_assert(n==diag.size()); - Matrix< Scalar, Dynamic, 1 > wa1(n), wa2(n); - - /* first, calculate the gauss-newton direction. */ - for (j = n-1; j >=0; --j) { - temp = qrfac(j,j); - if (temp == 0.) { - temp = epsmch * qrfac.col(j).head(j+1).maxCoeff(); - if (temp == 0.) - temp = epsmch; - } - if (j==n-1) - x[j] = qtb[j] / temp; - else - x[j] = (qtb[j] - qrfac.row(j).tail(n-j-1).dot(x.tail(n-j-1))) / temp; - } - - /* test whether the gauss-newton direction is acceptable. */ - qnorm = diag.cwiseProduct(x).stableNorm(); - if (qnorm <= delta) - return; - - // TODO : this path is not tested by Eigen unit tests - - /* the gauss-newton direction is not acceptable. */ - /* next, calculate the scaled gradient direction. */ - - wa1.fill(0.); - for (j = 0; j < n; ++j) { - wa1.tail(n-j) += qrfac.row(j).tail(n-j) * qtb[j]; - wa1[j] /= diag[j]; - } - - /* calculate the norm of the scaled gradient and test for */ - /* the special case in which the scaled gradient is zero. */ - gnorm = wa1.stableNorm(); - sgnorm = 0.; - alpha = delta / qnorm; - if (gnorm == 0.) - goto algo_end; - - /* calculate the point along the scaled gradient */ - /* at which the quadratic is minimized. */ - wa1.array() /= (diag*gnorm).array(); - // TODO : once unit tests cover this part,: - // wa2 = qrfac.template triangularView<Upper>() * wa1; - for (j = 0; j < n; ++j) { - sum = 0.; - for (i = j; i < n; ++i) { - sum += qrfac(j,i) * wa1[i]; - } - wa2[j] = sum; - } - temp = wa2.stableNorm(); - sgnorm = gnorm / temp / temp; - - /* test whether the scaled gradient direction is acceptable. */ - alpha = 0.; - if (sgnorm >= delta) - goto algo_end; - - /* the scaled gradient direction is not acceptable. */ - /* finally, calculate the point along the dogleg */ - /* at which the quadratic is minimized. */ - bnorm = qtb.stableNorm(); - temp = bnorm / gnorm * (bnorm / qnorm) * (sgnorm / delta); - temp = temp - delta / qnorm * numext::abs2(sgnorm / delta) + sqrt(numext::abs2(temp - delta / qnorm) + (1.-numext::abs2(delta / qnorm)) * (1.-numext::abs2(sgnorm / delta))); - alpha = delta / qnorm * (1. - numext::abs2(sgnorm / delta)) / temp; -algo_end: - - /* form appropriate convex combination of the gauss-newton */ - /* direction and the scaled gradient direction. */ - temp = (1.-alpha) * (std::min)(sgnorm,delta); - x = temp * wa1 + alpha * x; -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/fdjac1.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/fdjac1.h deleted file mode 100644 index bb7cf267..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/fdjac1.h +++ /dev/null @@ -1,79 +0,0 @@ -namespace Eigen { - -namespace internal { - -template<typename FunctorType, typename Scalar> -DenseIndex fdjac1( - const FunctorType &Functor, - Matrix< Scalar, Dynamic, 1 > &x, - Matrix< Scalar, Dynamic, 1 > &fvec, - Matrix< Scalar, Dynamic, Dynamic > &fjac, - DenseIndex ml, DenseIndex mu, - Scalar epsfcn) -{ - using std::sqrt; - using std::abs; - - typedef DenseIndex Index; - - /* Local variables */ - Scalar h; - Index j, k; - Scalar eps, temp; - Index msum; - int iflag; - Index start, length; - - /* Function Body */ - const Scalar epsmch = NumTraits<Scalar>::epsilon(); - const Index n = x.size(); - eigen_assert(fvec.size()==n); - Matrix< Scalar, Dynamic, 1 > wa1(n); - Matrix< Scalar, Dynamic, 1 > wa2(n); - - eps = sqrt((std::max)(epsfcn,epsmch)); - msum = ml + mu + 1; - if (msum >= n) { - /* computation of dense approximate jacobian. */ - for (j = 0; j < n; ++j) { - temp = x[j]; - h = eps * abs(temp); - if (h == 0.) - h = eps; - x[j] = temp + h; - iflag = Functor(x, wa1); - if (iflag < 0) - return iflag; - x[j] = temp; - fjac.col(j) = (wa1-fvec)/h; - } - - }else { - /* computation of banded approximate jacobian. */ - for (k = 0; k < msum; ++k) { - for (j = k; (msum<0) ? (j>n): (j<n); j += msum) { - wa2[j] = x[j]; - h = eps * abs(wa2[j]); - if (h == 0.) h = eps; - x[j] = wa2[j] + h; - } - iflag = Functor(x, wa1); - if (iflag < 0) - return iflag; - for (j = k; (msum<0) ? (j>n): (j<n); j += msum) { - x[j] = wa2[j]; - h = eps * abs(wa2[j]); - if (h == 0.) h = eps; - fjac.col(j).setZero(); - start = std::max<Index>(0,j-mu); - length = (std::min)(n-1, j+ml) - start + 1; - fjac.col(j).segment(start, length) = ( wa1.segment(start, length)-fvec.segment(start, length))/h; - } - } - } - return 0; -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/lmpar.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/lmpar.h deleted file mode 100644 index 4c17d4cd..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/lmpar.h +++ /dev/null @@ -1,298 +0,0 @@ -namespace Eigen { - -namespace internal { - -template <typename Scalar> -void lmpar( - Matrix< Scalar, Dynamic, Dynamic > &r, - const VectorXi &ipvt, - const Matrix< Scalar, Dynamic, 1 > &diag, - const Matrix< Scalar, Dynamic, 1 > &qtb, - Scalar delta, - Scalar &par, - Matrix< Scalar, Dynamic, 1 > &x) -{ - using std::abs; - using std::sqrt; - typedef DenseIndex Index; - - /* Local variables */ - Index i, j, l; - Scalar fp; - Scalar parc, parl; - Index iter; - Scalar temp, paru; - Scalar gnorm; - Scalar dxnorm; - - - /* Function Body */ - const Scalar dwarf = (std::numeric_limits<Scalar>::min)(); - const Index n = r.cols(); - eigen_assert(n==diag.size()); - eigen_assert(n==qtb.size()); - eigen_assert(n==x.size()); - - Matrix< Scalar, Dynamic, 1 > wa1, wa2; - - /* compute and store in x the gauss-newton direction. if the */ - /* jacobian is rank-deficient, obtain a least squares solution. */ - Index nsing = n-1; - wa1 = qtb; - for (j = 0; j < n; ++j) { - if (r(j,j) == 0. && nsing == n-1) - nsing = j - 1; - if (nsing < n-1) - wa1[j] = 0.; - } - for (j = nsing; j>=0; --j) { - wa1[j] /= r(j,j); - temp = wa1[j]; - for (i = 0; i < j ; ++i) - wa1[i] -= r(i,j) * temp; - } - - for (j = 0; j < n; ++j) - x[ipvt[j]] = wa1[j]; - - /* initialize the iteration counter. */ - /* evaluate the function at the origin, and test */ - /* for acceptance of the gauss-newton direction. */ - iter = 0; - wa2 = diag.cwiseProduct(x); - dxnorm = wa2.blueNorm(); - fp = dxnorm - delta; - if (fp <= Scalar(0.1) * delta) { - par = 0; - return; - } - - /* if the jacobian is not rank deficient, the newton */ - /* step provides a lower bound, parl, for the zero of */ - /* the function. otherwise set this bound to zero. */ - parl = 0.; - if (nsing >= n-1) { - for (j = 0; j < n; ++j) { - l = ipvt[j]; - wa1[j] = diag[l] * (wa2[l] / dxnorm); - } - // it's actually a triangularView.solveInplace(), though in a weird - // way: - for (j = 0; j < n; ++j) { - Scalar sum = 0.; - for (i = 0; i < j; ++i) - sum += r(i,j) * wa1[i]; - wa1[j] = (wa1[j] - sum) / r(j,j); - } - temp = wa1.blueNorm(); - parl = fp / delta / temp / temp; - } - - /* calculate an upper bound, paru, for the zero of the function. */ - for (j = 0; j < n; ++j) - wa1[j] = r.col(j).head(j+1).dot(qtb.head(j+1)) / diag[ipvt[j]]; - - gnorm = wa1.stableNorm(); - paru = gnorm / delta; - if (paru == 0.) - paru = dwarf / (std::min)(delta,Scalar(0.1)); - - /* if the input par lies outside of the interval (parl,paru), */ - /* set par to the closer endpoint. */ - par = (std::max)(par,parl); - par = (std::min)(par,paru); - if (par == 0.) - par = gnorm / dxnorm; - - /* beginning of an iteration. */ - while (true) { - ++iter; - - /* evaluate the function at the current value of par. */ - if (par == 0.) - par = (std::max)(dwarf,Scalar(.001) * paru); /* Computing MAX */ - wa1 = sqrt(par)* diag; - - Matrix< Scalar, Dynamic, 1 > sdiag(n); - qrsolv<Scalar>(r, ipvt, wa1, qtb, x, sdiag); - - wa2 = diag.cwiseProduct(x); - dxnorm = wa2.blueNorm(); - temp = fp; - fp = dxnorm - delta; - - /* if the function is small enough, accept the current value */ - /* of par. also test for the exceptional cases where parl */ - /* is zero or the number of iterations has reached 10. */ - if (abs(fp) <= Scalar(0.1) * delta || (parl == 0. && fp <= temp && temp < 0.) || iter == 10) - break; - - /* compute the newton correction. */ - for (j = 0; j < n; ++j) { - l = ipvt[j]; - wa1[j] = diag[l] * (wa2[l] / dxnorm); - } - for (j = 0; j < n; ++j) { - wa1[j] /= sdiag[j]; - temp = wa1[j]; - for (i = j+1; i < n; ++i) - wa1[i] -= r(i,j) * temp; - } - temp = wa1.blueNorm(); - parc = fp / delta / temp / temp; - - /* depending on the sign of the function, update parl or paru. */ - if (fp > 0.) - parl = (std::max)(parl,par); - if (fp < 0.) - paru = (std::min)(paru,par); - - /* compute an improved estimate for par. */ - /* Computing MAX */ - par = (std::max)(parl,par+parc); - - /* end of an iteration. */ - } - - /* termination. */ - if (iter == 0) - par = 0.; - return; -} - -template <typename Scalar> -void lmpar2( - const ColPivHouseholderQR<Matrix< Scalar, Dynamic, Dynamic> > &qr, - const Matrix< Scalar, Dynamic, 1 > &diag, - const Matrix< Scalar, Dynamic, 1 > &qtb, - Scalar delta, - Scalar &par, - Matrix< Scalar, Dynamic, 1 > &x) - -{ - using std::sqrt; - using std::abs; - typedef DenseIndex Index; - - /* Local variables */ - Index j; - Scalar fp; - Scalar parc, parl; - Index iter; - Scalar temp, paru; - Scalar gnorm; - Scalar dxnorm; - - - /* Function Body */ - const Scalar dwarf = (std::numeric_limits<Scalar>::min)(); - const Index n = qr.matrixQR().cols(); - eigen_assert(n==diag.size()); - eigen_assert(n==qtb.size()); - - Matrix< Scalar, Dynamic, 1 > wa1, wa2; - - /* compute and store in x the gauss-newton direction. if the */ - /* jacobian is rank-deficient, obtain a least squares solution. */ - -// const Index rank = qr.nonzeroPivots(); // exactly double(0.) - const Index rank = qr.rank(); // use a threshold - wa1 = qtb; - wa1.tail(n-rank).setZero(); - qr.matrixQR().topLeftCorner(rank, rank).template triangularView<Upper>().solveInPlace(wa1.head(rank)); - - x = qr.colsPermutation()*wa1; - - /* initialize the iteration counter. */ - /* evaluate the function at the origin, and test */ - /* for acceptance of the gauss-newton direction. */ - iter = 0; - wa2 = diag.cwiseProduct(x); - dxnorm = wa2.blueNorm(); - fp = dxnorm - delta; - if (fp <= Scalar(0.1) * delta) { - par = 0; - return; - } - - /* if the jacobian is not rank deficient, the newton */ - /* step provides a lower bound, parl, for the zero of */ - /* the function. otherwise set this bound to zero. */ - parl = 0.; - if (rank==n) { - wa1 = qr.colsPermutation().inverse() * diag.cwiseProduct(wa2)/dxnorm; - qr.matrixQR().topLeftCorner(n, n).transpose().template triangularView<Lower>().solveInPlace(wa1); - temp = wa1.blueNorm(); - parl = fp / delta / temp / temp; - } - - /* calculate an upper bound, paru, for the zero of the function. */ - for (j = 0; j < n; ++j) - wa1[j] = qr.matrixQR().col(j).head(j+1).dot(qtb.head(j+1)) / diag[qr.colsPermutation().indices()(j)]; - - gnorm = wa1.stableNorm(); - paru = gnorm / delta; - if (paru == 0.) - paru = dwarf / (std::min)(delta,Scalar(0.1)); - - /* if the input par lies outside of the interval (parl,paru), */ - /* set par to the closer endpoint. */ - par = (std::max)(par,parl); - par = (std::min)(par,paru); - if (par == 0.) - par = gnorm / dxnorm; - - /* beginning of an iteration. */ - Matrix< Scalar, Dynamic, Dynamic > s = qr.matrixQR(); - while (true) { - ++iter; - - /* evaluate the function at the current value of par. */ - if (par == 0.) - par = (std::max)(dwarf,Scalar(.001) * paru); /* Computing MAX */ - wa1 = sqrt(par)* diag; - - Matrix< Scalar, Dynamic, 1 > sdiag(n); - qrsolv<Scalar>(s, qr.colsPermutation().indices(), wa1, qtb, x, sdiag); - - wa2 = diag.cwiseProduct(x); - dxnorm = wa2.blueNorm(); - temp = fp; - fp = dxnorm - delta; - - /* if the function is small enough, accept the current value */ - /* of par. also test for the exceptional cases where parl */ - /* is zero or the number of iterations has reached 10. */ - if (abs(fp) <= Scalar(0.1) * delta || (parl == 0. && fp <= temp && temp < 0.) || iter == 10) - break; - - /* compute the newton correction. */ - wa1 = qr.colsPermutation().inverse() * diag.cwiseProduct(wa2/dxnorm); - // we could almost use this here, but the diagonal is outside qr, in sdiag[] - // qr.matrixQR().topLeftCorner(n, n).transpose().template triangularView<Lower>().solveInPlace(wa1); - for (j = 0; j < n; ++j) { - wa1[j] /= sdiag[j]; - temp = wa1[j]; - for (Index i = j+1; i < n; ++i) - wa1[i] -= s(i,j) * temp; - } - temp = wa1.blueNorm(); - parc = fp / delta / temp / temp; - - /* depending on the sign of the function, update parl or paru. */ - if (fp > 0.) - parl = (std::max)(parl,par); - if (fp < 0.) - paru = (std::min)(paru,par); - - /* compute an improved estimate for par. */ - par = (std::max)(parl,par+parc); - } - if (iter == 0) - par = 0.; - return; -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/qrsolv.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/qrsolv.h deleted file mode 100644 index 4f2f560b..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/qrsolv.h +++ /dev/null @@ -1,91 +0,0 @@ -namespace Eigen { - -namespace internal { - -// TODO : once qrsolv2 is removed, use ColPivHouseholderQR or PermutationMatrix instead of ipvt -template <typename Scalar> -void qrsolv( - Matrix< Scalar, Dynamic, Dynamic > &s, - // TODO : use a PermutationMatrix once lmpar is no more: - const VectorXi &ipvt, - const Matrix< Scalar, Dynamic, 1 > &diag, - const Matrix< Scalar, Dynamic, 1 > &qtb, - Matrix< Scalar, Dynamic, 1 > &x, - Matrix< Scalar, Dynamic, 1 > &sdiag) - -{ - typedef DenseIndex Index; - - /* Local variables */ - Index i, j, k, l; - Scalar temp; - Index n = s.cols(); - Matrix< Scalar, Dynamic, 1 > wa(n); - JacobiRotation<Scalar> givens; - - /* Function Body */ - // the following will only change the lower triangular part of s, including - // the diagonal, though the diagonal is restored afterward - - /* copy r and (q transpose)*b to preserve input and initialize s. */ - /* in particular, save the diagonal elements of r in x. */ - x = s.diagonal(); - wa = qtb; - - s.topLeftCorner(n,n).template triangularView<StrictlyLower>() = s.topLeftCorner(n,n).transpose(); - - /* eliminate the diagonal matrix d using a givens rotation. */ - for (j = 0; j < n; ++j) { - - /* prepare the row of d to be eliminated, locating the */ - /* diagonal element using p from the qr factorization. */ - l = ipvt[j]; - if (diag[l] == 0.) - break; - sdiag.tail(n-j).setZero(); - sdiag[j] = diag[l]; - - /* the transformations to eliminate the row of d */ - /* modify only a single element of (q transpose)*b */ - /* beyond the first n, which is initially zero. */ - Scalar qtbpj = 0.; - for (k = j; k < n; ++k) { - /* determine a givens rotation which eliminates the */ - /* appropriate element in the current row of d. */ - givens.makeGivens(-s(k,k), sdiag[k]); - - /* compute the modified diagonal element of r and */ - /* the modified element of ((q transpose)*b,0). */ - s(k,k) = givens.c() * s(k,k) + givens.s() * sdiag[k]; - temp = givens.c() * wa[k] + givens.s() * qtbpj; - qtbpj = -givens.s() * wa[k] + givens.c() * qtbpj; - wa[k] = temp; - - /* accumulate the transformation in the row of s. */ - for (i = k+1; i<n; ++i) { - temp = givens.c() * s(i,k) + givens.s() * sdiag[i]; - sdiag[i] = -givens.s() * s(i,k) + givens.c() * sdiag[i]; - s(i,k) = temp; - } - } - } - - /* solve the triangular system for z. if the system is */ - /* singular, then obtain a least squares solution. */ - Index nsing; - for(nsing=0; nsing<n && sdiag[nsing]!=0; nsing++) {} - - wa.tail(n-nsing).setZero(); - s.topLeftCorner(nsing, nsing).transpose().template triangularView<Upper>().solveInPlace(wa.head(nsing)); - - // restore - sdiag = s.diagonal(); - s.diagonal() = x; - - /* permute the components of z back to components of x. */ - for (j = 0; j < n; ++j) x[ipvt[j]] = wa[j]; -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/r1mpyq.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/r1mpyq.h deleted file mode 100644 index 36ff700e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/r1mpyq.h +++ /dev/null @@ -1,30 +0,0 @@ -namespace Eigen { - -namespace internal { - -// TODO : move this to GivensQR once there's such a thing in Eigen - -template <typename Scalar> -void r1mpyq(DenseIndex m, DenseIndex n, Scalar *a, const std::vector<JacobiRotation<Scalar> > &v_givens, const std::vector<JacobiRotation<Scalar> > &w_givens) -{ - typedef DenseIndex Index; - - /* apply the first set of givens rotations to a. */ - for (Index j = n-2; j>=0; --j) - for (Index i = 0; i<m; ++i) { - Scalar temp = v_givens[j].c() * a[i+m*j] - v_givens[j].s() * a[i+m*(n-1)]; - a[i+m*(n-1)] = v_givens[j].s() * a[i+m*j] + v_givens[j].c() * a[i+m*(n-1)]; - a[i+m*j] = temp; - } - /* apply the second set of givens rotations to a. */ - for (Index j = 0; j<n-1; ++j) - for (Index i = 0; i<m; ++i) { - Scalar temp = w_givens[j].c() * a[i+m*j] + w_givens[j].s() * a[i+m*(n-1)]; - a[i+m*(n-1)] = -w_givens[j].s() * a[i+m*j] + w_givens[j].c() * a[i+m*(n-1)]; - a[i+m*j] = temp; - } -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/r1updt.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/r1updt.h deleted file mode 100644 index 09fc6525..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/r1updt.h +++ /dev/null @@ -1,99 +0,0 @@ -namespace Eigen { - -namespace internal { - -template <typename Scalar> -void r1updt( - Matrix< Scalar, Dynamic, Dynamic > &s, - const Matrix< Scalar, Dynamic, 1> &u, - std::vector<JacobiRotation<Scalar> > &v_givens, - std::vector<JacobiRotation<Scalar> > &w_givens, - Matrix< Scalar, Dynamic, 1> &v, - Matrix< Scalar, Dynamic, 1> &w, - bool *sing) -{ - typedef DenseIndex Index; - const JacobiRotation<Scalar> IdentityRotation = JacobiRotation<Scalar>(1,0); - - /* Local variables */ - const Index m = s.rows(); - const Index n = s.cols(); - Index i, j=1; - Scalar temp; - JacobiRotation<Scalar> givens; - - // r1updt had a broader usecase, but we don't use it here. And, more - // importantly, we can not test it. - eigen_assert(m==n); - eigen_assert(u.size()==m); - eigen_assert(v.size()==n); - eigen_assert(w.size()==n); - - /* move the nontrivial part of the last column of s into w. */ - w[n-1] = s(n-1,n-1); - - /* rotate the vector v into a multiple of the n-th unit vector */ - /* in such a way that a spike is introduced into w. */ - for (j=n-2; j>=0; --j) { - w[j] = 0.; - if (v[j] != 0.) { - /* determine a givens rotation which eliminates the */ - /* j-th element of v. */ - givens.makeGivens(-v[n-1], v[j]); - - /* apply the transformation to v and store the information */ - /* necessary to recover the givens rotation. */ - v[n-1] = givens.s() * v[j] + givens.c() * v[n-1]; - v_givens[j] = givens; - - /* apply the transformation to s and extend the spike in w. */ - for (i = j; i < m; ++i) { - temp = givens.c() * s(j,i) - givens.s() * w[i]; - w[i] = givens.s() * s(j,i) + givens.c() * w[i]; - s(j,i) = temp; - } - } else - v_givens[j] = IdentityRotation; - } - - /* add the spike from the rank 1 update to w. */ - w += v[n-1] * u; - - /* eliminate the spike. */ - *sing = false; - for (j = 0; j < n-1; ++j) { - if (w[j] != 0.) { - /* determine a givens rotation which eliminates the */ - /* j-th element of the spike. */ - givens.makeGivens(-s(j,j), w[j]); - - /* apply the transformation to s and reduce the spike in w. */ - for (i = j; i < m; ++i) { - temp = givens.c() * s(j,i) + givens.s() * w[i]; - w[i] = -givens.s() * s(j,i) + givens.c() * w[i]; - s(j,i) = temp; - } - - /* store the information necessary to recover the */ - /* givens rotation. */ - w_givens[j] = givens; - } else - v_givens[j] = IdentityRotation; - - /* test for zero diagonal elements in the output s. */ - if (s(j,j) == 0.) { - *sing = true; - } - } - /* move w back into the last column of the output s. */ - s(n-1,n-1) = w[n-1]; - - if (s(j,j) == 0.) { - *sing = true; - } - return; -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/rwupdt.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/rwupdt.h deleted file mode 100644 index 6ebf8563..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/rwupdt.h +++ /dev/null @@ -1,49 +0,0 @@ -namespace Eigen { - -namespace internal { - -template <typename Scalar> -void rwupdt( - Matrix< Scalar, Dynamic, Dynamic > &r, - const Matrix< Scalar, Dynamic, 1> &w, - Matrix< Scalar, Dynamic, 1> &b, - Scalar alpha) -{ - typedef DenseIndex Index; - - const Index n = r.cols(); - eigen_assert(r.rows()>=n); - std::vector<JacobiRotation<Scalar> > givens(n); - - /* Local variables */ - Scalar temp, rowj; - - /* Function Body */ - for (Index j = 0; j < n; ++j) { - rowj = w[j]; - - /* apply the previous transformations to */ - /* r(i,j), i=0,1,...,j-1, and to w(j). */ - for (Index i = 0; i < j; ++i) { - temp = givens[i].c() * r(i,j) + givens[i].s() * rowj; - rowj = -givens[i].s() * r(i,j) + givens[i].c() * rowj; - r(i,j) = temp; - } - - /* determine a givens rotation which eliminates w(j). */ - givens[j].makeGivens(-r(j,j), rowj); - - if (rowj == 0.) - continue; // givens[j] is identity - - /* apply the current transformation to r(j,j), b(j), and alpha. */ - r(j,j) = givens[j].c() * r(j,j) + givens[j].s() * rowj; - temp = givens[j].c() * b[j] + givens[j].s() * alpha; - alpha = -givens[j].s() * b[j] + givens[j].c() * alpha; - b[j] = temp; - } -} - -} // end namespace internal - -} // end namespace Eigen diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/NumericalDiff/NumericalDiff.h b/external/eigen/include/eigen3/unsupported/Eigen/src/NumericalDiff/NumericalDiff.h deleted file mode 100644 index ea5d8bc2..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/NumericalDiff/NumericalDiff.h +++ /dev/null @@ -1,130 +0,0 @@ -// -*- coding: utf-8 -// vim: set fileencoding=utf-8 - -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_NUMERICAL_DIFF_H -#define EIGEN_NUMERICAL_DIFF_H - -namespace Eigen { - -enum NumericalDiffMode { - Forward, - Central -}; - - -/** - * This class allows you to add a method df() to your functor, which will - * use numerical differentiation to compute an approximate of the - * derivative for the functor. Of course, if you have an analytical form - * for the derivative, you should rather implement df() by yourself. - * - * More information on - * http://en.wikipedia.org/wiki/Numerical_differentiation - * - * Currently only "Forward" and "Central" scheme are implemented. - */ -template<typename _Functor, NumericalDiffMode mode=Forward> -class NumericalDiff : public _Functor -{ -public: - typedef _Functor Functor; - typedef typename Functor::Scalar Scalar; - typedef typename Functor::InputType InputType; - typedef typename Functor::ValueType ValueType; - typedef typename Functor::JacobianType JacobianType; - - NumericalDiff(Scalar _epsfcn=0.) : Functor(), epsfcn(_epsfcn) {} - NumericalDiff(const Functor& f, Scalar _epsfcn=0.) : Functor(f), epsfcn(_epsfcn) {} - - // forward constructors - template<typename T0> - NumericalDiff(const T0& a0) : Functor(a0), epsfcn(0) {} - template<typename T0, typename T1> - NumericalDiff(const T0& a0, const T1& a1) : Functor(a0, a1), epsfcn(0) {} - template<typename T0, typename T1, typename T2> - NumericalDiff(const T0& a0, const T1& a1, const T2& a2) : Functor(a0, a1, a2), epsfcn(0) {} - - enum { - InputsAtCompileTime = Functor::InputsAtCompileTime, - ValuesAtCompileTime = Functor::ValuesAtCompileTime - }; - - /** - * return the number of evaluation of functor - */ - int df(const InputType& _x, JacobianType &jac) const - { - using std::sqrt; - using std::abs; - /* Local variables */ - Scalar h; - int nfev=0; - const typename InputType::Index n = _x.size(); - const Scalar eps = sqrt(((std::max)(epsfcn,NumTraits<Scalar>::epsilon() ))); - ValueType val1, val2; - InputType x = _x; - // TODO : we should do this only if the size is not already known - val1.resize(Functor::values()); - val2.resize(Functor::values()); - - // initialization - switch(mode) { - case Forward: - // compute f(x) - Functor::operator()(x, val1); nfev++; - break; - case Central: - // do nothing - break; - default: - eigen_assert(false); - }; - - // Function Body - for (int j = 0; j < n; ++j) { - h = eps * abs(x[j]); - if (h == 0.) { - h = eps; - } - switch(mode) { - case Forward: - x[j] += h; - Functor::operator()(x, val2); - nfev++; - x[j] = _x[j]; - jac.col(j) = (val2-val1)/h; - break; - case Central: - x[j] += h; - Functor::operator()(x, val2); nfev++; - x[j] -= 2*h; - Functor::operator()(x, val1); nfev++; - x[j] = _x[j]; - jac.col(j) = (val2-val1)/(2*h); - break; - default: - eigen_assert(false); - }; - } - return nfev; - } -private: - Scalar epsfcn; - - NumericalDiff& operator=(const NumericalDiff&); -}; - -} // end namespace Eigen - -//vim: ai ts=4 sts=4 et sw=4 -#endif // EIGEN_NUMERICAL_DIFF_H - diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/Companion.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/Companion.h deleted file mode 100644 index 6ab8f971..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/Companion.h +++ /dev/null @@ -1,275 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Manuel Yguel <manuel.yguel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_COMPANION_H -#define EIGEN_COMPANION_H - -// This file requires the user to include -// * Eigen/Core -// * Eigen/src/PolynomialSolver.h - -namespace Eigen { - -namespace internal { - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -template <typename T> -T radix(){ return 2; } - -template <typename T> -T radix2(){ return radix<T>()*radix<T>(); } - -template<int Size> -struct decrement_if_fixed_size -{ - enum { - ret = (Size == Dynamic) ? Dynamic : Size-1 }; -}; - -#endif - -template< typename _Scalar, int _Deg > -class companion -{ - public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Deg==Dynamic ? Dynamic : _Deg) - - enum { - Deg = _Deg, - Deg_1=decrement_if_fixed_size<Deg>::ret - }; - - typedef _Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef Matrix<Scalar, Deg, 1> RightColumn; - //typedef DiagonalMatrix< Scalar, Deg_1, Deg_1 > BottomLeftDiagonal; - typedef Matrix<Scalar, Deg_1, 1> BottomLeftDiagonal; - - typedef Matrix<Scalar, Deg, Deg> DenseCompanionMatrixType; - typedef Matrix< Scalar, _Deg, Deg_1 > LeftBlock; - typedef Matrix< Scalar, Deg_1, Deg_1 > BottomLeftBlock; - typedef Matrix< Scalar, 1, Deg_1 > LeftBlockFirstRow; - - typedef DenseIndex Index; - - public: - EIGEN_STRONG_INLINE const _Scalar operator()(Index row, Index col ) const - { - if( m_bl_diag.rows() > col ) - { - if( 0 < row ){ return m_bl_diag[col]; } - else{ return 0; } - } - else{ return m_monic[row]; } - } - - public: - template<typename VectorType> - void setPolynomial( const VectorType& poly ) - { - const Index deg = poly.size()-1; - m_monic = -poly.head(deg)/poly[deg]; - m_bl_diag.setOnes(deg-1); - } - - template<typename VectorType> - companion( const VectorType& poly ){ - setPolynomial( poly ); } - - public: - DenseCompanionMatrixType denseMatrix() const - { - const Index deg = m_monic.size(); - const Index deg_1 = deg-1; - DenseCompanionMatrixType companMat(deg,deg); - companMat << - ( LeftBlock(deg,deg_1) - << LeftBlockFirstRow::Zero(1,deg_1), - BottomLeftBlock::Identity(deg-1,deg-1)*m_bl_diag.asDiagonal() ).finished() - , m_monic; - return companMat; - } - - - - protected: - /** Helper function for the balancing algorithm. - * \returns true if the row and the column, having colNorm and rowNorm - * as norms, are balanced, false otherwise. - * colB and rowB are respectively the multipliers for - * the column and the row in order to balance them. - * */ - bool balanced( RealScalar colNorm, RealScalar rowNorm, - bool& isBalanced, RealScalar& colB, RealScalar& rowB ); - - /** Helper function for the balancing algorithm. - * \returns true if the row and the column, having colNorm and rowNorm - * as norms, are balanced, false otherwise. - * colB and rowB are respectively the multipliers for - * the column and the row in order to balance them. - * */ - bool balancedR( RealScalar colNorm, RealScalar rowNorm, - bool& isBalanced, RealScalar& colB, RealScalar& rowB ); - - public: - /** - * Balancing algorithm from B. N. PARLETT and C. REINSCH (1969) - * "Balancing a matrix for calculation of eigenvalues and eigenvectors" - * adapted to the case of companion matrices. - * A matrix with non zero row and non zero column is balanced - * for a certain norm if the i-th row and the i-th column - * have same norm for all i. - */ - void balance(); - - protected: - RightColumn m_monic; - BottomLeftDiagonal m_bl_diag; -}; - - - -template< typename _Scalar, int _Deg > -inline -bool companion<_Scalar,_Deg>::balanced( RealScalar colNorm, RealScalar rowNorm, - bool& isBalanced, RealScalar& colB, RealScalar& rowB ) -{ - if( RealScalar(0) == colNorm || RealScalar(0) == rowNorm ){ return true; } - else - { - //To find the balancing coefficients, if the radix is 2, - //one finds \f$ \sigma \f$ such that - // \f$ 2^{2\sigma-1} < rowNorm / colNorm \le 2^{2\sigma+1} \f$ - // then the balancing coefficient for the row is \f$ 1/2^{\sigma} \f$ - // and the balancing coefficient for the column is \f$ 2^{\sigma} \f$ - rowB = rowNorm / radix<RealScalar>(); - colB = RealScalar(1); - const RealScalar s = colNorm + rowNorm; - - while (colNorm < rowB) - { - colB *= radix<RealScalar>(); - colNorm *= radix2<RealScalar>(); - } - - rowB = rowNorm * radix<RealScalar>(); - - while (colNorm >= rowB) - { - colB /= radix<RealScalar>(); - colNorm /= radix2<RealScalar>(); - } - - //This line is used to avoid insubstantial balancing - if ((rowNorm + colNorm) < RealScalar(0.95) * s * colB) - { - isBalanced = false; - rowB = RealScalar(1) / colB; - return false; - } - else{ - return true; } - } -} - -template< typename _Scalar, int _Deg > -inline -bool companion<_Scalar,_Deg>::balancedR( RealScalar colNorm, RealScalar rowNorm, - bool& isBalanced, RealScalar& colB, RealScalar& rowB ) -{ - if( RealScalar(0) == colNorm || RealScalar(0) == rowNorm ){ return true; } - else - { - /** - * Set the norm of the column and the row to the geometric mean - * of the row and column norm - */ - const RealScalar q = colNorm/rowNorm; - if( !isApprox( q, _Scalar(1) ) ) - { - rowB = sqrt( colNorm/rowNorm ); - colB = RealScalar(1)/rowB; - - isBalanced = false; - return false; - } - else{ - return true; } - } -} - - -template< typename _Scalar, int _Deg > -void companion<_Scalar,_Deg>::balance() -{ - using std::abs; - EIGEN_STATIC_ASSERT( Deg == Dynamic || 1 < Deg, YOU_MADE_A_PROGRAMMING_MISTAKE ); - const Index deg = m_monic.size(); - const Index deg_1 = deg-1; - - bool hasConverged=false; - while( !hasConverged ) - { - hasConverged = true; - RealScalar colNorm,rowNorm; - RealScalar colB,rowB; - - //First row, first column excluding the diagonal - //============================================== - colNorm = abs(m_bl_diag[0]); - rowNorm = abs(m_monic[0]); - - //Compute balancing of the row and the column - if( !balanced( colNorm, rowNorm, hasConverged, colB, rowB ) ) - { - m_bl_diag[0] *= colB; - m_monic[0] *= rowB; - } - - //Middle rows and columns excluding the diagonal - //============================================== - for( Index i=1; i<deg_1; ++i ) - { - // column norm, excluding the diagonal - colNorm = abs(m_bl_diag[i]); - - // row norm, excluding the diagonal - rowNorm = abs(m_bl_diag[i-1]) + abs(m_monic[i]); - - //Compute balancing of the row and the column - if( !balanced( colNorm, rowNorm, hasConverged, colB, rowB ) ) - { - m_bl_diag[i] *= colB; - m_bl_diag[i-1] *= rowB; - m_monic[i] *= rowB; - } - } - - //Last row, last column excluding the diagonal - //============================================ - const Index ebl = m_bl_diag.size()-1; - VectorBlock<RightColumn,Deg_1> headMonic( m_monic, 0, deg_1 ); - colNorm = headMonic.array().abs().sum(); - rowNorm = abs( m_bl_diag[ebl] ); - - //Compute balancing of the row and the column - if( !balanced( colNorm, rowNorm, hasConverged, colB, rowB ) ) - { - headMonic *= colB; - m_bl_diag[ebl] *= rowB; - } - } -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_COMPANION_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/PolynomialSolver.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/PolynomialSolver.h deleted file mode 100644 index 5e0ecbb4..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/PolynomialSolver.h +++ /dev/null @@ -1,428 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Manuel Yguel <manuel.yguel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_POLYNOMIAL_SOLVER_H -#define EIGEN_POLYNOMIAL_SOLVER_H - -namespace Eigen { - -/** \ingroup Polynomials_Module - * \class PolynomialSolverBase. - * - * \brief Defined to be inherited by polynomial solvers: it provides - * convenient methods such as - * - real roots, - * - greatest, smallest complex roots, - * - real roots with greatest, smallest absolute real value, - * - greatest, smallest real roots. - * - * It stores the set of roots as a vector of complexes. - * - */ -template< typename _Scalar, int _Deg > -class PolynomialSolverBase -{ - public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Deg==Dynamic ? Dynamic : _Deg) - - typedef _Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef std::complex<RealScalar> RootType; - typedef Matrix<RootType,_Deg,1> RootsType; - - typedef DenseIndex Index; - - protected: - template< typename OtherPolynomial > - inline void setPolynomial( const OtherPolynomial& poly ){ - m_roots.resize(poly.size()-1); } - - public: - template< typename OtherPolynomial > - inline PolynomialSolverBase( const OtherPolynomial& poly ){ - setPolynomial( poly() ); } - - inline PolynomialSolverBase(){} - - public: - /** \returns the complex roots of the polynomial */ - inline const RootsType& roots() const { return m_roots; } - - public: - /** Clear and fills the back insertion sequence with the real roots of the polynomial - * i.e. the real part of the complex roots that have an imaginary part which - * absolute value is smaller than absImaginaryThreshold. - * absImaginaryThreshold takes the dummy_precision associated - * with the _Scalar template parameter of the PolynomialSolver class as the default value. - * - * \param[out] bi_seq : the back insertion sequence (stl concept) - * \param[in] absImaginaryThreshold : the maximum bound of the imaginary part of a complex - * number that is considered as real. - * */ - template<typename Stl_back_insertion_sequence> - inline void realRoots( Stl_back_insertion_sequence& bi_seq, - const RealScalar& absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() ) const - { - using std::abs; - bi_seq.clear(); - for(Index i=0; i<m_roots.size(); ++i ) - { - if( abs( m_roots[i].imag() ) < absImaginaryThreshold ){ - bi_seq.push_back( m_roots[i].real() ); } - } - } - - protected: - template<typename squaredNormBinaryPredicate> - inline const RootType& selectComplexRoot_withRespectToNorm( squaredNormBinaryPredicate& pred ) const - { - Index res=0; - RealScalar norm2 = numext::abs2( m_roots[0] ); - for( Index i=1; i<m_roots.size(); ++i ) - { - const RealScalar currNorm2 = numext::abs2( m_roots[i] ); - if( pred( currNorm2, norm2 ) ){ - res=i; norm2=currNorm2; } - } - return m_roots[res]; - } - - public: - /** - * \returns the complex root with greatest norm. - */ - inline const RootType& greatestRoot() const - { - std::greater<RealScalar> greater; - return selectComplexRoot_withRespectToNorm( greater ); - } - - /** - * \returns the complex root with smallest norm. - */ - inline const RootType& smallestRoot() const - { - std::less<RealScalar> less; - return selectComplexRoot_withRespectToNorm( less ); - } - - protected: - template<typename squaredRealPartBinaryPredicate> - inline const RealScalar& selectRealRoot_withRespectToAbsRealPart( - squaredRealPartBinaryPredicate& pred, - bool& hasArealRoot, - const RealScalar& absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() ) const - { - using std::abs; - hasArealRoot = false; - Index res=0; - RealScalar abs2(0); - - for( Index i=0; i<m_roots.size(); ++i ) - { - if( abs( m_roots[i].imag() ) <= absImaginaryThreshold ) - { - if( !hasArealRoot ) - { - hasArealRoot = true; - res = i; - abs2 = m_roots[i].real() * m_roots[i].real(); - } - else - { - const RealScalar currAbs2 = m_roots[i].real() * m_roots[i].real(); - if( pred( currAbs2, abs2 ) ) - { - abs2 = currAbs2; - res = i; - } - } - } - else if(!hasArealRoot) - { - if( abs( m_roots[i].imag() ) < abs( m_roots[res].imag() ) ){ - res = i;} - } - } - return numext::real_ref(m_roots[res]); - } - - - template<typename RealPartBinaryPredicate> - inline const RealScalar& selectRealRoot_withRespectToRealPart( - RealPartBinaryPredicate& pred, - bool& hasArealRoot, - const RealScalar& absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() ) const - { - using std::abs; - hasArealRoot = false; - Index res=0; - RealScalar val(0); - - for( Index i=0; i<m_roots.size(); ++i ) - { - if( abs( m_roots[i].imag() ) <= absImaginaryThreshold ) - { - if( !hasArealRoot ) - { - hasArealRoot = true; - res = i; - val = m_roots[i].real(); - } - else - { - const RealScalar curr = m_roots[i].real(); - if( pred( curr, val ) ) - { - val = curr; - res = i; - } - } - } - else - { - if( abs( m_roots[i].imag() ) < abs( m_roots[res].imag() ) ){ - res = i; } - } - } - return numext::real_ref(m_roots[res]); - } - - public: - /** - * \returns a real root with greatest absolute magnitude. - * A real root is defined as the real part of a complex root with absolute imaginary - * part smallest than absImaginaryThreshold. - * absImaginaryThreshold takes the dummy_precision associated - * with the _Scalar template parameter of the PolynomialSolver class as the default value. - * If no real root is found the boolean hasArealRoot is set to false and the real part of - * the root with smallest absolute imaginary part is returned instead. - * - * \param[out] hasArealRoot : boolean true if a real root is found according to the - * absImaginaryThreshold criterion, false otherwise. - * \param[in] absImaginaryThreshold : threshold on the absolute imaginary part to decide - * whether or not a root is real. - */ - inline const RealScalar& absGreatestRealRoot( - bool& hasArealRoot, - const RealScalar& absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() ) const - { - std::greater<RealScalar> greater; - return selectRealRoot_withRespectToAbsRealPart( greater, hasArealRoot, absImaginaryThreshold ); - } - - - /** - * \returns a real root with smallest absolute magnitude. - * A real root is defined as the real part of a complex root with absolute imaginary - * part smallest than absImaginaryThreshold. - * absImaginaryThreshold takes the dummy_precision associated - * with the _Scalar template parameter of the PolynomialSolver class as the default value. - * If no real root is found the boolean hasArealRoot is set to false and the real part of - * the root with smallest absolute imaginary part is returned instead. - * - * \param[out] hasArealRoot : boolean true if a real root is found according to the - * absImaginaryThreshold criterion, false otherwise. - * \param[in] absImaginaryThreshold : threshold on the absolute imaginary part to decide - * whether or not a root is real. - */ - inline const RealScalar& absSmallestRealRoot( - bool& hasArealRoot, - const RealScalar& absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() ) const - { - std::less<RealScalar> less; - return selectRealRoot_withRespectToAbsRealPart( less, hasArealRoot, absImaginaryThreshold ); - } - - - /** - * \returns the real root with greatest value. - * A real root is defined as the real part of a complex root with absolute imaginary - * part smallest than absImaginaryThreshold. - * absImaginaryThreshold takes the dummy_precision associated - * with the _Scalar template parameter of the PolynomialSolver class as the default value. - * If no real root is found the boolean hasArealRoot is set to false and the real part of - * the root with smallest absolute imaginary part is returned instead. - * - * \param[out] hasArealRoot : boolean true if a real root is found according to the - * absImaginaryThreshold criterion, false otherwise. - * \param[in] absImaginaryThreshold : threshold on the absolute imaginary part to decide - * whether or not a root is real. - */ - inline const RealScalar& greatestRealRoot( - bool& hasArealRoot, - const RealScalar& absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() ) const - { - std::greater<RealScalar> greater; - return selectRealRoot_withRespectToRealPart( greater, hasArealRoot, absImaginaryThreshold ); - } - - - /** - * \returns the real root with smallest value. - * A real root is defined as the real part of a complex root with absolute imaginary - * part smallest than absImaginaryThreshold. - * absImaginaryThreshold takes the dummy_precision associated - * with the _Scalar template parameter of the PolynomialSolver class as the default value. - * If no real root is found the boolean hasArealRoot is set to false and the real part of - * the root with smallest absolute imaginary part is returned instead. - * - * \param[out] hasArealRoot : boolean true if a real root is found according to the - * absImaginaryThreshold criterion, false otherwise. - * \param[in] absImaginaryThreshold : threshold on the absolute imaginary part to decide - * whether or not a root is real. - */ - inline const RealScalar& smallestRealRoot( - bool& hasArealRoot, - const RealScalar& absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() ) const - { - std::less<RealScalar> less; - return selectRealRoot_withRespectToRealPart( less, hasArealRoot, absImaginaryThreshold ); - } - - protected: - RootsType m_roots; -}; - -#define EIGEN_POLYNOMIAL_SOLVER_BASE_INHERITED_TYPES( BASE ) \ - typedef typename BASE::Scalar Scalar; \ - typedef typename BASE::RealScalar RealScalar; \ - typedef typename BASE::RootType RootType; \ - typedef typename BASE::RootsType RootsType; - - - -/** \ingroup Polynomials_Module - * - * \class PolynomialSolver - * - * \brief A polynomial solver - * - * Computes the complex roots of a real polynomial. - * - * \param _Scalar the scalar type, i.e., the type of the polynomial coefficients - * \param _Deg the degree of the polynomial, can be a compile time value or Dynamic. - * Notice that the number of polynomial coefficients is _Deg+1. - * - * This class implements a polynomial solver and provides convenient methods such as - * - real roots, - * - greatest, smallest complex roots, - * - real roots with greatest, smallest absolute real value. - * - greatest, smallest real roots. - * - * WARNING: this polynomial solver is experimental, part of the unsupported Eigen modules. - * - * - * Currently a QR algorithm is used to compute the eigenvalues of the companion matrix of - * the polynomial to compute its roots. - * This supposes that the complex moduli of the roots are all distinct: e.g. there should - * be no multiple roots or conjugate roots for instance. - * With 32bit (float) floating types this problem shows up frequently. - * However, almost always, correct accuracy is reached even in these cases for 64bit - * (double) floating types and small polynomial degree (<20). - */ -template<typename _Scalar, int _Deg> -class PolynomialSolver : public PolynomialSolverBase<_Scalar,_Deg> -{ - public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Deg==Dynamic ? Dynamic : _Deg) - - typedef PolynomialSolverBase<_Scalar,_Deg> PS_Base; - EIGEN_POLYNOMIAL_SOLVER_BASE_INHERITED_TYPES( PS_Base ) - - typedef Matrix<Scalar,_Deg,_Deg> CompanionMatrixType; - typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, - ComplexEigenSolver<CompanionMatrixType>, - EigenSolver<CompanionMatrixType> >::type EigenSolverType; - typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, Scalar, std::complex<Scalar> >::type ComplexScalar; - - public: - /** Computes the complex roots of a new polynomial. */ - template< typename OtherPolynomial > - void compute( const OtherPolynomial& poly ) - { - eigen_assert( Scalar(0) != poly[poly.size()-1] ); - eigen_assert( poly.size() > 1 ); - if(poly.size() > 2 ) - { - internal::companion<Scalar,_Deg> companion( poly ); - companion.balance(); - m_eigenSolver.compute( companion.denseMatrix() ); - m_roots = m_eigenSolver.eigenvalues(); - // cleanup noise in imaginary part of real roots: - // if the imaginary part is rather small compared to the real part - // and that cancelling the imaginary part yield a smaller evaluation, - // then it's safe to keep the real part only. - RealScalar coarse_prec = RealScalar(std::pow(4,poly.size()+1))*NumTraits<RealScalar>::epsilon(); - for(Index i = 0; i<m_roots.size(); ++i) - { - if( internal::isMuchSmallerThan(numext::abs(numext::imag(m_roots[i])), - numext::abs(numext::real(m_roots[i])), - coarse_prec) ) - { - ComplexScalar as_real_root = ComplexScalar(numext::real(m_roots[i])); - if( numext::abs(poly_eval(poly, as_real_root)) - <= numext::abs(poly_eval(poly, m_roots[i]))) - { - m_roots[i] = as_real_root; - } - } - } - } - else if(poly.size () == 2) - { - m_roots.resize(1); - m_roots[0] = -poly[0]/poly[1]; - } - } - - public: - template< typename OtherPolynomial > - inline PolynomialSolver( const OtherPolynomial& poly ){ - compute( poly ); } - - inline PolynomialSolver(){} - - protected: - using PS_Base::m_roots; - EigenSolverType m_eigenSolver; -}; - - -template< typename _Scalar > -class PolynomialSolver<_Scalar,1> : public PolynomialSolverBase<_Scalar,1> -{ - public: - typedef PolynomialSolverBase<_Scalar,1> PS_Base; - EIGEN_POLYNOMIAL_SOLVER_BASE_INHERITED_TYPES( PS_Base ) - - public: - /** Computes the complex roots of a new polynomial. */ - template< typename OtherPolynomial > - void compute( const OtherPolynomial& poly ) - { - eigen_assert( poly.size() == 2 ); - eigen_assert( Scalar(0) != poly[1] ); - m_roots[0] = -poly[0]/poly[1]; - } - - public: - template< typename OtherPolynomial > - inline PolynomialSolver( const OtherPolynomial& poly ){ - compute( poly ); } - - inline PolynomialSolver(){} - - protected: - using PS_Base::m_roots; -}; - -} // end namespace Eigen - -#endif // EIGEN_POLYNOMIAL_SOLVER_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/PolynomialUtils.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/PolynomialUtils.h deleted file mode 100644 index 394e857a..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Polynomials/PolynomialUtils.h +++ /dev/null @@ -1,143 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2010 Manuel Yguel <manuel.yguel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_POLYNOMIAL_UTILS_H -#define EIGEN_POLYNOMIAL_UTILS_H - -namespace Eigen { - -/** \ingroup Polynomials_Module - * \returns the evaluation of the polynomial at x using Horner algorithm. - * - * \param[in] poly : the vector of coefficients of the polynomial ordered - * by degrees i.e. poly[i] is the coefficient of degree i of the polynomial - * e.g. \f$ 1 + 3x^2 \f$ is stored as a vector \f$ [ 1, 0, 3 ] \f$. - * \param[in] x : the value to evaluate the polynomial at. - * - * \note for stability: - * \f$ |x| \le 1 \f$ - */ -template <typename Polynomials, typename T> -inline -T poly_eval_horner( const Polynomials& poly, const T& x ) -{ - T val=poly[poly.size()-1]; - for(DenseIndex i=poly.size()-2; i>=0; --i ){ - val = val*x + poly[i]; } - return val; -} - -/** \ingroup Polynomials_Module - * \returns the evaluation of the polynomial at x using stabilized Horner algorithm. - * - * \param[in] poly : the vector of coefficients of the polynomial ordered - * by degrees i.e. poly[i] is the coefficient of degree i of the polynomial - * e.g. \f$ 1 + 3x^2 \f$ is stored as a vector \f$ [ 1, 0, 3 ] \f$. - * \param[in] x : the value to evaluate the polynomial at. - */ -template <typename Polynomials, typename T> -inline -T poly_eval( const Polynomials& poly, const T& x ) -{ - typedef typename NumTraits<T>::Real Real; - - if( numext::abs2( x ) <= Real(1) ){ - return poly_eval_horner( poly, x ); } - else - { - T val=poly[0]; - T inv_x = T(1)/x; - for( DenseIndex i=1; i<poly.size(); ++i ){ - val = val*inv_x + poly[i]; } - - return numext::pow(x,(T)(poly.size()-1)) * val; - } -} - -/** \ingroup Polynomials_Module - * \returns a maximum bound for the absolute value of any root of the polynomial. - * - * \param[in] poly : the vector of coefficients of the polynomial ordered - * by degrees i.e. poly[i] is the coefficient of degree i of the polynomial - * e.g. \f$ 1 + 3x^2 \f$ is stored as a vector \f$ [ 1, 0, 3 ] \f$. - * - * \pre - * the leading coefficient of the input polynomial poly must be non zero - */ -template <typename Polynomial> -inline -typename NumTraits<typename Polynomial::Scalar>::Real cauchy_max_bound( const Polynomial& poly ) -{ - using std::abs; - typedef typename Polynomial::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real Real; - - eigen_assert( Scalar(0) != poly[poly.size()-1] ); - const Scalar inv_leading_coeff = Scalar(1)/poly[poly.size()-1]; - Real cb(0); - - for( DenseIndex i=0; i<poly.size()-1; ++i ){ - cb += abs(poly[i]*inv_leading_coeff); } - return cb + Real(1); -} - -/** \ingroup Polynomials_Module - * \returns a minimum bound for the absolute value of any non zero root of the polynomial. - * \param[in] poly : the vector of coefficients of the polynomial ordered - * by degrees i.e. poly[i] is the coefficient of degree i of the polynomial - * e.g. \f$ 1 + 3x^2 \f$ is stored as a vector \f$ [ 1, 0, 3 ] \f$. - */ -template <typename Polynomial> -inline -typename NumTraits<typename Polynomial::Scalar>::Real cauchy_min_bound( const Polynomial& poly ) -{ - using std::abs; - typedef typename Polynomial::Scalar Scalar; - typedef typename NumTraits<Scalar>::Real Real; - - DenseIndex i=0; - while( i<poly.size()-1 && Scalar(0) == poly(i) ){ ++i; } - if( poly.size()-1 == i ){ - return Real(1); } - - const Scalar inv_min_coeff = Scalar(1)/poly[i]; - Real cb(1); - for( DenseIndex j=i+1; j<poly.size(); ++j ){ - cb += abs(poly[j]*inv_min_coeff); } - return Real(1)/cb; -} - -/** \ingroup Polynomials_Module - * Given the roots of a polynomial compute the coefficients in the - * monomial basis of the monic polynomial with same roots and minimal degree. - * If RootVector is a vector of complexes, Polynomial should also be a vector - * of complexes. - * \param[in] rv : a vector containing the roots of a polynomial. - * \param[out] poly : the vector of coefficients of the polynomial ordered - * by degrees i.e. poly[i] is the coefficient of degree i of the polynomial - * e.g. \f$ 3 + x^2 \f$ is stored as a vector \f$ [ 3, 0, 1 ] \f$. - */ -template <typename RootVector, typename Polynomial> -void roots_to_monicPolynomial( const RootVector& rv, Polynomial& poly ) -{ - - typedef typename Polynomial::Scalar Scalar; - - poly.setZero( rv.size()+1 ); - poly[0] = -rv[0]; poly[1] = Scalar(1); - for( DenseIndex i=1; i< rv.size(); ++i ) - { - for( DenseIndex j=i+1; j>0; --j ){ poly[j] = poly[j-1] - rv[i]*poly[j]; } - poly[0] = -rv[i]*poly[0]; - } -} - -} // end namespace Eigen - -#endif // EIGEN_POLYNOMIAL_UTILS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineInplaceLU.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineInplaceLU.h deleted file mode 100644 index 6d0370d5..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineInplaceLU.h +++ /dev/null @@ -1,352 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Guillaume Saupin <guillaume.saupin@cea.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SKYLINEINPLACELU_H -#define EIGEN_SKYLINEINPLACELU_H - -namespace Eigen { - -/** \ingroup Skyline_Module - * - * \class SkylineInplaceLU - * - * \brief Inplace LU decomposition of a skyline matrix and associated features - * - * \param MatrixType the type of the matrix of which we are computing the LU factorization - * - */ -template<typename MatrixType> -class SkylineInplaceLU { -protected: - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::Index Index; - - typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; - -public: - - /** Creates a LU object and compute the respective factorization of \a matrix using - * flags \a flags. */ - SkylineInplaceLU(MatrixType& matrix, int flags = 0) - : /*m_matrix(matrix.rows(), matrix.cols()),*/ m_flags(flags), m_status(0), m_lu(matrix) { - m_precision = RealScalar(0.1) * Eigen::dummy_precision<RealScalar > (); - m_lu.IsRowMajor ? computeRowMajor() : compute(); - } - - /** Sets the relative threshold value used to prune zero coefficients during the decomposition. - * - * Setting a value greater than zero speeds up computation, and yields to an incomplete - * factorization with fewer non zero coefficients. Such approximate factors are especially - * useful to initialize an iterative solver. - * - * Note that the exact meaning of this parameter might depends on the actual - * backend. Moreover, not all backends support this feature. - * - * \sa precision() */ - void setPrecision(RealScalar v) { - m_precision = v; - } - - /** \returns the current precision. - * - * \sa setPrecision() */ - RealScalar precision() const { - return m_precision; - } - - /** Sets the flags. Possible values are: - * - CompleteFactorization - * - IncompleteFactorization - * - MemoryEfficient - * - one of the ordering methods - * - etc... - * - * \sa flags() */ - void setFlags(int f) { - m_flags = f; - } - - /** \returns the current flags */ - int flags() const { - return m_flags; - } - - void setOrderingMethod(int m) { - m_flags = m; - } - - int orderingMethod() const { - return m_flags; - } - - /** Computes/re-computes the LU factorization */ - void compute(); - void computeRowMajor(); - - /** \returns the lower triangular matrix L */ - //inline const MatrixType& matrixL() const { return m_matrixL; } - - /** \returns the upper triangular matrix U */ - //inline const MatrixType& matrixU() const { return m_matrixU; } - - template<typename BDerived, typename XDerived> - bool solve(const MatrixBase<BDerived> &b, MatrixBase<XDerived>* x, - const int transposed = 0) const; - - /** \returns true if the factorization succeeded */ - inline bool succeeded(void) const { - return m_succeeded; - } - -protected: - RealScalar m_precision; - int m_flags; - mutable int m_status; - bool m_succeeded; - MatrixType& m_lu; -}; - -/** Computes / recomputes the in place LU decomposition of the SkylineInplaceLU. - * using the default algorithm. - */ -template<typename MatrixType> -//template<typename _Scalar> -void SkylineInplaceLU<MatrixType>::compute() { - const size_t rows = m_lu.rows(); - const size_t cols = m_lu.cols(); - - eigen_assert(rows == cols && "We do not (yet) support rectangular LU."); - eigen_assert(!m_lu.IsRowMajor && "LU decomposition does not work with rowMajor Storage"); - - for (Index row = 0; row < rows; row++) { - const double pivot = m_lu.coeffDiag(row); - - //Lower matrix Columns update - const Index& col = row; - for (typename MatrixType::InnerLowerIterator lIt(m_lu, col); lIt; ++lIt) { - lIt.valueRef() /= pivot; - } - - //Upper matrix update -> contiguous memory access - typename MatrixType::InnerLowerIterator lIt(m_lu, col); - for (Index rrow = row + 1; rrow < m_lu.rows(); rrow++) { - typename MatrixType::InnerUpperIterator uItPivot(m_lu, row); - typename MatrixType::InnerUpperIterator uIt(m_lu, rrow); - const double coef = lIt.value(); - - uItPivot += (rrow - row - 1); - - //update upper part -> contiguous memory access - for (++uItPivot; uIt && uItPivot;) { - uIt.valueRef() -= uItPivot.value() * coef; - - ++uIt; - ++uItPivot; - } - ++lIt; - } - - //Upper matrix update -> non contiguous memory access - typename MatrixType::InnerLowerIterator lIt3(m_lu, col); - for (Index rrow = row + 1; rrow < m_lu.rows(); rrow++) { - typename MatrixType::InnerUpperIterator uItPivot(m_lu, row); - const double coef = lIt3.value(); - - //update lower part -> non contiguous memory access - for (Index i = 0; i < rrow - row - 1; i++) { - m_lu.coeffRefLower(rrow, row + i + 1) -= uItPivot.value() * coef; - ++uItPivot; - } - ++lIt3; - } - //update diag -> contiguous - typename MatrixType::InnerLowerIterator lIt2(m_lu, col); - for (Index rrow = row + 1; rrow < m_lu.rows(); rrow++) { - - typename MatrixType::InnerUpperIterator uItPivot(m_lu, row); - typename MatrixType::InnerUpperIterator uIt(m_lu, rrow); - const double coef = lIt2.value(); - - uItPivot += (rrow - row - 1); - m_lu.coeffRefDiag(rrow) -= uItPivot.value() * coef; - ++lIt2; - } - } -} - -template<typename MatrixType> -void SkylineInplaceLU<MatrixType>::computeRowMajor() { - const size_t rows = m_lu.rows(); - const size_t cols = m_lu.cols(); - - eigen_assert(rows == cols && "We do not (yet) support rectangular LU."); - eigen_assert(m_lu.IsRowMajor && "You're trying to apply rowMajor decomposition on a ColMajor matrix !"); - - for (Index row = 0; row < rows; row++) { - typename MatrixType::InnerLowerIterator llIt(m_lu, row); - - - for (Index col = llIt.col(); col < row; col++) { - if (m_lu.coeffExistLower(row, col)) { - const double diag = m_lu.coeffDiag(col); - - typename MatrixType::InnerLowerIterator lIt(m_lu, row); - typename MatrixType::InnerUpperIterator uIt(m_lu, col); - - - const Index offset = lIt.col() - uIt.row(); - - - Index stop = offset > 0 ? col - lIt.col() : col - uIt.row(); - - //#define VECTORIZE -#ifdef VECTORIZE - Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop); - Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop); - - - Scalar newCoeff = m_lu.coeffLower(row, col) - rowVal.dot(colVal); -#else - if (offset > 0) //Skip zero value of lIt - uIt += offset; - else //Skip zero values of uIt - lIt += -offset; - Scalar newCoeff = m_lu.coeffLower(row, col); - - for (Index k = 0; k < stop; ++k) { - const Scalar tmp = newCoeff; - newCoeff = tmp - lIt.value() * uIt.value(); - ++lIt; - ++uIt; - } -#endif - - m_lu.coeffRefLower(row, col) = newCoeff / diag; - } - } - - //Upper matrix update - const Index col = row; - typename MatrixType::InnerUpperIterator uuIt(m_lu, col); - for (Index rrow = uuIt.row(); rrow < col; rrow++) { - - typename MatrixType::InnerLowerIterator lIt(m_lu, rrow); - typename MatrixType::InnerUpperIterator uIt(m_lu, col); - const Index offset = lIt.col() - uIt.row(); - - Index stop = offset > 0 ? rrow - lIt.col() : rrow - uIt.row(); - -#ifdef VECTORIZE - Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop); - Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop); - - Scalar newCoeff = m_lu.coeffUpper(rrow, col) - rowVal.dot(colVal); -#else - if (offset > 0) //Skip zero value of lIt - uIt += offset; - else //Skip zero values of uIt - lIt += -offset; - Scalar newCoeff = m_lu.coeffUpper(rrow, col); - for (Index k = 0; k < stop; ++k) { - const Scalar tmp = newCoeff; - newCoeff = tmp - lIt.value() * uIt.value(); - - ++lIt; - ++uIt; - } -#endif - m_lu.coeffRefUpper(rrow, col) = newCoeff; - } - - - //Diag matrix update - typename MatrixType::InnerLowerIterator lIt(m_lu, row); - typename MatrixType::InnerUpperIterator uIt(m_lu, row); - - const Index offset = lIt.col() - uIt.row(); - - - Index stop = offset > 0 ? lIt.size() : uIt.size(); -#ifdef VECTORIZE - Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop); - Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop); - Scalar newCoeff = m_lu.coeffDiag(row) - rowVal.dot(colVal); -#else - if (offset > 0) //Skip zero value of lIt - uIt += offset; - else //Skip zero values of uIt - lIt += -offset; - Scalar newCoeff = m_lu.coeffDiag(row); - for (Index k = 0; k < stop; ++k) { - const Scalar tmp = newCoeff; - newCoeff = tmp - lIt.value() * uIt.value(); - ++lIt; - ++uIt; - } -#endif - m_lu.coeffRefDiag(row) = newCoeff; - } -} - -/** Computes *x = U^-1 L^-1 b - * - * If \a transpose is set to SvTranspose or SvAdjoint, the solution - * of the transposed/adjoint system is computed instead. - * - * Not all backends implement the solution of the transposed or - * adjoint system. - */ -template<typename MatrixType> -template<typename BDerived, typename XDerived> -bool SkylineInplaceLU<MatrixType>::solve(const MatrixBase<BDerived> &b, MatrixBase<XDerived>* x, const int transposed) const { - const size_t rows = m_lu.rows(); - const size_t cols = m_lu.cols(); - - - for (Index row = 0; row < rows; row++) { - x->coeffRef(row) = b.coeff(row); - Scalar newVal = x->coeff(row); - typename MatrixType::InnerLowerIterator lIt(m_lu, row); - - Index col = lIt.col(); - while (lIt.col() < row) { - - newVal -= x->coeff(col++) * lIt.value(); - ++lIt; - } - - x->coeffRef(row) = newVal; - } - - - for (Index col = rows - 1; col > 0; col--) { - x->coeffRef(col) = x->coeff(col) / m_lu.coeffDiag(col); - - const Scalar x_col = x->coeff(col); - - typename MatrixType::InnerUpperIterator uIt(m_lu, col); - uIt += uIt.size()-1; - - - while (uIt) { - x->coeffRef(uIt.row()) -= x_col * uIt.value(); - //TODO : introduce --operator - uIt += -1; - } - - - } - x->coeffRef(0) = x->coeff(0) / m_lu.coeffDiag(0); - - return true; -} - -} // end namespace Eigen - -#endif // EIGEN_SKYLINEINPLACELU_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineMatrix.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineMatrix.h deleted file mode 100644 index 7c7eace7..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineMatrix.h +++ /dev/null @@ -1,862 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Guillaume Saupin <guillaume.saupin@cea.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SKYLINEMATRIX_H -#define EIGEN_SKYLINEMATRIX_H - -#include "SkylineStorage.h" -#include "SkylineMatrixBase.h" - -namespace Eigen { - -/** \ingroup Skyline_Module - * - * \class SkylineMatrix - * - * \brief The main skyline matrix class - * - * This class implements a skyline matrix using the very uncommon storage - * scheme. - * - * \param _Scalar the scalar type, i.e. the type of the coefficients - * \param _Options Union of bit flags controlling the storage scheme. Currently the only possibility - * is RowMajor. The default is 0 which means column-major. - * - * - */ -namespace internal { -template<typename _Scalar, int _Options> -struct traits<SkylineMatrix<_Scalar, _Options> > { - typedef _Scalar Scalar; - typedef Sparse StorageKind; - - enum { - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = Dynamic, - MaxRowsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic, - Flags = SkylineBit | _Options, - CoeffReadCost = NumTraits<Scalar>::ReadCost, - }; -}; -} - -template<typename _Scalar, int _Options> -class SkylineMatrix -: public SkylineMatrixBase<SkylineMatrix<_Scalar, _Options> > { -public: - EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(SkylineMatrix) - EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(SkylineMatrix, +=) - EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(SkylineMatrix, -=) - - using Base::IsRowMajor; - -protected: - - typedef SkylineMatrix<Scalar, (Flags&~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0) > TransposedSkylineMatrix; - - Index m_outerSize; - Index m_innerSize; - -public: - Index* m_colStartIndex; - Index* m_rowStartIndex; - SkylineStorage<Scalar> m_data; - -public: - - inline Index rows() const { - return IsRowMajor ? m_outerSize : m_innerSize; - } - - inline Index cols() const { - return IsRowMajor ? m_innerSize : m_outerSize; - } - - inline Index innerSize() const { - return m_innerSize; - } - - inline Index outerSize() const { - return m_outerSize; - } - - inline Index upperNonZeros() const { - return m_data.upperSize(); - } - - inline Index lowerNonZeros() const { - return m_data.lowerSize(); - } - - inline Index upperNonZeros(Index j) const { - return m_colStartIndex[j + 1] - m_colStartIndex[j]; - } - - inline Index lowerNonZeros(Index j) const { - return m_rowStartIndex[j + 1] - m_rowStartIndex[j]; - } - - inline const Scalar* _diagPtr() const { - return &m_data.diag(0); - } - - inline Scalar* _diagPtr() { - return &m_data.diag(0); - } - - inline const Scalar* _upperPtr() const { - return &m_data.upper(0); - } - - inline Scalar* _upperPtr() { - return &m_data.upper(0); - } - - inline const Scalar* _lowerPtr() const { - return &m_data.lower(0); - } - - inline Scalar* _lowerPtr() { - return &m_data.lower(0); - } - - inline const Index* _upperProfilePtr() const { - return &m_data.upperProfile(0); - } - - inline Index* _upperProfilePtr() { - return &m_data.upperProfile(0); - } - - inline const Index* _lowerProfilePtr() const { - return &m_data.lowerProfile(0); - } - - inline Index* _lowerProfilePtr() { - return &m_data.lowerProfile(0); - } - - inline Scalar coeff(Index row, Index col) const { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - - if (outer == inner) - return this->m_data.diag(outer); - - if (IsRowMajor) { - if (inner > outer) //upper matrix - { - const Index minOuterIndex = inner - m_data.upperProfile(inner); - if (outer >= minOuterIndex) - return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); - else - return Scalar(0); - } - if (inner < outer) //lower matrix - { - const Index minInnerIndex = outer - m_data.lowerProfile(outer); - if (inner >= minInnerIndex) - return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); - else - return Scalar(0); - } - return m_data.upper(m_colStartIndex[inner] + outer - inner); - } else { - if (outer > inner) //upper matrix - { - const Index maxOuterIndex = inner + m_data.upperProfile(inner); - if (outer <= maxOuterIndex) - return this->m_data.upper(m_colStartIndex[inner] + (outer - inner)); - else - return Scalar(0); - } - if (outer < inner) //lower matrix - { - const Index maxInnerIndex = outer + m_data.lowerProfile(outer); - - if (inner <= maxInnerIndex) - return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer)); - else - return Scalar(0); - } - } - } - - inline Scalar& coeffRef(Index row, Index col) { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - - if (outer == inner) - return this->m_data.diag(outer); - - if (IsRowMajor) { - if (col > row) //upper matrix - { - const Index minOuterIndex = inner - m_data.upperProfile(inner); - eigen_assert(outer >= minOuterIndex && "You tried to access a coeff that does not exist in the storage"); - return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); - } - if (col < row) //lower matrix - { - const Index minInnerIndex = outer - m_data.lowerProfile(outer); - eigen_assert(inner >= minInnerIndex && "You tried to access a coeff that does not exist in the storage"); - return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); - } - } else { - if (outer > inner) //upper matrix - { - const Index maxOuterIndex = inner + m_data.upperProfile(inner); - eigen_assert(outer <= maxOuterIndex && "You tried to access a coeff that does not exist in the storage"); - return this->m_data.upper(m_colStartIndex[inner] + (outer - inner)); - } - if (outer < inner) //lower matrix - { - const Index maxInnerIndex = outer + m_data.lowerProfile(outer); - eigen_assert(inner <= maxInnerIndex && "You tried to access a coeff that does not exist in the storage"); - return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer)); - } - } - } - - inline Scalar coeffDiag(Index idx) const { - eigen_assert(idx < outerSize()); - eigen_assert(idx < innerSize()); - return this->m_data.diag(idx); - } - - inline Scalar coeffLower(Index row, Index col) const { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - eigen_assert(inner != outer); - - if (IsRowMajor) { - const Index minInnerIndex = outer - m_data.lowerProfile(outer); - if (inner >= minInnerIndex) - return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); - else - return Scalar(0); - - } else { - const Index maxInnerIndex = outer + m_data.lowerProfile(outer); - if (inner <= maxInnerIndex) - return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer)); - else - return Scalar(0); - } - } - - inline Scalar coeffUpper(Index row, Index col) const { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - eigen_assert(inner != outer); - - if (IsRowMajor) { - const Index minOuterIndex = inner - m_data.upperProfile(inner); - if (outer >= minOuterIndex) - return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); - else - return Scalar(0); - } else { - const Index maxOuterIndex = inner + m_data.upperProfile(inner); - if (outer <= maxOuterIndex) - return this->m_data.upper(m_colStartIndex[inner] + (outer - inner)); - else - return Scalar(0); - } - } - - inline Scalar& coeffRefDiag(Index idx) { - eigen_assert(idx < outerSize()); - eigen_assert(idx < innerSize()); - return this->m_data.diag(idx); - } - - inline Scalar& coeffRefLower(Index row, Index col) { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - eigen_assert(inner != outer); - - if (IsRowMajor) { - const Index minInnerIndex = outer - m_data.lowerProfile(outer); - eigen_assert(inner >= minInnerIndex && "You tried to access a coeff that does not exist in the storage"); - return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); - } else { - const Index maxInnerIndex = outer + m_data.lowerProfile(outer); - eigen_assert(inner <= maxInnerIndex && "You tried to access a coeff that does not exist in the storage"); - return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer)); - } - } - - inline bool coeffExistLower(Index row, Index col) { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - eigen_assert(inner != outer); - - if (IsRowMajor) { - const Index minInnerIndex = outer - m_data.lowerProfile(outer); - return inner >= minInnerIndex; - } else { - const Index maxInnerIndex = outer + m_data.lowerProfile(outer); - return inner <= maxInnerIndex; - } - } - - inline Scalar& coeffRefUpper(Index row, Index col) { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - eigen_assert(inner != outer); - - if (IsRowMajor) { - const Index minOuterIndex = inner - m_data.upperProfile(inner); - eigen_assert(outer >= minOuterIndex && "You tried to access a coeff that does not exist in the storage"); - return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); - } else { - const Index maxOuterIndex = inner + m_data.upperProfile(inner); - eigen_assert(outer <= maxOuterIndex && "You tried to access a coeff that does not exist in the storage"); - return this->m_data.upper(m_colStartIndex[inner] + (outer - inner)); - } - } - - inline bool coeffExistUpper(Index row, Index col) { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - eigen_assert(inner != outer); - - if (IsRowMajor) { - const Index minOuterIndex = inner - m_data.upperProfile(inner); - return outer >= minOuterIndex; - } else { - const Index maxOuterIndex = inner + m_data.upperProfile(inner); - return outer <= maxOuterIndex; - } - } - - -protected: - -public: - class InnerUpperIterator; - class InnerLowerIterator; - - class OuterUpperIterator; - class OuterLowerIterator; - - /** Removes all non zeros */ - inline void setZero() { - m_data.clear(); - memset(m_colStartIndex, 0, (m_outerSize + 1) * sizeof (Index)); - memset(m_rowStartIndex, 0, (m_outerSize + 1) * sizeof (Index)); - } - - /** \returns the number of non zero coefficients */ - inline Index nonZeros() const { - return m_data.diagSize() + m_data.upperSize() + m_data.lowerSize(); - } - - /** Preallocates \a reserveSize non zeros */ - inline void reserve(Index reserveSize, Index reserveUpperSize, Index reserveLowerSize) { - m_data.reserve(reserveSize, reserveUpperSize, reserveLowerSize); - } - - /** \returns a reference to a novel non zero coefficient with coordinates \a row x \a col. - - * - * \warning This function can be extremely slow if the non zero coefficients - * are not inserted in a coherent order. - * - * After an insertion session, you should call the finalize() function. - */ - EIGEN_DONT_INLINE Scalar & insert(Index row, Index col) { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - eigen_assert(outer < outerSize()); - eigen_assert(inner < innerSize()); - - if (outer == inner) - return m_data.diag(col); - - if (IsRowMajor) { - if (outer < inner) //upper matrix - { - Index minOuterIndex = 0; - minOuterIndex = inner - m_data.upperProfile(inner); - - if (outer < minOuterIndex) //The value does not yet exist - { - const Index previousProfile = m_data.upperProfile(inner); - - m_data.upperProfile(inner) = inner - outer; - - - const Index bandIncrement = m_data.upperProfile(inner) - previousProfile; - //shift data stored after this new one - const Index stop = m_colStartIndex[cols()]; - const Index start = m_colStartIndex[inner]; - - - for (Index innerIdx = stop; innerIdx >= start; innerIdx--) { - m_data.upper(innerIdx + bandIncrement) = m_data.upper(innerIdx); - } - - for (Index innerIdx = cols(); innerIdx > inner; innerIdx--) { - m_colStartIndex[innerIdx] += bandIncrement; - } - - //zeros new data - memset(this->_upperPtr() + start, 0, (bandIncrement - 1) * sizeof (Scalar)); - - return m_data.upper(m_colStartIndex[inner]); - } else { - return m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); - } - } - - if (outer > inner) //lower matrix - { - const Index minInnerIndex = outer - m_data.lowerProfile(outer); - if (inner < minInnerIndex) //The value does not yet exist - { - const Index previousProfile = m_data.lowerProfile(outer); - m_data.lowerProfile(outer) = outer - inner; - - const Index bandIncrement = m_data.lowerProfile(outer) - previousProfile; - //shift data stored after this new one - const Index stop = m_rowStartIndex[rows()]; - const Index start = m_rowStartIndex[outer]; - - - for (Index innerIdx = stop; innerIdx >= start; innerIdx--) { - m_data.lower(innerIdx + bandIncrement) = m_data.lower(innerIdx); - } - - for (Index innerIdx = rows(); innerIdx > outer; innerIdx--) { - m_rowStartIndex[innerIdx] += bandIncrement; - } - - //zeros new data - memset(this->_lowerPtr() + start, 0, (bandIncrement - 1) * sizeof (Scalar)); - return m_data.lower(m_rowStartIndex[outer]); - } else { - return m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); - } - } - } else { - if (outer > inner) //upper matrix - { - const Index maxOuterIndex = inner + m_data.upperProfile(inner); - if (outer > maxOuterIndex) //The value does not yet exist - { - const Index previousProfile = m_data.upperProfile(inner); - m_data.upperProfile(inner) = outer - inner; - - const Index bandIncrement = m_data.upperProfile(inner) - previousProfile; - //shift data stored after this new one - const Index stop = m_rowStartIndex[rows()]; - const Index start = m_rowStartIndex[inner + 1]; - - for (Index innerIdx = stop; innerIdx >= start; innerIdx--) { - m_data.upper(innerIdx + bandIncrement) = m_data.upper(innerIdx); - } - - for (Index innerIdx = inner + 1; innerIdx < outerSize() + 1; innerIdx++) { - m_rowStartIndex[innerIdx] += bandIncrement; - } - memset(this->_upperPtr() + m_rowStartIndex[inner] + previousProfile + 1, 0, (bandIncrement - 1) * sizeof (Scalar)); - return m_data.upper(m_rowStartIndex[inner] + m_data.upperProfile(inner)); - } else { - return m_data.upper(m_rowStartIndex[inner] + (outer - inner)); - } - } - - if (outer < inner) //lower matrix - { - const Index maxInnerIndex = outer + m_data.lowerProfile(outer); - if (inner > maxInnerIndex) //The value does not yet exist - { - const Index previousProfile = m_data.lowerProfile(outer); - m_data.lowerProfile(outer) = inner - outer; - - const Index bandIncrement = m_data.lowerProfile(outer) - previousProfile; - //shift data stored after this new one - const Index stop = m_colStartIndex[cols()]; - const Index start = m_colStartIndex[outer + 1]; - - for (Index innerIdx = stop; innerIdx >= start; innerIdx--) { - m_data.lower(innerIdx + bandIncrement) = m_data.lower(innerIdx); - } - - for (Index innerIdx = outer + 1; innerIdx < outerSize() + 1; innerIdx++) { - m_colStartIndex[innerIdx] += bandIncrement; - } - memset(this->_lowerPtr() + m_colStartIndex[outer] + previousProfile + 1, 0, (bandIncrement - 1) * sizeof (Scalar)); - return m_data.lower(m_colStartIndex[outer] + m_data.lowerProfile(outer)); - } else { - return m_data.lower(m_colStartIndex[outer] + (inner - outer)); - } - } - } - } - - /** Must be called after inserting a set of non zero entries. - */ - inline void finalize() { - if (IsRowMajor) { - if (rows() > cols()) - m_data.resize(cols(), cols(), rows(), m_colStartIndex[cols()] + 1, m_rowStartIndex[rows()] + 1); - else - m_data.resize(rows(), cols(), rows(), m_colStartIndex[cols()] + 1, m_rowStartIndex[rows()] + 1); - - // eigen_assert(rows() == cols() && "memory reorganisatrion only works with suare matrix"); - // - // Scalar* newArray = new Scalar[m_colStartIndex[cols()] + 1 + m_rowStartIndex[rows()] + 1]; - // Index dataIdx = 0; - // for (Index row = 0; row < rows(); row++) { - // - // const Index nbLowerElts = m_rowStartIndex[row + 1] - m_rowStartIndex[row]; - // // std::cout << "nbLowerElts" << nbLowerElts << std::endl; - // memcpy(newArray + dataIdx, m_data.m_lower + m_rowStartIndex[row], nbLowerElts * sizeof (Scalar)); - // m_rowStartIndex[row] = dataIdx; - // dataIdx += nbLowerElts; - // - // const Index nbUpperElts = m_colStartIndex[row + 1] - m_colStartIndex[row]; - // memcpy(newArray + dataIdx, m_data.m_upper + m_colStartIndex[row], nbUpperElts * sizeof (Scalar)); - // m_colStartIndex[row] = dataIdx; - // dataIdx += nbUpperElts; - // - // - // } - // //todo : don't access m_data profile directly : add an accessor from SkylineMatrix - // m_rowStartIndex[rows()] = m_rowStartIndex[rows()-1] + m_data.lowerProfile(rows()-1); - // m_colStartIndex[cols()] = m_colStartIndex[cols()-1] + m_data.upperProfile(cols()-1); - // - // delete[] m_data.m_lower; - // delete[] m_data.m_upper; - // - // m_data.m_lower = newArray; - // m_data.m_upper = newArray; - } else { - if (rows() > cols()) - m_data.resize(cols(), rows(), cols(), m_rowStartIndex[cols()] + 1, m_colStartIndex[cols()] + 1); - else - m_data.resize(rows(), rows(), cols(), m_rowStartIndex[rows()] + 1, m_colStartIndex[rows()] + 1); - } - } - - inline void squeeze() { - finalize(); - m_data.squeeze(); - } - - void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar > ()) { - //TODO - } - - /** Resizes the matrix to a \a rows x \a cols matrix and initializes it to zero - * \sa resizeNonZeros(Index), reserve(), setZero() - */ - void resize(size_t rows, size_t cols) { - const Index diagSize = rows > cols ? cols : rows; - m_innerSize = IsRowMajor ? cols : rows; - - eigen_assert(rows == cols && "Skyline matrix must be square matrix"); - - if (diagSize % 2) { // diagSize is odd - const Index k = (diagSize - 1) / 2; - - m_data.resize(diagSize, IsRowMajor ? cols : rows, IsRowMajor ? rows : cols, - 2 * k * k + k + 1, - 2 * k * k + k + 1); - - } else // diagSize is even - { - const Index k = diagSize / 2; - m_data.resize(diagSize, IsRowMajor ? cols : rows, IsRowMajor ? rows : cols, - 2 * k * k - k + 1, - 2 * k * k - k + 1); - } - - if (m_colStartIndex && m_rowStartIndex) { - delete[] m_colStartIndex; - delete[] m_rowStartIndex; - } - m_colStartIndex = new Index [cols + 1]; - m_rowStartIndex = new Index [rows + 1]; - m_outerSize = diagSize; - - m_data.reset(); - m_data.clear(); - - m_outerSize = diagSize; - memset(m_colStartIndex, 0, (cols + 1) * sizeof (Index)); - memset(m_rowStartIndex, 0, (rows + 1) * sizeof (Index)); - } - - void resizeNonZeros(Index size) { - m_data.resize(size); - } - - inline SkylineMatrix() - : m_outerSize(-1), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) { - resize(0, 0); - } - - inline SkylineMatrix(size_t rows, size_t cols) - : m_outerSize(0), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) { - resize(rows, cols); - } - - template<typename OtherDerived> - inline SkylineMatrix(const SkylineMatrixBase<OtherDerived>& other) - : m_outerSize(0), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) { - *this = other.derived(); - } - - inline SkylineMatrix(const SkylineMatrix & other) - : Base(), m_outerSize(0), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) { - *this = other.derived(); - } - - inline void swap(SkylineMatrix & other) { - //EIGEN_DBG_SKYLINE(std::cout << "SkylineMatrix:: swap\n"); - std::swap(m_colStartIndex, other.m_colStartIndex); - std::swap(m_rowStartIndex, other.m_rowStartIndex); - std::swap(m_innerSize, other.m_innerSize); - std::swap(m_outerSize, other.m_outerSize); - m_data.swap(other.m_data); - } - - inline SkylineMatrix & operator=(const SkylineMatrix & other) { - std::cout << "SkylineMatrix& operator=(const SkylineMatrix& other)\n"; - if (other.isRValue()) { - swap(other.const_cast_derived()); - } else { - resize(other.rows(), other.cols()); - memcpy(m_colStartIndex, other.m_colStartIndex, (m_outerSize + 1) * sizeof (Index)); - memcpy(m_rowStartIndex, other.m_rowStartIndex, (m_outerSize + 1) * sizeof (Index)); - m_data = other.m_data; - } - return *this; - } - - template<typename OtherDerived> - inline SkylineMatrix & operator=(const SkylineMatrixBase<OtherDerived>& other) { - const bool needToTranspose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); - if (needToTranspose) { - // TODO - // return *this; - } else { - // there is no special optimization - return SkylineMatrixBase<SkylineMatrix>::operator=(other.derived()); - } - } - - friend std::ostream & operator <<(std::ostream & s, const SkylineMatrix & m) { - - EIGEN_DBG_SKYLINE( - std::cout << "upper elements : " << std::endl; - for (Index i = 0; i < m.m_data.upperSize(); i++) - std::cout << m.m_data.upper(i) << "\t"; - std::cout << std::endl; - std::cout << "upper profile : " << std::endl; - for (Index i = 0; i < m.m_data.upperProfileSize(); i++) - std::cout << m.m_data.upperProfile(i) << "\t"; - std::cout << std::endl; - std::cout << "lower startIdx : " << std::endl; - for (Index i = 0; i < m.m_data.upperProfileSize(); i++) - std::cout << (IsRowMajor ? m.m_colStartIndex[i] : m.m_rowStartIndex[i]) << "\t"; - std::cout << std::endl; - - - std::cout << "lower elements : " << std::endl; - for (Index i = 0; i < m.m_data.lowerSize(); i++) - std::cout << m.m_data.lower(i) << "\t"; - std::cout << std::endl; - std::cout << "lower profile : " << std::endl; - for (Index i = 0; i < m.m_data.lowerProfileSize(); i++) - std::cout << m.m_data.lowerProfile(i) << "\t"; - std::cout << std::endl; - std::cout << "lower startIdx : " << std::endl; - for (Index i = 0; i < m.m_data.lowerProfileSize(); i++) - std::cout << (IsRowMajor ? m.m_rowStartIndex[i] : m.m_colStartIndex[i]) << "\t"; - std::cout << std::endl; - ); - for (Index rowIdx = 0; rowIdx < m.rows(); rowIdx++) { - for (Index colIdx = 0; colIdx < m.cols(); colIdx++) { - s << m.coeff(rowIdx, colIdx) << "\t"; - } - s << std::endl; - } - return s; - } - - /** Destructor */ - inline ~SkylineMatrix() { - delete[] m_colStartIndex; - delete[] m_rowStartIndex; - } - - /** Overloaded for performance */ - Scalar sum() const; -}; - -template<typename Scalar, int _Options> -class SkylineMatrix<Scalar, _Options>::InnerUpperIterator { -public: - - InnerUpperIterator(const SkylineMatrix& mat, Index outer) - : m_matrix(mat), m_outer(outer), - m_id(_Options == RowMajor ? mat.m_colStartIndex[outer] : mat.m_rowStartIndex[outer] + 1), - m_start(m_id), - m_end(_Options == RowMajor ? mat.m_colStartIndex[outer + 1] : mat.m_rowStartIndex[outer + 1] + 1) { - } - - inline InnerUpperIterator & operator++() { - m_id++; - return *this; - } - - inline InnerUpperIterator & operator+=(Index shift) { - m_id += shift; - return *this; - } - - inline Scalar value() const { - return m_matrix.m_data.upper(m_id); - } - - inline Scalar* valuePtr() { - return const_cast<Scalar*> (&(m_matrix.m_data.upper(m_id))); - } - - inline Scalar& valueRef() { - return const_cast<Scalar&> (m_matrix.m_data.upper(m_id)); - } - - inline Index index() const { - return IsRowMajor ? m_outer - m_matrix.m_data.upperProfile(m_outer) + (m_id - m_start) : - m_outer + (m_id - m_start) + 1; - } - - inline Index row() const { - return IsRowMajor ? index() : m_outer; - } - - inline Index col() const { - return IsRowMajor ? m_outer : index(); - } - - inline size_t size() const { - return m_matrix.m_data.upperProfile(m_outer); - } - - inline operator bool() const { - return (m_id < m_end) && (m_id >= m_start); - } - -protected: - const SkylineMatrix& m_matrix; - const Index m_outer; - Index m_id; - const Index m_start; - const Index m_end; -}; - -template<typename Scalar, int _Options> -class SkylineMatrix<Scalar, _Options>::InnerLowerIterator { -public: - - InnerLowerIterator(const SkylineMatrix& mat, Index outer) - : m_matrix(mat), - m_outer(outer), - m_id(_Options == RowMajor ? mat.m_rowStartIndex[outer] : mat.m_colStartIndex[outer] + 1), - m_start(m_id), - m_end(_Options == RowMajor ? mat.m_rowStartIndex[outer + 1] : mat.m_colStartIndex[outer + 1] + 1) { - } - - inline InnerLowerIterator & operator++() { - m_id++; - return *this; - } - - inline InnerLowerIterator & operator+=(Index shift) { - m_id += shift; - return *this; - } - - inline Scalar value() const { - return m_matrix.m_data.lower(m_id); - } - - inline Scalar* valuePtr() { - return const_cast<Scalar*> (&(m_matrix.m_data.lower(m_id))); - } - - inline Scalar& valueRef() { - return const_cast<Scalar&> (m_matrix.m_data.lower(m_id)); - } - - inline Index index() const { - return IsRowMajor ? m_outer - m_matrix.m_data.lowerProfile(m_outer) + (m_id - m_start) : - m_outer + (m_id - m_start) + 1; - ; - } - - inline Index row() const { - return IsRowMajor ? m_outer : index(); - } - - inline Index col() const { - return IsRowMajor ? index() : m_outer; - } - - inline size_t size() const { - return m_matrix.m_data.lowerProfile(m_outer); - } - - inline operator bool() const { - return (m_id < m_end) && (m_id >= m_start); - } - -protected: - const SkylineMatrix& m_matrix; - const Index m_outer; - Index m_id; - const Index m_start; - const Index m_end; -}; - -} // end namespace Eigen - -#endif // EIGEN_SKYLINEMATRIX_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h deleted file mode 100644 index 753c1b33..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h +++ /dev/null @@ -1,212 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Guillaume Saupin <guillaume.saupin@cea.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SKYLINEMATRIXBASE_H -#define EIGEN_SKYLINEMATRIXBASE_H - -#include "SkylineUtil.h" - -namespace Eigen { - -/** \ingroup Skyline_Module - * - * \class SkylineMatrixBase - * - * \brief Base class of any skyline matrices or skyline expressions - * - * \param Derived - * - */ -template<typename Derived> class SkylineMatrixBase : public EigenBase<Derived> { -public: - - typedef typename internal::traits<Derived>::Scalar Scalar; - typedef typename internal::traits<Derived>::StorageKind StorageKind; - typedef typename internal::index<StorageKind>::type Index; - - enum { - RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, - /**< The number of rows at compile-time. This is just a copy of the value provided - * by the \a Derived type. If a value is not known at compile-time, - * it is set to the \a Dynamic constant. - * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */ - - ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, - /**< The number of columns at compile-time. This is just a copy of the value provided - * by the \a Derived type. If a value is not known at compile-time, - * it is set to the \a Dynamic constant. - * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ - - - SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime, - internal::traits<Derived>::ColsAtCompileTime>::ret), - /**< This is equal to the number of coefficients, i.e. the number of - * rows times the number of columns, or to \a Dynamic if this is not - * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ - - MaxRowsAtCompileTime = RowsAtCompileTime, - MaxColsAtCompileTime = ColsAtCompileTime, - - MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime, - MaxColsAtCompileTime>::ret), - - IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1, - /**< This is set to true if either the number of rows or the number of - * columns is known at compile-time to be equal to 1. Indeed, in that case, - * we are dealing with a column-vector (if there is only one column) or with - * a row-vector (if there is only one row). */ - - Flags = internal::traits<Derived>::Flags, - /**< This stores expression \ref flags flags which may or may not be inherited by new expressions - * constructed from this one. See the \ref flags "list of flags". - */ - - CoeffReadCost = internal::traits<Derived>::CoeffReadCost, - /**< This is a rough measure of how expensive it is to read one coefficient from - * this expression. - */ - - IsRowMajor = Flags & RowMajorBit ? 1 : 0 - }; - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** This is the "real scalar" type; if the \a Scalar type is already real numbers - * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If - * \a Scalar is \a std::complex<T> then RealScalar is \a T. - * - * \sa class NumTraits - */ - typedef typename NumTraits<Scalar>::Real RealScalar; - - /** type of the equivalent square matrix */ - typedef Matrix<Scalar, EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime), - EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime) > SquareMatrixType; - - inline const Derived& derived() const { - return *static_cast<const Derived*> (this); - } - - inline Derived& derived() { - return *static_cast<Derived*> (this); - } - - inline Derived& const_cast_derived() const { - return *static_cast<Derived*> (const_cast<SkylineMatrixBase*> (this)); - } -#endif // not EIGEN_PARSED_BY_DOXYGEN - - /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ - inline Index rows() const { - return derived().rows(); - } - - /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ - inline Index cols() const { - return derived().cols(); - } - - /** \returns the number of coefficients, which is \a rows()*cols(). - * \sa rows(), cols(), SizeAtCompileTime. */ - inline Index size() const { - return rows() * cols(); - } - - /** \returns the number of nonzero coefficients which is in practice the number - * of stored coefficients. */ - inline Index nonZeros() const { - return derived().nonZeros(); - } - - /** \returns the size of the storage major dimension, - * i.e., the number of columns for a columns major matrix, and the number of rows otherwise */ - Index outerSize() const { - return (int(Flags) & RowMajorBit) ? this->rows() : this->cols(); - } - - /** \returns the size of the inner dimension according to the storage order, - * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */ - Index innerSize() const { - return (int(Flags) & RowMajorBit) ? this->cols() : this->rows(); - } - - bool isRValue() const { - return m_isRValue; - } - - Derived& markAsRValue() { - m_isRValue = true; - return derived(); - } - - SkylineMatrixBase() : m_isRValue(false) { - /* TODO check flags */ - } - - inline Derived & operator=(const Derived& other) { - this->operator=<Derived > (other); - return derived(); - } - - template<typename OtherDerived> - inline void assignGeneric(const OtherDerived& other) { - derived().resize(other.rows(), other.cols()); - for (Index row = 0; row < rows(); row++) - for (Index col = 0; col < cols(); col++) { - if (other.coeff(row, col) != Scalar(0)) - derived().insert(row, col) = other.coeff(row, col); - } - derived().finalize(); - } - - template<typename OtherDerived> - inline Derived & operator=(const SkylineMatrixBase<OtherDerived>& other) { - //TODO - } - - template<typename Lhs, typename Rhs> - inline Derived & operator=(const SkylineProduct<Lhs, Rhs, SkylineTimeSkylineProduct>& product); - - friend std::ostream & operator <<(std::ostream & s, const SkylineMatrixBase& m) { - s << m.derived(); - return s; - } - - template<typename OtherDerived> - const typename SkylineProductReturnType<Derived, OtherDerived>::Type - operator*(const MatrixBase<OtherDerived> &other) const; - - /** \internal use operator= */ - template<typename DenseDerived> - void evalTo(MatrixBase<DenseDerived>& dst) const { - dst.setZero(); - for (Index i = 0; i < rows(); i++) - for (Index j = 0; j < rows(); j++) - dst(i, j) = derived().coeff(i, j); - } - - Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> toDense() const { - return derived(); - } - - /** \returns the matrix or vector obtained by evaluating this expression. - * - * Notice that in the case of a plain matrix or vector (not an expression) this function just returns - * a const reference, in order to avoid a useless copy. - */ - EIGEN_STRONG_INLINE const typename internal::eval<Derived, IsSkyline>::type eval() const { - return typename internal::eval<Derived>::type(derived()); - } - -protected: - bool m_isRValue; -}; - -} // end namespace Eigen - -#endif // EIGEN_SKYLINEMATRIXBASE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineProduct.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineProduct.h deleted file mode 100644 index d9eb814c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineProduct.h +++ /dev/null @@ -1,295 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Guillaume Saupin <guillaume.saupin@cea.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SKYLINEPRODUCT_H -#define EIGEN_SKYLINEPRODUCT_H - -namespace Eigen { - -template<typename Lhs, typename Rhs, int ProductMode> -struct SkylineProductReturnType { - typedef const typename internal::nested_eval<Lhs, Rhs::RowsAtCompileTime>::type LhsNested; - typedef const typename internal::nested_eval<Rhs, Lhs::RowsAtCompileTime>::type RhsNested; - - typedef SkylineProduct<LhsNested, RhsNested, ProductMode> Type; -}; - -template<typename LhsNested, typename RhsNested, int ProductMode> -struct internal::traits<SkylineProduct<LhsNested, RhsNested, ProductMode> > { - // clean the nested types: - typedef typename internal::remove_all<LhsNested>::type _LhsNested; - typedef typename internal::remove_all<RhsNested>::type _RhsNested; - typedef typename _LhsNested::Scalar Scalar; - - enum { - LhsCoeffReadCost = _LhsNested::CoeffReadCost, - RhsCoeffReadCost = _RhsNested::CoeffReadCost, - LhsFlags = _LhsNested::Flags, - RhsFlags = _RhsNested::Flags, - - RowsAtCompileTime = _LhsNested::RowsAtCompileTime, - ColsAtCompileTime = _RhsNested::ColsAtCompileTime, - InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime), - - MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime, - MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime, - - EvalToRowMajor = (RhsFlags & LhsFlags & RowMajorBit), - ResultIsSkyline = ProductMode == SkylineTimeSkylineProduct, - - RemovedBits = ~((EvalToRowMajor ? 0 : RowMajorBit) | (ResultIsSkyline ? 0 : SkylineBit)), - - Flags = (int(LhsFlags | RhsFlags) & HereditaryBits & RemovedBits) - | EvalBeforeAssigningBit - | EvalBeforeNestingBit, - - CoeffReadCost = HugeCost - }; - - typedef typename internal::conditional<ResultIsSkyline, - SkylineMatrixBase<SkylineProduct<LhsNested, RhsNested, ProductMode> >, - MatrixBase<SkylineProduct<LhsNested, RhsNested, ProductMode> > >::type Base; -}; - -namespace internal { -template<typename LhsNested, typename RhsNested, int ProductMode> -class SkylineProduct : no_assignment_operator, -public traits<SkylineProduct<LhsNested, RhsNested, ProductMode> >::Base { -public: - - EIGEN_GENERIC_PUBLIC_INTERFACE(SkylineProduct) - -private: - - typedef typename traits<SkylineProduct>::_LhsNested _LhsNested; - typedef typename traits<SkylineProduct>::_RhsNested _RhsNested; - -public: - - template<typename Lhs, typename Rhs> - EIGEN_STRONG_INLINE SkylineProduct(const Lhs& lhs, const Rhs& rhs) - : m_lhs(lhs), m_rhs(rhs) { - eigen_assert(lhs.cols() == rhs.rows()); - - enum { - ProductIsValid = _LhsNested::ColsAtCompileTime == Dynamic - || _RhsNested::RowsAtCompileTime == Dynamic - || int(_LhsNested::ColsAtCompileTime) == int(_RhsNested::RowsAtCompileTime), - AreVectors = _LhsNested::IsVectorAtCompileTime && _RhsNested::IsVectorAtCompileTime, - SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(_LhsNested, _RhsNested) - }; - // note to the lost user: - // * for a dot product use: v1.dot(v2) - // * for a coeff-wise product use: v1.cwise()*v2 - EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes), - INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS) - EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors), - INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION) - EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) - } - - EIGEN_STRONG_INLINE Index rows() const { - return m_lhs.rows(); - } - - EIGEN_STRONG_INLINE Index cols() const { - return m_rhs.cols(); - } - - EIGEN_STRONG_INLINE const _LhsNested& lhs() const { - return m_lhs; - } - - EIGEN_STRONG_INLINE const _RhsNested& rhs() const { - return m_rhs; - } - -protected: - LhsNested m_lhs; - RhsNested m_rhs; -}; - -// dense = skyline * dense -// Note that here we force no inlining and separate the setZero() because GCC messes up otherwise - -template<typename Lhs, typename Rhs, typename Dest> -EIGEN_DONT_INLINE void skyline_row_major_time_dense_product(const Lhs& lhs, const Rhs& rhs, Dest& dst) { - typedef typename remove_all<Lhs>::type _Lhs; - typedef typename remove_all<Rhs>::type _Rhs; - typedef typename traits<Lhs>::Scalar Scalar; - - enum { - LhsIsRowMajor = (_Lhs::Flags & RowMajorBit) == RowMajorBit, - LhsIsSelfAdjoint = (_Lhs::Flags & SelfAdjointBit) == SelfAdjointBit, - ProcessFirstHalf = LhsIsSelfAdjoint - && (((_Lhs::Flags & (UpperTriangularBit | LowerTriangularBit)) == 0) - || ((_Lhs::Flags & UpperTriangularBit) && !LhsIsRowMajor) - || ((_Lhs::Flags & LowerTriangularBit) && LhsIsRowMajor)), - ProcessSecondHalf = LhsIsSelfAdjoint && (!ProcessFirstHalf) - }; - - //Use matrix diagonal part <- Improvement : use inner iterator on dense matrix. - for (Index col = 0; col < rhs.cols(); col++) { - for (Index row = 0; row < lhs.rows(); row++) { - dst(row, col) = lhs.coeffDiag(row) * rhs(row, col); - } - } - //Use matrix lower triangular part - for (Index row = 0; row < lhs.rows(); row++) { - typename _Lhs::InnerLowerIterator lIt(lhs, row); - const Index stop = lIt.col() + lIt.size(); - for (Index col = 0; col < rhs.cols(); col++) { - - Index k = lIt.col(); - Scalar tmp = 0; - while (k < stop) { - tmp += - lIt.value() * - rhs(k++, col); - ++lIt; - } - dst(row, col) += tmp; - lIt += -lIt.size(); - } - - } - - //Use matrix upper triangular part - for (Index lhscol = 0; lhscol < lhs.cols(); lhscol++) { - typename _Lhs::InnerUpperIterator uIt(lhs, lhscol); - const Index stop = uIt.size() + uIt.row(); - for (Index rhscol = 0; rhscol < rhs.cols(); rhscol++) { - - - const Scalar rhsCoeff = rhs.coeff(lhscol, rhscol); - Index k = uIt.row(); - while (k < stop) { - dst(k++, rhscol) += - uIt.value() * - rhsCoeff; - ++uIt; - } - uIt += -uIt.size(); - } - } - -} - -template<typename Lhs, typename Rhs, typename Dest> -EIGEN_DONT_INLINE void skyline_col_major_time_dense_product(const Lhs& lhs, const Rhs& rhs, Dest& dst) { - typedef typename remove_all<Lhs>::type _Lhs; - typedef typename remove_all<Rhs>::type _Rhs; - typedef typename traits<Lhs>::Scalar Scalar; - - enum { - LhsIsRowMajor = (_Lhs::Flags & RowMajorBit) == RowMajorBit, - LhsIsSelfAdjoint = (_Lhs::Flags & SelfAdjointBit) == SelfAdjointBit, - ProcessFirstHalf = LhsIsSelfAdjoint - && (((_Lhs::Flags & (UpperTriangularBit | LowerTriangularBit)) == 0) - || ((_Lhs::Flags & UpperTriangularBit) && !LhsIsRowMajor) - || ((_Lhs::Flags & LowerTriangularBit) && LhsIsRowMajor)), - ProcessSecondHalf = LhsIsSelfAdjoint && (!ProcessFirstHalf) - }; - - //Use matrix diagonal part <- Improvement : use inner iterator on dense matrix. - for (Index col = 0; col < rhs.cols(); col++) { - for (Index row = 0; row < lhs.rows(); row++) { - dst(row, col) = lhs.coeffDiag(row) * rhs(row, col); - } - } - - //Use matrix upper triangular part - for (Index row = 0; row < lhs.rows(); row++) { - typename _Lhs::InnerUpperIterator uIt(lhs, row); - const Index stop = uIt.col() + uIt.size(); - for (Index col = 0; col < rhs.cols(); col++) { - - Index k = uIt.col(); - Scalar tmp = 0; - while (k < stop) { - tmp += - uIt.value() * - rhs(k++, col); - ++uIt; - } - - - dst(row, col) += tmp; - uIt += -uIt.size(); - } - } - - //Use matrix lower triangular part - for (Index lhscol = 0; lhscol < lhs.cols(); lhscol++) { - typename _Lhs::InnerLowerIterator lIt(lhs, lhscol); - const Index stop = lIt.size() + lIt.row(); - for (Index rhscol = 0; rhscol < rhs.cols(); rhscol++) { - - const Scalar rhsCoeff = rhs.coeff(lhscol, rhscol); - Index k = lIt.row(); - while (k < stop) { - dst(k++, rhscol) += - lIt.value() * - rhsCoeff; - ++lIt; - } - lIt += -lIt.size(); - } - } - -} - -template<typename Lhs, typename Rhs, typename ResultType, - int LhsStorageOrder = traits<Lhs>::Flags&RowMajorBit> - struct skyline_product_selector; - -template<typename Lhs, typename Rhs, typename ResultType> -struct skyline_product_selector<Lhs, Rhs, ResultType, RowMajor> { - typedef typename traits<typename remove_all<Lhs>::type>::Scalar Scalar; - - static void run(const Lhs& lhs, const Rhs& rhs, ResultType & res) { - skyline_row_major_time_dense_product<Lhs, Rhs, ResultType > (lhs, rhs, res); - } -}; - -template<typename Lhs, typename Rhs, typename ResultType> -struct skyline_product_selector<Lhs, Rhs, ResultType, ColMajor> { - typedef typename traits<typename remove_all<Lhs>::type>::Scalar Scalar; - - static void run(const Lhs& lhs, const Rhs& rhs, ResultType & res) { - skyline_col_major_time_dense_product<Lhs, Rhs, ResultType > (lhs, rhs, res); - } -}; - -} // end namespace internal - -// template<typename Derived> -// template<typename Lhs, typename Rhs > -// Derived & MatrixBase<Derived>::lazyAssign(const SkylineProduct<Lhs, Rhs, SkylineTimeDenseProduct>& product) { -// typedef typename internal::remove_all<Lhs>::type _Lhs; -// internal::skyline_product_selector<typename internal::remove_all<Lhs>::type, -// typename internal::remove_all<Rhs>::type, -// Derived>::run(product.lhs(), product.rhs(), derived()); -// -// return derived(); -// } - -// skyline * dense - -template<typename Derived> -template<typename OtherDerived > -EIGEN_STRONG_INLINE const typename SkylineProductReturnType<Derived, OtherDerived>::Type -SkylineMatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const { - - return typename SkylineProductReturnType<Derived, OtherDerived>::Type(derived(), other.derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_SKYLINEPRODUCT_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineStorage.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineStorage.h deleted file mode 100644 index cc7514f1..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineStorage.h +++ /dev/null @@ -1,259 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Guillaume Saupin <guillaume.saupin@cea.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SKYLINE_STORAGE_H -#define EIGEN_SKYLINE_STORAGE_H - -namespace Eigen { - -/** Stores a skyline set of values in three structures : - * The diagonal elements - * The upper elements - * The lower elements - * - */ -template<typename Scalar> -class SkylineStorage { - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef SparseIndex Index; -public: - - SkylineStorage() - : m_diag(0), - m_lower(0), - m_upper(0), - m_lowerProfile(0), - m_upperProfile(0), - m_diagSize(0), - m_upperSize(0), - m_lowerSize(0), - m_upperProfileSize(0), - m_lowerProfileSize(0), - m_allocatedSize(0) { - } - - SkylineStorage(const SkylineStorage& other) - : m_diag(0), - m_lower(0), - m_upper(0), - m_lowerProfile(0), - m_upperProfile(0), - m_diagSize(0), - m_upperSize(0), - m_lowerSize(0), - m_upperProfileSize(0), - m_lowerProfileSize(0), - m_allocatedSize(0) { - *this = other; - } - - SkylineStorage & operator=(const SkylineStorage& other) { - resize(other.diagSize(), other.m_upperProfileSize, other.m_lowerProfileSize, other.upperSize(), other.lowerSize()); - memcpy(m_diag, other.m_diag, m_diagSize * sizeof (Scalar)); - memcpy(m_upper, other.m_upper, other.upperSize() * sizeof (Scalar)); - memcpy(m_lower, other.m_lower, other.lowerSize() * sizeof (Scalar)); - memcpy(m_upperProfile, other.m_upperProfile, m_upperProfileSize * sizeof (Index)); - memcpy(m_lowerProfile, other.m_lowerProfile, m_lowerProfileSize * sizeof (Index)); - return *this; - } - - void swap(SkylineStorage& other) { - std::swap(m_diag, other.m_diag); - std::swap(m_upper, other.m_upper); - std::swap(m_lower, other.m_lower); - std::swap(m_upperProfile, other.m_upperProfile); - std::swap(m_lowerProfile, other.m_lowerProfile); - std::swap(m_diagSize, other.m_diagSize); - std::swap(m_upperSize, other.m_upperSize); - std::swap(m_lowerSize, other.m_lowerSize); - std::swap(m_allocatedSize, other.m_allocatedSize); - } - - ~SkylineStorage() { - delete[] m_diag; - delete[] m_upper; - if (m_upper != m_lower) - delete[] m_lower; - delete[] m_upperProfile; - delete[] m_lowerProfile; - } - - void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) { - Index newAllocatedSize = size + upperSize + lowerSize; - if (newAllocatedSize > m_allocatedSize) - reallocate(size, upperProfileSize, lowerProfileSize, upperSize, lowerSize); - } - - void squeeze() { - if (m_allocatedSize > m_diagSize + m_upperSize + m_lowerSize) - reallocate(m_diagSize, m_upperProfileSize, m_lowerProfileSize, m_upperSize, m_lowerSize); - } - - void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize, float reserveSizeFactor = 0) { - if (m_allocatedSize < diagSize + upperSize + lowerSize) - reallocate(diagSize, upperProfileSize, lowerProfileSize, upperSize + Index(reserveSizeFactor * upperSize), lowerSize + Index(reserveSizeFactor * lowerSize)); - m_diagSize = diagSize; - m_upperSize = upperSize; - m_lowerSize = lowerSize; - m_upperProfileSize = upperProfileSize; - m_lowerProfileSize = lowerProfileSize; - } - - inline Index diagSize() const { - return m_diagSize; - } - - inline Index upperSize() const { - return m_upperSize; - } - - inline Index lowerSize() const { - return m_lowerSize; - } - - inline Index upperProfileSize() const { - return m_upperProfileSize; - } - - inline Index lowerProfileSize() const { - return m_lowerProfileSize; - } - - inline Index allocatedSize() const { - return m_allocatedSize; - } - - inline void clear() { - m_diagSize = 0; - } - - inline Scalar& diag(Index i) { - return m_diag[i]; - } - - inline const Scalar& diag(Index i) const { - return m_diag[i]; - } - - inline Scalar& upper(Index i) { - return m_upper[i]; - } - - inline const Scalar& upper(Index i) const { - return m_upper[i]; - } - - inline Scalar& lower(Index i) { - return m_lower[i]; - } - - inline const Scalar& lower(Index i) const { - return m_lower[i]; - } - - inline Index& upperProfile(Index i) { - return m_upperProfile[i]; - } - - inline const Index& upperProfile(Index i) const { - return m_upperProfile[i]; - } - - inline Index& lowerProfile(Index i) { - return m_lowerProfile[i]; - } - - inline const Index& lowerProfile(Index i) const { - return m_lowerProfile[i]; - } - - static SkylineStorage Map(Index* upperProfile, Index* lowerProfile, Scalar* diag, Scalar* upper, Scalar* lower, Index size, Index upperSize, Index lowerSize) { - SkylineStorage res; - res.m_upperProfile = upperProfile; - res.m_lowerProfile = lowerProfile; - res.m_diag = diag; - res.m_upper = upper; - res.m_lower = lower; - res.m_allocatedSize = res.m_diagSize = size; - res.m_upperSize = upperSize; - res.m_lowerSize = lowerSize; - return res; - } - - inline void reset() { - memset(m_diag, 0, m_diagSize * sizeof (Scalar)); - memset(m_upper, 0, m_upperSize * sizeof (Scalar)); - memset(m_lower, 0, m_lowerSize * sizeof (Scalar)); - memset(m_upperProfile, 0, m_diagSize * sizeof (Index)); - memset(m_lowerProfile, 0, m_diagSize * sizeof (Index)); - } - - void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar>()) { - //TODO - } - -protected: - - inline void reallocate(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) { - - Scalar* diag = new Scalar[diagSize]; - Scalar* upper = new Scalar[upperSize]; - Scalar* lower = new Scalar[lowerSize]; - Index* upperProfile = new Index[upperProfileSize]; - Index* lowerProfile = new Index[lowerProfileSize]; - - Index copyDiagSize = (std::min)(diagSize, m_diagSize); - Index copyUpperSize = (std::min)(upperSize, m_upperSize); - Index copyLowerSize = (std::min)(lowerSize, m_lowerSize); - Index copyUpperProfileSize = (std::min)(upperProfileSize, m_upperProfileSize); - Index copyLowerProfileSize = (std::min)(lowerProfileSize, m_lowerProfileSize); - - // copy - memcpy(diag, m_diag, copyDiagSize * sizeof (Scalar)); - memcpy(upper, m_upper, copyUpperSize * sizeof (Scalar)); - memcpy(lower, m_lower, copyLowerSize * sizeof (Scalar)); - memcpy(upperProfile, m_upperProfile, copyUpperProfileSize * sizeof (Index)); - memcpy(lowerProfile, m_lowerProfile, copyLowerProfileSize * sizeof (Index)); - - - - // delete old stuff - delete[] m_diag; - delete[] m_upper; - delete[] m_lower; - delete[] m_upperProfile; - delete[] m_lowerProfile; - m_diag = diag; - m_upper = upper; - m_lower = lower; - m_upperProfile = upperProfile; - m_lowerProfile = lowerProfile; - m_allocatedSize = diagSize + upperSize + lowerSize; - m_upperSize = upperSize; - m_lowerSize = lowerSize; - } - -public: - Scalar* m_diag; - Scalar* m_upper; - Scalar* m_lower; - Index* m_upperProfile; - Index* m_lowerProfile; - Index m_diagSize; - Index m_upperSize; - Index m_lowerSize; - Index m_upperProfileSize; - Index m_lowerProfileSize; - Index m_allocatedSize; - -}; - -} // end namespace Eigen - -#endif // EIGEN_SKYLINE_STORAGE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineUtil.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineUtil.h deleted file mode 100644 index 75eb612f..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Skyline/SkylineUtil.h +++ /dev/null @@ -1,89 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Guillaume Saupin <guillaume.saupin@cea.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SKYLINEUTIL_H -#define EIGEN_SKYLINEUTIL_H - -namespace Eigen { - -#ifdef NDEBUG -#define EIGEN_DBG_SKYLINE(X) -#else -#define EIGEN_DBG_SKYLINE(X) X -#endif - -const unsigned int SkylineBit = 0x1200; -template<typename Lhs, typename Rhs, int ProductMode> class SkylineProduct; -enum AdditionalProductEvaluationMode {SkylineTimeDenseProduct, SkylineTimeSkylineProduct, DenseTimeSkylineProduct}; -enum {IsSkyline = SkylineBit}; - - -#define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \ -template<typename OtherDerived> \ -EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SkylineMatrixBase<OtherDerived>& other) \ -{ \ - return Base::operator Op(other.derived()); \ -} \ -EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \ -{ \ - return Base::operator Op(other); \ -} - -#define EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ -template<typename Other> \ -EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \ -{ \ - return Base::operator Op(scalar); \ -} - -#define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ - EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \ - EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \ - EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \ - EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \ - EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) - -#define _EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \ - typedef BaseClass Base; \ - typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; \ - typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ - typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \ - typedef typename Eigen::internal::index<StorageKind>::type Index; \ - enum { Flags = Eigen::internal::traits<Derived>::Flags, }; - -#define EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived) \ - _EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SkylineMatrixBase<Derived>) - -template<typename Derived> class SkylineMatrixBase; -template<typename _Scalar, int _Flags = 0> class SkylineMatrix; -template<typename _Scalar, int _Flags = 0> class DynamicSkylineMatrix; -template<typename _Scalar, int _Flags = 0> class SkylineVector; -template<typename _Scalar, int _Flags = 0> class MappedSkylineMatrix; - -namespace internal { - -template<typename Lhs, typename Rhs> struct skyline_product_mode; -template<typename Lhs, typename Rhs, int ProductMode = skyline_product_mode<Lhs,Rhs>::value> struct SkylineProductReturnType; - -template<typename T> class eval<T,IsSkyline> -{ - typedef typename traits<T>::Scalar _Scalar; - enum { - _Flags = traits<T>::Flags - }; - - public: - typedef SkylineMatrix<_Scalar, _Flags> type; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SKYLINEUTIL_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/BlockOfDynamicSparseMatrix.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/BlockOfDynamicSparseMatrix.h deleted file mode 100644 index e9ec746e..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/BlockOfDynamicSparseMatrix.h +++ /dev/null @@ -1,122 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H -#define EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H - -namespace Eigen { - -#if 0 - -// NOTE Have to be reimplemented as a specialization of BlockImpl< DynamicSparseMatrix<_Scalar, _Options, _Index>, ... > -// See SparseBlock.h for an example - - -/*************************************************************************** -* specialisation for DynamicSparseMatrix -***************************************************************************/ - -template<typename _Scalar, int _Options, typename _Index, int Size> -class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options, _Index>, Size> - : public SparseMatrixBase<SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options, _Index>, Size> > -{ - typedef DynamicSparseMatrix<_Scalar, _Options, _Index> MatrixType; - public: - - enum { IsRowMajor = internal::traits<SparseInnerVectorSet>::IsRowMajor }; - - EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet) - class InnerIterator: public MatrixType::InnerIterator - { - public: - inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer) - : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) - {} - inline Index row() const { return IsRowMajor ? m_outer : this->index(); } - inline Index col() const { return IsRowMajor ? this->index() : m_outer; } - protected: - Index m_outer; - }; - - inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize) - : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize) - { - eigen_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) ); - } - - inline SparseInnerVectorSet(const MatrixType& matrix, Index outer) - : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size) - { - eigen_assert(Size!=Dynamic); - eigen_assert( (outer>=0) && (outer<matrix.outerSize()) ); - } - - template<typename OtherDerived> - inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other) - { - if (IsRowMajor != ((OtherDerived::Flags&RowMajorBit)==RowMajorBit)) - { - // need to transpose => perform a block evaluation followed by a big swap - DynamicSparseMatrix<Scalar,IsRowMajor?RowMajorBit:0> aux(other); - *this = aux.markAsRValue(); - } - else - { - // evaluate/copy vector per vector - for (Index j=0; j<m_outerSize.value(); ++j) - { - SparseVector<Scalar,IsRowMajor ? RowMajorBit : 0> aux(other.innerVector(j)); - m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data()); - } - } - return *this; - } - - inline SparseInnerVectorSet& operator=(const SparseInnerVectorSet& other) - { - return operator=<SparseInnerVectorSet>(other); - } - - Index nonZeros() const - { - Index count = 0; - for (Index j=0; j<m_outerSize.value(); ++j) - count += m_matrix._data()[m_outerStart+j].size(); - return count; - } - - const Scalar& lastCoeff() const - { - EIGEN_STATIC_ASSERT_VECTOR_ONLY(SparseInnerVectorSet); - eigen_assert(m_matrix.data()[m_outerStart].size()>0); - return m_matrix.data()[m_outerStart].vale(m_matrix.data()[m_outerStart].size()-1); - } - -// template<typename Sparse> -// inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other) -// { -// return *this; -// } - - EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } - - protected: - - const typename MatrixType::Nested m_matrix; - Index m_outerStart; - const internal::variable_if_dynamic<Index, Size> m_outerSize; - -}; - -#endif - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h deleted file mode 100644 index 536a0c32..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h +++ /dev/null @@ -1,1079 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Desire Nuentsa <desire.nuentsa_wakam@inria.fr> -// Copyright (C) 2013 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSEBLOCKMATRIX_H -#define EIGEN_SPARSEBLOCKMATRIX_H - -namespace Eigen { -/** \ingroup SparseCore_Module - * - * \class BlockSparseMatrix - * - * \brief A versatile sparse matrix representation where each element is a block - * - * This class provides routines to manipulate block sparse matrices stored in a - * BSR-like representation. There are two main types : - * - * 1. All blocks have the same number of rows and columns, called block size - * in the following. In this case, if this block size is known at compile time, - * it can be given as a template parameter like - * \code - * BlockSparseMatrix<Scalar, 3, ColMajor> bmat(b_rows, b_cols); - * \endcode - * Here, bmat is a b_rows x b_cols block sparse matrix - * where each coefficient is a 3x3 dense matrix. - * If the block size is fixed but will be given at runtime, - * \code - * BlockSparseMatrix<Scalar, Dynamic, ColMajor> bmat(b_rows, b_cols); - * bmat.setBlockSize(block_size); - * \endcode - * - * 2. The second case is for variable-block sparse matrices. - * Here each block has its own dimensions. The only restriction is that all the blocks - * in a row (resp. a column) should have the same number of rows (resp. of columns). - * It is thus required in this case to describe the layout of the matrix by calling - * setBlockLayout(rowBlocks, colBlocks). - * - * In any of the previous case, the matrix can be filled by calling setFromTriplets(). - * A regular sparse matrix can be converted to a block sparse matrix and vice versa. - * It is obviously required to describe the block layout beforehand by calling either - * setBlockSize() for fixed-size blocks or setBlockLayout for variable-size blocks. - * - * \tparam _Scalar The Scalar type - * \tparam _BlockAtCompileTime The block layout option. It takes the following values - * Dynamic : block size known at runtime - * a numeric number : fixed-size block known at compile time - */ -template<typename _Scalar, int _BlockAtCompileTime=Dynamic, int _Options=ColMajor, typename _StorageIndex=int> class BlockSparseMatrix; - -template<typename BlockSparseMatrixT> class BlockSparseMatrixView; - -namespace internal { -template<typename _Scalar, int _BlockAtCompileTime, int _Options, typename _Index> -struct traits<BlockSparseMatrix<_Scalar,_BlockAtCompileTime,_Options, _Index> > -{ - typedef _Scalar Scalar; - typedef _Index Index; - typedef Sparse StorageKind; // FIXME Where is it used ?? - typedef MatrixXpr XprKind; - enum { - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = Dynamic, - MaxRowsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic, - BlockSize = _BlockAtCompileTime, - Flags = _Options | NestByRefBit | LvalueBit, - CoeffReadCost = NumTraits<Scalar>::ReadCost, - SupportedAccessPatterns = InnerRandomAccessPattern - }; -}; -template<typename BlockSparseMatrixT> -struct traits<BlockSparseMatrixView<BlockSparseMatrixT> > -{ - typedef Ref<Matrix<typename BlockSparseMatrixT::Scalar, BlockSparseMatrixT::BlockSize, BlockSparseMatrixT::BlockSize> > Scalar; - typedef Ref<Matrix<typename BlockSparseMatrixT::RealScalar, BlockSparseMatrixT::BlockSize, BlockSparseMatrixT::BlockSize> > RealScalar; - -}; - -// Function object to sort a triplet list -template<typename Iterator, bool IsColMajor> -struct TripletComp -{ - typedef typename Iterator::value_type Triplet; - bool operator()(const Triplet& a, const Triplet& b) - { if(IsColMajor) - return ((a.col() == b.col() && a.row() < b.row()) || (a.col() < b.col())); - else - return ((a.row() == b.row() && a.col() < b.col()) || (a.row() < b.row())); - } -}; -} // end namespace internal - - -/* Proxy to view the block sparse matrix as a regular sparse matrix */ -template<typename BlockSparseMatrixT> -class BlockSparseMatrixView : public SparseMatrixBase<BlockSparseMatrixT> -{ - public: - typedef Ref<typename BlockSparseMatrixT::BlockScalar> Scalar; - typedef Ref<typename BlockSparseMatrixT::BlockRealScalar> RealScalar; - typedef typename BlockSparseMatrixT::Index Index; - typedef BlockSparseMatrixT Nested; - enum { - Flags = BlockSparseMatrixT::Options, - Options = BlockSparseMatrixT::Options, - RowsAtCompileTime = BlockSparseMatrixT::RowsAtCompileTime, - ColsAtCompileTime = BlockSparseMatrixT::ColsAtCompileTime, - MaxColsAtCompileTime = BlockSparseMatrixT::MaxColsAtCompileTime, - MaxRowsAtCompileTime = BlockSparseMatrixT::MaxRowsAtCompileTime - }; - public: - BlockSparseMatrixView(const BlockSparseMatrixT& spblockmat) - : m_spblockmat(spblockmat) - {} - - Index outerSize() const - { - return (Flags&RowMajorBit) == 1 ? this->rows() : this->cols(); - } - Index cols() const - { - return m_spblockmat.blockCols(); - } - Index rows() const - { - return m_spblockmat.blockRows(); - } - Scalar coeff(Index row, Index col) - { - return m_spblockmat.coeff(row, col); - } - Scalar coeffRef(Index row, Index col) - { - return m_spblockmat.coeffRef(row, col); - } - // Wrapper to iterate over all blocks - class InnerIterator : public BlockSparseMatrixT::BlockInnerIterator - { - public: - InnerIterator(const BlockSparseMatrixView& mat, Index outer) - : BlockSparseMatrixT::BlockInnerIterator(mat.m_spblockmat, outer) - {} - - }; - - protected: - const BlockSparseMatrixT& m_spblockmat; -}; - -// Proxy to view a regular vector as a block vector -template<typename BlockSparseMatrixT, typename VectorType> -class BlockVectorView -{ - public: - enum { - BlockSize = BlockSparseMatrixT::BlockSize, - ColsAtCompileTime = VectorType::ColsAtCompileTime, - RowsAtCompileTime = VectorType::RowsAtCompileTime, - Flags = VectorType::Flags - }; - typedef Ref<const Matrix<typename BlockSparseMatrixT::Scalar, (RowsAtCompileTime==1)? 1 : BlockSize, (ColsAtCompileTime==1)? 1 : BlockSize> >Scalar; - typedef typename BlockSparseMatrixT::Index Index; - public: - BlockVectorView(const BlockSparseMatrixT& spblockmat, const VectorType& vec) - : m_spblockmat(spblockmat),m_vec(vec) - { } - inline Index cols() const - { - return m_vec.cols(); - } - inline Index size() const - { - return m_spblockmat.blockRows(); - } - inline Scalar coeff(Index bi) const - { - Index startRow = m_spblockmat.blockRowsIndex(bi); - Index rowSize = m_spblockmat.blockRowsIndex(bi+1) - startRow; - return m_vec.middleRows(startRow, rowSize); - } - inline Scalar coeff(Index bi, Index j) const - { - Index startRow = m_spblockmat.blockRowsIndex(bi); - Index rowSize = m_spblockmat.blockRowsIndex(bi+1) - startRow; - return m_vec.block(startRow, j, rowSize, 1); - } - protected: - const BlockSparseMatrixT& m_spblockmat; - const VectorType& m_vec; -}; - -template<typename VectorType, typename Index> class BlockVectorReturn; - - -// Proxy to view a regular vector as a block vector -template<typename BlockSparseMatrixT, typename VectorType> -class BlockVectorReturn -{ - public: - enum { - ColsAtCompileTime = VectorType::ColsAtCompileTime, - RowsAtCompileTime = VectorType::RowsAtCompileTime, - Flags = VectorType::Flags - }; - typedef Ref<Matrix<typename VectorType::Scalar, RowsAtCompileTime, ColsAtCompileTime> > Scalar; - typedef typename BlockSparseMatrixT::Index Index; - public: - BlockVectorReturn(const BlockSparseMatrixT& spblockmat, VectorType& vec) - : m_spblockmat(spblockmat),m_vec(vec) - { } - inline Index size() const - { - return m_spblockmat.blockRows(); - } - inline Scalar coeffRef(Index bi) - { - Index startRow = m_spblockmat.blockRowsIndex(bi); - Index rowSize = m_spblockmat.blockRowsIndex(bi+1) - startRow; - return m_vec.middleRows(startRow, rowSize); - } - inline Scalar coeffRef(Index bi, Index j) - { - Index startRow = m_spblockmat.blockRowsIndex(bi); - Index rowSize = m_spblockmat.blockRowsIndex(bi+1) - startRow; - return m_vec.block(startRow, j, rowSize, 1); - } - - protected: - const BlockSparseMatrixT& m_spblockmat; - VectorType& m_vec; -}; - -// Block version of the sparse dense product -template<typename Lhs, typename Rhs> -class BlockSparseTimeDenseProduct; - -namespace internal { - -template<typename BlockSparseMatrixT, typename VecType> -struct traits<BlockSparseTimeDenseProduct<BlockSparseMatrixT, VecType> > -{ - typedef Dense StorageKind; - typedef MatrixXpr XprKind; - typedef typename BlockSparseMatrixT::Scalar Scalar; - typedef typename BlockSparseMatrixT::Index Index; - enum { - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = Dynamic, - MaxRowsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic, - Flags = 0, - CoeffReadCost = internal::traits<BlockSparseMatrixT>::CoeffReadCost - }; -}; -} // end namespace internal - -template<typename Lhs, typename Rhs> -class BlockSparseTimeDenseProduct - : public ProductBase<BlockSparseTimeDenseProduct<Lhs,Rhs>, Lhs, Rhs> -{ - public: - EIGEN_PRODUCT_PUBLIC_INTERFACE(BlockSparseTimeDenseProduct) - - BlockSparseTimeDenseProduct(const Lhs& lhs, const Rhs& rhs) : Base(lhs,rhs) - {} - - template<typename Dest> void scaleAndAddTo(Dest& dest, const typename Rhs::Scalar& alpha) const - { - BlockVectorReturn<Lhs,Dest> tmpDest(m_lhs, dest); - internal::sparse_time_dense_product( BlockSparseMatrixView<Lhs>(m_lhs), BlockVectorView<Lhs, Rhs>(m_lhs, m_rhs), tmpDest, alpha); - } - - private: - BlockSparseTimeDenseProduct& operator=(const BlockSparseTimeDenseProduct&); -}; - -template<typename _Scalar, int _BlockAtCompileTime, int _Options, typename _StorageIndex> -class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_BlockAtCompileTime, _Options,_StorageIndex> > -{ - public: - typedef _Scalar Scalar; - typedef typename NumTraits<Scalar>::Real RealScalar; - typedef _StorageIndex StorageIndex; - typedef typename internal::ref_selector<BlockSparseMatrix<_Scalar, _BlockAtCompileTime, _Options, _StorageIndex> >::type Nested; - - enum { - Options = _Options, - Flags = Options, - BlockSize=_BlockAtCompileTime, - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = Dynamic, - MaxRowsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic, - IsVectorAtCompileTime = 0, - IsColMajor = Flags&RowMajorBit ? 0 : 1 - }; - typedef Matrix<Scalar, _BlockAtCompileTime, _BlockAtCompileTime,IsColMajor ? ColMajor : RowMajor> BlockScalar; - typedef Matrix<RealScalar, _BlockAtCompileTime, _BlockAtCompileTime,IsColMajor ? ColMajor : RowMajor> BlockRealScalar; - typedef typename internal::conditional<_BlockAtCompileTime==Dynamic, Scalar, BlockScalar>::type BlockScalarReturnType; - typedef BlockSparseMatrix<Scalar, BlockSize, IsColMajor ? ColMajor : RowMajor, StorageIndex> PlainObject; - public: - // Default constructor - BlockSparseMatrix() - : m_innerBSize(0),m_outerBSize(0),m_innerOffset(0),m_outerOffset(0), - m_nonzerosblocks(0),m_values(0),m_blockPtr(0),m_indices(0), - m_outerIndex(0),m_blockSize(BlockSize) - { } - - - /** - * \brief Construct and resize - * - */ - BlockSparseMatrix(Index brow, Index bcol) - : m_innerBSize(IsColMajor ? brow : bcol), - m_outerBSize(IsColMajor ? bcol : brow), - m_innerOffset(0),m_outerOffset(0),m_nonzerosblocks(0), - m_values(0),m_blockPtr(0),m_indices(0), - m_outerIndex(0),m_blockSize(BlockSize) - { } - - /** - * \brief Copy-constructor - */ - BlockSparseMatrix(const BlockSparseMatrix& other) - : m_innerBSize(other.m_innerBSize),m_outerBSize(other.m_outerBSize), - m_nonzerosblocks(other.m_nonzerosblocks),m_nonzeros(other.m_nonzeros), - m_blockPtr(0),m_blockSize(other.m_blockSize) - { - // should we allow copying between variable-size blocks and fixed-size blocks ?? - eigen_assert(m_blockSize == BlockSize && " CAN NOT COPY BETWEEN FIXED-SIZE AND VARIABLE-SIZE BLOCKS"); - - std::copy(other.m_innerOffset, other.m_innerOffset+m_innerBSize+1, m_innerOffset); - std::copy(other.m_outerOffset, other.m_outerOffset+m_outerBSize+1, m_outerOffset); - std::copy(other.m_values, other.m_values+m_nonzeros, m_values); - - if(m_blockSize != Dynamic) - std::copy(other.m_blockPtr, other.m_blockPtr+m_nonzerosblocks, m_blockPtr); - - std::copy(other.m_indices, other.m_indices+m_nonzerosblocks, m_indices); - std::copy(other.m_outerIndex, other.m_outerIndex+m_outerBSize, m_outerIndex); - } - - friend void swap(BlockSparseMatrix& first, BlockSparseMatrix& second) - { - std::swap(first.m_innerBSize, second.m_innerBSize); - std::swap(first.m_outerBSize, second.m_outerBSize); - std::swap(first.m_innerOffset, second.m_innerOffset); - std::swap(first.m_outerOffset, second.m_outerOffset); - std::swap(first.m_nonzerosblocks, second.m_nonzerosblocks); - std::swap(first.m_nonzeros, second.m_nonzeros); - std::swap(first.m_values, second.m_values); - std::swap(first.m_blockPtr, second.m_blockPtr); - std::swap(first.m_indices, second.m_indices); - std::swap(first.m_outerIndex, second.m_outerIndex); - std::swap(first.m_BlockSize, second.m_blockSize); - } - - BlockSparseMatrix& operator=(BlockSparseMatrix other) - { - //Copy-and-swap paradigm ... avoid leaked data if thrown - swap(*this, other); - return *this; - } - - // Destructor - ~BlockSparseMatrix() - { - delete[] m_outerIndex; - delete[] m_innerOffset; - delete[] m_outerOffset; - delete[] m_indices; - delete[] m_blockPtr; - delete[] m_values; - } - - - /** - * \brief Constructor from a sparse matrix - * - */ - template<typename MatrixType> - inline BlockSparseMatrix(const MatrixType& spmat) : m_blockSize(BlockSize) - { - EIGEN_STATIC_ASSERT((m_blockSize != Dynamic), THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE); - - *this = spmat; - } - - /** - * \brief Assignment from a sparse matrix with the same storage order - * - * Convert from a sparse matrix to block sparse matrix. - * \warning Before calling this function, tt is necessary to call - * either setBlockLayout() (matrices with variable-size blocks) - * or setBlockSize() (for fixed-size blocks). - */ - template<typename MatrixType> - inline BlockSparseMatrix& operator=(const MatrixType& spmat) - { - eigen_assert((m_innerBSize != 0 && m_outerBSize != 0) - && "Trying to assign to a zero-size matrix, call resize() first"); - eigen_assert(((MatrixType::Options&RowMajorBit) != IsColMajor) && "Wrong storage order"); - typedef SparseMatrix<bool,MatrixType::Options,typename MatrixType::Index> MatrixPatternType; - MatrixPatternType blockPattern(blockRows(), blockCols()); - m_nonzeros = 0; - - // First, compute the number of nonzero blocks and their locations - for(StorageIndex bj = 0; bj < m_outerBSize; ++bj) - { - // Browse each outer block and compute the structure - std::vector<bool> nzblocksFlag(m_innerBSize,false); // Record the existing blocks - blockPattern.startVec(bj); - for(StorageIndex j = blockOuterIndex(bj); j < blockOuterIndex(bj+1); ++j) - { - typename MatrixType::InnerIterator it_spmat(spmat, j); - for(; it_spmat; ++it_spmat) - { - StorageIndex bi = innerToBlock(it_spmat.index()); // Index of the current nonzero block - if(!nzblocksFlag[bi]) - { - // Save the index of this nonzero block - nzblocksFlag[bi] = true; - blockPattern.insertBackByOuterInnerUnordered(bj, bi) = true; - // Compute the total number of nonzeros (including explicit zeros in blocks) - m_nonzeros += blockOuterSize(bj) * blockInnerSize(bi); - } - } - } // end current outer block - } - blockPattern.finalize(); - - // Allocate the internal arrays - setBlockStructure(blockPattern); - - for(StorageIndex nz = 0; nz < m_nonzeros; ++nz) m_values[nz] = Scalar(0); - for(StorageIndex bj = 0; bj < m_outerBSize; ++bj) - { - // Now copy the values - for(StorageIndex j = blockOuterIndex(bj); j < blockOuterIndex(bj+1); ++j) - { - // Browse the outer block column by column (for column-major matrices) - typename MatrixType::InnerIterator it_spmat(spmat, j); - for(; it_spmat; ++it_spmat) - { - StorageIndex idx = 0; // Position of this block in the column block - StorageIndex bi = innerToBlock(it_spmat.index()); // Index of the current nonzero block - // Go to the inner block where this element belongs to - while(bi > m_indices[m_outerIndex[bj]+idx]) ++idx; // Not expensive for ordered blocks - StorageIndex idxVal;// Get the right position in the array of values for this element - if(m_blockSize == Dynamic) - { - // Offset from all blocks before ... - idxVal = m_blockPtr[m_outerIndex[bj]+idx]; - // ... and offset inside the block - idxVal += (j - blockOuterIndex(bj)) * blockOuterSize(bj) + it_spmat.index() - m_innerOffset[bi]; - } - else - { - // All blocks before - idxVal = (m_outerIndex[bj] + idx) * m_blockSize * m_blockSize; - // inside the block - idxVal += (j - blockOuterIndex(bj)) * m_blockSize + (it_spmat.index()%m_blockSize); - } - // Insert the value - m_values[idxVal] = it_spmat.value(); - } // end of this column - } // end of this block - } // end of this outer block - - return *this; - } - - /** - * \brief Set the nonzero block pattern of the matrix - * - * Given a sparse matrix describing the nonzero block pattern, - * this function prepares the internal pointers for values. - * After calling this function, any *nonzero* block (bi, bj) can be set - * with a simple call to coeffRef(bi,bj). - * - * - * \warning Before calling this function, tt is necessary to call - * either setBlockLayout() (matrices with variable-size blocks) - * or setBlockSize() (for fixed-size blocks). - * - * \param blockPattern Sparse matrix of boolean elements describing the block structure - * - * \sa setBlockLayout() \sa setBlockSize() - */ - template<typename MatrixType> - void setBlockStructure(const MatrixType& blockPattern) - { - resize(blockPattern.rows(), blockPattern.cols()); - reserve(blockPattern.nonZeros()); - - // Browse the block pattern and set up the various pointers - m_outerIndex[0] = 0; - if(m_blockSize == Dynamic) m_blockPtr[0] = 0; - for(StorageIndex nz = 0; nz < m_nonzeros; ++nz) m_values[nz] = Scalar(0); - for(StorageIndex bj = 0; bj < m_outerBSize; ++bj) - { - //Browse each outer block - - //First, copy and save the indices of nonzero blocks - //FIXME : find a way to avoid this ... - std::vector<int> nzBlockIdx; - typename MatrixType::InnerIterator it(blockPattern, bj); - for(; it; ++it) - { - nzBlockIdx.push_back(it.index()); - } - std::sort(nzBlockIdx.begin(), nzBlockIdx.end()); - - // Now, fill block indices and (eventually) pointers to blocks - for(StorageIndex idx = 0; idx < nzBlockIdx.size(); ++idx) - { - StorageIndex offset = m_outerIndex[bj]+idx; // offset in m_indices - m_indices[offset] = nzBlockIdx[idx]; - if(m_blockSize == Dynamic) - m_blockPtr[offset] = m_blockPtr[offset-1] + blockInnerSize(nzBlockIdx[idx]) * blockOuterSize(bj); - // There is no blockPtr for fixed-size blocks... not needed !??? - } - // Save the pointer to the next outer block - m_outerIndex[bj+1] = m_outerIndex[bj] + nzBlockIdx.size(); - } - } - - /** - * \brief Set the number of rows and columns blocks - */ - inline void resize(Index brow, Index bcol) - { - m_innerBSize = IsColMajor ? brow : bcol; - m_outerBSize = IsColMajor ? bcol : brow; - } - - /** - * \brief set the block size at runtime for fixed-size block layout - * - * Call this only for fixed-size blocks - */ - inline void setBlockSize(Index blockSize) - { - m_blockSize = blockSize; - } - - /** - * \brief Set the row and column block layouts, - * - * This function set the size of each row and column block. - * So this function should be used only for blocks with variable size. - * \param rowBlocks : Number of rows per row block - * \param colBlocks : Number of columns per column block - * \sa resize(), setBlockSize() - */ - inline void setBlockLayout(const VectorXi& rowBlocks, const VectorXi& colBlocks) - { - const VectorXi& innerBlocks = IsColMajor ? rowBlocks : colBlocks; - const VectorXi& outerBlocks = IsColMajor ? colBlocks : rowBlocks; - eigen_assert(m_innerBSize == innerBlocks.size() && "CHECK THE NUMBER OF ROW OR COLUMN BLOCKS"); - eigen_assert(m_outerBSize == outerBlocks.size() && "CHECK THE NUMBER OF ROW OR COLUMN BLOCKS"); - m_outerBSize = outerBlocks.size(); - // starting index of blocks... cumulative sums - m_innerOffset = new StorageIndex[m_innerBSize+1]; - m_outerOffset = new StorageIndex[m_outerBSize+1]; - m_innerOffset[0] = 0; - m_outerOffset[0] = 0; - std::partial_sum(&innerBlocks[0], &innerBlocks[m_innerBSize-1]+1, &m_innerOffset[1]); - std::partial_sum(&outerBlocks[0], &outerBlocks[m_outerBSize-1]+1, &m_outerOffset[1]); - - // Compute the total number of nonzeros - m_nonzeros = 0; - for(StorageIndex bj = 0; bj < m_outerBSize; ++bj) - for(StorageIndex bi = 0; bi < m_innerBSize; ++bi) - m_nonzeros += outerBlocks[bj] * innerBlocks[bi]; - - } - - /** - * \brief Allocate the internal array of pointers to blocks and their inner indices - * - * \note For fixed-size blocks, call setBlockSize() to set the block. - * And For variable-size blocks, call setBlockLayout() before using this function - * - * \param nonzerosblocks Number of nonzero blocks. The total number of nonzeros is - * is computed in setBlockLayout() for variable-size blocks - * \sa setBlockSize() - */ - inline void reserve(const Index nonzerosblocks) - { - eigen_assert((m_innerBSize != 0 && m_outerBSize != 0) && - "TRYING TO RESERVE ZERO-SIZE MATRICES, CALL resize() first"); - - //FIXME Should free if already allocated - m_outerIndex = new StorageIndex[m_outerBSize+1]; - - m_nonzerosblocks = nonzerosblocks; - if(m_blockSize != Dynamic) - { - m_nonzeros = nonzerosblocks * (m_blockSize * m_blockSize); - m_blockPtr = 0; - } - else - { - // m_nonzeros is already computed in setBlockLayout() - m_blockPtr = new StorageIndex[m_nonzerosblocks+1]; - } - m_indices = new StorageIndex[m_nonzerosblocks+1]; - m_values = new Scalar[m_nonzeros]; - } - - - /** - * \brief Fill values in a matrix from a triplet list. - * - * Each triplet item has a block stored in an Eigen dense matrix. - * The InputIterator class should provide the functions row(), col() and value() - * - * \note For fixed-size blocks, call setBlockSize() before this function. - * - * FIXME Do not accept duplicates - */ - template<typename InputIterator> - void setFromTriplets(const InputIterator& begin, const InputIterator& end) - { - eigen_assert((m_innerBSize!=0 && m_outerBSize !=0) && "ZERO BLOCKS, PLEASE CALL resize() before"); - - /* First, sort the triplet list - * FIXME This can be unnecessarily expensive since only the inner indices have to be sorted - * The best approach is like in SparseMatrix::setFromTriplets() - */ - internal::TripletComp<InputIterator, IsColMajor> tripletcomp; - std::sort(begin, end, tripletcomp); - - /* Count the number of rows and column blocks, - * and the number of nonzero blocks per outer dimension - */ - VectorXi rowBlocks(m_innerBSize); // Size of each block row - VectorXi colBlocks(m_outerBSize); // Size of each block column - rowBlocks.setZero(); colBlocks.setZero(); - VectorXi nzblock_outer(m_outerBSize); // Number of nz blocks per outer vector - VectorXi nz_outer(m_outerBSize); // Number of nz per outer vector...for variable-size blocks - nzblock_outer.setZero(); - nz_outer.setZero(); - for(InputIterator it(begin); it !=end; ++it) - { - eigen_assert(it->row() >= 0 && it->row() < this->blockRows() && it->col() >= 0 && it->col() < this->blockCols()); - eigen_assert((it->value().rows() == it->value().cols() && (it->value().rows() == m_blockSize)) - || (m_blockSize == Dynamic)); - - if(m_blockSize == Dynamic) - { - eigen_assert((rowBlocks[it->row()] == 0 || rowBlocks[it->row()] == it->value().rows()) && - "NON CORRESPONDING SIZES FOR ROW BLOCKS"); - eigen_assert((colBlocks[it->col()] == 0 || colBlocks[it->col()] == it->value().cols()) && - "NON CORRESPONDING SIZES FOR COLUMN BLOCKS"); - rowBlocks[it->row()] =it->value().rows(); - colBlocks[it->col()] = it->value().cols(); - } - nz_outer(IsColMajor ? it->col() : it->row()) += it->value().rows() * it->value().cols(); - nzblock_outer(IsColMajor ? it->col() : it->row())++; - } - // Allocate member arrays - if(m_blockSize == Dynamic) setBlockLayout(rowBlocks, colBlocks); - StorageIndex nzblocks = nzblock_outer.sum(); - reserve(nzblocks); - - // Temporary markers - VectorXi block_id(m_outerBSize); // To be used as a block marker during insertion - - // Setup outer index pointers and markers - m_outerIndex[0] = 0; - if (m_blockSize == Dynamic) m_blockPtr[0] = 0; - for(StorageIndex bj = 0; bj < m_outerBSize; ++bj) - { - m_outerIndex[bj+1] = m_outerIndex[bj] + nzblock_outer(bj); - block_id(bj) = m_outerIndex[bj]; - if(m_blockSize==Dynamic) - { - m_blockPtr[m_outerIndex[bj+1]] = m_blockPtr[m_outerIndex[bj]] + nz_outer(bj); - } - } - - // Fill the matrix - for(InputIterator it(begin); it!=end; ++it) - { - StorageIndex outer = IsColMajor ? it->col() : it->row(); - StorageIndex inner = IsColMajor ? it->row() : it->col(); - m_indices[block_id(outer)] = inner; - StorageIndex block_size = it->value().rows()*it->value().cols(); - StorageIndex nz_marker = blockPtr(block_id[outer]); - memcpy(&(m_values[nz_marker]), it->value().data(), block_size * sizeof(Scalar)); - if(m_blockSize == Dynamic) - { - m_blockPtr[block_id(outer)+1] = m_blockPtr[block_id(outer)] + block_size; - } - block_id(outer)++; - } - - // An alternative when the outer indices are sorted...no need to use an array of markers -// for(Index bcol = 0; bcol < m_outerBSize; ++bcol) -// { -// Index id = 0, id_nz = 0, id_nzblock = 0; -// for(InputIterator it(begin); it!=end; ++it) -// { -// while (id<bcol) // one pass should do the job unless there are empty columns -// { -// id++; -// m_outerIndex[id+1]=m_outerIndex[id]; -// } -// m_outerIndex[id+1] += 1; -// m_indices[id_nzblock]=brow; -// Index block_size = it->value().rows()*it->value().cols(); -// m_blockPtr[id_nzblock+1] = m_blockPtr[id_nzblock] + block_size; -// id_nzblock++; -// memcpy(&(m_values[id_nz]),it->value().data(), block_size*sizeof(Scalar)); -// id_nz += block_size; -// } -// while(id < m_outerBSize-1) // Empty columns at the end -// { -// id++; -// m_outerIndex[id+1]=m_outerIndex[id]; -// } -// } - } - - - /** - * \returns the number of rows - */ - inline Index rows() const - { -// return blockRows(); - return (IsColMajor ? innerSize() : outerSize()); - } - - /** - * \returns the number of cols - */ - inline Index cols() const - { -// return blockCols(); - return (IsColMajor ? outerSize() : innerSize()); - } - - inline Index innerSize() const - { - if(m_blockSize == Dynamic) return m_innerOffset[m_innerBSize]; - else return (m_innerBSize * m_blockSize) ; - } - - inline Index outerSize() const - { - if(m_blockSize == Dynamic) return m_outerOffset[m_outerBSize]; - else return (m_outerBSize * m_blockSize) ; - } - /** \returns the number of rows grouped by blocks */ - inline Index blockRows() const - { - return (IsColMajor ? m_innerBSize : m_outerBSize); - } - /** \returns the number of columns grouped by blocks */ - inline Index blockCols() const - { - return (IsColMajor ? m_outerBSize : m_innerBSize); - } - - inline Index outerBlocks() const { return m_outerBSize; } - inline Index innerBlocks() const { return m_innerBSize; } - - /** \returns the block index where outer belongs to */ - inline Index outerToBlock(Index outer) const - { - eigen_assert(outer < outerSize() && "OUTER INDEX OUT OF BOUNDS"); - - if(m_blockSize != Dynamic) - return (outer / m_blockSize); // Integer division - - StorageIndex b_outer = 0; - while(m_outerOffset[b_outer] <= outer) ++b_outer; - return b_outer - 1; - } - /** \returns the block index where inner belongs to */ - inline Index innerToBlock(Index inner) const - { - eigen_assert(inner < innerSize() && "OUTER INDEX OUT OF BOUNDS"); - - if(m_blockSize != Dynamic) - return (inner / m_blockSize); // Integer division - - StorageIndex b_inner = 0; - while(m_innerOffset[b_inner] <= inner) ++b_inner; - return b_inner - 1; - } - - /** - *\returns a reference to the (i,j) block as an Eigen Dense Matrix - */ - Ref<BlockScalar> coeffRef(Index brow, Index bcol) - { - eigen_assert(brow < blockRows() && "BLOCK ROW INDEX OUT OF BOUNDS"); - eigen_assert(bcol < blockCols() && "BLOCK nzblocksFlagCOLUMN OUT OF BOUNDS"); - - StorageIndex rsize = IsColMajor ? blockInnerSize(brow): blockOuterSize(bcol); - StorageIndex csize = IsColMajor ? blockOuterSize(bcol) : blockInnerSize(brow); - StorageIndex inner = IsColMajor ? brow : bcol; - StorageIndex outer = IsColMajor ? bcol : brow; - StorageIndex offset = m_outerIndex[outer]; - while(offset < m_outerIndex[outer+1] && m_indices[offset] != inner) - offset++; - if(m_indices[offset] == inner) - { - return Map<BlockScalar>(&(m_values[blockPtr(offset)]), rsize, csize); - } - else - { - //FIXME the block does not exist, Insert it !!!!!!!!! - eigen_assert("DYNAMIC INSERTION IS NOT YET SUPPORTED"); - } - } - - /** - * \returns the value of the (i,j) block as an Eigen Dense Matrix - */ - Map<const BlockScalar> coeff(Index brow, Index bcol) const - { - eigen_assert(brow < blockRows() && "BLOCK ROW INDEX OUT OF BOUNDS"); - eigen_assert(bcol < blockCols() && "BLOCK COLUMN OUT OF BOUNDS"); - - StorageIndex rsize = IsColMajor ? blockInnerSize(brow): blockOuterSize(bcol); - StorageIndex csize = IsColMajor ? blockOuterSize(bcol) : blockInnerSize(brow); - StorageIndex inner = IsColMajor ? brow : bcol; - StorageIndex outer = IsColMajor ? bcol : brow; - StorageIndex offset = m_outerIndex[outer]; - while(offset < m_outerIndex[outer+1] && m_indices[offset] != inner) offset++; - if(m_indices[offset] == inner) - { - return Map<const BlockScalar> (&(m_values[blockPtr(offset)]), rsize, csize); - } - else -// return BlockScalar::Zero(rsize, csize); - eigen_assert("NOT YET SUPPORTED"); - } - - // Block Matrix times vector product - template<typename VecType> - BlockSparseTimeDenseProduct<BlockSparseMatrix, VecType> operator*(const VecType& lhs) const - { - return BlockSparseTimeDenseProduct<BlockSparseMatrix, VecType>(*this, lhs); - } - - /** \returns the number of nonzero blocks */ - inline Index nonZerosBlocks() const { return m_nonzerosblocks; } - /** \returns the total number of nonzero elements, including eventual explicit zeros in blocks */ - inline Index nonZeros() const { return m_nonzeros; } - - inline BlockScalarReturnType *valuePtr() {return static_cast<BlockScalarReturnType *>(m_values);} -// inline Scalar *valuePtr(){ return m_values; } - inline StorageIndex *innerIndexPtr() {return m_indices; } - inline const StorageIndex *innerIndexPtr() const {return m_indices; } - inline StorageIndex *outerIndexPtr() {return m_outerIndex; } - inline const StorageIndex* outerIndexPtr() const {return m_outerIndex; } - - /** \brief for compatibility purposes with the SparseMatrix class */ - inline bool isCompressed() const {return true;} - /** - * \returns the starting index of the bi row block - */ - inline Index blockRowsIndex(Index bi) const - { - return IsColMajor ? blockInnerIndex(bi) : blockOuterIndex(bi); - } - - /** - * \returns the starting index of the bj col block - */ - inline Index blockColsIndex(Index bj) const - { - return IsColMajor ? blockOuterIndex(bj) : blockInnerIndex(bj); - } - - inline Index blockOuterIndex(Index bj) const - { - return (m_blockSize == Dynamic) ? m_outerOffset[bj] : (bj * m_blockSize); - } - inline Index blockInnerIndex(Index bi) const - { - return (m_blockSize == Dynamic) ? m_innerOffset[bi] : (bi * m_blockSize); - } - - // Not needed ??? - inline Index blockInnerSize(Index bi) const - { - return (m_blockSize == Dynamic) ? (m_innerOffset[bi+1] - m_innerOffset[bi]) : m_blockSize; - } - inline Index blockOuterSize(Index bj) const - { - return (m_blockSize == Dynamic) ? (m_outerOffset[bj+1]- m_outerOffset[bj]) : m_blockSize; - } - - /** - * \brief Browse the matrix by outer index - */ - class InnerIterator; // Browse column by column - - /** - * \brief Browse the matrix by block outer index - */ - class BlockInnerIterator; // Browse block by block - - friend std::ostream & operator << (std::ostream & s, const BlockSparseMatrix& m) - { - for (StorageIndex j = 0; j < m.outerBlocks(); ++j) - { - BlockInnerIterator itb(m, j); - for(; itb; ++itb) - { - s << "("<<itb.row() << ", " << itb.col() << ")\n"; - s << itb.value() <<"\n"; - } - } - s << std::endl; - return s; - } - - /** - * \returns the starting position of the block \p id in the array of values - */ - Index blockPtr(Index id) const - { - if(m_blockSize == Dynamic) return m_blockPtr[id]; - else return id * m_blockSize * m_blockSize; - //return blockDynIdx(id, typename internal::conditional<(BlockSize==Dynamic), internal::true_type, internal::false_type>::type()); - } - - - protected: -// inline Index blockDynIdx(Index id, internal::true_type) const -// { -// return m_blockPtr[id]; -// } -// inline Index blockDynIdx(Index id, internal::false_type) const -// { -// return id * BlockSize * BlockSize; -// } - - // To be implemented - // Insert a block at a particular location... need to make a room for that - Map<BlockScalar> insert(Index brow, Index bcol); - - Index m_innerBSize; // Number of block rows - Index m_outerBSize; // Number of block columns - StorageIndex *m_innerOffset; // Starting index of each inner block (size m_innerBSize+1) - StorageIndex *m_outerOffset; // Starting index of each outer block (size m_outerBSize+1) - Index m_nonzerosblocks; // Total nonzeros blocks (lower than m_innerBSize x m_outerBSize) - Index m_nonzeros; // Total nonzeros elements - Scalar *m_values; //Values stored block column after block column (size m_nonzeros) - StorageIndex *m_blockPtr; // Pointer to the beginning of each block in m_values, size m_nonzeroblocks ... null for fixed-size blocks - StorageIndex *m_indices; //Inner block indices, size m_nonzerosblocks ... OK - StorageIndex *m_outerIndex; // Starting pointer of each block column in m_indices (size m_outerBSize)... OK - Index m_blockSize; // Size of a block for fixed-size blocks, otherwise -1 -}; - -template<typename _Scalar, int _BlockAtCompileTime, int _Options, typename _StorageIndex> -class BlockSparseMatrix<_Scalar, _BlockAtCompileTime, _Options, _StorageIndex>::BlockInnerIterator -{ - public: - - enum{ - Flags = _Options - }; - - BlockInnerIterator(const BlockSparseMatrix& mat, const Index outer) - : m_mat(mat),m_outer(outer), - m_id(mat.m_outerIndex[outer]), - m_end(mat.m_outerIndex[outer+1]) - { - } - - inline BlockInnerIterator& operator++() {m_id++; return *this; } - - inline const Map<const BlockScalar> value() const - { - return Map<const BlockScalar>(&(m_mat.m_values[m_mat.blockPtr(m_id)]), - rows(),cols()); - } - inline Map<BlockScalar> valueRef() - { - return Map<BlockScalar>(&(m_mat.m_values[m_mat.blockPtr(m_id)]), - rows(),cols()); - } - // Block inner index - inline Index index() const {return m_mat.m_indices[m_id]; } - inline Index outer() const { return m_outer; } - // block row index - inline Index row() const {return index(); } - // block column index - inline Index col() const {return outer(); } - // FIXME Number of rows in the current block - inline Index rows() const { return (m_mat.m_blockSize==Dynamic) ? (m_mat.m_innerOffset[index()+1] - m_mat.m_innerOffset[index()]) : m_mat.m_blockSize; } - // Number of columns in the current block ... - inline Index cols() const { return (m_mat.m_blockSize==Dynamic) ? (m_mat.m_outerOffset[m_outer+1]-m_mat.m_outerOffset[m_outer]) : m_mat.m_blockSize;} - inline operator bool() const { return (m_id < m_end); } - - protected: - const BlockSparseMatrix<_Scalar, _BlockAtCompileTime, _Options, StorageIndex>& m_mat; - const Index m_outer; - Index m_id; - Index m_end; -}; - -template<typename _Scalar, int _BlockAtCompileTime, int _Options, typename _StorageIndex> -class BlockSparseMatrix<_Scalar, _BlockAtCompileTime, _Options, _StorageIndex>::InnerIterator -{ - public: - InnerIterator(const BlockSparseMatrix& mat, Index outer) - : m_mat(mat),m_outerB(mat.outerToBlock(outer)),m_outer(outer), - itb(mat, mat.outerToBlock(outer)), - m_offset(outer - mat.blockOuterIndex(m_outerB)) - { - if (itb) - { - m_id = m_mat.blockInnerIndex(itb.index()); - m_start = m_id; - m_end = m_mat.blockInnerIndex(itb.index()+1); - } - } - inline InnerIterator& operator++() - { - m_id++; - if (m_id >= m_end) - { - ++itb; - if (itb) - { - m_id = m_mat.blockInnerIndex(itb.index()); - m_start = m_id; - m_end = m_mat.blockInnerIndex(itb.index()+1); - } - } - return *this; - } - inline const Scalar& value() const - { - return itb.value().coeff(m_id - m_start, m_offset); - } - inline Scalar& valueRef() - { - return itb.valueRef().coeff(m_id - m_start, m_offset); - } - inline Index index() const { return m_id; } - inline Index outer() const {return m_outer; } - inline Index col() const {return outer(); } - inline Index row() const { return index();} - inline operator bool() const - { - return itb; - } - protected: - const BlockSparseMatrix& m_mat; - const Index m_outer; - const Index m_outerB; - BlockInnerIterator itb; // Iterator through the blocks - const Index m_offset; // Position of this column in the block - Index m_start; // starting inner index of this block - Index m_id; // current inner index in the block - Index m_end; // starting inner index of the next block - -}; -} // end namespace Eigen - -#endif // EIGEN_SPARSEBLOCKMATRIX_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h deleted file mode 100644 index 42c99e46..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h +++ /dev/null @@ -1,404 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_DYNAMIC_SPARSEMATRIX_H -#define EIGEN_DYNAMIC_SPARSEMATRIX_H - -namespace Eigen { - -/** \deprecated use a SparseMatrix in an uncompressed mode - * - * \class DynamicSparseMatrix - * - * \brief A sparse matrix class designed for matrix assembly purpose - * - * \param _Scalar the scalar type, i.e. the type of the coefficients - * - * Unlike SparseMatrix, this class provides a much higher degree of flexibility. In particular, it allows - * random read/write accesses in log(rho*outer_size) where \c rho is the probability that a coefficient is - * nonzero and outer_size is the number of columns if the matrix is column-major and the number of rows - * otherwise. - * - * Internally, the data are stored as a std::vector of compressed vector. The performances of random writes might - * decrease as the number of nonzeros per inner-vector increase. In practice, we observed very good performance - * till about 100 nonzeros/vector, and the performance remains relatively good till 500 nonzeros/vectors. - * - * \see SparseMatrix - */ - -namespace internal { -template<typename _Scalar, int _Options, typename _StorageIndex> -struct traits<DynamicSparseMatrix<_Scalar, _Options, _StorageIndex> > -{ - typedef _Scalar Scalar; - typedef _StorageIndex StorageIndex; - typedef Sparse StorageKind; - typedef MatrixXpr XprKind; - enum { - RowsAtCompileTime = Dynamic, - ColsAtCompileTime = Dynamic, - MaxRowsAtCompileTime = Dynamic, - MaxColsAtCompileTime = Dynamic, - Flags = _Options | NestByRefBit | LvalueBit, - CoeffReadCost = NumTraits<Scalar>::ReadCost, - SupportedAccessPatterns = OuterRandomAccessPattern - }; -}; -} - -template<typename _Scalar, int _Options, typename _StorageIndex> - class DynamicSparseMatrix - : public SparseMatrixBase<DynamicSparseMatrix<_Scalar, _Options, _StorageIndex> > -{ - typedef SparseMatrixBase<DynamicSparseMatrix> Base; - using Base::convert_index; - public: - EIGEN_SPARSE_PUBLIC_INTERFACE(DynamicSparseMatrix) - // FIXME: why are these operator already alvailable ??? - // EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, +=) - // EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, -=) - typedef MappedSparseMatrix<Scalar,Flags> Map; - using Base::IsRowMajor; - using Base::operator=; - enum { - Options = _Options - }; - - protected: - - typedef DynamicSparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0), StorageIndex> TransposedSparseMatrix; - - Index m_innerSize; - std::vector<internal::CompressedStorage<Scalar,StorageIndex> > m_data; - - public: - - inline Index rows() const { return IsRowMajor ? outerSize() : m_innerSize; } - inline Index cols() const { return IsRowMajor ? m_innerSize : outerSize(); } - inline Index innerSize() const { return m_innerSize; } - inline Index outerSize() const { return convert_index(m_data.size()); } - inline Index innerNonZeros(Index j) const { return m_data[j].size(); } - - std::vector<internal::CompressedStorage<Scalar,StorageIndex> >& _data() { return m_data; } - const std::vector<internal::CompressedStorage<Scalar,StorageIndex> >& _data() const { return m_data; } - - /** \returns the coefficient value at given position \a row, \a col - * This operation involes a log(rho*outer_size) binary search. - */ - inline Scalar coeff(Index row, Index col) const - { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - return m_data[outer].at(inner); - } - - /** \returns a reference to the coefficient value at given position \a row, \a col - * This operation involes a log(rho*outer_size) binary search. If the coefficient does not - * exist yet, then a sorted insertion into a sequential buffer is performed. - */ - inline Scalar& coeffRef(Index row, Index col) - { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - return m_data[outer].atWithInsertion(inner); - } - - class InnerIterator; - class ReverseInnerIterator; - - void setZero() - { - for (Index j=0; j<outerSize(); ++j) - m_data[j].clear(); - } - - /** \returns the number of non zero coefficients */ - Index nonZeros() const - { - Index res = 0; - for (Index j=0; j<outerSize(); ++j) - res += m_data[j].size(); - return res; - } - - - - void reserve(Index reserveSize = 1000) - { - if (outerSize()>0) - { - Index reserveSizePerVector = (std::max)(reserveSize/outerSize(),Index(4)); - for (Index j=0; j<outerSize(); ++j) - { - m_data[j].reserve(reserveSizePerVector); - } - } - } - - /** Does nothing: provided for compatibility with SparseMatrix */ - inline void startVec(Index /*outer*/) {} - - /** \returns a reference to the non zero coefficient at position \a row, \a col assuming that: - * - the nonzero does not already exist - * - the new coefficient is the last one of the given inner vector. - * - * \sa insert, insertBackByOuterInner */ - inline Scalar& insertBack(Index row, Index col) - { - return insertBackByOuterInner(IsRowMajor?row:col, IsRowMajor?col:row); - } - - /** \sa insertBack */ - inline Scalar& insertBackByOuterInner(Index outer, Index inner) - { - eigen_assert(outer<Index(m_data.size()) && inner<m_innerSize && "out of range"); - eigen_assert(((m_data[outer].size()==0) || (m_data[outer].index(m_data[outer].size()-1)<inner)) - && "wrong sorted insertion"); - m_data[outer].append(0, inner); - return m_data[outer].value(m_data[outer].size()-1); - } - - inline Scalar& insert(Index row, Index col) - { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - - Index startId = 0; - Index id = static_cast<Index>(m_data[outer].size()) - 1; - m_data[outer].resize(id+2,1); - - while ( (id >= startId) && (m_data[outer].index(id) > inner) ) - { - m_data[outer].index(id+1) = m_data[outer].index(id); - m_data[outer].value(id+1) = m_data[outer].value(id); - --id; - } - m_data[outer].index(id+1) = inner; - m_data[outer].value(id+1) = 0; - return m_data[outer].value(id+1); - } - - /** Does nothing: provided for compatibility with SparseMatrix */ - inline void finalize() {} - - /** Suppress all nonzeros which are smaller than \a reference under the tolerance \a epsilon */ - void prune(Scalar reference, RealScalar epsilon = NumTraits<RealScalar>::dummy_precision()) - { - for (Index j=0; j<outerSize(); ++j) - m_data[j].prune(reference,epsilon); - } - - /** Resize the matrix without preserving the data (the matrix is set to zero) - */ - void resize(Index rows, Index cols) - { - const Index outerSize = IsRowMajor ? rows : cols; - m_innerSize = convert_index(IsRowMajor ? cols : rows); - setZero(); - if (Index(m_data.size()) != outerSize) - { - m_data.resize(outerSize); - } - } - - void resizeAndKeepData(Index rows, Index cols) - { - const Index outerSize = IsRowMajor ? rows : cols; - const Index innerSize = IsRowMajor ? cols : rows; - if (m_innerSize>innerSize) - { - // remove all coefficients with innerCoord>=innerSize - // TODO - //std::cerr << "not implemented yet\n"; - exit(2); - } - if (m_data.size() != outerSize) - { - m_data.resize(outerSize); - } - } - - /** The class DynamicSparseMatrix is deprecated */ - EIGEN_DEPRECATED inline DynamicSparseMatrix() - : m_innerSize(0), m_data(0) - { - #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - #endif - eigen_assert(innerSize()==0 && outerSize()==0); - } - - /** The class DynamicSparseMatrix is deprecated */ - EIGEN_DEPRECATED inline DynamicSparseMatrix(Index rows, Index cols) - : m_innerSize(0) - { - #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - #endif - resize(rows, cols); - } - - /** The class DynamicSparseMatrix is deprecated */ - template<typename OtherDerived> - EIGEN_DEPRECATED explicit inline DynamicSparseMatrix(const SparseMatrixBase<OtherDerived>& other) - : m_innerSize(0) - { - #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - #endif - Base::operator=(other.derived()); - } - - inline DynamicSparseMatrix(const DynamicSparseMatrix& other) - : Base(), m_innerSize(0) - { - #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN - #endif - *this = other.derived(); - } - - inline void swap(DynamicSparseMatrix& other) - { - //EIGEN_DBG_SPARSE(std::cout << "SparseMatrix:: swap\n"); - std::swap(m_innerSize, other.m_innerSize); - //std::swap(m_outerSize, other.m_outerSize); - m_data.swap(other.m_data); - } - - inline DynamicSparseMatrix& operator=(const DynamicSparseMatrix& other) - { - if (other.isRValue()) - { - swap(other.const_cast_derived()); - } - else - { - resize(other.rows(), other.cols()); - m_data = other.m_data; - } - return *this; - } - - /** Destructor */ - inline ~DynamicSparseMatrix() {} - - public: - - /** \deprecated - * Set the matrix to zero and reserve the memory for \a reserveSize nonzero coefficients. */ - EIGEN_DEPRECATED void startFill(Index reserveSize = 1000) - { - setZero(); - reserve(reserveSize); - } - - /** \deprecated use insert() - * inserts a nonzero coefficient at given coordinates \a row, \a col and returns its reference assuming that: - * 1 - the coefficient does not exist yet - * 2 - this the coefficient with greater inner coordinate for the given outer coordinate. - * In other words, assuming \c *this is column-major, then there must not exists any nonzero coefficient of coordinates - * \c i \c x \a col such that \c i >= \a row. Otherwise the matrix is invalid. - * - * \see fillrand(), coeffRef() - */ - EIGEN_DEPRECATED Scalar& fill(Index row, Index col) - { - const Index outer = IsRowMajor ? row : col; - const Index inner = IsRowMajor ? col : row; - return insertBack(outer,inner); - } - - /** \deprecated use insert() - * Like fill() but with random inner coordinates. - * Compared to the generic coeffRef(), the unique limitation is that we assume - * the coefficient does not exist yet. - */ - EIGEN_DEPRECATED Scalar& fillrand(Index row, Index col) - { - return insert(row,col); - } - - /** \deprecated use finalize() - * Does nothing. Provided for compatibility with SparseMatrix. */ - EIGEN_DEPRECATED void endFill() {} - -# ifdef EIGEN_DYNAMICSPARSEMATRIX_PLUGIN -# include EIGEN_DYNAMICSPARSEMATRIX_PLUGIN -# endif - }; - -template<typename Scalar, int _Options, typename _StorageIndex> -class DynamicSparseMatrix<Scalar,_Options,_StorageIndex>::InnerIterator : public SparseVector<Scalar,_Options,_StorageIndex>::InnerIterator -{ - typedef typename SparseVector<Scalar,_Options,_StorageIndex>::InnerIterator Base; - public: - InnerIterator(const DynamicSparseMatrix& mat, Index outer) - : Base(mat.m_data[outer]), m_outer(outer) - {} - - inline Index row() const { return IsRowMajor ? m_outer : Base::index(); } - inline Index col() const { return IsRowMajor ? Base::index() : m_outer; } - inline Index outer() const { return m_outer; } - - protected: - const Index m_outer; -}; - -template<typename Scalar, int _Options, typename _StorageIndex> -class DynamicSparseMatrix<Scalar,_Options,_StorageIndex>::ReverseInnerIterator : public SparseVector<Scalar,_Options,_StorageIndex>::ReverseInnerIterator -{ - typedef typename SparseVector<Scalar,_Options,_StorageIndex>::ReverseInnerIterator Base; - public: - ReverseInnerIterator(const DynamicSparseMatrix& mat, Index outer) - : Base(mat.m_data[outer]), m_outer(outer) - {} - - inline Index row() const { return IsRowMajor ? m_outer : Base::index(); } - inline Index col() const { return IsRowMajor ? Base::index() : m_outer; } - inline Index outer() const { return m_outer; } - - protected: - const Index m_outer; -}; - -namespace internal { - -template<typename _Scalar, int _Options, typename _StorageIndex> -struct evaluator<DynamicSparseMatrix<_Scalar,_Options,_StorageIndex> > - : evaluator_base<DynamicSparseMatrix<_Scalar,_Options,_StorageIndex> > -{ - typedef _Scalar Scalar; - typedef DynamicSparseMatrix<_Scalar,_Options,_StorageIndex> SparseMatrixType; - typedef typename SparseMatrixType::InnerIterator InnerIterator; - typedef typename SparseMatrixType::ReverseInnerIterator ReverseInnerIterator; - - enum { - CoeffReadCost = NumTraits<_Scalar>::ReadCost, - Flags = SparseMatrixType::Flags - }; - - evaluator() : m_matrix(0) {} - evaluator(const SparseMatrixType &mat) : m_matrix(&mat) {} - - operator SparseMatrixType&() { return m_matrix->const_cast_derived(); } - operator const SparseMatrixType&() const { return *m_matrix; } - - Scalar coeff(Index row, Index col) const { return m_matrix->coeff(row,col); } - - Index nonZerosEstimate() const { return m_matrix->nonZeros(); } - - const SparseMatrixType *m_matrix; -}; - -} - -} // end namespace Eigen - -#endif // EIGEN_DYNAMIC_SPARSEMATRIX_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h deleted file mode 100644 index 1618b09a..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h +++ /dev/null @@ -1,282 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2012 Desire NUENTSA WAKAM <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPARSE_MARKET_IO_H -#define EIGEN_SPARSE_MARKET_IO_H - -#include <iostream> -#include <vector> - -namespace Eigen { - -namespace internal -{ - template <typename Scalar, typename StorageIndex> - inline void GetMarketLine (const char* line, StorageIndex& i, StorageIndex& j, Scalar& value) - { - std::stringstream sline(line); - sline >> i >> j >> value; - } - - template<> inline void GetMarketLine (const char* line, int& i, int& j, float& value) - { std::sscanf(line, "%d %d %g", &i, &j, &value); } - - template<> inline void GetMarketLine (const char* line, int& i, int& j, double& value) - { std::sscanf(line, "%d %d %lg", &i, &j, &value); } - - template<> inline void GetMarketLine (const char* line, int& i, int& j, std::complex<float>& value) - { std::sscanf(line, "%d %d %g %g", &i, &j, &numext::real_ref(value), &numext::imag_ref(value)); } - - template<> inline void GetMarketLine (const char* line, int& i, int& j, std::complex<double>& value) - { std::sscanf(line, "%d %d %lg %lg", &i, &j, &numext::real_ref(value), &numext::imag_ref(value)); } - - template <typename Scalar, typename StorageIndex> - inline void GetMarketLine (const char* line, StorageIndex& i, StorageIndex& j, std::complex<Scalar>& value) - { - std::stringstream sline(line); - Scalar valR, valI; - sline >> i >> j >> valR >> valI; - value = std::complex<Scalar>(valR,valI); - } - - template <typename RealScalar> - inline void GetVectorElt (const std::string& line, RealScalar& val) - { - std::istringstream newline(line); - newline >> val; - } - - template <typename RealScalar> - inline void GetVectorElt (const std::string& line, std::complex<RealScalar>& val) - { - RealScalar valR, valI; - std::istringstream newline(line); - newline >> valR >> valI; - val = std::complex<RealScalar>(valR, valI); - } - - template<typename Scalar> - inline void putMarketHeader(std::string& header,int sym) - { - header= "%%MatrixMarket matrix coordinate "; - if(internal::is_same<Scalar, std::complex<float> >::value || internal::is_same<Scalar, std::complex<double> >::value) - { - header += " complex"; - if(sym == Symmetric) header += " symmetric"; - else if (sym == SelfAdjoint) header += " Hermitian"; - else header += " general"; - } - else - { - header += " real"; - if(sym == Symmetric) header += " symmetric"; - else header += " general"; - } - } - - template<typename Scalar, typename StorageIndex> - inline void PutMatrixElt(Scalar value, StorageIndex row, StorageIndex col, std::ofstream& out) - { - out << row << " "<< col << " " << value << "\n"; - } - template<typename Scalar, typename StorageIndex> - inline void PutMatrixElt(std::complex<Scalar> value, StorageIndex row, StorageIndex col, std::ofstream& out) - { - out << row << " " << col << " " << value.real() << " " << value.imag() << "\n"; - } - - - template<typename Scalar> - inline void putVectorElt(Scalar value, std::ofstream& out) - { - out << value << "\n"; - } - template<typename Scalar> - inline void putVectorElt(std::complex<Scalar> value, std::ofstream& out) - { - out << value.real << " " << value.imag()<< "\n"; - } - -} // end namespace internal - -inline bool getMarketHeader(const std::string& filename, int& sym, bool& iscomplex, bool& isvector) -{ - sym = 0; - iscomplex = false; - isvector = false; - std::ifstream in(filename.c_str(),std::ios::in); - if(!in) - return false; - - std::string line; - // The matrix header is always the first line in the file - std::getline(in, line); eigen_assert(in.good()); - - std::stringstream fmtline(line); - std::string substr[5]; - fmtline>> substr[0] >> substr[1] >> substr[2] >> substr[3] >> substr[4]; - if(substr[2].compare("array") == 0) isvector = true; - if(substr[3].compare("complex") == 0) iscomplex = true; - if(substr[4].compare("symmetric") == 0) sym = Symmetric; - else if (substr[4].compare("Hermitian") == 0) sym = SelfAdjoint; - - return true; -} - -template<typename SparseMatrixType> -bool loadMarket(SparseMatrixType& mat, const std::string& filename) -{ - typedef typename SparseMatrixType::Scalar Scalar; - typedef typename SparseMatrixType::StorageIndex StorageIndex; - std::ifstream input(filename.c_str(),std::ios::in); - if(!input) - return false; - - char rdbuffer[4096]; - input.rdbuf()->pubsetbuf(rdbuffer, 4096); - - const int maxBuffersize = 2048; - char buffer[maxBuffersize]; - - bool readsizes = false; - - typedef Triplet<Scalar,StorageIndex> T; - std::vector<T> elements; - - Index M(-1), N(-1), NNZ(-1); - Index count = 0; - while(input.getline(buffer, maxBuffersize)) - { - // skip comments - //NOTE An appropriate test should be done on the header to get the symmetry - if(buffer[0]=='%') - continue; - - if(!readsizes) - { - std::stringstream line(buffer); - line >> M >> N >> NNZ; - if(M > 0 && N > 0 && NNZ > 0) - { - readsizes = true; - mat.resize(M,N); - mat.reserve(NNZ); - } - } - else - { - StorageIndex i(-1), j(-1); - Scalar value; - internal::GetMarketLine(buffer, i, j, value); - - i--; - j--; - if(i>=0 && j>=0 && i<M && j<N) - { - ++count; - elements.push_back(T(i,j,value)); - } - else - std::cerr << "Invalid read: " << i << "," << j << "\n"; - } - } - - mat.setFromTriplets(elements.begin(), elements.end()); - if(count!=NNZ) - std::cerr << count << "!=" << NNZ << "\n"; - - input.close(); - return true; -} - -template<typename VectorType> -bool loadMarketVector(VectorType& vec, const std::string& filename) -{ - typedef typename VectorType::Scalar Scalar; - std::ifstream in(filename.c_str(), std::ios::in); - if(!in) - return false; - - std::string line; - int n(0), col(0); - do - { // Skip comments - std::getline(in, line); eigen_assert(in.good()); - } while (line[0] == '%'); - std::istringstream newline(line); - newline >> n >> col; - eigen_assert(n>0 && col>0); - vec.resize(n); - int i = 0; - Scalar value; - while ( std::getline(in, line) && (i < n) ){ - internal::GetVectorElt(line, value); - vec(i++) = value; - } - in.close(); - if (i!=n){ - std::cerr<< "Unable to read all elements from file " << filename << "\n"; - return false; - } - return true; -} - -template<typename SparseMatrixType> -bool saveMarket(const SparseMatrixType& mat, const std::string& filename, int sym = 0) -{ - typedef typename SparseMatrixType::Scalar Scalar; - typedef typename SparseMatrixType::RealScalar RealScalar; - std::ofstream out(filename.c_str(),std::ios::out); - if(!out) - return false; - - out.flags(std::ios_base::scientific); - out.precision(std::numeric_limits<RealScalar>::digits10 + 2); - std::string header; - internal::putMarketHeader<Scalar>(header, sym); - out << header << std::endl; - out << mat.rows() << " " << mat.cols() << " " << mat.nonZeros() << "\n"; - int count = 0; - for(int j=0; j<mat.outerSize(); ++j) - for(typename SparseMatrixType::InnerIterator it(mat,j); it; ++it) - { - ++ count; - internal::PutMatrixElt(it.value(), it.row()+1, it.col()+1, out); - } - out.close(); - return true; -} - -template<typename VectorType> -bool saveMarketVector (const VectorType& vec, const std::string& filename) -{ - typedef typename VectorType::Scalar Scalar; - typedef typename VectorType::RealScalar RealScalar; - std::ofstream out(filename.c_str(),std::ios::out); - if(!out) - return false; - - out.flags(std::ios_base::scientific); - out.precision(std::numeric_limits<RealScalar>::digits10 + 2); - if(internal::is_same<Scalar, std::complex<float> >::value || internal::is_same<Scalar, std::complex<double> >::value) - out << "%%MatrixMarket matrix array complex general\n"; - else - out << "%%MatrixMarket matrix array real general\n"; - out << vec.size() << " "<< 1 << "\n"; - for (int i=0; i < vec.size(); i++){ - internal::putVectorElt(vec(i), out); - } - out.close(); - return true; -} - -} // end namespace Eigen - -#endif // EIGEN_SPARSE_MARKET_IO_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h deleted file mode 100644 index 02916ea6..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h +++ /dev/null @@ -1,247 +0,0 @@ - -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2012 Desire NUENTSA WAKAM <desire.nuentsa_wakam@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BROWSE_MATRICES_H -#define EIGEN_BROWSE_MATRICES_H - -namespace Eigen { - -enum { - SPD = 0x100, - NonSymmetric = 0x0 -}; - -/** - * @brief Iterator to browse matrices from a specified folder - * - * This is used to load all the matrices from a folder. - * The matrices should be in Matrix Market format - * It is assumed that the matrices are named as matname.mtx - * and matname_SPD.mtx if the matrix is Symmetric and positive definite (or Hermitian) - * The right hand side vectors are loaded as well, if they exist. - * They should be named as matname_b.mtx. - * Note that the right hand side for a SPD matrix is named as matname_SPD_b.mtx - * - * Sometimes a reference solution is available. In this case, it should be named as matname_x.mtx - * - * Sample code - * \code - * - * \endcode - * - * \tparam Scalar The scalar type - */ -template <typename Scalar> -class MatrixMarketIterator -{ - typedef typename NumTraits<Scalar>::Real RealScalar; - public: - typedef Matrix<Scalar,Dynamic,1> VectorType; - typedef SparseMatrix<Scalar,ColMajor> MatrixType; - - public: - MatrixMarketIterator(const std::string &folder) - : m_sym(0), m_isvalid(false), m_matIsLoaded(false), m_hasRhs(false), m_hasrefX(false), m_folder(folder) - { - m_folder_id = opendir(folder.c_str()); - if(m_folder_id) - Getnextvalidmatrix(); - } - - ~MatrixMarketIterator() - { - if (m_folder_id) closedir(m_folder_id); - } - - inline MatrixMarketIterator& operator++() - { - m_matIsLoaded = false; - m_hasrefX = false; - m_hasRhs = false; - Getnextvalidmatrix(); - return *this; - } - inline operator bool() const { return m_isvalid;} - - /** Return the sparse matrix corresponding to the current file */ - inline MatrixType& matrix() - { - // Read the matrix - if (m_matIsLoaded) return m_mat; - - std::string matrix_file = m_folder + "/" + m_matname + ".mtx"; - if ( !loadMarket(m_mat, matrix_file)) - { - std::cerr << "Warning loadMarket failed when loading \"" << matrix_file << "\"" << std::endl; - m_matIsLoaded = false; - return m_mat; - } - m_matIsLoaded = true; - - if (m_sym != NonSymmetric) - { - // Check whether we need to restore a full matrix: - RealScalar diag_norm = m_mat.diagonal().norm(); - RealScalar lower_norm = m_mat.template triangularView<Lower>().norm(); - RealScalar upper_norm = m_mat.template triangularView<Upper>().norm(); - if(lower_norm>diag_norm && upper_norm==diag_norm) - { - // only the lower part is stored - MatrixType tmp(m_mat); - m_mat = tmp.template selfadjointView<Lower>(); - } - else if(upper_norm>diag_norm && lower_norm==diag_norm) - { - // only the upper part is stored - MatrixType tmp(m_mat); - m_mat = tmp.template selfadjointView<Upper>(); - } - } - return m_mat; - } - - /** Return the right hand side corresponding to the current matrix. - * If the rhs file is not provided, a random rhs is generated - */ - inline VectorType& rhs() - { - // Get the right hand side - if (m_hasRhs) return m_rhs; - - std::string rhs_file; - rhs_file = m_folder + "/" + m_matname + "_b.mtx"; // The pattern is matname_b.mtx - m_hasRhs = Fileexists(rhs_file); - if (m_hasRhs) - { - m_rhs.resize(m_mat.cols()); - m_hasRhs = loadMarketVector(m_rhs, rhs_file); - } - if (!m_hasRhs) - { - // Generate a random right hand side - if (!m_matIsLoaded) this->matrix(); - m_refX.resize(m_mat.cols()); - m_refX.setRandom(); - m_rhs = m_mat * m_refX; - m_hasrefX = true; - m_hasRhs = true; - } - return m_rhs; - } - - /** Return a reference solution - * If it is not provided and if the right hand side is not available - * then refX is randomly generated such that A*refX = b - * where A and b are the matrix and the rhs. - * Note that when a rhs is provided, refX is not available - */ - inline VectorType& refX() - { - // Check if a reference solution is provided - if (m_hasrefX) return m_refX; - - std::string lhs_file; - lhs_file = m_folder + "/" + m_matname + "_x.mtx"; - m_hasrefX = Fileexists(lhs_file); - if (m_hasrefX) - { - m_refX.resize(m_mat.cols()); - m_hasrefX = loadMarketVector(m_refX, lhs_file); - } - else - m_refX.resize(0); - return m_refX; - } - - inline std::string& matname() { return m_matname; } - - inline int sym() { return m_sym; } - - bool hasRhs() {return m_hasRhs; } - bool hasrefX() {return m_hasrefX; } - bool isFolderValid() { return bool(m_folder_id); } - - protected: - - inline bool Fileexists(std::string file) - { - std::ifstream file_id(file.c_str()); - if (!file_id.good() ) - { - return false; - } - else - { - file_id.close(); - return true; - } - } - - void Getnextvalidmatrix( ) - { - m_isvalid = false; - // Here, we return with the next valid matrix in the folder - while ( (m_curs_id = readdir(m_folder_id)) != NULL) { - m_isvalid = false; - std::string curfile; - curfile = m_folder + "/" + m_curs_id->d_name; - // Discard if it is a folder - if (m_curs_id->d_type == DT_DIR) continue; //FIXME This may not be available on non BSD systems -// struct stat st_buf; -// stat (curfile.c_str(), &st_buf); -// if (S_ISDIR(st_buf.st_mode)) continue; - - // Determine from the header if it is a matrix or a right hand side - bool isvector,iscomplex=false; - if(!getMarketHeader(curfile,m_sym,iscomplex,isvector)) continue; - if(isvector) continue; - if (!iscomplex) - { - if(internal::is_same<Scalar, std::complex<float> >::value || internal::is_same<Scalar, std::complex<double> >::value) - continue; - } - if (iscomplex) - { - if(internal::is_same<Scalar, float>::value || internal::is_same<Scalar, double>::value) - continue; - } - - - // Get the matrix name - std::string filename = m_curs_id->d_name; - m_matname = filename.substr(0, filename.length()-4); - - // Find if the matrix is SPD - size_t found = m_matname.find("SPD"); - if( (found!=std::string::npos) && (m_sym != NonSymmetric) ) - m_sym = SPD; - - m_isvalid = true; - break; - } - } - int m_sym; // Symmetry of the matrix - MatrixType m_mat; // Current matrix - VectorType m_rhs; // Current vector - VectorType m_refX; // The reference solution, if exists - std::string m_matname; // Matrix Name - bool m_isvalid; - bool m_matIsLoaded; // Determine if the matrix has already been loaded from the file - bool m_hasRhs; // The right hand side exists - bool m_hasrefX; // A reference solution is provided - std::string m_folder; - DIR * m_folder_id; - struct dirent *m_curs_id; - -}; - -} // end namespace Eigen - -#endif diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/RandomSetter.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/RandomSetter.h deleted file mode 100644 index 7542cf76..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SparseExtra/RandomSetter.h +++ /dev/null @@ -1,327 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_RANDOMSETTER_H -#define EIGEN_RANDOMSETTER_H - -namespace Eigen { - -/** Represents a std::map - * - * \see RandomSetter - */ -template<typename Scalar> struct StdMapTraits -{ - typedef int KeyType; - typedef std::map<KeyType,Scalar> Type; - enum { - IsSorted = 1 - }; - - static void setInvalidKey(Type&, const KeyType&) {} -}; - -#ifdef EIGEN_UNORDERED_MAP_SUPPORT -/** Represents a std::unordered_map - * - * To use it you need to both define EIGEN_UNORDERED_MAP_SUPPORT and include the unordered_map header file - * yourself making sure that unordered_map is defined in the std namespace. - * - * For instance, with current version of gcc you can either enable C++0x standard (-std=c++0x) or do: - * \code - * #include <tr1/unordered_map> - * #define EIGEN_UNORDERED_MAP_SUPPORT - * namespace std { - * using std::tr1::unordered_map; - * } - * \endcode - * - * \see RandomSetter - */ -template<typename Scalar> struct StdUnorderedMapTraits -{ - typedef int KeyType; - typedef std::unordered_map<KeyType,Scalar> Type; - enum { - IsSorted = 0 - }; - - static void setInvalidKey(Type&, const KeyType&) {} -}; -#endif // EIGEN_UNORDERED_MAP_SUPPORT - -#ifdef _DENSE_HASH_MAP_H_ -/** Represents a google::dense_hash_map - * - * \see RandomSetter - */ -template<typename Scalar> struct GoogleDenseHashMapTraits -{ - typedef int KeyType; - typedef google::dense_hash_map<KeyType,Scalar> Type; - enum { - IsSorted = 0 - }; - - static void setInvalidKey(Type& map, const KeyType& k) - { map.set_empty_key(k); } -}; -#endif - -#ifdef _SPARSE_HASH_MAP_H_ -/** Represents a google::sparse_hash_map - * - * \see RandomSetter - */ -template<typename Scalar> struct GoogleSparseHashMapTraits -{ - typedef int KeyType; - typedef google::sparse_hash_map<KeyType,Scalar> Type; - enum { - IsSorted = 0 - }; - - static void setInvalidKey(Type&, const KeyType&) {} -}; -#endif - -/** \class RandomSetter - * - * \brief The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access - * - * \tparam SparseMatrixType the type of the sparse matrix we are updating - * \tparam MapTraits a traits class representing the map implementation used for the temporary sparse storage. - * Its default value depends on the system. - * \tparam OuterPacketBits defines the number of rows (or columns) manage by a single map object - * as a power of two exponent. - * - * This class temporarily represents a sparse matrix object using a generic map implementation allowing for - * efficient random access. The conversion from the compressed representation to a hash_map object is performed - * in the RandomSetter constructor, while the sparse matrix is updated back at destruction time. This strategy - * suggest the use of nested blocks as in this example: - * - * \code - * SparseMatrix<double> m(rows,cols); - * { - * RandomSetter<SparseMatrix<double> > w(m); - * // don't use m but w instead with read/write random access to the coefficients: - * for(;;) - * w(rand(),rand()) = rand; - * } - * // when w is deleted, the data are copied back to m - * // and m is ready to use. - * \endcode - * - * Since hash_map objects are not fully sorted, representing a full matrix as a single hash_map would - * involve a big and costly sort to update the compressed matrix back. To overcome this issue, a RandomSetter - * use multiple hash_map, each representing 2^OuterPacketBits columns or rows according to the storage order. - * To reach optimal performance, this value should be adjusted according to the average number of nonzeros - * per rows/columns. - * - * The possible values for the template parameter MapTraits are: - * - \b StdMapTraits: corresponds to std::map. (does not perform very well) - * - \b GnuHashMapTraits: corresponds to __gnu_cxx::hash_map (available only with GCC) - * - \b GoogleDenseHashMapTraits: corresponds to google::dense_hash_map (best efficiency, reasonable memory consumption) - * - \b GoogleSparseHashMapTraits: corresponds to google::sparse_hash_map (best memory consumption, relatively good performance) - * - * The default map implementation depends on the availability, and the preferred order is: - * GoogleSparseHashMapTraits, GnuHashMapTraits, and finally StdMapTraits. - * - * For performance and memory consumption reasons it is highly recommended to use one of - * the Google's hash_map implementation. To enable the support for them, you have two options: - * - \#include <google/dense_hash_map> yourself \b before Eigen/Sparse header - * - define EIGEN_GOOGLEHASH_SUPPORT - * In the later case the inclusion of <google/dense_hash_map> is made for you. - * - * \see http://code.google.com/p/google-sparsehash/ - */ -template<typename SparseMatrixType, - template <typename T> class MapTraits = -#if defined _DENSE_HASH_MAP_H_ - GoogleDenseHashMapTraits -#elif defined _HASH_MAP - GnuHashMapTraits -#else - StdMapTraits -#endif - ,int OuterPacketBits = 6> -class RandomSetter -{ - typedef typename SparseMatrixType::Scalar Scalar; - typedef typename SparseMatrixType::StorageIndex StorageIndex; - - struct ScalarWrapper - { - ScalarWrapper() : value(0) {} - Scalar value; - }; - typedef typename MapTraits<ScalarWrapper>::KeyType KeyType; - typedef typename MapTraits<ScalarWrapper>::Type HashMapType; - static const int OuterPacketMask = (1 << OuterPacketBits) - 1; - enum { - SwapStorage = 1 - MapTraits<ScalarWrapper>::IsSorted, - TargetRowMajor = (SparseMatrixType::Flags & RowMajorBit) ? 1 : 0, - SetterRowMajor = SwapStorage ? 1-TargetRowMajor : TargetRowMajor - }; - - public: - - /** Constructs a random setter object from the sparse matrix \a target - * - * Note that the initial value of \a target are imported. If you want to re-set - * a sparse matrix from scratch, then you must set it to zero first using the - * setZero() function. - */ - inline RandomSetter(SparseMatrixType& target) - : mp_target(&target) - { - const Index outerSize = SwapStorage ? target.innerSize() : target.outerSize(); - const Index innerSize = SwapStorage ? target.outerSize() : target.innerSize(); - m_outerPackets = outerSize >> OuterPacketBits; - if (outerSize&OuterPacketMask) - m_outerPackets += 1; - m_hashmaps = new HashMapType[m_outerPackets]; - // compute number of bits needed to store inner indices - Index aux = innerSize - 1; - m_keyBitsOffset = 0; - while (aux) - { - ++m_keyBitsOffset; - aux = aux >> 1; - } - KeyType ik = (1<<(OuterPacketBits+m_keyBitsOffset)); - for (Index k=0; k<m_outerPackets; ++k) - MapTraits<ScalarWrapper>::setInvalidKey(m_hashmaps[k],ik); - - // insert current coeffs - for (Index j=0; j<mp_target->outerSize(); ++j) - for (typename SparseMatrixType::InnerIterator it(*mp_target,j); it; ++it) - (*this)(TargetRowMajor?j:it.index(), TargetRowMajor?it.index():j) = it.value(); - } - - /** Destructor updating back the sparse matrix target */ - ~RandomSetter() - { - KeyType keyBitsMask = (1<<m_keyBitsOffset)-1; - if (!SwapStorage) // also means the map is sorted - { - mp_target->setZero(); - mp_target->makeCompressed(); - mp_target->reserve(nonZeros()); - Index prevOuter = -1; - for (Index k=0; k<m_outerPackets; ++k) - { - const Index outerOffset = (1<<OuterPacketBits) * k; - typename HashMapType::iterator end = m_hashmaps[k].end(); - for (typename HashMapType::iterator it = m_hashmaps[k].begin(); it!=end; ++it) - { - const Index outer = (it->first >> m_keyBitsOffset) + outerOffset; - const Index inner = it->first & keyBitsMask; - if (prevOuter!=outer) - { - for (Index j=prevOuter+1;j<=outer;++j) - mp_target->startVec(j); - prevOuter = outer; - } - mp_target->insertBackByOuterInner(outer, inner) = it->second.value; - } - } - mp_target->finalize(); - } - else - { - VectorXi positions(mp_target->outerSize()); - positions.setZero(); - // pass 1 - for (Index k=0; k<m_outerPackets; ++k) - { - typename HashMapType::iterator end = m_hashmaps[k].end(); - for (typename HashMapType::iterator it = m_hashmaps[k].begin(); it!=end; ++it) - { - const Index outer = it->first & keyBitsMask; - ++positions[outer]; - } - } - // prefix sum - StorageIndex count = 0; - for (Index j=0; j<mp_target->outerSize(); ++j) - { - StorageIndex tmp = positions[j]; - mp_target->outerIndexPtr()[j] = count; - positions[j] = count; - count += tmp; - } - mp_target->makeCompressed(); - mp_target->outerIndexPtr()[mp_target->outerSize()] = count; - mp_target->resizeNonZeros(count); - // pass 2 - for (Index k=0; k<m_outerPackets; ++k) - { - const Index outerOffset = (1<<OuterPacketBits) * k; - typename HashMapType::iterator end = m_hashmaps[k].end(); - for (typename HashMapType::iterator it = m_hashmaps[k].begin(); it!=end; ++it) - { - const Index inner = (it->first >> m_keyBitsOffset) + outerOffset; - const Index outer = it->first & keyBitsMask; - // sorted insertion - // Note that we have to deal with at most 2^OuterPacketBits unsorted coefficients, - // moreover those 2^OuterPacketBits coeffs are likely to be sparse, an so only a - // small fraction of them have to be sorted, whence the following simple procedure: - Index posStart = mp_target->outerIndexPtr()[outer]; - Index i = (positions[outer]++) - 1; - while ( (i >= posStart) && (mp_target->innerIndexPtr()[i] > inner) ) - { - mp_target->valuePtr()[i+1] = mp_target->valuePtr()[i]; - mp_target->innerIndexPtr()[i+1] = mp_target->innerIndexPtr()[i]; - --i; - } - mp_target->innerIndexPtr()[i+1] = internal::convert_index<StorageIndex>(inner); - mp_target->valuePtr()[i+1] = it->second.value; - } - } - } - delete[] m_hashmaps; - } - - /** \returns a reference to the coefficient at given coordinates \a row, \a col */ - Scalar& operator() (Index row, Index col) - { - const Index outer = SetterRowMajor ? row : col; - const Index inner = SetterRowMajor ? col : row; - const Index outerMajor = outer >> OuterPacketBits; // index of the packet/map - const Index outerMinor = outer & OuterPacketMask; // index of the inner vector in the packet - const KeyType key = internal::convert_index<KeyType>((outerMinor<<m_keyBitsOffset) | inner); - return m_hashmaps[outerMajor][key].value; - } - - /** \returns the number of non zero coefficients - * - * \note According to the underlying map/hash_map implementation, - * this function might be quite expensive. - */ - Index nonZeros() const - { - Index nz = 0; - for (Index k=0; k<m_outerPackets; ++k) - nz += static_cast<Index>(m_hashmaps[k].size()); - return nz; - } - - - protected: - - HashMapType* m_hashmaps; - SparseMatrixType* mp_target; - Index m_outerPackets; - unsigned char m_keyBitsOffset; -}; - -} // end namespace Eigen - -#endif // EIGEN_RANDOMSETTER_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsArrayAPI.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsArrayAPI.h deleted file mode 100644 index 41d2bf61..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsArrayAPI.h +++ /dev/null @@ -1,286 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_BESSELFUNCTIONS_ARRAYAPI_H -#define EIGEN_BESSELFUNCTIONS_ARRAYAPI_H - -namespace Eigen { - -/** \returns an expression of the coefficient-wise i0(\a x) to the given - * arrays. - * - * It returns the modified Bessel function of the first kind of order zero. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of i0(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_i0() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_i0_op<typename Derived::Scalar>, const Derived> -bessel_i0(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_i0_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise i0e(\a x) to the given - * arrays. - * - * It returns the exponentially scaled modified Bessel - * function of the first kind of order zero. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of i0e(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_i0e() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_i0e_op<typename Derived::Scalar>, const Derived> -bessel_i0e(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_i0e_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise i1(\a x) to the given - * arrays. - * - * It returns the modified Bessel function of the first kind of order one. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of i1(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_i1() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_i1_op<typename Derived::Scalar>, const Derived> -bessel_i1(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_i1_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise i1e(\a x) to the given - * arrays. - * - * It returns the exponentially scaled modified Bessel - * function of the first kind of order one. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of i1e(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_i1e() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_i1e_op<typename Derived::Scalar>, const Derived> -bessel_i1e(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_i1e_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise k0(\a x) to the given - * arrays. - * - * It returns the modified Bessel function of the second kind of order zero. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of k0(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_k0() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_k0_op<typename Derived::Scalar>, const Derived> -bessel_k0(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_k0_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise k0e(\a x) to the given - * arrays. - * - * It returns the exponentially scaled modified Bessel - * function of the second kind of order zero. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of k0e(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_k0e() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_k0e_op<typename Derived::Scalar>, const Derived> -bessel_k0e(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_k0e_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise k1(\a x) to the given - * arrays. - * - * It returns the modified Bessel function of the second kind of order one. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of k1(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_k1() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_k1_op<typename Derived::Scalar>, const Derived> -bessel_k1(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_k1_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise k1e(\a x) to the given - * arrays. - * - * It returns the exponentially scaled modified Bessel - * function of the second kind of order one. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of k1e(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_k1e() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_k1e_op<typename Derived::Scalar>, const Derived> -bessel_k1e(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_k1e_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise j0(\a x) to the given - * arrays. - * - * It returns the Bessel function of the first kind of order zero. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of j0(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_j0() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_j0_op<typename Derived::Scalar>, const Derived> -bessel_j0(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_j0_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise y0(\a x) to the given - * arrays. - * - * It returns the Bessel function of the second kind of order zero. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of y0(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_y0() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_y0_op<typename Derived::Scalar>, const Derived> -bessel_y0(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_y0_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise j1(\a x) to the given - * arrays. - * - * It returns the modified Bessel function of the first kind of order one. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of j1(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_j1() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_j1_op<typename Derived::Scalar>, const Derived> -bessel_j1(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_j1_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -/** \returns an expression of the coefficient-wise y1(\a x) to the given - * arrays. - * - * It returns the Bessel function of the second kind of order one. - * - * \param x is the argument - * - * \note This function supports only float and double scalar types. To support - * other scalar types, the user has to provide implementations of y1(T) for - * any scalar type T to be supported. - * - * \sa ArrayBase::bessel_y1() - */ -template <typename Derived> -EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_y1_op<typename Derived::Scalar>, const Derived> -bessel_y1(const Eigen::ArrayBase<Derived>& x) { - return Eigen::CwiseUnaryOp< - Eigen::internal::scalar_bessel_y1_op<typename Derived::Scalar>, - const Derived>(x.derived()); -} - -} // end namespace Eigen - -#endif // EIGEN_BESSELFUNCTIONS_ARRAYAPI_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsFunctors.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsFunctors.h deleted file mode 100644 index 8606a9f8..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsFunctors.h +++ /dev/null @@ -1,357 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com> -// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BESSELFUNCTIONS_FUNCTORS_H -#define EIGEN_BESSELFUNCTIONS_FUNCTORS_H - -namespace Eigen { - -namespace internal { - -/** \internal - * \brief Template functor to compute the modified Bessel function of the first - * kind of order zero. - * \sa class CwiseUnaryOp, Cwise::bessel_i0() - */ -template <typename Scalar> -struct scalar_bessel_i0_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_i0_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_i0; - return bessel_i0(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_i0(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_i0_op<Scalar> > { - enum { - // On average, a Chebyshev polynomial of order N=20 is computed. - // The cost is N multiplications and 2N additions. We also add - // the cost of an additional exp over i0e. - Cost = 28 * NumTraits<Scalar>::MulCost + 48 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the exponentially scaled modified Bessel - * function of the first kind of order zero - * \sa class CwiseUnaryOp, Cwise::bessel_i0e() - */ -template <typename Scalar> -struct scalar_bessel_i0e_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_i0e_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_i0e; - return bessel_i0e(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_i0e(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_i0e_op<Scalar> > { - enum { - // On average, a Chebyshev polynomial of order N=20 is computed. - // The cost is N multiplications and 2N additions. - Cost = 20 * NumTraits<Scalar>::MulCost + 40 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the modified Bessel function of the first - * kind of order one - * \sa class CwiseUnaryOp, Cwise::bessel_i1() - */ -template <typename Scalar> -struct scalar_bessel_i1_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_i1_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_i1; - return bessel_i1(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_i1(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_i1_op<Scalar> > { - enum { - // On average, a Chebyshev polynomial of order N=20 is computed. - // The cost is N multiplications and 2N additions. We also add - // the cost of an additional exp over i1e. - Cost = 28 * NumTraits<Scalar>::MulCost + 48 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the exponentially scaled modified Bessel - * function of the first kind of order zero - * \sa class CwiseUnaryOp, Cwise::bessel_i1e() - */ -template <typename Scalar> -struct scalar_bessel_i1e_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_i1e_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_i1e; - return bessel_i1e(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_i1e(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_i1e_op<Scalar> > { - enum { - // On average, a Chebyshev polynomial of order N=20 is computed. - // The cost is N multiplications and 2N additions. - Cost = 20 * NumTraits<Scalar>::MulCost + 40 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the Bessel function of the second kind of - * order zero - * \sa class CwiseUnaryOp, Cwise::bessel_j0() - */ -template <typename Scalar> -struct scalar_bessel_j0_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_j0_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_j0; - return bessel_j0(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_j0(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_j0_op<Scalar> > { - enum { - // 6 polynomial of order ~N=8 is computed. - // The cost is N multiplications and N additions each, along with a - // sine, cosine and rsqrt cost. - Cost = 63 * NumTraits<Scalar>::MulCost + 48 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the Bessel function of the second kind of - * order zero - * \sa class CwiseUnaryOp, Cwise::bessel_y0() - */ -template <typename Scalar> -struct scalar_bessel_y0_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_y0_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_y0; - return bessel_y0(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_y0(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_y0_op<Scalar> > { - enum { - // 6 polynomial of order ~N=8 is computed. - // The cost is N multiplications and N additions each, along with a - // sine, cosine, rsqrt and j0 cost. - Cost = 126 * NumTraits<Scalar>::MulCost + 96 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the Bessel function of the first kind of - * order one - * \sa class CwiseUnaryOp, Cwise::bessel_j1() - */ -template <typename Scalar> -struct scalar_bessel_j1_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_j1_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_j1; - return bessel_j1(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_j1(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_j1_op<Scalar> > { - enum { - // 6 polynomial of order ~N=8 is computed. - // The cost is N multiplications and N additions each, along with a - // sine, cosine and rsqrt cost. - Cost = 63 * NumTraits<Scalar>::MulCost + 48 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the Bessel function of the second kind of - * order one - * \sa class CwiseUnaryOp, Cwise::bessel_j1e() - */ -template <typename Scalar> -struct scalar_bessel_y1_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_y1_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_y1; - return bessel_y1(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_y1(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_y1_op<Scalar> > { - enum { - // 6 polynomial of order ~N=8 is computed. - // The cost is N multiplications and N additions each, along with a - // sine, cosine, rsqrt and j1 cost. - Cost = 126 * NumTraits<Scalar>::MulCost + 96 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the modified Bessel function of the second - * kind of order zero - * \sa class CwiseUnaryOp, Cwise::bessel_k0() - */ -template <typename Scalar> -struct scalar_bessel_k0_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_k0_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_k0; - return bessel_k0(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_k0(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_k0_op<Scalar> > { - enum { - // On average, a Chebyshev polynomial of order N=10 is computed. - // The cost is N multiplications and 2N additions. In addition we compute - // i0, a log, exp and prsqrt and sin and cos. - Cost = 68 * NumTraits<Scalar>::MulCost + 88 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the exponentially scaled modified Bessel - * function of the second kind of order zero - * \sa class CwiseUnaryOp, Cwise::bessel_k0e() - */ -template <typename Scalar> -struct scalar_bessel_k0e_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_k0e_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_k0e; - return bessel_k0e(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_k0e(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_k0e_op<Scalar> > { - enum { - // On average, a Chebyshev polynomial of order N=10 is computed. - // The cost is N multiplications and 2N additions. In addition we compute - // i0, a log, exp and prsqrt and sin and cos. - Cost = 68 * NumTraits<Scalar>::MulCost + 88 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the modified Bessel function of the - * second kind of order one - * \sa class CwiseUnaryOp, Cwise::bessel_k1() - */ -template <typename Scalar> -struct scalar_bessel_k1_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_k1_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_k1; - return bessel_k1(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_k1(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_k1_op<Scalar> > { - enum { - // On average, a Chebyshev polynomial of order N=10 is computed. - // The cost is N multiplications and 2N additions. In addition we compute - // i1, a log, exp and prsqrt and sin and cos. - Cost = 68 * NumTraits<Scalar>::MulCost + 88 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - -/** \internal - * \brief Template functor to compute the exponentially scaled modified Bessel - * function of the second kind of order one - * \sa class CwiseUnaryOp, Cwise::bessel_k1e() - */ -template <typename Scalar> -struct scalar_bessel_k1e_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_k1e_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const { - using numext::bessel_k1e; - return bessel_k1e(x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return internal::pbessel_k1e(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_bessel_k1e_op<Scalar> > { - enum { - // On average, a Chebyshev polynomial of order N=10 is computed. - // The cost is N multiplications and 2N additions. In addition we compute - // i1, a log, exp and prsqrt and sin and cos. - Cost = 68 * NumTraits<Scalar>::MulCost + 88 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBessel - }; -}; - - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_BESSELFUNCTIONS_FUNCTORS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsHalf.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsHalf.h deleted file mode 100644 index 8930d1a3..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsHalf.h +++ /dev/null @@ -1,66 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BESSELFUNCTIONS_HALF_H -#define EIGEN_BESSELFUNCTIONS_HALF_H - -namespace Eigen { -namespace numext { - -#if EIGEN_HAS_C99_MATH -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_i0(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_i0(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_i0e(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_i0e(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_i1(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_i1(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_i1e(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_i1e(static_cast<float>(x))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_j0(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_j0(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_j1(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_j1(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_y0(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_y0(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_y1(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_y1(static_cast<float>(x))); -} -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_k0(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_k0(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_k0e(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_k0e(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_k1(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_k1(static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bessel_k1e(const Eigen::half& x) { - return Eigen::half(Eigen::numext::bessel_k1e(static_cast<float>(x))); -} -#endif - -} // end namespace numext -} // end namespace Eigen - -#endif // EIGEN_BESSELFUNCTIONS_HALF_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsImpl.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsImpl.h deleted file mode 100644 index a9b6ad94..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsImpl.h +++ /dev/null @@ -1,1959 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Eugene Brevdo <ebrevdo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BESSEL_FUNCTIONS_H -#define EIGEN_BESSEL_FUNCTIONS_H - -namespace Eigen { -namespace internal { - -// Parts of this code are based on the Cephes Math Library. -// -// Cephes Math Library Release 2.8: June, 2000 -// Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier -// -// Permission has been kindly provided by the original author -// to incorporate the Cephes software into the Eigen codebase: -// -// From: Stephen Moshier -// To: Eugene Brevdo -// Subject: Re: Permission to wrap several cephes functions in Eigen -// -// Hello Eugene, -// -// Thank you for writing. -// -// If your licensing is similar to BSD, the formal way that has been -// handled is simply to add a statement to the effect that you are incorporating -// the Cephes software by permission of the author. -// -// Good luck with your project, -// Steve - - -/**************************************************************************** - * Implementation of Bessel function, based on Cephes * - ****************************************************************************/ - -template <typename Scalar> -struct bessel_i0e_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_i0e { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_i0e<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* i0ef.c - * - * Modified Bessel function of order zero, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * float x, y, i0ef(); - * - * y = i0ef( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of order zero of the argument. - * - * The function is defined as i0e(x) = exp(-|x|) j0( ix ). - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0,30 100000 3.7e-7 7.0e-8 - * See i0f(). - * - */ - - const float A[] = {-1.30002500998624804212E-8f, 6.04699502254191894932E-8f, - -2.67079385394061173391E-7f, 1.11738753912010371815E-6f, - -4.41673835845875056359E-6f, 1.64484480707288970893E-5f, - -5.75419501008210370398E-5f, 1.88502885095841655729E-4f, - -5.76375574538582365885E-4f, 1.63947561694133579842E-3f, - -4.32430999505057594430E-3f, 1.05464603945949983183E-2f, - -2.37374148058994688156E-2f, 4.93052842396707084878E-2f, - -9.49010970480476444210E-2f, 1.71620901522208775349E-1f, - -3.04682672343198398683E-1f, 6.76795274409476084995E-1f}; - - const float B[] = {3.39623202570838634515E-9f, 2.26666899049817806459E-8f, - 2.04891858946906374183E-7f, 2.89137052083475648297E-6f, - 6.88975834691682398426E-5f, 3.36911647825569408990E-3f, - 8.04490411014108831608E-1f}; - T y = pabs(x); - T y_le_eight = internal::pchebevl<T, 18>::run( - pmadd(pset1<T>(0.5f), y, pset1<T>(-2.0f)), A); - T y_gt_eight = pmul( - internal::pchebevl<T, 7>::run( - psub(pdiv(pset1<T>(32.0f), y), pset1<T>(2.0f)), B), - prsqrt(y)); - // TODO: Perhaps instead check whether all packet elements are in - // [-8, 8] and evaluate a branch based off of that. It's possible - // in practice most elements are in this region. - return pselect(pcmp_le(y, pset1<T>(8.0f)), y_le_eight, y_gt_eight); - } -}; - -template <typename T> -struct generic_i0e<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* i0e.c - * - * Modified Bessel function of order zero, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * double x, y, i0e(); - * - * y = i0e( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of order zero of the argument. - * - * The function is defined as i0e(x) = exp(-|x|) j0( ix ). - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0,30 30000 5.4e-16 1.2e-16 - * See i0(). - * - */ - - const double A[] = {-4.41534164647933937950E-18, 3.33079451882223809783E-17, - -2.43127984654795469359E-16, 1.71539128555513303061E-15, - -1.16853328779934516808E-14, 7.67618549860493561688E-14, - -4.85644678311192946090E-13, 2.95505266312963983461E-12, - -1.72682629144155570723E-11, 9.67580903537323691224E-11, - -5.18979560163526290666E-10, 2.65982372468238665035E-9, - -1.30002500998624804212E-8, 6.04699502254191894932E-8, - -2.67079385394061173391E-7, 1.11738753912010371815E-6, - -4.41673835845875056359E-6, 1.64484480707288970893E-5, - -5.75419501008210370398E-5, 1.88502885095841655729E-4, - -5.76375574538582365885E-4, 1.63947561694133579842E-3, - -4.32430999505057594430E-3, 1.05464603945949983183E-2, - -2.37374148058994688156E-2, 4.93052842396707084878E-2, - -9.49010970480476444210E-2, 1.71620901522208775349E-1, - -3.04682672343198398683E-1, 6.76795274409476084995E-1}; - const double B[] = { - -7.23318048787475395456E-18, -4.83050448594418207126E-18, - 4.46562142029675999901E-17, 3.46122286769746109310E-17, - -2.82762398051658348494E-16, -3.42548561967721913462E-16, - 1.77256013305652638360E-15, 3.81168066935262242075E-15, - -9.55484669882830764870E-15, -4.15056934728722208663E-14, - 1.54008621752140982691E-14, 3.85277838274214270114E-13, - 7.18012445138366623367E-13, -1.79417853150680611778E-12, - -1.32158118404477131188E-11, -3.14991652796324136454E-11, - 1.18891471078464383424E-11, 4.94060238822496958910E-10, - 3.39623202570838634515E-9, 2.26666899049817806459E-8, - 2.04891858946906374183E-7, 2.89137052083475648297E-6, - 6.88975834691682398426E-5, 3.36911647825569408990E-3, - 8.04490411014108831608E-1}; - T y = pabs(x); - T y_le_eight = internal::pchebevl<T, 30>::run( - pmadd(pset1<T>(0.5), y, pset1<T>(-2.0)), A); - T y_gt_eight = pmul( - internal::pchebevl<T, 25>::run( - psub(pdiv(pset1<T>(32.0), y), pset1<T>(2.0)), B), - prsqrt(y)); - // TODO: Perhaps instead check whether all packet elements are in - // [-8, 8] and evaluate a branch based off of that. It's possible - // in practice most elements are in this region. - return pselect(pcmp_le(y, pset1<T>(8.0)), y_le_eight, y_gt_eight); - } -}; - -template <typename Scalar> -struct bessel_i0e_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_i0e<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_i0_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_i0 { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - return pmul( - pexp(pabs(x)), - generic_i0e<T, ScalarType>::run(x)); - } -}; - -template <typename Scalar> -struct bessel_i0_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_i0<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_i1e_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_i1e { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_i1e<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* i1ef.c - * - * Modified Bessel function of order one, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * float x, y, i1ef(); - * - * y = i1ef( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of order one of the argument. - * - * The function is defined as i1(x) = -i exp(-|x|) j1( ix ). - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 1.5e-6 1.5e-7 - * See i1(). - * - */ - const float A[] = {9.38153738649577178388E-9f, -4.44505912879632808065E-8f, - 2.00329475355213526229E-7f, -8.56872026469545474066E-7f, - 3.47025130813767847674E-6f, -1.32731636560394358279E-5f, - 4.78156510755005422638E-5f, -1.61760815825896745588E-4f, - 5.12285956168575772895E-4f, -1.51357245063125314899E-3f, - 4.15642294431288815669E-3f, -1.05640848946261981558E-2f, - 2.47264490306265168283E-2f, -5.29459812080949914269E-2f, - 1.02643658689847095384E-1f, -1.76416518357834055153E-1f, - 2.52587186443633654823E-1f}; - - const float B[] = {-3.83538038596423702205E-9f, -2.63146884688951950684E-8f, - -2.51223623787020892529E-7f, -3.88256480887769039346E-6f, - -1.10588938762623716291E-4f, -9.76109749136146840777E-3f, - 7.78576235018280120474E-1f}; - - - T y = pabs(x); - T y_le_eight = pmul(y, internal::pchebevl<T, 17>::run( - pmadd(pset1<T>(0.5f), y, pset1<T>(-2.0f)), A)); - T y_gt_eight = pmul( - internal::pchebevl<T, 7>::run( - psub(pdiv(pset1<T>(32.0f), y), - pset1<T>(2.0f)), B), - prsqrt(y)); - // TODO: Perhaps instead check whether all packet elements are in - // [-8, 8] and evaluate a branch based off of that. It's possible - // in practice most elements are in this region. - y = pselect(pcmp_le(y, pset1<T>(8.0f)), y_le_eight, y_gt_eight); - return pselect(pcmp_lt(x, pset1<T>(0.0f)), pnegate(y), y); - } -}; - -template <typename T> -struct generic_i1e<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* i1e.c - * - * Modified Bessel function of order one, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * double x, y, i1e(); - * - * y = i1e( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of order one of the argument. - * - * The function is defined as i1(x) = -i exp(-|x|) j1( ix ). - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 2.0e-15 2.0e-16 - * See i1(). - * - */ - const double A[] = {2.77791411276104639959E-18, -2.11142121435816608115E-17, - 1.55363195773620046921E-16, -1.10559694773538630805E-15, - 7.60068429473540693410E-15, -5.04218550472791168711E-14, - 3.22379336594557470981E-13, -1.98397439776494371520E-12, - 1.17361862988909016308E-11, -6.66348972350202774223E-11, - 3.62559028155211703701E-10, -1.88724975172282928790E-9, - 9.38153738649577178388E-9, -4.44505912879632808065E-8, - 2.00329475355213526229E-7, -8.56872026469545474066E-7, - 3.47025130813767847674E-6, -1.32731636560394358279E-5, - 4.78156510755005422638E-5, -1.61760815825896745588E-4, - 5.12285956168575772895E-4, -1.51357245063125314899E-3, - 4.15642294431288815669E-3, -1.05640848946261981558E-2, - 2.47264490306265168283E-2, -5.29459812080949914269E-2, - 1.02643658689847095384E-1, -1.76416518357834055153E-1, - 2.52587186443633654823E-1}; - const double B[] = { - 7.51729631084210481353E-18, 4.41434832307170791151E-18, - -4.65030536848935832153E-17, -3.20952592199342395980E-17, - 2.96262899764595013876E-16, 3.30820231092092828324E-16, - -1.88035477551078244854E-15, -3.81440307243700780478E-15, - 1.04202769841288027642E-14, 4.27244001671195135429E-14, - -2.10154184277266431302E-14, -4.08355111109219731823E-13, - -7.19855177624590851209E-13, 2.03562854414708950722E-12, - 1.41258074366137813316E-11, 3.25260358301548823856E-11, - -1.89749581235054123450E-11, -5.58974346219658380687E-10, - -3.83538038596423702205E-9, -2.63146884688951950684E-8, - -2.51223623787020892529E-7, -3.88256480887769039346E-6, - -1.10588938762623716291E-4, -9.76109749136146840777E-3, - 7.78576235018280120474E-1}; - T y = pabs(x); - T y_le_eight = pmul(y, internal::pchebevl<T, 29>::run( - pmadd(pset1<T>(0.5), y, pset1<T>(-2.0)), A)); - T y_gt_eight = pmul( - internal::pchebevl<T, 25>::run( - psub(pdiv(pset1<T>(32.0), y), - pset1<T>(2.0)), B), - prsqrt(y)); - // TODO: Perhaps instead check whether all packet elements are in - // [-8, 8] and evaluate a branch based off of that. It's possible - // in practice most elements are in this region. - y = pselect(pcmp_le(y, pset1<T>(8.0)), y_le_eight, y_gt_eight); - return pselect(pcmp_lt(x, pset1<T>(0.0)), pnegate(y), y); - } -}; - -template <typename Scalar> -struct bessel_i1e_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_i1e<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_i1_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_i1 { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - return pmul( - pexp(pabs(x)), - generic_i1e<T, ScalarType>::run(x)); - } -}; - -template <typename Scalar> -struct bessel_i1_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_i1<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_k0e_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_k0e { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_k0e<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* k0ef.c - * Modified Bessel function, third kind, order zero, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * float x, y, k0ef(); - * - * y = k0ef( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of the third kind of order zero of the argument. - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 8.1e-7 7.8e-8 - * See k0(). - * - */ - - const float A[] = {1.90451637722020886025E-9f, 2.53479107902614945675E-7f, - 2.28621210311945178607E-5f, 1.26461541144692592338E-3f, - 3.59799365153615016266E-2f, 3.44289899924628486886E-1f, - -5.35327393233902768720E-1f}; - - const float B[] = {-1.69753450938905987466E-9f, 8.57403401741422608519E-9f, - -4.66048989768794782956E-8f, 2.76681363944501510342E-7f, - -1.83175552271911948767E-6f, 1.39498137188764993662E-5f, - -1.28495495816278026384E-4f, 1.56988388573005337491E-3f, - -3.14481013119645005427E-2f, 2.44030308206595545468E0f}; - const T MAXNUM = pset1<T>(NumTraits<float>::infinity()); - const T two = pset1<T>(2.0); - T x_le_two = internal::pchebevl<T, 7>::run( - pmadd(x, x, pset1<T>(-2.0)), A); - x_le_two = pmadd( - generic_i0<T, float>::run(x), pnegate( - plog(pmul(pset1<T>(0.5), x))), x_le_two); - x_le_two = pmul(pexp(x), x_le_two); - T x_gt_two = pmul( - internal::pchebevl<T, 10>::run( - psub(pdiv(pset1<T>(8.0), x), two), B), - prsqrt(x)); - return pselect( - pcmp_le(x, pset1<T>(0.0)), - MAXNUM, - pselect(pcmp_le(x, two), x_le_two, x_gt_two)); - } -}; - -template <typename T> -struct generic_k0e<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* k0e.c - * Modified Bessel function, third kind, order zero, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * double x, y, k0e(); - * - * y = k0e( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of the third kind of order zero of the argument. - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 1.4e-15 1.4e-16 - * See k0(). - * - */ - - const double A[] = { - 1.37446543561352307156E-16, - 4.25981614279661018399E-14, - 1.03496952576338420167E-11, - 1.90451637722020886025E-9, - 2.53479107902614945675E-7, - 2.28621210311945178607E-5, - 1.26461541144692592338E-3, - 3.59799365153615016266E-2, - 3.44289899924628486886E-1, - -5.35327393233902768720E-1}; - const double B[] = { - 5.30043377268626276149E-18, -1.64758043015242134646E-17, - 5.21039150503902756861E-17, -1.67823109680541210385E-16, - 5.51205597852431940784E-16, -1.84859337734377901440E-15, - 6.34007647740507060557E-15, -2.22751332699166985548E-14, - 8.03289077536357521100E-14, -2.98009692317273043925E-13, - 1.14034058820847496303E-12, -4.51459788337394416547E-12, - 1.85594911495471785253E-11, -7.95748924447710747776E-11, - 3.57739728140030116597E-10, -1.69753450938905987466E-9, - 8.57403401741422608519E-9, -4.66048989768794782956E-8, - 2.76681363944501510342E-7, -1.83175552271911948767E-6, - 1.39498137188764993662E-5, -1.28495495816278026384E-4, - 1.56988388573005337491E-3, -3.14481013119645005427E-2, - 2.44030308206595545468E0 - }; - const T MAXNUM = pset1<T>(NumTraits<double>::infinity()); - const T two = pset1<T>(2.0); - T x_le_two = internal::pchebevl<T, 10>::run( - pmadd(x, x, pset1<T>(-2.0)), A); - x_le_two = pmadd( - generic_i0<T, double>::run(x), pmul( - pset1<T>(-1.0), plog(pmul(pset1<T>(0.5), x))), x_le_two); - x_le_two = pmul(pexp(x), x_le_two); - x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two); - T x_gt_two = pmul( - internal::pchebevl<T, 25>::run( - psub(pdiv(pset1<T>(8.0), x), two), B), - prsqrt(x)); - return pselect(pcmp_le(x, two), x_le_two, x_gt_two); - } -}; - -template <typename Scalar> -struct bessel_k0e_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_k0e<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_k0_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_k0 { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_k0<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* k0f.c - * Modified Bessel function, third kind, order zero - * - * - * - * SYNOPSIS: - * - * float x, y, k0f(); - * - * y = k0f( x ); - * - * - * - * DESCRIPTION: - * - * Returns modified Bessel function of the third kind - * of order zero of the argument. - * - * The range is partitioned into the two intervals [0,8] and - * (8, infinity). Chebyshev polynomial expansions are employed - * in each interval. - * - * - * - * ACCURACY: - * - * Tested at 2000 random points between 0 and 8. Peak absolute - * error (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15. - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 7.8e-7 8.5e-8 - * - * ERROR MESSAGES: - * - * message condition value returned - * K0 domain x <= 0 MAXNUM - * - */ - - const float A[] = {1.90451637722020886025E-9f, 2.53479107902614945675E-7f, - 2.28621210311945178607E-5f, 1.26461541144692592338E-3f, - 3.59799365153615016266E-2f, 3.44289899924628486886E-1f, - -5.35327393233902768720E-1f}; - - const float B[] = {-1.69753450938905987466E-9f, 8.57403401741422608519E-9f, - -4.66048989768794782956E-8f, 2.76681363944501510342E-7f, - -1.83175552271911948767E-6f, 1.39498137188764993662E-5f, - -1.28495495816278026384E-4f, 1.56988388573005337491E-3f, - -3.14481013119645005427E-2f, 2.44030308206595545468E0f}; - const T MAXNUM = pset1<T>(NumTraits<float>::infinity()); - const T two = pset1<T>(2.0); - T x_le_two = internal::pchebevl<T, 7>::run( - pmadd(x, x, pset1<T>(-2.0)), A); - x_le_two = pmadd( - generic_i0<T, float>::run(x), pnegate( - plog(pmul(pset1<T>(0.5), x))), x_le_two); - x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two); - T x_gt_two = pmul( - pmul( - pexp(pnegate(x)), - internal::pchebevl<T, 10>::run( - psub(pdiv(pset1<T>(8.0), x), two), B)), - prsqrt(x)); - return pselect(pcmp_le(x, two), x_le_two, x_gt_two); - } -}; - -template <typename T> -struct generic_k0<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* - * - * Modified Bessel function, third kind, order zero, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * double x, y, k0(); - * - * y = k0( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of the third kind of order zero of the argument. - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 1.4e-15 1.4e-16 - * See k0(). - * - */ - const double A[] = { - 1.37446543561352307156E-16, - 4.25981614279661018399E-14, - 1.03496952576338420167E-11, - 1.90451637722020886025E-9, - 2.53479107902614945675E-7, - 2.28621210311945178607E-5, - 1.26461541144692592338E-3, - 3.59799365153615016266E-2, - 3.44289899924628486886E-1, - -5.35327393233902768720E-1}; - const double B[] = { - 5.30043377268626276149E-18, -1.64758043015242134646E-17, - 5.21039150503902756861E-17, -1.67823109680541210385E-16, - 5.51205597852431940784E-16, -1.84859337734377901440E-15, - 6.34007647740507060557E-15, -2.22751332699166985548E-14, - 8.03289077536357521100E-14, -2.98009692317273043925E-13, - 1.14034058820847496303E-12, -4.51459788337394416547E-12, - 1.85594911495471785253E-11, -7.95748924447710747776E-11, - 3.57739728140030116597E-10, -1.69753450938905987466E-9, - 8.57403401741422608519E-9, -4.66048989768794782956E-8, - 2.76681363944501510342E-7, -1.83175552271911948767E-6, - 1.39498137188764993662E-5, -1.28495495816278026384E-4, - 1.56988388573005337491E-3, -3.14481013119645005427E-2, - 2.44030308206595545468E0 - }; - const T MAXNUM = pset1<T>(NumTraits<double>::infinity()); - const T two = pset1<T>(2.0); - T x_le_two = internal::pchebevl<T, 10>::run( - pmadd(x, x, pset1<T>(-2.0)), A); - x_le_two = pmadd( - generic_i0<T, double>::run(x), pnegate( - plog(pmul(pset1<T>(0.5), x))), x_le_two); - x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two); - T x_gt_two = pmul( - pmul( - pexp(-x), - internal::pchebevl<T, 25>::run( - psub(pdiv(pset1<T>(8.0), x), two), B)), - prsqrt(x)); - return pselect(pcmp_le(x, two), x_le_two, x_gt_two); - } -}; - -template <typename Scalar> -struct bessel_k0_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_k0<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_k1e_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_k1e { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_k1e<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* k1ef.c - * - * Modified Bessel function, third kind, order one, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * float x, y, k1ef(); - * - * y = k1ef( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of the third kind of order one of the argument: - * - * k1e(x) = exp(x) * k1(x). - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 4.9e-7 6.7e-8 - * See k1(). - * - */ - - const float A[] = {-2.21338763073472585583E-8f, -2.43340614156596823496E-6f, - -1.73028895751305206302E-4f, -6.97572385963986435018E-3f, - -1.22611180822657148235E-1f, -3.53155960776544875667E-1f, - 1.52530022733894777053E0f}; - const float B[] = {2.01504975519703286596E-9f, -1.03457624656780970260E-8f, - 5.74108412545004946722E-8f, -3.50196060308781257119E-7f, - 2.40648494783721712015E-6f, -1.93619797416608296024E-5f, - 1.95215518471351631108E-4f, -2.85781685962277938680E-3f, - 1.03923736576817238437E-1f, 2.72062619048444266945E0f}; - const T MAXNUM = pset1<T>(NumTraits<float>::infinity()); - const T two = pset1<T>(2.0); - T x_le_two = pdiv(internal::pchebevl<T, 7>::run( - pmadd(x, x, pset1<T>(-2.0)), A), x); - x_le_two = pmadd( - generic_i1<T, float>::run(x), plog(pmul(pset1<T>(0.5), x)), x_le_two); - x_le_two = pmul(x_le_two, pexp(x)); - x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two); - T x_gt_two = pmul( - internal::pchebevl<T, 10>::run( - psub(pdiv(pset1<T>(8.0), x), two), B), - prsqrt(x)); - return pselect(pcmp_le(x, two), x_le_two, x_gt_two); - } -}; - -template <typename T> -struct generic_k1e<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* k1e.c - * - * Modified Bessel function, third kind, order one, - * exponentially scaled - * - * - * - * SYNOPSIS: - * - * double x, y, k1e(); - * - * y = k1e( x ); - * - * - * - * DESCRIPTION: - * - * Returns exponentially scaled modified Bessel function - * of the third kind of order one of the argument: - * - * k1e(x) = exp(x) * k1(x). - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 7.8e-16 1.2e-16 - * See k1(). - * - */ - const double A[] = {-7.02386347938628759343E-18, -2.42744985051936593393E-15, - -6.66690169419932900609E-13, -1.41148839263352776110E-10, - -2.21338763073472585583E-8, -2.43340614156596823496E-6, - -1.73028895751305206302E-4, -6.97572385963986435018E-3, - -1.22611180822657148235E-1, -3.53155960776544875667E-1, - 1.52530022733894777053E0}; - const double B[] = {-5.75674448366501715755E-18, 1.79405087314755922667E-17, - -5.68946255844285935196E-17, 1.83809354436663880070E-16, - -6.05704724837331885336E-16, 2.03870316562433424052E-15, - -7.01983709041831346144E-15, 2.47715442448130437068E-14, - -8.97670518232499435011E-14, 3.34841966607842919884E-13, - -1.28917396095102890680E-12, 5.13963967348173025100E-12, - -2.12996783842756842877E-11, 9.21831518760500529508E-11, - -4.19035475934189648750E-10, 2.01504975519703286596E-9, - -1.03457624656780970260E-8, 5.74108412545004946722E-8, - -3.50196060308781257119E-7, 2.40648494783721712015E-6, - -1.93619797416608296024E-5, 1.95215518471351631108E-4, - -2.85781685962277938680E-3, 1.03923736576817238437E-1, - 2.72062619048444266945E0}; - const T MAXNUM = pset1<T>(NumTraits<double>::infinity()); - const T two = pset1<T>(2.0); - T x_le_two = pdiv(internal::pchebevl<T, 11>::run( - pmadd(x, x, pset1<T>(-2.0)), A), x); - x_le_two = pmadd( - generic_i1<T, double>::run(x), plog(pmul(pset1<T>(0.5), x)), x_le_two); - x_le_two = pmul(x_le_two, pexp(x)); - x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two); - T x_gt_two = pmul( - internal::pchebevl<T, 25>::run( - psub(pdiv(pset1<T>(8.0), x), two), B), - prsqrt(x)); - return pselect(pcmp_le(x, two), x_le_two, x_gt_two); - } -}; - -template <typename Scalar> -struct bessel_k1e_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_k1e<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_k1_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_k1 { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_k1<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* k1f.c - * Modified Bessel function, third kind, order one - * - * - * - * SYNOPSIS: - * - * float x, y, k1f(); - * - * y = k1f( x ); - * - * - * - * DESCRIPTION: - * - * Computes the modified Bessel function of the third kind - * of order one of the argument. - * - * The range is partitioned into the two intervals [0,2] and - * (2, infinity). Chebyshev polynomial expansions are employed - * in each interval. - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 4.6e-7 7.6e-8 - * - * ERROR MESSAGES: - * - * message condition value returned - * k1 domain x <= 0 MAXNUM - * - */ - - const float A[] = {-2.21338763073472585583E-8f, -2.43340614156596823496E-6f, - -1.73028895751305206302E-4f, -6.97572385963986435018E-3f, - -1.22611180822657148235E-1f, -3.53155960776544875667E-1f, - 1.52530022733894777053E0f}; - const float B[] = {2.01504975519703286596E-9f, -1.03457624656780970260E-8f, - 5.74108412545004946722E-8f, -3.50196060308781257119E-7f, - 2.40648494783721712015E-6f, -1.93619797416608296024E-5f, - 1.95215518471351631108E-4f, -2.85781685962277938680E-3f, - 1.03923736576817238437E-1f, 2.72062619048444266945E0f}; - const T MAXNUM = pset1<T>(NumTraits<float>::infinity()); - const T two = pset1<T>(2.0); - T x_le_two = pdiv(internal::pchebevl<T, 7>::run( - pmadd(x, x, pset1<T>(-2.0)), A), x); - x_le_two = pmadd( - generic_i1<T, float>::run(x), plog(pmul(pset1<T>(0.5), x)), x_le_two); - x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two); - T x_gt_two = pmul( - pexp(pnegate(x)), - pmul( - internal::pchebevl<T, 10>::run( - psub(pdiv(pset1<T>(8.0), x), two), B), - prsqrt(x))); - return pselect(pcmp_le(x, two), x_le_two, x_gt_two); - } -}; - -template <typename T> -struct generic_k1<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* k1.c - * Modified Bessel function, third kind, order one - * - * - * - * SYNOPSIS: - * - * float x, y, k1f(); - * - * y = k1f( x ); - * - * - * - * DESCRIPTION: - * - * Computes the modified Bessel function of the third kind - * of order one of the argument. - * - * The range is partitioned into the two intervals [0,2] and - * (2, infinity). Chebyshev polynomial expansions are employed - * in each interval. - * - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0, 30 30000 4.6e-7 7.6e-8 - * - * ERROR MESSAGES: - * - * message condition value returned - * k1 domain x <= 0 MAXNUM - * - */ - const double A[] = {-7.02386347938628759343E-18, -2.42744985051936593393E-15, - -6.66690169419932900609E-13, -1.41148839263352776110E-10, - -2.21338763073472585583E-8, -2.43340614156596823496E-6, - -1.73028895751305206302E-4, -6.97572385963986435018E-3, - -1.22611180822657148235E-1, -3.53155960776544875667E-1, - 1.52530022733894777053E0}; - const double B[] = {-5.75674448366501715755E-18, 1.79405087314755922667E-17, - -5.68946255844285935196E-17, 1.83809354436663880070E-16, - -6.05704724837331885336E-16, 2.03870316562433424052E-15, - -7.01983709041831346144E-15, 2.47715442448130437068E-14, - -8.97670518232499435011E-14, 3.34841966607842919884E-13, - -1.28917396095102890680E-12, 5.13963967348173025100E-12, - -2.12996783842756842877E-11, 9.21831518760500529508E-11, - -4.19035475934189648750E-10, 2.01504975519703286596E-9, - -1.03457624656780970260E-8, 5.74108412545004946722E-8, - -3.50196060308781257119E-7, 2.40648494783721712015E-6, - -1.93619797416608296024E-5, 1.95215518471351631108E-4, - -2.85781685962277938680E-3, 1.03923736576817238437E-1, - 2.72062619048444266945E0}; - const T MAXNUM = pset1<T>(NumTraits<double>::infinity()); - const T two = pset1<T>(2.0); - T x_le_two = pdiv(internal::pchebevl<T, 11>::run( - pmadd(x, x, pset1<T>(-2.0)), A), x); - x_le_two = pmadd( - generic_i1<T, double>::run(x), plog(pmul(pset1<T>(0.5), x)), x_le_two); - x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two); - T x_gt_two = pmul( - pexp(-x), - pmul( - internal::pchebevl<T, 25>::run( - psub(pdiv(pset1<T>(8.0), x), two), B), - prsqrt(x))); - return pselect(pcmp_le(x, two), x_le_two, x_gt_two); - } -}; - -template <typename Scalar> -struct bessel_k1_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_k1<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_j0_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_j0 { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_j0<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* j0f.c - * Bessel function of order zero - * - * - * - * SYNOPSIS: - * - * float x, y, j0f(); - * - * y = j0f( x ); - * - * - * - * DESCRIPTION: - * - * Returns Bessel function of order zero of the argument. - * - * The domain is divided into the intervals [0, 2] and - * (2, infinity). In the first interval the following polynomial - * approximation is used: - * - * - * 2 2 2 - * (w - r ) (w - r ) (w - r ) P(w) - * 1 2 3 - * - * 2 - * where w = x and the three r's are zeros of the function. - * - * In the second interval, the modulus and phase are approximated - * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x) - * and Phase(x) = x + 1/x R(1/x^2) - pi/4. The function is - * - * j0(x) = Modulus(x) cos( Phase(x) ). - * - * - * - * ACCURACY: - * - * Absolute error: - * arithmetic domain # trials peak rms - * IEEE 0, 2 100000 1.3e-7 3.6e-8 - * IEEE 2, 32 100000 1.9e-7 5.4e-8 - * - */ - - const float JP[] = {-6.068350350393235E-008f, 6.388945720783375E-006f, - -3.969646342510940E-004f, 1.332913422519003E-002f, - -1.729150680240724E-001f}; - const float MO[] = {-6.838999669318810E-002f, 1.864949361379502E-001f, - -2.145007480346739E-001f, 1.197549369473540E-001f, - -3.560281861530129E-003f, -4.969382655296620E-002f, - -3.355424622293709E-006f, 7.978845717621440E-001f}; - const float PH[] = {3.242077816988247E+001f, -3.630592630518434E+001f, - 1.756221482109099E+001f, -4.974978466280903E+000f, - 1.001973420681837E+000f, -1.939906941791308E-001f, - 6.490598792654666E-002f, -1.249992184872738E-001f}; - const T DR1 = pset1<T>(5.78318596294678452118f); - const T NEG_PIO4F = pset1<T>(-0.7853981633974483096f); /* -pi / 4 */ - T y = pabs(x); - T z = pmul(y, y); - T y_le_two = pselect( - pcmp_lt(y, pset1<T>(1.0e-3f)), - pmadd(z, pset1<T>(-0.25f), pset1<T>(1.0f)), - pmul(psub(z, DR1), internal::ppolevl<T, 4>::run(z, JP))); - T q = pdiv(pset1<T>(1.0f), y); - T w = prsqrt(y); - T p = pmul(w, internal::ppolevl<T, 7>::run(q, MO)); - w = pmul(q, q); - T yn = pmadd(q, internal::ppolevl<T, 7>::run(w, PH), NEG_PIO4F); - T y_gt_two = pmul(p, pcos(padd(yn, y))); - return pselect(pcmp_le(y, pset1<T>(2.0)), y_le_two, y_gt_two); - } -}; - -template <typename T> -struct generic_j0<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* j0.c - * Bessel function of order zero - * - * - * - * SYNOPSIS: - * - * double x, y, j0(); - * - * y = j0( x ); - * - * - * - * DESCRIPTION: - * - * Returns Bessel function of order zero of the argument. - * - * The domain is divided into the intervals [0, 5] and - * (5, infinity). In the first interval the following rational - * approximation is used: - * - * - * 2 2 - * (w - r ) (w - r ) P (w) / Q (w) - * 1 2 3 8 - * - * 2 - * where w = x and the two r's are zeros of the function. - * - * In the second interval, the Hankel asymptotic expansion - * is employed with two rational functions of degree 6/6 - * and 7/7. - * - * - * - * ACCURACY: - * - * Absolute error: - * arithmetic domain # trials peak rms - * DEC 0, 30 10000 4.4e-17 6.3e-18 - * IEEE 0, 30 60000 4.2e-16 1.1e-16 - * - */ - const double PP[] = {7.96936729297347051624E-4, 8.28352392107440799803E-2, - 1.23953371646414299388E0, 5.44725003058768775090E0, - 8.74716500199817011941E0, 5.30324038235394892183E0, - 9.99999999999999997821E-1}; - const double PQ[] = {9.24408810558863637013E-4, 8.56288474354474431428E-2, - 1.25352743901058953537E0, 5.47097740330417105182E0, - 8.76190883237069594232E0, 5.30605288235394617618E0, - 1.00000000000000000218E0}; - const double QP[] = {-1.13663838898469149931E-2, -1.28252718670509318512E0, - -1.95539544257735972385E1, -9.32060152123768231369E1, - -1.77681167980488050595E2, -1.47077505154951170175E2, - -5.14105326766599330220E1, -6.05014350600728481186E0}; - const double QQ[] = {1.00000000000000000000E0, 6.43178256118178023184E1, - 8.56430025976980587198E2, 3.88240183605401609683E3, - 7.24046774195652478189E3, 5.93072701187316984827E3, - 2.06209331660327847417E3, 2.42005740240291393179E2}; - const double RP[] = {-4.79443220978201773821E9, 1.95617491946556577543E12, - -2.49248344360967716204E14, 9.70862251047306323952E15}; - const double RQ[] = {1.00000000000000000000E0, 4.99563147152651017219E2, - 1.73785401676374683123E5, 4.84409658339962045305E7, - 1.11855537045356834862E10, 2.11277520115489217587E12, - 3.10518229857422583814E14, 3.18121955943204943306E16, - 1.71086294081043136091E18}; - const T DR1 = pset1<T>(5.78318596294678452118E0); - const T DR2 = pset1<T>(3.04712623436620863991E1); - const T SQ2OPI = pset1<T>(7.9788456080286535587989E-1); /* sqrt(2 / pi) */ - const T NEG_PIO4 = pset1<T>(-0.7853981633974483096); /* pi / 4 */ - - T y = pabs(x); - T z = pmul(y, y); - T y_le_five = pselect( - pcmp_lt(y, pset1<T>(1.0e-5)), - pmadd(z, pset1<T>(-0.25), pset1<T>(1.0)), - pmul(pmul(psub(z, DR1), psub(z, DR2)), - pdiv(internal::ppolevl<T, 3>::run(z, RP), - internal::ppolevl<T, 8>::run(z, RQ)))); - T s = pdiv(pset1<T>(25.0), z); - T p = pdiv( - internal::ppolevl<T, 6>::run(s, PP), - internal::ppolevl<T, 6>::run(s, PQ)); - T q = pdiv( - internal::ppolevl<T, 7>::run(s, QP), - internal::ppolevl<T, 7>::run(s, QQ)); - T yn = padd(y, NEG_PIO4); - T w = pdiv(pset1<T>(-5.0), y); - p = pmadd(p, pcos(yn), pmul(w, pmul(q, psin(yn)))); - T y_gt_five = pmul(p, pmul(SQ2OPI, prsqrt(y))); - return pselect(pcmp_le(y, pset1<T>(5.0)), y_le_five, y_gt_five); - } -}; - -template <typename Scalar> -struct bessel_j0_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_j0<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_y0_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_y0 { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_y0<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* j0f.c - * Bessel function of the second kind, order zero - * - * - * - * SYNOPSIS: - * - * float x, y, y0f(); - * - * y = y0f( x ); - * - * - * - * DESCRIPTION: - * - * Returns Bessel function of the second kind, of order - * zero, of the argument. - * - * The domain is divided into the intervals [0, 2] and - * (2, infinity). In the first interval a rational approximation - * R(x) is employed to compute - * - * 2 2 2 - * y0(x) = (w - r ) (w - r ) (w - r ) R(x) + 2/pi ln(x) j0(x). - * 1 2 3 - * - * Thus a call to j0() is required. The three zeros are removed - * from R(x) to improve its numerical stability. - * - * In the second interval, the modulus and phase are approximated - * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x) - * and Phase(x) = x + 1/x S(1/x^2) - pi/4. Then the function is - * - * y0(x) = Modulus(x) sin( Phase(x) ). - * - * - * - * - * ACCURACY: - * - * Absolute error, when y0(x) < 1; else relative error: - * - * arithmetic domain # trials peak rms - * IEEE 0, 2 100000 2.4e-7 3.4e-8 - * IEEE 2, 32 100000 1.8e-7 5.3e-8 - * - */ - - const float YP[] = {9.454583683980369E-008f, -9.413212653797057E-006f, - 5.344486707214273E-004f, -1.584289289821316E-002f, - 1.707584643733568E-001f}; - const float MO[] = {-6.838999669318810E-002f, 1.864949361379502E-001f, - -2.145007480346739E-001f, 1.197549369473540E-001f, - -3.560281861530129E-003f, -4.969382655296620E-002f, - -3.355424622293709E-006f, 7.978845717621440E-001f}; - const float PH[] = {3.242077816988247E+001f, -3.630592630518434E+001f, - 1.756221482109099E+001f, -4.974978466280903E+000f, - 1.001973420681837E+000f, -1.939906941791308E-001f, - 6.490598792654666E-002f, -1.249992184872738E-001f}; - const T YZ1 = pset1<T>(0.43221455686510834878f); - const T TWOOPI = pset1<T>(0.636619772367581343075535f); /* 2 / pi */ - const T NEG_PIO4F = pset1<T>(-0.7853981633974483096f); /* -pi / 4 */ - const T NEG_MAXNUM = pset1<T>(-NumTraits<float>::infinity()); - T z = pmul(x, x); - T x_le_two = pmul(TWOOPI, pmul(plog(x), generic_j0<T, float>::run(x))); - x_le_two = pmadd( - psub(z, YZ1), internal::ppolevl<T, 4>::run(z, YP), x_le_two); - x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), NEG_MAXNUM, x_le_two); - T q = pdiv(pset1<T>(1.0), x); - T w = prsqrt(x); - T p = pmul(w, internal::ppolevl<T, 7>::run(q, MO)); - T u = pmul(q, q); - T xn = pmadd(q, internal::ppolevl<T, 7>::run(u, PH), NEG_PIO4F); - T x_gt_two = pmul(p, psin(padd(xn, x))); - return pselect(pcmp_le(x, pset1<T>(2.0)), x_le_two, x_gt_two); - } -}; - -template <typename T> -struct generic_y0<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* j0.c - * Bessel function of the second kind, order zero - * - * - * - * SYNOPSIS: - * - * double x, y, y0(); - * - * y = y0( x ); - * - * - * - * DESCRIPTION: - * - * Returns Bessel function of the second kind, of order - * zero, of the argument. - * - * The domain is divided into the intervals [0, 5] and - * (5, infinity). In the first interval a rational approximation - * R(x) is employed to compute - * y0(x) = R(x) + 2 * log(x) * j0(x) / PI. - * Thus a call to j0() is required. - * - * In the second interval, the Hankel asymptotic expansion - * is employed with two rational functions of degree 6/6 - * and 7/7. - * - * - * - * ACCURACY: - * - * Absolute error, when y0(x) < 1; else relative error: - * - * arithmetic domain # trials peak rms - * DEC 0, 30 9400 7.0e-17 7.9e-18 - * IEEE 0, 30 30000 1.3e-15 1.6e-16 - * - */ - const double PP[] = {7.96936729297347051624E-4, 8.28352392107440799803E-2, - 1.23953371646414299388E0, 5.44725003058768775090E0, - 8.74716500199817011941E0, 5.30324038235394892183E0, - 9.99999999999999997821E-1}; - const double PQ[] = {9.24408810558863637013E-4, 8.56288474354474431428E-2, - 1.25352743901058953537E0, 5.47097740330417105182E0, - 8.76190883237069594232E0, 5.30605288235394617618E0, - 1.00000000000000000218E0}; - const double QP[] = {-1.13663838898469149931E-2, -1.28252718670509318512E0, - -1.95539544257735972385E1, -9.32060152123768231369E1, - -1.77681167980488050595E2, -1.47077505154951170175E2, - -5.14105326766599330220E1, -6.05014350600728481186E0}; - const double QQ[] = {1.00000000000000000000E0, 6.43178256118178023184E1, - 8.56430025976980587198E2, 3.88240183605401609683E3, - 7.24046774195652478189E3, 5.93072701187316984827E3, - 2.06209331660327847417E3, 2.42005740240291393179E2}; - const double YP[] = {1.55924367855235737965E4, -1.46639295903971606143E7, - 5.43526477051876500413E9, -9.82136065717911466409E11, - 8.75906394395366999549E13, -3.46628303384729719441E15, - 4.42733268572569800351E16, -1.84950800436986690637E16}; - const double YQ[] = {1.00000000000000000000E0, 1.04128353664259848412E3, - 6.26107330137134956842E5, 2.68919633393814121987E8, - 8.64002487103935000337E10, 2.02979612750105546709E13, - 3.17157752842975028269E15, 2.50596256172653059228E17}; - const T SQ2OPI = pset1<T>(7.9788456080286535587989E-1); /* sqrt(2 / pi) */ - const T TWOOPI = pset1<T>(0.636619772367581343075535); /* 2 / pi */ - const T NEG_PIO4 = pset1<T>(-0.7853981633974483096); /* -pi / 4 */ - const T NEG_MAXNUM = pset1<T>(-NumTraits<double>::infinity()); - - T z = pmul(x, x); - T x_le_five = pdiv(internal::ppolevl<T, 7>::run(z, YP), - internal::ppolevl<T, 7>::run(z, YQ)); - x_le_five = pmadd( - pmul(TWOOPI, plog(x)), generic_j0<T, double>::run(x), x_le_five); - x_le_five = pselect(pcmp_le(x, pset1<T>(0.0)), NEG_MAXNUM, x_le_five); - T s = pdiv(pset1<T>(25.0), z); - T p = pdiv( - internal::ppolevl<T, 6>::run(s, PP), - internal::ppolevl<T, 6>::run(s, PQ)); - T q = pdiv( - internal::ppolevl<T, 7>::run(s, QP), - internal::ppolevl<T, 7>::run(s, QQ)); - T xn = padd(x, NEG_PIO4); - T w = pdiv(pset1<T>(5.0), x); - p = pmadd(p, psin(xn), pmul(w, pmul(q, pcos(xn)))); - T x_gt_five = pmul(p, pmul(SQ2OPI, prsqrt(x))); - return pselect(pcmp_le(x, pset1<T>(5.0)), x_le_five, x_gt_five); - } -}; - -template <typename Scalar> -struct bessel_y0_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_y0<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_j1_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_j1 { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_j1<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* j1f.c - * Bessel function of order one - * - * - * - * SYNOPSIS: - * - * float x, y, j1f(); - * - * y = j1f( x ); - * - * - * - * DESCRIPTION: - * - * Returns Bessel function of order one of the argument. - * - * The domain is divided into the intervals [0, 2] and - * (2, infinity). In the first interval a polynomial approximation - * 2 - * (w - r ) x P(w) - * 1 - * 2 - * is used, where w = x and r is the first zero of the function. - * - * In the second interval, the modulus and phase are approximated - * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x) - * and Phase(x) = x + 1/x R(1/x^2) - 3pi/4. The function is - * - * j0(x) = Modulus(x) cos( Phase(x) ). - * - * - * - * ACCURACY: - * - * Absolute error: - * arithmetic domain # trials peak rms - * IEEE 0, 2 100000 1.2e-7 2.5e-8 - * IEEE 2, 32 100000 2.0e-7 5.3e-8 - * - * - */ - - const float JP[] = {-4.878788132172128E-009f, 6.009061827883699E-007f, - -4.541343896997497E-005f, 1.937383947804541E-003f, - -3.405537384615824E-002f}; - const float MO1[] = {6.913942741265801E-002f, -2.284801500053359E-001f, - 3.138238455499697E-001f, -2.102302420403875E-001f, - 5.435364690523026E-003f, 1.493389585089498E-001f, - 4.976029650847191E-006f, 7.978845453073848E-001f}; - const float PH1[] = {-4.497014141919556E+001f, 5.073465654089319E+001f, - -2.485774108720340E+001f, 7.222973196770240E+000f, - -1.544842782180211E+000f, 3.503787691653334E-001f, - -1.637986776941202E-001f, 3.749989509080821E-001f}; - const T Z1 = pset1<T>(1.46819706421238932572E1f); - const T NEG_THPIO4F = pset1<T>(-2.35619449019234492885f); /* -3*pi/4 */ - - T y = pabs(x); - T z = pmul(y, y); - T y_le_two = pmul( - psub(z, Z1), - pmul(x, internal::ppolevl<T, 4>::run(z, JP))); - T q = pdiv(pset1<T>(1.0f), y); - T w = prsqrt(y); - T p = pmul(w, internal::ppolevl<T, 7>::run(q, MO1)); - w = pmul(q, q); - T yn = pmadd(q, internal::ppolevl<T, 7>::run(w, PH1), NEG_THPIO4F); - T y_gt_two = pmul(p, pcos(padd(yn, y))); - // j1 is an odd function. This implementation differs from cephes to - // take this fact in to account. Cephes returns -j1(x) for y > 2 range. - y_gt_two = pselect( - pcmp_lt(x, pset1<T>(0.0f)), pnegate(y_gt_two), y_gt_two); - return pselect(pcmp_le(y, pset1<T>(2.0f)), y_le_two, y_gt_two); - } -}; - -template <typename T> -struct generic_j1<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* j1.c - * Bessel function of order one - * - * - * - * SYNOPSIS: - * - * double x, y, j1(); - * - * y = j1( x ); - * - * - * - * DESCRIPTION: - * - * Returns Bessel function of order one of the argument. - * - * The domain is divided into the intervals [0, 8] and - * (8, infinity). In the first interval a 24 term Chebyshev - * expansion is used. In the second, the asymptotic - * trigonometric representation is employed using two - * rational functions of degree 5/5. - * - * - * - * ACCURACY: - * - * Absolute error: - * arithmetic domain # trials peak rms - * DEC 0, 30 10000 4.0e-17 1.1e-17 - * IEEE 0, 30 30000 2.6e-16 1.1e-16 - * - */ - const double PP[] = {7.62125616208173112003E-4, 7.31397056940917570436E-2, - 1.12719608129684925192E0, 5.11207951146807644818E0, - 8.42404590141772420927E0, 5.21451598682361504063E0, - 1.00000000000000000254E0}; - const double PQ[] = {5.71323128072548699714E-4, 6.88455908754495404082E-2, - 1.10514232634061696926E0, 5.07386386128601488557E0, - 8.39985554327604159757E0, 5.20982848682361821619E0, - 9.99999999999999997461E-1}; - const double QP[] = {5.10862594750176621635E-2, 4.98213872951233449420E0, - 7.58238284132545283818E1, 3.66779609360150777800E2, - 7.10856304998926107277E2, 5.97489612400613639965E2, - 2.11688757100572135698E2, 2.52070205858023719784E1}; - const double QQ[] = {1.00000000000000000000E0, 7.42373277035675149943E1, - 1.05644886038262816351E3, 4.98641058337653607651E3, - 9.56231892404756170795E3, 7.99704160447350683650E3, - 2.82619278517639096600E3, 3.36093607810698293419E2}; - const double RP[] = {-8.99971225705559398224E8, 4.52228297998194034323E11, - -7.27494245221818276015E13, 3.68295732863852883286E15}; - const double RQ[] = {1.00000000000000000000E0, 6.20836478118054335476E2, - 2.56987256757748830383E5, 8.35146791431949253037E7, - 2.21511595479792499675E10, 4.74914122079991414898E12, - 7.84369607876235854894E14, 8.95222336184627338078E16, - 5.32278620332680085395E18}; - const T Z1 = pset1<T>(1.46819706421238932572E1); - const T Z2 = pset1<T>(4.92184563216946036703E1); - const T NEG_THPIO4 = pset1<T>(-2.35619449019234492885); /* -3*pi/4 */ - const T SQ2OPI = pset1<T>(7.9788456080286535587989E-1); /* sqrt(2 / pi) */ - T y = pabs(x); - T z = pmul(y, y); - T y_le_five = pdiv(internal::ppolevl<T, 3>::run(z, RP), - internal::ppolevl<T, 8>::run(z, RQ)); - y_le_five = pmul(pmul(pmul(y_le_five, x), psub(z, Z1)), psub(z, Z2)); - T s = pdiv(pset1<T>(25.0), z); - T p = pdiv( - internal::ppolevl<T, 6>::run(s, PP), - internal::ppolevl<T, 6>::run(s, PQ)); - T q = pdiv( - internal::ppolevl<T, 7>::run(s, QP), - internal::ppolevl<T, 7>::run(s, QQ)); - T yn = padd(y, NEG_THPIO4); - T w = pdiv(pset1<T>(-5.0), y); - p = pmadd(p, pcos(yn), pmul(w, pmul(q, psin(yn)))); - T y_gt_five = pmul(p, pmul(SQ2OPI, prsqrt(y))); - // j1 is an odd function. This implementation differs from cephes to - // take this fact in to account. Cephes returns -j1(x) for y > 5 range. - y_gt_five = pselect( - pcmp_lt(x, pset1<T>(0.0)), pnegate(y_gt_five), y_gt_five); - return pselect(pcmp_le(y, pset1<T>(5.0)), y_le_five, y_gt_five); - } -}; - -template <typename Scalar> -struct bessel_j1_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_j1<Scalar, Scalar>::run(x); - } -}; - -template <typename Scalar> -struct bessel_y1_retval { - typedef Scalar type; -}; - -template <typename T, typename ScalarType> -struct generic_y1 { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T&) { - EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return ScalarType(0); - } -}; - -template <typename T> -struct generic_y1<T, float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* j1f.c - * Bessel function of second kind of order one - * - * - * - * SYNOPSIS: - * - * double x, y, y1(); - * - * y = y1( x ); - * - * - * - * DESCRIPTION: - * - * Returns Bessel function of the second kind of order one - * of the argument. - * - * The domain is divided into the intervals [0, 2] and - * (2, infinity). In the first interval a rational approximation - * R(x) is employed to compute - * - * 2 - * y0(x) = (w - r ) x R(x^2) + 2/pi (ln(x) j1(x) - 1/x) . - * 1 - * - * Thus a call to j1() is required. - * - * In the second interval, the modulus and phase are approximated - * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x) - * and Phase(x) = x + 1/x S(1/x^2) - 3pi/4. Then the function is - * - * y0(x) = Modulus(x) sin( Phase(x) ). - * - * - * - * - * ACCURACY: - * - * Absolute error: - * arithmetic domain # trials peak rms - * IEEE 0, 2 100000 2.2e-7 4.6e-8 - * IEEE 2, 32 100000 1.9e-7 5.3e-8 - * - * (error criterion relative when |y1| > 1). - * - */ - - const float YP[] = {8.061978323326852E-009f, -9.496460629917016E-007f, - 6.719543806674249E-005f, -2.641785726447862E-003f, - 4.202369946500099E-002f}; - const float MO1[] = {6.913942741265801E-002f, -2.284801500053359E-001f, - 3.138238455499697E-001f, -2.102302420403875E-001f, - 5.435364690523026E-003f, 1.493389585089498E-001f, - 4.976029650847191E-006f, 7.978845453073848E-001f}; - const float PH1[] = {-4.497014141919556E+001f, 5.073465654089319E+001f, - -2.485774108720340E+001f, 7.222973196770240E+000f, - -1.544842782180211E+000f, 3.503787691653334E-001f, - -1.637986776941202E-001f, 3.749989509080821E-001f}; - const T YO1 = pset1<T>(4.66539330185668857532f); - const T NEG_THPIO4F = pset1<T>(-2.35619449019234492885f); /* -3*pi/4 */ - const T TWOOPI = pset1<T>(0.636619772367581343075535f); /* 2/pi */ - const T NEG_MAXNUM = pset1<T>(-NumTraits<float>::infinity()); - - T z = pmul(x, x); - T x_le_two = pmul(psub(z, YO1), internal::ppolevl<T, 4>::run(z, YP)); - x_le_two = pmadd( - x_le_two, x, - pmul(TWOOPI, pmadd( - generic_j1<T, float>::run(x), plog(x), - pdiv(pset1<T>(-1.0f), x)))); - x_le_two = pselect(pcmp_lt(x, pset1<T>(0.0f)), NEG_MAXNUM, x_le_two); - - T q = pdiv(pset1<T>(1.0), x); - T w = prsqrt(x); - T p = pmul(w, internal::ppolevl<T, 7>::run(q, MO1)); - w = pmul(q, q); - T xn = pmadd(q, internal::ppolevl<T, 7>::run(w, PH1), NEG_THPIO4F); - T x_gt_two = pmul(p, psin(padd(xn, x))); - return pselect(pcmp_le(x, pset1<T>(2.0)), x_le_two, x_gt_two); - } -}; - -template <typename T> -struct generic_y1<T, double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T& x) { - /* j1.c - * Bessel function of second kind of order one - * - * - * - * SYNOPSIS: - * - * double x, y, y1(); - * - * y = y1( x ); - * - * - * - * DESCRIPTION: - * - * Returns Bessel function of the second kind of order one - * of the argument. - * - * The domain is divided into the intervals [0, 8] and - * (8, infinity). In the first interval a 25 term Chebyshev - * expansion is used, and a call to j1() is required. - * In the second, the asymptotic trigonometric representation - * is employed using two rational functions of degree 5/5. - * - * - * - * ACCURACY: - * - * Absolute error: - * arithmetic domain # trials peak rms - * DEC 0, 30 10000 8.6e-17 1.3e-17 - * IEEE 0, 30 30000 1.0e-15 1.3e-16 - * - * (error criterion relative when |y1| > 1). - * - */ - const double PP[] = {7.62125616208173112003E-4, 7.31397056940917570436E-2, - 1.12719608129684925192E0, 5.11207951146807644818E0, - 8.42404590141772420927E0, 5.21451598682361504063E0, - 1.00000000000000000254E0}; - const double PQ[] = {5.71323128072548699714E-4, 6.88455908754495404082E-2, - 1.10514232634061696926E0, 5.07386386128601488557E0, - 8.39985554327604159757E0, 5.20982848682361821619E0, - 9.99999999999999997461E-1}; - const double QP[] = {5.10862594750176621635E-2, 4.98213872951233449420E0, - 7.58238284132545283818E1, 3.66779609360150777800E2, - 7.10856304998926107277E2, 5.97489612400613639965E2, - 2.11688757100572135698E2, 2.52070205858023719784E1}; - const double QQ[] = {1.00000000000000000000E0, 7.42373277035675149943E1, - 1.05644886038262816351E3, 4.98641058337653607651E3, - 9.56231892404756170795E3, 7.99704160447350683650E3, - 2.82619278517639096600E3, 3.36093607810698293419E2}; - const double YP[] = {1.26320474790178026440E9, -6.47355876379160291031E11, - 1.14509511541823727583E14, -8.12770255501325109621E15, - 2.02439475713594898196E17, -7.78877196265950026825E17}; - const double YQ[] = {1.00000000000000000000E0, 5.94301592346128195359E2, - 2.35564092943068577943E5, 7.34811944459721705660E7, - 1.87601316108706159478E10, 3.88231277496238566008E12, - 6.20557727146953693363E14, 6.87141087355300489866E16, - 3.97270608116560655612E18}; - const T SQ2OPI = pset1<T>(.79788456080286535588); - const T NEG_THPIO4 = pset1<T>(-2.35619449019234492885); /* -3*pi/4 */ - const T TWOOPI = pset1<T>(0.636619772367581343075535); /* 2/pi */ - const T NEG_MAXNUM = pset1<T>(-NumTraits<double>::infinity()); - - T z = pmul(x, x); - T x_le_five = pdiv(internal::ppolevl<T, 5>::run(z, YP), - internal::ppolevl<T, 8>::run(z, YQ)); - x_le_five = pmadd( - x_le_five, x, pmul( - TWOOPI, pmadd(generic_j1<T, double>::run(x), plog(x), - pdiv(pset1<T>(-1.0), x)))); - - x_le_five = pselect(pcmp_le(x, pset1<T>(0.0)), NEG_MAXNUM, x_le_five); - T s = pdiv(pset1<T>(25.0), z); - T p = pdiv( - internal::ppolevl<T, 6>::run(s, PP), - internal::ppolevl<T, 6>::run(s, PQ)); - T q = pdiv( - internal::ppolevl<T, 7>::run(s, QP), - internal::ppolevl<T, 7>::run(s, QQ)); - T xn = padd(x, NEG_THPIO4); - T w = pdiv(pset1<T>(5.0), x); - p = pmadd(p, psin(xn), pmul(w, pmul(q, pcos(xn)))); - T x_gt_five = pmul(p, pmul(SQ2OPI, prsqrt(x))); - return pselect(pcmp_le(x, pset1<T>(5.0)), x_le_five, x_gt_five); - } -}; - -template <typename Scalar> -struct bessel_y1_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_y1<Scalar, Scalar>::run(x); - } -}; - -} // end namespace internal - -namespace numext { - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_i0, Scalar) - bessel_i0(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_i0, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_i0e, Scalar) - bessel_i0e(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_i0e, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_i1, Scalar) - bessel_i1(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_i1, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_i1e, Scalar) - bessel_i1e(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_i1e, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_k0, Scalar) - bessel_k0(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_k0, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_k0e, Scalar) - bessel_k0e(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_k0e, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_k1, Scalar) - bessel_k1(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_k1, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_k1e, Scalar) - bessel_k1e(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_k1e, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_j0, Scalar) - bessel_j0(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_j0, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_y0, Scalar) - bessel_y0(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_y0, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_j1, Scalar) - bessel_j1(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_j1, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(bessel_y1, Scalar) - bessel_y1(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(bessel_y1, Scalar)::run(x); -} - -} // end namespace numext - -} // end namespace Eigen - -#endif // EIGEN_BESSEL_FUNCTIONS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsPacketMath.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsPacketMath.h deleted file mode 100644 index efc6d9c8..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/BesselFunctionsPacketMath.h +++ /dev/null @@ -1,130 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_BESSELFUNCTIONS_PACKETMATH_H -#define EIGEN_BESSELFUNCTIONS_PACKETMATH_H - -namespace Eigen { - -namespace internal { - -/** \internal \returns the exponentially scaled modified Bessel function of - * order zero i0(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_i0(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_i0; return generic_i0<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order zero i0e(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_i0e(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_i0e; return generic_i0e<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order one i1(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_i1(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_i1; return generic_i1<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order one i1e(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_i1e(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_i1e; return generic_i1e<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order zero j0(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_j0(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_j0; return generic_j0<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order zero j1(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_j1(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_j1; return generic_j1<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order one y0(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_y0(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_y0; return generic_y0<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order one y1(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_y1(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_y1; return generic_y1<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order zero k0(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_k0(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_k0; return generic_k0<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order zero k0e(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_k0e(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_k0e; return generic_k0e<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order one k1e(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_k1(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_k1; return generic_k1<Packet, ScalarType>::run(x); -} - -/** \internal \returns the exponentially scaled modified Bessel function of - * order one k1e(\a a) (coeff-wise) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pbessel_k1e(const Packet& x) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_k1e; return generic_k1e<Packet, ScalarType>::run(x); -} - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_BESSELFUNCTIONS_PACKETMATH_H - diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/HipVectorCompatibility.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/HipVectorCompatibility.h deleted file mode 100644 index 60a3972a..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/HipVectorCompatibility.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef HIP_VECTOR_COMPATIBILITY_H -#define HIP_VECTOR_COMPATIBILITY_H - -namespace hip_impl { - template <typename, typename, unsigned int> struct Scalar_accessor; -} // end namespace hip_impl - -namespace Eigen { -namespace internal { - -#define HIP_SCALAR_ACCESSOR_BUILDER(NAME) \ -template <typename T, typename U, unsigned int n> \ -struct NAME <hip_impl::Scalar_accessor<T, U, n>> : NAME <T> {}; - -#define HIP_SCALAR_ACCESSOR_BUILDER_IGAMMA(NAME) \ -template <typename T, typename U, unsigned int n, IgammaComputationMode mode> \ -struct NAME <hip_impl::Scalar_accessor<T, U, n>, mode> : NAME <T, mode> {}; - -#if EIGEN_HAS_C99_MATH -HIP_SCALAR_ACCESSOR_BUILDER(betainc_helper) -HIP_SCALAR_ACCESSOR_BUILDER(erf_impl) -HIP_SCALAR_ACCESSOR_BUILDER(erfc_impl) -HIP_SCALAR_ACCESSOR_BUILDER(igammac_impl) -HIP_SCALAR_ACCESSOR_BUILDER(incbeta_cfe) -HIP_SCALAR_ACCESSOR_BUILDER(lgamma_impl) -HIP_SCALAR_ACCESSOR_BUILDER(ndtri_impl) -HIP_SCALAR_ACCESSOR_BUILDER(polygamma_impl) -HIP_SCALAR_ACCESSOR_BUILDER_IGAMMA(igamma_generic_impl) -#endif - -HIP_SCALAR_ACCESSOR_BUILDER(bessel_i0_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_i0e_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_i1_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_i1e_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_j0_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_j1_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_k0_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_k0e_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_k1_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_k1e_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_y0_impl) -HIP_SCALAR_ACCESSOR_BUILDER(bessel_y1_impl) -HIP_SCALAR_ACCESSOR_BUILDER(betainc_impl) -HIP_SCALAR_ACCESSOR_BUILDER(digamma_impl) -HIP_SCALAR_ACCESSOR_BUILDER(digamma_impl_maybe_poly) -HIP_SCALAR_ACCESSOR_BUILDER(gamma_sample_der_alpha_impl) -HIP_SCALAR_ACCESSOR_BUILDER(gamma_sample_der_alpha_retval) -HIP_SCALAR_ACCESSOR_BUILDER(igamma_der_a_impl) -HIP_SCALAR_ACCESSOR_BUILDER(igamma_der_a_retval) -HIP_SCALAR_ACCESSOR_BUILDER(igamma_impl) -HIP_SCALAR_ACCESSOR_BUILDER(zeta_impl) -HIP_SCALAR_ACCESSOR_BUILDER(zeta_impl_series) -HIP_SCALAR_ACCESSOR_BUILDER_IGAMMA(igamma_series_impl) -HIP_SCALAR_ACCESSOR_BUILDER_IGAMMA(igammac_cf_impl) - -} // end namespace internal -} // end namespace Eigen - -#endif // HIP_VECTOR_COMPATIBILITY_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsArrayAPI.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsArrayAPI.h deleted file mode 100644 index 691ff4d0..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsArrayAPI.h +++ /dev/null @@ -1,167 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -#ifndef EIGEN_SPECIALFUNCTIONS_ARRAYAPI_H -#define EIGEN_SPECIALFUNCTIONS_ARRAYAPI_H - -namespace Eigen { - -/** \cpp11 \returns an expression of the coefficient-wise igamma(\a a, \a x) to the given arrays. - * - * This function computes the coefficient-wise incomplete gamma function. - * - * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations of igammac(T,T) for any scalar - * type T to be supported. - * - * \sa Eigen::igammac(), Eigen::lgamma() - */ -template<typename Derived,typename ExponentDerived> -EIGEN_STRONG_INLINE const Eigen::CwiseBinaryOp<Eigen::internal::scalar_igamma_op<typename Derived::Scalar>, const Derived, const ExponentDerived> -igamma(const Eigen::ArrayBase<Derived>& a, const Eigen::ArrayBase<ExponentDerived>& x) -{ - return Eigen::CwiseBinaryOp<Eigen::internal::scalar_igamma_op<typename Derived::Scalar>, const Derived, const ExponentDerived>( - a.derived(), - x.derived() - ); -} - -/** \cpp11 \returns an expression of the coefficient-wise igamma_der_a(\a a, \a x) to the given arrays. - * - * This function computes the coefficient-wise derivative of the incomplete - * gamma function with respect to the parameter a. - * - * \note This function supports only float and double scalar types in c++11 - * mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations - * of igamma_der_a(T,T) for any scalar - * type T to be supported. - * - * \sa Eigen::igamma(), Eigen::lgamma() - */ -template <typename Derived, typename ExponentDerived> -EIGEN_STRONG_INLINE const Eigen::CwiseBinaryOp<Eigen::internal::scalar_igamma_der_a_op<typename Derived::Scalar>, const Derived, const ExponentDerived> -igamma_der_a(const Eigen::ArrayBase<Derived>& a, const Eigen::ArrayBase<ExponentDerived>& x) { - return Eigen::CwiseBinaryOp<Eigen::internal::scalar_igamma_der_a_op<typename Derived::Scalar>, const Derived, const ExponentDerived>( - a.derived(), - x.derived()); -} - -/** \cpp11 \returns an expression of the coefficient-wise gamma_sample_der_alpha(\a alpha, \a sample) to the given arrays. - * - * This function computes the coefficient-wise derivative of the sample - * of a Gamma(alpha, 1) random variable with respect to the parameter alpha. - * - * \note This function supports only float and double scalar types in c++11 - * mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations - * of gamma_sample_der_alpha(T,T) for any scalar - * type T to be supported. - * - * \sa Eigen::igamma(), Eigen::lgamma() - */ -template <typename AlphaDerived, typename SampleDerived> -EIGEN_STRONG_INLINE const Eigen::CwiseBinaryOp<Eigen::internal::scalar_gamma_sample_der_alpha_op<typename AlphaDerived::Scalar>, const AlphaDerived, const SampleDerived> -gamma_sample_der_alpha(const Eigen::ArrayBase<AlphaDerived>& alpha, const Eigen::ArrayBase<SampleDerived>& sample) { - return Eigen::CwiseBinaryOp<Eigen::internal::scalar_gamma_sample_der_alpha_op<typename AlphaDerived::Scalar>, const AlphaDerived, const SampleDerived>( - alpha.derived(), - sample.derived()); -} - -/** \cpp11 \returns an expression of the coefficient-wise igammac(\a a, \a x) to the given arrays. - * - * This function computes the coefficient-wise complementary incomplete gamma function. - * - * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations of igammac(T,T) for any scalar - * type T to be supported. - * - * \sa Eigen::igamma(), Eigen::lgamma() - */ -template<typename Derived,typename ExponentDerived> -EIGEN_STRONG_INLINE const Eigen::CwiseBinaryOp<Eigen::internal::scalar_igammac_op<typename Derived::Scalar>, const Derived, const ExponentDerived> -igammac(const Eigen::ArrayBase<Derived>& a, const Eigen::ArrayBase<ExponentDerived>& x) -{ - return Eigen::CwiseBinaryOp<Eigen::internal::scalar_igammac_op<typename Derived::Scalar>, const Derived, const ExponentDerived>( - a.derived(), - x.derived() - ); -} - -/** \cpp11 \returns an expression of the coefficient-wise polygamma(\a n, \a x) to the given arrays. - * - * It returns the \a n -th derivative of the digamma(psi) evaluated at \c x. - * - * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations of polygamma(T,T) for any scalar - * type T to be supported. - * - * \sa Eigen::digamma() - */ -// * \warning Be careful with the order of the parameters: x.polygamma(n) is equivalent to polygamma(n,x) -// * \sa ArrayBase::polygamma() -template<typename DerivedN,typename DerivedX> -EIGEN_STRONG_INLINE const Eigen::CwiseBinaryOp<Eigen::internal::scalar_polygamma_op<typename DerivedX::Scalar>, const DerivedN, const DerivedX> -polygamma(const Eigen::ArrayBase<DerivedN>& n, const Eigen::ArrayBase<DerivedX>& x) -{ - return Eigen::CwiseBinaryOp<Eigen::internal::scalar_polygamma_op<typename DerivedX::Scalar>, const DerivedN, const DerivedX>( - n.derived(), - x.derived() - ); -} - -/** \cpp11 \returns an expression of the coefficient-wise betainc(\a x, \a a, \a b) to the given arrays. - * - * This function computes the regularized incomplete beta function (integral). - * - * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, - * or float/double in non c++11 mode, the user has to provide implementations of betainc(T,T,T) for any scalar - * type T to be supported. - * - * \sa Eigen::betainc(), Eigen::lgamma() - */ -template<typename ArgADerived, typename ArgBDerived, typename ArgXDerived> -EIGEN_STRONG_INLINE const Eigen::CwiseTernaryOp<Eigen::internal::scalar_betainc_op<typename ArgXDerived::Scalar>, const ArgADerived, const ArgBDerived, const ArgXDerived> -betainc(const Eigen::ArrayBase<ArgADerived>& a, const Eigen::ArrayBase<ArgBDerived>& b, const Eigen::ArrayBase<ArgXDerived>& x) -{ - return Eigen::CwiseTernaryOp<Eigen::internal::scalar_betainc_op<typename ArgXDerived::Scalar>, const ArgADerived, const ArgBDerived, const ArgXDerived>( - a.derived(), - b.derived(), - x.derived() - ); -} - - -/** \returns an expression of the coefficient-wise zeta(\a x, \a q) to the given arrays. - * - * It returns the Riemann zeta function of two arguments \a x and \a q: - * - * \param x is the exponent, it must be > 1 - * \param q is the shift, it must be > 0 - * - * \note This function supports only float and double scalar types. To support other scalar types, the user has - * to provide implementations of zeta(T,T) for any scalar type T to be supported. - * - * \sa ArrayBase::zeta() - */ -template<typename DerivedX,typename DerivedQ> -EIGEN_STRONG_INLINE const Eigen::CwiseBinaryOp<Eigen::internal::scalar_zeta_op<typename DerivedX::Scalar>, const DerivedX, const DerivedQ> -zeta(const Eigen::ArrayBase<DerivedX>& x, const Eigen::ArrayBase<DerivedQ>& q) -{ - return Eigen::CwiseBinaryOp<Eigen::internal::scalar_zeta_op<typename DerivedX::Scalar>, const DerivedX, const DerivedQ>( - x.derived(), - q.derived() - ); -} - - -} // end namespace Eigen - -#endif // EIGEN_SPECIALFUNCTIONS_ARRAYAPI_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsFunctors.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsFunctors.h deleted file mode 100644 index abefe99b..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsFunctors.h +++ /dev/null @@ -1,330 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com> -// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPECIALFUNCTIONS_FUNCTORS_H -#define EIGEN_SPECIALFUNCTIONS_FUNCTORS_H - -namespace Eigen { - -namespace internal { - - -/** \internal - * \brief Template functor to compute the incomplete gamma function igamma(a, x) - * - * \sa class CwiseBinaryOp, Cwise::igamma - */ -template<typename Scalar> struct scalar_igamma_op : binary_op_base<Scalar,Scalar> -{ - EIGEN_EMPTY_STRUCT_CTOR(scalar_igamma_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& x) const { - using numext::igamma; return igamma(a, x); - } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& x) const { - return internal::pigamma(a, x); - } -}; -template<typename Scalar> -struct functor_traits<scalar_igamma_op<Scalar> > { - enum { - // Guesstimate - Cost = 20 * NumTraits<Scalar>::MulCost + 10 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasIGamma - }; -}; - -/** \internal - * \brief Template functor to compute the derivative of the incomplete gamma - * function igamma_der_a(a, x) - * - * \sa class CwiseBinaryOp, Cwise::igamma_der_a - */ -template <typename Scalar> -struct scalar_igamma_der_a_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_igamma_der_a_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& a, const Scalar& x) const { - using numext::igamma_der_a; - return igamma_der_a(a, x); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& x) const { - return internal::pigamma_der_a(a, x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_igamma_der_a_op<Scalar> > { - enum { - // 2x the cost of igamma - Cost = 40 * NumTraits<Scalar>::MulCost + 20 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasIGammaDerA - }; -}; - -/** \internal - * \brief Template functor to compute the derivative of the sample - * of a Gamma(alpha, 1) random variable with respect to the parameter alpha - * gamma_sample_der_alpha(alpha, sample) - * - * \sa class CwiseBinaryOp, Cwise::gamma_sample_der_alpha - */ -template <typename Scalar> -struct scalar_gamma_sample_der_alpha_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_gamma_sample_der_alpha_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& alpha, const Scalar& sample) const { - using numext::gamma_sample_der_alpha; - return gamma_sample_der_alpha(alpha, sample); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& alpha, const Packet& sample) const { - return internal::pgamma_sample_der_alpha(alpha, sample); - } -}; -template <typename Scalar> -struct functor_traits<scalar_gamma_sample_der_alpha_op<Scalar> > { - enum { - // 2x the cost of igamma, minus the lgamma cost (the lgamma cancels out) - Cost = 30 * NumTraits<Scalar>::MulCost + 15 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasGammaSampleDerAlpha - }; -}; - -/** \internal - * \brief Template functor to compute the complementary incomplete gamma function igammac(a, x) - * - * \sa class CwiseBinaryOp, Cwise::igammac - */ -template<typename Scalar> struct scalar_igammac_op : binary_op_base<Scalar,Scalar> -{ - EIGEN_EMPTY_STRUCT_CTOR(scalar_igammac_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& x) const { - using numext::igammac; return igammac(a, x); - } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& x) const - { - return internal::pigammac(a, x); - } -}; -template<typename Scalar> -struct functor_traits<scalar_igammac_op<Scalar> > { - enum { - // Guesstimate - Cost = 20 * NumTraits<Scalar>::MulCost + 10 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasIGammac - }; -}; - - -/** \internal - * \brief Template functor to compute the incomplete beta integral betainc(a, b, x) - * - */ -template<typename Scalar> struct scalar_betainc_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_betainc_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& x, const Scalar& a, const Scalar& b) const { - using numext::betainc; return betainc(x, a, b); - } - template<typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& x, const Packet& a, const Packet& b) const - { - return internal::pbetainc(x, a, b); - } -}; -template<typename Scalar> -struct functor_traits<scalar_betainc_op<Scalar> > { - enum { - // Guesstimate - Cost = 400 * NumTraits<Scalar>::MulCost + 400 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasBetaInc - }; -}; - - -/** \internal - * \brief Template functor to compute the natural log of the absolute - * value of Gamma of a scalar - * \sa class CwiseUnaryOp, Cwise::lgamma() - */ -template<typename Scalar> struct scalar_lgamma_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_lgamma_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { - using numext::lgamma; return lgamma(a); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a) const { return internal::plgamma(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_lgamma_op<Scalar> > -{ - enum { - // Guesstimate - Cost = 10 * NumTraits<Scalar>::MulCost + 5 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasLGamma - }; -}; - -/** \internal - * \brief Template functor to compute psi, the derivative of lgamma of a scalar. - * \sa class CwiseUnaryOp, Cwise::digamma() - */ -template<typename Scalar> struct scalar_digamma_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_digamma_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { - using numext::digamma; return digamma(a); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a) const { return internal::pdigamma(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_digamma_op<Scalar> > -{ - enum { - // Guesstimate - Cost = 10 * NumTraits<Scalar>::MulCost + 5 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasDiGamma - }; -}; - -/** \internal - * \brief Template functor to compute the Riemann Zeta function of two arguments. - * \sa class CwiseUnaryOp, Cwise::zeta() - */ -template<typename Scalar> struct scalar_zeta_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_zeta_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& x, const Scalar& q) const { - using numext::zeta; return zeta(x, q); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x, const Packet& q) const { return internal::pzeta(x, q); } -}; -template<typename Scalar> -struct functor_traits<scalar_zeta_op<Scalar> > -{ - enum { - // Guesstimate - Cost = 10 * NumTraits<Scalar>::MulCost + 5 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasZeta - }; -}; - -/** \internal - * \brief Template functor to compute the polygamma function. - * \sa class CwiseUnaryOp, Cwise::polygamma() - */ -template<typename Scalar> struct scalar_polygamma_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_polygamma_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& n, const Scalar& x) const { - using numext::polygamma; return polygamma(n, x); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& n, const Packet& x) const { return internal::ppolygamma(n, x); } -}; -template<typename Scalar> -struct functor_traits<scalar_polygamma_op<Scalar> > -{ - enum { - // Guesstimate - Cost = 10 * NumTraits<Scalar>::MulCost + 5 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasPolygamma - }; -}; - -/** \internal - * \brief Template functor to compute the error function of a scalar - * \sa class CwiseUnaryOp, ArrayBase::erf() - */ -template<typename Scalar> struct scalar_erf_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_erf_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar - operator()(const Scalar& a) const { - return numext::erf(a); - } - template <typename Packet> - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const { - return perf(x); - } -}; -template <typename Scalar> -struct functor_traits<scalar_erf_op<Scalar> > { - enum { - PacketAccess = packet_traits<Scalar>::HasErf, - Cost = - (PacketAccess -#ifdef EIGEN_VECTORIZE_FMA - // TODO(rmlarsen): Move the FMA cost model to a central location. - // Haswell can issue 2 add/mul/madd per cycle. - // 10 pmadd, 2 pmul, 1 div, 2 other - ? (2 * NumTraits<Scalar>::AddCost + - 7 * NumTraits<Scalar>::MulCost + - scalar_div_cost<Scalar, packet_traits<Scalar>::HasDiv>::value) -#else - ? (12 * NumTraits<Scalar>::AddCost + - 12 * NumTraits<Scalar>::MulCost + - scalar_div_cost<Scalar, packet_traits<Scalar>::HasDiv>::value) -#endif - // Assume for simplicity that this is as expensive as an exp(). - : (functor_traits<scalar_exp_op<Scalar> >::Cost)) - }; -}; - -/** \internal - * \brief Template functor to compute the Complementary Error Function - * of a scalar - * \sa class CwiseUnaryOp, Cwise::erfc() - */ -template<typename Scalar> struct scalar_erfc_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_erfc_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { - using numext::erfc; return erfc(a); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a) const { return internal::perfc(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_erfc_op<Scalar> > -{ - enum { - // Guesstimate - Cost = 10 * NumTraits<Scalar>::MulCost + 5 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasErfc - }; -}; - -/** \internal - * \brief Template functor to compute the Inverse of the normal distribution - * function of a scalar - * \sa class CwiseUnaryOp, Cwise::ndtri() - */ -template<typename Scalar> struct scalar_ndtri_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_ndtri_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { - using numext::ndtri; return ndtri(a); - } - typedef typename packet_traits<Scalar>::type Packet; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a) const { return internal::pndtri(a); } -}; -template<typename Scalar> -struct functor_traits<scalar_ndtri_op<Scalar> > -{ - enum { - // On average, We are evaluating rational functions with degree N=9 in the - // numerator and denominator. This results in 2*N additions and 2*N - // multiplications. - Cost = 18 * NumTraits<Scalar>::MulCost + 18 * NumTraits<Scalar>::AddCost, - PacketAccess = packet_traits<Scalar>::HasNdtri - }; -}; - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPECIALFUNCTIONS_FUNCTORS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsHalf.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsHalf.h deleted file mode 100644 index 2a3a5316..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsHalf.h +++ /dev/null @@ -1,58 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPECIALFUNCTIONS_HALF_H -#define EIGEN_SPECIALFUNCTIONS_HALF_H - -namespace Eigen { -namespace numext { - -#if EIGEN_HAS_C99_MATH -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half lgamma(const Eigen::half& a) { - return Eigen::half(Eigen::numext::lgamma(static_cast<float>(a))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half digamma(const Eigen::half& a) { - return Eigen::half(Eigen::numext::digamma(static_cast<float>(a))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half zeta(const Eigen::half& x, const Eigen::half& q) { - return Eigen::half(Eigen::numext::zeta(static_cast<float>(x), static_cast<float>(q))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half polygamma(const Eigen::half& n, const Eigen::half& x) { - return Eigen::half(Eigen::numext::polygamma(static_cast<float>(n), static_cast<float>(x))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half erf(const Eigen::half& a) { - return Eigen::half(Eigen::numext::erf(static_cast<float>(a))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half erfc(const Eigen::half& a) { - return Eigen::half(Eigen::numext::erfc(static_cast<float>(a))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half ndtri(const Eigen::half& a) { - return Eigen::half(Eigen::numext::ndtri(static_cast<float>(a))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half igamma(const Eigen::half& a, const Eigen::half& x) { - return Eigen::half(Eigen::numext::igamma(static_cast<float>(a), static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half igamma_der_a(const Eigen::half& a, const Eigen::half& x) { - return Eigen::half(Eigen::numext::igamma_der_a(static_cast<float>(a), static_cast<float>(x))); -} -template <> -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half gamma_sample_der_alpha(const Eigen::half& alpha, const Eigen::half& sample) { - return Eigen::half(Eigen::numext::gamma_sample_der_alpha(static_cast<float>(alpha), static_cast<float>(sample))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half igammac(const Eigen::half& a, const Eigen::half& x) { - return Eigen::half(Eigen::numext::igammac(static_cast<float>(a), static_cast<float>(x))); -} -template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half betainc(const Eigen::half& a, const Eigen::half& b, const Eigen::half& x) { - return Eigen::half(Eigen::numext::betainc(static_cast<float>(a), static_cast<float>(b), static_cast<float>(x))); -} -#endif - -} // end namespace numext -} // end namespace Eigen - -#endif // EIGEN_SPECIALFUNCTIONS_HALF_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsImpl.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsImpl.h deleted file mode 100644 index 0044b8a2..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsImpl.h +++ /dev/null @@ -1,2025 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2015 Eugene Brevdo <ebrevdo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPECIAL_FUNCTIONS_H -#define EIGEN_SPECIAL_FUNCTIONS_H - -namespace Eigen { -namespace internal { - -// Parts of this code are based on the Cephes Math Library. -// -// Cephes Math Library Release 2.8: June, 2000 -// Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier -// -// Permission has been kindly provided by the original author -// to incorporate the Cephes software into the Eigen codebase: -// -// From: Stephen Moshier -// To: Eugene Brevdo -// Subject: Re: Permission to wrap several cephes functions in Eigen -// -// Hello Eugene, -// -// Thank you for writing. -// -// If your licensing is similar to BSD, the formal way that has been -// handled is simply to add a statement to the effect that you are incorporating -// the Cephes software by permission of the author. -// -// Good luck with your project, -// Steve - - -/**************************************************************************** - * Implementation of lgamma, requires C++11/C99 * - ****************************************************************************/ - -template <typename Scalar> -struct lgamma_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -template <typename Scalar> -struct lgamma_retval { - typedef Scalar type; -}; - -#if EIGEN_HAS_C99_MATH -template <> -struct lgamma_impl<float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE float run(float x) { -#if !defined(EIGEN_GPU_COMPILE_PHASE) && (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) && !defined(__APPLE__) - int dummy; - return ::lgammaf_r(x, &dummy); -#elif defined(SYCL_DEVICE_ONLY) - return cl::sycl::lgamma(x); -#else - return ::lgammaf(x); -#endif - } -}; - -template <> -struct lgamma_impl<double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE double run(double x) { -#if !defined(EIGEN_GPU_COMPILE_PHASE) && (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) && !defined(__APPLE__) - int dummy; - return ::lgamma_r(x, &dummy); -#elif defined(SYCL_DEVICE_ONLY) - return cl::sycl::lgamma(x); -#else - return ::lgamma(x); -#endif - } -}; -#endif - -/**************************************************************************** - * Implementation of digamma (psi), based on Cephes * - ****************************************************************************/ - -template <typename Scalar> -struct digamma_retval { - typedef Scalar type; -}; - -/* - * - * Polynomial evaluation helper for the Psi (digamma) function. - * - * digamma_impl_maybe_poly::run(s) evaluates the asymptotic Psi expansion for - * input Scalar s, assuming s is above 10.0. - * - * If s is above a certain threshold for the given Scalar type, zero - * is returned. Otherwise the polynomial is evaluated with enough - * coefficients for results matching Scalar machine precision. - * - * - */ -template <typename Scalar> -struct digamma_impl_maybe_poly { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - - -template <> -struct digamma_impl_maybe_poly<float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE float run(const float s) { - const float A[] = { - -4.16666666666666666667E-3f, - 3.96825396825396825397E-3f, - -8.33333333333333333333E-3f, - 8.33333333333333333333E-2f - }; - - float z; - if (s < 1.0e8f) { - z = 1.0f / (s * s); - return z * internal::ppolevl<float, 3>::run(z, A); - } else return 0.0f; - } -}; - -template <> -struct digamma_impl_maybe_poly<double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE double run(const double s) { - const double A[] = { - 8.33333333333333333333E-2, - -2.10927960927960927961E-2, - 7.57575757575757575758E-3, - -4.16666666666666666667E-3, - 3.96825396825396825397E-3, - -8.33333333333333333333E-3, - 8.33333333333333333333E-2 - }; - - double z; - if (s < 1.0e17) { - z = 1.0 / (s * s); - return z * internal::ppolevl<double, 6>::run(z, A); - } - else return 0.0; - } -}; - -template <typename Scalar> -struct digamma_impl { - EIGEN_DEVICE_FUNC - static Scalar run(Scalar x) { - /* - * - * Psi (digamma) function (modified for Eigen) - * - * - * SYNOPSIS: - * - * double x, y, psi(); - * - * y = psi( x ); - * - * - * DESCRIPTION: - * - * d - - * psi(x) = -- ln | (x) - * dx - * - * is the logarithmic derivative of the gamma function. - * For integer x, - * n-1 - * - - * psi(n) = -EUL + > 1/k. - * - - * k=1 - * - * If x is negative, it is transformed to a positive argument by the - * reflection formula psi(1-x) = psi(x) + pi cot(pi x). - * For general positive x, the argument is made greater than 10 - * using the recurrence psi(x+1) = psi(x) + 1/x. - * Then the following asymptotic expansion is applied: - * - * inf. B - * - 2k - * psi(x) = log(x) - 1/2x - > ------- - * - 2k - * k=1 2k x - * - * where the B2k are Bernoulli numbers. - * - * ACCURACY (float): - * Relative error (except absolute when |psi| < 1): - * arithmetic domain # trials peak rms - * IEEE 0,30 30000 1.3e-15 1.4e-16 - * IEEE -30,0 40000 1.5e-15 2.2e-16 - * - * ACCURACY (double): - * Absolute error, relative when |psi| > 1 : - * arithmetic domain # trials peak rms - * IEEE -33,0 30000 8.2e-7 1.2e-7 - * IEEE 0,33 100000 7.3e-7 7.7e-8 - * - * ERROR MESSAGES: - * message condition value returned - * psi singularity x integer <=0 INFINITY - */ - - Scalar p, q, nz, s, w, y; - bool negative = false; - - const Scalar maxnum = NumTraits<Scalar>::infinity(); - const Scalar m_pi = Scalar(EIGEN_PI); - - const Scalar zero = Scalar(0); - const Scalar one = Scalar(1); - const Scalar half = Scalar(0.5); - nz = zero; - - if (x <= zero) { - negative = true; - q = x; - p = numext::floor(q); - if (p == q) { - return maxnum; - } - /* Remove the zeros of tan(m_pi x) - * by subtracting the nearest integer from x - */ - nz = q - p; - if (nz != half) { - if (nz > half) { - p += one; - nz = q - p; - } - nz = m_pi / numext::tan(m_pi * nz); - } - else { - nz = zero; - } - x = one - x; - } - - /* use the recurrence psi(x+1) = psi(x) + 1/x. */ - s = x; - w = zero; - while (s < Scalar(10)) { - w += one / s; - s += one; - } - - y = digamma_impl_maybe_poly<Scalar>::run(s); - - y = numext::log(s) - (half / s) - y - w; - - return (negative) ? y - nz : y; - } -}; - -/**************************************************************************** - * Implementation of erf, requires C++11/C99 * - ****************************************************************************/ - -/** \internal \returns the error function of \a a (coeff-wise) - Doesn't do anything fancy, just a 13/8-degree rational interpolant which - is accurate up to a couple of ulp in the range [-4, 4], outside of which - fl(erf(x)) = +/-1. - - This implementation works on both scalars and Ts. -*/ -template <typename T> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T generic_fast_erf_float(const T& a_x) { - // Clamp the inputs to the range [-4, 4] since anything outside - // this range is +/-1.0f in single-precision. - const T plus_4 = pset1<T>(4.f); - const T minus_4 = pset1<T>(-4.f); - const T x = pmax(pmin(a_x, plus_4), minus_4); - // The monomial coefficients of the numerator polynomial (odd). - const T alpha_1 = pset1<T>(-1.60960333262415e-02f); - const T alpha_3 = pset1<T>(-2.95459980854025e-03f); - const T alpha_5 = pset1<T>(-7.34990630326855e-04f); - const T alpha_7 = pset1<T>(-5.69250639462346e-05f); - const T alpha_9 = pset1<T>(-2.10102402082508e-06f); - const T alpha_11 = pset1<T>(2.77068142495902e-08f); - const T alpha_13 = pset1<T>(-2.72614225801306e-10f); - - // The monomial coefficients of the denominator polynomial (even). - const T beta_0 = pset1<T>(-1.42647390514189e-02f); - const T beta_2 = pset1<T>(-7.37332916720468e-03f); - const T beta_4 = pset1<T>(-1.68282697438203e-03f); - const T beta_6 = pset1<T>(-2.13374055278905e-04f); - const T beta_8 = pset1<T>(-1.45660718464996e-05f); - - // Since the polynomials are odd/even, we need x^2. - const T x2 = pmul(x, x); - - // Evaluate the numerator polynomial p. - T p = pmadd(x2, alpha_13, alpha_11); - p = pmadd(x2, p, alpha_9); - p = pmadd(x2, p, alpha_7); - p = pmadd(x2, p, alpha_5); - p = pmadd(x2, p, alpha_3); - p = pmadd(x2, p, alpha_1); - p = pmul(x, p); - - // Evaluate the denominator polynomial p. - T q = pmadd(x2, beta_8, beta_6); - q = pmadd(x2, q, beta_4); - q = pmadd(x2, q, beta_2); - q = pmadd(x2, q, beta_0); - - // Divide the numerator by the denominator. - return pdiv(p, q); -} - -template <typename T> -struct erf_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE T run(const T x) { - return generic_fast_erf_float(x); - } -}; - -template <typename Scalar> -struct erf_retval { - typedef Scalar type; -}; - -#if EIGEN_HAS_C99_MATH -template <> -struct erf_impl<float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE float run(float x) { -#if defined(SYCL_DEVICE_ONLY) - return cl::sycl::erf(x); -#else - return generic_fast_erf_float(x); -#endif - } -}; - -template <> -struct erf_impl<double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE double run(double x) { -#if defined(SYCL_DEVICE_ONLY) - return cl::sycl::erf(x); -#else - return ::erf(x); -#endif - } -}; -#endif // EIGEN_HAS_C99_MATH - -/*************************************************************************** -* Implementation of erfc, requires C++11/C99 * -****************************************************************************/ - -template <typename Scalar> -struct erfc_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -template <typename Scalar> -struct erfc_retval { - typedef Scalar type; -}; - -#if EIGEN_HAS_C99_MATH -template <> -struct erfc_impl<float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE float run(const float x) { -#if defined(SYCL_DEVICE_ONLY) - return cl::sycl::erfc(x); -#else - return ::erfcf(x); -#endif - } -}; - -template <> -struct erfc_impl<double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE double run(const double x) { -#if defined(SYCL_DEVICE_ONLY) - return cl::sycl::erfc(x); -#else - return ::erfc(x); -#endif - } -}; -#endif // EIGEN_HAS_C99_MATH - - -/*************************************************************************** -* Implementation of ndtri. * -****************************************************************************/ - -/* Inverse of Normal distribution function (modified for Eigen). - * - * - * SYNOPSIS: - * - * double x, y, ndtri(); - * - * x = ndtri( y ); - * - * - * - * DESCRIPTION: - * - * Returns the argument, x, for which the area under the - * Gaussian probability density function (integrated from - * minus infinity to x) is equal to y. - * - * - * For small arguments 0 < y < exp(-2), the program computes - * z = sqrt( -2.0 * log(y) ); then the approximation is - * x = z - log(z)/z - (1/z) P(1/z) / Q(1/z). - * There are two rational functions P/Q, one for 0 < y < exp(-32) - * and the other for y up to exp(-2). For larger arguments, - * w = y - 0.5, and x/sqrt(2pi) = w + w**3 R(w**2)/S(w**2)). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * DEC 0.125, 1 5500 9.5e-17 2.1e-17 - * DEC 6e-39, 0.135 3500 5.7e-17 1.3e-17 - * IEEE 0.125, 1 20000 7.2e-16 1.3e-16 - * IEEE 3e-308, 0.135 50000 4.6e-16 9.8e-17 - * - * - * ERROR MESSAGES: - * - * message condition value returned - * ndtri domain x <= 0 -MAXNUM - * ndtri domain x >= 1 MAXNUM - * - */ - /* - Cephes Math Library Release 2.2: June, 1992 - Copyright 1985, 1987, 1992 by Stephen L. Moshier - Direct inquiries to 30 Frost Street, Cambridge, MA 02140 - */ - - -// TODO: Add a cheaper approximation for float. - - -template<typename T> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T flipsign( - const T& should_flipsign, const T& x) { - const T sign_mask = pset1<T>(-0.0); - T sign_bit = pand<T>(should_flipsign, sign_mask); - return pxor<T>(sign_bit, x); -} - -template<> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double flipsign<double>( - const double& should_flipsign, const double& x) { - return should_flipsign == 0 ? x : -x; -} - -template<> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float flipsign<float>( - const float& should_flipsign, const float& x) { - return should_flipsign == 0 ? x : -x; -} - -// We split this computation in to two so that in the scalar path -// only one branch is evaluated (due to our template specialization of pselect -// being an if statement.) - -template <typename T, typename ScalarType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T generic_ndtri_gt_exp_neg_two(const T& b) { - const ScalarType p0[] = { - ScalarType(-5.99633501014107895267e1), - ScalarType(9.80010754185999661536e1), - ScalarType(-5.66762857469070293439e1), - ScalarType(1.39312609387279679503e1), - ScalarType(-1.23916583867381258016e0) - }; - const ScalarType q0[] = { - ScalarType(1.0), - ScalarType(1.95448858338141759834e0), - ScalarType(4.67627912898881538453e0), - ScalarType(8.63602421390890590575e1), - ScalarType(-2.25462687854119370527e2), - ScalarType(2.00260212380060660359e2), - ScalarType(-8.20372256168333339912e1), - ScalarType(1.59056225126211695515e1), - ScalarType(-1.18331621121330003142e0) - }; - const T sqrt2pi = pset1<T>(ScalarType(2.50662827463100050242e0)); - const T half = pset1<T>(ScalarType(0.5)); - T c, c2, ndtri_gt_exp_neg_two; - - c = psub(b, half); - c2 = pmul(c, c); - ndtri_gt_exp_neg_two = pmadd(c, pmul( - c2, pdiv( - internal::ppolevl<T, 4>::run(c2, p0), - internal::ppolevl<T, 8>::run(c2, q0))), c); - return pmul(ndtri_gt_exp_neg_two, sqrt2pi); -} - -template <typename T, typename ScalarType> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T generic_ndtri_lt_exp_neg_two( - const T& b, const T& should_flipsign) { - /* Approximation for interval z = sqrt(-2 log a ) between 2 and 8 - * i.e., a between exp(-2) = .135 and exp(-32) = 1.27e-14. - */ - const ScalarType p1[] = { - ScalarType(4.05544892305962419923e0), - ScalarType(3.15251094599893866154e1), - ScalarType(5.71628192246421288162e1), - ScalarType(4.40805073893200834700e1), - ScalarType(1.46849561928858024014e1), - ScalarType(2.18663306850790267539e0), - ScalarType(-1.40256079171354495875e-1), - ScalarType(-3.50424626827848203418e-2), - ScalarType(-8.57456785154685413611e-4) - }; - const ScalarType q1[] = { - ScalarType(1.0), - ScalarType(1.57799883256466749731e1), - ScalarType(4.53907635128879210584e1), - ScalarType(4.13172038254672030440e1), - ScalarType(1.50425385692907503408e1), - ScalarType(2.50464946208309415979e0), - ScalarType(-1.42182922854787788574e-1), - ScalarType(-3.80806407691578277194e-2), - ScalarType(-9.33259480895457427372e-4) - }; - /* Approximation for interval z = sqrt(-2 log a ) between 8 and 64 - * i.e., a between exp(-32) = 1.27e-14 and exp(-2048) = 3.67e-890. - */ - const ScalarType p2[] = { - ScalarType(3.23774891776946035970e0), - ScalarType(6.91522889068984211695e0), - ScalarType(3.93881025292474443415e0), - ScalarType(1.33303460815807542389e0), - ScalarType(2.01485389549179081538e-1), - ScalarType(1.23716634817820021358e-2), - ScalarType(3.01581553508235416007e-4), - ScalarType(2.65806974686737550832e-6), - ScalarType(6.23974539184983293730e-9) - }; - const ScalarType q2[] = { - ScalarType(1.0), - ScalarType(6.02427039364742014255e0), - ScalarType(3.67983563856160859403e0), - ScalarType(1.37702099489081330271e0), - ScalarType(2.16236993594496635890e-1), - ScalarType(1.34204006088543189037e-2), - ScalarType(3.28014464682127739104e-4), - ScalarType(2.89247864745380683936e-6), - ScalarType(6.79019408009981274425e-9) - }; - const T eight = pset1<T>(ScalarType(8.0)); - const T one = pset1<T>(ScalarType(1)); - const T neg_two = pset1<T>(ScalarType(-2)); - T x, x0, x1, z; - - x = psqrt(pmul(neg_two, plog(b))); - x0 = psub(x, pdiv(plog(x), x)); - z = pdiv(one, x); - x1 = pmul( - z, pselect( - pcmp_lt(x, eight), - pdiv(internal::ppolevl<T, 8>::run(z, p1), - internal::ppolevl<T, 8>::run(z, q1)), - pdiv(internal::ppolevl<T, 8>::run(z, p2), - internal::ppolevl<T, 8>::run(z, q2)))); - return flipsign(should_flipsign, psub(x0, x1)); -} - -template <typename T, typename ScalarType> -EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -T generic_ndtri(const T& a) { - const T maxnum = pset1<T>(NumTraits<ScalarType>::infinity()); - const T neg_maxnum = pset1<T>(-NumTraits<ScalarType>::infinity()); - - const T zero = pset1<T>(ScalarType(0)); - const T one = pset1<T>(ScalarType(1)); - // exp(-2) - const T exp_neg_two = pset1<T>(ScalarType(0.13533528323661269189)); - T b, ndtri, should_flipsign; - - should_flipsign = pcmp_le(a, psub(one, exp_neg_two)); - b = pselect(should_flipsign, a, psub(one, a)); - - ndtri = pselect( - pcmp_lt(exp_neg_two, b), - generic_ndtri_gt_exp_neg_two<T, ScalarType>(b), - generic_ndtri_lt_exp_neg_two<T, ScalarType>(b, should_flipsign)); - - return pselect( - pcmp_le(a, zero), neg_maxnum, - pselect(pcmp_le(one, a), maxnum, ndtri)); -} - -template <typename Scalar> -struct ndtri_retval { - typedef Scalar type; -}; - -#if !EIGEN_HAS_C99_MATH - -template <typename Scalar> -struct ndtri_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -# else - -template <typename Scalar> -struct ndtri_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar x) { - return generic_ndtri<Scalar, Scalar>(x); - } -}; - -#endif // EIGEN_HAS_C99_MATH - - -/************************************************************************************************************** - * Implementation of igammac (complemented incomplete gamma integral), based on Cephes but requires C++11/C99 * - **************************************************************************************************************/ - -template <typename Scalar> -struct igammac_retval { - typedef Scalar type; -}; - -// NOTE: cephes_helper is also used to implement zeta -template <typename Scalar> -struct cephes_helper { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar machep() { assert(false && "machep not supported for this type"); return 0.0; } - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar big() { assert(false && "big not supported for this type"); return 0.0; } - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar biginv() { assert(false && "biginv not supported for this type"); return 0.0; } -}; - -template <> -struct cephes_helper<float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE float machep() { - return NumTraits<float>::epsilon() / 2; // 1.0 - machep == 1.0 - } - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE float big() { - // use epsneg (1.0 - epsneg == 1.0) - return 1.0f / (NumTraits<float>::epsilon() / 2); - } - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE float biginv() { - // epsneg - return machep(); - } -}; - -template <> -struct cephes_helper<double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE double machep() { - return NumTraits<double>::epsilon() / 2; // 1.0 - machep == 1.0 - } - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE double big() { - return 1.0 / NumTraits<double>::epsilon(); - } - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE double biginv() { - // inverse of eps - return NumTraits<double>::epsilon(); - } -}; - -enum IgammaComputationMode { VALUE, DERIVATIVE, SAMPLE_DERIVATIVE }; - -template <typename Scalar> -EIGEN_DEVICE_FUNC -static EIGEN_STRONG_INLINE Scalar main_igamma_term(Scalar a, Scalar x) { - /* Compute x**a * exp(-x) / gamma(a) */ - Scalar logax = a * numext::log(x) - x - lgamma_impl<Scalar>::run(a); - if (logax < -numext::log(NumTraits<Scalar>::highest()) || - // Assuming x and a aren't Nan. - (numext::isnan)(logax)) { - return Scalar(0); - } - return numext::exp(logax); -} - -template <typename Scalar, IgammaComputationMode mode> -EIGEN_DEVICE_FUNC -int igamma_num_iterations() { - /* Returns the maximum number of internal iterations for igamma computation. - */ - if (mode == VALUE) { - return 2000; - } - - if (internal::is_same<Scalar, float>::value) { - return 200; - } else if (internal::is_same<Scalar, double>::value) { - return 500; - } else { - return 2000; - } -} - -template <typename Scalar, IgammaComputationMode mode> -struct igammac_cf_impl { - /* Computes igamc(a, x) or derivative (depending on the mode) - * using the continued fraction expansion of the complementary - * incomplete Gamma function. - * - * Preconditions: - * a > 0 - * x >= 1 - * x >= a - */ - EIGEN_DEVICE_FUNC - static Scalar run(Scalar a, Scalar x) { - const Scalar zero = 0; - const Scalar one = 1; - const Scalar two = 2; - const Scalar machep = cephes_helper<Scalar>::machep(); - const Scalar big = cephes_helper<Scalar>::big(); - const Scalar biginv = cephes_helper<Scalar>::biginv(); - - if ((numext::isinf)(x)) { - return zero; - } - - Scalar ax = main_igamma_term<Scalar>(a, x); - // This is independent of mode. If this value is zero, - // then the function value is zero. If the function value is zero, - // then we are in a neighborhood where the function value evalutes to zero, - // so the derivative is zero. - if (ax == zero) { - return zero; - } - - // continued fraction - Scalar y = one - a; - Scalar z = x + y + one; - Scalar c = zero; - Scalar pkm2 = one; - Scalar qkm2 = x; - Scalar pkm1 = x + one; - Scalar qkm1 = z * x; - Scalar ans = pkm1 / qkm1; - - Scalar dpkm2_da = zero; - Scalar dqkm2_da = zero; - Scalar dpkm1_da = zero; - Scalar dqkm1_da = -x; - Scalar dans_da = (dpkm1_da - ans * dqkm1_da) / qkm1; - - for (int i = 0; i < igamma_num_iterations<Scalar, mode>(); i++) { - c += one; - y += one; - z += two; - - Scalar yc = y * c; - Scalar pk = pkm1 * z - pkm2 * yc; - Scalar qk = qkm1 * z - qkm2 * yc; - - Scalar dpk_da = dpkm1_da * z - pkm1 - dpkm2_da * yc + pkm2 * c; - Scalar dqk_da = dqkm1_da * z - qkm1 - dqkm2_da * yc + qkm2 * c; - - if (qk != zero) { - Scalar ans_prev = ans; - ans = pk / qk; - - Scalar dans_da_prev = dans_da; - dans_da = (dpk_da - ans * dqk_da) / qk; - - if (mode == VALUE) { - if (numext::abs(ans_prev - ans) <= machep * numext::abs(ans)) { - break; - } - } else { - if (numext::abs(dans_da - dans_da_prev) <= machep) { - break; - } - } - } - - pkm2 = pkm1; - pkm1 = pk; - qkm2 = qkm1; - qkm1 = qk; - - dpkm2_da = dpkm1_da; - dpkm1_da = dpk_da; - dqkm2_da = dqkm1_da; - dqkm1_da = dqk_da; - - if (numext::abs(pk) > big) { - pkm2 *= biginv; - pkm1 *= biginv; - qkm2 *= biginv; - qkm1 *= biginv; - - dpkm2_da *= biginv; - dpkm1_da *= biginv; - dqkm2_da *= biginv; - dqkm1_da *= biginv; - } - } - - /* Compute x**a * exp(-x) / gamma(a) */ - Scalar dlogax_da = numext::log(x) - digamma_impl<Scalar>::run(a); - Scalar dax_da = ax * dlogax_da; - - switch (mode) { - case VALUE: - return ans * ax; - case DERIVATIVE: - return ans * dax_da + dans_da * ax; - case SAMPLE_DERIVATIVE: - default: // this is needed to suppress clang warning - return -(dans_da + ans * dlogax_da) * x; - } - } -}; - -template <typename Scalar, IgammaComputationMode mode> -struct igamma_series_impl { - /* Computes igam(a, x) or its derivative (depending on the mode) - * using the series expansion of the incomplete Gamma function. - * - * Preconditions: - * x > 0 - * a > 0 - * !(x > 1 && x > a) - */ - EIGEN_DEVICE_FUNC - static Scalar run(Scalar a, Scalar x) { - const Scalar zero = 0; - const Scalar one = 1; - const Scalar machep = cephes_helper<Scalar>::machep(); - - Scalar ax = main_igamma_term<Scalar>(a, x); - - // This is independent of mode. If this value is zero, - // then the function value is zero. If the function value is zero, - // then we are in a neighborhood where the function value evalutes to zero, - // so the derivative is zero. - if (ax == zero) { - return zero; - } - - ax /= a; - - /* power series */ - Scalar r = a; - Scalar c = one; - Scalar ans = one; - - Scalar dc_da = zero; - Scalar dans_da = zero; - - for (int i = 0; i < igamma_num_iterations<Scalar, mode>(); i++) { - r += one; - Scalar term = x / r; - Scalar dterm_da = -x / (r * r); - dc_da = term * dc_da + dterm_da * c; - dans_da += dc_da; - c *= term; - ans += c; - - if (mode == VALUE) { - if (c <= machep * ans) { - break; - } - } else { - if (numext::abs(dc_da) <= machep * numext::abs(dans_da)) { - break; - } - } - } - - Scalar dlogax_da = numext::log(x) - digamma_impl<Scalar>::run(a + one); - Scalar dax_da = ax * dlogax_da; - - switch (mode) { - case VALUE: - return ans * ax; - case DERIVATIVE: - return ans * dax_da + dans_da * ax; - case SAMPLE_DERIVATIVE: - default: // this is needed to suppress clang warning - return -(dans_da + ans * dlogax_da) * x / a; - } - } -}; - -#if !EIGEN_HAS_C99_MATH - -template <typename Scalar> -struct igammac_impl { - EIGEN_DEVICE_FUNC - static Scalar run(Scalar a, Scalar x) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -#else - -template <typename Scalar> -struct igammac_impl { - EIGEN_DEVICE_FUNC - static Scalar run(Scalar a, Scalar x) { - /* igamc() - * - * Incomplete gamma integral (modified for Eigen) - * - * - * - * SYNOPSIS: - * - * double a, x, y, igamc(); - * - * y = igamc( a, x ); - * - * DESCRIPTION: - * - * The function is defined by - * - * - * igamc(a,x) = 1 - igam(a,x) - * - * inf. - * - - * 1 | | -t a-1 - * = ----- | e t dt. - * - | | - * | (a) - - * x - * - * - * In this implementation both arguments must be positive. - * The integral is evaluated by either a power series or - * continued fraction expansion, depending on the relative - * values of a and x. - * - * ACCURACY (float): - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0,30 30000 7.8e-6 5.9e-7 - * - * - * ACCURACY (double): - * - * Tested at random a, x. - * a x Relative error: - * arithmetic domain domain # trials peak rms - * IEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15 - * IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15 - * - */ - /* - Cephes Math Library Release 2.2: June, 1992 - Copyright 1985, 1987, 1992 by Stephen L. Moshier - Direct inquiries to 30 Frost Street, Cambridge, MA 02140 - */ - const Scalar zero = 0; - const Scalar one = 1; - const Scalar nan = NumTraits<Scalar>::quiet_NaN(); - - if ((x < zero) || (a <= zero)) { - // domain error - return nan; - } - - if ((numext::isnan)(a) || (numext::isnan)(x)) { // propagate nans - return nan; - } - - if ((x < one) || (x < a)) { - return (one - igamma_series_impl<Scalar, VALUE>::run(a, x)); - } - - return igammac_cf_impl<Scalar, VALUE>::run(a, x); - } -}; - -#endif // EIGEN_HAS_C99_MATH - -/************************************************************************************************ - * Implementation of igamma (incomplete gamma integral), based on Cephes but requires C++11/C99 * - ************************************************************************************************/ - -#if !EIGEN_HAS_C99_MATH - -template <typename Scalar, IgammaComputationMode mode> -struct igamma_generic_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(Scalar a, Scalar x) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -#else - -template <typename Scalar, IgammaComputationMode mode> -struct igamma_generic_impl { - EIGEN_DEVICE_FUNC - static Scalar run(Scalar a, Scalar x) { - /* Depending on the mode, returns - * - VALUE: incomplete Gamma function igamma(a, x) - * - DERIVATIVE: derivative of incomplete Gamma function d/da igamma(a, x) - * - SAMPLE_DERIVATIVE: implicit derivative of a Gamma random variable - * x ~ Gamma(x | a, 1), dx/da = -1 / Gamma(x | a, 1) * d igamma(a, x) / dx - * - * Derivatives are implemented by forward-mode differentiation. - */ - const Scalar zero = 0; - const Scalar one = 1; - const Scalar nan = NumTraits<Scalar>::quiet_NaN(); - - if (x == zero) return zero; - - if ((x < zero) || (a <= zero)) { // domain error - return nan; - } - - if ((numext::isnan)(a) || (numext::isnan)(x)) { // propagate nans - return nan; - } - - if ((x > one) && (x > a)) { - Scalar ret = igammac_cf_impl<Scalar, mode>::run(a, x); - if (mode == VALUE) { - return one - ret; - } else { - return -ret; - } - } - - return igamma_series_impl<Scalar, mode>::run(a, x); - } -}; - -#endif // EIGEN_HAS_C99_MATH - -template <typename Scalar> -struct igamma_retval { - typedef Scalar type; -}; - -template <typename Scalar> -struct igamma_impl : igamma_generic_impl<Scalar, VALUE> { - /* igam() - * Incomplete gamma integral. - * - * The CDF of Gamma(a, 1) random variable at the point x. - * - * Accuracy estimation. For each a in [10^-2, 10^-1...10^3] we sample - * 50 Gamma random variables x ~ Gamma(x | a, 1), a total of 300 points. - * The ground truth is computed by mpmath. Mean absolute error: - * float: 1.26713e-05 - * double: 2.33606e-12 - * - * Cephes documentation below. - * - * SYNOPSIS: - * - * double a, x, y, igam(); - * - * y = igam( a, x ); - * - * DESCRIPTION: - * - * The function is defined by - * - * x - * - - * 1 | | -t a-1 - * igam(a,x) = ----- | e t dt. - * - | | - * | (a) - - * 0 - * - * - * In this implementation both arguments must be positive. - * The integral is evaluated by either a power series or - * continued fraction expansion, depending on the relative - * values of a and x. - * - * ACCURACY (double): - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0,30 200000 3.6e-14 2.9e-15 - * IEEE 0,100 300000 9.9e-14 1.5e-14 - * - * - * ACCURACY (float): - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0,30 20000 7.8e-6 5.9e-7 - * - */ - /* - Cephes Math Library Release 2.2: June, 1992 - Copyright 1985, 1987, 1992 by Stephen L. Moshier - Direct inquiries to 30 Frost Street, Cambridge, MA 02140 - */ - - /* left tail of incomplete gamma function: - * - * inf. k - * a -x - x - * x e > ---------- - * - - - * k=0 | (a+k+1) - * - */ -}; - -template <typename Scalar> -struct igamma_der_a_retval : igamma_retval<Scalar> {}; - -template <typename Scalar> -struct igamma_der_a_impl : igamma_generic_impl<Scalar, DERIVATIVE> { - /* Derivative of the incomplete Gamma function with respect to a. - * - * Computes d/da igamma(a, x) by forward differentiation of the igamma code. - * - * Accuracy estimation. For each a in [10^-2, 10^-1...10^3] we sample - * 50 Gamma random variables x ~ Gamma(x | a, 1), a total of 300 points. - * The ground truth is computed by mpmath. Mean absolute error: - * float: 6.17992e-07 - * double: 4.60453e-12 - * - * Reference: - * R. Moore. "Algorithm AS 187: Derivatives of the incomplete gamma - * integral". Journal of the Royal Statistical Society. 1982 - */ -}; - -template <typename Scalar> -struct gamma_sample_der_alpha_retval : igamma_retval<Scalar> {}; - -template <typename Scalar> -struct gamma_sample_der_alpha_impl - : igamma_generic_impl<Scalar, SAMPLE_DERIVATIVE> { - /* Derivative of a Gamma random variable sample with respect to alpha. - * - * Consider a sample of a Gamma random variable with the concentration - * parameter alpha: sample ~ Gamma(alpha, 1). The reparameterization - * derivative that we want to compute is dsample / dalpha = - * d igammainv(alpha, u) / dalpha, where u = igamma(alpha, sample). - * However, this formula is numerically unstable and expensive, so instead - * we use implicit differentiation: - * - * igamma(alpha, sample) = u, where u ~ Uniform(0, 1). - * Apply d / dalpha to both sides: - * d igamma(alpha, sample) / dalpha - * + d igamma(alpha, sample) / dsample * dsample/dalpha = 0 - * d igamma(alpha, sample) / dalpha - * + Gamma(sample | alpha, 1) dsample / dalpha = 0 - * dsample/dalpha = - (d igamma(alpha, sample) / dalpha) - * / Gamma(sample | alpha, 1) - * - * Here Gamma(sample | alpha, 1) is the PDF of the Gamma distribution - * (note that the derivative of the CDF w.r.t. sample is the PDF). - * See the reference below for more details. - * - * The derivative of igamma(alpha, sample) is computed by forward - * differentiation of the igamma code. Division by the Gamma PDF is performed - * in the same code, increasing the accuracy and speed due to cancellation - * of some terms. - * - * Accuracy estimation. For each alpha in [10^-2, 10^-1...10^3] we sample - * 50 Gamma random variables sample ~ Gamma(sample | alpha, 1), a total of 300 - * points. The ground truth is computed by mpmath. Mean absolute error: - * float: 2.1686e-06 - * double: 1.4774e-12 - * - * Reference: - * M. Figurnov, S. Mohamed, A. Mnih "Implicit Reparameterization Gradients". - * 2018 - */ -}; - -/***************************************************************************** - * Implementation of Riemann zeta function of two arguments, based on Cephes * - *****************************************************************************/ - -template <typename Scalar> -struct zeta_retval { - typedef Scalar type; -}; - -template <typename Scalar> -struct zeta_impl_series { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(const Scalar) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -template <> -struct zeta_impl_series<float> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE bool run(float& a, float& b, float& s, const float x, const float machep) { - int i = 0; - while(i < 9) - { - i += 1; - a += 1.0f; - b = numext::pow( a, -x ); - s += b; - if( numext::abs(b/s) < machep ) - return true; - } - - //Return whether we are done - return false; - } -}; - -template <> -struct zeta_impl_series<double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE bool run(double& a, double& b, double& s, const double x, const double machep) { - int i = 0; - while( (i < 9) || (a <= 9.0) ) - { - i += 1; - a += 1.0; - b = numext::pow( a, -x ); - s += b; - if( numext::abs(b/s) < machep ) - return true; - } - - //Return whether we are done - return false; - } -}; - -template <typename Scalar> -struct zeta_impl { - EIGEN_DEVICE_FUNC - static Scalar run(Scalar x, Scalar q) { - /* zeta.c - * - * Riemann zeta function of two arguments - * - * - * - * SYNOPSIS: - * - * double x, q, y, zeta(); - * - * y = zeta( x, q ); - * - * - * - * DESCRIPTION: - * - * - * - * inf. - * - -x - * zeta(x,q) = > (k+q) - * - - * k=0 - * - * where x > 1 and q is not a negative integer or zero. - * The Euler-Maclaurin summation formula is used to obtain - * the expansion - * - * n - * - -x - * zeta(x,q) = > (k+q) - * - - * k=1 - * - * 1-x inf. B x(x+1)...(x+2j) - * (n+q) 1 - 2j - * + --------- - ------- + > -------------------- - * x-1 x - x+2j+1 - * 2(n+q) j=1 (2j)! (n+q) - * - * where the B2j are Bernoulli numbers. Note that (see zetac.c) - * zeta(x,1) = zetac(x) + 1. - * - * - * - * ACCURACY: - * - * Relative error for single precision: - * arithmetic domain # trials peak rms - * IEEE 0,25 10000 6.9e-7 1.0e-7 - * - * Large arguments may produce underflow in powf(), in which - * case the results are inaccurate. - * - * REFERENCE: - * - * Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals, - * Series, and Products, p. 1073; Academic Press, 1980. - * - */ - - int i; - Scalar p, r, a, b, k, s, t, w; - - const Scalar A[] = { - Scalar(12.0), - Scalar(-720.0), - Scalar(30240.0), - Scalar(-1209600.0), - Scalar(47900160.0), - Scalar(-1.8924375803183791606e9), /*1.307674368e12/691*/ - Scalar(7.47242496e10), - Scalar(-2.950130727918164224e12), /*1.067062284288e16/3617*/ - Scalar(1.1646782814350067249e14), /*5.109094217170944e18/43867*/ - Scalar(-4.5979787224074726105e15), /*8.028576626982912e20/174611*/ - Scalar(1.8152105401943546773e17), /*1.5511210043330985984e23/854513*/ - Scalar(-7.1661652561756670113e18) /*1.6938241367317436694528e27/236364091*/ - }; - - const Scalar maxnum = NumTraits<Scalar>::infinity(); - const Scalar zero = 0.0, half = 0.5, one = 1.0; - const Scalar machep = cephes_helper<Scalar>::machep(); - const Scalar nan = NumTraits<Scalar>::quiet_NaN(); - - if( x == one ) - return maxnum; - - if( x < one ) - { - return nan; - } - - if( q <= zero ) - { - if(q == numext::floor(q)) - { - return maxnum; - } - p = x; - r = numext::floor(p); - if (p != r) - return nan; - } - - /* Permit negative q but continue sum until n+q > +9 . - * This case should be handled by a reflection formula. - * If q<0 and x is an integer, there is a relation to - * the polygamma function. - */ - s = numext::pow( q, -x ); - a = q; - b = zero; - // Run the summation in a helper function that is specific to the floating precision - if (zeta_impl_series<Scalar>::run(a, b, s, x, machep)) { - return s; - } - - w = a; - s += b*w/(x-one); - s -= half * b; - a = one; - k = zero; - for( i=0; i<12; i++ ) - { - a *= x + k; - b /= w; - t = a*b/A[i]; - s = s + t; - t = numext::abs(t/s); - if( t < machep ) { - break; - } - k += one; - a *= x + k; - b /= w; - k += one; - } - return s; - } -}; - -/**************************************************************************** - * Implementation of polygamma function, requires C++11/C99 * - ****************************************************************************/ - -template <typename Scalar> -struct polygamma_retval { - typedef Scalar type; -}; - -#if !EIGEN_HAS_C99_MATH - -template <typename Scalar> -struct polygamma_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(Scalar n, Scalar x) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -#else - -template <typename Scalar> -struct polygamma_impl { - EIGEN_DEVICE_FUNC - static Scalar run(Scalar n, Scalar x) { - Scalar zero = 0.0, one = 1.0; - Scalar nplus = n + one; - const Scalar nan = NumTraits<Scalar>::quiet_NaN(); - - // Check that n is an integer - if (numext::floor(n) != n) { - return nan; - } - // Just return the digamma function for n = 1 - else if (n == zero) { - return digamma_impl<Scalar>::run(x); - } - // Use the same implementation as scipy - else { - Scalar factorial = numext::exp(lgamma_impl<Scalar>::run(nplus)); - return numext::pow(-one, nplus) * factorial * zeta_impl<Scalar>::run(nplus, x); - } - } -}; - -#endif // EIGEN_HAS_C99_MATH - -/************************************************************************************************ - * Implementation of betainc (incomplete beta integral), based on Cephes but requires C++11/C99 * - ************************************************************************************************/ - -template <typename Scalar> -struct betainc_retval { - typedef Scalar type; -}; - -#if !EIGEN_HAS_C99_MATH - -template <typename Scalar> -struct betainc_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(Scalar a, Scalar b, Scalar x) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -#else - -template <typename Scalar> -struct betainc_impl { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(Scalar, Scalar, Scalar) { - /* betaincf.c - * - * Incomplete beta integral - * - * - * SYNOPSIS: - * - * float a, b, x, y, betaincf(); - * - * y = betaincf( a, b, x ); - * - * - * DESCRIPTION: - * - * Returns incomplete beta integral of the arguments, evaluated - * from zero to x. The function is defined as - * - * x - * - - - * | (a+b) | | a-1 b-1 - * ----------- | t (1-t) dt. - * - - | | - * | (a) | (b) - - * 0 - * - * The domain of definition is 0 <= x <= 1. In this - * implementation a and b are restricted to positive values. - * The integral from x to 1 may be obtained by the symmetry - * relation - * - * 1 - betainc( a, b, x ) = betainc( b, a, 1-x ). - * - * The integral is evaluated by a continued fraction expansion. - * If a < 1, the function calls itself recursively after a - * transformation to increase a to a+1. - * - * ACCURACY (float): - * - * Tested at random points (a,b,x) with a and b in the indicated - * interval and x between 0 and 1. - * - * arithmetic domain # trials peak rms - * Relative error: - * IEEE 0,30 10000 3.7e-5 5.1e-6 - * IEEE 0,100 10000 1.7e-4 2.5e-5 - * The useful domain for relative error is limited by underflow - * of the single precision exponential function. - * Absolute error: - * IEEE 0,30 100000 2.2e-5 9.6e-7 - * IEEE 0,100 10000 6.5e-5 3.7e-6 - * - * Larger errors may occur for extreme ratios of a and b. - * - * ACCURACY (double): - * arithmetic domain # trials peak rms - * IEEE 0,5 10000 6.9e-15 4.5e-16 - * IEEE 0,85 250000 2.2e-13 1.7e-14 - * IEEE 0,1000 30000 5.3e-12 6.3e-13 - * IEEE 0,10000 250000 9.3e-11 7.1e-12 - * IEEE 0,100000 10000 8.7e-10 4.8e-11 - * Outputs smaller than the IEEE gradual underflow threshold - * were excluded from these statistics. - * - * ERROR MESSAGES: - * message condition value returned - * incbet domain x<0, x>1 nan - * incbet underflow nan - */ - - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); - return Scalar(0); - } -}; - -/* Continued fraction expansion #1 for incomplete beta integral (small_branch = True) - * Continued fraction expansion #2 for incomplete beta integral (small_branch = False) - */ -template <typename Scalar> -struct incbeta_cfe { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE Scalar run(Scalar a, Scalar b, Scalar x, bool small_branch) { - EIGEN_STATIC_ASSERT((internal::is_same<Scalar, float>::value || - internal::is_same<Scalar, double>::value), - THIS_TYPE_IS_NOT_SUPPORTED); - const Scalar big = cephes_helper<Scalar>::big(); - const Scalar machep = cephes_helper<Scalar>::machep(); - const Scalar biginv = cephes_helper<Scalar>::biginv(); - - const Scalar zero = 0; - const Scalar one = 1; - const Scalar two = 2; - - Scalar xk, pk, pkm1, pkm2, qk, qkm1, qkm2; - Scalar k1, k2, k3, k4, k5, k6, k7, k8, k26update; - Scalar ans; - int n; - - const int num_iters = (internal::is_same<Scalar, float>::value) ? 100 : 300; - const Scalar thresh = - (internal::is_same<Scalar, float>::value) ? machep : Scalar(3) * machep; - Scalar r = (internal::is_same<Scalar, float>::value) ? zero : one; - - if (small_branch) { - k1 = a; - k2 = a + b; - k3 = a; - k4 = a + one; - k5 = one; - k6 = b - one; - k7 = k4; - k8 = a + two; - k26update = one; - } else { - k1 = a; - k2 = b - one; - k3 = a; - k4 = a + one; - k5 = one; - k6 = a + b; - k7 = a + one; - k8 = a + two; - k26update = -one; - x = x / (one - x); - } - - pkm2 = zero; - qkm2 = one; - pkm1 = one; - qkm1 = one; - ans = one; - n = 0; - - do { - xk = -(x * k1 * k2) / (k3 * k4); - pk = pkm1 + pkm2 * xk; - qk = qkm1 + qkm2 * xk; - pkm2 = pkm1; - pkm1 = pk; - qkm2 = qkm1; - qkm1 = qk; - - xk = (x * k5 * k6) / (k7 * k8); - pk = pkm1 + pkm2 * xk; - qk = qkm1 + qkm2 * xk; - pkm2 = pkm1; - pkm1 = pk; - qkm2 = qkm1; - qkm1 = qk; - - if (qk != zero) { - r = pk / qk; - if (numext::abs(ans - r) < numext::abs(r) * thresh) { - return r; - } - ans = r; - } - - k1 += one; - k2 += k26update; - k3 += two; - k4 += two; - k5 += one; - k6 -= k26update; - k7 += two; - k8 += two; - - if ((numext::abs(qk) + numext::abs(pk)) > big) { - pkm2 *= biginv; - pkm1 *= biginv; - qkm2 *= biginv; - qkm1 *= biginv; - } - if ((numext::abs(qk) < biginv) || (numext::abs(pk) < biginv)) { - pkm2 *= big; - pkm1 *= big; - qkm2 *= big; - qkm1 *= big; - } - } while (++n < num_iters); - - return ans; - } -}; - -/* Helper functions depending on the Scalar type */ -template <typename Scalar> -struct betainc_helper {}; - -template <> -struct betainc_helper<float> { - /* Core implementation, assumes a large (> 1.0) */ - EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE float incbsa(float aa, float bb, - float xx) { - float ans, a, b, t, x, onemx; - bool reversed_a_b = false; - - onemx = 1.0f - xx; - - /* see if x is greater than the mean */ - if (xx > (aa / (aa + bb))) { - reversed_a_b = true; - a = bb; - b = aa; - t = xx; - x = onemx; - } else { - a = aa; - b = bb; - t = onemx; - x = xx; - } - - /* Choose expansion for optimal convergence */ - if (b > 10.0f) { - if (numext::abs(b * x / a) < 0.3f) { - t = betainc_helper<float>::incbps(a, b, x); - if (reversed_a_b) t = 1.0f - t; - return t; - } - } - - ans = x * (a + b - 2.0f) / (a - 1.0f); - if (ans < 1.0f) { - ans = incbeta_cfe<float>::run(a, b, x, true /* small_branch */); - t = b * numext::log(t); - } else { - ans = incbeta_cfe<float>::run(a, b, x, false /* small_branch */); - t = (b - 1.0f) * numext::log(t); - } - - t += a * numext::log(x) + lgamma_impl<float>::run(a + b) - - lgamma_impl<float>::run(a) - lgamma_impl<float>::run(b); - t += numext::log(ans / a); - t = numext::exp(t); - - if (reversed_a_b) t = 1.0f - t; - return t; - } - - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE float incbps(float a, float b, float x) { - float t, u, y, s; - const float machep = cephes_helper<float>::machep(); - - y = a * numext::log(x) + (b - 1.0f) * numext::log1p(-x) - numext::log(a); - y -= lgamma_impl<float>::run(a) + lgamma_impl<float>::run(b); - y += lgamma_impl<float>::run(a + b); - - t = x / (1.0f - x); - s = 0.0f; - u = 1.0f; - do { - b -= 1.0f; - if (b == 0.0f) { - break; - } - a += 1.0f; - u *= t * b / a; - s += u; - } while (numext::abs(u) > machep); - - return numext::exp(y) * (1.0f + s); - } -}; - -template <> -struct betainc_impl<float> { - EIGEN_DEVICE_FUNC - static float run(float a, float b, float x) { - const float nan = NumTraits<float>::quiet_NaN(); - float ans, t; - - if (a <= 0.0f) return nan; - if (b <= 0.0f) return nan; - if ((x <= 0.0f) || (x >= 1.0f)) { - if (x == 0.0f) return 0.0f; - if (x == 1.0f) return 1.0f; - // mtherr("betaincf", DOMAIN); - return nan; - } - - /* transformation for small aa */ - if (a <= 1.0f) { - ans = betainc_helper<float>::incbsa(a + 1.0f, b, x); - t = a * numext::log(x) + b * numext::log1p(-x) + - lgamma_impl<float>::run(a + b) - lgamma_impl<float>::run(a + 1.0f) - - lgamma_impl<float>::run(b); - return (ans + numext::exp(t)); - } else { - return betainc_helper<float>::incbsa(a, b, x); - } - } -}; - -template <> -struct betainc_helper<double> { - EIGEN_DEVICE_FUNC - static EIGEN_STRONG_INLINE double incbps(double a, double b, double x) { - const double machep = cephes_helper<double>::machep(); - - double s, t, u, v, n, t1, z, ai; - - ai = 1.0 / a; - u = (1.0 - b) * x; - v = u / (a + 1.0); - t1 = v; - t = u; - n = 2.0; - s = 0.0; - z = machep * ai; - while (numext::abs(v) > z) { - u = (n - b) * x / n; - t *= u; - v = t / (a + n); - s += v; - n += 1.0; - } - s += t1; - s += ai; - - u = a * numext::log(x); - // TODO: gamma() is not directly implemented in Eigen. - /* - if ((a + b) < maxgam && numext::abs(u) < maxlog) { - t = gamma(a + b) / (gamma(a) * gamma(b)); - s = s * t * pow(x, a); - } - */ - t = lgamma_impl<double>::run(a + b) - lgamma_impl<double>::run(a) - - lgamma_impl<double>::run(b) + u + numext::log(s); - return s = numext::exp(t); - } -}; - -template <> -struct betainc_impl<double> { - EIGEN_DEVICE_FUNC - static double run(double aa, double bb, double xx) { - const double nan = NumTraits<double>::quiet_NaN(); - const double machep = cephes_helper<double>::machep(); - // const double maxgam = 171.624376956302725; - - double a, b, t, x, xc, w, y; - bool reversed_a_b = false; - - if (aa <= 0.0 || bb <= 0.0) { - return nan; // goto domerr; - } - - if ((xx <= 0.0) || (xx >= 1.0)) { - if (xx == 0.0) return (0.0); - if (xx == 1.0) return (1.0); - // mtherr("incbet", DOMAIN); - return nan; - } - - if ((bb * xx) <= 1.0 && xx <= 0.95) { - return betainc_helper<double>::incbps(aa, bb, xx); - } - - w = 1.0 - xx; - - /* Reverse a and b if x is greater than the mean. */ - if (xx > (aa / (aa + bb))) { - reversed_a_b = true; - a = bb; - b = aa; - xc = xx; - x = w; - } else { - a = aa; - b = bb; - xc = w; - x = xx; - } - - if (reversed_a_b && (b * x) <= 1.0 && x <= 0.95) { - t = betainc_helper<double>::incbps(a, b, x); - if (t <= machep) { - t = 1.0 - machep; - } else { - t = 1.0 - t; - } - return t; - } - - /* Choose expansion for better convergence. */ - y = x * (a + b - 2.0) - (a - 1.0); - if (y < 0.0) { - w = incbeta_cfe<double>::run(a, b, x, true /* small_branch */); - } else { - w = incbeta_cfe<double>::run(a, b, x, false /* small_branch */) / xc; - } - - /* Multiply w by the factor - a b _ _ _ - x (1-x) | (a+b) / ( a | (a) | (b) ) . */ - - y = a * numext::log(x); - t = b * numext::log(xc); - // TODO: gamma is not directly implemented in Eigen. - /* - if ((a + b) < maxgam && numext::abs(y) < maxlog && numext::abs(t) < maxlog) - { - t = pow(xc, b); - t *= pow(x, a); - t /= a; - t *= w; - t *= gamma(a + b) / (gamma(a) * gamma(b)); - } else { - */ - /* Resort to logarithms. */ - y += t + lgamma_impl<double>::run(a + b) - lgamma_impl<double>::run(a) - - lgamma_impl<double>::run(b); - y += numext::log(w / a); - t = numext::exp(y); - - /* } */ - // done: - - if (reversed_a_b) { - if (t <= machep) { - t = 1.0 - machep; - } else { - t = 1.0 - t; - } - } - return t; - } -}; - -#endif // EIGEN_HAS_C99_MATH - -} // end namespace internal - -namespace numext { - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(lgamma, Scalar) - lgamma(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(lgamma, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(digamma, Scalar) - digamma(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(digamma, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(zeta, Scalar) -zeta(const Scalar& x, const Scalar& q) { - return EIGEN_MATHFUNC_IMPL(zeta, Scalar)::run(x, q); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(polygamma, Scalar) -polygamma(const Scalar& n, const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(polygamma, Scalar)::run(n, x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(erf, Scalar) - erf(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(erf, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(erfc, Scalar) - erfc(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(erfc, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(ndtri, Scalar) - ndtri(const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(ndtri, Scalar)::run(x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(igamma, Scalar) - igamma(const Scalar& a, const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(igamma, Scalar)::run(a, x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(igamma_der_a, Scalar) - igamma_der_a(const Scalar& a, const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(igamma_der_a, Scalar)::run(a, x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(gamma_sample_der_alpha, Scalar) - gamma_sample_der_alpha(const Scalar& a, const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(gamma_sample_der_alpha, Scalar)::run(a, x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(igammac, Scalar) - igammac(const Scalar& a, const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(igammac, Scalar)::run(a, x); -} - -template <typename Scalar> -EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(betainc, Scalar) - betainc(const Scalar& a, const Scalar& b, const Scalar& x) { - return EIGEN_MATHFUNC_IMPL(betainc, Scalar)::run(a, b, x); -} - -} // end namespace numext -} // end namespace Eigen - -#endif // EIGEN_SPECIAL_FUNCTIONS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsPacketMath.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsPacketMath.h deleted file mode 100644 index 2bb01792..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/SpecialFunctionsPacketMath.h +++ /dev/null @@ -1,79 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPECIALFUNCTIONS_PACKETMATH_H -#define EIGEN_SPECIALFUNCTIONS_PACKETMATH_H - -namespace Eigen { - -namespace internal { - -/** \internal \returns the ln(|gamma(\a a)|) (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet plgamma(const Packet& a) { using numext::lgamma; return lgamma(a); } - -/** \internal \returns the derivative of lgamma, psi(\a a) (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pdigamma(const Packet& a) { using numext::digamma; return digamma(a); } - -/** \internal \returns the zeta function of two arguments (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pzeta(const Packet& x, const Packet& q) { using numext::zeta; return zeta(x, q); } - -/** \internal \returns the polygamma function (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet ppolygamma(const Packet& n, const Packet& x) { using numext::polygamma; return polygamma(n, x); } - -/** \internal \returns the erf(\a a) (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet perf(const Packet& a) { using numext::erf; return erf(a); } - -/** \internal \returns the erfc(\a a) (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet perfc(const Packet& a) { using numext::erfc; return erfc(a); } - -/** \internal \returns the ndtri(\a a) (coeff-wise) */ -template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -Packet pndtri(const Packet& a) { - typedef typename unpacket_traits<Packet>::type ScalarType; - using internal::generic_ndtri; return generic_ndtri<Packet, ScalarType>(a); -} - -/** \internal \returns the incomplete gamma function igamma(\a a, \a x) */ -template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -Packet pigamma(const Packet& a, const Packet& x) { using numext::igamma; return igamma(a, x); } - -/** \internal \returns the derivative of the incomplete gamma function - * igamma_der_a(\a a, \a x) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pigamma_der_a(const Packet& a, const Packet& x) { - using numext::igamma_der_a; return igamma_der_a(a, x); -} - -/** \internal \returns compute the derivative of the sample - * of Gamma(alpha, 1) random variable with respect to the parameter a - * gamma_sample_der_alpha(\a alpha, \a sample) */ -template <typename Packet> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pgamma_sample_der_alpha(const Packet& alpha, const Packet& sample) { - using numext::gamma_sample_der_alpha; return gamma_sample_der_alpha(alpha, sample); -} - -/** \internal \returns the complementary incomplete gamma function igammac(\a a, \a x) */ -template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -Packet pigammac(const Packet& a, const Packet& x) { using numext::igammac; return igammac(a, x); } - -/** \internal \returns the complementary incomplete gamma function betainc(\a a, \a b, \a x) */ -template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -Packet pbetainc(const Packet& a, const Packet& b,const Packet& x) { using numext::betainc; return betainc(a, b, x); } - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_SPECIALFUNCTIONS_PACKETMATH_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/arch/GPU/GpuSpecialFunctions.h b/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/arch/GPU/GpuSpecialFunctions.h deleted file mode 100644 index dd3bf4dd..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/SpecialFunctions/arch/GPU/GpuSpecialFunctions.h +++ /dev/null @@ -1,369 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_GPU_SPECIALFUNCTIONS_H -#define EIGEN_GPU_SPECIALFUNCTIONS_H - -namespace Eigen { - -namespace internal { - -// Make sure this is only available when targeting a GPU: we don't want to -// introduce conflicts between these packet_traits definitions and the ones -// we'll use on the host side (SSE, AVX, ...) -#if defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU) - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 plgamma<float4>(const float4& a) -{ - return make_float4(lgammaf(a.x), lgammaf(a.y), lgammaf(a.z), lgammaf(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 plgamma<double2>(const double2& a) -{ - using numext::lgamma; - return make_double2(lgamma(a.x), lgamma(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 pdigamma<float4>(const float4& a) -{ - using numext::digamma; - return make_float4(digamma(a.x), digamma(a.y), digamma(a.z), digamma(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 pdigamma<double2>(const double2& a) -{ - using numext::digamma; - return make_double2(digamma(a.x), digamma(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 pzeta<float4>(const float4& x, const float4& q) -{ - using numext::zeta; - return make_float4(zeta(x.x, q.x), zeta(x.y, q.y), zeta(x.z, q.z), zeta(x.w, q.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 pzeta<double2>(const double2& x, const double2& q) -{ - using numext::zeta; - return make_double2(zeta(x.x, q.x), zeta(x.y, q.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 ppolygamma<float4>(const float4& n, const float4& x) -{ - using numext::polygamma; - return make_float4(polygamma(n.x, x.x), polygamma(n.y, x.y), polygamma(n.z, x.z), polygamma(n.w, x.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 ppolygamma<double2>(const double2& n, const double2& x) -{ - using numext::polygamma; - return make_double2(polygamma(n.x, x.x), polygamma(n.y, x.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 perf<float4>(const float4& a) -{ - return make_float4(erff(a.x), erff(a.y), erff(a.z), erff(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 perf<double2>(const double2& a) -{ - using numext::erf; - return make_double2(erf(a.x), erf(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 perfc<float4>(const float4& a) -{ - using numext::erfc; - return make_float4(erfc(a.x), erfc(a.y), erfc(a.z), erfc(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 perfc<double2>(const double2& a) -{ - using numext::erfc; - return make_double2(erfc(a.x), erfc(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 pndtri<float4>(const float4& a) -{ - using numext::ndtri; - return make_float4(ndtri(a.x), ndtri(a.y), ndtri(a.z), ndtri(a.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 pndtri<double2>(const double2& a) -{ - using numext::ndtri; - return make_double2(ndtri(a.x), ndtri(a.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 pigamma<float4>(const float4& a, const float4& x) -{ - using numext::igamma; - return make_float4( - igamma(a.x, x.x), - igamma(a.y, x.y), - igamma(a.z, x.z), - igamma(a.w, x.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 pigamma<double2>(const double2& a, const double2& x) -{ - using numext::igamma; - return make_double2(igamma(a.x, x.x), igamma(a.y, x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pigamma_der_a<float4>( - const float4& a, const float4& x) { - using numext::igamma_der_a; - return make_float4(igamma_der_a(a.x, x.x), igamma_der_a(a.y, x.y), - igamma_der_a(a.z, x.z), igamma_der_a(a.w, x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pigamma_der_a<double2>(const double2& a, const double2& x) { - using numext::igamma_der_a; - return make_double2(igamma_der_a(a.x, x.x), igamma_der_a(a.y, x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pgamma_sample_der_alpha<float4>( - const float4& alpha, const float4& sample) { - using numext::gamma_sample_der_alpha; - return make_float4( - gamma_sample_der_alpha(alpha.x, sample.x), - gamma_sample_der_alpha(alpha.y, sample.y), - gamma_sample_der_alpha(alpha.z, sample.z), - gamma_sample_der_alpha(alpha.w, sample.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pgamma_sample_der_alpha<double2>(const double2& alpha, const double2& sample) { - using numext::gamma_sample_der_alpha; - return make_double2( - gamma_sample_der_alpha(alpha.x, sample.x), - gamma_sample_der_alpha(alpha.y, sample.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 pigammac<float4>(const float4& a, const float4& x) -{ - using numext::igammac; - return make_float4( - igammac(a.x, x.x), - igammac(a.y, x.y), - igammac(a.z, x.z), - igammac(a.w, x.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 pigammac<double2>(const double2& a, const double2& x) -{ - using numext::igammac; - return make_double2(igammac(a.x, x.x), igammac(a.y, x.y)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -float4 pbetainc<float4>(const float4& a, const float4& b, const float4& x) -{ - using numext::betainc; - return make_float4( - betainc(a.x, b.x, x.x), - betainc(a.y, b.y, x.y), - betainc(a.z, b.z, x.z), - betainc(a.w, b.w, x.w)); -} - -template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -double2 pbetainc<double2>(const double2& a, const double2& b, const double2& x) -{ - using numext::betainc; - return make_double2(betainc(a.x, b.x, x.x), betainc(a.y, b.y, x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_i0e<float4>(const float4& x) { - using numext::bessel_i0e; - return make_float4(bessel_i0e(x.x), bessel_i0e(x.y), bessel_i0e(x.z), bessel_i0e(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_i0e<double2>(const double2& x) { - using numext::bessel_i0e; - return make_double2(bessel_i0e(x.x), bessel_i0e(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_i0<float4>(const float4& x) { - using numext::bessel_i0; - return make_float4(bessel_i0(x.x), bessel_i0(x.y), bessel_i0(x.z), bessel_i0(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_i0<double2>(const double2& x) { - using numext::bessel_i0; - return make_double2(bessel_i0(x.x), bessel_i0(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_i1e<float4>(const float4& x) { - using numext::bessel_i1e; - return make_float4(bessel_i1e(x.x), bessel_i1e(x.y), bessel_i1e(x.z), bessel_i1e(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_i1e<double2>(const double2& x) { - using numext::bessel_i1e; - return make_double2(bessel_i1e(x.x), bessel_i1e(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_i1<float4>(const float4& x) { - using numext::bessel_i1; - return make_float4(bessel_i1(x.x), bessel_i1(x.y), bessel_i1(x.z), bessel_i1(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_i1<double2>(const double2& x) { - using numext::bessel_i1; - return make_double2(bessel_i1(x.x), bessel_i1(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_k0e<float4>(const float4& x) { - using numext::bessel_k0e; - return make_float4(bessel_k0e(x.x), bessel_k0e(x.y), bessel_k0e(x.z), bessel_k0e(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_k0e<double2>(const double2& x) { - using numext::bessel_k0e; - return make_double2(bessel_k0e(x.x), bessel_k0e(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_k0<float4>(const float4& x) { - using numext::bessel_k0; - return make_float4(bessel_k0(x.x), bessel_k0(x.y), bessel_k0(x.z), bessel_k0(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_k0<double2>(const double2& x) { - using numext::bessel_k0; - return make_double2(bessel_k0(x.x), bessel_k0(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_k1e<float4>(const float4& x) { - using numext::bessel_k1e; - return make_float4(bessel_k1e(x.x), bessel_k1e(x.y), bessel_k1e(x.z), bessel_k1e(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_k1e<double2>(const double2& x) { - using numext::bessel_k1e; - return make_double2(bessel_k1e(x.x), bessel_k1e(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_k1<float4>(const float4& x) { - using numext::bessel_k1; - return make_float4(bessel_k1(x.x), bessel_k1(x.y), bessel_k1(x.z), bessel_k1(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_k1<double2>(const double2& x) { - using numext::bessel_k1; - return make_double2(bessel_k1(x.x), bessel_k1(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_j0<float4>(const float4& x) { - using numext::bessel_j0; - return make_float4(bessel_j0(x.x), bessel_j0(x.y), bessel_j0(x.z), bessel_j0(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_j0<double2>(const double2& x) { - using numext::bessel_j0; - return make_double2(bessel_j0(x.x), bessel_j0(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_j1<float4>(const float4& x) { - using numext::bessel_j1; - return make_float4(bessel_j1(x.x), bessel_j1(x.y), bessel_j1(x.z), bessel_j1(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_j1<double2>(const double2& x) { - using numext::bessel_j1; - return make_double2(bessel_j1(x.x), bessel_j1(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_y0<float4>(const float4& x) { - using numext::bessel_y0; - return make_float4(bessel_y0(x.x), bessel_y0(x.y), bessel_y0(x.z), bessel_y0(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_y0<double2>(const double2& x) { - using numext::bessel_y0; - return make_double2(bessel_y0(x.x), bessel_y0(x.y)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_y1<float4>(const float4& x) { - using numext::bessel_y1; - return make_float4(bessel_y1(x.x), bessel_y1(x.y), bessel_y1(x.z), bessel_y1(x.w)); -} - -template <> -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 -pbessel_y1<double2>(const double2& x) { - using numext::bessel_y1; - return make_double2(bessel_y1(x.x), bessel_y1(x.y)); -} - -#endif - -} // end namespace internal - -} // end namespace Eigen - -#endif // EIGEN_GPU_SPECIALFUNCTIONS_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/Spline.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/Spline.h deleted file mode 100644 index 79edd52c..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/Spline.h +++ /dev/null @@ -1,507 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 20010-2011 Hauke Heibel <hauke.heibel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPLINE_H -#define EIGEN_SPLINE_H - -#include "SplineFwd.h" - -namespace Eigen -{ - /** - * \ingroup Splines_Module - * \class Spline - * \brief A class representing multi-dimensional spline curves. - * - * The class represents B-splines with non-uniform knot vectors. Each control - * point of the B-spline is associated with a basis function - * \f{align*} - * C(u) & = \sum_{i=0}^{n}N_{i,p}(u)P_i - * \f} - * - * \tparam _Scalar The underlying data type (typically float or double) - * \tparam _Dim The curve dimension (e.g. 2 or 3) - * \tparam _Degree Per default set to Dynamic; could be set to the actual desired - * degree for optimization purposes (would result in stack allocation - * of several temporary variables). - **/ - template <typename _Scalar, int _Dim, int _Degree> - class Spline - { - public: - typedef _Scalar Scalar; /*!< The spline curve's scalar type. */ - enum { Dimension = _Dim /*!< The spline curve's dimension. */ }; - enum { Degree = _Degree /*!< The spline curve's degree. */ }; - - /** \brief The point type the spline is representing. */ - typedef typename SplineTraits<Spline>::PointType PointType; - - /** \brief The data type used to store knot vectors. */ - typedef typename SplineTraits<Spline>::KnotVectorType KnotVectorType; - - /** \brief The data type used to store parameter vectors. */ - typedef typename SplineTraits<Spline>::ParameterVectorType ParameterVectorType; - - /** \brief The data type used to store non-zero basis functions. */ - typedef typename SplineTraits<Spline>::BasisVectorType BasisVectorType; - - /** \brief The data type used to store the values of the basis function derivatives. */ - typedef typename SplineTraits<Spline>::BasisDerivativeType BasisDerivativeType; - - /** \brief The data type representing the spline's control points. */ - typedef typename SplineTraits<Spline>::ControlPointVectorType ControlPointVectorType; - - /** - * \brief Creates a (constant) zero spline. - * For Splines with dynamic degree, the resulting degree will be 0. - **/ - Spline() - : m_knots(1, (Degree==Dynamic ? 2 : 2*Degree+2)) - , m_ctrls(ControlPointVectorType::Zero(Dimension,(Degree==Dynamic ? 1 : Degree+1))) - { - // in theory this code can go to the initializer list but it will get pretty - // much unreadable ... - enum { MinDegree = (Degree==Dynamic ? 0 : Degree) }; - m_knots.template segment<MinDegree+1>(0) = Array<Scalar,1,MinDegree+1>::Zero(); - m_knots.template segment<MinDegree+1>(MinDegree+1) = Array<Scalar,1,MinDegree+1>::Ones(); - } - - /** - * \brief Creates a spline from a knot vector and control points. - * \param knots The spline's knot vector. - * \param ctrls The spline's control point vector. - **/ - template <typename OtherVectorType, typename OtherArrayType> - Spline(const OtherVectorType& knots, const OtherArrayType& ctrls) : m_knots(knots), m_ctrls(ctrls) {} - - /** - * \brief Copy constructor for splines. - * \param spline The input spline. - **/ - template <int OtherDegree> - Spline(const Spline<Scalar, Dimension, OtherDegree>& spline) : - m_knots(spline.knots()), m_ctrls(spline.ctrls()) {} - - /** - * \brief Returns the knots of the underlying spline. - **/ - const KnotVectorType& knots() const { return m_knots; } - - /** - * \brief Returns the ctrls of the underlying spline. - **/ - const ControlPointVectorType& ctrls() const { return m_ctrls; } - - /** - * \brief Returns the spline value at a given site \f$u\f$. - * - * The function returns - * \f{align*} - * C(u) & = \sum_{i=0}^{n}N_{i,p}P_i - * \f} - * - * \param u Parameter \f$u \in [0;1]\f$ at which the spline is evaluated. - * \return The spline value at the given location \f$u\f$. - **/ - PointType operator()(Scalar u) const; - - /** - * \brief Evaluation of spline derivatives of up-to given order. - * - * The function returns - * \f{align*} - * \frac{d^i}{du^i}C(u) & = \sum_{i=0}^{n} \frac{d^i}{du^i} N_{i,p}(u)P_i - * \f} - * for i ranging between 0 and order. - * - * \param u Parameter \f$u \in [0;1]\f$ at which the spline derivative is evaluated. - * \param order The order up to which the derivatives are computed. - **/ - typename SplineTraits<Spline>::DerivativeType - derivatives(Scalar u, DenseIndex order) const; - - /** - * \copydoc Spline::derivatives - * Using the template version of this function is more efficieent since - * temporary objects are allocated on the stack whenever this is possible. - **/ - template <int DerivativeOrder> - typename SplineTraits<Spline,DerivativeOrder>::DerivativeType - derivatives(Scalar u, DenseIndex order = DerivativeOrder) const; - - /** - * \brief Computes the non-zero basis functions at the given site. - * - * Splines have local support and a point from their image is defined - * by exactly \f$p+1\f$ control points \f$P_i\f$ where \f$p\f$ is the - * spline degree. - * - * This function computes the \f$p+1\f$ non-zero basis function values - * for a given parameter value \f$u\f$. It returns - * \f{align*}{ - * N_{i,p}(u), \hdots, N_{i+p+1,p}(u) - * \f} - * - * \param u Parameter \f$u \in [0;1]\f$ at which the non-zero basis functions - * are computed. - **/ - typename SplineTraits<Spline>::BasisVectorType - basisFunctions(Scalar u) const; - - /** - * \brief Computes the non-zero spline basis function derivatives up to given order. - * - * The function computes - * \f{align*}{ - * \frac{d^i}{du^i} N_{i,p}(u), \hdots, \frac{d^i}{du^i} N_{i+p+1,p}(u) - * \f} - * with i ranging from 0 up to the specified order. - * - * \param u Parameter \f$u \in [0;1]\f$ at which the non-zero basis function - * derivatives are computed. - * \param order The order up to which the basis function derivatives are computes. - **/ - typename SplineTraits<Spline>::BasisDerivativeType - basisFunctionDerivatives(Scalar u, DenseIndex order) const; - - /** - * \copydoc Spline::basisFunctionDerivatives - * Using the template version of this function is more efficieent since - * temporary objects are allocated on the stack whenever this is possible. - **/ - template <int DerivativeOrder> - typename SplineTraits<Spline,DerivativeOrder>::BasisDerivativeType - basisFunctionDerivatives(Scalar u, DenseIndex order = DerivativeOrder) const; - - /** - * \brief Returns the spline degree. - **/ - DenseIndex degree() const; - - /** - * \brief Returns the span within the knot vector in which u is falling. - * \param u The site for which the span is determined. - **/ - DenseIndex span(Scalar u) const; - - /** - * \brief Computes the span within the provided knot vector in which u is falling. - **/ - static DenseIndex Span(typename SplineTraits<Spline>::Scalar u, DenseIndex degree, const typename SplineTraits<Spline>::KnotVectorType& knots); - - /** - * \brief Returns the spline's non-zero basis functions. - * - * The function computes and returns - * \f{align*}{ - * N_{i,p}(u), \hdots, N_{i+p+1,p}(u) - * \f} - * - * \param u The site at which the basis functions are computed. - * \param degree The degree of the underlying spline. - * \param knots The underlying spline's knot vector. - **/ - static BasisVectorType BasisFunctions(Scalar u, DenseIndex degree, const KnotVectorType& knots); - - /** - * \copydoc Spline::basisFunctionDerivatives - * \param degree The degree of the underlying spline - * \param knots The underlying spline's knot vector. - **/ - static BasisDerivativeType BasisFunctionDerivatives( - const Scalar u, const DenseIndex order, const DenseIndex degree, const KnotVectorType& knots); - - private: - KnotVectorType m_knots; /*!< Knot vector. */ - ControlPointVectorType m_ctrls; /*!< Control points. */ - - template <typename DerivativeType> - static void BasisFunctionDerivativesImpl( - const typename Spline<_Scalar, _Dim, _Degree>::Scalar u, - const DenseIndex order, - const DenseIndex p, - const typename Spline<_Scalar, _Dim, _Degree>::KnotVectorType& U, - DerivativeType& N_); - }; - - template <typename _Scalar, int _Dim, int _Degree> - DenseIndex Spline<_Scalar, _Dim, _Degree>::Span( - typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::Scalar u, - DenseIndex degree, - const typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::KnotVectorType& knots) - { - // Piegl & Tiller, "The NURBS Book", A2.1 (p. 68) - if (u <= knots(0)) return degree; - const Scalar* pos = std::upper_bound(knots.data()+degree-1, knots.data()+knots.size()-degree-1, u); - return static_cast<DenseIndex>( std::distance(knots.data(), pos) - 1 ); - } - - template <typename _Scalar, int _Dim, int _Degree> - typename Spline<_Scalar, _Dim, _Degree>::BasisVectorType - Spline<_Scalar, _Dim, _Degree>::BasisFunctions( - typename Spline<_Scalar, _Dim, _Degree>::Scalar u, - DenseIndex degree, - const typename Spline<_Scalar, _Dim, _Degree>::KnotVectorType& knots) - { - const DenseIndex p = degree; - const DenseIndex i = Spline::Span(u, degree, knots); - - const KnotVectorType& U = knots; - - BasisVectorType left(p+1); left(0) = Scalar(0); - BasisVectorType right(p+1); right(0) = Scalar(0); - - VectorBlock<BasisVectorType,Degree>(left,1,p) = u - VectorBlock<const KnotVectorType,Degree>(U,i+1-p,p).reverse(); - VectorBlock<BasisVectorType,Degree>(right,1,p) = VectorBlock<const KnotVectorType,Degree>(U,i+1,p) - u; - - BasisVectorType N(1,p+1); - N(0) = Scalar(1); - for (DenseIndex j=1; j<=p; ++j) - { - Scalar saved = Scalar(0); - for (DenseIndex r=0; r<j; r++) - { - const Scalar tmp = N(r)/(right(r+1)+left(j-r)); - N[r] = saved + right(r+1)*tmp; - saved = left(j-r)*tmp; - } - N(j) = saved; - } - return N; - } - - template <typename _Scalar, int _Dim, int _Degree> - DenseIndex Spline<_Scalar, _Dim, _Degree>::degree() const - { - if (_Degree == Dynamic) - return m_knots.size() - m_ctrls.cols() - 1; - else - return _Degree; - } - - template <typename _Scalar, int _Dim, int _Degree> - DenseIndex Spline<_Scalar, _Dim, _Degree>::span(Scalar u) const - { - return Spline::Span(u, degree(), knots()); - } - - template <typename _Scalar, int _Dim, int _Degree> - typename Spline<_Scalar, _Dim, _Degree>::PointType Spline<_Scalar, _Dim, _Degree>::operator()(Scalar u) const - { - enum { Order = SplineTraits<Spline>::OrderAtCompileTime }; - - const DenseIndex span = this->span(u); - const DenseIndex p = degree(); - const BasisVectorType basis_funcs = basisFunctions(u); - - const Replicate<BasisVectorType,Dimension,1> ctrl_weights(basis_funcs); - const Block<const ControlPointVectorType,Dimension,Order> ctrl_pts(ctrls(),0,span-p,Dimension,p+1); - return (ctrl_weights * ctrl_pts).rowwise().sum(); - } - - /* --------------------------------------------------------------------------------------------- */ - - template <typename SplineType, typename DerivativeType> - void derivativesImpl(const SplineType& spline, typename SplineType::Scalar u, DenseIndex order, DerivativeType& der) - { - enum { Dimension = SplineTraits<SplineType>::Dimension }; - enum { Order = SplineTraits<SplineType>::OrderAtCompileTime }; - enum { DerivativeOrder = DerivativeType::ColsAtCompileTime }; - - typedef typename SplineTraits<SplineType>::ControlPointVectorType ControlPointVectorType; - typedef typename SplineTraits<SplineType,DerivativeOrder>::BasisDerivativeType BasisDerivativeType; - typedef typename BasisDerivativeType::ConstRowXpr BasisDerivativeRowXpr; - - const DenseIndex p = spline.degree(); - const DenseIndex span = spline.span(u); - - const DenseIndex n = (std::min)(p, order); - - der.resize(Dimension,n+1); - - // Retrieve the basis function derivatives up to the desired order... - const BasisDerivativeType basis_func_ders = spline.template basisFunctionDerivatives<DerivativeOrder>(u, n+1); - - // ... and perform the linear combinations of the control points. - for (DenseIndex der_order=0; der_order<n+1; ++der_order) - { - const Replicate<BasisDerivativeRowXpr,Dimension,1> ctrl_weights( basis_func_ders.row(der_order) ); - const Block<const ControlPointVectorType,Dimension,Order> ctrl_pts(spline.ctrls(),0,span-p,Dimension,p+1); - der.col(der_order) = (ctrl_weights * ctrl_pts).rowwise().sum(); - } - } - - template <typename _Scalar, int _Dim, int _Degree> - typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::DerivativeType - Spline<_Scalar, _Dim, _Degree>::derivatives(Scalar u, DenseIndex order) const - { - typename SplineTraits< Spline >::DerivativeType res; - derivativesImpl(*this, u, order, res); - return res; - } - - template <typename _Scalar, int _Dim, int _Degree> - template <int DerivativeOrder> - typename SplineTraits< Spline<_Scalar, _Dim, _Degree>, DerivativeOrder >::DerivativeType - Spline<_Scalar, _Dim, _Degree>::derivatives(Scalar u, DenseIndex order) const - { - typename SplineTraits< Spline, DerivativeOrder >::DerivativeType res; - derivativesImpl(*this, u, order, res); - return res; - } - - template <typename _Scalar, int _Dim, int _Degree> - typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::BasisVectorType - Spline<_Scalar, _Dim, _Degree>::basisFunctions(Scalar u) const - { - return Spline::BasisFunctions(u, degree(), knots()); - } - - /* --------------------------------------------------------------------------------------------- */ - - - template <typename _Scalar, int _Dim, int _Degree> - template <typename DerivativeType> - void Spline<_Scalar, _Dim, _Degree>::BasisFunctionDerivativesImpl( - const typename Spline<_Scalar, _Dim, _Degree>::Scalar u, - const DenseIndex order, - const DenseIndex p, - const typename Spline<_Scalar, _Dim, _Degree>::KnotVectorType& U, - DerivativeType& N_) - { - typedef Spline<_Scalar, _Dim, _Degree> SplineType; - enum { Order = SplineTraits<SplineType>::OrderAtCompileTime }; - - const DenseIndex span = SplineType::Span(u, p, U); - - const DenseIndex n = (std::min)(p, order); - - N_.resize(n+1, p+1); - - BasisVectorType left = BasisVectorType::Zero(p+1); - BasisVectorType right = BasisVectorType::Zero(p+1); - - Matrix<Scalar,Order,Order> ndu(p+1,p+1); - - Scalar saved, temp; // FIXME These were double instead of Scalar. Was there a reason for that? - - ndu(0,0) = 1.0; - - DenseIndex j; - for (j=1; j<=p; ++j) - { - left[j] = u-U[span+1-j]; - right[j] = U[span+j]-u; - saved = 0.0; - - for (DenseIndex r=0; r<j; ++r) - { - /* Lower triangle */ - ndu(j,r) = right[r+1]+left[j-r]; - temp = ndu(r,j-1)/ndu(j,r); - /* Upper triangle */ - ndu(r,j) = static_cast<Scalar>(saved+right[r+1] * temp); - saved = left[j-r] * temp; - } - - ndu(j,j) = static_cast<Scalar>(saved); - } - - for (j = p; j>=0; --j) - N_(0,j) = ndu(j,p); - - // Compute the derivatives - DerivativeType a(n+1,p+1); - DenseIndex r=0; - for (; r<=p; ++r) - { - DenseIndex s1,s2; - s1 = 0; s2 = 1; // alternate rows in array a - a(0,0) = 1.0; - - // Compute the k-th derivative - for (DenseIndex k=1; k<=static_cast<DenseIndex>(n); ++k) - { - Scalar d = 0.0; - DenseIndex rk,pk,j1,j2; - rk = r-k; pk = p-k; - - if (r>=k) - { - a(s2,0) = a(s1,0)/ndu(pk+1,rk); - d = a(s2,0)*ndu(rk,pk); - } - - if (rk>=-1) j1 = 1; - else j1 = -rk; - - if (r-1 <= pk) j2 = k-1; - else j2 = p-r; - - for (j=j1; j<=j2; ++j) - { - a(s2,j) = (a(s1,j)-a(s1,j-1))/ndu(pk+1,rk+j); - d += a(s2,j)*ndu(rk+j,pk); - } - - if (r<=pk) - { - a(s2,k) = -a(s1,k-1)/ndu(pk+1,r); - d += a(s2,k)*ndu(r,pk); - } - - N_(k,r) = static_cast<Scalar>(d); - j = s1; s1 = s2; s2 = j; // Switch rows - } - } - - /* Multiply through by the correct factors */ - /* (Eq. [2.9]) */ - r = p; - for (DenseIndex k=1; k<=static_cast<DenseIndex>(n); ++k) - { - for (j=p; j>=0; --j) N_(k,j) *= r; - r *= p-k; - } - } - - template <typename _Scalar, int _Dim, int _Degree> - typename SplineTraits< Spline<_Scalar, _Dim, _Degree> >::BasisDerivativeType - Spline<_Scalar, _Dim, _Degree>::basisFunctionDerivatives(Scalar u, DenseIndex order) const - { - typename SplineTraits<Spline<_Scalar, _Dim, _Degree> >::BasisDerivativeType der; - BasisFunctionDerivativesImpl(u, order, degree(), knots(), der); - return der; - } - - template <typename _Scalar, int _Dim, int _Degree> - template <int DerivativeOrder> - typename SplineTraits< Spline<_Scalar, _Dim, _Degree>, DerivativeOrder >::BasisDerivativeType - Spline<_Scalar, _Dim, _Degree>::basisFunctionDerivatives(Scalar u, DenseIndex order) const - { - typename SplineTraits< Spline<_Scalar, _Dim, _Degree>, DerivativeOrder >::BasisDerivativeType der; - BasisFunctionDerivativesImpl(u, order, degree(), knots(), der); - return der; - } - - template <typename _Scalar, int _Dim, int _Degree> - typename SplineTraits<Spline<_Scalar, _Dim, _Degree> >::BasisDerivativeType - Spline<_Scalar, _Dim, _Degree>::BasisFunctionDerivatives( - const typename Spline<_Scalar, _Dim, _Degree>::Scalar u, - const DenseIndex order, - const DenseIndex degree, - const typename Spline<_Scalar, _Dim, _Degree>::KnotVectorType& knots) - { - typename SplineTraits<Spline>::BasisDerivativeType der; - BasisFunctionDerivativesImpl(u, order, degree, knots, der); - return der; - } -} - -#endif // EIGEN_SPLINE_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/SplineFitting.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/SplineFitting.h deleted file mode 100644 index 9f6e8afa..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/SplineFitting.h +++ /dev/null @@ -1,431 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 20010-2011 Hauke Heibel <hauke.heibel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPLINE_FITTING_H -#define EIGEN_SPLINE_FITTING_H - -#include <algorithm> -#include <functional> -#include <numeric> -#include <vector> - -#include "SplineFwd.h" - -#include "../../../../Eigen/LU" -#include "../../../../Eigen/QR" - -namespace Eigen -{ - /** - * \brief Computes knot averages. - * \ingroup Splines_Module - * - * The knots are computed as - * \f{align*} - * u_0 & = \hdots = u_p = 0 \\ - * u_{m-p} & = \hdots = u_{m} = 1 \\ - * u_{j+p} & = \frac{1}{p}\sum_{i=j}^{j+p-1}\bar{u}_i \quad\quad j=1,\hdots,n-p - * \f} - * where \f$p\f$ is the degree and \f$m+1\f$ the number knots - * of the desired interpolating spline. - * - * \param[in] parameters The input parameters. During interpolation one for each data point. - * \param[in] degree The spline degree which is used during the interpolation. - * \param[out] knots The output knot vector. - * - * \sa Les Piegl and Wayne Tiller, The NURBS book (2nd ed.), 1997, 9.2.1 Global Curve Interpolation to Point Data - **/ - template <typename KnotVectorType> - void KnotAveraging(const KnotVectorType& parameters, DenseIndex degree, KnotVectorType& knots) - { - knots.resize(parameters.size()+degree+1); - - for (DenseIndex j=1; j<parameters.size()-degree; ++j) - knots(j+degree) = parameters.segment(j,degree).mean(); - - knots.segment(0,degree+1) = KnotVectorType::Zero(degree+1); - knots.segment(knots.size()-degree-1,degree+1) = KnotVectorType::Ones(degree+1); - } - - /** - * \brief Computes knot averages when derivative constraints are present. - * Note that this is a technical interpretation of the referenced article - * since the algorithm contained therein is incorrect as written. - * \ingroup Splines_Module - * - * \param[in] parameters The parameters at which the interpolation B-Spline - * will intersect the given interpolation points. The parameters - * are assumed to be a non-decreasing sequence. - * \param[in] degree The degree of the interpolating B-Spline. This must be - * greater than zero. - * \param[in] derivativeIndices The indices corresponding to parameters at - * which there are derivative constraints. The indices are assumed - * to be a non-decreasing sequence. - * \param[out] knots The calculated knot vector. These will be returned as a - * non-decreasing sequence - * - * \sa Les A. Piegl, Khairan Rajab, Volha Smarodzinana. 2008. - * Curve interpolation with directional constraints for engineering design. - * Engineering with Computers - **/ - template <typename KnotVectorType, typename ParameterVectorType, typename IndexArray> - void KnotAveragingWithDerivatives(const ParameterVectorType& parameters, - const unsigned int degree, - const IndexArray& derivativeIndices, - KnotVectorType& knots) - { - typedef typename ParameterVectorType::Scalar Scalar; - - DenseIndex numParameters = parameters.size(); - DenseIndex numDerivatives = derivativeIndices.size(); - - if (numDerivatives < 1) - { - KnotAveraging(parameters, degree, knots); - return; - } - - DenseIndex startIndex; - DenseIndex endIndex; - - DenseIndex numInternalDerivatives = numDerivatives; - - if (derivativeIndices[0] == 0) - { - startIndex = 0; - --numInternalDerivatives; - } - else - { - startIndex = 1; - } - if (derivativeIndices[numDerivatives - 1] == numParameters - 1) - { - endIndex = numParameters - degree; - --numInternalDerivatives; - } - else - { - endIndex = numParameters - degree - 1; - } - - // There are (endIndex - startIndex + 1) knots obtained from the averaging - // and 2 for the first and last parameters. - DenseIndex numAverageKnots = endIndex - startIndex + 3; - KnotVectorType averageKnots(numAverageKnots); - averageKnots[0] = parameters[0]; - - int newKnotIndex = 0; - for (DenseIndex i = startIndex; i <= endIndex; ++i) - averageKnots[++newKnotIndex] = parameters.segment(i, degree).mean(); - averageKnots[++newKnotIndex] = parameters[numParameters - 1]; - - newKnotIndex = -1; - - ParameterVectorType temporaryParameters(numParameters + 1); - KnotVectorType derivativeKnots(numInternalDerivatives); - for (DenseIndex i = 0; i < numAverageKnots - 1; ++i) - { - temporaryParameters[0] = averageKnots[i]; - ParameterVectorType parameterIndices(numParameters); - int temporaryParameterIndex = 1; - for (DenseIndex j = 0; j < numParameters; ++j) - { - Scalar parameter = parameters[j]; - if (parameter >= averageKnots[i] && parameter < averageKnots[i + 1]) - { - parameterIndices[temporaryParameterIndex] = j; - temporaryParameters[temporaryParameterIndex++] = parameter; - } - } - temporaryParameters[temporaryParameterIndex] = averageKnots[i + 1]; - - for (int j = 0; j <= temporaryParameterIndex - 2; ++j) - { - for (DenseIndex k = 0; k < derivativeIndices.size(); ++k) - { - if (parameterIndices[j + 1] == derivativeIndices[k] - && parameterIndices[j + 1] != 0 - && parameterIndices[j + 1] != numParameters - 1) - { - derivativeKnots[++newKnotIndex] = temporaryParameters.segment(j, 3).mean(); - break; - } - } - } - } - - KnotVectorType temporaryKnots(averageKnots.size() + derivativeKnots.size()); - - std::merge(averageKnots.data(), averageKnots.data() + averageKnots.size(), - derivativeKnots.data(), derivativeKnots.data() + derivativeKnots.size(), - temporaryKnots.data()); - - // Number of knots (one for each point and derivative) plus spline order. - DenseIndex numKnots = numParameters + numDerivatives + degree + 1; - knots.resize(numKnots); - - knots.head(degree).fill(temporaryKnots[0]); - knots.tail(degree).fill(temporaryKnots.template tail<1>()[0]); - knots.segment(degree, temporaryKnots.size()) = temporaryKnots; - } - - /** - * \brief Computes chord length parameters which are required for spline interpolation. - * \ingroup Splines_Module - * - * \param[in] pts The data points to which a spline should be fit. - * \param[out] chord_lengths The resulting chord length vector. - * - * \sa Les Piegl and Wayne Tiller, The NURBS book (2nd ed.), 1997, 9.2.1 Global Curve Interpolation to Point Data - **/ - template <typename PointArrayType, typename KnotVectorType> - void ChordLengths(const PointArrayType& pts, KnotVectorType& chord_lengths) - { - typedef typename KnotVectorType::Scalar Scalar; - - const DenseIndex n = pts.cols(); - - // 1. compute the column-wise norms - chord_lengths.resize(pts.cols()); - chord_lengths[0] = 0; - chord_lengths.rightCols(n-1) = (pts.array().leftCols(n-1) - pts.array().rightCols(n-1)).matrix().colwise().norm(); - - // 2. compute the partial sums - std::partial_sum(chord_lengths.data(), chord_lengths.data()+n, chord_lengths.data()); - - // 3. normalize the data - chord_lengths /= chord_lengths(n-1); - chord_lengths(n-1) = Scalar(1); - } - - /** - * \brief Spline fitting methods. - * \ingroup Splines_Module - **/ - template <typename SplineType> - struct SplineFitting - { - typedef typename SplineType::KnotVectorType KnotVectorType; - typedef typename SplineType::ParameterVectorType ParameterVectorType; - - /** - * \brief Fits an interpolating Spline to the given data points. - * - * \param pts The points for which an interpolating spline will be computed. - * \param degree The degree of the interpolating spline. - * - * \returns A spline interpolating the initially provided points. - **/ - template <typename PointArrayType> - static SplineType Interpolate(const PointArrayType& pts, DenseIndex degree); - - /** - * \brief Fits an interpolating Spline to the given data points. - * - * \param pts The points for which an interpolating spline will be computed. - * \param degree The degree of the interpolating spline. - * \param knot_parameters The knot parameters for the interpolation. - * - * \returns A spline interpolating the initially provided points. - **/ - template <typename PointArrayType> - static SplineType Interpolate(const PointArrayType& pts, DenseIndex degree, const KnotVectorType& knot_parameters); - - /** - * \brief Fits an interpolating spline to the given data points and - * derivatives. - * - * \param points The points for which an interpolating spline will be computed. - * \param derivatives The desired derivatives of the interpolating spline at interpolation - * points. - * \param derivativeIndices An array indicating which point each derivative belongs to. This - * must be the same size as @a derivatives. - * \param degree The degree of the interpolating spline. - * - * \returns A spline interpolating @a points with @a derivatives at those points. - * - * \sa Les A. Piegl, Khairan Rajab, Volha Smarodzinana. 2008. - * Curve interpolation with directional constraints for engineering design. - * Engineering with Computers - **/ - template <typename PointArrayType, typename IndexArray> - static SplineType InterpolateWithDerivatives(const PointArrayType& points, - const PointArrayType& derivatives, - const IndexArray& derivativeIndices, - const unsigned int degree); - - /** - * \brief Fits an interpolating spline to the given data points and derivatives. - * - * \param points The points for which an interpolating spline will be computed. - * \param derivatives The desired derivatives of the interpolating spline at interpolation points. - * \param derivativeIndices An array indicating which point each derivative belongs to. This - * must be the same size as @a derivatives. - * \param degree The degree of the interpolating spline. - * \param parameters The parameters corresponding to the interpolation points. - * - * \returns A spline interpolating @a points with @a derivatives at those points. - * - * \sa Les A. Piegl, Khairan Rajab, Volha Smarodzinana. 2008. - * Curve interpolation with directional constraints for engineering design. - * Engineering with Computers - */ - template <typename PointArrayType, typename IndexArray> - static SplineType InterpolateWithDerivatives(const PointArrayType& points, - const PointArrayType& derivatives, - const IndexArray& derivativeIndices, - const unsigned int degree, - const ParameterVectorType& parameters); - }; - - template <typename SplineType> - template <typename PointArrayType> - SplineType SplineFitting<SplineType>::Interpolate(const PointArrayType& pts, DenseIndex degree, const KnotVectorType& knot_parameters) - { - typedef typename SplineType::KnotVectorType::Scalar Scalar; - typedef typename SplineType::ControlPointVectorType ControlPointVectorType; - - typedef Matrix<Scalar,Dynamic,Dynamic> MatrixType; - - KnotVectorType knots; - KnotAveraging(knot_parameters, degree, knots); - - DenseIndex n = pts.cols(); - MatrixType A = MatrixType::Zero(n,n); - for (DenseIndex i=1; i<n-1; ++i) - { - const DenseIndex span = SplineType::Span(knot_parameters[i], degree, knots); - - // The segment call should somehow be told the spline order at compile time. - A.row(i).segment(span-degree, degree+1) = SplineType::BasisFunctions(knot_parameters[i], degree, knots); - } - A(0,0) = 1.0; - A(n-1,n-1) = 1.0; - - HouseholderQR<MatrixType> qr(A); - - // Here, we are creating a temporary due to an Eigen issue. - ControlPointVectorType ctrls = qr.solve(MatrixType(pts.transpose())).transpose(); - - return SplineType(knots, ctrls); - } - - template <typename SplineType> - template <typename PointArrayType> - SplineType SplineFitting<SplineType>::Interpolate(const PointArrayType& pts, DenseIndex degree) - { - KnotVectorType chord_lengths; // knot parameters - ChordLengths(pts, chord_lengths); - return Interpolate(pts, degree, chord_lengths); - } - - template <typename SplineType> - template <typename PointArrayType, typename IndexArray> - SplineType - SplineFitting<SplineType>::InterpolateWithDerivatives(const PointArrayType& points, - const PointArrayType& derivatives, - const IndexArray& derivativeIndices, - const unsigned int degree, - const ParameterVectorType& parameters) - { - typedef typename SplineType::KnotVectorType::Scalar Scalar; - typedef typename SplineType::ControlPointVectorType ControlPointVectorType; - - typedef Matrix<Scalar, Dynamic, Dynamic> MatrixType; - - const DenseIndex n = points.cols() + derivatives.cols(); - - KnotVectorType knots; - - KnotAveragingWithDerivatives(parameters, degree, derivativeIndices, knots); - - // fill matrix - MatrixType A = MatrixType::Zero(n, n); - - // Use these dimensions for quicker populating, then transpose for solving. - MatrixType b(points.rows(), n); - - DenseIndex startRow; - DenseIndex derivativeStart; - - // End derivatives. - if (derivativeIndices[0] == 0) - { - A.template block<1, 2>(1, 0) << -1, 1; - - Scalar y = (knots(degree + 1) - knots(0)) / degree; - b.col(1) = y*derivatives.col(0); - - startRow = 2; - derivativeStart = 1; - } - else - { - startRow = 1; - derivativeStart = 0; - } - if (derivativeIndices[derivatives.cols() - 1] == points.cols() - 1) - { - A.template block<1, 2>(n - 2, n - 2) << -1, 1; - - Scalar y = (knots(knots.size() - 1) - knots(knots.size() - (degree + 2))) / degree; - b.col(b.cols() - 2) = y*derivatives.col(derivatives.cols() - 1); - } - - DenseIndex row = startRow; - DenseIndex derivativeIndex = derivativeStart; - for (DenseIndex i = 1; i < parameters.size() - 1; ++i) - { - const DenseIndex span = SplineType::Span(parameters[i], degree, knots); - - if (derivativeIndex < derivativeIndices.size() && derivativeIndices[derivativeIndex] == i) - { - A.block(row, span - degree, 2, degree + 1) - = SplineType::BasisFunctionDerivatives(parameters[i], 1, degree, knots); - - b.col(row++) = points.col(i); - b.col(row++) = derivatives.col(derivativeIndex++); - } - else - { - A.row(row).segment(span - degree, degree + 1) - = SplineType::BasisFunctions(parameters[i], degree, knots); - b.col(row++) = points.col(i); - } - } - b.col(0) = points.col(0); - b.col(b.cols() - 1) = points.col(points.cols() - 1); - A(0,0) = 1; - A(n - 1, n - 1) = 1; - - // Solve - FullPivLU<MatrixType> lu(A); - ControlPointVectorType controlPoints = lu.solve(MatrixType(b.transpose())).transpose(); - - SplineType spline(knots, controlPoints); - - return spline; - } - - template <typename SplineType> - template <typename PointArrayType, typename IndexArray> - SplineType - SplineFitting<SplineType>::InterpolateWithDerivatives(const PointArrayType& points, - const PointArrayType& derivatives, - const IndexArray& derivativeIndices, - const unsigned int degree) - { - ParameterVectorType parameters; - ChordLengths(points, parameters); - return InterpolateWithDerivatives(points, derivatives, derivativeIndices, degree, parameters); - } -} - -#endif // EIGEN_SPLINE_FITTING_H diff --git a/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/SplineFwd.h b/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/SplineFwd.h deleted file mode 100644 index 00d6b492..00000000 --- a/external/eigen/include/eigen3/unsupported/Eigen/src/Splines/SplineFwd.h +++ /dev/null @@ -1,93 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 20010-2011 Hauke Heibel <hauke.heibel@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef EIGEN_SPLINES_FWD_H -#define EIGEN_SPLINES_FWD_H - -#include "../../../../Eigen/Core" - -namespace Eigen -{ - template <typename Scalar, int Dim, int Degree = Dynamic> class Spline; - - template < typename SplineType, int DerivativeOrder = Dynamic > struct SplineTraits {}; - - /** - * \ingroup Splines_Module - * \brief Compile-time attributes of the Spline class for Dynamic degree. - **/ - template <typename _Scalar, int _Dim, int _Degree> - struct SplineTraits< Spline<_Scalar, _Dim, _Degree>, Dynamic > - { - typedef _Scalar Scalar; /*!< The spline curve's scalar type. */ - enum { Dimension = _Dim /*!< The spline curve's dimension. */ }; - enum { Degree = _Degree /*!< The spline curve's degree. */ }; - - enum { OrderAtCompileTime = _Degree==Dynamic ? Dynamic : _Degree+1 /*!< The spline curve's order at compile-time. */ }; - enum { NumOfDerivativesAtCompileTime = OrderAtCompileTime /*!< The number of derivatives defined for the current spline. */ }; - - enum { DerivativeMemoryLayout = Dimension==1 ? RowMajor : ColMajor /*!< The derivative type's memory layout. */ }; - - /** \brief The data type used to store non-zero basis functions. */ - typedef Array<Scalar,1,OrderAtCompileTime> BasisVectorType; - - /** \brief The data type used to store the values of the basis function derivatives. */ - typedef Array<Scalar,Dynamic,Dynamic,RowMajor,NumOfDerivativesAtCompileTime,OrderAtCompileTime> BasisDerivativeType; - - /** \brief The data type used to store the spline's derivative values. */ - typedef Array<Scalar,Dimension,Dynamic,DerivativeMemoryLayout,Dimension,NumOfDerivativesAtCompileTime> DerivativeType; - - /** \brief The point type the spline is representing. */ - typedef Array<Scalar,Dimension,1> PointType; - - /** \brief The data type used to store knot vectors. */ - typedef Array<Scalar,1,Dynamic> KnotVectorType; - - /** \brief The data type used to store parameter vectors. */ - typedef Array<Scalar,1,Dynamic> ParameterVectorType; - - /** \brief The data type representing the spline's control points. */ - typedef Array<Scalar,Dimension,Dynamic> ControlPointVectorType; - }; - - /** - * \ingroup Splines_Module - * \brief Compile-time attributes of the Spline class for fixed degree. - * - * The traits class inherits all attributes from the SplineTraits of Dynamic degree. - **/ - template < typename _Scalar, int _Dim, int _Degree, int _DerivativeOrder > - struct SplineTraits< Spline<_Scalar, _Dim, _Degree>, _DerivativeOrder > : public SplineTraits< Spline<_Scalar, _Dim, _Degree> > - { - enum { OrderAtCompileTime = _Degree==Dynamic ? Dynamic : _Degree+1 /*!< The spline curve's order at compile-time. */ }; - enum { NumOfDerivativesAtCompileTime = _DerivativeOrder==Dynamic ? Dynamic : _DerivativeOrder+1 /*!< The number of derivatives defined for the current spline. */ }; - - enum { DerivativeMemoryLayout = _Dim==1 ? RowMajor : ColMajor /*!< The derivative type's memory layout. */ }; - - /** \brief The data type used to store the values of the basis function derivatives. */ - typedef Array<_Scalar,Dynamic,Dynamic,RowMajor,NumOfDerivativesAtCompileTime,OrderAtCompileTime> BasisDerivativeType; - - /** \brief The data type used to store the spline's derivative values. */ - typedef Array<_Scalar,_Dim,Dynamic,DerivativeMemoryLayout,_Dim,NumOfDerivativesAtCompileTime> DerivativeType; - }; - - /** \brief 2D float B-spline with dynamic degree. */ - typedef Spline<float,2> Spline2f; - - /** \brief 3D float B-spline with dynamic degree. */ - typedef Spline<float,3> Spline3f; - - /** \brief 2D double B-spline with dynamic degree. */ - typedef Spline<double,2> Spline2d; - - /** \brief 3D double B-spline with dynamic degree. */ - typedef Spline<double,3> Spline3d; -} - -#endif // EIGEN_SPLINES_FWD_H diff --git a/external/eigen/share/eigen3/cmake/Eigen3Config.cmake b/external/eigen/share/eigen3/cmake/Eigen3Config.cmake deleted file mode 100644 index c2af93f6..00000000 --- a/external/eigen/share/eigen3/cmake/Eigen3Config.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# This file exports the Eigen3::Eigen CMake target which should be passed to the -# target_link_libraries command. - - -####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### -####### Any changes to this file will be overwritten by the next CMake run #### -####### The input file was Eigen3Config.cmake.in ######## - -get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) - -macro(set_and_check _var _file) - set(${_var} "${_file}") - if(NOT EXISTS "${_file}") - message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") - endif() -endmacro() - -#################################################################################### - -if (NOT TARGET eigen) - include ("${CMAKE_CURRENT_LIST_DIR}/Eigen3Targets.cmake") -endif () - -# Legacy variables, do *not* use. May be removed in the future. - -set (EIGEN3_FOUND 1) -set (EIGEN3_USE_FILE "${CMAKE_CURRENT_LIST_DIR}/UseEigen3.cmake") - -set (EIGEN3_DEFINITIONS "") -set (EIGEN3_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include/eigen3") -set (EIGEN3_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/eigen3") -set (EIGEN3_ROOT_DIR "${PACKAGE_PREFIX_DIR}") - -set (EIGEN3_VERSION_STRING "3.3.90") -set (EIGEN3_VERSION_MAJOR "3") -set (EIGEN3_VERSION_MINOR "3") -set (EIGEN3_VERSION_PATCH "90") diff --git a/external/eigen/share/eigen3/cmake/Eigen3ConfigVersion.cmake b/external/eigen/share/eigen3/cmake/Eigen3ConfigVersion.cmake deleted file mode 100644 index 40037023..00000000 --- a/external/eigen/share/eigen3/cmake/Eigen3ConfigVersion.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# This is a basic version file for the Config-mode of find_package(). -# It is used by write_basic_package_version_file() as input file for configure_file() -# to create a version-file which can be installed along a config.cmake file. -# -# The created file sets PACKAGE_VERSION_EXACT if the current version string and -# the requested version string are exactly the same and it sets -# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, -# but only if the requested major version is the same as the current one. -# The variable CVF_VERSION must be set before calling configure_file(). - - -set(PACKAGE_VERSION "3.3.90") - -if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - - if("3.3.90" MATCHES "^([0-9]+)\\.") - set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") - else() - set(CVF_VERSION_MAJOR "3.3.90") - endif() - - if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) - set(PACKAGE_VERSION_COMPATIBLE TRUE) - else() - set(PACKAGE_VERSION_COMPATIBLE FALSE) - endif() - - if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() - - -# if the installed project requested no architecture check, don't perform the check -if("FALSE") - return() -endif() - -# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: -if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "" STREQUAL "") - return() -endif() - -# check that the installed version has the same 32/64bit-ness as the one which is currently searching: -if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "") - math(EXPR installedBits " * 8") - set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") - set(PACKAGE_VERSION_UNSUITABLE TRUE) -endif() diff --git a/external/eigen/share/eigen3/cmake/Eigen3Targets.cmake b/external/eigen/share/eigen3/cmake/Eigen3Targets.cmake deleted file mode 100644 index f08a4579..00000000 --- a/external/eigen/share/eigen3/cmake/Eigen3Targets.cmake +++ /dev/null @@ -1,98 +0,0 @@ -# Generated by CMake - -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) - message(FATAL_ERROR "CMake >= 2.6.0 required") -endif() -cmake_policy(PUSH) -cmake_policy(VERSION 2.6) -#---------------------------------------------------------------- -# Generated CMake target import file. -#---------------------------------------------------------------- - -# Commands may need to know the format version. -set(CMAKE_IMPORT_FILE_VERSION 1) - -# Protect against multiple inclusion, which would fail when already imported targets are added once more. -set(_targetsDefined) -set(_targetsNotDefined) -set(_expectedTargets) -foreach(_expectedTarget Eigen3::Eigen) - list(APPEND _expectedTargets ${_expectedTarget}) - if(NOT TARGET ${_expectedTarget}) - list(APPEND _targetsNotDefined ${_expectedTarget}) - endif() - if(TARGET ${_expectedTarget}) - list(APPEND _targetsDefined ${_expectedTarget}) - endif() -endforeach() -if("${_targetsDefined}" STREQUAL "${_expectedTargets}") - unset(_targetsDefined) - unset(_targetsNotDefined) - unset(_expectedTargets) - set(CMAKE_IMPORT_FILE_VERSION) - cmake_policy(POP) - return() -endif() -if(NOT "${_targetsDefined}" STREQUAL "") - message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") -endif() -unset(_targetsDefined) -unset(_targetsNotDefined) -unset(_expectedTargets) - - -# Compute the installation prefix relative to this file. -get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -if(_IMPORT_PREFIX STREQUAL "/") - set(_IMPORT_PREFIX "") -endif() - -# Create imported target Eigen3::Eigen -add_library(Eigen3::Eigen INTERFACE IMPORTED) - -set_target_properties(Eigen3::Eigen PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/eigen3" -) - -if(CMAKE_VERSION VERSION_LESS 3.0.0) - message(FATAL_ERROR "This file relies on consumers using CMake 3.0.0 or greater.") -endif() - -# Load information for each installed configuration. -get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -file(GLOB CONFIG_FILES "${_DIR}/Eigen3Targets-*.cmake") -foreach(f ${CONFIG_FILES}) - include(${f}) -endforeach() - -# Cleanup temporary variables. -set(_IMPORT_PREFIX) - -# Loop over all imported files and verify that they actually exist -foreach(target ${_IMPORT_CHECK_TARGETS} ) - foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) - if(NOT EXISTS "${file}" ) - message(FATAL_ERROR "The imported target \"${target}\" references the file - \"${file}\" -but this file does not exist. Possible reasons include: -* The file was deleted, renamed, or moved to another location. -* An install or uninstall procedure did not complete successfully. -* The installation package was faulty and contained - \"${CMAKE_CURRENT_LIST_FILE}\" -but not all the files it references. -") - endif() - endforeach() - unset(_IMPORT_CHECK_FILES_FOR_${target}) -endforeach() -unset(_IMPORT_CHECK_TARGETS) - -# This file does not depend on other imported targets which have -# been exported from the same project but in a separate export set. - -# Commands beyond this point should not need to know the version. -set(CMAKE_IMPORT_FILE_VERSION) -cmake_policy(POP) diff --git a/external/eigen/share/eigen3/cmake/UseEigen3.cmake b/external/eigen/share/eigen3/cmake/UseEigen3.cmake deleted file mode 100644 index a38bac82..00000000 --- a/external/eigen/share/eigen3/cmake/UseEigen3.cmake +++ /dev/null @@ -1,6 +0,0 @@ -# -*- cmake -*- -# -# UseEigen3.cmake - -add_definitions ( ${EIGEN3_DEFINITIONS} ) -include_directories ( ${EIGEN3_INCLUDE_DIRS} ) diff --git a/external/pybind11 b/external/pybind11 new file mode 160000 index 00000000..3b1dbeba --- /dev/null +++ b/external/pybind11 @@ -0,0 +1 @@ +Subproject commit 3b1dbebabc801c9cf6f0953a4c20b904d444f879 diff --git a/external/pybind11/include/pybind11/attr.h b/external/pybind11/include/pybind11/attr.h deleted file mode 100644 index 6962d6fc..00000000 --- a/external/pybind11/include/pybind11/attr.h +++ /dev/null @@ -1,493 +0,0 @@ -/* - pybind11/attr.h: Infrastructure for processing custom - type and function attributes - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "cast.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -/// \addtogroup annotations -/// @{ - -/// Annotation for methods -struct is_method { handle class_; is_method(const handle &c) : class_(c) { } }; - -/// Annotation for operators -struct is_operator { }; - -/// Annotation for parent scope -struct scope { handle value; scope(const handle &s) : value(s) { } }; - -/// Annotation for documentation -struct doc { const char *value; doc(const char *value) : value(value) { } }; - -/// Annotation for function names -struct name { const char *value; name(const char *value) : value(value) { } }; - -/// Annotation indicating that a function is an overload associated with a given "sibling" -struct sibling { handle value; sibling(const handle &value) : value(value.ptr()) { } }; - -/// Annotation indicating that a class derives from another given type -template <typename T> struct base { - PYBIND11_DEPRECATED("base<T>() was deprecated in favor of specifying 'T' as a template argument to class_") - base() { } -}; - -/// Keep patient alive while nurse lives -template <size_t Nurse, size_t Patient> struct keep_alive { }; - -/// Annotation indicating that a class is involved in a multiple inheritance relationship -struct multiple_inheritance { }; - -/// Annotation which enables dynamic attributes, i.e. adds `__dict__` to a class -struct dynamic_attr { }; - -/// Annotation which enables the buffer protocol for a type -struct buffer_protocol { }; - -/// Annotation which requests that a special metaclass is created for a type -struct metaclass { - handle value; - - PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.") - metaclass() {} - - /// Override pybind11's default metaclass - explicit metaclass(handle value) : value(value) { } -}; - -/// Annotation that marks a class as local to the module: -struct module_local { const bool value; constexpr module_local(bool v = true) : value(v) { } }; - -/// Annotation to mark enums as an arithmetic type -struct arithmetic { }; - -/** \rst - A call policy which places one or more guard variables (``Ts...``) around the function call. - - For example, this definition: - - .. code-block:: cpp - - m.def("foo", foo, py::call_guard<T>()); - - is equivalent to the following pseudocode: - - .. code-block:: cpp - - m.def("foo", [](args...) { - T scope_guard; - return foo(args...); // forwarded arguments - }); - \endrst */ -template <typename... Ts> struct call_guard; - -template <> struct call_guard<> { using type = detail::void_type; }; - -template <typename T> -struct call_guard<T> { - static_assert(std::is_default_constructible<T>::value, - "The guard type must be default constructible"); - - using type = T; -}; - -template <typename T, typename... Ts> -struct call_guard<T, Ts...> { - struct type { - T guard{}; // Compose multiple guard types with left-to-right default-constructor order - typename call_guard<Ts...>::type next{}; - }; -}; - -/// @} annotations - -NAMESPACE_BEGIN(detail) -/* Forward declarations */ -enum op_id : int; -enum op_type : int; -struct undefined_t; -template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t> struct op_; -inline void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret); - -/// Internal data structure which holds metadata about a keyword argument -struct argument_record { - const char *name; ///< Argument name - const char *descr; ///< Human-readable version of the argument value - handle value; ///< Associated Python object - bool convert : 1; ///< True if the argument is allowed to convert when loading - bool none : 1; ///< True if None is allowed when loading - - argument_record(const char *name, const char *descr, handle value, bool convert, bool none) - : name(name), descr(descr), value(value), convert(convert), none(none) { } -}; - -/// Internal data structure which holds metadata about a bound function (signature, overloads, etc.) -struct function_record { - function_record() - : is_constructor(false), is_new_style_constructor(false), is_stateless(false), - is_operator(false), has_args(false), has_kwargs(false), is_method(false) { } - - /// Function name - char *name = nullptr; /* why no C++ strings? They generate heavier code.. */ - - // User-specified documentation string - char *doc = nullptr; - - /// Human-readable version of the function signature - char *signature = nullptr; - - /// List of registered keyword arguments - std::vector<argument_record> args; - - /// Pointer to lambda function which converts arguments and performs the actual call - handle (*impl) (function_call &) = nullptr; - - /// Storage for the wrapped function pointer and captured data, if any - void *data[3] = { }; - - /// Pointer to custom destructor for 'data' (if needed) - void (*free_data) (function_record *ptr) = nullptr; - - /// Return value policy associated with this function - return_value_policy policy = return_value_policy::automatic; - - /// True if name == '__init__' - bool is_constructor : 1; - - /// True if this is a new-style `__init__` defined in `detail/init.h` - bool is_new_style_constructor : 1; - - /// True if this is a stateless function pointer - bool is_stateless : 1; - - /// True if this is an operator (__add__), etc. - bool is_operator : 1; - - /// True if the function has a '*args' argument - bool has_args : 1; - - /// True if the function has a '**kwargs' argument - bool has_kwargs : 1; - - /// True if this is a method - bool is_method : 1; - - /// Number of arguments (including py::args and/or py::kwargs, if present) - std::uint16_t nargs; - - /// Python method object - PyMethodDef *def = nullptr; - - /// Python handle to the parent scope (a class or a module) - handle scope; - - /// Python handle to the sibling function representing an overload chain - handle sibling; - - /// Pointer to next overload - function_record *next = nullptr; -}; - -/// Special data structure which (temporarily) holds metadata about a bound class -struct type_record { - PYBIND11_NOINLINE type_record() - : multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false), - default_holder(true), module_local(false) { } - - /// Handle to the parent scope - handle scope; - - /// Name of the class - const char *name = nullptr; - - // Pointer to RTTI type_info data structure - const std::type_info *type = nullptr; - - /// How large is the underlying C++ type? - size_t type_size = 0; - - /// What is the alignment of the underlying C++ type? - size_t type_align = 0; - - /// How large is the type's holder? - size_t holder_size = 0; - - /// The global operator new can be overridden with a class-specific variant - void *(*operator_new)(size_t) = nullptr; - - /// Function pointer to class_<..>::init_instance - void (*init_instance)(instance *, const void *) = nullptr; - - /// Function pointer to class_<..>::dealloc - void (*dealloc)(detail::value_and_holder &) = nullptr; - - /// List of base classes of the newly created type - list bases; - - /// Optional docstring - const char *doc = nullptr; - - /// Custom metaclass (optional) - handle metaclass; - - /// Multiple inheritance marker - bool multiple_inheritance : 1; - - /// Does the class manage a __dict__? - bool dynamic_attr : 1; - - /// Does the class implement the buffer protocol? - bool buffer_protocol : 1; - - /// Is the default (unique_ptr) holder type used? - bool default_holder : 1; - - /// Is the class definition local to the module shared object? - bool module_local : 1; - - PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *)) { - auto base_info = detail::get_type_info(base, false); - if (!base_info) { - std::string tname(base.name()); - detail::clean_type_id(tname); - pybind11_fail("generic_type: type \"" + std::string(name) + - "\" referenced unknown base type \"" + tname + "\""); - } - - if (default_holder != base_info->default_holder) { - std::string tname(base.name()); - detail::clean_type_id(tname); - pybind11_fail("generic_type: type \"" + std::string(name) + "\" " + - (default_holder ? "does not have" : "has") + - " a non-default holder type while its base \"" + tname + "\" " + - (base_info->default_holder ? "does not" : "does")); - } - - bases.append((PyObject *) base_info->type); - - if (base_info->type->tp_dictoffset != 0) - dynamic_attr = true; - - if (caster) - base_info->implicit_casts.emplace_back(type, caster); - } -}; - -inline function_call::function_call(const function_record &f, handle p) : - func(f), parent(p) { - args.reserve(f.nargs); - args_convert.reserve(f.nargs); -} - -/// Tag for a new-style `__init__` defined in `detail/init.h` -struct is_new_style_constructor { }; - -/** - * Partial template specializations to process custom attributes provided to - * cpp_function_ and class_. These are either used to initialize the respective - * fields in the type_record and function_record data structures or executed at - * runtime to deal with custom call policies (e.g. keep_alive). - */ -template <typename T, typename SFINAE = void> struct process_attribute; - -template <typename T> struct process_attribute_default { - /// Default implementation: do nothing - static void init(const T &, function_record *) { } - static void init(const T &, type_record *) { } - static void precall(function_call &) { } - static void postcall(function_call &, handle) { } -}; - -/// Process an attribute specifying the function's name -template <> struct process_attribute<name> : process_attribute_default<name> { - static void init(const name &n, function_record *r) { r->name = const_cast<char *>(n.value); } -}; - -/// Process an attribute specifying the function's docstring -template <> struct process_attribute<doc> : process_attribute_default<doc> { - static void init(const doc &n, function_record *r) { r->doc = const_cast<char *>(n.value); } -}; - -/// Process an attribute specifying the function's docstring (provided as a C-style string) -template <> struct process_attribute<const char *> : process_attribute_default<const char *> { - static void init(const char *d, function_record *r) { r->doc = const_cast<char *>(d); } - static void init(const char *d, type_record *r) { r->doc = const_cast<char *>(d); } -}; -template <> struct process_attribute<char *> : process_attribute<const char *> { }; - -/// Process an attribute indicating the function's return value policy -template <> struct process_attribute<return_value_policy> : process_attribute_default<return_value_policy> { - static void init(const return_value_policy &p, function_record *r) { r->policy = p; } -}; - -/// Process an attribute which indicates that this is an overloaded function associated with a given sibling -template <> struct process_attribute<sibling> : process_attribute_default<sibling> { - static void init(const sibling &s, function_record *r) { r->sibling = s.value; } -}; - -/// Process an attribute which indicates that this function is a method -template <> struct process_attribute<is_method> : process_attribute_default<is_method> { - static void init(const is_method &s, function_record *r) { r->is_method = true; r->scope = s.class_; } -}; - -/// Process an attribute which indicates the parent scope of a method -template <> struct process_attribute<scope> : process_attribute_default<scope> { - static void init(const scope &s, function_record *r) { r->scope = s.value; } -}; - -/// Process an attribute which indicates that this function is an operator -template <> struct process_attribute<is_operator> : process_attribute_default<is_operator> { - static void init(const is_operator &, function_record *r) { r->is_operator = true; } -}; - -template <> struct process_attribute<is_new_style_constructor> : process_attribute_default<is_new_style_constructor> { - static void init(const is_new_style_constructor &, function_record *r) { r->is_new_style_constructor = true; } -}; - -/// Process a keyword argument attribute (*without* a default value) -template <> struct process_attribute<arg> : process_attribute_default<arg> { - static void init(const arg &a, function_record *r) { - if (r->is_method && r->args.empty()) - r->args.emplace_back("self", nullptr, handle(), true /*convert*/, false /*none not allowed*/); - r->args.emplace_back(a.name, nullptr, handle(), !a.flag_noconvert, a.flag_none); - } -}; - -/// Process a keyword argument attribute (*with* a default value) -template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> { - static void init(const arg_v &a, function_record *r) { - if (r->is_method && r->args.empty()) - r->args.emplace_back("self", nullptr /*descr*/, handle() /*parent*/, true /*convert*/, false /*none not allowed*/); - - if (!a.value) { -#if !defined(NDEBUG) - std::string descr("'"); - if (a.name) descr += std::string(a.name) + ": "; - descr += a.type + "'"; - if (r->is_method) { - if (r->name) - descr += " in method '" + (std::string) str(r->scope) + "." + (std::string) r->name + "'"; - else - descr += " in method of '" + (std::string) str(r->scope) + "'"; - } else if (r->name) { - descr += " in function '" + (std::string) r->name + "'"; - } - pybind11_fail("arg(): could not convert default argument " - + descr + " into a Python object (type not registered yet?)"); -#else - pybind11_fail("arg(): could not convert default argument " - "into a Python object (type not registered yet?). " - "Compile in debug mode for more information."); -#endif - } - r->args.emplace_back(a.name, a.descr, a.value.inc_ref(), !a.flag_noconvert, a.flag_none); - } -}; - -/// Process a parent class attribute. Single inheritance only (class_ itself already guarantees that) -template <typename T> -struct process_attribute<T, enable_if_t<is_pyobject<T>::value>> : process_attribute_default<handle> { - static void init(const handle &h, type_record *r) { r->bases.append(h); } -}; - -/// Process a parent class attribute (deprecated, does not support multiple inheritance) -template <typename T> -struct process_attribute<base<T>> : process_attribute_default<base<T>> { - static void init(const base<T> &, type_record *r) { r->add_base(typeid(T), nullptr); } -}; - -/// Process a multiple inheritance attribute -template <> -struct process_attribute<multiple_inheritance> : process_attribute_default<multiple_inheritance> { - static void init(const multiple_inheritance &, type_record *r) { r->multiple_inheritance = true; } -}; - -template <> -struct process_attribute<dynamic_attr> : process_attribute_default<dynamic_attr> { - static void init(const dynamic_attr &, type_record *r) { r->dynamic_attr = true; } -}; - -template <> -struct process_attribute<buffer_protocol> : process_attribute_default<buffer_protocol> { - static void init(const buffer_protocol &, type_record *r) { r->buffer_protocol = true; } -}; - -template <> -struct process_attribute<metaclass> : process_attribute_default<metaclass> { - static void init(const metaclass &m, type_record *r) { r->metaclass = m.value; } -}; - -template <> -struct process_attribute<module_local> : process_attribute_default<module_local> { - static void init(const module_local &l, type_record *r) { r->module_local = l.value; } -}; - -/// Process an 'arithmetic' attribute for enums (does nothing here) -template <> -struct process_attribute<arithmetic> : process_attribute_default<arithmetic> {}; - -template <typename... Ts> -struct process_attribute<call_guard<Ts...>> : process_attribute_default<call_guard<Ts...>> { }; - -/** - * Process a keep_alive call policy -- invokes keep_alive_impl during the - * pre-call handler if both Nurse, Patient != 0 and use the post-call handler - * otherwise - */ -template <size_t Nurse, size_t Patient> struct process_attribute<keep_alive<Nurse, Patient>> : public process_attribute_default<keep_alive<Nurse, Patient>> { - template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0> - static void precall(function_call &call) { keep_alive_impl(Nurse, Patient, call, handle()); } - template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0> - static void postcall(function_call &, handle) { } - template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0> - static void precall(function_call &) { } - template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0> - static void postcall(function_call &call, handle ret) { keep_alive_impl(Nurse, Patient, call, ret); } -}; - -/// Recursively iterate over variadic template arguments -template <typename... Args> struct process_attributes { - static void init(const Args&... args, function_record *r) { - int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... }; - ignore_unused(unused); - } - static void init(const Args&... args, type_record *r) { - int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... }; - ignore_unused(unused); - } - static void precall(function_call &call) { - int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::precall(call), 0) ... }; - ignore_unused(unused); - } - static void postcall(function_call &call, handle fn_ret) { - int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0) ... }; - ignore_unused(unused); - } -}; - -template <typename T> -using is_call_guard = is_instantiation<call_guard, T>; - -/// Extract the ``type`` from the first `call_guard` in `Extras...` (or `void_type` if none found) -template <typename... Extra> -using extract_guard_t = typename exactly_one_t<is_call_guard, call_guard<>, Extra...>::type; - -/// Check the number of named arguments at compile time -template <typename... Extra, - size_t named = constexpr_sum(std::is_base_of<arg, Extra>::value...), - size_t self = constexpr_sum(std::is_same<is_method, Extra>::value...)> -constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) { - return named == 0 || (self + named + has_args + has_kwargs) == nargs; -} - -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/buffer_info.h b/external/pybind11/include/pybind11/buffer_info.h deleted file mode 100644 index b106d2cc..00000000 --- a/external/pybind11/include/pybind11/buffer_info.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - pybind11/buffer_info.h: Python buffer object interface - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "detail/common.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -/// Information record describing a Python buffer object -struct buffer_info { - void *ptr = nullptr; // Pointer to the underlying storage - ssize_t itemsize = 0; // Size of individual items in bytes - ssize_t size = 0; // Total number of entries - std::string format; // For homogeneous buffers, this should be set to format_descriptor<T>::format() - ssize_t ndim = 0; // Number of dimensions - std::vector<ssize_t> shape; // Shape of the tensor (1 entry per dimension) - std::vector<ssize_t> strides; // Number of bytes between adjacent entries (for each per dimension) - - buffer_info() { } - - buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, - detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in) - : ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim), - shape(std::move(shape_in)), strides(std::move(strides_in)) { - if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size()) - pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length"); - for (size_t i = 0; i < (size_t) ndim; ++i) - size *= shape[i]; - } - - template <typename T> - buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in) - : buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor<T>::format(), static_cast<ssize_t>(shape_in->size()), std::move(shape_in), std::move(strides_in)) { } - - buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size) - : buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}) { } - - template <typename T> - buffer_info(T *ptr, ssize_t size) - : buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size) { } - - explicit buffer_info(Py_buffer *view, bool ownview = true) - : buffer_info(view->buf, view->itemsize, view->format, view->ndim, - {view->shape, view->shape + view->ndim}, {view->strides, view->strides + view->ndim}) { - this->view = view; - this->ownview = ownview; - } - - buffer_info(const buffer_info &) = delete; - buffer_info& operator=(const buffer_info &) = delete; - - buffer_info(buffer_info &&other) { - (*this) = std::move(other); - } - - buffer_info& operator=(buffer_info &&rhs) { - ptr = rhs.ptr; - itemsize = rhs.itemsize; - size = rhs.size; - format = std::move(rhs.format); - ndim = rhs.ndim; - shape = std::move(rhs.shape); - strides = std::move(rhs.strides); - std::swap(view, rhs.view); - std::swap(ownview, rhs.ownview); - return *this; - } - - ~buffer_info() { - if (view && ownview) { PyBuffer_Release(view); delete view; } - } - -private: - struct private_ctr_tag { }; - - buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, - detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in) - : buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in)) { } - - Py_buffer *view = nullptr; - bool ownview = false; -}; - -NAMESPACE_BEGIN(detail) - -template <typename T, typename SFINAE = void> struct compare_buffer_info { - static bool compare(const buffer_info& b) { - return b.format == format_descriptor<T>::format() && b.itemsize == (ssize_t) sizeof(T); - } -}; - -template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_integral<T>::value>> { - static bool compare(const buffer_info& b) { - return (size_t) b.itemsize == sizeof(T) && (b.format == format_descriptor<T>::value || - ((sizeof(T) == sizeof(long)) && b.format == (std::is_unsigned<T>::value ? "L" : "l")) || - ((sizeof(T) == sizeof(size_t)) && b.format == (std::is_unsigned<T>::value ? "N" : "n"))); - } -}; - -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/cast.h b/external/pybind11/include/pybind11/cast.h deleted file mode 100644 index 90407eb9..00000000 --- a/external/pybind11/include/pybind11/cast.h +++ /dev/null @@ -1,2157 +0,0 @@ -/* - pybind11/cast.h: Partial template specializations to cast between - C++ and Python types - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pytypes.h" -#include "detail/typeid.h" -#include "detail/descr.h" -#include "detail/internals.h" -#include <array> -#include <limits> -#include <tuple> -#include <type_traits> - -#if defined(PYBIND11_CPP17) -# if defined(__has_include) -# if __has_include(<string_view>) -# define PYBIND11_HAS_STRING_VIEW -# endif -# elif defined(_MSC_VER) -# define PYBIND11_HAS_STRING_VIEW -# endif -#endif -#ifdef PYBIND11_HAS_STRING_VIEW -#include <string_view> -#endif - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -/// A life support system for temporary objects created by `type_caster::load()`. -/// Adding a patient will keep it alive up until the enclosing function returns. -class loader_life_support { -public: - /// A new patient frame is created when a function is entered - loader_life_support() { - get_internals().loader_patient_stack.push_back(nullptr); - } - - /// ... and destroyed after it returns - ~loader_life_support() { - auto &stack = get_internals().loader_patient_stack; - if (stack.empty()) - pybind11_fail("loader_life_support: internal error"); - - auto ptr = stack.back(); - stack.pop_back(); - Py_CLEAR(ptr); - - // A heuristic to reduce the stack's capacity (e.g. after long recursive calls) - if (stack.capacity() > 16 && stack.size() != 0 && stack.capacity() / stack.size() > 2) - stack.shrink_to_fit(); - } - - /// This can only be used inside a pybind11-bound function, either by `argument_loader` - /// at argument preparation time or by `py::cast()` at execution time. - PYBIND11_NOINLINE static void add_patient(handle h) { - auto &stack = get_internals().loader_patient_stack; - if (stack.empty()) - throw cast_error("When called outside a bound function, py::cast() cannot " - "do Python -> C++ conversions which require the creation " - "of temporary values"); - - auto &list_ptr = stack.back(); - if (list_ptr == nullptr) { - list_ptr = PyList_New(1); - if (!list_ptr) - pybind11_fail("loader_life_support: error allocating list"); - PyList_SET_ITEM(list_ptr, 0, h.inc_ref().ptr()); - } else { - auto result = PyList_Append(list_ptr, h.ptr()); - if (result == -1) - pybind11_fail("loader_life_support: error adding patient"); - } - } -}; - -// Gets the cache entry for the given type, creating it if necessary. The return value is the pair -// returned by emplace, i.e. an iterator for the entry and a bool set to `true` if the entry was -// just created. -inline std::pair<decltype(internals::registered_types_py)::iterator, bool> all_type_info_get_cache(PyTypeObject *type); - -// Populates a just-created cache entry. -PYBIND11_NOINLINE inline void all_type_info_populate(PyTypeObject *t, std::vector<type_info *> &bases) { - std::vector<PyTypeObject *> check; - for (handle parent : reinterpret_borrow<tuple>(t->tp_bases)) - check.push_back((PyTypeObject *) parent.ptr()); - - auto const &type_dict = get_internals().registered_types_py; - for (size_t i = 0; i < check.size(); i++) { - auto type = check[i]; - // Ignore Python2 old-style class super type: - if (!PyType_Check((PyObject *) type)) continue; - - // Check `type` in the current set of registered python types: - auto it = type_dict.find(type); - if (it != type_dict.end()) { - // We found a cache entry for it, so it's either pybind-registered or has pre-computed - // pybind bases, but we have to make sure we haven't already seen the type(s) before: we - // want to follow Python/virtual C++ rules that there should only be one instance of a - // common base. - for (auto *tinfo : it->second) { - // NB: Could use a second set here, rather than doing a linear search, but since - // having a large number of immediate pybind11-registered types seems fairly - // unlikely, that probably isn't worthwhile. - bool found = false; - for (auto *known : bases) { - if (known == tinfo) { found = true; break; } - } - if (!found) bases.push_back(tinfo); - } - } - else if (type->tp_bases) { - // It's some python type, so keep follow its bases classes to look for one or more - // registered types - if (i + 1 == check.size()) { - // When we're at the end, we can pop off the current element to avoid growing - // `check` when adding just one base (which is typical--i.e. when there is no - // multiple inheritance) - check.pop_back(); - i--; - } - for (handle parent : reinterpret_borrow<tuple>(type->tp_bases)) - check.push_back((PyTypeObject *) parent.ptr()); - } - } -} - -/** - * Extracts vector of type_info pointers of pybind-registered roots of the given Python type. Will - * be just 1 pybind type for the Python type of a pybind-registered class, or for any Python-side - * derived class that uses single inheritance. Will contain as many types as required for a Python - * class that uses multiple inheritance to inherit (directly or indirectly) from multiple - * pybind-registered classes. Will be empty if neither the type nor any base classes are - * pybind-registered. - * - * The value is cached for the lifetime of the Python type. - */ -inline const std::vector<detail::type_info *> &all_type_info(PyTypeObject *type) { - auto ins = all_type_info_get_cache(type); - if (ins.second) - // New cache entry: populate it - all_type_info_populate(type, ins.first->second); - - return ins.first->second; -} - -/** - * Gets a single pybind11 type info for a python type. Returns nullptr if neither the type nor any - * ancestors are pybind11-registered. Throws an exception if there are multiple bases--use - * `all_type_info` instead if you want to support multiple bases. - */ -PYBIND11_NOINLINE inline detail::type_info* get_type_info(PyTypeObject *type) { - auto &bases = all_type_info(type); - if (bases.size() == 0) - return nullptr; - if (bases.size() > 1) - pybind11_fail("pybind11::detail::get_type_info: type has multiple pybind11-registered bases"); - return bases.front(); -} - -inline detail::type_info *get_local_type_info(const std::type_index &tp) { - auto &locals = registered_local_types_cpp(); - auto it = locals.find(tp); - if (it != locals.end()) - return it->second; - return nullptr; -} - -inline detail::type_info *get_global_type_info(const std::type_index &tp) { - auto &types = get_internals().registered_types_cpp; - auto it = types.find(tp); - if (it != types.end()) - return it->second; - return nullptr; -} - -/// Return the type info for a given C++ type; on lookup failure can either throw or return nullptr. -PYBIND11_NOINLINE inline detail::type_info *get_type_info(const std::type_index &tp, - bool throw_if_missing = false) { - if (auto ltype = get_local_type_info(tp)) - return ltype; - if (auto gtype = get_global_type_info(tp)) - return gtype; - - if (throw_if_missing) { - std::string tname = tp.name(); - detail::clean_type_id(tname); - pybind11_fail("pybind11::detail::get_type_info: unable to find type info for \"" + tname + "\""); - } - return nullptr; -} - -PYBIND11_NOINLINE inline handle get_type_handle(const std::type_info &tp, bool throw_if_missing) { - detail::type_info *type_info = get_type_info(tp, throw_if_missing); - return handle(type_info ? ((PyObject *) type_info->type) : nullptr); -} - -struct value_and_holder { - instance *inst = nullptr; - size_t index = 0u; - const detail::type_info *type = nullptr; - void **vh = nullptr; - - // Main constructor for a found value/holder: - value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index) : - inst{i}, index{index}, type{type}, - vh{inst->simple_layout ? inst->simple_value_holder : &inst->nonsimple.values_and_holders[vpos]} - {} - - // Default constructor (used to signal a value-and-holder not found by get_value_and_holder()) - value_and_holder() {} - - // Used for past-the-end iterator - value_and_holder(size_t index) : index{index} {} - - template <typename V = void> V *&value_ptr() const { - return reinterpret_cast<V *&>(vh[0]); - } - // True if this `value_and_holder` has a non-null value pointer - explicit operator bool() const { return value_ptr(); } - - template <typename H> H &holder() const { - return reinterpret_cast<H &>(vh[1]); - } - bool holder_constructed() const { - return inst->simple_layout - ? inst->simple_holder_constructed - : inst->nonsimple.status[index] & instance::status_holder_constructed; - } - void set_holder_constructed(bool v = true) { - if (inst->simple_layout) - inst->simple_holder_constructed = v; - else if (v) - inst->nonsimple.status[index] |= instance::status_holder_constructed; - else - inst->nonsimple.status[index] &= (uint8_t) ~instance::status_holder_constructed; - } - bool instance_registered() const { - return inst->simple_layout - ? inst->simple_instance_registered - : inst->nonsimple.status[index] & instance::status_instance_registered; - } - void set_instance_registered(bool v = true) { - if (inst->simple_layout) - inst->simple_instance_registered = v; - else if (v) - inst->nonsimple.status[index] |= instance::status_instance_registered; - else - inst->nonsimple.status[index] &= (uint8_t) ~instance::status_instance_registered; - } -}; - -// Container for accessing and iterating over an instance's values/holders -struct values_and_holders { -private: - instance *inst; - using type_vec = std::vector<detail::type_info *>; - const type_vec &tinfo; - -public: - values_and_holders(instance *inst) : inst{inst}, tinfo(all_type_info(Py_TYPE(inst))) {} - - struct iterator { - private: - instance *inst = nullptr; - const type_vec *types = nullptr; - value_and_holder curr; - friend struct values_and_holders; - iterator(instance *inst, const type_vec *tinfo) - : inst{inst}, types{tinfo}, - curr(inst /* instance */, - types->empty() ? nullptr : (*types)[0] /* type info */, - 0, /* vpos: (non-simple types only): the first vptr comes first */ - 0 /* index */) - {} - // Past-the-end iterator: - iterator(size_t end) : curr(end) {} - public: - bool operator==(const iterator &other) { return curr.index == other.curr.index; } - bool operator!=(const iterator &other) { return curr.index != other.curr.index; } - iterator &operator++() { - if (!inst->simple_layout) - curr.vh += 1 + (*types)[curr.index]->holder_size_in_ptrs; - ++curr.index; - curr.type = curr.index < types->size() ? (*types)[curr.index] : nullptr; - return *this; - } - value_and_holder &operator*() { return curr; } - value_and_holder *operator->() { return &curr; } - }; - - iterator begin() { return iterator(inst, &tinfo); } - iterator end() { return iterator(tinfo.size()); } - - iterator find(const type_info *find_type) { - auto it = begin(), endit = end(); - while (it != endit && it->type != find_type) ++it; - return it; - } - - size_t size() { return tinfo.size(); } -}; - -/** - * Extracts C++ value and holder pointer references from an instance (which may contain multiple - * values/holders for python-side multiple inheritance) that match the given type. Throws an error - * if the given type (or ValueType, if omitted) is not a pybind11 base of the given instance. If - * `find_type` is omitted (or explicitly specified as nullptr) the first value/holder are returned, - * regardless of type (and the resulting .type will be nullptr). - * - * The returned object should be short-lived: in particular, it must not outlive the called-upon - * instance. - */ -PYBIND11_NOINLINE inline value_and_holder instance::get_value_and_holder(const type_info *find_type /*= nullptr default in common.h*/, bool throw_if_missing /*= true in common.h*/) { - // Optimize common case: - if (!find_type || Py_TYPE(this) == find_type->type) - return value_and_holder(this, find_type, 0, 0); - - detail::values_and_holders vhs(this); - auto it = vhs.find(find_type); - if (it != vhs.end()) - return *it; - - if (!throw_if_missing) - return value_and_holder(); - -#if defined(NDEBUG) - pybind11_fail("pybind11::detail::instance::get_value_and_holder: " - "type is not a pybind11 base of the given instance " - "(compile in debug mode for type details)"); -#else - pybind11_fail("pybind11::detail::instance::get_value_and_holder: `" + - std::string(find_type->type->tp_name) + "' is not a pybind11 base of the given `" + - std::string(Py_TYPE(this)->tp_name) + "' instance"); -#endif -} - -PYBIND11_NOINLINE inline void instance::allocate_layout() { - auto &tinfo = all_type_info(Py_TYPE(this)); - - const size_t n_types = tinfo.size(); - - if (n_types == 0) - pybind11_fail("instance allocation failed: new instance has no pybind11-registered base types"); - - simple_layout = - n_types == 1 && tinfo.front()->holder_size_in_ptrs <= instance_simple_holder_in_ptrs(); - - // Simple path: no python-side multiple inheritance, and a small-enough holder - if (simple_layout) { - simple_value_holder[0] = nullptr; - simple_holder_constructed = false; - simple_instance_registered = false; - } - else { // multiple base types or a too-large holder - // Allocate space to hold: [v1*][h1][v2*][h2]...[bb...] where [vN*] is a value pointer, - // [hN] is the (uninitialized) holder instance for value N, and [bb...] is a set of bool - // values that tracks whether each associated holder has been initialized. Each [block] is - // padded, if necessary, to an integer multiple of sizeof(void *). - size_t space = 0; - for (auto t : tinfo) { - space += 1; // value pointer - space += t->holder_size_in_ptrs; // holder instance - } - size_t flags_at = space; - space += size_in_ptrs(n_types); // status bytes (holder_constructed and instance_registered) - - // Allocate space for flags, values, and holders, and initialize it to 0 (flags and values, - // in particular, need to be 0). Use Python's memory allocation functions: in Python 3.6 - // they default to using pymalloc, which is designed to be efficient for small allocations - // like the one we're doing here; in earlier versions (and for larger allocations) they are - // just wrappers around malloc. -#if PY_VERSION_HEX >= 0x03050000 - nonsimple.values_and_holders = (void **) PyMem_Calloc(space, sizeof(void *)); - if (!nonsimple.values_and_holders) throw std::bad_alloc(); -#else - nonsimple.values_and_holders = (void **) PyMem_New(void *, space); - if (!nonsimple.values_and_holders) throw std::bad_alloc(); - std::memset(nonsimple.values_and_holders, 0, space * sizeof(void *)); -#endif - nonsimple.status = reinterpret_cast<uint8_t *>(&nonsimple.values_and_holders[flags_at]); - } - owned = true; -} - -PYBIND11_NOINLINE inline void instance::deallocate_layout() { - if (!simple_layout) - PyMem_Free(nonsimple.values_and_holders); -} - -PYBIND11_NOINLINE inline bool isinstance_generic(handle obj, const std::type_info &tp) { - handle type = detail::get_type_handle(tp, false); - if (!type) - return false; - return isinstance(obj, type); -} - -PYBIND11_NOINLINE inline std::string error_string() { - if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_RuntimeError, "Unknown internal error occurred"); - return "Unknown internal error occurred"; - } - - error_scope scope; // Preserve error state - - std::string errorString; - if (scope.type) { - errorString += handle(scope.type).attr("__name__").cast<std::string>(); - errorString += ": "; - } - if (scope.value) - errorString += (std::string) str(scope.value); - - PyErr_NormalizeException(&scope.type, &scope.value, &scope.trace); - -#if PY_MAJOR_VERSION >= 3 - if (scope.trace != nullptr) - PyException_SetTraceback(scope.value, scope.trace); -#endif - -#if !defined(PYPY_VERSION) - if (scope.trace) { - PyTracebackObject *trace = (PyTracebackObject *) scope.trace; - - /* Get the deepest trace possible */ - while (trace->tb_next) - trace = trace->tb_next; - - PyFrameObject *frame = trace->tb_frame; - errorString += "\n\nAt:\n"; - while (frame) { - int lineno = PyFrame_GetLineNumber(frame); - errorString += - " " + handle(frame->f_code->co_filename).cast<std::string>() + - "(" + std::to_string(lineno) + "): " + - handle(frame->f_code->co_name).cast<std::string>() + "\n"; - frame = frame->f_back; - } - } -#endif - - return errorString; -} - -PYBIND11_NOINLINE inline handle get_object_handle(const void *ptr, const detail::type_info *type ) { - auto &instances = get_internals().registered_instances; - auto range = instances.equal_range(ptr); - for (auto it = range.first; it != range.second; ++it) { - for (auto vh : values_and_holders(it->second)) { - if (vh.type == type) - return handle((PyObject *) it->second); - } - } - return handle(); -} - -inline PyThreadState *get_thread_state_unchecked() { -#if defined(PYPY_VERSION) - return PyThreadState_GET(); -#elif PY_VERSION_HEX < 0x03000000 - return _PyThreadState_Current; -#elif PY_VERSION_HEX < 0x03050000 - return (PyThreadState*) _Py_atomic_load_relaxed(&_PyThreadState_Current); -#elif PY_VERSION_HEX < 0x03050200 - return (PyThreadState*) _PyThreadState_Current.value; -#else - return _PyThreadState_UncheckedGet(); -#endif -} - -// Forward declarations -inline void keep_alive_impl(handle nurse, handle patient); -inline PyObject *make_new_instance(PyTypeObject *type); - -class type_caster_generic { -public: - PYBIND11_NOINLINE type_caster_generic(const std::type_info &type_info) - : typeinfo(get_type_info(type_info)), cpptype(&type_info) { } - - type_caster_generic(const type_info *typeinfo) - : typeinfo(typeinfo), cpptype(typeinfo ? typeinfo->cpptype : nullptr) { } - - bool load(handle src, bool convert) { - return load_impl<type_caster_generic>(src, convert); - } - - PYBIND11_NOINLINE static handle cast(const void *_src, return_value_policy policy, handle parent, - const detail::type_info *tinfo, - void *(*copy_constructor)(const void *), - void *(*move_constructor)(const void *), - const void *existing_holder = nullptr) { - if (!tinfo) // no type info: error will be set already - return handle(); - - void *src = const_cast<void *>(_src); - if (src == nullptr) - return none().release(); - - auto it_instances = get_internals().registered_instances.equal_range(src); - for (auto it_i = it_instances.first; it_i != it_instances.second; ++it_i) { - for (auto instance_type : detail::all_type_info(Py_TYPE(it_i->second))) { - if (instance_type && same_type(*instance_type->cpptype, *tinfo->cpptype)) - return handle((PyObject *) it_i->second).inc_ref(); - } - } - - auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type)); - auto wrapper = reinterpret_cast<instance *>(inst.ptr()); - wrapper->owned = false; - void *&valueptr = values_and_holders(wrapper).begin()->value_ptr(); - - switch (policy) { - case return_value_policy::automatic: - case return_value_policy::take_ownership: - valueptr = src; - wrapper->owned = true; - break; - - case return_value_policy::automatic_reference: - case return_value_policy::reference: - valueptr = src; - wrapper->owned = false; - break; - - case return_value_policy::copy: - if (copy_constructor) - valueptr = copy_constructor(src); - else { -#if defined(NDEBUG) - throw cast_error("return_value_policy = copy, but type is " - "non-copyable! (compile in debug mode for details)"); -#else - std::string type_name(tinfo->cpptype->name()); - detail::clean_type_id(type_name); - throw cast_error("return_value_policy = copy, but type " + - type_name + " is non-copyable!"); -#endif - } - wrapper->owned = true; - break; - - case return_value_policy::move: - if (move_constructor) - valueptr = move_constructor(src); - else if (copy_constructor) - valueptr = copy_constructor(src); - else { -#if defined(NDEBUG) - throw cast_error("return_value_policy = move, but type is neither " - "movable nor copyable! " - "(compile in debug mode for details)"); -#else - std::string type_name(tinfo->cpptype->name()); - detail::clean_type_id(type_name); - throw cast_error("return_value_policy = move, but type " + - type_name + " is neither movable nor copyable!"); -#endif - } - wrapper->owned = true; - break; - - case return_value_policy::reference_internal: - valueptr = src; - wrapper->owned = false; - keep_alive_impl(inst, parent); - break; - - default: - throw cast_error("unhandled return_value_policy: should not happen!"); - } - - tinfo->init_instance(wrapper, existing_holder); - - return inst.release(); - } - - // Base methods for generic caster; there are overridden in copyable_holder_caster - void load_value(value_and_holder &&v_h) { - auto *&vptr = v_h.value_ptr(); - // Lazy allocation for unallocated values: - if (vptr == nullptr) { - auto *type = v_h.type ? v_h.type : typeinfo; - if (type->operator_new) { - vptr = type->operator_new(type->type_size); - } else { - #ifdef __cpp_aligned_new - if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) - vptr = ::operator new(type->type_size, - std::align_val_t(type->type_align)); - else - #endif - vptr = ::operator new(type->type_size); - } - } - value = vptr; - } - bool try_implicit_casts(handle src, bool convert) { - for (auto &cast : typeinfo->implicit_casts) { - type_caster_generic sub_caster(*cast.first); - if (sub_caster.load(src, convert)) { - value = cast.second(sub_caster.value); - return true; - } - } - return false; - } - bool try_direct_conversions(handle src) { - for (auto &converter : *typeinfo->direct_conversions) { - if (converter(src.ptr(), value)) - return true; - } - return false; - } - void check_holder_compat() {} - - PYBIND11_NOINLINE static void *local_load(PyObject *src, const type_info *ti) { - auto caster = type_caster_generic(ti); - if (caster.load(src, false)) - return caster.value; - return nullptr; - } - - /// Try to load with foreign typeinfo, if available. Used when there is no - /// native typeinfo, or when the native one wasn't able to produce a value. - PYBIND11_NOINLINE bool try_load_foreign_module_local(handle src) { - constexpr auto *local_key = PYBIND11_MODULE_LOCAL_ID; - const auto pytype = src.get_type(); - if (!hasattr(pytype, local_key)) - return false; - - type_info *foreign_typeinfo = reinterpret_borrow<capsule>(getattr(pytype, local_key)); - // Only consider this foreign loader if actually foreign and is a loader of the correct cpp type - if (foreign_typeinfo->module_local_load == &local_load - || (cpptype && !same_type(*cpptype, *foreign_typeinfo->cpptype))) - return false; - - if (auto result = foreign_typeinfo->module_local_load(src.ptr(), foreign_typeinfo)) { - value = result; - return true; - } - return false; - } - - // Implementation of `load`; this takes the type of `this` so that it can dispatch the relevant - // bits of code between here and copyable_holder_caster where the two classes need different - // logic (without having to resort to virtual inheritance). - template <typename ThisT> - PYBIND11_NOINLINE bool load_impl(handle src, bool convert) { - if (!src) return false; - if (!typeinfo) return try_load_foreign_module_local(src); - if (src.is_none()) { - // Defer accepting None to other overloads (if we aren't in convert mode): - if (!convert) return false; - value = nullptr; - return true; - } - - auto &this_ = static_cast<ThisT &>(*this); - this_.check_holder_compat(); - - PyTypeObject *srctype = Py_TYPE(src.ptr()); - - // Case 1: If src is an exact type match for the target type then we can reinterpret_cast - // the instance's value pointer to the target type: - if (srctype == typeinfo->type) { - this_.load_value(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder()); - return true; - } - // Case 2: We have a derived class - else if (PyType_IsSubtype(srctype, typeinfo->type)) { - auto &bases = all_type_info(srctype); - bool no_cpp_mi = typeinfo->simple_type; - - // Case 2a: the python type is a Python-inherited derived class that inherits from just - // one simple (no MI) pybind11 class, or is an exact match, so the C++ instance is of - // the right type and we can use reinterpret_cast. - // (This is essentially the same as case 2b, but because not using multiple inheritance - // is extremely common, we handle it specially to avoid the loop iterator and type - // pointer lookup overhead) - if (bases.size() == 1 && (no_cpp_mi || bases.front()->type == typeinfo->type)) { - this_.load_value(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder()); - return true; - } - // Case 2b: the python type inherits from multiple C++ bases. Check the bases to see if - // we can find an exact match (or, for a simple C++ type, an inherited match); if so, we - // can safely reinterpret_cast to the relevant pointer. - else if (bases.size() > 1) { - for (auto base : bases) { - if (no_cpp_mi ? PyType_IsSubtype(base->type, typeinfo->type) : base->type == typeinfo->type) { - this_.load_value(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder(base)); - return true; - } - } - } - - // Case 2c: C++ multiple inheritance is involved and we couldn't find an exact type match - // in the registered bases, above, so try implicit casting (needed for proper C++ casting - // when MI is involved). - if (this_.try_implicit_casts(src, convert)) - return true; - } - - // Perform an implicit conversion - if (convert) { - for (auto &converter : typeinfo->implicit_conversions) { - auto temp = reinterpret_steal<object>(converter(src.ptr(), typeinfo->type)); - if (load_impl<ThisT>(temp, false)) { - loader_life_support::add_patient(temp); - return true; - } - } - if (this_.try_direct_conversions(src)) - return true; - } - - // Failed to match local typeinfo. Try again with global. - if (typeinfo->module_local) { - if (auto gtype = get_global_type_info(*typeinfo->cpptype)) { - typeinfo = gtype; - return load(src, false); - } - } - - // Global typeinfo has precedence over foreign module_local - return try_load_foreign_module_local(src); - } - - - // Called to do type lookup and wrap the pointer and type in a pair when a dynamic_cast - // isn't needed or can't be used. If the type is unknown, sets the error and returns a pair - // with .second = nullptr. (p.first = nullptr is not an error: it becomes None). - PYBIND11_NOINLINE static std::pair<const void *, const type_info *> src_and_type( - const void *src, const std::type_info &cast_type, const std::type_info *rtti_type = nullptr) { - if (auto *tpi = get_type_info(cast_type)) - return {src, const_cast<const type_info *>(tpi)}; - - // Not found, set error: - std::string tname = rtti_type ? rtti_type->name() : cast_type.name(); - detail::clean_type_id(tname); - std::string msg = "Unregistered type : " + tname; - PyErr_SetString(PyExc_TypeError, msg.c_str()); - return {nullptr, nullptr}; - } - - const type_info *typeinfo = nullptr; - const std::type_info *cpptype = nullptr; - void *value = nullptr; -}; - -/** - * Determine suitable casting operator for pointer-or-lvalue-casting type casters. The type caster - * needs to provide `operator T*()` and `operator T&()` operators. - * - * If the type supports moving the value away via an `operator T&&() &&` method, it should use - * `movable_cast_op_type` instead. - */ -template <typename T> -using cast_op_type = - conditional_t<std::is_pointer<remove_reference_t<T>>::value, - typename std::add_pointer<intrinsic_t<T>>::type, - typename std::add_lvalue_reference<intrinsic_t<T>>::type>; - -/** - * Determine suitable casting operator for a type caster with a movable value. Such a type caster - * needs to provide `operator T*()`, `operator T&()`, and `operator T&&() &&`. The latter will be - * called in appropriate contexts where the value can be moved rather than copied. - * - * These operator are automatically provided when using the PYBIND11_TYPE_CASTER macro. - */ -template <typename T> -using movable_cast_op_type = - conditional_t<std::is_pointer<typename std::remove_reference<T>::type>::value, - typename std::add_pointer<intrinsic_t<T>>::type, - conditional_t<std::is_rvalue_reference<T>::value, - typename std::add_rvalue_reference<intrinsic_t<T>>::type, - typename std::add_lvalue_reference<intrinsic_t<T>>::type>>; - -// std::is_copy_constructible isn't quite enough: it lets std::vector<T> (and similar) through when -// T is non-copyable, but code containing such a copy constructor fails to actually compile. -template <typename T, typename SFINAE = void> struct is_copy_constructible : std::is_copy_constructible<T> {}; - -// Specialization for types that appear to be copy constructible but also look like stl containers -// (we specifically check for: has `value_type` and `reference` with `reference = value_type&`): if -// so, copy constructability depends on whether the value_type is copy constructible. -template <typename Container> struct is_copy_constructible<Container, enable_if_t<all_of< - std::is_copy_constructible<Container>, - std::is_same<typename Container::value_type &, typename Container::reference>, - // Avoid infinite recursion - negation<std::is_same<Container, typename Container::value_type>> - >::value>> : is_copy_constructible<typename Container::value_type> {}; - -// Likewise for std::pair -// (after C++17 it is mandatory that the copy constructor not exist when the two types aren't themselves -// copy constructible, but this can not be relied upon when T1 or T2 are themselves containers). -template <typename T1, typename T2> struct is_copy_constructible<std::pair<T1, T2>> - : all_of<is_copy_constructible<T1>, is_copy_constructible<T2>> {}; - -// The same problems arise with std::is_copy_assignable, so we use the same workaround. -template <typename T, typename SFINAE = void> struct is_copy_assignable : std::is_copy_assignable<T> {}; -template <typename Container> struct is_copy_assignable<Container, enable_if_t<all_of< - std::is_copy_assignable<Container>, - std::is_same<typename Container::value_type &, typename Container::reference> - >::value>> : is_copy_assignable<typename Container::value_type> {}; -template <typename T1, typename T2> struct is_copy_assignable<std::pair<T1, T2>> - : all_of<is_copy_assignable<T1>, is_copy_assignable<T2>> {}; - -NAMESPACE_END(detail) - -// polymorphic_type_hook<itype>::get(src, tinfo) determines whether the object pointed -// to by `src` actually is an instance of some class derived from `itype`. -// If so, it sets `tinfo` to point to the std::type_info representing that derived -// type, and returns a pointer to the start of the most-derived object of that type -// (in which `src` is a subobject; this will be the same address as `src` in most -// single inheritance cases). If not, or if `src` is nullptr, it simply returns `src` -// and leaves `tinfo` at its default value of nullptr. -// -// The default polymorphic_type_hook just returns src. A specialization for polymorphic -// types determines the runtime type of the passed object and adjusts the this-pointer -// appropriately via dynamic_cast<void*>. This is what enables a C++ Animal* to appear -// to Python as a Dog (if Dog inherits from Animal, Animal is polymorphic, Dog is -// registered with pybind11, and this Animal is in fact a Dog). -// -// You may specialize polymorphic_type_hook yourself for types that want to appear -// polymorphic to Python but do not use C++ RTTI. (This is a not uncommon pattern -// in performance-sensitive applications, used most notably in LLVM.) -template <typename itype, typename SFINAE = void> -struct polymorphic_type_hook -{ - static const void *get(const itype *src, const std::type_info*&) { return src; } -}; -template <typename itype> -struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_polymorphic<itype>::value>> -{ - static const void *get(const itype *src, const std::type_info*& type) { - type = src ? &typeid(*src) : nullptr; - return dynamic_cast<const void*>(src); - } -}; - -NAMESPACE_BEGIN(detail) - -/// Generic type caster for objects stored on the heap -template <typename type> class type_caster_base : public type_caster_generic { - using itype = intrinsic_t<type>; - -public: - static constexpr auto name = _<type>(); - - type_caster_base() : type_caster_base(typeid(type)) { } - explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) { } - - static handle cast(const itype &src, return_value_policy policy, handle parent) { - if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference) - policy = return_value_policy::copy; - return cast(&src, policy, parent); - } - - static handle cast(itype &&src, return_value_policy, handle parent) { - return cast(&src, return_value_policy::move, parent); - } - - // Returns a (pointer, type_info) pair taking care of necessary type lookup for a - // polymorphic type (using RTTI by default, but can be overridden by specializing - // polymorphic_type_hook). If the instance isn't derived, returns the base version. - static std::pair<const void *, const type_info *> src_and_type(const itype *src) { - auto &cast_type = typeid(itype); - const std::type_info *instance_type = nullptr; - const void *vsrc = polymorphic_type_hook<itype>::get(src, instance_type); - if (instance_type && !same_type(cast_type, *instance_type)) { - // This is a base pointer to a derived type. If the derived type is registered - // with pybind11, we want to make the full derived object available. - // In the typical case where itype is polymorphic, we get the correct - // derived pointer (which may be != base pointer) by a dynamic_cast to - // most derived type. If itype is not polymorphic, we won't get here - // except via a user-provided specialization of polymorphic_type_hook, - // and the user has promised that no this-pointer adjustment is - // required in that case, so it's OK to use static_cast. - if (const auto *tpi = get_type_info(*instance_type)) - return {vsrc, tpi}; - } - // Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so - // don't do a cast - return type_caster_generic::src_and_type(src, cast_type, instance_type); - } - - static handle cast(const itype *src, return_value_policy policy, handle parent) { - auto st = src_and_type(src); - return type_caster_generic::cast( - st.first, policy, parent, st.second, - make_copy_constructor(src), make_move_constructor(src)); - } - - static handle cast_holder(const itype *src, const void *holder) { - auto st = src_and_type(src); - return type_caster_generic::cast( - st.first, return_value_policy::take_ownership, {}, st.second, - nullptr, nullptr, holder); - } - - template <typename T> using cast_op_type = detail::cast_op_type<T>; - - operator itype*() { return (type *) value; } - operator itype&() { if (!value) throw reference_cast_error(); return *((itype *) value); } - -protected: - using Constructor = void *(*)(const void *); - - /* Only enabled when the types are {copy,move}-constructible *and* when the type - does not have a private operator new implementation. */ - template <typename T, typename = enable_if_t<is_copy_constructible<T>::value>> - static auto make_copy_constructor(const T *x) -> decltype(new T(*x), Constructor{}) { - return [](const void *arg) -> void * { - return new T(*reinterpret_cast<const T *>(arg)); - }; - } - - template <typename T, typename = enable_if_t<std::is_move_constructible<T>::value>> - static auto make_move_constructor(const T *x) -> decltype(new T(std::move(*const_cast<T *>(x))), Constructor{}) { - return [](const void *arg) -> void * { - return new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg)))); - }; - } - - static Constructor make_copy_constructor(...) { return nullptr; } - static Constructor make_move_constructor(...) { return nullptr; } -}; - -template <typename type, typename SFINAE = void> class type_caster : public type_caster_base<type> { }; -template <typename type> using make_caster = type_caster<intrinsic_t<type>>; - -// Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T -template <typename T> typename make_caster<T>::template cast_op_type<T> cast_op(make_caster<T> &caster) { - return caster.operator typename make_caster<T>::template cast_op_type<T>(); -} -template <typename T> typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type> -cast_op(make_caster<T> &&caster) { - return std::move(caster).operator - typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type>(); -} - -template <typename type> class type_caster<std::reference_wrapper<type>> { -private: - using caster_t = make_caster<type>; - caster_t subcaster; - using subcaster_cast_op_type = typename caster_t::template cast_op_type<type>; - static_assert(std::is_same<typename std::remove_const<type>::type &, subcaster_cast_op_type>::value, - "std::reference_wrapper<T> caster requires T to have a caster with an `T &` operator"); -public: - bool load(handle src, bool convert) { return subcaster.load(src, convert); } - static constexpr auto name = caster_t::name; - static handle cast(const std::reference_wrapper<type> &src, return_value_policy policy, handle parent) { - // It is definitely wrong to take ownership of this pointer, so mask that rvp - if (policy == return_value_policy::take_ownership || policy == return_value_policy::automatic) - policy = return_value_policy::automatic_reference; - return caster_t::cast(&src.get(), policy, parent); - } - template <typename T> using cast_op_type = std::reference_wrapper<type>; - operator std::reference_wrapper<type>() { return subcaster.operator subcaster_cast_op_type&(); } -}; - -#define PYBIND11_TYPE_CASTER(type, py_name) \ - protected: \ - type value; \ - public: \ - static constexpr auto name = py_name; \ - template <typename T_, enable_if_t<std::is_same<type, remove_cv_t<T_>>::value, int> = 0> \ - static handle cast(T_ *src, return_value_policy policy, handle parent) { \ - if (!src) return none().release(); \ - if (policy == return_value_policy::take_ownership) { \ - auto h = cast(std::move(*src), policy, parent); delete src; return h; \ - } else { \ - return cast(*src, policy, parent); \ - } \ - } \ - operator type*() { return &value; } \ - operator type&() { return value; } \ - operator type&&() && { return std::move(value); } \ - template <typename T_> using cast_op_type = pybind11::detail::movable_cast_op_type<T_> - - -template <typename CharT> using is_std_char_type = any_of< - std::is_same<CharT, char>, /* std::string */ - std::is_same<CharT, char16_t>, /* std::u16string */ - std::is_same<CharT, char32_t>, /* std::u32string */ - std::is_same<CharT, wchar_t> /* std::wstring */ ->; - -template <typename T> -struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_type<T>::value>> { - using _py_type_0 = conditional_t<sizeof(T) <= sizeof(long), long, long long>; - using _py_type_1 = conditional_t<std::is_signed<T>::value, _py_type_0, typename std::make_unsigned<_py_type_0>::type>; - using py_type = conditional_t<std::is_floating_point<T>::value, double, _py_type_1>; -public: - - bool load(handle src, bool convert) { - py_type py_value; - - if (!src) - return false; - - if (std::is_floating_point<T>::value) { - if (convert || PyFloat_Check(src.ptr())) - py_value = (py_type) PyFloat_AsDouble(src.ptr()); - else - return false; - } else if (PyFloat_Check(src.ptr())) { - return false; - } else if (std::is_unsigned<py_type>::value) { - py_value = as_unsigned<py_type>(src.ptr()); - } else { // signed integer: - py_value = sizeof(T) <= sizeof(long) - ? (py_type) PyLong_AsLong(src.ptr()) - : (py_type) PYBIND11_LONG_AS_LONGLONG(src.ptr()); - } - - bool py_err = py_value == (py_type) -1 && PyErr_Occurred(); - - // Protect std::numeric_limits::min/max with parentheses - if (py_err || (std::is_integral<T>::value && sizeof(py_type) != sizeof(T) && - (py_value < (py_type) (std::numeric_limits<T>::min)() || - py_value > (py_type) (std::numeric_limits<T>::max)()))) { - bool type_error = py_err && PyErr_ExceptionMatches( -#if PY_VERSION_HEX < 0x03000000 && !defined(PYPY_VERSION) - PyExc_SystemError -#else - PyExc_TypeError -#endif - ); - PyErr_Clear(); - if (type_error && convert && PyNumber_Check(src.ptr())) { - auto tmp = reinterpret_steal<object>(std::is_floating_point<T>::value - ? PyNumber_Float(src.ptr()) - : PyNumber_Long(src.ptr())); - PyErr_Clear(); - return load(tmp, false); - } - return false; - } - - value = (T) py_value; - return true; - } - - template<typename U = T> - static typename std::enable_if<std::is_floating_point<U>::value, handle>::type - cast(U src, return_value_policy /* policy */, handle /* parent */) { - return PyFloat_FromDouble((double) src); - } - - template<typename U = T> - static typename std::enable_if<!std::is_floating_point<U>::value && std::is_signed<U>::value && (sizeof(U) <= sizeof(long)), handle>::type - cast(U src, return_value_policy /* policy */, handle /* parent */) { - return PYBIND11_LONG_FROM_SIGNED((long) src); - } - - template<typename U = T> - static typename std::enable_if<!std::is_floating_point<U>::value && std::is_unsigned<U>::value && (sizeof(U) <= sizeof(unsigned long)), handle>::type - cast(U src, return_value_policy /* policy */, handle /* parent */) { - return PYBIND11_LONG_FROM_UNSIGNED((unsigned long) src); - } - - template<typename U = T> - static typename std::enable_if<!std::is_floating_point<U>::value && std::is_signed<U>::value && (sizeof(U) > sizeof(long)), handle>::type - cast(U src, return_value_policy /* policy */, handle /* parent */) { - return PyLong_FromLongLong((long long) src); - } - - template<typename U = T> - static typename std::enable_if<!std::is_floating_point<U>::value && std::is_unsigned<U>::value && (sizeof(U) > sizeof(unsigned long)), handle>::type - cast(U src, return_value_policy /* policy */, handle /* parent */) { - return PyLong_FromUnsignedLongLong((unsigned long long) src); - } - - PYBIND11_TYPE_CASTER(T, _<std::is_integral<T>::value>("int", "float")); -}; - -template<typename T> struct void_caster { -public: - bool load(handle src, bool) { - if (src && src.is_none()) - return true; - return false; - } - static handle cast(T, return_value_policy /* policy */, handle /* parent */) { - return none().inc_ref(); - } - PYBIND11_TYPE_CASTER(T, _("None")); -}; - -template <> class type_caster<void_type> : public void_caster<void_type> {}; - -template <> class type_caster<void> : public type_caster<void_type> { -public: - using type_caster<void_type>::cast; - - bool load(handle h, bool) { - if (!h) { - return false; - } else if (h.is_none()) { - value = nullptr; - return true; - } - - /* Check if this is a capsule */ - if (isinstance<capsule>(h)) { - value = reinterpret_borrow<capsule>(h); - return true; - } - - /* Check if this is a C++ type */ - auto &bases = all_type_info((PyTypeObject *) h.get_type().ptr()); - if (bases.size() == 1) { // Only allowing loading from a single-value type - value = values_and_holders(reinterpret_cast<instance *>(h.ptr())).begin()->value_ptr(); - return true; - } - - /* Fail */ - return false; - } - - static handle cast(const void *ptr, return_value_policy /* policy */, handle /* parent */) { - if (ptr) - return capsule(ptr).release(); - else - return none().inc_ref(); - } - - template <typename T> using cast_op_type = void*&; - operator void *&() { return value; } - static constexpr auto name = _("capsule"); -private: - void *value = nullptr; -}; - -template <> class type_caster<std::nullptr_t> : public void_caster<std::nullptr_t> { }; - -template <> class type_caster<bool> { -public: - bool load(handle src, bool convert) { - if (!src) return false; - else if (src.ptr() == Py_True) { value = true; return true; } - else if (src.ptr() == Py_False) { value = false; return true; } - else if (convert || !strcmp("numpy.bool_", Py_TYPE(src.ptr())->tp_name)) { - // (allow non-implicit conversion for numpy booleans) - - Py_ssize_t res = -1; - if (src.is_none()) { - res = 0; // None is implicitly converted to False - } - #if defined(PYPY_VERSION) - // On PyPy, check that "__bool__" (or "__nonzero__" on Python 2.7) attr exists - else if (hasattr(src, PYBIND11_BOOL_ATTR)) { - res = PyObject_IsTrue(src.ptr()); - } - #else - // Alternate approach for CPython: this does the same as the above, but optimized - // using the CPython API so as to avoid an unneeded attribute lookup. - else if (auto tp_as_number = src.ptr()->ob_type->tp_as_number) { - if (PYBIND11_NB_BOOL(tp_as_number)) { - res = (*PYBIND11_NB_BOOL(tp_as_number))(src.ptr()); - } - } - #endif - if (res == 0 || res == 1) { - value = (bool) res; - return true; - } - } - return false; - } - static handle cast(bool src, return_value_policy /* policy */, handle /* parent */) { - return handle(src ? Py_True : Py_False).inc_ref(); - } - PYBIND11_TYPE_CASTER(bool, _("bool")); -}; - -// Helper class for UTF-{8,16,32} C++ stl strings: -template <typename StringType, bool IsView = false> struct string_caster { - using CharT = typename StringType::value_type; - - // Simplify life by being able to assume standard char sizes (the standard only guarantees - // minimums, but Python requires exact sizes) - static_assert(!std::is_same<CharT, char>::value || sizeof(CharT) == 1, "Unsupported char size != 1"); - static_assert(!std::is_same<CharT, char16_t>::value || sizeof(CharT) == 2, "Unsupported char16_t size != 2"); - static_assert(!std::is_same<CharT, char32_t>::value || sizeof(CharT) == 4, "Unsupported char32_t size != 4"); - // wchar_t can be either 16 bits (Windows) or 32 (everywhere else) - static_assert(!std::is_same<CharT, wchar_t>::value || sizeof(CharT) == 2 || sizeof(CharT) == 4, - "Unsupported wchar_t size != 2/4"); - static constexpr size_t UTF_N = 8 * sizeof(CharT); - - bool load(handle src, bool) { -#if PY_MAJOR_VERSION < 3 - object temp; -#endif - handle load_src = src; - if (!src) { - return false; - } else if (!PyUnicode_Check(load_src.ptr())) { -#if PY_MAJOR_VERSION >= 3 - return load_bytes(load_src); -#else - if (sizeof(CharT) == 1) { - return load_bytes(load_src); - } - - // The below is a guaranteed failure in Python 3 when PyUnicode_Check returns false - if (!PYBIND11_BYTES_CHECK(load_src.ptr())) - return false; - - temp = reinterpret_steal<object>(PyUnicode_FromObject(load_src.ptr())); - if (!temp) { PyErr_Clear(); return false; } - load_src = temp; -#endif - } - - object utfNbytes = reinterpret_steal<object>(PyUnicode_AsEncodedString( - load_src.ptr(), UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr)); - if (!utfNbytes) { PyErr_Clear(); return false; } - - const CharT *buffer = reinterpret_cast<const CharT *>(PYBIND11_BYTES_AS_STRING(utfNbytes.ptr())); - size_t length = (size_t) PYBIND11_BYTES_SIZE(utfNbytes.ptr()) / sizeof(CharT); - if (UTF_N > 8) { buffer++; length--; } // Skip BOM for UTF-16/32 - value = StringType(buffer, length); - - // If we're loading a string_view we need to keep the encoded Python object alive: - if (IsView) - loader_life_support::add_patient(utfNbytes); - - return true; - } - - static handle cast(const StringType &src, return_value_policy /* policy */, handle /* parent */) { - const char *buffer = reinterpret_cast<const char *>(src.data()); - ssize_t nbytes = ssize_t(src.size() * sizeof(CharT)); - handle s = decode_utfN(buffer, nbytes); - if (!s) throw error_already_set(); - return s; - } - - PYBIND11_TYPE_CASTER(StringType, _(PYBIND11_STRING_NAME)); - -private: - static handle decode_utfN(const char *buffer, ssize_t nbytes) { -#if !defined(PYPY_VERSION) - return - UTF_N == 8 ? PyUnicode_DecodeUTF8(buffer, nbytes, nullptr) : - UTF_N == 16 ? PyUnicode_DecodeUTF16(buffer, nbytes, nullptr, nullptr) : - PyUnicode_DecodeUTF32(buffer, nbytes, nullptr, nullptr); -#else - // PyPy seems to have multiple problems related to PyUnicode_UTF*: the UTF8 version - // sometimes segfaults for unknown reasons, while the UTF16 and 32 versions require a - // non-const char * arguments, which is also a nuisance, so bypass the whole thing by just - // passing the encoding as a string value, which works properly: - return PyUnicode_Decode(buffer, nbytes, UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr); -#endif - } - - // When loading into a std::string or char*, accept a bytes object as-is (i.e. - // without any encoding/decoding attempt). For other C++ char sizes this is a no-op. - // which supports loading a unicode from a str, doesn't take this path. - template <typename C = CharT> - bool load_bytes(enable_if_t<sizeof(C) == 1, handle> src) { - if (PYBIND11_BYTES_CHECK(src.ptr())) { - // We were passed a Python 3 raw bytes; accept it into a std::string or char* - // without any encoding attempt. - const char *bytes = PYBIND11_BYTES_AS_STRING(src.ptr()); - if (bytes) { - value = StringType(bytes, (size_t) PYBIND11_BYTES_SIZE(src.ptr())); - return true; - } - } - - return false; - } - - template <typename C = CharT> - bool load_bytes(enable_if_t<sizeof(C) != 1, handle>) { return false; } -}; - -template <typename CharT, class Traits, class Allocator> -struct type_caster<std::basic_string<CharT, Traits, Allocator>, enable_if_t<is_std_char_type<CharT>::value>> - : string_caster<std::basic_string<CharT, Traits, Allocator>> {}; - -#ifdef PYBIND11_HAS_STRING_VIEW -template <typename CharT, class Traits> -struct type_caster<std::basic_string_view<CharT, Traits>, enable_if_t<is_std_char_type<CharT>::value>> - : string_caster<std::basic_string_view<CharT, Traits>, true> {}; -#endif - -// Type caster for C-style strings. We basically use a std::string type caster, but also add the -// ability to use None as a nullptr char* (which the string caster doesn't allow). -template <typename CharT> struct type_caster<CharT, enable_if_t<is_std_char_type<CharT>::value>> { - using StringType = std::basic_string<CharT>; - using StringCaster = type_caster<StringType>; - StringCaster str_caster; - bool none = false; - CharT one_char = 0; -public: - bool load(handle src, bool convert) { - if (!src) return false; - if (src.is_none()) { - // Defer accepting None to other overloads (if we aren't in convert mode): - if (!convert) return false; - none = true; - return true; - } - return str_caster.load(src, convert); - } - - static handle cast(const CharT *src, return_value_policy policy, handle parent) { - if (src == nullptr) return pybind11::none().inc_ref(); - return StringCaster::cast(StringType(src), policy, parent); - } - - static handle cast(CharT src, return_value_policy policy, handle parent) { - if (std::is_same<char, CharT>::value) { - handle s = PyUnicode_DecodeLatin1((const char *) &src, 1, nullptr); - if (!s) throw error_already_set(); - return s; - } - return StringCaster::cast(StringType(1, src), policy, parent); - } - - operator CharT*() { return none ? nullptr : const_cast<CharT *>(static_cast<StringType &>(str_caster).c_str()); } - operator CharT&() { - if (none) - throw value_error("Cannot convert None to a character"); - - auto &value = static_cast<StringType &>(str_caster); - size_t str_len = value.size(); - if (str_len == 0) - throw value_error("Cannot convert empty string to a character"); - - // If we're in UTF-8 mode, we have two possible failures: one for a unicode character that - // is too high, and one for multiple unicode characters (caught later), so we need to figure - // out how long the first encoded character is in bytes to distinguish between these two - // errors. We also allow want to allow unicode characters U+0080 through U+00FF, as those - // can fit into a single char value. - if (StringCaster::UTF_N == 8 && str_len > 1 && str_len <= 4) { - unsigned char v0 = static_cast<unsigned char>(value[0]); - size_t char0_bytes = !(v0 & 0x80) ? 1 : // low bits only: 0-127 - (v0 & 0xE0) == 0xC0 ? 2 : // 0b110xxxxx - start of 2-byte sequence - (v0 & 0xF0) == 0xE0 ? 3 : // 0b1110xxxx - start of 3-byte sequence - 4; // 0b11110xxx - start of 4-byte sequence - - if (char0_bytes == str_len) { - // If we have a 128-255 value, we can decode it into a single char: - if (char0_bytes == 2 && (v0 & 0xFC) == 0xC0) { // 0x110000xx 0x10xxxxxx - one_char = static_cast<CharT>(((v0 & 3) << 6) + (static_cast<unsigned char>(value[1]) & 0x3F)); - return one_char; - } - // Otherwise we have a single character, but it's > U+00FF - throw value_error("Character code point not in range(0x100)"); - } - } - - // UTF-16 is much easier: we can only have a surrogate pair for values above U+FFFF, thus a - // surrogate pair with total length 2 instantly indicates a range error (but not a "your - // string was too long" error). - else if (StringCaster::UTF_N == 16 && str_len == 2) { - one_char = static_cast<CharT>(value[0]); - if (one_char >= 0xD800 && one_char < 0xE000) - throw value_error("Character code point not in range(0x10000)"); - } - - if (str_len != 1) - throw value_error("Expected a character, but multi-character string found"); - - one_char = value[0]; - return one_char; - } - - static constexpr auto name = _(PYBIND11_STRING_NAME); - template <typename _T> using cast_op_type = pybind11::detail::cast_op_type<_T>; -}; - -// Base implementation for std::tuple and std::pair -template <template<typename...> class Tuple, typename... Ts> class tuple_caster { - using type = Tuple<Ts...>; - static constexpr auto size = sizeof...(Ts); - using indices = make_index_sequence<size>; -public: - - bool load(handle src, bool convert) { - if (!isinstance<sequence>(src)) - return false; - const auto seq = reinterpret_borrow<sequence>(src); - if (seq.size() != size) - return false; - return load_impl(seq, convert, indices{}); - } - - template <typename T> - static handle cast(T &&src, return_value_policy policy, handle parent) { - return cast_impl(std::forward<T>(src), policy, parent, indices{}); - } - - static constexpr auto name = _("Tuple[") + concat(make_caster<Ts>::name...) + _("]"); - - template <typename T> using cast_op_type = type; - - operator type() & { return implicit_cast(indices{}); } - operator type() && { return std::move(*this).implicit_cast(indices{}); } - -protected: - template <size_t... Is> - type implicit_cast(index_sequence<Is...>) & { return type(cast_op<Ts>(std::get<Is>(subcasters))...); } - template <size_t... Is> - type implicit_cast(index_sequence<Is...>) && { return type(cast_op<Ts>(std::move(std::get<Is>(subcasters)))...); } - - static constexpr bool load_impl(const sequence &, bool, index_sequence<>) { return true; } - - template <size_t... Is> - bool load_impl(const sequence &seq, bool convert, index_sequence<Is...>) { - for (bool r : {std::get<Is>(subcasters).load(seq[Is], convert)...}) - if (!r) - return false; - return true; - } - - /* Implementation: Convert a C++ tuple into a Python tuple */ - template <typename T, size_t... Is> - static handle cast_impl(T &&src, return_value_policy policy, handle parent, index_sequence<Is...>) { - std::array<object, size> entries{{ - reinterpret_steal<object>(make_caster<Ts>::cast(std::get<Is>(std::forward<T>(src)), policy, parent))... - }}; - for (const auto &entry: entries) - if (!entry) - return handle(); - tuple result(size); - int counter = 0; - for (auto & entry: entries) - PyTuple_SET_ITEM(result.ptr(), counter++, entry.release().ptr()); - return result.release(); - } - - Tuple<make_caster<Ts>...> subcasters; -}; - -template <typename T1, typename T2> class type_caster<std::pair<T1, T2>> - : public tuple_caster<std::pair, T1, T2> {}; - -template <typename... Ts> class type_caster<std::tuple<Ts...>> - : public tuple_caster<std::tuple, Ts...> {}; - -/// Helper class which abstracts away certain actions. Users can provide specializations for -/// custom holders, but it's only necessary if the type has a non-standard interface. -template <typename T> -struct holder_helper { - static auto get(const T &p) -> decltype(p.get()) { return p.get(); } -}; - -/// Type caster for holder types like std::shared_ptr, etc. -template <typename type, typename holder_type> -struct copyable_holder_caster : public type_caster_base<type> { -public: - using base = type_caster_base<type>; - static_assert(std::is_base_of<base, type_caster<type>>::value, - "Holder classes are only supported for custom types"); - using base::base; - using base::cast; - using base::typeinfo; - using base::value; - - bool load(handle src, bool convert) { - return base::template load_impl<copyable_holder_caster<type, holder_type>>(src, convert); - } - - explicit operator type*() { return this->value; } - explicit operator type&() { return *(this->value); } - explicit operator holder_type*() { return std::addressof(holder); } - - // Workaround for Intel compiler bug - // see pybind11 issue 94 - #if defined(__ICC) || defined(__INTEL_COMPILER) - operator holder_type&() { return holder; } - #else - explicit operator holder_type&() { return holder; } - #endif - - static handle cast(const holder_type &src, return_value_policy, handle) { - const auto *ptr = holder_helper<holder_type>::get(src); - return type_caster_base<type>::cast_holder(ptr, &src); - } - -protected: - friend class type_caster_generic; - void check_holder_compat() { - if (typeinfo->default_holder) - throw cast_error("Unable to load a custom holder type from a default-holder instance"); - } - - bool load_value(value_and_holder &&v_h) { - if (v_h.holder_constructed()) { - value = v_h.value_ptr(); - holder = v_h.template holder<holder_type>(); - return true; - } else { - throw cast_error("Unable to cast from non-held to held instance (T& to Holder<T>) " -#if defined(NDEBUG) - "(compile in debug mode for type information)"); -#else - "of type '" + type_id<holder_type>() + "''"); -#endif - } - } - - template <typename T = holder_type, detail::enable_if_t<!std::is_constructible<T, const T &, type*>::value, int> = 0> - bool try_implicit_casts(handle, bool) { return false; } - - template <typename T = holder_type, detail::enable_if_t<std::is_constructible<T, const T &, type*>::value, int> = 0> - bool try_implicit_casts(handle src, bool convert) { - for (auto &cast : typeinfo->implicit_casts) { - copyable_holder_caster sub_caster(*cast.first); - if (sub_caster.load(src, convert)) { - value = cast.second(sub_caster.value); - holder = holder_type(sub_caster.holder, (type *) value); - return true; - } - } - return false; - } - - static bool try_direct_conversions(handle) { return false; } - - - holder_type holder; -}; - -/// Specialize for the common std::shared_ptr, so users don't need to -template <typename T> -class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> { }; - -template <typename type, typename holder_type> -struct move_only_holder_caster { - static_assert(std::is_base_of<type_caster_base<type>, type_caster<type>>::value, - "Holder classes are only supported for custom types"); - - static handle cast(holder_type &&src, return_value_policy, handle) { - auto *ptr = holder_helper<holder_type>::get(src); - return type_caster_base<type>::cast_holder(ptr, std::addressof(src)); - } - static constexpr auto name = type_caster_base<type>::name; -}; - -template <typename type, typename deleter> -class type_caster<std::unique_ptr<type, deleter>> - : public move_only_holder_caster<type, std::unique_ptr<type, deleter>> { }; - -template <typename type, typename holder_type> -using type_caster_holder = conditional_t<is_copy_constructible<holder_type>::value, - copyable_holder_caster<type, holder_type>, - move_only_holder_caster<type, holder_type>>; - -template <typename T, bool Value = false> struct always_construct_holder { static constexpr bool value = Value; }; - -/// Create a specialization for custom holder types (silently ignores std::shared_ptr) -#define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...) \ - namespace pybind11 { namespace detail { \ - template <typename type> \ - struct always_construct_holder<holder_type> : always_construct_holder<void, ##__VA_ARGS__> { }; \ - template <typename type> \ - class type_caster<holder_type, enable_if_t<!is_shared_ptr<holder_type>::value>> \ - : public type_caster_holder<type, holder_type> { }; \ - }} - -// PYBIND11_DECLARE_HOLDER_TYPE holder types: -template <typename base, typename holder> struct is_holder_type : - std::is_base_of<detail::type_caster_holder<base, holder>, detail::type_caster<holder>> {}; -// Specialization for always-supported unique_ptr holders: -template <typename base, typename deleter> struct is_holder_type<base, std::unique_ptr<base, deleter>> : - std::true_type {}; - -template <typename T> struct handle_type_name { static constexpr auto name = _<T>(); }; -template <> struct handle_type_name<bytes> { static constexpr auto name = _(PYBIND11_BYTES_NAME); }; -template <> struct handle_type_name<args> { static constexpr auto name = _("*args"); }; -template <> struct handle_type_name<kwargs> { static constexpr auto name = _("**kwargs"); }; - -template <typename type> -struct pyobject_caster { - template <typename T = type, enable_if_t<std::is_same<T, handle>::value, int> = 0> - bool load(handle src, bool /* convert */) { value = src; return static_cast<bool>(value); } - - template <typename T = type, enable_if_t<std::is_base_of<object, T>::value, int> = 0> - bool load(handle src, bool /* convert */) { - if (!isinstance<type>(src)) - return false; - value = reinterpret_borrow<type>(src); - return true; - } - - static handle cast(const handle &src, return_value_policy /* policy */, handle /* parent */) { - return src.inc_ref(); - } - PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name); -}; - -template <typename T> -class type_caster<T, enable_if_t<is_pyobject<T>::value>> : public pyobject_caster<T> { }; - -// Our conditions for enabling moving are quite restrictive: -// At compile time: -// - T needs to be a non-const, non-pointer, non-reference type -// - type_caster<T>::operator T&() must exist -// - the type must be move constructible (obviously) -// At run-time: -// - if the type is non-copy-constructible, the object must be the sole owner of the type (i.e. it -// must have ref_count() == 1)h -// If any of the above are not satisfied, we fall back to copying. -template <typename T> using move_is_plain_type = satisfies_none_of<T, - std::is_void, std::is_pointer, std::is_reference, std::is_const ->; -template <typename T, typename SFINAE = void> struct move_always : std::false_type {}; -template <typename T> struct move_always<T, enable_if_t<all_of< - move_is_plain_type<T>, - negation<is_copy_constructible<T>>, - std::is_move_constructible<T>, - std::is_same<decltype(std::declval<make_caster<T>>().operator T&()), T&> ->::value>> : std::true_type {}; -template <typename T, typename SFINAE = void> struct move_if_unreferenced : std::false_type {}; -template <typename T> struct move_if_unreferenced<T, enable_if_t<all_of< - move_is_plain_type<T>, - negation<move_always<T>>, - std::is_move_constructible<T>, - std::is_same<decltype(std::declval<make_caster<T>>().operator T&()), T&> ->::value>> : std::true_type {}; -template <typename T> using move_never = none_of<move_always<T>, move_if_unreferenced<T>>; - -// Detect whether returning a `type` from a cast on type's type_caster is going to result in a -// reference or pointer to a local variable of the type_caster. Basically, only -// non-reference/pointer `type`s and reference/pointers from a type_caster_generic are safe; -// everything else returns a reference/pointer to a local variable. -template <typename type> using cast_is_temporary_value_reference = bool_constant< - (std::is_reference<type>::value || std::is_pointer<type>::value) && - !std::is_base_of<type_caster_generic, make_caster<type>>::value && - !std::is_same<intrinsic_t<type>, void>::value ->; - -// When a value returned from a C++ function is being cast back to Python, we almost always want to -// force `policy = move`, regardless of the return value policy the function/method was declared -// with. -template <typename Return, typename SFINAE = void> struct return_value_policy_override { - static return_value_policy policy(return_value_policy p) { return p; } -}; - -template <typename Return> struct return_value_policy_override<Return, - detail::enable_if_t<std::is_base_of<type_caster_generic, make_caster<Return>>::value, void>> { - static return_value_policy policy(return_value_policy p) { - return !std::is_lvalue_reference<Return>::value && - !std::is_pointer<Return>::value - ? return_value_policy::move : p; - } -}; - -// Basic python -> C++ casting; throws if casting fails -template <typename T, typename SFINAE> type_caster<T, SFINAE> &load_type(type_caster<T, SFINAE> &conv, const handle &handle) { - if (!conv.load(handle, true)) { -#if defined(NDEBUG) - throw cast_error("Unable to cast Python instance to C++ type (compile in debug mode for details)"); -#else - throw cast_error("Unable to cast Python instance of type " + - (std::string) str(handle.get_type()) + " to C++ type '" + type_id<T>() + "'"); -#endif - } - return conv; -} -// Wrapper around the above that also constructs and returns a type_caster -template <typename T> make_caster<T> load_type(const handle &handle) { - make_caster<T> conv; - load_type(conv, handle); - return conv; -} - -NAMESPACE_END(detail) - -// pytype -> C++ type -template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0> -T cast(const handle &handle) { - using namespace detail; - static_assert(!cast_is_temporary_value_reference<T>::value, - "Unable to cast type to reference: value is local to type caster"); - return cast_op<T>(load_type<T>(handle)); -} - -// pytype -> pytype (calls converting constructor) -template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, int> = 0> -T cast(const handle &handle) { return T(reinterpret_borrow<object>(handle)); } - -// C++ type -> py::object -template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0> -object cast(const T &value, return_value_policy policy = return_value_policy::automatic_reference, - handle parent = handle()) { - if (policy == return_value_policy::automatic) - policy = std::is_pointer<T>::value ? return_value_policy::take_ownership : return_value_policy::copy; - else if (policy == return_value_policy::automatic_reference) - policy = std::is_pointer<T>::value ? return_value_policy::reference : return_value_policy::copy; - return reinterpret_steal<object>(detail::make_caster<T>::cast(value, policy, parent)); -} - -template <typename T> T handle::cast() const { return pybind11::cast<T>(*this); } -template <> inline void handle::cast() const { return; } - -template <typename T> -detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) { - if (obj.ref_count() > 1) -#if defined(NDEBUG) - throw cast_error("Unable to cast Python instance to C++ rvalue: instance has multiple references" - " (compile in debug mode for details)"); -#else - throw cast_error("Unable to move from Python " + (std::string) str(obj.get_type()) + - " instance to C++ " + type_id<T>() + " instance: instance has multiple references"); -#endif - - // Move into a temporary and return that, because the reference may be a local value of `conv` - T ret = std::move(detail::load_type<T>(obj).operator T&()); - return ret; -} - -// Calling cast() on an rvalue calls pybind::cast with the object rvalue, which does: -// - If we have to move (because T has no copy constructor), do it. This will fail if the moved -// object has multiple references, but trying to copy will fail to compile. -// - If both movable and copyable, check ref count: if 1, move; otherwise copy -// - Otherwise (not movable), copy. -template <typename T> detail::enable_if_t<detail::move_always<T>::value, T> cast(object &&object) { - return move<T>(std::move(object)); -} -template <typename T> detail::enable_if_t<detail::move_if_unreferenced<T>::value, T> cast(object &&object) { - if (object.ref_count() > 1) - return cast<T>(object); - else - return move<T>(std::move(object)); -} -template <typename T> detail::enable_if_t<detail::move_never<T>::value, T> cast(object &&object) { - return cast<T>(object); -} - -template <typename T> T object::cast() const & { return pybind11::cast<T>(*this); } -template <typename T> T object::cast() && { return pybind11::cast<T>(std::move(*this)); } -template <> inline void object::cast() const & { return; } -template <> inline void object::cast() && { return; } - -NAMESPACE_BEGIN(detail) - -// Declared in pytypes.h: -template <typename T, enable_if_t<!is_pyobject<T>::value, int>> -object object_or_cast(T &&o) { return pybind11::cast(std::forward<T>(o)); } - -struct overload_unused {}; // Placeholder type for the unneeded (and dead code) static variable in the OVERLOAD_INT macro -template <typename ret_type> using overload_caster_t = conditional_t< - cast_is_temporary_value_reference<ret_type>::value, make_caster<ret_type>, overload_unused>; - -// Trampoline use: for reference/pointer types to value-converted values, we do a value cast, then -// store the result in the given variable. For other types, this is a no-op. -template <typename T> enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&o, make_caster<T> &caster) { - return cast_op<T>(load_type(caster, o)); -} -template <typename T> enable_if_t<!cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&, overload_unused &) { - pybind11_fail("Internal error: cast_ref fallback invoked"); } - -// Trampoline use: Having a pybind11::cast with an invalid reference type is going to static_assert, even -// though if it's in dead code, so we provide a "trampoline" to pybind11::cast that only does anything in -// cases where pybind11::cast is valid. -template <typename T> enable_if_t<!cast_is_temporary_value_reference<T>::value, T> cast_safe(object &&o) { - return pybind11::cast<T>(std::move(o)); } -template <typename T> enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_safe(object &&) { - pybind11_fail("Internal error: cast_safe fallback invoked"); } -template <> inline void cast_safe<void>(object &&) {} - -NAMESPACE_END(detail) - -template <return_value_policy policy = return_value_policy::automatic_reference> -tuple make_tuple() { return tuple(0); } - -template <return_value_policy policy = return_value_policy::automatic_reference, - typename... Args> tuple make_tuple(Args&&... args_) { - constexpr size_t size = sizeof...(Args); - std::array<object, size> args { - { reinterpret_steal<object>(detail::make_caster<Args>::cast( - std::forward<Args>(args_), policy, nullptr))... } - }; - for (size_t i = 0; i < args.size(); i++) { - if (!args[i]) { -#if defined(NDEBUG) - throw cast_error("make_tuple(): unable to convert arguments to Python object (compile in debug mode for details)"); -#else - std::array<std::string, size> argtypes { {type_id<Args>()...} }; - throw cast_error("make_tuple(): unable to convert argument of type '" + - argtypes[i] + "' to Python object"); -#endif - } - } - tuple result(size); - int counter = 0; - for (auto &arg_value : args) - PyTuple_SET_ITEM(result.ptr(), counter++, arg_value.release().ptr()); - return result; -} - -/// \ingroup annotations -/// Annotation for arguments -struct arg { - /// Constructs an argument with the name of the argument; if null or omitted, this is a positional argument. - constexpr explicit arg(const char *name = nullptr) : name(name), flag_noconvert(false), flag_none(true) { } - /// Assign a value to this argument - template <typename T> arg_v operator=(T &&value) const; - /// Indicate that the type should not be converted in the type caster - arg &noconvert(bool flag = true) { flag_noconvert = flag; return *this; } - /// Indicates that the argument should/shouldn't allow None (e.g. for nullable pointer args) - arg &none(bool flag = true) { flag_none = flag; return *this; } - - const char *name; ///< If non-null, this is a named kwargs argument - bool flag_noconvert : 1; ///< If set, do not allow conversion (requires a supporting type caster!) - bool flag_none : 1; ///< If set (the default), allow None to be passed to this argument -}; - -/// \ingroup annotations -/// Annotation for arguments with values -struct arg_v : arg { -private: - template <typename T> - arg_v(arg &&base, T &&x, const char *descr = nullptr) - : arg(base), - value(reinterpret_steal<object>( - detail::make_caster<T>::cast(x, return_value_policy::automatic, {}) - )), - descr(descr) -#if !defined(NDEBUG) - , type(type_id<T>()) -#endif - { } - -public: - /// Direct construction with name, default, and description - template <typename T> - arg_v(const char *name, T &&x, const char *descr = nullptr) - : arg_v(arg(name), std::forward<T>(x), descr) { } - - /// Called internally when invoking `py::arg("a") = value` - template <typename T> - arg_v(const arg &base, T &&x, const char *descr = nullptr) - : arg_v(arg(base), std::forward<T>(x), descr) { } - - /// Same as `arg::noconvert()`, but returns *this as arg_v&, not arg& - arg_v &noconvert(bool flag = true) { arg::noconvert(flag); return *this; } - - /// Same as `arg::nonone()`, but returns *this as arg_v&, not arg& - arg_v &none(bool flag = true) { arg::none(flag); return *this; } - - /// The default value - object value; - /// The (optional) description of the default value - const char *descr; -#if !defined(NDEBUG) - /// The C++ type name of the default value (only available when compiled in debug mode) - std::string type; -#endif -}; - -template <typename T> -arg_v arg::operator=(T &&value) const { return {std::move(*this), std::forward<T>(value)}; } - -/// Alias for backward compatibility -- to be removed in version 2.0 -template <typename /*unused*/> using arg_t = arg_v; - -inline namespace literals { -/** \rst - String literal version of `arg` - \endrst */ -constexpr arg operator"" _a(const char *name, size_t) { return arg(name); } -} - -NAMESPACE_BEGIN(detail) - -// forward declaration (definition in attr.h) -struct function_record; - -/// Internal data associated with a single function call -struct function_call { - function_call(const function_record &f, handle p); // Implementation in attr.h - - /// The function data: - const function_record &func; - - /// Arguments passed to the function: - std::vector<handle> args; - - /// The `convert` value the arguments should be loaded with - std::vector<bool> args_convert; - - /// Extra references for the optional `py::args` and/or `py::kwargs` arguments (which, if - /// present, are also in `args` but without a reference). - object args_ref, kwargs_ref; - - /// The parent, if any - handle parent; - - /// If this is a call to an initializer, this argument contains `self` - handle init_self; -}; - - -/// Helper class which loads arguments for C++ functions called from Python -template <typename... Args> -class argument_loader { - using indices = make_index_sequence<sizeof...(Args)>; - - template <typename Arg> using argument_is_args = std::is_same<intrinsic_t<Arg>, args>; - template <typename Arg> using argument_is_kwargs = std::is_same<intrinsic_t<Arg>, kwargs>; - // Get args/kwargs argument positions relative to the end of the argument list: - static constexpr auto args_pos = constexpr_first<argument_is_args, Args...>() - (int) sizeof...(Args), - kwargs_pos = constexpr_first<argument_is_kwargs, Args...>() - (int) sizeof...(Args); - - static constexpr bool args_kwargs_are_last = kwargs_pos >= - 1 && args_pos >= kwargs_pos - 1; - - static_assert(args_kwargs_are_last, "py::args/py::kwargs are only permitted as the last argument(s) of a function"); - -public: - static constexpr bool has_kwargs = kwargs_pos < 0; - static constexpr bool has_args = args_pos < 0; - - static constexpr auto arg_names = concat(type_descr(make_caster<Args>::name)...); - - bool load_args(function_call &call) { - return load_impl_sequence(call, indices{}); - } - - template <typename Return, typename Guard, typename Func> - enable_if_t<!std::is_void<Return>::value, Return> call(Func &&f) && { - return std::move(*this).template call_impl<Return>(std::forward<Func>(f), indices{}, Guard{}); - } - - template <typename Return, typename Guard, typename Func> - enable_if_t<std::is_void<Return>::value, void_type> call(Func &&f) && { - std::move(*this).template call_impl<Return>(std::forward<Func>(f), indices{}, Guard{}); - return void_type(); - } - -private: - - static bool load_impl_sequence(function_call &, index_sequence<>) { return true; } - - template <size_t... Is> - bool load_impl_sequence(function_call &call, index_sequence<Is...>) { - for (bool r : {std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])...}) - if (!r) - return false; - return true; - } - - template <typename Return, typename Func, size_t... Is, typename Guard> - Return call_impl(Func &&f, index_sequence<Is...>, Guard &&) { - return std::forward<Func>(f)(cast_op<Args>(std::move(std::get<Is>(argcasters)))...); - } - - std::tuple<make_caster<Args>...> argcasters; -}; - -/// Helper class which collects only positional arguments for a Python function call. -/// A fancier version below can collect any argument, but this one is optimal for simple calls. -template <return_value_policy policy> -class simple_collector { -public: - template <typename... Ts> - explicit simple_collector(Ts &&...values) - : m_args(pybind11::make_tuple<policy>(std::forward<Ts>(values)...)) { } - - const tuple &args() const & { return m_args; } - dict kwargs() const { return {}; } - - tuple args() && { return std::move(m_args); } - - /// Call a Python function and pass the collected arguments - object call(PyObject *ptr) const { - PyObject *result = PyObject_CallObject(ptr, m_args.ptr()); - if (!result) - throw error_already_set(); - return reinterpret_steal<object>(result); - } - -private: - tuple m_args; -}; - -/// Helper class which collects positional, keyword, * and ** arguments for a Python function call -template <return_value_policy policy> -class unpacking_collector { -public: - template <typename... Ts> - explicit unpacking_collector(Ts &&...values) { - // Tuples aren't (easily) resizable so a list is needed for collection, - // but the actual function call strictly requires a tuple. - auto args_list = list(); - int _[] = { 0, (process(args_list, std::forward<Ts>(values)), 0)... }; - ignore_unused(_); - - m_args = std::move(args_list); - } - - const tuple &args() const & { return m_args; } - const dict &kwargs() const & { return m_kwargs; } - - tuple args() && { return std::move(m_args); } - dict kwargs() && { return std::move(m_kwargs); } - - /// Call a Python function and pass the collected arguments - object call(PyObject *ptr) const { - PyObject *result = PyObject_Call(ptr, m_args.ptr(), m_kwargs.ptr()); - if (!result) - throw error_already_set(); - return reinterpret_steal<object>(result); - } - -private: - template <typename T> - void process(list &args_list, T &&x) { - auto o = reinterpret_steal<object>(detail::make_caster<T>::cast(std::forward<T>(x), policy, {})); - if (!o) { -#if defined(NDEBUG) - argument_cast_error(); -#else - argument_cast_error(std::to_string(args_list.size()), type_id<T>()); -#endif - } - args_list.append(o); - } - - void process(list &args_list, detail::args_proxy ap) { - for (const auto &a : ap) - args_list.append(a); - } - - void process(list &/*args_list*/, arg_v a) { - if (!a.name) -#if defined(NDEBUG) - nameless_argument_error(); -#else - nameless_argument_error(a.type); -#endif - - if (m_kwargs.contains(a.name)) { -#if defined(NDEBUG) - multiple_values_error(); -#else - multiple_values_error(a.name); -#endif - } - if (!a.value) { -#if defined(NDEBUG) - argument_cast_error(); -#else - argument_cast_error(a.name, a.type); -#endif - } - m_kwargs[a.name] = a.value; - } - - void process(list &/*args_list*/, detail::kwargs_proxy kp) { - if (!kp) - return; - for (const auto &k : reinterpret_borrow<dict>(kp)) { - if (m_kwargs.contains(k.first)) { -#if defined(NDEBUG) - multiple_values_error(); -#else - multiple_values_error(str(k.first)); -#endif - } - m_kwargs[k.first] = k.second; - } - } - - [[noreturn]] static void nameless_argument_error() { - throw type_error("Got kwargs without a name; only named arguments " - "may be passed via py::arg() to a python function call. " - "(compile in debug mode for details)"); - } - [[noreturn]] static void nameless_argument_error(std::string type) { - throw type_error("Got kwargs without a name of type '" + type + "'; only named " - "arguments may be passed via py::arg() to a python function call. "); - } - [[noreturn]] static void multiple_values_error() { - throw type_error("Got multiple values for keyword argument " - "(compile in debug mode for details)"); - } - - [[noreturn]] static void multiple_values_error(std::string name) { - throw type_error("Got multiple values for keyword argument '" + name + "'"); - } - - [[noreturn]] static void argument_cast_error() { - throw cast_error("Unable to convert call argument to Python object " - "(compile in debug mode for details)"); - } - - [[noreturn]] static void argument_cast_error(std::string name, std::string type) { - throw cast_error("Unable to convert call argument '" + name - + "' of type '" + type + "' to Python object"); - } - -private: - tuple m_args; - dict m_kwargs; -}; - -/// Collect only positional arguments for a Python function call -template <return_value_policy policy, typename... Args, - typename = enable_if_t<all_of<is_positional<Args>...>::value>> -simple_collector<policy> collect_arguments(Args &&...args) { - return simple_collector<policy>(std::forward<Args>(args)...); -} - -/// Collect all arguments, including keywords and unpacking (only instantiated when needed) -template <return_value_policy policy, typename... Args, - typename = enable_if_t<!all_of<is_positional<Args>...>::value>> -unpacking_collector<policy> collect_arguments(Args &&...args) { - // Following argument order rules for generalized unpacking according to PEP 448 - static_assert( - constexpr_last<is_positional, Args...>() < constexpr_first<is_keyword_or_ds, Args...>() - && constexpr_last<is_s_unpacking, Args...>() < constexpr_first<is_ds_unpacking, Args...>(), - "Invalid function call: positional args must precede keywords and ** unpacking; " - "* unpacking must precede ** unpacking" - ); - return unpacking_collector<policy>(std::forward<Args>(args)...); -} - -template <typename Derived> -template <return_value_policy policy, typename... Args> -object object_api<Derived>::operator()(Args &&...args) const { - return detail::collect_arguments<policy>(std::forward<Args>(args)...).call(derived().ptr()); -} - -template <typename Derived> -template <return_value_policy policy, typename... Args> -object object_api<Derived>::call(Args &&...args) const { - return operator()<policy>(std::forward<Args>(args)...); -} - -NAMESPACE_END(detail) - -#define PYBIND11_MAKE_OPAQUE(...) \ - namespace pybind11 { namespace detail { \ - template<> class type_caster<__VA_ARGS__> : public type_caster_base<__VA_ARGS__> { }; \ - }} - -/// Lets you pass a type containing a `,` through a macro parameter without needing a separate -/// typedef, e.g.: `PYBIND11_OVERLOAD(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)` -#define PYBIND11_TYPE(...) __VA_ARGS__ - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/chrono.h b/external/pybind11/include/pybind11/chrono.h deleted file mode 100644 index ea777e69..00000000 --- a/external/pybind11/include/pybind11/chrono.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - pybind11/chrono.h: Transparent conversion between std::chrono and python's datetime - - Copyright (c) 2016 Trent Houliston <trent@houliston.me> and - Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" -#include <cmath> -#include <ctime> -#include <chrono> -#include <datetime.h> - -// Backport the PyDateTime_DELTA functions from Python3.3 if required -#ifndef PyDateTime_DELTA_GET_DAYS -#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days) -#endif -#ifndef PyDateTime_DELTA_GET_SECONDS -#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)o)->seconds) -#endif -#ifndef PyDateTime_DELTA_GET_MICROSECONDS -#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds) -#endif - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -template <typename type> class duration_caster { -public: - typedef typename type::rep rep; - typedef typename type::period period; - - typedef std::chrono::duration<uint_fast32_t, std::ratio<86400>> days; - - bool load(handle src, bool) { - using namespace std::chrono; - - // Lazy initialise the PyDateTime import - if (!PyDateTimeAPI) { PyDateTime_IMPORT; } - - if (!src) return false; - // If invoked with datetime.delta object - if (PyDelta_Check(src.ptr())) { - value = type(duration_cast<duration<rep, period>>( - days(PyDateTime_DELTA_GET_DAYS(src.ptr())) - + seconds(PyDateTime_DELTA_GET_SECONDS(src.ptr())) - + microseconds(PyDateTime_DELTA_GET_MICROSECONDS(src.ptr())))); - return true; - } - // If invoked with a float we assume it is seconds and convert - else if (PyFloat_Check(src.ptr())) { - value = type(duration_cast<duration<rep, period>>(duration<double>(PyFloat_AsDouble(src.ptr())))); - return true; - } - else return false; - } - - // If this is a duration just return it back - static const std::chrono::duration<rep, period>& get_duration(const std::chrono::duration<rep, period> &src) { - return src; - } - - // If this is a time_point get the time_since_epoch - template <typename Clock> static std::chrono::duration<rep, period> get_duration(const std::chrono::time_point<Clock, std::chrono::duration<rep, period>> &src) { - return src.time_since_epoch(); - } - - static handle cast(const type &src, return_value_policy /* policy */, handle /* parent */) { - using namespace std::chrono; - - // Use overloaded function to get our duration from our source - // Works out if it is a duration or time_point and get the duration - auto d = get_duration(src); - - // Lazy initialise the PyDateTime import - if (!PyDateTimeAPI) { PyDateTime_IMPORT; } - - // Declare these special duration types so the conversions happen with the correct primitive types (int) - using dd_t = duration<int, std::ratio<86400>>; - using ss_t = duration<int, std::ratio<1>>; - using us_t = duration<int, std::micro>; - - auto dd = duration_cast<dd_t>(d); - auto subd = d - dd; - auto ss = duration_cast<ss_t>(subd); - auto us = duration_cast<us_t>(subd - ss); - return PyDelta_FromDSU(dd.count(), ss.count(), us.count()); - } - - PYBIND11_TYPE_CASTER(type, _("datetime.timedelta")); -}; - -// This is for casting times on the system clock into datetime.datetime instances -template <typename Duration> class type_caster<std::chrono::time_point<std::chrono::system_clock, Duration>> { -public: - typedef std::chrono::time_point<std::chrono::system_clock, Duration> type; - bool load(handle src, bool) { - using namespace std::chrono; - - // Lazy initialise the PyDateTime import - if (!PyDateTimeAPI) { PyDateTime_IMPORT; } - - if (!src) return false; - - std::tm cal; - microseconds msecs; - - if (PyDateTime_Check(src.ptr())) { - cal.tm_sec = PyDateTime_DATE_GET_SECOND(src.ptr()); - cal.tm_min = PyDateTime_DATE_GET_MINUTE(src.ptr()); - cal.tm_hour = PyDateTime_DATE_GET_HOUR(src.ptr()); - cal.tm_mday = PyDateTime_GET_DAY(src.ptr()); - cal.tm_mon = PyDateTime_GET_MONTH(src.ptr()) - 1; - cal.tm_year = PyDateTime_GET_YEAR(src.ptr()) - 1900; - cal.tm_isdst = -1; - msecs = microseconds(PyDateTime_DATE_GET_MICROSECOND(src.ptr())); - } else if (PyDate_Check(src.ptr())) { - cal.tm_sec = 0; - cal.tm_min = 0; - cal.tm_hour = 0; - cal.tm_mday = PyDateTime_GET_DAY(src.ptr()); - cal.tm_mon = PyDateTime_GET_MONTH(src.ptr()) - 1; - cal.tm_year = PyDateTime_GET_YEAR(src.ptr()) - 1900; - cal.tm_isdst = -1; - msecs = microseconds(0); - } else if (PyTime_Check(src.ptr())) { - cal.tm_sec = PyDateTime_TIME_GET_SECOND(src.ptr()); - cal.tm_min = PyDateTime_TIME_GET_MINUTE(src.ptr()); - cal.tm_hour = PyDateTime_TIME_GET_HOUR(src.ptr()); - cal.tm_mday = 1; // This date (day, month, year) = (1, 0, 70) - cal.tm_mon = 0; // represents 1-Jan-1970, which is the first - cal.tm_year = 70; // earliest available date for Python's datetime - cal.tm_isdst = -1; - msecs = microseconds(PyDateTime_TIME_GET_MICROSECOND(src.ptr())); - } - else return false; - - value = system_clock::from_time_t(std::mktime(&cal)) + msecs; - return true; - } - - static handle cast(const std::chrono::time_point<std::chrono::system_clock, Duration> &src, return_value_policy /* policy */, handle /* parent */) { - using namespace std::chrono; - - // Lazy initialise the PyDateTime import - if (!PyDateTimeAPI) { PyDateTime_IMPORT; } - - std::time_t tt = system_clock::to_time_t(time_point_cast<system_clock::duration>(src)); - // this function uses static memory so it's best to copy it out asap just in case - // otherwise other code that is using localtime may break this (not just python code) - std::tm localtime = *std::localtime(&tt); - - // Declare these special duration types so the conversions happen with the correct primitive types (int) - using us_t = duration<int, std::micro>; - - return PyDateTime_FromDateAndTime(localtime.tm_year + 1900, - localtime.tm_mon + 1, - localtime.tm_mday, - localtime.tm_hour, - localtime.tm_min, - localtime.tm_sec, - (duration_cast<us_t>(src.time_since_epoch() % seconds(1))).count()); - } - PYBIND11_TYPE_CASTER(type, _("datetime.datetime")); -}; - -// Other clocks that are not the system clock are not measured as datetime.datetime objects -// since they are not measured on calendar time. So instead we just make them timedeltas -// Or if they have passed us a time as a float we convert that -template <typename Clock, typename Duration> class type_caster<std::chrono::time_point<Clock, Duration>> -: public duration_caster<std::chrono::time_point<Clock, Duration>> { -}; - -template <typename Rep, typename Period> class type_caster<std::chrono::duration<Rep, Period>> -: public duration_caster<std::chrono::duration<Rep, Period>> { -}; - -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/common.h b/external/pybind11/include/pybind11/common.h deleted file mode 100644 index 6c8a4f1e..00000000 --- a/external/pybind11/include/pybind11/common.h +++ /dev/null @@ -1,2 +0,0 @@ -#include "detail/common.h" -#warning "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'." diff --git a/external/pybind11/include/pybind11/complex.h b/external/pybind11/include/pybind11/complex.h deleted file mode 100644 index 3f896385..00000000 --- a/external/pybind11/include/pybind11/complex.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - pybind11/complex.h: Complex number support - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" -#include <complex> - -/// glibc defines I as a macro which breaks things, e.g., boost template names -#ifdef I -# undef I -#endif - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -template <typename T> struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> { - static constexpr const char c = format_descriptor<T>::c; - static constexpr const char value[3] = { 'Z', c, '\0' }; - static std::string format() { return std::string(value); } -}; - -#ifndef PYBIND11_CPP17 - -template <typename T> constexpr const char format_descriptor< - std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>>::value[3]; - -#endif - -NAMESPACE_BEGIN(detail) - -template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> { - static constexpr bool value = true; - static constexpr int index = is_fmt_numeric<T>::index + 3; -}; - -template <typename T> class type_caster<std::complex<T>> { -public: - bool load(handle src, bool convert) { - if (!src) - return false; - if (!convert && !PyComplex_Check(src.ptr())) - return false; - Py_complex result = PyComplex_AsCComplex(src.ptr()); - if (result.real == -1.0 && PyErr_Occurred()) { - PyErr_Clear(); - return false; - } - value = std::complex<T>((T) result.real, (T) result.imag); - return true; - } - - static handle cast(const std::complex<T> &src, return_value_policy /* policy */, handle /* parent */) { - return PyComplex_FromDoubles((double) src.real(), (double) src.imag()); - } - - PYBIND11_TYPE_CASTER(std::complex<T>, _("complex")); -}; -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/detail/class.h b/external/pybind11/include/pybind11/detail/class.h deleted file mode 100644 index 230ae81a..00000000 --- a/external/pybind11/include/pybind11/detail/class.h +++ /dev/null @@ -1,632 +0,0 @@ -/* - pybind11/detail/class.h: Python C API implementation details for py::class_ - - Copyright (c) 2017 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "../attr.h" -#include "../options.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -#if PY_VERSION_HEX >= 0x03030000 -# define PYBIND11_BUILTIN_QUALNAME -# define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj) -#else -// In pre-3.3 Python, we still set __qualname__ so that we can produce reliable function type -// signatures; in 3.3+ this macro expands to nothing: -# define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj) setattr((PyObject *) obj, "__qualname__", nameobj) -#endif - -inline PyTypeObject *type_incref(PyTypeObject *type) { - Py_INCREF(type); - return type; -} - -#if !defined(PYPY_VERSION) - -/// `pybind11_static_property.__get__()`: Always pass the class instead of the instance. -extern "C" inline PyObject *pybind11_static_get(PyObject *self, PyObject * /*ob*/, PyObject *cls) { - return PyProperty_Type.tp_descr_get(self, cls, cls); -} - -/// `pybind11_static_property.__set__()`: Just like the above `__get__()`. -extern "C" inline int pybind11_static_set(PyObject *self, PyObject *obj, PyObject *value) { - PyObject *cls = PyType_Check(obj) ? obj : (PyObject *) Py_TYPE(obj); - return PyProperty_Type.tp_descr_set(self, cls, value); -} - -/** A `static_property` is the same as a `property` but the `__get__()` and `__set__()` - methods are modified to always use the object type instead of a concrete instance. - Return value: New reference. */ -inline PyTypeObject *make_static_property_type() { - constexpr auto *name = "pybind11_static_property"; - auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name)); - - /* Danger zone: from now (and until PyType_Ready), make sure to - issue no Python C API calls which could potentially invoke the - garbage collector (the GC will call type_traverse(), which will in - turn find the newly constructed type in an invalid state) */ - auto heap_type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0); - if (!heap_type) - pybind11_fail("make_static_property_type(): error allocating type!"); - - heap_type->ht_name = name_obj.inc_ref().ptr(); -#ifdef PYBIND11_BUILTIN_QUALNAME - heap_type->ht_qualname = name_obj.inc_ref().ptr(); -#endif - - auto type = &heap_type->ht_type; - type->tp_name = name; - type->tp_base = type_incref(&PyProperty_Type); - type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; - type->tp_descr_get = pybind11_static_get; - type->tp_descr_set = pybind11_static_set; - - if (PyType_Ready(type) < 0) - pybind11_fail("make_static_property_type(): failure in PyType_Ready()!"); - - setattr((PyObject *) type, "__module__", str("pybind11_builtins")); - PYBIND11_SET_OLDPY_QUALNAME(type, name_obj); - - return type; -} - -#else // PYPY - -/** PyPy has some issues with the above C API, so we evaluate Python code instead. - This function will only be called once so performance isn't really a concern. - Return value: New reference. */ -inline PyTypeObject *make_static_property_type() { - auto d = dict(); - PyObject *result = PyRun_String(R"(\ - class pybind11_static_property(property): - def __get__(self, obj, cls): - return property.__get__(self, cls, cls) - - def __set__(self, obj, value): - cls = obj if isinstance(obj, type) else type(obj) - property.__set__(self, cls, value) - )", Py_file_input, d.ptr(), d.ptr() - ); - if (result == nullptr) - throw error_already_set(); - Py_DECREF(result); - return (PyTypeObject *) d["pybind11_static_property"].cast<object>().release().ptr(); -} - -#endif // PYPY - -/** Types with static properties need to handle `Type.static_prop = x` in a specific way. - By default, Python replaces the `static_property` itself, but for wrapped C++ types - we need to call `static_property.__set__()` in order to propagate the new value to - the underlying C++ data structure. */ -extern "C" inline int pybind11_meta_setattro(PyObject* obj, PyObject* name, PyObject* value) { - // Use `_PyType_Lookup()` instead of `PyObject_GetAttr()` in order to get the raw - // descriptor (`property`) instead of calling `tp_descr_get` (`property.__get__()`). - PyObject *descr = _PyType_Lookup((PyTypeObject *) obj, name); - - // The following assignment combinations are possible: - // 1. `Type.static_prop = value` --> descr_set: `Type.static_prop.__set__(value)` - // 2. `Type.static_prop = other_static_prop` --> setattro: replace existing `static_prop` - // 3. `Type.regular_attribute = value` --> setattro: regular attribute assignment - const auto static_prop = (PyObject *) get_internals().static_property_type; - const auto call_descr_set = descr && PyObject_IsInstance(descr, static_prop) - && !PyObject_IsInstance(value, static_prop); - if (call_descr_set) { - // Call `static_property.__set__()` instead of replacing the `static_property`. -#if !defined(PYPY_VERSION) - return Py_TYPE(descr)->tp_descr_set(descr, obj, value); -#else - if (PyObject *result = PyObject_CallMethod(descr, "__set__", "OO", obj, value)) { - Py_DECREF(result); - return 0; - } else { - return -1; - } -#endif - } else { - // Replace existing attribute. - return PyType_Type.tp_setattro(obj, name, value); - } -} - -#if PY_MAJOR_VERSION >= 3 -/** - * Python 3's PyInstanceMethod_Type hides itself via its tp_descr_get, which prevents aliasing - * methods via cls.attr("m2") = cls.attr("m1"): instead the tp_descr_get returns a plain function, - * when called on a class, or a PyMethod, when called on an instance. Override that behaviour here - * to do a special case bypass for PyInstanceMethod_Types. - */ -extern "C" inline PyObject *pybind11_meta_getattro(PyObject *obj, PyObject *name) { - PyObject *descr = _PyType_Lookup((PyTypeObject *) obj, name); - if (descr && PyInstanceMethod_Check(descr)) { - Py_INCREF(descr); - return descr; - } - else { - return PyType_Type.tp_getattro(obj, name); - } -} -#endif - -/** This metaclass is assigned by default to all pybind11 types and is required in order - for static properties to function correctly. Users may override this using `py::metaclass`. - Return value: New reference. */ -inline PyTypeObject* make_default_metaclass() { - constexpr auto *name = "pybind11_type"; - auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name)); - - /* Danger zone: from now (and until PyType_Ready), make sure to - issue no Python C API calls which could potentially invoke the - garbage collector (the GC will call type_traverse(), which will in - turn find the newly constructed type in an invalid state) */ - auto heap_type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0); - if (!heap_type) - pybind11_fail("make_default_metaclass(): error allocating metaclass!"); - - heap_type->ht_name = name_obj.inc_ref().ptr(); -#ifdef PYBIND11_BUILTIN_QUALNAME - heap_type->ht_qualname = name_obj.inc_ref().ptr(); -#endif - - auto type = &heap_type->ht_type; - type->tp_name = name; - type->tp_base = type_incref(&PyType_Type); - type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; - - type->tp_setattro = pybind11_meta_setattro; -#if PY_MAJOR_VERSION >= 3 - type->tp_getattro = pybind11_meta_getattro; -#endif - - if (PyType_Ready(type) < 0) - pybind11_fail("make_default_metaclass(): failure in PyType_Ready()!"); - - setattr((PyObject *) type, "__module__", str("pybind11_builtins")); - PYBIND11_SET_OLDPY_QUALNAME(type, name_obj); - - return type; -} - -/// For multiple inheritance types we need to recursively register/deregister base pointers for any -/// base classes with pointers that are difference from the instance value pointer so that we can -/// correctly recognize an offset base class pointer. This calls a function with any offset base ptrs. -inline void traverse_offset_bases(void *valueptr, const detail::type_info *tinfo, instance *self, - bool (*f)(void * /*parentptr*/, instance * /*self*/)) { - for (handle h : reinterpret_borrow<tuple>(tinfo->type->tp_bases)) { - if (auto parent_tinfo = get_type_info((PyTypeObject *) h.ptr())) { - for (auto &c : parent_tinfo->implicit_casts) { - if (c.first == tinfo->cpptype) { - auto *parentptr = c.second(valueptr); - if (parentptr != valueptr) - f(parentptr, self); - traverse_offset_bases(parentptr, parent_tinfo, self, f); - break; - } - } - } - } -} - -inline bool register_instance_impl(void *ptr, instance *self) { - get_internals().registered_instances.emplace(ptr, self); - return true; // unused, but gives the same signature as the deregister func -} -inline bool deregister_instance_impl(void *ptr, instance *self) { - auto ®istered_instances = get_internals().registered_instances; - auto range = registered_instances.equal_range(ptr); - for (auto it = range.first; it != range.second; ++it) { - if (Py_TYPE(self) == Py_TYPE(it->second)) { - registered_instances.erase(it); - return true; - } - } - return false; -} - -inline void register_instance(instance *self, void *valptr, const type_info *tinfo) { - register_instance_impl(valptr, self); - if (!tinfo->simple_ancestors) - traverse_offset_bases(valptr, tinfo, self, register_instance_impl); -} - -inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo) { - bool ret = deregister_instance_impl(valptr, self); - if (!tinfo->simple_ancestors) - traverse_offset_bases(valptr, tinfo, self, deregister_instance_impl); - return ret; -} - -/// Instance creation function for all pybind11 types. It allocates the internal instance layout for -/// holding C++ objects and holders. Allocation is done lazily (the first time the instance is cast -/// to a reference or pointer), and initialization is done by an `__init__` function. -inline PyObject *make_new_instance(PyTypeObject *type) { -#if defined(PYPY_VERSION) - // PyPy gets tp_basicsize wrong (issue 2482) under multiple inheritance when the first inherited - // object is a a plain Python type (i.e. not derived from an extension type). Fix it. - ssize_t instance_size = static_cast<ssize_t>(sizeof(instance)); - if (type->tp_basicsize < instance_size) { - type->tp_basicsize = instance_size; - } -#endif - PyObject *self = type->tp_alloc(type, 0); - auto inst = reinterpret_cast<instance *>(self); - // Allocate the value/holder internals: - inst->allocate_layout(); - - inst->owned = true; - - return self; -} - -/// Instance creation function for all pybind11 types. It only allocates space for the -/// C++ object, but doesn't call the constructor -- an `__init__` function must do that. -extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, PyObject *) { - return make_new_instance(type); -} - -/// An `__init__` function constructs the C++ object. Users should provide at least one -/// of these using `py::init` or directly with `.def(__init__, ...)`. Otherwise, the -/// following default function will be used which simply throws an exception. -extern "C" inline int pybind11_object_init(PyObject *self, PyObject *, PyObject *) { - PyTypeObject *type = Py_TYPE(self); - std::string msg; -#if defined(PYPY_VERSION) - msg += handle((PyObject *) type).attr("__module__").cast<std::string>() + "."; -#endif - msg += type->tp_name; - msg += ": No constructor defined!"; - PyErr_SetString(PyExc_TypeError, msg.c_str()); - return -1; -} - -inline void add_patient(PyObject *nurse, PyObject *patient) { - auto &internals = get_internals(); - auto instance = reinterpret_cast<detail::instance *>(nurse); - instance->has_patients = true; - Py_INCREF(patient); - internals.patients[nurse].push_back(patient); -} - -inline void clear_patients(PyObject *self) { - auto instance = reinterpret_cast<detail::instance *>(self); - auto &internals = get_internals(); - auto pos = internals.patients.find(self); - assert(pos != internals.patients.end()); - // Clearing the patients can cause more Python code to run, which - // can invalidate the iterator. Extract the vector of patients - // from the unordered_map first. - auto patients = std::move(pos->second); - internals.patients.erase(pos); - instance->has_patients = false; - for (PyObject *&patient : patients) - Py_CLEAR(patient); -} - -/// Clears all internal data from the instance and removes it from registered instances in -/// preparation for deallocation. -inline void clear_instance(PyObject *self) { - auto instance = reinterpret_cast<detail::instance *>(self); - - // Deallocate any values/holders, if present: - for (auto &v_h : values_and_holders(instance)) { - if (v_h) { - - // We have to deregister before we call dealloc because, for virtual MI types, we still - // need to be able to get the parent pointers. - if (v_h.instance_registered() && !deregister_instance(instance, v_h.value_ptr(), v_h.type)) - pybind11_fail("pybind11_object_dealloc(): Tried to deallocate unregistered instance!"); - - if (instance->owned || v_h.holder_constructed()) - v_h.type->dealloc(v_h); - } - } - // Deallocate the value/holder layout internals: - instance->deallocate_layout(); - - if (instance->weakrefs) - PyObject_ClearWeakRefs(self); - - PyObject **dict_ptr = _PyObject_GetDictPtr(self); - if (dict_ptr) - Py_CLEAR(*dict_ptr); - - if (instance->has_patients) - clear_patients(self); -} - -/// Instance destructor function for all pybind11 types. It calls `type_info.dealloc` -/// to destroy the C++ object itself, while the rest is Python bookkeeping. -extern "C" inline void pybind11_object_dealloc(PyObject *self) { - clear_instance(self); - - auto type = Py_TYPE(self); - type->tp_free(self); - -#if PY_VERSION_HEX < 0x03080000 - // `type->tp_dealloc != pybind11_object_dealloc` means that we're being called - // as part of a derived type's dealloc, in which case we're not allowed to decref - // the type here. For cross-module compatibility, we shouldn't compare directly - // with `pybind11_object_dealloc`, but with the common one stashed in internals. - auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base; - if (type->tp_dealloc == pybind11_object_type->tp_dealloc) - Py_DECREF(type); -#else - // This was not needed before Python 3.8 (Python issue 35810) - // https://github.com/pybind/pybind11/issues/1946 - Py_DECREF(type); -#endif -} - -/** Create the type which can be used as a common base for all classes. This is - needed in order to satisfy Python's requirements for multiple inheritance. - Return value: New reference. */ -inline PyObject *make_object_base_type(PyTypeObject *metaclass) { - constexpr auto *name = "pybind11_object"; - auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name)); - - /* Danger zone: from now (and until PyType_Ready), make sure to - issue no Python C API calls which could potentially invoke the - garbage collector (the GC will call type_traverse(), which will in - turn find the newly constructed type in an invalid state) */ - auto heap_type = (PyHeapTypeObject *) metaclass->tp_alloc(metaclass, 0); - if (!heap_type) - pybind11_fail("make_object_base_type(): error allocating type!"); - - heap_type->ht_name = name_obj.inc_ref().ptr(); -#ifdef PYBIND11_BUILTIN_QUALNAME - heap_type->ht_qualname = name_obj.inc_ref().ptr(); -#endif - - auto type = &heap_type->ht_type; - type->tp_name = name; - type->tp_base = type_incref(&PyBaseObject_Type); - type->tp_basicsize = static_cast<ssize_t>(sizeof(instance)); - type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; - - type->tp_new = pybind11_object_new; - type->tp_init = pybind11_object_init; - type->tp_dealloc = pybind11_object_dealloc; - - /* Support weak references (needed for the keep_alive feature) */ - type->tp_weaklistoffset = offsetof(instance, weakrefs); - - if (PyType_Ready(type) < 0) - pybind11_fail("PyType_Ready failed in make_object_base_type():" + error_string()); - - setattr((PyObject *) type, "__module__", str("pybind11_builtins")); - PYBIND11_SET_OLDPY_QUALNAME(type, name_obj); - - assert(!PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC)); - return (PyObject *) heap_type; -} - -/// dynamic_attr: Support for `d = instance.__dict__`. -extern "C" inline PyObject *pybind11_get_dict(PyObject *self, void *) { - PyObject *&dict = *_PyObject_GetDictPtr(self); - if (!dict) - dict = PyDict_New(); - Py_XINCREF(dict); - return dict; -} - -/// dynamic_attr: Support for `instance.__dict__ = dict()`. -extern "C" inline int pybind11_set_dict(PyObject *self, PyObject *new_dict, void *) { - if (!PyDict_Check(new_dict)) { - PyErr_Format(PyExc_TypeError, "__dict__ must be set to a dictionary, not a '%.200s'", - Py_TYPE(new_dict)->tp_name); - return -1; - } - PyObject *&dict = *_PyObject_GetDictPtr(self); - Py_INCREF(new_dict); - Py_CLEAR(dict); - dict = new_dict; - return 0; -} - -/// dynamic_attr: Allow the garbage collector to traverse the internal instance `__dict__`. -extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *arg) { - PyObject *&dict = *_PyObject_GetDictPtr(self); - Py_VISIT(dict); - return 0; -} - -/// dynamic_attr: Allow the GC to clear the dictionary. -extern "C" inline int pybind11_clear(PyObject *self) { - PyObject *&dict = *_PyObject_GetDictPtr(self); - Py_CLEAR(dict); - return 0; -} - -/// Give instances of this type a `__dict__` and opt into garbage collection. -inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) { - auto type = &heap_type->ht_type; -#if defined(PYPY_VERSION) - pybind11_fail(std::string(type->tp_name) + ": dynamic attributes are " - "currently not supported in " - "conjunction with PyPy!"); -#endif - type->tp_flags |= Py_TPFLAGS_HAVE_GC; - type->tp_dictoffset = type->tp_basicsize; // place dict at the end - type->tp_basicsize += (ssize_t)sizeof(PyObject *); // and allocate enough space for it - type->tp_traverse = pybind11_traverse; - type->tp_clear = pybind11_clear; - - static PyGetSetDef getset[] = { - {const_cast<char*>("__dict__"), pybind11_get_dict, pybind11_set_dict, nullptr, nullptr}, - {nullptr, nullptr, nullptr, nullptr, nullptr} - }; - type->tp_getset = getset; -} - -/// buffer_protocol: Fill in the view as specified by flags. -extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int flags) { - // Look for a `get_buffer` implementation in this type's info or any bases (following MRO). - type_info *tinfo = nullptr; - for (auto type : reinterpret_borrow<tuple>(Py_TYPE(obj)->tp_mro)) { - tinfo = get_type_info((PyTypeObject *) type.ptr()); - if (tinfo && tinfo->get_buffer) - break; - } - if (view == nullptr || !tinfo || !tinfo->get_buffer) { - if (view) - view->obj = nullptr; - PyErr_SetString(PyExc_BufferError, "pybind11_getbuffer(): Internal error"); - return -1; - } - std::memset(view, 0, sizeof(Py_buffer)); - buffer_info *info = tinfo->get_buffer(obj, tinfo->get_buffer_data); - view->obj = obj; - view->ndim = 1; - view->internal = info; - view->buf = info->ptr; - view->itemsize = info->itemsize; - view->len = view->itemsize; - for (auto s : info->shape) - view->len *= s; - if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) - view->format = const_cast<char *>(info->format.c_str()); - if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) { - view->ndim = (int) info->ndim; - view->strides = &info->strides[0]; - view->shape = &info->shape[0]; - } - Py_INCREF(view->obj); - return 0; -} - -/// buffer_protocol: Release the resources of the buffer. -extern "C" inline void pybind11_releasebuffer(PyObject *, Py_buffer *view) { - delete (buffer_info *) view->internal; -} - -/// Give this type a buffer interface. -inline void enable_buffer_protocol(PyHeapTypeObject *heap_type) { - heap_type->ht_type.tp_as_buffer = &heap_type->as_buffer; -#if PY_MAJOR_VERSION < 3 - heap_type->ht_type.tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER; -#endif - - heap_type->as_buffer.bf_getbuffer = pybind11_getbuffer; - heap_type->as_buffer.bf_releasebuffer = pybind11_releasebuffer; -} - -/** Create a brand new Python type according to the `type_record` specification. - Return value: New reference. */ -inline PyObject* make_new_python_type(const type_record &rec) { - auto name = reinterpret_steal<object>(PYBIND11_FROM_STRING(rec.name)); - - auto qualname = name; - if (rec.scope && !PyModule_Check(rec.scope.ptr()) && hasattr(rec.scope, "__qualname__")) { -#if PY_MAJOR_VERSION >= 3 - qualname = reinterpret_steal<object>( - PyUnicode_FromFormat("%U.%U", rec.scope.attr("__qualname__").ptr(), name.ptr())); -#else - qualname = str(rec.scope.attr("__qualname__").cast<std::string>() + "." + rec.name); -#endif - } - - object module; - if (rec.scope) { - if (hasattr(rec.scope, "__module__")) - module = rec.scope.attr("__module__"); - else if (hasattr(rec.scope, "__name__")) - module = rec.scope.attr("__name__"); - } - - auto full_name = c_str( -#if !defined(PYPY_VERSION) - module ? str(module).cast<std::string>() + "." + rec.name : -#endif - rec.name); - - char *tp_doc = nullptr; - if (rec.doc && options::show_user_defined_docstrings()) { - /* Allocate memory for docstring (using PyObject_MALLOC, since - Python will free this later on) */ - size_t size = strlen(rec.doc) + 1; - tp_doc = (char *) PyObject_MALLOC(size); - memcpy((void *) tp_doc, rec.doc, size); - } - - auto &internals = get_internals(); - auto bases = tuple(rec.bases); - auto base = (bases.size() == 0) ? internals.instance_base - : bases[0].ptr(); - - /* Danger zone: from now (and until PyType_Ready), make sure to - issue no Python C API calls which could potentially invoke the - garbage collector (the GC will call type_traverse(), which will in - turn find the newly constructed type in an invalid state) */ - auto metaclass = rec.metaclass.ptr() ? (PyTypeObject *) rec.metaclass.ptr() - : internals.default_metaclass; - - auto heap_type = (PyHeapTypeObject *) metaclass->tp_alloc(metaclass, 0); - if (!heap_type) - pybind11_fail(std::string(rec.name) + ": Unable to create type object!"); - - heap_type->ht_name = name.release().ptr(); -#ifdef PYBIND11_BUILTIN_QUALNAME - heap_type->ht_qualname = qualname.inc_ref().ptr(); -#endif - - auto type = &heap_type->ht_type; - type->tp_name = full_name; - type->tp_doc = tp_doc; - type->tp_base = type_incref((PyTypeObject *)base); - type->tp_basicsize = static_cast<ssize_t>(sizeof(instance)); - if (bases.size() > 0) - type->tp_bases = bases.release().ptr(); - - /* Don't inherit base __init__ */ - type->tp_init = pybind11_object_init; - - /* Supported protocols */ - type->tp_as_number = &heap_type->as_number; - type->tp_as_sequence = &heap_type->as_sequence; - type->tp_as_mapping = &heap_type->as_mapping; -#if PY_VERSION_HEX >= 0x03050000 - type->tp_as_async = &heap_type->as_async; -#endif - - /* Flags */ - type->tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; -#if PY_MAJOR_VERSION < 3 - type->tp_flags |= Py_TPFLAGS_CHECKTYPES; -#endif - - if (rec.dynamic_attr) - enable_dynamic_attributes(heap_type); - - if (rec.buffer_protocol) - enable_buffer_protocol(heap_type); - - if (PyType_Ready(type) < 0) - pybind11_fail(std::string(rec.name) + ": PyType_Ready failed (" + error_string() + ")!"); - - assert(rec.dynamic_attr ? PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC) - : !PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC)); - - /* Register type with the parent scope */ - if (rec.scope) - setattr(rec.scope, rec.name, (PyObject *) type); - else - Py_INCREF(type); // Keep it alive forever (reference leak) - - if (module) // Needed by pydoc - setattr((PyObject *) type, "__module__", module); - - PYBIND11_SET_OLDPY_QUALNAME(type, qualname); - - return (PyObject *) type; -} - -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/detail/common.h b/external/pybind11/include/pybind11/detail/common.h deleted file mode 100644 index bb1affce..00000000 --- a/external/pybind11/include/pybind11/detail/common.h +++ /dev/null @@ -1,808 +0,0 @@ -/* - pybind11/detail/common.h -- Basic macros - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#if !defined(NAMESPACE_BEGIN) -# define NAMESPACE_BEGIN(name) namespace name { -#endif -#if !defined(NAMESPACE_END) -# define NAMESPACE_END(name) } -#endif - -// Robust support for some features and loading modules compiled against different pybind versions -// requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute on -// the main `pybind11` namespace. -#if !defined(PYBIND11_NAMESPACE) -# ifdef __GNUG__ -# define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden"))) -# else -# define PYBIND11_NAMESPACE pybind11 -# endif -#endif - -#if !(defined(_MSC_VER) && __cplusplus == 199711L) && !defined(__INTEL_COMPILER) -# if __cplusplus >= 201402L -# define PYBIND11_CPP14 -# if __cplusplus >= 201703L -# define PYBIND11_CPP17 -# endif -# endif -#elif defined(_MSC_VER) && __cplusplus == 199711L -// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented) -// Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer -# if _MSVC_LANG >= 201402L -# define PYBIND11_CPP14 -# if _MSVC_LANG > 201402L && _MSC_VER >= 1910 -# define PYBIND11_CPP17 -# endif -# endif -#endif - -// Compiler version assertions -#if defined(__INTEL_COMPILER) -# if __INTEL_COMPILER < 1700 -# error pybind11 requires Intel C++ compiler v17 or newer -# endif -#elif defined(__clang__) && !defined(__apple_build_version__) -# if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3) -# error pybind11 requires clang 3.3 or newer -# endif -#elif defined(__clang__) -// Apple changes clang version macros to its Xcode version; the first Xcode release based on -// (upstream) clang 3.3 was Xcode 5: -# if __clang_major__ < 5 -# error pybind11 requires Xcode/clang 5.0 or newer -# endif -#elif defined(__GNUG__) -# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8) -# error pybind11 requires gcc 4.8 or newer -# endif -#elif defined(_MSC_VER) -// Pybind hits various compiler bugs in 2015u2 and earlier, and also makes use of some stl features -// (e.g. std::negation) added in 2015u3: -# if _MSC_FULL_VER < 190024210 -# error pybind11 requires MSVC 2015 update 3 or newer -# endif -#endif - -#if !defined(PYBIND11_EXPORT) -# if defined(WIN32) || defined(_WIN32) -# define PYBIND11_EXPORT __declspec(dllexport) -# else -# define PYBIND11_EXPORT __attribute__ ((visibility("default"))) -# endif -#endif - -#if defined(_MSC_VER) -# define PYBIND11_NOINLINE __declspec(noinline) -#else -# define PYBIND11_NOINLINE __attribute__ ((noinline)) -#endif - -#if defined(PYBIND11_CPP14) -# define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]] -#else -# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason))) -#endif - -#define PYBIND11_VERSION_MAJOR 2 -#define PYBIND11_VERSION_MINOR 4 -#define PYBIND11_VERSION_PATCH dev4 - -/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode -#if defined(_MSC_VER) -# if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4) -# define HAVE_ROUND 1 -# endif -# pragma warning(push) -# pragma warning(disable: 4510 4610 4512 4005) -# if defined(_DEBUG) -# define PYBIND11_DEBUG_MARKER -# undef _DEBUG -# endif -#endif - -#include <Python.h> -#include <frameobject.h> -#include <pythread.h> - -#if defined(isalnum) -# undef isalnum -# undef isalpha -# undef islower -# undef isspace -# undef isupper -# undef tolower -# undef toupper -#endif - -#if defined(_MSC_VER) -# if defined(PYBIND11_DEBUG_MARKER) -# define _DEBUG -# undef PYBIND11_DEBUG_MARKER -# endif -# pragma warning(pop) -#endif - -#include <cstddef> -#include <cstring> -#include <forward_list> -#include <vector> -#include <string> -#include <stdexcept> -#include <unordered_set> -#include <unordered_map> -#include <memory> -#include <typeindex> -#include <type_traits> - -#if PY_MAJOR_VERSION >= 3 /// Compatibility macros for various Python versions -#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr) -#define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check -#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION -#define PYBIND11_BYTES_CHECK PyBytes_Check -#define PYBIND11_BYTES_FROM_STRING PyBytes_FromString -#define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize -#define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize -#define PYBIND11_BYTES_AS_STRING PyBytes_AsString -#define PYBIND11_BYTES_SIZE PyBytes_Size -#define PYBIND11_LONG_CHECK(o) PyLong_Check(o) -#define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o) -#define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) o) -#define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) o) -#define PYBIND11_BYTES_NAME "bytes" -#define PYBIND11_STRING_NAME "str" -#define PYBIND11_SLICE_OBJECT PyObject -#define PYBIND11_FROM_STRING PyUnicode_FromString -#define PYBIND11_STR_TYPE ::pybind11::str -#define PYBIND11_BOOL_ATTR "__bool__" -#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool) -// Providing a separate declaration to make Clang's -Wmissing-prototypes happy -#define PYBIND11_PLUGIN_IMPL(name) \ - extern "C" PYBIND11_EXPORT PyObject *PyInit_##name(); \ - extern "C" PYBIND11_EXPORT PyObject *PyInit_##name() - -#else -#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyMethod_New(ptr, nullptr, class_) -#define PYBIND11_INSTANCE_METHOD_CHECK PyMethod_Check -#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyMethod_GET_FUNCTION -#define PYBIND11_BYTES_CHECK PyString_Check -#define PYBIND11_BYTES_FROM_STRING PyString_FromString -#define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyString_FromStringAndSize -#define PYBIND11_BYTES_AS_STRING_AND_SIZE PyString_AsStringAndSize -#define PYBIND11_BYTES_AS_STRING PyString_AsString -#define PYBIND11_BYTES_SIZE PyString_Size -#define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o)) -#define PYBIND11_LONG_AS_LONGLONG(o) (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o)) -#define PYBIND11_LONG_FROM_SIGNED(o) PyInt_FromSsize_t((ssize_t) o) // Returns long if needed. -#define PYBIND11_LONG_FROM_UNSIGNED(o) PyInt_FromSize_t((size_t) o) // Returns long if needed. -#define PYBIND11_BYTES_NAME "str" -#define PYBIND11_STRING_NAME "unicode" -#define PYBIND11_SLICE_OBJECT PySliceObject -#define PYBIND11_FROM_STRING PyString_FromString -#define PYBIND11_STR_TYPE ::pybind11::bytes -#define PYBIND11_BOOL_ATTR "__nonzero__" -#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_nonzero) -// Providing a separate PyInit decl to make Clang's -Wmissing-prototypes happy -#define PYBIND11_PLUGIN_IMPL(name) \ - static PyObject *pybind11_init_wrapper(); \ - extern "C" PYBIND11_EXPORT void init##name(); \ - extern "C" PYBIND11_EXPORT void init##name() { \ - (void)pybind11_init_wrapper(); \ - } \ - PyObject *pybind11_init_wrapper() -#endif - -#if PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03050200 -extern "C" { - struct _Py_atomic_address { void *value; }; - PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current; -} -#endif - -#define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code -#define PYBIND11_STRINGIFY(x) #x -#define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x) -#define PYBIND11_CONCAT(first, second) first##second - -#define PYBIND11_CHECK_PYTHON_VERSION \ - { \ - const char *compiled_ver = PYBIND11_TOSTRING(PY_MAJOR_VERSION) \ - "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \ - const char *runtime_ver = Py_GetVersion(); \ - size_t len = std::strlen(compiled_ver); \ - if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \ - || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \ - PyErr_Format(PyExc_ImportError, \ - "Python version mismatch: module was compiled for Python %s, " \ - "but the interpreter version is incompatible: %s.", \ - compiled_ver, runtime_ver); \ - return nullptr; \ - } \ - } - -#define PYBIND11_CATCH_INIT_EXCEPTIONS \ - catch (pybind11::error_already_set &e) { \ - PyErr_SetString(PyExc_ImportError, e.what()); \ - return nullptr; \ - } catch (const std::exception &e) { \ - PyErr_SetString(PyExc_ImportError, e.what()); \ - return nullptr; \ - } \ - -/** \rst - ***Deprecated in favor of PYBIND11_MODULE*** - - This macro creates the entry point that will be invoked when the Python interpreter - imports a plugin library. Please create a `module` in the function body and return - the pointer to its underlying Python object at the end. - - .. code-block:: cpp - - PYBIND11_PLUGIN(example) { - pybind11::module m("example", "pybind11 example plugin"); - /// Set up bindings here - return m.ptr(); - } -\endrst */ -#define PYBIND11_PLUGIN(name) \ - PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \ - static PyObject *pybind11_init(); \ - PYBIND11_PLUGIN_IMPL(name) { \ - PYBIND11_CHECK_PYTHON_VERSION \ - try { \ - return pybind11_init(); \ - } PYBIND11_CATCH_INIT_EXCEPTIONS \ - } \ - PyObject *pybind11_init() - -/** \rst - This macro creates the entry point that will be invoked when the Python interpreter - imports an extension module. The module name is given as the fist argument and it - should not be in quotes. The second macro argument defines a variable of type - `py::module` which can be used to initialize the module. - - .. code-block:: cpp - - PYBIND11_MODULE(example, m) { - m.doc() = "pybind11 example module"; - - // Add bindings here - m.def("foo", []() { - return "Hello, World!"; - }); - } -\endrst */ -#define PYBIND11_MODULE(name, variable) \ - static void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &); \ - PYBIND11_PLUGIN_IMPL(name) { \ - PYBIND11_CHECK_PYTHON_VERSION \ - auto m = pybind11::module(PYBIND11_TOSTRING(name)); \ - try { \ - PYBIND11_CONCAT(pybind11_init_, name)(m); \ - return m.ptr(); \ - } PYBIND11_CATCH_INIT_EXCEPTIONS \ - } \ - void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable) - - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -using ssize_t = Py_ssize_t; -using size_t = std::size_t; - -/// Approach used to cast a previously unknown C++ instance into a Python object -enum class return_value_policy : uint8_t { - /** This is the default return value policy, which falls back to the policy - return_value_policy::take_ownership when the return value is a pointer. - Otherwise, it uses return_value::move or return_value::copy for rvalue - and lvalue references, respectively. See below for a description of what - all of these different policies do. */ - automatic = 0, - - /** As above, but use policy return_value_policy::reference when the return - value is a pointer. This is the default conversion policy for function - arguments when calling Python functions manually from C++ code (i.e. via - handle::operator()). You probably won't need to use this. */ - automatic_reference, - - /** Reference an existing object (i.e. do not create a new copy) and take - ownership. Python will call the destructor and delete operator when the - object’s reference count reaches zero. Undefined behavior ensues when - the C++ side does the same.. */ - take_ownership, - - /** Create a new copy of the returned object, which will be owned by - Python. This policy is comparably safe because the lifetimes of the two - instances are decoupled. */ - copy, - - /** Use std::move to move the return value contents into a new instance - that will be owned by Python. This policy is comparably safe because the - lifetimes of the two instances (move source and destination) are - decoupled. */ - move, - - /** Reference an existing object, but do not take ownership. The C++ side - is responsible for managing the object’s lifetime and deallocating it - when it is no longer used. Warning: undefined behavior will ensue when - the C++ side deletes an object that is still referenced and used by - Python. */ - reference, - - /** This policy only applies to methods and properties. It references the - object without taking ownership similar to the above - return_value_policy::reference policy. In contrast to that policy, the - function or property’s implicit this argument (called the parent) is - considered to be the the owner of the return value (the child). - pybind11 then couples the lifetime of the parent to the child via a - reference relationship that ensures that the parent cannot be garbage - collected while Python is still using the child. More advanced - variations of this scheme are also possible using combinations of - return_value_policy::reference and the keep_alive call policy */ - reference_internal -}; - -NAMESPACE_BEGIN(detail) - -inline static constexpr int log2(size_t n, int k = 0) { return (n <= 1) ? k : log2(n >> 1, k + 1); } - -// Returns the size as a multiple of sizeof(void *), rounded up. -inline static constexpr size_t size_in_ptrs(size_t s) { return 1 + ((s - 1) >> log2(sizeof(void *))); } - -/** - * The space to allocate for simple layout instance holders (see below) in multiple of the size of - * a pointer (e.g. 2 means 16 bytes on 64-bit architectures). The default is the minimum required - * to holder either a std::unique_ptr or std::shared_ptr (which is almost always - * sizeof(std::shared_ptr<T>)). - */ -constexpr size_t instance_simple_holder_in_ptrs() { - static_assert(sizeof(std::shared_ptr<int>) >= sizeof(std::unique_ptr<int>), - "pybind assumes std::shared_ptrs are at least as big as std::unique_ptrs"); - return size_in_ptrs(sizeof(std::shared_ptr<int>)); -} - -// Forward declarations -struct type_info; -struct value_and_holder; - -struct nonsimple_values_and_holders { - void **values_and_holders; - uint8_t *status; -}; - -/// The 'instance' type which needs to be standard layout (need to be able to use 'offsetof') -struct instance { - PyObject_HEAD - /// Storage for pointers and holder; see simple_layout, below, for a description - union { - void *simple_value_holder[1 + instance_simple_holder_in_ptrs()]; - nonsimple_values_and_holders nonsimple; - }; - /// Weak references - PyObject *weakrefs; - /// If true, the pointer is owned which means we're free to manage it with a holder. - bool owned : 1; - /** - * An instance has two possible value/holder layouts. - * - * Simple layout (when this flag is true), means the `simple_value_holder` is set with a pointer - * and the holder object governing that pointer, i.e. [val1*][holder]. This layout is applied - * whenever there is no python-side multiple inheritance of bound C++ types *and* the type's - * holder will fit in the default space (which is large enough to hold either a std::unique_ptr - * or std::shared_ptr). - * - * Non-simple layout applies when using custom holders that require more space than `shared_ptr` - * (which is typically the size of two pointers), or when multiple inheritance is used on the - * python side. Non-simple layout allocates the required amount of memory to have multiple - * bound C++ classes as parents. Under this layout, `nonsimple.values_and_holders` is set to a - * pointer to allocated space of the required space to hold a sequence of value pointers and - * holders followed `status`, a set of bit flags (1 byte each), i.e. - * [val1*][holder1][val2*][holder2]...[bb...] where each [block] is rounded up to a multiple of - * `sizeof(void *)`. `nonsimple.status` is, for convenience, a pointer to the - * beginning of the [bb...] block (but not independently allocated). - * - * Status bits indicate whether the associated holder is constructed (& - * status_holder_constructed) and whether the value pointer is registered (& - * status_instance_registered) in `registered_instances`. - */ - bool simple_layout : 1; - /// For simple layout, tracks whether the holder has been constructed - bool simple_holder_constructed : 1; - /// For simple layout, tracks whether the instance is registered in `registered_instances` - bool simple_instance_registered : 1; - /// If true, get_internals().patients has an entry for this object - bool has_patients : 1; - - /// Initializes all of the above type/values/holders data (but not the instance values themselves) - void allocate_layout(); - - /// Destroys/deallocates all of the above - void deallocate_layout(); - - /// Returns the value_and_holder wrapper for the given type (or the first, if `find_type` - /// omitted). Returns a default-constructed (with `.inst = nullptr`) object on failure if - /// `throw_if_missing` is false. - value_and_holder get_value_and_holder(const type_info *find_type = nullptr, bool throw_if_missing = true); - - /// Bit values for the non-simple status flags - static constexpr uint8_t status_holder_constructed = 1; - static constexpr uint8_t status_instance_registered = 2; -}; - -static_assert(std::is_standard_layout<instance>::value, "Internal error: `pybind11::detail::instance` is not standard layout!"); - -/// from __cpp_future__ import (convenient aliases from C++14/17) -#if defined(PYBIND11_CPP14) && (!defined(_MSC_VER) || _MSC_VER >= 1910) -using std::enable_if_t; -using std::conditional_t; -using std::remove_cv_t; -using std::remove_reference_t; -#else -template <bool B, typename T = void> using enable_if_t = typename std::enable_if<B, T>::type; -template <bool B, typename T, typename F> using conditional_t = typename std::conditional<B, T, F>::type; -template <typename T> using remove_cv_t = typename std::remove_cv<T>::type; -template <typename T> using remove_reference_t = typename std::remove_reference<T>::type; -#endif - -/// Index sequences -#if defined(PYBIND11_CPP14) -using std::index_sequence; -using std::make_index_sequence; -#else -template<size_t ...> struct index_sequence { }; -template<size_t N, size_t ...S> struct make_index_sequence_impl : make_index_sequence_impl <N - 1, N - 1, S...> { }; -template<size_t ...S> struct make_index_sequence_impl <0, S...> { typedef index_sequence<S...> type; }; -template<size_t N> using make_index_sequence = typename make_index_sequence_impl<N>::type; -#endif - -/// Make an index sequence of the indices of true arguments -template <typename ISeq, size_t, bool...> struct select_indices_impl { using type = ISeq; }; -template <size_t... IPrev, size_t I, bool B, bool... Bs> struct select_indices_impl<index_sequence<IPrev...>, I, B, Bs...> - : select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>, I + 1, Bs...> {}; -template <bool... Bs> using select_indices = typename select_indices_impl<index_sequence<>, 0, Bs...>::type; - -/// Backports of std::bool_constant and std::negation to accommodate older compilers -template <bool B> using bool_constant = std::integral_constant<bool, B>; -template <typename T> struct negation : bool_constant<!T::value> { }; - -template <typename...> struct void_t_impl { using type = void; }; -template <typename... Ts> using void_t = typename void_t_impl<Ts...>::type; - -/// Compile-time all/any/none of that check the boolean value of all template types -#if defined(__cpp_fold_expressions) && !(defined(_MSC_VER) && (_MSC_VER < 1916)) -template <class... Ts> using all_of = bool_constant<(Ts::value && ...)>; -template <class... Ts> using any_of = bool_constant<(Ts::value || ...)>; -#elif !defined(_MSC_VER) -template <bool...> struct bools {}; -template <class... Ts> using all_of = std::is_same< - bools<Ts::value..., true>, - bools<true, Ts::value...>>; -template <class... Ts> using any_of = negation<all_of<negation<Ts>...>>; -#else -// MSVC has trouble with the above, but supports std::conjunction, which we can use instead (albeit -// at a slight loss of compilation efficiency). -template <class... Ts> using all_of = std::conjunction<Ts...>; -template <class... Ts> using any_of = std::disjunction<Ts...>; -#endif -template <class... Ts> using none_of = negation<any_of<Ts...>>; - -template <class T, template<class> class... Predicates> using satisfies_all_of = all_of<Predicates<T>...>; -template <class T, template<class> class... Predicates> using satisfies_any_of = any_of<Predicates<T>...>; -template <class T, template<class> class... Predicates> using satisfies_none_of = none_of<Predicates<T>...>; - -/// Strip the class from a method type -template <typename T> struct remove_class { }; -template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...)> { typedef R type(A...); }; -template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...) const> { typedef R type(A...); }; - -/// Helper template to strip away type modifiers -template <typename T> struct intrinsic_type { typedef T type; }; -template <typename T> struct intrinsic_type<const T> { typedef typename intrinsic_type<T>::type type; }; -template <typename T> struct intrinsic_type<T*> { typedef typename intrinsic_type<T>::type type; }; -template <typename T> struct intrinsic_type<T&> { typedef typename intrinsic_type<T>::type type; }; -template <typename T> struct intrinsic_type<T&&> { typedef typename intrinsic_type<T>::type type; }; -template <typename T, size_t N> struct intrinsic_type<const T[N]> { typedef typename intrinsic_type<T>::type type; }; -template <typename T, size_t N> struct intrinsic_type<T[N]> { typedef typename intrinsic_type<T>::type type; }; -template <typename T> using intrinsic_t = typename intrinsic_type<T>::type; - -/// Helper type to replace 'void' in some expressions -struct void_type { }; - -/// Helper template which holds a list of types -template <typename...> struct type_list { }; - -/// Compile-time integer sum -#ifdef __cpp_fold_expressions -template <typename... Ts> constexpr size_t constexpr_sum(Ts... ns) { return (0 + ... + size_t{ns}); } -#else -constexpr size_t constexpr_sum() { return 0; } -template <typename T, typename... Ts> -constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); } -#endif - -NAMESPACE_BEGIN(constexpr_impl) -/// Implementation details for constexpr functions -constexpr int first(int i) { return i; } -template <typename T, typename... Ts> -constexpr int first(int i, T v, Ts... vs) { return v ? i : first(i + 1, vs...); } - -constexpr int last(int /*i*/, int result) { return result; } -template <typename T, typename... Ts> -constexpr int last(int i, int result, T v, Ts... vs) { return last(i + 1, v ? i : result, vs...); } -NAMESPACE_END(constexpr_impl) - -/// Return the index of the first type in Ts which satisfies Predicate<T>. Returns sizeof...(Ts) if -/// none match. -template <template<typename> class Predicate, typename... Ts> -constexpr int constexpr_first() { return constexpr_impl::first(0, Predicate<Ts>::value...); } - -/// Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match. -template <template<typename> class Predicate, typename... Ts> -constexpr int constexpr_last() { return constexpr_impl::last(0, -1, Predicate<Ts>::value...); } - -/// Return the Nth element from the parameter pack -template <size_t N, typename T, typename... Ts> -struct pack_element { using type = typename pack_element<N - 1, Ts...>::type; }; -template <typename T, typename... Ts> -struct pack_element<0, T, Ts...> { using type = T; }; - -/// Return the one and only type which matches the predicate, or Default if none match. -/// If more than one type matches the predicate, fail at compile-time. -template <template<typename> class Predicate, typename Default, typename... Ts> -struct exactly_one { - static constexpr auto found = constexpr_sum(Predicate<Ts>::value...); - static_assert(found <= 1, "Found more than one type matching the predicate"); - - static constexpr auto index = found ? constexpr_first<Predicate, Ts...>() : 0; - using type = conditional_t<found, typename pack_element<index, Ts...>::type, Default>; -}; -template <template<typename> class P, typename Default> -struct exactly_one<P, Default> { using type = Default; }; - -template <template<typename> class Predicate, typename Default, typename... Ts> -using exactly_one_t = typename exactly_one<Predicate, Default, Ts...>::type; - -/// Defer the evaluation of type T until types Us are instantiated -template <typename T, typename... /*Us*/> struct deferred_type { using type = T; }; -template <typename T, typename... Us> using deferred_t = typename deferred_type<T, Us...>::type; - -/// Like is_base_of, but requires a strict base (i.e. `is_strict_base_of<T, T>::value == false`, -/// unlike `std::is_base_of`) -template <typename Base, typename Derived> using is_strict_base_of = bool_constant< - std::is_base_of<Base, Derived>::value && !std::is_same<Base, Derived>::value>; - -/// Like is_base_of, but also requires that the base type is accessible (i.e. that a Derived pointer -/// can be converted to a Base pointer) -template <typename Base, typename Derived> using is_accessible_base_of = bool_constant< - std::is_base_of<Base, Derived>::value && std::is_convertible<Derived *, Base *>::value>; - -template <template<typename...> class Base> -struct is_template_base_of_impl { - template <typename... Us> static std::true_type check(Base<Us...> *); - static std::false_type check(...); -}; - -/// Check if a template is the base of a type. For example: -/// `is_template_base_of<Base, T>` is true if `struct T : Base<U> {}` where U can be anything -template <template<typename...> class Base, typename T> -#if !defined(_MSC_VER) -using is_template_base_of = decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T>*)nullptr)); -#else // MSVC2015 has trouble with decltype in template aliases -struct is_template_base_of : decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T>*)nullptr)) { }; -#endif - -/// Check if T is an instantiation of the template `Class`. For example: -/// `is_instantiation<shared_ptr, T>` is true if `T == shared_ptr<U>` where U can be anything. -template <template<typename...> class Class, typename T> -struct is_instantiation : std::false_type { }; -template <template<typename...> class Class, typename... Us> -struct is_instantiation<Class, Class<Us...>> : std::true_type { }; - -/// Check if T is std::shared_ptr<U> where U can be anything -template <typename T> using is_shared_ptr = is_instantiation<std::shared_ptr, T>; - -/// Check if T looks like an input iterator -template <typename T, typename = void> struct is_input_iterator : std::false_type {}; -template <typename T> -struct is_input_iterator<T, void_t<decltype(*std::declval<T &>()), decltype(++std::declval<T &>())>> - : std::true_type {}; - -template <typename T> using is_function_pointer = bool_constant< - std::is_pointer<T>::value && std::is_function<typename std::remove_pointer<T>::type>::value>; - -template <typename F> struct strip_function_object { - using type = typename remove_class<decltype(&F::operator())>::type; -}; - -// Extracts the function signature from a function, function pointer or lambda. -template <typename Function, typename F = remove_reference_t<Function>> -using function_signature_t = conditional_t< - std::is_function<F>::value, - F, - typename conditional_t< - std::is_pointer<F>::value || std::is_member_pointer<F>::value, - std::remove_pointer<F>, - strip_function_object<F> - >::type ->; - -/// Returns true if the type looks like a lambda: that is, isn't a function, pointer or member -/// pointer. Note that this can catch all sorts of other things, too; this is intended to be used -/// in a place where passing a lambda makes sense. -template <typename T> using is_lambda = satisfies_none_of<remove_reference_t<T>, - std::is_function, std::is_pointer, std::is_member_pointer>; - -/// Ignore that a variable is unused in compiler warnings -inline void ignore_unused(const int *) { } - -/// Apply a function over each element of a parameter pack -#ifdef __cpp_fold_expressions -#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...) -#else -using expand_side_effects = bool[]; -#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false } -#endif - -NAMESPACE_END(detail) - -/// C++ bindings of builtin Python exceptions -class builtin_exception : public std::runtime_error { -public: - using std::runtime_error::runtime_error; - /// Set the error using the Python C API - virtual void set_error() const = 0; -}; - -#define PYBIND11_RUNTIME_EXCEPTION(name, type) \ - class name : public builtin_exception { public: \ - using builtin_exception::builtin_exception; \ - name() : name("") { } \ - void set_error() const override { PyErr_SetString(type, what()); } \ - }; - -PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration) -PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError) -PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError) -PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError) -PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError) -PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError) -PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or handle::call fail due to a type casting error -PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally - -[[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const char *reason) { throw std::runtime_error(reason); } -[[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const std::string &reason) { throw std::runtime_error(reason); } - -template <typename T, typename SFINAE = void> struct format_descriptor { }; - -NAMESPACE_BEGIN(detail) -// Returns the index of the given type in the type char array below, and in the list in numpy.h -// The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double; -// complex float,double,long double. Note that the long double types only participate when long -// double is actually longer than double (it isn't under MSVC). -// NB: not only the string below but also complex.h and numpy.h rely on this order. -template <typename T, typename SFINAE = void> struct is_fmt_numeric { static constexpr bool value = false; }; -template <typename T> struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>::value>> { - static constexpr bool value = true; - static constexpr int index = std::is_same<T, bool>::value ? 0 : 1 + ( - std::is_integral<T>::value ? detail::log2(sizeof(T))*2 + std::is_unsigned<T>::value : 8 + ( - std::is_same<T, double>::value ? 1 : std::is_same<T, long double>::value ? 2 : 0)); -}; -NAMESPACE_END(detail) - -template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> { - static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index]; - static constexpr const char value[2] = { c, '\0' }; - static std::string format() { return std::string(1, c); } -}; - -#if !defined(PYBIND11_CPP17) - -template <typename T> constexpr const char format_descriptor< - T, detail::enable_if_t<std::is_arithmetic<T>::value>>::value[2]; - -#endif - -/// RAII wrapper that temporarily clears any Python error state -struct error_scope { - PyObject *type, *value, *trace; - error_scope() { PyErr_Fetch(&type, &value, &trace); } - ~error_scope() { PyErr_Restore(type, value, trace); } -}; - -/// Dummy destructor wrapper that can be used to expose classes with a private destructor -struct nodelete { template <typename T> void operator()(T*) { } }; - -NAMESPACE_BEGIN(detail) -template <typename... Args> -struct overload_cast_impl { - constexpr overload_cast_impl() {} // MSVC 2015 needs this - - template <typename Return> - constexpr auto operator()(Return (*pf)(Args...)) const noexcept - -> decltype(pf) { return pf; } - - template <typename Return, typename Class> - constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept - -> decltype(pmf) { return pmf; } - - template <typename Return, typename Class> - constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept - -> decltype(pmf) { return pmf; } -}; -NAMESPACE_END(detail) - -// overload_cast requires variable templates: C++14 -#if defined(PYBIND11_CPP14) -#define PYBIND11_OVERLOAD_CAST 1 -/// Syntax sugar for resolving overloaded function pointers: -/// - regular: static_cast<Return (Class::*)(Arg0, Arg1, Arg2)>(&Class::func) -/// - sweet: overload_cast<Arg0, Arg1, Arg2>(&Class::func) -template <typename... Args> -static constexpr detail::overload_cast_impl<Args...> overload_cast = {}; -// MSVC 2015 only accepts this particular initialization syntax for this variable template. -#endif - -/// Const member function selector for overload_cast -/// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func) -/// - sweet: overload_cast<Arg>(&Class::func, const_) -static constexpr auto const_ = std::true_type{}; - -#if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails: -template <typename... Args> struct overload_cast { - static_assert(detail::deferred_t<std::false_type, Args...>::value, - "pybind11::overload_cast<...> requires compiling in C++14 mode"); -}; -#endif // overload_cast - -NAMESPACE_BEGIN(detail) - -// Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from -// any standard container (or C-style array) supporting std::begin/std::end, any singleton -// arithmetic type (if T is arithmetic), or explicitly constructible from an iterator pair. -template <typename T> -class any_container { - std::vector<T> v; -public: - any_container() = default; - - // Can construct from a pair of iterators - template <typename It, typename = enable_if_t<is_input_iterator<It>::value>> - any_container(It first, It last) : v(first, last) { } - - // Implicit conversion constructor from any arbitrary container type with values convertible to T - template <typename Container, typename = enable_if_t<std::is_convertible<decltype(*std::begin(std::declval<const Container &>())), T>::value>> - any_container(const Container &c) : any_container(std::begin(c), std::end(c)) { } - - // initializer_list's aren't deducible, so don't get matched by the above template; we need this - // to explicitly allow implicit conversion from one: - template <typename TIn, typename = enable_if_t<std::is_convertible<TIn, T>::value>> - any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) { } - - // Avoid copying if given an rvalue vector of the correct type. - any_container(std::vector<T> &&v) : v(std::move(v)) { } - - // Moves the vector out of an rvalue any_container - operator std::vector<T> &&() && { return std::move(v); } - - // Dereferencing obtains a reference to the underlying vector - std::vector<T> &operator*() { return v; } - const std::vector<T> &operator*() const { return v; } - - // -> lets you call methods on the underlying vector - std::vector<T> *operator->() { return &v; } - const std::vector<T> *operator->() const { return &v; } -}; - -NAMESPACE_END(detail) - - - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/detail/descr.h b/external/pybind11/include/pybind11/detail/descr.h deleted file mode 100644 index 8d404e53..00000000 --- a/external/pybind11/include/pybind11/detail/descr.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - pybind11/detail/descr.h: Helper type for concatenating type signatures at compile time - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "common.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -#if !defined(_MSC_VER) -# define PYBIND11_DESCR_CONSTEXPR static constexpr -#else -# define PYBIND11_DESCR_CONSTEXPR const -#endif - -/* Concatenate type signatures at compile time */ -template <size_t N, typename... Ts> -struct descr { - char text[N + 1]; - - constexpr descr() : text{'\0'} { } - constexpr descr(char const (&s)[N+1]) : descr(s, make_index_sequence<N>()) { } - - template <size_t... Is> - constexpr descr(char const (&s)[N+1], index_sequence<Is...>) : text{s[Is]..., '\0'} { } - - template <typename... Chars> - constexpr descr(char c, Chars... cs) : text{c, static_cast<char>(cs)..., '\0'} { } - - static constexpr std::array<const std::type_info *, sizeof...(Ts) + 1> types() { - return {{&typeid(Ts)..., nullptr}}; - } -}; - -template <size_t N1, size_t N2, typename... Ts1, typename... Ts2, size_t... Is1, size_t... Is2> -constexpr descr<N1 + N2, Ts1..., Ts2...> plus_impl(const descr<N1, Ts1...> &a, const descr<N2, Ts2...> &b, - index_sequence<Is1...>, index_sequence<Is2...>) { - return {a.text[Is1]..., b.text[Is2]...}; -} - -template <size_t N1, size_t N2, typename... Ts1, typename... Ts2> -constexpr descr<N1 + N2, Ts1..., Ts2...> operator+(const descr<N1, Ts1...> &a, const descr<N2, Ts2...> &b) { - return plus_impl(a, b, make_index_sequence<N1>(), make_index_sequence<N2>()); -} - -template <size_t N> -constexpr descr<N - 1> _(char const(&text)[N]) { return descr<N - 1>(text); } -constexpr descr<0> _(char const(&)[1]) { return {}; } - -template <size_t Rem, size_t... Digits> struct int_to_str : int_to_str<Rem/10, Rem%10, Digits...> { }; -template <size_t...Digits> struct int_to_str<0, Digits...> { - static constexpr auto digits = descr<sizeof...(Digits)>(('0' + Digits)...); -}; - -// Ternary description (like std::conditional) -template <bool B, size_t N1, size_t N2> -constexpr enable_if_t<B, descr<N1 - 1>> _(char const(&text1)[N1], char const(&)[N2]) { - return _(text1); -} -template <bool B, size_t N1, size_t N2> -constexpr enable_if_t<!B, descr<N2 - 1>> _(char const(&)[N1], char const(&text2)[N2]) { - return _(text2); -} - -template <bool B, typename T1, typename T2> -constexpr enable_if_t<B, T1> _(const T1 &d, const T2 &) { return d; } -template <bool B, typename T1, typename T2> -constexpr enable_if_t<!B, T2> _(const T1 &, const T2 &d) { return d; } - -template <size_t Size> auto constexpr _() -> decltype(int_to_str<Size / 10, Size % 10>::digits) { - return int_to_str<Size / 10, Size % 10>::digits; -} - -template <typename Type> constexpr descr<1, Type> _() { return {'%'}; } - -constexpr descr<0> concat() { return {}; } - -template <size_t N, typename... Ts> -constexpr descr<N, Ts...> concat(const descr<N, Ts...> &descr) { return descr; } - -template <size_t N, typename... Ts, typename... Args> -constexpr auto concat(const descr<N, Ts...> &d, const Args &...args) - -> decltype(std::declval<descr<N + 2, Ts...>>() + concat(args...)) { - return d + _(", ") + concat(args...); -} - -template <size_t N, typename... Ts> -constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) { - return _("{") + descr + _("}"); -} - -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/detail/init.h b/external/pybind11/include/pybind11/detail/init.h deleted file mode 100644 index acfe00bd..00000000 --- a/external/pybind11/include/pybind11/detail/init.h +++ /dev/null @@ -1,335 +0,0 @@ -/* - pybind11/detail/init.h: init factory function implementation and support code. - - Copyright (c) 2017 Jason Rhinelander <jason@imaginary.ca> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "class.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -template <> -class type_caster<value_and_holder> { -public: - bool load(handle h, bool) { - value = reinterpret_cast<value_and_holder *>(h.ptr()); - return true; - } - - template <typename> using cast_op_type = value_and_holder &; - operator value_and_holder &() { return *value; } - static constexpr auto name = _<value_and_holder>(); - -private: - value_and_holder *value = nullptr; -}; - -NAMESPACE_BEGIN(initimpl) - -inline void no_nullptr(void *ptr) { - if (!ptr) throw type_error("pybind11::init(): factory function returned nullptr"); -} - -// Implementing functions for all forms of py::init<...> and py::init(...) -template <typename Class> using Cpp = typename Class::type; -template <typename Class> using Alias = typename Class::type_alias; -template <typename Class> using Holder = typename Class::holder_type; - -template <typename Class> using is_alias_constructible = std::is_constructible<Alias<Class>, Cpp<Class> &&>; - -// Takes a Cpp pointer and returns true if it actually is a polymorphic Alias instance. -template <typename Class, enable_if_t<Class::has_alias, int> = 0> -bool is_alias(Cpp<Class> *ptr) { - return dynamic_cast<Alias<Class> *>(ptr) != nullptr; -} -// Failing fallback version of the above for a no-alias class (always returns false) -template <typename /*Class*/> -constexpr bool is_alias(void *) { return false; } - -// Constructs and returns a new object; if the given arguments don't map to a constructor, we fall -// back to brace aggregate initiailization so that for aggregate initialization can be used with -// py::init, e.g. `py::init<int, int>` to initialize a `struct T { int a; int b; }`. For -// non-aggregate types, we need to use an ordinary T(...) constructor (invoking as `T{...}` usually -// works, but will not do the expected thing when `T` has an `initializer_list<T>` constructor). -template <typename Class, typename... Args, detail::enable_if_t<std::is_constructible<Class, Args...>::value, int> = 0> -inline Class *construct_or_initialize(Args &&...args) { return new Class(std::forward<Args>(args)...); } -template <typename Class, typename... Args, detail::enable_if_t<!std::is_constructible<Class, Args...>::value, int> = 0> -inline Class *construct_or_initialize(Args &&...args) { return new Class{std::forward<Args>(args)...}; } - -// Attempts to constructs an alias using a `Alias(Cpp &&)` constructor. This allows types with -// an alias to provide only a single Cpp factory function as long as the Alias can be -// constructed from an rvalue reference of the base Cpp type. This means that Alias classes -// can, when appropriate, simply define a `Alias(Cpp &&)` constructor rather than needing to -// inherit all the base class constructors. -template <typename Class> -void construct_alias_from_cpp(std::true_type /*is_alias_constructible*/, - value_and_holder &v_h, Cpp<Class> &&base) { - v_h.value_ptr() = new Alias<Class>(std::move(base)); -} -template <typename Class> -[[noreturn]] void construct_alias_from_cpp(std::false_type /*!is_alias_constructible*/, - value_and_holder &, Cpp<Class> &&) { - throw type_error("pybind11::init(): unable to convert returned instance to required " - "alias class: no `Alias<Class>(Class &&)` constructor available"); -} - -// Error-generating fallback for factories that don't match one of the below construction -// mechanisms. -template <typename Class> -void construct(...) { - static_assert(!std::is_same<Class, Class>::value /* always false */, - "pybind11::init(): init function must return a compatible pointer, " - "holder, or value"); -} - -// Pointer return v1: the factory function returns a class pointer for a registered class. -// If we don't need an alias (because this class doesn't have one, or because the final type is -// inherited on the Python side) we can simply take over ownership. Otherwise we need to try to -// construct an Alias from the returned base instance. -template <typename Class> -void construct(value_and_holder &v_h, Cpp<Class> *ptr, bool need_alias) { - no_nullptr(ptr); - if (Class::has_alias && need_alias && !is_alias<Class>(ptr)) { - // We're going to try to construct an alias by moving the cpp type. Whether or not - // that succeeds, we still need to destroy the original cpp pointer (either the - // moved away leftover, if the alias construction works, or the value itself if we - // throw an error), but we can't just call `delete ptr`: it might have a special - // deleter, or might be shared_from_this. So we construct a holder around it as if - // it was a normal instance, then steal the holder away into a local variable; thus - // the holder and destruction happens when we leave the C++ scope, and the holder - // class gets to handle the destruction however it likes. - v_h.value_ptr() = ptr; - v_h.set_instance_registered(true); // To prevent init_instance from registering it - v_h.type->init_instance(v_h.inst, nullptr); // Set up the holder - Holder<Class> temp_holder(std::move(v_h.holder<Holder<Class>>())); // Steal the holder - v_h.type->dealloc(v_h); // Destroys the moved-out holder remains, resets value ptr to null - v_h.set_instance_registered(false); - - construct_alias_from_cpp<Class>(is_alias_constructible<Class>{}, v_h, std::move(*ptr)); - } else { - // Otherwise the type isn't inherited, so we don't need an Alias - v_h.value_ptr() = ptr; - } -} - -// Pointer return v2: a factory that always returns an alias instance ptr. We simply take over -// ownership of the pointer. -template <typename Class, enable_if_t<Class::has_alias, int> = 0> -void construct(value_and_holder &v_h, Alias<Class> *alias_ptr, bool) { - no_nullptr(alias_ptr); - v_h.value_ptr() = static_cast<Cpp<Class> *>(alias_ptr); -} - -// Holder return: copy its pointer, and move or copy the returned holder into the new instance's -// holder. This also handles types like std::shared_ptr<T> and std::unique_ptr<T> where T is a -// derived type (through those holder's implicit conversion from derived class holder constructors). -template <typename Class> -void construct(value_and_holder &v_h, Holder<Class> holder, bool need_alias) { - auto *ptr = holder_helper<Holder<Class>>::get(holder); - // If we need an alias, check that the held pointer is actually an alias instance - if (Class::has_alias && need_alias && !is_alias<Class>(ptr)) - throw type_error("pybind11::init(): construction failed: returned holder-wrapped instance " - "is not an alias instance"); - - v_h.value_ptr() = ptr; - v_h.type->init_instance(v_h.inst, &holder); -} - -// return-by-value version 1: returning a cpp class by value. If the class has an alias and an -// alias is required the alias must have an `Alias(Cpp &&)` constructor so that we can construct -// the alias from the base when needed (i.e. because of Python-side inheritance). When we don't -// need it, we simply move-construct the cpp value into a new instance. -template <typename Class> -void construct(value_and_holder &v_h, Cpp<Class> &&result, bool need_alias) { - static_assert(std::is_move_constructible<Cpp<Class>>::value, - "pybind11::init() return-by-value factory function requires a movable class"); - if (Class::has_alias && need_alias) - construct_alias_from_cpp<Class>(is_alias_constructible<Class>{}, v_h, std::move(result)); - else - v_h.value_ptr() = new Cpp<Class>(std::move(result)); -} - -// return-by-value version 2: returning a value of the alias type itself. We move-construct an -// Alias instance (even if no the python-side inheritance is involved). The is intended for -// cases where Alias initialization is always desired. -template <typename Class> -void construct(value_and_holder &v_h, Alias<Class> &&result, bool) { - static_assert(std::is_move_constructible<Alias<Class>>::value, - "pybind11::init() return-by-alias-value factory function requires a movable alias class"); - v_h.value_ptr() = new Alias<Class>(std::move(result)); -} - -// Implementing class for py::init<...>() -template <typename... Args> -struct constructor { - template <typename Class, typename... Extra, enable_if_t<!Class::has_alias, int> = 0> - static void execute(Class &cl, const Extra&... extra) { - cl.def("__init__", [](value_and_holder &v_h, Args... args) { - v_h.value_ptr() = construct_or_initialize<Cpp<Class>>(std::forward<Args>(args)...); - }, is_new_style_constructor(), extra...); - } - - template <typename Class, typename... Extra, - enable_if_t<Class::has_alias && - std::is_constructible<Cpp<Class>, Args...>::value, int> = 0> - static void execute(Class &cl, const Extra&... extra) { - cl.def("__init__", [](value_and_holder &v_h, Args... args) { - if (Py_TYPE(v_h.inst) == v_h.type->type) - v_h.value_ptr() = construct_or_initialize<Cpp<Class>>(std::forward<Args>(args)...); - else - v_h.value_ptr() = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...); - }, is_new_style_constructor(), extra...); - } - - template <typename Class, typename... Extra, - enable_if_t<Class::has_alias && - !std::is_constructible<Cpp<Class>, Args...>::value, int> = 0> - static void execute(Class &cl, const Extra&... extra) { - cl.def("__init__", [](value_and_holder &v_h, Args... args) { - v_h.value_ptr() = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...); - }, is_new_style_constructor(), extra...); - } -}; - -// Implementing class for py::init_alias<...>() -template <typename... Args> struct alias_constructor { - template <typename Class, typename... Extra, - enable_if_t<Class::has_alias && std::is_constructible<Alias<Class>, Args...>::value, int> = 0> - static void execute(Class &cl, const Extra&... extra) { - cl.def("__init__", [](value_and_holder &v_h, Args... args) { - v_h.value_ptr() = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...); - }, is_new_style_constructor(), extra...); - } -}; - -// Implementation class for py::init(Func) and py::init(Func, AliasFunc) -template <typename CFunc, typename AFunc = void_type (*)(), - typename = function_signature_t<CFunc>, typename = function_signature_t<AFunc>> -struct factory; - -// Specialization for py::init(Func) -template <typename Func, typename Return, typename... Args> -struct factory<Func, void_type (*)(), Return(Args...)> { - remove_reference_t<Func> class_factory; - - factory(Func &&f) : class_factory(std::forward<Func>(f)) { } - - // The given class either has no alias or has no separate alias factory; - // this always constructs the class itself. If the class is registered with an alias - // type and an alias instance is needed (i.e. because the final type is a Python class - // inheriting from the C++ type) the returned value needs to either already be an alias - // instance, or the alias needs to be constructible from a `Class &&` argument. - template <typename Class, typename... Extra> - void execute(Class &cl, const Extra &...extra) && { - #if defined(PYBIND11_CPP14) - cl.def("__init__", [func = std::move(class_factory)] - #else - auto &func = class_factory; - cl.def("__init__", [func] - #endif - (value_and_holder &v_h, Args... args) { - construct<Class>(v_h, func(std::forward<Args>(args)...), - Py_TYPE(v_h.inst) != v_h.type->type); - }, is_new_style_constructor(), extra...); - } -}; - -// Specialization for py::init(Func, AliasFunc) -template <typename CFunc, typename AFunc, - typename CReturn, typename... CArgs, typename AReturn, typename... AArgs> -struct factory<CFunc, AFunc, CReturn(CArgs...), AReturn(AArgs...)> { - static_assert(sizeof...(CArgs) == sizeof...(AArgs), - "pybind11::init(class_factory, alias_factory): class and alias factories " - "must have identical argument signatures"); - static_assert(all_of<std::is_same<CArgs, AArgs>...>::value, - "pybind11::init(class_factory, alias_factory): class and alias factories " - "must have identical argument signatures"); - - remove_reference_t<CFunc> class_factory; - remove_reference_t<AFunc> alias_factory; - - factory(CFunc &&c, AFunc &&a) - : class_factory(std::forward<CFunc>(c)), alias_factory(std::forward<AFunc>(a)) { } - - // The class factory is called when the `self` type passed to `__init__` is the direct - // class (i.e. not inherited), the alias factory when `self` is a Python-side subtype. - template <typename Class, typename... Extra> - void execute(Class &cl, const Extra&... extra) && { - static_assert(Class::has_alias, "The two-argument version of `py::init()` can " - "only be used if the class has an alias"); - #if defined(PYBIND11_CPP14) - cl.def("__init__", [class_func = std::move(class_factory), alias_func = std::move(alias_factory)] - #else - auto &class_func = class_factory; - auto &alias_func = alias_factory; - cl.def("__init__", [class_func, alias_func] - #endif - (value_and_holder &v_h, CArgs... args) { - if (Py_TYPE(v_h.inst) == v_h.type->type) - // If the instance type equals the registered type we don't have inheritance, so - // don't need the alias and can construct using the class function: - construct<Class>(v_h, class_func(std::forward<CArgs>(args)...), false); - else - construct<Class>(v_h, alias_func(std::forward<CArgs>(args)...), true); - }, is_new_style_constructor(), extra...); - } -}; - -/// Set just the C++ state. Same as `__init__`. -template <typename Class, typename T> -void setstate(value_and_holder &v_h, T &&result, bool need_alias) { - construct<Class>(v_h, std::forward<T>(result), need_alias); -} - -/// Set both the C++ and Python states -template <typename Class, typename T, typename O, - enable_if_t<std::is_convertible<O, handle>::value, int> = 0> -void setstate(value_and_holder &v_h, std::pair<T, O> &&result, bool need_alias) { - construct<Class>(v_h, std::move(result.first), need_alias); - setattr((PyObject *) v_h.inst, "__dict__", result.second); -} - -/// Implementation for py::pickle(GetState, SetState) -template <typename Get, typename Set, - typename = function_signature_t<Get>, typename = function_signature_t<Set>> -struct pickle_factory; - -template <typename Get, typename Set, - typename RetState, typename Self, typename NewInstance, typename ArgState> -struct pickle_factory<Get, Set, RetState(Self), NewInstance(ArgState)> { - static_assert(std::is_same<intrinsic_t<RetState>, intrinsic_t<ArgState>>::value, - "The type returned by `__getstate__` must be the same " - "as the argument accepted by `__setstate__`"); - - remove_reference_t<Get> get; - remove_reference_t<Set> set; - - pickle_factory(Get get, Set set) - : get(std::forward<Get>(get)), set(std::forward<Set>(set)) { } - - template <typename Class, typename... Extra> - void execute(Class &cl, const Extra &...extra) && { - cl.def("__getstate__", std::move(get)); - -#if defined(PYBIND11_CPP14) - cl.def("__setstate__", [func = std::move(set)] -#else - auto &func = set; - cl.def("__setstate__", [func] -#endif - (value_and_holder &v_h, ArgState state) { - setstate<Class>(v_h, func(std::forward<ArgState>(state)), - Py_TYPE(v_h.inst) != v_h.type->type); - }, is_new_style_constructor(), extra...); - } -}; - -NAMESPACE_END(initimpl) -NAMESPACE_END(detail) -NAMESPACE_END(pybind11) diff --git a/external/pybind11/include/pybind11/detail/internals.h b/external/pybind11/include/pybind11/detail/internals.h deleted file mode 100644 index 067780c2..00000000 --- a/external/pybind11/include/pybind11/detail/internals.h +++ /dev/null @@ -1,336 +0,0 @@ -/* - pybind11/detail/internals.h: Internal data structure and related functions - - Copyright (c) 2017 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "../pytypes.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) -// Forward declarations -inline PyTypeObject *make_static_property_type(); -inline PyTypeObject *make_default_metaclass(); -inline PyObject *make_object_base_type(PyTypeObject *metaclass); - -// The old Python Thread Local Storage (TLS) API is deprecated in Python 3.7 in favor of the new -// Thread Specific Storage (TSS) API. -#if PY_VERSION_HEX >= 0x03070000 -# define PYBIND11_TLS_KEY_INIT(var) Py_tss_t *var = nullptr -# define PYBIND11_TLS_GET_VALUE(key) PyThread_tss_get((key)) -# define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_tss_set((key), (value)) -# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_tss_set((key), nullptr) -#else - // Usually an int but a long on Cygwin64 with Python 3.x -# define PYBIND11_TLS_KEY_INIT(var) decltype(PyThread_create_key()) var = 0 -# define PYBIND11_TLS_GET_VALUE(key) PyThread_get_key_value((key)) -# if PY_MAJOR_VERSION < 3 -# define PYBIND11_TLS_DELETE_VALUE(key) \ - PyThread_delete_key_value(key) -# define PYBIND11_TLS_REPLACE_VALUE(key, value) \ - do { \ - PyThread_delete_key_value((key)); \ - PyThread_set_key_value((key), (value)); \ - } while (false) -# else -# define PYBIND11_TLS_DELETE_VALUE(key) \ - PyThread_set_key_value((key), nullptr) -# define PYBIND11_TLS_REPLACE_VALUE(key, value) \ - PyThread_set_key_value((key), (value)) -# endif -#endif - -// Python loads modules by default with dlopen with the RTLD_LOCAL flag; under libc++ and possibly -// other STLs, this means `typeid(A)` from one module won't equal `typeid(A)` from another module -// even when `A` is the same, non-hidden-visibility type (e.g. from a common include). Under -// libstdc++, this doesn't happen: equality and the type_index hash are based on the type name, -// which works. If not under a known-good stl, provide our own name-based hash and equality -// functions that use the type name. -#if defined(__GLIBCXX__) -inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) { return lhs == rhs; } -using type_hash = std::hash<std::type_index>; -using type_equal_to = std::equal_to<std::type_index>; -#else -inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) { - return lhs.name() == rhs.name() || std::strcmp(lhs.name(), rhs.name()) == 0; -} - -struct type_hash { - size_t operator()(const std::type_index &t) const { - size_t hash = 5381; - const char *ptr = t.name(); - while (auto c = static_cast<unsigned char>(*ptr++)) - hash = (hash * 33) ^ c; - return hash; - } -}; - -struct type_equal_to { - bool operator()(const std::type_index &lhs, const std::type_index &rhs) const { - return lhs.name() == rhs.name() || std::strcmp(lhs.name(), rhs.name()) == 0; - } -}; -#endif - -template <typename value_type> -using type_map = std::unordered_map<std::type_index, value_type, type_hash, type_equal_to>; - -struct overload_hash { - inline size_t operator()(const std::pair<const PyObject *, const char *>& v) const { - size_t value = std::hash<const void *>()(v.first); - value ^= std::hash<const void *>()(v.second) + 0x9e3779b9 + (value<<6) + (value>>2); - return value; - } -}; - -/// Internal data structure used to track registered instances and types. -/// Whenever binary incompatible changes are made to this structure, -/// `PYBIND11_INTERNALS_VERSION` must be incremented. -struct internals { - type_map<type_info *> registered_types_cpp; // std::type_index -> pybind11's type information - std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py; // PyTypeObject* -> base type_info(s) - std::unordered_multimap<const void *, instance*> registered_instances; // void * -> instance* - std::unordered_set<std::pair<const PyObject *, const char *>, overload_hash> inactive_overload_cache; - type_map<std::vector<bool (*)(PyObject *, void *&)>> direct_conversions; - std::unordered_map<const PyObject *, std::vector<PyObject *>> patients; - std::forward_list<void (*) (std::exception_ptr)> registered_exception_translators; - std::unordered_map<std::string, void *> shared_data; // Custom data to be shared across extensions - std::vector<PyObject *> loader_patient_stack; // Used by `loader_life_support` - std::forward_list<std::string> static_strings; // Stores the std::strings backing detail::c_str() - PyTypeObject *static_property_type; - PyTypeObject *default_metaclass; - PyObject *instance_base; -#if defined(WITH_THREAD) - PYBIND11_TLS_KEY_INIT(tstate); - PyInterpreterState *istate = nullptr; -#endif -}; - -/// Additional type information which does not fit into the PyTypeObject. -/// Changes to this struct also require bumping `PYBIND11_INTERNALS_VERSION`. -struct type_info { - PyTypeObject *type; - const std::type_info *cpptype; - size_t type_size, type_align, holder_size_in_ptrs; - void *(*operator_new)(size_t); - void (*init_instance)(instance *, const void *); - void (*dealloc)(value_and_holder &v_h); - std::vector<PyObject *(*)(PyObject *, PyTypeObject *)> implicit_conversions; - std::vector<std::pair<const std::type_info *, void *(*)(void *)>> implicit_casts; - std::vector<bool (*)(PyObject *, void *&)> *direct_conversions; - buffer_info *(*get_buffer)(PyObject *, void *) = nullptr; - void *get_buffer_data = nullptr; - void *(*module_local_load)(PyObject *, const type_info *) = nullptr; - /* A simple type never occurs as a (direct or indirect) parent - * of a class that makes use of multiple inheritance */ - bool simple_type : 1; - /* True if there is no multiple inheritance in this type's inheritance tree */ - bool simple_ancestors : 1; - /* for base vs derived holder_type checks */ - bool default_holder : 1; - /* true if this is a type registered with py::module_local */ - bool module_local : 1; -}; - -/// Tracks the `internals` and `type_info` ABI version independent of the main library version -#define PYBIND11_INTERNALS_VERSION 3 - -/// On MSVC, debug and release builds are not ABI-compatible! -#if defined(_MSC_VER) && defined(_DEBUG) -# define PYBIND11_BUILD_TYPE "_debug" -#else -# define PYBIND11_BUILD_TYPE "" -#endif - -/// Let's assume that different compilers are ABI-incompatible. -#if defined(_MSC_VER) -# define PYBIND11_COMPILER_TYPE "_msvc" -#elif defined(__INTEL_COMPILER) -# define PYBIND11_COMPILER_TYPE "_icc" -#elif defined(__clang__) -# define PYBIND11_COMPILER_TYPE "_clang" -#elif defined(__PGI) -# define PYBIND11_COMPILER_TYPE "_pgi" -#elif defined(__MINGW32__) -# define PYBIND11_COMPILER_TYPE "_mingw" -#elif defined(__CYGWIN__) -# define PYBIND11_COMPILER_TYPE "_gcc_cygwin" -#elif defined(__GNUC__) -# define PYBIND11_COMPILER_TYPE "_gcc" -#else -# define PYBIND11_COMPILER_TYPE "_unknown" -#endif - -#if defined(_LIBCPP_VERSION) -# define PYBIND11_STDLIB "_libcpp" -#elif defined(__GLIBCXX__) || defined(__GLIBCPP__) -# define PYBIND11_STDLIB "_libstdcpp" -#else -# define PYBIND11_STDLIB "" -#endif - -/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility. -#if defined(__GXX_ABI_VERSION) -# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) -#else -# define PYBIND11_BUILD_ABI "" -#endif - -#if defined(WITH_THREAD) -# define PYBIND11_INTERNALS_KIND "" -#else -# define PYBIND11_INTERNALS_KIND "_without_thread" -#endif - -#define PYBIND11_INTERNALS_ID "__pybind11_internals_v" \ - PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__" - -#define PYBIND11_MODULE_LOCAL_ID "__pybind11_module_local_v" \ - PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__" - -/// Each module locally stores a pointer to the `internals` data. The data -/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`. -inline internals **&get_internals_pp() { - static internals **internals_pp = nullptr; - return internals_pp; -} - -inline void translate_exception(std::exception_ptr p) { - try { - if (p) std::rethrow_exception(p); - } catch (error_already_set &e) { e.restore(); return; - } catch (const builtin_exception &e) { e.set_error(); return; - } catch (const std::bad_alloc &e) { PyErr_SetString(PyExc_MemoryError, e.what()); return; - } catch (const std::domain_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return; - } catch (const std::invalid_argument &e) { PyErr_SetString(PyExc_ValueError, e.what()); return; - } catch (const std::length_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return; - } catch (const std::out_of_range &e) { PyErr_SetString(PyExc_IndexError, e.what()); return; - } catch (const std::range_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return; - } catch (const std::exception &e) { PyErr_SetString(PyExc_RuntimeError, e.what()); return; - } catch (...) { - PyErr_SetString(PyExc_RuntimeError, "Caught an unknown exception!"); - return; - } -} - -#if !defined(__GLIBCXX__) -inline void translate_local_exception(std::exception_ptr p) { - try { - if (p) std::rethrow_exception(p); - } catch (error_already_set &e) { e.restore(); return; - } catch (const builtin_exception &e) { e.set_error(); return; - } -} -#endif - -/// Return a reference to the current `internals` data -PYBIND11_NOINLINE inline internals &get_internals() { - auto **&internals_pp = get_internals_pp(); - if (internals_pp && *internals_pp) - return **internals_pp; - - // Ensure that the GIL is held since we will need to make Python calls. - // Cannot use py::gil_scoped_acquire here since that constructor calls get_internals. - struct gil_scoped_acquire_local { - gil_scoped_acquire_local() : state (PyGILState_Ensure()) {} - ~gil_scoped_acquire_local() { PyGILState_Release(state); } - const PyGILState_STATE state; - } gil; - - constexpr auto *id = PYBIND11_INTERNALS_ID; - auto builtins = handle(PyEval_GetBuiltins()); - if (builtins.contains(id) && isinstance<capsule>(builtins[id])) { - internals_pp = static_cast<internals **>(capsule(builtins[id])); - - // We loaded builtins through python's builtins, which means that our `error_already_set` - // and `builtin_exception` may be different local classes than the ones set up in the - // initial exception translator, below, so add another for our local exception classes. - // - // libstdc++ doesn't require this (types there are identified only by name) -#if !defined(__GLIBCXX__) - (*internals_pp)->registered_exception_translators.push_front(&translate_local_exception); -#endif - } else { - if (!internals_pp) internals_pp = new internals*(); - auto *&internals_ptr = *internals_pp; - internals_ptr = new internals(); -#if defined(WITH_THREAD) - PyEval_InitThreads(); - PyThreadState *tstate = PyThreadState_Get(); - #if PY_VERSION_HEX >= 0x03070000 - internals_ptr->tstate = PyThread_tss_alloc(); - if (!internals_ptr->tstate || PyThread_tss_create(internals_ptr->tstate)) - pybind11_fail("get_internals: could not successfully initialize the TSS key!"); - PyThread_tss_set(internals_ptr->tstate, tstate); - #else - internals_ptr->tstate = PyThread_create_key(); - if (internals_ptr->tstate == -1) - pybind11_fail("get_internals: could not successfully initialize the TLS key!"); - PyThread_set_key_value(internals_ptr->tstate, tstate); - #endif - internals_ptr->istate = tstate->interp; -#endif - builtins[id] = capsule(internals_pp); - internals_ptr->registered_exception_translators.push_front(&translate_exception); - internals_ptr->static_property_type = make_static_property_type(); - internals_ptr->default_metaclass = make_default_metaclass(); - internals_ptr->instance_base = make_object_base_type(internals_ptr->default_metaclass); - } - return **internals_pp; -} - -/// Works like `internals.registered_types_cpp`, but for module-local registered types: -inline type_map<type_info *> ®istered_local_types_cpp() { - static type_map<type_info *> locals{}; - return locals; -} - -/// Constructs a std::string with the given arguments, stores it in `internals`, and returns its -/// `c_str()`. Such strings objects have a long storage duration -- the internal strings are only -/// cleared when the program exits or after interpreter shutdown (when embedding), and so are -/// suitable for c-style strings needed by Python internals (such as PyTypeObject's tp_name). -template <typename... Args> -const char *c_str(Args &&...args) { - auto &strings = get_internals().static_strings; - strings.emplace_front(std::forward<Args>(args)...); - return strings.front().c_str(); -} - -NAMESPACE_END(detail) - -/// Returns a named pointer that is shared among all extension modules (using the same -/// pybind11 version) running in the current interpreter. Names starting with underscores -/// are reserved for internal usage. Returns `nullptr` if no matching entry was found. -inline PYBIND11_NOINLINE void *get_shared_data(const std::string &name) { - auto &internals = detail::get_internals(); - auto it = internals.shared_data.find(name); - return it != internals.shared_data.end() ? it->second : nullptr; -} - -/// Set the shared data that can be later recovered by `get_shared_data()`. -inline PYBIND11_NOINLINE void *set_shared_data(const std::string &name, void *data) { - detail::get_internals().shared_data[name] = data; - return data; -} - -/// Returns a typed reference to a shared data entry (by using `get_shared_data()`) if -/// such entry exists. Otherwise, a new object of default-constructible type `T` is -/// added to the shared data under the given name and a reference to it is returned. -template<typename T> -T &get_or_create_shared_data(const std::string &name) { - auto &internals = detail::get_internals(); - auto it = internals.shared_data.find(name); - T *ptr = (T *) (it != internals.shared_data.end() ? it->second : nullptr); - if (!ptr) { - ptr = new T(); - internals.shared_data[name] = ptr; - } - return *ptr; -} - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/detail/typeid.h b/external/pybind11/include/pybind11/detail/typeid.h deleted file mode 100644 index 9c8a4fc6..00000000 --- a/external/pybind11/include/pybind11/detail/typeid.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - pybind11/detail/typeid.h: Compiler-independent access to type identifiers - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include <cstdio> -#include <cstdlib> - -#if defined(__GNUG__) -#include <cxxabi.h> -#endif - -#include "common.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) -/// Erase all occurrences of a substring -inline void erase_all(std::string &string, const std::string &search) { - for (size_t pos = 0;;) { - pos = string.find(search, pos); - if (pos == std::string::npos) break; - string.erase(pos, search.length()); - } -} - -PYBIND11_NOINLINE inline void clean_type_id(std::string &name) { -#if defined(__GNUG__) - int status = 0; - std::unique_ptr<char, void (*)(void *)> res { - abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free }; - if (status == 0) - name = res.get(); -#else - detail::erase_all(name, "class "); - detail::erase_all(name, "struct "); - detail::erase_all(name, "enum "); -#endif - detail::erase_all(name, "pybind11::"); -} -NAMESPACE_END(detail) - -/// Return a string representation of a C++ type -template <typename T> static std::string type_id() { - std::string name(typeid(T).name()); - detail::clean_type_id(name); - return name; -} - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/eigen.h b/external/pybind11/include/pybind11/eigen.h deleted file mode 100644 index d963d965..00000000 --- a/external/pybind11/include/pybind11/eigen.h +++ /dev/null @@ -1,607 +0,0 @@ -/* - pybind11/eigen.h: Transparent conversion for dense and sparse Eigen matrices - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "numpy.h" - -#if defined(__INTEL_COMPILER) -# pragma warning(disable: 1682) // implicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem) -#elif defined(__GNUG__) || defined(__clang__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wconversion" -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -# ifdef __clang__ -// Eigen generates a bunch of implicit-copy-constructor-is-deprecated warnings with -Wdeprecated -// under Clang, so disable that warning here: -# pragma GCC diagnostic ignored "-Wdeprecated" -# endif -# if __GNUC__ >= 7 -# pragma GCC diagnostic ignored "-Wint-in-bool-context" -# endif -#endif - -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant -# pragma warning(disable: 4996) // warning C4996: std::unary_negate is deprecated in C++17 -#endif - -#include <Eigen/Core> -#include <Eigen/SparseCore> - -// Eigen prior to 3.2.7 doesn't have proper move constructors--but worse, some classes get implicit -// move constructors that break things. We could detect this an explicitly copy, but an extra copy -// of matrices seems highly undesirable. -static_assert(EIGEN_VERSION_AT_LEAST(3,2,7), "Eigen support in pybind11 requires Eigen >= 3.2.7"); - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -// Provide a convenience alias for easier pass-by-ref usage with fully dynamic strides: -using EigenDStride = Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>; -template <typename MatrixType> using EigenDRef = Eigen::Ref<MatrixType, 0, EigenDStride>; -template <typename MatrixType> using EigenDMap = Eigen::Map<MatrixType, 0, EigenDStride>; - -NAMESPACE_BEGIN(detail) - -#if EIGEN_VERSION_AT_LEAST(3,3,0) -using EigenIndex = Eigen::Index; -#else -using EigenIndex = EIGEN_DEFAULT_DENSE_INDEX_TYPE; -#endif - -// Matches Eigen::Map, Eigen::Ref, blocks, etc: -template <typename T> using is_eigen_dense_map = all_of<is_template_base_of<Eigen::DenseBase, T>, std::is_base_of<Eigen::MapBase<T, Eigen::ReadOnlyAccessors>, T>>; -template <typename T> using is_eigen_mutable_map = std::is_base_of<Eigen::MapBase<T, Eigen::WriteAccessors>, T>; -template <typename T> using is_eigen_dense_plain = all_of<negation<is_eigen_dense_map<T>>, is_template_base_of<Eigen::PlainObjectBase, T>>; -template <typename T> using is_eigen_sparse = is_template_base_of<Eigen::SparseMatrixBase, T>; -// Test for objects inheriting from EigenBase<Derived> that aren't captured by the above. This -// basically covers anything that can be assigned to a dense matrix but that don't have a typical -// matrix data layout that can be copied from their .data(). For example, DiagonalMatrix and -// SelfAdjointView fall into this category. -template <typename T> using is_eigen_other = all_of< - is_template_base_of<Eigen::EigenBase, T>, - negation<any_of<is_eigen_dense_map<T>, is_eigen_dense_plain<T>, is_eigen_sparse<T>>> ->; - -// Captures numpy/eigen conformability status (returned by EigenProps::conformable()): -template <bool EigenRowMajor> struct EigenConformable { - bool conformable = false; - EigenIndex rows = 0, cols = 0; - EigenDStride stride{0, 0}; // Only valid if negativestrides is false! - bool negativestrides = false; // If true, do not use stride! - - EigenConformable(bool fits = false) : conformable{fits} {} - // Matrix type: - EigenConformable(EigenIndex r, EigenIndex c, - EigenIndex rstride, EigenIndex cstride) : - conformable{true}, rows{r}, cols{c} { - // TODO: when Eigen bug #747 is fixed, remove the tests for non-negativity. http://eigen.tuxfamily.org/bz/show_bug.cgi?id=747 - if (rstride < 0 || cstride < 0) { - negativestrides = true; - } else { - stride = {EigenRowMajor ? rstride : cstride /* outer stride */, - EigenRowMajor ? cstride : rstride /* inner stride */ }; - } - } - // Vector type: - EigenConformable(EigenIndex r, EigenIndex c, EigenIndex stride) - : EigenConformable(r, c, r == 1 ? c*stride : stride, c == 1 ? r : r*stride) {} - - template <typename props> bool stride_compatible() const { - // To have compatible strides, we need (on both dimensions) one of fully dynamic strides, - // matching strides, or a dimension size of 1 (in which case the stride value is irrelevant) - return - !negativestrides && - (props::inner_stride == Eigen::Dynamic || props::inner_stride == stride.inner() || - (EigenRowMajor ? cols : rows) == 1) && - (props::outer_stride == Eigen::Dynamic || props::outer_stride == stride.outer() || - (EigenRowMajor ? rows : cols) == 1); - } - operator bool() const { return conformable; } -}; - -template <typename Type> struct eigen_extract_stride { using type = Type; }; -template <typename PlainObjectType, int MapOptions, typename StrideType> -struct eigen_extract_stride<Eigen::Map<PlainObjectType, MapOptions, StrideType>> { using type = StrideType; }; -template <typename PlainObjectType, int Options, typename StrideType> -struct eigen_extract_stride<Eigen::Ref<PlainObjectType, Options, StrideType>> { using type = StrideType; }; - -// Helper struct for extracting information from an Eigen type -template <typename Type_> struct EigenProps { - using Type = Type_; - using Scalar = typename Type::Scalar; - using StrideType = typename eigen_extract_stride<Type>::type; - static constexpr EigenIndex - rows = Type::RowsAtCompileTime, - cols = Type::ColsAtCompileTime, - size = Type::SizeAtCompileTime; - static constexpr bool - row_major = Type::IsRowMajor, - vector = Type::IsVectorAtCompileTime, // At least one dimension has fixed size 1 - fixed_rows = rows != Eigen::Dynamic, - fixed_cols = cols != Eigen::Dynamic, - fixed = size != Eigen::Dynamic, // Fully-fixed size - dynamic = !fixed_rows && !fixed_cols; // Fully-dynamic size - - template <EigenIndex i, EigenIndex ifzero> using if_zero = std::integral_constant<EigenIndex, i == 0 ? ifzero : i>; - static constexpr EigenIndex inner_stride = if_zero<StrideType::InnerStrideAtCompileTime, 1>::value, - outer_stride = if_zero<StrideType::OuterStrideAtCompileTime, - vector ? size : row_major ? cols : rows>::value; - static constexpr bool dynamic_stride = inner_stride == Eigen::Dynamic && outer_stride == Eigen::Dynamic; - static constexpr bool requires_row_major = !dynamic_stride && !vector && (row_major ? inner_stride : outer_stride) == 1; - static constexpr bool requires_col_major = !dynamic_stride && !vector && (row_major ? outer_stride : inner_stride) == 1; - - // Takes an input array and determines whether we can make it fit into the Eigen type. If - // the array is a vector, we attempt to fit it into either an Eigen 1xN or Nx1 vector - // (preferring the latter if it will fit in either, i.e. for a fully dynamic matrix type). - static EigenConformable<row_major> conformable(const array &a) { - const auto dims = a.ndim(); - if (dims < 1 || dims > 2) - return false; - - if (dims == 2) { // Matrix type: require exact match (or dynamic) - - EigenIndex - np_rows = a.shape(0), - np_cols = a.shape(1), - np_rstride = a.strides(0) / static_cast<ssize_t>(sizeof(Scalar)), - np_cstride = a.strides(1) / static_cast<ssize_t>(sizeof(Scalar)); - if ((fixed_rows && np_rows != rows) || (fixed_cols && np_cols != cols)) - return false; - - return {np_rows, np_cols, np_rstride, np_cstride}; - } - - // Otherwise we're storing an n-vector. Only one of the strides will be used, but whichever - // is used, we want the (single) numpy stride value. - const EigenIndex n = a.shape(0), - stride = a.strides(0) / static_cast<ssize_t>(sizeof(Scalar)); - - if (vector) { // Eigen type is a compile-time vector - if (fixed && size != n) - return false; // Vector size mismatch - return {rows == 1 ? 1 : n, cols == 1 ? 1 : n, stride}; - } - else if (fixed) { - // The type has a fixed size, but is not a vector: abort - return false; - } - else if (fixed_cols) { - // Since this isn't a vector, cols must be != 1. We allow this only if it exactly - // equals the number of elements (rows is Dynamic, and so 1 row is allowed). - if (cols != n) return false; - return {1, n, stride}; - } - else { - // Otherwise it's either fully dynamic, or column dynamic; both become a column vector - if (fixed_rows && rows != n) return false; - return {n, 1, stride}; - } - } - - static constexpr bool show_writeable = is_eigen_dense_map<Type>::value && is_eigen_mutable_map<Type>::value; - static constexpr bool show_order = is_eigen_dense_map<Type>::value; - static constexpr bool show_c_contiguous = show_order && requires_row_major; - static constexpr bool show_f_contiguous = !show_c_contiguous && show_order && requires_col_major; - - static constexpr auto descriptor = - _("numpy.ndarray[") + npy_format_descriptor<Scalar>::name + - _("[") + _<fixed_rows>(_<(size_t) rows>(), _("m")) + - _(", ") + _<fixed_cols>(_<(size_t) cols>(), _("n")) + - _("]") + - // For a reference type (e.g. Ref<MatrixXd>) we have other constraints that might need to be - // satisfied: writeable=True (for a mutable reference), and, depending on the map's stride - // options, possibly f_contiguous or c_contiguous. We include them in the descriptor output - // to provide some hint as to why a TypeError is occurring (otherwise it can be confusing to - // see that a function accepts a 'numpy.ndarray[float64[3,2]]' and an error message that you - // *gave* a numpy.ndarray of the right type and dimensions. - _<show_writeable>(", flags.writeable", "") + - _<show_c_contiguous>(", flags.c_contiguous", "") + - _<show_f_contiguous>(", flags.f_contiguous", "") + - _("]"); -}; - -// Casts an Eigen type to numpy array. If given a base, the numpy array references the src data, -// otherwise it'll make a copy. writeable lets you turn off the writeable flag for the array. -template <typename props> handle eigen_array_cast(typename props::Type const &src, handle base = handle(), bool writeable = true) { - constexpr ssize_t elem_size = sizeof(typename props::Scalar); - array a; - if (props::vector) - a = array({ src.size() }, { elem_size * src.innerStride() }, src.data(), base); - else - a = array({ src.rows(), src.cols() }, { elem_size * src.rowStride(), elem_size * src.colStride() }, - src.data(), base); - - if (!writeable) - array_proxy(a.ptr())->flags &= ~detail::npy_api::NPY_ARRAY_WRITEABLE_; - - return a.release(); -} - -// Takes an lvalue ref to some Eigen type and a (python) base object, creating a numpy array that -// reference the Eigen object's data with `base` as the python-registered base class (if omitted, -// the base will be set to None, and lifetime management is up to the caller). The numpy array is -// non-writeable if the given type is const. -template <typename props, typename Type> -handle eigen_ref_array(Type &src, handle parent = none()) { - // none here is to get past array's should-we-copy detection, which currently always - // copies when there is no base. Setting the base to None should be harmless. - return eigen_array_cast<props>(src, parent, !std::is_const<Type>::value); -} - -// Takes a pointer to some dense, plain Eigen type, builds a capsule around it, then returns a numpy -// array that references the encapsulated data with a python-side reference to the capsule to tie -// its destruction to that of any dependent python objects. Const-ness is determined by whether or -// not the Type of the pointer given is const. -template <typename props, typename Type, typename = enable_if_t<is_eigen_dense_plain<Type>::value>> -handle eigen_encapsulate(Type *src) { - capsule base(src, [](void *o) { delete static_cast<Type *>(o); }); - return eigen_ref_array<props>(*src, base); -} - -// Type caster for regular, dense matrix types (e.g. MatrixXd), but not maps/refs/etc. of dense -// types. -template<typename Type> -struct type_caster<Type, enable_if_t<is_eigen_dense_plain<Type>::value>> { - using Scalar = typename Type::Scalar; - using props = EigenProps<Type>; - - bool load(handle src, bool convert) { - // If we're in no-convert mode, only load if given an array of the correct type - if (!convert && !isinstance<array_t<Scalar>>(src)) - return false; - - // Coerce into an array, but don't do type conversion yet; the copy below handles it. - auto buf = array::ensure(src); - - if (!buf) - return false; - - auto dims = buf.ndim(); - if (dims < 1 || dims > 2) - return false; - - auto fits = props::conformable(buf); - if (!fits) - return false; - - // Allocate the new type, then build a numpy reference into it - value = Type(fits.rows, fits.cols); - auto ref = reinterpret_steal<array>(eigen_ref_array<props>(value)); - if (dims == 1) ref = ref.squeeze(); - else if (ref.ndim() == 1) buf = buf.squeeze(); - - int result = detail::npy_api::get().PyArray_CopyInto_(ref.ptr(), buf.ptr()); - - if (result < 0) { // Copy failed! - PyErr_Clear(); - return false; - } - - return true; - } - -private: - - // Cast implementation - template <typename CType> - static handle cast_impl(CType *src, return_value_policy policy, handle parent) { - switch (policy) { - case return_value_policy::take_ownership: - case return_value_policy::automatic: - return eigen_encapsulate<props>(src); - case return_value_policy::move: - return eigen_encapsulate<props>(new CType(std::move(*src))); - case return_value_policy::copy: - return eigen_array_cast<props>(*src); - case return_value_policy::reference: - case return_value_policy::automatic_reference: - return eigen_ref_array<props>(*src); - case return_value_policy::reference_internal: - return eigen_ref_array<props>(*src, parent); - default: - throw cast_error("unhandled return_value_policy: should not happen!"); - }; - } - -public: - - // Normal returned non-reference, non-const value: - static handle cast(Type &&src, return_value_policy /* policy */, handle parent) { - return cast_impl(&src, return_value_policy::move, parent); - } - // If you return a non-reference const, we mark the numpy array readonly: - static handle cast(const Type &&src, return_value_policy /* policy */, handle parent) { - return cast_impl(&src, return_value_policy::move, parent); - } - // lvalue reference return; default (automatic) becomes copy - static handle cast(Type &src, return_value_policy policy, handle parent) { - if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference) - policy = return_value_policy::copy; - return cast_impl(&src, policy, parent); - } - // const lvalue reference return; default (automatic) becomes copy - static handle cast(const Type &src, return_value_policy policy, handle parent) { - if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference) - policy = return_value_policy::copy; - return cast(&src, policy, parent); - } - // non-const pointer return - static handle cast(Type *src, return_value_policy policy, handle parent) { - return cast_impl(src, policy, parent); - } - // const pointer return - static handle cast(const Type *src, return_value_policy policy, handle parent) { - return cast_impl(src, policy, parent); - } - - static constexpr auto name = props::descriptor; - - operator Type*() { return &value; } - operator Type&() { return value; } - operator Type&&() && { return std::move(value); } - template <typename T> using cast_op_type = movable_cast_op_type<T>; - -private: - Type value; -}; - -// Base class for casting reference/map/block/etc. objects back to python. -template <typename MapType> struct eigen_map_caster { -private: - using props = EigenProps<MapType>; - -public: - - // Directly referencing a ref/map's data is a bit dangerous (whatever the map/ref points to has - // to stay around), but we'll allow it under the assumption that you know what you're doing (and - // have an appropriate keep_alive in place). We return a numpy array pointing directly at the - // ref's data (The numpy array ends up read-only if the ref was to a const matrix type.) Note - // that this means you need to ensure you don't destroy the object in some other way (e.g. with - // an appropriate keep_alive, or with a reference to a statically allocated matrix). - static handle cast(const MapType &src, return_value_policy policy, handle parent) { - switch (policy) { - case return_value_policy::copy: - return eigen_array_cast<props>(src); - case return_value_policy::reference_internal: - return eigen_array_cast<props>(src, parent, is_eigen_mutable_map<MapType>::value); - case return_value_policy::reference: - case return_value_policy::automatic: - case return_value_policy::automatic_reference: - return eigen_array_cast<props>(src, none(), is_eigen_mutable_map<MapType>::value); - default: - // move, take_ownership don't make any sense for a ref/map: - pybind11_fail("Invalid return_value_policy for Eigen Map/Ref/Block type"); - } - } - - static constexpr auto name = props::descriptor; - - // Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return - // types but not bound arguments). We still provide them (with an explicitly delete) so that - // you end up here if you try anyway. - bool load(handle, bool) = delete; - operator MapType() = delete; - template <typename> using cast_op_type = MapType; -}; - -// We can return any map-like object (but can only load Refs, specialized next): -template <typename Type> struct type_caster<Type, enable_if_t<is_eigen_dense_map<Type>::value>> - : eigen_map_caster<Type> {}; - -// Loader for Ref<...> arguments. See the documentation for info on how to make this work without -// copying (it requires some extra effort in many cases). -template <typename PlainObjectType, typename StrideType> -struct type_caster< - Eigen::Ref<PlainObjectType, 0, StrideType>, - enable_if_t<is_eigen_dense_map<Eigen::Ref<PlainObjectType, 0, StrideType>>::value> -> : public eigen_map_caster<Eigen::Ref<PlainObjectType, 0, StrideType>> { -private: - using Type = Eigen::Ref<PlainObjectType, 0, StrideType>; - using props = EigenProps<Type>; - using Scalar = typename props::Scalar; - using MapType = Eigen::Map<PlainObjectType, 0, StrideType>; - using Array = array_t<Scalar, array::forcecast | - ((props::row_major ? props::inner_stride : props::outer_stride) == 1 ? array::c_style : - (props::row_major ? props::outer_stride : props::inner_stride) == 1 ? array::f_style : 0)>; - static constexpr bool need_writeable = is_eigen_mutable_map<Type>::value; - // Delay construction (these have no default constructor) - std::unique_ptr<MapType> map; - std::unique_ptr<Type> ref; - // Our array. When possible, this is just a numpy array pointing to the source data, but - // sometimes we can't avoid copying (e.g. input is not a numpy array at all, has an incompatible - // layout, or is an array of a type that needs to be converted). Using a numpy temporary - // (rather than an Eigen temporary) saves an extra copy when we need both type conversion and - // storage order conversion. (Note that we refuse to use this temporary copy when loading an - // argument for a Ref<M> with M non-const, i.e. a read-write reference). - Array copy_or_ref; -public: - bool load(handle src, bool convert) { - // First check whether what we have is already an array of the right type. If not, we can't - // avoid a copy (because the copy is also going to do type conversion). - bool need_copy = !isinstance<Array>(src); - - EigenConformable<props::row_major> fits; - if (!need_copy) { - // We don't need a converting copy, but we also need to check whether the strides are - // compatible with the Ref's stride requirements - Array aref = reinterpret_borrow<Array>(src); - - if (aref && (!need_writeable || aref.writeable())) { - fits = props::conformable(aref); - if (!fits) return false; // Incompatible dimensions - if (!fits.template stride_compatible<props>()) - need_copy = true; - else - copy_or_ref = std::move(aref); - } - else { - need_copy = true; - } - } - - if (need_copy) { - // We need to copy: If we need a mutable reference, or we're not supposed to convert - // (either because we're in the no-convert overload pass, or because we're explicitly - // instructed not to copy (via `py::arg().noconvert()`) we have to fail loading. - if (!convert || need_writeable) return false; - - Array copy = Array::ensure(src); - if (!copy) return false; - fits = props::conformable(copy); - if (!fits || !fits.template stride_compatible<props>()) - return false; - copy_or_ref = std::move(copy); - loader_life_support::add_patient(copy_or_ref); - } - - ref.reset(); - map.reset(new MapType(data(copy_or_ref), fits.rows, fits.cols, make_stride(fits.stride.outer(), fits.stride.inner()))); - ref.reset(new Type(*map)); - - return true; - } - - operator Type*() { return ref.get(); } - operator Type&() { return *ref; } - template <typename _T> using cast_op_type = pybind11::detail::cast_op_type<_T>; - -private: - template <typename T = Type, enable_if_t<is_eigen_mutable_map<T>::value, int> = 0> - Scalar *data(Array &a) { return a.mutable_data(); } - - template <typename T = Type, enable_if_t<!is_eigen_mutable_map<T>::value, int> = 0> - const Scalar *data(Array &a) { return a.data(); } - - // Attempt to figure out a constructor of `Stride` that will work. - // If both strides are fixed, use a default constructor: - template <typename S> using stride_ctor_default = bool_constant< - S::InnerStrideAtCompileTime != Eigen::Dynamic && S::OuterStrideAtCompileTime != Eigen::Dynamic && - std::is_default_constructible<S>::value>; - // Otherwise, if there is a two-index constructor, assume it is (outer,inner) like - // Eigen::Stride, and use it: - template <typename S> using stride_ctor_dual = bool_constant< - !stride_ctor_default<S>::value && std::is_constructible<S, EigenIndex, EigenIndex>::value>; - // Otherwise, if there is a one-index constructor, and just one of the strides is dynamic, use - // it (passing whichever stride is dynamic). - template <typename S> using stride_ctor_outer = bool_constant< - !any_of<stride_ctor_default<S>, stride_ctor_dual<S>>::value && - S::OuterStrideAtCompileTime == Eigen::Dynamic && S::InnerStrideAtCompileTime != Eigen::Dynamic && - std::is_constructible<S, EigenIndex>::value>; - template <typename S> using stride_ctor_inner = bool_constant< - !any_of<stride_ctor_default<S>, stride_ctor_dual<S>>::value && - S::InnerStrideAtCompileTime == Eigen::Dynamic && S::OuterStrideAtCompileTime != Eigen::Dynamic && - std::is_constructible<S, EigenIndex>::value>; - - template <typename S = StrideType, enable_if_t<stride_ctor_default<S>::value, int> = 0> - static S make_stride(EigenIndex, EigenIndex) { return S(); } - template <typename S = StrideType, enable_if_t<stride_ctor_dual<S>::value, int> = 0> - static S make_stride(EigenIndex outer, EigenIndex inner) { return S(outer, inner); } - template <typename S = StrideType, enable_if_t<stride_ctor_outer<S>::value, int> = 0> - static S make_stride(EigenIndex outer, EigenIndex) { return S(outer); } - template <typename S = StrideType, enable_if_t<stride_ctor_inner<S>::value, int> = 0> - static S make_stride(EigenIndex, EigenIndex inner) { return S(inner); } - -}; - -// type_caster for special matrix types (e.g. DiagonalMatrix), which are EigenBase, but not -// EigenDense (i.e. they don't have a data(), at least not with the usual matrix layout). -// load() is not supported, but we can cast them into the python domain by first copying to a -// regular Eigen::Matrix, then casting that. -template <typename Type> -struct type_caster<Type, enable_if_t<is_eigen_other<Type>::value>> { -protected: - using Matrix = Eigen::Matrix<typename Type::Scalar, Type::RowsAtCompileTime, Type::ColsAtCompileTime>; - using props = EigenProps<Matrix>; -public: - static handle cast(const Type &src, return_value_policy /* policy */, handle /* parent */) { - handle h = eigen_encapsulate<props>(new Matrix(src)); - return h; - } - static handle cast(const Type *src, return_value_policy policy, handle parent) { return cast(*src, policy, parent); } - - static constexpr auto name = props::descriptor; - - // Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return - // types but not bound arguments). We still provide them (with an explicitly delete) so that - // you end up here if you try anyway. - bool load(handle, bool) = delete; - operator Type() = delete; - template <typename> using cast_op_type = Type; -}; - -template<typename Type> -struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> { - typedef typename Type::Scalar Scalar; - typedef remove_reference_t<decltype(*std::declval<Type>().outerIndexPtr())> StorageIndex; - typedef typename Type::Index Index; - static constexpr bool rowMajor = Type::IsRowMajor; - - bool load(handle src, bool) { - if (!src) - return false; - - auto obj = reinterpret_borrow<object>(src); - object sparse_module = module::import("scipy.sparse"); - object matrix_type = sparse_module.attr( - rowMajor ? "csr_matrix" : "csc_matrix"); - - if (!obj.get_type().is(matrix_type)) { - try { - obj = matrix_type(obj); - } catch (const error_already_set &) { - return false; - } - } - - auto values = array_t<Scalar>((object) obj.attr("data")); - auto innerIndices = array_t<StorageIndex>((object) obj.attr("indices")); - auto outerIndices = array_t<StorageIndex>((object) obj.attr("indptr")); - auto shape = pybind11::tuple((pybind11::object) obj.attr("shape")); - auto nnz = obj.attr("nnz").cast<Index>(); - - if (!values || !innerIndices || !outerIndices) - return false; - - value = Eigen::MappedSparseMatrix<Scalar, Type::Flags, StorageIndex>( - shape[0].cast<Index>(), shape[1].cast<Index>(), nnz, - outerIndices.mutable_data(), innerIndices.mutable_data(), values.mutable_data()); - - return true; - } - - static handle cast(const Type &src, return_value_policy /* policy */, handle /* parent */) { - const_cast<Type&>(src).makeCompressed(); - - object matrix_type = module::import("scipy.sparse").attr( - rowMajor ? "csr_matrix" : "csc_matrix"); - - array data(src.nonZeros(), src.valuePtr()); - array outerIndices((rowMajor ? src.rows() : src.cols()) + 1, src.outerIndexPtr()); - array innerIndices(src.nonZeros(), src.innerIndexPtr()); - - return matrix_type( - std::make_tuple(data, innerIndices, outerIndices), - std::make_pair(src.rows(), src.cols()) - ).release(); - } - - PYBIND11_TYPE_CASTER(Type, _<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[", "scipy.sparse.csc_matrix[") - + npy_format_descriptor<Scalar>::name + _("]")); -}; - -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) - -#if defined(__GNUG__) || defined(__clang__) -# pragma GCC diagnostic pop -#elif defined(_MSC_VER) -# pragma warning(pop) -#endif diff --git a/external/pybind11/include/pybind11/embed.h b/external/pybind11/include/pybind11/embed.h deleted file mode 100644 index f814c783..00000000 --- a/external/pybind11/include/pybind11/embed.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - pybind11/embed.h: Support for embedding the interpreter - - Copyright (c) 2017 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" -#include "eval.h" - -#if defined(PYPY_VERSION) -# error Embedding the interpreter is not supported with PyPy -#endif - -#if PY_MAJOR_VERSION >= 3 -# define PYBIND11_EMBEDDED_MODULE_IMPL(name) \ - extern "C" PyObject *pybind11_init_impl_##name(); \ - extern "C" PyObject *pybind11_init_impl_##name() { \ - return pybind11_init_wrapper_##name(); \ - } -#else -# define PYBIND11_EMBEDDED_MODULE_IMPL(name) \ - extern "C" void pybind11_init_impl_##name(); \ - extern "C" void pybind11_init_impl_##name() { \ - pybind11_init_wrapper_##name(); \ - } -#endif - -/** \rst - Add a new module to the table of builtins for the interpreter. Must be - defined in global scope. The first macro parameter is the name of the - module (without quotes). The second parameter is the variable which will - be used as the interface to add functions and classes to the module. - - .. code-block:: cpp - - PYBIND11_EMBEDDED_MODULE(example, m) { - // ... initialize functions and classes here - m.def("foo", []() { - return "Hello, World!"; - }); - } - \endrst */ -#define PYBIND11_EMBEDDED_MODULE(name, variable) \ - static void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &); \ - static PyObject PYBIND11_CONCAT(*pybind11_init_wrapper_, name)() { \ - auto m = pybind11::module(PYBIND11_TOSTRING(name)); \ - try { \ - PYBIND11_CONCAT(pybind11_init_, name)(m); \ - return m.ptr(); \ - } catch (pybind11::error_already_set &e) { \ - PyErr_SetString(PyExc_ImportError, e.what()); \ - return nullptr; \ - } catch (const std::exception &e) { \ - PyErr_SetString(PyExc_ImportError, e.what()); \ - return nullptr; \ - } \ - } \ - PYBIND11_EMBEDDED_MODULE_IMPL(name) \ - pybind11::detail::embedded_module name(PYBIND11_TOSTRING(name), \ - PYBIND11_CONCAT(pybind11_init_impl_, name)); \ - void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable) - - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -/// Python 2.7/3.x compatible version of `PyImport_AppendInittab` and error checks. -struct embedded_module { -#if PY_MAJOR_VERSION >= 3 - using init_t = PyObject *(*)(); -#else - using init_t = void (*)(); -#endif - embedded_module(const char *name, init_t init) { - if (Py_IsInitialized()) - pybind11_fail("Can't add new modules after the interpreter has been initialized"); - - auto result = PyImport_AppendInittab(name, init); - if (result == -1) - pybind11_fail("Insufficient memory to add a new module"); - } -}; - -NAMESPACE_END(detail) - -/** \rst - Initialize the Python interpreter. No other pybind11 or CPython API functions can be - called before this is done; with the exception of `PYBIND11_EMBEDDED_MODULE`. The - optional parameter can be used to skip the registration of signal handlers (see the - `Python documentation`_ for details). Calling this function again after the interpreter - has already been initialized is a fatal error. - - If initializing the Python interpreter fails, then the program is terminated. (This - is controlled by the CPython runtime and is an exception to pybind11's normal behavior - of throwing exceptions on errors.) - - .. _Python documentation: https://docs.python.org/3/c-api/init.html#c.Py_InitializeEx - \endrst */ -inline void initialize_interpreter(bool init_signal_handlers = true) { - if (Py_IsInitialized()) - pybind11_fail("The interpreter is already running"); - - Py_InitializeEx(init_signal_handlers ? 1 : 0); - - // Make .py files in the working directory available by default - module::import("sys").attr("path").cast<list>().append("."); -} - -/** \rst - Shut down the Python interpreter. No pybind11 or CPython API functions can be called - after this. In addition, pybind11 objects must not outlive the interpreter: - - .. code-block:: cpp - - { // BAD - py::initialize_interpreter(); - auto hello = py::str("Hello, World!"); - py::finalize_interpreter(); - } // <-- BOOM, hello's destructor is called after interpreter shutdown - - { // GOOD - py::initialize_interpreter(); - { // scoped - auto hello = py::str("Hello, World!"); - } // <-- OK, hello is cleaned up properly - py::finalize_interpreter(); - } - - { // BETTER - py::scoped_interpreter guard{}; - auto hello = py::str("Hello, World!"); - } - - .. warning:: - - The interpreter can be restarted by calling `initialize_interpreter` again. - Modules created using pybind11 can be safely re-initialized. However, Python - itself cannot completely unload binary extension modules and there are several - caveats with regard to interpreter restarting. All the details can be found - in the CPython documentation. In short, not all interpreter memory may be - freed, either due to reference cycles or user-created global data. - - \endrst */ -inline void finalize_interpreter() { - handle builtins(PyEval_GetBuiltins()); - const char *id = PYBIND11_INTERNALS_ID; - - // Get the internals pointer (without creating it if it doesn't exist). It's possible for the - // internals to be created during Py_Finalize() (e.g. if a py::capsule calls `get_internals()` - // during destruction), so we get the pointer-pointer here and check it after Py_Finalize(). - detail::internals **internals_ptr_ptr = detail::get_internals_pp(); - // It could also be stashed in builtins, so look there too: - if (builtins.contains(id) && isinstance<capsule>(builtins[id])) - internals_ptr_ptr = capsule(builtins[id]); - - Py_Finalize(); - - if (internals_ptr_ptr) { - delete *internals_ptr_ptr; - *internals_ptr_ptr = nullptr; - } -} - -/** \rst - Scope guard version of `initialize_interpreter` and `finalize_interpreter`. - This a move-only guard and only a single instance can exist. - - .. code-block:: cpp - - #include <pybind11/embed.h> - - int main() { - py::scoped_interpreter guard{}; - py::print(Hello, World!); - } // <-- interpreter shutdown - \endrst */ -class scoped_interpreter { -public: - scoped_interpreter(bool init_signal_handlers = true) { - initialize_interpreter(init_signal_handlers); - } - - scoped_interpreter(const scoped_interpreter &) = delete; - scoped_interpreter(scoped_interpreter &&other) noexcept { other.is_valid = false; } - scoped_interpreter &operator=(const scoped_interpreter &) = delete; - scoped_interpreter &operator=(scoped_interpreter &&) = delete; - - ~scoped_interpreter() { - if (is_valid) - finalize_interpreter(); - } - -private: - bool is_valid = true; -}; - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/eval.h b/external/pybind11/include/pybind11/eval.h deleted file mode 100644 index ea85ba1d..00000000 --- a/external/pybind11/include/pybind11/eval.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - pybind11/exec.h: Support for evaluating Python expressions and statements - from strings and files - - Copyright (c) 2016 Klemens Morgenstern <klemens.morgenstern@ed-chemnitz.de> and - Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -enum eval_mode { - /// Evaluate a string containing an isolated expression - eval_expr, - - /// Evaluate a string containing a single statement. Returns \c none - eval_single_statement, - - /// Evaluate a string containing a sequence of statement. Returns \c none - eval_statements -}; - -template <eval_mode mode = eval_expr> -object eval(str expr, object global = globals(), object local = object()) { - if (!local) - local = global; - - /* PyRun_String does not accept a PyObject / encoding specifier, - this seems to be the only alternative */ - std::string buffer = "# -*- coding: utf-8 -*-\n" + (std::string) expr; - - int start; - switch (mode) { - case eval_expr: start = Py_eval_input; break; - case eval_single_statement: start = Py_single_input; break; - case eval_statements: start = Py_file_input; break; - default: pybind11_fail("invalid evaluation mode"); - } - - PyObject *result = PyRun_String(buffer.c_str(), start, global.ptr(), local.ptr()); - if (!result) - throw error_already_set(); - return reinterpret_steal<object>(result); -} - -template <eval_mode mode = eval_expr, size_t N> -object eval(const char (&s)[N], object global = globals(), object local = object()) { - /* Support raw string literals by removing common leading whitespace */ - auto expr = (s[0] == '\n') ? str(module::import("textwrap").attr("dedent")(s)) - : str(s); - return eval<mode>(expr, global, local); -} - -inline void exec(str expr, object global = globals(), object local = object()) { - eval<eval_statements>(expr, global, local); -} - -template <size_t N> -void exec(const char (&s)[N], object global = globals(), object local = object()) { - eval<eval_statements>(s, global, local); -} - -template <eval_mode mode = eval_statements> -object eval_file(str fname, object global = globals(), object local = object()) { - if (!local) - local = global; - - int start; - switch (mode) { - case eval_expr: start = Py_eval_input; break; - case eval_single_statement: start = Py_single_input; break; - case eval_statements: start = Py_file_input; break; - default: pybind11_fail("invalid evaluation mode"); - } - - int closeFile = 1; - std::string fname_str = (std::string) fname; -#if PY_VERSION_HEX >= 0x03040000 - FILE *f = _Py_fopen_obj(fname.ptr(), "r"); -#elif PY_VERSION_HEX >= 0x03000000 - FILE *f = _Py_fopen(fname.ptr(), "r"); -#else - /* No unicode support in open() :( */ - auto fobj = reinterpret_steal<object>(PyFile_FromString( - const_cast<char *>(fname_str.c_str()), - const_cast<char*>("r"))); - FILE *f = nullptr; - if (fobj) - f = PyFile_AsFile(fobj.ptr()); - closeFile = 0; -#endif - if (!f) { - PyErr_Clear(); - pybind11_fail("File \"" + fname_str + "\" could not be opened!"); - } - -#if PY_VERSION_HEX < 0x03000000 && defined(PYPY_VERSION) - PyObject *result = PyRun_File(f, fname_str.c_str(), start, global.ptr(), - local.ptr()); - (void) closeFile; -#else - PyObject *result = PyRun_FileEx(f, fname_str.c_str(), start, global.ptr(), - local.ptr(), closeFile); -#endif - - if (!result) - throw error_already_set(); - return reinterpret_steal<object>(result); -} - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/functional.h b/external/pybind11/include/pybind11/functional.h deleted file mode 100644 index f8bda648..00000000 --- a/external/pybind11/include/pybind11/functional.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - pybind11/functional.h: std::function<> support - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" -#include <functional> - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -template <typename Return, typename... Args> -struct type_caster<std::function<Return(Args...)>> { - using type = std::function<Return(Args...)>; - using retval_type = conditional_t<std::is_same<Return, void>::value, void_type, Return>; - using function_type = Return (*) (Args...); - -public: - bool load(handle src, bool convert) { - if (src.is_none()) { - // Defer accepting None to other overloads (if we aren't in convert mode): - if (!convert) return false; - return true; - } - - if (!isinstance<function>(src)) - return false; - - auto func = reinterpret_borrow<function>(src); - - /* - When passing a C++ function as an argument to another C++ - function via Python, every function call would normally involve - a full C++ -> Python -> C++ roundtrip, which can be prohibitive. - Here, we try to at least detect the case where the function is - stateless (i.e. function pointer or lambda function without - captured variables), in which case the roundtrip can be avoided. - */ - if (auto cfunc = func.cpp_function()) { - auto c = reinterpret_borrow<capsule>(PyCFunction_GET_SELF(cfunc.ptr())); - auto rec = (function_record *) c; - - if (rec && rec->is_stateless && - same_type(typeid(function_type), *reinterpret_cast<const std::type_info *>(rec->data[1]))) { - struct capture { function_type f; }; - value = ((capture *) &rec->data)->f; - return true; - } - } - - // ensure GIL is held during functor destruction - struct func_handle { - function f; - func_handle(function&& f_) : f(std::move(f_)) {} - func_handle(const func_handle&) = default; - ~func_handle() { - gil_scoped_acquire acq; - function kill_f(std::move(f)); - } - }; - - // to emulate 'move initialization capture' in C++11 - struct func_wrapper { - func_handle hfunc; - func_wrapper(func_handle&& hf): hfunc(std::move(hf)) {} - Return operator()(Args... args) const { - gil_scoped_acquire acq; - object retval(hfunc.f(std::forward<Args>(args)...)); - /* Visual studio 2015 parser issue: need parentheses around this expression */ - return (retval.template cast<Return>()); - } - }; - - value = func_wrapper(func_handle(std::move(func))); - return true; - } - - template <typename Func> - static handle cast(Func &&f_, return_value_policy policy, handle /* parent */) { - if (!f_) - return none().inc_ref(); - - auto result = f_.template target<function_type>(); - if (result) - return cpp_function(*result, policy).release(); - else - return cpp_function(std::forward<Func>(f_), policy).release(); - } - - PYBIND11_TYPE_CASTER(type, _("Callable[[") + concat(make_caster<Args>::name...) + _("], ") - + make_caster<retval_type>::name + _("]")); -}; - -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/iostream.h b/external/pybind11/include/pybind11/iostream.h deleted file mode 100644 index c43b7c93..00000000 --- a/external/pybind11/include/pybind11/iostream.h +++ /dev/null @@ -1,209 +0,0 @@ -/* - pybind11/iostream.h -- Tools to assist with redirecting cout and cerr to Python - - Copyright (c) 2017 Henry F. Schreiner - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" - -#include <streambuf> -#include <ostream> -#include <string> -#include <memory> -#include <iostream> - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -// Buffer that writes to Python instead of C++ -class pythonbuf : public std::streambuf { -private: - using traits_type = std::streambuf::traits_type; - - const size_t buf_size; - std::unique_ptr<char[]> d_buffer; - object pywrite; - object pyflush; - - int overflow(int c) { - if (!traits_type::eq_int_type(c, traits_type::eof())) { - *pptr() = traits_type::to_char_type(c); - pbump(1); - } - return sync() == 0 ? traits_type::not_eof(c) : traits_type::eof(); - } - - int sync() { - if (pbase() != pptr()) { - // This subtraction cannot be negative, so dropping the sign - str line(pbase(), static_cast<size_t>(pptr() - pbase())); - - { - gil_scoped_acquire tmp; - pywrite(line); - pyflush(); - } - - setp(pbase(), epptr()); - } - return 0; - } - -public: - - pythonbuf(object pyostream, size_t buffer_size = 1024) - : buf_size(buffer_size), - d_buffer(new char[buf_size]), - pywrite(pyostream.attr("write")), - pyflush(pyostream.attr("flush")) { - setp(d_buffer.get(), d_buffer.get() + buf_size - 1); - } - - pythonbuf(pythonbuf&&) = default; - - /// Sync before destroy - ~pythonbuf() { - sync(); - } -}; - -NAMESPACE_END(detail) - - -/** \rst - This a move-only guard that redirects output. - - .. code-block:: cpp - - #include <pybind11/iostream.h> - - ... - - { - py::scoped_ostream_redirect output; - std::cout << "Hello, World!"; // Python stdout - } // <-- return std::cout to normal - - You can explicitly pass the c++ stream and the python object, - for example to guard stderr instead. - - .. code-block:: cpp - - { - py::scoped_ostream_redirect output{std::cerr, py::module::import("sys").attr("stderr")}; - std::cerr << "Hello, World!"; - } - \endrst */ -class scoped_ostream_redirect { -protected: - std::streambuf *old; - std::ostream &costream; - detail::pythonbuf buffer; - -public: - scoped_ostream_redirect( - std::ostream &costream = std::cout, - object pyostream = module::import("sys").attr("stdout")) - : costream(costream), buffer(pyostream) { - old = costream.rdbuf(&buffer); - } - - ~scoped_ostream_redirect() { - costream.rdbuf(old); - } - - scoped_ostream_redirect(const scoped_ostream_redirect &) = delete; - scoped_ostream_redirect(scoped_ostream_redirect &&other) = default; - scoped_ostream_redirect &operator=(const scoped_ostream_redirect &) = delete; - scoped_ostream_redirect &operator=(scoped_ostream_redirect &&) = delete; -}; - - -/** \rst - Like `scoped_ostream_redirect`, but redirects cerr by default. This class - is provided primary to make ``py::call_guard`` easier to make. - - .. code-block:: cpp - - m.def("noisy_func", &noisy_func, - py::call_guard<scoped_ostream_redirect, - scoped_estream_redirect>()); - -\endrst */ -class scoped_estream_redirect : public scoped_ostream_redirect { -public: - scoped_estream_redirect( - std::ostream &costream = std::cerr, - object pyostream = module::import("sys").attr("stderr")) - : scoped_ostream_redirect(costream,pyostream) {} -}; - - -NAMESPACE_BEGIN(detail) - -// Class to redirect output as a context manager. C++ backend. -class OstreamRedirect { - bool do_stdout_; - bool do_stderr_; - std::unique_ptr<scoped_ostream_redirect> redirect_stdout; - std::unique_ptr<scoped_estream_redirect> redirect_stderr; - -public: - OstreamRedirect(bool do_stdout = true, bool do_stderr = true) - : do_stdout_(do_stdout), do_stderr_(do_stderr) {} - - void enter() { - if (do_stdout_) - redirect_stdout.reset(new scoped_ostream_redirect()); - if (do_stderr_) - redirect_stderr.reset(new scoped_estream_redirect()); - } - - void exit() { - redirect_stdout.reset(); - redirect_stderr.reset(); - } -}; - -NAMESPACE_END(detail) - -/** \rst - This is a helper function to add a C++ redirect context manager to Python - instead of using a C++ guard. To use it, add the following to your binding code: - - .. code-block:: cpp - - #include <pybind11/iostream.h> - - ... - - py::add_ostream_redirect(m, "ostream_redirect"); - - You now have a Python context manager that redirects your output: - - .. code-block:: python - - with m.ostream_redirect(): - m.print_to_cout_function() - - This manager can optionally be told which streams to operate on: - - .. code-block:: python - - with m.ostream_redirect(stdout=true, stderr=true): - m.noisy_function_with_error_printing() - - \endrst */ -inline class_<detail::OstreamRedirect> add_ostream_redirect(module m, std::string name = "ostream_redirect") { - return class_<detail::OstreamRedirect>(m, name.c_str(), module_local()) - .def(init<bool,bool>(), arg("stdout")=true, arg("stderr")=true) - .def("__enter__", &detail::OstreamRedirect::enter) - .def("__exit__", [](detail::OstreamRedirect &self_, args) { self_.exit(); }); -} - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/numpy.h b/external/pybind11/include/pybind11/numpy.h deleted file mode 100644 index ba41a223..00000000 --- a/external/pybind11/include/pybind11/numpy.h +++ /dev/null @@ -1,1642 +0,0 @@ -/* - pybind11/numpy.h: Basic NumPy support, vectorize() wrapper - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" -#include "complex.h" -#include <numeric> -#include <algorithm> -#include <array> -#include <cstdint> -#include <cstdlib> -#include <cstring> -#include <sstream> -#include <string> -#include <functional> -#include <utility> -#include <vector> -#include <typeindex> - -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant -#endif - -/* This will be true on all flat address space platforms and allows us to reduce the - whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size - and dimension types (e.g. shape, strides, indexing), instead of inflicting this - upon the library user. */ -static_assert(sizeof(ssize_t) == sizeof(Py_intptr_t), "ssize_t != Py_intptr_t"); - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -class array; // Forward declaration - -NAMESPACE_BEGIN(detail) -template <typename type, typename SFINAE = void> struct npy_format_descriptor; - -struct PyArrayDescr_Proxy { - PyObject_HEAD - PyObject *typeobj; - char kind; - char type; - char byteorder; - char flags; - int type_num; - int elsize; - int alignment; - char *subarray; - PyObject *fields; - PyObject *names; -}; - -struct PyArray_Proxy { - PyObject_HEAD - char *data; - int nd; - ssize_t *dimensions; - ssize_t *strides; - PyObject *base; - PyObject *descr; - int flags; -}; - -struct PyVoidScalarObject_Proxy { - PyObject_VAR_HEAD - char *obval; - PyArrayDescr_Proxy *descr; - int flags; - PyObject *base; -}; - -struct numpy_type_info { - PyObject* dtype_ptr; - std::string format_str; -}; - -struct numpy_internals { - std::unordered_map<std::type_index, numpy_type_info> registered_dtypes; - - numpy_type_info *get_type_info(const std::type_info& tinfo, bool throw_if_missing = true) { - auto it = registered_dtypes.find(std::type_index(tinfo)); - if (it != registered_dtypes.end()) - return &(it->second); - if (throw_if_missing) - pybind11_fail(std::string("NumPy type info missing for ") + tinfo.name()); - return nullptr; - } - - template<typename T> numpy_type_info *get_type_info(bool throw_if_missing = true) { - return get_type_info(typeid(typename std::remove_cv<T>::type), throw_if_missing); - } -}; - -inline PYBIND11_NOINLINE void load_numpy_internals(numpy_internals* &ptr) { - ptr = &get_or_create_shared_data<numpy_internals>("_numpy_internals"); -} - -inline numpy_internals& get_numpy_internals() { - static numpy_internals* ptr = nullptr; - if (!ptr) - load_numpy_internals(ptr); - return *ptr; -} - -template <typename T> struct same_size { - template <typename U> using as = bool_constant<sizeof(T) == sizeof(U)>; -}; - -template <typename Concrete> constexpr int platform_lookup() { return -1; } - -// Lookup a type according to its size, and return a value corresponding to the NumPy typenum. -template <typename Concrete, typename T, typename... Ts, typename... Ints> -constexpr int platform_lookup(int I, Ints... Is) { - return sizeof(Concrete) == sizeof(T) ? I : platform_lookup<Concrete, Ts...>(Is...); -} - -struct npy_api { - enum constants { - NPY_ARRAY_C_CONTIGUOUS_ = 0x0001, - NPY_ARRAY_F_CONTIGUOUS_ = 0x0002, - NPY_ARRAY_OWNDATA_ = 0x0004, - NPY_ARRAY_FORCECAST_ = 0x0010, - NPY_ARRAY_ENSUREARRAY_ = 0x0040, - NPY_ARRAY_ALIGNED_ = 0x0100, - NPY_ARRAY_WRITEABLE_ = 0x0400, - NPY_BOOL_ = 0, - NPY_BYTE_, NPY_UBYTE_, - NPY_SHORT_, NPY_USHORT_, - NPY_INT_, NPY_UINT_, - NPY_LONG_, NPY_ULONG_, - NPY_LONGLONG_, NPY_ULONGLONG_, - NPY_FLOAT_, NPY_DOUBLE_, NPY_LONGDOUBLE_, - NPY_CFLOAT_, NPY_CDOUBLE_, NPY_CLONGDOUBLE_, - NPY_OBJECT_ = 17, - NPY_STRING_, NPY_UNICODE_, NPY_VOID_, - // Platform-dependent normalization - NPY_INT8_ = NPY_BYTE_, - NPY_UINT8_ = NPY_UBYTE_, - NPY_INT16_ = NPY_SHORT_, - NPY_UINT16_ = NPY_USHORT_, - // `npy_common.h` defines the integer aliases. In order, it checks: - // NPY_BITSOF_LONG, NPY_BITSOF_LONGLONG, NPY_BITSOF_INT, NPY_BITSOF_SHORT, NPY_BITSOF_CHAR - // and assigns the alias to the first matching size, so we should check in this order. - NPY_INT32_ = platform_lookup<std::int32_t, long, int, short>( - NPY_LONG_, NPY_INT_, NPY_SHORT_), - NPY_UINT32_ = platform_lookup<std::uint32_t, unsigned long, unsigned int, unsigned short>( - NPY_ULONG_, NPY_UINT_, NPY_USHORT_), - NPY_INT64_ = platform_lookup<std::int64_t, long, long long, int>( - NPY_LONG_, NPY_LONGLONG_, NPY_INT_), - NPY_UINT64_ = platform_lookup<std::uint64_t, unsigned long, unsigned long long, unsigned int>( - NPY_ULONG_, NPY_ULONGLONG_, NPY_UINT_), - }; - - typedef struct { - Py_intptr_t *ptr; - int len; - } PyArray_Dims; - - static npy_api& get() { - static npy_api api = lookup(); - return api; - } - - bool PyArray_Check_(PyObject *obj) const { - return (bool) PyObject_TypeCheck(obj, PyArray_Type_); - } - bool PyArrayDescr_Check_(PyObject *obj) const { - return (bool) PyObject_TypeCheck(obj, PyArrayDescr_Type_); - } - - unsigned int (*PyArray_GetNDArrayCFeatureVersion_)(); - PyObject *(*PyArray_DescrFromType_)(int); - PyObject *(*PyArray_NewFromDescr_) - (PyTypeObject *, PyObject *, int, Py_intptr_t *, - Py_intptr_t *, void *, int, PyObject *); - PyObject *(*PyArray_DescrNewFromType_)(int); - int (*PyArray_CopyInto_)(PyObject *, PyObject *); - PyObject *(*PyArray_NewCopy_)(PyObject *, int); - PyTypeObject *PyArray_Type_; - PyTypeObject *PyVoidArrType_Type_; - PyTypeObject *PyArrayDescr_Type_; - PyObject *(*PyArray_DescrFromScalar_)(PyObject *); - PyObject *(*PyArray_FromAny_) (PyObject *, PyObject *, int, int, int, PyObject *); - int (*PyArray_DescrConverter_) (PyObject *, PyObject **); - bool (*PyArray_EquivTypes_) (PyObject *, PyObject *); - int (*PyArray_GetArrayParamsFromObject_)(PyObject *, PyObject *, char, PyObject **, int *, - Py_ssize_t *, PyObject **, PyObject *); - PyObject *(*PyArray_Squeeze_)(PyObject *); - int (*PyArray_SetBaseObject_)(PyObject *, PyObject *); - PyObject* (*PyArray_Resize_)(PyObject*, PyArray_Dims*, int, int); -private: - enum functions { - API_PyArray_GetNDArrayCFeatureVersion = 211, - API_PyArray_Type = 2, - API_PyArrayDescr_Type = 3, - API_PyVoidArrType_Type = 39, - API_PyArray_DescrFromType = 45, - API_PyArray_DescrFromScalar = 57, - API_PyArray_FromAny = 69, - API_PyArray_Resize = 80, - API_PyArray_CopyInto = 82, - API_PyArray_NewCopy = 85, - API_PyArray_NewFromDescr = 94, - API_PyArray_DescrNewFromType = 9, - API_PyArray_DescrConverter = 174, - API_PyArray_EquivTypes = 182, - API_PyArray_GetArrayParamsFromObject = 278, - API_PyArray_Squeeze = 136, - API_PyArray_SetBaseObject = 282 - }; - - static npy_api lookup() { - module m = module::import("numpy.core.multiarray"); - auto c = m.attr("_ARRAY_API"); -#if PY_MAJOR_VERSION >= 3 - void **api_ptr = (void **) PyCapsule_GetPointer(c.ptr(), NULL); -#else - void **api_ptr = (void **) PyCObject_AsVoidPtr(c.ptr()); -#endif - npy_api api; -#define DECL_NPY_API(Func) api.Func##_ = (decltype(api.Func##_)) api_ptr[API_##Func]; - DECL_NPY_API(PyArray_GetNDArrayCFeatureVersion); - if (api.PyArray_GetNDArrayCFeatureVersion_() < 0x7) - pybind11_fail("pybind11 numpy support requires numpy >= 1.7.0"); - DECL_NPY_API(PyArray_Type); - DECL_NPY_API(PyVoidArrType_Type); - DECL_NPY_API(PyArrayDescr_Type); - DECL_NPY_API(PyArray_DescrFromType); - DECL_NPY_API(PyArray_DescrFromScalar); - DECL_NPY_API(PyArray_FromAny); - DECL_NPY_API(PyArray_Resize); - DECL_NPY_API(PyArray_CopyInto); - DECL_NPY_API(PyArray_NewCopy); - DECL_NPY_API(PyArray_NewFromDescr); - DECL_NPY_API(PyArray_DescrNewFromType); - DECL_NPY_API(PyArray_DescrConverter); - DECL_NPY_API(PyArray_EquivTypes); - DECL_NPY_API(PyArray_GetArrayParamsFromObject); - DECL_NPY_API(PyArray_Squeeze); - DECL_NPY_API(PyArray_SetBaseObject); -#undef DECL_NPY_API - return api; - } -}; - -inline PyArray_Proxy* array_proxy(void* ptr) { - return reinterpret_cast<PyArray_Proxy*>(ptr); -} - -inline const PyArray_Proxy* array_proxy(const void* ptr) { - return reinterpret_cast<const PyArray_Proxy*>(ptr); -} - -inline PyArrayDescr_Proxy* array_descriptor_proxy(PyObject* ptr) { - return reinterpret_cast<PyArrayDescr_Proxy*>(ptr); -} - -inline const PyArrayDescr_Proxy* array_descriptor_proxy(const PyObject* ptr) { - return reinterpret_cast<const PyArrayDescr_Proxy*>(ptr); -} - -inline bool check_flags(const void* ptr, int flag) { - return (flag == (array_proxy(ptr)->flags & flag)); -} - -template <typename T> struct is_std_array : std::false_type { }; -template <typename T, size_t N> struct is_std_array<std::array<T, N>> : std::true_type { }; -template <typename T> struct is_complex : std::false_type { }; -template <typename T> struct is_complex<std::complex<T>> : std::true_type { }; - -template <typename T> struct array_info_scalar { - typedef T type; - static constexpr bool is_array = false; - static constexpr bool is_empty = false; - static constexpr auto extents = _(""); - static void append_extents(list& /* shape */) { } -}; -// Computes underlying type and a comma-separated list of extents for array -// types (any mix of std::array and built-in arrays). An array of char is -// treated as scalar because it gets special handling. -template <typename T> struct array_info : array_info_scalar<T> { }; -template <typename T, size_t N> struct array_info<std::array<T, N>> { - using type = typename array_info<T>::type; - static constexpr bool is_array = true; - static constexpr bool is_empty = (N == 0) || array_info<T>::is_empty; - static constexpr size_t extent = N; - - // appends the extents to shape - static void append_extents(list& shape) { - shape.append(N); - array_info<T>::append_extents(shape); - } - - static constexpr auto extents = _<array_info<T>::is_array>( - concat(_<N>(), array_info<T>::extents), _<N>() - ); -}; -// For numpy we have special handling for arrays of characters, so we don't include -// the size in the array extents. -template <size_t N> struct array_info<char[N]> : array_info_scalar<char[N]> { }; -template <size_t N> struct array_info<std::array<char, N>> : array_info_scalar<std::array<char, N>> { }; -template <typename T, size_t N> struct array_info<T[N]> : array_info<std::array<T, N>> { }; -template <typename T> using remove_all_extents_t = typename array_info<T>::type; - -template <typename T> using is_pod_struct = all_of< - std::is_standard_layout<T>, // since we're accessing directly in memory we need a standard layout type -#if !defined(__GNUG__) || defined(_LIBCPP_VERSION) || defined(_GLIBCXX_USE_CXX11_ABI) - // _GLIBCXX_USE_CXX11_ABI indicates that we're using libstdc++ from GCC 5 or newer, independent - // of the actual compiler (Clang can also use libstdc++, but it always defines __GNUC__ == 4). - std::is_trivially_copyable<T>, -#else - // GCC 4 doesn't implement is_trivially_copyable, so approximate it - std::is_trivially_destructible<T>, - satisfies_any_of<T, std::has_trivial_copy_constructor, std::has_trivial_copy_assign>, -#endif - satisfies_none_of<T, std::is_reference, std::is_array, is_std_array, std::is_arithmetic, is_complex, std::is_enum> ->; - -template <ssize_t Dim = 0, typename Strides> ssize_t byte_offset_unsafe(const Strides &) { return 0; } -template <ssize_t Dim = 0, typename Strides, typename... Ix> -ssize_t byte_offset_unsafe(const Strides &strides, ssize_t i, Ix... index) { - return i * strides[Dim] + byte_offset_unsafe<Dim + 1>(strides, index...); -} - -/** - * Proxy class providing unsafe, unchecked const access to array data. This is constructed through - * the `unchecked<T, N>()` method of `array` or the `unchecked<N>()` method of `array_t<T>`. `Dims` - * will be -1 for dimensions determined at runtime. - */ -template <typename T, ssize_t Dims> -class unchecked_reference { -protected: - static constexpr bool Dynamic = Dims < 0; - const unsigned char *data_; - // Storing the shape & strides in local variables (i.e. these arrays) allows the compiler to - // make large performance gains on big, nested loops, but requires compile-time dimensions - conditional_t<Dynamic, const ssize_t *, std::array<ssize_t, (size_t) Dims>> - shape_, strides_; - const ssize_t dims_; - - friend class pybind11::array; - // Constructor for compile-time dimensions: - template <bool Dyn = Dynamic> - unchecked_reference(const void *data, const ssize_t *shape, const ssize_t *strides, enable_if_t<!Dyn, ssize_t>) - : data_{reinterpret_cast<const unsigned char *>(data)}, dims_{Dims} { - for (size_t i = 0; i < (size_t) dims_; i++) { - shape_[i] = shape[i]; - strides_[i] = strides[i]; - } - } - // Constructor for runtime dimensions: - template <bool Dyn = Dynamic> - unchecked_reference(const void *data, const ssize_t *shape, const ssize_t *strides, enable_if_t<Dyn, ssize_t> dims) - : data_{reinterpret_cast<const unsigned char *>(data)}, shape_{shape}, strides_{strides}, dims_{dims} {} - -public: - /** - * Unchecked const reference access to data at the given indices. For a compile-time known - * number of dimensions, this requires the correct number of arguments; for run-time - * dimensionality, this is not checked (and so is up to the caller to use safely). - */ - template <typename... Ix> const T &operator()(Ix... index) const { - static_assert(ssize_t{sizeof...(Ix)} == Dims || Dynamic, - "Invalid number of indices for unchecked array reference"); - return *reinterpret_cast<const T *>(data_ + byte_offset_unsafe(strides_, ssize_t(index)...)); - } - /** - * Unchecked const reference access to data; this operator only participates if the reference - * is to a 1-dimensional array. When present, this is exactly equivalent to `obj(index)`. - */ - template <ssize_t D = Dims, typename = enable_if_t<D == 1 || Dynamic>> - const T &operator[](ssize_t index) const { return operator()(index); } - - /// Pointer access to the data at the given indices. - template <typename... Ix> const T *data(Ix... ix) const { return &operator()(ssize_t(ix)...); } - - /// Returns the item size, i.e. sizeof(T) - constexpr static ssize_t itemsize() { return sizeof(T); } - - /// Returns the shape (i.e. size) of dimension `dim` - ssize_t shape(ssize_t dim) const { return shape_[(size_t) dim]; } - - /// Returns the number of dimensions of the array - ssize_t ndim() const { return dims_; } - - /// Returns the total number of elements in the referenced array, i.e. the product of the shapes - template <bool Dyn = Dynamic> - enable_if_t<!Dyn, ssize_t> size() const { - return std::accumulate(shape_.begin(), shape_.end(), (ssize_t) 1, std::multiplies<ssize_t>()); - } - template <bool Dyn = Dynamic> - enable_if_t<Dyn, ssize_t> size() const { - return std::accumulate(shape_, shape_ + ndim(), (ssize_t) 1, std::multiplies<ssize_t>()); - } - - /// Returns the total number of bytes used by the referenced data. Note that the actual span in - /// memory may be larger if the referenced array has non-contiguous strides (e.g. for a slice). - ssize_t nbytes() const { - return size() * itemsize(); - } -}; - -template <typename T, ssize_t Dims> -class unchecked_mutable_reference : public unchecked_reference<T, Dims> { - friend class pybind11::array; - using ConstBase = unchecked_reference<T, Dims>; - using ConstBase::ConstBase; - using ConstBase::Dynamic; -public: - /// Mutable, unchecked access to data at the given indices. - template <typename... Ix> T& operator()(Ix... index) { - static_assert(ssize_t{sizeof...(Ix)} == Dims || Dynamic, - "Invalid number of indices for unchecked array reference"); - return const_cast<T &>(ConstBase::operator()(index...)); - } - /** - * Mutable, unchecked access data at the given index; this operator only participates if the - * reference is to a 1-dimensional array (or has runtime dimensions). When present, this is - * exactly equivalent to `obj(index)`. - */ - template <ssize_t D = Dims, typename = enable_if_t<D == 1 || Dynamic>> - T &operator[](ssize_t index) { return operator()(index); } - - /// Mutable pointer access to the data at the given indices. - template <typename... Ix> T *mutable_data(Ix... ix) { return &operator()(ssize_t(ix)...); } -}; - -template <typename T, ssize_t Dim> -struct type_caster<unchecked_reference<T, Dim>> { - static_assert(Dim == 0 && Dim > 0 /* always fail */, "unchecked array proxy object is not castable"); -}; -template <typename T, ssize_t Dim> -struct type_caster<unchecked_mutable_reference<T, Dim>> : type_caster<unchecked_reference<T, Dim>> {}; - -NAMESPACE_END(detail) - -class dtype : public object { -public: - PYBIND11_OBJECT_DEFAULT(dtype, object, detail::npy_api::get().PyArrayDescr_Check_); - - explicit dtype(const buffer_info &info) { - dtype descr(_dtype_from_pep3118()(PYBIND11_STR_TYPE(info.format))); - // If info.itemsize == 0, use the value calculated from the format string - m_ptr = descr.strip_padding(info.itemsize ? info.itemsize : descr.itemsize()).release().ptr(); - } - - explicit dtype(const std::string &format) { - m_ptr = from_args(pybind11::str(format)).release().ptr(); - } - - dtype(const char *format) : dtype(std::string(format)) { } - - dtype(list names, list formats, list offsets, ssize_t itemsize) { - dict args; - args["names"] = names; - args["formats"] = formats; - args["offsets"] = offsets; - args["itemsize"] = pybind11::int_(itemsize); - m_ptr = from_args(args).release().ptr(); - } - - /// This is essentially the same as calling numpy.dtype(args) in Python. - static dtype from_args(object args) { - PyObject *ptr = nullptr; - if (!detail::npy_api::get().PyArray_DescrConverter_(args.ptr(), &ptr) || !ptr) - throw error_already_set(); - return reinterpret_steal<dtype>(ptr); - } - - /// Return dtype associated with a C++ type. - template <typename T> static dtype of() { - return detail::npy_format_descriptor<typename std::remove_cv<T>::type>::dtype(); - } - - /// Size of the data type in bytes. - ssize_t itemsize() const { - return detail::array_descriptor_proxy(m_ptr)->elsize; - } - - /// Returns true for structured data types. - bool has_fields() const { - return detail::array_descriptor_proxy(m_ptr)->names != nullptr; - } - - /// Single-character type code. - char kind() const { - return detail::array_descriptor_proxy(m_ptr)->kind; - } - -private: - static object _dtype_from_pep3118() { - static PyObject *obj = module::import("numpy.core._internal") - .attr("_dtype_from_pep3118").cast<object>().release().ptr(); - return reinterpret_borrow<object>(obj); - } - - dtype strip_padding(ssize_t itemsize) { - // Recursively strip all void fields with empty names that are generated for - // padding fields (as of NumPy v1.11). - if (!has_fields()) - return *this; - - struct field_descr { PYBIND11_STR_TYPE name; object format; pybind11::int_ offset; }; - std::vector<field_descr> field_descriptors; - - for (auto field : attr("fields").attr("items")()) { - auto spec = field.cast<tuple>(); - auto name = spec[0].cast<pybind11::str>(); - auto format = spec[1].cast<tuple>()[0].cast<dtype>(); - auto offset = spec[1].cast<tuple>()[1].cast<pybind11::int_>(); - if (!len(name) && format.kind() == 'V') - continue; - field_descriptors.push_back({(PYBIND11_STR_TYPE) name, format.strip_padding(format.itemsize()), offset}); - } - - std::sort(field_descriptors.begin(), field_descriptors.end(), - [](const field_descr& a, const field_descr& b) { - return a.offset.cast<int>() < b.offset.cast<int>(); - }); - - list names, formats, offsets; - for (auto& descr : field_descriptors) { - names.append(descr.name); - formats.append(descr.format); - offsets.append(descr.offset); - } - return dtype(names, formats, offsets, itemsize); - } -}; - -class array : public buffer { -public: - PYBIND11_OBJECT_CVT(array, buffer, detail::npy_api::get().PyArray_Check_, raw_array) - - enum { - c_style = detail::npy_api::NPY_ARRAY_C_CONTIGUOUS_, - f_style = detail::npy_api::NPY_ARRAY_F_CONTIGUOUS_, - forcecast = detail::npy_api::NPY_ARRAY_FORCECAST_ - }; - - array() : array({{0}}, static_cast<const double *>(nullptr)) {} - - using ShapeContainer = detail::any_container<ssize_t>; - using StridesContainer = detail::any_container<ssize_t>; - - // Constructs an array taking shape/strides from arbitrary container types - array(const pybind11::dtype &dt, ShapeContainer shape, StridesContainer strides, - const void *ptr = nullptr, handle base = handle()) { - - if (strides->empty()) - *strides = c_strides(*shape, dt.itemsize()); - - auto ndim = shape->size(); - if (ndim != strides->size()) - pybind11_fail("NumPy: shape ndim doesn't match strides ndim"); - auto descr = dt; - - int flags = 0; - if (base && ptr) { - if (isinstance<array>(base)) - /* Copy flags from base (except ownership bit) */ - flags = reinterpret_borrow<array>(base).flags() & ~detail::npy_api::NPY_ARRAY_OWNDATA_; - else - /* Writable by default, easy to downgrade later on if needed */ - flags = detail::npy_api::NPY_ARRAY_WRITEABLE_; - } - - auto &api = detail::npy_api::get(); - auto tmp = reinterpret_steal<object>(api.PyArray_NewFromDescr_( - api.PyArray_Type_, descr.release().ptr(), (int) ndim, shape->data(), strides->data(), - const_cast<void *>(ptr), flags, nullptr)); - if (!tmp) - throw error_already_set(); - if (ptr) { - if (base) { - api.PyArray_SetBaseObject_(tmp.ptr(), base.inc_ref().ptr()); - } else { - tmp = reinterpret_steal<object>(api.PyArray_NewCopy_(tmp.ptr(), -1 /* any order */)); - } - } - m_ptr = tmp.release().ptr(); - } - - array(const pybind11::dtype &dt, ShapeContainer shape, const void *ptr = nullptr, handle base = handle()) - : array(dt, std::move(shape), {}, ptr, base) { } - - template <typename T, typename = detail::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> - array(const pybind11::dtype &dt, T count, const void *ptr = nullptr, handle base = handle()) - : array(dt, {{count}}, ptr, base) { } - - template <typename T> - array(ShapeContainer shape, StridesContainer strides, const T *ptr, handle base = handle()) - : array(pybind11::dtype::of<T>(), std::move(shape), std::move(strides), ptr, base) { } - - template <typename T> - array(ShapeContainer shape, const T *ptr, handle base = handle()) - : array(std::move(shape), {}, ptr, base) { } - - template <typename T> - explicit array(ssize_t count, const T *ptr, handle base = handle()) : array({count}, {}, ptr, base) { } - - explicit array(const buffer_info &info) - : array(pybind11::dtype(info), info.shape, info.strides, info.ptr) { } - - /// Array descriptor (dtype) - pybind11::dtype dtype() const { - return reinterpret_borrow<pybind11::dtype>(detail::array_proxy(m_ptr)->descr); - } - - /// Total number of elements - ssize_t size() const { - return std::accumulate(shape(), shape() + ndim(), (ssize_t) 1, std::multiplies<ssize_t>()); - } - - /// Byte size of a single element - ssize_t itemsize() const { - return detail::array_descriptor_proxy(detail::array_proxy(m_ptr)->descr)->elsize; - } - - /// Total number of bytes - ssize_t nbytes() const { - return size() * itemsize(); - } - - /// Number of dimensions - ssize_t ndim() const { - return detail::array_proxy(m_ptr)->nd; - } - - /// Base object - object base() const { - return reinterpret_borrow<object>(detail::array_proxy(m_ptr)->base); - } - - /// Dimensions of the array - const ssize_t* shape() const { - return detail::array_proxy(m_ptr)->dimensions; - } - - /// Dimension along a given axis - ssize_t shape(ssize_t dim) const { - if (dim >= ndim()) - fail_dim_check(dim, "invalid axis"); - return shape()[dim]; - } - - /// Strides of the array - const ssize_t* strides() const { - return detail::array_proxy(m_ptr)->strides; - } - - /// Stride along a given axis - ssize_t strides(ssize_t dim) const { - if (dim >= ndim()) - fail_dim_check(dim, "invalid axis"); - return strides()[dim]; - } - - /// Return the NumPy array flags - int flags() const { - return detail::array_proxy(m_ptr)->flags; - } - - /// If set, the array is writeable (otherwise the buffer is read-only) - bool writeable() const { - return detail::check_flags(m_ptr, detail::npy_api::NPY_ARRAY_WRITEABLE_); - } - - /// If set, the array owns the data (will be freed when the array is deleted) - bool owndata() const { - return detail::check_flags(m_ptr, detail::npy_api::NPY_ARRAY_OWNDATA_); - } - - /// Pointer to the contained data. If index is not provided, points to the - /// beginning of the buffer. May throw if the index would lead to out of bounds access. - template<typename... Ix> const void* data(Ix... index) const { - return static_cast<const void *>(detail::array_proxy(m_ptr)->data + offset_at(index...)); - } - - /// Mutable pointer to the contained data. If index is not provided, points to the - /// beginning of the buffer. May throw if the index would lead to out of bounds access. - /// May throw if the array is not writeable. - template<typename... Ix> void* mutable_data(Ix... index) { - check_writeable(); - return static_cast<void *>(detail::array_proxy(m_ptr)->data + offset_at(index...)); - } - - /// Byte offset from beginning of the array to a given index (full or partial). - /// May throw if the index would lead to out of bounds access. - template<typename... Ix> ssize_t offset_at(Ix... index) const { - if ((ssize_t) sizeof...(index) > ndim()) - fail_dim_check(sizeof...(index), "too many indices for an array"); - return byte_offset(ssize_t(index)...); - } - - ssize_t offset_at() const { return 0; } - - /// Item count from beginning of the array to a given index (full or partial). - /// May throw if the index would lead to out of bounds access. - template<typename... Ix> ssize_t index_at(Ix... index) const { - return offset_at(index...) / itemsize(); - } - - /** - * Returns a proxy object that provides access to the array's data without bounds or - * dimensionality checking. Will throw if the array is missing the `writeable` flag. Use with - * care: the array must not be destroyed or reshaped for the duration of the returned object, - * and the caller must take care not to access invalid dimensions or dimension indices. - */ - template <typename T, ssize_t Dims = -1> detail::unchecked_mutable_reference<T, Dims> mutable_unchecked() & { - if (Dims >= 0 && ndim() != Dims) - throw std::domain_error("array has incorrect number of dimensions: " + std::to_string(ndim()) + - "; expected " + std::to_string(Dims)); - return detail::unchecked_mutable_reference<T, Dims>(mutable_data(), shape(), strides(), ndim()); - } - - /** - * Returns a proxy object that provides const access to the array's data without bounds or - * dimensionality checking. Unlike `mutable_unchecked()`, this does not require that the - * underlying array have the `writable` flag. Use with care: the array must not be destroyed or - * reshaped for the duration of the returned object, and the caller must take care not to access - * invalid dimensions or dimension indices. - */ - template <typename T, ssize_t Dims = -1> detail::unchecked_reference<T, Dims> unchecked() const & { - if (Dims >= 0 && ndim() != Dims) - throw std::domain_error("array has incorrect number of dimensions: " + std::to_string(ndim()) + - "; expected " + std::to_string(Dims)); - return detail::unchecked_reference<T, Dims>(data(), shape(), strides(), ndim()); - } - - /// Return a new view with all of the dimensions of length 1 removed - array squeeze() { - auto& api = detail::npy_api::get(); - return reinterpret_steal<array>(api.PyArray_Squeeze_(m_ptr)); - } - - /// Resize array to given shape - /// If refcheck is true and more that one reference exist to this array - /// then resize will succeed only if it makes a reshape, i.e. original size doesn't change - void resize(ShapeContainer new_shape, bool refcheck = true) { - detail::npy_api::PyArray_Dims d = { - new_shape->data(), int(new_shape->size()) - }; - // try to resize, set ordering param to -1 cause it's not used anyway - object new_array = reinterpret_steal<object>( - detail::npy_api::get().PyArray_Resize_(m_ptr, &d, int(refcheck), -1) - ); - if (!new_array) throw error_already_set(); - if (isinstance<array>(new_array)) { *this = std::move(new_array); } - } - - /// Ensure that the argument is a NumPy array - /// In case of an error, nullptr is returned and the Python error is cleared. - static array ensure(handle h, int ExtraFlags = 0) { - auto result = reinterpret_steal<array>(raw_array(h.ptr(), ExtraFlags)); - if (!result) - PyErr_Clear(); - return result; - } - -protected: - template<typename, typename> friend struct detail::npy_format_descriptor; - - void fail_dim_check(ssize_t dim, const std::string& msg) const { - throw index_error(msg + ": " + std::to_string(dim) + - " (ndim = " + std::to_string(ndim()) + ")"); - } - - template<typename... Ix> ssize_t byte_offset(Ix... index) const { - check_dimensions(index...); - return detail::byte_offset_unsafe(strides(), ssize_t(index)...); - } - - void check_writeable() const { - if (!writeable()) - throw std::domain_error("array is not writeable"); - } - - // Default, C-style strides - static std::vector<ssize_t> c_strides(const std::vector<ssize_t> &shape, ssize_t itemsize) { - auto ndim = shape.size(); - std::vector<ssize_t> strides(ndim, itemsize); - if (ndim > 0) - for (size_t i = ndim - 1; i > 0; --i) - strides[i - 1] = strides[i] * shape[i]; - return strides; - } - - // F-style strides; default when constructing an array_t with `ExtraFlags & f_style` - static std::vector<ssize_t> f_strides(const std::vector<ssize_t> &shape, ssize_t itemsize) { - auto ndim = shape.size(); - std::vector<ssize_t> strides(ndim, itemsize); - for (size_t i = 1; i < ndim; ++i) - strides[i] = strides[i - 1] * shape[i - 1]; - return strides; - } - - template<typename... Ix> void check_dimensions(Ix... index) const { - check_dimensions_impl(ssize_t(0), shape(), ssize_t(index)...); - } - - void check_dimensions_impl(ssize_t, const ssize_t*) const { } - - template<typename... Ix> void check_dimensions_impl(ssize_t axis, const ssize_t* shape, ssize_t i, Ix... index) const { - if (i >= *shape) { - throw index_error(std::string("index ") + std::to_string(i) + - " is out of bounds for axis " + std::to_string(axis) + - " with size " + std::to_string(*shape)); - } - check_dimensions_impl(axis + 1, shape + 1, index...); - } - - /// Create array from any object -- always returns a new reference - static PyObject *raw_array(PyObject *ptr, int ExtraFlags = 0) { - if (ptr == nullptr) { - PyErr_SetString(PyExc_ValueError, "cannot create a pybind11::array from a nullptr"); - return nullptr; - } - return detail::npy_api::get().PyArray_FromAny_( - ptr, nullptr, 0, 0, detail::npy_api::NPY_ARRAY_ENSUREARRAY_ | ExtraFlags, nullptr); - } -}; - -template <typename T, int ExtraFlags = array::forcecast> class array_t : public array { -private: - struct private_ctor {}; - // Delegating constructor needed when both moving and accessing in the same constructor - array_t(private_ctor, ShapeContainer &&shape, StridesContainer &&strides, const T *ptr, handle base) - : array(std::move(shape), std::move(strides), ptr, base) {} -public: - static_assert(!detail::array_info<T>::is_array, "Array types cannot be used with array_t"); - - using value_type = T; - - array_t() : array(0, static_cast<const T *>(nullptr)) {} - array_t(handle h, borrowed_t) : array(h, borrowed_t{}) { } - array_t(handle h, stolen_t) : array(h, stolen_t{}) { } - - PYBIND11_DEPRECATED("Use array_t<T>::ensure() instead") - array_t(handle h, bool is_borrowed) : array(raw_array_t(h.ptr()), stolen_t{}) { - if (!m_ptr) PyErr_Clear(); - if (!is_borrowed) Py_XDECREF(h.ptr()); - } - - array_t(const object &o) : array(raw_array_t(o.ptr()), stolen_t{}) { - if (!m_ptr) throw error_already_set(); - } - - explicit array_t(const buffer_info& info) : array(info) { } - - array_t(ShapeContainer shape, StridesContainer strides, const T *ptr = nullptr, handle base = handle()) - : array(std::move(shape), std::move(strides), ptr, base) { } - - explicit array_t(ShapeContainer shape, const T *ptr = nullptr, handle base = handle()) - : array_t(private_ctor{}, std::move(shape), - ExtraFlags & f_style ? f_strides(*shape, itemsize()) : c_strides(*shape, itemsize()), - ptr, base) { } - - explicit array_t(size_t count, const T *ptr = nullptr, handle base = handle()) - : array({count}, {}, ptr, base) { } - - constexpr ssize_t itemsize() const { - return sizeof(T); - } - - template<typename... Ix> ssize_t index_at(Ix... index) const { - return offset_at(index...) / itemsize(); - } - - template<typename... Ix> const T* data(Ix... index) const { - return static_cast<const T*>(array::data(index...)); - } - - template<typename... Ix> T* mutable_data(Ix... index) { - return static_cast<T*>(array::mutable_data(index...)); - } - - // Reference to element at a given index - template<typename... Ix> const T& at(Ix... index) const { - if ((ssize_t) sizeof...(index) != ndim()) - fail_dim_check(sizeof...(index), "index dimension mismatch"); - return *(static_cast<const T*>(array::data()) + byte_offset(ssize_t(index)...) / itemsize()); - } - - // Mutable reference to element at a given index - template<typename... Ix> T& mutable_at(Ix... index) { - if ((ssize_t) sizeof...(index) != ndim()) - fail_dim_check(sizeof...(index), "index dimension mismatch"); - return *(static_cast<T*>(array::mutable_data()) + byte_offset(ssize_t(index)...) / itemsize()); - } - - /** - * Returns a proxy object that provides access to the array's data without bounds or - * dimensionality checking. Will throw if the array is missing the `writeable` flag. Use with - * care: the array must not be destroyed or reshaped for the duration of the returned object, - * and the caller must take care not to access invalid dimensions or dimension indices. - */ - template <ssize_t Dims = -1> detail::unchecked_mutable_reference<T, Dims> mutable_unchecked() & { - return array::mutable_unchecked<T, Dims>(); - } - - /** - * Returns a proxy object that provides const access to the array's data without bounds or - * dimensionality checking. Unlike `unchecked()`, this does not require that the underlying - * array have the `writable` flag. Use with care: the array must not be destroyed or reshaped - * for the duration of the returned object, and the caller must take care not to access invalid - * dimensions or dimension indices. - */ - template <ssize_t Dims = -1> detail::unchecked_reference<T, Dims> unchecked() const & { - return array::unchecked<T, Dims>(); - } - - /// Ensure that the argument is a NumPy array of the correct dtype (and if not, try to convert - /// it). In case of an error, nullptr is returned and the Python error is cleared. - static array_t ensure(handle h) { - auto result = reinterpret_steal<array_t>(raw_array_t(h.ptr())); - if (!result) - PyErr_Clear(); - return result; - } - - static bool check_(handle h) { - const auto &api = detail::npy_api::get(); - return api.PyArray_Check_(h.ptr()) - && api.PyArray_EquivTypes_(detail::array_proxy(h.ptr())->descr, dtype::of<T>().ptr()); - } - -protected: - /// Create array from any object -- always returns a new reference - static PyObject *raw_array_t(PyObject *ptr) { - if (ptr == nullptr) { - PyErr_SetString(PyExc_ValueError, "cannot create a pybind11::array_t from a nullptr"); - return nullptr; - } - return detail::npy_api::get().PyArray_FromAny_( - ptr, dtype::of<T>().release().ptr(), 0, 0, - detail::npy_api::NPY_ARRAY_ENSUREARRAY_ | ExtraFlags, nullptr); - } -}; - -template <typename T> -struct format_descriptor<T, detail::enable_if_t<detail::is_pod_struct<T>::value>> { - static std::string format() { - return detail::npy_format_descriptor<typename std::remove_cv<T>::type>::format(); - } -}; - -template <size_t N> struct format_descriptor<char[N]> { - static std::string format() { return std::to_string(N) + "s"; } -}; -template <size_t N> struct format_descriptor<std::array<char, N>> { - static std::string format() { return std::to_string(N) + "s"; } -}; - -template <typename T> -struct format_descriptor<T, detail::enable_if_t<std::is_enum<T>::value>> { - static std::string format() { - return format_descriptor< - typename std::remove_cv<typename std::underlying_type<T>::type>::type>::format(); - } -}; - -template <typename T> -struct format_descriptor<T, detail::enable_if_t<detail::array_info<T>::is_array>> { - static std::string format() { - using namespace detail; - static constexpr auto extents = _("(") + array_info<T>::extents + _(")"); - return extents.text + format_descriptor<remove_all_extents_t<T>>::format(); - } -}; - -NAMESPACE_BEGIN(detail) -template <typename T, int ExtraFlags> -struct pyobject_caster<array_t<T, ExtraFlags>> { - using type = array_t<T, ExtraFlags>; - - bool load(handle src, bool convert) { - if (!convert && !type::check_(src)) - return false; - value = type::ensure(src); - return static_cast<bool>(value); - } - - static handle cast(const handle &src, return_value_policy /* policy */, handle /* parent */) { - return src.inc_ref(); - } - PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name); -}; - -template <typename T> -struct compare_buffer_info<T, detail::enable_if_t<detail::is_pod_struct<T>::value>> { - static bool compare(const buffer_info& b) { - return npy_api::get().PyArray_EquivTypes_(dtype::of<T>().ptr(), dtype(b).ptr()); - } -}; - -template <typename T, typename = void> -struct npy_format_descriptor_name; - -template <typename T> -struct npy_format_descriptor_name<T, enable_if_t<std::is_integral<T>::value>> { - static constexpr auto name = _<std::is_same<T, bool>::value>( - _("bool"), _<std::is_signed<T>::value>("int", "uint") + _<sizeof(T)*8>() - ); -}; - -template <typename T> -struct npy_format_descriptor_name<T, enable_if_t<std::is_floating_point<T>::value>> { - static constexpr auto name = _<std::is_same<T, float>::value || std::is_same<T, double>::value>( - _("float") + _<sizeof(T)*8>(), _("longdouble") - ); -}; - -template <typename T> -struct npy_format_descriptor_name<T, enable_if_t<is_complex<T>::value>> { - static constexpr auto name = _<std::is_same<typename T::value_type, float>::value - || std::is_same<typename T::value_type, double>::value>( - _("complex") + _<sizeof(typename T::value_type)*16>(), _("longcomplex") - ); -}; - -template <typename T> -struct npy_format_descriptor<T, enable_if_t<satisfies_any_of<T, std::is_arithmetic, is_complex>::value>> - : npy_format_descriptor_name<T> { -private: - // NB: the order here must match the one in common.h - constexpr static const int values[15] = { - npy_api::NPY_BOOL_, - npy_api::NPY_BYTE_, npy_api::NPY_UBYTE_, npy_api::NPY_INT16_, npy_api::NPY_UINT16_, - npy_api::NPY_INT32_, npy_api::NPY_UINT32_, npy_api::NPY_INT64_, npy_api::NPY_UINT64_, - npy_api::NPY_FLOAT_, npy_api::NPY_DOUBLE_, npy_api::NPY_LONGDOUBLE_, - npy_api::NPY_CFLOAT_, npy_api::NPY_CDOUBLE_, npy_api::NPY_CLONGDOUBLE_ - }; - -public: - static constexpr int value = values[detail::is_fmt_numeric<T>::index]; - - static pybind11::dtype dtype() { - if (auto ptr = npy_api::get().PyArray_DescrFromType_(value)) - return reinterpret_steal<pybind11::dtype>(ptr); - pybind11_fail("Unsupported buffer format!"); - } -}; - -#define PYBIND11_DECL_CHAR_FMT \ - static constexpr auto name = _("S") + _<N>(); \ - static pybind11::dtype dtype() { return pybind11::dtype(std::string("S") + std::to_string(N)); } -template <size_t N> struct npy_format_descriptor<char[N]> { PYBIND11_DECL_CHAR_FMT }; -template <size_t N> struct npy_format_descriptor<std::array<char, N>> { PYBIND11_DECL_CHAR_FMT }; -#undef PYBIND11_DECL_CHAR_FMT - -template<typename T> struct npy_format_descriptor<T, enable_if_t<array_info<T>::is_array>> { -private: - using base_descr = npy_format_descriptor<typename array_info<T>::type>; -public: - static_assert(!array_info<T>::is_empty, "Zero-sized arrays are not supported"); - - static constexpr auto name = _("(") + array_info<T>::extents + _(")") + base_descr::name; - static pybind11::dtype dtype() { - list shape; - array_info<T>::append_extents(shape); - return pybind11::dtype::from_args(pybind11::make_tuple(base_descr::dtype(), shape)); - } -}; - -template<typename T> struct npy_format_descriptor<T, enable_if_t<std::is_enum<T>::value>> { -private: - using base_descr = npy_format_descriptor<typename std::underlying_type<T>::type>; -public: - static constexpr auto name = base_descr::name; - static pybind11::dtype dtype() { return base_descr::dtype(); } -}; - -struct field_descriptor { - const char *name; - ssize_t offset; - ssize_t size; - std::string format; - dtype descr; -}; - -inline PYBIND11_NOINLINE void register_structured_dtype( - any_container<field_descriptor> fields, - const std::type_info& tinfo, ssize_t itemsize, - bool (*direct_converter)(PyObject *, void *&)) { - - auto& numpy_internals = get_numpy_internals(); - if (numpy_internals.get_type_info(tinfo, false)) - pybind11_fail("NumPy: dtype is already registered"); - - // Use ordered fields because order matters as of NumPy 1.14: - // https://docs.scipy.org/doc/numpy/release.html#multiple-field-indexing-assignment-of-structured-arrays - std::vector<field_descriptor> ordered_fields(std::move(fields)); - std::sort(ordered_fields.begin(), ordered_fields.end(), - [](const field_descriptor &a, const field_descriptor &b) { return a.offset < b.offset; }); - - list names, formats, offsets; - for (auto& field : ordered_fields) { - if (!field.descr) - pybind11_fail(std::string("NumPy: unsupported field dtype: `") + - field.name + "` @ " + tinfo.name()); - names.append(PYBIND11_STR_TYPE(field.name)); - formats.append(field.descr); - offsets.append(pybind11::int_(field.offset)); - } - auto dtype_ptr = pybind11::dtype(names, formats, offsets, itemsize).release().ptr(); - - // There is an existing bug in NumPy (as of v1.11): trailing bytes are - // not encoded explicitly into the format string. This will supposedly - // get fixed in v1.12; for further details, see these: - // - https://github.com/numpy/numpy/issues/7797 - // - https://github.com/numpy/numpy/pull/7798 - // Because of this, we won't use numpy's logic to generate buffer format - // strings and will just do it ourselves. - ssize_t offset = 0; - std::ostringstream oss; - // mark the structure as unaligned with '^', because numpy and C++ don't - // always agree about alignment (particularly for complex), and we're - // explicitly listing all our padding. This depends on none of the fields - // overriding the endianness. Putting the ^ in front of individual fields - // isn't guaranteed to work due to https://github.com/numpy/numpy/issues/9049 - oss << "^T{"; - for (auto& field : ordered_fields) { - if (field.offset > offset) - oss << (field.offset - offset) << 'x'; - oss << field.format << ':' << field.name << ':'; - offset = field.offset + field.size; - } - if (itemsize > offset) - oss << (itemsize - offset) << 'x'; - oss << '}'; - auto format_str = oss.str(); - - // Sanity check: verify that NumPy properly parses our buffer format string - auto& api = npy_api::get(); - auto arr = array(buffer_info(nullptr, itemsize, format_str, 1)); - if (!api.PyArray_EquivTypes_(dtype_ptr, arr.dtype().ptr())) - pybind11_fail("NumPy: invalid buffer descriptor!"); - - auto tindex = std::type_index(tinfo); - numpy_internals.registered_dtypes[tindex] = { dtype_ptr, format_str }; - get_internals().direct_conversions[tindex].push_back(direct_converter); -} - -template <typename T, typename SFINAE> struct npy_format_descriptor { - static_assert(is_pod_struct<T>::value, "Attempt to use a non-POD or unimplemented POD type as a numpy dtype"); - - static constexpr auto name = make_caster<T>::name; - - static pybind11::dtype dtype() { - return reinterpret_borrow<pybind11::dtype>(dtype_ptr()); - } - - static std::string format() { - static auto format_str = get_numpy_internals().get_type_info<T>(true)->format_str; - return format_str; - } - - static void register_dtype(any_container<field_descriptor> fields) { - register_structured_dtype(std::move(fields), typeid(typename std::remove_cv<T>::type), - sizeof(T), &direct_converter); - } - -private: - static PyObject* dtype_ptr() { - static PyObject* ptr = get_numpy_internals().get_type_info<T>(true)->dtype_ptr; - return ptr; - } - - static bool direct_converter(PyObject *obj, void*& value) { - auto& api = npy_api::get(); - if (!PyObject_TypeCheck(obj, api.PyVoidArrType_Type_)) - return false; - if (auto descr = reinterpret_steal<object>(api.PyArray_DescrFromScalar_(obj))) { - if (api.PyArray_EquivTypes_(dtype_ptr(), descr.ptr())) { - value = ((PyVoidScalarObject_Proxy *) obj)->obval; - return true; - } - } - return false; - } -}; - -#ifdef __CLION_IDE__ // replace heavy macro with dummy code for the IDE (doesn't affect code) -# define PYBIND11_NUMPY_DTYPE(Type, ...) ((void)0) -# define PYBIND11_NUMPY_DTYPE_EX(Type, ...) ((void)0) -#else - -#define PYBIND11_FIELD_DESCRIPTOR_EX(T, Field, Name) \ - ::pybind11::detail::field_descriptor { \ - Name, offsetof(T, Field), sizeof(decltype(std::declval<T>().Field)), \ - ::pybind11::format_descriptor<decltype(std::declval<T>().Field)>::format(), \ - ::pybind11::detail::npy_format_descriptor<decltype(std::declval<T>().Field)>::dtype() \ - } - -// Extract name, offset and format descriptor for a struct field -#define PYBIND11_FIELD_DESCRIPTOR(T, Field) PYBIND11_FIELD_DESCRIPTOR_EX(T, Field, #Field) - -// The main idea of this macro is borrowed from https://github.com/swansontec/map-macro -// (C) William Swanson, Paul Fultz -#define PYBIND11_EVAL0(...) __VA_ARGS__ -#define PYBIND11_EVAL1(...) PYBIND11_EVAL0 (PYBIND11_EVAL0 (PYBIND11_EVAL0 (__VA_ARGS__))) -#define PYBIND11_EVAL2(...) PYBIND11_EVAL1 (PYBIND11_EVAL1 (PYBIND11_EVAL1 (__VA_ARGS__))) -#define PYBIND11_EVAL3(...) PYBIND11_EVAL2 (PYBIND11_EVAL2 (PYBIND11_EVAL2 (__VA_ARGS__))) -#define PYBIND11_EVAL4(...) PYBIND11_EVAL3 (PYBIND11_EVAL3 (PYBIND11_EVAL3 (__VA_ARGS__))) -#define PYBIND11_EVAL(...) PYBIND11_EVAL4 (PYBIND11_EVAL4 (PYBIND11_EVAL4 (__VA_ARGS__))) -#define PYBIND11_MAP_END(...) -#define PYBIND11_MAP_OUT -#define PYBIND11_MAP_COMMA , -#define PYBIND11_MAP_GET_END() 0, PYBIND11_MAP_END -#define PYBIND11_MAP_NEXT0(test, next, ...) next PYBIND11_MAP_OUT -#define PYBIND11_MAP_NEXT1(test, next) PYBIND11_MAP_NEXT0 (test, next, 0) -#define PYBIND11_MAP_NEXT(test, next) PYBIND11_MAP_NEXT1 (PYBIND11_MAP_GET_END test, next) -#ifdef _MSC_VER // MSVC is not as eager to expand macros, hence this workaround -#define PYBIND11_MAP_LIST_NEXT1(test, next) \ - PYBIND11_EVAL0 (PYBIND11_MAP_NEXT0 (test, PYBIND11_MAP_COMMA next, 0)) -#else -#define PYBIND11_MAP_LIST_NEXT1(test, next) \ - PYBIND11_MAP_NEXT0 (test, PYBIND11_MAP_COMMA next, 0) -#endif -#define PYBIND11_MAP_LIST_NEXT(test, next) \ - PYBIND11_MAP_LIST_NEXT1 (PYBIND11_MAP_GET_END test, next) -#define PYBIND11_MAP_LIST0(f, t, x, peek, ...) \ - f(t, x) PYBIND11_MAP_LIST_NEXT (peek, PYBIND11_MAP_LIST1) (f, t, peek, __VA_ARGS__) -#define PYBIND11_MAP_LIST1(f, t, x, peek, ...) \ - f(t, x) PYBIND11_MAP_LIST_NEXT (peek, PYBIND11_MAP_LIST0) (f, t, peek, __VA_ARGS__) -// PYBIND11_MAP_LIST(f, t, a1, a2, ...) expands to f(t, a1), f(t, a2), ... -#define PYBIND11_MAP_LIST(f, t, ...) \ - PYBIND11_EVAL (PYBIND11_MAP_LIST1 (f, t, __VA_ARGS__, (), 0)) - -#define PYBIND11_NUMPY_DTYPE(Type, ...) \ - ::pybind11::detail::npy_format_descriptor<Type>::register_dtype \ - (::std::vector<::pybind11::detail::field_descriptor> \ - {PYBIND11_MAP_LIST (PYBIND11_FIELD_DESCRIPTOR, Type, __VA_ARGS__)}) - -#ifdef _MSC_VER -#define PYBIND11_MAP2_LIST_NEXT1(test, next) \ - PYBIND11_EVAL0 (PYBIND11_MAP_NEXT0 (test, PYBIND11_MAP_COMMA next, 0)) -#else -#define PYBIND11_MAP2_LIST_NEXT1(test, next) \ - PYBIND11_MAP_NEXT0 (test, PYBIND11_MAP_COMMA next, 0) -#endif -#define PYBIND11_MAP2_LIST_NEXT(test, next) \ - PYBIND11_MAP2_LIST_NEXT1 (PYBIND11_MAP_GET_END test, next) -#define PYBIND11_MAP2_LIST0(f, t, x1, x2, peek, ...) \ - f(t, x1, x2) PYBIND11_MAP2_LIST_NEXT (peek, PYBIND11_MAP2_LIST1) (f, t, peek, __VA_ARGS__) -#define PYBIND11_MAP2_LIST1(f, t, x1, x2, peek, ...) \ - f(t, x1, x2) PYBIND11_MAP2_LIST_NEXT (peek, PYBIND11_MAP2_LIST0) (f, t, peek, __VA_ARGS__) -// PYBIND11_MAP2_LIST(f, t, a1, a2, ...) expands to f(t, a1, a2), f(t, a3, a4), ... -#define PYBIND11_MAP2_LIST(f, t, ...) \ - PYBIND11_EVAL (PYBIND11_MAP2_LIST1 (f, t, __VA_ARGS__, (), 0)) - -#define PYBIND11_NUMPY_DTYPE_EX(Type, ...) \ - ::pybind11::detail::npy_format_descriptor<Type>::register_dtype \ - (::std::vector<::pybind11::detail::field_descriptor> \ - {PYBIND11_MAP2_LIST (PYBIND11_FIELD_DESCRIPTOR_EX, Type, __VA_ARGS__)}) - -#endif // __CLION_IDE__ - -template <class T> -using array_iterator = typename std::add_pointer<T>::type; - -template <class T> -array_iterator<T> array_begin(const buffer_info& buffer) { - return array_iterator<T>(reinterpret_cast<T*>(buffer.ptr)); -} - -template <class T> -array_iterator<T> array_end(const buffer_info& buffer) { - return array_iterator<T>(reinterpret_cast<T*>(buffer.ptr) + buffer.size); -} - -class common_iterator { -public: - using container_type = std::vector<ssize_t>; - using value_type = container_type::value_type; - using size_type = container_type::size_type; - - common_iterator() : p_ptr(0), m_strides() {} - - common_iterator(void* ptr, const container_type& strides, const container_type& shape) - : p_ptr(reinterpret_cast<char*>(ptr)), m_strides(strides.size()) { - m_strides.back() = static_cast<value_type>(strides.back()); - for (size_type i = m_strides.size() - 1; i != 0; --i) { - size_type j = i - 1; - value_type s = static_cast<value_type>(shape[i]); - m_strides[j] = strides[j] + m_strides[i] - strides[i] * s; - } - } - - void increment(size_type dim) { - p_ptr += m_strides[dim]; - } - - void* data() const { - return p_ptr; - } - -private: - char* p_ptr; - container_type m_strides; -}; - -template <size_t N> class multi_array_iterator { -public: - using container_type = std::vector<ssize_t>; - - multi_array_iterator(const std::array<buffer_info, N> &buffers, - const container_type &shape) - : m_shape(shape.size()), m_index(shape.size(), 0), - m_common_iterator() { - - // Manual copy to avoid conversion warning if using std::copy - for (size_t i = 0; i < shape.size(); ++i) - m_shape[i] = shape[i]; - - container_type strides(shape.size()); - for (size_t i = 0; i < N; ++i) - init_common_iterator(buffers[i], shape, m_common_iterator[i], strides); - } - - multi_array_iterator& operator++() { - for (size_t j = m_index.size(); j != 0; --j) { - size_t i = j - 1; - if (++m_index[i] != m_shape[i]) { - increment_common_iterator(i); - break; - } else { - m_index[i] = 0; - } - } - return *this; - } - - template <size_t K, class T = void> T* data() const { - return reinterpret_cast<T*>(m_common_iterator[K].data()); - } - -private: - - using common_iter = common_iterator; - - void init_common_iterator(const buffer_info &buffer, - const container_type &shape, - common_iter &iterator, - container_type &strides) { - auto buffer_shape_iter = buffer.shape.rbegin(); - auto buffer_strides_iter = buffer.strides.rbegin(); - auto shape_iter = shape.rbegin(); - auto strides_iter = strides.rbegin(); - - while (buffer_shape_iter != buffer.shape.rend()) { - if (*shape_iter == *buffer_shape_iter) - *strides_iter = *buffer_strides_iter; - else - *strides_iter = 0; - - ++buffer_shape_iter; - ++buffer_strides_iter; - ++shape_iter; - ++strides_iter; - } - - std::fill(strides_iter, strides.rend(), 0); - iterator = common_iter(buffer.ptr, strides, shape); - } - - void increment_common_iterator(size_t dim) { - for (auto &iter : m_common_iterator) - iter.increment(dim); - } - - container_type m_shape; - container_type m_index; - std::array<common_iter, N> m_common_iterator; -}; - -enum class broadcast_trivial { non_trivial, c_trivial, f_trivial }; - -// Populates the shape and number of dimensions for the set of buffers. Returns a broadcast_trivial -// enum value indicating whether the broadcast is "trivial"--that is, has each buffer being either a -// singleton or a full-size, C-contiguous (`c_trivial`) or Fortran-contiguous (`f_trivial`) storage -// buffer; returns `non_trivial` otherwise. -template <size_t N> -broadcast_trivial broadcast(const std::array<buffer_info, N> &buffers, ssize_t &ndim, std::vector<ssize_t> &shape) { - ndim = std::accumulate(buffers.begin(), buffers.end(), ssize_t(0), [](ssize_t res, const buffer_info &buf) { - return std::max(res, buf.ndim); - }); - - shape.clear(); - shape.resize((size_t) ndim, 1); - - // Figure out the output size, and make sure all input arrays conform (i.e. are either size 1 or - // the full size). - for (size_t i = 0; i < N; ++i) { - auto res_iter = shape.rbegin(); - auto end = buffers[i].shape.rend(); - for (auto shape_iter = buffers[i].shape.rbegin(); shape_iter != end; ++shape_iter, ++res_iter) { - const auto &dim_size_in = *shape_iter; - auto &dim_size_out = *res_iter; - - // Each input dimension can either be 1 or `n`, but `n` values must match across buffers - if (dim_size_out == 1) - dim_size_out = dim_size_in; - else if (dim_size_in != 1 && dim_size_in != dim_size_out) - pybind11_fail("pybind11::vectorize: incompatible size/dimension of inputs!"); - } - } - - bool trivial_broadcast_c = true; - bool trivial_broadcast_f = true; - for (size_t i = 0; i < N && (trivial_broadcast_c || trivial_broadcast_f); ++i) { - if (buffers[i].size == 1) - continue; - - // Require the same number of dimensions: - if (buffers[i].ndim != ndim) - return broadcast_trivial::non_trivial; - - // Require all dimensions be full-size: - if (!std::equal(buffers[i].shape.cbegin(), buffers[i].shape.cend(), shape.cbegin())) - return broadcast_trivial::non_trivial; - - // Check for C contiguity (but only if previous inputs were also C contiguous) - if (trivial_broadcast_c) { - ssize_t expect_stride = buffers[i].itemsize; - auto end = buffers[i].shape.crend(); - for (auto shape_iter = buffers[i].shape.crbegin(), stride_iter = buffers[i].strides.crbegin(); - trivial_broadcast_c && shape_iter != end; ++shape_iter, ++stride_iter) { - if (expect_stride == *stride_iter) - expect_stride *= *shape_iter; - else - trivial_broadcast_c = false; - } - } - - // Check for Fortran contiguity (if previous inputs were also F contiguous) - if (trivial_broadcast_f) { - ssize_t expect_stride = buffers[i].itemsize; - auto end = buffers[i].shape.cend(); - for (auto shape_iter = buffers[i].shape.cbegin(), stride_iter = buffers[i].strides.cbegin(); - trivial_broadcast_f && shape_iter != end; ++shape_iter, ++stride_iter) { - if (expect_stride == *stride_iter) - expect_stride *= *shape_iter; - else - trivial_broadcast_f = false; - } - } - } - - return - trivial_broadcast_c ? broadcast_trivial::c_trivial : - trivial_broadcast_f ? broadcast_trivial::f_trivial : - broadcast_trivial::non_trivial; -} - -template <typename T> -struct vectorize_arg { - static_assert(!std::is_rvalue_reference<T>::value, "Functions with rvalue reference arguments cannot be vectorized"); - // The wrapped function gets called with this type: - using call_type = remove_reference_t<T>; - // Is this a vectorized argument? - static constexpr bool vectorize = - satisfies_any_of<call_type, std::is_arithmetic, is_complex, std::is_pod>::value && - satisfies_none_of<call_type, std::is_pointer, std::is_array, is_std_array, std::is_enum>::value && - (!std::is_reference<T>::value || - (std::is_lvalue_reference<T>::value && std::is_const<call_type>::value)); - // Accept this type: an array for vectorized types, otherwise the type as-is: - using type = conditional_t<vectorize, array_t<remove_cv_t<call_type>, array::forcecast>, T>; -}; - -template <typename Func, typename Return, typename... Args> -struct vectorize_helper { -private: - static constexpr size_t N = sizeof...(Args); - static constexpr size_t NVectorized = constexpr_sum(vectorize_arg<Args>::vectorize...); - static_assert(NVectorized >= 1, - "pybind11::vectorize(...) requires a function with at least one vectorizable argument"); - -public: - template <typename T> - explicit vectorize_helper(T &&f) : f(std::forward<T>(f)) { } - - object operator()(typename vectorize_arg<Args>::type... args) { - return run(args..., - make_index_sequence<N>(), - select_indices<vectorize_arg<Args>::vectorize...>(), - make_index_sequence<NVectorized>()); - } - -private: - remove_reference_t<Func> f; - - // Internal compiler error in MSVC 19.16.27025.1 (Visual Studio 2017 15.9.4), when compiling with "/permissive-" flag - // when arg_call_types is manually inlined. - using arg_call_types = std::tuple<typename vectorize_arg<Args>::call_type...>; - template <size_t Index> using param_n_t = typename std::tuple_element<Index, arg_call_types>::type; - - // Runs a vectorized function given arguments tuple and three index sequences: - // - Index is the full set of 0 ... (N-1) argument indices; - // - VIndex is the subset of argument indices with vectorized parameters, letting us access - // vectorized arguments (anything not in this sequence is passed through) - // - BIndex is a incremental sequence (beginning at 0) of the same size as VIndex, so that - // we can store vectorized buffer_infos in an array (argument VIndex has its buffer at - // index BIndex in the array). - template <size_t... Index, size_t... VIndex, size_t... BIndex> object run( - typename vectorize_arg<Args>::type &...args, - index_sequence<Index...> i_seq, index_sequence<VIndex...> vi_seq, index_sequence<BIndex...> bi_seq) { - - // Pointers to values the function was called with; the vectorized ones set here will start - // out as array_t<T> pointers, but they will be changed them to T pointers before we make - // call the wrapped function. Non-vectorized pointers are left as-is. - std::array<void *, N> params{{ &args... }}; - - // The array of `buffer_info`s of vectorized arguments: - std::array<buffer_info, NVectorized> buffers{{ reinterpret_cast<array *>(params[VIndex])->request()... }}; - - /* Determine dimensions parameters of output array */ - ssize_t nd = 0; - std::vector<ssize_t> shape(0); - auto trivial = broadcast(buffers, nd, shape); - size_t ndim = (size_t) nd; - - size_t size = std::accumulate(shape.begin(), shape.end(), (size_t) 1, std::multiplies<size_t>()); - - // If all arguments are 0-dimension arrays (i.e. single values) return a plain value (i.e. - // not wrapped in an array). - if (size == 1 && ndim == 0) { - PYBIND11_EXPAND_SIDE_EFFECTS(params[VIndex] = buffers[BIndex].ptr); - return cast(f(*reinterpret_cast<param_n_t<Index> *>(params[Index])...)); - } - - array_t<Return> result; - if (trivial == broadcast_trivial::f_trivial) result = array_t<Return, array::f_style>(shape); - else result = array_t<Return>(shape); - - if (size == 0) return std::move(result); - - /* Call the function */ - if (trivial == broadcast_trivial::non_trivial) - apply_broadcast(buffers, params, result, i_seq, vi_seq, bi_seq); - else - apply_trivial(buffers, params, result.mutable_data(), size, i_seq, vi_seq, bi_seq); - - return std::move(result); - } - - template <size_t... Index, size_t... VIndex, size_t... BIndex> - void apply_trivial(std::array<buffer_info, NVectorized> &buffers, - std::array<void *, N> ¶ms, - Return *out, - size_t size, - index_sequence<Index...>, index_sequence<VIndex...>, index_sequence<BIndex...>) { - - // Initialize an array of mutable byte references and sizes with references set to the - // appropriate pointer in `params`; as we iterate, we'll increment each pointer by its size - // (except for singletons, which get an increment of 0). - std::array<std::pair<unsigned char *&, const size_t>, NVectorized> vecparams{{ - std::pair<unsigned char *&, const size_t>( - reinterpret_cast<unsigned char *&>(params[VIndex] = buffers[BIndex].ptr), - buffers[BIndex].size == 1 ? 0 : sizeof(param_n_t<VIndex>) - )... - }}; - - for (size_t i = 0; i < size; ++i) { - out[i] = f(*reinterpret_cast<param_n_t<Index> *>(params[Index])...); - for (auto &x : vecparams) x.first += x.second; - } - } - - template <size_t... Index, size_t... VIndex, size_t... BIndex> - void apply_broadcast(std::array<buffer_info, NVectorized> &buffers, - std::array<void *, N> ¶ms, - array_t<Return> &output_array, - index_sequence<Index...>, index_sequence<VIndex...>, index_sequence<BIndex...>) { - - buffer_info output = output_array.request(); - multi_array_iterator<NVectorized> input_iter(buffers, output.shape); - - for (array_iterator<Return> iter = array_begin<Return>(output), end = array_end<Return>(output); - iter != end; - ++iter, ++input_iter) { - PYBIND11_EXPAND_SIDE_EFFECTS(( - params[VIndex] = input_iter.template data<BIndex>() - )); - *iter = f(*reinterpret_cast<param_n_t<Index> *>(std::get<Index>(params))...); - } - } -}; - -template <typename Func, typename Return, typename... Args> -vectorize_helper<Func, Return, Args...> -vectorize_extractor(const Func &f, Return (*) (Args ...)) { - return detail::vectorize_helper<Func, Return, Args...>(f); -} - -template <typename T, int Flags> struct handle_type_name<array_t<T, Flags>> { - static constexpr auto name = _("numpy.ndarray[") + npy_format_descriptor<T>::name + _("]"); -}; - -NAMESPACE_END(detail) - -// Vanilla pointer vectorizer: -template <typename Return, typename... Args> -detail::vectorize_helper<Return (*)(Args...), Return, Args...> -vectorize(Return (*f) (Args ...)) { - return detail::vectorize_helper<Return (*)(Args...), Return, Args...>(f); -} - -// lambda vectorizer: -template <typename Func, detail::enable_if_t<detail::is_lambda<Func>::value, int> = 0> -auto vectorize(Func &&f) -> decltype( - detail::vectorize_extractor(std::forward<Func>(f), (detail::function_signature_t<Func> *) nullptr)) { - return detail::vectorize_extractor(std::forward<Func>(f), (detail::function_signature_t<Func> *) nullptr); -} - -// Vectorize a class method (non-const): -template <typename Return, typename Class, typename... Args, - typename Helper = detail::vectorize_helper<decltype(std::mem_fn(std::declval<Return (Class::*)(Args...)>())), Return, Class *, Args...>> -Helper vectorize(Return (Class::*f)(Args...)) { - return Helper(std::mem_fn(f)); -} - -// Vectorize a class method (const): -template <typename Return, typename Class, typename... Args, - typename Helper = detail::vectorize_helper<decltype(std::mem_fn(std::declval<Return (Class::*)(Args...) const>())), Return, const Class *, Args...>> -Helper vectorize(Return (Class::*f)(Args...) const) { - return Helper(std::mem_fn(f)); -} - -NAMESPACE_END(PYBIND11_NAMESPACE) - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif diff --git a/external/pybind11/include/pybind11/operators.h b/external/pybind11/include/pybind11/operators.h deleted file mode 100644 index b3dd62c3..00000000 --- a/external/pybind11/include/pybind11/operators.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - pybind11/operator.h: Metatemplates for operator overloading - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" - -#if defined(__clang__) && !defined(__INTEL_COMPILER) -# pragma clang diagnostic ignored "-Wunsequenced" // multiple unsequenced modifications to 'self' (when using def(py::self OP Type())) -#elif defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant -#endif - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -/// Enumeration with all supported operator types -enum op_id : int { - op_add, op_sub, op_mul, op_div, op_mod, op_divmod, op_pow, op_lshift, - op_rshift, op_and, op_xor, op_or, op_neg, op_pos, op_abs, op_invert, - op_int, op_long, op_float, op_str, op_cmp, op_gt, op_ge, op_lt, op_le, - op_eq, op_ne, op_iadd, op_isub, op_imul, op_idiv, op_imod, op_ilshift, - op_irshift, op_iand, op_ixor, op_ior, op_complex, op_bool, op_nonzero, - op_repr, op_truediv, op_itruediv, op_hash -}; - -enum op_type : int { - op_l, /* base type on left */ - op_r, /* base type on right */ - op_u /* unary operator */ -}; - -struct self_t { }; -static const self_t self = self_t(); - -/// Type for an unused type slot -struct undefined_t { }; - -/// Don't warn about an unused variable -inline self_t __self() { return self; } - -/// base template of operator implementations -template <op_id, op_type, typename B, typename L, typename R> struct op_impl { }; - -/// Operator implementation generator -template <op_id id, op_type ot, typename L, typename R> struct op_ { - template <typename Class, typename... Extra> void execute(Class &cl, const Extra&... extra) const { - using Base = typename Class::type; - using L_type = conditional_t<std::is_same<L, self_t>::value, Base, L>; - using R_type = conditional_t<std::is_same<R, self_t>::value, Base, R>; - using op = op_impl<id, ot, Base, L_type, R_type>; - cl.def(op::name(), &op::execute, is_operator(), extra...); - #if PY_MAJOR_VERSION < 3 - if (id == op_truediv || id == op_itruediv) - cl.def(id == op_itruediv ? "__idiv__" : ot == op_l ? "__div__" : "__rdiv__", - &op::execute, is_operator(), extra...); - #endif - } - template <typename Class, typename... Extra> void execute_cast(Class &cl, const Extra&... extra) const { - using Base = typename Class::type; - using L_type = conditional_t<std::is_same<L, self_t>::value, Base, L>; - using R_type = conditional_t<std::is_same<R, self_t>::value, Base, R>; - using op = op_impl<id, ot, Base, L_type, R_type>; - cl.def(op::name(), &op::execute_cast, is_operator(), extra...); - #if PY_MAJOR_VERSION < 3 - if (id == op_truediv || id == op_itruediv) - cl.def(id == op_itruediv ? "__idiv__" : ot == op_l ? "__div__" : "__rdiv__", - &op::execute, is_operator(), extra...); - #endif - } -}; - -#define PYBIND11_BINARY_OPERATOR(id, rid, op, expr) \ -template <typename B, typename L, typename R> struct op_impl<op_##id, op_l, B, L, R> { \ - static char const* name() { return "__" #id "__"; } \ - static auto execute(const L &l, const R &r) -> decltype(expr) { return (expr); } \ - static B execute_cast(const L &l, const R &r) { return B(expr); } \ -}; \ -template <typename B, typename L, typename R> struct op_impl<op_##id, op_r, B, L, R> { \ - static char const* name() { return "__" #rid "__"; } \ - static auto execute(const R &r, const L &l) -> decltype(expr) { return (expr); } \ - static B execute_cast(const R &r, const L &l) { return B(expr); } \ -}; \ -inline op_<op_##id, op_l, self_t, self_t> op(const self_t &, const self_t &) { \ - return op_<op_##id, op_l, self_t, self_t>(); \ -} \ -template <typename T> op_<op_##id, op_l, self_t, T> op(const self_t &, const T &) { \ - return op_<op_##id, op_l, self_t, T>(); \ -} \ -template <typename T> op_<op_##id, op_r, T, self_t> op(const T &, const self_t &) { \ - return op_<op_##id, op_r, T, self_t>(); \ -} - -#define PYBIND11_INPLACE_OPERATOR(id, op, expr) \ -template <typename B, typename L, typename R> struct op_impl<op_##id, op_l, B, L, R> { \ - static char const* name() { return "__" #id "__"; } \ - static auto execute(L &l, const R &r) -> decltype(expr) { return expr; } \ - static B execute_cast(L &l, const R &r) { return B(expr); } \ -}; \ -template <typename T> op_<op_##id, op_l, self_t, T> op(const self_t &, const T &) { \ - return op_<op_##id, op_l, self_t, T>(); \ -} - -#define PYBIND11_UNARY_OPERATOR(id, op, expr) \ -template <typename B, typename L> struct op_impl<op_##id, op_u, B, L, undefined_t> { \ - static char const* name() { return "__" #id "__"; } \ - static auto execute(const L &l) -> decltype(expr) { return expr; } \ - static B execute_cast(const L &l) { return B(expr); } \ -}; \ -inline op_<op_##id, op_u, self_t, undefined_t> op(const self_t &) { \ - return op_<op_##id, op_u, self_t, undefined_t>(); \ -} - -PYBIND11_BINARY_OPERATOR(sub, rsub, operator-, l - r) -PYBIND11_BINARY_OPERATOR(add, radd, operator+, l + r) -PYBIND11_BINARY_OPERATOR(mul, rmul, operator*, l * r) -PYBIND11_BINARY_OPERATOR(truediv, rtruediv, operator/, l / r) -PYBIND11_BINARY_OPERATOR(mod, rmod, operator%, l % r) -PYBIND11_BINARY_OPERATOR(lshift, rlshift, operator<<, l << r) -PYBIND11_BINARY_OPERATOR(rshift, rrshift, operator>>, l >> r) -PYBIND11_BINARY_OPERATOR(and, rand, operator&, l & r) -PYBIND11_BINARY_OPERATOR(xor, rxor, operator^, l ^ r) -PYBIND11_BINARY_OPERATOR(eq, eq, operator==, l == r) -PYBIND11_BINARY_OPERATOR(ne, ne, operator!=, l != r) -PYBIND11_BINARY_OPERATOR(or, ror, operator|, l | r) -PYBIND11_BINARY_OPERATOR(gt, lt, operator>, l > r) -PYBIND11_BINARY_OPERATOR(ge, le, operator>=, l >= r) -PYBIND11_BINARY_OPERATOR(lt, gt, operator<, l < r) -PYBIND11_BINARY_OPERATOR(le, ge, operator<=, l <= r) -//PYBIND11_BINARY_OPERATOR(pow, rpow, pow, std::pow(l, r)) -PYBIND11_INPLACE_OPERATOR(iadd, operator+=, l += r) -PYBIND11_INPLACE_OPERATOR(isub, operator-=, l -= r) -PYBIND11_INPLACE_OPERATOR(imul, operator*=, l *= r) -PYBIND11_INPLACE_OPERATOR(itruediv, operator/=, l /= r) -PYBIND11_INPLACE_OPERATOR(imod, operator%=, l %= r) -PYBIND11_INPLACE_OPERATOR(ilshift, operator<<=, l <<= r) -PYBIND11_INPLACE_OPERATOR(irshift, operator>>=, l >>= r) -PYBIND11_INPLACE_OPERATOR(iand, operator&=, l &= r) -PYBIND11_INPLACE_OPERATOR(ixor, operator^=, l ^= r) -PYBIND11_INPLACE_OPERATOR(ior, operator|=, l |= r) -PYBIND11_UNARY_OPERATOR(neg, operator-, -l) -PYBIND11_UNARY_OPERATOR(pos, operator+, +l) -PYBIND11_UNARY_OPERATOR(abs, abs, std::abs(l)) -PYBIND11_UNARY_OPERATOR(hash, hash, std::hash<L>()(l)) -PYBIND11_UNARY_OPERATOR(invert, operator~, (~l)) -PYBIND11_UNARY_OPERATOR(bool, operator!, !!l) -PYBIND11_UNARY_OPERATOR(int, int_, (int) l) -PYBIND11_UNARY_OPERATOR(float, float_, (double) l) - -#undef PYBIND11_BINARY_OPERATOR -#undef PYBIND11_INPLACE_OPERATOR -#undef PYBIND11_UNARY_OPERATOR -NAMESPACE_END(detail) - -using detail::self; - -NAMESPACE_END(PYBIND11_NAMESPACE) - -#if defined(_MSC_VER) -# pragma warning(pop) -#endif diff --git a/external/pybind11/include/pybind11/options.h b/external/pybind11/include/pybind11/options.h deleted file mode 100644 index cc1e1f6f..00000000 --- a/external/pybind11/include/pybind11/options.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - pybind11/options.h: global settings that are configurable at runtime. - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "detail/common.h" - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -class options { -public: - - // Default RAII constructor, which leaves settings as they currently are. - options() : previous_state(global_state()) {} - - // Class is non-copyable. - options(const options&) = delete; - options& operator=(const options&) = delete; - - // Destructor, which restores settings that were in effect before. - ~options() { - global_state() = previous_state; - } - - // Setter methods (affect the global state): - - options& disable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = false; return *this; } - - options& enable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = true; return *this; } - - options& disable_function_signatures() & { global_state().show_function_signatures = false; return *this; } - - options& enable_function_signatures() & { global_state().show_function_signatures = true; return *this; } - - // Getter methods (return the global state): - - static bool show_user_defined_docstrings() { return global_state().show_user_defined_docstrings; } - - static bool show_function_signatures() { return global_state().show_function_signatures; } - - // This type is not meant to be allocated on the heap. - void* operator new(size_t) = delete; - -private: - - struct state { - bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings. - bool show_function_signatures = true; //< Include auto-generated function signatures in docstrings. - }; - - static state &global_state() { - static state instance; - return instance; - } - - state previous_state; -}; - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/pybind11.h b/external/pybind11/include/pybind11/pybind11.h deleted file mode 100644 index 513ceed5..00000000 --- a/external/pybind11/include/pybind11/pybind11.h +++ /dev/null @@ -1,2183 +0,0 @@ -/* - pybind11/pybind11.h: Main header file of the C++11 python - binding generator library - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#if defined(__INTEL_COMPILER) -# pragma warning push -# pragma warning disable 68 // integer conversion resulted in a change of sign -# pragma warning disable 186 // pointless comparison of unsigned integer with zero -# pragma warning disable 878 // incompatible exception specifications -# pragma warning disable 1334 // the "template" keyword used for syntactic disambiguation may only be used within a template -# pragma warning disable 1682 // implicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem) -# pragma warning disable 1786 // function "strdup" was declared deprecated -# pragma warning disable 1875 // offsetof applied to non-POD (Plain Old Data) types is nonstandard -# pragma warning disable 2196 // warning #2196: routine is both "inline" and "noinline" -#elif defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable: 4100) // warning C4100: Unreferenced formal parameter -# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant -# pragma warning(disable: 4512) // warning C4512: Assignment operator was implicitly defined as deleted -# pragma warning(disable: 4800) // warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning) -# pragma warning(disable: 4996) // warning C4996: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name -# pragma warning(disable: 4702) // warning C4702: unreachable code -# pragma warning(disable: 4522) // warning C4522: multiple assignment operators specified -#elif defined(__GNUG__) && !defined(__clang__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wunused-but-set-parameter" -# pragma GCC diagnostic ignored "-Wunused-but-set-variable" -# pragma GCC diagnostic ignored "-Wmissing-field-initializers" -# pragma GCC diagnostic ignored "-Wstrict-aliasing" -# pragma GCC diagnostic ignored "-Wattributes" -# if __GNUC__ >= 7 -# pragma GCC diagnostic ignored "-Wnoexcept-type" -# endif -#endif - -#include "attr.h" -#include "options.h" -#include "detail/class.h" -#include "detail/init.h" - -#if defined(__GNUG__) && !defined(__clang__) -# include <cxxabi.h> -#endif - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -/// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object -class cpp_function : public function { -public: - cpp_function() { } - cpp_function(std::nullptr_t) { } - - /// Construct a cpp_function from a vanilla function pointer - template <typename Return, typename... Args, typename... Extra> - cpp_function(Return (*f)(Args...), const Extra&... extra) { - initialize(f, f, extra...); - } - - /// Construct a cpp_function from a lambda function (possibly with internal state) - template <typename Func, typename... Extra, - typename = detail::enable_if_t<detail::is_lambda<Func>::value>> - cpp_function(Func &&f, const Extra&... extra) { - initialize(std::forward<Func>(f), - (detail::function_signature_t<Func> *) nullptr, extra...); - } - - /// Construct a cpp_function from a class method (non-const) - template <typename Return, typename Class, typename... Arg, typename... Extra> - cpp_function(Return (Class::*f)(Arg...), const Extra&... extra) { - initialize([f](Class *c, Arg... args) -> Return { return (c->*f)(args...); }, - (Return (*) (Class *, Arg...)) nullptr, extra...); - } - - /// Construct a cpp_function from a class method (const) - template <typename Return, typename Class, typename... Arg, typename... Extra> - cpp_function(Return (Class::*f)(Arg...) const, const Extra&... extra) { - initialize([f](const Class *c, Arg... args) -> Return { return (c->*f)(args...); }, - (Return (*)(const Class *, Arg ...)) nullptr, extra...); - } - - /// Return the function name - object name() const { return attr("__name__"); } - -protected: - /// Space optimization: don't inline this frequently instantiated fragment - PYBIND11_NOINLINE detail::function_record *make_function_record() { - return new detail::function_record(); - } - - /// Special internal constructor for functors, lambda functions, etc. - template <typename Func, typename Return, typename... Args, typename... Extra> - void initialize(Func &&f, Return (*)(Args...), const Extra&... extra) { - using namespace detail; - struct capture { remove_reference_t<Func> f; }; - - /* Store the function including any extra state it might have (e.g. a lambda capture object) */ - auto rec = make_function_record(); - - /* Store the capture object directly in the function record if there is enough space */ - if (sizeof(capture) <= sizeof(rec->data)) { - /* Without these pragmas, GCC warns that there might not be - enough space to use the placement new operator. However, the - 'if' statement above ensures that this is the case. */ -#if defined(__GNUG__) && !defined(__clang__) && __GNUC__ >= 6 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wplacement-new" -#endif - new ((capture *) &rec->data) capture { std::forward<Func>(f) }; -#if defined(__GNUG__) && !defined(__clang__) && __GNUC__ >= 6 -# pragma GCC diagnostic pop -#endif - if (!std::is_trivially_destructible<Func>::value) - rec->free_data = [](function_record *r) { ((capture *) &r->data)->~capture(); }; - } else { - rec->data[0] = new capture { std::forward<Func>(f) }; - rec->free_data = [](function_record *r) { delete ((capture *) r->data[0]); }; - } - - /* Type casters for the function arguments and return value */ - using cast_in = argument_loader<Args...>; - using cast_out = make_caster< - conditional_t<std::is_void<Return>::value, void_type, Return> - >; - - static_assert(expected_num_args<Extra...>(sizeof...(Args), cast_in::has_args, cast_in::has_kwargs), - "The number of argument annotations does not match the number of function arguments"); - - /* Dispatch code which converts function arguments and performs the actual function call */ - rec->impl = [](function_call &call) -> handle { - cast_in args_converter; - - /* Try to cast the function arguments into the C++ domain */ - if (!args_converter.load_args(call)) - return PYBIND11_TRY_NEXT_OVERLOAD; - - /* Invoke call policy pre-call hook */ - process_attributes<Extra...>::precall(call); - - /* Get a pointer to the capture object */ - auto data = (sizeof(capture) <= sizeof(call.func.data) - ? &call.func.data : call.func.data[0]); - capture *cap = const_cast<capture *>(reinterpret_cast<const capture *>(data)); - - /* Override policy for rvalues -- usually to enforce rvp::move on an rvalue */ - return_value_policy policy = return_value_policy_override<Return>::policy(call.func.policy); - - /* Function scope guard -- defaults to the compile-to-nothing `void_type` */ - using Guard = extract_guard_t<Extra...>; - - /* Perform the function call */ - handle result = cast_out::cast( - std::move(args_converter).template call<Return, Guard>(cap->f), policy, call.parent); - - /* Invoke call policy post-call hook */ - process_attributes<Extra...>::postcall(call, result); - - return result; - }; - - /* Process any user-provided function attributes */ - process_attributes<Extra...>::init(extra..., rec); - - /* Generate a readable signature describing the function's arguments and return value types */ - static constexpr auto signature = _("(") + cast_in::arg_names + _(") -> ") + cast_out::name; - PYBIND11_DESCR_CONSTEXPR auto types = decltype(signature)::types(); - - /* Register the function with Python from generic (non-templated) code */ - initialize_generic(rec, signature.text, types.data(), sizeof...(Args)); - - if (cast_in::has_args) rec->has_args = true; - if (cast_in::has_kwargs) rec->has_kwargs = true; - - /* Stash some additional information used by an important optimization in 'functional.h' */ - using FunctionType = Return (*)(Args...); - constexpr bool is_function_ptr = - std::is_convertible<Func, FunctionType>::value && - sizeof(capture) == sizeof(void *); - if (is_function_ptr) { - rec->is_stateless = true; - rec->data[1] = const_cast<void *>(reinterpret_cast<const void *>(&typeid(FunctionType))); - } - } - - /// Register a function call with Python (generic non-templated code goes here) - void initialize_generic(detail::function_record *rec, const char *text, - const std::type_info *const *types, size_t args) { - - /* Create copies of all referenced C-style strings */ - rec->name = strdup(rec->name ? rec->name : ""); - if (rec->doc) rec->doc = strdup(rec->doc); - for (auto &a: rec->args) { - if (a.name) - a.name = strdup(a.name); - if (a.descr) - a.descr = strdup(a.descr); - else if (a.value) - a.descr = strdup(a.value.attr("__repr__")().cast<std::string>().c_str()); - } - - rec->is_constructor = !strcmp(rec->name, "__init__") || !strcmp(rec->name, "__setstate__"); - -#if !defined(NDEBUG) && !defined(PYBIND11_DISABLE_NEW_STYLE_INIT_WARNING) - if (rec->is_constructor && !rec->is_new_style_constructor) { - const auto class_name = std::string(((PyTypeObject *) rec->scope.ptr())->tp_name); - const auto func_name = std::string(rec->name); - PyErr_WarnEx( - PyExc_FutureWarning, - ("pybind11-bound class '" + class_name + "' is using an old-style " - "placement-new '" + func_name + "' which has been deprecated. See " - "the upgrade guide in pybind11's docs. This message is only visible " - "when compiled in debug mode.").c_str(), 0 - ); - } -#endif - - /* Generate a proper function signature */ - std::string signature; - size_t type_index = 0, arg_index = 0; - for (auto *pc = text; *pc != '\0'; ++pc) { - const auto c = *pc; - - if (c == '{') { - // Write arg name for everything except *args and **kwargs. - if (*(pc + 1) == '*') - continue; - - if (arg_index < rec->args.size() && rec->args[arg_index].name) { - signature += rec->args[arg_index].name; - } else if (arg_index == 0 && rec->is_method) { - signature += "self"; - } else { - signature += "arg" + std::to_string(arg_index - (rec->is_method ? 1 : 0)); - } - signature += ": "; - } else if (c == '}') { - // Write default value if available. - if (arg_index < rec->args.size() && rec->args[arg_index].descr) { - signature += " = "; - signature += rec->args[arg_index].descr; - } - arg_index++; - } else if (c == '%') { - const std::type_info *t = types[type_index++]; - if (!t) - pybind11_fail("Internal error while parsing type signature (1)"); - if (auto tinfo = detail::get_type_info(*t)) { - handle th((PyObject *) tinfo->type); - signature += - th.attr("__module__").cast<std::string>() + "." + - th.attr("__qualname__").cast<std::string>(); // Python 3.3+, but we backport it to earlier versions - } else if (rec->is_new_style_constructor && arg_index == 0) { - // A new-style `__init__` takes `self` as `value_and_holder`. - // Rewrite it to the proper class type. - signature += - rec->scope.attr("__module__").cast<std::string>() + "." + - rec->scope.attr("__qualname__").cast<std::string>(); - } else { - std::string tname(t->name()); - detail::clean_type_id(tname); - signature += tname; - } - } else { - signature += c; - } - } - if (arg_index != args || types[type_index] != nullptr) - pybind11_fail("Internal error while parsing type signature (2)"); - -#if PY_MAJOR_VERSION < 3 - if (strcmp(rec->name, "__next__") == 0) { - std::free(rec->name); - rec->name = strdup("next"); - } else if (strcmp(rec->name, "__bool__") == 0) { - std::free(rec->name); - rec->name = strdup("__nonzero__"); - } -#endif - rec->signature = strdup(signature.c_str()); - rec->args.shrink_to_fit(); - rec->nargs = (std::uint16_t) args; - - if (rec->sibling && PYBIND11_INSTANCE_METHOD_CHECK(rec->sibling.ptr())) - rec->sibling = PYBIND11_INSTANCE_METHOD_GET_FUNCTION(rec->sibling.ptr()); - - detail::function_record *chain = nullptr, *chain_start = rec; - if (rec->sibling) { - if (PyCFunction_Check(rec->sibling.ptr())) { - auto rec_capsule = reinterpret_borrow<capsule>(PyCFunction_GET_SELF(rec->sibling.ptr())); - chain = (detail::function_record *) rec_capsule; - /* Never append a method to an overload chain of a parent class; - instead, hide the parent's overloads in this case */ - if (!chain->scope.is(rec->scope)) - chain = nullptr; - } - // Don't trigger for things like the default __init__, which are wrapper_descriptors that we are intentionally replacing - else if (!rec->sibling.is_none() && rec->name[0] != '_') - pybind11_fail("Cannot overload existing non-function object \"" + std::string(rec->name) + - "\" with a function of the same name"); - } - - if (!chain) { - /* No existing overload was found, create a new function object */ - rec->def = new PyMethodDef(); - std::memset(rec->def, 0, sizeof(PyMethodDef)); - rec->def->ml_name = rec->name; - rec->def->ml_meth = reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) (void)>(*dispatcher)); - rec->def->ml_flags = METH_VARARGS | METH_KEYWORDS; - - capsule rec_capsule(rec, [](void *ptr) { - destruct((detail::function_record *) ptr); - }); - - object scope_module; - if (rec->scope) { - if (hasattr(rec->scope, "__module__")) { - scope_module = rec->scope.attr("__module__"); - } else if (hasattr(rec->scope, "__name__")) { - scope_module = rec->scope.attr("__name__"); - } - } - - m_ptr = PyCFunction_NewEx(rec->def, rec_capsule.ptr(), scope_module.ptr()); - if (!m_ptr) - pybind11_fail("cpp_function::cpp_function(): Could not allocate function object"); - } else { - /* Append at the end of the overload chain */ - m_ptr = rec->sibling.ptr(); - inc_ref(); - chain_start = chain; - if (chain->is_method != rec->is_method) - pybind11_fail("overloading a method with both static and instance methods is not supported; " - #if defined(NDEBUG) - "compile in debug mode for more details" - #else - "error while attempting to bind " + std::string(rec->is_method ? "instance" : "static") + " method " + - std::string(pybind11::str(rec->scope.attr("__name__"))) + "." + std::string(rec->name) + signature - #endif - ); - while (chain->next) - chain = chain->next; - chain->next = rec; - } - - std::string signatures; - int index = 0; - /* Create a nice pydoc rec including all signatures and - docstrings of the functions in the overload chain */ - if (chain && options::show_function_signatures()) { - // First a generic signature - signatures += rec->name; - signatures += "(*args, **kwargs)\n"; - signatures += "Overloaded function.\n\n"; - } - // Then specific overload signatures - bool first_user_def = true; - for (auto it = chain_start; it != nullptr; it = it->next) { - if (options::show_function_signatures()) { - if (index > 0) signatures += "\n"; - if (chain) - signatures += std::to_string(++index) + ". "; - signatures += rec->name; - signatures += it->signature; - signatures += "\n"; - } - if (it->doc && strlen(it->doc) > 0 && options::show_user_defined_docstrings()) { - // If we're appending another docstring, and aren't printing function signatures, we - // need to append a newline first: - if (!options::show_function_signatures()) { - if (first_user_def) first_user_def = false; - else signatures += "\n"; - } - if (options::show_function_signatures()) signatures += "\n"; - signatures += it->doc; - if (options::show_function_signatures()) signatures += "\n"; - } - } - - /* Install docstring */ - PyCFunctionObject *func = (PyCFunctionObject *) m_ptr; - if (func->m_ml->ml_doc) - std::free(const_cast<char *>(func->m_ml->ml_doc)); - func->m_ml->ml_doc = strdup(signatures.c_str()); - - if (rec->is_method) { - m_ptr = PYBIND11_INSTANCE_METHOD_NEW(m_ptr, rec->scope.ptr()); - if (!m_ptr) - pybind11_fail("cpp_function::cpp_function(): Could not allocate instance method object"); - Py_DECREF(func); - } - } - - /// When a cpp_function is GCed, release any memory allocated by pybind11 - static void destruct(detail::function_record *rec) { - while (rec) { - detail::function_record *next = rec->next; - if (rec->free_data) - rec->free_data(rec); - std::free((char *) rec->name); - std::free((char *) rec->doc); - std::free((char *) rec->signature); - for (auto &arg: rec->args) { - std::free(const_cast<char *>(arg.name)); - std::free(const_cast<char *>(arg.descr)); - arg.value.dec_ref(); - } - if (rec->def) { - std::free(const_cast<char *>(rec->def->ml_doc)); - delete rec->def; - } - delete rec; - rec = next; - } - } - - /// Main dispatch logic for calls to functions bound using pybind11 - static PyObject *dispatcher(PyObject *self, PyObject *args_in, PyObject *kwargs_in) { - using namespace detail; - - /* Iterator over the list of potentially admissible overloads */ - const function_record *overloads = (function_record *) PyCapsule_GetPointer(self, nullptr), - *it = overloads; - - /* Need to know how many arguments + keyword arguments there are to pick the right overload */ - const size_t n_args_in = (size_t) PyTuple_GET_SIZE(args_in); - - handle parent = n_args_in > 0 ? PyTuple_GET_ITEM(args_in, 0) : nullptr, - result = PYBIND11_TRY_NEXT_OVERLOAD; - - auto self_value_and_holder = value_and_holder(); - if (overloads->is_constructor) { - const auto tinfo = get_type_info((PyTypeObject *) overloads->scope.ptr()); - const auto pi = reinterpret_cast<instance *>(parent.ptr()); - self_value_and_holder = pi->get_value_and_holder(tinfo, false); - - if (!self_value_and_holder.type || !self_value_and_holder.inst) { - PyErr_SetString(PyExc_TypeError, "__init__(self, ...) called with invalid `self` argument"); - return nullptr; - } - - // If this value is already registered it must mean __init__ is invoked multiple times; - // we really can't support that in C++, so just ignore the second __init__. - if (self_value_and_holder.instance_registered()) - return none().release().ptr(); - } - - try { - // We do this in two passes: in the first pass, we load arguments with `convert=false`; - // in the second, we allow conversion (except for arguments with an explicit - // py::arg().noconvert()). This lets us prefer calls without conversion, with - // conversion as a fallback. - std::vector<function_call> second_pass; - - // However, if there are no overloads, we can just skip the no-convert pass entirely - const bool overloaded = it != nullptr && it->next != nullptr; - - for (; it != nullptr; it = it->next) { - - /* For each overload: - 1. Copy all positional arguments we were given, also checking to make sure that - named positional arguments weren't *also* specified via kwarg. - 2. If we weren't given enough, try to make up the omitted ones by checking - whether they were provided by a kwarg matching the `py::arg("name")` name. If - so, use it (and remove it from kwargs; if not, see if the function binding - provided a default that we can use. - 3. Ensure that either all keyword arguments were "consumed", or that the function - takes a kwargs argument to accept unconsumed kwargs. - 4. Any positional arguments still left get put into a tuple (for args), and any - leftover kwargs get put into a dict. - 5. Pack everything into a vector; if we have py::args or py::kwargs, they are an - extra tuple or dict at the end of the positional arguments. - 6. Call the function call dispatcher (function_record::impl) - - If one of these fail, move on to the next overload and keep trying until we get a - result other than PYBIND11_TRY_NEXT_OVERLOAD. - */ - - const function_record &func = *it; - size_t pos_args = func.nargs; // Number of positional arguments that we need - if (func.has_args) --pos_args; // (but don't count py::args - if (func.has_kwargs) --pos_args; // or py::kwargs) - - if (!func.has_args && n_args_in > pos_args) - continue; // Too many arguments for this overload - - if (n_args_in < pos_args && func.args.size() < pos_args) - continue; // Not enough arguments given, and not enough defaults to fill in the blanks - - function_call call(func, parent); - - size_t args_to_copy = (std::min)(pos_args, n_args_in); // Protect std::min with parentheses - size_t args_copied = 0; - - // 0. Inject new-style `self` argument - if (func.is_new_style_constructor) { - // The `value` may have been preallocated by an old-style `__init__` - // if it was a preceding candidate for overload resolution. - if (self_value_and_holder) - self_value_and_holder.type->dealloc(self_value_and_holder); - - call.init_self = PyTuple_GET_ITEM(args_in, 0); - call.args.push_back(reinterpret_cast<PyObject *>(&self_value_and_holder)); - call.args_convert.push_back(false); - ++args_copied; - } - - // 1. Copy any position arguments given. - bool bad_arg = false; - for (; args_copied < args_to_copy; ++args_copied) { - const argument_record *arg_rec = args_copied < func.args.size() ? &func.args[args_copied] : nullptr; - if (kwargs_in && arg_rec && arg_rec->name && PyDict_GetItemString(kwargs_in, arg_rec->name)) { - bad_arg = true; - break; - } - - handle arg(PyTuple_GET_ITEM(args_in, args_copied)); - if (arg_rec && !arg_rec->none && arg.is_none()) { - bad_arg = true; - break; - } - call.args.push_back(arg); - call.args_convert.push_back(arg_rec ? arg_rec->convert : true); - } - if (bad_arg) - continue; // Maybe it was meant for another overload (issue #688) - - // We'll need to copy this if we steal some kwargs for defaults - dict kwargs = reinterpret_borrow<dict>(kwargs_in); - - // 2. Check kwargs and, failing that, defaults that may help complete the list - if (args_copied < pos_args) { - bool copied_kwargs = false; - - for (; args_copied < pos_args; ++args_copied) { - const auto &arg = func.args[args_copied]; - - handle value; - if (kwargs_in && arg.name) - value = PyDict_GetItemString(kwargs.ptr(), arg.name); - - if (value) { - // Consume a kwargs value - if (!copied_kwargs) { - kwargs = reinterpret_steal<dict>(PyDict_Copy(kwargs.ptr())); - copied_kwargs = true; - } - PyDict_DelItemString(kwargs.ptr(), arg.name); - } else if (arg.value) { - value = arg.value; - } - - if (value) { - call.args.push_back(value); - call.args_convert.push_back(arg.convert); - } - else - break; - } - - if (args_copied < pos_args) - continue; // Not enough arguments, defaults, or kwargs to fill the positional arguments - } - - // 3. Check everything was consumed (unless we have a kwargs arg) - if (kwargs && kwargs.size() > 0 && !func.has_kwargs) - continue; // Unconsumed kwargs, but no py::kwargs argument to accept them - - // 4a. If we have a py::args argument, create a new tuple with leftovers - if (func.has_args) { - tuple extra_args; - if (args_to_copy == 0) { - // We didn't copy out any position arguments from the args_in tuple, so we - // can reuse it directly without copying: - extra_args = reinterpret_borrow<tuple>(args_in); - } else if (args_copied >= n_args_in) { - extra_args = tuple(0); - } else { - size_t args_size = n_args_in - args_copied; - extra_args = tuple(args_size); - for (size_t i = 0; i < args_size; ++i) { - extra_args[i] = PyTuple_GET_ITEM(args_in, args_copied + i); - } - } - call.args.push_back(extra_args); - call.args_convert.push_back(false); - call.args_ref = std::move(extra_args); - } - - // 4b. If we have a py::kwargs, pass on any remaining kwargs - if (func.has_kwargs) { - if (!kwargs.ptr()) - kwargs = dict(); // If we didn't get one, send an empty one - call.args.push_back(kwargs); - call.args_convert.push_back(false); - call.kwargs_ref = std::move(kwargs); - } - - // 5. Put everything in a vector. Not technically step 5, we've been building it - // in `call.args` all along. - #if !defined(NDEBUG) - if (call.args.size() != func.nargs || call.args_convert.size() != func.nargs) - pybind11_fail("Internal error: function call dispatcher inserted wrong number of arguments!"); - #endif - - std::vector<bool> second_pass_convert; - if (overloaded) { - // We're in the first no-convert pass, so swap out the conversion flags for a - // set of all-false flags. If the call fails, we'll swap the flags back in for - // the conversion-allowed call below. - second_pass_convert.resize(func.nargs, false); - call.args_convert.swap(second_pass_convert); - } - - // 6. Call the function. - try { - loader_life_support guard{}; - result = func.impl(call); - } catch (reference_cast_error &) { - result = PYBIND11_TRY_NEXT_OVERLOAD; - } - - if (result.ptr() != PYBIND11_TRY_NEXT_OVERLOAD) - break; - - if (overloaded) { - // The (overloaded) call failed; if the call has at least one argument that - // permits conversion (i.e. it hasn't been explicitly specified `.noconvert()`) - // then add this call to the list of second pass overloads to try. - for (size_t i = func.is_method ? 1 : 0; i < pos_args; i++) { - if (second_pass_convert[i]) { - // Found one: swap the converting flags back in and store the call for - // the second pass. - call.args_convert.swap(second_pass_convert); - second_pass.push_back(std::move(call)); - break; - } - } - } - } - - if (overloaded && !second_pass.empty() && result.ptr() == PYBIND11_TRY_NEXT_OVERLOAD) { - // The no-conversion pass finished without success, try again with conversion allowed - for (auto &call : second_pass) { - try { - loader_life_support guard{}; - result = call.func.impl(call); - } catch (reference_cast_error &) { - result = PYBIND11_TRY_NEXT_OVERLOAD; - } - - if (result.ptr() != PYBIND11_TRY_NEXT_OVERLOAD) { - // The error reporting logic below expects 'it' to be valid, as it would be - // if we'd encountered this failure in the first-pass loop. - if (!result) - it = &call.func; - break; - } - } - } - } catch (error_already_set &e) { - e.restore(); - return nullptr; -#if defined(__GNUG__) && !defined(__clang__) - } catch ( abi::__forced_unwind& ) { - throw; -#endif - } catch (...) { - /* When an exception is caught, give each registered exception - translator a chance to translate it to a Python exception - in reverse order of registration. - - A translator may choose to do one of the following: - - - catch the exception and call PyErr_SetString or PyErr_SetObject - to set a standard (or custom) Python exception, or - - do nothing and let the exception fall through to the next translator, or - - delegate translation to the next translator by throwing a new type of exception. */ - - auto last_exception = std::current_exception(); - auto ®istered_exception_translators = get_internals().registered_exception_translators; - for (auto& translator : registered_exception_translators) { - try { - translator(last_exception); - } catch (...) { - last_exception = std::current_exception(); - continue; - } - return nullptr; - } - PyErr_SetString(PyExc_SystemError, "Exception escaped from default exception translator!"); - return nullptr; - } - - auto append_note_if_missing_header_is_suspected = [](std::string &msg) { - if (msg.find("std::") != std::string::npos) { - msg += "\n\n" - "Did you forget to `#include <pybind11/stl.h>`? Or <pybind11/complex.h>,\n" - "<pybind11/functional.h>, <pybind11/chrono.h>, etc. Some automatic\n" - "conversions are optional and require extra headers to be included\n" - "when compiling your pybind11 module."; - } - }; - - if (result.ptr() == PYBIND11_TRY_NEXT_OVERLOAD) { - if (overloads->is_operator) - return handle(Py_NotImplemented).inc_ref().ptr(); - - std::string msg = std::string(overloads->name) + "(): incompatible " + - std::string(overloads->is_constructor ? "constructor" : "function") + - " arguments. The following argument types are supported:\n"; - - int ctr = 0; - for (const function_record *it2 = overloads; it2 != nullptr; it2 = it2->next) { - msg += " "+ std::to_string(++ctr) + ". "; - - bool wrote_sig = false; - if (overloads->is_constructor) { - // For a constructor, rewrite `(self: Object, arg0, ...) -> NoneType` as `Object(arg0, ...)` - std::string sig = it2->signature; - size_t start = sig.find('(') + 7; // skip "(self: " - if (start < sig.size()) { - // End at the , for the next argument - size_t end = sig.find(", "), next = end + 2; - size_t ret = sig.rfind(" -> "); - // Or the ), if there is no comma: - if (end >= sig.size()) next = end = sig.find(')'); - if (start < end && next < sig.size()) { - msg.append(sig, start, end - start); - msg += '('; - msg.append(sig, next, ret - next); - wrote_sig = true; - } - } - } - if (!wrote_sig) msg += it2->signature; - - msg += "\n"; - } - msg += "\nInvoked with: "; - auto args_ = reinterpret_borrow<tuple>(args_in); - bool some_args = false; - for (size_t ti = overloads->is_constructor ? 1 : 0; ti < args_.size(); ++ti) { - if (!some_args) some_args = true; - else msg += ", "; - msg += pybind11::repr(args_[ti]); - } - if (kwargs_in) { - auto kwargs = reinterpret_borrow<dict>(kwargs_in); - if (kwargs.size() > 0) { - if (some_args) msg += "; "; - msg += "kwargs: "; - bool first = true; - for (auto kwarg : kwargs) { - if (first) first = false; - else msg += ", "; - msg += pybind11::str("{}={!r}").format(kwarg.first, kwarg.second); - } - } - } - - append_note_if_missing_header_is_suspected(msg); - PyErr_SetString(PyExc_TypeError, msg.c_str()); - return nullptr; - } else if (!result) { - std::string msg = "Unable to convert function return value to a " - "Python type! The signature was\n\t"; - msg += it->signature; - append_note_if_missing_header_is_suspected(msg); - PyErr_SetString(PyExc_TypeError, msg.c_str()); - return nullptr; - } else { - if (overloads->is_constructor && !self_value_and_holder.holder_constructed()) { - auto *pi = reinterpret_cast<instance *>(parent.ptr()); - self_value_and_holder.type->init_instance(pi, nullptr); - } - return result.ptr(); - } - } -}; - -/// Wrapper for Python extension modules -class module : public object { -public: - PYBIND11_OBJECT_DEFAULT(module, object, PyModule_Check) - - /// Create a new top-level Python module with the given name and docstring - explicit module(const char *name, const char *doc = nullptr) { - if (!options::show_user_defined_docstrings()) doc = nullptr; -#if PY_MAJOR_VERSION >= 3 - PyModuleDef *def = new PyModuleDef(); - std::memset(def, 0, sizeof(PyModuleDef)); - def->m_name = name; - def->m_doc = doc; - def->m_size = -1; - Py_INCREF(def); - m_ptr = PyModule_Create(def); -#else - m_ptr = Py_InitModule3(name, nullptr, doc); -#endif - if (m_ptr == nullptr) - pybind11_fail("Internal error in module::module()"); - inc_ref(); - } - - /** \rst - Create Python binding for a new function within the module scope. ``Func`` - can be a plain C++ function, a function pointer, or a lambda function. For - details on the ``Extra&& ... extra`` argument, see section :ref:`extras`. - \endrst */ - template <typename Func, typename... Extra> - module &def(const char *name_, Func &&f, const Extra& ... extra) { - cpp_function func(std::forward<Func>(f), name(name_), scope(*this), - sibling(getattr(*this, name_, none())), extra...); - // NB: allow overwriting here because cpp_function sets up a chain with the intention of - // overwriting (and has already checked internally that it isn't overwriting non-functions). - add_object(name_, func, true /* overwrite */); - return *this; - } - - /** \rst - Create and return a new Python submodule with the given name and docstring. - This also works recursively, i.e. - - .. code-block:: cpp - - py::module m("example", "pybind11 example plugin"); - py::module m2 = m.def_submodule("sub", "A submodule of 'example'"); - py::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'"); - \endrst */ - module def_submodule(const char *name, const char *doc = nullptr) { - std::string full_name = std::string(PyModule_GetName(m_ptr)) - + std::string(".") + std::string(name); - auto result = reinterpret_borrow<module>(PyImport_AddModule(full_name.c_str())); - if (doc && options::show_user_defined_docstrings()) - result.attr("__doc__") = pybind11::str(doc); - attr(name) = result; - return result; - } - - /// Import and return a module or throws `error_already_set`. - static module import(const char *name) { - PyObject *obj = PyImport_ImportModule(name); - if (!obj) - throw error_already_set(); - return reinterpret_steal<module>(obj); - } - - /// Reload the module or throws `error_already_set`. - void reload() { - PyObject *obj = PyImport_ReloadModule(ptr()); - if (!obj) - throw error_already_set(); - *this = reinterpret_steal<module>(obj); - } - - // Adds an object to the module using the given name. Throws if an object with the given name - // already exists. - // - // overwrite should almost always be false: attempting to overwrite objects that pybind11 has - // established will, in most cases, break things. - PYBIND11_NOINLINE void add_object(const char *name, handle obj, bool overwrite = false) { - if (!overwrite && hasattr(*this, name)) - pybind11_fail("Error during initialization: multiple incompatible definitions with name \"" + - std::string(name) + "\""); - - PyModule_AddObject(ptr(), name, obj.inc_ref().ptr() /* steals a reference */); - } -}; - -/// \ingroup python_builtins -/// Return a dictionary representing the global variables in the current execution frame, -/// or ``__main__.__dict__`` if there is no frame (usually when the interpreter is embedded). -inline dict globals() { - PyObject *p = PyEval_GetGlobals(); - return reinterpret_borrow<dict>(p ? p : module::import("__main__").attr("__dict__").ptr()); -} - -NAMESPACE_BEGIN(detail) -/// Generic support for creating new Python heap types -class generic_type : public object { - template <typename...> friend class class_; -public: - PYBIND11_OBJECT_DEFAULT(generic_type, object, PyType_Check) -protected: - void initialize(const type_record &rec) { - if (rec.scope && hasattr(rec.scope, rec.name)) - pybind11_fail("generic_type: cannot initialize type \"" + std::string(rec.name) + - "\": an object with that name is already defined"); - - if (rec.module_local ? get_local_type_info(*rec.type) : get_global_type_info(*rec.type)) - pybind11_fail("generic_type: type \"" + std::string(rec.name) + - "\" is already registered!"); - - m_ptr = make_new_python_type(rec); - - /* Register supplemental type information in C++ dict */ - auto *tinfo = new detail::type_info(); - tinfo->type = (PyTypeObject *) m_ptr; - tinfo->cpptype = rec.type; - tinfo->type_size = rec.type_size; - tinfo->type_align = rec.type_align; - tinfo->operator_new = rec.operator_new; - tinfo->holder_size_in_ptrs = size_in_ptrs(rec.holder_size); - tinfo->init_instance = rec.init_instance; - tinfo->dealloc = rec.dealloc; - tinfo->simple_type = true; - tinfo->simple_ancestors = true; - tinfo->default_holder = rec.default_holder; - tinfo->module_local = rec.module_local; - - auto &internals = get_internals(); - auto tindex = std::type_index(*rec.type); - tinfo->direct_conversions = &internals.direct_conversions[tindex]; - if (rec.module_local) - registered_local_types_cpp()[tindex] = tinfo; - else - internals.registered_types_cpp[tindex] = tinfo; - internals.registered_types_py[(PyTypeObject *) m_ptr] = { tinfo }; - - if (rec.bases.size() > 1 || rec.multiple_inheritance) { - mark_parents_nonsimple(tinfo->type); - tinfo->simple_ancestors = false; - } - else if (rec.bases.size() == 1) { - auto parent_tinfo = get_type_info((PyTypeObject *) rec.bases[0].ptr()); - tinfo->simple_ancestors = parent_tinfo->simple_ancestors; - } - - if (rec.module_local) { - // Stash the local typeinfo and loader so that external modules can access it. - tinfo->module_local_load = &type_caster_generic::local_load; - setattr(m_ptr, PYBIND11_MODULE_LOCAL_ID, capsule(tinfo)); - } - } - - /// Helper function which tags all parents of a type using mult. inheritance - void mark_parents_nonsimple(PyTypeObject *value) { - auto t = reinterpret_borrow<tuple>(value->tp_bases); - for (handle h : t) { - auto tinfo2 = get_type_info((PyTypeObject *) h.ptr()); - if (tinfo2) - tinfo2->simple_type = false; - mark_parents_nonsimple((PyTypeObject *) h.ptr()); - } - } - - void install_buffer_funcs( - buffer_info *(*get_buffer)(PyObject *, void *), - void *get_buffer_data) { - PyHeapTypeObject *type = (PyHeapTypeObject*) m_ptr; - auto tinfo = detail::get_type_info(&type->ht_type); - - if (!type->ht_type.tp_as_buffer) - pybind11_fail( - "To be able to register buffer protocol support for the type '" + - std::string(tinfo->type->tp_name) + - "' the associated class<>(..) invocation must " - "include the pybind11::buffer_protocol() annotation!"); - - tinfo->get_buffer = get_buffer; - tinfo->get_buffer_data = get_buffer_data; - } - - // rec_func must be set for either fget or fset. - void def_property_static_impl(const char *name, - handle fget, handle fset, - detail::function_record *rec_func) { - const auto is_static = rec_func && !(rec_func->is_method && rec_func->scope); - const auto has_doc = rec_func && rec_func->doc && pybind11::options::show_user_defined_docstrings(); - auto property = handle((PyObject *) (is_static ? get_internals().static_property_type - : &PyProperty_Type)); - attr(name) = property(fget.ptr() ? fget : none(), - fset.ptr() ? fset : none(), - /*deleter*/none(), - pybind11::str(has_doc ? rec_func->doc : "")); - } -}; - -/// Set the pointer to operator new if it exists. The cast is needed because it can be overloaded. -template <typename T, typename = void_t<decltype(static_cast<void *(*)(size_t)>(T::operator new))>> -void set_operator_new(type_record *r) { r->operator_new = &T::operator new; } - -template <typename> void set_operator_new(...) { } - -template <typename T, typename SFINAE = void> struct has_operator_delete : std::false_type { }; -template <typename T> struct has_operator_delete<T, void_t<decltype(static_cast<void (*)(void *)>(T::operator delete))>> - : std::true_type { }; -template <typename T, typename SFINAE = void> struct has_operator_delete_size : std::false_type { }; -template <typename T> struct has_operator_delete_size<T, void_t<decltype(static_cast<void (*)(void *, size_t)>(T::operator delete))>> - : std::true_type { }; -/// Call class-specific delete if it exists or global otherwise. Can also be an overload set. -template <typename T, enable_if_t<has_operator_delete<T>::value, int> = 0> -void call_operator_delete(T *p, size_t, size_t) { T::operator delete(p); } -template <typename T, enable_if_t<!has_operator_delete<T>::value && has_operator_delete_size<T>::value, int> = 0> -void call_operator_delete(T *p, size_t s, size_t) { T::operator delete(p, s); } - -inline void call_operator_delete(void *p, size_t s, size_t a) { - (void)s; (void)a; - #ifdef __cpp_aligned_new - if (a > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { - #ifdef __cpp_sized_deallocation - ::operator delete(p, s, std::align_val_t(a)); - #else - ::operator delete(p, std::align_val_t(a)); - #endif - return; - } - #endif - #ifdef __cpp_sized_deallocation - ::operator delete(p, s); - #else - ::operator delete(p); - #endif -} - -NAMESPACE_END(detail) - -/// Given a pointer to a member function, cast it to its `Derived` version. -/// Forward everything else unchanged. -template <typename /*Derived*/, typename F> -auto method_adaptor(F &&f) -> decltype(std::forward<F>(f)) { return std::forward<F>(f); } - -template <typename Derived, typename Return, typename Class, typename... Args> -auto method_adaptor(Return (Class::*pmf)(Args...)) -> Return (Derived::*)(Args...) { - static_assert(detail::is_accessible_base_of<Class, Derived>::value, - "Cannot bind an inaccessible base class method; use a lambda definition instead"); - return pmf; -} - -template <typename Derived, typename Return, typename Class, typename... Args> -auto method_adaptor(Return (Class::*pmf)(Args...) const) -> Return (Derived::*)(Args...) const { - static_assert(detail::is_accessible_base_of<Class, Derived>::value, - "Cannot bind an inaccessible base class method; use a lambda definition instead"); - return pmf; -} - -template <typename type_, typename... options> -class class_ : public detail::generic_type { - template <typename T> using is_holder = detail::is_holder_type<type_, T>; - template <typename T> using is_subtype = detail::is_strict_base_of<type_, T>; - template <typename T> using is_base = detail::is_strict_base_of<T, type_>; - // struct instead of using here to help MSVC: - template <typename T> struct is_valid_class_option : - detail::any_of<is_holder<T>, is_subtype<T>, is_base<T>> {}; - -public: - using type = type_; - using type_alias = detail::exactly_one_t<is_subtype, void, options...>; - constexpr static bool has_alias = !std::is_void<type_alias>::value; - using holder_type = detail::exactly_one_t<is_holder, std::unique_ptr<type>, options...>; - - static_assert(detail::all_of<is_valid_class_option<options>...>::value, - "Unknown/invalid class_ template parameters provided"); - - static_assert(!has_alias || std::is_polymorphic<type>::value, - "Cannot use an alias class with a non-polymorphic type"); - - PYBIND11_OBJECT(class_, generic_type, PyType_Check) - - template <typename... Extra> - class_(handle scope, const char *name, const Extra &... extra) { - using namespace detail; - - // MI can only be specified via class_ template options, not constructor parameters - static_assert( - none_of<is_pyobject<Extra>...>::value || // no base class arguments, or: - ( constexpr_sum(is_pyobject<Extra>::value...) == 1 && // Exactly one base - constexpr_sum(is_base<options>::value...) == 0 && // no template option bases - none_of<std::is_same<multiple_inheritance, Extra>...>::value), // no multiple_inheritance attr - "Error: multiple inheritance bases must be specified via class_ template options"); - - type_record record; - record.scope = scope; - record.name = name; - record.type = &typeid(type); - record.type_size = sizeof(conditional_t<has_alias, type_alias, type>); - record.type_align = alignof(conditional_t<has_alias, type_alias, type>&); - record.holder_size = sizeof(holder_type); - record.init_instance = init_instance; - record.dealloc = dealloc; - record.default_holder = detail::is_instantiation<std::unique_ptr, holder_type>::value; - - set_operator_new<type>(&record); - - /* Register base classes specified via template arguments to class_, if any */ - PYBIND11_EXPAND_SIDE_EFFECTS(add_base<options>(record)); - - /* Process optional arguments, if any */ - process_attributes<Extra...>::init(extra..., &record); - - generic_type::initialize(record); - - if (has_alias) { - auto &instances = record.module_local ? registered_local_types_cpp() : get_internals().registered_types_cpp; - instances[std::type_index(typeid(type_alias))] = instances[std::type_index(typeid(type))]; - } - } - - template <typename Base, detail::enable_if_t<is_base<Base>::value, int> = 0> - static void add_base(detail::type_record &rec) { - rec.add_base(typeid(Base), [](void *src) -> void * { - return static_cast<Base *>(reinterpret_cast<type *>(src)); - }); - } - - template <typename Base, detail::enable_if_t<!is_base<Base>::value, int> = 0> - static void add_base(detail::type_record &) { } - - template <typename Func, typename... Extra> - class_ &def(const char *name_, Func&& f, const Extra&... extra) { - cpp_function cf(method_adaptor<type>(std::forward<Func>(f)), name(name_), is_method(*this), - sibling(getattr(*this, name_, none())), extra...); - attr(cf.name()) = cf; - return *this; - } - - template <typename Func, typename... Extra> class_ & - def_static(const char *name_, Func &&f, const Extra&... extra) { - static_assert(!std::is_member_function_pointer<Func>::value, - "def_static(...) called with a non-static member function pointer"); - cpp_function cf(std::forward<Func>(f), name(name_), scope(*this), - sibling(getattr(*this, name_, none())), extra...); - attr(cf.name()) = staticmethod(cf); - return *this; - } - - template <detail::op_id id, detail::op_type ot, typename L, typename R, typename... Extra> - class_ &def(const detail::op_<id, ot, L, R> &op, const Extra&... extra) { - op.execute(*this, extra...); - return *this; - } - - template <detail::op_id id, detail::op_type ot, typename L, typename R, typename... Extra> - class_ & def_cast(const detail::op_<id, ot, L, R> &op, const Extra&... extra) { - op.execute_cast(*this, extra...); - return *this; - } - - template <typename... Args, typename... Extra> - class_ &def(const detail::initimpl::constructor<Args...> &init, const Extra&... extra) { - init.execute(*this, extra...); - return *this; - } - - template <typename... Args, typename... Extra> - class_ &def(const detail::initimpl::alias_constructor<Args...> &init, const Extra&... extra) { - init.execute(*this, extra...); - return *this; - } - - template <typename... Args, typename... Extra> - class_ &def(detail::initimpl::factory<Args...> &&init, const Extra&... extra) { - std::move(init).execute(*this, extra...); - return *this; - } - - template <typename... Args, typename... Extra> - class_ &def(detail::initimpl::pickle_factory<Args...> &&pf, const Extra &...extra) { - std::move(pf).execute(*this, extra...); - return *this; - } - - template <typename Func> class_& def_buffer(Func &&func) { - struct capture { Func func; }; - capture *ptr = new capture { std::forward<Func>(func) }; - install_buffer_funcs([](PyObject *obj, void *ptr) -> buffer_info* { - detail::make_caster<type> caster; - if (!caster.load(obj, false)) - return nullptr; - return new buffer_info(((capture *) ptr)->func(caster)); - }, ptr); - return *this; - } - - template <typename Return, typename Class, typename... Args> - class_ &def_buffer(Return (Class::*func)(Args...)) { - return def_buffer([func] (type &obj) { return (obj.*func)(); }); - } - - template <typename Return, typename Class, typename... Args> - class_ &def_buffer(Return (Class::*func)(Args...) const) { - return def_buffer([func] (const type &obj) { return (obj.*func)(); }); - } - - template <typename C, typename D, typename... Extra> - class_ &def_readwrite(const char *name, D C::*pm, const Extra&... extra) { - static_assert(std::is_same<C, type>::value || std::is_base_of<C, type>::value, "def_readwrite() requires a class member (or base class member)"); - cpp_function fget([pm](const type &c) -> const D &{ return c.*pm; }, is_method(*this)), - fset([pm](type &c, const D &value) { c.*pm = value; }, is_method(*this)); - def_property(name, fget, fset, return_value_policy::reference_internal, extra...); - return *this; - } - - template <typename C, typename D, typename... Extra> - class_ &def_readonly(const char *name, const D C::*pm, const Extra& ...extra) { - static_assert(std::is_same<C, type>::value || std::is_base_of<C, type>::value, "def_readonly() requires a class member (or base class member)"); - cpp_function fget([pm](const type &c) -> const D &{ return c.*pm; }, is_method(*this)); - def_property_readonly(name, fget, return_value_policy::reference_internal, extra...); - return *this; - } - - template <typename D, typename... Extra> - class_ &def_readwrite_static(const char *name, D *pm, const Extra& ...extra) { - cpp_function fget([pm](object) -> const D &{ return *pm; }, scope(*this)), - fset([pm](object, const D &value) { *pm = value; }, scope(*this)); - def_property_static(name, fget, fset, return_value_policy::reference, extra...); - return *this; - } - - template <typename D, typename... Extra> - class_ &def_readonly_static(const char *name, const D *pm, const Extra& ...extra) { - cpp_function fget([pm](object) -> const D &{ return *pm; }, scope(*this)); - def_property_readonly_static(name, fget, return_value_policy::reference, extra...); - return *this; - } - - /// Uses return_value_policy::reference_internal by default - template <typename Getter, typename... Extra> - class_ &def_property_readonly(const char *name, const Getter &fget, const Extra& ...extra) { - return def_property_readonly(name, cpp_function(method_adaptor<type>(fget)), - return_value_policy::reference_internal, extra...); - } - - /// Uses cpp_function's return_value_policy by default - template <typename... Extra> - class_ &def_property_readonly(const char *name, const cpp_function &fget, const Extra& ...extra) { - return def_property(name, fget, nullptr, extra...); - } - - /// Uses return_value_policy::reference by default - template <typename Getter, typename... Extra> - class_ &def_property_readonly_static(const char *name, const Getter &fget, const Extra& ...extra) { - return def_property_readonly_static(name, cpp_function(fget), return_value_policy::reference, extra...); - } - - /// Uses cpp_function's return_value_policy by default - template <typename... Extra> - class_ &def_property_readonly_static(const char *name, const cpp_function &fget, const Extra& ...extra) { - return def_property_static(name, fget, nullptr, extra...); - } - - /// Uses return_value_policy::reference_internal by default - template <typename Getter, typename Setter, typename... Extra> - class_ &def_property(const char *name, const Getter &fget, const Setter &fset, const Extra& ...extra) { - return def_property(name, fget, cpp_function(method_adaptor<type>(fset)), extra...); - } - template <typename Getter, typename... Extra> - class_ &def_property(const char *name, const Getter &fget, const cpp_function &fset, const Extra& ...extra) { - return def_property(name, cpp_function(method_adaptor<type>(fget)), fset, - return_value_policy::reference_internal, extra...); - } - - /// Uses cpp_function's return_value_policy by default - template <typename... Extra> - class_ &def_property(const char *name, const cpp_function &fget, const cpp_function &fset, const Extra& ...extra) { - return def_property_static(name, fget, fset, is_method(*this), extra...); - } - - /// Uses return_value_policy::reference by default - template <typename Getter, typename... Extra> - class_ &def_property_static(const char *name, const Getter &fget, const cpp_function &fset, const Extra& ...extra) { - return def_property_static(name, cpp_function(fget), fset, return_value_policy::reference, extra...); - } - - /// Uses cpp_function's return_value_policy by default - template <typename... Extra> - class_ &def_property_static(const char *name, const cpp_function &fget, const cpp_function &fset, const Extra& ...extra) { - static_assert( 0 == detail::constexpr_sum(std::is_base_of<arg, Extra>::value...), - "Argument annotations are not allowed for properties"); - auto rec_fget = get_function_record(fget), rec_fset = get_function_record(fset); - auto *rec_active = rec_fget; - if (rec_fget) { - char *doc_prev = rec_fget->doc; /* 'extra' field may include a property-specific documentation string */ - detail::process_attributes<Extra...>::init(extra..., rec_fget); - if (rec_fget->doc && rec_fget->doc != doc_prev) { - free(doc_prev); - rec_fget->doc = strdup(rec_fget->doc); - } - } - if (rec_fset) { - char *doc_prev = rec_fset->doc; - detail::process_attributes<Extra...>::init(extra..., rec_fset); - if (rec_fset->doc && rec_fset->doc != doc_prev) { - free(doc_prev); - rec_fset->doc = strdup(rec_fset->doc); - } - if (! rec_active) rec_active = rec_fset; - } - def_property_static_impl(name, fget, fset, rec_active); - return *this; - } - -private: - /// Initialize holder object, variant 1: object derives from enable_shared_from_this - template <typename T> - static void init_holder(detail::instance *inst, detail::value_and_holder &v_h, - const holder_type * /* unused */, const std::enable_shared_from_this<T> * /* dummy */) { - try { - auto sh = std::dynamic_pointer_cast<typename holder_type::element_type>( - v_h.value_ptr<type>()->shared_from_this()); - if (sh) { - new (std::addressof(v_h.holder<holder_type>())) holder_type(std::move(sh)); - v_h.set_holder_constructed(); - } - } catch (const std::bad_weak_ptr &) {} - - if (!v_h.holder_constructed() && inst->owned) { - new (std::addressof(v_h.holder<holder_type>())) holder_type(v_h.value_ptr<type>()); - v_h.set_holder_constructed(); - } - } - - static void init_holder_from_existing(const detail::value_and_holder &v_h, - const holder_type *holder_ptr, std::true_type /*is_copy_constructible*/) { - new (std::addressof(v_h.holder<holder_type>())) holder_type(*reinterpret_cast<const holder_type *>(holder_ptr)); - } - - static void init_holder_from_existing(const detail::value_and_holder &v_h, - const holder_type *holder_ptr, std::false_type /*is_copy_constructible*/) { - new (std::addressof(v_h.holder<holder_type>())) holder_type(std::move(*const_cast<holder_type *>(holder_ptr))); - } - - /// Initialize holder object, variant 2: try to construct from existing holder object, if possible - static void init_holder(detail::instance *inst, detail::value_and_holder &v_h, - const holder_type *holder_ptr, const void * /* dummy -- not enable_shared_from_this<T>) */) { - if (holder_ptr) { - init_holder_from_existing(v_h, holder_ptr, std::is_copy_constructible<holder_type>()); - v_h.set_holder_constructed(); - } else if (inst->owned || detail::always_construct_holder<holder_type>::value) { - new (std::addressof(v_h.holder<holder_type>())) holder_type(v_h.value_ptr<type>()); - v_h.set_holder_constructed(); - } - } - - /// Performs instance initialization including constructing a holder and registering the known - /// instance. Should be called as soon as the `type` value_ptr is set for an instance. Takes an - /// optional pointer to an existing holder to use; if not specified and the instance is - /// `.owned`, a new holder will be constructed to manage the value pointer. - static void init_instance(detail::instance *inst, const void *holder_ptr) { - auto v_h = inst->get_value_and_holder(detail::get_type_info(typeid(type))); - if (!v_h.instance_registered()) { - register_instance(inst, v_h.value_ptr(), v_h.type); - v_h.set_instance_registered(); - } - init_holder(inst, v_h, (const holder_type *) holder_ptr, v_h.value_ptr<type>()); - } - - /// Deallocates an instance; via holder, if constructed; otherwise via operator delete. - static void dealloc(detail::value_and_holder &v_h) { - if (v_h.holder_constructed()) { - v_h.holder<holder_type>().~holder_type(); - v_h.set_holder_constructed(false); - } - else { - detail::call_operator_delete(v_h.value_ptr<type>(), - v_h.type->type_size, - v_h.type->type_align - ); - } - v_h.value_ptr() = nullptr; - } - - static detail::function_record *get_function_record(handle h) { - h = detail::get_function(h); - return h ? (detail::function_record *) reinterpret_borrow<capsule>(PyCFunction_GET_SELF(h.ptr())) - : nullptr; - } -}; - -/// Binds an existing constructor taking arguments Args... -template <typename... Args> detail::initimpl::constructor<Args...> init() { return {}; } -/// Like `init<Args...>()`, but the instance is always constructed through the alias class (even -/// when not inheriting on the Python side). -template <typename... Args> detail::initimpl::alias_constructor<Args...> init_alias() { return {}; } - -/// Binds a factory function as a constructor -template <typename Func, typename Ret = detail::initimpl::factory<Func>> -Ret init(Func &&f) { return {std::forward<Func>(f)}; } - -/// Dual-argument factory function: the first function is called when no alias is needed, the second -/// when an alias is needed (i.e. due to python-side inheritance). Arguments must be identical. -template <typename CFunc, typename AFunc, typename Ret = detail::initimpl::factory<CFunc, AFunc>> -Ret init(CFunc &&c, AFunc &&a) { - return {std::forward<CFunc>(c), std::forward<AFunc>(a)}; -} - -/// Binds pickling functions `__getstate__` and `__setstate__` and ensures that the type -/// returned by `__getstate__` is the same as the argument accepted by `__setstate__`. -template <typename GetState, typename SetState> -detail::initimpl::pickle_factory<GetState, SetState> pickle(GetState &&g, SetState &&s) { - return {std::forward<GetState>(g), std::forward<SetState>(s)}; -} - -NAMESPACE_BEGIN(detail) -struct enum_base { - enum_base(handle base, handle parent) : m_base(base), m_parent(parent) { } - - PYBIND11_NOINLINE void init(bool is_arithmetic, bool is_convertible) { - m_base.attr("__entries") = dict(); - auto property = handle((PyObject *) &PyProperty_Type); - auto static_property = handle((PyObject *) get_internals().static_property_type); - - m_base.attr("__repr__") = cpp_function( - [](handle arg) -> str { - handle type = arg.get_type(); - object type_name = type.attr("__name__"); - dict entries = type.attr("__entries"); - for (const auto &kv : entries) { - object other = kv.second[int_(0)]; - if (other.equal(arg)) - return pybind11::str("{}.{}").format(type_name, kv.first); - } - return pybind11::str("{}.???").format(type_name); - }, is_method(m_base) - ); - - m_base.attr("name") = property(cpp_function( - [](handle arg) -> str { - dict entries = arg.get_type().attr("__entries"); - for (const auto &kv : entries) { - if (handle(kv.second[int_(0)]).equal(arg)) - return pybind11::str(kv.first); - } - return "???"; - }, is_method(m_base) - )); - - m_base.attr("__doc__") = static_property(cpp_function( - [](handle arg) -> std::string { - std::string docstring; - dict entries = arg.attr("__entries"); - if (((PyTypeObject *) arg.ptr())->tp_doc) - docstring += std::string(((PyTypeObject *) arg.ptr())->tp_doc) + "\n\n"; - docstring += "Members:"; - for (const auto &kv : entries) { - auto key = std::string(pybind11::str(kv.first)); - auto comment = kv.second[int_(1)]; - docstring += "\n\n " + key; - if (!comment.is_none()) - docstring += " : " + (std::string) pybind11::str(comment); - } - return docstring; - } - ), none(), none(), ""); - - m_base.attr("__members__") = static_property(cpp_function( - [](handle arg) -> dict { - dict entries = arg.attr("__entries"), m; - for (const auto &kv : entries) - m[kv.first] = kv.second[int_(0)]; - return m; - }), none(), none(), "" - ); - - #define PYBIND11_ENUM_OP_STRICT(op, expr, strict_behavior) \ - m_base.attr(op) = cpp_function( \ - [](object a, object b) { \ - if (!a.get_type().is(b.get_type())) \ - strict_behavior; \ - return expr; \ - }, \ - is_method(m_base)) - - #define PYBIND11_ENUM_OP_CONV(op, expr) \ - m_base.attr(op) = cpp_function( \ - [](object a_, object b_) { \ - int_ a(a_), b(b_); \ - return expr; \ - }, \ - is_method(m_base)) - - #define PYBIND11_ENUM_OP_CONV_LHS(op, expr) \ - m_base.attr(op) = cpp_function( \ - [](object a_, object b) { \ - int_ a(a_); \ - return expr; \ - }, \ - is_method(m_base)) - - if (is_convertible) { - PYBIND11_ENUM_OP_CONV_LHS("__eq__", !b.is_none() && a.equal(b)); - PYBIND11_ENUM_OP_CONV_LHS("__ne__", b.is_none() || !a.equal(b)); - - if (is_arithmetic) { - PYBIND11_ENUM_OP_CONV("__lt__", a < b); - PYBIND11_ENUM_OP_CONV("__gt__", a > b); - PYBIND11_ENUM_OP_CONV("__le__", a <= b); - PYBIND11_ENUM_OP_CONV("__ge__", a >= b); - PYBIND11_ENUM_OP_CONV("__and__", a & b); - PYBIND11_ENUM_OP_CONV("__rand__", a & b); - PYBIND11_ENUM_OP_CONV("__or__", a | b); - PYBIND11_ENUM_OP_CONV("__ror__", a | b); - PYBIND11_ENUM_OP_CONV("__xor__", a ^ b); - PYBIND11_ENUM_OP_CONV("__rxor__", a ^ b); - m_base.attr("__invert__") = cpp_function( - [](object arg) { return ~(int_(arg)); }, is_method(m_base)); - } - } else { - PYBIND11_ENUM_OP_STRICT("__eq__", int_(a).equal(int_(b)), return false); - PYBIND11_ENUM_OP_STRICT("__ne__", !int_(a).equal(int_(b)), return true); - - if (is_arithmetic) { - #define PYBIND11_THROW throw type_error("Expected an enumeration of matching type!"); - PYBIND11_ENUM_OP_STRICT("__lt__", int_(a) < int_(b), PYBIND11_THROW); - PYBIND11_ENUM_OP_STRICT("__gt__", int_(a) > int_(b), PYBIND11_THROW); - PYBIND11_ENUM_OP_STRICT("__le__", int_(a) <= int_(b), PYBIND11_THROW); - PYBIND11_ENUM_OP_STRICT("__ge__", int_(a) >= int_(b), PYBIND11_THROW); - #undef PYBIND11_THROW - } - } - - #undef PYBIND11_ENUM_OP_CONV_LHS - #undef PYBIND11_ENUM_OP_CONV - #undef PYBIND11_ENUM_OP_STRICT - - object getstate = cpp_function( - [](object arg) { return int_(arg); }, is_method(m_base)); - - m_base.attr("__getstate__") = getstate; - m_base.attr("__hash__") = getstate; - } - - PYBIND11_NOINLINE void value(char const* name_, object value, const char *doc = nullptr) { - dict entries = m_base.attr("__entries"); - str name(name_); - if (entries.contains(name)) { - std::string type_name = (std::string) str(m_base.attr("__name__")); - throw value_error(type_name + ": element \"" + std::string(name_) + "\" already exists!"); - } - - entries[name] = std::make_pair(value, doc); - m_base.attr(name) = value; - } - - PYBIND11_NOINLINE void export_values() { - dict entries = m_base.attr("__entries"); - for (const auto &kv : entries) - m_parent.attr(kv.first) = kv.second[int_(0)]; - } - - handle m_base; - handle m_parent; -}; - -NAMESPACE_END(detail) - -/// Binds C++ enumerations and enumeration classes to Python -template <typename Type> class enum_ : public class_<Type> { -public: - using Base = class_<Type>; - using Base::def; - using Base::attr; - using Base::def_property_readonly; - using Base::def_property_readonly_static; - using Scalar = typename std::underlying_type<Type>::type; - - template <typename... Extra> - enum_(const handle &scope, const char *name, const Extra&... extra) - : class_<Type>(scope, name, extra...), m_base(*this, scope) { - constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value; - constexpr bool is_convertible = std::is_convertible<Type, Scalar>::value; - m_base.init(is_arithmetic, is_convertible); - - def(init([](Scalar i) { return static_cast<Type>(i); })); - def("__int__", [](Type value) { return (Scalar) value; }); - #if PY_MAJOR_VERSION < 3 - def("__long__", [](Type value) { return (Scalar) value; }); - #endif - #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) - def("__index__", [](Type value) { return (Scalar) value; }); - #endif - - cpp_function setstate( - [](Type &value, Scalar arg) { value = static_cast<Type>(arg); }, - is_method(*this)); - attr("__setstate__") = setstate; - } - - /// Export enumeration entries into the parent scope - enum_& export_values() { - m_base.export_values(); - return *this; - } - - /// Add an enumeration entry - enum_& value(char const* name, Type value, const char *doc = nullptr) { - m_base.value(name, pybind11::cast(value, return_value_policy::copy), doc); - return *this; - } - -private: - detail::enum_base m_base; -}; - -NAMESPACE_BEGIN(detail) - - -inline void keep_alive_impl(handle nurse, handle patient) { - if (!nurse || !patient) - pybind11_fail("Could not activate keep_alive!"); - - if (patient.is_none() || nurse.is_none()) - return; /* Nothing to keep alive or nothing to be kept alive by */ - - auto tinfo = all_type_info(Py_TYPE(nurse.ptr())); - if (!tinfo.empty()) { - /* It's a pybind-registered type, so we can store the patient in the - * internal list. */ - add_patient(nurse.ptr(), patient.ptr()); - } - else { - /* Fall back to clever approach based on weak references taken from - * Boost.Python. This is not used for pybind-registered types because - * the objects can be destroyed out-of-order in a GC pass. */ - cpp_function disable_lifesupport( - [patient](handle weakref) { patient.dec_ref(); weakref.dec_ref(); }); - - weakref wr(nurse, disable_lifesupport); - - patient.inc_ref(); /* reference patient and leak the weak reference */ - (void) wr.release(); - } -} - -PYBIND11_NOINLINE inline void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret) { - auto get_arg = [&](size_t n) { - if (n == 0) - return ret; - else if (n == 1 && call.init_self) - return call.init_self; - else if (n <= call.args.size()) - return call.args[n - 1]; - return handle(); - }; - - keep_alive_impl(get_arg(Nurse), get_arg(Patient)); -} - -inline std::pair<decltype(internals::registered_types_py)::iterator, bool> all_type_info_get_cache(PyTypeObject *type) { - auto res = get_internals().registered_types_py -#ifdef __cpp_lib_unordered_map_try_emplace - .try_emplace(type); -#else - .emplace(type, std::vector<detail::type_info *>()); -#endif - if (res.second) { - // New cache entry created; set up a weak reference to automatically remove it if the type - // gets destroyed: - weakref((PyObject *) type, cpp_function([type](handle wr) { - get_internals().registered_types_py.erase(type); - wr.dec_ref(); - })).release(); - } - - return res; -} - -template <typename Iterator, typename Sentinel, bool KeyIterator, return_value_policy Policy> -struct iterator_state { - Iterator it; - Sentinel end; - bool first_or_done; -}; - -NAMESPACE_END(detail) - -/// Makes a python iterator from a first and past-the-end C++ InputIterator. -template <return_value_policy Policy = return_value_policy::reference_internal, - typename Iterator, - typename Sentinel, - typename ValueType = decltype(*std::declval<Iterator>()), - typename... Extra> -iterator make_iterator(Iterator first, Sentinel last, Extra &&... extra) { - typedef detail::iterator_state<Iterator, Sentinel, false, Policy> state; - - if (!detail::get_type_info(typeid(state), false)) { - class_<state>(handle(), "iterator", pybind11::module_local()) - .def("__iter__", [](state &s) -> state& { return s; }) - .def("__next__", [](state &s) -> ValueType { - if (!s.first_or_done) - ++s.it; - else - s.first_or_done = false; - if (s.it == s.end) { - s.first_or_done = true; - throw stop_iteration(); - } - return *s.it; - }, std::forward<Extra>(extra)..., Policy); - } - - return cast(state{first, last, true}); -} - -/// Makes an python iterator over the keys (`.first`) of a iterator over pairs from a -/// first and past-the-end InputIterator. -template <return_value_policy Policy = return_value_policy::reference_internal, - typename Iterator, - typename Sentinel, - typename KeyType = decltype((*std::declval<Iterator>()).first), - typename... Extra> -iterator make_key_iterator(Iterator first, Sentinel last, Extra &&... extra) { - typedef detail::iterator_state<Iterator, Sentinel, true, Policy> state; - - if (!detail::get_type_info(typeid(state), false)) { - class_<state>(handle(), "iterator", pybind11::module_local()) - .def("__iter__", [](state &s) -> state& { return s; }) - .def("__next__", [](state &s) -> KeyType { - if (!s.first_or_done) - ++s.it; - else - s.first_or_done = false; - if (s.it == s.end) { - s.first_or_done = true; - throw stop_iteration(); - } - return (*s.it).first; - }, std::forward<Extra>(extra)..., Policy); - } - - return cast(state{first, last, true}); -} - -/// Makes an iterator over values of an stl container or other container supporting -/// `std::begin()`/`std::end()` -template <return_value_policy Policy = return_value_policy::reference_internal, - typename Type, typename... Extra> iterator make_iterator(Type &value, Extra&&... extra) { - return make_iterator<Policy>(std::begin(value), std::end(value), extra...); -} - -/// Makes an iterator over the keys (`.first`) of a stl map-like container supporting -/// `std::begin()`/`std::end()` -template <return_value_policy Policy = return_value_policy::reference_internal, - typename Type, typename... Extra> iterator make_key_iterator(Type &value, Extra&&... extra) { - return make_key_iterator<Policy>(std::begin(value), std::end(value), extra...); -} - -template <typename InputType, typename OutputType> void implicitly_convertible() { - struct set_flag { - bool &flag; - set_flag(bool &flag) : flag(flag) { flag = true; } - ~set_flag() { flag = false; } - }; - auto implicit_caster = [](PyObject *obj, PyTypeObject *type) -> PyObject * { - static bool currently_used = false; - if (currently_used) // implicit conversions are non-reentrant - return nullptr; - set_flag flag_helper(currently_used); - if (!detail::make_caster<InputType>().load(obj, false)) - return nullptr; - tuple args(1); - args[0] = obj; - PyObject *result = PyObject_Call((PyObject *) type, args.ptr(), nullptr); - if (result == nullptr) - PyErr_Clear(); - return result; - }; - - if (auto tinfo = detail::get_type_info(typeid(OutputType))) - tinfo->implicit_conversions.push_back(implicit_caster); - else - pybind11_fail("implicitly_convertible: Unable to find type " + type_id<OutputType>()); -} - -template <typename ExceptionTranslator> -void register_exception_translator(ExceptionTranslator&& translator) { - detail::get_internals().registered_exception_translators.push_front( - std::forward<ExceptionTranslator>(translator)); -} - -/** - * Wrapper to generate a new Python exception type. - * - * This should only be used with PyErr_SetString for now. - * It is not (yet) possible to use as a py::base. - * Template type argument is reserved for future use. - */ -template <typename type> -class exception : public object { -public: - exception() = default; - exception(handle scope, const char *name, PyObject *base = PyExc_Exception) { - std::string full_name = scope.attr("__name__").cast<std::string>() + - std::string(".") + name; - m_ptr = PyErr_NewException(const_cast<char *>(full_name.c_str()), base, NULL); - if (hasattr(scope, name)) - pybind11_fail("Error during initialization: multiple incompatible " - "definitions with name \"" + std::string(name) + "\""); - scope.attr(name) = *this; - } - - // Sets the current python exception to this exception object with the given message - void operator()(const char *message) { - PyErr_SetString(m_ptr, message); - } -}; - -NAMESPACE_BEGIN(detail) -// Returns a reference to a function-local static exception object used in the simple -// register_exception approach below. (It would be simpler to have the static local variable -// directly in register_exception, but that makes clang <3.5 segfault - issue #1349). -template <typename CppException> -exception<CppException> &get_exception_object() { static exception<CppException> ex; return ex; } -NAMESPACE_END(detail) - -/** - * Registers a Python exception in `m` of the given `name` and installs an exception translator to - * translate the C++ exception to the created Python exception using the exceptions what() method. - * This is intended for simple exception translations; for more complex translation, register the - * exception object and translator directly. - */ -template <typename CppException> -exception<CppException> ®ister_exception(handle scope, - const char *name, - PyObject *base = PyExc_Exception) { - auto &ex = detail::get_exception_object<CppException>(); - if (!ex) ex = exception<CppException>(scope, name, base); - - register_exception_translator([](std::exception_ptr p) { - if (!p) return; - try { - std::rethrow_exception(p); - } catch (const CppException &e) { - detail::get_exception_object<CppException>()(e.what()); - } - }); - return ex; -} - -NAMESPACE_BEGIN(detail) -PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) { - auto strings = tuple(args.size()); - for (size_t i = 0; i < args.size(); ++i) { - strings[i] = str(args[i]); - } - auto sep = kwargs.contains("sep") ? kwargs["sep"] : cast(" "); - auto line = sep.attr("join")(strings); - - object file; - if (kwargs.contains("file")) { - file = kwargs["file"].cast<object>(); - } else { - try { - file = module::import("sys").attr("stdout"); - } catch (const error_already_set &) { - /* If print() is called from code that is executed as - part of garbage collection during interpreter shutdown, - importing 'sys' can fail. Give up rather than crashing the - interpreter in this case. */ - return; - } - } - - auto write = file.attr("write"); - write(line); - write(kwargs.contains("end") ? kwargs["end"] : cast("\n")); - - if (kwargs.contains("flush") && kwargs["flush"].cast<bool>()) - file.attr("flush")(); -} -NAMESPACE_END(detail) - -template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args> -void print(Args &&...args) { - auto c = detail::collect_arguments<policy>(std::forward<Args>(args)...); - detail::print(c.args(), c.kwargs()); -} - -#if defined(WITH_THREAD) && !defined(PYPY_VERSION) - -/* The functions below essentially reproduce the PyGILState_* API using a RAII - * pattern, but there are a few important differences: - * - * 1. When acquiring the GIL from an non-main thread during the finalization - * phase, the GILState API blindly terminates the calling thread, which - * is often not what is wanted. This API does not do this. - * - * 2. The gil_scoped_release function can optionally cut the relationship - * of a PyThreadState and its associated thread, which allows moving it to - * another thread (this is a fairly rare/advanced use case). - * - * 3. The reference count of an acquired thread state can be controlled. This - * can be handy to prevent cases where callbacks issued from an external - * thread would otherwise constantly construct and destroy thread state data - * structures. - * - * See the Python bindings of NanoGUI (http://github.com/wjakob/nanogui) for an - * example which uses features 2 and 3 to migrate the Python thread of - * execution to another thread (to run the event loop on the original thread, - * in this case). - */ - -class gil_scoped_acquire { -public: - PYBIND11_NOINLINE gil_scoped_acquire() { - auto const &internals = detail::get_internals(); - tstate = (PyThreadState *) PYBIND11_TLS_GET_VALUE(internals.tstate); - - if (!tstate) { - /* Check if the GIL was acquired using the PyGILState_* API instead (e.g. if - calling from a Python thread). Since we use a different key, this ensures - we don't create a new thread state and deadlock in PyEval_AcquireThread - below. Note we don't save this state with internals.tstate, since we don't - create it we would fail to clear it (its reference count should be > 0). */ - tstate = PyGILState_GetThisThreadState(); - } - - if (!tstate) { - tstate = PyThreadState_New(internals.istate); - #if !defined(NDEBUG) - if (!tstate) - pybind11_fail("scoped_acquire: could not create thread state!"); - #endif - tstate->gilstate_counter = 0; - PYBIND11_TLS_REPLACE_VALUE(internals.tstate, tstate); - } else { - release = detail::get_thread_state_unchecked() != tstate; - } - - if (release) { - /* Work around an annoying assertion in PyThreadState_Swap */ - #if defined(Py_DEBUG) - PyInterpreterState *interp = tstate->interp; - tstate->interp = nullptr; - #endif - PyEval_AcquireThread(tstate); - #if defined(Py_DEBUG) - tstate->interp = interp; - #endif - } - - inc_ref(); - } - - void inc_ref() { - ++tstate->gilstate_counter; - } - - PYBIND11_NOINLINE void dec_ref() { - --tstate->gilstate_counter; - #if !defined(NDEBUG) - if (detail::get_thread_state_unchecked() != tstate) - pybind11_fail("scoped_acquire::dec_ref(): thread state must be current!"); - if (tstate->gilstate_counter < 0) - pybind11_fail("scoped_acquire::dec_ref(): reference count underflow!"); - #endif - if (tstate->gilstate_counter == 0) { - #if !defined(NDEBUG) - if (!release) - pybind11_fail("scoped_acquire::dec_ref(): internal error!"); - #endif - PyThreadState_Clear(tstate); - PyThreadState_DeleteCurrent(); - PYBIND11_TLS_DELETE_VALUE(detail::get_internals().tstate); - release = false; - } - } - - PYBIND11_NOINLINE ~gil_scoped_acquire() { - dec_ref(); - if (release) - PyEval_SaveThread(); - } -private: - PyThreadState *tstate = nullptr; - bool release = true; -}; - -class gil_scoped_release { -public: - explicit gil_scoped_release(bool disassoc = false) : disassoc(disassoc) { - // `get_internals()` must be called here unconditionally in order to initialize - // `internals.tstate` for subsequent `gil_scoped_acquire` calls. Otherwise, an - // initialization race could occur as multiple threads try `gil_scoped_acquire`. - const auto &internals = detail::get_internals(); - tstate = PyEval_SaveThread(); - if (disassoc) { - auto key = internals.tstate; - PYBIND11_TLS_DELETE_VALUE(key); - } - } - ~gil_scoped_release() { - if (!tstate) - return; - PyEval_RestoreThread(tstate); - if (disassoc) { - auto key = detail::get_internals().tstate; - PYBIND11_TLS_REPLACE_VALUE(key, tstate); - } - } -private: - PyThreadState *tstate; - bool disassoc; -}; -#elif defined(PYPY_VERSION) -class gil_scoped_acquire { - PyGILState_STATE state; -public: - gil_scoped_acquire() { state = PyGILState_Ensure(); } - ~gil_scoped_acquire() { PyGILState_Release(state); } -}; - -class gil_scoped_release { - PyThreadState *state; -public: - gil_scoped_release() { state = PyEval_SaveThread(); } - ~gil_scoped_release() { PyEval_RestoreThread(state); } -}; -#else -class gil_scoped_acquire { }; -class gil_scoped_release { }; -#endif - -error_already_set::~error_already_set() { - if (m_type) { - gil_scoped_acquire gil; - error_scope scope; - m_type.release().dec_ref(); - m_value.release().dec_ref(); - m_trace.release().dec_ref(); - } -} - -inline function get_type_overload(const void *this_ptr, const detail::type_info *this_type, const char *name) { - handle self = detail::get_object_handle(this_ptr, this_type); - if (!self) - return function(); - handle type = self.get_type(); - auto key = std::make_pair(type.ptr(), name); - - /* Cache functions that aren't overloaded in Python to avoid - many costly Python dictionary lookups below */ - auto &cache = detail::get_internals().inactive_overload_cache; - if (cache.find(key) != cache.end()) - return function(); - - function overload = getattr(self, name, function()); - if (overload.is_cpp_function()) { - cache.insert(key); - return function(); - } - - /* Don't call dispatch code if invoked from overridden function. - Unfortunately this doesn't work on PyPy. */ -#if !defined(PYPY_VERSION) - PyFrameObject *frame = PyThreadState_Get()->frame; - if (frame && (std::string) str(frame->f_code->co_name) == name && - frame->f_code->co_argcount > 0) { - PyFrame_FastToLocals(frame); - PyObject *self_caller = PyDict_GetItem( - frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0)); - if (self_caller == self.ptr()) - return function(); - } -#else - /* PyPy currently doesn't provide a detailed cpyext emulation of - frame objects, so we have to emulate this using Python. This - is going to be slow..*/ - dict d; d["self"] = self; d["name"] = pybind11::str(name); - PyObject *result = PyRun_String( - "import inspect\n" - "frame = inspect.currentframe()\n" - "if frame is not None:\n" - " frame = frame.f_back\n" - " if frame is not None and str(frame.f_code.co_name) == name and " - "frame.f_code.co_argcount > 0:\n" - " self_caller = frame.f_locals[frame.f_code.co_varnames[0]]\n" - " if self_caller == self:\n" - " self = None\n", - Py_file_input, d.ptr(), d.ptr()); - if (result == nullptr) - throw error_already_set(); - if (d["self"].is_none()) - return function(); - Py_DECREF(result); -#endif - - return overload; -} - -/** \rst - Try to retrieve a python method by the provided name from the instance pointed to by the this_ptr. - - :this_ptr: The pointer to the object the overload should be retrieved for. This should be the first - non-trampoline class encountered in the inheritance chain. - :name: The name of the overloaded Python method to retrieve. - :return: The Python method by this name from the object or an empty function wrapper. - \endrst */ -template <class T> function get_overload(const T *this_ptr, const char *name) { - auto tinfo = detail::get_type_info(typeid(T)); - return tinfo ? get_type_overload(this_ptr, tinfo, name) : function(); -} - -#define PYBIND11_OVERLOAD_INT(ret_type, cname, name, ...) { \ - pybind11::gil_scoped_acquire gil; \ - pybind11::function overload = pybind11::get_overload(static_cast<const cname *>(this), name); \ - if (overload) { \ - auto o = overload(__VA_ARGS__); \ - if (pybind11::detail::cast_is_temporary_value_reference<ret_type>::value) { \ - static pybind11::detail::overload_caster_t<ret_type> caster; \ - return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \ - } \ - else return pybind11::detail::cast_safe<ret_type>(std::move(o)); \ - } \ - } - -/** \rst - Macro to populate the virtual method in the trampoline class. This macro tries to look up a method named 'fn' - from the Python side, deals with the :ref:`gil` and necessary argument conversions to call this method and return - the appropriate type. See :ref:`overriding_virtuals` for more information. This macro should be used when the method - name in C is not the same as the method name in Python. For example with `__str__`. - - .. code-block:: cpp - - std::string toString() override { - PYBIND11_OVERLOAD_NAME( - std::string, // Return type (ret_type) - Animal, // Parent class (cname) - toString, // Name of function in C++ (name) - "__str__", // Name of method in Python (fn) - ); - } -\endrst */ -#define PYBIND11_OVERLOAD_NAME(ret_type, cname, name, fn, ...) \ - PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \ - return cname::fn(__VA_ARGS__) - -/** \rst - Macro for pure virtual functions, this function is identical to :c:macro:`PYBIND11_OVERLOAD_NAME`, except that it - throws if no overload can be found. -\endrst */ -#define PYBIND11_OVERLOAD_PURE_NAME(ret_type, cname, name, fn, ...) \ - PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \ - pybind11::pybind11_fail("Tried to call pure virtual function \"" PYBIND11_STRINGIFY(cname) "::" name "\""); - -/** \rst - Macro to populate the virtual method in the trampoline class. This macro tries to look up the method - from the Python side, deals with the :ref:`gil` and necessary argument conversions to call this method and return - the appropriate type. This macro should be used if the method name in C and in Python are identical. - See :ref:`overriding_virtuals` for more information. - - .. code-block:: cpp - - class PyAnimal : public Animal { - public: - // Inherit the constructors - using Animal::Animal; - - // Trampoline (need one for each virtual function) - std::string go(int n_times) override { - PYBIND11_OVERLOAD_PURE( - std::string, // Return type (ret_type) - Animal, // Parent class (cname) - go, // Name of function in C++ (must match Python name) (fn) - n_times // Argument(s) (...) - ); - } - }; -\endrst */ -#define PYBIND11_OVERLOAD(ret_type, cname, fn, ...) \ - PYBIND11_OVERLOAD_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__) - -/** \rst - Macro for pure virtual functions, this function is identical to :c:macro:`PYBIND11_OVERLOAD`, except that it throws - if no overload can be found. -\endrst */ -#define PYBIND11_OVERLOAD_PURE(ret_type, cname, fn, ...) \ - PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__) - -NAMESPACE_END(PYBIND11_NAMESPACE) - -#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) -# pragma warning(pop) -#elif defined(__GNUG__) && !defined(__clang__) -# pragma GCC diagnostic pop -#endif diff --git a/external/pybind11/include/pybind11/pytypes.h b/external/pybind11/include/pybind11/pytypes.h deleted file mode 100644 index 96eab966..00000000 --- a/external/pybind11/include/pybind11/pytypes.h +++ /dev/null @@ -1,1484 +0,0 @@ -/* - pybind11/pytypes.h: Convenience wrapper classes for basic Python types - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "detail/common.h" -#include "buffer_info.h" -#include <utility> -#include <type_traits> - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) - -/* A few forward declarations */ -class handle; class object; -class str; class iterator; -struct arg; struct arg_v; - -NAMESPACE_BEGIN(detail) -class args_proxy; -inline bool isinstance_generic(handle obj, const std::type_info &tp); - -// Accessor forward declarations -template <typename Policy> class accessor; -namespace accessor_policies { - struct obj_attr; - struct str_attr; - struct generic_item; - struct sequence_item; - struct list_item; - struct tuple_item; -} -using obj_attr_accessor = accessor<accessor_policies::obj_attr>; -using str_attr_accessor = accessor<accessor_policies::str_attr>; -using item_accessor = accessor<accessor_policies::generic_item>; -using sequence_accessor = accessor<accessor_policies::sequence_item>; -using list_accessor = accessor<accessor_policies::list_item>; -using tuple_accessor = accessor<accessor_policies::tuple_item>; - -/// Tag and check to identify a class which implements the Python object API -class pyobject_tag { }; -template <typename T> using is_pyobject = std::is_base_of<pyobject_tag, remove_reference_t<T>>; - -/** \rst - A mixin class which adds common functions to `handle`, `object` and various accessors. - The only requirement for `Derived` is to implement ``PyObject *Derived::ptr() const``. -\endrst */ -template <typename Derived> -class object_api : public pyobject_tag { - const Derived &derived() const { return static_cast<const Derived &>(*this); } - -public: - /** \rst - Return an iterator equivalent to calling ``iter()`` in Python. The object - must be a collection which supports the iteration protocol. - \endrst */ - iterator begin() const; - /// Return a sentinel which ends iteration. - iterator end() const; - - /** \rst - Return an internal functor to invoke the object's sequence protocol. Casting - the returned ``detail::item_accessor`` instance to a `handle` or `object` - subclass causes a corresponding call to ``__getitem__``. Assigning a `handle` - or `object` subclass causes a call to ``__setitem__``. - \endrst */ - item_accessor operator[](handle key) const; - /// See above (the only difference is that they key is provided as a string literal) - item_accessor operator[](const char *key) const; - - /** \rst - Return an internal functor to access the object's attributes. Casting the - returned ``detail::obj_attr_accessor`` instance to a `handle` or `object` - subclass causes a corresponding call to ``getattr``. Assigning a `handle` - or `object` subclass causes a call to ``setattr``. - \endrst */ - obj_attr_accessor attr(handle key) const; - /// See above (the only difference is that they key is provided as a string literal) - str_attr_accessor attr(const char *key) const; - - /** \rst - Matches * unpacking in Python, e.g. to unpack arguments out of a ``tuple`` - or ``list`` for a function call. Applying another * to the result yields - ** unpacking, e.g. to unpack a dict as function keyword arguments. - See :ref:`calling_python_functions`. - \endrst */ - args_proxy operator*() const; - - /// Check if the given item is contained within this object, i.e. ``item in obj``. - template <typename T> bool contains(T &&item) const; - - /** \rst - Assuming the Python object is a function or implements the ``__call__`` - protocol, ``operator()`` invokes the underlying function, passing an - arbitrary set of parameters. The result is returned as a `object` and - may need to be converted back into a Python object using `handle::cast()`. - - When some of the arguments cannot be converted to Python objects, the - function will throw a `cast_error` exception. When the Python function - call fails, a `error_already_set` exception is thrown. - \endrst */ - template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args> - object operator()(Args &&...args) const; - template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args> - PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)") - object call(Args&&... args) const; - - /// Equivalent to ``obj is other`` in Python. - bool is(object_api const& other) const { return derived().ptr() == other.derived().ptr(); } - /// Equivalent to ``obj is None`` in Python. - bool is_none() const { return derived().ptr() == Py_None; } - /// Equivalent to obj == other in Python - bool equal(object_api const &other) const { return rich_compare(other, Py_EQ); } - bool not_equal(object_api const &other) const { return rich_compare(other, Py_NE); } - bool operator<(object_api const &other) const { return rich_compare(other, Py_LT); } - bool operator<=(object_api const &other) const { return rich_compare(other, Py_LE); } - bool operator>(object_api const &other) const { return rich_compare(other, Py_GT); } - bool operator>=(object_api const &other) const { return rich_compare(other, Py_GE); } - - object operator-() const; - object operator~() const; - object operator+(object_api const &other) const; - object operator+=(object_api const &other) const; - object operator-(object_api const &other) const; - object operator-=(object_api const &other) const; - object operator*(object_api const &other) const; - object operator*=(object_api const &other) const; - object operator/(object_api const &other) const; - object operator/=(object_api const &other) const; - object operator|(object_api const &other) const; - object operator|=(object_api const &other) const; - object operator&(object_api const &other) const; - object operator&=(object_api const &other) const; - object operator^(object_api const &other) const; - object operator^=(object_api const &other) const; - object operator<<(object_api const &other) const; - object operator<<=(object_api const &other) const; - object operator>>(object_api const &other) const; - object operator>>=(object_api const &other) const; - - PYBIND11_DEPRECATED("Use py::str(obj) instead") - pybind11::str str() const; - - /// Get or set the object's docstring, i.e. ``obj.__doc__``. - str_attr_accessor doc() const; - - /// Return the object's current reference count - int ref_count() const { return static_cast<int>(Py_REFCNT(derived().ptr())); } - /// Return a handle to the Python type object underlying the instance - handle get_type() const; - -private: - bool rich_compare(object_api const &other, int value) const; -}; - -NAMESPACE_END(detail) - -/** \rst - Holds a reference to a Python object (no reference counting) - - The `handle` class is a thin wrapper around an arbitrary Python object (i.e. a - ``PyObject *`` in Python's C API). It does not perform any automatic reference - counting and merely provides a basic C++ interface to various Python API functions. - - .. seealso:: - The `object` class inherits from `handle` and adds automatic reference - counting features. -\endrst */ -class handle : public detail::object_api<handle> { -public: - /// The default constructor creates a handle with a ``nullptr``-valued pointer - handle() = default; - /// Creates a ``handle`` from the given raw Python object pointer - handle(PyObject *ptr) : m_ptr(ptr) { } // Allow implicit conversion from PyObject* - - /// Return the underlying ``PyObject *`` pointer - PyObject *ptr() const { return m_ptr; } - PyObject *&ptr() { return m_ptr; } - - /** \rst - Manually increase the reference count of the Python object. Usually, it is - preferable to use the `object` class which derives from `handle` and calls - this function automatically. Returns a reference to itself. - \endrst */ - const handle& inc_ref() const & { Py_XINCREF(m_ptr); return *this; } - - /** \rst - Manually decrease the reference count of the Python object. Usually, it is - preferable to use the `object` class which derives from `handle` and calls - this function automatically. Returns a reference to itself. - \endrst */ - const handle& dec_ref() const & { Py_XDECREF(m_ptr); return *this; } - - /** \rst - Attempt to cast the Python object into the given C++ type. A `cast_error` - will be throw upon failure. - \endrst */ - template <typename T> T cast() const; - /// Return ``true`` when the `handle` wraps a valid Python object - explicit operator bool() const { return m_ptr != nullptr; } - /** \rst - Deprecated: Check that the underlying pointers are the same. - Equivalent to ``obj1 is obj2`` in Python. - \endrst */ - PYBIND11_DEPRECATED("Use obj1.is(obj2) instead") - bool operator==(const handle &h) const { return m_ptr == h.m_ptr; } - PYBIND11_DEPRECATED("Use !obj1.is(obj2) instead") - bool operator!=(const handle &h) const { return m_ptr != h.m_ptr; } - PYBIND11_DEPRECATED("Use handle::operator bool() instead") - bool check() const { return m_ptr != nullptr; } -protected: - PyObject *m_ptr = nullptr; -}; - -/** \rst - Holds a reference to a Python object (with reference counting) - - Like `handle`, the `object` class is a thin wrapper around an arbitrary Python - object (i.e. a ``PyObject *`` in Python's C API). In contrast to `handle`, it - optionally increases the object's reference count upon construction, and it - *always* decreases the reference count when the `object` instance goes out of - scope and is destructed. When using `object` instances consistently, it is much - easier to get reference counting right at the first attempt. -\endrst */ -class object : public handle { -public: - object() = default; - PYBIND11_DEPRECATED("Use reinterpret_borrow<object>() or reinterpret_steal<object>()") - object(handle h, bool is_borrowed) : handle(h) { if (is_borrowed) inc_ref(); } - /// Copy constructor; always increases the reference count - object(const object &o) : handle(o) { inc_ref(); } - /// Move constructor; steals the object from ``other`` and preserves its reference count - object(object &&other) noexcept { m_ptr = other.m_ptr; other.m_ptr = nullptr; } - /// Destructor; automatically calls `handle::dec_ref()` - ~object() { dec_ref(); } - - /** \rst - Resets the internal pointer to ``nullptr`` without without decreasing the - object's reference count. The function returns a raw handle to the original - Python object. - \endrst */ - handle release() { - PyObject *tmp = m_ptr; - m_ptr = nullptr; - return handle(tmp); - } - - object& operator=(const object &other) { - other.inc_ref(); - dec_ref(); - m_ptr = other.m_ptr; - return *this; - } - - object& operator=(object &&other) noexcept { - if (this != &other) { - handle temp(m_ptr); - m_ptr = other.m_ptr; - other.m_ptr = nullptr; - temp.dec_ref(); - } - return *this; - } - - // Calling cast() on an object lvalue just copies (via handle::cast) - template <typename T> T cast() const &; - // Calling on an object rvalue does a move, if needed and/or possible - template <typename T> T cast() &&; - -protected: - // Tags for choosing constructors from raw PyObject * - struct borrowed_t { }; - struct stolen_t { }; - - template <typename T> friend T reinterpret_borrow(handle); - template <typename T> friend T reinterpret_steal(handle); - -public: - // Only accessible from derived classes and the reinterpret_* functions - object(handle h, borrowed_t) : handle(h) { inc_ref(); } - object(handle h, stolen_t) : handle(h) { } -}; - -/** \rst - Declare that a `handle` or ``PyObject *`` is a certain type and borrow the reference. - The target type ``T`` must be `object` or one of its derived classes. The function - doesn't do any conversions or checks. It's up to the user to make sure that the - target type is correct. - - .. code-block:: cpp - - PyObject *p = PyList_GetItem(obj, index); - py::object o = reinterpret_borrow<py::object>(p); - // or - py::tuple t = reinterpret_borrow<py::tuple>(p); // <-- `p` must be already be a `tuple` -\endrst */ -template <typename T> T reinterpret_borrow(handle h) { return {h, object::borrowed_t{}}; } - -/** \rst - Like `reinterpret_borrow`, but steals the reference. - - .. code-block:: cpp - - PyObject *p = PyObject_Str(obj); - py::str s = reinterpret_steal<py::str>(p); // <-- `p` must be already be a `str` -\endrst */ -template <typename T> T reinterpret_steal(handle h) { return {h, object::stolen_t{}}; } - -NAMESPACE_BEGIN(detail) -inline std::string error_string(); -NAMESPACE_END(detail) - -/// Fetch and hold an error which was already set in Python. An instance of this is typically -/// thrown to propagate python-side errors back through C++ which can either be caught manually or -/// else falls back to the function dispatcher (which then raises the captured error back to -/// python). -class error_already_set : public std::runtime_error { -public: - /// Constructs a new exception from the current Python error indicator, if any. The current - /// Python error indicator will be cleared. - error_already_set() : std::runtime_error(detail::error_string()) { - PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); - } - - error_already_set(const error_already_set &) = default; - error_already_set(error_already_set &&) = default; - - inline ~error_already_set(); - - /// Give the currently-held error back to Python, if any. If there is currently a Python error - /// already set it is cleared first. After this call, the current object no longer stores the - /// error variables (but the `.what()` string is still available). - void restore() { PyErr_Restore(m_type.release().ptr(), m_value.release().ptr(), m_trace.release().ptr()); } - - // Does nothing; provided for backwards compatibility. - PYBIND11_DEPRECATED("Use of error_already_set.clear() is deprecated") - void clear() {} - - /// Check if the currently trapped error type matches the given Python exception class (or a - /// subclass thereof). May also be passed a tuple to search for any exception class matches in - /// the given tuple. - bool matches(handle exc) const { return PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()); } - - const object& type() const { return m_type; } - const object& value() const { return m_value; } - const object& trace() const { return m_trace; } - -private: - object m_type, m_value, m_trace; -}; - -/** \defgroup python_builtins _ - Unless stated otherwise, the following C++ functions behave the same - as their Python counterparts. - */ - -/** \ingroup python_builtins - \rst - Return true if ``obj`` is an instance of ``T``. Type ``T`` must be a subclass of - `object` or a class which was exposed to Python as ``py::class_<T>``. -\endrst */ -template <typename T, detail::enable_if_t<std::is_base_of<object, T>::value, int> = 0> -bool isinstance(handle obj) { return T::check_(obj); } - -template <typename T, detail::enable_if_t<!std::is_base_of<object, T>::value, int> = 0> -bool isinstance(handle obj) { return detail::isinstance_generic(obj, typeid(T)); } - -template <> inline bool isinstance<handle>(handle obj) = delete; -template <> inline bool isinstance<object>(handle obj) { return obj.ptr() != nullptr; } - -/// \ingroup python_builtins -/// Return true if ``obj`` is an instance of the ``type``. -inline bool isinstance(handle obj, handle type) { - const auto result = PyObject_IsInstance(obj.ptr(), type.ptr()); - if (result == -1) - throw error_already_set(); - return result != 0; -} - -/// \addtogroup python_builtins -/// @{ -inline bool hasattr(handle obj, handle name) { - return PyObject_HasAttr(obj.ptr(), name.ptr()) == 1; -} - -inline bool hasattr(handle obj, const char *name) { - return PyObject_HasAttrString(obj.ptr(), name) == 1; -} - -inline void delattr(handle obj, handle name) { - if (PyObject_DelAttr(obj.ptr(), name.ptr()) != 0) { throw error_already_set(); } -} - -inline void delattr(handle obj, const char *name) { - if (PyObject_DelAttrString(obj.ptr(), name) != 0) { throw error_already_set(); } -} - -inline object getattr(handle obj, handle name) { - PyObject *result = PyObject_GetAttr(obj.ptr(), name.ptr()); - if (!result) { throw error_already_set(); } - return reinterpret_steal<object>(result); -} - -inline object getattr(handle obj, const char *name) { - PyObject *result = PyObject_GetAttrString(obj.ptr(), name); - if (!result) { throw error_already_set(); } - return reinterpret_steal<object>(result); -} - -inline object getattr(handle obj, handle name, handle default_) { - if (PyObject *result = PyObject_GetAttr(obj.ptr(), name.ptr())) { - return reinterpret_steal<object>(result); - } else { - PyErr_Clear(); - return reinterpret_borrow<object>(default_); - } -} - -inline object getattr(handle obj, const char *name, handle default_) { - if (PyObject *result = PyObject_GetAttrString(obj.ptr(), name)) { - return reinterpret_steal<object>(result); - } else { - PyErr_Clear(); - return reinterpret_borrow<object>(default_); - } -} - -inline void setattr(handle obj, handle name, handle value) { - if (PyObject_SetAttr(obj.ptr(), name.ptr(), value.ptr()) != 0) { throw error_already_set(); } -} - -inline void setattr(handle obj, const char *name, handle value) { - if (PyObject_SetAttrString(obj.ptr(), name, value.ptr()) != 0) { throw error_already_set(); } -} - -inline ssize_t hash(handle obj) { - auto h = PyObject_Hash(obj.ptr()); - if (h == -1) { throw error_already_set(); } - return h; -} - -/// @} python_builtins - -NAMESPACE_BEGIN(detail) -inline handle get_function(handle value) { - if (value) { -#if PY_MAJOR_VERSION >= 3 - if (PyInstanceMethod_Check(value.ptr())) - value = PyInstanceMethod_GET_FUNCTION(value.ptr()); - else -#endif - if (PyMethod_Check(value.ptr())) - value = PyMethod_GET_FUNCTION(value.ptr()); - } - return value; -} - -// Helper aliases/functions to support implicit casting of values given to python accessors/methods. -// When given a pyobject, this simply returns the pyobject as-is; for other C++ type, the value goes -// through pybind11::cast(obj) to convert it to an `object`. -template <typename T, enable_if_t<is_pyobject<T>::value, int> = 0> -auto object_or_cast(T &&o) -> decltype(std::forward<T>(o)) { return std::forward<T>(o); } -// The following casting version is implemented in cast.h: -template <typename T, enable_if_t<!is_pyobject<T>::value, int> = 0> -object object_or_cast(T &&o); -// Match a PyObject*, which we want to convert directly to handle via its converting constructor -inline handle object_or_cast(PyObject *ptr) { return ptr; } - -template <typename Policy> -class accessor : public object_api<accessor<Policy>> { - using key_type = typename Policy::key_type; - -public: - accessor(handle obj, key_type key) : obj(obj), key(std::move(key)) { } - accessor(const accessor &) = default; - accessor(accessor &&) = default; - - // accessor overload required to override default assignment operator (templates are not allowed - // to replace default compiler-generated assignments). - void operator=(const accessor &a) && { std::move(*this).operator=(handle(a)); } - void operator=(const accessor &a) & { operator=(handle(a)); } - - template <typename T> void operator=(T &&value) && { - Policy::set(obj, key, object_or_cast(std::forward<T>(value))); - } - template <typename T> void operator=(T &&value) & { - get_cache() = reinterpret_borrow<object>(object_or_cast(std::forward<T>(value))); - } - - template <typename T = Policy> - PYBIND11_DEPRECATED("Use of obj.attr(...) as bool is deprecated in favor of pybind11::hasattr(obj, ...)") - explicit operator enable_if_t<std::is_same<T, accessor_policies::str_attr>::value || - std::is_same<T, accessor_policies::obj_attr>::value, bool>() const { - return hasattr(obj, key); - } - template <typename T = Policy> - PYBIND11_DEPRECATED("Use of obj[key] as bool is deprecated in favor of obj.contains(key)") - explicit operator enable_if_t<std::is_same<T, accessor_policies::generic_item>::value, bool>() const { - return obj.contains(key); - } - - operator object() const { return get_cache(); } - PyObject *ptr() const { return get_cache().ptr(); } - template <typename T> T cast() const { return get_cache().template cast<T>(); } - -private: - object &get_cache() const { - if (!cache) { cache = Policy::get(obj, key); } - return cache; - } - -private: - handle obj; - key_type key; - mutable object cache; -}; - -NAMESPACE_BEGIN(accessor_policies) -struct obj_attr { - using key_type = object; - static object get(handle obj, handle key) { return getattr(obj, key); } - static void set(handle obj, handle key, handle val) { setattr(obj, key, val); } -}; - -struct str_attr { - using key_type = const char *; - static object get(handle obj, const char *key) { return getattr(obj, key); } - static void set(handle obj, const char *key, handle val) { setattr(obj, key, val); } -}; - -struct generic_item { - using key_type = object; - - static object get(handle obj, handle key) { - PyObject *result = PyObject_GetItem(obj.ptr(), key.ptr()); - if (!result) { throw error_already_set(); } - return reinterpret_steal<object>(result); - } - - static void set(handle obj, handle key, handle val) { - if (PyObject_SetItem(obj.ptr(), key.ptr(), val.ptr()) != 0) { throw error_already_set(); } - } -}; - -struct sequence_item { - using key_type = size_t; - - static object get(handle obj, size_t index) { - PyObject *result = PySequence_GetItem(obj.ptr(), static_cast<ssize_t>(index)); - if (!result) { throw error_already_set(); } - return reinterpret_steal<object>(result); - } - - static void set(handle obj, size_t index, handle val) { - // PySequence_SetItem does not steal a reference to 'val' - if (PySequence_SetItem(obj.ptr(), static_cast<ssize_t>(index), val.ptr()) != 0) { - throw error_already_set(); - } - } -}; - -struct list_item { - using key_type = size_t; - - static object get(handle obj, size_t index) { - PyObject *result = PyList_GetItem(obj.ptr(), static_cast<ssize_t>(index)); - if (!result) { throw error_already_set(); } - return reinterpret_borrow<object>(result); - } - - static void set(handle obj, size_t index, handle val) { - // PyList_SetItem steals a reference to 'val' - if (PyList_SetItem(obj.ptr(), static_cast<ssize_t>(index), val.inc_ref().ptr()) != 0) { - throw error_already_set(); - } - } -}; - -struct tuple_item { - using key_type = size_t; - - static object get(handle obj, size_t index) { - PyObject *result = PyTuple_GetItem(obj.ptr(), static_cast<ssize_t>(index)); - if (!result) { throw error_already_set(); } - return reinterpret_borrow<object>(result); - } - - static void set(handle obj, size_t index, handle val) { - // PyTuple_SetItem steals a reference to 'val' - if (PyTuple_SetItem(obj.ptr(), static_cast<ssize_t>(index), val.inc_ref().ptr()) != 0) { - throw error_already_set(); - } - } -}; -NAMESPACE_END(accessor_policies) - -/// STL iterator template used for tuple, list, sequence and dict -template <typename Policy> -class generic_iterator : public Policy { - using It = generic_iterator; - -public: - using difference_type = ssize_t; - using iterator_category = typename Policy::iterator_category; - using value_type = typename Policy::value_type; - using reference = typename Policy::reference; - using pointer = typename Policy::pointer; - - generic_iterator() = default; - generic_iterator(handle seq, ssize_t index) : Policy(seq, index) { } - - reference operator*() const { return Policy::dereference(); } - reference operator[](difference_type n) const { return *(*this + n); } - pointer operator->() const { return **this; } - - It &operator++() { Policy::increment(); return *this; } - It operator++(int) { auto copy = *this; Policy::increment(); return copy; } - It &operator--() { Policy::decrement(); return *this; } - It operator--(int) { auto copy = *this; Policy::decrement(); return copy; } - It &operator+=(difference_type n) { Policy::advance(n); return *this; } - It &operator-=(difference_type n) { Policy::advance(-n); return *this; } - - friend It operator+(const It &a, difference_type n) { auto copy = a; return copy += n; } - friend It operator+(difference_type n, const It &b) { return b + n; } - friend It operator-(const It &a, difference_type n) { auto copy = a; return copy -= n; } - friend difference_type operator-(const It &a, const It &b) { return a.distance_to(b); } - - friend bool operator==(const It &a, const It &b) { return a.equal(b); } - friend bool operator!=(const It &a, const It &b) { return !(a == b); } - friend bool operator< (const It &a, const It &b) { return b - a > 0; } - friend bool operator> (const It &a, const It &b) { return b < a; } - friend bool operator>=(const It &a, const It &b) { return !(a < b); } - friend bool operator<=(const It &a, const It &b) { return !(a > b); } -}; - -NAMESPACE_BEGIN(iterator_policies) -/// Quick proxy class needed to implement ``operator->`` for iterators which can't return pointers -template <typename T> -struct arrow_proxy { - T value; - - arrow_proxy(T &&value) : value(std::move(value)) { } - T *operator->() const { return &value; } -}; - -/// Lightweight iterator policy using just a simple pointer: see ``PySequence_Fast_ITEMS`` -class sequence_fast_readonly { -protected: - using iterator_category = std::random_access_iterator_tag; - using value_type = handle; - using reference = const handle; - using pointer = arrow_proxy<const handle>; - - sequence_fast_readonly(handle obj, ssize_t n) : ptr(PySequence_Fast_ITEMS(obj.ptr()) + n) { } - - reference dereference() const { return *ptr; } - void increment() { ++ptr; } - void decrement() { --ptr; } - void advance(ssize_t n) { ptr += n; } - bool equal(const sequence_fast_readonly &b) const { return ptr == b.ptr; } - ssize_t distance_to(const sequence_fast_readonly &b) const { return ptr - b.ptr; } - -private: - PyObject **ptr; -}; - -/// Full read and write access using the sequence protocol: see ``detail::sequence_accessor`` -class sequence_slow_readwrite { -protected: - using iterator_category = std::random_access_iterator_tag; - using value_type = object; - using reference = sequence_accessor; - using pointer = arrow_proxy<const sequence_accessor>; - - sequence_slow_readwrite(handle obj, ssize_t index) : obj(obj), index(index) { } - - reference dereference() const { return {obj, static_cast<size_t>(index)}; } - void increment() { ++index; } - void decrement() { --index; } - void advance(ssize_t n) { index += n; } - bool equal(const sequence_slow_readwrite &b) const { return index == b.index; } - ssize_t distance_to(const sequence_slow_readwrite &b) const { return index - b.index; } - -private: - handle obj; - ssize_t index; -}; - -/// Python's dictionary protocol permits this to be a forward iterator -class dict_readonly { -protected: - using iterator_category = std::forward_iterator_tag; - using value_type = std::pair<handle, handle>; - using reference = const value_type; - using pointer = arrow_proxy<const value_type>; - - dict_readonly() = default; - dict_readonly(handle obj, ssize_t pos) : obj(obj), pos(pos) { increment(); } - - reference dereference() const { return {key, value}; } - void increment() { if (!PyDict_Next(obj.ptr(), &pos, &key, &value)) { pos = -1; } } - bool equal(const dict_readonly &b) const { return pos == b.pos; } - -private: - handle obj; - PyObject *key = nullptr, *value = nullptr; - ssize_t pos = -1; -}; -NAMESPACE_END(iterator_policies) - -#if !defined(PYPY_VERSION) -using tuple_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>; -using list_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>; -#else -using tuple_iterator = generic_iterator<iterator_policies::sequence_slow_readwrite>; -using list_iterator = generic_iterator<iterator_policies::sequence_slow_readwrite>; -#endif - -using sequence_iterator = generic_iterator<iterator_policies::sequence_slow_readwrite>; -using dict_iterator = generic_iterator<iterator_policies::dict_readonly>; - -inline bool PyIterable_Check(PyObject *obj) { - PyObject *iter = PyObject_GetIter(obj); - if (iter) { - Py_DECREF(iter); - return true; - } else { - PyErr_Clear(); - return false; - } -} - -inline bool PyNone_Check(PyObject *o) { return o == Py_None; } -#if PY_MAJOR_VERSION >= 3 -inline bool PyEllipsis_Check(PyObject *o) { return o == Py_Ellipsis; } -#endif - -inline bool PyUnicode_Check_Permissive(PyObject *o) { return PyUnicode_Check(o) || PYBIND11_BYTES_CHECK(o); } - -inline bool PyStaticMethod_Check(PyObject *o) { return o->ob_type == &PyStaticMethod_Type; } - -class kwargs_proxy : public handle { -public: - explicit kwargs_proxy(handle h) : handle(h) { } -}; - -class args_proxy : public handle { -public: - explicit args_proxy(handle h) : handle(h) { } - kwargs_proxy operator*() const { return kwargs_proxy(*this); } -}; - -/// Python argument categories (using PEP 448 terms) -template <typename T> using is_keyword = std::is_base_of<arg, T>; -template <typename T> using is_s_unpacking = std::is_same<args_proxy, T>; // * unpacking -template <typename T> using is_ds_unpacking = std::is_same<kwargs_proxy, T>; // ** unpacking -template <typename T> using is_positional = satisfies_none_of<T, - is_keyword, is_s_unpacking, is_ds_unpacking ->; -template <typename T> using is_keyword_or_ds = satisfies_any_of<T, is_keyword, is_ds_unpacking>; - -// Call argument collector forward declarations -template <return_value_policy policy = return_value_policy::automatic_reference> -class simple_collector; -template <return_value_policy policy = return_value_policy::automatic_reference> -class unpacking_collector; - -NAMESPACE_END(detail) - -// TODO: After the deprecated constructors are removed, this macro can be simplified by -// inheriting ctors: `using Parent::Parent`. It's not an option right now because -// the `using` statement triggers the parent deprecation warning even if the ctor -// isn't even used. -#define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ - public: \ - PYBIND11_DEPRECATED("Use reinterpret_borrow<"#Name">() or reinterpret_steal<"#Name">()") \ - Name(handle h, bool is_borrowed) : Parent(is_borrowed ? Parent(h, borrowed_t{}) : Parent(h, stolen_t{})) { } \ - Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) { } \ - Name(handle h, stolen_t) : Parent(h, stolen_t{}) { } \ - PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \ - bool check() const { return m_ptr != nullptr && (bool) CheckFun(m_ptr); } \ - static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } - -#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \ - PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ - /* This is deliberately not 'explicit' to allow implicit conversion from object: */ \ - Name(const object &o) \ - : Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) \ - { if (!m_ptr) throw error_already_set(); } \ - Name(object &&o) \ - : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) \ - { if (!m_ptr) throw error_already_set(); } \ - template <typename Policy_> \ - Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) { } - -#define PYBIND11_OBJECT(Name, Parent, CheckFun) \ - PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ - /* This is deliberately not 'explicit' to allow implicit conversion from object: */ \ - Name(const object &o) : Parent(o) { } \ - Name(object &&o) : Parent(std::move(o)) { } - -#define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun) \ - PYBIND11_OBJECT(Name, Parent, CheckFun) \ - Name() : Parent() { } - -/// \addtogroup pytypes -/// @{ - -/** \rst - Wraps a Python iterator so that it can also be used as a C++ input iterator - - Caveat: copying an iterator does not (and cannot) clone the internal - state of the Python iterable. This also applies to the post-increment - operator. This iterator should only be used to retrieve the current - value using ``operator*()``. -\endrst */ -class iterator : public object { -public: - using iterator_category = std::input_iterator_tag; - using difference_type = ssize_t; - using value_type = handle; - using reference = const handle; - using pointer = const handle *; - - PYBIND11_OBJECT_DEFAULT(iterator, object, PyIter_Check) - - iterator& operator++() { - advance(); - return *this; - } - - iterator operator++(int) { - auto rv = *this; - advance(); - return rv; - } - - reference operator*() const { - if (m_ptr && !value.ptr()) { - auto& self = const_cast<iterator &>(*this); - self.advance(); - } - return value; - } - - pointer operator->() const { operator*(); return &value; } - - /** \rst - The value which marks the end of the iteration. ``it == iterator::sentinel()`` - is equivalent to catching ``StopIteration`` in Python. - - .. code-block:: cpp - - void foo(py::iterator it) { - while (it != py::iterator::sentinel()) { - // use `*it` - ++it; - } - } - \endrst */ - static iterator sentinel() { return {}; } - - friend bool operator==(const iterator &a, const iterator &b) { return a->ptr() == b->ptr(); } - friend bool operator!=(const iterator &a, const iterator &b) { return a->ptr() != b->ptr(); } - -private: - void advance() { - value = reinterpret_steal<object>(PyIter_Next(m_ptr)); - if (PyErr_Occurred()) { throw error_already_set(); } - } - -private: - object value = {}; -}; - -class iterable : public object { -public: - PYBIND11_OBJECT_DEFAULT(iterable, object, detail::PyIterable_Check) -}; - -class bytes; - -class str : public object { -public: - PYBIND11_OBJECT_CVT(str, object, detail::PyUnicode_Check_Permissive, raw_str) - - str(const char *c, size_t n) - : object(PyUnicode_FromStringAndSize(c, (ssize_t) n), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate string object!"); - } - - // 'explicit' is explicitly omitted from the following constructors to allow implicit conversion to py::str from C++ string-like objects - str(const char *c = "") - : object(PyUnicode_FromString(c), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate string object!"); - } - - str(const std::string &s) : str(s.data(), s.size()) { } - - explicit str(const bytes &b); - - /** \rst - Return a string representation of the object. This is analogous to - the ``str()`` function in Python. - \endrst */ - explicit str(handle h) : object(raw_str(h.ptr()), stolen_t{}) { } - - operator std::string() const { - object temp = *this; - if (PyUnicode_Check(m_ptr)) { - temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(m_ptr)); - if (!temp) - pybind11_fail("Unable to extract string contents! (encoding issue)"); - } - char *buffer; - ssize_t length; - if (PYBIND11_BYTES_AS_STRING_AND_SIZE(temp.ptr(), &buffer, &length)) - pybind11_fail("Unable to extract string contents! (invalid type)"); - return std::string(buffer, (size_t) length); - } - - template <typename... Args> - str format(Args &&...args) const { - return attr("format")(std::forward<Args>(args)...); - } - -private: - /// Return string representation -- always returns a new reference, even if already a str - static PyObject *raw_str(PyObject *op) { - PyObject *str_value = PyObject_Str(op); -#if PY_MAJOR_VERSION < 3 - if (!str_value) throw error_already_set(); - PyObject *unicode = PyUnicode_FromEncodedObject(str_value, "utf-8", nullptr); - Py_XDECREF(str_value); str_value = unicode; -#endif - return str_value; - } -}; -/// @} pytypes - -inline namespace literals { -/** \rst - String literal version of `str` - \endrst */ -inline str operator"" _s(const char *s, size_t size) { return {s, size}; } -} - -/// \addtogroup pytypes -/// @{ -class bytes : public object { -public: - PYBIND11_OBJECT(bytes, object, PYBIND11_BYTES_CHECK) - - // Allow implicit conversion: - bytes(const char *c = "") - : object(PYBIND11_BYTES_FROM_STRING(c), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate bytes object!"); - } - - bytes(const char *c, size_t n) - : object(PYBIND11_BYTES_FROM_STRING_AND_SIZE(c, (ssize_t) n), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate bytes object!"); - } - - // Allow implicit conversion: - bytes(const std::string &s) : bytes(s.data(), s.size()) { } - - explicit bytes(const pybind11::str &s); - - operator std::string() const { - char *buffer; - ssize_t length; - if (PYBIND11_BYTES_AS_STRING_AND_SIZE(m_ptr, &buffer, &length)) - pybind11_fail("Unable to extract bytes contents!"); - return std::string(buffer, (size_t) length); - } -}; - -inline bytes::bytes(const pybind11::str &s) { - object temp = s; - if (PyUnicode_Check(s.ptr())) { - temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(s.ptr())); - if (!temp) - pybind11_fail("Unable to extract string contents! (encoding issue)"); - } - char *buffer; - ssize_t length; - if (PYBIND11_BYTES_AS_STRING_AND_SIZE(temp.ptr(), &buffer, &length)) - pybind11_fail("Unable to extract string contents! (invalid type)"); - auto obj = reinterpret_steal<object>(PYBIND11_BYTES_FROM_STRING_AND_SIZE(buffer, length)); - if (!obj) - pybind11_fail("Could not allocate bytes object!"); - m_ptr = obj.release().ptr(); -} - -inline str::str(const bytes& b) { - char *buffer; - ssize_t length; - if (PYBIND11_BYTES_AS_STRING_AND_SIZE(b.ptr(), &buffer, &length)) - pybind11_fail("Unable to extract bytes contents!"); - auto obj = reinterpret_steal<object>(PyUnicode_FromStringAndSize(buffer, (ssize_t) length)); - if (!obj) - pybind11_fail("Could not allocate string object!"); - m_ptr = obj.release().ptr(); -} - -class none : public object { -public: - PYBIND11_OBJECT(none, object, detail::PyNone_Check) - none() : object(Py_None, borrowed_t{}) { } -}; - -#if PY_MAJOR_VERSION >= 3 -class ellipsis : public object { -public: - PYBIND11_OBJECT(ellipsis, object, detail::PyEllipsis_Check) - ellipsis() : object(Py_Ellipsis, borrowed_t{}) { } -}; -#endif - -class bool_ : public object { -public: - PYBIND11_OBJECT_CVT(bool_, object, PyBool_Check, raw_bool) - bool_() : object(Py_False, borrowed_t{}) { } - // Allow implicit conversion from and to `bool`: - bool_(bool value) : object(value ? Py_True : Py_False, borrowed_t{}) { } - operator bool() const { return m_ptr && PyLong_AsLong(m_ptr) != 0; } - -private: - /// Return the truth value of an object -- always returns a new reference - static PyObject *raw_bool(PyObject *op) { - const auto value = PyObject_IsTrue(op); - if (value == -1) return nullptr; - return handle(value ? Py_True : Py_False).inc_ref().ptr(); - } -}; - -NAMESPACE_BEGIN(detail) -// Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1; -// otherwise you get back the unsigned long or unsigned long long value cast to (Unsigned). -// (The distinction is critically important when casting a returned -1 error value to some other -// unsigned type: (A)-1 != (B)-1 when A and B are unsigned types of different sizes). -template <typename Unsigned> -Unsigned as_unsigned(PyObject *o) { - if (sizeof(Unsigned) <= sizeof(unsigned long) -#if PY_VERSION_HEX < 0x03000000 - || PyInt_Check(o) -#endif - ) { - unsigned long v = PyLong_AsUnsignedLong(o); - return v == (unsigned long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v; - } - else { - unsigned long long v = PyLong_AsUnsignedLongLong(o); - return v == (unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v; - } -} -NAMESPACE_END(detail) - -class int_ : public object { -public: - PYBIND11_OBJECT_CVT(int_, object, PYBIND11_LONG_CHECK, PyNumber_Long) - int_() : object(PyLong_FromLong(0), stolen_t{}) { } - // Allow implicit conversion from C++ integral types: - template <typename T, - detail::enable_if_t<std::is_integral<T>::value, int> = 0> - int_(T value) { - if (sizeof(T) <= sizeof(long)) { - if (std::is_signed<T>::value) - m_ptr = PyLong_FromLong((long) value); - else - m_ptr = PyLong_FromUnsignedLong((unsigned long) value); - } else { - if (std::is_signed<T>::value) - m_ptr = PyLong_FromLongLong((long long) value); - else - m_ptr = PyLong_FromUnsignedLongLong((unsigned long long) value); - } - if (!m_ptr) pybind11_fail("Could not allocate int object!"); - } - - template <typename T, - detail::enable_if_t<std::is_integral<T>::value, int> = 0> - operator T() const { - return std::is_unsigned<T>::value - ? detail::as_unsigned<T>(m_ptr) - : sizeof(T) <= sizeof(long) - ? (T) PyLong_AsLong(m_ptr) - : (T) PYBIND11_LONG_AS_LONGLONG(m_ptr); - } -}; - -class float_ : public object { -public: - PYBIND11_OBJECT_CVT(float_, object, PyFloat_Check, PyNumber_Float) - // Allow implicit conversion from float/double: - float_(float value) : object(PyFloat_FromDouble((double) value), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate float object!"); - } - float_(double value = .0) : object(PyFloat_FromDouble((double) value), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate float object!"); - } - operator float() const { return (float) PyFloat_AsDouble(m_ptr); } - operator double() const { return (double) PyFloat_AsDouble(m_ptr); } -}; - -class weakref : public object { -public: - PYBIND11_OBJECT_DEFAULT(weakref, object, PyWeakref_Check) - explicit weakref(handle obj, handle callback = {}) - : object(PyWeakref_NewRef(obj.ptr(), callback.ptr()), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate weak reference!"); - } -}; - -class slice : public object { -public: - PYBIND11_OBJECT_DEFAULT(slice, object, PySlice_Check) - slice(ssize_t start_, ssize_t stop_, ssize_t step_) { - int_ start(start_), stop(stop_), step(step_); - m_ptr = PySlice_New(start.ptr(), stop.ptr(), step.ptr()); - if (!m_ptr) pybind11_fail("Could not allocate slice object!"); - } - bool compute(size_t length, size_t *start, size_t *stop, size_t *step, - size_t *slicelength) const { - return PySlice_GetIndicesEx((PYBIND11_SLICE_OBJECT *) m_ptr, - (ssize_t) length, (ssize_t *) start, - (ssize_t *) stop, (ssize_t *) step, - (ssize_t *) slicelength) == 0; - } - bool compute(ssize_t length, ssize_t *start, ssize_t *stop, ssize_t *step, - ssize_t *slicelength) const { - return PySlice_GetIndicesEx((PYBIND11_SLICE_OBJECT *) m_ptr, - length, start, - stop, step, - slicelength) == 0; - } -}; - -class capsule : public object { -public: - PYBIND11_OBJECT_DEFAULT(capsule, object, PyCapsule_CheckExact) - PYBIND11_DEPRECATED("Use reinterpret_borrow<capsule>() or reinterpret_steal<capsule>()") - capsule(PyObject *ptr, bool is_borrowed) : object(is_borrowed ? object(ptr, borrowed_t{}) : object(ptr, stolen_t{})) { } - - explicit capsule(const void *value, const char *name = nullptr, void (*destructor)(PyObject *) = nullptr) - : object(PyCapsule_New(const_cast<void *>(value), name, destructor), stolen_t{}) { - if (!m_ptr) - pybind11_fail("Could not allocate capsule object!"); - } - - PYBIND11_DEPRECATED("Please pass a destructor that takes a void pointer as input") - capsule(const void *value, void (*destruct)(PyObject *)) - : object(PyCapsule_New(const_cast<void*>(value), nullptr, destruct), stolen_t{}) { - if (!m_ptr) - pybind11_fail("Could not allocate capsule object!"); - } - - capsule(const void *value, void (*destructor)(void *)) { - m_ptr = PyCapsule_New(const_cast<void *>(value), nullptr, [](PyObject *o) { - auto destructor = reinterpret_cast<void (*)(void *)>(PyCapsule_GetContext(o)); - void *ptr = PyCapsule_GetPointer(o, nullptr); - destructor(ptr); - }); - - if (!m_ptr) - pybind11_fail("Could not allocate capsule object!"); - - if (PyCapsule_SetContext(m_ptr, (void *) destructor) != 0) - pybind11_fail("Could not set capsule context!"); - } - - capsule(void (*destructor)()) { - m_ptr = PyCapsule_New(reinterpret_cast<void *>(destructor), nullptr, [](PyObject *o) { - auto destructor = reinterpret_cast<void (*)()>(PyCapsule_GetPointer(o, nullptr)); - destructor(); - }); - - if (!m_ptr) - pybind11_fail("Could not allocate capsule object!"); - } - - template <typename T> operator T *() const { - auto name = this->name(); - T * result = static_cast<T *>(PyCapsule_GetPointer(m_ptr, name)); - if (!result) pybind11_fail("Unable to extract capsule contents!"); - return result; - } - - const char *name() const { return PyCapsule_GetName(m_ptr); } -}; - -class tuple : public object { -public: - PYBIND11_OBJECT_CVT(tuple, object, PyTuple_Check, PySequence_Tuple) - explicit tuple(size_t size = 0) : object(PyTuple_New((ssize_t) size), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate tuple object!"); - } - size_t size() const { return (size_t) PyTuple_Size(m_ptr); } - bool empty() const { return size() == 0; } - detail::tuple_accessor operator[](size_t index) const { return {*this, index}; } - detail::item_accessor operator[](handle h) const { return object::operator[](h); } - detail::tuple_iterator begin() const { return {*this, 0}; } - detail::tuple_iterator end() const { return {*this, PyTuple_GET_SIZE(m_ptr)}; } -}; - -class dict : public object { -public: - PYBIND11_OBJECT_CVT(dict, object, PyDict_Check, raw_dict) - dict() : object(PyDict_New(), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate dict object!"); - } - template <typename... Args, - typename = detail::enable_if_t<detail::all_of<detail::is_keyword_or_ds<Args>...>::value>, - // MSVC workaround: it can't compile an out-of-line definition, so defer the collector - typename collector = detail::deferred_t<detail::unpacking_collector<>, Args...>> - explicit dict(Args &&...args) : dict(collector(std::forward<Args>(args)...).kwargs()) { } - - size_t size() const { return (size_t) PyDict_Size(m_ptr); } - bool empty() const { return size() == 0; } - detail::dict_iterator begin() const { return {*this, 0}; } - detail::dict_iterator end() const { return {}; } - void clear() const { PyDict_Clear(ptr()); } - template <typename T> bool contains(T &&key) const { - return PyDict_Contains(m_ptr, detail::object_or_cast(std::forward<T>(key)).ptr()) == 1; - } - -private: - /// Call the `dict` Python type -- always returns a new reference - static PyObject *raw_dict(PyObject *op) { - if (PyDict_Check(op)) - return handle(op).inc_ref().ptr(); - return PyObject_CallFunctionObjArgs((PyObject *) &PyDict_Type, op, nullptr); - } -}; - -class sequence : public object { -public: - PYBIND11_OBJECT_DEFAULT(sequence, object, PySequence_Check) - size_t size() const { return (size_t) PySequence_Size(m_ptr); } - bool empty() const { return size() == 0; } - detail::sequence_accessor operator[](size_t index) const { return {*this, index}; } - detail::item_accessor operator[](handle h) const { return object::operator[](h); } - detail::sequence_iterator begin() const { return {*this, 0}; } - detail::sequence_iterator end() const { return {*this, PySequence_Size(m_ptr)}; } -}; - -class list : public object { -public: - PYBIND11_OBJECT_CVT(list, object, PyList_Check, PySequence_List) - explicit list(size_t size = 0) : object(PyList_New((ssize_t) size), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate list object!"); - } - size_t size() const { return (size_t) PyList_Size(m_ptr); } - bool empty() const { return size() == 0; } - detail::list_accessor operator[](size_t index) const { return {*this, index}; } - detail::item_accessor operator[](handle h) const { return object::operator[](h); } - detail::list_iterator begin() const { return {*this, 0}; } - detail::list_iterator end() const { return {*this, PyList_GET_SIZE(m_ptr)}; } - template <typename T> void append(T &&val) const { - PyList_Append(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()); - } - template <typename T> void insert(size_t index, T &&val) const { - PyList_Insert(m_ptr, static_cast<ssize_t>(index), - detail::object_or_cast(std::forward<T>(val)).ptr()); - } -}; - -class args : public tuple { PYBIND11_OBJECT_DEFAULT(args, tuple, PyTuple_Check) }; -class kwargs : public dict { PYBIND11_OBJECT_DEFAULT(kwargs, dict, PyDict_Check) }; - -class set : public object { -public: - PYBIND11_OBJECT_CVT(set, object, PySet_Check, PySet_New) - set() : object(PySet_New(nullptr), stolen_t{}) { - if (!m_ptr) pybind11_fail("Could not allocate set object!"); - } - size_t size() const { return (size_t) PySet_Size(m_ptr); } - bool empty() const { return size() == 0; } - template <typename T> bool add(T &&val) const { - return PySet_Add(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) == 0; - } - void clear() const { PySet_Clear(m_ptr); } - template <typename T> bool contains(T &&val) const { - return PySet_Contains(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) == 1; - } -}; - -class function : public object { -public: - PYBIND11_OBJECT_DEFAULT(function, object, PyCallable_Check) - handle cpp_function() const { - handle fun = detail::get_function(m_ptr); - if (fun && PyCFunction_Check(fun.ptr())) - return fun; - return handle(); - } - bool is_cpp_function() const { return (bool) cpp_function(); } -}; - -class staticmethod : public object { -public: - PYBIND11_OBJECT_CVT(staticmethod, object, detail::PyStaticMethod_Check, PyStaticMethod_New) -}; - -class buffer : public object { -public: - PYBIND11_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer) - - buffer_info request(bool writable = false) const { - int flags = PyBUF_STRIDES | PyBUF_FORMAT; - if (writable) flags |= PyBUF_WRITABLE; - Py_buffer *view = new Py_buffer(); - if (PyObject_GetBuffer(m_ptr, view, flags) != 0) { - delete view; - throw error_already_set(); - } - return buffer_info(view); - } -}; - -class memoryview : public object { -public: - explicit memoryview(const buffer_info& info) { - static Py_buffer buf { }; - // Py_buffer uses signed sizes, strides and shape!.. - static std::vector<Py_ssize_t> py_strides { }; - static std::vector<Py_ssize_t> py_shape { }; - buf.buf = info.ptr; - buf.itemsize = info.itemsize; - buf.format = const_cast<char *>(info.format.c_str()); - buf.ndim = (int) info.ndim; - buf.len = info.size; - py_strides.clear(); - py_shape.clear(); - for (size_t i = 0; i < (size_t) info.ndim; ++i) { - py_strides.push_back(info.strides[i]); - py_shape.push_back(info.shape[i]); - } - buf.strides = py_strides.data(); - buf.shape = py_shape.data(); - buf.suboffsets = nullptr; - buf.readonly = false; - buf.internal = nullptr; - - m_ptr = PyMemoryView_FromBuffer(&buf); - if (!m_ptr) - pybind11_fail("Unable to create memoryview from buffer descriptor"); - } - - PYBIND11_OBJECT_CVT(memoryview, object, PyMemoryView_Check, PyMemoryView_FromObject) -}; -/// @} pytypes - -/// \addtogroup python_builtins -/// @{ -inline size_t len(handle h) { - ssize_t result = PyObject_Length(h.ptr()); - if (result < 0) - pybind11_fail("Unable to compute length of object"); - return (size_t) result; -} - -inline size_t len_hint(handle h) { -#if PY_VERSION_HEX >= 0x03040000 - ssize_t result = PyObject_LengthHint(h.ptr(), 0); -#else - ssize_t result = PyObject_Length(h.ptr()); -#endif - if (result < 0) { - // Sometimes a length can't be determined at all (eg generators) - // In which case simply return 0 - PyErr_Clear(); - return 0; - } - return (size_t) result; -} - -inline str repr(handle h) { - PyObject *str_value = PyObject_Repr(h.ptr()); - if (!str_value) throw error_already_set(); -#if PY_MAJOR_VERSION < 3 - PyObject *unicode = PyUnicode_FromEncodedObject(str_value, "utf-8", nullptr); - Py_XDECREF(str_value); str_value = unicode; - if (!str_value) throw error_already_set(); -#endif - return reinterpret_steal<str>(str_value); -} - -inline iterator iter(handle obj) { - PyObject *result = PyObject_GetIter(obj.ptr()); - if (!result) { throw error_already_set(); } - return reinterpret_steal<iterator>(result); -} -/// @} python_builtins - -NAMESPACE_BEGIN(detail) -template <typename D> iterator object_api<D>::begin() const { return iter(derived()); } -template <typename D> iterator object_api<D>::end() const { return iterator::sentinel(); } -template <typename D> item_accessor object_api<D>::operator[](handle key) const { - return {derived(), reinterpret_borrow<object>(key)}; -} -template <typename D> item_accessor object_api<D>::operator[](const char *key) const { - return {derived(), pybind11::str(key)}; -} -template <typename D> obj_attr_accessor object_api<D>::attr(handle key) const { - return {derived(), reinterpret_borrow<object>(key)}; -} -template <typename D> str_attr_accessor object_api<D>::attr(const char *key) const { - return {derived(), key}; -} -template <typename D> args_proxy object_api<D>::operator*() const { - return args_proxy(derived().ptr()); -} -template <typename D> template <typename T> bool object_api<D>::contains(T &&item) const { - return attr("__contains__")(std::forward<T>(item)).template cast<bool>(); -} - -template <typename D> -pybind11::str object_api<D>::str() const { return pybind11::str(derived()); } - -template <typename D> -str_attr_accessor object_api<D>::doc() const { return attr("__doc__"); } - -template <typename D> -handle object_api<D>::get_type() const { return (PyObject *) Py_TYPE(derived().ptr()); } - -template <typename D> -bool object_api<D>::rich_compare(object_api const &other, int value) const { - int rv = PyObject_RichCompareBool(derived().ptr(), other.derived().ptr(), value); - if (rv == -1) - throw error_already_set(); - return rv == 1; -} - -#define PYBIND11_MATH_OPERATOR_UNARY(op, fn) \ - template <typename D> object object_api<D>::op() const { \ - object result = reinterpret_steal<object>(fn(derived().ptr())); \ - if (!result.ptr()) \ - throw error_already_set(); \ - return result; \ - } - -#define PYBIND11_MATH_OPERATOR_BINARY(op, fn) \ - template <typename D> \ - object object_api<D>::op(object_api const &other) const { \ - object result = reinterpret_steal<object>( \ - fn(derived().ptr(), other.derived().ptr())); \ - if (!result.ptr()) \ - throw error_already_set(); \ - return result; \ - } - -PYBIND11_MATH_OPERATOR_UNARY (operator~, PyNumber_Invert) -PYBIND11_MATH_OPERATOR_UNARY (operator-, PyNumber_Negative) -PYBIND11_MATH_OPERATOR_BINARY(operator+, PyNumber_Add) -PYBIND11_MATH_OPERATOR_BINARY(operator+=, PyNumber_InPlaceAdd) -PYBIND11_MATH_OPERATOR_BINARY(operator-, PyNumber_Subtract) -PYBIND11_MATH_OPERATOR_BINARY(operator-=, PyNumber_InPlaceSubtract) -PYBIND11_MATH_OPERATOR_BINARY(operator*, PyNumber_Multiply) -PYBIND11_MATH_OPERATOR_BINARY(operator*=, PyNumber_InPlaceMultiply) -PYBIND11_MATH_OPERATOR_BINARY(operator/, PyNumber_TrueDivide) -PYBIND11_MATH_OPERATOR_BINARY(operator/=, PyNumber_InPlaceTrueDivide) -PYBIND11_MATH_OPERATOR_BINARY(operator|, PyNumber_Or) -PYBIND11_MATH_OPERATOR_BINARY(operator|=, PyNumber_InPlaceOr) -PYBIND11_MATH_OPERATOR_BINARY(operator&, PyNumber_And) -PYBIND11_MATH_OPERATOR_BINARY(operator&=, PyNumber_InPlaceAnd) -PYBIND11_MATH_OPERATOR_BINARY(operator^, PyNumber_Xor) -PYBIND11_MATH_OPERATOR_BINARY(operator^=, PyNumber_InPlaceXor) -PYBIND11_MATH_OPERATOR_BINARY(operator<<, PyNumber_Lshift) -PYBIND11_MATH_OPERATOR_BINARY(operator<<=, PyNumber_InPlaceLshift) -PYBIND11_MATH_OPERATOR_BINARY(operator>>, PyNumber_Rshift) -PYBIND11_MATH_OPERATOR_BINARY(operator>>=, PyNumber_InPlaceRshift) - -#undef PYBIND11_MATH_OPERATOR_UNARY -#undef PYBIND11_MATH_OPERATOR_BINARY - -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/include/pybind11/stl.h b/external/pybind11/include/pybind11/stl.h deleted file mode 100644 index 32f8d294..00000000 --- a/external/pybind11/include/pybind11/stl.h +++ /dev/null @@ -1,386 +0,0 @@ -/* - pybind11/stl.h: Transparent conversion for STL data types - - Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "pybind11.h" -#include <set> -#include <unordered_set> -#include <map> -#include <unordered_map> -#include <iostream> -#include <list> -#include <deque> -#include <valarray> - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable: 4127) // warning C4127: Conditional expression is constant -#endif - -#ifdef __has_include -// std::optional (but including it in c++14 mode isn't allowed) -# if defined(PYBIND11_CPP17) && __has_include(<optional>) -# include <optional> -# define PYBIND11_HAS_OPTIONAL 1 -# endif -// std::experimental::optional (but not allowed in c++11 mode) -# if defined(PYBIND11_CPP14) && (__has_include(<experimental/optional>) && \ - !__has_include(<optional>)) -# include <experimental/optional> -# define PYBIND11_HAS_EXP_OPTIONAL 1 -# endif -// std::variant -# if defined(PYBIND11_CPP17) && __has_include(<variant>) -# include <variant> -# define PYBIND11_HAS_VARIANT 1 -# endif -#elif defined(_MSC_VER) && defined(PYBIND11_CPP17) -# include <optional> -# include <variant> -# define PYBIND11_HAS_OPTIONAL 1 -# define PYBIND11_HAS_VARIANT 1 -#endif - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -/// Extracts an const lvalue reference or rvalue reference for U based on the type of T (e.g. for -/// forwarding a container element). Typically used indirect via forwarded_type(), below. -template <typename T, typename U> -using forwarded_type = conditional_t< - std::is_lvalue_reference<T>::value, remove_reference_t<U> &, remove_reference_t<U> &&>; - -/// Forwards a value U as rvalue or lvalue according to whether T is rvalue or lvalue; typically -/// used for forwarding a container's elements. -template <typename T, typename U> -forwarded_type<T, U> forward_like(U &&u) { - return std::forward<detail::forwarded_type<T, U>>(std::forward<U>(u)); -} - -template <typename Type, typename Key> struct set_caster { - using type = Type; - using key_conv = make_caster<Key>; - - bool load(handle src, bool convert) { - if (!isinstance<pybind11::set>(src)) - return false; - auto s = reinterpret_borrow<pybind11::set>(src); - value.clear(); - for (auto entry : s) { - key_conv conv; - if (!conv.load(entry, convert)) - return false; - value.insert(cast_op<Key &&>(std::move(conv))); - } - return true; - } - - template <typename T> - static handle cast(T &&src, return_value_policy policy, handle parent) { - if (!std::is_lvalue_reference<T>::value) - policy = return_value_policy_override<Key>::policy(policy); - pybind11::set s; - for (auto &&value : src) { - auto value_ = reinterpret_steal<object>(key_conv::cast(forward_like<T>(value), policy, parent)); - if (!value_ || !s.add(value_)) - return handle(); - } - return s.release(); - } - - PYBIND11_TYPE_CASTER(type, _("Set[") + key_conv::name + _("]")); -}; - -template <typename Type, typename Key, typename Value> struct map_caster { - using key_conv = make_caster<Key>; - using value_conv = make_caster<Value>; - - bool load(handle src, bool convert) { - if (!isinstance<dict>(src)) - return false; - auto d = reinterpret_borrow<dict>(src); - value.clear(); - for (auto it : d) { - key_conv kconv; - value_conv vconv; - if (!kconv.load(it.first.ptr(), convert) || - !vconv.load(it.second.ptr(), convert)) - return false; - value.emplace(cast_op<Key &&>(std::move(kconv)), cast_op<Value &&>(std::move(vconv))); - } - return true; - } - - template <typename T> - static handle cast(T &&src, return_value_policy policy, handle parent) { - dict d; - return_value_policy policy_key = policy; - return_value_policy policy_value = policy; - if (!std::is_lvalue_reference<T>::value) { - policy_key = return_value_policy_override<Key>::policy(policy_key); - policy_value = return_value_policy_override<Value>::policy(policy_value); - } - for (auto &&kv : src) { - auto key = reinterpret_steal<object>(key_conv::cast(forward_like<T>(kv.first), policy_key, parent)); - auto value = reinterpret_steal<object>(value_conv::cast(forward_like<T>(kv.second), policy_value, parent)); - if (!key || !value) - return handle(); - d[key] = value; - } - return d.release(); - } - - PYBIND11_TYPE_CASTER(Type, _("Dict[") + key_conv::name + _(", ") + value_conv::name + _("]")); -}; - -template <typename Type, typename Value> struct list_caster { - using value_conv = make_caster<Value>; - - bool load(handle src, bool convert) { - if (!isinstance<sequence>(src) || isinstance<str>(src)) - return false; - auto s = reinterpret_borrow<sequence>(src); - value.clear(); - reserve_maybe(s, &value); - for (auto it : s) { - value_conv conv; - if (!conv.load(it, convert)) - return false; - value.push_back(cast_op<Value &&>(std::move(conv))); - } - return true; - } - -private: - template <typename T = Type, - enable_if_t<std::is_same<decltype(std::declval<T>().reserve(0)), void>::value, int> = 0> - void reserve_maybe(sequence s, Type *) { value.reserve(s.size()); } - void reserve_maybe(sequence, void *) { } - -public: - template <typename T> - static handle cast(T &&src, return_value_policy policy, handle parent) { - if (!std::is_lvalue_reference<T>::value) - policy = return_value_policy_override<Value>::policy(policy); - list l(src.size()); - size_t index = 0; - for (auto &&value : src) { - auto value_ = reinterpret_steal<object>(value_conv::cast(forward_like<T>(value), policy, parent)); - if (!value_) - return handle(); - PyList_SET_ITEM(l.ptr(), (ssize_t) index++, value_.release().ptr()); // steals a reference - } - return l.release(); - } - - PYBIND11_TYPE_CASTER(Type, _("List[") + value_conv::name + _("]")); -}; - -template <typename Type, typename Alloc> struct type_caster<std::vector<Type, Alloc>> - : list_caster<std::vector<Type, Alloc>, Type> { }; - -template <typename Type, typename Alloc> struct type_caster<std::deque<Type, Alloc>> - : list_caster<std::deque<Type, Alloc>, Type> { }; - -template <typename Type, typename Alloc> struct type_caster<std::list<Type, Alloc>> - : list_caster<std::list<Type, Alloc>, Type> { }; - -template <typename ArrayType, typename Value, bool Resizable, size_t Size = 0> struct array_caster { - using value_conv = make_caster<Value>; - -private: - template <bool R = Resizable> - bool require_size(enable_if_t<R, size_t> size) { - if (value.size() != size) - value.resize(size); - return true; - } - template <bool R = Resizable> - bool require_size(enable_if_t<!R, size_t> size) { - return size == Size; - } - -public: - bool load(handle src, bool convert) { - if (!isinstance<sequence>(src)) - return false; - auto l = reinterpret_borrow<sequence>(src); - if (!require_size(l.size())) - return false; - size_t ctr = 0; - for (auto it : l) { - value_conv conv; - if (!conv.load(it, convert)) - return false; - value[ctr++] = cast_op<Value &&>(std::move(conv)); - } - return true; - } - - template <typename T> - static handle cast(T &&src, return_value_policy policy, handle parent) { - list l(src.size()); - size_t index = 0; - for (auto &&value : src) { - auto value_ = reinterpret_steal<object>(value_conv::cast(forward_like<T>(value), policy, parent)); - if (!value_) - return handle(); - PyList_SET_ITEM(l.ptr(), (ssize_t) index++, value_.release().ptr()); // steals a reference - } - return l.release(); - } - - PYBIND11_TYPE_CASTER(ArrayType, _("List[") + value_conv::name + _<Resizable>(_(""), _("[") + _<Size>() + _("]")) + _("]")); -}; - -template <typename Type, size_t Size> struct type_caster<std::array<Type, Size>> - : array_caster<std::array<Type, Size>, Type, false, Size> { }; - -template <typename Type> struct type_caster<std::valarray<Type>> - : array_caster<std::valarray<Type>, Type, true> { }; - -template <typename Key, typename Compare, typename Alloc> struct type_caster<std::set<Key, Compare, Alloc>> - : set_caster<std::set<Key, Compare, Alloc>, Key> { }; - -template <typename Key, typename Hash, typename Equal, typename Alloc> struct type_caster<std::unordered_set<Key, Hash, Equal, Alloc>> - : set_caster<std::unordered_set<Key, Hash, Equal, Alloc>, Key> { }; - -template <typename Key, typename Value, typename Compare, typename Alloc> struct type_caster<std::map<Key, Value, Compare, Alloc>> - : map_caster<std::map<Key, Value, Compare, Alloc>, Key, Value> { }; - -template <typename Key, typename Value, typename Hash, typename Equal, typename Alloc> struct type_caster<std::unordered_map<Key, Value, Hash, Equal, Alloc>> - : map_caster<std::unordered_map<Key, Value, Hash, Equal, Alloc>, Key, Value> { }; - -// This type caster is intended to be used for std::optional and std::experimental::optional -template<typename T> struct optional_caster { - using value_conv = make_caster<typename T::value_type>; - - template <typename T_> - static handle cast(T_ &&src, return_value_policy policy, handle parent) { - if (!src) - return none().inc_ref(); - policy = return_value_policy_override<typename T::value_type>::policy(policy); - return value_conv::cast(*std::forward<T_>(src), policy, parent); - } - - bool load(handle src, bool convert) { - if (!src) { - return false; - } else if (src.is_none()) { - return true; // default-constructed value is already empty - } - value_conv inner_caster; - if (!inner_caster.load(src, convert)) - return false; - - value.emplace(cast_op<typename T::value_type &&>(std::move(inner_caster))); - return true; - } - - PYBIND11_TYPE_CASTER(T, _("Optional[") + value_conv::name + _("]")); -}; - -#if PYBIND11_HAS_OPTIONAL -template<typename T> struct type_caster<std::optional<T>> - : public optional_caster<std::optional<T>> {}; - -template<> struct type_caster<std::nullopt_t> - : public void_caster<std::nullopt_t> {}; -#endif - -#if PYBIND11_HAS_EXP_OPTIONAL -template<typename T> struct type_caster<std::experimental::optional<T>> - : public optional_caster<std::experimental::optional<T>> {}; - -template<> struct type_caster<std::experimental::nullopt_t> - : public void_caster<std::experimental::nullopt_t> {}; -#endif - -/// Visit a variant and cast any found type to Python -struct variant_caster_visitor { - return_value_policy policy; - handle parent; - - using result_type = handle; // required by boost::variant in C++11 - - template <typename T> - result_type operator()(T &&src) const { - return make_caster<T>::cast(std::forward<T>(src), policy, parent); - } -}; - -/// Helper class which abstracts away variant's `visit` function. `std::variant` and similar -/// `namespace::variant` types which provide a `namespace::visit()` function are handled here -/// automatically using argument-dependent lookup. Users can provide specializations for other -/// variant-like classes, e.g. `boost::variant` and `boost::apply_visitor`. -template <template<typename...> class Variant> -struct visit_helper { - template <typename... Args> - static auto call(Args &&...args) -> decltype(visit(std::forward<Args>(args)...)) { - return visit(std::forward<Args>(args)...); - } -}; - -/// Generic variant caster -template <typename Variant> struct variant_caster; - -template <template<typename...> class V, typename... Ts> -struct variant_caster<V<Ts...>> { - static_assert(sizeof...(Ts) > 0, "Variant must consist of at least one alternative."); - - template <typename U, typename... Us> - bool load_alternative(handle src, bool convert, type_list<U, Us...>) { - auto caster = make_caster<U>(); - if (caster.load(src, convert)) { - value = cast_op<U>(caster); - return true; - } - return load_alternative(src, convert, type_list<Us...>{}); - } - - bool load_alternative(handle, bool, type_list<>) { return false; } - - bool load(handle src, bool convert) { - // Do a first pass without conversions to improve constructor resolution. - // E.g. `py::int_(1).cast<variant<double, int>>()` needs to fill the `int` - // slot of the variant. Without two-pass loading `double` would be filled - // because it appears first and a conversion is possible. - if (convert && load_alternative(src, false, type_list<Ts...>{})) - return true; - return load_alternative(src, convert, type_list<Ts...>{}); - } - - template <typename Variant> - static handle cast(Variant &&src, return_value_policy policy, handle parent) { - return visit_helper<V>::call(variant_caster_visitor{policy, parent}, - std::forward<Variant>(src)); - } - - using Type = V<Ts...>; - PYBIND11_TYPE_CASTER(Type, _("Union[") + detail::concat(make_caster<Ts>::name...) + _("]")); -}; - -#if PYBIND11_HAS_VARIANT -template <typename... Ts> -struct type_caster<std::variant<Ts...>> : variant_caster<std::variant<Ts...>> { }; -#endif - -NAMESPACE_END(detail) - -inline std::ostream &operator<<(std::ostream &os, const handle &obj) { - os << (std::string) str(obj); - return os; -} - -NAMESPACE_END(PYBIND11_NAMESPACE) - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif diff --git a/external/pybind11/include/pybind11/stl_bind.h b/external/pybind11/include/pybind11/stl_bind.h deleted file mode 100644 index 62bd9081..00000000 --- a/external/pybind11/include/pybind11/stl_bind.h +++ /dev/null @@ -1,649 +0,0 @@ -/* - pybind11/std_bind.h: Binding generators for STL data types - - Copyright (c) 2016 Sergey Lyskov and Wenzel Jakob - - All rights reserved. Use of this source code is governed by a - BSD-style license that can be found in the LICENSE file. -*/ - -#pragma once - -#include "detail/common.h" -#include "operators.h" - -#include <algorithm> -#include <sstream> - -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) - -/* SFINAE helper class used by 'is_comparable */ -template <typename T> struct container_traits { - template <typename T2> static std::true_type test_comparable(decltype(std::declval<const T2 &>() == std::declval<const T2 &>())*); - template <typename T2> static std::false_type test_comparable(...); - template <typename T2> static std::true_type test_value(typename T2::value_type *); - template <typename T2> static std::false_type test_value(...); - template <typename T2> static std::true_type test_pair(typename T2::first_type *, typename T2::second_type *); - template <typename T2> static std::false_type test_pair(...); - - static constexpr const bool is_comparable = std::is_same<std::true_type, decltype(test_comparable<T>(nullptr))>::value; - static constexpr const bool is_pair = std::is_same<std::true_type, decltype(test_pair<T>(nullptr, nullptr))>::value; - static constexpr const bool is_vector = std::is_same<std::true_type, decltype(test_value<T>(nullptr))>::value; - static constexpr const bool is_element = !is_pair && !is_vector; -}; - -/* Default: is_comparable -> std::false_type */ -template <typename T, typename SFINAE = void> -struct is_comparable : std::false_type { }; - -/* For non-map data structures, check whether operator== can be instantiated */ -template <typename T> -struct is_comparable< - T, enable_if_t<container_traits<T>::is_element && - container_traits<T>::is_comparable>> - : std::true_type { }; - -/* For a vector/map data structure, recursively check the value type (which is std::pair for maps) */ -template <typename T> -struct is_comparable<T, enable_if_t<container_traits<T>::is_vector>> { - static constexpr const bool value = - is_comparable<typename T::value_type>::value; -}; - -/* For pairs, recursively check the two data types */ -template <typename T> -struct is_comparable<T, enable_if_t<container_traits<T>::is_pair>> { - static constexpr const bool value = - is_comparable<typename T::first_type>::value && - is_comparable<typename T::second_type>::value; -}; - -/* Fallback functions */ -template <typename, typename, typename... Args> void vector_if_copy_constructible(const Args &...) { } -template <typename, typename, typename... Args> void vector_if_equal_operator(const Args &...) { } -template <typename, typename, typename... Args> void vector_if_insertion_operator(const Args &...) { } -template <typename, typename, typename... Args> void vector_modifiers(const Args &...) { } - -template<typename Vector, typename Class_> -void vector_if_copy_constructible(enable_if_t<is_copy_constructible<Vector>::value, Class_> &cl) { - cl.def(init<const Vector &>(), "Copy constructor"); -} - -template<typename Vector, typename Class_> -void vector_if_equal_operator(enable_if_t<is_comparable<Vector>::value, Class_> &cl) { - using T = typename Vector::value_type; - - cl.def(self == self); - cl.def(self != self); - - cl.def("count", - [](const Vector &v, const T &x) { - return std::count(v.begin(), v.end(), x); - }, - arg("x"), - "Return the number of times ``x`` appears in the list" - ); - - cl.def("remove", [](Vector &v, const T &x) { - auto p = std::find(v.begin(), v.end(), x); - if (p != v.end()) - v.erase(p); - else - throw value_error(); - }, - arg("x"), - "Remove the first item from the list whose value is x. " - "It is an error if there is no such item." - ); - - cl.def("__contains__", - [](const Vector &v, const T &x) { - return std::find(v.begin(), v.end(), x) != v.end(); - }, - arg("x"), - "Return true the container contains ``x``" - ); -} - -// Vector modifiers -- requires a copyable vector_type: -// (Technically, some of these (pop and __delitem__) don't actually require copyability, but it seems -// silly to allow deletion but not insertion, so include them here too.) -template <typename Vector, typename Class_> -void vector_modifiers(enable_if_t<is_copy_constructible<typename Vector::value_type>::value, Class_> &cl) { - using T = typename Vector::value_type; - using SizeType = typename Vector::size_type; - using DiffType = typename Vector::difference_type; - - auto wrap_i = [](DiffType i, SizeType n) { - if (i < 0) - i += n; - if (i < 0 || (SizeType)i >= n) - throw index_error(); - return i; - }; - - cl.def("append", - [](Vector &v, const T &value) { v.push_back(value); }, - arg("x"), - "Add an item to the end of the list"); - - cl.def(init([](iterable it) { - auto v = std::unique_ptr<Vector>(new Vector()); - v->reserve(len_hint(it)); - for (handle h : it) - v->push_back(h.cast<T>()); - return v.release(); - })); - - cl.def("extend", - [](Vector &v, const Vector &src) { - v.insert(v.end(), src.begin(), src.end()); - }, - arg("L"), - "Extend the list by appending all the items in the given list" - ); - - cl.def("extend", - [](Vector &v, iterable it) { - const size_t old_size = v.size(); - v.reserve(old_size + len_hint(it)); - try { - for (handle h : it) { - v.push_back(h.cast<T>()); - } - } catch (const cast_error &) { - v.erase(v.begin() + static_cast<typename Vector::difference_type>(old_size), v.end()); - try { - v.shrink_to_fit(); - } catch (const std::exception &) { - // Do nothing - } - throw; - } - }, - arg("L"), - "Extend the list by appending all the items in the given list" - ); - - cl.def("insert", - [](Vector &v, DiffType i, const T &x) { - // Can't use wrap_i; i == v.size() is OK - if (i < 0) - i += v.size(); - if (i < 0 || (SizeType)i > v.size()) - throw index_error(); - v.insert(v.begin() + i, x); - }, - arg("i") , arg("x"), - "Insert an item at a given position." - ); - - cl.def("pop", - [](Vector &v) { - if (v.empty()) - throw index_error(); - T t = v.back(); - v.pop_back(); - return t; - }, - "Remove and return the last item" - ); - - cl.def("pop", - [wrap_i](Vector &v, DiffType i) { - i = wrap_i(i, v.size()); - T t = v[(SizeType) i]; - v.erase(v.begin() + i); - return t; - }, - arg("i"), - "Remove and return the item at index ``i``" - ); - - cl.def("__setitem__", - [wrap_i](Vector &v, DiffType i, const T &t) { - i = wrap_i(i, v.size()); - v[(SizeType)i] = t; - } - ); - - /// Slicing protocol - cl.def("__getitem__", - [](const Vector &v, slice slice) -> Vector * { - size_t start, stop, step, slicelength; - - if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) - throw error_already_set(); - - Vector *seq = new Vector(); - seq->reserve((size_t) slicelength); - - for (size_t i=0; i<slicelength; ++i) { - seq->push_back(v[start]); - start += step; - } - return seq; - }, - arg("s"), - "Retrieve list elements using a slice object" - ); - - cl.def("__setitem__", - [](Vector &v, slice slice, const Vector &value) { - size_t start, stop, step, slicelength; - if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) - throw error_already_set(); - - if (slicelength != value.size()) - throw std::runtime_error("Left and right hand size of slice assignment have different sizes!"); - - for (size_t i=0; i<slicelength; ++i) { - v[start] = value[i]; - start += step; - } - }, - "Assign list elements using a slice object" - ); - - cl.def("__delitem__", - [wrap_i](Vector &v, DiffType i) { - i = wrap_i(i, v.size()); - v.erase(v.begin() + i); - }, - "Delete the list elements at index ``i``" - ); - - cl.def("__delitem__", - [](Vector &v, slice slice) { - size_t start, stop, step, slicelength; - - if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) - throw error_already_set(); - - if (step == 1 && false) { - v.erase(v.begin() + (DiffType) start, v.begin() + DiffType(start + slicelength)); - } else { - for (size_t i = 0; i < slicelength; ++i) { - v.erase(v.begin() + DiffType(start)); - start += step - 1; - } - } - }, - "Delete list elements using a slice object" - ); - -} - -// If the type has an operator[] that doesn't return a reference (most notably std::vector<bool>), -// we have to access by copying; otherwise we return by reference. -template <typename Vector> using vector_needs_copy = negation< - std::is_same<decltype(std::declval<Vector>()[typename Vector::size_type()]), typename Vector::value_type &>>; - -// The usual case: access and iterate by reference -template <typename Vector, typename Class_> -void vector_accessor(enable_if_t<!vector_needs_copy<Vector>::value, Class_> &cl) { - using T = typename Vector::value_type; - using SizeType = typename Vector::size_type; - using DiffType = typename Vector::difference_type; - using ItType = typename Vector::iterator; - - auto wrap_i = [](DiffType i, SizeType n) { - if (i < 0) - i += n; - if (i < 0 || (SizeType)i >= n) - throw index_error(); - return i; - }; - - cl.def("__getitem__", - [wrap_i](Vector &v, DiffType i) -> T & { - i = wrap_i(i, v.size()); - return v[(SizeType)i]; - }, - return_value_policy::reference_internal // ref + keepalive - ); - - cl.def("__iter__", - [](Vector &v) { - return make_iterator< - return_value_policy::reference_internal, ItType, ItType, T&>( - v.begin(), v.end()); - }, - keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ - ); -} - -// The case for special objects, like std::vector<bool>, that have to be returned-by-copy: -template <typename Vector, typename Class_> -void vector_accessor(enable_if_t<vector_needs_copy<Vector>::value, Class_> &cl) { - using T = typename Vector::value_type; - using SizeType = typename Vector::size_type; - using DiffType = typename Vector::difference_type; - using ItType = typename Vector::iterator; - cl.def("__getitem__", - [](const Vector &v, DiffType i) -> T { - if (i < 0 && (i += v.size()) < 0) - throw index_error(); - if ((SizeType)i >= v.size()) - throw index_error(); - return v[(SizeType)i]; - } - ); - - cl.def("__iter__", - [](Vector &v) { - return make_iterator< - return_value_policy::copy, ItType, ItType, T>( - v.begin(), v.end()); - }, - keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ - ); -} - -template <typename Vector, typename Class_> auto vector_if_insertion_operator(Class_ &cl, std::string const &name) - -> decltype(std::declval<std::ostream&>() << std::declval<typename Vector::value_type>(), void()) { - using size_type = typename Vector::size_type; - - cl.def("__repr__", - [name](Vector &v) { - std::ostringstream s; - s << name << '['; - for (size_type i=0; i < v.size(); ++i) { - s << v[i]; - if (i != v.size() - 1) - s << ", "; - } - s << ']'; - return s.str(); - }, - "Return the canonical string representation of this list." - ); -} - -// Provide the buffer interface for vectors if we have data() and we have a format for it -// GCC seems to have "void std::vector<bool>::data()" - doing SFINAE on the existence of data() is insufficient, we need to check it returns an appropriate pointer -template <typename Vector, typename = void> -struct vector_has_data_and_format : std::false_type {}; -template <typename Vector> -struct vector_has_data_and_format<Vector, enable_if_t<std::is_same<decltype(format_descriptor<typename Vector::value_type>::format(), std::declval<Vector>().data()), typename Vector::value_type*>::value>> : std::true_type {}; - -// Add the buffer interface to a vector -template <typename Vector, typename Class_, typename... Args> -enable_if_t<detail::any_of<std::is_same<Args, buffer_protocol>...>::value> -vector_buffer(Class_& cl) { - using T = typename Vector::value_type; - - static_assert(vector_has_data_and_format<Vector>::value, "There is not an appropriate format descriptor for this vector"); - - // numpy.h declares this for arbitrary types, but it may raise an exception and crash hard at runtime if PYBIND11_NUMPY_DTYPE hasn't been called, so check here - format_descriptor<T>::format(); - - cl.def_buffer([](Vector& v) -> buffer_info { - return buffer_info(v.data(), static_cast<ssize_t>(sizeof(T)), format_descriptor<T>::format(), 1, {v.size()}, {sizeof(T)}); - }); - - cl.def(init([](buffer buf) { - auto info = buf.request(); - if (info.ndim != 1 || info.strides[0] % static_cast<ssize_t>(sizeof(T))) - throw type_error("Only valid 1D buffers can be copied to a vector"); - if (!detail::compare_buffer_info<T>::compare(info) || (ssize_t) sizeof(T) != info.itemsize) - throw type_error("Format mismatch (Python: " + info.format + " C++: " + format_descriptor<T>::format() + ")"); - - auto vec = std::unique_ptr<Vector>(new Vector()); - vec->reserve((size_t) info.shape[0]); - T *p = static_cast<T*>(info.ptr); - ssize_t step = info.strides[0] / static_cast<ssize_t>(sizeof(T)); - T *end = p + info.shape[0] * step; - for (; p != end; p += step) - vec->push_back(*p); - return vec.release(); - })); - - return; -} - -template <typename Vector, typename Class_, typename... Args> -enable_if_t<!detail::any_of<std::is_same<Args, buffer_protocol>...>::value> vector_buffer(Class_&) {} - -NAMESPACE_END(detail) - -// -// std::vector -// -template <typename Vector, typename holder_type = std::unique_ptr<Vector>, typename... Args> -class_<Vector, holder_type> bind_vector(handle scope, std::string const &name, Args&&... args) { - using Class_ = class_<Vector, holder_type>; - - // If the value_type is unregistered (e.g. a converting type) or is itself registered - // module-local then make the vector binding module-local as well: - using vtype = typename Vector::value_type; - auto vtype_info = detail::get_type_info(typeid(vtype)); - bool local = !vtype_info || vtype_info->module_local; - - Class_ cl(scope, name.c_str(), pybind11::module_local(local), std::forward<Args>(args)...); - - // Declare the buffer interface if a buffer_protocol() is passed in - detail::vector_buffer<Vector, Class_, Args...>(cl); - - cl.def(init<>()); - - // Register copy constructor (if possible) - detail::vector_if_copy_constructible<Vector, Class_>(cl); - - // Register comparison-related operators and functions (if possible) - detail::vector_if_equal_operator<Vector, Class_>(cl); - - // Register stream insertion operator (if possible) - detail::vector_if_insertion_operator<Vector, Class_>(cl, name); - - // Modifiers require copyable vector value type - detail::vector_modifiers<Vector, Class_>(cl); - - // Accessor and iterator; return by value if copyable, otherwise we return by ref + keep-alive - detail::vector_accessor<Vector, Class_>(cl); - - cl.def("__bool__", - [](const Vector &v) -> bool { - return !v.empty(); - }, - "Check whether the list is nonempty" - ); - - cl.def("__len__", &Vector::size); - - - - -#if 0 - // C++ style functions deprecated, leaving it here as an example - cl.def(init<size_type>()); - - cl.def("resize", - (void (Vector::*) (size_type count)) & Vector::resize, - "changes the number of elements stored"); - - cl.def("erase", - [](Vector &v, SizeType i) { - if (i >= v.size()) - throw index_error(); - v.erase(v.begin() + i); - }, "erases element at index ``i``"); - - cl.def("empty", &Vector::empty, "checks whether the container is empty"); - cl.def("size", &Vector::size, "returns the number of elements"); - cl.def("push_back", (void (Vector::*)(const T&)) &Vector::push_back, "adds an element to the end"); - cl.def("pop_back", &Vector::pop_back, "removes the last element"); - - cl.def("max_size", &Vector::max_size, "returns the maximum possible number of elements"); - cl.def("reserve", &Vector::reserve, "reserves storage"); - cl.def("capacity", &Vector::capacity, "returns the number of elements that can be held in currently allocated storage"); - cl.def("shrink_to_fit", &Vector::shrink_to_fit, "reduces memory usage by freeing unused memory"); - - cl.def("clear", &Vector::clear, "clears the contents"); - cl.def("swap", &Vector::swap, "swaps the contents"); - - cl.def("front", [](Vector &v) { - if (v.size()) return v.front(); - else throw index_error(); - }, "access the first element"); - - cl.def("back", [](Vector &v) { - if (v.size()) return v.back(); - else throw index_error(); - }, "access the last element "); - -#endif - - return cl; -} - - - -// -// std::map, std::unordered_map -// - -NAMESPACE_BEGIN(detail) - -/* Fallback functions */ -template <typename, typename, typename... Args> void map_if_insertion_operator(const Args &...) { } -template <typename, typename, typename... Args> void map_assignment(const Args &...) { } - -// Map assignment when copy-assignable: just copy the value -template <typename Map, typename Class_> -void map_assignment(enable_if_t<is_copy_assignable<typename Map::mapped_type>::value, Class_> &cl) { - using KeyType = typename Map::key_type; - using MappedType = typename Map::mapped_type; - - cl.def("__setitem__", - [](Map &m, const KeyType &k, const MappedType &v) { - auto it = m.find(k); - if (it != m.end()) it->second = v; - else m.emplace(k, v); - } - ); -} - -// Not copy-assignable, but still copy-constructible: we can update the value by erasing and reinserting -template<typename Map, typename Class_> -void map_assignment(enable_if_t< - !is_copy_assignable<typename Map::mapped_type>::value && - is_copy_constructible<typename Map::mapped_type>::value, - Class_> &cl) { - using KeyType = typename Map::key_type; - using MappedType = typename Map::mapped_type; - - cl.def("__setitem__", - [](Map &m, const KeyType &k, const MappedType &v) { - // We can't use m[k] = v; because value type might not be default constructable - auto r = m.emplace(k, v); - if (!r.second) { - // value type is not copy assignable so the only way to insert it is to erase it first... - m.erase(r.first); - m.emplace(k, v); - } - } - ); -} - - -template <typename Map, typename Class_> auto map_if_insertion_operator(Class_ &cl, std::string const &name) --> decltype(std::declval<std::ostream&>() << std::declval<typename Map::key_type>() << std::declval<typename Map::mapped_type>(), void()) { - - cl.def("__repr__", - [name](Map &m) { - std::ostringstream s; - s << name << '{'; - bool f = false; - for (auto const &kv : m) { - if (f) - s << ", "; - s << kv.first << ": " << kv.second; - f = true; - } - s << '}'; - return s.str(); - }, - "Return the canonical string representation of this map." - ); -} - - -NAMESPACE_END(detail) - -template <typename Map, typename holder_type = std::unique_ptr<Map>, typename... Args> -class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&... args) { - using KeyType = typename Map::key_type; - using MappedType = typename Map::mapped_type; - using Class_ = class_<Map, holder_type>; - - // If either type is a non-module-local bound type then make the map binding non-local as well; - // otherwise (e.g. both types are either module-local or converting) the map will be - // module-local. - auto tinfo = detail::get_type_info(typeid(MappedType)); - bool local = !tinfo || tinfo->module_local; - if (local) { - tinfo = detail::get_type_info(typeid(KeyType)); - local = !tinfo || tinfo->module_local; - } - - Class_ cl(scope, name.c_str(), pybind11::module_local(local), std::forward<Args>(args)...); - - cl.def(init<>()); - - // Register stream insertion operator (if possible) - detail::map_if_insertion_operator<Map, Class_>(cl, name); - - cl.def("__bool__", - [](const Map &m) -> bool { return !m.empty(); }, - "Check whether the map is nonempty" - ); - - cl.def("__iter__", - [](Map &m) { return make_key_iterator(m.begin(), m.end()); }, - keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ - ); - - cl.def("items", - [](Map &m) { return make_iterator(m.begin(), m.end()); }, - keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ - ); - - cl.def("__getitem__", - [](Map &m, const KeyType &k) -> MappedType & { - auto it = m.find(k); - if (it == m.end()) - throw key_error(); - return it->second; - }, - return_value_policy::reference_internal // ref + keepalive - ); - - cl.def("__contains__", - [](Map &m, const KeyType &k) -> bool { - auto it = m.find(k); - if (it == m.end()) - return false; - return true; - } - ); - - // Assignment provided only if the type is copyable - detail::map_assignment<Map, Class_>(cl); - - cl.def("__delitem__", - [](Map &m, const KeyType &k) { - auto it = m.find(k); - if (it == m.end()) - throw key_error(); - m.erase(it); - } - ); - - cl.def("__len__", &Map::size); - - return cl; -} - -NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/external/pybind11/share/cmake/pybind11/FindPythonLibsNew.cmake b/external/pybind11/share/cmake/pybind11/FindPythonLibsNew.cmake deleted file mode 100644 index e660c5f3..00000000 --- a/external/pybind11/share/cmake/pybind11/FindPythonLibsNew.cmake +++ /dev/null @@ -1,202 +0,0 @@ -# - Find python libraries -# This module finds the libraries corresponding to the Python interpreter -# FindPythonInterp provides. -# This code sets the following variables: -# -# PYTHONLIBS_FOUND - have the Python libs been found -# PYTHON_PREFIX - path to the Python installation -# PYTHON_LIBRARIES - path to the python library -# PYTHON_INCLUDE_DIRS - path to where Python.h is found -# PYTHON_MODULE_EXTENSION - lib extension, e.g. '.so' or '.pyd' -# PYTHON_MODULE_PREFIX - lib name prefix: usually an empty string -# PYTHON_SITE_PACKAGES - path to installation site-packages -# PYTHON_IS_DEBUG - whether the Python interpreter is a debug build -# -# Thanks to talljimbo for the patch adding the 'LDVERSION' config -# variable usage. - -#============================================================================= -# Copyright 2001-2009 Kitware, Inc. -# Copyright 2012 Continuum Analytics, Inc. -# -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the names of Kitware, Inc., the Insight Software Consortium, -# nor the names of their contributors may be used to endorse or promote -# products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#============================================================================= - -# Checking for the extension makes sure that `LibsNew` was found and not just `Libs`. -if(PYTHONLIBS_FOUND AND PYTHON_MODULE_EXTENSION) - return() -endif() - -# Use the Python interpreter to find the libs. -if(PythonLibsNew_FIND_REQUIRED) - find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} REQUIRED) -else() - find_package(PythonInterp ${PythonLibsNew_FIND_VERSION}) -endif() - -if(NOT PYTHONINTERP_FOUND) - set(PYTHONLIBS_FOUND FALSE) - set(PythonLibsNew_FOUND FALSE) - return() -endif() - -# According to http://stackoverflow.com/questions/646518/python-how-to-detect-debug-interpreter -# testing whether sys has the gettotalrefcount function is a reliable, cross-platform -# way to detect a CPython debug interpreter. -# -# The library suffix is from the config var LDVERSION sometimes, otherwise -# VERSION. VERSION will typically be like "2.7" on unix, and "27" on windows. -execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" - "from distutils import sysconfig as s;import sys;import struct; -print('.'.join(str(v) for v in sys.version_info)); -print(sys.prefix); -print(s.get_python_inc(plat_specific=True)); -print(s.get_python_lib(plat_specific=True)); -print(s.get_config_var('SO')); -print(hasattr(sys, 'gettotalrefcount')+0); -print(struct.calcsize('@P')); -print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION')); -print(s.get_config_var('LIBDIR') or ''); -print(s.get_config_var('MULTIARCH') or ''); -" - RESULT_VARIABLE _PYTHON_SUCCESS - OUTPUT_VARIABLE _PYTHON_VALUES - ERROR_VARIABLE _PYTHON_ERROR_VALUE) - -if(NOT _PYTHON_SUCCESS MATCHES 0) - if(PythonLibsNew_FIND_REQUIRED) - message(FATAL_ERROR - "Python config failure:\n${_PYTHON_ERROR_VALUE}") - endif() - set(PYTHONLIBS_FOUND FALSE) - set(PythonLibsNew_FOUND FALSE) - return() -endif() - -# Convert the process output into a list -if(WIN32) - string(REGEX REPLACE "\\\\" "/" _PYTHON_VALUES ${_PYTHON_VALUES}) -endif() -string(REGEX REPLACE ";" "\\\\;" _PYTHON_VALUES ${_PYTHON_VALUES}) -string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES}) -list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST) -list(GET _PYTHON_VALUES 1 PYTHON_PREFIX) -list(GET _PYTHON_VALUES 2 PYTHON_INCLUDE_DIR) -list(GET _PYTHON_VALUES 3 PYTHON_SITE_PACKAGES) -list(GET _PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION) -list(GET _PYTHON_VALUES 5 PYTHON_IS_DEBUG) -list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P) -list(GET _PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX) -list(GET _PYTHON_VALUES 8 PYTHON_LIBDIR) -list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH) - -# Make sure the Python has the same pointer-size as the chosen compiler -# Skip if CMAKE_SIZEOF_VOID_P is not defined -if(CMAKE_SIZEOF_VOID_P AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL "${CMAKE_SIZEOF_VOID_P}")) - if(PythonLibsNew_FIND_REQUIRED) - math(EXPR _PYTHON_BITS "${PYTHON_SIZEOF_VOID_P} * 8") - math(EXPR _CMAKE_BITS "${CMAKE_SIZEOF_VOID_P} * 8") - message(FATAL_ERROR - "Python config failure: Python is ${_PYTHON_BITS}-bit, " - "chosen compiler is ${_CMAKE_BITS}-bit") - endif() - set(PYTHONLIBS_FOUND FALSE) - set(PythonLibsNew_FOUND FALSE) - return() -endif() - -# The built-in FindPython didn't always give the version numbers -string(REGEX REPLACE "\\." ";" _PYTHON_VERSION_LIST ${_PYTHON_VERSION_LIST}) -list(GET _PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR) -list(GET _PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR) -list(GET _PYTHON_VERSION_LIST 2 PYTHON_VERSION_PATCH) - -# Make sure all directory separators are '/' -string(REGEX REPLACE "\\\\" "/" PYTHON_PREFIX ${PYTHON_PREFIX}) -string(REGEX REPLACE "\\\\" "/" PYTHON_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}) -string(REGEX REPLACE "\\\\" "/" PYTHON_SITE_PACKAGES ${PYTHON_SITE_PACKAGES}) - -if(CMAKE_HOST_WIN32 AND NOT (MSYS OR MINGW)) - set(PYTHON_LIBRARY - "${PYTHON_PREFIX}/libs/Python${PYTHON_LIBRARY_SUFFIX}.lib") - - # when run in a venv, PYTHON_PREFIX points to it. But the libraries remain in the - # original python installation. They may be found relative to PYTHON_INCLUDE_DIR. - if(NOT EXISTS "${PYTHON_LIBRARY}") - get_filename_component(_PYTHON_ROOT ${PYTHON_INCLUDE_DIR} DIRECTORY) - set(PYTHON_LIBRARY - "${_PYTHON_ROOT}/libs/Python${PYTHON_LIBRARY_SUFFIX}.lib") - endif() - - # raise an error if the python libs are still not found. - if(NOT EXISTS "${PYTHON_LIBRARY}") - message(FATAL_ERROR "Python libraries not found") - endif() - -else() - if(PYTHON_MULTIARCH) - set(_PYTHON_LIBS_SEARCH "${PYTHON_LIBDIR}/${PYTHON_MULTIARCH}" "${PYTHON_LIBDIR}") - else() - set(_PYTHON_LIBS_SEARCH "${PYTHON_LIBDIR}") - endif() - #message(STATUS "Searching for Python libs in ${_PYTHON_LIBS_SEARCH}") - # Probably this needs to be more involved. It would be nice if the config - # information the python interpreter itself gave us were more complete. - find_library(PYTHON_LIBRARY - NAMES "python${PYTHON_LIBRARY_SUFFIX}" - PATHS ${_PYTHON_LIBS_SEARCH} - NO_DEFAULT_PATH) - - # If all else fails, just set the name/version and let the linker figure out the path. - if(NOT PYTHON_LIBRARY) - set(PYTHON_LIBRARY python${PYTHON_LIBRARY_SUFFIX}) - endif() -endif() - -MARK_AS_ADVANCED( - PYTHON_LIBRARY - PYTHON_INCLUDE_DIR -) - -# We use PYTHON_INCLUDE_DIR, PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the -# cache entries because they are meant to specify the location of a single -# library. We now set the variables listed by the documentation for this -# module. -SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") -SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") -SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}") - -find_package_message(PYTHON - "Found PythonLibs: ${PYTHON_LIBRARY}" - "${PYTHON_EXECUTABLE}${PYTHON_VERSION}") - -set(PYTHONLIBS_FOUND TRUE) -set(PythonLibsNew_FOUND TRUE) diff --git a/external/pybind11/share/cmake/pybind11/pybind11Config.cmake b/external/pybind11/share/cmake/pybind11/pybind11Config.cmake deleted file mode 100644 index e084a0bb..00000000 --- a/external/pybind11/share/cmake/pybind11/pybind11Config.cmake +++ /dev/null @@ -1,128 +0,0 @@ -# pybind11Config.cmake -# -------------------- -# -# PYBIND11 cmake module. -# This module sets the following variables in your project:: -# -# pybind11_FOUND - true if pybind11 and all required components found on the system -# pybind11_VERSION - pybind11 version in format Major.Minor.Release -# pybind11_INCLUDE_DIRS - Directories where pybind11 and python headers are located. -# pybind11_INCLUDE_DIR - Directory where pybind11 headers are located. -# pybind11_DEFINITIONS - Definitions necessary to use pybind11, namely USING_pybind11. -# pybind11_LIBRARIES - compile flags and python libraries (as needed) to link against. -# pybind11_LIBRARY - empty. -# CMAKE_MODULE_PATH - appends location of accompanying FindPythonLibsNew.cmake and -# pybind11Tools.cmake modules. -# -# -# Available components: None -# -# -# Exported targets:: -# -# If pybind11 is found, this module defines the following :prop_tgt:`IMPORTED` -# interface library targets:: -# -# pybind11::module - for extension modules -# pybind11::embed - for embedding the Python interpreter -# -# Python headers, libraries (as needed by platform), and the C++ standard -# are attached to the target. Set PythonLibsNew variables to influence -# python detection and PYBIND11_CPP_STANDARD (-std=c++11 or -std=c++14) to -# influence standard setting. :: -# -# find_package(pybind11 CONFIG REQUIRED) -# message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") -# -# # Create an extension module -# add_library(mylib MODULE main.cpp) -# target_link_libraries(mylib pybind11::module) -# -# # Or embed the Python interpreter into an executable -# add_executable(myexe main.cpp) -# target_link_libraries(myexe pybind11::embed) -# -# Suggested usage:: -# -# find_package with version info is not recommended except for release versions. :: -# -# find_package(pybind11 CONFIG) -# find_package(pybind11 2.0 EXACT CONFIG REQUIRED) -# -# -# The following variables can be set to guide the search for this package:: -# -# pybind11_DIR - CMake variable, set to directory containing this Config file -# CMAKE_PREFIX_PATH - CMake variable, set to root directory of this package -# PATH - environment variable, set to bin directory of this package -# CMAKE_DISABLE_FIND_PACKAGE_pybind11 - CMake variable, disables -# find_package(pybind11) when not REQUIRED, perhaps to force internal build - - -####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### -####### Any changes to this file will be overwritten by the next CMake run #### -####### The input file was pybind11Config.cmake.in ######## - -get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) - -macro(set_and_check _var _file) - set(${_var} "${_file}") - if(NOT EXISTS "${_file}") - message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") - endif() -endmacro() - -macro(check_required_components _NAME) - foreach(comp ${${_NAME}_FIND_COMPONENTS}) - if(NOT ${_NAME}_${comp}_FOUND) - if(${_NAME}_FIND_REQUIRED_${comp}) - set(${_NAME}_FOUND FALSE) - endif() - endif() - endforeach() -endmacro() - -#################################################################################### - -set(PN pybind11) - -# location of pybind11/pybind11.h -set(${PN}_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") - -set(${PN}_LIBRARY "") -set(${PN}_DEFINITIONS USING_${PN}) - -check_required_components(${PN}) - -# make detectable the FindPythonLibsNew.cmake module -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) - -include(pybind11Tools) - -if(NOT (CMAKE_VERSION VERSION_LESS 3.0)) -#----------------------------------------------------------------------------- -# Don't include targets if this file is being picked up by another -# project which has already built this as a subproject -#----------------------------------------------------------------------------- -if(NOT TARGET ${PN}::pybind11) - include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets.cmake") - - find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED) - set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS}) - set_property(TARGET ${PN}::embed APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES}) - if(WIN32 OR CYGWIN) - set_property(TARGET ${PN}::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES}) - endif() - - if(CMAKE_VERSION VERSION_LESS 3.3) - set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "${PYBIND11_CPP_STANDARD}") - else() - set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CXX>:${PYBIND11_CPP_STANDARD}>) - endif() - - get_property(_iid TARGET ${PN}::pybind11 PROPERTY INTERFACE_INCLUDE_DIRECTORIES) - get_property(_ill TARGET ${PN}::module PROPERTY INTERFACE_LINK_LIBRARIES) - set(${PN}_INCLUDE_DIRS ${_iid}) - set(${PN}_LIBRARIES ${_ico} ${_ill}) -endif() -endif() diff --git a/external/pybind11/share/cmake/pybind11/pybind11ConfigVersion.cmake b/external/pybind11/share/cmake/pybind11/pybind11ConfigVersion.cmake deleted file mode 100644 index 987143f2..00000000 --- a/external/pybind11/share/cmake/pybind11/pybind11ConfigVersion.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# This is a basic version file for the Config-mode of find_package(). -# It is used by write_basic_package_version_file() as input file for configure_file() -# to create a version-file which can be installed along a config.cmake file. -# -# The created file sets PACKAGE_VERSION_EXACT if the current version string and -# the requested version string are exactly the same and it sets -# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version. -# The variable CVF_VERSION must be set before calling configure_file(). - -set(PACKAGE_VERSION "2.4.dev4") - -if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() - - -# if the installed project requested no architecture check, don't perform the check -if("FALSE") - return() -endif() - -# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: -if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "" STREQUAL "") - return() -endif() - -# check that the installed version has the same 32/64bit-ness as the one which is currently searching: -if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "") - math(EXPR installedBits " * 8") - set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") - set(PACKAGE_VERSION_UNSUITABLE TRUE) -endif() diff --git a/external/pybind11/share/cmake/pybind11/pybind11Targets.cmake b/external/pybind11/share/cmake/pybind11/pybind11Targets.cmake deleted file mode 100644 index 1575a47c..00000000 --- a/external/pybind11/share/cmake/pybind11/pybind11Targets.cmake +++ /dev/null @@ -1,113 +0,0 @@ -# Generated by CMake - -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) - message(FATAL_ERROR "CMake >= 2.6.0 required") -endif() -cmake_policy(PUSH) -cmake_policy(VERSION 2.6) -#---------------------------------------------------------------- -# Generated CMake target import file. -#---------------------------------------------------------------- - -# Commands may need to know the format version. -set(CMAKE_IMPORT_FILE_VERSION 1) - -# Protect against multiple inclusion, which would fail when already imported targets are added once more. -set(_targetsDefined) -set(_targetsNotDefined) -set(_expectedTargets) -foreach(_expectedTarget pybind11::pybind11 pybind11::module pybind11::embed) - list(APPEND _expectedTargets ${_expectedTarget}) - if(NOT TARGET ${_expectedTarget}) - list(APPEND _targetsNotDefined ${_expectedTarget}) - endif() - if(TARGET ${_expectedTarget}) - list(APPEND _targetsDefined ${_expectedTarget}) - endif() -endforeach() -if("${_targetsDefined}" STREQUAL "${_expectedTargets}") - unset(_targetsDefined) - unset(_targetsNotDefined) - unset(_expectedTargets) - set(CMAKE_IMPORT_FILE_VERSION) - cmake_policy(POP) - return() -endif() -if(NOT "${_targetsDefined}" STREQUAL "") - message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") -endif() -unset(_targetsDefined) -unset(_targetsNotDefined) -unset(_expectedTargets) - - -# Compute the installation prefix relative to this file. -get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -if(_IMPORT_PREFIX STREQUAL "/") - set(_IMPORT_PREFIX "") -endif() - -# Create imported target pybind11::pybind11 -add_library(pybind11::pybind11 INTERFACE IMPORTED) - -set_target_properties(pybind11::pybind11 PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" -) - -# Create imported target pybind11::module -add_library(pybind11::module INTERFACE IMPORTED) - -set_target_properties(pybind11::module PROPERTIES - INTERFACE_COMPILE_OPTIONS "-fvisibility=hidden" - INTERFACE_LINK_LIBRARIES "pybind11::pybind11" -) - -# Create imported target pybind11::embed -add_library(pybind11::embed INTERFACE IMPORTED) - -set_target_properties(pybind11::embed PROPERTIES - INTERFACE_LINK_LIBRARIES "pybind11::pybind11" -) - -if(CMAKE_VERSION VERSION_LESS 3.0.0) - message(FATAL_ERROR "This file relies on consumers using CMake 3.0.0 or greater.") -endif() - -# Load information for each installed configuration. -get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -file(GLOB CONFIG_FILES "${_DIR}/pybind11Targets-*.cmake") -foreach(f ${CONFIG_FILES}) - include(${f}) -endforeach() - -# Cleanup temporary variables. -set(_IMPORT_PREFIX) - -# Loop over all imported files and verify that they actually exist -foreach(target ${_IMPORT_CHECK_TARGETS} ) - foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) - if(NOT EXISTS "${file}" ) - message(FATAL_ERROR "The imported target \"${target}\" references the file - \"${file}\" -but this file does not exist. Possible reasons include: -* The file was deleted, renamed, or moved to another location. -* An install or uninstall procedure did not complete successfully. -* The installation package was faulty and contained - \"${CMAKE_CURRENT_LIST_FILE}\" -but not all the files it references. -") - endif() - endforeach() - unset(_IMPORT_CHECK_FILES_FOR_${target}) -endforeach() -unset(_IMPORT_CHECK_TARGETS) - -# This file does not depend on other imported targets which have -# been exported from the same project but in a separate export set. - -# Commands beyond this point should not need to know the version. -set(CMAKE_IMPORT_FILE_VERSION) -cmake_policy(POP) diff --git a/external/pybind11/share/cmake/pybind11/pybind11Tools.cmake b/external/pybind11/share/cmake/pybind11/pybind11Tools.cmake deleted file mode 100644 index d0a2bfc8..00000000 --- a/external/pybind11/share/cmake/pybind11/pybind11Tools.cmake +++ /dev/null @@ -1,227 +0,0 @@ -# tools/pybind11Tools.cmake -- Build system for the pybind11 modules -# -# Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch> -# -# All rights reserved. Use of this source code is governed by a -# BSD-style license that can be found in the LICENSE file. - -cmake_minimum_required(VERSION 2.8.12) - -# Add a CMake parameter for choosing a desired Python version -if(NOT PYBIND11_PYTHON_VERSION) - set(PYBIND11_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling modules") -endif() - -set(Python_ADDITIONAL_VERSIONS 3.8 3.7 3.6 3.5 3.4) -find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED) - -include(CheckCXXCompilerFlag) -include(CMakeParseArguments) - -if(NOT PYBIND11_CPP_STANDARD AND NOT CMAKE_CXX_STANDARD) - if(NOT MSVC) - check_cxx_compiler_flag("-std=c++14" HAS_CPP14_FLAG) - - if (HAS_CPP14_FLAG) - set(PYBIND11_CPP_STANDARD -std=c++14) - else() - check_cxx_compiler_flag("-std=c++11" HAS_CPP11_FLAG) - if (HAS_CPP11_FLAG) - set(PYBIND11_CPP_STANDARD -std=c++11) - else() - message(FATAL_ERROR "Unsupported compiler -- pybind11 requires C++11 support!") - endif() - endif() - elseif(MSVC) - set(PYBIND11_CPP_STANDARD /std:c++14) - endif() - - set(PYBIND11_CPP_STANDARD ${PYBIND11_CPP_STANDARD} CACHE STRING - "C++ standard flag, e.g. -std=c++11, -std=c++14, /std:c++14. Defaults to C++14 mode." FORCE) -endif() - -# Checks whether the given CXX/linker flags can compile and link a cxx file. cxxflags and -# linkerflags are lists of flags to use. The result variable is a unique variable name for each set -# of flags: the compilation result will be cached base on the result variable. If the flags work, -# sets them in cxxflags_out/linkerflags_out internal cache variables (in addition to ${result}). -function(_pybind11_return_if_cxx_and_linker_flags_work result cxxflags linkerflags cxxflags_out linkerflags_out) - set(CMAKE_REQUIRED_LIBRARIES ${linkerflags}) - check_cxx_compiler_flag("${cxxflags}" ${result}) - if (${result}) - set(${cxxflags_out} "${cxxflags}" CACHE INTERNAL "" FORCE) - set(${linkerflags_out} "${linkerflags}" CACHE INTERNAL "" FORCE) - endif() -endfunction() - -# Internal: find the appropriate link time optimization flags for this compiler -function(_pybind11_add_lto_flags target_name prefer_thin_lto) - if (NOT DEFINED PYBIND11_LTO_CXX_FLAGS) - set(PYBIND11_LTO_CXX_FLAGS "" CACHE INTERNAL "") - set(PYBIND11_LTO_LINKER_FLAGS "" CACHE INTERNAL "") - - if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - set(cxx_append "") - set(linker_append "") - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE) - # Clang Gold plugin does not support -Os; append -O3 to MinSizeRel builds to override it - set(linker_append ";$<$<CONFIG:MinSizeRel>:-O3>") - elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - set(cxx_append ";-fno-fat-lto-objects") - endif() - - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND prefer_thin_lto) - _pybind11_return_if_cxx_and_linker_flags_work(HAS_FLTO_THIN - "-flto=thin${cxx_append}" "-flto=thin${linker_append}" - PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS) - endif() - - if (NOT HAS_FLTO_THIN) - _pybind11_return_if_cxx_and_linker_flags_work(HAS_FLTO - "-flto${cxx_append}" "-flto${linker_append}" - PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS) - endif() - elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel") - # Intel equivalent to LTO is called IPO - _pybind11_return_if_cxx_and_linker_flags_work(HAS_INTEL_IPO - "-ipo" "-ipo" PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS) - elseif(MSVC) - # cmake only interprets libraries as linker flags when they start with a - (otherwise it - # converts /LTCG to \LTCG as if it was a Windows path). Luckily MSVC supports passing flags - # with - instead of /, even if it is a bit non-standard: - _pybind11_return_if_cxx_and_linker_flags_work(HAS_MSVC_GL_LTCG - "/GL" "-LTCG" PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS) - endif() - - if (PYBIND11_LTO_CXX_FLAGS) - message(STATUS "LTO enabled") - else() - message(STATUS "LTO disabled (not supported by the compiler and/or linker)") - endif() - endif() - - # Enable LTO flags if found, except for Debug builds - if (PYBIND11_LTO_CXX_FLAGS) - target_compile_options(${target_name} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:${PYBIND11_LTO_CXX_FLAGS}>") - endif() - if (PYBIND11_LTO_LINKER_FLAGS) - target_link_libraries(${target_name} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:${PYBIND11_LTO_LINKER_FLAGS}>") - endif() -endfunction() - -# Build a Python extension module: -# pybind11_add_module(<name> [MODULE | SHARED] [EXCLUDE_FROM_ALL] -# [NO_EXTRAS] [SYSTEM] [THIN_LTO] source1 [source2 ...]) -# -function(pybind11_add_module target_name) - set(options MODULE SHARED EXCLUDE_FROM_ALL NO_EXTRAS SYSTEM THIN_LTO) - cmake_parse_arguments(ARG "${options}" "" "" ${ARGN}) - - if(ARG_MODULE AND ARG_SHARED) - message(FATAL_ERROR "Can't be both MODULE and SHARED") - elseif(ARG_SHARED) - set(lib_type SHARED) - else() - set(lib_type MODULE) - endif() - - if(ARG_EXCLUDE_FROM_ALL) - set(exclude_from_all EXCLUDE_FROM_ALL) - endif() - - add_library(${target_name} ${lib_type} ${exclude_from_all} ${ARG_UNPARSED_ARGUMENTS}) - - if(ARG_SYSTEM) - set(inc_isystem SYSTEM) - endif() - - target_include_directories(${target_name} ${inc_isystem} - PRIVATE ${PYBIND11_INCLUDE_DIR} # from project CMakeLists.txt - PRIVATE ${pybind11_INCLUDE_DIR} # from pybind11Config - PRIVATE ${PYTHON_INCLUDE_DIRS}) - - # Python debug libraries expose slightly different objects - # https://docs.python.org/3.6/c-api/intro.html#debugging-builds - # https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib - if(PYTHON_IS_DEBUG) - target_compile_definitions(${target_name} PRIVATE Py_DEBUG) - endif() - - # The prefix and extension are provided by FindPythonLibsNew.cmake - set_target_properties(${target_name} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}") - set_target_properties(${target_name} PROPERTIES SUFFIX "${PYTHON_MODULE_EXTENSION}") - - # -fvisibility=hidden is required to allow multiple modules compiled against - # different pybind versions to work properly, and for some features (e.g. - # py::module_local). We force it on everything inside the `pybind11` - # namespace; also turning it on for a pybind module compilation here avoids - # potential warnings or issues from having mixed hidden/non-hidden types. - set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden") - set_target_properties(${target_name} PROPERTIES CUDA_VISIBILITY_PRESET "hidden") - - if(WIN32 OR CYGWIN) - # Link against the Python shared library on Windows - target_link_libraries(${target_name} PRIVATE ${PYTHON_LIBRARIES}) - elseif(APPLE) - # It's quite common to have multiple copies of the same Python version - # installed on one's system. E.g.: one copy from the OS and another copy - # that's statically linked into an application like Blender or Maya. - # If we link our plugin library against the OS Python here and import it - # into Blender or Maya later on, this will cause segfaults when multiple - # conflicting Python instances are active at the same time (even when they - # are of the same version). - - # Windows is not affected by this issue since it handles DLL imports - # differently. The solution for Linux and Mac OS is simple: we just don't - # link against the Python library. The resulting shared library will have - # missing symbols, but that's perfectly fine -- they will be resolved at - # import time. - - target_link_libraries(${target_name} PRIVATE "-undefined dynamic_lookup") - - if(ARG_SHARED) - # Suppress CMake >= 3.0 warning for shared libraries - set_target_properties(${target_name} PROPERTIES MACOSX_RPATH ON) - endif() - endif() - - # Make sure C++11/14 are enabled - if(CMAKE_VERSION VERSION_LESS 3.3) - target_compile_options(${target_name} PUBLIC ${PYBIND11_CPP_STANDARD}) - else() - target_compile_options(${target_name} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:${PYBIND11_CPP_STANDARD}>) - endif() - - if(ARG_NO_EXTRAS) - return() - endif() - - _pybind11_add_lto_flags(${target_name} ${ARG_THIN_LTO}) - - if (NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo) - # Strip unnecessary sections of the binary on Linux/Mac OS - if(CMAKE_STRIP) - if(APPLE) - add_custom_command(TARGET ${target_name} POST_BUILD - COMMAND ${CMAKE_STRIP} -x $<TARGET_FILE:${target_name}>) - else() - add_custom_command(TARGET ${target_name} POST_BUILD - COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${target_name}>) - endif() - endif() - endif() - - if(MSVC) - # /MP enables multithreaded builds (relevant when there are many files), /bigobj is - # needed for bigger binding projects due to the limit to 64k addressable sections - target_compile_options(${target_name} PRIVATE /bigobj) - if(CMAKE_VERSION VERSION_LESS 3.11) - target_compile_options(${target_name} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/MP>) - else() - # Only set these options for C++ files. This is important so that, for - # instance, projects that include other types of source files like CUDA - # .cu files don't get these options propagated to nvcc since that would - # cause the build to fail. - target_compile_options(${target_name} PRIVATE $<$<NOT:$<CONFIG:Debug>>:$<$<COMPILE_LANGUAGE:CXX>:/MP>>) - endif() - endif() -endfunction() -- GitLab